LoginSignup
4
2

More than 1 year has passed since last update.

iverilog と verilisp を使う

Last updated at Posted at 2015-12-13

Icarus Verilog(iverilog) を簡単に cygwin で使えると聞いたので試しに使ってみることにしました。ついでに verilisp も使ってみます。

まずは cygwin(64bit) 上でコンパイル

Icarus Verilog のソースを github から clone します。

$ git clone git://github.com/steveicarus/iverilog.git

しかし、configure がありません。autoconf から実行しないといけないようです。ということで、cygwin でコンパイルするには次のものが必要でした。

  • autoconf
  • gperf
  • flex
  • bison

ついでに clisp もインストールしておきます(あとで verilisp で使うから)。autoconf は2種類あったのですが autoconf-2.69 なるものをつかってみました。違いは把握していません。

$ cd iverilog
$ autoconf-2.69
$ ls configure
configure
$ which iverilog
/usr/local/bin/iverilog

autoconf が必要だったものの意外と簡単にインストールできました。

ivtest でテスト

テストベンチも clone します。

$ cd ..
$ git clone git://github.com/steveicarus/ivtest.git
$ mkdir test
$ cd test

Hello World があったのでコンパイルして動作させてみます。

$ iverilog -o hello ../ivtest/ivltests/hello1.v
$ ls hello
hello
$ ./hello
$ ./hello
Hello, World.
PASSED

これも簡単にできました。順調です。

verilisp をもってくる。

ここからだんだん怪しい世界に入っていきます。
verilisp
以前はちゃんとしたホームページがあったのですが、今や残骸として code.google.com に残っているのみです。
そこで、ちょっと使えるように修正し始めました(2021年)
githbu 上の verilisp

verilisp は Common Lisp で動作する Verilog HDL の補助ツールです。S 式で書いたプログラムを Verilog HDL に落とすことが出来ます。

verilisp は一度 python で文字列変換した後に clisp を呼ぶようになっています。ここでは tests にある multiplier をコンパイルしてみます。拡張子がないので適当に vl という拡張子をつけます。lib も必要なのでコピーします。

$ cp ~/verilisp/tests/multiplier multiplier.vl
$ cp -rp ~/verilisp/lib .
$ ls
lib multiplier.vl
$ verilisp.py multiplier.vl
*** - read from #<input unbuffered file-stream character > #P"/dev/fd/0" @157>:
After ## is #\; an undefined dispatch macro character

コンパイルエラーです。S 式以外に検証用の verilog コードもくっついているのでエラーになります。66行以下を削除してもう一度コンパイル。

$ ls
lib multiplier.v multiplier.vl

見事に multiplier.v ができました。といいたいところですが、iverilog を通りません。

$ iverilog -o multiplier multiplier.v
multiplier.v:109: error: Wrong number of ports. Expecting 5, got 3.
1 error(s) during elaboration.

記述に間違いがあるようです。以下パッチ

--- multiplier.vl       2015-12-13 23:30:45.402498100 +0900
+++ multiplier-ok.vl       2015-12-13 22:46:00.471913900 +0900
@@ -34,7 +34,9 @@
         (module test_mul ()
             (reg (,WORDSIZE a b))
             (wire (,(l_* WORDSIZE 2) out))
-            (mul out a b)
+            (wire overflow)
+            (wire signed_)
+            (mul out overflow a b signed_)
             (dump "test.vcd")
             (initial
                 (delay 10000 nil)

ソースを修正して再度コンパイル。

$ verilisp.py multiplier.vl
$ iverilog -o multiplier multiplier.v
$ ls
lib multiplier multiplier.v multiplier.vl

実行してみます。

$ ./multiplier
VCD info: dumpfile test.vcd opened for output.
0011 0
good: 0 * 0 = 0 :: 0000 * 0000 = 00000000
good: 0 * 1 = 0 :: 0000 * 0001 = 00000000
good: 0 * 2 = 0 :: 0000 * 0010 = 00000000
結果中略
good: 14 * 14 = 196 :: 1110 * 1110 = 11000100
good: 14 * 15 = 210 :: 1110 * 1111 = 11010010
good: 15 * 15 = 225 :: 1111 * 1111 = 11100001

どうやらうまくいったようです。
これで cygwin 上で Verilog HDL のテスト環境だけでなく怪しい Common Lisp でのメタプログラミング(?)環境を手に入れることが出来ました。

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2