aboutsummaryrefslogtreecommitdiffstats
path: root/src/grt
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2022-10-02 13:57:49 +0200
committerTristan Gingold <tgingold@free.fr>2022-10-02 13:57:49 +0200
commit298fa787da01ded60f2b9d02c9529760aabd2921 (patch)
treef8697578f8ac6011720f561d5ecc5074849ae142 /src/grt
parent7d642ac4d912c4111769f124a2da97fa83828548 (diff)
downloadghdl-298fa787da01ded60f2b9d02c9529760aabd2921.tar.gz
ghdl-298fa787da01ded60f2b9d02c9529760aabd2921.tar.bz2
ghdl-298fa787da01ded60f2b9d02c9529760aabd2921.zip
translate, grt: add lib function for div and rem.
Do not rely on hardware exceptions to catch division by 0, they are caught in windows by the c handler and not propagated
Diffstat (limited to 'src/grt')
-rw-r--r--src/grt/grt-lib.adb44
-rw-r--r--src/grt/grt-lib.ads12
2 files changed, 56 insertions, 0 deletions
diff --git a/src/grt/grt-lib.adb b/src/grt/grt-lib.adb
index f69da860f..ec64f810f 100644
--- a/src/grt/grt-lib.adb
+++ b/src/grt/grt-lib.adb
@@ -271,6 +271,50 @@ package body Grt.Lib is
return Res;
end Ghdl_I64_Exp;
+ function Ghdl_I32_Div (L, R : Ghdl_I32) return Ghdl_I32
+ is
+ pragma Suppress (Overflow_Check);
+ begin
+ if R = 0 then
+ Error ("division by 0");
+ elsif R = -1 and L = Ghdl_I32'First then
+ Error ("overflow in division");
+ end if;
+ return L / R;
+ end Ghdl_I32_Div;
+
+ function Ghdl_I64_Div (L, R : Ghdl_I64) return Ghdl_I64
+ is
+ pragma Suppress (Overflow_Check);
+ begin
+ if R = 0 then
+ Error ("division by 0");
+ elsif R = -1 and L = Ghdl_I64'First then
+ Error ("overflow in division");
+ end if;
+ return L / R;
+ end Ghdl_I64_Div;
+
+ function Ghdl_I32_Mod (L, R : Ghdl_I32) return Ghdl_I32
+ is
+ pragma Suppress (Overflow_Check);
+ begin
+ if R = 0 then
+ Error ("division by 0");
+ end if;
+ return L mod R;
+ end Ghdl_I32_Mod;
+
+ function Ghdl_I64_Mod (L, R : Ghdl_I64) return Ghdl_I64
+ is
+ pragma Suppress (Overflow_Check);
+ begin
+ if R = 0 then
+ Error ("division by 0");
+ end if;
+ return L mod R;
+ end Ghdl_I64_Mod;
+
procedure Ghdl_Check_Stack_Allocation (Size : Ghdl_Index_Type)
is
Bt : Backtrace_Addrs;
diff --git a/src/grt/grt-lib.ads b/src/grt/grt-lib.ads
index f8e7f0a7a..0210057fa 100644
--- a/src/grt/grt-lib.ads
+++ b/src/grt/grt-lib.ads
@@ -69,6 +69,12 @@ package Grt.Lib is
function Ghdl_I32_Exp (V : Ghdl_I32; E : Std_Integer) return Ghdl_I32;
function Ghdl_I64_Exp (V : Ghdl_I64; E : Std_Integer) return Ghdl_I64;
+ function Ghdl_I32_Div (L, R : Ghdl_I32) return Ghdl_I32;
+ function Ghdl_I64_Div (L, R : Ghdl_I64) return Ghdl_I64;
+
+ function Ghdl_I32_Mod (L, R : Ghdl_I32) return Ghdl_I32;
+ function Ghdl_I64_Mod (L, R : Ghdl_I64) return Ghdl_I64;
+
-- Called before allocation of large (complex) objects.
procedure Ghdl_Check_Stack_Allocation (Size : Ghdl_Index_Type);
@@ -141,6 +147,12 @@ private
pragma Export (C, Ghdl_I64_Exp, "__ghdl_i64_exp");
pragma Export (C, Ghdl_Real_Exp, "__ghdl_real_exp");
+ pragma Export (C, Ghdl_I32_Div, "__ghdl_i32_div");
+ pragma Export (C, Ghdl_I64_Div, "__ghdl_i64_div");
+
+ pragma Export (C, Ghdl_I32_Mod, "__ghdl_i32_mod");
+ pragma Export (C, Ghdl_I64_Mod, "__ghdl_i64_mod");
+
pragma Export (C, Ghdl_Std_Ulogic_To_Boolean_Array,
"__ghdl_std_ulogic_to_boolean_array");