diff --git a/codegen/binary.rs b/codegen/binary.rs index 515338c6..31fdb2c0 100644 --- a/codegen/binary.rs +++ b/codegen/binary.rs @@ -196,8 +196,7 @@ fn gen_operand_param_parse_methods(grammar: &Vec) // associated parameters. let cases: Vec = pairs.into_iter().map(|(symbol, params)| { let params: Vec = params.iter().map(|element| { - format!("mr::Operand::{kind}(\ - try_decode!(self.decoder.{decode}()))", + format!("mr::Operand::{kind}(self.decoder.{decode}()?)", kind = get_mr_operand_kind(element), decode = get_decode_method(element)) }).collect(); @@ -225,8 +224,7 @@ fn gen_operand_param_parse_methods(grammar: &Vec) } else { // ValueEnum let cases: Vec = pairs.into_iter().map(|(symbol, params)| { let params: Vec = params.iter().map(|element| { - format!("mr::Operand::{kind}(\ - try_decode!(self.decoder.{decode}()))", + format!("mr::Operand::{kind}(self.decoder.{decode}()?)", kind = get_mr_operand_kind(element), decode = get_decode_method(element)) }).collect(); @@ -265,7 +263,7 @@ pub fn gen_operand_parse_methods(grammar: &Vec) -> String further_parse_kinds.iter().map(|kind| { format!( "{s:12}GOpKind::{kind} => {{\n\ - {s:16}let val = try_decode!(self.decoder.{decode}());\n\ + {s:16}let val = self.decoder.{decode}()?;\n\ {s:16}let mut ops = vec![mr::Operand::{kind}(val)];\n\ {s:16}ops.append(&mut self.parse_{k}_arguments(val)?);\n\ {s:16}ops\n\ @@ -287,8 +285,8 @@ pub fn gen_operand_parse_methods(grammar: &Vec) -> String let pair_cases: Vec = pair_kinds.iter().map(|&(k0, k1)| { format!("{s:12}GOpKind::{kind} => {{\n\ {s:16}vec![\ - mr::Operand::{k0}(try_decode!(self.decoder.{m0}())), \ - mr::Operand::{k1}(try_decode!(self.decoder.{m1}()))\ + mr::Operand::{k0}(self.decoder.{m0}()?), \ + mr::Operand::{k1}(self.decoder.{m1}()?)\ ]\n{s:12}}}", s = "", kind = format!("Pair{}{}", k0, k1), @@ -314,7 +312,7 @@ pub fn gen_operand_parse_methods(grammar: &Vec) -> String }).map(|kind| { format!( "{s:12}GOpKind::{gkind} => vec![mr::Operand::{mkind}\ - (try_decode!(self.decoder.{decode}()))],", + (self.decoder.{decode}()?)],", s = "", gkind = kind, mkind = get_mr_operand_kind(kind), diff --git a/rspirv/binary/autogen_parse_operand.rs b/rspirv/binary/autogen_parse_operand.rs index 7dd628f4..5be1ea06 100644 --- a/rspirv/binary/autogen_parse_operand.rs +++ b/rspirv/binary/autogen_parse_operand.rs @@ -19,72 +19,72 @@ impl<'c, 'd> Parser<'c, 'd> { fn parse_operand(&mut self, kind: GOpKind) -> Result> { Ok(match kind { - GOpKind::FPFastMathMode => vec![mr::Operand::FPFastMathMode(try_decode!(self.decoder.fpfast_math_mode()))], - GOpKind::SelectionControl => vec![mr::Operand::SelectionControl(try_decode!(self.decoder.selection_control()))], - GOpKind::FunctionControl => vec![mr::Operand::FunctionControl(try_decode!(self.decoder.function_control()))], - GOpKind::MemorySemantics => vec![mr::Operand::MemorySemantics(try_decode!(self.decoder.memory_semantics()))], - GOpKind::KernelProfilingInfo => vec![mr::Operand::KernelProfilingInfo(try_decode!(self.decoder.kernel_profiling_info()))], - GOpKind::SourceLanguage => vec![mr::Operand::SourceLanguage(try_decode!(self.decoder.source_language()))], - GOpKind::ExecutionModel => vec![mr::Operand::ExecutionModel(try_decode!(self.decoder.execution_model()))], - GOpKind::AddressingModel => vec![mr::Operand::AddressingModel(try_decode!(self.decoder.addressing_model()))], - GOpKind::MemoryModel => vec![mr::Operand::MemoryModel(try_decode!(self.decoder.memory_model()))], - GOpKind::StorageClass => vec![mr::Operand::StorageClass(try_decode!(self.decoder.storage_class()))], - GOpKind::Dim => vec![mr::Operand::Dim(try_decode!(self.decoder.dim()))], - GOpKind::SamplerAddressingMode => vec![mr::Operand::SamplerAddressingMode(try_decode!(self.decoder.sampler_addressing_mode()))], - GOpKind::SamplerFilterMode => vec![mr::Operand::SamplerFilterMode(try_decode!(self.decoder.sampler_filter_mode()))], - GOpKind::ImageFormat => vec![mr::Operand::ImageFormat(try_decode!(self.decoder.image_format()))], - GOpKind::ImageChannelOrder => vec![mr::Operand::ImageChannelOrder(try_decode!(self.decoder.image_channel_order()))], - GOpKind::ImageChannelDataType => vec![mr::Operand::ImageChannelDataType(try_decode!(self.decoder.image_channel_data_type()))], - GOpKind::FPRoundingMode => vec![mr::Operand::FPRoundingMode(try_decode!(self.decoder.fprounding_mode()))], - GOpKind::LinkageType => vec![mr::Operand::LinkageType(try_decode!(self.decoder.linkage_type()))], - GOpKind::AccessQualifier => vec![mr::Operand::AccessQualifier(try_decode!(self.decoder.access_qualifier()))], - GOpKind::FunctionParameterAttribute => vec![mr::Operand::FunctionParameterAttribute(try_decode!(self.decoder.function_parameter_attribute()))], - GOpKind::BuiltIn => vec![mr::Operand::BuiltIn(try_decode!(self.decoder.built_in()))], - GOpKind::Scope => vec![mr::Operand::Scope(try_decode!(self.decoder.scope()))], - GOpKind::GroupOperation => vec![mr::Operand::GroupOperation(try_decode!(self.decoder.group_operation()))], - GOpKind::KernelEnqueueFlags => vec![mr::Operand::KernelEnqueueFlags(try_decode!(self.decoder.kernel_enqueue_flags()))], - GOpKind::Capability => vec![mr::Operand::Capability(try_decode!(self.decoder.capability()))], - GOpKind::IdMemorySemantics => vec![mr::Operand::IdMemorySemantics(try_decode!(self.decoder.id()))], - GOpKind::IdScope => vec![mr::Operand::IdScope(try_decode!(self.decoder.id()))], - GOpKind::IdRef => vec![mr::Operand::IdRef(try_decode!(self.decoder.id()))], - GOpKind::LiteralInteger => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - GOpKind::LiteralString => vec![mr::Operand::LiteralString(try_decode!(self.decoder.string()))], - GOpKind::LiteralExtInstInteger => vec![mr::Operand::LiteralExtInstInteger(try_decode!(self.decoder.ext_inst_integer()))], + GOpKind::FPFastMathMode => vec![mr::Operand::FPFastMathMode(self.decoder.fpfast_math_mode()?)], + GOpKind::SelectionControl => vec![mr::Operand::SelectionControl(self.decoder.selection_control()?)], + GOpKind::FunctionControl => vec![mr::Operand::FunctionControl(self.decoder.function_control()?)], + GOpKind::MemorySemantics => vec![mr::Operand::MemorySemantics(self.decoder.memory_semantics()?)], + GOpKind::KernelProfilingInfo => vec![mr::Operand::KernelProfilingInfo(self.decoder.kernel_profiling_info()?)], + GOpKind::SourceLanguage => vec![mr::Operand::SourceLanguage(self.decoder.source_language()?)], + GOpKind::ExecutionModel => vec![mr::Operand::ExecutionModel(self.decoder.execution_model()?)], + GOpKind::AddressingModel => vec![mr::Operand::AddressingModel(self.decoder.addressing_model()?)], + GOpKind::MemoryModel => vec![mr::Operand::MemoryModel(self.decoder.memory_model()?)], + GOpKind::StorageClass => vec![mr::Operand::StorageClass(self.decoder.storage_class()?)], + GOpKind::Dim => vec![mr::Operand::Dim(self.decoder.dim()?)], + GOpKind::SamplerAddressingMode => vec![mr::Operand::SamplerAddressingMode(self.decoder.sampler_addressing_mode()?)], + GOpKind::SamplerFilterMode => vec![mr::Operand::SamplerFilterMode(self.decoder.sampler_filter_mode()?)], + GOpKind::ImageFormat => vec![mr::Operand::ImageFormat(self.decoder.image_format()?)], + GOpKind::ImageChannelOrder => vec![mr::Operand::ImageChannelOrder(self.decoder.image_channel_order()?)], + GOpKind::ImageChannelDataType => vec![mr::Operand::ImageChannelDataType(self.decoder.image_channel_data_type()?)], + GOpKind::FPRoundingMode => vec![mr::Operand::FPRoundingMode(self.decoder.fprounding_mode()?)], + GOpKind::LinkageType => vec![mr::Operand::LinkageType(self.decoder.linkage_type()?)], + GOpKind::AccessQualifier => vec![mr::Operand::AccessQualifier(self.decoder.access_qualifier()?)], + GOpKind::FunctionParameterAttribute => vec![mr::Operand::FunctionParameterAttribute(self.decoder.function_parameter_attribute()?)], + GOpKind::BuiltIn => vec![mr::Operand::BuiltIn(self.decoder.built_in()?)], + GOpKind::Scope => vec![mr::Operand::Scope(self.decoder.scope()?)], + GOpKind::GroupOperation => vec![mr::Operand::GroupOperation(self.decoder.group_operation()?)], + GOpKind::KernelEnqueueFlags => vec![mr::Operand::KernelEnqueueFlags(self.decoder.kernel_enqueue_flags()?)], + GOpKind::Capability => vec![mr::Operand::Capability(self.decoder.capability()?)], + GOpKind::IdMemorySemantics => vec![mr::Operand::IdMemorySemantics(self.decoder.id()?)], + GOpKind::IdScope => vec![mr::Operand::IdScope(self.decoder.id()?)], + GOpKind::IdRef => vec![mr::Operand::IdRef(self.decoder.id()?)], + GOpKind::LiteralInteger => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + GOpKind::LiteralString => vec![mr::Operand::LiteralString(self.decoder.string()?)], + GOpKind::LiteralExtInstInteger => vec![mr::Operand::LiteralExtInstInteger(self.decoder.ext_inst_integer()?)], GOpKind::PairLiteralIntegerIdRef => { - vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32())), mr::Operand::IdRef(try_decode!(self.decoder.id()))] + vec![mr::Operand::LiteralInt32(self.decoder.int32()?), mr::Operand::IdRef(self.decoder.id()?)] } GOpKind::PairIdRefLiteralInteger => { - vec![mr::Operand::IdRef(try_decode!(self.decoder.id())), mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))] + vec![mr::Operand::IdRef(self.decoder.id()?), mr::Operand::LiteralInt32(self.decoder.int32()?)] } GOpKind::PairIdRefIdRef => { - vec![mr::Operand::IdRef(try_decode!(self.decoder.id())), mr::Operand::IdRef(try_decode!(self.decoder.id()))] + vec![mr::Operand::IdRef(self.decoder.id()?), mr::Operand::IdRef(self.decoder.id()?)] } GOpKind::ImageOperands => { - let val = try_decode!(self.decoder.image_operands()); + let val = self.decoder.image_operands()?; let mut ops = vec![mr::Operand::ImageOperands(val)]; ops.append(&mut self.parse_image_operands_arguments(val)?); ops } GOpKind::LoopControl => { - let val = try_decode!(self.decoder.loop_control()); + let val = self.decoder.loop_control()?; let mut ops = vec![mr::Operand::LoopControl(val)]; ops.append(&mut self.parse_loop_control_arguments(val)?); ops } GOpKind::MemoryAccess => { - let val = try_decode!(self.decoder.memory_access()); + let val = self.decoder.memory_access()?; let mut ops = vec![mr::Operand::MemoryAccess(val)]; ops.append(&mut self.parse_memory_access_arguments(val)?); ops } GOpKind::ExecutionMode => { - let val = try_decode!(self.decoder.execution_mode()); + let val = self.decoder.execution_mode()?; let mut ops = vec![mr::Operand::ExecutionMode(val)]; ops.append(&mut self.parse_execution_mode_arguments(val)?); ops } GOpKind::Decoration => { - let val = try_decode!(self.decoder.decoration()); + let val = self.decoder.decoration()?; let mut ops = vec![mr::Operand::Decoration(val)]; ops.append(&mut self.parse_decoration_arguments(val)?); ops @@ -99,34 +99,34 @@ impl<'c, 'd> Parser<'c, 'd> { fn parse_image_operands_arguments(&mut self, image_operands: spirv::ImageOperands) -> Result> { let mut params = vec![]; if image_operands.contains(spirv::ImageOperands::BIAS) { - params.append(&mut vec![mr::Operand::IdRef(try_decode!(self.decoder.id()))]); + params.append(&mut vec![mr::Operand::IdRef(self.decoder.id()?)]); } if image_operands.contains(spirv::ImageOperands::LOD) { - params.append(&mut vec![mr::Operand::IdRef(try_decode!(self.decoder.id()))]); + params.append(&mut vec![mr::Operand::IdRef(self.decoder.id()?)]); } if image_operands.contains(spirv::ImageOperands::GRAD) { - params.append(&mut vec![mr::Operand::IdRef(try_decode!(self.decoder.id())), mr::Operand::IdRef(try_decode!(self.decoder.id()))]); + params.append(&mut vec![mr::Operand::IdRef(self.decoder.id()?), mr::Operand::IdRef(self.decoder.id()?)]); } if image_operands.contains(spirv::ImageOperands::CONST_OFFSET) { - params.append(&mut vec![mr::Operand::IdRef(try_decode!(self.decoder.id()))]); + params.append(&mut vec![mr::Operand::IdRef(self.decoder.id()?)]); } if image_operands.contains(spirv::ImageOperands::OFFSET) { - params.append(&mut vec![mr::Operand::IdRef(try_decode!(self.decoder.id()))]); + params.append(&mut vec![mr::Operand::IdRef(self.decoder.id()?)]); } if image_operands.contains(spirv::ImageOperands::CONST_OFFSETS) { - params.append(&mut vec![mr::Operand::IdRef(try_decode!(self.decoder.id()))]); + params.append(&mut vec![mr::Operand::IdRef(self.decoder.id()?)]); } if image_operands.contains(spirv::ImageOperands::SAMPLE) { - params.append(&mut vec![mr::Operand::IdRef(try_decode!(self.decoder.id()))]); + params.append(&mut vec![mr::Operand::IdRef(self.decoder.id()?)]); } if image_operands.contains(spirv::ImageOperands::MIN_LOD) { - params.append(&mut vec![mr::Operand::IdRef(try_decode!(self.decoder.id()))]); + params.append(&mut vec![mr::Operand::IdRef(self.decoder.id()?)]); } if image_operands.contains(spirv::ImageOperands::MAKE_TEXEL_AVAILABLE_KHR) { - params.append(&mut vec![mr::Operand::IdScope(try_decode!(self.decoder.id()))]); + params.append(&mut vec![mr::Operand::IdScope(self.decoder.id()?)]); } if image_operands.contains(spirv::ImageOperands::MAKE_TEXEL_VISIBLE_KHR) { - params.append(&mut vec![mr::Operand::IdScope(try_decode!(self.decoder.id()))]); + params.append(&mut vec![mr::Operand::IdScope(self.decoder.id()?)]); } Ok(params) } @@ -134,7 +134,7 @@ impl<'c, 'd> Parser<'c, 'd> { fn parse_loop_control_arguments(&mut self, loop_control: spirv::LoopControl) -> Result> { let mut params = vec![]; if loop_control.contains(spirv::LoopControl::DEPENDENCY_LENGTH) { - params.append(&mut vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))]); + params.append(&mut vec![mr::Operand::LiteralInt32(self.decoder.int32()?)]); } Ok(params) } @@ -142,60 +142,60 @@ impl<'c, 'd> Parser<'c, 'd> { fn parse_memory_access_arguments(&mut self, memory_access: spirv::MemoryAccess) -> Result> { let mut params = vec![]; if memory_access.contains(spirv::MemoryAccess::ALIGNED) { - params.append(&mut vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))]); + params.append(&mut vec![mr::Operand::LiteralInt32(self.decoder.int32()?)]); } if memory_access.contains(spirv::MemoryAccess::MAKE_POINTER_AVAILABLE_KHR) { - params.append(&mut vec![mr::Operand::IdScope(try_decode!(self.decoder.id()))]); + params.append(&mut vec![mr::Operand::IdScope(self.decoder.id()?)]); } if memory_access.contains(spirv::MemoryAccess::MAKE_POINTER_VISIBLE_KHR) { - params.append(&mut vec![mr::Operand::IdScope(try_decode!(self.decoder.id()))]); + params.append(&mut vec![mr::Operand::IdScope(self.decoder.id()?)]); } Ok(params) } fn parse_execution_mode_arguments(&mut self, execution_mode: spirv::ExecutionMode) -> Result> { Ok(match execution_mode { - spirv::ExecutionMode::Invocations => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::ExecutionMode::LocalSize => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32())), mr::Operand::LiteralInt32(try_decode!(self.decoder.int32())), mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::ExecutionMode::LocalSizeHint => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32())), mr::Operand::LiteralInt32(try_decode!(self.decoder.int32())), mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::ExecutionMode::OutputVertices => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::ExecutionMode::VecTypeHint => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::ExecutionMode::SubgroupSize => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::ExecutionMode::SubgroupsPerWorkgroup => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::ExecutionMode::SubgroupsPerWorkgroupId => vec![mr::Operand::IdRef(try_decode!(self.decoder.id()))], - spirv::ExecutionMode::LocalSizeId => vec![mr::Operand::IdRef(try_decode!(self.decoder.id())), mr::Operand::IdRef(try_decode!(self.decoder.id())), mr::Operand::IdRef(try_decode!(self.decoder.id()))], - spirv::ExecutionMode::LocalSizeHintId => vec![mr::Operand::IdRef(try_decode!(self.decoder.id()))], + spirv::ExecutionMode::Invocations => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::ExecutionMode::LocalSize => vec![mr::Operand::LiteralInt32(self.decoder.int32()?), mr::Operand::LiteralInt32(self.decoder.int32()?), mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::ExecutionMode::LocalSizeHint => vec![mr::Operand::LiteralInt32(self.decoder.int32()?), mr::Operand::LiteralInt32(self.decoder.int32()?), mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::ExecutionMode::OutputVertices => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::ExecutionMode::VecTypeHint => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::ExecutionMode::SubgroupSize => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::ExecutionMode::SubgroupsPerWorkgroup => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::ExecutionMode::SubgroupsPerWorkgroupId => vec![mr::Operand::IdRef(self.decoder.id()?)], + spirv::ExecutionMode::LocalSizeId => vec![mr::Operand::IdRef(self.decoder.id()?), mr::Operand::IdRef(self.decoder.id()?), mr::Operand::IdRef(self.decoder.id()?)], + spirv::ExecutionMode::LocalSizeHintId => vec![mr::Operand::IdRef(self.decoder.id()?)], _ => vec![] }) } fn parse_decoration_arguments(&mut self, decoration: spirv::Decoration) -> Result> { Ok(match decoration { - spirv::Decoration::SpecId => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::Decoration::ArrayStride => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::Decoration::MatrixStride => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::Decoration::BuiltIn => vec![mr::Operand::BuiltIn(try_decode!(self.decoder.built_in()))], - spirv::Decoration::Stream => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::Decoration::Location => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::Decoration::Component => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::Decoration::Index => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::Decoration::Binding => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::Decoration::DescriptorSet => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::Decoration::Offset => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::Decoration::XfbBuffer => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::Decoration::XfbStride => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::Decoration::FuncParamAttr => vec![mr::Operand::FunctionParameterAttribute(try_decode!(self.decoder.function_parameter_attribute()))], - spirv::Decoration::FPRoundingMode => vec![mr::Operand::FPRoundingMode(try_decode!(self.decoder.fprounding_mode()))], - spirv::Decoration::FPFastMathMode => vec![mr::Operand::FPFastMathMode(try_decode!(self.decoder.fpfast_math_mode()))], - spirv::Decoration::LinkageAttributes => vec![mr::Operand::LiteralString(try_decode!(self.decoder.string())), mr::Operand::LinkageType(try_decode!(self.decoder.linkage_type()))], - spirv::Decoration::InputAttachmentIndex => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::Decoration::Alignment => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::Decoration::MaxByteOffset => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::Decoration::AlignmentId => vec![mr::Operand::IdRef(try_decode!(self.decoder.id()))], - spirv::Decoration::MaxByteOffsetId => vec![mr::Operand::IdRef(try_decode!(self.decoder.id()))], - spirv::Decoration::SecondaryViewportRelativeNV => vec![mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))], - spirv::Decoration::HlslCounterBufferGOOGLE => vec![mr::Operand::IdRef(try_decode!(self.decoder.id()))], - spirv::Decoration::HlslSemanticGOOGLE => vec![mr::Operand::LiteralString(try_decode!(self.decoder.string()))], + spirv::Decoration::SpecId => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::Decoration::ArrayStride => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::Decoration::MatrixStride => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::Decoration::BuiltIn => vec![mr::Operand::BuiltIn(self.decoder.built_in()?)], + spirv::Decoration::Stream => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::Decoration::Location => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::Decoration::Component => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::Decoration::Index => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::Decoration::Binding => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::Decoration::DescriptorSet => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::Decoration::Offset => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::Decoration::XfbBuffer => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::Decoration::XfbStride => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::Decoration::FuncParamAttr => vec![mr::Operand::FunctionParameterAttribute(self.decoder.function_parameter_attribute()?)], + spirv::Decoration::FPRoundingMode => vec![mr::Operand::FPRoundingMode(self.decoder.fprounding_mode()?)], + spirv::Decoration::FPFastMathMode => vec![mr::Operand::FPFastMathMode(self.decoder.fpfast_math_mode()?)], + spirv::Decoration::LinkageAttributes => vec![mr::Operand::LiteralString(self.decoder.string()?), mr::Operand::LinkageType(self.decoder.linkage_type()?)], + spirv::Decoration::InputAttachmentIndex => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::Decoration::Alignment => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::Decoration::MaxByteOffset => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::Decoration::AlignmentId => vec![mr::Operand::IdRef(self.decoder.id()?)], + spirv::Decoration::MaxByteOffsetId => vec![mr::Operand::IdRef(self.decoder.id()?)], + spirv::Decoration::SecondaryViewportRelativeNV => vec![mr::Operand::LiteralInt32(self.decoder.int32()?)], + spirv::Decoration::HlslCounterBufferGOOGLE => vec![mr::Operand::IdRef(self.decoder.id()?)], + spirv::Decoration::HlslSemanticGOOGLE => vec![mr::Operand::LiteralString(self.decoder.string()?)], _ => vec![] }) } diff --git a/rspirv/binary/parser.rs b/rspirv/binary/parser.rs index df4ea877..9074ad39 100644 --- a/rspirv/binary/parser.rs +++ b/rspirv/binary/parser.rs @@ -67,6 +67,12 @@ pub enum State { SpecConstantOpIntegerIncorrect(usize, usize), } +impl From for State { + fn from(err: DecodeError) -> Self { + State::OperandError(err) + } +} + impl error::Error for State { fn description(&self) -> &str { match *self { @@ -258,14 +264,6 @@ pub struct Parser<'c, 'd> { inst_index: usize, } -/// Tries to decode `$e` and returns the error if errored out. -macro_rules! try_decode { - ($e: expr) => (match $e { - Ok(val) => val, - Err(err) => return Err(State::OperandError(err)) - }); -} - impl<'c, 'd> Parser<'c, 'd> { /// Creates a new parser to parse the given `binary` and send the module /// header and instructions to the given `consumer`. @@ -356,8 +354,8 @@ impl<'c, 'd> Parser<'c, 'd> { match t { Type::Integer(size, _) => { match size { - 32 => Ok(mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))), - 64 => Ok(mr::Operand::LiteralInt64(try_decode!(self.decoder.int64()))), + 32 => Ok(mr::Operand::LiteralInt32(self.decoder.int32()?)), + 64 => Ok(mr::Operand::LiteralInt64(self.decoder.int64()?)), _ => { Err(State::TypeUnsupported(self.decoder.offset(), self.inst_index)) } @@ -366,10 +364,10 @@ impl<'c, 'd> Parser<'c, 'd> { Type::Float(size) => { match size { 32 => { - Ok(mr::Operand::LiteralFloat32(try_decode!(self.decoder.float32()))) + Ok(mr::Operand::LiteralFloat32(self.decoder.float32()?)) } 64 => { - Ok(mr::Operand::LiteralFloat64(try_decode!(self.decoder.float64()))) + Ok(mr::Operand::LiteralFloat64(self.decoder.float64()?)) } _ => { Err(State::TypeUnsupported(self.decoder.offset(), self.inst_index)) @@ -380,21 +378,21 @@ impl<'c, 'd> Parser<'c, 'd> { } // Treat as a normal SPIR-V word if we don't know the type. // TODO: find a better way to handle this. - None => Ok(mr::Operand::LiteralInt32(try_decode!(self.decoder.int32()))), + None => Ok(mr::Operand::LiteralInt32(self.decoder.int32()?)), } } fn parse_spec_constant_op(&mut self) -> Result> { let mut operands = vec![]; - let number = try_decode!(self.decoder.int32()); + let number = self.decoder.int32()?; if let Some(g) = GInstTable::lookup_opcode(number as u16) { // TODO: check whether this opcode is allowed here. operands.push(mr::Operand::LiteralSpecConstantOpInteger(g.opcode)); // We need id parameters to this SpecConstantOp. for operand in g.operands { if operand.kind == GOpKind::IdRef { - operands.push(mr::Operand::IdRef(try_decode!(self.decoder.id()))) + operands.push(mr::Operand::IdRef(self.decoder.id()?)) } } Ok(operands) @@ -414,8 +412,8 @@ impl<'c, 'd> Parser<'c, 'd> { let has_more_coperands = !self.decoder.limit_reached(); if has_more_coperands { match loperand.kind { - GOpKind::IdResultType => rtype = Some(try_decode!(self.decoder.id())), - GOpKind::IdResult => rid = Some(try_decode!(self.decoder.id())), + GOpKind::IdResultType => rtype = Some(self.decoder.id()?), + GOpKind::IdResult => rid = Some(self.decoder.id()?), GOpKind::LiteralContextDependentNumber => { // Only constant defining instructions use this kind. // If it is not true, that means the grammar is wrong