diff options
author | Tristan Gingold <tgingold@free.fr> | 2022-12-26 17:32:55 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2022-12-26 17:33:39 +0100 |
commit | 0784c5351937b948d914238f570305d34e35e9ae (patch) | |
tree | 90c22cd945e344f53a6afd40d3cb0ed8edfb2568 | |
parent | 0f348cb94e9f7bd83f52c0317bb7f858b87ece05 (diff) | |
download | ghdl-0784c5351937b948d914238f570305d34e35e9ae.tar.gz ghdl-0784c5351937b948d914238f570305d34e35e9ae.tar.bz2 ghdl-0784c5351937b948d914238f570305d34e35e9ae.zip |
synth: improve support of value attribute
-rw-r--r-- | src/grt/grt-strings.adb | 3 | ||||
-rw-r--r-- | src/grt/grt-strings.ads | 4 | ||||
-rw-r--r-- | src/synth/elab-vhdl_expr.adb | 39 |
3 files changed, 40 insertions, 6 deletions
diff --git a/src/grt/grt-strings.adb b/src/grt/grt-strings.adb index 5d6fc8706..3f8f8ed29 100644 --- a/src/grt/grt-strings.adb +++ b/src/grt/grt-strings.adb @@ -23,9 +23,8 @@ package body Grt.Strings is function Is_Whitespace (C : in Character) return Boolean is - use ASCII; begin - return C = ' ' or C = NBSP or C = HT; + return C = ' ' or C = NBSP; end Is_Whitespace; function First_Non_Whitespace_Pos (Str : String) return Integer is diff --git a/src/grt/grt-strings.ads b/src/grt/grt-strings.ads index 7b8535425..1d52a62fc 100644 --- a/src/grt/grt-strings.ads +++ b/src/grt/grt-strings.ads @@ -26,7 +26,9 @@ package Grt.Strings is NBSP : constant Character := Character'Val (160); - -- Return True IFF C is a whitespace character (as defined in LRM93 14.3) + -- Return True IFF C is a whitespace character as defined by LRM93 13.1 + -- Note: this is different from the definition in LRM93 14.3 (for files, + -- which includes HT). function Is_Whitespace (C : in Character) return Boolean; -- The following functions return -1 in case there is no match in string --- diff --git a/src/synth/elab-vhdl_expr.adb b/src/synth/elab-vhdl_expr.adb index cb5e7a26d..d9ad9f27d 100644 --- a/src/synth/elab-vhdl_expr.adb +++ b/src/synth/elab-vhdl_expr.adb @@ -23,6 +23,7 @@ with Str_Table; with Netlists; with Vhdl.Errors; use Vhdl.Errors; +with Vhdl.Scanner; with Vhdl.Utils; use Vhdl.Utils; with Vhdl.Evaluation; use Vhdl.Evaluation; @@ -36,6 +37,7 @@ with Synth.Vhdl_Eval; use Synth.Vhdl_Eval; with Synth.Errors; use Synth.Errors; with Grt.Types; +with Grt.Vhdl_Types; with Grt.To_Strings; with Grt.Vstrings; @@ -125,17 +127,48 @@ package body Elab.Vhdl_Expr is end if; declare - Str : constant String := Value_To_String (V); + Value : constant String := Value_To_String (V); + First, Last : Integer; Res_N : Node; Val : Int64; begin + -- LRM93 14.1 Predefined attributes. + -- Leading and trailing whitespace are ignored. + First := Value'First; + Last := Value'Last; + while First <= Last loop + exit when not Vhdl.Scanner.Is_Whitespace (Value (First)); + First := First + 1; + end loop; + while Last >= First loop + exit when not Vhdl.Scanner.Is_Whitespace (Value (Last)); + Last := Last - 1; + end loop; + case Get_Kind (Btype) is when Iir_Kind_Enumeration_Type_Definition => - Res_N := Eval_Value_Attribute (Str, Etype, Attr); + Res_N := Eval_Value_Attribute + (Value (First .. Last), Etype, Attr); Val := Int64 (Get_Enum_Pos (Res_N)); Free_Iir (Res_N); when Iir_Kind_Integer_Type_Definition => - Val := Int64'Value (Str); + declare + use Grt.To_Strings; + use Grt.Types; + use Grt.Vhdl_Types; + Value1 : String renames Value (First .. Last); + Res : Value_I64_Result; + begin + Res := Value_I64 (To_Std_String_Basep (Value1'Address), + Value1'Length, 0); + if Res.Status = Value_Ok then + Val := Int64 (Res.Val); + else + Error_Msg_Synth + (Syn_Inst, Attr, "incorrect 'value string"); + return No_Valtyp; + end if; + end; when others => Error_Msg_Elab (+Attr, "unhandled type for 'value"); return No_Valtyp; |