[spv-out] support select expressions

This commit is contained in:
Anthony Cowley authored and Dzmitry Malyshau committed 2021-02-13 22:56:43 -05:00
1 parent 8183f4ff6f
commit d0ef4e9dbe
2 files changed
+39

No files matched your search

+16
View File
@@ -709,6 +709,22 @@ impl super::Instruction {
instruction
}
pub(super) fn select(
result_type_id: Word,
id: Word,
condition_id: Word,
accept_id: Word,
reject_id: Word,
) -> Self {
let mut instruction = Self::new(Op::Select);
instruction.add_operand(result_type_id);
instruction.add_operand(id);
instruction.add_operand(condition_id);
instruction.add_operand(accept_id);
instruction.add_operand(reject_id);
instruction
}
pub(super) fn kill() -> Self {
Self::new(Op::Kill)
}
+23
View File
@@ -1734,6 +1734,29 @@ impl Writer {
block.body.push(main_instruction);
RawExpression::Value(id)
}
crate::Expression::Select {
condition,
accept,
reject,
} => {
let id = self.generate_id();
let condition_id =
self.write_expression(ir_module, ir_function, condition, block, function)?;
let accept_id =
self.write_expression(ir_module, ir_function, accept, block, function)?;
let reject_id =
self.write_expression(ir_module, ir_function, reject, block, function)?;
let instruction = Instruction::select(
result_type_id,
id,
condition_id,
accept_id,
reject_id,
);
block.body.push(instruction);
RawExpression::Value(id)
}
ref other => {
log::error!("unimplemented {:?}", other);
return Err(Error::FeatureNotImplemented("expression"));