Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| language:interface [2021/11/21 17:41] – created rajit | language:interface [2025/10/06 11:10] (current) – [Interfaces with functions and macros] rajit | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ===== Constructors for Types ===== | ===== Constructors for Types ===== | ||
| - | **XXX: this section | + | There are cases when it is useful to be able to build more complex types |
| + | from existing types. ACT provides a mechanism to do so via interfaces and | ||
| + | parameter types. | ||
| + | |||
| + | ==== Interfaces ==== | ||
| + | |||
| + | An interface is defined in the following way: | ||
| + | <code act> | ||
| + | interface linearchain (bool? in; bool! out); | ||
| + | </ | ||
| + | This defines '' | ||
| + | |||
| + | Any process can export a list of interfaces. | ||
| + | When a process exports an interface, it means that it has I/O ports that correspond to the names in the interface. | ||
| + | The port names within the process need not match the port names in the interface; when an interface is exported, a mapping must be provided as part of the interface export specification. | ||
| + | |||
| + | <code act> | ||
| + | defproc proc1 (bool? a; bool! b) :> linearchain { in -> a, out -> b } | ||
| + | { | ||
| + | ... | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | In this definition, '' | ||
| + | |||
| + | ==== Parameter types ==== | ||
| The special '' | The special '' | ||
| Line 8: | Line 33: | ||
| '' | '' | ||
| - | < | + | < |
| ptype(foo) x; | ptype(foo) x; | ||
| </ | </ | ||
| Line 14: | Line 39: | ||
| This says that '' | This says that '' | ||
| constraint that '' | constraint that '' | ||
| - | '' | + | interface |
| - | operations supported by type '' | + | ports corresponding to interface |
| '' | '' | ||
| following example: | following example: | ||
| - | < | + | < |
| // A constructor for a datapath with W-bit ripple connections, | // A constructor for a datapath with W-bit ripple connections, | ||
| - | // where each component has M inputs and one output | + | // where each component has an additional |
| - | // A skeleton | + | // Interface definition |
| template< | template< | ||
| - | defproc | + | interface |
| - | | + | |
| // the constructor | // the constructor | ||
| Line 34: | Line 58: | ||
| | | ||
| { | { | ||
| - | t x[N]; | + | t x[N]; // array of type " |
| // ripple connections | // ripple connections | ||
| - | (;i:N-1: x[i].rout=x[i+1].rin); | + | |
| | | ||
| - | | + | |
| + | |||
| // i/o connections | // i/o connections | ||
| - | (;i:N: x[i].in[i*M..(i+1)*M-1] | + | (i:N: x[i].in = in[i*M..(i+1)*M-1]; |
| - | x[i].out=out[i] ) | + | x[i].out=out[i]; ) |
| } | } | ||
| - | // A one-bit adder | + | // A one-bit adder, that exports the bitslice interface |
| - | defproc onebit (e1of2? in[2], rin[1]; e1of2! out, rout[1]) { ... } | + | defproc onebit (e1of2? in[2], rin[1]; e1of2! out, rout[1]) |
| + | :> | ||
| + | { ... } | ||
| defproc ripple_adder (e1of2? a[32], b[32], cin; e1of2! out[32], cout) | defproc ripple_adder (e1of2? a[32], b[32], cin; e1of2! out[32], cout) | ||
| { | { | ||
| - | build_dpath< | + | build_dpath< |
| - | (; i : 32 : dp.in[2*i] = a[i]; dp.in[2*i+1] = b[i]); | + | (i : 32 : dp.in[2*i] = a[i]; dp.in[2*i+1] = b[i];) |
| dp.out = out; | dp.out = out; | ||
| dp.rin[0] = cin; | dp.rin[0] = cin; | ||
| - | dp.rout[0] = cout | + | dp.rout[0] = cout; |
| } | } | ||
| </ | </ | ||
| + | Process type ('' | ||
| + | ==== Interfaces with functions and macros | ||
| + | |||
| + | An interface type can also include function and macro prototypes. | ||
| + | |||
| + | <code act> | ||
| + | export template< | ||
| + | { | ||
| + | methods { | ||
| + | | ||
| + | macro update(int< | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | This defines an interface that exports two methods. Note that, unlike port parameters, method names cannot be changed when a type exports an interface. | ||