aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2018-01-07 04:21:49 +0100
committerTristan Gingold <tgingold@free.fr>2018-01-11 12:51:48 +0100
commit97314e1e9d5cf748c83ba63da8a449e339783009 (patch)
tree6673d09d1e3b2fe898ba22892ff4cbcb693e067e /src
parent2d0b6074af96f3375165afc7386b0e9071be206a (diff)
downloadghdl-97314e1e9d5cf748c83ba63da8a449e339783009.tar.gz
ghdl-97314e1e9d5cf748c83ba63da8a449e339783009.tar.bz2
ghdl-97314e1e9d5cf748c83ba63da8a449e339783009.zip
WIP: index arrays of unbounded elements.
Diffstat (limited to 'src')
-rw-r--r--src/vhdl/translate/trans-chap3.adb81
-rw-r--r--src/vhdl/translate/trans-chap3.ads4
-rw-r--r--src/vhdl/translate/trans-chap7.adb6
-rw-r--r--src/vhdl/translate/trans.adb12
-rw-r--r--src/vhdl/translate/trans.ads10
5 files changed, 96 insertions, 17 deletions
diff --git a/src/vhdl/translate/trans-chap3.adb b/src/vhdl/translate/trans-chap3.adb
index 3ff57a1cc..28579288b 100644
--- a/src/vhdl/translate/trans-chap3.adb
+++ b/src/vhdl/translate/trans-chap3.adb
@@ -919,6 +919,9 @@ package body Trans.Chap3 is
-- Type is bounded, but not statically.
Create_Size_Var (Def, Info);
+ elsif Get_Array_Element_Constraint (Def) /= Null_Iir then
+ -- Length is known, element is static.
+ raise Internal_Error;
else
-- Length is known. Create a constrained array.
Info.Ortho_Type (Mode_Signal) := O_Tnode_Null;
@@ -931,8 +934,7 @@ package body Trans.Chap3 is
Id := Create_Identifier ("SIG");
end case;
Info.Ortho_Type (I) := New_Constrained_Array_Type
- (Binfo.B.Base_Type (I),
- New_Unsigned_Literal (Ghdl_Index_Type, Unsigned_64 (Len)));
+ (Binfo.B.Base_Type (I), New_Index_Lit (Unsigned_64 (Len)));
New_Type_Decl (Id, Info.Ortho_Type (I));
end loop;
end if;
@@ -2631,6 +2633,24 @@ package body Trans.Chap3 is
El_Tinfo.B.Bounds_Type, El_Tinfo.B.Bounds_Ptr_Type);
end Array_Bounds_To_Element_Bounds;
+ function Array_Bounds_To_Element_Size (B : Mnode; Atype : Iir)
+ return O_Lnode
+ is
+ Arr_Tinfo : constant Type_Info_Acc := Get_Info (Atype);
+ Sizes : O_Lnode;
+ Field : O_Fnode;
+ begin
+ Sizes := New_Selected_Element (M2Lv (B), Arr_Tinfo.B.El_Size);
+ case Get_Object_Kind (B) is
+ when Mode_Value =>
+ Field := Ghdl_Sizes_Val;
+ when Mode_Signal =>
+ Field := Ghdl_Sizes_Sig;
+ end case;
+ Sizes := New_Selected_Element (Sizes, Field);
+ return Sizes;
+ end Array_Bounds_To_Element_Size;
+
function Type_To_Range (Atype : Iir) return Mnode
is
Info : constant Type_Info_Acc := Get_Info (Atype);
@@ -2889,6 +2909,19 @@ package body Trans.Chap3 is
D_Info.B.Base_Ptr_Type (Mode_Value));
end Get_Bounds_Acc_Base;
+ function Reindex_Array
+ (Base : Mnode; Atype : Iir; Index : O_Enode; Stride : O_Enode)
+ return O_Enode
+ is
+ El_Type : constant Iir := Get_Element_Subtype (Atype);
+ El_Tinfo : constant Type_Info_Acc := Get_Info (El_Type);
+ Kind : constant Object_Kind_Type := Get_Object_Kind (Base);
+ begin
+ return Add_Pointer (M2E (Base),
+ New_Dyadic_Op (ON_Mul_Ov, Stride, Index),
+ El_Tinfo.Ortho_Ptr_Type (Kind));
+ end Reindex_Array;
+
function Reindex_Complex_Array
(Base : Mnode; Atype : Iir; Index : O_Enode; Res_Info : Type_Info_Acc)
return Mnode
@@ -2897,15 +2930,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
- pragma Assert (Is_Complex_Type (El_Tinfo));
- return E2M
- (Add_Pointer
- (M2E (Base),
- New_Dyadic_Op (ON_Mul_Ov,
- New_Value (Get_Var (El_Tinfo.C (Kind).Size_Var)),
- Index),
- El_Tinfo.Ortho_Ptr_Type (Kind)),
- Res_Info, Kind);
+ return E2M (Reindex_Array
+ (Base, Atype,
+ Index,
+ New_Value (Get_Var (El_Tinfo.C (Kind).Size_Var))),
+ Res_Info, Kind);
end Reindex_Complex_Array;
function Index_Base (Base : Mnode; Atype : Iir; Index : O_Enode)
@@ -2927,6 +2956,36 @@ package body Trans.Chap3 is
end if;
end Index_Base;
+ function Index_Array (Arr : Mnode; Atype : Iir; Index : O_Enode)
+ return Mnode
+ is
+ El_Type : constant Iir := Get_Element_Subtype (Atype);
+ El_Tinfo : constant Type_Info_Acc := Get_Info (El_Type);
+ Kind : constant Object_Kind_Type := Get_Object_Kind (Arr);
+ begin
+ if Is_Unbounded_Type (El_Tinfo) then
+ return E2M
+ (Add_Pointer
+ (M2E (Get_Composite_Base (Arr)),
+ New_Dyadic_Op
+ (ON_Mul_Ov,
+ Index,
+ New_Value (Array_Bounds_To_Element_Size
+ (Get_Composite_Bounds (Arr), Atype))),
+ El_Tinfo.B.Base_Ptr_Type (Kind)),
+ El_Tinfo, Kind,
+ El_Tinfo.B.Base_Type (Kind),
+ El_Tinfo.B.Base_Ptr_Type (Kind));
+ elsif Is_Complex_Type (El_Tinfo) then
+ return Reindex_Complex_Array
+ (Get_Composite_Base (Arr), Atype, Index, El_Tinfo);
+ else
+ return Lv2M
+ (New_Indexed_Element (M2Lv (Get_Composite_Base (Arr)), Index),
+ El_Tinfo, Kind);
+ end if;
+ end Index_Array;
+
function Slice_Base (Base : Mnode; Atype : Iir; Index : O_Enode)
return Mnode
is
diff --git a/src/vhdl/translate/trans-chap3.ads b/src/vhdl/translate/trans-chap3.ads
index 552813451..ec77c1d52 100644
--- a/src/vhdl/translate/trans-chap3.ads
+++ b/src/vhdl/translate/trans-chap3.ads
@@ -139,6 +139,10 @@ package Trans.Chap3 is
function Index_Base (Base : Mnode; Atype : Iir; Index : O_Enode)
return Mnode;
+ -- Index array ARR of type ATYPE with INDEX.
+ function Index_Array (Arr : Mnode; Atype : Iir; Index : O_Enode)
+ return Mnode;
+
-- Same for for slicing.
function Slice_Base (Base : Mnode; Atype : Iir; Index : O_Enode)
return Mnode;
diff --git a/src/vhdl/translate/trans-chap7.adb b/src/vhdl/translate/trans-chap7.adb
index 09b005e92..44855162c 100644
--- a/src/vhdl/translate/trans-chap7.adb
+++ b/src/vhdl/translate/trans-chap7.adb
@@ -4764,11 +4764,9 @@ package body Trans.Chap7 is
New_Return_Stmt (New_Lit (Std_Boolean_True_Node));
Finish_If_Stmt (If_Blk);
Open_Temp;
- Base_Le := Chap3.Index_Base (Chap3.Get_Composite_Base (L), Arr_Type,
- New_Obj_Value (Var_I));
+ Base_Le := Chap3.Index_Array (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.Index_Array (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,
diff --git a/src/vhdl/translate/trans.adb b/src/vhdl/translate/trans.adb
index 4689150cc..06fc2c15d 100644
--- a/src/vhdl/translate/trans.adb
+++ b/src/vhdl/translate/trans.adb
@@ -1504,6 +1504,18 @@ package body Trans is
Ptype => T.Ortho_Ptr_Type (Kind)));
end E2M;
+ function E2M (E : O_Enode;
+ T : Type_Info_Acc;
+ Kind : Object_Kind_Type;
+ Vtype : O_Tnode;
+ Ptype : O_Tnode)
+ return Mnode is
+ begin
+ return Mnode'(M1 => (State => Mstate_E,
+ K => Kind, T => T, E => E,
+ Vtype => Vtype, Ptype => Ptype));
+ end E2M;
+
function Lv2M (L : O_Lnode; T : Type_Info_Acc; Kind : Object_Kind_Type)
return Mnode is
begin
diff --git a/src/vhdl/translate/trans.ads b/src/vhdl/translate/trans.ads
index 342af4847..15ce5d117 100644
--- a/src/vhdl/translate/trans.ads
+++ b/src/vhdl/translate/trans.ads
@@ -924,9 +924,9 @@ package Trans is
Type_Mode_Record,
-- Record with unbounded component(s).
Type_Mode_Unbounded_Record,
- -- Unbounded array type (used for unconstrained array).
+ -- Unbounded array type (used for unconstrained arrays).
Type_Mode_Unbounded_Array,
- -- Constrained array type (length is known at compile-time).
+ -- Constrained array type (for constrained arrays).
Type_Mode_Array,
-- Protected type
Type_Mode_Protected);
@@ -1798,6 +1798,12 @@ package Trans is
function E2M (E : O_Enode; T : Type_Info_Acc; Kind : Object_Kind_Type)
return Mnode;
+ function E2M (E : O_Enode;
+ T : Type_Info_Acc;
+ Kind : Object_Kind_Type;
+ Vtype : O_Tnode;
+ Ptype : O_Tnode)
+ return Mnode;
-- From a Lnode, general form (can be used for ranges, bounds, base...)
function Lv2M (L : O_Lnode;