arbitrary addr
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -19,7 +19,8 @@ pub struct X86_64;
|
||||
impl Arch for X86_64 {
|
||||
const NAME: &str = "x86_64";
|
||||
type Asm = Asm;
|
||||
fn compile(p: &Program<Self>) -> Result<LinkedProgram, CompilerMsg> {
|
||||
type Addr = u64;
|
||||
fn compile(p: &Program<Self>) -> Result<LinkedProgram<Self::Addr>, CompilerMsg> {
|
||||
encode_program(p)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user