diff --git a/lang/src/fs.rs b/lang/src/fs.rs index 0768ba8b..82941a66 100644 --- a/lang/src/fs.rs +++ b/lang/src/fs.rs @@ -39,6 +39,7 @@ pub struct Options { pub fmt: bool, pub fmt_stdout: bool, pub dump_asm: bool, + pub in_house_regalloc: bool, pub extra_threads: usize, } @@ -54,6 +55,7 @@ impl Options { fmt: args.contains(&"--fmt"), fmt_stdout: args.contains(&"--fmt-stdout"), dump_asm: args.contains(&"--dump-asm"), + in_house_regalloc: args.contains(&"--in-house-regalloc"), extra_threads: args .iter() .position(|&a| a == "--threads") @@ -92,6 +94,8 @@ pub fn run_compiler(root_file: &str, options: Options, out: &mut Vec) -> std write!(out, "{}", &parsed.ast[0])?; } else { let mut backend = HbvmBackend::default(); + backend.use_in_house_regalloc = options.in_house_regalloc; + let mut ctx = crate::son::CodegenCtx::default(); *ctx.parser.errors.get_mut() = parsed.errors; let mut codegen = son::Codegen::new(&mut backend, &parsed.ast, &mut ctx); diff --git a/lang/src/son/hbvm.rs b/lang/src/son/hbvm.rs index 1a79b6de..e5266e49 100644 --- a/lang/src/son/hbvm.rs +++ b/lang/src/son/hbvm.rs @@ -49,6 +49,8 @@ struct Assembler { #[derive(Default)] pub struct HbvmBackend { + pub use_in_house_regalloc: bool, + funcs: EntVec, globals: EntVec, asm: Assembler, @@ -258,8 +260,11 @@ impl Backend for HbvmBackend { nodes[MEM].outputs = mems; } - let (saved, tail) = self.emit_body_code(nodes, sig, tys, files); - //let (saved, tail) = self.emit_body_code_my(nodes, sig, tys, files); + let (saved, tail) = if self.use_in_house_regalloc { + self.emit_body_code_my(nodes, sig, tys, files) + } else { + self.emit_body_code(nodes, sig, tys, files) + }; if let Some(last_ret) = self.ret_relocs.last() && last_ret.offset as usize == self.code.len() - 5