From c31485ff2c32f2aaf6e00e3447be2783a49bd71e Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Mon, 24 Dec 2018 07:23:08 +0100 Subject: Add testcase for #718 --- testsuite/gna/issue718/bug_repro.vhdl | 67 +++++++++++++++++++++++++++++++++++ testsuite/gna/issue718/rom.txt | 4 +++ testsuite/gna/issue718/testsuite.sh | 11 ++++++ 3 files changed, 82 insertions(+) create mode 100644 testsuite/gna/issue718/bug_repro.vhdl create mode 100644 testsuite/gna/issue718/rom.txt create mode 100755 testsuite/gna/issue718/testsuite.sh (limited to 'testsuite/gna') diff --git a/testsuite/gna/issue718/bug_repro.vhdl b/testsuite/gna/issue718/bug_repro.vhdl new file mode 100644 index 000000000..30fcc4a58 --- /dev/null +++ b/testsuite/gna/issue718/bug_repro.vhdl @@ -0,0 +1,67 @@ +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; +use ieee.numeric_std_unsigned.all; +use std.textio.all; + +package rom is + generic ( + word_bits: positive; + address_bits: positive; + rom_filename: string + ); + + subtype word_type is std_logic_vector(word_bits-1 downto 0); + + impure function read_at(address: in integer range 0 to 2**address_bits-1) return word_type; +end package rom; + +package body rom is + + impure function read_at( + address: in integer range 0 to 2**address_bits-1 + ) return word_type is + type rom_type is array(0 to 2**address_bits-1) of word_type; + + impure function init_rom_from_file (filename: in string) return rom_type is + file rom_file: text; + variable file_line : line; + variable rom_array: rom_type; + begin + file_open(rom_file, filename, read_mode); + for i in rom_type'range loop + readline(rom_file, file_line); + read(file_line, rom_array(i)); + end loop; + file_close(rom_file); + return rom_array; + end function; + constant rom_array: rom_type := init_rom_from_file(rom_filename); + begin + return rom_array(address); + end function read_at; +end package body rom; + +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; +use ieee.numeric_std_unsigned.all; +use std.textio.all; + +entity test is +end test; + +architecture dataflow of test is + package p is new work.rom generic map( + word_bits => 2, + address_bits => 2, + rom_filename => "rom.txt" + ); + + signal word: std_logic_vector(1 downto 0); +begin + process (all) + begin + word <= p.read_at(0); + end process; +end dataflow; diff --git a/testsuite/gna/issue718/rom.txt b/testsuite/gna/issue718/rom.txt new file mode 100644 index 000000000..22c8c838b --- /dev/null +++ b/testsuite/gna/issue718/rom.txt @@ -0,0 +1,4 @@ +01 +00 +10 +11 diff --git a/testsuite/gna/issue718/testsuite.sh b/testsuite/gna/issue718/testsuite.sh new file mode 100755 index 000000000..608340a12 --- /dev/null +++ b/testsuite/gna/issue718/testsuite.sh @@ -0,0 +1,11 @@ +#! /bin/sh + +. ../../testenv.sh + +export GHDL_STD_FLAGS=--std=08 +analyze bug_repro.vhdl +elab_simulate test + +clean + +echo "Test successful" -- cgit v1.2.3