IMPORTS WORKING
This commit is contained in:
+27
-7
@@ -11,6 +11,7 @@ pub struct Program<A: Arch> {
|
||||
pub entry: Option<Symbol>,
|
||||
pub external: Vec<External>,
|
||||
|
||||
sym_info: Vec<SymInfo>,
|
||||
sym_count: usize,
|
||||
}
|
||||
|
||||
@@ -29,6 +30,11 @@ pub struct External {
|
||||
pub syms: Vec<Symbol>,
|
||||
}
|
||||
|
||||
pub struct SymInfo {
|
||||
pub name: String,
|
||||
pub external: bool,
|
||||
}
|
||||
|
||||
pub enum Instr<A: Arch> {
|
||||
Set { dst: VarId, src: Vec<u8> },
|
||||
Call { dst: FnId, args: Vec<VarId> },
|
||||
@@ -48,16 +54,22 @@ impl<A: Arch> Program<A> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ro_data(&mut self, bytes: impl Into<Vec<u8>>) -> Symbol {
|
||||
pub fn ro_data(&mut self, name: impl Into<String>, bytes: impl Into<Vec<u8>>) -> Symbol {
|
||||
let bytes = bytes.into();
|
||||
let sym = self.reserve();
|
||||
let sym = self.reserve(SymInfo {
|
||||
name: name.into(),
|
||||
external: false,
|
||||
});
|
||||
self.ro_data.push(Data { bytes, sym });
|
||||
sym
|
||||
}
|
||||
|
||||
pub fn func(&mut self, instrs: impl Into<Vec<Instr<A>>>) -> Symbol {
|
||||
pub fn func(&mut self, name: impl Into<String>, instrs: impl Into<Vec<Instr<A>>>) -> Symbol {
|
||||
let instrs = instrs.into();
|
||||
let sym = self.reserve();
|
||||
let sym = self.reserve(SymInfo {
|
||||
name: name.into(),
|
||||
external: false,
|
||||
});
|
||||
self.funcs.push(Func { instrs, sym });
|
||||
sym
|
||||
}
|
||||
@@ -68,8 +80,10 @@ impl<A: Arch> Program<A> {
|
||||
names: [impl Into<String>; LEN],
|
||||
) -> [Symbol; LEN] {
|
||||
let syms = names.map(|s| {
|
||||
let sym = self.reserve();
|
||||
sym
|
||||
self.reserve(SymInfo {
|
||||
name: s.into(),
|
||||
external: true,
|
||||
})
|
||||
});
|
||||
self.external.push(External {
|
||||
file: file.into(),
|
||||
@@ -78,8 +92,9 @@ impl<A: Arch> Program<A> {
|
||||
syms
|
||||
}
|
||||
|
||||
fn reserve(&mut self) -> Symbol {
|
||||
fn reserve(&mut self, info: SymInfo) -> Symbol {
|
||||
let res = Symbol(self.sym_count);
|
||||
self.sym_info.push(info);
|
||||
self.sym_count += 1;
|
||||
res
|
||||
}
|
||||
@@ -91,6 +106,10 @@ impl<A: Arch> Program<A> {
|
||||
pub fn sym_count(&self) -> usize {
|
||||
self.sym_count
|
||||
}
|
||||
|
||||
pub fn sym_info(&self, sym: Symbol) -> &SymInfo {
|
||||
&self.sym_info[sym.0]
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: Arch> Default for Program<A> {
|
||||
@@ -101,6 +120,7 @@ impl<A: Arch> Default for Program<A> {
|
||||
entry: Default::default(),
|
||||
sym_count: Default::default(),
|
||||
external: Default::default(),
|
||||
sym_info: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user