aboutsummaryrefslogtreecommitdiffstats
path: root/src/grt
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2018-10-19 05:12:20 +0200
committerTristan Gingold <tgingold@free.fr>2018-10-21 08:03:38 +0200
commit1803f976121985c6e8e7506c9b959e8d2b5f718c (patch)
treec590acb9a797c28b01adc40cf5b00b5b017c799c /src/grt
parentf910e02797a83d0c5748768d20359a3d95569cc7 (diff)
downloadghdl-1803f976121985c6e8e7506c9b959e8d2b5f718c.tar.gz
ghdl-1803f976121985c6e8e7506c9b959e8d2b5f718c.tar.bz2
ghdl-1803f976121985c6e8e7506c9b959e8d2b5f718c.zip
Pass time-resolution to grt.
Use time-resolution for Put_Time. Use time-resolution for --stop-time (Parse_Time). Use time-resolution as VpiTimePrecision and for vcd. TODO: ghw (but needs to update ghwlib and gtkwave) Fix #672
Diffstat (limited to 'src/grt')
-rw-r--r--src/grt/grt-astdio.adb44
-rw-r--r--src/grt/grt-disp.adb15
-rw-r--r--src/grt/grt-options.adb44
-rw-r--r--src/grt/grt-options.ads10
-rw-r--r--src/grt/grt-vcd.adb16
-rw-r--r--src/grt/grt-vpi.adb6
-rw-r--r--src/grt/grt-waves.adb5
7 files changed, 97 insertions, 43 deletions
diff --git a/src/grt/grt-astdio.adb b/src/grt/grt-astdio.adb
index a572dd3cc..5fdcd1a64 100644
--- a/src/grt/grt-astdio.adb
+++ b/src/grt/grt-astdio.adb
@@ -23,6 +23,7 @@
-- however invalidate any other reasons why the executable file might be
-- covered by the GNU Public License.
with Grt.C; use Grt.C;
+with Grt.Options;
package body Grt.Astdio is
procedure Put (Stream : FILEs; Str : String)
@@ -209,28 +210,37 @@ package body Grt.Astdio is
end case;
end Put_Dir;
- procedure Put_Time (Stream : FILEs; Time : Std_Time) is
+ procedure Put_Time (Stream : FILEs; Time : Std_Time)
+ is
+ use Grt.Options;
+ Unit : Natural_Time_Scale;
+ T : Std_Time;
begin
if Time = Std_Time'First then
Put (Stream, "-Inf");
else
-- Do not bother with sec, min, and hr.
- if (Time mod 1_000_000_000_000) = 0 then
- Put_I64 (Stream, Ghdl_I64 (Time / 1_000_000_000_000));
- Put (Stream, "ms");
- elsif (Time mod 1_000_000_000) = 0 then
- Put_I64 (Stream, Ghdl_I64 (Time / 1_000_000_000));
- Put (Stream, "us");
- elsif (Time mod 1_000_000) = 0 then
- Put_I64 (Stream, Ghdl_I64 (Time / 1_000_000));
- Put (Stream, "ns");
- elsif (Time mod 1_000) = 0 then
- Put_I64 (Stream, Ghdl_I64 (Time / 1_000));
- Put (Stream, "ps");
- else
- Put_I64 (Stream, Ghdl_I64 (Time));
- Put (Stream, "fs");
- end if;
+ Unit := Time_Resolution_Scale;
+ T := Time;
+ while Unit > 1 and then (T mod 1_000) = 0 loop
+ T := T / 1000;
+ Unit := Unit - 1;
+ end loop;
+ Put_I64 (Stream, Ghdl_I64 (T));
+ case Unit is
+ when 0 =>
+ Put (Stream, "sec");
+ when 1 =>
+ Put (Stream, "ms");
+ when 2 =>
+ Put (Stream, "us");
+ when 3 =>
+ Put (Stream, "ns");
+ when 4 =>
+ Put (Stream, "ps");
+ when 5 =>
+ Put (Stream, "fs");
+ end case;
end if;
end Put_Time;
diff --git a/src/grt/grt-disp.adb b/src/grt/grt-disp.adb
index e68b1168b..36644bf1a 100644
--- a/src/grt/grt-disp.adb
+++ b/src/grt/grt-disp.adb
@@ -54,14 +54,12 @@ package body Grt.Disp is
-- Put_Str_Len (Stream, Type_Desc.E32.Values (Natural (E32)));
--end Put_E32;
- procedure Put_Sig_Index (Sig : Sig_Table_Index)
- is
+ procedure Put_Sig_Index (Sig : Sig_Table_Index) is
begin
Put_I32 (stdout, Ghdl_I32 (Sig));
end Put_Sig_Index;
- procedure Put_Sig_Range (Sig : Sig_Table_Range)
- is
+ procedure Put_Sig_Range (Sig : Sig_Table_Range) is
begin
Put_Sig_Index (Sig.First);
if Sig.Last /= Sig.First then
@@ -70,8 +68,7 @@ package body Grt.Disp is
end if;
end Put_Sig_Range;
- procedure Disp_Now
- is
+ procedure Disp_Now is
begin
Put ("Now is ");
Put_Time (stdout, Current_Time);
@@ -80,8 +77,7 @@ package body Grt.Disp is
New_Line;
end Disp_Now;
- procedure Disp_Propagation_Kind (Kind : Propagation_Kind_Type)
- is
+ procedure Disp_Propagation_Kind (Kind : Propagation_Kind_Type) is
begin
case Kind is
when Drv_One_Driver =>
@@ -184,8 +180,7 @@ package body Grt.Disp is
end loop;
end Disp_Signals_Order;
- procedure Disp_Mode (Mode : Mode_Type)
- is
+ procedure Disp_Mode (Mode : Mode_Type) is
begin
case Mode is
when Mode_B1 =>
diff --git a/src/grt/grt-options.adb b/src/grt/grt-options.adb
index cdf6c2886..5b154e4a5 100644
--- a/src/grt/grt-options.adb
+++ b/src/grt/grt-options.adb
@@ -117,6 +117,7 @@ package body Grt.Options is
Pos : Natural;
Time : Integer_64;
Unit : String (1 .. 3);
+ Scale : Natural_Time_Scale;
begin
Extract_Integer (Str, Ok, Time, Pos);
if not Ok then
@@ -138,27 +139,33 @@ package body Grt.Options is
Unit (2) := To_Lower (Str (Pos + 1));
if Unit = "fs " then
- null;
+ Scale := 5;
elsif Unit = "ps " then
- Time := Time * (10 ** 3);
+ Scale := 4;
elsif Unit = "ns " then
- Time := Time * (10 ** 6);
+ Scale := 3;
elsif Unit = "us " then
- Time := Time * (10 ** 9);
+ Scale := 2;
elsif Unit = "ms " then
- Time := Time * (10 ** 12);
+ Scale := 1;
elsif Unit = "sec" then
- Time := Time * (10 ** 15);
- elsif Unit = "min" then
- Time := Time * (10 ** 15) * 60;
- elsif Unit = "hr " then
- Time := Time * (10 ** 15) * 3600;
+ Scale := 0;
else
Error_S ("bad unit name for '");
Diag_C (Str);
Error_E ("'");
return -1;
end if;
+ if Scale > Time_Resolution_Scale then
+ Error_S ("unit for '");
+ Diag_C (Str);
+ Error_E ("' is less than time resolution");
+ return -1;
+ end if;
+ while Scale < Time_Resolution_Scale loop
+ Time := Time * 1000;
+ Scale := Scale + 1;
+ end loop;
return Std_Time (Time);
end Parse_Time;
@@ -361,6 +368,23 @@ package body Grt.Options is
Len : Natural;
Status : Decode_Option_Status;
begin
+ case Flag_String (5) is
+ when 'f' | '-' =>
+ Time_Resolution_Scale := 5;
+ when 'p' =>
+ Time_Resolution_Scale := 4;
+ when 'n' =>
+ Time_Resolution_Scale := 3;
+ when 'u' =>
+ Time_Resolution_Scale := 2;
+ when 'm' =>
+ Time_Resolution_Scale := 1;
+ when 's' =>
+ Time_Resolution_Scale := 0;
+ when others =>
+ Error ("unhandled time resolution");
+ end case;
+
Stop := False;
Last_Opt := Argc - 1;
for I in 1 .. Argc - 1 loop
diff --git a/src/grt/grt-options.ads b/src/grt/grt-options.ads
index 4f24793f0..fa7e1f660 100644
--- a/src/grt/grt-options.ads
+++ b/src/grt/grt-options.ads
@@ -55,6 +55,16 @@ package Grt.Options is
Flag_String : constant String (1 .. 5);
pragma Import (C, Flag_String, "__ghdl_flag_string");
+ -- Time resolution extracted from Flag_String, in multiple of -3:
+ -- 0: sec
+ -- 1: ms
+ -- 2: us
+ -- 3: ns
+ -- 4: ps
+ -- 5: fs
+ subtype Natural_Time_Scale is Natural range 0 .. 5;
+ Time_Resolution_Scale : Natural_Time_Scale;
+
-- Display options help.
-- Should not be called directly.
procedure Help;
diff --git a/src/grt/grt-vcd.adb b/src/grt/grt-vcd.adb
index 9050a26a4..b058dcdaf 100644
--- a/src/grt/grt-vcd.adb
+++ b/src/grt/grt-vcd.adb
@@ -53,6 +53,7 @@ with Grt.Vstrings;
with Grt.Wave_Opt; use Grt.Wave_Opt;
with Grt.Wave_Opt.Design; use Grt.Wave_Opt.Design;
with Grt.Fcvt;
+with Grt.Options;
pragma Elaborate_All (Grt.Table);
package body Grt.Vcd is
@@ -241,7 +242,20 @@ package body Grt.Vcd is
Vcd_Putline (" GHDL v0");
Vcd_Put_End;
Vcd_Putline ("$timescale");
- Vcd_Putline (" 1 fs");
+ case Options.Time_Resolution_Scale is
+ when 5 =>
+ Vcd_Putline (" 1 fs");
+ when 4 =>
+ Vcd_Putline (" 1 ps");
+ when 3 =>
+ Vcd_Putline (" 1 ns");
+ when 2 =>
+ Vcd_Putline (" 1 us");
+ when 1 =>
+ Vcd_Putline (" 1 ms");
+ when 0 =>
+ Vcd_Putline (" 1 sec");
+ end case;
Vcd_Put_End;
end Vcd_Init;
diff --git a/src/grt/grt-vpi.adb b/src/grt/grt-vpi.adb
index 4efa39584..ee6a9fdf5 100644
--- a/src/grt/grt-vpi.adb
+++ b/src/grt/grt-vpi.adb
@@ -325,7 +325,7 @@ package body Grt.Vpi is
raise Program_Error;
end if;
Res := Std_Time (Unsigned_64 (V.mHigh) * 2 ** 32 + Unsigned_64 (V.mLow));
- return Res * 1000;
+ return Res;
end Vpi_Time_To_Time;
-------------------------------------------------------------------------------
@@ -479,7 +479,7 @@ package body Grt.Vpi is
when vpiType =>
Res := Ref.mType;
when vpiTimePrecision =>
- Res := -12; -- In ps.
+ Res := -3 * Options.Time_Resolution_Scale;
when vpiSize =>
Res := Vpi_Get_Size (Ref);
when vpiVector =>
@@ -1148,7 +1148,7 @@ package body Grt.Vpi is
Res := Current_Time;
- V := To_Unsigned_64 (Res) / 1000;
+ V := To_Unsigned_64 (Res);
Time.mHigh := Unsigned_32 (V / 2 ** 32);
Time.mLow := Unsigned_32 (V mod 2 ** 32);
Time.mReal := 0.0;
diff --git a/src/grt/grt-waves.adb b/src/grt/grt-waves.adb
index e1931bfa2..c0d12993f 100644
--- a/src/grt/grt-waves.adb
+++ b/src/grt/grt-waves.adb
@@ -318,8 +318,7 @@ package body Grt.Waves is
end if;
end Wave_Init;
- procedure Write_File_Header
- is
+ procedure Write_File_Header is
begin
-- Magic, 9 bytes.
Wave_Put ("GHDLwave" & Nl);
@@ -331,6 +330,8 @@ package body Grt.Waves is
Wave_Put_Byte (1);
Wave_Write_Size_Order;
+
+ -- TODO: add time resolution.
end Write_File_Header;
procedure Avhpi_Error (Err : AvhpiErrorT)