/// Returns the generated build methods for SPIR-V types by walking the given
/// SPIR-V instructions `grammar`.
Returns the generated build methods for SPIR-V types by walking the given
SPIR-V instructions `grammar`.
Returns the generated build methods for SPIR - V types by walking the given SPIR - V instructions ` grammar ` .
pub fn gen_dr_builder_types(grammar: &structs::Grammar) -> TokenStream {
    let kinds = &grammar.operand_kinds;
    // Generate build methods for all types.
    let elements = grammar.instructions.iter().filter(|inst| {
        inst.class == Some(structs::Class::Type) && inst.opname != "OpTypeForwardPointer" &&
            inst.opname != "OpTypePointer" && inst.opname != "OpTypeOpaque"
    }).map(|inst| {
        // Parameter list for this build method.
        let param_list = get_param_list(&inst.operands, false, kinds);
        // Initializer list for constructing the operands parameter
        // for Instruction.
        let init_list = get_init_list(&inst.operands[1..]);
        // Parameters that are not single values thus need special treatment.
        let extras = get_push_extras(&inst.operands[1..],
                                     kinds,
                                     quote! { inst.operands });
        let opcode = as_ident(&inst.opname[2..]);
        let name = as_ident(&inst.opname[2..].to_snake_case());
        let comment = format!("Appends an Op{} instruction and returns the result id, or return the existing id if the instruction was already present.", opcode);
        quote! {
            #[doc = #comment]
            pub fn #name(&mut self,#(#param_list),*) -> spirv::Word {
                let mut inst = dr::Instruction::new(spirv::Op::#opcode, None, None, vec![#(#init_list),*]);
                #(#extras)*
                if let Some(id) = self.dedup_insert_type(&inst) {
                    id
                } else {
                    let new_id = self.id();
                    inst.result_id = Some(new_id);
                    self.module.types_global_values.push(inst);
                    new_id
                }
            }
        }
    });
    quote! {
        impl Builder {
            #(#elements)*
        }
    }
}
pub fn gen_dr_builder_types ( grammar : & structs :: Grammar ) -> TokenStream { let kinds = & grammar . operand_kinds ; // Generate build methods for all types. let elements = grammar . instructions . iter ( ) . filter ( | inst | { inst . class == Some ( structs :: Class :: Type ) && inst . opname != " " && inst . opname != " " && inst . opname != " " } ) . map ( | inst | { // Parameter list for this build method. let param_list = get_param_list ( & inst . operands , false , kinds ) ; // Initializer list for constructing the operands parameter // for Instruction. let init_list = get_init_list ( & inst . operands [ 1 .. ] ) ; // Parameters that are not single values thus need special treatment. let extras = get_push_extras ( & inst . operands [ 1 .. ] , kinds , quote ! { inst operands } ) ; let opcode = as_ident ( & inst . opname [ 2 .. ] ) ; let name = as_ident ( & inst . opname [ 2 .. ] . to_snake_case ( ) ) ; let comment = format ! ( " " opcode ) ; quote ! { [ doc comment ] pub fn name ( mut self ( param_list ) ) spirv Word { let mut inst dr Instruction new ( spirv Op opcode None None vec [ ( init_list ) ] ) ( extras ) if let Some ( id ) self dedup_insert_type ( inst ) { id } else { let new_id self id ( ) inst result_id Some ( new_id ) self module types_global_values push ( inst ) new_id } } } } ) ; quote ! { impl Builder { ( elements ) } } }
Returns the generated build methods for SPIR-V types by walking the given
SPIR-V instructions `grammar`.
Returns the generated build methods for SPIR - V types by walking the given SPIR - V instructions ` grammar ` .
grammar
&structs::Grammar