[Tools] Verilog-mode 用法整理 (usage collections)

上一篇文章已經說明如何安裝 Verilog-mode 在 Vim 內。
以下主要把常用的 Verilog-mode 自動接線技巧做整理。

1.   最基本的 verilog 自動接線使用方法如下:
module a(/*autoarg*/);

input a,b;
output c;

endmodule


也就是在小括號內,輸入 /*autoarg*/ 關鍵字,通過 Verilog-mode 處理後,a, b, c 會自動貼到小括號內的 port 上:
module a(/*autoarg*/

   // Outputs
   c,
   // Inputs
   a, b
   );

input a, b;
output c;

endmodule
其實這一直是我覺得 Verilog 語法比較多餘的地方,因為已經宣告成 IO 的訊號,再貼一次到小括號內,似乎增加 code 長度,顯得多餘。一般的程式語言,函式的 argument 都只宣告一次而已。

2.   宣告 instance,也能自動接線,使用的關鍵字為 /*autoinst*/:
module test;
a a_inst(/*autoinst*/);
endmodule
自動接線結果:

module test;
a a_inst(/*autoinst*/
  // Outputs
  .c    (c),
  // Inputs
  .a    (a),
  .b    (b));
endmodule
以上兩個就是最常用的自動接線。

3.   自動宣告 input 和 output:
假如在上述 test.v 內開頭寫:
/*autoinput*/
/*autooutput*/
則 Verilog-mode 處理結果:

module test;

/*autoinput*/
// Beginning of automatic inputs (from unused autoinst inputs)
input   a;   // To a_inst of a.v
input   b;   // To a_inst of a.v
// End of automatics
/*autooutput*/
// Beginning of automatic outputs (from unused autoinst outputs)
output   c;   // From a_inst of a.v
// End of automatics
a a_inst(/*autoinst*/
  // Outputs
  .c    (c),
  // Inputs
  .a    (a),
  .b    (b));

endmodule

4.   自動宣告 reg 和 wire:
在 test.v 開頭寫上:

/*autoreginput*/
/*autowire*/

Verilog-mode 處理完結果:
module test;

/*autoreginput*/
// Beginning of automatic reg inputs (for undeclared instantiated-module inputs)
reg   a;   // To a_inst of a.v
reg   b;   // To a_inst of a.v
// End of automatics
/*autowire*/
// Beginning of automatic wires (for undeclared instantiated-module outputs)
wire   c;   // From a_inst of a.v
// End of automatics

a a_inst(/*autoinst*/
  // Outputs
  .c    (c),
  // Inputs
  .a    (a),
  .b    (b));

endmodule
注意 /*autoinput*/ 會比 /*autoreginput*/ 更優先,因此兩關鍵字同時出現,只有 autoinput 會有效果。
同理 /*autooutput*/ 比 /*autowire*/ 更優先。但要注意,如果當前的 code 裡面有兩個子 module 分別叫 X 和 Y,X module 的某條 output (假設叫做 wire_a)接到 Y module 的 input,如此可以宣告 /*autowire*/,Verilog-mode 會自動宣告 wira_a 在 /*autowire*/ 的關鍵字下面,且此 wire_a 不受 /*autooutput*/ 關鍵字影響,此 wire 不會被 Verilog-mode 宣告成 output,也不會穿出當前 module 的外部。

5.   搜尋子 module 檔案路徑:
在 verilog code 結尾可以設定 Verilog-mode 要去哪裡尋找子 module 資訊:

....
endmodule
//Local Variables:
//verilog-library-directories:("." "./*/" "../")
//End:

6.   指定某些訊號跳過不處理,不要穿出 module 界面:
/*AUTO_LISP(setq verilog-auto-output-ignore-regexp
                           ( concat "signal_0"
                                    "\\|signal_1"
                                    "\\|signal_2"
))*/
這樣 signal_0, signal_1 和 signal_2 都不會被穿出 port。


留言

這個網誌中的熱門文章

[Env] Icarus Verilog(iverilog) + gtkwave 安裝與環境建立

[Env] Vim 安裝 Verilog-mode