Commit f66a2348 authored by qinsoon's avatar qinsoon

use default debug info. move previous Debug impl as Display

parent 0b7c8424
This diff is collapsed.
...@@ -7,7 +7,7 @@ use std::sync::RwLock; ...@@ -7,7 +7,7 @@ use std::sync::RwLock;
pub type MuType = MuType_; pub type MuType = MuType_;
#[derive(Clone, PartialEq, Eq)] #[derive(Clone, PartialEq, Eq, Debug)]
pub enum MuType_ { pub enum MuType_ {
/// int <length> /// int <length>
Int (usize), Int (usize),
...@@ -56,25 +56,25 @@ pub enum MuType_ { ...@@ -56,25 +56,25 @@ pub enum MuType_ {
UFuncPtr (P<MuFuncSig>), UFuncPtr (P<MuFuncSig>),
} }
impl fmt::Debug for MuType_ { impl fmt::Display for MuType_ {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self { match self {
&MuType_::Int(n) => write!(f, "int<{}>", n), &MuType_::Int(n) => write!(f, "int<{}>", n),
&MuType_::Float => write!(f, "float"), &MuType_::Float => write!(f, "float"),
&MuType_::Double => write!(f, "double"), &MuType_::Double => write!(f, "double"),
&MuType_::Ref(ref ty) => write!(f, "ref<{:?}>", ty), &MuType_::Ref(ref ty) => write!(f, "ref<{}>", ty),
&MuType_::IRef(ref ty) => write!(f, "iref<{:?}>", ty), &MuType_::IRef(ref ty) => write!(f, "iref<{}>", ty),
&MuType_::WeakRef(ref ty) => write!(f, "weakref<{:?}>", ty), &MuType_::WeakRef(ref ty) => write!(f, "weakref<{}>", ty),
&MuType_::UPtr(ref ty) => write!(f, "uptr<{:?}>", ty), &MuType_::UPtr(ref ty) => write!(f, "uptr<{}>", ty),
&MuType_::Array(ref ty, size) => write!(f, "array<{:?} {:?}>", ty, size), &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_::Hybrid(ref fix_tys, ref var_ty) => write!(f, "hybrid<[{}] {}>", type_vector_str(fix_tys), var_ty),
&MuType_::Void => write!(f, "void"), &MuType_::Void => write!(f, "void"),
&MuType_::ThreadRef => write!(f, "threadref"), &MuType_::ThreadRef => write!(f, "threadref"),
&MuType_::StackRef => write!(f, "stackref"), &MuType_::StackRef => write!(f, "stackref"),
&MuType_::Tagref64 => write!(f, "tagref64"), &MuType_::Tagref64 => write!(f, "tagref64"),
&MuType_::Vector(ref ty, size) => write!(f, "vector<{:?} {:?}>", ty, size), &MuType_::Vector(ref ty, size) => write!(f, "vector<{} {}>", ty, size),
&MuType_::FuncRef(ref sig) => write!(f, "funcref<{:?}>", sig), &MuType_::FuncRef(ref sig) => write!(f, "funcref<{}>", sig),
&MuType_::UFuncPtr(ref sig) => write!(f, "ufuncref<{:?}>", sig), &MuType_::UFuncPtr(ref sig) => write!(f, "ufuncref<{}>", sig),
&MuType_::Struct(tag) => write!(f, "{}(struct)", tag) &MuType_::Struct(tag) => write!(f, "{}(struct)", tag)
} }
} }
...@@ -85,17 +85,17 @@ lazy_static! { ...@@ -85,17 +85,17 @@ lazy_static! {
pub static ref STRUCT_TAG_MAP : RwLock<HashMap<MuTag, StructType_>> = RwLock::new(HashMap::new()); pub static ref STRUCT_TAG_MAP : RwLock<HashMap<MuTag, StructType_>> = RwLock::new(HashMap::new());
} }
#[derive(Clone, PartialEq, Eq)] #[derive(Clone, PartialEq, Eq, Debug)]
pub struct StructType_ { pub struct StructType_ {
tys: Vec<P<MuType_>> tys: Vec<P<MuType_>>
} }
impl fmt::Debug for StructType_ { impl fmt::Display for StructType_ {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "struct<").unwrap(); write!(f, "struct<").unwrap();
for i in 0..self.tys.len() { for i in 0..self.tys.len() {
let ty = &self.tys[i]; let ty = &self.tys[i];
write!(f, "{:?}", ty).unwrap(); write!(f, "{}", ty).unwrap();
if i != self.tys.len() - 1 { if i != self.tys.len() - 1 {
write!(f, " ").unwrap(); write!(f, " ").unwrap();
} }
...@@ -293,14 +293,25 @@ macro_rules! is_type ( ...@@ -293,14 +293,25 @@ macro_rules! is_type (
) )
); );
#[derive(Clone, PartialEq, Eq)] #[derive(Clone, PartialEq, Eq, Debug)]
pub struct MuFuncSig { pub struct MuFuncSig {
pub ret_tys : Vec<P<MuType>>, pub ret_tys : Vec<P<MuType>>,
pub arg_tys: Vec<P<MuType>> pub arg_tys: Vec<P<MuType>>
} }
impl fmt::Debug for MuFuncSig { impl fmt::Display for MuFuncSig {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?} -> {:?}", self.ret_tys, self.arg_tys) write!(f, "[{}] -> [{}]", type_vector_str(&self.ret_tys), type_vector_str(&self.arg_tys))
} }
}
fn type_vector_str(vec: &Vec<P<MuType>>) -> String {
let mut ret = String::new();
for i in 0..vec.len() {
ret.push_str(fmt::format(format_args!("{}", vec[i])).as_str());
if i != vec.len() - 1 {
ret.push_str(", ");
}
}
ret
} }
\ No newline at end of file
...@@ -57,7 +57,7 @@ pub trait CompilerPass { ...@@ -57,7 +57,7 @@ pub trait CompilerPass {
self.visit_block(vm_context, &mut func.context, block); self.visit_block(vm_context, &mut func.context, block);
for inst in block.content.as_mut().unwrap().body.iter_mut() { for inst in block.content.as_mut().unwrap().body.iter_mut() {
debug!("{:?}", inst); debug!("{}", inst);
self.visit_inst(vm_context, &mut func.context, inst); self.visit_inst(vm_context, &mut func.context, inst);
} }
......
...@@ -63,7 +63,7 @@ impl CompilerPass for DefUse { ...@@ -63,7 +63,7 @@ impl CompilerPass for DefUse {
debug!("check use count for variables"); debug!("check use count for variables");
for entry in func.context.values.values() { for entry in func.context.values.values() {
debug!("{}({}): {}", entry.tag, entry.id, entry.use_count.get()) debug!("{}#{}: {}", entry.tag, entry.id, entry.use_count.get())
} }
} }
} }
\ No newline at end of file
...@@ -39,7 +39,7 @@ impl CompilerPass for TreeGen { ...@@ -39,7 +39,7 @@ impl CompilerPass for TreeGen {
trace!(""); trace!("");
for node in body.into_iter() { for node in body.into_iter() {
trace!("check inst: {:?}", node); trace!("check inst: {}", node);
match &node.v { match &node.v {
&TreeNode_::Instruction(ref inst) => { &TreeNode_::Instruction(ref inst) => {
// check if any operands can be replaced by expression // check if any operands can be replaced by expression
...@@ -56,11 +56,11 @@ impl CompilerPass for TreeGen { ...@@ -56,11 +56,11 @@ impl CompilerPass for TreeGen {
// replace the node with its expr // replace the node with its expr
let expr = entry_value.expr.take().unwrap(); let expr = entry_value.expr.take().unwrap();
trace!("{:?} replaced by {:?}", ops[index], expr); trace!("{} replaced by {}", ops[index], expr);
ops[index] = TreeNode::new_inst(expr); ops[index] = TreeNode::new_inst(expr);
} }
} else { } else {
trace!("{:?} cant be replaced", ops[index]); trace!("{} cant be replaced", ops[index]);
} }
} }
} }
...@@ -97,7 +97,7 @@ impl CompilerPass for TreeGen { ...@@ -97,7 +97,7 @@ impl CompilerPass for TreeGen {
_ => panic!("expected an instruction node here") _ => panic!("expected an instruction node here")
} }
trace!("add {:?} back to block {}", node, label); trace!("add {} back to block {}", node, label);
trace!(""); trace!("");
new_body.push(node); new_body.push(node);
} }
...@@ -123,7 +123,7 @@ impl CompilerPass for TreeGen { ...@@ -123,7 +123,7 @@ impl CompilerPass for TreeGen {
debug!("block {}", entry.0); debug!("block {}", entry.0);
for inst in entry.1.content.as_ref().unwrap().body.iter() { for inst in entry.1.content.as_ref().unwrap().body.iter() {
debug!("{:?}", inst); debug!("{}", inst);
} }
} }
} }
......
...@@ -5,13 +5,13 @@ use self::mu::ast::types::*; ...@@ -5,13 +5,13 @@ use self::mu::ast::types::*;
macro_rules! assert_type ( macro_rules! assert_type (
($test:expr, $expect: expr) => ( ($test:expr, $expect: expr) => (
assert_eq!(format!("{:?}", $test), $expect) assert_eq!(format!("{}", $test), $expect)
) )
); );
macro_rules! println_type ( macro_rules! println_type (
($test:expr) => ( ($test:expr) => (
println!("{:?}", $test) println!("{}", $test)
) )
); );
......
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