forked from AZO234/NP2kai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler_base.h
500 lines (455 loc) · 11.3 KB
/
compiler_base.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
/* === compiler base header === (c) 2020 AZO */
// for VC2013, ICC12, GCC4, Clang3
#ifndef _COMPILER_BASE_H_
#define _COMPILER_BASE_H_
#if defined(__LIBRETRO__)
#include <libretro.h>
#endif
// secure
#if defined(__MINGW32__) || defined(__MINGW64__)
#define MINGW_HAS_SECURE_API 1
#endif
// Windows
#if defined(_WIN32) || defined(_WIN64) || defined(__MINGW32__) || defined(__MINGW64__) || defined(__CYGWIN__)
#if !defined(_WINDOWS)
#define _WINDOWS
#endif
#endif
/* archtecture */
#if defined(amd64) || defined(__AMD64__) || defined(__amd64__) || \
defined(x86_64) || defined(__x86_64__) || defined(__X86_64__) || \
defined(__aarch64__) || defined(_WIN64) || defined(_M_X64) || \
defined(__LP64__) || defined(__LLP64__) || defined(__LLP64__)
#define NP2_CPU_64BIT
#endif
#if defined(i386) || defined(__i386__) || defined(__arm__) || \
defined(_WIN32) || defined(_M_IX86) || \
defined(NP2_CPU_ARCH_AMD64)
#define NP2_CPU_32BIT
#endif
#if defined(amd64) || defined(__AMD64__) || defined(__amd64__) || \
defined(x86_64) || defined(__x86_64__) || defined(__X86_64__)
#define NP2_CPU_ARCH_AMD64
#endif
#if defined(i386) || defined(__i386__) || defined(NP2_CPU_ARCH_AMD64)
#define NP2_CPU_ARCH_IA32
#endif
#if defined(__GNUC__)
#if defined(NP2_CPU_ARCH_IA32)
#define GCC_CPU_ARCH_IA32
#endif
#if defined(NP2_CPU_ARCH_AMD64)
#define GCC_CPU_ARCH_AMD64
#endif
#endif
// standard include
#if defined(_WINDOWS)
#include <windows.h>
#include <tchar.h>
// not define _UNICODE, UNICODE now
#endif
#if defined(__cplusplus)
#include <cstdio>
#include <cstdlib> // include cwchar
#include <cstddef>
#include <cstring>
#include <cmath>
#include <climits>
#include <csetjmp>
#include <cstdarg>
#else
#include <stdio.h>
#include <stdlib.h> // include wchar.h
#include <stddef.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <setjmp.h>
#include <stdarg.h>
#endif
// C/C++ standard
#if defined(__cplusplus)
#include <inttypes.h>
#if defined(__APPLE__)
#include <cstdint>
#if !defined(CPP11)
#define CPP11
#endif
#elif defined(_MSC_VER)
#include <stdint.h>
#if !defined(CPP11)
#define CPP11
#endif
#else
#if __cplusplus >= 201103L
#include <cstdint>
#if !defined(CPP11)
#define CPP11
#endif
#endif
#if defined(__GXX_EXPERIMENTAL_CXX0X__)
#if !defined(CPP0X)
#define CPP0X
#endif
#endif
#endif
#if !defined(_MSC_VER)
#if !defined(SUPPORT_SNPRINTF)
#define SUPPORT_SNPRINTF
#endif
#endif
#else
#if defined(_MSC_VER)
#if _MSC_VER >= 1800
#include <inttypes.h>
#include <stdint.h>
#if !defined(C99)
#define C99
#endif
// _MSC_VER<1900(older VC2015) not support snprintf()
#elif _MSC_VER >= 1900
#if !defined(SUPPORT_SNPRINTF)
#define SUPPORT_SNPRINTF
#endif
#endif
#elif defined(__STDC_VERSION__)
#if __STDC_VERSION__ >= 199901L
#include <inttypes.h>
#if !defined(C99)
#define C99
#endif
#if !defined(SUPPORT_SNPRINTF)
#define SUPPORT_SNPRINTF
#endif
#endif
#if __STDC_VERSION__ >= 201112L
#if !defined(C11)
#define C11
#endif
#if !defined(SUPPORT_STRNLENS)
//#define SUPPORT_STRNLENS
#endif
#endif
#endif
#endif
#if __STDC_VERSION__ >= 199901L
#define _XOPEN_SOURCE 600
#else
#define _XOPEN_SOURCE 500
#endif /* __STDC_VERSION__ */
// size fixed integer
#if !defined(__cplusplus) && !defined(C99)
typedef char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef long int32_t;
typedef unsigned long uint32_t;
#if defined(NP2_CPU_64BIT)
typedef long long int64_t; // literal: nnnLL format: %PRId64
typedef unsigned long long uint64_t; // literal: nnnULL format: %PRIu64
#else
typedef int32_t int64_t;
typedef uint32_t uint64_t;
#endif
#if defined(NP2_CPU_64BIT)
typedef int64_t intptr_t;
typedef uint64_t uintptr_t;
typedef int64_t intmax_t;
typedef uint64_t uintmax_t;
#else
typedef int32_t intptr_t;
typedef uint32_t uintptr_t;
typedef int32_t intmax_t;
typedef uint32_t uintmax_t;
#endif
#endif
#if !defined(_MSC_VER)
typedef int32_t INT;
typedef uint32_t UINT;
typedef int8_t INT8;
typedef uint8_t UINT8;
typedef int32_t INT32;
typedef uint32_t UINT32;
#endif
typedef INT SINT;
typedef INT8 SINT8;
typedef int16_t INT16;
typedef INT16 SINT16;
typedef uint16_t UINT16;
typedef INT32 SINT32;
#if defined(NP2_CPU_64BIT) || defined(__arm__)
typedef int64_t INT64;
typedef uint64_t UINT64;
typedef INT64 SINT64;
#else
#if !defined(__MINGW32__) && !defined(__arm__) // for libretro
//#if !defined(_WINDOWS) && !defined(__arm__) // for me
typedef int32_t INT64;
typedef uint32_t UINT64;
#endif
typedef INT32 SINT64;
#endif
// variable size
typedef size_t SIZET; // format: %zu
typedef intptr_t INTPTR; // format: %PRIdPTR
typedef uintptr_t UINTPTR; // format: %PRIuPTR
#if !defined(_MSC_VER)
typedef intptr_t INT_PTR; // format: %PRIdPTR
typedef uintptr_t UINT_PTR; // format: %PRIuPTR
#endif
typedef intmax_t INTMAX; // format: %PRIdMAX
typedef uintmax_t UINTMAX; // format: %PRIuMAX
// bool
#if defined(__cplusplus)
#if !defined(_WINDOWS) // BOOL typedefed as int in winnt.h
typedef bool BOOL;
#endif
#if !defined(TRUE)
#define TRUE true
#endif
#if !defined(FALSE)
#define FALSE false
#endif
#else
#if defined(C99)
#include <stdbool.h>
#if !defined(_WINDOWS) // BOOL typedefed as int in winnt.h
typedef bool BOOL;
#endif
#if !defined(TRUE)
#define TRUE true
#endif
#if !defined(FALSE)
#define FALSE false
#endif
#else
typedef int BOOL;
#if !defined(TRUE)
#define TRUE (1==1)
#endif
#if !defined(FALSE)
#define FALSE (1==0)
#endif
#endif
#endif
// inline
#if !defined(DEBUG) || !defined(_DEBUG)
#if !defined(INLINE)
#if defined(_MSC_VER)
#pragma warning(disable: 4244)
#pragma warning(disable: 4245)
#define INLINE __inline
#elif defined(__BORLANDC__)
#define INLINE __inline
#elif defined(__GNUC__)
#define INLINE __inline__ __attribute__((always_inline))
#else
#define INLINE
#endif
#endif
#else
#undef INLINE
#define INLINE
#endif
// pi
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_PI
#define M_PIl 3.1415926535897932384626433832795029L
#endif
// --> milstr OEMCHAR
#if defined(_WINDOWS)
#define OEMNEWLINE "\r\n"
#define OEMPATHDIV "\\"
#define OEMPATHDIVC '\\'
#else
#define OEMNEWLINE "\n"
#define OEMPATHDIV "/"
#define OEMPATHDIVC '/'
#endif
#define OEMSLASH "/"
#define OEMSLASHC '/'
#if defined(SUPPORT_STRNLENS)
#define OEMSTRNLENS strnlen_s
#define OEMSTRNLEN strnlen_s
#elif defined(C99) || defined(CPP11)
#define OEMSTRNLENS strnlen
#define OEMSTRNLEN strnlen
#else
#define OEMSTRNLENS(s, z) strlen(s)
#define OEMSTRNLEN(s, z) strlen(s)
#endif
#define OEMSTRLEN strlen
#define STRNLENS OEMSTRNLENS
#define STRNLEN OEMSTRNLEN
#define STRLEN OEMSTRLEN
#if defined(SUPPORT_SNPRINTF)
#define OEMSNPRINTF snprintf
#else
#if defined(C99) || defined(CPP11)
#define OEMSNPRINTF(s, z, f, ...) sprintf(s, f, __VA_ARGS__)
#else
#define OEMSNPRINTF(s, z, f, d) sprintf(s, f, d)
#endif
#endif
#define OEMSPRINTF sprintf
#define SNPRINTF OEMSNPRINTF
#define SPRINTF OEMSPRINTF
#define OEMSTRCPY(s1, s2) OEMSPRINTF(s1, OEMTEXT("%s"), s2)
#define OEMPRINTFSTR(s) printf(OEMTEXT("%s"), s)
// future depracted maybe
#define OEMCHAR char
#define OEMTEXT(string) string
#define STRCALL
// <-- milstr OEMCHAR
// --> Windowsnize
// calling convention
#undef CDECL
#undef STDCALL
#undef CLRCALL
#undef FASTCALL
#undef VECTORCALL
#if defined(__cpluscplus)
#undef THISCALL
#endif
#if defined(_MSC_VER) && defined(_M_IX86) && !defined(LR_VS2017)
#define CDECL __cdecl
#define STDCALL __stdcall
#define FASTCALL __fastcall
#define SAFECALL __safecall
#define CLRCALL __clrcall
#define VECTORCALL __vectorcall
#if defined(__cpluscplus)
#define THISCALL __thiscall
#endif
#elif defined(__GNUC__) && defined(__i386__) && !defined(__ANDROID__) && !defined(EMSCRIPTEN)
#define CDECL __attribute__ ((cdecl))
#define STDCALL __attribute__ ((stdcall))
#define FASTCALL __attribute__ ((fastcall))
#define CLRCALL
#define VECTORCALL __attribute__ ((interrupt))
#if defined(__cpluscplus)
#define THISCALL __attribute__ ((thiscall))
#endif
#else
#define CDECL
#define STDCALL
#define FASTCALL
#define SAFECALL
#define CLRCALL
#define VECTORCALL
#if defined(__cpluscplus)
#define THISCALL
#endif
#endif
#if !defined(_WINDOWS)
#define WINAPI
typedef uint8_t BYTE;
typedef uint16_t WORD;
typedef uint32_t DWORD;
typedef bool BRESULT;
typedef wchar_t TCHAR;
typedef union {
struct {
UINT32 LowPart;
SINT32 HighPart;
} u;
SINT64 QuadPart;
} LARGE_INTEGER;
#define _T(string) string
#define _tcscpy OEMSTRCPY
#define _tcsicmp milstr_cmp
#define _tcsnicmp strncasecmp
#ifndef ZeroMemory
#define ZeroMemory(d, z) memset((d), 0, (z))
#endif
#ifndef CopyMemory
#define CopyMemory(d, s, z) memcpy((d), (s), (z))
#endif
#ifndef FillMemory
#define FillMemory(d, z, c) memset((d), (c), (z))
#endif
#if defined(__WINRT__) && defined(_M_IX86)
#define CreateFileW(f, a, s, sec, p, flg, t) CreateFile2(f, a, s, p, NULL)
#endif
#endif
// <-- Windowsnize
typedef uint8_t REG8;
typedef uint16_t REG16;
#define UNUSED(v) (void)(v)
#define CPUCALL FASTCALL
#define MEMCALL FASTCALL
#define DMACCALL FASTCALL
#define IOOUTCALL FASTCALL
#define IOINPCALL FASTCALL
#define SOUNDCALL FASTCALL
#define VRAMCALL FASTCALL
#define SCRNCALL FASTCALL
#define VERMOUTHCL FASTCALL
#define PARTSCALL FASTCALL
#define GETRAND() rand()
#ifndef MSB_FIRST
#define BYTESEX_LITTLE
#else
#define BYTESEX_BIG
#endif
#define sigjmp_buf jmp_buf
#ifndef sigsetjmp
#define sigsetjmp(env, mask) setjmp(env)
#endif
#ifndef siglongjmp
#define siglongjmp(env, val) longjmp(env, val)
#endif
#define COPY64(pd, ps) *(UINT64*)(pd) = *(UINT64*)(ps);
#ifndef MAX_PATH
#define MAX_PATH 4096
#endif
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef NELEMENTS
#define NELEMENTS(a) (sizeof(a) / sizeof(a[0]))
#endif
#if defined(SUPPORT_LARGE_MEMORY)
#define MEMORY_MAXSIZE 4000
#else
#define MEMORY_MAXSIZE 230
#endif
#if defined(NP2_CPU_64BIT)
#if defined(SUPPORT_LARGE_HDD)
typedef int64_t FILEPOS;
typedef int64_t FILELEN;
#define NHD_MAXSIZE 8000
#define NHD_MAXSIZE2 ((uint32_t)0xffffffff/1024/2)
#define NHD_MAXSIZE28 130558
#else
typedef int32_t FILEPOS;
typedef int32_t FILELEN;
#define NHD_MAXSIZE 2000
#define NHD_MAXSIZE2 2000
#endif
#else
typedef int32_t FILEPOS;
typedef int32_t FILELEN;
#define NHD_MAXSIZE 2000
#define NHD_MAXSIZE2 2000
#endif
#undef MEMOPTIMIZE
#if defined(arm) || defined (__arm__)
#define MEMOPTIMIZE 2
#define LOW12(a) ((((UINT32)(a)) << 20) >> 20)
#define LOW14(a) ((((UINT32)(a)) << 18) >> 18)
#define LOW15(a) ((((UINT32)(a)) << 17) >> 17)
#define LOW16(a) ((UINT16)(a))
#define HIGH16(a) (((UINT32)(a)) >> 16)
#endif
#include "common.h"
#include "common/_memory.h"
#include "common/rect.h"
#include "common/lstarray.h"
#endif // _COMPILER_BASE_H_