2017-10-12 172 views
0

我想連接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

回答

1

宏在解析任何Verilog/SystemVerilog語法之前得到擴展。使用一組電線。

+0

感謝戴夫的快速反應。不幸的是,「rhs」是一個DUT信號,它不是一個數組。你知道我能做到這一點嗎? – rtmot

+0

我覺得如果你需要使用本地語法,你就會陷入困境。如果你願意去vpp路線,你可以實現你要找的東西。現在很難找到鏈接(這是舊的東西),但似乎在https://github.com/balanx/vbpp –

+0

,它似乎有一個(有點)保持版本在你的例子模塊沒有端口。所有的「臨時」都是模塊的內部。它在現實中看起來如何?另外,你的循環只有3次迭代。是這個嗎? – Serge

0

由於`定義在編譯之前展開,因此您會收到這些錯誤。

避免這種情況的一種方法是使用腳本來自動定義使用情況,並在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