aboutsummaryrefslogtreecommitdiffstats
path: root/src/synth
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2022-05-22 09:41:11 +0200
committerTristan Gingold <tgingold@free.fr>2022-05-22 09:41:11 +0200
commitd010636f5bb5cf00f6f26fd6e83a21b8a1dd5c2a (patch)
tree2d4f49db512c37a2ca289b9936d08c16c9897367 /src/synth
parent946320e0984df406f0e3c50cd3db0fb49df5ec9b (diff)
downloadghdl-d010636f5bb5cf00f6f26fd6e83a21b8a1dd5c2a.tar.gz
ghdl-d010636f5bb5cf00f6f26fd6e83a21b8a1dd5c2a.tar.bz2
ghdl-d010636f5bb5cf00f6f26fd6e83a21b8a1dd5c2a.zip
synth: also use one-dimensional unbounded arrays for objtypes
Diffstat (limited to 'src/synth')
-rw-r--r--src/synth/elab-vhdl_expr.adb2
-rw-r--r--src/synth/elab-vhdl_objtypes.adb63
-rw-r--r--src/synth/elab-vhdl_objtypes.ads20
-rw-r--r--src/synth/elab-vhdl_types.adb22
-rw-r--r--src/synth/elab-vhdl_values-debug.adb15
-rw-r--r--src/synth/synth-vhdl_aggr.adb2
6 files changed, 66 insertions, 58 deletions
diff --git a/src/synth/elab-vhdl_expr.adb b/src/synth/elab-vhdl_expr.adb
index fd57960cb..0ddc874cf 100644
--- a/src/synth/elab-vhdl_expr.adb
+++ b/src/synth/elab-vhdl_expr.adb
@@ -473,7 +473,7 @@ package body Elab.Vhdl_Expr is
pragma Assert (Is_Bounded_Type (Btyp.Arr_El));
Res := Create_Array_Type (Bnd, True, Btyp.Arr_El);
when Type_Unbounded_Array =>
- pragma Assert (Btyp.Uarr_Ndim = 1);
+ pragma Assert (Btyp.Ulast);
pragma Assert (Is_Bounded_Type (El_Typ));
Res := Create_Array_Type (Bnd, True, El_Typ);
when others =>
diff --git a/src/synth/elab-vhdl_objtypes.adb b/src/synth/elab-vhdl_objtypes.adb
index cd44324a7..13f28abe0 100644
--- a/src/synth/elab-vhdl_objtypes.adb
+++ b/src/synth/elab-vhdl_objtypes.adb
@@ -22,9 +22,6 @@ with System; use System;
with Mutils; use Mutils;
package body Elab.Vhdl_Objtypes is
- function To_Bound_Array_Acc is new Ada.Unchecked_Conversion
- (System.Address, Bound_Array_Acc);
-
function To_Rec_El_Array_Acc is new Ada.Unchecked_Conversion
(System.Address, Rec_El_Array_Acc);
@@ -87,8 +84,11 @@ package body Elab.Vhdl_Objtypes is
end if;
return Are_Types_Equal (L.Arr_El, R.Arr_El);
when Type_Unbounded_Array =>
- return L.Uarr_Ndim = R.Uarr_Ndim
- and then Are_Types_Equal (L.Uarr_El, R.Uarr_El);
+ if L.Ulast /= R.Ulast then
+ return False;
+ end if;
+ -- Also check index ?
+ return Are_Types_Equal (L.Uarr_El, R.Uarr_El);
when Type_Unbounded_Vector =>
return Are_Types_Equal (L.Uvec_El, R.Uvec_El);
when Type_Slice =>
@@ -113,6 +113,21 @@ package body Elab.Vhdl_Objtypes is
end case;
end Are_Types_Equal;
+ function Is_Last_Dimension (Arr : Type_Acc) return Boolean is
+ begin
+ case Arr.Kind is
+ when Type_Vector
+ | Type_Array =>
+ return Arr.Alast;
+ when Type_Unbounded_Vector =>
+ return True;
+ when Type_Unbounded_Array =>
+ return Arr.Ulast;
+ when others =>
+ raise Internal_Error;
+ end case;
+ end Is_Last_Dimension;
+
function Is_Null_Range (Rng : Discrete_Range_Type) return Boolean is
begin
case Rng.Dir is
@@ -314,32 +329,6 @@ package body Elab.Vhdl_Objtypes is
El);
end Create_Vec_Type_By_Length;
- function Create_Bound_Array (Ndims : Dim_Type) return Bound_Array_Acc
- is
- subtype Data_Type is Bound_Array (Ndims);
- Res : Address;
- begin
- -- Manually allocate the array to handle large arrays without
- -- creating a large temporary value.
- Areapools.Allocate
- (Current_Pool.all, Res,
- Data_Type'Size / Storage_Unit, Data_Type'Alignment);
-
- declare
- -- Discard the warnings for no pragma Import as we really want
- -- to use the default initialization.
- pragma Warnings (Off);
- Addr1 : constant Address := Res;
- Init : Data_Type;
- for Init'Address use Addr1;
- pragma Warnings (On);
- begin
- null;
- end;
-
- return To_Bound_Array_Acc (Res);
- end Create_Bound_Array;
-
function Create_Array_Type
(Bnd : Bound_Type; Last : Boolean; El_Type : Type_Acc) return Type_Acc
is
@@ -358,7 +347,7 @@ package body Elab.Vhdl_Objtypes is
end Create_Array_Type;
function Create_Unbounded_Array
- (Ndim : Dim_Type; El_Type : Type_Acc; Idx1 : Type_Acc) return Type_Acc
+ (Idx : Type_Acc; Last : Boolean; El_Type : Type_Acc) return Type_Acc
is
subtype Unbounded_Type_Type is Type_Type (Type_Unbounded_Array);
function Alloc is new Areapools.Alloc_On_Pool_Addr (Unbounded_Type_Type);
@@ -368,12 +357,12 @@ package body Elab.Vhdl_Objtypes is
Al => El_Type.Al,
Sz => 0,
W => 0,
- Uarr_Ndim => Ndim,
+ Ulast => Last,
Uarr_El => El_Type,
- Uarr_Idx1 => Idx1)));
+ Uarr_Idx => Idx)));
end Create_Unbounded_Array;
- function Create_Unbounded_Vector (El_Type : Type_Acc; Idx1 : Type_Acc)
+ function Create_Unbounded_Vector (El_Type : Type_Acc; Idx : Type_Acc)
return Type_Acc
is
subtype Unbounded_Type_Type is Type_Type (Type_Unbounded_Vector);
@@ -385,7 +374,7 @@ package body Elab.Vhdl_Objtypes is
Sz => 0,
W => 0,
Uvec_El => El_Type,
- Uvec_Idx1 => Idx1)));
+ Uvec_Idx1 => Idx)));
end Create_Unbounded_Vector;
function Get_Array_Element (Arr_Type : Type_Acc) return Type_Acc is
@@ -424,7 +413,7 @@ package body Elab.Vhdl_Objtypes is
when Type_Unbounded_Vector =>
return Typ.Uvec_Idx1;
when Type_Unbounded_Array =>
- return Typ.Uarr_Idx1;
+ return Typ.Uarr_Idx;
when others =>
raise Internal_Error;
end case;
diff --git a/src/synth/elab-vhdl_objtypes.ads b/src/synth/elab-vhdl_objtypes.ads
index c9f1a4894..93376d652 100644
--- a/src/synth/elab-vhdl_objtypes.ads
+++ b/src/synth/elab-vhdl_objtypes.ads
@@ -56,14 +56,6 @@ package Elab.Vhdl_Objtypes is
Len : Uns32;
end record;
- type Bound_Array_Type is array (Dim_Type range <>) of Bound_Type;
-
- type Bound_Array (Ndim : Dim_Type) is record
- D : Bound_Array_Type (1 .. Ndim);
- end record;
-
- type Bound_Array_Acc is access Bound_Array;
-
type Type_Kind is
(
Type_Bit,
@@ -151,11 +143,11 @@ package Elab.Vhdl_Objtypes is
Uvec_El : Type_Acc;
Uvec_Idx1 : Type_Acc;
when Type_Unbounded_Array =>
- Uarr_Ndim : Dim_Type;
Uarr_El : Type_Acc;
+ Ulast : Boolean;
-- Type of the first index. The only place we need the index is
-- for concatenation.
- Uarr_Idx1 : Type_Acc;
+ Uarr_Idx : Type_Acc;
when Type_Record
| Type_Unbounded_Record =>
Rec : Rec_El_Array_Acc;
@@ -206,15 +198,14 @@ package Elab.Vhdl_Objtypes 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; Idx1 : Type_Acc)
+ function Create_Unbounded_Vector (El_Type : Type_Acc; Idx : Type_Acc)
return Type_Acc;
function Create_Slice_Type (Len : Uns32; El_Type : Type_Acc)
return Type_Acc;
- function Create_Bound_Array (Ndims : Dim_Type) return Bound_Array_Acc;
function Create_Array_Type
(Bnd : Bound_Type; Last : Boolean; El_Type : Type_Acc) return Type_Acc;
function Create_Unbounded_Array
- (Ndim : Dim_Type; El_Type : Type_Acc; Idx1 : Type_Acc) return Type_Acc;
+ (Idx : Type_Acc; Last : Boolean; El_Type : Type_Acc) return Type_Acc;
function Create_Rec_El_Array (Nels : Iir_Index32) return Rec_El_Array_Acc;
function Create_Record_Type (Els : Rec_El_Array_Acc) return Type_Acc;
@@ -232,6 +223,9 @@ package Elab.Vhdl_Objtypes is
-- Return the first index of an unbounded array or vector.
function Get_Uarray_First_Index (Typ : Type_Acc) return Type_Acc;
+ -- Return True iff ARR is the last dimension of a multidimensional array.
+ function Is_Last_Dimension (Arr : Type_Acc) return Boolean;
+
-- Return the bounds of dimension DIM of a vector/array. For a vector,
-- DIM must be 1.
function Get_Array_Bound (Typ : Type_Acc; Dim : Dim_Type)
diff --git a/src/synth/elab-vhdl_types.adb b/src/synth/elab-vhdl_types.adb
index 82e63da15..527c825e2 100644
--- a/src/synth/elab-vhdl_types.adb
+++ b/src/synth/elab-vhdl_types.adb
@@ -227,13 +227,17 @@ package body Elab.Vhdl_Types is
Synth_Subtype_Indication_If_Anonymous (Syn_Inst, El_Type);
El_Typ := Get_Subtype_Object (Syn_Inst, El_Type);
- Idx := Get_Index_Type (Def, 0);
- Idx_Typ := Get_Subtype_Object (Syn_Inst, Idx);
-
if El_Typ.Kind in Type_Nets and then Ndims = 1 then
+ Idx := Get_Index_Type (Def, 0);
+ Idx_Typ := Get_Subtype_Object (Syn_Inst, Idx);
Typ := Create_Unbounded_Vector (El_Typ, Idx_Typ);
else
- Typ := Create_Unbounded_Array (Dim_Type (Ndims), El_Typ, Idx_Typ);
+ Typ := El_Typ;
+ for I in reverse 1 .. Ndims loop
+ Idx := Get_Index_Type (Def, 0);
+ Idx_Typ := Get_Subtype_Object (Syn_Inst, Idx);
+ Typ := Create_Unbounded_Array (Idx_Typ, I = Ndims, Typ);
+ end loop;
end if;
return Typ;
end Synth_Array_Type_Definition;
@@ -489,7 +493,15 @@ package body Elab.Vhdl_Types is
-- element.
El_Typ := Synth_Subtype_Indication_If_Anonymous (Syn_Inst, El_Type);
else
- El_Typ := Get_Array_Element (Parent_Typ);
+ El_Typ := Parent_Typ;
+ loop
+ if Is_Last_Dimension (El_Typ) then
+ El_Typ := Get_Array_Element (El_Typ);
+ exit;
+ else
+ El_Typ := Get_Array_Element (El_Typ);
+ end if;
+ end loop;
end if;
if not Get_Index_Constraint_Flag (Atype) then
diff --git a/src/synth/elab-vhdl_values-debug.adb b/src/synth/elab-vhdl_values-debug.adb
index c149c2eb0..2faf45b7b 100644
--- a/src/synth/elab-vhdl_values-debug.adb
+++ b/src/synth/elab-vhdl_values-debug.adb
@@ -131,7 +131,20 @@ package body Elab.Vhdl_Values.Debug is
when Type_Unbounded_Vector =>
Put ("unbounded vector");
when Type_Unbounded_Array =>
- Put ("unbounded array");
+ Put ("unbounded arr (");
+ declare
+ It : Type_Acc;
+ begin
+ It := T;
+ loop
+ Put ("<>");
+ exit when It.Ulast;
+ Put (", ");
+ It := It.Uarr_El;
+ end loop;
+ Put (") of ");
+ Debug_Typ1 (It.Uarr_El);
+ end;
when Type_Protected =>
Put ("protected");
end case;
diff --git a/src/synth/synth-vhdl_aggr.adb b/src/synth/synth-vhdl_aggr.adb
index 2115fde07..0694a99b0 100644
--- a/src/synth/synth-vhdl_aggr.adb
+++ b/src/synth/synth-vhdl_aggr.adb
@@ -138,7 +138,7 @@ package body Synth.Vhdl_Aggr is
begin
Nbr_Els := Nbr_Els + 1;
- if Typ.Kind = Type_Vector or else Typ.Alast then
+ if Typ.Alast then
pragma Assert (Dim = Strides'Last);
Val := Synth_Expression_With_Type (Syn_Inst, Value, El_Typ);
Val := Synth_Subtype_Conversion (Ctxt, Val, El_Typ, False, Value);