diff options
author | Tristan Gingold <tgingold@free.fr> | 2019-08-06 07:49:00 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2019-08-06 07:49:00 +0200 |
commit | 5034635df4c711dfa2dc3ae1faad49c49d018511 (patch) | |
tree | 9e5aacd67a88ae9f4852cd491ed147227d7e4242 | |
parent | 7687582d7faebfb3e3c691ccd57df15106f09046 (diff) | |
download | ghdl-5034635df4c711dfa2dc3ae1faad49c49d018511.tar.gz ghdl-5034635df4c711dfa2dc3ae1faad49c49d018511.tar.bz2 ghdl-5034635df4c711dfa2dc3ae1faad49c49d018511.zip |
vhdl: for time resolution, do not consider unit name from textio body.
For #881
-rw-r--r-- | libraries/std/textio-body.vhdl | 8 | ||||
-rw-r--r-- | src/vhdl/vhdl-sem_expr.adb | 11 | ||||
-rw-r--r-- | src/vhdl/vhdl-sem_names.adb | 37 |
3 files changed, 42 insertions, 14 deletions
diff --git a/libraries/std/textio-body.vhdl b/libraries/std/textio-body.vhdl index d01cb8bad..235da706a 100644 --- a/libraries/std/textio-body.vhdl +++ b/libraries/std/textio-body.vhdl @@ -287,9 +287,9 @@ package body textio is -- Note: we must start from unit, since all units are not a power of 10. -- Note: UN can be multiplied only after we know it is possible. This -- is a to avoid overflow. - if un <= 0 fs then + if un <= 0 sec then assert false report "UNIT argument is not positive" severity error; - un := 1 ns; + un := ns; end if; while val / 10 >= un or val / 10 <= -un loop un := un * 10; @@ -1034,7 +1034,7 @@ package body textio is is_neg := false; exp := 0; exp_neg := false; - res := 0 fs; + res := 0 sec; -- Look for exponent and unit name. -- Parse the string: this loop checks the correctness of the format, and @@ -1199,7 +1199,7 @@ package body textio is end if; when '0' to '9' => -- Leading "0" are not significant. - if l (i) /= '0' or res /= 0 fs then + if l (i) /= '0' or res /= 0 sec then res := res + char_to_nat (l (i)) * unit; unit := unit / 10; end if; diff --git a/src/vhdl/vhdl-sem_expr.adb b/src/vhdl/vhdl-sem_expr.adb index 06c689848..ef9b18c9b 100644 --- a/src/vhdl/vhdl-sem_expr.adb +++ b/src/vhdl/vhdl-sem_expr.adb @@ -17,15 +17,15 @@ -- 02111-1307, USA. with Grt.Algos; -with Vhdl.Std_Package; use Vhdl.Std_Package; with Errorout; use Errorout; -with Vhdl.Errors; use Vhdl.Errors; +with Name_Table; +with Str_Table; with Flags; use Flags; +with Vhdl.Std_Package; use Vhdl.Std_Package; with Vhdl.Sem_Scopes; use Vhdl.Sem_Scopes; with Vhdl.Sem_Names; use Vhdl.Sem_Names; with Vhdl.Sem; -with Name_Table; -with Str_Table; +with Vhdl.Errors; use Vhdl.Errors; with Vhdl.Utils; use Vhdl.Utils; with Vhdl.Evaluation; use Vhdl.Evaluation; with Vhdl.Nodes_Utils; use Vhdl.Nodes_Utils; @@ -4023,6 +4023,9 @@ package body Vhdl.Sem_Expr is end if; Set_Named_Entity (Unit_Name, Create_Error_Name (Unit_Name)); else + -- Note: there is corresponding code for physical literal without + -- literal (so only the unit) in vhdl.sem_expr.name_to_expression. + -- Physical unit is used. Set_Use_Flag (Unit, True); diff --git a/src/vhdl/vhdl-sem_names.adb b/src/vhdl/vhdl-sem_names.adb index 9c8cda5a4..d6ff02da4 100644 --- a/src/vhdl/vhdl-sem_names.adb +++ b/src/vhdl/vhdl-sem_names.adb @@ -15,12 +15,13 @@ -- along with GHDL; see the file COPYING. If not, write to the Free -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- 02111-1307, USA. +with Flags; use Flags; +with Name_Table; +with Libraries; with Vhdl.Evaluation; use Vhdl.Evaluation; with Vhdl.Utils; use Vhdl.Utils; with Errorout; use Errorout; with Vhdl.Errors; use Vhdl.Errors; -with Flags; use Flags; -with Name_Table; with Vhdl.Std_Package; use Vhdl.Std_Package; with Types; use Types; with Vhdl.Nodes_Utils; use Vhdl.Nodes_Utils; @@ -3959,6 +3960,21 @@ package body Vhdl.Sem_Names is end case; end Name_To_Analyzed_Name; + -- Return True iff the current design unit is package body textio. + function Is_Current_Design_Unit_Textio_Body return Boolean + is + Unit : constant Iir := Sem.Get_Current_Design_Unit; + Cur_Lib : constant Iir := Get_Library_Unit (Unit); + begin + if Get_Kind (Cur_Lib) /= Iir_Kind_Package_Body then + return False; + end if; + if Get_Library (Get_Design_File (Unit)) /= Libraries.Std_Library then + return False; + end if; + return Get_Identifier (Cur_Lib) = Std_Names.Name_Textio; + end Is_Current_Design_Unit_Textio_Body; + -- Convert name EXPR to an expression (ie, create function call). -- A_TYPE is the expected type of the expression. -- Returns an Error node in case of error. @@ -4113,13 +4129,22 @@ package body Vhdl.Sem_Names is --Set_Name_Staticness (Name, Get_Name_Staticness (Expr)); --Set_Base_Name (Name, Get_Base_Name (Expr)); + -- For time physical literal (without a literal), check for + -- resolution and mark the literal used. + -- Don't check for textio body, as it uses all units and + -- user code shouldn't be affected by it. if Get_Type (Expr) = Time_Type_Definition - and then Get_Value (Get_Physical_Literal (Expr)) = 0 + and then not Is_Current_Design_Unit_Textio_Body then + pragma Assert (Get_Kind (Expr) = Iir_Kind_Unit_Declaration); + Set_Use_Flag (Expr, True); + -- See Sem_Physical_Literal. - Error_Msg_Sem - (+Res, - "physical unit %i is below the time resolution", +Expr); + if Get_Value (Get_Physical_Literal (Expr)) = 0 then + Error_Msg_Sem + (+Res, "physical unit %i is below the " + & "time resolution", +Expr); + end if; end if; return Res; |