8000 Console and regview branch by huynguyen2019 · Pull Request #104 · SWIM-ucf/SWIM · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Console and regview branch #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/emulation_core/mips/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl ToString for Memory {
let mut output = String::new();

for byte in self.memory.iter() {
output.push_str(&format!("{:x}", byte));
output.push_str(&format!("{byte:x}"));
}

output
Expand All @@ -33,7 +33,7 @@ impl Memory {
/// the address.
fn check_valid_address(&self, address: usize) -> Result<(), String> {
if address % 4 != 0 {
Err(format!("Address `{}` is not word-aligned", address))
Err(format!("Address `{address}` is not word-aligned"))
} else if address > self.memory.len() {
Err(format!(
"Address `{}` out of bounds of memory of size {}",
Expand Down
6 changes: 3 additions & 3 deletions src/emulation_core/mips/registers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl ToString for GpRegisters {
.gpr
.iter()
.enumerate()
.map(|(i, inst)| format!("gpr[{}] = {}", i, inst))
.map(|(i, inst)| format!("gpr[{i}] = {inst}"))
.collect::<Vec<String>>()
.join("\n");
output.push_str(&gpr_registers);
Expand All @@ -79,7 +79,7 @@ impl Index<&str> for GpRegisters {
fn index(&self, index: &str) -> &Self::Output {
match GpRegisterType::from_str(index) {
Ok(register) => &self[register],
_ => panic!("{} is not a valid register", index),
_ => panic!("{index} is not a valid register"),
}
}
}
Expand All @@ -90,7 +90,7 @@ impl IndexMut<&str> for GpRegisters {
fn index_mut(&mut self, index: &str) -> &mut Self::Output {
match GpRegisterType::from_str(index) {
Ok(register) => &mut self[register],
_ => panic!("{} is not a valid register", index),
_ => panic!("{index} is not a valid register"),
}
}
}
Expand Down
39 changes: 39 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod emulation_core;
pub mod parser;
#[cfg(test)]
pub mod tests;
pub mod ui;

use emulation_core::datapath::Datapath;
use emulation_core::mips::datapath::MipsDatapath;
Expand All @@ -14,8 +15,17 @@ use monaco::{
use parser::parser_main::parser;
use std::{cell::RefCell, rc::Rc};
use stylist::css;
//use stylist::yew::*;
use ui::console::component::Console;
use ui::regview::component::Regview;
use wasm_bindgen::JsValue;
use yew::prelude::*;
use yew::{html, Html, Properties};

#[derive(Properties, PartialEq)]
pub struct Consoleprops {
pub parsermsg: String,
}

#[function_component(App)]
fn app() -> Html {
Expand All @@ -30,6 +40,8 @@ fn app() -> Html {
let text_model =
use_state_eq(|| TextModel::create(&default_code, Some(&language), None).unwrap());

let parser_text_output = use_state_eq(String::new);

// TODO: Output will be stored in two ways, the first would be the parser's
// messages via logs and the registers will be stored
// in a custom-built register viewer.
Expand Down Expand Up @@ -81,12 +93,39 @@ fn app() -> Html {
)
};

let on_reset_clicked = {
let datapath = Rc::clone(&datapath);
use_callback(
move |_, _| {
let mut datapath = (*datapath).borrow_mut();
(*datapath).reset();
log!(JsValue::from_str(&datapath.registers.to_string()));
},
(),
)
};

let on_error_clicked = {
let parser_text_output = parser_text_output.clone();
use_callback(
move |_, _| {
parser_text_output.set("Arial".to_string());
},
(),
)
};

html! {
<div>
<h1>{"Welcome to SWIM"}</h1>
<button "Assemble" }</button>
<button { "Execute" }</button>
<button "Reset" }</button>
// Pass in register data from emu core
<Regview gp={(*datapath).borrow().registers}/>
<SwimEditor text_model={(*text_model).clone()} />
<button "Click" }</button>
<Console parsermsg={(*parser_text_output).clone()}/>
</div>
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/parser/parser_structs_and_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub mod instruction_tokenization {
println!("Int representation: {}", instruction.binary);

for error in &instruction.errors {
print!("{:?}", error);
print!("{error:?}");
if error.operand_number.is_some() {
println!(" on operand {}.", error.operand_number.unwrap());
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/ui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//! User interface using Yew, organized into components.

pub mod console;
pub mod regview;
19 changes: 19 additions & 0 deletions src/ui/console/component.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use yew::prelude::*;

#[derive(Properties, PartialEq)]
pub struct Consoleprops {
pub parsermsg: String,
}

#[function_component(Console)]
pub fn console(props: &Consoleprops) -> Html {
html! {
<>
// <div style="width: 80.4%; height: 17vh; border: 1px solid black;"></div>
<div style="width: 80.4%; height: 17vh; border: 2px solid black; background-color: #b9cceb; color: #000000;">
<p>{ props.parsermsg.clone() }</p>
//<p>{ ">" }</p>
</div>
</>
}
}
1 change: 1 addition & 0 deletions src/ui/console/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod component;
42 changes: 42 additions & 0 deletions src/ui/regview/component.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use yew::prelude::*;

use crate::emulation_core::mips::registers::GpRegisters;

#[derive(Properties, PartialEq)]
pub struct Regviewprops {
pub gp: GpRegisters,
}

//Convert register to html through iterator
pub fn gen_reg_html(gp: GpRegisters) -> Html {
gp.into_iter()
.map(|(register, data)| {
html! {
<tr style="border: 1px solid black;">
<td style="border: 1px solid black;">
{register}
</td>
<td style="border: 1px solid black;">
{data.to_string()}
</td>
</tr>
}
})
.collect::<Html>()
}
#[function_component(Regview)]
pub fn regview(props: &Regviewprops) -> Html {
html! {
<>
<div>
<table style="width: 19.2%; height: 97vh; border: 1px solid black; background-color: white; float: right;" content="width=device-width; initial-scale=1.0">
<tr style="border: 1px solid black;">
<th style="border: 1px solid black;">{"Register Name"}</th>
<th style="border: 1px solid black;">{"Data"}</th>
</tr>
{gen_reg_html(props.gp)}
</table>
</div>
</>
}
}
Empty file added src/ui/regview/labelcont.rs
Empty file.
1 change: 1 addition & 0 deletions src/ui/regview/mod.rs
93BD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod component;
Empty file added src/ui/regview/tabs.rs
Empty file.
Empty file added src/ui/regview/value.rs
Empty file.
0