diff options
-rw-r--r-- | src/synth/synth-decls.adb | 22 | ||||
-rw-r--r-- | src/synth/synth-expr.adb | 50 | ||||
-rw-r--r-- | src/synth/synth-values.adb | 38 | ||||
-rw-r--r-- | src/synth/synth-values.ads | 4 |
4 files changed, 89 insertions, 25 deletions
diff --git a/src/synth/synth-decls.adb b/src/synth/synth-decls.adb index 122e8ca99..f41d0e9ca 100644 --- a/src/synth/synth-decls.adb +++ b/src/synth/synth-decls.adb @@ -77,11 +77,19 @@ package body Synth.Decls is (Syn_Inst : Synth_Instance_Acc; Def : Node) return Type_Acc is El_Type : constant Node := Get_Element_Subtype (Def); + El_Typ : Type_Acc; Typ : Type_Acc; begin Synth_Subtype_Indication_If_Anonymous (Syn_Inst, El_Type); - Typ := Create_Unbounded_Array - (Get_Value_Type (Syn_Inst, El_Type)); + El_Typ := Get_Value_Type (Syn_Inst, El_Type); + + if El_Typ.Kind = Type_Bit + and then Is_One_Dimensional_Array_Type (Def) + then + Typ := Create_Unbounded_Vector (El_Typ); + else + Typ := Create_Unbounded_Array (El_Typ); + end if; return Typ; end Synth_Array_Type_Definition; @@ -230,6 +238,7 @@ package body Synth.Decls is El_Type : constant Node := Get_Element_Subtype (Atype); St_Indexes : constant Iir_Flist := Get_Index_Subtype_List (Atype); St_El : Iir; + Btyp : Type_Acc; Etyp : Type_Acc; Bnds : Bound_Array_Acc; begin @@ -246,16 +255,15 @@ package body Synth.Decls is Synth_Subtype_Indication (Syn_Inst, El_Type); end if; - Etyp := Get_Value_Type (Syn_Inst, El_Type); + Btyp := Get_Value_Type (Syn_Inst, Get_Base_Type (Atype)); - if Etyp.Kind = Type_Bit - and then Is_One_Dimensional_Array_Type (Atype) - then + if Btyp.Kind = Type_Unbounded_Vector then St_El := Get_Index_Type (St_Indexes, 0); return Create_Vector_Type - (Synth_Bounds_From_Range (Syn_Inst, St_El), Etyp); + (Synth_Bounds_From_Range (Syn_Inst, St_El), Btyp.Uvec_El); else -- FIXME: partially constrained arrays, subtype in indexes... + Etyp := Get_Value_Type (Syn_Inst, El_Type); Bnds := Create_Bound_Array (Iir_Index32 (Get_Nbr_Elements (St_Indexes))); for I in Flist_First .. Flist_Last (St_Indexes) loop diff --git a/src/synth/synth-expr.adb b/src/synth/synth-expr.adb index 645b09d8a..49a57dcec 100644 --- a/src/synth/synth-expr.adb +++ b/src/synth/synth-expr.adb @@ -225,6 +225,20 @@ package body Synth.Expr is return 0; end Get_Index_Offset; + function Get_Array_Bound (Typ : Type_Acc; Dim : Natural) + return Bound_Type is + begin + case Typ.Kind is + when Type_Vector => + pragma Assert (Dim = 0); + return Typ.Vbound; + when Type_Array => + return Typ.Abounds.D (Iir_Index32 (Dim + 1)); + when others => + raise Internal_Error; + end case; + end Get_Array_Bound; + procedure Fill_Array_Aggregate (Syn_Inst : Synth_Instance_Acc; Aggr : Node; Res : Value_Array_Acc; @@ -232,7 +246,7 @@ package body Synth.Expr is Dim : Natural; Const_P : out Boolean) is - Bound : Bound_Type renames Typ.Abounds.D (1); + Bound : constant Bound_Type := Get_Array_Bound (Typ, Dim); Aggr_Type : constant Node := Get_Type (Aggr); El_Type : constant Node := Get_Element_Subtype (Aggr_Type); Nbr_Dims : constant Natural := Get_Nbr_Dimensions (Aggr_Type); @@ -638,20 +652,35 @@ package body Synth.Expr is is Ndims : constant Natural := Get_Nbr_Dimensions (Aggr_Type); El_Type : constant Node := Get_Element_Subtype (Aggr_Type); - Bnds : Bound_Array_Acc; + El_Typ : Type_Acc; Res_Type : Type_Acc; Arr : Value_Array_Acc; Res : Value_Acc; Const_P : Boolean; begin + El_Typ := Get_Value_Type (Syn_Inst, El_Type); + -- Allocate the result. - Bnds := Create_Bound_Array (Iir_Index32 (Ndims)); - for I in 1 .. Ndims loop - Bnds.D (Iir_Index32 (I)) := - Synth_Array_Bounds (Syn_Inst, Aggr_Type, I - 1); - end loop; - Res_Type := Create_Array_Type - (Bnds, Get_Value (Syn_Inst, El_Type).Typ); + if Is_Vector_Type (Aggr_Type) then + declare + Bnd : Bound_Type; + begin + Bnd := Synth_Array_Bounds (Syn_Inst, Aggr_Type, 0); + Res_Type := Create_Vector_Type (Bnd, El_Typ); + end; + else + declare + Bnds : Bound_Array_Acc; + begin + Bnds := Create_Bound_Array (Iir_Index32 (Ndims)); + for I in 1 .. Ndims loop + Bnds.D (Iir_Index32 (I)) := + Synth_Array_Bounds (Syn_Inst, Aggr_Type, I - 1); + end loop; + Res_Type := Create_Array_Type (Bnds, El_Typ); + end; + end if; + Arr := Create_Value_Array (Iir_Index32 (Get_Array_Flat_Length (Res_Type))); @@ -829,6 +858,9 @@ package body Synth.Expr is pragma Assert (Vtype.Kind = Type_Vector or else Vtype.Kind = Type_Array); return Val; + when Type_Unbounded_Vector => + pragma Assert (Vtype.Kind = Type_Vector); + return Val; when Type_Record => -- TODO: handle elements. return Val; diff --git a/src/synth/synth-values.adb b/src/synth/synth-values.adb index 223aeb5cb..4cffaeedf 100644 --- a/src/synth/synth-values.adb +++ b/src/synth/synth-values.adb @@ -97,7 +97,8 @@ package body Synth.Values is | Type_Array | Type_Record => return True; - when Type_Unbounded_Array => + when Type_Unbounded_Array + | Type_Unbounded_Vector => return False; end case; end Is_Bounded_Type; @@ -272,6 +273,16 @@ package body Synth.Values is Uarr_El => El_Type))); end Create_Unbounded_Array; + function Create_Unbounded_Vector (El_Type : Type_Acc) return Type_Acc + is + subtype Unbounded_Type_Type is Type_Type (Type_Unbounded_Vector); + function Alloc is new Areapools.Alloc_On_Pool_Addr (Unbounded_Type_Type); + begin + return To_Type_Acc (Alloc (Current_Pool, (Kind => Type_Unbounded_Vector, + W => 0, + Uvec_El => El_Type))); + end Create_Unbounded_Vector; + function Get_Array_Element (Arr_Type : Type_Acc) return Type_Acc is begin case Arr_Type.Kind is @@ -429,15 +440,24 @@ package body Synth.Values is return Res; end Create_Value_Const_Array; - function Get_Array_Flat_Length (Typ : Type_Acc) return Width - is - Len : Width; + function Get_Array_Flat_Length (Typ : Type_Acc) return Width is begin - Len := 1; - for I in Typ.Abounds.D'Range loop - Len := Len * Typ.Abounds.D (I).Len; - end loop; - return Len; + case Typ.Kind is + when Type_Vector => + return Typ.Vbound.Len; + when Type_Array => + declare + Len : Width; + begin + Len := 1; + for I in Typ.Abounds.D'Range loop + Len := Len * Typ.Abounds.D (I).Len; + end loop; + return Len; + end; + when others => + raise Internal_Error; + end case; end Get_Array_Flat_Length; procedure Create_Array_Data (Arr : Value_Acc) diff --git a/src/synth/synth-values.ads b/src/synth/synth-values.ads index 81565e1fc..5c5c35e97 100644 --- a/src/synth/synth-values.ads +++ b/src/synth/synth-values.ads @@ -76,6 +76,7 @@ package Synth.Values is Type_Discrete, Type_Float, Type_Vector, + Type_Unbounded_Vector, -- A slice is for a slice of vector with dynamic bounds. So the bounds -- of the result aren't known, but its width is. @@ -112,6 +113,8 @@ package Synth.Values is when Type_Vector => Vbound : Bound_Type; Vec_El : Type_Acc; + when Type_Unbounded_Vector => + Uvec_El : Type_Acc; when Type_Slice => Slice_El : Type_Acc; when Type_Array => @@ -219,6 +222,7 @@ package Synth.Values is return Type_Acc; function Create_Vector_Type (Bnd : Bound_Type; El_Type : Type_Acc) return Type_Acc; + function Create_Unbounded_Vector (El_Type : Type_Acc) return Type_Acc; function Create_Slice_Type (W : Width; El_Type : Type_Acc) return Type_Acc; function Create_Bound_Array (Ndims : Iir_Index32) return Bound_Array_Acc; function Create_Array_Type (Bnd : Bound_Array_Acc; El_Type : Type_Acc) |