Cyclicity CDL Language Specification - Grammar
Gavin J Stark
v0.01
April 14th 2004
|
CDL is a language that, at the top level, specifies four things:
Type definitions
Constant declarations
Module prototypes and timing specifications
Module definitions
The lexical order of the first two of these in a file is
important; constant evaluations and type definitions are performed in
lexical order, so that a type that utilizes a constant value as a bit
width, for example, must not precede the declaration of that constant
value.
However, module definitions may refer to modules that have not
been defined or prototyped; there is no lexical order requirement
between module definitions and prototypes.
|
|
Constants have their own scope. Enumerations are explicitly typed,
and so are within their own type's scope.
|
Grammatical building blocks |
|
user symbol list |
user symbol list | := |
<user symbol> [ ',' [ <user symbol list> ] ] |
|
type specifier |
type specifier | := |
<user symbol> |
| | | <base type> |
| | | <type specifier> '['<expression> ']' |
|
base type |
base type | := |
signed bit |
| | | unsigned bit |
| | | bit |
| | | integer |
| | | string |
|
lvar |
lvar | := |
<user symbol> |
| | | <lvar> '.' <user symbol> |
| | | <lvar> '[' <expression>']' |
| | | <lvar> '[' <expression> ';' <expression> ']' |
|
expression |
expression | := |
<integer> |
| | | <lvar> |
| | | sizeof '(' <expression> ')' |
| | | bundle '(' <expression list> ')' |
| | | <expression> '?' <expression>':' <expression> |
| | | <expression> ( '+' | '-' | '*' | '/' | '%' ) <expression> |
| | | <expression> ( '&' | '|' | '^' | '&&' | '||' | '^^' ) <expression> |
| | | <expression> ( '<' | '<=' | '>' | '>=' | '==' | '!=' ) <expression> |
| | | <expression> ( '<<' | '>>' ) <expression> |
| | | ( '!' | '-' | '~' ) <expression> |
| | | '(' <expression> ')' |
|
expression list |
expression list | := |
<expression> [ ',' [ <expression list> ] ] |
|
|
|
type definition |
type definition | := |
typedef <user symbol> <user symbol> ';' |
| | | typedef enum '[' [ <expression> ] ']' '{' <enumerations> '}' <user symbol> ';' |
| | | typedef struct '{' <structure element>* '}' <user symbol> ';' |
| | | typedef [ one_hot | one_cold ] fsm '{' <fsm state>* '}' <user symbol> ';' |
|
enumerations |
enumerations | := |
<user symbol> [ '=' <expression> ] [ ',' [ <enumerations> ] ] |
|
structure element |
structure element | := |
<type specifier> <user symbol> [ <documentation string> ] ';' |
|
fsm state |
fsm state | := |
<user symbol> [ '{' <user symbol list> '}' [ '{' <user symbol list> '}' ] ] [ '=' <expression> ] [<documentation string> ] ';' |
|
constant declaration |
constant declaration | := |
constant <type specifier> <user symbol> = <expression> [ <optional documentation> ] ';' |
|
Module prototypes and timing specifications |
Module prototypes provide a mechanism for declaring a module's
ports and the timing of those ports. The module may also be defined
later in the file. A module prototype may also contain details of how
the module may be drawn in a schematic, and its documentation should
describe the overal functionality of the module.
|
module prototype |
module prototype | := |
extern module <user symbol> '(' <port list> ')' [ <documentation> ] '{' <prototype body>* '}' |
|
port list |
port list | := |
<port> [ ',' [ <port list> ] ] |
|
port |
port | := |
clock <user symbol> [ <documentation> ] |
| | | ( input | output ) <type specifier> <user symbol> [ <documentation> ] |
| | | parameter <type specifier> <user symbol> [ <documentation> ] |
|
prototype body |
prototype body | := |
<timing specification> |
|
timing specification |
timing specification | := |
timing ( to | from ) [ rising | falling ] <user symbol> <user symbol list> [ <documentation> ] ';' |
| | | timing comb ( input | output ) <user symbol list> [ <documentation> ] ';' |
Schematic symbol specification is not yet defined in the language.
All types must be determinable at build time, currently. This
means parameters must not be
used to specify the widths of bit vectors, for example; this would
require run-time checks. (Er, not quite true, but parameters in types
are certainly tricky at the moment... but there are workarounds with
constants and module naming)
|
|
Module definitions define the contents of a module. This may
include a schematic of the module itself, which is relatable to the
code inside the module due to the structuring of the CDL language;
however, schematics are not in any sense required.
The documentation of the module should describe the design details
of the module; if figures are required for such documentation, they
should be referenced from here.
|
module definition |
module definition | := |
module <user symbol> '(' <port list> ')' [ <documentation> ] '{' <module body>* '}' |
|
module body |
module body | := |
<clock definition> |
| | | <reset definition> |
| | | <clocked variable> |
| | | <comb variable> |
| | | <net variable> |
| | | <labelled code> |
|
clock definition |
clock definition | := |
default <clock specification> [ <documentation> ] ';' |
|
reset definition |
reset definition | := |
default <reset specification> [ <documentation> ] ';' |
|
clocked variable |
clocked variable | := |
clocked [ <clock specification> ] [ <reset specification> ] <type specifier> <user symbol> '=' <nested assignment list> [ <documentation> ] ';' |
|
comb variable |
comb variable | := |
comb <type specifier> <user symbol> [ '=' <nested assignment list> ] [ <documentation> ] ';' |
|
net variable |
net variable | := |
net <type specifier> <user symbol> [ <documentation> ] ';' |
|
clock specification |
clock specification | := |
clock [ rising | falling ] <user symbol> |
|
reset specification |
reset specification | := |
reset [ active_low | active_high ] <user symbol> |
|
labelled code |
labelled code | := |
<user symbol> [ <documentation> ] ':' '{' <statement>* '}' |
|
statement |
statement | := |
<for statement> |
| | | <assignment statement> |
| | | <if statement> |
| | | <switch statement> |
| | | <print statement> |
| | | <assertion statement> |
| | | <sequence definition> |
| | | <instantiation> |
|
for statement |
for statement | := |
for '(' <user symbol> ';' <expression> ')' [ '(' <expression> ';' <expression> ';' <expression> ')' ] '{' <statement>* '}' |
|
assignment statement |
assignment statement | := |
<lvar> ( '=' | '<=' ) <nested assignment> ';' |
|
if statement |
if statement | := |
if '(' <expression> ')' '{' <statement>* '}' ( elsif '(' <expression> ')' '{' <statement>* '}' )* [ else '{' <statement>* '}' ] |
|
switch statement |
switch statement | := |
( full_switch | part_switch | priority ) '(' <expression> ')' '{' <case entries> '}' |
|
case entries |
case entries | := |
( default | (case <expression list> ) ) ':' [ '{' <statement>* '}' ] |
|
print statement |
print statement | := |
print [<clock specification>] [<reset specification>] '(' <string> ')' ';' |
|
assert statement |
assert statement | := |
assert [<clock specification>] [<reset specification>] '(' <expression> ',' <string> ')' ';' |
| | | assert [<clock specification>] [<reset specification>] '(' <expression> ',' <user symbol> ',' <string> ')' ';' |
|
sequence definition |
sequence definition | := |
sequence '{' <sequence item>* '}' <user symbol> ';' |
|
sequence item |
sequence item | := |
delay <unsized integer> [ to <unsized integer> ] |
| | | <sequence expression> |
|
sequence expression |
sequence expression | := |
<user symbol> |
| | | '(' <expression> ')' |
| | | <sequence_expression> ( '&&' | '||' | '^^' ) <sequence_expression> |
| | | not <sequence expression> |
|
instantiation |
instantiation | := |
<user symbol> <user symbol> [ '[' <expression< ']' ] '(' [<port map list> ] ')' ';' |
|
port map list |
port map list | := |
<port map> [ ',' [ <port map list> ] ] |
|
port map |
port map | := |
<user symbol> '<-' <user symbol> |
| | | <user symbol> '=' <expression> |
| | | <user symbol> '<=' <expression> |
| | | <user symbol> '=>' <lvar> |
|