Skip to content

Commit

Permalink
fix conditional compile
Browse files Browse the repository at this point in the history
  • Loading branch information
Spooky-Firefox committed Sep 26, 2024
1 parent 121199e commit 90192d9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
8 changes: 8 additions & 0 deletions mips-lib/src/components/mips_dm.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "gui-egui")]
use crate::gui_egui::mips_mem_view_window::MemViewWindow;
use core::cell::RefCell;
use std::cell::RefMut;
Expand Down Expand Up @@ -42,6 +43,7 @@ pub struct DataMem {
pub write_enable_input: Input,
pub phys_mem_id: String,
pub regfile_id: String,
#[cfg(feature = "gui-egui")]
pub mem_view: RefCell<MemViewWindow>,
}

Expand All @@ -56,6 +58,7 @@ impl DataMem {
phys_mem_id: String,
regfile_id: String,
) -> Self {
#[cfg(feature = "gui-egui")]
let mem_view =
MemViewWindow::new(id.clone(), "Data memory view".into()).set_data_view(None);
DataMem {
Expand All @@ -66,6 +69,7 @@ impl DataMem {
data_input: data_input,
op_input: op_input,
write_enable_input: write_enable_input,
#[cfg(feature = "gui-egui")]
mem_view: RefCell::new(mem_view),
regfile_id: regfile_id,
}
Expand Down Expand Up @@ -215,6 +219,7 @@ impl Component for DataMem {
.unwrap();

// update dynamic symbol PC_IM
#[cfg(feature = "gui-egui")]
self.mem_view
.borrow_mut()
.set_dynamic_symbol("DM_ADRS", address);
Expand Down Expand Up @@ -362,6 +367,7 @@ impl Component for DataMem {
Ok(_) => match mem_op {
data_op::NO_OP => Ok(()),
_ => {
#[cfg(feature = "gui-egui")]
if self.mem_view.borrow().is_break_point(&(address & !0b11)) {
Err(Condition::Halt(format!(
"Read or write at breakpoint address {:#0x}",
Expand All @@ -370,6 +376,8 @@ impl Component for DataMem {
} else {
Ok(())
}
#[cfg(not(feature = "gui-egui"))]
Ok(())
}
},
Err(_) => ret,
Expand Down
9 changes: 9 additions & 0 deletions mips-lib/src/components/mips_im.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use syncrim::common::{Component, Condition, Id, Input, InputPort, OutputType, Po

use crate::components::physical_mem::{MemOpSize, MipsMem};
use crate::components::RegFile;
#[cfg(feature = "gui-egui")]
use crate::gui_egui::mips_mem_view_window::MemViewWindow;

use super::PhysicalMem;
Expand All @@ -24,6 +25,7 @@ pub struct InstrMem {
// All components who deal with memory acess this
pub phys_mem_id: String,
pub regfile_id: String,
#[cfg(feature = "gui-egui")]
pub mem_view: RefCell<MemViewWindow>,
}

Expand All @@ -35,13 +37,15 @@ impl InstrMem {
phys_mem_id: String,
regfile_id: String,
) -> InstrMem {
#[cfg(feature = "gui-egui")]
let mem_view =
MemViewWindow::new(id.clone(), "instruction memory view".into()).set_code_view(None);
InstrMem {
id: id,
pos: pos,
pc: pc_input,
phys_mem_id: phys_mem_id,
#[cfg(feature = "gui-egui")]
mem_view: RefCell::new(mem_view),
regfile_id: regfile_id,
}
Expand Down Expand Up @@ -74,6 +78,7 @@ impl Component for InstrMem {
pos: pos,
pc: dummy_input,
phys_mem_id: "dummy".into(),
#[cfg(feature = "gui-egui")]
mem_view: RefCell::new(MemViewWindow::new("dummy".into(), "IM dummy".into())),
regfile_id: "dummy".into(),
}))
Expand Down Expand Up @@ -123,6 +128,7 @@ impl Component for InstrMem {
};

// update dynamic symbol PC_IM
#[cfg(feature = "gui-egui")]
self.mem_view.borrow_mut().set_dynamic_symbol("PC_IM", pc);

// Get a word at PC with the size of 32bits, read as big endian,
Expand All @@ -131,10 +137,13 @@ impl Component for InstrMem {
Ok(instr) => {
simulator.set_out_value(&self.id, INSTR_MEM_INSTRUCTION_ID, instr);
// check if pc is at breakpoint
#[cfg(feature = "gui-egui")]
match self.mem_view.borrow().is_break_point(&pc) {
true => Err(Condition::Halt(format!("Reached breakpoint at {:#0x}", pc))),
false => Ok(()),
}
#[cfg(not(feature = "gui-egui"))]
Ok(())
}
Err(_) => Err(Condition::Error(format!("Unaligned Read, PC = {:#0x}", pc))),
}
Expand Down
14 changes: 1 addition & 13 deletions mips-lib/src/components/mips_reg_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,7 @@ impl Component for RegFile {
fn to_(&self) {
trace!("reg_file");
}
#[cfg(feature = "gui-egui")]
// fn dummy(&self, id: &str, pos: (f32, f32)) -> Box<Rc<dyn EguiComponent>> {
// let dummy_input = Input::new("dummy", "out");
// Box::new(Rc::new(RegFile {
// id: "dummy".to_string(),
// pos: (0.0, 0.0),
// a1_in: dummy_input.clone(),
// a2_in: dummy_input.clone(),
// a3_in: dummy_input.clone(),
// wd3_in: dummy_input.clone(),
// we3_in: dummy_input.clone(),
// }))
// }

fn get_id_ports(&self) -> (Id, Ports) {
(
self.id.clone(),
Expand Down
10 changes: 1 addition & 9 deletions mips-lib/src/components/sz_extend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,7 @@ impl Component for SignZeroExtend {
fn to_(&self) {
trace!("pc+4");
}
#[cfg(feature = "gui-egui")]
// fn dummy(&self, _id: &str, _pos: (f32, f32)) -> Box<Rc<dyn EguiComponent>> {
// let dummy_input = Input::new("dummy", "out");
// Box::new(Rc::new(SignZeroExtend {
// id: "dummy".to_string(),
// pos: (0.0, 0.0),
// signzero_extend_in: dummy_input.clone(),
// }))
// }

fn get_id_ports(&self) -> (Id, Ports) {
(
self.id.clone(),
Expand Down
1 change: 1 addition & 0 deletions mips-lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod components;

#[cfg(feature = "gui-egui")]
pub mod gui_egui;

pub mod helpers;

0 comments on commit 90192d9

Please sign in to comment.