简体   繁体   English

在Systemverilog中使用宏创建结构数组

[英]Creating an array of structs with macro in Systemverilog

I've created a module with (example) two in and two out-puts. 我创建了一个带有(两个)输入和两个输出的模块(示例)。 The definition of every in and output is delcared through a macro. 每个输入和输出的定义都通过一个宏传递。

Is it possible to create it a bit more elegant (later usability)? 是否可以将其创建得更加优雅(可用性更高)? Something like an array of inputs and outputs (NAME(i), in(i), out(i))? 有点像输入和输出数组(NAME(i),in(i),out(i))?

It would be helpful, because i am later using much more out and inputs and there is a possbility using later loops to access the in/outputs much more elegant. 这将是有帮助的,因为稍后我会使用更多的out和输入,并且有可能使用稍后的循环来更优雅地访问in /输出。

top: 最佳:

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

There is no way to do this with an array because, by definition, an array is a collection of uniformly typed variables. 无法对数组执行此操作,因为根据定义,数组是统一类型变量的集合。 Access with a dynamic index value requires that each element have an identical layout. 具有动态索引值的访问要求每个元素具有相同的布局。 It would not work even with simple bit vectors of different lengths. 即使使用不同长度的简单位向量也无法使用。 Your only synthesizable option is to declare info with a max size and hope the unused bits are optimized away. 您唯一可综合的选项是声明info的最大大小,并希望将未使用的位进行优化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM