mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-15 15:08:52 +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).
|
- 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`,
|
- Run `./scripts/make-submissions.sh` to generate `irgen.zip` to `final.zip`,
|
||||||
which you should submit for homework 2 to the final project.
|
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"
|
",rtz"
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
}
|
};
|
||||||
.to_string();
|
let rs2 = rs2.map(|rs2| format!(",{rs2}")).unwrap_or_default();
|
||||||
|
write!(f, "{instr}\t{rd},{rs1}{rs2}{rounding_mode}")
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"{}\t{},{}{}{}",
|
|
||||||
instr,
|
|
||||||
rd,
|
|
||||||
rs1,
|
|
||||||
if let Some(rs2) = rs2 {
|
|
||||||
format!(",{rs2}")
|
|
||||||
} else {
|
|
||||||
"".to_string()
|
|
||||||
},
|
|
||||||
rounding_mode
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
Self::IType {
|
Self::IType {
|
||||||
instr,
|
instr,
|
||||||
@@ -263,7 +250,7 @@ impl fmt::Display for Instruction {
|
|||||||
rs1,
|
rs1,
|
||||||
rs2,
|
rs2,
|
||||||
imm,
|
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::UType { instr, rd, imm } => write!(f, "{instr}\t{rd}, {imm}",),
|
||||||
Self::Pseudo(pseudo) => write!(f, "{pseudo}"),
|
Self::Pseudo(pseudo) => write!(f, "{pseudo}"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ impl WriteLine for Variable {
|
|||||||
impl WriteLine for Block {
|
impl WriteLine for Block {
|
||||||
fn write_line(&self, indent: usize, write: &mut dyn Write) -> Result<()> {
|
fn write_line(&self, indent: usize, write: &mut dyn Write) -> Result<()> {
|
||||||
if let Some(label) = &self.label {
|
if let Some(label) = &self.label {
|
||||||
writeln!(write, "{}:", label.0)?;
|
writeln!(write, "{label}:")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for instruction in &self.instructions {
|
for instruction in &self.instructions {
|
||||||
|
|||||||
@@ -23,30 +23,25 @@ impl Translate<TranslationUnit> for Visualizer {
|
|||||||
|
|
||||||
// TODO: Add variables and structs information
|
// TODO: Add variables and structs information
|
||||||
for (name, decl) in &source.decls {
|
for (name, decl) in &source.decls {
|
||||||
match decl {
|
if let Declaration::Function {
|
||||||
Declaration::Variable { .. } => {}
|
|
||||||
Declaration::Function {
|
|
||||||
signature,
|
signature,
|
||||||
definition,
|
definition: Some(definition),
|
||||||
} => {
|
} = decl
|
||||||
let Some(definition) = definition else {
|
{
|
||||||
continue;
|
|
||||||
};
|
|
||||||
let subgraph = self.translate_function(name, signature, definition)?;
|
let subgraph = self.translate_function(name, signature, definition)?;
|
||||||
subgraphs.push(subgraph);
|
subgraphs.push(subgraph);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let mut edges = Vec::new();
|
let mut edges = Vec::new();
|
||||||
|
|
||||||
// Add edges between subgraphs
|
// Add edges between subgraphs
|
||||||
for (name, decl) in &source.decls {
|
for (name, decl) in &source.decls {
|
||||||
if let Declaration::Function { definition, .. } = decl {
|
if let Declaration::Function {
|
||||||
let Some(definition) = definition else {
|
definition: Some(definition),
|
||||||
continue;
|
..
|
||||||
};
|
} = decl
|
||||||
|
{
|
||||||
for (bid, block) in &definition.blocks {
|
for (bid, block) in &definition.blocks {
|
||||||
for (iid, instruction) in block.instructions.iter().enumerate() {
|
for (iid, instruction) in block.instructions.iter().enumerate() {
|
||||||
if let Instruction::Call { callee, .. } = &instruction.inner {
|
if let Instruction::Call { callee, .. } = &instruction.inner {
|
||||||
|
|||||||
Reference in New Issue
Block a user