Skip to content

Commit a165524

Browse files
committed
Cleanup some formatting code, add tips
1 parent 6f18d77 commit a165524

File tree

4 files changed

+22
-35
lines changed

4 files changed

+22
-35
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,8 @@ make run
239239
- Submit the corresponding files to [gg.kaist.ac.kr](https://gg.kaist.ac.kr).
240240
- Run `./scripts/make-submissions.sh` to generate `irgen.zip` to `final.zip`,
241241
which you should submit for homework 2 to the final project.
242+
243+
## Running on a local machine
244+
245+
- https://github.com/kaist-cp/cs420/issues/314
246+
- https://github.com/kaist-cp/cs420/issues/460

src/asm/mod.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -223,22 +223,9 @@ impl fmt::Display for Instruction {
223223
",rtz"
224224
} else {
225225
""
226-
}
227-
.to_string();
228-
229-
write!(
230-
f,
231-
"{}\t{},{}{}{}",
232-
instr,
233-
rd,
234-
rs1,
235-
if let Some(rs2) = rs2 {
236-
format!(",{rs2}")
237-
} else {
238-
"".to_string()
239-
},
240-
rounding_mode
241-
)
226+
};
227+
let rs2 = rs2.map(|rs2| format!(",{rs2}")).unwrap_or_default();
228+
write!(f, "{instr}\t{rd},{rs1}{rs2}{rounding_mode}")
242229
}
243230
Self::IType {
244231
instr,
@@ -263,7 +250,7 @@ impl fmt::Display for Instruction {
263250
rs1,
264251
rs2,
265252
imm,
266-
} => write!(f, "{}\t{},{}, {}", instr, rs1, rs2, imm.0,),
253+
} => write!(f, "{instr}\t{rs1},{rs2}, {imm}"),
267254
Self::UType { instr, rd, imm } => write!(f, "{instr}\t{rd}, {imm}",),
268255
Self::Pseudo(pseudo) => write!(f, "{pseudo}"),
269256
}

src/asm/write_asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl WriteLine for Variable {
6262
impl WriteLine for Block {
6363
fn write_line(&self, indent: usize, write: &mut dyn Write) -> Result<()> {
6464
if let Some(label) = &self.label {
65-
writeln!(write, "{}:", label.0)?;
65+
writeln!(write, "{label}:")?;
6666
}
6767

6868
for instruction in &self.instructions {

src/ir/visualize.rs

+12-17
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,25 @@ impl Translate<TranslationUnit> for Visualizer {
2323

2424
// TODO: Add variables and structs information
2525
for (name, decl) in &source.decls {
26-
match decl {
27-
Declaration::Variable { .. } => {}
28-
Declaration::Function {
29-
signature,
30-
definition,
31-
} => {
32-
let Some(definition) = definition else {
33-
continue;
34-
};
35-
let subgraph = self.translate_function(name, signature, definition)?;
36-
subgraphs.push(subgraph);
37-
}
26+
if let Declaration::Function {
27+
signature,
28+
definition: Some(definition),
29+
} = decl
30+
{
31+
let subgraph = self.translate_function(name, signature, definition)?;
32+
subgraphs.push(subgraph);
3833
}
3934
}
4035

4136
let mut edges = Vec::new();
4237

4338
// Add edges between subgraphs
4439
for (name, decl) in &source.decls {
45-
if let Declaration::Function { definition, .. } = decl {
46-
let Some(definition) = definition else {
47-
continue;
48-
};
49-
40+
if let Declaration::Function {
41+
definition: Some(definition),
42+
..
43+
} = decl
44+
{
5045
for (bid, block) in &definition.blocks {
5146
for (iid, instruction) in block.instructions.iter().enumerate() {
5247
if let Instruction::Call { callee, .. } = &instruction.inner {

0 commit comments

Comments
 (0)