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

Function gen_builder

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

Generate a Builder trait with methods for all instructions.

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

Source from the content-addressed store, hash-verified

1441
1442/// Generate a Builder trait with methods for all instructions.
1443fn gen_builder(
1444 instructions: &AllInstructions,
1445 formats: &[Rc<InstructionFormat>],
1446 fmt: &mut Formatter,
1447) {
1448 fmt.doc_comment(
1449 r#"
1450 Convenience methods for building instructions.
1451
1452 The `InstBuilder` trait has one method per instruction opcode for
1453 conveniently constructing the instruction with minimum arguments.
1454 Polymorphic instructions infer their result types from the input
1455 arguments when possible. In some cases, an explicit `ctrl_typevar`
1456 argument is required.
1457
1458 The opcode methods return the new instruction's result values, or
1459 the `Inst` itself for instructions that don't have any results.
1460
1461 There is also a method per instruction format. These methods all
1462 return an `Inst`.
1463
1464 When an address to a load or store is specified, its integer
1465 size is required to be equal to the platform's pointer width.
1466 "#,
1467 );
1468 fmt.add_block("pub trait InstBuilder<'f>: InstBuilderBase<'f>", |fmt| {
1469 for inst in instructions.iter() {
1470 gen_inst_builder(inst, &inst.format, fmt);
1471 fmt.empty_line();
1472 if inst.inst_builder_imm_method {
1473 gen_imm_inst_builder(inst, fmt);
1474 fmt.empty_line();
1475 }
1476 }
1477 for (i, format) in formats.iter().enumerate() {
1478 gen_format_constructor(format, fmt);
1479 if i + 1 != formats.len() {
1480 fmt.empty_line();
1481 }
1482 }
1483 });
1484}
1485
1486pub(crate) fn generate(
1487 formats: &[Rc<InstructionFormat>],

Callers 1

generateFunction · 0.85

Calls 8

gen_inst_builderFunction · 0.85
gen_imm_inst_builderFunction · 0.85
gen_format_constructorFunction · 0.85
doc_commentMethod · 0.80
empty_lineMethod · 0.80
add_blockMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected