aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2018-11-28 06:10:47 +0100
committerTristan Gingold <tgingold@free.fr>2018-11-28 06:10:47 +0100
commit5e5355d878c3b5259b133ff0fdebe318cb5338d5 (patch)
treeac500e76243d714aefab7f61f972d97fa59f8bae /src
parentc5f48631616aaa6b4c8a03031f0458fdcba90b68 (diff)
downloadghdl-5e5355d878c3b5259b133ff0fdebe318cb5338d5.tar.gz
ghdl-5e5355d878c3b5259b133ff0fdebe318cb5338d5.tar.bz2
ghdl-5e5355d878c3b5259b133ff0fdebe318cb5338d5.zip
sem_expr: allow non-static length aggregate.
For #676
Diffstat (limited to 'src')
-rw-r--r--src/vhdl/sem_expr.adb28
-rw-r--r--src/vhdl/translate/trans-chap8.adb6
2 files changed, 24 insertions, 10 deletions
diff --git a/src/vhdl/sem_expr.adb b/src/vhdl/sem_expr.adb
index 23507b954..ef69e08f7 100644
--- a/src/vhdl/sem_expr.adb
+++ b/src/vhdl/sem_expr.adb
@@ -3376,6 +3376,7 @@ package body Sem_Expr is
Index_Constraint : Iir_Range_Expression; -- FIXME: 'range.
Dir : Iir_Direction;
Choice_Staticness : Iir_Staticness;
+ Len_Staticness : Iir_Staticness;
Expr_Staticness : Iir_Staticness;
Info : Array_Aggr_Info renames Infos (Dim);
@@ -3448,6 +3449,7 @@ package body Sem_Expr is
(Aggr, Min (Expr_Staticness, Get_Expr_Staticness (Aggr)));
-- Analyze choices.
+ Len_Staticness := Locally;
case Get_Kind (Aggr) is
when Iir_Kind_Aggregate =>
Assoc_Chain := Get_Association_Choices_Chain (Aggr);
@@ -3498,17 +3500,23 @@ package body Sem_Expr is
Expr : constant Iir := Get_Associated_Expr (Choice);
Expr_Type : constant Iir := Get_Type (Expr);
Expr_Index : Iir;
+ Index_Staticness : Iir_Staticness;
begin
if not Is_Error (Expr_Type) then
Expr_Index := Get_Index_Type (Expr_Type, 0);
- if Get_Type_Staticness (Expr_Index) = Locally
- then
- Len := Len + Natural
- (Eval_Discrete_Type_Length (Expr_Index));
- else
- -- TODO: length is not locally static...
- raise Internal_Error;
- end if;
+ Index_Staticness :=
+ Get_Type_Staticness (Expr_Index);
+ case Index_Staticness is
+ when Locally =>
+ Len := Len + Natural
+ (Eval_Discrete_Type_Length (Expr_Index));
+ when Globally | None =>
+ Len_Staticness := Iirs.Min
+ (Len_Staticness, Index_Staticness);
+ when Unknown =>
+ -- Must have been caught by Is_Error.
+ raise Internal_Error;
+ end case;
end if;
end;
end if;
@@ -3601,7 +3609,9 @@ package body Sem_Expr is
-- by S'LEFT where S is the index subtype of the base type of the
-- array; [...] the rightmost bound is determined by the direction
-- of the index subtype and the number of element.
- if Get_Type_Staticness (Index_Type) = Locally then
+ if Get_Type_Staticness (Index_Type) = Locally
+ and then Len_Staticness = Locally
+ then
Info.Index_Subtype := Create_Range_Subtype_By_Length
(Index_Type, Iir_Int64 (Len), Get_Location (Aggr));
end if;
diff --git a/src/vhdl/translate/trans-chap8.adb b/src/vhdl/translate/trans-chap8.adb
index 22921dd13..7726c3719 100644
--- a/src/vhdl/translate/trans-chap8.adb
+++ b/src/vhdl/translate/trans-chap8.adb
@@ -4308,7 +4308,11 @@ package body Trans.Chap8 is
if Get_Kind (Target) = Iir_Kind_Aggregate then
Chap3.Translate_Anonymous_Subtype_Definition (Target_Type, False);
Targ := Create_Temp (Get_Info (Target_Type), Mode_Signal);
- Chap4.Allocate_Complex_Object (Target_Type, Alloc_Stack, Targ);
+ if Get_Constraint_State (Target_Type) /= Fully_Constrained then
+ raise Internal_Error;
+ else
+ Chap4.Allocate_Complex_Object (Target_Type, Alloc_Stack, Targ);
+ end if;
Translate_Signal_Target_Aggr (Targ, Target, Target_Type);
else
if Mechanism = Signal_Assignment_Direct then