使用宏在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
答
由于`定义在编译之前展开,因此您会收到这些错误。
避免这种情况的一种方法是使用脚本来自动定义使用情况,并在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
膨胀后的宏将看起来像这样:'分配aitemp =双温;'它将代替lhs_poststr和rhs_poststr的替代'temp',I,a和b将被替换为其他部分。所以,你需要一个不同的方案。 – Serge