From 1c59818d0a07f10781abb565e7941e0a3411926f Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Mon, 1 Jul 2019 20:35:00 +0200 Subject: synth: destroy iterator after for-loop. --- src/synth/synth-context.adb | 17 ++++++++++++++++- src/synth/synth-context.ads | 3 +++ src/synth/synth-decls.adb | 23 ++++++++++++++++------- src/synth/synth-decls.ads | 7 +++++++ src/synth/synth-expr.adb | 2 ++ src/synth/synth-stmts.adb | 12 ++++++++++-- 6 files changed, 54 insertions(+), 10 deletions(-) diff --git a/src/synth/synth-context.adb b/src/synth/synth-context.adb index 1b170b490..84fac7ab5 100644 --- a/src/synth/synth-context.adb +++ b/src/synth/synth-context.adb @@ -133,7 +133,7 @@ package body Synth.Context is if Slot /= Syn_Inst.Elab_Objects + 1 or else Syn_Inst.Objects (Slot) /= null then - Error_Msg_Elab ("bad elaboration order"); + Error_Msg_Elab ("synth: bad elaboration order of objects"); raise Internal_Error; end if; Syn_Inst.Elab_Objects := Slot + Num - 1; @@ -148,6 +148,21 @@ package body Synth.Context is Syn_Inst.Objects (Info.Slot) := Val; end Create_Object; + procedure Destroy_Object + (Syn_Inst : Synth_Instance_Acc; Decl : Iir) + 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"); + end if; + Syn_Inst.Objects (Slot) := null; + Syn_Inst.Elab_Objects := Slot - 1; + end Destroy_Object; + procedure Make_Object (Syn_Inst : Synth_Instance_Acc; Kind : Wire_Kind; Obj : Iir) diff --git a/src/synth/synth-context.ads b/src/synth/synth-context.ads index bb633b17c..ee7de6d72 100644 --- a/src/synth/synth-context.ads +++ b/src/synth/synth-context.ads @@ -75,6 +75,9 @@ package Synth.Context is procedure Create_Object (Syn_Inst : Synth_Instance_Acc; Decl : Iir; Val : Value_Acc); + procedure Destroy_Object + (Syn_Inst : Synth_Instance_Acc; Decl : Iir); + -- Build the value for object OBJ. -- KIND must be Wire_Variable or Wire_Signal. procedure Make_Object (Syn_Inst : Synth_Instance_Acc; diff --git a/src/synth/synth-decls.adb b/src/synth/synth-decls.adb index 0726cfa6d..0166a07b8 100644 --- a/src/synth/synth-decls.adb +++ b/src/synth/synth-decls.adb @@ -160,15 +160,14 @@ package body Synth.Decls is Synth_Subtype_Indication (Syn_Inst, Atype); end Synth_Anonymous_Subtype_Indication; - procedure Synth_Declaration_Type - (Syn_Inst : Synth_Instance_Acc; Decl : Node) + function Get_Declaration_Type (Decl : Node) return Node is Ind : constant Node := Get_Subtype_Indication (Decl); Atype : Node; begin if Ind = Null_Node then -- No subtype indication; use the same type. - return; + return Null_Node; end if; Atype := Ind; loop @@ -177,18 +176,28 @@ package body Synth.Decls is Atype := Get_Named_Entity (Atype); when Iir_Kind_Subtype_Declaration | Iir_Kind_Type_Declaration => - return; + return Null_Node; when Iir_Kind_Array_Subtype_Definition | Iir_Kind_Integer_Subtype_Definition | Iir_Kind_Floating_Subtype_Definition | Iir_Kind_Physical_Subtype_Definition | Iir_Kind_Enumeration_Subtype_Definition => - Synth_Subtype_Indication (Syn_Inst, Atype); - return; + return Atype; when others => - Error_Kind ("synth_declaration_type", Atype); + Error_Kind ("get_declaration_type", Atype); end case; end loop; + end Get_Declaration_Type; + + procedure Synth_Declaration_Type + (Syn_Inst : Synth_Instance_Acc; Decl : Node) + is + Atype : constant Node := Get_Declaration_Type (Decl); + begin + if Atype = Null_Node then + return; + end if; + Synth_Subtype_Indication (Syn_Inst, Atype); end Synth_Declaration_Type; procedure Synth_Constant_Declaration diff --git a/src/synth/synth-decls.ads b/src/synth/synth-decls.ads index 0a5590b35..aaae102c3 100644 --- a/src/synth/synth-decls.ads +++ b/src/synth/synth-decls.ads @@ -22,6 +22,13 @@ with Vhdl.Nodes; use Vhdl.Nodes; with Synth.Context; use Synth.Context; package Synth.Decls is + -- Get the type of DECL iff it is standalone (not an already existing + -- subtype). + function Get_Declaration_Type (Decl : Node) return Node; + + procedure Synth_Subtype_Indication + (Syn_Inst : Synth_Instance_Acc; Atype : Node); + -- Elaborate the type of DECL. procedure Synth_Declaration_Type (Syn_Inst : Synth_Instance_Acc; Decl : Node); diff --git a/src/synth/synth-expr.adb b/src/synth/synth-expr.adb index fac2ede6f..0bb7f122f 100644 --- a/src/synth/synth-expr.adb +++ b/src/synth/synth-expr.adb @@ -716,6 +716,8 @@ package body Synth.Expr is raise Internal_Error; end if; return Synth_Compare (Id_Ne); + when Iir_Predefined_Enum_Less_Equal => + return Synth_Compare (Id_Ult); when Iir_Predefined_Array_Equality => -- TODO: check size, handle non-vector. diff --git a/src/synth/synth-stmts.adb b/src/synth/synth-stmts.adb index c83c44b56..33d198d9f 100644 --- a/src/synth/synth-stmts.adb +++ b/src/synth/synth-stmts.adb @@ -901,9 +901,14 @@ package body Synth.Stmts is Iterator : constant Node := Get_Parameter_Specification (Stmt); Stmts : constant Node := Get_Sequential_Statement_Chain (Stmt); It_Rng : Value_Acc; + It_Type : Node; Val : Value_Acc; begin - Synth_Declaration_Type (Syn_Inst, Iterator); + It_Type := Get_Declaration_Type (Iterator); + if It_Type /= Null_Node then + Synth_Subtype_Indication (Syn_Inst, It_Type); + end if; + -- Initial value. It_Rng := Get_Value (Syn_Inst, Get_Type (Iterator)); Val := Create_Value_Discrete (It_Rng.Rng.Left); @@ -918,7 +923,10 @@ package body Synth.Stmts is Val.Scal := Val.Scal - 1; end case; end loop; - -- Destroy ? + Destroy_Object (Syn_Inst, Iterator); + if It_Type /= Null_Node then + Destroy_Object (Syn_Inst, It_Type); + end if; end Synth_For_Loop_Statement; procedure Synth_Sequential_Statements -- cgit v1.2.3