diff --git a/crates/fayalite/src/expr.rs b/crates/fayalite/src/expr.rs index 644d058..fa50852 100644 --- a/crates/fayalite/src/expr.rs +++ b/crates/fayalite/src/expr.rs @@ -9,7 +9,7 @@ use crate::{ ops::ExprCastTo, target::{GetTarget, Target}, }, - int::{Bool, DynSize, IntType, SIntType, SIntValue, Size, UInt, UIntType, UIntValue}, + int::{Bool, DynSize, IntType, SIntType, SIntValue, Size, SizeType, UInt, UIntType, UIntValue}, intern::{Intern, Interned}, memory::{DynPortType, MemPort, PortType}, module::{ @@ -720,3 +720,18 @@ impl MakeUninitExpr for T { ops::Uninit::new(self).to_expr() } } + +pub fn repeat( + element: impl ToExpr, + len: L, +) -> Expr> { + let element = element.to_expr(); + let canonical_element = Expr::canonical(element); + ops::ArrayLiteral::new( + Expr::ty(element), + std::iter::repeat(canonical_element) + .take(L::Size::as_usize(len)) + .collect(), + ) + .to_expr() +} diff --git a/crates/fayalite/src/prelude.rs b/crates/fayalite/src/prelude.rs index 5dc503e..7b7d718 100644 --- a/crates/fayalite/src/prelude.rs +++ b/crates/fayalite/src/prelude.rs @@ -7,7 +7,7 @@ pub use crate::{ clock::{Clock, ClockDomain, ToClock}, enum_::{HdlNone, HdlOption, HdlSome}, expr::{ - CastBitsTo, CastTo, CastToBits, Expr, HdlPartialEq, HdlPartialOrd, MakeUninitExpr, + repeat, CastBitsTo, CastTo, CastToBits, Expr, HdlPartialEq, HdlPartialOrd, MakeUninitExpr, ReduceBits, ToExpr, }, hdl, hdl_module,