GHDL



 GHDLは、Tristan Gingoldさんが開発しているVHDLシミュレータです。ソースからインストールするには、AdaのコンパイルであるGNATが必要で、コンパイルに使うgccは、インストールするGHDLのバージョンによって異なります。Linux、Windows、MacOS Xでバイナリーインストーラがあります。ドキュメントはこちらです。波形は、GTKwaveで表示します。

1.GHDLが実行できるか確かめるために半加算器を例にして説明します。下記に半加算器のVHDL記述を示します。


library IEEE;
  use IEEE.std_logic_1164.all;

entity half_adder is port ( A, B : in std_logic; S, C : out std_logic ); end half_adder;
architecture STRUCTURE of half_adder is begin S <= A xor B; C <= A and B; end STRUCTURE;

これは回路モジュールなのでファイル名は何でもいいのですが halfadder.vhdlとします。(拡張子は、.vhdlか又は.vhdです。) 次にシュミレーションする為のテストベンチを作成します。


library IEEE;
  use IEEE.std_logic_1164.all;

entity tb_half_adder is end tb_half_adder;
architecture TESTBENCH of tb_half_adder is
component half_adder port ( A, B : in std_logic; S, C : out std_logic ); end component;
signal SA, SB, SS, SC : std_logic;
begin M1 : half_adder port map (SA, SB, SS, SC); P1 : process begin SA <= '0'; wait for 50 ns; SA <= '1'; wait for 50 ns; end process; P2 : process begin SB <= '0'; wait for 100 ns; SB <= '1'; wait for 100 ns; end process; end TESTBENCH;
configuration CFG_HA of tb_half_adder is for TESTBENCH end for; end CFG_HA;

このファイル名はtb_half_adder.vhdlとします。
ではghdlを走らせてみましょう。次のコマンドを順次入力していきます。


ghdl -a half_adder.vhdl tb_half_adder.vhdl

ghdl -e tb_half_adder

実行ファイルtb_half_adderができあがり再び入力します。


./tb_half_adder --stop-time=200ns --vcd=halfadder.vcd

入力後、画面に次のように表示されます。


./tb_half_adder:info: simulation stopped by --stop-time

次にhalfadder.vcdができているのでgtkwaveで表示させます。


gtkwave halfadder.vcd

ウインドウが開きます。SearchメニューのSignal Search Treeボタンをクリックして表示したいトレース波形を選んで下さい。一例ですが、下のような表示がされます。





2.GHDLは、foreign宣言でCプログラムを呼び出せます。例えば、以下のCプログラムを動作させてみます。ファイル名は、helloc.cとしています。


#include 
int helloc(void)
{
   printf ("Hello! C...\n");
   return 1;
}

次のようなVHDLファイルをhello_world.vhdlとして作成してみました。


package test is
  function helloc return integer;
  attribute foreign of helloc: function is
    "VHPIDIRECT helloc";
end test;

package body test is
  function helloc return integer is
  begin
    assert false severity failure;
  end helloc;
end test;

use std.textio.all;
use work.test.helloc;

entity hello_world is
end hello_world;

architecture beh of hello_world is
begin
  process
    variable l : line;
    variable v : integer;
  begin
    l := new string'("Hello! VHDL...");
    writeline (output,l);

    --invite to a function of C
    v:=helloc;
    wait;
  end process;
end beh;

Makefileを以下のように作ります。


GHDL=ghdl
CC=gcc

all: hello_world

hello_world: test.o helloc.o
	$(GHDL) -e -Wl,helloc.o hello_world 

test.o: hello_world.vhdl 
	$(GHDL) -a $<

clean:
	$(RM) -f hello_world *.o *.cf *~

makeすると、hello_worldの実行ファイルが出来上がります。./hello_worldと入力すると


Hello! VHDL...
Hello! C...

と表示されます。


(参考)
co-simulation
ghdl-simulation
ghdl-cosim
VHDL DPI