arch refactor + backend ir start

This commit is contained in:
2026-06-06 21:00:39 -04:00
parent 0ac7c5cc02
commit 4587f687b9
22 changed files with 547 additions and 661 deletions
+22 -28
View File
@@ -1,34 +1,28 @@
use crate::backend::{
program::{UnlinkedFunction, UnlinkedProgram},
symbol::Symbol,
x86_64::{Instr, instr::*, reg::*},
};
use std::{fs::OpenOptions, io::Write, os::unix::fs::OpenOptionsExt, process::Command};
use crate::{
arch::x86_64::*,
backend::{Instr as BInstr, Program},
};
pub fn test_x86_64() {
let s = b"Hello world!\n";
let program = UnlinkedProgram {
fns: vec![UnlinkedFunction {
instrs: vec![
mov(rax, 1),
mov(rdi, 1),
lea(rsi, Symbol::raw(1)),
mov(rdx, s.len() as u64),
Instr::Syscall,
mov(rax, 0x3c),
mov(rdi, 39),
Instr::Syscall,
],
sym: Symbol::raw(0),
locations: Default::default(),
}],
ro_data: vec![(s.to_vec(), Symbol::raw(1))],
sym_count: 2,
start: Some(Symbol::raw(0)),
};
let Ok(linked) = program.link() else {
panic!("failed to link");
};
let mut program = Program::<X86_64>::default();
let text = b"Hello world!\n";
let text_sym = program.ro_data(text);
let entry = program.func([BInstr::Asm(Asm {
instrs: vec![
mov(ax, 1),
mov(di, 1),
lea(rsi, text_sym),
mov(dx, text.len() as u64),
Instr::Syscall,
mov(ax, 0x3c),
mov(di, 39),
Instr::Syscall,
],
})]);
program.entry = Some(entry);
let linked = program.compile().expect("failed to compile");
let binary = linked.to_elf();
let path = "./x86_64_test";
let mut file = OpenOptions::new()