Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
platform.hpp
Go to the documentation of this file.
1#pragma once
2
3// Platform-specific API macros
4#ifdef HELIOS_PLATFORM_WINDOWS
5#ifdef HELIOS_BUILD_SHARED
6#define HELIOS_API __declspec(dllexport)
7#else
8#define HELIOS_API __declspec(dllimport)
9#endif
10#elifdef HELIOS_PLATFORM_LINUX
11#ifdef HELIOS_BUILD_SHARED
12#define HELIOS_API __attribute__((visibility("default")))
13#else
14#define HELIOS_API
15#endif
16#else
17#define HELIOS_API
18#endif
19
20#ifdef HELIOS_PLATFORM_WINDOWS
21#define HELIOS_EXPORT __declspec(dllexport)
22#elifdef HELIOS_PLATFORM_LINUX
23#define HELIOS_EXPORT __attribute__((visibility("default")))
24#else
25#define HELIOS_EXPORT
26#endif
27
28// TODO: Replace with std::breakpoint() from <debugging> in C++26
29// https://en.cppreference.com/w/cpp/utility/breakpoint.html
30
31// NOLINTBEGIN(hicpp-no-assembler)
32
33// MSVC: Use the intrinsic which maps to the appropriate inlined assembly
34#if defined(_MSC_VER) && (_MSC_VER >= 1300)
35#define HELIOS_DEBUG_BREAK() __debugbreak()
36
37// ARM64 on Apple: Use signal-based break (better debugger integration)
38#elif defined(__arm64__) && defined(__APPLE__)
39#include <unistd.h>
40#include <csignal>
41#define HELIOS_DEBUG_BREAK() ::kill(::getpid(), SIGINT)
42
43// ARM64 with GCC/Clang: Use brk instruction
44#elif defined(__arm64__) && (defined(__GNUC__) || defined(__clang__))
45#define HELIOS_DEBUG_BREAK() __asm__("brk 0")
46
47// ARM (32-bit) on Apple: Use trap instruction
48#elif defined(__arm__) && defined(__APPLE__)
49#define HELIOS_DEBUG_BREAK() __asm__("trap")
50
51// ARM (32-bit) with GCC/Clang: Use bkpt instruction
52#elif defined(__arm__) && (defined(__GNUC__) || defined(__clang__))
53#define HELIOS_DEBUG_BREAK() __asm__("bkpt 0")
54
55// ARM with Arm Compiler: Use breakpoint intrinsic
56#elif defined(__arm__) && defined(__ARMCC_VERSION)
57#define HELIOS_DEBUG_BREAK() __breakpoint(0)
58
59// x86/x86_64 with Clang/GCC: Use int3 instruction (AT&T syntax)
60#elif (defined(__x86_64__) || defined(__i386__)) && \
61 (defined(__GNUC__) || defined(__clang__))
62#define HELIOS_DEBUG_BREAK() __asm__("int3")
63
64// x86/x86_64 with MSVC: Use int3 instruction (Intel syntax)
65#elif (defined(_M_X64) || defined(_M_IX86)) && defined(_MSC_VER)
66#define HELIOS_DEBUG_BREAK() __asm int 3
67
68// PowerPC: Trigger exception via opcode 0x00000000
69#elif defined(__powerpc__) || defined(__ppc__) || defined(_ARCH_PPC)
70#define HELIOS_DEBUG_BREAK() __asm__(".long 0")
71
72// RISC-V: Use ebreak instruction
73#elif defined(__riscv) || defined(__riscv__)
74#define HELIOS_DEBUG_BREAK() __asm__("ebreak")
75
76// WebAssembly: No breakpoint support, use unreachable
77#elif defined(__wasm__)
78#define HELIOS_DEBUG_BREAK() __asm__("unreachable")
79
80// Fallback: Use compiler builtin trap (works on most modern compilers)
81#elif defined(__has_builtin) && __has_builtin(__builtin_trap)
82#define HELIOS_DEBUG_BREAK() __builtin_trap()
83
84// NOLINTEND(hicpp-no-assembler)
85
86// Last resort: Use signal-based approach
87#else
88#include <csignal>
89#define HELIOS_DEBUG_BREAK() ::std::raise(SIGTRAP)
90#endif