LeviLamina
Loading...
Searching...
No Matches
CompilerPredefine.h
1#pragma once
2
3#include <optional>
4#include <type_traits>
5
6#include "ll/api/base/StdInt.h"
7#include "ll/api/reflection/TypeName.h"
8
9#ifdef _MSC_VER
10
11#include "intrin.h"
12#include "sal.h"
13
14#ifndef LL_HAS_CXX23
15#if _HAS_CXX23
16#define LL_HAS_CXX23 1
17#else
18#define LL_HAS_CXX23 0
19#endif
20#endif
21
22#ifndef LL_SHARED_EXPORT
23#define LL_SHARED_EXPORT __declspec(dllexport)
24#endif
25#ifndef LL_SHARED_IMPORT
26#define LL_SHARED_IMPORT __declspec(dllimport)
27#endif
28
29#ifndef LL_EBO
30#define LL_EBO __declspec(empty_bases)
31#endif
32
33#ifndef LL_ALLOCATOR
34#define LL_ALLOCATOR _Ret_notnull_ _Post_writable_byte_size_(size) _VCRT_ALLOCATOR
35#endif
36
37#ifndef LL_NOTHROW_ALLOCATOR
38#define LL_NOTHROW_ALLOCATOR _Ret_maybenull_ _Success_(return != NULL) _Post_writable_byte_size_(size) _VCRT_ALLOCATOR
39#endif
40
41#ifndef LL_FORCEINLINE
42#define LL_FORCEINLINE __forceinline
43#endif
44
45#ifndef LL_NOINLINE
46#define LL_NOINLINE __declspec(noinline)
47#endif
48
49#ifndef LL_NO_UNIQUE_ADDRESS
50#define LL_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
51#endif
52
53#ifndef LL_CONSTEXPR23
54#define LL_CONSTEXPR23 _CONSTEXPR23
55#endif
56
57#ifndef LL_UNREACHABLE
58#define LL_UNREACHABLE _STL_UNREACHABLE
59#endif
60
61#ifndef LL_RETURN_ADDRESS
62#define LL_RETURN_ADDRESS _ReturnAddress()
63#endif
64
65#ifndef LL_CURRENT_LINE
66#define LL_CURRENT_LINE __builtin_LINE()
67#endif
68
69#ifndef LL_CURRENT_COLUMN
70#define LL_CURRENT_COLUMN __builtin_COLUMN()
71#endif
72
73#ifndef LL_CURRENT_FILE
74#define LL_CURRENT_FILE __builtin_FILE()
75#endif
76
77#ifndef LL_CURRENT_FUNCTION
78#define LL_CURRENT_FUNCTION __builtin_FUNCTION()
79#endif
80
81#ifndef LL_CURRENT_FUNCSIG
82#define LL_CURRENT_FUNCSIG __builtin_FUNCSIG()
83#endif
84
85#ifndef LL_MACHINE_PAUSE
86#define LL_MACHINE_PAUSE _mm_pause()
87#endif
88
89// MSVC has customized some functions and classes inside the compiler, but they are not included in IntelliSense. This
90// header file is only used for IntelliSense.
91#if defined(__INTELLISENSE__) || defined(__clang__) || defined(__clangd__)
92// NOLINTBEGIN
93#pragma pack(push, ehdata, 4)
94
95typedef struct _PMD {
96 int mdisp; // Offset of intended data within base
97 int pdisp; // Displacement to virtual base pointer
98 int vdisp; // Index within vbTable to offset of base
99} _PMD;
100
101typedef void (*_PMFN)(void);
102
103#pragma warning(disable : 4200)
104#pragma pack(push, _TypeDescriptor, 8)
105typedef struct _TypeDescriptor {
106 void const* pVFTable; // Field overloaded by RTTI
107 void* spare; // reserved, possible for RTTI
108 char name[]; // The decorated name of the type; 0 terminated.
109} _TypeDescriptor;
110#pragma pack(pop, _TypeDescriptor)
111#pragma warning(default : 4200)
112
113typedef const struct _s__CatchableType {
114 unsigned int properties; // Catchable Type properties (Bit field)
115 _TypeDescriptor* pType; // Image relative offset of TypeDescriptor
116 _PMD thisDisplacement; // Pointer to instance of catch type within thrown object.
117 int sizeOrOffset; // Size of simple-type object or offset into buffer of 'this' pointer for catch object
118 _PMFN copyFunction; // Copy constructor or CC-closure
119} _CatchableType;
120
121#pragma warning(disable : 4200)
122typedef const struct _s__CatchableTypeArray {
123 int nCatchableTypes;
124 _CatchableType* arrayOfCatchableTypes[]; // Image relative offset of Catchable Types
125} _CatchableTypeArray;
126#pragma warning(default : 4200)
127
128typedef const struct _s__ThrowInfo {
129 unsigned int attributes; // Throw Info attributes (Bit field)
130 _PMFN pmfnUnwind; // Destructor to call when exception has been handled or aborted
131 int(__cdecl* pForwardCompat)(...); // Image relative offset of Forward compatibility frame handler
132 _CatchableTypeArray* pCatchableTypeArray; // Image relative offset of CatchableTypeArray
133} _ThrowInfo;
134
135//
136// Here's how to throw:
137// _ThrowInfo is the name of the type that is 'pre-injected' into the
138// since this prototype is known to the FE along with the pre-injected
139// types, it has to match exactly.
140//
141__declspec(noreturn) extern "C" void __stdcall _CxxThrowException(void* pExceptionObject, _ThrowInfo* pThrowInfo);
142extern "C" int __cdecl __CxxExceptionFilter(void*, void*, int, void*);
143
144// Returns true if the object is really a C++ exception
145// If it is, stores the previous exception in *storage, and saves the current one
146// This is needed to keep track of the current exception object (used for rethrow & destruction)
147extern "C" int __cdecl __CxxRegisterExceptionObject(void* exception, void* storage);
148
149// Returns true if exception is a C++ rethrown exception
150// This is needed, so Unregister can know whether or not to destroy the object
151extern "C" int __cdecl __CxxDetectRethrow(void* exception);
152
153// Returns the byte count of stack space required to store the exception info
154extern "C" int __cdecl __CxxQueryExceptionSize(void);
155
156// Pops the current exception, restoring the previous one from *storage
157// This detects whether or not the exception object needs to be destroyed
158extern "C" void __cdecl __CxxUnregisterExceptionObject(void* storage, int rethrow);
159
160#pragma pack(pop, ehdata)
161
162#pragma pack(push, rttidata, 4)
163
164typedef const struct _s__RTTIBaseClassDescriptor {
165 _TypeDescriptor* pTypeDescriptor; // type descriptor of the class
166 uint numContainedBases; // number of nested classes following in the Base Class Array
167 _PMD where; // pointer-to-member displacement info
168 uint attributes; // flags, usually 0
169} __RTTIBaseClassDescriptor;
170
171#pragma warning(disable : 4200)
172typedef const struct _s__RTTIBaseClassArray {
173 __RTTIBaseClassDescriptor* arrayOfBaseClassDescriptors[];
174} __RTTIBaseClassArray;
175#pragma warning(default : 4200)
176
177typedef const struct _s__RTTIClassHierarchyDescriptor {
178 uint signature; // always zero?
179 uint attributes; // bit 0 set = multiple inheritance, bit 1 set = virtual inheritance
180 uint numBaseClasses; // number of classes in pBaseClassArray
181 __RTTIBaseClassArray* pBaseClassArray;
182} __RTTIClassHierarchyDescriptor;
183
184typedef const struct _s__RTTICompleteObjectLocator {
185 uint signature; // always zero ?
186 uint offset; // offset of this vtable in the complete class
187 uint cdOffset; // constructor displacement offset
188 _TypeDescriptor* pTypeDescriptor; // TypeDescriptor of the complete class
189 __RTTIClassHierarchyDescriptor* pClassDescriptor; // describes inheritance hierarchy
190} __RTTICompleteObjectLocator;
191
192typedef class type_info const& __RTtypeidReturnType;
193
194extern "C" void* __cdecl __RTDynamicCast(
195 void const* ptr,
196 long offset,
197 _TypeDescriptor const* fromType,
198 _TypeDescriptor const* toType,
199 int isReference
200);
201extern "C" void* __cdecl __RTtypeid(void*);
202extern "C" void* __cdecl __RTCastToVoid(void*);
203
204#pragma pack(pop, rttidata)
205// NOLINTEND
206#endif
207struct _IMAGE_DOS_HEADER;
208
209// No one guarantees that the compiler's internal definitions are correct
210namespace ll::internal {
211#if !(defined(__INTELLISENSE__) || defined(__clangd__))
212#pragma pack(push, 4)
213struct CatchableType {
214 uint properties;
215 uint pType;
216 _PMD thisDisplacement;
217 uint sizeOrOffset;
218 uint copyFunction;
219};
220struct ThrowInfo {
221 uint attributes;
222 uint pmfnUnwind;
223 uint pForwardCompat;
224 uint pCatchableTypeArray;
225};
226#pragma pack(pop)
227#else
228using CatchableType = ::_CatchableType;
229using ThrowInfo = ::_ThrowInfo;
230#endif
231
232extern "C" ::_IMAGE_DOS_HEADER __ImageBase; // NOLINT(bugprone-reserved-identifier)
233
234[[nodiscard]] LL_FORCEINLINE void* getCurrentModuleHandle() noexcept { return &__ImageBase; }
235
236template <class T>
237concept MemFuncPtrT = std::is_member_function_pointer_v<T>;
238
239template <MemFuncPtrT T, T f>
240consteval bool virtualDetector() noexcept {
241 return reflection::getRawName<f>().find("::`vcall'{") != std::string_view::npos;
242}
243
244using FileHandleT = void*;
245
246} // namespace ll::internal
247
248#else
249
250#ifndef LL_HAS_CXX23
251#if _LIBCPP_STD_VER >= 23
252#define LL_HAS_CXX23 1
253#else
254#define LL_HAS_CXX23 0
255#endif
256#endif
257
258#ifndef LL_SHARED_EXPORT
259#define LL_SHARED_EXPORT __attribute__((visibility("default")))
260#endif
261
262#ifndef LL_SHARED_IMPORT
263#define LL_SHARED_IMPORT
264#endif
265
266#ifndef LL_EBO
267#define LL_EBO
268#endif
269
270#ifndef LL_ALLOCATOR
271#define LL_ALLOCATOR
272#endif
273
274#ifndef LL_FORCEINLINE
275#define LL_FORCEINLINE inline __attribute__((always_inline))
276#endif
277
278#ifndef LL_NOINLINE
279#define LL_NOINLINE __attribute__((noinline))
280#endif
281
282#ifndef LL_NO_UNIQUE_ADDRESS
283#define LL_NO_UNIQUE_ADDRESS [[no_unique_address]]
284#endif
285
286#ifndef LL_CONSTEXPR23
287#if defined(__cpp_constexpr) && __cpp_constexpr >= 202211L
288#define LL_CONSTEXPR23 constexpr
289#else
290#define LL_CONSTEXPR23 inline
291#endif
292#endif
293
294#ifndef LL_UNREACHABLE
295#define LL_UNREACHABLE __builtin_unreachable()
296#endif
297
298#ifndef LL_RETURN_ADDRESS
299#define LL_RETURN_ADDRESS __builtin_return_address(0)
300#endif
301
302#ifndef LL_CURRENT_LINE
303#define LL_CURRENT_LINE __builtin_LINE()
304#endif
305
306#ifndef LL_CURRENT_COLUMN
307#define LL_CURRENT_COLUMN (0)
308#endif
309
310#ifndef LL_CURRENT_FILE
311#define LL_CURRENT_FILE __builtin_FILE()
312#endif
313
314#ifndef LL_CURRENT_FUNCTION
315#define LL_CURRENT_FUNCTION __builtin_FUNCTION()
316#endif
317
318#ifndef LL_CURRENT_FUNCSIG
319#define LL_CURRENT_FUNCSIG __builtin_FUNCTION()
320#endif
321
322namespace ll::internal {
323
324[[nodiscard]] void* getCurrentModuleHandle() noexcept; // Implemented in SystemUtils_linux.cpp
325
326using FileHandleT = int;
327
328template <class T, T v1, T v2, class = std::integral_constant<bool, true>>
329struct CanCompare : std::false_type {};
330
331template <class T, T v1, T v2>
332struct CanCompare<T, v1, v2, std::integral_constant<bool, v1 == v2>> : std::true_type {};
333
334template <class T>
335concept MemFuncPtrT = std::is_member_function_pointer_v<T>;
336
337template <MemFuncPtrT T, T f>
338consteval bool virtualDetector() noexcept {
339 return !CanCompare<T, f, f>::value;
340}
341
342} // namespace ll::internal
343
344#endif
Definition CompilerPredefine.h:335
STL namespace.
Definition CompilerPredefine.h:329