chiark / gitweb /
Changelog entry for 2:8.35-7
[pcre3.git] / sljit / sljitConfigInternal.h
1 /*
2  *    Stack-less Just-In-Time compiler
3  *
4  *    Copyright 2009-2012 Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without modification, are
7  * permitted provided that the following conditions are met:
8  *
9  *   1. Redistributions of source code must retain the above copyright notice, this list of
10  *      conditions and the following disclaimer.
11  *
12  *   2. Redistributions in binary form must reproduce the above copyright notice, this list
13  *      of conditions and the following disclaimer in the documentation and/or other materials
14  *      provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19  * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #ifndef _SLJIT_CONFIG_INTERNAL_H_
28 #define _SLJIT_CONFIG_INTERNAL_H_
29
30 /*
31    SLJIT defines the following macros depending on the target architecture:
32
33    Feature detection (boolean) macros:
34    SLJIT_32BIT_ARCHITECTURE : 32 bit architecture
35    SLJIT_64BIT_ARCHITECTURE : 64 bit architecture
36    SLJIT_WORD_SHIFT : the shift required to apply when accessing a sljit_sw/sljit_uw array by index
37    SLJIT_DOUBLE_SHIFT : the shift required to apply when accessing a double array by index
38    SLJIT_LITTLE_ENDIAN : little endian architecture
39    SLJIT_BIG_ENDIAN : big endian architecture
40    SLJIT_UNALIGNED : allows unaligned memory accesses for non-fpu operations (only!)
41    SLJIT_INDIRECT_CALL : see SLJIT_FUNC_OFFSET() for more information
42    SLJIT_RETURN_ADDRESS_OFFSET : a return instruction always adds this offset to the return address
43
44    Types and useful macros:
45    sljit_sb, sljit_ub : signed and unsigned 8 bit byte
46    sljit_sh, sljit_uh : signed and unsigned 16 bit half-word (short) type
47    sljit_si, sljit_ui : signed and unsigned 32 bit integer type
48    sljit_sw, sljit_uw : signed and unsigned machine word, enough to store a pointer
49    sljit_p : unsgined pointer value (usually the same as sljit_uw, but
50              some 64 bit ABIs may use 32 bit pointers)
51    sljit_s : single precision floating point value
52    sljit_d : double precision floating point value
53    SLJIT_CALL : C calling convention define for both calling JIT form C and C callbacks for JIT
54    SLJIT_W(number) : defining 64 bit constants on 64 bit architectures (compiler independent helper)
55 */
56
57 #if !((defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
58         || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
59         || (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) \
60         || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
61         || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
62         || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
63         || (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
64         || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
65         || (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
66         || (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) \
67         || (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) \
68         || (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX) \
69         || (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO) \
70         || (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED))
71 #error "An architecture must be selected"
72 #endif
73
74 /* Sanity check. */
75 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
76         + (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
77         + (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) \
78         + (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
79         + (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
80         + (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
81         + (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
82         + (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
83         + (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX) \
84         + (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
85         + (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) \
86         + (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) \
87         + (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO) \
88         + (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) >= 2
89 #error "Multiple architectures are selected"
90 #endif
91
92 /* Auto select option (requires compiler support) */
93 #if (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO)
94
95 #ifndef _WIN32
96
97 #if defined(__i386__) || defined(__i386)
98 #define SLJIT_CONFIG_X86_32 1
99 #elif defined(__x86_64__)
100 # if defined(__ILP32__)
101 #  define SLJIT_CONFIG_UNSUPPORTED 1
102 # else
103 #  define SLJIT_CONFIG_X86_64 1
104 # endif
105 #elif defined(__arm__) || defined(__ARM__)
106 #ifdef __thumb2__
107 #define SLJIT_CONFIG_ARM_THUMB2 1
108 #elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__)
109 #define SLJIT_CONFIG_ARM_V7 1
110 #else
111 #define SLJIT_CONFIG_ARM_V5 1
112 #endif
113 #elif defined (__aarch64__)
114 #define SLJIT_CONFIG_ARM_64 1
115 #elif defined(__ppc64__) || defined(__powerpc64__) || defined(_ARCH_PPC64) || (defined(_POWER) && defined(__64BIT__))
116 #define SLJIT_CONFIG_PPC_64 1
117 #elif defined(__ppc__) || defined(__powerpc__) || defined(_ARCH_PPC) || defined(_ARCH_PWR) || defined(_ARCH_PWR2) || defined(_POWER)
118 # ifndef __NO_FPRS__
119 #  define SLJIT_CONFIG_PPC_32 1
120 # else
121 #  define SLJIT_CONFIG_UNSUPPORTED 1
122 # endif
123 #elif defined(__mips__) && !defined(_LP64)
124 #define SLJIT_CONFIG_MIPS_32 1
125 #elif defined(__mips64)
126 #define SLJIT_CONFIG_MIPS_64 1
127 #elif defined(__sparc__) || defined(__sparc)
128 #define SLJIT_CONFIG_SPARC_32 1
129 #elif defined(__tilegx__)
130 #define SLJIT_CONFIG_TILEGX 1
131 #else
132 /* Unsupported architecture */
133 #define SLJIT_CONFIG_UNSUPPORTED 1
134 #endif
135
136 #else /* !_WIN32 */
137
138 #if defined(_M_X64) || defined(__x86_64__)
139 #define SLJIT_CONFIG_X86_64 1
140 #elif defined(_ARM_)
141 #define SLJIT_CONFIG_ARM_V5 1
142 #else
143 #define SLJIT_CONFIG_X86_32 1
144 #endif
145
146 #endif /* !WIN32 */
147 #endif /* SLJIT_CONFIG_AUTO */
148
149 #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
150 #undef SLJIT_EXECUTABLE_ALLOCATOR
151 #endif
152
153 #if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED)
154
155 /* These libraries are needed for the macros below. */
156 #include <stdlib.h>
157 #include <string.h>
158
159 #endif /* STD_MACROS_DEFINED */
160
161 /* General macros:
162    Note: SLJIT is designed to be independent from them as possible.
163
164    In release mode (SLJIT_DEBUG is not defined) only the following macros are needed:
165 */
166
167 #ifndef SLJIT_MALLOC
168 #define SLJIT_MALLOC(size) malloc(size)
169 #endif
170
171 #ifndef SLJIT_FREE
172 #define SLJIT_FREE(ptr) free(ptr)
173 #endif
174
175 #ifndef SLJIT_MEMMOVE
176 #define SLJIT_MEMMOVE(dest, src, len) memmove(dest, src, len)
177 #endif
178
179 #ifndef SLJIT_ZEROMEM
180 #define SLJIT_ZEROMEM(dest, len) memset(dest, 0, len)
181 #endif
182
183 #if !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY)
184
185 #if defined(__GNUC__) && (__GNUC__ >= 3)
186 #define SLJIT_LIKELY(x)         __builtin_expect((x), 1)
187 #define SLJIT_UNLIKELY(x)       __builtin_expect((x), 0)
188 #else
189 #define SLJIT_LIKELY(x)         (x)
190 #define SLJIT_UNLIKELY(x)       (x)
191 #endif
192
193 #endif /* !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY) */
194
195 #ifndef SLJIT_INLINE
196 /* Inline functions. Some old compilers do not support them. */
197 #if defined(__SUNPRO_C) && __SUNPRO_C <= 0x510
198 #define SLJIT_INLINE
199 #else
200 #define SLJIT_INLINE __inline
201 #endif
202 #endif /* !SLJIT_INLINE */
203
204 #ifndef SLJIT_CONST
205 /* Const variables. */
206 #define SLJIT_CONST const
207 #endif
208
209 #ifndef SLJIT_UNUSED_ARG
210 /* Unused arguments. */
211 #define SLJIT_UNUSED_ARG(arg) (void)arg
212 #endif
213
214 #if (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC)
215 /* Static ABI functions. For all-in-one programs. */
216
217 #if defined(__GNUC__)
218 /* Disable unused warnings in gcc. */
219 #define SLJIT_API_FUNC_ATTRIBUTE static __attribute__((unused))
220 #else
221 #define SLJIT_API_FUNC_ATTRIBUTE static
222 #endif
223
224 #else
225 #define SLJIT_API_FUNC_ATTRIBUTE
226 #endif /* (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC) */
227
228 #ifndef SLJIT_CACHE_FLUSH
229
230 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
231
232 /* Not required to implement on archs with unified caches. */
233 #define SLJIT_CACHE_FLUSH(from, to)
234
235 #elif defined __APPLE__
236
237 /* Supported by all macs since Mac OS 10.5.
238    However, it does not work on non-jailbroken iOS devices,
239    although the compilation is successful. */
240
241 #define SLJIT_CACHE_FLUSH(from, to) \
242         sys_icache_invalidate((char*)(from), (char*)(to) - (char*)(from))
243
244 #elif defined __ANDROID__
245
246 /* Android lacks __clear_cache; instead, cacheflush should be used. */
247
248 #define SLJIT_CACHE_FLUSH(from, to) \
249     cacheflush((long)(from), (long)(to), 0)
250
251 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
252
253 /* The __clear_cache() implementation of GCC is a dummy function on PowerPC. */
254 #define SLJIT_CACHE_FLUSH(from, to) \
255         ppc_cache_flush((from), (to))
256
257 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
258
259 /* The __clear_cache() implementation of GCC is a dummy function on Sparc. */
260 #define SLJIT_CACHE_FLUSH(from, to) \
261         sparc_cache_flush((from), (to))
262
263 #else
264
265 /* Calls __ARM_NR_cacheflush on ARM-Linux. */
266 #define SLJIT_CACHE_FLUSH(from, to) \
267         __clear_cache((char*)(from), (char*)(to))
268
269 #endif
270
271 #endif /* !SLJIT_CACHE_FLUSH */
272
273 /* 8 bit byte type. */
274 typedef unsigned char sljit_ub;
275 typedef signed char sljit_sb;
276
277 /* 16 bit half-word type. */
278 typedef unsigned short int sljit_uh;
279 typedef signed short int sljit_sh;
280
281 /* 32 bit integer type. */
282 typedef unsigned int sljit_ui;
283 typedef signed int sljit_si;
284
285 /* Machine word type. Can encapsulate a pointer.
286      32 bit for 32 bit machines.
287      64 bit for 64 bit machines. */
288 #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
289 /* Just to have something. */
290 #define SLJIT_WORD_SHIFT 0
291 typedef unsigned long int sljit_uw;
292 typedef long int sljit_sw;
293 #elif !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
294         && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
295         && !(defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
296         && !(defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) \
297         && !(defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
298 #define SLJIT_32BIT_ARCHITECTURE 1
299 #define SLJIT_WORD_SHIFT 2
300 typedef unsigned int sljit_uw;
301 typedef int sljit_sw;
302 #else
303 #define SLJIT_64BIT_ARCHITECTURE 1
304 #define SLJIT_WORD_SHIFT 3
305 #ifdef _WIN32
306 typedef unsigned __int64 sljit_uw;
307 typedef __int64 sljit_sw;
308 #else
309 typedef unsigned long int sljit_uw;
310 typedef long int sljit_sw;
311 #endif
312 #endif
313
314 typedef sljit_uw sljit_p;
315
316 /* Floating point types. */
317 typedef float sljit_s;
318 typedef double sljit_d;
319
320 /* Shift for pointer sized data. */
321 #define SLJIT_POINTER_SHIFT SLJIT_WORD_SHIFT
322
323 /* Shift for double precision sized data. */
324 #define SLJIT_DOUBLE_SHIFT 3
325
326 #ifndef SLJIT_W
327
328 /* Defining long constants. */
329 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
330 #define SLJIT_W(w)      (w##ll)
331 #else
332 #define SLJIT_W(w)      (w)
333 #endif
334
335 #endif /* !SLJIT_W */
336
337 #ifndef SLJIT_CALL
338
339 /* ABI (Application Binary Interface) types. */
340 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
341
342 #if defined(__GNUC__) && !defined(__APPLE__)
343
344 #define SLJIT_CALL __attribute__ ((fastcall))
345 #define SLJIT_X86_32_FASTCALL 1
346
347 #elif defined(_MSC_VER)
348
349 #define SLJIT_CALL __fastcall
350 #define SLJIT_X86_32_FASTCALL 1
351
352 #elif defined(__BORLANDC__)
353
354 #define SLJIT_CALL __msfastcall
355 #define SLJIT_X86_32_FASTCALL 1
356
357 #else /* Unknown compiler. */
358
359 /* The cdecl attribute is the default. */
360 #define SLJIT_CALL
361
362 #endif
363
364 #else /* Non x86-32 architectures. */
365
366 #define SLJIT_CALL
367
368 #endif /* SLJIT_CONFIG_X86_32 */
369
370 #endif /* !SLJIT_CALL */
371
372 #if !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN)
373
374 /* These macros are useful for the applications. */
375 #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
376         || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
377
378 #ifdef __LITTLE_ENDIAN__
379 #define SLJIT_LITTLE_ENDIAN 1
380 #else
381 #define SLJIT_BIG_ENDIAN 1
382 #endif
383
384 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
385         || (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
386
387 #ifdef __MIPSEL__
388 #define SLJIT_LITTLE_ENDIAN 1
389 #else
390 #define SLJIT_BIG_ENDIAN 1
391 #endif
392
393 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
394
395 #define SLJIT_BIG_ENDIAN 1
396
397 #else
398 #define SLJIT_LITTLE_ENDIAN 1
399 #endif
400
401 #endif /* !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN) */
402
403 /* Sanity check. */
404 #if (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
405 #error "Exactly one endianness must be selected"
406 #endif
407
408 #if !(defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && !(defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
409 #error "Exactly one endianness must be selected"
410 #endif
411
412 #ifndef SLJIT_INDIRECT_CALL
413 #if ((defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)) \
414         || ((defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) && defined _AIX)
415 /* It seems certain ppc compilers use an indirect addressing for functions
416    which makes things complicated. */
417 #define SLJIT_INDIRECT_CALL 1
418 #endif
419 #endif /* SLJIT_INDIRECT_CALL */
420
421 #ifndef SLJIT_RETURN_ADDRESS_OFFSET
422 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
423 #define SLJIT_RETURN_ADDRESS_OFFSET 8
424 #else
425 #define SLJIT_RETURN_ADDRESS_OFFSET 0
426 #endif
427 #endif /* SLJIT_RETURN_ADDRESS_OFFSET */
428
429 #ifndef SLJIT_SSE2
430
431 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
432 /* Turn on SSE2 support on x86. */
433 #define SLJIT_SSE2 1
434
435 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
436 /* Auto detect SSE2 support using CPUID.
437    On 64 bit x86 cpus, sse2 must be present. */
438 #define SLJIT_DETECT_SSE2 1
439 #endif
440
441 #endif /* (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) */
442
443 #endif /* !SLJIT_SSE2 */
444
445 #ifndef SLJIT_UNALIGNED
446
447 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
448         || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
449         || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
450         || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
451         || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
452         || (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
453         || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
454 #define SLJIT_UNALIGNED 1
455 #endif
456
457 #endif /* !SLJIT_UNALIGNED */
458
459 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
460 SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size);
461 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_exec(void* ptr);
462 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_unused_memory_exec(void);
463 #define SLJIT_MALLOC_EXEC(size) sljit_malloc_exec(size)
464 #define SLJIT_FREE_EXEC(ptr) sljit_free_exec(ptr)
465 #endif
466
467 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
468 #include <stdio.h>
469 #endif
470
471 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
472
473 #if !defined(SLJIT_ASSERT) || !defined(SLJIT_ASSERT_STOP)
474
475 /* SLJIT_HALT_PROCESS must halt the process. */
476 #ifndef SLJIT_HALT_PROCESS
477 #include <stdlib.h>
478
479 #define SLJIT_HALT_PROCESS() \
480         abort();
481 #endif /* !SLJIT_HALT_PROCESS */
482
483 #include <stdio.h>
484
485 #endif /* !SLJIT_ASSERT || !SLJIT_ASSERT_STOP */
486
487 /* Feel free to redefine these two macros. */
488 #ifndef SLJIT_ASSERT
489
490 #define SLJIT_ASSERT(x) \
491         do { \
492                 if (SLJIT_UNLIKELY(!(x))) { \
493                         printf("Assertion failed at " __FILE__ ":%d\n", __LINE__); \
494                         SLJIT_HALT_PROCESS(); \
495                 } \
496         } while (0)
497
498 #endif /* !SLJIT_ASSERT */
499
500 #ifndef SLJIT_ASSERT_STOP
501
502 #define SLJIT_ASSERT_STOP() \
503         do { \
504                 printf("Should never been reached " __FILE__ ":%d\n", __LINE__); \
505                 SLJIT_HALT_PROCESS(); \
506         } while (0)
507
508 #endif /* !SLJIT_ASSERT_STOP */
509
510 #else /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
511
512 /* Forcing empty, but valid statements. */
513 #undef SLJIT_ASSERT
514 #undef SLJIT_ASSERT_STOP
515
516 #define SLJIT_ASSERT(x) \
517         do { } while (0)
518 #define SLJIT_ASSERT_STOP() \
519         do { } while (0)
520
521 #endif /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
522
523 #ifndef SLJIT_COMPILE_ASSERT
524
525 /* Should be improved eventually. */
526 #define SLJIT_COMPILE_ASSERT(x, description) \
527         SLJIT_ASSERT(x)
528
529 #endif /* !SLJIT_COMPILE_ASSERT */
530
531 #endif