From bec888e0a5369791bd1dd6d81f9d5998a22fe1b5 Mon Sep 17 00:00:00 2001 From: Alan Li Date: Wed, 10 Apr 2024 08:49:35 -0400 Subject: [PATCH] fmt --- basic/src/bin/valida.rs | 12 +++---- machine/src/program.rs | 78 ++++++++++++++++++++--------------------- opcodes/src/lib.rs | 4 +-- 3 files changed, 45 insertions(+), 49 deletions(-) diff --git a/basic/src/bin/valida.rs b/basic/src/bin/valida.rs index cf115d72..87f23467 100644 --- a/basic/src/bin/valida.rs +++ b/basic/src/bin/valida.rs @@ -185,8 +185,7 @@ fn list_instrs(args: ArgMatches, context: &mut Context) -> Result let program_rom = &context.machine_.program().program_rom; let total_size = program_rom.0.len(); - let print_size_arg = args - .get_one::("size"); + let print_size_arg = args.get_one::("size"); let print_size = match print_size_arg { Some(size) => size.parse::().unwrap(), @@ -216,7 +215,7 @@ fn set_bp(args: ArgMatches, context: &mut Context) -> Result> { Ok(Some(message)) } -fn run_until(_ : ArgMatches, context: &mut Context) -> Result> { +fn run_until(_: ArgMatches, context: &mut Context) -> Result> { let mut message = String::new(); loop { let (stop, pc) = context.step(); @@ -233,7 +232,7 @@ fn run_until(_ : ArgMatches, context: &mut Context) -> Result> { Ok(Some(message)) } -fn step(_ : ArgMatches, context: &mut Context) -> Result> { +fn step(_: ArgMatches, context: &mut Context) -> Result> { let (stop, _) = context.step(); if stop { context.stopped_ = true; @@ -278,8 +277,9 @@ fn repl_run(args: &Args) { run_until, ) .with_command( - Command::new("l").about("list instruction at current PC") - .arg(Arg::new("size").required(false)), + Command::new("l") + .about("list instruction at current PC") + .arg(Arg::new("size").required(false)), list_instrs, ) .with_command( diff --git a/machine/src/program.rs b/machine/src/program.rs index 273572ca..1ea765d2 100644 --- a/machine/src/program.rs +++ b/machine/src/program.rs @@ -30,7 +30,9 @@ impl ToString for InstructionWord { Ok(opcode_name) => { format!("{:?}", opcode_name) } - Err(_) => {format!("UNKNOWN_OP:{}", self.opcode.to_string())} + Err(_) => { + format!("UNKNOWN_OP:{}", self.opcode.to_string()) + } }; format!("{} {}", opcode, self.print_operands()) } @@ -46,13 +48,17 @@ impl InstructionWord { pub fn print_imm32(&self) -> String { assert!(self.opcode == IMM32, "Instruction is not immediate"); - + //extract the immediate value let imm0 = self.operands.0[1]; let imm1 = self.operands.0[2]; let imm2 = self.operands.0[3]; let imm3 = self.operands.0[4]; - format!("{}(fp), {}", self.operands.0[0], imm0 << 24 | imm1 << 16 | imm2 << 8 | imm3) + format!( + "{}(fp), {}", + self.operands.0[0], + imm0 << 24 | imm1 << 16 | imm2 << 8 | imm3 + ) } pub fn print_first_operand(&self) -> String { @@ -68,51 +74,43 @@ impl InstructionWord { } } - pub fn print_address(&self, index : usize) -> String { - format!("{}", self.operands.0[index]/24) + pub fn print_address(&self, index: usize) -> String { + format!("{}", self.operands.0[index] / 24) } pub fn print_operands(&self) -> String { match self.opcode { valida_opcodes::IMM32 => self.print_imm32(), - valida_opcodes::JAL => - format!( - "{}(fp), PC: {}, {}", - self.operands.0[0], - self.print_address(1), - self.operands.0[2]), - valida_opcodes::JALV => - format!( - "{}(fp), {}(fp), {}(fp)", - self.operands.0[0], - self.operands.0[1], - self.operands.0[2]), - valida_opcodes::LOADFP => - format!( - "{}(fp), {}", - self.operands.0[0], - self.operands.0[1]), - valida_opcodes::BEQ | - valida_opcodes::BNE => - format!( - "{}, {}, {}", - self.print_address(0), - self.print_first_operand(), - self.print_second_operand()), + valida_opcodes::JAL => format!( + "{}(fp), PC: {}, {}", + self.operands.0[0], + self.print_address(1), + self.operands.0[2] + ), + valida_opcodes::JALV => format!( + "{}(fp), {}(fp), {}(fp)", + self.operands.0[0], self.operands.0[1], self.operands.0[2] + ), + valida_opcodes::LOADFP => format!("{}(fp), {}", self.operands.0[0], self.operands.0[1]), + valida_opcodes::BEQ | valida_opcodes::BNE => format!( + "{}, {}, {}", + self.print_address(0), + self.print_first_operand(), + self.print_second_operand() + ), valida_opcodes::STOP => "".to_string(), - valida_opcodes::LOAD32 => - format!( - "{}(fp), {}(fp)", - self.operands.0[0], - self.operands.0[1]), - valida_opcodes::STORE32 => - format!( - "{}(fp), {}(fp)", - self.operands.0[1], - self.operands.0[2]), + valida_opcodes::LOAD32 => { + format!("{}(fp), {}(fp)", self.operands.0[0], self.operands.0[1]) + } + valida_opcodes::STORE32 => { + format!("{}(fp), {}(fp)", self.operands.0[1], self.operands.0[2]) + } _ => { format!( - "{}(fp), {}, {}", self.operands.0[0], self.print_first_operand(), self.print_second_operand() + "{}(fp), {}, {}", + self.operands.0[0], + self.print_first_operand(), + self.print_second_operand() ) } } diff --git a/opcodes/src/lib.rs b/opcodes/src/lib.rs index 5e67a494..161be3f2 100644 --- a/opcodes/src/lib.rs +++ b/opcodes/src/lib.rs @@ -40,7 +40,7 @@ pub enum Opcode { macro_rules! declare_opcode { ($opcode : ident) => { - pub const $opcode : u32 = Opcode::$opcode as u32; + pub const $opcode: u32 = Opcode::$opcode as u32; }; } @@ -60,7 +60,6 @@ declare_opcode!(LOADFP); /// NONDETERMINISTIC declare_opcode!(READ_ADVICE); - /// U32 ALU declare_opcode!(ADD32); declare_opcode!(SUB32); @@ -80,7 +79,6 @@ declare_opcode!(MULHS32); declare_opcode!(LTE32); declare_opcode!(EQ32); - /// NATIVE FIELD declare_opcode!(ADD); declare_opcode!(SUB);