Generate Expressions
Generate
Repetitive code can be generated programmatically with two constructs: generate and generate_seq.
generate-expression ::= "generate" ( $identifier : $start, $end, $step ) { $expression }
generate-seq-expression ::= "generate_seq" ( $identifier : $start, $end, $step ) { $expression }
Both constructs unroll the body for each value of the loop variable, from start to end inclusive, using the specified step. The generate construct combines these bodies in parallel, like a join expression. The generate_seq construct combines them in sequence, like a wait expression.
For example:
In this program, the Top process uses the generate construct to initialize an array mem in parallel, while the Bar process uses the generate_seq construct to initialize its own array mem in sequence. Each iteration of the loop variable i sets the corresponding element of the array and prints its value. The Top process completes the initialization in one cycle, while the Bar process takes multiple cycles to complete its sequential initialization.