diff --git a/crates/cpu/src/unit.rs b/crates/cpu/src/unit.rs index ce024a4..d7442a3 100644 --- a/crates/cpu/src/unit.rs +++ b/crates/cpu/src/unit.rs @@ -387,6 +387,12 @@ impl RenamedMOpFilter for () { } } +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct UnitIO { + pub cd: Option>, + pub from_execute: Expr>>, +} + pub trait UnitTrait: 'static + Send + Sync + std::fmt::Debug + fayalite::intern::SupportsPtrEqWithTypeId { @@ -395,11 +401,7 @@ pub trait UnitTrait: fn ty(&self) -> Self::Type; fn unit_kind(&self) -> UnitKind; fn module(&self) -> Interned>; - fn cd(&self, this: Expr) -> Option>; - fn from_execute( - &self, - this: Expr, - ) -> Expr>>; + fn io(&self, this: Expr) -> UnitIO; fn to_dyn(&self) -> DynUnit; } @@ -434,15 +436,8 @@ impl UnitTrait for DynUnit { self.unit.module() } - fn cd(&self, this: Expr) -> Option> { - self.unit.cd(this) - } - - fn from_execute( - &self, - this: Expr, - ) -> Expr>> { - self.unit.from_execute(this) + fn io(&self, this: Expr) -> UnitIO { + self.unit.io(this) } fn to_dyn(&self) -> DynUnit { @@ -468,15 +463,8 @@ impl UnitTrait for DynUnitWrapper) -> Option> { - self.0.cd(Expr::from_bundle(this)) - } - - fn from_execute( - &self, - this: Expr, - ) -> Expr>> { - self.0.from_execute(Expr::from_bundle(this)) + fn io(&self, this: Expr) -> UnitIO { + self.0.io(Expr::from_bundle(this)) } fn to_dyn(&self) -> DynUnit { diff --git a/crates/cpu/src/unit/alu_branch.rs b/crates/cpu/src/unit/alu_branch.rs index 9ad3f4b..52bd4ab 100644 --- a/crates/cpu/src/unit/alu_branch.rs +++ b/crates/cpu/src/unit/alu_branch.rs @@ -18,7 +18,7 @@ use crate::{ ExecuteToUnitInterface, GlobalState, NextPcPredictorOp, RenamedMOp, UnitCausedCancel, UnitFinishCauseCancel, UnitInputsReady, UnitOutputReady, }, - unit::{DynUnit, DynUnitWrapper, RenamedMOpFilter, UnitKind, UnitTrait}, + unit::{DynUnit, DynUnitWrapper, RenamedMOpFilter, UnitIO, UnitKind, UnitTrait}, }; use fayalite::{ expr::CastToImpl, @@ -1613,15 +1613,11 @@ impl UnitTrait for AluBranch { self.module } - fn cd(&self, _this: Expr) -> Option> { - None - } - - fn from_execute( - &self, - this: Expr, - ) -> Expr>> { - this.from_execute + fn io(&self, this: Expr) -> UnitIO { + UnitIO { + cd: None, + from_execute: this.from_execute, + } } fn to_dyn(&self) -> DynUnit { diff --git a/crates/cpu/tests/units_formal.rs b/crates/cpu/tests/units_formal.rs index 47ad415..fa3397d 100644 --- a/crates/cpu/tests/units_formal.rs +++ b/crates/cpu/tests/units_formal.rs @@ -14,7 +14,7 @@ use cpu::{ DecodeAndRunSingleInsnInput, DecodeAndRunSingleInsnOutput, DecodeOneInsnInput, DecodeOneInsnMaxMOpCount, decode_and_run_single_insn, }, - unit::{RenamedMOpFilter, UnitKind, UnitMOp, UnitTrait}, + unit::{RenamedMOpFilter, UnitIO, UnitKind, UnitMOp, UnitTrait}, util::array_vec::ArrayVec, }; use fayalite::{ @@ -91,11 +91,15 @@ fn formal_harness( dyn_unit.module(), SourceLocation::caller(), ); + let UnitIO { + cd: unit_cd, + from_execute: unit_from_execute, + } = dyn_unit.io(unit); connect( - dyn_unit.from_execute(unit), + unit_from_execute, ExecuteToUnitInterfaces::unit_fields(decode_and_run.to_units)[unit_index], ); - if let Some(unit_cd) = dyn_unit.cd(unit) { + if let Some(unit_cd) = unit_cd { connect(unit_cd, cd); } }