From 8c8d9a8bf91d22d4cb7c350a016e0cdcfdae2ef9 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Fri, 6 Jan 2023 21:05:13 +0100 Subject: synth: handle value attribute for physical types --- src/grt/grt-values.adb | 25 ++++++++++++++----------- src/grt/grt-values.ads | 3 ++- 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'src/grt') diff --git a/src/grt/grt-values.adb b/src/grt/grt-values.adb index 7a2f09ed5..b2e98f6a0 100644 --- a/src/grt/grt-values.adb +++ b/src/grt/grt-values.adb @@ -234,38 +234,40 @@ package body Grt.Values is return Value_F64 (S, Len, Pos); end Ghdl_Value_F64; - procedure Ghdl_Value_Physical_Split (Str : Std_String_Ptr; + procedure Ghdl_Value_Physical_Split (Str : Std_String_Basep; + Len : Ghdl_Index_Type; Is_Real : out Boolean; Lit_Pos : out Ghdl_Index_Type; Lit_End : out Ghdl_Index_Type; Unit_Pos : out Ghdl_Index_Type) is - S : constant Std_String_Basep := Str.Base; - Len : Ghdl_Index_Type := Str.Bounds.Dim_1.Length; + L : Ghdl_Index_Type; begin -- LRM 14.1 -- Leading and trailing whitespace is allowed and ignored. Lit_Pos := 0; - Remove_Whitespaces (S, Len, Lit_Pos); + L := Len; + Remove_Whitespaces (Str, L, Lit_Pos); + pragma Unreferenced (Len); -- Split between abstract literal (optionnal) and unit name. Lit_End := Lit_Pos; Is_Real := False; - while Lit_End < Len loop - exit when Is_Whitespace (S (Lit_End)); - if S (Lit_End) = '.' then + while Lit_End < L loop + exit when Is_Whitespace (Str (Lit_End)); + if Str (Lit_End) = '.' then Is_Real := True; end if; Lit_End := Lit_End + 1; end loop; - if Lit_End = Len then + if Lit_End = L then -- No literal Unit_Pos := Lit_Pos; Lit_End := 0; else Unit_Pos := Lit_End + 1; - while Unit_Pos < Len loop - exit when not Is_Whitespace (S (Unit_Pos)); + while Unit_Pos < L loop + exit when not Is_Whitespace (Str (Unit_Pos)); Unit_Pos := Unit_Pos + 1; end loop; end if; @@ -294,7 +296,8 @@ package body Grt.Values is Remove_Whitespaces (S, Len, Lit_Pos); -- Extract literal and unit - Ghdl_Value_Physical_Split (Str, Found_Real, Lit_Pos, Lit_End, Unit_Pos); + Ghdl_Value_Physical_Split + (S, Len, Found_Real, Lit_Pos, Lit_End, Unit_Pos); -- Find unit value Multiple := null; diff --git a/src/grt/grt-values.ads b/src/grt/grt-values.ads index 369c69cfd..8a81d1fbd 100644 --- a/src/grt/grt-values.ads +++ b/src/grt/grt-values.ads @@ -31,7 +31,8 @@ package Grt.Values is -- Set LIT_POS to the position of the first character of the numeric -- literal (after whitespaces are skipped). -- Set LIT_END to the position of the next character of the numeric lit. - procedure Ghdl_Value_Physical_Split (Str : Std_String_Ptr; + procedure Ghdl_Value_Physical_Split (Str : Std_String_Basep; + Len : Ghdl_Index_Type; Is_Real : out Boolean; Lit_Pos : out Ghdl_Index_Type; Lit_End : out Ghdl_Index_Type; -- cgit v1.2.3