Commit 495c8587 authored by qinsoon's avatar qinsoon

an empty defuse pass

parent bed34cc1
......@@ -3,6 +3,7 @@ use ast::op::{BinOp, CmpOp, AtomicRMWOp};
use ast::types::*;
use std::fmt;
use std::cell::Cell;
pub type WPID = usize;
pub type MuID = usize;
......@@ -42,6 +43,7 @@ pub struct TreeNode {
pub id: MuID,
pub tag: MuTag,
pub v: TreeNode_,
pub use_count: Cell<usize>
}
impl TreeNode {
......@@ -49,7 +51,8 @@ impl TreeNode {
P(TreeNode{
id: id,
tag: tag,
v: TreeNode_::Value(P(Value{ty: ty, v: Value_::SSAVar}))
v: TreeNode_::Value(P(Value{ty: ty, v: Value_::SSAVar})),
use_count: Cell::new(0)
})
}
......@@ -57,7 +60,8 @@ impl TreeNode {
P(TreeNode{
id: id,
tag: tag,
v: TreeNode_::Value(P(Value{ty: ty, v: Value_::Constant(v)}))
v: TreeNode_::Value(P(Value{ty: ty, v: Value_::Constant(v)})),
use_count: Cell::new(0)
})
}
......@@ -65,20 +69,14 @@ impl TreeNode {
P(TreeNode{
id: id,
tag: tag,
v: TreeNode_::Value(v)
v: TreeNode_::Value(v),
use_count: Cell::new(0)
}
)
}
pub fn new_inst(id: MuID, tag: MuTag, v: Instruction) -> P<TreeNode> {
P(TreeNode{id: id, tag: tag, v: TreeNode_::Instruction(v)})
}
pub fn as_value(&self) -> Option<&P<Value>> {
match self.v {
TreeNode_::Value(ref pv) => Some(&pv),
_ => None
}
P(TreeNode{id: id, tag: tag, v: TreeNode_::Instruction(v), use_count: Cell::new(0)})
}
}
......
use ast::ir::*;
use ast::ptr::*;
use vm::context::VMContext;
use std::cell::RefCell;
......@@ -28,12 +29,35 @@ pub struct CompilerPolicy {
impl CompilerPolicy {
pub fn default() -> CompilerPolicy {
let mut passes : Vec<Box<CompilerPass>> = vec![];
passes.push(Box::new(passes::tree_gen::TreeGenerationPass::new()));
passes.push(Box::new(passes::tree_gen::TreeGenerationPass::new("Tree Generation")));
CompilerPolicy{passes: passes}
}
}
pub trait CompilerPass {
fn execute(&mut self, vm:&VMContext, func: &mut MuFunction);
fn name(&self) -> &'static str;
fn execute(&mut self, vm_context: &VMContext, func: &mut MuFunction) {
debug!("---CompilerPass {} for {}---", self.name(), func.fn_name);
self.visit_function(vm_context, func);
for entry in func.blocks.iter_mut() {
let label : MuTag = entry.0;
let ref mut block : &mut Block = &mut entry.1;
debug!("block: {}", label);
for node in block.content.as_mut().unwrap().body.iter_mut() {
debug!("{:?}", node);
}
debug!("---finish---");
}
}
fn visit_function(&mut self, vm_context: &VMContext, func: &mut MuFunction) {}
fn visit_block(&mut self, vm_context: &VMContext, block: &mut Block) {}
fn visit_node(&mut self, vm_context: &VMContext, node: &mut TreeNode) {}
}
use ast::ir::*;
use vm::context::VMContext;
use compiler::CompilerPass;
pub struct DefUsePass {
name: &'static str,
}
impl DefUsePass {
pub fn name(name: &'static str) -> DefUsePass {
DefUsePass{name: name}
}
}
impl CompilerPass for DefUsePass {
fn name(&self) -> &'static str {
self.name
}
fn visit_node(&mut self, vm_context: &VMContext, node: &mut TreeNode) {
}
}
\ No newline at end of file
pub mod def_use;
pub mod tree_gen;
\ No newline at end of file
......@@ -3,29 +3,18 @@ use vm::context::VMContext;
use compiler::CompilerPass;
pub struct TreeGenerationPass;
pub struct TreeGenerationPass {
name: &'static str,
}
impl TreeGenerationPass {
pub fn new() -> TreeGenerationPass {
TreeGenerationPass
pub fn new(name: &'static str) -> TreeGenerationPass {
TreeGenerationPass{name: name}
}
}
impl CompilerPass for TreeGenerationPass {
fn execute(&mut self, vm: &VMContext, func: &mut MuFunction) {
debug!("Generating Tree for {}", func.fn_name);
for entry in func.blocks.iter_mut() {
let label : MuTag = entry.0;
let ref mut block : &mut Block = &mut entry.1;
debug!(" block: {}", label);
for inst in block.content.take().unwrap().body {
debug!(" {:?}", inst);
}
debug!(" ");
}
fn name(&self) -> &'static str {
self.name
}
}
\ No newline at end of file
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