Syntactic Replication
Syntactic replication (sometimes called a syntactic loop construct) is a useful construct that can be used in a variety of places. The syntactic replication construct is written as follows:
(sym id : range : body(id) )
The sym (symbol) might be empty. id is a variable that can be used in the body(id), and takes the range specified by range. range can be either an integer-valued expression or start .. end to indicate a start and end index. The integer value of “id” is substituted into “body(id)” when the replication construct is expanded out. The result of the replication is
body(lo) sym body(lo+1) sym ... sym body(hi)
where lo is the starting index of the range, and hi is the ending index. What follows are different forms of the same construct that can be used in ACT.
The core ACT language
Within the core ACT language (i.e. outside the sublanguage braces), the most common use of syntactic replication is a parameterized list of connections. The statement
(i : 9 : b[i].R = b[i+1].L;)
is syntactic sugar for:
b[0].R = b[1].L; b[1].R = b[2].L; ... b[8].R = b[9].L;
In this particular case, the separator is empty.
Another example is:
(i : 1..8 : register r[i..i]; r[i](in[i],out[i],control); )
This would be equivalent to:
register r[1..1]; r[1](in[1],out[1],control); register r[2..2]; r[2](in[2],out[2],control); ... register r[8..8]; r[8](in[8],out[8],control);
The second place the construct can be used is in guards of selection statements:
[ x = 0 -> inst i1; [] ( [] i : 1..3 -> x = i -> inst i2;) [] x = 4 -> inst i3; ]
This would be turned into:
[ x = 0 -> inst i1; [] x = 1 > inst i2; [] x = 2 -> inst i2; [] x = 3 -> inst i2; [] x = 4 -> inst i3; ]
In this scenario, the separator is the [] operator that is used to separate guarded actions.
CHP
CHP also supports syntactic replication for guards like the core language1). In addition, CHP permits syntactic replication for sequential and parallel composition, as illustrated in the following examples:
Sequential composition:
(; i : 5 : x.d[i]-; y := y + 1 )
Parallel composition:
(, i : 5 : x.d[i]-)
CHP expressions also support some forms of syntactic replication. The following binary operators allow syntactic replication:
- Logical or bitwise and (
&) - Logical or bitwise or (
|) - Bitwise exclusive or (
^) - Addition (
+) - Multiplication (
*)
This means you can write statements like:
x := (+ i : 5 : a[i])
Dataflow
Split and merge operators in the dataflow language can use syntactic replication. This is primarily through comma-separated operators, as in the following parameterized N-way split:
dataflow { {ctrl} l -> (, i : N : out[i]) }
PRS
Production rules support both simple syntactic replication as well as syntactic replication in expressions.
Simple replication:
prs { (i : 5 : Reset -> x[i]-) // simple replication of production rule }
Expressions to create a single N-input NAND gate:
prs { (&i : N : x[i]) -> y- (|i : N : ~x[i]) -> y+ }
Sizing
The sizing body also supports syntactic replication.
sizing { ... (; i : 5 : out[i] {-1}); ... }