diff options
author | Tristan Gingold <tgingold@free.fr> | 2021-09-07 05:59:50 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2021-09-07 18:20:04 +0200 |
commit | 2ef89e53dd5baf684005afb4c955eb678b3d551f (patch) | |
tree | 0677699a86e7a5d93cd848456521b341a1992e04 /src | |
parent | a00dcb23d7dd4ea2a12cff28a87b8c0129e78fe7 (diff) | |
download | ghdl-2ef89e53dd5baf684005afb4c955eb678b3d551f.tar.gz ghdl-2ef89e53dd5baf684005afb4c955eb678b3d551f.tar.bz2 ghdl-2ef89e53dd5baf684005afb4c955eb678b3d551f.zip |
trans-chap3: add a stride parameter to index_array. For #1831
Diffstat (limited to 'src')
-rw-r--r-- | src/vhdl/translate/trans-chap3.adb | 33 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap3.ads | 6 |
2 files changed, 21 insertions, 18 deletions
diff --git a/src/vhdl/translate/trans-chap3.adb b/src/vhdl/translate/trans-chap3.adb index b036f4d5f..9291bd38b 100644 --- a/src/vhdl/translate/trans-chap3.adb +++ b/src/vhdl/translate/trans-chap3.adb @@ -3104,8 +3104,10 @@ package body Trans.Chap3 is return E2M (Res, Res_Info, Kind); end Reindex_Complex_Array; - function Index_Base (Base : Mnode; Atype : Iir; Index : O_Enode) - return Mnode + function Index_Base (Base : Mnode; + Atype : Iir; + Index : O_Enode; + Stride : O_Enode := O_Enode_Null) return Mnode is Arr_Tinfo : constant Type_Info_Acc := Get_Type_Info (Base); Kind : constant Object_Kind_Type := Get_Object_Kind (Base); @@ -3119,6 +3121,13 @@ package body Trans.Chap3 is -- If the array is fully constrained it can be indexed. return Lv2M (New_Indexed_Element (M2Lv (Base), Index), El_Tinfo, Kind); + elsif Is_Unbounded_Type (El_Tinfo) then + return E2M (Add_Pointer (M2E (Base), + New_Dyadic_Op (ON_Mul_Ov, Index, Stride), + El_Tinfo.B.Base_Ptr_Type (Kind)), + El_Tinfo, Kind, + El_Tinfo.B.Base_Type (Kind), + El_Tinfo.B.Base_Ptr_Type (Kind)); end if; -- If the element type of the base type is static, the array @@ -3148,26 +3157,18 @@ package body Trans.Chap3 is El_Tinfo : constant Type_Info_Acc := Get_Info (El_Type); Kind : constant Object_Kind_Type := Get_Object_Kind (Arr); Base : Mnode; + Stride : O_Enode; begin Base := Get_Composite_Base (Arr); -- For indexing, we need to consider the size of elements. if Is_Unbounded_Type (El_Tinfo) then - return E2M - (Add_Pointer - (M2E (Base), - New_Dyadic_Op - (ON_Mul_Ov, - Index, - New_Value (Array_Bounds_To_Element_Size - (Get_Composite_Bounds (Arr), Atype, - Get_Object_Kind (Arr)))), - El_Tinfo.B.Base_Ptr_Type (Kind)), - El_Tinfo, Kind, - El_Tinfo.B.Base_Type (Kind), - El_Tinfo.B.Base_Ptr_Type (Kind)); + Stride := New_Value + (Array_Bounds_To_Element_Size + (Get_Composite_Bounds (Arr), Atype, Kind)); else - return Index_Base (Base, Atype, Index); + Stride := O_Enode_Null; end if; + return Index_Base (Base, Atype, Index, Stride); end Index_Array; function Slice_Base diff --git a/src/vhdl/translate/trans-chap3.ads b/src/vhdl/translate/trans-chap3.ads index 92338bc93..78e7a324f 100644 --- a/src/vhdl/translate/trans-chap3.ads +++ b/src/vhdl/translate/trans-chap3.ads @@ -143,8 +143,10 @@ package Trans.Chap3 is -- 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; + function Index_Base (Base : Mnode; + Atype : Iir; + Index : O_Enode; + Stride : O_Enode := O_Enode_Null) return Mnode; -- Index array ARR of type ATYPE with INDEX. -- Return the base. |