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 #include "sljitLir.h"
28
29 #define CHECK_ERROR() \
30 do { \
31 if (SLJIT_UNLIKELY(compiler->error)) \
32 return compiler->error; \
33 } while (0)
34
35 #define CHECK_ERROR_PTR() \
36 do { \
37 if (SLJIT_UNLIKELY(compiler->error)) \
38 return NULL; \
39 } while (0)
40
41 #define FAIL_IF(expr) \
42 do { \
43 if (SLJIT_UNLIKELY(expr)) \
44 return compiler->error; \
45 } while (0)
46
47 #define PTR_FAIL_IF(expr) \
48 do { \
49 if (SLJIT_UNLIKELY(expr)) \
50 return NULL; \
51 } while (0)
52
53 #define FAIL_IF_NULL(ptr) \
54 do { \
55 if (SLJIT_UNLIKELY(!(ptr))) { \
56 compiler->error = SLJIT_ERR_ALLOC_FAILED; \
57 return SLJIT_ERR_ALLOC_FAILED; \
58 } \
59 } while (0)
60
61 #define PTR_FAIL_IF_NULL(ptr) \
62 do { \
63 if (SLJIT_UNLIKELY(!(ptr))) { \
64 compiler->error = SLJIT_ERR_ALLOC_FAILED; \
65 return NULL; \
66 } \
67 } while (0)
68
69 #define PTR_FAIL_WITH_EXEC_IF(ptr) \
70 do { \
71 if (SLJIT_UNLIKELY(!(ptr))) { \
72 compiler->error = SLJIT_ERR_EX_ALLOC_FAILED; \
73 return NULL; \
74 } \
75 } while (0)
76
77 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
78
79 #define GET_OPCODE(op) \
80 ((op) & ~(SLJIT_INT_OP | SLJIT_SET_E | SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))
81
82 #define GET_FLAGS(op) \
83 ((op) & (SLJIT_SET_E | SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_O | SLJIT_SET_C))
84
85 #define GET_ALL_FLAGS(op) \
86 ((op) & (SLJIT_INT_OP | SLJIT_SET_E | SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))
87
88 #define TYPE_CAST_NEEDED(op) \
89 (((op) >= SLJIT_MOV_UB && (op) <= SLJIT_MOV_SH) || ((op) >= SLJIT_MOVU_UB && (op) <= SLJIT_MOVU_SH))
90
91 #define BUF_SIZE 4096
92
93 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
94 #define ABUF_SIZE 2048
95 #else
96 #define ABUF_SIZE 4096
97 #endif
98
99 /* Parameter parsing. */
100 #define REG_MASK 0x3f
101 #define OFFS_REG(reg) (((reg) >> 8) & REG_MASK)
102 #define OFFS_REG_MASK (REG_MASK << 8)
103 #define TO_OFFS_REG(reg) ((reg) << 8)
104 /* When reg cannot be unused. */
105 #define FAST_IS_REG(reg) ((reg) <= REG_MASK)
106 /* When reg can be unused. */
107 #define SLOW_IS_REG(reg) ((reg) > 0 && (reg) <= REG_MASK)
108
109 /* Jump flags. */
110 #define JUMP_LABEL 0x1
111 #define JUMP_ADDR 0x2
112 /* SLJIT_REWRITABLE_JUMP is 0x1000. */
113
114 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
115 # define PATCH_MB 0x4
116 # define PATCH_MW 0x8
117 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
118 # define PATCH_MD 0x10
119 #endif
120 #endif
121
122 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
123 # define IS_BL 0x4
124 # define PATCH_B 0x8
125 #endif
126
127 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
128 # define CPOOL_SIZE 512
129 #endif
130
131 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
132 # define IS_COND 0x04
133 # define IS_BL 0x08
134 /* conditional + imm8 */
135 # define PATCH_TYPE1 0x10
136 /* conditional + imm20 */
137 # define PATCH_TYPE2 0x20
138 /* IT + imm24 */
139 # define PATCH_TYPE3 0x30
140 /* imm11 */
141 # define PATCH_TYPE4 0x40
142 /* imm24 */
143 # define PATCH_TYPE5 0x50
144 /* BL + imm24 */
145 # define PATCH_BL 0x60
146 /* 0xf00 cc code for branches */
147 #endif
148
149 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
150 # define IS_COND 0x004
151 # define IS_CBZ 0x008
152 # define IS_BL 0x010
153 # define PATCH_B 0x020
154 # define PATCH_COND 0x040
155 # define PATCH_ABS48 0x080
156 # define PATCH_ABS64 0x100
157 #endif
158
159 #if (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
160 # define IS_COND 0x004
161 # define IS_CALL 0x008
162 # define PATCH_B 0x010
163 # define PATCH_ABS_B 0x020
164 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
165 # define PATCH_ABS32 0x040
166 # define PATCH_ABS48 0x080
167 #endif
168 # define REMOVE_COND 0x100
169 #endif
170
171 #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
172 # define IS_MOVABLE 0x004
173 # define IS_JAL 0x008
174 # define IS_CALL 0x010
175 # define IS_BIT26_COND 0x020
176 # define IS_BIT16_COND 0x040
177
178 # define IS_COND (IS_BIT26_COND | IS_BIT16_COND)
179
180 # define PATCH_B 0x080
181 # define PATCH_J 0x100
182
183 #if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
184 # define PATCH_ABS32 0x200
185 # define PATCH_ABS48 0x400
186 #endif
187
188 /* instruction types */
189 # define MOVABLE_INS 0
190 /* 1 - 31 last destination register */
191 /* no destination (i.e: store) */
192 # define UNMOVABLE_INS 32
193 /* FPU status register */
194 # define FCSR_FCC 33
195 #endif
196
197 #if (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
198 # define IS_JAL 0x04
199 # define IS_COND 0x08
200
201 # define PATCH_B 0x10
202 # define PATCH_J 0x20
203 #endif
204
205 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
206 # define IS_MOVABLE 0x04
207 # define IS_COND 0x08
208 # define IS_CALL 0x10
209
210 # define PATCH_B 0x20
211 # define PATCH_CALL 0x40
212
213 /* instruction types */
214 # define MOVABLE_INS 0
215 /* 1 - 31 last destination register */
216 /* no destination (i.e: store) */
217 # define UNMOVABLE_INS 32
218
219 # define DST_INS_MASK 0xff
220
221 /* ICC_SET is the same as SET_FLAGS. */
222 # define ICC_IS_SET (1 << 23)
223 # define FCC_IS_SET (1 << 24)
224 #endif
225
226 /* Stack management. */
227
228 #define GET_SAVED_REGISTERS_SIZE(scratches, saveds, extra) \
229 (((scratches < SLJIT_NUMBER_OF_SCRATCH_REGISTERS ? 0 : (scratches - SLJIT_NUMBER_OF_SCRATCH_REGISTERS)) + \
230 (saveds < SLJIT_NUMBER_OF_SAVED_REGISTERS ? saveds : SLJIT_NUMBER_OF_SAVED_REGISTERS) + \
231 extra) * sizeof(sljit_sw))
232
233 #define ADJUST_LOCAL_OFFSET(p, i) \
234 if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
235 (i) += SLJIT_LOCALS_OFFSET;
236
237 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
238
239 /* Utils can still be used even if SLJIT_CONFIG_UNSUPPORTED is set. */
240 #include "sljitUtils.c"
241
242 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
243
244 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
245 #include "sljitExecAllocator.c"
246 #endif
247
248 /* Argument checking features. */
249
250 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
251
252 /* Returns with error when an invalid argument is passed. */
253
254 #define CHECK_ARGUMENT(x) \
255 do { \
256 if (SLJIT_UNLIKELY(!(x))) \
257 return 1; \
258 } while (0)
259
260 #define CHECK_RETURN_TYPE sljit_si
261 #define CHECK_RETURN_OK return 0
262
263 #define CHECK(x) \
264 do { \
265 if (SLJIT_UNLIKELY(x)) { \
266 compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
267 return SLJIT_ERR_BAD_ARGUMENT; \
268 } \
269 } while (0)
270
271 #define CHECK_PTR(x) \
272 do { \
273 if (SLJIT_UNLIKELY(x)) { \
274 compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
275 return NULL; \
276 } \
277 } while (0)
278
279 #define CHECK_REG_INDEX(x) \
280 do { \
281 if (SLJIT_UNLIKELY(x)) { \
282 return -2; \
283 } \
284 } while (0)
285
286 #elif (defined SLJIT_DEBUG && SLJIT_DEBUG)
287
288 /* Assertion failure occures if an invalid argument is passed. */
289 #undef SLJIT_ARGUMENT_CHECKS
290 #define SLJIT_ARGUMENT_CHECKS 1
291
292 #define CHECK_ARGUMENT(x) SLJIT_ASSERT(x)
293 #define CHECK_RETURN_TYPE void
294 #define CHECK_RETURN_OK return
295 #define CHECK(x) x
296 #define CHECK_PTR(x) x
297 #define CHECK_REG_INDEX(x) x
298
299 #elif (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
300
301 /* Arguments are not checked. */
302 #define CHECK_RETURN_TYPE void
303 #define CHECK_RETURN_OK return
304 #define CHECK(x) x
305 #define CHECK_PTR(x) x
306 #define CHECK_REG_INDEX(x) x
307
308 #else
309
310 /* Arguments are not checked. */
311 #define CHECK(x)
312 #define CHECK_PTR(x)
313 #define CHECK_REG_INDEX(x)
314
315 #endif /* SLJIT_ARGUMENT_CHECKS */
316
317 /* --------------------------------------------------------------------- */
318 /* Public functions */
319 /* --------------------------------------------------------------------- */
320
321 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
322 #define SLJIT_NEEDS_COMPILER_INIT 1
323 static sljit_si compiler_initialized = 0;
324 /* A thread safe initialization. */
325 static void init_compiler(void);
326 #endif
327
sljit_create_compiler(void * allocator_data)328 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data)
329 {
330 struct sljit_compiler *compiler = (struct sljit_compiler*)SLJIT_MALLOC(sizeof(struct sljit_compiler), allocator_data);
331 if (!compiler)
332 return NULL;
333 SLJIT_ZEROMEM(compiler, sizeof(struct sljit_compiler));
334
335 SLJIT_COMPILE_ASSERT(
336 sizeof(sljit_sb) == 1 && sizeof(sljit_ub) == 1
337 && sizeof(sljit_sh) == 2 && sizeof(sljit_uh) == 2
338 && sizeof(sljit_si) == 4 && sizeof(sljit_ui) == 4
339 && (sizeof(sljit_p) == 4 || sizeof(sljit_p) == 8)
340 && sizeof(sljit_p) <= sizeof(sljit_sw)
341 && (sizeof(sljit_sw) == 4 || sizeof(sljit_sw) == 8)
342 && (sizeof(sljit_uw) == 4 || sizeof(sljit_uw) == 8),
343 invalid_integer_types);
344 SLJIT_COMPILE_ASSERT(SLJIT_INT_OP == SLJIT_SINGLE_OP,
345 int_op_and_single_op_must_be_the_same);
346 SLJIT_COMPILE_ASSERT(SLJIT_REWRITABLE_JUMP != SLJIT_SINGLE_OP,
347 rewritable_jump_and_single_op_must_not_be_the_same);
348
349 /* Only the non-zero members must be set. */
350 compiler->error = SLJIT_SUCCESS;
351
352 compiler->allocator_data = allocator_data;
353 compiler->buf = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, allocator_data);
354 compiler->abuf = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, allocator_data);
355
356 if (!compiler->buf || !compiler->abuf) {
357 if (compiler->buf)
358 SLJIT_FREE(compiler->buf, allocator_data);
359 if (compiler->abuf)
360 SLJIT_FREE(compiler->abuf, allocator_data);
361 SLJIT_FREE(compiler, allocator_data);
362 return NULL;
363 }
364
365 compiler->buf->next = NULL;
366 compiler->buf->used_size = 0;
367 compiler->abuf->next = NULL;
368 compiler->abuf->used_size = 0;
369
370 compiler->scratches = -1;
371 compiler->saveds = -1;
372 compiler->fscratches = -1;
373 compiler->fsaveds = -1;
374 compiler->local_size = -1;
375
376 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
377 compiler->args = -1;
378 #endif
379
380 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
381 compiler->cpool = (sljit_uw*)SLJIT_MALLOC(CPOOL_SIZE * sizeof(sljit_uw)
382 + CPOOL_SIZE * sizeof(sljit_ub), allocator_data);
383 if (!compiler->cpool) {
384 SLJIT_FREE(compiler->buf, allocator_data);
385 SLJIT_FREE(compiler->abuf, allocator_data);
386 SLJIT_FREE(compiler, allocator_data);
387 return NULL;
388 }
389 compiler->cpool_unique = (sljit_ub*)(compiler->cpool + CPOOL_SIZE);
390 compiler->cpool_diff = 0xffffffff;
391 #endif
392
393 #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
394 compiler->delay_slot = UNMOVABLE_INS;
395 #endif
396
397 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
398 compiler->delay_slot = UNMOVABLE_INS;
399 #endif
400
401 #if (defined SLJIT_NEEDS_COMPILER_INIT && SLJIT_NEEDS_COMPILER_INIT)
402 if (!compiler_initialized) {
403 init_compiler();
404 compiler_initialized = 1;
405 }
406 #endif
407
408 return compiler;
409 }
410
sljit_free_compiler(struct sljit_compiler * compiler)411 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
412 {
413 struct sljit_memory_fragment *buf;
414 struct sljit_memory_fragment *curr;
415 void *allocator_data = compiler->allocator_data;
416 SLJIT_UNUSED_ARG(allocator_data);
417
418 buf = compiler->buf;
419 while (buf) {
420 curr = buf;
421 buf = buf->next;
422 SLJIT_FREE(curr, allocator_data);
423 }
424
425 buf = compiler->abuf;
426 while (buf) {
427 curr = buf;
428 buf = buf->next;
429 SLJIT_FREE(curr, allocator_data);
430 }
431
432 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
433 SLJIT_FREE(compiler->cpool, allocator_data);
434 #endif
435 SLJIT_FREE(compiler, allocator_data);
436 }
437
sljit_set_compiler_memory_error(struct sljit_compiler * compiler)438 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
439 {
440 if (compiler->error == SLJIT_SUCCESS)
441 compiler->error = SLJIT_ERR_ALLOC_FAILED;
442 }
443
444 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
sljit_free_code(void * code)445 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
446 {
447 /* Remove thumb mode flag. */
448 SLJIT_FREE_EXEC((void*)((sljit_uw)code & ~0x1));
449 }
450 #elif (defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL)
sljit_free_code(void * code)451 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
452 {
453 /* Resolve indirection. */
454 code = (void*)(*(sljit_uw*)code);
455 SLJIT_FREE_EXEC(code);
456 }
457 #else
sljit_free_code(void * code)458 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
459 {
460 SLJIT_FREE_EXEC(code);
461 }
462 #endif
463
sljit_set_label(struct sljit_jump * jump,struct sljit_label * label)464 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
465 {
466 if (SLJIT_LIKELY(!!jump) && SLJIT_LIKELY(!!label)) {
467 jump->flags &= ~JUMP_ADDR;
468 jump->flags |= JUMP_LABEL;
469 jump->u.label = label;
470 }
471 }
472
sljit_set_target(struct sljit_jump * jump,sljit_uw target)473 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
474 {
475 if (SLJIT_LIKELY(!!jump)) {
476 jump->flags &= ~JUMP_LABEL;
477 jump->flags |= JUMP_ADDR;
478 jump->u.target = target;
479 }
480 }
481
482 /* --------------------------------------------------------------------- */
483 /* Private functions */
484 /* --------------------------------------------------------------------- */
485
ensure_buf(struct sljit_compiler * compiler,sljit_uw size)486 static void* ensure_buf(struct sljit_compiler *compiler, sljit_uw size)
487 {
488 sljit_ub *ret;
489 struct sljit_memory_fragment *new_frag;
490
491 SLJIT_ASSERT(size <= 256);
492 if (compiler->buf->used_size + size <= (BUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
493 ret = compiler->buf->memory + compiler->buf->used_size;
494 compiler->buf->used_size += size;
495 return ret;
496 }
497 new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, compiler->allocator_data);
498 PTR_FAIL_IF_NULL(new_frag);
499 new_frag->next = compiler->buf;
500 compiler->buf = new_frag;
501 new_frag->used_size = size;
502 return new_frag->memory;
503 }
504
ensure_abuf(struct sljit_compiler * compiler,sljit_uw size)505 static void* ensure_abuf(struct sljit_compiler *compiler, sljit_uw size)
506 {
507 sljit_ub *ret;
508 struct sljit_memory_fragment *new_frag;
509
510 SLJIT_ASSERT(size <= 256);
511 if (compiler->abuf->used_size + size <= (ABUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
512 ret = compiler->abuf->memory + compiler->abuf->used_size;
513 compiler->abuf->used_size += size;
514 return ret;
515 }
516 new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, compiler->allocator_data);
517 PTR_FAIL_IF_NULL(new_frag);
518 new_frag->next = compiler->abuf;
519 compiler->abuf = new_frag;
520 new_frag->used_size = size;
521 return new_frag->memory;
522 }
523
sljit_alloc_memory(struct sljit_compiler * compiler,sljit_si size)524 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_si size)
525 {
526 CHECK_ERROR_PTR();
527
528 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
529 if (size <= 0 || size > 128)
530 return NULL;
531 size = (size + 7) & ~7;
532 #else
533 if (size <= 0 || size > 64)
534 return NULL;
535 size = (size + 3) & ~3;
536 #endif
537 return ensure_abuf(compiler, size);
538 }
539
reverse_buf(struct sljit_compiler * compiler)540 static SLJIT_INLINE void reverse_buf(struct sljit_compiler *compiler)
541 {
542 struct sljit_memory_fragment *buf = compiler->buf;
543 struct sljit_memory_fragment *prev = NULL;
544 struct sljit_memory_fragment *tmp;
545
546 do {
547 tmp = buf->next;
548 buf->next = prev;
549 prev = buf;
550 buf = tmp;
551 } while (buf != NULL);
552
553 compiler->buf = prev;
554 }
555
set_emit_enter(struct sljit_compiler * compiler,sljit_si options,sljit_si args,sljit_si scratches,sljit_si saveds,sljit_si fscratches,sljit_si fsaveds,sljit_si local_size)556 static SLJIT_INLINE void set_emit_enter(struct sljit_compiler *compiler,
557 sljit_si options, sljit_si args, sljit_si scratches, sljit_si saveds,
558 sljit_si fscratches, sljit_si fsaveds, sljit_si local_size)
559 {
560 SLJIT_UNUSED_ARG(args);
561 SLJIT_UNUSED_ARG(local_size);
562
563 compiler->options = options;
564 compiler->scratches = scratches;
565 compiler->saveds = saveds;
566 compiler->fscratches = fscratches;
567 compiler->fsaveds = fsaveds;
568 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
569 compiler->logical_local_size = local_size;
570 #endif
571 }
572
set_set_context(struct sljit_compiler * compiler,sljit_si options,sljit_si args,sljit_si scratches,sljit_si saveds,sljit_si fscratches,sljit_si fsaveds,sljit_si local_size)573 static SLJIT_INLINE void set_set_context(struct sljit_compiler *compiler,
574 sljit_si options, sljit_si args, sljit_si scratches, sljit_si saveds,
575 sljit_si fscratches, sljit_si fsaveds, sljit_si local_size)
576 {
577 SLJIT_UNUSED_ARG(args);
578 SLJIT_UNUSED_ARG(local_size);
579
580 compiler->options = options;
581 compiler->scratches = scratches;
582 compiler->saveds = saveds;
583 compiler->fscratches = fscratches;
584 compiler->fsaveds = fsaveds;
585 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
586 compiler->logical_local_size = local_size;
587 #endif
588 }
589
set_label(struct sljit_label * label,struct sljit_compiler * compiler)590 static SLJIT_INLINE void set_label(struct sljit_label *label, struct sljit_compiler *compiler)
591 {
592 label->next = NULL;
593 label->size = compiler->size;
594 if (compiler->last_label)
595 compiler->last_label->next = label;
596 else
597 compiler->labels = label;
598 compiler->last_label = label;
599 }
600
set_jump(struct sljit_jump * jump,struct sljit_compiler * compiler,sljit_si flags)601 static SLJIT_INLINE void set_jump(struct sljit_jump *jump, struct sljit_compiler *compiler, sljit_si flags)
602 {
603 jump->next = NULL;
604 jump->flags = flags;
605 if (compiler->last_jump)
606 compiler->last_jump->next = jump;
607 else
608 compiler->jumps = jump;
609 compiler->last_jump = jump;
610 }
611
set_const(struct sljit_const * const_,struct sljit_compiler * compiler)612 static SLJIT_INLINE void set_const(struct sljit_const *const_, struct sljit_compiler *compiler)
613 {
614 const_->next = NULL;
615 const_->addr = compiler->size;
616 if (compiler->last_const)
617 compiler->last_const->next = const_;
618 else
619 compiler->consts = const_;
620 compiler->last_const = const_;
621 }
622
623 #define ADDRESSING_DEPENDS_ON(exp, reg) \
624 (((exp) & SLJIT_MEM) && (((exp) & REG_MASK) == reg || OFFS_REG(exp) == reg))
625
626 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
627 #define FUNCTION_CHECK_OP() \
628 CHECK_ARGUMENT(!GET_FLAGS(op) || !(op & SLJIT_KEEP_FLAGS)); \
629 switch (GET_OPCODE(op)) { \
630 case SLJIT_NOT: \
631 case SLJIT_CLZ: \
632 case SLJIT_AND: \
633 case SLJIT_OR: \
634 case SLJIT_XOR: \
635 case SLJIT_SHL: \
636 case SLJIT_LSHR: \
637 case SLJIT_ASHR: \
638 CHECK_ARGUMENT(!(op & (SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_O | SLJIT_SET_C))); \
639 break; \
640 case SLJIT_NEG: \
641 CHECK_ARGUMENT(!(op & (SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_C))); \
642 break; \
643 case SLJIT_MUL: \
644 CHECK_ARGUMENT(!(op & (SLJIT_SET_E | SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_C))); \
645 break; \
646 case SLJIT_ADD: \
647 CHECK_ARGUMENT(!(op & (SLJIT_SET_U | SLJIT_SET_S))); \
648 break; \
649 case SLJIT_SUB: \
650 break; \
651 case SLJIT_ADDC: \
652 case SLJIT_SUBC: \
653 CHECK_ARGUMENT(!(op & (SLJIT_SET_E | SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_O))); \
654 break; \
655 case SLJIT_BREAKPOINT: \
656 case SLJIT_NOP: \
657 case SLJIT_LUMUL: \
658 case SLJIT_LSMUL: \
659 case SLJIT_MOV: \
660 case SLJIT_MOV_UI: \
661 case SLJIT_MOV_P: \
662 case SLJIT_MOVU: \
663 case SLJIT_MOVU_UI: \
664 case SLJIT_MOVU_P: \
665 /* Nothing allowed */ \
666 CHECK_ARGUMENT(!(op & (SLJIT_INT_OP | SLJIT_SET_E | SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))); \
667 break; \
668 default: \
669 /* Only SLJIT_INT_OP or SLJIT_SINGLE_OP is allowed. */ \
670 CHECK_ARGUMENT(!(op & (SLJIT_SET_E | SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))); \
671 break; \
672 }
673
674 #define FUNCTION_CHECK_FOP() \
675 CHECK_ARGUMENT(!GET_FLAGS(op) || !(op & SLJIT_KEEP_FLAGS)); \
676 switch (GET_OPCODE(op)) { \
677 case SLJIT_DCMP: \
678 CHECK_ARGUMENT(!(op & (SLJIT_SET_U | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))); \
679 CHECK_ARGUMENT((op & (SLJIT_SET_E | SLJIT_SET_S))); \
680 break; \
681 default: \
682 /* Only SLJIT_INT_OP or SLJIT_SINGLE_OP is allowed. */ \
683 CHECK_ARGUMENT(!(op & (SLJIT_SET_E | SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))); \
684 break; \
685 }
686
687 #define FUNCTION_CHECK_IS_REG(r) \
688 (((r) >= SLJIT_R0 && (r) < (SLJIT_R0 + compiler->scratches)) || \
689 ((r) > (SLJIT_S0 - compiler->saveds) && (r) <= SLJIT_S0))
690
691 #define FUNCTION_CHECK_IS_REG_OR_UNUSED(r) \
692 ((r) == SLJIT_UNUSED || \
693 ((r) >= SLJIT_R0 && (r) < (SLJIT_R0 + compiler->scratches)) || \
694 ((r) > (SLJIT_S0 - compiler->saveds) && (r) <= SLJIT_S0))
695
696 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
697 #define CHECK_NOT_VIRTUAL_REGISTER(p) \
698 CHECK_ARGUMENT((p) < SLJIT_R3 || (p) > SLJIT_R6);
699 #else
700 #define CHECK_NOT_VIRTUAL_REGISTER(p)
701 #endif
702
703 #define FUNCTION_CHECK_SRC(p, i) \
704 CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1); \
705 if (FUNCTION_CHECK_IS_REG(p)) \
706 CHECK_ARGUMENT((i) == 0); \
707 else if ((p) == SLJIT_IMM) \
708 ; \
709 else if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
710 CHECK_ARGUMENT((i) >= 0 && (i) < compiler->logical_local_size); \
711 else { \
712 CHECK_ARGUMENT((p) & SLJIT_MEM); \
713 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG_OR_UNUSED((p) & REG_MASK)); \
714 CHECK_NOT_VIRTUAL_REGISTER((p) & REG_MASK); \
715 if ((p) & OFFS_REG_MASK) { \
716 CHECK_ARGUMENT(((p) & REG_MASK) != SLJIT_UNUSED); \
717 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(OFFS_REG(p))); \
718 CHECK_NOT_VIRTUAL_REGISTER(OFFS_REG(p)); \
719 CHECK_ARGUMENT(!((i) & ~0x3)); \
720 } \
721 CHECK_ARGUMENT(!((p) & ~(SLJIT_MEM | SLJIT_IMM | REG_MASK | OFFS_REG_MASK))); \
722 }
723
724 #define FUNCTION_CHECK_DST(p, i) \
725 CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1); \
726 if (FUNCTION_CHECK_IS_REG_OR_UNUSED(p)) \
727 CHECK_ARGUMENT((i) == 0); \
728 else if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
729 CHECK_ARGUMENT((i) >= 0 && (i) < compiler->logical_local_size); \
730 else { \
731 CHECK_ARGUMENT((p) & SLJIT_MEM); \
732 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG_OR_UNUSED((p) & REG_MASK)); \
733 CHECK_NOT_VIRTUAL_REGISTER((p) & REG_MASK); \
734 if ((p) & OFFS_REG_MASK) { \
735 CHECK_ARGUMENT(((p) & REG_MASK) != SLJIT_UNUSED); \
736 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(OFFS_REG(p))); \
737 CHECK_NOT_VIRTUAL_REGISTER(OFFS_REG(p)); \
738 CHECK_ARGUMENT(!((i) & ~0x3)); \
739 } \
740 CHECK_ARGUMENT(!((p) & ~(SLJIT_MEM | SLJIT_IMM | REG_MASK | OFFS_REG_MASK))); \
741 }
742
743 #define FUNCTION_FCHECK(p, i) \
744 CHECK_ARGUMENT(compiler->fscratches != -1 && compiler->fsaveds != -1); \
745 if (((p) >= SLJIT_FR0 && (p) < (SLJIT_FR0 + compiler->fscratches)) || \
746 ((p) > (SLJIT_FS0 - compiler->fsaveds) && (p) <= SLJIT_FS0)) \
747 CHECK_ARGUMENT(i == 0); \
748 else if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
749 CHECK_ARGUMENT((i) >= 0 && (i) < compiler->logical_local_size); \
750 else { \
751 CHECK_ARGUMENT((p) & SLJIT_MEM); \
752 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG_OR_UNUSED((p) & REG_MASK)); \
753 CHECK_NOT_VIRTUAL_REGISTER((p) & REG_MASK); \
754 if ((p) & OFFS_REG_MASK) { \
755 CHECK_ARGUMENT(((p) & REG_MASK) != SLJIT_UNUSED); \
756 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(OFFS_REG(p))); \
757 CHECK_NOT_VIRTUAL_REGISTER(OFFS_REG(p)); \
758 CHECK_ARGUMENT(((p) & OFFS_REG_MASK) != TO_OFFS_REG(SLJIT_SP) && !(i & ~0x3)); \
759 } \
760 CHECK_ARGUMENT(!((p) & ~(SLJIT_MEM | SLJIT_IMM | REG_MASK | OFFS_REG_MASK))); \
761 }
762
763 #define FUNCTION_CHECK_OP1() \
764 if (GET_OPCODE(op) >= SLJIT_MOVU && GET_OPCODE(op) <= SLJIT_MOVU_P) { \
765 CHECK_ARGUMENT(!(src & SLJIT_MEM) || (src & REG_MASK) != SLJIT_SP); \
766 CHECK_ARGUMENT(!(dst & SLJIT_MEM) || (dst & REG_MASK) != SLJIT_SP); \
767 if ((src & SLJIT_MEM) && (src & REG_MASK)) \
768 CHECK_ARGUMENT((dst & REG_MASK) != (src & REG_MASK) && OFFS_REG(dst) != (src & REG_MASK)); \
769 }
770
771 #endif /* SLJIT_ARGUMENT_CHECKS */
772
773 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
774
sljit_compiler_verbose(struct sljit_compiler * compiler,FILE * verbose)775 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
776 {
777 compiler->verbose = verbose;
778 }
779
780 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
781 #ifdef _WIN64
782 # define SLJIT_PRINT_D "I64"
783 #else
784 # define SLJIT_PRINT_D "l"
785 #endif
786 #else
787 # define SLJIT_PRINT_D ""
788 #endif
789
790 #define sljit_verbose_reg(compiler, r) \
791 do { \
792 if ((r) < (SLJIT_R0 + compiler->scratches)) \
793 fprintf(compiler->verbose, "r%d", (r) - SLJIT_R0); \
794 else \
795 fprintf(compiler->verbose, "s%d", SLJIT_NUMBER_OF_REGISTERS - (r)); \
796 } while (0)
797
798 #define sljit_verbose_param(compiler, p, i) \
799 if ((p) & SLJIT_IMM) \
800 fprintf(compiler->verbose, "#%" SLJIT_PRINT_D "d", (i)); \
801 else if ((p) & SLJIT_MEM) { \
802 if ((p) & REG_MASK) { \
803 fputc('[', compiler->verbose); \
804 sljit_verbose_reg(compiler, (p) & REG_MASK); \
805 if ((p) & OFFS_REG_MASK) { \
806 fprintf(compiler->verbose, " + "); \
807 sljit_verbose_reg(compiler, OFFS_REG(p)); \
808 if (i) \
809 fprintf(compiler->verbose, " * %d", 1 << (i)); \
810 } \
811 else if (i) \
812 fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i)); \
813 fputc(']', compiler->verbose); \
814 } \
815 else \
816 fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i)); \
817 } else if (p) \
818 sljit_verbose_reg(compiler, p); \
819 else \
820 fprintf(compiler->verbose, "unused");
821
822 #define sljit_verbose_fparam(compiler, p, i) \
823 if ((p) & SLJIT_MEM) { \
824 if ((p) & REG_MASK) { \
825 fputc('[', compiler->verbose); \
826 sljit_verbose_reg(compiler, (p) & REG_MASK); \
827 if ((p) & OFFS_REG_MASK) { \
828 fprintf(compiler->verbose, " + "); \
829 sljit_verbose_reg(compiler, OFFS_REG(p)); \
830 if (i) \
831 fprintf(compiler->verbose, "%d", 1 << (i)); \
832 } \
833 else if (i) \
834 fprintf(compiler->verbose, "%" SLJIT_PRINT_D "d", (i)); \
835 fputc(']', compiler->verbose); \
836 } \
837 else \
838 fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i)); \
839 } \
840 else { \
841 if ((p) < (SLJIT_FR0 + compiler->fscratches)) \
842 fprintf(compiler->verbose, "fr%d", (p) - SLJIT_FR0); \
843 else \
844 fprintf(compiler->verbose, "fs%d", SLJIT_NUMBER_OF_FLOAT_REGISTERS - (p)); \
845 }
846
847 static SLJIT_CONST char* op0_names[] = {
848 (char*)"breakpoint", (char*)"nop",
849 (char*)"lumul", (char*)"lsmul", (char*)"ludiv", (char*)"lsdiv",
850 };
851
852 static SLJIT_CONST char* op1_names[] = {
853 (char*)"mov", (char*)"mov_ub", (char*)"mov_sb", (char*)"mov_uh",
854 (char*)"mov_sh", (char*)"mov_ui", (char*)"mov_si", (char*)"mov_p",
855 (char*)"movu", (char*)"movu_ub", (char*)"movu_sb", (char*)"movu_uh",
856 (char*)"movu_sh", (char*)"movu_ui", (char*)"movu_si", (char*)"movu_p",
857 (char*)"not", (char*)"neg", (char*)"clz",
858 };
859
860 static SLJIT_CONST char* op2_names[] = {
861 (char*)"add", (char*)"addc", (char*)"sub", (char*)"subc",
862 (char*)"mul", (char*)"and", (char*)"or", (char*)"xor",
863 (char*)"shl", (char*)"lshr", (char*)"ashr",
864 };
865
866 static SLJIT_CONST char* fop1_names[] = {
867 (char*)"mov", (char*)"conv", (char*)"conv", (char*)"conv",
868 (char*)"conv", (char*)"conv", (char*)"cmp", (char*)"neg",
869 (char*)"abs",
870 };
871
872 static SLJIT_CONST char* fop2_names[] = {
873 (char*)"add", (char*)"sub", (char*)"mul", (char*)"div"
874 };
875
876 #define JUMP_PREFIX(type) \
877 ((type & 0xff) <= SLJIT_MUL_NOT_OVERFLOW ? ((type & SLJIT_INT_OP) ? "i_" : "") \
878 : ((type & 0xff) <= SLJIT_D_ORDERED ? ((type & SLJIT_SINGLE_OP) ? "s_" : "d_") : ""))
879
880 static char* jump_names[] = {
881 (char*)"equal", (char*)"not_equal",
882 (char*)"less", (char*)"greater_equal",
883 (char*)"greater", (char*)"less_equal",
884 (char*)"sig_less", (char*)"sig_greater_equal",
885 (char*)"sig_greater", (char*)"sig_less_equal",
886 (char*)"overflow", (char*)"not_overflow",
887 (char*)"mul_overflow", (char*)"mul_not_overflow",
888 (char*)"equal", (char*)"not_equal",
889 (char*)"less", (char*)"greater_equal",
890 (char*)"greater", (char*)"less_equal",
891 (char*)"unordered", (char*)"ordered",
892 (char*)"jump", (char*)"fast_call",
893 (char*)"call0", (char*)"call1", (char*)"call2", (char*)"call3"
894 };
895
896 #endif /* SLJIT_VERBOSE */
897
898 /* --------------------------------------------------------------------- */
899 /* Arch dependent */
900 /* --------------------------------------------------------------------- */
901
902 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
903 || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
904
check_sljit_generate_code(struct sljit_compiler * compiler)905 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_generate_code(struct sljit_compiler *compiler)
906 {
907 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
908 struct sljit_jump *jump;
909 #endif
910
911 SLJIT_UNUSED_ARG(compiler);
912
913 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
914 CHECK_ARGUMENT(compiler->size > 0);
915 jump = compiler->jumps;
916 while (jump) {
917 /* All jumps have target. */
918 CHECK_ARGUMENT(jump->flags & (JUMP_LABEL | JUMP_ADDR));
919 jump = jump->next;
920 }
921 #endif
922 CHECK_RETURN_OK;
923 }
924
check_sljit_emit_enter(struct sljit_compiler * compiler,sljit_si options,sljit_si args,sljit_si scratches,sljit_si saveds,sljit_si fscratches,sljit_si fsaveds,sljit_si local_size)925 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_enter(struct sljit_compiler *compiler,
926 sljit_si options, sljit_si args, sljit_si scratches, sljit_si saveds,
927 sljit_si fscratches, sljit_si fsaveds, sljit_si local_size)
928 {
929 SLJIT_UNUSED_ARG(compiler);
930
931 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
932 CHECK_ARGUMENT(!(options & ~SLJIT_DOUBLE_ALIGNMENT));
933 CHECK_ARGUMENT(args >= 0 && args <= 3);
934 CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
935 CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_REGISTERS);
936 CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
937 CHECK_ARGUMENT(args <= saveds);
938 CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
939 CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
940 CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
941 CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
942 #endif
943 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
944 if (SLJIT_UNLIKELY(!!compiler->verbose))
945 fprintf(compiler->verbose, " enter options:none args:%d scratches:%d saveds:%d fscratches:%d fsaveds:%d local_size:%d\n",
946 args, scratches, saveds, fscratches, fsaveds, local_size);
947 #endif
948 CHECK_RETURN_OK;
949 }
950
check_sljit_set_context(struct sljit_compiler * compiler,sljit_si options,sljit_si args,sljit_si scratches,sljit_si saveds,sljit_si fscratches,sljit_si fsaveds,sljit_si local_size)951 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_set_context(struct sljit_compiler *compiler,
952 sljit_si options, sljit_si args, sljit_si scratches, sljit_si saveds,
953 sljit_si fscratches, sljit_si fsaveds, sljit_si local_size)
954 {
955 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
956 compiler->skip_checks = 0;
957 CHECK_RETURN_OK;
958 }
959
960 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
961 CHECK_ARGUMENT(!(options & ~SLJIT_DOUBLE_ALIGNMENT));
962 CHECK_ARGUMENT(args >= 0 && args <= 3);
963 CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
964 CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_REGISTERS);
965 CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
966 CHECK_ARGUMENT(args <= saveds);
967 CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
968 CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
969 CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
970 CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
971 #endif
972 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
973 if (SLJIT_UNLIKELY(!!compiler->verbose))
974 fprintf(compiler->verbose, " set_context options:none args:%d scratches:%d saveds:%d fscratches:%d fsaveds:%d local_size:%d\n",
975 args, scratches, saveds, fscratches, fsaveds, local_size);
976 #endif
977 CHECK_RETURN_OK;
978 }
979
check_sljit_emit_return(struct sljit_compiler * compiler,sljit_si op,sljit_si src,sljit_sw srcw)980 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return(struct sljit_compiler *compiler, sljit_si op, sljit_si src, sljit_sw srcw)
981 {
982 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
983 CHECK_ARGUMENT(compiler->scratches >= 0);
984 if (op != SLJIT_UNUSED) {
985 CHECK_ARGUMENT(op >= SLJIT_MOV && op <= SLJIT_MOV_P);
986 FUNCTION_CHECK_SRC(src, srcw);
987 }
988 else
989 CHECK_ARGUMENT(src == 0 && srcw == 0);
990 #endif
991 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
992 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
993 if (op == SLJIT_UNUSED)
994 fprintf(compiler->verbose, " return\n");
995 else {
996 fprintf(compiler->verbose, " return.%s ", op1_names[op - SLJIT_OP1_BASE]);
997 sljit_verbose_param(compiler, src, srcw);
998 fprintf(compiler->verbose, "\n");
999 }
1000 }
1001 #endif
1002 CHECK_RETURN_OK;
1003 }
1004
check_sljit_emit_fast_enter(struct sljit_compiler * compiler,sljit_si dst,sljit_sw dstw)1005 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw)
1006 {
1007 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1008 FUNCTION_CHECK_DST(dst, dstw);
1009 #endif
1010 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1011 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1012 fprintf(compiler->verbose, " fast_enter ");
1013 sljit_verbose_param(compiler, dst, dstw);
1014 fprintf(compiler->verbose, "\n");
1015 }
1016 #endif
1017 CHECK_RETURN_OK;
1018 }
1019
check_sljit_emit_fast_return(struct sljit_compiler * compiler,sljit_si src,sljit_sw srcw)1020 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_si src, sljit_sw srcw)
1021 {
1022 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1023 FUNCTION_CHECK_SRC(src, srcw);
1024 #endif
1025 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1026 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1027 fprintf(compiler->verbose, " fast_return ");
1028 sljit_verbose_param(compiler, src, srcw);
1029 fprintf(compiler->verbose, "\n");
1030 }
1031 #endif
1032 CHECK_RETURN_OK;
1033 }
1034
check_sljit_emit_op0(struct sljit_compiler * compiler,sljit_si op)1035 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op0(struct sljit_compiler *compiler, sljit_si op)
1036 {
1037 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1038 CHECK_ARGUMENT((op >= SLJIT_BREAKPOINT && op <= SLJIT_LSMUL)
1039 || ((op & ~SLJIT_INT_OP) >= SLJIT_LUDIV && (op & ~SLJIT_INT_OP) <= SLJIT_LSDIV));
1040 CHECK_ARGUMENT(op < SLJIT_LUMUL || compiler->scratches >= 2);
1041 #endif
1042 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1043 if (SLJIT_UNLIKELY(!!compiler->verbose))
1044 fprintf(compiler->verbose, " %s%s\n", !(op & SLJIT_INT_OP) ? "" : "i", op0_names[GET_OPCODE(op) - SLJIT_OP0_BASE]);
1045 #endif
1046 CHECK_RETURN_OK;
1047 }
1048
check_sljit_emit_op1(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src,sljit_sw srcw)1049 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op1(struct sljit_compiler *compiler, sljit_si op,
1050 sljit_si dst, sljit_sw dstw,
1051 sljit_si src, sljit_sw srcw)
1052 {
1053 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1054 compiler->skip_checks = 0;
1055 CHECK_RETURN_OK;
1056 }
1057
1058 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1059 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_CLZ);
1060 FUNCTION_CHECK_OP();
1061 FUNCTION_CHECK_SRC(src, srcw);
1062 FUNCTION_CHECK_DST(dst, dstw);
1063 FUNCTION_CHECK_OP1();
1064 #endif
1065 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1066 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1067 fprintf(compiler->verbose, " %s%s%s%s%s%s%s%s ", !(op & SLJIT_INT_OP) ? "" : "i", op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE],
1068 !(op & SLJIT_SET_E) ? "" : ".e", !(op & SLJIT_SET_U) ? "" : ".u", !(op & SLJIT_SET_S) ? "" : ".s",
1069 !(op & SLJIT_SET_O) ? "" : ".o", !(op & SLJIT_SET_C) ? "" : ".c", !(op & SLJIT_KEEP_FLAGS) ? "" : ".k");
1070 sljit_verbose_param(compiler, dst, dstw);
1071 fprintf(compiler->verbose, ", ");
1072 sljit_verbose_param(compiler, src, srcw);
1073 fprintf(compiler->verbose, "\n");
1074 }
1075 #endif
1076 CHECK_RETURN_OK;
1077 }
1078
check_sljit_emit_op2(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1079 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2(struct sljit_compiler *compiler, sljit_si op,
1080 sljit_si dst, sljit_sw dstw,
1081 sljit_si src1, sljit_sw src1w,
1082 sljit_si src2, sljit_sw src2w)
1083 {
1084 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1085 compiler->skip_checks = 0;
1086 CHECK_RETURN_OK;
1087 }
1088
1089 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1090 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD && GET_OPCODE(op) <= SLJIT_ASHR);
1091 FUNCTION_CHECK_OP();
1092 FUNCTION_CHECK_SRC(src1, src1w);
1093 FUNCTION_CHECK_SRC(src2, src2w);
1094 FUNCTION_CHECK_DST(dst, dstw);
1095 #endif
1096 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1097 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1098 fprintf(compiler->verbose, " %s%s%s%s%s%s%s%s ", !(op & SLJIT_INT_OP) ? "" : "i", op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE],
1099 !(op & SLJIT_SET_E) ? "" : ".e", !(op & SLJIT_SET_U) ? "" : ".u", !(op & SLJIT_SET_S) ? "" : ".s",
1100 !(op & SLJIT_SET_O) ? "" : ".o", !(op & SLJIT_SET_C) ? "" : ".c", !(op & SLJIT_KEEP_FLAGS) ? "" : ".k");
1101 sljit_verbose_param(compiler, dst, dstw);
1102 fprintf(compiler->verbose, ", ");
1103 sljit_verbose_param(compiler, src1, src1w);
1104 fprintf(compiler->verbose, ", ");
1105 sljit_verbose_param(compiler, src2, src2w);
1106 fprintf(compiler->verbose, "\n");
1107 }
1108 #endif
1109 CHECK_RETURN_OK;
1110 }
1111
check_sljit_get_register_index(sljit_si reg)1112 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_register_index(sljit_si reg)
1113 {
1114 SLJIT_UNUSED_ARG(reg);
1115 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1116 CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_REGISTERS);
1117 #endif
1118 CHECK_RETURN_OK;
1119 }
1120
check_sljit_get_float_register_index(sljit_si reg)1121 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_float_register_index(sljit_si reg)
1122 {
1123 SLJIT_UNUSED_ARG(reg);
1124 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1125 CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1126 #endif
1127 CHECK_RETURN_OK;
1128 }
1129
check_sljit_emit_op_custom(struct sljit_compiler * compiler,void * instruction,sljit_si size)1130 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_custom(struct sljit_compiler *compiler,
1131 void *instruction, sljit_si size)
1132 {
1133 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1134 int i;
1135 #endif
1136
1137 SLJIT_UNUSED_ARG(compiler);
1138
1139 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1140 CHECK_ARGUMENT(instruction);
1141 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
1142 CHECK_ARGUMENT(size > 0 && size < 16);
1143 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
1144 CHECK_ARGUMENT((size == 2 && (((sljit_sw)instruction) & 0x1) == 0)
1145 || (size == 4 && (((sljit_sw)instruction) & 0x3) == 0));
1146 #else
1147 CHECK_ARGUMENT(size == 4 && (((sljit_sw)instruction) & 0x3) == 0);
1148 #endif
1149
1150 #endif
1151 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1152 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1153 fprintf(compiler->verbose, " op_custom");
1154 for (i = 0; i < size; i++)
1155 fprintf(compiler->verbose, " 0x%x", ((sljit_ub*)instruction)[i]);
1156 fprintf(compiler->verbose, "\n");
1157 }
1158 #endif
1159 CHECK_RETURN_OK;
1160 }
1161
check_sljit_emit_fop1(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src,sljit_sw srcw)1162 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1(struct sljit_compiler *compiler, sljit_si op,
1163 sljit_si dst, sljit_sw dstw,
1164 sljit_si src, sljit_sw srcw)
1165 {
1166 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1167 compiler->skip_checks = 0;
1168 CHECK_RETURN_OK;
1169 }
1170
1171 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1172 CHECK_ARGUMENT(sljit_is_fpu_available());
1173 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_DMOV && GET_OPCODE(op) <= SLJIT_DABS);
1174 FUNCTION_CHECK_FOP();
1175 FUNCTION_FCHECK(src, srcw);
1176 FUNCTION_FCHECK(dst, dstw);
1177 #endif
1178 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1179 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1180 if (GET_OPCODE(op) == SLJIT_CONVD_FROMS)
1181 fprintf(compiler->verbose, " %s%s ", fop1_names[SLJIT_CONVD_FROMS - SLJIT_FOP1_BASE],
1182 (op & SLJIT_SINGLE_OP) ? "s.fromd" : "d.froms");
1183 else
1184 fprintf(compiler->verbose, " %s%s ", (op & SLJIT_SINGLE_OP) ? "s" : "d",
1185 fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE]);
1186
1187 sljit_verbose_fparam(compiler, dst, dstw);
1188 fprintf(compiler->verbose, ", ");
1189 sljit_verbose_fparam(compiler, src, srcw);
1190 fprintf(compiler->verbose, "\n");
1191 }
1192 #endif
1193 CHECK_RETURN_OK;
1194 }
1195
check_sljit_emit_fop1_cmp(struct sljit_compiler * compiler,sljit_si op,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1196 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_cmp(struct sljit_compiler *compiler, sljit_si op,
1197 sljit_si src1, sljit_sw src1w,
1198 sljit_si src2, sljit_sw src2w)
1199 {
1200 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1201 compiler->skip_checks = 0;
1202 CHECK_RETURN_OK;
1203 }
1204
1205 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1206 CHECK_ARGUMENT(sljit_is_fpu_available());
1207 CHECK_ARGUMENT(GET_OPCODE(op) == SLJIT_DCMP);
1208 FUNCTION_CHECK_FOP();
1209 FUNCTION_FCHECK(src1, src1w);
1210 FUNCTION_FCHECK(src2, src2w);
1211 #endif
1212 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1213 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1214 fprintf(compiler->verbose, " %s%s%s%s ", (op & SLJIT_SINGLE_OP) ? "s" : "d", fop1_names[SLJIT_DCMP - SLJIT_FOP1_BASE],
1215 (op & SLJIT_SET_E) ? ".e" : "", (op & SLJIT_SET_S) ? ".s" : "");
1216 sljit_verbose_fparam(compiler, src1, src1w);
1217 fprintf(compiler->verbose, ", ");
1218 sljit_verbose_fparam(compiler, src2, src2w);
1219 fprintf(compiler->verbose, "\n");
1220 }
1221 #endif
1222 CHECK_RETURN_OK;
1223 }
1224
check_sljit_emit_fop1_convw_fromd(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src,sljit_sw srcw)1225 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_convw_fromd(struct sljit_compiler *compiler, sljit_si op,
1226 sljit_si dst, sljit_sw dstw,
1227 sljit_si src, sljit_sw srcw)
1228 {
1229 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1230 compiler->skip_checks = 0;
1231 CHECK_RETURN_OK;
1232 }
1233
1234 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1235 CHECK_ARGUMENT(sljit_is_fpu_available());
1236 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONVW_FROMD && GET_OPCODE(op) <= SLJIT_CONVI_FROMD);
1237 FUNCTION_CHECK_FOP();
1238 FUNCTION_FCHECK(src, srcw);
1239 FUNCTION_CHECK_DST(dst, dstw);
1240 #endif
1241 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1242 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1243 fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1244 (GET_OPCODE(op) == SLJIT_CONVI_FROMD) ? "i" : "w",
1245 (op & SLJIT_SINGLE_OP) ? "s" : "d");
1246 sljit_verbose_param(compiler, dst, dstw);
1247 fprintf(compiler->verbose, ", ");
1248 sljit_verbose_fparam(compiler, src, srcw);
1249 fprintf(compiler->verbose, "\n");
1250 }
1251 #endif
1252 CHECK_RETURN_OK;
1253 }
1254
check_sljit_emit_fop1_convd_fromw(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src,sljit_sw srcw)1255 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_convd_fromw(struct sljit_compiler *compiler, sljit_si op,
1256 sljit_si dst, sljit_sw dstw,
1257 sljit_si src, sljit_sw srcw)
1258 {
1259 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1260 compiler->skip_checks = 0;
1261 CHECK_RETURN_OK;
1262 }
1263
1264 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1265 CHECK_ARGUMENT(sljit_is_fpu_available());
1266 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONVD_FROMW && GET_OPCODE(op) <= SLJIT_CONVD_FROMI);
1267 FUNCTION_CHECK_FOP();
1268 FUNCTION_CHECK_SRC(src, srcw);
1269 FUNCTION_FCHECK(dst, dstw);
1270 #endif
1271 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1272 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1273 fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1274 (op & SLJIT_SINGLE_OP) ? "s" : "d",
1275 (GET_OPCODE(op) == SLJIT_CONVD_FROMI) ? "i" : "w");
1276 sljit_verbose_fparam(compiler, dst, dstw);
1277 fprintf(compiler->verbose, ", ");
1278 sljit_verbose_param(compiler, src, srcw);
1279 fprintf(compiler->verbose, "\n");
1280 }
1281 #endif
1282 CHECK_RETURN_OK;
1283 }
1284
check_sljit_emit_fop2(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1285 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop2(struct sljit_compiler *compiler, sljit_si op,
1286 sljit_si dst, sljit_sw dstw,
1287 sljit_si src1, sljit_sw src1w,
1288 sljit_si src2, sljit_sw src2w)
1289 {
1290 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1291 CHECK_ARGUMENT(sljit_is_fpu_available());
1292 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_DADD && GET_OPCODE(op) <= SLJIT_DDIV);
1293 FUNCTION_CHECK_FOP();
1294 FUNCTION_FCHECK(src1, src1w);
1295 FUNCTION_FCHECK(src2, src2w);
1296 FUNCTION_FCHECK(dst, dstw);
1297 #endif
1298 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1299 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1300 fprintf(compiler->verbose, " %s%s ", (op & SLJIT_SINGLE_OP) ? "s" : "d", fop2_names[GET_OPCODE(op) - SLJIT_FOP2_BASE]);
1301 sljit_verbose_fparam(compiler, dst, dstw);
1302 fprintf(compiler->verbose, ", ");
1303 sljit_verbose_fparam(compiler, src1, src1w);
1304 fprintf(compiler->verbose, ", ");
1305 sljit_verbose_fparam(compiler, src2, src2w);
1306 fprintf(compiler->verbose, "\n");
1307 }
1308 #endif
1309 CHECK_RETURN_OK;
1310 }
1311
check_sljit_emit_label(struct sljit_compiler * compiler)1312 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_label(struct sljit_compiler *compiler)
1313 {
1314 SLJIT_UNUSED_ARG(compiler);
1315
1316 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1317 if (SLJIT_UNLIKELY(!!compiler->verbose))
1318 fprintf(compiler->verbose, "label:\n");
1319 #endif
1320 CHECK_RETURN_OK;
1321 }
1322
check_sljit_emit_jump(struct sljit_compiler * compiler,sljit_si type)1323 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_jump(struct sljit_compiler *compiler, sljit_si type)
1324 {
1325 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1326 compiler->skip_checks = 0;
1327 CHECK_RETURN_OK;
1328 }
1329
1330 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1331 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_INT_OP)));
1332 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_CALL3);
1333 CHECK_ARGUMENT((type & 0xff) < SLJIT_JUMP || !(type & SLJIT_INT_OP));
1334 CHECK_ARGUMENT((type & 0xff) <= SLJIT_CALL0 || ((type & 0xff) - SLJIT_CALL0) <= compiler->scratches);
1335 #endif
1336 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1337 if (SLJIT_UNLIKELY(!!compiler->verbose))
1338 fprintf(compiler->verbose, " jump%s.%s%s\n", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1339 JUMP_PREFIX(type), jump_names[type & 0xff]);
1340 #endif
1341 CHECK_RETURN_OK;
1342 }
1343
check_sljit_emit_cmp(struct sljit_compiler * compiler,sljit_si type,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1344 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmp(struct sljit_compiler *compiler, sljit_si type,
1345 sljit_si src1, sljit_sw src1w,
1346 sljit_si src2, sljit_sw src2w)
1347 {
1348 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1349 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_INT_OP)));
1350 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_SIG_LESS_EQUAL);
1351 FUNCTION_CHECK_SRC(src1, src1w);
1352 FUNCTION_CHECK_SRC(src2, src2w);
1353 #endif
1354 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1355 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1356 fprintf(compiler->verbose, " cmp%s.%s%s ", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1357 (type & SLJIT_INT_OP) ? "i_" : "", jump_names[type & 0xff]);
1358 sljit_verbose_param(compiler, src1, src1w);
1359 fprintf(compiler->verbose, ", ");
1360 sljit_verbose_param(compiler, src2, src2w);
1361 fprintf(compiler->verbose, "\n");
1362 }
1363 #endif
1364 CHECK_RETURN_OK;
1365 }
1366
check_sljit_emit_fcmp(struct sljit_compiler * compiler,sljit_si type,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1367 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_si type,
1368 sljit_si src1, sljit_sw src1w,
1369 sljit_si src2, sljit_sw src2w)
1370 {
1371 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1372 CHECK_ARGUMENT(sljit_is_fpu_available());
1373 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_SINGLE_OP)));
1374 CHECK_ARGUMENT((type & 0xff) >= SLJIT_D_EQUAL && (type & 0xff) <= SLJIT_D_ORDERED);
1375 FUNCTION_FCHECK(src1, src1w);
1376 FUNCTION_FCHECK(src2, src2w);
1377 #endif
1378 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1379 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1380 fprintf(compiler->verbose, " fcmp%s.%s%s ", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1381 (type & SLJIT_SINGLE_OP) ? "s_" : "d_", jump_names[type & 0xff]);
1382 sljit_verbose_fparam(compiler, src1, src1w);
1383 fprintf(compiler->verbose, ", ");
1384 sljit_verbose_fparam(compiler, src2, src2w);
1385 fprintf(compiler->verbose, "\n");
1386 }
1387 #endif
1388 CHECK_RETURN_OK;
1389 }
1390
check_sljit_emit_ijump(struct sljit_compiler * compiler,sljit_si type,sljit_si src,sljit_sw srcw)1391 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_ijump(struct sljit_compiler *compiler, sljit_si type, sljit_si src, sljit_sw srcw)
1392 {
1393 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1394 compiler->skip_checks = 0;
1395 CHECK_RETURN_OK;
1396 }
1397
1398 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1399 CHECK_ARGUMENT(type >= SLJIT_JUMP && type <= SLJIT_CALL3);
1400 CHECK_ARGUMENT(type <= SLJIT_CALL0 || (type - SLJIT_CALL0) <= compiler->scratches);
1401 FUNCTION_CHECK_SRC(src, srcw);
1402 #endif
1403 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1404 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1405 fprintf(compiler->verbose, " ijump.%s ", jump_names[type]);
1406 sljit_verbose_param(compiler, src, srcw);
1407 fprintf(compiler->verbose, "\n");
1408 }
1409 #endif
1410 CHECK_RETURN_OK;
1411 }
1412
check_sljit_emit_op_flags(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src,sljit_sw srcw,sljit_si type)1413 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_si op,
1414 sljit_si dst, sljit_sw dstw,
1415 sljit_si src, sljit_sw srcw,
1416 sljit_si type)
1417 {
1418 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1419 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_INT_OP)));
1420 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_D_ORDERED);
1421 CHECK_ARGUMENT(op == SLJIT_MOV || GET_OPCODE(op) == SLJIT_MOV_UI || GET_OPCODE(op) == SLJIT_MOV_SI
1422 || (GET_OPCODE(op) >= SLJIT_AND && GET_OPCODE(op) <= SLJIT_XOR));
1423 CHECK_ARGUMENT((op & (SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_O | SLJIT_SET_C)) == 0);
1424 CHECK_ARGUMENT((op & (SLJIT_SET_E | SLJIT_KEEP_FLAGS)) != (SLJIT_SET_E | SLJIT_KEEP_FLAGS));
1425 if (GET_OPCODE(op) < SLJIT_ADD) {
1426 CHECK_ARGUMENT(src == SLJIT_UNUSED && srcw == 0);
1427 } else {
1428 CHECK_ARGUMENT(src == dst && srcw == dstw);
1429 }
1430 FUNCTION_CHECK_DST(dst, dstw);
1431 #endif
1432 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1433 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1434 fprintf(compiler->verbose, " flags.%s%s%s%s ", !(op & SLJIT_INT_OP) ? "" : "i",
1435 GET_OPCODE(op) >= SLJIT_OP2_BASE ? op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE] : op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE],
1436 !(op & SLJIT_SET_E) ? "" : ".e", !(op & SLJIT_KEEP_FLAGS) ? "" : ".k");
1437 sljit_verbose_param(compiler, dst, dstw);
1438 if (src != SLJIT_UNUSED) {
1439 fprintf(compiler->verbose, ", ");
1440 sljit_verbose_param(compiler, src, srcw);
1441 }
1442 fprintf(compiler->verbose, ", %s%s\n", JUMP_PREFIX(type), jump_names[type & 0xff]);
1443 }
1444 #endif
1445 CHECK_RETURN_OK;
1446 }
1447
check_sljit_get_local_base(struct sljit_compiler * compiler,sljit_si dst,sljit_sw dstw,sljit_sw offset)1448 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_local_base(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw offset)
1449 {
1450 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1451 FUNCTION_CHECK_DST(dst, dstw);
1452 #endif
1453 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1454 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1455 fprintf(compiler->verbose, " local_base ");
1456 sljit_verbose_param(compiler, dst, dstw);
1457 fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", offset);
1458 }
1459 #endif
1460 CHECK_RETURN_OK;
1461 }
1462
check_sljit_emit_const(struct sljit_compiler * compiler,sljit_si dst,sljit_sw dstw,sljit_sw init_value)1463 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_const(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw init_value)
1464 {
1465 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1466 FUNCTION_CHECK_DST(dst, dstw);
1467 #endif
1468 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1469 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1470 fprintf(compiler->verbose, " const ");
1471 sljit_verbose_param(compiler, dst, dstw);
1472 fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", init_value);
1473 }
1474 #endif
1475 CHECK_RETURN_OK;
1476 }
1477
1478 #endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_VERBOSE */
1479
1480 #define SELECT_FOP1_OPERATION_WITH_CHECKS(compiler, op, dst, dstw, src, srcw) \
1481 SLJIT_COMPILE_ASSERT(!(SLJIT_CONVW_FROMD & 0x1) && !(SLJIT_CONVD_FROMW & 0x1), \
1482 invalid_float_opcodes); \
1483 if (GET_OPCODE(op) >= SLJIT_CONVW_FROMD && GET_OPCODE(op) <= SLJIT_DCMP) { \
1484 if (GET_OPCODE(op) == SLJIT_DCMP) { \
1485 CHECK(check_sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw)); \
1486 ADJUST_LOCAL_OFFSET(dst, dstw); \
1487 ADJUST_LOCAL_OFFSET(src, srcw); \
1488 return sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw); \
1489 } \
1490 if ((GET_OPCODE(op) | 0x1) == SLJIT_CONVI_FROMD) { \
1491 CHECK(check_sljit_emit_fop1_convw_fromd(compiler, op, dst, dstw, src, srcw)); \
1492 ADJUST_LOCAL_OFFSET(dst, dstw); \
1493 ADJUST_LOCAL_OFFSET(src, srcw); \
1494 return sljit_emit_fop1_convw_fromd(compiler, op, dst, dstw, src, srcw); \
1495 } \
1496 CHECK(check_sljit_emit_fop1_convd_fromw(compiler, op, dst, dstw, src, srcw)); \
1497 ADJUST_LOCAL_OFFSET(dst, dstw); \
1498 ADJUST_LOCAL_OFFSET(src, srcw); \
1499 return sljit_emit_fop1_convd_fromw(compiler, op, dst, dstw, src, srcw); \
1500 } \
1501 CHECK(check_sljit_emit_fop1(compiler, op, dst, dstw, src, srcw)); \
1502 ADJUST_LOCAL_OFFSET(dst, dstw); \
1503 ADJUST_LOCAL_OFFSET(src, srcw);
1504
emit_mov_before_return(struct sljit_compiler * compiler,sljit_si op,sljit_si src,sljit_sw srcw)1505 static SLJIT_INLINE sljit_si emit_mov_before_return(struct sljit_compiler *compiler, sljit_si op, sljit_si src, sljit_sw srcw)
1506 {
1507 /* Return if don't need to do anything. */
1508 if (op == SLJIT_UNUSED)
1509 return SLJIT_SUCCESS;
1510
1511 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1512 /* At the moment the pointer size is always equal to sljit_sw. May be changed in the future. */
1513 if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_P))
1514 return SLJIT_SUCCESS;
1515 #else
1516 if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_UI || op == SLJIT_MOV_SI || op == SLJIT_MOV_P))
1517 return SLJIT_SUCCESS;
1518 #endif
1519
1520 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
1521 || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1522 compiler->skip_checks = 1;
1523 #endif
1524 return sljit_emit_op1(compiler, op, SLJIT_RETURN_REG, 0, src, srcw);
1525 }
1526
1527 /* CPU description section */
1528
1529 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
1530 #define SLJIT_CPUINFO_PART1 " 32bit ("
1531 #elif (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1532 #define SLJIT_CPUINFO_PART1 " 64bit ("
1533 #else
1534 #error "Internal error: CPU type info missing"
1535 #endif
1536
1537 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1538 #define SLJIT_CPUINFO_PART2 "little endian + "
1539 #elif (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
1540 #define SLJIT_CPUINFO_PART2 "big endian + "
1541 #else
1542 #error "Internal error: CPU type info missing"
1543 #endif
1544
1545 #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED)
1546 #define SLJIT_CPUINFO_PART3 "unaligned)"
1547 #else
1548 #define SLJIT_CPUINFO_PART3 "aligned)"
1549 #endif
1550
1551 #define SLJIT_CPUINFO SLJIT_CPUINFO_PART1 SLJIT_CPUINFO_PART2 SLJIT_CPUINFO_PART3
1552
1553 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
1554 # include "sljitNativeX86_common.c"
1555 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
1556 # include "sljitNativeARM_32.c"
1557 #elif (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
1558 # include "sljitNativeARM_32.c"
1559 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
1560 # include "sljitNativeARM_T2_32.c"
1561 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
1562 # include "sljitNativeARM_64.c"
1563 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
1564 # include "sljitNativePPC_common.c"
1565 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
1566 # include "sljitNativeMIPS_common.c"
1567 #elif (defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
1568 # include "sljitNativeSPARC_common.c"
1569 #elif (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
1570 # include "sljitNativeTILEGX_64.c"
1571 #endif
1572
1573 #if !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
1574
sljit_emit_cmp(struct sljit_compiler * compiler,sljit_si type,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1575 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_si type,
1576 sljit_si src1, sljit_sw src1w,
1577 sljit_si src2, sljit_sw src2w)
1578 {
1579 /* Default compare for most architectures. */
1580 sljit_si flags, tmp_src, condition;
1581 sljit_sw tmp_srcw;
1582
1583 CHECK_ERROR_PTR();
1584 CHECK_PTR(check_sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w));
1585
1586 condition = type & 0xff;
1587 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
1588 if ((condition == SLJIT_EQUAL || condition == SLJIT_NOT_EQUAL)) {
1589 if ((src1 & SLJIT_IMM) && !src1w) {
1590 src1 = src2;
1591 src1w = src2w;
1592 src2 = SLJIT_IMM;
1593 src2w = 0;
1594 }
1595 if ((src2 & SLJIT_IMM) && !src2w)
1596 return emit_cmp_to0(compiler, type, src1, src1w);
1597 }
1598 #endif
1599
1600 if (SLJIT_UNLIKELY((src1 & SLJIT_IMM) && !(src2 & SLJIT_IMM))) {
1601 /* Immediate is prefered as second argument by most architectures. */
1602 switch (condition) {
1603 case SLJIT_LESS:
1604 condition = SLJIT_GREATER;
1605 break;
1606 case SLJIT_GREATER_EQUAL:
1607 condition = SLJIT_LESS_EQUAL;
1608 break;
1609 case SLJIT_GREATER:
1610 condition = SLJIT_LESS;
1611 break;
1612 case SLJIT_LESS_EQUAL:
1613 condition = SLJIT_GREATER_EQUAL;
1614 break;
1615 case SLJIT_SIG_LESS:
1616 condition = SLJIT_SIG_GREATER;
1617 break;
1618 case SLJIT_SIG_GREATER_EQUAL:
1619 condition = SLJIT_SIG_LESS_EQUAL;
1620 break;
1621 case SLJIT_SIG_GREATER:
1622 condition = SLJIT_SIG_LESS;
1623 break;
1624 case SLJIT_SIG_LESS_EQUAL:
1625 condition = SLJIT_SIG_GREATER_EQUAL;
1626 break;
1627 }
1628 type = condition | (type & (SLJIT_INT_OP | SLJIT_REWRITABLE_JUMP));
1629 tmp_src = src1;
1630 src1 = src2;
1631 src2 = tmp_src;
1632 tmp_srcw = src1w;
1633 src1w = src2w;
1634 src2w = tmp_srcw;
1635 }
1636
1637 if (condition <= SLJIT_NOT_ZERO)
1638 flags = SLJIT_SET_E;
1639 else if (condition <= SLJIT_LESS_EQUAL)
1640 flags = SLJIT_SET_U;
1641 else
1642 flags = SLJIT_SET_S;
1643
1644 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1645 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1646 compiler->skip_checks = 1;
1647 #endif
1648 PTR_FAIL_IF(sljit_emit_op2(compiler, SLJIT_SUB | flags | (type & SLJIT_INT_OP),
1649 SLJIT_UNUSED, 0, src1, src1w, src2, src2w));
1650 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1651 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1652 compiler->skip_checks = 1;
1653 #endif
1654 return sljit_emit_jump(compiler, condition | (type & SLJIT_REWRITABLE_JUMP));
1655 }
1656
sljit_emit_fcmp(struct sljit_compiler * compiler,sljit_si type,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1657 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_si type,
1658 sljit_si src1, sljit_sw src1w,
1659 sljit_si src2, sljit_sw src2w)
1660 {
1661 sljit_si flags, condition;
1662
1663 CHECK_ERROR_PTR();
1664 CHECK_PTR(check_sljit_emit_fcmp(compiler, type, src1, src1w, src2, src2w));
1665
1666 condition = type & 0xff;
1667 flags = (condition <= SLJIT_D_NOT_EQUAL) ? SLJIT_SET_E : SLJIT_SET_S;
1668 if (type & SLJIT_SINGLE_OP)
1669 flags |= SLJIT_SINGLE_OP;
1670
1671 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1672 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1673 compiler->skip_checks = 1;
1674 #endif
1675 sljit_emit_fop1(compiler, SLJIT_DCMP | flags, src1, src1w, src2, src2w);
1676
1677 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1678 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1679 compiler->skip_checks = 1;
1680 #endif
1681 return sljit_emit_jump(compiler, condition | (type & SLJIT_REWRITABLE_JUMP));
1682 }
1683
1684 #endif
1685
1686 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
1687
sljit_get_local_base(struct sljit_compiler * compiler,sljit_si dst,sljit_sw dstw,sljit_sw offset)1688 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_get_local_base(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw offset)
1689 {
1690 CHECK_ERROR();
1691 CHECK(check_sljit_get_local_base(compiler, dst, dstw, offset));
1692
1693 ADJUST_LOCAL_OFFSET(SLJIT_MEM1(SLJIT_SP), offset);
1694 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1695 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1696 compiler->skip_checks = 1;
1697 #endif
1698 if (offset != 0)
1699 return sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_KEEP_FLAGS, dst, dstw, SLJIT_SP, 0, SLJIT_IMM, offset);
1700 return sljit_emit_op1(compiler, SLJIT_MOV, dst, dstw, SLJIT_SP, 0);
1701 }
1702
1703 #endif
1704
1705 #else /* SLJIT_CONFIG_UNSUPPORTED */
1706
1707 /* Empty function bodies for those machines, which are not (yet) supported. */
1708
sljit_get_platform_name(void)1709 SLJIT_API_FUNC_ATTRIBUTE SLJIT_CONST char* sljit_get_platform_name(void)
1710 {
1711 return "unsupported";
1712 }
1713
sljit_create_compiler(void)1714 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void)
1715 {
1716 SLJIT_ASSERT_STOP();
1717 return NULL;
1718 }
1719
sljit_free_compiler(struct sljit_compiler * compiler)1720 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
1721 {
1722 SLJIT_UNUSED_ARG(compiler);
1723 SLJIT_ASSERT_STOP();
1724 }
1725
sljit_alloc_memory(struct sljit_compiler * compiler,sljit_si size)1726 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_si size)
1727 {
1728 SLJIT_UNUSED_ARG(compiler);
1729 SLJIT_UNUSED_ARG(size);
1730 SLJIT_ASSERT_STOP();
1731 return NULL;
1732 }
1733
1734 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
sljit_compiler_verbose(struct sljit_compiler * compiler,FILE * verbose)1735 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
1736 {
1737 SLJIT_UNUSED_ARG(compiler);
1738 SLJIT_UNUSED_ARG(verbose);
1739 SLJIT_ASSERT_STOP();
1740 }
1741 #endif
1742
sljit_generate_code(struct sljit_compiler * compiler)1743 SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler)
1744 {
1745 SLJIT_UNUSED_ARG(compiler);
1746 SLJIT_ASSERT_STOP();
1747 return NULL;
1748 }
1749
sljit_free_code(void * code)1750 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
1751 {
1752 SLJIT_UNUSED_ARG(code);
1753 SLJIT_ASSERT_STOP();
1754 }
1755
sljit_emit_enter(struct sljit_compiler * compiler,sljit_si options,sljit_si args,sljit_si scratches,sljit_si saveds,sljit_si fscratches,sljit_si fsaveds,sljit_si local_size)1756 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_enter(struct sljit_compiler *compiler,
1757 sljit_si options, sljit_si args, sljit_si scratches, sljit_si saveds,
1758 sljit_si fscratches, sljit_si fsaveds, sljit_si local_size)
1759 {
1760 SLJIT_UNUSED_ARG(compiler);
1761 SLJIT_UNUSED_ARG(options);
1762 SLJIT_UNUSED_ARG(args);
1763 SLJIT_UNUSED_ARG(scratches);
1764 SLJIT_UNUSED_ARG(saveds);
1765 SLJIT_UNUSED_ARG(fscratches);
1766 SLJIT_UNUSED_ARG(fsaveds);
1767 SLJIT_UNUSED_ARG(local_size);
1768 SLJIT_ASSERT_STOP();
1769 return SLJIT_ERR_UNSUPPORTED;
1770 }
1771
sljit_set_context(struct sljit_compiler * compiler,sljit_si options,sljit_si args,sljit_si scratches,sljit_si saveds,sljit_si fscratches,sljit_si fsaveds,sljit_si local_size)1772 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_set_context(struct sljit_compiler *compiler,
1773 sljit_si options, sljit_si args, sljit_si scratches, sljit_si saveds,
1774 sljit_si fscratches, sljit_si fsaveds, sljit_si local_size)
1775 {
1776 SLJIT_UNUSED_ARG(compiler);
1777 SLJIT_UNUSED_ARG(options);
1778 SLJIT_UNUSED_ARG(args);
1779 SLJIT_UNUSED_ARG(scratches);
1780 SLJIT_UNUSED_ARG(saveds);
1781 SLJIT_UNUSED_ARG(fscratches);
1782 SLJIT_UNUSED_ARG(fsaveds);
1783 SLJIT_UNUSED_ARG(local_size);
1784 SLJIT_ASSERT_STOP();
1785 return SLJIT_ERR_UNSUPPORTED;
1786 }
1787
sljit_emit_return(struct sljit_compiler * compiler,sljit_si op,sljit_si src,sljit_sw srcw)1788 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_return(struct sljit_compiler *compiler, sljit_si op, sljit_si src, sljit_sw srcw)
1789 {
1790 SLJIT_UNUSED_ARG(compiler);
1791 SLJIT_UNUSED_ARG(op);
1792 SLJIT_UNUSED_ARG(src);
1793 SLJIT_UNUSED_ARG(srcw);
1794 SLJIT_ASSERT_STOP();
1795 return SLJIT_ERR_UNSUPPORTED;
1796 }
1797
sljit_emit_fast_enter(struct sljit_compiler * compiler,sljit_si dst,sljit_sw dstw)1798 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw)
1799 {
1800 SLJIT_UNUSED_ARG(compiler);
1801 SLJIT_UNUSED_ARG(dst);
1802 SLJIT_UNUSED_ARG(dstw);
1803 SLJIT_ASSERT_STOP();
1804 return SLJIT_ERR_UNSUPPORTED;
1805 }
1806
sljit_emit_fast_return(struct sljit_compiler * compiler,sljit_si src,sljit_sw srcw)1807 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_si src, sljit_sw srcw)
1808 {
1809 SLJIT_UNUSED_ARG(compiler);
1810 SLJIT_UNUSED_ARG(src);
1811 SLJIT_UNUSED_ARG(srcw);
1812 SLJIT_ASSERT_STOP();
1813 return SLJIT_ERR_UNSUPPORTED;
1814 }
1815
sljit_emit_op0(struct sljit_compiler * compiler,sljit_si op)1816 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op0(struct sljit_compiler *compiler, sljit_si op)
1817 {
1818 SLJIT_UNUSED_ARG(compiler);
1819 SLJIT_UNUSED_ARG(op);
1820 SLJIT_ASSERT_STOP();
1821 return SLJIT_ERR_UNSUPPORTED;
1822 }
1823
sljit_emit_op1(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src,sljit_sw srcw)1824 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op1(struct sljit_compiler *compiler, sljit_si op,
1825 sljit_si dst, sljit_sw dstw,
1826 sljit_si src, sljit_sw srcw)
1827 {
1828 SLJIT_UNUSED_ARG(compiler);
1829 SLJIT_UNUSED_ARG(op);
1830 SLJIT_UNUSED_ARG(dst);
1831 SLJIT_UNUSED_ARG(dstw);
1832 SLJIT_UNUSED_ARG(src);
1833 SLJIT_UNUSED_ARG(srcw);
1834 SLJIT_ASSERT_STOP();
1835 return SLJIT_ERR_UNSUPPORTED;
1836 }
1837
sljit_emit_op2(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1838 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op2(struct sljit_compiler *compiler, sljit_si op,
1839 sljit_si dst, sljit_sw dstw,
1840 sljit_si src1, sljit_sw src1w,
1841 sljit_si src2, sljit_sw src2w)
1842 {
1843 SLJIT_UNUSED_ARG(compiler);
1844 SLJIT_UNUSED_ARG(op);
1845 SLJIT_UNUSED_ARG(dst);
1846 SLJIT_UNUSED_ARG(dstw);
1847 SLJIT_UNUSED_ARG(src1);
1848 SLJIT_UNUSED_ARG(src1w);
1849 SLJIT_UNUSED_ARG(src2);
1850 SLJIT_UNUSED_ARG(src2w);
1851 SLJIT_ASSERT_STOP();
1852 return SLJIT_ERR_UNSUPPORTED;
1853 }
1854
sljit_get_register_index(sljit_si reg)1855 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_get_register_index(sljit_si reg)
1856 {
1857 SLJIT_ASSERT_STOP();
1858 return reg;
1859 }
1860
sljit_emit_op_custom(struct sljit_compiler * compiler,void * instruction,sljit_si size)1861 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op_custom(struct sljit_compiler *compiler,
1862 void *instruction, sljit_si size)
1863 {
1864 SLJIT_UNUSED_ARG(compiler);
1865 SLJIT_UNUSED_ARG(instruction);
1866 SLJIT_UNUSED_ARG(size);
1867 SLJIT_ASSERT_STOP();
1868 return SLJIT_ERR_UNSUPPORTED;
1869 }
1870
sljit_is_fpu_available(void)1871 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_is_fpu_available(void)
1872 {
1873 SLJIT_ASSERT_STOP();
1874 return 0;
1875 }
1876
sljit_emit_fop1(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src,sljit_sw srcw)1877 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fop1(struct sljit_compiler *compiler, sljit_si op,
1878 sljit_si dst, sljit_sw dstw,
1879 sljit_si src, sljit_sw srcw)
1880 {
1881 SLJIT_UNUSED_ARG(compiler);
1882 SLJIT_UNUSED_ARG(op);
1883 SLJIT_UNUSED_ARG(dst);
1884 SLJIT_UNUSED_ARG(dstw);
1885 SLJIT_UNUSED_ARG(src);
1886 SLJIT_UNUSED_ARG(srcw);
1887 SLJIT_ASSERT_STOP();
1888 return SLJIT_ERR_UNSUPPORTED;
1889 }
1890
sljit_emit_fop2(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1891 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fop2(struct sljit_compiler *compiler, sljit_si op,
1892 sljit_si dst, sljit_sw dstw,
1893 sljit_si src1, sljit_sw src1w,
1894 sljit_si src2, sljit_sw src2w)
1895 {
1896 SLJIT_UNUSED_ARG(compiler);
1897 SLJIT_UNUSED_ARG(op);
1898 SLJIT_UNUSED_ARG(dst);
1899 SLJIT_UNUSED_ARG(dstw);
1900 SLJIT_UNUSED_ARG(src1);
1901 SLJIT_UNUSED_ARG(src1w);
1902 SLJIT_UNUSED_ARG(src2);
1903 SLJIT_UNUSED_ARG(src2w);
1904 SLJIT_ASSERT_STOP();
1905 return SLJIT_ERR_UNSUPPORTED;
1906 }
1907
sljit_emit_label(struct sljit_compiler * compiler)1908 SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
1909 {
1910 SLJIT_UNUSED_ARG(compiler);
1911 SLJIT_ASSERT_STOP();
1912 return NULL;
1913 }
1914
sljit_emit_jump(struct sljit_compiler * compiler,sljit_si type)1915 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_si type)
1916 {
1917 SLJIT_UNUSED_ARG(compiler);
1918 SLJIT_UNUSED_ARG(type);
1919 SLJIT_ASSERT_STOP();
1920 return NULL;
1921 }
1922
sljit_emit_cmp(struct sljit_compiler * compiler,sljit_si type,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1923 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_si type,
1924 sljit_si src1, sljit_sw src1w,
1925 sljit_si src2, sljit_sw src2w)
1926 {
1927 SLJIT_UNUSED_ARG(compiler);
1928 SLJIT_UNUSED_ARG(type);
1929 SLJIT_UNUSED_ARG(src1);
1930 SLJIT_UNUSED_ARG(src1w);
1931 SLJIT_UNUSED_ARG(src2);
1932 SLJIT_UNUSED_ARG(src2w);
1933 SLJIT_ASSERT_STOP();
1934 return NULL;
1935 }
1936
sljit_emit_fcmp(struct sljit_compiler * compiler,sljit_si type,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1937 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_si type,
1938 sljit_si src1, sljit_sw src1w,
1939 sljit_si src2, sljit_sw src2w)
1940 {
1941 SLJIT_UNUSED_ARG(compiler);
1942 SLJIT_UNUSED_ARG(type);
1943 SLJIT_UNUSED_ARG(src1);
1944 SLJIT_UNUSED_ARG(src1w);
1945 SLJIT_UNUSED_ARG(src2);
1946 SLJIT_UNUSED_ARG(src2w);
1947 SLJIT_ASSERT_STOP();
1948 return NULL;
1949 }
1950
sljit_set_label(struct sljit_jump * jump,struct sljit_label * label)1951 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
1952 {
1953 SLJIT_UNUSED_ARG(jump);
1954 SLJIT_UNUSED_ARG(label);
1955 SLJIT_ASSERT_STOP();
1956 }
1957
sljit_set_target(struct sljit_jump * jump,sljit_uw target)1958 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
1959 {
1960 SLJIT_UNUSED_ARG(jump);
1961 SLJIT_UNUSED_ARG(target);
1962 SLJIT_ASSERT_STOP();
1963 }
1964
sljit_emit_ijump(struct sljit_compiler * compiler,sljit_si type,sljit_si src,sljit_sw srcw)1965 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_ijump(struct sljit_compiler *compiler, sljit_si type, sljit_si src, sljit_sw srcw)
1966 {
1967 SLJIT_UNUSED_ARG(compiler);
1968 SLJIT_UNUSED_ARG(type);
1969 SLJIT_UNUSED_ARG(src);
1970 SLJIT_UNUSED_ARG(srcw);
1971 SLJIT_ASSERT_STOP();
1972 return SLJIT_ERR_UNSUPPORTED;
1973 }
1974
sljit_emit_op_flags(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src,sljit_sw srcw,sljit_si type)1975 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_si op,
1976 sljit_si dst, sljit_sw dstw,
1977 sljit_si src, sljit_sw srcw,
1978 sljit_si type)
1979 {
1980 SLJIT_UNUSED_ARG(compiler);
1981 SLJIT_UNUSED_ARG(op);
1982 SLJIT_UNUSED_ARG(dst);
1983 SLJIT_UNUSED_ARG(dstw);
1984 SLJIT_UNUSED_ARG(src);
1985 SLJIT_UNUSED_ARG(srcw);
1986 SLJIT_UNUSED_ARG(type);
1987 SLJIT_ASSERT_STOP();
1988 return SLJIT_ERR_UNSUPPORTED;
1989 }
1990
sljit_get_local_base(struct sljit_compiler * compiler,sljit_si dst,sljit_sw dstw,sljit_sw offset)1991 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_get_local_base(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw offset)
1992 {
1993 SLJIT_UNUSED_ARG(compiler);
1994 SLJIT_UNUSED_ARG(dst);
1995 SLJIT_UNUSED_ARG(dstw);
1996 SLJIT_UNUSED_ARG(offset);
1997 SLJIT_ASSERT_STOP();
1998 return SLJIT_ERR_UNSUPPORTED;
1999 }
2000
sljit_emit_const(struct sljit_compiler * compiler,sljit_si dst,sljit_sw dstw,sljit_sw initval)2001 SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw initval)
2002 {
2003 SLJIT_UNUSED_ARG(compiler);
2004 SLJIT_UNUSED_ARG(dst);
2005 SLJIT_UNUSED_ARG(dstw);
2006 SLJIT_UNUSED_ARG(initval);
2007 SLJIT_ASSERT_STOP();
2008 return NULL;
2009 }
2010
sljit_set_jump_addr(sljit_uw addr,sljit_uw new_addr)2011 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_addr)
2012 {
2013 SLJIT_UNUSED_ARG(addr);
2014 SLJIT_UNUSED_ARG(new_addr);
2015 SLJIT_ASSERT_STOP();
2016 }
2017
sljit_set_const(sljit_uw addr,sljit_sw new_constant)2018 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant)
2019 {
2020 SLJIT_UNUSED_ARG(addr);
2021 SLJIT_UNUSED_ARG(new_constant);
2022 SLJIT_ASSERT_STOP();
2023 }
2024
2025 #endif
2026