-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathassert.cpp
More file actions
57 lines (53 loc) · 1.4 KB
/
assert.cpp
File metadata and controls
57 lines (53 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <common/assert.hpp>
#include <common/compiler.hpp>
#include <common/platform.hpp>
namespace transmute::common
{
#if TR_COMPILER_IS(CLANG) || TR_COMPILER_IS(GCC)
void BreakPoint()
{
#if TR_PLATFORM_IS(X86)
__asm__ __volatile__("int $3\n\t");
#elif TR_PLATFORM_IS(ARM32)
__asm__ __volatile__("bkpt 0");
#elif TR_PLATFORM_IS(ARM64)
__asm__ __volatile__("brk 0xf000");
#elif TR_PLATFORM_IS(LOONGARCH)
__asm__ __volatile__("break 0");
#elif TR_PLATFORM_IS(RISCV)
__asm__ __volatile__("ebreak");
#elif TR_PLATFORM_IS(MIPS)
__asm__ __volatile__("break");
#elif TR_PLATFORM_IS(S390) || TR_PLATFORM_IS(S390X)
__asm__ __volatile__(".word 0x0001");
#elif TR_PLATFORM_IS(PPC) || TR_PLATFORM_IS(PPC64)
__asm__ __volatile__("twge 2,2");
#elif TR_PLATFORM_IS(WASM32) || TR_PLATFORM_IS(WASM64)
EM_ASM(debugger;);
#else
#error "Unsupported platform"
#endif
}
#elif TR_COMPILER_IS(MSVC)
void BreakPoint()
{
__debugbreak();
}
#else
#error "Unsupported compiler"
#endif
void HandleAssertionFailure(const char *file,
const char *function,
int line,
const char *condition)
{
std::cerr << "Assertion failure at " << file << ":" << line << " (" << function
<< "): " << condition;
#if defined(TR_ABORT_ON_ASSERT)
abort();
#else
BreakPoint();
#endif
}
}