aboutsummaryrefslogtreecommitdiffstats
path: root/src/ortho/mcode/ortho_code-consts.adb
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2020-05-27 17:50:12 +0200
committerTristan Gingold <tgingold@free.fr>2020-05-28 17:47:48 +0200
commit691d4875f0710e0603a7ae563600f9a6c041c6d6 (patch)
tree529071dca47189003ebc87cc6e1c6afd5e12b975 /src/ortho/mcode/ortho_code-consts.adb
parent58756712b9465c24e1d2a198e5a03aae7ebbf774 (diff)
downloadghdl-691d4875f0710e0603a7ae563600f9a6c041c6d6.tar.gz
ghdl-691d4875f0710e0603a7ae563600f9a6c041c6d6.tar.bz2
ghdl-691d4875f0710e0603a7ae563600f9a6c041c6d6.zip
ortho: add a length parameter to start_array_aggr.
Diffstat (limited to 'src/ortho/mcode/ortho_code-consts.adb')
-rw-r--r--src/ortho/mcode/ortho_code-consts.adb42
1 files changed, 36 insertions, 6 deletions
diff --git a/src/ortho/mcode/ortho_code-consts.adb b/src/ortho/mcode/ortho_code-consts.adb
index 1b2146dc4..dcb9c13be 100644
--- a/src/ortho/mcode/ortho_code-consts.adb
+++ b/src/ortho/mcode/ortho_code-consts.adb
@@ -420,20 +420,29 @@ package body Ortho_Code.Consts is
end Finish_Record_Aggr;
- procedure Start_Array_Aggr (List : out O_Array_Aggr_List; Atype : O_Tnode)
+ procedure Start_Array_Aggr
+ (List : out O_Array_Aggr_List; Arr_Type : O_Tnode; Len : Unsigned_32)
is
- Num : constant Uns32 := Get_Type_Subarray_Length (Atype);
Val : Int32;
begin
- Val := Els.Allocate (Integer (Num));
+ case Get_Type_Kind (Arr_Type) is
+ when OT_Subarray =>
+ pragma Assert (Uns32 (Len) = Get_Type_Subarray_Length (Arr_Type));
+ when OT_Ucarray =>
+ null;
+ when others =>
+ -- The type of an array aggregate must be an array type.
+ raise Syntax_Error;
+ end case;
+ Val := Els.Allocate (Integer (Len));
Cnodes.Append (Cnode_Common'(Kind => OC_Array,
- Lit_Type => Atype));
+ Lit_Type => Arr_Type));
List := (Res => Cnodes.Last,
El => Val,
- Len => Num);
+ Len => Uns32 (Len));
Cnodes.Append (To_Cnode_Common (Cnode_Aggr'(Els => Val,
- Nbr => Int32 (Num))));
+ Nbr => Int32 (Len))));
end Start_Array_Aggr;
procedure New_Array_Aggr_El (List : in out O_Array_Aggr_List;
@@ -658,6 +667,27 @@ package body Ortho_Code.Consts is
end case;
end Get_Const_Bytes;
+ function Get_Const_Size (Cst : O_Cnode) return Uns32
+ is
+ T : constant O_Tnode := Get_Const_Type (Cst);
+ begin
+ case Get_Type_Kind (T) is
+ when OT_Ucarray =>
+ declare
+ Len : constant Int32 := Get_Const_Aggr_Length (Cst);
+ El_Sz : Uns32;
+ begin
+ if Len = 0 then
+ return 0;
+ end if;
+ El_Sz := Get_Const_Size (Get_Const_Aggr_Element (Cst, 0));
+ return Uns32 (Len) * El_Sz;
+ end;
+ when others =>
+ return Get_Type_Size (T);
+ end case;
+ end Get_Const_Size;
+
procedure Mark (M : out Mark_Type) is
begin
M.Cnode := Cnodes.Last;