簡體   English   中英

使用宏在systemverilog中連接信號名稱

[英]Concatenate signal names in systemverilog using macro

我試圖在systemverilog / verilog中連接兩個字符串以創建信號名稱。 在我下面的代碼片段中,lhs方面似乎工作正常,但rhs方面卻沒有。 該工具給出錯誤“尚未聲明bitemp”。

如果我將硬編碼的值傳遞給“ clno”參數,請說“ 0”,那么它對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 / SystemVerilog語法之前,宏將得到擴展。 使用電線陣列。

由於定義會在編譯前擴展,因此您會遇到這些錯誤。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM