aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2022-08-11 21:31:46 +0200
committerTristan Gingold <tgingold@free.fr>2022-08-11 21:31:46 +0200
commitf6968a23424563d08494347bfab6d9b5ef9a2d55 (patch)
treef83cc2631d29727497f5c26733139c6d284ee263 /testsuite
parent19689779317783c8d44e41111e73ed37c6307dd6 (diff)
downloadghdl-f6968a23424563d08494347bfab6d9b5ef9a2d55.tar.gz
ghdl-f6968a23424563d08494347bfab6d9b5ef9a2d55.tar.bz2
ghdl-f6968a23424563d08494347bfab6d9b5ef9a2d55.zip
testsuite/gna: add tests for #2175
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/gna/issue2175/pkg.vhdl85
-rw-r--r--testsuite/gna/issue2175/tb2.vhdl27
-rw-r--r--testsuite/gna/issue2175/tb3.vhdl47
-rwxr-xr-xtestsuite/gna/issue2175/testsuite.sh17
4 files changed, 176 insertions, 0 deletions
diff --git a/testsuite/gna/issue2175/pkg.vhdl b/testsuite/gna/issue2175/pkg.vhdl
new file mode 100644
index 000000000..7cea1f9f3
--- /dev/null
+++ b/testsuite/gna/issue2175/pkg.vhdl
@@ -0,0 +1,85 @@
+library ieee;
+use ieee.std_logic_1164.all;
+
+package pkg is
+
+ type sulv_vector is array (natural range <>) of std_ulogic_vector;
+
+ subtype NULL_RANGE is natural range 0 downto 1;
+ constant NULL_SULV : std_ulogic_vector(NULL_RANGE) := (others => '0');
+ constant NULL_SULV_VECTOR : sulv_vector(NULL_RANGE)(NULL_RANGE) := (others => NULL_SULV);
+
+ function repeat(
+ val : std_ulogic;
+ n : natural
+ ) return std_ulogic_vector;
+
+ function repeat(
+ val : std_ulogic_vector;
+ m : natural
+ ) return sulv_vector;
+
+ function align_left(
+ vec : std_ulogic_vector;
+ len : positive;
+ pad : std_ulogic := '0'
+ ) return std_ulogic_vector;
+
+end package;
+
+package body pkg is
+
+ function repeat(
+ val : std_ulogic;
+ n : natural)
+ return std_ulogic_vector
+ is
+ begin
+ if n = 0 then
+ return NULL_SULV;
+ else
+ return (n - 1 downto 0 => val);
+ end if;
+ end function;
+
+ function repeat(
+ val : std_ulogic_vector;
+ m : natural
+ ) return sulv_vector
+ is
+ begin
+ if m = 0 then
+ return NULL_SULV_VECTOR;
+ else
+ return (m - 1 downto 0 => val);
+ end if;
+ end function;
+
+-- function repeat(
+-- val : std_ulogic_vector;
+-- m : natural
+-- ) return sulv_vector
+-- is
+-- constant result : sulv_vector(m downto 1)(val'range) := (others => val);
+-- begin
+-- return result;
+-- end function;
+
+ function align_left(
+ vec : std_ulogic_vector;
+ len : positive;
+ pad : std_ulogic := '0')
+ return std_ulogic_vector
+ is
+ constant diff : integer := len - vec'length;
+ alias v : std_ulogic_vector(vec'length - 1 downto 0) is vec;
+ variable result : std_ulogic_vector(len - 1 downto 0);
+ begin
+ assert diff >= 0
+ report "align_left: cannot align larger vector into smaller vector"
+ severity failure;
+ result := (v, repeat(pad, diff));
+ return result;
+ end function;
+
+end package body;
diff --git a/testsuite/gna/issue2175/tb2.vhdl b/testsuite/gna/issue2175/tb2.vhdl
new file mode 100644
index 000000000..482d92acd
--- /dev/null
+++ b/testsuite/gna/issue2175/tb2.vhdl
@@ -0,0 +1,27 @@
+library ieee;
+use ieee.std_logic_1164.all;
+
+entity tb2 is
+end;
+
+architecture behav of tb2 is
+ type sulv_vector is array (natural range <>) of std_ulogic_vector;
+
+ function repeat(
+ val : std_ulogic_vector;
+ m : natural
+ ) return sulv_vector
+ is
+ constant result : sulv_vector(m downto 1)(val'range) := (others => val);
+ begin
+ return result;
+ end function;
+begin
+ process
+ constant c : sulv_vector := repeat ("0101", 2);
+ begin
+ assert c(2) = x"5";
+ assert c(1) = "0101";
+ wait;
+ end process;
+end behav;
diff --git a/testsuite/gna/issue2175/tb3.vhdl b/testsuite/gna/issue2175/tb3.vhdl
new file mode 100644
index 000000000..b5428d782
--- /dev/null
+++ b/testsuite/gna/issue2175/tb3.vhdl
@@ -0,0 +1,47 @@
+library ieee;
+use ieee.std_logic_1164.all;
+
+package pkg2 is
+
+ type sulv_vector is array (natural range <>) of std_ulogic_vector;
+
+ subtype NULL_RANGE is natural range 0 downto 1;
+ constant NULL_SULV : std_ulogic_vector(NULL_RANGE) := (others => '0');
+ constant NULL_SULV_VECTOR : sulv_vector(NULL_RANGE)(NULL_RANGE) := (others => NULL_SULV);
+
+ function repeat(
+ val : std_ulogic_vector;
+ m : natural
+ ) return sulv_vector;
+end package;
+
+package body pkg2 is
+ function repeat(
+ val : std_ulogic_vector;
+ m : natural
+ ) return sulv_vector
+ is
+ constant result : sulv_vector(m downto 1)(val'range) := (others => val);
+ begin
+ return result;
+ end function;
+
+end package body;
+
+library ieee;
+use ieee.std_logic_1164.all;
+use work.pkg2.all;
+
+entity tb3 is
+end;
+
+architecture behav of tb3 is
+begin
+ process
+ constant c : sulv_vector := repeat ("0101", 2);
+ begin
+ assert c(2) = x"5";
+ assert c(1) = "0101";
+ wait;
+ end process;
+end behav;
diff --git a/testsuite/gna/issue2175/testsuite.sh b/testsuite/gna/issue2175/testsuite.sh
new file mode 100755
index 000000000..7c2d94bff
--- /dev/null
+++ b/testsuite/gna/issue2175/testsuite.sh
@@ -0,0 +1,17 @@
+#! /bin/sh
+
+. ../../testenv.sh
+
+export GHDL_STD_FLAGS=--std=08
+
+analyze_failure pkg.vhdl
+
+analyze tb2.vhdl
+elab_simulate tb2
+
+analyze tb3.vhdl
+elab_simulate tb3
+
+clean
+
+echo "Test successful"