Commit 20b2980c authored by qinsoon's avatar qinsoon

[wip] adding frame

parent 05584663
......@@ -6,7 +6,8 @@ use compiler::backend::AOT_EMIT_DIR;
use utils::ByteSize;
use compiler::backend::x86_64;
use compiler::backend::x86_64::CodeGenerator;
use vm::MachineCode;
use compiler::machine_code::CompiledFunction;
use compiler::machine_code::MachineCode;
use vm::VM;
use utils::string_utils;
......
use ast::ptr::P;
use ast::ir::*;
use vm::MachineCode;
use compiler::machine_code::MachineCode;
pub trait CodeGenerator {
fn start_code(&mut self, func_name: MuName);
......
......@@ -9,7 +9,6 @@ use ast::op;
use ast::types;
use ast::types::*;
use vm::VM;
use vm::CompiledFunction;
use runtime;
use runtime::mm;
use runtime::ValueLocation;
......@@ -21,6 +20,8 @@ use compiler::CompilerPass;
use compiler::backend::x86_64;
use compiler::backend::x86_64::CodeGenerator;
use compiler::backend::x86_64::ASMCodeGen;
use compiler::machine_code::CompiledFunction;
use compiler::frame::Frame;
use std::collections::HashMap;
......@@ -1147,7 +1148,8 @@ impl CompilerPass for InstructionSelection {
func_id: func.func_id,
func_ver_id: func.id(),
temps: HashMap::new(),
mc: mc
mc: mc,
frame: Frame::new()
};
vm.add_compiled_func(compiled_func);
......
use compiler::CompilerPass;
use ast::ir::*;
use vm::VM;
use vm::CompiledFunction;
use compiler::machine_code::CompiledFunction;
pub struct PeepholeOptimization {
name: &'static str
......
extern crate nalgebra;
use vm::CompiledFunction;
use compiler::machine_code::CompiledFunction;
use ast::ir::*;
use ast::types;
use compiler::backend;
......
......@@ -3,6 +3,7 @@
use compiler::CompilerPass;
use compiler::PassExecutionResult;
use compiler;
use compiler::machine_code::CompiledFunction;
use ast::ir::*;
use vm::VM;
......
use ast::ir::*;
use ast::ptr::*;
use utils::LinkedHashMap;
use utils::POINTER_SIZE;
type SlotID = usize;
// | previous frame ...
// |---------------
// | return address
// | old RBP <- RBP
// | func ID
// | callee saved
// | spilled
// |---------------
// | alloca area
pub struct Frame {
cur_slot_id: SlotID,
cur_offset: isize, // offset to rbp
allocated: LinkedHashMap<SlotID, FrameSlot>,
}
impl Frame {
pub fn new() -> Frame {
Frame {
cur_slot_id: 0,
cur_offset: -POINTER_SIZE * 2, // reserve for old RBP and func ID
allocated: LinkedHashMap::new()
}
}
pub fn alloc_slot_for_callee_saved_reg(&mut self, reg: P<Value>, vm: &VM) -> P<Value> {
let slot = {
let ret = FrameSlot {
id: cur_slot_id,
offset: cur_offset,
value: reg.clone()
};
cur_slot_id += 1;
offset -= vm.get_type_size(reg.id());
ret
};
slot.make_memory_op(vm)
}
pub fn alloc_slot_for_spilling(&mut self, reg: P<Value>) -> P<Value> {
unimplemented!()
}
}
struct FrameSlot {
id: SlotID,
offset: isize,
value: P<Value>
}
impl FrameSlot {
#[cfg(target_arch = "x86_64")]
pub fn make_memory_op(&self, vm: &VM) -> P<Value> {
use compiler::backend::x86_64;
unimplemented!()
// P(Value{
// hdr: MuEntityHeader::unnamed(vm.next_id()),
// ty: reg.ty.clone(),
// v: Value_::Memory(
// MemoryLocation::Address{
// base: x86_64::RBP.clone(),
// offset:
// }
// )
// })
}
}
\ No newline at end of file
use ast::ir::*;
use compiler::frame::*;
use std::ops;
use std::collections::HashMap;
......@@ -6,7 +7,9 @@ pub struct CompiledFunction {
pub func_id: MuID,
pub func_ver_id: MuID,
pub temps: HashMap<MuID, MuID>, // assumes one temperary maps to one register
pub mc: Box<MachineCode>
pub mc: Box<MachineCode>,
pub frame: Frame
}
pub trait MachineCode {
......
......@@ -8,6 +8,8 @@ use std::sync::Arc;
pub mod passes;
pub mod backend;
pub mod frame;
pub mod machine_code;
pub use compiler::passes::CompilerPass;
pub use compiler::passes::PassExecutionResult;
......
mod vm;
mod vm_options;
mod machine_code;
pub mod api;
pub use vm::vm::VM;
pub use vm::vm_options::VMOptions;
pub use vm::machine_code::CompiledFunction;
pub use vm::machine_code::MachineCode;
......@@ -6,7 +6,7 @@ use ast::types;
use ast::types::*;
use compiler::backend;
use compiler::backend::BackendTypeInfo;
use vm::machine_code::CompiledFunction;
use compiler::machine_code::CompiledFunction;
use vm::vm_options::VMOptions;
use runtime::thread::*;
use runtime::ValueLocation;
......@@ -459,6 +459,10 @@ impl <'a> VM {
resolved
}
pub fn get_type_size(&self, tyid: MuID) -> ByteSize {
self.get_backend_type_info(tyid).size
}
pub fn globals(&self) -> &RwLock<HashMap<MuID, P<Value>>> {
&self.globals
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment