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