Skip to content

Commit

Permalink
WIP fix bug with debug print for dag
Browse files Browse the repository at this point in the history
  • Loading branch information
maekawatoshiki committed Sep 27, 2020
1 parent 21c9417 commit d1df595
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/codegen/common/dag/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ impl DAGFunction {
}
}

pub fn debug(&self, f: &mut fmt::Formatter, tys: &Types) -> fmt::Result {
pub fn debug(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(
f,
"DAGFunc(name: {}, ty: {}):",
self.name,
tys.to_string(self.ty)
self.types.to_string(self.ty)
)?;

for bb_id in &self.dag_basic_blocks {
let bb = &self.dag_basic_block_arena[*bb_id];
bb.debug(f, tys, bb_id.index())?;
bb.debug(f, &self.types, bb_id.index())?;
}

fmt::Result::Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/common/dag/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl fmt::Debug for DAGModule {
writeln!(f, "DAGModule: {}", self.name)?;

for (_, func) in &self.functions {
func.debug(f, &self.types)?;
func.debug(f)?;
}

fmt::Result::Ok(())
Expand Down
16 changes: 10 additions & 6 deletions src/codegen/common/dag/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,13 @@ impl DAGNode {
&self,
f: &mut fmt::Formatter<'_>,
tys: &Types,
s: &mut FxHashMap<Raw<DAGNode>, usize>,
s: &mut FxHashMap<Raw<DAGNode>, (usize, bool)>,
self_id: usize, // 0 is entry
indent: usize,
) -> fmt::Result {
#[rustfmt::skip]
macro_rules! id4op { ($op:expr) => {{
let l=s.len()+1; s.entry($op).or_insert(l)
let l=s.len()+1; s.entry($op).or_insert((l, false))
}}}
write!(f, "{}", " ".repeat(indent))?;
write!(f, "id{}({}) = ", self_id, tys.to_string(self.ty))?;
Expand All @@ -380,7 +380,7 @@ impl DAGNode {
continue;
}
if op.may_contain_children() {
write!(f, " id{}", id4op!(*op))?;
write!(f, " id{}", id4op!(*op).0)?;
} else {
write!(f, " ")?;
op.kind.as_operand().debug(f, tys)?;
Expand All @@ -392,11 +392,15 @@ impl DAGNode {
if !op.may_contain_children() || op.kind == NodeKind::None {
continue;
}
let id = *id4op!(*op);
op.debug(f, tys, s, id, indent + 2)?;
let id = id4op!(*op).0;
if !s[op].1 {
s.get_mut(op).unwrap().1 = true;
op.debug(f, tys, s, id, indent + 2)?;
}
}
if let Some(next) = self.next {
let id = *id4op!(next);
let id = id4op!(next).0;
s.get_mut(&next).unwrap().1 = true;
next.debug(f, tys, s, id, indent)?;
}
fmt::Result::Ok(())
Expand Down

0 comments on commit d1df595

Please sign in to comment.