在Systemverilog

时间:2015-07-27 12:30:03

标签: arrays struct module macros system-verilog

我创建了一个模块,其中包含(示例)两个输入和两个输出。每个in和output的定义都是通过宏来定义的。

是否可以创建它更优雅(以后的可用性)?像输入和输出数组(NAME(i),in(i),out(i))?

这会有所帮助,因为我后来使用了更多的输入和输入,并且有可能使用后来的循环访问输入/输出更加优雅。

`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)

1 个答案:

答案 0 :(得分:0)

无法使用数组执行此操作,因为根据定义,数组是统一类型变量的集合。使用动态索引值进行访问需要每个元素具有相同的布局。即使使用不同长度的简单位向量也不会起作用。您唯一的可综合选项是使用最大大小声明info并希望将未使用的位优化掉。

相关问题