Skip to content

Commit

Permalink
Merge pull request #355 from SWIM-ucf/risc-v-parser
Browse files Browse the repository at this point in the history
Pseudo-Instructions, test cases, and bug fixes
  • Loading branch information
brooksmckinley authored Mar 13, 2024
2 parents d002a5e + f6d8ee7 commit 2242acf
Show file tree
Hide file tree
Showing 26 changed files with 3,101 additions and 1,861 deletions.
7 changes: 4 additions & 3 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 0 additions & 9 deletions src/parser/assembling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand All @@ -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() {
Expand All @@ -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

Expand Down Expand Up @@ -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<Error> = Vec::new();
Expand Down
Loading

0 comments on commit 2242acf

Please sign in to comment.