From 7201b1537e396d72ace4259a8a9578eda300a6a2 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Mon, 30 Sep 2019 01:03:56 +0200 Subject: synth: special handling of 'const' functions. --- src/synth/synth-values.adb | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'src/synth/synth-values.adb') diff --git a/src/synth/synth-values.adb b/src/synth/synth-values.adb index 030ceec81..a2c9f8623 100644 --- a/src/synth/synth-values.adb +++ b/src/synth/synth-values.adb @@ -592,6 +592,59 @@ package body Synth.Values is return Atype.W; end Get_Type_Width; + function Create_Value_Default (Typ : Type_Acc) return Value_Acc is + begin + case Typ.Kind is + when Type_Bit + | Type_Logic => + -- FIXME: what about subtype ? + return Create_Value_Discrete (0, Typ); + when Type_Discrete => + return Create_Value_Discrete (Typ.Drange.Left, Typ); + when Type_Float => + return Create_Value_Float (Typ.Frange.Left, Typ); + when Type_Vector => + declare + El_Typ : constant Type_Acc := Typ.Vec_El; + Arr : Value_Array_Acc; + begin + Arr := Create_Value_Array (Iir_Index32 (Typ.Vbound.Len)); + for I in Arr.V'Range loop + Arr.V (I) := Create_Value_Default (El_Typ); + end loop; + return Create_Value_Array (Typ, Arr); + end; + when Type_Unbounded_Vector => + raise Internal_Error; + when Type_Slice => + raise Internal_Error; + when Type_Array => + declare + El_Typ : constant Type_Acc := Typ.Vec_El; + Arr : Value_Array_Acc; + begin + Arr := Create_Value_Array + (Iir_Index32 (Get_Array_Flat_Length (Typ))); + for I in Arr.V'Range loop + Arr.V (I) := Create_Value_Default (El_Typ); + end loop; + return Create_Value_Array (Typ, Arr); + end; + when Type_Unbounded_Array => + raise Internal_Error; + when Type_Record => + declare + Els : Value_Array_Acc; + begin + Els := Create_Value_Array (Typ.Rec.Len); + for I in Els.V'Range loop + Els.V (I) := Create_Value_Default (Typ.Rec.E (I).Typ); + end loop; + return Create_Value_Record (Typ, Els); + end; + end case; + end Create_Value_Default; + procedure Init is begin Instance_Pool := Global_Pool'Access; -- cgit v1.2.3