Skip to content

Commit

Permalink
ir: Spacing & indent for debug printed IR
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkajetanp committed Aug 21, 2024
1 parent a4bd26a commit eb3a999
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl fmt::Display for Function {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} -> {}:\n", self.name, self.return_type).unwrap();
for instr in &self.instructions {
write!(f, "\t{}\n", instr).unwrap();
write!(f, "{}\n", instr).unwrap();
}
Ok(())
}
Expand Down Expand Up @@ -243,15 +243,15 @@ impl Instruction {
impl fmt::Display for Instruction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let result = match self {
Instruction::Return(val) => format!("return {}", val),
Instruction::Unary(op, src, dst) => format!("{} = {}{}", dst, op, src),
Instruction::Return(val) => format!("\treturn {}", val),
Instruction::Unary(op, src, dst) => format!("\t{} = {}{}", dst, op, src),
Instruction::Binary(op, src1, src2, dst) => {
format!("{} = {} {} {}", dst, src1, op, src2)
format!("\t{} = {} {} {}", dst, src1, op, src2)
}
Instruction::Copy(src, dst) => format!("{} = {}", dst, src),
Instruction::Jump(ident) => format!("jump {}", ident),
Instruction::JumpIfZero(val, ident) => format!("jumpz {} {}", val, ident),
Instruction::JumpIfNotZero(val, ident) => format!("jumpnz {} {}", val, ident),
Instruction::Copy(src, dst) => format!("\t{} = {}", dst, src),
Instruction::Jump(ident) => format!("\tjump {}\n\n", ident),
Instruction::JumpIfZero(val, ident) => format!("\tjumpz {} {}\n", val, ident),
Instruction::JumpIfNotZero(val, ident) => format!("\tjumpnz {} {}\n", val, ident),
Instruction::Label(ident) => format!(":{}", ident),
};
write!(f, "{}", result)
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ impl Driver {
let asm = code.emit();

if log::log_enabled!(log::Level::Debug) {
log::debug!("Emitted asm:");
Driver::print_asm_with_highlight(&asm);
}

Expand Down

0 comments on commit eb3a999

Please sign in to comment.