Generate a Builder trait with methods for all instructions.
(
instructions: &AllInstructions,
formats: &[Rc<InstructionFormat>],
fmt: &mut Formatter,
)
| 1441 | |
| 1442 | /// Generate a Builder trait with methods for all instructions. |
| 1443 | fn 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 | |
| 1486 | pub(crate) fn generate( |
| 1487 | formats: &[Rc<InstructionFormat>], |
no test coverage detected