diff options
author | Tristan Gingold <tgingold@free.fr> | 2022-06-16 05:42:06 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2022-06-16 05:42:06 +0200 |
commit | 78b32ad57f7ed510f25954e0bd93cd649fa8a1b8 (patch) | |
tree | f3e6c854a30148f3b986dee8a428bfce221071d2 /testsuite/gna/issue2097 | |
parent | 4e816c37af61b6c6dc0a13020a189bc3d8d7dc39 (diff) | |
download | ghdl-78b32ad57f7ed510f25954e0bd93cd649fa8a1b8.tar.gz ghdl-78b32ad57f7ed510f25954e0bd93cd649fa8a1b8.tar.bz2 ghdl-78b32ad57f7ed510f25954e0bd93cd649fa8a1b8.zip |
testsuite/gna: add a test for #2097
Diffstat (limited to 'testsuite/gna/issue2097')
-rw-r--r-- | testsuite/gna/issue2097/my_fixed_pkg.vhdl | 7 | ||||
-rw-r--r-- | testsuite/gna/issue2097/tb_fixed.vhdl | 55 | ||||
-rw-r--r-- | testsuite/gna/issue2097/tb_fixed1.vhdl | 43 | ||||
-rw-r--r-- | testsuite/gna/issue2097/tb_fixed2.vhdl | 43 | ||||
-rw-r--r-- | testsuite/gna/issue2097/tb_fixed3.vhdl | 43 | ||||
-rwxr-xr-x | testsuite/gna/issue2097/testsuite.sh | 18 |
6 files changed, 209 insertions, 0 deletions
diff --git a/testsuite/gna/issue2097/my_fixed_pkg.vhdl b/testsuite/gna/issue2097/my_fixed_pkg.vhdl new file mode 100644 index 000000000..eee9cde50 --- /dev/null +++ b/testsuite/gna/issue2097/my_fixed_pkg.vhdl @@ -0,0 +1,7 @@ +library IEEE; +context IEEE.IEEE_std_context; + +package my_fixed_pkg is new IEEE.fixed_generic_pkg; + +--! + diff --git a/testsuite/gna/issue2097/tb_fixed.vhdl b/testsuite/gna/issue2097/tb_fixed.vhdl new file mode 100644 index 000000000..658026dae --- /dev/null +++ b/testsuite/gna/issue2097/tb_fixed.vhdl @@ -0,0 +1,55 @@ +library IEEE; +context IEEE.IEEE_std_context; + +package my_fixed_pkg is new IEEE.fixed_generic_pkg; + +--! + +library IEEE; +context IEEE.IEEE_std_context; + +library work; +use work.my_fixed_pkg.all; + +entity tb_fixed is +end; + +architecture arch of tb_fixed is + +begin + + process + constant ref : real := -9.96484375; + + subtype stype is sfixed(7 downto -8); + + -- Subtype not allowed as size_res argument of to_sfixed: + -- constant input : std_logic_vector (stype'length-1 downto 0) := to_slv(to_sfixed(ref, stype)); + -- Therefore, a variable needs to be created: + variable fmt : stype; + constant input : std_logic_vector (stype'length-1 downto 0) := to_slv(to_sfixed(ref, fmt)); + + variable sfmt : fmt'subtype; + + procedure report_sfixed(arg: sfixed) is begin report to_string(to_real(arg)); end procedure; + + begin + report_sfixed(stype(input)); + report_sfixed(stype(signed(input))); + + -- CRASH + report_sfixed(fmt'subtype(input)); + -- CRASH + report_sfixed(fmt'subtype(signed(input))); + + -- CRASH + report to_string(fmt'subtype); + + -- However, sfmt, which is declared using fmt'subtype, does work + sfmt := stype(input); + report_sfixed(sfmt); + + wait; + end process; + +end; diff --git a/testsuite/gna/issue2097/tb_fixed1.vhdl b/testsuite/gna/issue2097/tb_fixed1.vhdl new file mode 100644 index 000000000..1a2d02c6f --- /dev/null +++ b/testsuite/gna/issue2097/tb_fixed1.vhdl @@ -0,0 +1,43 @@ +library IEEE; +context IEEE.IEEE_std_context; + +library work; +use work.my_fixed_pkg.all; + +entity tb_fixed1 is +end; + +architecture arch of tb_fixed1 is + +begin + + process + constant ref : real := -9.96484375; + + subtype stype is sfixed(7 downto -8); + + -- Subtype not allowed as size_res argument of to_sfixed: + -- constant input : std_logic_vector (stype'length-1 downto 0) := to_slv(to_sfixed(ref, stype)); + -- Therefore, a variable needs to be created: + variable fmt : stype; + constant input : std_logic_vector (stype'length-1 downto 0) := to_slv(to_sfixed(ref, fmt)); + + variable sfmt : fmt'subtype; + + procedure report_sfixed(arg: sfixed) is begin report to_string(to_real(arg)); end procedure; + + begin + report_sfixed(stype(input)); + report_sfixed(stype(signed(input))); + + -- CRASH + report_sfixed(fmt'subtype(input)); + + -- However, sfmt, which is declared using fmt'subtype, does work + sfmt := stype(input); + report_sfixed(sfmt); + + wait; + end process; + +end; diff --git a/testsuite/gna/issue2097/tb_fixed2.vhdl b/testsuite/gna/issue2097/tb_fixed2.vhdl new file mode 100644 index 000000000..777718f21 --- /dev/null +++ b/testsuite/gna/issue2097/tb_fixed2.vhdl @@ -0,0 +1,43 @@ +library IEEE; +context IEEE.IEEE_std_context; + +library work; +use work.my_fixed_pkg.all; + +entity tb_fixed2 is +end; + +architecture arch of tb_fixed2 is + +begin + + process + constant ref : real := -9.96484375; + + subtype stype is sfixed(7 downto -8); + + -- Subtype not allowed as size_res argument of to_sfixed: + -- constant input : std_logic_vector (stype'length-1 downto 0) := to_slv(to_sfixed(ref, stype)); + -- Therefore, a variable needs to be created: + variable fmt : stype; + constant input : std_logic_vector (stype'length-1 downto 0) := to_slv(to_sfixed(ref, fmt)); + + variable sfmt : fmt'subtype; + + procedure report_sfixed(arg: sfixed) is begin report to_string(to_real(arg)); end procedure; + + begin + report_sfixed(stype(input)); + report_sfixed(stype(signed(input))); + + -- CRASH + report_sfixed(fmt'subtype(signed(input))); + + -- However, sfmt, which is declared using fmt'subtype, does work + sfmt := stype(input); + report_sfixed(sfmt); + + wait; + end process; + +end; diff --git a/testsuite/gna/issue2097/tb_fixed3.vhdl b/testsuite/gna/issue2097/tb_fixed3.vhdl new file mode 100644 index 000000000..839930710 --- /dev/null +++ b/testsuite/gna/issue2097/tb_fixed3.vhdl @@ -0,0 +1,43 @@ +library IEEE; +context IEEE.IEEE_std_context; + +library work; +use work.my_fixed_pkg.all; + +entity tb_fixed is +end; + +architecture arch of tb_fixed is + +begin + + process + constant ref : real := -9.96484375; + + subtype stype is sfixed(7 downto -8); + + -- Subtype not allowed as size_res argument of to_sfixed: + -- constant input : std_logic_vector (stype'length-1 downto 0) := to_slv(to_sfixed(ref, stype)); + -- Therefore, a variable needs to be created: + variable fmt : stype; + constant input : std_logic_vector (stype'length-1 downto 0) := to_slv(to_sfixed(ref, fmt)); + + variable sfmt : fmt'subtype; + + procedure report_sfixed(arg: sfixed) is begin report to_string(to_real(arg)); end procedure; + + begin + report_sfixed(stype(input)); + report_sfixed(stype(signed(input))); + + -- CRASH + report to_string(fmt'subtype); + + -- However, sfmt, which is declared using fmt'subtype, does work + sfmt := stype(input); + report_sfixed(sfmt); + + wait; + end process; + +end; diff --git a/testsuite/gna/issue2097/testsuite.sh b/testsuite/gna/issue2097/testsuite.sh new file mode 100755 index 000000000..922abea62 --- /dev/null +++ b/testsuite/gna/issue2097/testsuite.sh @@ -0,0 +1,18 @@ +#! /bin/sh + +. ../../testenv.sh + +export GHDL_STD_FLAGS=--std=08 +analyze my_fixed_pkg.vhdl + +analyze tb_fixed1.vhdl +elab_simulate tb_fixed1 + +analyze tb_fixed2.vhdl +elab_simulate tb_fixed2 + +analyze_failure tb_fixed3.vhdl + +clean + +echo "Test successful" |