Commit c626fc25 authored by qinsoon's avatar qinsoon

[wip] keep refactoring

parent 76504d0b
build_targets=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>\n<build_targets xmlns\="com.github.rustdt.ide.core">\n<target auto_enabled\="false" config\="build" n_enabled\="true" version2\="true"/>\n<target auto_enabled\="true" config\="check" n_enabled\="false" version2\="true">\n<command_invocation append_env\="true" command_arguments\="${CARGO_TOOL_PATH} build">\n<env_vars/>\n</command_invocation>\n</target>\n</build_targets>\n build_targets=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>\n<build_targets xmlns\="com.github.rustdt.ide.core">\n<target auto_enabled\="true" config\="build" n_enabled\="true" version2\="true"/>\n<target auto_enabled\="false" config\="check" n_enabled\="false" version2\="true">\n<command_invocation append_env\="true" command_arguments\="${CARGO_TOOL_PATH} build">\n<env_vars/>\n</command_invocation>\n</target>\n</build_targets>\n
eclipse.preferences.version=1 eclipse.preferences.version=1
...@@ -346,7 +346,7 @@ impl ResumptionData { ...@@ -346,7 +346,7 @@ impl ResumptionData {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Destination { pub struct Destination {
pub target: MuName, pub target: MuID,
pub args: Vec<DestArg> pub args: Vec<DestArg>
} }
......
...@@ -19,16 +19,19 @@ pub type OpIndex = usize; ...@@ -19,16 +19,19 @@ pub type OpIndex = usize;
#[derive(Debug)] #[derive(Debug)]
pub struct MuFunction { pub struct MuFunction {
pub fn_name: MuName, pub id: MuID,
pub name: Option<MuName>,
pub sig: P<MuFuncSig>, pub sig: P<MuFuncSig>,
pub cur_ver: Option<MuName>, pub cur_ver: Option<MuID>,
pub all_vers: Vec<MuName> pub all_vers: Vec<MuID>
} }
impl MuFunction { impl MuFunction {
pub fn new(fn_name: MuName, sig: P<MuFuncSig>) -> MuFunction { pub fn new(id: MuID, sig: P<MuFuncSig>) -> MuFunction {
MuFunction { MuFunction {
fn_name: fn_name, id: id,
name: None,
sig: sig, sig: sig,
cur_ver: None, cur_ver: None,
all_vers: vec![] all_vers: vec![]
...@@ -36,25 +39,47 @@ impl MuFunction { ...@@ -36,25 +39,47 @@ impl MuFunction {
} }
} }
impl fmt::Display for MuFunction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.name.is_none() {
write!(f, "Func #{}", self.id)
} else {
write!(f, "Func {}#{}", self.name.unwrap(), self.id)
}
}
}
#[derive(Debug)] #[derive(Debug)]
pub struct MuFunctionVersion { pub struct MuFunctionVersion {
pub fn_name: MuName, pub id: MuID,
pub version: MuName, pub name: Option<MuName>,
pub func_id: MuID,
pub sig: P<MuFuncSig>, pub sig: P<MuFuncSig>,
pub content: Option<FunctionContent>, pub content: Option<FunctionContent>,
pub context: FunctionContext, pub context: FunctionContext,
pub block_trace: Option<Vec<MuName>> // only available after Trace Generation Pass pub block_trace: Option<Vec<MuID>> // only available after Trace Generation Pass
}
impl fmt::Display for MuFunctionVersion {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.name.is_none() {
write!(f, "FuncVer #{} of Func#{}", self.id, self.func_id)
} else {
write!(f, "FuncVer {}#{} of Func#{}", self.name.unwrap(), self.id, self.func_id)
}
}
} }
pub const RESERVED_NODE_IDS_FOR_MACHINE : usize = 100; pub const RESERVED_NODE_IDS_FOR_MACHINE : usize = 100;
impl MuFunctionVersion { impl MuFunctionVersion {
pub fn new(fn_name: MuName, ver: MuName, sig: P<MuFuncSig>) -> MuFunctionVersion { pub fn new(id: MuID, func: MuID, sig: P<MuFuncSig>) -> MuFunctionVersion {
MuFunctionVersion{ MuFunctionVersion{
fn_name: fn_name, id: id,
version: ver, name: None,
func_id: func,
sig: sig, sig: sig,
content: None, content: None,
context: FunctionContext::new(), context: FunctionContext::new(),
...@@ -71,6 +96,7 @@ impl MuFunctionVersion { ...@@ -71,6 +96,7 @@ impl MuFunctionVersion {
P(TreeNode { P(TreeNode {
id: id, id: id,
name: None,
op: pick_op_code_for_ssa(&ty), op: pick_op_code_for_ssa(&ty),
v: TreeNode_::Value(P(Value{ v: TreeNode_::Value(P(Value{
tag: tag, tag: tag,
...@@ -83,6 +109,7 @@ impl MuFunctionVersion { ...@@ -83,6 +109,7 @@ impl MuFunctionVersion {
pub fn new_constant(&mut self, id: MuID, v: P<Value>) -> P<TreeNode> { pub fn new_constant(&mut self, id: MuID, v: P<Value>) -> P<TreeNode> {
P(TreeNode{ P(TreeNode{
id: id, id: id,
name: None,
op: pick_op_code_for_value(&v.ty), op: pick_op_code_for_value(&v.ty),
v: TreeNode_::Value(v) v: TreeNode_::Value(v)
}) })
...@@ -91,6 +118,7 @@ impl MuFunctionVersion { ...@@ -91,6 +118,7 @@ impl MuFunctionVersion {
pub fn new_global(&mut self, id: MuID, v: P<Value>) -> P<TreeNode> { pub fn new_global(&mut self, id: MuID, v: P<Value>) -> P<TreeNode> {
P(TreeNode{ P(TreeNode{
id: id, id: id,
name: None,
op: pick_op_code_for_value(&v.ty), op: pick_op_code_for_value(&v.ty),
v: TreeNode_::Value(v) v: TreeNode_::Value(v)
}) })
...@@ -99,6 +127,7 @@ impl MuFunctionVersion { ...@@ -99,6 +127,7 @@ impl MuFunctionVersion {
pub fn new_inst(&mut self, id: MuID, v: Instruction) -> P<TreeNode> { pub fn new_inst(&mut self, id: MuID, v: Instruction) -> P<TreeNode> {
P(TreeNode{ P(TreeNode{
id: id, id: id,
name: None,
op: pick_op_code_for_inst(&v), op: pick_op_code_for_inst(&v),
v: TreeNode_::Instruction(v), v: TreeNode_::Instruction(v),
}) })
...@@ -107,33 +136,33 @@ impl MuFunctionVersion { ...@@ -107,33 +136,33 @@ impl MuFunctionVersion {
#[derive(Debug)] #[derive(Debug)]
pub struct FunctionContent { pub struct FunctionContent {
pub entry: MuName, pub entry: MuID,
pub blocks: HashMap<MuName, Block> pub blocks: HashMap<MuID, Block>
} }
impl FunctionContent { impl FunctionContent {
pub fn get_entry_block(&self) -> &Block { pub fn get_entry_block(&self) -> &Block {
self.get_block(self.entry) self.get_block(self.entry)
} }
pub fn get_entry_block_mut(&mut self) -> &mut Block { pub fn get_entry_block_mut(&mut self) -> &mut Block {
let entry = self.entry; let entry = self.entry;
self.get_block_mut(entry) self.get_block_mut(entry)
} }
pub fn get_block(&self, tag: MuName) -> &Block { pub fn get_block(&self, id: MuID) -> &Block {
let ret = self.blocks.get(tag); let ret = self.blocks.get(&id);
match ret { match ret {
Some(b) => b, Some(b) => b,
None => panic!("cannot find block {}", tag) None => panic!("cannot find block #{}", id)
} }
} }
pub fn get_block_mut(&mut self, tag: MuName) -> &mut Block { pub fn get_block_mut(&mut self, id: MuID) -> &mut Block {
let ret = self.blocks.get_mut(tag); let ret = self.blocks.get_mut(&id);
match ret { match ret {
Some(b) => b, Some(b) => b,
None => panic!("cannot find block {}", tag) None => panic!("cannot find block #{}", id)
} }
} }
} }
...@@ -179,25 +208,26 @@ impl FunctionContext { ...@@ -179,25 +208,26 @@ impl FunctionContext {
#[derive(Debug)] #[derive(Debug)]
pub struct Block { pub struct Block {
pub label: MuName, pub id: MuID,
pub name: Option<MuName>,
pub content: Option<BlockContent>, pub content: Option<BlockContent>,
pub control_flow: ControlFlow pub control_flow: ControlFlow
} }
impl Block { impl Block {
pub fn new(label: MuName) -> Block { pub fn new(id: MuID) -> Block {
Block{label: label, content: None, control_flow: ControlFlow::default()} Block{id: id, name: None, content: None, control_flow: ControlFlow::default()}
} }
} }
#[derive(Debug)] #[derive(Debug)]
pub struct ControlFlow { pub struct ControlFlow {
pub preds : Vec<MuName>, pub preds : Vec<MuID>,
pub succs : Vec<BlockEdge> pub succs : Vec<BlockEdge>
} }
impl ControlFlow { impl ControlFlow {
pub fn get_hottest_succ(&self) -> Option<MuName> { pub fn get_hottest_succ(&self) -> Option<MuID> {
if self.succs.len() == 0 { if self.succs.len() == 0 {
None None
} else { } else {
...@@ -231,7 +261,7 @@ impl default::Default for ControlFlow { ...@@ -231,7 +261,7 @@ impl default::Default for ControlFlow {
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub struct BlockEdge { pub struct BlockEdge {
pub target: MuName, pub target: MuID,
pub kind: EdgeKind, pub kind: EdgeKind,
pub is_exception: bool, pub is_exception: bool,
pub probability: f32 pub probability: f32
...@@ -330,6 +360,7 @@ impl BlockContent { ...@@ -330,6 +360,7 @@ impl BlockContent {
/// always use with P<TreeNode> /// always use with P<TreeNode>
pub struct TreeNode { pub struct TreeNode {
pub id: MuID, pub id: MuID,
pub name: Option<MuName>,
pub op: OpCode, pub op: OpCode,
pub v: TreeNode_, pub v: TreeNode_,
} }
...@@ -339,6 +370,7 @@ impl TreeNode { ...@@ -339,6 +370,7 @@ impl TreeNode {
pub fn new_inst(id: MuID, v: Instruction) -> P<TreeNode> { pub fn new_inst(id: MuID, v: Instruction) -> P<TreeNode> {
P(TreeNode{ P(TreeNode{
id: id, id: id,
name: None,
op: pick_op_code_for_inst(&v), op: pick_op_code_for_inst(&v),
v: TreeNode_::Instruction(v), v: TreeNode_::Instruction(v),
}) })
......
...@@ -920,82 +920,93 @@ impl CodeGenerator for ASMCodeGen { ...@@ -920,82 +920,93 @@ impl CodeGenerator for ASMCodeGen {
unimplemented!() unimplemented!()
} }
fn emit_jmp(&mut self, dest: &Destination) { fn emit_jmp(&mut self, dest: &Block) {
trace!("emit: jmp {}", dest.target); let dest_name = dest.name.unwrap();
trace!("emit: jmp {}", dest_name);
// symbolic label, we dont need to patch it // symbolic label, we dont need to patch it
let asm = format!("jmp {}", self.asm_block_label(dest.target)); let asm = format!("jmp {}", self.asm_block_label(dest_name));
self.add_asm_branch(asm, dest.target) self.add_asm_branch(asm, dest_name)
} }
fn emit_je(&mut self, dest: &Destination) { fn emit_je(&mut self, dest: &Block) {
trace!("emit: je {}", dest.target); let dest_name = dest.name.unwrap();
trace!("emit: je {}", dest_name);
let asm = format!("je {}", self.asm_block_label(dest.target)); let asm = format!("je {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest.target); self.add_asm_branch2(asm, dest_name);
} }
fn emit_jne(&mut self, dest: &Destination) { fn emit_jne(&mut self, dest: &Block) {
trace!("emit: jne {}", dest.target); let dest_name = dest.name.unwrap();
trace!("emit: jne {}", dest_name);
let asm = format!("jne {}", self.asm_block_label(dest.target)); let asm = format!("jne {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest.target); self.add_asm_branch2(asm, dest_name);
} }
fn emit_ja(&mut self, dest: &Destination) { fn emit_ja(&mut self, dest: &Block) {
trace!("emit: ja {}", dest.target); let dest_name = dest.name.unwrap();
trace!("emit: ja {}", dest_name);
let asm = format!("ja {}", self.asm_block_label(dest.target)); let asm = format!("ja {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest.target); self.add_asm_branch2(asm, dest_name);
} }
fn emit_jae(&mut self, dest: &Destination) { fn emit_jae(&mut self, dest: &Block) {
trace!("emit: jae {}", dest.target); let dest_name = dest.name.unwrap();
trace!("emit: jae {}", dest_name);
let asm = format!("jae {}", self.asm_block_label(dest.target)); let asm = format!("jae {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest.target); self.add_asm_branch2(asm, dest_name);
} }
fn emit_jb(&mut self, dest: &Destination) { fn emit_jb(&mut self, dest: &Block) {
trace!("emit: jb {}", dest.target); let dest_name = dest.name.unwrap();
trace!("emit: jb {}", dest_name);
let asm = format!("jb {}", self.asm_block_label(dest.target)); let asm = format!("jb {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest.target); self.add_asm_branch2(asm, dest_name);
} }
fn emit_jbe(&mut self, dest: &Destination) { fn emit_jbe(&mut self, dest: &Block) {
trace!("emit: jbe {}", dest.target); let dest_name = dest.name.unwrap();
trace!("emit: jbe {}", dest_name);
let asm = format!("jbe {}", self.asm_block_label(dest.target)); let asm = format!("jbe {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest.target); self.add_asm_branch2(asm, dest_name);
} }
fn emit_jg(&mut self, dest: &Destination) { fn emit_jg(&mut self, dest: &Block) {
trace!("emit: jg {}", dest.target); let dest_name = dest.name.unwrap();
trace!("emit: jg {}", dest_name);
let asm = format!("jg {}", self.asm_block_label(dest.target)); let asm = format!("jg {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest.target); self.add_asm_branch2(asm, dest_name);
} }
fn emit_jge(&mut self, dest: &Destination) { fn emit_jge(&mut self, dest: &Block) {
trace!("emit: jge {}", dest.target); let dest_name = dest.name.unwrap();
trace!("emit: jge {}", dest_name);
let asm = format!("jge {}", self.asm_block_label(dest.target)); let asm = format!("jge {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest.target); self.add_asm_branch2(asm, dest_name);
} }
fn emit_jl(&mut self, dest: &Destination) { fn emit_jl(&mut self, dest: &Block) {
trace!("emit: jl {}", dest.target); let dest_name = dest.name.unwrap();
trace!("emit: jl {}", dest_name);
let asm = format!("jl {}", self.asm_block_label(dest.target)); let asm = format!("jl {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest.target); self.add_asm_branch2(asm, dest_name);
} }
fn emit_jle(&mut self, dest: &Destination) { fn emit_jle(&mut self, dest: &Block) {
trace!("emit: jle {}", dest.target); let dest_name = dest.name.unwrap();
trace!("emit: jle {}", dest_name);
let asm = format!("jle {}", self.asm_block_label(dest.target)); let asm = format!("jle {}", self.asm_block_label(dest_name));
self.add_asm_branch2(asm, dest.target); self.add_asm_branch2(asm, dest_name);
} }
fn emit_call_near_rel32(&mut self, func: MuName) { fn emit_call_near_rel32(&mut self, func: MuName) {
...@@ -1077,7 +1088,7 @@ pub fn emit_code(func: &mut MuFunctionVersion, vm: &VM) { ...@@ -1077,7 +1088,7 @@ pub fn emit_code(func: &mut MuFunctionVersion, vm: &VM) {
use std::path; use std::path;
let compiled_funcs = vm.compiled_funcs().read().unwrap(); let compiled_funcs = vm.compiled_funcs().read().unwrap();
let cf = compiled_funcs.get(func.fn_name).unwrap().borrow(); let cf = compiled_funcs.get(&func.id).unwrap().borrow();
let code = cf.mc.emit(); let code = cf.mc.emit();
...@@ -1086,7 +1097,7 @@ pub fn emit_code(func: &mut MuFunctionVersion, vm: &VM) { ...@@ -1086,7 +1097,7 @@ pub fn emit_code(func: &mut MuFunctionVersion, vm: &VM) {
let mut file_path = path::PathBuf::new(); let mut file_path = path::PathBuf::new();
file_path.push(EMIT_DIR); file_path.push(EMIT_DIR);
file_path.push(func.fn_name.to_string() + ".s"); file_path.push(func.name.unwrap().to_string() + ".s");
let mut file = match File::create(file_path.as_path()) { let mut file = match File::create(file_path.as_path()) {
Err(why) => panic!("couldn't create emission file {}: {}", file_path.to_str().unwrap(), why), Err(why) => panic!("couldn't create emission file {}: {}", file_path.to_str().unwrap(), why),
Ok(file) => file Ok(file) => file
......
...@@ -36,17 +36,17 @@ pub trait CodeGenerator { ...@@ -36,17 +36,17 @@ pub trait CodeGenerator {
fn emit_mul_r64(&mut self, src: &P<Value>); fn emit_mul_r64(&mut self, src: &P<Value>);
fn emit_mul_mem64(&mut self, src: &P<Value>); fn emit_mul_mem64(&mut self, src: &P<Value>);
fn emit_jmp(&mut self, dest: &Destination); fn emit_jmp(&mut self, dest: &Block);
fn emit_je(&mut self, dest: &Destination); fn emit_je(&mut self, dest: &Block);
fn emit_jne(&mut self, dest: &Destination); fn emit_jne(&mut self, dest: &Block);
fn emit_ja(&mut self, dest: &Destination); fn emit_ja(&mut self, dest: &Block);
fn emit_jae(&mut self, dest: &Destination); fn emit_jae(&mut self, dest: &Block);
fn emit_jb(&mut self, dest: &Destination); fn emit_jb(&mut self, dest: &Block);
fn emit_jbe(&mut self, dest: &Destination); fn emit_jbe(&mut self, dest: &Block);
fn emit_jg(&mut self, dest: &Destination); fn emit_jg(&mut self, dest: &Block);
fn emit_jge(&mut self, dest: &Destination); fn emit_jge(&mut self, dest: &Block);
fn emit_jl(&mut self, dest: &Destination); fn emit_jl(&mut self, dest: &Block);
fn emit_jle(&mut self, dest: &Destination); fn emit_jle(&mut self, dest: &Block);
fn emit_call_near_rel32(&mut self, func: MuName); fn emit_call_near_rel32(&mut self, func: MuName);
fn emit_call_near_r64(&mut self, func: &P<Value>); fn emit_call_near_r64(&mut self, func: &P<Value>);
......
...@@ -59,22 +59,24 @@ impl <'a> InstructionSelection { ...@@ -59,22 +59,24 @@ impl <'a> InstructionSelection {
self.process_dest(&ops, fallthrough_dest, cur_func, vm); self.process_dest(&ops, fallthrough_dest, cur_func, vm);
self.process_dest(&ops, branch_dest, cur_func, vm); self.process_dest(&ops, branch_dest, cur_func, vm);
let branch_target = cur_func.content.as_ref().unwrap().get_block(branch_dest.target);
let ref cond = ops[cond]; let ref cond = ops[cond];
if self.match_cmp_res(cond) { if self.match_cmp_res(cond) {
trace!("emit cmp_eq-branch2"); trace!("emit cmp_eq-branch2");
match self.emit_cmp_res(cond, cur_func, vm) { match self.emit_cmp_res(cond, cur_func, vm) {
op::CmpOp::EQ => self.backend.emit_je(branch_dest), op::CmpOp::EQ => self.backend.emit_je(branch_target),
op::CmpOp::NE => self.backend.emit_jne(branch_dest), op::CmpOp::NE => self.backend.emit_jne(branch_target),
op::CmpOp::UGE => self.backend.emit_jae(branch_dest), op::CmpOp::UGE => self.backend.emit_jae(branch_target),
op::CmpOp::UGT => self.backend.emit_ja(branch_dest), op::CmpOp::UGT => self.backend.emit_ja(branch_target),
op::CmpOp::ULE => self.backend.emit_jbe(branch_dest), op::CmpOp::ULE => self.backend.emit_jbe(branch_target),
op::CmpOp::ULT => self.backend.emit_jb(branch_dest), op::CmpOp::ULT => self.backend.emit_jb(branch_target),
op::CmpOp::SGE => self.backend.emit_jge(branch_dest), op::CmpOp::SGE => self.backend.emit_jge(branch_target),
op::CmpOp::SGT => self.backend.emit_jg(branch_dest), op::CmpOp::SGT => self.backend.emit_jg(branch_target),
op::CmpOp::SLE => self.backend.emit_jle(branch_dest), op::CmpOp::SLE => self.backend.emit_jle(branch_target),
op::CmpOp::SLT => self.backend.emit_jl(branch_dest), op::CmpOp::SLT => self.backend.emit_jl(branch_target),
_ => unimplemented!() _ => unimplemented!()
} }
} else if self.match_ireg(cond) { } else if self.match_ireg(cond) {
...@@ -85,7 +87,7 @@ impl <'a> InstructionSelection { ...@@ -85,7 +87,7 @@ impl <'a> InstructionSelection {
// emit: cmp cond_reg 1 // emit: cmp cond_reg 1
self.backend.emit_cmp_r64_imm32(&cond_reg, 1); self.backend.emit_cmp_r64_imm32(&cond_reg, 1);
// emit: je #branch_dest // emit: je #branch_dest
self.backend.emit_je(branch_dest); self.backend.emit_je(branch_target);
} else { } else {
unimplemented!(); unimplemented!();
} }
...@@ -96,9 +98,11 @@ impl <'a> InstructionSelection { ...@@ -96,9 +98,11 @@ impl <'a> InstructionSelection {
self.process_dest(&ops, dest, cur_func, vm); self.process_dest(&ops, dest, cur_func, vm);
let target = cur_func.content.as_ref().unwrap().get_block(dest.target);
trace!("emit branch1"); trace!("emit branch1");
// jmp // jmp
self.backend.emit_jmp(dest); self.backend.emit_jmp(target);
}, },
Instruction_::ExprCall{ref data, is_abort} => { Instruction_::ExprCall{ref data, is_abort} => {
...@@ -779,7 +783,7 @@ impl CompilerPass for InstructionSelection { ...@@ -779,7 +783,7 @@ impl CompilerPass for InstructionSelection {
fn start_function(&mut self, vm: &VM, func: &mut MuFunctionVersion) { fn start_function(&mut self, vm: &VM, func: &mut MuFunctionVersion) {
debug!("{}", self.name()); debug!("{}", self.name());
self.backend.start_code(func.fn_name); self.backend.start_code(func.name.unwrap());
// prologue (get arguments from entry block first) // prologue (get arguments from entry block first)
let entry_block = func.content.as_ref().unwrap().get_entry_block(); let entry_block = func.content.as_ref().unwrap().get_entry_block();
...@@ -789,25 +793,26 @@ impl CompilerPass for InstructionSelection { ...@@ -789,25 +793,26 @@ impl CompilerPass for InstructionSelection {
#[allow(unused_variables)] #[allow(unused_variables)]
fn visit_function(&mut self, vm: &VM, func: &mut MuFunctionVersion) { fn visit_function(&mut self, vm: &VM, func: &mut MuFunctionVersion) {
for block_label in func.block_trace.as_ref().unwrap() { for block_id in func.block_trace.as_ref().unwrap() {
let block = func.content.as_ref().unwrap().get_block(block_label); let block = func.content.as_ref().unwrap().get_block(*block_id);
let block_label = block.name.unwrap();
self.backend.start_block(block.label); self.backend.start_block(block_label);
let block_content = block.content.as_ref().unwrap(); let block_content = block.content.as_ref().unwrap();
// live in is args of the block // live in is args of the block
self.backend.set_block_livein(block.label, &block_content.args); self.backend.set_block_livein(block_label, &block_content.args);
// live out is the union of all branch args of this block // live out is the union of all branch args of this block
let live_out = block_content.get_out_arguments(); let live_out = block_content.get_out_arguments();
self.backend.set_block_liveout(block.label, &live_out); self.backend.set_block_liveout(block_label, &live_out);
for inst in block_content.body.iter() { for inst in block_content.body.iter() {
self.instruction_select(inst, func, vm); self.instruction_select(inst, func, vm);
} }
self.backend.end_block(block.label); self.backend.end_block(block_label);
} }
} }
...@@ -817,7 +822,7 @@ impl CompilerPass for InstructionSelection { ...@@ -817,7 +822,7 @@ impl CompilerPass for InstructionSelection {
let mc = self.backend.finish_code(); let mc = self.backend.finish_code();
let compiled_func = CompiledFunction { let compiled_func = CompiledFunction {
fn_name: func.fn_name, func_ver_id: func.id,
temps: HashMap::new(), temps: HashMap::new(),
mc: mc mc: mc
}; };
......
...@@ -57,7 +57,7 @@ impl CompilerPass for PeepholeOptimization { ...@@ -57,7 +57,7 @@ impl CompilerPass for PeepholeOptimization {
fn visit_function(&mut self, vm: &VM, func: &mut MuFunctionVersion) { fn visit_function(&mut self, vm: &VM, func: &mut MuFunctionVersion) {
let compiled_funcs = vm.compiled_funcs().read().unwrap(); let compiled_funcs = vm.compiled_funcs().read().unwrap();