From 23b3cadc1c6b96928f3d0829f8b0c5b7337fcc9c Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Fri, 5 Aug 2022 07:24:08 +0200 Subject: testsuite/gna: add a test for #2156 --- .../gna/issue2156/tb_to_string_overloading.vhdl | 17 ++++++++ testsuite/gna/issue2156/testsuite.sh | 16 +++++++ testsuite/gna/issue2156/timing_pkg.vhdl | 46 +++++++++++++++++++ testsuite/gna/issue2156/timing_pkg2.vhdl | 51 ++++++++++++++++++++++ 4 files changed, 130 insertions(+) create mode 100644 testsuite/gna/issue2156/tb_to_string_overloading.vhdl create mode 100755 testsuite/gna/issue2156/testsuite.sh create mode 100644 testsuite/gna/issue2156/timing_pkg.vhdl create mode 100644 testsuite/gna/issue2156/timing_pkg2.vhdl 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; -- cgit v1.2.3