diff --git a/src/main/scala/backends/calyx/Ast.scala b/src/main/scala/backends/calyx/Ast.scala index f6a87505..da19bdc1 100644 --- a/src/main/scala/backends/calyx/Ast.scala +++ b/src/main/scala/backends/calyx/Ast.scala @@ -307,10 +307,15 @@ object Calyx: else space <> text("else") <+> scope(falseBr.doc) ) - case While(port, cond, body) => + case While(port, cond, body) => { text("while") <+> port.doc() <+> text("with") <+> cond.doc() <+> scope(body.doc(meta)) + } + case While(count, body) => { + text("repeat") <+> count.toString <+> + scope(body.doc(meta)) + } case e @ Enable(id) => { emitPos(e.pos, e.span) <> id.doc() <> semi } @@ -340,6 +345,7 @@ object Calyx: case class If(port: Port, cond: CompVar, trueBr: Control, falseBr: Control) extends Control case class While(port: Port, cond: CompVar, body: Control) extends Control + case class Repeat(count: Int, body: Control) extends Control case class Enable(id: CompVar) extends Control with Syntax.PositionalWithSpan case class Invoke( id: CompVar, diff --git a/src/main/scala/backends/calyx/Backend.scala b/src/main/scala/backends/calyx/Backend.scala index 6606025d..3088bcff 100644 --- a/src/main/scala/backends/calyx/Backend.scala +++ b/src/main/scala/backends/calyx/Backend.scala @@ -936,23 +936,29 @@ private class CalyxBackendHelper { } case CEmpty => (List(), Empty, store) case wh @ CWhile(cond, _, body) => { - val condOut = emitExpr(cond) - val groupName = genName("cond") - assertOrThrow( - !condOut.done.isDefined, - BackendError("Loop condition is non-combinational") - ) - val (condGroup, condDefs) = - Group.fromStructure( - groupName, - condOut.structure, - condOut.delay, - true + if wh.attributes.contains("bound") then { + val (bodyStruct, bodyCon, st) = emitCmd(body) + val control = Repeat(10, bodyCon) + (bodyStruct, control, st) + } else { + val condOut = emitExpr(cond) + val groupName = genName("cond") + assertOrThrow( + !condOut.done.isDefined, + BackendError("Loop condition is non-combinational") ) - val (bodyStruct, bodyCon, st) = emitCmd(body) - val control = While(condOut.port, condGroup.id, bodyCon) - control.attributes = wh.attributes - (condGroup :: bodyStruct ++ condDefs, control, st) + val (condGroup, condDefs) = + Group.fromStructure( + groupName, + condOut.structure, + condOut.delay, + true + ) + val (bodyStruct, bodyCon, st) = emitCmd(body) + val control = While(condOut.port, condGroup.id, bodyCon) + control.attributes = wh.attributes + (condGroup :: bodyStruct ++ condDefs, control, st) + } } case _: CFor => throw BackendError(