Data Types
Anvil supports both primitive and user-defined data types. Types are constructed using data type expressions.
Data Type Expressions
data-type-expression ::= ()
| logic
| $identifier
| ( $data-type-expression [ {digit}+ ] )
Meaning:
()represents the unit type.logicis the single-bit type.$identifierrefers to a named type.(T[n])is an array ofnelements of typeT.
Examples:
logic
address_data_pair
logic[8]
Type Definitions
A named type can be introduced using a type definition:
data-type-definition ::= type $identifier [ $params ] = $data-type-expression ;
Example:
type byte = (logic[8]);
type word = (logic[32]);
Struct Definitions
A named struct type is defined as:
struct $identifier [ $params ] {
$identifier : $data-type-expression
{ , $identifier : $data-type-expression }
}
Example:
struct address_data_pair {
data : (logic[8]),
addr : (logic[16])
}
Enum Definitions
An enum type is defined as:
enum $identifier {
$identifier { , $identifier }
}
Example:
enum state {
IDLE,
BUSY,
DONE
}