mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-02-25 13:23:47 +00:00
Add support for unary ops to glsl
This commit is contained in:
parent
708751a805
commit
993521965d
@ -3,7 +3,7 @@ use crate::{
|
||||
proc::{ResolveContext, Typifier},
|
||||
Arena, BinaryOperator, Binding, Constant, Expression, FastHashMap, Function, FunctionArgument,
|
||||
GlobalVariable, Handle, Interpolation, LocalVariable, Module, RelationalFunction, ShaderStage,
|
||||
Statement, StorageClass, Type,
|
||||
Statement, StorageClass, Type, UnaryOperator,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -57,6 +57,13 @@ impl Program {
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn unary_expr(&mut self, op: UnaryOperator, tgt: &ExpressionRule) -> ExpressionRule {
|
||||
ExpressionRule::from_expression(self.context.expressions.append(Expression::Unary {
|
||||
op,
|
||||
expr: tgt.expression,
|
||||
}))
|
||||
}
|
||||
|
||||
/// Helper function to insert equality expressions, this handles the special
|
||||
/// case of `vec1 == vec2` and `vec1 != vec2` since in the IR they are
|
||||
/// represented as `all(equal(vec1, vec2))` and `any(notEqual(vec1, vec2))`
|
||||
|
@ -8,7 +8,7 @@ pomelo! {
|
||||
Arena, BinaryOperator, Binding, Block, Constant,
|
||||
ConstantInner, EntryPoint, Expression,
|
||||
Function, GlobalVariable, Handle, Interpolation,
|
||||
LocalVariable, ScalarValue,
|
||||
LocalVariable, ScalarValue, ScalarKind,
|
||||
Statement, StorageAccess, StorageClass, StructMember,
|
||||
SwitchCase, Type, TypeInner, UnaryOperator, FunctionArgument
|
||||
};
|
||||
@ -319,15 +319,27 @@ pomelo! {
|
||||
//TODO
|
||||
return Err(ErrorKind::NotImplemented("--pre"))
|
||||
}
|
||||
unary_expression ::= unary_operator unary_expression {
|
||||
//TODO
|
||||
return Err(ErrorKind::NotImplemented("unary_op"))
|
||||
unary_expression ::= Plus unary_expression(tgt) {
|
||||
tgt
|
||||
}
|
||||
unary_expression ::= Dash unary_expression(tgt) {
|
||||
extra.unary_expr(UnaryOperator::Negate, &tgt)
|
||||
}
|
||||
unary_expression ::= Bang unary_expression(tgt) {
|
||||
if let TypeInner::Scalar { kind: ScalarKind::Bool, .. } = extra.resolve_type(tgt.expression)? {
|
||||
extra.unary_expr(UnaryOperator::Not, &tgt)
|
||||
} else {
|
||||
return Err(ErrorKind::SemanticError("Cannot apply '!' to non bool type".into()))
|
||||
}
|
||||
}
|
||||
unary_expression ::= Tilde unary_expression(tgt) {
|
||||
if extra.resolve_type(tgt.expression)?.scalar_kind() != Some(ScalarKind::Bool) {
|
||||
extra.unary_expr(UnaryOperator::Not, &tgt)
|
||||
} else {
|
||||
return Err(ErrorKind::SemanticError("Cannot apply '~' to type".into()))
|
||||
}
|
||||
}
|
||||
|
||||
unary_operator ::= Plus;
|
||||
unary_operator ::= Dash;
|
||||
unary_operator ::= Bang;
|
||||
unary_operator ::= Tilde;
|
||||
multiplicative_expression ::= unary_expression;
|
||||
multiplicative_expression ::= multiplicative_expression(left) Star unary_expression(right) {
|
||||
extra.binary_expr(BinaryOperator::Multiply, &left, &right)
|
||||
|
Loading…
Reference in New Issue
Block a user