switch UnitTrait to using UnitIO instead of separate methods for each IO port

This commit is contained in:
Jacob Lifshay 2026-07-12 18:44:03 -07:00
parent fb0b07fbb2
commit bc2bcf4434
Signed by: programmerjake
SSH key fingerprint: SHA256:HnFTLGpSm4Q4Fj502oCFisjZSoakwEuTsJJMSke63RQ
3 changed files with 24 additions and 36 deletions

View file

@ -387,6 +387,12 @@ impl RenamedMOpFilter for () {
}
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct UnitIO {
pub cd: Option<Expr<ClockDomain>>,
pub from_execute: Expr<ExecuteToUnitInterface<PhantomConst<CpuConfig>>>,
}
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<Module<Self::Type>>;
fn cd(&self, this: Expr<Self::Type>) -> Option<Expr<ClockDomain>>;
fn from_execute(
&self,
this: Expr<Self::Type>,
) -> Expr<ExecuteToUnitInterface<PhantomConst<CpuConfig>>>;
fn io(&self, this: Expr<Self::Type>) -> UnitIO;
fn to_dyn(&self) -> DynUnit;
}
@ -434,15 +436,8 @@ impl UnitTrait for DynUnit {
self.unit.module()
}
fn cd(&self, this: Expr<Self::Type>) -> Option<Expr<ClockDomain>> {
self.unit.cd(this)
}
fn from_execute(
&self,
this: Expr<Self::Type>,
) -> Expr<ExecuteToUnitInterface<PhantomConst<CpuConfig>>> {
self.unit.from_execute(this)
fn io(&self, this: Expr<Self::Type>) -> UnitIO {
self.unit.io(this)
}
fn to_dyn(&self) -> DynUnit {
@ -468,15 +463,8 @@ impl<T: UnitTrait + Clone + std::hash::Hash + Eq> UnitTrait for DynUnitWrapper<T
self.0.module().canonical().intern_sized()
}
fn cd(&self, this: Expr<Self::Type>) -> Option<Expr<ClockDomain>> {
self.0.cd(Expr::from_bundle(this))
}
fn from_execute(
&self,
this: Expr<Self::Type>,
) -> Expr<ExecuteToUnitInterface<PhantomConst<CpuConfig>>> {
self.0.from_execute(Expr::from_bundle(this))
fn io(&self, this: Expr<Self::Type>) -> UnitIO {
self.0.io(Expr::from_bundle(this))
}
fn to_dyn(&self) -> DynUnit {

View file

@ -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<Self::Type>) -> Option<Expr<ClockDomain>> {
None
}
fn from_execute(
&self,
this: Expr<Self::Type>,
) -> Expr<ExecuteToUnitInterface<PhantomConst<CpuConfig>>> {
this.from_execute
fn io(&self, this: Expr<Self::Type>) -> UnitIO {
UnitIO {
cd: None,
from_execute: this.from_execute,
}
}
fn to_dyn(&self) -> DynUnit {

View file

@ -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);
}
}