aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/gna/issue2156/timing_pkg.vhdl
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/gna/issue2156/timing_pkg.vhdl')
-rw-r--r--testsuite/gna/issue2156/timing_pkg.vhdl46
1 files changed, 46 insertions, 0 deletions
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;