Stdlib compiled once per flag setting (the flag changes its codegen too). Each module is its own object (no source concatenation).
(regalloc: bool)
| 14 | // Stdlib compiled once per flag setting (the flag changes its codegen too). |
| 15 | // Each module is its own object (no source concatenation). |
| 16 | fn cached_stdlib_objs(regalloc: bool) -> &'static [(String, AssembledOutput)] { |
| 17 | static STDLIB_OFF: OnceLock<Vec<(String, AssembledOutput)>> = OnceLock::new(); |
| 18 | static STDLIB_ON: OnceLock<Vec<(String, AssembledOutput)>> = OnceLock::new(); |
| 19 | let cell = if regalloc { &STDLIB_ON } else { &STDLIB_OFF }; |
| 20 | cell.get_or_init(|| { |
| 21 | let mut pipeline = CompilationPipeline::new(); |
| 22 | pipeline.set_write_artifacts(false); |
| 23 | pipeline.set_register_allocation(regalloc); |
| 24 | pipeline.set_type_prelude(get_stdlib_type_prelude()); |
| 25 | get_stdlib_modules_for_mode(TargetMode::Hosted) |
| 26 | .iter() |
| 27 | .map(|(name, src)| { |
| 28 | let r = pipeline.compile(src).expect("stdlib compile failed"); |
| 29 | let (_, tokens) = pipeline.compile_ir_to_assembly_with_tokens(&r.ir_program); |
| 30 | let obj = pipeline |
| 31 | .assemble_named(name, &tokens) |
| 32 | .expect("stdlib assemble failed"); |
| 33 | ((*name).to_owned(), obj) |
| 34 | }) |
| 35 | .collect() |
| 36 | }) |
| 37 | } |
| 38 | |
| 39 | // Returns the VM outcome, UART output, emitted user-code instruction count, |
| 40 | // and executed cycles. |