diff options
Diffstat (limited to 'src/synth/elab-vhdl_context.adb')
-rw-r--r-- | src/synth/elab-vhdl_context.adb | 80 |
1 files changed, 54 insertions, 26 deletions
diff --git a/src/synth/elab-vhdl_context.adb b/src/synth/elab-vhdl_context.adb index c14a82964..95b9ddf29 100644 --- a/src/synth/elab-vhdl_context.adb +++ b/src/synth/elab-vhdl_context.adb @@ -25,7 +25,7 @@ with Vhdl.Utils; package body Elab.Vhdl_Context is - Sig_Nbr : Signal_Index_Type := 0; + Sig_Nbr : Signal_Index_Type := No_Signal_Index; function Get_Nbr_Signal return Signal_Index_Type is begin @@ -63,7 +63,6 @@ package body Elab.Vhdl_Context is Foreign => 0, Extra_Units => null, Extra_Link => null, - Cur_Stmt => Null_Node, Elab_Objects => 0, Objects => (others => (Kind => Obj_None))); Inst_Tables.Append (Root_Instance); @@ -112,7 +111,6 @@ package body Elab.Vhdl_Context is Foreign => 0, Extra_Units => null, Extra_Link => null, - Cur_Stmt => Null_Node, Elab_Objects => 0, Objects => (others => (Kind => Obj_None))); @@ -154,7 +152,6 @@ package body Elab.Vhdl_Context is Foreign => 0, Extra_Units => null, Extra_Link => null, - Cur_Stmt => Null_Node, Elab_Objects => 0, Objects => (others => (Kind => Obj_None))); @@ -308,8 +305,8 @@ package body Elab.Vhdl_Context is Vt : Valtyp; begin Create_Object (Syn_Inst, Info.Slot, 1); - Vt := (Typ, Create_Value_Signal (Sig_Nbr, Init)); Sig_Nbr := Sig_Nbr + 1; + Vt := (Typ, Create_Value_Signal (Sig_Nbr, Init)); Syn_Inst.Objects (Info.Slot) := (Kind => Obj_Object, Obj => Vt); end Create_Signal; @@ -461,24 +458,64 @@ package body Elab.Vhdl_Context is Syn_Inst.Uninst_Scope := Get_Info (Bod); end Set_Uninstantiated_Scope; - procedure Destroy_Object - (Syn_Inst : Synth_Instance_Acc; Decl : Node) + procedure Destroy_Init (D : out Destroy_Type; + Syn_Inst : Synth_Instance_Acc) is + begin + D := (Inst => Syn_Inst, + First => Object_Slot_Type'Last, + Last => Syn_Inst.Elab_Objects); + end Destroy_Init; + + procedure Destroy_Object (D : in out Destroy_Type; Decl : Node) is Info : constant Sim_Info_Acc := Get_Info (Decl); Slot : constant Object_Slot_Type := Info.Slot; begin - if Slot /= Syn_Inst.Elab_Objects - or else Info.Obj_Scope /= Syn_Inst.Block_Scope - then - Error_Msg_Elab ("synth: bad destroy order"); + if Info.Obj_Scope /= D.Inst.Block_Scope then + -- Bad context. + raise Internal_Error; + end if; + if Slot > D.Last then + -- Not elaborated object ? + raise Internal_Error; end if; - Syn_Inst.Objects (Slot) := (Kind => Obj_None); - Syn_Inst.Elab_Objects := Slot - 1; + if D.Inst.Objects (Slot).Kind = Obj_None then + -- Already destroyed. + raise Internal_Error; + end if; + if Slot < D.First then + D.First := Slot; + end if; + D.Inst.Objects (Slot) := (Kind => Obj_None); end Destroy_Object; + procedure Destroy_Finish (D : in out Destroy_Type) is + begin + if D.First = Object_Slot_Type'Last then + -- No object destroyed. + return; + end if; + + if D.Last /= D.Inst.Elab_Objects then + -- Two destroys at the same time. + raise Internal_Error; + end if; + + -- Check all objects have been destroyed. + for I in D.First .. D.Last loop + if D.Inst.Objects (I).Kind /= Obj_None then + raise Internal_Error; + end if; + end loop; + + D.Inst.Elab_Objects := D.First - 1; + end Destroy_Finish; + function Get_Instance_By_Scope (Syn_Inst: Synth_Instance_Acc; Scope: Sim_Info_Acc) - return Synth_Instance_Acc is + return Synth_Instance_Acc + is + pragma Assert (Scope /= null); begin case Scope.Kind is when Kind_Block @@ -489,7 +526,9 @@ package body Elab.Vhdl_Context is begin Current := Syn_Inst; while Current /= null loop - if Current.Block_Scope = Scope then + if Current.Block_Scope = Scope + or else Current.Uninst_Scope = Scope + then return Current; end if; Current := Current.Up_Block; @@ -563,15 +602,4 @@ package body Elab.Vhdl_Context is begin return Syn_Inst.Caller; end Get_Caller_Instance; - - function Get_Current_Stmt (Inst : Synth_Instance_Acc) return Node is - begin - return Inst.Cur_Stmt; - end Get_Current_Stmt; - - procedure Set_Current_Stmt (Inst : Synth_Instance_Acc; Stmt : Node) is - begin - Inst.Cur_Stmt := Stmt; - end Set_Current_Stmt; - end Elab.Vhdl_Context; |