mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-12 21:18:45 +00:00
Cleanup some formatting code, add tips
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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}"),
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user