From 454b0ffd1c94f883d3210e5e05a37f5e9f448472 Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Thu, 14 Nov 2024 21:34:31 +0100 Subject: [PATCH] adding regalloc option --- lang/src/fs.rs | 4 ++++ lang/src/son/hbvm.rs | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) 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