diff options
author | Tristan Gingold <tgingold@free.fr> | 2022-08-05 07:24:08 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2022-08-07 10:00:11 +0200 |
commit | 23b3cadc1c6b96928f3d0829f8b0c5b7337fcc9c (patch) | |
tree | 0571afd98a0bce44d213d390417ae96f7d887f66 | |
parent | 07746787b84a99fdfdc240cacd4696bc66d562c2 (diff) | |
download | ghdl-23b3cadc1c6b96928f3d0829f8b0c5b7337fcc9c.tar.gz ghdl-23b3cadc1c6b96928f3d0829f8b0c5b7337fcc9c.tar.bz2 ghdl-23b3cadc1c6b96928f3d0829f8b0c5b7337fcc9c.zip |
testsuite/gna: add a test for #2156
-rw-r--r-- | testsuite/gna/issue2156/tb_to_string_overloading.vhdl | 17 | ||||
-rwxr-xr-x | testsuite/gna/issue2156/testsuite.sh | 16 | ||||
-rw-r--r-- | testsuite/gna/issue2156/timing_pkg.vhdl | 46 | ||||
-rw-r--r-- | testsuite/gna/issue2156/timing_pkg2.vhdl | 51 |
4 files changed, 130 insertions, 0 deletions
diff --git a/testsuite/gna/issue2156/tb_to_string_overloading.vhdl b/testsuite/gna/issue2156/tb_to_string_overloading.vhdl new file mode 100644 index 000000000..17e911f19 --- /dev/null +++ b/testsuite/gna/issue2156/tb_to_string_overloading.vhdl @@ -0,0 +1,17 @@ +use work.timing_pkg.all; + +entity tb_to_string_overloading is +end entity; + +architecture tb of tb_to_string_overloading is + constant freq : frequency := 40.0e6; +begin + + process + begin + --report to_string(freq, ""); + report to_string(freq); + wait; + end process; + +end architecture; diff --git a/testsuite/gna/issue2156/testsuite.sh b/testsuite/gna/issue2156/testsuite.sh new file mode 100755 index 000000000..0bab2bc7f --- /dev/null +++ b/testsuite/gna/issue2156/testsuite.sh @@ -0,0 +1,16 @@ +#! /bin/sh + +. ../../testenv.sh + +export GHDL_STD_FLAGS=--std=08 +analyze timing_pkg.vhdl +analyze_failure tb_to_string_overloading.vhdl + +clean + +analyze timing_pkg2.vhdl +analyze_failure tb_to_string_overloading.vhdl + +clean + +echo "Test successful" diff --git a/testsuite/gna/issue2156/timing_pkg.vhdl b/testsuite/gna/issue2156/timing_pkg.vhdl new file mode 100644 index 000000000..ab00651e5 --- /dev/null +++ b/testsuite/gna/issue2156/timing_pkg.vhdl @@ -0,0 +1,46 @@ +package timing_pkg is + + type frequency is range 0.0 to real'high; + + function to_string( + freq : frequency; + unit : string := ""; + fmt : string := "%.6f") + return string; + +end package; + +package body timing_pkg is + + function to_string( + freq : frequency; + unit : string := ""; + fmt : string := "%.6f") + return string + is + begin + if unit = "" then + if freq < 1.0e3 then + return to_string(real(freq), fmt) & " Hz"; + elsif 1.0e3 <= freq and freq < 1.0e6 then + return to_string(real(freq) * 1.0e-3, fmt) & " kHz"; + elsif 1.0e6 <= freq and freq < 1.0e9 then + return to_string(real(freq) * 1.0e-6, fmt) & " MHz"; + else + return to_string(real(freq) * 1.0e-9, fmt) & " GHz"; + end if; + elsif unit = "Hz" then + return to_string(real(freq), fmt) & " Hz"; + elsif unit = "kHz" then + return to_string(real(freq) * 1.0e-3, fmt) & " kHz"; + elsif unit = "MHz" then + return to_string(real(freq) * 1.0e-6, fmt) & " MHz"; + elsif unit = "GHz" then + return to_string(real(freq) * 1.0e-9, fmt) & " GHz"; + else + report "invalid frequency unit (Hz, kHz, MHz, GHz)" + severity failure; + end if; + end function; + +end package body; diff --git a/testsuite/gna/issue2156/timing_pkg2.vhdl b/testsuite/gna/issue2156/timing_pkg2.vhdl new file mode 100644 index 000000000..e04acad99 --- /dev/null +++ b/testsuite/gna/issue2156/timing_pkg2.vhdl @@ -0,0 +1,51 @@ +package timing_pkg is + + type frequency is range 0.0 to real'high; + + function to_string( + freq : frequency; + unit : string := ""; + fmt : string := "%.6f") + return string; + + function to_string(value: frequency) return string; +end package; + +package body timing_pkg is + + function to_string( + freq : frequency; + unit : string := ""; + fmt : string := "%.6f") + return string + is + begin + if unit = "" then + if freq < 1.0e3 then + return to_string(real(freq), fmt) & " Hz"; + elsif 1.0e3 <= freq and freq < 1.0e6 then + return to_string(real(freq) * 1.0e-3, fmt) & " kHz"; + elsif 1.0e6 <= freq and freq < 1.0e9 then + return to_string(real(freq) * 1.0e-6, fmt) & " MHz"; + else + return to_string(real(freq) * 1.0e-9, fmt) & " GHz"; + end if; + elsif unit = "Hz" then + return to_string(real(freq), fmt) & " Hz"; + elsif unit = "kHz" then + return to_string(real(freq) * 1.0e-3, fmt) & " kHz"; + elsif unit = "MHz" then + return to_string(real(freq) * 1.0e-6, fmt) & " MHz"; + elsif unit = "GHz" then + return to_string(real(freq) * 1.0e-9, fmt) & " GHz"; + else + report "invalid frequency unit (Hz, kHz, MHz, GHz)" + severity failure; + end if; + end function; + + function to_string(value: frequency) return string is + begin + return to_string(value, "", "%.6f"); + end function; +end package body; |