core/irrt/exceptions: add debug utils with exceptions
This commit is contained in:
parent
cf34002179
commit
f169d37074
@ -18,18 +18,13 @@ fn main() {
|
|||||||
* HACK: Sadly, clang doesn't let us emit generic LLVM bitcode.
|
* 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.
|
* 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",
|
"--target=wasm32",
|
||||||
"-x",
|
"-x",
|
||||||
"c++",
|
"c++",
|
||||||
"-fno-discard-value-names",
|
"-fno-discard-value-names",
|
||||||
"-fno-exceptions",
|
"-fno-exceptions",
|
||||||
"-fno-rtti",
|
"-fno-rtti",
|
||||||
match env::var("PROFILE").as_deref() {
|
|
||||||
Ok("debug") => "-O0",
|
|
||||||
Ok("release") => "-O3",
|
|
||||||
flavor => panic!("Unknown or missing build flavor {flavor:?}"),
|
|
||||||
},
|
|
||||||
"-emit-llvm",
|
"-emit-llvm",
|
||||||
"-S",
|
"-S",
|
||||||
"-Wall",
|
"-Wall",
|
||||||
@ -41,6 +36,17 @@ fn main() {
|
|||||||
irrt_cpp_path.to_str().unwrap(),
|
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
|
// Tell Cargo to rerun if any file under `irrt_dir` (recursive) changes
|
||||||
println!("cargo:rerun-if-changed={}", irrt_dir.to_str().unwrap());
|
println!("cargo:rerun-if-changed={}", irrt_dir.to_str().unwrap());
|
||||||
|
|
||||||
|
23
nac3core/irrt/irrt/debug.hpp
Normal file
23
nac3core/irrt/irrt/debug.hpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Set in nac3core/build.rs
|
||||||
|
#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); \
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user