[英]Creating an array of structs with macro in Systemverilog
我創建了一個帶有(兩個)輸入和兩個輸出的模塊(示例)。 每個輸入和輸出的定義都通過一個宏傳遞。
是否可以將其創建得更加優雅(可用性更高)? 有點像輸入和輸出數組(NAME(i),in(i),out(i))?
這將是有幫助的,因為稍后我會使用更多的out和輸入,並且有可能使用稍后的循環來更優雅地訪問in /輸出。
最佳:
`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
的最大大小,並希望將未使用的位進行優化。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.