在 Systemverilog 中使用宏创建结构数组
Creating an array of structs with macro in Systemverilog
我创建了一个带有(示例)两个输入和两个输出的模块。每个输入和输出的定义都是通过宏定义的。
是否可以将其创建得更优雅一点(以后的可用性)?类似于输入和输出数组 (NAME(i), in(i), out(i))?
这会很有帮助,因为我以后会使用更多的输出和输入,并且有可能使用以后的循环来访问 in/outputs 更优雅。
顶部:
`include "macro.sv"
module top (in_0, in_1, out_0, out_1);
`STRUCT_i(in_0_temp, 10);
`STRUCT_i(in_1_temp, 22);
`STRUCT_i(out_0_temp, 55);
`STRUCT_i(out_1_temp, 99);
input `STRUCT(in_0_temp) in_0;
input `STRUCT(in_1_temp) in_1;
output `STRUCT(out_0_temp) out_0;
output `STRUCT(out_1_temp) out_1;
...
endmodule
Macro.sv :
`define STRUCT(NAME) \
struct_i_``NAME``
`define STRUCT_i(NAME, DATA) \
typedef struct packed { \
logic [DATA:0] info; \
logic test1; \
logic test2; \
} `STRUCT(NAME)
无法对数组执行此操作,因为根据定义,数组是统一类型变量的集合。使用动态索引值访问要求每个元素具有相同的布局。即使使用不同长度的简单位向量,它也不起作用。您唯一可综合的选择是声明 info
最大大小,并希望未使用的位被优化掉。
我创建了一个带有(示例)两个输入和两个输出的模块。每个输入和输出的定义都是通过宏定义的。
是否可以将其创建得更优雅一点(以后的可用性)?类似于输入和输出数组 (NAME(i), in(i), out(i))?
这会很有帮助,因为我以后会使用更多的输出和输入,并且有可能使用以后的循环来访问 in/outputs 更优雅。
顶部:
`include "macro.sv"
module top (in_0, in_1, out_0, out_1);
`STRUCT_i(in_0_temp, 10);
`STRUCT_i(in_1_temp, 22);
`STRUCT_i(out_0_temp, 55);
`STRUCT_i(out_1_temp, 99);
input `STRUCT(in_0_temp) in_0;
input `STRUCT(in_1_temp) in_1;
output `STRUCT(out_0_temp) out_0;
output `STRUCT(out_1_temp) out_1;
...
endmodule
Macro.sv :
`define STRUCT(NAME) \
struct_i_``NAME``
`define STRUCT_i(NAME, DATA) \
typedef struct packed { \
logic [DATA:0] info; \
logic test1; \
logic test2; \
} `STRUCT(NAME)
无法对数组执行此操作,因为根据定义,数组是统一类型变量的集合。使用动态索引值访问要求每个元素具有相同的布局。即使使用不同长度的简单位向量,它也不起作用。您唯一可综合的选择是声明 info
最大大小,并希望未使用的位被优化掉。