diff --git a/nac3core/build.rs b/nac3core/build.rs index 9466f37d..968fe0df 100644 --- a/nac3core/build.rs +++ b/nac3core/build.rs @@ -19,18 +19,13 @@ fn main() { * HACK: Sadly, clang doesn't let us emit generic LLVM bitcode. * Compiling for WASM32 and filtering the output with regex is the closest we can get. */ - let flags: &[&str] = &[ + let mut flags: Vec<&str> = vec![ "--target=wasm32", "-x", "c++", "-fno-discard-value-names", "-fno-exceptions", "-fno-rtti", - match env::var("PROFILE").as_deref() { - Ok("debug") => "-O0", - Ok("release") => "-O3", - flavor => panic!("Unknown or missing build flavor {flavor:?}"), - }, "-emit-llvm", "-S", "-Wall", @@ -42,6 +37,17 @@ fn main() { irrt_cpp_path.to_str().unwrap(), ]; + match env::var("PROFILE").as_deref() { + Ok("debug") => { + flags.push("-O0"); + flags.push("-DIRRT_DEBUG_ASSERT"); + } + Ok("release") => { + flags.push("-O3"); + } + flavor => panic!("Unknown or missing build flavor {flavor:?}"), + } + // Tell Cargo to rerun if any file under `irrt_dir` (recursive) changes println!("cargo:rerun-if-changed={}", irrt_dir.to_str().unwrap()); diff --git a/nac3core/irrt/irrt/debug.hpp b/nac3core/irrt/irrt/debug.hpp new file mode 100644 index 00000000..1444e316 --- /dev/null +++ b/nac3core/irrt/irrt/debug.hpp @@ -0,0 +1,22 @@ +#pragma once + +#ifdef IRRT_DEBUG_ASSERT +#define IRRT_DEBUG_ASSERT_BOOL true +#else +#define IRRT_DEBUG_ASSERT_BOOL false +#endif + +#define raise_debug_assert(SizeT, msg, param1, param2, param3) \ + raise_exception(SizeT, EXN_ASSERTION_ERROR, "IRRT debug assert failed: " msg, param1, param2, param3); + +#define debug_assert_eq(SizeT, lhs, rhs) \ + if (IRRT_DEBUG_ASSERT_BOOL && (lhs) != (rhs)) \ + { \ + raise_debug_assert(SizeT, "LHS = {0}. RHS = {1}", lhs, rhs, NO_PARAM); \ + } + +#define debug_assert(SizeT, expr) \ + if (IRRT_DEBUG_ASSERT_BOOL && !(expr)) \ + { \ + raise_debug_assert(SizeT, "Got false.", NO_PARAM, NO_PARAM, NO_PARAM); \ + } \ No newline at end of file