aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-09-05 11:15:06 +0200
committerTristan Gingold <tgingold@free.fr>2019-09-05 11:15:06 +0200
commit7585dba6b20036cd981d0434d27643f4a5a80244 (patch)
tree7e9711248e21b2858ef29e1fb550e5a8c900efb8
parented03458afa64cbd19a4ab35e651582e73096bfaf (diff)
downloadghdl-7585dba6b20036cd981d0434d27643f4a5a80244.tar.gz
ghdl-7585dba6b20036cd981d0434d27643f4a5a80244.tar.bz2
ghdl-7585dba6b20036cd981d0434d27643f4a5a80244.zip
synth: handle const record aggregates.
-rw-r--r--src/synth/synth-context.adb14
-rw-r--r--src/synth/synth-expr.adb33
-rw-r--r--src/synth/synth-values.adb25
-rw-r--r--src/synth/synth-values.ads13
4 files changed, 64 insertions, 21 deletions
diff --git a/src/synth/synth-context.adb b/src/synth/synth-context.adb
index b87f9b06b..48a0114b3 100644
--- a/src/synth/synth-context.adb
+++ b/src/synth/synth-context.adb
@@ -388,7 +388,7 @@ package body Synth.Context is
raise Internal_Error;
end if;
when Value_Const_Array
- | Value_Record =>
+ | Value_Const_Record =>
declare
W : constant Width := Get_Type_Width (Val.Typ);
Nd : constant Digit_Index := Digit_Index ((W + 31) / 32);
@@ -424,6 +424,18 @@ package body Synth.Context is
Build (Build_Context, C, Res);
return Res;
end;
+ when Value_Record =>
+ declare
+ use Netlists.Concats;
+ C : Concat_Type;
+ Res : Net;
+ begin
+ for I in Val.Rec.V'Range loop
+ Append (C, Get_Net (Val.Rec.V (I)));
+ end loop;
+ Build (Build_Context, C, Res);
+ return Res;
+ end;
when others =>
raise Internal_Error;
end case;
diff --git a/src/synth/synth-expr.adb b/src/synth/synth-expr.adb
index 7b0553d38..4bb556a22 100644
--- a/src/synth/synth-expr.adb
+++ b/src/synth/synth-expr.adb
@@ -59,8 +59,12 @@ package body Synth.Expr is
| Value_Wire
| Value_Mux2 =>
return False;
- when Value_Const_Array =>
+ when Value_Const_Array
+ | Value_Const_Record =>
return True;
+ when Value_Array
+ | Value_Record =>
+ return False;
when others =>
-- TODO.
raise Internal_Error;
@@ -379,7 +383,8 @@ package body Synth.Expr is
procedure Fill_Record_Aggregate (Syn_Inst : Synth_Instance_Acc;
Aggr : Node;
- Res : Value_Acc)
+ Rec : Value_Array_Acc;
+ Const_P : out Boolean)
is
El_List : constant Node_Flist :=
Get_Elements_Declaration_List (Get_Type (Aggr));
@@ -393,12 +398,16 @@ package body Synth.Expr is
begin
Val := Synth_Expression_With_Type
(Syn_Inst, Value, Get_Type (Get_Nth_Element (El_List, Pos)));
- Res.Rec.V (Iir_Index32 (Pos + 1)) := Val;
+ Rec.V (Iir_Index32 (Pos + 1)) := Val;
+ if Const_P and not Is_Const (Val) then
+ Const_P := False;
+ end if;
end Set_Elem;
begin
Assoc := Get_Association_Choices_Chain (Aggr);
Pos := 0;
- Res.Rec.V := (others => null);
+ Const_P := True;
+ Rec.V := (others => null);
while Is_Valid (Assoc) loop
Value := Get_Associated_Expr (Assoc);
loop
@@ -407,8 +416,8 @@ package body Synth.Expr is
Set_Elem (Pos);
Pos := Pos + 1;
when Iir_Kind_Choice_By_Others =>
- for I in Res.Rec.V'Range loop
- if Res.Rec.V (I) = null then
+ for I in Rec.V'Range loop
+ if Rec.V (I) = null then
Set_Elem (Natural (I - 1));
end if;
end loop;
@@ -749,13 +758,21 @@ package body Synth.Expr is
Aggr_Type : Node) return Value_Acc
is
Res_Type : Type_Acc;
+ Arr : Value_Array_Acc;
Res : Value_Acc;
+ Const_P : Boolean;
begin
-- Allocate the result.
Res_Type := Get_Value_Type (Syn_Inst, Aggr_Type);
- Res := Create_Value_Record (Res_Type);
+ Arr := Create_Value_Array (Res_Type.Rec.Len);
- Fill_Record_Aggregate (Syn_Inst, Aggr, Res);
+ Fill_Record_Aggregate (Syn_Inst, Aggr, Arr, Const_P);
+
+ if Const_P then
+ Res := Create_Value_Const_Record (Res_Type, Arr);
+ else
+ Res := Create_Value_Record (Res_Type, Arr);
+ end if;
return Res;
end Synth_Aggregate_Record;
diff --git a/src/synth/synth-values.adb b/src/synth/synth-values.adb
index 4ca48933a..ded8e6a1b 100644
--- a/src/synth/synth-values.adb
+++ b/src/synth/synth-values.adb
@@ -357,22 +357,31 @@ package body Synth.Values is
return Res;
end Create_Value_Array;
- function Create_Value_Record (Typ : Type_Acc) return Value_Acc
+ function Create_Value_Record (Typ : Type_Acc; Els : Value_Array_Acc)
+ return Value_Acc
is
subtype Value_Type_Record is Value_Type (Value_Record);
function Alloc is new Areapools.Alloc_On_Pool_Addr (Value_Type_Record);
-
- Res : Value_Acc;
- Rec_El : Value_Array_Acc;
begin
- Rec_El := Create_Value_Array (Typ.Rec.Len);
- Res := To_Value_Acc (Alloc (Current_Pool,
+ return To_Value_Acc (Alloc (Current_Pool,
(Kind => Value_Record,
Typ => Typ,
- Rec => Rec_El)));
- return Res;
+ Rec => Els)));
end Create_Value_Record;
+ function Create_Value_Const_Record (Typ : Type_Acc; Els : Value_Array_Acc)
+ return Value_Acc
+ is
+ subtype Value_Type_Const_Record is Value_Type (Value_Const_Record);
+ function Alloc is
+ new Areapools.Alloc_On_Pool_Addr (Value_Type_Const_Record);
+ begin
+ return To_Value_Acc (Alloc (Current_Pool,
+ (Kind => Value_Const_Record,
+ Typ => Typ,
+ Rec => Els)));
+ end Create_Value_Const_Record;
+
function Create_Value_Instance (Inst : Instance_Id) return Value_Acc
is
subtype Value_Type_Instance is Value_Type (Value_Instance);
diff --git a/src/synth/synth-values.ads b/src/synth/synth-values.ads
index 744791a29..e7d5acc20 100644
--- a/src/synth/synth-values.ads
+++ b/src/synth/synth-values.ads
@@ -136,12 +136,13 @@ package Synth.Values is
Value_Float,
- -- An array.
+ -- An array (const if all elements are constants).
Value_Array,
Value_Const_Array,
- -- A record.
+ -- A record (const if all elements are constants).
Value_Record,
+ Value_Const_Record,
-- A package.
Value_Instance,
@@ -185,7 +186,8 @@ package Synth.Values is
when Value_Array
| Value_Const_Array =>
Arr : Value_Array_Acc;
- when Value_Record =>
+ when Value_Record
+ | Value_Const_Record =>
Rec : Value_Array_Acc;
when Value_Instance =>
Instance : Instance_Id;
@@ -253,7 +255,10 @@ package Synth.Values is
-- Allocate the ARR component of the Value_Type ARR, using BOUNDS.
procedure Create_Array_Data (Arr : Value_Acc);
- function Create_Value_Record (Typ : Type_Acc) return Value_Acc;
+ function Create_Value_Record (Typ : Type_Acc; Els : Value_Array_Acc)
+ return Value_Acc;
+ function Create_Value_Const_Record (Typ : Type_Acc; Els : Value_Array_Acc)
+ return Value_Acc;
function Create_Value_Instance (Inst : Instance_Id) return Value_Acc;