FPGA開発日記

カテゴリ別記事インデックス https://msyksphinz.github.io/github_pages , English Version https://fpgadevdiary.hatenadiary.com/

Verilatorの使い方(3. Lintとして活用する)

Verilatorは論理シミュレータだけではなく、Lintとしても活用することができる。例えばこれまで使用してきたcounter_4bit.vをLintに掛けてみよう。

$ verilator --lint-only -Wall counter_4bit.v
%Warning-DECLFILENAME: counter_4bit.v:1:8: Filename 'counter_4bit' does not match MODULE name: 'counter'
    1 | module counter
      |        ^~~~~~~
                       ... Use "/* verilator lint_off DECLFILENAME */" and lint_on around source to disable this message.
%Error: Exiting due to 1 warning(s)

いきなりエラー通知が出てきた。どうやらファイル名と中のモジュール名が一致しないようだ。確かにこれはVerilog記述の一般常識から外れている。。。エラーが消えるように修正する。

diff --git a/counter_4bit.v b/counter_4bit.v
index 9cbe73c..27e98e7 100644
--- a/counter_4bit.v
+++ b/counter_4bit.v
@@ -1,4 +1,4 @@
-module counter
+module counter_4bit
   (
    input logic        clk,
    input logic        reset_n,
@@ -14,4 +14,4 @@ always_ff @(posedge clk, negedge reset_n) begin
     end
   end
 end
-endmodule // counter
+endmodule // counter_4bit

これでLintを通すとエラーが無くなった。問題なさそうだ。