From d1f0d6c14cb5ce89c61e1021102bcf39421b3a7b Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Thu, 16 Nov 2023 13:30:03 +0100 Subject: [PATCH] InstructionSelector --> Instruction --- optimism/src/mips/interpreter.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/optimism/src/mips/interpreter.rs b/optimism/src/mips/interpreter.rs index 897f2c830b..3712c94b51 100644 --- a/optimism/src/mips/interpreter.rs +++ b/optimism/src/mips/interpreter.rs @@ -99,6 +99,7 @@ pub enum ITypeInstruction { } +// InstructionSelectors #[derive(Clone, Copy, Default, Debug, Serialize, Deserialize)] pub struct InstructionSelectors { pub r_type: RTypeInstructionSelectors, @@ -106,24 +107,24 @@ pub struct InstructionSelectors { pub i_type: ITypeInstructionSelectors, } -impl Index for InstructionSelectors { +impl Index for InstructionSelectors { type Output = A; - fn index(&self, idx: InstructionSelector) -> &Self::Output { + fn index(&self, idx: Instruction) -> &Self::Output { match idx { - InstructionSelector::RType(instr) => &self.r_type[instr], - InstructionSelector::JType(instr) => &self.j_type[instr], - InstructionSelector::IType(instr) => &self.i_type[instr], + Instruction::RType(instr) => &self.r_type[instr], + Instruction::JType(instr) => &self.j_type[instr], + Instruction::IType(instr) => &self.i_type[instr], } } } -impl IndexMut for InstructionSelectors { - fn index_mut(&mut self, idx: InstructionSelector) -> &mut Self::Output { +impl IndexMut for InstructionSelectors { + fn index_mut(&mut self, idx: Instruction) -> &mut Self::Output { match idx { - InstructionSelector::RType(instr) => &mut self.r_type[instr], - InstructionSelector::JType(instr) => &mut self.j_type[instr], - InstructionSelector::IType(instr) => &mut self.i_type[instr], + Instruction::RType(instr) => &mut self.r_type[instr], + Instruction::JType(instr) => &mut self.j_type[instr], + Instruction::IType(instr) => &mut self.i_type[instr], } } } @@ -270,7 +271,7 @@ impl IndexMut for RTypeInstructionSelectors { RTypeInstruction::Nor => &mut self.nor, RTypeInstruction::SetLessThan => &mut self.set_less_than, RTypeInstruction::SetLessThanUnsigned => &mut self.set_less_than_unsigned, - _ => /* TODO */ assert!(false) + _ => /* TODO */ panic!("Not implemented") } } } @@ -765,15 +766,15 @@ impl ITypeInstructionSelectors { } } -impl IntoEnumIterator for InstructionSelector { +impl IntoEnumIterator for Instruction { // The underlying type is inexpressible, due to the function types :| type Iterator = Box>; fn iter() -> Self::Iterator { Box::new( RTypeInstruction::iter() - .map(&InstructionSelector::RType) - .chain(JTypeInstruction::iter().map(&InstructionSelector::JType)) - .chain(ITypeInstruction::iter().map(&InstructionSelector::IType)), + .map(&Instruction::RType) + .chain(JTypeInstruction::iter().map(&Instruction::JType)) + .chain(ITypeInstruction::iter().map(&Instruction::IType)), ) } }