Parent Directory
|
Revision Log
|
Patch
revision 991 by zherczeg, Sun Jul 8 16:44:39 2012 UTC | revision 1306 by zherczeg, Mon Apr 1 17:04:17 2013 UTC | |
---|---|---|
# | Line 6 | Line 6 |
6 | and semantics are as close as possible to those of the Perl 5 language. | and semantics are as close as possible to those of the Perl 5 language. |
7 | ||
8 | Written by Philip Hazel | Written by Philip Hazel |
9 | Copyright (c) 1997-2012 University of Cambridge | Copyright (c) 1997-2013 University of Cambridge |
10 | ||
11 | The machine code generator part (this module) was written by Zoltan Herczeg | The machine code generator part (this module) was written by Zoltan Herczeg |
12 | Copyright (c) 2010-2012 | Copyright (c) 2010-2013 |
13 | ||
14 | ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
15 | Redistribution and use in source and binary forms, with or without | Redistribution and use in source and binary forms, with or without |
# | Line 46 POSSIBILITY OF SUCH DAMAGE. | Line 46 POSSIBILITY OF SUCH DAMAGE. |
46 | ||
47 | #include "pcre_internal.h" | #include "pcre_internal.h" |
48 | ||
49 | #ifdef SUPPORT_JIT | #if defined SUPPORT_JIT |
50 | ||
51 | /* All-in-one: Since we use the JIT compiler only from here, | /* All-in-one: Since we use the JIT compiler only from here, |
52 | we just include it. This way we don't need to touch the build | we just include it. This way we don't need to touch the build |
# | Line 65 system files. */ | Line 65 system files. */ |
65 | #error Unsupported architecture | #error Unsupported architecture |
66 | #endif | #endif |
67 | ||
68 | /* Allocate memory on the stack. Fast, but limited size. */ | /* Defines for debugging purposes. */ |
#define LOCAL_SPACE_SIZE 32768 | ||
69 | ||
70 | /* 1 - Use unoptimized capturing brackets. | |
71 | 2 - Enable capture_last_ptr (includes option 1). */ | |
72 | /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */ | |
73 | ||
74 | /* 1 - Always have a control head. */ | |
75 | /* #define DEBUG_FORCE_CONTROL_HEAD 1 */ | |
76 | ||
77 | /* Allocate memory for the regex stack on the real machine stack. | |
78 | Fast, but limited size. */ | |
79 | #define MACHINE_STACK_SIZE 32768 | |
80 | ||
81 | /* Growth rate for stack allocated by the OS. Should be the multiply | |
82 | of page size. */ | |
83 | #define STACK_GROWTH_RATE 8192 | #define STACK_GROWTH_RATE 8192 |
84 | ||
85 | /* Enable to check that the allocation could destroy temporaries. */ | /* Enable to check that the allocation could destroy temporaries. */ |
# | Line 89 vertical (sub-expression) (See struct ba | Line 101 vertical (sub-expression) (See struct ba |
101 | ||
102 | The condition checkers are boolean (true/false) checkers. Machine code is generated | The condition checkers are boolean (true/false) checkers. Machine code is generated |
103 | for the checker itself and for the actions depending on the result of the checker. | for the checker itself and for the actions depending on the result of the checker. |
104 | The 'true' case is called as the try path (expected path), and the other is called as | The 'true' case is called as the matching path (expected path), and the other is called as |
105 | the 'backtrack' path. Branch instructions are expesive for all CPUs, so we avoid taken | the 'backtrack' path. Branch instructions are expesive for all CPUs, so we avoid taken |
106 | branches on the try path. | branches on the matching path. |
107 | ||
108 | Greedy star operator (*) : | Greedy star operator (*) : |
109 | Try path: match happens. | Matching path: match happens. |
110 | Backtrack path: match failed. | Backtrack path: match failed. |
111 | Non-greedy star operator (*?) : | Non-greedy star operator (*?) : |
112 | Try path: no need to perform a match. | Matching path: no need to perform a match. |
113 | Backtrack path: match is required. | Backtrack path: match is required. |
114 | ||
115 | The following example shows how the code generated for a capturing bracket | The following example shows how the code generated for a capturing bracket |
# | Line 108 we have the following regular expression | Line 120 we have the following regular expression |
120 | ||
121 | The generated code will be the following: | The generated code will be the following: |
122 | ||
123 | A try path | A matching path |
124 | '(' try path (pushing arguments to the stack) | '(' matching path (pushing arguments to the stack) |
125 | B try path | B matching path |
126 | ')' try path (pushing arguments to the stack) | ')' matching path (pushing arguments to the stack) |
127 | D try path | D matching path |
128 | return with successful match | return with successful match |
129 | ||
130 | D backtrack path | D backtrack path |
131 | ')' backtrack path (If we arrived from "C" jump to the backtrack of "C") | ')' backtrack path (If we arrived from "C" jump to the backtrack of "C") |
132 | B backtrack path | B backtrack path |
133 | C expected path | C expected path |
134 | jump to D try path | jump to D matching path |
135 | C backtrack path | C backtrack path |
136 | A backtrack path | A backtrack path |
137 | ||
# | Line 127 The generated code will be the following | Line 139 The generated code will be the following |
139 | code paths. In this way the topmost value on the stack is always belong | code paths. In this way the topmost value on the stack is always belong |
140 | to the current backtrack code path. The backtrack path must check | to the current backtrack code path. The backtrack path must check |
141 | whether there is a next alternative. If so, it needs to jump back to | whether there is a next alternative. If so, it needs to jump back to |
142 | the try path eventually. Otherwise it needs to clear out its own stack | the matching path eventually. Otherwise it needs to clear out its own stack |
143 | frame and continue the execution on the backtrack code paths. | frame and continue the execution on the backtrack code paths. |
144 | */ | */ |
145 | ||
146 | /* | /* |
147 | Saved stack frames: | Saved stack frames: |
148 | ||
149 | Atomic blocks and asserts require reloading the values of local variables | Atomic blocks and asserts require reloading the values of private data |
150 | when the backtrack mechanism performed. Because of OP_RECURSE, the locals | when the backtrack mechanism performed. Because of OP_RECURSE, the data |
151 | are not necessarly known in compile time, thus we need a dynamic restore | are not necessarly known in compile time, thus we need a dynamic restore |
152 | mechanism. | mechanism. |
153 | ||
154 | The stack frames are stored in a chain list, and have the following format: | The stack frames are stored in a chain list, and have the following format: |
155 | ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ] | ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ] |
156 | ||
157 | Thus we can restore the locals to a particular point in the stack. | Thus we can restore the private data to a particular point in the stack. |
158 | */ | */ |
159 | ||
160 | typedef struct jit_arguments { | typedef struct jit_arguments { |
# | Line 154 typedef struct jit_arguments { | Line 166 typedef struct jit_arguments { |
166 | int *offsets; | int *offsets; |
167 | pcre_uchar *uchar_ptr; | pcre_uchar *uchar_ptr; |
168 | pcre_uchar *mark_ptr; | pcre_uchar *mark_ptr; |
169 | void *callout_data; | |
170 | /* Everything else after. */ | /* Everything else after. */ |
171 | int offsetcount; | int real_offset_count; |
172 | int calllimit; | int offset_count; |
173 | int call_limit; | |
174 | pcre_uint8 notbol; | pcre_uint8 notbol; |
175 | pcre_uint8 noteol; | pcre_uint8 noteol; |
176 | pcre_uint8 notempty; | pcre_uint8 notempty; |
# | Line 167 typedef struct executable_functions { | Line 181 typedef struct executable_functions { |
181 | void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES]; | void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES]; |
182 | PUBL(jit_callback) callback; | PUBL(jit_callback) callback; |
183 | void *userdata; | void *userdata; |
184 | pcre_uint32 top_bracket; | |
185 | sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES]; | sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES]; |
186 | } executable_functions; | } executable_functions; |
187 | ||
# | Line 175 typedef struct jump_list { | Line 190 typedef struct jump_list { |
190 | struct jump_list *next; | struct jump_list *next; |
191 | } jump_list; | } jump_list; |
192 | ||
enum stub_types { stack_alloc }; | ||
193 | typedef struct stub_list { | typedef struct stub_list { |
enum stub_types type; | ||
int data; | ||
194 | struct sljit_jump *start; | struct sljit_jump *start; |
195 | struct sljit_label *quit; | struct sljit_label *quit; |
196 | struct stub_list *next; | struct stub_list *next; |
197 | } stub_list; | } stub_list; |
198 | ||
199 | enum frame_types { | |
200 | no_frame = -1, | |
201 | no_stack = -2 | |
202 | }; | |
203 | ||
204 | enum control_types { | |
205 | type_mark = 0, | |
206 | type_then_trap = 1 | |
207 | }; | |
208 | ||
209 | typedef int (SLJIT_CALL *jit_function)(jit_arguments *args); | typedef int (SLJIT_CALL *jit_function)(jit_arguments *args); |
210 | ||
211 | /* The following structure is the key data type for the recursive | /* The following structure is the key data type for the recursive |
212 | code generator. It is allocated by compile_trypath, and contains | code generator. It is allocated by compile_matchingpath, and contains |
213 | the aguments for compile_backtrackpath. Must be the first member | the aguments for compile_backtrackingpath. Must be the first member |
214 | of its descendants. */ | of its descendants. */ |
215 | typedef struct backtrack_common { | typedef struct backtrack_common { |
216 | /* Concatenation stack. */ | /* Concatenation stack. */ |
# | Line 205 typedef struct backtrack_common { | Line 226 typedef struct backtrack_common { |
226 | typedef struct assert_backtrack { | typedef struct assert_backtrack { |
227 | backtrack_common common; | backtrack_common common; |
228 | jump_list *condfailed; | jump_list *condfailed; |
229 | /* Less than 0 (-1) if a frame is not needed. */ | /* Less than 0 if a frame is not needed. */ |
230 | int framesize; | int framesize; |
231 | /* Points to our private memory word on the stack. */ | /* Points to our private memory word on the stack. */ |
232 | int localptr; | int private_data_ptr; |
233 | /* For iterators. */ | /* For iterators. */ |
234 | struct sljit_label *trypath; | struct sljit_label *matchingpath; |
235 | } assert_backtrack; | } assert_backtrack; |
236 | ||
237 | typedef struct bracket_backtrack { | typedef struct bracket_backtrack { |
238 | backtrack_common common; | backtrack_common common; |
239 | /* Where to coninue if an alternative is successfully matched. */ | /* Where to coninue if an alternative is successfully matched. */ |
240 | struct sljit_label *alttrypath; | struct sljit_label *alternative_matchingpath; |
241 | /* For rmin and rmax iterators. */ | /* For rmin and rmax iterators. */ |
242 | struct sljit_label *recursivetrypath; | struct sljit_label *recursive_matchingpath; |
243 | /* For greedy ? operator. */ | /* For greedy ? operator. */ |
244 | struct sljit_label *zerotrypath; | struct sljit_label *zero_matchingpath; |
245 | /* Contains the branches of a failed condition. */ | /* Contains the branches of a failed condition. */ |
246 | union { | union { |
247 | /* Both for OP_COND, OP_SCOND. */ | /* Both for OP_COND, OP_SCOND. */ |
248 | jump_list *condfailed; | jump_list *condfailed; |
249 | assert_backtrack *assert; | assert_backtrack *assert; |
250 | /* For OP_ONCE. -1 if not needed. */ | /* For OP_ONCE. Less than 0 if not needed. */ |
251 | int framesize; | int framesize; |
252 | } u; | } u; |
253 | /* Points to our private memory word on the stack. */ | /* Points to our private memory word on the stack. */ |
254 | int localptr; | int private_data_ptr; |
255 | } bracket_backtrack; | } bracket_backtrack; |
256 | ||
257 | typedef struct bracketpos_backtrack { | typedef struct bracketpos_backtrack { |
258 | backtrack_common common; | backtrack_common common; |
259 | /* Points to our private memory word on the stack. */ | /* Points to our private memory word on the stack. */ |
260 | int localptr; | int private_data_ptr; |
261 | /* Reverting stack is needed. */ | /* Reverting stack is needed. */ |
262 | int framesize; | int framesize; |
263 | /* Allocated stack size. */ | /* Allocated stack size. */ |
# | Line 245 typedef struct bracketpos_backtrack { | Line 266 typedef struct bracketpos_backtrack { |
266 | ||
267 | typedef struct braminzero_backtrack { | typedef struct braminzero_backtrack { |
268 | backtrack_common common; | backtrack_common common; |
269 | struct sljit_label *trypath; | struct sljit_label *matchingpath; |
270 | } braminzero_backtrack; | } braminzero_backtrack; |
271 | ||
272 | typedef struct iterator_backtrack { | typedef struct iterator_backtrack { |
273 | backtrack_common common; | backtrack_common common; |
274 | /* Next iteration. */ | /* Next iteration. */ |
275 | struct sljit_label *trypath; | struct sljit_label *matchingpath; |
276 | } iterator_backtrack; | } iterator_backtrack; |
277 | ||
278 | typedef struct recurse_entry { | typedef struct recurse_entry { |
# | Line 261 typedef struct recurse_entry { | Line 282 typedef struct recurse_entry { |
282 | /* Collects the calls until the function is not created. */ | /* Collects the calls until the function is not created. */ |
283 | jump_list *calls; | jump_list *calls; |
284 | /* Points to the starting opcode. */ | /* Points to the starting opcode. */ |
285 | int start; | sljit_sw start; |
286 | } recurse_entry; | } recurse_entry; |
287 | ||
288 | typedef struct recurse_backtrack { | typedef struct recurse_backtrack { |
289 | backtrack_common common; | backtrack_common common; |
290 | BOOL inlined_pattern; | |
291 | } recurse_backtrack; | } recurse_backtrack; |
292 | ||
293 | #define OP_THEN_TRAP OP_TABLE_LENGTH | |
294 | ||
295 | typedef struct then_trap_backtrack { | |
296 | backtrack_common common; | |
297 | /* If then_trap is not NULL, this structure contains the real | |
298 | then_trap for the backtracking path. */ | |
299 | struct then_trap_backtrack *then_trap; | |
300 | /* Points to the starting opcode. */ | |
301 | sljit_sw start; | |
302 | /* Exit point for the then opcodes of this alternative. */ | |
303 | jump_list *quit; | |
304 | /* Frame size of the current alternative. */ | |
305 | int framesize; | |
306 | } then_trap_backtrack; | |
307 | ||
308 | #define MAX_RANGE_SIZE 6 | #define MAX_RANGE_SIZE 6 |
309 | ||
310 | typedef struct compiler_common { | typedef struct compiler_common { |
311 | /* The sljit ceneric compiler. */ | |
312 | struct sljit_compiler *compiler; | struct sljit_compiler *compiler; |
313 | /* First byte code. */ | |
314 | pcre_uchar *start; | pcre_uchar *start; |
315 | /* Maps private data offset to each opcode. */ | |
316 | /* Opcode local area direct map. */ | sljit_si *private_data_ptrs; |
317 | int *localptrs; | /* Tells whether the capturing bracket is optimized. */ |
318 | int cbraptr; | pcre_uint8 *optimized_cbracket; |
319 | /* OVector starting point. Must be divisible by 2. */ | /* Tells whether the starting offset is a target of then. */ |
320 | pcre_uint8 *then_offsets; | |
321 | /* Current position where a THEN must jump. */ | |
322 | then_trap_backtrack *then_trap; | |
323 | /* Starting offset of private data for capturing brackets. */ | |
324 | int cbra_ptr; | |
325 | /* Output vector starting point. Must be divisible by 2. */ | |
326 | int ovector_start; | int ovector_start; |
327 | /* Last known position of the requested byte. */ | /* Last known position of the requested byte. */ |
328 | int req_char_ptr; | int req_char_ptr; |
329 | /* Head of the last recursion. */ | /* Head of the last recursion. */ |
330 | int recursive_head; | int recursive_head_ptr; |
331 | /* First inspected character for partial matching. */ | /* First inspected character for partial matching. */ |
332 | int start_used_ptr; | int start_used_ptr; |
333 | /* Starting pointer for partial soft matches. */ | /* Starting pointer for partial soft matches. */ |
# | Line 291 typedef struct compiler_common { | Line 336 typedef struct compiler_common { |
336 | int first_line_end; | int first_line_end; |
337 | /* Points to the marked string. */ | /* Points to the marked string. */ |
338 | int mark_ptr; | int mark_ptr; |
339 | /* Recursive control verb management chain. */ | |
340 | int control_head_ptr; | |
341 | /* Points to the last matched capture block index. */ | |
342 | int capture_last_ptr; | |
343 | /* Points to the starting position of the current match. */ | |
344 | int start_ptr; | |
345 | ||
346 | /* Flipped and lower case tables. */ | /* Flipped and lower case tables. */ |
347 | const pcre_uint8 *fcc; | const pcre_uint8 *fcc; |
348 | sljit_w lcc; | sljit_sw lcc; |
349 | /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */ | /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */ |
350 | int mode; | int mode; |
351 | /* \K is found in the pattern. */ | |
352 | BOOL has_set_som; | |
353 | /* (*SKIP:arg) is found in the pattern. */ | |
354 | BOOL has_skip_arg; | |
355 | /* (*THEN) is found in the pattern. */ | |
356 | BOOL has_then; | |
357 | /* Needs to know the start position anytime. */ | |
358 | BOOL needs_start_ptr; | |
359 | /* Currently in recurse or negative assert. */ | |
360 | BOOL local_exit; | |
361 | /* Currently in a positive assert. */ | |
362 | BOOL positive_assert; | |
363 | /* Newline control. */ | /* Newline control. */ |
364 | int nltype; | int nltype; |
365 | int newline; | int newline; |
366 | int bsr_nltype; | int bsr_nltype; |
367 | /* Dollar endonly. */ | /* Dollar endonly. */ |
368 | int endonly; | int endonly; |
BOOL has_set_som; | ||
369 | /* Tables. */ | /* Tables. */ |
370 | sljit_w ctypes; | sljit_sw ctypes; |
371 | int digits[2 + MAX_RANGE_SIZE]; | int digits[2 + MAX_RANGE_SIZE]; |
372 | /* Named capturing brackets. */ | /* Named capturing brackets. */ |
373 | sljit_uw name_table; | sljit_uw name_table; |
374 | sljit_w name_count; | sljit_sw name_count; |
375 | sljit_w name_entry_size; | sljit_sw name_entry_size; |
376 | ||
377 | /* Labels and jump lists. */ | /* Labels and jump lists. */ |
378 | struct sljit_label *partialmatchlabel; | struct sljit_label *partialmatchlabel; |
379 | struct sljit_label *quitlabel; | struct sljit_label *quit_label; |
380 | struct sljit_label *acceptlabel; | struct sljit_label *forced_quit_label; |
381 | struct sljit_label *accept_label; | |
382 | stub_list *stubs; | stub_list *stubs; |
383 | recurse_entry *entries; | recurse_entry *entries; |
384 | recurse_entry *currententry; | recurse_entry *currententry; |
385 | jump_list *partialmatch; | jump_list *partialmatch; |
386 | jump_list *quit; | jump_list *quit; |
387 | jump_list *positive_assert_quit; | |
388 | jump_list *forced_quit; | |
389 | jump_list *accept; | jump_list *accept; |
390 | jump_list *calllimit; | jump_list *calllimit; |
391 | jump_list *stackalloc; | jump_list *stackalloc; |
# | Line 331 typedef struct compiler_common { | Line 396 typedef struct compiler_common { |
396 | jump_list *vspace; | jump_list *vspace; |
397 | jump_list *casefulcmp; | jump_list *casefulcmp; |
398 | jump_list *caselesscmp; | jump_list *caselesscmp; |
399 | jump_list *reset_match; | |
400 | BOOL jscript_compat; | BOOL jscript_compat; |
401 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
402 | BOOL utf; | BOOL utf; |
403 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
404 | BOOL use_ucp; | BOOL use_ucp; |
405 | #endif | #endif |
406 | #ifndef COMPILE_PCRE32 | |
407 | jump_list *utfreadchar; | jump_list *utfreadchar; |
408 | #endif | |
409 | #ifdef COMPILE_PCRE8 | #ifdef COMPILE_PCRE8 |
410 | jump_list *utfreadtype8; | jump_list *utfreadtype8; |
411 | #endif | #endif |
# | Line 355 typedef struct compare_context { | Line 423 typedef struct compare_context { |
423 | #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED | #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED |
424 | int ucharptr; | int ucharptr; |
425 | union { | union { |
426 | sljit_i asint; | sljit_si asint; |
427 | sljit_uh asushort; | sljit_uh asushort; |
428 | #ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 |
429 | sljit_ub asbyte; | sljit_ub asbyte; |
430 | sljit_ub asuchars[4]; | sljit_ub asuchars[4]; |
431 | #else | #elif defined COMPILE_PCRE16 |
#ifdef COMPILE_PCRE16 | ||
432 | sljit_uh asuchars[2]; | sljit_uh asuchars[2]; |
433 | #endif | #elif defined COMPILE_PCRE32 |
434 | sljit_ui asuchars[1]; | |
435 | #endif | #endif |
436 | } c; | } c; |
437 | union { | union { |
438 | sljit_i asint; | sljit_si asint; |
439 | sljit_uh asushort; | sljit_uh asushort; |
440 | #ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 |
441 | sljit_ub asbyte; | sljit_ub asbyte; |
442 | sljit_ub asuchars[4]; | sljit_ub asuchars[4]; |
443 | #else | #elif defined COMPILE_PCRE16 |
#ifdef COMPILE_PCRE16 | ||
444 | sljit_uh asuchars[2]; | sljit_uh asuchars[2]; |
445 | #endif | #elif defined COMPILE_PCRE32 |
446 | sljit_ui asuchars[1]; | |
447 | #endif | #endif |
448 | } oc; | } oc; |
449 | #endif | #endif |
450 | } compare_context; | } compare_context; |
451 | ||
enum { | ||
frame_end = 0, | ||
frame_setstrbegin = -1, | ||
frame_setmark = -2 | ||
}; | ||
452 | /* Undefine sljit macros. */ | /* Undefine sljit macros. */ |
453 | #undef CMP | #undef CMP |
454 | ||
455 | /* Used for accessing the elements of the stack. */ | /* Used for accessing the elements of the stack. */ |
456 | #define STACK(i) ((-(i) - 1) * (int)sizeof(sljit_w)) | #define STACK(i) ((-(i) - 1) * (int)sizeof(sljit_sw)) |
457 | ||
458 | #define TMP1 SLJIT_TEMPORARY_REG1 | #define TMP1 SLJIT_SCRATCH_REG1 |
459 | #define TMP2 SLJIT_TEMPORARY_REG3 | #define TMP2 SLJIT_SCRATCH_REG3 |
460 | #define TMP3 SLJIT_TEMPORARY_EREG2 | #define TMP3 SLJIT_TEMPORARY_EREG2 |
461 | #define STR_PTR SLJIT_SAVED_REG1 | #define STR_PTR SLJIT_SAVED_REG1 |
462 | #define STR_END SLJIT_SAVED_REG2 | #define STR_END SLJIT_SAVED_REG2 |
463 | #define STACK_TOP SLJIT_TEMPORARY_REG2 | #define STACK_TOP SLJIT_SCRATCH_REG2 |
464 | #define STACK_LIMIT SLJIT_SAVED_REG3 | #define STACK_LIMIT SLJIT_SAVED_REG3 |
465 | #define ARGUMENTS SLJIT_SAVED_EREG1 | #define ARGUMENTS SLJIT_SAVED_EREG1 |
466 | #define CALL_COUNT SLJIT_SAVED_EREG2 | #define CALL_COUNT SLJIT_SAVED_EREG2 |
467 | #define RETURN_ADDR SLJIT_TEMPORARY_EREG1 | #define RETURN_ADDR SLJIT_TEMPORARY_EREG1 |
468 | ||
469 | /* Locals layout. */ | /* Local space layout. */ |
470 | /* These two locals can be used by the current opcode. */ | /* These two locals can be used by the current opcode. */ |
471 | #define LOCALS0 (0 * sizeof(sljit_w)) | #define LOCALS0 (0 * sizeof(sljit_sw)) |
472 | #define LOCALS1 (1 * sizeof(sljit_w)) | #define LOCALS1 (1 * sizeof(sljit_sw)) |
473 | /* Two local variables for possessive quantifiers (char1 cannot use them). */ | /* Two local variables for possessive quantifiers (char1 cannot use them). */ |
474 | #define POSSESSIVE0 (2 * sizeof(sljit_w)) | #define POSSESSIVE0 (2 * sizeof(sljit_sw)) |
475 | #define POSSESSIVE1 (3 * sizeof(sljit_w)) | #define POSSESSIVE1 (3 * sizeof(sljit_sw)) |
476 | /* Max limit of recursions. */ | /* Max limit of recursions. */ |
477 | #define CALL_LIMIT (4 * sizeof(sljit_w)) | #define CALL_LIMIT (4 * sizeof(sljit_sw)) |
478 | /* The output vector is stored on the stack, and contains pointers | /* The output vector is stored on the stack, and contains pointers |
479 | to characters. The vector data is divided into two groups: the first | to characters. The vector data is divided into two groups: the first |
480 | group contains the start / end character pointers, and the second is | group contains the start / end character pointers, and the second is |
481 | the start pointers when the end of the capturing group has not yet reached. */ | the start pointers when the end of the capturing group has not yet reached. */ |
482 | #define OVECTOR_START (common->ovector_start) | #define OVECTOR_START (common->ovector_start) |
483 | #define OVECTOR(i) (OVECTOR_START + (i) * sizeof(sljit_w)) | #define OVECTOR(i) (OVECTOR_START + (i) * sizeof(sljit_sw)) |
484 | #define OVECTOR_PRIV(i) (common->cbraptr + (i) * sizeof(sljit_w)) | #define OVECTOR_PRIV(i) (common->cbra_ptr + (i) * sizeof(sljit_sw)) |
485 | #define PRIV_DATA(cc) (common->localptrs[(cc) - common->start]) | #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start]) |
486 | ||
487 | #ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 |
488 | #define MOV_UCHAR SLJIT_MOV_UB | #define MOV_UCHAR SLJIT_MOV_UB |
489 | #define MOVU_UCHAR SLJIT_MOVU_UB | #define MOVU_UCHAR SLJIT_MOVU_UB |
490 | #else | #elif defined COMPILE_PCRE16 |
#ifdef COMPILE_PCRE16 | ||
491 | #define MOV_UCHAR SLJIT_MOV_UH | #define MOV_UCHAR SLJIT_MOV_UH |
492 | #define MOVU_UCHAR SLJIT_MOVU_UH | #define MOVU_UCHAR SLJIT_MOVU_UH |
493 | #elif defined COMPILE_PCRE32 | |
494 | #define MOV_UCHAR SLJIT_MOV_UI | |
495 | #define MOVU_UCHAR SLJIT_MOVU_UI | |
496 | #else | #else |
497 | #error Unsupported compiling mode | #error Unsupported compiling mode |
498 | #endif | #endif |
#endif | ||
499 | ||
500 | /* Shortcuts. */ | /* Shortcuts. */ |
501 | #define DEFINE_COMPILER \ | #define DEFINE_COMPILER \ |
# | Line 449 the start pointers when the end of the c | Line 512 the start pointers when the end of the c |
512 | sljit_set_label(sljit_emit_jump(compiler, (type)), (label)) | sljit_set_label(sljit_emit_jump(compiler, (type)), (label)) |
513 | #define JUMPHERE(jump) \ | #define JUMPHERE(jump) \ |
514 | sljit_set_label((jump), sljit_emit_label(compiler)) | sljit_set_label((jump), sljit_emit_label(compiler)) |
515 | #define SET_LABEL(jump, label) \ | |
516 | sljit_set_label((jump), (label)) | |
517 | #define CMP(type, src1, src1w, src2, src2w) \ | #define CMP(type, src1, src1w, src2, src2w) \ |
518 | sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)) | sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)) |
519 | #define CMPTO(type, src1, src1w, src2, src2w, label) \ | #define CMPTO(type, src1, src1w, src2, src2w, label) \ |
520 | sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label)) | sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label)) |
521 | #define COND_VALUE(op, dst, dstw, type) \ | #define OP_FLAGS(op, dst, dstw, src, srcw, type) \ |
522 | sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type)) | sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type)) |
523 | #define GET_LOCAL_BASE(dst, dstw, offset) \ | #define GET_LOCAL_BASE(dst, dstw, offset) \ |
524 | sljit_get_local_base(compiler, (dst), (dstw), (offset)) | sljit_get_local_base(compiler, (dst), (dstw), (offset)) |
525 | ||
# | Line 469 return cc; | Line 534 return cc; |
534 | ||
535 | /* Functions whose might need modification for all new supported opcodes: | /* Functions whose might need modification for all new supported opcodes: |
536 | next_opcode | next_opcode |
537 | get_localspace | check_opcode_types |
538 | set_localptrs | set_private_data_ptrs |
539 | get_framesize | get_framesize |
540 | init_frame | init_frame |
541 | get_localsize | get_private_data_copy_length |
542 | copy_locals | copy_private_data |
543 | compile_trypath | compile_matchingpath |
544 | compile_backtrackpath | compile_backtrackingpath |
545 | */ | */ |
546 | ||
547 | static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc) | static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc) |
# | Line 497 switch(*cc) | Line 562 switch(*cc) |
562 | case OP_WORDCHAR: | case OP_WORDCHAR: |
563 | case OP_ANY: | case OP_ANY: |
564 | case OP_ALLANY: | case OP_ALLANY: |
565 | case OP_NOTPROP: | |
566 | case OP_PROP: | |
567 | case OP_ANYNL: | case OP_ANYNL: |
568 | case OP_NOT_HSPACE: | case OP_NOT_HSPACE: |
569 | case OP_HSPACE: | case OP_HSPACE: |
# | Line 509 switch(*cc) | Line 576 switch(*cc) |
576 | case OP_CIRCM: | case OP_CIRCM: |
577 | case OP_DOLL: | case OP_DOLL: |
578 | case OP_DOLLM: | case OP_DOLLM: |
case OP_TYPESTAR: | ||
case OP_TYPEMINSTAR: | ||
case OP_TYPEPLUS: | ||
case OP_TYPEMINPLUS: | ||
case OP_TYPEQUERY: | ||
case OP_TYPEMINQUERY: | ||
case OP_TYPEPOSSTAR: | ||
case OP_TYPEPOSPLUS: | ||
case OP_TYPEPOSQUERY: | ||
579 | case OP_CRSTAR: | case OP_CRSTAR: |
580 | case OP_CRMINSTAR: | case OP_CRMINSTAR: |
581 | case OP_CRPLUS: | case OP_CRPLUS: |
582 | case OP_CRMINPLUS: | case OP_CRMINPLUS: |
583 | case OP_CRQUERY: | case OP_CRQUERY: |
584 | case OP_CRMINQUERY: | case OP_CRMINQUERY: |
585 | case OP_CRRANGE: | |
586 | case OP_CRMINRANGE: | |
587 | case OP_CLASS: | |
588 | case OP_NCLASS: | |
589 | case OP_REF: | |
590 | case OP_REFI: | |
591 | case OP_RECURSE: | |
592 | case OP_CALLOUT: | |
593 | case OP_ALT: | |
594 | case OP_KET: | |
595 | case OP_KETRMAX: | |
596 | case OP_KETRMIN: | |
597 | case OP_KETRPOS: | |
598 | case OP_REVERSE: | |
599 | case OP_ASSERT: | |
600 | case OP_ASSERT_NOT: | |
601 | case OP_ASSERTBACK: | |
602 | case OP_ASSERTBACK_NOT: | |
603 | case OP_ONCE: | |
604 | case OP_ONCE_NC: | |
605 | case OP_BRA: | |
606 | case OP_BRAPOS: | |
607 | case OP_CBRA: | |
608 | case OP_CBRAPOS: | |
609 | case OP_COND: | |
610 | case OP_SBRA: | |
611 | case OP_SBRAPOS: | |
612 | case OP_SCBRA: | |
613 | case OP_SCBRAPOS: | |
614 | case OP_SCOND: | |
615 | case OP_CREF: | |
616 | case OP_NCREF: | |
617 | case OP_RREF: | |
618 | case OP_NRREF: | |
619 | case OP_DEF: | case OP_DEF: |
620 | case OP_BRAZERO: | case OP_BRAZERO: |
621 | case OP_BRAMINZERO: | case OP_BRAMINZERO: |
622 | case OP_BRAPOSZERO: | case OP_BRAPOSZERO: |
623 | case OP_PRUNE: | |
624 | case OP_SKIP: | |
625 | case OP_THEN: | |
626 | case OP_COMMIT: | case OP_COMMIT: |
627 | case OP_FAIL: | case OP_FAIL: |
628 | case OP_ACCEPT: | case OP_ACCEPT: |
629 | case OP_ASSERT_ACCEPT: | case OP_ASSERT_ACCEPT: |
630 | case OP_CLOSE: | |
631 | case OP_SKIPZERO: | case OP_SKIPZERO: |
632 | return cc + 1; | return cc + PRIV(OP_lengths)[*cc]; |
case OP_ANYBYTE: | ||
#ifdef SUPPORT_UTF | ||
if (common->utf) return NULL; | ||
#endif | ||
return cc + 1; | ||
633 | ||
634 | case OP_CHAR: | case OP_CHAR: |
635 | case OP_CHARI: | case OP_CHARI: |
# | Line 551 switch(*cc) | Line 641 switch(*cc) |
641 | case OP_MINPLUS: | case OP_MINPLUS: |
642 | case OP_QUERY: | case OP_QUERY: |
643 | case OP_MINQUERY: | case OP_MINQUERY: |
644 | case OP_UPTO: | |
645 | case OP_MINUPTO: | |
646 | case OP_EXACT: | |
647 | case OP_POSSTAR: | case OP_POSSTAR: |
648 | case OP_POSPLUS: | case OP_POSPLUS: |
649 | case OP_POSQUERY: | case OP_POSQUERY: |
650 | case OP_POSUPTO: | |
651 | case OP_STARI: | case OP_STARI: |
652 | case OP_MINSTARI: | case OP_MINSTARI: |
653 | case OP_PLUSI: | case OP_PLUSI: |
654 | case OP_MINPLUSI: | case OP_MINPLUSI: |
655 | case OP_QUERYI: | case OP_QUERYI: |
656 | case OP_MINQUERYI: | case OP_MINQUERYI: |
657 | case OP_UPTOI: | |
658 | case OP_MINUPTOI: | |
659 | case OP_EXACTI: | |
660 | case OP_POSSTARI: | case OP_POSSTARI: |
661 | case OP_POSPLUSI: | case OP_POSPLUSI: |
662 | case OP_POSQUERYI: | case OP_POSQUERYI: |
663 | case OP_POSUPTOI: | |
664 | case OP_NOTSTAR: | case OP_NOTSTAR: |
665 | case OP_NOTMINSTAR: | case OP_NOTMINSTAR: |
666 | case OP_NOTPLUS: | case OP_NOTPLUS: |
667 | case OP_NOTMINPLUS: | case OP_NOTMINPLUS: |
668 | case OP_NOTQUERY: | case OP_NOTQUERY: |
669 | case OP_NOTMINQUERY: | case OP_NOTMINQUERY: |
670 | case OP_NOTUPTO: | |
671 | case OP_NOTMINUPTO: | |
672 | case OP_NOTEXACT: | |
673 | case OP_NOTPOSSTAR: | case OP_NOTPOSSTAR: |
674 | case OP_NOTPOSPLUS: | case OP_NOTPOSPLUS: |
675 | case OP_NOTPOSQUERY: | case OP_NOTPOSQUERY: |
676 | case OP_NOTPOSUPTO: | |
677 | case OP_NOTSTARI: | case OP_NOTSTARI: |
678 | case OP_NOTMINSTARI: | case OP_NOTMINSTARI: |
679 | case OP_NOTPLUSI: | case OP_NOTPLUSI: |
680 | case OP_NOTMINPLUSI: | case OP_NOTMINPLUSI: |
681 | case OP_NOTQUERYI: | case OP_NOTQUERYI: |
682 | case OP_NOTMINQUERYI: | case OP_NOTMINQUERYI: |
case OP_NOTPOSSTARI: | ||
case OP_NOTPOSPLUSI: | ||
case OP_NOTPOSQUERYI: | ||
cc += 2; | ||
#ifdef SUPPORT_UTF | ||
if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); | ||
#endif | ||
return cc; | ||
case OP_UPTO: | ||
case OP_MINUPTO: | ||
case OP_EXACT: | ||
case OP_POSUPTO: | ||
case OP_UPTOI: | ||
case OP_MINUPTOI: | ||
case OP_EXACTI: | ||
case OP_POSUPTOI: | ||
case OP_NOTUPTO: | ||
case OP_NOTMINUPTO: | ||
case OP_NOTEXACT: | ||
case OP_NOTPOSUPTO: | ||
683 | case OP_NOTUPTOI: | case OP_NOTUPTOI: |
684 | case OP_NOTMINUPTOI: | case OP_NOTMINUPTOI: |
685 | case OP_NOTEXACTI: | case OP_NOTEXACTI: |
686 | case OP_NOTPOSSTARI: | |
687 | case OP_NOTPOSPLUSI: | |
688 | case OP_NOTPOSQUERYI: | |
689 | case OP_NOTPOSUPTOI: | case OP_NOTPOSUPTOI: |
690 | cc += 2 + IMM2_SIZE; | cc += PRIV(OP_lengths)[*cc]; |
691 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
692 | if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); | if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); |
693 | #endif | #endif |
694 | return cc; | return cc; |
695 | ||
696 | case OP_NOTPROP: | /* Special cases. */ |
697 | case OP_PROP: | case OP_TYPESTAR: |
698 | return cc + 1 + 2; | case OP_TYPEMINSTAR: |
699 | case OP_TYPEPLUS: | |
700 | case OP_TYPEMINPLUS: | |
701 | case OP_TYPEQUERY: | |
702 | case OP_TYPEMINQUERY: | |
703 | case OP_TYPEUPTO: | case OP_TYPEUPTO: |
704 | case OP_TYPEMINUPTO: | case OP_TYPEMINUPTO: |
705 | case OP_TYPEEXACT: | case OP_TYPEEXACT: |
706 | case OP_TYPEPOSSTAR: | |
707 | case OP_TYPEPOSPLUS: | |
708 | case OP_TYPEPOSQUERY: | |
709 | case OP_TYPEPOSUPTO: | case OP_TYPEPOSUPTO: |
710 | case OP_REF: | return cc + PRIV(OP_lengths)[*cc] - 1; |
case OP_REFI: | ||
case OP_CREF: | ||
case OP_NCREF: | ||
case OP_RREF: | ||
case OP_NRREF: | ||
case OP_CLOSE: | ||
cc += 1 + IMM2_SIZE; | ||
return cc; | ||
711 | ||
712 | case OP_CRRANGE: | case OP_ANYBYTE: |
713 | case OP_CRMINRANGE: | #ifdef SUPPORT_UTF |
714 | return cc + 1 + 2 * IMM2_SIZE; | if (common->utf) return NULL; |
715 | #endif | |
716 | case OP_CLASS: | return cc + 1; |
case OP_NCLASS: | ||
return cc + 1 + 32 / sizeof(pcre_uchar); | ||
717 | ||
718 | #if defined SUPPORT_UTF || !defined COMPILE_PCRE8 | #if defined SUPPORT_UTF || !defined COMPILE_PCRE8 |
719 | case OP_XCLASS: | case OP_XCLASS: |
720 | return cc + GET(cc, 1); | return cc + GET(cc, 1); |
721 | #endif | #endif |
722 | ||
case OP_RECURSE: | ||
case OP_ASSERT: | ||
case OP_ASSERT_NOT: | ||
case OP_ASSERTBACK: | ||
case OP_ASSERTBACK_NOT: | ||
case OP_REVERSE: | ||
case OP_ONCE: | ||
case OP_ONCE_NC: | ||
case OP_BRA: | ||
case OP_BRAPOS: | ||
case OP_COND: | ||
case OP_SBRA: | ||
case OP_SBRAPOS: | ||
case OP_SCOND: | ||
case OP_ALT: | ||
case OP_KET: | ||
case OP_KETRMAX: | ||
case OP_KETRMIN: | ||
case OP_KETRPOS: | ||
return cc + 1 + LINK_SIZE; | ||
case OP_CBRA: | ||
case OP_CBRAPOS: | ||
case OP_SCBRA: | ||
case OP_SCBRAPOS: | ||
return cc + 1 + LINK_SIZE + IMM2_SIZE; | ||
723 | case OP_MARK: | case OP_MARK: |
724 | case OP_PRUNE_ARG: | |
725 | case OP_SKIP_ARG: | |
726 | case OP_THEN_ARG: | |
727 | return cc + 1 + 2 + cc[1]; | return cc + 1 + 2 + cc[1]; |
728 | ||
729 | default: | default: |
730 | /* All opcodes are supported now! */ | |
731 | SLJIT_ASSERT_STOP(); | |
732 | return NULL; | return NULL; |
733 | } | } |
734 | } | } |
735 | ||
736 | #define CASE_ITERATOR_LOCAL1 \ | static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend) |
case OP_MINSTAR: \ | ||
case OP_MINPLUS: \ | ||
case OP_QUERY: \ | ||
case OP_MINQUERY: \ | ||
case OP_MINSTARI: \ | ||
case OP_MINPLUSI: \ | ||
case OP_QUERYI: \ | ||
case OP_MINQUERYI: \ | ||
case OP_NOTMINSTAR: \ | ||
case OP_NOTMINPLUS: \ | ||
case OP_NOTQUERY: \ | ||
case OP_NOTMINQUERY: \ | ||
case OP_NOTMINSTARI: \ | ||
case OP_NOTMINPLUSI: \ | ||
case OP_NOTQUERYI: \ | ||
case OP_NOTMINQUERYI: | ||
#define CASE_ITERATOR_LOCAL2A \ | ||
case OP_STAR: \ | ||
case OP_PLUS: \ | ||
case OP_STARI: \ | ||
case OP_PLUSI: \ | ||
case OP_NOTSTAR: \ | ||
case OP_NOTPLUS: \ | ||
case OP_NOTSTARI: \ | ||
case OP_NOTPLUSI: | ||
#define CASE_ITERATOR_LOCAL2B \ | ||
case OP_UPTO: \ | ||
case OP_MINUPTO: \ | ||
case OP_UPTOI: \ | ||
case OP_MINUPTOI: \ | ||
case OP_NOTUPTO: \ | ||
case OP_NOTMINUPTO: \ | ||
case OP_NOTUPTOI: \ | ||
case OP_NOTMINUPTOI: | ||
#define CASE_ITERATOR_TYPE_LOCAL1 \ | ||
case OP_TYPEMINSTAR: \ | ||
case OP_TYPEMINPLUS: \ | ||
case OP_TYPEQUERY: \ | ||
case OP_TYPEMINQUERY: | ||
#define CASE_ITERATOR_TYPE_LOCAL2A \ | ||
case OP_TYPESTAR: \ | ||
case OP_TYPEPLUS: | ||
#define CASE_ITERATOR_TYPE_LOCAL2B \ | ||
case OP_TYPEUPTO: \ | ||
case OP_TYPEMINUPTO: | ||
static int get_class_iterator_size(pcre_uchar *cc) | ||
{ | ||
switch(*cc) | ||
{ | ||
case OP_CRSTAR: | ||
case OP_CRPLUS: | ||
return 2; | ||
case OP_CRMINSTAR: | ||
case OP_CRMINPLUS: | ||
case OP_CRQUERY: | ||
case OP_CRMINQUERY: | ||
return 1; | ||
case OP_CRRANGE: | ||
case OP_CRMINRANGE: | ||
if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE)) | ||
return 0; | ||
return 2; | ||
default: | ||
return 0; | ||
} | ||
} | ||
static int get_localspace(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend) | ||
737 | { | { |
738 | int localspace = 0; | pcre_uchar *name; |
739 | pcre_uchar *alternative; | pcre_uchar *name2; |
740 | pcre_uchar *end = NULL; | int i, cbra_index; |
int space, size, bracketlen; | ||
741 | ||
742 | /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */ | /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */ |
743 | while (cc < ccend) | while (cc < ccend) |
744 | { | { |
space = 0; | ||
size = 0; | ||
bracketlen = 0; | ||
745 | switch(*cc) | switch(*cc) |
746 | { | { |
747 | case OP_SET_SOM: | case OP_SET_SOM: |
# | Line 772 while (cc < ccend) | Line 749 while (cc < ccend) |
749 | cc += 1; | cc += 1; |
750 | break; | break; |
751 | ||
752 | case OP_ASSERT: | case OP_REF: |
753 | case OP_ASSERT_NOT: | case OP_REFI: |
754 | case OP_ASSERTBACK: | common->optimized_cbracket[GET2(cc, 1)] = 0; |
755 | case OP_ASSERTBACK_NOT: | cc += 1 + IMM2_SIZE; |
case OP_ONCE: | ||
case OP_ONCE_NC: | ||
case OP_BRAPOS: | ||
case OP_SBRA: | ||
case OP_SBRAPOS: | ||
case OP_SCOND: | ||
localspace += sizeof(sljit_w); | ||
bracketlen = 1 + LINK_SIZE; | ||
756 | break; | break; |
757 | ||
758 | case OP_CBRAPOS: | case OP_CBRAPOS: |
759 | case OP_SCBRAPOS: | case OP_SCBRAPOS: |
760 | localspace += sizeof(sljit_w); | common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0; |
761 | bracketlen = 1 + LINK_SIZE + IMM2_SIZE; | cc += 1 + LINK_SIZE + IMM2_SIZE; |
762 | break; | break; |
763 | ||
764 | case OP_COND: | case OP_COND: |
765 | /* Might be a hidden SCOND. */ | case OP_SCOND: |
766 | alternative = cc + GET(cc, 1); | /* Only AUTO_CALLOUT can insert this opcode. We do |
767 | if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN) | not intend to support this case. */ |
768 | localspace += sizeof(sljit_w); | if (cc[1 + LINK_SIZE] == OP_CALLOUT) |
769 | bracketlen = 1 + LINK_SIZE; | return FALSE; |
770 | break; | cc += 1 + LINK_SIZE; |
case OP_BRA: | ||
bracketlen = 1 + LINK_SIZE; | ||
break; | ||
case OP_CBRA: | ||
case OP_SCBRA: | ||
bracketlen = 1 + LINK_SIZE + IMM2_SIZE; | ||
break; | ||
CASE_ITERATOR_LOCAL1 | ||
space = 1; | ||
size = -2; | ||
break; | ||
CASE_ITERATOR_LOCAL2A | ||
space = 2; | ||
size = -2; | ||
break; | ||
CASE_ITERATOR_LOCAL2B | ||
space = 2; | ||
size = -(2 + IMM2_SIZE); | ||
break; | ||
CASE_ITERATOR_TYPE_LOCAL1 | ||
space = 1; | ||
size = 1; | ||
break; | ||
CASE_ITERATOR_TYPE_LOCAL2A | ||
if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI) | ||
space = 2; | ||
size = 1; | ||
break; | ||
CASE_ITERATOR_TYPE_LOCAL2B | ||
if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI) | ||
space = 2; | ||
size = 1 + IMM2_SIZE; | ||
771 | break; | break; |
772 | ||
773 | case OP_CLASS: | case OP_CREF: |
774 | case OP_NCLASS: | i = GET2(cc, 1); |
775 | size += 1 + 32 / sizeof(pcre_uchar); | common->optimized_cbracket[i] = 0; |
776 | space = get_class_iterator_size(cc + size); | cc += 1 + IMM2_SIZE; |
777 | break; | break; |
778 | ||
779 | #if defined SUPPORT_UTF || !defined COMPILE_PCRE8 | case OP_NCREF: |
780 | case OP_XCLASS: | cbra_index = GET2(cc, 1); |
781 | size = GET(cc, 1); | name = (pcre_uchar *)common->name_table; |
782 | space = get_class_iterator_size(cc + size); | name2 = name; |
783 | for (i = 0; i < common->name_count; i++) | |
784 | { | |
785 | if (GET2(name, 0) == cbra_index) break; | |
786 | name += common->name_entry_size; | |
787 | } | |
788 | SLJIT_ASSERT(i != common->name_count); | |
789 | ||
790 | for (i = 0; i < common->name_count; i++) | |
791 | { | |
792 | if (STRCMP_UC_UC(name2 + IMM2_SIZE, name + IMM2_SIZE) == 0) | |
793 | common->optimized_cbracket[GET2(name2, 0)] = 0; | |
794 | name2 += common->name_entry_size; | |
795 | } | |
796 | cc += 1 + IMM2_SIZE; | |
797 | break; | break; |
#endif | ||
798 | ||
799 | case OP_RECURSE: | case OP_RECURSE: |
800 | /* Set its value only once. */ | /* Set its value only once. */ |
801 | if (common->recursive_head == 0) | if (common->recursive_head_ptr == 0) |
802 | { | { |
803 | common->recursive_head = common->ovector_start; | common->recursive_head_ptr = common->ovector_start; |
804 | common->ovector_start += sizeof(sljit_w); | common->ovector_start += sizeof(sljit_sw); |
805 | } | } |
806 | cc += 1 + LINK_SIZE; | cc += 1 + LINK_SIZE; |
807 | break; | break; |
808 | ||
809 | case OP_CALLOUT: | |
810 | if (common->capture_last_ptr == 0) | |
811 | { | |
812 | common->capture_last_ptr = common->ovector_start; | |
813 | common->ovector_start += sizeof(sljit_sw); | |
814 | } | |
815 | cc += 2 + 2 * LINK_SIZE; | |
816 | break; | |
817 | ||
818 | case OP_THEN_ARG: | |
819 | common->has_then = TRUE; | |
820 | common->control_head_ptr = 1; | |
821 | /* Fall through. */ | |
822 | ||
823 | case OP_PRUNE_ARG: | |
824 | common->needs_start_ptr = TRUE; | |
825 | /* Fall through. */ | |
826 | ||
827 | case OP_MARK: | case OP_MARK: |
828 | if (common->mark_ptr == 0) | if (common->mark_ptr == 0) |
829 | { | { |
830 | common->mark_ptr = common->ovector_start; | common->mark_ptr = common->ovector_start; |
831 | common->ovector_start += sizeof(sljit_w); | common->ovector_start += sizeof(sljit_sw); |
832 | } | } |
833 | cc += 1 + 2 + cc[1]; | cc += 1 + 2 + cc[1]; |
834 | break; | break; |
835 | ||
836 | case OP_THEN: | |
837 | common->has_then = TRUE; | |
838 | common->control_head_ptr = 1; | |
839 | /* Fall through. */ | |
840 | ||
841 | case OP_PRUNE: | |
842 | case OP_SKIP: | |
843 | common->needs_start_ptr = TRUE; | |
844 | cc += 1; | |
845 | break; | |
846 | ||
847 | case OP_SKIP_ARG: | |
848 | common->control_head_ptr = 1; | |
849 | common->has_skip_arg = TRUE; | |
850 | cc += 1 + 2 + cc[1]; | |
851 | break; | |
852 | ||
853 | default: | default: |
854 | cc = next_opcode(common, cc); | cc = next_opcode(common, cc); |
855 | if (cc == NULL) | if (cc == NULL) |
856 | return -1; | return FALSE; |
857 | break; | break; |
858 | } | } |
859 | } | |
860 | return TRUE; | |
861 | } | |
862 | ||
863 | if (space > 0 && cc >= end) | static int get_class_iterator_size(pcre_uchar *cc) |
864 | localspace += sizeof(sljit_w) * space; | { |
865 | switch(*cc) | |
866 | { | |
867 | case OP_CRSTAR: | |
868 | case OP_CRPLUS: | |
869 | return 2; | |
870 | ||
871 | if (size != 0) | case OP_CRMINSTAR: |
872 | case OP_CRMINPLUS: | |
873 | case OP_CRQUERY: | |
874 | case OP_CRMINQUERY: | |
875 | return 1; | |
876 | ||
877 | case OP_CRRANGE: | |
878 | case OP_CRMINRANGE: | |
879 | if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE)) | |
880 | return 0; | |
881 | return 2; | |
882 | ||
883 | default: | |
884 | return 0; | |
885 | } | |
886 | } | |
887 | ||
888 | static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin) | |
889 | { | |
890 | pcre_uchar *end = bracketend(begin); | |
891 | pcre_uchar *next; | |
892 | pcre_uchar *next_end; | |
893 | pcre_uchar *max_end; | |
894 | pcre_uchar type; | |
895 | sljit_uw length = end - begin; | |
896 | int min, max, i; | |
897 | ||
898 | /* Detect fixed iterations first. */ | |
899 | if (end[-(1 + LINK_SIZE)] != OP_KET) | |
900 | return FALSE; | |
901 | ||
902 | /* Already detected repeat. */ | |
903 | if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0) | |
904 | return TRUE; | |
905 | ||
906 | next = end; | |
907 | min = 1; | |
908 | while (1) | |
909 | { | |
910 | if (*next != *begin) | |
911 | break; | |
912 | next_end = bracketend(next); | |
913 | if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0) | |
914 | break; | |
915 | next = next_end; | |
916 | min++; | |
917 | } | |
918 | ||
919 | if (min == 2) | |
920 | return FALSE; | |
921 | ||
922 | max = 0; | |
923 | max_end = next; | |
924 | if (*next == OP_BRAZERO || *next == OP_BRAMINZERO) | |
925 | { | |
926 | type = *next; | |
927 | while (1) | |
928 | { | { |
929 | if (size < 0) | if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin) |
930 | break; | |
931 | next_end = bracketend(next + 2 + LINK_SIZE); | |
932 | if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0) | |
933 | break; | |
934 | next = next_end; | |
935 | max++; | |
936 | } | |
937 | ||
938 | if (next[0] == type && next[1] == *begin && max >= 1) | |
939 | { | |
940 | next_end = bracketend(next + 1); | |
941 | if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0) | |
942 | { | { |
943 | cc += -size; | for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE) |
944 | #ifdef SUPPORT_UTF | if (*next_end != OP_KET) |
945 | if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); | break; |
946 | #endif | |
947 | if (i == max) | |
948 | { | |
949 | common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end; | |
950 | common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO; | |
951 | /* +2 the original and the last. */ | |
952 | common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2; | |
953 | if (min == 1) | |
954 | return TRUE; | |
955 | min--; | |
956 | max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE); | |
957 | } | |
958 | } | } |
else | ||
cc += size; | ||
959 | } | } |
960 | } | |
961 | ||
962 | if (min >= 3) | |
963 | { | |
964 | common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end; | |
965 | common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT; | |
966 | common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min; | |
967 | return TRUE; | |
968 | } | |
969 | ||
970 | return FALSE; | |
971 | } | |
972 | ||
973 | #define CASE_ITERATOR_PRIVATE_DATA_1 \ | |
974 | case OP_MINSTAR: \ | |
975 | case OP_MINPLUS: \ | |
976 | case OP_QUERY: \ | |
977 | case OP_MINQUERY: \ | |
978 | case OP_MINSTARI: \ | |
979 | case OP_MINPLUSI: \ | |
980 | case OP_QUERYI: \ | |
981 | case OP_MINQUERYI: \ | |
982 | case OP_NOTMINSTAR: \ | |
983 | case OP_NOTMINPLUS: \ | |
984 | case OP_NOTQUERY: \ | |
985 | case OP_NOTMINQUERY: \ | |
986 | case OP_NOTMINSTARI: \ | |
987 | case OP_NOTMINPLUSI: \ | |
988 | case OP_NOTQUERYI: \ | |
989 | case OP_NOTMINQUERYI: | |
990 | ||
991 | #define CASE_ITERATOR_PRIVATE_DATA_2A \ | |
992 | case OP_STAR: \ | |
993 | case OP_PLUS: \ | |
994 | case OP_STARI: \ | |
995 | case OP_PLUSI: \ | |
996 | case OP_NOTSTAR: \ | |
997 | case OP_NOTPLUS: \ | |
998 | case OP_NOTSTARI: \ | |
999 | case OP_NOTPLUSI: | |
1000 | ||
1001 | #define CASE_ITERATOR_PRIVATE_DATA_2B \ | |
1002 | case OP_UPTO: \ | |
1003 | case OP_MINUPTO: \ | |
1004 | case OP_UPTOI: \ | |
1005 | case OP_MINUPTOI: \ | |
1006 | case OP_NOTUPTO: \ | |
1007 | case OP_NOTMINUPTO: \ | |
1008 | case OP_NOTUPTOI: \ | |
1009 | case OP_NOTMINUPTOI: | |
1010 | ||
1011 | #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \ | |
1012 | case OP_TYPEMINSTAR: \ | |
1013 | case OP_TYPEMINPLUS: \ | |
1014 | case OP_TYPEQUERY: \ | |
1015 | case OP_TYPEMINQUERY: | |
1016 | ||
1017 | if (bracketlen > 0) | #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \ |
1018 | { | case OP_TYPESTAR: \ |
1019 | if (cc >= end) | case OP_TYPEPLUS: |
1020 | { | |
1021 | end = bracketend(cc); | #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \ |
1022 | if (end[-1 - LINK_SIZE] == OP_KET) | case OP_TYPEUPTO: \ |
1023 | end = NULL; | case OP_TYPEMINUPTO: |
} | ||
cc += bracketlen; | ||
} | ||
} | ||
return localspace; | ||
} | ||
1024 | ||
1025 | static void set_localptrs(compiler_common *common, int localptr, pcre_uchar *ccend) | static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend) |
1026 | { | { |
1027 | pcre_uchar *cc = common->start; | pcre_uchar *cc = common->start; |
1028 | pcre_uchar *alternative; | pcre_uchar *alternative; |
1029 | pcre_uchar *end = NULL; | pcre_uchar *end = NULL; |
1030 | int private_data_ptr = *private_data_start; | |
1031 | int space, size, bracketlen; | int space, size, bracketlen; |
1032 | ||
1033 | while (cc < ccend) | while (cc < ccend) |
# | Line 922 while (cc < ccend) | Line 1035 while (cc < ccend) |
1035 | space = 0; | space = 0; |
1036 | size = 0; | size = 0; |
1037 | bracketlen = 0; | bracketlen = 0; |
1038 | if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE) | |
1039 | return; | |
1040 | ||
1041 | if (*cc == OP_BRA || *cc == OP_CBRA || *cc == OP_ONCE || *cc == OP_ONCE_NC) | |
1042 | if (detect_repeat(common, cc)) | |
1043 | { | |
1044 | /* These brackets are converted to repeats, so no global | |
1045 | based single character repeat is allowed. */ | |
1046 | if (cc >= end) | |
1047 | end = bracketend(cc); | |
1048 | } | |
1049 | ||
1050 | switch(*cc) | switch(*cc) |
1051 | { | { |
1052 | case OP_KET: | |
1053 | if (common->private_data_ptrs[cc + 1 - common->start] != 0) | |
1054 | { | |
1055 | common->private_data_ptrs[cc - common->start] = private_data_ptr; | |
1056 | private_data_ptr += sizeof(sljit_sw); | |
1057 | cc += common->private_data_ptrs[cc + 1 - common->start]; | |
1058 | } | |
1059 | cc += 1 + LINK_SIZE; | |
1060 | break; | |
1061 | ||
1062 | case OP_ASSERT: | case OP_ASSERT: |
1063 | case OP_ASSERT_NOT: | case OP_ASSERT_NOT: |
1064 | case OP_ASSERTBACK: | case OP_ASSERTBACK: |
# | Line 934 while (cc < ccend) | Line 1069 while (cc < ccend) |
1069 | case OP_SBRA: | case OP_SBRA: |
1070 | case OP_SBRAPOS: | case OP_SBRAPOS: |
1071 | case OP_SCOND: | case OP_SCOND: |
1072 | common->localptrs[cc - common->start] = localptr; | common->private_data_ptrs[cc - common->start] = private_data_ptr; |
1073 | localptr += sizeof(sljit_w); | private_data_ptr += sizeof(sljit_sw); |
1074 | bracketlen = 1 + LINK_SIZE; | bracketlen = 1 + LINK_SIZE; |
1075 | break; | break; |
1076 | ||
1077 | case OP_CBRAPOS: | case OP_CBRAPOS: |
1078 | case OP_SCBRAPOS: | case OP_SCBRAPOS: |
1079 | common->localptrs[cc - common->start] = localptr; | common->private_data_ptrs[cc - common->start] = private_data_ptr; |
1080 | localptr += sizeof(sljit_w); | private_data_ptr += sizeof(sljit_sw); |
1081 | bracketlen = 1 + LINK_SIZE + IMM2_SIZE; | bracketlen = 1 + LINK_SIZE + IMM2_SIZE; |
1082 | break; | break; |
1083 | ||
# | Line 951 while (cc < ccend) | Line 1086 while (cc < ccend) |
1086 | alternative = cc + GET(cc, 1); | alternative = cc + GET(cc, 1); |
1087 | if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN) | if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN) |
1088 | { | { |
1089 | common->localptrs[cc - common->start] = localptr; | common->private_data_ptrs[cc - common->start] = private_data_ptr; |
1090 | localptr += sizeof(sljit_w); | private_data_ptr += sizeof(sljit_sw); |
1091 | } | } |
1092 | bracketlen = 1 + LINK_SIZE; | bracketlen = 1 + LINK_SIZE; |
1093 | break; | break; |
# | Line 966 while (cc < ccend) | Line 1101 while (cc < ccend) |
1101 | bracketlen = 1 + LINK_SIZE + IMM2_SIZE; | bracketlen = 1 + LINK_SIZE + IMM2_SIZE; |
1102 | break; | break; |
1103 | ||
1104 | CASE_ITERATOR_LOCAL1 | CASE_ITERATOR_PRIVATE_DATA_1 |
1105 | space = 1; | space = 1; |
1106 | size = -2; | size = -2; |
1107 | break; | break; |
1108 | ||
1109 | CASE_ITERATOR_LOCAL2A | CASE_ITERATOR_PRIVATE_DATA_2A |
1110 | space = 2; | space = 2; |
1111 | size = -2; | size = -2; |
1112 | break; | break; |
1113 | ||
1114 | CASE_ITERATOR_LOCAL2B | CASE_ITERATOR_PRIVATE_DATA_2B |
1115 | space = 2; | space = 2; |
1116 | size = -(2 + IMM2_SIZE); | size = -(2 + IMM2_SIZE); |
1117 | break; | break; |
1118 | ||
1119 | CASE_ITERATOR_TYPE_LOCAL1 | CASE_ITERATOR_TYPE_PRIVATE_DATA_1 |
1120 | space = 1; | space = 1; |
1121 | size = 1; | size = 1; |
1122 | break; | break; |
1123 | ||
1124 | CASE_ITERATOR_TYPE_LOCAL2A | CASE_ITERATOR_TYPE_PRIVATE_DATA_2A |
1125 | if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI) | if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI) |
1126 | space = 2; | space = 2; |
1127 | size = 1; | size = 1; |
1128 | break; | break; |
1129 | ||
1130 | CASE_ITERATOR_TYPE_LOCAL2B | CASE_ITERATOR_TYPE_PRIVATE_DATA_2B |
1131 | if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI) | if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI) |
1132 | space = 2; | space = 2; |
1133 | size = 1 + IMM2_SIZE; | size = 1 + IMM2_SIZE; |
# | Line 1017 while (cc < ccend) | Line 1152 while (cc < ccend) |
1152 | break; | break; |
1153 | } | } |
1154 | ||
1155 | /* Character iterators, which are not inside a repeated bracket, | |
1156 | gets a private slot instead of allocating it on the stack. */ | |
1157 | if (space > 0 && cc >= end) | if (space > 0 && cc >= end) |
1158 | { | { |
1159 | common->localptrs[cc - common->start] = localptr; | common->private_data_ptrs[cc - common->start] = private_data_ptr; |
1160 | localptr += sizeof(sljit_w) * space; | private_data_ptr += sizeof(sljit_sw) * space; |
1161 | } | } |
1162 | ||
1163 | if (size != 0) | if (size != 0) |
# | Line 1047 while (cc < ccend) | Line 1184 while (cc < ccend) |
1184 | cc += bracketlen; | cc += bracketlen; |
1185 | } | } |
1186 | } | } |
1187 | *private_data_start = private_data_ptr; | |
1188 | } | } |
1189 | ||
1190 | /* Returns with -1 if no need for frame. */ | /* Returns with a frame_types (always < 0) if no need for frame. */ |
1191 | static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive) | static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL* needs_control_head) |
1192 | { | { |
pcre_uchar *ccend = bracketend(cc); | ||
1193 | int length = 0; | int length = 0; |
1194 | BOOL possessive = FALSE; | int possessive = 0; |
1195 | BOOL stack_restore = FALSE; | |
1196 | BOOL setsom_found = recursive; | BOOL setsom_found = recursive; |
1197 | BOOL setmark_found = recursive; | BOOL setmark_found = recursive; |
1198 | /* The last capture is a local variable even for recursions. */ | |
1199 | BOOL capture_last_found = FALSE; | |
1200 | ||
1201 | if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS)) | #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD |
1202 | SLJIT_ASSERT(common->control_head_ptr != 0); | |
1203 | *needs_control_head = TRUE; | |
1204 | #else | |
1205 | *needs_control_head = FALSE; | |
1206 | #endif | |
1207 | ||
1208 | if (ccend == NULL) | |
1209 | { | { |
1210 | length = 3; | ccend = bracketend(cc) - (1 + LINK_SIZE); |
1211 | possessive = TRUE; | if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS)) |
1212 | { | |
1213 | possessive = length = (common->capture_last_ptr != 0) ? 5 : 3; | |
1214 | /* This is correct regardless of common->capture_last_ptr. */ | |
1215 | capture_last_found = TRUE; | |
1216 | } | |
1217 | cc = next_opcode(common, cc); | |
1218 | } | } |
1219 | ||
cc = next_opcode(common, cc); | ||
1220 | SLJIT_ASSERT(cc != NULL); | SLJIT_ASSERT(cc != NULL); |
1221 | while (cc < ccend) | while (cc < ccend) |
1222 | switch(*cc) | switch(*cc) |
1223 | { | { |
1224 | case OP_SET_SOM: | case OP_SET_SOM: |
1225 | SLJIT_ASSERT(common->has_set_som); | SLJIT_ASSERT(common->has_set_som); |
1226 | stack_restore = TRUE; | |
1227 | if (!setsom_found) | if (!setsom_found) |
1228 | { | { |
1229 | length += 2; | length += 2; |
# | Line 1080 while (cc < ccend) | Line 1233 while (cc < ccend) |
1233 | break; | break; |
1234 | ||
1235 | case OP_MARK: | case OP_MARK: |
1236 | case OP_PRUNE_ARG: | |
1237 | case OP_THEN_ARG: | |
1238 | SLJIT_ASSERT(common->mark_ptr != 0); | SLJIT_ASSERT(common->mark_ptr != 0); |
1239 | stack_restore = TRUE; | |
1240 | if (!setmark_found) | if (!setmark_found) |
1241 | { | { |
1242 | length += 2; | length += 2; |
1243 | setmark_found = TRUE; | setmark_found = TRUE; |
1244 | } | } |
1245 | if (common->control_head_ptr != 0) | |
1246 | *needs_control_head = TRUE; | |
1247 | cc += 1 + 2 + cc[1]; | cc += 1 + 2 + cc[1]; |
1248 | break; | break; |
1249 | ||
1250 | case OP_RECURSE: | case OP_RECURSE: |
1251 | stack_restore = TRUE; | |
1252 | if (common->has_set_som && !setsom_found) | if (common->has_set_som && !setsom_found) |
1253 | { | { |
1254 | length += 2; | length += 2; |
# | Line 1100 while (cc < ccend) | Line 1259 while (cc < ccend) |
1259 | length += 2; | length += 2; |
1260 | setmark_found = TRUE; | setmark_found = TRUE; |
1261 | } | } |
1262 | if (common->capture_last_ptr != 0 && !capture_last_found) | |
1263 | { | |
1264 | length += 2; | |
1265 | capture_last_found = TRUE; | |
1266 | } | |
1267 | cc += 1 + LINK_SIZE; | cc += 1 + LINK_SIZE; |
1268 | break; | break; |
1269 | ||
# | Line 1107 while (cc < ccend) | Line 1271 while (cc < ccend) |
1271 | case OP_CBRAPOS: | case OP_CBRAPOS: |
1272 | case OP_SCBRA: | case OP_SCBRA: |
1273 | case OP_SCBRAPOS: | case OP_SCBRAPOS: |
1274 | stack_restore = TRUE; | |
1275 | if (common->capture_last_ptr != 0 && !capture_last_found) | |
1276 | { | |
1277 | length += 2; | |
1278 | capture_last_found = TRUE; | |
1279 | } | |
1280 | length += 3; | length += 3; |
1281 | cc += 1 + LINK_SIZE + IMM2_SIZE; | cc += 1 + LINK_SIZE + IMM2_SIZE; |
1282 | break; | break; |
1283 | ||
1284 | default: | default: |
1285 | stack_restore = TRUE; | |
1286 | /* Fall through. */ | |
1287 | ||
1288 | case OP_NOT_WORD_BOUNDARY: | |
1289 | case OP_WORD_BOUNDARY: | |
1290 | case OP_NOT_DIGIT: | |
1291 | case OP_DIGIT: | |
1292 | case OP_NOT_WHITESPACE: | |
1293 | case OP_WHITESPACE: | |
1294 | case OP_NOT_WORDCHAR: | |
1295 | case OP_WORDCHAR: | |
1296 | case OP_ANY: | |
1297 | case OP_ALLANY: | |
1298 | case OP_ANYBYTE: | |
1299 | case OP_NOTPROP: | |
1300 | case OP_PROP: | |
1301 | case OP_ANYNL: | |
1302 | case OP_NOT_HSPACE: | |
1303 | case OP_HSPACE: | |
1304 | case OP_NOT_VSPACE: | |
1305 | case OP_VSPACE: | |
1306 | case OP_EXTUNI: | |
1307 | case OP_EODN: | |
1308 | case OP_EOD: | |
1309 | case OP_CIRC: | |
1310 | case OP_CIRCM: | |
1311 | case OP_DOLL: | |
1312 | case OP_DOLLM: | |
1313 | case OP_CHAR: | |
1314 | case OP_CHARI: | |
1315 | case OP_NOT: | |
1316 | case OP_NOTI: | |
1317 | ||
1318 | case OP_EXACT: | |
1319 | case OP_POSSTAR: | |
1320 | case OP_POSPLUS: | |
1321 | case OP_POSQUERY: | |
1322 | case OP_POSUPTO: | |
1323 | ||
1324 | case OP_EXACTI: | |
1325 | case OP_POSSTARI: | |
1326 | case OP_POSPLUSI: | |
1327 | case OP_POSQUERYI: | |
1328 | case OP_POSUPTOI: | |
1329 | ||
1330 | case OP_NOTEXACT: | |
1331 | case OP_NOTPOSSTAR: | |
1332 | case OP_NOTPOSPLUS: | |
1333 | case OP_NOTPOSQUERY: | |
1334 | case OP_NOTPOSUPTO: | |
1335 | ||
1336 | case OP_NOTEXACTI: | |
1337 | case OP_NOTPOSSTARI: | |
1338 | case OP_NOTPOSPLUSI: | |
1339 | case OP_NOTPOSQUERYI: | |
1340 | case OP_NOTPOSUPTOI: | |
1341 | ||
1342 | case OP_TYPEEXACT: | |
1343 | case OP_TYPEPOSSTAR: | |
1344 | case OP_TYPEPOSPLUS: | |
1345 | case OP_TYPEPOSQUERY: | |
1346 | case OP_TYPEPOSUPTO: | |
1347 | ||
1348 | case OP_CLASS: | |
1349 | case OP_NCLASS: | |
1350 | case OP_XCLASS: | |
1351 | ||
1352 | cc = next_opcode(common, cc); | cc = next_opcode(common, cc); |
1353 | SLJIT_ASSERT(cc != NULL); | SLJIT_ASSERT(cc != NULL); |
1354 | break; | break; |
1355 | } | } |
1356 | ||
1357 | /* Possessive quantifiers can use a special case. */ | /* Possessive quantifiers can use a special case. */ |
1358 | if (SLJIT_UNLIKELY(possessive) && length == 3) | if (SLJIT_UNLIKELY(possessive == length)) |
1359 | return -1; | return stack_restore ? no_frame : no_stack; |
1360 | ||
1361 | if (length > 0) | if (length > 0) |
1362 | return length + 1; | return length + 1; |
1363 | return -1; | return stack_restore ? no_frame : no_stack; |
1364 | } | } |
1365 | ||
1366 | static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive) | static void init_frame(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, int stackpos, int stacktop, BOOL recursive) |
1367 | { | { |
1368 | DEFINE_COMPILER; | DEFINE_COMPILER; |
pcre_uchar *ccend = bracketend(cc); | ||
1369 | BOOL setsom_found = recursive; | BOOL setsom_found = recursive; |
1370 | BOOL setmark_found = recursive; | BOOL setmark_found = recursive; |
1371 | /* The last capture is a local variable even for recursions. */ | |
1372 | BOOL capture_last_found = FALSE; | |
1373 | int offset; | int offset; |
1374 | ||
1375 | /* >= 1 + shortest item size (2) */ | /* >= 1 + shortest item size (2) */ |
# | Line 1139 SLJIT_UNUSED_ARG(stacktop); | Line 1377 SLJIT_UNUSED_ARG(stacktop); |
1377 | SLJIT_ASSERT(stackpos >= stacktop + 2); | SLJIT_ASSERT(stackpos >= stacktop + 2); |
1378 | ||
1379 | stackpos = STACK(stackpos); | stackpos = STACK(stackpos); |
1380 | if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS)) | if (ccend == NULL) |
1381 | cc = next_opcode(common, cc); | { |
1382 | ccend = bracketend(cc) - (1 + LINK_SIZE); | |
1383 | if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS)) | |
1384 | cc = next_opcode(common, cc); | |
1385 | } | |
1386 | ||
1387 | SLJIT_ASSERT(cc != NULL); | SLJIT_ASSERT(cc != NULL); |
1388 | while (cc < ccend) | while (cc < ccend) |
1389 | switch(*cc) | switch(*cc) |
# | Line 1150 while (cc < ccend) | Line 1393 while (cc < ccend) |
1393 | if (!setsom_found) | if (!setsom_found) |
1394 | { | { |
1395 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0)); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0)); |
1396 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0)); |
1397 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1398 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); |
1399 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1400 | setsom_found = TRUE; | setsom_found = TRUE; |
1401 | } | } |
1402 | cc += 1; | cc += 1; |
1403 | break; | break; |
1404 | ||
1405 | case OP_MARK: | case OP_MARK: |
1406 | case OP_PRUNE_ARG: | |
1407 | case OP_THEN_ARG: | |
1408 | SLJIT_ASSERT(common->mark_ptr != 0); | SLJIT_ASSERT(common->mark_ptr != 0); |
1409 | if (!setmark_found) | if (!setmark_found) |
1410 | { | { |
1411 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr); |
1412 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setmark); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr); |
1413 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1414 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); |
1415 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1416 | setmark_found = TRUE; | setmark_found = TRUE; |
1417 | } | } |
1418 | cc += 1 + 2 + cc[1]; | cc += 1 + 2 + cc[1]; |
# | Line 1177 while (cc < ccend) | Line 1422 while (cc < ccend) |
1422 | if (common->has_set_som && !setsom_found) | if (common->has_set_som && !setsom_found) |
1423 | { | { |
1424 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0)); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0)); |
1425 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0)); |
1426 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1427 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); |
1428 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1429 | setsom_found = TRUE; | setsom_found = TRUE; |
1430 | } | } |
1431 | if (common->mark_ptr != 0 && !setmark_found) | if (common->mark_ptr != 0 && !setmark_found) |
1432 | { | { |
1433 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr); |
1434 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setmark); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr); |
1435 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1436 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); |
1437 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1438 | setmark_found = TRUE; | setmark_found = TRUE; |
1439 | } | } |
1440 | if (common->capture_last_ptr != 0 && !capture_last_found) | |
1441 | { | |
1442 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr); | |
1443 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr); | |
1444 | stackpos += (int)sizeof(sljit_sw); | |
1445 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); | |
1446 | stackpos += (int)sizeof(sljit_sw); | |
1447 | capture_last_found = TRUE; | |
1448 | } | |
1449 | cc += 1 + LINK_SIZE; | cc += 1 + LINK_SIZE; |
1450 | break; | break; |
1451 | ||
# | Line 1199 while (cc < ccend) | Line 1453 while (cc < ccend) |
1453 | case OP_CBRAPOS: | case OP_CBRAPOS: |
1454 | case OP_SCBRA: | case OP_SCBRA: |
1455 | case OP_SCBRAPOS: | case OP_SCBRAPOS: |
1456 | if (common->capture_last_ptr != 0 && !capture_last_found) | |
1457 | { | |
1458 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr); | |
1459 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr); | |
1460 | stackpos += (int)sizeof(sljit_sw); | |
1461 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); | |
1462 | stackpos += (int)sizeof(sljit_sw); | |
1463 | capture_last_found = TRUE; | |
1464 | } | |
1465 | offset = (GET2(cc, 1 + LINK_SIZE)) << 1; | offset = (GET2(cc, 1 + LINK_SIZE)) << 1; |
1466 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset)); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset)); |
1467 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1468 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset)); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset)); |
1469 | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1)); | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1)); |
1470 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); |
1471 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1472 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0); |
1473 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1474 | ||
1475 | cc += 1 + LINK_SIZE + IMM2_SIZE; | cc += 1 + LINK_SIZE + IMM2_SIZE; |
1476 | break; | break; |
# | Line 1218 while (cc < ccend) | Line 1481 while (cc < ccend) |
1481 | break; | break; |
1482 | } | } |
1483 | ||
1484 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0); |
1485 | SLJIT_ASSERT(stackpos == STACK(stacktop)); | SLJIT_ASSERT(stackpos == STACK(stacktop)); |
1486 | } | } |
1487 | ||
1488 | static SLJIT_INLINE int get_localsize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend) | static SLJIT_INLINE int get_private_data_copy_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL needs_control_head) |
1489 | { | { |
1490 | int localsize = 2; | int private_data_length = needs_control_head ? 3 : 2; |
1491 | int size; | int size; |
1492 | pcre_uchar *alternative; | pcre_uchar *alternative; |
1493 | /* Calculate the sum of the local variables. */ | /* Calculate the sum of the private machine words. */ |
1494 | while (cc < ccend) | while (cc < ccend) |
1495 | { | { |
1496 | size = 0; | size = 0; |
# | Line 1243 while (cc < ccend) | Line 1506 while (cc < ccend) |
1506 | case OP_SBRA: | case OP_SBRA: |
1507 | case OP_SBRAPOS: | case OP_SBRAPOS: |
1508 | case OP_SCOND: | case OP_SCOND: |
1509 | localsize++; | private_data_length++; |
1510 | cc += 1 + LINK_SIZE; | cc += 1 + LINK_SIZE; |
1511 | break; | break; |
1512 | ||
1513 | case OP_CBRA: | case OP_CBRA: |
1514 | case OP_SCBRA: | case OP_SCBRA: |
1515 | localsize++; | if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0) |
1516 | private_data_length++; | |
1517 | cc += 1 + LINK_SIZE + IMM2_SIZE; | cc += 1 + LINK_SIZE + IMM2_SIZE; |
1518 | break; | break; |
1519 | ||
1520 | case OP_CBRAPOS: | case OP_CBRAPOS: |
1521 | case OP_SCBRAPOS: | case OP_SCBRAPOS: |
1522 | localsize += 2; | private_data_length += 2; |
1523 | cc += 1 + LINK_SIZE + IMM2_SIZE; | cc += 1 + LINK_SIZE + IMM2_SIZE; |
1524 | break; | break; |
1525 | ||
# | Line 1263 while (cc < ccend) | Line 1527 while (cc < ccend) |
1527 | /* Might be a hidden SCOND. */ | /* Might be a hidden SCOND. */ |
1528 | alternative = cc + GET(cc, 1); | alternative = cc + GET(cc, 1); |
1529 | if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN) | if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN) |
1530 | localsize++; | private_data_length++; |
1531 | cc += 1 + LINK_SIZE; | cc += 1 + LINK_SIZE; |
1532 | break; | break; |
1533 | ||
1534 | CASE_ITERATOR_LOCAL1 | CASE_ITERATOR_PRIVATE_DATA_1 |
1535 | if (PRIV_DATA(cc)) | if (PRIVATE_DATA(cc)) |
1536 | localsize++; | private_data_length++; |
1537 | cc += 2; | cc += 2; |
1538 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
1539 | if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); | if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); |
1540 | #endif | #endif |
1541 | break; | break; |
1542 | ||
1543 | CASE_ITERATOR_LOCAL2A | CASE_ITERATOR_PRIVATE_DATA_2A |
1544 | if (PRIV_DATA(cc)) | if (PRIVATE_DATA(cc)) |
1545 | localsize += 2; | private_data_length += 2; |
1546 | cc += 2; | cc += 2; |
1547 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
1548 | if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); | if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); |
1549 | #endif | #endif |
1550 | break; | break; |
1551 | ||
1552 | CASE_ITERATOR_LOCAL2B | CASE_ITERATOR_PRIVATE_DATA_2B |
1553 | if (PRIV_DATA(cc)) | if (PRIVATE_DATA(cc)) |
1554 | localsize += 2; | private_data_length += 2; |
1555 | cc += 2 + IMM2_SIZE; | cc += 2 + IMM2_SIZE; |
1556 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
1557 | if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); | if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); |
1558 | #endif | #endif |
1559 | break; | break; |
1560 | ||
1561 | CASE_ITERATOR_TYPE_LOCAL1 | CASE_ITERATOR_TYPE_PRIVATE_DATA_1 |
1562 | if (PRIV_DATA(cc)) | if (PRIVATE_DATA(cc)) |
1563 | localsize++; | private_data_length++; |
1564 | cc += 1; | cc += 1; |
1565 | break; | break; |
1566 | ||
1567 | CASE_ITERATOR_TYPE_LOCAL2A | CASE_ITERATOR_TYPE_PRIVATE_DATA_2A |
1568 | if (PRIV_DATA(cc)) | if (PRIVATE_DATA(cc)) |
1569 | localsize += 2; | private_data_length += 2; |
1570 | cc += 1; | cc += 1; |
1571 | break; | break; |
1572 | ||
1573 | CASE_ITERATOR_TYPE_LOCAL2B | CASE_ITERATOR_TYPE_PRIVATE_DATA_2B |
1574 | if (PRIV_DATA(cc)) | if (PRIVATE_DATA(cc)) |
1575 | localsize += 2; | private_data_length += 2; |
1576 | cc += 1 + IMM2_SIZE; | cc += 1 + IMM2_SIZE; |
1577 | break; | break; |
1578 | ||
# | Line 1320 while (cc < ccend) | Line 1584 while (cc < ccend) |
1584 | #else | #else |
1585 | size = 1 + 32 / (int)sizeof(pcre_uchar); | size = 1 + 32 / (int)sizeof(pcre_uchar); |
1586 | #endif | #endif |
1587 | if (PRIV_DATA(cc)) | if (PRIVATE_DATA(cc)) |
1588 | localsize += get_class_iterator_size(cc + size); | private_data_length += get_class_iterator_size(cc + size); |
1589 | cc += size; | cc += size; |
1590 | break; | break; |
1591 | ||
# | Line 1332 while (cc < ccend) | Line 1596 while (cc < ccend) |
1596 | } | } |
1597 | } | } |
1598 | SLJIT_ASSERT(cc == ccend); | SLJIT_ASSERT(cc == ccend); |
1599 | return localsize; | return private_data_length; |
1600 | } | } |
1601 | ||
1602 | static void copy_locals(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, | static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, |
1603 | BOOL save, int stackptr, int stacktop) | BOOL save, int stackptr, int stacktop, BOOL needs_control_head) |
1604 | { | { |
1605 | DEFINE_COMPILER; | DEFINE_COMPILER; |
1606 | int srcw[2]; | int srcw[2]; |
# | Line 1357 stacktop = STACK(stacktop - 1); | Line 1621 stacktop = STACK(stacktop - 1); |
1621 | ||
1622 | if (!save) | if (!save) |
1623 | { | { |
1624 | stackptr += sizeof(sljit_w); | stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw); |
1625 | if (stackptr < stacktop) | if (stackptr < stacktop) |
1626 | { | { |
1627 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr); |
1628 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1629 | tmp1empty = FALSE; | tmp1empty = FALSE; |
1630 | } | } |
1631 | if (stackptr < stacktop) | if (stackptr < stacktop) |
1632 | { | { |
1633 | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr); | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr); |
1634 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1635 | tmp2empty = FALSE; | tmp2empty = FALSE; |
1636 | } | } |
1637 | /* The tmp1next must be TRUE in either way. */ | /* The tmp1next must be TRUE in either way. */ |
1638 | } | } |
1639 | ||
1640 | while (status != end) | do |
1641 | { | { |
1642 | count = 0; | count = 0; |
1643 | switch(status) | switch(status) |
1644 | { | { |
1645 | case start: | case start: |
1646 | SLJIT_ASSERT(save && common->recursive_head != 0); | SLJIT_ASSERT(save && common->recursive_head_ptr != 0); |
1647 | count = 1; | count = 1; |
1648 | srcw[0] = common->recursive_head; | srcw[0] = common->recursive_head_ptr; |
1649 | if (needs_control_head) | |
1650 | { | |
1651 | SLJIT_ASSERT(common->control_head_ptr != 0); | |
1652 | count = 2; | |
1653 | srcw[1] = common->control_head_ptr; | |
1654 | } | |
1655 | status = loop; | status = loop; |
1656 | break; | break; |
1657 | ||
# | Line 1405 while (status != end) | Line 1675 while (status != end) |
1675 | case OP_SBRAPOS: | case OP_SBRAPOS: |
1676 | case OP_SCOND: | case OP_SCOND: |
1677 | count = 1; | count = 1; |
1678 | srcw[0] = PRIV_DATA(cc); | srcw[0] = PRIVATE_DATA(cc); |
1679 | SLJIT_ASSERT(srcw[0] != 0); | SLJIT_ASSERT(srcw[0] != 0); |
1680 | cc += 1 + LINK_SIZE; | cc += 1 + LINK_SIZE; |
1681 | break; | break; |
1682 | ||
1683 | case OP_CBRA: | case OP_CBRA: |
1684 | case OP_SCBRA: | case OP_SCBRA: |
1685 | count = 1; | if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0) |
1686 | srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE)); | { |
1687 | count = 1; | |
1688 | srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE)); | |
1689 | } | |
1690 | cc += 1 + LINK_SIZE + IMM2_SIZE; | cc += 1 + LINK_SIZE + IMM2_SIZE; |
1691 | break; | break; |
1692 | ||
1693 | case OP_CBRAPOS: | case OP_CBRAPOS: |
1694 | case OP_SCBRAPOS: | case OP_SCBRAPOS: |
1695 | count = 2; | count = 2; |
1696 | srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE)); | srcw[0] = PRIVATE_DATA(cc); |
1697 | srcw[1] = PRIV_DATA(cc); | srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE)); |
1698 | SLJIT_ASSERT(srcw[0] != 0); | SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0); |
1699 | cc += 1 + LINK_SIZE + IMM2_SIZE; | cc += 1 + LINK_SIZE + IMM2_SIZE; |
1700 | break; | break; |
1701 | ||
# | Line 1432 while (status != end) | Line 1705 while (status != end) |
1705 | if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN) | if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN) |
1706 | { | { |
1707 | count = 1; | count = 1; |
1708 | srcw[0] = PRIV_DATA(cc); | srcw[0] = PRIVATE_DATA(cc); |
1709 | SLJIT_ASSERT(srcw[0] != 0); | SLJIT_ASSERT(srcw[0] != 0); |
1710 | } | } |
1711 | cc += 1 + LINK_SIZE; | cc += 1 + LINK_SIZE; |
1712 | break; | break; |
1713 | ||
1714 | CASE_ITERATOR_LOCAL1 | CASE_ITERATOR_PRIVATE_DATA_1 |
1715 | if (PRIV_DATA(cc)) | if (PRIVATE_DATA(cc)) |
1716 | { | { |
1717 | count = 1; | count = 1; |
1718 | srcw[0] = PRIV_DATA(cc); | srcw[0] = PRIVATE_DATA(cc); |
1719 | } | } |
1720 | cc += 2; | cc += 2; |
1721 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
# | Line 1450 while (status != end) | Line 1723 while (status != end) |
1723 | #endif | #endif |
1724 | break; | break; |
1725 | ||
1726 | CASE_ITERATOR_LOCAL2A | CASE_ITERATOR_PRIVATE_DATA_2A |
1727 | if (PRIV_DATA(cc)) | if (PRIVATE_DATA(cc)) |
1728 | { | { |
1729 | count = 2; | count = 2; |
1730 | srcw[0] = PRIV_DATA(cc); | srcw[0] = PRIVATE_DATA(cc); |
1731 | srcw[1] = PRIV_DATA(cc) + sizeof(sljit_w); | srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw); |
1732 | } | } |
1733 | cc += 2; | cc += 2; |
1734 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
# | Line 1463 while (status != end) | Line 1736 while (status != end) |
1736 | #endif | #endif |
1737 | break; | break; |
1738 | ||
1739 | CASE_ITERATOR_LOCAL2B | CASE_ITERATOR_PRIVATE_DATA_2B |
1740 | if (PRIV_DATA(cc)) | if (PRIVATE_DATA(cc)) |
1741 | { | { |
1742 | count = 2; | count = 2; |
1743 | srcw[0] = PRIV_DATA(cc); | srcw[0] = PRIVATE_DATA(cc); |
1744 | srcw[1] = PRIV_DATA(cc) + sizeof(sljit_w); | srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw); |
1745 | } | } |
1746 | cc += 2 + IMM2_SIZE; | cc += 2 + IMM2_SIZE; |
1747 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
# | Line 1476 while (status != end) | Line 1749 while (status != end) |
1749 | #endif | #endif |
1750 | break; | break; |
1751 | ||
1752 | CASE_ITERATOR_TYPE_LOCAL1 | CASE_ITERATOR_TYPE_PRIVATE_DATA_1 |
1753 | if (PRIV_DATA(cc)) | if (PRIVATE_DATA(cc)) |
1754 | { | { |
1755 | count = 1; | count = 1; |
1756 | srcw[0] = PRIV_DATA(cc); | srcw[0] = PRIVATE_DATA(cc); |
1757 | } | } |
1758 | cc += 1; | cc += 1; |
1759 | break; | break; |
1760 | ||
1761 | CASE_ITERATOR_TYPE_LOCAL2A | CASE_ITERATOR_TYPE_PRIVATE_DATA_2A |
1762 | if (PRIV_DATA(cc)) | if (PRIVATE_DATA(cc)) |
1763 | { | { |
1764 | count = 2; | count = 2; |
1765 | srcw[0] = PRIV_DATA(cc); | srcw[0] = PRIVATE_DATA(cc); |
1766 | srcw[1] = srcw[0] + sizeof(sljit_w); | srcw[1] = srcw[0] + sizeof(sljit_sw); |
1767 | } | } |
1768 | cc += 1; | cc += 1; |
1769 | break; | break; |
1770 | ||
1771 | CASE_ITERATOR_TYPE_LOCAL2B | CASE_ITERATOR_TYPE_PRIVATE_DATA_2B |
1772 | if (PRIV_DATA(cc)) | if (PRIVATE_DATA(cc)) |
1773 | { | { |
1774 | count = 2; | count = 2; |
1775 | srcw[0] = PRIV_DATA(cc); | srcw[0] = PRIVATE_DATA(cc); |
1776 | srcw[1] = srcw[0] + sizeof(sljit_w); | srcw[1] = srcw[0] + sizeof(sljit_sw); |
1777 | } | } |
1778 | cc += 1 + IMM2_SIZE; | cc += 1 + IMM2_SIZE; |
1779 | break; | break; |
# | Line 1513 while (status != end) | Line 1786 while (status != end) |
1786 | #else | #else |
1787 | size = 1 + 32 / (int)sizeof(pcre_uchar); | size = 1 + 32 / (int)sizeof(pcre_uchar); |
1788 | #endif | #endif |
1789 | if (PRIV_DATA(cc)) | if (PRIVATE_DATA(cc)) |
1790 | switch(get_class_iterator_size(cc + size)) | switch(get_class_iterator_size(cc + size)) |
1791 | { | { |
1792 | case 1: | case 1: |
1793 | count = 1; | count = 1; |
1794 | srcw[0] = PRIV_DATA(cc); | srcw[0] = PRIVATE_DATA(cc); |
1795 | break; | break; |
1796 | ||
1797 | case 2: | case 2: |
1798 | count = 2; | count = 2; |
1799 | srcw[0] = PRIV_DATA(cc); | srcw[0] = PRIVATE_DATA(cc); |
1800 | srcw[1] = srcw[0] + sizeof(sljit_w); | srcw[1] = srcw[0] + sizeof(sljit_sw); |
1801 | break; | break; |
1802 | ||
1803 | default: | default: |
# | Line 1556 while (status != end) | Line 1829 while (status != end) |
1829 | if (!tmp1empty) | if (!tmp1empty) |
1830 | { | { |
1831 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0); |
1832 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1833 | } | } |
1834 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]); |
1835 | tmp1empty = FALSE; | tmp1empty = FALSE; |
# | Line 1567 while (status != end) | Line 1840 while (status != end) |
1840 | if (!tmp2empty) | if (!tmp2empty) |
1841 | { | { |
1842 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0); |
1843 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1844 | } | } |
1845 | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]); | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]); |
1846 | tmp2empty = FALSE; | tmp2empty = FALSE; |
# | Line 1584 while (status != end) | Line 1857 while (status != end) |
1857 | if (!tmp1empty) | if (!tmp1empty) |
1858 | { | { |
1859 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr); |
1860 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1861 | } | } |
1862 | tmp1next = FALSE; | tmp1next = FALSE; |
1863 | } | } |
# | Line 1596 while (status != end) | Line 1869 while (status != end) |
1869 | if (!tmp2empty) | if (!tmp2empty) |
1870 | { | { |
1871 | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr); | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr); |
1872 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1873 | } | } |
1874 | tmp1next = TRUE; | tmp1next = TRUE; |
1875 | } | } |
1876 | } | } |
1877 | } | } |
1878 | } | } |
1879 | while (status != end); | |
1880 | ||
1881 | if (save) | if (save) |
1882 | { | { |
# | Line 1611 if (save) | Line 1885 if (save) |
1885 | if (!tmp1empty) | if (!tmp1empty) |
1886 | { | { |
1887 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0); |
1888 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1889 | } | } |
1890 | if (!tmp2empty) | if (!tmp2empty) |
1891 | { | { |
1892 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0); |
1893 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1894 | } | } |
1895 | } | } |
1896 | else | else |
# | Line 1624 if (save) | Line 1898 if (save) |
1898 | if (!tmp2empty) | if (!tmp2empty) |
1899 | { | { |
1900 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0); |
1901 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1902 | } | } |
1903 | if (!tmp1empty) | if (!tmp1empty) |
1904 | { | { |
1905 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0); |
1906 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1907 | } | } |
1908 | } | } |
1909 | } | } |
1910 | SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty))); | SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty))); |
1911 | } | } |
1912 | ||
1913 | #undef CASE_ITERATOR_LOCAL1 | static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset) |
1914 | #undef CASE_ITERATOR_LOCAL2A | { |
1915 | #undef CASE_ITERATOR_LOCAL2B | pcre_uchar *end = bracketend(cc); |
1916 | #undef CASE_ITERATOR_TYPE_LOCAL1 | BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT; |
1917 | #undef CASE_ITERATOR_TYPE_LOCAL2A | |
1918 | #undef CASE_ITERATOR_TYPE_LOCAL2B | /* Assert captures then. */ |
1919 | if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) | |
1920 | current_offset = NULL; | |
1921 | /* Conditional block does not. */ | |
1922 | if (*cc == OP_COND || *cc == OP_SCOND) | |
1923 | has_alternatives = FALSE; | |
1924 | ||
1925 | cc = next_opcode(common, cc); | |
1926 | if (has_alternatives) | |
1927 | current_offset = common->then_offsets + (cc - common->start); | |
1928 | ||
1929 | while (cc < end) | |
1930 | { | |
1931 | if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND)) | |
1932 | cc = set_then_offsets(common, cc, current_offset); | |
1933 | else | |
1934 | { | |
1935 | if (*cc == OP_ALT && has_alternatives) | |
1936 | current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start); | |
1937 | if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL) | |
1938 | *current_offset = 1; | |
1939 | cc = next_opcode(common, cc); | |
1940 | } | |
1941 | } | |
1942 | ||
1943 | return end; | |
1944 | } | |
1945 | ||
1946 | #undef CASE_ITERATOR_PRIVATE_DATA_1 | |
1947 | #undef CASE_ITERATOR_PRIVATE_DATA_2A | |
1948 | #undef CASE_ITERATOR_PRIVATE_DATA_2B | |
1949 | #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1 | |
1950 | #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A | |
1951 | #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B | |
1952 | ||
1953 | static SLJIT_INLINE BOOL ispowerof2(unsigned int value) | static SLJIT_INLINE BOOL is_powerof2(unsigned int value) |
1954 | { | { |
1955 | return (value & (value - 1)) == 0; | return (value & (value - 1)) == 0; |
1956 | } | } |
# | Line 1653 static SLJIT_INLINE void set_jumps(jump_ | Line 1960 static SLJIT_INLINE void set_jumps(jump_ |
1960 | while (list) | while (list) |
1961 | { | { |
1962 | /* sljit_set_label is clever enough to do nothing | /* sljit_set_label is clever enough to do nothing |
1963 | if either the jump or the label is NULL */ | if either the jump or the label is NULL. */ |
1964 | sljit_set_label(list->jump, label); | SET_LABEL(list->jump, label); |
1965 | list = list->next; | list = list->next; |
1966 | } | } |
1967 | } | } |
# | Line 1670 if (list_item) | Line 1977 if (list_item) |
1977 | } | } |
1978 | } | } |
1979 | ||
1980 | static void add_stub(compiler_common *common, enum stub_types type, int data, struct sljit_jump *start) | static void add_stub(compiler_common *common, struct sljit_jump *start) |
1981 | { | { |
1982 | DEFINE_COMPILER; | DEFINE_COMPILER; |
1983 | stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list)); | stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list)); |
1984 | ||
1985 | if (list_item) | if (list_item) |
1986 | { | { |
list_item->type = type; | ||
list_item->data = data; | ||
1987 | list_item->start = start; | list_item->start = start; |
1988 | list_item->quit = LABEL(); | list_item->quit = LABEL(); |
1989 | list_item->next = common->stubs; | list_item->next = common->stubs; |
# | Line 1694 stub_list* list_item = common->stubs; | Line 1999 stub_list* list_item = common->stubs; |
1999 | while (list_item) | while (list_item) |
2000 | { | { |
2001 | JUMPHERE(list_item->start); | JUMPHERE(list_item->start); |
2002 | switch(list_item->type) | add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL)); |
{ | ||
case stack_alloc: | ||
add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL)); | ||
break; | ||
} | ||
2003 | JUMPTO(SLJIT_JUMP, list_item->quit); | JUMPTO(SLJIT_JUMP, list_item->quit); |
2004 | list_item = list_item->next; | list_item = list_item->next; |
2005 | } | } |
# | Line 1719 static SLJIT_INLINE void allocate_stack( | Line 2019 static SLJIT_INLINE void allocate_stack( |
2019 | /* May destroy all locals and registers except TMP2. */ | /* May destroy all locals and registers except TMP2. */ |
2020 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2021 | ||
2022 | OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w)); | OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw)); |
2023 | #ifdef DESTROY_REGISTERS | #ifdef DESTROY_REGISTERS |
2024 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345); |
2025 | OP1(SLJIT_MOV, TMP3, 0, TMP1, 0); | OP1(SLJIT_MOV, TMP3, 0, TMP1, 0); |
# | Line 1727 OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); | Line 2027 OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); |
2027 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0); |
2028 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0); |
2029 | #endif | #endif |
2030 | add_stub(common, stack_alloc, 0, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0)); | add_stub(common, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0)); |
2031 | } | } |
2032 | ||
2033 | static SLJIT_INLINE void free_stack(compiler_common *common, int size) | static SLJIT_INLINE void free_stack(compiler_common *common, int size) |
2034 | { | { |
2035 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2036 | OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w)); | OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw)); |
2037 | } | } |
2038 | ||
2039 | static SLJIT_INLINE void reset_ovector(compiler_common *common, int length) | static SLJIT_INLINE void reset_ovector(compiler_common *common, int length) |
# | Line 1741 static SLJIT_INLINE void reset_ovector(c | Line 2041 static SLJIT_INLINE void reset_ovector(c |
2041 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2042 | struct sljit_label *loop; | struct sljit_label *loop; |
2043 | int i; | int i; |
2044 | ||
2045 | /* At this point we can freely use all temporary registers. */ | /* At this point we can freely use all temporary registers. */ |
2046 | SLJIT_ASSERT(length > 1); | |
2047 | /* TMP1 returns with begin - 1. */ | /* TMP1 returns with begin - 1. */ |
2048 | OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1)); | OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1)); |
2049 | if (length < 8) | |
2050 | { | |
2051 | for (i = 1; i < length; i++) | |
2052 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0); | |
2053 | } | |
2054 | else | |
2055 | { | |
2056 | GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START); | |
2057 | OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1); | |
2058 | loop = LABEL(); | |
2059 | OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0); | |
2060 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1); | |
2061 | JUMPTO(SLJIT_C_NOT_ZERO, loop); | |
2062 | } | |
2063 | } | |
2064 | ||
2065 | static SLJIT_INLINE void do_reset_match(compiler_common *common, int length) | |
2066 | { | |
2067 | DEFINE_COMPILER; | |
2068 | struct sljit_label *loop; | |
2069 | int i; | |
2070 | ||
2071 | SLJIT_ASSERT(length > 1); | |
2072 | /* OVECTOR(1) contains the "string begin - 1" constant. */ | |
2073 | if (length > 2) | |
2074 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)); | |
2075 | if (length < 8) | if (length < 8) |
2076 | { | { |
2077 | for (i = 0; i < length; i++) | for (i = 2; i < length; i++) |
2078 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_TEMPORARY_REG1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0); |
2079 | } | } |
2080 | else | else |
2081 | { | { |
2082 | GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w)); | GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw)); |
2083 | OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length); | OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2); |
2084 | loop = LABEL(); | loop = LABEL(); |
2085 | OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0); | OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0); |
2086 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1); | OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1); |
2087 | JUMPTO(SLJIT_C_NOT_ZERO, loop); | JUMPTO(SLJIT_C_NOT_ZERO, loop); |
2088 | } | } |
2089 | ||
2090 | OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0); | |
2091 | if (common->mark_ptr != 0) | |
2092 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0); | |
2093 | if (common->control_head_ptr != 0) | |
2094 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0); | |
2095 | OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack)); | |
2096 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr); | |
2097 | OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base)); | |
2098 | } | |
2099 | ||
2100 | static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg) | |
2101 | { | |
2102 | while (current != NULL) | |
2103 | { | |
2104 | switch (current[-2]) | |
2105 | { | |
2106 | case type_then_trap: | |
2107 | break; | |
2108 | ||
2109 | case type_mark: | |
2110 | if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0) | |
2111 | return current[-4]; | |
2112 | break; | |
2113 | ||
2114 | default: | |
2115 | SLJIT_ASSERT_STOP(); | |
2116 | break; | |
2117 | } | |
2118 | current = (sljit_sw*)current[-1]; | |
2119 | } | |
2120 | return -1; | |
2121 | } | } |
2122 | ||
2123 | static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket) | static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket) |
2124 | { | { |
2125 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2126 | struct sljit_label *loop; | struct sljit_label *loop; |
2127 | struct sljit_jump *earlyexit; | struct sljit_jump *early_quit; |
2128 | ||
2129 | /* At this point we can freely use all registers. */ | /* At this point we can freely use all registers. */ |
2130 | OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)); | OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)); |
2131 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0); |
2132 | ||
2133 | OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0); | OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0); |
2134 | if (common->mark_ptr != 0) | if (common->mark_ptr != 0) |
2135 | OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr); | OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr); |
2136 | OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount)); | OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offset_count)); |
2137 | if (common->mark_ptr != 0) | if (common->mark_ptr != 0) |
2138 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_TEMPORARY_REG3, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0); |
2139 | OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int)); | OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int)); |
2140 | OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, begin)); | OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin)); |
2141 | GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START); | GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START); |
2142 | /* Unlikely, but possible */ | /* Unlikely, but possible */ |
2143 | earlyexit = CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0); | early_quit = CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0); |
2144 | loop = LABEL(); | loop = LABEL(); |
2145 | OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0); | OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0); |
2146 | OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_w)); | OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw)); |
2147 | /* Copy the integer value to the output buffer */ | /* Copy the integer value to the output buffer */ |
2148 | #ifdef COMPILE_PCRE16 | #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32 |
2149 | OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1); | OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT); |
2150 | #endif | #endif |
2151 | OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), sizeof(int), SLJIT_SAVED_REG2, 0); | OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0); |
2152 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1); |
2153 | JUMPTO(SLJIT_C_NOT_ZERO, loop); | JUMPTO(SLJIT_C_NOT_ZERO, loop); |
2154 | JUMPHERE(earlyexit); | JUMPHERE(early_quit); |
2155 | ||
2156 | /* Calculate the return value, which is the maximum ovector value. */ | /* Calculate the return value, which is the maximum ovector value. */ |
2157 | if (topbracket > 1) | if (topbracket > 1) |
2158 | { | { |
2159 | GET_LOCAL_BASE(SLJIT_TEMPORARY_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_w)); | GET_LOCAL_BASE(SLJIT_SCRATCH_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw)); |
2160 | OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1); | OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1); |
2161 | ||
2162 | /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */ | /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */ |
2163 | loop = LABEL(); | loop = LABEL(); |
2164 | OP1(SLJIT_MOVU, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), -(2 * (sljit_w)sizeof(sljit_w))); | OP1(SLJIT_MOVU, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), -(2 * (sljit_sw)sizeof(sljit_sw))); |
2165 | OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1); | OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1); |
2166 | CMPTO(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG3, 0, loop); | CMPTO(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG3, 0, loop); |
2167 | OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0); | OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0); |
2168 | } | } |
2169 | else | else |
2170 | OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1); | OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1); |
# | Line 1813 else | Line 2173 else |
2173 | static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit) | static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit) |
2174 | { | { |
2175 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2176 | struct sljit_jump *jump; | |
2177 | ||
2178 | SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2); | SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2); |
2179 | SLJIT_ASSERT(common->start_used_ptr != 0 && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0)); | SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0 |
2180 | && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0)); | |
2181 | ||
2182 | OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0); | OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0); |
2183 | OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL); | OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL); |
2184 | OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, offsetcount)); | OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, real_offset_count)); |
2185 | CMPTO(SLJIT_C_LESS, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2, quit); | CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit); |
2186 | ||
2187 | /* Store match begin and end. */ | /* Store match begin and end. */ |
2188 | OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, begin)); | OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin)); |
2189 | OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, offsets)); | OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets)); |
2190 | OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start); | |
2191 | jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3); | |
2192 | OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + (int)sizeof(sljit_sw)), SLJIT_SAVED_REG1, 0); | |
2193 | #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32 | |
2194 | OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT); | |
2195 | #endif | |
2196 | OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0); | |
2197 | JUMPHERE(jump); | |
2198 | ||
2199 | OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start); | |
2200 | OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0); | OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0); |
2201 | #ifdef COMPILE_PCRE16 | #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32 |
2202 | OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1); | OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT); |
2203 | #endif | #endif |
2204 | OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(int), SLJIT_SAVED_REG2, 0); | OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(int), SLJIT_SAVED_REG2, 0); |
2205 | ||
2206 | OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG1, 0); | OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG1, 0); |
2207 | #ifdef COMPILE_PCRE16 | #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32 |
2208 | OP2(SLJIT_ASHR, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1); | OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT); |
2209 | #endif | #endif |
2210 | OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), 0, SLJIT_TEMPORARY_REG3, 0); | OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0, SLJIT_SCRATCH_REG3, 0); |
2211 | ||
2212 | JUMPTO(SLJIT_JUMP, quit); | JUMPTO(SLJIT_JUMP, quit); |
2213 | } | } |
# | Line 1949 if (c <= 127 && bit == 0x20) | Line 2320 if (c <= 127 && bit == 0x20) |
2320 | return (0 << 8) | 0x20; | return (0 << 8) | 0x20; |
2321 | ||
2322 | /* Since c != oc, they must have at least 1 bit difference. */ | /* Since c != oc, they must have at least 1 bit difference. */ |
2323 | if (!ispowerof2(bit)) | if (!is_powerof2(bit)) |
2324 | return 0; | return 0; |
2325 | ||
2326 | #ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 |
2327 | ||
2328 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
2329 | if (common->utf && c > 127) | if (common->utf && c > 127) |
# | Line 1968 if (common->utf && c > 127) | Line 2339 if (common->utf && c > 127) |
2339 | #endif /* SUPPORT_UTF */ | #endif /* SUPPORT_UTF */ |
2340 | return (0 << 8) | bit; | return (0 << 8) | bit; |
2341 | ||
2342 | #else /* COMPILE_PCRE8 */ | #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32 |
2343 | ||
#ifdef COMPILE_PCRE16 | ||
2344 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
2345 | if (common->utf && c > 65535) | if (common->utf && c > 65535) |
2346 | { | { |
# | Line 1981 if (common->utf && c > 65535) | Line 2351 if (common->utf && c > 65535) |
2351 | } | } |
2352 | #endif /* SUPPORT_UTF */ | #endif /* SUPPORT_UTF */ |
2353 | return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8)); | return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8)); |
#endif /* COMPILE_PCRE16 */ | ||
2354 | ||
2355 | #endif /* COMPILE_PCRE8 */ | #endif /* COMPILE_PCRE[8|16|32] */ |
2356 | } | } |
2357 | ||
2358 | static void check_partial(compiler_common *common, BOOL force) | static void check_partial(compiler_common *common, BOOL force) |
# | Line 2003 else if (common->mode == JIT_PARTIAL_SOF | Line 2372 else if (common->mode == JIT_PARTIAL_SOF |
2372 | jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1); | jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1); |
2373 | ||
2374 | if (common->mode == JIT_PARTIAL_SOFT_COMPILE) | if (common->mode == JIT_PARTIAL_SOFT_COMPILE) |
2375 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0); |
2376 | else | else |
2377 | { | { |
2378 | if (common->partialmatchlabel != NULL) | if (common->partialmatchlabel != NULL) |
# | Line 2016 if (jump != NULL) | Line 2385 if (jump != NULL) |
2385 | JUMPHERE(jump); | JUMPHERE(jump); |
2386 | } | } |
2387 | ||
2388 | static struct sljit_jump *check_str_end(compiler_common *common) | static void check_str_end(compiler_common *common, jump_list **end_reached) |
2389 | { | { |
2390 | /* Does not affect registers. Usually used in a tight spot. */ | /* Does not affect registers. Usually used in a tight spot. */ |
2391 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2392 | struct sljit_jump *jump; | struct sljit_jump *jump; |
struct sljit_jump *nohit; | ||
struct sljit_jump *return_value; | ||
2393 | ||
2394 | if (common->mode == JIT_COMPILE) | if (common->mode == JIT_COMPILE) |
2395 | return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); | { |
2396 | add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0)); | |
2397 | return; | |
2398 | } | |
2399 | ||
2400 | jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0); | jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0); |
2401 | if (common->mode == JIT_PARTIAL_SOFT_COMPILE) | if (common->mode == JIT_PARTIAL_SOFT_COMPILE) |
2402 | { | { |
2403 | nohit = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0); | add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0)); |
2404 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0); |
2405 | JUMPHERE(nohit); | add_jump(compiler, end_reached, JUMP(SLJIT_JUMP)); |
return_value = JUMP(SLJIT_JUMP); | ||
2406 | } | } |
2407 | else | else |
2408 | { | { |
2409 | return_value = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0); | add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0)); |
2410 | if (common->partialmatchlabel != NULL) | if (common->partialmatchlabel != NULL) |
2411 | JUMPTO(SLJIT_JUMP, common->partialmatchlabel); | JUMPTO(SLJIT_JUMP, common->partialmatchlabel); |
2412 | else | else |
2413 | add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP)); | add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP)); |
2414 | } | } |
2415 | JUMPHERE(jump); | JUMPHERE(jump); |
return return_value; | ||
2416 | } | } |
2417 | ||
2418 | static void detect_partial_match(compiler_common *common, jump_list **backtracks) | static void detect_partial_match(compiler_common *common, jump_list **backtracks) |
# | Line 2063 jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR | Line 2431 jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR |
2431 | add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0)); | add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0)); |
2432 | if (common->mode == JIT_PARTIAL_SOFT_COMPILE) | if (common->mode == JIT_PARTIAL_SOFT_COMPILE) |
2433 | { | { |
2434 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0); |
2435 | add_jump(compiler, backtracks, JUMP(SLJIT_JUMP)); | add_jump(compiler, backtracks, JUMP(SLJIT_JUMP)); |
2436 | } | } |
2437 | else | else |
# | Line 2081 static void read_char(compiler_common *c | Line 2449 static void read_char(compiler_common *c |
2449 | /* Reads the character into TMP1, updates STR_PTR. | /* Reads the character into TMP1, updates STR_PTR. |
2450 | Does not check STR_END. TMP2 Destroyed. */ | Does not check STR_END. TMP2 Destroyed. */ |
2451 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2452 | #ifdef SUPPORT_UTF | #if defined SUPPORT_UTF && !defined COMPILE_PCRE32 |
2453 | struct sljit_jump *jump; | struct sljit_jump *jump; |
2454 | #endif | #endif |
2455 | ||
2456 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); |
2457 | #ifdef SUPPORT_UTF | #if defined SUPPORT_UTF && !defined COMPILE_PCRE32 |
2458 | if (common->utf) | if (common->utf) |
2459 | { | { |
2460 | #ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 |
2461 | jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0); | jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0); |
2462 | #else | #elif defined COMPILE_PCRE16 |
#ifdef COMPILE_PCRE16 | ||
2463 | jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800); | jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800); |
2464 | #endif | #endif /* COMPILE_PCRE[8|16] */ |
#endif /* COMPILE_PCRE8 */ | ||
2465 | add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL)); | add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL)); |
2466 | JUMPHERE(jump); | JUMPHERE(jump); |
2467 | } | } |
2468 | #endif | #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */ |
2469 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); |
2470 | } | } |
2471 | ||
# | Line 2108 static void peek_char(compiler_common *c | Line 2474 static void peek_char(compiler_common *c |
2474 | /* Reads the character into TMP1, keeps STR_PTR. | /* Reads the character into TMP1, keeps STR_PTR. |
2475 | Does not check STR_END. TMP2 Destroyed. */ | Does not check STR_END. TMP2 Destroyed. */ |
2476 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2477 | #ifdef SUPPORT_UTF | #if defined SUPPORT_UTF && !defined COMPILE_PCRE32 |
2478 | struct sljit_jump *jump; | struct sljit_jump *jump; |
2479 | #endif | #endif |
2480 | ||
2481 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); |
2482 | #ifdef SUPPORT_UTF | #if defined SUPPORT_UTF && !defined COMPILE_PCRE32 |
2483 | if (common->utf) | if (common->utf) |
2484 | { | { |
2485 | #ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 |
2486 | jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0); | jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0); |
2487 | #else | #elif defined COMPILE_PCRE16 |
#ifdef COMPILE_PCRE16 | ||
2488 | jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800); | jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800); |
2489 | #endif | #endif /* COMPILE_PCRE[8|16] */ |
#endif /* COMPILE_PCRE8 */ | ||
2490 | add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL)); | add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL)); |
2491 | OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0); | OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0); |
2492 | JUMPHERE(jump); | JUMPHERE(jump); |
2493 | } | } |
2494 | #endif | #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */ |
2495 | } | } |
2496 | ||
2497 | static void read_char8_type(compiler_common *common) | static void read_char8_type(compiler_common *common) |
2498 | { | { |
2499 | /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */ | /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */ |
2500 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2501 | #if defined SUPPORT_UTF || defined COMPILE_PCRE16 | #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32 |
2502 | struct sljit_jump *jump; | struct sljit_jump *jump; |
2503 | #endif | #endif |
2504 | ||
# | Line 2143 if (common->utf) | Line 2507 if (common->utf) |
2507 | { | { |
2508 | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0); | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0); |
2509 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); |
2510 | #ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 |
2511 | /* This can be an extra read in some situations, but hopefully | /* This can be an extra read in some situations, but hopefully |
2512 | it is needed in most cases. */ | it is needed in most cases. */ |
2513 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); |
2514 | jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0); | jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0); |
2515 | add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL)); | add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL)); |
2516 | JUMPHERE(jump); | JUMPHERE(jump); |
2517 | #else | #elif defined COMPILE_PCRE16 |
#ifdef COMPILE_PCRE16 | ||
2518 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); |
2519 | jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255); | jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255); |
2520 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); |
# | Line 2159 if (common->utf) | Line 2522 if (common->utf) |
2522 | /* Skip low surrogate if necessary. */ | /* Skip low surrogate if necessary. */ |
2523 | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00); | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00); |
2524 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800); |
2525 | COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL); |
2526 | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1); | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1); |
2527 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0); |
2528 | #endif | #elif defined COMPILE_PCRE32 |
2529 | #endif /* COMPILE_PCRE8 */ | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); |
2530 | jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255); | |
2531 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); | |
2532 | JUMPHERE(jump); | |
2533 | #endif /* COMPILE_PCRE[8|16|32] */ | |
2534 | return; | return; |
2535 | } | } |
2536 | #endif | #endif /* SUPPORT_UTF */ |
2537 | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0); | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0); |
2538 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); |
2539 | #ifdef COMPILE_PCRE16 | #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32 |
2540 | /* The ctypes array contains only 256 values. */ | /* The ctypes array contains only 256 values. */ |
2541 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); |
2542 | jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255); | jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255); |
2543 | #endif | #endif |
2544 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); |
2545 | #ifdef COMPILE_PCRE16 | #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32 |
2546 | JUMPHERE(jump); | JUMPHERE(jump); |
2547 | #endif | #endif |
2548 | } | } |
# | Line 2184 static void skip_char_back(compiler_comm | Line 2551 static void skip_char_back(compiler_comm |
2551 | { | { |
2552 | /* Goes one character back. Affects STR_PTR and TMP1. Does not check begin. */ | /* Goes one character back. Affects STR_PTR and TMP1. Does not check begin. */ |
2553 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2554 | #if defined SUPPORT_UTF && defined COMPILE_PCRE8 | #if defined SUPPORT_UTF && !defined COMPILE_PCRE32 |
2555 | #if defined COMPILE_PCRE8 | |
2556 | struct sljit_label *label; | struct sljit_label *label; |
2557 | ||
2558 | if (common->utf) | if (common->utf) |
# | Line 2196 if (common->utf) | Line 2564 if (common->utf) |
2564 | CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label); | CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label); |
2565 | return; | return; |
2566 | } | } |
2567 | #endif | #elif defined COMPILE_PCRE16 |
#if defined SUPPORT_UTF && defined COMPILE_PCRE16 | ||
2568 | if (common->utf) | if (common->utf) |
2569 | { | { |
2570 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1)); | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1)); |
# | Line 2205 if (common->utf) | Line 2572 if (common->utf) |
2572 | /* Skip low surrogate if necessary. */ | /* Skip low surrogate if necessary. */ |
2573 | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00); | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00); |
2574 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00); |
2575 | COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL); |
2576 | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); |
2577 | OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0); | OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0); |
2578 | return; | return; |
2579 | } | } |
2580 | #endif | #endif /* COMPILE_PCRE[8|16] */ |
2581 | #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */ | |
2582 | OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); |
2583 | } | } |
2584 | ||
# | Line 2227 if (nltype == NLTYPE_ANY) | Line 2595 if (nltype == NLTYPE_ANY) |
2595 | else if (nltype == NLTYPE_ANYCRLF) | else if (nltype == NLTYPE_ANYCRLF) |
2596 | { | { |
2597 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR); |
2598 | COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL); |
2599 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL); |
2600 | COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); |
2601 | add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO)); | add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO)); |
2602 | } | } |
2603 | else | else |
# | Line 2241 else | Line 2609 else |
2609 | ||
2610 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
2611 | ||
2612 | #ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 |
2613 | static void do_utfreadchar(compiler_common *common) | static void do_utfreadchar(compiler_common *common) |
2614 | { | { |
2615 | /* Fast decoding a UTF-8 character. TMP1 contains the first byte | /* Fast decoding a UTF-8 character. TMP1 contains the first byte |
# | Line 2329 sljit_emit_fast_return(compiler, RETURN_ | Line 2697 sljit_emit_fast_return(compiler, RETURN_ |
2697 | JUMPHERE(jump); | JUMPHERE(jump); |
2698 | ||
2699 | /* We only have types for characters less than 256. */ | /* We only have types for characters less than 256. */ |
2700 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(utf8_table4) - 0xc0); | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0); |
2701 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); |
2702 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); |
2703 | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); |
2704 | } | } |
2705 | ||
2706 | #else /* COMPILE_PCRE8 */ | #elif defined COMPILE_PCRE16 |
2707 | ||
#ifdef COMPILE_PCRE16 | ||
2708 | static void do_utfreadchar(compiler_common *common) | static void do_utfreadchar(compiler_common *common) |
2709 | { | { |
2710 | /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char | /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char |
# | Line 2362 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC | Line 2729 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC |
2729 | OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000); | OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000); |
2730 | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); |
2731 | } | } |
#endif /* COMPILE_PCRE16 */ | ||
2732 | ||
2733 | #endif /* COMPILE_PCRE8 */ | #endif /* COMPILE_PCRE[8|16] */ |
2734 | ||
2735 | #endif /* SUPPORT_UTF */ | #endif /* SUPPORT_UTF */ |
2736 | ||
# | Line 2384 SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si | Line 2750 SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si |
2750 | ||
2751 | sljit_emit_fast_enter(compiler, RETURN_ADDR, 0); | sljit_emit_fast_enter(compiler, RETURN_ADDR, 0); |
2752 | OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT); | OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT); |
2753 | OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(ucd_stage1)); | OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(ucd_stage1)); |
2754 | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK); | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK); |
2755 | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT); | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT); |
2756 | OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0); | OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0); |
2757 | OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2)); | OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2)); |
2758 | OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1); | OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1); |
2759 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype)); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype)); |
2760 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3); | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3); |
2761 | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); |
2762 | } | } |
# | Line 2404 struct sljit_label *newlinelabel = NULL; | Line 2770 struct sljit_label *newlinelabel = NULL; |
2770 | struct sljit_jump *start; | struct sljit_jump *start; |
2771 | struct sljit_jump *end = NULL; | struct sljit_jump *end = NULL; |
2772 | struct sljit_jump *nl = NULL; | struct sljit_jump *nl = NULL; |
2773 | #ifdef SUPPORT_UTF | #if defined SUPPORT_UTF && !defined COMPILE_PCRE32 |
2774 | struct sljit_jump *singlechar; | struct sljit_jump *singlechar; |
2775 | #endif | #endif |
2776 | jump_list *newline = NULL; | jump_list *newline = NULL; |
# | Line 2419 if (firstline) | Line 2785 if (firstline) |
2785 | { | { |
2786 | /* Search for the end of the first line. */ | /* Search for the end of the first line. */ |
2787 | SLJIT_ASSERT(common->first_line_end != 0); | SLJIT_ASSERT(common->first_line_end != 0); |
2788 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0); | OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0); |
OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_END, 0); | ||
2789 | ||
2790 | if (common->nltype == NLTYPE_FIXED && common->newline > 255) | if (common->nltype == NLTYPE_FIXED && common->newline > 255) |
2791 | { | { |
# | Line 2431 if (firstline) | Line 2796 if (firstline) |
2796 | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); |
2797 | CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop); | CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop); |
2798 | CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop); | CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop); |
2799 | JUMPHERE(end); | |
2800 | OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); |
2801 | } | } |
2802 | else | else |
# | Line 2442 if (firstline) | Line 2808 if (firstline) |
2808 | read_char(common); | read_char(common); |
2809 | check_newlinechar(common, common->nltype, &newline, TRUE); | check_newlinechar(common, common->nltype, &newline, TRUE); |
2810 | CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop); | CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop); |
2811 | JUMPHERE(end); | |
2812 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0); |
2813 | set_jumps(newline, LABEL()); | set_jumps(newline, LABEL()); |
2814 | } | } |
2815 | ||
2816 | JUMPHERE(end); | OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0); |
OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0); | ||
2817 | } | } |
2818 | ||
2819 | start = JUMP(SLJIT_JUMP); | start = JUMP(SLJIT_JUMP); |
# | Line 2459 if (newlinecheck) | Line 2825 if (newlinecheck) |
2825 | end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); | end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); |
2826 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); |
2827 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff); |
2828 | COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL); |
2829 | #ifdef COMPILE_PCRE16 | #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32 |
2830 | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT); |
2831 | #endif | #endif |
2832 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); |
2833 | nl = JUMP(SLJIT_JUMP); | nl = JUMP(SLJIT_JUMP); |
# | Line 2482 if (newlinecheck) | Line 2848 if (newlinecheck) |
2848 | CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel); | CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel); |
2849 | ||
2850 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); |
2851 | #if defined SUPPORT_UTF && defined COMPILE_PCRE8 | #if defined SUPPORT_UTF && !defined COMPILE_PCRE32 |
2852 | #if defined COMPILE_PCRE8 | |
2853 | if (common->utf) | if (common->utf) |
2854 | { | { |
2855 | singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0); | singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0); |
2856 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0); | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0); |
2857 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); |
2858 | JUMPHERE(singlechar); | JUMPHERE(singlechar); |
2859 | } | } |
2860 | #endif | #elif defined COMPILE_PCRE16 |
#if defined SUPPORT_UTF && defined COMPILE_PCRE16 | ||
2861 | if (common->utf) | if (common->utf) |
2862 | { | { |
2863 | singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800); | singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800); |
2864 | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00); | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00); |
2865 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800); |
2866 | COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL); |
2867 | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); |
2868 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); |
2869 | JUMPHERE(singlechar); | JUMPHERE(singlechar); |
2870 | } | } |
2871 | #endif | #endif /* COMPILE_PCRE[8|16] */ |
2872 | #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */ | |
2873 | JUMPHERE(start); | JUMPHERE(start); |
2874 | ||
2875 | if (newlinecheck) | if (newlinecheck) |
# | Line 2514 if (newlinecheck) | Line 2881 if (newlinecheck) |
2881 | return mainloop; | return mainloop; |
2882 | } | } |
2883 | ||
2884 | static SLJIT_INLINE BOOL fast_forward_first_two_chars(compiler_common *common, BOOL firstline) | #define MAX_N_CHARS 3 |
2885 | ||
2886 | static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline) | |
2887 | { | { |
2888 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2889 | struct sljit_label *start; | struct sljit_label *start; |
2890 | struct sljit_jump *quit; | struct sljit_jump *quit; |
2891 | struct sljit_jump *found; | pcre_uint32 chars[MAX_N_CHARS * 2]; |
2892 | pcre_int32 chars[4]; | pcre_uchar *cc = common->start + 1 + LINK_SIZE; |
pcre_uchar *cc = common->start + 1 + IMM2_SIZE; | ||
2893 | int location = 0; | int location = 0; |
2894 | pcre_int32 len, c, bit, caseless; | pcre_int32 len, c, bit, caseless; |
2895 | BOOL must_end; | int must_stop; |
#ifdef COMPILE_PCRE8 | ||
union { | ||
sljit_uh ascombined; | ||
sljit_ub asuchars[2]; | ||
} pair; | ||
#else | ||
union { | ||
sljit_ui ascombined; | ||
sljit_uh asuchars[2]; | ||
} pair; | ||
#endif | ||
2896 | ||
2897 | /* We do not support alternatives now. */ | |
2898 | if (*(common->start + GET(common->start, 1)) == OP_ALT) | if (*(common->start + GET(common->start, 1)) == OP_ALT) |
2899 | return FALSE; | return FALSE; |
2900 | ||
2901 | while (TRUE) | while (TRUE) |
2902 | { | { |
2903 | caseless = 0; | caseless = 0; |
2904 | must_end = TRUE; | must_stop = 1; |
2905 | switch(*cc) | switch(*cc) |
2906 | { | { |
2907 | case OP_CHAR: | case OP_CHAR: |
2908 | must_end = FALSE; | must_stop = 0; |
2909 | cc++; | cc++; |
2910 | break; | break; |
2911 | ||
2912 | case OP_CHARI: | case OP_CHARI: |
2913 | caseless = 1; | caseless = 1; |
2914 | must_end = FALSE; | must_stop = 0; |
2915 | cc++; | cc++; |
2916 | break; | break; |
2917 | ||
# | Line 2596 while (TRUE) | Line 2953 while (TRUE) |
2953 | break; | break; |
2954 | ||
2955 | default: | default: |
2956 | return FALSE; | must_stop = 2; |
2957 | break; | |
2958 | } | } |
2959 | ||
2960 | if (must_stop == 2) | |
2961 | break; | |
2962 | ||
2963 | len = 1; | len = 1; |
2964 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
2965 | if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]); | if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]); |
# | Line 2621 while (TRUE) | Line 2982 while (TRUE) |
2982 | else | else |
2983 | caseless = 0; | caseless = 0; |
2984 | ||
2985 | while (len > 0 && location < 2 * 2) | while (len > 0 && location < MAX_N_CHARS * 2) |
2986 | { | { |
2987 | c = *cc; | c = *cc; |
2988 | bit = 0; | bit = 0; |
# | Line 2639 while (TRUE) | Line 3000 while (TRUE) |
3000 | cc++; | cc++; |
3001 | } | } |
3002 | ||
3003 | if (location == 2 * 2) | if (location >= MAX_N_CHARS * 2 || must_stop != 0) |
3004 | break; | break; |
else if (must_end) | ||
return FALSE; | ||
3005 | } | } |
3006 | ||
3007 | /* At least two characters are required. */ | |
3008 | if (location < 2 * 2) | |
3009 | return FALSE; | |
3010 | ||
3011 | if (firstline) | if (firstline) |
3012 | { | { |
3013 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0); | SLJIT_ASSERT(common->first_line_end != 0); |
3014 | OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, 1); | OP1(SLJIT_MOV, TMP3, 0, STR_END, 0); |
3015 | OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1)); | |
3016 | } | } |
3017 | else | else |
3018 | OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, 1); | OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1)); |
3019 | ||
3020 | start = LABEL(); | start = LABEL(); |
3021 | quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); | quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); |
#if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED | ||
#ifdef COMPILE_PCRE8 | ||
OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); | ||
#else /* COMPILE_PCRE8 */ | ||
OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); | ||
#endif | ||
#else /* SLJIT_UNALIGNED */ | ||
3022 | ||
3023 | #if defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); |
OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0); | ||
OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); | ||
#else /* SLJIT_BIG_ENDIAN */ | ||
3024 | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); |
3025 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); |
3026 | #endif /* SLJIT_BIG_ENDIAN */ | if (chars[1] != 0) |
3027 | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]); | |
3028 | #ifdef COMPILE_PCRE8 | CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start); |
3029 | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 8); | if (location > 2 * 2) |
3030 | #else /* COMPILE_PCRE8 */ | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); |
3031 | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 16); | if (chars[3] != 0) |
3032 | #endif | OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]); |
3033 | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); | CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start); |
3034 | if (location > 2 * 2) | |
3035 | #endif | { |
3036 | if (chars[5] != 0) | |
3037 | if (chars[1] != 0 || chars[3] != 0) | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]); |
3038 | { | CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start); |
pair.asuchars[0] = chars[1]; | ||
pair.asuchars[1] = chars[3]; | ||
OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, pair.ascombined); | ||
3039 | } | } |
3040 | OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | |
3041 | ||
pair.asuchars[0] = chars[0]; | ||
pair.asuchars[1] = chars[2]; | ||
found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, pair.ascombined); | ||
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | ||
JUMPTO(SLJIT_JUMP, start); | ||
JUMPHERE(found); | ||
3042 | JUMPHERE(quit); | JUMPHERE(quit); |
3043 | ||
3044 | if (firstline) | if (firstline) |
3045 | OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0); | OP1(SLJIT_MOV, STR_END, 0, TMP3, 0); |
3046 | OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, 1); | else |
3047 | OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1)); | |
3048 | return TRUE; | return TRUE; |
3049 | } | } |
3050 | ||
3051 | #undef MAX_N_CHARS | |
3052 | ||
3053 | static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline) | static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline) |
3054 | { | { |
3055 | DEFINE_COMPILER; | DEFINE_COMPILER; |
# | Line 2713 pcre_uchar oc, bit; | Line 3060 pcre_uchar oc, bit; |
3060 | ||
3061 | if (firstline) | if (firstline) |
3062 | { | { |
3063 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0); | SLJIT_ASSERT(common->first_line_end != 0); |
3064 | OP1(SLJIT_MOV, TMP3, 0, STR_END, 0); | |
3065 | OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end); | OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end); |
3066 | } | } |
3067 | ||
# | Line 2735 if (first_char == oc) | Line 3083 if (first_char == oc) |
3083 | else | else |
3084 | { | { |
3085 | bit = first_char ^ oc; | bit = first_char ^ oc; |
3086 | if (ispowerof2(bit)) | if (is_powerof2(bit)) |
3087 | { | { |
3088 | OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit); | OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit); |
3089 | found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit); | found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit); |
# | Line 2743 else | Line 3091 else |
3091 | else | else |
3092 | { | { |
3093 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, first_char); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, first_char); |
3094 | COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL); |
3095 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc); |
3096 | COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); |
3097 | found = JUMP(SLJIT_C_NOT_ZERO); | found = JUMP(SLJIT_C_NOT_ZERO); |
3098 | } | } |
3099 | } | } |
# | Line 2756 JUMPHERE(found); | Line 3104 JUMPHERE(found); |
3104 | JUMPHERE(quit); | JUMPHERE(quit); |
3105 | ||
3106 | if (firstline) | if (firstline) |
3107 | OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0); | OP1(SLJIT_MOV, STR_END, 0, TMP3, 0); |
3108 | } | } |
3109 | ||
3110 | static SLJIT_INLINE void fast_forward_newline(compiler_common *common, BOOL firstline) | static SLJIT_INLINE void fast_forward_newline(compiler_common *common, BOOL firstline) |
# | Line 2772 jump_list *newline = NULL; | Line 3120 jump_list *newline = NULL; |
3120 | ||
3121 | if (firstline) | if (firstline) |
3122 | { | { |
3123 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0); | SLJIT_ASSERT(common->first_line_end != 0); |
3124 | OP1(SLJIT_MOV, TMP3, 0, STR_END, 0); | |
3125 | OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end); | OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end); |
3126 | } | } |
3127 | ||
# | Line 2786 if (common->nltype == NLTYPE_FIXED && co | Line 3135 if (common->nltype == NLTYPE_FIXED && co |
3135 | ||
3136 | OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2)); | OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2)); |
3137 | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_PTR, 0, TMP1, 0); | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_PTR, 0, TMP1, 0); |
3138 | COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL); |
3139 | #ifdef COMPILE_PCRE16 | #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32 |
3140 | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1); | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT); |
3141 | #endif | #endif |
3142 | OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0); | OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0); |
3143 | ||
# | Line 2829 if (common->nltype == NLTYPE_ANY || comm | Line 3178 if (common->nltype == NLTYPE_ANY || comm |
3178 | notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); | notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); |
3179 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); |
3180 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL); |
3181 | COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL); |
3182 | #ifdef COMPILE_PCRE16 | #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32 |
3183 | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT); |
3184 | #endif | #endif |
3185 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); |
3186 | JUMPHERE(notfoundnl); | JUMPHERE(notfoundnl); |
# | Line 2841 JUMPHERE(lastchar); | Line 3190 JUMPHERE(lastchar); |
3190 | JUMPHERE(firstchar); | JUMPHERE(firstchar); |
3191 | ||
3192 | if (firstline) | if (firstline) |
3193 | OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0); | OP1(SLJIT_MOV, STR_END, 0, TMP3, 0); |
3194 | } | } |
3195 | ||
3196 | static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks); | |
3197 | ||
3198 | static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline) | static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline) |
3199 | { | { |
3200 | DEFINE_COMPILER; | DEFINE_COMPILER; |
3201 | struct sljit_label *start; | struct sljit_label *start; |
3202 | struct sljit_jump *quit; | struct sljit_jump *quit; |
3203 | struct sljit_jump *found; | struct sljit_jump *found = NULL; |
3204 | jump_list *matches = NULL; | |
3205 | pcre_uint8 inverted_start_bits[32]; | |
3206 | int i; | |
3207 | #ifndef COMPILE_PCRE8 | #ifndef COMPILE_PCRE8 |
3208 | struct sljit_jump *jump; | struct sljit_jump *jump; |
3209 | #endif | #endif |
3210 | ||
3211 | for (i = 0; i < 32; ++i) | |
3212 | inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]); | |
3213 | ||
3214 | if (firstline) | if (firstline) |
3215 | { | { |
3216 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0); | SLJIT_ASSERT(common->first_line_end != 0); |
3217 | OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0); | |
3218 | OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end); | OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end); |
3219 | } | } |
3220 | ||
# | Line 2867 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P | Line 3225 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P |
3225 | if (common->utf) | if (common->utf) |
3226 | OP1(SLJIT_MOV, TMP3, 0, TMP1, 0); | OP1(SLJIT_MOV, TMP3, 0, TMP1, 0); |
3227 | #endif | #endif |
3228 | ||
3229 | if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches)) | |
3230 | { | |
3231 | #ifndef COMPILE_PCRE8 | #ifndef COMPILE_PCRE8 |
3232 | jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255); | jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255); |
3233 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255); |
3234 | JUMPHERE(jump); | JUMPHERE(jump); |
3235 | #endif | #endif |
3236 | OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7); | OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7); |
3237 | OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3); | OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3); |
3238 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits); | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits); |
3239 | OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0); | OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0); |
3240 | OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0); | OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0); |
3241 | found = JUMP(SLJIT_C_NOT_ZERO); | found = JUMP(SLJIT_C_NOT_ZERO); |
3242 | } | |
3243 | ||
3244 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
3245 | if (common->utf) | if (common->utf) |
3246 | OP1(SLJIT_MOV, TMP1, 0, TMP3, 0); | OP1(SLJIT_MOV, TMP1, 0, TMP3, 0); |
3247 | #endif | #endif |
3248 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); |
3249 | #if defined SUPPORT_UTF && defined COMPILE_PCRE8 | #ifdef SUPPORT_UTF |
3250 | #if defined COMPILE_PCRE8 | |
3251 | if (common->utf) | if (common->utf) |
3252 | { | { |
3253 | CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start); | CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start); |
3254 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0); | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0); |
3255 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); |
3256 | } | } |
3257 | #endif | #elif defined COMPILE_PCRE16 |
#if defined SUPPORT_UTF && defined COMPILE_PCRE16 | ||
3258 | if (common->utf) | if (common->utf) |
3259 | { | { |
3260 | CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start); | CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start); |
3261 | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00); | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00); |
3262 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800); |
3263 | COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL); |
3264 | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); |
3265 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); |
3266 | } | } |
3267 | #endif | #endif /* COMPILE_PCRE[8|16] */ |
3268 | #endif /* SUPPORT_UTF */ | |
3269 | JUMPTO(SLJIT_JUMP, start); | JUMPTO(SLJIT_JUMP, start); |
3270 | JUMPHERE(found); | if (found != NULL) |
3271 | JUMPHERE(found); | |
3272 | if (matches != NULL) | |
3273 | set_jumps(matches, LABEL()); | |
3274 | JUMPHERE(quit); | JUMPHERE(quit); |
3275 | ||
3276 | if (firstline) | if (firstline) |
3277 | OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0); | OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0); |
3278 | } | } |
3279 | ||
3280 | static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uchar req_char, BOOL caseless, BOOL has_firstchar) | static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uchar req_char, BOOL caseless, BOOL has_firstchar) |
# | Line 2920 struct sljit_jump *alreadyfound; | Line 3286 struct sljit_jump *alreadyfound; |
3286 | struct sljit_jump *found; | struct sljit_jump *found; |
3287 | struct sljit_jump *foundoc = NULL; | struct sljit_jump *foundoc = NULL; |
3288 | struct sljit_jump *notfound; | struct sljit_jump *notfound; |
3289 | pcre_uchar oc, bit; | pcre_uint32 oc, bit; |
3290 | ||
3291 | SLJIT_ASSERT(common->req_char_ptr != 0); | SLJIT_ASSERT(common->req_char_ptr != 0); |
3292 | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr); | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr); |
# | Line 2951 if (req_char == oc) | Line 3317 if (req_char == oc) |
3317 | else | else |
3318 | { | { |
3319 | bit = req_char ^ oc; | bit = req_char ^ oc; |
3320 | if (ispowerof2(bit)) | if (is_powerof2(bit)) |
3321 | { | { |
3322 | OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit); | OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit); |
3323 | found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit); | found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit); |
# | Line 2987 GET_LOCAL_BASE(TMP3, 0, 0); | Line 3353 GET_LOCAL_BASE(TMP3, 0, 0); |
3353 | /* Drop frames until we reach STACK_TOP. */ | /* Drop frames until we reach STACK_TOP. */ |
3354 | mainloop = LABEL(); | mainloop = LABEL(); |
3355 | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0); | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0); |
3356 | jump = CMP(SLJIT_C_SIG_LESS_EQUAL, TMP2, 0, SLJIT_IMM, frame_end); | OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0); |
3357 | jump = JUMP(SLJIT_C_SIG_LESS_EQUAL); | |
3358 | ||
3359 | OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0); | OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0); |
3360 | OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w)); | OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw)); |
3361 | OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_w), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_w)); | OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw)); |
3362 | OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_w)); | OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw)); |
3363 | JUMPTO(SLJIT_JUMP, mainloop); | JUMPTO(SLJIT_JUMP, mainloop); |
3364 | ||
3365 | JUMPHERE(jump); | JUMPHERE(jump); |
3366 | jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end); | jump = JUMP(SLJIT_C_SIG_LESS); |
3367 | /* End of dropping frames. */ | /* End of dropping frames. */ |
3368 | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); |
3369 | ||
3370 | JUMPHERE(jump); | JUMPHERE(jump); |
3371 | jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin); | OP1(SLJIT_NEG, TMP2, 0, TMP2, 0); |
3372 | /* Set string begin. */ | OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0); |
3373 | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w)); | OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw)); |
3374 | OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w)); | OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw)); |
OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), TMP2, 0); | ||
JUMPTO(SLJIT_JUMP, mainloop); | ||
JUMPHERE(jump); | ||
if (common->mark_ptr != 0) | ||
{ | ||
jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setmark); | ||
OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w)); | ||
OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w)); | ||
OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0); | ||
JUMPTO(SLJIT_JUMP, mainloop); | ||
JUMPHERE(jump); | ||
} | ||
/* Unknown command. */ | ||
OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w)); | ||
3375 | JUMPTO(SLJIT_JUMP, mainloop); | JUMPTO(SLJIT_JUMP, mainloop); |
3376 | } | } |
3377 | ||
# | Line 3028 static void check_wordboundary(compiler_ | Line 3379 static void check_wordboundary(compiler_ |
3379 | { | { |
3380 | DEFINE_COMPILER; | DEFINE_COMPILER; |
3381 | struct sljit_jump *skipread; | struct sljit_jump *skipread; |
3382 | jump_list *skipread_list = NULL; | |
3383 | #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF | #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF |
3384 | struct sljit_jump *jump; | struct sljit_jump *jump; |
3385 | #endif | #endif |
# | Line 3053 if (common->use_ucp) | Line 3405 if (common->use_ucp) |
3405 | add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL)); | add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL)); |
3406 | OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll); | OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll); |
3407 | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll); | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll); |
3408 | COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL); |
3409 | OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll); | OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll); |
3410 | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd); | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd); |
3411 | COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL); | OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL); |
3412 | JUMPHERE(jump); | JUMPHERE(jump); |
3413 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0); |
3414 | } | } |
# | Line 3085 else | Line 3437 else |
3437 | JUMPHERE(skipread); | JUMPHERE(skipread); |
3438 | ||
3439 | OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0); | OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0); |
3440 | skipread = check_str_end(common); | check_str_end(common, &skipread_list); |
3441 | peek_char(common); | peek_char(common); |
3442 | ||
3443 | /* Testing char type. This is a code duplication. */ | /* Testing char type. This is a code duplication. */ |
# | Line 3097 if (common->use_ucp) | Line 3449 if (common->use_ucp) |
3449 | add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL)); | add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL)); |
3450 | OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll); | OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll); |
3451 | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll); | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll); |
3452 | COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL); |
3453 | OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll); | OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll); |
3454 | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd); | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd); |
3455 | COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL); | OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL); |
3456 | JUMPHERE(jump); | JUMPHERE(jump); |
3457 | } | } |
3458 | else | else |
# | Line 3126 else | Line 3478 else |
3478 | JUMPHERE(jump); | JUMPHERE(jump); |
3479 | #endif /* COMPILE_PCRE8 */ | #endif /* COMPILE_PCRE8 */ |
3480 | } | } |
3481 | JUMPHERE(skipread); | set_jumps(skipread_list, LABEL()); |
3482 | ||
3483 | OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1); | OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1); |
3484 | sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0); | sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0); |
# | Line 3181 switch(ranges[0]) | Line 3533 switch(ranges[0]) |
3533 | } | } |
3534 | return TRUE; | return TRUE; |
3535 | } | } |
3536 | if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2])) | |
3537 | { | |
3538 | if (readch) | |
3539 | read_char(common); | |
3540 | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]); | |
3541 | OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]); | |
3542 | add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4])); | |
3543 | return TRUE; | |
3544 | } | |
3545 | return FALSE; | return FALSE; |
3546 | ||
3547 | default: | default: |
# | Line 3194 int i, bit, length; | Line 3555 int i, bit, length; |
3555 | const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes; | const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes; |
3556 | ||
3557 | bit = ctypes[0] & flag; | bit = ctypes[0] & flag; |
3558 | ranges[0] = -1; | |
3559 | ranges[1] = bit != 0 ? 1 : 0; | ranges[1] = bit != 0 ? 1 : 0; |
3560 | length = 0; | length = 0; |
3561 | ||
# | Line 3201 for (i = 1; i < 256; i++) | Line 3563 for (i = 1; i < 256; i++) |
3563 | if ((ctypes[i] & flag) != bit) | if ((ctypes[i] & flag) != bit) |
3564 | { | { |
3565 | if (length >= MAX_RANGE_SIZE) | if (length >= MAX_RANGE_SIZE) |
{ | ||
ranges[0] = -1; | ||
3566 | return; | return; |
} | ||
3567 | ranges[2 + length] = i; | ranges[2 + length] = i; |
3568 | length++; | length++; |
3569 | bit ^= flag; | bit ^= flag; |
# | Line 3213 for (i = 1; i < 256; i++) | Line 3572 for (i = 1; i < 256; i++) |
3572 | if (bit != 0) | if (bit != 0) |
3573 | { | { |
3574 | if (length >= MAX_RANGE_SIZE) | if (length >= MAX_RANGE_SIZE) |
{ | ||
ranges[0] = -1; | ||
3575 | return; | return; |
} | ||
3576 | ranges[2 + length] = 256; | ranges[2 + length] = 256; |
3577 | length++; | length++; |
3578 | } | } |
# | Line 3276 sljit_emit_fast_enter(compiler, RETURN_A | Line 3632 sljit_emit_fast_enter(compiler, RETURN_A |
3632 | ||
3633 | OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a); | OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a); |
3634 | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a); | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a); |
3635 | COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL); |
3636 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a); |
3637 | #if defined SUPPORT_UTF || defined COMPILE_PCRE16 | #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32 |
3638 | #ifdef COMPILE_PCRE8 | #ifdef COMPILE_PCRE8 |
3639 | if (common->utf) | if (common->utf) |
3640 | { | { |
3641 | #endif | #endif |
3642 | COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); |
3643 | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1); | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1); |
3644 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a); |
3645 | #ifdef COMPILE_PCRE8 | #ifdef COMPILE_PCRE8 |
3646 | } | } |
3647 | #endif | #endif |
3648 | #endif /* SUPPORT_UTF || COMPILE_PCRE16 */ | #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */ |
3649 | COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); |
3650 | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); |
3651 | } | } |
3652 | ||
# | Line 3302 DEFINE_COMPILER; | Line 3658 DEFINE_COMPILER; |
3658 | sljit_emit_fast_enter(compiler, RETURN_ADDR, 0); | sljit_emit_fast_enter(compiler, RETURN_ADDR, 0); |
3659 | ||
3660 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09); |
3661 | COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL); |
3662 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20); |
3663 | COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); |
3664 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0); |
3665 | #if defined SUPPORT_UTF || defined COMPILE_PCRE16 | #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32 |
3666 | #ifdef COMPILE_PCRE8 | #ifdef COMPILE_PCRE8 |
3667 | if (common->utf) | if (common->utf) |
3668 | { | { |
3669 | #endif | #endif |
3670 | COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); |
3671 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680); |
3672 | COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); |
3673 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e); |
3674 | COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); |
3675 | OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000); | OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000); |
3676 | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000); | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000); |
3677 | COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL); | OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL); |
3678 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000); |
3679 | COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); |
3680 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000); |
3681 | COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); |
3682 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000); |
3683 | #ifdef COMPILE_PCRE8 | #ifdef COMPILE_PCRE8 |
3684 | } | } |
3685 | #endif | #endif |
3686 | #endif /* SUPPORT_UTF || COMPILE_PCRE16 */ | #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */ |
3687 | COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); |
3688 | ||
3689 | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); |
3690 | } | } |
# | Line 3342 sljit_emit_fast_enter(compiler, RETURN_A | Line 3698 sljit_emit_fast_enter(compiler, RETURN_A |
3698 | ||
3699 | OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a); | OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a); |
3700 | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a); | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a); |
3701 | COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL); |
3702 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a); |
3703 | #if defined SUPPORT_UTF || defined COMPILE_PCRE16 | #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32 |
3704 | #ifdef COMPILE_PCRE8 | #ifdef COMPILE_PCRE8 |
3705 | if (common->utf) | if (common->utf) |
3706 | { | { |
3707 | #endif | #endif |
3708 | COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); |
3709 | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1); | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1); |
3710 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a); |
3711 | #ifdef COMPILE_PCRE8 | #ifdef COMPILE_PCRE8 |
3712 | } | } |
3713 | #endif | #endif |
3714 | #endif /* SUPPORT_UTF || COMPILE_PCRE16 */ | #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */ |
3715 | COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); |
3716 | ||
3717 | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); |
3718 | } | } |
# | Line 3442 sljit_emit_fast_return(compiler, RETURN_ | Line 3798 sljit_emit_fast_return(compiler, RETURN_ |
3798 | ||
3799 | #if defined SUPPORT_UTF && defined SUPPORT_UCP | #if defined SUPPORT_UTF && defined SUPPORT_UCP |
3800 | ||
3801 | static const pcre_uchar *SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1) | static const pcre_uchar * SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1) |
3802 | { | { |
3803 | /* This function would be ineffective to do in JIT level. */ | /* This function would be ineffective to do in JIT level. */ |
3804 | int c1, c2; | pcre_uint32 c1, c2; |
3805 | const pcre_uchar *src2 = args->uchar_ptr; | const pcre_uchar *src2 = args->uchar_ptr; |
3806 | const pcre_uchar *end2 = args->end; | const pcre_uchar *end2 = args->end; |
3807 | const ucd_record *ur; | |
3808 | const pcre_uint32 *pp; | |
3809 | ||
3810 | while (src1 < end1) | while (src1 < end1) |
3811 | { | { |
# | Line 3455 while (src1 < end1) | Line 3813 while (src1 < end1) |
3813 | return (pcre_uchar*)1; | return (pcre_uchar*)1; |
3814 | GETCHARINC(c1, src1); | GETCHARINC(c1, src1); |
3815 | GETCHARINC(c2, src2); | GETCHARINC(c2, src2); |
3816 | if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return NULL; | ur = GET_UCD(c2); |
3817 | if (c1 != c2 && c1 != c2 + ur->other_case) | |
3818 | { | |
3819 | pp = PRIV(ucd_caseless_sets) + ur->caseset; | |
3820 | for (;;) | |
3821 | { | |
3822 | if (c1 < *pp) return NULL; | |
3823 | if (c1 == *pp++) break; | |
3824 | } | |
3825 | } | |
3826 | } | } |
3827 | return src2; | return src2; |
3828 | } | } |
# | Line 3477 if (caseless && char_has_othercase(commo | Line 3844 if (caseless && char_has_othercase(commo |
3844 | othercasebit = char_get_othercase_bit(common, cc); | othercasebit = char_get_othercase_bit(common, cc); |
3845 | SLJIT_ASSERT(othercasebit); | SLJIT_ASSERT(othercasebit); |
3846 | /* Extracting bit difference info. */ | /* Extracting bit difference info. */ |
3847 | #ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 |
3848 | othercasechar = cc + (othercasebit >> 8); | othercasechar = cc + (othercasebit >> 8); |
3849 | othercasebit &= 0xff; | othercasebit &= 0xff; |
3850 | #else | #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32 |
3851 | #ifdef COMPILE_PCRE16 | /* Note that this code only handles characters in the BMP. If there |
3852 | ever are characters outside the BMP whose othercase differs in only one | |
3853 | bit from itself (there currently are none), this code will need to be | |
3854 | revised for COMPILE_PCRE32. */ | |
3855 | othercasechar = cc + (othercasebit >> 9); | othercasechar = cc + (othercasebit >> 9); |
3856 | if ((othercasebit & 0x100) != 0) | if ((othercasebit & 0x100) != 0) |
3857 | othercasebit = (othercasebit & 0xff) << 8; | othercasebit = (othercasebit & 0xff) << 8; |
3858 | else | else |
3859 | othercasebit &= 0xff; | othercasebit &= 0xff; |
3860 | #endif | #endif /* COMPILE_PCRE[8|16|32] */ |
#endif | ||
3861 | } | } |
3862 | ||
3863 | if (context->sourcereg == -1) | if (context->sourcereg == -1) |
3864 | { | { |
3865 | #ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 |
3866 | #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED | #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED |
3867 | if (context->length >= 4) | if (context->length >= 4) |
3868 | OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length); | OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length); |
# | Line 3502 if (context->sourcereg == -1) | Line 3871 if (context->sourcereg == -1) |
3871 | else | else |
3872 | #endif | #endif |
3873 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length); | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length); |
3874 | #else | #elif defined COMPILE_PCRE16 |
#ifdef COMPILE_PCRE16 | ||
3875 | #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED | #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED |
3876 | if (context->length >= 4) | if (context->length >= 4) |
3877 | OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length); | OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length); |
3878 | else | else |
3879 | #endif | #endif |
3880 | OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length); | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length); |
3881 | #endif | #elif defined COMPILE_PCRE32 |
3882 | #endif /* COMPILE_PCRE8 */ | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length); |
3883 | #endif /* COMPILE_PCRE[8|16|32] */ | |
3884 | context->sourcereg = TMP2; | context->sourcereg = TMP2; |
3885 | } | } |
3886 | ||
# | Line 3525 do | Line 3894 do |
3894 | #endif | #endif |
3895 | ||
3896 | context->length -= IN_UCHARS(1); | context->length -= IN_UCHARS(1); |
3897 | #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED | #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16) |
3898 | ||
3899 | /* Unaligned read is supported. */ | /* Unaligned read is supported. */ |
3900 | if (othercasebit != 0 && othercasechar == cc) | if (othercasebit != 0 && othercasechar == cc) |
# | Line 3540 do | Line 3909 do |
3909 | } | } |
3910 | context->ucharptr++; | context->ucharptr++; |
3911 | ||
3912 | #ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 |
3913 | if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1)) | if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1)) |
3914 | #else | #else |
3915 | if (context->ucharptr >= 2 || context->length == 0) | if (context->ucharptr >= 2 || context->length == 0) |
# | Line 3548 do | Line 3917 do |
3917 | { | { |
3918 | if (context->length >= 4) | if (context->length >= 4) |
3919 | OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length); | OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length); |
#ifdef COMPILE_PCRE8 | ||
3920 | else if (context->length >= 2) | else if (context->length >= 2) |
3921 | OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length); | OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length); |
3922 | #if defined COMPILE_PCRE8 | |
3923 | else if (context->length >= 1) | else if (context->length >= 1) |
3924 | OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length); | OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length); |
3925 | #else | #endif /* COMPILE_PCRE8 */ |
else if (context->length >= 2) | ||
OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length); | ||
#endif | ||
3926 | context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1; | context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1; |
3927 | ||
3928 | switch(context->ucharptr) | switch(context->ucharptr) |
# | Line 3590 do | Line 3956 do |
3956 | ||
3957 | #else | #else |
3958 | ||
3959 | /* Unaligned read is unsupported. */ | /* Unaligned read is unsupported or in 32 bit mode. */ |
3960 | #ifdef COMPILE_PCRE8 | if (context->length >= 1) |
3961 | if (context->length > 0) | OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length); |
3962 | OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length); | |
#else | ||
if (context->length > 0) | ||
OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length); | ||
#endif | ||
3963 | context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1; | context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1; |
3964 | ||
3965 | if (othercasebit != 0 && othercasechar == cc) | if (othercasebit != 0 && othercasechar == cc) |
# | Line 3642 return cc; | Line 4004 return cc; |
4004 | } \ | } \ |
4005 | charoffset = (value); | charoffset = (value); |
4006 | ||
4007 | static void compile_xclass_trypath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks) | static void compile_xclass_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks) |
4008 | { | { |
4009 | DEFINE_COMPILER; | DEFINE_COMPILER; |
4010 | jump_list *found = NULL; | jump_list *found = NULL; |
4011 | jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks; | jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks; |
4012 | unsigned int c; | pcre_int32 c, charoffset; |
4013 | int compares; | const pcre_uint32 *other_cases; |
4014 | struct sljit_jump *jump = NULL; | struct sljit_jump *jump = NULL; |
4015 | pcre_uchar *ccbegin; | pcre_uchar *ccbegin; |
4016 | int compares, invertcmp, numberofcmps; | |
4017 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
4018 | BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE; | BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE; |
4019 | BOOL charsaved = FALSE; | BOOL charsaved = FALSE; |
4020 | int typereg = TMP1, scriptreg = TMP1; | int typereg = TMP1, scriptreg = TMP1; |
4021 | unsigned int typeoffset; | pcre_int32 typeoffset; |
4022 | #endif | #endif |
int invertcmp, numberofcmps; | ||
unsigned int charoffset; | ||
4023 | ||
4024 | /* Although SUPPORT_UTF must be defined, we are | /* Although SUPPORT_UTF must be defined, we are |
4025 | not necessary in utf mode even in 8 bit mode. */ | not necessary in utf mode even in 8 bit mode. */ |
# | Line 3679 if ((*cc++ & XCL_MAP) != 0) | Line 4040 if ((*cc++ & XCL_MAP) != 0) |
4040 | { | { |
4041 | OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7); | OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7); |
4042 | OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3); | OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3); |
4043 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc); | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc); |
4044 | OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0); | OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0); |
4045 | OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0); | OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0); |
4046 | add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO)); | add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO)); |
# | Line 3756 while (*cc != XCL_END) | Line 4117 while (*cc != XCL_END) |
4117 | needschar = TRUE; | needschar = TRUE; |
4118 | break; | break; |
4119 | ||
4120 | case PT_CLIST: | |
4121 | case PT_UCNC: | |
4122 | needschar = TRUE; | |
4123 | break; | |
4124 | ||
4125 | default: | default: |
4126 | SLJIT_ASSERT_STOP(); | SLJIT_ASSERT_STOP(); |
4127 | break; | break; |
# | Line 3792 if (needstype || needsscript) | Line 4158 if (needstype || needsscript) |
4158 | { | { |
4159 | if (scriptreg == TMP1) | if (scriptreg == TMP1) |
4160 | { | { |
4161 | OP1(SLJIT_MOV, scriptreg, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script)); | OP1(SLJIT_MOV, scriptreg, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script)); |
4162 | OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3); | OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3); |
4163 | } | } |
4164 | else | else |
4165 | { | { |
4166 | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3); | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3); |
4167 | OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script)); | OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script)); |
4168 | OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0); | OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0); |
4169 | } | } |
4170 | } | } |
# | Line 3834 while (*cc != XCL_END) | Line 4200 while (*cc != XCL_END) |
4200 | if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE)) | if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE)) |
4201 | { | { |
4202 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset); |
4203 | COND_VALUE(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, numberofcmps == 0 ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_EQUAL); |
4204 | numberofcmps++; | numberofcmps++; |
4205 | } | } |
4206 | else if (numberofcmps > 0) | else if (numberofcmps > 0) |
4207 | { | { |
4208 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset); |
4209 | COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); |
4210 | jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp); | jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp); |
4211 | numberofcmps = 0; | numberofcmps = 0; |
4212 | } | } |
# | Line 3873 while (*cc != XCL_END) | Line 4239 while (*cc != XCL_END) |
4239 | if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE)) | if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE)) |
4240 | { | { |
4241 | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset); | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset); |
4242 | COND_VALUE(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL); | OP_FLAGS(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, numberofcmps == 0 ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_LESS_EQUAL); |
4243 | numberofcmps++; | numberofcmps++; |
4244 | } | } |
4245 | else if (numberofcmps > 0) | else if (numberofcmps > 0) |
4246 | { | { |
4247 | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset); | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset); |
4248 | COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL); | OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL); |
4249 | jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp); | jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp); |
4250 | numberofcmps = 0; | numberofcmps = 0; |
4251 | } | } |
# | Line 3910 while (*cc != XCL_END) | Line 4276 while (*cc != XCL_END) |
4276 | ||
4277 | case PT_LAMP: | case PT_LAMP: |
4278 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - typeoffset); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - typeoffset); |
4279 | COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL); |
4280 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ll - typeoffset); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ll - typeoffset); |
4281 | COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); |
4282 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lt - typeoffset); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lt - typeoffset); |
4283 | COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); |
4284 | jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp); | jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp); |
4285 | break; | break; |
4286 | ||
# | Line 3941 while (*cc != XCL_END) | Line 4307 while (*cc != XCL_END) |
4307 | } | } |
4308 | SET_CHAR_OFFSET(9); | SET_CHAR_OFFSET(9); |
4309 | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 13 - 9); | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 13 - 9); |
4310 | COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL); |
4311 | if (*cc == PT_SPACE) | if (*cc == PT_SPACE) |
4312 | JUMPHERE(jump); | JUMPHERE(jump); |
4313 | ||
4314 | SET_TYPE_OFFSET(ucp_Zl); | SET_TYPE_OFFSET(ucp_Zl); |
4315 | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl); | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl); |
4316 | COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL); | OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL); |
4317 | jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp); | jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp); |
4318 | break; | break; |
4319 | ||
4320 | case PT_WORD: | case PT_WORD: |
4321 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE - charoffset); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE - charoffset); |
4322 | COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL); |
4323 | /* ... fall through */ | /* Fall through. */ |
4324 | ||
4325 | case PT_ALNUM: | case PT_ALNUM: |
4326 | SET_TYPE_OFFSET(ucp_Ll); | SET_TYPE_OFFSET(ucp_Ll); |
4327 | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - ucp_Ll); | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - ucp_Ll); |
4328 | COND_VALUE((*cc == PT_ALNUM) ? SLJIT_MOV : SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL); | OP_FLAGS((*cc == PT_ALNUM) ? SLJIT_MOV : SLJIT_OR, TMP2, 0, (*cc == PT_ALNUM) ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_LESS_EQUAL); |
4329 | SET_TYPE_OFFSET(ucp_Nd); | SET_TYPE_OFFSET(ucp_Nd); |
4330 | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_No - ucp_Nd); | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_No - ucp_Nd); |
4331 | COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL); | OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL); |
4332 | jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp); | |
4333 | break; | |
4334 | ||
4335 | case PT_CLIST: | |
4336 | other_cases = PRIV(ucd_caseless_sets) + cc[1]; | |
4337 | ||
4338 | /* At least three characters are required. | |
4339 | Otherwise this case would be handled by the normal code path. */ | |
4340 | SLJIT_ASSERT(other_cases[0] != NOTACHAR && other_cases[1] != NOTACHAR && other_cases[2] != NOTACHAR); | |
4341 | SLJIT_ASSERT(other_cases[0] < other_cases[1] && other_cases[1] < other_cases[2]); | |
4342 | ||
4343 | /* Optimizing character pairs, if their difference is power of 2. */ | |
4344 | if (is_powerof2(other_cases[1] ^ other_cases[0])) | |
4345 | { | |
4346 | if (charoffset == 0) | |
4347 | OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]); | |
4348 | else | |
4349 | { | |
4350 | OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset); | |
4351 | OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]); | |
4352 | } | |
4353 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[1]); | |
4354 | OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL); | |
4355 | other_cases += 2; | |
4356 | } | |
4357 | else if (is_powerof2(other_cases[2] ^ other_cases[1])) | |
4358 | { | |
4359 | if (charoffset == 0) | |
4360 | OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[2] ^ other_cases[1]); | |
4361 | else | |
4362 | { | |
4363 | OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset); | |
4364 | OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]); | |
4365 | } | |
4366 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[2]); | |
4367 | OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL); | |
4368 | ||
4369 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, other_cases[0] - charoffset); | |
4370 | OP_FLAGS(SLJIT_OR | ((other_cases[3] == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); | |
4371 | ||
4372 | other_cases += 3; | |
4373 | } | |
4374 | else | |
4375 | { | |
4376 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset); | |
4377 | OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL); | |
4378 | } | |
4379 | ||
4380 | while (*other_cases != NOTACHAR) | |
4381 | { | |
4382 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset); | |
4383 | OP_FLAGS(SLJIT_OR | ((*other_cases == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); | |
4384 | } | |
4385 | jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp); | |
4386 | break; | |
4387 | ||
4388 | case PT_UCNC: | |
4389 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset); | |
4390 | OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL); | |
4391 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset); | |
4392 | OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); | |
4393 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset); | |
4394 | OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL); | |
4395 | ||
4396 | SET_CHAR_OFFSET(0xa0); | |
4397 | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset); | |
4398 | OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL); | |
4399 | SET_CHAR_OFFSET(0); | |
4400 | OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0); | |
4401 | OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL); | |
4402 | jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp); | jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp); |
4403 | break; | break; |
4404 | } | } |
# | Line 3983 if (found != NULL) | Line 4419 if (found != NULL) |
4419 | ||
4420 | #endif | #endif |
4421 | ||
4422 | static pcre_uchar *compile_char1_trypath(compiler_common *common, pcre_uchar type, pcre_uchar *cc, jump_list **backtracks) | static pcre_uchar *compile_char1_matchingpath(compiler_common *common, pcre_uchar type, pcre_uchar *cc, jump_list **backtracks) |
4423 | { | { |
4424 | DEFINE_COMPILER; | DEFINE_COMPILER; |
4425 | int length; | int length; |
4426 | unsigned int c, oc, bit; | unsigned int c, oc, bit; |
4427 | compare_context context; | compare_context context; |
4428 | struct sljit_jump *jump[4]; | struct sljit_jump *jump[4]; |
4429 | jump_list *end_list; | |
4430 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
4431 | struct sljit_label *label; | struct sljit_label *label; |
4432 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
# | Line 4058 switch(type) | Line 4495 switch(type) |
4495 | if (common->nltype == NLTYPE_FIXED && common->newline > 255) | if (common->nltype == NLTYPE_FIXED && common->newline > 255) |
4496 | { | { |
4497 | jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff); | jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff); |
4498 | end_list = NULL; | |
4499 | if (common->mode != JIT_PARTIAL_HARD_COMPILE) | if (common->mode != JIT_PARTIAL_HARD_COMPILE) |
4500 | jump[1] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); | add_jump(compiler, &end_list, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0)); |
4501 | else | else |
4502 | jump[1] = check_str_end(common); | check_str_end(common, &end_list); |
4503 | ||
4504 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); |
4505 | add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff)); | add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff)); |
4506 | if (jump[1] != NULL) | set_jumps(end_list, LABEL()); |
JUMPHERE(jump[1]); | ||
4507 | JUMPHERE(jump[0]); | JUMPHERE(jump[0]); |
4508 | } | } |
4509 | else | else |
# | Line 4080 switch(type) | Line 4517 switch(type) |
4517 | { | { |
4518 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); |
4519 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); |
4520 | #ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16 |
4521 | #if defined COMPILE_PCRE8 | |
4522 | jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0); | jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0); |
4523 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0); | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0); |
4524 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); |
4525 | #else /* COMPILE_PCRE8 */ | #elif defined COMPILE_PCRE16 |
#ifdef COMPILE_PCRE16 | ||
4526 | jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800); | jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800); |
4527 | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00); | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00); |
4528 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800); |
4529 | COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL); |
4530 | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); |
4531 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); |
4532 | #endif /* COMPILE_PCRE16 */ | #endif |
#endif /* COMPILE_PCRE8 */ | ||
4533 | JUMPHERE(jump[0]); | JUMPHERE(jump[0]); |
4534 | #endif /* COMPILE_PCRE[8|16] */ | |
4535 | return cc; | return cc; |