From c39ce65f7dae0abda71afdde2a5f5e8c48306879 Mon Sep 17 00:00:00 2001 From: aprzn Date: Wed, 22 May 2024 04:55:56 -0400 Subject: [PATCH] update Long instruction type to reflect its nature as a special case of Var.2OP --- zing/src/encoding/instruction.rs | 39 ++++++++++++-------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/zing/src/encoding/instruction.rs b/zing/src/encoding/instruction.rs index 88516fc..6ddbe9b 100644 --- a/zing/src/encoding/instruction.rs +++ b/zing/src/encoding/instruction.rs @@ -16,12 +16,8 @@ pub enum Instruction { operand: Operand, opcode: Short1OpOpcode, }, - Long2Op { - operands: (Operand, Operand), - opcode: Long2OpOpcode, - }, Variable2Op { - operands: (Operand, Operand), + operands: Vec, opcode: Variable2OpOpcode, }, VariableVarOp { @@ -122,8 +118,6 @@ make_instruction_type!(Variable2OpOpcode { 28 Throw, }); -type Long2OpOpcode = Variable2OpOpcode; - make_instruction_type!(VariableVarOpOpcode { 0 CallVs, 1 Storew, @@ -273,9 +267,9 @@ pub fn decode_instruction(cursor: &mut SimpleCursor) -> Result Operand::make_small(cursor.read_const().unwrap()), OperandType::Var => Operand::make_var(cursor.read_const().unwrap()), }; - let PotentialStoreBranchText { store, branch, text } = decode_store_branch_text::(cursor, opcode_num); - Long2OpOpcode::from_number(opcode_num, store, branch,text) - .map(|opcode| Instruction::Long2Op { operands: (operand_1, operand_2), opcode }) + let PotentialStoreBranchText { store, branch, text } = decode_store_branch_text::(cursor, opcode_num); + Variable2OpOpcode::from_number(opcode_num, store, branch,text) + .map(|opcode| Instruction::Variable2Op { operands: vec![operand_1, operand_2], opcode }) } fn decode_extended(cursor: &mut SimpleCursor) -> Result { @@ -328,22 +322,17 @@ pub fn decode_instruction(cursor: &mut SimpleCursor) -> Result> 6) & 0b11 { - 0b00 => Operand::make_large(cursor.read_const().unwrap()), - 0b01 => Operand::make_small(cursor.read_const().unwrap()), - 0b10 => Operand::make_var(cursor.read_const().unwrap()), - 0b11 => return Err(InstructionDecodeError::InsufficientOperands), - _ => unreachable!() - }; - let op1 = match (op_descs >> 4) & 0b11 { - 0b00 => Operand::make_large(cursor.read_const().unwrap()), - 0b01 => Operand::make_small(cursor.read_const().unwrap()), - 0b10 => Operand::make_var(cursor.read_const().unwrap()), - 0b11 => return Err(InstructionDecodeError::InsufficientOperands), - _ => unreachable!() - }; - let operands = (op0, op1); + for i in 0..4 { + match (op_descs >> (6 - 2 * i)) & 0b11 { + 0b00 => operands.push(Operand::make_large(cursor.read_const().unwrap())), + 0b01 => operands.push(Operand::make_small(cursor.read_const().unwrap())), + 0b10 => operands.push(Operand::make_var(cursor.read_const().unwrap())), + 0b11 => (), + _ => unreachable!() + }; + } let PotentialStoreBranchText { store, branch, text } = decode_store_branch_text::(cursor, opcode_num); Variable2OpOpcode::from_number(opcode_num, store, branch, text) .map(|opcode| Instruction::Variable2Op { operands, opcode })