[spv-out] support select expressions

This commit is contained in:
Anthony Cowley
2021-02-13 03:33:23 -05:00
committed by Dzmitry Malyshau
parent 8183f4ff6f
commit d0ef4e9dbe
2 changed files with 39 additions and 0 deletions

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)
}

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"));