我試圖在System Verilog中對宏進行串聯處理,以便我可以在字符串中使用它進行打印。如何從具有參數的預處理器宏創建字符串
我創建了一個字符串化宏:
`define STRINGIFY(x) `"x`"
的建議在這裏: How to create a string from a pre-processor macro
不過,我試圖字符串化宏帶有參數。
考慮下面的代碼:
`define STRINGIFY(x) `"x`"
`define HPATH(signal) top.chip.block.signal
string hpath = `STRINGIFY(`HPATH(wire));
$display(hpath); // Output: "`HPATH(wire)"
我所要的輸出是 "top.chip.block.wire"
代替。
請注意,HPATH
宏需要參數wire
。
這是示例代碼運行在這裏:http://www.edaplayground.com/x/CKB
編輯: 的問題是`字符串化宏停止宏觀內的擴張當宏內部有爭論。 例如:
`define STRINGIFY(x) `"x`"
`define HPATH top.chip.block
`define HPATH_SIGNAL(signal) top.chip.block.signal
$display(`"`HPATH`"); // correctly outputs "top.chip.block"
$display(`STRINGIFY(`HPATH)); // correctly outputs "top.chip.block"
$display(`"`HPATH_SIGNAL(sig)`"); // correctly outputs "top.chip.block.sig"
$display(`STRINGIFY(`HPATH_SIGNAL(sig))); // incorrectly outputs "`HPATH_SIGNAL(sig)"
看來,`HPATH_SIGNAL(SIG)嵌套在`字符串化宏內部時沒有解決
的問題是,爲什麼在過去的擴大不是HPATH_SIGNAL(SIG)線?
這裏的示例代碼運行: http://www.edaplayground.com/x/RF2
嗯,我仍然想使用HPATH宏作爲分層路徑(不含引號)。自從我縮小這個問題之後,我會修改我的問題。 –