Remove Mul expression type

This commit is contained in:
Dzmitry Malyshau 2020-03-15 11:55:01 -04:00 committed by Dzmitry Malyshau
parent 1957b09c4d
commit 4a72abb142
4 changed files with 19 additions and 6 deletions

View File

@ -420,10 +420,17 @@ impl<W: Write> Writer<W> {
ref other => panic!("Unexpected load pointer {:?}", other),
}
}
crate::Expression::Mul(left, right) => {
crate::Expression::Binary { op, left, right } => {
let op_ch = match op {
crate::BinaryOperator::Add => '+',
crate::BinaryOperator::Multiply => '*',
crate::BinaryOperator::Divide => '/',
crate::BinaryOperator::Modulo => '%',
_ => panic!("Unsupported binary op {:?}", op),
};
write!(self.out, "(")?;
let ty_left = self.put_expression(left, expressions, module)?;
write!(self.out, " * ")?;
write!(self.out, " {} ", op_ch)?;
let ty_right = self.put_expression(right, expressions, module)?;
write!(self.out, ")")?;
Ok(match (ty_left.borrow(), ty_right.borrow()) {

View File

@ -577,7 +577,11 @@ impl<I: Iterator<Item = u32>> Parser<I> {
crate::TypeInner::Scalar { kind: crate::ScalarKind::Float, width } if width == res_width => (),
_ => return Err(Error::UnsupportedType(scalar_type_lookup.handle)),
};
let expr = crate::Expression::Mul(vector_lexp.handle, scalar_lexp.handle);
let expr = crate::Expression::Binary {
op: crate::BinaryOperator::Multiply,
left: vector_lexp.handle,
right: scalar_lexp.handle,
};
self.lookup_expression.insert(result_id, LookupExpression {
handle: fun.expressions.append(expr),
type_id: result_type_id,
@ -606,7 +610,11 @@ impl<I: Iterator<Item = u32>> Parser<I> {
crate::TypeInner::Vector { size, kind: crate::ScalarKind::Float, width } if size == columns && width == res_width => (),
_ => return Err(Error::UnsupportedType(vector_type_lookup.handle)),
};
let expr = crate::Expression::Mul(matrix_lexp.handle, vector_lexp.handle);
let expr = crate::Expression::Binary {
op: crate::BinaryOperator::Multiply,
left: matrix_lexp.handle,
right: vector_lexp.handle,
};
self.lookup_expression.insert(result_id, LookupExpression {
handle: fun.expressions.append(expr),
type_id: result_type_id,

View File

@ -197,7 +197,6 @@ pub enum Expression {
Load {
pointer: Handle<Expression>,
},
Mul(Handle<Expression>, Handle<Expression>),
ImageSample {
image: Handle<Expression>,
sampler: Handle<Expression>,

View File

@ -65,7 +65,6 @@ impl Typifier {
crate::Expression::GlobalVariable(h) => global_vars[h].ty,
crate::Expression::LocalVariable(h) => local_vars[h].ty,
crate::Expression::Load { .. } => unimplemented!(),
crate::Expression::Mul(_, _) => unimplemented!(),
crate::Expression::ImageSample { .. } => unimplemented!(),
crate::Expression::Unary { expr, .. } => self.types[expr.index()],
crate::Expression::Binary { op, left, right } => {