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