Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/pcre2/deps/sljit/sljit_src/sljitSerialize.c
21827 views
1
/*
2
* Stack-less Just-In-Time compiler
3
*
4
* Copyright Zoltan Herczeg ([email protected]). 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
#define SLJIT_GET_LABEL_INDEX(label) \
28
((label)->u.index < SLJIT_LABEL_ALIGNED ? (label)->u.index : ((struct sljit_extended_label*)(label))->index)
29
30
SLJIT_API_FUNC_ATTRIBUTE sljit_uw sljit_get_label_index(struct sljit_label *label)
31
{
32
return SLJIT_GET_LABEL_INDEX(label);
33
}
34
35
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_jump_has_label(struct sljit_jump *jump)
36
{
37
return !(jump->flags & JUMP_ADDR) && (jump->u.label != NULL);
38
}
39
40
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_jump_has_target(struct sljit_jump *jump)
41
{
42
return (jump->flags & JUMP_ADDR) != 0;
43
}
44
45
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_jump_is_mov_addr(struct sljit_jump *jump)
46
{
47
return (jump->flags & JUMP_MOV_ADDR) != 0;
48
}
49
50
#define SLJIT_SERIALIZE_DEBUG ((sljit_u16)0x1)
51
52
struct sljit_serialized_compiler {
53
sljit_u32 signature;
54
sljit_u16 version;
55
sljit_u16 cpu_type;
56
57
sljit_uw buf_segment_count;
58
sljit_uw label_count;
59
sljit_uw aligned_label_count;
60
sljit_uw jump_count;
61
sljit_uw const_count;
62
63
sljit_s32 options;
64
sljit_s32 scratches;
65
sljit_s32 saveds;
66
sljit_s32 fscratches;
67
sljit_s32 fsaveds;
68
sljit_s32 local_size;
69
sljit_uw size;
70
71
#if (defined SLJIT_HAS_STATUS_FLAGS_STATE && SLJIT_HAS_STATUS_FLAGS_STATE)
72
sljit_s32 status_flags_state;
73
#endif /* SLJIT_HAS_STATUS_FLAGS_STATE */
74
75
#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
76
sljit_s32 args_size;
77
#endif /* SLJIT_CONFIG_X86_32 */
78
79
#if ((defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) && (defined __SOFTFP__)) \
80
|| (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
81
sljit_uw args_size;
82
#endif /* (SLJIT_CONFIG_ARM_32 && __SOFTFP__) || SLJIT_CONFIG_MIPS_32 */
83
84
#if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6)
85
sljit_uw cpool_diff;
86
sljit_uw cpool_fill;
87
sljit_uw patches;
88
#endif /* SLJIT_CONFIG_ARM_V6 */
89
90
#if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
91
sljit_s32 delay_slot;
92
#endif /* SLJIT_CONFIG_MIPS */
93
94
};
95
96
struct sljit_serialized_debug_info {
97
sljit_sw last_flags;
98
sljit_s32 last_return;
99
sljit_s32 logical_local_size;
100
};
101
102
struct sljit_serialized_label {
103
sljit_uw size;
104
};
105
106
struct sljit_serialized_aligned_label {
107
sljit_uw size;
108
sljit_uw data;
109
};
110
111
struct sljit_serialized_jump {
112
sljit_uw addr;
113
sljit_uw flags;
114
sljit_uw value;
115
};
116
117
struct sljit_serialized_const {
118
sljit_uw addr;
119
};
120
121
#define SLJIT_SERIALIZE_ALIGN(v) (((v) + sizeof(sljit_uw) - 1) & ~(sljit_uw)(sizeof(sljit_uw) - 1))
122
#if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
123
#define SLJIT_SERIALIZE_SIGNATURE 0x534c4a54
124
#else /* !SLJIT_LITTLE_ENDIAN */
125
#define SLJIT_SERIALIZE_SIGNATURE 0x544a4c53
126
#endif /* SLJIT_LITTLE_ENDIAN */
127
#define SLJIT_SERIALIZE_VERSION 1
128
129
SLJIT_API_FUNC_ATTRIBUTE sljit_uw* sljit_serialize_compiler(struct sljit_compiler *compiler,
130
sljit_s32 options, sljit_uw *size)
131
{
132
sljit_uw serialized_size = sizeof(struct sljit_serialized_compiler);
133
struct sljit_memory_fragment *buf;
134
struct sljit_label *label;
135
struct sljit_jump *jump;
136
struct sljit_const *const_;
137
struct sljit_serialized_compiler *serialized_compiler;
138
struct sljit_serialized_label *serialized_label;
139
struct sljit_serialized_aligned_label *serialized_aligned_label;
140
struct sljit_serialized_jump *serialized_jump;
141
struct sljit_serialized_const *serialized_const;
142
#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
143
|| (defined SLJIT_DEBUG && SLJIT_DEBUG)
144
struct sljit_serialized_debug_info *serialized_debug_info;
145
#endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_DEBUG */
146
sljit_uw counter, used_size;
147
sljit_u8 *result;
148
sljit_u8 *ptr;
149
SLJIT_UNUSED_ARG(options);
150
151
if (size != NULL)
152
*size = 0;
153
154
PTR_FAIL_IF(compiler->error);
155
156
#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
157
|| (defined SLJIT_DEBUG && SLJIT_DEBUG)
158
if (!(options & SLJIT_SERIALIZE_IGNORE_DEBUG))
159
serialized_size += sizeof(struct sljit_serialized_debug_info);
160
#endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_DEBUG */
161
162
#if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6)
163
serialized_size += SLJIT_SERIALIZE_ALIGN(compiler->cpool_fill * (sizeof(sljit_uw) + 1));
164
#endif /* SLJIT_CONFIG_ARM_V6 */
165
166
/* Compute the size of the data. */
167
buf = compiler->buf;
168
while (buf != NULL) {
169
serialized_size += sizeof(sljit_uw) + SLJIT_SERIALIZE_ALIGN(buf->used_size);
170
buf = buf->next;
171
}
172
173
label = compiler->labels;
174
while (label != NULL) {
175
used_size = sizeof(struct sljit_serialized_label);
176
177
if (label->u.index >= SLJIT_LABEL_ALIGNED)
178
used_size += sizeof(struct sljit_serialized_aligned_label);
179
180
serialized_size += used_size;
181
label = label->next;
182
}
183
184
jump = compiler->jumps;
185
while (jump != NULL) {
186
serialized_size += sizeof(struct sljit_serialized_jump);
187
jump = jump->next;
188
}
189
190
const_ = compiler->consts;
191
while (const_ != NULL) {
192
serialized_size += sizeof(struct sljit_serialized_const);
193
const_ = const_->next;
194
}
195
196
result = (sljit_u8*)SLJIT_MALLOC(serialized_size, compiler->allocator_data);
197
PTR_FAIL_IF_NULL(result);
198
199
if (size != NULL)
200
*size = serialized_size;
201
202
ptr = result;
203
serialized_compiler = (struct sljit_serialized_compiler*)ptr;
204
ptr += sizeof(struct sljit_serialized_compiler);
205
206
serialized_compiler->signature = SLJIT_SERIALIZE_SIGNATURE;
207
serialized_compiler->version = SLJIT_SERIALIZE_VERSION;
208
serialized_compiler->cpu_type = 0;
209
serialized_compiler->label_count = compiler->label_count;
210
serialized_compiler->options = compiler->options;
211
serialized_compiler->scratches = compiler->scratches;
212
serialized_compiler->saveds = compiler->saveds;
213
serialized_compiler->fscratches = compiler->fscratches;
214
serialized_compiler->fsaveds = compiler->fsaveds;
215
serialized_compiler->local_size = compiler->local_size;
216
serialized_compiler->size = compiler->size;
217
218
#if (defined SLJIT_HAS_STATUS_FLAGS_STATE && SLJIT_HAS_STATUS_FLAGS_STATE)
219
serialized_compiler->status_flags_state = compiler->status_flags_state;
220
#endif /* SLJIT_HAS_STATUS_FLAGS_STATE */
221
222
#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
223
|| ((defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) && (defined __SOFTFP__)) \
224
|| (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
225
serialized_compiler->args_size = compiler->args_size;
226
#endif /* SLJIT_CONFIG_X86_32 || (SLJIT_CONFIG_ARM_32 && __SOFTFP__) || SLJIT_CONFIG_MIPS_32 */
227
228
#if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6)
229
serialized_compiler->cpool_diff = compiler->cpool_diff;
230
serialized_compiler->cpool_fill = compiler->cpool_fill;
231
serialized_compiler->patches = compiler->patches;
232
233
SLJIT_MEMCPY(ptr, compiler->cpool, compiler->cpool_fill * sizeof(sljit_uw));
234
SLJIT_MEMCPY(ptr + compiler->cpool_fill * sizeof(sljit_uw), compiler->cpool_unique, compiler->cpool_fill);
235
ptr += SLJIT_SERIALIZE_ALIGN(compiler->cpool_fill * (sizeof(sljit_uw) + 1));
236
#endif /* SLJIT_CONFIG_ARM_V6 */
237
238
#if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
239
serialized_compiler->delay_slot = compiler->delay_slot;
240
#endif /* SLJIT_CONFIG_MIPS */
241
242
buf = compiler->buf;
243
counter = 0;
244
while (buf != NULL) {
245
used_size = buf->used_size;
246
*(sljit_uw*)ptr = used_size;
247
ptr += sizeof(sljit_uw);
248
SLJIT_MEMCPY(ptr, buf->memory, used_size);
249
ptr += SLJIT_SERIALIZE_ALIGN(used_size);
250
buf = buf->next;
251
counter++;
252
}
253
serialized_compiler->buf_segment_count = counter;
254
255
label = compiler->labels;
256
counter = 0;
257
while (label != NULL) {
258
serialized_label = (struct sljit_serialized_label*)ptr;
259
serialized_label->size = (label->u.index < SLJIT_LABEL_ALIGNED) ? label->size : label->u.index;
260
ptr += sizeof(struct sljit_serialized_label);
261
262
if (label->u.index >= SLJIT_LABEL_ALIGNED) {
263
serialized_aligned_label = (struct sljit_serialized_aligned_label*)ptr;
264
serialized_aligned_label->size = label->size;
265
serialized_aligned_label->data = ((struct sljit_extended_label*)label)->data;
266
ptr += sizeof(struct sljit_serialized_aligned_label);
267
counter++;
268
}
269
270
label = label->next;
271
}
272
serialized_compiler->aligned_label_count = counter;
273
274
jump = compiler->jumps;
275
counter = 0;
276
while (jump != NULL) {
277
serialized_jump = (struct sljit_serialized_jump*)ptr;
278
serialized_jump->addr = jump->addr;
279
serialized_jump->flags = jump->flags;
280
281
if (jump->flags & JUMP_ADDR)
282
serialized_jump->value = jump->u.target;
283
else if (jump->u.label != NULL)
284
serialized_jump->value = SLJIT_GET_LABEL_INDEX(jump->u.label);
285
else
286
serialized_jump->value = SLJIT_MAX_ADDRESS;
287
288
ptr += sizeof(struct sljit_serialized_jump);
289
jump = jump->next;
290
counter++;
291
}
292
serialized_compiler->jump_count = counter;
293
294
const_ = compiler->consts;
295
counter = 0;
296
while (const_ != NULL) {
297
serialized_const = (struct sljit_serialized_const*)ptr;
298
serialized_const->addr = const_->addr;
299
ptr += sizeof(struct sljit_serialized_const);
300
const_ = const_->next;
301
counter++;
302
}
303
serialized_compiler->const_count = counter;
304
305
#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
306
|| (defined SLJIT_DEBUG && SLJIT_DEBUG)
307
if (!(options & SLJIT_SERIALIZE_IGNORE_DEBUG)) {
308
serialized_debug_info = (struct sljit_serialized_debug_info*)ptr;
309
serialized_debug_info->last_flags = compiler->last_flags;
310
serialized_debug_info->last_return = compiler->last_return;
311
serialized_debug_info->logical_local_size = compiler->logical_local_size;
312
serialized_compiler->cpu_type |= SLJIT_SERIALIZE_DEBUG;
313
#if (defined SLJIT_DEBUG && SLJIT_DEBUG)
314
ptr += sizeof(struct sljit_serialized_debug_info);
315
#endif /* SLJIT_DEBUG */
316
}
317
#endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_DEBUG */
318
319
SLJIT_ASSERT((sljit_uw)(ptr - result) == serialized_size);
320
return (sljit_uw*)result;
321
}
322
323
SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler *sljit_deserialize_compiler(sljit_uw* buffer, sljit_uw size,
324
sljit_s32 options, void *allocator_data)
325
{
326
struct sljit_compiler *compiler;
327
struct sljit_serialized_compiler *serialized_compiler;
328
struct sljit_serialized_label *serialized_label;
329
struct sljit_serialized_aligned_label *serialized_aligned_label;
330
struct sljit_serialized_jump *serialized_jump;
331
struct sljit_serialized_const *serialized_const;
332
#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
333
|| (defined SLJIT_DEBUG && SLJIT_DEBUG)
334
struct sljit_serialized_debug_info *serialized_debug_info;
335
#endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_DEBUG */
336
struct sljit_memory_fragment *buf;
337
struct sljit_memory_fragment *last_buf;
338
struct sljit_label *label;
339
struct sljit_label *last_label;
340
struct sljit_label **label_list = NULL;
341
struct sljit_label **label_list_ptr = NULL;
342
struct sljit_jump *jump;
343
struct sljit_jump *last_jump;
344
struct sljit_const *const_;
345
struct sljit_const *last_const;
346
sljit_u8 *ptr = (sljit_u8*)buffer;
347
sljit_u8 *end = ptr + size;
348
sljit_uw i, type, used_size, aligned_size;
349
sljit_uw label_count, aligned_label_count;
350
SLJIT_UNUSED_ARG(options);
351
352
if (size < sizeof(struct sljit_serialized_compiler) || (size & (sizeof(sljit_uw) - 1)) != 0)
353
return NULL;
354
355
serialized_compiler = (struct sljit_serialized_compiler*)ptr;
356
357
if (serialized_compiler->signature != SLJIT_SERIALIZE_SIGNATURE || serialized_compiler->version != SLJIT_SERIALIZE_VERSION)
358
return NULL;
359
360
compiler = sljit_create_compiler(allocator_data);
361
PTR_FAIL_IF(compiler == NULL);
362
363
compiler->label_count = serialized_compiler->label_count;
364
compiler->options = serialized_compiler->options;
365
compiler->scratches = serialized_compiler->scratches;
366
compiler->saveds = serialized_compiler->saveds;
367
compiler->fscratches = serialized_compiler->fscratches;
368
compiler->fsaveds = serialized_compiler->fsaveds;
369
compiler->local_size = serialized_compiler->local_size;
370
compiler->size = serialized_compiler->size;
371
372
#if (defined SLJIT_HAS_STATUS_FLAGS_STATE && SLJIT_HAS_STATUS_FLAGS_STATE)
373
compiler->status_flags_state = serialized_compiler->status_flags_state;
374
#endif /* SLJIT_HAS_STATUS_FLAGS_STATE */
375
376
#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
377
|| ((defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) && (defined __SOFTFP__)) \
378
|| (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
379
compiler->args_size = serialized_compiler->args_size;
380
#endif /* SLJIT_CONFIG_X86_32 || (SLJIT_CONFIG_ARM_32 && __SOFTFP__) || SLJIT_CONFIG_MIPS_32 */
381
382
#if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6)
383
used_size = serialized_compiler->cpool_fill;
384
aligned_size = SLJIT_SERIALIZE_ALIGN(used_size * (sizeof(sljit_uw) + 1));
385
compiler->cpool_diff = serialized_compiler->cpool_diff;
386
compiler->cpool_fill = used_size;
387
compiler->patches = serialized_compiler->patches;
388
389
if ((sljit_uw)(end - ptr) < aligned_size)
390
goto error;
391
392
SLJIT_MEMCPY(compiler->cpool, ptr, used_size * sizeof(sljit_uw));
393
SLJIT_MEMCPY(compiler->cpool_unique, ptr + used_size * sizeof(sljit_uw), used_size);
394
ptr += aligned_size;
395
#endif /* SLJIT_CONFIG_ARM_V6 */
396
397
#if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
398
compiler->delay_slot = serialized_compiler->delay_slot;
399
#endif /* SLJIT_CONFIG_MIPS */
400
401
#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
402
|| (defined SLJIT_DEBUG && SLJIT_DEBUG)
403
if (!(serialized_compiler->cpu_type & SLJIT_SERIALIZE_DEBUG))
404
goto error;
405
#endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_DEBUG */
406
407
ptr += sizeof(struct sljit_serialized_compiler);
408
i = serialized_compiler->buf_segment_count;
409
last_buf = NULL;
410
while (i > 0) {
411
if ((sljit_uw)(end - ptr) < sizeof(sljit_uw))
412
goto error;
413
414
used_size = *(sljit_uw*)ptr;
415
aligned_size = SLJIT_SERIALIZE_ALIGN(used_size);
416
ptr += sizeof(sljit_uw);
417
418
if ((sljit_uw)(end - ptr) < aligned_size)
419
goto error;
420
421
if (last_buf == NULL) {
422
SLJIT_ASSERT(compiler->buf != NULL && compiler->buf->next == NULL);
423
buf = compiler->buf;
424
} else {
425
buf = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, allocator_data);
426
if (!buf)
427
goto error;
428
buf->next = NULL;
429
}
430
431
buf->used_size = used_size;
432
SLJIT_MEMCPY(buf->memory, ptr, used_size);
433
434
if (last_buf != NULL)
435
last_buf->next = buf;
436
last_buf = buf;
437
438
ptr += aligned_size;
439
i--;
440
}
441
442
last_label = NULL;
443
label_count = serialized_compiler->label_count;
444
aligned_label_count = serialized_compiler->aligned_label_count;
445
i = (label_count * sizeof(struct sljit_serialized_label)) + (aligned_label_count * sizeof(struct sljit_serialized_aligned_label));
446
447
if ((sljit_uw)(end - ptr) < i)
448
goto error;
449
450
label_list = (struct sljit_label **)SLJIT_MALLOC(label_count * sizeof(struct sljit_label*), allocator_data);
451
if (label_list == NULL)
452
goto error;
453
454
label_list_ptr = label_list;
455
for (i = 0; i < label_count; i++) {
456
serialized_label = (struct sljit_serialized_label*)ptr;
457
type = serialized_label->size;
458
459
if (type < SLJIT_LABEL_ALIGNED) {
460
label = (struct sljit_label*)ensure_abuf(compiler, sizeof(struct sljit_label));
461
} else {
462
label = (struct sljit_label*)ensure_abuf(compiler, sizeof(struct sljit_extended_label));
463
}
464
465
if (label == NULL)
466
goto error;
467
468
label->next = NULL;
469
470
if (last_label != NULL)
471
last_label->next = label;
472
else
473
compiler->labels = label;
474
last_label = label;
475
476
*label_list_ptr++ = label;
477
478
ptr += sizeof(struct sljit_serialized_label);
479
480
if (type < SLJIT_LABEL_ALIGNED) {
481
label->u.index = i;
482
label->size = type;
483
} else {
484
if (aligned_label_count == 0)
485
goto error;
486
487
aligned_label_count--;
488
489
serialized_aligned_label = (struct sljit_serialized_aligned_label*)ptr;
490
label->u.index = type;
491
label->size = serialized_aligned_label->size;
492
493
((struct sljit_extended_label*)label)->index = i;
494
((struct sljit_extended_label*)label)->data = serialized_aligned_label->data;
495
ptr += sizeof(struct sljit_serialized_aligned_label);
496
}
497
}
498
compiler->last_label = last_label;
499
500
if (aligned_label_count != 0)
501
goto error;
502
503
last_jump = NULL;
504
i = serialized_compiler->jump_count;
505
if ((sljit_uw)(end - ptr) < i * sizeof(struct sljit_serialized_jump))
506
goto error;
507
508
while (i > 0) {
509
jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump));
510
if (jump == NULL)
511
goto error;
512
513
serialized_jump = (struct sljit_serialized_jump*)ptr;
514
jump->next = NULL;
515
jump->addr = serialized_jump->addr;
516
jump->flags = serialized_jump->flags;
517
518
if (!(serialized_jump->flags & JUMP_ADDR)) {
519
if (serialized_jump->value != SLJIT_MAX_ADDRESS) {
520
if (serialized_jump->value >= label_count)
521
goto error;
522
jump->u.label = label_list[serialized_jump->value];
523
} else
524
jump->u.label = NULL;
525
} else
526
jump->u.target = serialized_jump->value;
527
528
if (last_jump != NULL)
529
last_jump->next = jump;
530
else
531
compiler->jumps = jump;
532
last_jump = jump;
533
534
ptr += sizeof(struct sljit_serialized_jump);
535
i--;
536
}
537
compiler->last_jump = last_jump;
538
539
SLJIT_FREE(label_list, allocator_data);
540
label_list = NULL;
541
542
last_const = NULL;
543
i = serialized_compiler->const_count;
544
if ((sljit_uw)(end - ptr) < i * sizeof(struct sljit_serialized_const))
545
goto error;
546
547
while (i > 0) {
548
const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const));
549
if (const_ == NULL)
550
goto error;
551
552
serialized_const = (struct sljit_serialized_const*)ptr;
553
const_->next = NULL;
554
const_->addr = serialized_const->addr;
555
556
if (last_const != NULL)
557
last_const->next = const_;
558
else
559
compiler->consts = const_;
560
last_const = const_;
561
562
ptr += sizeof(struct sljit_serialized_const);
563
i--;
564
}
565
compiler->last_const = last_const;
566
567
#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
568
|| (defined SLJIT_DEBUG && SLJIT_DEBUG)
569
if ((sljit_uw)(end - ptr) < sizeof(struct sljit_serialized_debug_info))
570
goto error;
571
572
serialized_debug_info = (struct sljit_serialized_debug_info*)ptr;
573
compiler->last_flags = (sljit_s32)serialized_debug_info->last_flags;
574
compiler->last_return = serialized_debug_info->last_return;
575
compiler->logical_local_size = serialized_debug_info->logical_local_size;
576
#endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_DEBUG */
577
578
return compiler;
579
580
error:
581
sljit_free_compiler(compiler);
582
if (label_list != NULL)
583
SLJIT_FREE(label_list, allocator_data);
584
return NULL;
585
}
586
587