This commit is contained in:
Jacob Lifshay 2024-07-10 23:00:05 -07:00
parent 25aa90ec60
commit 28f32d7d1a
Signed by: programmerjake
SSH key fingerprint: SHA256:B1iRVvUJkvd7upMIiMqn6OyxvD2SgJkAH3ZnUOj6z+c
7 changed files with 426 additions and 145 deletions

View file

@ -4,7 +4,7 @@ use crate::{
array::ArrayType,
bundle::{BundleType, BundleValue, DynBundle, DynBundleType, FieldType},
enum_::{DynEnumType, EnumType, EnumValue},
int::{DynSIntType, DynUIntType, FixedOrDynIntType, IntValue, UInt, UIntType},
int::{DynSIntType, DynUInt, DynUIntType, FixedOrDynIntType, IntValue, UInt, UIntType},
intern::{Intern, Interned, InternedCompare, PtrEqWithTypeId, SupportsPtrEqWithTypeId},
memory::{DynPortType, MemPort, PortType},
module::{
@ -288,7 +288,12 @@ impl<T> Hash for Expr<T> {
impl<T> Expr<IntValue<T>>
where
T: FixedOrDynIntType<1, Signed = ConstBool<false>>,
T: FixedOrDynIntType<
1,
Signed = ConstBool<false>,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>,
{
pub fn as_bool(self) -> Expr<UInt<1>> {
assert_eq!(self.canonical_type().width, 1);

View file

@ -10,8 +10,8 @@ use crate::{
TargetPathDynArrayElement, TargetPathElement, ToExpr,
},
int::{
DynIntType, DynSInt, DynSIntType, DynUInt, DynUIntType, FixedOrDynIntType, Int, IntCmp,
IntTypeTrait, IntValue, UInt, UIntType,
DynInt, DynIntType, DynSInt, DynSIntType, DynUInt, DynUIntType, FixedOrDynIntType, Int,
IntCmp, IntTypeTrait, IntValue, UInt, UIntType,
},
intern::{Intern, Interned},
reset::{
@ -242,7 +242,7 @@ unary_op! {
#[method = not]
impl<T> Not for _
where (
T: IntTypeTrait,
T: IntTypeTrait<CanonicalType = DynIntType<<T as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<T as IntTypeTrait>::Signed>>,
)
{
fn expr_enum(&self) -> _ {
@ -262,7 +262,7 @@ unary_op! {
#[method = neg]
impl<T> Neg for _
where (
T: IntTypeTrait<Signed = ConstBool<true>>,
T: IntTypeTrait<Signed = ConstBool<true>, CanonicalType = DynSIntType, CanonicalValue = DynSInt>,
)
{
fn expr_enum(&self) -> _ {
@ -361,48 +361,48 @@ binary_op! {
#[method = bitand, rhs_to_canonical_dyn = to_canonical_dyn, expr_enum_u = BitAndU, expr_enum_s = BitAndS]
impl<L, R> BitAnd for _
where
L: IntTypeTrait,
R: IntTypeTrait<Signed = L::Signed>,
L: IntTypeTrait<CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>>,
R: IntTypeTrait<Signed = L::Signed, CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>>,
}
binary_op! {
#[method = bitor, rhs_to_canonical_dyn = to_canonical_dyn, expr_enum_u = BitOrU, expr_enum_s = BitOrS]
impl<L, R> BitOr for _
where
L: IntTypeTrait,
R: IntTypeTrait<Signed = L::Signed>,
L: IntTypeTrait<CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>>,
R: IntTypeTrait<Signed = L::Signed, CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>>,
}
binary_op! {
#[method = bitxor, rhs_to_canonical_dyn = to_canonical_dyn, expr_enum_u = BitXorU, expr_enum_s = BitXorS]
impl<L, R> BitXor for _
where
L: IntTypeTrait,
R: IntTypeTrait<Signed = L::Signed>,
L: IntTypeTrait<CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>>,
R: IntTypeTrait<Signed = L::Signed, CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>>,
}
binary_op! {
#[method = add, rhs_to_canonical_dyn = to_canonical_dyn, expr_enum_u = AddU, expr_enum_s = AddS]
impl<L, R> Add for _
where
L: IntTypeTrait,
R: IntTypeTrait<Signed = L::Signed>,
L: IntTypeTrait<CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>>,
R: IntTypeTrait<Signed = L::Signed, CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>>,
}
binary_op! {
#[method = sub, rhs_to_canonical_dyn = to_canonical_dyn, expr_enum_u = SubU, expr_enum_s = SubS]
impl<L, R> Sub for _
where
L: IntTypeTrait,
R: IntTypeTrait<Signed = L::Signed>,
L: IntTypeTrait<CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>>,
R: IntTypeTrait<Signed = L::Signed, CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>>,
}
binary_op! {
#[method = mul, rhs_to_canonical_dyn = to_canonical_dyn, expr_enum_u = MulU, expr_enum_s = MulS]
impl<L, R> Mul for _
where
L: IntTypeTrait,
R: IntTypeTrait<Signed = L::Signed>,
L: IntTypeTrait<CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>>,
R: IntTypeTrait<Signed = L::Signed, CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>>,
}
macro_rules! dyn_shift_op {
@ -413,7 +413,7 @@ macro_rules! dyn_shift_op {
fixed_ary_op! {
pub struct $DynOp<LhsType,>
where (
LhsType: IntTypeTrait,
LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>,
)
{
pub lhs: Expr<LhsType::CanonicalValue>,
@ -458,8 +458,8 @@ macro_rules! dyn_shift_op {
impl<Lhs: Value<Type = LhsType>, LhsType, RhsType, Rhs: Value<Type = RhsType>> ops::$Op<Expr<Rhs>> for Expr<Lhs>
where
LhsType: IntTypeTrait,
RhsType: IntTypeTrait<Signed = ConstBool<false>>,
LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>,
RhsType: IntTypeTrait<Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>,
{
type Output = Expr<<<Valueless<LhsType> as ops::$Op<Valueless<RhsType>>>::Output as ValuelessTr>::Value>;
@ -470,8 +470,8 @@ macro_rules! dyn_shift_op {
impl<LhsType, RhsType, Rhs: Value<Type = RhsType>> ops::$Op<Expr<Rhs>> for IntValue<LhsType>
where
LhsType: IntTypeTrait,
RhsType: IntTypeTrait<Signed = ConstBool<false>>,
LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>,
RhsType: IntTypeTrait<Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>,
{
type Output = Expr<<<Valueless<LhsType> as ops::$Op<Valueless<RhsType>>>::Output as ValuelessTr>::Value>;
@ -490,7 +490,7 @@ macro_rules! fixed_shift_op {
fixed_ary_op! {
pub struct $FixedOp<LhsType,>
where (
LhsType: IntTypeTrait,
LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>,
)
{
pub lhs: Expr<LhsType::CanonicalValue>,
@ -532,7 +532,7 @@ macro_rules! fixed_shift_op {
impl<Lhs: Value<Type = LhsType>, LhsType> ops::$Op<usize> for Expr<Lhs>
where
LhsType: IntTypeTrait,
LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>,
{
type Output = Expr<<<Valueless<LhsType> as ops::$Op<usize>>::Output as ValuelessTr>::Value>;
@ -568,9 +568,9 @@ macro_rules! cmp_op {
$(fixed_ary_op! {
pub struct $CmpOp<LhsType, RhsType, Output,>
where (
LhsType: IntTypeTrait,
RhsType: IntTypeTrait<Signed = LhsType::Signed>,
Output: FixedOrDynIntType<1, Signed = ConstBool<false>>,
LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>,
RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>,
Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>,
)
{
pub lhs: Expr<LhsType::CanonicalValue>,
@ -612,7 +612,7 @@ macro_rules! cmp_op {
}
})*
impl<LhsType: IntTypeTrait, RhsType: IntTypeTrait<Signed = LhsType::Signed>, Rhs: Value<Type = RhsType>, Lhs: Value<Type = LhsType>> IntCmp<Expr<Rhs>> for Expr<Lhs> {
impl<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Rhs: Value<Type = RhsType>, Lhs: Value<Type = LhsType>> IntCmp<Expr<Rhs>> for Expr<Lhs> {
type Output = Expr<UInt<1>>;
$(fn $fn(self, rhs: Expr<Rhs>) -> Self::Output {
@ -620,7 +620,7 @@ macro_rules! cmp_op {
})*
}
impl<LhsType: IntTypeTrait, RhsType: IntTypeTrait<Signed = LhsType::Signed>, Rhs: Value<Type = RhsType>, Lhs: Value<Type = LhsType>> IntCmp<Rhs> for Expr<Lhs> {
impl<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Rhs: Value<Type = RhsType>, Lhs: Value<Type = LhsType>> IntCmp<Rhs> for Expr<Lhs> {
type Output = Expr<UInt<1>>;
$(fn $fn(self, rhs: Rhs) -> Self::Output {
@ -628,7 +628,7 @@ macro_rules! cmp_op {
})*
}
impl<LhsType: IntTypeTrait, RhsType: IntTypeTrait<Signed = LhsType::Signed>, Rhs: Value<Type = RhsType>> IntCmp<Expr<Rhs>> for IntValue<LhsType> {
impl<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Rhs: Value<Type = RhsType>> IntCmp<Expr<Rhs>> for IntValue<LhsType> {
type Output = Expr<UInt<1>>;
$(fn $fn(self, rhs: Expr<Rhs>) -> Self::Output {
@ -658,8 +658,8 @@ cmp_op! {
fixed_ary_op! {
pub struct CastInt<FromType, ToType,>
where (
FromType: IntTypeTrait,
ToType: IntTypeTrait,
FromType: IntTypeTrait<CanonicalType = DynIntType<<FromType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<FromType as IntTypeTrait>::Signed>>,
ToType: IntTypeTrait<CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>,
)
{
pub value: Expr<FromType::CanonicalValue>,
@ -705,9 +705,18 @@ fixed_ary_op! {
}
}
impl<FromType: IntTypeTrait> Expr<IntValue<FromType>> {
impl<
FromType: IntTypeTrait<
CanonicalType = DynIntType<<FromType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<FromType as IntTypeTrait>::Signed>,
>,
> Expr<IntValue<FromType>>
{
pub fn cast<
ToType: IntTypeTrait<CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>>,
ToType: IntTypeTrait<
CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>,
>,
>(
self,
ty: ToType,
@ -731,7 +740,7 @@ impl<FromType: IntTypeTrait> Expr<IntValue<FromType>> {
fixed_ary_op! {
pub struct Slice<Base,>
where (
Base: IntTypeTrait,
Base: IntTypeTrait<CanonicalType = DynIntType<<Base as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<Base as IntTypeTrait>::Signed>>,
)
{
pub base: Expr<Base::CanonicalValue>,
@ -765,7 +774,13 @@ fixed_ary_op! {
}
}
impl<T: IntTypeTrait> Expr<IntValue<T>> {
impl<
T: IntTypeTrait<
CanonicalType = DynIntType<<T as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<T as IntTypeTrait>::Signed>,
>,
> Expr<IntValue<T>>
{
pub fn slice<I: RangeBounds<usize>>(self, index: I) -> Expr<DynUInt> {
Slice::<T>::new_unchecked(
self.canonical(),
@ -841,7 +856,14 @@ impl_built_in_range!(<T> std::ops::RangeInclusive<T>);
impl_built_in_range!(<T> std::ops::RangeTo<T>);
impl_built_in_range!(<T> std::ops::RangeToInclusive<T>);
impl<T: IntTypeTrait, I: BuiltInRange<usize>> ExprIndex<I> for IntValue<T> {
impl<
T: IntTypeTrait<
CanonicalType = DynIntType<<T as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<T as IntTypeTrait>::Signed>,
>,
I: BuiltInRange<usize>,
> ExprIndex<I> for IntValue<T>
{
type OutputValue = DynUInt;
fn expr_index(this: Expr<Self>, index: I) -> Expr<Self::OutputValue> {
@ -849,7 +871,13 @@ impl<T: IntTypeTrait, I: BuiltInRange<usize>> ExprIndex<I> for IntValue<T> {
}
}
impl<T: IntTypeTrait> ExprIndex<usize> for IntValue<T> {
impl<
T: IntTypeTrait<
CanonicalType = DynIntType<<T as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<T as IntTypeTrait>::Signed>,
>,
> ExprIndex<usize> for IntValue<T>
{
type OutputValue = UInt<1>;
fn expr_index(this: Expr<Self>, index: usize) -> Expr<Self::OutputValue> {
@ -862,7 +890,7 @@ macro_rules! reduce_bit_op {
fixed_ary_op! {
pub struct $name<Output,>
where (
Output: FixedOrDynIntType<1, Signed = ConstBool<false>>,
Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>,
)
{
pub arg: Expr<DynUInt>,
@ -892,7 +920,14 @@ reduce_bit_op!(ReduceBitAnd; |bits| bits.all());
reduce_bit_op!(ReduceBitOr; |bits| bits.any());
reduce_bit_op!(ReduceBitXor; |bits| bits.count_ones() % 2 == 1);
impl<T: IntTypeTrait<Signed = ConstBool<false>>> Expr<IntValue<T>> {
impl<
T: IntTypeTrait<
Signed = ConstBool<false>,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>,
> Expr<IntValue<T>>
{
pub fn reduce_bitand(self) -> Expr<UInt<1>> {
ReduceBitAnd::<UIntType<1>>::new_unchecked(self.canonical()).to_expr()
}
@ -939,7 +974,9 @@ fixed_ary_op! {
},
#[target]
target: Option<Interned<Target>> = base.target().map(|base| {
Intern::intern_sized(base.join(TargetPathElement::intern_sized(TargetPathBundleField{name:field.name}.into())))
Intern::intern_sized(base.join(
TargetPathElement::intern_sized(TargetPathBundleField{ name: field.name }.into()),
))
}),
fn simulate(&self, sim_state: &mut SimState) -> _ {
todo!()
@ -985,9 +1022,9 @@ fixed_ary_op! {
#[cache]
base_ty: DynEnumType = base.canonical_type(),
#[type]
ty: VariantTy = VariantTy::from_dyn_canonical_type(base_ty.variants()[variant_index].ty.unwrap_or_else(
|| ().canonical_dyn(),
)),
ty: VariantTy = VariantTy::from_dyn_canonical_type(
base_ty.variants()[variant_index].ty.unwrap_or_else(|| ().canonical_dyn()),
),
#[cache]
literal_bits: Result<Interned<BitSlice>, ()> = {
base.to_literal_bits().map(|base| {
@ -1086,7 +1123,9 @@ fixed_ary_op! {
}
fn expr_enum(&self) -> _ {
ExprEnum::CastBitsTo(CastBitsTo::new_unchecked(self.value, self.ty.canonical_dyn()).intern_sized())
ExprEnum::CastBitsTo(
CastBitsTo::new_unchecked(self.value, self.ty.canonical_dyn()).intern_sized(),
)
}
fn to_literal_bits(&self) -> Result<Interned<BitSlice>, ()> {
@ -1105,7 +1144,14 @@ where
}
}
impl<T: IntTypeTrait<Signed = ConstBool<false>>> Expr<IntValue<T>> {
impl<
T: IntTypeTrait<
Signed = ConstBool<false>,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>,
> Expr<IntValue<T>>
{
pub fn cast_bits_to<U: Value>(self, ty: U::Type) -> Expr<U>
where
U::Type: Type<Value = U>,
@ -1115,11 +1161,11 @@ impl<T: IntTypeTrait<Signed = ConstBool<false>>> Expr<IntValue<T>> {
}
macro_rules! cast_bit_to_typed_bit {
(pub struct $Op:ident$(<$T:ident: $Bound:ident<$BoundArg:tt>>)?; $FromType:ty => $ToType:ty) => {
(pub struct $Op:ident$(<$T:ident: $Bound:path>)?; $FromType:ty => $ToType:ty) => {
fixed_ary_op! {
pub struct $Op<$($T,)?>
where (
$($T: $Bound<$BoundArg>,)?
$($T: $Bound,)?
)
{
pub value: Expr<<$FromType as Type>::Value>,
@ -1244,7 +1290,7 @@ where
}
}
cast_bit_to_typed_bit!(pub struct CastClockToBit<ToType: FixedOrDynIntType<1>>; ClockType => ToType);
cast_bit_to_typed_bit!(pub struct CastClockToBit<ToType: FixedOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>; ClockType => ToType);
impl ToBit for Clock {
fn to_bit(v: Expr<Self>) -> Expr<UInt<1>> {
@ -1252,7 +1298,7 @@ impl ToBit for Clock {
}
}
cast_bit_to_typed_bit!(pub struct CastSyncResetToBit<ToType: FixedOrDynIntType<1>>; SyncResetType => ToType);
cast_bit_to_typed_bit!(pub struct CastSyncResetToBit<ToType: FixedOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>; SyncResetType => ToType);
impl ToBit for SyncReset {
fn to_bit(v: Expr<Self>) -> Expr<UInt<1>> {
@ -1260,7 +1306,7 @@ impl ToBit for SyncReset {
}
}
cast_bit_to_typed_bit!(pub struct CastAsyncResetToBit<ToType: FixedOrDynIntType<1>>; AsyncResetType => ToType);
cast_bit_to_typed_bit!(pub struct CastAsyncResetToBit<ToType: FixedOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>; AsyncResetType => ToType);
impl ToBit for AsyncReset {
fn to_bit(v: Expr<Self>) -> Expr<UInt<1>> {
@ -1268,7 +1314,7 @@ impl ToBit for AsyncReset {
}
}
cast_bit_to_typed_bit!(pub struct CastResetToBit<ToType: FixedOrDynIntType<1>>; ResetType => ToType);
cast_bit_to_typed_bit!(pub struct CastResetToBit<ToType: FixedOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>; ResetType => ToType);
impl ToBit for Reset {
fn to_bit(v: Expr<Self>) -> Expr<UInt<1>> {
@ -1355,7 +1401,9 @@ fixed_ary_op! {
},
#[target]
target: Option<Interned<Target>> = base.target().map(|base| {
Intern::intern_sized(base.join(TargetPathElement::ArrayElement(TargetPathArrayElement { index }).intern()))
Intern::intern_sized(base.join(
TargetPathElement::ArrayElement(TargetPathArrayElement { index }).intern(),
))
}),
fn simulate(&self, sim_state: &mut SimState) -> _ {
todo!()
@ -1398,21 +1446,28 @@ fixed_ary_op! {
let base_ty = base.ty();
let element_bit_width = base_ty.element().bit_width();
base.to_literal_bits().ok().zip(index.to_literal_bits().ok()).and_then(|(base, index)| {
let start = DynUInt::from_bit_slice(&index).uint_value().to_usize()?.checked_mul(element_bit_width)?;
let start = DynUInt::from_bit_slice(&index)
.uint_value()
.to_usize()?
.checked_mul(element_bit_width)?;
let end = start.checked_add(element_bit_width)?;
Some(base.get(start..end)?.intern())
}).ok_or(())
},
#[target]
target: Option<Interned<Target>> = base.target().map(|base| {
Intern::intern_sized(base.join(TargetPathElement::DynArrayElement(TargetPathDynArrayElement {}).intern()))
Intern::intern_sized(base.join(
TargetPathElement::DynArrayElement(TargetPathDynArrayElement {}).intern(),
))
}),
fn simulate(&self, sim_state: &mut SimState) -> _ {
todo!()
}
fn expr_enum(&self) -> _ {
ExprEnum::DynArrayIndex(DynArrayIndex::new_unchecked(self.base, self.index).intern_sized())
ExprEnum::DynArrayIndex(
DynArrayIndex::new_unchecked(self.base, self.index).intern_sized(),
)
}
fn to_literal_bits(&self) -> Result<Interned<BitSlice>, ()> {
@ -1432,7 +1487,11 @@ impl<ElementType: Type> DynArrayIndex<ElementType> {
impl<
VA: ?Sized + ValueArrayOrSlice,
Idx: IntTypeTrait<Signed = ConstBool<false>, CanonicalType = DynUIntType>,
Idx: IntTypeTrait<
Signed = ConstBool<false>,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>,
> ExprIndex<IntValue<Idx>> for Array<VA>
{
type OutputValue = VA::Element;
@ -1445,7 +1504,11 @@ impl<
impl<
VA: ?Sized + ValueArrayOrSlice,
Idx: IntTypeTrait<Signed = ConstBool<false>, CanonicalType = DynUIntType>,
Idx: IntTypeTrait<
Signed = ConstBool<false>,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>,
> ExprIndex<Expr<IntValue<Idx>>> for Array<VA>
{
type OutputValue = VA::Element;
@ -1555,7 +1618,8 @@ fixed_ary_op! {
ty
},
#[cache]
literal_bits: Result<Interned<BitSlice>, ()> = ty.variant_to_bits(variant_index, variant_value.as_ref()),
literal_bits: Result<Interned<BitSlice>, ()> =
ty.variant_to_bits(variant_index, variant_value.as_ref()),
fn simulate(&self, sim_state: &mut SimState) -> _ {
todo!()
}

View file

@ -35,7 +35,13 @@ pub type Int<Signed, const WIDTH: usize> = IntValue<IntType<Signed, WIDTH>>;
pub type UInt<const WIDTH: usize> = Int<ConstBool<false>, WIDTH>;
pub type SInt<const WIDTH: usize> = Int<ConstBool<true>, WIDTH>;
impl<T: IntTypeTrait> ToExpr for IntValue<T> {
impl<
T: IntTypeTrait<
CanonicalType = DynIntType<<T as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<T as IntTypeTrait>::Signed>,
>,
> ToExpr for IntValue<T>
{
type Type = T;
fn ty(&self) -> Self::Type {
@ -47,13 +53,25 @@ impl<T: IntTypeTrait> ToExpr for IntValue<T> {
}
}
impl<T: IntTypeTrait> fmt::Display for IntValue<T> {
impl<
T: IntTypeTrait<
CanonicalType = DynIntType<<T as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<T as IntTypeTrait>::Signed>,
>,
> fmt::Display for IntValue<T>
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.to_canonical(), f)
}
}
impl<T: IntTypeTrait> fmt::Debug for IntValue<T> {
impl<
T: IntTypeTrait<
CanonicalType = DynIntType<<T as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<T as IntTypeTrait>::Signed>,
>,
> fmt::Debug for IntValue<T>
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let neg;
let (sign, magnitude) = if self.is_negative() {
@ -93,7 +111,13 @@ impl<Signed: GenericConstBool> DynInt<Signed> {
}
}
impl<T: IntTypeTrait> IntValue<T> {
impl<
T: IntTypeTrait<
CanonicalType = DynIntType<<T as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<T as IntTypeTrait>::Signed>,
>,
> IntValue<T>
{
pub fn with_type<I: Into<BigInt>>(ty: T, value: I) -> Self {
let int_type = ty.canonical();
let mut value: BigInt = value.into();
@ -172,14 +196,30 @@ impl<T: IntTypeTrait> IntValue<T> {
let width = self.ty.width();
T::Signed::VALUE && width > 0 && self.uint_value.bit((width - 1).try_into().unwrap())
}
pub fn into_cast<NewType: IntTypeTrait>(self, new_type: NewType) -> IntValue<NewType> {
pub fn into_cast<
NewType: IntTypeTrait<
CanonicalType = DynIntType<<NewType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<NewType as IntTypeTrait>::Signed>,
>,
>(
self,
new_type: NewType,
) -> IntValue<NewType> {
if new_type.width() > self.ty.width() && self.is_negative() {
IntValue::with_type(new_type, self.into_value())
} else {
IntValue::with_type(new_type, self.into_uint_value())
}
}
pub fn cast<NewType: IntTypeTrait>(&self, new_type: NewType) -> IntValue<NewType> {
pub fn cast<
NewType: IntTypeTrait<
CanonicalType = DynIntType<<NewType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<NewType as IntTypeTrait>::Signed>,
>,
>(
&self,
new_type: NewType,
) -> IntValue<NewType> {
if new_type.width() > self.ty.width() && self.is_negative() {
IntValue::with_type(new_type, self.value())
} else {
@ -221,7 +261,14 @@ impl<T: IntTypeTrait> IntValue<T> {
assert!(index < self.ty.width(), "bit index out of range");
self.uint_value.set_bit(index.try_into().unwrap(), value)
}
pub fn set_slice<I: RangeBounds<usize>, RhsType: IntTypeTrait<Signed = ConstBool<false>>>(
pub fn set_slice<
I: RangeBounds<usize>,
RhsType: IntTypeTrait<
Signed = ConstBool<false>,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>,
>(
&mut self,
index: I,
value: impl Into<IntValue<RhsType>>,
@ -240,7 +287,11 @@ impl<T: IntTypeTrait> IntValue<T> {
}
pub fn with_replaced_slice<
I: RangeBounds<usize>,
RhsType: IntTypeTrait<Signed = ConstBool<false>>,
RhsType: IntTypeTrait<
Signed = ConstBool<false>,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>,
>(
mut self,
index: I,
@ -249,7 +300,12 @@ impl<T: IntTypeTrait> IntValue<T> {
self.set_slice(index, value);
self
}
pub fn concat<HighType: IntTypeTrait>(
pub fn concat<
HighType: IntTypeTrait<
CanonicalType = DynIntType<<HighType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<HighType as IntTypeTrait>::Signed>,
>,
>(
&self,
high_part: IntValue<HighType>,
) -> IntValue<DynIntType<HighType::Signed>> {
@ -279,7 +335,13 @@ impl<T: IntTypeTrait> IntValue<T> {
}
}
impl<Ty: IntTypeTrait> Value for IntValue<Ty> {
impl<
Ty: IntTypeTrait<
CanonicalType = DynIntType<<Ty as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<Ty as IntTypeTrait>::Signed>,
>,
> Value for IntValue<Ty>
{
fn to_canonical(&self) -> <Self::Type as Type>::CanonicalValue {
IntValue {
ty: self.ty.canonical(),
@ -295,7 +357,13 @@ impl<Ty: IntTypeTrait> Value for IntValue<Ty> {
}
}
impl<T> Copy for ToBitsMemoize<T> {}
impl<Ty: IntTypeTrait> Memoize for ToBitsMemoize<IntValue<Ty>> {
impl<
Ty: IntTypeTrait<
CanonicalType = DynIntType<<Ty as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<Ty as IntTypeTrait>::Signed>,
>,
> Memoize for ToBitsMemoize<IntValue<Ty>>
{
type Input = IntValue<Ty>;
type InputOwned = IntValue<Ty>;
type Output = Interned<BitSlice>;
@ -321,8 +389,15 @@ macro_rules! impl_add_sub {
($Op:ident::$op:ident) => {
impl<LhsType, RhsType> $Op<IntValue<RhsType>> for IntValue<LhsType>
where
LhsType: IntTypeTrait,
RhsType: IntTypeTrait<Signed = <LhsType as IntTypeTrait>::Signed>,
LhsType: IntTypeTrait<
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
RhsType: IntTypeTrait<
Signed = <LhsType as IntTypeTrait>::Signed,
CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>,
>,
{
type Output = IntValue<DynIntType<LhsType::Signed>>;
@ -334,8 +409,15 @@ macro_rules! impl_add_sub {
impl<LhsType, RhsType> $Op<Valueless<RhsType>> for Valueless<LhsType>
where
LhsType: IntTypeTrait,
RhsType: IntTypeTrait<Signed = <LhsType as IntTypeTrait>::Signed>,
LhsType: IntTypeTrait<
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
RhsType: IntTypeTrait<
Signed = <LhsType as IntTypeTrait>::Signed,
CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>,
>,
{
type Output = Valueless<DynIntType<LhsType::Signed>>;
@ -357,8 +439,16 @@ macro_rules! impl_bitwise {
($Op:ident::$op:ident) => {
impl<
Signed: GenericConstBool,
LhsType: IntTypeTrait<Signed = Signed>,
RhsType: IntTypeTrait<Signed = Signed>,
LhsType: IntTypeTrait<
Signed = Signed,
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
RhsType: IntTypeTrait<
Signed = Signed,
CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>,
>,
> $Op<IntValue<RhsType>> for IntValue<LhsType>
{
type Output = IntValue<DynIntType<Signed>>;
@ -371,8 +461,16 @@ macro_rules! impl_bitwise {
impl<
Signed: GenericConstBool,
LhsType: IntTypeTrait<Signed = Signed>,
RhsType: IntTypeTrait<Signed = Signed>,
LhsType: IntTypeTrait<
Signed = Signed,
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
RhsType: IntTypeTrait<
Signed = Signed,
CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>,
>,
> $Op<Valueless<RhsType>> for Valueless<LhsType>
{
type Output = Valueless<DynIntType<Signed>>;
@ -390,8 +488,16 @@ impl_add_sub!(Sub::sub);
impl<
Signed: GenericConstBool,
LhsType: IntTypeTrait<Signed = Signed>,
RhsType: IntTypeTrait<Signed = Signed>,
LhsType: IntTypeTrait<
Signed = Signed,
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
RhsType: IntTypeTrait<
Signed = Signed,
CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>,
>,
> Mul<IntValue<RhsType>> for IntValue<LhsType>
{
type Output = IntValue<DynIntType<Signed>>;
@ -403,8 +509,16 @@ impl<
impl<
Signed: GenericConstBool,
LhsType: IntTypeTrait<Signed = Signed>,
RhsType: IntTypeTrait<Signed = Signed>,
LhsType: IntTypeTrait<
Signed = Signed,
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
RhsType: IntTypeTrait<
Signed = Signed,
CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>,
>,
> Mul<Valueless<RhsType>> for Valueless<LhsType>
{
type Output = Valueless<DynIntType<Signed>>;
@ -425,8 +539,16 @@ impl_bitwise!(BitXor::bitxor);
impl<
Signed: GenericConstBool,
LhsType: IntTypeTrait<Signed = Signed>,
RhsType: IntTypeTrait<Signed = ConstBool<false>>,
LhsType: IntTypeTrait<
Signed = Signed,
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
RhsType: IntTypeTrait<
Signed = ConstBool<false>,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>,
> Shl<IntValue<RhsType>> for IntValue<LhsType>
{
type Output = IntValue<DynIntType<Signed>>;
@ -447,8 +569,16 @@ impl<
impl<
Signed: GenericConstBool,
LhsType: IntTypeTrait<Signed = Signed>,
RhsType: IntTypeTrait<Signed = ConstBool<false>>,
LhsType: IntTypeTrait<
Signed = Signed,
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
RhsType: IntTypeTrait<
Signed = ConstBool<false>,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>,
> Shl<Valueless<RhsType>> for Valueless<LhsType>
{
type Output = Valueless<DynIntType<Signed>>;
@ -469,8 +599,16 @@ impl<
impl<
Signed: GenericConstBool,
LhsType: IntTypeTrait<Signed = Signed>,
RhsType: IntTypeTrait<Signed = ConstBool<false>>,
LhsType: IntTypeTrait<
Signed = Signed,
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
RhsType: IntTypeTrait<
Signed = ConstBool<false>,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>,
> Shr<IntValue<RhsType>> for IntValue<LhsType>
{
type Output = IntValue<DynIntType<Signed>>;
@ -488,8 +626,12 @@ impl<
impl<
Signed: GenericConstBool,
LhsType: IntTypeTrait<Signed = Signed>,
RhsType: IntTypeTrait<Signed = ConstBool<false>>,
LhsType: IntTypeTrait<Signed = Signed, CanonicalType = DynIntType<Signed>>,
RhsType: IntTypeTrait<
Signed = ConstBool<false>,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>,
> Shr<Valueless<RhsType>> for Valueless<LhsType>
{
type Output = Valueless<DynIntType<Signed>>;
@ -501,8 +643,14 @@ impl<
}
}
impl<Signed: GenericConstBool, LhsType: IntTypeTrait<Signed = Signed>> Shl<usize>
for IntValue<LhsType>
impl<
Signed: GenericConstBool,
LhsType: IntTypeTrait<
Signed = Signed,
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
> Shl<usize> for IntValue<LhsType>
{
type Output = IntValue<DynIntType<Signed>>;
@ -512,8 +660,14 @@ impl<Signed: GenericConstBool, LhsType: IntTypeTrait<Signed = Signed>> Shl<usize
}
}
impl<Signed: GenericConstBool, LhsType: IntTypeTrait<Signed = Signed>> Shl<usize>
for Valueless<LhsType>
impl<
Signed: GenericConstBool,
LhsType: IntTypeTrait<
Signed = Signed,
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
> Shl<usize> for Valueless<LhsType>
{
type Output = Valueless<DynIntType<Signed>>;
@ -528,8 +682,14 @@ impl<Signed: GenericConstBool, LhsType: IntTypeTrait<Signed = Signed>> Shl<usize
}
}
impl<Signed: GenericConstBool, LhsType: IntTypeTrait<Signed = Signed>> Shr<usize>
for IntValue<LhsType>
impl<
Signed: GenericConstBool,
LhsType: IntTypeTrait<
Signed = Signed,
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
> Shr<usize> for IntValue<LhsType>
{
type Output = IntValue<DynIntType<Signed>>;
@ -541,8 +701,14 @@ impl<Signed: GenericConstBool, LhsType: IntTypeTrait<Signed = Signed>> Shr<usize
}
}
impl<Signed: GenericConstBool, LhsType: IntTypeTrait<Signed = Signed>> Shr<usize>
for Valueless<LhsType>
impl<
Signed: GenericConstBool,
LhsType: IntTypeTrait<
Signed = Signed,
CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>,
>,
> Shr<usize> for Valueless<LhsType>
{
type Output = Valueless<DynIntType<Signed>>;
@ -552,7 +718,14 @@ impl<Signed: GenericConstBool, LhsType: IntTypeTrait<Signed = Signed>> Shr<usize
}
}
impl<T: IntTypeTrait<Signed = ConstBool<true>>> Neg for IntValue<T> {
impl<
T: IntTypeTrait<
Signed = ConstBool<true>,
CanonicalType = DynSIntType,
CanonicalValue = DynSInt,
>,
> Neg for IntValue<T>
{
type Output = IntValue<DynSIntType>;
fn neg(self) -> Self::Output {
let ty = self.valueless().neg().ty;
@ -560,7 +733,14 @@ impl<T: IntTypeTrait<Signed = ConstBool<true>>> Neg for IntValue<T> {
}
}
impl<T: IntTypeTrait<Signed = ConstBool<true>>> Neg for Valueless<T> {
impl<
T: IntTypeTrait<
Signed = ConstBool<true>,
CanonicalType = DynSIntType,
CanonicalValue = DynSInt,
>,
> Neg for Valueless<T>
{
type Output = Valueless<DynSIntType>;
fn neg(self) -> Self::Output {
let ty = DynIntType::new(
@ -573,14 +753,26 @@ impl<T: IntTypeTrait<Signed = ConstBool<true>>> Neg for Valueless<T> {
}
}
impl<T: IntTypeTrait> Not for IntValue<T> {
impl<
T: IntTypeTrait<
CanonicalType = DynIntType<<T as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<T as IntTypeTrait>::Signed>,
>,
> Not for IntValue<T>
{
type Output = IntValue<T>;
fn not(self) -> Self::Output {
IntValue::with_type(self.valueless().not().ty, Not::not(self.into_value()))
}
}
impl<T: IntTypeTrait> Not for Valueless<T> {
impl<
T: IntTypeTrait<
CanonicalType = DynIntType<<T as IntTypeTrait>::Signed>,
CanonicalValue = DynInt<<T as IntTypeTrait>::Signed>,
>,
> Not for Valueless<T>
{
type Output = Valueless<T>;
fn not(self) -> Self::Output {
self
@ -626,7 +818,15 @@ impl_int!(i32, true);
impl_int!(i64, true);
impl_int!(i128, true);
impl<T: FixedOrDynIntType<1, Signed = ConstBool<false>>> From<bool> for IntValue<T> {
impl<
T: FixedOrDynIntType<
1,
Signed = ConstBool<false>,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>,
> From<bool> for IntValue<T>
{
fn from(v: bool) -> Self {
IntValue::with_type(T::new(), v)
}
@ -665,11 +865,7 @@ pub trait IntTypeTrait:
+ Eq
+ Hash
+ fmt::Debug
+ Type<
Value = IntValue<Self>,
CanonicalType = DynIntType<<Self as IntTypeTrait>::Signed>,
CanonicalValue = IntValue<DynIntType<<Self as IntTypeTrait>::Signed>>,
>
+ Type<Value = IntValue<Self>>
+ Connect<Self>
+ Connect<DynIntType<<Self as IntTypeTrait>::Signed>>
{
@ -678,11 +874,15 @@ pub trait IntTypeTrait:
Signed = ConstBool<false>,
SameWidthUInt = Self::SameWidthUInt,
SameWidthSInt = Self::SameWidthSInt,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>;
type SameWidthSInt: IntTypeTrait<
Signed = ConstBool<true>,
SameWidthUInt = Self::SameWidthUInt,
SameWidthSInt = Self::SameWidthSInt,
CanonicalType = DynSIntType,
CanonicalValue = DynSInt,
>;
fn from_width_unchecked(width: usize) -> Self;
fn width(self) -> usize;
@ -735,12 +935,12 @@ pub trait IntTypeTrait:
start..end
}
fn slice_and_shift<I: RangeBounds<usize>>(self, index: I) -> (DynUIntType, usize) {
let range = self.canonical().slice_index_to_range(index);
let range = self.slice_index_to_range(index);
let width = range.end - range.start;
(DynUIntType::new(width), range.start)
}
fn slice<I: RangeBounds<usize>>(self, index: I) -> DynUIntType {
self.canonical().slice_and_shift(index).0
self.slice_and_shift(index).0
}
}

View file

@ -11,7 +11,7 @@ use crate::{
ops::VariantAccess, Expr, Flow, Target, TargetBase, TargetPathArrayElement,
TargetPathBundleField, TargetPathElement, ToExpr,
},
int::{FixedOrDynIntType, UInt},
int::{DynUInt, DynUIntType, FixedOrDynIntType, UInt},
intern::{Intern, Interned},
memory::{Mem, MemBuilder, MemBuilderTarget, PortName},
reg::Reg,
@ -2254,7 +2254,12 @@ where
#[track_caller]
pub fn if_<Ty>(&mut self, cond: impl ToExpr<Type = Ty>) -> IfScope
where
Ty: FixedOrDynIntType<1, Signed = ConstBool<false>>,
Ty: FixedOrDynIntType<
1,
Signed = ConstBool<false>,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>,
{
self.if_with_loc(cond, SourceLocation::caller())
}
@ -2264,7 +2269,12 @@ where
source_location: SourceLocation,
) -> IfScope
where
Ty: FixedOrDynIntType<1, Signed = ConstBool<false>>,
Ty: FixedOrDynIntType<
1,
Signed = ConstBool<false>,
CanonicalType = DynUIntType,
CanonicalValue = DynUInt,
>,
{
let cond = cond.to_expr().as_bool();
let outer_block = self.block_stack.top();

View file

@ -11,7 +11,10 @@ use crate::{
ops, Expr, ExprEnum, Literal, Target, TargetBase, TargetChild, TargetPathArrayElement,
TargetPathBundleField, TargetPathDynArrayElement, TargetPathElement, ToExpr,
},
int::{DynInt, DynIntType, FixedOrDynIntType, IntType, IntTypeTrait},
int::{
DynInt, DynIntType, DynSInt, DynSIntType, DynUInt, DynUIntType, FixedOrDynIntType, IntType,
IntTypeTrait,
},
intern::{Intern, Interned},
memory::{Mem, MemPort, PortKind, PortName, PortType, ReadUnderWrite},
module::{

View file

@ -68,10 +68,9 @@ impl<T: IntTypeTrait> Valueless<T> {
&self,
high_part: Valueless<HighType>,
) -> Valueless<DynIntType<HighType::Signed>> {
let self_type = self.ty.canonical();
let ty = DynIntType::new(
self_type
.width
self.ty
.width()
.checked_add(high_part.ty.width())
.expect("result has too many bits"),
);

View file

@ -376,7 +376,7 @@
"$constructor": "ops::Not::new_unchecked",
"arg": "Visible"
},
"generics": "<T: IntTypeTrait>"
"generics": "<T: IntTypeTrait<CanonicalType = DynIntType<<T as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<T as IntTypeTrait>::Signed>>>"
},
"ops::Neg": {
"data": {
@ -384,7 +384,7 @@
"$constructor": "ops::Neg::new_unchecked",
"arg": "Visible"
},
"generics": "<T: IntTypeTrait<Signed = ConstBool<true>>>"
"generics": "<T: IntTypeTrait<Signed = ConstBool<true>, CanonicalType = DynSIntType, CanonicalValue = DynSInt>>"
},
"ops::BitAnd": {
"data": {
@ -395,7 +395,7 @@
},
"generics": {
"generics": "<L, R>",
"where": "L: IntTypeTrait, R: IntTypeTrait<Signed = L::Signed>"
"where": "L: IntTypeTrait<CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>>, R: IntTypeTrait<Signed = L::Signed, CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>>"
}
},
"ops::BitOr": {
@ -407,7 +407,7 @@
},
"generics": {
"generics": "<L, R>",
"where": "L: IntTypeTrait, R: IntTypeTrait<Signed = L::Signed>"
"where": "L: IntTypeTrait<CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>>, R: IntTypeTrait<Signed = L::Signed, CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>>"
}
},
"ops::BitXor": {
@ -419,7 +419,7 @@
},
"generics": {
"generics": "<L, R>",
"where": "L: IntTypeTrait, R: IntTypeTrait<Signed = L::Signed>"
"where": "L: IntTypeTrait<CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>>, R: IntTypeTrait<Signed = L::Signed, CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>>"
}
},
"ops::Add": {
@ -431,7 +431,7 @@
},
"generics": {
"generics": "<L, R>",
"where": "L: IntTypeTrait, R: IntTypeTrait<Signed = L::Signed>"
"where": "L: IntTypeTrait<CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>>, R: IntTypeTrait<Signed = L::Signed, CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>>"
}
},
"ops::Sub": {
@ -443,7 +443,7 @@
},
"generics": {
"generics": "<L, R>",
"where": "L: IntTypeTrait, R: IntTypeTrait<Signed = L::Signed>"
"where": "L: IntTypeTrait<CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>>, R: IntTypeTrait<Signed = L::Signed, CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>>"
}
},
"ops::Mul": {
@ -455,7 +455,7 @@
},
"generics": {
"generics": "<L, R>",
"where": "L: IntTypeTrait, R: IntTypeTrait<Signed = L::Signed>"
"where": "L: IntTypeTrait<CanonicalType = DynIntType<<L as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<L as IntTypeTrait>::Signed>>, R: IntTypeTrait<Signed = L::Signed, CanonicalType = DynIntType<<R as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<R as IntTypeTrait>::Signed>>"
}
},
"ops::DynShl": {
@ -465,7 +465,7 @@
"lhs": "Visible",
"rhs": "Visible"
},
"generics": "<LhsType: IntTypeTrait>"
"generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>>"
},
"ops::DynShr": {
"data": {
@ -474,7 +474,7 @@
"lhs": "Visible",
"rhs": "Visible"
},
"generics": "<LhsType: IntTypeTrait>"
"generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>>"
},
"ops::FixedShl": {
"data": {
@ -483,7 +483,7 @@
"lhs": "Visible",
"rhs": "Visible"
},
"generics": "<LhsType: IntTypeTrait>"
"generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>>"
},
"ops::FixedShr": {
"data": {
@ -492,7 +492,7 @@
"lhs": "Visible",
"rhs": "Visible"
},
"generics": "<LhsType: IntTypeTrait>"
"generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>>"
},
"ops::CmpLt": {
"data": {
@ -501,7 +501,7 @@
"lhs": "Visible",
"rhs": "Visible"
},
"generics": "<LhsType: IntTypeTrait, RhsType: IntTypeTrait<Signed = LhsType::Signed>, Output: FixedOrDynIntType<1, Signed = ConstBool<false>>>"
"generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>"
},
"ops::CmpLe": {
"data": {
@ -510,7 +510,7 @@
"lhs": "Visible",
"rhs": "Visible"
},
"generics": "<LhsType: IntTypeTrait, RhsType: IntTypeTrait<Signed = LhsType::Signed>, Output: FixedOrDynIntType<1, Signed = ConstBool<false>>>"
"generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>"
},
"ops::CmpGt": {
"data": {
@ -519,7 +519,7 @@
"lhs": "Visible",
"rhs": "Visible"
},
"generics": "<LhsType: IntTypeTrait, RhsType: IntTypeTrait<Signed = LhsType::Signed>, Output: FixedOrDynIntType<1, Signed = ConstBool<false>>>"
"generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>"
},
"ops::CmpGe": {
"data": {
@ -528,7 +528,7 @@
"lhs": "Visible",
"rhs": "Visible"
},
"generics": "<LhsType: IntTypeTrait, RhsType: IntTypeTrait<Signed = LhsType::Signed>, Output: FixedOrDynIntType<1, Signed = ConstBool<false>>>"
"generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>"
},
"ops::CmpEq": {
"data": {
@ -537,7 +537,7 @@
"lhs": "Visible",
"rhs": "Visible"
},
"generics": "<LhsType: IntTypeTrait, RhsType: IntTypeTrait<Signed = LhsType::Signed>, Output: FixedOrDynIntType<1, Signed = ConstBool<false>>>"
"generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>"
},
"ops::CmpNe": {
"data": {
@ -546,7 +546,7 @@
"lhs": "Visible",
"rhs": "Visible"
},
"generics": "<LhsType: IntTypeTrait, RhsType: IntTypeTrait<Signed = LhsType::Signed>, Output: FixedOrDynIntType<1, Signed = ConstBool<false>>>"
"generics": "<LhsType: IntTypeTrait<CanonicalType = DynIntType<<LhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<LhsType as IntTypeTrait>::Signed>>, RhsType: IntTypeTrait<Signed = LhsType::Signed, CanonicalType = DynIntType<<RhsType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<RhsType as IntTypeTrait>::Signed>>, Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>"
},
"ops::CastInt": {
"data": {
@ -555,7 +555,7 @@
"value": "Visible",
"ty()": "Visible"
},
"generics": "<FromType: IntTypeTrait, ToType: IntTypeTrait>",
"generics": "<FromType: IntTypeTrait<CanonicalType = DynIntType<<FromType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<FromType as IntTypeTrait>::Signed>>, ToType: IntTypeTrait<CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>",
"fold_where": "ToType: Fold<State>",
"visit_where": "ToType: Visit<State>"
},
@ -566,7 +566,7 @@
"base": "Visible",
"range": "Opaque"
},
"generics": "<Base: IntTypeTrait>"
"generics": "<Base: IntTypeTrait<CanonicalType = DynIntType<<Base as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<Base as IntTypeTrait>::Signed>>>"
},
"ops::ReduceBitAnd": {
"data": {
@ -574,7 +574,7 @@
"$constructor": "ops::ReduceBitAnd::new_unchecked",
"arg": "Visible"
},
"generics": "<Output: FixedOrDynIntType<1, Signed = ConstBool<false>>>"
"generics": "<Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>"
},
"ops::ReduceBitOr": {
"data": {
@ -582,7 +582,7 @@
"$constructor": "ops::ReduceBitOr::new_unchecked",
"arg": "Visible"
},
"generics": "<Output: FixedOrDynIntType<1, Signed = ConstBool<false>>>"
"generics": "<Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>"
},
"ops::ReduceBitXor": {
"data": {
@ -590,7 +590,7 @@
"$constructor": "ops::ReduceBitXor::new_unchecked",
"arg": "Visible"
},
"generics": "<Output: FixedOrDynIntType<1, Signed = ConstBool<false>>>"
"generics": "<Output: FixedOrDynIntType<1, Signed = ConstBool<false>, CanonicalType = DynUIntType, CanonicalValue = DynUInt>>"
},
"ops::FieldAccess": {
"data": {
@ -696,7 +696,7 @@
"$constructor": "ops::CastClockToBit::new_unchecked",
"value": "Visible"
},
"generics": "<ToType: FixedOrDynIntType<1>>"
"generics": "<ToType: FixedOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>"
},
"ops::CastSyncResetToBit": {
"data": {
@ -704,7 +704,7 @@
"$constructor": "ops::CastSyncResetToBit::new_unchecked",
"value": "Visible"
},
"generics": "<ToType: FixedOrDynIntType<1>>"
"generics": "<ToType: FixedOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>"
},
"ops::CastAsyncResetToBit": {
"data": {
@ -712,7 +712,7 @@
"$constructor": "ops::CastAsyncResetToBit::new_unchecked",
"value": "Visible"
},
"generics": "<ToType: FixedOrDynIntType<1>>"
"generics": "<ToType: FixedOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>"
},
"ops::CastResetToBit": {
"data": {
@ -720,7 +720,7 @@
"$constructor": "ops::CastResetToBit::new_unchecked",
"value": "Visible"
},
"generics": "<ToType: FixedOrDynIntType<1>>"
"generics": "<ToType: FixedOrDynIntType<1, CanonicalType = DynIntType<<ToType as IntTypeTrait>::Signed>, CanonicalValue = DynInt<<ToType as IntTypeTrait>::Signed>>>"
},
"BlockId": {
"data": {