forked from libre-chip/fayalite
make ToReset generic over the reset type
This commit is contained in:
parent
d744d85c66
commit
d36cf92d7f
|
@ -19,7 +19,10 @@ use crate::{
|
||||||
UIntType, UIntValue,
|
UIntType, UIntValue,
|
||||||
},
|
},
|
||||||
intern::{Intern, Interned},
|
intern::{Intern, Interned},
|
||||||
reset::{AsyncReset, Reset, SyncReset, ToAsyncReset, ToReset, ToSyncReset},
|
reset::{
|
||||||
|
AsyncReset, Reset, ResetType, ResetTypeDispatch, SyncReset, ToAsyncReset, ToReset,
|
||||||
|
ToSyncReset,
|
||||||
|
},
|
||||||
ty::{CanonicalType, StaticType, Type},
|
ty::{CanonicalType, StaticType, Type},
|
||||||
util::ConstUsize,
|
util::ConstUsize,
|
||||||
};
|
};
|
||||||
|
@ -1773,11 +1776,11 @@ impl_cast_bit_op!(CastSIntToAsyncReset, SInt<1>, #[dyn] SInt, AsyncReset, #[trai
|
||||||
impl_cast_bit_op!(CastSyncResetToBool, SyncReset, Bool);
|
impl_cast_bit_op!(CastSyncResetToBool, SyncReset, Bool);
|
||||||
impl_cast_bit_op!(CastSyncResetToUInt, SyncReset, UInt<1>, #[dyn] UInt);
|
impl_cast_bit_op!(CastSyncResetToUInt, SyncReset, UInt<1>, #[dyn] UInt);
|
||||||
impl_cast_bit_op!(CastSyncResetToSInt, SyncReset, SInt<1>, #[dyn] SInt);
|
impl_cast_bit_op!(CastSyncResetToSInt, SyncReset, SInt<1>, #[dyn] SInt);
|
||||||
impl_cast_bit_op!(CastSyncResetToReset, SyncReset, Reset, #[trait] ToReset::to_reset);
|
impl_cast_bit_op!(CastSyncResetToReset, SyncReset, Reset);
|
||||||
impl_cast_bit_op!(CastAsyncResetToBool, AsyncReset, Bool);
|
impl_cast_bit_op!(CastAsyncResetToBool, AsyncReset, Bool);
|
||||||
impl_cast_bit_op!(CastAsyncResetToUInt, AsyncReset, UInt<1>, #[dyn] UInt);
|
impl_cast_bit_op!(CastAsyncResetToUInt, AsyncReset, UInt<1>, #[dyn] UInt);
|
||||||
impl_cast_bit_op!(CastAsyncResetToSInt, AsyncReset, SInt<1>, #[dyn] SInt);
|
impl_cast_bit_op!(CastAsyncResetToSInt, AsyncReset, SInt<1>, #[dyn] SInt);
|
||||||
impl_cast_bit_op!(CastAsyncResetToReset, AsyncReset, Reset, #[trait] ToReset::to_reset);
|
impl_cast_bit_op!(CastAsyncResetToReset, AsyncReset, Reset);
|
||||||
impl_cast_bit_op!(CastResetToBool, Reset, Bool);
|
impl_cast_bit_op!(CastResetToBool, Reset, Bool);
|
||||||
impl_cast_bit_op!(CastResetToUInt, Reset, UInt<1>, #[dyn] UInt);
|
impl_cast_bit_op!(CastResetToUInt, Reset, UInt<1>, #[dyn] UInt);
|
||||||
impl_cast_bit_op!(CastResetToSInt, Reset, SInt<1>, #[dyn] SInt);
|
impl_cast_bit_op!(CastResetToSInt, Reset, SInt<1>, #[dyn] SInt);
|
||||||
|
@ -1788,6 +1791,29 @@ impl_cast_bit_op!(CastClockToBool, Clock, Bool);
|
||||||
impl_cast_bit_op!(CastClockToUInt, Clock, UInt<1>, #[dyn] UInt);
|
impl_cast_bit_op!(CastClockToUInt, Clock, UInt<1>, #[dyn] UInt);
|
||||||
impl_cast_bit_op!(CastClockToSInt, Clock, SInt<1>, #[dyn] SInt);
|
impl_cast_bit_op!(CastClockToSInt, Clock, SInt<1>, #[dyn] SInt);
|
||||||
|
|
||||||
|
impl<T: ResetType> ToReset for Expr<T> {
|
||||||
|
fn to_reset(&self) -> Expr<Reset> {
|
||||||
|
struct Dispatch;
|
||||||
|
impl ResetTypeDispatch for Dispatch {
|
||||||
|
type Input<T: ResetType> = Expr<T>;
|
||||||
|
type Output<T: ResetType> = Expr<Reset>;
|
||||||
|
|
||||||
|
fn reset(self, input: Self::Input<Reset>) -> Self::Output<Reset> {
|
||||||
|
input
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sync_reset(self, input: Self::Input<SyncReset>) -> Self::Output<SyncReset> {
|
||||||
|
input.cast_to_static()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn async_reset(self, input: Self::Input<AsyncReset>) -> Self::Output<AsyncReset> {
|
||||||
|
input.cast_to_static()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
T::dispatch(*self, Dispatch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ExprCastTo<AsyncReset> for AsyncReset {
|
impl ExprCastTo<AsyncReset> for AsyncReset {
|
||||||
fn cast_to(src: Expr<Self>, _to_type: AsyncReset) -> Expr<AsyncReset> {
|
fn cast_to(src: Expr<Self>, _to_type: AsyncReset) -> Expr<AsyncReset> {
|
||||||
src
|
src
|
||||||
|
|
|
@ -25,7 +25,7 @@ pub trait ResetTypeDispatch: Sized {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! reset_type {
|
macro_rules! reset_type {
|
||||||
($name:ident, $Trait:ident::$trait_fn:ident, $is_castable_from_bits:literal, $dispatch_fn:ident) => {
|
($name:ident, $(#[$impl_trait:ident])? $Trait:ident::$trait_fn:ident, $is_castable_from_bits:literal, $dispatch_fn:ident) => {
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default)]
|
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default)]
|
||||||
pub struct $name;
|
pub struct $name;
|
||||||
|
|
||||||
|
@ -109,16 +109,16 @@ macro_rules! reset_type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl $Trait for Expr<$name> {
|
$($impl_trait $Trait for Expr<$name> {
|
||||||
fn $trait_fn(&self) -> Expr<$name> {
|
fn $trait_fn(&self) -> Expr<$name> {
|
||||||
*self
|
*self
|
||||||
}
|
}
|
||||||
}
|
})?
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_type!(AsyncReset, ToAsyncReset::to_async_reset, true, async_reset);
|
reset_type!(AsyncReset, #[impl] ToAsyncReset::to_async_reset, true, async_reset);
|
||||||
reset_type!(SyncReset, ToSyncReset::to_sync_reset, true, sync_reset);
|
reset_type!(SyncReset, #[impl] ToSyncReset::to_sync_reset, true, sync_reset);
|
||||||
reset_type!(
|
reset_type!(
|
||||||
Reset,
|
Reset,
|
||||||
ToReset::to_reset,
|
ToReset::to_reset,
|
||||||
|
|
Loading…
Reference in a new issue