diff --git a/README.md b/README.md index b58c535..10e586d 100644 --- a/README.md +++ b/README.md @@ -239,3 +239,8 @@ make run - Submit the corresponding files to [gg.kaist.ac.kr](https://gg.kaist.ac.kr). - Run `./scripts/make-submissions.sh` to generate `irgen.zip` to `final.zip`, which you should submit for homework 2 to the final project. + +## Running on a local machine + +- https://github.com/kaist-cp/cs420/issues/314 +- https://github.com/kaist-cp/cs420/issues/460 diff --git a/src/asm/mod.rs b/src/asm/mod.rs index f3eef13..cac5cd7 100644 --- a/src/asm/mod.rs +++ b/src/asm/mod.rs @@ -223,22 +223,9 @@ impl fmt::Display for Instruction { ",rtz" } else { "" - } - .to_string(); - - write!( - f, - "{}\t{},{}{}{}", - instr, - rd, - rs1, - if let Some(rs2) = rs2 { - format!(",{rs2}") - } else { - "".to_string() - }, - rounding_mode - ) + }; + let rs2 = rs2.map(|rs2| format!(",{rs2}")).unwrap_or_default(); + write!(f, "{instr}\t{rd},{rs1}{rs2}{rounding_mode}") } Self::IType { instr, @@ -263,7 +250,7 @@ impl fmt::Display for Instruction { rs1, rs2, imm, - } => write!(f, "{}\t{},{}, {}", instr, rs1, rs2, imm.0,), + } => write!(f, "{instr}\t{rs1},{rs2}, {imm}"), Self::UType { instr, rd, imm } => write!(f, "{instr}\t{rd}, {imm}",), Self::Pseudo(pseudo) => write!(f, "{pseudo}"), } diff --git a/src/asm/write_asm.rs b/src/asm/write_asm.rs index d33225d..01396c4 100644 --- a/src/asm/write_asm.rs +++ b/src/asm/write_asm.rs @@ -62,7 +62,7 @@ impl WriteLine for Variable { impl WriteLine for Block { fn write_line(&self, indent: usize, write: &mut dyn Write) -> Result<()> { if let Some(label) = &self.label { - writeln!(write, "{}:", label.0)?; + writeln!(write, "{label}:")?; } for instruction in &self.instructions { diff --git a/src/ir/visualize.rs b/src/ir/visualize.rs index c274ffd..2f857fe 100644 --- a/src/ir/visualize.rs +++ b/src/ir/visualize.rs @@ -23,18 +23,13 @@ impl Translate for Visualizer { // TODO: Add variables and structs information for (name, decl) in &source.decls { - match decl { - Declaration::Variable { .. } => {} - Declaration::Function { - signature, - definition, - } => { - let Some(definition) = definition else { - continue; - }; - let subgraph = self.translate_function(name, signature, definition)?; - subgraphs.push(subgraph); - } + if let Declaration::Function { + signature, + definition: Some(definition), + } = decl + { + let subgraph = self.translate_function(name, signature, definition)?; + subgraphs.push(subgraph); } } @@ -42,11 +37,11 @@ impl Translate for Visualizer { // Add edges between subgraphs for (name, decl) in &source.decls { - if let Declaration::Function { definition, .. } = decl { - let Some(definition) = definition else { - continue; - }; - + if let Declaration::Function { + definition: Some(definition), + .. + } = decl + { for (bid, block) in &definition.blocks { for (iid, instruction) in block.instructions.iter().enumerate() { if let Instruction::Call { callee, .. } = &instruction.inner {