(binary_code: Vec<String>, prophet: Option<OlaProphet>)
| 222 | instruction_binary |
| 223 | ))?; |
| 224 | |
| 225 | let is_op1_imm = instruction_u64 & (1 << Self::BIT_SHIFT_OP1_IMM) != 0; |
| 226 | let instruction_length = |
| 227 | if is_op1_imm || opcode == OlaOpcode::MLOAD || opcode == OlaOpcode::MSTORE { |
| 228 | 2 |
| 229 | } else { |
| 230 | 1 |
| 231 | }; |
| 232 | if binary_code.len() != instruction_length { |
| 233 | return Err(format!("decode binary instruction error, length should be {}, but input code length is {}: {}", instruction_length, binary_code.len(), instruction_binary)); |
| 234 | } |
| 235 | let immediate_value = if instruction_length == 2 { |
| 236 | let imm_line = binary_code |
| 237 | .get(1) |
| 238 | .ok_or("Binary code has only 1 string")? |
| 239 | .clone(); |
| 240 | let imm = ImmediateValue::from_str(imm_line.as_str())?; |
| 241 | Some(imm) |
| 242 | } else { |
| 243 | None |
| 244 | }; |
| 245 | |
| 246 | let op0 = all::<OlaRegister>() |
| 247 | .collect::<Vec<_>>() |
| 248 | .iter() |
| 249 | .map(|reg| { |
| 250 | let mask = reg.binary_bit_mask_as_op0(); |
| 251 | let matched = instruction_u64 & mask != 0; |
| 252 | (reg, matched) |
| 253 | }) |
| 254 | .find(|(_reg, matched)| matched.clone()) |
| 255 | .map(|(reg, _matched)| OlaOperand::RegisterOperand { |
| 256 | register: reg.clone(), |
| 257 | }); |
| 258 | |
| 259 | let immediate_value = immediate_value.ok_or("Empty immediate value")?; |
| 260 | let op1 = if is_op1_imm { |
| 261 | Some(OlaOperand::ImmediateOperand { |
| 262 | value: immediate_value, |
| 263 | }) |
| 264 | } else { |
| 265 | let matched_op1_reg = all::<OlaRegister>() |
| 266 | .collect::<Vec<_>>() |
| 267 | .iter() |
| 268 | .map(|reg| { |
| 269 | let mask = reg.binary_bit_mask_as_op1(); |
| 270 | let matched = instruction_u64 & mask != 0; |
| 271 | (reg, matched) |
| 272 | }) |
| 273 | .find(|(_reg, matched)| matched.clone()) |
| 274 | .map(|(reg, _matched)| reg.clone()) |
| 275 | .ok_or("No matched op1 register"); |
| 276 | if opcode == OlaOpcode::MSTORE || opcode == OlaOpcode::MLOAD { |
| 277 | Some(OlaOperand::RegisterWithFactor { |
| 278 | register: matched_op1_reg?, |
| 279 | factor: immediate_value, |
| 280 | }) |
| 281 | } else { |
nothing calls this directly
no test coverage detected