Loops
DFHDL supports loops in several contexts with different semantics depending on the domain and placement.
Elaboration-Time Loops (Generate Loops)
Scala for loops at design scope (outside processes) run at elaboration time. They unroll into repeated hardware -- equivalent to Verilog generate for. The generated HDL contains no loop; each iteration produces distinct instances.
1 2 3 4 5 6 7 8 9 10 11 12 | |
When a design containing an elaboration-time loop is instantiated with different parameter values, DFHDL creates distinct elaborated designs (with enumerated names), each with a different number of unrolled instances.
Elaboration-Time Conditionals
Unlike Verilog generate if, DFHDL type-checks both branches of an if expression at elaboration time, regardless of the parameter value. This means both branches must be type-correct for all possible parameter values:
1 2 3 4 5 6 7 8 9 10 11 | |
ED Domain Loops
In ED designs, for and while loops inside processes produce combinational or sequential logic depending on the process type. These loops are unrolled by the compiler.
RT Domain Loops
In RT designs, for and while loops inside processes create synthesizable procedural FSMs. The compiler transforms the loop body into state machine transitions. See Processes for details on RT domain process semantics.