Cleanup some formatting code, add tips

This commit is contained in:
Janggun Lee
2025-02-27 12:54:15 +09:00
parent 6f18d77861
commit a1655246c9
4 changed files with 22 additions and 35 deletions

View File

@@ -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

View File

@@ -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}"),
}

View File

@@ -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 {

View File

@@ -23,18 +23,13 @@ impl Translate<TranslationUnit> 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<TranslationUnit> 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 {