diff options
| Commit | acbd7c4b6cb7917ab0033d2cb18df182d614a85a (patch) | |
|---|---|---|
| Author | 2025-02-14 18:15:12 +0200 | |
| Committer | 2025-02-14 18:15:12 +0200 | |
| Files | 8b6e351f066119574c7f0782187ae6ba06b7a424 /assembler/src/parser | |
| tonkobali-acbd7c4b6cb7917ab0033d2cb18df182d614a85a.tar tonkobali-acbd7c4b6cb7917ab0033d2cb18df182d614a85a.tar.gz tonkobali-acbd7c4b6cb7917ab0033d2cb18df182d614a85a.zip | ||
| Parent | 741c317d0ab0481117033b6826cc69856807506e (diff) | |
feat(assembler): Implement proper cli interface and improve debug output
1 files changed, 10 insertions, 11 deletions
| -rw-r--r-- | assembler/src/parser/mod.rs | 21 |
diff --git a/assembler/src/parser/mod.rs b/assembler/src/parser/mod.rs index d43b9c5..f93875b 100644 --- a/assembler/src/parser/mod.rs +++ b/assembler/src/parser/mod.rs @@ -16,25 +16,24 @@ pub(crate) struct Program { instructions: Vec<Instruction>, } -impl Display for Program { - fn fmt(&self, f: &mut Formatter) -> Result { - writeln!(f, "-- Definitions --")?; +impl Program { + pub(crate) fn print(&self, start_index: usize) { + println!("-- Definitions --"); for (name, loc) in self.definitions.iter() { - writeln!(f, "{} := {:?}", name, loc)?; + println!("{} := {:?}", name, loc); } - writeln!(f, "-- Constants --")?; + println!("-- Constants --"); for (i, cnst) in self.constants.iter().enumerate() { - writeln!(f, "{: >8}: {} ", i, cnst)?; + println!("{: >8}: {} ", i + start_index, cnst); } - writeln!(f, "-- Instructions --")?; + println!("-- Instructions --"); for (i, instr) in self.instructions.iter().enumerate() { - write!(f, "{: >8}: {} ", i, instr.name)?; + print!("{: >8}: {} ", i + start_index, instr.name); for arg in &instr.args { - write!(f, "{:?}, ", arg)?; + print!("{:?}, ", arg); } - writeln!(f, "")?; + println!(""); } - Ok(()) } } |
