MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / run_with_regalloc

Function run_with_regalloc

tests/integration/regalloc.rs:41–65  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

39// Returns the VM outcome, UART output, emitted user-code instruction count,
40// and executed cycles.
41fn 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.

Calls 13

set_write_artifactsMethod · 0.80
is_codeMethod · 0.80
collectMethod · 0.80
pushMethod · 0.80
pipeline_statsMethod · 0.80
cached_stdlib_objsFunction · 0.70
compileMethod · 0.45
assembleMethod · 0.45
runMethod · 0.45