From 49eb93cf7dfdf154d26a02c0e500422dc58b5d78 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Wed, 10 Feb 2021 16:09:54 -0500 Subject: [PATCH] [spv-in] support boolean constants --- src/front/spv/mod.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/front/spv/mod.rs b/src/front/spv/mod.rs index 46dc68adde..1a78c80574 100644 --- a/src/front/spv/mod.rs +++ b/src/front/spv/mod.rs @@ -1554,6 +1554,8 @@ impl> Parser { 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> Parser { 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,