@@ -13,19 +13,18 @@ fn convert_quantifier(quantifier: structs::Quantifier) -> Ident {
1313 } )
1414}
1515
16- /// Returns the code for the whole instruction table by walking the given
17- /// `grammar`.
16+ /// Returns the code for the whole instruction table.
1817///
19- /// `grammar ` is expected to be an array of SPIR-V instructions.
18+ /// `instructions ` is expected to be an array of SPIR-V instructions.
2019/// `name` is the name of the generated table.
2120/// `is_ext` indicates whether the grammar is for an extended instruction set.
2221pub ( crate ) fn gen_instruction_table (
23- grammar : & [ structs:: Instruction ] ,
22+ instructions : & [ structs:: Instruction ] ,
2423 ext_op_name : Option < & str > ,
2524 name : & str ,
2625) -> TokenStream {
2726 // Vector for strings for all instructions.
28- let instructions = grammar . iter ( ) . map ( |inst| {
27+ let instructions = instructions . iter ( ) . map ( |inst| {
2928 // Vector of strings for all operands.
3029 let operands = inst. operands . iter ( ) . map ( |e| {
3130 let kind = as_ident ( & e. kind ) ;
@@ -65,24 +64,33 @@ pub(crate) fn gen_instruction_table(
6564
6665/// Returns the generated grammar::INSTRUCTION_TABLE and grammar::OperandKind
6766/// by walking the given SPIR-V `grammar`.
68- pub fn gen_grammar_inst_table_operand_kinds ( grammar : & structs:: Grammar ) -> TokenStream {
67+ pub fn gen_grammar_inst_table_operand_kinds (
68+ operand_kinds : & [ structs:: OperandKind ] ,
69+ instructions : & [ structs:: Instruction ] ,
70+ ext_op_name : Option < & str > ,
71+ name : & str ,
72+ ) -> TokenStream {
6973 // Enum for all operand kinds.
70- let elements = grammar
71- . operand_kinds
72- . iter ( )
73- . map ( |kind| as_ident ( & kind. kind ) ) ;
74+ let elements = operand_kinds. iter ( ) . map ( |kind| as_ident ( & kind. kind ) ) ;
7475
7576 // Instruction table.
76- let table = gen_instruction_table ( & grammar . instructions , None , "INSTRUCTION" ) ;
77+ let table = gen_instruction_table ( instructions, ext_op_name , name ) ;
7778
78- quote ! {
79- #[ doc = "All operand kinds in the SPIR-V grammar." ]
80- #[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
81- #[ allow( clippy:: upper_case_acronyms) ]
82- pub enum OperandKind {
83- #( #elements) , *
84- }
79+ let operand_kinds = if operand_kinds. is_empty ( ) {
80+ None
81+ } else {
82+ Some ( quote ! {
83+ #[ doc = "All operand kinds in the SPIR-V grammar." ]
84+ #[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
85+ #[ allow( clippy:: upper_case_acronyms) ]
86+ pub enum OperandKind {
87+ #( #elements) , *
88+ }
89+ } )
90+ } ;
8591
92+ quote ! {
93+ #operand_kinds
8694 #table
8795 }
8896}
0 commit comments