MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / gen_instruction_data

Function gen_instruction_data

cranelift/codegen/meta/src/gen_inst.rs:63–103  ·  view source on GitHub ↗

Generate the InstructionData enum. Every variant must contain an `opcode` field. The size of `InstructionData` should be kept at 16 bytes on 64-bit architectures. If more space is needed to represent an instruction, use a `ValueList` to store the additional information out of line.

(formats: &[Rc<InstructionFormat>], fmt: &mut Formatter)

Source from the content-addressed store, hash-verified

61/// 16 bytes on 64-bit architectures. If more space is needed to represent an instruction, use a
62/// `ValueList` to store the additional information out of line.
63fn gen_instruction_data(formats: &[Rc<InstructionFormat>], fmt: &mut Formatter) {
64 fmt.line("#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]");
65 fmt.line(r#"#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]"#);
66 fmt.line("#[allow(missing_docs, reason = \"generated code\")]");
67 fmt.add_block("pub enum InstructionData", |fmt| {
68 for format in formats {
69 fmt.add_block(&format!("{}", format.name), |fmt| {
70 fmt.line("opcode: Opcode,");
71 if format.has_value_list {
72 fmt.line("args: ValueList,");
73 } else if format.num_value_operands == 1 {
74 fmt.line("arg: Value,");
75 } else if format.num_value_operands > 0 {
76 fmtln!(fmt, "args: [Value; {}],", format.num_value_operands);
77 }
78
79 match format.num_block_operands {
80 0 => (),
81 1 => fmt.line("destination: ir::BlockCall,"),
82 2 => fmtln!(
83 fmt,
84 "blocks: [ir::BlockCall; {}],",
85 format.num_block_operands
86 ),
87 n => panic!("Too many block operands in instruction: {n}"),
88 }
89
90 match format.num_raw_block_operands {
91 0 => (),
92 1 => fmt.line("block: ir::Block,"),
93 n => panic!("Too many block operands in instruction: {n}"),
94 }
95
96 for field in &format.imm_fields {
97 fmtln!(fmt, "{}: {},", field.member, field.kind.rust_type);
98 }
99 });
100 fmtln!(fmt, ",");
101 }
102 });
103}
104
105fn gen_arguments_method(formats: &[Rc<InstructionFormat>], fmt: &mut Formatter, is_mut: bool) {
106 let (method, mut_, rslice, as_slice) = if is_mut {

Callers 1

generateFunction · 0.85

Calls 2

lineMethod · 0.45
add_blockMethod · 0.45

Tested by

no test coverage detected