dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
CompilerSupport.hpp
1// SPDX-FileCopyrightText: 2025 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 DIAGNOSTIC_PRAGMA(x) _Pragma(#x)
16
17#if defined(PLATFORM_COMPILER_CLANG)
18# define DIAGNOSTIC_PUSH DIAGNOSTIC_PRAGMA(clang diagnostic push)
19# define DIAGNOSTIC_POP DIAGNOSTIC_PRAGMA(clang diagnostic pop)
20#elif defined(PLATFORM_COMPILER_GCC)
21# define DIAGNOSTIC_PUSH DIAGNOSTIC_PRAGMA(GCC diagnostic push)
22# define DIAGNOSTIC_POP DIAGNOSTIC_PRAGMA(GCC diagnostic pop)
23#else
24# define DIAGNOSTIC_PUSH
25# define DIAGNOSTIC_POP
26#endif
27
28#if defined(PLATFORM_COMPILER_CLANG)
29# define DIAGNOSTIC_IGNORE(warningName) DIAGNOSTIC_PRAGMA(clang diagnostic ignored warningName)
30#elif defined(PLATFORM_COMPILER_GCC)
31# define DIAGNOSTIC_IGNORE(warningName) DIAGNOSTIC_PRAGMA(GCC diagnostic ignored warningName)
32#else
33# define DIAGNOSTIC_IGNORE(x)
34#endif
35
36#ifdef PLATFORM_COMPILER_CLANG_OR_GCC
37# define LIKELY(expr) __builtin_expect(!!(expr), true)
38# define UNLIKELY(expr) __builtin_expect(!!(expr), false)
39# define UNREACHABLE_IMPL() std::unreachable()
40# define VISIBLE_FUNC_ATTR __attribute__((visibility("default")))
41# define HIDDEN_FUNC_ATTR __attribute__((visibility("hidden")))
42# define ALWAYS_INLINE_ATTR __attribute__((always_inline))
43#else
44# define LIKELY(expr) (expr)
45# define UNLIKELY(expr) (expr)
46# define UNREACHABLE_IMPL() std::abort()
47# define VISIBLE_FUNC_ATTR
48# define HIDDEN_FUNC_ATTR
49# define ALWAYS_INLINE_ATTR
50#endif // PLATFORM_COMPILER_CLANG_OR_GCC
51
52#define UNREACHABLE() do { THROW("Unreachable code was reached"); UNREACHABLE_IMPL(); } while (false)
Exception utilities for dfx (source-location aware exceptions, nested stacks, and safe invocation hel...