diff options
author | Tristan Gingold <tgingold@free.fr> | 2017-12-01 04:34:20 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2017-12-01 04:35:16 +0100 |
commit | d265cf4189aa50685d68c04675f15c0466b45314 (patch) | |
tree | 8a1103873b2bbced33869fe947812d790c97e623 /src/vhdl | |
parent | 2f9a512ca216f2c8a62e2251d551580ef67d9c8d (diff) | |
download | ghdl-d265cf4189aa50685d68c04675f15c0466b45314.tar.gz ghdl-d265cf4189aa50685d68c04675f15c0466b45314.tar.bz2 ghdl-d265cf4189aa50685d68c04675f15c0466b45314.zip |
Improve error message in case of circular dependency.
Fix #471
Diffstat (limited to 'src/vhdl')
-rw-r--r-- | src/vhdl/iirs.ads | 9 | ||||
-rw-r--r-- | src/vhdl/sem.adb | 52 |
2 files changed, 32 insertions, 29 deletions
diff --git a/src/vhdl/iirs.ads b/src/vhdl/iirs.ads index 1ff1934ea..5501894a1 100644 --- a/src/vhdl/iirs.ads +++ b/src/vhdl/iirs.ads @@ -5479,15 +5479,14 @@ package Iirs is type Date_Type is new Nat32; -- The unit is obsoleted (ie replaced) by a more recently analyzed design - -- unit.another design unit. + -- unit. -- If another design unit depends (directly or not) on an obseleted design -- unit, it is also obsolete, and cannot be defined. Date_Obsolete : constant Date_Type := 0; + -- A unit with the same name (could also be the same unit) is being + -- analyzed. Used to detect circular dependencies. + Date_Replacing : constant Date_Type := 1; -- The unit was not analyzed. - Date_Not_Analyzed : constant Date_Type := 1; - -- The unit has been analyzed but it has bad dependences. - Date_Bad_Analyze : constant Date_Type := 2; - -- The unit has been parsed but not analyzed. Date_Parsed : constant Date_Type := 4; -- The unit is being analyzed. Date_Analyzing : constant Date_Type := 5; diff --git a/src/vhdl/sem.adb b/src/vhdl/sem.adb index 0893120e2..c8f0822e2 100644 --- a/src/vhdl/sem.adb +++ b/src/vhdl/sem.adb @@ -3172,10 +3172,12 @@ package body Sem is end Get_Current_Design_Unit; -- LRM 11.1 Design units. - procedure Semantic (Design_Unit: Iir_Design_Unit) + procedure Semantic (Design_Unit : Iir_Design_Unit) is - El: Iir; - Old_Design_Unit: Iir_Design_Unit; + Library_Unit : constant Iir := Get_Library_Unit (Design_Unit); + Library : constant Iir := Get_Library (Get_Design_File (Design_Unit)); + Prev_Unit : Iir; + Old_Design_Unit : Iir_Design_Unit; Implicit : Implicit_Signal_Declaration_Type; begin -- Sanity check: can analyze either previously analyzed unit or just @@ -3193,7 +3195,17 @@ package body Sem is raise Internal_Error; end case; - -- Save and set current_design_unit. + -- If there is already a unit with the same name, mark it as being + -- replaced. + if Get_Kind (Library_Unit) in Iir_Kinds_Primary_Unit then + Prev_Unit := Libraries.Find_Primary_Unit + (Library, Get_Identifier (Library_Unit)); + if Is_Valid (Prev_Unit) and then Prev_Unit /= Design_Unit then + Set_Date (Prev_Unit, Date_Replacing); + end if; + end if; + + -- Save and set current_design_unit. Old_Design_Unit := Current_Design_Unit; Current_Design_Unit := Design_Unit; Push_Signals_Declarative_Part (Implicit, Null_Iir); @@ -3214,45 +3226,37 @@ package body Sem is -- due to reasons given by LCS 3 (VHDL Issue # 1028). Open_Declarative_Region; - -- Set_Dependence_List (Design_Unit, --- Create_Iir (Iir_Kind_Design_Unit_List)); - -- LRM 11.2 -- Every design unit is assumed to contain the following implicit -- context items as part of its context clause: -- library STD, WORK; use STD.STANDARD.all; Sem_Scopes.Add_Name (Libraries.Std_Library, Std_Names.Name_Std, False); - Sem_Scopes.Add_Name (Get_Library (Get_Design_File (Design_Unit)), - Std_Names.Name_Work, - False); + Sem_Scopes.Add_Name (Library, Std_Names.Name_Work, False); Sem_Scopes.Use_All_Names (Standard_Package); if Get_Dependence_List (Design_Unit) = Null_Iir_List then Set_Dependence_List (Design_Unit, Create_Iir_List); end if; Add_Dependence (Std_Standard_Unit); - -- Semantic on context clauses. + -- Analyze context clauses. Sem_Context_Clauses (Design_Unit); - -- semantic on the library unit. - El := Get_Library_Unit (Design_Unit); - case Get_Kind (El) is + -- Analyze the library unit. + case Iir_Kinds_Library_Unit (Get_Kind (Library_Unit)) is when Iir_Kind_Entity_Declaration => - Sem_Entity_Declaration (El); + Sem_Entity_Declaration (Library_Unit); when Iir_Kind_Architecture_Body => - Sem_Architecture_Body (El); + Sem_Architecture_Body (Library_Unit); when Iir_Kind_Package_Declaration => - Sem_Package_Declaration (El); + Sem_Package_Declaration (Library_Unit); when Iir_Kind_Package_Body => - Sem_Package_Body (El); + Sem_Package_Body (Library_Unit); when Iir_Kind_Configuration_Declaration => - Sem_Configuration_Declaration (El); + Sem_Configuration_Declaration (Library_Unit); when Iir_Kind_Package_Instantiation_Declaration => - Sem_Package_Instantiation_Declaration (El); + Sem_Package_Instantiation_Declaration (Library_Unit); when Iir_Kind_Context_Declaration => - Sem_Context_Declaration (El); - when others => - Error_Kind ("semantic", El); + Sem_Context_Declaration (Library_Unit); end case; Close_Declarative_Region; @@ -3267,7 +3271,7 @@ package body Sem is Sem_Analysis_Checks_List (Design_Unit, False); end if; - -- Restore current_design_unit. + -- Restore current_design_unit. Current_Design_Unit := Old_Design_Unit; Pop_Signals_Declarative_Part (Implicit); end Semantic; |