diff options
author | Tristan Gingold <tgingold@free.fr> | 2017-12-03 10:27:57 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2017-12-03 10:27:57 +0100 |
commit | e62abb62264f7271ad5521d75a84fd689c3b49e0 (patch) | |
tree | e3a14524a135b4dad09f3b0833d77ef474fe601a | |
parent | 2b61f516ef9775502da6dfcc8b21e79cf8482c87 (diff) | |
download | ghdl-e62abb62264f7271ad5521d75a84fd689c3b49e0.tar.gz ghdl-e62abb62264f7271ad5521d75a84fd689c3b49e0.tar.bz2 ghdl-e62abb62264f7271ad5521d75a84fd689c3b49e0.zip |
simul: refactoring: scope is now the corresponding sim_info.
-rw-r--r-- | src/vhdl/simulate/simul-annotations.adb | 40 | ||||
-rw-r--r-- | src/vhdl/simulate/simul-annotations.ads | 73 | ||||
-rw-r--r-- | src/vhdl/simulate/simul-debugger.adb | 2 | ||||
-rw-r--r-- | src/vhdl/simulate/simul-elaboration.adb | 7 | ||||
-rw-r--r-- | src/vhdl/simulate/simul-elaboration.ads | 1 | ||||
-rw-r--r-- | src/vhdl/simulate/simul-environments.ads | 74 | ||||
-rw-r--r-- | src/vhdl/simulate/simul-execution.adb | 30 | ||||
-rw-r--r-- | src/vhdl/simulate/simul-execution.ads | 4 |
8 files changed, 119 insertions, 112 deletions
diff --git a/src/vhdl/simulate/simul-annotations.adb b/src/vhdl/simulate/simul-annotations.adb index de811e424..551974a88 100644 --- a/src/vhdl/simulate/simul-annotations.adb +++ b/src/vhdl/simulate/simul-annotations.adb @@ -21,6 +21,7 @@ with Ada.Text_IO; with Std_Package; with Errorout; use Errorout; with Iirs_Utils; use Iirs_Utils; +with Types; use Types; package body Simul.Annotations is -- Current scope. Used when an object is created to indicate which scope @@ -74,29 +75,29 @@ package body Simul.Annotations is case Obj_Kind is when Kind_Object => Info := new Sim_Info_Type'(Kind => Kind_Object, - Obj_Scope => Current_Scope, + Obj_Scope => Block_Info, Slot => Block_Info.Nbr_Objects); when Kind_File => Info := new Sim_Info_Type'(Kind => Kind_File, - Obj_Scope => Current_Scope, + Obj_Scope => Block_Info, Slot => Block_Info.Nbr_Objects); when Kind_Signal => Info := new Sim_Info_Type'(Kind => Kind_Signal, - Obj_Scope => Current_Scope, + Obj_Scope => Block_Info, Slot => Block_Info.Nbr_Objects); -- Reserve one more slot for value. Block_Info.Nbr_Objects := Block_Info.Nbr_Objects + 1; when Kind_Terminal => Info := new Sim_Info_Type'(Kind => Kind_Terminal, - Obj_Scope => Current_Scope, + Obj_Scope => Block_Info, Slot => Block_Info.Nbr_Objects); when Kind_Quantity => Info := new Sim_Info_Type'(Kind => Kind_Quantity, - Obj_Scope => Current_Scope, + Obj_Scope => Block_Info, Slot => Block_Info.Nbr_Objects); when Kind_PSL => Info := new Sim_Info_Type'(Kind => Kind_PSL, - Obj_Scope => Current_Scope, + Obj_Scope => Block_Info, Slot => Block_Info.Nbr_Objects); when Kind_Environment => Info := new Sim_Info_Type'(Kind => Kind_Environment, @@ -1020,6 +1021,7 @@ package body Simul.Annotations is is Entity_Info : constant Sim_Info_Acc := Get_Info (Get_Entity (Decl)); Arch_Info: Sim_Info_Acc; + Saved_Info : constant Sim_Info_Type (Kind_Block) := Entity_Info.all; begin pragma Assert (Current_Scope.Kind = Scope_Kind_None); Current_Scope := Entity_Info.Frame_Scope; @@ -1027,22 +1029,16 @@ package body Simul.Annotations is -- No blocks nor instantiation in entities. pragma Assert (Entity_Info.Nbr_Instances = 0); - Arch_Info := new Sim_Info_Type' - (Kind => Kind_Block, - Inst_Slot => 0, -- Slot for a component - Frame_Scope => Current_Scope, - Nbr_Objects => Entity_Info.Nbr_Objects, - Nbr_Instances => Entity_Info.Nbr_Instances); -- Should be 0. - Set_Info (Decl, Arch_Info); - - -- FIXME: annotate the default configuration for the arch ? - - -- declarations - Annotate_Declaration_List (Arch_Info, Get_Declaration_Chain (Decl)); + -- Annotate architecture using the entity as the architecture extend + -- the scope of the entity, and the entity is the reference. - -- processes. + Annotate_Declaration_List (Entity_Info, Get_Declaration_Chain (Decl)); Annotate_Concurrent_Statements_List - (Arch_Info, Get_Concurrent_Statement_Chain (Decl)); + (Entity_Info, Get_Concurrent_Statement_Chain (Decl)); + + Arch_Info := new Sim_Info_Type'(Entity_Info.all); + Entity_Info.all := Saved_Info; + Set_Info (Decl, Arch_Info); Current_Scope := (Kind => Scope_Kind_None); end Annotate_Architecture; @@ -1275,7 +1271,7 @@ package body Simul.Annotations is | Kind_Environment | Kind_PSL => Put_Line ("-- slot:" & Object_Slot_Type'Image (Info.Slot) - & ", scope:" & Image (Info.Obj_Scope)); + & ", scope:" & Image (Info.Obj_Scope.Frame_Scope)); when Kind_Scalar_Type | Kind_File_Type | Kind_Extra => @@ -1310,7 +1306,7 @@ package body Simul.Annotations is | Kind_Terminal | Kind_Quantity | Kind_Environment | Kind_PSL => Put_Line ("slot:" & Object_Slot_Type'Image (Info.Slot) - & ", scope:" & Image (Info.Obj_Scope)); + & ", scope:" & Image (Info.Obj_Scope.Frame_Scope)); when Kind_Extra => Put_Line ("extra:" & Extra_Slot_Type'Image (Info.Extra_Slot)); when Kind_Scalar_Type => diff --git a/src/vhdl/simulate/simul-annotations.ads b/src/vhdl/simulate/simul-annotations.ads index 46b38d674..f4991b093 100644 --- a/src/vhdl/simulate/simul-annotations.ads +++ b/src/vhdl/simulate/simul-annotations.ads @@ -18,7 +18,6 @@ with Iirs; use Iirs; with Simul.Environments; use Simul.Environments; -with Types; use Types; package Simul.Annotations is -- Decorate the tree in order to be usable with the internal simulator. @@ -28,83 +27,11 @@ package Simul.Annotations is procedure Disp_Vhdl_Info (Node : Iir); procedure Disp_Tree_Info (Node : Iir); - -- For Kind_Extra: a number. Kind_Extra is not used by annotations, and - -- is free for another pass like preelab. - type Extra_Slot_Type is new Natural; - Nbr_Packages : Pkg_Index_Type := 0; -- Annotations are used to collect informations for elaboration and to -- locate iir_value_literal for signals, variables or constants. - -- The annotation depends on the kind of the node. - type Sim_Info_Kind is - (Kind_Block, Kind_Process, Kind_Frame, - Kind_Scalar_Type, Kind_File_Type, - Kind_Object, Kind_Signal, - Kind_File, - Kind_Terminal, Kind_Quantity, - Kind_Environment, - Kind_PSL, - Kind_Extra); - - type Sim_Info_Type (Kind : Sim_Info_Kind); - type Sim_Info_Acc is access all Sim_Info_Type; - - type Instance_Slot_Type is new Integer; - Invalid_Instance_Slot : constant Instance_Slot_Type := -1; - - -- Annotation for an iir node in order to be able to simulate it. - type Sim_Info_Type (Kind: Sim_Info_Kind) is record - case Kind is - when Kind_Block - | Kind_Frame - | Kind_Process - | Kind_Environment => - -- Scope level for this frame. - Frame_Scope : Scope_Type; - - -- Number of objects/signals. - Nbr_Objects : Object_Slot_Type; - - case Kind is - when Kind_Block => - -- Slot number in the parent (for blocks). - Inst_Slot : Instance_Slot_Type; - - -- Number of children (blocks, generate, instantiation). - Nbr_Instances : Instance_Slot_Type; - - when Kind_Environment => - Env_Slot : Object_Slot_Type; - - when others => - null; - end case; - - when Kind_Object - | Kind_Signal - | Kind_File - | Kind_Terminal - | Kind_Quantity - | Kind_PSL => - -- Block in which this object is declared in. - Obj_Scope : Scope_Type; - - -- Variable index in the block. - Slot: Object_Slot_Type; - - when Kind_Scalar_Type => - Scalar_Mode : Iir_Value_Kind; - - when Kind_File_Type => - File_Signature : String_Acc; - - when Kind_Extra => - Extra_Slot : Extra_Slot_Type; - end case; - end record; - -- Get/Set annotation fied from/to an iir. procedure Set_Info (Target : Iir; Info : Sim_Info_Acc); pragma Inline (Set_Info); diff --git a/src/vhdl/simulate/simul-debugger.adb b/src/vhdl/simulate/simul-debugger.adb index 105b16e81..648e99501 100644 --- a/src/vhdl/simulate/simul-debugger.adb +++ b/src/vhdl/simulate/simul-debugger.adb @@ -313,7 +313,7 @@ package body Simul.Debugger is -- Used to debug. procedure Disp_Block_Instance (Instance: Block_Instance_Acc) is begin - Put_Line ("scope:" & Image (Instance.Block_Scope)); + Put_Line ("scope:" & Image (Instance.Block_Scope.Frame_Scope)); Put_Line ("Objects:"); for I in Instance.Objects'Range loop Put (Object_Slot_Type'Image (I) & ": "); diff --git a/src/vhdl/simulate/simul-elaboration.adb b/src/vhdl/simulate/simul-elaboration.adb index 86a936458..21fe3001b 100644 --- a/src/vhdl/simulate/simul-elaboration.adb +++ b/src/vhdl/simulate/simul-elaboration.adb @@ -26,6 +26,7 @@ with Libraries; with Name_Table; with Simul.File_Operation; with Iir_Chains; use Iir_Chains; +with Simul.Annotations; use Simul.Annotations; with Simul.Elaboration.AMS; use Simul.Elaboration.AMS; with Areapools; use Areapools; with Grt.Errors; @@ -343,7 +344,7 @@ package body Simul.Elaboration is Res := new Block_Instance_Type' (Max_Objs => Obj_Info.Nbr_Objects, Id => Nbr_Block_Instances, - Block_Scope => Obj_Info.Frame_Scope, + Block_Scope => Obj_Info, Up_Block => Father, Label => Stmt, Stmt => Obj, @@ -1144,8 +1145,7 @@ package body Simul.Elaboration is Info : constant Sim_Info_Acc := Get_Info (Actual); Pkg_Block : Block_Instance_Acc; begin - Pkg_Block := Get_Instance_By_Scope - (Local_Instance, Info.Frame_Scope); + Pkg_Block := Get_Instance_By_Scope (Local_Instance, Info); Environment_Table.Append (Pkg_Block); Val := Create_Environment_Value (Environment_Table.Last); Target_Instance.Objects (Get_Info (Inter).Env_Slot) := @@ -2747,6 +2747,7 @@ package body Simul.Elaboration is end if; Instance := Create_Block_Instance (Parent_Instance, Arch, Stmt); + Instance.Block_Scope := Get_Info (Entity); Instance.Up_Block := null; -- Packages_Instance; -- LRM93 §12.1 diff --git a/src/vhdl/simulate/simul-elaboration.ads b/src/vhdl/simulate/simul-elaboration.ads index 07969719f..a469ead00 100644 --- a/src/vhdl/simulate/simul-elaboration.ads +++ b/src/vhdl/simulate/simul-elaboration.ads @@ -21,7 +21,6 @@ with Types; use Types; with Iirs; use Iirs; with Simul.Environments; use Simul.Environments; with Grt.Types; use Grt.Types; -with Simul.Annotations; use Simul.Annotations; -- This package elaborates design hierarchy. diff --git a/src/vhdl/simulate/simul-environments.ads b/src/vhdl/simulate/simul-environments.ads index e043659b3..ad5e0b59f 100644 --- a/src/vhdl/simulate/simul-environments.ads +++ b/src/vhdl/simulate/simul-environments.ads @@ -248,6 +248,78 @@ package Simul.Environments is type Objects_Array is array (Object_Slot_Type range <>) of Iir_Value_Literal_Acc; + -- For Kind_Extra: a number. Kind_Extra is not used by annotations, and + -- is free for another pass like preelab. + type Extra_Slot_Type is new Natural; + + -- The annotation depends on the kind of the node. + type Sim_Info_Kind is + (Kind_Block, Kind_Process, Kind_Frame, + Kind_Scalar_Type, Kind_File_Type, + Kind_Object, Kind_Signal, + Kind_File, + Kind_Terminal, Kind_Quantity, + Kind_Environment, + Kind_PSL, + Kind_Extra); + + type Instance_Slot_Type is new Integer; + Invalid_Instance_Slot : constant Instance_Slot_Type := -1; + + type Sim_Info_Type (Kind : Sim_Info_Kind); + type Sim_Info_Acc is access all Sim_Info_Type; + + -- Annotation for an iir node in order to be able to simulate it. + type Sim_Info_Type (Kind: Sim_Info_Kind) is record + case Kind is + when Kind_Block + | Kind_Frame + | Kind_Process + | Kind_Environment => + -- Scope level for this frame. + Frame_Scope : Scope_Type; + + -- Number of objects/signals. + Nbr_Objects : Object_Slot_Type; + + case Kind is + when Kind_Block => + -- Slot number in the parent (for blocks). + Inst_Slot : Instance_Slot_Type; + + -- Number of children (blocks, generate, instantiation). + Nbr_Instances : Instance_Slot_Type; + + when Kind_Environment => + Env_Slot : Object_Slot_Type; + + when others => + null; + end case; + + when Kind_Object + | Kind_Signal + | Kind_File + | Kind_Terminal + | Kind_Quantity + | Kind_PSL => + -- Block in which this object is declared in. + Obj_Scope : Sim_Info_Acc; + + -- Variable index in the block. + Slot: Object_Slot_Type; + + when Kind_Scalar_Type => + Scalar_Mode : Iir_Value_Kind; + + when Kind_File_Type => + File_Signature : String_Acc; + + when Kind_Extra => + Extra_Slot : Extra_Slot_Type; + end case; + end record; + type Block_Instance_Type (Max_Objs : Object_Slot_Type) is record -- Flag for wait statement: true if not yet executed. In_Wait_Flag : Boolean; @@ -257,7 +329,7 @@ package Simul.Environments is -- Useful informations for a dynamic block (ie, a frame). -- The scope level and an access to the block of upper scope level. - Block_Scope : Scope_Type; + Block_Scope : Sim_Info_Acc; Up_Block : Block_Instance_Acc; -- Block, architecture, package, process, component instantiation for diff --git a/src/vhdl/simulate/simul-execution.adb b/src/vhdl/simulate/simul-execution.adb index d6639c06d..e7ea76fe2 100644 --- a/src/vhdl/simulate/simul-execution.adb +++ b/src/vhdl/simulate/simul-execution.adb @@ -65,10 +65,10 @@ package body Simul.Execution is Stmt: Iir); function Get_Instance_By_Scope - (Instance: Block_Instance_Acc; Scope: Scope_Type) + (Instance: Block_Instance_Acc; Scope: Sim_Info_Acc) return Block_Instance_Acc is begin - case Scope.Kind is + case Scope.Frame_Scope.Kind is when Scope_Kind_Frame => declare Current : Block_Instance_Acc; @@ -82,8 +82,9 @@ package body Simul.Execution is Last := Current; Current := Current.Up_Block; end loop; - if Scope.Depth = 0 - and then Last.Block_Scope.Kind = Scope_Kind_Package + if Scope.Frame_Scope.Depth = 0 + and then (Last.Block_Scope.Frame_Scope.Kind + = Scope_Kind_Package) then -- For instantiated packages. return Last; @@ -92,7 +93,7 @@ package body Simul.Execution is end; when Scope_Kind_Package => -- Global scope (packages) - return Package_Instances (Scope.Pkg_Index); + return Package_Instances (Scope.Frame_Scope.Pkg_Index); when Scope_Kind_Component => pragma Assert (Current_Component /= null); return Current_Component; @@ -109,6 +110,16 @@ package body Simul.Execution is return Get_Instance_By_Scope (Instance, Get_Info (Decl).Obj_Scope); end Get_Instance_For_Slot; + function Get_Info_For_Scope (Scope : Iir) return Sim_Info_Acc is + begin + -- The info for an architecture is in fact the entity. + if Get_Kind (Scope) = Iir_Kind_Architecture_Body then + return Get_Info (Get_Entity (Scope)); + else + return Get_Info (Scope); + end if; + end Get_Info_For_Scope; + procedure Create_Right_Bound_From_Length (Bounds : Iir_Value_Literal_Acc; Len : Iir_Index32) is @@ -339,7 +350,7 @@ package body Simul.Execution is end if; Instance := Get_Instance_By_Scope - (Block, Get_Info (Name.Path_Instance).Frame_Scope); + (Block, Get_Info_For_Scope (Name.Path_Instance)); loop case Get_Kind (Instance.Label) is @@ -3247,6 +3258,7 @@ package body Simul.Execution is return Block_Instance_Acc is Func_Info : constant Sim_Info_Acc := Get_Info (Imp); + Parent : constant Iir := Get_Parent (Imp); subtype Block_Type is Block_Instance_Type (Func_Info.Nbr_Objects); function To_Block_Instance_Acc is new @@ -3268,8 +3280,8 @@ package body Simul.Execution is Up_Block := Prot_Obj; Label := Imp; else - Up_Info := Get_Info (Get_Parent (Imp)); - Up_Block := Get_Instance_By_Scope (Instance, Up_Info.Frame_Scope); + Up_Info := Get_Info_For_Scope (Parent); + Up_Block := Get_Instance_By_Scope (Instance, Up_Info); Origin := Sem_Inst.Get_Origin (Imp); if Origin /= Null_Iir then @@ -3295,7 +3307,7 @@ package body Simul.Execution is (Instance_Pool, Block_Instance_Type'(Max_Objs => Func_Info.Nbr_Objects, Id => No_Block_Instance_Id, - Block_Scope => Get_Info (Label).Frame_Scope, + Block_Scope => Get_Info (Label), Up_Block => Up_Block, Label => Label, Stmt => Null_Iir, diff --git a/src/vhdl/simulate/simul-execution.ads b/src/vhdl/simulate/simul-execution.ads index 358c26eae..ac69ed8f5 100644 --- a/src/vhdl/simulate/simul-execution.ads +++ b/src/vhdl/simulate/simul-execution.ads @@ -102,7 +102,7 @@ package Simul.Execution is Default_Severity : Natural); function Execute_Resolution_Function - (Block: Block_Instance_Acc; Imp : Iir; Arr : Iir_Value_Literal_Acc) + (Block: Block_Instance_Acc; Imp : Iir; Arr : Iir_Value_Literal_Acc) return Iir_Value_Literal_Acc; function Execute_Assoc_Conversion @@ -126,7 +126,7 @@ package Simul.Execution is return Iir_Value_Literal_Acc; function Get_Instance_By_Scope - (Instance: Block_Instance_Acc; Scope: Scope_Type) + (Instance: Block_Instance_Acc; Scope: Sim_Info_Acc) return Block_Instance_Acc; function Get_Instance_For_Slot (Instance: Block_Instance_Acc; Decl: Iir) |