adding regalloc option

This commit is contained in:
Jakub Doka 2024-11-14 21:34:31 +01:00
parent 981c17ff19
commit 454b0ffd1c
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
2 changed files with 11 additions and 2 deletions

View file

@ -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<u8>) -> 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);

View file

@ -49,6 +49,8 @@ struct Assembler {
#[derive(Default)]
pub struct HbvmBackend {
pub use_in_house_regalloc: bool,
funcs: EntVec<ty::Func, FuncDt>,
globals: EntVec<ty::Global, GlobalDt>,
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