arbitrary addr

This commit is contained in:
2026-06-06 21:19:09 -04:00
parent 4587f687b9
commit ef35509c98
8 changed files with 35 additions and 18 deletions
+4 -4
View File
@@ -1,13 +1,13 @@
use super::*;
use crate::backend::{Addr, LinkedProgram, SymTable, Symbol};
use crate::backend::{LinkedProgram, SymTable, Symbol};
pub struct Encoder {
pub data: Vec<u8>,
pub sym_tab: SymTable,
pub sym_tab: SymTable<u64>,
pub missing: Vec<(usize, Symbol)>,
}
pub fn encode_program(p: &Program<X86_64>) -> Result<LinkedProgram, CompilerMsg> {
pub fn encode_program(p: &Program<X86_64>) -> Result<LinkedProgram<u64>, CompilerMsg> {
let mut encoder = Encoder::new(p.sym_count());
p.encode_data(&mut encoder.data, &mut encoder.sym_tab);
@@ -124,7 +124,7 @@ impl Encoder {
}
/// assumes the next instruction is directly after
fn addr_offset(pos: usize, addr: Addr) -> [u8; 4] {
fn addr_offset(pos: usize, addr: u64) -> [u8; 4] {
let pos = (pos + 4) as i32;
let offset = addr as i32 - pos;
offset.to_le_bytes()