Structs
Structs group related wires together, enforcing identical timing and, when used as module IO, direction. They can also be parameterized.
Definition
Structs are defined using the struct
keyword, followed by the name and map of fields. Fields are of the form name: type
, where type
is an expression that resolves to a LogicType
value.
neo
struct MyStruct {
a: Bits(32),
b: Bits(32),
}
struct MyParameterizedStruct(t: LogicType) {
a: Bits(32),
b: t,
}
Use
For unparameterized structs, the name becomes a LogicType
value and can be used directly. For parameterized structs, the name is a function reference to be called with values for the parameters.
neo
logic val(0): MyStruct;
logic parameterized_val(0): MyParameterizedStruct(Int(32));
Accessing fields of a struct works as in any other language, and they can be assigned or read:
neo
assign val.a = some_data;
assign some_value = val.a;
Structs can also be assigned as a whole:
neo
assign val = another_instance_of_MyStruct;
Structs can be instantiated with a map of field names to values:
neo
assign my_struct = .{
a: some_data,
b: some_other_data,
};