简体   繁体   English

Systemverilog:在宏实例化模块时,有没有办法使信号唯一?

[英]Systemverilog: Is there a way to make signal unique in macro instantiating a module?

I have a macro like this: 我有一个这样的宏:

`define BOB_STAGE(_BUS_IN, _BUS_OUT) \
   bob_module auto_``_BUS_OUT``_bob_module ( .bus_in(_BUS_IN), .bus_out(_BUS_OUT) );

(Notice _BUS_OUT becomes part of the instance name to make unique instances.) (注意_BUS_OUT成为实例名称的一部分,以创建唯一的实例。)

So these are used all over the place and take concatenated signals in to 1 signal out, but the out signal is indexed. 因此,这些信号在各处使用,并将连接的信号输入为1信号输出,但输出信号被索引。

Example Use: 使用示例:

`BOB_STAGE( {A,B,C,D}, OUT[1] );

The problem is both the concat {} and index [] mess up the automatic assignment in the module instance name. 问题是concat {}和index []都弄乱了模块实例名称中的自动分配。

I want to solve this without adding another input for signal name and without temporary signals on the outside of the macro. 我想解决此问题,而无需在信号名称中添加其他输入,并且在宏外部也没有临时信号。

Is there some way to convert the output signal name with the index to a unique string... such as with $sformatf and then replace the index brackets with underscores? 是否有某种方法可以将带有索引的输出信号名称转换为唯一的字符串...例如使用$ sformatf,然后用下划线替换索引括号?

Or is there some other way to uniqify the signal name but keep it legal? 还是有其他方法可以使信号名称唯一化但保持其合法性? Something like atoi() to make it a unique number based off the signal name? 类似atoi()使其基于信号名称成为唯一数字吗?

You can escape the name to allow symbols in an identifier 您可以转义名称以允许在标识符中使用符号

`define BOB_STAGE(_BUS_IN, _BUS_OUT) \
   bob_module \auto_``_BUS_OUT``_bob_module ( .bus_in(_BUS_IN), .bus_out(_BUS_OUT) );

`BOB_STAGE( {A,B,C,D}, OUT[1] );

will become 会变成

bob_module \auto_OUT[1]_bob_module ( .bus_in(_BUS_IN), .bus_out(_BUS_OUT) );

This is really the limit of what you can do for creating identifiers in SystemVerilog. 这实际上是您在SystemVerilog中创建标识符所能做的限制。

You can add one more argument to the macro to solve the issue. 您可以在宏中再添加一个参数来解决该问题。

Your macro may look like this: 您的宏可能看起来像这样:

`define BOB_STAGE(_BUS_IN, _BUS_OUT, _NO) \
   bob_module auto_``_BUS_OUT``_``_NO``_bob_module ( .bus_in(_BUS_IN), .bus_out(_BUS_OUT[_NO]) );

Now your macro usage will look like this: 现在您的宏用法将如下所示:

`BOB_STAGE( {A,B,C,D}, OUT, 1 );

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

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