diff --git a/src/bin/main.rs b/src/bin/main.rs index 57ecbac8a..cad68d3c6 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -38,7 +38,8 @@ use yew_hooks::prelude::*; // To load in the Fibonacci example, uncomment the CONTENT and fib_model lines // and comment the code, language, and text_model lines. IMPORTANT: // rename fib_model to text_model to have it work. -const CONTENT: &str = include_str!("../../static/assembly_examples/floating_point.asm"); +const CONTENT: &str = include_str!("../../static/assembly_examples/fibonacci.asm"); +const ARCH: AvailableDatapaths = AvailableDatapaths::MIPS; #[derive(Properties, Clone, PartialEq)] struct AppProps { @@ -122,7 +123,7 @@ fn app(props: &AppProps) -> Html { let text_model = text_model.clone(); let memory_text_model = memory_text_model.clone(); // parses through the code to assemble the binary and retrieves programinfo for error marking and mouse hover - let (program_info, assembled) = parser(text_model.get_value()); + let (program_info, assembled) = parser(text_model.get_value(), ARCH); *program_info_ref.borrow_mut() = program_info.clone(); *binary_ref.borrow_mut() = assembled.clone(); pc_limit.set(assembled.len() * 4); @@ -397,7 +398,7 @@ fn app(props: &AppProps) -> Html { } // Update the parsed info for text and data segment views - let (program_info, _) = parser(text_model.get_value()); + let (program_info, _) = parser(text_model.get_value(), ARCH); *program_info_ref.borrow_mut() = program_info; trigger.force_update(); diff --git a/src/parser/assembling.rs b/src/parser/assembling.rs index 3ae1de2bd..4c11fb276 100644 --- a/src/parser/assembling.rs +++ b/src/parser/assembling.rs @@ -20,8 +20,6 @@ use std::collections::HashMap; use super::parser_structs_and_enums::{RISCV_FP_REGISTERS, RISCV_GP_REGISTERS}; -use gloo_console::log; - ///This function takes an instruction whose operands it is supposed to read, the order of expected operand types and then ///the order these operands should be concatenated onto the binary representation of the string ///the function returns the instruction it was given with any errors and the binary of the operands added on. @@ -229,7 +227,6 @@ pub fn read_operands_riscv( //the binary is pushed to the string representations vec. Otherwise, the errors are pushed to the instruction.errors vec. match operand_type { RegisterGP => { - log!("RegisterGP"); instruction.operands[i].token_type = TokenType::RegisterGP; bit_lengths.push(5); @@ -239,8 +236,6 @@ pub fn read_operands_riscv( GeneralPurpose, ); - log!("Register Results: ", format!("{:?}", register_results)); - // Vector holding all register arguments binary_representation.push(register_results.0 as u32); if register_results.1.is_some() { @@ -265,7 +260,6 @@ pub fn read_operands_riscv( UpperImmediate => // Can be used to represent offsets for J-type instructions { - log!("Upper Immediate"); instruction.operands[i].token_type = TokenType::Immediate; bit_lengths.push(20); // 20 bits to represent upper immediates @@ -552,9 +546,6 @@ pub fn read_memory_address_riscv( let immediate_results = read_immediate(offset_str, start_end_columns, 16); let register_results = read_register_riscv(&cleaned_base, start_end_columns, GeneralPurpose); - log!("Immediate: ", format!("{:?}", immediate_results)); - log!("Register: ", format!("{:?}", register_results)); - //any errors found in the read_immediate or read_register functions are collected into a vec //if there were any errors, those are returned let mut return_errors: Vec = Vec::new(); diff --git a/src/parser/parser_assembler_main.rs b/src/parser/parser_assembler_main.rs index b345be4ea..aab92cea1 100644 --- a/src/parser/parser_assembler_main.rs +++ b/src/parser/parser_assembler_main.rs @@ -1,3 +1,4 @@ +use crate::emulation_core::architectures::AvailableDatapaths; use crate::parser::assembling::{assemble_data_binary, read_operands, read_operands_riscv}; use crate::parser::parser_structs_and_enums::ErrorType::*; use crate::parser::parser_structs_and_enums::OperandType::*; @@ -6,135 +7,129 @@ use crate::parser::parser_structs_and_enums::*; use crate::parser::parsing::*; use crate::parser::pseudo_instruction_parsing::{ complete_lw_sw_pseudo_instructions, expand_pseudo_instructions_and_assign_instruction_numbers, + expand_pseudo_instructions_and_assign_instruction_numbers_riscv, }; use std::collections::HashMap; -use gloo_console::log; - ///Parser is the starting function of the parser / assembler process. It takes a string representation of a MIPS /// program and builds the binary of the instructions while cataloging any errors that are found. -pub fn parser(file_string: String) -> (ProgramInfo, Vec) { - // Force MIPS to pass unit tests until I change the function arguments for SWIMv1 test cases`` - let arch = Architecture::MIPS; - - if arch == Architecture::MIPS { - let mut program_info = ProgramInfo { - monaco_line_info: tokenize_program(file_string), - ..Default::default() - }; - - (program_info.instructions, program_info.data) = - separate_data_and_text(&mut program_info.monaco_line_info); - - expand_pseudo_instructions_and_assign_instruction_numbers( - &mut program_info.instructions, - &program_info.data, - &mut program_info.monaco_line_info, - ); - - let vec_of_data = assemble_data_binary(&mut program_info.data); - - let labels: HashMap = - create_label_map(&mut program_info.instructions, &mut program_info.data); - - complete_lw_sw_pseudo_instructions( - &mut program_info.instructions, - &labels, - &mut program_info.monaco_line_info, - ); - - read_instructions( - &mut program_info.instructions, - &labels, - &mut program_info.monaco_line_info, - ); - - program_info.console_out_post_assembly = suggest_error_corrections( - &mut program_info.instructions, - &mut program_info.data, - &labels, - &mut program_info.monaco_line_info, - ); - - let (binary, data_starting_point) = - create_binary_vec(program_info.instructions.clone(), vec_of_data); - - for entry in &program_info.monaco_line_info { - program_info - .updated_monaco_string - .push_str(&format!("{}\n", entry.updated_monaco_string)); +pub fn parser(file_string: String, arch: AvailableDatapaths) -> (ProgramInfo, Vec) { + match arch { + AvailableDatapaths::MIPS => { + let mut program_info = ProgramInfo { + monaco_line_info: tokenize_program(file_string), + ..Default::default() + }; + + (program_info.instructions, program_info.data) = + separate_data_and_text(&mut program_info.monaco_line_info); + + expand_pseudo_instructions_and_assign_instruction_numbers( + &mut program_info.instructions, + &program_info.data, + &mut program_info.monaco_line_info, + ); + + let vec_of_data = assemble_data_binary(&mut program_info.data); + + let labels: HashMap = + create_label_map(&mut program_info.instructions, &mut program_info.data); + + complete_lw_sw_pseudo_instructions( + &mut program_info.instructions, + &labels, + &mut program_info.monaco_line_info, + ); + + read_instructions( + &mut program_info.instructions, + &labels, + &mut program_info.monaco_line_info, + ); + + program_info.console_out_post_assembly = suggest_error_corrections( + &mut program_info.instructions, + &mut program_info.data, + &labels, + &mut program_info.monaco_line_info, + arch, + ); + + let (binary, data_starting_point) = + create_binary_vec(program_info.instructions.clone(), vec_of_data); + + for entry in &program_info.monaco_line_info { + program_info + .updated_monaco_string + .push_str(&format!("{}\n", entry.updated_monaco_string)); + } + + for instruction in program_info.instructions.clone() { + program_info + .address_to_line_number + .push(instruction.line_number); + } + + program_info.pc_starting_point = determine_pc_starting_point(labels); + program_info.data_starting_point = data_starting_point; + + (program_info.clone(), binary) } + AvailableDatapaths::RISCV => { + let mut program_info = ProgramInfo { + monaco_line_info: tokenize_program(file_string), + ..Default::default() + }; - for instruction in program_info.instructions.clone() { - program_info - .address_to_line_number - .push(instruction.line_number); - } + (program_info.instructions, program_info.data) = + separate_data_and_text(&mut program_info.monaco_line_info); - program_info.pc_starting_point = determine_pc_starting_point(labels); - program_info.data_starting_point = data_starting_point; - - (program_info.clone(), binary) - } else { - let mut program_info = ProgramInfo { - monaco_line_info: tokenize_program(file_string), - ..Default::default() - }; - - (program_info.instructions, program_info.data) = - separate_data_and_text(&mut program_info.monaco_line_info); - - // Implement a RISC-V version - /*expand_pseudo_instructions_and_assign_instruction_numbers( - &mut program_info.instructions, - &program_info.data, - &mut program_info.monaco_line_info, - );*/ - - let vec_of_data = assemble_data_binary(&mut program_info.data); - - let labels: HashMap = - create_label_map(&mut program_info.instructions, &mut program_info.data); - - // Implement a RISC-V version - /*complete_lw_sw_pseudo_instructions( - &mut program_info.instructions, - &labels, - &mut program_info.monaco_line_info, - );*/ - - read_instructions_riscv( - &mut program_info.instructions, - &labels, - &mut program_info.monaco_line_info, - ); - - program_info.console_out_post_assembly = suggest_error_corrections( - &mut program_info.instructions, - &mut program_info.data, - &labels, - &mut program_info.monaco_line_info, - ); - - let (binary, data_starting_point) = - create_binary_vec(program_info.instructions.clone(), vec_of_data); - - for entry in &program_info.monaco_line_info { - program_info - .updated_monaco_string - .push_str(&format!("{}\n", entry.updated_monaco_string)); - } + // Implement a RISC-V version + expand_pseudo_instructions_and_assign_instruction_numbers_riscv( + &mut program_info.instructions, + &program_info.data, + &mut program_info.monaco_line_info, + ); - for instruction in program_info.instructions.clone() { - program_info - .address_to_line_number - .push(instruction.line_number); - } + let vec_of_data = assemble_data_binary(&mut program_info.data); + + let labels: HashMap = + create_label_map(&mut program_info.instructions, &mut program_info.data); + + read_instructions_riscv( + &mut program_info.instructions, + &labels, + &mut program_info.monaco_line_info, + ); + + program_info.console_out_post_assembly = suggest_error_corrections( + &mut program_info.instructions, + &mut program_info.data, + &labels, + &mut program_info.monaco_line_info, + arch, + ); + + let (binary, data_starting_point) = + create_binary_vec(program_info.instructions.clone(), vec_of_data); - program_info.pc_starting_point = determine_pc_starting_point(labels); - program_info.data_starting_point = data_starting_point; + for entry in &program_info.monaco_line_info { + program_info + .updated_monaco_string + .push_str(&format!("{}\n", entry.updated_monaco_string)); + } + + for instruction in program_info.instructions.clone() { + program_info + .address_to_line_number + .push(instruction.line_number); + } + + program_info.pc_starting_point = determine_pc_starting_point(labels); + program_info.data_starting_point = data_starting_point; - (program_info.clone(), binary) + (program_info.clone(), binary) + } } } @@ -1529,7 +1524,7 @@ pub fn read_instructions( } _ => { - if UNSUPPORTED_INSTRUCTIONS.contains(&&*instruction.operator.token_name) { + if UNSUPPORTED_INSTRUCTIONS_MIPS.contains(&&*instruction.operator.token_name) { instruction.errors.push(Error { error_name: UnsupportedInstruction, token_causing_error: instruction.operator.token_name.to_string(), @@ -1546,7 +1541,6 @@ pub fn read_instructions( } } } - //print_instruction_contents(instruction.clone()); } } @@ -1558,17 +1552,8 @@ pub fn read_instructions_riscv( for mut instruction in &mut instruction_list.iter_mut() { match &*instruction.operator.token_name.to_lowercase() { "add" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -1581,10 +1566,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -1599,17 +1580,8 @@ pub fn read_instructions_riscv( } } "sub" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0100000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -1622,10 +1594,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -1640,17 +1608,8 @@ pub fn read_instructions_riscv( } } "sll" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -1663,10 +1622,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -1681,17 +1636,8 @@ pub fn read_instructions_riscv( } } "slt" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -1704,10 +1650,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -1722,17 +1664,8 @@ pub fn read_instructions_riscv( } } "sltu" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -1745,10 +1678,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -1763,17 +1692,8 @@ pub fn read_instructions_riscv( } } "xor" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -1786,10 +1706,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -1804,17 +1720,8 @@ pub fn read_instructions_riscv( } } "srl" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -1827,10 +1734,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -1845,17 +1748,8 @@ pub fn read_instructions_riscv( } } "sra" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0100000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -1868,10 +1762,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -1886,17 +1776,8 @@ pub fn read_instructions_riscv( } } "or" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -1909,10 +1790,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -1927,17 +1804,8 @@ pub fn read_instructions_riscv( } } "and" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -1950,10 +1818,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -1970,11 +1834,6 @@ pub fn read_instructions_riscv( "addi" => // This instruction requires the 12-bit immediate to be sign extended before moving to the emulator's register { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, RegisterGP, Immediate], @@ -1986,10 +1845,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2004,11 +1859,6 @@ pub fn read_instructions_riscv( } } "slti" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, RegisterGP, Immediate], @@ -2020,10 +1870,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2038,11 +1884,6 @@ pub fn read_instructions_riscv( } } "sltiu" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, RegisterGP, Immediate], @@ -2054,10 +1895,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2072,11 +1909,6 @@ pub fn read_instructions_riscv( } } "xori" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, RegisterGP, Immediate], @@ -2088,10 +1920,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2106,11 +1934,6 @@ pub fn read_instructions_riscv( } } "ori" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, RegisterGP, Immediate], @@ -2122,10 +1945,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2140,11 +1959,6 @@ pub fn read_instructions_riscv( } } "andi" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, RegisterGP, Immediate], @@ -2156,10 +1970,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2174,11 +1984,6 @@ pub fn read_instructions_riscv( } } "slli" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b00000, 5); // Check if the next 2 bits are needed @@ -2193,10 +1998,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2211,11 +2012,6 @@ pub fn read_instructions_riscv( } } "srli" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b00000, 5); // Check if the next 2 bits are needed @@ -2230,10 +2026,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2248,11 +2040,6 @@ pub fn read_instructions_riscv( } } "srai" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b01000, 5); // Check if the next 2 bits are needed @@ -2267,10 +2054,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2285,11 +2068,6 @@ pub fn read_instructions_riscv( } } "lb" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, MemoryAddress], @@ -2301,10 +2079,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0000011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2319,11 +2093,6 @@ pub fn read_instructions_riscv( } } "lh" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, MemoryAddress], @@ -2335,10 +2104,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0000011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2353,11 +2118,6 @@ pub fn read_instructions_riscv( } } "lw" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, MemoryAddress], @@ -2369,10 +2129,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0000011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2387,11 +2143,6 @@ pub fn read_instructions_riscv( } } "lbu" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, MemoryAddress], @@ -2403,10 +2154,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0000011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2421,11 +2168,6 @@ pub fn read_instructions_riscv( } } "lhu" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, MemoryAddress], @@ -2437,10 +2179,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0000011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2455,11 +2193,6 @@ pub fn read_instructions_riscv( } } "sb" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, MemoryAddress], @@ -2471,14 +2204,9 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0100011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); // Encoded as I-type, but needs reordering for S-type instruction.binary = immediate_to_stored(instruction.binary); - log!("3. Reordered: ", format!("{:032b}", instruction.binary)); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2495,11 +2223,6 @@ pub fn read_instructions_riscv( } } "sh" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, MemoryAddress], @@ -2511,14 +2234,9 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0100011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); // Encoded as I-type, but needs reordering for S-type instruction.binary = immediate_to_stored(instruction.binary); - log!("3. Reordered: ", format!("{:032b}", instruction.binary)); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2535,11 +2253,6 @@ pub fn read_instructions_riscv( } } "sw" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, MemoryAddress], @@ -2551,14 +2264,9 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0100011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); // Encoded as I-type, but needs reordering for S-type instruction.binary = immediate_to_stored(instruction.binary); - log!("3. Reordered: ", format!("{:032b}", instruction.binary)); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2574,15 +2282,7 @@ pub fn read_instructions_riscv( monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); } } - "jal" => - // Finish J instructions - { - log!("jal instruction"); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - + "jal" => { // Read as U-type instruction and reorder immediate value after read_operands_riscv( instruction, @@ -2595,17 +2295,9 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1101111, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); // Reorder immediate instruction.binary = upper_to_jump(instruction.binary); - log!( - "3. Reordered Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2620,11 +2312,6 @@ pub fn read_instructions_riscv( } } "jalr" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, MemoryAddress], @@ -2636,10 +2323,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1100111, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2654,11 +2337,6 @@ pub fn read_instructions_riscv( } } "beq" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, RegisterGP, Immediate], @@ -2670,16 +2348,8 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1100011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); instruction.binary = immediate_to_branch(instruction.binary); - log!( - "3. Reordered Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2695,11 +2365,6 @@ pub fn read_instructions_riscv( } } "bne" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, RegisterGP, Immediate], @@ -2711,16 +2376,8 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1100011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); instruction.binary = immediate_to_branch(instruction.binary); - log!( - "3. Reordered Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2736,11 +2393,6 @@ pub fn read_instructions_riscv( } } "blt" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, RegisterGP, Immediate], @@ -2752,16 +2404,8 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1100011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); instruction.binary = immediate_to_branch(instruction.binary); - log!( - "3. Reordered Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2776,11 +2420,6 @@ pub fn read_instructions_riscv( } } "bge" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, RegisterGP, Immediate], @@ -2792,16 +2431,8 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1100011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); instruction.binary = immediate_to_branch(instruction.binary); - log!( - "3. Reordered Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2816,11 +2447,6 @@ pub fn read_instructions_riscv( } } "bltu" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, RegisterGP, Immediate], @@ -2832,16 +2458,8 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1100011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); instruction.binary = immediate_to_branch(instruction.binary); - log!( - "3. Reordered Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2856,11 +2474,6 @@ pub fn read_instructions_riscv( } } "bgeu" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, RegisterGP, Immediate], @@ -2872,16 +2485,8 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1100011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); instruction.binary = immediate_to_branch(instruction.binary); - log!( - "3. Reordered Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2896,17 +2501,8 @@ pub fn read_instructions_riscv( } } "ecall" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // ecall instruction encoding does not change instruction.binary = 0b00000000000000000000000001110011; - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2921,17 +2517,8 @@ pub fn read_instructions_riscv( } } "ebreak" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // ebreak instruction encoding does not change instruction.binary = 0b00000000000100000000000001110011; - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2946,17 +2533,8 @@ pub fn read_instructions_riscv( } } "uret" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // uret instruction encoding does not change instruction.binary = 0b00000000001000000000000001110011; - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2971,17 +2549,8 @@ pub fn read_instructions_riscv( } } "sret" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // uret instruction encoding does not change instruction.binary = 0b00010000001000000000000001110011; - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -2996,17 +2565,8 @@ pub fn read_instructions_riscv( } } "mret" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // uret instruction encoding does not change instruction.binary = 0b00110000001000000000000001110011; - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3021,17 +2581,8 @@ pub fn read_instructions_riscv( } } "wfi" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // uret instruction encoding does not change instruction.binary = 0b00010000010100000000000001110011; - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3046,17 +2597,8 @@ pub fn read_instructions_riscv( } } "fence.i" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // fence.i instruction encoding does not change instruction.binary = 0b00000000000000000001000000001111; - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3071,11 +2613,6 @@ pub fn read_instructions_riscv( } } "lui" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, UpperImmediate], @@ -3087,10 +2624,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110111, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3105,12 +2638,6 @@ pub fn read_instructions_riscv( } } "auipc" => { - log!("auipc instruction"); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, UpperImmediate], @@ -3122,10 +2649,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0010111, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3142,11 +2665,6 @@ pub fn read_instructions_riscv( "addiw" => // Start of RV64I Instructions { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, RegisterGP, Immediate], @@ -3158,10 +2676,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0011011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3176,11 +2690,6 @@ pub fn read_instructions_riscv( } } "slliw" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000000, 7); @@ -3195,10 +2704,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0011011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3213,11 +2718,6 @@ pub fn read_instructions_riscv( } } "srliw" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000000, 7); @@ -3232,10 +2732,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0011011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3250,11 +2746,6 @@ pub fn read_instructions_riscv( } } "sraiw" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b01000, 7); @@ -3269,10 +2760,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0011011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3287,17 +2774,8 @@ pub fn read_instructions_riscv( } } "addw" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -3310,10 +2788,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0111011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3328,17 +2802,8 @@ pub fn read_instructions_riscv( } } "subw" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0100000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -3351,10 +2816,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0111011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3369,17 +2830,8 @@ pub fn read_instructions_riscv( } } "sllw" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -3392,10 +2844,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0111011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3410,17 +2858,8 @@ pub fn read_instructions_riscv( } } "srlw" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -3433,10 +2872,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0111011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3451,17 +2886,8 @@ pub fn read_instructions_riscv( } } "sraw" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0100000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -3474,10 +2900,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0111011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3492,11 +2914,6 @@ pub fn read_instructions_riscv( } } "lwu" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, MemoryAddress], @@ -3508,10 +2925,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0000011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3526,11 +2939,6 @@ pub fn read_instructions_riscv( } } "ld" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, MemoryAddress], @@ -3542,10 +2950,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0000011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3561,11 +2965,6 @@ pub fn read_instructions_riscv( } } "sd" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterGP, MemoryAddress], @@ -3577,14 +2976,9 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0100011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); // Encoded as I-type, but needs reordering for S-type instruction.binary = immediate_to_stored(instruction.binary); - log!("3. Reordered: ", format!("{:032b}", instruction.binary)); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3602,17 +2996,8 @@ pub fn read_instructions_riscv( "mul" => // Start of RV32M { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -3625,10 +3010,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3643,17 +3024,8 @@ pub fn read_instructions_riscv( } } "mulh" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -3666,10 +3038,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3685,17 +3053,8 @@ pub fn read_instructions_riscv( } } "mulhsu" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -3708,10 +3067,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3726,17 +3081,8 @@ pub fn read_instructions_riscv( } } "mulhu" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -3749,10 +3095,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3767,17 +3109,8 @@ pub fn read_instructions_riscv( } } "div" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -3790,10 +3123,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3808,17 +3137,8 @@ pub fn read_instructions_riscv( } } "divu" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -3831,10 +3151,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3849,17 +3165,8 @@ pub fn read_instructions_riscv( } } "rem" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -3872,10 +3179,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3890,17 +3193,8 @@ pub fn read_instructions_riscv( } } "remu" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -3913,10 +3207,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0110011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3933,17 +3223,8 @@ pub fn read_instructions_riscv( "mulw" => // Start of RV64M { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -3956,10 +3237,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0111011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -3974,17 +3251,8 @@ pub fn read_instructions_riscv( } } "divw" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -3997,10 +3265,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0111011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4015,17 +3279,8 @@ pub fn read_instructions_riscv( } } "divuw" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4038,10 +3293,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0111011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4056,17 +3307,8 @@ pub fn read_instructions_riscv( } } "remw" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4079,10 +3321,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0111011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4097,17 +3335,8 @@ pub fn read_instructions_riscv( } } "remuw" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct7 instruction.binary = append_binary(instruction.binary, 0b0000001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4120,10 +3349,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0111011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4137,14 +3362,8 @@ pub fn read_instructions_riscv( monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); } } - "fmadd.s" => // Start of RV32F - { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - + "fmadd.s" => { read_operands_riscv( instruction, vec![RegisterFP, RegisterFP, RegisterFP, RegisterFP], @@ -4156,10 +3375,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1000011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4174,11 +3389,6 @@ pub fn read_instructions_riscv( } } "fmsub.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterFP, RegisterFP, RegisterFP, RegisterFP], @@ -4190,10 +3400,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1000111, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4208,11 +3414,6 @@ pub fn read_instructions_riscv( } } "fnmsub.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterFP, RegisterFP, RegisterFP, RegisterFP], @@ -4224,10 +3425,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1001011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4242,11 +3439,6 @@ pub fn read_instructions_riscv( } } "fnmadd.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterFP, RegisterFP, RegisterFP, RegisterFP], @@ -4258,10 +3450,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1001111, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4276,17 +3464,8 @@ pub fn read_instructions_riscv( } } "fadd.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b0000000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4299,10 +3478,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4318,17 +3493,8 @@ pub fn read_instructions_riscv( } } "fsub.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b0000100, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4341,10 +3507,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4360,17 +3522,8 @@ pub fn read_instructions_riscv( } } "fmul.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b0001000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4383,10 +3536,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4402,17 +3551,8 @@ pub fn read_instructions_riscv( } } "fdiv.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b0001100, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4425,10 +3565,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4444,17 +3580,8 @@ pub fn read_instructions_riscv( } } "fsqrt.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + padding for absent register instruction.binary = append_binary(instruction.binary, 0b010110000000, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4467,10 +3594,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4485,17 +3608,8 @@ pub fn read_instructions_riscv( } } "fsgnj.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b0010000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4508,10 +3622,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4526,17 +3636,8 @@ pub fn read_instructions_riscv( } } "fsgnjn.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b0010000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4549,10 +3650,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4567,17 +3664,8 @@ pub fn read_instructions_riscv( } } "fsgnjx.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b0010000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4590,10 +3678,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4608,17 +3692,8 @@ pub fn read_instructions_riscv( } } "fmin.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b0010100, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4631,10 +3706,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4651,17 +3722,8 @@ pub fn read_instructions_riscv( } } "fmax.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b0010100, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4674,10 +3736,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4694,17 +3752,8 @@ pub fn read_instructions_riscv( } } "fcvt.w.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + padding for absent register instruction.binary = append_binary(instruction.binary, 0b110000000000, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4717,10 +3766,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4735,17 +3780,8 @@ pub fn read_instructions_riscv( } } "fcvt.wu.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + rs2 instruction.binary = append_binary(instruction.binary, 0b110000000001, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4758,10 +3794,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4776,17 +3808,8 @@ pub fn read_instructions_riscv( } } "fmv.x.w" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + rs2 instruction.binary = append_binary(instruction.binary, 0b111000000000, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4799,10 +3822,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4817,17 +3836,8 @@ pub fn read_instructions_riscv( } } "feq.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b1010000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4840,10 +3850,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4858,17 +3864,8 @@ pub fn read_instructions_riscv( } } "flt.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b1010000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4881,10 +3878,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4899,17 +3892,8 @@ pub fn read_instructions_riscv( } } "fle.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b1010000, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4922,10 +3906,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4940,17 +3920,8 @@ pub fn read_instructions_riscv( } } "fclass.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + rs2 instruction.binary = append_binary(instruction.binary, 0b111000000000, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -4963,10 +3934,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -4981,17 +3948,8 @@ pub fn read_instructions_riscv( } } "fcvt.s.w" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + rs2 instruction.binary = append_binary(instruction.binary, 0b110100000000, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5004,10 +3962,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5022,17 +3976,8 @@ pub fn read_instructions_riscv( } } "fcvt.s.wu" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + rs2 instruction.binary = append_binary(instruction.binary, 0b110100000001, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5045,10 +3990,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5063,17 +4004,8 @@ pub fn read_instructions_riscv( } } "fmv.w.x" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + rs2 instruction.binary = append_binary(instruction.binary, 0b111100000000, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5086,10 +4018,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5104,11 +4032,6 @@ pub fn read_instructions_riscv( } } "fmadd.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterFP, RegisterFP, RegisterFP, RegisterFP], @@ -5120,10 +4043,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1000011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5138,11 +4057,6 @@ pub fn read_instructions_riscv( } } "fmsub.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterFP, RegisterFP, RegisterFP, RegisterFP], @@ -5154,10 +4068,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1000111, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5172,11 +4082,6 @@ pub fn read_instructions_riscv( } } "fnmsub.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterFP, RegisterFP, RegisterFP, RegisterFP], @@ -5188,10 +4093,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1001011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5206,11 +4107,6 @@ pub fn read_instructions_riscv( } } "fnmadd.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterFP, RegisterFP, RegisterFP, RegisterFP], @@ -5222,10 +4118,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1001111, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5240,17 +4132,8 @@ pub fn read_instructions_riscv( } } "fadd.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b0000001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5263,10 +4146,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5282,17 +4161,8 @@ pub fn read_instructions_riscv( } } "fsub.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b0000101, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5305,10 +4175,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5324,17 +4190,8 @@ pub fn read_instructions_riscv( } } "fmul.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b0001001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5347,10 +4204,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5366,17 +4219,8 @@ pub fn read_instructions_riscv( } } "fdiv.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b0001101, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5389,10 +4233,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5408,17 +4248,8 @@ pub fn read_instructions_riscv( } } "fsqrt.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + rs2 instruction.binary = append_binary(instruction.binary, 0b010110100000, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5431,10 +4262,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5449,17 +4276,8 @@ pub fn read_instructions_riscv( } } "fsgnj.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b0010001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5472,10 +4290,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5490,17 +4304,8 @@ pub fn read_instructions_riscv( } } "fsgnjn.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b0010001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5513,10 +4318,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5531,17 +4332,8 @@ pub fn read_instructions_riscv( } } "fsgnjx.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b0010001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5554,10 +4346,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5572,17 +4360,8 @@ pub fn read_instructions_riscv( } } "fmin.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b0010101, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5595,10 +4374,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5615,17 +4390,8 @@ pub fn read_instructions_riscv( } } "fmax.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b0010101, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5638,10 +4404,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5658,17 +4420,8 @@ pub fn read_instructions_riscv( } } "fcvt.s.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + rs2 instruction.binary = append_binary(instruction.binary, 0b010000000001, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5681,10 +4434,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5699,17 +4448,8 @@ pub fn read_instructions_riscv( } } "fcvt.d.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + rs2 instruction.binary = append_binary(instruction.binary, 0b010000100000, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5722,10 +4462,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5740,17 +4476,8 @@ pub fn read_instructions_riscv( } } "feq.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b1010001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5763,10 +4490,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5781,17 +4504,8 @@ pub fn read_instructions_riscv( } } "flt.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b1010001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5804,10 +4518,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5822,17 +4532,8 @@ pub fn read_instructions_riscv( } } "fle.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt instruction.binary = append_binary(instruction.binary, 0b1010001, 7); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5845,10 +4546,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5863,17 +4560,8 @@ pub fn read_instructions_riscv( } } "fclass.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + rs2 instruction.binary = append_binary(instruction.binary, 0b111000100000, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5886,10 +4574,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5904,17 +4588,8 @@ pub fn read_instructions_riscv( } } "fcvt.w.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + rs2 instruction.binary = append_binary(instruction.binary, 0b110000100000, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5927,10 +4602,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5945,17 +4616,8 @@ pub fn read_instructions_riscv( } } "fcvt.wu.d" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + rs2 instruction.binary = append_binary(instruction.binary, 0b110000100001, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -5968,10 +4630,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -5986,17 +4644,8 @@ pub fn read_instructions_riscv( } } "fcvt.d.w" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + rs2 instruction.binary = append_binary(instruction.binary, 0b110100100000, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -6009,10 +4658,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -6027,17 +4672,8 @@ pub fn read_instructions_riscv( } } "fcvt.d.wu" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + rs2 instruction.binary = append_binary(instruction.binary, 0b110100100001, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -6050,10 +4686,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -6068,11 +4700,6 @@ pub fn read_instructions_riscv( } } "flw" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterFP, MemoryAddress], @@ -6084,10 +4711,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0000111, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -6102,11 +4725,6 @@ pub fn read_instructions_riscv( } } "fsw" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterFP, MemoryAddress], @@ -6118,14 +4736,9 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0100111, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); // Encoded as I-type, but needs reordering for S-type instruction.binary = immediate_to_stored(instruction.binary); - log!("3. Reordered: ", format!("{:032b}", instruction.binary)); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -6140,11 +4753,6 @@ pub fn read_instructions_riscv( } } "fld" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterFP, MemoryAddress], @@ -6156,10 +4764,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0000111, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -6174,11 +4778,6 @@ pub fn read_instructions_riscv( } } "fsd" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - read_operands_riscv( instruction, vec![RegisterFP, MemoryAddress], @@ -6190,14 +4789,9 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b0100111, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); // Encoded as I-type, but needs reordering for S-type instruction.binary = immediate_to_stored(instruction.binary); - log!("3. Reordered: ", format!("{:032b}", instruction.binary)); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -6212,17 +4806,8 @@ pub fn read_instructions_riscv( } } "fcvt.l.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + rs2 instruction.binary = append_binary(instruction.binary, 0b110000000010, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -6235,10 +4820,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -6253,17 +4834,8 @@ pub fn read_instructions_riscv( } } "fcvt.lu.s" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + rs2 instruction.binary = append_binary(instruction.binary, 0b110000000011, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -6276,10 +4848,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -6294,17 +4862,8 @@ pub fn read_instructions_riscv( } } "fcvt.s.l" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + rs2 instruction.binary = append_binary(instruction.binary, 0b110100000010, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -6317,10 +4876,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -6335,17 +4890,8 @@ pub fn read_instructions_riscv( } } "fcvt.s.lu" => { - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); - // Funct5 + fmt + rs2 instruction.binary = append_binary(instruction.binary, 0b110100000011, 12); - log!( - "Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); read_operands_riscv( instruction, @@ -6358,10 +4904,6 @@ pub fn read_instructions_riscv( // Opcode instruction.binary = append_binary(instruction.binary, 0b1010011, 7); - log!( - "2. Instruction Binary: ", - format!("{:032b}", instruction.binary) - ); //Pseudo-instructions already have text in mouse_hover_string so we check if there's text there already before adding in the blurb if monaco_line_info[instruction.line_number] @@ -6376,7 +4918,7 @@ pub fn read_instructions_riscv( } } _ => { - if UNSUPPORTED_INSTRUCTIONS.contains(&&*instruction.operator.token_name) { + if UNSUPPORTED_INSTRUCTIONS_RISCV.contains(&&*instruction.operator.token_name) { instruction.errors.push(Error { error_name: UnsupportedInstruction, token_causing_error: instruction.operator.token_name.to_string(), @@ -6404,13 +4946,8 @@ fn immediate_to_stored(mut bin: u32) -> u32 { // Extract bits 11-7 from the second segment let rs2 = (bin >> 7) & 0b11111; - log!("Bits to move (24-20): ", format!("{:05b}", lower_imm)); - log!("Bits to move (11-7): ", format!("{:05b}", rs2)); - // Clear bits 24-20 and 11-7 - bin &= !((0b11111 << 20) | (0b11111 << 6)); - - log!("Cleared bits: ", format!("{:032b}", bin)); + bin &= !((0b11111 << 20) | (0b111111 << 6)); // Move bits 24-20 to positions 11-7 let moved_imm = lower_imm << 7; @@ -6427,14 +4964,11 @@ fn immediate_to_stored(mut bin: u32) -> u32 { // Converts an I-type instruction to B-type instruction // Easier to encode in this manner fn immediate_to_branch(mut bin: u32) -> u32 { - log!("Binary: ", format!("{:032b}", bin)); - log!("Immediate: ", format!("{:012b}", (bin >> 20))); - // Extract bits imm[4:1] from the immediate, last bit is ignored let lower_imm = (bin >> 21) & 0b1111; // Extract imm[10:5] - let upper_imm = (bin >> 24) & 0b111111; + let upper_imm = (bin >> 25) & 0b111111; // Extract bit 11 and bit 12 let bit_11 = (bin >> 30) & 0b1; @@ -6470,28 +5004,25 @@ fn immediate_to_branch(mut bin: u32) -> u32 { // Reorder the immediate value to comply with J-type format fn upper_to_jump(mut bin: u32) -> u32 { - // Extract bits 24-20 from the first segment - let lower_imm = (bin >> 20) & 0b11111; + // Extract bits immediate + let imm = bin >> 12; - // Extract bits 11-7 from the second segment - let rs2 = (bin >> 7) & 0b11111; + // Extract bits imm[1-10] + let lower_imm = (imm >> 1) & 0b1111111111; - log!("Bits to move (24-20): ", format!("{:05b}", lower_imm)); - log!("Bits to move (11-7): ", format!("{:05b}", rs2)); + // Extracts bits imm[12:19] + let upper_imm = imm >> 12; - // Clear bits 24-20 and 11-7 - bin &= !((0b11111 << 20) | (0b11111 << 6)); + // Extract bit imm[11] + let bit_11 = (imm >> 11) & 1; - log!("Cleared bits: ", format!("{:032b}", bin)); + // Extract bit imm[20] + let bit_20 = (imm >> 20) & 1; - // Move bits 24-20 to positions 11-7 - let moved_imm = lower_imm << 7; + // Clear bits [12-31] + bin &= !(0b11111111111111111111 << 12); - // Move bits 11-7 to positions 24-20 - let moved_rs2 = rs2 << 20; - - // Combine the manipulated bits - bin |= moved_imm | moved_rs2; + bin |= (upper_imm << 12) | (bit_11 << 20) | (lower_imm << 21) | (bit_20 << 31); bin } diff --git a/src/parser/parser_structs_and_enums.rs b/src/parser/parser_structs_and_enums.rs index a8a41d57d..2b8b52ad9 100644 --- a/src/parser/parser_structs_and_enums.rs +++ b/src/parser/parser_structs_and_enums.rs @@ -18,13 +18,6 @@ pub struct ProgramInfo { pub data_starting_point: usize, } -#[derive(Clone, Debug, Default, Eq, PartialEq)] -pub enum Architecture { - #[default] - MIPS, - RISCV, -} - #[derive(Clone, Debug, Default, Eq, PartialEq)] ///This struct holds all the information we gather in the parser & assembler about a single line the user wrote pub struct MonacoLineInfo { @@ -262,7 +255,7 @@ pub enum OperandType { ShiftAmount, } -pub const SUPPORTED_INSTRUCTIONS: [&str; 64] = [ +pub const SUPPORTED_INSTRUCTIONS_MIPS: [&str; 64] = [ // MIPS Instructions "add", "add.d", "add.s", "addi", "addiu", "addu", "and", "andi", "aui", "b", "bc1f", "bc1t", "beq", "bne", "c.eq.d", "c.eq.s", "c.le.d", "c.le.s", "c.lt.d", "c.lt.s", "c.nge.d", "c.nge.s", @@ -270,10 +263,149 @@ pub const SUPPORTED_INSTRUCTIONS: [&str; 64] = [ "div", "div.d", "div.s", "dmfc1", "dmtc1", "dmul", "dmulu", "dsub", "dsubu", "j", "jal", "jalr", "jr", "lui", "lw", "lwc1", "mfc1", "mtc1", "mul", "mul.d", "mul.s", "nop", "or", "ori", "sll", "slt", "sltu", "sub", "sub.d", "sub.s", "sw", "swc1", - // RISC-V Instructions ]; -pub const UNSUPPORTED_INSTRUCTIONS: [&str; 408] = [ +pub const SUPPORTED_INSTRUCTIONS_RISCV: [&str; 131] = [ + // RV32I + "lui", + "auipc", + "addi", + "slti", + "xori", + "ori", + "andi", + "slli", + "srli", + "srai", + "add", + "sub", + "sll", + "slt", + "sltu", + "cor", + "srl", + "sra", + "or", + "and", + "fence", + "fence.i", + "csrrw", + "csrrs", + "csrrc", + "csrrwi", + "csrrsi", + "csrrci", + "ecall", + "ebreak", + "uret", + "sret", + "mret", + "wfi", + "sfence.vma", + "lb", + "lh", + "lw", + "lbu", + "lhu", + "sb", + "sh", + "sw", + "jal", + "jalr", + "beq", + "bne", + "blt", + "bge", + "bltu", + "bgeu", + // RV64I + "addiw", + "slliw", + "srliw", + "addw", + "subw", + "sllw", + "srlw", + "sraw", + "lwu", + "ld", + "sd", + // RV32M + "mul", + "mulh", + "mulhsu", + "mulhu", + "div", + "divu", + "rem", + "remu", + // RV64M + "mulw", + "divw", + "divuw", + "remw", + "remuw", + // RV32F + "fmadd.s", + "fmsub.s", + "fnmsub.s", + "fnmadd.s", + "fadd.s", + "fsub.s", + "fmul.s", + "fdiv.s", + "fsqrt.s", + "fsgnj.s", + "fsgnjn.s", + "fsgnjx.s", + "fmin.s", + "fmax.s", + "fcvt.w.s", + "fcvt.wu.s", + "fmv.x.w", + "feq.s", + "flt.s", + "fle.s", + "fclass.s", + "fcvt.s.w", + "fcvt.s.wu", + "fmv.w.x", + "fmadd.d", + "fmsub.d", + "fnmadd.d", + "fnmsub.d", + "fadd.d", + "fsub.d", + "fmul.d", + "fdiv.d", + "fsqrt.d", + "fsgnj.d", + "fsgnjn.d", + "fsgnjx.d", + "fmin.d", + "fmax.d", + "fcvt.s.d", + "fcvt.d.s", + "feq.d", + "flt.d", + "fle.d", + "fclass.d", + "fcvt.w.d", + "fcvt.wu.d", + "fcvt.d.w", + "fcvt.d.wu", + "flw", + "fsw", + "fld", + "fsd", + // RV64F + "fcvt.l.s", + "fcvt.lu.s", + "fcvt.s.l", + "fcvt.s.lu", +]; + +pub const UNSUPPORTED_INSTRUCTIONS_MIPS: [&str; 408] = [ // MIPS Instructions "abs.d", "abs.ps", @@ -686,6 +818,78 @@ pub const UNSUPPORTED_INSTRUCTIONS: [&str; 408] = [ // RISC-V Instructions ]; +pub const UNSUPPORTED_INSTRUCTIONS_RISCV: [&str; 69] = [ + "lr.w", + "sc.w", + "amoswap.w", + "amoadd.w", + "amoxor.w", + "amoand.w", + "amomin.w", + "amomax.w", + "amominu.w", + "amomaxu.w", + "lr.d", + "sc.d", + "amoswap.d", + "amoadd.d", + "amoxor.d", + "amoand.d", + "amoor.d", + "amomin.d", + "amomax.d", + "amominu.d", + "amomaxu.d", + "fcvt.l.d", + "scvt.lu.d", + "fmv.x.d", + "fcvt.d.l", + "fcvt.d.lu", + "fmv.d.x", + "c.addi4spn", + "c.fld", + "c.lw", + "c.flw", + "c.ld", + "c.fsd", + "c.sw", + "c.fsw", + "c.sd", + "c.nop", + "c.addi", + "c.jal", + "c.addiw", + "c.li", + "c.addi16sp", + "c.lui", + "c.srli", + "c.srai", + "c.andi", + "c.sub", + "c.xor", + "c.or", + "c.and", + "c.subw", + "c.addw", + "c.j", + "c.beqz", + "c.bnez", + "c.slli", + "c.fldsp", + "c.lwsp", + "c.flwsp", + "c.ldsp", + "c.jr", + "c.mv", + "c.ebreak", + "c.jalr", + "c.add", + "c.fsdsp", + "c.swsp", + "c.fswsp", + "c.sdsp", +]; + ///Contains every general purpose register's binary value and the various names they are recognized as. Any reference to gp registers throughout the parser/assembler should reference this array pub const GP_REGISTERS: &[GPRegister; 32] = &[ GPRegister { diff --git a/src/parser/parsing.rs b/src/parser/parsing.rs index 5fe39244b..4881ce8e6 100644 --- a/src/parser/parsing.rs +++ b/src/parser/parsing.rs @@ -1,12 +1,15 @@ +use crate::emulation_core::architectures::AvailableDatapaths; use crate::parser::parser_structs_and_enums::ErrorType::*; use crate::parser::parser_structs_and_enums::TokenType::{Directive, Label, Operator, Unknown}; use crate::parser::parser_structs_and_enums::{ Data, Error, Instruction, LabelInstance, MonacoLineInfo, Token, FP_REGISTERS, GP_REGISTERS, - SUPPORTED_INSTRUCTIONS, + SUPPORTED_INSTRUCTIONS_MIPS, }; use levenshtein::levenshtein; use std::collections::HashMap; +use super::parser_structs_and_enums::SUPPORTED_INSTRUCTIONS_RISCV; + ///Takes the initial string of the program given by the editor and turns it into a vector of Line, /// a struct that holds tokens and the original line number. pub fn tokenize_program(program: String) -> Vec { @@ -402,6 +405,7 @@ pub fn suggest_error_corrections( data: &mut [Data], labels: &HashMap, monaco_line_info: &mut [MonacoLineInfo], + arch: AvailableDatapaths, ) -> String { let levenshtein_threshold = 2_f32 / 3_f32; let mut console_out_string: String = "".to_string(); @@ -468,10 +472,22 @@ pub fn suggest_error_corrections( let given_string = &instruction.operator.token_name; let mut closest: (usize, String) = (usize::MAX, "".to_string()); - for instruction in SUPPORTED_INSTRUCTIONS { - if levenshtein(given_string, instruction) < closest.0 { - closest.0 = levenshtein(given_string, instruction); - closest.1 = instruction.to_string(); + match arch { + AvailableDatapaths::MIPS => { + for instruction in SUPPORTED_INSTRUCTIONS_MIPS { + if levenshtein(given_string, instruction) < closest.0 { + closest.0 = levenshtein(given_string, instruction); + closest.1 = instruction.to_string(); + } + } + } + AvailableDatapaths::RISCV => { + for instruction in SUPPORTED_INSTRUCTIONS_RISCV { + if levenshtein(given_string, instruction) < closest.0 { + closest.0 = levenshtein(given_string, instruction); + closest.1 = instruction.to_string(); + } + } } } let mut message = "Instruction is not recognized.".to_string(); diff --git a/src/parser/pseudo_instruction_parsing.rs b/src/parser/pseudo_instruction_parsing.rs index 6bb384d9c..02a1dcfbc 100644 --- a/src/parser/pseudo_instruction_parsing.rs +++ b/src/parser/pseudo_instruction_parsing.rs @@ -1237,6 +1237,816 @@ pub fn expand_pseudo_instructions_and_assign_instruction_numbers( } } +///Iterates through the instruction list and translates pseudo-instructions into real instructions. +/// LW and SW with labelled memory are not completely translated in this step because they require +/// the address of the labelled memory to be known which is not found until after all other pseudo-instructions +/// have been translated. Updated pseudo-instructions are added to updated_monaco_string to appear in the editor after assembly. +/// Also ensures a syscall is at the end of the program +pub fn expand_pseudo_instructions_and_assign_instruction_numbers_riscv( + instructions: &mut Vec, + data: &Vec, + monaco_line_info: &mut [MonacoLineInfo], +) { + //figure out list of labels to be used for lw and sw labels + let mut list_of_labels: Vec = Vec::new(); + for instruction in instructions.clone() { + for label in instruction.labels { + list_of_labels.push(label.token.token_name); + } + } + for data in data { + list_of_labels.push(data.label.token_name.clone()); + } + + //vec_of_added_instructions is needed because of rust ownership rules. It will not let us + //insert into instruction_list while instruction_list is being iterated over. + let vec_of_added_instructions: Vec = Vec::new(); + + //iterate through every instruction and check if the operator is a pseudo-instruction + for (i, mut instruction) in &mut instructions.iter_mut().enumerate() { + instruction.instruction_number = i + vec_of_added_instructions.len(); + match &*instruction.operator.token_name.to_lowercase() { + "nop" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "nop".to_string(), + syntax: "nop".to_string(), + translation_lines: vec!["addi x0, x0, 0".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 0) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "addi".to_string(); + + // Replace Operands + instruction.operands.insert( + 0, + Token { + token_name: "x0".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + instruction.operands.insert( + 1, + Token { + token_name: "x0".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + instruction.operands.insert( + 2, + Token { + token_name: "0".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "mv" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "mv".to_string(), + syntax: "mv rd, rs1".to_string(), + translation_lines: vec!["addi rd, rs, 0".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 2) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "addi".to_string(); + + // Replace Operands + instruction.operands.insert( + 2, + Token { + token_name: "0".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "not" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "not".to_string(), + syntax: "not rd, rs1".to_string(), + translation_lines: vec!["xori rd, rs, -1".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 2) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "xori".to_string(); + + // Replace Operands + instruction.operands.insert( + 2, + Token { + token_name: "-1".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "neg" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "neg".to_string(), + syntax: "neg rd, rs1".to_string(), + translation_lines: vec!["sub rd, x0, rs".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 2) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "sub".to_string(); + + // Replace Operands + instruction.operands.insert( + 1, + Token { + token_name: "x0".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "negw" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "negw".to_string(), + syntax: "negw rd, rs1".to_string(), + translation_lines: vec!["subw rd, x0, rs".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 2) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "subw".to_string(); + + // Replace Operands + instruction.operands.insert( + 1, + Token { + token_name: "x0".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "sext.w" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "sext.w".to_string(), + syntax: "sext.w rd, rs1".to_string(), + translation_lines: vec!["addiw rd, rs, 0".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 2) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "addiw".to_string(); + + // Replace Operands + instruction.operands.insert( + 2, + Token { + token_name: "0".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "seqz" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "seqz".to_string(), + syntax: "seqz rd, rs1".to_string(), + translation_lines: vec!["sltiu rd, rs, 1".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 2) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "sltiu".to_string(); + + // Replace Operands + instruction.operands.insert( + 2, + Token { + token_name: "1".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "snez" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "snez".to_string(), + syntax: "snez rd, rs1".to_string(), + translation_lines: vec!["sltu rd, x0, rs".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 2) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "sltu".to_string(); + + // Replace Operands + instruction.operands.insert( + 1, + Token { + token_name: "x0".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "sltz" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "sltz".to_string(), + syntax: "sltz rd, rs1".to_string(), + translation_lines: vec!["slt rd, rs, x0".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 2) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "slt".to_string(); + + // Replace Operands + instruction.operands.insert( + 2, + Token { + token_name: "x0".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "sgtz" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "sgtz".to_string(), + syntax: "sgtz rd, rs1".to_string(), + translation_lines: vec!["slt rd, x0, rs".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 2) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "slt".to_string(); + + // Replace Operands + instruction.operands.insert( + 1, + Token { + token_name: "x0".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "beqz" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "beqz".to_string(), + syntax: "beqz rs1, offset".to_string(), + translation_lines: vec!["beq rs, x0, offset".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 2) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "beq".to_string(); + + // Replace Operands + instruction.operands.insert( + 1, + Token { + token_name: "x0".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "bnez" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "bnez".to_string(), + syntax: "bnez rs1, offset".to_string(), + translation_lines: vec!["bne rs, x0, offset".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 2) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "bne".to_string(); + + // Replace Operands + instruction.operands.insert( + 1, + Token { + token_name: "x0".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "blez" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "blez".to_string(), + syntax: "blez rs1, offset".to_string(), + translation_lines: vec!["bge x0, rs, offset".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 2) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "bge".to_string(); + + // Replace Operands + instruction.operands.insert( + 0, + Token { + token_name: "x0".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "bgez" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "bgez".to_string(), + syntax: "bgez rs1, offset".to_string(), + translation_lines: vec!["bge rs, x0, offset".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 2) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "bge".to_string(); + + // Replace Operands + instruction.operands.insert( + 1, + Token { + token_name: "x0".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "bltz" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "bltz".to_string(), + syntax: "bltz rs1, offset".to_string(), + translation_lines: vec!["blt rs, x0, offset".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 2) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "blt".to_string(); + + // Replace Operands + instruction.operands.insert( + 1, + Token { + token_name: "x0".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "bgtz" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "bgtz".to_string(), + syntax: "bgtz rs1, offset".to_string(), + translation_lines: vec!["blt x0, rs, offset".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 2) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "blt".to_string(); + + // Replace Operands + instruction.operands.insert( + 0, + Token { + token_name: "x0".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "bgt" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "bgt".to_string(), + syntax: "bgt rs, rt, offset".to_string(), + translation_lines: vec!["blt rt, rs, offset".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 3) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "blt".to_string(); + + // Reorder Operands + let tmp = instruction.operands[0].token_name.clone(); + instruction.operands[0].token_name = instruction.operands[1].token_name.clone(); + instruction.operands[1].token_name = tmp; + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "ble" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "ble".to_string(), + syntax: "ble rs, rt, offset".to_string(), + translation_lines: vec!["bge rt, rs, offset".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 3) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "bge".to_string(); + + // Reorder Operands + let tmp = instruction.operands[0].token_name.clone(); + instruction.operands[0].token_name = instruction.operands[1].token_name.clone(); + instruction.operands[1].token_name = tmp; + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "bgtu" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "bgtu".to_string(), + syntax: "bgtu rs, rt, offset".to_string(), + translation_lines: vec!["bltu rt, rs, offset".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 3) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "bltu".to_string(); + + // Reorder Operands + let tmp = instruction.operands[0].token_name.clone(); + instruction.operands[0].token_name = instruction.operands[1].token_name.clone(); + instruction.operands[1].token_name = tmp; + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "bleu" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "bleu".to_string(), + syntax: "bleu rs, rt, offset".to_string(), + translation_lines: vec!["bgeu rt, rs, offset".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 3) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "bgeu".to_string(); + + // Reorder Operands + let tmp = instruction.operands[0].token_name.clone(); + instruction.operands[0].token_name = instruction.operands[1].token_name.clone(); + instruction.operands[1].token_name = tmp; + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + // Start of Jump Pseudo-Instructions + "j" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "j".to_string(), + syntax: "j offset".to_string(), + translation_lines: vec!["jal x0, offset".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 1) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "jal".to_string(); + + // Replace Operands + instruction.operands.insert( + 0, + Token { + token_name: "x0".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "jr" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "jr".to_string(), + syntax: "jr offset".to_string(), + translation_lines: vec!["jal x1, offset".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 1) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "jal".to_string(); + + // Replace Operands + instruction.operands.insert( + 0, + Token { + token_name: "x1".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "ret" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "ret".to_string(), + syntax: "ret".to_string(), + translation_lines: vec!["jalr x1, 0(x0)".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 0) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "jalr".to_string(); + + // Replace Operands + instruction.operands.insert( + 0, + Token { + token_name: "x1".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + instruction.operands.insert( + 1, + Token { + token_name: "0(x0)".to_string(), + start_end_columns: (0, 0), + token_type: Default::default(), + }, + ); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + // Start of F extension pseudo-instructions + "fmv.s" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "fmv.s".to_string(), + syntax: "fmv.s frd, frs1".to_string(), + translation_lines: vec!["fsgnj.s frd, frs, frs".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 2) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "fsgnj.s".to_string(); + + // Replace Operands + instruction + .operands + .insert(2, instruction.operands[1].clone()); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "fabs.s" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "fabs.s".to_string(), + syntax: "fabs.s frd, frs1".to_string(), + translation_lines: vec!["fsgnjx.s frd, frs, frs".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 2) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "fsgnjx.s".to_string(); + + // Replace Operands + instruction + .operands + .insert(2, instruction.operands[1].clone()); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + "fneg.s" => { + // Set Pseudo Description + let info = PseudoDescription { + name: "fneg.s".to_string(), + syntax: "fneg.s frd, frs1".to_string(), + translation_lines: vec!["fsgnjn.s frd, frs, frs".to_string()], + }; + monaco_line_info[instruction.line_number].mouse_hover_string = info.to_string(); + + // Check operands + if !check_operands(instruction, 2) { + continue; + } + + // Replace Instruction + instruction.operator.token_name = "fsgnjn.s".to_string(); + + // Replace Operands + instruction + .operands + .insert(2, instruction.operands[1].clone()); + + // Update Line Info + //monaco_line_info[instruction.line_number].update_pseudo_string(vec![instruction]); + } + _ => {} + } + } + + //insert all new new instructions + for instruction in vec_of_added_instructions { + instructions.insert(instruction.instruction_number, instruction); + } +} + ///the second part of completing pseudo-instructions. LW and SW with labels requires the address of the label to be known, /// the second part of this must occur after the label hashmap is completed. pub fn complete_lw_sw_pseudo_instructions( @@ -1278,3 +2088,16 @@ pub fn complete_lw_sw_pseudo_instructions( } } } + +fn check_operands(instruction: &mut Instruction, num_operands: usize) -> bool { + if instruction.operands.len() != num_operands { + instruction.errors.push(Error { + error_name: IncorrectNumberOfOperands, + token_causing_error: "".to_string(), + start_end_columns: instruction.operator.start_end_columns, + message: "".to_string(), + }); + return false; + } + true +} diff --git a/src/tests/emulation_core/mips.rs b/src/tests/emulation_core/mips.rs index 57658a1bc..0581f9b11 100644 --- a/src/tests/emulation_core/mips.rs +++ b/src/tests/emulation_core/mips.rs @@ -6,7 +6,9 @@ use crate::emulation_core::mips::gp_registers::GpRegisterType; pub mod api { use super::*; - use crate::parser::parser_assembler_main::parser; + use crate::{ + emulation_core::architectures::AvailableDatapaths, parser::parser_assembler_main::parser, + }; #[test] fn reset_datapath() -> Result<(), String> { @@ -14,7 +16,7 @@ pub mod api { // Add instruction into emulation core memory. let instruction = String::from("ori $s0, $zero, 5"); - let (_, instruction_bits) = parser(instruction); + let (_, instruction_bits) = parser(instruction, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.execute_instruction(); diff --git a/src/tests/integration/core_parser/arithmetic.rs b/src/tests/integration/core_parser/arithmetic.rs index bf09ce6f0..6c6f86693 100644 --- a/src/tests/integration/core_parser/arithmetic.rs +++ b/src/tests/integration/core_parser/arithmetic.rs @@ -1,5 +1,7 @@ //! Tests for additional arithmetic instructions: addu, sll, move, nop. +use crate::emulation_core::architectures::AvailableDatapaths; + use super::*; #[test] @@ -8,7 +10,7 @@ fn basic_addu() -> Result<(), String> { let instructions = String::from("addu r20, r19, r18"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[18] = 6849841; @@ -32,7 +34,7 @@ fn basic_sll() -> Result<(), String> { sll $s1, $s1, 3"#, ); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; while !datapath.is_halted() { @@ -53,7 +55,7 @@ fn basic_move() -> Result<(), String> { move $s5, $s4"#, ); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; while !datapath.is_halted() { @@ -71,7 +73,7 @@ fn basic_nop() -> Result<(), String> { let instructions = String::from(r#"nop"#); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; let mut expected_registers = datapath.registers; diff --git a/src/tests/integration/core_parser/basic_immediate.rs b/src/tests/integration/core_parser/basic_immediate.rs index 46ca3a88e..169b1389f 100644 --- a/src/tests/integration/core_parser/basic_immediate.rs +++ b/src/tests/integration/core_parser/basic_immediate.rs @@ -2,6 +2,8 @@ //! //! Note that some of these instructions are pseudo-instructions. +use crate::emulation_core::architectures::AvailableDatapaths; + use super::*; #[test] @@ -10,7 +12,7 @@ fn basic_addi() -> Result<(), String> { let instructions = String::from("addi r11, r15, 2"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[15] = 100; @@ -30,7 +32,7 @@ fn basic_addiu() -> Result<(), String> { let instructions = String::from("addiu r14, r17, 5"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[17] = 500; @@ -50,7 +52,7 @@ fn basic_subi() -> Result<(), String> { let instructions = String::from("subi r11, r15, 2"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[15] = 100; @@ -70,7 +72,7 @@ fn basic_muli() -> Result<(), String> { let instructions = String::from("muli r11, r15, 2"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[15] = 100; @@ -90,7 +92,7 @@ fn basic_divi() -> Result<(), String> { let instructions = String::from("divi r11, r15, 2"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[15] = 100; @@ -110,7 +112,7 @@ fn basic_ori() -> Result<(), String> { let instructions = String::from("ori r11, r15, 2"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[15] = 100; @@ -130,7 +132,7 @@ fn basic_andi() -> Result<(), String> { let instructions = String::from("andi r11, r15, 4"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[15] = 100; @@ -150,7 +152,7 @@ fn basic_li() -> Result<(), String> { let instructions = String::from("li r15, 56"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; while !datapath.is_halted() { @@ -169,7 +171,7 @@ fn basic_lui() -> Result<(), String> { // 65530 == 0xFFFA let instructions = String::from("lui r20, 65530"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; while !datapath.is_halted() { @@ -189,7 +191,7 @@ fn basic_aui() -> Result<(), String> { // 4612 == 0x1204 let instructions = String::from("aui r15, r18, 4612"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[18] = 0x0000_0000_0030_ABCD; diff --git a/src/tests/integration/core_parser/basic_operations.rs b/src/tests/integration/core_parser/basic_operations.rs index 4ea6f6728..6319b01c8 100644 --- a/src/tests/integration/core_parser/basic_operations.rs +++ b/src/tests/integration/core_parser/basic_operations.rs @@ -1,5 +1,7 @@ //! Covering the basic arithmetic instructions: add, sub, mul, div, or, and. +use crate::emulation_core::architectures::AvailableDatapaths; + use super::*; #[test] @@ -8,7 +10,7 @@ fn basic_add() -> Result<(), String> { let instructions = String::from("add r11, r7, r8"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[7] = 51; @@ -29,7 +31,7 @@ fn basic_sub() -> Result<(), String> { let instructions = String::from("sub r12, r7, r8"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[7] = 51; @@ -50,7 +52,7 @@ fn basic_mul() -> Result<(), String> { let instructions = String::from("mul r13, r7, r8"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[7] = 51; @@ -71,7 +73,7 @@ fn basic_div() -> Result<(), String> { let instructions = String::from("div r14, r7, r8"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[7] = 51; @@ -92,7 +94,7 @@ fn basic_or() -> Result<(), String> { let instructions = String::from("or r15, r7, r8"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[7] = 51; @@ -113,7 +115,7 @@ fn basic_and() -> Result<(), String> { let instructions = String::from("and r16, r7, r8"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[7] = 51; diff --git a/src/tests/integration/core_parser/branch_jump.rs b/src/tests/integration/core_parser/branch_jump.rs index 0cbbcedd5..e886a531e 100644 --- a/src/tests/integration/core_parser/branch_jump.rs +++ b/src/tests/integration/core_parser/branch_jump.rs @@ -1,5 +1,7 @@ //! Tests for the branch and jump instructions: j, jr, jal, jalr, beq, bne +use crate::emulation_core::architectures::AvailableDatapaths; + use super::*; #[test] @@ -16,7 +18,7 @@ loop: daddu $s1, $s1, $s0 j loop"#, ); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; // Execute the ori instruction. @@ -44,7 +46,7 @@ fn basic_jr() -> Result<(), String> { jr r15"#, ); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; // Execute 2 instructions. @@ -69,7 +71,7 @@ syscall function: ori $t0, $zero, 5831"#, ); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; while !datapath.is_halted() { @@ -95,7 +97,7 @@ or $zero, $zero, $zero function: ori $t1, $zero, 9548"#, ); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; // Execute 3 instructions. @@ -144,7 +146,7 @@ daddiu $s2, $s2, 20 change10: daddiu $s2, $s2, 10"#, ); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; while !datapath.is_halted() { @@ -185,7 +187,7 @@ syscall changez: daddiu $s2, $s2, 20"#, ); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; while !datapath.is_halted() { @@ -217,7 +219,7 @@ daddiu $s0, $s0, 1 bne $s0, $s2, loop"#, ); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; let mut iterations = 0; diff --git a/src/tests/integration/core_parser/conditions.rs b/src/tests/integration/core_parser/conditions.rs index 774cafe66..6f2503498 100644 --- a/src/tests/integration/core_parser/conditions.rs +++ b/src/tests/integration/core_parser/conditions.rs @@ -2,6 +2,8 @@ //! //! Includes: seq, sne, slt, sltu, sle, sleu, sgt, sgtu, sge, sgeu. +use crate::emulation_core::architectures::AvailableDatapaths; + use super::*; akin! { @@ -26,7 +28,7 @@ akin! { let mut datapath = MipsDatapath::default(); let instructions = String::from("*instruction_name r*destination_register, r5, r6"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[5] = *true_value1; @@ -45,7 +47,7 @@ akin! { let mut datapath = MipsDatapath::default(); let instructions = String::from("*instruction_name r*destination_register, r5, r6"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[5] = *false_value1; diff --git a/src/tests/integration/core_parser/coprocessor_move.rs b/src/tests/integration/core_parser/coprocessor_move.rs index 56f403101..36380e127 100644 --- a/src/tests/integration/core_parser/coprocessor_move.rs +++ b/src/tests/integration/core_parser/coprocessor_move.rs @@ -1,5 +1,7 @@ //! Tests for the "move from/to Coprocessor 1" instructions: mtc1, dmtc1, mfc1, dmfc1 +use crate::emulation_core::architectures::AvailableDatapaths; + use super::*; #[test] @@ -7,7 +9,7 @@ fn basic_mtc1() -> Result<(), String> { let mut datapath = MipsDatapath::default(); let instructions = String::from("mtc1 $t2, $f5"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[10] = 658461658; // $t2 @@ -25,7 +27,7 @@ fn truncate_32_bit_mtc1() -> Result<(), String> { let mut datapath = MipsDatapath::default(); let instructions = String::from("mtc1 $t3, $f6"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[11] = 0x0000_02F2_AC71_AC41; // $t3 @@ -43,7 +45,7 @@ fn basic_mfc1() -> Result<(), String> { let mut datapath = MipsDatapath::default(); let instructions = String::from("mfc1 $t3, $f5"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.coprocessor.registers.fpr[5] = 657861659; @@ -61,7 +63,7 @@ fn truncate_32_bit_mfc1() -> Result<(), String> { let mut datapath = MipsDatapath::default(); let instructions = String::from("mfc1 $t4, $f6"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.coprocessor.registers.fpr[6] = 0x0003_7F80_E5E7_D785; @@ -79,7 +81,7 @@ fn basic_dmtc1() -> Result<(), String> { let mut datapath = MipsDatapath::default(); let instructions = String::from("dmtc1 $t3, $f6"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[11] = 0x0120_02F2_AC71_AC41; // $t3 @@ -97,7 +99,7 @@ fn basic_dmfc1() -> Result<(), String> { let mut datapath = MipsDatapath::default(); let instructions = String::from("dmfc1 $t4, $f6"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.coprocessor.registers.fpr[6] = 0x0003_7F90_E5E7_D785; diff --git a/src/tests/integration/core_parser/double_arithmetic.rs b/src/tests/integration/core_parser/double_arithmetic.rs index 9c2c46e2e..9e975fc80 100644 --- a/src/tests/integration/core_parser/double_arithmetic.rs +++ b/src/tests/integration/core_parser/double_arithmetic.rs @@ -1,5 +1,7 @@ //! Tests for the double arithmetic instructions: dadd, dsub, dmul, ddiv, daddu, dsubu, dmulu, ddivu. +use crate::emulation_core::architectures::AvailableDatapaths; + use super::*; akin! { @@ -16,7 +18,7 @@ akin! { let mut datapath = MipsDatapath::default(); let instructions = String::from(*instruction); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[16] = *value1; @@ -45,7 +47,7 @@ akin! { let mut datapath = MipsDatapath::default(); let instructions = String::from(*instruction); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[25] = *value1; diff --git a/src/tests/integration/core_parser/double_immediate.rs b/src/tests/integration/core_parser/double_immediate.rs index 531f3795e..773c47680 100644 --- a/src/tests/integration/core_parser/double_immediate.rs +++ b/src/tests/integration/core_parser/double_immediate.rs @@ -1,5 +1,7 @@ //! Tests for the double immediate instructions: dahi, dati, daddi, dsubi, dmuli, ddivi, daddiu, dsubiu, dmuliu, ddiviu. +use crate::emulation_core::architectures::AvailableDatapaths; + use super::*; #[test] @@ -7,7 +9,7 @@ fn basic_dahi() -> Result<(), String> { let mut datapath = MipsDatapath::default(); let instructions = String::from("dahi r3, 123"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[3] = 0; @@ -28,7 +30,7 @@ fn dahi_sign_extend() -> Result<(), String> { let mut datapath = MipsDatapath::default(); let instructions = String::from("dahi r5, 43158"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[5] = 0; @@ -49,7 +51,7 @@ fn basic_dati() -> Result<(), String> { let mut datapath = MipsDatapath::default(); let instructions = String::from("dati r10, 4321"); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[10] = 0; @@ -77,7 +79,7 @@ akin! { let mut datapath = MipsDatapath::default(); let instructions = String::from(*instruction); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[20] = *rs_value; @@ -103,7 +105,7 @@ akin! { let mut datapath = MipsDatapath::default(); let instructions = String::from(*instruction); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.registers.gpr[20] = *rs_value; diff --git a/src/tests/integration/core_parser/fibonacci.rs b/src/tests/integration/core_parser/fibonacci.rs index e4c5c9cd2..3fe8924e7 100644 --- a/src/tests/integration/core_parser/fibonacci.rs +++ b/src/tests/integration/core_parser/fibonacci.rs @@ -1,3 +1,4 @@ +use crate::emulation_core::architectures::AvailableDatapaths; use crate::emulation_core::mips::gp_registers::GpRegisterType; use super::*; @@ -22,11 +23,11 @@ fn recursive_fibonacci() -> Result<(), String> { slt $v0,$v0,$s1 beq $v0,$zero,L2 nop - + lw $v0,40($fp) b L3 nop - + L2: lw $v0,40($fp) nop @@ -34,7 +35,7 @@ fn recursive_fibonacci() -> Result<(), String> { move $a0,$v0 jal fib(int) nop - + move $s0,$v0 lw $v0,40($fp) nop @@ -42,7 +43,7 @@ fn recursive_fibonacci() -> Result<(), String> { move $a0,$v0 jal fib(int) nop - + addu $v0,$s0,$v0 L3: move $sp,$fp @@ -52,7 +53,7 @@ fn recursive_fibonacci() -> Result<(), String> { addiu $sp,$sp,40 jr $ra nop - + main: addiu $sp,$sp,-40 sw $ra,36($sp) @@ -63,7 +64,7 @@ fn recursive_fibonacci() -> Result<(), String> { lw $a0,24($fp) jal fib(int) nop - + sw $v0,28($fp) lw $v0,28($fp) # This is where the final answer gets loaded off the stack move $sp,$fp @@ -74,7 +75,7 @@ fn recursive_fibonacci() -> Result<(), String> { nop", ); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; while !datapath.is_halted() { diff --git a/src/tests/integration/core_parser/floating_point_arithmetic.rs b/src/tests/integration/core_parser/floating_point_arithmetic.rs index f8e1b4352..9d68307d6 100644 --- a/src/tests/integration/core_parser/floating_point_arithmetic.rs +++ b/src/tests/integration/core_parser/floating_point_arithmetic.rs @@ -1,5 +1,7 @@ //! Tests for the floating-point arithmetic instructions: add.s, add.d, sub.s, sub.d, mul.s, mul.d, div.s, div.d +use crate::emulation_core::architectures::AvailableDatapaths; + use super::*; akin! { @@ -18,7 +20,7 @@ akin! { let mut datapath = MipsDatapath::default(); let instructions = String::from(*instruction); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.coprocessor.registers.fpr[15] = *value1; @@ -49,7 +51,7 @@ akin! { let mut datapath = MipsDatapath::default(); let instructions = String::from(*instruction); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.coprocessor.registers.fpr[15] = *value1; diff --git a/src/tests/integration/core_parser/floating_point_branch.rs b/src/tests/integration/core_parser/floating_point_branch.rs index bf3da5776..60444e64b 100644 --- a/src/tests/integration/core_parser/floating_point_branch.rs +++ b/src/tests/integration/core_parser/floating_point_branch.rs @@ -1,5 +1,7 @@ //! Tests for the floating-point branch instructions: bc1t, bc1f +use crate::emulation_core::architectures::AvailableDatapaths; + use super::*; #[test] @@ -30,7 +32,7 @@ c.lt.s $f0, $f2 bc1t loop"#, ); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; while !datapath.is_halted() { @@ -76,7 +78,7 @@ c.lt.s $f2, $f0 bc1f loop"#, ); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; while !datapath.is_halted() { diff --git a/src/tests/integration/core_parser/floating_point_comparison.rs b/src/tests/integration/core_parser/floating_point_comparison.rs index b00b51506..e5632850d 100644 --- a/src/tests/integration/core_parser/floating_point_comparison.rs +++ b/src/tests/integration/core_parser/floating_point_comparison.rs @@ -1,5 +1,7 @@ //! Tests for the floating-point comparison instructions: c.eq.s, c.eq.d, c.lt.s, c.lt.d, c.le.s, c.le.d, c.ngt.s, c.ngt.d, c.nge.s, c.nge.d +use crate::emulation_core::architectures::AvailableDatapaths; + use super::*; akin! { @@ -16,7 +18,7 @@ akin! { let mut datapath = MipsDatapath::default(); let instructions = String::from(*instruction); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.coprocessor.registers.fpr[15] = *value1; @@ -45,7 +47,7 @@ akin! { let mut datapath = MipsDatapath::default(); let instructions = String::from(*instruction); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.coprocessor.registers.fpr[15] = *value1; diff --git a/src/tests/integration/core_parser/mod.rs b/src/tests/integration/core_parser/mod.rs index 79b7166a5..7b94c18ee 100644 --- a/src/tests/integration/core_parser/mod.rs +++ b/src/tests/integration/core_parser/mod.rs @@ -1,5 +1,6 @@ use akin::akin; +use crate::emulation_core::architectures::AvailableDatapaths; use crate::emulation_core::datapath::Datapath; use crate::emulation_core::mips::datapath::MipsDatapath; use crate::parser::parser_assembler_main::parser; @@ -30,7 +31,7 @@ add $s1, $s0, $s0"#, ); // Parse instructions and load into emulation core memory. - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; // Execute 2 instructions. @@ -69,7 +70,7 @@ dati r1, 43982"#, // dati r1, 43982 | ABCD 8765 CCCC EEEE | 43982 == 0xABCE. FFFF + ABCE = ABCD. // Parse instructions and load into emulation core memory. - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; // Execute 4 instructions. @@ -96,7 +97,7 @@ dadd r7, r5, r6 dmuli r8, r7, 2"#, ); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; while !datapath.is_halted() { diff --git a/src/tests/integration/core_parser/store_load_word.rs b/src/tests/integration/core_parser/store_load_word.rs index 7c52f83a6..5cdfec739 100644 --- a/src/tests/integration/core_parser/store_load_word.rs +++ b/src/tests/integration/core_parser/store_load_word.rs @@ -12,7 +12,7 @@ li r25, 1234 sw r25, 0(r14)"#, ); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; while !datapath.is_halted() { @@ -33,7 +33,7 @@ fn basic_lw() -> Result<(), String> { lw r25, 0(r14)"#, ); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.memory.memory[403] = 36; @@ -61,7 +61,7 @@ daddiu $s2, $s1, 1 sw $s2, secret_number"#, ); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; while !datapath.is_halted() { @@ -88,7 +88,7 @@ mtc1 $s1, $f25 swc1 $f25, 0($s0)"#, ); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; while !datapath.is_halted() { @@ -109,7 +109,7 @@ fn basic_lwc1() -> Result<(), String> { lwc1 $f12, 0($t4)"#, ); - let (_, instruction_bits) = parser(instructions); + let (_, instruction_bits) = parser(instructions, AvailableDatapaths::MIPS); datapath.initialize_legacy(instruction_bits)?; datapath.memory.memory[403] = 36; diff --git a/src/tests/parser/assembling.rs b/src/tests/parser/assembling.rs index 16b25f837..0c0ec4868 100644 --- a/src/tests/parser/assembling.rs +++ b/src/tests/parser/assembling.rs @@ -1,3 +1,4 @@ +use crate::emulation_core::architectures::AvailableDatapaths; use crate::parser::assembling::assemble_data_binary; use crate::parser::parser_assembler_main::parser; use crate::parser::parser_structs_and_enums::ErrorType::{NonASCIIChar, NonASCIIString}; @@ -374,20 +375,32 @@ fn assemble_data_binary_works_for_asciiz() { #[test] fn assemble_data_binary_gives_errors_on_non_ascii_characters_for_ascii_asciiz_and_byte() { - let result = parser(".data\nlabel: .ascii \"❤️🦧❤️\"".to_string()).0; + let result = parser( + ".data\nlabel: .ascii \"❤️🦧❤️\"".to_string(), + AvailableDatapaths::MIPS, + ) + .0; assert_eq!( result.monaco_line_info[1].errors[0].error_name, NonASCIIString ); - let result = parser(".data\nlabel: .asciiz \"❤️🦧❤️\"".to_string()).0; + let result = parser( + ".data\nlabel: .asciiz \"❤️🦧❤️\"".to_string(), + AvailableDatapaths::MIPS, + ) + .0; assert_eq!( result.monaco_line_info[1].errors[0].error_name, NonASCIIString ); - let result = parser(".data\nlabel: .byte \'🦧\'".to_string()).0; + let result = parser( + ".data\nlabel: .byte \'🦧\'".to_string(), + AvailableDatapaths::MIPS, + ) + .0; assert_eq!( result.monaco_line_info[1].errors[0].error_name, NonASCIIChar diff --git a/src/tests/parser/parser_assembler_main.rs b/src/tests/parser/parser_assembler_main.rs index ccbb5a155..398b0acf4 100644 --- a/src/tests/parser/parser_assembler_main.rs +++ b/src/tests/parser/parser_assembler_main.rs @@ -1,36 +1,1554 @@ #[cfg(test)] mod parser_main_function_tests { + use crate::emulation_core::architectures::AvailableDatapaths; use crate::parser::parser_assembler_main::*; #[test] fn parser_takes_string_and_returns_vec_of_instructions() { - let results = - parser("lw $t1, 512($t1)\nadd $t1, $s6, $t2\naddi $t1, $t2, 43690".to_string()); + let results = parser( + "lw $t1, 512($t1)\nadd $t1, $s6, $t2\naddi $t1, $t2, 43690".to_string(), + AvailableDatapaths::MIPS, + ); + + assert_eq!( + results.0.instructions[0].binary, + 0b10001101001010010000001000000000 + ); + assert_eq!( + results.0.instructions[1].binary, + 0b00000010110010100100100000100000 + ); + assert_eq!( + results.0.instructions[2].binary, + 0b00100001010010011010101010101010 + ); + } +} + +mod read_riscv_instructions_tests { + + use crate::tests::parser::parser_assembler_main::helper_functions::instruction_parser_riscv; + + // RV32I Instructions + + #[test] + fn read_instructions_add() { + let file_string = "add ra, t5, s0".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000000100011110000000010110011 + ); + } + + #[test] + fn read_instructions_sub() { + let file_string = "sub x1, x2, x3".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01000000001100010000000010110011 + ); + } + + #[test] + fn read_instructions_sll() { + let file_string = "sll x4, x5, x6".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000000011000101001001000110011 + ); + } + + #[test] + fn read_instructions_slt() { + let file_string = "slt x7, x8, x9".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000000100101000010001110110011 + ); + } + + #[test] + fn read_instructions_sltu() { + let file_string = "sltu x10, x11, x12".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000000110001011011010100110011 + ); + } + + #[test] + fn read_instructions_xor() { + let file_string = "xor x13, x14, x15".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000000111101110100011010110011 + ); + } + + #[test] + fn read_instructions_srl() { + let file_string = "srl x16, x17, x18".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000001001010001101100000110011 + ); + } + + #[test] + fn read_instructions_sra() { + let file_string = "sra x19, x20, x21".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01000001010110100101100110110011 + ); + } + + #[test] + fn read_instructions_or() { + let file_string = "or x22, x23, x24".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000001100010111110101100110011 + ); + } + + #[test] + fn read_instructions_and() { + let file_string = "and x25, x26, x27".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000001101111010111110010110011 + ); + } + + #[test] + fn read_instructions_addi() { + let file_string = "addi x28, x29, x30".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000000000011101000111000010011 + ); + } + + #[test] + fn read_instructions_slti() { + let file_string = "slti x31, t0, 150".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00001001011000101010111110010011 + ); + } + + #[test] + fn read_instructions_sltiu() { + let file_string = "sltiu t1, t2, 241".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00001111000100111011001100010011 + ); + } + + #[test] + fn read_instructions_xori() { + let file_string = "xori t3, t4, 440".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00011011100011101100111000010011 + ); + } + + #[test] + fn read_instructions_ori() { + let file_string = "ori t5, t6, 621".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00100110110111111110111100010011 + ); + } + + #[test] + fn read_instructions_andi() { + let file_string = "andi ra, sp, 1024".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01000000000000010111000010010011 + ); + } + + #[test] + fn read_instructions_slli() { + let file_string = "slli gp, tp, 5".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000000010100100001000110010011 + ); + } + + #[test] + fn read_instructions_srli() { + let file_string = "srli s0, s1, 10".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000000101001001101010000010011 + ); + } + + #[test] + fn read_instructions_srai() { + let file_string = "srai a0, a1, 6".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01000000011001011101010100010011 + ); + } + + #[test] + fn read_instructions_lb() { + let file_string = "lb a2, 150(a3)".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00001001011001101000011000000011 + ); + } + + #[test] + fn read_instructions_lh() { + let file_string = "lh a4, 220(a5)".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00001101110001111001011100000011 + ); + } + + #[test] + fn read_instructions_lw() { + let file_string = "lw a6, 32(a7)".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000010000010001010100000000011 + ); + } + + #[test] + fn read_instructions_lbu() { + let file_string = "lbu s2, 128(s3)".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00001000000010011100100100000011 + ); + } + + #[test] + fn read_instructions_lhu() { + let file_string = "lhu s4, 256(s5)".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00010000000010101101101000000011 + ); + } + + #[test] + fn read_instructions_sb() { + let file_string = "sb s6, 512(s7)".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00100001011010111000000000100011 + ); + } + + #[test] + fn read_instructions_sh() { + let file_string = "sh s8, 1024(s9)".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01000001100011001001000000100011 + ); + } + + #[test] + fn read_instructions_sw() { + let file_string = "sw s10, 2044(s11)".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01111111101011011010111000100011 + ); + } + + #[test] + fn read_instructions_jal() { + let file_string = "jal x1, 2044".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01111111110000000000000011101111 + ); + } + + #[test] + fn read_instructions_jalr() { + let file_string = "jalr x2, 128(x3)".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00001000000000011000000101100111 + ); + } + + #[test] + fn read_instructions_beq() { + let file_string = "beq x4, x5, 256".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00010000010100100000000001100011 + ); + } + + #[test] + fn read_instructions_bne() { + let file_string = "bne x6, x7, 512".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00100000011100110001000001100011 + ); + } + + #[test] + fn read_instructions_blt() { + let file_string = "blt x8, x9, 1024".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01000000100101000100000011100011 + ); + } + + #[test] + fn read_instructions_bge() { + let file_string = "bge x10, x11, 256".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00010000101101010101000001100011 + ); + } + + #[test] + fn read_instructions_bltu() { + let file_string = "bltu x12, x13, 64".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000100110101100110000001100011 + ); + } + + #[test] + fn read_instructions_bgeu() { + let file_string = "bgeu x14, x15, 32".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000010111101110111000001100011 + ); + } + + #[test] + fn read_instructions_ecall() { + let file_string = "ecall".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000000000000000000000001110011 + ); + } + + #[test] + fn read_instructions_ebreak() { + let file_string = "ebreak".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000000000100000000000001110011 + ); + } + + #[test] + fn read_instructions_uret() { + let file_string = "uret".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000000001000000000000001110011 + ); + } + + #[test] + fn read_instructions_sret() { + let file_string = "sret".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00010000001000000000000001110011 + ); + } + + #[test] + fn read_instructions_mret() { + let file_string = "mret".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00110000001000000000000001110011 + ); + } + + #[test] + fn read_instructions_wfi() { + let file_string = "wfi".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00010000010100000000000001110011 + ); + } + + #[test] + fn read_instructions_fencei() { + let file_string = "fence.i".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000000000000000001000000001111 + ); + } + + #[test] + fn read_instructions_lui() { + let file_string = "lui x16, 4096".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000001000000000000100000110111 + ); + } + + #[test] + fn read_instructions_auipc() { + let file_string = "auipc x17, 5024".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000001001110100000100010010111 + ); + } + + // RV64I Tests + + #[test] + fn read_instructions_addiw() { + let file_string = "addiw x18, x19, 50".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000011001010011000100100011011 + ); + } + + #[test] + fn read_instructions_slliw() { + let file_string = "slliw x20, x21, 16".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000001000010101001101000011011 + ); + } + + #[test] + fn read_instructions_srliw() { + let file_string = "srliw x22, x23, 20".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000001010010111101101100011011 + ); + } + + #[test] + fn read_instructions_sraiw() { + let file_string = "sraiw x24, x25, 10".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01000000101011001101110000011011 + ); + } + + #[test] + fn read_instructions_addw() { + let file_string = "addw x26, x27, x28".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000001110011011000110100111011 + ); + } + + #[test] + fn read_instructions_subw() { + let file_string = "subw x29, x30, x31".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01000001111111110000111010111011 + ); + } + + #[test] + fn read_instructions_sllw() { + let file_string = "sllw ra, sp, gp".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000000001100010001000010111011 + ); + } + + #[test] + fn read_instructions_srlw() { + let file_string = "srlw tp, t0, t1".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000000011000101101001000111011 + ); + } + + #[test] + fn read_instructions_sraw() { + let file_string = "sraw t2, fp, s1".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01000000100101000101001110111011 + ); + } + + #[test] + fn read_instructions_lwu() { + let file_string = "lwu a0, 50(a1)".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000011001001011110010100000011 + ); + } + + #[test] + fn read_instructions_ld() { + let file_string = "ld a2, 50(a3)".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000011001001101011011000000011 + ); + } + + #[test] + fn read_instructions_sd() { + let file_string = "sd a4, 50(a5)".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000010111001111011100100100011 + ); + } + + // Start of RV32M + + #[test] + fn read_instructions_mul() { + let file_string = "mul a6, a7, s2".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000011001010001000100000110011 + ); + } + + #[test] + fn read_instructions_mulh() { + let file_string = "mulh s3, s4, s5".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000011010110100001100110110011 + ); + } + + #[test] + fn read_instructions_mulhsu() { + let file_string = "mulhsu s6, s7, s8".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000011100010111010101100110011 + ); + } + + #[test] + fn read_instructions_mulhu() { + let file_string = "mulhu s9, s10, s11".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000011101111010011110010110011 + ); + } + + #[test] + fn read_instructions_div() { + let file_string = "div t3, t4, t5".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000011111011101100111000110011 + ); + } + + #[test] + fn read_instructions_divu() { + let file_string = "divu t6, x1, x2".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000010001000001101111110110011 + ); + } + + #[test] + fn read_instructions_rem() { + let file_string = "rem x3, x4, x5".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000010010100100110000110110011 + ); + } + + #[test] + fn read_instructions_remu() { + let file_string = "remu x6, x7, x8".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000010100000111111001100110011 + ); + } + + // RV64M + + #[test] + fn read_instructions_mulw() { + let file_string = "mulw x9, x10, x11".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000010101101010000010010111011 + ); + } + + #[test] + fn read_instructions_divw() { + let file_string = "divw x12, x13, x14".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000010111001101100011000111011 + ); + } + + #[test] + fn read_instructions_divuw() { + let file_string = "divuw x15, x16, x17".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000011000110000101011110111011 + ); + } + + #[test] + fn read_instructions_remw() { + let file_string = "remw x18, x19, x20".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000011010010011110100100111011 + ); + } + + #[test] + fn read_instructions_remuw() { + let file_string = "remuw x21, x22, x23".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000011011110110111101010111011 + ); + } + + // Start of RV32F + + #[test] + fn read_instructions_fmadds() { + let file_string = "fmadd.s f1, f2, f3, f4".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00100000001100010111000011000011 + ); + } + + #[test] + fn read_instructions_fmsubs() { + let file_string = "fmsub.s f5, f6, f7, f8".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01000000011100110111001011000111 + ); + } + + #[test] + fn read_instructions_fnmsubs() { + let file_string = "fnmsub.s f9, f10, f11, f12".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01100000101101010111010011001011 + ); + } + + #[test] + fn read_instructions_fnmadds() { + let file_string = "fnmadd.s f13, f14, f15, f16".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b10000000111101110111011011001111 + ); + } + + #[test] + fn read_instructions_fadds() { + let file_string = "fadd.s f17, f18, f19".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000001001110010111100011010011 + ); + } + + #[test] + fn read_instructions_fsubs() { + let file_string = "fsub.s f20, f21, f22".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00001001011010101111101001010011 + ); + } + + #[test] + fn read_instructions_fmuls() { + let file_string = "fmul.s f23, f24, f25".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00010001100111000111101111010011 + ); + } + + #[test] + fn read_instructions_fdivs() { + let file_string = "fdiv.s f26, f27, f28".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00011001110011011111110101010011 + ); + } + + #[test] + fn read_instructions_fsqrts() { + let file_string = "fsqrt.s f29, f30".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01011000000011110111111011010011 + ); + } + + #[test] + fn read_instructions_fsgnjs() { + let file_string = "fsgnj.s f31, ft1, ft2".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00100000001000001000111111010011 + ); + } + + #[test] + fn read_instructions_fsgnjns() { + let file_string = "fsgnjn.s ft3, ft4, ft5".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00100000010100100001000111010011 + ); + } + + #[test] + fn read_instructions_fsgnjxs() { + let file_string = "fsgnjx.s f6, f7, f8".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00100000100000111010001101010011 + ); + } + + #[test] + fn read_instructions_fmins() { + let file_string = "fmin.s fs1, fa0, fa1".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00101000101101010000010011010011 + ); + } + + #[test] + fn read_instructions_fmaxs() { + let file_string = "fmax.s fa2, fa3, fa4".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00101000111001101001011001010011 + ); + } + + #[test] + fn read_instructions_fcvtws() { + let file_string = "fcvt.w.s x1, fa5".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b11000000000001111111000011010011 + ); + } + + #[test] + fn read_instructions_fcvtwus() { + let file_string = "fcvt.wu.s x2, fa6".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b11000000000110000111000101010011 + ); + } + + #[test] + fn read_instructions_fmvxw() { + let file_string = "fmv.x.w x3, fa7".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b11100000000010001000000111010011 + ); + } + + #[test] + fn read_instructions_feqs() { + let file_string = "feq.s x4, fs2, fs3".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b10100001001110010010001001010011 + ); + } + + #[test] + fn read_instructions_flts() { + let file_string = "flt.s x5, fs4, fs5".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b10100001010110100001001011010011 + ); + } + + #[test] + fn read_instructions_fles() { + let file_string = "fle.s x6, fs6, fs7".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b10100001011110110000001101010011 + ); + } + + #[test] + fn read_instructions_fclasss() { + let file_string = "fclass.s x7, fs8".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b11100000000011000001001111010011 + ); + } + + #[test] + fn read_instructions_fcvtsw() { + let file_string = "fcvt.s.w fs9, x8".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b11010000000001000111110011010011 + ); + } + + #[test] + fn read_instructions_fcvtswu() { + let file_string = "fcvt.s.wu fs10, x9".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b11010000000101001111110101010011 + ); + } + + #[test] + fn read_instructions_fmvwx() { + let file_string = "fmv.w.x fs11, x10".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b11110000000001010000110111010011 + ); + } + + #[test] + fn read_instructions_fmaddd() { + let file_string = "fmadd.d ft8, ft9, ft10, ft11".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b11111011111011101111111001000011 + ); + } + + #[test] + fn read_instructions_fmsubd() { + let file_string = "fmsub.d f1, f2, f3, f4".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00100010001100010111000011000111 + ); + } + + #[test] + fn read_instructions_fnmaddd() { + let file_string = "fnmsub.d f5, f6, f7, f8".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01000010011100110111001011001011 + ); + } + + #[test] + fn read_instructions_fnmsubd() { + let file_string = "fnmadd.d f9, f10, f11, f12".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01100010101101010111010011001111 + ); + } + + #[test] + fn read_instructions_faddd() { + let file_string = "fadd.d f13, f14, f15".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00000010111101110111011011010011 + ); + } + + #[test] + fn read_instructions_fsubd() { + let file_string = "fsub.d f16, f17, f18".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00001011001010001111100001010011 + ); + } + + #[test] + fn read_instructions_fmuld() { + let file_string = "fmul.d f19, f20, f21".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); assert_eq!( - results.0.instructions[0].binary, - 0b10001101001010010000001000000000 + instruction_list[0].binary, + 0b00010011010110100111100111010011 ); + } + + #[test] + fn read_instructions_fdivd() { + let file_string = "fdiv.d f22, f23, f24".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + assert_eq!( - results.0.instructions[1].binary, - 0b00000010110010100100100000100000 + instruction_list[0].binary, + 0b00011011100010111111101101010011 + ); + } + + #[test] + fn read_instructions_fsqrtd() { + let file_string = "fsqrt.d f25, f26".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01011010000011010111110011010011 ); + } + + #[test] + fn read_instructions_fsgnjd() { + let file_string = "fsgnj.d f27, f28, f29".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + assert_eq!( - results.0.instructions[2].binary, - 0b00100001010010011010101010101010 + instruction_list[0].binary, + 0b00100011110111100000110111010011 + ); + } + + #[test] + fn read_instructions_fsgnjnd() { + let file_string = "fsgnjn.d f30, f31, f1".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00100010000111111001111101010011 + ); + } + + #[test] + fn read_instructions_fsgnjxd() { + let file_string = "fsgnjx.d f2, f3, f4".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00100010010000011010000101010011 + ); + } + + #[test] + fn read_instructions_fmind() { + let file_string = "fmin.d f5, f6, f7".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00101010011100110000001011010011 + ); + } + + #[test] + fn read_instructions_fmaxd() { + let file_string = "fmax.d f8, f9, f10".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00101010101001001001010001010011 + ); + } + + #[test] + fn read_instructions_fcvtsd() { + let file_string = "fcvt.s.d f11, f12".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01000000000101100111010111010011 + ); + } + + #[test] + fn read_instructions_fcvtds() { + let file_string = "fcvt.d.s f13, f14".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01000010000001110111011011010011 + ); + } + + #[test] + fn read_instructions_feqd() { + let file_string = "feq.d x11, f15, f16".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b10100011000001111010010111010011 + ); + } + + #[test] + fn read_instructions_fltd() { + let file_string = "flt.d x12, f17, f18".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b10100011001010001001011001010011 + ); + } + + #[test] + fn read_instructions_fled() { + let file_string = "fle.d x13, f19, f20".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b10100011010010011000011011010011 + ); + } + + #[test] + fn read_instructions_fclassd() { + let file_string = "fclass.d x14, f21".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b11100010000010101001011101010011 + ); + } + + #[test] + fn read_instructions_fcvtwd() { + let file_string = "fcvt.w.d x15, f22".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b11000010000010110111011111010011 + ); + } + + #[test] + fn read_instructions_fcvtwud() { + let file_string = "fcvt.wu.d x16, f23".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b11000010000110111111100001010011 + ); + } + + #[test] + fn read_instructions_fcvtdw() { + let file_string = "fcvt.d.w f24, x17".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b11010010000010001111110001010011 + ); + } + + #[test] + fn read_instructions_fcvtdwu() { + let file_string = "fcvt.d.wu f25, x18".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b11010010000110010111110011010011 + ); + } + + #[test] + fn read_instructions_flw() { + let file_string = "flw f26, 128(x19)".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00001000000010011010110100000111 + ); + } + + #[test] + fn read_instructions_fsw() { + let file_string = "fsw f27, 256(x20)".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00010001101110100010000000100111 + ); + } + + #[test] + fn read_instructions_fld() { + let file_string = "fld f28, 512(x21)".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b00100000000010101011111000000111 + ); + } + + #[test] + fn read_instructions_fsd() { + let file_string = "fsd f29, 1024(x22)".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b01000001110110110011000000100111 + ); + } + + #[test] + fn read_instructions_fcvtls() { + let file_string = "fcvt.l.s x23, f30".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b11000000001011110111101111010011 + ); + } + + #[test] + fn read_instructions_fcvtlus() { + let file_string = "fcvt.lu.s x24, f31".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b11000000001111111111110001010011 + ); + } + + #[test] + fn read_instructions_fcvtsl() { + let file_string = "fcvt.s.l f1, x25".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b11010000001011001111000011010011 + ); + } + + #[test] + fn read_instructions_fcvtslu() { + let file_string = "fcvt.s.lu f2, x26".to_string(); + + let instruction_list = instruction_parser_riscv(file_string); + + assert_eq!( + instruction_list[0].binary, + 0b11010000001111010111000101010011 ); } } -mod read_instructions_tests { +mod read_mips_instructions_tests { use crate::parser::parser_structs_and_enums::ErrorType::JALRRDRegisterZero; - use crate::tests::parser::parser_assembler_main::helper_functions::instruction_parser; + use crate::tests::parser::parser_assembler_main::helper_functions::instruction_parser_mips; #[test] fn read_instructions_add() { let file_string = "add $t1, $s6, $t2".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -42,7 +1560,7 @@ mod read_instructions_tests { fn read_instructions_addu() { let file_string = "addu $t1, $t2, $t3".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -54,7 +1572,7 @@ mod read_instructions_tests { fn read_instructions_sub() { let file_string = "sub $t1, $s6, $t2".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -66,7 +1584,7 @@ mod read_instructions_tests { fn read_instructions_mul() { let file_string = "mul $t1, $s6, $t2".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -78,7 +1596,7 @@ mod read_instructions_tests { fn read_instructions_div() { let file_string = "div $t1, $t1, $s6".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -90,7 +1608,7 @@ mod read_instructions_tests { fn read_instructions_lw() { let file_string = "lw $t1, 512($t1)".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -102,7 +1620,7 @@ mod read_instructions_tests { fn read_instructions_sw() { let file_string = "sw $t1, 512($t1)".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -114,7 +1632,7 @@ mod read_instructions_tests { fn read_instructions_lui() { let file_string = "lui $t1, 43690".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -126,7 +1644,7 @@ mod read_instructions_tests { fn read_instructions_aui() { let file_string = "aui $t1, $t1, 43690".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -138,7 +1656,7 @@ mod read_instructions_tests { fn read_instructions_addi() { let file_string = "addi $t1, $t2, 43690".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, 0b00100001010010011010101010101010 @@ -147,7 +1665,7 @@ mod read_instructions_tests { #[test] fn read_instructions_recognizes_addiu() { - let instruction_list = instruction_parser("addiu $t1, $t2, 0x64".to_string()); + let instruction_list = instruction_parser_mips("addiu $t1, $t2, 0x64".to_string()); assert_eq!( instruction_list[0].binary, @@ -159,7 +1677,7 @@ mod read_instructions_tests { fn read_instructions_and() { let file_string = "and $t1, $s6, $t2".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -171,7 +1689,7 @@ mod read_instructions_tests { fn read_instructions_or() { let file_string = "or $t1, $s6, $t2".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -183,7 +1701,7 @@ mod read_instructions_tests { fn read_instructions_ori() { let file_string = "ori $t1, $t2, 43690".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -195,7 +1713,7 @@ mod read_instructions_tests { fn read_instructions_andi() { let file_string = "andi $t1, $t2, 43690".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -207,7 +1725,7 @@ mod read_instructions_tests { fn read_instructions_dadd() { let file_string = "dadd $t1, $t2, $s6".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -219,7 +1737,7 @@ mod read_instructions_tests { fn read_instructions_dsub() { let file_string = "dsub $t1, $t2, $s6".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -231,7 +1749,7 @@ mod read_instructions_tests { fn read_instructions_dmul() { let file_string = "dmul $t1, $t2, $s6".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -243,7 +1761,7 @@ mod read_instructions_tests { fn read_instructions_ddiv() { let file_string = "ddiv $t1, $t1, $t2".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -255,7 +1773,7 @@ mod read_instructions_tests { fn read_instructions_add_s() { let file_string = "add.s $f9, $f10, $f22".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -267,7 +1785,7 @@ mod read_instructions_tests { fn read_instructions_add_d() { let file_string = "add.d $f9, $f10, $f22".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -279,7 +1797,7 @@ mod read_instructions_tests { fn read_instructions_sub_s() { let file_string = "sub.s $f9, $f10, $f22".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -291,7 +1809,7 @@ mod read_instructions_tests { fn read_instructions_sub_d() { let file_string = "sub.d $f9, $f10, $f22".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -303,7 +1821,7 @@ mod read_instructions_tests { fn read_instructions_mul_s() { let file_string = "mul.s $f9, $f10, $f22".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -315,7 +1833,7 @@ mod read_instructions_tests { fn read_instructions_mul_d() { let file_string = "mul.d $f9, $f10, $f22".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -327,7 +1845,7 @@ mod read_instructions_tests { fn read_instructions_div_s() { let file_string = "div.s $f9, $f10, $f22".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -339,7 +1857,7 @@ mod read_instructions_tests { fn read_instructions_div_d() { let file_string = "div.d $f9, $f10, $f22".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -351,7 +1869,7 @@ mod read_instructions_tests { fn read_instructions_dahi() { let file_string = "dahi $t1, 43690".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -363,7 +1881,7 @@ mod read_instructions_tests { fn read_instructions_dati() { let file_string = "dati $t1, 43690".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -375,7 +1893,7 @@ mod read_instructions_tests { fn read_instructions_daddi() { let file_string = "daddi $t1, $t2, 43690".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -387,7 +1905,7 @@ mod read_instructions_tests { fn read_instructions_daddiu() { let file_string = "daddiu $t1, $t2, 43690".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -399,7 +1917,7 @@ mod read_instructions_tests { fn read_instructions_daddu() { let file_string = "daddu $t1, $t2, $t3".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -411,7 +1929,7 @@ mod read_instructions_tests { fn read_instructions_dsubu() { let file_string = "dsubu $t1, $t2, $t3".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -423,7 +1941,7 @@ mod read_instructions_tests { fn read_instructions_dmulu() { let file_string = "dmulu $t1, $t2, $t3".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -435,7 +1953,7 @@ mod read_instructions_tests { fn read_instructions_ddivu() { let file_string = "ddivu $t1, $t1, $t2".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -447,7 +1965,7 @@ mod read_instructions_tests { fn read_instructions_slt() { let file_string = "slt $t1, $t2, $s6".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -459,7 +1977,7 @@ mod read_instructions_tests { fn read_instructions_sltu() { let file_string = "sltu $t1, $t2, $s6".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -471,7 +1989,7 @@ mod read_instructions_tests { fn read_instructions_swc1() { let file_string = "swc1 $f9, 43690($t2)".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -483,7 +2001,7 @@ mod read_instructions_tests { fn read_instructions_lwc1() { let file_string = "lwc1 $f9, 43690($t2)".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -495,7 +2013,7 @@ mod read_instructions_tests { fn read_instructions_mtc1() { let file_string = "mtc1 $t1, $f22".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -507,7 +2025,7 @@ mod read_instructions_tests { fn read_instructions_dmtc1() { let file_string = "dmtc1 $t1, $f22".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -519,7 +2037,7 @@ mod read_instructions_tests { fn read_instructions_mfc1() { let file_string = "mfc1 $t1, $f22".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -531,7 +2049,7 @@ mod read_instructions_tests { fn read_instructions_dmfc1() { let file_string = "dmfc1 $t1, $f22".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[0].binary, @@ -545,7 +2063,7 @@ mod read_instructions_tests { "Add $t1, $t2, $t3\nAddress: add $t1, #t2, $t3\nlw $t1, 400($t2)\nj Address" .to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[3].binary, @@ -559,7 +2077,7 @@ mod read_instructions_tests { "Add $t1, $t2, $t3\nAddress: add $t1, #t2, $t3\nlw $t1, 400($t2)\njal Address" .to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[3].binary, @@ -570,7 +2088,7 @@ mod read_instructions_tests { #[test] fn read_instructions_beq() { let file_string = "Add $t1, $t2, $t3\nAddress: add $t1, #t2, $t3\nlw $t1, 400($t2)\nbeq $t1, $t2, address".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[3].binary, @@ -581,7 +2099,7 @@ mod read_instructions_tests { #[test] fn read_instructions_bne() { let file_string = "Add $t1, $t2, $t3\nAddress: add $t1, #t2, $t3\nlw $t1, 400($t2)\nbne $t1, $t2, address".to_string(); - let instruction_list = instruction_parser(file_string); + let instruction_list = instruction_parser_mips(file_string); assert_eq!( instruction_list[3].binary, @@ -591,7 +2109,7 @@ mod read_instructions_tests { #[test] fn read_instructions_c_eq_s() { - let instruction_list = instruction_parser("c.eq.s $f9, $f22".to_string()); + let instruction_list = instruction_parser_mips("c.eq.s $f9, $f22".to_string()); assert_eq!( instruction_list[0].binary, @@ -601,7 +2119,7 @@ mod read_instructions_tests { #[test] fn read_instructions_c_eq_d() { - let instruction_list = instruction_parser("c.eq.d $f9, $f22".to_string()); + let instruction_list = instruction_parser_mips("c.eq.d $f9, $f22".to_string()); assert_eq!( instruction_list[0].binary, @@ -611,7 +2129,7 @@ mod read_instructions_tests { #[test] fn read_instructions_c_lt_s() { - let instruction_list = instruction_parser("c.lt.s $f9, $f22".to_string()); + let instruction_list = instruction_parser_mips("c.lt.s $f9, $f22".to_string()); assert_eq!( instruction_list[0].binary, @@ -621,7 +2139,7 @@ mod read_instructions_tests { #[test] fn read_instructions_c_lt_d() { - let instruction_list = instruction_parser("c.lt.d $f9, $f22".to_string()); + let instruction_list = instruction_parser_mips("c.lt.d $f9, $f22".to_string()); assert_eq!( instruction_list[0].binary, @@ -631,7 +2149,7 @@ mod read_instructions_tests { #[test] fn read_instructions_c_le_s() { - let instruction_list = instruction_parser("c.le.s $f9, $f22".to_string()); + let instruction_list = instruction_parser_mips("c.le.s $f9, $f22".to_string()); assert_eq!( instruction_list[0].binary, @@ -641,7 +2159,7 @@ mod read_instructions_tests { #[test] fn read_instructions_c_le_d() { - let instruction_list = instruction_parser("c.le.d $f9, $f22".to_string()); + let instruction_list = instruction_parser_mips("c.le.d $f9, $f22".to_string()); assert_eq!( instruction_list[0].binary, @@ -651,7 +2169,7 @@ mod read_instructions_tests { #[test] fn read_instructions_c_ngt_s() { - let instruction_list = instruction_parser("c.ngt.s $f9, $f22".to_string()); + let instruction_list = instruction_parser_mips("c.ngt.s $f9, $f22".to_string()); assert_eq!( instruction_list[0].binary, @@ -661,7 +2179,7 @@ mod read_instructions_tests { #[test] fn read_instructions_c_ngt_d() { - let instruction_list = instruction_parser("c.ngt.d $f9, $f22".to_string()); + let instruction_list = instruction_parser_mips("c.ngt.d $f9, $f22".to_string()); assert_eq!( instruction_list[0].binary, @@ -671,7 +2189,7 @@ mod read_instructions_tests { #[test] fn read_instructions_c_nge_s() { - let instruction_list = instruction_parser("c.nge.s $f9, $f22".to_string()); + let instruction_list = instruction_parser_mips("c.nge.s $f9, $f22".to_string()); assert_eq!( instruction_list[0].binary, @@ -681,7 +2199,7 @@ mod read_instructions_tests { #[test] fn read_instructions_c_nge_d() { - let instruction_list = instruction_parser("c.nge.d $f9, $f22".to_string()); + let instruction_list = instruction_parser_mips("c.nge.d $f9, $f22".to_string()); assert_eq!( instruction_list[0].binary, @@ -692,7 +2210,7 @@ mod read_instructions_tests { #[test] fn read_instruction_bc1t() { let instruction_list = - instruction_parser("instruction: add $t1, $t2, $t3\nbc1t instruction".to_string()); + instruction_parser_mips("instruction: add $t1, $t2, $t3\nbc1t instruction".to_string()); assert_eq!( instruction_list[1].binary, @@ -703,7 +2221,7 @@ mod read_instructions_tests { #[test] fn read_instruction_bc1f() { let instruction_list = - instruction_parser("instruction: add $t1, $t2, $t3\nbc1f instruction".to_string()); + instruction_parser_mips("instruction: add $t1, $t2, $t3\nbc1f instruction".to_string()); assert_eq!( instruction_list[1].binary, @@ -713,7 +2231,7 @@ mod read_instructions_tests { #[test] fn read_instruction_jalr_with_rd() { - let instruction_list = instruction_parser("jalr $t1, $t2".to_string()); + let instruction_list = instruction_parser_mips("jalr $t1, $t2".to_string()); assert_eq!( instruction_list[0].binary, @@ -723,7 +2241,7 @@ mod read_instructions_tests { #[test] fn read_instruction_jalr_without_rd() { - let instruction_list = instruction_parser("jalr $t2".to_string()); + let instruction_list = instruction_parser_mips("jalr $t2".to_string()); assert_eq!( instruction_list[0].binary, @@ -733,7 +2251,7 @@ mod read_instructions_tests { #[test] fn read_instruction_jalr_creates_error_with_rd_equal_0() { - let instruction_list = instruction_parser("jalr $zero, $t2".to_string()); + let instruction_list = instruction_parser_mips("jalr $zero, $t2".to_string()); assert_eq!(instruction_list[0].errors[0].error_name, JALRRDRegisterZero); } @@ -741,7 +2259,7 @@ mod read_instructions_tests { #[test] fn read_instructions_recognizes_b() { let instruction_list = - instruction_parser(".text\njump: addi $t1, $t2, 100\nb jump".to_string()); + instruction_parser_mips(".text\njump: addi $t1, $t2, 100\nb jump".to_string()); assert_eq!( instruction_list[1].binary, @@ -751,7 +2269,7 @@ mod read_instructions_tests { #[test] fn read_instructions_recognizes_jr() { - let instruction_list = instruction_parser(".text\njump: jr $zero\nb jump".to_string()); + let instruction_list = instruction_parser_mips(".text\njump: jr $zero\nb jump".to_string()); assert_eq!( instruction_list[0].binary, @@ -761,7 +2279,7 @@ mod read_instructions_tests { #[test] fn read_instructions_recognizes_jr_ra() { - let instruction_list = instruction_parser(".text\njump: jr $ra\nb jump".to_string()); + let instruction_list = instruction_parser_mips(".text\njump: jr $ra\nb jump".to_string()); // Page 249 in the MIPS64 release 6 manual // https://s3-eu-west-1.amazonaws.com/downloads-mips/documents/MIPS_Architecture_MIPS64_InstructionSet_%20AFP_P_MD00087_06.05.pdf @@ -773,7 +2291,7 @@ mod read_instructions_tests { #[test] fn read_instructions_recognizes_sll() { - let instruction_list = instruction_parser(".text\nsll $t1, $t2, 5".to_string()); + let instruction_list = instruction_parser_mips(".text\nsll $t1, $t2, 5".to_string()); assert_eq!( instruction_list[0].binary, @@ -783,12 +2301,13 @@ mod read_instructions_tests { #[test] fn read_instructions_recognizes_nop() { - let instruction_list = instruction_parser(".text\nnop".to_string()); + let instruction_list = instruction_parser_mips(".text\nnop".to_string()); assert_eq!(instruction_list[0].binary, 0); } } +use crate::emulation_core::architectures::AvailableDatapaths; use crate::parser::assembling::assemble_data_binary; use crate::parser::parser_assembler_main::{ create_binary_vec, parser, place_binary_in_middle_of_another, read_instructions, @@ -797,7 +2316,7 @@ use crate::parser::parser_structs_and_enums::ErrorType::{ UnrecognizedInstruction, UnsupportedInstruction, }; use crate::parser::parser_structs_and_enums::{ - ProgramInfo, SUPPORTED_INSTRUCTIONS, UNSUPPORTED_INSTRUCTIONS, + ProgramInfo, SUPPORTED_INSTRUCTIONS_MIPS, UNSUPPORTED_INSTRUCTIONS_MIPS, }; use crate::parser::parsing::{create_label_map, separate_data_and_text, tokenize_program}; use crate::parser::pseudo_instruction_parsing::{ @@ -829,13 +2348,16 @@ fn place_binary_works_dahi() { mod helper_functions { use crate::parser::assembling::assemble_data_binary; - use crate::parser::parser_assembler_main::read_instructions; + use crate::parser::parser_assembler_main::{read_instructions, read_instructions_riscv}; use crate::parser::parser_structs_and_enums::Instruction; use crate::parser::parsing::{create_label_map, separate_data_and_text, tokenize_program}; - use crate::parser::pseudo_instruction_parsing::expand_pseudo_instructions_and_assign_instruction_numbers; + use crate::parser::pseudo_instruction_parsing::{ + expand_pseudo_instructions_and_assign_instruction_numbers, + expand_pseudo_instructions_and_assign_instruction_numbers_riscv, + }; use std::collections::HashMap; - pub fn instruction_parser(mut file_string: String) -> Vec { + pub fn instruction_parser_mips(mut file_string: String) -> Vec { file_string = file_string.to_lowercase(); let mut monaco_line_info_vec = tokenize_program(file_string); @@ -854,6 +2376,26 @@ mod helper_functions { instruction_list } + + pub fn instruction_parser_riscv(mut file_string: String) -> Vec { + file_string = file_string.to_lowercase(); + + let mut monaco_line_info_vec = tokenize_program(file_string); + let (mut instruction_list, mut data) = + separate_data_and_text(&mut monaco_line_info_vec.clone()); + expand_pseudo_instructions_and_assign_instruction_numbers_riscv( + &mut instruction_list, + &data, + &mut monaco_line_info_vec, + ); + assemble_data_binary(&mut data); + + let labels: HashMap = create_label_map(&mut instruction_list, &mut data); + + read_instructions_riscv(&mut instruction_list, &labels, &mut monaco_line_info_vec); + + instruction_list + } } #[test] @@ -896,7 +2438,11 @@ fn create_binary_vec_works_with_data() { #[test] fn read_instructions_recognizes_valid_but_unsupported_instructions() { - let program_info = parser("nor $t1, $t2, $t3\ndsrav $t1, $t2, $t3\n".to_string()).0; + let program_info = parser( + "nor $t1, $t2, $t3\ndsrav $t1, $t2, $t3\n".to_string(), + AvailableDatapaths::MIPS, + ) + .0; assert_eq!( program_info.instructions[0].errors[0].error_name, @@ -912,6 +2458,7 @@ fn read_instructions_recognizes_valid_but_unsupported_instructions() { fn console_output_post_assembly_works_with_errors() { let result = parser( ".text\nadd $t1, $t2, 1235\n.data\nlabel: .ascii 100\n.text\nlw t1, address".to_string(), + AvailableDatapaths::MIPS, ) .0 .console_out_post_assembly; @@ -924,6 +2471,7 @@ fn console_output_post_assembly_works_with_no_errors_present() { let result = parser( ".text\nadd $t1, $t2, $t3\n.data\nlabel: .ascii \"string\"\n.text\nlw $t1, 40($t1)" .to_string(), + AvailableDatapaths::MIPS, ) .0 .console_out_post_assembly; @@ -933,7 +2481,11 @@ fn console_output_post_assembly_works_with_no_errors_present() { #[test] fn mouse_hover_holds_information_about_valid_instructions() { - let program_info = parser(".text\nori $t1, $t2, 100\nsyscall".to_string()).0; + let program_info = parser( + ".text\nori $t1, $t2, 100\nsyscall".to_string(), + AvailableDatapaths::MIPS, + ) + .0; assert_eq!(program_info.monaco_line_info[0].mouse_hover_string, ""); assert_eq!(program_info.monaco_line_info[1].mouse_hover_string, "**Syntax:** `ori rt, rs, immediate`\n\nBitwise ors the contents of `rs` with the left zero-extended `immediate` value, and stores the result in `rt`.\n\n\n\n**Binary:** `0b00110101010010010000000001100100`"); @@ -941,7 +2493,11 @@ fn mouse_hover_holds_information_about_valid_instructions() { #[test] fn mouse_hover_holds_information_about_pseudo_instructions() { - let program_info = parser(".text\nlabel: subi $t1, $t2, 100\nsyscall".to_string()).0; + let program_info = parser( + ".text\nlabel: subi $t1, $t2, 100\nsyscall".to_string(), + AvailableDatapaths::MIPS, + ) + .0; assert_eq!(program_info.monaco_line_info[0].mouse_hover_string, ""); assert_eq!(program_info.monaco_line_info[1].mouse_hover_string, "`subi` is a pseudo-instruction.\n\n```\nsubi rt, rs, immediate =>\nori $at, $zero, immediate\nsub rt, rs, $at\n\n```\n\n\n\n**Binary:** `0b00110100000000010000000001100100`\n\n**Binary:** `0b00000001010000010100100000100010`"); @@ -949,7 +2505,11 @@ fn mouse_hover_holds_information_about_pseudo_instructions() { #[test] fn errors_do_not_go_into_mouse_hover() { - let program_info = parser(".text\nori $t1, $t2, $t3\nsyscall".to_string()).0; + let program_info = parser( + ".text\nori $t1, $t2, $t3\nsyscall".to_string(), + AvailableDatapaths::MIPS, + ) + .0; assert_eq!(program_info.monaco_line_info[0].mouse_hover_string, ""); assert_eq!(program_info.monaco_line_info[1].mouse_hover_string, "**Syntax:** `ori rt, rs, immediate`\n\nBitwise ors the contents of `rs` with the left zero-extended `immediate` value, and stores the result in `rt`.\n\n"); @@ -959,6 +2519,7 @@ fn errors_do_not_go_into_mouse_hover() { fn syscall_message_and_binary_does_not_go_in_mouse_hover_if_the_syscall_was_added_by_parser() { let monaco_line_info = parser( ".text\nori $t1, $t2, 100\nlabel: subi $t1, $t2, 100\nadd $t1, $t2, $t3\n".to_string(), + AvailableDatapaths::MIPS, ) .0 .monaco_line_info; @@ -968,7 +2529,9 @@ fn syscall_message_and_binary_does_not_go_in_mouse_hover_if_the_syscall_was_adde assert_eq!(monaco_line_info[2].mouse_hover_string, "`subi` is a pseudo-instruction.\n\n```\nsubi rt, rs, immediate =>\nori $at, $zero, immediate\nsub rt, rs, $at\n\n```\n\n\n\n**Binary:** `0b00110100000000010000000001100100`\n\n**Binary:** `0b00000001010000010100100000100010`"); assert_eq!(monaco_line_info[3].mouse_hover_string, "**Syntax:** `add rd, rs, rt`\n\nAdds the 32-bit values in `rs` and `rt`, and places the result in `rd`.\n\nIn hardware implementations, the result is not placed in `rd` if adding `rs` and `rt` causes a 32-bit overflow. However, SWIM places the result in `rd` regardless since there is no exception handling.\n\n**Binary:** `0b00000001010010110100100000100000`\n\n"); - let monaco_line_info = parser(".text".to_string()).0.monaco_line_info; + let monaco_line_info = parser(".text".to_string(), AvailableDatapaths::MIPS) + .0 + .monaco_line_info; assert_eq!(monaco_line_info[0].mouse_hover_string, "\n\n"); } @@ -977,6 +2540,7 @@ fn mouse_hover_holds_information_info_for_various_instruction_types() { let program_info = parser( ".text\nori $t1, $t2, 100\nlabel: subi $t1, $t2, 100\nadd $t1, $t2, $t3\nsyscall\n" .to_string(), + AvailableDatapaths::MIPS, ) .0; @@ -989,11 +2553,15 @@ fn mouse_hover_holds_information_info_for_various_instruction_types() { #[test] fn instructions_directives_and_registers_work_regardless_of_capitalization() { - let result = - parser(".TexT\nOR $t1, $T2, $t3\nor $t1, $t2, $t3\n.DATA\nabel: .WOrD 100".to_string()); + let result = parser( + ".TexT\nOR $t1, $T2, $t3\nor $t1, $t2, $t3\n.DATA\nabel: .WOrD 100".to_string(), + AvailableDatapaths::MIPS, + ); - let correct = - parser(".TexT\nOR $t1, $T2, $t3\nor $t1, $t2, $t3\n.DATA\nabel: .WOrD 100".to_lowercase()); + let correct = parser( + ".TexT\nOR $t1, $T2, $t3\nor $t1, $t2, $t3\n.DATA\nabel: .WOrD 100".to_lowercase(), + AvailableDatapaths::MIPS, + ); assert_eq!(result.1, correct.1); assert_eq!( result.0.console_out_post_assembly, @@ -1013,21 +2581,23 @@ fn instructions_directives_and_registers_work_regardless_of_capitalization() { #[test] fn parser_assembler_works_with_empty_strings() { - let _ = parser("".to_string()); - let _ = parser("\n".to_string()); - let _ = parser("\n\n".to_string()); + let _ = parser("".to_string(), AvailableDatapaths::MIPS); + let _ = parser("\n".to_string(), AvailableDatapaths::MIPS); + let _ = parser("\n\n".to_string(), AvailableDatapaths::MIPS); } #[test] fn create_binary_vec_works_with_all_mod_4_options() { let result = parser( "ori $s0, $zero, 12345\nori $s0, $zero, 12345\n.data\nlab: .ascii \"h\"".to_string(), + AvailableDatapaths::MIPS, ) .1; assert_eq!(result, vec![873476153, 873476153, 12, 1744830464]); let result = parser( "ori $s0, $zero, 12345\nori $s0, $zero, 12345\n.data\nlab: .ascii \"ha\"".to_string(), + AvailableDatapaths::MIPS, ) .1; assert_eq!( @@ -1037,6 +2607,7 @@ fn create_binary_vec_works_with_all_mod_4_options() { let result = parser( "ori $s0, $zero, 12345\nori $s0, $zero, 12345\n.data\nlab: .ascii \"han\"".to_string(), + AvailableDatapaths::MIPS, ) .1; assert_eq!( @@ -1046,6 +2617,7 @@ fn create_binary_vec_works_with_all_mod_4_options() { let result = parser( "ori $s0, $zero, 12345\nori $s0, $zero, 12345\n.data\nlab: .ascii \"hank\"".to_string(), + AvailableDatapaths::MIPS, ) .1; assert_eq!( @@ -1055,17 +2627,21 @@ fn create_binary_vec_works_with_all_mod_4_options() { } #[test] -fn no_unsupported_instructions_are_recognized_by_parser() { - for instruction in UNSUPPORTED_INSTRUCTIONS { - let result = parser(instruction.to_string()).0.monaco_line_info; +fn no_unsupported_mips_instructions_are_recognized_by_parser() { + for instruction in UNSUPPORTED_INSTRUCTIONS_MIPS { + let result = parser(instruction.to_string(), AvailableDatapaths::MIPS) + .0 + .monaco_line_info; assert_eq!(result[0].errors[0].error_name, UnsupportedInstruction); } } #[test] -fn supported_instructions_are_recognized_by_parser() { - for instruction in SUPPORTED_INSTRUCTIONS { - let result = parser(instruction.to_string()).0.monaco_line_info; +fn supported_mips_instructions_are_recognized_by_parser() { + for instruction in SUPPORTED_INSTRUCTIONS_MIPS { + let result = parser(instruction.to_string(), AvailableDatapaths::MIPS) + .0 + .monaco_line_info; for error in &result[0].errors { assert_ne!(error.error_name, UnsupportedInstruction); assert_ne!(error.error_name, UnrecognizedInstruction); @@ -1075,25 +2651,33 @@ fn supported_instructions_are_recognized_by_parser() { #[test] fn main_and_start_labelled_instructions_change_program_info_pc_starting_point() { - let result = parser("addi $t1, $t2, 100\nsw $t1, 400($zero)".to_string()) - .0 - .pc_starting_point; + let result = parser( + "addi $t1, $t2, 100\nsw $t1, 400($zero)".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .pc_starting_point; assert_eq!(result, 0); - let result = - parser("addi $t1, $t2, 100\nsw $t1, 400($zero)\nmain: lw $t2, 320($zero)".to_string()) - .0 - .pc_starting_point; + let result = parser( + "addi $t1, $t2, 100\nsw $t1, 400($zero)\nmain: lw $t2, 320($zero)".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .pc_starting_point; assert_eq!(result, 8); - let result = - parser("addi $t1, $t2, 100\nstart: sw $t1, 400($zero)\nlw $t2, 320($zero)".to_string()) - .0 - .pc_starting_point; + let result = parser( + "addi $t1, $t2, 100\nstart: sw $t1, 400($zero)\nlw $t2, 320($zero)".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .pc_starting_point; assert_eq!(result, 4); let result = parser( "addi $t1, $t2, 100\nstart: sw $t1, 400($zero)\nmain: lw $t2, 320($zero)".to_string(), + AvailableDatapaths::MIPS, ) .0 .pc_starting_point; diff --git a/src/tests/parser/parsing.rs b/src/tests/parser/parsing.rs index 1a6829c49..c0ca9ae18 100644 --- a/src/tests/parser/parsing.rs +++ b/src/tests/parser/parsing.rs @@ -1,3 +1,4 @@ +use crate::emulation_core::architectures::AvailableDatapaths; use crate::parser::assembling::assemble_data_binary; use crate::parser::parser_assembler_main::parser; use crate::parser::parser_structs_and_enums::ErrorType::{ @@ -325,13 +326,18 @@ fn separate_data_and_text_works_basic_version() { fn separate_data_and_text_can_handle_empty_lines() { //this test realistically is only important to check that it does not panic but we might as well go a step further and //check that the result generated with empty lines is identical to the result without empty lines save for line number - let mut result_1 = - parser(".text\nori $s0, $zero, 0x1234\n\n.data\nlabel: .word 0xface".to_string()) - .0 - .monaco_line_info; - let result_2 = parser(".text\nori $s0, $zero, 0x1234\n.data\nlabel: .word 0xface".to_string()) - .0 - .monaco_line_info; + let mut result_1 = parser( + ".text\nori $s0, $zero, 0x1234\n\n.data\nlabel: .word 0xface".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .monaco_line_info; + let result_2 = parser( + ".text\nori $s0, $zero, 0x1234\n.data\nlabel: .word 0xface".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .monaco_line_info; result_1[2].line_number = 1; result_1[3].line_number = 2; result_1[4].line_number = 3; @@ -344,9 +350,12 @@ fn separate_data_and_text_can_handle_empty_lines() { #[test] fn separate_data_and_text_generates_error_on_missing_commas_text() { - let result = parser("add, $t1, $t2, $t3,\nlw $t1 400($t2)".to_string()) - .0 - .monaco_line_info; + let result = parser( + "add, $t1, $t2, $t3,\nlw $t1 400($t2)".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .monaco_line_info; let error_0_line_0 = Error { error_name: UnnecessaryComma, @@ -736,9 +745,12 @@ fn build_instruction_list_allows_double_label_on_instructions() { #[test] fn build_instruction_list_generates_error_on_label_on_last_line() { - let result = parser("lw $t1, 400($zero)\nadd $t1, $t2, $t3\nlabel:\n".to_string()) - .0 - .monaco_line_info; + let result = parser( + "lw $t1, 400($zero)\nadd $t1, $t2, $t3\nlabel:\n".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .monaco_line_info; assert_eq!(result[2].errors[0].error_name, LabelAssignmentError); } @@ -832,9 +844,12 @@ fn create_label_map_pushes_errors_instead_of_inserting_duplicate_label_name() { } #[test] fn suggest_error_corrections_works_with_various_gp_registers() { - let result = parser("add $t1, $t2, @t3\nori not, ro, 100".to_string()) - .0 - .instructions; + let result = parser( + "add $t1, $t2, @t3\nori not, ro, 100".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .instructions; assert_eq!( result[0].errors[0].message, @@ -852,9 +867,12 @@ fn suggest_error_corrections_works_with_various_gp_registers() { #[test] fn suggest_error_corrections_works_with_various_fp_registers() { - let result = parser("add.s $f1, $f2, f3\nadd.d fake, $052, 1qp".to_string()) - .0 - .instructions; + let result = parser( + "add.s $f1, $f2, f3\nadd.d fake, $052, 1qp".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .instructions; assert_eq!( result[0].errors[0].message, @@ -876,10 +894,12 @@ fn suggest_error_corrections_works_with_various_fp_registers() { #[test] fn suggest_error_corrections_works_with_labels() { - let result = - parser("j stable\nlabel: add $t1, $t2, $t3\ntable: sub $t1, $t2, $t3\nj lapel".to_string()) - .0 - .instructions; + let result = parser( + "j stable\nlabel: add $t1, $t2, $t3\ntable: sub $t1, $t2, $t3\nj lapel".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .instructions; assert_eq!( result[0].errors[0].message, @@ -893,9 +913,12 @@ fn suggest_error_corrections_works_with_labels() { #[test] fn suggest_error_corrections_works_with_labels_when_no_labels_specified() { - let result = parser("add $t1, $t2, $t3\nj stable\nlw $t1, 100($zero)\n".to_string()) - .0 - .instructions; + let result = parser( + "add $t1, $t2, $t3\nj stable\nlw $t1, 100($zero)\n".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .instructions; assert_eq!( result[1].errors[0].message, "There is no recognized labelled memory.\n" @@ -904,9 +927,12 @@ fn suggest_error_corrections_works_with_labels_when_no_labels_specified() { #[test] fn suggest_error_corrections_works_with_instructions() { - let result = parser("sun $t1, $t2, $t3\nqq $t1, 100($zero)\n.c.eqd $f1, $f1, $f3".to_string()) - .0 - .instructions; + let result = parser( + "sun $t1, $t2, $t3\nqq $t1, 100($zero)\n.c.eqd $f1, $f1, $f3".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .instructions; assert_eq!( result[0].errors[0].message, @@ -927,6 +953,7 @@ fn suggest_error_corrections_works_with_data_types() { let result = parser( ".data\nlabel: word 100\ntable: .bite 'c','1'\nlapel: gobbledygook \"this is a string\"" .to_string(), + AvailableDatapaths::MIPS, ) .0 .data; @@ -947,10 +974,12 @@ fn suggest_error_corrections_works_with_data_types() { #[test] fn suggest_error_suggestions_associates_error_with_monaco_line_info() { - let lines = - parser("ori $t1, 100, $t2\nlw $f1, 400($zero)\n.data\nword .wod \"a\"\n".to_string()) - .0 - .monaco_line_info; + let lines = parser( + "ori $t1, 100, $t2\nlw $f1, 400($zero)\n.data\nword .wod \"a\"\n".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .monaco_line_info; let actual = Error { error_name: ErrorType::UnrecognizedGPRegister, @@ -995,7 +1024,9 @@ fn suggest_error_suggestions_associates_error_with_monaco_line_info() { #[test] fn operators_with_commas_cause_error() { - let result = parser("ori, $t1, $t2, 100".to_string()).0.monaco_line_info; + let result = parser("ori, $t1, $t2, 100".to_string(), AvailableDatapaths::MIPS) + .0 + .monaco_line_info; for line in result { for error in line.errors { diff --git a/src/tests/parser/pseudo_instruction_parsing.rs b/src/tests/parser/pseudo_instruction_parsing.rs index 99d90264f..1fcfb0b18 100644 --- a/src/tests/parser/pseudo_instruction_parsing.rs +++ b/src/tests/parser/pseudo_instruction_parsing.rs @@ -1,3 +1,4 @@ +use crate::emulation_core::architectures::AvailableDatapaths; use crate::parser::assembling::assemble_data_binary; use crate::parser::parser_assembler_main::parser; use crate::parser::parser_structs_and_enums::TokenType::Operator; @@ -10,9 +11,12 @@ use std::collections::HashMap; #[test] fn expand_pseudo_instructions_and_assign_instruction_number_adds_syscall_if_it_is_missing() { - let result = parser("addi $t1, $t2, 100\nsw $t1, label".to_string()) - .0 - .updated_monaco_string; + let result = parser( + "addi $t1, $t2, 100\nsw $t1, label".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .updated_monaco_string; let correct_result = "addi $t1, $t2, 100\nsw $t1, label\nsyscall\n".to_string(); assert_eq!(result, correct_result); @@ -21,9 +25,12 @@ fn expand_pseudo_instructions_and_assign_instruction_number_adds_syscall_if_it_i #[test] fn expand_pseudo_instructions_and_assign_instruction_number_adds_syscall_at_beginning_if_no_instruction( ) { - let result = parser(".data\nword .word 100\nother .byte 'a','a'\n".to_string()) - .0 - .updated_monaco_string; + let result = parser( + ".data\nword .word 100\nother .byte 'a','a'\n".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .updated_monaco_string; let correct_result = ".text\nsyscall\n.data\nword .word 100\nother .byte 'a','a'\n".to_string(); @@ -33,7 +40,7 @@ fn expand_pseudo_instructions_and_assign_instruction_number_adds_syscall_at_begi #[test] fn expand_pseudo_instructions_and_assign_instruction_number_adds_syscall_after_first_instance_of_text( ) { - let result = parser(".data\nword .word 100\n.text\n.data\nother .byte 'a','a'\n.text\n.data\nfinal: .space 10\n".to_string()).0.updated_monaco_string; + let result = parser(".data\nword .word 100\n.text\n.data\nother .byte 'a','a'\n.text\n.data\nfinal: .space 10\n".to_string(), AvailableDatapaths::MIPS).0.updated_monaco_string; let correct_result = ".data\nword .word 100\n.text\nsyscall\n.data\nother .byte 'a','a'\n.text\n.data\nfinal: .space 10\n".to_string(); @@ -43,9 +50,12 @@ fn expand_pseudo_instructions_and_assign_instruction_number_adds_syscall_after_f #[test] fn expand_pseudo_instructions_and_assign_instruction_number_does_not_add_syscall_if_it_is_present() { - let result = parser("addi $t1, $t2, 100\nsw $t1, label\nsyscall\n".to_string()) - .0 - .updated_monaco_string; + let result = parser( + "addi $t1, $t2, 100\nsw $t1, label\nsyscall\n".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .updated_monaco_string; let correct_result: String = "addi $t1, $t2, 100\nsw $t1, label\nsyscall\n".to_string(); @@ -55,9 +65,12 @@ fn expand_pseudo_instructions_and_assign_instruction_number_does_not_add_syscall #[test] fn expand_pseudo_instructions_and_assign_instruction_number_adds_syscall_at_proper_spot_with_data_after( ) { - let result = parser("addi $t1, $t2, 100\nsw $t1, label\n.data\n word: .word 100\n".to_string()) - .0 - .updated_monaco_string; + let result = parser( + "addi $t1, $t2, 100\nsw $t1, label\n.data\n word: .word 100\n".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .updated_monaco_string; let correct_result = "addi $t1, $t2, 100\nsw $t1, label\nsyscall\n.data\n word: .word 100\n".to_string(); @@ -67,9 +80,12 @@ fn expand_pseudo_instructions_and_assign_instruction_number_adds_syscall_at_prop #[test] fn add_syscall_to_program_info() { - let result = parser(".text\naddi $t1, $t2, $t3\nsyscall\n.data\n".to_string()) - .0 - .instructions; + let result = parser( + ".text\naddi $t1, $t2, $t3\nsyscall\n.data\n".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .instructions; for instr in result { println!("{}", instr.operator.token_name); @@ -1961,7 +1977,7 @@ fn complete_lw_sw_pseudo_instructions_doesnt_break_with_empty_instruction_list() fn expanded_pseudo_instructions_are_added_into_updated_monaco_string() { let result = parser( ".text\nli $t1, 100\nseq $t1, $t2, $t3\nsne $t1, $t2, $t3\nsle $t1, $t2, $t3\nsleu $t1, $t2, $t3\nsgt $t1, $t2, $t3\nsgtu $t1, $t2, $t3\nsge $t1, $t2, $t3\nsgeu $t1, $t2, $t3\nsubi $t1, $t2, 100\ndsubi $t1, $t2, 100\ndsubiu $t1, $t2, 100\nmuli $t1, $t2, 100\ndmuli $t1, $t2, 100\ndmuliu $t1, $t2, 100\ndivi $t1, 100\nddivi $t1, 100\nddiviu $t1, 100\nlw $t1, memory\n.data\nmemory: .word 200" - .to_string(), + .to_string(), AvailableDatapaths::MIPS ) .0.updated_monaco_string; @@ -1970,9 +1986,12 @@ fn expanded_pseudo_instructions_are_added_into_updated_monaco_string() { #[test] fn pseudo_instructions_with_labels_put_label_on_the_first_expanded_instruction() { - let result = parser("label: ddiviu $t2, $t2, 100\n".to_string()) - .0 - .instructions; + let result = parser( + "label: ddiviu $t2, $t2, 100\n".to_string(), + AvailableDatapaths::MIPS, + ) + .0 + .instructions; assert!(!result[0].labels.is_empty()); assert!(result[1].labels.is_empty()); } diff --git a/static/assembly_examples/riscv_test.asm b/static/assembly_examples/riscv_test.asm index 66836342f..ef828b552 100644 --- a/static/assembly_examples/riscv_test.asm +++ b/static/assembly_examples/riscv_test.asm @@ -1,3 +1,4 @@ main: - jal x1, 2047 + jal x1, 2044 + fmv.s f1, f2 ret \ No newline at end of file