Compile a user program with IR optimization on or off, returning the VM run (exit outcome + UART) and the emitted instruction count.
(src: &str, opts: hll_to_ir::OptOptions)
| 361 | let primary = r#" |
| 362 | boxlib := import("boxlib") |
| 363 | main: () -> i32 { |
| 364 | holder: boxlib.Box<i32> = { .value = 42 } |
| 365 | return boxlib.unwrap<i32>(&holder) |
| 366 | } |
| 367 | "#; |
| 368 | let closure = pipeline |
| 369 | .compile_program_closure("user", primary) |
| 370 | .expect("closure compile failed"); |
| 371 | |
| 372 | let mut modules: Vec<(&str, &AssembledOutput)> = cached_stdlib_objs() |
| 373 | .iter() |
| 374 | .map(|(n, o)| (n.as_str(), o)) |
| 375 | .collect(); |
| 376 | for (name, obj) in &closure { |
| 377 | modules.push((name.as_str(), obj)); |
| 378 | } |
| 379 | let assembled = pipeline |
| 380 | .link_assembled_objects(&modules) |
| 381 | .expect("link failed"); |
| 382 | let mut vm = VirtualMachine::new(&assembled); |
| 383 | let run = vm.run(5_000_000); |
| 384 | assert!( |