work
This commit is contained in:
+35
-8
@@ -1,6 +1,8 @@
|
||||
mod addr;
|
||||
mod id;
|
||||
mod symbol;
|
||||
pub use addr::*;
|
||||
pub use id::*;
|
||||
pub use symbol::*;
|
||||
|
||||
use crate::{arch::Arch, backend::LinkedProgram, io::CompilerMsg};
|
||||
@@ -10,6 +12,7 @@ pub struct Program<A: Arch> {
|
||||
pub funcs: Vec<Func<A>>,
|
||||
pub entry: Option<Symbol>,
|
||||
pub external: Vec<External>,
|
||||
pub call_convs: Vec<A::CallConv>,
|
||||
|
||||
sym_info: Vec<SymInfo>,
|
||||
sym_count: usize,
|
||||
@@ -21,8 +24,10 @@ pub struct Data {
|
||||
}
|
||||
|
||||
pub struct Func<A: Arch> {
|
||||
pub instrs: Vec<Instr<A>>,
|
||||
pub params: Vec<VarId>,
|
||||
pub body: Body<A>,
|
||||
pub sym: Symbol,
|
||||
pub conv: usize,
|
||||
}
|
||||
|
||||
pub struct External {
|
||||
@@ -35,16 +40,38 @@ pub struct SymInfo {
|
||||
pub external: bool,
|
||||
}
|
||||
|
||||
pub type Body<A> = Vec<Instr<A>>;
|
||||
|
||||
pub enum Instr<A: Arch> {
|
||||
Set { dst: VarId, src: Vec<u8> },
|
||||
Call { dst: FnId, args: Vec<VarId> },
|
||||
Copy { dst: VarId, src: VarId },
|
||||
Set {
|
||||
dst: VarId,
|
||||
src: Vec<u8>,
|
||||
},
|
||||
Call {
|
||||
dst: VarId,
|
||||
f: FnId,
|
||||
args: Vec<VarId>,
|
||||
},
|
||||
Copy {
|
||||
dst: VarId,
|
||||
src: VarId,
|
||||
},
|
||||
Add {
|
||||
dst: VarId,
|
||||
src1: VarId,
|
||||
src2: VarId,
|
||||
},
|
||||
If {
|
||||
cond: VarId,
|
||||
then: Body<A>,
|
||||
else_: Body<A>,
|
||||
},
|
||||
Loop(Body<A>),
|
||||
Return(Option<VarId>),
|
||||
Break(Option<VarId>),
|
||||
Asm(A::Asm),
|
||||
}
|
||||
|
||||
pub type VarId = usize;
|
||||
pub type FnId = usize;
|
||||
|
||||
impl<A: Arch> Program<A> {
|
||||
pub fn encode_data(&self, data: &mut Vec<u8>, sym_tab: &mut SymTable<A::Addr>) {
|
||||
for d in &self.ro_data {
|
||||
@@ -70,7 +97,7 @@ impl<A: Arch> Program<A> {
|
||||
name: name.into(),
|
||||
external: false,
|
||||
});
|
||||
self.funcs.push(Func { instrs, sym });
|
||||
self.funcs.push(Func { body: instrs, sym });
|
||||
sym
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user