aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-07-26 03:53:59 +0200
committerTristan Gingold <tgingold@free.fr>2019-07-26 03:53:59 +0200
commit1aa373bd730caa2a558cc02f3f6a0fb269316a16 (patch)
tree9c61b3123bbc42c64e79e077a2362d6808ef553e /src
parent16b564158369b435372de417e2c0ce8e71af6419 (diff)
downloadghdl-1aa373bd730caa2a558cc02f3f6a0fb269316a16.tar.gz
ghdl-1aa373bd730caa2a558cc02f3f6a0fb269316a16.tar.bz2
ghdl-1aa373bd730caa2a558cc02f3f6a0fb269316a16.zip
synth: handle array aggregate.
Diffstat (limited to 'src')
-rw-r--r--src/synth/synth-context.adb2
-rw-r--r--src/synth/synth-expr.adb57
2 files changed, 32 insertions, 27 deletions
diff --git a/src/synth/synth-context.adb b/src/synth/synth-context.adb
index c638c5616..1d87df365 100644
--- a/src/synth/synth-context.adb
+++ b/src/synth/synth-context.adb
@@ -121,7 +121,7 @@ package body Synth.Context is
end if;
end;
when others =>
- raise Internal_Error;
+ Error_Kind ("alloc_object", Obj_Type);
end case;
end Alloc_Object;
diff --git a/src/synth/synth-expr.adb b/src/synth/synth-expr.adb
index caf0135df..74b07b446 100644
--- a/src/synth/synth-expr.adb
+++ b/src/synth/synth-expr.adb
@@ -492,37 +492,42 @@ package body Synth.Expr is
Uns32 (Len)));
end Synth_Bounds_From_Range;
+ function Synth_Aggregate_Array (Syn_Inst : Synth_Instance_Acc;
+ Aggr : Node;
+ Aggr_Type : Node) return Value_Acc
+ is
+ Ndims : constant Natural := Get_Nbr_Dimensions (Aggr_Type);
+ Bnds : Value_Bound_Array_Acc;
+ Res : Value_Acc;
+ begin
+ -- Allocate the result.
+ Bnds := Create_Value_Bound_Array (Iir_Index32 (Ndims));
+ for I in 1 .. Ndims loop
+ Bnds.D (Iir_Index32 (I)) :=
+ Synth_Array_Bounds (Syn_Inst, Aggr_Type, I - 1);
+ end loop;
+ Res := Create_Value_Array (Bnds);
+ Create_Array_Data (Res);
+
+ Fill_Array_Aggregate (Syn_Inst, Aggr, Res, 0);
+
+ if Is_Vector_Type (Aggr_Type) then
+ Res := Vectorize_Array (Res, Get_Element_Subtype (Aggr_Type));
+ end if;
+
+ return Res;
+ end Synth_Aggregate_Array;
+
+ -- Aggr_Type is the type from the context.
function Synth_Aggregate (Syn_Inst : Synth_Instance_Acc;
Aggr : Node;
Aggr_Type : Node) return Value_Acc is
begin
case Get_Kind (Aggr_Type) is
- when Iir_Kind_Array_Type_Definition
- | Iir_Kind_Array_Subtype_Definition =>
- if not Is_Vector_Type (Aggr_Type) then
- -- TODO: generalize, in particular multi-dim arrays.
- raise Internal_Error;
- end if;
- declare
- Bnd : Value_Bound_Acc;
- Bnds : Value_Bound_Array_Acc;
- Res : Value_Acc;
- begin
- -- Create bounds.
- Bnd := Synth_Array_Bounds (Syn_Inst, Aggr_Type, 0);
- -- Allocate result
- Bnds := Create_Value_Bound_Array (1);
- Bnds.D (1) := Bnd;
- Res := Create_Value_Array (Bnds);
- Create_Array_Data (Res);
- Fill_Array_Aggregate (Syn_Inst, Aggr, Res, 0);
- if Is_Vector_Type (Aggr_Type) then
- -- Vectorize
- Res := Vectorize_Array
- (Res, Get_Element_Subtype (Aggr_Type));
- end if;
- return Res;
- end;
+ when Iir_Kind_Array_Type_Definition =>
+ return Synth_Aggregate_Array (Syn_Inst, Aggr, Get_Type (Aggr));
+ when Iir_Kind_Array_Subtype_Definition =>
+ return Synth_Aggregate_Array (Syn_Inst, Aggr, Aggr_Type);
when Iir_Kind_Record_Type_Definition
| Iir_Kind_Record_Subtype_Definition =>
raise Internal_Error;