新千葉 ガーベージ・コレクション

FPGA マガジンやインターフェースで書けなかったこと等をちょぼちょぼ書いてます。@ryos36

ghdl で ieee 2008

ghdl で numeric_std を使う方法。

結論から書くと --std=08 を使う。

ghdl のライブラリの下の list は次の通り。

ieee/      Makefile.inc  README       std/       vital2000/
ieee2008/  mentor/       redist1164/  synopsys/  vital95/

普通に ghdl xxx_tb.vhdl とかすると ieee が利用される。ieee の下はこんな感じ。わかりやすいように body を省いてある

math_complex.vhdl
math_real.vhdl
numeric_bit.vhdl
numeric_std.vhdl
std_logic_1164.vhdl

numeric_std はある。なので、次の簡単な test bench のコンパイルが通りそうなものだ

library IEEE, std;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
use std.textio.all;

entity text_io_example is
end text_io_example;

architecture beh of text_io_example is
    signal v : std_logic_vector(5 downto 0);
begin
    process is
    variable line0 : line;
    variable c : std_logic;
    begin
        c := '0';
        write(line0, c);
        writeline(output, line0);
        v <= v - 1;
        wait;
    end process;
end beh;

しかし、結果はコンパイルエラー

test_tb.vhdl:19:14: cannot resolve overloading for subprogram call
test_tb.vhdl:21:16: no function declarations for operator "-"
ghdl: compilation error

write に合致した方がないのと、- という関数が定義されていないことが問題。ソースの中身見ると

  function "-" (L: SIGNED; R: INTEGER) return SIGNED;

とかあって、ありそうなんだけどないと言われる。じゃ integer は通るのかな?

    signal i : integer;
....
        i <= i - 1;

これは通ったりするのでやっぱり定義が足りていないのでしょう。ieee のソースは 1995 年のそのまま純粋に使っているようなので当時はなかったのかもしれない。--ieee=synopsys とかすると synopsys が用意した ieee を使うこともできる。

> ls -1 =3/synopsys/
std_logic_arith.vhdl
std_logic_misc.vhdl
std_logic_misc-body.vhdl
std_logic_signed.vhdl
std_logic_textio.vhdl
std_logic_unsigned.vhdl

しかし、今度は numeric_std がないぜ。これを解決しようとすると ieee2008 を使う必要があるみたい。指定方法は --std=08 のようだ。--ieee=2008 じゃない。

> ghdl -i --ieee=synopsys test_tb.vhdl
> ghdl -i --ieee=2008 test_tb.vhdl
ghdl: unknown option '--ieee=2008' for command '-i'
> ghdl -i --std=08 test_tb.vhdl
> ghdl -a --std=08 test_tb.vhdl
test_tb.vhdl:22:16: no function declarations for operator "-"

おーっとやっぱり operator がない。しかし ieee2008 はファイルが増えている。

> ls -1 =3/ieee2008/ | grep -v body
fixed_float_types.vhdl
fixed_generic_pkg.vhdl
fixed_pkg.vhdl
float_generic_pkg.vhdl
float_pkg.vhdl
ieee_bit_context.vhdl
ieee_std_context.vhdl
math_complex.vhdl
math_real.vhdl
numeric_bit.vhdl
numeric_bit_unsigned.vhdl
numeric_std.vhdl
numeric_std_unsigned.vhdl
std_logic_1164.vhdl
std_logic_textio.vhdl

std_logic_vector 用の - の operator は numeric_std_unsigned にあるみたい。write はstd_logic_textio にある。

で結局うまくコンパイルするには次のようにする。

> cat test_tb.vhdl
library IEEE, std;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
use IEEE.numeric_std_unsigned.all;
use IEEE.std_logic_textio.all;
use std.textio.all;

entity text_io_example is
end text_io_example;

architecture beh of text_io_example is
    signal v : std_logic_vector(5 downto 0);
    signal i : integer;
begin
    process is
    variable line0 : line;
    variable c : std_logic;
    begin
        c := '0';
        write(line0, c);
        writeline(output, line0);
        v <= v - 1;
        i <= i - 1;
        wait;
    end process;
end beh;
> ghdl -a --std=08 test_tb.vhdl