aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2023-03-26 21:02:55 +0200
committerTristan Gingold <tgingold@free.fr>2023-03-26 21:02:55 +0200
commit01c3e24c1b726aa4c975c2663e530982a0711029 (patch)
treeb12fe918dcaf5060ddb8ae5bc21bf0aaf20e67b0
parentecbbdef6b884f4375aad600595f71b9a82e64c37 (diff)
downloadghdl-01c3e24c1b726aa4c975c2663e530982a0711029.tar.gz
ghdl-01c3e24c1b726aa4c975c2663e530982a0711029.tar.bz2
ghdl-01c3e24c1b726aa4c975c2663e530982a0711029.zip
eval_static_expr_orig: free temporary node for range attributes
-rw-r--r--src/vhdl/vhdl-evaluation.adb81
1 files changed, 64 insertions, 17 deletions
diff --git a/src/vhdl/vhdl-evaluation.adb b/src/vhdl/vhdl-evaluation.adb
index fe96ab8f5..e20952634 100644
--- a/src/vhdl/vhdl-evaluation.adb
+++ b/src/vhdl/vhdl-evaluation.adb
@@ -51,6 +51,9 @@ package body Vhdl.Evaluation is
function Eval_Floating_Image (Val : Fp64; Orig : Iir) return Iir;
function Eval_Floating_To_String_Format (Val : Fp64; Fmt : Iir; Orig : Iir)
return Iir;
+ procedure Eval_Range_Bounds (Rng : Iir;
+ Dir : out Direction_Type;
+ Left, Right : out Iir);
function Eval_Scalar_Compare (Left, Right : Iir) return Compare_Type;
@@ -3798,21 +3801,57 @@ package body Vhdl.Evaluation is
end;
when Iir_Kind_Left_Type_Attribute =>
- return Eval_Static_Expr
- (Get_Left_Limit (Eval_Static_Range (Get_Prefix (Expr))));
+ declare
+ L, R : Iir;
+ Dir : Direction_Type;
+ begin
+ Eval_Range_Bounds (Get_Prefix (Expr), Dir, L, R);
+ return Eval_Static_Expr (L);
+ end;
when Iir_Kind_Right_Type_Attribute =>
- return Eval_Static_Expr
- (Get_Right_Limit (Eval_Static_Range (Get_Prefix (Expr))));
+ declare
+ L, R : Iir;
+ Dir : Direction_Type;
+ begin
+ Eval_Range_Bounds (Get_Prefix (Expr), Dir, L, R);
+ return Eval_Static_Expr (R);
+ end;
when Iir_Kind_High_Type_Attribute =>
- return Eval_Static_Expr
- (Get_High_Limit (Eval_Static_Range (Get_Prefix (Expr))));
+ declare
+ L, R, Res : Iir;
+ Dir : Direction_Type;
+ begin
+ Eval_Range_Bounds (Get_Prefix (Expr), Dir, L, R);
+ case Dir is
+ when Dir_To =>
+ Res := R;
+ when Dir_Downto =>
+ Res := L;
+ end case;
+ return Eval_Static_Expr (Res);
+ end;
when Iir_Kind_Low_Type_Attribute =>
- return Eval_Static_Expr
- (Get_Low_Limit (Eval_Static_Range (Get_Prefix (Expr))));
+ declare
+ L, R, Res : Iir;
+ Dir : Direction_Type;
+ begin
+ Eval_Range_Bounds (Get_Prefix (Expr), Dir, L, R);
+ case Dir is
+ when Dir_To =>
+ Res := L;
+ when Dir_Downto =>
+ Res := R;
+ end case;
+ return Eval_Static_Expr (Res);
+ end;
when Iir_Kind_Ascending_Type_Attribute =>
- return Build_Boolean
- (Get_Direction (Eval_Static_Range (Get_Prefix (Expr))) = Dir_To);
-
+ declare
+ L, R : Iir;
+ Dir : Direction_Type;
+ begin
+ Eval_Range_Bounds (Get_Prefix (Expr), Dir, L, R);
+ return Build_Boolean (Dir = Dir_To);
+ end;
when Iir_Kind_Length_Array_Attribute =>
declare
Index : Iir;
@@ -4725,7 +4764,8 @@ package body Vhdl.Evaluation is
return Res;
end Eval_Range;
- function Eval_Static_Range (Rng : Iir) return Iir
+ -- Return a range expression or a range attribute.
+ function Eval_Static_Range_Prefix (Rng : Iir) return Iir
is
Expr : Iir;
Kind : Iir_Kind;
@@ -4737,11 +4777,7 @@ package body Vhdl.Evaluation is
when Iir_Kind_Range_Expression
| Iir_Kind_Range_Array_Attribute
| Iir_Kind_Reverse_Range_Array_Attribute =>
- if Get_Expr_Staticness (Expr) /= Locally then
- return Null_Iir;
- end if;
-
- return Eval_Range (Expr);
+ return Expr;
when Iir_Kind_Integer_Subtype_Definition
| Iir_Kind_Floating_Subtype_Definition
| Iir_Kind_Enumeration_Type_Definition
@@ -4762,6 +4798,17 @@ package body Vhdl.Evaluation is
Error_Kind ("eval_static_range", Expr);
end case;
end loop;
+ end Eval_Static_Range_Prefix;
+
+ function Eval_Static_Range (Rng : Iir) return Iir
+ is
+ Expr : Iir;
+ begin
+ Expr := Eval_Static_Range_Prefix (Rng);
+ if Get_Expr_Staticness (Expr) /= Locally then
+ return Null_Iir;
+ end if;
+ return Eval_Range (Expr);
end Eval_Static_Range;
-- Check range expression A_RANGE.