使用宏在systemverilog中连接信号名称

使用宏在systemverilog中连接信号名称

问题描述:

我想连接systemverilog/verilog中的两个字符串来创建信号名称。 在我的下面的代码片段中,lhs方似乎工作正常,但rhs方面没有。 该工具给出错误“bitemp尚未声明”。使用宏在systemverilog中连接信号名称

如果我通过一个hardcorded值说“0”为“clno”参数,那么它适用于lhs和rhs。

enter code here 
`define strcat_assign_macro(lhs_prestr,lhs_poststr,rhs_prestr,rhs_poststr,clno) \ 
assign lhs_prestr``clno``lhs_poststr = rhs_prestr``clno``rhs_poststr; 

module tempmod; 
    wire a0temp,b0temp; 
    wire a1temp,b1temp; 
    wire a2temp,b2temp; 

    assign b0temp =1'b1; 

    genvar i; 
    generate 
    for(i = 0; i < 3; i++) 
    begin 
     `strcat_assign_macro(a,temp,b,temp,i) 
    end 
    endgenerate 


    initial begin 
    $display (a0temp); 
    end 

endmodule 
+0

膨胀后的宏将看起来像这样:'分配aitemp =双温;'它将代替lhs_poststr和rhs_poststr的替代'temp',I,a和b将被替换为其他部分。所以,你需要一个不同的方案。 – Serge

宏在解析任何Verilog/SystemVerilog语法之前得到扩展。使用一组电线。

+0

感谢戴夫的快速反应。不幸的是,“rhs”是一个DUT信号,它不是一个数组。你知道我能做到这一点吗? – rtmot

+0

我觉得如果你需要使用本地语法,你就会陷入困境。如果你愿意去vpp路线,你可以实现你要找的东西。现在很难找到链接(这是旧的东西),但似乎在https://github.com/balanx/vbpp –

+0

,它似乎有一个(有点)保持版本在你的例子模块没有端口。所有的“临时”都是模块的内部。它在现实中看起来如何?另外,你的循环只有3次迭代。是这个吗? – Serge

由于`定义在编译之前展开,因此您会收到这些错误。

避免这种情况的一种方法是使用脚本来自动定义使用情况,并在Verilog文件中使用相同的定义。

这里是一个示例shell脚本,我已经为此做了这个。这是一个基本的脚本,但我认为足以让你的想法。

#!/bin/csh 

set b='`' 
set a=`egrep -n "^ *${b}strcat_assign_macro" $2 | cut -d: -f1` 
set line=`egrep -n "${b}strcat_assign_macro" $2 | cut -d: -f2` 

foreach i (`seq $1`) 
    set c=`expr $a + $i` 
    sed -i "${c}i${line}" temp.ip 
    sed -i "${c}s/^\(.*\), *[0-9]* *)/\1, ${i})/g" temp.ip 
end 

这是&之后的文件。

// Before 
karan 
shah 
    `strcat_assign_macro(b, temp, a, temp, 0) 
maheshbhai 

// ./temp.sh <Extra Define Lines> <FileName> 
./temp.sh 2 input.v 

// After 
karan 
shah 
    `strcat_assign_macro(b, temp, a, temp, 0) 
`strcat_assign_macro(b, temp, a, temp, 1) 
`strcat_assign_macro(b, temp, a, temp, 2) 
maheshbhai