dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
CompilerSupport.hpp
1// SPDX-FileCopyrightText: 2025-2026 Vincent Leroy
2// SPDX-License-Identifier: MIT
3//
4// This file is part of dfx.
5//
6// Licensed under the MIT License. See the LICENSE file in the project root
7// for full license information.
8
9#pragma once
10
11// Project includes
12#include "ArchDetection.hpp"
13#include "Exception.hpp"
14
15#define DFX_PRAGMA(x) _Pragma(#x)
16
17#if defined(DFX_PLATFORM_COMPILER_CLANG)
18# define DFX_DIAGNOSTIC_PUSH DFX_PRAGMA(clang diagnostic push)
19# define DFX_DIAGNOSTIC_POP DFX_PRAGMA(clang diagnostic pop)
20#elif defined(DFX_PLATFORM_COMPILER_GCC)
21# define DFX_DIAGNOSTIC_PUSH DFX_PRAGMA(GCC diagnostic push)
22# define DFX_DIAGNOSTIC_POP DFX_PRAGMA(GCC diagnostic pop)
23#else
24# define DFX_DIAGNOSTIC_PUSH
25# define DFX_DIAGNOSTIC_POP
26#endif
27
28#if defined(DFX_PLATFORM_COMPILER_CLANG)
29# define DFX_DIAGNOSTIC_IGNORE(warningName) DFX_PRAGMA(clang diagnostic ignored warningName)
30#elif defined(DFX_PLATFORM_COMPILER_GCC)
31# define DFX_DIAGNOSTIC_IGNORE(warningName) DFX_PRAGMA(GCC diagnostic ignored warningName)
32#else
33# define DFX_DIAGNOSTIC_IGNORE(x)
34#endif
35
36#ifdef DFX_PLATFORM_COMPILER_CLANG_OR_GCC
37# define DFX_LIKELY(expr) __builtin_expect(!!(expr), true)
38# define DFX_UNLIKELY(expr) __builtin_expect(!!(expr), false)
39# define DFX_UNREACHABLE_IMPL() std::unreachable()
40# define DFX_ATTR(...) __attribute__((__VA_ARGS__))
41#else
42# define DFX_LIKELY(expr) (expr)
43# define DFX_UNLIKELY(expr) (expr)
44# define DFX_UNREACHABLE_IMPL() std::abort()
45# define DFX_ATTR(expr)
46#endif // DFX_PLATFORM_COMPILER_CLANG_OR_GCC
47
48#define DFX_ALWAYS_INLINE DFX_ATTR(always_inline)
49#define DFX_PACKED DFX_ATTR(packed)
50#define DFX_ALIGNED(n) DFX_ATTR(aligned(n))
51#define DFX_DEPRECATED [[deprecated]]
52#define DFX_DEPRECATED_X(msg) [[deprecated(msg)]]
53
54#define DFX_UNREACHABLE() do { DFX_THROW("Unreachable code was reached"); DFX_UNREACHABLE_IMPL(); } while (false)
Exception utilities for dfx (source-location aware exceptions, nested stacks, and safe invocation hel...