Commit bed34cc1 authored by qinsoon's avatar qinsoon

implemented Debug for tree nodes and types

parent e7ec3053
This diff is collapsed.
extern crate std;
use std::fmt;
use ast::ptr::P;
use ast::ir::*;
......@@ -7,7 +7,7 @@ use std::sync::RwLock;
pub type MuType = MuType_;
#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Clone, PartialEq, Eq)]
enum MuType_ {
/// int <length>
Int (usize),
......@@ -56,16 +56,57 @@ enum MuType_ {
UFuncPtr (P<MuFuncSig>),
}
impl fmt::Debug for MuType_ {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&MuType_::Int(n) => write!(f, "<int<{}>>", n),
&MuType_::Float => write!(f, "<float>"),
&MuType_::Double => write!(f, "<double>"),
&MuType_::Ref(ref ty) => write!(f, "<ref<{:?}>>", ty),
&MuType_::IRef(ref ty) => write!(f, "<iref<{:?}>>", ty),
&MuType_::WeakRef(ref ty) => write!(f, "<weakref<{:?}>>", ty),
&MuType_::UPtr(ref ty) => write!(f, "<uptr<{:?}>>", ty),
&MuType_::Array(ref ty, size) => write!(f, "<array<{:?}, {:?}>", ty, size),
&MuType_::Hybrid(ref fix_tys, ref var_ty) => write!(f, "<hybrid<{:?} {:?}>>", fix_tys, var_ty),
&MuType_::Void => write!(f, "<void>"),
&MuType_::ThreadRef => write!(f, "<threadref>"),
&MuType_::StackRef => write!(f, "<stackref>"),
&MuType_::Tagref64 => write!(f, "<tagref64>"),
&MuType_::Vector(ref ty, size) => write!(f, "<vector<{:?} {:?}>>", ty, size),
&MuType_::FuncRef(ref sig) => write!(f, "<funcref<{:?}>>", sig),
&MuType_::UFuncPtr(ref sig) => write!(f, "<ufuncref<{:?}>>", sig),
&MuType_::Struct(tag) => {
write!(f, "<struct<").unwrap();
let struct_tag_map_lock = STRUCT_TAG_MAP.read().unwrap();
let struct_ty = struct_tag_map_lock.get(tag);
for ty in struct_ty {
write!(f, "{:?}", ty).unwrap()
}
write!(f, ">>")
}
}
}
}
lazy_static! {
/// storing a map from MuTag to StructType_
pub static ref STRUCT_TAG_MAP : RwLock<HashMap<MuTag, StructType_>> = RwLock::new(HashMap::new());
}
#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Clone, PartialEq, Eq)]
pub struct StructType_ {
tys: Vec<P<MuType_>>
}
impl fmt::Debug for StructType_ {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for ty in self.tys.iter() {
write!(f, "{:?}", ty).unwrap();
}
write!(f, "")
}
}
impl StructType_ {
pub fn set_tys(&mut self, mut list: Vec<P<MuType>>) {
self.tys.clear();
......@@ -255,8 +296,14 @@ macro_rules! is_type (
)
);
#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Clone, PartialEq, Eq)]
pub struct MuFuncSig {
pub ret_tys : Vec<P<MuType>>,
pub arg_tys: Vec<P<MuType>>
}
impl fmt::Debug for MuFuncSig {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?} -> {:?}", self.ret_tys, self.arg_tys)
}
}
\ No newline at end of file
......@@ -13,13 +13,13 @@ impl TreeGenerationPass {
impl CompilerPass for TreeGenerationPass {
fn execute(&mut self, vm: &VMContext, func: &mut MuFunction) {
debug!("Generating Tree for {:?}", func.fn_name);
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);
debug!(" block: {}", label);
for inst in block.content.take().unwrap().body {
debug!(" {:?}", inst);
......
......@@ -32,7 +32,7 @@ pub fn factorial() -> VMContext {
let type_def_int32 = vm.declare_type("int32", P(MuType::int(32)));
// .const @int_64_1 <@int_64> = 1
let const_def_int64_1 = vm.declare_const("int64_1", type_def_int64.clone(), Constant::Int(64, 1));
let const_def_int64_1 = vm.declare_const("int64_1", type_def_int64.clone(), Constant::Int(1));
// .funcsig @fac_sig = (@int_64) -> (@int_64)
let fac_sig = vm.declare_func_sig("fac_sig", vec![type_def_int64.clone()], vec![type_def_int64.clone()]);
......
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