[spv-in] support boolean constants

This commit is contained in:
Dzmitry Malyshau 2021-02-10 16:09:54 -05:00
parent 2507794bc6
commit 49eb93cf7d

View File

@ -1554,6 +1554,8 @@ impl<I: Iterator<Item = u32>> Parser<I> {
Op::Constant | Op::SpecConstant => self.parse_constant(inst, &mut module),
Op::ConstantComposite => self.parse_composite_constant(inst, &mut module),
Op::ConstantNull | Op::Undef => self.parse_null_constant(inst, &mut module),
Op::ConstantTrue => self.parse_bool_constant(inst, true, &mut module),
Op::ConstantFalse => self.parse_bool_constant(inst, false, &mut module),
Op::Variable => self.parse_global_variable(inst, &mut module),
Op::Function => {
self.switch(ModuleState::Function, inst.op)?;
@ -2398,6 +2400,34 @@ impl<I: Iterator<Item = u32>> Parser<I> {
Ok(())
}
fn parse_bool_constant(
&mut self,
inst: Instruction,
value: bool,
module: &mut crate::Module,
) -> Result<(), Error> {
self.switch(ModuleState::Type, inst.op)?;
inst.expect(3)?;
let type_id = self.next()?;
let id = self.next()?;
self.lookup_constant.insert(
id,
LookupConstant {
handle: module.constants.append(crate::Constant {
name: self.future_decor.remove(&id).and_then(|dec| dec.name),
specialization: None, //TODO
inner: crate::ConstantInner::Scalar {
width: 1,
value: crate::ScalarValue::Bool(value),
},
}),
type_id,
},
);
Ok(())
}
fn parse_global_variable(
&mut self,
inst: Instruction,