aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2018-01-05 09:29:59 +0100
committerTristan Gingold <tgingold@free.fr>2018-01-11 12:51:47 +0100
commit2d0b6074af96f3375165afc7386b0e9071be206a (patch)
tree8205991632ab8a28d8b4eb17708076a272e89f67 /src
parent1e0718e33573d3b855e4e57006c0293a2fe0f40b (diff)
downloadghdl-2d0b6074af96f3375165afc7386b0e9071be206a.tar.gz
ghdl-2d0b6074af96f3375165afc7386b0e9071be206a.tar.bz2
ghdl-2d0b6074af96f3375165afc7386b0e9071be206a.zip
WIP: arrays of unbounded type.
Diffstat (limited to 'src')
-rw-r--r--src/vhdl/translate/trans-chap3.adb102
-rw-r--r--src/vhdl/translate/trans-chap3.ads22
-rw-r--r--src/vhdl/translate/trans-chap7.adb26
-rw-r--r--src/vhdl/translate/trans-foreach_non_composite.adb13
4 files changed, 133 insertions, 30 deletions
diff --git a/src/vhdl/translate/trans-chap3.adb b/src/vhdl/translate/trans-chap3.adb
index 63d32f3f9..3ff57a1cc 100644
--- a/src/vhdl/translate/trans-chap3.adb
+++ b/src/vhdl/translate/trans-chap3.adb
@@ -571,6 +571,28 @@ package body Trans.Chap3 is
(List, Create_Static_Type_Definition_Type_Range (Index));
end loop;
end;
+ if Binfo.B.El_Size /= O_Fnode_Null then
+ -- For arrays of unbounded type.
+ declare
+ El_Type : constant Iir := Get_Element_Subtype (Def);
+ El_Info : constant Type_Info_Acc := Get_Info (El_Type);
+ Sz_List : O_Record_Aggr_List;
+ Sz_Res : O_Cnode;
+ begin
+ New_Record_Aggr_El
+ (List, Create_Static_Composite_Subtype_Bounds (El_Type));
+
+ Start_Record_Aggr (Sz_List, Ghdl_Sizes_Type);
+ New_Record_Aggr_El
+ (Sz_List, New_Sizeof (El_Info.Ortho_Type (Mode_Value),
+ Ghdl_Index_Type));
+ New_Record_Aggr_El
+ (Sz_List, New_Sizeof (El_Info.Ortho_Type (Mode_Signal),
+ Ghdl_Index_Type));
+ Finish_Record_Aggr (Sz_List, Sz_Res);
+ New_Record_Aggr_El (List, Sz_Res);
+ end;
+ end if;
when Iir_Kind_Record_Subtype_Definition =>
declare
@@ -788,8 +810,8 @@ package body Trans.Chap3 is
El_Type : constant Iir := Get_Element_Subtype (Def);
El_Tinfo : constant Type_Info_Acc := Get_Info (El_Type);
begin
- if Is_Complex_Type (El_Tinfo) then
- if El_Tinfo.Type_Mode = Type_Mode_Array then
+ if Is_Complex_Type (El_Tinfo) or else Is_Unbounded_Type (El_Tinfo) then
+ if El_Tinfo.Type_Mode in Type_Mode_Arrays then
Info.B.Base_Type := El_Tinfo.B.Base_Ptr_Type;
Info.B.Base_Ptr_Type := El_Tinfo.B.Base_Ptr_Type;
else
@@ -2298,18 +2320,19 @@ package body Trans.Chap3 is
when Iir_Kind_Array_Subtype_Definition =>
Translate_Array_Element_Definition (Def);
- if Get_Index_Constraint_Flag (Def) then
- if Base_Info = null or else Base_Info.Type_Incomplete then
- -- This subtype also declare the base type. Create it.
- declare
- Mark : Id_Mark_Type;
- begin
- Push_Identifier_Prefix (Mark, "BT");
- Translate_Type_Definition (Base_Type);
- Pop_Identifier_Prefix (Mark);
- Base_Info := Get_Info (Base_Type);
- end;
- end if;
+ if Base_Info = null or else Base_Info.Type_Incomplete then
+ -- This subtype also declare the base type. Create it.
+ declare
+ Mark : Id_Mark_Type;
+ begin
+ Push_Identifier_Prefix (Mark, "BT");
+ Translate_Type_Definition (Base_Type);
+ Pop_Identifier_Prefix (Mark);
+ Base_Info := Get_Info (Base_Type);
+ end;
+ end if;
+
+ if Get_Constraint_State (Def) = Fully_Constrained then
Translate_Array_Subtype_Definition (Def);
Info.B := Base_Info.B;
Info.S := Base_Info.S;
@@ -2595,6 +2618,19 @@ package body Trans.Chap3 is
El_Tinfo.B.Bounds_Type, El_Tinfo.B.Bounds_Ptr_Type);
end Bounds_To_Element_Bounds;
+ function Array_Bounds_To_Element_Bounds (B : Mnode; Atype : Iir)
+ return Mnode
+ is
+ Arr_Tinfo : constant Type_Info_Acc := Get_Info (Atype);
+ El_Type : constant Iir := Get_Element_Subtype (Atype);
+ El_Tinfo : constant Type_Info_Acc := Get_Info (El_Type);
+ begin
+ return Lv2M
+ (New_Selected_Element (M2Lv (B), Arr_Tinfo.B.El_Bounds),
+ El_Tinfo, Mode_Value,
+ El_Tinfo.B.Bounds_Type, El_Tinfo.B.Bounds_Ptr_Type);
+ end Array_Bounds_To_Element_Bounds;
+
function Type_To_Range (Atype : Iir) return Mnode
is
Info : constant Type_Info_Acc := Get_Info (Atype);
@@ -2810,6 +2846,38 @@ package body Trans.Chap3 is
end case;
end Unbox_Record;
+ function Create_Maybe_Fat_Array_Element (Arr : Mnode; Arr_Type : Iir)
+ return Mnode
+ is
+ El_Type : constant Iir := Get_Element_Subtype (Arr_Type);
+ El_Info : constant Type_Info_Acc := Get_Info (El_Type);
+ El_Unbounded : constant Boolean := Is_Unbounded_Type (El_Info);
+ Kind : constant Object_Kind_Type := Get_Object_Kind (Arr);
+ Var_El : Mnode;
+ begin
+ if El_Unbounded then
+ Var_El := Create_Temp (El_Info, Kind);
+ New_Assign_Stmt
+ (M2Lp (Chap3.Get_Composite_Bounds (Var_El)),
+ M2Addr (Chap3.Array_Bounds_To_Element_Bounds
+ (Chap3.Get_Composite_Bounds (Arr), Arr_Type)));
+ return Var_El;
+ else
+ return Mnode_Null;
+ end if;
+ end Create_Maybe_Fat_Array_Element;
+
+ function Assign_Maybe_Fat_Array_Element (Var : Mnode; El : Mnode)
+ return Mnode is
+ begin
+ if Var = Mnode_Null then
+ return El;
+ else
+ New_Assign_Stmt (M2Lp (Chap3.Get_Composite_Base (Var)), M2Addr (El));
+ return Var;
+ end if;
+ end Assign_Maybe_Fat_Array_Element;
+
function Get_Bounds_Acc_Base
(Acc : O_Enode; D_Type : Iir) return O_Enode
is
@@ -2847,7 +2915,11 @@ package body Trans.Chap3 is
El_Tinfo : constant Type_Info_Acc := Get_Info (El_Type);
Kind : constant Object_Kind_Type := Get_Object_Kind (Base);
begin
- if Is_Complex_Type (El_Tinfo) then
+ if Is_Unbounded_Type (El_Tinfo) then
+ -- return Reindex_Unbounded_Array (Base, Atype, Index, El_Tinfo);
+ -- TODO
+ raise Internal_Error;
+ elsif Is_Complex_Type (El_Tinfo) then
return Reindex_Complex_Array (Base, Atype, Index, El_Tinfo);
else
return Lv2M (New_Indexed_Element (M2Lv (Base), Index),
diff --git a/src/vhdl/translate/trans-chap3.ads b/src/vhdl/translate/trans-chap3.ads
index c1e53695f..552813451 100644
--- a/src/vhdl/translate/trans-chap3.ads
+++ b/src/vhdl/translate/trans-chap3.ads
@@ -120,15 +120,28 @@ package Trans.Chap3 is
-- number of dimensions; these fields are a structure describing the
-- range of the dimension.
+ -- If the element subtype of ARR_TYPE is unbounded, create a fat pointer,
+ -- set the bounds of it (from ARR), and return it.
+ -- Otherwise, return a null mnode.
+ -- Used to build a var for a subelement of ARR.
+ function Create_Maybe_Fat_Array_Element (Arr : Mnode; Arr_Type : Iir)
+ return Mnode;
+
+ -- If the element subtype of the array is unbounded, set the base of VAR
+ -- from EL, and return it.
+ -- Otherwise directly return EL (VAR must be null).
+ function Assign_Maybe_Fat_Array_Element (Var : Mnode; El : Mnode)
+ return Mnode;
+
-- Index array BASE of type ATYPE with INDEX.
-- INDEX must be of type ghdl_index_type, thus no bounds checks are
-- performed.
function Index_Base (Base : Mnode; Atype : Iir; Index : O_Enode)
- return Mnode;
+ return Mnode;
-- Same for for slicing.
function Slice_Base (Base : Mnode; Atype : Iir; Index : O_Enode)
- return Mnode;
+ return Mnode;
-- Get the length of the array (the number of elements).
function Get_Array_Length (Arr : Mnode; Atype : Iir) return O_Enode;
@@ -179,6 +192,11 @@ package Trans.Chap3 is
-- element EL.
function Bounds_To_Element_Bounds (B : Mnode; El : Iir) return Mnode;
+ -- From an unbounded array bounds B, get the bounds for the (unbounded)
+ -- element.
+ function Array_Bounds_To_Element_Bounds (B : Mnode; Atype : Iir)
+ return Mnode;
+
-- Deallocate OBJ.
procedure Gen_Deallocate (Obj : O_Enode);
diff --git a/src/vhdl/translate/trans-chap7.adb b/src/vhdl/translate/trans-chap7.adb
index 438eb105c..09b005e92 100644
--- a/src/vhdl/translate/trans-chap7.adb
+++ b/src/vhdl/translate/trans-chap7.adb
@@ -4716,7 +4716,8 @@ package body Trans.Chap7 is
Var_I : O_Dnode;
Var_Len : O_Dnode;
Label : O_Snode;
- Le, Re : Mnode;
+ Base_Le, Base_Re : Mnode;
+ Var_L, Var_R : Mnode;
begin
if Global_Storage = O_Storage_External then
return;
@@ -4749,29 +4750,36 @@ package body Trans.Chap7 is
New_Assign_Stmt (New_Obj (Var_Len),
Chap3.Get_Array_Length (L, Arr_Type));
Close_Temp;
+ Open_Temp;
+ Var_L := Chap3.Create_Maybe_Fat_Array_Element (L, Arr_Type);
+ Var_R := Chap3.Create_Maybe_Fat_Array_Element (R, Arr_Type);
Init_Var (Var_I);
Start_Loop_Stmt (Label);
-- If the end of the array is reached, return TRUE.
Start_If_Stmt (If_Blk,
New_Compare_Op (ON_Ge,
- New_Obj_Value (Var_I),
- New_Obj_Value (Var_Len),
- Ghdl_Bool_Type));
+ New_Obj_Value (Var_I),
+ New_Obj_Value (Var_Len),
+ Ghdl_Bool_Type));
New_Return_Stmt (New_Lit (Std_Boolean_True_Node));
Finish_If_Stmt (If_Blk);
Open_Temp;
- Le := Chap3.Index_Base (Chap3.Get_Composite_Base (L), Arr_Type,
- New_Obj_Value (Var_I));
- Re := Chap3.Index_Base (Chap3.Get_Composite_Base (R), Arr_Type,
- New_Obj_Value (Var_I));
+ Base_Le := Chap3.Index_Base (Chap3.Get_Composite_Base (L), Arr_Type,
+ New_Obj_Value (Var_I));
+ Base_Le := Chap3.Assign_Maybe_Fat_Array_Element (Var_L, Base_Le);
+ Base_Re := Chap3.Index_Base (Chap3.Get_Composite_Base (R), Arr_Type,
+ New_Obj_Value (Var_I));
+ Base_Re := Chap3.Assign_Maybe_Fat_Array_Element (Var_R, Base_Re);
Start_If_Stmt
(If_Blk,
- New_Monadic_Op (ON_Not, Translate_Equality (Le, Re, El_Type)));
+ New_Monadic_Op (ON_Not,
+ Translate_Equality (Base_Le, Base_Re, El_Type)));
New_Return_Stmt (New_Lit (Std_Boolean_False_Node));
Finish_If_Stmt (If_Blk);
Close_Temp;
Inc_Var (Var_I);
Finish_Loop_Stmt (Label);
+ Close_Temp;
Finish_Operator_Instance_Use (F_Info);
Finish_Subprogram_Body;
end Translate_Predefined_Array_Equality_Body;
diff --git a/src/vhdl/translate/trans-foreach_non_composite.adb b/src/vhdl/translate/trans-foreach_non_composite.adb
index c2dc58b7e..1c203f68f 100644
--- a/src/vhdl/translate/trans-foreach_non_composite.adb
+++ b/src/vhdl/translate/trans-foreach_non_composite.adb
@@ -34,6 +34,9 @@ begin
when Type_Mode_Unbounded_Array
| Type_Mode_Array =>
declare
+ El_Type : constant Iir := Get_Element_Subtype (Targ_Type);
+ Var_El : Mnode;
+ El_Base : Mnode;
Var_Array : Mnode;
Var_Base : Mnode;
Var_Length : O_Dnode;
@@ -57,6 +60,8 @@ begin
New_Var_Decl
(Var_I, Wki_I, O_Storage_Local, Ghdl_Index_Type);
end if;
+ Var_El :=
+ Chap3.Create_Maybe_Fat_Array_Element (Var_Array, Targ_Type);
Init_Var (Var_I);
Start_Loop_Stmt (Label);
Gen_Exit_When
@@ -66,11 +71,11 @@ begin
Ghdl_Bool_Type));
Sub_Data := Update_Data_Array
(Composite_Data, Targ_Type, Var_I);
+ El_Base := Chap3.Index_Base (Var_Base, Targ_Type,
+ New_Value (New_Obj (Var_I)));
Foreach_Non_Composite
- (Chap3.Index_Base (Var_Base, Targ_Type,
- New_Value (New_Obj (Var_I))),
- Get_Element_Subtype (Targ_Type),
- Sub_Data);
+ (Chap3.Assign_Maybe_Fat_Array_Element (Var_El, El_Base),
+ El_Type, Sub_Data);
Inc_Var (Var_I);
Finish_Loop_Stmt (Label);
Finish_Data_Array (Composite_Data);