diff options
author | Tristan Gingold <tgingold@free.fr> | 2014-09-02 21:17:16 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2014-09-02 21:17:16 +0200 |
commit | e6ffb98cb5ad3f07bcaf79323d8ab8411688c494 (patch) | |
tree | 46a91868b6e4aeb5354249c74507b3e92e85f01f | |
parent | e393e8b7babd9d2dbe5e6bb7816b82036b857a1f (diff) | |
download | ghdl-e6ffb98cb5ad3f07bcaf79323d8ab8411688c494.tar.gz ghdl-e6ffb98cb5ad3f07bcaf79323d8ab8411688c494.tar.bz2 ghdl-e6ffb98cb5ad3f07bcaf79323d8ab8411688c494.zip |
Keep names in the tree.
This is a large change to improve error locations and allow pretty printing.
50 files changed, 6624 insertions, 4592 deletions
@@ -410,7 +410,7 @@ package body Canon is -- LRM08 11.3 -- See loop statement case. declare - It : constant Iir := Get_Iterator_Scheme (Stmt); + It : constant Iir := Get_Parameter_Specification (Stmt); It_Type : constant Iir := Get_Type (It); Rng : constant Iir := Get_Range_Constraint (It_Type); begin @@ -438,7 +438,7 @@ package body Canon is while Param /= Null_Iir loop if (Get_Kind (Param) = Iir_Kind_Association_Element_By_Expression) - and then (Get_Mode (Get_Base_Name (Get_Formal (Param))) + and then (Get_Mode (Get_Association_Interface (Param)) /= Iir_Out_Mode) then Canon_Extract_Sensitivity (Get_Actual (Param), List); @@ -622,18 +622,13 @@ package body Canon is Canon_Expression (El); end loop; --- when Iir_Kind_Selected_Name => --- -- Use this order to allow tail recursion optimisation. --- Canon_Expression (Get_Suffix (Expr)); --- Canon_Expression (Get_Prefix (Expr)); when Iir_Kind_Selected_Element => Canon_Expression (Get_Prefix (Expr)); when Iir_Kind_Dereference | Iir_Kind_Implicit_Dereference => Canon_Expression (Get_Prefix (Expr)); - when Iir_Kind_Simple_Name - | Iir_Kind_Selected_Name => + when Iir_Kinds_Denoting_Name => Canon_Expression (Get_Named_Entity (Expr)); when Iir_Kinds_Monadic_Operator => @@ -664,7 +659,7 @@ package body Canon is Canon_Expression (Get_Expression (Expr)); when Iir_Kind_Allocator_By_Subtype => declare - Ind : constant Iir := Get_Expression (Expr); + Ind : constant Iir := Get_Subtype_Indication (Expr); begin if Get_Kind (Ind) = Iir_Kind_Array_Subtype_Definition then Canon_Subtype_Indication (Ind); @@ -680,16 +675,17 @@ package body Canon is -- No need to canon parameter, since it is a locally static -- expression. declare - Prefix : Iir; + Prefix : constant Iir := Get_Prefix (Expr); begin - Prefix := Get_Prefix (Expr); - case Get_Kind (Prefix) is - when Iir_Kind_Type_Declaration - | Iir_Kind_Subtype_Declaration => - null; - when others => - Canon_Expression (Prefix); - end case; + if Get_Kind (Prefix) in Iir_Kinds_Denoting_Name + and then (Get_Kind (Get_Named_Entity (Prefix)) + in Iir_Kinds_Type_Declaration) + then + -- No canon for types. + null; + else + Canon_Expression (Prefix); + end if; end; when Iir_Kinds_Type_Attribute => @@ -732,13 +728,15 @@ package body Canon is | Iir_Kind_Object_Alias_Declaration => null; - when Iir_Kind_Enumeration_Literal => + when Iir_Kind_Enumeration_Literal + | Iir_Kind_Overflow_Literal => null; when Iir_Kind_Element_Declaration => null; - when Iir_Kind_Attribute_Value => + when Iir_Kind_Attribute_Value + | Iir_Kind_Attribute_Name => null; when others => @@ -820,7 +818,7 @@ package body Canon is if Get_Formal (Assoc_El) = Null_Iir then Set_Formal (Assoc_El, Inter); end if; - if Get_Associated_Formal (Assoc_El) = Inter then + if Get_Association_Interface (Assoc_El) = Inter then -- Remove ASSOC_EL from ASSOC_CHAIN if Prev_Assoc_El /= Null_Iir then @@ -903,12 +901,10 @@ package body Canon is procedure Canon_Subprogram_Call (Call : Iir) is - Imp : Iir; + Imp : constant Iir := Get_Named_Entity (Get_Implementation (Call)); + Inter_Chain : constant Iir := Get_Interface_Declaration_Chain (Imp); Assoc_Chain : Iir; - Inter_Chain : Iir; begin - Imp := Get_Implementation (Call); - Inter_Chain := Get_Interface_Declaration_Chain (Imp); Assoc_Chain := Get_Parameter_Association_Chain (Call); Assoc_Chain := Canon_Association_Chain (Inter_Chain, Assoc_Chain, Call); Set_Parameter_Association_Chain (Call, Assoc_Chain); @@ -998,7 +994,6 @@ package body Canon is Stmt: Iir; Expr: Iir; Prev_Loop : Iir; - Label : Iir; begin Stmt := First; while Stmt /= Null_Iir loop @@ -1080,7 +1075,8 @@ package body Canon is Prev_Loop := Cur_Loop; Cur_Loop := Stmt; if Canon_Flag_Expressions then - Canon_Discrete_Range (Get_Type (Get_Iterator_Scheme (Stmt))); + Canon_Discrete_Range + (Get_Type (Get_Parameter_Specification (Stmt))); end if; Canon_Sequential_Stmts (Get_Sequential_Statement_Chain (Stmt)); Cur_Loop := Prev_Loop; @@ -1097,14 +1093,18 @@ package body Canon is when Iir_Kind_Next_Statement | Iir_Kind_Exit_Statement => - Expr := Get_Condition (Stmt); - if Expr /= Null_Iir then - Canon_Expression (Expr); - end if; - Label := Get_Loop (Stmt); - if Label = Null_Iir then - Set_Loop (Stmt, Cur_Loop); - end if; + declare + Loop_Label : Iir; + begin + Expr := Get_Condition (Stmt); + if Expr /= Null_Iir then + Canon_Expression (Expr); + end if; + Loop_Label := Get_Loop_Label (Stmt); + if Loop_Label = Null_Iir then + Set_Loop_Label (Stmt, Build_Simple_Name (Cur_Loop, Stmt)); + end if; + end; when Iir_Kind_Procedure_Call_Statement => Canon_Subprogram_Call_And_Actuals (Get_Procedure_Call (Stmt)); @@ -1221,17 +1221,14 @@ package body Canon is Proc : Iir_Sensitized_Process_Statement; Call_Stmt : Iir_Procedure_Call_Statement; Wait_Stmt : Iir_Wait_Statement; - Call : Iir_Procedure_Call; + Call : constant Iir_Procedure_Call := Get_Procedure_Call (El); + Imp : constant Iir := Get_Named_Entity (Get_Implementation (Call)); Assoc_Chain : Iir; Assoc : Iir; - Imp : Iir; Inter : Iir; Sensitivity_List : Iir_List; Is_Sensitized : Boolean; begin - Call := Get_Procedure_Call (El); - Imp := Get_Implementation (Call); - -- Optimization: the process is a sensitized process only if the -- procedure is known not to have wait statement. Is_Sensitized := Get_Wait_State (Imp) = False; @@ -1288,7 +1285,7 @@ package body Canon is while Assoc /= Null_Iir loop case Get_Kind (Assoc) is when Iir_Kind_Association_Element_By_Expression => - Inter := Get_Associated_Formal (Assoc); + Inter := Get_Association_Interface (Assoc); if Get_Mode (Inter) in Iir_In_Modes then Canon_Extract_Sensitivity (Get_Actual (Assoc), Sensitivity_List, False); @@ -1788,7 +1785,7 @@ package body Canon is raise Internal_Error; else Bind := Get_Default_Binding_Indication - (Get_First_Element (Instances)); + (Get_Named_Entity (Get_First_Element (Instances))); end if; if Bind = Null_Iir then -- Component is not bound. @@ -1895,7 +1892,7 @@ package body Canon is Sub_Chain_Append (First, Last, El); Assoc := Get_Chain (Assoc); exit when Assoc = Null_Iir; - exit when Get_Associated_Formal (Assoc) /= Inter; + exit when Get_Association_Interface (Assoc) /= Inter; end loop; end Copy_Association; @@ -1905,7 +1902,7 @@ package body Canon is loop Assoc := Get_Chain (Assoc); exit when Assoc = Null_Iir; - exit when Get_Associated_Formal (Assoc) /= Inter; + exit when Get_Association_Interface (Assoc) /= Inter; end loop; end Advance; @@ -1922,13 +1919,12 @@ package body Canon is Inter := Inter_Chain; while Inter /= Null_Iir loop -- Consistency check. - if Get_Associated_Formal (F_El) /= Inter then - raise Internal_Error; - end if; + pragma Assert (Get_Association_Interface (F_El) = Inter); + -- Find the associated in the second chain. S_El := Sec_Chain; while S_El /= Null_Iir loop - exit when Get_Associated_Formal (S_El) = Inter; + exit when Get_Association_Interface (S_El) = Inter; S_El := Get_Chain (S_El); end loop; if S_El /= Null_Iir @@ -1953,6 +1949,7 @@ package body Canon is Instance_List : Iir_List; Conf_Instance_List : Iir_List; Instance : Iir; + Instance_Name : Iir; N_Nbr : Natural; begin -- Create the new component configuration @@ -2019,13 +2016,14 @@ package body Canon is Conf_Instance_List := Get_Instantiation_List (Comp_Conf); N_Nbr := 0; for I in 0 .. Get_Nbr_Elements (Conf_Instance_List) - 1 loop - Instance := Get_Nth_Element (Conf_Instance_List, I); + Instance_Name := Get_Nth_Element (Conf_Instance_List, I); + Instance := Get_Named_Entity (Instance_Name); if Get_Component_Configuration (Instance) = Conf_Spec then -- The incremental binding applies to this instance. Set_Component_Configuration (Instance, Res); - Append_Element (Instance_List, Instance); + Append_Element (Instance_List, Instance_Name); else - Replace_Nth_Element (Conf_Instance_List, N_Nbr, Instance); + Replace_Nth_Element (Conf_Instance_List, N_Nbr, Instance_Name); N_Nbr := N_Nbr + 1; end if; end loop; @@ -2041,16 +2039,20 @@ package body Canon is is El : Iir; Comp_Conf : Iir; + Inst : Iir; begin El := Get_Concurrent_Statement_Chain (Parent); while El /= Null_Iir loop case Get_Kind (El) is when Iir_Kind_Component_Instantiation_Statement => - if Get_Instantiated_Unit (El) = Comp then + Inst := Get_Instantiated_Unit (El); + if Get_Kind (Inst) in Iir_Kinds_Denoting_Name + and then Get_Named_Entity (Inst) = Comp + then Comp_Conf := Get_Component_Configuration (El); if Comp_Conf = Null_Iir then -- The component is not yet configured. - Append_Element (List, El); + Append_Element (List, Build_Simple_Name (El, El)); Set_Component_Configuration (El, Conf); else -- The component is already configured. @@ -2099,6 +2101,7 @@ package body Canon is for I in Natural loop El := Get_Nth_Element (Spec, I); exit when El = Null_Iir; + El := Get_Named_Entity (El); Comp_Conf := Get_Component_Configuration (El); if Comp_Conf /= Null_Iir and then Comp_Conf /= Conf then if Get_Kind (Comp_Conf) /= Iir_Kind_Configuration_Specification @@ -2124,7 +2127,8 @@ package body Canon is if Spec = Iir_List_All or Spec = Iir_List_Others then List := Create_Iir_List; Canon_Component_Specification_All_Others - (Conf, Parent, Spec, List, Get_Component_Name (Conf)); + (Conf, Parent, Spec, List, + Get_Named_Entity (Get_Component_Name (Conf))); Set_Instantiation_List (Conf, List); else -- Has Already a designator list. @@ -2140,6 +2144,7 @@ package body Canon is Force : Boolean; El : Iir; N_List : Iir_Designator_List; + Dis_Type : Iir; begin if Canon_Flag_Expressions then Canon_Expression (Get_Expression (Dis)); @@ -2152,12 +2157,13 @@ package body Canon is else return; end if; + Dis_Type := Get_Type (Get_Type_Mark (Dis)); N_List := Create_Iir_List; Set_Signal_List (Dis, N_List); El := Get_Declaration_Chain (Decl_Parent); while El /= Null_Iir loop if Get_Kind (El) = Iir_Kind_Signal_Declaration - and then Get_Type (El) = Get_Type (Dis) + and then Get_Type (El) = Dis_Type and then Get_Signal_Kind (El) /= Iir_No_Signal_Kind then if not Get_Has_Disconnect_Flag (El) then @@ -2442,11 +2448,12 @@ package body Canon is Designator_List : Iir_List; Inst_List : Iir_List; Inst : Iir; + Inst_Name : Iir; begin Comp_Conf := Get_Component_Configuration (El); if Comp_Conf = Null_Iir then Comp := Get_Instantiated_Unit (El); - if Get_Kind (Comp) = Iir_Kind_Component_Declaration then + if Get_Kind (Comp) in Iir_Kinds_Denoting_Name then -- Create a component configuration. -- FIXME: should merge all these default configuration -- of the same component. @@ -2455,7 +2462,8 @@ package body Canon is Set_Parent (Res, Conf); Set_Component_Name (Res, Comp); Designator_List := Create_Iir_List; - Append_Element (Designator_List, El); + Append_Element + (Designator_List, Build_Simple_Name (El, El)); Set_Instantiation_List (Res, Designator_List); Append (Last_Item, Conf, Res); end if; @@ -2473,12 +2481,13 @@ package body Canon is Inst_List := Get_Instantiation_List (Comp_Conf); Designator_List := Create_Iir_List; for I in 0 .. Get_Nbr_Elements (Inst_List) - 1 loop - Inst := Get_Nth_Element (Inst_List, I); + Inst_Name := Get_Nth_Element (Inst_List, I); + Inst := Get_Named_Entity (Inst_Name); if Get_Component_Configuration (Inst) = Comp_Conf and then Get_Parent (Inst) = Blk then Set_Component_Configuration (Inst, Res); - Append_Element (Designator_List, Inst); + Append_Element (Designator_List, Inst_Name); end if; end loop; Set_Instantiation_List (Res, Designator_List); @@ -2684,7 +2693,6 @@ package body Canon is Loc : constant Location_Type := Get_Location (Arch); Config : Iir_Configuration_Declaration; Res : Iir_Design_Unit; - Entity : Iir_Entity_Declaration; Blk_Cfg : Iir_Block_Configuration; begin Res := Create_Iir (Iir_Kind_Design_Unit); @@ -2697,10 +2705,9 @@ package body Canon is Set_Location (Config, Loc); Set_Library_Unit (Res, Config); Set_Design_Unit (Config, Res); - Entity := Get_Entity (Arch); - Set_Entity (Config, Entity); + Set_Entity_Name (Config, Get_Entity_Name (Arch)); Set_Dependence_List (Res, Create_Iir_List); - Add_Dependence (Res, Get_Design_Unit (Entity)); + Add_Dependence (Res, Get_Design_Unit (Get_Entity (Config))); Add_Dependence (Res, Get_Design_Unit (Arch)); Blk_Cfg := Create_Iir (Iir_Kind_Block_Configuration); diff --git a/configuration.adb b/configuration.adb index 4cf51ef89..997c9d287 100644 --- a/configuration.adb +++ b/configuration.adb @@ -21,7 +21,7 @@ with Std_Package; with Sem_Names; with Name_Table; use Name_Table; with Flags; -with Iirs_Utils; +with Iirs_Utils; use Iirs_Utils; package body Configuration is procedure Add_Design_Concurrent_Stmts (Parent : Iir); @@ -207,10 +207,10 @@ package body Configuration is case Get_Kind (Stmt) is when Iir_Kind_Component_Instantiation_Statement => declare - Unit : Iir; + Unit : constant Iir := Get_Instantiated_Unit (Stmt); begin - Unit := Get_Instantiated_Unit (Stmt); - if Get_Kind (Unit) /= Iir_Kind_Component_Declaration then + if Get_Kind (Unit) not in Iir_Kinds_Denoting_Name then + -- Entity or configuration instantiation. Add_Design_Aspect (Unit, True); end if; end; @@ -365,7 +365,7 @@ package body Configuration is Assoc := Conf_Chain; while Assoc /= Null_Iir loop if Get_Kind (Assoc) = Iir_Kind_Association_Element_Open then - Formal := Get_Formal (Assoc); + Formal := Get_Association_Interface (Assoc); Err := Err or Check_Open_Port (Formal, Assoc); if Flags.Warn_Binding and then not Get_Artificial_Flag (Assoc) then Warning_Msg_Elab @@ -387,6 +387,7 @@ package body Configuration is for I in Natural loop Inst := Get_Nth_Element (Inst_List, I); exit when Inst = Null_Iir; + Inst := Get_Named_Entity (Inst); Err := False; -- Mark component ports not associated. @@ -394,7 +395,7 @@ package body Configuration is Assoc := Inst_Chain; while Assoc /= Null_Iir loop if Get_Kind (Assoc) = Iir_Kind_Association_Element_Open then - Formal := Get_Base_Name (Get_Formal (Assoc)); + Formal := Get_Association_Interface (Assoc); Set_Open_Flag (Formal, True); Err := True; end if; @@ -406,15 +407,15 @@ package body Configuration is if Err then Assoc := Conf_Chain; while Assoc /= Null_Iir loop - Formal := Get_Base_Name (Get_Formal (Assoc)); + Formal := Get_Association_Interface (Assoc); if Get_Kind (Assoc) = Iir_Kind_Association_Element_Open then Actual := Null_Iir; else Actual := Get_Actual (Assoc); Actual := Sem_Names.Name_To_Object (Actual); - end if; - if Actual /= Null_Iir then - Actual := Get_Base_Name (Actual); + if Actual /= Null_Iir then + Actual := Get_Object_Prefix (Actual); + end if; end if; if Actual /= Null_Iir and then Get_Open_Flag (Actual) @@ -424,7 +425,7 @@ package body Configuration is Assoc_1 := Inst_Chain; while Assoc_1 /= Null_Iir loop if Get_Kind (Assoc_1) = Iir_Kind_Association_Element_Open - and then Actual = Get_Base_Name (Get_Formal (Assoc_1)) + and then Actual = Get_Association_Interface (Assoc_1) then Err := Check_Open_Port (Formal, Assoc_1); exit; @@ -439,7 +440,7 @@ package body Configuration is Assoc := Inst_Chain; while Assoc /= Null_Iir loop if Get_Kind (Assoc) = Iir_Kind_Association_Element_Open then - Formal := Get_Base_Name (Get_Formal (Assoc)); + Formal := Get_Association_Interface (Assoc); Set_Open_Flag (Formal, False); end if; Assoc := Get_Chain (Assoc); @@ -454,10 +455,9 @@ package body Configuration is -- binding must be added if required. procedure Add_Design_Binding_Indication (Conf : Iir; Add_Default : Boolean) is - Bind : Iir_Binding_Indication; + Bind : constant Iir_Binding_Indication := Get_Binding_Indication (Conf); Inst : Iir; begin - Bind := Get_Binding_Indication (Conf); if Bind = Null_Iir then if Flags.Warn_Binding then Inst := Get_First_Element (Get_Instantiation_List (Conf)); @@ -603,7 +603,7 @@ package body Configuration is -- Check port. El := Get_Port_Chain (Entity); while El /= Null_Iir loop - if not Iirs_Utils.Is_Fully_Constrained_Type (Get_Type (El)) + if not Is_Fully_Constrained_Type (Get_Type (El)) and then Get_Default_Value (El) = Null_Iir then Error ("(" & Disp_Node (El) diff --git a/disp_tree.adb b/disp_tree.adb index 8ac5108a6..db2102a33 100644 --- a/disp_tree.adb +++ b/disp_tree.adb @@ -15,15 +15,24 @@ -- 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. + +-- Display trees in raw form. Mainly used for debugging. + with Ada.Text_IO; use Ada.Text_IO; with Name_Table; -with Iirs_Utils; use Iirs_Utils; with Tokens; with Errorout; with Files_Map; with PSL.Dump_Tree; +-- Do not add a use clause for iirs_utils, as it may crash for ill-formed +-- trees, which is annoying while debugging. +with Iirs_Utils; + package body Disp_Tree is + function Is_Anonymous_Type_Definition (Def : Iir) return Boolean + renames Iirs_Utils.Is_Anonymous_Type_Definition; + procedure Disp_Tab (Tab: Natural) is Blanks : constant String (1 .. Tab) := (others => ' '); begin @@ -192,9 +201,6 @@ package body Disp_Tree is Put ("library declaration"); Disp_Identifier (Tree); - when Iir_Kind_Proxy => - Put_Line ("proxy"); - when Iir_Kind_Waveform_Element => Put_Line ("waveform_element"); @@ -433,7 +439,7 @@ package body Disp_Tree is Put_Line ("floating_point_literal: " & Iir_Fp64'Image (Get_Fp_Value (Tree))); when Iir_Kind_String_Literal => - Put_Line ("string_literal: " & Image_String_Lit (Tree)); + Put_Line ("string_literal: " & Iirs_Utils.Image_String_Lit (Tree)); when Iir_Kind_Unit_Declaration => Put ("physical unit"); Disp_Identifier (Tree); @@ -708,8 +714,6 @@ package body Disp_Tree is end if; Header ("entity_name:"); Disp_Tree (Get_Entity_Name (Tree), Ntab, True); - Header ("entity:"); - Disp_Tree_Flat (Get_Entity (Tree), Ntab); Header ("declaration_chain:"); Disp_Tree_Chain (Get_Declaration_Chain (Tree), Ntab); Header ("concurrent_statements:"); @@ -718,8 +722,8 @@ package body Disp_Tree is Disp_Tree_Flat (Get_Default_Configuration_Declaration (Tree), Ntab); when Iir_Kind_Configuration_Declaration => - Header ("entity:"); - Disp_Tree_Flat (Get_Entity (Tree), Ntab); + Header ("entity_Name:"); + Disp_Tree_Flat (Get_Entity_Name (Tree), Ntab); Header ("declaration_chain:"); Disp_Tree_Chain (Get_Declaration_Chain (Tree), Ntab); Header ("block_configuration:"); @@ -735,13 +739,13 @@ package body Disp_Tree is Disp_Tree_Chain (Get_Generic_Map_Aspect_Chain (Tree), Ntab); when Iir_Kind_Entity_Aspect_Entity => - Header ("entity:"); - Disp_Tree_Flat (Get_Entity (Tree), Ntab); + Header ("entity_name:"); + Disp_Tree_Flat (Get_Entity_Name (Tree), Ntab); Header ("architecture:"); Disp_Tree_Flat (Get_Architecture (Tree), Ntab); when Iir_Kind_Entity_Aspect_Configuration => Header ("configuration:"); - Disp_Tree (Get_Configuration (Tree), Ntab, True); + Disp_Tree (Get_Configuration_Name (Tree), Ntab, True); when Iir_Kind_Entity_Aspect_Open => null; @@ -814,7 +818,7 @@ package body Disp_Tree is Header ("signal_list:"); Disp_Tree_List (Get_Signal_List (Tree), Ntab, True); Header ("type_mark:"); - Disp_Tree (Get_Type (Tree), Ntab, True); + Disp_Tree (Get_Type_Mark (Tree), Ntab, True); Header ("time expression:"); Disp_Tree (Get_Expression (Tree), Ntab); @@ -1072,8 +1076,8 @@ package body Disp_Tree is if Flat_Decl then return; end if; - Header ("type:"); - Disp_Tree (Get_Type (Tree), Ntab, True); + Header ("type mark:"); + Disp_Tree (Get_Type_Mark (Tree), Ntab, True); when Iir_Kind_Terminal_Declaration => if Flat_Decl then return; @@ -1183,7 +1187,7 @@ package body Disp_Tree is Header ("name:"); Disp_Tree (Get_Name (Tree), Ntab); Header ("signature:"); - Disp_Tree (Get_Signature (Tree), Ntab, True); + Disp_Tree (Get_Alias_Signature (Tree), Ntab, True); when Iir_Kind_Group_Template_Declaration => Header ("entity_class_entry:"); @@ -1240,7 +1244,7 @@ package body Disp_Tree is Disp_Tree (Get_Base_Type (Tree), Ntab, True); end if; Header ("type mark:"); - Disp_Tree (Get_Type_Mark (Tree), Ntab, True); + Disp_Tree (Get_Subtype_Type_Mark (Tree), Ntab, True); Header ("resolution function:"); Disp_Tree_Flat (Get_Resolution_Function (Tree), Ntab); Header ("range constraint:"); @@ -1262,6 +1266,9 @@ package body Disp_Tree is & Iir_Direction'Image (Get_Direction (Tree))); Header ("type:"); Disp_Tree (Get_Type (Tree), Ntab, True); + Header ("origin:"); + Disp_Tree (Get_Range_Origin (Tree), Ntab, True); + when Iir_Kind_Array_Subtype_Definition => if Flat_Decl and then Get_Type_Declarator (Tree) /= Null_Iir then return; @@ -1296,11 +1303,11 @@ package body Disp_Tree is Disp_Tree (Base, Ntab, Fl); end; Header ("type mark:"); - Disp_Tree (Get_Type_Mark (Tree), Ntab, True); + Disp_Tree (Get_Subtype_Type_Mark (Tree), Ntab, True); Header ("index_subtype_list:"); Disp_Tree_List (Get_Index_Subtype_List (Tree), Ntab, True); - Header ("element_subtype:"); - Disp_Tree (Get_Element_Subtype (Tree), Ntab, True); + Header ("element_subtype_indication:"); + Disp_Tree (Get_Element_Subtype_Indication (Tree), Ntab, True); Header ("resolution function:"); Disp_Tree_Flat (Get_Resolution_Function (Tree), Ntab); when Iir_Kind_Array_Type_Definition => @@ -1317,8 +1324,8 @@ package body Disp_Tree is Disp_Flag (Get_Has_Signal_Flag (Tree)); Header ("index_subtype_list:"); Disp_Tree_List (Get_Index_Subtype_List (Tree), Ntab, True); - Header ("element_subtype:"); - Disp_Tree (Get_Element_Subtype (Tree), Ntab, True); + Header ("element_subtype_indication:"); + Disp_Tree (Get_Element_Subtype_Indication (Tree), Ntab, True); when Iir_Kind_Record_Type_Definition => if Flat_Decl and then Get_Type_Declarator (Tree) /= Null_Iir then return; @@ -1348,7 +1355,7 @@ package body Disp_Tree is Header ("base type:"); Disp_Tree (Get_Base_Type (Tree), Ntab, True); Header ("type mark:"); - Disp_Tree (Get_Type_Mark (Tree), Ntab, True); + Disp_Tree (Get_Subtype_Type_Mark (Tree), Ntab, True); Header ("resolution function:"); Disp_Tree_Flat (Get_Resolution_Function (Tree), Ntab); Header ("constraint_state: " @@ -1403,8 +1410,8 @@ package body Disp_Tree is Disp_Tree_Flat (Get_Type_Declarator (Tree), Ntab); Header ("base type:"); Disp_Tree (Get_Base_Type (Tree), Ntab, True); - Header ("type mark:"); - Disp_Tree (Get_Type_Mark (Tree), Ntab, True); + Header ("designated subtype indication:"); + Disp_Tree (Get_Designated_Subtype_Indication (Tree), Ntab); when Iir_Kind_Incomplete_Type_Definition => Header ("staticness: ", False); @@ -1419,8 +1426,8 @@ package body Disp_Tree is Disp_Type_Staticness (Tree); Header ("declarator:"); Disp_Tree_Flat (Get_Type_Declarator (Tree), Ntab); - Header ("type mark:"); - Disp_Tree_Flat (Get_Type_Mark (Tree), Ntab); + Header ("file type mark:"); + Disp_Tree_Flat (Get_File_Type_Mark (Tree), Ntab); when Iir_Kind_Protected_Type_Declaration => Header ("staticness: ", False); Disp_Type_Staticness (Tree); @@ -1584,8 +1591,8 @@ package body Disp_Tree is Header ("elsif:"); Disp_Tree (Get_Else_Clause (Tree), Tab); when Iir_Kind_For_Loop_Statement => - Header ("iterator:"); - Disp_Tree (Get_Iterator_Scheme (Tree), Ntab); + Header ("parameter specification:"); + Disp_Tree (Get_Parameter_Specification (Tree), Ntab); Header ("statements:"); Disp_Tree_Chain (Get_Sequential_Statement_Chain (Tree), Ntab); Header ("attribute_value_chain:"); @@ -1659,6 +1666,8 @@ package body Disp_Tree is Header ("attribute_value_chain:"); Disp_Tree_Flat_Chain (Get_Attribute_Value_Chain (Tree), Ntab); when Iir_Kind_Procedure_Call => + Header ("prefix:"); + Disp_Tree (Get_Prefix (Tree), Ntab); Header ("implementation:"); Disp_Tree (Get_Implementation (Tree), Ntab, True); Header ("method_object:"); @@ -1667,8 +1676,8 @@ package body Disp_Tree is Disp_Tree_Chain (Get_Parameter_Association_Chain (Tree), Ntab); when Iir_Kind_Exit_Statement | Iir_Kind_Next_Statement => - Header ("loop:"); - Disp_Tree_Flat (Get_Loop (Tree), Ntab); + Header ("loop_label:"); + Disp_Tree (Get_Loop_Label (Tree), Ntab); Header ("condition:"); Disp_Tree (Get_Condition (Tree), Ntab); Header ("attribute_value_chain:"); @@ -1704,6 +1713,8 @@ package body Disp_Tree is Disp_Expr_Staticness (Tree); Header ("type:"); Disp_Tree_Flat (Get_Type (Tree), Ntab); + Header ("prefix:"); + Disp_Tree (Get_Prefix (Tree), Ntab); Header ("implementation:"); Disp_Tree_Flat (Get_Implementation (Tree), Ntab); Header ("method_object:"); @@ -1731,6 +1742,8 @@ package body Disp_Tree is Disp_Expr_Staticness (Tree); Header ("type:"); Disp_Tree_Flat (Get_Type (Tree), Ntab); + Header ("type_mark:"); + Disp_Tree_Flat (Get_Type_Mark (Tree), Ntab); Header ("expression:"); Disp_Tree (Get_Expression (Tree), Ntab, True); when Iir_Kind_Allocator_By_Expression => @@ -1744,6 +1757,8 @@ package body Disp_Tree is Header ("subtype indication:"); Disp_Tree (Get_Expression (Tree), Ntab, True); when Iir_Kind_Selected_Element => + Header ("staticness:", false); + Disp_Name_Staticness (Tree); Header ("prefix:"); Disp_Tree (Get_Prefix (Tree), Ntab, True); Header ("selected element:"); @@ -1784,9 +1799,11 @@ package body Disp_Tree is null; when Iir_Kind_Simple_Name => Header ("staticness:", false); - Disp_Expr_Staticness (Tree); + Disp_Name_Staticness (Tree); Header ("type:"); Disp_Tree (Get_Type (Tree), Ntab, True); + Header ("named_entity:"); + Disp_Tree_Flat (Get_Named_Entity (Tree), Ntab); when Iir_Kind_Indexed_Name => Header ("staticness:", false); Disp_Name_Staticness (Tree); @@ -1820,12 +1837,14 @@ package body Disp_Tree is Disp_Tree (Get_Prefix (Tree), Ntab, True); Header ("identifier: ", False); Disp_Ident (Get_Identifier (Tree)); + Header ("named_entity:"); + Disp_Tree_Flat (Get_Named_Entity (Tree), Ntab); when Iir_Kind_Attribute_Name => Header ("prefix:"); Disp_Tree (Get_Prefix (Tree), Ntab, True); Header ("signature:"); - Disp_Tree (Get_Signature (Tree), Ntab); + Disp_Tree (Get_Attribute_Signature (Tree), Ntab); when Iir_Kind_Base_Attribute => Header ("prefix:"); @@ -1846,7 +1865,7 @@ package body Disp_Tree is when Iir_Kind_Image_Attribute | Iir_Kind_Value_Attribute => Header ("prefix:"); - Disp_Tree_Flat (Get_Prefix (Tree), Ntab); + Disp_Tree (Get_Prefix (Tree), Ntab); Header ("type:"); Disp_Tree_Flat (Get_Type (Tree), Ntab); Header ("parameter:"); @@ -1860,7 +1879,7 @@ package body Disp_Tree is Header ("staticness:", false); Disp_Expr_Staticness (Tree); Header ("prefix:"); - Disp_Tree_Flat (Get_Prefix (Tree), Ntab); + Disp_Tree (Get_Prefix (Tree), Ntab); Header ("type:"); Disp_Tree_Flat (Get_Type (Tree), Ntab); Header ("parameter:"); @@ -1999,9 +2018,6 @@ package body Disp_Tree is Header ("origin:"); Disp_Tree (Get_Literal_Origin (Tree), Ntab, True); - when Iir_Kind_Proxy => - Header ("proxy:"); - Disp_Tree_Flat (Get_Proxy (Tree), Ntab); when Iir_Kind_Entity_Class => null; end case; diff --git a/disp_vhdl.adb b/disp_vhdl.adb index fd571ae98..c0a4f9697 100644 --- a/disp_vhdl.adb +++ b/disp_vhdl.adb @@ -16,10 +16,10 @@ -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- 02111-1307, USA. - --- Disp an iir tree. --- Try to be as pretty as possible, and to keep line numbers and positions --- of the identifiers. +-- Re-print a tree as VHDL sources. Except for comments and parenthesis, the +-- sequence of tokens displayed is the same as the sequence of tokens in the +-- input file. If parenthesis are kept by the parser, the only differences +-- are comments and layout. with GNAT.OS_Lib; with Std_Package; with Flags; use Flags; @@ -112,10 +112,13 @@ package body Disp_Vhdl is procedure Set_Col (P : Count) is begin - if Col /= 1 then + if Col = P then + return; + end if; + if Col >= P then New_Line; end if; - Put ((1 .. P - 1 => ' ')); + Put ((Col .. P - 1 => ' ')); end Set_Col; procedure Disp_Ident (Id: Name_Id) is @@ -123,7 +126,8 @@ package body Disp_Vhdl is Put (Name_Table.Image (Id)); end Disp_Ident; - procedure Disp_Identifier (Node : Iir) is + procedure Disp_Identifier (Node : Iir) + is Ident : Name_Id; begin Ident := Get_Identifier (Node); @@ -134,17 +138,6 @@ package body Disp_Vhdl is end if; end Disp_Identifier; - procedure Disp_Label (Node : Iir) is - Ident : Name_Id; - begin - Ident := Get_Label (Node); - if Ident /= Null_Identifier then - Disp_Ident (Ident); - else - Put ("<anonymous>"); - end if; - end Disp_Label; - procedure Disp_Character_Literal (Lit: Iir_Character_Literal) is begin Put (''' & Name_Table.Get_Character (Get_Identifier (Lit)) & '''); @@ -215,7 +208,11 @@ package body Disp_Vhdl is | Iir_Kind_Implicit_Procedure_Declaration => Disp_Identifier (Decl); when Iir_Kind_Physical_Subtype_Definition - | Iir_Kind_Enumeration_Type_Definition => + | Iir_Kind_Enumeration_Type_Definition + | Iir_Kind_Physical_Type_Definition + | Iir_Kind_Record_Type_Definition + | Iir_Kind_Protected_Type_Declaration => + -- Used for 'end' DECL_NAME. Disp_Identifier (Get_Type_Declarator (Decl)); when Iir_Kind_Component_Instantiation_Statement => Disp_Ident (Get_Label (Decl)); @@ -226,33 +223,28 @@ package body Disp_Vhdl is Disp_Identifier (Decl); when Iir_Kind_Block_Statement | Iir_Kind_Generate_Statement => - Disp_Label (Decl); + declare + Ident : constant Name_Id := Get_Label (Decl); + begin + if Ident /= Null_Identifier then + Disp_Ident (Ident); + else + Put ("<anonymous>"); + end if; + end; + when Iir_Kind_Package_Body => + Disp_Identifier (Get_Package (Decl)); + when Iir_Kind_Procedure_Body + | Iir_Kind_Function_Body => + Disp_Function_Name (Get_Subprogram_Specification (Decl)); + when Iir_Kind_Protected_Type_Body => + Disp_Identifier + (Get_Type_Declarator (Get_Protected_Type_Declaration (Decl))); when others => Error_Kind ("disp_name_of", Decl); end case; end Disp_Name_Of; - procedure Disp_Range (Rng : Iir) is - begin - case Get_Kind (Rng) is - when Iir_Kind_Range_Expression => - Disp_Expression (Get_Left_Limit (Rng)); - if Get_Direction (Rng) = Iir_To then - Put (" to "); - else - Put (" downto "); - end if; - Disp_Expression (Get_Right_Limit (Rng)); - when Iir_Kind_Range_Array_Attribute => - Disp_Parametered_Attribute ("range", Rng); - when Iir_Kind_Reverse_Range_Array_Attribute => - Disp_Parametered_Attribute ("reverse_range", Rng); - when others => - Disp_Subtype_Indication (Rng); - -- Disp_Name_Of (Get_Type_Declarator (Decl)); - end case; - end Disp_Range; - procedure Disp_Name (Name: Iir) is begin case Get_Kind (Name) is @@ -262,12 +254,21 @@ package body Disp_Vhdl is when Iir_Kind_Dereference => Disp_Name (Get_Prefix (Name)); Put (".all"); - when Iir_Kind_Simple_Name => + when Iir_Kind_Simple_Name + | Iir_Kind_Character_Literal => Put (Iirs_Utils.Image_Identifier (Name)); + when Iir_Kind_Operator_Symbol => + Disp_Function_Name (Name); when Iir_Kind_Selected_Name => Disp_Name (Get_Prefix (Name)); Put ("."); - Disp_Ident (Get_Identifier (Name)); + Disp_Function_Name (Name); + when Iir_Kind_Parenthesis_Name => + Disp_Name (Get_Prefix (Name)); + Disp_Association_Chain (Get_Association_Chain (Name)); + when Iir_Kind_Base_Attribute => + Disp_Name (Get_Prefix (Name)); + Put ("'base"); when Iir_Kind_Type_Declaration | Iir_Kind_Subtype_Declaration | Iir_Kind_Enumeration_Literal @@ -287,16 +288,119 @@ package body Disp_Vhdl is end case; end Disp_Name; - procedure Disp_Use_Clause (Clause: Iir_Use_Clause) is + procedure Disp_Range (Rng : Iir) is + begin + case Get_Kind (Rng) is + when Iir_Kind_Range_Expression => + declare + Origin : constant Iir := Get_Range_Origin (Rng); + begin + if Origin /= Null_Iir then + Disp_Expression (Origin); + else + Disp_Expression (Get_Left_Limit (Rng)); + if Get_Direction (Rng) = Iir_To then + Put (" to "); + else + Put (" downto "); + end if; + Disp_Expression (Get_Right_Limit (Rng)); + end if; + end; + when Iir_Kind_Range_Array_Attribute => + Disp_Parametered_Attribute ("range", Rng); + when Iir_Kind_Reverse_Range_Array_Attribute => + Disp_Parametered_Attribute ("reverse_range", Rng); + when Iir_Kind_Simple_Name + | Iir_Kind_Selected_Name => + Disp_Name (Rng); + when others => + Disp_Subtype_Indication (Rng); + -- Disp_Name_Of (Get_Type_Declarator (Decl)); + end case; + end Disp_Range; + + procedure Disp_After_End (Decl : Iir; Name : String) is + begin + if Get_End_Has_Reserved_Id (Decl) then + Put (' '); + Put (Name); + end if; + if Get_End_Has_Identifier (Decl) then + Put (' '); + Disp_Name_Of (Decl); + end if; + Put (';'); + New_Line; + end Disp_After_End; + + procedure Disp_End (Decl : Iir; Name : String) is + begin + Put ("end"); + Disp_After_End (Decl, Name); + end Disp_End; + + procedure Disp_End_Label (Stmt : Iir; Name : String) is + begin + Put ("end"); + Put (' '); + Put (Name); + if Get_End_Has_Identifier (Stmt) then + Put (' '); + Disp_Ident (Get_Label (Stmt)); + end if; + Put (';'); + New_Line; + end Disp_End_Label; + + procedure Disp_Use_Clause (Clause: Iir_Use_Clause) + is + Name : Iir; begin Put ("use "); - Disp_Name (Get_Selected_Name (Clause)); + Name := Clause; + loop + Disp_Name (Get_Selected_Name (Name)); + Name := Get_Use_Clause_Chain (Name); + exit when Name = Null_Iir; + Put (", "); + end loop; Put_Line (";"); end Disp_Use_Clause; -- Disp the resolution function (if any) of type definition DEF. procedure Disp_Resolution_Function (Subtype_Def: Iir) is + -- Return TRUE iff subtype indication DEF has a resolution function + -- that differ from its type mark. + function Has_Own_Resolution_Function (Def : Iir) return Boolean is + begin + -- Only subtype indications may have their own resolution functions. + if Get_Kind (Def) not in Iir_Kinds_Subtype_Definition then + return False; + end if; + + -- A resolution function is present. + if Get_Resolution_Function (Def) /= Null_Iir then + return True; + end if; + + case Get_Kind (Def) is + when Iir_Kind_Array_Subtype_Definition => + declare + El_Def : constant Iir := Get_Element_Subtype (Def); + begin + if El_Def /= Get_Element_Subtype (Get_Base_Type (Def)) then + return Has_Own_Resolution_Function (El_Def); + else + return False; + end if; + end; + when others => + Error_Kind ("disp_resolution_function(1)", Def); + end case; + end Has_Own_Resolution_Function; + procedure Inner (Def : Iir) is Decl: Iir; @@ -312,14 +416,17 @@ package body Disp_Vhdl is Inner (Get_Element_Subtype (Def)); Put (')'); when others => - Error_Kind ("disp_resolution_function", Def); + Error_Kind ("disp_resolution_function(2)", Def); end case; end if; end if; end Inner; begin - if Get_Resolved_Flag (Subtype_Def) then + if not Get_Resolved_Flag (Subtype_Def) then + return; + end if; + if Has_Own_Resolution_Function (Subtype_Def) then Inner (Subtype_Def); Put (' '); end if; @@ -373,36 +480,33 @@ package body Disp_Vhdl is procedure Disp_Array_Element_Constraint (Def : Iir; Type_Mark : Iir) is + Def_El : constant Iir := Get_Element_Subtype (Def); + Tm_El : constant Iir := Get_Element_Subtype (Type_Mark); + Has_Index : constant Boolean := Get_Index_Constraint_Flag (Def); + Has_Own_Element_Subtype : constant Boolean := Def_El /= Tm_El; Index : Iir; - Def_El : Iir; - Tm_El : Iir; - Has_Index : Boolean; - Has_Own_Element_Subtype : Boolean; begin - Has_Index := Get_Index_Constraint_Flag (Def); - Def_El := Get_Element_Subtype (Def); - Tm_El := Get_Element_Subtype (Type_Mark); - Has_Own_Element_Subtype := Def_El /= Tm_El; - if not Has_Index and not Has_Own_Element_Subtype then return; end if; - Put (" ("); - if Has_Index then - for I in Natural loop - Index := Get_Nth_Element (Get_Index_Subtype_List (Def), I); - exit when Index = Null_Iir; - if I /= 0 then - Put (", "); - end if; - --Disp_Expression (Get_Range_Constraint (Index)); - Disp_Range (Index); - end loop; - else - Put ("open"); + if Get_Constraint_State (Type_Mark) /= Fully_Constrained then + Put (" ("); + if Has_Index then + for I in Natural loop + Index := Get_Nth_Element (Get_Index_Subtype_List (Def), I); + exit when Index = Null_Iir; + if I /= 0 then + Put (", "); + end if; + --Disp_Expression (Get_Range_Constraint (Index)); + Disp_Range (Index); + end loop; + else + Put ("open"); + end if; + Put (")"); end if; - Put (")"); if Has_Own_Element_Subtype and then Get_Kind (Def_El) in Iir_Kinds_Composite_Type_Definition @@ -466,6 +570,11 @@ package body Disp_Vhdl is Base_Type : Iir; Decl : Iir; begin + if Get_Kind (Def) in Iir_Kinds_Denoting_Name then + Disp_Name (Def); + return; + end if; + Decl := Get_Type_Declarator (Def); if not Full_Decl and then Decl /= Null_Iir then Disp_Name_Of (Decl); @@ -476,10 +585,10 @@ package body Disp_Vhdl is Disp_Resolution_Function (Def); -- type mark. - Type_Mark := Get_Type_Mark (Def); + Type_Mark := Get_Subtype_Type_Mark (Def); if Type_Mark /= Null_Iir then - Decl := Get_Type_Declarator (Type_Mark); - Disp_Name_Of (Decl); + Disp_Name (Type_Mark); + Type_Mark := Get_Type (Type_Mark); end if; Base_Type := Get_Base_Type (Def); @@ -501,9 +610,23 @@ package body Disp_Vhdl is Disp_Tolerance_Opt (Def); end if; when Iir_Kind_Access_Type_Definition => - Disp_Type (Get_Type_Mark (Def)); + declare + Des_Ind : constant Iir := + Get_Designated_Subtype_Indication (Def); + begin + if Des_Ind /= Null_Iir then + pragma Assert + (Get_Kind (Des_Ind) = Iir_Kind_Array_Subtype_Definition); + Disp_Array_Element_Constraint + (Des_Ind, Get_Designated_Type (Base_Type)); + end if; + end; when Iir_Kind_Array_Type_Definition => - Disp_Array_Element_Constraint (Def, Type_Mark); + if Type_Mark = Null_Iir then + Disp_Array_Element_Constraint (Def, Def); + else + Disp_Array_Element_Constraint (Def, Type_Mark); + end if; when Iir_Kind_Record_Type_Definition => Disp_Record_Element_Constraint (Def); when others => @@ -553,6 +676,15 @@ package body Disp_Vhdl is Put (";"); end Disp_Enumeration_Subtype_Definition; + procedure Disp_Discrete_Range (Iterator: Iir) is + begin + if Get_Kind (Iterator) in Iir_Kinds_Subtype_Definition then + Disp_Subtype_Indication (Iterator); + else + Disp_Range (Iterator); + end if; + end Disp_Discrete_Range; + procedure Disp_Array_Subtype_Definition (Def: Iir_Array_Subtype_Definition) is @@ -567,7 +699,7 @@ package body Disp_Vhdl is if I /= 0 then Put (", "); end if; - Disp_Subtype_Indication (Index); + Disp_Discrete_Range (Index); end loop; Put (") of "); Disp_Subtype_Indication (Get_Element_Subtype (Def)); @@ -583,11 +715,11 @@ package body Disp_Vhdl is if I /= 0 then Put (", "); end if; - Disp_Subtype_Indication (Index); + Disp_Name (Index); Put (" range <>"); end loop; Put (") of "); - Disp_Type (Get_Element_Subtype (Def)); + Disp_Subtype_Indication (Get_Element_Subtype_Indication (Def)); Put (";"); end Disp_Array_Type_Definition; @@ -605,37 +737,15 @@ package body Disp_Vhdl is Error_Kind ("disp_physical_literal", Lit); end case; Put (' '); - Disp_Identifier (Get_Unit_Name (Lit)); + Disp_Name (Get_Unit_Name (Lit)); end Disp_Physical_Literal; procedure Disp_Physical_Subtype_Definition - (Def: Iir_Physical_Subtype_Definition; Indent: Count) - is - Base_Type: Iir; - Unit: Iir_Unit_Declaration; + (Def: Iir_Physical_Subtype_Definition) is begin Disp_Resolution_Function (Def); Put ("range "); Disp_Expression (Get_Range_Constraint (Def)); - Base_Type := Get_Base_Type (Def); - if Get_Type_Declarator (Base_Type) = Get_Type_Declarator (Def) then - Put_Line (" units"); - Set_Col (Indent + Indentation); - Unit := Get_Unit_Chain (Base_Type); - Disp_Identifier (Unit); - Put_Line (";"); - Unit := Get_Chain (Unit); - while Unit /= Null_Iir loop - Set_Col (Indent + Indentation); - Disp_Identifier (Unit); - Put (" = "); - Disp_Physical_Literal (Get_Physical_Literal (Unit)); - Put_Line (";"); - Unit := Get_Chain (Unit); - end loop; - Set_Col (Indent); - Put ("end units;"); - end if; end Disp_Physical_Subtype_Definition; procedure Disp_Record_Type_Definition @@ -643,22 +753,31 @@ package body Disp_Vhdl is is List : Iir_List; El: Iir_Element_Declaration; + Reindent : Boolean; begin Put_Line ("record"); Set_Col (Indent); - Put_Line ("begin"); List := Get_Elements_Declaration_List (Def); + Reindent := True; for I in Natural loop El := Get_Nth_Element (List, I); exit when El = Null_Iir; - Set_Col (Indent + Indentation); + if Reindent then + Set_Col (Indent + Indentation); + end if; Disp_Identifier (El); - Put (" : "); - Disp_Subtype_Indication (Get_Type (El)); - Put_Line (";"); + if Get_Has_Identifier_List (El) then + Put (", "); + Reindent := False; + else + Put (" : "); + Disp_Subtype_Indication (Get_Type (El)); + Put_Line (";"); + Reindent := True; + end if; end loop; Set_Col (Indent); - Put ("end record;"); + Disp_End (Def, "record"); end Disp_Record_Type_Definition; procedure Disp_Designator_List (List: Iir_List) is @@ -699,22 +818,22 @@ package body Disp_Vhdl is when Iir_Kind_Array_Subtype_Definition => Disp_Array_Subtype_Definition (Def); when Iir_Kind_Physical_Subtype_Definition => - Disp_Physical_Subtype_Definition (Def, Indent); + Disp_Physical_Subtype_Definition (Def); when Iir_Kind_Record_Type_Definition => Disp_Record_Type_Definition (Def, Indent); when Iir_Kind_Access_Type_Definition => Put ("access "); - Disp_Subtype_Indication (Get_Designated_Type (Def)); + Disp_Subtype_Indication (Get_Designated_Subtype_Indication (Def)); Put (';'); when Iir_Kind_File_Type_Definition => Put ("file of "); - Disp_Subtype_Indication (Get_Type_Mark (Def)); + Disp_Subtype_Indication (Get_File_Type_Mark (Def)); Put (';'); when Iir_Kind_Protected_Type_Declaration => Put_Line ("protected"); Disp_Declaration_Chain (Def, Indent + Indentation); Set_Col (Indent); - Put ("end protected;"); + Disp_End (Def, "protected"); when Iir_Kind_Integer_Type_Definition => Put ("<integer base type>"); when Iir_Kind_Floating_Type_Definition => @@ -749,48 +868,83 @@ package body Disp_Vhdl is procedure Disp_Anonymous_Type_Declaration (Decl: Iir_Anonymous_Type_Declaration) is - Indent: Count; - Def : Iir; + Def : constant Iir := Get_Type_Definition (Decl); + Indent: constant Count := Col; begin - Indent := Col; - Put ("-- type "); - Disp_Name_Of (Decl); + Put ("type "); + Disp_Identifier (Decl); Put (" is "); - Def := Get_Type_Definition (Decl); - Disp_Type_Definition (Def, Indent); - if Get_Kind (Def) = Iir_Kind_Physical_Type_Definition then - declare - Unit : Iir_Unit_Declaration; - begin - Put_Line (" units"); - Set_Col (Indent); - Put ("-- "); - Unit := Get_Unit_Chain (Def); - Disp_Identifier (Unit); - Put_Line (";"); - Unit := Get_Chain (Unit); - while Unit /= Null_Iir loop - Set_Col (Indent); - Put ("-- "); + case Get_Kind (Def) is + when Iir_Kind_Array_Type_Definition => + declare + St : constant Iir := Get_Subtype_Definition (Decl); + Indexes : constant Iir_List := Get_Index_Subtype_List (St); + Index : Iir; + begin + Put ("array ("); + for I in Natural loop + Index := Get_Nth_Element (Indexes, I); + exit when Index = Null_Iir; + if I /= 0 then + Put (", "); + end if; + Disp_Discrete_Range (Index); + end loop; + Put (") of "); + Disp_Subtype_Indication (Get_Element_Subtype_Indication (Def)); + Put (";"); + end; + when Iir_Kind_Physical_Type_Definition => + declare + St : constant Iir := Get_Subtype_Definition (Decl); + Unit : Iir_Unit_Declaration; + begin + Put ("range "); + Disp_Expression (Get_Range_Constraint (St)); + Put_Line (" units"); + Set_Col (Indent + Indentation); + Unit := Get_Unit_Chain (Def); Disp_Identifier (Unit); - Put (" = "); - Disp_Physical_Literal (Get_Physical_Literal (Unit)); Put_Line (";"); Unit := Get_Chain (Unit); - end loop; - Set_Col (Indent); - Put ("-- end units;"); - end; - end if; + while Unit /= Null_Iir loop + Set_Col (Indent + Indentation); + Disp_Identifier (Unit); + Put (" = "); + Disp_Expression (Get_Physical_Literal (Unit)); + Put_Line (";"); + Unit := Get_Chain (Unit); + end loop; + Set_Col (Indent); + Disp_End (Def, "units"); + end; + when Iir_Kind_Floating_Type_Definition + | Iir_Kind_Integer_Type_Definition => + declare + St : constant Iir := Get_Subtype_Definition (Decl); + begin + Put ("range "); + Disp_Expression (Get_Range_Constraint (St)); + Put (";"); + end; + when others => + Disp_Type_Definition (Def, Indent); + end case; New_Line; end Disp_Anonymous_Type_Declaration; - procedure Disp_Subtype_Declaration (Decl: in Iir_Subtype_Declaration) is + procedure Disp_Subtype_Declaration (Decl: in Iir_Subtype_Declaration) + is + Def : constant Iir := Get_Type (Decl); + Bt_Decl : constant Iir := Get_Type_Declarator (Get_Base_Type (Def)); begin + if Get_Identifier (Decl) = Get_Identifier (Bt_Decl) then + Put ("-- "); + end if; Put ("subtype "); Disp_Name_Of (Decl); Put (" is "); - Disp_Subtype_Indication (Get_Type (Decl), True); + Disp_Subtype_Indication (Def, True); Put_Line (";"); end Disp_Subtype_Declaration; @@ -884,41 +1038,55 @@ package body Disp_Vhdl is end case; end Disp_Signal_Kind; - procedure Disp_Interface_Declaration (Inter: Iir) + procedure Disp_Interface_Class (Inter: Iir) is + begin + if (Get_Lexical_Layout (Inter) and Iir_Lexical_Has_Class) /= 0 then + case Get_Kind (Inter) is + when Iir_Kind_Signal_Interface_Declaration => + Put ("signal "); + when Iir_Kind_Variable_Interface_Declaration => + Put ("variable "); + when Iir_Kind_Constant_Interface_Declaration => + Put ("constant "); + when Iir_Kind_File_Interface_Declaration => + Put ("file "); + when others => + Error_Kind ("disp_interface_class", Inter); + end case; + end if; + end Disp_Interface_Class; + + procedure Disp_Interface_Mode_And_Type (Inter: Iir) is - Default: Iir; + Default: constant Iir := Get_Default_Value (Inter); + Ind : constant Iir := Get_Subtype_Indication (Inter); begin - case Get_Kind (Inter) is - when Iir_Kind_Signal_Interface_Declaration => - Put ("signal "); - when Iir_Kind_Variable_Interface_Declaration => - Put ("variable "); - when Iir_Kind_Constant_Interface_Declaration => - Put ("constant "); - when Iir_Kind_File_Interface_Declaration => - Put ("file "); - when others => - Error_Kind ("disp_interface_declaration", Inter); - end case; - Disp_Name_Of (Inter); Put (": "); if (Get_Lexical_Layout (Inter) and Iir_Lexical_Has_Mode) /= 0 then Disp_Mode (Get_Mode (Inter)); end if; - Disp_Type (Get_Type (Inter)); + if Ind = Null_Iir then + -- For implicit subprogram + Disp_Type (Get_Type (Inter)); + else + Disp_Subtype_Indication (Get_Subtype_Indication (Inter)); + end if; if Get_Kind (Inter) = Iir_Kind_Signal_Interface_Declaration then Disp_Signal_Kind (Get_Signal_Kind (Inter)); end if; - Default := Get_Default_Value (Inter); if Default /= Null_Iir then Put (" := "); Disp_Expression (Default); end if; - end Disp_Interface_Declaration; + end Disp_Interface_Mode_And_Type; - procedure Disp_Interface_Chain (Chain: Iir; Str: String) + -- Disp interfaces, followed by END_STR (';' in general). + procedure Disp_Interface_Chain (Chain: Iir; + End_Str: String := ""; + Comment_Col : Natural := 0) is Inter: Iir; + Next_Inter : Iir; Start: Count; begin if Chain = Null_Iir then @@ -927,16 +1095,32 @@ package body Disp_Vhdl is Put (" ("); Start := Col; Inter := Chain; - while Inter /= Null_Iir loop + loop + Next_Inter := Get_Chain (Inter); Set_Col (Start); - Disp_Interface_Declaration (Inter); - if Get_Chain (Inter) /= Null_Iir then - Put ("; "); + Disp_Interface_Class (Inter); + Disp_Name_Of (Inter); + while (Get_Lexical_Layout (Inter) and Iir_Lexical_Has_Type) = 0 loop + Put (", "); + Inter := Next_Inter; + Next_Inter := Get_Chain (Inter); + Disp_Name_Of (Inter); + end loop; + Disp_Interface_Mode_And_Type (Inter); + if Next_Inter /= Null_Iir then + Put (";"); + if Comment_Col /= 0 then + New_Line; + Set_Col (Comment_Col); + Put ("--"); + end if; else Put (')'); - Put (Str); + Put (End_Str); + exit; end if; - Inter := Get_Chain (Inter); + Inter := Next_Inter; + Next_Inter := Get_Chain (Inter); end loop; end Disp_Interface_Chain; @@ -952,21 +1136,6 @@ package body Disp_Vhdl is Disp_Interface_Chain (Get_Generic_Chain (Parent), ";"); end Disp_Generics; - procedure Disp_End (Decl : Iir; Name : String) is - begin - Put ("end"); - if Get_End_Has_Reserved_Id (Decl) then - Put (' '); - Put (Name); - end if; - if Get_End_Has_Identifier (Decl) then - Put (' '); - Disp_Name_Of (Decl); - end if; - Put (';'); - New_Line; - end Disp_End; - procedure Disp_Entity_Declaration (Decl: Iir_Entity_Declaration) is Start: Count; begin @@ -1001,6 +1170,9 @@ package body Disp_Vhdl is Indent := Col; Put ("component "); Disp_Name_Of (Decl); + if Get_Has_Is (Decl) then + Put (" is"); + end if; if Get_Generic_Chain (Decl) /= Null_Iir then Set_Col (Indent + Indentation); Disp_Generics (Decl); @@ -1010,7 +1182,7 @@ package body Disp_Vhdl is Disp_Ports (Decl); end if; Set_Col (Indent); - Put ("end component;"); + Disp_End (Decl, "component"); end Disp_Component_Declaration; procedure Disp_Concurrent_Statement_Chain (Parent : Iir; Indent : Count) @@ -1033,7 +1205,7 @@ package body Disp_Vhdl is Put ("architecture "); Disp_Name_Of (Arch); Put (" of "); - Disp_Name_Of (Get_Entity (Arch)); + Disp_Name (Get_Entity_Name (Arch)); Put_Line (" is"); Disp_Declaration_Chain (Arch, Start + Indentation); Set_Col (Start); @@ -1043,6 +1215,32 @@ package body Disp_Vhdl is Disp_End (Arch, "architecture"); end Disp_Architecture_Body; + procedure Disp_Signature (Sig : Iir) + is + List : Iir_List; + El : Iir; + begin + Disp_Name (Get_Prefix (Sig)); + Put (" ["); + List := Get_Type_Marks_List (Sig); + if List /= Null_Iir_List then + for I in Natural loop + El := Get_Nth_Element (List, I); + exit when El = Null_Iir; + if I /= 0 then + Put (", "); + end if; + Disp_Name (El); + end loop; + end if; + El := Get_Return_Type (Sig); + if El /= Null_Iir then + Put (" return "); + Disp_Name (El); + end if; + Put ("]"); + end Disp_Signature; + procedure Disp_Object_Alias_Declaration (Decl: Iir_Object_Alias_Declaration) is begin @@ -1058,24 +1256,43 @@ package body Disp_Vhdl is procedure Disp_Non_Object_Alias_Declaration (Decl: Iir_Non_Object_Alias_Declaration) is + Sig : constant Iir := Get_Alias_Signature (Decl); begin + if Get_Implicit_Alias_Flag (Decl) then + Put ("-- "); + end if; + Put ("alias "); Disp_Function_Name (Decl); Put (" is "); - Disp_Name (Get_Name (Decl)); + if Sig /= Null_Iir then + Disp_Signature (Sig); + else + Disp_Name (Get_Name (Decl)); + end if; Put_Line (";"); end Disp_Non_Object_Alias_Declaration; - procedure Disp_File_Declaration (Decl: Iir_File_Declaration) is + procedure Disp_File_Declaration (Decl: Iir_File_Declaration) + is + Next_Decl : Iir; Expr: Iir; begin Put ("file "); Disp_Name_Of (Decl); + Next_Decl := Decl; + while Get_Has_Identifier_List (Next_Decl) loop + Next_Decl := Get_Chain (Next_Decl); + Put (", "); + Disp_Name_Of (Next_Decl); + end loop; Put (": "); Disp_Type (Get_Type (Decl)); if Vhdl_Std = Vhdl_87 then Put (" is "); - Disp_Mode (Get_Mode (Decl)); + if Get_Has_Mode (Decl) then + Disp_Mode (Get_Mode (Decl)); + end if; Disp_Expression (Get_File_Logical_Name (Decl)); else Expr := Get_File_Open_Kind (Decl); @@ -1142,7 +1359,9 @@ package body Disp_Vhdl is Put (';'); end Disp_Terminal_Declaration; - procedure Disp_Object_Declaration (Decl: Iir) is + procedure Disp_Object_Declaration (Decl: Iir) + is + Next_Decl : Iir; begin case Get_Kind (Decl) is when Iir_Kind_Variable_Declaration => @@ -1154,9 +1373,6 @@ package body Disp_Vhdl is Put ("constant "); when Iir_Kind_Signal_Declaration => Put ("signal "); - when Iir_Kind_Object_Alias_Declaration => - Disp_Object_Alias_Declaration (Decl); - return; when Iir_Kind_File_Declaration => Disp_File_Declaration (Decl); return; @@ -1164,8 +1380,14 @@ package body Disp_Vhdl is raise Internal_Error; end case; Disp_Name_Of (Decl); + Next_Decl := Decl; + while Get_Has_Identifier_List (Next_Decl) loop + Next_Decl := Get_Chain (Next_Decl); + Put (", "); + Disp_Name_Of (Next_Decl); + end loop; Put (": "); - Disp_Type (Get_Type (Decl)); + Disp_Subtype_Indication (Get_Subtype_Indication (Decl)); if Get_Kind (Decl) = Iir_Kind_Signal_Declaration then Disp_Signal_Kind (Get_Signal_Kind (Decl)); end if; @@ -1177,28 +1399,64 @@ package body Disp_Vhdl is Put_Line (";"); end Disp_Object_Declaration; - procedure Disp_Subprogram_Declaration (Subprg: Iir) is + procedure Disp_Pure (Subprg : Iir) is begin + if Get_Pure_Flag (Subprg) then + Put ("pure"); + else + Put ("impure"); + end if; + end Disp_Pure; + + procedure Disp_Subprogram_Declaration (Subprg: Iir) + is + Start : constant Count := Col; + Implicit : constant Boolean := + Get_Kind (Subprg) in Iir_Kinds_Implicit_Subprogram_Declaration; + Inter : Iir; + begin + if Implicit + and then + Get_Implicit_Definition (Subprg) /= Iir_Predefined_Now_Function + then + Put ("-- "); + end if; + case Get_Kind (Subprg) is - when Iir_Kind_Function_Declaration - | Iir_Kind_Implicit_Function_Declaration => - Put ("function "); - Disp_Function_Name (Subprg); + when Iir_Kind_Function_Declaration => + if Get_Has_Pure (Subprg) then + Disp_Pure (Subprg); + Put (' '); + end if; + Put ("function"); + when Iir_Kind_Implicit_Function_Declaration => + Put ("function"); when Iir_Kind_Procedure_Declaration | Iir_Kind_Implicit_Procedure_Declaration => - Put ("procedure "); - Disp_Identifier (Subprg); + Put ("procedure"); when others => raise Internal_Error; end case; - Disp_Interface_Chain (Get_Interface_Declaration_Chain (Subprg), ""); + Put (' '); + Disp_Function_Name (Subprg); + + Inter := Get_Interface_Declaration_Chain (Subprg); + if Implicit then + Disp_Interface_Chain (Inter, "", Start); + else + Disp_Interface_Chain (Inter, "", 0); + end if; case Get_Kind (Subprg) is when Iir_Kind_Function_Declaration | Iir_Kind_Implicit_Function_Declaration => Put (" return "); - Disp_Type (Get_Return_Type (Subprg)); + if Implicit then + Disp_Type (Get_Return_Type (Subprg)); + else + Disp_Name (Get_Return_Type_Mark (Subprg)); + end if; when Iir_Kind_Procedure_Declaration | Iir_Kind_Implicit_Procedure_Declaration => null; @@ -1209,24 +1467,19 @@ package body Disp_Vhdl is procedure Disp_Subprogram_Body (Subprg : Iir) is - Decl : Iir; - Indent : Count; + Indent : constant Count := Col; begin - Decl := Get_Subprogram_Specification (Subprg); - Indent := Col; - if Get_Chain (Decl) /= Subprg then - Disp_Subprogram_Declaration (Decl); - end if; - Put_Line ("is"); - Set_Col (Indent); Disp_Declaration_Chain (Subprg, Indent + Indentation); Set_Col (Indent); Put_Line ("begin"); Set_Col (Indent + Indentation); Disp_Sequential_Statements (Get_Sequential_Statement_Chain (Subprg)); Set_Col (Indent); - Put_Line ("end;"); - New_Line; + if Get_Kind (Subprg) = Iir_Kind_Function_Body then + Disp_End (Subprg, "function"); + else + Disp_End (Subprg, "procedure"); + end if; end Disp_Subprogram_Body; procedure Disp_Instantiation_List (Insts: Iir_List) is @@ -1257,7 +1510,7 @@ package body Disp_Vhdl is Put ("for "); Disp_Instantiation_List (Get_Instantiation_List (Spec)); Put (": "); - Disp_Name_Of (Get_Component_Name (Spec)); + Disp_Name (Get_Component_Name (Spec)); New_Line; Disp_Binding_Indication (Get_Binding_Indication (Spec), Indent + Indentation); @@ -1271,7 +1524,7 @@ package body Disp_Vhdl is Put ("disconnect "); Disp_Instantiation_List (Get_Signal_List (Dis)); Put (": "); - Disp_Subtype_Indication (Get_Type (Dis)); + Disp_Name (Get_Type_Mark (Dis)); Put (" after "); Disp_Expression (Get_Expression (Dis)); Put_Line (";"); @@ -1283,7 +1536,7 @@ package body Disp_Vhdl is Put ("attribute "); Disp_Identifier (Attr); Put (": "); - Disp_Type (Get_Type (Attr)); + Disp_Name (Get_Type_Mark (Attr)); Put_Line (";"); end Disp_Attribute_Declaration; @@ -1295,37 +1548,24 @@ package body Disp_Vhdl is (Get_Attribute_Designator (Get_Attribute_Specification (Attr))); end Disp_Attribute_Value; + procedure Disp_Attribute_Name (Attr : Iir) + is + Sig : constant Iir := Get_Attribute_Signature (Attr); + begin + if Sig /= Null_Iir then + Disp_Signature (Sig); + else + Disp_Name (Get_Prefix (Attr)); + end if; + Put ("'"); + Disp_Ident (Get_Identifier (Attr)); + end Disp_Attribute_Name; + procedure Disp_Entity_Kind (Tok : Tokens.Token_Type) is begin Put (Tokens.Image (Tok)); end Disp_Entity_Kind; - procedure Disp_Signature (Sig : Iir) - is - List : Iir_List; - El : Iir; - begin - Disp_Name (Get_Prefix (Sig)); - Put (" ["); - List := Get_Type_Marks_List (Sig); - if List /= Null_Iir_List then - for I in Natural loop - El := Get_Nth_Element (List, I); - exit when El = Null_Iir; - if I /= 0 then - Put (", "); - end if; - Disp_Name (El); - end loop; - end if; - El := Get_Return_Type (Sig); - if El /= Null_Iir then - Put (" return "); - Disp_Type (El); - end if; - Put ("]"); - end Disp_Signature; - procedure Disp_Entity_Name_List (List : Iir_List) is El : Iir; @@ -1344,7 +1584,7 @@ package body Disp_Vhdl is if Get_Kind (El) = Iir_Kind_Signature then Disp_Signature (El); else - Disp_Name_Of (El); + Disp_Name (El); end if; end loop; end if; @@ -1374,11 +1614,12 @@ package body Disp_Vhdl is New_Line; Disp_Declaration_Chain (Bod, Indent + Indentation); Set_Col (Indent); - Put_Line ("end protected body;"); + Disp_End (Bod, "protected body"); end Disp_Protected_Type_Body; procedure Disp_Group_Template_Declaration (Decl : Iir) is + use Tokens; Ent : Iir; begin Put ("group "); @@ -1389,7 +1630,12 @@ package body Disp_Vhdl is Disp_Entity_Kind (Get_Entity_Class (Ent)); Ent := Get_Chain (Ent); exit when Ent = Null_Iir; - Put (", "); + if Get_Entity_Class (Ent) = Tok_Box then + Put (" <>"); + exit; + else + Put (", "); + end if; end loop; Put_Line (");"); end Disp_Group_Template_Declaration; @@ -1434,8 +1680,16 @@ package body Disp_Vhdl is Disp_Use_Clause (Decl); when Iir_Kind_Component_Declaration => Disp_Component_Declaration (Decl); - when Iir_Kinds_Object_Declaration => + when Iir_Kind_File_Declaration + | Iir_Kind_Signal_Declaration + | Iir_Kind_Constant_Declaration + | Iir_Kind_Variable_Declaration => Disp_Object_Declaration (Decl); + while Get_Has_Identifier_List (Decl) loop + Decl := Get_Chain (Decl); + end loop; + when Iir_Kind_Object_Alias_Declaration => + Disp_Object_Alias_Declaration (Decl); when Iir_Kind_Terminal_Declaration => Disp_Terminal_Declaration (Decl); when Iir_Kinds_Quantity_Declaration => @@ -1451,13 +1705,14 @@ package body Disp_Vhdl is when Iir_Kind_Function_Declaration | Iir_Kind_Procedure_Declaration => Disp_Subprogram_Declaration (Decl); - if Get_Subprogram_Body (Decl) = Null_Iir - or else Get_Subprogram_Body (Decl) /= Get_Chain (Decl) - then + if not Get_Has_Body (Decl) then Put_Line (";"); end if; when Iir_Kind_Function_Body | Iir_Kind_Procedure_Body => + -- The declaration was just displayed. + Put_Line (" is"); + Set_Col (Indent); Disp_Subprogram_Body (Decl); when Iir_Kind_Protected_Type_Body => Disp_Protected_Type_Body (Decl, Indent); @@ -1539,7 +1794,9 @@ package body Disp_Vhdl is Put_Line (";"); end Disp_Variable_Assignment; - procedure Disp_Label (Label: Name_Id) is + procedure Disp_Label (Stmt : Iir) + is + Label: constant Name_Id := Get_Label (Stmt); begin if Label /= Null_Identifier then Disp_Ident (Label); @@ -1547,15 +1804,22 @@ package body Disp_Vhdl is end if; end Disp_Label; + procedure Disp_Postponed (Stmt : Iir) is + begin + if Get_Postponed_Flag (Stmt) then + Put ("postponed "); + end if; + end Disp_Postponed; + procedure Disp_Concurrent_Selected_Signal_Assignment (Stmt: Iir) is - Indent: Count; + Indent: constant Count := Col; Assoc: Iir; Assoc_Chain : Iir; begin - Indent := Col; Set_Col (Indent); - Disp_Label (Get_Label (Stmt)); + Disp_Label (Stmt); + Disp_Postponed (Stmt); Put ("with "); Disp_Expression (Get_Expression (Stmt)); Put (" select "); @@ -1585,7 +1849,8 @@ package body Disp_Vhdl is Cond_Wf : Iir_Conditional_Waveform; Expr : Iir; begin - Disp_Label (Get_Label (Stmt)); + Disp_Label (Stmt); + Disp_Postponed (Stmt); Disp_Expression (Get_Target (Stmt)); Put (" <= "); if Get_Guard (Stmt) /= Null_Iir then @@ -1610,13 +1875,14 @@ package body Disp_Vhdl is Put_Line (";"); end Disp_Concurrent_Conditional_Signal_Assignment; - procedure Disp_Assertion_Statement (Stmt: Iir) is - Start: Count; + procedure Disp_Assertion_Statement (Stmt: Iir) + is + Start: constant Count := Col; Expr: Iir; begin - Start := Col; if Get_Kind (Stmt) = Iir_Kind_Concurrent_Assertion_Statement then - Disp_Label (Get_Label (Stmt)); + Disp_Label (Stmt); + Disp_Postponed (Stmt); end if; Put ("assert "); Disp_Expression (Get_Assertion_Condition (Stmt)); @@ -1668,9 +1934,15 @@ package body Disp_Vhdl is procedure Disp_Monadic_Operator (Expr: Iir) is begin - Put (Name_Table.Image (Iirs_Utils.Get_Operator_Name (Expr)) & " ("); + Put (Name_Table.Image (Iirs_Utils.Get_Operator_Name (Expr))); + Put (' '); + if Flag_Parenthesis then + Put ('('); + end if; Disp_Expression (Get_Operand (Expr)); - Put (")"); + if Flag_Parenthesis then + Put (')'); + end if; end Disp_Monadic_Operator; procedure Disp_Case_Statement (Stmt: Iir_Case_Statement) @@ -1694,7 +1966,7 @@ package body Disp_Vhdl is Disp_Sequential_Statements (Sel_Stmt); end loop; Set_Col (Indent); - Put_Line ("end case;"); + Disp_End_Label (Stmt, "case"); end Disp_Case_Statement; procedure Disp_Wait_Statement (Stmt: Iir_Wait_Statement) is @@ -1746,23 +2018,18 @@ package body Disp_Vhdl is end if; end loop; Set_Col (Start); - Put_Line ("end if;"); + Disp_End_Label (Stmt, "if"); end Disp_If_Statement; - procedure Disp_Iterator (Iterator: Iir) is - begin - Disp_Subtype_Indication (Iterator); - end Disp_Iterator; - procedure Disp_Parameter_Specification (Iterator : Iir_Iterator_Declaration) is begin Disp_Identifier (Iterator); Put (" in "); - Disp_Iterator (Get_Type (Iterator)); + Disp_Discrete_Range (Get_Discrete_Range (Iterator)); end Disp_Parameter_Specification; - procedure Disp_Procedure_Call (Call : Iir) + procedure Disp_Method_Object (Call : Iir) is Obj : Iir; begin @@ -1771,8 +2038,17 @@ package body Disp_Vhdl is Disp_Name (Obj); Put ('.'); end if; - Disp_Identifier (Get_Implementation (Call)); - Put (' '); + end Disp_Method_Object; + + procedure Disp_Procedure_Call (Call : Iir) is + begin + if True then + Disp_Name (Get_Prefix (Call)); + else + Disp_Method_Object (Call); + Disp_Identifier (Get_Implementation (Call)); + Put (' '); + end if; Disp_Association_Chain (Get_Parameter_Association_Chain (Call)); Put_Line (";"); end Disp_Procedure_Call; @@ -1780,12 +2056,12 @@ package body Disp_Vhdl is procedure Disp_Sequential_Statements (First : Iir) is Stmt: Iir; - Start: Count; + Start: constant Count := Col; begin - Start := Col; Stmt := First; while Stmt /= Null_Iir loop Set_Col (Start); + Disp_Label (Stmt); case Get_Kind (Stmt) is when Iir_Kind_Null_Statement => Put_Line ("null;"); @@ -1793,13 +2069,14 @@ package body Disp_Vhdl is Disp_If_Statement (Stmt); when Iir_Kind_For_Loop_Statement => Put ("for "); - Disp_Parameter_Specification (Get_Iterator_Scheme (Stmt)); + Disp_Parameter_Specification + (Get_Parameter_Specification (Stmt)); Put_Line (" loop"); Set_Col (Start + Indentation); Disp_Sequential_Statements (Get_Sequential_Statement_Chain (Stmt)); Set_Col (Start); - Put_Line ("end loop;"); + Disp_End_Label (Stmt, "loop"); when Iir_Kind_While_Loop_Statement => if Get_Condition (Stmt) /= Null_Iir then Put ("while "); @@ -1811,7 +2088,7 @@ package body Disp_Vhdl is Disp_Sequential_Statements (Get_Sequential_Statement_Chain (Stmt)); Set_Col (Start); - Put_Line ("end loop;"); + Disp_End_Label (Stmt, "loop"); when Iir_Kind_Signal_Assignment_Statement => Disp_Signal_Assignment (Stmt); when Iir_Kind_Variable_Assignment_Statement => @@ -1836,17 +2113,25 @@ package body Disp_Vhdl is Disp_Procedure_Call (Get_Procedure_Call (Stmt)); when Iir_Kind_Exit_Statement | Iir_Kind_Next_Statement => - if Get_Kind (Stmt) = Iir_Kind_Exit_Statement then - Put ("exit"); - else - Put ("next"); - end if; - -- FIXME: label. - if Get_Condition (Stmt) /= Null_Iir then - Put (" when "); - Disp_Expression (Get_Condition (Stmt)); - end if; - Put_Line (";"); + declare + Label : constant Iir := Get_Loop_Label (Stmt); + Cond : constant Iir := Get_Condition (Stmt); + begin + if Get_Kind (Stmt) = Iir_Kind_Exit_Statement then + Put ("exit"); + else + Put ("next"); + end if; + if Label /= Null_Iir then + Put (" "); + Disp_Name (Label); + end if; + if Cond /= Null_Iir then + Put (" when "); + Disp_Expression (Cond); + end if; + Put_Line (";"); + end; when others => Error_Kind ("disp_sequential_statements", Stmt); @@ -1857,10 +2142,10 @@ package body Disp_Vhdl is procedure Disp_Process_Statement (Process: Iir) is - Start: Count; + Start: constant Count := Col; begin - Start := Col; - Disp_Label (Get_Label (Process)); + Disp_Label (Process); + Disp_Postponed (Process); Put ("process "); if Get_Kind (Process) = Iir_Kind_Sensitized_Process_Statement then @@ -1868,18 +2153,21 @@ package body Disp_Vhdl is Disp_Designator_List (Get_Sensitivity_List (Process)); Put (")"); end if; - if Vhdl_Std >= Vhdl_93 then - Put_Line (" is"); - else - New_Line; + if Get_Has_Is (Process) then + Put (" is"); end if; + New_Line; Disp_Declaration_Chain (Process, Start + Indentation); Set_Col (Start); Put_Line ("begin"); Set_Col (Start + Indentation); Disp_Sequential_Statements (Get_Sequential_Statement_Chain (Process)); Set_Col (Start); - Disp_End (Process, "process"); + Put ("end"); + if Get_End_Has_Postponed (Process) then + Put (" postponed"); + end if; + Disp_After_End (Process, "process"); end Disp_Process_Statement; procedure Disp_Conversion (Conv : Iir) is @@ -1968,7 +2256,7 @@ package body Disp_Vhdl is case Get_Kind (Aspect) is when Iir_Kind_Entity_Aspect_Entity => Put ("entity "); - Disp_Name_Of (Get_Entity (Aspect)); + Disp_Name (Get_Entity_Name (Aspect)); Arch := Get_Architecture (Aspect); if Arch /= Null_Iir then Put (" ("); @@ -1977,7 +2265,7 @@ package body Disp_Vhdl is end if; when Iir_Kind_Entity_Aspect_Configuration => Put ("configuration "); - Disp_Name_Of (Get_Configuration (Aspect)); + Disp_Name (Get_Configuration_Name (Aspect)); when Iir_Kind_Entity_Aspect_Open => Put ("open"); when others => @@ -1988,13 +2276,12 @@ package body Disp_Vhdl is procedure Disp_Component_Instantiation_Statement (Stmt: Iir_Component_Instantiation_Statement) is - Component: Iir; + Component: constant Iir := Get_Instantiated_Unit (Stmt); Alist: Iir; begin - Disp_Label (Get_Label (Stmt)); - Component := Get_Instantiated_Unit (Stmt); - if Get_Kind (Component) = Iir_Kind_Component_Declaration then - Disp_Name_Of (Component); + Disp_Label (Stmt); + if Get_Kind (Component) in Iir_Kinds_Denoting_Name then + Disp_Name (Component); else Disp_Entity_Aspect (Component); end if; @@ -2013,7 +2300,12 @@ package body Disp_Vhdl is procedure Disp_Function_Call (Expr: Iir_Function_Call) is begin - Disp_Function_Name (Get_Implementation (Expr)); + if True then + Disp_Name (Get_Prefix (Expr)); + else + Disp_Method_Object (Expr); + Disp_Function_Name (Get_Implementation (Expr)); + end if; Disp_Association_Chain (Get_Parameter_Association_Chain (Expr)); end Disp_Function_Call; @@ -2129,21 +2421,36 @@ package body Disp_Vhdl is Put ("'"); Put (Name); Param := Get_Parameter (Expr); - if Param /= Null_Iir then + if Param /= Null_Iir + and then Param /= Std_Package.Universal_Integer_One + then Put (" ("); Disp_Expression (Param); Put (")"); end if; end Disp_Parametered_Attribute; + procedure Disp_Parametered_Type_Attribute (Name : String; Expr : Iir) is + begin + Disp_Name (Get_Prefix (Expr)); + Put ("'"); + Put (Name); + Put (" ("); + Disp_Expression (Get_Parameter (Expr)); + Put (")"); + end Disp_Parametered_Type_Attribute; + procedure Disp_String_Literal (Str : Iir) is - Ptr : String_Fat_Acc; - Len : Int32; + Ptr : constant String_Fat_Acc := Get_String_Fat_Acc (Str); + Len : constant Int32 := Get_String_Length (Str); begin - Ptr := Get_String_Fat_Acc (Str); - Len := Get_String_Length (Str); - Put (String (Ptr (1 .. Len))); + for I in 1 .. Len loop + if Ptr (I) = '"' then + Put ('"'); + end if; + Put (Ptr (I)); + end loop; end Disp_String_Literal; procedure Disp_Expression (Expr: Iir) @@ -2166,28 +2473,38 @@ package body Disp_Vhdl is Disp_Fp64 (Get_Fp_Value (Expr)); end if; when Iir_Kind_String_Literal => - Put (""""); - Disp_String_Literal (Expr); - Put (""""); - if Disp_String_Literal_Type or Flags.List_Verbose then - Put ("[type: "); - Disp_Type (Get_Type (Expr)); - Put ("]"); + Orig := Get_Literal_Origin (Expr); + if Orig /= Null_Iir then + Disp_Expression (Orig); + else + Put (""""); + Disp_String_Literal (Expr); + Put (""""); + if Disp_String_Literal_Type or Flags.List_Verbose then + Put ("[type: "); + Disp_Type (Get_Type (Expr)); + Put ("]"); + end if; end if; when Iir_Kind_Bit_String_Literal => - if False then - case Get_Bit_String_Base (Expr) is - when Base_2 => - Put ('B'); - when Base_8 => - Put ('O'); - when Base_16 => - Put ('X'); - end case; + Orig := Get_Literal_Origin (Expr); + if Orig /= Null_Iir then + Disp_Expression (Orig); + else + if False then + case Get_Bit_String_Base (Expr) is + when Base_2 => + Put ('B'); + when Base_8 => + Put ('O'); + when Base_16 => + Put ('X'); + end case; + end if; + Put ("B"""); + Disp_String_Literal (Expr); + Put (""""); end if; - Put ("B"""); - Disp_String_Literal (Expr); - Put (""""); when Iir_Kind_Physical_Fp_Literal | Iir_Kind_Physical_Int_Literal => Orig := Get_Literal_Origin (Expr); @@ -2201,7 +2518,12 @@ package body Disp_Vhdl is when Iir_Kind_Character_Literal => Disp_Identifier (Expr); when Iir_Kind_Enumeration_Literal => - Disp_Name_Of (Expr); + Orig := Get_Literal_Origin (Expr); + if Orig /= Null_Iir then + Disp_Expression (Orig); + else + Disp_Name_Of (Expr); + end if; when Iir_Kind_Overflow_Literal => Orig := Get_Literal_Origin (Expr); if Orig /= Null_Iir then @@ -2226,6 +2548,8 @@ package body Disp_Vhdl is when Iir_Kind_Attribute_Value => Disp_Attribute_Value (Expr); + when Iir_Kind_Attribute_Name => + Disp_Attribute_Name (Expr); when Iir_Kind_Element_Declaration => Disp_Name_Of (Expr); @@ -2243,9 +2567,6 @@ package body Disp_Vhdl is Disp_Name_Of (Expr); return; - when Iir_Kind_Simple_Name => - Disp_Name (Expr); - when Iir_Kinds_Dyadic_Operator => Disp_Dyadic_Operator (Expr); when Iir_Kinds_Monadic_Operator => @@ -2257,21 +2578,33 @@ package body Disp_Vhdl is Disp_Expression (Get_Expression (Expr)); Put (")"); when Iir_Kind_Type_Conversion => - Disp_Type (Get_Type (Expr)); + Disp_Name (Get_Type_Mark (Expr)); Put (" ("); Disp_Expression (Get_Expression (Expr)); Put (")"); when Iir_Kind_Qualified_Expression => - Disp_Type (Get_Type_Mark (Expr)); - Put ("'("); - Disp_Expression (Get_Expression (Expr)); - Put (")"); + declare + Qexpr : constant Iir := Get_Expression (Expr); + Has_Paren : constant Boolean := + Get_Kind (Qexpr) = Iir_Kind_Parenthesis_Expression + or else Get_Kind (Qexpr) = Iir_Kind_Aggregate; + begin + Disp_Name (Get_Type_Mark (Expr)); + Put ("'"); + if not Has_Paren then + Put ("("); + end if; + Disp_Expression (Qexpr); + if not Has_Paren then + Put (")"); + end if; + end; when Iir_Kind_Allocator_By_Expression => Put ("new "); Disp_Expression (Get_Expression (Expr)); when Iir_Kind_Allocator_By_Subtype => Put ("new "); - Disp_Subtype_Indication (Get_Expression (Expr)); + Disp_Subtype_Indication (Get_Subtype_Indication (Expr)); when Iir_Kind_Indexed_Name => Disp_Indexed_Name (Expr); @@ -2291,16 +2624,16 @@ package body Disp_Vhdl is Put (".all"); when Iir_Kind_Left_Type_Attribute => - Disp_Expression (Get_Prefix (Expr)); + Disp_Name (Get_Prefix (Expr)); Put ("'left"); when Iir_Kind_Right_Type_Attribute => - Disp_Expression (Get_Prefix (Expr)); + Disp_Name (Get_Prefix (Expr)); Put ("'right"); when Iir_Kind_High_Type_Attribute => - Disp_Expression (Get_Prefix (Expr)); + Disp_Name (Get_Prefix (Expr)); Put ("'high"); when Iir_Kind_Low_Type_Attribute => - Disp_Expression (Get_Prefix (Expr)); + Disp_Name (Get_Prefix (Expr)); Put ("'low"); when Iir_Kind_Stable_Attribute => @@ -2335,13 +2668,17 @@ package body Disp_Vhdl is Put ("'last_event"); when Iir_Kind_Pos_Attribute => - Disp_Parametered_Attribute ("pos", Expr); + Disp_Parametered_Type_Attribute ("pos", Expr); when Iir_Kind_Val_Attribute => - Disp_Parametered_Attribute ("val", Expr); + Disp_Parametered_Type_Attribute ("val", Expr); when Iir_Kind_Succ_Attribute => - Disp_Parametered_Attribute ("succ", Expr); + Disp_Parametered_Type_Attribute ("succ", Expr); when Iir_Kind_Pred_Attribute => - Disp_Parametered_Attribute ("pred", Expr); + Disp_Parametered_Type_Attribute ("pred", Expr); + when Iir_Kind_Leftof_Attribute => + Disp_Parametered_Type_Attribute ("leftof", Expr); + when Iir_Kind_Rightof_Attribute => + Disp_Parametered_Type_Attribute ("rightof", Expr); when Iir_Kind_Length_Array_Attribute => Disp_Parametered_Attribute ("length", Expr); @@ -2365,28 +2702,25 @@ package body Disp_Vhdl is when Iir_Kind_Value_Attribute => Disp_Parametered_Attribute ("value", Expr); when Iir_Kind_Simple_Name_Attribute => - Disp_Name_Of (Get_Prefix (Expr)); + Disp_Name (Get_Prefix (Expr)); Put ("'simple_name"); when Iir_Kind_Instance_Name_Attribute => - Disp_Name_Of (Get_Prefix (Expr)); + Disp_Name (Get_Prefix (Expr)); Put ("'instance_name"); when Iir_Kind_Path_Name_Attribute => - Disp_Name_Of (Get_Prefix (Expr)); + Disp_Name (Get_Prefix (Expr)); Put ("'path_name"); when Iir_Kind_Selected_By_All_Name => Disp_Expression (Get_Prefix (Expr)); - Put (""); - return; when Iir_Kind_Selected_Name => - Disp_Expression (Get_Named_Entity (Expr)); + Disp_Name (Expr); + when Iir_Kind_Simple_Name => + Disp_Name (Expr); when Iir_Kinds_Type_And_Subtype_Definition => Disp_Type (Expr); - when Iir_Kind_Proxy => - Disp_Expression (Get_Proxy (Expr)); - when Iir_Kind_Range_Expression => Disp_Range (Expr); when Iir_Kind_Subtype_Declaration => @@ -2446,7 +2780,7 @@ package body Disp_Vhdl is Guard : Iir_Guard_Signal_Declaration; begin Indent := Col; - Disp_Label (Get_Label (Block)); + Disp_Label (Block); Put ("block"); Guard := Get_Guard_Decl (Block); if Guard /= Null_Iir then @@ -2469,7 +2803,7 @@ package body Disp_Vhdl is Put_Line ("begin"); Disp_Concurrent_Statement_Chain (Block, Indent + Indentation); Set_Col (Indent); - Put_Line ("end;"); + Disp_End (Block, "block"); end Disp_Block_Statement; procedure Disp_Generate_Statement (Stmt : Iir_Generate_Statement) @@ -2478,7 +2812,7 @@ package body Disp_Vhdl is Scheme : Iir; begin Indent := Col; - Disp_Label (Get_Label (Stmt)); + Disp_Label (Stmt); Scheme := Get_Generation_Scheme (Stmt); case Get_Kind (Scheme) is when Iir_Kind_Iterator_Declaration => @@ -2490,11 +2824,13 @@ package body Disp_Vhdl is end case; Put_Line (" generate"); Disp_Declaration_Chain (Stmt, Indent); - Set_Col (Indent); - Put_Line ("begin"); + if Get_Has_Begin (Stmt) then + Set_Col (Indent); + Put_Line ("begin"); + end if; Disp_Concurrent_Statement_Chain (Stmt, Indent + Indentation); Set_Col (Indent); - Put_Line ("end generate;"); + Disp_End (Stmt, "generate"); end Disp_Generate_Statement; procedure Disp_Psl_Default_Clock (Stmt : Iir) is @@ -2556,7 +2892,7 @@ package body Disp_Vhdl is procedure Disp_Simple_Simultaneous_Statement (Stmt : Iir) is begin - Disp_Label (Get_Label (Stmt)); + Disp_Label (Stmt); Disp_Expression (Get_Simultaneous_Left (Stmt)); Put (" == "); Disp_Expression (Get_Simultaneous_Right (Stmt)); @@ -2578,6 +2914,8 @@ package body Disp_Vhdl is when Iir_Kind_Component_Instantiation_Statement => Disp_Component_Instantiation_Statement (Stmt); when Iir_Kind_Concurrent_Procedure_Call_Statement => + Disp_Label (Stmt); + Disp_Postponed (Stmt); Disp_Procedure_Call (Get_Procedure_Call (Stmt)); when Iir_Kind_Block_Statement => Disp_Block_Statement (Stmt); @@ -2602,7 +2940,7 @@ package body Disp_Vhdl is Disp_Identifier (Decl); Put_Line (" is"); Disp_Declaration_Chain (Decl, Col + Indentation); - Put_Line ("end;"); + Disp_End (Decl, "package"); end Disp_Package_Declaration; procedure Disp_Package_Body (Decl: Iir) @@ -2612,7 +2950,7 @@ package body Disp_Vhdl is Disp_Identifier (Decl); Put_Line (" is"); Disp_Declaration_Chain (Decl, Col + Indentation); - Put_Line ("end;"); + Disp_End (Decl, "package body"); end Disp_Package_Body; procedure Disp_Binding_Indication (Bind : Iir; Indent : Count) @@ -2646,12 +2984,13 @@ package body Disp_Vhdl is Set_Col (Indent); Put ("for "); Disp_Instantiation_List (Get_Instantiation_List (Conf)); - Put(" : "); + Put (" : "); Disp_Name_Of (Get_Component_Name (Conf)); New_Line; Binding := Get_Binding_Indication (Conf); if Binding /= Null_Iir then Disp_Binding_Indication (Binding, Indent + Indentation); + Put (";"); end if; Block := Get_Block_Configuration (Conf); if Block /= Null_Iir then @@ -2731,22 +3070,24 @@ package body Disp_Vhdl is Put ("configuration "); Disp_Name_Of (Decl); Put (" of "); - Disp_Name_Of (Get_Entity (Decl)); + Disp_Name (Get_Entity_Name (Decl)); Put_Line (" is"); Disp_Declaration_Chain (Decl, Col); Disp_Block_Configuration (Get_Block_Configuration (Decl), Col + Indentation); - Put_Line ("end;"); + Disp_End (Decl, "configuration"); end Disp_Configuration_Declaration; procedure Disp_Design_Unit (Unit: Iir_Design_Unit) is + Indent: constant Count := Col; Decl: Iir; - Indent: Count; + Next_Decl : Iir; begin - Indent := Col; Decl := Get_Context_Items (Unit); while Decl /= Null_Iir loop + Next_Decl := Get_Chain (Decl); + Set_Col (Indent); case Get_Kind (Decl) is when Iir_Kind_Use_Clause => @@ -2754,11 +3095,17 @@ package body Disp_Vhdl is when Iir_Kind_Library_Clause => Put ("library "); Disp_Identifier (Decl); + while Get_Has_Identifier_List (Decl) loop + Decl := Next_Decl; + Next_Decl := Get_Chain (Decl); + Put (", "); + Disp_Identifier (Decl); + end loop; Put_Line (";"); when others => Error_Kind ("disp_design_unit1", Decl); end case; - Decl := Get_Chain (Decl); + Decl := Next_Decl; end loop; Decl := Get_Library_Unit (Unit); diff --git a/errorout.adb b/errorout.adb index 90551fe8b..a701e1a3a 100644 --- a/errorout.adb +++ b/errorout.adb @@ -20,7 +20,7 @@ with Ada.Command_Line; with Scanner; with Tokens; use Tokens; with Name_Table; -with Iirs_Utils; +with Iirs_Utils; use Iirs_Utils; with Files_Map; use Files_Map; with Ada.Strings.Unbounded; with Std_Names; @@ -369,12 +369,12 @@ package body Errorout is case Get_Kind (Node) is when Iir_Kind_String_Literal => return "string literal """ - & Iirs_Utils.Image_String_Lit (Node) & """"; + & Image_String_Lit (Node) & """"; when Iir_Kind_Bit_String_Literal => return "bit string literal """ - & Iirs_Utils.Image_String_Lit (Node) & """"; + & Image_String_Lit (Node) & """"; when Iir_Kind_Character_Literal => - return "character literal " & Iirs_Utils.Image_Identifier (Node); + return "character literal " & Image_Identifier (Node); when Iir_Kind_Integer_Literal => return "integer literal"; when Iir_Kind_Floating_Point_Literal => @@ -383,7 +383,7 @@ package body Errorout is | Iir_Kind_Physical_Fp_Literal => return "physical literal"; when Iir_Kind_Enumeration_Literal => - return "enumeration literal " & Iirs_Utils.Image_Identifier (Node); + return "enumeration literal " & Image_Identifier (Node); when Iir_Kind_Element_Declaration => return Disp_Identifier (Node, "element"); when Iir_Kind_Record_Element_Constraint => @@ -399,9 +399,6 @@ package body Errorout is when Iir_Kind_Simple_Aggregate => return "locally static array literal"; - -- Should never be displayed, but for completness... - when Iir_Kind_Proxy => - return "proxy"; when Iir_Kind_Operator_Symbol => return "operator name"; when Iir_Kind_Aggregate_Info => @@ -423,7 +420,7 @@ package body Errorout is when Iir_Kind_Integer_Type_Definition | Iir_Kind_Enumeration_Type_Definition => - return Iirs_Utils.Image_Identifier (Get_Type_Declarator (Node)); + return Image_Identifier (Get_Type_Declarator (Node)); when Iir_Kind_Array_Type_Definition => return Disp_Type (Node, "array type"); when Iir_Kind_Array_Subtype_Definition => @@ -459,7 +456,7 @@ package body Errorout is return "subtype definition"; when Iir_Kind_Scalar_Nature_Definition => - return Iirs_Utils.Image_Identifier (Get_Nature_Declarator (Node)); + return Image_Identifier (Get_Nature_Declarator (Node)); when Iir_Kind_Choice_By_Expression => return "choice by expression"; @@ -490,8 +487,7 @@ package body Errorout is & '''; when Iir_Kind_Entity_Aspect_Entity => return "aspect " & Disp_Node (Get_Entity (Node)) - & '(' & Iirs_Utils.Image_Identifier (Get_Architecture (Node)) - & ')'; + & '(' & Image_Identifier (Get_Architecture (Node)) & ')'; when Iir_Kind_Entity_Aspect_Configuration => return "configuration entity aspect"; when Iir_Kind_Entity_Aspect_Open => @@ -500,8 +496,7 @@ package body Errorout is when Iir_Kinds_Monadic_Operator | Iir_Kinds_Dyadic_Operator => return "operator """ - & Name_Table.Image (Iirs_Utils.Get_Operator_Name (Node)) - & """"; + & Name_Table.Image (Get_Operator_Name (Node)) & """"; when Iir_Kind_Parenthesis_Expression => return "expression"; when Iir_Kind_Qualified_Expression => @@ -609,8 +604,8 @@ package body Errorout is Arch := Get_Block_Specification (Get_Block_Configuration (Node)); return "default configuration of " - & Iirs_Utils.Image_Identifier (Ent) - & '(' & Iirs_Utils.Image_Identifier (Arch) & ')'; + & Image_Identifier (Ent) + & '(' & Image_Identifier (Arch) & ')'; end if; end; when Iir_Kind_Package_Instantiation_Declaration => @@ -655,12 +650,11 @@ package body Errorout is return Disp_Identifier (Node, "implicit function") & Disp_Identifier (Get_Type_Reference (Node), " of type"); -- return "implicit function " --- & Iirs_Utils.Get_Predefined_Function_Name --- (Get_Implicit_Definition (Node)); +-- & Get_Predefined_Function_Name +-- (Get_Implicit_Definition (Node)); when Iir_Kind_Implicit_Procedure_Declaration => return "implicit procedure " - & Iirs_Utils.Get_Predefined_Function_Name - (Get_Implicit_Definition (Node)); + & Get_Predefined_Function_Name (Get_Implicit_Definition (Node)); when Iir_Kind_Concurrent_Procedure_Call_Statement => return "concurrent procedure call"; @@ -1004,7 +998,6 @@ package body Errorout is -- Return the type name of DEF, handle anonymous subtypes. function Disp_Type_Name (Def : Iir) return String is - use Iirs_Utils; Decl : Iir; begin Decl := Get_Type_Declarator (Def); diff --git a/evaluation.adb b/evaluation.adb index b7b53599a..bd6649c0f 100644 --- a/evaluation.adb +++ b/evaluation.adb @@ -29,16 +29,24 @@ package body Evaluation is function Get_Physical_Value (Expr : Iir) return Iir_Int64 is pragma Unsuppress (Overflow_Check); + Kind : constant Iir_Kind := Get_Kind (Expr); + Unit : Iir; begin - case Get_Kind (Expr) is - when Iir_Kind_Physical_Int_Literal => - return Get_Value (Expr) - * Get_Value (Get_Physical_Unit_Value (Get_Unit_Name (Expr))); - when Iir_Kind_Physical_Fp_Literal => - return Iir_Int64 - (Get_Fp_Value (Expr) - * Iir_Fp64 (Get_Value (Get_Physical_Unit_Value - (Get_Unit_Name (Expr))))); + case Kind is + when Iir_Kind_Physical_Int_Literal + | Iir_Kind_Physical_Fp_Literal => + -- Extract Unit. + Unit := Get_Physical_Unit_Value + (Get_Named_Entity (Get_Unit_Name (Expr))); + case Kind is + when Iir_Kind_Physical_Int_Literal => + return Get_Value (Expr) * Get_Value (Unit); + when Iir_Kind_Physical_Fp_Literal => + return Iir_Int64 + (Get_Fp_Value (Expr) * Iir_Fp64 (Get_Value (Unit))); + when others => + raise Program_Error; + end case; when Iir_Kind_Unit_Declaration => return Get_Value (Get_Physical_Unit_Value (Expr)); when others => @@ -78,7 +86,7 @@ package body Evaluation is return Res; end Build_Floating; - function Build_Enumeration (Val : Iir_Index32; Origin : Iir) + function Build_Enumeration_Constant (Val : Iir_Index32; Origin : Iir) return Iir_Enumeration_Literal is Res : Iir_Enumeration_Literal; @@ -99,21 +107,18 @@ package body Evaluation is Set_Expr_Staticness (Res, Locally); Set_Enumeration_Decl (Res, Lit); return Res; - end Build_Enumeration; - - function Build_Boolean (Cond : Boolean; Origin : Iir) return Iir is - begin - return Build_Enumeration (Boolean'Pos (Cond), Origin); - end Build_Boolean; + end Build_Enumeration_Constant; function Build_Physical (Val : Iir_Int64; Origin : Iir) return Iir_Physical_Int_Literal is Res : Iir_Physical_Int_Literal; + Unit_Name : Iir; begin Res := Create_Iir (Iir_Kind_Physical_Int_Literal); Location_Copy (Res, Origin); - Set_Unit_Name (Res, Get_Primary_Unit (Get_Type (Origin))); + Unit_Name := Get_Primary_Unit_Name (Get_Base_Type (Get_Type (Origin))); + Set_Unit_Name (Res, Unit_Name); Set_Value (Res, Val); Set_Type (Res, Get_Type (Origin)); Set_Literal_Origin (Res, Origin); @@ -121,14 +126,12 @@ package body Evaluation is return Res; end Build_Physical; - function Build_Discrete (Val : Iir_Int64; Origin : Iir) - return Iir - is + function Build_Discrete (Val : Iir_Int64; Origin : Iir) return Iir is begin case Get_Kind (Get_Type (Origin)) is when Iir_Kind_Enumeration_Type_Definition | Iir_Kind_Enumeration_Subtype_Definition => - return Build_Enumeration (Iir_Index32 (Val), Origin); + return Build_Enumeration_Constant (Iir_Index32 (Val), Origin); when Iir_Kind_Integer_Type_Definition | Iir_Kind_Integer_Subtype_Definition => return Build_Integer (Val, Origin); @@ -193,18 +196,17 @@ package body Evaluation is Res := Create_Iir (Iir_Kind_Floating_Point_Literal); Set_Fp_Value (Res, Get_Fp_Value (Val)); when Iir_Kind_Enumeration_Literal => - return Get_Nth_Element - (Get_Enumeration_Literal_List - (Get_Base_Type (Get_Type (Origin))), - Integer (Get_Enum_Pos (Val))); + return Build_Enumeration_Constant + (Iir_Index32 (Get_Enum_Pos (Val)), Origin); when Iir_Kind_Physical_Int_Literal => declare - Prim : Iir; + Prim_Name : Iir; begin Res := Create_Iir (Iir_Kind_Physical_Int_Literal); - Prim := Get_Primary_Unit (Get_Base_Type (Get_Type (Origin))); - Set_Unit_Name (Res, Prim); - if Get_Unit_Name (Val) = Prim then + Prim_Name := Get_Primary_Unit_Name + (Get_Base_Type (Get_Type (Origin))); + Set_Unit_Name (Res, Prim_Name); + if Get_Unit_Name (Val) = Prim_Name then Set_Value (Res, Get_Value (Val)); else raise Internal_Error; @@ -215,7 +217,7 @@ package body Evaluation is when Iir_Kind_Unit_Declaration => Res := Create_Iir (Iir_Kind_Physical_Int_Literal); Set_Value (Res, Get_Physical_Value (Val)); - Set_Unit_Name (Res, Get_Primary_Unit (Get_Type (Val))); + Set_Unit_Name (Res, Get_Primary_Unit_Name (Get_Type (Val))); when Iir_Kind_String_Literal => Res := Create_Iir (Iir_Kind_String_Literal); @@ -247,6 +249,50 @@ package body Evaluation is return Res; end Build_Constant; + function Build_Boolean (Cond : Boolean) return Iir is + begin + if Cond then + return Boolean_True; + else + return Boolean_False; + end if; + end Build_Boolean; + + function Build_Enumeration (Val : Iir_Index32; Origin : Iir) + return Iir_Enumeration_Literal + is + Enum_Type : constant Iir := Get_Base_Type (Get_Type (Origin)); + Enum_List : constant Iir_List := + Get_Enumeration_Literal_List (Enum_Type); + begin + return Get_Nth_Element (Enum_List, Integer (Val)); + end Build_Enumeration; + + function Build_Enumeration (Val : Boolean; Origin : Iir) + return Iir_Enumeration_Literal + is + Enum_Type : constant Iir := Get_Base_Type (Get_Type (Origin)); + Enum_List : constant Iir_List := + Get_Enumeration_Literal_List (Enum_Type); + begin + return Get_Nth_Element (Enum_List, Boolean'Pos (Val)); + end Build_Enumeration; + + function Build_Constant_Range (Range_Expr : Iir; Origin : Iir) return Iir + is + Res : Iir; + begin + Res := Create_Iir (Iir_Kind_Range_Expression); + Location_Copy (Res, Origin); + Set_Type (Res, Get_Type (Range_Expr)); + Set_Left_Limit (Res, Get_Left_Limit (Range_Expr)); + Set_Right_Limit (Res, Get_Right_Limit (Range_Expr)); + Set_Direction (Res, Get_Direction (Range_Expr)); + Set_Range_Origin (Res, Origin); + Set_Expr_Staticness (Res, Locally); + return Res; + end Build_Constant_Range; + -- A_RANGE is a range expression, whose type, location, expr_staticness, -- left_limit and direction are set. -- Type of A_RANGE must have a range_constraint. @@ -367,10 +413,9 @@ package body Evaluation is (Base_Type : Iir; Len : Iir_Int64; Loc : Iir) return Iir_Array_Subtype_Definition is - Index_Type : Iir; + Index_Type : constant Iir := Get_Index_Type (Base_Type, 0); N_Index_Type : Iir; begin - Index_Type := Get_First_Element (Get_Index_Subtype_List (Base_Type)); N_Index_Type := Create_Range_Subtype_By_Length (Index_Type, Len, Get_Location (Loc)); return Create_Unidim_Array_From_Index (Base_Type, N_Index_Type, Loc); @@ -476,8 +521,7 @@ package body Evaluation is when Iir_Predefined_Boolean_Not | Iir_Predefined_Bit_Not => - return Build_Enumeration - (Boolean'Pos (Get_Enum_Pos (Operand) = 0), Orig); + return Build_Enumeration (Get_Enum_Pos (Operand) = 0, Orig); when Iir_Predefined_TF_Array_Not => declare @@ -528,6 +572,7 @@ package body Evaluation is R_Str : constant String_Fat_Acc := Get_String_Fat_Acc (Right); Len : Nat32; Id : String_Id; + Res : Iir; begin Len := Get_String_Length (Left); if Len /= Get_String_Length (Right) then @@ -624,7 +669,11 @@ package body Evaluation is Iir_Predefined_Functions'Image (Func)); end case; Finish; - return Build_String (Id, Len, Left); + Res := Build_String (Id, Len, Expr); + + -- The unconstrained type is replaced by the constrained one. + Set_Type (Res, Get_Type (Left)); + return Res; end if; end Eval_Dyadic_Bit_Array_Operator; @@ -823,21 +872,17 @@ package body Evaluation is -- The direction of the result is the direction of the left -- operand, [...] declare + Left_Index : constant Iir := + Get_Index_Type (Get_Type (Left), 0); + Left_Range : constant Iir := + Get_Range_Constraint (Left_Index); + Ret_Type : constant Iir := + Get_Return_Type (Get_Implementation (Orig)); A_Range : Iir; - Left_Index : Iir; - Left_Range : Iir; Index_Type : Iir; - Ret_Type : Iir; begin - Left_Index := Get_Nth_Element - (Get_Index_Subtype_List (Get_Type (Left)), 0); - Left_Range := Get_Range_Constraint (Left_Index); - A_Range := Create_Iir (Iir_Kind_Range_Expression); - Ret_Type := Get_Return_Type (Get_Implementation (Orig)); - Set_Type - (A_Range, - Get_First_Element (Get_Index_Subtype_List (Ret_Type))); + Set_Type (A_Range, Get_Index_Type (Ret_Type, 0)); Set_Expr_Staticness (A_Range, Locally); Set_Left_Limit (A_Range, Get_Left_Limit (Left_Range)); Set_Direction (A_Range, Get_Direction (Left_Range)); @@ -888,11 +933,12 @@ package body Evaluation is end Eval_Array_Equality; -- ORIG is either a dyadic operator or a function call. - function Eval_Dyadic_Operator (Orig : Iir; Left, Right : Iir) + function Eval_Dyadic_Operator (Orig : Iir; Imp : Iir; Left, Right : Iir) return Iir is pragma Unsuppress (Overflow_Check); - Func : Iir_Predefined_Functions; + Func : constant Iir_Predefined_Functions := + Get_Implicit_Definition (Imp); begin if Get_Kind (Left) = Iir_Kind_Overflow_Literal or else Get_Kind (Right) = Iir_Kind_Overflow_Literal @@ -900,7 +946,6 @@ package body Evaluation is return Build_Overflow (Orig); end if; - Func := Get_Implicit_Definition (Get_Implementation (Orig)); case Func is when Iir_Predefined_Integer_Plus => return Build_Integer (Get_Value (Left) + Get_Value (Right), Orig); @@ -934,43 +979,43 @@ package body Evaluation is (Get_Value (Left) ** Integer (Get_Value (Right)), Orig); when Iir_Predefined_Integer_Equality => - return Build_Boolean (Get_Value (Left) = Get_Value (Right), Orig); + return Build_Boolean (Get_Value (Left) = Get_Value (Right)); when Iir_Predefined_Integer_Inequality => - return Build_Boolean (Get_Value (Left) /= Get_Value (Right), Orig); + return Build_Boolean (Get_Value (Left) /= Get_Value (Right)); when Iir_Predefined_Integer_Greater_Equal => - return Build_Boolean (Get_Value (Left) >= Get_Value (Right), Orig); + return Build_Boolean (Get_Value (Left) >= Get_Value (Right)); when Iir_Predefined_Integer_Greater => - return Build_Boolean (Get_Value (Left) > Get_Value (Right), Orig); + return Build_Boolean (Get_Value (Left) > Get_Value (Right)); when Iir_Predefined_Integer_Less_Equal => - return Build_Boolean (Get_Value (Left) <= Get_Value (Right), Orig); + return Build_Boolean (Get_Value (Left) <= Get_Value (Right)); when Iir_Predefined_Integer_Less => - return Build_Boolean (Get_Value (Left) < Get_Value (Right), Orig); + return Build_Boolean (Get_Value (Left) < Get_Value (Right)); when Iir_Predefined_Integer_Minimum => - return Build_Integer - (Iir_Int64'Min (Get_Value (Left), Get_Value (Right)), Orig); + if Get_Value (Left) < Get_Value (Right) then + return Left; + else + return Right; + end if; when Iir_Predefined_Integer_Maximum => - return Build_Integer - (Iir_Int64'Max (Get_Value (Left), Get_Value (Right)), Orig); + if Get_Value (Left) > Get_Value (Right) then + return Left; + else + return Right; + end if; when Iir_Predefined_Floating_Equality => - return Build_Boolean - (Get_Fp_Value (Left) = Get_Fp_Value (Right), Orig); + return Build_Boolean (Get_Fp_Value (Left) = Get_Fp_Value (Right)); when Iir_Predefined_Floating_Inequality => - return Build_Boolean - (Get_Fp_Value (Left) /= Get_Fp_Value (Right), Orig); + return Build_Boolean (Get_Fp_Value (Left) /= Get_Fp_Value (Right)); when Iir_Predefined_Floating_Greater => - return Build_Boolean - (Get_Fp_Value (Left) > Get_Fp_Value (Right), Orig); + return Build_Boolean (Get_Fp_Value (Left) > Get_Fp_Value (Right)); when Iir_Predefined_Floating_Greater_Equal => - return Build_Boolean - (Get_Fp_Value (Left) >= Get_Fp_Value (Right), Orig); + return Build_Boolean (Get_Fp_Value (Left) >= Get_Fp_Value (Right)); when Iir_Predefined_Floating_Less => - return Build_Boolean - (Get_Fp_Value (Left) < Get_Fp_Value (Right), Orig); + return Build_Boolean (Get_Fp_Value (Left) < Get_Fp_Value (Right)); when Iir_Predefined_Floating_Less_Equal => - return Build_Boolean - (Get_Fp_Value (Left) <= Get_Fp_Value (Right), Orig); + return Build_Boolean (Get_Fp_Value (Left) <= Get_Fp_Value (Right)); when Iir_Predefined_Floating_Minus => return Build_Floating @@ -1012,30 +1057,36 @@ package body Evaluation is end; when Iir_Predefined_Floating_Minimum => - return Build_Floating - (Iir_Fp64'Min (Get_Fp_Value (Left), Get_Fp_Value (Right)), Orig); + if Get_Fp_Value (Left) < Get_Fp_Value (Right) then + return Left; + else + return Right; + end if; when Iir_Predefined_Floating_Maximum => - return Build_Floating - (Iir_Fp64'Max (Get_Fp_Value (Left), Get_Fp_Value (Right)), Orig); + if Get_Fp_Value (Left) > Get_Fp_Value (Right) then + return Left; + else + return Right; + end if; when Iir_Predefined_Physical_Equality => return Build_Boolean - (Get_Physical_Value (Left) = Get_Physical_Value (Right), Orig); + (Get_Physical_Value (Left) = Get_Physical_Value (Right)); when Iir_Predefined_Physical_Inequality => return Build_Boolean - (Get_Physical_Value (Left) /= Get_Physical_Value (Right), Orig); + (Get_Physical_Value (Left) /= Get_Physical_Value (Right)); when Iir_Predefined_Physical_Greater_Equal => return Build_Boolean - (Get_Physical_Value (Left) >= Get_Physical_Value (Right), Orig); + (Get_Physical_Value (Left) >= Get_Physical_Value (Right)); when Iir_Predefined_Physical_Greater => return Build_Boolean - (Get_Physical_Value (Left) > Get_Physical_Value (Right), Orig); + (Get_Physical_Value (Left) > Get_Physical_Value (Right)); when Iir_Predefined_Physical_Less_Equal => return Build_Boolean - (Get_Physical_Value (Left) <= Get_Physical_Value (Right), Orig); + (Get_Physical_Value (Left) <= Get_Physical_Value (Right)); when Iir_Predefined_Physical_Less => return Build_Boolean - (Get_Physical_Value (Left) < Get_Physical_Value (Right), Orig); + (Get_Physical_Value (Left) < Get_Physical_Value (Right)); when Iir_Predefined_Physical_Physical_Div => return Build_Integer @@ -1088,65 +1139,67 @@ package body Evaluation is when Iir_Predefined_Enum_Equality | Iir_Predefined_Bit_Match_Equality => - return Build_Boolean + return Build_Enumeration (Get_Enum_Pos (Left) = Get_Enum_Pos (Right), Orig); when Iir_Predefined_Enum_Inequality | Iir_Predefined_Bit_Match_Inequality => - return Build_Boolean + return Build_Enumeration (Get_Enum_Pos (Left) /= Get_Enum_Pos (Right), Orig); when Iir_Predefined_Enum_Greater_Equal | Iir_Predefined_Bit_Match_Greater_Equal => - return Build_Boolean + return Build_Enumeration (Get_Enum_Pos (Left) >= Get_Enum_Pos (Right), Orig); when Iir_Predefined_Enum_Greater | Iir_Predefined_Bit_Match_Greater => - return Build_Boolean + return Build_Enumeration (Get_Enum_Pos (Left) > Get_Enum_Pos (Right), Orig); when Iir_Predefined_Enum_Less_Equal | Iir_Predefined_Bit_Match_Less_Equal => - return Build_Boolean + return Build_Enumeration (Get_Enum_Pos (Left) <= Get_Enum_Pos (Right), Orig); when Iir_Predefined_Enum_Less | Iir_Predefined_Bit_Match_Less => - return Build_Boolean + return Build_Enumeration (Get_Enum_Pos (Left) < Get_Enum_Pos (Right), Orig); when Iir_Predefined_Enum_Minimum => - return Build_Enumeration - (Iir_Index32 (Iir_Int32'Min (Get_Enum_Pos (Left), - Get_Enum_Pos (Right))), - Orig); + if Get_Enum_Pos (Left) < Get_Enum_Pos (Right) then + return Left; + else + return Right; + end if; when Iir_Predefined_Enum_Maximum => - return Build_Enumeration - (Iir_Index32 (Iir_Int32'Max (Get_Enum_Pos (Left), - Get_Enum_Pos (Right))), - Orig); + if Get_Enum_Pos (Left) > Get_Enum_Pos (Right) then + return Left; + else + return Right; + end if; when Iir_Predefined_Boolean_And | Iir_Predefined_Bit_And => - return Build_Boolean + return Build_Enumeration (Get_Enum_Pos (Left) = 1 and Get_Enum_Pos (Right) = 1, Orig); when Iir_Predefined_Boolean_Nand | Iir_Predefined_Bit_Nand => - return Build_Boolean + return Build_Enumeration (not (Get_Enum_Pos (Left) = 1 and Get_Enum_Pos (Right) = 1), Orig); when Iir_Predefined_Boolean_Or | Iir_Predefined_Bit_Or => - return Build_Boolean + return Build_Enumeration (Get_Enum_Pos (Left) = 1 or Get_Enum_Pos (Right) = 1, Orig); when Iir_Predefined_Boolean_Nor | Iir_Predefined_Bit_Nor => - return Build_Boolean + return Build_Enumeration (not (Get_Enum_Pos (Left) = 1 or Get_Enum_Pos (Right) = 1), Orig); when Iir_Predefined_Boolean_Xor | Iir_Predefined_Bit_Xor => - return Build_Boolean + return Build_Enumeration (Get_Enum_Pos (Left) = 1 xor Get_Enum_Pos (Right) = 1, Orig); when Iir_Predefined_Boolean_Xnor | Iir_Predefined_Bit_Xnor => - return Build_Boolean + return Build_Enumeration (not (Get_Enum_Pos (Left) = 1 xor Get_Enum_Pos (Right) = 1), Orig); @@ -1165,10 +1218,10 @@ package body Evaluation is (Get_Fp_Value (Left) / Iir_Fp64 (Get_Value (Right)), Orig); when Iir_Predefined_Array_Equality => - return Build_Boolean (Eval_Array_Equality (Left, Right), Orig); + return Build_Boolean (Eval_Array_Equality (Left, Right)); when Iir_Predefined_Array_Inequality => - return Build_Boolean (not Eval_Array_Equality (Left, Right), Orig); + return Build_Boolean (not Eval_Array_Equality (Left, Right)); when Iir_Predefined_Array_Sll | Iir_Predefined_Array_Srl @@ -1316,7 +1369,7 @@ package body Evaluation is begin Prefix := Get_Prefix (Attr); case Get_Kind (Prefix) is - when Iir_Kinds_Object_Declaration + when Iir_Kinds_Object_Declaration -- FIXME: remove | Iir_Kind_Selected_Element | Iir_Kind_Indexed_Name | Iir_Kind_Slice_Name @@ -1330,6 +1383,8 @@ package body Evaluation is (Get_Expression (Get_Attribute_Specification (Prefix))); when Iir_Kinds_Subtype_Definition => Prefix_Type := Prefix; + when Iir_Kinds_Denoting_Name => + Prefix_Type := Get_Type (Prefix); when others => Error_Kind ("eval_array_attribute", Prefix); end case; @@ -1499,8 +1554,7 @@ package body Evaluation is function Eval_Physical_Image (Phys, Expr: Iir) return Iir is -- Reduces to the base unit (e.g. femtoseconds). - Value : constant String := - Iir_Int64'Image (Get_Physical_Literal_Value (Phys)); + Value : constant String := Iir_Int64'Image (Get_Physical_Value (Phys)); Unit : constant Iir := Get_Primary_Unit (Get_Base_Type (Get_Type (Phys))); UnitName : constant String := Image_Identifier (Unit); @@ -1637,21 +1691,14 @@ package body Evaluation is function Eval_Array_Type_Conversion (Conv : Iir; Val : Iir) return Iir is - Conv_Type : Iir; - Res : Iir; - Val_Type : Iir; - Conv_Index_Type : Iir; - Val_Index_Type : Iir; + Conv_Type : constant Iir := Get_Type (Conv); + Val_Type : constant Iir := Get_Type (Val); + Conv_Index_Type : constant Iir := Get_Index_Type (Conv_Type, 0); + Val_Index_Type : constant Iir := Get_Index_Type (Val_Type, 0); Index_Type : Iir; + Res : Iir; Rng : Iir; begin - Conv_Type := Get_Type (Conv); - Conv_Index_Type := Get_Nth_Element - (Get_Index_Subtype_List (Conv_Type), 0); - Val_Type := Get_Type (Val); - Val_Index_Type := Get_Nth_Element - (Get_Index_Subtype_List (Val_Type), 0); - -- The expression is either a simple aggregate or a (bit) string. Res := Build_Constant (Val, Conv); case Get_Kind (Conv_Type) is @@ -1695,8 +1742,7 @@ package body Evaluation is Val_Type : Iir; Conv_Type : Iir; begin - Val := Eval_Expr (Get_Expression (Expr)); - Set_Expression (Expr, Val); + Val := Eval_Static_Expr (Get_Expression (Expr)); Val_Type := Get_Base_Type (Get_Type (Val)); Conv_Type := Get_Base_Type (Get_Type (Expr)); if Conv_Type = Val_Type then @@ -1734,6 +1780,9 @@ package body Evaluation is Val : Iir; begin case Get_Kind (Expr) is + when Iir_Kinds_Denoting_Name => + return Eval_Static_Expr (Get_Named_Entity (Expr)); + when Iir_Kind_Integer_Literal | Iir_Kind_Enumeration_Literal | Iir_Kind_Floating_Point_Literal @@ -1747,48 +1796,46 @@ package body Evaluation is then return Expr; else + -- Convert to the primary unit. return Build_Physical (Get_Physical_Value (Expr), Expr); end if; when Iir_Kind_Physical_Fp_Literal => return Build_Physical (Get_Physical_Value (Expr), Expr); when Iir_Kind_Constant_Declaration => - Val := Get_Default_Value (Expr); - Res := Build_Constant (Val, Expr); + Val := Eval_Static_Expr (Get_Default_Value (Expr)); -- Type of the expression should be type of the constant -- declaration at least in case of array subtype. -- If the constant is declared as an unconstrained array, get type -- from the default value. - -- FIXME: handle this during semantisation of the declaration. - if Get_Kind (Get_Type (Res)) = Iir_Kind_Array_Type_Definition then + -- FIXME: handle this during semantisation of the declaration: + -- add an implicit subtype conversion node ? + -- FIXME: this currently creates a node at each evalation. + if Get_Kind (Get_Type (Val)) = Iir_Kind_Array_Type_Definition then + Res := Build_Constant (Val, Expr); Set_Type (Res, Get_Type (Val)); + return Res; + else + return Val; end if; - return Res; when Iir_Kind_Object_Alias_Declaration => - return Build_Constant (Eval_Static_Expr (Get_Name (Expr)), Expr); + return Eval_Static_Expr (Get_Name (Expr)); when Iir_Kind_Unit_Declaration => return Expr; when Iir_Kind_Simple_Aggregate => return Expr; when Iir_Kind_Parenthesis_Expression => - return Build_Constant - (Eval_Static_Expr (Get_Expression (Expr)), Expr); + return Eval_Static_Expr (Get_Expression (Expr)); when Iir_Kind_Qualified_Expression => - return Build_Constant - (Eval_Static_Expr (Get_Expression (Expr)), Expr); + return Eval_Static_Expr (Get_Expression (Expr)); when Iir_Kind_Type_Conversion => return Eval_Type_Conversion (Expr); - when Iir_Kind_Range_Expression => - Set_Left_Limit (Expr, Eval_Static_Expr (Get_Left_Limit (Expr))); - Set_Right_Limit (Expr, Eval_Static_Expr (Get_Right_Limit (Expr))); - return Expr; when Iir_Kinds_Monadic_Operator => declare Operand : Iir; begin Operand := Eval_Static_Expr (Get_Operand (Expr)); - Set_Operand (Expr, Operand); return Eval_Monadic_Operator (Expr, Operand); end; when Iir_Kinds_Dyadic_Operator => @@ -1798,39 +1845,38 @@ package body Evaluation is Left := Eval_Static_Expr (Get_Left (Expr)); Right := Eval_Static_Expr (Get_Right (Expr)); - Set_Left (Expr, Left); - Set_Right (Expr, Right); - return Eval_Dyadic_Operator (Expr, Left, Right); + return Eval_Dyadic_Operator + (Expr, Get_Implementation (Expr), Left, Right); end; when Iir_Kind_Attribute_Value => - -- FIXME. + -- FIXME: see constant_declaration. -- Currently, this avoids weird nodes, such as a string literal -- whose type is an unconstrained array type. Val := Get_Expression (Get_Attribute_Specification (Expr)); - Res := Build_Constant (Val, Expr); + Res := Build_Constant (Eval_Static_Expr (Val), Expr); Set_Type (Res, Get_Type (Val)); return Res; + when Iir_Kind_Attribute_Name => + return Eval_Static_Expr (Get_Named_Entity (Expr)); when Iir_Kind_Pos_Attribute => declare Val : Iir; begin - Val := Eval_Expr (Get_Parameter (Expr)); - Set_Parameter (Expr, Val); + Val := Eval_Static_Expr (Get_Parameter (Expr)); + -- FIXME: check bounds, handle overflow. return Build_Integer (Eval_Pos (Val), Expr); end; when Iir_Kind_Val_Attribute => declare + Expr_Type : constant Iir := Get_Type (Expr); Val_Expr : Iir; Val : Iir_Int64; - Expr_Type : Iir; begin - Val_Expr := Eval_Expr (Get_Parameter (Expr)); - Set_Parameter (Expr, Val_Expr); + Val_Expr := Eval_Static_Expr (Get_Parameter (Expr)); Val := Eval_Pos (Val_Expr); -- Note: the type of 'val is a base type. - Expr_Type := Get_Type (Expr); -- FIXME: handle VHDL93 restrictions. if Get_Kind (Expr_Type) = Iir_Kind_Enumeration_Type_Definition and then @@ -1906,50 +1952,21 @@ package body Evaluation is end; when Iir_Kind_Left_Type_Attribute => - return Build_Constant - (Get_Left_Limit (Eval_Range (Get_Prefix (Expr))), Expr); + return Eval_Static_Expr + (Get_Left_Limit (Eval_Static_Range (Get_Prefix (Expr)))); when Iir_Kind_Right_Type_Attribute => - return Build_Constant - (Get_Right_Limit (Eval_Range (Get_Prefix (Expr))), Expr); + return Eval_Static_Expr + (Get_Right_Limit (Eval_Static_Range (Get_Prefix (Expr)))); when Iir_Kind_High_Type_Attribute => - return Build_Constant - (Get_High_Limit (Eval_Range (Get_Prefix (Expr))), Expr); + return Eval_Static_Expr + (Get_High_Limit (Eval_Static_Range (Get_Prefix (Expr)))); when Iir_Kind_Low_Type_Attribute => - return Build_Constant - (Get_Low_Limit (Eval_Range (Get_Prefix (Expr))), Expr); + return Eval_Static_Expr + (Get_Low_Limit (Eval_Static_Range (Get_Prefix (Expr)))); when Iir_Kind_Ascending_Type_Attribute => return Build_Boolean - (Get_Direction (Eval_Range (Get_Prefix (Expr))) = Iir_To, Expr); + (Get_Direction (Eval_Static_Range (Get_Prefix (Expr))) = Iir_To); - when Iir_Kind_Range_Array_Attribute => - declare - Index : Iir; - begin - Index := Eval_Array_Attribute (Expr); - return Get_Range_Constraint (Index); - end; - when Iir_Kind_Reverse_Range_Array_Attribute => - declare - Res : Iir; - Rng : Iir; - begin - Rng := Get_Range_Constraint (Eval_Array_Attribute (Expr)); - Res := Create_Iir (Iir_Kind_Range_Expression); - Location_Copy (Res, Rng); - Set_Type (Res, Get_Type (Rng)); - case Get_Direction (Rng) is - when Iir_To => - Set_Direction (Res, Iir_Downto); - when Iir_Downto => - Set_Direction (Res, Iir_To); - end case; - Set_Left_Limit (Res, Get_Right_Limit (Rng)); - Set_Right_Limit (Res, Get_Left_Limit (Rng)); - -- FIXME: todo. - --Set_Literal_Origin (Res, Rng); - Set_Expr_Staticness (Res, Get_Expr_Staticness (Rng)); - return Res; - end; when Iir_Kind_Length_Array_Attribute => declare Index : Iir; @@ -1962,32 +1979,32 @@ package body Evaluation is Index : Iir; begin Index := Eval_Array_Attribute (Expr); - return Build_Constant - (Get_Left_Limit (Get_Range_Constraint (Index)), Expr); + return Eval_Static_Expr + (Get_Left_Limit (Get_Range_Constraint (Index))); end; when Iir_Kind_Right_Array_Attribute => declare Index : Iir; begin Index := Eval_Array_Attribute (Expr); - return Build_Constant - (Get_Right_Limit (Get_Range_Constraint (Index)), Expr); + return Eval_Static_Expr + (Get_Right_Limit (Get_Range_Constraint (Index))); end; when Iir_Kind_Low_Array_Attribute => declare Index : Iir; begin Index := Eval_Array_Attribute (Expr); - return Build_Constant - (Get_Low_Limit (Get_Range_Constraint (Index)), Expr); + return Eval_Static_Expr + (Get_Low_Limit (Get_Range_Constraint (Index))); end; when Iir_Kind_High_Array_Attribute => declare Index : Iir; begin Index := Eval_Array_Attribute (Expr); - return Build_Constant - (Get_High_Limit (Get_Range_Constraint (Index)), Expr); + return Eval_Static_Expr + (Get_High_Limit (Get_Range_Constraint (Index))); end; when Iir_Kind_Ascending_Array_Attribute => declare @@ -1995,16 +2012,16 @@ package body Evaluation is begin Index := Eval_Array_Attribute (Expr); return Build_Boolean - (Get_Direction (Get_Range_Constraint (Index)) = Iir_To, Expr); + (Get_Direction (Get_Range_Constraint (Index)) = Iir_To); end; when Iir_Kind_Pred_Attribute => Res := Eval_Incdec (Eval_Static_Expr (Get_Parameter (Expr)), -1); - Eval_Check_Bound (Res, Get_Type_Of_Type_Mark (Get_Prefix (Expr))); + Eval_Check_Bound (Res, Get_Type (Get_Prefix (Expr))); return Res; when Iir_Kind_Succ_Attribute => Res := Eval_Incdec (Eval_Static_Expr (Get_Parameter (Expr)), +1); - Eval_Check_Bound (Res, Get_Type_Of_Type_Mark (Get_Prefix (Expr))); + Eval_Check_Bound (Res, Get_Type (Get_Prefix (Expr))); return Res; when Iir_Kind_Leftof_Attribute | Iir_Kind_Rightof_Attribute => @@ -2014,8 +2031,8 @@ package body Evaluation is Prefix_Type : Iir; Res : Iir; begin - Prefix_Type := Get_Type_Of_Type_Mark (Get_Prefix (Expr)); - Rng := Eval_Range (Prefix_Type); + Prefix_Type := Get_Type (Get_Prefix (Expr)); + Rng := Eval_Static_Range (Prefix_Type); case Get_Direction (Rng) is when Iir_To => N := 1; @@ -2055,38 +2072,59 @@ package body Evaluation is when Iir_Kind_Function_Call => declare Left, Right : Iir; + Imp : constant Iir := + Get_Named_Entity (Get_Implementation (Expr)); begin -- Note: there can't be association by name. Left := Get_Parameter_Association_Chain (Expr); Right := Get_Chain (Left); + + Left := Eval_Static_Expr (Get_Actual (Left)); if Right = Null_Iir then - return Eval_Monadic_Operator (Expr, Get_Actual (Left)); + return Eval_Monadic_Operator (Expr, Left); else - return Eval_Dyadic_Operator - (Expr, Get_Actual (Left), Get_Actual (Right)); + Right := Eval_Static_Expr (Get_Actual (Right)); + return Eval_Dyadic_Operator (Expr, Imp, Left, Right); end if; end; + when Iir_Kind_Error => + return Expr; + when others => + Error_Kind ("eval_static_expr", Expr); + end case; + end Eval_Static_Expr; + + -- If FORCE is true, always return a literal. + function Eval_Expr_Keep_Orig (Expr : Iir; Force : Boolean) return Iir + is + Res : Iir; + begin + case Get_Kind (Expr) is when Iir_Kind_Simple_Name | Iir_Kind_Character_Literal | Iir_Kind_Selected_Name => declare Orig : constant Iir := Get_Named_Entity (Expr); - Res : Iir; begin Res := Eval_Static_Expr (Orig); - if Res /= Orig then + if Res /= Orig or else Force then return Build_Constant (Res, Expr); else - return Res; + return Expr; end if; end; - when Iir_Kind_Error => - return Expr; when others => - Error_Kind ("eval_static_expr", Expr); + Res := Eval_Static_Expr (Expr); + if Res /= Expr + and then Get_Literal_Origin (Res) /= Expr + then + return Build_Constant (Res, Expr); + else + return Res; + end if; end case; - end Eval_Static_Expr; + end Eval_Expr_Keep_Orig; function Eval_Expr (Expr: Iir) return Iir is begin @@ -2094,31 +2132,45 @@ package body Evaluation is Error_Msg_Sem ("expression must be locally static", Expr); return Expr; else - return Eval_Static_Expr (Expr); + return Eval_Expr_Keep_Orig (Expr, False); end if; end Eval_Expr; function Eval_Expr_If_Static (Expr : Iir) return Iir is begin if Expr /= Null_Iir and then Get_Expr_Staticness (Expr) = Locally then - return Eval_Static_Expr (Expr); + return Eval_Expr_Keep_Orig (Expr, False); else return Expr; end if; end Eval_Expr_If_Static; + function Eval_Expr_Check (Expr : Iir; Sub_Type : Iir) return Iir + is + Res : Iir; + begin + Res := Eval_Expr_Keep_Orig (Expr, False); + Eval_Check_Bound (Res, Sub_Type); + return Res; + end Eval_Expr_Check; + function Eval_Expr_Check_If_Static (Expr : Iir; Atype : Iir) return Iir is Res : Iir; begin if Expr /= Null_Iir and then Get_Expr_Staticness (Expr) = Locally then - Res := Eval_Expr (Expr); + -- Expression is static and can be evaluated. + Res := Eval_Expr_Keep_Orig (Expr, False); + if Res /= Null_Iir and then Get_Type_Staticness (Atype) = Locally and then Get_Kind (Atype) in Iir_Kinds_Range_Type_Definition then + -- Check bounds (as this can be done). + -- FIXME: create overflow_expr ? Eval_Check_Bound (Res, Atype); end if; + return Res; else return Expr; @@ -2208,38 +2260,46 @@ package body Evaluation is end Eval_Fp_In_Range; -- Return TRUE if literal EXPR is in SUB_TYPE bounds. - function Eval_Is_In_Bound (Expr : Iir; Sub_Type : Iir) - return Boolean + function Eval_Is_In_Bound (Expr : Iir; Sub_Type : Iir) return Boolean is Type_Range : Iir; + Val : Iir; begin - if Get_Kind (Expr) = Iir_Kind_Error then - return True; - end if; - if Get_Kind (Expr) = Iir_Kind_Overflow_Literal then - return False; - end if; + case Get_Kind (Expr) is + when Iir_Kind_Error => + -- Ignore errors. + return True; + when Iir_Kind_Overflow_Literal => + -- Never within bounds + return False; + when Iir_Kind_Simple_Name + | Iir_Kind_Character_Literal + | Iir_Kind_Selected_Name => + Val := Get_Named_Entity (Expr); + when others => + Val := Expr; + end case; case Get_Kind (Sub_Type) is when Iir_Kind_Integer_Subtype_Definition => Type_Range := Get_Range_Constraint (Sub_Type); - return Eval_Int_In_Range (Get_Value (Expr), Type_Range); + return Eval_Int_In_Range (Get_Value (Val), Type_Range); when Iir_Kind_Floating_Subtype_Definition => Type_Range := Get_Range_Constraint (Sub_Type); - return Eval_Fp_In_Range (Get_Fp_Value (Expr), Type_Range); + return Eval_Fp_In_Range (Get_Fp_Value (Val), Type_Range); when Iir_Kind_Enumeration_Subtype_Definition | Iir_Kind_Enumeration_Type_Definition => -- A check is required for an enumeration type definition for -- 'val attribute. Type_Range := Get_Range_Constraint (Sub_Type); return Eval_Int_In_Range - (Iir_Int64 (Get_Enum_Pos (Expr)), Type_Range); + (Iir_Int64 (Get_Enum_Pos (Val)), Type_Range); when Iir_Kind_Physical_Subtype_Definition => Type_Range := Get_Range_Constraint (Sub_Type); - return Eval_Phys_In_Range (Get_Physical_Value (Expr), Type_Range); + return Eval_Phys_In_Range (Get_Physical_Value (Val), Type_Range); when Iir_Kind_Base_Attribute => - return Eval_Is_In_Bound (Expr, Get_Type (Sub_Type)); + return Eval_Is_In_Bound (Val, Get_Type (Sub_Type)); when Iir_Kind_Array_Subtype_Definition | Iir_Kind_Array_Type_Definition @@ -2247,16 +2307,8 @@ package body Evaluation is -- FIXME: do it. return True; - --when Iir_Kind_Integer_Type_Definition => - -- This case should not happen but it may be called to check a - -- simple choice value belongs to the *type* of the case - -- expression. - -- Of course, this is always true. - -- return True; - when others => Error_Kind ("eval_is_in_bound", Sub_Type); - return False; end case; end Eval_Is_In_Bound; @@ -2277,10 +2329,11 @@ package body Evaluation is return Boolean is Type_Range : Iir; + Range_Constraint : constant Iir := Eval_Static_Range (A_Range); begin Type_Range := Get_Range_Constraint (Sub_Type); if not Any_Dir - and then Get_Direction (Type_Range) /= Get_Direction (A_Range) + and then Get_Direction (Type_Range) /= Get_Direction (Range_Constraint) then return True; end if; @@ -2294,9 +2347,9 @@ package body Evaluation is L, R : Iir_Int64; begin -- Check for null range. - L := Eval_Pos (Get_Left_Limit (A_Range)); - R := Eval_Pos (Get_Right_Limit (A_Range)); - case Get_Direction (A_Range) is + L := Eval_Pos (Get_Left_Limit (Range_Constraint)); + R := Eval_Pos (Get_Right_Limit (Range_Constraint)); + case Get_Direction (Range_Constraint) is when Iir_To => if L > R then return True; @@ -2314,9 +2367,9 @@ package body Evaluation is L, R : Iir_Fp64; begin -- Check for null range. - L := Get_Fp_Value (Get_Left_Limit (A_Range)); - R := Get_Fp_Value (Get_Right_Limit (A_Range)); - case Get_Direction (A_Range) is + L := Get_Fp_Value (Get_Left_Limit (Range_Constraint)); + R := Get_Fp_Value (Get_Right_Limit (Range_Constraint)); + case Get_Direction (Range_Constraint) is when Iir_To => if L > R then return True; @@ -2347,15 +2400,6 @@ package body Evaluation is end if; end Eval_Check_Range; - function Eval_Expr_Check (Expr : Iir; Sub_Type : Iir) return Iir - is - Res : Iir; - begin - Res := Eval_Expr (Expr); - Eval_Check_Bound (Res, Sub_Type); - return Res; - end Eval_Expr_Check; - function Eval_Discrete_Range_Length (Constraint : Iir) return Iir_Int64 is Res : Iir_Int64; @@ -2407,19 +2451,32 @@ package body Evaluation is return Get_Physical_Value (Expr); when Iir_Kind_Unit_Declaration => return Get_Value (Get_Physical_Unit_Value (Expr)); + when Iir_Kinds_Denoting_Name => + return Eval_Pos (Get_Named_Entity (Expr)); when others => Error_Kind ("eval_pos", Expr); end case; end Eval_Pos; - function Eval_Range (Rng : Iir) return Iir + function Eval_Static_Range (Rng : Iir) return Iir is Expr : Iir; + Kind : Iir_Kind; begin Expr := Rng; loop - case Get_Kind (Expr) is + Kind := Get_Kind (Expr); + case Kind is when Iir_Kind_Range_Expression => + if Get_Expr_Staticness (Expr) /= Locally then + return Null_Iir; + end if; + + -- Normalize the range expression. + Set_Left_Limit + (Expr, Eval_Expr_Keep_Orig (Get_Left_Limit (Expr), True)); + Set_Right_Limit + (Expr, Eval_Expr_Keep_Orig (Get_Right_Limit (Expr), True)); return Expr; when Iir_Kind_Integer_Subtype_Definition | Iir_Kind_Floating_Subtype_Definition @@ -2427,9 +2484,11 @@ package body Evaluation is | Iir_Kind_Enumeration_Subtype_Definition | Iir_Kind_Physical_Subtype_Definition => Expr := Get_Range_Constraint (Expr); - when Iir_Kind_Range_Array_Attribute => + when Iir_Kind_Range_Array_Attribute + | Iir_Kind_Reverse_Range_Array_Attribute => declare Prefix : Iir; + Res : Iir; begin Prefix := Get_Prefix (Expr); if Get_Kind (Prefix) /= Iir_Kind_Array_Subtype_Definition @@ -2444,26 +2503,68 @@ package body Evaluation is Expr := Get_Nth_Element (Get_Index_Subtype_List (Prefix), Natural (Eval_Pos (Get_Parameter (Expr))) - 1); + if Kind = Iir_Kind_Reverse_Range_Array_Attribute then + Expr := Eval_Static_Range (Expr); + + Res := Create_Iir (Iir_Kind_Range_Expression); + Location_Copy (Res, Expr); + Set_Type (Res, Get_Type (Expr)); + case Get_Direction (Expr) is + when Iir_To => + Set_Direction (Res, Iir_Downto); + when Iir_Downto => + Set_Direction (Res, Iir_To); + end case; + Set_Left_Limit (Res, Get_Right_Limit (Expr)); + Set_Right_Limit (Res, Get_Left_Limit (Expr)); + Set_Range_Origin (Res, Expr); + Set_Expr_Staticness (Res, Get_Expr_Staticness (Expr)); + return Res; + end if; end; + when Iir_Kind_Subtype_Declaration | Iir_Kind_Base_Attribute => - return Eval_Range (Get_Type (Expr)); + Expr := Get_Type (Expr); when Iir_Kind_Type_Declaration => - return Eval_Range (Get_Type_Definition (Expr)); + Expr := Get_Type_Definition (Expr); + when Iir_Kind_Simple_Name + | Iir_Kind_Selected_Name => + Expr := Get_Named_Entity (Expr); when others => - Error_Kind ("eval_range", Expr); + Error_Kind ("eval_static_range", Expr); end case; end loop; + end Eval_Static_Range; + + function Eval_Range (Arange : Iir) return Iir is + Res : Iir; + begin + Res := Eval_Static_Range (Arange); + if Res /= Arange then + return Build_Constant_Range (Res, Arange); + else + return Res; + end if; end Eval_Range; + function Eval_Range_If_Static (Arange : Iir) return Iir is + begin + if Get_Expr_Staticness (Arange) /= Locally then + return Arange; + else + return Eval_Range (Arange); + end if; + end Eval_Range_If_Static; + -- Return the range constraint of a discrete range. function Eval_Discrete_Range_Expression (Constraint : Iir) return Iir is Res : Iir; begin - Res := Eval_Range (Constraint); + Res := Eval_Static_Range (Constraint); if Res = Null_Iir then - Error_Kind ("eval_range_expression", Constraint); + Error_Kind ("eval_discrete_range_expression", Constraint); else return Res; end if; @@ -2799,7 +2900,7 @@ package body Evaluation is end case; end Path_Add_Element; - Prefix : constant Iir := Get_Prefix (Attr); + Prefix : constant Iir := Get_Named_Entity (Get_Prefix (Attr)); Is_Instance : constant Boolean := Get_Kind (Attr) = Iir_Kind_Instance_Name_Attribute; begin diff --git a/evaluation.ads b/evaluation.ads index 86dd977b4..e22f36a6f 100644 --- a/evaluation.ads +++ b/evaluation.ads @@ -20,20 +20,42 @@ with Iirs; use Iirs; package Evaluation is + -- Evaluation is about compile-time computation of expressions, such as + -- 2 + 1 --> 3. This is (of course) possible only with locally (and some + -- globally) static expressions. Evaluation is required during semantic + -- analysis at many places (in fact those where locally static expression + -- are required by the language). For example, the type of O'Range (N) + -- depends on N, so we need to evaluate N. + -- + -- The result of evaluation is a literal (integer, enumeration, real, + -- physical), a string or a simple aggregate. For scalar types, the + -- result is therefore normalized (there is only one kind of result), but + -- for array types, the result isn't: in general it will be a string, but + -- it may be a simple aggregate. Strings are preferred (because they are + -- more compact), but aren't possible in some cases. For example, the + -- evaluation of "Text" & NUL cannot be a string. + -- + -- Some functions (like Eval_Static_Expr) simply returns a result (which + -- may be a node of the expression), others returns a result and set the + -- origin (Literal_Origin or Range_Origin) to remember the original + -- expression that was evaluation. The original expression is kept so that + -- it is possible to print the original tree. + -- Get the value of a physical integer literal or unit. function Get_Physical_Value (Expr : Iir) return Iir_Int64; + -- Evaluate the locally static expression EXPR (without checking that EXPR + -- is locally static). Return a literal or an aggregate, without setting + -- the origin, and do not modify EXPR. This can be used only to get the + -- value of an expression, without replacing it. + function Eval_Static_Expr (Expr: Iir) return Iir; + -- Evaluate (ie compute) expression EXPR. -- EXPR is required to be a locally static expression, otherwise an error -- message is generated. - -- The result is a literal. + -- The result is a literal with the origin set. function Eval_Expr (Expr: Iir) return Iir; - -- Same as Eval_Expr, but do not check that EXPR is locally static. - -- May be used instead of Eval_Expr if you know than EXPR is locally - -- static, or for literals of type std.time. - function Eval_Static_Expr (Expr: Iir) return Iir; - -- Same as Eval_Expr, but if EXPR is not locally static, the result is -- EXPR. Also, if EXPR is null_iir, then null_iir is returned. -- The purpose of this function is to evaluate an expression only if it @@ -46,15 +68,6 @@ package Evaluation is -- Emit an error if EXPR violates SUB_TYPE bounds. procedure Eval_Check_Bound (Expr : Iir; Sub_Type : Iir); - -- Return TRUE if range expression A_RANGE is not included in SUB_TYPE. - function Eval_Is_Range_In_Bound - (A_Range : Iir; Sub_Type : Iir; Any_Dir : Boolean) - return Boolean; - - -- Emit an error if A_RANGE is not included in SUB_TYPE. - procedure Eval_Check_Range (A_Range : Iir; Sub_Type : Iir; - Any_Dir : Boolean); - -- Same as Eval_Expr, but a range check with SUB_TYPE is performed after -- computation. function Eval_Expr_Check (Expr : Iir; Sub_Type : Iir) return Iir; @@ -62,6 +75,31 @@ package Evaluation is -- Call Eval_Expr_Check only if EXPR is static. function Eval_Expr_Check_If_Static (Expr : Iir; Atype : Iir) return Iir; + -- For a locally static range RNG (a range expression, a range attribute + -- or a name that denotes a type or a subtype) returns its corresponding + -- locally static range_expression. The bounds of the results are also + -- literals. + -- Return a range_expression or NULL_IIR for a non locally static range. + function Eval_Static_Range (Rng : Iir) return Iir; + + -- Return a locally static range expression with the origin set for ARANGE. + function Eval_Range (Arange : Iir) return Iir; + + -- If ARANGE is a locally static range, return locally static range + -- expression (with the origin set), else return ARANGE. + function Eval_Range_If_Static (Arange : Iir) return Iir; + + -- Emit an error if A_RANGE is not included in SUB_TYPE. A_RANGE can be + -- a range expression, a range attribute or a name that denotes a discrete + -- type or subtype. A_RANGE must be a locally static range. + procedure Eval_Check_Range (A_Range : Iir; Sub_Type : Iir; + Any_Dir : Boolean); + + -- Return TRUE if range expression A_RANGE is not included in SUB_TYPE. + function Eval_Is_Range_In_Bound + (A_Range : Iir; Sub_Type : Iir; Any_Dir : Boolean) + return Boolean; + -- Return TRUE iff VAL belongs to BOUND. function Eval_Int_In_Range (Val : Iir_Int64; Bound : Iir) return Boolean; @@ -75,10 +113,6 @@ package Evaluation is -- Note: the range constraint may be an attribute or a subtype. function Eval_Discrete_Range_Left (Constraint : Iir) return Iir; - -- Return the range_expression of RNG, which is a range or a subtype. - -- Return NULL_IIR if the range constraint is not a range_expression. - function Eval_Range (Rng : Iir) return Iir; - -- Return the position of EXPR, ie the result of sub_type'pos (EXPR), where -- sub_type is the type of expr. -- EXPR must be of a discrete subtype. @@ -96,7 +130,7 @@ package Evaluation is (A_Type : Iir; Len : Iir_Int64; Loc : Location_Type) return Iir; - -- Store into NAME_BUFFER,NAME_LENGTH the simple name, character literal + -- Store into NAME_BUFFER, NAME_LENGTH the simple name, character literal -- or operator sumbol of ID, using the same format as SIMPLE_NAME -- attribute. procedure Eval_Simple_Name (Id : Name_Id); diff --git a/ieee-std_logic_1164.adb b/ieee-std_logic_1164.adb index 4accb0a3f..ee58fe7a5 100644 --- a/ieee-std_logic_1164.adb +++ b/ieee-std_logic_1164.adb @@ -19,7 +19,6 @@ with Types; use Types; with Std_Names; use Std_Names; with Errorout; use Errorout; with Std_Package; -with Iirs_Utils; use Iirs_Utils; package body Ieee.Std_Logic_1164 is function Skip_Implicit (Decl : Iir) return Iir @@ -120,7 +119,7 @@ package body Ieee.Std_Logic_1164 is then raise Error; end if; - Def := Get_Type_Of_Type_Mark (Decl); + Def := Get_Type (Decl); -- if Get_Kind (Def) /= Iir_Kind_Array_Type_Definition then -- raise Error; -- end if; @@ -169,5 +168,3 @@ package body Ieee.Std_Logic_1164 is Falling_Edge := Null_Iir; end Extract_Declarations; end Ieee.Std_Logic_1164; - - diff --git a/ieee-vital_timing.adb b/ieee-vital_timing.adb index 20315556b..361d0f663 100644 --- a/ieee-vital_timing.adb +++ b/ieee-vital_timing.adb @@ -25,6 +25,7 @@ with Ieee.Std_Logic_1164; use Ieee.Std_Logic_1164; with Sem_Scopes; with Evaluation; with Sem; +with Iirs_Utils; with Flags; package body Ieee.Vital_Timing is @@ -207,7 +208,9 @@ package body Ieee.Vital_Timing is -- The expression in the VITAL_Level0 attribute specification shall be -- the Boolean literal TRUE. Expr := Get_Expression (Decl); - if Expr /= Boolean_True then + if Get_Kind (Expr) not in Iir_Kinds_Denoting_Name + or else Get_Named_Entity (Expr) /= Boolean_True + then Error_Vital ("the expression in the VITAL_Level0 attribute specification shall " & "be the Boolean literal TRUE", Decl); @@ -1304,12 +1307,12 @@ package body Ieee.Vital_Timing is end Check_Vital_Level0_Entity; -- Return TRUE if UNIT was decorated with attribute VITAL_Level0. - function Is_Vital_Level0 (Unit : Iir_Design_Unit) return Boolean + function Is_Vital_Level0 (Unit : Iir_Entity_Declaration) return Boolean is Value : Iir_Attribute_Value; Spec : Iir_Attribute_Specification; begin - Value := Get_Attribute_Value_Chain (Get_Library_Unit (Unit)); + Value := Get_Attribute_Value_Chain (Unit); while Value /= Null_Iir loop Spec := Get_Attribute_Specification (Value); if Get_Attribute_Designator (Spec) = Vital_Level0_Attribute then @@ -1328,7 +1331,7 @@ package body Ieee.Vital_Timing is -- IEEE 1076.4 4.1 -- The entity associated with a Level 0 architecture shall be a VITAL -- Level 0 entity. - if not Is_Vital_Level0 (Get_Design_Unit (Get_Entity (Arch))) then + if not Is_Vital_Level0 (Iirs_Utils.Get_Entity (Arch)) then Error_Vital ("entity associated with a VITAL level 0 architecture " & "shall be a VITAL level 0 entity", Arch); end if; @@ -114,16 +114,6 @@ package body Iirs is end case; end Iir_Predefined_Shortcut_P; - function Create_Proxy (Proxy: Iir) return Iir_Proxy is - Res : Iir_Proxy; - begin - Res := Create_Iir (Iir_Kind_Proxy); - Set_Proxy (Res, Proxy); - return Res; - end Create_Proxy; - - -- - function Create_Iir_Error return Iir is Res : Iir; @@ -148,74 +138,6 @@ package body Iirs is return Iir_Kind'Val (Get_Nkind (An_Iir)); end Get_Kind; --- function Clone_Iir (Src : Iir; New_Kind : Iir_Kind) return Iir --- is --- Res : Iir; --- begin --- Res := new Iir_Node (New_Kind); --- Res.Flag1 := Src.Flag1; --- Res.Flag2 := Src.Flag2; --- Res.Flag3 := Src.Flag3; --- Res.Flag4 := Src.Flag4; --- Res.Flag5 := Src.Flag5; --- Res.Flag6 := Src.Flag6; --- Res.Flag7 := Src.Flag7; --- Res.Flag8 := Src.Flag8; --- Res.State1 := Src.State1; --- Res.State2 := Src.State2; --- Res.State3 := Src.State3; --- Res.Staticness1 := Src.Staticness1; --- Res.Staticness2 := Src.Staticness2; --- Res.Odigit1 := Src.Odigit1; --- Res.Odigit2 := Src.Odigit2; --- Res.Location := Src.Location; --- Res.Back_End_Info := Src.Back_End_Info; --- Res.Identifier := Src.Identifier; --- Res.Field1 := Src.Field1; --- Res.Field2 := Src.Field2; --- Res.Field3 := Src.Field3; --- Res.Field4 := Src.Field4; --- Res.Field5 := Src.Field5; --- Res.Nbr2 := Src.Nbr2; --- Res.Nbr3 := Src.Nbr3; - --- Src.Identifier := Null_Identifier; --- Src.Field1 := null; --- Src.Field2 := null; --- Src.Field3 := null; --- Src.Field4 := null; --- Src.Field5 := null; --- return Res; --- end Clone_Iir; - - - ----------------- - -- design file -- - ----------------- - - -- Iir_Design_File - --- type Int_Access_Type is new Integer; --- for Int_Access_Type'Size use System.Word_Size; --Iir_Identifier_Acc'Size; - - -- Safe conversions. --- function Iir_To_Int_Access_Type is --- new Ada.Unchecked_Conversion (Source => Iir, --- Target => Int_Access_Type); --- function Int_Access_Type_To_Iir is --- new Ada.Unchecked_Conversion (Source => Int_Access_Type, --- Target => Iir); - --- function To_Iir (V : Integer) return Iir is --- begin --- return Int_Access_Type_To_Iir (Int_Access_Type (V)); --- end To_Iir; - --- function To_Integer (N : Iir) return Integer is --- begin --- return Integer (Iir_To_Int_Access_Type (N)); --- end To_Integer; - procedure Set_Pos_Line_Off (Design_Unit: Iir_Design_Unit; Pos : Source_Ptr; Line, Off: Natural) is begin @@ -235,6 +157,7 @@ package body Iirs is ----------- -- Lists -- ----------- + -- Layout of lists: -- A list is stored into an IIR. -- There are two bounds for a list: @@ -330,12 +253,10 @@ package body Iirs is when Iir_Kind_Error | Iir_Kind_Library_Clause | Iir_Kind_Use_Clause - | Iir_Kind_Character_Literal | Iir_Kind_Null_Literal | Iir_Kind_String_Literal | Iir_Kind_Simple_Aggregate | Iir_Kind_Overflow_Literal - | Iir_Kind_Proxy | Iir_Kind_Waveform_Element | Iir_Kind_Conditional_Waveform | Iir_Kind_Association_Element_By_Expression @@ -356,7 +277,6 @@ package body Iirs is | Iir_Kind_Signature | Iir_Kind_Aggregate_Info | Iir_Kind_Procedure_Call - | Iir_Kind_Operator_Symbol | Iir_Kind_Record_Element_Constraint | Iir_Kind_Disconnection_Specification | Iir_Kind_Configuration_Specification @@ -445,6 +365,8 @@ package body Iirs is | Iir_Kind_Selected_Element | Iir_Kind_Dereference | Iir_Kind_Implicit_Dereference + | Iir_Kind_Slice_Name + | Iir_Kind_Indexed_Name | Iir_Kind_Psl_Expression | Iir_Kind_Psl_Default_Clock | Iir_Kind_Concurrent_Procedure_Call_Statement @@ -457,10 +379,10 @@ package body Iirs is | Iir_Kind_Exit_Statement | Iir_Kind_Case_Statement | Iir_Kind_Procedure_Call_Statement + | Iir_Kind_Character_Literal | Iir_Kind_Simple_Name - | Iir_Kind_Slice_Name - | Iir_Kind_Indexed_Name | Iir_Kind_Selected_Name + | Iir_Kind_Operator_Symbol | Iir_Kind_Selected_By_All_Name | Iir_Kind_Parenthesis_Name | Iir_Kind_Base_Attribute @@ -1284,27 +1206,27 @@ package body Iirs is Set_Field2 (Lit, Orig); end Set_Literal_Origin; - procedure Check_Kind_For_Proxy (Target : Iir) is + procedure Check_Kind_For_Range_Origin (Target : Iir) is begin case Get_Kind (Target) is - when Iir_Kind_Proxy => + when Iir_Kind_Range_Expression => null; when others => - Failed ("Proxy", Target); + Failed ("Range_Origin", Target); end case; - end Check_Kind_For_Proxy; + end Check_Kind_For_Range_Origin; - function Get_Proxy (Target : Iir_Proxy) return Iir is + function Get_Range_Origin (Lit : Iir) return Iir is begin - Check_Kind_For_Proxy (Target); - return Get_Field1 (Target); - end Get_Proxy; + Check_Kind_For_Range_Origin (Lit); + return Get_Field4 (Lit); + end Get_Range_Origin; - procedure Set_Proxy (Target : Iir_Proxy; Proxy : Iir) is + procedure Set_Range_Origin (Lit : Iir; Orig : Iir) is begin - Check_Kind_For_Proxy (Target); - Set_Field1 (Target, Proxy); - end Set_Proxy; + Check_Kind_For_Range_Origin (Lit); + Set_Field4 (Lit, Orig); + end Set_Range_Origin; procedure Check_Kind_For_Entity_Class (Target : Iir) is begin @@ -1430,13 +1352,13 @@ package body Iirs is function Get_Signal_List (Target : Iir) return Iir_List is begin Check_Kind_For_Signal_List (Target); - return Iir_To_Iir_List (Get_Field4 (Target)); + return Iir_To_Iir_List (Get_Field3 (Target)); end Get_Signal_List; procedure Set_Signal_List (Target : Iir; List : Iir_List) is begin Check_Kind_For_Signal_List (Target); - Set_Field4 (Target, Iir_List_To_Iir (List)); + Set_Field3 (Target, Iir_List_To_Iir (List)); end Set_Signal_List; procedure Check_Kind_For_Designated_Entity (Target : Iir) is @@ -1976,7 +1898,7 @@ package body Iirs is Set_Field4 (Target, Chain); end Set_Attribute_Value_Spec_Chain; - procedure Check_Kind_For_Entity (Target : Iir) is + procedure Check_Kind_For_Entity_Name (Target : Iir) is begin case Get_Kind (Target) is when Iir_Kind_Entity_Aspect_Entity @@ -1984,29 +1906,6 @@ package body Iirs is | Iir_Kind_Architecture_Body => null; when others => - Failed ("Entity", Target); - end case; - end Check_Kind_For_Entity; - - function Get_Entity (Decl : Iir) return Iir is - begin - Check_Kind_For_Entity (Decl); - return Get_Field2 (Decl); - end Get_Entity; - - procedure Set_Entity (Decl : Iir; Entity : Iir) is - begin - Check_Kind_For_Entity (Decl); - Set_Field2 (Decl, Entity); - end Set_Entity; - - procedure Check_Kind_For_Entity_Name (Target : Iir) is - begin - case Get_Kind (Target) is - when Iir_Kind_Configuration_Declaration - | Iir_Kind_Architecture_Body => - null; - when others => Failed ("Entity_Name", Target); end case; end Check_Kind_For_Entity_Name; @@ -2014,13 +1913,13 @@ package body Iirs is function Get_Entity_Name (Arch : Iir) return Iir is begin Check_Kind_For_Entity_Name (Arch); - return Get_Field7 (Arch); + return Get_Field2 (Arch); end Get_Entity_Name; procedure Set_Entity_Name (Arch : Iir; Entity : Iir) is begin Check_Kind_For_Entity_Name (Arch); - Set_Field7 (Arch, Entity); + Set_Field2 (Arch, Entity); end Set_Entity_Name; procedure Check_Kind_For_Package (Target : Iir) is @@ -2303,7 +2202,6 @@ package body Iirs is begin case Get_Kind (Target) is when Iir_Kind_Error - | Iir_Kind_Character_Literal | Iir_Kind_Integer_Literal | Iir_Kind_Floating_Point_Literal | Iir_Kind_Null_Literal @@ -2315,8 +2213,8 @@ package body Iirs is | Iir_Kind_Overflow_Literal | Iir_Kind_Attribute_Value | Iir_Kind_Record_Element_Constraint - | Iir_Kind_Disconnection_Specification | Iir_Kind_Range_Expression + | Iir_Kind_Type_Declaration | Iir_Kind_Subtype_Declaration | Iir_Kind_Unit_Declaration | Iir_Kind_Attribute_Declaration @@ -2391,12 +2289,14 @@ package body Iirs is | Iir_Kind_Selected_Element | Iir_Kind_Dereference | Iir_Kind_Implicit_Dereference + | Iir_Kind_Slice_Name + | Iir_Kind_Indexed_Name | Iir_Kind_Psl_Expression | Iir_Kind_Return_Statement + | Iir_Kind_Character_Literal | Iir_Kind_Simple_Name - | Iir_Kind_Slice_Name - | Iir_Kind_Indexed_Name | Iir_Kind_Selected_Name + | Iir_Kind_Operator_Symbol | Iir_Kind_Selected_By_All_Name | Iir_Kind_Parenthesis_Name | Iir_Kind_Base_Attribute @@ -2454,6 +2354,61 @@ package body Iirs is Set_Field1 (Target, Atype); end Set_Type; + procedure Check_Kind_For_Subtype_Indication (Target : Iir) is + begin + case Get_Kind (Target) is + when Iir_Kind_Subtype_Declaration + | Iir_Kind_Element_Declaration + | Iir_Kind_Object_Alias_Declaration + | Iir_Kind_File_Declaration + | Iir_Kind_Signal_Declaration + | Iir_Kind_Variable_Declaration + | Iir_Kind_Constant_Declaration + | Iir_Kind_Constant_Interface_Declaration + | Iir_Kind_Variable_Interface_Declaration + | Iir_Kind_Signal_Interface_Declaration + | Iir_Kind_File_Interface_Declaration + | Iir_Kind_Allocator_By_Subtype => + null; + when others => + Failed ("Subtype_Indication", Target); + end case; + end Check_Kind_For_Subtype_Indication; + + function Get_Subtype_Indication (Target : Iir) return Iir is + begin + Check_Kind_For_Subtype_Indication (Target); + return Get_Field5 (Target); + end Get_Subtype_Indication; + + procedure Set_Subtype_Indication (Target : Iir; Atype : Iir) is + begin + Check_Kind_For_Subtype_Indication (Target); + Set_Field5 (Target, Atype); + end Set_Subtype_Indication; + + procedure Check_Kind_For_Discrete_Range (Target : Iir) is + begin + case Get_Kind (Target) is + when Iir_Kind_Iterator_Declaration => + null; + when others => + Failed ("Discrete_Range", Target); + end case; + end Check_Kind_For_Discrete_Range; + + function Get_Discrete_Range (Target : Iir) return Iir is + begin + Check_Kind_For_Discrete_Range (Target); + return Get_Field5 (Target); + end Get_Discrete_Range; + + procedure Set_Discrete_Range (Target : Iir; Rng : Iir) is + begin + Check_Kind_For_Discrete_Range (Target); + Set_Field5 (Target, Rng); + end Set_Discrete_Range; + procedure Check_Kind_For_Type_Definition (Target : Iir) is begin case Get_Kind (Target) is @@ -2576,32 +2531,17 @@ package body Iirs is procedure Check_Kind_For_Base_Name (Target : Iir) is begin case Get_Kind (Target) is - when Iir_Kind_Character_Literal - | Iir_Kind_Attribute_Value - | Iir_Kind_Operator_Symbol - | Iir_Kind_Free_Quantity_Declaration - | Iir_Kind_Across_Quantity_Declaration - | Iir_Kind_Through_Quantity_Declaration - | Iir_Kind_Enumeration_Literal - | Iir_Kind_Object_Alias_Declaration - | Iir_Kind_File_Declaration - | Iir_Kind_Guard_Signal_Declaration - | Iir_Kind_Signal_Declaration - | Iir_Kind_Variable_Declaration - | Iir_Kind_Constant_Declaration - | Iir_Kind_Iterator_Declaration - | Iir_Kind_Constant_Interface_Declaration - | Iir_Kind_Variable_Interface_Declaration - | Iir_Kind_Signal_Interface_Declaration - | Iir_Kind_File_Interface_Declaration + when Iir_Kind_Attribute_Value | Iir_Kind_Function_Call | Iir_Kind_Selected_Element | Iir_Kind_Dereference | Iir_Kind_Implicit_Dereference - | Iir_Kind_Simple_Name | Iir_Kind_Slice_Name | Iir_Kind_Indexed_Name + | Iir_Kind_Character_Literal + | Iir_Kind_Simple_Name | Iir_Kind_Selected_Name + | Iir_Kind_Operator_Symbol | Iir_Kind_Selected_By_All_Name | Iir_Kind_Left_Type_Attribute | Iir_Kind_Right_Type_Attribute @@ -2630,7 +2570,8 @@ package body Iirs is | Iir_Kind_Length_Array_Attribute | Iir_Kind_Ascending_Array_Attribute | Iir_Kind_Range_Array_Attribute - | Iir_Kind_Reverse_Range_Array_Attribute => + | Iir_Kind_Reverse_Range_Array_Attribute + | Iir_Kind_Attribute_Name => null; when others => Failed ("Base_Name", Target); @@ -3308,16 +3249,16 @@ package body Iirs is end case; end Check_Kind_For_Type_Declarator; - function Get_Type_Declarator (Target : Iir) return Iir is + function Get_Type_Declarator (Def : Iir) return Iir is begin - Check_Kind_For_Type_Declarator (Target); - return Get_Field3 (Target); + Check_Kind_For_Type_Declarator (Def); + return Get_Field3 (Def); end Get_Type_Declarator; - procedure Set_Type_Declarator (Target : Iir; Decl : Iir) is + procedure Set_Type_Declarator (Def : Iir; Decl : Iir) is begin - Check_Kind_For_Type_Declarator (Target); - Set_Field3 (Target, Decl); + Check_Kind_For_Type_Declarator (Def); + Set_Field3 (Def, Decl); end Set_Type_Declarator; procedure Check_Kind_For_Enumeration_Literal_List (Target : Iir) is @@ -3429,8 +3370,6 @@ package body Iirs is case Get_Kind (Target) is when Iir_Kind_Design_Unit | Iir_Kind_Library_Clause - | Iir_Kind_Character_Literal - | Iir_Kind_Operator_Symbol | Iir_Kind_Record_Element_Constraint | Iir_Kind_Protected_Type_Body | Iir_Kind_Type_Declaration @@ -3500,8 +3439,10 @@ package body Iirs is | Iir_Kind_Case_Statement | Iir_Kind_Procedure_Call_Statement | Iir_Kind_If_Statement + | Iir_Kind_Character_Literal | Iir_Kind_Simple_Name | Iir_Kind_Selected_Name + | Iir_Kind_Operator_Symbol | Iir_Kind_Attribute_Name => null; when others => @@ -4086,28 +4027,28 @@ package body Iirs is Set_Field2 (Decl, Iir_List_To_Iir (List)); end Set_Index_List; - procedure Check_Kind_For_Element_Subtype (Target : Iir) is + procedure Check_Kind_For_Element_Subtype_Indication (Target : Iir) is begin case Get_Kind (Target) is when Iir_Kind_Array_Type_Definition | Iir_Kind_Array_Subtype_Definition => null; when others => - Failed ("Element_Subtype", Target); + Failed ("Element_Subtype_Indication", Target); end case; - end Check_Kind_For_Element_Subtype; + end Check_Kind_For_Element_Subtype_Indication; - function Get_Element_Subtype (Decl : Iir) return Iir is + function Get_Element_Subtype_Indication (Decl : Iir) return Iir is begin - Check_Kind_For_Element_Subtype (Decl); + Check_Kind_For_Element_Subtype_Indication (Decl); return Get_Field1 (Decl); - end Get_Element_Subtype; + end Get_Element_Subtype_Indication; - procedure Set_Element_Subtype (Decl : Iir; Sub_Type : Iir) is + procedure Set_Element_Subtype_Indication (Decl : Iir; Sub_Type : Iir) is begin - Check_Kind_For_Element_Subtype (Decl); + Check_Kind_For_Element_Subtype_Indication (Decl); Set_Field1 (Decl, Sub_Type); - end Set_Element_Subtype; + end Set_Element_Subtype_Indication; procedure Check_Kind_For_Elements_Declaration_List (Target : Iir) is begin @@ -4135,7 +4076,8 @@ package body Iirs is procedure Check_Kind_For_Designated_Type (Target : Iir) is begin case Get_Kind (Target) is - when Iir_Kind_Access_Type_Definition => + when Iir_Kind_Access_Type_Definition + | Iir_Kind_Access_Subtype_Definition => null; when others => Failed ("Designated_Type", Target); @@ -4145,15 +4087,38 @@ package body Iirs is function Get_Designated_Type (Target : Iir) return Iir is begin Check_Kind_For_Designated_Type (Target); - return Get_Field2 (Target); + return Get_Field1 (Target); end Get_Designated_Type; procedure Set_Designated_Type (Target : Iir; Dtype : Iir) is begin Check_Kind_For_Designated_Type (Target); - Set_Field2 (Target, Dtype); + Set_Field1 (Target, Dtype); end Set_Designated_Type; + procedure Check_Kind_For_Designated_Subtype_Indication (Target : Iir) is + begin + case Get_Kind (Target) is + when Iir_Kind_Access_Type_Definition + | Iir_Kind_Access_Subtype_Definition => + null; + when others => + Failed ("Designated_Subtype_Indication", Target); + end case; + end Check_Kind_For_Designated_Subtype_Indication; + + function Get_Designated_Subtype_Indication (Target : Iir) return Iir is + begin + Check_Kind_For_Designated_Subtype_Indication (Target); + return Get_Field5 (Target); + end Get_Designated_Subtype_Indication; + + procedure Set_Designated_Subtype_Indication (Target : Iir; Dtype : Iir) is + begin + Check_Kind_For_Designated_Subtype_Indication (Target); + Set_Field5 (Target, Dtype); + end Set_Designated_Subtype_Indication; + procedure Check_Kind_For_Reference (Target : Iir) is begin case Get_Kind (Target) is @@ -4963,10 +4928,8 @@ package body Iirs is | Iir_Kind_Binding_Indication | Iir_Kind_Package_Instantiation_Declaration | Iir_Kind_Package_Header - | Iir_Kind_Function_Declaration | Iir_Kind_Implicit_Function_Declaration | Iir_Kind_Implicit_Procedure_Declaration - | Iir_Kind_Procedure_Declaration | Iir_Kind_Component_Instantiation_Statement => null; when others => @@ -5010,27 +4973,27 @@ package body Iirs is Set_Field9 (Target, Port); end Set_Port_Map_Aspect_Chain; - procedure Check_Kind_For_Configuration (Target : Iir) is + procedure Check_Kind_For_Configuration_Name (Target : Iir) is begin case Get_Kind (Target) is when Iir_Kind_Entity_Aspect_Configuration => null; when others => - Failed ("Configuration", Target); + Failed ("Configuration_Name", Target); end case; - end Check_Kind_For_Configuration; + end Check_Kind_For_Configuration_Name; - function Get_Configuration (Target : Iir) return Iir is + function Get_Configuration_Name (Target : Iir) return Iir is begin - Check_Kind_For_Configuration (Target); + Check_Kind_For_Configuration_Name (Target); return Get_Field1 (Target); - end Get_Configuration; + end Get_Configuration_Name; - procedure Set_Configuration (Target : Iir; Conf : Iir) is + procedure Set_Configuration_Name (Target : Iir; Conf : Iir) is begin - Check_Kind_For_Configuration (Target); + Check_Kind_For_Configuration_Name (Target); Set_Field1 (Target, Conf); - end Set_Configuration; + end Set_Configuration_Name; procedure Check_Kind_For_Component_Configuration (Target : Iir) is begin @@ -5132,7 +5095,6 @@ package body Iirs is | Iir_Kind_Qualified_Expression | Iir_Kind_Type_Conversion | Iir_Kind_Allocator_By_Expression - | Iir_Kind_Allocator_By_Subtype | Iir_Kind_Concurrent_Selected_Signal_Assignment | Iir_Kind_Variable_Assignment_Statement | Iir_Kind_Return_Statement @@ -5470,27 +5432,27 @@ package body Iirs is Set_Field6 (Target, Clause); end Set_Else_Clause; - procedure Check_Kind_For_Iterator_Scheme (Target : Iir) is + procedure Check_Kind_For_Parameter_Specification (Target : Iir) is begin case Get_Kind (Target) is when Iir_Kind_For_Loop_Statement => null; when others => - Failed ("Iterator_Scheme", Target); + Failed ("Parameter_Specification", Target); end case; - end Check_Kind_For_Iterator_Scheme; + end Check_Kind_For_Parameter_Specification; - function Get_Iterator_Scheme (Target : Iir) return Iir is + function Get_Parameter_Specification (Target : Iir) return Iir is begin - Check_Kind_For_Iterator_Scheme (Target); + Check_Kind_For_Parameter_Specification (Target); return Get_Field1 (Target); - end Get_Iterator_Scheme; + end Get_Parameter_Specification; - procedure Set_Iterator_Scheme (Target : Iir; Iterator : Iir) is + procedure Set_Parameter_Specification (Target : Iir; Param : Iir) is begin - Check_Kind_For_Iterator_Scheme (Target); - Set_Field1 (Target, Iterator); - end Set_Iterator_Scheme; + Check_Kind_For_Parameter_Specification (Target); + Set_Field1 (Target, Param); + end Set_Parameter_Specification; procedure Check_Kind_For_Parent (Target : Iir) is begin @@ -5506,7 +5468,6 @@ package body Iirs is | Iir_Kind_Choice_By_Name | Iir_Kind_Block_Configuration | Iir_Kind_Component_Configuration - | Iir_Kind_Procedure_Call | Iir_Kind_Record_Element_Constraint | Iir_Kind_Attribute_Specification | Iir_Kind_Disconnection_Specification @@ -5597,28 +5558,28 @@ package body Iirs is Set_Field0 (Target, Parent); end Set_Parent; - procedure Check_Kind_For_Loop (Target : Iir) is + procedure Check_Kind_For_Loop_Label (Target : Iir) is begin case Get_Kind (Target) is when Iir_Kind_Next_Statement | Iir_Kind_Exit_Statement => null; when others => - Failed ("Loop", Target); + Failed ("Loop_Label", Target); end case; - end Check_Kind_For_Loop; + end Check_Kind_For_Loop_Label; - function Get_Loop (Target : Iir) return Iir is + function Get_Loop_Label (Target : Iir) return Iir is begin - Check_Kind_For_Loop (Target); + Check_Kind_For_Loop_Label (Target); return Get_Field5 (Target); - end Get_Loop; + end Get_Loop_Label; - procedure Set_Loop (Target : Iir; Stmt : Iir) is + procedure Set_Loop_Label (Target : Iir; Stmt : Iir) is begin - Check_Kind_For_Loop (Target); + Check_Kind_For_Loop_Label (Target); Set_Field5 (Target, Stmt); - end Set_Loop; + end Set_Loop_Label; procedure Check_Kind_For_Component_Name (Target : Iir) is begin @@ -5783,9 +5744,9 @@ package body Iirs is begin case Get_Kind (Target) is when Iir_Kind_Character_Literal - | Iir_Kind_Operator_Symbol | Iir_Kind_Simple_Name | Iir_Kind_Selected_Name + | Iir_Kind_Operator_Symbol | Iir_Kind_Selected_By_All_Name | Iir_Kind_Parenthesis_Name | Iir_Kind_Attribute_Name => @@ -5795,23 +5756,47 @@ package body Iirs is end case; end Check_Kind_For_Named_Entity; - function Get_Named_Entity (Target : Iir) return Iir is + function Get_Named_Entity (Name : Iir) return Iir is begin - Check_Kind_For_Named_Entity (Target); - return Get_Field4 (Target); + Check_Kind_For_Named_Entity (Name); + return Get_Field4 (Name); end Get_Named_Entity; - procedure Set_Named_Entity (Target : Iir; Val : Iir) is + procedure Set_Named_Entity (Name : Iir; Val : Iir) is begin - Check_Kind_For_Named_Entity (Target); - Set_Field4 (Target, Val); + Check_Kind_For_Named_Entity (Name); + Set_Field4 (Name, Val); end Set_Named_Entity; + procedure Check_Kind_For_Alias_Declaration (Target : Iir) is + begin + case Get_Kind (Target) is + when Iir_Kind_Character_Literal + | Iir_Kind_Simple_Name + | Iir_Kind_Selected_Name + | Iir_Kind_Operator_Symbol => + null; + when others => + Failed ("Alias_Declaration", Target); + end case; + end Check_Kind_For_Alias_Declaration; + + function Get_Alias_Declaration (Name : Iir) return Iir is + begin + Check_Kind_For_Alias_Declaration (Name); + return Get_Field2 (Name); + end Get_Alias_Declaration; + + procedure Set_Alias_Declaration (Name : Iir; Val : Iir) is + begin + Check_Kind_For_Alias_Declaration (Name); + Set_Field2 (Name, Val); + end Set_Alias_Declaration; + procedure Check_Kind_For_Expr_Staticness (Target : Iir) is begin case Get_Kind (Target) is when Iir_Kind_Error - | Iir_Kind_Character_Literal | Iir_Kind_Integer_Literal | Iir_Kind_Floating_Point_Literal | Iir_Kind_Null_Literal @@ -5892,9 +5877,10 @@ package body Iirs is | Iir_Kind_Selected_Element | Iir_Kind_Dereference | Iir_Kind_Implicit_Dereference - | Iir_Kind_Simple_Name | Iir_Kind_Slice_Name | Iir_Kind_Indexed_Name + | Iir_Kind_Character_Literal + | Iir_Kind_Simple_Name | Iir_Kind_Selected_Name | Iir_Kind_Selected_By_All_Name | Iir_Kind_Left_Type_Attribute @@ -6184,6 +6170,7 @@ package body Iirs is begin case Get_Kind (Target) is when Iir_Kind_Attribute_Value + | Iir_Kind_Unit_Declaration | Iir_Kind_Free_Quantity_Declaration | Iir_Kind_Across_Quantity_Declaration | Iir_Kind_Through_Quantity_Declaration @@ -6205,6 +6192,9 @@ package body Iirs is | Iir_Kind_Implicit_Dereference | Iir_Kind_Slice_Name | Iir_Kind_Indexed_Name + | Iir_Kind_Character_Literal + | Iir_Kind_Simple_Name + | Iir_Kind_Selected_Name | Iir_Kind_Left_Type_Attribute | Iir_Kind_Right_Type_Attribute | Iir_Kind_High_Type_Attribute @@ -6239,7 +6229,8 @@ package body Iirs is | Iir_Kind_Length_Array_Attribute | Iir_Kind_Ascending_Array_Attribute | Iir_Kind_Range_Array_Attribute - | Iir_Kind_Reverse_Range_Array_Attribute => + | Iir_Kind_Reverse_Range_Array_Attribute + | Iir_Kind_Attribute_Name => null; when others => Failed ("Name_Staticness", Target); @@ -6262,6 +6253,8 @@ package body Iirs is begin case Get_Kind (Target) is when Iir_Kind_Signature + | Iir_Kind_Procedure_Call + | Iir_Kind_Function_Call | Iir_Kind_Selected_Element | Iir_Kind_Dereference | Iir_Kind_Implicit_Dereference @@ -6893,18 +6886,40 @@ package body Iirs is Set_Field4 (Target, Object); end Set_Method_Object; - procedure Check_Kind_For_Type_Mark (Target : Iir) is + procedure Check_Kind_For_Subtype_Type_Mark (Target : Iir) is begin case Get_Kind (Target) is - when Iir_Kind_File_Type_Definition - | Iir_Kind_Array_Subtype_Definition + when Iir_Kind_Array_Subtype_Definition | Iir_Kind_Record_Subtype_Definition | Iir_Kind_Access_Subtype_Definition | Iir_Kind_Physical_Subtype_Definition | Iir_Kind_Floating_Subtype_Definition | Iir_Kind_Integer_Subtype_Definition | Iir_Kind_Enumeration_Subtype_Definition - | Iir_Kind_Subtype_Definition + | Iir_Kind_Subtype_Definition => + null; + when others => + Failed ("Subtype_Type_Mark", Target); + end case; + end Check_Kind_For_Subtype_Type_Mark; + + function Get_Subtype_Type_Mark (Target : Iir) return Iir is + begin + Check_Kind_For_Subtype_Type_Mark (Target); + return Get_Field2 (Target); + end Get_Subtype_Type_Mark; + + procedure Set_Subtype_Type_Mark (Target : Iir; Mark : Iir) is + begin + Check_Kind_For_Subtype_Type_Mark (Target); + Set_Field2 (Target, Mark); + end Set_Subtype_Type_Mark; + + procedure Check_Kind_For_Type_Mark (Target : Iir) is + begin + case Get_Kind (Target) is + when Iir_Kind_Disconnection_Specification + | Iir_Kind_Attribute_Declaration | Iir_Kind_Qualified_Expression | Iir_Kind_Type_Conversion => null; @@ -6916,15 +6931,60 @@ package body Iirs is function Get_Type_Mark (Target : Iir) return Iir is begin Check_Kind_For_Type_Mark (Target); - return Get_Field2 (Target); + return Get_Field4 (Target); end Get_Type_Mark; procedure Set_Type_Mark (Target : Iir; Mark : Iir) is begin Check_Kind_For_Type_Mark (Target); - Set_Field2 (Target, Mark); + Set_Field4 (Target, Mark); end Set_Type_Mark; + procedure Check_Kind_For_File_Type_Mark (Target : Iir) is + begin + case Get_Kind (Target) is + when Iir_Kind_File_Type_Definition => + null; + when others => + Failed ("File_Type_Mark", Target); + end case; + end Check_Kind_For_File_Type_Mark; + + function Get_File_Type_Mark (Target : Iir) return Iir is + begin + Check_Kind_For_File_Type_Mark (Target); + return Get_Field2 (Target); + end Get_File_Type_Mark; + + procedure Set_File_Type_Mark (Target : Iir; Mark : Iir) is + begin + Check_Kind_For_File_Type_Mark (Target); + Set_Field2 (Target, Mark); + end Set_File_Type_Mark; + + procedure Check_Kind_For_Return_Type_Mark (Target : Iir) is + begin + case Get_Kind (Target) is + when Iir_Kind_Function_Declaration + | Iir_Kind_Procedure_Declaration => + null; + when others => + Failed ("Return_Type_Mark", Target); + end case; + end Check_Kind_For_Return_Type_Mark; + + function Get_Return_Type_Mark (Target : Iir) return Iir is + begin + Check_Kind_For_Return_Type_Mark (Target); + return Get_Field8 (Target); + end Get_Return_Type_Mark; + + procedure Set_Return_Type_Mark (Target : Iir; Mark : Iir) is + begin + Check_Kind_For_Return_Type_Mark (Target); + Set_Field8 (Target, Mark); + end Set_Return_Type_Mark; + procedure Check_Kind_For_Lexical_Layout (Target : Iir) is begin case Get_Kind (Target) is @@ -7099,28 +7159,49 @@ package body Iirs is Set_Flag1 (Decl, Flag); end Set_Implicit_Alias_Flag; - procedure Check_Kind_For_Signature (Target : Iir) is + procedure Check_Kind_For_Alias_Signature (Target : Iir) is begin case Get_Kind (Target) is - when Iir_Kind_Non_Object_Alias_Declaration - | Iir_Kind_Attribute_Name => + when Iir_Kind_Non_Object_Alias_Declaration => null; when others => - Failed ("Signature", Target); + Failed ("Alias_Signature", Target); end case; - end Check_Kind_For_Signature; + end Check_Kind_For_Alias_Signature; - function Get_Signature (Target : Iir) return Iir is + function Get_Alias_Signature (Alias : Iir) return Iir is begin - Check_Kind_For_Signature (Target); - return Get_Field5 (Target); - end Get_Signature; + Check_Kind_For_Alias_Signature (Alias); + return Get_Field5 (Alias); + end Get_Alias_Signature; - procedure Set_Signature (Target : Iir; Value : Iir) is + procedure Set_Alias_Signature (Alias : Iir; Signature : Iir) is begin - Check_Kind_For_Signature (Target); - Set_Field5 (Target, Value); - end Set_Signature; + Check_Kind_For_Alias_Signature (Alias); + Set_Field5 (Alias, Signature); + end Set_Alias_Signature; + + procedure Check_Kind_For_Attribute_Signature (Target : Iir) is + begin + case Get_Kind (Target) is + when Iir_Kind_Attribute_Name => + null; + when others => + Failed ("Attribute_Signature", Target); + end case; + end Check_Kind_For_Attribute_Signature; + + function Get_Attribute_Signature (Attr : Iir) return Iir is + begin + Check_Kind_For_Attribute_Signature (Attr); + return Get_Field2 (Attr); + end Get_Attribute_Signature; + + procedure Set_Attribute_Signature (Attr : Iir; Signature : Iir) is + begin + Check_Kind_For_Attribute_Signature (Attr); + Set_Field2 (Attr, Signature); + end Set_Attribute_Signature; procedure Check_Kind_For_Overload_List (Target : Iir) is begin @@ -7409,10 +7490,34 @@ package body Iirs is Set_Flag9 (Decl, Flag); end Set_End_Has_Identifier; + procedure Check_Kind_For_End_Has_Postponed (Target : Iir) is + begin + case Get_Kind (Target) is + when Iir_Kind_Sensitized_Process_Statement + | Iir_Kind_Process_Statement => + null; + when others => + Failed ("End_Has_Postponed", Target); + end case; + end Check_Kind_For_End_Has_Postponed; + + function Get_End_Has_Postponed (Decl : Iir) return Boolean is + begin + Check_Kind_For_End_Has_Postponed (Decl); + return Get_Flag10 (Decl); + end Get_End_Has_Postponed; + + procedure Set_End_Has_Postponed (Decl : Iir; Flag : Boolean) is + begin + Check_Kind_For_End_Has_Postponed (Decl); + Set_Flag10 (Decl, Flag); + end Set_End_Has_Postponed; + procedure Check_Kind_For_Has_Begin (Target : Iir) is begin case Get_Kind (Target) is - when Iir_Kind_Entity_Declaration => + when Iir_Kind_Entity_Declaration + | Iir_Kind_Generate_Statement => null; when others => Failed ("Has_Begin", Target); @@ -7431,6 +7536,125 @@ package body Iirs is Set_Flag10 (Decl, Flag); end Set_Has_Begin; + procedure Check_Kind_For_Has_Is (Target : Iir) is + begin + case Get_Kind (Target) is + when Iir_Kind_Component_Declaration + | Iir_Kind_Sensitized_Process_Statement + | Iir_Kind_Process_Statement => + null; + when others => + Failed ("Has_Is", Target); + end case; + end Check_Kind_For_Has_Is; + + function Get_Has_Is (Decl : Iir) return Boolean is + begin + Check_Kind_For_Has_Is (Decl); + return Get_Flag7 (Decl); + end Get_Has_Is; + + procedure Set_Has_Is (Decl : Iir; Flag : Boolean) is + begin + Check_Kind_For_Has_Is (Decl); + Set_Flag7 (Decl, Flag); + end Set_Has_Is; + + procedure Check_Kind_For_Has_Pure (Target : Iir) is + begin + case Get_Kind (Target) is + when Iir_Kind_Function_Declaration => + null; + when others => + Failed ("Has_Pure", Target); + end case; + end Check_Kind_For_Has_Pure; + + function Get_Has_Pure (Decl : Iir) return Boolean is + begin + Check_Kind_For_Has_Pure (Decl); + return Get_Flag8 (Decl); + end Get_Has_Pure; + + procedure Set_Has_Pure (Decl : Iir; Flag : Boolean) is + begin + Check_Kind_For_Has_Pure (Decl); + Set_Flag8 (Decl, Flag); + end Set_Has_Pure; + + procedure Check_Kind_For_Has_Body (Target : Iir) is + begin + case Get_Kind (Target) is + when Iir_Kind_Function_Declaration + | Iir_Kind_Procedure_Declaration => + null; + when others => + Failed ("Has_Body", Target); + end case; + end Check_Kind_For_Has_Body; + + function Get_Has_Body (Decl : Iir) return Boolean is + begin + Check_Kind_For_Has_Body (Decl); + return Get_Flag9 (Decl); + end Get_Has_Body; + + procedure Set_Has_Body (Decl : Iir; Flag : Boolean) is + begin + Check_Kind_For_Has_Body (Decl); + Set_Flag9 (Decl, Flag); + end Set_Has_Body; + + procedure Check_Kind_For_Has_Identifier_List (Target : Iir) is + begin + case Get_Kind (Target) is + when Iir_Kind_Library_Clause + | Iir_Kind_Element_Declaration + | Iir_Kind_File_Declaration + | Iir_Kind_Signal_Declaration + | Iir_Kind_Variable_Declaration + | Iir_Kind_Constant_Declaration + | Iir_Kind_Iterator_Declaration => + null; + when others => + Failed ("Has_Identifier_List", Target); + end case; + end Check_Kind_For_Has_Identifier_List; + + function Get_Has_Identifier_List (Decl : Iir) return Boolean is + begin + Check_Kind_For_Has_Identifier_List (Decl); + return Get_Flag7 (Decl); + end Get_Has_Identifier_List; + + procedure Set_Has_Identifier_List (Decl : Iir; Flag : Boolean) is + begin + Check_Kind_For_Has_Identifier_List (Decl); + Set_Flag7 (Decl, Flag); + end Set_Has_Identifier_List; + + procedure Check_Kind_For_Has_Mode (Target : Iir) is + begin + case Get_Kind (Target) is + when Iir_Kind_File_Declaration => + null; + when others => + Failed ("Has_Mode", Target); + end case; + end Check_Kind_For_Has_Mode; + + function Get_Has_Mode (Decl : Iir) return Boolean is + begin + Check_Kind_For_Has_Mode (Decl); + return Get_Flag8 (Decl); + end Get_Has_Mode; + + procedure Set_Has_Mode (Decl : Iir; Flag : Boolean) is + begin + Check_Kind_For_Has_Mode (Decl); + Set_Flag8 (Decl, Flag); + end Set_Has_Mode; + procedure Check_Kind_For_Psl_Property (Target : Iir) is begin case Get_Kind (Target) is diff --git a/iirs.adb.in b/iirs.adb.in index 6ed1c4dfb..0ced4673f 100644 --- a/iirs.adb.in +++ b/iirs.adb.in @@ -114,16 +114,6 @@ package body Iirs is end case; end Iir_Predefined_Shortcut_P; - function Create_Proxy (Proxy: Iir) return Iir_Proxy is - Res : Iir_Proxy; - begin - Res := Create_Iir (Iir_Kind_Proxy); - Set_Proxy (Res, Proxy); - return Res; - end Create_Proxy; - - -- - function Create_Iir_Error return Iir is Res : Iir; @@ -148,74 +138,6 @@ package body Iirs is return Iir_Kind'Val (Get_Nkind (An_Iir)); end Get_Kind; --- function Clone_Iir (Src : Iir; New_Kind : Iir_Kind) return Iir --- is --- Res : Iir; --- begin --- Res := new Iir_Node (New_Kind); --- Res.Flag1 := Src.Flag1; --- Res.Flag2 := Src.Flag2; --- Res.Flag3 := Src.Flag3; --- Res.Flag4 := Src.Flag4; --- Res.Flag5 := Src.Flag5; --- Res.Flag6 := Src.Flag6; --- Res.Flag7 := Src.Flag7; --- Res.Flag8 := Src.Flag8; --- Res.State1 := Src.State1; --- Res.State2 := Src.State2; --- Res.State3 := Src.State3; --- Res.Staticness1 := Src.Staticness1; --- Res.Staticness2 := Src.Staticness2; --- Res.Odigit1 := Src.Odigit1; --- Res.Odigit2 := Src.Odigit2; --- Res.Location := Src.Location; --- Res.Back_End_Info := Src.Back_End_Info; --- Res.Identifier := Src.Identifier; --- Res.Field1 := Src.Field1; --- Res.Field2 := Src.Field2; --- Res.Field3 := Src.Field3; --- Res.Field4 := Src.Field4; --- Res.Field5 := Src.Field5; --- Res.Nbr2 := Src.Nbr2; --- Res.Nbr3 := Src.Nbr3; - --- Src.Identifier := Null_Identifier; --- Src.Field1 := null; --- Src.Field2 := null; --- Src.Field3 := null; --- Src.Field4 := null; --- Src.Field5 := null; --- return Res; --- end Clone_Iir; - - - ----------------- - -- design file -- - ----------------- - - -- Iir_Design_File - --- type Int_Access_Type is new Integer; --- for Int_Access_Type'Size use System.Word_Size; --Iir_Identifier_Acc'Size; - - -- Safe conversions. --- function Iir_To_Int_Access_Type is --- new Ada.Unchecked_Conversion (Source => Iir, --- Target => Int_Access_Type); --- function Int_Access_Type_To_Iir is --- new Ada.Unchecked_Conversion (Source => Int_Access_Type, --- Target => Iir); - --- function To_Iir (V : Integer) return Iir is --- begin --- return Int_Access_Type_To_Iir (Int_Access_Type (V)); --- end To_Iir; - --- function To_Integer (N : Iir) return Integer is --- begin --- return Integer (Iir_To_Int_Access_Type (N)); --- end To_Integer; - procedure Set_Pos_Line_Off (Design_Unit: Iir_Design_Unit; Pos : Source_Ptr; Line, Off: Natural) is begin @@ -235,6 +157,7 @@ package body Iirs is ----------- -- Lists -- ----------- + -- Layout of lists: -- A list is stored into an IIR. -- There are two bounds for a list: @@ -22,47 +22,47 @@ with Nodes; with Lists; package Iirs is - -- This package defines the semantic tree and functions to handle it. - -- The tree is roughly based on IIR (Internal Intermediate Representation), - -- [AIRE/CE Advanced Intermediate Representation with Extensibility, - -- Common Environment. http://www.vhdl.org/aire/index.html ] - -- but oriented object features are not used, and sometimes, functions - -- or fields have changed. - - -- Note: this tree is also used during syntaxic analysis, but with - -- a little bit different meanings for the fields. - -- The parser (parse package) build the tree. - -- The semantic pass (sem, sem_expr, sem_name) transforms it into a - -- semantic tree. - - -- Documentation: - -- Only the semantic aspect is to be fully documented. - -- The syntaxic aspect is only used between parse and sem. - - -- Each node of the tree is a record of type iir. The record has only - -- one discriminent, which contains the kind of the node. There is - -- currenlty no variant (but this can change, this is not public). - - -- The root of a semantic tree is a library_declaration. - -- All the library_declarations are kept in a private list, held by - -- package libraries. - -- Exemple of a tree: + -- This package defines the semantic tree and functions to handle it. + -- The tree is roughly based on IIR (Internal Intermediate Representation), + -- [AIRE/CE Advanced Intermediate Representation with Extensibility, + -- Common Environment. http://www.vhdl.org/aire/index.html ] + -- but oriented object features are not used, and sometimes, functions + -- or fields have changed. + + -- Note: this tree is also used during syntaxic analysis, but with + -- a little bit different meanings for the fields. + -- The parser (parse package) build the tree. + -- The semantic pass (sem, sem_expr, sem_name) transforms it into a + -- semantic tree. + + -- Documentation: + -- Only the semantic aspect is to be fully documented. + -- The syntaxic aspect is only used between parse and sem. + + -- Each node of the tree is a record of type iir. The record has only + -- one discriminent, which contains the kind of the node. There is + -- currenlty no variant (but this can change, this is not public). + + -- The root of a semantic tree is a library_declaration. + -- All the library_declarations are kept in a private list, held by + -- package libraries. + -- Exemple of a tree: -- library_declaration -- +-- design_file -- +-- design_unit -- | +-- entity_declaration -- +-- design_unit -- +-- architecture_body - -- ... + -- ... - -- Since the tree can represent all the libraries and their contents, it - -- is not always loaded into memory. - -- When a library is loaded, only library_declaration, design_file, - -- design_unit and library_unit nodes are created. When a design_unit is - -- really loaded, the design_unit node is not replaced but modified (ie, - -- access to this node are still valid). + -- Since the tree can represent all the libraries and their contents, it + -- is not always loaded into memory. + -- When a library is loaded, only library_declaration, design_file, + -- design_unit and library_unit nodes are created. When a design_unit is + -- really loaded, the design_unit node is not replaced but modified (ie, + -- access to this node are still valid). - -- To add a new kind of node: + -- To add a new kind of node: -- the name should be of the form iir_kind_NAME -- add iir_kind_NAME in the definition of type iir_kind_type -- document the node below: grammar, methods. @@ -75,38 +75,39 @@ package Iirs is -- General methods (can be used on all nodes): -- ------------------------------------------------- - -- Create a node of kind KIND. - -- function Create_Iir (Kind: Iir_Kind) return Iir; + -- Create a node of kind KIND. + -- function Create_Iir (Kind: Iir_Kind) return Iir; -- - -- Deallocate a node. Deallocate fields that where allocated by create_iir. + -- Deallocate a node. Deallocate fields that where allocated by + -- create_iir. -- procedure Free_Iir (Target: in out Iir); -- - -- Get the kind of the iir. - -- See below for the (public) list of kinds. + -- Get the kind of the iir. + -- See below for the (public) list of kinds. -- function Get_Kind (An_Iir: Iir) return Iir_Kind; - -- Get the location of the node: ie the current position in the source - -- file when the node was created. This is a little bit fuzzy. + -- Get the location of the node: ie the current position in the source + -- file when the node was created. This is a little bit fuzzy. -- -- procedure Set_Location (Target: in out Iir; Location: Location_Type); -- function Get_Location (Target: in out Iir) return Location_Type; -- - -- Copy a location from a node to another one. + -- Copy a location from a node to another one. -- procedure Location_Copy (Target: in out Iir; Src: in Iir); - -- The next line marks the start of the node description. + -- The next line marks the start of the node description. -- Start of Iir_Kind. - ------------------------------------------------- - -- A set of methods are associed with a kind. -- - ------------------------------------------------- + -------------------------------------------------- + -- A set of methods are associed with a kind. -- + -------------------------------------------------- -- Iir_Kind_Design_File (Medium) - -- LRM93 11 - -- DESIGN_FILE ::= DESIGN_UNIT { DESIGN_UNIT} + -- LRM93 11 + -- design_file ::= design_unit { design_unit } -- - -- The library containing this design file. + -- The library containing this design file. -- Get/Set_Library (Field0) -- Get/Set_Parent (Alias Field0) -- @@ -118,117 +119,116 @@ package Iirs is -- -- Get/Set_File_Time_Stamp (Field4) -- - -- Get the chain of unit contained in the file. This is a simply linked - -- chain, but the tail is kept to speed-up appending operation. + -- Get the chain of unit contained in the file. This is a simply linked + -- chain, but the tail is kept to speed-up appending operation. -- Get/Set_First_Design_Unit (Field5) -- -- Get/Set_Last_Design_Unit (Field6) -- - -- Identifier for the design file file name and dirname. + -- Identifier for the design file file name and dirname. -- Get/Set_Design_File_Filename (Field12) -- Get/Set_Design_File_Directory (Field11) -- - -- Flag used during elaboration. Set when the file was already seen. + -- Flag used during elaboration. Set when the file was already seen. -- Get/Set_Elab_Flag (Flag3) -- Iir_Kind_Design_Unit (Medium) - -- LRM93 11 - -- DESIGN_UNIT ::= CONTEXT_CLAUSE LIBRARY_UNIT + -- LRM93 11 + -- design_unit ::= context_clause library_unit -- - -- The design_file containing this design unit. + -- The design_file containing this design unit. -- Get/Set_Design_File (Field0) -- Get/Set_Parent (Alias Field0) -- - -- Get the chain of context clause. + -- Get the chain of context clause. -- Get_Context_Items (Field1) -- -- Get/Set_Chain (Field2) -- -- Get/Set_Identifier (Field3) -- - -- Get/Set the library unit, which can be an entity, an architecture, - -- a package, a package body or a configuration. + -- Get/Set the library unit, which can be an entity, an architecture, + -- a package, a package body or a configuration. -- Get/Set_Library_Unit (Field5) -- -- Get/Set_End_Location (Field6) -- - -- Collision chain for units. + -- Collision chain for units. -- Get/Set_Hash_Chain (Field7) -- - -- Get the list of design units that must be analysed before this unit. - -- See LRM93 11.4 for the rules defining the order of analysis. + -- Get the list of design units that must be analysed before this unit. + -- See LRM93 11.4 for the rules defining the order of analysis. -- Get/Set_Dependence_List (Field8) -- - -- FIXME: this field can be put in the library_unit, since it is only used - -- when the units have been analyzed. + -- FIXME: this field can be put in the library_unit, since it is only used + -- when the units have been analyzed. -- Get/Set_Analysis_Checks_List (Field9) -- - -- This is a symbolic date, only used as a order of analysis of design - -- units. + -- This is a symbolic date, only used as a order of analysis of design + -- units. -- Get/Set_Date (Field10) -- - -- Set the line and the offset in the line, only for the library manager. - -- This is valid until the file is really loaded in memory. On loading, - -- location will contain all this informations. - -- Get/Set_Pos_Line_Off (Field1,Field11,Field12) + -- Set the line and the offset in the line, only for the library manager. + -- This is valid until the file is really loaded in memory. On loading, + -- location will contain all this informations. + -- Get/Set_Pos_Line_Off (Field1,Field11,Field12) -- - -- Get/Set the date state, which indicates whether this design unit is in - -- memory or not. + -- Get/Set the date state, which indicates whether this design unit is in + -- memory or not. -- Get/Set_Date_State (State1) -- - -- Flag used during elaboration. Set when the file was already seen. + -- Flag used during elaboration. Set when the file was already seen. -- Get/Set_Elab_Flag (Flag3) -- Iir_Kind_Library_Clause (Short) - -- Note: a library_clause node is created for every logical_name. - -- As a consequence, the scope of the library starts after the logical_name - -- and not after the library_clause. However, since an identifier - -- can only be used as a logical_name, and since the second occurence has - -- no effect, this is correct. -- - -- Get/Set_Parent (Field0) + -- LRM08 13.2 Design libraries -- - -- Get/Set_Identifier (Field3) + -- library_clause ::= LIBRARY logical_name_list ; -- - -- Get/Set_Library_Declaration (Field1) + -- logical_name_list ::= logical_name { , logical_name } -- - -- Get/Set_Chain (Field2) - - -------------- - -- Literals -- - -------------- - - -- Iir_Kind_Character_Literal (Short) + -- logical_name ::= identifier -- - -- Get/Set_Type (Field1) + -- Note: a library_clause node is created for every logical_name. + -- As a consequence, the scope of the library starts after the logical_name + -- and not after the library_clause. However, since an identifier + -- can only be used as a logical_name, and since the second occurence has + -- no effect, this is correct. + -- + -- Get/Set_Parent (Field0) -- -- Get/Set_Identifier (Field3) -- - -- Get/Set_Named_Entity (Field4) + -- Get/Set_Library_Declaration (Field1) -- - -- Get/Set_Base_Name (Field5) + -- Get/Set_Chain (Field2) -- - -- Get/Set_Expr_Staticness (State1) + -- Get/Set_Has_Identifier_List (Flag7) + + --------------- + -- Literals -- + --------------- -- Iir_Kind_String_Literal (Short) -- Iir_Kind_Bit_String_Literal (Medium) -- -- Get/Set_Type (Field1) -- - -- Used for computed literals. Literal_Origin contains the expression whose - -- value was computed during analysis and replaces the expression. + -- Used for computed literals. Literal_Origin contains the expression + -- whose value was computed during analysis and replaces the expression. -- Get/Set_Literal_Origin (Field2) -- -- Get/Set_String_Id (Field3) -- - -- As bit-strings are expanded to '0'/'1' strings, this is the number of - -- characters. + -- As bit-strings are expanded to '0'/'1' strings, this is the number of + -- characters. -- Get/Set_String_Length (Field0) -- - -- For bit string only: - -- Enumeration literal which correspond to '0' and '1'. - -- This cannot be defined only in the enumeration type definition, due to - -- possible aliases. + -- For bit string only: + -- Enumeration literal which correspond to '0' and '1'. + -- This cannot be defined only in the enumeration type definition, due to + -- possible aliases. -- Only for Iir_Kind_Bit_String_Literal: -- Get/Set_Bit_String_0 (Field4) -- Only for Iir_Kind_Bit_String_Literal: @@ -240,9 +240,10 @@ package Iirs is -- Get/Set_Expr_Staticness (State1) -- Iir_Kind_Integer_Literal (Int) + -- -- Get/Set_Type (Field1) -- - -- Get/Set the value of the integer. + -- Get/Set the value of the integer. -- Get/Set_Value (Int64) -- -- Get/Set_Literal_Origin (Field2) @@ -250,9 +251,10 @@ package Iirs is -- Get/Set_Expr_Staticness (State1) -- Iir_Kind_Floating_Point_Literal (Fp) + -- -- Get/Set_Type (Field1) -- - -- Get/Set the value of the literal. + -- The value of the literal. -- Get/Set_Fp_Value (Fp64) -- -- Get/Set_Literal_Origin (Field2) @@ -260,7 +262,7 @@ package Iirs is -- Get/Set_Expr_Staticness (State1) -- Iir_Kind_Null_Literal (Short) - -- The null literal, which can be a disconnection or a null access. + -- The null literal, which can be a disconnection or a null access. -- -- Get/Set_Type (Field1) -- @@ -273,23 +275,23 @@ package Iirs is -- -- Get/Set_Literal_Origin (Field2) -- - -- Get/Set the physical unit of the literal. + -- The physical unit of the literal. -- Get/Set_Unit_Name (Field3) -- - -- Must be set to locally except for time literal, which is globally. + -- Must be set to locally except for time literal, which is globally. -- Get/Set_Expr_Staticness (State1) -- -- Only for Iir_Kind_Physical_Int_Literal: - -- The multiplicand. + -- The multiplicand. -- Get/Set_Value (Int64) -- -- Only for Iir_Kind_Physical_Fp_Literal: - -- The multiplicand. + -- The multiplicand. -- Get/Set_Fp_Value (Fp64) -- Iir_Kind_Simple_Aggregate (Short) - -- This node can only be generated by evaluation: it is an unidimentional - -- positional aggregate. + -- This node can only be generated by evaluation: it is an unidimentional + -- positional aggregate. -- -- Get/Set_Type (Field1) -- @@ -297,12 +299,12 @@ package Iirs is -- -- Get/Set_Expr_Staticness (State1) -- - -- List of elements + -- List of elements -- Get/Set_Simple_Aggregate_List (Field3) -- Iir_Kind_Overflow_Literal (Short) - -- This node can only be generated by evaluation to represent an error: out - -- of range, division by zero... + -- This node can only be generated by evaluation to represent an error: out + -- of range, division by zero... -- -- Get/Set_Type (Field1) -- @@ -310,15 +312,15 @@ package Iirs is -- -- Get/Set_Expr_Staticness (State1) - ------------ - -- Tuples -- - ------------ + ------------- + -- Tuples -- + ------------- -- Iir_Kind_Association_Element_By_Expression (Short) -- Iir_Kind_Association_Element_Open (Short) -- Iir_Kind_Association_Element_By_Individual (Short) - -- These are used for association element of an association list with - -- an interface (ie subprogram call, port map, generic map). + -- These are used for association element of an association list with + -- an interface (ie subprogram call, port map, generic map). -- -- Get/Set_Formal (Field1) -- @@ -333,16 +335,16 @@ package Iirs is -- Only for Iir_Kind_Association_Element_By_Individual: -- Get/Set_Individual_Association_Chain (Field4) -- - -- A function call or a type conversion for the association. - -- FIXME: should be a name ? + -- A function call or a type conversion for the association. + -- FIXME: should be a name ? -- Only for Iir_Kind_Association_Element_By_Expression: -- Get/Set_In_Conversion (Field4) -- -- Only for Iir_Kind_Association_Element_By_Expression: -- Get/Set_Out_Conversion (Field5) -- - -- Get/Set the whole association flag (true if the formal is associated in - -- whole and not individually, see LRM93 4.3.2.2) + -- Get/Set the whole association flag (true if the formal is associated in + -- whole and not individually, see LRM93 4.3.2.2) -- Get/Set_Whole_Association_Flag (Flag1) -- -- Get/Set_Collapse_Signal_Flag (Flag2) @@ -350,18 +352,6 @@ package Iirs is -- Only for Iir_Kind_Association_Element_Open: -- Get/Set_Artificial_Flag (Flag3) - -- Iir_Kind_Proxy (Short) - -- A proxy is used to avoid duplication of a node. - -- Ex: instead of copying a default value of an insterface in the subprogram - -- call, a proxy is used. The default value can't be so easily aliased - -- due to annotation. - -- - -- Create a proxy for PROXY. - -- function Create_Proxy (Proxy: Iir) return Iir_Proxy; - -- - -- Get/Set the value of the proxy. - -- Get/Set_Proxy (Field1) - -- Iir_Kind_Waveform_Element (Short) -- -- Get/Set_We_Value (Field1) @@ -383,32 +373,31 @@ package Iirs is -- Iir_Kind_Choice_By_Range (Short) -- Iir_Kind_Choice_By_Name (Short) -- Iir_Kind_Choice_By_Expression (Short) - -- (Iir_Kinds_Choice) + -- (Iir_Kinds_Choice) -- -- Get/Set_Parent (Field0) -- - -- These are elements of an choice chain, which is used for - -- case_statement, concurrent_select_signal_assignment, aggregates. + -- These are elements of an choice chain, which is used for + -- case_statement, concurrent_select_signal_assignment, aggregates. -- - -- Get/Set what is associated with the choice. This can be: - -- * a waveform_chain for a concurrent_select_signal_assignment, - -- * an expression for an aggregate, - -- * a sequential statement list for a case_statement. - -- For a list of choices, only the first one is associated, the following - -- associations have the same_alternative_flag set. + -- Get/Set what is associated with the choice. This can be: + -- * a waveform_chain for a concurrent_select_signal_assignment, + -- * an expression for an aggregate, + -- * a sequential statement list for a case_statement. + -- For a list of choices, only the first one is associated, the following + -- associations have the same_alternative_flag set. -- Get/Set_Associated (Field1) -- -- Get/Set_Chain (Field2) -- -- Only for Iir_Kind_Choice_By_Name: - -- Get/Set the name. -- Get/Set_Name (Field4) -- -- Only for Iir_Kind_Choice_By_Expression: -- Get/Set_Expression (Field5) -- -- Only for Iir_Kind_Choice_By_Range: - -- Get/Set the range. + -- Get/Set the range. -- Get/Set_Expression (Field5) -- -- Get/Set_Same_Alternative_Flag (Flag1) @@ -419,21 +408,17 @@ package Iirs is -- Iir_Kind_Entity_Aspect_Entity (Short) -- - -- Parse: a name - -- Sem: a design unit - -- Get/Set_Entity (Field2) + -- Get/Set_Entity_Name (Field2) -- - -- parse: a simple name. - -- sem: an architecture declaration or NULL_IIR. + -- parse: a simple name. + -- sem: an architecture declaration or NULL_IIR. -- Get/Set_Architecture (Field3) -- Iir_Kind_Entity_Aspect_Open (Short) -- Iir_Kind_Entity_Aspect_Configuration (Short) -- - -- Parse: a name - -- Sem: a design unit - -- Get/Set_Configuration (Field1) + -- Get/Set_Configuration_Name (Field1) -- Iir_Kind_Block_Configuration (Short) -- @@ -445,22 +430,22 @@ package Iirs is -- -- Get/Set_Configuration_Item_Chain (Field3) -- - -- Note: for default block configurations of iterative generate statement, - -- the block specification is a selected_name, whose identifier is others. + -- Note: for default block configurations of iterative generate statement, + -- the block specification is a selected_name, whose identifier is others. -- Get/Set_Block_Specification (Field5) -- - -- Single linked list of block configuration that apply to the same - -- for scheme generate block. + -- Single linked list of block configuration that apply to the same + -- for scheme generate block. -- Get/Set_Prev_Block_Configuration (Field4) -- Iir_Kind_Binding_Indication (Medium) -- -- Get/Set_Default_Entity_Aspect (Field1) -- - -- The entity aspect. - -- It is a iir_kind_entity_aspect_entity, iir_kind_entity_aspect_open or - -- iir_kind_entity_aspect_configuration. This may be transformed into a - -- declaration by semantic. + -- The entity aspect. + -- It is a iir_kind_entity_aspect_entity, iir_kind_entity_aspect_open or + -- iir_kind_entity_aspect_configuration. This may be transformed into a + -- declaration by semantic. -- Get/Set_Entity_Aspect (Field3) -- -- Get/Set_Default_Generic_Map_Aspect_Chain (Field6) @@ -474,13 +459,37 @@ package Iirs is -- Iir_Kind_Component_Configuration (Short) -- Iir_Kind_Configuration_Specification (Short) -- - -- The declaration containing this type declaration. + -- LRM08 7.3 Configuration specification + -- + -- configuration_specification ::= + -- simple_configuration_specification + -- | compound_configuration_specification + -- + -- simple_configuration_specification ::= + -- FOR component_specification binding_indication ; + -- [ END FOR ; ] + -- + -- compound_configuration_specification ::= + -- FOR component_specification binding_indication ; + -- verification_unit_binding_indication ; + -- { verification_unit_binding_indication ; } + -- END FOR ; + -- + -- component_specification ::= + -- instantiation_list : component_name + -- + -- instantiation_list ::= + -- instantiation_label { , instantiation_label } + -- | OTHERS + -- | ALL + -- + -- The declaration containing this type declaration. -- Get/Set_Parent (Field0) -- -- Get/Set_Component_Name (Field4) -- - -- Must be one of designator_list, designator_by_others or - -- designator_by_all. + -- Must be one of designator_list, designator_by_others or + -- designator_by_all. -- Get/Set_Instantiation_List (Field1) -- -- Only for Iir_Kind_Component_Configuration: @@ -492,16 +501,29 @@ package Iirs is -- Iir_Kind_Disconnection_Specification (Short) -- - -- The declaration containing this type declaration. - -- Get/Set_Parent (Field0) + -- LRM08 7.4 Disconnection specification -- - -- Get/Set_Signal_List (Field4) + -- disconnection_specification ::= + -- DISCONNECT guarded_signal_specification AFTER time_expression ; -- - -- Get/Set_Type (Field1) + -- guarded_signal_specification ::= + -- guarded_signal_list : type_mark -- - -- Get/Set_Expression (Field5) + -- signal_list ::= + -- signal_name { , signal_name } + -- | OTHERS + -- | ALL + -- + -- The declaration containing this type declaration. + -- Get/Set_Parent (Field0) -- -- Get/Set_Chain (Field2) + -- + -- Get/Set_Signal_List (Field3) + -- + -- Get/Set_Type_Mark (Field4) + -- + -- Get/Set_Expression (Field5) -- Iir_Kind_Block_Header (Medium) -- @@ -521,6 +543,27 @@ package Iirs is -- Iir_Kind_Attribute_Specification (Medium) -- + -- LRM08 7.2 Attribute specification + -- + -- attribute_specification ::= + -- ATTRIBUTE attribute_designator OF entity_specification + -- IS expression ; + -- + -- entity_specification ::= entity_name_list : entity_class + -- + -- entity_name_list ::= + -- entity_designator { , entity_designator } + -- | OTHERS + -- | ALL + -- + -- entity_designator ::= entity_tag [ signature ] + -- + -- entity_tag ::= simple_name | character_literal | operator_symbol + -- + -- LRM08 8.6 Attribute names + -- + -- attribute_designator ::= /attribute/_simple_name + -- -- Get/Set_Parent (Field0) -- -- Get/Set_Entity_Name_List (Field1) @@ -533,18 +576,19 @@ package Iirs is -- -- Get/Set_Expression (Field5) -- + -- Always a simple name. -- Get/Set_Attribute_Designator (Field6) -- -- Get/Set_Attribute_Specification_Chain (Field7) -- Iir_Kind_Attribute_Value (Short) - -- An attribute value is the element of the chain of attribute of an entity, - -- marking the entity as decorated by the attribute. - -- This node is built only by sem. - -- In fact, the node is member of the chain of attribute of an entity, and - -- of the chain of entity of the attribute specification. - -- This makes elaboration (and more precisely, expression evaluation) - -- easier. + -- An attribute value is the element of the chain of attribute of an + -- entity, marking the entity as decorated by the attribute. + -- This node is built only by sem. + -- In fact, the node is member of the chain of attribute of an entity, and + -- of the chain of entity of the attribute specification. + -- This makes elaboration (and more precisely, expression evaluation) + -- easier. -- -- Get/Set_Spec_Chain (Field0) -- @@ -562,35 +606,6 @@ package Iirs is -- -- Get/Set_Name_Staticness (State2) - -- Iir_Kind_Selected_Element (Short) - -- A record element selection. - -- - -- Get/Set_Prefix (Field0) - -- - -- Get/Set_Type (Field1) - -- - -- Get/Set_Selected_Element (Field2) - -- - -- Get/Set_Base_Name (Field5) - -- - -- Get/Set_Expr_Staticness (State1) - -- - -- Get/Set_Name_Staticness (State2) - - -- Iir_Kind_Implicit_Dereference (Short) - -- Iir_Kind_Dereference (Short) - -- An implicit access dereference. - -- - -- Get/Set_Prefix (Field0) - -- - -- Get/Set_Type (Field1) - -- - -- Get/Set_Base_Name (Field5) - -- - -- Get/Set_Expr_Staticness (State1) - -- - -- Get/Set_Name_Staticness (State2) - -- Iir_Kind_Psl_Expression (Short) -- -- Get/Set_Type (Field1) @@ -609,9 +624,9 @@ package Iirs is -- -- Get/Set_Overload_List (Field1) - ------------------ - -- Declarations -- - ------------------ + ------------------- + -- Declarations -- + ------------------- -- Iir_Kind_Entity_Declaration (Medium) -- @@ -647,9 +662,8 @@ package Iirs is -- -- Get_Declaration_Chain (Field1) -- - -- Entity declaration for the architecture. - -- Before the semantic pass, it can be a name. - -- Get/Set_Entity (Field2) + -- Name of the entity declaration for the architecture. + -- Get/Set_Entity_Name (Field2) -- -- Get/Set_Identifier (Field3) -- @@ -657,11 +671,9 @@ package Iirs is -- -- Get/Set_Concurrent_Statement_Chain (Field5) -- - -- The default configuration created by canon. This is a design unit. + -- The default configuration created by canon. This is a design unit. -- Get/Set_Default_Configuration_Declaration (Field6) -- - -- Get/Set_Entity_Name (Field7) - -- -- Get/Set_Foreign_Flag (Flag3) -- -- Get/Set_Visible_Flag (Flag4) @@ -679,9 +691,8 @@ package Iirs is -- -- Get_Declaration_Chain (Field1) -- - -- Set the entity of a configuration (a design_unit) - -- Before the semantic pass, it can be an identifier. - -- Get/Set_Entity (Field2) + -- Name of the entity of a configuration. + -- Get/Set_Entity_Name (Field2) -- -- Get/Set_Identifier (Field3) -- @@ -689,8 +700,6 @@ package Iirs is -- -- Get/Set_Block_Configuration (Field5) -- - -- Get/Set_Entity_Name (Field7) - -- -- Get/Set_Visible_Flag (Flag4) -- -- Get/Set_End_Has_Reserved_Id (Flag8) @@ -727,8 +736,8 @@ package Iirs is -- Get/Set_End_Has_Identifier (Flag9) -- Iir_Kind_Package_Body (Short) - -- Note: a body is not a declaration, that's the reason why there is no - -- _declaration suffix in the name. + -- Note: a body is not a declaration, that's the reason why there is no + -- _declaration suffix in the name. -- -- Get/Set_Parent (Field0) -- Get/Set_Design_Unit (Alias Field0) @@ -737,7 +746,7 @@ package Iirs is -- -- Get/Set_Identifier (Field3) -- - -- The corresponding package declaration. + -- The corresponding package declaration. -- Get/Set_Package (Field4) -- -- Get/Set_End_Has_Reserved_Id (Flag8) @@ -765,13 +774,13 @@ package Iirs is -- Iir_Kind_Library_Declaration (Medium) -- - -- Design files in the library. + -- Design files in the library. -- Get/Set_Design_File_Chain (Field1) -- -- Get/Set_Chain (Field2) -- - -- This node is used to contain all a library. Only internaly used. - -- Name (identifier) of the library. + -- This node is used to contain all a library. Only internaly used. + -- Name (identifier) of the library. -- Get/Set_Identifier (Field3) -- -- Get/Set_Date (Field10) @@ -798,14 +807,31 @@ package Iirs is -- -- Get/Set_Use_Flag (Flag6) -- + -- Get/Set_Has_Is (Flag7) + -- -- Get/Set_End_Has_Reserved_Id (Flag8) -- -- Get/Set_End_Has_Identifier (Flag9) + -- LRM08 6.6 Alias declarations + -- + -- alias_declaration ::= + -- ALIAS alias_designator [ : subtype_indication ] IS + -- name [ signature ] ; + -- + -- alias_designator ::= identifier | character_literal | operator_symbol + -- + -- Object aliases and non-object aliases are represented by two different + -- nodes, as their semantic is different. The parser only creates object + -- alias declaration nodes, but sem_decl replaces the node for non-object + -- alias declarations. + -- Iir_Kind_Object_Alias_Declaration (Short) -- -- Get/Set_Parent (Field0) -- + -- The type can be deduced from the subtype indication, but this field is + -- present for uniformity (and speed). -- Get/Set_Type (Field1) -- -- Get/Set_Chain (Field2) @@ -814,8 +840,8 @@ package Iirs is -- -- Get/Set_Name (Field4) -- - -- Note: base name is the alias itself. - -- Get/Set_Base_Name (Field5) + -- The subtype indication may not be present. + -- Get/Set_Subtype_Indication (Field5) -- -- Get/Set_Expr_Staticness (State1) -- @@ -837,10 +863,10 @@ package Iirs is -- -- Get/Set_Name (Field4) -- - -- Get/Set_Signature (Field5) + -- Get/Set_Alias_Signature (Field5) -- - -- Set when the alias was implicitely created (by Sem) because of an - -- explicit alias of a type. + -- Set when the alias was implicitely created (by Sem) because of an + -- explicit alias of a type. -- Get/Set_Implicit_Alias_Flag (Flag1) -- -- Get/Set_Visible_Flag (Flag4) @@ -855,23 +881,45 @@ package Iirs is -- -- Get/Set_Chain (Field2) -- - -- Used for informative purpose only. + -- Used for informative purpose only. -- Get/Set_Identifier (Field3) -- -- Get/Set_Subtype_Definition (Field4) -- Iir_Kind_Type_Declaration (Short) -- + -- LRM08 6.3 Type declarations + -- + -- type_declaration ::= + -- full_type_declaration + -- | incomplete_type_declaration + -- + -- full_type_declaration ::= + -- TYPE identifier IS type_definition ; + -- + -- type_definition ::= + -- scalar_type_definition + -- | composite_type_definition + -- | access_type_definition + -- | file_type_definition + -- | protected_type_definition + -- + -- LRM08 5.4.2 Incomplete type declarations + -- + -- incomplete_type_declaration ::= + -- TYPE identifier ; + -- -- Get/Set_Parent (Field0) -- - -- Definition of the type. - -- Note: the type definition can be a real type (unconstrained array, - -- enumeration, file, record, access) or a subtype (integer, floating - -- point). - -- The parser set this field to null_iir for an incomplete type declaration. - -- This field is set to an incomplete_type_definition node when first - -- semantized. + -- Definition of the type. + -- Note: the type definition can be a real type (unconstrained array, + -- enumeration, file, record, access) or a subtype (integer, floating + -- point). + -- The parser set this field to null_iir for an incomplete type + -- declaration. This field is set to an incomplete_type_definition node + -- when first semantized. -- Get/Set_Type_Definition (Field1) + -- Get/Set_Type (Alias Field1) -- -- Get/Set_Chain (Field2) -- @@ -885,6 +933,11 @@ package Iirs is -- Iir_Kind_Subtype_Declaration (Short) -- + -- LRM08 6.3 Subtype declarations + -- + -- subtype_declaration ::= + -- SUBTYPE identifier IS subtype_indication ; + -- -- Get/Set_Parent (Field0) -- -- Get/Set_Type (Field1) @@ -895,6 +948,8 @@ package Iirs is -- -- Get/Set_Attribute_Value_Chain (Field4) -- + -- Get/Set_Subtype_Indication (Field5) + -- -- Get/Set_Visible_Flag (Flag4) -- -- Get/Set_Use_Flag (Flag6) @@ -936,15 +991,14 @@ package Iirs is -- Iir_Kind_Variable_Interface_Declaration (Medium) -- Iir_Kind_File_Interface_Declaration (Medium) -- - -- Note: If type is an iir_kind_proxy node, then type *and* default value - -- (if any) must be extracted from proxy. - -- - -- Get/Set the parent of an interface declaration. - -- The parent is an entity declaration, a subprogram specification, a - -- component declaration, a loop statement, a block declaration or ?? - -- Useful to distinguish a port and an interface. + -- Get/Set the parent of an interface declaration. + -- The parent is an entity declaration, a subprogram specification, a + -- component declaration, a loop statement, a block declaration or ?? + -- Useful to distinguish a port and an interface. -- Get/Set_Parent (Field0) -- + -- The type can be deduced from the subtype indication, but this field is + -- present for uniformity (and speed). -- Get/Set_Type (Field1) -- -- Get/Set_Chain (Field2) @@ -953,9 +1007,9 @@ package Iirs is -- -- Get/Set_Attribute_Value_Chain (Field4) -- - -- Get/Set_Base_Name (Field5) + -- Get/Set_Subtype_Indication (Field5) -- - -- Must always be null_iir for iir_kind_file_interface_declaration. + -- Must always be null_iir for iir_kind_file_interface_declaration. -- Get/Set_Default_Value (Field6) -- -- Get/Set_Mode (Odigit1) @@ -987,12 +1041,36 @@ package Iirs is -- Iir_Kind_Function_Declaration (Medium) -- Iir_Kind_Procedure_Declaration (Medium) -- - -- Subprogram declaration. + -- LRM08 4.2 Subprogram declarations + -- + -- subprogram_declaration ::= subprogram_specification ; + -- + -- subprogram_specification ::= + -- procedure_specification | function_specification + -- + -- procedure_specification ::= + -- PROCEDURE designator + -- subprogram_header + -- [ [ PARAMETER ] ( formal_parameter_list ) ] + -- + -- function_specification ::= + -- [ PURE | IMPURE ] FUNCTION designator + -- subprogram_header + -- [ [ PARAMETER ] ( formal_parameter_list ) ] return type_mark -- - -- The declaration containing this subrogram declaration. + -- designator ::= identifier | operator_symbol + -- + -- operator_symbol ::= string_literal + -- + -- Note: the subprogram specification of a body is kept, but should be + -- ignored if there is a subprogram declaration. The function + -- Is_Second_Subprogram_Specification returns True on such specification. + -- + -- The declaration containing this subrogram declaration. -- Get/Set_Parent (Field0) -- -- Only for Iir_Kind_Function_Declaration: + -- FIXME: this is a type_mark. -- Get/Set_Return_Type (Field1) -- -- Only for Iir_Kind_Function_Declaration: @@ -1010,7 +1088,9 @@ package Iirs is -- -- Get/Set_Callees_List (Field7) -- - -- Get/Set_Generic_Map_Aspect_Chain (Field8) + -- --Get/Set_Generic_Map_Aspect_Chain (Field8) + -- + -- Get/Set_Return_Type_Mark (Field8) -- -- Get/Set_Subprogram_Body (Field9) -- @@ -1039,6 +1119,12 @@ package Iirs is -- Only for Iir_Kind_Function_Declaration: -- Get/Set_Resolution_Function_Flag (Flag7) -- + -- Only for Iir_Kind_Function_Declaration: + -- Get/Set_Has_Pure (Flag8) + -- + -- True is the specification is immediately followed by a body. + -- Get/Set_Has_Body (Flag9) + -- -- Get/Set_Wait_State (State1) -- -- Only for Iir_Kind_Procedure_Declaration: @@ -1049,10 +1135,21 @@ package Iirs is -- Iir_Kind_Function_Body (Short) -- Iir_Kind_Procedure_Body (Short) -- + -- LRM08 4.3 Subprogram bodies + -- + -- subprogram_body ::= + -- subprogram_specification IS + -- subprogram_declarative_part + -- BEGIN + -- subprogram_statement_part + -- END [ subprogram_kind ] [ designator ] ; + -- + -- subprogram_kind ::= PROCEDURE | FUNCTION + -- -- Get/Set_Parent (Field0) -- - -- The parse stage always puts a declaration before a body. - -- Sem will remove the declaration if there is a forward declaration. + -- The parse stage always puts a declaration before a body. + -- Sem will remove the declaration if there is a forward declaration. -- -- Get_Declaration_Chain (Field1) -- @@ -1071,9 +1168,9 @@ package Iirs is -- Iir_Kind_Implicit_Procedure_Declaration (Medium) -- Iir_Kind_Implicit_Function_Declaration (Medium) -- - -- This node contains a subprogram_declaration that was implicitly defined - -- just after a type declaration. - -- This declaration is inserted by sem. + -- This node contains a subprogram_declaration that was implicitly defined + -- just after a type declaration. + -- This declaration is inserted by sem. -- -- Get/Set_Parent (Field0) -- @@ -1130,14 +1227,14 @@ package Iirs is -- -- Get/Set_Attribute_Value_Chain (Field4) -- - -- Get/Set_Base_Name (Field5) + -- Get/Set_Subtype_Indication (Field5) -- -- Get/Set_Default_Value (Field6) -- - -- For a non-resolved signal: null_iir if the signal has no driver, or - -- a process/concurrent_statement for which the signal should have a - -- driver. This is used to catch at analyse time unresolved signals with - -- several drivers. + -- For a non-resolved signal: null_iir if the signal has no driver, or + -- a process/concurrent_statement for which the signal should have a + -- driver. This is used to catch at analyse time unresolved signals with + -- several drivers. -- Get/Set_Signal_Driver (Field7) -- -- Get/Set_Has_Disconnect_Flag (Flag1) @@ -1150,6 +1247,8 @@ package Iirs is -- -- Get/Set_Use_Flag (Flag6) -- + -- Get/Set_Has_Identifier_List (Flag7) + -- -- Get/Set_Expr_Staticness (State1) -- -- Get/Set_Name_Staticness (State2) @@ -1168,8 +1267,6 @@ package Iirs is -- -- Get/Set_Attribute_Value_Chain (Field4) -- - -- Get/Set_Base_Name (Field5) - -- -- Get/Set_Guard_Sensitivity_List (Field6) -- -- Get/Set_Block_Statement (Field7) @@ -1199,24 +1296,28 @@ package Iirs is -- -- Get/Set_Attribute_Value_Chain (Field4) -- - -- Get/Set_Base_Name (Field5) + -- Only for Iir_Kind_Constant_Declaration: + -- Get/Set_Subtype_Indication (Field5) + -- + -- Only for Iir_Kind_Iterator_Declaration: + -- Get/Set_Discrete_Range (Field5) -- -- Only for Iir_Kind_Constant_Declaration: - -- Default value of a deferred constant points to the full constant - -- declaration. + -- Default value of a deferred constant points to the full constant + -- declaration. -- Get/Set_Default_Value (Field6) -- -- Only for Iir_Kind_Constant_Declaration: - -- Summary: - -- | constant C1 : integer; -- Deferred declaration (in a package) - -- | constant C2 : integer := 4; -- Declaration - -- | constant C1 : integer := 3; -- Full declaration (in a body) - -- | NAME Deferred_declaration Deferred_declaration_flag - -- | C1 Null_iir or C1' (*) True - -- | C2 Null_Iir False - -- | C1' C1 False - -- |(*): Deferred_declaration is Null_Iir as long as the full declaration - -- | has not been analyzed. + -- Summary: + -- | constant C1 : integer; -- Deferred declaration (in a package) + -- | constant C2 : integer := 4; -- Declaration + -- | constant C1 : integer := 3; -- Full declaration (in a body) + -- | NAME Deferred_declaration Deferred_declaration_flag + -- | C1 Null_iir or C1' (*) True + -- | C2 Null_Iir False + -- | C1' C1 False + -- |(*): Deferred_declaration is Null_Iir as long as the full declaration + -- | has not been analyzed. -- Get/Set_Deferred_Declaration (Field7) -- -- Only for Iir_Kind_Constant_Declaration: @@ -1226,6 +1327,8 @@ package Iirs is -- -- Get/Set_Use_Flag (Flag6) -- + -- Get/Set_Has_Identifier_List (Flag7) + -- -- Get/Set_Expr_Staticness (State1) -- -- Get/Set_Name_Staticness (State2) @@ -1242,23 +1345,40 @@ package Iirs is -- -- Get/Set_Attribute_Value_Chain (Field4) -- - -- Get/Set_Base_Name (Field5) + -- Get/Set_Subtype_Indication (Field5) -- -- Get/Set_Default_Value (Field6) -- - -- True if the variable is a shared variable. + -- True if the variable is a shared variable. -- Get/Set_Shared_Flag (Flag2) -- -- Get/Set_Visible_Flag (Flag4) -- -- Get/Set_Use_Flag (Flag6) -- + -- Get/Set_Has_Identifier_List (Flag7) + -- -- Get/Set_Expr_Staticness (State1) -- -- Get/Set_Name_Staticness (State2) -- Iir_Kind_File_Declaration (Medium) -- + -- LRM08 6.4.2.5 File declarations + -- + -- file_declaration ::= + -- FILE identifier_list : subtype_indication [ file_open_information ] ; + -- + -- file_open_information ::= + -- [ OPEN file_open_kind_expression ] IS file_logical_name + -- + -- file_logical_name ::= string_expression + -- + -- LRM87 + -- + -- file_declaration ::= + -- FILE identifier : subtype_indication IS [ mode ] file_logical_name ; + -- -- Get/Set_Parent (Field0) -- -- Get/Set_Type (Field1) @@ -1269,39 +1389,58 @@ package Iirs is -- -- Get/Set_Attribute_Value_Chain (Field4) -- - -- Get/Set_Base_Name (Field5) + -- Get/Set_Subtype_Indication (Field5) -- -- Get/Set_File_Logical_Name (Field6) -- - -- This is not used in vhdl 87. + -- This is not used in vhdl 87. -- Get/Set_File_Open_Kind (Field7) -- - -- This is used only in vhdl 87. + -- This is used only in vhdl 87. -- Get/Set_Mode (Odigit1) -- -- Get/Set_Visible_Flag (Flag4) -- -- Get/Set_Use_Flag (Flag6) -- + -- Get/Set_Has_Identifier_List (Flag7) + -- -- Get/Set_Expr_Staticness (State1) -- -- Get/Set_Name_Staticness (State2) + -- + -- Get/Set_Has_Mode (Flag8) -- Iir_Kind_Element_Declaration (Short) -- + -- LRM08 5.3.3 Record types + -- + -- element_declaration ::= + -- identifier_list : element_subtype_definition ; + -- + -- identifier_list ::= identifier { , identifier } + -- + -- element_subtype_definition ::= subtype_indication + -- + -- The type can be deduced from the subtype indication, but this field is + -- present for uniformity (and speed). -- Get/Set_Type (Field1) -- -- Get/Set_Identifier (Field3) -- - -- Return the position of the element in the record, starting from 0 for the - -- first record element, increasing by one for each successive element. + -- Return the position of the element in the record, starting from 0 for + -- the first record element, increasing by one for each successive element. -- Get/Set_Element_Position (Field4) -- + -- Get/Set_Subtype_Indication (Field5) + -- -- Get/Set_Visible_Flag (Flag4) + -- + -- Get/Set_Has_Identifier_List (Flag7) -- Iir_Kind_Record_Element_Constraint (Short) -- - -- Record subtype definition which defines this constraint. + -- Record subtype definition which defines this constraint. -- Get/Set_Parent (Field0) -- -- Get/Set_Type (Field1) @@ -1310,14 +1449,19 @@ package Iirs is -- -- Get/Set_Identifier (Field3) -- - -- Return the position of the element in the record, starting from 0 for the - -- first record element, increasing by one for each successive element. + -- Return the position of the element in the record, starting from 0 for + -- the first record element, increasing by one for each successive element. -- Get/Set_Element_Position (Field4) -- -- Get/Set_Visible_Flag (Flag4) -- Iir_Kind_Attribute_Declaration (Short) -- + -- LRM08 6.7 Attribute declarations + -- + -- attribute_declaration ::= + -- ATTRIBUTE identifier : type_mark ; + -- -- Get/Set_Parent (Field0) -- -- Get/Set_Type (Field1) @@ -1326,6 +1470,8 @@ package Iirs is -- -- Get/Set_Identifier (Field3) -- + -- Get/Set_Type_Mark (Field4) + -- -- Get/Set_Visible_Flag (Flag4) -- -- Get/Set_Use_Flag (Flag6) @@ -1334,9 +1480,9 @@ package Iirs is -- -- Get/Set_Parent (Field0) -- - -- List of entity class entry. - -- To handle `<>', the last element of the list can be an entity_class of - -- kind tok_box. + -- List of entity class entry. + -- To handle `<>', the last element of the list can be an entity_class of + -- kind tok_box. -- Get/Set_Entity_Class_Entry_Chain (Field1) -- -- Get/Set_Chain (Field2) @@ -1349,10 +1495,10 @@ package Iirs is -- Iir_Kind_Group_Declaration (Short) -- - -- The declaration containing this type declaration. + -- The declaration containing this type declaration. -- Get/Set_Parent (Field0) -- - -- List of constituent. + -- List of constituents. -- Get/Set_Group_Constituent_List (Field1) -- -- Get/Set_Chain (Field2) @@ -1377,10 +1523,10 @@ package Iirs is -- -- Get/Set_Identifier (Field3) -- - -- Valid only for property declaration. + -- Valid only for property declaration. -- Get/Set_PSL_Clock (Field7) -- - -- Valid only for property declaration without parameters. + -- Valid only for property declaration without parameters. -- Get/Set_PSL_NFA (Field8) -- -- Get/Set_Visible_Flag (Flag4) @@ -1413,8 +1559,6 @@ package Iirs is -- -- Get/Set_Attribute_Value_Chain (Field4) -- - -- Get/Set_Base_Name (Field5) - -- -- Get/Set_Default_Value (Field6) -- -- Get/Set_Visible_Flag (Flag4) @@ -1438,8 +1582,6 @@ package Iirs is -- -- Get/Set_Attribute_Value_Chain (Field4) -- - -- Get/Set_Base_Name (Field5) - -- -- Get/Set_Default_Value (Field6) -- -- Get/Set_Tolerance (Field7) @@ -1458,6 +1600,11 @@ package Iirs is -- Iir_Kind_Use_Clause (Short) -- + -- LRM08 12.4 Use clauses + -- + -- use_clause ::= + -- USE selected_name { , selected_name } ; + -- -- Get/Set_Parent (Field0) -- -- Get/Set_Selected_Name (Field1) @@ -1467,50 +1614,50 @@ package Iirs is -- Get/Set_Use_Clause_Chain (Field3) - ---------------------- - -- type definitions -- - ---------------------- + ----------------------- + -- type definitions -- + ----------------------- -- For Iir_Kinds_Type_And_Subtype_Definition: -- - -- Type_Declarator: - -- Points to the type declaration or subtype declaration that has created - -- this definition. For some types, such as integer and floating point - -- types, both type and subtype points to the declaration. - -- However, there are cases where a type definition doesn't point to - -- a declarator: anonymous subtype created by index contraints, or - -- anonymous subtype created by an object declaration. - -- Note: a type definition cannot be anoynymous. + -- Type_Declarator: + -- Points to the type declaration or subtype declaration that has created + -- this definition. For some types, such as integer and floating point + -- types, both type and subtype points to the declaration. + -- However, there are cases where a type definition doesn't point to + -- a declarator: anonymous subtype created by index contraints, or + -- anonymous subtype created by an object declaration. + -- Note: a type definition cannot be anoynymous. -- Get/Set_Type_Declarator (Field3) -- - -- Get/Set the base type. - -- For a subtype, it returns the type. - -- For a type, it must return the type itself. + -- The base type. + -- For a subtype, it returns the type. + -- For a type, it must return the type itself. -- Get/Set_Base_Type (Field4) -- - -- Get/Set the staticness of a type, according to LRM93 7.4.1. - -- Note: These types definition are always locally static: - -- enumeration, integer, floating. - -- However, their subtype are not necessary locally static. + -- The staticness of a type, according to LRM93 7.4.1. + -- Note: These types definition are always locally static: + -- enumeration, integer, floating. + -- However, their subtype are not necessary locally static. -- Get/Set_Type_Staticness (State1) -- - -- Get/Set the resolved flag of a subtype, according to LRM93 2.4 + -- The resolved flag of a subtype, according to LRM93 2.4 -- Get/Set_Resolved_Flag (Flag1) -- - -- Get/Set the signal_type flag of a type definition. - -- It is true when the type can be used for a signal. + -- The signal_type flag of a type definition. + -- It is true when the type can be used for a signal. -- Get/Set_Signal_Type_Flag (Flag2) -- -- Get/Set_Has_Signal_Flag (Flag3) -- Iir_Kind_Enumeration_Type_Definition (Short) -- - -- Get the range of the type (This is just an ascending range from the - -- first literal to the last declared literal). + -- Get the range of the type (This is just an ascending range from the + -- first literal to the last declared literal). -- Get/Set_Range_Constraint (Field1) -- - -- Return the list of literals. This list is created when the node is - -- created. + -- Return the list of literals. This list is created when the node is + -- created. -- Get/Set_Enumeration_Literal_List (Field2) -- -- Get/Set_Type_Declarator (Field3) @@ -1529,8 +1676,9 @@ package Iirs is -- Iir_Kind_Enumeration_Literal (Medium) -- - -- Nota: two literals of the same type are equal iff their value is the - -- same; in other words, there may be severals literals with the same value. + -- Nota: two literals of the same type are equal iff their value is the + -- same; in other words, there may be severals literals with the same + -- value. -- -- Get/Set_Parent (Field0) -- @@ -1543,13 +1691,11 @@ package Iirs is -- -- Get/Set_Attribute_Value_Chain (Field4) -- - -- Get/Set_Base_Name (Field5) - -- - -- The declaration of the literal. If LITERAL_ORIGIN is not set, then this - -- is the node itself, else this is the literal defined. + -- The declaration of the literal. If LITERAL_ORIGIN is not set, then this + -- is the node itself, else this is the literal defined. -- Get/Set_Enumeration_Decl (Field6) -- - -- The value of an enumeration literal is the position. + -- The value of an enumeration literal is the position. -- Get/Set_Enum_Pos (Field10) -- -- Get/Set_Subprogram_Hash (Field11) @@ -1558,8 +1704,8 @@ package Iirs is -- -- Get/Set_Visible_Flag (Flag4) -- - -- Never set to true, but possible when used as a prefix of an expanded - -- name in a overloaded subprogram. + -- Never set to true, but possible when used as a prefix of an expanded + -- name in a overloaded subprogram. -- Get/Set_Is_Within_Flag (Flag5) -- -- Get/Set_Expr_Staticness (State1) @@ -1589,6 +1735,14 @@ package Iirs is -- Iir_Kind_Unit_Declaration (Medium) -- + -- LRM08 5.2.4 Physical types + -- + -- primary_unit_declaration ::= identifier ; + -- + -- secondary_unit_declaration ::= identifier = physical_literal ; + -- + -- physical_literal ::= [ abstract_literal ] /unit/_name + -- -- Get/Set_Type (Field1) -- -- Get/Set_Chain (Field2) @@ -1597,23 +1751,39 @@ package Iirs is -- -- Get/Set_Attribute_Value_Chain (Field4) -- + -- The Physical_Literal is the expression that appear in the sources, so + -- this is Null_Iir for a primary unit. -- Get/Set_Physical_Literal (Field6) -- + -- The value of the unit, computed from the primary unit. This is always + -- a physical integer literal. -- Get/Set_Physical_Unit_Value (Field7) -- -- Get/Set_Expr_Staticness (State1) -- + -- Get/Set_Name_Staticness (State2) + -- -- Get/Set_Visible_Flag (Flag4) + -- LRM08 5.2 Scalar types + -- + -- range_constraint ::= RANGE range + -- + -- range ::= + -- range_attribute_name + -- | simple_expression direction simple_expression + -- + -- direction ::= to | downto + -- Iir_Kind_Integer_Type_Definition (Short) -- Iir_Kind_Floating_Type_Definition (Short) -- - -- Get/Set the declarator that has created this integer type. + -- The type declarator that has created this type. -- Get/Set_Type_Declarator (Field3) -- -- Get/Set_Base_Type (Field4) -- - -- Type staticness is always locally. + -- Type staticness is always locally. -- Get/Set_Type_Staticness (State1) -- -- Get/Set_Resolved_Flag (Flag1) @@ -1623,14 +1793,22 @@ package Iirs is -- Get/Set_Has_Signal_Flag (Flag3) -- Iir_Kind_Array_Type_Definition (Medium) - -- This defines an unconstrained array type. -- - -- Get/Set_Element_Subtype (Field1) + -- LRM08 5.3.2 Array types / LRM93 3.2.1 + -- + -- unbounded_array_definition ::= + -- ARRAY ( index_subtype_definition { , index_subtype_definition } ) + -- OF element_subtype_indication + -- + -- index_subtype_definition ::= type_mark RANGE <> + -- + -- Get/Set_Element_Subtype_Indication (Field1) -- -- Get/Set_Type_Declarator (Field3) -- -- Get/Set_Base_Type (Field4) -- + -- This is a list of type marks. -- Get/Set_Index_Subtype_List (Field6) -- -- Get/Set_Type_Staticness (State1) @@ -1647,6 +1825,14 @@ package Iirs is -- Iir_Kind_Record_Type_Definition (Short) -- + -- LRM08 5.3.3 Record types / LRM93 3.2.2 Record types + -- + -- record_type_definition ::= + -- RECORD + -- element_declaration + -- { element_declaration } + -- END RECORD [ /record_type/_simple_name ] + -- -- Get/Set_Elements_Declaration_List (Field1) -- -- Get/Set_Type_Declarator (Field3) @@ -1669,15 +1855,18 @@ package Iirs is -- Iir_Kind_Access_Type_Definition (Short) -- - -- Get/Set_Designated_Type (Field2) + -- LRM08 5.4 Access types + -- + -- access_type_definition ::= ACCESS subtype_indication + -- + -- Get/Set_Designated_Type (Field1) + -- + -- Get/Set_Designated_Subtype_Indication (Field5) -- -- Get/Set_Type_Declarator (Field3) -- -- Get/Set_Base_Type (Field4) -- - -- FIXME: Only for access_subtype. - -- FIXME: Get/Set_Resolution_Function (Field5) - -- -- Get/Set_Resolved_Flag (Flag1) -- -- Get/Set_Signal_Type_Flag (Flag2) @@ -1686,7 +1875,7 @@ package Iirs is -- Iir_Kind_File_Type_Definition (Short) -- - -- Get/Set_Type_Mark (Field2) + -- Get/Set_File_Type_Mark (Field2) -- -- Get/Set_Type_Declarator (Field3) -- @@ -1696,20 +1885,20 @@ package Iirs is -- -- Get/Set_Signal_Type_Flag (Flag2) -- - -- True if this is the std.textio.text file type, which may require special - -- handling. + -- True if this is the std.textio.text file type, which may require special + -- handling. -- Get/Set_Text_File_Flag (Flag4) -- -- Get/Set_Type_Staticness (State1) -- Iir_Kind_Incomplete_Type_Definition (Short) - -- Type definition for an incomplete type. This is created during the - -- semantisation of the incomplete type declaration. + -- Type definition for an incomplete type. This is created during the + -- semantisation of the incomplete type declaration. -- -- Get/Set_Incomplete_Type_List (Field2) -- - -- Set to the incomplete type declaration when semantized, and set to the - -- complete type declaration when the latter one is semantized. + -- Set to the incomplete type declaration when semantized, and set to the + -- complete type declaration when the latter one is semantized. -- Get/Set_Type_Declarator (Field3) -- -- Get/Set_Base_Type (Field4) @@ -1758,9 +1947,80 @@ package Iirs is -- -- Get/Set_End_Has_Identifier (Flag9) - ------------------------- - -- subtype definitions -- - ------------------------- + -------------------------- + -- subtype definitions -- + -------------------------- + + -- LRM08 6.3 Subtype declarations + -- + -- subtype_indication ::= + -- [ resolution_indication ] type_mark [ constraint ] + -- + -- There is no uniq representation for a subtype indication. If there is + -- only a type_mark, then a subtype indication is represented by a name + -- (a simple name or an expanded name); otherwise it is represented by one + -- of the subtype definition node. + -- + -- resolution_indication ::= + -- resolution_function_name | ( element_resolution ) + -- + -- element_resolution ::= array_element_resolution | record_resolution + -- + -- array_element_resolution ::= resolution_indication + -- + -- record_resolution ::= + -- record_element_resolution { , record_element_resolution } + -- + -- record_element_resolution ::= + -- record_element_simple_name resolution_indication + -- + -- If there is no constraint but a resolution function name, the subtype + -- indication is represented by a subtype_definition (which will be + -- replaced by the correct subtype definition). If there is an array + -- element resolution the subtype indication is represented by an array + -- subtype definition, and if there is a record resolution, it is + -- represented by a record subtype definition. + -- + -- constraint ::= + -- range_constraint + -- | index_constraint + -- | array_constraint + -- | record_constraint + -- + -- There is no node for constraint, it is directly represented by one of + -- the rhs. + -- + -- element_constraint ::= + -- array_constraint + -- | record_constraint + -- + -- Likewise, there is no node for element_constraint. + -- + -- index_constraint ::= ( discrete_range { , discrete_range } ) + -- + -- An index_constraint is represented by an array_subtype_definition. + -- + -- discrete_range ::= /discrete/_subtype_indication | range + -- + -- array_constraint ::= + -- index_constraint [ array_element_constraint ] + -- | ( OPEN ) [ array_element_constraint ] + -- + -- An array_constraint is also represented by an array_subtype_definition. + -- + -- array_element_constraint ::= element_constraint + -- + -- There is no node for array_element_constraint. + -- + -- record_constraint ::= + -- ( record_element_constraint { , record_element_constraint } ) + -- + -- A record_constraint is represented by a record_subtype_definition. + -- + -- record_element_constraint ::= + -- record_element_simple_name element_constraint + -- + -- Represented by Record_Element_Constraint. -- Iir_Kind_Enumeration_Subtype_Definition (Short) -- Iir_Kind_Integer_Subtype_Definition (Short) @@ -1768,7 +2028,7 @@ package Iirs is -- -- Get/Set_Range_Constraint (Field1) -- - -- Get/Set_Type_Mark (Field2) + -- Get/Set_Subtype_Type_Mark (Field2) -- -- Get/Set_Type_Declarator (Field3) -- @@ -1788,7 +2048,7 @@ package Iirs is -- -- Get/Set_Range_Constraint (Field1) -- - -- Get/Set_Type_Mark (Field2) + -- Get/Set_Subtype_Type_Mark (Field2) -- -- Get/Set_Type_Declarator (Field3) -- @@ -1808,15 +2068,19 @@ package Iirs is -- Iir_Kind_Access_Subtype_Definition (Short) -- - -- Get/Set_Type_Staticness (State1) + -- Get/Set_Designated_Type (Field1) -- - -- Get/Set_Type_Mark (Field2) + -- Get/Set_Subtype_Type_Mark (Field2) -- -- Get/Set_Type_Declarator (Field3) -- -- Get/Set_Base_Type (Field4) -- - -- Note: no resolution function for access subtype. + -- Get/Set_Designated_Subtype_Indication (Field5) + -- + -- Note: no resolution function for access subtype. + -- + -- Get/Set_Type_Staticness (State1) -- -- Get/Set_Resolved_Flag (Flag1) -- @@ -1826,7 +2090,7 @@ package Iirs is -- -- Get/Set_Elements_Declaration_List (Field1) -- - -- Get/Set_Type_Mark (Field2) + -- Get/Set_Subtype_Type_Mark (Field2) -- -- Get/Set_Type_Declarator (Field3) -- @@ -1848,9 +2112,9 @@ package Iirs is -- Iir_Kind_Array_Subtype_Definition (Medium) -- - -- Get/Set_Element_Subtype (Field1) + -- Get/Set_Element_Subtype_Indication (Field1) -- - -- Get/Set_Type_Mark (Field2) + -- Get/Set_Subtype_Type_Mark (Field2) -- -- Get/Set_Type_Declarator (Field3) -- @@ -1858,6 +2122,7 @@ package Iirs is -- -- Get/Set_Resolution_Function (Field5) -- + -- The index_constraint. This is a list of subtype indication. -- Get/Set_Index_Subtype_List (Field6) -- -- Get/Set_Tolerance (Field7) @@ -1882,45 +2147,47 @@ package Iirs is -- -- Get/Set_Right_Limit (Field3) -- + -- Get/Set_Range_Origin (Field4) + -- -- Get/Set_Expr_Staticness (State1) -- -- Get/Set_Direction (State2) -- Iir_Kind_Subtype_Definition (Medium) - -- Such a node is only created by parse and transformed into the correct - -- kind (enumeration_subtype, integer_subtype...) by sem. + -- Such a node is only created by parse and transformed into the correct + -- kind (enumeration_subtype, integer_subtype...) by sem. -- -- Get/Set_Range_Constraint (Field1) -- - -- Get/Set_Type_Mark (Field2) + -- Get/Set_Subtype_Type_Mark (Field2) -- -- Get/Set_Resolution_Function (Field5) -- -- Get/Set_Tolerance (Field7) - ------------------------ - -- Nature definitions -- - ------------------------ + ------------------------- + -- Nature definitions -- + ------------------------- -- Iir_Kind_Scalar_Nature_Definition (Medium) -- -- Get/Set_Reference (Field2) -- - -- Get/Set the declarator that has created this nature type. + -- The declarator that has created this nature type. -- Get/Set_Nature_Declarator (Field3) -- - -- C-- Get/Set_Base_Type (Field4) + -- C-- Get/Set_Base_Type (Field4) -- - -- Type staticness is always locally. - -- C-- Get/Set_Type_Staticness (State1) + -- Type staticness is always locally. + -- C-- Get/Set_Type_Staticness (State1) -- -- Get/Set_Across_Type (Field7) -- -- Get/Set_Through_Type (Field8) - --------------------------- - -- concurrent statements -- - --------------------------- + ---------------------------- + -- concurrent statements -- + ---------------------------- -- Iir_Kind_Concurrent_Conditional_Signal_Assignment (Medium) -- Iir_Kind_Concurrent_Selected_Signal_Assignment (Medium) @@ -1947,10 +2214,10 @@ package Iirs is -- Only for Iir_Kind_Concurrent_Selected_Signal_Assignment: -- Get/Set_Selected_Waveform_Chain (Field7) -- - -- If the assignment is guarded, then get_guard must return the - -- declaration of the signal guard, otherwise, null_iir. - -- If the guard signal decl is not known, as a kludge and only to mark this - -- assignment guarded, the guard can be this assignment. + -- If the assignment is guarded, then get_guard must return the + -- declaration of the signal guard, otherwise, null_iir. + -- If the guard signal decl is not known, as a kludge and only to mark this + -- assignment guarded, the guard can be this assignment. -- Get/Set_Guard (Field8) -- -- Get/Set_Delay_Mechanism (Field12) @@ -1959,7 +2226,7 @@ package Iirs is -- -- Get/Set_Visible_Flag (Flag4) -- - -- True if the target of the assignment is guarded + -- True if the target of the assignment is guarded -- Get_Guarded_Target_State (State3) -- Iir_Kind_Sensitized_Process_Statement (Medium) @@ -1983,8 +2250,8 @@ package Iirs is -- -- Get/Set_Callees_List (Field7) -- - -- The concurrent statement at the origin of that process. This is Null_Iir - -- for a user process. + -- The concurrent statement at the origin of that process. This is + -- Null_Iir for a user process. -- Get/Set_Process_Origin (Field8) -- -- Get/Set_Wait_State (State1) @@ -1999,9 +2266,13 @@ package Iirs is -- -- Get/Set_Is_Within_Flag (Flag5) -- + -- Get/Set_Has_Is (Flag7) + -- -- Get/Set_End_Has_Reserved_Id (Flag8) -- -- Get/Set_End_Has_Identifier (Flag9) + -- + -- Get/Set_End_Has_Postponed (Flag10) -- Iir_Kind_Concurrent_Assertion_Statement (Medium) -- @@ -2061,11 +2332,23 @@ package Iirs is -- Iir_Kind_Component_Instantiation_Statement (Medium) -- + -- LRM08 11.7 Component instantiation statements + -- + -- component_instantiation_statement ::= + -- instantiation_label : + -- instantiated_unit + -- [ generic_map_aspect ] + -- [ port_map_aspect ] ; + -- + -- instantiated_unit ::= + -- [ COMPONENT ] component_name + -- | ENTITY entity_name [ ( architecture_identifier ) ] + -- | CONFIGURATION configuration_name + -- -- Get/Set_Parent (Field0) -- - -- Unit instantiated. - -- Parse: a name, a entity_aspect_entity or a entity_aspect_configuration - -- Sem: the component declaration or the design unit. + -- Unit instantiated. This is a name, an entity_aspect_entity or an + -- entity_aspect_configuration. -- Get/Set_Instantiated_Unit (Field1) -- -- Get/Set_Chain (Field2) @@ -2081,17 +2364,17 @@ package Iirs is -- -- Get/Set_Port_Map_Aspect_Chain (Field9) -- - -- Configuration: - -- In case of a configuration specification, the node is put into - -- default configuration. In the absence of a specification, the - -- default entity aspect, if any; if none, this field is null_iir. + -- Configuration: + -- In case of a configuration specification, the node is put into + -- default configuration. In the absence of a specification, the + -- default entity aspect, if any; if none, this field is null_iir. -- Get/Set_Configuration_Specification (Field7) -- - -- During Sem and elaboration, the configuration field can be filled by - -- a component configuration declaration. + -- During Sem and elaboration, the configuration field can be filled by + -- a component configuration declaration. -- - -- Configuration for this component. - -- FIXME: must be get/set_binding_indication. + -- Configuration for this component. + -- FIXME: must be get/set_binding_indication. -- Get/Set_Component_Configuration (Field6) -- -- Get/Set_Visible_Flag (Flag4) @@ -2115,8 +2398,8 @@ package Iirs is -- -- Get/Set_Block_Header (Field7) -- - -- get/set_guard_decl is used for semantic analysis, in order to add - -- a signal declaration. + -- get/set_guard_decl is used for semantic analysis, in order to add + -- a signal declaration. -- Get/Set_Guard_Decl (Field8) -- -- Get/Set_Visible_Flag (Flag4) @@ -2142,12 +2425,12 @@ package Iirs is -- -- Get/Set_Concurrent_Statement_Chain (Field5) -- - -- The generation scheme. - -- A (boolean) expression for a conditionnal elaboration (if). - -- A (iterator) declaration for an iterative elaboration (for). + -- The generation scheme. + -- A (boolean) expression for a conditionnal elaboration (if). + -- A (iterator) declaration for an iterative elaboration (for). -- Get/Set_Generation_Scheme (Field6) -- - -- The block configuration for this statement. + -- The block configuration for this statement. -- Get/Set_Generate_Block_Configuration (Field7) -- -- Get/Set_Visible_Flag (Flag4) @@ -2155,6 +2438,8 @@ package Iirs is -- Get/Set_End_Has_Reserved_Id (Flag8) -- -- Get/Set_End_Has_Identifier (Flag9) + -- + -- Get/Set_Has_Begin (Flag10) -- Iir_Kind_Simple_Simultaneous_Statement (Medium) -- @@ -2175,17 +2460,17 @@ package Iirs is -- -- Get/Set_Visible_Flag (Flag4) - --------------------------- - -- sequential statements -- - --------------------------- + ---------------------------- + -- sequential statements -- + ---------------------------- -- Iir_Kind_If_Statement (Medium) -- Iir_Kind_Elsif (Medium) -- -- Get/Set_Parent (Field0) -- - -- May be NULL only for an iir_kind_elsif node, and then means the else - -- clause. + -- May be NULL only for an iir_kind_elsif node, and then means the else + -- clause. -- Get/Set_Condition (Field1) -- -- Only for Iir_Kind_If_Statement: @@ -2202,7 +2487,7 @@ package Iirs is -- -- Get/Set_Sequential_Statement_Chain (Field5) -- - -- Must be an Iir_kind_elsif node, or NULL for no more elsif clauses. + -- Must be an Iir_kind_elsif node, or NULL for no more elsif clauses. -- Get/Set_Else_Clause (Field6) -- -- Only for Iir_Kind_If_Statement: @@ -2210,11 +2495,27 @@ package Iirs is -- -- Get/Set_End_Has_Identifier (Flag9) + -- LRM08 10.10 Loop statement / LRM93 8.9 + -- + -- loop_statement ::= + -- [ loop_label : ] + -- [ iteration_scheme ] LOOP + -- sequence_of_statements + -- END LOOP [ loop_label ] ; + -- + -- iteration_scheme ::= + -- WHILE condition + -- | FOR loop_parameter_specification + -- + -- parameter_specification ::= + -- identifier IN discrete_range + -- Iir_Kind_For_Loop_Statement (Short) -- -- Get/Set_Parent (Field0) -- - -- Get/Set_Iterator_Scheme (Field1) + -- The parameters specification is represented by an Iterator_Declaration. + -- Get/Set_Parameter_Specification (Field1) -- -- Get/Set_Chain (Field2) -- @@ -2253,6 +2554,16 @@ package Iirs is -- Iir_Kind_Exit_Statement (Short) -- Iir_Kind_Next_Statement (Short) -- + -- LRM08 10.11 Next statement + -- + -- next_statement ::= + -- [ label : ] NEXT [ loop_label ] [ WHEN condition ] ; + -- + -- LRM08 10.12 Exit statement + -- + -- exit_statement ::= + -- [ label : ] exit [ loop_label ] [ when condition ] ; + -- -- Get/Set_Parent (Field0) -- -- Get/Set_Condition (Field1) @@ -2264,8 +2575,7 @@ package Iirs is -- -- Get/Set_Attribute_Value_Chain (Field4) -- - -- Label identifier after parse. - -- Get/Set_Loop (Field5) + -- Get/Set_Loop_Label (Field5) -- -- Get/Set_Visible_Flag (Flag4) @@ -2282,10 +2592,10 @@ package Iirs is -- -- Get/Set_Attribute_Value_Chain (Field4) -- - -- The waveform. - -- If the waveform_chain is null_iir, then the signal assignment is a - -- disconnection statement, ie TARGET <= null_iir after disconection_time, - -- where disconnection_time is specified by a disconnection specification. + -- The waveform. + -- If the waveform_chain is null_iir, then the signal assignment is a + -- disconnection statement, ie TARGET <= null_iir after disconection_time, + -- where disconnection_time is specified by a disconnection specification. -- Get/Set_Waveform_Chain (Field5) -- -- Get/Set_Reject_Time_Expression (Field6) @@ -2294,7 +2604,7 @@ package Iirs is -- -- Get/Set_Visible_Flag (Flag4) -- - -- True if the target of the assignment is guarded + -- True if the target of the assignment is guarded -- Get_Guarded_Target_State (State3) -- Iir_Kind_Variable_Assignment_Statement (Short) @@ -2373,7 +2683,8 @@ package Iirs is -- -- Get/Set_Parent (Field0) -- - -- Type of the return value of the function. This is a copy of return_type. + -- Type of the return value of the function. This is a copy of + -- return_type. -- Get/Set_Type (Field1) -- -- Get/Set_Chain (Field2) @@ -2391,7 +2702,7 @@ package Iirs is -- -- Get/Set_Parent (Field0) -- - -- Chain is compose of Iir_Kind_Choice_By_XXX. + -- Chain is compose of Iir_Kind_Choice_By_XXX. -- Get/Set_Case_Statement_Alternative_Chain (Field1) -- -- Get/Set_Chain (Field2) @@ -2428,7 +2739,7 @@ package Iirs is -- Iir_Kind_Procedure_Call (Short) -- - -- Get/Set_Parent (Field0) + -- Get/Set_Prefix (Field0) -- -- Get/Set_Parameter_Association_Chain (Field2) -- @@ -2449,9 +2760,9 @@ package Iirs is -- -- Get/Set_Visible_Flag (Flag4) - --------------- - -- operators -- - --------------- + ---------------- + -- operators -- + ---------------- -- Iir_Kinds_Monadic_Operator (Short) -- @@ -2459,20 +2770,20 @@ package Iirs is -- -- Get/Set_Operand (Field2) -- - -- Function declaration corresponding to the function to call. + -- Function declaration corresponding to the function to call. -- Get/Set_Implementation (Field3) -- - -- Expr_staticness is defined by §7.4 + -- Expr_staticness is defined by §7.4 -- Get/Set_Expr_Staticness (State1) -- Iir_Kinds_Dyadic_Operator (Short) -- -- Get/Set_Type (Field1) -- - -- Left and Right operands. + -- Left and Right operands. -- Get/Set_Left (Field2) -- - -- Function declaration corresponding to the function to call. + -- Function declaration corresponding to the function to call. -- Get/Set_Implementation (Field3) -- -- Get/Set_Right (Field4) @@ -2481,11 +2792,13 @@ package Iirs is -- Iir_Kind_Function_Call (Short) -- + -- Get/Set_Prefix (Field0) + -- -- Get/Set_Type (Field1) -- -- Get/Set_Parameter_Association_Chain (Field2) -- - -- Function declaration corresponding to the function to call. + -- Function declaration corresponding to the function to call. -- Get/Set_Implementation (Field3) -- -- Get/Set_Method_Object (Field4) @@ -2510,35 +2823,35 @@ package Iirs is -- Iir_Kind_Aggregate_Info (Short) -- - -- Get info for the next dimension. NULL_IIR terminated. + -- Get info for the next dimension. NULL_IIR terminated. -- Get/Set_Sub_Aggregate_Info (Field1) -- - -- For array aggregate only: - -- If TRUE, the choices are not locally static. - -- This flag is only valid when the array aggregate is constrained, ie - -- has no 'others' choice. + -- For array aggregate only: + -- If TRUE, the choices are not locally static. + -- This flag is only valid when the array aggregate is constrained, ie + -- has no 'others' choice. -- Get/Set_Aggr_Dynamic_Flag (Flag3) -- - -- If TRUE, the aggregate is named, else it is positionnal. + -- If TRUE, the aggregate is named, else it is positionnal. -- Get/Set_Aggr_Named_Flag (Flag4) -- - -- The following three fields are used to check bounds of an array - -- aggregate. - -- For named aggregate, low and high bounds are computed, for positionnal - -- aggregate, the (minimum) number of elements is computed. - -- Note there may be elements beyond the bounds, due to other choice. - -- These fields may apply for the aggregate or for the aggregate and its - -- brothers if the node is for a sub-aggregate. + -- The following three fields are used to check bounds of an array + -- aggregate. + -- For named aggregate, low and high bounds are computed, for positionnal + -- aggregate, the (minimum) number of elements is computed. + -- Note there may be elements beyond the bounds, due to other choice. + -- These fields may apply for the aggregate or for the aggregate and its + -- brothers if the node is for a sub-aggregate. -- - -- The low and high index choice, if any. + -- The low and high index choice, if any. -- Get/Set_Aggr_Low_Limit (Field2) -- -- Get/Set_Aggr_High_Limit (Field3) -- - -- The minimum number of elements, if any. This is a minimax. + -- The minimum number of elements, if any. This is a minimax. -- Get/Set_Aggr_Min_Length (Field4) -- - -- True if the choice list has an 'others' choice. + -- True if the choice list has an 'others' choice. -- Get/Set_Aggr_Others_Flag (Flag2) -- Iir_Kind_Parenthesis_Expression (Short) @@ -2551,9 +2864,15 @@ package Iirs is -- Iir_Kind_Qualified_Expression (Short) -- + -- LRM08 9.3.5 Qualified expressions + -- + -- qualified_expression ::= + -- type_mark ' ( expression ) + -- | type_mark ' aggregate + -- -- Get/Set_Type (Field1) -- - -- Get/Set_Type_Mark (Field2) + -- Get/Set_Type_Mark (Field4) -- -- Get/Set_Expression (Field5) -- @@ -2561,9 +2880,13 @@ package Iirs is -- Iir_Kind_Type_Conversion (Short) -- + -- LRM08 9.3.6 Type conversions + -- + -- type_conversion ::= type_mark ( expression ) + -- -- Get/Set_Type (Field1) -- - -- Get/Set_Type_Mark (Field2) + -- Get/Set_Type_Mark (Field4) -- -- Get/Set_Expression (Field5) -- @@ -2572,26 +2895,38 @@ package Iirs is -- Iir_Kind_Allocator_By_Expression (Short) -- Iir_Kind_Allocator_By_Subtype (Short) -- + -- LRM08 9.3.7 Allocators + -- + -- allocator ::= + -- NEW subtype_indication + -- | NEW qualified_expression + -- -- Get/Set_Type (Field1) -- - -- To ease analysis: set to the designated type (either the type of the - -- expression or the subtype) + -- To ease analysis: set to the designated type (either the type of the + -- expression or the subtype) -- Get/Set_Allocator_Designated_Type (Field2) -- - -- Contains the expression for a by expression allocator or the - -- subtype indication for a by subtype allocator. + -- Only for Iir_Kind_Allocator_By_Expression: + -- Contains the expression for a by expression allocator. -- Get/Set_Expression (Field5) -- + -- Only for Iir_Kind_Allocator_By_Subtype: + -- Contains the subtype indication for a by subtype allocator. + -- Get/Set_Subtype_Indication (Field5) + -- -- Get/Set_Expr_Staticness (State1) - ----------- - -- names -- - ----------- + ------------ + -- Names -- + ------------ -- Iir_Kind_Simple_Name (Short) -- -- Get/Set_Type (Field1) -- + -- Get/Set_Alias_Declaration (Field2) + -- -- Get/Set_Identifier (Field3) -- -- Get/Set_Named_Entity (Field4) @@ -2599,13 +2934,15 @@ package Iirs is -- Get/Set_Base_Name (Field5) -- -- Get/Set_Expr_Staticness (State1) - - -- Iir_Kind_Selected_Name (Short) -- - -- Get/Set_Prefix (Field0) + -- Get/Set_Name_Staticness (State2) + + -- Iir_Kind_Character_Literal (Short) -- -- Get/Set_Type (Field1) -- + -- Get/Set_Alias_Declaration (Field2) + -- -- Get/Set_Identifier (Field3) -- -- Get/Set_Named_Entity (Field4) @@ -2613,29 +2950,53 @@ package Iirs is -- Get/Set_Base_Name (Field5) -- -- Get/Set_Expr_Staticness (State1) + -- + -- Get/Set_Name_Staticness (State2) - -- Iir_Kind_Selected_By_All_Name (Short) + -- Iir_Kind_Operator_Symbol (Short) + -- + -- Get/Set_Type (Field1) + -- + -- Get/Set_Alias_Declaration (Field2) + -- + -- Get/Set_Identifier (Field3) + -- + -- Get/Set_Named_Entity (Field4) + -- + -- Get/Set_Base_Name (Field5) + + -- Iir_Kind_Selected_Name (Short) -- -- Get/Set_Prefix (Field0) -- -- Get/Set_Type (Field1) -- + -- Get/Set_Alias_Declaration (Field2) + -- + -- Get/Set_Identifier (Field3) + -- -- Get/Set_Named_Entity (Field4) -- -- Get/Set_Base_Name (Field5) -- -- Get/Set_Expr_Staticness (State1) + -- + -- Get/Set_Name_Staticness (State2) - -- Iir_Kind_Operator_Symbol (Short) + -- Iir_Kind_Selected_By_All_Name (Short) -- - -- Get/Set_Identifier (Field3) + -- Get/Set_Prefix (Field0) + -- + -- Get/Set_Type (Field1) -- -- Get/Set_Named_Entity (Field4) -- -- Get/Set_Base_Name (Field5) + -- + -- Get/Set_Expr_Staticness (State1) -- Iir_Kind_Indexed_Name (Short) - -- Select the element designed with the INDEX_LIST from array PREFIX. + -- Select the element designed with the INDEX_LIST from array PREFIX. -- -- Get/Set_Prefix (Field0) -- @@ -2664,22 +3025,51 @@ package Iirs is -- Get/Set_Name_Staticness (State2) -- Iir_Kind_Parenthesis_Name (Short) - -- Created by the parser, and mutated into the correct iir node: it can be - -- either a function call, an indexed array, a type conversion or a slice - -- name. + -- Created by the parser, and mutated into the correct iir node: it can be + -- either a function call, an indexed array, a type conversion or a slice + -- name. -- -- Get/Set_Prefix (Field0) -- - -- Always returns null_iir. + -- Always returns null_iir. -- Get/Set_Type (Field1) -- -- Get/Set_Association_Chain (Field2) -- -- Get/Set_Named_Entity (Field4) - ---------------- - -- attributes -- - ---------------- + -- Iir_Kind_Selected_Element (Short) + -- A record element selection. + -- + -- Get/Set_Prefix (Field0) + -- + -- Get/Set_Type (Field1) + -- + -- Get/Set_Selected_Element (Field2) + -- + -- Get/Set_Base_Name (Field5) + -- + -- Get/Set_Expr_Staticness (State1) + -- + -- Get/Set_Name_Staticness (State2) + + -- Iir_Kind_Implicit_Dereference (Short) + -- Iir_Kind_Dereference (Short) + -- An implicit access dereference. + -- + -- Get/Set_Prefix (Field0) + -- + -- Get/Set_Type (Field1) + -- + -- Get/Set_Base_Name (Field5) + -- + -- Get/Set_Expr_Staticness (State1) + -- + -- Get/Set_Name_Staticness (State2) + + ----------------- + -- Attributes -- + ----------------- -- Iir_Kind_Attribute_Name (Short) -- @@ -2687,13 +3077,17 @@ package Iirs is -- -- Get/Set_Type (Field1) -- + -- Get/Set_Attribute_Signature (Field2) + -- -- Get/Set_Identifier (Field3) -- -- Get/Set_Named_Entity (Field4) -- - -- Get/Set_Signature (Field5) + -- Get/Set_Base_Name (Field5) -- -- Get/Set_Expr_Staticness (State1) + -- + -- Get/Set_Name_Staticness (State2) -- Iir_Kind_Base_Attribute (Short) -- @@ -2744,7 +3138,7 @@ package Iirs is -- Iir_Kind_Delayed_Attribute (Short) -- Iir_Kind_Quiet_Attribute (Short) -- Iir_Kind_Transaction_Attribute (Short) - -- (Iir_Kinds_Signal_Attribute) + -- (Iir_Kinds_Signal_Attribute) -- -- Get/Set_Prefix (Field0) -- @@ -2752,16 +3146,16 @@ package Iirs is -- -- Get/Set_Chain (Field2) -- - -- Not used by Iir_Kind_Transaction_Attribute + -- Not used by Iir_Kind_Transaction_Attribute -- Get/Set_Parameter (Field4) -- + -- Get/Set_Base_Name (Field5) + -- -- Get/Set_Has_Active_Flag (Flag2) -- -- Get/Set_Expr_Staticness (State1) -- -- Get/Set_Name_Staticness (State2) - -- - -- Get/Set_Base_Name (Field5) -- Iir_Kind_Event_Attribute (Short) -- Iir_Kind_Last_Event_Attribute (Short) @@ -2832,10 +3226,10 @@ package Iirs is -- Iir_Kind_Behavior_Attribute (Short) -- Iir_Kind_Structure_Attribute (Short) - -- FIXME: to describe (Short) + -- FIXME: to describe (Short) -- Iir_Kind_Error (Short) - -- Can be used instead of an expression or a type. + -- Can be used instead of an expression or a type. -- Get/Set_Type (Field1) -- -- Get/Set_Error_Origin (Field2) @@ -2854,7 +3248,6 @@ package Iirs is -- -- Get/Set_Has_Signal_Flag (Flag3) - -- End of Iir_Kind. @@ -2869,7 +3262,6 @@ package Iirs is Iir_Kind_Use_Clause, -- Literals. - Iir_Kind_Character_Literal, Iir_Kind_Integer_Literal, Iir_Kind_Floating_Point_Literal, Iir_Kind_Null_Literal, @@ -2881,7 +3273,6 @@ package Iirs is Iir_Kind_Overflow_Literal, -- Tuple, - Iir_Kind_Proxy, Iir_Kind_Waveform_Element, Iir_Kind_Conditional_Waveform, Iir_Kind_Association_Element_By_Expression, @@ -2904,7 +3295,6 @@ package Iirs is Iir_Kind_Signature, Iir_Kind_Aggregate_Info, Iir_Kind_Procedure_Call, - Iir_Kind_Operator_Symbol, Iir_Kind_Record_Element_Constraint, Iir_Kind_Attribute_Specification, @@ -3043,6 +3433,8 @@ package Iirs is Iir_Kind_Selected_Element, Iir_Kind_Dereference, Iir_Kind_Implicit_Dereference, + Iir_Kind_Slice_Name, + Iir_Kind_Indexed_Name, Iir_Kind_Psl_Expression, -- Concurrent statements. @@ -3079,10 +3471,11 @@ package Iirs is Iir_Kind_Elsif, -- Names - Iir_Kind_Simple_Name, - Iir_Kind_Slice_Name, - Iir_Kind_Indexed_Name, - Iir_Kind_Selected_Name, + Iir_Kind_Character_Literal, -- denoting_name + Iir_Kind_Simple_Name, -- denoting_name + Iir_Kind_Selected_Name, -- denoting_name + Iir_Kind_Operator_Symbol, -- denoting_name + Iir_Kind_Selected_By_All_Name, Iir_Kind_Parenthesis_Name, @@ -3166,22 +3559,24 @@ package Iirs is -- has_class: set if class (constant, signal, variable or file) is explicit -- -- Exemple: - -- procedure P (A,B: integer; - -- C: in constant bit; - -- D: inout bit; - -- E: variable bit; - -- F, G: in bit; - -- H, I: constant bit; - -- J, K: in constant bit); + -- procedure P ( A, B: integer; + -- constant C: in bit; + -- D: inout bit; + -- variable E: bit; + -- F, G: in bit; + -- constant H, I: bit; + -- constant J, K: in bit); -- A: - -- B: has_type - -- C, K: has_mode, has_class, has_type - -- D: has_mode, has_type - -- E, I: has_class, has_type - -- F: has_mode - -- G: has_mode, has_type - -- H: has_class - -- J: has_mode, has_class + -- B: has_type + -- C, has_class, has_mode, has_type + -- D: has_mode, has_type + -- E, has_class, has_type + -- F: has_mode + -- G: has_mode, has_type + -- H: has_class + -- I: has_class, has_type + -- J: has_class, has_mode + -- K: has_class, has_mode, has_type type Iir_Lexical_Layout_Type is mod 2 ** 3; Iir_Lexical_Has_Mode : constant Iir_Lexical_Layout_Type := 2 ** 0; Iir_Lexical_Has_Class : constant Iir_Lexical_Layout_Type := 2 ** 1; @@ -3480,10 +3875,10 @@ package Iirs is --Iir_Predefined_Std_Ulogic_Match_Greater Iir_Predefined_Std_Ulogic_Match_Greater_Equal; - -- Staticness as defined by LRM93 §6.1 and §7.4 + -- Staticness as defined by LRM93 §6.1 and §7.4 type Iir_Staticness is (Unknown, None, Globally, Locally); - -- Staticness as defined by LRM93 §6.1 and §7.4 + -- Staticness as defined by LRM93 §6.1 and §7.4 function Min (L,R: Iir_Staticness) return Iir_Staticness renames Iir_Staticness'Min; @@ -3555,8 +3950,7 @@ package Iirs is -- Note: does not include iir_kind_enumeration_literal since it is -- considered as a declaration. subtype Iir_Kinds_Literal is Iir_Kind range - Iir_Kind_Character_Literal .. - --Iir_Kind_Integer_Literal + Iir_Kind_Integer_Literal .. --Iir_Kind_Floating_Point_Literal --Iir_Kind_Null_Literal --Iir_Kind_String_Literal @@ -3619,7 +4013,6 @@ package Iirs is --Iir_Kind_Enumeration_Type_Definition Iir_Kind_Integer_Type_Definition; - -- subtype Iir_Kinds_Discrete_Subtype_Definition is Iir_Kind range -- Iir_Kind_Integer_Subtype_Definition .. -- Iir_Kind_Enumeration_Subtype_Definition; @@ -3765,11 +4158,17 @@ package Iirs is --Iir_Kind_Choice_By_None Iir_Kind_Choice_By_Name; + subtype Iir_Kinds_Denoting_Name is Iir_Kind range + Iir_Kind_Character_Literal .. + --Iir_Kind_Simple_Name + --Iir_Kind_Selected_Name + Iir_Kind_Operator_Symbol; + subtype Iir_Kinds_Name is Iir_Kind range - Iir_Kind_Simple_Name .. - --Iir_Kind_Slice_Name - --Iir_Kind_Indexed_Name + Iir_Kind_Character_Literal .. + --Iir_Kind_Simple_Name --Iir_Kind_Selected_Name + --Iir_Kind_Operator_Symbol --Iir_Kind_Selected_By_All_Name Iir_Kind_Parenthesis_Name; @@ -3815,10 +4214,10 @@ package Iirs is --Iir_Kind_Length_Array_Attribute Iir_Kind_Ascending_Array_Attribute; - + -- All the attributes. subtype Iir_Kinds_Attribute is Iir_Kind range Iir_Kind_Base_Attribute .. - Iir_Kind_Path_Name_Attribute; + Iir_Kind_Reverse_Range_Array_Attribute; subtype Iir_Kinds_Type_Attribute is Iir_Kind range Iir_Kind_Left_Type_Attribute .. @@ -4130,9 +4529,6 @@ package Iirs is subtype Iir_File_Type_Definition is Iir; - -- Tuples. - subtype Iir_Proxy is Iir; - subtype Iir_Waveform_Element is Iir; subtype Iir_Conditional_Waveform is Iir; @@ -4547,13 +4943,9 @@ package Iirs is function Get_Literal_Origin (Lit : Iir) return Iir; procedure Set_Literal_Origin (Lit : Iir; Orig : Iir); - -- tuples. - - function Create_Proxy (Proxy: Iir) return Iir_Proxy; - - -- Field: Field1 - function Get_Proxy (Target : Iir_Proxy) return Iir; - procedure Set_Proxy (Target : Iir_Proxy; Proxy : Iir); + -- Field: Field4 + function Get_Range_Origin (Lit : Iir) return Iir; + procedure Set_Range_Origin (Lit : Iir; Orig : Iir); -- Field: Field3 (uc) function Get_Entity_Class (Target : Iir) return Token_Type; @@ -4578,7 +4970,7 @@ package Iirs is function Get_Attribute_Specification (Val : Iir) return Iir; procedure Set_Attribute_Specification (Val : Iir; Attr : Iir); - -- Field: Field4 (uc) + -- Field: Field3 (uc) function Get_Signal_List (Target : Iir) return Iir_List; procedure Set_Signal_List (Target : Iir; List : Iir_List); @@ -4694,13 +5086,8 @@ package Iirs is function Get_Attribute_Value_Spec_Chain (Target : Iir) return Iir; procedure Set_Attribute_Value_Spec_Chain (Target : Iir; Chain : Iir); - -- The entity declaration for an architecture or a configuration. - -- Field: Field2 - function Get_Entity (Decl : Iir) return Iir; - procedure Set_Entity (Decl : Iir; Entity : Iir); - -- The entity name for an architecture or a configuration. - -- Field: Field7 + -- Field: Field2 function Get_Entity_Name (Arch : Iir) return Iir; procedure Set_Entity_Name (Arch : Iir; Entity : Iir); @@ -4745,6 +5132,14 @@ package Iirs is procedure Set_Type (Target : Iir; Atype : Iir); pragma Inline (Get_Type); + -- Field: Field5 + function Get_Subtype_Indication (Target : Iir) return Iir; + procedure Set_Subtype_Indication (Target : Iir; Atype : Iir); + + -- Field: Field5 + function Get_Discrete_Range (Target : Iir) return Iir; + procedure Set_Discrete_Range (Target : Iir; Rng : Iir); + -- Field: Field1 function Get_Type_Definition (Decl : Iir) return Iir; procedure Set_Type_Definition (Decl : Iir; Atype : Iir); @@ -4917,10 +5312,10 @@ package Iirs is function Get_Selected_Name (Target : Iir_Use_Clause) return Iir; procedure Set_Selected_Name (Target : Iir_Use_Clause; Name : Iir); - -- The type declarator which declares the type definition TARGET. + -- The type declarator which declares the type definition DEF. -- Field: Field3 - function Get_Type_Declarator (Target : Iir) return Iir; - procedure Set_Type_Declarator (Target : Iir; Decl : Iir); + function Get_Type_Declarator (Def : Iir) return Iir; + procedure Set_Type_Declarator (Def : Iir; Decl : Iir); -- Field: Field2 (uc) function Get_Enumeration_Literal_List (Target : Iir) return Iir_List; @@ -5037,18 +5432,22 @@ package Iirs is procedure Set_Index_List (Decl : Iir; List : Iir_List); -- Field: Field1 - function Get_Element_Subtype (Decl : Iir) return Iir; - procedure Set_Element_Subtype (Decl : Iir; Sub_Type : Iir); + function Get_Element_Subtype_Indication (Decl : Iir) return Iir; + procedure Set_Element_Subtype_Indication (Decl : Iir; Sub_Type : Iir); -- Chains of elements of a record. -- Field: Field1 (uc) function Get_Elements_Declaration_List (Decl : Iir) return Iir_List; procedure Set_Elements_Declaration_List (Decl : Iir; List : Iir_List); - -- Field: Field2 + -- Field: Field1 function Get_Designated_Type (Target : Iir) return Iir; procedure Set_Designated_Type (Target : Iir; Dtype : Iir); + -- Field: Field5 + function Get_Designated_Subtype_Indication (Target : Iir) return Iir; + procedure Set_Designated_Subtype_Indication (Target : Iir; Dtype : Iir); + -- The terminal declaration for the reference (ground) of a nature -- Field: Field2 function Get_Reference (Def : Iir) return Iir; @@ -5240,8 +5639,8 @@ package Iirs is -- Configuration of an entity_aspect_configuration. -- Field: Field1 - function Get_Configuration (Target : Iir) return Iir; - procedure Set_Configuration (Target : Iir; Conf : Iir); + function Get_Configuration_Name (Target : Iir) return Iir; + procedure Set_Configuration_Name (Target : Iir; Conf : Iir); -- Component configuration for a component_instantiation_statement. -- Field: Field6 @@ -5339,8 +5738,8 @@ package Iirs is -- Iterator of a for_loop_statement. -- Field: Field1 - function Get_Iterator_Scheme (Target : Iir) return Iir; - procedure Set_Iterator_Scheme (Target : Iir; Iterator : Iir); + function Get_Parameter_Specification (Target : Iir) return Iir; + procedure Set_Parameter_Specification (Target : Iir; Param : Iir); -- Get/Set the statement in which TARGET appears. This is used to check -- if next/exit is in a loop. @@ -5350,8 +5749,8 @@ package Iirs is -- Loop label for an exit_statement or next_statement. -- Field: Field5 - function Get_Loop (Target : Iir) return Iir; - procedure Set_Loop (Target : Iir; Stmt : Iir); + function Get_Loop_Label (Target : Iir) return Iir; + procedure Set_Loop_Label (Target : Iir; Stmt : Iir); -- Component name for a component_configuration or -- a configuration_specification. @@ -5385,8 +5784,14 @@ package Iirs is -- The named entity designated by a name. -- Field: Field4 - function Get_Named_Entity (Target : Iir) return Iir; - procedure Set_Named_Entity (Target : Iir; Val : Iir); + function Get_Named_Entity (Name : Iir) return Iir; + procedure Set_Named_Entity (Name : Iir; Val : Iir); + + -- If a name designate a non-object alias, the designated alias. + -- Named_Entity will designate the aliased entity. + -- Field: Field2 + function Get_Alias_Declaration (Name : Iir) return Iir; + procedure Set_Alias_Declaration (Name : Iir; Val : Iir); -- Expression staticness, defined by rules of LRM 7.4 -- Field: State1 (pos) @@ -5553,13 +5958,27 @@ package Iirs is function Get_Method_Object (Target : Iir) return Iir; procedure Set_Method_Object (Target : Iir; Object : Iir); - -- The type_mark that appeared in the subtype indication. + -- The type_mark that appeared in the subtype indication. This is a name. -- May be null_iir if there is no type mark (as in an iterator). - -- May differ from base_type, if the type_mark is a subtype_name. -- Field: Field2 + function Get_Subtype_Type_Mark (Target : Iir) return Iir; + procedure Set_Subtype_Type_Mark (Target : Iir; Mark : Iir); + + -- The type_mark that appeared in qualified expressions or type + -- conversions. + -- Field: Field4 function Get_Type_Mark (Target : Iir) return Iir; procedure Set_Type_Mark (Target : Iir; Mark : Iir); + -- The type of values for a type file. + -- Field: Field2 + function Get_File_Type_Mark (Target : Iir) return Iir; + procedure Set_File_Type_Mark (Target : Iir; Mark : Iir); + + -- Field: Field8 + function Get_Return_Type_Mark (Target : Iir) return Iir; + procedure Set_Return_Type_Mark (Target : Iir; Mark : Iir); + -- Get/set the lexical layout of an interface. -- Field: Odigit2 (pos) function Get_Lexical_Layout (Decl : Iir) return Iir_Lexical_Layout_Type; @@ -5601,8 +6020,12 @@ package Iirs is procedure Set_Implicit_Alias_Flag (Decl : Iir; Flag : Boolean); -- Field: Field5 - function Get_Signature (Target : Iir) return Iir; - procedure Set_Signature (Target : Iir; Value : Iir); + function Get_Alias_Signature (Alias : Iir) return Iir; + procedure Set_Alias_Signature (Alias : Iir; Signature : Iir); + + -- Field: Field2 + function Get_Attribute_Signature (Attr : Iir) return Iir; + procedure Set_Attribute_Signature (Attr : Iir; Signature : Iir); -- Field: Field1 (uc) function Get_Overload_List (Target : Iir) return Iir_List; @@ -5653,11 +6076,44 @@ package Iirs is function Get_End_Has_Identifier (Decl : Iir) return Boolean; procedure Set_End_Has_Identifier (Decl : Iir; Flag : Boolean); + -- Layout flag: true if 'end' is followed by 'postponed'. + -- Field: Flag10 + function Get_End_Has_Postponed (Decl : Iir) return Boolean; + procedure Set_End_Has_Postponed (Decl : Iir; Flag : Boolean); + -- Layout flag: true if 'begin' is present. -- Field: Flag10 function Get_Has_Begin (Decl : Iir) return Boolean; procedure Set_Has_Begin (Decl : Iir; Flag : Boolean); + -- Layout flag: true if 'is' is present. + -- Field: Flag7 + function Get_Has_Is (Decl : Iir) return Boolean; + procedure Set_Has_Is (Decl : Iir; Flag : Boolean); + + -- Layout flag: true if 'pure' or 'impure' is present. + -- Field: Flag8 + function Get_Has_Pure (Decl : Iir) return Boolean; + procedure Set_Has_Pure (Decl : Iir; Flag : Boolean); + + -- Layout flag: true if body appears just after the specification. + -- Field: Flag9 + function Get_Has_Body (Decl : Iir) return Boolean; + procedure Set_Has_Body (Decl : Iir; Flag : Boolean); + + -- Layout flag for object declaration. If True, the identifier of this + -- declaration is followed by an identifier (and separated by a comma). + -- This flag is set on all but the last declarations. + -- Eg: on 'signal A, B, C : Bit', the flag is set on A and B (but not C). + -- Field: Flag7 + function Get_Has_Identifier_List (Decl : Iir) return Boolean; + procedure Set_Has_Identifier_List (Decl : Iir; Flag : Boolean); + + -- Layout flag for object declaration. If True, the mode is present. + -- Field: Flag8 + function Get_Has_Mode (Decl : Iir) return Boolean; + procedure Set_Has_Mode (Decl : Iir; Flag : Boolean); + -- Field: Field1 (uc) function Get_Psl_Property (Decl : Iir) return PSL_Node; procedure Set_Psl_Property (Decl : Iir; Prop : PSL_Node); diff --git a/iirs_utils.adb b/iirs_utils.adb index d307febda..310fffa3f 100644 --- a/iirs_utils.adb +++ b/iirs_utils.adb @@ -45,6 +45,11 @@ package body Iirs_Utils is return Res; end Current_Text; + function Is_Error (N : Iir) return Boolean is + begin + return Get_Kind (N) = Iir_Kind_Error; + end Is_Error; + function Get_Operator_Name (Op : Iir) return Name_Id is begin case Get_Kind (Op) is @@ -175,10 +180,12 @@ package body Iirs_Utils is end loop; end Get_Longuest_Static_Prefix; - function Get_Object_Prefix (Decl: Iir) return Iir is - Adecl: Iir; + function Get_Object_Prefix (Name: Iir; With_Alias : Boolean := True) + return Iir + is + Adecl : Iir; begin - Adecl := Decl; + Adecl := Name; loop case Get_Kind (Adecl) is when Iir_Kind_Variable_Declaration @@ -193,7 +200,11 @@ package body Iirs_Utils is | Iir_Kind_Iterator_Declaration => return Adecl; when Iir_Kind_Object_Alias_Declaration => - Adecl := Get_Name (Adecl); + if With_Alias then + Adecl := Get_Name (Adecl); + else + return Adecl; + end if; when Iir_Kind_Indexed_Name | Iir_Kind_Slice_Name | Iir_Kind_Selected_Element @@ -220,12 +231,35 @@ package body Iirs_Utils is when Iir_Kind_Simple_Name | Iir_Kind_Selected_Name => Adecl := Get_Named_Entity (Adecl); + when Iir_Kind_Attribute_Name => + return Get_Named_Entity (Adecl); when others => Error_Kind ("get_object_prefix", Adecl); end case; end loop; end Get_Object_Prefix; + function Get_Association_Interface (Assoc : Iir) return Iir + is + Formal : Iir; + begin + Formal := Get_Formal (Assoc); + loop + case Get_Kind (Formal) is + when Iir_Kind_Simple_Name => + return Get_Named_Entity (Formal); + when Iir_Kinds_Interface_Declaration => + return Formal; + when Iir_Kind_Slice_Name + | Iir_Kind_Indexed_Name + | Iir_Kind_Selected_Element => + Formal := Get_Prefix (Formal); + when others => + Error_Kind ("get_association_interface", Formal); + end case; + end loop; + end Get_Association_Interface; + function Find_Name_In_List (List: Iir_List; Lit: Name_Id) return Iir is El: Iir; Ident: Name_Id; @@ -492,8 +526,6 @@ package body Iirs_Utils is return; when Iir_Kind_Architecture_Body => Free_Recursive (Get_Entity (N)); - when Iir_Kind_Proxy => - null; when Iir_Kind_Overload_List => Free_Recursive_List (Get_Overload_List (N)); if not Free_List then @@ -549,18 +581,101 @@ package body Iirs_Utils is or else Get_Constraint_State (Def) = Fully_Constrained; end Is_Fully_Constrained_Type; - function Get_Type_Of_Type_Mark (Mark : Iir) return Iir is + function Strip_Denoting_Name (Name : Iir) return Iir is begin - case Get_Kind (Mark) is - when Iir_Kind_Type_Declaration => - return Get_Type_Definition (Mark); - when Iir_Kind_Subtype_Declaration - | Iir_Kind_Base_Attribute => - return Get_Type (Mark); + if Get_Kind (Name) in Iir_Kinds_Denoting_Name then + return Get_Named_Entity (Name); + else + return Name; + end if; + end Strip_Denoting_Name; + + function Build_Simple_Name (Ref : Iir; Loc : Location_Type) return Iir + is + Res : Iir; + begin + Res := Create_Iir (Iir_Kind_Simple_Name); + Set_Location (Res, Loc); + Set_Identifier (Res, Get_Identifier (Ref)); + Set_Named_Entity (Res, Ref); + Set_Base_Name (Res, Res); + -- FIXME: set type and expr staticness ? + return Res; + end Build_Simple_Name; + + function Build_Simple_Name (Ref : Iir; Loc : Iir) return Iir is + begin + return Build_Simple_Name (Ref, Get_Location (Loc)); + end Build_Simple_Name; + + function Get_Primary_Unit_Name (Physical_Def : Iir) return Iir + is + Unit : constant Iir := Get_Primary_Unit (Physical_Def); + begin + return Get_Unit_Name (Get_Physical_Unit_Value (Unit)); + end Get_Primary_Unit_Name; + + function Is_Type_Name (Name : Iir) return Iir + is + Ent : Iir; + begin + if Get_Kind (Name) in Iir_Kinds_Denoting_Name then + Ent := Get_Named_Entity (Name); + case Get_Kind (Ent) is + when Iir_Kind_Type_Declaration => + return Get_Type_Definition (Ent); + when Iir_Kind_Subtype_Declaration + | Iir_Kind_Base_Attribute => + return Get_Type (Ent); + when others => + return Null_Iir; + end case; + else + return Null_Iir; + end if; + end Is_Type_Name; + + function Get_Type_Of_Subtype_Indication (Ind : Iir) return Iir is + begin + case Get_Kind (Ind) is + when Iir_Kinds_Denoting_Name => + return Get_Type (Ind); + when Iir_Kinds_Subtype_Definition => + return Ind; when others => - Error_Kind ("get_type_of_type_mark", Mark); + Error_Kind ("get_type_of_subtype_indication", Ind); end case; - end Get_Type_Of_Type_Mark; + end Get_Type_Of_Subtype_Indication; + + function Get_Index_Type (Indexes : Iir_List; Idx : Natural) return Iir + is + Index : constant Iir := Get_Nth_Element (Indexes, Idx); + begin + if Index = Null_Iir then + return Null_Iir; + else + return Get_Index_Type (Index); + end if; + end Get_Index_Type; + + function Get_Index_Type (Array_Type : Iir; Idx : Natural) return Iir is + begin + return Get_Index_Type (Get_Index_Subtype_List (Array_Type), Idx); + end Get_Index_Type; + + function Get_Element_Subtype (Def : Iir) return Iir is + begin + return Get_Type_Of_Subtype_Indication + (Get_Element_Subtype_Indication (Def)); + end Get_Element_Subtype; + + function Is_Second_Subprogram_Specification (Spec : Iir) return Boolean + is + Bod : constant Iir := Get_Subprogram_Body (Spec); + begin + return Bod /= Null_Iir + and then Get_Subprogram_Specification (Bod) /= Spec; + end Is_Second_Subprogram_Specification; function Is_Same_Profile (L, R: Iir) return Boolean is @@ -570,14 +685,14 @@ package body Iirs_Utils is begin L_Kind := Get_Kind (L); if L_Kind = Iir_Kind_Non_Object_Alias_Declaration then - L1 := Get_Name (L); + L1 := Get_Named_Entity (Get_Name (L)); L_Kind := Get_Kind (L1); else L1 := L; end if; R_Kind := Get_Kind (R); if R_Kind = Iir_Kind_Non_Object_Alias_Declaration then - R1 := Get_Name (R); + R1 := Get_Named_Entity (Get_Name (R)); R_Kind := Get_Kind (R1); else R1 := R; @@ -652,6 +767,25 @@ package body Iirs_Utils is end case; end Get_Block_From_Block_Specification; + function Get_Entity (Decl : Iir) return Iir + is + Name : constant Iir := Get_Entity_Name (Decl); + Res : constant Iir := Get_Named_Entity (Name); + begin + pragma Assert (Res = Null_Iir + or else Get_Kind (Res) = Iir_Kind_Entity_Declaration); + return Res; + end Get_Entity; + + function Get_Configuration (Aspect : Iir) return Iir + is + Name : constant Iir := Get_Configuration_Name (Aspect); + Res : constant Iir := Get_Named_Entity (Name); + begin + pragma Assert (Get_Kind (Res) = Iir_Kind_Configuration_Declaration); + return Res; + end Get_Configuration; + function Get_Entity_Identifier_Of_Architecture (Arch : Iir) return Name_Id is Name : constant Iir := Get_Entity_Name (Arch); @@ -747,7 +881,8 @@ package body Iirs_Utils is Set_Location (Res, Loc); Base_Type := Get_Base_Type (Arr_Type); Set_Base_Type (Res, Base_Type); - Set_Element_Subtype (Res, Get_Element_Subtype (Base_Type)); + Set_Element_Subtype_Indication + (Res, Get_Element_Subtype_Indication (Base_Type)); if Get_Kind (Arr_Type) /= Iir_Kind_Array_Type_Definition then Set_Resolution_Function (Res, Get_Resolution_Function (Arr_Type)); end if; @@ -811,21 +946,6 @@ package body Iirs_Utils is return Res; end Create_Error_Type; - function Get_Associated_Formal (Assoc : Iir) return Iir - is - Formal : Iir; - begin - Formal := Get_Formal (Assoc); - case Get_Kind (Formal) is - when Iir_Kind_Simple_Name - | Iir_Kind_Selected_Name => - Formal := Get_Named_Entity (Formal); - when others => - null; - end case; - return Get_Base_Name (Formal); - end Get_Associated_Formal; - -- Extract the entity from ASPECT. -- Note: if ASPECT is a component declaration, returns ASPECT. function Get_Entity_From_Entity_Aspect (Aspect : Iir) return Iir @@ -833,6 +953,11 @@ package body Iirs_Utils is Inst : Iir; begin case Get_Kind (Aspect) is + when Iir_Kinds_Denoting_Name => + -- A component declaration. + Inst := Get_Named_Entity (Aspect); + pragma Assert (Get_Kind (Inst) = Iir_Kind_Component_Declaration); + return Inst; when Iir_Kind_Component_Declaration => return Aspect; when Iir_Kind_Entity_Aspect_Entity => @@ -847,43 +972,22 @@ package body Iirs_Utils is end case; end Get_Entity_From_Entity_Aspect; - function Get_Physical_Literal_Value (Lit : Iir) return Iir_Int64 - is - begin - case Get_Kind (Lit) is - when Iir_Kind_Physical_Int_Literal => - return Get_Value (Lit) - * Get_Value (Get_Physical_Unit_Value (Get_Unit_Name (Lit))); - when Iir_Kind_Unit_Declaration => - return Get_Value (Get_Physical_Unit_Value (Lit)); - when Iir_Kind_Physical_Fp_Literal => - return Iir_Int64 - (Get_Fp_Value (Lit) - * Iir_Fp64 (Get_Value (Get_Physical_Unit_Value - (Get_Unit_Name (Lit))))); - when others => - Error_Kind ("get_physical_literal_value", Lit); - end case; - end Get_Physical_Literal_Value; - function Is_Signal_Object (Name : Iir) return Boolean is Adecl: Iir; begin - Adecl := Get_Base_Name (Name); - loop - case Get_Kind (Adecl) is - when Iir_Kind_Signal_Declaration - | Iir_Kind_Signal_Interface_Declaration - | Iir_Kind_Guard_Signal_Declaration - | Iir_Kinds_Signal_Attribute => - return True; - when Iir_Kind_Object_Alias_Declaration => - Adecl := Get_Base_Name (Get_Name (Adecl)); - when others => - return False; - end case; - end loop; + Adecl := Get_Object_Prefix (Name, True); + case Get_Kind (Adecl) is + when Iir_Kind_Signal_Declaration + | Iir_Kind_Signal_Interface_Declaration + | Iir_Kind_Guard_Signal_Declaration + | Iir_Kinds_Signal_Attribute => + return True; + when Iir_Kind_Object_Alias_Declaration => + raise Internal_Error; + when others => + return False; + end case; end Is_Signal_Object; -- LRM08 4.7 Package declarations @@ -920,4 +1024,9 @@ package body Iirs_Utils is begin return Iir (PSL.Nodes.Get_HDL_Node (N)); end Get_HDL_Node; + + procedure Set_HDL_Node (N : PSL_Node; Expr : Iir) is + begin + PSL.Nodes.Set_HDL_Node (N, PSL.Nodes.HDL_Node (Expr)); + end Set_HDL_Node; end Iirs_Utils; diff --git a/iirs_utils.ads b/iirs_utils.ads index fb3e1b45f..98b6b9e7f 100644 --- a/iirs_utils.ads +++ b/iirs_utils.ads @@ -19,8 +19,8 @@ with Types; use Types; with Iirs; use Iirs; package Iirs_Utils is - -- Transform the current token into an iir literal. - -- The current token must be either a character, a string or an identifier. + -- Transform the current token into an iir literal. + -- The current token must be either a character, a string or an identifier. function Current_Text return Iir; -- Get identifier of NODE as a string. @@ -31,6 +31,10 @@ package Iirs_Utils is function Get_String_Fat_Acc (Str : Iir) return String_Fat_Acc; pragma Inline (Get_String_Fat_Acc); + -- Return True iff N is an error node. + function Is_Error (N : Iir) return Boolean; + pragma Inline (Is_Error); + -- Find LIT in the list of identifiers or characters LIST. -- Return the literal (whose name is LIT) or null_iir if not found. function Find_Name_In_Chain (Chain: Iir; Lit: Name_Id) return Iir; @@ -46,10 +50,18 @@ package Iirs_Utils is -- See LRM §8.1 function Get_Longuest_Static_Prefix (Expr: Iir) return Iir; - -- Get the prefix of DECL, ie: - -- {signal, variable, constant}{interface_declaration, declaration}, or - -- DECL itself, if it is not an object. - function Get_Object_Prefix (Decl: Iir) return Iir; + -- Get the prefix of NAME, ie the declaration at the base of NAME. + -- Return NAME itself if NAME is not an object or a subelement of + -- an object. If WITH_ALIAS is true, continue with the alias name when an + -- alias is found, else return the alias. + -- FIXME: clarify when NAME is returned. + function Get_Object_Prefix (Name: Iir; With_Alias : Boolean := True) + return Iir; + + + -- Get the interface associated by the association ASSOC. This is always + -- an interface, even if the formal is a name. + function Get_Association_Interface (Assoc : Iir) return Iir; -- Make TARGETS depends on UNIT. -- UNIT must be either a design unit or a entity_aspect_entity. @@ -88,9 +100,49 @@ package Iirs_Utils is -- Return TRUE iff DEF is a fully constrained type (or subtype) definition. function Is_Fully_Constrained_Type (Def : Iir) return Boolean; - -- Return the type of a type name (type declaration, subtype declaration or - -- base attribute). - function Get_Type_Of_Type_Mark (Mark : Iir) return Iir; + -- Return the type definition/subtype indication of NAME if NAME denotes + -- a type or subtype name. Otherwise, return Null_Iir; + function Is_Type_Name (Name : Iir) return Iir; + + -- Return TRUE iff SPEC is the subprogram specification of a subprogram + -- body which was previously declared. In that case, the only use of SPEC + -- is to match the body with its declaration. + function Is_Second_Subprogram_Specification (Spec : Iir) return Boolean; + + -- If NAME is a simple or an expanded name, return the denoted declaration. + -- Otherwise, return NAME. + function Strip_Denoting_Name (Name : Iir) return Iir; + + -- Build a simple name node whose named entity is REF and location LOC. + function Build_Simple_Name (Ref : Iir; Loc : Location_Type) return Iir; + function Build_Simple_Name (Ref : Iir; Loc : Iir) return Iir; + + -- Return a simple name for the primary unit of physical type PHYSICAL_DEF. + -- This is the artificial unit name for the value of the primary unit, thus + -- its location is the location of the primary unit. Used mainly to build + -- evaluated literals. + function Get_Primary_Unit_Name (Physical_Def : Iir) return Iir; + + -- Get the type of any node representing a subtype indication. This simply + -- skip over denoting names. + function Get_Type_Of_Subtype_Indication (Ind : Iir) return Iir; + + -- Get the type of an index_subtype_definition or of a discrete_range from + -- an index_constraint. + function Get_Index_Type (Index_Type : Iir) return Iir + renames Get_Type_Of_Subtype_Indication; + + -- Return the IDX-th index type for index subtype definition list or + -- index_constraint INDEXES. Return Null_Iir if IDX is out of dimension + -- bounds, so that this function can be used to iterator over indexes of + -- a type (or subtype). Note that IDX starts at 0. + function Get_Index_Type (Indexes : Iir_List; Idx : Natural) return Iir; + + -- Likewise but for array type or subtype ARRAY_TYPE. + function Get_Index_Type (Array_Type : Iir; Idx : Natural) return Iir; + + -- Return the element type of array type or array subtype DEF. + function Get_Element_Subtype (Def : Iir) return Iir; -- Return true iff L and R have the same profile. -- L and R must be subprograms specification (or spec_body). @@ -101,6 +153,14 @@ package Iirs_Utils is function Get_Block_From_Block_Specification (Block_Spec : Iir) return Iir; + -- Wrapper around Get_Entity_Name: return the entity declaration of the + -- entity name of DECL. + function Get_Entity (Decl : Iir) return Iir; + + -- Wrapper around get_Configuration_Name: return the configuration + -- declaration of ASPECT. + function Get_Configuration (Aspect : Iir) return Iir; + -- Return the identifier of the entity for architecture ARCH. function Get_Entity_Identifier_Of_Architecture (Arch : Iir) return Name_Id; @@ -143,20 +203,11 @@ package Iirs_Utils is -- Create an error node for node ORIG, which is supposed to be a type. function Create_Error_Type (Orig : Iir) return Iir; - -- Get the base name of the formal of an association. - function Get_Associated_Formal (Assoc : Iir) return Iir; - -- Extract the entity from ASPECT. -- Note: if ASPECT is a component declaration, returns ASPECT. -- if ASPECT is open, return Null_Iir; function Get_Entity_From_Entity_Aspect (Aspect : Iir) return Iir; - -- Get the value of any physical literals. - -- A physical literal can be either an int_literal, and fp_literal or - -- a unit_declaration. - -- See also Evaluation.Get_Physical_Value. - function Get_Physical_Literal_Value (Lit : Iir) return Iir_Int64; - -- Definitions from LRM08 4.7 Package declarations. -- PKG must denote a package declaration. function Is_Simple_Package (Pkg : Iir) return Boolean; @@ -166,6 +217,7 @@ package Iirs_Utils is -- Return TRUE if the base name of NAME is a signal object. function Is_Signal_Object (Name: Iir) return Boolean; - -- IIR wrapper around Get_HDL_Node. + -- IIR wrapper around Get_HDL_Node/Set_HDL_Node. function Get_HDL_Node (N : PSL_Node) return Iir; + procedure Set_HDL_Node (N : PSL_Node; Expr : Iir); end Iirs_Utils; diff --git a/libraries.adb b/libraries.adb index d99b4d268..3120d72d1 100644 --- a/libraries.adb +++ b/libraries.adb @@ -836,7 +836,8 @@ package body Libraries is Last_Design_File : Iir_Design_File := Null_Iir; -- Add or replace a design unit in the working library. - procedure Add_Design_Unit_Into_Library (Unit : Iir_Design_Unit) + procedure Add_Design_Unit_Into_Library + (Unit : in Iir_Design_Unit; Keep_Obsolete : Boolean := False) is Design_File: Iir_Design_File; Design_Unit, Prev_Design_Unit : Iir_Design_Unit; @@ -852,11 +853,11 @@ package body Libraries is File_Name : Name_Id; Dir_Name : Name_Id; begin + -- As specified, the Chain must be not set. pragma Assert (Get_Chain (Unit) = Null_Iir); - if Get_Date_State (Unit) /= Date_Extern then - raise Internal_Error; - end if; + -- The unit must not be in the library. + pragma Assert (Get_Date_State (Unit) = Date_Extern); -- Mark this design unit as being loaded. New_Library_Unit := Get_Library_Unit (Unit); @@ -921,11 +922,20 @@ package body Libraries is end if; -- Remove DESIGN_UNIT from the design_file. - Remove_Unit_From_File (Design_Unit, Design_File); + -- If KEEP_OBSOLETE is True, units that are obsoleted by units + -- in the same design file are kept. This allows to process + -- (pretty print, xrefs, ...) all units of a design file. + -- But still remove units that are replaced (if a file was + -- already in the library). + if not Keep_Obsolete + or else Get_Date_State (Design_Unit) = Date_Disk + then + Remove_Unit_From_File (Design_Unit, Design_File); + end if; end; - -- UNIT *must* replace library_unit if they don't belong - -- to the same file. + -- UNIT *must* replace library_unit if they don't belong + -- to the same file. if Get_Design_File_Filename (Design_File) = File_Name and then Get_Design_File_Directory (Design_File) = Dir_Name then @@ -943,7 +953,9 @@ package body Libraries is end if; else -- Free the stub. - Free_Design_Unit (Design_Unit); + if not Keep_Obsolete then + Free_Design_Unit (Design_Unit); + end if; end if; -- Note: the current design unit should not be freed if @@ -965,9 +977,10 @@ package body Libraries is end if; end if; exit; + else + Prev_Design_Unit := Design_Unit; + Design_Unit := Get_Hash_Chain (Design_Unit); end if; - Prev_Design_Unit := Design_Unit; - Design_Unit := Get_Hash_Chain (Design_Unit); end loop; -- Try to find the design file in the library. @@ -1068,7 +1081,7 @@ package body Libraries is while Unit /= Null_Iir loop Next_Unit := Get_Chain (Unit); Set_Chain (Unit, Null_Iir); - Libraries.Add_Design_Unit_Into_Library (Unit); + Libraries.Add_Design_Unit_Into_Library (Unit, True); Unit := Next_Unit; end loop; if First_Unit /= Null_Iir then diff --git a/libraries.ads b/libraries.ads index 852a4ef6a..3a89c473b 100644 --- a/libraries.ads +++ b/libraries.ads @@ -149,7 +149,12 @@ package Libraries is -- -- Units are always appended to the design_file. Therefore, the order is -- kept. - procedure Add_Design_Unit_Into_Library (Unit : in Iir_Design_Unit); + -- + -- If KEEP_OBSOLETE is True, obsoleted units are kept in the library. + -- This is used when a whole design file has to be added in the library and + -- then processed (without that feature, redefined units would disappear). + procedure Add_Design_Unit_Into_Library + (Unit : in Iir_Design_Unit; Keep_Obsolete : Boolean := False); -- Put all design_units of FILE into the work library, by calling -- Add_Design_Unit_Into_Library. diff --git a/libraries/Makefile.inc b/libraries/Makefile.inc index a6dfe61a9..92283517a 100644 --- a/libraries/Makefile.inc +++ b/libraries/Makefile.inc @@ -51,16 +51,15 @@ ieee2008/std_logic_1164.vhdl ieee2008/std_logic_1164-body.vhdl \ ieee2008/std_logic_textio.vhdl \ ieee2008/math_real.vhdl ieee2008/math_real-body.vhdl \ ieee2008/math_complex.vhdl ieee2008/math_complex-body.vhdl \ -ieee2008/numeric_bit.vhdl \ +ieee2008/numeric_bit.vhdl ieee2008/numeric_bit-body.vhdl \ ieee2008/numeric_bit_unsigned.vhdl ieee2008/numeric_bit_unsigned-body.vhdl \ ieee2008/numeric_std.vhdl \ ieee2008/numeric_std-body.vhdl \ ieee2008/numeric_std_unsigned.vhdl ieee2008/numeric_std_unsigned-body.vhdl \ ieee2008/fixed_float_types.vhdl \ ieee2008/fixed_generic_pkg.vhdl \ -ieee2008/fixed_pkg.vhdl \ -ieee2008/numeric_bit-body.vhdl \ ieee2008/fixed_generic_pkg-body.vhdl +# ieee2008/fixed_pkg.vhdl \ #ieee2008/float_generic_pkg.vhdl #ieee2008/float_generic_pkg-body.vhdl # diff --git a/libraries/std/textio_body.vhdl b/libraries/std/textio_body.vhdl index b402174a4..5d148cef4 100644 --- a/libraries/std/textio_body.vhdl +++ b/libraries/std/textio_body.vhdl @@ -83,7 +83,7 @@ package body textio is end case; end is_Whitespace; - procedure writeline (f: out text; l: inout line) is --V87 + procedure writeline (variable f: out text; l: inout line) is --V87 procedure writeline (file f: text; l: inout line) is --V93 begin if l = null then @@ -69,6 +69,7 @@ package body Parse is function Parse_Aggregate return Iir; function Parse_Signature return Iir_Signature; procedure Parse_Declarative_Part (Parent : Iir); + function Parse_Tolerance_Aspect_Opt return Iir; Expect_Error: exception; @@ -171,6 +172,7 @@ package body Parse is Error_Msg_Parse ("""end"" must be followed by """ & Image (Tok) & """"); else + Set_End_Has_Reserved_Id (Decl, True); Scan; end if; Check_End_Name (Decl); @@ -271,11 +273,11 @@ package body Parse is -- If left is null_iir, the current token is used to create the left limit -- expression. -- - -- [§ 3.1] + -- [3.1] -- range ::= RANGE_attribute_name -- | simple_expression direction simple_expression - function Parse_Range_Expression - (Left: Iir; Discrete: Boolean := False) return Iir + function Parse_Range_Expression (Left: Iir; Discrete: Boolean := False) + return Iir is Res : Iir; Left1: Iir; @@ -315,7 +317,9 @@ package body Parse is if Is_Range_Attribute_Name (Left1) then return Left1; end if; - if Discrete and then Get_Kind (Left1) in Iir_Kinds_Name then + if Discrete + and then Get_Kind (Left1) in Iir_Kinds_Denoting_Name + then return Left1; end if; Error_Msg_Parse ("'to' or 'downto' expected"); @@ -386,16 +390,10 @@ package body Parse is end case; end Parse_Range; - -- precond: RANGE + -- precond: next token (after RANGE) -- postcond: next token function Parse_Range_Constraint return Iir is begin - if Current_Token /= Tok_Range then - Error_Msg_Parse ("'range' expected"); - return Null_Iir; - end if; - Scan; - if Current_Token = Tok_Box then Error_Msg_Parse ("range constraint required"); Scan; @@ -405,6 +403,25 @@ package body Parse is return Parse_Range; end Parse_Range_Constraint; + -- precond: next token (after RANGE) + -- postcond: next token + function Parse_Range_Constraint_Of_Subtype_Indication + (Type_Mark : Iir; + Resolution_Function : Iir := Null_Iir) + return Iir + is + Def : Iir; + begin + Def := Create_Iir (Iir_Kind_Subtype_Definition); + Location_Copy (Def, Type_Mark); + Set_Subtype_Type_Mark (Def, Type_Mark); + Set_Range_Constraint (Def, Parse_Range_Constraint); + Set_Resolution_Function (Def, Resolution_Function); + Set_Tolerance (Def, Parse_Tolerance_Aspect_Opt); + + return Def; + end Parse_Range_Constraint_Of_Subtype_Indication; + -- precond: next token -- postcond: next token -- @@ -413,7 +430,6 @@ package body Parse is function Parse_Discrete_Range return Iir is Left: Iir; - Rng : Iir; begin Left := Parse_Simple_Expression; @@ -422,15 +438,9 @@ package body Parse is | Tok_Downto => return Parse_Range_Right (Left); when Tok_Range => - -- FIXME: create a subtype indication. - Rng := Parse_Range_Constraint; - if Rng = Null_Iir then - return Left; - end if; - Set_Type (Rng, Left); - return Rng; + return Parse_Subtype_Indication (Left); when others => - -- Assume a discrete subtype indication. + -- Either a /range/_attribute_name or a type_mark. return Left; end case; end Parse_Discrete_Range; @@ -807,7 +817,7 @@ package body Parse is Set_Identifier (Res, Current_Identifier); Set_Location (Res); if Get_Kind (Prefix) = Iir_Kind_Signature then - Set_Signature (Res, Prefix); + Set_Attribute_Signature (Res, Prefix); Set_Prefix (Res, Get_Prefix (Prefix)); else Set_Prefix (Res, Prefix); @@ -887,6 +897,18 @@ package body Parse is return Parse_Name_Suffix (Res, Allow_Indexes); end Parse_Name; + -- Emit an error message if MARK doesn't have the form of a type mark. + procedure Check_Type_Mark (Mark : Iir) is + begin + case Get_Kind (Mark) is + when Iir_Kind_Simple_Name + | Iir_Kind_Selected_Name => + null; + when others => + Error_Msg_Parse ("type mark must be a name of a type", Mark); + end case; + end Check_Type_Mark; + -- precond : next token -- postcond: next token -- @@ -900,6 +922,7 @@ package body Parse is pragma Unreferenced (Old); begin Res := Parse_Name (Allow_Indexes => False); + Check_Type_Mark (Res); if Check_Paren and then Current_Token = Tok_Left_Paren then Error_Msg_Parse ("index constraint not allowed here"); Old := Parse_Name_Suffix (Res, True); @@ -956,16 +979,19 @@ package body Parse is Interface_Type: Iir; Signal_Kind: Iir_Signal_Kind; Default_Value: Iir; - Proxy : Iir_Proxy; Lexical_Layout : Iir_Lexical_Layout_Type; Prev_Loc : Location_Type; begin Expect (Tok_Left_Paren); + Res := Null_Iir; Last := Null_Iir; loop Prev_Loc := Get_Token_Location; + + -- Skip '(' or ';' Scan; + case Current_Token is when Tok_Identifier => Inter := Create_Iir (Default); @@ -1002,6 +1028,8 @@ package body Parse is else Is_Default := False; Lexical_Layout := Iir_Lexical_Has_Class; + + -- Skip 'signal', 'variable', 'constant' or 'file'. Scan; end if; @@ -1021,15 +1049,22 @@ package body Parse is end if; Last := Inter; + -- Skip identifier Scan; + exit when Current_Token = Tok_Colon; Expect (Tok_Comma, "',' or ':' expected after identifier"); + + -- Skip ',' Scan; + Inter := Create_Iir (Get_Kind (Inter)); end loop; Expect (Tok_Colon, "':' must follow the interface element identifier"); + + -- Skip ':' Scan; -- LRM93 2.1.1 @@ -1069,6 +1104,7 @@ package body Parse is end; end if; + -- Update lexical layout if mode is present. case Current_Token is when Tok_In | Tok_Out @@ -1080,6 +1116,7 @@ package body Parse is null; end case; + -- Parse mode (and handle default mode). case Get_Kind (Inter) is when Iir_Kind_File_Interface_Declaration => if Parse_Mode (Iir_Unknown_Mode) /= Iir_Unknown_Mode then @@ -1104,6 +1141,8 @@ package body Parse is end case; Interface_Type := Parse_Subtype_Indication; + + -- Signal kind (but only for signal). if Get_Kind (Inter) = Iir_Kind_Signal_Interface_Declaration then Signal_Kind := Parse_Signal_Kind; else @@ -1115,7 +1154,10 @@ package body Parse is Error_Msg_Parse ("default expression not allowed for an interface file"); end if; + + -- Skip ':=' Scan; + Default_Value := Parse_Expression; else Default_Value := Null_Iir; @@ -1132,14 +1174,10 @@ package body Parse is Set_Lexical_Layout (Inter, Lexical_Layout); end if; if Inter = First then - Set_Type (Inter, Interface_Type); + Set_Subtype_Indication (Inter, Interface_Type); if Get_Kind (Inter) /= Iir_Kind_File_Interface_Declaration then Set_Default_Value (Inter, Default_Value); end if; - else - Proxy := Create_Iir (Iir_Kind_Proxy); - Set_Proxy (Proxy, First); - Set_Type (Inter, Proxy); end if; if Get_Kind (Inter) = Iir_Kind_Signal_Interface_Declaration then Set_Signal_Kind (Inter, Signal_Kind); @@ -1148,10 +1186,14 @@ package body Parse is end loop; exit when Current_Token /= Tok_Semi_Colon; end loop; + if Current_Token /= Tok_Right_Paren then Error_Msg_Parse ("')' expected at end of interface list"); end if; + + -- Skip ')' Scan; + return Res; end Parse_Interface_Chain; @@ -1365,46 +1407,55 @@ package body Parse is Loc : Location_Type; Def : Iir; Type_Mark : Iir; - Rng : Iir; begin Loc := Get_Token_Location; + -- Skip 'array', scan '(' Scan_Expect (Tok_Left_Paren); Scan; + First := True; Index_List := Create_Iir_List; loop + -- The accepted syntax can be one of: + -- * index_subtype_definition, which is: + -- * type_mark RANGE <> + -- * discrete_range, which is either: + -- * /discrete/_subtype_indication + -- * [ resolution_indication ] type_mark [ range_constraint ] + -- * range_constraint ::= RANGE range + -- * range + -- * /range/_attribute_name + -- * simple_expression direction simple_expression + + -- Parse a simple expression (for the range), which can also parse a + -- name. Type_Mark := Parse_Simple_Expression; + case Current_Token is when Tok_Range => - -- Type_Mark is a name... + -- Skip 'range' Scan; + if Current_Token = Tok_Box then - -- This is an index_subtype_definition. + -- Parsed 'RANGE <>': this is an index_subtype_definition. Index_Constrained := False; Scan; Def := Type_Mark; else + -- This is a /discrete/_subtype_indication Index_Constrained := True; - Rng := Parse_Range; - -- FIXME: create a subtype_definition ? - if Rng /= Null_Iir then - Set_Type (Rng, Type_Mark); - Def := Rng; - else - Def := Type_Mark; - end if; + Def := + Parse_Range_Constraint_Of_Subtype_Indication (Type_Mark); end if; when Tok_To | Tok_Downto => + -- A range Index_Constrained := True; Def := Parse_Range_Right (Type_Mark); --- Def := Create_Iir (Iir_Kind_Subtype_Definition); --- Location_Copy (Def, Type_Mark); --- Set_Type_Mark (Def, Type_Mark); --- Set_Range_Constraint (Def, Rng); when others => + -- For a /range/_attribute_name Index_Constrained := True; Def := Type_Mark; end case; @@ -1432,17 +1483,19 @@ package body Parse is Set_Location (Res_Type, Loc); Set_Index_Subtype_List (Res_Type, Index_List); + -- Skip ')' and 'of' Expect (Tok_Right_Paren); Scan_Expect (Tok_Of); Scan; - Set_Element_Subtype (Res_Type, Parse_Subtype_Indication); + + Set_Element_Subtype_Indication (Res_Type, Parse_Subtype_Indication); return Res_Type; end Parse_Array_Definition; -- precond : UNITS -- postcond: next token -- - -- [ §3.1.3 ] + -- [ LRM93 3.1.3 ] -- physical_type_definition ::= -- range_constraint -- UNITS @@ -1450,10 +1503,10 @@ package body Parse is -- { secondary_unit_declaration } -- END UNITS [ PHYSICAL_TYPE_simple_name ] -- - -- [ §3.1.3 ] + -- [ LRM93 3.1.3 ] -- base_unit_declaration ::= identifier ; -- - -- [ §3.1.3 ] + -- [ LRM93 3.1.3 ] -- secondary_unit_declaration ::= identifier = physical_literal ; function Parse_Physical_Type_Definition return Iir_Physical_Type_Definition @@ -1467,7 +1520,7 @@ package body Parse is Res := Create_Iir (Iir_Kind_Physical_Type_Definition); Set_Location (Res); - -- Eat 'units' + -- Skip 'units' Expect (Tok_Units); Scan; @@ -1490,22 +1543,37 @@ package body Parse is Unit := Create_Iir (Iir_Kind_Unit_Declaration); Set_Location (Unit); Set_Identifier (Unit, Current_Identifier); + + -- Skip identifier. Scan_Expect (Tok_Equal); + + -- Skip '='. Scan; + Multiplier := Parse_Primary; Set_Physical_Literal (Unit, Multiplier); case Get_Kind (Multiplier) is when Iir_Kind_Simple_Name + | Iir_Kind_Selected_Name | Iir_Kind_Physical_Int_Literal => null; + when Iir_Kind_Physical_Fp_Literal => + Error_Msg_Parse + ("secondary units may only be defined with integer literals"); when others => Error_Msg_Parse ("a physical literal is expected here"); end case; Append (Last, Res, Unit); Scan_Semi_Colon ("secondary unit"); end loop; + + -- Skip 'end'. Scan; + Expect (Tok_Units); + Set_End_Has_Reserved_Id (Res, True); + + -- Skip 'units'. Scan; return Res; end Parse_Physical_Type_Definition; @@ -1513,7 +1581,7 @@ package body Parse is -- precond : RECORD -- postcond: next token -- - -- [ §3.2.2 ] + -- [ LRM93 3.2.2 ] -- record_type_definition ::= -- RECORD -- element_declaration @@ -1524,7 +1592,7 @@ package body Parse is -- identifier_list : element_subtype_definition -- -- element_subtype_definition ::= subtype_indication - function Parse_Record_Definition return Iir_Record_Type_Definition + function Parse_Record_Type_Definition return Iir_Record_Type_Definition is Res: Iir_Record_Type_Definition; El_List : Iir_List; @@ -1537,7 +1605,10 @@ package body Parse is Set_Location (Res); El_List := Create_Iir_List; Set_Elements_Declaration_List (Res, El_List); + + -- Skip 'record' Scan; + Pos := 0; First := Null_Iir; loop @@ -1557,43 +1628,66 @@ package body Parse is if First = Null_Iir then First := El; end if; + + -- Skip identifier Scan; + exit when Current_Token /= Tok_Comma; + + Set_Has_Identifier_List (El, True); + + -- Skip ',' Scan; end loop; + + -- Scan ':'. Expect (Tok_Colon); Scan; + + -- Parse element subtype indication. Subtype_Indication := Parse_Subtype_Indication; - Set_Type (First, Subtype_Indication); + Set_Subtype_Indication (First, Subtype_Indication); + First := Null_Iir; Scan_Semi_Colon ("element declaration"); exit when Current_Token = Tok_End; end loop; + + -- Skip 'end' Scan_Expect (Tok_Record); + Set_End_Has_Reserved_Id (Res, True); + + -- Skip 'record' Scan; + return Res; - end Parse_Record_Definition; + end Parse_Record_Type_Definition; -- precond : ACCESS -- postcond: ? -- - -- [§3.3] + -- [ LRM93 3.3] -- access_type_definition ::= ACCESS subtype_indication. - function Parse_Access_Definition return Iir_Access_Type_Definition is + function Parse_Access_Type_Definition return Iir_Access_Type_Definition + is Res : Iir_Access_Type_Definition; begin Res := Create_Iir (Iir_Kind_Access_Type_Definition); Set_Location (Res); + + -- Skip 'access' Expect (Tok_Access); Scan; - Set_Designated_Type (Res, Parse_Subtype_Indication); + + Set_Designated_Subtype_Indication (Res, Parse_Subtype_Indication); + return Res; - end Parse_Access_Definition; + end Parse_Access_Type_Definition; -- precond : FILE - -- postcond: ??? + -- postcond: next token -- - -- [ §3.4 ] + -- [ LRM93 3.4 ] -- file_type_definition ::= FILE OF type_mark function Parse_File_Type_Definition return Iir_File_Type_Definition is @@ -1606,10 +1700,10 @@ package body Parse is Scan_Expect (Tok_Of); Scan; Type_Mark := Parse_Type_Mark (Check_Paren => True); - if Get_Kind (Type_Mark) not in Iir_Kinds_Name then + if Get_Kind (Type_Mark) not in Iir_Kinds_Denoting_Name then Error_Msg_Parse ("type mark expected"); else - Set_Type_Mark (Res, Type_Mark); + Set_File_Type_Mark (Res, Type_Mark); end if; return Res; end Parse_File_Type_Definition; @@ -1617,11 +1711,11 @@ package body Parse is -- precond : PROTECTED -- postcond: ';' -- - -- [ §3.5 ] + -- [ 3.5 ] -- protected_type_definition ::= protected_type_declaration -- | protected_type_body -- - -- [ §3.5.1 ] + -- [ 3.5.1 ] -- protected_type_declaration ::= PROTECTED -- protected_type_declarative_part -- END PROTECTED [ simple_name ] @@ -1634,7 +1728,7 @@ package body Parse is -- | attribute_specification -- | use_clause -- - -- [ §3.5.2 ] + -- [ 3.5.2 ] -- protected_type_body ::= PROTECTED BODY -- protected_type_body_declarative_part -- END PROTECTED BODY [ simple_name ] @@ -1680,6 +1774,7 @@ package body Parse is Expect (Tok_End); Scan_Expect (Tok_Protected); + Set_End_Has_Reserved_Id (Res, True); if Get_Kind (Res) = Iir_Kind_Protected_Type_Body then Scan_Expect (Tok_Body); end if; @@ -1721,9 +1816,7 @@ package body Parse is Decl : Iir; begin -- The current token must be type. - if Current_Token /= Tok_Type then - raise Program_Error; - end if; + pragma Assert (Current_Token = Tok_Type); -- Get the identifier Scan_Expect (Tok_Identifier, @@ -1731,7 +1824,9 @@ package body Parse is Loc := Get_Token_Location; Ident := Current_Identifier; + -- Skip identifier Scan; + if Current_Token = Tok_Semi_Colon then -- If there is a ';', this is an imcomplete type declaration. Invalidate_Current_Token; @@ -1751,17 +1846,24 @@ package body Parse is case Current_Token is when Tok_Left_Paren => - -- This is an enumeration. + -- This is an enumeration. Def := Parse_Enumeration_Type_Definition; Decl := Null_Iir; + when Tok_Range => - -- This is a range definition. + -- This is a range definition. Decl := Create_Iir (Iir_Kind_Anonymous_Type_Declaration); Set_Identifier (Decl, Ident); Set_Location (Decl, Loc); + + -- Skip 'range' + Scan; + Def := Parse_Range_Constraint; Set_Type_Definition (Decl, Def); + if Current_Token = Tok_Units then + -- A physical type definition. declare Unit_Def : Iir; begin @@ -1778,14 +1880,16 @@ package body Parse is end if; end; end if; + when Tok_Array => Def := Parse_Array_Definition; Decl := Null_Iir; + when Tok_Record => Decl := Create_Iir (Iir_Kind_Type_Declaration); Set_Identifier (Decl, Ident); Set_Location (Decl, Loc); - Def := Parse_Record_Definition; + Def := Parse_Record_Type_Definition; Set_Type_Definition (Decl, Def); if Current_Token = Tok_Identifier then if Flags.Vhdl_Std = Vhdl_87 then @@ -1793,12 +1897,15 @@ package body Parse is end if; Check_End_Name (Get_Identifier (Decl), Def); end if; + when Tok_Access => - Def := Parse_Access_Definition; + Def := Parse_Access_Type_Definition; Decl := Null_Iir; + when Tok_File => Def := Parse_File_Type_Definition; Decl := Null_Iir; + when Tok_Identifier => if Current_Identifier = Name_Protected then Error_Msg_Parse ("protected type not allowed in vhdl87/93"); @@ -1810,11 +1917,13 @@ package body Parse is Decl := Create_Iir (Iir_Kind_Type_Declaration); Eat_Tokens_Until_Semi_Colon; end if; + when Tok_Protected => if Flags.Vhdl_Std < Vhdl_00 then Error_Msg_Parse ("protected type not allowed in vhdl87/93"); end if; Decl := Parse_Protected_Type_Definition (Ident, Loc); + when others => Error_Msg_Parse ("type definition starting with a keyword such as RANGE, ARRAY"); @@ -1917,7 +2026,7 @@ package body Parse is else Def := Create_Iir (Iir_Kind_Array_Subtype_Definition); Set_Location (Def, Loc); - Set_Element_Subtype (Def, Res); + Set_Element_Subtype_Indication (Def, Res); end if; Expect (Tok_Right_Paren); Scan; @@ -1974,7 +2083,7 @@ package body Parse is Scan; if Current_Token = Tok_Left_Paren then - Set_Element_Subtype (Def, Parse_Element_Constraint); + Set_Element_Subtype_Indication (Def, Parse_Element_Constraint); end if; return Def; end Parse_Element_Constraint; @@ -1984,8 +2093,7 @@ package body Parse is -- -- [ LRM93 4.2 ] -- tolerance_aspect ::= TOLERANCE string_expression - function Parse_Tolerance_Aspect_Opt return Iir - is + function Parse_Tolerance_Aspect_Opt return Iir is begin if AMS_Vhdl and then Current_Token = Tok_Tolerance @@ -2026,6 +2134,7 @@ package body Parse is if Name /= Null_Iir then Type_Mark := Name; + Check_Type_Mark (Name); else if Current_Token = Tok_Left_Paren then if Vhdl_Std < Vhdl_08 then @@ -2038,7 +2147,7 @@ package body Parse is Error_Msg_Parse ("type mark expected in a subtype indication"); raise Parse_Error; end if; - Type_Mark := Parse_Name (Allow_Indexes => False); + Type_Mark := Parse_Type_Mark (Check_Paren => False); end if; if Current_Token = Tok_Identifier then @@ -2053,18 +2162,17 @@ package body Parse is when Tok_Left_Paren => -- element_constraint. Def := Parse_Element_Constraint; - Set_Type_Mark (Def, Type_Mark); + Set_Subtype_Type_Mark (Def, Type_Mark); Set_Resolution_Function (Def, Resolution_Function); Set_Tolerance (Def, Parse_Tolerance_Aspect_Opt); when Tok_Range => -- range_constraint. - Def := Create_Iir (Iir_Kind_Subtype_Definition); - Location_Copy (Def, Type_Mark); - Set_Type_Mark (Def, Type_Mark); - Set_Range_Constraint (Def, Parse_Range_Constraint); - Set_Resolution_Function (Def, Resolution_Function); - Set_Tolerance (Def, Parse_Tolerance_Aspect_Opt); + -- Skip 'range' + Scan; + + Def := Parse_Range_Constraint_Of_Subtype_Indication + (Type_Mark, Resolution_Function); when others => Tolerance := Parse_Tolerance_Aspect_Opt; @@ -2073,7 +2181,7 @@ package body Parse is then Def := Create_Iir (Iir_Kind_Subtype_Definition); Location_Copy (Def, Type_Mark); - Set_Type_Mark (Def, Type_Mark); + Set_Subtype_Type_Mark (Def, Type_Mark); Set_Resolution_Function (Def, Resolution_Function); Set_Tolerance (Def, Tolerance); else @@ -2088,7 +2196,8 @@ package body Parse is -- -- [ §4.2 ] -- subtype_declaration ::= SUBTYPE identifier IS subtype_indication ; - function Parse_Subtype_Declaration return Iir_Subtype_Declaration is + function Parse_Subtype_Declaration return Iir_Subtype_Declaration + is Decl: Iir_Subtype_Declaration; Def: Iir; begin @@ -2101,7 +2210,7 @@ package body Parse is Scan_Expect (Tok_Is); Scan; Def := Parse_Subtype_Indication; - Set_Type (Decl, Def); + Set_Subtype_Indication (Decl, Def); Expect (Tok_Semi_Colon); return Decl; @@ -2256,7 +2365,6 @@ package body Parse is First, Last : Iir; Terminal : Iir; Subnature : Iir; - Proxy : Iir_Proxy; begin Sub_Chain_Init (First, Last); @@ -2284,7 +2392,6 @@ package body Parse is Scan; Subnature := Parse_Subnature_Indication; - Proxy := Null_Iir; Terminal := First; while Terminal /= Null_Iir loop -- Type definitions are factorized. This is OK, but not done by @@ -2292,11 +2399,7 @@ package body Parse is if Terminal = First then Set_Nature (Terminal, Subnature); else - -- FIXME: could avoid to create many proxies, by adding - -- a reference counter. - Proxy := Create_Iir (Iir_Kind_Proxy); - Set_Proxy (Proxy, First); - Set_Nature (Terminal, Proxy); + Set_Nature (Terminal, Null_Iir); end if; Terminal := Get_Chain (Terminal); end loop; @@ -2340,8 +2443,6 @@ package body Parse is Default_Value : Iir; Kind : Iir_Kind; Plus_Terminal : Iir; - Proxy : Iir; - First_Through : Iir; begin Sub_Chain_Init (First, Last); @@ -2418,9 +2519,7 @@ package body Parse is Sub_Chain_Append (First, Last, New_Object); if Object /= First then - Proxy := Create_Iir (Iir_Kind_Proxy); - Set_Proxy (Proxy, First); - Set_Plus_Terminal (New_Object, Proxy); + Set_Plus_Terminal (New_Object, Null_Iir); end if; New_Object := Get_Chain (Object); Free_Iir (Object); @@ -2447,10 +2546,7 @@ package body Parse is else Set_Identifier (Object, Get_Identifier (Plus_Terminal)); end if; - Proxy := Create_Iir (Iir_Kind_Proxy); - Set_Proxy (Proxy, First); - Set_Plus_Terminal (Object, Proxy); - First_Through := Object; + Set_Plus_Terminal (Object, Null_Iir); Free_Iir (Plus_Terminal); loop @@ -2469,9 +2565,7 @@ package body Parse is Set_Identifier (Object, Current_Identifier); Scan; end if; - Proxy := Create_Iir (Iir_Kind_Proxy); - Set_Proxy (Proxy, First_Through); - Set_Plus_Terminal (Object, Proxy); + Set_Plus_Terminal (Object, Null_Iir); end loop; @@ -2524,38 +2618,42 @@ package body Parse is -- KIND can be iir_kind_constant_declaration, iir_kind_file_declaration -- or iir_kind_variable_declaration -- - -- [ §4.3.1 ] + -- [ LRM93 4.3.1 ] -- object_declaration ::= constant_declaration -- | signal_declaration -- | variable_declaration -- | file_declaration -- - -- [ §4.3.1.1 ] + -- [ LRM93 4.3.1.1 ] -- constant_declaration ::= -- CONSTANT identifier_list : subtype_indication [ := expression ] -- - -- [ §4.3.1.4 ] + -- [ LRM87 4.3.2 ] + -- file_declaration ::= + -- FILE identifier : subtype_indication IS [ mode ] file_logical_name + -- + -- [ LRM93 4.3.1.4 ] -- file_declaration ::= -- FILE identifier_list : subtype_indication [ file_open_information ] -- - -- [ §4.3.1.4 ] + -- [ LRM93 4.3.1.4 ] -- file_open_information ::= -- [ OPEN FILE_OPEN_KIND_expression ] IS file_logical_name -- - -- [ §4.3.1.4 ] + -- [ LRM93 4.3.1.4 ] -- file_logical_name ::= STRING_expression -- - -- [ §4.3.1.3 ] + -- [ LRM93 4.3.1.3 ] -- variable_declaration ::= -- [ SHARED ] VARIABLE identifier_list : subtype_indication -- [ := expression ] -- - -- [ §4.3.1.2 ] + -- [ LRM93 4.3.1.2 ] -- signal_declaration ::= -- SIGNAL identifier_list : subtype_information [ signal_kind ] -- [ := expression ] -- - -- [ §4.3.1.2 ] + -- [ LRM93 4.3.1.2 ] -- signal_kind ::= REGISTER | BUS -- -- FIXME: file_open_information. @@ -2570,9 +2668,9 @@ package body Parse is Signal_Kind : Iir_Signal_Kind; Open_Kind : Iir; Logical_Name : Iir; - Proxy : Iir_Proxy; Kind: Iir_Kind; Shared : Boolean; + Has_Mode : Boolean; begin Sub_Chain_Init (First, Last); @@ -2622,6 +2720,7 @@ package body Parse is raise Expect_Error; end case; end if; + Set_Has_Identifier_List (Object, True); end loop; -- The colon was parsed. @@ -2637,7 +2736,10 @@ package body Parse is Error_Msg_Parse ("default expression not allowed for a file declaration"); end if; + + -- Skip ':='. Scan; + Default_Value := Parse_Expression; else Default_Value := Null_Iir; @@ -2655,18 +2757,16 @@ package body Parse is Open_Kind := Null_Iir; end if; - if Flags.Vhdl_Std = Vhdl_87 then - -- LRM 4.3.1.4 - -- The default mode is IN, if no mode is specified. - Mode := Iir_In_Mode; - else - -- GHDL: no mode for vhdl 93. - Mode := Iir_Unknown_Mode; - end if; + -- LRM 4.3.1.4 + -- The default mode is IN, if no mode is specified. + Mode := Iir_In_Mode; Logical_Name := Null_Iir; + Has_Mode := False; if Current_Token = Tok_Is then + -- Skip 'is'. Scan; + case Current_Token is when Tok_In | Tok_Out | Tok_Inout => if Flags.Vhdl_Std >= Vhdl_93 then @@ -2676,6 +2776,7 @@ package body Parse is if Mode = Iir_Inout_Mode then Error_Msg_Parse ("inout mode not allowed for file"); end if; + Has_Mode := True; when others => null; end case; @@ -2685,30 +2786,23 @@ package body Parse is end if; end if; - Proxy := Null_Iir; Object := First; while Object /= Null_Iir loop - -- Type definitions are factorized. This is OK, but not done by - -- sem. if Object = First then - Set_Type (Object, Object_Type); + Set_Subtype_Indication (Object, Object_Type); else - -- FIXME: could avoid to create many proxies, by adding - -- a reference counter. - Proxy := Create_Iir (Iir_Kind_Proxy); - Set_Proxy (Proxy, First); - Set_Type (Object, Proxy); + Set_Subtype_Indication (Object, Null_Iir); end if; if Kind = Iir_Kind_File_Declaration then Set_Mode (Object, Mode); Set_File_Open_Kind (Object, Open_Kind); Set_File_Logical_Name (Object, Logical_Name); - end if; - if Kind /= Iir_Kind_File_Declaration then + Set_Has_Mode (Object, Has_Mode); + else Set_Default_Value (Object, Default_Value); - end if; - if Kind = Iir_Kind_Signal_Declaration then - Set_Signal_Kind (Object, Signal_Kind); + if Kind = Iir_Kind_Signal_Declaration then + Set_Signal_Kind (Object, Signal_Kind); + end if; end if; Object := Get_Chain (Object); end loop; @@ -2740,6 +2834,7 @@ package body Parse is if Flags.Vhdl_Std = Vhdl_87 then Error_Msg_Parse ("""is"" keyword is not allowed here by vhdl 87"); end if; + Set_Has_Is (Component, True); Scan; end if; Parse_Generic_Port_Clauses (Component); @@ -2783,26 +2878,26 @@ package body Parse is -- precond : ALIAS -- postcond: a token -- - -- [ §4.3.3 ] + -- [ LRM93 4.3.3 ] -- alias_declaration ::= -- ALIAS alias_designator [ : subtype_indication ] -- IS name [ signature ] ; -- - -- [ §4.3.3 ] + -- [ LRM93 4.3.3 ] -- alias_designator ::= identifier | character_literal | operator_symbol -- - -- FIXME: signature + -- FIXME: signature is not part of the node. function Parse_Alias_Declaration return Iir is Res: Iir; Ident : Name_Id; begin + -- Eat 'alias'. + Scan; + Res := Create_Iir (Iir_Kind_Object_Alias_Declaration); Set_Location (Res); - -- accept ALIAS. - Scan; - case Current_Token is when Tok_Identifier => Ident := Current_Identifier; @@ -2815,12 +2910,14 @@ package body Parse is when others => Error_Msg_Parse ("alias designator expected"); end case; + + -- Eat identifier. Set_Identifier (Res, Ident); Scan; if Current_Token = Tok_Colon then Scan; - Set_Type (Res, Parse_Subtype_Indication); + Set_Subtype_Indication (Res, Parse_Subtype_Indication); end if; -- FIXME: nice message if token is ':=' ? @@ -3009,7 +3106,7 @@ package body Parse is Set_Location (Res, Loc); Set_Identifier (Res, Ident); Scan; - Set_Type (Res, Parse_Type_Mark (Check_Paren => True)); + Set_Type_Mark (Res, Parse_Type_Mark (Check_Paren => True)); Expect (Tok_Semi_Colon); return Res; end; @@ -3165,14 +3262,23 @@ package body Parse is begin Res := Create_Iir (Iir_Kind_Disconnection_Specification); Set_Location (Res); + + -- Skip 'disconnect' Expect (Tok_Disconnect); Scan; + Set_Signal_List (Res, Parse_Signal_List); + + -- Skip ':' Expect (Tok_Colon); Scan; - Set_Type (Res, Parse_Name (Allow_Indexes => False)); + + Set_Type_Mark (Res, Parse_Type_Mark (Check_Paren => True)); + + -- Skip 'after' Expect (Tok_After); Scan; + Set_Expression (Res, Parse_Expression); return Res; end Parse_Disconnection_Specification; @@ -3180,7 +3286,7 @@ package body Parse is -- precond : next token -- postcond: next token -- - -- [ §4 ] + -- [ LRM93 4 ] -- declaration ::= type_declaration -- | subtype_declaration -- | object_declaration @@ -3362,7 +3468,7 @@ package body Parse is Expect (Tok_Entity); Res := Create_Iir (Iir_Kind_Entity_Declaration); - -- Get identifier. + -- Get identifier. Scan_Expect (Tok_Identifier, "an identifier is expected after ""entity"""); Set_Identifier (Res, Current_Identifier); @@ -3399,7 +3505,7 @@ package body Parse is Set_Library_Unit (Unit, Res); end Parse_Entity_Declaration; - -- [ §7.3.2 ] + -- [ LRM93 7.3.2 ] -- choice ::= simple_expression -- | discrete_range -- | ELEMENT_simple_name @@ -3481,10 +3587,10 @@ package body Parse is -- -- This can be an expression or an aggregate. -- - -- [ §7.3.2 ] + -- [ LRM93 7.3.2 ] -- aggregate ::= ( element_association { , element_association } ) -- - -- [ §7.3.2 ] + -- [ LRM93 7.3.2 ] -- element_association ::= [ choices => ] expression function Parse_Aggregate return Iir is @@ -3514,15 +3620,21 @@ package body Parse is -- Eat ')'. Scan; - if Flag_Parse_Parenthesis then - -- Create a node for the parenthesis. - Res := Create_Iir (Iir_Kind_Parenthesis_Expression); - Set_Location (Res, Loc); - Set_Expression (Res, Expr); - return Res; - else + if Get_Kind (Expr) = Iir_Kind_Aggregate then + -- Parenthesis around aggregate is useless and change the + -- context for array aggregate. + Warning_Msg_Sem + ("suspicious parenthesis around aggregate", Expr); + elsif not Flag_Parse_Parenthesis then return Expr; end if; + + -- Create a node for the parenthesis. + Res := Create_Iir (Iir_Kind_Parenthesis_Expression); + Set_Location (Res, Loc); + Set_Expression (Res, Expr); + return Res; + when Tok_Semi_Colon => -- Surely a missing parenthesis. -- FIXME: in case of multiple missing parenthesises, several @@ -3577,17 +3689,19 @@ package body Parse is end Parse_Aggregate; -- precond : NEW - -- postcond: ??? + -- postcond: next token -- - -- [ §7.3.6] + -- [LRM93 7.3.6] -- allocator ::= NEW subtype_indication -- | NEW qualified_expression - function Parse_Allocator return Iir is + function Parse_Allocator return Iir + is Loc: Location_Type; Res : Iir; Expr: Iir; begin Loc := Get_Token_Location; + -- Accept 'new'. Scan; Expr := Parse_Name (Allow_Indexes => False); @@ -3595,11 +3709,13 @@ package body Parse is -- This is a subtype_indication. Res := Create_Iir (Iir_Kind_Allocator_By_Subtype); Expr := Parse_Subtype_Indication (Expr); + Set_Subtype_Indication (Res, Expr); else Res := Create_Iir (Iir_Kind_Allocator_By_Expression); + Set_Expression (Res, Expr); end if; + Set_Location (Res, Loc); - Set_Expression (Res, Expr); return Res; end Parse_Allocator; @@ -3643,12 +3759,14 @@ package body Parse is when Tok_Integer => Int := Current_Iir_Int64; Loc := Get_Token_Location; + + -- Skip integer Scan; + if Current_Token = Tok_Identifier then -- physical literal Res := Create_Iir (Iir_Kind_Physical_Int_Literal); - Set_Unit_Name (Res, Current_Text); - Scan; + Set_Unit_Name (Res, Parse_Name (Allow_Indexes => False)); else -- integer literal Res := Create_Iir (Iir_Kind_Integer_Literal); @@ -3656,15 +3774,18 @@ package body Parse is Set_Location (Res, Loc); Set_Value (Res, Int); return Res; + when Tok_Real => Fp := Current_Iir_Fp64; Loc := Get_Token_Location; + + -- Skip real Scan; + if Current_Token = Tok_Identifier then -- physical literal Res := Create_Iir (Iir_Kind_Physical_Fp_Literal); - Set_Unit_Name (Res, Current_Text); - Scan; + Set_Unit_Name (Res, Parse_Name (Allow_Indexes => False)); else -- real literal Res := Create_Iir (Iir_Kind_Floating_Point_Literal); @@ -3672,6 +3793,7 @@ package body Parse is Set_Location (Res, Loc); Set_Fp_Value (Res, Fp); return Res; + when Tok_Identifier => return Parse_Name (Allow_Indexes => True); when Tok_Character => @@ -4544,13 +4666,13 @@ package body Parse is Set_Procedure_Call (Res, Call); case Get_Kind (Name) is when Iir_Kind_Parenthesis_Name => - Set_Implementation (Call, Get_Prefix (Name)); + Set_Prefix (Call, Get_Prefix (Name)); Set_Parameter_Association_Chain (Call, Get_Association_Chain (Name)); Free_Iir (Name); when Iir_Kind_Simple_Name | Iir_Kind_Selected_Name => - Set_Implementation (Call, Name); + Set_Prefix (Call, Name); when Iir_Kind_Attribute_Name => Error_Msg_Parse ("attribute cannot be used as procedure call"); when others => @@ -4562,7 +4684,7 @@ package body Parse is -- precond : identifier -- postcond: next token -- - -- [ §8.9 ] + -- [ LRM93 8.9 ] -- parameter_specification ::= identifier IN discrete_range function Parse_Parameter_Specification (Parent : Iir) return Iir_Iterator_Declaration @@ -4572,12 +4694,17 @@ package body Parse is Decl := Create_Iir (Iir_Kind_Iterator_Declaration); Set_Location (Decl); Set_Parent (Decl, Parent); + Expect (Tok_Identifier); Set_Identifier (Decl, Current_Identifier); + + -- Skip identifier Scan_Expect (Tok_In); + + -- Skip 'in' Scan; - -- parse a range. - Set_Type (Decl, Parse_Range_Expression (Null_Iir, True)); + + Set_Discrete_Range (Decl, Parse_Discrete_Range); return Decl; end Parse_Parameter_Specification; @@ -4704,7 +4831,7 @@ package body Parse is & Image (Current_Token)); Stmt := Create_Iir (Iir_Kind_Procedure_Call_Statement); Call := Create_Iir (Iir_Kind_Procedure_Call); - Set_Implementation (Call, Target); + Set_Prefix (Call, Target); Set_Procedure_Call (Stmt, Call); Set_Location (Call); Eat_Tokens_Until_Semi_Colon; @@ -4779,29 +4906,43 @@ package body Parse is return First_Stmt; end if; end; + when Tok_Return => Stmt := Create_Iir (Iir_Kind_Return_Statement); Scan; if Current_Token /= Tok_Semi_Colon then Set_Expression (Stmt, Parse_Expression); end if; + when Tok_For => Stmt := Create_Iir (Iir_Kind_For_Loop_Statement); Set_Location (Stmt, Loc); Set_Label (Stmt, Label); + + -- Skip 'for' Scan; - Set_Iterator_Scheme + + Set_Parameter_Specification (Stmt, Parse_Parameter_Specification (Stmt)); + + -- Skip 'loop' Expect (Tok_Loop); Scan; + Set_Sequential_Statement_Chain (Stmt, Parse_Sequential_Statements (Stmt)); + + -- Skip 'end' Expect (Tok_End); Scan_Expect (Tok_Loop); + + -- Skip 'loop' Scan; + Check_End_Name (Stmt); -- A loop statement can have a label, even in vhdl87. Label := Null_Identifier; + when Tok_While | Tok_Loop => Stmt := Create_Iir (Iir_Kind_While_Loop_Statement); @@ -4821,6 +4962,7 @@ package body Parse is Check_End_Name (Stmt); -- A loop statement can have a label, even in vhdl87. Label := Null_Identifier; + when Tok_Next | Tok_Exit => if Current_Token = Tok_Next then @@ -4828,15 +4970,21 @@ package body Parse is else Stmt := Create_Iir (Iir_Kind_Exit_Statement); end if; + + -- Skip 'next' or 'exit'. Scan; + if Current_Token = Tok_Identifier then - Set_Loop (Stmt, Current_Text); - Scan; + Set_Loop_Label (Stmt, Parse_Name (Allow_Indexes => False)); end if; + if Current_Token = Tok_When then + -- Skip 'when'. Scan; + Set_Condition (Stmt, Parse_Expression); end if; + when Tok_Case => declare use Iir_Chains.Case_Statement_Alternative_Chain_Handling; @@ -4972,6 +5120,7 @@ package body Parse is Error_Msg_Parse ("'pure' and 'impure' are not allowed in vhdl 87"); end if; + Set_Has_Pure (Subprg, True); -- FIXME: what to do in case of error ?? -- Eat PURE or IMPURE. Scan; @@ -5015,11 +5164,17 @@ package body Parse is if Get_Kind (Subprg) = Iir_Kind_Procedure_Declaration then Error_Msg_Parse ("'return' not allowed for a procedure"); Error_Msg_Parse ("(remove return part or define a function)"); + + -- Skip 'return' Scan; + Old := Parse_Type_Mark; else + -- Skip 'return' Scan; - Set_Return_Type (Subprg, Parse_Type_Mark (Check_Paren => True)); + + Set_Return_Type_Mark + (Subprg, Parse_Type_Mark (Check_Paren => True)); end if; else if Get_Kind (Subprg) = Iir_Kind_Function_Declaration then @@ -5030,6 +5185,9 @@ package body Parse is if Current_Token = Tok_Semi_Colon then return Subprg; end if; + + -- The body. + Set_Has_Body (Subprg, True); if Get_Kind (Subprg) = Iir_Kind_Function_Declaration then Subprg_Body := Create_Iir (Iir_Kind_Function_Body); else @@ -5062,6 +5220,7 @@ package body Parse is if Get_Kind (Subprg) = Iir_Kind_Procedure_Declaration then Error_Msg_Parse ("'procedure' expected instead of 'function'"); end if; + Set_End_Has_Reserved_Id (Subprg_Body, True); Scan; when Tok_Procedure => if Flags.Vhdl_Std = Vhdl_87 then @@ -5070,6 +5229,7 @@ package body Parse is if Get_Kind (Subprg) = Iir_Kind_Function_Declaration then Error_Msg_Parse ("'function' expected instead of 'procedure'"); end if; + Set_End_Has_Reserved_Id (Subprg_Body, True); Scan; when others => null; @@ -5085,6 +5245,7 @@ package body Parse is ("mispelling, 'end """ & Image_Identifier (Subprg) & """;' expected"); end if; + Set_End_Has_Identifier (Subprg_Body, True); Scan; when others => null; @@ -5144,17 +5305,20 @@ package body Parse is if Flags.Vhdl_Std = Vhdl_87 then Error_Msg_Parse ("""is"" not allowed here by vhdl 87"); end if; + Set_Has_Is (Res, True); Scan; end if; -- declarative part. Parse_Declarative_Part (Res); + -- Skip 'begin'. Expect (Tok_Begin); Scan; Set_Sequential_Statement_Chain (Res, Parse_Sequential_Statements (Res)); + -- Skip 'end'. Expect (Tok_End); Scan; @@ -5165,6 +5329,10 @@ package body Parse is -- statement, the process must be a postponed process. Error_Msg_Parse ("process is not a postponed process"); end if; + + Set_End_Has_Postponed (Res, True); + + -- Skip 'postponed', Scan; end if; @@ -5350,7 +5518,7 @@ package body Parse is Res := Create_Iir (Iir_Kind_Entity_Aspect_Entity); Set_Location (Res); Scan; - Set_Entity (Res, Parse_Name (False)); + Set_Entity_Name (Res, Parse_Name (False)); if Current_Token = Tok_Left_Paren then Scan_Expect (Tok_Identifier); Set_Architecture (Res, Current_Text); @@ -5362,7 +5530,7 @@ package body Parse is Res := Create_Iir (Iir_Kind_Entity_Aspect_Configuration); Set_Location (Res); Scan_Expect (Tok_Identifier); - Set_Configuration (Res, Parse_Name (False)); + Set_Configuration_Name (Res, Parse_Name (False)); return Res; when others => raise Internal_Error; @@ -5486,7 +5654,7 @@ package body Parse is -- precond : IF or FOR -- postcond: ';' -- - -- [ §9.7 ] + -- [ LRM93 9.7 ] -- generate_statement ::= -- GENERATE_label : generation_scheme GENERATE -- [ { block_declarative_item } @@ -5494,7 +5662,7 @@ package body Parse is -- { concurrent_statement } -- END GENERATE [ GENERATE_label ] ; -- - -- [ §9.7 ] + -- [ LRM93 9.7 ] -- generation_scheme ::= -- FOR GENERATE_parameter_specification -- | IF condition @@ -5569,14 +5737,21 @@ package body Parse is end if; Parse_Declarative_Part (Res); Expect (Tok_Begin); + Set_Has_Begin (Res, True); Scan; when others => null; end case; Parse_Concurrent_Statements (Res); + Expect (Tok_End); + + -- Skip 'end' Scan_Expect (Tok_Generate); + Set_End_Has_Reserved_Id (Res, True); + + -- Skip 'generate' Scan; -- LRM93 9.7 @@ -5893,7 +6068,7 @@ package body Parse is -- precond : LIBRARY -- postcond: ; -- - -- [ §11.2 ] + -- [ LRM93 11.2 ] -- library_clause ::= LIBRARY logical_name_list function Parse_Library_Clause return Iir is @@ -5904,14 +6079,24 @@ package body Parse is Expect (Tok_Library); loop Library := Create_Iir (Iir_Kind_Library_Clause); + + -- Skip 'library' or ','. Scan_Expect (Tok_Identifier); + Set_Identifier (Library, Current_Identifier); Set_Location (Library); Sub_Chain_Append (First, Last, Library); + + -- Skip identifier. Scan; + exit when Current_Token = Tok_Semi_Colon; Expect (Tok_Comma); + + Set_Has_Identifier_List (Library, True); end loop; + + -- Skip ';'. Scan; return First; end Parse_Library_Clause; @@ -6071,7 +6256,7 @@ package body Parse is Res := Create_Iir (Iir_Kind_Entity_Aspect_Entity); Set_Location (Res); Scan_Expect (Tok_Identifier); - Set_Entity (Res, Parse_Name (False)); + Set_Entity_Name (Res, Parse_Name (False)); if Current_Token = Tok_Left_Paren then Scan_Expect (Tok_Identifier); Set_Architecture (Res, Current_Text); @@ -6082,7 +6267,7 @@ package body Parse is Res := Create_Iir (Iir_Kind_Entity_Aspect_Configuration); Set_Location (Res); Scan_Expect (Tok_Identifier); - Set_Configuration (Res, Parse_Name (False)); + Set_Configuration_Name (Res, Parse_Name (False)); when Tok_Open => Res := Create_Iir (Iir_Kind_Entity_Aspect_Open); Set_Location (Res); @@ -6362,14 +6547,14 @@ package body Parse is -- precond : CONFIGURATION -- postcond: ';' -- - -- [ §1.3 ] + -- [ LRM93 1.3 ] -- configuration_declaration ::= -- CONFIGURATION identifier OF ENTITY_name IS -- configuration_declarative_part -- block_configuration -- END [ CONFIGURATION ] [ CONFIGURATION_simple_name ] ; -- - -- [ §1.3 ] + -- [ LRM93 1.3 ] -- configuration_declarative_part ::= { configuration_declarative_item } procedure Parse_Configuration_Declaration (Unit : Iir_Design_Unit) is @@ -6384,25 +6569,37 @@ package body Parse is Scan_Expect (Tok_Identifier); Set_Identifier (Res, Current_Identifier); Set_Location (Res); + + -- Skip identifier. Scan_Expect (Tok_Of); + + -- Skip 'of'. Scan; + Set_Entity_Name (Res, Parse_Name (False)); - Expect (Tok_Is); + -- Skip 'is'. + Expect (Tok_Is); Scan; + Parse_Configuration_Declarative_Part (Res); Set_Block_Configuration (Res, Parse_Block_Configuration); Scan_Expect (Tok_End); Set_End_Location (Unit); - -- end was scanned. + + -- Skip 'end'. Scan; + if Current_Token = Tok_Configuration then if Flags.Vhdl_Std = Vhdl_87 then Error_Msg_Parse ("'configuration' keyword not allowed here by vhdl 87"); end if; + Set_End_Has_Reserved_Id (Res, True); + + -- Skip 'configuration'. Scan; end if; @@ -6444,12 +6641,13 @@ package body Parse is -- package_header -- LRM08 -- package_declarative_part -- END [ PACKAGE ] [ PACKAGE_simple_name ] ; - procedure Parse_Package_Declaration (Unit : Iir_Design_Unit; Id : Name_Id) + procedure Parse_Package_Declaration + (Unit : Iir_Design_Unit; Id : Name_Id; Loc : Location_Type) is Res: Iir_Package_Declaration; begin Res := Create_Iir (Iir_Kind_Package_Declaration); - Set_Location (Res); + Set_Location (Res, Loc); Set_Identifier (Res, Id); if Current_Token = Tok_Generic then @@ -6463,13 +6661,20 @@ package body Parse is Expect (Tok_End); Set_End_Location (Unit); + + -- Skip 'end' Scan; + if Current_Token = Tok_Package then if Flags.Vhdl_Std = Vhdl_87 then Error_Msg_Parse ("'package' keyword not allowed here by vhdl 87"); end if; + Set_End_Has_Reserved_Id (Res, True); + + -- Skip 'package'. Scan; end if; + Check_End_Name (Res); Expect (Tok_Semi_Colon); Set_Library_Unit (Unit, Res); @@ -6500,11 +6705,16 @@ package body Parse is Expect (Tok_End); Set_End_Location (Unit); + + -- Skip 'end' Scan; + if Current_Token = Tok_Package then if Flags.Vhdl_Std = Vhdl_87 then Error_Msg_Parse ("'package' keyword not allowed here by vhdl 87"); end if; + Set_End_Has_Reserved_Id (Res, True); + -- Skip 'package' Scan; @@ -6515,6 +6725,7 @@ package body Parse is Scan; end if; end if; + Check_End_Name (Res); Expect (Tok_Semi_Colon); Set_Library_Unit (Unit, Res); @@ -6559,7 +6770,7 @@ package body Parse is -- | package_instantiation_declaration procedure Parse_Package (Unit : Iir_Design_Unit) is - Loc : constant Location_Type := Get_Token_Location; + Loc : Location_Type; Id : Name_Id; begin -- Skip 'package' @@ -6573,8 +6784,12 @@ package body Parse is else Expect (Tok_Identifier); Id := Current_Identifier; + Loc := Get_Token_Location; + + -- Skip identifier. Scan; + -- Skip 'is'. Expect (Tok_Is); Scan; @@ -6585,7 +6800,7 @@ package body Parse is -- Note: there is no 'end' in instantiation. Set_End_Location (Unit, Get_Token_Location); else - Parse_Package_Declaration (Unit, Id); + Parse_Package_Declaration (Unit, Id, Loc); end if; end if; end Parse_Package; diff --git a/psl/psl-nodes.ads b/psl/psl-nodes.ads index 8802dce83..241091805 100644 --- a/psl/psl-nodes.ads +++ b/psl/psl-nodes.ads @@ -511,7 +511,7 @@ package PSL.Nodes is function Get_Decl (N : Node) return Node; procedure Set_Decl (N : Node; D : Node); - -- Field: Field1 + -- Field: Field1 (conv) function Get_HDL_Node (N : Node) return HDL_Node; procedure Set_HDL_Node (N : Node; H : HDL_Node); @@ -32,7 +32,6 @@ with Flags; use Flags; with Name_Table; with Str_Table; with Sem_Stmts; use Sem_Stmts; -with Sem_Types; use Sem_Types; with Iir_Chains; with Xrefs; use Xrefs; @@ -89,7 +88,7 @@ package body Sem is -- Return NULL_IIR in case of error (not found, bad library). function Sem_Entity_Name (Library_Unit : Iir) return Iir is - Name : constant Iir := Get_Entity_Name (Library_Unit); + Name : Iir; Library : Iir_Library_Declaration; Entity : Iir; begin @@ -97,6 +96,9 @@ package body Sem is Library := Get_Library (Get_Design_File (Get_Design_Unit (Library_Unit))); + -- Resolve the name. + + Name := Get_Entity_Name (Library_Unit); if Get_Kind (Name) = Iir_Kind_Simple_Name then -- LRM93 10.1 Declarative Region -- LRM08 12.1 Declarative Region @@ -116,37 +118,36 @@ package body Sem is end if; Entity := Get_Library_Unit (Entity); Set_Named_Entity (Name, Entity); + Xrefs.Xref_Ref (Name, Entity); else - Sem_Name (Name, False); + -- Certainly an expanded name. Use the standard name analysis. + Name := Sem_Denoting_Name (Name); + Set_Entity_Name (Library_Unit, Name); Entity := Get_Named_Entity (Name); - if Entity = Error_Mark then - return Null_Iir; - end if; end if; - Xrefs.Xref_Ref (Name, Entity); - - if Get_Kind (Entity) = Iir_Kind_Entity_Declaration then - -- LRM 1.2 Architecture bodies - -- For a given design entity, both the entity declaration and the - -- associated architecture body must reside in the same library. - - -- LRM 1.3 Configuration Declarations - -- For a configuration of a given design entity, both the - -- configuration declaration and the corresponding entity - -- declaration must reside in the same library. - if Get_Library (Get_Design_File (Get_Design_Unit (Entity))) /= Library - then - Error_Msg_Sem - (Disp_Node (Entity) & " does not reside in " - & Disp_Node (Library), Library_Unit); - return Null_Iir; - end if; - return Entity; - else - Error_Msg_Sem ("entity name expected, found " & Disp_Node (Entity), - Library_Unit); + + if Get_Kind (Entity) /= Iir_Kind_Entity_Declaration then + Error_Class_Match (Name, "entity"); return Null_Iir; end if; + + -- LRM 1.2 Architecture bodies + -- For a given design entity, both the entity declaration and the + -- associated architecture body must reside in the same library. + + -- LRM 1.3 Configuration Declarations + -- For a configuration of a given design entity, both the + -- configuration declaration and the corresponding entity + -- declaration must reside in the same library. + if Get_Library (Get_Design_File (Get_Design_Unit (Entity))) /= Library + then + Error_Msg_Sem + (Disp_Node (Entity) & " does not reside in " + & Disp_Node (Library), Library_Unit); + return Null_Iir; + end if; + + return Entity; end Sem_Entity_Name; -- LRM 1.2 Architecture bodies. @@ -168,9 +169,6 @@ package body Sem is -- GHDL: an architecture depends on its entity. Add_Dependence (Entity_Unit); - -- Transforms an identifier into an entity_decl. - Set_Entity (Arch, Entity_Library); - Add_Context_Clauses (Entity_Unit); Set_Is_Within_Flag (Arch, True); @@ -280,7 +278,7 @@ package body Sem is return False; end if; - Formal_Base := Get_Base_Name (Formal); + Formal_Base := Get_Object_Prefix (Formal); Actual_Base := Get_Object_Prefix (Actual); -- If the formal is of mode IN, then it has no driving value, and its @@ -442,6 +440,7 @@ package body Sem is Miss : Missing_Type; Inter : Iir; Formal : Iir; + Formal_Base : Iir; begin -- Note: CHECK_MATCH argument of sem_subprogram_arguments must be -- true if parent is a component instantiation. @@ -503,9 +502,11 @@ package body Sem is if Formal = Null_Iir then -- No formal: use association by position. Formal := Inter; + Formal_Base := Inter; Inter := Get_Chain (Inter); else Inter := Null_Iir; + Formal_Base := Get_Association_Interface (El); end if; if Get_Kind (El) = Iir_Kind_Association_Element_By_Expression then @@ -537,7 +538,7 @@ package body Sem is pragma Unreferenced (P); begin P := Check_Port_Association_Restriction - (Get_Base_Name (Formal), Prefix, El); + (Formal_Base, Prefix, El); end; end if; when others => @@ -564,8 +565,7 @@ package body Sem is -- with an expression, in order to provide these ports -- with constant driving values; such ports must be -- of mode in. - if Get_Mode (Get_Base_Name (Formal)) /= Iir_In_Mode - then + if Get_Mode (Formal_Base) /= Iir_In_Mode then Error_Msg_Sem ("only 'in' ports may be associated " & "with expression", El); end if; @@ -614,7 +614,6 @@ package body Sem is if Entity = Null_Iir then return; end if; - Set_Entity (Decl, Entity); Entity_Unit := Get_Design_Unit (Entity); -- LRM 11.4 @@ -772,6 +771,7 @@ package body Sem is -- containing block configuration. declare Block_Spec : Iir; + Block_Name : Iir; Block_Stmts : Iir; Block_Spec_Kind : Iir_Kind; Prev : Iir_Block_Configuration; @@ -782,19 +782,17 @@ package body Sem is Block_Spec_Kind := Get_Kind (Block_Spec); case Block_Spec_Kind is when Iir_Kind_Simple_Name => - Block := Block_Spec; + Block_Name := Block_Spec; when Iir_Kind_Parenthesis_Name => - Block := Get_Prefix (Block_Spec); + Block_Name := Get_Prefix (Block_Spec); when Iir_Kind_Slice_Name => - Block := Get_Prefix (Block_Spec); + Block_Name := Get_Prefix (Block_Spec); when others => Error_Msg_Sem ("label expected", Block_Spec); return; end case; - Block := Find_Declaration (Block, Decl_Label); - if Block = Null_Iir then - return; - end if; + Block_Name := Sem_Denoting_Name (Block_Name); + Block := Get_Named_Entity (Block_Name); case Get_Kind (Block) is when Iir_Kind_Block_Statement => if Block_Spec_Kind /= Iir_Kind_Simple_Name then @@ -966,10 +964,11 @@ package body Sem is Sem_Component_Specification (Configured_Block, Conf, Primary_Entity_Aspect); - Comp := Get_Component_Name (Conf); + Comp := Get_Named_Entity (Get_Component_Name (Conf)); if Get_Kind (Comp) /= Iir_Kind_Component_Declaration then -- There has been an error in sem_component_specification. -- Leave here. + Close_Declarative_Region; return; end if; @@ -1013,10 +1012,10 @@ package body Sem is S_El := Get_Port_Map_Aspect_Chain (Binding); while S_El /= Null_Iir loop -- Find S_EL formal in F_CHAIN. - Formal := Get_Associated_Formal (S_El); + Formal := Get_Association_Interface (S_El); F_El := F_Chain; while F_El /= Null_Iir loop - exit when Get_Associated_Formal (F_El) = Formal; + exit when Get_Association_Interface (F_El) = Formal; F_El := Get_Chain (F_El); end loop; if F_El /= Null_Iir @@ -1143,7 +1142,9 @@ package body Sem is (Get_Interface_Declaration_Chain (Left), Get_Interface_Declaration_Chain (Right)); when Iir_Kinds_Function_Declaration => - if Get_Return_Type (Left) /= Get_Return_Type (Right) then + if not Are_Trees_Equal (Get_Return_Type (Left), + Get_Return_Type (Right)) + then return False; end if; if Get_Pure_Flag (Left) /= Get_Pure_Flag (Right) then @@ -1224,17 +1225,45 @@ package body Sem is end loop; end; return True; + when Iir_Kind_Record_Subtype_Definition => + if Get_Base_Type (Left) /= Get_Base_Type (Right) + or else (Get_Resolution_Function (Left) + /= Get_Resolution_Function (Right)) + then + return False; + end if; + declare + L_Left, L_Right : Iir_List; + begin + L_Left := Get_Elements_Declaration_List (Left); + L_Right := Get_Elements_Declaration_List (Right); + for I in Natural loop + El_Left := Get_Nth_Element (L_Left, I); + El_Right := Get_Nth_Element (L_Right, I); + exit when El_Left = Null_Iir; + if not Are_Trees_Equal (El_Left, El_Right) then + return False; + end if; + end loop; + end; + return True; - when Iir_Kind_Integer_Literal - | Iir_Kind_Enumeration_Literal => + when Iir_Kind_Integer_Literal => if Get_Value (Left) /= Get_Value (Right) then return False; end if; return Are_Trees_Equal (Get_Literal_Origin (Left), Get_Literal_Origin (Right)); + when Iir_Kind_Enumeration_Literal => + if Get_Enum_Pos (Left) /= Get_Enum_Pos (Right) then + return False; + end if; + return Are_Trees_Equal (Get_Literal_Origin (Left), + Get_Literal_Origin (Right)); when Iir_Kind_Physical_Int_Literal => if Get_Value (Left) /= Get_Value (Right) - or else Get_Unit_Name (Left) /= Get_Unit_Name (Right) + or else not Are_Trees_Equal (Get_Unit_Name (Left), + Get_Unit_Name (Right)) then return False; end if; @@ -1356,6 +1385,9 @@ package body Sem is end if; return Are_Trees_Equal (Get_Associated (Left), Get_Associated (Right)); + when Iir_Kind_Character_Literal => + return Are_Trees_Equal (Get_Named_Entity (Left), + Get_Named_Entity (Right)); when others => Error_Kind ("are_trees_equal", Left); end case; @@ -1597,11 +1629,12 @@ package body Sem is end Compute_Subprogram_Hash; -- LRM 2.1 Subprogram Declarations. - function Sem_Subprogram_Declaration (Subprg: Iir) return Iir + procedure Sem_Subprogram_Declaration (Subprg: Iir) is Spec: Iir; Interface_Chain : Iir; Subprg_Body : Iir; + Return_Type : Iir; begin -- Set depth. declare @@ -1632,8 +1665,11 @@ package body Sem is case Get_Kind (Subprg) is when Iir_Kind_Function_Declaration => Sem_Interface_Chain (Interface_Chain, Interface_Function); - Set_Return_Type - (Subprg, Sem_Subtype_Indication (Get_Return_Type (Subprg))); + -- FIXME: the return type is in fact a type mark. + Return_Type := Get_Return_Type_Mark (Subprg); + Return_Type := Sem_Type_Mark (Return_Type); + Set_Return_Type_Mark (Subprg, Return_Type); + Set_Return_Type (Subprg, Get_Type (Return_Type)); Set_All_Sensitized_State (Subprg, Unknown); when Iir_Kind_Procedure_Declaration => Sem_Interface_Chain (Interface_Chain, Interface_Procedure); @@ -1669,6 +1705,7 @@ package body Sem is -- now. Close_Declarative_Region; + -- Look if there is an associated body (the next node). Subprg_Body := Get_Chain (Subprg); if Subprg_Body /= Null_Iir and then (Get_Kind (Subprg_Body) = Iir_Kind_Function_Body @@ -1683,17 +1720,15 @@ package body Sem is -- SUBPRG is the body of the specification SPEC. Check_Conformance_Rules (Subprg, Spec); Xref_Body (Subprg, Spec); - Free_Old_Iir (Subprg); + Set_Subprogram_Body (Subprg, Subprg_Body); Set_Subprogram_Specification (Subprg_Body, Spec); Set_Subprogram_Body (Spec, Subprg_Body); - return Subprg_Body; else -- Forward declaration or specification followed by body. Set_Subprogram_Overload_Number (Subprg); Sem_Scopes.Add_Name (Subprg); Name_Visible (Subprg); Xref_Decl (Subprg); - return Subprg; end if; end Sem_Subprogram_Declaration; @@ -2348,15 +2383,11 @@ package body Sem is -- LRM08 4.9 -- The uninstantiated package name shall denote an uninstantiated -- package declared in a package declaration. - Name := Get_Uninstantiated_Name (Decl); - Sem_Name (Name, False); + Name := Sem_Denoting_Name (Get_Uninstantiated_Name (Decl)); + Set_Uninstantiated_Name (Decl, Name); Pkg := Get_Named_Entity (Name); - if Get_Kind (Pkg) = Iir_Kind_Design_Unit then - Pkg := Get_Library_Unit (Pkg); - Set_Named_Entity (Name, Pkg); - end if; if Get_Kind (Pkg) /= Iir_Kind_Package_Declaration then - Error_Msg_Sem ("name must denote a package declaration", Name); + Error_Class_Match (Name, "package"); -- What could be done ? return; @@ -2368,8 +2399,6 @@ package body Sem is return; end if; - Xref_Name (Name); - -- LRM08 4.9 -- The generic map aspect, if present, optionally associates a single -- actual with each formal generic (or member thereof) in the @@ -2384,7 +2413,7 @@ package body Sem is Clause : Iir_Use_Clause; Name: Iir; Prefix: Iir; - Prefix_Name : Iir; + Name_Prefix : Iir; begin Clause := Clauses; loop @@ -2398,15 +2427,16 @@ package body Sem is case Get_Kind (Name) is when Iir_Kind_Selected_By_All_Name | Iir_Kind_Selected_Name => - Prefix := Get_Prefix (Name); + Name_Prefix := Get_Prefix (Name); when others => Error_Msg_Sem ("use clause allows only selected name", Name); return; end case; - Sem_Name (Prefix, False); - Prefix_Name := Get_Named_Entity (Prefix); - if Prefix_Name = Error_Mark then + Name_Prefix := Sem_Denoting_Name (Name_Prefix); + Set_Prefix (Name, Name_Prefix); + Prefix := Get_Named_Entity (Name_Prefix); + if Is_Error (Prefix) then -- FIXME: continue with the clauses return; end if; @@ -2423,7 +2453,7 @@ package body Sem is -- or library denoted by the prefix of the selected name. -- -- GHDL: therefore, the suffix must be either a package or a library. - case Get_Kind (Prefix_Name) is + case Get_Kind (Prefix) is when Iir_Kind_Library_Declaration => null; when Iir_Kind_Package_Instantiation_Declaration => @@ -2432,9 +2462,10 @@ package body Sem is -- LRM08 12.4 Use clauses -- It is an error if the prefix of a selected name in a use -- clause denotes an uninstantiated package. - if Is_Uninstantiated_Package (Prefix_Name) then + if Is_Uninstantiated_Package (Prefix) then Error_Msg_Sem - ("use of uninstantiated package is not allowed", Prefix); + ("use of uninstantiated package is not allowed", + Name_Prefix); return; end if; when others => @@ -2445,13 +2476,19 @@ package body Sem is case Get_Kind (Name) is when Iir_Kind_Selected_Name => - Sem_Name (Name, False); - if Get_Named_Entity (Name) = Error_Mark then - return; - end if; - Xref_Name (Name); + Sem_Name (Name); + case Get_Kind (Get_Named_Entity (Name)) is + when Iir_Kind_Error => + -- Continue in case of error. + null; + when Iir_Kind_Overload_List => + -- Analyze is correct as is. + null; + when others => + Name := Finish_Sem_Name (Name); + Set_Selected_Name (Clause, Name); + end case; when Iir_Kind_Selected_By_All_Name => - Xref_Name (Prefix); null; when others => raise Internal_Error; @@ -2531,6 +2568,10 @@ package body Sem is Set_Date (Design_Unit, Date_Analyzing); when Date_Valid => null; + when Date_Obsolete => + -- This happens only when design files are added into the library + -- and keeping obsolete units (eg: to pretty print a file). + Set_Date (Design_Unit, Date_Analyzing); when others => raise Internal_Error; end case; @@ -65,8 +65,7 @@ package Sem is procedure Compute_Subprogram_Hash (Subprg : Iir); -- LRM 2.1 Subprogram Declarations. - -- SUBPRG is either a _specification or a _spec_body. - function Sem_Subprogram_Declaration (Subprg: Iir) return Iir; + procedure Sem_Subprogram_Declaration (Subprg: Iir); -- LRM 2.2 Subprogram Bodies. procedure Sem_Subprogram_Body (Subprg: Iir); diff --git a/sem_assocs.adb b/sem_assocs.adb index 23252f5ce..80fd24640 100644 --- a/sem_assocs.adb +++ b/sem_assocs.adb @@ -117,7 +117,7 @@ package body Sem_Assocs is Inter := Get_Chain (Inter); else -- Association by name. - Formal_Inter := Get_Base_Name (Formal); + Formal_Inter := Get_Association_Interface (Assoc); Inter := Null_Iir; end if; case Get_Kind (Assoc) is @@ -420,7 +420,7 @@ package body Sem_Assocs is Index := Get_Suffix (Formal); -- Evaluate index. - Index := Eval_Expr (Index); + Index := Eval_Range (Index); Set_Suffix (Formal, Index); Choice := Create_Iir (Iir_Kind_Choice_By_Range); @@ -482,7 +482,7 @@ package body Sem_Assocs is when others => Error_Msg_Sem ("individual association of " - & Disp_Node (Get_Associated_Formal (Iassoc)) + & Disp_Node (Get_Association_Interface (Iassoc)) & " conflicts with that at " & Disp_Location (Sub), Formal); return; @@ -517,7 +517,7 @@ package body Sem_Assocs is Prev := Get_Associated (Iass); if Prev /= Null_Iir then Error_Msg_Sem ("individual association of " - & Disp_Node (Get_Base_Name (Formal)) + & Disp_Node (Get_Association_Interface (Assoc)) & " conflicts with that at " & Disp_Location (Prev), Assoc); else @@ -568,8 +568,7 @@ package body Sem_Assocs is Base_Index := Actual_Index; else Base_Type := Get_Base_Type (Actual_Type); - Base_Index := Get_Nth_Element (Get_Index_Subtype_List (Base_Type), - Dim - 1); + Base_Index := Get_Index_Type (Base_Type, Dim - 1); end if; Chain := Get_Individual_Association_Chain (Assoc); Sem_Choices_Range @@ -675,7 +674,7 @@ package body Sem_Assocs is return; end if; - Formal := Get_Associated_Formal (Assoc); + Formal := Get_Association_Interface (Assoc); Atype := Get_Type (Formal); case Get_Kind (Atype) is @@ -715,7 +714,7 @@ package body Sem_Assocs is while Assoc /= Null_Iir loop Formal := Get_Formal (Assoc); if Formal /= Null_Iir then - Formal := Get_Base_Name (Formal); + Formal := Get_Object_Prefix (Formal); end if; if Formal = Null_Iir or else Formal /= Cur_Iface then -- New formal name, sem the current assoc. @@ -804,7 +803,7 @@ package body Sem_Assocs is if Flags.Vhdl_Std = Vhdl_87 then return Null_Iir; end if; - return Get_Type_Of_Type_Mark (Func); + return Get_Type (Func); when others => return Null_Iir; end case; @@ -1010,7 +1009,6 @@ package body Sem_Assocs is Set_Named_Entity (Formal, Inter); Set_Type (Formal, Formal_Type); Set_Base_Name (Formal, Inter); - --Xrefs.Xref_Name (Formal); return Whole; end if; return None; @@ -1053,7 +1051,7 @@ package body Sem_Assocs is end if; when Iir_Kind_Type_Declaration | Iir_Kind_Subtype_Declaration => - R_Type := Get_Type_Of_Type_Mark (Func); + R_Type := Get_Type (Func); if Get_Base_Type (R_Type) = Res_Base_Type and then Are_Types_Closely_Related (R_Type, Param_Base_Type) then @@ -1067,6 +1065,9 @@ package body Sem_Assocs is when Iir_Kind_Type_Conversion => return Is_Valid_Conversion (Get_Type_Mark (Func), Res_Base_Type, Param_Base_Type); + when Iir_Kinds_Denoting_Name => + return Is_Valid_Conversion (Get_Named_Entity (Func), + Res_Base_Type, Param_Base_Type); when others => Error_Kind ("is_valid_conversion(2)", Func); end case; @@ -1150,12 +1151,14 @@ package body Sem_Assocs is if Func = Null_Iir then return Null_Iir; end if; + pragma Assert (Get_Kind (Conv) in Iir_Kinds_Denoting_Name); + Set_Named_Entity (Conv, Func); case Get_Kind (Func) is when Iir_Kinds_Function_Declaration => Res := Create_Iir (Iir_Kind_Function_Call); Location_Copy (Res, Conv); - Set_Implementation (Res, Func); + Set_Implementation (Res, Conv); Set_Base_Name (Res, Res); Set_Parameter_Association_Chain (Res, Null_Iir); Set_Type (Res, Get_Return_Type (Func)); @@ -1165,14 +1168,13 @@ package body Sem_Assocs is | Iir_Kind_Type_Declaration => Res := Create_Iir (Iir_Kind_Type_Conversion); Location_Copy (Res, Conv); - Set_Type_Mark (Res, Func); - Set_Type (Res, Get_Type_Of_Type_Mark (Func)); + Set_Type_Mark (Res, Conv); + Set_Type (Res, Get_Type (Func)); Set_Expression (Res, Null_Iir); Set_Expr_Staticness (Res, None); when others => Error_Kind ("extract_out_conversion", Res); end case; - Set_Named_Entity (Conv, Res); Xrefs.Xref_Name (Conv); return Res; end Extract_Out_Conversion; @@ -1206,13 +1208,16 @@ package body Sem_Assocs is end if; Set_Whole_Association_Flag (Assoc, Assoc_Kind = Whole); if Finish then - Set_Type (Formal, Null_Iir); - Sem_Name (Formal, False); - Expr := Get_Named_Entity (Formal); - if Get_Kind (Expr) = Iir_Kind_Error then + Sem_Name (Formal); + Formal := Finish_Sem_Name (Formal); + Set_Formal (Assoc, Formal); + if Get_Kind (Formal) in Iir_Kinds_Denoting_Name + and then Is_Error (Get_Named_Entity (Formal)) + then Match := False; return; end if; + -- LRM 4.3.3.2 Associations lists -- It is an error if an actual of open is associated with a -- formal that is associated individually. @@ -1220,9 +1225,6 @@ package body Sem_Assocs is Error_Msg_Sem ("cannot associate individually with open", Assoc); end if; - - Xrefs.Xref_Name (Formal); - Set_Formal (Assoc, Expr); end if; else Set_Whole_Association_Flag (Assoc, True); @@ -1338,14 +1340,13 @@ package body Sem_Assocs is -- Semantize formal. if Get_Formal (Assoc) /= Null_Iir then Set_Type (Formal, Null_Iir); - Sem_Name (Formal, False); + Sem_Name (Formal); Expr := Get_Named_Entity (Formal); if Get_Kind (Expr) = Iir_Kind_Error then return; end if; - Xrefs.Xref_Name (Formal); - Free_Name (Formal); - Set_Formal (Assoc, Expr); + Formal := Finish_Sem_Name (Formal); + Set_Formal (Assoc, Formal); Formal_Type := Get_Type (Expr); if Out_Conv = Null_Iir and In_Conv = Null_Iir then Res_Type := Formal_Type; diff --git a/sem_decls.adb b/sem_decls.adb index da485f8da..8f4a8b7e0 100644 --- a/sem_decls.adb +++ b/sem_decls.adb @@ -69,22 +69,32 @@ package body Sem_Decls is Interface_Kind : Interface_Kind_Type) is El, A_Type: Iir; - Proxy : Iir_Proxy; Default_Value: Iir; + + -- LAST is the last interface declaration that has a type. This is + -- used to set type and default value for the following declarations + -- that appeared in a list of identifiers. + Last : Iir; begin + Last := Null_Iir; + El := Interface_Chain; while El /= Null_Iir loop -- Avoid the reanalysed duplicated types. -- This is not an optimization, since the unanalysed type must have -- been freed. - A_Type := Get_Type (El); - if Get_Kind (A_Type) = Iir_Kind_Proxy then - Proxy := A_Type; - A_Type := Get_Type (Get_Proxy (Proxy)); - Default_Value := Get_Default_Value (Get_Proxy (Proxy)); - Free_Iir (Proxy); + A_Type := Get_Subtype_Indication (El); + if A_Type = Null_Iir then + pragma Assert (Last /= Null_Iir); + Set_Subtype_Indication (El, Get_Subtype_Indication (Last)); + A_Type := Get_Type (Last); + Default_Value := Get_Default_Value (Last); else + Last := El; A_Type := Sem_Subtype_Indication (A_Type); + Set_Subtype_Indication (El, A_Type); + A_Type := Get_Type_Of_Subtype_Indication (A_Type); + Default_Value := Get_Default_Value (El); if Default_Value /= Null_Iir and then A_Type /= Null_Iir then Deferred_Constant_Allowed := True; @@ -96,7 +106,6 @@ package body Sem_Decls is end if; end if; - Set_Base_Name (El, El); Set_Name_Staticness (El, Locally); Xref_Decl (El); @@ -345,7 +354,8 @@ package body Sem_Decls is (Decl : Iir_Type_Declaration; Type_Definition : Iir_File_Type_Definition) is use Iir_Chains.Interface_Declaration_Chain_Handling; - Type_Mark: Iir; + Type_Mark : constant Iir := Get_File_Type_Mark (Type_Definition); + Type_Mark_Type : constant Iir := Get_Type (Type_Mark); Proc: Iir_Implicit_Procedure_Declaration; Func: Iir_Implicit_Function_Declaration; Inter: Iir; @@ -355,7 +365,6 @@ package body Sem_Decls is Last : Iir; begin Last := Decl; - Type_Mark := Get_Type_Mark (Type_Definition); Loc := Get_Location (Decl); if Flags.Vhdl_Std >= Vhdl_93c then @@ -383,7 +392,7 @@ package body Sem_Decls is Set_Type (Inter, Std_Package.File_Open_Status_Type_Definition); Set_Mode (Inter, Iir_Out_Mode); - Set_Base_Name (Inter, Inter); + Set_Lexical_Layout (Inter, Iir_Lexical_Has_Type); Append (Last_Interface, Proc, Inter); end case; -- File F : FT @@ -392,7 +401,7 @@ package body Sem_Decls is Set_Identifier (Inter, Std_Names.Name_F); Set_Type (Inter, Type_Definition); Set_Mode (Inter, Iir_Inout_Mode); - Set_Base_Name (Inter, Inter); + Set_Lexical_Layout (Inter, Iir_Lexical_Has_Type); Append (Last_Interface, Proc, Inter); -- External_Name : in STRING Inter := Create_Iir (Iir_Kind_Constant_Interface_Declaration); @@ -400,7 +409,7 @@ package body Sem_Decls is Set_Identifier (Inter, Std_Names.Name_External_Name); Set_Type (Inter, Std_Package.String_Type_Definition); Set_Mode (Inter, Iir_In_Mode); - Set_Base_Name (Inter, Inter); + Set_Lexical_Layout (Inter, Iir_Lexical_Has_Type); Append (Last_Interface, Proc, Inter); -- Open_Kind : in File_Open_Kind := Read_Mode. Inter := Create_Iir (Iir_Kind_Constant_Interface_Declaration); @@ -408,9 +417,9 @@ package body Sem_Decls is Set_Identifier (Inter, Std_Names.Name_Open_Kind); Set_Type (Inter, Std_Package.File_Open_Kind_Type_Definition); Set_Mode (Inter, Iir_In_Mode); - Set_Base_Name (Inter, Inter); Set_Default_Value (Inter, Std_Package.File_Open_Kind_Read_Mode); + Set_Lexical_Layout (Inter, Iir_Lexical_Has_Type); Append (Last_Interface, Proc, Inter); Compute_Subprogram_Hash (Proc); -- Add it to the list. @@ -431,7 +440,7 @@ package body Sem_Decls is Set_Location (Inter, Loc); Set_Type (Inter, Type_Definition); Set_Mode (Inter, Iir_Inout_Mode); - Set_Base_Name (Inter, Inter); + Set_Lexical_Layout (Inter, Iir_Lexical_Has_Type); Append (Last_Interface, Proc, Inter); Compute_Subprogram_Hash (Proc); -- Add it to the list. @@ -457,24 +466,25 @@ package body Sem_Decls is Set_Location (Inter, Loc); Set_Type (Inter, Type_Definition); Set_Mode (Inter, Iir_In_Mode); - Set_Base_Name (Inter, Inter); + Set_Lexical_Layout (Inter, Iir_Lexical_Has_Type); Append (Last_Interface, Proc, Inter); Inter := Create_Iir (Iir_Kind_Variable_Interface_Declaration); Set_Identifier (Inter, Std_Names.Name_Value); Set_Location (Inter, Loc); - Set_Type (Inter, Type_Mark); + Set_Subtype_Indication (Inter, Type_Mark); + Set_Type (Inter, Type_Mark_Type); Set_Mode (Inter, Iir_Out_Mode); - Set_Base_Name (Inter, Inter); + Set_Lexical_Layout (Inter, Iir_Lexical_Has_Type); Append (Last_Interface, Proc, Inter); - if Get_Kind (Type_Mark) in Iir_Kinds_Array_Type_Definition - and then Get_Constraint_State (Type_Mark) /= Fully_Constrained + if Get_Kind (Type_Mark_Type) in Iir_Kinds_Array_Type_Definition + and then Get_Constraint_State (Type_Mark_Type) /= Fully_Constrained then Inter := Create_Iir (Iir_Kind_Variable_Interface_Declaration); Set_Identifier (Inter, Std_Names.Name_Length); Set_Location (Inter, Loc); Set_Type (Inter, Std_Package.Natural_Subtype_Definition); Set_Mode (Inter, Iir_Out_Mode); - Set_Base_Name (Inter, Inter); + Set_Lexical_Layout (Inter, Iir_Lexical_Has_Type); Append (Last_Interface, Proc, Inter); Set_Implicit_Definition (Proc, Iir_Predefined_Read_Length); else @@ -497,16 +507,17 @@ package body Sem_Decls is Set_Location (Inter, Loc); Set_Type (Inter, Type_Definition); Set_Mode (Inter, Iir_Out_Mode); - Set_Base_Name (Inter, Inter); Set_Name_Staticness (Inter, Locally); Set_Expr_Staticness (Inter, None); + Set_Lexical_Layout (Inter, Iir_Lexical_Has_Type); Append (Last_Interface, Proc, Inter); Inter := Create_Iir (Iir_Kind_Constant_Interface_Declaration); Set_Identifier (Inter, Std_Names.Name_Value); Set_Location (Inter, Loc); - Set_Type (Inter, Type_Mark); + Set_Subtype_Indication (Inter, Type_Mark); + Set_Type (Inter, Type_Mark_Type); Set_Mode (Inter, Iir_In_Mode); - Set_Base_Name (Inter, Inter); + Set_Lexical_Layout (Inter, Iir_Lexical_Has_Type); Append (Last_Interface, Proc, Inter); Set_Implicit_Definition (Proc, Iir_Predefined_Write); Compute_Subprogram_Hash (Proc); @@ -526,9 +537,9 @@ package body Sem_Decls is Set_Identifier (Inter, Std_Names.Name_F); Set_Location (Inter, Loc); Set_Type (Inter, Type_Definition); - Set_Base_Name (Inter, Inter); Set_Name_Staticness (Inter, Locally); Set_Expr_Staticness (Inter, None); + Set_Lexical_Layout (Inter, Iir_Lexical_Has_Type); Append (Last_Interface, Proc, Inter); Set_Implicit_Definition (Proc, Iir_Predefined_Flush); Compute_Subprogram_Hash (Proc); @@ -548,7 +559,7 @@ package body Sem_Decls is Set_Location (Inter, Loc); Set_Type (Inter, Type_Definition); Set_Mode (Inter, Iir_In_Mode); - Set_Base_Name (Inter, Inter); + Set_Lexical_Layout (Inter, Iir_Lexical_Has_Type); Append (Last_Interface, Func, Inter); Set_Return_Type (Func, Std_Package.Boolean_Type_Definition); Set_Implicit_Definition (Func, Iir_Predefined_Endfile); @@ -565,9 +576,9 @@ package body Sem_Decls is Inter := Create_Iir (Iir_Kind_Constant_Interface_Declaration); Location_Copy (Inter, Atype); Set_Identifier (Inter, Null_Identifier); + Set_Lexical_Layout (Inter, Iir_Lexical_Has_Type); Set_Mode (Inter, Iir_In_Mode); Set_Type (Inter, Atype); - Set_Base_Name (Inter, Inter); return Inter; end Create_Anonymous_Interface; @@ -659,7 +670,7 @@ package body Sem_Decls is Set_Identifier (Inter_Int, Null_Identifier); Set_Mode (Inter_Int, Iir_In_Mode); Set_Type (Inter_Int, Std_Package.Integer_Subtype_Definition); - Set_Base_Name (Inter_Int, Inter_Int); + Set_Lexical_Layout (Inter_Int, Iir_Lexical_Has_Type); Set_Chain (Inter_Chain, Inter_Int); @@ -995,7 +1006,7 @@ package body Sem_Decls is Set_Identifier (Var_Interface, Std_Names.Name_P); Set_Type (Var_Interface, Type_Definition); Set_Mode (Var_Interface, Iir_Inout_Mode); - Set_Base_Name (Var_Interface, Var_Interface); + Set_Lexical_Layout (Var_Interface, Iir_Lexical_Has_Type); --Set_Purity_State (Deallocate_Proc, Impure); Set_Wait_State (Deallocate_Proc, False); Set_Type_Reference (Deallocate_Proc, Decl); @@ -1205,7 +1216,7 @@ package body Sem_Decls is if not Is_Std_Standard then return; end if; - if Decl = Std_Package.Boolean_Type then + if Decl = Std_Package.Boolean_Type_Declaration then Add_Binary (Name_And, Iir_Predefined_Boolean_And); Add_Binary (Name_Or, Iir_Predefined_Boolean_Or); Add_Binary (Name_Nand, Iir_Predefined_Boolean_Nand); @@ -1215,7 +1226,7 @@ package body Sem_Decls is Add_Binary (Name_Xnor, Iir_Predefined_Boolean_Xnor); end if; Add_Unary (Name_Not, Iir_Predefined_Boolean_Not); - elsif Decl = Std_Package.Bit_Type then + elsif Decl = Std_Package.Bit_Type_Declaration then Add_Binary (Name_And, Iir_Predefined_Bit_And); Add_Binary (Name_Or, Iir_Predefined_Bit_Or); Add_Binary (Name_Nand, Iir_Predefined_Bit_Nand); @@ -1246,7 +1257,7 @@ package body Sem_Decls is Unary_Chain, Std_Package.Boolean_Type_Definition); end if; - elsif Decl = Std_Package.Universal_Real_Type then + elsif Decl = Std_Package.Universal_Real_Type_Declaration then declare Inter_Chain : Iir; begin @@ -1323,12 +1334,15 @@ package body Sem_Decls is Set_Incomplete_Type_List (Def, Create_Iir_List); Xref_Decl (Decl); else + -- A complete type declaration. if Old_Decl = Null_Iir then Xref_Decl (Decl); else Xref_Body (Decl, Old_Decl); end if; + Def := Sem_Type_Definition (Def, Decl); + if Def /= Null_Iir then case Get_Kind (Def) is when Iir_Kind_Integer_Subtype_Definition @@ -1423,6 +1437,7 @@ package body Sem_Decls is procedure Sem_Subtype_Declaration (Decl: Iir; Is_Global : Boolean) is Def: Iir; + Atype : Iir; begin -- Real hack to skip subtype declarations of anonymous type decls. if Get_Visible_Flag (Decl) then @@ -1433,7 +1448,10 @@ package body Sem_Decls is Xref_Decl (Decl); -- Check the definition of the type. - Def := Sem_Subtype_Indication (Get_Type (Decl)); + Atype := Get_Subtype_Indication (Decl); + Def := Sem_Subtype_Indication (Atype); + Set_Subtype_Indication (Decl, Def); + Def := Get_Type_Of_Subtype_Indication (Def); if Def = Null_Iir then return; end if; @@ -1443,6 +1461,7 @@ package body Sem_Decls is -- declaration is in fact an alias of the type. Def := Copy_Subtype_Indication (Def); Location_Copy (Def, Decl); + Set_Subtype_Type_Mark (Def, Atype); end if; Set_Type (Decl, Def); @@ -1493,25 +1512,16 @@ package body Sem_Decls is return Deferred_Const; end Get_Deferred_Constant; - procedure Sem_Object_Declaration (Decl: Iir; Parent : Iir) + procedure Sem_Object_Declaration (Decl: Iir; Parent : Iir; Last_Decl : Iir) is + Deferred_Const : constant Iir := Get_Deferred_Constant (Decl); Atype: Iir; Default_Value : Iir; - Proxy : Iir; - Deferred_Const : Iir; Staticness : Iir_Staticness; begin - Deferred_Const := Get_Deferred_Constant (Decl); - - -- Semantize type and default value: - Atype := Get_Type (Decl); - if Get_Kind (Atype) /= Iir_Kind_Proxy then - Atype := Sem_Subtype_Indication (Atype); - if Atype = Null_Iir then - Atype := Create_Error_Type (Get_Type (Decl)); - end if; - end if; - + -- LRM08 12.2 Scope of declarations + -- Then scope of a declaration [...] extends from the beginning of the + -- declaration [...] if Deferred_Const = Null_Iir then Sem_Scopes.Add_Name (Decl); Xref_Decl (Decl); @@ -1519,16 +1529,16 @@ package body Sem_Decls is Xref_Ref (Decl, Deferred_Const); end if; - if Get_Kind (Atype) = Iir_Kind_Proxy then - Proxy := Get_Proxy (Atype); - Default_Value := Get_Default_Value (Proxy); - Atype := Get_Type (Proxy); + -- Semantize type and default value: + Atype := Get_Subtype_Indication (Decl); + if Atype /= Null_Iir then + Atype := Sem_Subtype_Indication (Atype); + Set_Subtype_Indication (Decl, Atype); + Atype := Get_Type_Of_Subtype_Indication (Atype); if Atype = Null_Iir then - return; + Atype := Create_Error_Type (Get_Type (Decl)); end if; - Proxy := Get_Type (Decl); - Free_Iir (Proxy); - else + Default_Value := Get_Default_Value (Decl); if Default_Value /= Null_Iir then Default_Value := Sem_Expression (Default_Value, Atype); @@ -1537,13 +1547,15 @@ package body Sem_Decls is Create_Error_Expr (Get_Default_Value (Decl), Atype); end if; Check_Read (Default_Value); + Default_Value := Eval_Expr_Check_If_Static (Default_Value, Atype); end if; + else + Default_Value := Get_Default_Value (Last_Decl); + Atype := Get_Type (Last_Decl); end if; Set_Type (Decl, Atype); - Default_Value := Eval_Expr_Check_If_Static (Default_Value, Atype); Set_Default_Value (Decl, Default_Value); - Set_Base_Name (Decl, Decl); Set_Name_Staticness (Decl, Locally); Set_Visible_Flag (Decl, True); @@ -1774,7 +1786,7 @@ package body Sem_Decls is end case; end Sem_Object_Declaration; - procedure Sem_File_Declaration (Decl: Iir_File_Declaration) + procedure Sem_File_Declaration (Decl: Iir_File_Declaration; Last_Decl : Iir) is Atype: Iir; Logical_Name: Iir; @@ -1782,19 +1794,19 @@ package body Sem_Decls is begin Sem_Scopes.Add_Name (Decl); Set_Expr_Staticness (Decl, None); - Set_Base_Name (Decl, Decl); Xref_Decl (Decl); -- Try to find a type. - Atype := Get_Type (Decl); - if Get_Kind (Atype) = Iir_Kind_Proxy then - Atype := Get_Type (Get_Proxy (Atype)); - Free_Iir (Get_Type (Decl)); - else - Atype := Sem_Subtype_Indication (Get_Type (Decl)); + Atype := Get_Subtype_Indication (Decl); + if Atype /= Null_Iir then + Atype := Sem_Subtype_Indication (Atype); + Set_Subtype_Indication (Decl, Atype); + Atype := Get_Type_Of_Subtype_Indication (Atype); if Atype = Null_Iir then - return; + Atype := Create_Error_Type (Get_Type (Decl)); end if; + else + Atype := Get_Type (Last_Decl); end if; Set_Type (Decl, Atype); @@ -1838,7 +1850,8 @@ package body Sem_Decls is if Flags.Vhdl_Std = Vhdl_87 then Set_Mode (Decl, Iir_In_Mode); else - Set_File_Open_Kind (Decl, File_Open_Kind_Read_Mode); + null; + -- Set_File_Open_Kind (Decl, File_Open_Kind_Read_Mode); end if; end if; end if; @@ -1901,10 +1914,9 @@ package body Sem_Decls is Sem_Scopes.Add_Name (Decl); Xref_Decl (Decl); - A_Type := Sem_Subtype_Indication (Get_Type (Decl)); - if A_Type = Null_Iir then - return; - end if; + A_Type := Sem_Type_Mark (Get_Type_Mark (Decl)); + Set_Type_Mark (Decl, A_Type); + A_Type := Get_Type (A_Type); Set_Type (Decl, A_Type); -- LRM93 4.4 Attribute declarations. @@ -1936,12 +1948,10 @@ package body Sem_Decls is procedure Sem_Object_Alias_Declaration (Alias: Iir_Object_Alias_Declaration) is - N_Type: Iir; N_Name: constant Iir := Get_Name (Alias); + N_Type: Iir; Name_Type : Iir; begin - Set_Base_Name (Alias, Alias); -- Get_Base_Name (N_Name)); - -- LRM93 4.3.3.1 Object Aliases. -- 1. A signature may not appear in a declaration of an object alias. -- FIXME: todo. @@ -1956,13 +1966,15 @@ package body Sem_Decls is -- the same as the base type of the type mark in the subtype indication -- (if the subtype indication is present); Name_Type := Get_Type (N_Name); - N_Type := Get_Type (Alias); + N_Type := Get_Subtype_Indication (Alias); if N_Type = Null_Iir then Set_Type (Alias, Name_Type); N_Type := Name_Type; else -- FIXME: must be analyzed before calling Name_Visibility. N_Type := Sem_Subtype_Indication (N_Type); + Set_Subtype_Indication (Alias, N_Type); + N_Type := Get_Type_Of_Subtype_Indication (N_Type); if N_Type /= Null_Iir then Set_Type (Alias, N_Type); if Get_Base_Type (N_Type) /= Get_Base_Type (Name_Type) then @@ -2016,7 +2028,7 @@ package body Sem_Decls is -- of the subprogram equivalent to the enumeration literal, -- defined in Section 3.1.1 return List = Null_Iir_List - and then Get_Type (N_Entity) = Get_Return_Type (Sig); + and then Get_Type (N_Entity) = Get_Type (Get_Return_Type (Sig)); when Iir_Kind_Function_Declaration | Iir_Kind_Implicit_Function_Declaration => -- LRM93 2.3.2 Signatures @@ -2024,7 +2036,7 @@ package body Sem_Decls is -- a function and the base type of the type mark following -- the reserved word in the signature is the same as the base -- type of the return type of the function, [...] - if Get_Return_Type (Sig) /= + if Get_Type (Get_Return_Type (Sig)) /= Get_Base_Type (Get_Return_Type (N_Entity)) then return False; @@ -2063,7 +2075,7 @@ package body Sem_Decls is if El = Null_Iir or Inter = Null_Iir then return False; end if; - if Get_Base_Type (Get_Type (Inter)) /= El then + if Get_Base_Type (Get_Type (Inter)) /= Get_Type (El) then return False; end if; Inter := Get_Chain (Inter); @@ -2086,20 +2098,24 @@ package body Sem_Decls is for I in Natural loop El := Get_Nth_Element (List, I); exit when El = Null_Iir; - El := Find_Declaration (El, Decl_Type); - if El /= Null_Iir then - Replace_Nth_Element (List, I, Get_Base_Type (El)); - end if; + El := Sem_Type_Mark (El); + Replace_Nth_Element (List, I, El); + + -- Reuse the Type field of the name for the base type. This is + -- a deviation from the use of Type in a name, but restricted to + -- analysis of signatures. + Set_Type (El, Get_Base_Type (Get_Type (El))); end loop; end if; El := Get_Return_Type (Sig); if El /= Null_Iir then - El := Find_Declaration (El, Decl_Type); - if El /= Null_Iir then - Set_Return_Type (Sig, Get_Base_Type (El)); - end if; + El := Sem_Type_Mark (El); + Set_Return_Type (Sig, El); + -- Likewise. + Set_Type (El, Get_Base_Type (Get_Type (El))); end if; + -- FIXME: what to do in case of error ? Res := Null_Iir; Error := False; if Is_Overload_List (Name) then @@ -2134,14 +2150,15 @@ package body Sem_Decls is Error_Msg_Sem ("cannot resolve signature, no matching subprogram", Sig); end if; + return Res; end Sem_Signature; -- Create implicit aliases for an alias ALIAS of a type or of a subtype. procedure Add_Aliases_For_Type_Alias (Alias : Iir) is - N_Entity : constant Iir := Get_Name (Alias); - Def : constant Iir := Get_Base_Type (Get_Type_Of_Type_Mark (N_Entity)); + N_Entity : constant Iir := Get_Named_Entity (Get_Name (Alias)); + Def : constant Iir := Get_Base_Type (Get_Type (N_Entity)); Type_Decl : constant Iir := Get_Type_Declarator (Def); Last : Iir; El : Iir; @@ -2152,10 +2169,17 @@ package body Sem_Decls is is N_Alias : constant Iir_Non_Object_Alias_Declaration := Create_Iir (Iir_Kind_Non_Object_Alias_Declaration); + N_Name : constant Iir := Create_Iir (Iir_Kind_Simple_Name); begin + -- Create the name (can be in fact a character literal or a symbol + -- operator). + Location_Copy (N_Name, Alias); + Set_Identifier (N_Name, Get_Identifier (Decl)); + Set_Named_Entity (N_Name, Decl); + Location_Copy (N_Alias, Alias); Set_Identifier (N_Alias, Get_Identifier (Decl)); - Set_Name (N_Alias, Decl); + Set_Name (N_Alias, N_Name); Set_Parent (N_Alias, Get_Parent (Alias)); Set_Implicit_Alias_Flag (N_Alias, True); @@ -2272,7 +2296,7 @@ package body Sem_Decls is (Alias : Iir_Non_Object_Alias_Declaration) is use Std_Names; - N_Entity : constant Iir := Get_Name (Alias); + N_Entity : constant Iir := Get_Named_Entity (Get_Name (Alias)); Id : Name_Id; begin case Get_Kind (N_Entity) is @@ -2283,11 +2307,11 @@ package body Sem_Decls is -- LRM93 4.3.3.2 Non-Object Aliases -- 2. A signature is required if the name denotes a subprogram -- (including an operator) or enumeration literal. - if Get_Signature (Alias) = Null_Iir then + if Get_Alias_Signature (Alias) = Null_Iir then Error_Msg_Sem ("signature required for subprogram", Alias); end if; when Iir_Kind_Enumeration_Literal => - if Get_Signature (Alias) = Null_Iir then + if Get_Alias_Signature (Alias) = Null_Iir then Error_Msg_Sem ("signature required for enumeration literal", Alias); end if; @@ -2356,12 +2380,14 @@ package body Sem_Decls is Name := Get_Name (Alias); if Get_Kind (Name) = Iir_Kind_Signature then Sig := Name; - Name := Get_Prefix (Name); + Name := Get_Prefix (Sig); + Sem_Name (Name); + Set_Prefix (Sig, Name); else + Sem_Name (Name); Sig := Null_Iir; end if; - Sem_Name (Name, False); N_Entity := Get_Named_Entity (Name); if N_Entity = Error_Mark then return Alias; @@ -2383,31 +2409,40 @@ package body Sem_Decls is end if; Set_Named_Entity (Name, N_Entity); - Xref_Name (Name); + Set_Name (Alias, Finish_Sem_Name (Name)); if Is_Object_Name (N_Entity) then + -- Object alias declaration. + Sem_Scopes.Add_Name (Alias); Name_Visible (Alias); if Sig /= Null_Iir then - Error_Msg_Sem - ("signature not allowed for object alias", Sig); + Error_Msg_Sem ("signature not allowed for object alias", Sig); end if; Set_Name (Alias, N_Entity); Sem_Object_Alias_Declaration (Alias); return Alias; else + -- Non object alias declaration. + if Get_Type (Alias) /= Null_Iir then Error_Msg_Sem ("subtype indication not allowed for non-object alias", Alias); end if; + if Get_Subtype_Indication (Alias) /= Null_Iir then + Error_Msg_Sem + ("subtype indication shall not appear in a nonobject alias", + Alias); + end if; + Res := Create_Iir (Iir_Kind_Non_Object_Alias_Declaration); Location_Copy (Res, Alias); Set_Parent (Res, Get_Parent (Alias)); Set_Chain (Res, Get_Chain (Alias)); Set_Identifier (Res, Get_Identifier (Alias)); - Set_Name (Res, N_Entity); - Set_Signature (Res, Sig); + Set_Name (Res, Name); + Set_Alias_Signature (Res, Sig); Sem_Scopes.Add_Name (Res); Name_Visible (Res); @@ -2434,6 +2469,7 @@ package body Sem_Decls is Constituent_List : Iir_Group_Constituent_List; Template : Iir_Group_Template_Declaration; + Template_Name : Iir; Class, Prev_Class : Token_Type; El : Iir; El_Name : Iir; @@ -2441,12 +2477,14 @@ package body Sem_Decls is begin Sem_Scopes.Add_Name (Group); Xref_Decl (Group); - Template := Find_Declaration (Get_Group_Template_Name (Group), - Decl_Group_Template); - if Template = Null_Iir then + + Template_Name := Sem_Denoting_Name (Get_Group_Template_Name (Group)); + Set_Group_Template_Name (Group, Template_Name); + Template := Get_Named_Entity (Template_Name); + if Get_Kind (Template) /= Iir_Kind_Group_Template_Declaration then + Error_Class_Match (Template_Name, "group template"); return; end if; - Set_Group_Template_Name (Group, Template); Constituent_List := Get_Group_Constituent_List (Group); El_Entity := Get_Entity_Class_Entry_Chain (Template); Prev_Class := Tok_Eof; @@ -2454,6 +2492,8 @@ package body Sem_Decls is El := Get_Nth_Element (Constituent_List, I); exit when El = Null_Iir; + Sem_Name (El); + if El_Entity = Null_Iir then Error_Msg_Sem ("too many elements in group constituent list", Group); @@ -2472,9 +2512,16 @@ package body Sem_Decls is El_Entity := Get_Chain (El_Entity); end if; - Sem_Name (El, False); El_Name := Get_Named_Entity (El); - if El_Name /= Error_Mark then + if Is_Error (El_Name) then + null; + elsif Is_Overload_List (El_Name) then + Error_Overload (El_Name); + else + El := Finish_Sem_Name (El); + Replace_Nth_Element (Constituent_List, I, El); + El_Name := Get_Named_Entity (El); + -- LRM93 4.7 -- It is an error if the class of any group constituent in the -- group constituent list is not the same as the class specified @@ -2485,7 +2532,6 @@ package body Sem_Decls is ("constituent not of class '" & Tokens.Image (Class) & ''', El); end if; - Xref_Name (El); end if; end loop; @@ -2505,8 +2551,9 @@ package body Sem_Decls is is Res : Iir; begin - Res := Find_Declaration (T, Decl_Type); - if Res = Null_Iir then + Res := Sem_Type_Mark (T); + Res := Get_Type (Res); + if Is_Error (Res) then return Real_Type_Definition; end if; -- LRM93 3.5.1 @@ -2570,78 +2617,73 @@ package body Sem_Decls is end if; end Sem_Nature_Declaration; - procedure Sem_Terminal_Declaration (Decl : Iir) + procedure Sem_Terminal_Declaration (Decl : Iir; Last_Decl : Iir) is Def, Nature : Iir; begin + Sem_Scopes.Add_Name (Decl); + Xref_Decl (Decl); + Def := Get_Nature (Decl); - if Def /= Null_Iir then - Sem_Scopes.Add_Name (Decl); - Xref_Decl (Decl); - if Get_Kind (Def) = Iir_Kind_Proxy then - Nature := Get_Nature (Get_Proxy (Def)); - Free_Iir (Def); - else - Nature := Sem_Subnature_Indication (Def); - end if; - if Nature /= Null_Iir then - Set_Nature (Decl, Nature); - Sem_Scopes.Name_Visible (Decl); - end if; + if Def = Null_Iir then + Nature := Get_Nature (Last_Decl); + else + Nature := Sem_Subnature_Indication (Def); + end if; + + if Nature /= Null_Iir then + Set_Nature (Decl, Nature); + Sem_Scopes.Name_Visible (Decl); end if; end Sem_Terminal_Declaration; - procedure Sem_Branch_Quantity_Declaration (Decl : Iir) + procedure Sem_Branch_Quantity_Declaration (Decl : Iir; Last_Decl : Iir) is - Plus : Iir; - Minus : Iir; + Plus_Name : Iir; + Minus_Name : Iir; Branch_Type : Iir; Value : Iir; - Proxy : Iir; + Is_Second : Boolean; begin - Plus := Get_Plus_Terminal (Decl); - if Get_Kind (Plus) = Iir_Kind_Proxy then - Proxy := Get_Proxy (Plus); - Free_Iir (Plus); - Plus := Get_Plus_Terminal (Proxy); - Minus := Get_Minus_Terminal (Proxy); - Value := Get_Default_Value (Proxy); + Sem_Scopes.Add_Name (Decl); + Xref_Decl (Decl); + + Plus_Name := Get_Plus_Terminal (Decl); + if Plus_Name = Null_Iir then + -- List of identifier. + Is_Second := True; + Plus_Name := Get_Plus_Terminal (Last_Decl); + Minus_Name := Get_Minus_Terminal (Last_Decl); + Value := Get_Default_Value (Last_Decl); else - Plus := Find_Declaration (Plus, Decl_Terminal); - Minus := Get_Minus_Terminal (Decl); - if Minus /= Null_Iir then - Minus := Find_Declaration (Minus, Decl_Terminal); + Is_Second := False; + Plus_Name := Sem_Terminal_Name (Plus_Name); + Minus_Name := Get_Minus_Terminal (Decl); + if Minus_Name /= Null_Iir then + Minus_Name := Sem_Terminal_Name (Minus_Name); end if; - Proxy := Null_Iir; + Value := Get_Default_Value (Decl); end if; - Set_Plus_Terminal (Decl, Plus); - Set_Minus_Terminal (Decl, Minus); + Set_Plus_Terminal (Decl, Plus_Name); + Set_Minus_Terminal (Decl, Minus_Name); case Get_Kind (Decl) is when Iir_Kind_Across_Quantity_Declaration => - Branch_Type := Get_Across_Type (Get_Nature (Plus)); + Branch_Type := Get_Across_Type (Get_Nature (Plus_Name)); when Iir_Kind_Through_Quantity_Declaration => - Branch_Type := Get_Through_Type (Get_Nature (Plus)); + Branch_Type := Get_Through_Type (Get_Nature (Plus_Name)); when others => raise Program_Error; end case; Set_Type (Decl, Branch_Type); - Set_Base_Name (Decl, Decl); - if Proxy = Null_Iir then - Value := Get_Default_Value (Decl); - if Value /= Null_Iir then - Value := Sem_Expression (Value, Branch_Type); - end if; - else - Value := Get_Default_Value (Proxy); + if not Is_Second and then Value /= Null_Iir then + Value := Sem_Expression (Value, Branch_Type); end if; Set_Default_Value (Decl, Value); -- TODO: tolerance - Sem_Scopes.Add_Name (Decl); - Xref_Decl (Decl); Sem_Scopes.Name_Visible (Decl); end Sem_Branch_Quantity_Declaration; @@ -2650,7 +2692,10 @@ package body Sem_Decls is Decl: Iir; Last_Decl : Iir; Attr_Spec_Chain : Iir; - Kind : Iir_Kind; + + -- Used for list of identifiers in object declarations to get the type + -- and default value for the following declarations. + Last_Obj_Decl : Iir; -- If IS_GLOBAL is set, then declarations may be seen outside of unit. -- This must be set for entities and packages (except when @@ -2660,7 +2705,7 @@ package body Sem_Decls is case Get_Kind (Parent) is when Iir_Kind_Entity_Declaration | Iir_Kind_Package_Declaration => - Is_Global := not Flags.Flag_Whole_Analyze; + Is_Global := not Flags.Flag_Whole_Analyze; when others => Is_Global := False; end case; @@ -2669,22 +2714,27 @@ package body Sem_Decls is Decl := Get_Declaration_Chain (Parent); Last_Decl := Null_Iir; Attr_Spec_Chain := Null_Iir; + Last_Obj_Decl := Null_Iir; - loop - << Again >> exit when Decl = Null_Iir; - Kind := Get_Kind (Decl); - case Kind is + while Decl /= Null_Iir loop + case Get_Kind (Decl) is when Iir_Kind_Type_Declaration | Iir_Kind_Anonymous_Type_Declaration => Sem_Type_Declaration (Decl, Is_Global); when Iir_Kind_Subtype_Declaration => Sem_Subtype_Declaration (Decl, Is_Global); when Iir_Kind_Signal_Declaration => - Sem_Object_Declaration (Decl, Parent); + Sem_Object_Declaration (Decl, Parent, Last_Obj_Decl); + Last_Obj_Decl := Decl; when Iir_Kind_Constant_Declaration => - Sem_Object_Declaration (Decl, Parent); + Sem_Object_Declaration (Decl, Parent, Last_Obj_Decl); + Last_Obj_Decl := Decl; when Iir_Kind_Variable_Declaration => - Sem_Object_Declaration (Decl, Parent); + Sem_Object_Declaration (Decl, Parent, Last_Obj_Decl); + Last_Obj_Decl := Decl; + when Iir_Kind_File_Declaration => + Sem_File_Declaration (Decl, Last_Obj_Decl); + Last_Obj_Decl := Decl; when Iir_Kind_Attribute_Declaration => Sem_Attribute_Declaration (Decl); when Iir_Kind_Attribute_Specification => @@ -2695,31 +2745,15 @@ package body Sem_Decls is end if; when Iir_Kind_Component_Declaration => Sem_Component_Declaration (Decl); - when Iir_Kind_Function_Declaration - | Iir_Kind_Procedure_Declaration => - declare - Res : Iir; - begin - Res := Sem_Subprogram_Declaration (Decl); - if Res /= Decl then - -- Replace DECL with RES. - if Last_Decl = Null_Iir then - Set_Declaration_Chain (Parent, Res); - else - Set_Chain (Last_Decl, Res); - end if; - Decl := Res; - -- Since RES is a body, no need to check for post - -- attribute specification. - goto Again; - end if; - if Is_Global - and then Kind = Iir_Kind_Function_Declaration - and then Is_A_Resolution_Function (Res, Null_Iir) - then - Set_Resolution_Function_Flag (Res, True); - end if; - end; + when Iir_Kind_Function_Declaration => + Sem_Subprogram_Declaration (Decl); + if Is_Global + and then Is_A_Resolution_Function (Decl, Null_Iir) + then + Set_Resolution_Function_Flag (Decl, True); + end if; + when Iir_Kind_Procedure_Declaration => + Sem_Subprogram_Declaration (Decl); when Iir_Kind_Function_Body | Iir_Kind_Procedure_Body => Sem_Subprogram_Body (Decl); @@ -2750,14 +2784,12 @@ package body Sem_Decls is -- apply to them. end if; end; - when Iir_Kind_File_Declaration => - Sem_File_Declaration (Decl); when Iir_Kind_Use_Clause => Sem_Use_Clause (Decl); when Iir_Kind_Configuration_Specification => null; when Iir_Kind_Disconnection_Specification => - Sem_Disconnect_Specification (Decl); + Sem_Disconnection_Specification (Decl); when Iir_Kind_Group_Template_Declaration => Sem_Group_Template_Declaration (Decl); when Iir_Kind_Group_Declaration => @@ -2770,10 +2802,12 @@ package body Sem_Decls is when Iir_Kind_Nature_Declaration => Sem_Nature_Declaration (Decl); when Iir_Kind_Terminal_Declaration => - Sem_Terminal_Declaration (Decl); + Sem_Terminal_Declaration (Decl, Last_Obj_Decl); + Last_Obj_Decl := Decl; when Iir_Kind_Across_Quantity_Declaration | Iir_Kind_Through_Quantity_Declaration => - Sem_Branch_Quantity_Declaration (Decl); + Sem_Branch_Quantity_Declaration (Decl, Last_Obj_Decl); + Last_Obj_Decl := Decl; when others => Error_Kind ("sem_declaration_chain", Decl); end case; @@ -2900,7 +2934,9 @@ package body Sem_Decls is case Get_Kind (El) is when Iir_Kind_Function_Declaration | Iir_Kind_Procedure_Declaration => - if not Get_Use_Flag (El) then + if not Get_Use_Flag (El) + and then not Is_Second_Subprogram_Specification (El) + then Warning_Msg_Sem (Disp_Node (El) & " is never referenced", El); end if; @@ -2916,33 +2952,22 @@ package body Sem_Decls is procedure Sem_Iterator (Iterator : Iir_Iterator_Declaration; Staticness : Iir_Staticness) is - It_Type: Iir; + It_Type: constant Iir := Get_Discrete_Range (Iterator); A_Range: Iir; - Range_Type : Iir; begin Xref_Decl (Iterator); - It_Type := Get_Type (Iterator); + A_Range := Sem_Discrete_Range_Integer (It_Type); if A_Range = Null_Iir then - Set_Type (Iterator, Create_Error_Type (Iterator)); + Set_Type (Iterator, Create_Error_Type (It_Type)); return; end if; - if Get_Kind (A_Range) in Iir_Kinds_Type_And_Subtype_Definition then - Range_Type := A_Range; - else - Range_Type := Get_Type (A_Range); - end if; - case Get_Kind (Range_Type) is - when Iir_Kinds_Discrete_Type_Definition => - null; - when others => - Error_Msg_Sem ("iterator is not of discrete type", A_Range); - Set_Type (Iterator, Null_Iir); - return; - end case; - Set_Type (Iterator, Range_To_Subtype_Definition (A_Range)); - Set_Base_Name (Iterator, Iterator); + Set_Discrete_Range (Iterator, A_Range); + + Set_Type (Iterator, + Get_Type_Of_Subtype_Indication + (Range_To_Subtype_Indication (A_Range))); Set_Expr_Staticness (Iterator, Staticness); end Sem_Iterator; end Sem_Decls; diff --git a/sem_expr.adb b/sem_expr.adb index c77170a14..6100150e2 100644 --- a/sem_expr.adb +++ b/sem_expr.adb @@ -335,6 +335,7 @@ package body Sem_Expr is when Iir_Kind_Overload_List => return Expr; when Iir_Kinds_Literal + | Iir_Kind_Character_Literal | Iir_Kind_Simple_Aggregate | Iir_Kind_Unit_Declaration | Iir_Kind_Enumeration_Literal => @@ -404,8 +405,8 @@ package body Sem_Expr is Targ_Indexes := Get_Index_Subtype_List (Targ_Type); Expr_Indexes := Get_Index_Subtype_List (Expr_Type); for I in Natural loop - Targ_Index := Get_Nth_Element (Targ_Indexes, I); - Expr_Index := Get_Nth_Element (Expr_Indexes, I); + Targ_Index := Get_Index_Type (Targ_Indexes, I); + Expr_Index := Get_Index_Type (Expr_Indexes, I); exit when Targ_Index = Null_Iir and Expr_Index = Null_Iir; if Targ_Index = Null_Iir or Expr_Index = Null_Iir then -- Types does not match. @@ -506,115 +507,139 @@ package body Sem_Expr is Expr_Type : Iir; begin Expr_Type := Get_Type (Expr); + Left := Get_Left_Limit (Expr); + Right := Get_Right_Limit (Expr); if Expr_Type = Null_Iir then - -- EXPR has the form: 'range L to/downto R' - Expr_Type := A_Type; - elsif Get_Kind (Expr_Type) not in Iir_Kinds_Scalar_Type_Definition then - -- EXPR has the form: 'NAME range L to/downto R', but NAME may - -- have already be analyzed. - Expr_Type := Find_Declaration (Expr_Type, Decl_Type); - if A_Type /= Null_Iir and then A_Type /= Expr_Type then - -- This can happend when EXPR is an array subtype index subtype - -- and A_TYPE is the array index type. - Error_Msg_Sem ("subtype " & Disp_Node (Expr_Type) - & " doesn't match expected type " - & Disp_Node (A_Type), Expr); - end if; - end if; + -- Pass 1. - if Expr_Type /= Null_Iir then - Base_Type := Get_Base_Type (Expr_Type); - else - Base_Type := Null_Iir; - end if; + if A_Type = Null_Iir then + Base_Type := Null_Iir; + else + Base_Type := Get_Base_Type (A_Type); + end if; - -- Analyze left and right bounds. - Left := Get_Left_Limit (Expr); - Right := Get_Right_Limit (Expr); - Right := Sem_Expression_Ov (Right, Base_Type); - Left := Sem_Expression_Ov (Left, Base_Type); - if Left = Null_Iir or else Right = Null_Iir then - return Null_Iir; - end if; + -- Analyze left and right bounds. + Right := Sem_Expression_Ov (Right, Base_Type); + Left := Sem_Expression_Ov (Left, Base_Type); - Left_Type := Get_Type (Left); - Right_Type := Get_Type (Right); - -- Check for string or aggregate literals - -- FIXME: improve error message - if Left_Type = Null_Iir then - Error_Msg_Sem ("bad expression for a scalar", Left); - return Null_Iir; - end if; - if Right_Type = Null_Iir then - Error_Msg_Sem ("bad expression for a scalar", Right); - return Null_Iir; - end if; + if Left = Null_Iir or else Right = Null_Iir then + -- Error. + return Null_Iir; + end if; - if Is_Overload_List (Left_Type) - or else Is_Overload_List (Right_Type) - then - if Base_Type /= Null_Iir then - -- Cannot happen, since sem_expression_ov should resolved - -- ambiguties if a type is given. - raise Internal_Error; + Left_Type := Get_Type (Left); + Right_Type := Get_Type (Right); + -- Check for string or aggregate literals + -- FIXME: improve error message + if Left_Type = Null_Iir then + Error_Msg_Sem ("bad expression for a scalar", Left); + return Null_Iir; + end if; + if Right_Type = Null_Iir then + Error_Msg_Sem ("bad expression for a scalar", Right); + return Null_Iir; end if; - -- Try to find a common type. - Base_Type := Search_Compatible_Type (Left_Type, Right_Type); - if Base_Type = Null_Iir then - if Compatibility_Types1 (Universal_Integer_Type_Definition, - Left_Type) - and then - Compatibility_Types1 (Universal_Integer_Type_Definition, - Right_Type) - then - Base_Type := Universal_Integer_Type_Definition; - elsif Compatibility_Types1 (Universal_Real_Type_Definition, + if Is_Overload_List (Left_Type) + or else Is_Overload_List (Right_Type) + then + if Base_Type /= Null_Iir then + -- Cannot happen, since sem_expression_ov should resolve + -- ambiguties if a type is given. + raise Internal_Error; + end if; + + -- Try to find a common type. + Expr_Type := Search_Compatible_Type (Left_Type, Right_Type); + if Expr_Type = Null_Iir then + if Compatibility_Types1 (Universal_Integer_Type_Definition, Left_Type) - and then - Compatibility_Types1 (Universal_Real_Type_Definition, - Right_Type) - then - Base_Type := Universal_Real_Type_Definition; - else + and then + Compatibility_Types1 (Universal_Integer_Type_Definition, + Right_Type) + then + Expr_Type := Universal_Integer_Type_Definition; + elsif Compatibility_Types1 (Universal_Real_Type_Definition, + Left_Type) + and then + Compatibility_Types1 (Universal_Real_Type_Definition, + Right_Type) + then + Expr_Type := Universal_Real_Type_Definition; + else + -- FIXME: handle overload + Error_Msg_Sem + ("left and right expressions of range are not compatible", + Expr); + return Null_Iir; + end if; + end if; + Left := Sem_Expression (Left, Expr_Type); + Right := Sem_Expression (Right, Expr_Type); + if Left = Null_Iir or else Right = Null_Iir then + return Null_Iir; + end if; + else + Expr_Type := Get_Common_Basetype (Get_Base_Type (Left_Type), + Get_Base_Type (Right_Type)); + if Expr_Type = Null_Iir then Error_Msg_Sem ("left and right expressions of range are not compatible", Expr); return Null_Iir; end if; end if; - Base_Type := Get_Base_Type (Base_Type); - Left := Sem_Expression (Left, Base_Type); - Right := Sem_Expression (Right, Base_Type); - if Left = Null_Iir or else Right = Null_Iir then - return Null_Iir; + + -- The type of the range is known, finish analysis. + else + -- Second call. + + pragma Assert (A_Type /= Null_Iir); + + if Is_Overload_List (Expr_Type) then + -- FIXME: resolve overload + raise Internal_Error; + else + if not Are_Types_Compatible (Expr_Type, A_Type) then + Error_Msg_Sem + ("type of range doesn't match expected type", Expr); + return Null_Iir; + end if; + + return Expr; end if; end if; + Left := Eval_Expr_If_Static (Left); Right := Eval_Expr_If_Static (Right); Set_Left_Limit (Expr, Left); Set_Right_Limit (Expr, Right); Set_Expr_Staticness (Expr, Min (Get_Expr_Staticness (Left), Get_Expr_Staticness (Right))); - if Expr_Type /= Null_Iir then - Set_Type (Expr, Base_Type); - if Get_Expr_Staticness (Expr) = Locally - and then Get_Type_Staticness (Expr_Type) = Locally - and then Get_Kind (Expr_Type) in Iir_Kinds_Subtype_Definition - then - Eval_Check_Range (Expr, Expr_Type, Any_Dir); - end if; - else - Base_Type := Get_Common_Basetype (Get_Base_Type (Get_Type (Left)), - Get_Base_Type (Get_Type (Right))); - if Base_Type = Null_Iir then - Error_Msg_Sem - ("left and right expressions of range are not compatible", Expr); - return Null_Iir; - end if; - Set_Type (Expr, Base_Type); + + if A_Type /= Null_Iir + and then not Are_Types_Compatible (Expr_Type, A_Type) + then + Error_Msg_Sem ("type of range doesn't match expected type", Expr); + return Null_Iir; + end if; + + Set_Type (Expr, Expr_Type); + if Get_Kind (Get_Base_Type (Expr_Type)) + not in Iir_Kinds_Scalar_Type_Definition + then + Error_Msg_Sem ("type of range is not a scalar type", Expr); + return Null_Iir; end if; + + if Get_Expr_Staticness (Expr) = Locally + and then Get_Type_Staticness (Expr_Type) = Locally + and then Get_Kind (Expr_Type) in Iir_Kinds_Subtype_Definition + then + Eval_Check_Range (Expr, Expr_Type, Any_Dir); + end if; + return Expr; end Sem_Simple_Range_Expression; @@ -625,77 +650,70 @@ package body Sem_Expr is -- LRM93 3.2.1.1 -- FIXME: avoid to run it on an already semantized node, be careful -- with range_type_expr. - function Sem_Range_Expression - (Expr: Iir; A_Type: Iir; Any_Dir : Boolean) - return Iir + function Sem_Range_Expression (Expr: Iir; A_Type: Iir; Any_Dir : Boolean) + return Iir is Res : Iir; Res_Type : Iir; begin - if Get_Kind (Expr) = Iir_Kind_Range_Expression then - Res := Sem_Simple_Range_Expression (Expr, A_Type, Any_Dir); - if Res = Null_Iir then - return Null_Iir; - end if; - Res_Type := Get_Type (Res); - else - if Get_Kind (Expr) in Iir_Kinds_Name - or else Get_Kind (Expr) = Iir_Kind_Attribute_Name - then - Sem_Name (Expr, False); - Maybe_Finish_Sem_Name (Expr); - Res := Get_Named_Entity (Expr); + case Get_Kind (Expr) is + when Iir_Kind_Range_Expression => + Res := Sem_Simple_Range_Expression (Expr, A_Type, Any_Dir); + if Res = Null_Iir then + return Null_Iir; + end if; + Res_Type := Get_Type (Res); + + when Iir_Kinds_Denoting_Name + | Iir_Kind_Attribute_Name + | Iir_Kind_Parenthesis_Name => + if Get_Named_Entity (Expr) = Null_Iir then + Sem_Name (Expr); + end if; + Res := Name_To_Range (Expr); if Res = Error_Mark then return Null_Iir; end if; - Xref_Name (Expr); - else - Res := Expr; - end if; - case Get_Kind (Res) is - when Iir_Kind_Type_Declaration => - Res := Get_Type_Definition (Res); - Res_Type := Res; - when Iir_Kind_Subtype_Declaration => - Res := Get_Type (Res); - Res_Type := Res; - when Iir_Kind_Range_Array_Attribute - | Iir_Kind_Reverse_Range_Array_Attribute => - Res_Type := Get_Type (Res); - Res := Eval_Expr_If_Static (Res); - when others => - Error_Msg_Sem ("name must denote a range", Expr); + case Get_Kind (Res) is + when Iir_Kind_Simple_Name + | Iir_Kind_Selected_Name => + pragma Assert (Get_Kind (Get_Named_Entity (Res)) + in Iir_Kinds_Type_Declaration); + Res_Type := Get_Type (Get_Named_Entity (Res)); + when Iir_Kind_Range_Array_Attribute + | Iir_Kind_Reverse_Range_Array_Attribute => + Res_Type := Get_Type (Res); + when others => + Error_Msg_Sem ("name must denote a range", Expr); + return Null_Iir; + end case; + if A_Type /= Null_Iir + and then Get_Base_Type (Res_Type) /= Get_Base_Type (A_Type) + then + Not_Match (Expr, A_Type); return Null_Iir; - end case; - if A_Type /= Null_Iir - and then Get_Base_Type (Res_Type) /= Get_Base_Type (A_Type) - then - Not_Match (Expr, A_Type); + end if; + + when others => + Error_Msg_Sem ("range expression required", Expr); return Null_Iir; - end if; - end if; + end case; if Get_Kind (Res_Type) not in Iir_Kinds_Scalar_Type_Definition then Error_Msg_Sem (Disp_Node (Res) & " is not a range type", Expr); return Null_Iir; end if; + Res := Eval_Range_If_Static (Res); + if A_Type /= Null_Iir and then Get_Type_Staticness (A_Type) = Locally and then Get_Kind (A_Type) in Iir_Kinds_Subtype_Definition then - case Get_Kind (Res) is - when Iir_Kinds_Type_And_Subtype_Definition => - if Get_Type_Staticness (Res) = Locally then - Eval_Check_Range - (Get_Range_Constraint (Res), A_Type, Any_Dir); - end if; - when others => - if Get_Expr_Staticness (Res) = Locally then - Eval_Check_Range (Res, A_Type, Any_Dir); - end if; - end case; + if Get_Expr_Staticness (Res) = Locally then + Eval_Check_Range (Res, A_Type, Any_Dir); + end if; end if; return Res; end Sem_Range_Expression; @@ -707,21 +725,45 @@ package body Sem_Expr is Res : Iir; Res_Type : Iir; begin - Res := Sem_Range_Expression (Expr, A_Type, Any_Dir); - - if Res = Null_Iir then - return Null_Iir; - end if; + if Get_Kind (Expr) = Iir_Kind_Subtype_Definition then + Res := Sem_Types.Sem_Subtype_Indication (Expr); + if Res = Null_Iir then + return Null_Iir; + end if; - if Get_Kind (Res) in Iir_Kinds_Type_And_Subtype_Definition then Res_Type := Res; + if A_Type /= Null_Iir + and then (not Are_Types_Compatible + (A_Type, Get_Type_Of_Subtype_Indication (Res))) + then + -- A_TYPE is known when analyzing an index_constraint within + -- a subtype indication. + Error_Msg_Sem ("subtype " & Disp_Node (Res) + & " doesn't match expected type " + & Disp_Node (A_Type), Expr); + -- FIXME: override type of RES ? + end if; else + Res := Sem_Range_Expression (Expr, A_Type, Any_Dir); + + if Res = Null_Iir then + return Null_Iir; + end if; + Res_Type := Get_Type (Res); end if; + -- Check the type is discrete. if Get_Kind (Res_Type) not in Iir_Kinds_Discrete_Type_Definition then - Error_Msg_Sem - (Disp_Node (Res) & " is not a discrete range type", Expr); + if Get_Kind (Res_Type) /= Iir_Kind_Error then + -- FIXME: avoid that test with error. + if Get_Kind (Res) not in Iir_Kinds_Denoting_Name then + Error_Msg_Sem ("range is not discrete", Res); + else + Error_Msg_Sem + (Disp_Node (Res) & " is not a discrete range type", Expr); + end if; + end if; return Null_Iir; end if; @@ -779,15 +821,6 @@ package body Sem_Expr is return Expr; end Sem_Discrete_Range_Integer; - function Get_Discrete_Range_Staticness (Expr : Iir) return Iir_Staticness is - begin - if Get_Kind (Expr) in Iir_Kinds_Discrete_Type_Definition then - return Get_Type_Staticness (Expr); - else - return Get_Expr_Staticness (Expr); - end if; - end Get_Discrete_Range_Staticness; - procedure Set_Function_Call_Staticness (Expr : Iir; Imp : Iir) is Staticness : Iir_Staticness; @@ -1097,7 +1130,6 @@ package body Sem_Expr is is Subprg : constant Iir := Get_Current_Subprogram; begin - Set_Implementation (Expr, Imp); Set_Function_Call_Staticness (Expr, Imp); Set_Use_Flag (Imp, True); @@ -1150,6 +1182,7 @@ package body Sem_Expr is (Expr : Iir; A_Type : Iir; Is_Func_Call : Boolean) return Iir is + Imp : constant Iir := Get_Implementation (Expr); Nbr_Inter: Natural; A_Func: Iir; Imp_List: Iir_List; @@ -1162,7 +1195,7 @@ package body Sem_Expr is -- Sem_Name has gathered all the possible names for the prefix of this -- call. Reduce this list to only names that match the types. Nbr_Inter := 0; - Imp_List := Get_Overload_List (Get_Implementation (Expr)); + Imp_List := Get_Overload_List (Get_Named_Entity (Imp)); Assoc_Chain := Get_Parameter_Association_Chain (Expr); for I in Natural loop @@ -1215,7 +1248,7 @@ package body Sem_Expr is when 1 => -- Simple case: no overloading. Inter := Get_First_Element (Imp_List); - Free_Iir (Get_Implementation (Expr)); + Free_Iir (Get_Named_Entity (Imp)); if Is_Func_Call then Set_Type (Expr, Get_Return_Type (Inter)); end if; @@ -1228,6 +1261,7 @@ package body Sem_Expr is raise Internal_Error; end if; Check_Subprogram_Associations (Inter_Chain, Assoc_Chain); + Set_Named_Entity (Imp, Inter); Sem_Subprogram_Call_Finish (Expr, Inter); return Expr; @@ -1292,7 +1326,7 @@ package body Sem_Expr is -- NOTE: the list of possible implementations was already created -- during the transformation of iir_kind_parenthesis_name to -- iir_kind_function_call. - Inter_List := Get_Implementation (Expr); + Inter_List := Get_Named_Entity (Get_Implementation (Expr)); if Get_Kind (Inter_List) = Iir_Kind_Error then return Null_Iir; elsif Is_Overload_List (Inter_List) then @@ -1329,6 +1363,7 @@ package body Sem_Expr is Set_Type (Expr, Get_Return_Type (Inter_List)); end if; Check_Subprogram_Associations (Param_Chain, Assoc_Chain); + Set_Named_Entity (Get_Implementation (Expr), Inter_List); Sem_Subprogram_Call_Finish (Expr, Inter_List); return Expr; end if; @@ -1403,6 +1438,7 @@ package body Sem_Expr is return Null_Iir; end if; Check_Subprogram_Associations (Param_Chain, Assoc_Chain); + Set_Named_Entity (Get_Implementation (Expr), Res); Sem_Subprogram_Call_Finish (Expr, Res); return Expr; end Sem_Subprogram_Call; @@ -1417,12 +1453,17 @@ package body Sem_Expr is Prefix : Iir; Inter : Iir; begin - Name := Get_Implementation (Call); - Sem_Name (Name, False); + Name := Get_Prefix (Call); + -- FIXME: check for denoting name. + Sem_Name (Name); + Set_Implementation (Call, Name); + + -- Return now if the procedure declaration wasn't found. Imp := Get_Named_Entity (Name); - if Imp = Null_Iir then + if Is_Error (Imp) then return; end if; + Name_To_Method_Object (Call, Name); Parameters_Chain := Get_Parameter_Association_Chain (Call); if Sem_Actual_Of_Association_Chain (Parameters_Chain) = False then @@ -1431,14 +1472,13 @@ package body Sem_Expr is if Sem_Subprogram_Call (Call, Null_Iir) /= Call then return; end if; - Imp := Get_Implementation (Call); + Imp := Get_Named_Entity (Get_Implementation (Call)); if Is_Overload_List (Imp) then -- Failed to resolve overload. return; end if; Set_Named_Entity (Name, Imp); - Xref_Name (Name); - Free_Name (Name); + Set_Prefix (Call, Finish_Sem_Name (Name)); -- LRM 2.1.1.2 Signal Parameters -- A process statement contains a driver for each actual signal @@ -1463,7 +1503,7 @@ package body Sem_Expr is then Prefix := Name_To_Object (Get_Actual (Param)); if Prefix /= Null_Iir then - case Get_Kind (Get_Base_Name (Prefix)) is + case Get_Kind (Get_Object_Prefix (Prefix)) is when Iir_Kind_Signal_Declaration | Iir_Kind_Signal_Interface_Declaration => Prefix := Get_Longuest_Static_Prefix (Prefix); @@ -1508,8 +1548,8 @@ package body Sem_Expr is if Get_Kind (El) = Iir_Kind_Implicit_Function_Declaration then Ref_Type := Get_Type_Reference (El); - if Ref_Type = Universal_Integer_Type - or Ref_Type = Universal_Real_Type + if Ref_Type = Universal_Integer_Type_Declaration + or Ref_Type = Universal_Real_Type_Declaration then if Res = Null_Iir then Res := El; @@ -1624,6 +1664,7 @@ package body Sem_Expr is end if; Destroy_Iir_List (Overload_List); if not Err then + Set_Implementation (Expr, Decl); Sem_Subprogram_Call_Finish (Expr, Decl); return Eval_Expr_If_Static (Expr); else @@ -1917,8 +1958,7 @@ package body Sem_Expr is if Get_Constraint_State (Lit_Type) = Fully_Constrained then -- The type of the context is constrained. - Index_Type := Get_First_Element - (Get_Index_Subtype_List (Lit_Type)); + Index_Type := Get_Index_Type (Lit_Type, 0); if Get_Type_Staticness (Index_Type) = Locally then if Eval_Discrete_Type_Length (Index_Type) /= Iir_Int64 (Len) then Error_Msg_Sem ("string length does not match that of " @@ -2186,20 +2226,6 @@ package body Sem_Expr is end if; end Sem_String_Choices_Range; - function Is_Choice_Name (Name : Iir) return Boolean - is - begin - case Get_Kind (Name) is - when Iir_Kind_Simple_Name - | Iir_Kind_Selected_Name - | Iir_Kind_Attribute_Name - | Iir_Kind_Parenthesis_Name => - return True; - when others => - return False; - end case; - end Is_Choice_Name; - procedure Sem_Choices_Range (Choice_Chain : in out Iir; Sub_Type : Iir; @@ -2235,69 +2261,89 @@ package body Sem_Expr is -- Staticness of all the choices. Staticness : Iir_Staticness; + function Replace_By_Range_Choice (Name : Iir; Range_Type : Iir) + return Boolean + is + N_Choice : Iir; + Name1 : Iir; + begin + if not Are_Types_Compatible (Range_Type, Sub_Type) then + Not_Match (Name, Sub_Type); + return False; + end if; + + Name1 := Finish_Sem_Name (Name); + N_Choice := Create_Iir (Iir_Kind_Choice_By_Range); + Location_Copy (N_Choice, El); + Set_Chain (N_Choice, Get_Chain (El)); + Set_Associated (N_Choice, Get_Associated (El)); + Set_Same_Alternative_Flag (N_Choice, Get_Same_Alternative_Flag (El)); + Set_Expression (N_Choice, Eval_Range_If_Static (Name1)); + Set_Choice_Staticness (N_Choice, Get_Type_Staticness (Range_Type)); + Free_Iir (El); + + if Prev_El = Null_Iir then + Choice_Chain := N_Choice; + else + Set_Chain (Prev_El, N_Choice); + end if; + El := N_Choice; + + return True; + end Replace_By_Range_Choice; + -- Semantize a simple (by expression or by range) choice. -- Return FALSE in case of error. function Sem_Simple_Choice return Boolean is Expr : Iir; + Ent : Iir; begin Expr := Get_Expression (El); if Get_Kind (El) = Iir_Kind_Choice_By_Range then Expr := Sem_Discrete_Range_Expression (Expr, Sub_Type, True); - elsif Is_Choice_Name (Expr) then - declare - Name : Iir; - N_Choice : Iir; - begin - Sem_Name (Expr, False); - Name := Get_Named_Entity (Expr); - case Get_Kind (Name) is - when Iir_Kind_Type_Declaration - | Iir_Kind_Subtype_Declaration => - Xref_Name (Expr); - Name := Get_Type (Name); - when others => - null; - end case; - case Get_Kind (Name) is - when Iir_Kinds_Type_And_Subtype_Definition - | Iir_Kind_Range_Array_Attribute - | Iir_Kind_Reverse_Range_Array_Attribute => - if not Are_Types_Compatible (Name, Sub_Type) then - Not_Match (Name, Sub_Type); - return False; - end if; - N_Choice := Create_Iir (Iir_Kind_Choice_By_Range); - Location_Copy (N_Choice, El); - Set_Chain (N_Choice, Get_Chain (El)); - Set_Associated (N_Choice, Get_Associated (El)); - Set_Same_Alternative_Flag - (N_Choice, Get_Same_Alternative_Flag (El)); - Set_Expression (N_Choice, Eval_Range (Name)); - Set_Choice_Staticness - (N_Choice, Get_Type_Staticness (Name)); - Free_Iir (El); - if Prev_El = Null_Iir then - Choice_Chain := N_Choice; - else - Set_Chain (Prev_El, N_Choice); - end if; - El := N_Choice; - return True; - when Iir_Kind_Error => - return False; - when others => - Expr := Name_To_Expression - (Expr, Get_Base_Type (Sub_Type)); - end case; - end; + if Expr = Null_Iir then + return False; + end if; + Expr := Eval_Range_If_Static (Expr); else - Expr := Sem_Expression_Ov (Expr, Get_Base_Type (Sub_Type)); - end if; - if Expr = Null_Iir then - return False; + case Get_Kind (Expr) is + when Iir_Kind_Selected_Name + | Iir_Kind_Simple_Name + | Iir_Kind_Character_Literal + | Iir_Kind_Parenthesis_Name + | Iir_Kind_Selected_By_All_Name + | Iir_Kind_Attribute_Name => + Sem_Name (Expr); + Ent := Get_Named_Entity (Expr); + if Ent = Error_Mark then + return False; + end if; + + -- So range or expression ? + -- FIXME: share code with sem_name for slice/index. + case Get_Kind (Ent) is + when Iir_Kind_Range_Array_Attribute + | Iir_Kind_Reverse_Range_Array_Attribute + | Iir_Kind_Range_Expression => + return Replace_By_Range_Choice (Expr, Ent); + when Iir_Kind_Subtype_Declaration + | Iir_Kind_Type_Declaration => + Ent := Is_Type_Name (Expr); + Set_Expr_Staticness (Expr, Get_Type_Staticness (Ent)); + return Replace_By_Range_Choice (Expr, Ent); + when others => + Expr := Name_To_Expression + (Expr, Get_Base_Type (Sub_Type)); + end case; + when others => + Expr := Sem_Expression_Ov (Expr, Get_Base_Type (Sub_Type)); + end case; + if Expr = Null_Iir then + return False; + end if; + Expr := Eval_Expr_If_Static (Expr); end if; - Expr := Eval_Expr_If_Static (Expr); Set_Expression (El, Expr); Set_Choice_Staticness (El, Get_Expr_Staticness (Expr)); return True; @@ -2954,7 +3000,7 @@ package body Sem_Expr is Info : Array_Aggr_Info renames Infos (Dim); begin Index_List := Get_Index_Subtype_List (A_Type); - Index_Type := Get_Nth_Element (Index_List, Dim - 1); + Index_Type := Get_Index_Type (Index_List, Dim - 1); -- Sem choices. case Get_Kind (Aggr) is @@ -3119,6 +3165,7 @@ package body Sem_Expr is Set_Range_Constraint (Info.Index_Subtype, Index_Subtype_Constraint); Set_Type_Staticness (Info.Index_Subtype, Choice_Staticness); + Set_Expr_Staticness (Index_Subtype_Constraint, Choice_Staticness); -- LRM93 7.3.2.2 -- For an aggregate that has named associations, the leftmost and @@ -3394,39 +3441,45 @@ package body Sem_Expr is -- literal is created. function Sem_Physical_Literal (Lit: Iir) return Iir is - Decl: Iir; - Decl_Type : Iir; + Unit_Name : Iir; + Unit_Type : Iir; Res: Iir; begin case Get_Kind (Lit) is when Iir_Kind_Physical_Int_Literal | Iir_Kind_Physical_Fp_Literal => - Decl := Find_Declaration (Get_Unit_Name (Lit), Decl_Unit); + Unit_Name := Get_Unit_Name (Lit); Res := Lit; when Iir_Kind_Unit_Declaration => Res := Create_Iir (Iir_Kind_Physical_Int_Literal); Location_Copy (Res, Lit); Set_Value (Res, 1); - Decl := Lit; - when others => + Unit_Name := Null_Iir; + raise Program_Error; + when Iir_Kinds_Denoting_Name => Res := Create_Iir (Iir_Kind_Physical_Int_Literal); Location_Copy (Res, Lit); Set_Value (Res, 1); - Decl := Find_Declaration (Lit, Decl_Unit); + Unit_Name := Lit; + when others => + Error_Kind ("sem_physical_literal", Lit); end case; - if Decl = Null_Iir then - return Null_Iir; + Unit_Name := Sem_Denoting_Name (Unit_Name); + if Get_Kind (Get_Named_Entity (Unit_Name)) /= Iir_Kind_Unit_Declaration + then + Error_Class_Match (Unit_Name, "unit"); + Set_Named_Entity (Unit_Name, Create_Error_Name (Unit_Name)); end if; - Set_Unit_Name (Res, Decl); - Decl_Type := Get_Type (Decl); - Set_Type (Res, Decl_Type); + Set_Unit_Name (Res, Unit_Name); + Unit_Type := Get_Type (Unit_Name); + Set_Type (Res, Unit_Type); -- LRM93 7.4.2 -- 1. a literal of type TIME. -- -- LRM93 7.4.1 -- 1. a literal of any type other than type TIME; - Set_Expr_Staticness (Res, Get_Expr_Staticness (Decl)); + Set_Expr_Staticness (Res, Get_Expr_Staticness (Unit_Name)); --Eval_Check_Constraints (Res); return Res; end Sem_Physical_Literal; @@ -3437,7 +3490,6 @@ package body Sem_Expr is Arg: Iir; Arg_Type : Iir; begin - Arg := Get_Expression (Expr); Set_Expr_Staticness (Expr, None); Arg_Type := Get_Allocator_Designated_Type (Expr); @@ -3446,21 +3498,24 @@ package body Sem_Expr is -- Expression was not analyzed. case Iir_Kinds_Allocator (Get_Kind (Expr)) is when Iir_Kind_Allocator_By_Expression => - if Get_Kind (Arg) /= Iir_Kind_Qualified_Expression then - raise Internal_Error; - end if; + Arg := Get_Expression (Expr); + pragma Assert (Get_Kind (Arg) = Iir_Kind_Qualified_Expression); Arg := Sem_Expression (Arg, Null_Iir); if Arg = Null_Iir then return Null_Iir; end if; Check_Read (Arg); + Set_Expression (Expr, Arg); Arg_Type := Get_Type (Arg); when Iir_Kind_Allocator_By_Subtype => + Arg := Get_Subtype_Indication (Expr); Arg := Sem_Types.Sem_Subtype_Indication (Arg); + Set_Subtype_Indication (Expr, Arg); + Arg := Get_Type_Of_Subtype_Indication (Arg); if Arg = Null_Iir then return Null_Iir; end if; - -- LRM93 §7.3.6 + -- LRM93 7.3.6 -- If an allocator includes a subtype indication and if the -- type of the object created is an array type, then the -- subtype indication must either denote a constrained @@ -3481,7 +3536,6 @@ package body Sem_Expr is end if; Arg_Type := Arg; end case; - Set_Expression (Expr, Arg); Set_Allocator_Designated_Type (Expr, Arg_Type); end if; @@ -3587,7 +3641,8 @@ package body Sem_Expr is | Iir_Kind_Allocator_By_Expression | Iir_Kind_Allocator_By_Subtype | Iir_Kind_Implicit_Dereference - | Iir_Kind_Dereference => + | Iir_Kind_Dereference + | Iir_Kind_Attribute_Name => return; when Iir_Kinds_Scalar_Type_Attribute | Iir_Kinds_Type_Attribute @@ -3604,7 +3659,9 @@ package body Sem_Expr is when Iir_Kind_Indexed_Name | Iir_Kind_Slice_Name | Iir_Kind_Selected_Element => - Obj := Get_Base_Name (Obj); + -- FIXME: speed up using Base_Name + -- Obj := Get_Base_Name (Obj); + Obj := Get_Prefix (Obj); when Iir_Kind_Simple_Name | Iir_Kind_Selected_Name => Obj := Get_Named_Entity (Obj); @@ -3707,7 +3764,7 @@ package body Sem_Expr is begin E := Get_Named_Entity (Expr); if E = Null_Iir then - Sem_Name (Expr, False); + Sem_Name (Expr); E := Get_Named_Entity (Expr); if E = Null_Iir then raise Internal_Error; @@ -3854,12 +3911,9 @@ package body Sem_Expr is N_Type: Iir; Res: Iir; begin - N_Type := Sem_Types.Sem_Subtype_Indication - (Get_Type_Mark (Expr)); - if N_Type = Null_Iir then - return Null_Iir; - end if; + N_Type := Sem_Type_Mark (Get_Type_Mark (Expr)); Set_Type_Mark (Expr, N_Type); + N_Type := Get_Type (N_Type); Set_Type (Expr, N_Type); if A_Type /= Null_Iir and then not Are_Types_Compatible (A_Type, N_Type) diff --git a/sem_expr.ads b/sem_expr.ads index d8c006b95..a0422e727 100644 --- a/sem_expr.ads +++ b/sem_expr.ads @@ -88,8 +88,7 @@ package Sem_Expr is return Boolean; -- For a procedure call, A_TYPE must be null. - function Sem_Subprogram_Call (Expr: Iir; A_Type: Iir) - return Iir; + function Sem_Subprogram_Call (Expr: Iir; A_Type: Iir) return Iir; -- If EXPR is a node for an expression, then return EXPR. -- Otherwise, emit an error message using LOC as location @@ -98,30 +97,31 @@ package Sem_Expr is function Check_Is_Expression (Expr : Iir; Loc : Iir) return Iir; -- Semantize a procedure_call or a concurrent_procedure_call_statement. + -- A procedure call is not an expression but because most of the code + -- for procedure call is common with function call, procedure calls are + -- handled in this package. procedure Sem_Procedure_Call (Call : Iir_Procedure_Call; Stmt : Iir); - -- Semantize a range. If ANY_DIR is true, the range can't be a - -- null range (slice vs subtype -- used in static evaluation). + -- Analyze a range (ie a range attribute or a range expression). If + -- ANY_DIR is true, the range can't be a null range (slice vs subtype, + -- used in static evaluation). A_TYPE may be Null_Iir. + -- Return Null_Iir in case of error, or EXPR analyzed (and evaluated if + -- possible). function Sem_Range_Expression (Expr: Iir; A_Type: Iir; Any_Dir : Boolean) return Iir; - -- Semantize a discrete range. If ANY_DIR is true, the range can't be a - -- null range (slice vs subtype -- used in static evaluation). + -- Analyze a discrete range. If ANY_DIR is true, the range can't be a + -- null range (slice vs subtype -- used in static evaluation). A_TYPE may + -- be Null_Iir. Return Null_Iir in case of error. function Sem_Discrete_Range_Expression (Expr: Iir; A_Type: Iir; Any_Dir: Boolean) return Iir; - function Get_Discrete_Range_Staticness (Expr : Iir) return Iir_Staticness; -- Semantize a discrete range and convert to integer if both bounds are -- universal integer types, according to rules of LRM 3.2.1.1 function Sem_Discrete_Range_Integer (Expr: Iir) return Iir; - -- Convert a parenthesis_name to a slice_name or an index_name, according - -- to the suffix expression. - -- This is used in sem by generates. - --function Sem_Parenthesis_Name (Name : Iir_Parenthesis_Name) return Iir; - - -- Transform LIT into a physical_literal. - -- LIT can be either a not semantized physical literal or + -- Transform LIT into a physical_literal. + -- LIT can be either a not semantized physical literal or -- a simple name that is a physical unit. In the later case, a physical -- literal is created. function Sem_Physical_Literal (Lit: Iir) return Iir; diff --git a/sem_names.adb b/sem_names.adb index 8d85c0eca..113a7cde3 100644 --- a/sem_names.adb +++ b/sem_names.adb @@ -41,7 +41,7 @@ package body Sem_Names is -- interpretation has been determined (RES). -- -- Error messages are emitted here. - procedure Finish_Sem_Name (Name : Iir; Res : Iir); + function Finish_Sem_Name (Name : Iir; Res : Iir) return Iir; procedure Error_Overload (Expr: Iir) is begin @@ -274,7 +274,7 @@ package body Sem_Names is if Keep_Alias then Add_Result (Res, Decl); else - Add_Result (Res, Get_Name (Decl)); + Add_Result (Res, Get_Named_Entity (Get_Name (Decl))); end if; end if; when others => @@ -319,7 +319,7 @@ package body Sem_Names is end if; end; when Iir_Kind_For_Loop_Statement => - Handle_Decl (Get_Iterator_Scheme (Decl), Id); + Handle_Decl (Get_Parameter_Specification (Decl), Id); when Iir_Kind_Process_Statement | Iir_Kind_Sensitized_Process_Statement => null; @@ -412,25 +412,26 @@ package body Sem_Names is Prefix : Iir; Obj : Iir; begin - if Get_Kind (Name) = Iir_Kind_Selected_Name then - Prefix := Get_Prefix (Name); - Obj := Get_Named_Entity (Prefix); - if Obj /= Null_Iir - and then - (Get_Kind (Obj) = Iir_Kind_Variable_Declaration - or Get_Kind (Obj) = Iir_Kind_Variable_Interface_Declaration) - and then Get_Type (Obj) /= Null_Iir + if Get_Kind (Name) /= Iir_Kind_Selected_Name then + return; + end if; + + Prefix := Get_Prefix (Name); + Obj := Get_Named_Entity (Prefix); + if Obj /= Null_Iir + and then + (Get_Kind (Obj) = Iir_Kind_Variable_Declaration + or Get_Kind (Obj) = Iir_Kind_Variable_Interface_Declaration) + and then Get_Type (Obj) /= Null_Iir + then + if Get_Kind (Get_Type (Obj)) /= Iir_Kind_Protected_Type_Declaration then - if Get_Kind (Get_Type (Obj)) /= Iir_Kind_Protected_Type_Declaration - then - Error_Msg_Sem ("type of the prefix should be a protected type", - Prefix); - return; - end if; - Set_Method_Object (Call, Obj); + Error_Msg_Sem ("type of the prefix should be a protected type", + Prefix); + return; end if; + Set_Method_Object (Call, Obj); end if; - Set_Implementation (Call, Get_Named_Entity (Name)); end Name_To_Method_Object; -- NAME is the name of the function (and not the parenthesis name) @@ -440,17 +441,15 @@ package body Sem_Names is Call : Iir_Function_Call; begin -- Check. - case Get_Kind (Name) is - when Iir_Kind_Simple_Name - | Iir_Kind_Selected_Name - | Iir_Kind_Operator_Symbol => - null; - when others => - Error_Kind ("sem_as_function_call", Name); - end case; + pragma Assert (Get_Kind (Name) in Iir_Kinds_Denoting_Name); Call := Create_Iir (Iir_Kind_Function_Call); Location_Copy (Call, Name); + if Get_Kind (Name) = Iir_Kind_Parenthesis_Name then + Set_Prefix (Call, Get_Prefix (Name)); + else + Set_Prefix (Call, Name); + end if; Name_To_Method_Object (Call, Name); Set_Implementation (Call, Spec); Set_Parameter_Association_Chain (Call, Assoc_Chain); @@ -501,15 +500,14 @@ package body Sem_Names is Prefix := Get_Prefix (Expr); Prefix_Type := Get_Type (Prefix); Expr_Staticness := Locally; - Index_List := Get_Index_List (Expr); + -- LRM93 §6.4: there must be one such expression for each index -- position of the array and each expression must be of the -- type of the corresponding index. -- Loop on the indexes. for I in Natural loop - Index_Subtype := - Get_Nth_Element (Get_Index_Subtype_List (Prefix_Type), I); + Index_Subtype := Get_Index_Type (Prefix_Type, I); exit when Index_Subtype = Null_Iir; Index := Get_Nth_Element (Index_List, I); -- The index_subtype can be an unconstrained index type. @@ -566,27 +564,23 @@ package body Sem_Names is procedure Finish_Sem_Slice_Name (Name : Iir_Slice_Name) is -- The prefix of the slice - Prefix: Iir; - Prefix_Type: Iir; + Prefix : constant Iir := Get_Prefix (Name); + Prefix_Type : constant Iir := Get_Type (Prefix); Prefix_Base_Type : Iir; - Prefix_Bt : Iir; + Prefix_Bt : constant Iir := Get_Base_Type (Prefix_Type); Index_List: Iir_List; Index_Type: Iir; Suffix: Iir; Slice_Type : Iir; Expr_Type : Iir; Staticness : Iir_Staticness; - Suffix_Rng : Iir; Prefix_Rng : Iir; begin - -- Set a type to the prefix. - Prefix := Get_Prefix (Name); - Prefix_Type := Get_Type (Prefix); + -- Set a type to the prefix. Set_Base_Name (Name, Get_Base_Name (Prefix)); - -- LRM93 §6.5: the prefix of an indexed name must be appropriate - -- for an array type. - Prefix_Bt := Get_Base_Type (Prefix_Type); + -- LRM93 §6.5: the prefix of an indexed name must be appropriate + -- for an array type. if Get_Kind (Prefix_Bt) /= Iir_Kind_Array_Type_Definition then Error_Msg_Sem ("slice can only be applied to an array", Name); return; @@ -601,8 +595,8 @@ package body Sem_Names is return; end if; - Index_Type := Get_First_Element (Index_List); - Prefix_Rng := Eval_Range (Index_Type); + Index_Type := Get_Index_Type (Index_List, 0); + Prefix_Rng := Eval_Static_Range (Index_Type); -- LRM93 6.5 -- It is an error if either the bounds of the discrete range does not @@ -620,6 +614,7 @@ package body Sem_Names is if Suffix = Null_Iir then return; end if; + Suffix := Eval_Range_If_Static (Suffix); Set_Suffix (Name, Suffix); -- LRM93 §6.5: @@ -628,12 +623,11 @@ package body Sem_Names is -- by the prefix of the slice name. -- Check this only if the type is a constrained type. - Suffix_Rng := Eval_Range (Suffix); if Get_Kind (Prefix_Type) = Iir_Kind_Array_Subtype_Definition and then Get_Index_Constraint_Flag (Prefix_Type) + and then Get_Expr_Staticness (Suffix) = Locally and then Prefix_Rng /= Null_Iir - and then Suffix_Rng /= Null_Iir - and then Get_Direction (Suffix_Rng) /= Get_Direction (Prefix_Rng) + and then Get_Direction (Suffix) /= Get_Direction (Prefix_Rng) then if False and then Flags.Vhdl_Std = Vhdl_87 then -- emit a warning for a null slice. @@ -645,7 +639,18 @@ package body Sem_Names is -- LRM93 §7.4.1 -- A slice is never a locally static expression. - Staticness := Get_Discrete_Range_Staticness (Suffix); + case Get_Kind (Suffix) is + when Iir_Kind_Simple_Name + | Iir_Kind_Selected_Name => + Suffix := Get_Type (Suffix); + Staticness := Get_Type_Staticness (Suffix); + when Iir_Kind_Range_Expression + | Iir_Kind_Range_Array_Attribute + | Iir_Kind_Reverse_Range_Array_Attribute => + Staticness := Get_Expr_Staticness (Suffix); + when others => + Error_Kind ("finish_sem_slice_name", Suffix); + end case; Set_Expr_Staticness (Name, Min (Min (Staticness, Get_Expr_Staticness (Prefix)), Globally)); Set_Name_Staticness @@ -679,7 +684,8 @@ package body Sem_Names is Set_Signal_Type_Flag (Expr_Type, Get_Signal_Type_Flag (Prefix_Base_Type)); Append_Element (Get_Index_Subtype_List (Expr_Type), Slice_Type); - Set_Element_Subtype (Expr_Type, Get_Element_Subtype (Prefix_Type)); + Set_Element_Subtype_Indication + (Expr_Type, Get_Element_Subtype_Indication (Prefix_Type)); if Get_Kind (Prefix_Type) /= Iir_Kind_Array_Type_Definition then Set_Resolution_Function (Expr_Type, Get_Resolution_Function (Prefix_Type)); @@ -697,11 +703,22 @@ package body Sem_Names is end if; end Finish_Sem_Slice_Name; - procedure Finish_Sem_Function_Call (Call : Iir) + -- PREFIX is the name denoting the function declaration, and its analysis + -- is already finished. + procedure Finish_Sem_Function_Call (Call : Iir; Prefix : Iir) is Rtype : Iir; begin + Set_Prefix (Call, Prefix); + Set_Implementation (Call, Prefix); + + -- LRM08 8.1 Names + -- The name is a simple name or seleted name that does NOT denote a + -- function call [...] + -- + -- GHDL: so function calls are never static names. Set_Name_Staticness (Call, None); + -- FIXME: modify sem_subprogram_call to avoid such a type swap. Rtype := Get_Type (Call); Set_Type (Call, Null_Iir); @@ -710,12 +727,66 @@ package body Sem_Names is end if; end Finish_Sem_Function_Call; - procedure Finish_Sem_Array_Attribute (Attr : Iir; Param : Iir) + function Sem_Type_Mark (Name : Iir; Incomplete : Boolean := False) + return Iir + is + Atype : Iir; + Res : Iir; + begin + -- The name must not have been analyzed. + pragma Assert (Get_Type (Name) = Null_Iir); + + -- Analyze the name (if not already done). + if Get_Named_Entity (Name) = Null_Iir then + Sem_Name (Name); + end if; + Res := Finish_Sem_Name (Name); + + if Get_Kind (Res) in Iir_Kinds_Denoting_Name then + -- Common correct case. + Atype := Get_Named_Entity (Res); + if Get_Kind (Atype) = Iir_Kind_Type_Declaration then + Atype := Get_Type_Definition (Atype); + elsif Get_Kind (Atype) = Iir_Kind_Subtype_Declaration then + Atype := Get_Type (Atype); + else + Error_Msg_Sem + ("a type mark must denote a type or a subtype", Name); + Atype := Create_Error_Type (Atype); + Set_Named_Entity (Res, Atype); + end if; + else + if Get_Kind (Res) /= Iir_Kind_Error then + Error_Msg_Sem + ("a type mark must be a simple or expanded name", Name); + end if; + Res := Name; + Atype := Create_Error_Type (Name); + Set_Named_Entity (Res, Atype); + end if; + + if not Incomplete then + if Get_Kind (Atype) = Iir_Kind_Incomplete_Type_Definition then + Error_Msg_Sem + ("invalid use of an incomplete type definition", Name); + Atype := Create_Error_Type (Name); + Set_Named_Entity (Res, Atype); + end if; + end if; + + Set_Type (Res, Atype); + + return Res; + end Sem_Type_Mark; + + procedure Finish_Sem_Array_Attribute + (Attr_Name : Iir; Attr : Iir; Param : Iir) is Parameter : Iir; Prefix_Type : Iir; Index_Type : Iir; Prefix : Iir; + Prefix_Name : Iir; Staticness : Iir_Staticness; begin -- LRM93 14.1 @@ -736,18 +807,25 @@ package body Sem_Names is end if; end if; end if; - Prefix := Get_Prefix (Attr); - -- FIXME: the prefix should be a name. - if Get_Kind (Prefix) = Iir_Kind_Type_Declaration then - Prefix_Type := Get_Type_Definition (Prefix); + + Prefix_Name := Get_Prefix (Attr_Name); + if Is_Type_Name (Prefix_Name) /= Null_Iir then + Prefix := Sem_Type_Mark (Prefix_Name); else - Prefix_Type := Get_Type (Prefix); + Prefix := Finish_Sem_Name (Prefix_Name, Get_Prefix (Attr)); end if; + Set_Prefix (Attr, Prefix); + + Prefix_Type := Get_Type (Prefix); + if Is_Error (Prefix_Type) then + return; + end if; + declare Dim : Iir_Int64; - Indexes_List : Iir_List; + Indexes_List : constant Iir_List := + Get_Index_Subtype_List (Prefix_Type); begin - Indexes_List := Get_Index_Subtype_List (Prefix_Type); Dim := Get_Value (Parameter); if Dim < 1 or else Dim > Iir_Int64 (Get_Nbr_Elements (Indexes_List)) then @@ -755,7 +833,7 @@ package body Sem_Names is Parameter := Universal_Integer_One; Dim := 1; end if; - Index_Type := Get_Nth_Element (Indexes_List, Natural (Dim - 1)); + Index_Type := Get_Index_Type (Indexes_List, Natural (Dim - 1)); end; case Get_Kind (Attr) is @@ -775,9 +853,7 @@ package body Sem_Names is raise Internal_Error; end case; - if Get_Parameter (Attr) /= Null_Iir then - raise Internal_Error; - end if; + pragma Assert (Get_Parameter (Attr) = Null_Iir); Set_Parameter (Attr, Parameter); if Get_Kind (Prefix_Type) = Iir_Kind_Array_Subtype_Definition then @@ -829,7 +905,15 @@ package body Sem_Names is end if; Prefix := Get_Prefix (Attr); - Prefix_Type := Get_Type_Of_Type_Mark (Prefix); + if Get_Kind (Prefix) = Iir_Kind_Attribute_Name then + Prefix := Finish_Sem_Name (Prefix); + Set_Prefix (Attr, Prefix); + pragma Assert (Get_Kind (Prefix) = Iir_Kind_Base_Attribute); + else + Prefix := Sem_Type_Mark (Prefix); + end if; + Set_Prefix (Attr, Prefix); + Prefix_Type := Get_Type (Prefix); Prefix_Bt := Get_Base_Type (Prefix_Type); case Get_Kind (Attr) is @@ -884,14 +968,21 @@ package body Sem_Names is Set_Name_Staticness (Attr, Get_Expr_Staticness (Attr)); end Finish_Sem_Scalar_Type_Attribute; - procedure Finish_Sem_Signal_Attribute (Attr : Iir; Parameter : Iir) + procedure Finish_Sem_Signal_Attribute + (Attr_Name : Iir; Attr : Iir; Parameter : Iir) is Param : Iir; + Prefix : Iir; + Prefix_Name : Iir; begin + Prefix_Name := Get_Prefix (Attr_Name); + Prefix := Finish_Sem_Name (Prefix_Name, Get_Prefix (Attr)); + Set_Prefix (Attr, Prefix); + if Parameter = Null_Iir then return; end if; - if Get_Kind (Attr)= Iir_Kind_Transaction_Attribute then + if Get_Kind (Attr) = Iir_Kind_Transaction_Attribute then Error_Msg_Sem ("'transaction does not allow a parameter", Attr); else Param := Sem_Expression (Parameter, Time_Subtype_Definition); @@ -923,15 +1014,12 @@ package body Sem_Names is function Are_Types_Closely_Related (Type1, Type2 : Iir) return Boolean is - Base_Type1 : Iir; - Base_Type2 : Iir; + Base_Type1 : constant Iir := Get_Base_Type (Type1); + Base_Type2 : constant Iir := Get_Base_Type (Type2); Ant1, Ant2 : Boolean; Index_List1, Index_List2 : Iir_List; El1, El2 : Iir; begin - Base_Type1 := Get_Base_Type (Type1); - Base_Type2 := Get_Base_Type (Type2); - -- LRM 7.3.5 -- In particular, a type is closely related to itself. if Base_Type1 = Base_Type2 then @@ -973,9 +1061,9 @@ package body Sem_Names is return False; end if; for I in Natural loop - El1 := Get_Nth_Element (Index_List1, I); + El1 := Get_Index_Type (Index_List1, I); exit when El1 = Null_Iir; - El2 := Get_Nth_Element (Index_List2, I); + El2 := Get_Index_Type (Index_List2, I); if not Are_Types_Closely_Related (El1, El2) then return False; end if; @@ -983,42 +1071,56 @@ package body Sem_Names is return True; end Are_Types_Closely_Related; - procedure Finish_Sem_Type_Conversion (Conv: Iir_Type_Conversion) + function Sem_Type_Conversion (Loc : Iir; Type_Mark : Iir; Actual : Iir) + return Iir is + Conv: Iir_Type_Conversion; Expr: Iir; Staticness : Iir_Staticness; begin + Conv := Create_Iir (Iir_Kind_Type_Conversion); + Location_Copy (Conv, Loc); + Set_Type_Mark (Conv, Type_Mark); + Set_Type (Conv, Get_Type (Type_Mark)); + Set_Expression (Conv, Actual); + + -- Default staticness in case of error. + Set_Expr_Staticness (Conv, None); + + -- Bail out if no actual (or invalid one). + if Actual = Null_Iir then + return Conv; + end if; + -- LRM93 7.3.5 -- Furthermore, the operand of a type conversion is not allowed to be -- the literal null, an allocator, an aggregate, or a string literal. - Expr := Get_Expression (Conv); - case Get_Kind (Expr) is + case Get_Kind (Actual) is when Iir_Kind_Null_Literal | Iir_Kind_Aggregate | Iir_Kind_String_Literal | Iir_Kind_Bit_String_Literal => Error_Msg_Sem - (Disp_Node (Expr) & " cannot be a type conversion operand", - Expr); - return; + (Disp_Node (Actual) & " cannot be a type conversion operand", + Actual); + return Conv; when others => -- LRM93 7.3.5 -- The type of the operand of a type conversion must be -- determinable independent of the context (in particular, -- independent of the target type). - Expr := Sem_Expression_Universal (Expr); + Expr := Sem_Expression_Universal (Actual); if Expr = Null_Iir then - return; + return Conv; end if; if Get_Kind (Expr) in Iir_Kinds_Allocator then Error_Msg_Sem (Disp_Node (Expr) & " cannot be a type conversion operand", Expr); end if; + Set_Expression (Conv, Expr); end case; - Set_Expression (Conv, Expr); - -- LRM93 7.4.1 Locally Static Primaries. -- 9. a type conversion whose expression is a locally static expression. -- LRM93 7.4.2 Globally Static Primaries. @@ -1043,64 +1145,13 @@ package body Sem_Names is Check_Read (Expr); end if; end if; - end Finish_Sem_Type_Conversion; - - procedure Finish_Sem_Function_Specification (Name : Iir; Spec : Iir) - is - Res : Iir; - begin - if not Maybe_Function_Call (Spec) then - Error_Msg_Sem (Disp_Node (Spec) & " requires parameters", Name); - Set_Named_Entity (Name, Null_Iir); - return; - end if; - Res := Maybe_Insert_Function_Call (Name, Spec); - if Get_Kind (Res) /= Iir_Kind_Function_Call then - raise Internal_Error; - end if; - Finish_Sem_Function_Call (Res); - Set_Named_Entity (Name, Res); - end Finish_Sem_Function_Specification; - - procedure Finish_Sem_Implicits (Name : Iir; Pfx : Iir) - is - Name_Pfx : Iir; - begin - case Get_Kind (Pfx) is - when Iir_Kinds_Object_Declaration - | Iir_Kind_Attribute_Value => - null; - when Iir_Kind_Indexed_Name - | Iir_Kind_Selected_Element - | Iir_Kind_Slice_Name => - Name_Pfx := Get_Prefix (Name); - if Is_Overload_List (Name_Pfx) then - Finish_Sem_Name (Name_Pfx, Pfx); - end if; - when Iir_Kind_Implicit_Dereference => - Finish_Sem_Implicits (Name, Get_Prefix (Pfx)); - Finish_Sem_Dereference (Pfx); - when Iir_Kind_Dereference => - null; - when Iir_Kind_Function_Call => - if Get_Name_Staticness (Pfx) = Unknown then - Finish_Sem_Function_Call (Pfx); - else - Name_Pfx := Get_Prefix (Name); - if Is_Overload_List (Name_Pfx) then - Finish_Sem_Name (Name_Pfx, Pfx); - end if; - end if; - when Iir_Kinds_Attribute => - null; - when others => - Error_Kind ("finish_sem_implicits", Pfx); - end case; - end Finish_Sem_Implicits; + return Conv; + end Sem_Type_Conversion; -- OBJ is an 'impure' object (variable, signal or file) referenced at -- location LOC. - -- Check the pure rules. + -- Check the pure rules (LRM08 4 Subprograms and packages, + -- LRM08 4.3 Subprograms bodies). procedure Sem_Check_Pure (Loc : Iir; Obj : Iir) is procedure Update_Impure_Depth (Subprg_Spec : Iir; Depth : Iir_Int32) @@ -1155,10 +1206,15 @@ package body Sem_Names is | Iir_Kind_Guard_Signal_Declaration | Iir_Kind_Signal_Declaration | Iir_Kind_Variable_Declaration - | Iir_Kind_Variable_Interface_Declaration - | Iir_Kind_Signal_Interface_Declaration | Iir_Kind_File_Interface_Declaration => null; + when Iir_Kind_Variable_Interface_Declaration + | Iir_Kind_Signal_Interface_Declaration => + -- When referenced as a formal name (FIXME: this is an + -- approximation), the rules don't apply. + if not Get_Is_Within_Flag (Get_Parent (Obj)) then + return; + end if; when Iir_Kind_File_Declaration => -- LRM 93 2.2 -- If a pure function is the parent of a given procedure, then @@ -1246,67 +1302,156 @@ package body Sem_Names is end if; end Sem_Check_All_Sensitized; - procedure Finish_Sem_Name (Name : Iir; Res : Iir) + function Finish_Sem_Denoting_Name (Name : Iir; Res : Iir) return Iir is - Pfx : Iir; + Prefix : Iir; + begin + case Iir_Kinds_Denoting_Name (Get_Kind (Name)) is + when Iir_Kind_Simple_Name + | Iir_Kind_Character_Literal + | Iir_Kind_Operator_Symbol => + Xref_Ref (Name, Res); + return Name; + when Iir_Kind_Selected_Name => + Xref_Ref (Name, Res); + Prefix := Get_Prefix (Name); + loop + pragma Assert (Get_Kind (Prefix) in Iir_Kinds_Denoting_Name); + Xref_Ref (Prefix, Get_Named_Entity (Prefix)); + exit when Get_Kind (Prefix) /= Iir_Kind_Selected_Name; + Prefix := Get_Prefix (Prefix); + end loop; + return Name; + end case; + end Finish_Sem_Denoting_Name; + + function Finish_Sem_Name_1 (Name : Iir; Res : Iir) return Iir + is + Prefix : Iir; + Name_Prefix : Iir; + Name_Res : Iir; begin case Get_Kind (Res) is when Iir_Kinds_Library_Unit_Declaration => - return; - when Iir_Kind_Block_Statement => - -- Part of an expanded name - return; + return Finish_Sem_Denoting_Name (Name, Res); + when Iir_Kinds_Sequential_Statement + | Iir_Kinds_Concurrent_Statement => + -- Label or part of an expanded name (for process, block + -- and generate). + return Finish_Sem_Denoting_Name (Name, Res); when Iir_Kinds_Object_Declaration - | Iir_Kind_Attribute_Value - | Iir_Kind_Type_Declaration - | Iir_Kind_Subtype_Declaration + | Iir_Kinds_Quantity_Declaration | Iir_Kind_Enumeration_Literal + | Iir_Kind_Unit_Declaration => + Name_Res := Finish_Sem_Denoting_Name (Name, Res); + Set_Base_Name (Name_Res, Res); + Set_Name_Staticness (Name_Res, Get_Name_Staticness (Res)); + Set_Expr_Staticness (Name_Res, Get_Expr_Staticness (Res)); + Sem_Check_Pure (Name_Res, Res); + Sem_Check_All_Sensitized (Res); + Set_Type (Name_Res, Get_Type (Res)); + return Name_Res; + when Iir_Kind_Attribute_Value => + pragma Assert (Get_Kind (Name) = Iir_Kind_Attribute_Name); + Prefix := Finish_Sem_Name (Get_Prefix (Name)); + Set_Prefix (Name, Prefix); + Set_Base_Name (Name, Res); + Set_Type (Name, Get_Type (Res)); + Set_Name_Staticness (Name, Get_Name_Staticness (Res)); + Set_Expr_Staticness (Name, Get_Expr_Staticness (Res)); + return Name; + when Iir_Kind_Type_Declaration + | Iir_Kind_Subtype_Declaration | Iir_Kind_Component_Declaration | Iir_Kind_Group_Template_Declaration | Iir_Kind_Group_Declaration | Iir_Kind_Attribute_Declaration - | Iir_Kind_Non_Object_Alias_Declaration => - Set_Base_Name (Name, Res); - return; + | Iir_Kind_Non_Object_Alias_Declaration + | Iir_Kind_Library_Declaration => + Name_Res := Finish_Sem_Denoting_Name (Name, Res); + Set_Base_Name (Name_Res, Res); + return Name_Res; + when Iir_Kinds_Function_Declaration => + Name_Res := Finish_Sem_Denoting_Name (Name, Res); + Set_Type (Name_Res, Get_Return_Type (Res)); + return Name_Res; + when Iir_Kinds_Procedure_Declaration => + return Finish_Sem_Denoting_Name (Name, Res); when Iir_Kind_Type_Conversion => - Finish_Sem_Type_Conversion (Res); - return; + pragma Assert (Get_Kind (Name) = Iir_Kind_Parenthesis_Name); + Set_Type_Mark (Res, Sem_Type_Mark (Get_Prefix (Name))); + -- FIXME: free name + return Res; when Iir_Kind_Indexed_Name | Iir_Kind_Selected_Element | Iir_Kind_Slice_Name | Iir_Kind_Dereference => + -- Fall through. null; + when Iir_Kind_Implicit_Dereference => + -- The name may not have a prefix. + Prefix := Finish_Sem_Name (Name, Get_Prefix (Res)); + Set_Prefix (Res, Prefix); + Finish_Sem_Dereference (Res); + return Res; when Iir_Kind_Function_Call => - Finish_Sem_Function_Call (Res); - return; - when Iir_Kinds_Function_Declaration - | Iir_Kinds_Procedure_Declaration => - --declare - -- Nres : Iir; - --begin - -- Nres := Sem_As_Function_Call (Res, Null_Iir, Name); - -- Set_Named_Entity (Name, Nres); - -- Finish_Sem_Function_Call (Nres); - --end; - return; - when Iir_Kind_Length_Array_Attribute - | Iir_Kind_Range_Array_Attribute - | Iir_Kind_Reverse_Range_Array_Attribute => - Finish_Sem_Array_Attribute (Res, Null_Iir); - return; --- when Iir_Kind_Pos_Attribute => --- if Get_Parameter (Res) = Null_Iir then --- Finish_Sem_Scalar_Type_Attribute (Res, Null_Iir); --- end if; --- return; + case Get_Kind (Name) is + when Iir_Kind_Parenthesis_Name => + Prefix := Finish_Sem_Name + (Get_Prefix (Name), Get_Implementation (Res)); + Finish_Sem_Function_Call (Res, Prefix); + -- FIXME: free name + when Iir_Kinds_Denoting_Name => + Prefix := Finish_Sem_Name (Name, Get_Implementation (Res)); + Finish_Sem_Function_Call (Res, Prefix); + when others => + Error_Kind ("Finish_Sem_Name(function call)", Name); + end case; + return Res; + when Iir_Kinds_Array_Attribute => + if Get_Parameter (Res) = Null_Iir then + Finish_Sem_Array_Attribute (Name, Res, Null_Iir); + end if; + return Res; + when Iir_Kinds_Scalar_Type_Attribute + | Iir_Kind_Image_Attribute + | Iir_Kind_Value_Attribute => + if Get_Parameter (Res) = Null_Iir then + Finish_Sem_Scalar_Type_Attribute (Res, Null_Iir); + end if; + return Res; + when Iir_Kinds_Signal_Value_Attribute => + null; + when Iir_Kinds_Signal_Attribute => + if Get_Parameter (Res) = Null_Iir then + Finish_Sem_Signal_Attribute (Name, Res, Null_Iir); + end if; + return Res; + when Iir_Kinds_Type_Attribute => + return Res; + when Iir_Kind_Base_Attribute => + return Res; + when Iir_Kind_Simple_Name_Attribute + | Iir_Kind_Path_Name_Attribute + | Iir_Kind_Instance_Name_Attribute => + return Res; when Iir_Kind_Psl_Expression => - return; + return Res; + when Iir_Kind_Psl_Declaration => + return Name; + when Iir_Kind_Element_Declaration + | Iir_Kind_Error => + -- Certainly an error! + return Res; when others => Error_Kind ("finish_sem_name", Res); end case; - Pfx := Get_Prefix (Res); - Finish_Sem_Implicits (Name, Pfx); + -- Finish prefix. + Prefix := Get_Prefix (Res); + Name_Prefix := Get_Prefix (Name); + Prefix := Finish_Sem_Name_1 (Name_Prefix, Prefix); + Set_Prefix (Res, Prefix); case Get_Kind (Res) is when Iir_Kind_Indexed_Name => @@ -1314,14 +1459,38 @@ package body Sem_Names is when Iir_Kind_Slice_Name => Finish_Sem_Slice_Name (Res); when Iir_Kind_Selected_Element => - Set_Name_Staticness (Res, Get_Name_Staticness (Pfx)); - Set_Expr_Staticness (Res, Get_Expr_Staticness (Pfx)); - Set_Base_Name (Res, Get_Base_Name (Pfx)); + Xref_Ref (Res, Get_Selected_Element (Res)); + Set_Name_Staticness (Res, Get_Name_Staticness (Prefix)); + Set_Expr_Staticness (Res, Get_Expr_Staticness (Prefix)); + Set_Base_Name (Res, Get_Base_Name (Prefix)); when Iir_Kind_Dereference => Finish_Sem_Dereference (Res); + when Iir_Kinds_Signal_Value_Attribute => + null; when others => Error_Kind ("finish_sem_name(2)", Res); end case; + return Res; + end Finish_Sem_Name_1; + + function Finish_Sem_Name (Name : Iir; Res : Iir) return Iir + is + Old_Res : Iir; + begin + if Get_Kind (Res) /= Iir_Kind_Implicit_Dereference then + Old_Res := Get_Named_Entity (Name); + if Old_Res /= Null_Iir and then Old_Res /= Res then + pragma Assert (Is_Overload_List (Old_Res)); + Sem_Name_Free_Result (Old_Res, Res); + end if; + Set_Named_Entity (Name, Res); + end if; + return Finish_Sem_Name_1 (Name, Res); + end Finish_Sem_Name; + + function Finish_Sem_Name (Name : Iir) return Iir is + begin + return Finish_Sem_Name_1 (Name, Get_Named_Entity (Name)); end Finish_Sem_Name; -- LRM93 6.2 @@ -1384,7 +1553,8 @@ package body Sem_Names is if not Keep_Alias and then Get_Kind (Res) = Iir_Kind_Non_Object_Alias_Declaration then - Res := Get_Name (Res); + Set_Alias_Declaration (Name, Res); + Res := Get_Named_Entity (Get_Name (Res)); end if; else -- Name is overloaded. @@ -1393,11 +1563,10 @@ package body Sem_Names is -- The SEEN_FLAG is used to get only one meaning which can be reached -- through several pathes (such as aliases). while Valid_Interpretation (Interpretation) loop - Res := Get_Declaration (Interpretation); - if not Keep_Alias - and then Get_Kind (Res) = Iir_Kind_Non_Object_Alias_Declaration - then - Res := Get_Name (Res); + if Keep_Alias then + Res := Get_Declaration (Interpretation); + else + Res := Get_Non_Alias_Declaration (Interpretation); end if; if not Get_Seen_Flag (Res) then Set_Seen_Flag (Res, True); @@ -1407,6 +1576,8 @@ package body Sem_Names is Interpretation := Get_Next_Interpretation (Interpretation); end loop; + -- FIXME: there can be only one element (a function and its alias!). + -- Clear SEEN_FLAG. for I in 0 .. N - 1 loop Res := Get_Nth_Element (Res_List, I); @@ -1422,11 +1593,13 @@ package body Sem_Names is -- LRM93 §6.3 -- Selected Names. - procedure Sem_Selected_Name (Name: Iir; Keep_Alias : Boolean) + procedure Sem_Selected_Name (Name: Iir; Keep_Alias : Boolean := False) is + Suffix : constant Name_Id := Get_Identifier (Name); + Prefix_Name : constant Iir := Get_Prefix (Name); + Prefix_Loc : constant Location_Type := Get_Location (Prefix_Name); + Prefix: Iir; - Suffix: Name_Id; - Prefix_Loc : Location_Type; Res : Iir; -- Semantize SUB_NAME.NAME as an expanded name (ie, NAME is declared @@ -1482,7 +1655,7 @@ package body Sem_Names is return; end if; - R := Maybe_Insert_Function_Call (Name, Sub_Name); + R := Maybe_Insert_Function_Call (Prefix_Name, Sub_Name); R := Maybe_Insert_Dereference (R, Ptr_Type); Se := Create_Iir (Iir_Kind_Selected_Element); @@ -1490,8 +1663,7 @@ package body Sem_Names is Set_Prefix (Se, R); Set_Type (Se, Get_Type (Rec_El)); Set_Selected_Element (Se, Rec_El); - Set_Base_Name (Se, Get_Base_Name (R)); - Set_Base_Name (Name, Get_Base_Name (R)); + Set_Base_Name (Se, Get_Object_Prefix (R, False)); Add_Result (Res, Se); end Sem_As_Selected_Element; @@ -1551,20 +1723,16 @@ package body Sem_Names is end Sem_As_Method_Call; begin - Prefix := Get_Prefix (Name); - Prefix_Loc := Get_Location (Prefix); - Sem_Name (Prefix, False); - Prefix := Get_Named_Entity (Prefix); + -- Analyze prefix. + Sem_Name (Prefix_Name); + Prefix := Get_Named_Entity (Prefix_Name); if Prefix = Error_Mark then Set_Named_Entity (Name, Prefix); return; end if; - Suffix := Get_Identifier (Name); Res := Null_Iir; - -- FIXME: do better. - -- case Get_Kind (Prefix) is when Iir_Kind_Overload_List => -- LRM93 6.3 @@ -1706,9 +1874,6 @@ package body Sem_Names is end case; if Res = Null_Iir then Res := Error_Mark; - elsif not Is_Overload_List (Res) then - -- Finish sem - Finish_Sem_Name (Name, Res); end if; Set_Named_Entity (Name, Res); end Sem_Selected_Name; @@ -1719,22 +1884,27 @@ package body Sem_Names is is Assoc : Iir; begin + -- Only one actual ? if Assoc_Chain = Null_Iir or else Get_Chain (Assoc_Chain) /= Null_Iir then return Null_Iir; end if; + + -- Not 'open' association element ? Assoc := Assoc_Chain; if Get_Kind (Assoc) /= Iir_Kind_Association_Element_By_Expression then return Null_Iir; end if; + + -- Not an association (ie no formal) ? if Get_Formal (Assoc) /= Null_Iir then return Null_Iir; end if; + return Get_Actual (Assoc); end Get_One_Actual; - function Slice_Or_Index (Actual : Iir) return Iir_Kind - is + function Slice_Or_Index (Actual : Iir) return Iir_Kind is begin -- But it may be a slice name. case Get_Kind (Actual) is @@ -1753,6 +1923,27 @@ package body Sem_Names is return Iir_Kind_Indexed_Name; end Slice_Or_Index; + -- Check whether association chain ASSOCS may be interpreted as indexes. + function Index_Or_Not (Assocs : Iir) return Iir_Kind + is + El : Iir; + begin + El := Assocs; + while El /= Null_Iir loop + case Get_Kind (El) is + when Iir_Kind_Association_Element_By_Expression => + if Get_Formal (El) /= Null_Iir then + return Iir_Kind_Error; + end if; + when others => + -- Only expression are allowed. + return Iir_Kind_Error; + end case; + El := Get_Chain (El); + end loop; + return Iir_Kind_Indexed_Name; + end Index_Or_Not; + function Sem_Index_Specification (Name : Iir_Parenthesis_Name; Itype : Iir) return Iir is @@ -1760,6 +1951,8 @@ package body Sem_Names is Kind : Iir_Kind; Res : Iir; begin + -- FIXME: reuse Sem_Name for the whole analysis ? + Actual := Get_One_Actual (Get_Association_Chain (Name)); if Actual = Null_Iir then Error_Msg_Sem ("only one index specification is allowed", Name); @@ -1768,14 +1961,14 @@ package body Sem_Names is case Get_Kind (Actual) is when Iir_Kind_Simple_Name | Iir_Kind_Selected_Name => - Sem_Name (Actual, False); - Actual := Get_Named_Entity (Actual); + Sem_Name (Actual); + Kind := Slice_Or_Index (Get_Named_Entity (Actual)); -- FIXME: semantization to be finished. --Maybe_Finish_Sem_Name (Actual); when others => - null; + Kind := Slice_Or_Index (Actual); end case; - Kind := Slice_Or_Index (Actual); + Res := Create_Iir (Kind); Location_Copy (Res, Name); case Kind is @@ -1795,7 +1988,7 @@ package body Sem_Names is if Actual = Null_Iir then return Null_Iir; end if; - if Get_Discrete_Range_Staticness (Actual) < Globally then + if Get_Expr_Staticness (Actual) < Globally then Error_Msg_Sem ("index must be a static expression", Name); end if; Set_Suffix (Res, Actual); @@ -1814,27 +2007,6 @@ package body Sem_Names is Slice_Index_Kind : Iir_Kind; - procedure Index_Or_Not - is - El : Iir; - begin - Slice_Index_Kind := Iir_Kind_Error; - El := Assoc_Chain; - while El /= Null_Iir loop - case Get_Kind (El) is - when Iir_Kind_Association_Element_By_Expression => - if Get_Formal (El) /= Null_Iir then - return; - end if; - when others => - -- Only expression are allowed. - return; - end case; - El := Get_Chain (El); - end loop; - Slice_Index_Kind := Iir_Kind_Indexed_Name; - end Index_Or_Not; - -- If FINISH is TRUE, then display error message in case of error. function Sem_As_Indexed_Or_Slice_Name (Sub_Name : Iir; Finish : Boolean) return Iir @@ -1903,11 +2075,12 @@ package body Sem_Names is R := Create_Iir (Slice_Index_Kind); Location_Copy (R, Name); Set_Prefix (R, P); + Set_Base_Name (R, Get_Object_Prefix (P)); case Slice_Index_Kind is when Iir_Kind_Slice_Name => Set_Suffix (R, Get_Actual (Assoc_Chain)); - Set_Type (R, Get_Type (P)); + Set_Type (R, Get_Base_Type (Get_Type (P))); when Iir_Kind_Indexed_Name => declare Idx_El : Iir; @@ -1966,7 +2139,7 @@ package body Sem_Names is begin -- The prefix is a function name, a type mark or an array. Prefix_Name := Get_Prefix (Name); - Sem_Name (Prefix_Name, False); + Sem_Name (Prefix_Name); Prefix := Get_Named_Entity (Prefix_Name); if Prefix = Error_Mark then Set_Named_Entity (Name, Error_Mark); @@ -1977,35 +2150,31 @@ package body Sem_Names is Assoc_Chain := Get_Association_Chain (Name); Actual := Get_One_Actual (Assoc_Chain); - if Actual /= Null_Iir - and then - (Get_Kind (Actual) = Iir_Kind_Range_Expression - or else - (Get_Kind (Actual) = Iir_Kind_Attribute_Name - and then (Get_Identifier (Actual) = Std_Names.Name_Range - or else - Get_Identifier (Actual) - = Std_Names.Name_Reverse_Range))) + if Get_Kind (Prefix) = Iir_Kind_Type_Declaration + or else Get_Kind (Prefix) = Iir_Kind_Subtype_Declaration then - -- A slice. - Slice_Index_Kind := Iir_Kind_Slice_Name; - Add_Result (Res, Sem_As_Indexed_Or_Slice_Name (Prefix, True)); - elsif Actual /= Null_Iir - and then (Get_Kind (Prefix) = Iir_Kind_Type_Declaration - or else Get_Kind (Prefix) = Iir_Kind_Subtype_Declaration) - then - -- A type conversion - Res := Create_Iir (Iir_Kind_Type_Conversion); - Location_Copy (Res, Name); - Set_Type_Mark (Res, Prefix); - Set_Type (Res, Get_Type_Of_Type_Mark (Prefix)); - Set_Expression (Res, Actual); - else - if Actual /= Null_Iir - and then (Get_Kind (Actual) = Iir_Kind_Simple_Name - or Get_Kind (Actual) = Iir_Kind_Selected_Name) + -- A type conversion. The prefix is a type mark. + + if Actual = Null_Iir then + -- More than one actual. Keep only the first. + Error_Msg_Sem + ("type conversion allows only one expression", Name); + end if; + + -- This is certainly the easiest case: the prefix is not overloaded, + -- so the result can be computed. + Set_Named_Entity (Name, Sem_Type_Conversion (Name, Prefix, Actual)); + return; + end if; + + -- Select between slice or indexed name. + Actual_Expr := Null_Iir; + if Actual /= Null_Iir then + if Get_Kind (Actual) in Iir_Kinds_Name + or else Get_Kind (Actual) = Iir_Kind_Attribute_Name then - Sem_Name (Actual, False); + -- Maybe a discrete range name. + Sem_Name (Actual); Actual_Expr := Get_Named_Entity (Actual); if Actual_Expr = Error_Mark then Set_Named_Entity (Name, Actual_Expr); @@ -2013,132 +2182,139 @@ package body Sem_Names is end if; -- Decides between sliced or indexed name to actual. Slice_Index_Kind := Slice_Or_Index (Actual_Expr); + elsif Get_Kind (Actual) = Iir_Kind_Range_Expression then + -- This can only be a slice. + Slice_Index_Kind := Iir_Kind_Slice_Name; + -- Actual_Expr := + -- Sem_Discrete_Range_Expression (Actual, Null_Iir, False); + -- Set_Actual (Assoc_Chain, Actual_Expr); else - Index_Or_Not; + Slice_Index_Kind := Iir_Kind_Indexed_Name; end if; + else + -- FIXME: improve error message for multi-dim slice ? + Slice_Index_Kind := Index_Or_Not (Assoc_Chain); + end if; - if Slice_Index_Kind /= Iir_Kind_Slice_Name then - if Sem_Actual_Of_Association_Chain (Assoc_Chain) = False then - Actual := Null_Iir; - else - Actual := Get_One_Actual (Assoc_Chain); - end if; + if Slice_Index_Kind /= Iir_Kind_Slice_Name then + if Sem_Actual_Of_Association_Chain (Assoc_Chain) = False then + Actual := Null_Iir; + else + Actual := Get_One_Actual (Assoc_Chain); end if; + end if; - case Get_Kind (Prefix) is - when Iir_Kind_Overload_List => + case Get_Kind (Prefix) is + when Iir_Kind_Overload_List => + declare + El : Iir; + Prefix_List : Iir_List; + begin + Prefix_List := Get_Overload_List (Prefix); + for I in Natural loop + El := Get_Nth_Element (Prefix_List, I); + exit when El = Null_Iir; + Sem_Parenthesis_Function (El); + end loop; + end; + if Res = Null_Iir then + Error_Msg_Sem + ("no overloaded function found matching " + & Disp_Node (Prefix_Name), Name); + end if; + when Iir_Kinds_Function_Declaration => + Sem_Parenthesis_Function (Prefix); + if Res = Null_Iir then + Error_Msg_Sem + ("cannot match " & Disp_Node (Prefix) & " with actuals", + Name); + -- Display error message. declare - El : Iir; - Prefix_List : Iir_List; + Match : Boolean; begin - Prefix_List := Get_Overload_List (Prefix); - for I in Natural loop - El := Get_Nth_Element (Prefix_List, I); - exit when El = Null_Iir; - Sem_Parenthesis_Function (El); - end loop; + Sem_Association_Chain + (Get_Interface_Declaration_Chain (Prefix), + Assoc_Chain, True, Missing_Parameter, Name, Match); end; - if Res = Null_Iir then - Error_Msg_Sem - ("no overloaded function found matching " - & Disp_Node (Prefix_Name), Name); - end if; - when Iir_Kinds_Function_Declaration => - Sem_Parenthesis_Function (Prefix); - if Res = Null_Iir then - Error_Msg_Sem - ("cannot match " & Disp_Node (Prefix) & " with actuals", - Name); - -- Display error message. - declare - Match : Boolean; - begin - Sem_Association_Chain - (Get_Interface_Declaration_Chain (Prefix), - Assoc_Chain, True, Missing_Parameter, Name, Match); - end; - end if; - - when Iir_Kinds_Object_Declaration - | Iir_Kind_Indexed_Name - | Iir_Kind_Slice_Name - | Iir_Kind_Dereference - | Iir_Kind_Implicit_Dereference - | Iir_Kind_Selected_Element - | Iir_Kind_Attribute_Value - | Iir_Kind_Function_Call => - Add_Result (Res, Sem_As_Indexed_Or_Slice_Name (Prefix, True)); - - when Iir_Kinds_Array_Attribute => - if Actual /= Null_Iir then - Finish_Sem_Array_Attribute (Prefix, Actual); - Set_Named_Entity (Name, Prefix); - else - Error_Msg_Sem ("bad attribute parameter", Name); - Set_Named_Entity (Name, Error_Mark); - end if; - return; + end if; - when Iir_Kinds_Scalar_Type_Attribute - | Iir_Kind_Image_Attribute - | Iir_Kind_Value_Attribute => - if Get_Parameter (Prefix) /= Null_Iir then - -- Attribute already has a parameter, the expression - -- is either a slice or an index. - Add_Result - (Res, Sem_As_Indexed_Or_Slice_Name (Prefix, True)); - elsif Actual /= Null_Iir then - Finish_Sem_Scalar_Type_Attribute (Prefix, Actual); - Set_Named_Entity (Name, Prefix); - return; - else - Error_Msg_Sem ("bad attribute parameter", Name); - Set_Named_Entity (Name, Error_Mark); - return; - end if; + when Iir_Kinds_Object_Declaration + | Iir_Kind_Indexed_Name + | Iir_Kind_Slice_Name + | Iir_Kind_Dereference + | Iir_Kind_Implicit_Dereference + | Iir_Kind_Selected_Element + | Iir_Kind_Attribute_Value + | Iir_Kind_Function_Call => + Add_Result (Res, Sem_As_Indexed_Or_Slice_Name (Prefix, True)); - when Iir_Kind_Type_Declaration - | Iir_Kind_Subtype_Declaration => - Error_Msg_Sem - ("subprogram name is a type mark (missing apostrophe)", Name); + when Iir_Kinds_Array_Attribute => + if Actual /= Null_Iir then + Finish_Sem_Array_Attribute (Prefix_Name, Prefix, Actual); + Set_Named_Entity (Name, Prefix); + else + Error_Msg_Sem ("bad attribute parameter", Name); + Set_Named_Entity (Name, Error_Mark); + end if; + return; - when Iir_Kind_Stable_Attribute - | Iir_Kind_Quiet_Attribute - | Iir_Kind_Delayed_Attribute => - if Actual /= Null_Iir then - Finish_Sem_Signal_Attribute (Prefix, Actual); - Set_Named_Entity (Name, Prefix); - else - Error_Msg_Sem ("bad attribute parameter", Name); - Set_Named_Entity (Name, Error_Mark); - end if; + when Iir_Kinds_Scalar_Type_Attribute + | Iir_Kind_Image_Attribute + | Iir_Kind_Value_Attribute => + if Get_Parameter (Prefix) /= Null_Iir then + -- Attribute already has a parameter, the expression + -- is either a slice or an index. + Add_Result + (Res, Sem_As_Indexed_Or_Slice_Name (Prefix, True)); + elsif Actual /= Null_Iir then + Finish_Sem_Scalar_Type_Attribute (Prefix, Actual); + Set_Named_Entity (Name, Prefix); + return; + else + Error_Msg_Sem ("bad attribute parameter", Name); + Set_Named_Entity (Name, Error_Mark); return; + end if; - when Iir_Kinds_Procedure_Declaration => - Error_Msg_Sem ("function name is a procedure", Name); + when Iir_Kind_Type_Declaration + | Iir_Kind_Subtype_Declaration => + Error_Msg_Sem + ("subprogram name is a type mark (missing apostrophe)", Name); - when Iir_Kinds_Process_Statement - | Iir_Kind_Component_Declaration - | Iir_Kind_Type_Conversion => - Error_Msg_Sem - (Disp_Node (Prefix) & " cannot be indexed or sliced", Name); - Res := Null_Iir; + when Iir_Kind_Stable_Attribute + | Iir_Kind_Quiet_Attribute + | Iir_Kind_Delayed_Attribute => + if Actual /= Null_Iir then + Finish_Sem_Signal_Attribute (Prefix_Name, Prefix, Actual); + Set_Named_Entity (Name, Prefix); + else + Error_Msg_Sem ("bad attribute parameter", Name); + Set_Named_Entity (Name, Error_Mark); + end if; + return; - when Iir_Kind_Psl_Declaration => - Res := Sem_Psl.Sem_Psl_Name (Name); + when Iir_Kinds_Procedure_Declaration => + Error_Msg_Sem ("function name is a procedure", Name); - when Iir_Kinds_Library_Unit_Declaration => - Error_Msg_Sem ("function name is a design unit", Name); + when Iir_Kinds_Process_Statement + | Iir_Kind_Component_Declaration + | Iir_Kind_Type_Conversion => + Error_Msg_Sem + (Disp_Node (Prefix) & " cannot be indexed or sliced", Name); + Res := Null_Iir; - when others => - Error_Kind ("sem_parenthesis_name", Prefix); - end case; - end if; + when Iir_Kind_Psl_Declaration => + Res := Sem_Psl.Sem_Psl_Name (Name); + + when Iir_Kinds_Library_Unit_Declaration => + Error_Msg_Sem ("function name is a design unit", Name); + + when others => + Error_Kind ("sem_parenthesis_name", Prefix); + end case; if Res = Null_Iir then Res := Error_Mark; - elsif not Is_Overload_List (Res) then - Finish_Sem_Name (Name, Res); end if; Set_Named_Entity (Name, Res); end Sem_Parenthesis_Name; @@ -2175,7 +2351,7 @@ package body Sem_Names is end Sem_As_Selected_By_All_Name; begin Prefix := Get_Prefix (Name); - Sem_Name (Prefix, True); + Sem_Name (Prefix); Prefix_Name := Prefix; Prefix := Get_Named_Entity (Prefix); if Prefix = Null_Iir then @@ -2216,20 +2392,20 @@ package body Sem_Names is if Res = Null_Iir then Error_Msg_Sem ("prefix is not an access", Name); Res := Error_Mark; - elsif not Is_Overload_List (Res) then - Finish_Sem_Name (Name, Res); end if; Set_Named_Entity (Name, Res); end Sem_Selected_By_All_Name; function Sem_Base_Attribute (Attr : Iir_Attribute_Name) return Iir is - Prefix_Name : constant Iir := Get_Prefix (Attr); + Prefix_Name : Iir; Prefix : Iir; Res : Iir; Base_Type : Iir; Type_Decl : Iir; begin + Prefix_Name := Finish_Sem_Name (Get_Prefix (Attr)); + -- FIXME: handle error Prefix := Get_Named_Entity (Prefix_Name); case Get_Kind (Prefix) is when Iir_Kind_Type_Declaration => @@ -2248,7 +2424,7 @@ package body Sem_Names is end case; Res := Create_Iir (Iir_Kind_Base_Attribute); Location_Copy (Res, Attr); - Set_Prefix (Res, Prefix); + Set_Prefix (Res, Prefix_Name); Set_Type (Res, Base_Type); return Res; end Sem_Base_Attribute; @@ -2329,6 +2505,9 @@ package body Sem_Names is return Value; end Sem_User_Attribute; + -- The prefix of scalar type attributes is a type name (or 'base), and + -- therefore isn't overloadable. So at the end of the function, the + -- analyze is finished. function Sem_Scalar_Type_Attribute (Attr : Iir_Attribute_Name) return Iir is @@ -2408,7 +2587,7 @@ package body Sem_Names is raise Internal_Error; end case; Location_Copy (Res, Attr); - Set_Prefix (Res, Prefix); + Set_Prefix (Res, Prefix_Name); Set_Base_Name (Res, Res); case Get_Identifier (Attr) is @@ -2441,7 +2620,8 @@ package body Sem_Names is return Res; end Sem_Scalar_Type_Attribute; - -- Sem attributes whose prefix is a type or a subtype. + -- Analyze attributes whose prefix is a type or a subtype and result is + -- a value (not a function). function Sem_Predefined_Type_Attribute (Attr : Iir_Attribute_Name) return Iir is @@ -2475,19 +2655,25 @@ package body Sem_Names is return Error_Mark; end case; Location_Copy (Res, Attr); - Prefix := Get_Named_Entity (Prefix_Name); - Set_Prefix (Res, Prefix); Set_Base_Name (Res, Res); + Prefix := Get_Named_Entity (Prefix_Name); case Get_Kind (Prefix) is when Iir_Kind_Range_Array_Attribute | Iir_Kind_Reverse_Range_Array_Attribute => + Prefix := Finish_Sem_Name (Prefix_Name, Prefix); Prefix_Type := Get_Type (Prefix); Set_Expr_Staticness (Res, Get_Expr_Staticness (Prefix)); + when Iir_Kind_Base_Attribute => + -- Base_Attribute is already finished. + Prefix_Type := Get_Type (Prefix); + Set_Expr_Staticness (Res, Get_Type_Staticness (Prefix_Type)); when others => - Prefix_Type := Get_Type_Of_Type_Mark (Prefix); + Prefix := Sem_Type_Mark (Prefix_Name); + Prefix_Type := Get_Type (Prefix); Set_Expr_Staticness (Res, Get_Type_Staticness (Prefix_Type)); end case; + Set_Prefix (Res, Prefix); case Get_Identifier (Attr) is when Name_Ascending => @@ -2550,7 +2736,7 @@ package body Sem_Names is when Iir_Kind_Subtype_Declaration | Iir_Kind_Type_Declaration | Iir_Kind_Base_Attribute => - Prefix_Type := Get_Type_Of_Type_Mark (Prefix); + Prefix_Type := Get_Type (Prefix); if not Is_Fully_Constrained_Type (Prefix_Type) then Error_Msg_Sem ("prefix type is not constrained", Attr); -- We continue using the unconstrained array type. @@ -2560,7 +2746,7 @@ package body Sem_Names is when Iir_Kind_Range_Array_Attribute | Iir_Kind_Reverse_Range_Array_Attribute => -- For names such as pfx'Range'Left. - Finish_Sem_Array_Attribute (Prefix, Null_Iir); + Finish_Sem_Array_Attribute (Prefix_Name, Prefix, Null_Iir); Prefix_Type := Get_Type (Prefix); when Iir_Kind_Process_Statement => Error_Msg_Sem @@ -2576,7 +2762,7 @@ package body Sem_Names is case Get_Kind (Prefix_Type) is when Iir_Kinds_Scalar_Type_Definition => - -- FIXME: check prefix is a scalar type or subtype. + -- Note: prefix is a scalar type or subtype. return Sem_Predefined_Type_Attribute (Attr); when Iir_Kinds_Array_Type_Definition => null; @@ -2843,10 +3029,13 @@ package body Sem_Names is function Sem_Name_Attribute (Attr : Iir_Attribute_Name) return Iir is use Std_Names; + Prefix_Name : constant Iir := Get_Prefix (Attr); Prefix: Iir; Res : Iir; begin - Prefix := Get_Named_Entity (Get_Prefix (Attr)); + Prefix := Get_Named_Entity (Prefix_Name); + Set_Prefix (Attr, Finish_Sem_Name (Prefix_Name, Prefix)); + -- LRM 14.1 Predefined attributes -- E'SIMPLE_NAME -- Prefix: Any named entity as defined in 5.1 @@ -2920,7 +3109,7 @@ package body Sem_Names is end case; Location_Copy (Res, Attr); - Set_Prefix (Res, Prefix); + Set_Prefix (Res, Prefix_Name); return Res; end Sem_Name_Attribute; @@ -2953,8 +3142,8 @@ package body Sem_Names is else Sem_Name (Prefix, False); end if; - Prefix := Get_Named_Entity (Prefix); + if Prefix = Error_Mark then Set_Named_Entity (Attr, Prefix); return; @@ -2967,7 +3156,7 @@ package body Sem_Names is -- the parameter and result type profile of exactly one visible -- subprogram or enumeration literal, as is appropriate to the prefix. -- GHDL: this is done by Sem_Signature. - Sig := Get_Signature (Attr); + Sig := Get_Attribute_Signature (Attr); if Sig /= Null_Iir then Prefix := Sem_Signature (Prefix, Sig); if Prefix = Null_Iir then @@ -2984,6 +3173,8 @@ package body Sem_Names is return; end if; + -- Set_Prefix (Attr, Finish_Sem_Name (Get_Prefix (Attr), Prefix)); + case Get_Identifier (Attr) is when Name_Base => Res := Sem_Base_Attribute (Attr); @@ -3058,7 +3249,7 @@ package body Sem_Names is end Sem_Attribute_Name; -- LRM93 §6 - procedure Sem_Name (Name : Iir; Keep_Alias : Boolean) is + procedure Sem_Name (Name : Iir; Keep_Alias : Boolean := False) is begin -- Exit now if NAME was already semantized. if Get_Named_Entity (Name) /= Null_Iir then @@ -3070,7 +3261,7 @@ package body Sem_Names is | Iir_Kind_Character_Literal | Iir_Kind_Operator_Symbol => -- String_Literal may be a symbol_operator. - Sem_Simple_Name (Name, Keep_Alias, False); + Sem_Simple_Name (Name, Keep_Alias, Soft => False); when Iir_Kind_Selected_Name => Sem_Selected_Name (Name, Keep_Alias); when Iir_Kind_Parenthesis_Name => @@ -3084,94 +3275,6 @@ package body Sem_Names is end case; end Sem_Name; - -- Finish semantisation of NAME, if necessary. - procedure Maybe_Finish_Sem_Name (Name : Iir) - is - Expr : Iir; - begin - Expr := Get_Named_Entity (Name); - case Get_Kind (Expr) is - when Iir_Kind_Error => - null; - when Iir_Kinds_Object_Declaration - | Iir_Kinds_Quantity_Declaration => - Set_Base_Name (Name, Expr); - Sem_Check_Pure (Name, Expr); - Sem_Check_All_Sensitized (Expr); - when Iir_Kind_Indexed_Name - | Iir_Kind_Slice_Name - | Iir_Kind_Selected_Element - | Iir_Kind_Dereference => - declare - E : Iir; - begin - -- Get over implicit and explicit dereferences. - E := Expr; - loop - E := Get_Base_Name (E); - if Get_Kind (E) in Iir_Kinds_Dereference then - E := Get_Prefix (E); - else - exit; - end if; - end loop; - Sem_Check_Pure (Name, E); - Sem_Check_All_Sensitized (E); - end; - when Iir_Kind_Enumeration_Literal - | Iir_Kind_Unit_Declaration => - null; - when Iir_Kind_Type_Declaration - | Iir_Kind_Subtype_Declaration => - null; - when Iir_Kind_Function_Call - | Iir_Kind_Attribute_Value - | Iir_Kind_Type_Conversion => - null; - when Iir_Kinds_Type_Attribute => - null; - when Iir_Kind_Event_Attribute - | Iir_Kind_Active_Attribute - | Iir_Kind_Last_Event_Attribute - | Iir_Kind_Last_Active_Attribute - | Iir_Kind_Last_Value_Attribute - | Iir_Kind_Transaction_Attribute - | Iir_Kind_Driving_Attribute - | Iir_Kind_Driving_Value_Attribute => - null; - when Iir_Kind_Simple_Name_Attribute - | Iir_Kind_Path_Name_Attribute - | Iir_Kind_Instance_Name_Attribute => - null; - when Iir_Kind_Stable_Attribute - | Iir_Kind_Quiet_Attribute - | Iir_Kind_Delayed_Attribute => - if Get_Parameter (Expr) = Null_Iir then - Finish_Sem_Signal_Attribute (Expr, Null_Iir); - end if; - when Iir_Kinds_Array_Attribute => - if Get_Parameter (Expr) = Null_Iir then - Finish_Sem_Array_Attribute (Expr, Null_Iir); - end if; - when Iir_Kinds_Scalar_Type_Attribute - | Iir_Kind_Image_Attribute - | Iir_Kind_Value_Attribute => - if Get_Parameter (Expr) = Null_Iir then - Finish_Sem_Scalar_Type_Attribute (Expr, Null_Iir); - end if; - when Iir_Kind_Implicit_Dereference => - -- Should not happen. - raise Internal_Error; - when Iir_Kind_Implicit_Function_Declaration - | Iir_Kind_Function_Declaration => - Finish_Sem_Function_Specification (Name, Expr); - when Iir_Kind_Psl_Expression => - null; - when others => - Error_Kind ("maybe_finish_sem_name", Expr); - end case; - end Maybe_Finish_Sem_Name; - procedure Sem_Name_Soft (Name : Iir) is begin @@ -3184,7 +3287,7 @@ package body Sem_Names is when Iir_Kind_Simple_Name | Iir_Kind_Operator_Symbol => -- String_Literal may be a symbol_operator. - Sem_Simple_Name (Name, False, True); + Sem_Simple_Name (Name, False, Soft => True); when others => Error_Kind ("sem_name_soft", Name); end case; @@ -3300,19 +3403,16 @@ package body Sem_Names is end if; if not Is_Overload_List (Expr) then - Maybe_Finish_Sem_Name (Name); - Expr := Get_Named_Entity (Name); - if Expr = Null_Iir then - return Null_Iir; - end if; + Res := Finish_Sem_Name (Name); + pragma Assert (Res /= Null_Iir); if A_Type /= Null_Iir then - Res_Type := Get_Type (Expr); + Res_Type := Get_Type (Res); if Res_Type = Null_Iir then return Null_Iir; end if; if not Are_Basetypes_Compatible (Get_Base_Type (Res_Type), A_Type) then - Error_Not_Match (Expr, A_Type, Name); + Error_Not_Match (Res, A_Type, Name); return Null_Iir; end if; -- Fall through. @@ -3343,8 +3443,7 @@ package body Sem_Names is else Sem_Name_Free_Result (Expr, Res); Set_Named_Entity (Name, Res); - Finish_Sem_Name (Name, Res); - Maybe_Finish_Sem_Name (Name); + Res := Finish_Sem_Name (Name); Expr := Get_Named_Entity (Name); -- Fall through. end if; @@ -3365,26 +3464,98 @@ package body Sem_Names is end if; -- NAME has only one meaning, which is EXPR. - Xref_Name (Name); - case Get_Kind (Name) is + case Get_Kind (Res) is when Iir_Kind_Simple_Name | Iir_Kind_Character_Literal | Iir_Kind_Selected_Name => - --Set_Base_Name (Name, Get_Base_Name (Expr)); - Set_Type (Name, Get_Type (Expr)); - Set_Expr_Staticness (Name, Get_Expr_Staticness (Expr)); + Expr := Get_Named_Entity (Res); + case Get_Kind (Expr) is + when Iir_Kind_Implicit_Function_Declaration + | Iir_Kind_Function_Declaration => + if Maybe_Function_Call (Expr) then + Expr := Sem_As_Function_Call (Res, Expr, Null_Iir); + if Get_Kind (Expr) /= Iir_Kind_Function_Call then + raise Internal_Error; + end if; + Finish_Sem_Function_Call (Expr, Res); + return Expr; + else + Error_Msg_Sem + (Disp_Node (Expr) & " requires parameters", Res); + Set_Type (Res, Get_Type (Expr)); + Set_Expr_Staticness (Res, None); + return Res; + end if; + when others => + null; + end case; + Set_Type (Res, Get_Type (Expr)); + Set_Expr_Staticness (Res, Get_Expr_Staticness (Expr)); --Set_Name_Staticness (Name, Get_Name_Staticness (Expr)); - return Name; + --Set_Base_Name (Name, Get_Base_Name (Expr)); + return Res; + when Iir_Kind_Function_Call + | Iir_Kind_Selected_Element + | Iir_Kind_Indexed_Name + | Iir_Kind_Slice_Name + | Iir_Kind_Type_Conversion + | Iir_Kind_Attribute_Name => + return Eval_Expr_If_Static (Res); + when Iir_Kind_Dereference => + -- Never static. + return Res; + when Iir_Kinds_Array_Attribute => + -- FIXME: exclude range and reverse_range. + return Eval_Expr_If_Static (Res); + when Iir_Kinds_Signal_Attribute + | Iir_Kinds_Signal_Value_Attribute => + -- Never static + return Res; + when Iir_Kinds_Type_Attribute + | Iir_Kinds_Scalar_Type_Attribute + | Iir_Kind_Image_Attribute + | Iir_Kind_Value_Attribute + | Iir_Kind_Simple_Name_Attribute + | Iir_Kind_Path_Name_Attribute + | Iir_Kind_Instance_Name_Attribute => + return Eval_Expr_If_Static (Res); when Iir_Kind_Parenthesis_Name - | Iir_Kind_Attribute_Name | Iir_Kind_Selected_By_All_Name => - Free_Iir (Name); - return Eval_Expr_If_Static (Expr); + raise Internal_Error; when others => - Error_Kind ("name_to_expression", Name); + Error_Kind ("name_to_expression", Res); end case; end Name_To_Expression; + function Name_To_Range (Name : Iir) return Iir + is + Expr : Iir; + begin + Expr := Get_Named_Entity (Name); + if Get_Kind (Expr) = Iir_Kind_Error then + return Error_Mark; + end if; + + case Get_Kind (Expr) is + when Iir_Kind_Subtype_Declaration + | Iir_Kind_Type_Declaration => + Expr := Sem_Type_Mark (Name); + Set_Expr_Staticness + (Expr, Get_Type_Staticness (Get_Type (Expr))); + return Expr; + when Iir_Kind_Range_Array_Attribute + | Iir_Kind_Reverse_Range_Array_Attribute => + if Get_Parameter (Expr) = Null_Iir then + Finish_Sem_Array_Attribute (Name, Expr, Null_Iir); + end if; + return Expr; + when others => + Error_Msg_Sem ("name " & Disp_Node (Name) + & " doesn't denote a range", Name); + return Error_Mark; + end case; + end Name_To_Range; + function Is_Object_Name (Name : Iir) return Boolean is begin @@ -3449,97 +3620,85 @@ package body Sem_Names is end case; end Name_To_Object; - -- Find a uniq declaration for a name. - function Find_Declaration (Name: Iir; Kind: Decl_Kind_Type) - return Iir + function Create_Error_Name (Orig : Iir) return Iir is - procedure Error (Res : Iir; Str : String) - is - begin - Error_Msg_Sem (Str & " expected, found " & Disp_Node (Res), Name); - end Error; - - function Check_Kind (Res: Iir; Kind : Iir_Kind; Str: String) - return Iir - is - Res_Kind : Iir_Kind; - begin - Res_Kind := Get_Kind (Res); - if Res_Kind /= Kind then - Error (Res, Str); - return Null_Iir; - else - return Res; - end if; - end Check_Kind; + Res : Iir; + begin + Res := Create_Iir (Iir_Kind_Error); + Set_Expr_Staticness (Res, None); + Set_Error_Origin (Res, Orig); + Location_Copy (Res, Orig); + return Res; + end Create_Error_Name; + function Sem_Denoting_Name (Name: Iir) return Iir + is Res: Iir; begin - Sem_Name (Name, False); - Res := Get_Named_Entity (Name); - - if Res = Error_Mark then - -- A message must have been displayed. - -- FIXME: is it the case for find_selected_declarations ??? - -- Error_Msg_Sem ("identifier is not defined", Name); - return Null_Iir; - end if; + pragma Assert (Get_Kind (Name) in Iir_Kinds_Denoting_Name); - Xref_Name (Name); + Sem_Name (Name); + Res := Get_Named_Entity (Name); - case Kind is - when Decl_Type - | Decl_Incomplete_Type => - case Get_Kind (Res) is - when Iir_Kind_Type_Declaration => - Res := Get_Type_Definition (Res); - -- Note: RES cannot be NULL_IIR, this is just to be more - -- bullet-proof. - if Kind /= Decl_Incomplete_Type - and then - (Res = Null_Iir or else - Get_Kind (Res) = Iir_Kind_Incomplete_Type_Definition) - then - Error_Msg_Sem - ("invalid use of an incomplete type definition", Name); - end if; - when Iir_Kind_Subtype_Declaration => - Res := Get_Type (Res); - when others => - Error_Msg_Sem - ("type expected, found " & Disp_Node (Res), Name); - return Null_Iir; - end case; - when Decl_Nature => - case Get_Kind (Res) is - when Iir_Kind_Nature_Declaration => - Res := Get_Nature (Res); - when others => - Error_Msg_Sem - ("nature expected, found " & Disp_Node (Res), Name); - return Null_Iir; - end case; - when Decl_Terminal => - Res := Check_Kind (Res, Iir_Kind_Terminal_Declaration, "terminal"); - when Decl_Component => - Res := Check_Kind (Res, Iir_Kind_Component_Declaration, - "component"); - when Decl_Unit => - null; - when Decl_Label => - null; - when Decl_Entity => - Res := Check_Kind (Res, Iir_Kind_Entity_Declaration, "entity"); - when Decl_Configuration => - Res := Check_Kind (Res, Iir_Kind_Configuration_Declaration, - "configuration"); - when Decl_Group_Template => - Res := Check_Kind (Res, Iir_Kind_Group_Template_Declaration, - "group template"); - when Decl_Attribute => - Res := Check_Kind (Res, Iir_Kind_Attribute_Declaration, - "attribute"); + case Get_Kind (Res) is + when Iir_Kind_Error => + -- A message must have been displayed. + return Name; + when Iir_Kind_Overload_List => + Error_Overload (Res); + Set_Named_Entity (Name, Create_Error_Name (Name)); + return Name; + when Iir_Kinds_Concurrent_Statement + | Iir_Kinds_Sequential_Statement + | Iir_Kind_Type_Declaration + | Iir_Kind_Subtype_Declaration + | Iir_Kind_Enumeration_Literal + | Iir_Kind_Unit_Declaration + | Iir_Kind_Group_Template_Declaration + | Iir_Kind_Group_Declaration + | Iir_Kind_Attribute_Declaration + | Iir_Kinds_Object_Declaration + | Iir_Kind_Entity_Declaration + | Iir_Kind_Configuration_Declaration + | Iir_Kind_Package_Declaration + | Iir_Kind_Library_Declaration + | Iir_Kinds_Subprogram_Declaration + | Iir_Kind_Component_Declaration => + Res := Finish_Sem_Name (Name, Res); + pragma Assert (Get_Kind (Res) in Iir_Kinds_Denoting_Name); + return Res; + when Iir_Kind_Selected_Element => + -- An error (to be diagnosticed by the caller). + return Name; + when others => + Error_Kind ("sem_denoting_name", Res); end case; + end Sem_Denoting_Name; + + function Sem_Terminal_Name (Name : Iir) return Iir + is + Res : Iir; + Ent : Iir; + begin + Res := Sem_Denoting_Name (Name); + Ent := Get_Named_Entity (Res); + if Get_Kind (Ent) /= Iir_Kind_Terminal_Declaration then + Error_Class_Match (Name, "terminal"); + Set_Named_Entity (Res, Create_Error_Name (Name)); + end if; return Res; - end Find_Declaration; + end Sem_Terminal_Name; + + procedure Error_Class_Match (Name : Iir; Class_Name : String) + is + Ent : constant Iir := Get_Named_Entity (Name); + begin + if Is_Error (Ent) then + Error_Msg_Sem (Class_Name & " name expected", Name); + else + Error_Msg_Sem + (Class_Name & " name expected, found " + & Disp_Node (Get_Named_Entity (Name)), Name); + end if; + end Error_Class_Match; end Sem_Names; diff --git a/sem_names.ads b/sem_names.ads index 75db2fc17..a77774141 100644 --- a/sem_names.ads +++ b/sem_names.ads @@ -18,22 +18,56 @@ with Iirs; use Iirs; package Sem_Names is - -- Semantize NAME as long as it consists in named entities. - -- Set Named_Entity field of NAME, with: - -- * the named entity (if any) - -- * an overload_list of named entity - -- * error_mark (in case of error, the message error is displayed). - procedure Sem_Name (Name : Iir; Keep_Alias : Boolean); - - -- Finish semantisation of NAME, if necessary. + -- In VHDL, most of name notations are ambiguous: + -- P.N is either + -- an expanded name or + -- a selected name for an element (with a possible implicit dereference) + -- P (A1, A2, ...) can be + -- an indexed name (with a possible implicit dereference) + -- a slice name (with a possible implicit dereference) + -- a subprogram call + -- a type conversion + + -- The name analysis resolves two ambiguities: notation and overload. + -- In a first pass, all possible meaning are collected as an overload + -- list in the Named_Entity field of the name. Prefixes in that list + -- are always declarations and not simple or expanded names. This is done + -- to avoid creating nodes for simple or expanded names, as they cannot be + -- shared in the prefixes because they can have several meanings. + -- + -- In a second pass, when the caller has resolved the overloading (using + -- the context), the name is rewritten: parenthesis and selected names are + -- replaced (by slice, index, call, element selection...). Prefixes are + -- simple or expanded names (and never declarations). Checks are also + -- performed on the result (pure, all sensitized). + -- + -- The result of the name analysis may not be a name: a function_call or + -- a type conversion are not names. + + -- Analyze NAME: perform the first pass only. In case of error, a message + -- is displayed and the named entity is error_mark. + procedure Sem_Name (Name : Iir; Keep_Alias : Boolean := False); + + -- Finish semantisation of NAME, if necessary. The named entity must not + -- be an overload list (ie the overload resolution must have been done). -- This make remaining checks, transforms function names into calls... - procedure Maybe_Finish_Sem_Name (Name : Iir); + function Finish_Sem_Name (Name : Iir) return Iir; + + -- Analyze NAME as a type mark. NAME must be either a simple name or an + -- expanded name, and the denoted entity must be either a type or a subtype + -- declaration. Return the name (possibly modified) and set named_entity + -- and type. In case of error, the type is error_mark. NAME may have + -- already been analyzed by Sem_Name. + -- Incomplete types are allowed only if INCOMPLETE is True. + function Sem_Type_Mark (Name : Iir; Incomplete : Boolean := False) + return Iir; -- Same as Sem_Name but without any side-effect: -- * do not report error -- * do not set xrefs -- Currently, only simple names (and expanded names) are handled. - -- This is to be used during sem of associations. + -- This is to be used during sem of associations. Because there is no side + -- effect, NAME is not modified. procedure Sem_Name_Soft (Name : Iir); -- Remove every named_entity of NAME. @@ -54,12 +88,16 @@ package Sem_Names is -- method_object of CALL. procedure Name_To_Method_Object (Call : Iir; Name : Iir); - -- Convert name EXPR to an expression (ie, can create function call). + -- Convert name NAME to an expression (ie, can create function call). -- A_TYPE is the expected type of the expression. -- FIXME: it is unclear wether the result must be an expression or not -- (ie, it *must* have a type, but may be a range). function Name_To_Expression (Name : Iir; A_Type : Iir) return Iir; + -- Finish analyze of NAME and expect a range (either a type or subtype + -- declaration or a range attribute). Return Error_Mark in case of error. + function Name_To_Range (Name : Iir) return Iir; + -- Return true if AN_IIR is an overload list. function Is_Overload_List (An_Iir: Iir) return Boolean; pragma Inline (Is_Overload_List); @@ -103,25 +141,16 @@ package Sem_Names is function Sem_Index_Specification (Name : Iir_Parenthesis_Name; Itype : Iir) return Iir; - -- Kind of declaration to find. - -- Decl_entity: an entity declaration (used for binding_indication). - -- Decl_Any : no checks is performed. - - type Decl_Kind_Type is - (Decl_Type, Decl_Incomplete_Type, - Decl_Component, Decl_Unit, Decl_Label, - Decl_Group_Template, Decl_Entity, Decl_Configuration, Decl_Attribute, - Decl_Nature, Decl_Terminal); - - -- Find a uniq declaration for name NAME, which can be a simple_name, - -- an identifier or a selected_name. - -- Disp an error message if: - -- NAME (or any prefix of it) is undefined - -- NAME is overloaded - -- NAME does not belong to KIND. - -- In these case, null_iir is returned. - -- Otherwise, the declaration is returned, and NAME is freed. - -- If NAME is a selected_name, dependencies can be added to the current - -- design unit. - function Find_Declaration (Name: Iir; Kind: Decl_Kind_Type) return Iir; + -- Analyze denoting name NAME. NAME must be either a simple name or an + -- expanded name and so is the result. + function Sem_Denoting_Name (Name: Iir) return Iir; + + -- Like Sem_Denoting_Name but expect a terminal name. + function Sem_Terminal_Name (Name : Iir) return Iir; + + -- Emit an error for NAME that doesn't match its class CLASS_NAME. + procedure Error_Class_Match (Name : Iir; Class_Name : String); + + -- Create an error node for name ORIG; set its expr staticness to none. + function Create_Error_Name (Orig : Iir) return Iir; end Sem_Names; diff --git a/sem_psl.adb b/sem_psl.adb index 15b924ce9..cae63f740 100644 --- a/sem_psl.adb +++ b/sem_psl.adb @@ -146,8 +146,16 @@ package body Sem_Psl is begin Expr := Get_HDL_Node (N); if Get_Kind (Expr) in Iir_Kinds_Name then - Sem_Name (Expr, False); - Name := Get_Named_Entity (Expr); + Sem_Name (Expr); + Expr := Finish_Sem_Name (Expr); + Set_HDL_Node (N, Expr); + + if Get_Kind (Expr) in Iir_Kinds_Denoting_Name then + Name := Get_Named_Entity (Expr); + else + Name := Expr; + end if; + case Get_Kind (Name) is when Iir_Kind_Error => return N; @@ -183,9 +191,15 @@ package body Sem_Psl is Free_Iir (Expr); return Res; when Iir_Kind_Psl_Expression => + -- Remove the two bridge nodes: from PSL to HDL and from + -- HDL to PSL. Free_Node (N); + Res := Get_Psl_Expression (Name); Free_Iir (Expr); - return Get_Psl_Expression (Name); + if Name /= Expr then + Free_Iir (Name); + end if; + return Res; when others => Expr := Name; end case; diff --git a/sem_scopes.adb b/sem_scopes.adb index e1f266d2b..2ff4b4e58 100644 --- a/sem_scopes.adb +++ b/sem_scopes.adb @@ -20,7 +20,7 @@ with GNAT.Table; with Flags; use Flags; with Name_Table; -- use Name_Table; with Errorout; use Errorout; -with Iirs_Utils; +with Iirs_Utils; use Iirs_Utils; package body Sem_Scopes is -- FIXME: names: @@ -258,7 +258,7 @@ package body Sem_Scopes is begin Res := Decl; if Get_Kind (Res) = Iir_Kind_Non_Object_Alias_Declaration then - Res := Get_Name (Res); + Res := Get_Named_Entity (Get_Name (Res)); end if; return Res; end Strip_Non_Object_Alias; @@ -366,7 +366,7 @@ package body Sem_Scopes is | Iir_Kinds_Procedure_Declaration => return True; when Iir_Kind_Non_Object_Alias_Declaration => - case Get_Kind (Get_Name (Decl)) is + case Get_Kind (Get_Named_Entity (Get_Name (Decl))) is when Iir_Kind_Enumeration_Literal | Iir_Kinds_Function_Declaration | Iir_Kinds_Procedure_Declaration => @@ -585,7 +585,7 @@ package body Sem_Scopes is -- physical units. return Get_Kind (D) = Iir_Kind_Non_Object_Alias_Declaration and then Get_Implicit_Alias_Flag (D) - and then (Get_Kind (Get_Name (D)) + and then (Get_Kind (Get_Named_Entity (Get_Name (D))) in Iir_Kinds_Implicit_Subprogram_Declaration); end Is_Implicit_Alias; @@ -612,7 +612,7 @@ package body Sem_Scopes is Current_Decl := Get_Declaration (Homograph); Hash := Get_Hash_Non_Alias (Current_Decl); exit when Decl_Hash = Hash - and then Iirs_Utils.Is_Same_Profile (Decl, Current_Decl); + and then Is_Same_Profile (Decl, Current_Decl); Prev_Homograph := Homograph; Homograph := Get_Next_Interpretation (Homograph); end loop; @@ -973,8 +973,8 @@ package body Sem_Scopes is is begin case Get_Kind (Decl) is - when Iir_Kinds_Procedure_Declaration - | Iir_Kinds_Function_Declaration + when Iir_Kind_Implicit_Procedure_Declaration + | Iir_Kind_Implicit_Function_Declaration | Iir_Kind_Subtype_Declaration | Iir_Kind_Enumeration_Literal -- By use clause | Iir_Kind_Constant_Declaration @@ -1002,6 +1002,11 @@ package body Sem_Scopes is | Iir_Kinds_Concurrent_Statement | Iir_Kinds_Sequential_Statement => Handle_Decl (Decl, Arg); + when Iir_Kind_Procedure_Declaration + | Iir_Kind_Function_Declaration => + if not Is_Second_Subprogram_Specification (Decl) then + Handle_Decl (Decl, Arg); + end if; when Iir_Kind_Type_Declaration => declare Def : Iir; @@ -1242,11 +1247,14 @@ package body Sem_Scopes is procedure Use_Selected_Name (Name : Iir) is begin - if Get_Kind (Name) = Iir_Kind_Overload_List then - Add_Declarations_List (Get_Overload_List (Name), True); - else - Add_Declaration (Name, True); - end if; + case Get_Kind (Name) is + when Iir_Kind_Overload_List => + Add_Declarations_List (Get_Overload_List (Name), True); + when Iir_Kind_Error => + null; + when others => + Add_Declaration (Name, True); + end case; end Use_Selected_Name; procedure Use_All_Names (Name: Iir) is @@ -1265,6 +1273,8 @@ package body Sem_Scopes is Add_Package_Declarations (Pkg, True); end if; end; + when Iir_Kind_Error => + null; when others => raise Internal_Error; end case; diff --git a/sem_specs.adb b/sem_specs.adb index cf4d8353c..039e57654 100644 --- a/sem_specs.adb +++ b/sem_specs.adb @@ -27,7 +27,6 @@ with Sem_Scopes; use Sem_Scopes; with Sem_Assocs; use Sem_Assocs; with Libraries; with Iir_Chains; use Iir_Chains; -with Sem_Types; with Flags; use Flags; with Name_Table; with Std_Names; @@ -36,27 +35,6 @@ with Xrefs; use Xrefs; with Back_End; package body Sem_Specs is - -- Compare ATYPE and TYPE_MARK. - -- ATYPE is a type definition, which can be anonymous. - -- TYPE_MARK is a subtype definition, established from a type mark. - -- Therefore, it is the name of a type or a subtype. - -- Return TRUE iff the type mark of ATYPE is TYPE_MARK. - function Is_Same_Type_Mark (Atype : Iir; Type_Mark : Iir) - return Boolean is - begin - if Get_Kind (Atype) in Iir_Kinds_Subtype_Definition - and then Is_Anonymous_Type_Definition (Atype) - then - -- FIXME: to be removed; used to catch uninitialized type_mark. - if Get_Type_Mark (Atype) = Null_Iir then - raise Internal_Error; - end if; - return Get_Type_Mark (Atype) = Type_Mark; - else - return Atype = Type_Mark; - end if; - end Is_Same_Type_Mark; - function Get_Entity_Class_Kind (Decl : Iir) return Tokens.Token_Type is use Tokens; @@ -143,7 +121,6 @@ package body Sem_Specs is procedure Attribute_A_Decl (Decl : Iir; Attr : Iir_Attribute_Specification; - Name : Iir; Check_Class : Boolean; Check_Defined : Boolean) is @@ -201,7 +178,7 @@ package body Sem_Specs is null; end case; - Attr_Decl := Get_Attribute_Designator (Attr); + Attr_Decl := Get_Named_Entity (Get_Attribute_Designator (Attr)); -- LRM93 5.1 -- It is an error if a given attribute is associated more than once with @@ -213,10 +190,10 @@ package body Sem_Specs is El := Get_Attribute_Value_Chain (Decl); while El /= Null_Iir loop declare - El_Attr : Iir_Attribute_Declaration; + El_Attr : constant Iir_Attribute_Declaration := + Get_Named_Entity (Get_Attribute_Designator + (Get_Attribute_Specification (El))); begin - El_Attr := Get_Attribute_Designator - (Get_Attribute_Specification (El)); if El_Attr = Attr_Decl then if Get_Attribute_Specification (El) = Attr then -- Was already specified with the same attribute value. @@ -270,9 +247,6 @@ package body Sem_Specs is Set_Attribute_Value_Chain (Decl, El); Set_Spec_Chain (El, Get_Attribute_Value_Spec_Chain (Attr)); Set_Attribute_Value_Spec_Chain (Attr, El); - if Name /= Null_Iir then - Xref_Ref (Name, Decl); - end if; if (Flags.Vhdl_Std >= Vhdl_93c and then Attr_Decl = Foreign_Attribute) @@ -329,20 +303,22 @@ package body Sem_Specs is -- If declaration DECL matches then named entity ENT, apply attribute -- specification and returns TRUE. Otherwise, return FALSE. + -- Note: ENT and DECL are different for aliases. function Sem_Named_Entity1 (Ent : Iir; Decl : Iir) return Boolean is - Ent_Id : Name_Id; + Ent_Id : constant Name_Id := Get_Identifier (Ent); begin - Ent_Id := Get_Identifier (Ent); if (Name = Null_Iir or else Ent_Id = Get_Identifier (Name)) and then Ent_Id /= Null_Identifier then + if Is_Designators then + Xref_Ref (Name, Ent); + end if; if Get_Visible_Flag (Ent) = False then Error_Msg_Sem (Disp_Node (Ent) & " is not yet visible", Attr); else - Attribute_A_Decl - (Decl, Attr, Name, Is_Designators, Check_Defined); + Attribute_A_Decl (Decl, Attr, Is_Designators, Check_Defined); return True; end if; end if; @@ -354,8 +330,8 @@ package body Sem_Specs is case Get_Kind (Ent) is when Iir_Kinds_Library_Unit_Declaration | Iir_Kinds_Concurrent_Statement - | Iir_Kinds_Function_Declaration - | Iir_Kinds_Procedure_Declaration + | Iir_Kind_Implicit_Function_Declaration + | Iir_Kind_Implicit_Procedure_Declaration | Iir_Kinds_Sequential_Statement | Iir_Kinds_Non_Alias_Object_Declaration | Iir_Kind_Type_Declaration @@ -366,19 +342,24 @@ package body Sem_Specs is | Iir_Kind_Group_Template_Declaration | Iir_Kind_Group_Declaration => Res := Res or Sem_Named_Entity1 (Ent, Ent); + when Iir_Kind_Function_Declaration + | Iir_Kind_Procedure_Declaration => + if not Is_Second_Subprogram_Specification (Ent) then + Res := Res or Sem_Named_Entity1 (Ent, Ent); + end if; when Iir_Kind_Object_Alias_Declaration => -- LRM93 5.1 -- An entity designator that denotes an alias of an object is -- required to denote the entire object, and not a subelement -- or slice thereof. declare - Decl : Iir; + Decl : constant Iir := Get_Name (Ent); + Base : constant Iir := Get_Object_Prefix (Decl, False); Applied : Boolean; begin - Decl := Get_Name (Ent); - Applied := Sem_Named_Entity1 (Ent, Get_Base_Name (Decl)); + Applied := Sem_Named_Entity1 (Ent, Base); -- FIXME: check the alias denotes a local entity... - if Applied and then Get_Base_Name (Decl) /= Decl then + if Applied and then Base /= Decl then Error_Msg_Sem (Disp_Node (Ent) & " does not denote the entire object", Attr); @@ -386,7 +367,8 @@ package body Sem_Specs is Res := Res or Applied; end; when Iir_Kind_Non_Object_Alias_Declaration => - Res := Res or Sem_Named_Entity1 (Ent, Get_Name (Ent)); + Res := Res + or Sem_Named_Entity1 (Ent, Get_Named_Entity (Get_Name (Ent))); when Iir_Kind_Attribute_Declaration | Iir_Kind_Attribute_Specification | Iir_Kind_Configuration_Specification @@ -589,13 +571,18 @@ package body Sem_Specs is procedure Sem_Signature_Entity_Designator (Sig : Iir_Signature; Attr : Iir_Attribute_Specification) is + Prefix : Iir; Inter : Name_Interpretation_Type; List : Iir_List; Ov_List : Iir_Overload_List; Name : Iir; begin List := Create_Iir_List; - Inter := Get_Interpretation (Get_Identifier (Get_Prefix (Sig))); + + -- Sem_Name cannot be used here (at least not directly) because only + -- the declarations of the current scope are considered. + Prefix := Get_Prefix (Sig); + Inter := Get_Interpretation (Get_Identifier (Prefix)); while Valid_Interpretation (Inter) loop exit when not Is_In_Current_Declarative_Region (Inter); if not Is_Potentially_Visible (Inter) then @@ -618,6 +605,7 @@ package body Sem_Specs is end if; Inter := Get_Next_Interpretation (Inter); end loop; + Ov_List := Create_Overload_List (List); Name := Sem_Decls.Sem_Signature (Ov_List, Sig); Destroy_Iir_List (List); @@ -625,7 +613,12 @@ package body Sem_Specs is if Name = Null_Iir then return; end if; - Attribute_A_Decl (Name, Attr, Get_Prefix (Sig), True, True); + + Set_Named_Entity (Prefix, Name); + Prefix := Finish_Sem_Name (Prefix); + Set_Prefix (Sig, Prefix); + + Attribute_A_Decl (Name, Attr, True, True); end Sem_Signature_Entity_Designator; procedure Sem_Attribute_Specification @@ -634,26 +627,28 @@ package body Sem_Specs is is use Tokens; - Name : Iir_Attribute_Declaration; + Name : Iir; + Attr : Iir_Attribute_Declaration; List : Iir_List; Expr : Iir; Res : Boolean; begin -- LRM93 5.1 -- The attribute designator must denote an attribute. - Name := Find_Declaration (Get_Attribute_Designator (Spec), - Decl_Attribute); - if Name = Null_Iir then + Name := Sem_Denoting_Name (Get_Attribute_Designator (Spec)); + Set_Attribute_Designator (Spec, Name); + + Attr := Get_Named_Entity (Name); + if Get_Kind (Attr) /= Iir_Kind_Attribute_Declaration then + Error_Class_Match (Name, "attribute"); return; end if; - Set_Attribute_Designator (Spec, Name); - -- LRM 5.1 -- The type of the expression in the attribute specification must be -- the same as (or implicitly convertible to) the type mark in the -- corresponding attribute declaration. - Expr := Sem_Expression (Get_Expression (Spec), Get_Type (Name)); + Expr := Sem_Expression (Get_Expression (Spec), Get_Type (Attr)); if Expr /= Null_Iir then Check_Read (Expr); Set_Expression (Spec, Eval_Expr_If_Static (Expr)); @@ -830,9 +825,31 @@ package body Sem_Specs is end loop; end Check_Post_Attribute_Specification; - procedure Sem_Disconnect_Specification + -- Compare ATYPE and TYPE_MARK. + -- ATYPE is a type definition, which can be anonymous. + -- TYPE_MARK is a subtype definition, established from a type mark. + -- Therefore, it is the name of a type or a subtype. + -- Return TRUE iff the type mark of ATYPE is TYPE_MARK. + function Is_Same_Type_Mark (Atype : Iir; Type_Mark : Iir) + return Boolean is + begin + if Get_Kind (Atype) in Iir_Kinds_Subtype_Definition + and then Is_Anonymous_Type_Definition (Atype) + then + -- FIXME: to be removed; used to catch uninitialized type_mark. + if Get_Subtype_Type_Mark (Atype) = Null_Iir then + raise Internal_Error; + end if; + return Get_Type (Get_Subtype_Type_Mark (Atype)) = Type_Mark; + else + return Atype = Type_Mark; + end if; + end Is_Same_Type_Mark; + + procedure Sem_Disconnection_Specification (Dis : Iir_Disconnection_Specification) is + Type_Mark : Iir; Atype : Iir; Time_Expr : Iir; List : Iir_List; @@ -841,11 +858,10 @@ package body Sem_Specs is Prefix : Iir; begin -- Sem type mark. - Atype := Get_Type (Dis); - Atype := Sem_Types.Sem_Subtype_Indication (Atype); - if Atype /= Null_Iir then - Set_Type (Dis, Atype); - end if; + Type_Mark := Get_Type_Mark (Dis); + Type_Mark := Sem_Type_Mark (Type_Mark); + Set_Type_Mark (Dis, Type_Mark); + Atype := Get_Type (Type_Mark); -- LRM93 5.3 -- The time expression in a disconnection specification must be static @@ -868,13 +884,16 @@ package body Sem_Specs is for I in Natural loop El := Get_Nth_Element (List, I); exit when El = Null_Iir; - Sem_Name (El, False); + + Sem_Name (El); + El := Finish_Sem_Name (El); + Replace_Nth_Element (List, I, El); Sig := Get_Named_Entity (El); Sig := Name_To_Object (Sig); if Sig /= Null_Iir then Set_Type (El, Get_Type (Sig)); - Prefix := Get_Base_Name (Sig); + Prefix := Get_Object_Prefix (Sig); -- LRM93 5.3 -- Each signal name in a signal list in a guarded signal -- specification must be a locally static name that @@ -898,7 +917,7 @@ package body Sem_Specs is -- LRM93 5.3 -- If the guarded signal is a declared signal or a slice of -- thereof, the type mark must be the same as the type mark - -- indicated in the guarded sugnal specification. + -- indicated in the guarded signal specification. -- If the guarded signal is an array element of an explicitly -- declared signal, the type mark must be the same as the -- element subtype indication in the (explicit or implicit) @@ -924,55 +943,63 @@ package body Sem_Specs is end if; end loop; end if; - end Sem_Disconnect_Specification; + end Sem_Disconnection_Specification; -- Semantize entity aspect ASPECT and return the entity declaration. -- Return NULL_IIR if not found. - function Sem_Entity_Aspect (Aspect : Iir) return Iir - is - Entity : Iir; - New_Entity : Iir; - Conf : Iir; - Arch : Iir; - Arch_Unit : Iir; + function Sem_Entity_Aspect (Aspect : Iir) return Iir is begin case Get_Kind (Aspect) is when Iir_Kind_Entity_Aspect_Entity => - Entity := Get_Entity (Aspect); - New_Entity := Find_Declaration (Entity, Decl_Entity); - if New_Entity = Null_Iir then - return Null_Iir; - end if; - -- Note: dependency is added by Find_Declaration. - Set_Entity (Aspect, New_Entity); - - -- Check architecture. - Arch := Get_Architecture (Aspect); - if Arch /= Null_Iir then - Arch_Unit := Libraries.Find_Secondary_Unit - (Get_Design_Unit (New_Entity), Get_Identifier (Arch)); - if Arch_Unit /= Null_Iir then - Xref_Ref (Arch, Arch_Unit); + declare + Entity_Name : Iir; + Entity : Iir; + Arch_Name : Iir; + Arch_Unit : Iir; + begin + Entity_Name := Sem_Denoting_Name (Get_Entity_Name (Aspect)); + Set_Entity_Name (Aspect, Entity_Name); + Entity := Get_Named_Entity (Entity_Name); + if Get_Kind (Entity) /= Iir_Kind_Entity_Declaration then + Error_Class_Match (Entity_Name, "entity"); + return Null_Iir; end if; + -- Note: dependency is added by Sem_Denoting_Name. + + -- Check architecture. + Arch_Name := Get_Architecture (Aspect); + if Arch_Name /= Null_Iir then + Arch_Unit := Libraries.Find_Secondary_Unit + (Get_Design_Unit (Entity), Get_Identifier (Arch_Name)); + Set_Named_Entity (Arch_Name, Arch_Unit); + if Arch_Unit /= Null_Iir then + Xref_Ref (Arch_Name, Arch_Unit); + end if; - -- FIXME: may emit a warning if the architecture does not - -- exist. - -- Note: the design needs the architecture. - Add_Dependence (Aspect); - end if; - return New_Entity; + -- FIXME: may emit a warning if the architecture does not + -- exist. + -- Note: the design needs the architecture. + Add_Dependence (Aspect); + end if; + return Entity; + end; when Iir_Kind_Entity_Aspect_Configuration => - Conf := Get_Configuration (Aspect); - Conf := Find_Declaration (Conf, Decl_Configuration); - if Conf = Null_Iir then - return Null_Iir; - end if; - - -- Note: dependency is added by Find_Declaration. - Set_Configuration (Aspect, Conf); + declare + Conf_Name : Iir; + Conf : Iir; + begin + Conf_Name := + Sem_Denoting_Name (Get_Configuration_Name (Aspect)); + Set_Configuration_Name (Aspect, Conf_Name); + Conf := Get_Named_Entity (Conf_Name); + if Get_Kind (Conf) /= Iir_Kind_Configuration_Declaration then + Error_Class_Match (Conf, "configuration"); + return Null_Iir; + end if; - return Get_Entity (Conf); + return Get_Entity (Conf); + end; when Iir_Kind_Entity_Aspect_Open => return Null_Iir; @@ -1159,17 +1186,19 @@ package body Sem_Specs is (Chain : Iir; Check_Applied : Boolean) return Boolean is - Comp : Iir; + Comp : constant Iir := Get_Named_Entity (Get_Component_Name (Spec)); + Inst : Iir; El : Iir; Res : Boolean; begin - Comp := Get_Component_Name (Spec); El := Get_Concurrent_Statement_Chain (Chain); Res := False; while El /= Null_Iir loop case Get_Kind (El) is when Iir_Kind_Component_Instantiation_Statement => - if Get_Instantiated_Unit (El) = Comp + Inst := Get_Instantiated_Unit (El); + if Get_Kind (Inst) in Iir_Kinds_Denoting_Name + and then Get_Named_Entity (Inst) = Comp and then (not Check_Applied or else Get_Component_Configuration (El) = Null_Iir) @@ -1195,14 +1224,18 @@ package body Sem_Specs is El : Iir; Inter : Sem_Scopes.Name_Interpretation_Type; Comp : Iir; + Comp_Name : Iir; Inst : Iir; + Inst_Unit : Iir; begin Primary_Entity_Aspect := Null_Iir; - Comp := Find_Declaration (Get_Component_Name (Spec), Decl_Component); - if Comp = Null_Iir then + Comp_Name := Sem_Denoting_Name (Get_Component_Name (Spec)); + Set_Component_Name (Spec, Comp_Name); + Comp := Get_Named_Entity (Comp_Name); + if Get_Kind (Comp) /= Iir_Kind_Component_Declaration then + Error_Class_Match (Comp_Name, "component"); return; end if; - Set_Component_Name (Spec, Comp); List := Get_Instantiation_List (Spec); if List = Iir_List_All then @@ -1263,24 +1296,26 @@ package body Sem_Specs is -- FIXME. Error_Msg_Sem ("label not in block declarative part", El); else - Comp := Get_Declaration (Inter); - if Get_Kind (Comp) /= Iir_Kind_Component_Instantiation_Statement + Inst := Get_Declaration (Inter); + if Get_Kind (Inst) /= Iir_Kind_Component_Instantiation_Statement then Error_Msg_Sem ("label does not denote an instantiation", El); else - Inst := Get_Instantiated_Unit (Comp); - if Get_Kind (Inst) /= Iir_Kind_Component_Declaration then + Inst_Unit := Get_Instantiated_Unit (Inst); + if Get_Kind (Inst_Unit) not in Iir_Kinds_Denoting_Name + or else (Get_Kind (Get_Named_Entity (Inst_Unit)) + /= Iir_Kind_Component_Declaration) + then Error_Msg_Sem ("specification does not apply to direct instantiation", El); - elsif Inst /= Get_Component_Name (Spec) then + elsif Get_Named_Entity (Inst_Unit) /= Comp then Error_Msg_Sem ("component names mismatch", El); else Apply_Configuration_Specification - (Comp, Spec, Primary_Entity_Aspect); - Xref_Ref (El, Comp); - Free_Iir (El); - Replace_Nth_Element (List, I, Comp); + (Inst, Spec, Primary_Entity_Aspect); + Xref_Ref (El, Inst); + Set_Named_Entity (El, Inst); end if; end if; end if; @@ -1295,7 +1330,7 @@ package body Sem_Specs is Component : Iir; begin Sem_Component_Specification (Parent_Stmts, Conf, Primary_Entity_Aspect); - Component := Get_Component_Name (Conf); + Component := Get_Named_Entity (Get_Component_Name (Conf)); -- Return now in case of error. if Get_Kind (Component) /= Iir_Kind_Component_Declaration then @@ -1318,6 +1353,7 @@ package body Sem_Specs is return Iir_Binding_Indication is Entity : Iir_Entity_Declaration; + Entity_Name : Iir; Aspect : Iir; Res : Iir; Design_Unit : Iir_Design_Unit; @@ -1386,7 +1422,12 @@ package body Sem_Specs is Res := Create_Iir (Iir_Kind_Binding_Indication); Aspect := Create_Iir (Iir_Kind_Entity_Aspect_Entity); Location_Copy (Aspect, Parent); - Set_Entity (Aspect, Entity); + + Entity_Name := Create_Iir (Iir_Kind_Simple_Name); + Location_Copy (Entity_Name, Parent); + Set_Named_Entity (Entity_Name, Entity); + + Set_Entity_Name (Aspect, Entity_Name); Set_Entity_Aspect (Res, Aspect); -- LRM 5.2.2 diff --git a/sem_specs.ads b/sem_specs.ads index f37d32ff9..c27207b01 100644 --- a/sem_specs.ads +++ b/sem_specs.ads @@ -31,7 +31,7 @@ package Sem_Specs is procedure Check_Post_Attribute_Specification (Attr_Spec_Chain : Iir; Decl : Iir); - procedure Sem_Disconnect_Specification + procedure Sem_Disconnection_Specification (Dis : Iir_Disconnection_Specification); procedure Sem_Configuration_Specification diff --git a/sem_stmts.adb b/sem_stmts.adb index a62890a55..b4d84f098 100644 --- a/sem_stmts.adb +++ b/sem_stmts.adb @@ -205,8 +205,13 @@ package body Sem_Stmts is end if; end loop; return False; + elsif Get_Kind (N1) in Iir_Kinds_Denoting_Name + and then Get_Kind (N2) in Iir_Kinds_Denoting_Name + then + return Get_Named_Entity (N1) /= Get_Named_Entity (N2); + else + return True; end if; - return True; end Is_Disjoint; procedure Check_Uniq_Aggregate_Associated @@ -544,7 +549,9 @@ package body Sem_Stmts is if Get_Time (We) /= Null_Iir then Expr := Sem_Expression (Get_Time (We), Time_Type_Definition); if Expr /= Null_Iir then + Set_Time (We, Expr); Check_Read (Expr); + if Get_Expr_Staticness (Expr) = Locally or else (Get_Kind (Expr) = Iir_Kind_Physical_Int_Literal and then Flags.Flag_Time_64) @@ -571,7 +578,6 @@ package body Sem_Stmts is Last_Time := Time; end if; end if; - Set_Time (We, Expr); end if; else if We /= Waveform_Chain then @@ -992,26 +998,28 @@ package body Sem_Stmts is -- El is an iir_identifier. El := Get_Nth_Element (List, I); exit when El = Null_Iir; - Sem_Name (El, False); + + Sem_Name (El); + Res := Get_Named_Entity (El); if Res = Error_Mark then null; elsif Is_Overload_List (Res) or else not Is_Object_Name (Res) then Error_Msg_Sem ("a sensitivity element must be a signal name", El); else + Res := Finish_Sem_Name (El); Prefix := Get_Object_Prefix (Res); case Get_Kind (Prefix) is when Iir_Kind_Signal_Declaration | Iir_Kind_Guard_Signal_Declaration | Iir_Kinds_Signal_Attribute => - Xref_Name (El); + null; when Iir_Kind_Signal_Interface_Declaration => if not Iir_Mode_Readable (Get_Mode (Prefix)) then Error_Msg_Sem (Disp_Node (Res) & " of mode out" & " can't be in a sensivity list", El); end if; - Xref_Name (El); when others => Error_Msg_Sem (Disp_Node (Res) & " is neither a signal nor a port", El); @@ -1101,7 +1109,8 @@ package body Sem_Stmts is procedure Sem_Exit_Next_Statement (Stmt : Iir) is Cond: Iir; - Label: Iir; + Loop_Label : Iir; + Loop_Stmt: Iir; P : Iir; begin Cond := Get_Condition (Stmt); @@ -1109,20 +1118,24 @@ package body Sem_Stmts is Cond := Sem_Condition (Cond); Set_Condition (Stmt, Cond); end if; - Label := Get_Loop (Stmt); - if Label /= Null_Iir then - Label := Find_Declaration (Label, Decl_Label); - end if; - if Label /= Null_Iir then - case Get_Kind (Label) is - when Iir_Kind_While_Loop_Statement - | Iir_Kind_For_Loop_Statement => - Set_Loop (Stmt, Label); + + Loop_Label := Get_Loop_Label (Stmt); + if Loop_Label /= Null_Iir then + Loop_Label := Sem_Denoting_Name (Loop_Label); + Set_Loop_Label (Stmt, Loop_Label); + Loop_Stmt := Get_Named_Entity (Loop_Label); + case Get_Kind (Loop_Stmt) is + when Iir_Kind_For_Loop_Statement + | Iir_Kind_While_Loop_Statement => + null; when others => - Error_Msg_Sem ("loop label expected", Stmt); - Label := Null_Iir; + Error_Class_Match (Loop_Label, "loop statement"); + Loop_Stmt := Null_Iir; end case; + else + Loop_Stmt := Null_Iir; end if; + -- Check the current statement is inside the labeled loop. P := Stmt; loop @@ -1130,7 +1143,7 @@ package body Sem_Stmts is case Get_Kind (P) is when Iir_Kind_While_Loop_Statement | Iir_Kind_For_Loop_Statement => - if Label = Null_Iir or else Label = P then + if Loop_Stmt = Null_Iir or else P = Loop_Stmt then exit; end if; when Iir_Kind_If_Statement @@ -1181,7 +1194,7 @@ package body Sem_Stmts is Open_Declarative_Region; Set_Is_Within_Flag (Stmt, True); - Iterator := Get_Iterator_Scheme (Stmt); + Iterator := Get_Parameter_Specification (Stmt); Sem_Scopes.Add_Name (Iterator); Sem_Iterator (Iterator, None); Set_Visible_Flag (Iterator, True); @@ -1266,21 +1279,28 @@ package body Sem_Stmts is return Iir is Inst : Iir; + Comp_Name : Iir; + Comp : Iir; begin Inst := Get_Instantiated_Unit (Stmt); - if Get_Kind (Inst) = Iir_Kind_Component_Declaration then - -- Already semantized before, while trying to separate - -- concurrent procedure calls from instantiation stmts. - return Inst; - elsif Get_Kind (Inst) in Iir_Kinds_Name then + if Get_Kind (Inst) in Iir_Kinds_Denoting_Name then + Comp := Get_Named_Entity (Inst); + if Comp /= Null_Iir then + -- Already semantized before, while trying to separate + -- concurrent procedure calls from instantiation stmts. + pragma Assert (Get_Kind (Comp) = Iir_Kind_Component_Declaration); + return Comp; + end if; -- The component may be an entity or a configuration. - Inst := Find_Declaration (Inst, Decl_Component); - if Inst = Null_Iir then + Comp_Name := Sem_Denoting_Name (Inst); + Set_Instantiated_Unit (Stmt, Comp_Name); + Comp := Get_Named_Entity (Comp_Name); + if Get_Kind (Comp) /= Iir_Kind_Component_Declaration then + Error_Class_Match (Comp_Name, "component"); return Null_Iir; end if; - Set_Instantiated_Unit (Stmt, Inst); - return Inst; + return Comp; else return Sem_Entity_Aspect (Inst); end if; @@ -1358,17 +1378,18 @@ package body Sem_Stmts is begin Call := Get_Procedure_Call (Stmt); if Get_Parameter_Association_Chain (Call) = Null_Iir then - Imp := Get_Implementation (Call); - Sem_Name (Imp, False); + Imp := Get_Prefix (Call); + Sem_Name (Imp); + Set_Prefix (Call, Imp); + Decl := Get_Named_Entity (Imp); if Get_Kind (Decl) = Iir_Kind_Component_Declaration then N_Stmt := Create_Iir (Iir_Kind_Component_Instantiation_Statement); Label := Get_Label (Stmt); Set_Label (N_Stmt, Label); Set_Parent (N_Stmt, Get_Parent (Stmt)); - Set_Instantiated_Unit (N_Stmt, Decl); + Set_Instantiated_Unit (N_Stmt, Finish_Sem_Name (Imp)); Location_Copy (N_Stmt, Stmt); - Xref_Name (Imp); if Label /= Null_Identifier then -- A component instantiation statement must have @@ -1387,7 +1408,7 @@ package body Sem_Stmts is Sem_Procedure_Call (Call, Stmt); if Is_Passive then - Imp := Get_Implementation (Call); + Imp := Get_Named_Entity (Get_Implementation (Call)); if Get_Kind (Imp) = Iir_Kind_Procedure_Declaration then Decl := Get_Interface_Declaration_Chain (Imp); while Decl /= Null_Iir loop @@ -1467,7 +1488,6 @@ package body Sem_Stmts is -- the guard expression is an implicit definition of a signal named -- GUARD. Create this definition. This is necessary for the type. - Set_Base_Name (Guard, Guard); Set_Identifier (Guard, Std_Names.Name_Guard); Set_Type (Guard, Boolean_Type_Definition); Set_Block_Statement (Guard, Stmt); diff --git a/sem_types.adb b/sem_types.adb index ffa426809..7a2cb6828 100644 --- a/sem_types.adb +++ b/sem_types.adb @@ -33,10 +33,9 @@ with Ieee.Std_Logic_1164; with Xrefs; use Xrefs; package body Sem_Types is - procedure Set_Type_Has_Signal (Atype : Iir) - is + procedure Set_Type_Has_Signal (Atype : Iir) is begin - -- Sanity check. + -- Sanity check: ATYPE can be a signal type (eg: not an access type) if not Get_Signal_Type_Flag (Atype) then -- Do not crash since this may be called on an erroneous design. return; @@ -47,8 +46,11 @@ package body Sem_Types is return; end if; + -- This type is used to declare a signal. Set_Has_Signal_Flag (Atype, True); + -- Mark resolution function, and for composite types, also mark type + -- of elements. case Get_Kind (Atype) is when Iir_Kind_Integer_Type_Definition | Iir_Kind_Enumeration_Type_Definition @@ -58,7 +60,6 @@ package body Sem_Types is when Iir_Kinds_Subtype_Definition => declare Func : Iir_Function_Declaration; - Mark : Iir; begin Set_Type_Has_Signal (Get_Base_Type (Atype)); -- Mark the resolution function (this may be required by the @@ -71,10 +72,6 @@ package body Sem_Types is Set_Resolution_Function_Flag (Func, True); end if; end if; - Mark := Get_Type_Mark (Atype); - if Mark /= Null_Iir then - Set_Type_Has_Signal (Mark); - end if; end; when Iir_Kind_Array_Type_Definition => Set_Type_Has_Signal (Get_Element_Subtype (Atype)); @@ -103,10 +100,11 @@ package body Sem_Types is -- Sem a range expression that appears in an integer, real or physical -- type definition. -- - -- Both left and right bounds must be of the same type kind, ie + -- Both left and right bounds must be of the same type class, ie -- integer types, or if INT_ONLY is false, real types. -- However, the two bounds need not have the same type. - function Sem_Range_Expression (Expr : Iir; Int_Only : Boolean) return Iir + function Sem_Type_Range_Expression (Expr : Iir; Int_Only : Boolean) + return Iir is Left, Right: Iir; Bt_L_Kind, Bt_R_Kind : Iir_Kind; @@ -146,8 +144,8 @@ package body Sem_Types is end if; else if Bt_L_Kind /= Bt_R_Kind then - Error_Msg_Sem ("left and right bounds must be of the same type", - Expr); + Error_Msg_Sem + ("left and right bounds must be of the same type class", Expr); return Null_Iir; end if; case Bt_L_Kind is @@ -163,10 +161,10 @@ package body Sem_Types is end if; return Expr; - end Sem_Range_Expression; + end Sem_Type_Range_Expression; function Create_Integer_Type (Loc : Iir; Constraint : Iir; Decl : Iir) - return Iir + return Iir is Ntype: Iir_Integer_Subtype_Definition; Ndef: Iir_Integer_Type_Definition; @@ -195,23 +193,22 @@ package body Sem_Types is function Range_Expr_To_Type_Definition (Expr : Iir; Decl: Iir) return Iir is - Left, Right : Iir; + Rng : Iir; + Res : Iir; + Base_Type : Iir; begin - if Sem_Range_Expression (Expr, False) = Null_Iir then + if Sem_Type_Range_Expression (Expr, False) = Null_Iir then return Null_Iir; end if; - Left := Get_Left_Limit (Expr); - Right := Get_Right_Limit (Expr); - if Get_Expr_Staticness (Expr) = Locally then - Left := Eval_Expr (Left); - Set_Left_Limit (Expr, Left); - Right := Eval_Expr (Right); - Set_Right_Limit (Expr, Right); + Rng := Eval_Range_If_Static (Expr); + if Get_Expr_Staticness (Rng) /= Locally then + -- FIXME: create an artificial range to avoid error storm ? + null; end if; - case Get_Kind (Get_Base_Type (Get_Type (Left))) is + case Get_Kind (Get_Base_Type (Get_Type (Get_Left_Limit (Rng)))) is when Iir_Kind_Integer_Type_Definition => - return Create_Integer_Type (Expr, Expr, Decl); + Res := Create_Integer_Type (Expr, Rng, Decl); when Iir_Kind_Floating_Type_Definition => declare Ntype: Iir_Floating_Subtype_Definition; @@ -227,16 +224,33 @@ package body Sem_Types is Set_Signal_Type_Flag (Ndef, True); Set_Base_Type (Ntype, Ndef); Set_Type_Declarator (Ntype, Decl); - Set_Range_Constraint (Ntype, Expr); + Set_Range_Constraint (Ntype, Rng); Set_Resolved_Flag (Ntype, False); Set_Type_Staticness (Ntype, Get_Expr_Staticness (Expr)); Set_Signal_Type_Flag (Ntype, True); - return Ntype; + Res := Ntype; end; when others => -- sem_range_expression should catch such errors. raise Internal_Error; end case; + + -- A type and a subtype were declared. The type of the bounds are now + -- used for the implicit subtype declaration. But the type of the + -- bounds aren't of the type of the type declaration (this is 'obvious' + -- because they exist before the type declaration). Override their + -- type. This is doable without destroying information as they are + -- either literals (of type convertible_xx_type_definition) or an + -- evaluated literal. + -- + -- Overriding makes these implicit subtype homogenous with explicit + -- subtypes. + Base_Type := Get_Base_Type (Res); + Set_Type (Rng, Base_Type); + Set_Type (Get_Left_Limit (Rng), Base_Type); + Set_Type (Get_Right_Limit (Rng), Base_Type); + + return Res; end Range_Expr_To_Type_Definition; function Create_Physical_Literal (Val : Iir_Int64; Unit : Iir) return Iir @@ -252,11 +266,12 @@ package body Sem_Types is return Lit; end Create_Physical_Literal; - -- Sem a physical type definition. Create a subtype. + -- Analyze a physical type definition. Create a subtype. function Sem_Physical_Type_Definition (Range_Expr: Iir; Decl : Iir) return Iir_Physical_Subtype_Definition is Unit: Iir_Unit_Declaration; + Unit_Name : Iir; Def : Iir_Physical_Type_Definition; Sub_Type: Iir_Physical_Subtype_Definition; Range_Expr1: Iir; @@ -265,7 +280,7 @@ package body Sem_Types is begin Def := Get_Type (Range_Expr); - -- LRM93 §4.1 + -- LRM93 4.1 -- The simple name declared by a type declaration denotes the -- declared type, unless the type declaration declares both a base -- type and a subtype of the base type, in which case the simple name @@ -276,13 +291,18 @@ package body Sem_Types is Set_Type_Staticness (Def, Locally); Set_Signal_Type_Flag (Def, True); - -- LRM93 §3.1.3 + -- Set the type definition of the type declaration (it was currently the + -- range expression). Do it early so that the units can be referenced + -- by expanded names. + Set_Type_Definition (Decl, Def); + + -- LRM93 3.1.3 -- Each bound of a range constraint that is used in a physical type -- definition must be a locally static expression of some integer type -- but the two bounds need not have the same integer type. case Get_Kind (Range_Expr) is when Iir_Kind_Range_Expression => - Range_Expr1 := Sem_Range_Expression (Range_Expr, True); + Range_Expr1 := Sem_Type_Range_Expression (Range_Expr, True); when others => Error_Kind ("sem_physical_type_definition", Range_Expr); end case; @@ -293,7 +313,7 @@ package body Sem_Types is Range_Expr1); Range_Expr1 := Null_Iir; else - Range_Expr1 := Eval_Expr (Range_Expr1); + Range_Expr1 := Eval_Range_If_Static (Range_Expr1); end if; end if; @@ -303,58 +323,20 @@ package body Sem_Types is Set_Base_Type (Sub_Type, Def); Set_Signal_Type_Flag (Sub_Type, True); - -- Sem primary units. + -- Analyze the primary unit. Unit := Get_Unit_Chain (Def); - Lit := Create_Physical_Literal (1, Unit); + Unit_Name := Build_Simple_Name (Unit, Unit); + Lit := Create_Physical_Literal (1, Unit_Name); Set_Physical_Unit_Value (Unit, Lit); - Add_Name (Unit); + Sem_Scopes.Add_Name (Unit); Set_Type (Unit, Def); Set_Expr_Staticness (Unit, Locally); + Set_Name_Staticness (Unit, Locally); Set_Visible_Flag (Unit, True); Xref_Decl (Unit); - -- Sem secondary units. - Unit := Get_Chain (Unit); - while Unit /= Null_Iir loop - -- Val := Sem_Physical_Literal (Get_Multiplier (Unit)); - Val := Sem_Expression (Get_Physical_Literal (Unit), Def); - if Val /= Null_Iir then - Val := Eval_Expr (Val); - Set_Physical_Literal (Unit, Val); - if Get_Kind (Val) = Iir_Kind_Unit_Declaration then - Val := Create_Physical_Literal (1, Val); - end if; - Set_Physical_Unit_Value (Unit, Val); - - -- LRM93 §3.1 - -- The position number of unit names need not lie within the range - -- specified by the range constraint. - -- GHDL: this was not true in VHDL87. - -- GHDL: This is not so simple if 1 is not included in the range. - if False and then Flags.Vhdl_Std = Vhdl_87 - and then Range_Expr1 /= Null_Iir - then - if not Eval_Int_In_Range (Get_Value (Unit), Range_Expr1) then - Error_Msg_Sem - ("physical literal does not lie within the range", Unit); - end if; - end if; - else - -- Avoid errors storm. - Set_Physical_Literal (Unit, Get_Primary_Unit (Def)); - Set_Physical_Unit_Value (Unit, Lit); - end if; - - Sem_Scopes.Add_Name (Unit); - Set_Type (Unit, Def); - Set_Expr_Staticness (Unit, Locally); - Sem_Scopes.Name_Visible (Unit); - Xref_Decl (Unit); - Unit := Get_Chain (Unit); - end loop; - if Range_Expr1 /= Null_Iir then declare -- Convert an integer literal to a physical literal. @@ -368,7 +350,7 @@ package body Sem_Types is Location_Copy (Res, Lim); Set_Type (Res, Def); Set_Value (Res, Get_Value (Lim)); - Set_Unit_Name (Res, Get_Primary_Unit (Def)); + Set_Unit_Name (Res, Get_Primary_Unit_Name (Def)); Set_Expr_Staticness (Res, Locally); Set_Literal_Origin (Res, Lim); return Res; @@ -395,6 +377,46 @@ package body Sem_Types is end if; Set_Resolved_Flag (Sub_Type, False); + -- Analyze secondary units. + Unit := Get_Chain (Unit); + while Unit /= Null_Iir loop + Sem_Scopes.Add_Name (Unit); + Val := Sem_Expression (Get_Physical_Literal (Unit), Def); + if Val /= Null_Iir then + Set_Physical_Literal (Unit, Val); + Val := Eval_Static_Expr (Val); + if Get_Kind (Val) = Iir_Kind_Unit_Declaration then + Val := Create_Physical_Literal (1, Val); + end if; + Set_Physical_Unit_Value (Unit, Val); + + -- LRM93 §3.1 + -- The position number of unit names need not lie within the range + -- specified by the range constraint. + -- GHDL: this was not true in VHDL87. + -- GHDL: This is not so simple if 1 is not included in the range. + if False and then Flags.Vhdl_Std = Vhdl_87 + and then Range_Expr1 /= Null_Iir + then + if not Eval_Int_In_Range (Get_Value (Unit), Range_Expr1) then + Error_Msg_Sem + ("physical literal does not lie within the range", Unit); + end if; + end if; + else + -- Avoid errors storm. + Set_Physical_Literal (Unit, Get_Primary_Unit (Def)); + Set_Physical_Unit_Value (Unit, Lit); + end if; + + Set_Type (Unit, Def); + Set_Expr_Staticness (Unit, Locally); + Set_Name_Staticness (Unit, Locally); + Sem_Scopes.Name_Visible (Unit); + Xref_Decl (Unit); + Unit := Get_Chain (Unit); + end loop; + return Sub_Type; end Sem_Physical_Type_Definition; @@ -441,15 +463,16 @@ package body Sem_Types is is El_Type : Iir; begin - El_Type := Get_Element_Subtype (Def); + El_Type := Get_Element_Subtype_Indication (Def); El_Type := Sem_Subtype_Indication (El_Type); if El_Type = Null_Iir then Set_Type_Staticness (Def, None); Set_Resolved_Flag (Def, False); - Set_Element_Subtype (Def, Error_Type); return; end if; - Set_Element_Subtype (Def, El_Type); + Set_Element_Subtype_Indication (Def, El_Type); + + El_Type := Get_Type_Of_Subtype_Indication (El_Type); Check_No_File_Type (El_Type, Def); Set_Signal_Type_Flag (Def, Get_Signal_Type_Flag (El_Type)); @@ -719,55 +742,356 @@ package body Sem_Types is end if; end Get_Array_Constraint; - function Sem_Type_Definition (Def: Iir; Decl: Iir) return Iir + function Sem_Enumeration_Type_Definition (Def: Iir; Decl: Iir) return Iir is begin - case Get_Kind (Def) is - when Iir_Kind_Enumeration_Type_Definition => - Set_Base_Type (Def, Def); - Set_Type_Staticness (Def, Locally); - Set_Signal_Type_Flag (Def, True); + Set_Base_Type (Def, Def); + Set_Type_Staticness (Def, Locally); + Set_Signal_Type_Flag (Def, True); - Create_Range_Constraint_For_Enumeration_Type (Def); + Create_Range_Constraint_For_Enumeration_Type (Def); - -- Makes all literal visible. - declare - El: Iir; - Literal_List: Iir_List; - Only_Characters : Boolean := True; - begin - Literal_List := Get_Enumeration_Literal_List (Def); - for I in Natural loop - El := Get_Nth_Element (Literal_List, I); - exit when El = Null_Iir; - Set_Expr_Staticness (El, Locally); - Set_Name_Staticness (El, Locally); - Set_Base_Name (El, El); - Set_Type (El, Def); - Set_Enumeration_Decl (El, El); - Sem.Compute_Subprogram_Hash (El); - Sem_Scopes.Add_Name (El); - Name_Visible (El); - Xref_Decl (El); - if Only_Characters - and then not Name_Table.Is_Character (Get_Identifier (El)) - then - Only_Characters := False; - end if; - end loop; - Set_Only_Characters_Flag (Def, Only_Characters); - end; - Set_Resolved_Flag (Def, False); + -- Makes all literal visible. + declare + El: Iir; + Literal_List: Iir_List; + Only_Characters : Boolean := True; + begin + Literal_List := Get_Enumeration_Literal_List (Def); + for I in Natural loop + El := Get_Nth_Element (Literal_List, I); + exit when El = Null_Iir; + Set_Expr_Staticness (El, Locally); + Set_Name_Staticness (El, Locally); + Set_Type (El, Def); + Set_Enumeration_Decl (El, El); + Sem.Compute_Subprogram_Hash (El); + Sem_Scopes.Add_Name (El); + Name_Visible (El); + Xref_Decl (El); + if Only_Characters + and then not Name_Table.Is_Character (Get_Identifier (El)) + then + Only_Characters := False; + end if; + end loop; + Set_Only_Characters_Flag (Def, Only_Characters); + end; + Set_Resolved_Flag (Def, False); + + -- Identifier IEEE.Std_Logic_1164.Std_Ulogic. + if Get_Identifier (Decl) = Std_Names.Name_Std_Ulogic + and then + Get_Parent (Decl) = Ieee.Std_Logic_1164.Std_Logic_1164_Pkg + then + Ieee.Std_Logic_1164.Std_Ulogic_Type := Def; + end if; - -- Identifier IEEE.Std_Logic_1164.Std_Ulogic. - if Get_Identifier (Decl) = Std_Names.Name_Std_Ulogic - and then - Get_Parent (Decl) = Ieee.Std_Logic_1164.Std_Logic_1164_Pkg + return Def; + end Sem_Enumeration_Type_Definition; + + function Sem_Record_Type_Definition (Def: Iir) return Iir + is + -- Semantized type of previous element + Last_Type : Iir; + + El_List : constant Iir_List := Get_Elements_Declaration_List (Def); + El: Iir; + El_Type : Iir; + Resolved_Flag : Boolean; + Staticness : Iir_Staticness; + Constraint : Iir_Constraint; + begin + -- LRM 10.1 + -- 5. A record type declaration, + Open_Declarative_Region; + + Resolved_Flag := True; + Last_Type := Null_Iir; + Staticness := Locally; + Constraint := Fully_Constrained; + Set_Signal_Type_Flag (Def, True); + + for I in Natural loop + El := Get_Nth_Element (El_List, I); + exit when El = Null_Iir; + + El_Type := Get_Subtype_Indication (El); + if El_Type /= Null_Iir then + -- Be careful for a declaration list (r,g,b: integer). + El_Type := Sem_Subtype_Indication (El_Type); + Set_Subtype_Indication (El, El_Type); + El_Type := Get_Type_Of_Subtype_Indication (El_Type); + Last_Type := El_Type; + else + El_Type := Last_Type; + end if; + if El_Type /= Null_Iir then + Set_Type (El, El_Type); + Check_No_File_Type (El_Type, El); + if not Get_Signal_Type_Flag (El_Type) then + Set_Signal_Type_Flag (Def, False); + end if; + + -- LRM93 3.2.1.1 + -- The same requirement [must define a constrained array + -- subtype] exits for the subtype indication of an + -- element declaration, if the type of the record + -- element is an array type. + if Vhdl_Std < Vhdl_08 + and then not Is_Fully_Constrained_Type (El_Type) then - Ieee.Std_Logic_1164.Std_Ulogic_Type := Def; + Error_Msg_Sem + ("element declaration of unconstrained " + & Disp_Node (El_Type) & " is not allowed", El); end if; + Resolved_Flag := + Resolved_Flag and Get_Resolved_Flag (El_Type); + Staticness := Min (Staticness, + Get_Type_Staticness (El_Type)); + Constraint := Update_Record_Constraint + (Constraint, El_Type); + else + Staticness := None; + end if; + Sem_Scopes.Add_Name (El); + Name_Visible (El); + Xref_Decl (El); + end loop; + Close_Declarative_Region; + Set_Base_Type (Def, Def); + Set_Resolved_Flag (Def, Resolved_Flag); + Set_Type_Staticness (Def, Staticness); + Set_Constraint_State (Def, Constraint); + return Def; + end Sem_Record_Type_Definition; - return Def; + function Sem_Unbounded_Array_Type_Definition (Def: Iir) return Iir + is + Index_List : constant Iir_List := Get_Index_Subtype_List (Def); + Index_Type : Iir; + begin + Set_Base_Type (Def, Def); + + for I in Natural loop + Index_Type := Get_Nth_Element (Index_List, I); + exit when Index_Type = Null_Iir; + + Index_Type := Sem_Type_Mark (Index_Type); + Replace_Nth_Element (Index_List, I, Index_Type); + + Index_Type := Get_Type (Index_Type); + if Get_Kind (Index_Type) not in Iir_Kinds_Discrete_Type_Definition + then + Error_Msg_Sem ("an index type of an array must be a discrete type", + Index_Type); + -- FIXME: disp type Index_Type ? + end if; + end loop; + + -- According to LRM93 7.4.1, an unconstrained array type is not static. + Set_Type_Staticness (Def, None); + + Sem_Array_Element (Def); + Set_Constraint_State (Def, Get_Array_Constraint (Def)); + return Def; + end Sem_Unbounded_Array_Type_Definition; + + -- Return the subtype declaration corresponding to the base type of ATYPE + -- (for integer and real types), or the type for enumerated types. To say + -- that differently, it returns the type or subtype which defines the + -- original range. + function Get_First_Subtype_Declaration (Atype : Iir) return Iir is + Base_Type : constant Iir := Get_Base_Type (Atype); + Base_Decl : constant Iir := Get_Type_Declarator (Base_Type); + begin + if Get_Kind (Base_Type) = Iir_Kind_Enumeration_Type_Definition then + pragma Assert (Get_Kind (Base_Decl) = Iir_Kind_Type_Declaration); + return Base_Decl; + else + return Get_Type_Declarator (Get_Subtype_Definition (Base_Decl)); + end if; + end Get_First_Subtype_Declaration; + + function Sem_Constrained_Array_Type_Definition (Def: Iir; Decl: Iir) + return Iir + is + Index_Type : Iir; + Index_Name : Iir; + Index_List : Iir_List; + Base_Index_List : Iir_List; + Staticness : Iir_Staticness; + + -- array_type_definition, which is the same as the subtype, + -- but without any constraint in the indexes. + Base_Type: Iir; + begin + -- LRM08 5.3.2.1 Array types + -- A constrained array definition similarly defines both an array + -- type and a subtype of this type. + -- - The array type is an implicitely declared anonymous type, + -- this type is defined by an (implicit) unbounded array + -- definition in which the element subtype indication either + -- denotes the base type of the subtype denoted by the element + -- subtype indication of the constrained array definition, if + -- that subtype is a composite type, or otherwise is the + -- element subtype indication of the constrained array + -- definition, and in which the type mark of each index subtype + -- definition denotes the subtype defined by the corresponding + -- discrete range. + -- - The array subtype is the subtype obtained by imposition of + -- the index constraint on the array type and if the element + -- subtype indication of the constrained array definition + -- denotes a fully or partially constrained composite subtype, + -- imposition of the constraint of that subtype as an array + -- element constraint on the array type. + + -- FIXME: all indexes must be either constrained or + -- unconstrained. + -- If all indexes are unconstrained, this is really a type + -- otherwise, this is a subtype. + + -- Create a definition for the base type of subtype DEF. + Base_Type := Create_Iir (Iir_Kind_Array_Type_Definition); + Location_Copy (Base_Type, Def); + Set_Base_Type (Base_Type, Base_Type); + Set_Type_Declarator (Base_Type, Decl); + Base_Index_List := Create_Iir_List; + Set_Index_Subtype_List (Base_Type, Base_Index_List); + + Staticness := Locally; + Index_List := Get_Index_Subtype_List (Def); + for I in Natural loop + Index_Type := Get_Nth_Element (Index_List, I); + exit when Index_Type = Null_Iir; + + Index_Name := Sem_Discrete_Range_Integer (Index_Type); + if Index_Name /= Null_Iir then + Index_Name := Range_To_Subtype_Indication (Index_Name); + else + -- Avoid errors. + Index_Name := + Build_Simple_Name (Natural_Subtype_Declaration, Index_Type); + Set_Type (Index_Name, Natural_Subtype_Definition); + end if; + + Replace_Nth_Element (Index_List, I, Index_Name); + + Index_Type := Get_Index_Type (Index_Name); + Staticness := Min (Staticness, Get_Type_Staticness (Index_Type)); + + -- Set the index subtype definition for the array base type. + if Get_Kind (Index_Name) not in Iir_Kinds_Denoting_Name then + pragma Assert + (Get_Kind (Index_Name) in Iir_Kinds_Subtype_Definition); + Index_Type := Get_Subtype_Type_Mark (Index_Name); + if Index_Type = Null_Iir then + -- From a range expression like '1 to 4' or from an attribute + -- name. + declare + Subtype_Decl : constant Iir := + Get_First_Subtype_Declaration (Index_Name); + begin + Index_Type := Build_Simple_Name (Subtype_Decl, Index_Name); + Set_Type (Index_Type, Get_Type (Subtype_Decl)); + end; + end if; + end if; + Append_Element (Base_Index_List, Index_Type); + end loop; + Set_Type_Staticness (Def, Staticness); + + -- Element type. + Sem_Array_Element (Def); + + Set_Element_Subtype_Indication + (Base_Type, Get_Element_Subtype_Indication (Def)); + Set_Signal_Type_Flag (Base_Type, Get_Signal_Type_Flag (Def)); + -- According to LRM93 §7.4.1, an unconstrained array type + -- is not static. + Set_Type_Staticness (Base_Type, None); + Set_Type_Declarator (Base_Type, Decl); + Set_Resolved_Flag (Base_Type, Get_Resolved_Flag (Def)); + Set_Index_Constraint_Flag (Def, True); + Set_Constraint_State (Def, Get_Array_Constraint (Def)); + Set_Constraint_State (Base_Type, Get_Array_Constraint (Base_Type)); + Set_Base_Type (Def, Base_Type); + Set_Subtype_Type_Mark (Def, Null_Iir); + return Def; + end Sem_Constrained_Array_Type_Definition; + + function Sem_Access_Type_Definition (Def: Iir) return Iir + is + D_Type : Iir; + begin + D_Type := Sem_Subtype_Indication + (Get_Designated_Subtype_Indication (Def), True); + Set_Designated_Subtype_Indication (Def, D_Type); + + D_Type := Get_Type_Of_Subtype_Indication (D_Type); + if D_Type /= Null_Iir then + case Get_Kind (D_Type) is + when Iir_Kind_Incomplete_Type_Definition => + Append_Element (Get_Incomplete_Type_List (D_Type), Def); + when Iir_Kind_File_Type_Definition => + -- LRM 3.3 + -- The designated type must not be a file type. + Error_Msg_Sem ("designated type must not be a file type", Def); + when others => + null; + end case; + Set_Designated_Type (Def, D_Type); + end if; + Set_Base_Type (Def, Def); + Set_Type_Staticness (Def, None); + Set_Resolved_Flag (Def, False); + Set_Signal_Type_Flag (Def, False); + return Def; + end Sem_Access_Type_Definition; + + function Sem_File_Type_Definition (Def: Iir; Decl: Iir) return Iir + is + Type_Mark : Iir; + begin + Type_Mark := Sem_Type_Mark (Get_File_Type_Mark (Def)); + Set_File_Type_Mark (Def, Type_Mark); + + Type_Mark := Get_Type (Type_Mark); + + if Get_Kind (Type_Mark) = Iir_Kind_Error then + null; + elsif Get_Signal_Type_Flag (Type_Mark) = False then + -- LRM 3.4 + -- The base type of this subtype must not be a file type + -- or an access type. + -- If the base type is a composite type, it must not + -- contain a subelement of an access type. + Error_Msg_Sem + (Disp_Node (Type_Mark) & " cannot be a file type", Def); + elsif Get_Kind (Type_Mark) in Iir_Kinds_Array_Type_Definition then + -- LRM 3.4 + -- If the base type is an array type, it must be a one + -- dimensional array type. + if not Is_Unidim_Array_Type (Type_Mark) then + Error_Msg_Sem + ("multi-dimensional " & Disp_Node (Type_Mark) + & " cannot be a file type", Def); + end if; + end if; + + Set_Base_Type (Def, Def); + Set_Resolved_Flag (Def, False); + Set_Text_File_Flag (Def, Is_Text_Type_Declaration (Decl)); + Set_Signal_Type_Flag (Def, False); + Set_Type_Staticness (Def, None); + return Def; + end Sem_File_Type_Definition; + + function Sem_Type_Definition (Def: Iir; Decl: Iir) return Iir is + begin + case Get_Kind (Def) is + when Iir_Kind_Enumeration_Type_Definition => + return Sem_Enumeration_Type_Definition (Def, Decl); when Iir_Kind_Range_Expression => if Get_Type (Def) /= Null_Iir then @@ -796,263 +1120,19 @@ package body Sem_Types is end; when Iir_Kind_Array_Subtype_Definition => - -- LRM08 5.3.2.1 Array types - -- A constrained array definition similarly defines both an array - -- type and a subtype of this type. - -- - The array type is an implicitely declared anonymous type, - -- this type is defined by an (implicit) unbounded array - -- definition in which the element subtype indication either - -- denotes the base type of the subtype denoted by the element - -- subtype indication of the constrained array definition, if - -- that subtype is a composite type, or otherwise is the - -- element subtype indication of the constrained array - -- definition, and in which the type mark of each index subtype - -- definition denotes the subtype defined by the corresponding - -- discrete range. - -- - The array subtype is the subtype obtained by imposition of - -- the index constraint on the array type and if the element - -- subtype indication of the constrained array definition - -- denotes a fully or partially constrained composite subtype, - -- imposition of the constraint of that subtype as an array - -- element constraint on the array type. - declare - Index_Type : Iir; - Index_List : Iir_List; - Base_Index_List : Iir_List; - Staticness : Iir_Staticness; - - -- array_type_definition, which is the same as the subtype, - -- but without any constraint in the indexes. - Base_Type: Iir; - begin - -- FIXME: all indexes must be either constrained or - -- unconstrained. - -- If all indexes are unconstrained, this is really a type - -- otherwise, this is a subtype. - - -- Create a definition for the base type of subtype DEF. - Base_Type := Create_Iir (Iir_Kind_Array_Type_Definition); - Location_Copy (Base_Type, Def); - Set_Base_Type (Base_Type, Base_Type); - Set_Type_Declarator (Base_Type, Decl); - Base_Index_List := Create_Iir_List; - Set_Index_Subtype_List (Base_Type, Base_Index_List); - - Staticness := Locally; - Index_List := Get_Index_Subtype_List (Def); - for I in Natural loop - Index_Type := Get_Nth_Element (Index_List, I); - exit when Index_Type = Null_Iir; - - Index_Type := Sem_Discrete_Range_Integer (Index_Type); - if Index_Type /= Null_Iir then - Index_Type := Range_To_Subtype_Definition (Index_Type); - else - -- Avoid errors. - Index_Type := Natural_Subtype_Definition; - end if; - - Replace_Nth_Element (Index_List, I, Index_Type); - Staticness := Min (Staticness, - Get_Type_Staticness (Index_Type)); - - -- Set the index type in the array type. - -- must "unconstraint" the subtype. - Append_Element (Base_Index_List, Index_Type); - end loop; - Set_Type_Staticness (Def, Staticness); - - -- Element type. - Sem_Array_Element (Def); - - Set_Element_Subtype (Base_Type, Get_Element_Subtype (Def)); - Set_Signal_Type_Flag (Base_Type, Get_Signal_Type_Flag (Def)); - -- According to LRM93 §7.4.1, an unconstrained array type - -- is not static. - Set_Type_Staticness (Base_Type, None); - Set_Type_Declarator (Base_Type, Decl); - Set_Resolved_Flag (Base_Type, Get_Resolved_Flag (Def)); - Set_Index_Constraint_Flag (Def, True); - Set_Constraint_State (Def, Get_Array_Constraint (Def)); - Set_Constraint_State - (Base_Type, Get_Array_Constraint (Base_Type)); - Set_Base_Type (Def, Base_Type); - Set_Type_Mark (Def, Base_Type); - return Def; - end; + return Sem_Constrained_Array_Type_Definition (Def, Decl); when Iir_Kind_Array_Type_Definition => - declare - Index_Type : Iir; - Index_List : Iir_List; - begin - Set_Base_Type (Def, Def); - Index_List := Get_Index_Subtype_List (Def); - - for I in Natural loop - Index_Type := Get_Nth_Element (Index_List, I); - exit when Index_Type = Null_Iir; - - Index_Type := Sem_Subtype_Indication (Index_Type); - if Index_Type /= Null_Iir then - if Get_Kind (Index_Type) not in - Iir_Kinds_Discrete_Type_Definition - then - Error_Msg_Sem - ("index type of an array must be discrete", - Index_Type); - end if; - else - -- Avoid errors. - Index_Type := Natural_Subtype_Definition; - end if; - - Replace_Nth_Element (Index_List, I, Index_Type); - end loop; - - -- According to LRM93 §7.4.1, an unconstrained array type - -- is not static. - Set_Type_Staticness (Def, None); - Sem_Array_Element (Def); - Set_Constraint_State (Def, Get_Array_Constraint (Def)); - return Def; - end; + return Sem_Unbounded_Array_Type_Definition (Def); when Iir_Kind_Record_Type_Definition => - declare - -- Semantized type of previous element - Last_Type : Iir; - - El_List : Iir_List; - El: Iir; - El_Type : Iir; - Resolved_Flag : Boolean; - Staticness : Iir_Staticness; - Constraint : Iir_Constraint; - begin - -- LRM 10.1 - -- 5. A record type declaration, - Open_Declarative_Region; - - Resolved_Flag := True; - Last_Type := Null_Iir; - Staticness := Locally; - Constraint := Fully_Constrained; - Set_Signal_Type_Flag (Def, True); - El_List := Get_Elements_Declaration_List (Def); - for I in Natural loop - El := Get_Nth_Element (El_List, I); - exit when El = Null_Iir; - El_Type := Get_Type (El); - if El_Type /= Null_Iir then - -- Be careful for a declaration list (r,g,b: integer). - El_Type := Sem_Subtype_Indication (El_Type); - Last_Type := El_Type; - else - El_Type := Last_Type; - end if; - if El_Type /= Null_Iir then - Set_Type (El, El_Type); - Check_No_File_Type (El_Type, El); - if not Get_Signal_Type_Flag (El_Type) then - Set_Signal_Type_Flag (Def, False); - end if; - - -- LRM93 §3.2.1.1 - -- The same requirement [must define a constrained array - -- subtype] exits for the subtype indication of an - -- element declaration, if the type of the record - -- element is an array type. - if Vhdl_Std < Vhdl_08 - and then not Is_Fully_Constrained_Type (El_Type) - then - Error_Msg_Sem - ("element declaration of unconstrained " - & Disp_Node (El_Type) & " is not allowed", El); - end if; - Resolved_Flag := - Resolved_Flag and Get_Resolved_Flag (El_Type); - Staticness := Min (Staticness, - Get_Type_Staticness (El_Type)); - Constraint := Update_Record_Constraint - (Constraint, El_Type); - else - Staticness := None; - end if; - Sem_Scopes.Add_Name (El); - Name_Visible (El); - Xref_Decl (El); - end loop; - Close_Declarative_Region; - Set_Base_Type (Def, Def); - Set_Resolved_Flag (Def, Resolved_Flag); - Set_Type_Staticness (Def, Staticness); - Set_Constraint_State (Def, Constraint); - return Def; - end; + return Sem_Record_Type_Definition (Def); when Iir_Kind_Access_Type_Definition => - declare - D_Type : Iir; - begin - D_Type := Sem_Subtype_Indication (Get_Designated_Type (Def), - True); - if D_Type /= Null_Iir then - case Get_Kind (D_Type) is - when Iir_Kind_Incomplete_Type_Definition => - Append_Element - (Get_Incomplete_Type_List (D_Type), Def); - when Iir_Kind_File_Type_Definition => - -- LRM 3.3 - -- The designated type must not be a file type. - Error_Msg_Sem - ("designated type must not be a file type", Def); - when others => - null; - end case; - Set_Designated_Type (Def, D_Type); - end if; - Set_Base_Type (Def, Def); - Set_Type_Staticness (Def, None); - Set_Resolved_Flag (Def, False); - Set_Signal_Type_Flag (Def, False); - return Def; - end; + return Sem_Access_Type_Definition (Def); when Iir_Kind_File_Type_Definition => - declare - Type_Mark : Iir; - begin - Type_Mark := Sem_Subtype_Indication (Get_Type_Mark (Def)); - Set_Type_Mark (Def, Type_Mark); - if Type_Mark /= Null_Iir then - if Get_Signal_Type_Flag (Type_Mark) = False then - -- LRM 3.4 - -- The base type of this subtype must not be a file type - -- or an access type. - -- If the base type is a composite type, it must not - -- contain a subelement of an access type. - Error_Msg_Sem - (Disp_Node (Type_Mark) & " cannot be a file type", Def); - elsif Get_Kind (Type_Mark) in Iir_Kinds_Array_Type_Definition - then - -- LRM 3.4 - -- If the base type is an array type, it must be a one - -- dimensional array type. - if not Is_Unidim_Array_Type (Type_Mark) then - Error_Msg_Sem - ("multi-dimensional " & Disp_Node (Type_Mark) - & " cannot be a file type", Def); - end if; - end if; - end if; - Set_Base_Type (Def, Def); - Set_Resolved_Flag (Def, False); - Set_Text_File_Flag (Def, Is_Text_Type_Declaration (Decl)); - Set_Signal_Type_Flag (Def, False); - Set_Type_Staticness (Def, None); - return Def; - end; + return Sem_File_Type_Definition (Def, Decl); when Iir_Kind_Protected_Type_Declaration => Sem_Protected_Type_Declaration (Decl); @@ -1064,10 +1144,7 @@ package body Sem_Types is end case; end Sem_Type_Definition; - -- Convert a range expression to a subtype definition whose constraint is - -- A_RANGE. - -- This function extract the type of the range expression. - function Range_To_Subtype_Definition (A_Range: Iir) return Iir + function Range_To_Subtype_Indication (A_Range: Iir) return Iir is Sub_Type: Iir; Range_Type : Iir; @@ -1078,11 +1155,14 @@ package body Sem_Types is | Iir_Kind_Reverse_Range_Array_Attribute => -- Create a sub type. Range_Type := Get_Type (A_Range); + when Iir_Kind_Simple_Name + | Iir_Kind_Selected_Name => + return A_Range; when Iir_Kinds_Discrete_Type_Definition => -- A_RANGE is already a subtype definition. return A_Range; when others => - Error_Kind ("range_to_subtype_definition", A_Range); + Error_Kind ("range_to_subtype_indication", A_Range); return Null_Iir; end case; @@ -1105,7 +1185,7 @@ package body Sem_Types is Set_Type_Staticness (Sub_Type, Get_Expr_Staticness (A_Range)); Set_Signal_Type_Flag (Sub_Type, True); return Sub_Type; - end Range_To_Subtype_Definition; + end Range_To_Subtype_Indication; -- Return TRUE iff FUNC is a resolution function for ATYPE. function Is_A_Resolution_Function (Func: Iir; Atype: Iir) return Boolean @@ -1172,8 +1252,10 @@ package body Sem_Types is El : Iir; List : Iir_List; Has_Error : Boolean; + Name1 : Iir; begin - Sem_Name (Name, False); + Sem_Name (Name); + Func := Get_Named_Entity (Name); if Func = Error_Mark then return; @@ -1203,9 +1285,11 @@ package body Sem_Types is end if; end if; end loop; + Free_Overload_List (Func); if Has_Error then return; end if; + Set_Named_Entity (Name, Res); else if Is_A_Resolution_Function (Func, Atype) then Res := Func; @@ -1216,28 +1300,30 @@ package body Sem_Types is Error_Msg_Sem ("no matching resolution function for " & Disp_Node (Name), Atype); else - Set_Named_Entity (Name, Res); + Name1 := Finish_Sem_Name (Name); Set_Use_Flag (Res, True); Set_Resolved_Flag (Atype, True); - Set_Resolution_Function (Atype, Name); - Xref_Name (Name); + Set_Resolution_Function (Atype, Name1); end if; end Sem_Resolution_Function; + -- Analyze the constraint DEF + RESOLUTION for type TYPE_MARK. The + -- result is always a subtype definition. function Sem_Subtype_Constraint (Def : Iir; Type_Mark : Iir; Resolution : Iir) return Iir; - -- DEF is an incomplete subtype_indication or array_constraint, - -- BASE_TYPE is the base type of the subtype_indication. - function Sem_Array_Constraint (Def : Iir; Type_Mark : Iir; Resolution : Iir) - return Iir + -- DEF is an incomplete subtype_indication or array_constraint, + -- TYPE_MARK is the base type of the subtype_indication. + function Sem_Array_Constraint + (Def : Iir; Type_Mark : Iir; Resolution : Iir) + return Iir is Res : Iir; Type_Index, Subtype_Index: Iir; Base_Type : Iir; - Mark_El_Type : Iir; El_Type : Iir; + El_Def : Iir; Staticness : Iir_Staticness; Error_Seen : Boolean; Type_Index_List : Iir_List; @@ -1247,7 +1333,7 @@ package body Sem_Types is begin if Resolution /= Null_Iir then case Get_Kind (Resolution) is - when Iir_Kinds_Name => + when Iir_Kinds_Denoting_Name => Resolv_Func := Resolution; when Iir_Kind_Array_Subtype_Definition => Resolv_El := Get_Element_Subtype (Resolution); @@ -1261,9 +1347,11 @@ package body Sem_Types is end case; end if; - Mark_El_Type := Get_Element_Subtype (Type_Mark); + El_Type := Get_Element_Subtype (Type_Mark); if Def = Null_Iir then + -- There is no element_constraint. + pragma Assert (Resolution /= Null_Iir); Res := Copy_Subtype_Indication (Type_Mark); else case Get_Kind (Def) is @@ -1273,14 +1361,15 @@ package body Sem_Types is if Get_Range_Constraint (Def) /= Null_Iir then Error_Msg_Sem ("cannot use a range constraint for array types", Def); - return Type_Mark; + return Copy_Subtype_Indication (Type_Mark); end if; - -- LRM08 6.3 Subtype declarations + -- LRM08 6.3 Subtype declarations -- - -- If the subtype indication does not include a constraint, the - -- subtype is the same as that denoted by the type mark. + -- If the subtype indication does not include a constraint, the + -- subtype is the same as that denoted by the type mark. if Resolution = Null_Iir then + -- FIXME: is it reachable ? Free_Name (Def); return Type_Mark; end if; @@ -1288,7 +1377,9 @@ package body Sem_Types is Res := Copy_Subtype_Indication (Type_Mark); Location_Copy (Res, Def); Free_Name (Def); - El_Type := Null_Iir; + + -- No element constraint. + El_Def := Null_Iir; when Iir_Kind_Array_Subtype_Definition => -- Case of a constraint for an array. @@ -1296,12 +1387,12 @@ package body Sem_Types is Base_Type := Get_Base_Type (Type_Mark); Set_Base_Type (Def, Base_Type); + El_Def := Get_Element_Subtype_Indication (Def); - Staticness := Get_Type_Staticness (Mark_El_Type); + Staticness := Get_Type_Staticness (El_Type); Error_Seen := False; Type_Index_List := Get_Index_Subtype_List (Base_Type); Subtype_Index_List := Get_Index_Subtype_List (Def); - El_Type := Get_Element_Subtype (Def); -- LRM08 5.3.2.2 -- If an array constraint of the first form (including an index @@ -1346,25 +1437,28 @@ package body Sem_Types is & Disp_Location (Type_Mark), Def); Error_Seen := True; end if; - -- Use type_index as a fake subtype - -- FIXME: it is too fake. - Append_Element (Subtype_Index_List, Type_Index); - Staticness := None; else Subtype_Index := Sem_Discrete_Range_Expression - (Subtype_Index, Type_Index, True); + (Subtype_Index, Get_Index_Type (Type_Index), True); if Subtype_Index /= Null_Iir then Subtype_Index := - Range_To_Subtype_Definition (Subtype_Index); + Range_To_Subtype_Indication (Subtype_Index); Staticness := Min - (Staticness, Get_Type_Staticness (Subtype_Index)); - end if; - if Subtype_Index = Null_Iir then - -- Create a fake subtype from type_index. - -- FIXME: It is too fake. - Subtype_Index := Type_Index; - Staticness := None; + (Staticness, + Get_Type_Staticness + (Get_Type_Of_Subtype_Indication + (Subtype_Index))); end if; + end if; + if Subtype_Index = Null_Iir then + -- Create a fake subtype from type_index. + -- FIXME: It is too fake. + Subtype_Index := Type_Index; + Staticness := None; + end if; + if Error_Seen then + Append_Element (Subtype_Index_List, Subtype_Index); + else Replace_Nth_Element (Subtype_Index_List, I, Subtype_Index); end if; @@ -1372,7 +1466,6 @@ package body Sem_Types is Set_Index_Constraint_Flag (Def, True); end if; Set_Type_Staticness (Def, Staticness); - Set_Type_Mark (Def, Type_Mark); Set_Signal_Type_Flag (Def, Get_Signal_Type_Flag (Type_Mark)); Res := Def; @@ -1395,15 +1488,13 @@ package body Sem_Types is end if; -- Element subtype. - if Resolv_El /= Null_Iir then - El_Type := Sem_Subtype_Constraint (Null_Iir, Mark_El_Type, Resolv_El); - elsif El_Type /= Null_Iir then - El_Type := Sem_Subtype_Constraint (El_Type, Mark_El_Type, Null_Iir); + if Resolv_El /= Null_Iir or else El_Def /= Null_Iir then + El_Def := Sem_Subtype_Constraint (El_Def, El_Type, Resolv_El); end if; - if El_Type = Null_Iir then - El_Type := Mark_El_Type; + if El_Def = Null_Iir then + El_Def := Get_Element_Subtype_Indication (Type_Mark); end if; - Set_Element_Subtype (Res, El_Type); + Set_Element_Subtype_Indication (Res, El_Def); Set_Constraint_State (Res, Get_Array_Constraint (Res)); @@ -1536,7 +1627,7 @@ package body Sem_Types is if Parent /= Null_Iir then case Get_Kind (Def_El_Type) is when Iir_Kinds_Array_Type_Definition => - Set_Element_Subtype + Set_Element_Subtype_Indication (Res, Reparse_As_Array_Constraint (Def, Def_El_Type)); when others => Error_Kind ("reparse_as_array_constraint", Def_El_Type); @@ -1564,7 +1655,6 @@ package body Sem_Types is Location_Copy (Res, Def); Set_Base_Type (Res, Get_Base_Type (Type_Mark)); Set_Type_Staticness (Res, Get_Type_Staticness (Type_Mark)); - Set_Type_Mark (Res, Type_Mark); if Get_Kind (Type_Mark) = Iir_Kind_Record_Subtype_Definition then Set_Resolution_Function (Res, Get_Resolution_Function (Type_Mark)); end if; @@ -1604,7 +1694,7 @@ package body Sem_Types is Res_List := Null_Iir_List; if Resolution /= Null_Iir then case Get_Kind (Resolution) is - when Iir_Kinds_Name => + when Iir_Kinds_Denoting_Name => null; when Iir_Kind_Record_Subtype_Definition => Res_List := Get_Elements_Declaration_List (Resolution); @@ -1733,7 +1823,7 @@ package body Sem_Types is Set_Signal_Type_Flag (Res, Get_Signal_Type_Flag (Type_Mark)); if Resolution /= Null_Iir - and then Get_Kind (Resolution) in Iir_Kinds_Name + and then Get_Kind (Resolution) in Iir_Kinds_Denoting_Name then Sem_Resolution_Function (Resolution, Res); end if; @@ -1741,8 +1831,10 @@ package body Sem_Types is return Res; end Sem_Record_Constraint; - function Sem_Range_Constraint (Def : Iir; Type_Mark : Iir; Resolution : Iir) - return Iir + -- Return a scalar subtype definition (even in case of error). + function Sem_Range_Constraint + (Def : Iir; Type_Mark : Iir; Resolution : Iir) + return Iir is Res : Iir; A_Range : Iir; @@ -1750,19 +1842,15 @@ package body Sem_Types is begin if Def = Null_Iir then Res := Copy_Subtype_Indication (Type_Mark); + elsif Get_Kind (Def) /= Iir_Kind_Subtype_Definition then + -- FIXME: find the correct sentence from LRM + -- GHDL: subtype_definition may also be used just to add + -- a resolution function. + Error_Msg_Sem ("only scalar types may be constrained by range", Def); + Error_Msg_Sem (" (type mark is " & Disp_Node (Type_Mark) & ")", + Type_Mark); + Res := Copy_Subtype_Indication (Type_Mark); else - if Get_Kind (Def) /= Iir_Kind_Subtype_Definition then - -- FIXME: find the correct sentence from LRM - -- GHDL: subtype_definition may also be used just to add - -- a resolution function. - Error_Msg_Sem - ("only scalar types may be constrained by range", Def); - Error_Msg_Sem - (" (type mark is " & Disp_Node (Type_Mark) & ")", - Type_Mark); - return Type_Mark; - end if; - Tolerance := Get_Tolerance (Def); if Get_Range_Constraint (Def) = Null_Iir @@ -1782,7 +1870,6 @@ package body Sem_Types is end if; Location_Copy (Res, Def); Set_Base_Type (Res, Get_Base_Type (Type_Mark)); - Set_Type_Mark (Res, Type_Mark); Set_Resolution_Function (Res, Get_Resolution_Function (Def)); A_Range := Get_Range_Constraint (Def); if A_Range = Null_Iir then @@ -1825,7 +1912,7 @@ package body Sem_Types is if Resolution /= Null_Iir then -- LRM08 6.3 Subtype declarations. - if Get_Kind (Resolution) not in Iir_Kinds_Name then + if Get_Kind (Resolution) not in Iir_Kinds_Denoting_Name then Error_Msg_Sem ("resolution indication must be a function name", Resolution); else @@ -1837,8 +1924,7 @@ package body Sem_Types is function Sem_Subtype_Constraint (Def : Iir; Type_Mark : Iir; Resolution : Iir) - return Iir - is + return Iir is begin case Get_Kind (Type_Mark) is when Iir_Kind_Array_Subtype_Definition @@ -1866,15 +1952,14 @@ package body Sem_Types is case Get_Kind (Def) is when Iir_Kind_Subtype_Definition => Free_Name (Def); - return Type_Mark; + return Copy_Subtype_Indication (Type_Mark); when Iir_Kind_Array_Subtype_Definition => - -- LRM93 §3.3 + -- LRM93 3.3 -- The only form of constraint that is allowed after a name -- of an access type in a subtype indication is an index -- constraint. declare Sub_Type : Iir; - pragma Unreferenced (Sub_Type); Base_Type : Iir; Res : Iir; begin @@ -1884,9 +1969,8 @@ package body Sem_Types is Res := Create_Iir (Iir_Kind_Access_Subtype_Definition); Location_Copy (Res, Def); Set_Base_Type (Res, Type_Mark); - Set_Type_Mark (Res, Base_Type); + Set_Designated_Subtype_Indication (Res, Sub_Type); Set_Signal_Type_Flag (Res, False); - Free_Old_Iir (Def); return Res; end; when others => @@ -1938,51 +2022,45 @@ package body Sem_Types is return Type_Mark; when others => - Error_Kind ("sem_subtype_indication", Type_Mark); + Error_Kind ("sem_subtype_constraint", Type_Mark); return Type_Mark; end case; end Sem_Subtype_Constraint; - -- Semantize a subtype indication. - -- DEF can be either a name or an iir_subtype_definition. - -- Return a new (an anonymous) subtype definition (with the correct kind), - -- or an already defined type definition (if DEF is a name). function Sem_Subtype_Indication (Def: Iir; Incomplete : Boolean := False) - return Iir + return Iir is + Type_Mark_Name : Iir; Type_Mark: Iir; - Decl_Kind : Decl_Kind_Type; + Res : Iir; begin - if Incomplete then - Decl_Kind := Decl_Incomplete_Type; - else - Decl_Kind := Decl_Type; - end if; - - -- LRM08 6.3 Subtype declarations + -- LRM08 6.3 Subtype declarations -- - -- If the subtype indication does not include a constraint, the subtype - -- is the same as that denoted by the type mark. - if Get_Kind (Def) in Iir_Kinds_Name then - Type_Mark := Find_Declaration (Def, Decl_Kind); - if Type_Mark = Null_Iir then - return Create_Error_Type (Def); - else - return Type_Mark; - end if; + -- If the subtype indication does not include a constraint, the subtype + -- is the same as that denoted by the type mark. + if Get_Kind (Def) in Iir_Kinds_Denoting_Name then + Type_Mark := Sem_Type_Mark (Def, Incomplete); + return Type_Mark; end if; -- Semantize the type mark. - Type_Mark := Find_Declaration (Get_Type_Mark (Def), Decl_Kind); - if Type_Mark = Null_Iir then + Type_Mark_Name := Get_Subtype_Type_Mark (Def); + Type_Mark_Name := Sem_Type_Mark (Type_Mark_Name); + Set_Subtype_Type_Mark (Def, Type_Mark_Name); + Type_Mark := Get_Type (Type_Mark_Name); + -- FIXME: incomplete type ? + if Get_Kind (Type_Mark) = Iir_Kind_Error then -- FIXME: handle inversion such as "subtype BASETYPE RESOLV", which -- should emit "resolution function must precede type name". - return Create_Error_Type (Get_Type_Mark (Def)); + + -- Discard the subtype definition and only keep the type mark. + return Type_Mark_Name; end if; - Set_Type_Mark (Def, Type_Mark); - return Sem_Subtype_Constraint + Res := Sem_Subtype_Constraint (Def, Type_Mark, Get_Resolution_Function (Def)); + Set_Subtype_Type_Mark (Res, Type_Mark_Name); + return Res; end Sem_Subtype_Indication; function Copy_Subtype_Indication (Def : Iir) return Iir @@ -1999,32 +2077,29 @@ package body Sem_Types is Set_Resolution_Function (Res, Get_Resolution_Function (Def)); when Iir_Kind_Enumeration_Type_Definition => Res := Create_Iir (Iir_Kind_Enumeration_Subtype_Definition); - Set_Type_Mark (Res, Def); Set_Range_Constraint (Res, Get_Range_Constraint (Def)); - when Iir_Kind_Access_Subtype_Definition => - Res := Create_Iir (Iir_Kind_Access_Subtype_Definition); - Set_Type_Mark (Res, Get_Type_Mark (Def)); - when Iir_Kind_Access_Type_Definition => + when Iir_Kind_Access_Subtype_Definition + | Iir_Kind_Access_Type_Definition => Res := Create_Iir (Iir_Kind_Access_Subtype_Definition); - Set_Type_Mark (Res, Get_Designated_Type (Def)); + Set_Designated_Type (Res, Get_Designated_Type (Def)); when Iir_Kind_Array_Type_Definition => Res := Create_Iir (Iir_Kind_Array_Subtype_Definition); Set_Type_Staticness (Res, Get_Type_Staticness (Def)); Set_Resolved_Flag (Res, Get_Resolved_Flag (Def)); - Set_Type_Mark (Res, Def); Set_Index_Subtype_List (Res, Get_Index_Subtype_List (Def)); - Set_Element_Subtype (Res, Get_Element_Subtype (Def)); + Set_Element_Subtype_Indication + (Res, Get_Element_Subtype_Indication (Def)); Set_Index_Constraint_Flag (Res, False); Set_Constraint_State (Res, Get_Constraint_State (Def)); when Iir_Kind_Array_Subtype_Definition => Res := Create_Iir (Iir_Kind_Array_Subtype_Definition); Set_Resolution_Function (Res, Get_Resolution_Function (Def)); Set_Resolved_Flag (Res, Get_Resolved_Flag (Def)); - Set_Type_Mark (Res, Def); Set_Index_Subtype_List (Res, Get_Index_Subtype_List (Def)); - Set_Element_Subtype (Res, Get_Element_Subtype (Def)); + Set_Element_Subtype_Indication + (Res, Get_Element_Subtype_Indication (Def)); Set_Index_Constraint_Flag (Res, Get_Index_Constraint_Flag (Def)); Set_Constraint_State (Res, Get_Constraint_State (Def)); @@ -2042,7 +2117,7 @@ package body Sem_Types is Set_Elements_Declaration_List (Res, Get_Elements_Declaration_List (Def)); when others => - -- FIXME: todo + -- FIXME: todo (protected type ?) Error_Kind ("copy_subtype_indication", Def); end case; Location_Copy (Res, Def); @@ -2055,6 +2130,7 @@ package body Sem_Types is function Sem_Subnature_Indication (Def: Iir) return Iir is Nature_Mark: Iir; + Res : Iir; begin -- LRM 4.8 Nature declatation -- @@ -2064,10 +2140,11 @@ package body Sem_Types is when Iir_Kind_Scalar_Nature_Definition => -- Used for reference declared by a nature return Def; - when Iir_Kinds_Name => - Nature_Mark := Find_Declaration (Def, Decl_Nature); - if Nature_Mark = Null_Iir then - -- return Create_Error_Type (Def); + when Iir_Kinds_Denoting_Name => + Nature_Mark := Sem_Denoting_Name (Def); + Res := Get_Named_Entity (Nature_Mark); + if Get_Kind (Res) /= Iir_Kind_Scalar_Nature_Definition then + Error_Class_Match (Nature_Mark, "nature"); raise Program_Error; -- TODO else return Nature_Mark; diff --git a/sem_types.ads b/sem_types.ads index 16548b007..8eb7de108 100644 --- a/sem_types.ads +++ b/sem_types.ads @@ -18,26 +18,24 @@ with Iirs; use Iirs; package Sem_Types is - -- Semantization of types (LRM chapter 3) + -- Semantization of types (LRM93 3 / LRM08 5) - -- Semantize subtype indication DEF. - -- If INCOMPLETE is TRUE, then DEF may designate an incomplete type - -- definition. - -- This is used by sem_expr for qualified expression and allocators. + -- Semantize subtype indication DEF. + -- If INCOMPLETE is TRUE, then DEF may designate an incomplete type + -- definition. Return either a name (denoting a type) or an anonymous + -- subtype definition. function Sem_Subtype_Indication (Def: Iir; Incomplete : Boolean := False) return Iir; - -- Return FALSE if A_TYPE is an unconstrained array type or subtype. - --function Sem_Is_Constrained (A_Type: Iir) return Boolean; - procedure Sem_Protected_Type_Body (Bod : Iir); function Sem_Type_Definition (Def: Iir; Decl: Iir) return Iir; - -- Convert a range expression to a subtype definition whose constraint is - -- A_RANGE. - -- This function extract the type of the range expression. - function Range_To_Subtype_Definition (A_Range: Iir) return Iir; + -- If A_RANGE is a range (range expression or range attribute), convert it + -- to a subtype definition. Otherwise return A_RANGE. + -- The result is a subtype indication: either a type name or a subtype + -- definition. + function Range_To_Subtype_Indication (A_Range: Iir) return Iir; -- ATYPE is used to declare a signal. -- Set (recursively) the Has_Signal_Flag on ATYPE and all types used by @@ -54,6 +52,6 @@ package Sem_Types is -- This is used when an alias of DEF is required (eg: subtype a is b). function Copy_Subtype_Indication (Def : Iir) return Iir; + -- Although a nature is not a type, it is patterned like a type. function Sem_Subnature_Indication (Def: Iir) return Iir; - -- Also a nature is not a type, it is patterned like a type. end Sem_Types; diff --git a/simulate/annotations.adb b/simulate/annotations.adb index b447ba374..4508d8373 100644 --- a/simulate/annotations.adb +++ b/simulate/annotations.adb @@ -380,7 +380,7 @@ package body Annotations is when Iir_Kind_File_Type_Definition => declare - Type_Name : constant Iir := Get_Type_Mark (Def); + Type_Name : constant Iir := Get_Type (Get_File_Type_Mark (Def)); Res : String_Acc; begin if Get_Text_File_Flag (Def) @@ -617,8 +617,10 @@ package body Annotations is when Iir_Kind_Function_Declaration | Iir_Kind_Procedure_Declaration => - Annotate_Subprogram_Interfaces_Type (Block_Info, Decl); - Annotate_Subprogram_Specification (Block_Info, Decl); + if not Is_Second_Subprogram_Specification (Decl) then + Annotate_Subprogram_Interfaces_Type (Block_Info, Decl); + Annotate_Subprogram_Specification (Block_Info, Decl); + end if; when Iir_Kind_Function_Body | Iir_Kind_Procedure_Body => Annotate_Subprogram_Body (Block_Info, Decl); diff --git a/simulate/elaboration.adb b/simulate/elaboration.adb index d968389f7..4808b4589 100644 --- a/simulate/elaboration.adb +++ b/simulate/elaboration.adb @@ -945,7 +945,7 @@ package body Elaboration is -- elaboration of the formal part and the evaluation of the actual -- part. -- FIXME: elaboration of the formal part. - Inter := Get_Formal (Assoc); + Inter := Get_Association_Interface (Assoc); case Get_Kind (Assoc) is when Iir_Kind_Association_Element_Open => -- The generic association list contains an implicit @@ -1110,7 +1110,7 @@ package body Elaboration is -- Elaboration of a port association list consists of the elaboration -- of each port association element in the association list whose -- actual is not the reserved word OPEN. - Inter := Get_Formal (Assoc); + Inter := Get_Association_Interface (Assoc); case Get_Kind (Assoc) is when Iir_Kind_Association_Element_By_Expression => if Get_In_Conversion (Assoc) = Null_Iir diff --git a/simulate/execution.adb b/simulate/execution.adb index a8a73b13a..d82f32f80 100644 --- a/simulate/execution.adb +++ b/simulate/execution.adb @@ -468,8 +468,13 @@ package body Execution is Result := Unshare (Left, Expr_Pool'Access); end Eval_Array; + Imp : Iir; begin - Func := Get_Implicit_Definition (Get_Implementation (Expr)); + Imp := Get_Implementation (Expr); + if Get_Kind (Imp) in Iir_Kinds_Denoting_Name then + Imp := Get_Named_Entity (Imp); + end if; + Func := Get_Implicit_Definition (Imp); -- Eval left operand. case Func is @@ -1350,7 +1355,7 @@ package body Execution is (Block: Block_Instance_Acc; Stmt: Iir_Procedure_Call) is Imp : constant Iir_Implicit_Procedure_Declaration := - Get_Implementation (Stmt); + Get_Named_Entity (Get_Implementation (Stmt)); Assoc_Chain : constant Iir := Get_Parameter_Association_Chain (Stmt); Assoc: Iir; Args: Iir_Value_Literal_Array (0 .. 3); @@ -1663,7 +1668,7 @@ package body Execution is -- When created from static evaluation, a string may still have an -- unconstrained type. - if Get_Kind (Array_Type) = Iir_Kind_Array_Type_Definition then + if Get_Constraint_State (Array_Type) /= Fully_Constrained then Res.Bounds.D (1) := Create_Range_Value (Create_I64_Value (1), Create_I64_Value (Ghdl_I64 (Res.Val_Array.Len)), @@ -2105,6 +2110,8 @@ package body Execution is Natural (Dim - 1)); return Execute_Bounds (Block, Index); end; + when Iir_Kinds_Denoting_Name => + return Execute_Indexes (Block, Get_Named_Entity (Prefix), Dim); when Iir_Kind_Array_Type_Definition | Iir_Kind_Array_Subtype_Definition => Error_Kind ("execute_indexes", Prefix); @@ -2126,9 +2133,8 @@ package body Execution is case Get_Kind (Prefix) is when Iir_Kind_Range_Expression => declare - Info : Sim_Info_Acc; + Info : constant Sim_Info_Acc := Get_Info (Prefix); begin - Info := Get_Info (Prefix); if Info = null then Bound := Create_Range_Value (Execute_Expression (Block, Get_Left_Limit (Prefix)), @@ -2184,6 +2190,9 @@ package body Execution is (Block, Get_Range_Constraint (Get_Type (Get_Type_Declarator (Prefix)))); + when Iir_Kinds_Denoting_Name => + return Execute_Bounds (Block, Get_Named_Entity (Prefix)); + when others => -- Error_Kind ("execute_bounds", Get_Kind (Prefix)); declare @@ -2362,7 +2371,7 @@ package body Execution is function Execute_Signal_Init_Value (Block : Block_Instance_Acc; Expr : Iir) return Iir_Value_Literal_Acc is - Base : constant Iir := Get_Base_Name (Expr); + Base : constant Iir := Get_Object_Prefix (Expr); Info : constant Sim_Info_Acc := Get_Info (Base); Bblk : Block_Instance_Acc; Base_Val : Iir_Value_Literal_Acc; @@ -2543,8 +2552,8 @@ package body Execution is end if; end; - when Iir_Kind_Simple_Name - | Iir_Kind_Selected_Name => + when Iir_Kinds_Denoting_Name + | Iir_Kind_Attribute_Name => Execute_Name_With_Base (Block, Get_Named_Entity (Expr), Base, Res, Is_Sig); @@ -2584,7 +2593,7 @@ package body Execution is return Iir_Value_Literal_Acc is Val : Iir_Value_Literal_Acc; - Attr_Type : constant Iir := Get_Type_Of_Type_Mark (Get_Prefix (Expr)); + Attr_Type : constant Iir := Get_Type (Get_Prefix (Expr)); begin Val := Execute_Expression (Block, Get_Parameter (Expr)); return String_To_Iir_Value @@ -2853,9 +2862,8 @@ package body Execution is | Iir_Kind_Implicit_Dereference => return Execute_Name (Block, Expr); - when Iir_Kind_Simple_Name - | Iir_Kind_Character_Literal - | Iir_Kind_Selected_Name => + when Iir_Kinds_Denoting_Name + | Iir_Kind_Attribute_Name => return Execute_Expression (Block, Get_Named_Entity (Expr)); when Iir_Kind_Aggregate => @@ -2887,11 +2895,11 @@ package body Execution is when Iir_Kind_Function_Call => declare - Imp : Iir; + Imp : constant Iir := + Get_Named_Entity (Get_Implementation (Expr)); Assoc : Iir; Args : Iir_Array (0 .. 1); begin - Imp := Get_Implementation (Expr); if Get_Kind (Imp) = Iir_Kind_Function_Declaration then return Execute_Function_Call (Block, Expr, Imp); else @@ -2956,6 +2964,10 @@ package body Execution is when Iir_Kind_Null_Literal => return Null_Lit; + when Iir_Kind_Overflow_Literal => + Error_Msg_Constraint (Expr); + return null; + when Iir_Kind_Type_Conversion => return Execute_Type_Conversion (Block, Expr, @@ -2963,7 +2975,7 @@ package body Execution is when Iir_Kind_Qualified_Expression => Res := Execute_Expression_With_Type - (Block, Get_Expression (Expr), Get_Type_Mark (Expr)); + (Block, Get_Expression (Expr), Get_Type (Get_Type_Mark (Expr))); return Res; when Iir_Kind_Allocator_By_Expression => @@ -2972,7 +2984,10 @@ package body Execution is return Create_Access_Value (Res); when Iir_Kind_Allocator_By_Subtype => - Res := Create_Value_For_Type (Block, Get_Expression (Expr), True); + Res := Create_Value_For_Type + (Block, + Get_Type_Of_Subtype_Indication (Get_Subtype_Indication (Expr)), + True); Res := Unshare_Heap (Res); return Create_Access_Value (Res); @@ -3052,8 +3067,7 @@ package body Execution is when Iir_Kind_Val_Attribute => declare - Prefix_Type: constant Iir := - Get_Type_Of_Type_Mark (Get_Prefix (Expr)); + Prefix_Type: constant Iir := Get_Type (Get_Prefix (Expr)); Base_Type : constant Iir := Get_Base_Type (Prefix_Type); Mode : constant Iir_Value_Kind := Get_Info (Base_Type).Scalar_Mode; @@ -3077,8 +3091,7 @@ package body Execution is when Iir_Kind_Pos_Attribute => declare N_Res: Iir_Value_Literal_Acc; - Prefix_Type: constant Iir := - Get_Type_Of_Type_Mark (Get_Prefix (Expr)); + Prefix_Type: constant Iir := Get_Type (Get_Prefix (Expr)); Base_Type : constant Iir := Get_Base_Type (Prefix_Type); Mode : constant Iir_Value_Kind := Get_Info (Base_Type).Scalar_Mode; @@ -3119,7 +3132,7 @@ package body Execution is begin Res := Execute_Expression (Block, Get_Parameter (Expr)); Bound := Execute_Bounds - (Block, Get_Type_Of_Type_Mark (Get_Prefix (Expr))); + (Block, Get_Type (Get_Prefix (Expr))); case Bound.Dir is when Iir_To => Res := Execute_Dec (Res, Expr); @@ -3136,7 +3149,7 @@ package body Execution is begin Res := Execute_Expression (Block, Get_Parameter (Expr)); Bound := Execute_Bounds - (Block, Get_Type_Of_Type_Mark (Get_Prefix (Expr))); + (Block, Get_Type (Get_Prefix (Expr))); case Bound.Dir is when Iir_Downto => Res := Execute_Dec (Res, Expr); @@ -3315,15 +3328,28 @@ package body Execution is (Block : Block_Instance_Acc; Conv : Iir; Val : Iir_Value_Literal_Acc) return Iir_Value_Literal_Acc is + Ent : Iir; begin - if Get_Kind (Conv) = Iir_Kind_Function_Call then - return Execute_Assoc_Function_Conversion - (Block, Get_Implementation (Conv), Val); - elsif Get_Kind (Conv) = Iir_Kind_Function_Declaration then - return Execute_Assoc_Function_Conversion (Block, Conv, Val); - else - return Execute_Type_Conversion (Block, Conv, Val); - end if; + case Get_Kind (Conv) is + when Iir_Kind_Function_Call => + -- FIXME: shouldn't CONV always be a denoting_name ? + return Execute_Assoc_Function_Conversion + (Block, Get_Named_Entity (Get_Implementation (Conv)), Val); + when Iir_Kind_Type_Conversion => + -- FIXME: shouldn't CONV always be a denoting_name ? + return Execute_Type_Conversion (Block, Conv, Val); + when Iir_Kinds_Denoting_Name => + Ent := Get_Named_Entity (Conv); + if Get_Kind (Ent) = Iir_Kind_Function_Declaration then + return Execute_Assoc_Function_Conversion (Block, Ent, Val); + elsif Get_Kind (Ent) in Iir_Kinds_Type_Declaration then + return Execute_Type_Conversion (Block, Ent, Val); + else + Error_Kind ("execute_assoc_conversion(1)", Ent); + end if; + when others => + Error_Kind ("execute_assoc_conversion(2)", Conv); + end case; end Execute_Assoc_Conversion; -- Establish correspondance for association list ASSOC_LIST from block @@ -3352,7 +3378,7 @@ package body Execution is Assoc_Idx := 1; while Assoc /= Null_Iir loop Formal := Get_Formal (Assoc); - Inter := Get_Base_Name (Formal); + Inter := Get_Association_Interface (Assoc); -- Extract the actual value. case Get_Kind (Assoc) is @@ -3508,7 +3534,7 @@ package body Execution is while Assoc /= Null_Iir loop if Get_Kind (Assoc) /= Iir_Kind_Association_Element_By_Individual then Formal := Get_Formal (Assoc); - Inter := Get_Base_Name (Formal); + Inter := Get_Association_Interface (Assoc); case Get_Kind (Inter) is when Iir_Kind_Variable_Interface_Declaration => if Get_Mode (Inter) /= Iir_In_Mode @@ -4511,7 +4537,7 @@ package body Execution is Instance : constant Block_Instance_Acc := Proc.Instance; Stmt : constant Iir := Instance.Stmt; Call : constant Iir := Get_Procedure_Call (Stmt); - Imp : constant Iir := Get_Implementation (Call); + Imp : constant Iir := Get_Named_Entity (Get_Implementation (Call)); Subprg_Instance : Block_Instance_Acc; Assoc_Chain: Iir; Subprg_Body : Iir; diff --git a/simulate/iir_values.adb b/simulate/iir_values.adb index 67784df58..93c0ade7c 100644 --- a/simulate/iir_values.adb +++ b/simulate/iir_values.adb @@ -21,6 +21,7 @@ with Ada.Unchecked_Conversion; with GNAT.Debug_Utilities; with Name_Table; with Debugger; use Debugger; +with Iirs_Utils; use Iirs_Utils; package body Iir_Values is diff --git a/simulate/simulation.adb b/simulate/simulation.adb index 6a725ee9d..350192ab3 100644 --- a/simulate/simulation.adb +++ b/simulate/simulation.adb @@ -19,6 +19,7 @@ with Ada.Unchecked_Conversion; with Ada.Text_IO; use Ada.Text_IO; with Errorout; use Errorout; +with Iirs_Utils; use Iirs_Utils; with Trans_Analyzes; with Types; use Types; with Debugger; use Debugger; @@ -1592,7 +1593,7 @@ package body Simulation is Instance_Pool := Global_Pool'Access; Elaboration.Elaborate_Design (Top_Config); - Entity := Get_Entity (Get_Library_Unit (Top_Config)); + Entity := Iirs_Utils.Get_Entity (Get_Library_Unit (Top_Config)); if not Is_Empty (Expr_Pool) then raise Internal_Error; diff --git a/std_package.adb b/std_package.adb index 7932ad3fe..153c84b5e 100644 --- a/std_package.adb +++ b/std_package.adb @@ -54,6 +54,15 @@ package body Std_Package is return Res; end Create_Std_Decl; + function Create_Std_Type_Mark (Ref : Iir) return Iir + is + Res : Iir; + begin + Res := Iirs_Utils.Build_Simple_Name (Ref, Std_Location); + Set_Type (Res, Get_Type (Ref)); + return Res; + end Create_Std_Type_Mark; + procedure Create_First_Nodes is begin @@ -153,7 +162,6 @@ package body Std_Package is Set_Type (Res, Sub_Type); Set_Expr_Staticness (Res, Locally); Set_Name_Staticness (Res, Locally); - Set_Base_Name (Res, Res); Set_Enumeration_Decl (Res, Res); Set_Enum_Pos (Res, Iir_Int32 (Get_Nbr_Elements (List))); Sem.Compute_Subprogram_Hash (Res); @@ -247,16 +255,23 @@ package body Std_Package is -- Create an array of EL_TYPE, indexed by Natural. procedure Create_Array_Type - (Def : out Iir; Decl : out Iir; El_Type : Iir; Name : Name_Id) + (Def : out Iir; Decl : out Iir; El_Decl : Iir; Name : Name_Id) is Index_List : Iir_List; + Index : Iir; + Element : Iir; begin + Element := Create_Std_Type_Mark (El_Decl); + Index := Create_Std_Type_Mark (Natural_Subtype_Declaration); + Def := Create_Std_Iir (Iir_Kind_Array_Type_Definition); Set_Base_Type (Def, Def); + Index_List := Create_Iir_List; Set_Index_Subtype_List (Def, Index_List); - Append_Element (Index_List, Natural_Subtype_Definition); - Set_Element_Subtype (Def, El_Type); + Append_Element (Index_List, Index); + + Set_Element_Subtype_Indication (Def, Element); Set_Type_Staticness (Def, None); Set_Signal_Type_Flag (Def, True); Set_Has_Signal_Flag (Def, not Flags.Flag_Whole_Analyze); @@ -288,7 +303,7 @@ package body Std_Package is Set_Identifier (Inter, Std_Names.Name_Value); Set_Type (Inter, Inter_Type); Set_Mode (Inter, Iir_In_Mode); - Set_Base_Name (Inter, Inter); + Set_Lexical_Layout (Inter, Iir_Lexical_Has_Type); Set_Interface_Declaration_Chain (Decl, Inter); if Inter2_Id /= Null_Identifier then @@ -296,7 +311,7 @@ package body Std_Package is Set_Identifier (Inter2, Inter2_Id); Set_Type (Inter2, Inter2_Type); Set_Mode (Inter2, Iir_In_Mode); - Set_Base_Name (Inter2, Inter2); + Set_Lexical_Layout (Inter2, Iir_Lexical_Has_Type); Set_Chain (Inter, Inter2); end if; @@ -322,8 +337,8 @@ package body Std_Package is Set_Identifier (Inter, Std_Names.Name_S); Set_Type (Inter, Inter_Type); Set_Mode (Inter, Iir_In_Mode); - Set_Base_Name (Inter, Inter); Set_Interface_Declaration_Chain (Decl, Inter); + Set_Lexical_Layout (Inter, Iir_Lexical_Has_Type); Sem.Compute_Subprogram_Hash (Decl); Add_Decl (Decl); @@ -386,11 +401,12 @@ package body Std_Package is not Flags.Flag_Whole_Analyze); -- type boolean is - Create_Std_Type (Boolean_Type, Boolean_Type_Definition, Name_Boolean); + Create_Std_Type (Boolean_Type_Declaration, Boolean_Type_Definition, + Name_Boolean); Iirs_Utils.Create_Range_Constraint_For_Enumeration_Type (Boolean_Type_Definition); - Add_Implicit_Operations (Boolean_Type); + Add_Implicit_Operations (Boolean_Type_Declaration); end; if Vhdl_Std >= Vhdl_08 then @@ -422,11 +438,11 @@ package body Std_Package is Set_Only_Characters_Flag (Bit_Type_Definition, True); -- type bit is - Create_Std_Type (Bit_Type, Bit_Type_Definition, Name_Bit); + Create_Std_Type (Bit_Type_Declaration, Bit_Type_Definition, Name_Bit); Iirs_Utils.Create_Range_Constraint_For_Enumeration_Type (Bit_Type_Definition); - Add_Implicit_Operations (Bit_Type); + Add_Implicit_Operations (Bit_Type_Declaration); end; if Vhdl_Std >= Vhdl_08 then @@ -473,12 +489,13 @@ package body Std_Package is not Flags.Flag_Whole_Analyze); -- type character is - Create_Std_Type (Character_Type, Character_Type_Definition, - Name_Character); + Create_Std_Type + (Character_Type_Declaration, Character_Type_Definition, + Name_Character); Iirs_Utils.Create_Range_Constraint_For_Enumeration_Type (Character_Type_Definition); - Add_Implicit_Operations (Character_Type); + Add_Implicit_Operations (Character_Type_Declaration); end; -- severity level. @@ -505,28 +522,29 @@ package body Std_Package is not Flags.Flag_Whole_Analyze); -- type severity_level is - Create_Std_Type (Severity_Level_Type, Severity_Level_Type_Definition, - Name_Severity_Level); + Create_Std_Type + (Severity_Level_Type_Declaration, Severity_Level_Type_Definition, + Name_Severity_Level); Iirs_Utils.Create_Range_Constraint_For_Enumeration_Type (Severity_Level_Type_Definition); - Add_Implicit_Operations (Severity_Level_Type); + Add_Implicit_Operations (Severity_Level_Type_Declaration); end; -- universal integer begin Create_Integer_Type (Universal_Integer_Type_Definition, - Universal_Integer_Type, + Universal_Integer_Type_Declaration, Name_Universal_Integer); - Add_Decl (Universal_Integer_Type); + Add_Decl (Universal_Integer_Type_Declaration); Create_Integer_Subtype (Universal_Integer_Type_Definition, - Universal_Integer_Type, + Universal_Integer_Type_Declaration, Universal_Integer_Subtype_Definition, - Universal_Integer_Subtype); + Universal_Integer_Subtype_Declaration); - Add_Decl (Universal_Integer_Subtype); - Set_Subtype_Definition (Universal_Integer_Type, + Add_Decl (Universal_Integer_Subtype_Declaration); + Set_Subtype_Definition (Universal_Integer_Type_Declaration, Universal_Integer_Subtype_Definition); -- Do not create implicit operations yet, since "**" needs integer @@ -547,14 +565,14 @@ package body Std_Package is Set_Signal_Type_Flag (Universal_Real_Type_Definition, True); Set_Has_Signal_Flag (Universal_Real_Type_Definition, False); - Universal_Real_Type := + Universal_Real_Type_Declaration := Create_Std_Decl (Iir_Kind_Anonymous_Type_Declaration); - Set_Identifier (Universal_Real_Type, Name_Universal_Real); - Set_Type_Definition (Universal_Real_Type, + Set_Identifier (Universal_Real_Type_Declaration, Name_Universal_Real); + Set_Type_Definition (Universal_Real_Type_Declaration, Universal_Real_Type_Definition); Set_Type_Declarator (Universal_Real_Type_Definition, - Universal_Real_Type); - Add_Decl (Universal_Real_Type); + Universal_Real_Type_Declaration); + Add_Decl (Universal_Real_Type_Declaration); Universal_Real_Subtype_Definition := Create_Std_Iir (Iir_Kind_Floating_Subtype_Definition); @@ -570,17 +588,18 @@ package body Std_Package is Set_Has_Signal_Flag (Universal_Real_Subtype_Definition, False); -- type is - Universal_Real_Subtype := + Universal_Real_Subtype_Declaration := Create_Std_Decl (Iir_Kind_Subtype_Declaration); - Set_Identifier (Universal_Real_Subtype, Name_Universal_Real); - Set_Type (Universal_Real_Subtype, + Set_Identifier (Universal_Real_Subtype_Declaration, + Name_Universal_Real); + Set_Type (Universal_Real_Subtype_Declaration, Universal_Real_Subtype_Definition); Set_Type_Declarator (Universal_Real_Subtype_Definition, - Universal_Real_Subtype); - Set_Subtype_Definition (Universal_Real_Type, + Universal_Real_Subtype_Declaration); + Set_Subtype_Definition (Universal_Real_Type_Declaration, Universal_Real_Subtype_Definition); - Add_Decl (Universal_Real_Subtype); + Add_Decl (Universal_Real_Subtype_Declaration); -- Do not create implicit operations yet, since "**" needs integer -- type. @@ -589,12 +608,12 @@ package body Std_Package is -- Convertible type. begin Create_Integer_Type (Convertible_Integer_Type_Definition, - Convertible_Integer_Type, + Convertible_Integer_Type_Declaration, Name_Convertible_Integer); Create_Integer_Subtype (Convertible_Integer_Type_Definition, - Convertible_Integer_Type, + Convertible_Integer_Type_Declaration, Convertible_Integer_Subtype_Definition, - Convertible_Integer_Subtype); + Convertible_Integer_Subtype_Declaration); -- Not added in std.standard. end; @@ -606,13 +625,14 @@ package body Std_Package is Set_Signal_Type_Flag (Convertible_Real_Type_Definition, True); Set_Has_Signal_Flag (Convertible_Real_Type_Definition, False); - Convertible_Real_Type := + Convertible_Real_Type_Declaration := Create_Std_Decl (Iir_Kind_Anonymous_Type_Declaration); - Set_Identifier (Convertible_Real_Type, Name_Convertible_Real); - Set_Type_Definition (Convertible_Real_Type, + Set_Identifier (Convertible_Real_Type_Declaration, + Name_Convertible_Real); + Set_Type_Definition (Convertible_Real_Type_Declaration, Convertible_Real_Type_Definition); Set_Type_Declarator (Convertible_Real_Type_Definition, - Convertible_Real_Type); + Convertible_Real_Type_Declaration); end; -- integer type. @@ -620,19 +640,19 @@ package body Std_Package is Integer_Type_Definition := Create_Std_Iir (Iir_Kind_Integer_Type_Definition); Create_Integer_Type (Integer_Type_Definition, - Integer_Type, + Integer_Type_Declaration, Name_Integer); - Add_Decl (Integer_Type); + Add_Decl (Integer_Type_Declaration); - Add_Implicit_Operations (Integer_Type); - Add_Implicit_Operations (Universal_Integer_Type); - Add_Implicit_Operations (Universal_Real_Type); + Add_Implicit_Operations (Integer_Type_Declaration); + Add_Implicit_Operations (Universal_Integer_Type_Declaration); + Add_Implicit_Operations (Universal_Real_Type_Declaration); Create_Integer_Subtype (Integer_Type_Definition, - Integer_Type, + Integer_Type_Declaration, Integer_Subtype_Definition, - Integer_Subtype); - Add_Decl (Integer_Subtype); + Integer_Subtype_Declaration); + Add_Decl (Integer_Subtype_Declaration); end; -- Real type. @@ -647,13 +667,14 @@ package body Std_Package is Set_Has_Signal_Flag (Real_Type_Definition, not Flags.Flag_Whole_Analyze); - Real_Type := Create_Std_Decl (Iir_Kind_Anonymous_Type_Declaration); - Set_Identifier (Real_Type, Name_Real); - Set_Type_Definition (Real_Type, Real_Type_Definition); - Set_Type_Declarator (Real_Type_Definition, Real_Type); - Add_Decl (Real_Type); + Real_Type_Declaration := + Create_Std_Decl (Iir_Kind_Anonymous_Type_Declaration); + Set_Identifier (Real_Type_Declaration, Name_Real); + Set_Type_Definition (Real_Type_Declaration, Real_Type_Definition); + Set_Type_Declarator (Real_Type_Definition, Real_Type_Declaration); + Add_Decl (Real_Type_Declaration); - Add_Implicit_Operations (Real_Type); + Add_Implicit_Operations (Real_Type_Declaration); Real_Subtype_Definition := Create_Std_Iir (Iir_Kind_Floating_Subtype_Definition); @@ -668,13 +689,16 @@ package body Std_Package is Set_Has_Signal_Flag (Real_Subtype_Definition, not Flags.Flag_Whole_Analyze); - Real_Subtype := Create_Std_Decl (Iir_Kind_Subtype_Declaration); - Set_Std_Identifier (Real_Subtype, Name_Real); - Set_Type (Real_Subtype, Real_Subtype_Definition); - Set_Type_Declarator (Real_Subtype_Definition, Real_Subtype); - Add_Decl (Real_Subtype); - - Set_Subtype_Definition (Real_Type, Real_Subtype_Definition); + Real_Subtype_Declaration := + Create_Std_Decl (Iir_Kind_Subtype_Declaration); + Set_Std_Identifier (Real_Subtype_Declaration, Name_Real); + Set_Type (Real_Subtype_Declaration, Real_Subtype_Definition); + Set_Type_Declarator + (Real_Subtype_Definition, Real_Subtype_Declaration); + Add_Decl (Real_Subtype_Declaration); + + Set_Subtype_Definition + (Real_Type_Declaration, Real_Subtype_Definition); end; -- time definition @@ -684,13 +708,14 @@ package body Std_Package is use Iir_Chains.Unit_Chain_Handling; function Create_Std_Phys_Lit (Value : Iir_Int64; - Unit : Iir_Unit_Declaration) + Unit : Iir_Simple_Name) return Iir_Physical_Int_Literal is Lit: Iir_Physical_Int_Literal; begin Lit := Create_Std_Iir (Iir_Kind_Physical_Int_Literal); Set_Value (Lit, Value); + pragma Assert (Get_Kind (Unit) = Iir_Kind_Simple_Name); Set_Unit_Name (Lit, Unit); Set_Type (Lit, Time_Type_Definition); Set_Expr_Staticness (Lit, Time_Staticness); @@ -703,12 +728,15 @@ package body Std_Package is Name : Name_Id) is Lit: Iir_Physical_Int_Literal; + Mul_Name : Iir; begin Unit := Create_Std_Iir (Iir_Kind_Unit_Declaration); Set_Std_Identifier (Unit, Name); Set_Type (Unit, Time_Type_Definition); - Lit := Create_Std_Phys_Lit (Multiplier_Value, Multiplier); + Mul_Name := Iirs_Utils.Build_Simple_Name + (Multiplier, Std_Location); + Lit := Create_Std_Phys_Lit (Multiplier_Value, Mul_Name); Set_Physical_Literal (Unit, Lit); Lit := Create_Std_Phys_Lit (Multiplier_Value @@ -717,9 +745,11 @@ package body Std_Package is Set_Physical_Unit_Value (Unit, Lit); Set_Expr_Staticness (Unit, Time_Staticness); + Set_Name_Staticness (Unit, Locally); Append (Last_Unit, Time_Type_Definition, Unit); end Create_Unit; + Time_Fs_Name : Iir; Time_Fs_Unit: Iir_Unit_Declaration; Time_Ps_Unit: Iir_Unit_Declaration; Time_Ns_Unit: Iir_Unit_Declaration; @@ -743,6 +773,7 @@ package body Std_Package is Set_Signal_Type_Flag (Time_Type_Definition, True); Set_Has_Signal_Flag (Time_Type_Definition, not Flags.Flag_Whole_Analyze); + Set_End_Has_Reserved_Id (Time_Type_Definition, True); Build_Init (Last_Unit); @@ -750,8 +781,11 @@ package body Std_Package is Set_Std_Identifier (Time_Fs_Unit, Name_Fs); Set_Type (Time_Fs_Unit, Time_Type_Definition); Set_Expr_Staticness (Time_Fs_Unit, Time_Staticness); + Set_Name_Staticness (Time_Fs_Unit, Locally); + Time_Fs_Name := Iirs_Utils.Build_Simple_Name + (Time_Fs_Unit, Std_Location); Set_Physical_Unit_Value - (Time_Fs_Unit, Create_Std_Phys_Lit (1, Time_Fs_Unit)); + (Time_Fs_Unit, Create_Std_Phys_Lit (1, Time_Fs_Name)); Append (Last_Unit, Time_Type_Definition, Time_Fs_Unit); Create_Unit (Time_Ps_Unit, 1000, Time_Fs_Unit, Name_Ps); @@ -763,37 +797,42 @@ package body Std_Package is Create_Unit (Time_Hr_Unit, 60, Time_Min_Unit, Name_Hr); -- type is - Time_Type := Create_Std_Decl (Iir_Kind_Anonymous_Type_Declaration); - Set_Identifier (Time_Type, Name_Time); - Set_Type_Definition (Time_Type, Time_Type_Definition); - Set_Type_Declarator (Time_Type_Definition, Time_Type); - Add_Decl (Time_Type); + Time_Type_Declaration := + Create_Std_Decl (Iir_Kind_Anonymous_Type_Declaration); + Set_Identifier (Time_Type_Declaration, Name_Time); + Set_Type_Definition (Time_Type_Declaration, Time_Type_Definition); + Set_Type_Declarator (Time_Type_Definition, Time_Type_Declaration); + Add_Decl (Time_Type_Declaration); - Add_Implicit_Operations (Time_Type); + Add_Implicit_Operations (Time_Type_Declaration); Time_Subtype_Definition := Create_Std_Iir (Iir_Kind_Physical_Subtype_Definition); Constraint := Create_Std_Range_Expr (Create_Std_Phys_Lit (Low_Bound (Flags.Flag_Time_64), - Time_Fs_Unit), + Time_Fs_Name), Create_Std_Phys_Lit (High_Bound (Flags.Flag_Time_64), - Time_Fs_Unit), + Time_Fs_Name), Time_Type_Definition); Set_Range_Constraint (Time_Subtype_Definition, Constraint); Set_Base_Type (Time_Subtype_Definition, Time_Type_Definition); - --Set_Type_Mark (Time_Subtype_Definition, Time_Type_Definition); + --Set_Subtype_Type_Mark (Time_Subtype_Definition, + -- Time_Type_Definition); Set_Type_Staticness (Time_Subtype_Definition, Time_Staticness); Set_Signal_Type_Flag (Time_Subtype_Definition, True); Set_Has_Signal_Flag (Time_Subtype_Definition, not Flags.Flag_Whole_Analyze); -- subtype - Time_Subtype := Create_Std_Decl (Iir_Kind_Subtype_Declaration); - Set_Std_Identifier (Time_Subtype, Name_Time); - Set_Type (Time_Subtype, Time_Subtype_Definition); - Set_Type_Declarator (Time_Subtype_Definition, Time_Subtype); - Add_Decl (Time_Subtype); - Set_Subtype_Definition (Time_Type, Time_Subtype_Definition); + Time_Subtype_Declaration := + Create_Std_Decl (Iir_Kind_Subtype_Declaration); + Set_Std_Identifier (Time_Subtype_Declaration, Name_Time); + Set_Type (Time_Subtype_Declaration, Time_Subtype_Definition); + Set_Type_Declarator (Time_Subtype_Definition, + Time_Subtype_Declaration); + Add_Decl (Time_Subtype_Declaration); + Set_Subtype_Definition + (Time_Type_Declaration, Time_Subtype_Definition); -- The default time base. case Flags.Time_Resolution is @@ -822,12 +861,13 @@ package body Std_Package is if Vhdl_Std >= Vhdl_93c then Delay_Length_Subtype_Definition := Create_Std_Iir (Iir_Kind_Physical_Subtype_Definition); - Set_Type_Mark (Delay_Length_Subtype_Definition, - Time_Subtype_Definition); + Set_Subtype_Type_Mark + (Delay_Length_Subtype_Definition, + Create_Std_Type_Mark (Time_Subtype_Declaration)); Constraint := Create_Std_Range_Expr - (Create_Std_Phys_Lit (0, Time_Fs_Unit), + (Create_Std_Phys_Lit (0, Time_Fs_Name), Create_Std_Phys_Lit (High_Bound (Flags.Flag_Time_64), - Time_Fs_Unit), + Time_Fs_Name), Time_Type_Definition); Set_Range_Constraint (Delay_Length_Subtype_Definition, Constraint); Set_Base_Type @@ -838,16 +878,18 @@ package body Std_Package is Set_Has_Signal_Flag (Delay_Length_Subtype_Definition, not Flags.Flag_Whole_Analyze); - Delay_Length_Subtype := + Delay_Length_Subtype_Declaration := Create_Std_Decl (Iir_Kind_Subtype_Declaration); - Set_Std_Identifier (Delay_Length_Subtype, Name_Delay_Length); - Set_Type (Delay_Length_Subtype, Delay_Length_Subtype_Definition); - Set_Type_Declarator - (Delay_Length_Subtype_Definition, Delay_Length_Subtype); - Add_Decl (Delay_Length_Subtype); + Set_Std_Identifier (Delay_Length_Subtype_Declaration, + Name_Delay_Length); + Set_Type (Delay_Length_Subtype_Declaration, + Delay_Length_Subtype_Definition); + Set_Type_Declarator (Delay_Length_Subtype_Definition, + Delay_Length_Subtype_Declaration); + Add_Decl (Delay_Length_Subtype_Declaration); else Delay_Length_Subtype_Definition := Null_Iir; - Delay_Length_Subtype := Null_Iir; + Delay_Length_Subtype_Declaration := Null_Iir; end if; end; @@ -894,11 +936,13 @@ package body Std_Package is Set_Has_Signal_Flag (Natural_Subtype_Definition, not Flags.Flag_Whole_Analyze); - Natural_Subtype := Create_Std_Decl (Iir_Kind_Subtype_Declaration); - Set_Std_Identifier (Natural_Subtype, Name_Natural); - Set_Type (Natural_Subtype, Natural_Subtype_Definition); - Add_Decl (Natural_Subtype); - Set_Type_Declarator (Natural_Subtype_Definition, Natural_Subtype); + Natural_Subtype_Declaration := + Create_Std_Decl (Iir_Kind_Subtype_Declaration); + Set_Std_Identifier (Natural_Subtype_Declaration, Name_Natural); + Set_Type (Natural_Subtype_Declaration, Natural_Subtype_Definition); + Add_Decl (Natural_Subtype_Declaration); + Set_Type_Declarator (Natural_Subtype_Definition, + Natural_Subtype_Declaration); end; -- positive subtype @@ -920,45 +964,54 @@ package body Std_Package is Set_Has_Signal_Flag (Positive_Subtype_Definition, not Flags.Flag_Whole_Analyze); - Positive_Subtype := Create_Std_Decl (Iir_Kind_Subtype_Declaration); - Set_Std_Identifier (Positive_Subtype, Name_Positive); - Set_Type (Positive_Subtype, Positive_Subtype_Definition); - Add_Decl (Positive_Subtype); - Set_Type_Declarator (Positive_Subtype_Definition, Positive_Subtype); + Positive_Subtype_Declaration := + Create_Std_Decl (Iir_Kind_Subtype_Declaration); + Set_Std_Identifier (Positive_Subtype_Declaration, Name_Positive); + Set_Type (Positive_Subtype_Declaration, Positive_Subtype_Definition); + Add_Decl (Positive_Subtype_Declaration); + Set_Type_Declarator (Positive_Subtype_Definition, + Positive_Subtype_Declaration); end; -- string type. -- type string is array (positive range <>) of character; + declare + Element : Iir; + Index_List : Iir_List; begin + Element := Create_Std_Type_Mark (Character_Type_Declaration); + String_Type_Definition := Create_Std_Iir (Iir_Kind_Array_Type_Definition); Set_Base_Type (String_Type_Definition, String_Type_Definition); - Set_Index_Subtype_List (String_Type_Definition, Create_Iir_List); - Append_Element (Get_Index_Subtype_List (String_Type_Definition), - Positive_Subtype_Definition); - Set_Element_Subtype (String_Type_Definition, - Character_Type_Definition); + Index_List := Create_Iir_List; + Append_Element (Index_List, + Create_Std_Type_Mark (Positive_Subtype_Declaration)); + Set_Index_Subtype_List (String_Type_Definition, Index_List); + Set_Element_Subtype_Indication (String_Type_Definition, Element); Set_Type_Staticness (String_Type_Definition, None); Set_Signal_Type_Flag (String_Type_Definition, True); Set_Has_Signal_Flag (String_Type_Definition, not Flags.Flag_Whole_Analyze); - Create_Std_Type (String_Type, String_Type_Definition, Name_String); + Create_Std_Type + (String_Type_Declaration, String_Type_Definition, Name_String); - Add_Implicit_Operations (String_Type); + Add_Implicit_Operations (String_Type_Declaration); end; if Vhdl_Std >= Vhdl_08 then -- type Boolean_Vector is array (Natural range <>) of Boolean; Create_Array_Type - (Boolean_Vector_Type_Definition, Boolean_Vector_Type, - Boolean_Type_Definition, Name_Boolean_Vector); + (Boolean_Vector_Type_Definition, Boolean_Vector_Type_Declaration, + Boolean_Type_Declaration, Name_Boolean_Vector); end if; -- bit_vector type. -- type bit_vector is array (natural range <>) of bit; - Create_Array_Type (Bit_Vector_Type_Definition, Bit_Vector_Type, - Bit_Type_Definition, Name_Bit_Vector); + Create_Array_Type + (Bit_Vector_Type_Definition, Bit_Vector_Type_Declaration, + Bit_Type_Declaration, Name_Bit_Vector); -- LRM08 5.3.2.4 Predefined operations on array types -- The following operations are implicitly declared in package @@ -978,18 +1031,18 @@ package body Std_Package is if Vhdl_Std >= Vhdl_08 then -- type integer_vector is array (natural range <>) of Integer; Create_Array_Type - (Integer_Vector_Type_Definition, Integer_Vector_Type, - Integer_Subtype_Definition, Name_Integer_Vector); + (Integer_Vector_Type_Definition, Integer_Vector_Type_Declaration, + Integer_Subtype_Declaration, Name_Integer_Vector); -- type Real_vector is array (natural range <>) of Real; Create_Array_Type - (Real_Vector_Type_Definition, Real_Vector_Type, - Real_Subtype_Definition, Name_Real_Vector); + (Real_Vector_Type_Definition, Real_Vector_Type_Declaration, + Real_Subtype_Declaration, Name_Real_Vector); -- type Time_vector is array (natural range <>) of Time; Create_Array_Type - (Time_Vector_Type_Definition, Time_Vector_Type, - Time_Subtype_Definition, Name_Time_Vector); + (Time_Vector_Type_Definition, Time_Vector_Type_Declaration, + Time_Subtype_Declaration, Name_Time_Vector); end if; -- VHDL93: @@ -1014,14 +1067,15 @@ package body Std_Package is not Flags.Flag_Whole_Analyze); -- type file_open_kind is - Create_Std_Type (File_Open_Kind_Type, File_Open_Kind_Type_Definition, - Name_File_Open_Kind); + Create_Std_Type + (File_Open_Kind_Type_Declaration, File_Open_Kind_Type_Definition, + Name_File_Open_Kind); Iirs_Utils.Create_Range_Constraint_For_Enumeration_Type (File_Open_Kind_Type_Definition); - Add_Implicit_Operations (File_Open_Kind_Type); + Add_Implicit_Operations (File_Open_Kind_Type_Declaration); else - File_Open_Kind_Type := Null_Iir; + File_Open_Kind_Type_Declaration := Null_Iir; File_Open_Kind_Type_Definition := Null_Iir; File_Open_Kind_Read_Mode := Null_Iir; File_Open_Kind_Write_Mode := Null_Iir; @@ -1053,14 +1107,14 @@ package body Std_Package is not Flags.Flag_Whole_Analyze); -- type file_open_kind is - Create_Std_Type (File_Open_Status_Type, + Create_Std_Type (File_Open_Status_Type_Declaration, File_Open_Status_Type_Definition, Name_File_Open_Status); Iirs_Utils.Create_Range_Constraint_For_Enumeration_Type (File_Open_Status_Type_Definition); - Add_Implicit_Operations (File_Open_Status_Type); + Add_Implicit_Operations (File_Open_Status_Type_Declaration); else - File_Open_Status_Type := Null_Iir; + File_Open_Status_Type_Declaration := Null_Iir; File_Open_Status_Type_Definition := Null_Iir; File_Open_Status_Open_Ok := Null_Iir; File_Open_Status_Status_Error := Null_Iir; @@ -1073,6 +1127,8 @@ package body Std_Package is if Vhdl_Std >= Vhdl_93c then Foreign_Attribute := Create_Std_Decl (Iir_Kind_Attribute_Declaration); Set_Std_Identifier (Foreign_Attribute, Name_Foreign); + Set_Type_Mark (Foreign_Attribute, + Create_Std_Type_Mark (String_Type_Declaration)); Set_Type (Foreign_Attribute, String_Type_Definition); Add_Decl (Foreign_Attribute); else diff --git a/std_package.ads b/std_package.ads index eebb610b5..166c3c789 100644 --- a/std_package.ads +++ b/std_package.ads @@ -37,23 +37,23 @@ package Std_Package is Standard_Package : Iir_Package_Declaration := Null_Iir; -- Boolean values. - Boolean_Type: Iir_Type_Declaration := Null_Iir; - Boolean_Type_Definition: Iir_Enumeration_Type_Definition; - Boolean_False: Iir_Enumeration_Literal; - Boolean_True: Iir_Enumeration_Literal; + Boolean_Type_Declaration : Iir_Type_Declaration := Null_Iir; + Boolean_Type_Definition : Iir_Enumeration_Type_Definition; + Boolean_False : Iir_Enumeration_Literal; + Boolean_True : Iir_Enumeration_Literal; -- Bit values. - Bit_Type: Iir_Type_Declaration := Null_Iir; - Bit_Type_Definition: Iir_Enumeration_Type_Definition; - Bit_0: Iir_Enumeration_Literal; - Bit_1: Iir_Enumeration_Literal; + Bit_Type_Declaration : Iir_Type_Declaration := Null_Iir; + Bit_Type_Definition : Iir_Enumeration_Type_Definition; + Bit_0 : Iir_Enumeration_Literal; + Bit_1 : Iir_Enumeration_Literal; -- Predefined character. - Character_Type: Iir_Type_Declaration; + Character_Type_Declaration : Iir_Type_Declaration; Character_Type_Definition : Iir_Enumeration_Type_Definition; -- severity level. - Severity_Level_Type : Iir_Type_Declaration; + Severity_Level_Type_Declaration : Iir_Type_Declaration; Severity_Level_Type_Definition : Iir_Enumeration_Type_Definition; Severity_Level_Note : Iir_Enumeration_Literal; Severity_Level_Warning : Iir_Enumeration_Literal; @@ -61,22 +61,22 @@ package Std_Package is Severity_Level_Failure : Iir_Enumeration_Literal; -- Universal types. - Universal_Integer_Type : Iir_Anonymous_Type_Declaration; + Universal_Integer_Type_Declaration : Iir_Anonymous_Type_Declaration; Universal_Integer_Type_Definition : constant Iir_Integer_Type_Definition; - Universal_Integer_Subtype : Iir_Subtype_Declaration; + Universal_Integer_Subtype_Declaration : Iir_Subtype_Declaration; Universal_Integer_Subtype_Definition : Iir_Integer_Subtype_Definition; Universal_Integer_One : Iir_Integer_Literal; - Universal_Real_Type : Iir_Anonymous_Type_Declaration; + Universal_Real_Type_Declaration : Iir_Anonymous_Type_Declaration; Universal_Real_Type_Definition : constant Iir_Floating_Type_Definition; - Universal_Real_Subtype : Iir_Subtype_Declaration; + Universal_Real_Subtype_Declaration : Iir_Subtype_Declaration; Universal_Real_Subtype_Definition : Iir_Floating_Subtype_Definition; -- Predefined integer type. - Integer_Type: Iir_Anonymous_Type_Declaration; + Integer_Type_Declaration : Iir_Anonymous_Type_Declaration; Integer_Type_Definition : Iir_Integer_Type_Definition; - Integer_Subtype : Iir_Subtype_Declaration; + Integer_Subtype_Declaration : Iir_Subtype_Declaration; Integer_Subtype_Definition : Iir_Integer_Subtype_Definition; -- Type used when a subtype indication cannot be semantized. @@ -84,40 +84,40 @@ package Std_Package is Error_Type : Iir_Integer_Type_Definition renames Integer_Type_Definition; -- Predefined real type. - Real_Type: Iir_Anonymous_Type_Declaration; + Real_Type_Declaration : Iir_Anonymous_Type_Declaration; Real_Type_Definition : Iir_Floating_Type_Definition; - Real_Subtype : Iir_Subtype_Declaration; + Real_Subtype_Declaration : Iir_Subtype_Declaration; Real_Subtype_Definition : Iir_Floating_Subtype_Definition; -- Predefined natural subtype. - Natural_Subtype: Iir_Subtype_Declaration; + Natural_Subtype_Declaration : Iir_Subtype_Declaration; Natural_Subtype_Definition : Iir_Integer_Subtype_Definition; -- Predefined positive subtype. - Positive_Subtype: Iir_Subtype_Declaration; + Positive_Subtype_Declaration : Iir_Subtype_Declaration; Positive_Subtype_Definition : Iir_Integer_Subtype_Definition; -- Predefined positive subtype. - String_Type: Iir_Type_Declaration; + String_Type_Declaration : Iir_Type_Declaration; String_Type_Definition : Iir_Array_Type_Definition; -- Predefined positive subtype. - Bit_Vector_Type: Iir_Type_Declaration; + Bit_Vector_Type_Declaration : Iir_Type_Declaration; Bit_Vector_Type_Definition : Iir_Array_Type_Definition; -- predefined time subtype - Time_Type: Iir_Anonymous_Type_Declaration; + Time_Type_Declaration : Iir_Anonymous_Type_Declaration; Time_Type_Definition: Iir_Physical_Type_Definition; Time_Subtype_Definition: Iir_Physical_Subtype_Definition; - Time_Subtype : Iir_Subtype_Declaration; + Time_Subtype_Declaration : Iir_Subtype_Declaration; -- For VHDL-93 Delay_Length_Subtype_Definition : Iir_Physical_Subtype_Definition; - Delay_Length_Subtype : Iir_Subtype_Declaration; + Delay_Length_Subtype_Declaration : Iir_Subtype_Declaration; -- For VHDL-93: -- type File_Open_Kind - File_Open_Kind_Type : Iir_Type_Declaration; + File_Open_Kind_Type_Declaration : Iir_Type_Declaration; File_Open_Kind_Type_Definition : Iir_Enumeration_Type_Definition; File_Open_Kind_Read_Mode : Iir_Enumeration_Literal; File_Open_Kind_Write_Mode : Iir_Enumeration_Literal; @@ -125,7 +125,7 @@ package Std_Package is -- For VHDL-93: -- type File_Open_Status - File_Open_Status_Type : Iir_Type_Declaration; + File_Open_Status_Type_Declaration : Iir_Type_Declaration; File_Open_Status_Type_Definition : Iir_Enumeration_Type_Definition; File_Open_Status_Open_Ok : Iir_Enumeration_Literal; File_Open_Status_Status_Error : Iir_Enumeration_Literal; @@ -138,16 +138,16 @@ package Std_Package is -- For VHDL-08 Boolean_Vector_Type_Definition : Iir_Array_Type_Definition; - Boolean_Vector_Type : Iir_Type_Declaration; + Boolean_Vector_Type_Declaration : Iir_Type_Declaration; Integer_Vector_Type_Definition : Iir_Array_Type_Definition; - Integer_Vector_Type : Iir_Type_Declaration; + Integer_Vector_Type_Declaration : Iir_Type_Declaration; Real_Vector_Type_Definition : Iir_Array_Type_Definition; - Real_Vector_Type : Iir_Type_Declaration; + Real_Vector_Type_Declaration : Iir_Type_Declaration; Time_Vector_Type_Definition : Iir_Array_Type_Definition; - Time_Vector_Type : Iir_Type_Declaration; + Time_Vector_Type_Declaration : Iir_Type_Declaration; -- Internal use only. -- These types should be considered like universal types, but @@ -155,11 +155,11 @@ package Std_Package is -- universal cannot. Convertible_Integer_Type_Definition : constant Iir_Integer_Type_Definition; Convertible_Real_Type_Definition : constant Iir_Floating_Type_Definition; - Convertible_Integer_Type : Iir_Anonymous_Type_Declaration; - Convertible_Real_Type : Iir_Anonymous_Type_Declaration; + Convertible_Integer_Type_Declaration : Iir_Anonymous_Type_Declaration; + Convertible_Real_Type_Declaration : Iir_Anonymous_Type_Declaration; Convertible_Integer_Subtype_Definition : Iir_Integer_Subtype_Definition; - Convertible_Integer_Subtype : Iir_Subtype_Declaration; + Convertible_Integer_Subtype_Declaration : Iir_Subtype_Declaration; -- Create the first well-known nodes. procedure Create_First_Nodes; diff --git a/translate/ghdldrv/Makefile b/translate/ghdldrv/Makefile index fe859f273..9dd86b64f 100644 --- a/translate/ghdldrv/Makefile +++ b/translate/ghdldrv/Makefile @@ -153,10 +153,12 @@ grt.links: cd ../lib; ln -sf $(GRTSRCDIR)/grt.lst .; ln -sf $(GRTSRCDIR)/libgrt.a .; ln -sf $(GRTSRCDIR)/grt.ver . install.all: install.v87 install.v93 install.standard -install.mcode: install.v87 install.v93 install.v08 + +install.mcode: + $(MAKE) GHDL=ghdl_mcode install.v87 install.v93 # install.v08 install.simul: - $(MAKE) GHDL=ghdl_simul install.v87 install.v93 + $(MAKE) GHDL=ghdl_simul install.v87 install.v93 install.v08 install.llvm: $(MAKE) GHDL=ghdl_llvm GHDL1=../ghdl1-llvm install.all diff --git a/translate/ghdldrv/ghdlprint.adb b/translate/ghdldrv/ghdlprint.adb index 3af75f864..73d5ba7ad 100644 --- a/translate/ghdldrv/ghdlprint.adb +++ b/translate/ghdldrv/ghdlprint.adb @@ -78,6 +78,9 @@ package body Ghdlprint is type Filexref_Info_Arr_Acc is access Filexref_Info_Arr; Filexref_Info : Filexref_Info_Arr_Acc := null; + -- If True, at least one xref is missing. + Missing_Xref : Boolean := False; + procedure PP_Html_File (File : Source_File_Entry) is use Flags; @@ -238,6 +241,7 @@ package body Ghdlprint is if Ref = Bad_Xref then Disp_Text; Warning_Msg_Sem ("cannot find xref", Loc); + Missing_Xref := True; return; end if; else @@ -989,7 +993,7 @@ package body Ghdlprint is Unit := Get_First_Design_Unit (Design_File); while Unit /= Null_Iir loop - -- Sem, canon, annotate a design unit. + -- Analyze the design unit. Back_End.Finish_Compilation (Unit, True); Next_Unit := Get_Chain (Unit); @@ -1204,6 +1208,7 @@ package body Ghdlprint is -- Command --xref-html. type Command_Xref_Html is new Command_Html with record Output_Dir : String_Access := null; + Check_Missing : Boolean := False; end record; function Decode_Command (Cmd : Command_Xref_Html; Name : String) @@ -1246,6 +1251,9 @@ package body Ghdlprint is Cmd.Output_Dir := new String'(Arg); Res := Option_Arg; end if; + elsif Option = "--check-missing" then + Cmd.Check_Missing := True; + Res := Option_Ok; else Decode_Option (Command_Html (Cmd), Option, Arg, Res); end if; @@ -1255,6 +1263,7 @@ package body Ghdlprint is begin Disp_Long_Help (Command_Html (Cmd)); Put_Line ("-o DIR Put generated files into DIR (def: html/)"); + Put_Line ("--check-missing Fail if a reference is missing"); New_Line; Put_Line ("When format is css, the CSS file 'ghdl.css' " & "is never overwritten."); @@ -1493,6 +1502,11 @@ package body Ghdlprint is end if; end; end if; + + if Missing_Xref and Cmd.Check_Missing then + Error ("missing xrefs"); + raise Compile_Error; + end if; exception when Compilation_Error => Error ("xrefs has failed due to compilation error"); diff --git a/translate/ghdldrv/ghdlsimul.adb b/translate/ghdldrv/ghdlsimul.adb index 27b1ce62c..17cece726 100644 --- a/translate/ghdldrv/ghdlsimul.adb +++ b/translate/ghdldrv/ghdlsimul.adb @@ -32,6 +32,7 @@ with Std_Package; with Libraries; with Canon; with Configuration; +with Iirs_Utils; with Annotations; with Elaboration; with Sim_Be; @@ -109,7 +110,7 @@ package body Ghdlsimul is Conf_Unit : constant Iir := Get_Library_Unit (Top_Conf); Arch : constant Iir := Get_Block_Specification (Get_Block_Configuration (Conf_Unit)); - Entity : constant Iir := Get_Entity (Arch); + Entity : constant Iir := Iirs_Utils.Get_Entity (Arch); begin Configuration.Check_Entity_Declaration_Top (Entity); if Nbr_Errors > 0 then diff --git a/translate/trans_analyzes.adb b/translate/trans_analyzes.adb index fd533e283..c8fb14e62 100644 --- a/translate/trans_analyzes.adb +++ b/translate/trans_analyzes.adb @@ -81,14 +81,14 @@ package body Trans_Analyzes is Call := Get_Procedure_Call (Stmt); Assoc := Get_Parameter_Association_Chain (Call); Inter := Get_Interface_Declaration_Chain - (Get_Implementation (Call)); + (Get_Named_Entity (Get_Implementation (Call))); while Assoc /= Null_Iir loop Formal := Get_Formal (Assoc); if Formal = Null_Iir then Formal := Inter; Inter := Get_Chain (Inter); else - Formal := Get_Base_Name (Formal); + Formal := Get_Association_Interface (Assoc); end if; if Get_Kind (Assoc) = Iir_Kind_Association_Element_By_Expression @@ -154,7 +154,7 @@ package body Trans_Analyzes is for I in Natural loop El := Get_Nth_Element (List, I); exit when El = Null_Iir; - Set_After_Drivers_Flag (Get_Base_Name (El), False); + Set_After_Drivers_Flag (Get_Object_Prefix (El), False); end loop; Destroy_Iir_List (List); end Free_Drivers_List; @@ -170,7 +170,7 @@ package body Trans_Analyzes is for I in Natural loop El := Get_Nth_Element (List, I); exit when El = Null_Iir; - if Get_After_Drivers_Flag (Get_Base_Name (El)) then + if Get_After_Drivers_Flag (Get_Object_Prefix (El)) then Put ("* "); else Put (" "); diff --git a/translate/translation.adb b/translate/translation.adb index 98cf8bccd..03333b11c 100644 --- a/translate/translation.adb +++ b/translate/translation.adb @@ -2071,13 +2071,13 @@ package body Translation is procedure Elab_Signal_Declaration_Storage (Decl : Iir); -- Create signal object. - -- Note: DECL can be a signal sub-element (used when signals are + -- Note: SIG can be a signal sub-element (used when signals are -- collapsed). -- If CHECK_NULL is TRUE, create the signal only if it was not yet -- created. -- PARENT is used to link the signal to its parent by rti. procedure Elab_Signal_Declaration_Object - (Decl : Iir; Parent : Iir; Check_Null : Boolean); + (Sig : Iir; Parent : Iir; Check_Null : Boolean); -- True of SIG has a direct driver. function Has_Direct_Driver (Sig : Iir) return Boolean; @@ -4294,7 +4294,7 @@ package body Translation is Entity_Aspect := Get_Entity_Aspect (Binding); - Comp := Get_Component_Name (Cfg); + Comp := Get_Named_Entity (Get_Component_Name (Cfg)); Comp_Info := Get_Info (Comp); if Get_Kind (Cfg) = Iir_Kind_Component_Configuration then @@ -4450,13 +4450,15 @@ package body Translation is for I in Natural loop El := Get_Nth_Element (List, I); exit when El = Null_Iir; + El := Get_Named_Entity (El); case Get_Kind (El) is when Iir_Kind_Component_Instantiation_Statement => declare Assoc : O_Assoc_List; Info : constant Block_Info_Acc := Get_Info (El); Comp_Info : constant Comp_Info_Acc := - Get_Info (Get_Instantiated_Unit (El)); + Get_Info (Get_Named_Entity + (Get_Instantiated_Unit (El))); V : O_Lnode; begin -- The component is really a component and not a @@ -6291,7 +6293,7 @@ package body Translation is procedure Create_File_Type_Var (Def : Iir_File_Type_Definition) is - Type_Name : constant Iir := Get_Type_Mark (Def); + Type_Name : constant Iir := Get_Type (Get_File_Type_Mark (Def)); Info : Type_Info_Acc; begin if Get_Kind (Type_Name) in Iir_Kinds_Scalar_Type_Definition then @@ -6378,25 +6380,26 @@ package body Translation is Info : Type_Info_Acc; Complete : Boolean) is + Indexes_List : constant Iir_List := Get_Index_Subtype_List (Def); Constr : O_Element_List; Dim : String (1 .. 8); N : Natural; P : Natural; - Index_List : Iir_List; Index : Iir; Mark : Id_Mark_Type; begin Start_Record_Type (Constr); - Index_List := Get_Index_Subtype_List (Def); Info.T.Bounds_Vector := - new O_Fnode_Arr (1 .. Get_Nbr_Elements (Index_List)); + new O_Fnode_Arr (1 .. Get_Nbr_Elements (Indexes_List)); for I in Natural loop - Index := Get_Nth_Element (Index_List, I); + Index := Get_Index_Type (Indexes_List, I); exit when Index = Null_Iir; if Is_Anonymous_Type_Definition (Index) then + -- Can this happen ? This is a type mark. Push_Identifier_Prefix (Mark, "DIM", Iir_Int32 (I + 1)); Translate_Type_Definition (Index, True); Pop_Identifier_Prefix (Mark); + raise Program_Error; end if; N := I + 1; P := Dim'Last; @@ -6482,7 +6485,7 @@ package body Translation is procedure Translate_Static_Unidimensional_Array_Length_One (Def : Iir_Array_Type_Definition) is - Indexes : Iir_List; + Indexes : constant Iir_List := Get_Index_Subtype_List (Def); Index_Type : Iir; Index_Base_Type : Iir; Constr : O_Record_Aggr_List; @@ -6493,11 +6496,11 @@ package body Translation is Res1 : O_Cnode; Res : O_Cnode; begin - Indexes := Get_Index_Subtype_List (Def); if Get_Nbr_Elements (Indexes) /= 1 then + -- Not a one-dimensional array. return; end if; - Index_Type := Get_First_Element (Indexes); + Index_Type := Get_Index_Type (Indexes, 0); Arr_Info := Get_Info (Def); if Get_Type_Staticness (Index_Type) = Locally then if Global_Storage /= O_Storage_External then @@ -6543,7 +6546,7 @@ package body Translation is if Get_Nbr_Elements (Indexes) /= 1 then return; end if; - Index_Type := Get_First_Element (Indexes); + Index_Type := Get_Index_Type (Indexes, 0); if Get_Type_Staticness (Index_Type) = Locally then return; end if; @@ -6612,15 +6615,14 @@ package body Translation is function Get_Array_Subtype_Length (Def : Iir_Array_Subtype_Definition) return Iir_Int64 is - Index_List : Iir_List; + Indexes_List : constant Iir_List := Get_Index_Subtype_List (Def); Index : Iir; Len : Iir_Int64; begin - Index_List := Get_Index_Subtype_List (Def); -- Check if the bounds of the array are locally static. Len := 1; for I in Natural loop - Index := Get_Nth_Element (Index_List, I); + Index := Get_Index_Type (Indexes_List, I); exit when Index = Null_Iir; if Get_Type_Staticness (Index) /= Locally then @@ -6686,17 +6688,15 @@ package body Translation is (Def : Iir_Array_Subtype_Definition) return O_Cnode is - Index_List : Iir_List; + Indexes_List : constant Iir_List := Get_Index_Subtype_List (Def); + Baseinfo : constant Type_Info_Acc := Get_Info (Get_Base_Type (Def)); Index : Iir; List : O_Record_Aggr_List; Res : O_Cnode; - Baseinfo : Type_Info_Acc; begin - Index_List := Get_Index_Subtype_List (Def); - Baseinfo := Get_Info (Get_Base_Type (Def)); Start_Record_Aggr (List, Baseinfo.T.Bounds_Type); for I in Natural loop - Index := Get_Nth_Element (Index_List, I); + Index := Get_Index_Type (Indexes_List, I); exit when Index = Null_Iir; New_Record_Aggr_El (List, Create_Static_Type_Definition_Type_Range (Index)); @@ -6708,31 +6708,27 @@ package body Translation is procedure Create_Array_Subtype_Bounds (Def : Iir_Array_Subtype_Definition; Target : O_Lnode) is - Index_List : Iir_List; + Baseinfo : constant Type_Info_Acc := Get_Info (Get_Base_Type (Def)); + Indexes_List : constant Iir_List := Get_Index_Subtype_List (Def); Index : Iir; - Baseinfo : Type_Info_Acc; Targ : Mnode; begin - Baseinfo := Get_Info (Get_Base_Type (Def)); Targ := Lv2M (Target, True, Baseinfo.T.Bounds_Type, Baseinfo.T.Bounds_Ptr_Type, null, Mode_Value); - Index_List := Get_Index_Subtype_List (Def); Open_Temp; - if Get_Nbr_Elements (Index_List) > 1 then + if Get_Nbr_Elements (Indexes_List) > 1 then Targ := Stabilize (Targ); end if; for I in Natural loop - Index := Get_Nth_Element (Index_List, I); + Index := Get_Index_Type (Indexes_List, I); exit when Index = Null_Iir; declare - Index_Type : Iir; - Index_Info : Type_Info_Acc; + Index_Type : constant Iir := Get_Base_Type (Index); + Index_Info : constant Type_Info_Acc := Get_Info (Index_Type); D : O_Dnode; begin - Index_Type := Get_Base_Type (Index); - Index_Info := Get_Info (Index_Type); Open_Temp; D := Create_Temp_Ptr (Index_Info.T.Range_Ptr_Type, @@ -6748,14 +6744,13 @@ package body Translation is -- Get staticness of the array bounds. function Get_Array_Bounds_Staticness (Def : Iir) return Iir_Staticness is - List : Iir_List; - El : Iir; + List : constant Iir_List := Get_Index_Subtype_List (Def); + Idx_Type : Iir; begin - List := Get_Index_Subtype_List (Def); for I in Natural loop - El := Get_Nth_Element (List, I); - exit when El = Null_Iir; - if Get_Type_Staticness (El) /= Locally then + Idx_Type := Get_Index_Type (List, I); + exit when Idx_Type = Null_Iir; + if Get_Type_Staticness (Idx_Type) /= Locally then return Globally; end if; end loop; @@ -7164,24 +7159,10 @@ package body Translation is -- types not used before the full type declaration). return; end if; - Ctype := Get_Type_Of_Type_Mark (Get_Type_Declarator (Def)); + Ctype := Get_Type (Get_Type_Declarator (Def)); Info := Add_Info (Ctype, Kind_Incomplete_Type); Info.Incomplete_Type := Def; Info.Incomplete_Array := null; - return; --- Info := Get_Info (Def); --- Ftype := Get_Type (Get_Type_Declarator (Def)); --- case Get_Kind (Ftype) is --- when Iir_Kind_Record_Type_Definition => --- Info.Type_Mode := Type_Mode_Unknown; --- for I in Mode_Value .. Type_To_Last_Object_Kind (Def) loop --- New_Uncomplete_Record_Type (Info.Ortho_Type (I)); --- end loop; --- when others => --- Error_Kind ("translate_incomplete_type", Ftype); --- end case; --- Set_Info (Ftype, Info); --- Finish_Type_Definition (Info, Incomplete_Type); end Translate_Incomplete_Type; -- CTYPE is the type which has been completed. @@ -7542,7 +7523,7 @@ package body Translation is Index : Iir; begin for I in Natural loop - Index := Get_Nth_Element (Index_List, I); + Index := Get_Index_Type (Index_List, I); exit when Index = Null_Iir; if Is_Anonymous_Type_Definition (Index) then Create_Type_Definition_Type_Range (Index); @@ -7764,7 +7745,7 @@ package body Translation is declare V : Iir_Int32; begin - V := Get_Enum_Pos (Lit); + V := Iir_Int32 (Eval_Pos (Lit)); if Is_Hi then return V = 1; else @@ -7776,7 +7757,7 @@ package body Translation is V : Iir_Int32; Base_Type : Iir; begin - V := Get_Enum_Pos (Lit); + V := Iir_Int32 (Eval_Pos (Lit)); if Is_Hi then Base_Type := Get_Base_Type (Def); return V = Iir_Int32 @@ -7801,7 +7782,7 @@ package body Translation is declare V : Iir_Int32; begin - V := Iir_Int32 (Get_Physical_Literal_Value (Lit)); + V := Iir_Int32 (Get_Physical_Value (Lit)); if Is_Hi then return V = Iir_Int32'Last; else @@ -7823,7 +7804,7 @@ package body Translation is declare V : Iir_Int64; begin - V := Get_Physical_Literal_Value (Lit); + V := Get_Physical_Value (Lit); if Is_Hi then return V = Iir_Int64'Last; else @@ -8222,17 +8203,16 @@ package body Translation is function Get_Thin_Array_Length (Atype : Iir) return O_Cnode is - Index_List : Iir_List; - Nbr_Dim : Natural; + Indexes_List : constant Iir_List := Get_Index_Subtype_List (Atype); + Nbr_Dim : constant Natural := Get_Nbr_Elements (Indexes_List); + Index : Iir; Val : Iir_Int64; Rng : Iir; begin - Index_List := Get_Index_Subtype_List (Atype); - Nbr_Dim := Get_Nbr_Elements (Index_List); Val := 1; for I in 0 .. Nbr_Dim - 1 loop - Rng := Get_Range_Constraint - (Get_Nth_Element (Index_List, I)); + Index := Get_Index_Type (Indexes_List, I); + Rng := Get_Range_Constraint (Index); Val := Val * Eval_Discrete_Range_Length (Rng); end loop; return New_Unsigned_Literal (Ghdl_Index_Type, Unsigned_64 (Val)); @@ -8241,14 +8221,12 @@ package body Translation is function Bounds_To_Range (B : Mnode; Atype : Iir; Dim : Positive) return Mnode is - Tinfo : Type_Info_Acc; - Index_Type : Iir; - Iinfo : Type_Info_Acc; + Tinfo : constant Type_Info_Acc := Get_Type_Info (B); + Index_Type : constant Iir := + Get_Index_Type (Get_Base_Type (Atype), Dim - 1); + Iinfo : constant Type_Info_Acc := + Get_Info (Get_Base_Type (Index_Type)); begin - Tinfo := Get_Type_Info (B); - Index_Type := Get_Nth_Element - (Get_Index_Subtype_List (Get_Base_Type (Atype)), Dim - 1); - Iinfo := Get_Info (Get_Base_Type (Index_Type)); return Lv2M (New_Selected_Element (M2Lv (B), Tinfo.T.Bounds_Vector (Dim)), Iinfo, @@ -8259,9 +8237,8 @@ package body Translation is function Type_To_Range (Atype : Iir) return Mnode is - Info : Type_Info_Acc; + Info : constant Type_Info_Acc := Get_Info (Atype); begin - Info := Get_Info (Atype); return Varv2M (Info.T.Range_Var, Info, Mode_Value, Info.T.Range_Type, Info.T.Range_Ptr_Type); end Type_To_Range; @@ -8400,20 +8377,17 @@ package body Translation is function Get_Bounds_Ptr_Length (Ptr : O_Dnode; Atype : Iir) return O_Enode is - Index_List : Iir_List; + Index_List : constant Iir_List := Get_Index_Subtype_List (Atype); + Nbr_Dim : constant Natural := Get_Nbr_Elements (Index_List); Index_Type : Iir; - Nbr_Dim : Natural; Dim_Length : O_Enode; Res : O_Enode; - Type_Info : Type_Info_Acc; + Type_Info : constant Type_Info_Acc := + Get_Info (Get_Base_Type (Atype)); Index_Info : Type_Info_Acc; begin - Index_List := Get_Index_Subtype_List (Atype); - Nbr_Dim := Get_Nbr_Elements (Index_List); - - Type_Info := Get_Info (Get_Base_Type (Atype)); for Dim in 1 .. Nbr_Dim loop - Index_Type := Get_Nth_Element (Index_List, Dim - 1); + Index_Type := Get_Index_Type (Index_List, Dim - 1); Index_Info := Get_Info (Get_Base_Type (Index_Type)); Dim_Length := New_Value (New_Selected_Element @@ -8571,15 +8545,12 @@ package body Translation is Is_Sig : Object_Kind_Type) return O_Enode is - Array_Info : Type_Info_Acc; + Array_Info : constant Type_Info_Acc := Get_Info (Array_Type); + Index_Type : constant Iir := Get_Index_Type (Array_Type, Dim - 1); + Index_Info : constant Type_Info_Acc := + Get_Info (Get_Base_Type (Index_Type)); Res : O_Lnode; - Index_Type : Iir; - Index_Info : Type_Info_Acc; begin - Array_Info := Get_Info (Array_Type); - Index_Type := Get_Nth_Element (Get_Index_Subtype_List (Array_Type), - Dim - 1); - Index_Info := Get_Info (Get_Base_Type (Index_Type)); case Array_Info.Type_Mode is when Type_Mode_Array => -- Extract bound variable. @@ -9072,8 +9043,8 @@ package body Translation is R_Indexes := Get_Index_Subtype_List (R_Type); Err := False; for I in Natural loop - L_El := Get_Nth_Element (L_Indexes, I); - R_El := Get_Nth_Element (R_Indexes, I); + L_El := Get_Index_Type (L_Indexes, I); + R_El := Get_Index_Type (R_Indexes, I); exit when L_El = Null_Iir and R_El = Null_Iir; if Eval_Discrete_Type_Length (L_El) /= Eval_Discrete_Type_Length (R_El) @@ -9088,12 +9059,12 @@ package body Translation is else -- Check length match. declare - Index_List : Iir_List; + Index_List : constant Iir_List := + Get_Index_Subtype_List (L_Type); Index : Iir; Cond : O_Enode; Sub_Cond : O_Enode; begin - Index_List := Get_Index_Subtype_List (L_Type); for I in Natural loop Index := Get_Nth_Element (Index_List, I); exit when Index = Null_Iir; @@ -9232,19 +9203,15 @@ package body Translation is procedure Create_Range_From_Length (Index_Type : Iir; Length : O_Dnode; Range_Ptr : O_Dnode; Loc : Iir) is - Iinfo : Type_Info_Acc; + Iinfo : constant Type_Info_Acc := Get_Info (Index_Type); + Range_Constr : constant Iir := Get_Range_Constraint (Index_Type); Op : ON_Op_Kind; Diff : O_Enode; Left_Bound : O_Enode; Var_Right : O_Dnode; If_Blk : O_If_Block; - Range_Constr : Iir; - Range_Expr : Iir; begin - Iinfo := Get_Info (Index_Type); - Range_Constr := Get_Range_Constraint (Index_Type); - Range_Expr := Eval_Range (Range_Constr); - if Range_Expr = Null_Iir then + if Get_Kind (Range_Constr) /= Iir_Kind_Range_Expression then Create_Range_From_Array_Attribute_And_Length (Range_Constr, Length, Range_Ptr); return; @@ -9707,20 +9674,16 @@ package body Translation is -- Generate code to create object OBJ and initialize it with value VAL. procedure Elab_Object_Init (Name : Mnode; Obj : Iir; Value : Iir) is - Obj_Info : Object_Info_Acc; + Obj_Type : constant Iir := Get_Type (Obj); + Type_Info : constant Type_Info_Acc := Get_Info (Obj_Type); + Obj_Info : constant Object_Info_Acc := Get_Info (Obj); Name_Node : Mnode; Value_Node : O_Enode; - Obj_Type : Iir; - Type_Info : Type_Info_Acc; Alloc_Kind : Allocation_Kind; begin -- Elaborate subtype. - Obj_Type := Get_Type (Obj); - Type_Info := Get_Info (Obj_Type); - Obj_Info := Get_Info (Obj); - Alloc_Kind := Get_Alloc_Kind_For_Var (Obj_Info.Object_Var); -- Note: no temporary variable region is created, as the allocation @@ -10242,7 +10205,7 @@ package body Translation is is Info : Ortho_Info_Acc; begin - Info := Get_Info (Get_Base_Name (Sig)); + Info := Get_Info (Get_Object_Prefix (Sig)); return Info.Kind = Kind_Object and then Info.Object_Driver /= null; end Has_Direct_Driver; @@ -10280,26 +10243,24 @@ package body Translation is end Elab_Direct_Driver_Declaration_Storage; -- Create signal object. - -- Note: DECL can be a signal sub-element (used when signals are + -- Note: SIG can be a signal sub-element (used when signals are -- collapsed). -- If CHECK_NULL is TRUE, create the signal only if it was not yet -- created. procedure Elab_Signal_Declaration_Object - (Decl : Iir; Parent : Iir; Check_Null : Boolean) + (Sig : Iir; Parent : Iir; Check_Null : Boolean) is - Sig_Type : Iir; + Decl : constant Iir := Strip_Denoting_Name (Sig); + Sig_Type : constant Iir := Get_Type (Sig); + Base_Decl : constant Iir := Get_Object_Prefix (Sig); Name_Node : Mnode; Val : Iir; Data : Elab_Signal_Data; - Base_Decl : Iir; begin - New_Debug_Line_Stmt (Get_Line_Number (Decl)); + New_Debug_Line_Stmt (Get_Line_Number (Sig)); Open_Temp; - Sig_Type := Get_Type (Decl); - Base_Decl := Get_Base_Name (Decl); - -- Set the name of the signal. declare Assoc : O_Assoc_List; @@ -10563,8 +10524,8 @@ package body Translation is Name := Chap6.Translate_Name (Decl); Open_Kind := Get_File_Open_Kind (Decl); if Open_Kind /= Null_Iir then - Mode_Val := New_Convert_Ov (Chap7.Translate_Expression (Open_Kind), - Ghdl_I32_Type); + Mode_Val := New_Convert_Ov + (Chap7.Translate_Expression (Open_Kind), Ghdl_I32_Type); else case Get_Mode (Decl) is when Iir_In_Mode => @@ -11120,7 +11081,7 @@ package body Translation is El_Type := Get_Element_Subtype (Arr_Type); El_Info := Get_Info (El_Type); - Index_Type := Get_First_Element (Get_Index_Subtype_List (Arr_Type)); + Index_Type := Get_Index_Type (Arr_Type, 0); Index_Tinfo := Get_Info (Index_Type); Start_Subprogram_Body (Rinfo.Resolv_Func); @@ -11300,13 +11261,15 @@ package body Translation is when Iir_Kind_Procedure_Declaration | Iir_Kind_Function_Declaration => -- Translate interfaces. - if not Flag_Discard_Unused or else Get_Use_Flag (El) then + if (not Flag_Discard_Unused or else Get_Use_Flag (El)) + and then not Is_Second_Subprogram_Specification (El) + then Info := Add_Info (El, Kind_Subprg); Chap2.Translate_Subprogram_Interfaces (El); - if Get_Kind (El) = Iir_Kind_Function_Declaration - and then Get_Resolution_Function_Flag (El) - then - Info.Subprg_Resolv := new Subprg_Resolv_Info; + if Get_Kind (El) = Iir_Kind_Function_Declaration then + if Get_Resolution_Function_Flag (El) then + Info.Subprg_Resolv := new Subprg_Resolv_Info; + end if; end if; end if; when Iir_Kind_Function_Body @@ -11565,7 +11528,7 @@ package body Translation is end case; -- FIXME: individual assoc -> overload. Push_Identifier_Prefix - (Mark3, Get_Identifier (Get_Base_Name (Formal))); + (Mark3, Get_Identifier (Get_Association_Interface (Assoc))); -- Handle anonymous subtypes. Chap3.Translate_Anonymous_Type_Definition (Out_Type, False); @@ -11689,7 +11652,7 @@ package body Translation is case Get_Kind (Imp) is when Iir_Kind_Function_Call => - Func := Get_Implementation (Imp); + Func := Get_Named_Entity (Get_Implementation (Imp)); R := Chap7.Translate_Implicit_Conv (R, In_Type, Get_Type (Get_Interface_Declaration_Chain (Func)), @@ -11989,13 +11952,12 @@ package body Translation is procedure Translate_Attribute_Specification (Spec : Iir_Attribute_Specification) is - Attr : Iir_Attribute_Declaration; + Attr : constant Iir_Attribute_Declaration := + Get_Named_Entity (Get_Attribute_Designator (Spec)); + Atinfo : constant Type_Info_Acc := Get_Info (Get_Type (Attr)); Mark : Id_Mark_Type; Info : Object_Info_Acc; - Atinfo : Type_Info_Acc; begin - Attr := Get_Attribute_Designator (Spec); - Atinfo := Get_Info (Get_Type (Attr)); Push_Identifier_Prefix_Uniq (Mark); Info := Add_Info (Spec, Kind_Object); Info.Object_Var := Create_Var @@ -12008,9 +11970,9 @@ package body Translation is procedure Elab_Attribute_Specification (Spec : Iir_Attribute_Specification) is - Attr : Iir_Attribute_Declaration; + Attr : constant Iir_Attribute_Declaration := + Get_Named_Entity (Get_Attribute_Designator (Spec)); begin - Attr := Get_Attribute_Designator (Spec); -- Kludge Set_Info (Attr, Get_Info (Spec)); Chap4.Elab_Object_Value (Attr, Get_Expression (Spec)); @@ -12082,12 +12044,11 @@ package body Translation is (Spec : Iir_Disconnection_Specification) is Val : O_Dnode; - List : Iir_List; + List : constant Iir_List := Get_Signal_List (Spec); El : Iir; begin Val := Create_Temp_Init (Std_Time_Type, Chap7.Translate_Expression (Get_Expression (Spec))); - List := Get_Signal_List (Spec); for I in Natural loop El := Get_Nth_Element (List, I); exit when El = Null_Iir; @@ -12343,15 +12304,6 @@ package body Translation is Obj := Sem_Names.Name_To_Object (Expr); if Obj /= Null_Iir then return Is_Signal_Object (Obj); --- case Get_Kind (Get_Base_Name (Obj)) is --- when Iir_Kind_Signal_Declaration --- | Iir_Kind_Signal_Interface_Declaration --- | Iir_Kind_Guard_Signal_Declaration --- | Iir_Kinds_Signal_Attribute => --- return True; --- when others => --- return False; --- end case; else return False; end if; @@ -12359,8 +12311,11 @@ package body Translation is procedure Elab_Port_Map_Aspect_Assoc (Assoc : Iir; By_Copy : Boolean) is - Formal, Actual : Iir; - Formal_Type, Actual_Type : Iir; + Formal : constant Iir := Get_Formal (Assoc); + Actual : constant Iir := Get_Actual (Assoc); + Formal_Type : constant Iir := Get_Type (Formal); + Actual_Type : constant Iir := Get_Type (Actual); + Inter : constant Iir := Get_Association_Interface (Assoc); Formal_Node, Actual_Node : Mnode; Data : Connect_Data; Mode : Connect_Mode; @@ -12370,10 +12325,6 @@ package body Translation is end if; Open_Temp; - Formal := Get_Formal (Assoc); - Actual := Get_Actual (Assoc); - Formal_Type := Get_Type (Formal); - Actual_Type := Get_Type (Actual); if Get_In_Conversion (Assoc) = Null_Iir and then Get_Out_Conversion (Assoc) = Null_Iir then @@ -12400,7 +12351,7 @@ package body Translation is -- association element that associates an actual -- with S. -- * [...] - case Get_Mode (Get_Base_Name (Formal)) is + case Get_Mode (Inter) is when Iir_In_Mode => Mode := Connect_Effective; when Iir_Inout_Mode => @@ -12522,6 +12473,9 @@ package body Translation is while Assoc /= Null_Iir loop Open_Temp; Formal := Get_Formal (Assoc); + if Get_Kind (Formal) in Iir_Kinds_Denoting_Name then + Formal := Get_Named_Entity (Formal); + end if; case Get_Kind (Assoc) is when Iir_Kind_Association_Element_By_Expression => if Get_Whole_Association_Flag (Assoc) then @@ -12574,7 +12528,7 @@ package body Translation is Assoc := Get_Port_Map_Aspect_Chain (Mapping); while Assoc /= Null_Iir loop Formal := Get_Formal (Assoc); - Formal_Base := Get_Base_Name (Formal); + Formal_Base := Get_Association_Interface (Assoc); Fb_Type := Get_Type (Formal_Base); Open_Temp; @@ -12592,7 +12546,8 @@ package body Translation is Bounds : Mnode; Formal_Node : Mnode; begin - Actual_Type := Get_Type (Get_Default_Value (Formal)); + Actual_Type := + Get_Type (Get_Default_Value (Formal_Base)); Chap3.Create_Array_Subtype (Actual_Type, True); Bounds := Chap3.Get_Array_Type_Bounds (Actual_Type); Formal_Node := Chap6.Translate_Name (Formal); @@ -12720,15 +12675,11 @@ package body Translation is Is_Sig : Object_Kind_Type) return O_Enode is - Tinfo : Type_Info_Acc; - Index_Type : Iir; + Index_Type : constant Iir := Get_Index_Type (Arr_Type, Dim - 1); + Tinfo : constant Type_Info_Acc := Get_Info (Arr_Type); Rinfo : Type_Info_Acc; Constraint : Iir; begin - Index_Type := Get_Nth_Element (Get_Index_Subtype_List (Arr_Type), - Dim - 1); - - Tinfo := Get_Info (Arr_Type); if Tinfo.Type_Locally_Constrained then Constraint := Get_Range_Constraint (Index_Type); return New_Lit (Chap7.Translate_Static_Range_Length (Constraint)); @@ -12998,19 +12949,18 @@ package body Translation is Expr : Iir) return O_Enode is + Index_Range : constant Iir := Get_Range_Constraint (Index_Type); Obound : O_Cnode; Res : O_Dnode; Cond2: O_Enode; Index : O_Enode; Index_Base_Type : Iir; - Index_Range : Iir; V : Iir_Int64; B : Iir_Int64; begin - Index_Range := Get_Range_Constraint (Index_Type); B := Eval_Pos (Get_Left_Limit (Index_Range)); if Get_Expr_Staticness (Expr) = Locally then - V := Eval_Pos (Expr); + V := Eval_Pos (Eval_Static_Expr (Expr)); if Get_Direction (Index_Range) = Iir_To then B := V - B; else @@ -13095,7 +13045,7 @@ package body Translation is Offset := Create_Temp (Ghdl_Index_Type); for Dim in 1 .. Nbr_Dim loop Index := Get_Nth_Element (Index_List, Dim - 1); - Itype := Get_Nth_Element (Type_List, Dim - 1); + Itype := Get_Index_Type (Type_List, Dim - 1); Ibasetype := Get_Base_Type (Itype); Open_Temp; -- Compute index for the current dimension. @@ -13224,8 +13174,7 @@ package body Translation is Slice_Type := Get_Type (Expr); Expr_Range := Get_Suffix (Expr); Prefix_Type := Get_Type (Get_Prefix (Expr)); - Index_Type := Get_Nth_Element - (Get_Index_Subtype_List (Prefix_Type), 0); + Index_Type := Get_Index_Type (Prefix_Type, 0); -- Evaluate slice bounds. Chap3.Create_Array_Subtype (Slice_Type, True); @@ -13252,8 +13201,7 @@ package body Translation is begin Index_Range := Get_Range_Constraint (Index_Type); Prefix_Left := Eval_Pos (Get_Left_Limit (Index_Range)); - Slice_Index_Type := Get_First_Element - (Get_Index_Subtype_List (Slice_Type)); + Slice_Index_Type := Get_Index_Type (Slice_Type, 0); Slice_Range := Get_Range_Constraint (Slice_Index_Type); Slice_Left := Eval_Pos (Get_Left_Limit (Slice_Range)); Slice_Length := Eval_Discrete_Range_Length (Slice_Range); @@ -13623,6 +13571,8 @@ package body Translation is | Iir_Kind_File_Declaration => return Get_Var (Name_Info.Object_Var, Type_Info, Mode_Value); + when Iir_Kind_Attribute_Name => + return Translate_Name (Get_Named_Entity (Name)); when Iir_Kind_Attribute_Value => return Get_Var (Get_Info (Get_Attribute_Specification (Name)).Object_Var, @@ -13703,13 +13653,13 @@ package body Translation is when Iir_Kind_Function_Call => -- This can appear as a prefix of a name, therefore, the - -- result is always a composite type. + -- result is always a composite type or an access type. declare - Imp : Iir; + Imp : constant Iir := + Get_Named_Entity (Get_Implementation (Name)); Obj : Iir; Assoc_Chain : Iir; begin - Imp := Get_Implementation (Name); if Get_Kind (Imp) = Iir_Kind_Implicit_Function_Declaration then -- FIXME : to be done @@ -13741,21 +13691,20 @@ package body Translation is procedure Translate_Direct_Driver (Name : Iir; Sig : out Mnode; Drv : out Mnode) is - Name_Type : Iir; - Name_Info : Ortho_Info_Acc; - Type_Info : Type_Info_Acc; + Name_Type : constant Iir := Get_Type (Name); + Name_Info : constant Ortho_Info_Acc := Get_Info (Name); + Type_Info : constant Type_Info_Acc := Get_Info (Name_Type); begin - Name_Type := Get_Type (Name); - Name_Info := Get_Info (Name); - Type_Info := Get_Info (Name_Type); case Get_Kind (Name) is + when Iir_Kind_Simple_Name + | Iir_Kind_Selected_Name => + Translate_Direct_Driver (Get_Named_Entity (Name), Sig, Drv); + when Iir_Kind_Object_Alias_Declaration => + Translate_Direct_Driver (Get_Name (Name), Sig, Drv); when Iir_Kind_Signal_Declaration | Iir_Kind_Signal_Interface_Declaration => Sig := Get_Var (Name_Info.Object_Var, Type_Info, Mode_Signal); Drv := Get_Var (Name_Info.Object_Driver, Type_Info, Mode_Value); - when Iir_Kind_Simple_Name - | Iir_Kind_Selected_Name => - Translate_Direct_Driver (Get_Named_Entity (Name), Sig, Drv); when Iir_Kind_Slice_Name => declare Data : Slice_Name_Data; @@ -14085,12 +14034,12 @@ package body Translation is Lit_Type : constant Iir := Get_Type (Str); Type_Info : constant Type_Info_Acc := Get_Info (Lit_Type); - Index_Type : Iir; + Index_Type : constant Iir := Get_Index_Type (Lit_Type, 0); + Index_Type_Info : constant Type_Info_Acc := Get_Info (Index_Type); Bound_Aggr : O_Record_Aggr_List; Index_Aggr : O_Record_Aggr_List; Res_Aggr : O_Record_Aggr_List; Res : O_Cnode; - Index_Type_Info : Type_Info_Acc; Len : Int32; Val : Var_Acc; Bound : Var_Acc; @@ -14100,10 +14049,6 @@ package body Translation is Len := Get_String_Length (Str); Val := Create_String_Literal_Var (Str); - Index_Type := - Get_First_Element (Get_Index_Subtype_List (Lit_Type)); - Index_Type_Info := Get_Info (Index_Type); - if Type_Info.Type_Mode = Type_Mode_Fat_Array then -- Create the string bound. Start_Record_Aggr (Bound_Aggr, Type_Info.T.Bounds_Type); @@ -14219,9 +14164,8 @@ package body Translation is begin Str_Type := Get_Type (Str); if Get_Constraint_State (Str_Type) = Fully_Constrained - and then Get_Type_Staticness - (Get_First_Element (Get_Index_Subtype_List (Str_Type))) - = Locally + and then + Get_Type_Staticness (Get_Index_Type (Str_Type, 0)) = Locally then case Get_Kind (Str) is when Iir_Kind_String_Literal => @@ -14312,20 +14256,12 @@ package body Translation is return New_Float_Literal (Res_Type, IEEE_Float_64 (Get_Fp_Value (Expr))); - when Iir_Kind_Physical_Int_Literal => + when Iir_Kind_Physical_Int_Literal + | Iir_Kind_Physical_Fp_Literal + | Iir_Kind_Unit_Declaration => return New_Signed_Literal (Res_Type, Integer_64 (Get_Physical_Value (Expr))); - when Iir_Kind_Unit_Declaration => - return New_Signed_Literal - (Res_Type, - Integer_64 (Get_Value (Get_Physical_Unit_Value (Expr)))); - when Iir_Kind_Physical_Fp_Literal => - return New_Signed_Literal - (Res_Type, - Integer_64 - (Get_Fp_Value (Expr) - * Iir_Fp64 (Get_Value (Get_Physical_Unit_Value - (Get_Unit_Name (Expr)))))); + when others => Error_Kind ("translate_numeric_literal", Expr); end case; @@ -14389,6 +14325,9 @@ package body Translation is return Translate_Static_Implicit_Conv (Translate_Static_Aggregate (Expr), Expr_Type, Res_Type); + when Iir_Kinds_Denoting_Name => + return Translate_Static_Expression + (Get_Named_Entity (Expr), Res_Type); when others => Error_Kind ("translate_static_expression", Expr); end case; @@ -14541,13 +14480,12 @@ package body Translation is end case; end Translate_Range_Length; - function Translate_Association (Assoc : Iir) - return O_Enode + function Translate_Association (Assoc : Iir) return O_Enode is - Actual, Formal : Iir; - Formal_Base : Iir; + Formal : constant Iir := Get_Formal (Assoc); + Formal_Base : constant Iir := Get_Association_Interface (Assoc); + Actual : Iir; begin - Formal := Get_Formal (Assoc); case Get_Kind (Assoc) is when Iir_Kind_Association_Element_By_Expression => Actual := Get_Actual (Assoc); @@ -14557,7 +14495,6 @@ package body Translation is Error_Kind ("translate_association", Assoc); end case; - Formal_Base := Get_Base_Name (Formal); case Get_Kind (Formal_Base) is when Iir_Kind_Constant_Interface_Declaration | Iir_Kind_File_Interface_Declaration => @@ -14579,13 +14516,11 @@ package body Translation is (Imp : Iir; Assoc_Chain : Iir; Obj : Iir) return O_Enode is + Info : constant Subprg_Info_Acc := Get_Info (Imp); Constr : O_Assoc_List; Assoc : Iir; - Info : Subprg_Info_Acc; Res : Mnode; begin - Info := Get_Info (Imp); - if Info.Use_Stack2 then Create_Temp_Stack2_Mark; end if; @@ -14789,15 +14724,17 @@ package body Translation is then -- FIXME: optimize static vs non-static -- constrained to constrained. + -- FIXME: share with check_array_match ? declare - E_List, A_List : Iir_List; + E_List : constant Iir_List := + Get_Index_Subtype_List (Expr_Type); + A_List : constant Iir_List := + Get_Index_Subtype_List (Atype); E_El, A_El : Iir; begin - E_List := Get_Index_Subtype_List (Expr_Type); - A_List := Get_Index_Subtype_List (Atype); for I in Natural loop - E_El := Get_Nth_Element (E_List, I); - A_El := Get_Nth_Element (A_List, I); + E_El := Get_Index_Type (E_List, I); + A_El := Get_Index_Type (A_List, I); exit when E_El = Null_Iir and then A_El = Null_Iir; if Eval_Discrete_Type_Length (E_El) @@ -15920,9 +15857,9 @@ package body Translation is Targ_Index_List := Get_Index_Subtype_List (Target_Type); Aggr_Info := Get_Aggregate_Info (Aggr); for I in Natural loop - Subaggr_Type := Get_Nth_Element (Index_List, I); + Subaggr_Type := Get_Index_Type (Index_List, I); exit when Subaggr_Type = Null_Iir; - Subtarg_Type := Get_Nth_Element (Targ_Index_List, I); + Subtarg_Type := Get_Index_Type (Targ_Index_List, I); Bt := Get_Base_Type (Subaggr_Type); Rinfo := Get_Info (Bt); @@ -16118,26 +16055,23 @@ package body Translation is function Translate_Allocator_By_Subtype (Expr : Iir) return O_Enode is + P_Type : constant Iir := Get_Type (Expr); + P_Info : constant Type_Info_Acc := Get_Info (P_Type); + D_Type : constant Iir := Get_Designated_Type (P_Type); + D_Info : constant Type_Info_Acc := Get_Info (D_Type); Sub_Type : Iir; Bounds : O_Enode; Res : Mnode; Rtype : O_Tnode; - P_Type : Iir; - P_Info : Type_Info_Acc; - D_Type : Iir; - D_Info : Type_Info_Acc; - begin - P_Type := Get_Type (Expr); - P_Info := Get_Info (P_Type); - D_Type := Get_Designated_Type (P_Type); - D_Info := Get_Info (D_Type); + begin case P_Info.Type_Mode is when Type_Mode_Fat_Acc => Res := Dv2M (Create_Temp (D_Info.Ortho_Type (Mode_Value)), D_Info, Mode_Value); -- FIXME: should allocate bounds, and directly set bounds -- from the range. - Sub_Type := Get_Expression (Expr); + Sub_Type := Get_Subtype_Indication (Expr); + Sub_Type := Get_Type_Of_Subtype_Indication (Sub_Type); Chap3.Create_Array_Subtype (Sub_Type, True); Bounds := M2E (Chap3.Get_Array_Type_Bounds (Sub_Type)); Rtype := P_Info.Ortho_Ptr_Type (Mode_Value); @@ -16286,23 +16220,22 @@ package body Translation is Res_Indexes := Get_Index_Subtype_List (Res_Type); Expr_Indexes := Get_Index_Subtype_List (Expr_Type); for I in Natural loop - R_El := Get_Nth_Element (Res_Indexes, I); - E_El := Get_Nth_Element (Expr_Indexes, I); + R_El := Get_Index_Type (Res_Indexes, I); + E_El := Get_Index_Type (Expr_Indexes, I); exit when R_El = Null_Iir; declare Rb_Ptr : O_Dnode; Eb_Ptr : O_Dnode; - Rr_Info : Type_Info_Acc; - Er_Info : Type_Info_Acc; + Rr_Info : constant Type_Info_Acc := Get_Info (R_El); + Er_Info : constant Type_Info_Acc := + Get_Info (Get_Base_Type (E_El)); begin Open_Temp; - Rr_Info := Get_Info (R_El); Rb_Ptr := Create_Temp_Init (Rr_Info.T.Range_Ptr_Type, Chap3.Get_Array_Ptr_Range_Ptr (New_Obj (Res_Ptr), Res_Type, I + 1, Mode_Value)); - Er_Info := Get_Info (Get_Base_Type (E_El)); Eb_Ptr := Create_Temp_Init (Er_Info.T.Range_Ptr_Type, Chap3.Get_Array_Ptr_Range_Ptr (New_Obj (E), Expr_Type, I + 1, @@ -16523,7 +16456,7 @@ package body Translation is renames Translate_Signal_Assign_Driving; function Translate_Expression (Expr : Iir; Rtype : Iir := Null_Iir) - return O_Enode + return O_Enode is Imp : Iir; Expr_Type : Iir; @@ -16701,6 +16634,9 @@ package body Translation is end if; end; + when Iir_Kind_Parenthesis_Expression => + return Translate_Expression (Get_Expression (Expr), Rtype); + when Iir_Kind_Allocator_By_Expression => return Translate_Allocator_By_Expression (Expr); when Iir_Kind_Allocator_By_Subtype => @@ -16729,7 +16665,8 @@ package body Translation is | Iir_Kind_Delayed_Attribute | Iir_Kind_Transaction_Attribute | Iir_Kind_Guard_Signal_Declaration - | Iir_Kind_Attribute_Value => + | Iir_Kind_Attribute_Value + | Iir_Kind_Attribute_Name => declare L : Mnode; begin @@ -16773,7 +16710,7 @@ package body Translation is (Imp, Get_Operand (Expr), Null_Iir, Res_Type); end if; when Iir_Kind_Function_Call => - Imp := Get_Implementation (Expr); + Imp := Get_Named_Entity (Get_Implementation (Expr)); declare Assoc_Chain : Iir; begin @@ -17164,6 +17101,8 @@ package body Translation is return O_Lnode is begin case Get_Kind (Arange) is + when Iir_Kinds_Denoting_Name => + return Translate_Range (Get_Named_Entity (Arange), Range_Type); when Iir_Kind_Subtype_Declaration => -- Must be a scalar subtype. Range of types is static. return Get_Var (Get_Info (Get_Type (Arange)).T.Range_Var); @@ -17654,7 +17593,7 @@ package body Translation is return; end if; - Index_Type := Get_First_Element (Get_Index_Subtype_List (Arr_Type)); + Index_Type := Get_Index_Type (Arr_Type, 0); Iinfo := Get_Info (Index_Type); Index_Otype := Iinfo.Ortho_Type (Mode_Value); @@ -18498,7 +18437,7 @@ package body Translation is Var : Mnode; begin - Etype := Get_Type_Mark (File_Type); + Etype := Get_Type (Get_File_Type_Mark (File_Type)); Tinfo := Get_Info (Etype); if Tinfo.Type_Mode in Type_Mode_Scalar then -- Intrinsic. @@ -19119,11 +19058,11 @@ package body Translation is procedure Translate_For_Loop_Statement (Stmt : Iir_For_Loop_Statement) is - Iterator : Iir; + Iterator : constant Iir := Get_Parameter_Specification (Stmt); + Iter_Type : constant Iir := Get_Type (Iterator); + Iter_Base_Type : constant Iir := Get_Base_Type (Iter_Type); + Iter_Type_Info : constant Type_Info_Acc := Get_Info (Iter_Base_Type); Data : For_Loop_Data; - Iter_Type : Iir; - Iter_Base_Type : Iir; - Iter_Type_Info : Type_Info_Acc; It_Info : Ortho_Info_Acc; Var_Iter : Var_Acc; Prev_Loop : Iir; @@ -19131,10 +19070,6 @@ package body Translation is Prev_Loop := Current_Loop; Current_Loop := Stmt; Start_Declare_Stmt; - Iterator := Get_Iterator_Scheme (Stmt); - Iter_Type := Get_Type (Iterator); - Iter_Base_Type := Get_Base_Type (Iter_Type); - Iter_Type_Info := Get_Info (Iter_Base_Type); Chap3.Translate_Object_Subtype (Iterator, False); @@ -19191,19 +19126,23 @@ package body Translation is procedure Translate_Exit_Next_Statement (Stmt : Iir) is - Cond : Iir; + Cond : constant Iir := Get_Condition (Stmt); If_Blk : O_If_Block; Info : Loop_Info_Acc; + Loop_Label : Iir; Loop_Stmt : Iir; begin - Cond := Get_Condition (Stmt); if Cond /= Null_Iir then Start_If_Stmt (If_Blk, Chap7.Translate_Expression (Cond)); end if; - Loop_Stmt := Get_Loop (Stmt); - if Loop_Stmt = Null_Iir then + + Loop_Label := Get_Loop_Label (Stmt); + if Loop_Label = Null_Iir then Loop_Stmt := Current_Loop; + else + Loop_Stmt := Get_Named_Entity (Loop_Label); end if; + Info := Get_Info (Loop_Stmt); case Get_Kind (Stmt) is when Iir_Kind_Exit_Statement => @@ -19411,7 +19350,7 @@ package body Translation is if Get_Expr_Staticness (Expr) = Locally then if Eval_Pos (Expr) = 1 then -- Assert TRUE is a noop. - -- FIXME: generate a noop. + -- FIXME: generate a noop ? return; end if; Translate_Report (Stmt, Ghdl_Assert_Failed, Severity_Level_Error); @@ -20137,13 +20076,11 @@ package body Translation is procedure Translate_Implicit_Procedure_Call (Call : Iir_Procedure_Call) is - Kind : Iir_Predefined_Functions; - Imp : Iir; - Param_Chain : Iir; + Imp : constant Iir := Get_Named_Entity (Get_Implementation (Call)); + Kind : constant Iir_Predefined_Functions := + Get_Implicit_Definition (Imp); + Param_Chain : constant Iir := Get_Parameter_Association_Chain (Call); begin - Imp := Get_Implementation (Call); - Kind := Get_Implicit_Definition (Imp); - Param_Chain := Get_Parameter_Association_Chain (Call); case Kind is when Iir_Predefined_Write => -- Check wether text or not. @@ -20325,7 +20262,7 @@ package body Translation is case Get_Kind (Conv) is when Iir_Kind_Function_Call => -- Call conversion function. - Imp := Get_Implementation (Conv); + Imp := Get_Named_Entity (Get_Implementation (Conv)); Conv_Info := Get_Info (Imp); Start_Association (Constr, Conv_Info.Ortho_Func); @@ -20369,7 +20306,7 @@ package body Translation is Iir_Chains.Get_Chain_Length (Assoc_Chain); Params : Mnode_Array (0 .. Nbr_Assoc - 1); E_Params : O_Enode_Array (0 .. Nbr_Assoc - 1); - Imp : constant Iir := Get_Implementation (Stmt); + Imp : constant Iir := Get_Named_Entity (Get_Implementation (Stmt)); Info : constant Subprg_Info_Acc := Get_Info (Imp); Res : O_Dnode; El : Iir; @@ -20413,7 +20350,10 @@ package body Translation is E_Params (Pos) := O_Enode_Null; Formal := Get_Formal (El); - Base_Formal := Get_Base_Name (Formal); + if Get_Kind (Formal) in Iir_Kinds_Denoting_Name then + Formal := Get_Named_Entity (Formal); + end if; + Base_Formal := Get_Association_Interface (El); Formal_Type := Get_Type (Formal); Formal_Info := Get_Info (Base_Formal); if Get_Kind (Base_Formal) = Iir_Kind_Signal_Interface_Declaration @@ -20573,7 +20513,10 @@ package body Translation is Pos := 0; while El /= Null_Iir loop Formal := Get_Formal (El); - Base_Formal := Get_Base_Name (Formal); + if Get_Kind (Formal) in Iir_Kinds_Denoting_Name then + Formal := Get_Named_Entity (Formal); + end if; + Base_Formal := Get_Association_Interface (El); Formal_Info := Get_Info (Base_Formal); Formal_Type := Get_Type (Formal); Ftype_Info := Get_Info (Formal_Type); @@ -20639,7 +20582,7 @@ package body Translation is Pos := 0; while El /= Null_Iir loop Formal := Get_Formal (El); - Base_Formal := Get_Base_Name (Formal); + Base_Formal := Get_Association_Interface (El); Formal_Type := Get_Type (Formal); Ftype_Info := Get_Info (Formal_Type); Formal_Info := Get_Info (Base_Formal); @@ -21151,14 +21094,13 @@ package body Translation is Idx : O_Dnode; Dim : Natural) is + Index_List : constant Iir_List := + Get_Index_Subtype_List (Target_Type); + Nbr_Dim : constant Natural := Get_Nbr_Elements (Index_List); Sub_Aggr : Mnode; El : Iir; - Index_List : Iir_List; - Nbr_Dim : Natural; Expr : Iir; begin - Index_List := Get_Index_Subtype_List (Target_Type); - Nbr_Dim := Get_Nbr_Elements (Index_List); El := Get_Association_Choices_Chain (Target); while El /= Null_Iir loop case Get_Kind (El) is @@ -21383,20 +21325,17 @@ package body Translation is procedure Translate_Direct_Signal_Assignment (Stmt : Iir; We : Iir) is - Target : Iir; - Target_Type : Iir; + Target : constant Iir := Get_Target (Stmt); + Target_Type : constant Iir := Get_Type (Target); Arg : Signal_Direct_Assign_Data; Targ_Sig : Mnode; begin - Target := Get_Target (Stmt); - Target_Type := Get_Type (Target); Chap6.Translate_Direct_Driver (Target, Targ_Sig, Arg.Drv); Arg.Expr := E2M (Chap7.Translate_Expression (We, Target_Type), Get_Info (Target_Type), Mode_Value); Arg.Expr_Node := We; Gen_Signal_Direct_Assign (Targ_Sig, Target_Type, Arg); - return; end Translate_Direct_Signal_Assignment; procedure Translate_Signal_Assignment_Statement (Stmt : Iir) @@ -21603,15 +21542,11 @@ package body Translation is when Iir_Kind_Procedure_Call_Statement => declare - Assocs : Iir; - pragma Unreferenced (Assocs); -- FIXME - Call : Iir_Procedure_Call; - Imp : Iir; + Call : constant Iir := Get_Procedure_Call (Stmt); + Imp : constant Iir := + Get_Named_Entity (Get_Implementation (Call)); begin - Call := Get_Procedure_Call (Stmt); Canon.Canon_Subprogram_Call (Call); - Assocs := Get_Parameter_Association_Chain (Call); - Imp := Get_Implementation (Call); if Get_Kind (Imp) = Iir_Kind_Implicit_Procedure_Declaration then Translate_Implicit_Procedure_Call (Call); @@ -21669,8 +21604,8 @@ package body Translation is begin for I in Drivers.all'Range loop Var := Drivers (I).Var; - Sig := Get_Base_Name (Drivers (I).Sig); if Var /= null then + Sig := Get_Object_Prefix (Drivers (I).Sig); Info := Get_Info (Sig); case Info.Kind is when Kind_Object => @@ -21694,8 +21629,8 @@ package body Translation is begin for I in Drivers.all'Range loop Var := Drivers (I).Var; - Sig := Get_Base_Name (Drivers (I).Sig); if Var /= null then + Sig := Get_Object_Prefix (Drivers (I).Sig); Info := Get_Info (Sig); case Info.Kind is when Kind_Object => @@ -21775,9 +21710,9 @@ package body Translation is begin Info := Add_Info (Inst, Kind_Block); Info.Block_Decls_Type := O_Tnode_Null; - if Get_Kind (Comp) = Iir_Kind_Component_Declaration then + if Get_Kind (Comp) in Iir_Kinds_Denoting_Name then -- Via a component declaration. - Comp_Info := Get_Info (Comp); + Comp_Info := Get_Info (Get_Named_Entity (Comp)); Info.Block_Link_Field := Add_Instance_Factory_Field (Create_Identifier_Without_Prefix (Inst), Comp_Info.Comp_Type); @@ -21812,7 +21747,7 @@ package body Translation is -- formal. Push_Identifier_Prefix (Mark2, - Get_Identifier (Get_Base_Name (Get_Formal (Assoc)))); + Get_Identifier (Get_Association_Interface (Assoc))); Chap3.Translate_Type_Definition (In_Type, True); Pop_Identifier_Prefix (Mark2); end if; @@ -21860,7 +21795,7 @@ package body Translation is for I in 1 .. Nbr_Drivers loop Sig := Get_Nth_Element (Drivers, I - 1); Info.Process_Drivers (I) := (Sig => Sig, Var => null); - Sig := Get_Base_Name (Sig); + Sig := Get_Object_Prefix (Sig); if Get_Kind (Sig) /= Iir_Kind_Object_Alias_Declaration and then not Get_After_Drivers_Flag (Sig) then @@ -22437,12 +22372,13 @@ package body Translation is end if; Comp := Get_Instantiated_Unit (Stmt); - if Get_Kind (Comp) /= Iir_Kind_Component_Declaration then + if Get_Kind (Comp) not in Iir_Kinds_Denoting_Name then -- This is a direct instantiation. Set_Component_Link (Parent_Info.Block_Decls_Type, Info.Block_Link_Field); Translate_Entity_Instantiation (Comp, Stmt, Stmt, Null_Iir); else + Comp := Get_Named_Entity (Comp); Comp_Info := Get_Info (Comp); Push_Scope (Comp_Info.Comp_Type, Info.Block_Link_Field, Parent_Info.Block_Decls_Type); @@ -22608,6 +22544,8 @@ package body Translation is | Iir_Kind_Signal_Interface_Declaration | Iir_Kind_Guard_Signal_Declaration => exit; + when Iir_Kinds_Denoting_Name => + El := Get_Named_Entity (El); when others => Error_Kind ("destroy_types_in_name", El); end case; @@ -22795,7 +22733,7 @@ package body Translation is for I in Info.Process_Drivers.all'Range loop Sig := Info.Process_Drivers (I).Sig; Open_Temp; - Base := Get_Base_Name (Sig); + Base := Get_Object_Prefix (Sig); if Info.Process_Drivers (I).Var /= null then -- Elaborate direct driver. Done only once. Chap4.Elab_Direct_Driver_Declaration_Storage (Base); @@ -24496,18 +24434,18 @@ package body Translation is package body Chap14 is function Translate_Array_Attribute_To_Range (Expr : Iir) return Mnode is - Prefix : Iir; + Prefix : constant Iir := Get_Prefix (Expr); + Type_Name : constant Iir := Is_Type_Name (Prefix); Arr : Mnode; Dim : Natural; begin - Prefix := Get_Prefix (Expr); - case Get_Kind (Prefix) is - when Iir_Kind_Type_Declaration - | Iir_Kind_Subtype_Declaration => - Arr := T2M (Get_Type_Of_Type_Mark (Prefix), Mode_Value); - when others => - Arr := Chap6.Translate_Name (Prefix); - end case; + if Type_Name /= Null_Iir then + -- Prefix denotes a type name + Arr := T2M (Type_Name, Mode_Value); + else + -- Prefix is an object. + Arr := Chap6.Translate_Name (Prefix); + end if; Dim := Natural (Get_Value (Get_Parameter (Expr))); return Chap3.Get_Array_Range (Arr, Get_Type (Prefix), Dim); end Translate_Array_Attribute_To_Range; @@ -24723,7 +24661,7 @@ package body Translation is New_Assign_Stmt (New_Obj (Res_Var), New_Convert_Ov (Val, Res_Type)); Chap3.Check_Range - (Res_Var, Attr, Get_Type_Of_Type_Mark (Get_Prefix (Attr)), Attr); + (Res_Var, Attr, Get_Type (Get_Prefix (Attr)), Attr); return New_Obj_Value (Res_Var); end Translate_Val_Attribute; @@ -25245,16 +25183,14 @@ package body Translation is function Translate_Image_Attribute (Attr : Iir) return O_Enode is - Prefix_Type : Iir; - Pinfo : Type_Info_Acc; + Prefix_Type : constant Iir := + Get_Base_Type (Get_Type (Get_Prefix (Attr))); + Pinfo : constant Type_Info_Acc := Get_Info (Prefix_Type); Res : O_Dnode; Subprg : O_Dnode; Assoc : O_Assoc_List; Conv : O_Tnode; begin - Prefix_Type := - Get_Base_Type (Get_Type_Of_Type_Mark (Get_Prefix (Attr))); - Pinfo := Get_Info (Prefix_Type); Res := Create_Temp (Std_String_Node); Create_Temp_Stack2_Mark; case Pinfo.Type_Mode is @@ -25310,14 +25246,12 @@ package body Translation is function Translate_Value_Attribute (Attr : Iir) return O_Enode is - Prefix_Type : Iir; - Pinfo : Type_Info_Acc; + Prefix_Type : constant Iir := + Get_Base_Type (Get_Type (Get_Prefix (Attr))); + Pinfo : constant Type_Info_Acc := Get_Info (Prefix_Type); Subprg : O_Dnode; Assoc : O_Assoc_List; begin - Prefix_Type := - Get_Base_Type (Get_Type_Of_Type_Mark (Get_Prefix (Attr))); - Pinfo := Get_Info (Prefix_Type); case Pinfo.Type_Mode is when Type_Mode_B2 => Subprg := Ghdl_Value_B2; @@ -26595,7 +26529,7 @@ package body Translation is -- loops. Base_Type := Null_Iir; when Iir_Kind_File_Type_Definition => - Base_Type := Get_Type_Mark (Atype); + Base_Type := Get_Type (Get_File_Type_Mark (Atype)); Base := Generate_Type_Definition (Base_Type); Kind := Ghdl_Rtik_Type_File; when Iir_Kind_Record_Subtype_Definition => @@ -26629,8 +26563,8 @@ package body Translation is procedure Generate_Array_Type_Indexes (Atype : Iir; Res : out O_Dnode; Max_Depth : in out Rti_Depth_Type) is - List : Iir_List; - Nbr_Indexes : Integer; + List : constant Iir_List := Get_Index_Subtype_List (Atype); + Nbr_Indexes : constant Natural := Get_Nbr_Elements (List); Index : Iir; Tmp : O_Dnode; pragma Unreferenced (Tmp); @@ -26640,10 +26574,8 @@ package body Translation is Mark : Id_Mark_Type; begin -- Translate each index. - List := Get_Index_Subtype_List (Atype); - Nbr_Indexes := Get_Nbr_Elements (List); for I in 1 .. Nbr_Indexes loop - Index := Get_Nth_Element (List, I - 1); + Index := Get_Index_Type (List, I - 1); Push_Identifier_Prefix (Mark, "DIM", Iir_Int32 (I)); Tmp := Generate_Type_Definition (Index); Max_Depth := Rti_Depth_Type'Max (Max_Depth, @@ -26660,8 +26592,8 @@ package body Translation is Start_Const_Value (Res); Start_Array_Aggr (Arr_Aggr, Arr_Type); - for I in 0 .. Nbr_Indexes - 1 loop - Index := Get_Nth_Element (List, I); + for I in 1 .. Nbr_Indexes loop + Index := Get_Index_Type (List, I - 1); New_Array_Aggr_El (Arr_Aggr, New_Rti_Address (Generate_Type_Definition (Index))); end loop; @@ -26962,9 +26894,8 @@ package body Translation is function Generate_Type_Definition (Atype : Iir; Force : Boolean := False) return O_Dnode is - Info : Type_Info_Acc; + Info : constant Type_Info_Acc := Get_Info (Atype); begin - Info := Get_Info (Atype); if not Force and then Info.Type_Rti /= O_Dnode_Null then return Info.Type_Rti; end if; @@ -27005,12 +26936,10 @@ package body Translation is function Generate_Incomplete_Type_Definition (Def : Iir) return O_Dnode is - Ndef : Iir; - Info : Type_Info_Acc; + Ndef : constant Iir := Get_Type (Get_Type_Declarator (Def)); + Info : constant Type_Info_Acc := Get_Info (Ndef); Rti_Type : O_Tnode; begin - Ndef := Get_Type_Of_Type_Mark (Get_Type_Declarator (Def)); - Info := Get_Info (Ndef); case Get_Kind (Ndef) is when Iir_Kind_Integer_Type_Definition | Iir_Kind_Floating_Type_Definition => @@ -27043,14 +26972,12 @@ package body Translation is function Generate_Type_Decl (Decl : Iir) return O_Dnode is + Id : constant Name_Id := Get_Identifier (Decl); + Def : constant Iir := Get_Type (Decl); Rti : O_Dnode; Mark : Id_Mark_Type; - Id : Name_Id; - Def : Iir; begin - Id := Get_Identifier (Decl); Push_Identifier_Prefix (Mark, Id); - Def := Get_Type_Of_Type_Mark (Decl); if Get_Kind (Def) = Iir_Kind_Incomplete_Type_Definition then Rti := Generate_Incomplete_Type_Definition (Def); else @@ -27361,8 +27288,9 @@ package body Translation is Ghdl_Ptr_Type)); New_Record_Aggr_El (List, New_Rti_Address (Parent)); case Get_Kind (Inst) is - when Iir_Kind_Component_Declaration => - Val := New_Rti_Address (Get_Info (Inst).Comp_Rti_Const); + when Iir_Kinds_Denoting_Name => + Val := New_Rti_Address + (Get_Info (Get_Named_Entity (Inst)).Comp_Rti_Const); when Iir_Kind_Entity_Aspect_Entity => declare Ent : constant Iir := Get_Entity (Inst); @@ -29485,7 +29413,7 @@ package body Translation is Push_Identifier_Prefix (Unit_Mark, Get_Identifier (Standard_Package)); - Chap4.Translate_Bool_Type_Declaration (Boolean_Type); + Chap4.Translate_Bool_Type_Declaration (Boolean_Type_Declaration); -- We need this type very early, for predefined functions. Std_Boolean_Type_Node := Get_Ortho_Type (Boolean_Type_Definition, Mode_Value); @@ -29496,35 +29424,41 @@ package body Translation is New_Array_Type (Std_Boolean_Type_Node, Ghdl_Index_Type); New_Type_Decl (Create_Identifier ("BOOLEAN_ARRAY"), Std_Boolean_Array_Type); - Chap4.Translate_Bool_Type_Declaration (Bit_Type); + Chap4.Translate_Bool_Type_Declaration (Bit_Type_Declaration); - Chap4.Translate_Type_Declaration (Character_Type); + Chap4.Translate_Type_Declaration (Character_Type_Declaration); - Chap4.Translate_Type_Declaration (Severity_Level_Type); + Chap4.Translate_Type_Declaration (Severity_Level_Type_Declaration); - Chap4.Translate_Anonymous_Type_Declaration (Universal_Integer_Type); - Chap4.Translate_Subtype_Declaration (Universal_Integer_Subtype); + Chap4.Translate_Anonymous_Type_Declaration + (Universal_Integer_Type_Declaration); + Chap4.Translate_Subtype_Declaration + (Universal_Integer_Subtype_Declaration); - Chap4.Translate_Anonymous_Type_Declaration (Universal_Real_Type); - Chap4.Translate_Subtype_Declaration (Universal_Real_Subtype); + Chap4.Translate_Anonymous_Type_Declaration + (Universal_Real_Type_Declaration); + Chap4.Translate_Subtype_Declaration + (Universal_Real_Subtype_Declaration); - Chap4.Translate_Anonymous_Type_Declaration (Convertible_Integer_Type); - Chap4.Translate_Anonymous_Type_Declaration (Convertible_Real_Type); + Chap4.Translate_Anonymous_Type_Declaration + (Convertible_Integer_Type_Declaration); + Chap4.Translate_Anonymous_Type_Declaration + (Convertible_Real_Type_Declaration); - Translate_Std_Type_Declaration (Real_Type); + Translate_Std_Type_Declaration (Real_Type_Declaration); Std_Real_Type_Node := Get_Ortho_Type (Real_Type_Definition, Mode_Value); - Chap4.Translate_Subtype_Declaration (Real_Subtype); + Chap4.Translate_Subtype_Declaration (Real_Subtype_Declaration); - Translate_Std_Type_Declaration (Integer_Type); + Translate_Std_Type_Declaration (Integer_Type_Declaration); Std_Integer_Type_Node := Get_Ortho_Type (Integer_Type_Definition, Mode_Value); - Chap4.Translate_Subtype_Declaration (Integer_Subtype); - Chap4.Translate_Subtype_Declaration (Natural_Subtype); - Chap4.Translate_Subtype_Declaration (Positive_Subtype); + Chap4.Translate_Subtype_Declaration (Integer_Subtype_Declaration); + Chap4.Translate_Subtype_Declaration (Natural_Subtype_Declaration); + Chap4.Translate_Subtype_Declaration (Positive_Subtype_Declaration); - Translate_Std_Type_Declaration (String_Type); + Translate_Std_Type_Declaration (String_Type_Declaration); - Translate_Std_Type_Declaration (Bit_Vector_Type); + Translate_Std_Type_Declaration (Bit_Vector_Type_Declaration); declare Type_Staticness : Iir_Staticness; @@ -29543,12 +29477,13 @@ package body Translation is end if; Set_Type_Staticness (Time_Subtype_Definition, Locally); - Translate_Std_Type_Declaration (Time_Type); - Chap4.Translate_Subtype_Declaration (Time_Subtype); + Translate_Std_Type_Declaration (Time_Type_Declaration); + Chap4.Translate_Subtype_Declaration (Time_Subtype_Declaration); if Flags.Vhdl_Std > Vhdl_87 then Set_Type_Staticness (Delay_Length_Subtype_Definition, Locally); - Chap4.Translate_Subtype_Declaration (Delay_Length_Subtype); + Chap4.Translate_Subtype_Declaration + (Delay_Length_Subtype_Declaration); Set_Type_Staticness (Delay_Length_Subtype_Definition, Subtype_Staticness); end if; @@ -29559,8 +29494,8 @@ package body Translation is Std_Time_Type := Get_Ortho_Type (Time_Type_Definition, Mode_Value); if Flags.Vhdl_Std > Vhdl_87 then - Translate_Std_Type_Declaration (File_Open_Kind_Type); - Translate_Std_Type_Declaration (File_Open_Status_Type); + Translate_Std_Type_Declaration (File_Open_Kind_Type_Declaration); + Translate_Std_Type_Declaration (File_Open_Status_Type_Declaration); Std_File_Open_Status_Type := Get_Ortho_Type (File_Open_Status_Type_Definition, Mode_Value); end if; @@ -29916,6 +29851,12 @@ package body Translation is when Iir_Kind_Function_Declaration | Iir_Kind_Procedure_Declaration => -- Generate empty body. + + -- Never a second spec, as this is within a package + -- declaration. + pragma Assert + (not Is_Second_Subprogram_Specification (Decl)); + if not Get_Foreign_Flag (Decl) then declare Mark : Id_Mark_Type; @@ -68,6 +68,16 @@ package body Xrefs is procedure Add_Xref (Loc : Location_Type; Ref : Iir; Kind : Xref_Kind) is begin + -- Check there is no xref for the same location to the same reference. + -- (Note that a designatore may reference several declarations, this + -- is possible in attribute specification for an overloadable name). + -- This is a simple heuristic as this catch only two referenced in the + -- row but efficient and should be enough to catch errors. + pragma Assert + (Xref_Table.Last < Xref_Table.First + or else Xref_Table.Table (Xref_Table.Last).Loc /= Loc + or else Xref_Table.Table (Xref_Table.Last).Ref /= Ref); + Xref_Table.Append (Xref_Type'(Loc => Loc, Ref => Ref, Kind => Kind)); @@ -101,27 +111,37 @@ package body Xrefs is end if; end Xref_End; - procedure Xref_Name_1 (Name : Iir) - is - Res : Iir; + procedure Xref_Name_1 (Name : Iir) is begin case Get_Kind (Name) is when Iir_Kind_Simple_Name | Iir_Kind_Selected_Name | Iir_Kind_Operator_Symbol | Iir_Kind_Character_Literal => - Res := Get_Named_Entity (Name); - if Res = Std_Package.Error_Mark then - return; - end if; - Add_Xref (Get_Location (Name), Res, Xref_Ref); - when Iir_Kind_Parenthesis_Name - | Iir_Kind_Selected_By_All_Name - | Iir_Kind_Slice_Name => + declare + Res : constant Iir := Get_Named_Entity (Name); + begin + if Res = Std_Package.Error_Mark then + return; + end if; + Add_Xref (Get_Location (Name), Res, Xref_Ref); + end; + when Iir_Kind_Selected_Element => + Add_Xref (Get_Location (Name), + Get_Selected_Element (Name), Xref_Ref); + when Iir_Kind_Dereference + | Iir_Kind_Implicit_Dereference + | Iir_Kind_Slice_Name + | Iir_Kind_Indexed_Name + | Iir_Kind_Function_Call => + null; + when Iir_Kinds_Attribute => null; when Iir_Kind_Attribute_Name => -- FIXME: user defined attributes. null; + when Iir_Kind_Type_Conversion => + return; when others => Error_Kind ("xref_name_1", Name); end case; @@ -131,10 +151,14 @@ package body Xrefs is | Iir_Kind_Character_Literal => null; when Iir_Kind_Selected_Name - | Iir_Kind_Parenthesis_Name + | Iir_Kind_Selected_Element | Iir_Kind_Attribute_Name | Iir_Kind_Slice_Name - | Iir_Kind_Selected_By_All_Name => + | Iir_Kind_Indexed_Name + | Iir_Kind_Dereference + | Iir_Kind_Implicit_Dereference + | Iir_Kinds_Attribute + | Iir_Kind_Function_Call => Xref_Name_1 (Get_Prefix (Name)); when others => Error_Kind ("xref_name_1", Name); @@ -157,9 +181,12 @@ package body Xrefs is Xref_Table.Table (From) := Tmp; end Move; - function Loc_Lt (Op1, Op2 : Natural) return Boolean is + function Loc_Lt (Op1, Op2 : Natural) return Boolean + is + L1 : constant Location_Type := Xref_Table.Table (Op1).Loc; + L2 : constant Location_Type := Xref_Table.Table (Op2).Loc; begin - return Xref_Table.Table (Op1).Loc < Xref_Table.Table (Op2).Loc; + return L1 < L2; end Loc_Lt; procedure Sort_By_Location is @@ -250,4 +277,3 @@ package body Xrefs is end loop; end Fix_End_Xrefs; end Xrefs; - diff --git a/xtools/Makefile b/xtools/Makefile index 1c4d5b46d..e1546ec20 100644 --- a/xtools/Makefile +++ b/xtools/Makefile @@ -17,7 +17,7 @@ all: ../iirs.adb check_iirs: force - gnatmake -g check_iirs + gnatmake -g -gnatwa check_iirs MODE=--generate diff --git a/xtools/check_iirs_pkg.adb b/xtools/check_iirs_pkg.adb index 72781bbb3..219c13276 100644 --- a/xtools/check_iirs_pkg.adb +++ b/xtools/check_iirs_pkg.adb @@ -43,83 +43,82 @@ package body Check_Iirs_Pkg is -- Patterns -- Space. - Wsp : Pattern := Span (' '); + Wsp : constant Pattern := Span (' '); -- "type Iir_Kind is". - Type_Iir_Kind_Pat : Pattern := + Type_Iir_Kind_Pat : constant Pattern := Wsp & "type" & Wsp & "Iir_Kind" & Wsp & "is" & Rpos (0); -- "(" - Lparen_Pat : Pattern := Wsp & '(' & Rpos (0); + Lparen_Pat : constant Pattern := Wsp & '(' & Rpos (0); -- Comment. - Comment_Pat : Pattern := Wsp & "--"; + Comment_Pat : constant Pattern := Wsp & "--"; -- End of ada line - Eol_Pat : Pattern := Comment_Pat or Rpos (0); - - -- "," followed by EOL. - Comma_Eol_Pat : Pattern := ',' & Eol_Pat; + Eol_Pat : constant Pattern := Comment_Pat or Rpos (0); -- A-Za-z - Basic_Pat : Pattern := Span (Basic_Set); + Basic_Pat : constant Pattern := Span (Basic_Set); -- A-Za-z0-9 - Alnum_Pat : Pattern := Span (Alphanumeric_Set); + Alnum_Pat : constant Pattern := Span (Alphanumeric_Set); -- Ada identifier. - Ident_Pat : Pattern := Basic_Pat & Arbno (('_' or "") & Alnum_Pat); + Ident_Pat : constant Pattern := Basic_Pat & Arbno (('_' or "") & Alnum_Pat); -- Basic_Pat & Arbno (Alnum_Pat) & Arbno ('_' & Alnum_Pat); -- Eat the ada identifier. - Getident_Pat : Pattern := Ident_Pat * Ident; - Getident2_Pat : Pattern := Ident_Pat * Ident_2; - Getident3_Pat : Pattern := Ident_Pat * Ident_3; - Getident4_Pat : Pattern := Ident_Pat * Ident_4; - Getident5_Pat : Pattern := Ident_Pat * Ident_5; + Getident_Pat : constant Pattern := Ident_Pat * Ident; + Getident2_Pat : constant Pattern := Ident_Pat * Ident_2; + Getident3_Pat : constant Pattern := Ident_Pat * Ident_3; + Getident4_Pat : constant Pattern := Ident_Pat * Ident_4; + Getident5_Pat : constant Pattern := Ident_Pat * Ident_5; -- Get an enumeration elements. - Enumel_Pat : Pattern := Wsp & Getident_Pat + Enumel_Pat : constant Pattern := Wsp & Getident_Pat & ((',' & Setcur (Comma_Pos'Access)) or "") & Eol_Pat; -- End of an enumeration declaration. - End_Enum_Pat : Pattern := Wsp & ");" & Eol_Pat; + End_Enum_Pat : constant Pattern := Wsp & ");" & Eol_Pat; - Format_Pat : Pattern := " Format_" & Getident_Pat + Format_Pat : constant Pattern := " Format_" & Getident_Pat & ((',' & Setcur (Comma_Pos'Access)) or "") & Eol_Pat; - Fields_Of_Format_Pat : Pattern := " -- Fields of Format_" & Getident_Pat - & ":" & Rpos (0); + Fields_Of_Format_Pat : constant Pattern := + " -- Fields of Format_" & Getident_Pat & ":" & Rpos (0); -- "subtype XX is Iir_Kind range". - Iir_Kind_Subtype_Pat : Pattern := + Iir_Kind_Subtype_Pat : constant Pattern := Wsp & "subtype" & Wsp & Getident_Pat & Wsp & "is" & Wsp & "Iir_Kind" & Wsp & "range" & Eol_Pat; -- Pattern for a range. - Start_Range_Pat : Pattern := Wsp & Getident_Pat & Wsp & ".." & Eol_Pat; - Comment_Range_Pat : Pattern := Wsp & "--" & Getident_Pat & Rpos (0); - End_Range_Pat : Pattern := Wsp & Getident_Pat & ";" & Eol_Pat; + Start_Range_Pat : constant Pattern := + Wsp & Getident_Pat & Wsp & ".." & Eol_Pat; + Comment_Range_Pat : constant Pattern := + Wsp & "--" & Getident_Pat & Rpos (0); + End_Range_Pat : constant Pattern := Wsp & Getident_Pat & ";" & Eol_Pat; -- End of public package part. - End_Pat : Pattern := "end Iirs;" & Rpos (0); + End_Pat : constant Pattern := "end Iirs;" & Rpos (0); -- Pattern for a function field. - Func_Decl_Pat : Pattern := " -- Field: " & Getident_Pat + Func_Decl_Pat : constant Pattern := " -- Field: " & Getident_Pat & ( "" or (" (" & Getident2_Pat & ")")) & Rpos (0); -- function Get_XXX. - Function_Get_Pat : Pattern := " function Get_" & Getident_Pat + Function_Get_Pat : constant Pattern := " function Get_" & Getident_Pat & " (" & Getident2_Pat & " : " & Getident3_Pat & ") return " & Getident4_Pat & ";" & Rpos (0); -- procedure Set_XXX. - Procedure_Set_Pat : Pattern := " procedure Set_" & Getident_Pat + Procedure_Set_Pat : constant Pattern := " procedure Set_" & Getident_Pat & " (" & Getident2_Pat & " : " & Getident3_Pat & "; " & Getident4_Pat & " : " & Getident5_Pat & ");" & Rpos (0); - Field_Decl_Pat : Pattern := " -- " & Getident_Pat & " : "; - Field_Type_Pat : Pattern := " -- " & Ident_Pat & " : " + Field_Decl_Pat : constant Pattern := " -- " & Getident_Pat & " : "; + Field_Type_Pat : constant Pattern := " -- " & Ident_Pat & " : " & Getident_Pat & ("" or (" (" & Arb & ")")) & Rpos (0); -- Formats of nodes. @@ -270,10 +269,8 @@ package body Check_Iirs_Pkg is return Iir_Type (P); end Get_Iir_Pos; - Disp_Func : Boolean := False; - - Flag_Disp_Format : Boolean := False; - Flag_Disp_Field : Boolean := False; + Flag_Disp_Format : constant Boolean := False; + Flag_Disp_Field : constant Boolean := False; procedure Read_Fields is @@ -285,7 +282,7 @@ package body Check_Iirs_Pkg is procedure Parse_Field is P : Integer; - Name : Vstring := Ident; + Name : constant Vstring := Ident; begin if not Match (Line, Field_Type_Pat) then Put_Line ("** field declaration without type"); @@ -500,7 +497,7 @@ package body Check_Iirs_Pkg is Start : Iir_Type; Pos : Iir_Type; P : Iir_Type; - Rng_Ident : VString := Ident; + Rng_Ident : constant VString := Ident; begin Line := Get_Line (In_Iirs); if not Match (Line, Start_Range_Pat) then @@ -638,34 +635,37 @@ package body Check_Iirs_Pkg is end Check_Iirs; -- Start of node description. - Start_Of_Iir_Kind_Pat : Pattern := " -- Start of Iir_Kind." & Rpos (0); - End_Of_Iir_Kind_Pat : Pattern := " -- End of Iir_Kind." & Rpos (0); + Start_Of_Iir_Kind_Pat : constant Pattern := + " -- Start of Iir_Kind." & Rpos (0); + End_Of_Iir_Kind_Pat : constant Pattern := + " -- End of Iir_Kind." & Rpos (0); -- Box ("----------") delimiters. - Box_Delim_Pat : Pattern := " --" & Span ('-') & Rpos (0); + Desc_Box_Comment_Pat : constant Pattern := " --" & Span ('-') & Rpos (0); - -- Inside a box ("-- XXX --"). - Box_Inside_Pat : Pattern := " --" & Arb & "--" & Rpos (0); + -- A comment ("-- XXXX") + Desc_Comment_Pat : constant Pattern := " -- " & Arb & Rpos (0); + Desc_Empty_Comment_Pat : constant Pattern := " --" & Rpos (0); -- Get a iir_kind identifier. - Desc_Iir_Kind_Pat : Pattern := + Desc_Iir_Kind_Pat : constant Pattern := " -- " & Getident_Pat & ("" or ( " (" & Getident2_Pat & ")")) & Rpos (0); - Subprogram_Pat : Pattern := " -- Get" & ("_" or "/Set_") & Getident_Pat + Subprogram_Pat : constant Pattern := + " -- Get" & ("_" or "/Set_") & Getident_Pat & ((" " & Arb) or "") & Rpos (0); - Desc_Only_For_Pat : Pattern := " -- Only for " & Getident_Pat & ":" - & Rpos (0); - Desc_Comment_Pat : Pattern := " -- " & (Alnum_Pat or Any ("*_(.|")); - Desc_Empty_Pat : Pattern := " --" & Rpos (0); - Desc_Subprogram_Pat : Pattern := " -- " & ("function" or "procedure"); + Desc_Only_For_Pat : constant Pattern := + " -- Only for " & Getident_Pat & ":" & Rpos (0); + Desc_Subprogram_Pat : constant Pattern := + " -- " & ("function" or "procedure"); - Field_Pat : Pattern := Arb & "(" & Getident_Pat & ")"; - Alias_Field_Pat : Pattern := Arb & "(Alias " & Getident_Pat & ")"; + Field_Pat : constant Pattern := Arb & "(" & Getident_Pat & ")"; + Alias_Field_Pat : constant Pattern := Arb & "(Alias " & Getident_Pat & ")"; - Disp_Desc : Boolean := False; + Disp_Desc : constant Boolean := False; -- Check descriptions. procedure Read_Desc @@ -744,229 +744,230 @@ package body Check_Iirs_Pkg is -- Read descriptions. L1 : loop - -- Empty lines. + -- Look for a description + loop Line := Get_Line (In_Iirs); - exit when not Match (Line, Rpos (0)); - end loop; - if Match (Line, Box_Delim_Pat) then - -- A box. - Line := Get_Line (In_Iirs); - if not Match (Line, Box_Inside_Pat) then - raise Err; - end if; - Line := Get_Line (In_Iirs); - if not Match (Line, Box_Delim_Pat) then - raise Err; - end if; - else - -- A description. - if not Match (Line, " -- Iir_Kind") then - if Match (Line, End_Of_Iir_Kind_Pat) then - exit L1; - elsif Match (Line, " -- For Iir_Kinds_") then - null; - else - raise Err; - end if; - end if; + -- The description + exit when Match (Line, " -- Iir_Kind"); - -- Get iir_kind. - declare - P_Num : Integer; - Rng : Range_Type; - Format : Format_Type; - begin - -- No iir being described. - Nbr_Desc := 0; - loop - Ident_2 := Nul; - exit when not Match (Line, Desc_Iir_Kind_Pat); + -- End of descriptions + exit L1 when Match (Line, End_Of_Iir_Kind_Pat); - -- Check format. - if Ident_2 = Nul then - Put_Line (Standard_Error, - "*** no format for " & S (Ident)); + -- Skip over comments + if Match (Line, Desc_Box_Comment_Pat) + or else Match (Line, Desc_Comment_Pat) + then + loop + Line := Get_Line (In_Iirs); + exit when Match (Line, Rpos (0)); + if Match (Line, Desc_Comment_Pat) + or else Match (Line, Desc_Empty_Comment_Pat) + or else Match (Line, Desc_Box_Comment_Pat) + then + null; + else raise Err; end if; - P_Num := Get (Format2pos, Ident_2); - if P_Num < 0 then - Put_Line (Standard_Error, "*** unknown format"); + end loop; + end if; + end loop; + + -- Get iir_kind. + declare + P_Num : Integer; + Rng : Range_Type; + Format : Format_Type; + begin + -- No iir being described. + Nbr_Desc := 0; + loop + Ident_2 := Nul; + exit when not Match (Line, Desc_Iir_Kind_Pat); + + -- Check format. + if Ident_2 = Nul then + Put_Line (Standard_Error, + "*** no format for " & S (Ident)); + raise Err; + end if; + P_Num := Get (Format2pos, Ident_2); + if P_Num < 0 then + Put_Line (Standard_Error, "*** unknown format"); + raise Err; + end if; + Format := Format_Type (P_Num); + + -- Handle nodes. + P_Num := Get (Iir_Kind2pos, Ident); + if P_Num >= 0 then + Add_Desc (Iir_Type (P_Num), Format); + else + Rng := Get (Iir_Kinds2pos, Ident); + if Rng = Null_Range then + Put_Line (Standard_Error, "*** " & S (Ident)); raise Err; end if; - Format := Format_Type (P_Num); + for I in Rng.L .. Rng.H loop + Add_Desc (I, Format); + end loop; + end if; - -- Handle nodes. - P_Num := Get (Iir_Kind2pos, Ident); - if P_Num >= 0 then - Add_Desc (Iir_Type (P_Num), Format); - else - Rng := Get (Iir_Kinds2pos, Ident); - if Rng = Null_Range then - Put_Line (Standard_Error, "*** " & S (Ident)); - raise Err; - end if; - for I in Rng.L .. Rng.H loop - Add_Desc (I, Format); - end loop; - end if; + if Disp_Desc then + Put_Line ("desc for " & S (Ident)); + end if; - if Disp_Desc then - Put_Line ("desc for " & S (Ident)); - end if; + Line := Get_Line (In_Iirs); + end loop; + end; - Line := Get_Line (In_Iirs); - end loop; - end; + --Debug_Mode := True; - --Debug_Mode := True; + -- Read the functions. + loop + if not Match (Line, Comment_Pat) then + if Match (Line, Rpos (0)) then + exit; + else + raise Err; + end if; + end if; + declare + Func : Func_Type; + Func_Num : Integer; + Field : Field_Type; + Field_Num : Integer; + Is_Alias : Boolean; - -- Read the functions. - loop - if not Match (Line, Comment_Pat) then - if Match (Line, Rpos (0)) then - exit; - else + procedure Add_Field (N : Iir_Type) is + begin + if not Field_Table.Table (Field). + Formats (Iir_Table.Table (N).Format) + then + Put_Line (Standard_Error, "** no field for format"); raise Err; end if; - end if; - declare - Func : Func_Type; - Func_Num : Integer; - Field : Field_Type; - Field_Num : Integer; - Is_Alias : Boolean; - - procedure Add_Field (N : Iir_Type) is - begin - if not Field_Table.Table (Field). - Formats (Iir_Table.Table (N).Format) + if Is_Alias then + if Iir_Table.Table (N).Func (Field) = No_Func then - Put_Line (Standard_Error, "** no field for format"); + Put_Line (Standard_Error, + "** aliased field not yet used"); raise Err; end if; - if Is_Alias then - if Iir_Table.Table (N).Func (Field) = No_Func - then - Put_Line (Standard_Error, - "** aliased field not yet used"); - raise Err; - end if; - else - if Iir_Table.Table (N).Func (Field) /= No_Func - --and then - --Iir_Table.Table (N).Func (Field) /= Func + else + if Iir_Table.Table (N).Func (Field) /= No_Func + --and then + --Iir_Table.Table (N).Func (Field) /= Func then Put_Line (Standard_Error, "** Field already used"); raise Err; - end if; - Iir_Table.Table (N).Func (Field) := Func; - end if; - Func_Table.Table (Func).Uses (N) := True; - end Add_Field; - begin - if Match (Line, Subprogram_Pat) then - if Disp_Desc then - Put ("subprg: " & S (Ident)); - end if; - Func_Num := Get (Function2pos, Ident); - if Func_Num < 0 then - Put_Line (Standard_Error, - "*** function not found: " & S (Ident)); - raise Err; end if; - Func := Func_Type (Func_Num); - if Match (Line, Field_Pat) then - Is_Alias := False; - elsif Match (Line, Alias_Field_Pat) then - Is_Alias := True; + Iir_Table.Table (N).Func (Field) := Func; + end if; + Func_Table.Table (Func).Uses (N) := True; + end Add_Field; + begin + if Match (Line, Subprogram_Pat) then + if Disp_Desc then + Put ("subprg: " & S (Ident)); + end if; + Func_Num := Get (Function2pos, Ident); + if Func_Num < 0 then + Put_Line (Standard_Error, + "*** function not found: " & S (Ident)); + raise Err; + end if; + Func := Func_Type (Func_Num); + if Match (Line, Field_Pat) then + Is_Alias := False; + elsif Match (Line, Alias_Field_Pat) then + Is_Alias := True; + else + raise Err; + end if; + if Disp_Desc then + Put_Line (" (" & S (Ident) & ")"); + end if; + Field_Num := Get (Field2pos, Ident); + if Field_Num < 0 then + Put_Line (Standard_Error, + "*** unknown field: " & S (Ident)); + raise Err; + end if; + Field := Field_Type (Field_Num); + if Func_Table.Table (Func).Field /= Field then + if Func_Table.Table (Func).Field = No_Field then + Func_Table.Table (Func).Field := Field; else - raise Err; - end if; - if Disp_Desc then - Put_Line (" (" & S (Ident) & ")"); - end if; - Field_Num := Get (Field2pos, Ident); - if Field_Num < 0 then + -- Field redefined for the function. Put_Line (Standard_Error, - "*** unknown field: " & S (Ident)); - raise Err; - end if; - Field := Field_Type (Field_Num); - if Func_Table.Table (Func).Field /= Field then - if Func_Table.Table (Func).Field = No_Field then - Func_Table.Table (Func).Field := Field; - else - -- Field redefined for the function. - Put_Line (Standard_Error, - "** field redefined for function " + "** field redefined for function " & Func_Table.Table (Func).Name.all); - raise Err; - end if; + raise Err; end if; + end if; - -- Check the field is not already used by another func. - if Nbr_Only_For > 0 then - for I in 1 .. Nbr_Only_For loop - Add_Field (Only_For (I)); - end loop; - Nbr_Only_For := 0; - else + -- Check the field is not already used by another func. + if Nbr_Only_For > 0 then + for I in 1 .. Nbr_Only_For loop + Add_Field (Only_For (I)); + end loop; + Nbr_Only_For := 0; + else + for I in 1 .. Nbr_Desc loop + Add_Field (Iir_Desc (I)); + end loop; + end if; + elsif Match (Line, Desc_Only_For_Pat) then + declare + P_Num : Integer; + Rng : Range_Type; + + procedure Add_Only_For (N : Iir_Type) is + begin for I in 1 .. Nbr_Desc loop - Add_Field (Iir_Desc (I)); + if Iir_Desc (I) = N then + Nbr_Only_For := Nbr_Only_For + 1; + Only_For (Nbr_Only_For) := N; + return; + end if; end loop; - end if; - elsif Match (Line, Desc_Only_For_Pat) then - declare - P_Num : Integer; - Rng : Range_Type; - - procedure Add_Only_For (N : Iir_Type) is - begin - for I in 1 .. Nbr_Desc loop - if Iir_Desc (I) = N then - Nbr_Only_For := Nbr_Only_For + 1; - Only_For (Nbr_Only_For) := N; - return; - end if; - end loop; - Put_Line (Standard_Error, - "** not currently described"); + Put_Line (Standard_Error, + "** not currently described"); + raise Err; + end Add_Only_For; + begin + P_Num := Get (Iir_Kind2pos, Ident); + if P_Num >= 0 then + Add_Only_For (Iir_Type (P_Num)); + else + Rng := Get (Iir_Kinds2pos, Ident); + if Rng = Null_Range then + Put_Line (Standard_Error, "*** " & S (Ident)); raise Err; - end Add_Only_For; - begin - P_Num := Get (Iir_Kind2pos, Ident); - if P_Num >= 0 then - Add_Only_For (Iir_Type (P_Num)); - else - Rng := Get (Iir_Kinds2pos, Ident); - if Rng = Null_Range then - Put_Line (Standard_Error, "*** " & S (Ident)); - raise Err; - end if; - for I in Rng.L .. Rng.H loop - Add_Only_For (I); - end loop; end if; - end; - elsif Match (Line, " -- Only") then - Put_Line (Standard_Error, "** bad 'Only' for line"); - raise Err; - elsif Match (Line, Desc_Comment_Pat) then - null; - elsif Match (Line, Desc_Empty_Pat) then - null; - elsif Match (Line, Desc_Subprogram_Pat) then - null; - else - raise Err; - end if; - end; - Line := Get_Line (In_Iirs); - end loop; - end if; + for I in Rng.L .. Rng.H loop + Add_Only_For (I); + end loop; + end if; + end; + elsif Match (Line, " -- Only") then + Put_Line (Standard_Error, "** bad 'Only' for line"); + raise Err; + elsif Match (Line, Desc_Comment_Pat) then + null; + elsif Match (Line, Desc_Empty_Comment_Pat) then + null; + elsif Match (Line, Desc_Subprogram_Pat) then + null; + else + raise Err; + end if; + end; + Line := Get_Line (In_Iirs); + end loop; end loop L1; -- Check each Iir was described. @@ -1231,4 +1232,3 @@ package body Check_Iirs_Pkg is end loop; end List_Free_Fields; end Check_Iirs_Pkg; - |