pretty code

2025年3月10日 星期一

bash script 的框架

今天為了解一個小 bug,花了我快 40 分鐘。

雖然早就知道 local 的用法,但今天沒有意會到之前寫的程式沒有在函數中的參數加上 local 修飾字,導致我不小心改到外面的全域變數,難怪看了快 40 分鐘才找到問題。

我覺得,即使是 bash script,最好還是要用 main 函數並在所有的函數中都使用 local 關鍵字修飾變數,這樣就不會誤改到全域變數了。

下面是示意圖,Line 13 就是忘了加 local 導致改到全域變數了,這也是我今天耍笨的地方。

2025年3月7日 星期五

Verilog $value$plusargs

平常用 iverilog 時,最常使用的是 -D 選項,此選項是 for 編譯時期使用。

如果我們想要在 simulation 時期傳遞參數,就必須使用 Verilog-2001 新增的語法 $value$plusargs

既然是 simulation 時期,故必須在模擬時傳遞參數,也就是需要傳遞參數給 vvp 這支程式。

module TB;
reg[512*8:1] _new_path;
initial begin
if ($value$plusargs("NEWPATH=%s", _new_path)) begin
$display("%0s", _new_path);
end
else begin
$display("No NEWPATH");
end
end
endmodule

vvp -n test.vcd +NEWPATH="XXXXX"