Build a minimal pass/fail IR program around an entry block. `entry` must not yet have a terminator; this adds the branch, a pass block (return 0), and a fail block (return 1).
(module: &str, mut entry: IrBlock, cond: IrValue)
| 81 | let i32_ty = IrType::Integer(IntWidth::I32); |
| 82 | let mut program = IrProgram::new(module); |
| 83 | let mut func = IrFunction::new("main", i32_ty.clone()); |
| 84 | |
| 85 | entry.set_terminator(IrTerminator::Branch { |
| 86 | cond, |
| 87 | then_label: IrLabel::new("pass"), |
| 88 | else_label: IrLabel::new("fail"), |
| 89 | }); |
| 90 | |
| 91 | let mut pass_block = IrBlock::new("pass"); |
| 92 | pass_block.set_terminator(IrTerminator::Return(Some(IrValue::Integer(0)))); |
| 93 | |
| 94 | let mut fail_block = IrBlock::new("fail"); |
| 95 | fail_block.set_terminator(IrTerminator::Return(Some(IrValue::Integer(1)))); |
| 96 | |
| 97 | func.push_block(entry); |
| 98 | func.push_block(pass_block); |
| 99 | func.push_block(fail_block); |
| 100 | program.push_function(func); |
| 101 | program |
| 102 | } |
| 103 | |
| 104 | fn run_hll_file(path: &str) -> (VirtualMachine, StepOutcome, String) { |
| 105 | let manifest = env!("CARGO_MANIFEST_DIR"); |
| 106 | let full_path = std::path::Path::new(manifest).join(path); |
| 107 | let src = std::fs::read_to_string(&full_path) |
| 108 | .unwrap_or_else(|e| panic!("failed to read {path}: {e}")); |