Skip to content

Commit e37977a

Browse files
author
Oron Port
committed
change repeat functionality for vectors
1 parent fb52426 commit e37977a

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

compiler/ir/src/main/scala/dfhdl/compiler/printing/DFValPrinter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ protected trait DFValPrinter extends AbstractValPrinter:
186186
// repeat func
187187
case argL :: argR :: Nil if dfVal.op == Func.Op.repeat =>
188188
dfVal.dfType match
189-
case _: DFVector => s"all(${argL.refCodeString})"
190-
case _ =>
189+
case dfType: DFVector => s"DFVector(${printer.csDFType(dfType)})(${argL.refCodeString})"
190+
case _ =>
191191
val csArgL = argL.refCodeString(typeCS)
192192
val csArgR = argR.refCodeString(typeCS)
193193
s"${csArgL.applyBrackets()}.repeat${csArgR.applyBrackets(onlyIfRequired = false)}"

core/src/main/scala/dfhdl/core/DFVector.scala

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,20 @@ object DFVector:
230230
object DFVector:
231231
def apply[T <: DFTypeAny, D1 <: IntP, P](vectorType: DFVector[T, Tuple1[D1]])(
232232
elems: DFValTP[T, P]*
233-
)(using DFC): DFValTP[DFVector[T, Tuple1[D1]], P] =
234-
DFVal.Func(vectorType, FuncOp.++, elems.toList)
233+
)(using DFC): DFValTP[DFVector[T, Tuple1[D1]], P] = trydf:
234+
if (elems.size == 1)
235+
DFVal.Func(
236+
vectorType,
237+
FuncOp.repeat,
238+
List(elems.head, vectorType.lengthIntParam.toDFConst)
239+
).asValTP[DFVector[T, Tuple1[D1]], P]
240+
else
241+
assert(
242+
elems.size == dfhdl.core.DFVector.lengthInt(vectorType),
243+
"The number of elements in the vector does not match the vector length."
244+
)
245+
DFVal.Func(vectorType, FuncOp.++, elems.toList)
246+
end DFVector
235247

236248
extension [T <: DFTypeAny, D1 <: IntP, M <: ModifierAny](
237249
lhs: DFVal[DFVector[T, Tuple1[D1]], M]

0 commit comments

Comments
 (0)