[hlsl-out] Implement Access and Unary expressions

This commit is contained in:
Gordon-F 2021-06-21 23:32:32 +03:00 committed by Dzmitry Malyshau
parent d3fe1c978b
commit 9b823c1b60
2 changed files with 33 additions and 1 deletions

View File

@ -50,7 +50,7 @@ impl Default for Options {
pub enum Error {
#[error(transparent)]
IoError(#[from] FmtError),
#[error("BuiltIn {0:?} is not supported")]
#[error("Shader model {0:?} is not supported")]
UnsupportedShaderModel(ShaderModel),
#[error("A scalar with an unsupported width was requested: {0:?} {1:?}")]
UnsupportedScalar(crate::ScalarKind, crate::Bytes),

View File

@ -937,6 +937,38 @@ impl<'a, W: Write> Writer<'a, W> {
write!(self.out, "{}", name)?;
}
Expression::Load { pointer } => self.write_expr(module, pointer, func_ctx)?,
Expression::Access { base, index } => {
self.write_expr(module, base, func_ctx)?;
write!(self.out, "[")?;
self.write_expr(module, index, func_ctx)?;
write!(self.out, "]")?
}
Expression::Unary { op, expr } => {
// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-operators#unary-operators
write!(
self.out,
"({} ",
match op {
crate::UnaryOperator::Negate => "-",
crate::UnaryOperator::Not =>
match *func_ctx.info[expr].ty.inner_with(&module.types) {
TypeInner::Scalar {
kind: ScalarKind::Bool,
..
} => "!",
ref other =>
return Err(Error::Custom(format!(
"Cannot apply not to type {:?}",
other
))),
},
}
)?;
self.write_expr(module, expr, func_ctx)?;
write!(self.out, ")")?
}
_ => return Err(Error::Unimplemented(format!("write_expr {:?}", expression))),
}