Compile and run with register allocation on or off; returns the VM outcome, UART output, emitted user-code instruction count, and executed cycles.
(src: &str, regalloc: bool)
| 39 | // Returns the VM outcome, UART output, emitted user-code instruction count, |
| 40 | // and executed cycles. |
| 41 | fn run_with_regalloc(src: &str, regalloc: bool) -> (StepOutcome, String, usize, u64) { |
| 42 | let mut pipeline = CompilationPipeline::new(); |
| 43 | pipeline.set_write_artifacts(false); |
| 44 | pipeline.set_register_allocation(regalloc); |
| 45 | |
| 46 | let user_result = pipeline.compile(src).expect("user compile failed"); |
| 47 | let (_, user_tokens) = pipeline.compile_ir_to_assembly_with_tokens(&user_result.ir_program); |
| 48 | let code_lines = user_tokens.iter().filter(|t| t.is_code()).count(); |
| 49 | let user_obj = pipeline |
| 50 | .assemble(&user_tokens) |
| 51 | .expect("user assemble failed"); |
| 52 | |
| 53 | let mut modules: Vec<(&str, &AssembledOutput)> = cached_stdlib_objs(regalloc) |
| 54 | .iter() |
| 55 | .map(|(n, o)| (n.as_str(), o)) |
| 56 | .collect(); |
| 57 | modules.push(("user", &user_obj)); |
| 58 | let assembled = pipeline |
| 59 | .link_assembled_objects(&modules) |
| 60 | .expect("link failed"); |
| 61 | let mut vm = VirtualMachine::new(&assembled); |
| 62 | let run = vm.run(20_000_000); |
| 63 | let cycles = vm.pipeline_stats().cycles; |
| 64 | (run.outcome, run.uart_output.clone(), code_lines, cycles) |
| 65 | } |
| 66 | |
| 67 | // Asserts identical behaviour with allocation off and on, and returns the |
| 68 | // (off, on) instruction and cycle counts for extra checks. |