aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2019-09-22 19:58:12 +0200
committerTristan Gingold <tgingold@free.fr>2019-09-22 19:58:12 +0200
commitdfdcfa6a6db7e44fba39fc7b9758ff68cdb7f313 (patch)
tree36f6a8020c164f3e9ea4133315500e0565b6ef8d
parentac8b203059b2d054880550c72adef815ea29950d (diff)
downloadghdl-dfdcfa6a6db7e44fba39fc7b9758ff68cdb7f313.tar.gz
ghdl-dfdcfa6a6db7e44fba39fc7b9758ff68cdb7f313.tar.bz2
ghdl-dfdcfa6a6db7e44fba39fc7b9758ff68cdb7f313.zip
synth: preliminary work for subtype conversions on interfaces.
-rw-r--r--src/synth/synth-expr.adb13
-rw-r--r--src/synth/synth-expr.ads9
-rw-r--r--src/synth/synth-oper.adb4
-rw-r--r--src/synth/synth-stmts.adb13
4 files changed, 26 insertions, 13 deletions
diff --git a/src/synth/synth-expr.adb b/src/synth/synth-expr.adb
index bba515707..645b09d8a 100644
--- a/src/synth/synth-expr.adb
+++ b/src/synth/synth-expr.adb
@@ -751,10 +751,13 @@ package body Synth.Expr is
return Create_Value_Const_Array (Res_Type, Arr);
end Synth_Simple_Aggregate;
- function Synth_Subtype_Conversion
- (Val : Value_Acc; Dtype : Type_Acc; Loc : Source.Syn_Src)
- return Value_Acc
+ function Synth_Subtype_Conversion (Val : Value_Acc;
+ Dtype : Type_Acc;
+ Bounds : Boolean;
+ Loc : Source.Syn_Src)
+ return Value_Acc
is
+ pragma Unreferenced (Bounds);
Vtype : constant Type_Acc := Val.Typ;
begin
case Dtype.Kind is
@@ -812,12 +815,14 @@ package body Synth.Expr is
-- TODO: check range
return Val;
when Type_Vector =>
+ -- pragma Assert (Vtype.Kind = Type_Vector);
-- TODO: check width
return Val;
when Type_Slice =>
-- TODO: check width
return Val;
when Type_Array =>
+ pragma Assert (Vtype.Kind = Type_Array);
-- TODO: check bounds, handle elements
return Val;
when Type_Unbounded_Array =>
@@ -1514,7 +1519,7 @@ package body Synth.Expr is
| Iir_Kind_Signal_Declaration => -- For PSL.
Res := Synth_Name (Syn_Inst, Expr);
return Synth_Subtype_Conversion
- (Res, Get_Value_Type (Syn_Inst, Expr_Type), Expr);
+ (Res, Get_Value_Type (Syn_Inst, Expr_Type), False, Expr);
when Iir_Kind_Reference_Name =>
return Synth_Name (Syn_Inst, Get_Named_Entity (Expr));
when Iir_Kind_Indexed_Name =>
diff --git a/src/synth/synth-expr.ads b/src/synth/synth-expr.ads
index 5ce27e49b..142a8a3a2 100644
--- a/src/synth/synth-expr.ads
+++ b/src/synth/synth-expr.ads
@@ -32,9 +32,12 @@ package Synth.Expr is
procedure Set_Location (N : Net; Loc : Node);
pragma Inline (Set_Location);
- function Synth_Subtype_Conversion
- (Val : Value_Acc; Dtype : Type_Acc; Loc : Source.Syn_Src)
- return Value_Acc;
+ -- Perform a subtype conversion. Check constraints.
+ function Synth_Subtype_Conversion (Val : Value_Acc;
+ Dtype : Type_Acc;
+ Bounds : Boolean;
+ Loc : Source.Syn_Src)
+ return Value_Acc;
function Get_Const_Discrete (V : Value_Acc) return Int64;
diff --git a/src/synth/synth-oper.adb b/src/synth/synth-oper.adb
index 8f960a6c2..eb7bc6cef 100644
--- a/src/synth/synth-oper.adb
+++ b/src/synth/synth-oper.adb
@@ -217,8 +217,8 @@ package body Synth.Oper is
begin
pragma Assert (Left_Type = Right_Type);
Typ := Get_Value_Type (Syn_Inst, Left_Type);
- L := Synth_Subtype_Conversion (Left, Typ, Expr);
- R := Synth_Subtype_Conversion (Right, Typ, Expr);
+ L := Synth_Subtype_Conversion (Left, Typ, False, Expr);
+ R := Synth_Subtype_Conversion (Right, Typ, False, Expr);
N := Build_Compare (Build_Context, Id, Get_Net (L), Get_Net (R));
Set_Location (N, Expr);
return Create_Value_Net (N, Boolean_Type);
diff --git a/src/synth/synth-stmts.adb b/src/synth/synth-stmts.adb
index dbc11c28a..adff77778 100644
--- a/src/synth/synth-stmts.adb
+++ b/src/synth/synth-stmts.adb
@@ -83,7 +83,7 @@ package body Synth.Stmts is
Loc : Source.Syn_Src) is
begin
Phi_Assign (Build_Context, Wid,
- Get_Net (Synth_Subtype_Conversion (Val, Typ, Loc)),
+ Get_Net (Synth_Subtype_Conversion (Val, Typ, False, Loc)),
Offset);
end Synth_Assign;
@@ -1109,6 +1109,7 @@ package body Synth.Stmts is
Assoc_Chain : Node)
is
Inter : Node;
+ Inter_Type : Node;
Assoc : Node;
Assoc_Inter : Node;
Actual : Node;
@@ -1118,6 +1119,7 @@ package body Synth.Stmts is
Assoc_Inter := Inter_Chain;
while Is_Valid (Assoc) loop
Inter := Get_Association_Interface (Assoc, Assoc_Inter);
+ Inter_Type := Get_Type (Inter);
case Iir_Parameter_Modes (Get_Mode (Inter)) is
when Iir_In_Mode =>
@@ -1125,11 +1127,11 @@ package body Synth.Stmts is
when Iir_Kind_Association_Element_Open =>
Actual := Get_Default_Value (Inter);
Val := Synth_Expression_With_Type
- (Subprg_Inst, Actual, Get_Type (Inter));
+ (Subprg_Inst, Actual, Inter_Type);
when Iir_Kind_Association_Element_By_Expression =>
Actual := Get_Actual (Assoc);
Val := Synth_Expression_With_Type
- (Caller_Inst, Actual, Get_Type (Inter));
+ (Caller_Inst, Actual, Inter_Type);
when others =>
raise Internal_Error;
end case;
@@ -1138,6 +1140,9 @@ package body Synth.Stmts is
raise Internal_Error;
end case;
+ Val := Synth_Subtype_Conversion
+ (Val, Get_Value_Type (Subprg_Inst, Inter_Type), True, Assoc);
+
case Iir_Kinds_Interface_Object_Declaration (Get_Kind (Inter)) is
when Iir_Kind_Interface_Constant_Declaration
| Iir_Kind_Interface_Variable_Declaration =>
@@ -1446,7 +1451,7 @@ package body Synth.Stmts is
if Expr /= Null_Node then
-- Return in function.
Val := Synth_Expression (C.Inst, Expr);
- Val := Synth_Subtype_Conversion (Val, C.Ret_Typ, Stmt);
+ Val := Synth_Subtype_Conversion (Val, C.Ret_Typ, False, Stmt);
if C.Nbr_Ret = 0 then
C.Ret_Value := Val;