aboutsummaryrefslogtreecommitdiffstats
path: root/src/synth
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2022-09-12 21:21:50 +0200
committerTristan Gingold <tgingold@free.fr>2022-09-14 07:44:18 +0200
commite15b91f0f4ed0fc3bcf990ec8a92ade9dc258206 (patch)
treeca74804f4f5b47f362124e842bb667129c4b5145 /src/synth
parentc4c21c2d74f24fefa9f34747dc0e9c85ada603b4 (diff)
downloadghdl-e15b91f0f4ed0fc3bcf990ec8a92ade9dc258206.tar.gz
ghdl-e15b91f0f4ed0fc3bcf990ec8a92ade9dc258206.tar.bz2
ghdl-e15b91f0f4ed0fc3bcf990ec8a92ade9dc258206.zip
synth: detect overflow in static exponentiation
src/grt: extract grt.arith from grt.lib
Diffstat (limited to 'src/synth')
-rw-r--r--src/synth/synth-vhdl_eval.adb19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/synth/synth-vhdl_eval.adb b/src/synth/synth-vhdl_eval.adb
index af2c9e0d6..cddcc5a5d 100644
--- a/src/synth/synth-vhdl_eval.adb
+++ b/src/synth/synth-vhdl_eval.adb
@@ -23,6 +23,7 @@ with Name_Table;
with Grt.Types; use Grt.Types;
with Grt.Vhdl_Types; use Grt.Vhdl_Types;
with Grt.To_Strings;
+with Grt.Arith;
with Vhdl.Utils;
with Vhdl.Evaluation;
@@ -487,9 +488,21 @@ package body Synth.Vhdl_Eval is
end;
when Iir_Predefined_Integer_Exp =>
- return Create_Memory_Discrete
- (Read_Discrete (Left) ** Natural (Read_Discrete (Right)),
- Res_Typ);
+ declare
+ Lv : Ghdl_I64;
+ Rv : Std_Integer;
+ Res : Ghdl_I64;
+ Ovf : Boolean;
+ begin
+ Lv := Ghdl_I64 (Read_Discrete (Left));
+ Rv := Std_Integer (Read_Discrete (Right));
+ Grt.Arith.Exp_I64 (Lv, Rv, Res, Ovf);
+ if Ovf then
+ Error_Msg_Synth (+Expr, "exponentiation overflow");
+ Res := 0;
+ end if;
+ return Create_Memory_Discrete (Int64 (Res), Res_Typ);
+ end;
when Iir_Predefined_Integer_Less_Equal
| Iir_Predefined_Physical_Less_Equal