Parent Directory
|
Revision Log
|
Patch
revision 958 by zherczeg, Wed Apr 11 10:19:10 2012 UTC | revision 1596 by zherczeg, Wed Aug 26 13:44:24 2015 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 |
53 | system files. */ | system files. */ |
54 | ||
55 | #define SLJIT_MALLOC(size) (PUBL(malloc))(size) | #define SLJIT_MALLOC(size, allocator_data) (PUBL(malloc))(size) |
56 | #define SLJIT_FREE(ptr) (PUBL(free))(ptr) | #define SLJIT_FREE(ptr, allocator_data) (PUBL(free))(ptr) |
57 | #define SLJIT_CONFIG_AUTO 1 | #define SLJIT_CONFIG_AUTO 1 |
58 | #define SLJIT_CONFIG_STATIC 1 | #define SLJIT_CONFIG_STATIC 1 |
59 | #define SLJIT_VERBOSE 0 | #define SLJIT_VERBOSE 0 |
# | 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 82 The code generator follows the recursive | Line 94 The code generator follows the recursive |
94 | expressions. The basic blocks of regular expressions are condition checkers | expressions. The basic blocks of regular expressions are condition checkers |
95 | whose execute different commands depending on the result of the condition check. | whose execute different commands depending on the result of the condition check. |
96 | The relationship between the operators can be horizontal (concatenation) and | The relationship between the operators can be horizontal (concatenation) and |
97 | vertical (sub-expression) (See struct fallback_common for more details). | vertical (sub-expression) (See struct backtrack_common for more details). |
98 | ||
99 | 'ab' - 'a' and 'b' regexps are concatenated | 'ab' - 'a' and 'b' regexps are concatenated |
100 | 'a+' - 'a' is the sub-expression of the '+' operator | 'a+' - 'a' is the sub-expression of the '+' operator |
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 hot 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 'fallback' 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 hot path. | branches on the matching path. |
107 | ||
108 | Greedy star operator (*) : | Greedy star operator (*) : |
109 | Hot path: match happens. | Matching path: match happens. |
110 | Fallback path: match failed. | Backtrack path: match failed. |
111 | Non-greedy star operator (*?) : | Non-greedy star operator (*?) : |
112 | Hot path: no need to perform a match. | Matching path: no need to perform a match. |
113 | Fallback 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 |
116 | with two alternatives. Let A, B, C, D are arbirary regular expressions, and | with two alternatives. Let A, B, C, D are arbirary regular expressions, and |
# | 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 hot path | A matching path |
124 | '(' hot path (pushing arguments to the stack) | '(' matching path (pushing arguments to the stack) |
125 | B hot path | B matching path |
126 | ')' hot path (pushing arguments to the stack) | ')' matching path (pushing arguments to the stack) |
127 | D hot path | D matching path |
128 | return with successful match | return with successful match |
129 | ||
130 | D fallback path | D backtrack path |
131 | ')' fallback path (If we arrived from "C" jump to the fallback of "C") | ')' backtrack path (If we arrived from "C" jump to the backtrack of "C") |
132 | B fallback path | B backtrack path |
133 | C expected path | C expected path |
134 | jump to D hot path | jump to D matching path |
135 | C fallback path | C backtrack path |
136 | A fallback path | A backtrack path |
137 | ||
138 | Notice, that the order of fallback code paths are the opposite of the fast | Notice, that the order of backtrack code paths are the opposite of the fast |
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 fallback code path. The fallback code 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 hot 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 fallback 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 fallback 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; | pcre_uint32 limit_match; |
172 | int calllimit; | int real_offset_count; |
173 | int offset_count; | |
174 | pcre_uint8 notbol; | pcre_uint8 notbol; |
175 | pcre_uint8 noteol; | pcre_uint8 noteol; |
176 | pcre_uint8 notempty; | pcre_uint8 notempty; |
# | Line 165 typedef struct jit_arguments { | Line 179 typedef struct jit_arguments { |
179 | ||
180 | typedef struct executable_functions { | typedef struct executable_functions { |
181 | void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES]; | void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES]; |
182 | void *read_only_data_heads[JIT_NUMBER_OF_COMPILE_MODES]; | |
183 | sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES]; | |
184 | PUBL(jit_callback) callback; | PUBL(jit_callback) callback; |
185 | void *userdata; | void *userdata; |
186 | sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES]; | pcre_uint32 top_bracket; |
187 | pcre_uint32 limit_match; | |
188 | } executable_functions; | } executable_functions; |
189 | ||
190 | typedef struct jump_list { | typedef struct jump_list { |
# | Line 175 typedef struct jump_list { | Line 192 typedef struct jump_list { |
192 | struct jump_list *next; | struct jump_list *next; |
193 | } jump_list; | } jump_list; |
194 | ||
enum stub_types { stack_alloc }; | ||
195 | typedef struct stub_list { | typedef struct stub_list { |
enum stub_types type; | ||
int data; | ||
196 | struct sljit_jump *start; | struct sljit_jump *start; |
197 | struct sljit_label *leave; | struct sljit_label *quit; |
198 | struct stub_list *next; | struct stub_list *next; |
199 | } stub_list; | } stub_list; |
200 | ||
201 | typedef struct label_addr_list { | |
202 | struct sljit_label *label; | |
203 | sljit_uw *update_addr; | |
204 | struct label_addr_list *next; | |
205 | } label_addr_list; | |
206 | ||
207 | enum frame_types { | |
208 | no_frame = -1, | |
209 | no_stack = -2 | |
210 | }; | |
211 | ||
212 | enum control_types { | |
213 | type_mark = 0, | |
214 | type_then_trap = 1 | |
215 | }; | |
216 | ||
217 | typedef int (SLJIT_CALL *jit_function)(jit_arguments *args); | typedef int (SLJIT_CALL *jit_function)(jit_arguments *args); |
218 | ||
219 | /* The following structure is the key data type for the recursive | /* The following structure is the key data type for the recursive |
220 | code generator. It is allocated by compile_hotpath, and contains | code generator. It is allocated by compile_matchingpath, and contains |
221 | the aguments for compile_fallbackpath. Must be the first member | the arguments for compile_backtrackingpath. Must be the first member |
222 | of its descendants. */ | of its descendants. */ |
223 | typedef struct fallback_common { | typedef struct backtrack_common { |
224 | /* Concatenation stack. */ | /* Concatenation stack. */ |
225 | struct fallback_common *prev; | struct backtrack_common *prev; |
226 | jump_list *nextfallbacks; | jump_list *nextbacktracks; |
227 | /* Internal stack (for component operators). */ | /* Internal stack (for component operators). */ |
228 | struct fallback_common *top; | struct backtrack_common *top; |
229 | jump_list *topfallbacks; | jump_list *topbacktracks; |
230 | /* Opcode pointer. */ | /* Opcode pointer. */ |
231 | pcre_uchar *cc; | pcre_uchar *cc; |
232 | } fallback_common; | } backtrack_common; |
233 | ||
234 | typedef struct assert_fallback { | typedef struct assert_backtrack { |
235 | fallback_common common; | backtrack_common common; |
236 | jump_list *condfailed; | jump_list *condfailed; |
237 | /* Less than 0 (-1) if a frame is not needed. */ | /* Less than 0 if a frame is not needed. */ |
238 | int framesize; | int framesize; |
239 | /* Points to our private memory word on the stack. */ | /* Points to our private memory word on the stack. */ |
240 | int localptr; | int private_data_ptr; |
241 | /* For iterators. */ | /* For iterators. */ |
242 | struct sljit_label *hotpath; | struct sljit_label *matchingpath; |
243 | } assert_fallback; | } assert_backtrack; |
244 | ||
245 | typedef struct bracket_fallback { | typedef struct bracket_backtrack { |
246 | fallback_common common; | backtrack_common common; |
247 | /* Where to coninue if an alternative is successfully matched. */ | /* Where to coninue if an alternative is successfully matched. */ |
248 | struct sljit_label *althotpath; | struct sljit_label *alternative_matchingpath; |
249 | /* For rmin and rmax iterators. */ | /* For rmin and rmax iterators. */ |
250 | struct sljit_label *recursivehotpath; | struct sljit_label *recursive_matchingpath; |
251 | /* For greedy ? operator. */ | /* For greedy ? operator. */ |
252 | struct sljit_label *zerohotpath; | struct sljit_label *zero_matchingpath; |
253 | /* Contains the branches of a failed condition. */ | /* Contains the branches of a failed condition. */ |
254 | union { | union { |
255 | /* Both for OP_COND, OP_SCOND. */ | /* Both for OP_COND, OP_SCOND. */ |
256 | jump_list *condfailed; | jump_list *condfailed; |
257 | assert_fallback *assert; | assert_backtrack *assert; |
258 | /* For OP_ONCE. -1 if not needed. */ | /* For OP_ONCE. Less than 0 if not needed. */ |
259 | int framesize; | int framesize; |
260 | } u; | } u; |
261 | /* Points to our private memory word on the stack. */ | /* Points to our private memory word on the stack. */ |
262 | int localptr; | int private_data_ptr; |
263 | } bracket_fallback; | } bracket_backtrack; |
264 | ||
265 | typedef struct bracketpos_fallback { | typedef struct bracketpos_backtrack { |
266 | fallback_common common; | backtrack_common common; |
267 | /* Points to our private memory word on the stack. */ | /* Points to our private memory word on the stack. */ |
268 | int localptr; | int private_data_ptr; |
269 | /* Reverting stack is needed. */ | /* Reverting stack is needed. */ |
270 | int framesize; | int framesize; |
271 | /* Allocated stack size. */ | /* Allocated stack size. */ |
272 | int stacksize; | int stacksize; |
273 | } bracketpos_fallback; | } bracketpos_backtrack; |
274 | ||
275 | typedef struct braminzero_fallback { | typedef struct braminzero_backtrack { |
276 | fallback_common common; | backtrack_common common; |
277 | struct sljit_label *hotpath; | struct sljit_label *matchingpath; |
278 | } braminzero_fallback; | } braminzero_backtrack; |
279 | ||
280 | typedef struct iterator_fallback { | typedef struct iterator_backtrack { |
281 | fallback_common common; | backtrack_common common; |
282 | /* Next iteration. */ | /* Next iteration. */ |
283 | struct sljit_label *hotpath; | struct sljit_label *matchingpath; |
284 | } iterator_fallback; | } iterator_backtrack; |
285 | ||
286 | typedef struct recurse_entry { | typedef struct recurse_entry { |
287 | struct recurse_entry *next; | struct recurse_entry *next; |
# | Line 261 typedef struct recurse_entry { | Line 290 typedef struct recurse_entry { |
290 | /* Collects the calls until the function is not created. */ | /* Collects the calls until the function is not created. */ |
291 | jump_list *calls; | jump_list *calls; |
292 | /* Points to the starting opcode. */ | /* Points to the starting opcode. */ |
293 | int start; | sljit_sw start; |
294 | } recurse_entry; | } recurse_entry; |
295 | ||
296 | typedef struct recurse_fallback { | typedef struct recurse_backtrack { |
297 | fallback_common common; | backtrack_common common; |
298 | } recurse_fallback; | BOOL inlined_pattern; |
299 | } recurse_backtrack; | |
300 | ||
301 | #define OP_THEN_TRAP OP_TABLE_LENGTH | |
302 | ||
303 | typedef struct then_trap_backtrack { | |
304 | backtrack_common common; | |
305 | /* If then_trap is not NULL, this structure contains the real | |
306 | then_trap for the backtracking path. */ | |
307 | struct then_trap_backtrack *then_trap; | |
308 | /* Points to the starting opcode. */ | |
309 | sljit_sw start; | |
310 | /* Exit point for the then opcodes of this alternative. */ | |
311 | jump_list *quit; | |
312 | /* Frame size of the current alternative. */ | |
313 | int framesize; | |
314 | } then_trap_backtrack; | |
315 | ||
316 | #define MAX_RANGE_SIZE 4 | |
317 | ||
318 | typedef struct compiler_common { | typedef struct compiler_common { |
319 | /* The sljit ceneric compiler. */ | |
320 | struct sljit_compiler *compiler; | struct sljit_compiler *compiler; |
321 | /* First byte code. */ | |
322 | pcre_uchar *start; | pcre_uchar *start; |
323 | /* Maps private data offset to each opcode. */ | |
324 | /* Opcode local area direct map. */ | sljit_si *private_data_ptrs; |
325 | int *localptrs; | /* Chain list of read-only data ptrs. */ |
326 | int cbraptr; | void *read_only_data_head; |
327 | /* OVector starting point. Must be divisible by 2. */ | /* Tells whether the capturing bracket is optimized. */ |
328 | pcre_uint8 *optimized_cbracket; | |
329 | /* Tells whether the starting offset is a target of then. */ | |
330 | pcre_uint8 *then_offsets; | |
331 | /* Current position where a THEN must jump. */ | |
332 | then_trap_backtrack *then_trap; | |
333 | /* Starting offset of private data for capturing brackets. */ | |
334 | int cbra_ptr; | |
335 | /* Output vector starting point. Must be divisible by 2. */ | |
336 | int ovector_start; | int ovector_start; |
337 | /* Last known position of the requested byte. */ | /* Last known position of the requested byte. */ |
338 | int req_char_ptr; | int req_char_ptr; |
339 | /* Head of the last recursion. */ | /* Head of the last recursion. */ |
340 | int recursive_head; | int recursive_head_ptr; |
341 | /* First inspected character for partial matching. */ | /* First inspected character for partial matching. */ |
342 | int start_used_ptr; | int start_used_ptr; |
343 | /* Starting pointer for partial soft matches. */ | /* Starting pointer for partial soft matches. */ |
# | Line 289 typedef struct compiler_common { | Line 346 typedef struct compiler_common { |
346 | int first_line_end; | int first_line_end; |
347 | /* Points to the marked string. */ | /* Points to the marked string. */ |
348 | int mark_ptr; | int mark_ptr; |
349 | /* Recursive control verb management chain. */ | |
350 | int control_head_ptr; | |
351 | /* Points to the last matched capture block index. */ | |
352 | int capture_last_ptr; | |
353 | /* Points to the starting position of the current match. */ | |
354 | int start_ptr; | |
355 | ||
356 | /* Other */ | /* Flipped and lower case tables. */ |
357 | const pcre_uint8 *fcc; | const pcre_uint8 *fcc; |
358 | sljit_w lcc; | sljit_sw lcc; |
359 | /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */ | |
360 | int mode; | int mode; |
361 | /* TRUE, when minlength is greater than 0. */ | |
362 | BOOL might_be_empty; | |
363 | /* \K is found in the pattern. */ | |
364 | BOOL has_set_som; | |
365 | /* (*SKIP:arg) is found in the pattern. */ | |
366 | BOOL has_skip_arg; | |
367 | /* (*THEN) is found in the pattern. */ | |
368 | BOOL has_then; | |
369 | /* Needs to know the start position anytime. */ | |
370 | BOOL needs_start_ptr; | |
371 | /* Currently in recurse or negative assert. */ | |
372 | BOOL local_exit; | |
373 | /* Currently in a positive assert. */ | |
374 | BOOL positive_assert; | |
375 | /* Newline control. */ | |
376 | int nltype; | int nltype; |
377 | pcre_uint32 nlmax; | |
378 | pcre_uint32 nlmin; | |
379 | int newline; | int newline; |
380 | int bsr_nltype; | int bsr_nltype; |
381 | pcre_uint32 bsr_nlmax; | |
382 | pcre_uint32 bsr_nlmin; | |
383 | /* Dollar endonly. */ | |
384 | int endonly; | int endonly; |
385 | BOOL has_set_som; | /* Tables. */ |
386 | sljit_w ctypes; | sljit_sw ctypes; |
387 | sljit_uw name_table; | /* Named capturing brackets. */ |
388 | sljit_w name_count; | pcre_uchar *name_table; |
389 | sljit_w name_entry_size; | sljit_sw name_count; |
390 | sljit_sw name_entry_size; | |
391 | ||
392 | /* Labels and jump lists. */ | /* Labels and jump lists. */ |
393 | struct sljit_label *partialmatchlabel; | struct sljit_label *partialmatchlabel; |
394 | struct sljit_label *leavelabel; | struct sljit_label *quit_label; |
395 | struct sljit_label *acceptlabel; | struct sljit_label *forced_quit_label; |
396 | struct sljit_label *accept_label; | |
397 | struct sljit_label *ff_newline_shortcut; | |
398 | stub_list *stubs; | stub_list *stubs; |
399 | label_addr_list *label_addrs; | |
400 | recurse_entry *entries; | recurse_entry *entries; |
401 | recurse_entry *currententry; | recurse_entry *currententry; |
402 | jump_list *partialmatch; | jump_list *partialmatch; |
403 | jump_list *leave; | jump_list *quit; |
404 | jump_list *positive_assert_quit; | |
405 | jump_list *forced_quit; | |
406 | jump_list *accept; | jump_list *accept; |
407 | jump_list *calllimit; | jump_list *calllimit; |
408 | jump_list *stackalloc; | jump_list *stackalloc; |
# | Line 323 typedef struct compiler_common { | Line 413 typedef struct compiler_common { |
413 | jump_list *vspace; | jump_list *vspace; |
414 | jump_list *casefulcmp; | jump_list *casefulcmp; |
415 | jump_list *caselesscmp; | jump_list *caselesscmp; |
416 | jump_list *reset_match; | |
417 | BOOL jscript_compat; | BOOL jscript_compat; |
418 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
419 | BOOL utf; | BOOL utf; |
420 | #ifdef SUPPORT_UCP | #ifdef SUPPORT_UCP |
421 | BOOL use_ucp; | BOOL use_ucp; |
422 | #endif | #endif |
jump_list *utfreadchar; | ||
423 | #ifdef COMPILE_PCRE8 | #ifdef COMPILE_PCRE8 |
424 | jump_list *utfreadchar; | |
425 | jump_list *utfreadchar16; | |
426 | jump_list *utfreadtype8; | jump_list *utfreadtype8; |
427 | #endif | #endif |
428 | #endif /* SUPPORT_UTF */ | #endif /* SUPPORT_UTF */ |
# | Line 347 typedef struct compare_context { | Line 439 typedef struct compare_context { |
439 | #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED | #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED |
440 | int ucharptr; | int ucharptr; |
441 | union { | union { |
442 | sljit_i asint; | sljit_si asint; |
443 | sljit_uh asushort; | sljit_uh asushort; |
444 | #ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 |
445 | sljit_ub asbyte; | sljit_ub asbyte; |
446 | sljit_ub asuchars[4]; | sljit_ub asuchars[4]; |
447 | #else | #elif defined COMPILE_PCRE16 |
#ifdef COMPILE_PCRE16 | ||
448 | sljit_uh asuchars[2]; | sljit_uh asuchars[2]; |
449 | #endif | #elif defined COMPILE_PCRE32 |
450 | sljit_ui asuchars[1]; | |
451 | #endif | #endif |
452 | } c; | } c; |
453 | union { | union { |
454 | sljit_i asint; | sljit_si asint; |
455 | sljit_uh asushort; | sljit_uh asushort; |
456 | #ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 |
457 | sljit_ub asbyte; | sljit_ub asbyte; |
458 | sljit_ub asuchars[4]; | sljit_ub asuchars[4]; |
459 | #else | #elif defined COMPILE_PCRE16 |
#ifdef COMPILE_PCRE16 | ||
460 | sljit_uh asuchars[2]; | sljit_uh asuchars[2]; |
461 | #endif | #elif defined COMPILE_PCRE32 |
462 | sljit_ui asuchars[1]; | |
463 | #endif | #endif |
464 | } oc; | } oc; |
465 | #endif | #endif |
466 | } compare_context; | } compare_context; |
467 | ||
enum { | ||
frame_end = 0, | ||
frame_setstrbegin = -1, | ||
frame_setmark = -2 | ||
}; | ||
468 | /* Undefine sljit macros. */ | /* Undefine sljit macros. */ |
469 | #undef CMP | #undef CMP |
470 | ||
471 | /* Used for accessing the elements of the stack. */ | /* Used for accessing the elements of the stack. */ |
472 | #define STACK(i) ((-(i) - 1) * (int)sizeof(sljit_w)) | #define STACK(i) ((-(i) - 1) * (int)sizeof(sljit_sw)) |
473 | ||
474 | #define TMP1 SLJIT_TEMPORARY_REG1 | #define TMP1 SLJIT_R0 |
475 | #define TMP2 SLJIT_TEMPORARY_REG3 | #define TMP2 SLJIT_R2 |
476 | #define TMP3 SLJIT_TEMPORARY_EREG2 | #define TMP3 SLJIT_R3 |
477 | #define STR_PTR SLJIT_SAVED_REG1 | #define STR_PTR SLJIT_S0 |
478 | #define STR_END SLJIT_SAVED_REG2 | #define STR_END SLJIT_S1 |
479 | #define STACK_TOP SLJIT_TEMPORARY_REG2 | #define STACK_TOP SLJIT_R1 |
480 | #define STACK_LIMIT SLJIT_SAVED_REG3 | #define STACK_LIMIT SLJIT_S2 |
481 | #define ARGUMENTS SLJIT_SAVED_EREG1 | #define COUNT_MATCH SLJIT_S3 |
482 | #define CALL_COUNT SLJIT_SAVED_EREG2 | #define ARGUMENTS SLJIT_S4 |
483 | #define RETURN_ADDR SLJIT_TEMPORARY_EREG1 | #define RETURN_ADDR SLJIT_R4 |
484 | ||
485 | /* Locals layout. */ | /* Local space layout. */ |
486 | /* These two locals can be used by the current opcode. */ | /* These two locals can be used by the current opcode. */ |
487 | #define LOCALS0 (0 * sizeof(sljit_w)) | #define LOCALS0 (0 * sizeof(sljit_sw)) |
488 | #define LOCALS1 (1 * sizeof(sljit_w)) | #define LOCALS1 (1 * sizeof(sljit_sw)) |
489 | /* Two local variables for possessive quantifiers (char1 cannot use them). */ | /* Two local variables for possessive quantifiers (char1 cannot use them). */ |
490 | #define POSSESSIVE0 (2 * sizeof(sljit_w)) | #define POSSESSIVE0 (2 * sizeof(sljit_sw)) |
491 | #define POSSESSIVE1 (3 * sizeof(sljit_w)) | #define POSSESSIVE1 (3 * sizeof(sljit_sw)) |
492 | /* Max limit of recursions. */ | /* Max limit of recursions. */ |
493 | #define CALL_LIMIT (4 * sizeof(sljit_w)) | #define LIMIT_MATCH (4 * sizeof(sljit_sw)) |
494 | /* The output vector is stored on the stack, and contains pointers | /* The output vector is stored on the stack, and contains pointers |
495 | to characters. The vector data is divided into two groups: the first | to characters. The vector data is divided into two groups: the first |
496 | group contains the start / end character pointers, and the second is | group contains the start / end character pointers, and the second is |
497 | 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. */ |
498 | #define OVECTOR_START (common->ovector_start) | #define OVECTOR_START (common->ovector_start) |
499 | #define OVECTOR(i) (OVECTOR_START + (i) * sizeof(sljit_w)) | #define OVECTOR(i) (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw)) |
500 | #define OVECTOR_PRIV(i) (common->cbraptr + (i) * sizeof(sljit_w)) | #define OVECTOR_PRIV(i) (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw)) |
501 | #define PRIV_DATA(cc) (common->localptrs[(cc) - common->start]) | #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start]) |
502 | ||
503 | #ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 |
504 | #define MOV_UCHAR SLJIT_MOV_UB | #define MOV_UCHAR SLJIT_MOV_UB |
505 | #define MOVU_UCHAR SLJIT_MOVU_UB | #define MOVU_UCHAR SLJIT_MOVU_UB |
506 | #else | #elif defined COMPILE_PCRE16 |
#ifdef COMPILE_PCRE16 | ||
507 | #define MOV_UCHAR SLJIT_MOV_UH | #define MOV_UCHAR SLJIT_MOV_UH |
508 | #define MOVU_UCHAR SLJIT_MOVU_UH | #define MOVU_UCHAR SLJIT_MOVU_UH |
509 | #elif defined COMPILE_PCRE32 | |
510 | #define MOV_UCHAR SLJIT_MOV_UI | |
511 | #define MOVU_UCHAR SLJIT_MOVU_UI | |
512 | #else | #else |
513 | #error Unsupported compiling mode | #error Unsupported compiling mode |
514 | #endif | #endif |
#endif | ||
515 | ||
516 | /* Shortcuts. */ | /* Shortcuts. */ |
517 | #define DEFINE_COMPILER \ | #define DEFINE_COMPILER \ |
# | Line 441 the start pointers when the end of the c | Line 528 the start pointers when the end of the c |
528 | sljit_set_label(sljit_emit_jump(compiler, (type)), (label)) | sljit_set_label(sljit_emit_jump(compiler, (type)), (label)) |
529 | #define JUMPHERE(jump) \ | #define JUMPHERE(jump) \ |
530 | sljit_set_label((jump), sljit_emit_label(compiler)) | sljit_set_label((jump), sljit_emit_label(compiler)) |
531 | #define SET_LABEL(jump, label) \ | |
532 | sljit_set_label((jump), (label)) | |
533 | #define CMP(type, src1, src1w, src2, src2w) \ | #define CMP(type, src1, src1w, src2, src2w) \ |
534 | sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)) | sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)) |
535 | #define CMPTO(type, src1, src1w, src2, src2w, label) \ | #define CMPTO(type, src1, src1w, src2, src2w, label) \ |
536 | 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)) |
537 | #define COND_VALUE(op, dst, dstw, type) \ | #define OP_FLAGS(op, dst, dstw, src, srcw, type) \ |
538 | sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type)) | sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type)) |
539 | #define GET_LOCAL_BASE(dst, dstw, offset) \ | #define GET_LOCAL_BASE(dst, dstw, offset) \ |
540 | sljit_get_local_base(compiler, (dst), (dstw), (offset)) | sljit_get_local_base(compiler, (dst), (dstw), (offset)) |
541 | ||
542 | static pcre_uchar* bracketend(pcre_uchar* cc) | #define READ_CHAR_MAX 0x7fffffff |
543 | ||
544 | static pcre_uchar *bracketend(pcre_uchar *cc) | |
545 | { | { |
546 | SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND)); | SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND)); |
547 | do cc += GET(cc, 1); while (*cc == OP_ALT); | do cc += GET(cc, 1); while (*cc == OP_ALT); |
# | Line 459 cc += 1 + LINK_SIZE; | Line 550 cc += 1 + LINK_SIZE; |
550 | return cc; | return cc; |
551 | } | } |
552 | ||
553 | static int no_alternatives(pcre_uchar *cc) | |
554 | { | |
555 | int count = 0; | |
556 | SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND)); | |
557 | do | |
558 | { | |
559 | cc += GET(cc, 1); | |
560 | count++; | |
561 | } | |
562 | while (*cc == OP_ALT); | |
563 | SLJIT_ASSERT(*cc >= OP_KET && *cc <= OP_KETRPOS); | |
564 | return count; | |
565 | } | |
566 | ||
567 | static int ones_in_half_byte[16] = { | |
568 | /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3, | |
569 | /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4 | |
570 | }; | |
571 | ||
572 | /* Functions whose might need modification for all new supported opcodes: | /* Functions whose might need modification for all new supported opcodes: |
573 | next_opcode | next_opcode |
574 | get_localspace | check_opcode_types |
575 | set_localptrs | set_private_data_ptrs |
576 | get_framesize | get_framesize |
577 | init_frame | init_frame |
578 | get_localsize | get_private_data_copy_length |
579 | copy_locals | copy_private_data |
580 | compile_hotpath | compile_matchingpath |
581 | compile_fallbackpath | compile_backtrackingpath |
582 | */ | */ |
583 | ||
584 | static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc) | static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc) |
# | Line 489 switch(*cc) | Line 599 switch(*cc) |
599 | case OP_WORDCHAR: | case OP_WORDCHAR: |
600 | case OP_ANY: | case OP_ANY: |
601 | case OP_ALLANY: | case OP_ALLANY: |
602 | case OP_NOTPROP: | |
603 | case OP_PROP: | |
604 | case OP_ANYNL: | case OP_ANYNL: |
605 | case OP_NOT_HSPACE: | case OP_NOT_HSPACE: |
606 | case OP_HSPACE: | case OP_HSPACE: |
# | Line 501 switch(*cc) | Line 613 switch(*cc) |
613 | case OP_CIRCM: | case OP_CIRCM: |
614 | case OP_DOLL: | case OP_DOLL: |
615 | 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: | ||
616 | case OP_CRSTAR: | case OP_CRSTAR: |
617 | case OP_CRMINSTAR: | case OP_CRMINSTAR: |
618 | case OP_CRPLUS: | case OP_CRPLUS: |
619 | case OP_CRMINPLUS: | case OP_CRMINPLUS: |
620 | case OP_CRQUERY: | case OP_CRQUERY: |
621 | case OP_CRMINQUERY: | case OP_CRMINQUERY: |
622 | case OP_CRRANGE: | |
623 | case OP_CRMINRANGE: | |
624 | case OP_CRPOSSTAR: | |
625 | case OP_CRPOSPLUS: | |
626 | case OP_CRPOSQUERY: | |
627 | case OP_CRPOSRANGE: | |
628 | case OP_CLASS: | |
629 | case OP_NCLASS: | |
630 | case OP_REF: | |
631 | case OP_REFI: | |
632 | case OP_DNREF: | |
633 | case OP_DNREFI: | |
634 | case OP_RECURSE: | |
635 | case OP_CALLOUT: | |
636 | case OP_ALT: | |
637 | case OP_KET: | |
638 | case OP_KETRMAX: | |
639 | case OP_KETRMIN: | |
640 | case OP_KETRPOS: | |
641 | case OP_REVERSE: | |
642 | case OP_ASSERT: | |
643 | case OP_ASSERT_NOT: | |
644 | case OP_ASSERTBACK: | |
645 | case OP_ASSERTBACK_NOT: | |
646 | case OP_ONCE: | |
647 | case OP_ONCE_NC: | |
648 | case OP_BRA: | |
649 | case OP_BRAPOS: | |
650 | case OP_CBRA: | |
651 | case OP_CBRAPOS: | |
652 | case OP_COND: | |
653 | case OP_SBRA: | |
654 | case OP_SBRAPOS: | |
655 | case OP_SCBRA: | |
656 | case OP_SCBRAPOS: | |
657 | case OP_SCOND: | |
658 | case OP_CREF: | |
659 | case OP_DNCREF: | |
660 | case OP_RREF: | |
661 | case OP_DNRREF: | |
662 | case OP_DEF: | case OP_DEF: |
663 | case OP_BRAZERO: | case OP_BRAZERO: |
664 | case OP_BRAMINZERO: | case OP_BRAMINZERO: |
665 | case OP_BRAPOSZERO: | case OP_BRAPOSZERO: |
666 | case OP_PRUNE: | |
667 | case OP_SKIP: | |
668 | case OP_THEN: | |
669 | case OP_COMMIT: | case OP_COMMIT: |
670 | case OP_FAIL: | case OP_FAIL: |
671 | case OP_ACCEPT: | case OP_ACCEPT: |
672 | case OP_ASSERT_ACCEPT: | case OP_ASSERT_ACCEPT: |
673 | case OP_CLOSE: | |
674 | case OP_SKIPZERO: | case OP_SKIPZERO: |
675 | return cc + 1; | return cc + PRIV(OP_lengths)[*cc]; |
case OP_ANYBYTE: | ||
#ifdef SUPPORT_UTF | ||
if (common->utf) return NULL; | ||
#endif | ||
return cc + 1; | ||
676 | ||
677 | case OP_CHAR: | case OP_CHAR: |
678 | case OP_CHARI: | case OP_CHARI: |
# | Line 543 switch(*cc) | Line 684 switch(*cc) |
684 | case OP_MINPLUS: | case OP_MINPLUS: |
685 | case OP_QUERY: | case OP_QUERY: |
686 | case OP_MINQUERY: | case OP_MINQUERY: |
687 | case OP_UPTO: | |
688 | case OP_MINUPTO: | |
689 | case OP_EXACT: | |
690 | case OP_POSSTAR: | case OP_POSSTAR: |
691 | case OP_POSPLUS: | case OP_POSPLUS: |
692 | case OP_POSQUERY: | case OP_POSQUERY: |
693 | case OP_POSUPTO: | |
694 | case OP_STARI: | case OP_STARI: |
695 | case OP_MINSTARI: | case OP_MINSTARI: |
696 | case OP_PLUSI: | case OP_PLUSI: |
697 | case OP_MINPLUSI: | case OP_MINPLUSI: |
698 | case OP_QUERYI: | case OP_QUERYI: |
699 | case OP_MINQUERYI: | case OP_MINQUERYI: |
700 | case OP_UPTOI: | |
701 | case OP_MINUPTOI: | |
702 | case OP_EXACTI: | |
703 | case OP_POSSTARI: | case OP_POSSTARI: |
704 | case OP_POSPLUSI: | case OP_POSPLUSI: |
705 | case OP_POSQUERYI: | case OP_POSQUERYI: |
706 | case OP_POSUPTOI: | |
707 | case OP_NOTSTAR: | case OP_NOTSTAR: |
708 | case OP_NOTMINSTAR: | case OP_NOTMINSTAR: |
709 | case OP_NOTPLUS: | case OP_NOTPLUS: |
710 | case OP_NOTMINPLUS: | case OP_NOTMINPLUS: |
711 | case OP_NOTQUERY: | case OP_NOTQUERY: |
712 | case OP_NOTMINQUERY: | case OP_NOTMINQUERY: |
713 | case OP_NOTUPTO: | |
714 | case OP_NOTMINUPTO: | |
715 | case OP_NOTEXACT: | |
716 | case OP_NOTPOSSTAR: | case OP_NOTPOSSTAR: |
717 | case OP_NOTPOSPLUS: | case OP_NOTPOSPLUS: |
718 | case OP_NOTPOSQUERY: | case OP_NOTPOSQUERY: |
719 | case OP_NOTPOSUPTO: | |
720 | case OP_NOTSTARI: | case OP_NOTSTARI: |
721 | case OP_NOTMINSTARI: | case OP_NOTMINSTARI: |
722 | case OP_NOTPLUSI: | case OP_NOTPLUSI: |
723 | case OP_NOTMINPLUSI: | case OP_NOTMINPLUSI: |
724 | case OP_NOTQUERYI: | case OP_NOTQUERYI: |
725 | 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: | ||
726 | case OP_NOTUPTOI: | case OP_NOTUPTOI: |
727 | case OP_NOTMINUPTOI: | case OP_NOTMINUPTOI: |
728 | case OP_NOTEXACTI: | case OP_NOTEXACTI: |
729 | case OP_NOTPOSSTARI: | |
730 | case OP_NOTPOSPLUSI: | |
731 | case OP_NOTPOSQUERYI: | |
732 | case OP_NOTPOSUPTOI: | case OP_NOTPOSUPTOI: |
733 | cc += 2 + IMM2_SIZE; | cc += PRIV(OP_lengths)[*cc]; |
734 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
735 | if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); | if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); |
736 | #endif | #endif |
737 | return cc; | return cc; |
738 | ||
739 | case OP_NOTPROP: | /* Special cases. */ |
740 | case OP_PROP: | case OP_TYPESTAR: |
741 | return cc + 1 + 2; | case OP_TYPEMINSTAR: |
742 | case OP_TYPEPLUS: | |
743 | case OP_TYPEMINPLUS: | |
744 | case OP_TYPEQUERY: | |
745 | case OP_TYPEMINQUERY: | |
746 | case OP_TYPEUPTO: | case OP_TYPEUPTO: |
747 | case OP_TYPEMINUPTO: | case OP_TYPEMINUPTO: |
748 | case OP_TYPEEXACT: | case OP_TYPEEXACT: |
749 | case OP_TYPEPOSSTAR: | |
750 | case OP_TYPEPOSPLUS: | |
751 | case OP_TYPEPOSQUERY: | |
752 | case OP_TYPEPOSUPTO: | case OP_TYPEPOSUPTO: |
753 | 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; | ||
case OP_CRRANGE: | ||
case OP_CRMINRANGE: | ||
return cc + 1 + 2 * IMM2_SIZE; | ||
754 | ||
755 | case OP_CLASS: | case OP_ANYBYTE: |
756 | case OP_NCLASS: | #ifdef SUPPORT_UTF |
757 | return cc + 1 + 32 / sizeof(pcre_uchar); | if (common->utf) return NULL; |
758 | #endif | |
759 | return cc + 1; | |
760 | ||
761 | #if defined SUPPORT_UTF || !defined COMPILE_PCRE8 | #if defined SUPPORT_UTF || !defined COMPILE_PCRE8 |
762 | case OP_XCLASS: | case OP_XCLASS: |
763 | return cc + GET(cc, 1); | return cc + GET(cc, 1); |
764 | #endif | #endif |
765 | ||
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; | ||
766 | case OP_MARK: | case OP_MARK: |
767 | case OP_PRUNE_ARG: | |
768 | case OP_SKIP_ARG: | |
769 | case OP_THEN_ARG: | |
770 | return cc + 1 + 2 + cc[1]; | return cc + 1 + 2 + cc[1]; |
771 | ||
772 | default: | default: |
773 | /* All opcodes are supported now! */ | |
774 | SLJIT_ASSERT_STOP(); | |
775 | return NULL; | return NULL; |
776 | } | } |
777 | } | } |
778 | ||
779 | static int get_localspace(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend) | static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend) |
780 | { | { |
781 | int localspace = 0; | int count; |
782 | pcre_uchar *alternative; | pcre_uchar *slot; |
783 | ||
784 | /* 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. */ |
785 | while (cc < ccend) | while (cc < ccend) |
786 | { | { |
# | Line 678 while (cc < ccend) | Line 788 while (cc < ccend) |
788 | { | { |
789 | case OP_SET_SOM: | case OP_SET_SOM: |
790 | common->has_set_som = TRUE; | common->has_set_som = TRUE; |
791 | common->might_be_empty = TRUE; | |
792 | cc += 1; | cc += 1; |
793 | break; | break; |
794 | ||
795 | case OP_ASSERT: | case OP_REF: |
796 | case OP_ASSERT_NOT: | case OP_REFI: |
797 | case OP_ASSERTBACK: | common->optimized_cbracket[GET2(cc, 1)] = 0; |
798 | 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); | ||
cc += 1 + LINK_SIZE; | ||
799 | break; | break; |
800 | ||
801 | case OP_CBRAPOS: | case OP_CBRAPOS: |
802 | case OP_SCBRAPOS: | case OP_SCBRAPOS: |
803 | localspace += sizeof(sljit_w); | common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0; |
804 | cc += 1 + LINK_SIZE + IMM2_SIZE; | cc += 1 + LINK_SIZE + IMM2_SIZE; |
805 | break; | break; |
806 | ||
807 | case OP_COND: | case OP_COND: |
808 | /* Might be a hidden SCOND. */ | case OP_SCOND: |
809 | alternative = cc + GET(cc, 1); | /* Only AUTO_CALLOUT can insert this opcode. We do |
810 | if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN) | not intend to support this case. */ |
811 | localspace += sizeof(sljit_w); | if (cc[1 + LINK_SIZE] == OP_CALLOUT) |
812 | return FALSE; | |
813 | cc += 1 + LINK_SIZE; | cc += 1 + LINK_SIZE; |
814 | break; | break; |
815 | ||
816 | case OP_CREF: | |
817 | common->optimized_cbracket[GET2(cc, 1)] = 0; | |
818 | cc += 1 + IMM2_SIZE; | |
819 | break; | |
820 | ||
821 | case OP_DNREF: | |
822 | case OP_DNREFI: | |
823 | case OP_DNCREF: | |
824 | count = GET2(cc, 1 + IMM2_SIZE); | |
825 | slot = common->name_table + GET2(cc, 1) * common->name_entry_size; | |
826 | while (count-- > 0) | |
827 | { | |
828 | common->optimized_cbracket[GET2(slot, 0)] = 0; | |
829 | slot += common->name_entry_size; | |
830 | } | |
831 | cc += 1 + 2 * IMM2_SIZE; | |
832 | break; | |
833 | ||
834 | case OP_RECURSE: | case OP_RECURSE: |
835 | /* Set its value only once. */ | /* Set its value only once. */ |
836 | if (common->recursive_head == 0) | if (common->recursive_head_ptr == 0) |
837 | { | { |
838 | common->recursive_head = common->ovector_start; | common->recursive_head_ptr = common->ovector_start; |
839 | common->ovector_start += sizeof(sljit_w); | common->ovector_start += sizeof(sljit_sw); |
840 | } | } |
841 | cc += 1 + LINK_SIZE; | cc += 1 + LINK_SIZE; |
842 | break; | break; |
843 | ||
844 | case OP_CALLOUT: | |
845 | if (common->capture_last_ptr == 0) | |
846 | { | |
847 | common->capture_last_ptr = common->ovector_start; | |
848 | common->ovector_start += sizeof(sljit_sw); | |
849 | } | |
850 | cc += 2 + 2 * LINK_SIZE; | |
851 | break; | |
852 | ||
853 | case OP_THEN_ARG: | |
854 | common->has_then = TRUE; | |
855 | common->control_head_ptr = 1; | |
856 | /* Fall through. */ | |
857 | ||
858 | case OP_PRUNE_ARG: | |
859 | common->needs_start_ptr = TRUE; | |
860 | /* Fall through. */ | |
861 | ||
862 | case OP_MARK: | case OP_MARK: |
863 | if (common->mark_ptr == 0) | if (common->mark_ptr == 0) |
864 | { | { |
865 | common->mark_ptr = common->ovector_start; | common->mark_ptr = common->ovector_start; |
866 | common->ovector_start += sizeof(sljit_w); | common->ovector_start += sizeof(sljit_sw); |
867 | } | } |
868 | cc += 1 + 2 + cc[1]; | cc += 1 + 2 + cc[1]; |
869 | break; | break; |
870 | ||
871 | case OP_THEN: | |
872 | common->has_then = TRUE; | |
873 | common->control_head_ptr = 1; | |
874 | /* Fall through. */ | |
875 | ||
876 | case OP_PRUNE: | |
877 | case OP_SKIP: | |
878 | common->needs_start_ptr = TRUE; | |
879 | cc += 1; | |
880 | break; | |
881 | ||
882 | case OP_SKIP_ARG: | |
883 | common->control_head_ptr = 1; | |
884 | common->has_skip_arg = TRUE; | |
885 | cc += 1 + 2 + cc[1]; | |
886 | break; | |
887 | ||
888 | default: | default: |
889 | cc = next_opcode(common, cc); | cc = next_opcode(common, cc); |
890 | if (cc == NULL) | if (cc == NULL) |
891 | return -1; | return FALSE; |
892 | break; | break; |
893 | } | } |
894 | } | } |
895 | return localspace; | return TRUE; |
896 | } | } |
897 | ||
898 | static void set_localptrs(compiler_common *common, int localptr, pcre_uchar *ccend) | static int get_class_iterator_size(pcre_uchar *cc) |
899 | { | { |
900 | pcre_uchar *cc = common->start; | switch(*cc) |
pcre_uchar *alternative; | ||
while (cc < ccend) | ||
901 | { | { |
902 | switch(*cc) | case OP_CRSTAR: |
903 | { | case OP_CRPLUS: |
904 | case OP_ASSERT: | return 2; |
case OP_ASSERT_NOT: | ||
case OP_ASSERTBACK: | ||
case OP_ASSERTBACK_NOT: | ||
case OP_ONCE: | ||
case OP_ONCE_NC: | ||
case OP_BRAPOS: | ||
case OP_SBRA: | ||
case OP_SBRAPOS: | ||
case OP_SCOND: | ||
common->localptrs[cc - common->start] = localptr; | ||
localptr += sizeof(sljit_w); | ||
cc += 1 + LINK_SIZE; | ||
break; | ||
905 | ||
906 | case OP_CBRAPOS: | case OP_CRMINSTAR: |
907 | case OP_SCBRAPOS: | case OP_CRMINPLUS: |
908 | common->localptrs[cc - common->start] = localptr; | case OP_CRQUERY: |
909 | localptr += sizeof(sljit_w); | case OP_CRMINQUERY: |
910 | cc += 1 + LINK_SIZE + IMM2_SIZE; | return 1; |
break; | ||
911 | ||
912 | case OP_COND: | case OP_CRRANGE: |
913 | /* Might be a hidden SCOND. */ | case OP_CRMINRANGE: |
914 | alternative = cc + GET(cc, 1); | if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE)) |
915 | if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN) | return 0; |
916 | { | return 2; |
917 | common->localptrs[cc - common->start] = localptr; | |
918 | localptr += sizeof(sljit_w); | default: |
919 | } | return 0; |
920 | cc += 1 + LINK_SIZE; | } |
921 | break; | } |
922 | ||
923 | static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin) | |
924 | { | |
925 | pcre_uchar *end = bracketend(begin); | |
926 | pcre_uchar *next; | |
927 | pcre_uchar *next_end; | |
928 | pcre_uchar *max_end; | |
929 | pcre_uchar type; | |
930 | sljit_sw length = end - begin; | |
931 | int min, max, i; | |
932 | ||
933 | /* Detect fixed iterations first. */ | |
934 | if (end[-(1 + LINK_SIZE)] != OP_KET) | |
935 | return FALSE; | |
936 | ||
937 | /* Already detected repeat. */ | |
938 | if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0) | |
939 | return TRUE; | |
940 | ||
941 | next = end; | |
942 | min = 1; | |
943 | while (1) | |
944 | { | |
945 | if (*next != *begin) | |
946 | break; | |
947 | next_end = bracketend(next); | |
948 | if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0) | |
949 | break; | |
950 | next = next_end; | |
951 | min++; | |
952 | } | |
953 | ||
954 | if (min == 2) | |
955 | return FALSE; | |
956 | ||
957 | max = 0; | |
958 | max_end = next; | |
959 | if (*next == OP_BRAZERO || *next == OP_BRAMINZERO) | |
960 | { | |
961 | type = *next; | |
962 | while (1) | |
963 | { | |
964 | if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin) | |
965 | break; | |
966 | next_end = bracketend(next + 2 + LINK_SIZE); | |
967 | if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0) | |
968 | break; | |
969 | next = next_end; | |
970 | max++; | |
971 | } | |
972 | ||
973 | if (next[0] == type && next[1] == *begin && max >= 1) | |
974 | { | |
975 | next_end = bracketend(next + 1); | |
976 | if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0) | |
977 | { | |
978 | for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE) | |
979 | if (*next_end != OP_KET) | |
980 | break; | |
981 | ||
982 | if (i == max) | |
983 | { | |
984 | common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end; | |
985 | common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO; | |
986 | /* +2 the original and the last. */ | |
987 | common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2; | |
988 | if (min == 1) | |
989 | return TRUE; | |
990 | min--; | |
991 | max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE); | |
992 | } | |
993 | } | |
994 | } | |
995 | } | |
996 | ||
997 | if (min >= 3) | |
998 | { | |
999 | common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end; | |
1000 | common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT; | |
1001 | common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min; | |
1002 | return TRUE; | |
1003 | } | |
1004 | ||
1005 | return FALSE; | |
1006 | } | |
1007 | ||
1008 | #define CASE_ITERATOR_PRIVATE_DATA_1 \ | |
1009 | case OP_MINSTAR: \ | |
1010 | case OP_MINPLUS: \ | |
1011 | case OP_QUERY: \ | |
1012 | case OP_MINQUERY: \ | |
1013 | case OP_MINSTARI: \ | |
1014 | case OP_MINPLUSI: \ | |
1015 | case OP_QUERYI: \ | |
1016 | case OP_MINQUERYI: \ | |
1017 | case OP_NOTMINSTAR: \ | |
1018 | case OP_NOTMINPLUS: \ | |
1019 | case OP_NOTQUERY: \ | |
1020 | case OP_NOTMINQUERY: \ | |
1021 | case OP_NOTMINSTARI: \ | |
1022 | case OP_NOTMINPLUSI: \ | |
1023 | case OP_NOTQUERYI: \ | |
1024 | case OP_NOTMINQUERYI: | |
1025 | ||
1026 | #define CASE_ITERATOR_PRIVATE_DATA_2A \ | |
1027 | case OP_STAR: \ | |
1028 | case OP_PLUS: \ | |
1029 | case OP_STARI: \ | |
1030 | case OP_PLUSI: \ | |
1031 | case OP_NOTSTAR: \ | |
1032 | case OP_NOTPLUS: \ | |
1033 | case OP_NOTSTARI: \ | |
1034 | case OP_NOTPLUSI: | |
1035 | ||
1036 | #define CASE_ITERATOR_PRIVATE_DATA_2B \ | |
1037 | case OP_UPTO: \ | |
1038 | case OP_MINUPTO: \ | |
1039 | case OP_UPTOI: \ | |
1040 | case OP_MINUPTOI: \ | |
1041 | case OP_NOTUPTO: \ | |
1042 | case OP_NOTMINUPTO: \ | |
1043 | case OP_NOTUPTOI: \ | |
1044 | case OP_NOTMINUPTOI: | |
1045 | ||
1046 | #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \ | |
1047 | case OP_TYPEMINSTAR: \ | |
1048 | case OP_TYPEMINPLUS: \ | |
1049 | case OP_TYPEQUERY: \ | |
1050 | case OP_TYPEMINQUERY: | |
1051 | ||
1052 | #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \ | |
1053 | case OP_TYPESTAR: \ | |
1054 | case OP_TYPEPLUS: | |
1055 | ||
1056 | #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \ | |
1057 | case OP_TYPEUPTO: \ | |
1058 | case OP_TYPEMINUPTO: | |
1059 | ||
1060 | static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend) | |
1061 | { | |
1062 | pcre_uchar *cc = common->start; | |
1063 | pcre_uchar *alternative; | |
1064 | pcre_uchar *end = NULL; | |
1065 | int private_data_ptr = *private_data_start; | |
1066 | int space, size, bracketlen; | |
1067 | BOOL repeat_check = TRUE; | |
1068 | ||
1069 | while (cc < ccend) | |
1070 | { | |
1071 | space = 0; | |
1072 | size = 0; | |
1073 | bracketlen = 0; | |
1074 | if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE) | |
1075 | break; | |
1076 | ||
1077 | if (repeat_check && (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)) | |
1078 | { | |
1079 | if (detect_repeat(common, cc)) | |
1080 | { | |
1081 | /* These brackets are converted to repeats, so no global | |
1082 | based single character repeat is allowed. */ | |
1083 | if (cc >= end) | |
1084 | end = bracketend(cc); | |
1085 | } | |
1086 | } | |
1087 | repeat_check = TRUE; | |
1088 | ||
1089 | switch(*cc) | |
1090 | { | |
1091 | case OP_KET: | |
1092 | if (common->private_data_ptrs[cc + 1 - common->start] != 0) | |
1093 | { | |
1094 | common->private_data_ptrs[cc - common->start] = private_data_ptr; | |
1095 | private_data_ptr += sizeof(sljit_sw); | |
1096 | cc += common->private_data_ptrs[cc + 1 - common->start]; | |
1097 | } | |
1098 | cc += 1 + LINK_SIZE; | |
1099 | break; | |
1100 | ||
1101 | case OP_ASSERT: | |
1102 | case OP_ASSERT_NOT: | |
1103 | case OP_ASSERTBACK: | |
1104 | case OP_ASSERTBACK_NOT: | |
1105 | case OP_ONCE: | |
1106 | case OP_ONCE_NC: | |
1107 | case OP_BRAPOS: | |
1108 | case OP_SBRA: | |
1109 | case OP_SBRAPOS: | |
1110 | case OP_SCOND: | |
1111 | common->private_data_ptrs[cc - common->start] = private_data_ptr; | |
1112 | private_data_ptr += sizeof(sljit_sw); | |
1113 | bracketlen = 1 + LINK_SIZE; | |
1114 | break; | |
1115 | ||
1116 | case OP_CBRAPOS: | |
1117 | case OP_SCBRAPOS: | |
1118 | common->private_data_ptrs[cc - common->start] = private_data_ptr; | |
1119 | private_data_ptr += sizeof(sljit_sw); | |
1120 | bracketlen = 1 + LINK_SIZE + IMM2_SIZE; | |
1121 | break; | |
1122 | ||
1123 | case OP_COND: | |
1124 | /* Might be a hidden SCOND. */ | |
1125 | alternative = cc + GET(cc, 1); | |
1126 | if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN) | |
1127 | { | |
1128 | common->private_data_ptrs[cc - common->start] = private_data_ptr; | |
1129 | private_data_ptr += sizeof(sljit_sw); | |
1130 | } | |
1131 | bracketlen = 1 + LINK_SIZE; | |
1132 | break; | |
1133 | ||
1134 | case OP_BRA: | |
1135 | bracketlen = 1 + LINK_SIZE; | |
1136 | break; | |
1137 | ||
1138 | case OP_CBRA: | |
1139 | case OP_SCBRA: | |
1140 | bracketlen = 1 + LINK_SIZE + IMM2_SIZE; | |
1141 | break; | |
1142 | ||
1143 | case OP_BRAZERO: | |
1144 | case OP_BRAMINZERO: | |
1145 | case OP_BRAPOSZERO: | |
1146 | repeat_check = FALSE; | |
1147 | size = 1; | |
1148 | break; | |
1149 | ||
1150 | CASE_ITERATOR_PRIVATE_DATA_1 | |
1151 | space = 1; | |
1152 | size = -2; | |
1153 | break; | |
1154 | ||
1155 | CASE_ITERATOR_PRIVATE_DATA_2A | |
1156 | space = 2; | |
1157 | size = -2; | |
1158 | break; | |
1159 | ||
1160 | CASE_ITERATOR_PRIVATE_DATA_2B | |
1161 | space = 2; | |
1162 | size = -(2 + IMM2_SIZE); | |
1163 | break; | |
1164 | ||
1165 | CASE_ITERATOR_TYPE_PRIVATE_DATA_1 | |
1166 | space = 1; | |
1167 | size = 1; | |
1168 | break; | |
1169 | ||
1170 | CASE_ITERATOR_TYPE_PRIVATE_DATA_2A | |
1171 | if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI) | |
1172 | space = 2; | |
1173 | size = 1; | |
1174 | break; | |
1175 | ||
1176 | case OP_TYPEUPTO: | |
1177 | if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI) | |
1178 | space = 2; | |
1179 | size = 1 + IMM2_SIZE; | |
1180 | break; | |
1181 | ||
1182 | case OP_TYPEMINUPTO: | |
1183 | space = 2; | |
1184 | size = 1 + IMM2_SIZE; | |
1185 | break; | |
1186 | ||
1187 | case OP_CLASS: | |
1188 | case OP_NCLASS: | |
1189 | size += 1 + 32 / sizeof(pcre_uchar); | |
1190 | space = get_class_iterator_size(cc + size); | |
1191 | break; | |
1192 | ||
1193 | #if defined SUPPORT_UTF || !defined COMPILE_PCRE8 | |
1194 | case OP_XCLASS: | |
1195 | size = GET(cc, 1); | |
1196 | space = get_class_iterator_size(cc + size); | |
1197 | break; | |
1198 | #endif | |
1199 | ||
1200 | default: | default: |
1201 | cc = next_opcode(common, cc); | cc = next_opcode(common, cc); |
1202 | SLJIT_ASSERT(cc != NULL); | SLJIT_ASSERT(cc != NULL); |
1203 | break; | break; |
1204 | } | } |
1205 | ||
1206 | /* Character iterators, which are not inside a repeated bracket, | |
1207 | gets a private slot instead of allocating it on the stack. */ | |
1208 | if (space > 0 && cc >= end) | |
1209 | { | |
1210 | common->private_data_ptrs[cc - common->start] = private_data_ptr; | |
1211 | private_data_ptr += sizeof(sljit_sw) * space; | |
1212 | } | |
1213 | ||
1214 | if (size != 0) | |
1215 | { | |
1216 | if (size < 0) | |
1217 | { | |
1218 | cc += -size; | |
1219 | #ifdef SUPPORT_UTF | |
1220 | if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); | |
1221 | #endif | |
1222 | } | |
1223 | else | |
1224 | cc += size; | |
1225 | } | |
1226 | ||
1227 | if (bracketlen > 0) | |
1228 | { | |
1229 | if (cc >= end) | |
1230 | { | |
1231 | end = bracketend(cc); | |
1232 | if (end[-1 - LINK_SIZE] == OP_KET) | |
1233 | end = NULL; | |
1234 | } | |
1235 | cc += bracketlen; | |
1236 | } | |
1237 | } | } |
1238 | *private_data_start = private_data_ptr; | |
1239 | } | } |
1240 | ||
1241 | /* Returns with -1 if no need for frame. */ | /* Returns with a frame_types (always < 0) if no need for frame. */ |
1242 | 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) |
1243 | { | { |
pcre_uchar *ccend = bracketend(cc); | ||
1244 | int length = 0; | int length = 0; |
1245 | BOOL possessive = FALSE; | int possessive = 0; |
1246 | BOOL stack_restore = FALSE; | |
1247 | BOOL setsom_found = recursive; | BOOL setsom_found = recursive; |
1248 | BOOL setmark_found = recursive; | BOOL setmark_found = recursive; |
1249 | /* The last capture is a local variable even for recursions. */ | |
1250 | BOOL capture_last_found = FALSE; | |
1251 | ||
1252 | if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS)) | #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD |
1253 | SLJIT_ASSERT(common->control_head_ptr != 0); | |
1254 | *needs_control_head = TRUE; | |
1255 | #else | |
1256 | *needs_control_head = FALSE; | |
1257 | #endif | |
1258 | ||
1259 | if (ccend == NULL) | |
1260 | { | { |
1261 | length = 3; | ccend = bracketend(cc) - (1 + LINK_SIZE); |
1262 | possessive = TRUE; | if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS)) |
1263 | { | |
1264 | possessive = length = (common->capture_last_ptr != 0) ? 5 : 3; | |
1265 | /* This is correct regardless of common->capture_last_ptr. */ | |
1266 | capture_last_found = TRUE; | |
1267 | } | |
1268 | cc = next_opcode(common, cc); | |
1269 | } | } |
1270 | ||
cc = next_opcode(common, cc); | ||
1271 | SLJIT_ASSERT(cc != NULL); | SLJIT_ASSERT(cc != NULL); |
1272 | while (cc < ccend) | while (cc < ccend) |
1273 | switch(*cc) | switch(*cc) |
1274 | { | { |
1275 | case OP_SET_SOM: | case OP_SET_SOM: |
1276 | SLJIT_ASSERT(common->has_set_som); | SLJIT_ASSERT(common->has_set_som); |
1277 | stack_restore = TRUE; | |
1278 | if (!setsom_found) | if (!setsom_found) |
1279 | { | { |
1280 | length += 2; | length += 2; |
# | Line 818 while (cc < ccend) | Line 1284 while (cc < ccend) |
1284 | break; | break; |
1285 | ||
1286 | case OP_MARK: | case OP_MARK: |
1287 | case OP_PRUNE_ARG: | |
1288 | case OP_THEN_ARG: | |
1289 | SLJIT_ASSERT(common->mark_ptr != 0); | SLJIT_ASSERT(common->mark_ptr != 0); |
1290 | stack_restore = TRUE; | |
1291 | if (!setmark_found) | if (!setmark_found) |
1292 | { | { |
1293 | length += 2; | length += 2; |
1294 | setmark_found = TRUE; | setmark_found = TRUE; |
1295 | } | } |
1296 | if (common->control_head_ptr != 0) | |
1297 | *needs_control_head = TRUE; | |
1298 | cc += 1 + 2 + cc[1]; | cc += 1 + 2 + cc[1]; |
1299 | break; | break; |
1300 | ||
1301 | case OP_RECURSE: | case OP_RECURSE: |
1302 | stack_restore = TRUE; | |
1303 | if (common->has_set_som && !setsom_found) | if (common->has_set_som && !setsom_found) |
1304 | { | { |
1305 | length += 2; | length += 2; |
# | Line 838 while (cc < ccend) | Line 1310 while (cc < ccend) |
1310 | length += 2; | length += 2; |
1311 | setmark_found = TRUE; | setmark_found = TRUE; |
1312 | } | } |
1313 | if (common->capture_last_ptr != 0 && !capture_last_found) | |
1314 | { | |
1315 | length += 2; | |
1316 | capture_last_found = TRUE; | |
1317 | } | |
1318 | cc += 1 + LINK_SIZE; | cc += 1 + LINK_SIZE; |
1319 | break; | break; |
1320 | ||
# | Line 845 while (cc < ccend) | Line 1322 while (cc < ccend) |
1322 | case OP_CBRAPOS: | case OP_CBRAPOS: |
1323 | case OP_SCBRA: | case OP_SCBRA: |
1324 | case OP_SCBRAPOS: | case OP_SCBRAPOS: |
1325 | stack_restore = TRUE; | |
1326 | if (common->capture_last_ptr != 0 && !capture_last_found) | |
1327 | { | |
1328 | length += 2; | |
1329 | capture_last_found = TRUE; | |
1330 | } | |
1331 | length += 3; | length += 3; |
1332 | cc += 1 + LINK_SIZE + IMM2_SIZE; | cc += 1 + LINK_SIZE + IMM2_SIZE; |
1333 | break; | break; |
1334 | ||
1335 | case OP_THEN: | |
1336 | stack_restore = TRUE; | |
1337 | if (common->control_head_ptr != 0) | |
1338 | *needs_control_head = TRUE; | |
1339 | cc ++; | |
1340 | break; | |
1341 | ||
1342 | default: | default: |
1343 | stack_restore = TRUE; | |
1344 | /* Fall through. */ | |
1345 | ||
1346 | case OP_NOT_WORD_BOUNDARY: | |
1347 | case OP_WORD_BOUNDARY: | |
1348 | case OP_NOT_DIGIT: | |
1349 | case OP_DIGIT: | |
1350 | case OP_NOT_WHITESPACE: | |
1351 | case OP_WHITESPACE: | |
1352 | case OP_NOT_WORDCHAR: | |
1353 | case OP_WORDCHAR: | |
1354 | case OP_ANY: | |
1355 | case OP_ALLANY: | |
1356 | case OP_ANYBYTE: | |
1357 | case OP_NOTPROP: | |
1358 | case OP_PROP: | |
1359 | case OP_ANYNL: | |
1360 | case OP_NOT_HSPACE: | |
1361 | case OP_HSPACE: | |
1362 | case OP_NOT_VSPACE: | |
1363 | case OP_VSPACE: | |
1364 | case OP_EXTUNI: | |
1365 | case OP_EODN: | |
1366 | case OP_EOD: | |
1367 | case OP_CIRC: | |
1368 | case OP_CIRCM: | |
1369 | case OP_DOLL: | |
1370 | case OP_DOLLM: | |
1371 | case OP_CHAR: | |
1372 | case OP_CHARI: | |
1373 | case OP_NOT: | |
1374 | case OP_NOTI: | |
1375 | ||
1376 | case OP_EXACT: | |
1377 | case OP_POSSTAR: | |
1378 | case OP_POSPLUS: | |
1379 | case OP_POSQUERY: | |
1380 | case OP_POSUPTO: | |
1381 | ||
1382 | case OP_EXACTI: | |
1383 | case OP_POSSTARI: | |
1384 | case OP_POSPLUSI: | |
1385 | case OP_POSQUERYI: | |
1386 | case OP_POSUPTOI: | |
1387 | ||
1388 | case OP_NOTEXACT: | |
1389 | case OP_NOTPOSSTAR: | |
1390 | case OP_NOTPOSPLUS: | |
1391 | case OP_NOTPOSQUERY: | |
1392 | case OP_NOTPOSUPTO: | |
1393 | ||
1394 | case OP_NOTEXACTI: | |
1395 | case OP_NOTPOSSTARI: | |
1396 | case OP_NOTPOSPLUSI: | |
1397 | case OP_NOTPOSQUERYI: | |
1398 | case OP_NOTPOSUPTOI: | |
1399 | ||
1400 | case OP_TYPEEXACT: | |
1401 | case OP_TYPEPOSSTAR: | |
1402 | case OP_TYPEPOSPLUS: | |
1403 | case OP_TYPEPOSQUERY: | |
1404 | case OP_TYPEPOSUPTO: | |
1405 | ||
1406 | case OP_CLASS: | |
1407 | case OP_NCLASS: | |
1408 | case OP_XCLASS: | |
1409 | ||
1410 | cc = next_opcode(common, cc); | cc = next_opcode(common, cc); |
1411 | SLJIT_ASSERT(cc != NULL); | SLJIT_ASSERT(cc != NULL); |
1412 | break; | break; |
1413 | } | } |
1414 | ||
1415 | /* Possessive quantifiers can use a special case. */ | /* Possessive quantifiers can use a special case. */ |
1416 | if (SLJIT_UNLIKELY(possessive) && length == 3) | if (SLJIT_UNLIKELY(possessive == length)) |
1417 | return -1; | return stack_restore ? no_frame : no_stack; |
1418 | ||
1419 | if (length > 0) | if (length > 0) |
1420 | return length + 1; | return length + 1; |
1421 | return -1; | return stack_restore ? no_frame : no_stack; |
1422 | } | } |
1423 | ||
1424 | 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) |
1425 | { | { |
1426 | DEFINE_COMPILER; | DEFINE_COMPILER; |
pcre_uchar *ccend = bracketend(cc); | ||
1427 | BOOL setsom_found = recursive; | BOOL setsom_found = recursive; |
1428 | BOOL setmark_found = recursive; | BOOL setmark_found = recursive; |
1429 | /* The last capture is a local variable even for recursions. */ | |
1430 | BOOL capture_last_found = FALSE; | |
1431 | int offset; | int offset; |
1432 | ||
1433 | /* >= 1 + shortest item size (2) */ | /* >= 1 + shortest item size (2) */ |
# | Line 877 SLJIT_UNUSED_ARG(stacktop); | Line 1435 SLJIT_UNUSED_ARG(stacktop); |
1435 | SLJIT_ASSERT(stackpos >= stacktop + 2); | SLJIT_ASSERT(stackpos >= stacktop + 2); |
1436 | ||
1437 | stackpos = STACK(stackpos); | stackpos = STACK(stackpos); |
1438 | if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS)) | if (ccend == NULL) |
1439 | cc = next_opcode(common, cc); | { |
1440 | ccend = bracketend(cc) - (1 + LINK_SIZE); | |
1441 | if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS)) | |
1442 | cc = next_opcode(common, cc); | |
1443 | } | |
1444 | ||
1445 | SLJIT_ASSERT(cc != NULL); | SLJIT_ASSERT(cc != NULL); |
1446 | while (cc < ccend) | while (cc < ccend) |
1447 | switch(*cc) | switch(*cc) |
# | Line 887 while (cc < ccend) | Line 1450 while (cc < ccend) |
1450 | SLJIT_ASSERT(common->has_set_som); | SLJIT_ASSERT(common->has_set_som); |
1451 | if (!setsom_found) | if (!setsom_found) |
1452 | { | { |
1453 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0)); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0)); |
1454 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0)); |
1455 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1456 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); |
1457 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1458 | setsom_found = TRUE; | setsom_found = TRUE; |
1459 | } | } |
1460 | cc += 1; | cc += 1; |
1461 | break; | break; |
1462 | ||
1463 | case OP_MARK: | case OP_MARK: |
1464 | case OP_PRUNE_ARG: | |
1465 | case OP_THEN_ARG: | |
1466 | SLJIT_ASSERT(common->mark_ptr != 0); | SLJIT_ASSERT(common->mark_ptr != 0); |
1467 | if (!setmark_found) | if (!setmark_found) |
1468 | { | { |
1469 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr); |
1470 | 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); |
1471 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1472 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); |
1473 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1474 | setmark_found = TRUE; | setmark_found = TRUE; |
1475 | } | } |
1476 | cc += 1 + 2 + cc[1]; | cc += 1 + 2 + cc[1]; |
# | Line 914 while (cc < ccend) | Line 1479 while (cc < ccend) |
1479 | case OP_RECURSE: | case OP_RECURSE: |
1480 | if (common->has_set_som && !setsom_found) | if (common->has_set_som && !setsom_found) |
1481 | { | { |
1482 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0)); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0)); |
1483 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0)); |
1484 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1485 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); |
1486 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1487 | setsom_found = TRUE; | setsom_found = TRUE; |
1488 | } | } |
1489 | if (common->mark_ptr != 0 && !setmark_found) | if (common->mark_ptr != 0 && !setmark_found) |
1490 | { | { |
1491 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr); |
1492 | 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); |
1493 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1494 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); |
1495 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1496 | setmark_found = TRUE; | setmark_found = TRUE; |
1497 | } | } |
1498 | if (common->capture_last_ptr != 0 && !capture_last_found) | |
1499 | { | |
1500 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr); | |
1501 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr); | |
1502 | stackpos += (int)sizeof(sljit_sw); | |
1503 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); | |
1504 | stackpos += (int)sizeof(sljit_sw); | |
1505 | capture_last_found = TRUE; | |
1506 | } | |
1507 | cc += 1 + LINK_SIZE; | cc += 1 + LINK_SIZE; |
1508 | break; | break; |
1509 | ||
# | Line 937 while (cc < ccend) | Line 1511 while (cc < ccend) |
1511 | case OP_CBRAPOS: | case OP_CBRAPOS: |
1512 | case OP_SCBRA: | case OP_SCBRA: |
1513 | case OP_SCBRAPOS: | case OP_SCBRAPOS: |
1514 | if (common->capture_last_ptr != 0 && !capture_last_found) | |
1515 | { | |
1516 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr); | |
1517 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr); | |
1518 | stackpos += (int)sizeof(sljit_sw); | |
1519 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); | |
1520 | stackpos += (int)sizeof(sljit_sw); | |
1521 | capture_last_found = TRUE; | |
1522 | } | |
1523 | offset = (GET2(cc, 1 + LINK_SIZE)) << 1; | offset = (GET2(cc, 1 + LINK_SIZE)) << 1; |
1524 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset)); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset)); |
1525 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1526 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset)); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset)); |
1527 | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1)); | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1)); |
1528 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0); |
1529 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1530 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0); |
1531 | stackpos += (int)sizeof(sljit_w); | stackpos += (int)sizeof(sljit_sw); |
1532 | ||
1533 | cc += 1 + LINK_SIZE + IMM2_SIZE; | cc += 1 + LINK_SIZE + IMM2_SIZE; |
1534 | break; | break; |
# | Line 956 while (cc < ccend) | Line 1539 while (cc < ccend) |
1539 | break; | break; |
1540 | } | } |
1541 | ||
1542 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0); |
1543 | SLJIT_ASSERT(stackpos == STACK(stacktop)); | SLJIT_ASSERT(stackpos == STACK(stacktop)); |
1544 | } | } |
1545 | ||
1546 | 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) |
1547 | { | { |
1548 | int localsize = 2; | int private_data_length = needs_control_head ? 3 : 2; |
1549 | int size; | |
1550 | pcre_uchar *alternative; | pcre_uchar *alternative; |
1551 | /* Calculate the sum of the local variables. */ | /* Calculate the sum of the private machine words. */ |
1552 | while (cc < ccend) | while (cc < ccend) |
1553 | { | { |
1554 | size = 0; | |
1555 | switch(*cc) | switch(*cc) |
1556 | { | { |
1557 | case OP_KET: | |
1558 | if (PRIVATE_DATA(cc) != 0) | |
1559 | { | |
1560 | private_data_length++; | |
1561 | SLJIT_ASSERT(PRIVATE_DATA(cc + 1) != 0); | |
1562 | cc += PRIVATE_DATA(cc + 1); | |
1563 | } | |
1564 | cc += 1 + LINK_SIZE; | |
1565 | break; | |
1566 | ||
1567 | case OP_ASSERT: | case OP_ASSERT: |
1568 | case OP_ASSERT_NOT: | case OP_ASSERT_NOT: |
1569 | case OP_ASSERTBACK: | case OP_ASSERTBACK: |
# | Line 979 while (cc < ccend) | Line 1574 while (cc < ccend) |
1574 | case OP_SBRA: | case OP_SBRA: |
1575 | case OP_SBRAPOS: | case OP_SBRAPOS: |
1576 | case OP_SCOND: | case OP_SCOND: |
1577 | localsize++; | private_data_length++; |
1578 | SLJIT_ASSERT(PRIVATE_DATA(cc) != 0); | |
1579 | cc += 1 + LINK_SIZE; | cc += 1 + LINK_SIZE; |
1580 | break; | break; |
1581 | ||
1582 | case OP_CBRA: | case OP_CBRA: |
1583 | case OP_SCBRA: | case OP_SCBRA: |
1584 | localsize++; | if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0) |
1585 | private_data_length++; | |
1586 | cc += 1 + LINK_SIZE + IMM2_SIZE; | cc += 1 + LINK_SIZE + IMM2_SIZE; |
1587 | break; | break; |
1588 | ||
1589 | case OP_CBRAPOS: | case OP_CBRAPOS: |
1590 | case OP_SCBRAPOS: | case OP_SCBRAPOS: |
1591 | localsize += 2; | private_data_length += 2; |
1592 | cc += 1 + LINK_SIZE + IMM2_SIZE; | cc += 1 + LINK_SIZE + IMM2_SIZE; |
1593 | break; | break; |
1594 | ||
# | Line 999 while (cc < ccend) | Line 1596 while (cc < ccend) |
1596 | /* Might be a hidden SCOND. */ | /* Might be a hidden SCOND. */ |
1597 | alternative = cc + GET(cc, 1); | alternative = cc + GET(cc, 1); |
1598 | if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN) | if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN) |
1599 | localsize++; | private_data_length++; |
1600 | cc += 1 + LINK_SIZE; | cc += 1 + LINK_SIZE; |
1601 | break; | break; |
1602 | ||
1603 | default: | CASE_ITERATOR_PRIVATE_DATA_1 |
1604 | cc = next_opcode(common, cc); | if (PRIVATE_DATA(cc)) |
1605 | SLJIT_ASSERT(cc != NULL); | private_data_length++; |
1606 | cc += 2; | |
1607 | #ifdef SUPPORT_UTF | |
1608 | if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); | |
1609 | #endif | |
1610 | break; | break; |
} | ||
} | ||
SLJIT_ASSERT(cc == ccend); | ||
return localsize; | ||
} | ||
1611 | ||
1612 | static void copy_locals(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, | CASE_ITERATOR_PRIVATE_DATA_2A |
1613 | BOOL save, int stackptr, int stacktop) | if (PRIVATE_DATA(cc)) |
1614 | { | private_data_length += 2; |
1615 | DEFINE_COMPILER; | cc += 2; |
1616 | #ifdef SUPPORT_UTF | |
1617 | if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); | |
1618 | #endif | |
1619 | break; | |
1620 | ||
1621 | CASE_ITERATOR_PRIVATE_DATA_2B | |
1622 | if (PRIVATE_DATA(cc)) | |
1623 | private_data_length += 2; | |
1624 | cc += 2 + IMM2_SIZE; | |
1625 | #ifdef SUPPORT_UTF | |
1626 | if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); | |
1627 | #endif | |
1628 | break; | |
1629 | ||
1630 | CASE_ITERATOR_TYPE_PRIVATE_DATA_1 | |
1631 | if (PRIVATE_DATA(cc)) | |
1632 | private_data_length++; | |
1633 | cc += 1; | |
1634 | break; | |
1635 | ||
1636 | CASE_ITERATOR_TYPE_PRIVATE_DATA_2A | |
1637 | if (PRIVATE_DATA(cc)) | |
1638 | private_data_length += 2; | |
1639 | cc += 1; | |
1640 | break; | |
1641 | ||
1642 | CASE_ITERATOR_TYPE_PRIVATE_DATA_2B | |
1643 | if (PRIVATE_DATA(cc)) | |
1644 | private_data_length += 2; | |
1645 | cc += 1 + IMM2_SIZE; | |
1646 | break; | |
1647 | ||
1648 | case OP_CLASS: | |
1649 | case OP_NCLASS: | |
1650 | #if defined SUPPORT_UTF || !defined COMPILE_PCRE8 | |
1651 | case OP_XCLASS: | |
1652 | size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar); | |
1653 | #else | |
1654 | size = 1 + 32 / (int)sizeof(pcre_uchar); | |
1655 | #endif | |
1656 | if (PRIVATE_DATA(cc)) | |
1657 | private_data_length += get_class_iterator_size(cc + size); | |
1658 | cc += size; | |
1659 | break; | |
1660 | ||
1661 | default: | |
1662 | cc = next_opcode(common, cc); | |
1663 | SLJIT_ASSERT(cc != NULL); | |
1664 | break; | |
1665 | } | |
1666 | } | |
1667 | SLJIT_ASSERT(cc == ccend); | |
1668 | return private_data_length; | |
1669 | } | |
1670 | ||
1671 | static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, | |
1672 | BOOL save, int stackptr, int stacktop, BOOL needs_control_head) | |
1673 | { | |
1674 | DEFINE_COMPILER; | |
1675 | int srcw[2]; | int srcw[2]; |
1676 | int count; | int count, size; |
1677 | BOOL tmp1next = TRUE; | BOOL tmp1next = TRUE; |
1678 | BOOL tmp1empty = TRUE; | BOOL tmp1empty = TRUE; |
1679 | BOOL tmp2empty = TRUE; | BOOL tmp2empty = TRUE; |
# | Line 1035 stacktop = STACK(stacktop - 1); | Line 1690 stacktop = STACK(stacktop - 1); |
1690 | ||
1691 | if (!save) | if (!save) |
1692 | { | { |
1693 | stackptr += sizeof(sljit_w); | stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw); |
1694 | if (stackptr < stacktop) | if (stackptr < stacktop) |
1695 | { | { |
1696 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr); |
1697 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1698 | tmp1empty = FALSE; | tmp1empty = FALSE; |
1699 | } | } |
1700 | if (stackptr < stacktop) | if (stackptr < stacktop) |
1701 | { | { |
1702 | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr); | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr); |
1703 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1704 | tmp2empty = FALSE; | tmp2empty = FALSE; |
1705 | } | } |
1706 | /* The tmp1next must be TRUE in either way. */ | /* The tmp1next must be TRUE in either way. */ |
1707 | } | } |
1708 | ||
1709 | while (status != end) | do |
1710 | { | { |
1711 | count = 0; | count = 0; |
1712 | switch(status) | switch(status) |
1713 | { | { |
1714 | case start: | case start: |
1715 | SLJIT_ASSERT(save && common->recursive_head != 0); | SLJIT_ASSERT(save && common->recursive_head_ptr != 0); |
1716 | count = 1; | count = 1; |
1717 | srcw[0] = common->recursive_head; | srcw[0] = common->recursive_head_ptr; |
1718 | if (needs_control_head) | |
1719 | { | |
1720 | SLJIT_ASSERT(common->control_head_ptr != 0); | |
1721 | count = 2; | |
1722 | srcw[1] = common->control_head_ptr; | |
1723 | } | |
1724 | status = loop; | status = loop; |
1725 | break; | break; |
1726 | ||
# | Line 1072 while (status != end) | Line 1733 while (status != end) |
1733 | ||
1734 | switch(*cc) | switch(*cc) |
1735 | { | { |
1736 | case OP_KET: | |
1737 | if (PRIVATE_DATA(cc) != 0) | |
1738 | { | |
1739 | count = 1; | |
1740 | srcw[0] = PRIVATE_DATA(cc); | |
1741 | SLJIT_ASSERT(PRIVATE_DATA(cc + 1) != 0); | |
1742 | cc += PRIVATE_DATA(cc + 1); | |
1743 | } | |
1744 | cc += 1 + LINK_SIZE; | |
1745 | break; | |
1746 | ||
1747 | case OP_ASSERT: | case OP_ASSERT: |
1748 | case OP_ASSERT_NOT: | case OP_ASSERT_NOT: |
1749 | case OP_ASSERTBACK: | case OP_ASSERTBACK: |
# | Line 1083 while (status != end) | Line 1755 while (status != end) |
1755 | case OP_SBRAPOS: | case OP_SBRAPOS: |
1756 | case OP_SCOND: | case OP_SCOND: |
1757 | count = 1; | count = 1; |
1758 | srcw[0] = PRIV_DATA(cc); | srcw[0] = PRIVATE_DATA(cc); |
1759 | SLJIT_ASSERT(srcw[0] != 0); | SLJIT_ASSERT(srcw[0] != 0); |
1760 | cc += 1 + LINK_SIZE; | cc += 1 + LINK_SIZE; |
1761 | break; | break; |
1762 | ||
1763 | case OP_CBRA: | case OP_CBRA: |
1764 | case OP_SCBRA: | case OP_SCBRA: |
1765 | count = 1; | if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0) |
1766 | srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE)); | { |
1767 | count = 1; | |
1768 | srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE)); | |
1769 | } | |
1770 | cc += 1 + LINK_SIZE + IMM2_SIZE; | cc += 1 + LINK_SIZE + IMM2_SIZE; |
1771 | break; | break; |
1772 | ||
1773 | case OP_CBRAPOS: | case OP_CBRAPOS: |
1774 | case OP_SCBRAPOS: | case OP_SCBRAPOS: |
1775 | count = 2; | count = 2; |
1776 | srcw[0] = PRIVATE_DATA(cc); | |
1777 | srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE)); | srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE)); |
1778 | srcw[0] = PRIV_DATA(cc); | SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0); |
SLJIT_ASSERT(srcw[0] != 0); | ||
1779 | cc += 1 + LINK_SIZE + IMM2_SIZE; | cc += 1 + LINK_SIZE + IMM2_SIZE; |
1780 | break; | break; |
1781 | ||
# | Line 1110 while (status != end) | Line 1785 while (status != end) |
1785 | if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN) | if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN) |
1786 | { | { |
1787 | count = 1; | count = 1; |
1788 | srcw[0] = PRIV_DATA(cc); | srcw[0] = PRIVATE_DATA(cc); |
1789 | SLJIT_ASSERT(srcw[0] != 0); | SLJIT_ASSERT(srcw[0] != 0); |
1790 | } | } |
1791 | cc += 1 + LINK_SIZE; | cc += 1 + LINK_SIZE; |
1792 | break; | break; |
1793 | ||
1794 | CASE_ITERATOR_PRIVATE_DATA_1 | |
1795 | if (PRIVATE_DATA(cc)) | |
1796 | { | |
1797 | count = 1; | |
1798 | srcw[0] = PRIVATE_DATA(cc); | |
1799 | } | |
1800 | cc += 2; | |
1801 | #ifdef SUPPORT_UTF | |
1802 | if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); | |
1803 | #endif | |
1804 | break; | |
1805 | ||
1806 | CASE_ITERATOR_PRIVATE_DATA_2A | |
1807 | if (PRIVATE_DATA(cc)) | |
1808 | { | |
1809 | count = 2; | |
1810 | srcw[0] = PRIVATE_DATA(cc); | |
1811 | srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw); | |
1812 | } | |
1813 | cc += 2; | |
1814 | #ifdef SUPPORT_UTF | |
1815 | if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); | |
1816 | #endif | |
1817 | break; | |
1818 | ||
1819 | CASE_ITERATOR_PRIVATE_DATA_2B | |
1820 | if (PRIVATE_DATA(cc)) | |
1821 | { | |
1822 | count = 2; | |
1823 | srcw[0] = PRIVATE_DATA(cc); | |
1824 | srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw); | |
1825 | } | |
1826 | cc += 2 + IMM2_SIZE; | |
1827 | #ifdef SUPPORT_UTF | |
1828 | if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); | |
1829 | #endif | |
1830 | break; | |
1831 | ||
1832 | CASE_ITERATOR_TYPE_PRIVATE_DATA_1 | |
1833 | if (PRIVATE_DATA(cc)) | |
1834 | { | |
1835 | count = 1; | |
1836 | srcw[0] = PRIVATE_DATA(cc); | |
1837 | } | |
1838 | cc += 1; | |
1839 | break; | |
1840 | ||
1841 | CASE_ITERATOR_TYPE_PRIVATE_DATA_2A | |
1842 | if (PRIVATE_DATA(cc)) | |
1843 | { | |
1844 | count = 2; | |
1845 | srcw[0] = PRIVATE_DATA(cc); | |
1846 | srcw[1] = srcw[0] + sizeof(sljit_sw); | |
1847 | } | |
1848 | cc += 1; | |
1849 | break; | |
1850 | ||
1851 | CASE_ITERATOR_TYPE_PRIVATE_DATA_2B | |
1852 | if (PRIVATE_DATA(cc)) | |
1853 | { | |
1854 | count = 2; | |
1855 | srcw[0] = PRIVATE_DATA(cc); | |
1856 | srcw[1] = srcw[0] + sizeof(sljit_sw); | |
1857 | } | |
1858 | cc += 1 + IMM2_SIZE; | |
1859 | break; | |
1860 | ||
1861 | case OP_CLASS: | |
1862 | case OP_NCLASS: | |
1863 | #if defined SUPPORT_UTF || !defined COMPILE_PCRE8 | |
1864 | case OP_XCLASS: | |
1865 | size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar); | |
1866 | #else | |
1867 | size = 1 + 32 / (int)sizeof(pcre_uchar); | |
1868 | #endif | |
1869 | if (PRIVATE_DATA(cc)) | |
1870 | switch(get_class_iterator_size(cc + size)) | |
1871 | { | |
1872 | case 1: | |
1873 | count = 1; | |
1874 | srcw[0] = PRIVATE_DATA(cc); | |
1875 | break; | |
1876 | ||
1877 | case 2: | |
1878 | count = 2; | |
1879 | srcw[0] = PRIVATE_DATA(cc); | |
1880 | srcw[1] = srcw[0] + sizeof(sljit_sw); | |
1881 | break; | |
1882 | ||
1883 | default: | |
1884 | SLJIT_ASSERT_STOP(); | |
1885 | break; | |
1886 | } | |
1887 | cc += size; | |
1888 | break; | |
1889 | ||
1890 | default: | default: |
1891 | cc = next_opcode(common, cc); | cc = next_opcode(common, cc); |
1892 | SLJIT_ASSERT(cc != NULL); | SLJIT_ASSERT(cc != NULL); |
# | Line 1138 while (status != end) | Line 1909 while (status != end) |
1909 | if (!tmp1empty) | if (!tmp1empty) |
1910 | { | { |
1911 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0); |
1912 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1913 | } | } |
1914 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), srcw[count]); |
1915 | tmp1empty = FALSE; | tmp1empty = FALSE; |
1916 | tmp1next = FALSE; | tmp1next = FALSE; |
1917 | } | } |
# | Line 1149 while (status != end) | Line 1920 while (status != end) |
1920 | if (!tmp2empty) | if (!tmp2empty) |
1921 | { | { |
1922 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0); |
1923 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1924 | } | } |
1925 | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]); | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), srcw[count]); |
1926 | tmp2empty = FALSE; | tmp2empty = FALSE; |
1927 | tmp1next = TRUE; | tmp1next = TRUE; |
1928 | } | } |
# | Line 1161 while (status != end) | Line 1932 while (status != end) |
1932 | if (tmp1next) | if (tmp1next) |
1933 | { | { |
1934 | SLJIT_ASSERT(!tmp1empty); | SLJIT_ASSERT(!tmp1empty); |
1935 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count], TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), srcw[count], TMP1, 0); |
1936 | tmp1empty = stackptr >= stacktop; | tmp1empty = stackptr >= stacktop; |
1937 | if (!tmp1empty) | if (!tmp1empty) |
1938 | { | { |
1939 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr); |
1940 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1941 | } | } |
1942 | tmp1next = FALSE; | tmp1next = FALSE; |
1943 | } | } |
1944 | else | else |
1945 | { | { |
1946 | SLJIT_ASSERT(!tmp2empty); | SLJIT_ASSERT(!tmp2empty); |
1947 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count], TMP2, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), srcw[count], TMP2, 0); |
1948 | tmp2empty = stackptr >= stacktop; | tmp2empty = stackptr >= stacktop; |
1949 | if (!tmp2empty) | if (!tmp2empty) |
1950 | { | { |
1951 | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr); | OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr); |
1952 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1953 | } | } |
1954 | tmp1next = TRUE; | tmp1next = TRUE; |
1955 | } | } |
1956 | } | } |
1957 | } | } |
1958 | } | } |
1959 | while (status != end); | |
1960 | ||
1961 | if (save) | if (save) |
1962 | { | { |
# | Line 1193 if (save) | Line 1965 if (save) |
1965 | if (!tmp1empty) | if (!tmp1empty) |
1966 | { | { |
1967 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0); |
1968 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1969 | } | } |
1970 | if (!tmp2empty) | if (!tmp2empty) |
1971 | { | { |
1972 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0); |
1973 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1974 | } | } |
1975 | } | } |
1976 | else | else |
# | Line 1206 if (save) | Line 1978 if (save) |
1978 | if (!tmp2empty) | if (!tmp2empty) |
1979 | { | { |
1980 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0); |
1981 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1982 | } | } |
1983 | if (!tmp1empty) | if (!tmp1empty) |
1984 | { | { |
1985 | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0); |
1986 | stackptr += sizeof(sljit_w); | stackptr += sizeof(sljit_sw); |
1987 | } | } |
1988 | } | } |
1989 | } | } |
1990 | SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty))); | SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty))); |
1991 | } | } |
1992 | ||
1993 | static SLJIT_INLINE BOOL ispowerof2(unsigned int value) | static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset) |
1994 | { | |
1995 | pcre_uchar *end = bracketend(cc); | |
1996 | BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT; | |
1997 | ||
1998 | /* Assert captures then. */ | |
1999 | if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) | |
2000 | current_offset = NULL; | |
2001 | /* Conditional block does not. */ | |
2002 | if (*cc == OP_COND || *cc == OP_SCOND) | |
2003 | has_alternatives = FALSE; | |
2004 | ||
2005 | cc = next_opcode(common, cc); | |
2006 | if (has_alternatives) | |
2007 | current_offset = common->then_offsets + (cc - common->start); | |
2008 | ||
2009 | while (cc < end) | |
2010 | { | |
2011 | if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND)) | |
2012 | cc = set_then_offsets(common, cc, current_offset); | |
2013 | else | |
2014 | { | |
2015 | if (*cc == OP_ALT && has_alternatives) | |
2016 | current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start); | |
2017 | if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL) | |
2018 | *current_offset = 1; | |
2019 | cc = next_opcode(common, cc); | |
2020 | } | |
2021 | } | |
2022 | ||
2023 | return end; | |
2024 | } | |
2025 | ||
2026 | #undef CASE_ITERATOR_PRIVATE_DATA_1 | |
2027 | #undef CASE_ITERATOR_PRIVATE_DATA_2A | |
2028 | #undef CASE_ITERATOR_PRIVATE_DATA_2B | |
2029 | #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1 | |
2030 | #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A | |
2031 | #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B | |
2032 | ||
2033 | static SLJIT_INLINE BOOL is_powerof2(unsigned int value) | |
2034 | { | { |
2035 | return (value & (value - 1)) == 0; | return (value & (value - 1)) == 0; |
2036 | } | } |
# | Line 1228 static SLJIT_INLINE void set_jumps(jump_ | Line 2040 static SLJIT_INLINE void set_jumps(jump_ |
2040 | while (list) | while (list) |
2041 | { | { |
2042 | /* sljit_set_label is clever enough to do nothing | /* sljit_set_label is clever enough to do nothing |
2043 | if either the jump or the label is NULL */ | if either the jump or the label is NULL. */ |
2044 | sljit_set_label(list->jump, label); | SET_LABEL(list->jump, label); |
2045 | list = list->next; | list = list->next; |
2046 | } | } |
2047 | } | } |
2048 | ||
2049 | static SLJIT_INLINE void add_jump(struct sljit_compiler *compiler, jump_list **list, struct sljit_jump* jump) | static SLJIT_INLINE void add_jump(struct sljit_compiler *compiler, jump_list **list, struct sljit_jump *jump) |
2050 | { | { |
2051 | jump_list *list_item = sljit_alloc_memory(compiler, sizeof(jump_list)); | jump_list *list_item = sljit_alloc_memory(compiler, sizeof(jump_list)); |
2052 | if (list_item) | if (list_item) |
# | Line 1245 if (list_item) | Line 2057 if (list_item) |
2057 | } | } |
2058 | } | } |
2059 | ||
2060 | 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) |
2061 | { | { |
2062 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2063 | stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list)); | stub_list *list_item = sljit_alloc_memory(compiler, sizeof(stub_list)); |
2064 | ||
2065 | if (list_item) | if (list_item) |
2066 | { | { |
list_item->type = type; | ||
list_item->data = data; | ||
2067 | list_item->start = start; | list_item->start = start; |
2068 | list_item->leave = LABEL(); | list_item->quit = LABEL(); |
2069 | list_item->next = common->stubs; | list_item->next = common->stubs; |
2070 | common->stubs = list_item; | common->stubs = list_item; |
2071 | } | } |
# | Line 1264 if (list_item) | Line 2074 if (list_item) |
2074 | static void flush_stubs(compiler_common *common) | static void flush_stubs(compiler_common *common) |
2075 | { | { |
2076 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2077 | stub_list* list_item = common->stubs; | stub_list *list_item = common->stubs; |
2078 | ||
2079 | while (list_item) | while (list_item) |
2080 | { | { |
2081 | JUMPHERE(list_item->start); | JUMPHERE(list_item->start); |
2082 | switch(list_item->type) | add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL)); |
2083 | { | JUMPTO(SLJIT_JUMP, list_item->quit); |
case stack_alloc: | ||
add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL)); | ||
break; | ||
} | ||
JUMPTO(SLJIT_JUMP, list_item->leave); | ||
2084 | list_item = list_item->next; | list_item = list_item->next; |
2085 | } | } |
2086 | common->stubs = NULL; | common->stubs = NULL; |
2087 | } | } |
2088 | ||
2089 | static SLJIT_INLINE void decrease_call_count(compiler_common *common) | static void add_label_addr(compiler_common *common, sljit_uw *update_addr) |
2090 | { | |
2091 | DEFINE_COMPILER; | |
2092 | label_addr_list *label_addr; | |
2093 | ||
2094 | label_addr = sljit_alloc_memory(compiler, sizeof(label_addr_list)); | |
2095 | if (label_addr == NULL) | |
2096 | return; | |
2097 | label_addr->label = LABEL(); | |
2098 | label_addr->update_addr = update_addr; | |
2099 | label_addr->next = common->label_addrs; | |
2100 | common->label_addrs = label_addr; | |
2101 | } | |
2102 | ||
2103 | static SLJIT_INLINE void count_match(compiler_common *common) | |
2104 | { | { |
2105 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2106 | ||
2107 | OP2(SLJIT_SUB | SLJIT_SET_E, CALL_COUNT, 0, CALL_COUNT, 0, SLJIT_IMM, 1); | OP2(SLJIT_SUB | SLJIT_SET_E, COUNT_MATCH, 0, COUNT_MATCH, 0, SLJIT_IMM, 1); |
2108 | add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO)); | add_jump(compiler, &common->calllimit, JUMP(SLJIT_ZERO)); |
2109 | } | } |
2110 | ||
2111 | static SLJIT_INLINE void allocate_stack(compiler_common *common, int size) | static SLJIT_INLINE void allocate_stack(compiler_common *common, int size) |
# | Line 1294 static SLJIT_INLINE void allocate_stack( | Line 2113 static SLJIT_INLINE void allocate_stack( |
2113 | /* May destroy all locals and registers except TMP2. */ | /* May destroy all locals and registers except TMP2. */ |
2114 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2115 | ||
2116 | 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)); |
2117 | #ifdef DESTROY_REGISTERS | #ifdef DESTROY_REGISTERS |
2118 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345); |
2119 | OP1(SLJIT_MOV, TMP3, 0, TMP1, 0); | OP1(SLJIT_MOV, TMP3, 0, TMP1, 0); |
2120 | OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); | OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); |
2121 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS0, TMP1, 0); |
2122 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, TMP1, 0); |
2123 | #endif | #endif |
2124 | add_stub(common, stack_alloc, 0, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0)); | add_stub(common, CMP(SLJIT_GREATER, STACK_TOP, 0, STACK_LIMIT, 0)); |
2125 | } | } |
2126 | ||
2127 | static SLJIT_INLINE void free_stack(compiler_common *common, int size) | static SLJIT_INLINE void free_stack(compiler_common *common, int size) |
2128 | { | { |
2129 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2130 | 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)); |
2131 | } | |
2132 | ||
2133 | static sljit_uw * allocate_read_only_data(compiler_common *common, sljit_uw size) | |
2134 | { | |
2135 | DEFINE_COMPILER; | |
2136 | sljit_uw *result; | |
2137 | ||
2138 | if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) | |
2139 | return NULL; | |
2140 | ||
2141 | result = (sljit_uw *)SLJIT_MALLOC(size + sizeof(sljit_uw), compiler->allocator_data); | |
2142 | if (SLJIT_UNLIKELY(result == NULL)) | |
2143 | { | |
2144 | sljit_set_compiler_memory_error(compiler); | |
2145 | return NULL; | |
2146 | } | |
2147 | ||
2148 | *(void**)result = common->read_only_data_head; | |
2149 | common->read_only_data_head = (void *)result; | |
2150 | return result + 1; | |
2151 | } | |
2152 | ||
2153 | static void free_read_only_data(void *current, void *allocator_data) | |
2154 | { | |
2155 | void *next; | |
2156 | ||
2157 | SLJIT_UNUSED_ARG(allocator_data); | |
2158 | ||
2159 | while (current != NULL) | |
2160 | { | |
2161 | next = *(void**)current; | |
2162 | SLJIT_FREE(current, allocator_data); | |
2163 | current = next; | |
2164 | } | |
2165 | } | } |
2166 | ||
2167 | static SLJIT_INLINE void reset_ovector(compiler_common *common, int length) | static SLJIT_INLINE void reset_ovector(compiler_common *common, int length) |
# | Line 1316 static SLJIT_INLINE void reset_ovector(c | Line 2169 static SLJIT_INLINE void reset_ovector(c |
2169 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2170 | struct sljit_label *loop; | struct sljit_label *loop; |
2171 | int i; | int i; |
2172 | ||
2173 | /* At this point we can freely use all temporary registers. */ | /* At this point we can freely use all temporary registers. */ |
2174 | SLJIT_ASSERT(length > 1); | |
2175 | /* TMP1 returns with begin - 1. */ | /* TMP1 returns with begin - 1. */ |
2176 | 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_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1)); |
2177 | if (length < 8) | |
2178 | { | |
2179 | for (i = 1; i < length; i++) | |
2180 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(i), SLJIT_R0, 0); | |
2181 | } | |
2182 | else | |
2183 | { | |
2184 | GET_LOCAL_BASE(SLJIT_R1, 0, OVECTOR_START); | |
2185 | OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, length - 1); | |
2186 | loop = LABEL(); | |
2187 | OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_sw), SLJIT_R0, 0); | |
2188 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, 1); | |
2189 | JUMPTO(SLJIT_NOT_ZERO, loop); | |
2190 | } | |
2191 | } | |
2192 | ||
2193 | static SLJIT_INLINE void do_reset_match(compiler_common *common, int length) | |
2194 | { | |
2195 | DEFINE_COMPILER; | |
2196 | struct sljit_label *loop; | |
2197 | int i; | |
2198 | ||
2199 | SLJIT_ASSERT(length > 1); | |
2200 | /* OVECTOR(1) contains the "string begin - 1" constant. */ | |
2201 | if (length > 2) | |
2202 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1)); | |
2203 | if (length < 8) | if (length < 8) |
2204 | { | { |
2205 | for (i = 0; i < length; i++) | for (i = 2; i < length; i++) |
2206 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_TEMPORARY_REG1, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(i), TMP1, 0); |
2207 | } | } |
2208 | else | else |
2209 | { | { |
2210 | GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w)); | GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw)); |
2211 | OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length); | OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2); |
2212 | loop = LABEL(); | loop = LABEL(); |
2213 | 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); |
2214 | 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); |
2215 | JUMPTO(SLJIT_C_NOT_ZERO, loop); | JUMPTO(SLJIT_NOT_ZERO, loop); |
2216 | } | |
2217 | ||
2218 | OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0); | |
2219 | if (common->mark_ptr != 0) | |
2220 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->mark_ptr, SLJIT_IMM, 0); | |
2221 | if (common->control_head_ptr != 0) | |
2222 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_IMM, 0); | |
2223 | OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack)); | |
2224 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->start_ptr); | |
2225 | OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base)); | |
2226 | } | |
2227 | ||
2228 | static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg) | |
2229 | { | |
2230 | while (current != NULL) | |
2231 | { | |
2232 | switch (current[-2]) | |
2233 | { | |
2234 | case type_then_trap: | |
2235 | break; | |
2236 | ||
2237 | case type_mark: | |
2238 | if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0) | |
2239 | return current[-4]; | |
2240 | break; | |
2241 | ||
2242 | default: | |
2243 | SLJIT_ASSERT_STOP(); | |
2244 | break; | |
2245 | } | |
2246 | SLJIT_ASSERT(current > (sljit_sw*)current[-1]); | |
2247 | current = (sljit_sw*)current[-1]; | |
2248 | } | } |
2249 | return -1; | |
2250 | } | } |
2251 | ||
2252 | static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket) | static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket) |
2253 | { | { |
2254 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2255 | struct sljit_label *loop; | struct sljit_label *loop; |
2256 | struct sljit_jump *earlyexit; | struct sljit_jump *early_quit; |
2257 | ||
2258 | /* At this point we can freely use all registers. */ | /* At this point we can freely use all registers. */ |
2259 | OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)); | OP1(SLJIT_MOV, SLJIT_S2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1)); |
2260 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(1), STR_PTR, 0); |
2261 | ||
2262 | OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0); | OP1(SLJIT_MOV, SLJIT_R0, 0, ARGUMENTS, 0); |
2263 | if (common->mark_ptr != 0) | if (common->mark_ptr != 0) |
2264 | OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr); | OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr); |
2265 | OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount)); | OP1(SLJIT_MOV_SI, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, offset_count)); |
2266 | if (common->mark_ptr != 0) | if (common->mark_ptr != 0) |
2267 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_TEMPORARY_REG3, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_R2, 0); |
2268 | 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_R2, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int)); |
2269 | OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, begin)); | OP1(SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, begin)); |
2270 | GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START); | GET_LOCAL_BASE(SLJIT_S0, 0, OVECTOR_START); |
2271 | /* Unlikely, but possible */ | /* Unlikely, but possible */ |
2272 | earlyexit = CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0); | early_quit = CMP(SLJIT_EQUAL, SLJIT_R1, 0, SLJIT_IMM, 0); |
2273 | loop = LABEL(); | loop = LABEL(); |
2274 | OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0); | OP2(SLJIT_SUB, SLJIT_S1, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0); |
2275 | OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_w)); | OP2(SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, sizeof(sljit_sw)); |
2276 | /* Copy the integer value to the output buffer */ | /* Copy the integer value to the output buffer */ |
2277 | #ifdef COMPILE_PCRE16 | #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32 |
2278 | OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1); | OP2(SLJIT_ASHR, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, UCHAR_SHIFT); |
2279 | #endif | #endif |
2280 | OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), sizeof(int), SLJIT_SAVED_REG2, 0); | OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_R2), sizeof(int), SLJIT_S1, 0); |
2281 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1); | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1); |
2282 | JUMPTO(SLJIT_C_NOT_ZERO, loop); | JUMPTO(SLJIT_NOT_ZERO, loop); |
2283 | JUMPHERE(earlyexit); | JUMPHERE(early_quit); |
2284 | ||
2285 | /* Calculate the return value, which is the maximum ovector value. */ | /* Calculate the return value, which is the maximum ovector value. */ |
2286 | if (topbracket > 1) | if (topbracket > 1) |
2287 | { | { |
2288 | GET_LOCAL_BASE(SLJIT_TEMPORARY_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_w)); | GET_LOCAL_BASE(SLJIT_R0, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw)); |
2289 | OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1); | OP1(SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, topbracket + 1); |
2290 | ||
2291 | /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */ | /* OVECTOR(0) is never equal to SLJIT_S2. */ |
2292 | loop = LABEL(); | loop = LABEL(); |
2293 | OP1(SLJIT_MOVU, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), -(2 * (sljit_w)sizeof(sljit_w))); | OP1(SLJIT_MOVU, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_R0), -(2 * (sljit_sw)sizeof(sljit_sw))); |
2294 | OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1); | OP2(SLJIT_SUB, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1); |
2295 | CMPTO(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG3, 0, loop); | CMPTO(SLJIT_EQUAL, SLJIT_R2, 0, SLJIT_S2, 0, loop); |
2296 | OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0); | OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_R1, 0); |
2297 | } | } |
2298 | else | else |
2299 | OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1); | OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1); |
2300 | } | } |
2301 | ||
2302 | static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *leave) | static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit) |
2303 | { | { |
2304 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2305 | struct sljit_jump *jump; | |
2306 | ||
2307 | SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2); | SLJIT_COMPILE_ASSERT(STR_END == SLJIT_S1, str_end_must_be_saved_reg2); |
2308 | 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 |
2309 | && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0)); | |
2310 | ||
2311 | OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0); | OP1(SLJIT_MOV, SLJIT_R1, 0, ARGUMENTS, 0); |
2312 | OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL); | OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL); |
2313 | OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, offsetcount)); | OP1(SLJIT_MOV_SI, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_R1), SLJIT_OFFSETOF(jit_arguments, real_offset_count)); |
2314 | CMPTO(SLJIT_C_LESS, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2, leave); | CMPTO(SLJIT_SIG_LESS, SLJIT_R2, 0, SLJIT_IMM, 2, quit); |
2315 | ||
2316 | /* Store match begin and end. */ | /* Store match begin and end. */ |
2317 | OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, begin)); | OP1(SLJIT_MOV, SLJIT_S0, 0, SLJIT_MEM1(SLJIT_R1), SLJIT_OFFSETOF(jit_arguments, begin)); |
2318 | OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, offsets)); | OP1(SLJIT_MOV, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R1), SLJIT_OFFSETOF(jit_arguments, offsets)); |
2319 | 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); | |
2320 | OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0); | jump = CMP(SLJIT_SIG_LESS, SLJIT_R2, 0, SLJIT_IMM, 3); |
2321 | #ifdef COMPILE_PCRE16 | OP2(SLJIT_SUB, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_SP), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + (int)sizeof(sljit_sw)), SLJIT_S0, 0); |
2322 | OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1); | #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32 |
2323 | #endif | OP2(SLJIT_ASHR, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, UCHAR_SHIFT); |
2324 | OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(int), SLJIT_SAVED_REG2, 0); | #endif |
2325 | OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_R1), 2 * sizeof(int), SLJIT_R2, 0); | |
2326 | OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG1, 0); | JUMPHERE(jump); |
2327 | #ifdef COMPILE_PCRE16 | |
2328 | OP2(SLJIT_ASHR, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1); | OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_SP), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start); |
2329 | OP2(SLJIT_SUB, SLJIT_S1, 0, STR_END, 0, SLJIT_S0, 0); | |
2330 | #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32 | |
2331 | OP2(SLJIT_ASHR, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, UCHAR_SHIFT); | |
2332 | #endif | #endif |
2333 | OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), 0, SLJIT_TEMPORARY_REG3, 0); | OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_R1), sizeof(int), SLJIT_S1, 0); |
2334 | ||
2335 | JUMPTO(SLJIT_JUMP, leave); | OP2(SLJIT_SUB, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_S0, 0); |
2336 | #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32 | |
2337 | OP2(SLJIT_ASHR, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, UCHAR_SHIFT); | |
2338 | #endif | |
2339 | OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_R1), 0, SLJIT_R2, 0); | |
2340 | ||
2341 | JUMPTO(SLJIT_JUMP, quit); | |
2342 | } | } |
2343 | ||
2344 | static SLJIT_INLINE void check_start_used_ptr(compiler_common *common) | static SLJIT_INLINE void check_start_used_ptr(compiler_common *common) |
# | Line 1425 struct sljit_jump *jump; | Line 2350 struct sljit_jump *jump; |
2350 | if (common->mode == JIT_PARTIAL_SOFT_COMPILE) | if (common->mode == JIT_PARTIAL_SOFT_COMPILE) |
2351 | { | { |
2352 | /* The value of -1 must be kept for start_used_ptr! */ | /* The value of -1 must be kept for start_used_ptr! */ |
2353 | OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, 1); | OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, SLJIT_IMM, 1); |
2354 | /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting | /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting |
2355 | is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */ | is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */ |
2356 | jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, STR_PTR, 0); | jump = CMP(SLJIT_LESS_EQUAL, TMP1, 0, STR_PTR, 0); |
2357 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0); |
2358 | JUMPHERE(jump); | JUMPHERE(jump); |
2359 | } | } |
2360 | else if (common->mode == JIT_PARTIAL_HARD_COMPILE) | else if (common->mode == JIT_PARTIAL_HARD_COMPILE) |
2361 | { | { |
2362 | jump = CMP(SLJIT_C_LESS_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0); | jump = CMP(SLJIT_LESS_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0); |
2363 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0); |
2364 | JUMPHERE(jump); | JUMPHERE(jump); |
2365 | } | } |
2366 | } | } |
2367 | ||
2368 | static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar* cc) | static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar *cc) |
2369 | { | { |
2370 | /* Detects if the character has an othercase. */ | /* Detects if the character has an othercase. */ |
2371 | unsigned int c; | unsigned int c; |
# | Line 1483 if (common->utf && c > 127) | Line 2408 if (common->utf && c > 127) |
2408 | return TABLE_GET(c, common->fcc, c); | return TABLE_GET(c, common->fcc, c); |
2409 | } | } |
2410 | ||
2411 | static unsigned int char_get_othercase_bit(compiler_common *common, pcre_uchar* cc) | static unsigned int char_get_othercase_bit(compiler_common *common, pcre_uchar *cc) |
2412 | { | { |
2413 | /* Detects if the character and its othercase has only 1 bit difference. */ | /* Detects if the character and its othercase has only 1 bit difference. */ |
2414 | unsigned int c, oc, bit; | unsigned int c, oc, bit; |
# | Line 1524 if (c <= 127 && bit == 0x20) | Line 2449 if (c <= 127 && bit == 0x20) |
2449 | return (0 << 8) | 0x20; | return (0 << 8) | 0x20; |
2450 | ||
2451 | /* Since c != oc, they must have at least 1 bit difference. */ | /* Since c != oc, they must have at least 1 bit difference. */ |
2452 | if (!ispowerof2(bit)) | if (!is_powerof2(bit)) |
2453 | return 0; | return 0; |
2454 | ||
2455 | #ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 |
2456 | ||
2457 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
2458 | if (common->utf && c > 127) | if (common->utf && c > 127) |
# | Line 1543 if (common->utf && c > 127) | Line 2468 if (common->utf && c > 127) |
2468 | #endif /* SUPPORT_UTF */ | #endif /* SUPPORT_UTF */ |
2469 | return (0 << 8) | bit; | return (0 << 8) | bit; |
2470 | ||
2471 | #else /* COMPILE_PCRE8 */ | #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32 |
2472 | ||
#ifdef COMPILE_PCRE16 | ||
2473 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
2474 | if (common->utf && c > 65535) | if (common->utf && c > 65535) |
2475 | { | { |
# | Line 1556 if (common->utf && c > 65535) | Line 2480 if (common->utf && c > 65535) |
2480 | } | } |
2481 | #endif /* SUPPORT_UTF */ | #endif /* SUPPORT_UTF */ |
2482 | return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8)); | return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8)); |
#endif /* COMPILE_PCRE16 */ | ||
2483 | ||
2484 | #endif /* COMPILE_PCRE8 */ | #endif /* COMPILE_PCRE[8|16|32] */ |
2485 | } | } |
2486 | ||
2487 | static void check_partial(compiler_common *common, BOOL force) | static void check_partial(compiler_common *common, BOOL force) |
2488 | { | { |
2489 | /* Checks whether a partial matching is occured. Does not modify registers. */ | /* Checks whether a partial matching is occurred. Does not modify registers. */ |
2490 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2491 | struct sljit_jump *jump = NULL; | struct sljit_jump *jump = NULL; |
2492 | ||
# | Line 1573 if (common->mode == JIT_COMPILE) | Line 2496 if (common->mode == JIT_COMPILE) |
2496 | return; | return; |
2497 | ||
2498 | if (!force) | if (!force) |
2499 | jump = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0); | jump = CMP(SLJIT_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0); |
2500 | else if (common->mode == JIT_PARTIAL_SOFT_COMPILE) | else if (common->mode == JIT_PARTIAL_SOFT_COMPILE) |
2501 | jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1); | jump = CMP(SLJIT_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, SLJIT_IMM, -1); |
2502 | ||
2503 | if (common->mode == JIT_PARTIAL_SOFT_COMPILE) | if (common->mode == JIT_PARTIAL_SOFT_COMPILE) |
2504 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0); |
2505 | else | else |
2506 | { | { |
2507 | if (common->partialmatchlabel != NULL) | if (common->partialmatchlabel != NULL) |
# | Line 1591 if (jump != NULL) | Line 2514 if (jump != NULL) |
2514 | JUMPHERE(jump); | JUMPHERE(jump); |
2515 | } | } |
2516 | ||
2517 | static struct sljit_jump *check_str_end(compiler_common *common) | static void check_str_end(compiler_common *common, jump_list **end_reached) |
2518 | { | { |
2519 | /* Does not affect registers. Usually used in a tight spot. */ | /* Does not affect registers. Usually used in a tight spot. */ |
2520 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2521 | struct sljit_jump *jump; | struct sljit_jump *jump; |
struct sljit_jump *nohit; | ||
struct sljit_jump *return_value; | ||
2522 | ||
2523 | if (common->mode == JIT_COMPILE) | if (common->mode == JIT_COMPILE) |
2524 | return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); | { |
2525 | add_jump(compiler, end_reached, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0)); | |
2526 | return; | |
2527 | } | |
2528 | ||
2529 | jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0); | jump = CMP(SLJIT_LESS, STR_PTR, 0, STR_END, 0); |
2530 | if (common->mode == JIT_PARTIAL_SOFT_COMPILE) | if (common->mode == JIT_PARTIAL_SOFT_COMPILE) |
2531 | { | { |
2532 | 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_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0)); |
2533 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0); |
2534 | JUMPHERE(nohit); | add_jump(compiler, end_reached, JUMP(SLJIT_JUMP)); |
return_value = JUMP(SLJIT_JUMP); | ||
2535 | } | } |
2536 | else | else |
2537 | { | { |
2538 | 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_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0)); |
2539 | if (common->partialmatchlabel != NULL) | if (common->partialmatchlabel != NULL) |
2540 | JUMPTO(SLJIT_JUMP, common->partialmatchlabel); | JUMPTO(SLJIT_JUMP, common->partialmatchlabel); |
2541 | else | else |
2542 | add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP)); | add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP)); |
2543 | } | } |
2544 | JUMPHERE(jump); | JUMPHERE(jump); |
return return_value; | ||
2545 | } | } |
2546 | ||
2547 | static void fallback_at_str_end(compiler_common *common, jump_list **fallbacks) | static void detect_partial_match(compiler_common *common, jump_list **backtracks) |
2548 | { | { |
2549 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2550 | struct sljit_jump *jump; | struct sljit_jump *jump; |
2551 | ||
2552 | if (common->mode == JIT_COMPILE) | if (common->mode == JIT_COMPILE) |
2553 | { | { |
2554 | add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0)); | add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0)); |
2555 | return; | return; |
2556 | } | } |
2557 | ||
2558 | /* Partial matching mode. */ | /* Partial matching mode. */ |
2559 | jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0); | jump = CMP(SLJIT_LESS, STR_PTR, 0, STR_END, 0); |
2560 | add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0)); | add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0)); |
2561 | if (common->mode == JIT_PARTIAL_SOFT_COMPILE) | if (common->mode == JIT_PARTIAL_SOFT_COMPILE) |
2562 | { | { |
2563 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1); | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0); |
2564 | add_jump(compiler, fallbacks, JUMP(SLJIT_JUMP)); | add_jump(compiler, backtracks, JUMP(SLJIT_JUMP)); |
2565 | } | } |
2566 | else | else |
2567 | { | { |
# | Line 1651 else | Line 2573 else |
2573 | JUMPHERE(jump); | JUMPHERE(jump); |
2574 | } | } |
2575 | ||
2576 | static void read_char(compiler_common *common) | static void peek_char(compiler_common *common, pcre_uint32 max) |
2577 | { | { |
2578 | /* Reads the character into TMP1, updates STR_PTR. | /* Reads the character into TMP1, keeps STR_PTR. |
2579 | Does not check STR_END. TMP2 Destroyed. */ | Does not check STR_END. TMP2 Destroyed. */ |
2580 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2581 | #ifdef SUPPORT_UTF | #if defined SUPPORT_UTF && !defined COMPILE_PCRE32 |
2582 | struct sljit_jump *jump; | struct sljit_jump *jump; |
2583 | #endif | #endif |
2584 | ||
2585 | SLJIT_UNUSED_ARG(max); | |
2586 | ||
2587 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); |
2588 | #ifdef SUPPORT_UTF | #if defined SUPPORT_UTF && defined COMPILE_PCRE8 |
2589 | if (common->utf) | if (common->utf) |
2590 | { | { |
2591 | #ifdef COMPILE_PCRE8 | if (max < 128) return; |
2592 | jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0); | |
2593 | #else | jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0); |
2594 | #ifdef COMPILE_PCRE16 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); |
jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800); | ||
#endif | ||
#endif /* COMPILE_PCRE8 */ | ||
2595 | add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL)); | add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL)); |
2596 | OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0); | |
2597 | JUMPHERE(jump); | |
2598 | } | |
2599 | #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */ | |
2600 | ||
2601 | #if defined SUPPORT_UTF && defined COMPILE_PCRE16 | |
2602 | if (common->utf) | |
2603 | { | |
2604 | if (max < 0xd800) return; | |
2605 | ||
2606 | OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800); | |
2607 | jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1); | |
2608 | /* TMP2 contains the high surrogate. */ | |
2609 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); | |
2610 | OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40); | |
2611 | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10); | |
2612 | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff); | |
2613 | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); | |
2614 | JUMPHERE(jump); | JUMPHERE(jump); |
2615 | } | } |
2616 | #endif | #endif |
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | ||
2617 | } | } |
2618 | ||
2619 | static void peek_char(compiler_common *common) | #if defined SUPPORT_UTF && defined COMPILE_PCRE8 |
2620 | ||
2621 | static BOOL is_char7_bitset(const pcre_uint8 *bitset, BOOL nclass) | |
2622 | { | { |
2623 | /* Reads the character into TMP1, keeps STR_PTR. | /* Tells whether the character codes below 128 are enough |
2624 | Does not check STR_END. TMP2 Destroyed. */ | to determine a match. */ |
2625 | const pcre_uint8 value = nclass ? 0xff : 0; | |
2626 | const pcre_uint8 *end = bitset + 32; | |
2627 | ||
2628 | bitset += 16; | |
2629 | do | |
2630 | { | |
2631 | if (*bitset++ != value) | |
2632 | return FALSE; | |
2633 | } | |
2634 | while (bitset < end); | |
2635 | return TRUE; | |
2636 | } | |
2637 | ||
2638 | static void read_char7_type(compiler_common *common, BOOL full_read) | |
2639 | { | |
2640 | /* Reads the precise character type of a character into TMP1, if the character | |
2641 | is less than 128. Otherwise it returns with zero. Does not check STR_END. The | |
2642 | full_read argument tells whether characters above max are accepted or not. */ | |
2643 | DEFINE_COMPILER; | DEFINE_COMPILER; |
#ifdef SUPPORT_UTF | ||
2644 | struct sljit_jump *jump; | struct sljit_jump *jump; |
#endif | ||
2645 | ||
2646 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); | SLJIT_ASSERT(common->utf); |
2647 | #ifdef SUPPORT_UTF | |
2648 | if (common->utf) | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0); |
2649 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | |
2650 | ||
2651 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); | |
2652 | ||
2653 | if (full_read) | |
2654 | { | { |
2655 | #ifdef COMPILE_PCRE8 | jump = CMP(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0xc0); |
2656 | jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0); | OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0); |
2657 | #else | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0); |
#ifdef COMPILE_PCRE16 | ||
jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800); | ||
#endif | ||
#endif /* COMPILE_PCRE8 */ | ||
add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL)); | ||
OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0); | ||
2658 | JUMPHERE(jump); | JUMPHERE(jump); |
2659 | } | } |
#endif | ||
2660 | } | } |
2661 | ||
2662 | static void read_char8_type(compiler_common *common) | #endif /* SUPPORT_UTF && COMPILE_PCRE8 */ |
2663 | ||
2664 | static void read_char_range(compiler_common *common, pcre_uint32 min, pcre_uint32 max, BOOL update_str_ptr) | |
2665 | { | { |
2666 | /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */ | /* Reads the precise value of a character into TMP1, if the character is |
2667 | between min and max (c >= min && c <= max). Otherwise it returns with a value | |
2668 | outside the range. Does not check STR_END. */ | |
2669 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2670 | #if defined SUPPORT_UTF || defined COMPILE_PCRE16 | #if defined SUPPORT_UTF && !defined COMPILE_PCRE32 |
2671 | struct sljit_jump *jump; | struct sljit_jump *jump; |
2672 | #endif | #endif |
2673 | #if defined SUPPORT_UTF && defined COMPILE_PCRE8 | |
2674 | struct sljit_jump *jump2; | |
2675 | #endif | |
2676 | ||
2677 | #ifdef SUPPORT_UTF | SLJIT_UNUSED_ARG(update_str_ptr); |
2678 | SLJIT_UNUSED_ARG(min); | |
2679 | SLJIT_UNUSED_ARG(max); | |
2680 | SLJIT_ASSERT(min <= max); | |
2681 | ||
2682 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); | |
2683 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | |
2684 | ||
2685 | #if defined SUPPORT_UTF && defined COMPILE_PCRE8 | |
2686 | if (common->utf) | if (common->utf) |
2687 | { | { |
2688 | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0); | if (max < 128 && !update_str_ptr) return; |
2689 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | |
2690 | #ifdef COMPILE_PCRE8 | jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0); |
2691 | /* This can be an extra read in some situations, but hopefully | if (min >= 0x10000) |
2692 | it is needed in most cases. */ | { |
2693 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); | OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xf0); |
2694 | jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0); | if (update_str_ptr) |
2695 | add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL)); | OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0); |
2696 | JUMPHERE(jump); | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); |
2697 | #else | jump2 = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0x7); |
2698 | #ifdef COMPILE_PCRE16 | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6); |
2699 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f); |
2700 | jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255); | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); |
2701 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); |
2702 | JUMPHERE(jump); | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); |
2703 | /* Skip low surrogate if necessary. */ | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); |
2704 | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00); | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); |
2705 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800); | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2)); |
2706 | COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL); | if (!update_str_ptr) |
2707 | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3)); |
2708 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0); | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); |
2709 | #endif | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); |
2710 | #endif /* COMPILE_PCRE8 */ | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); |
2711 | return; | JUMPHERE(jump2); |
2712 | if (update_str_ptr) | |
2713 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0); | |
2714 | } | |
2715 | else if (min >= 0x800 && max <= 0xffff) | |
2716 | { | |
2717 | OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xe0); | |
2718 | if (update_str_ptr) | |
2719 | OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0); | |
2720 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); | |
2721 | jump2 = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xf); | |
2722 | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6); | |
2723 | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f); | |
2724 | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); | |
2725 | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); | |
2726 | if (!update_str_ptr) | |
2727 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2)); | |
2728 | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); | |
2729 | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); | |
2730 | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); | |
2731 | JUMPHERE(jump2); | |
2732 | if (update_str_ptr) | |
2733 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0); | |
2734 | } | |
2735 | else if (max >= 0x800) | |
2736 | add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL)); | |
2737 | else if (max < 128) | |
2738 | { | |
2739 | OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0); | |
2740 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0); | |
2741 | } | |
2742 | else | |
2743 | { | |
2744 | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); | |
2745 | if (!update_str_ptr) | |
2746 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | |
2747 | else | |
2748 | OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0); | |
2749 | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f); | |
2750 | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); | |
2751 | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); | |
2752 | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); | |
2753 | if (update_str_ptr) | |
2754 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0); | |
2755 | } | |
2756 | JUMPHERE(jump); | |
2757 | } | } |
2758 | #endif | #endif |
2759 | ||
2760 | #if defined SUPPORT_UTF && defined COMPILE_PCRE16 | |
2761 | if (common->utf) | |
2762 | { | |
2763 | if (max >= 0x10000) | |
2764 | { | |
2765 | OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800); | |
2766 | jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1); | |
2767 | /* TMP2 contains the high surrogate. */ | |
2768 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); | |
2769 | OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40); | |
2770 | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10); | |
2771 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | |
2772 | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff); | |
2773 | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); | |
2774 | JUMPHERE(jump); | |
2775 | return; | |
2776 | } | |
2777 | ||
2778 | if (max < 0xd800 && !update_str_ptr) return; | |
2779 | ||
2780 | /* Skip low surrogate if necessary. */ | |
2781 | OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800); | |
2782 | jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1); | |
2783 | if (update_str_ptr) | |
2784 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | |
2785 | if (max >= 0xd800) | |
2786 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000); | |
2787 | JUMPHERE(jump); | |
2788 | } | |
2789 | #endif | |
2790 | } | |
2791 | ||
2792 | static SLJIT_INLINE void read_char(compiler_common *common) | |
2793 | { | |
2794 | read_char_range(common, 0, READ_CHAR_MAX, TRUE); | |
2795 | } | |
2796 | ||
2797 | static void read_char8_type(compiler_common *common, BOOL update_str_ptr) | |
2798 | { | |
2799 | /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */ | |
2800 | DEFINE_COMPILER; | |
2801 | #if defined SUPPORT_UTF || !defined COMPILE_PCRE8 | |
2802 | struct sljit_jump *jump; | |
2803 | #endif | |
2804 | #if defined SUPPORT_UTF && defined COMPILE_PCRE8 | |
2805 | struct sljit_jump *jump2; | |
2806 | #endif | |
2807 | ||
2808 | SLJIT_UNUSED_ARG(update_str_ptr); | |
2809 | ||
2810 | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0); | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0); |
2811 | 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)); |
2812 | #ifdef COMPILE_PCRE16 | |
2813 | #if defined SUPPORT_UTF && defined COMPILE_PCRE8 | |
2814 | if (common->utf) | |
2815 | { | |
2816 | /* This can be an extra read in some situations, but hopefully | |
2817 | it is needed in most cases. */ | |
2818 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); | |
2819 | jump = CMP(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0xc0); | |
2820 | if (!update_str_ptr) | |
2821 | { | |
2822 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); | |
2823 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | |
2824 | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); | |
2825 | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6); | |
2826 | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f); | |
2827 | OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0); | |
2828 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); | |
2829 | jump2 = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 255); | |
2830 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); | |
2831 | JUMPHERE(jump2); | |
2832 | } | |
2833 | else | |
2834 | add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL)); | |
2835 | JUMPHERE(jump); | |
2836 | return; | |
2837 | } | |
2838 | #endif /* SUPPORT_UTF && COMPILE_PCRE8 */ | |
2839 | ||
2840 | #if !defined COMPILE_PCRE8 | |
2841 | /* The ctypes array contains only 256 values. */ | /* The ctypes array contains only 256 values. */ |
2842 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); |
2843 | jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255); | jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 255); |
2844 | #endif | #endif |
2845 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); |
2846 | #ifdef COMPILE_PCRE16 | #if !defined COMPILE_PCRE8 |
2847 | JUMPHERE(jump); | JUMPHERE(jump); |
2848 | #endif | #endif |
2849 | ||
2850 | #if defined SUPPORT_UTF && defined COMPILE_PCRE16 | |
2851 | if (common->utf && update_str_ptr) | |
2852 | { | |
2853 | /* Skip low surrogate if necessary. */ | |
2854 | OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800); | |
2855 | jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1); | |
2856 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | |
2857 | JUMPHERE(jump); | |
2858 | } | |
2859 | #endif /* SUPPORT_UTF && COMPILE_PCRE16 */ | |
2860 | } | } |
2861 | ||
2862 | static void skip_char_back(compiler_common *common) | static void skip_char_back(compiler_common *common) |
2863 | { | { |
2864 | /* 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. */ |
2865 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2866 | #if defined SUPPORT_UTF && defined COMPILE_PCRE8 | #if defined SUPPORT_UTF && !defined COMPILE_PCRE32 |
2867 | #if defined COMPILE_PCRE8 | |
2868 | struct sljit_label *label; | struct sljit_label *label; |
2869 | ||
2870 | if (common->utf) | if (common->utf) |
# | Line 1768 if (common->utf) | Line 2873 if (common->utf) |
2873 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1)); | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1)); |
2874 | 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)); |
2875 | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0); | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0); |
2876 | CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label); | CMPTO(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label); |
2877 | return; | return; |
2878 | } | } |
2879 | #endif | #elif defined COMPILE_PCRE16 |
#if defined SUPPORT_UTF && defined COMPILE_PCRE16 | ||
2880 | if (common->utf) | if (common->utf) |
2881 | { | { |
2882 | 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 1780 if (common->utf) | Line 2884 if (common->utf) |
2884 | /* Skip low surrogate if necessary. */ | /* Skip low surrogate if necessary. */ |
2885 | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00); | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00); |
2886 | 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); |
2887 | COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL); | OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_EQUAL); |
2888 | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); |
2889 | OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0); | OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0); |
2890 | return; | return; |
2891 | } | } |
2892 | #endif | #endif /* COMPILE_PCRE[8|16] */ |
2893 | #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */ | |
2894 | 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)); |
2895 | } | } |
2896 | ||
2897 | static void check_newlinechar(compiler_common *common, int nltype, jump_list **fallbacks, BOOL jumpiftrue) | static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpifmatch) |
2898 | { | { |
2899 | /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */ | /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */ |
2900 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2901 | struct sljit_jump *jump; | |
2902 | ||
2903 | if (nltype == NLTYPE_ANY) | if (nltype == NLTYPE_ANY) |
2904 | { | { |
2905 | add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL)); | add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL)); |
2906 | add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO)); | add_jump(compiler, backtracks, JUMP(jumpifmatch ? SLJIT_NOT_ZERO : SLJIT_ZERO)); |
2907 | } | } |
2908 | else if (nltype == NLTYPE_ANYCRLF) | else if (nltype == NLTYPE_ANYCRLF) |
2909 | { | { |
2910 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR); | if (jumpifmatch) |
2911 | COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL); | { |
2912 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL); | add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR)); |
2913 | COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL); | add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL)); |
2914 | add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO)); | } |
2915 | else | |
2916 | { | |
2917 | jump = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR); | |
2918 | add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL)); | |
2919 | JUMPHERE(jump); | |
2920 | } | |
2921 | } | } |
2922 | else | else |
2923 | { | { |
2924 | SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256); | SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256); |
2925 | add_jump(compiler, fallbacks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline)); | add_jump(compiler, backtracks, CMP(jumpifmatch ? SLJIT_EQUAL : SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline)); |
2926 | } | } |
2927 | } | } |
2928 | ||
2929 | #ifdef SUPPORT_UTF | #ifdef SUPPORT_UTF |
2930 | ||
2931 | #ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 |
2932 | static void do_utfreadchar(compiler_common *common) | static void do_utfreadchar(compiler_common *common) |
2933 | { | { |
2934 | /* Fast decoding a UTF-8 character. TMP1 contains the first byte | /* Fast decoding a UTF-8 character. TMP1 contains the first byte |
2935 | of the character (>= 0xc0). Return char value in TMP1, length - 1 in TMP2. */ | of the character (>= 0xc0). Return char value in TMP1, length in TMP2. */ |
2936 | DEFINE_COMPILER; | DEFINE_COMPILER; |
2937 | struct sljit_jump *jump; | struct sljit_jump *jump; |
2938 | ||
2939 | sljit_emit_fast_enter(compiler, RETURN_ADDR, 0); | sljit_emit_fast_enter(compiler, RETURN_ADDR, 0); |
2940 | /* Searching for the first zero. */ | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); |
2941 | OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20); | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f); |
jump = JUMP(SLJIT_C_NOT_ZERO); | ||
/* Two byte sequence. */ | ||
OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); | ||
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | ||
OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f); | ||
2942 | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); |
2943 | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); |
2944 | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); |
2945 | OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1)); | |
2946 | /* Searching for the first zero. */ | |
2947 | OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800); | |
2948 | jump = JUMP(SLJIT_NOT_ZERO); | |
2949 | /* Two byte sequence. */ | |
2950 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | |
2951 | OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2)); | |
2952 | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); |
JUMPHERE(jump); | ||
2953 | ||
2954 | OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10); | JUMPHERE(jump); |
jump = JUMP(SLJIT_C_NOT_ZERO); | ||
/* Three byte sequence. */ | ||
2955 | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); |
2956 | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f); | OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800); |
2957 | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12); | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); |
2958 | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); |
OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6); | ||
2959 | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); |
2960 | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2)); | |
2961 | OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10000); | |
2962 | jump = JUMP(SLJIT_NOT_ZERO); | |
2963 | /* Three byte sequence. */ | |
2964 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2)); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2)); |
2965 | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); | OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3)); |
OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); | ||
OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2)); | ||
2966 | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); |
JUMPHERE(jump); | ||
2967 | ||
2968 | /* Four byte sequence. */ | /* Four byte sequence. */ |
2969 | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); | JUMPHERE(jump); |
2970 | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07); | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2)); |
2971 | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18); | OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000); |
2972 | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); | |
2973 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3)); | |
2974 | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); |
OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12); | ||
2975 | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); |
2976 | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2)); | OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(4)); |
2977 | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); | |
2978 | } | |
2979 | ||
2980 | static void do_utfreadchar16(compiler_common *common) | |
2981 | { | |
2982 | /* Fast decoding a UTF-8 character. TMP1 contains the first byte | |
2983 | of the character (>= 0xc0). Return value in TMP1. */ | |
2984 | DEFINE_COMPILER; | |
2985 | struct sljit_jump *jump; | |
2986 | ||
2987 | sljit_emit_fast_enter(compiler, RETURN_ADDR, 0); | |
2988 | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); | |
2989 | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f); | |
2990 | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); | |
2991 | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); |
OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6); | ||
2992 | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); |
2993 | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3)); | |
2994 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3)); | /* Searching for the first zero. */ |
2995 | OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800); | |
2996 | jump = JUMP(SLJIT_NOT_ZERO); | |
2997 | /* Two byte sequence. */ | |
2998 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | |
2999 | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); | |
3000 | ||
3001 | JUMPHERE(jump); | |
3002 | OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x400); | |
3003 | OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_NOT_ZERO); | |
3004 | /* This code runs only in 8 bit mode. No need to shift the value. */ | |
3005 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0); | |
3006 | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); | |
3007 | OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800); | |
3008 | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6); | |
3009 | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f); |
3010 | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); | OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); |
3011 | OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3)); | /* Three byte sequence. */ |
3012 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2)); | |
3013 | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); |
3014 | } | } |
3015 | ||
# | Line 1886 struct sljit_jump *compare; | Line 3024 struct sljit_jump *compare; |
3024 | sljit_emit_fast_enter(compiler, RETURN_ADDR, 0); | sljit_emit_fast_enter(compiler, RETURN_ADDR, 0); |
3025 | ||
3026 | OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20); | OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20); |
3027 | jump = JUMP(SLJIT_C_NOT_ZERO); | jump = JUMP(SLJIT_NOT_ZERO); |
3028 | /* Two byte sequence. */ | /* Two byte sequence. */ |
3029 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); |
3030 | 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)); |
3031 | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f); | OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f); |
3032 | /* The upper 5 bits are known at this point. */ | |
3033 | compare = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0x3); | |
3034 | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6); | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6); |
3035 | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f); | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f); |
3036 | OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0); | OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0); |
compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255); | ||
3037 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes); |
3038 | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); |
3039 | ||
3040 | JUMPHERE(compare); | JUMPHERE(compare); |
3041 | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); |
3042 | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); |
JUMPHERE(jump); | ||
3043 | ||
3044 | /* We only have types for characters less than 256. */ | /* We only have types for characters less than 256. */ |
OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(utf8_table4) - 0xc0); | ||
OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); | ||
OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); | ||
sljit_emit_fast_return(compiler, RETURN_ADDR, 0); | ||
} | ||
#else /* COMPILE_PCRE8 */ | ||
#ifdef COMPILE_PCRE16 | ||
static void do_utfreadchar(compiler_common *common) | ||
{ | ||
/* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char | ||
of the character (>= 0xd800). Return char value in TMP1, length - 1 in TMP2. */ | ||
DEFINE_COMPILER; | ||
struct sljit_jump *jump; | ||
sljit_emit_fast_enter(compiler, RETURN_ADDR, 0); | ||
jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00); | ||
/* Do nothing, only return. */ | ||
sljit_emit_fast_return(compiler, RETURN_ADDR, 0); | ||
3045 | JUMPHERE(jump); | JUMPHERE(jump); |
3046 | /* Combine two 16 bit characters. */ | OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0); |
3047 | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1)); | OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0); |
3048 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0); |
OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff); | ||
OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10); | ||
OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3ff); | ||
OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0); | ||
OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1)); | ||
OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000); | ||
3049 | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); |
3050 | } | } |
#endif /* COMPILE_PCRE16 */ | ||
3051 | ||
3052 | #endif /* COMPILE_PCRE8 */ | #endif /* COMPILE_PCRE8 */ |
3053 | ||
# | Line 1959 SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si | Line 3069 SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si |
3069 | ||
3070 | sljit_emit_fast_enter(compiler, RETURN_ADDR, 0); | sljit_emit_fast_enter(compiler, RETURN_ADDR, 0); |
3071 | OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT); | OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT); |
3072 | 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)); |
3073 | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK); | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK); |
3074 | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT); | OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT); |
3075 | OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0); | OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0); |
3076 | OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2)); | OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2)); |
3077 | OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1); | OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1); |
3078 | 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)); |
3079 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3); | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3); |
3080 | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); | sljit_emit_fast_return(compiler, RETURN_ADDR, 0); |
3081 | } | } |
# | Line 1979 struct sljit_label *newlinelabel = NULL; | Line 3089 struct sljit_label *newlinelabel = NULL; |
3089 | struct sljit_jump *start; | struct sljit_jump *start; |
3090 | struct sljit_jump *end = NULL; | struct sljit_jump *end = NULL; |
3091 | struct sljit_jump *nl = NULL; | struct sljit_jump *nl = NULL; |
3092 | #ifdef SUPPORT_UTF | #if defined SUPPORT_UTF && !defined COMPILE_PCRE32 |
3093 | struct sljit_jump *singlechar; | struct sljit_jump *singlechar; |
3094 | #endif | #endif |
3095 | jump_list *newline = NULL; | jump_list *newline = NULL; |
# | Line 1990 if (!(hascrorlf || firstline) && (common | Line 3100 if (!(hascrorlf || firstline) && (common |
3100 | common->nltype == NLTYPE_ANYCRLF || common->newline > 255)) | common->nltype == NLTYPE_ANYCRLF || common->newline > 255)) |
3101 | newlinecheck = TRUE; | newlinecheck = TRUE; |
3102 | ||
3103 | if (firstline) | if (firstline) |
3104 | { | { |
3105 | /* Search for the end of the first line. */ | /* Search for the end of the first line. */ |
3106 | SLJIT_ASSERT(common->first_line_end != 0); | SLJIT_ASSERT(common->first_line_end != 0); |
3107 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0); | OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0); |
3108 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_END, 0); | |
3109 | if (common->nltype == NLTYPE_FIXED && common->newline > 255) | |
3110 | { | |
3111 | mainloop = LABEL(); | |
3112 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | |
3113 | end = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); | |
3114 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1)); | |
3115 | OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0)); | |
3116 | CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop); | |
3117 | CMPTO(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop); | |
3118 | JUMPHERE(end); | |
3119 | OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_SP), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | |
3120 | } | |
3121 | else | |
3122 | { | |
3123 | end = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); | |
3124 | mainloop = LABEL(); | |
3125 | /* Continual stores does not cause data dependency. */ | |
3126 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->first_line_end, STR_PTR, 0); | |
3127 | read_char_range(common, common->nlmin, common->nlmax, TRUE); | |
3128 | check_newlinechar(common, common->nltype, &newline, TRUE); | |
3129 | CMPTO(SLJIT_LESS, STR_PTR, 0, STR_END, 0, mainloop); | |
3130 | JUMPHERE(end); | |
3131 | OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->first_line_end, STR_PTR, 0); | |
3132 | set_jumps(newline, LABEL()); | |
3133 | } | |
3134 | ||
3135 | OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0); | |
3136 | } | |
3137 | ||
3138 | start = JUMP(SLJIT_JUMP); | |
3139 | ||
3140 | if (newlinecheck) | |
3141 | { | |
3142 | newlinelabel = LABEL(); | |
3143 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | |
3144 | end = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0); | |
3145 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); | |
3146 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff); | |
3147 | OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_EQUAL); | |
3148 | #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32 | |
3149 | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT); | |
3150 | #endif | |
3151 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); | |
3152 | nl = JUMP(SLJIT_JUMP); | |
3153 | } | |
3154 | ||
3155 | mainloop = LABEL(); | |
3156 | ||
3157 | /* Increasing the STR_PTR here requires one less jump in the most common case. */ | |
3158 | #ifdef SUPPORT_UTF | |
3159 | if (common->utf) readuchar = TRUE; | |
3160 | #endif | |
3161 | if (newlinecheck) readuchar = TRUE; | |
3162 | ||
3163 | if (readuchar) | |
3164 | OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0); | |
3165 | ||
3166 | if (newlinecheck) | |
3167 | CMPTO(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel); | |
3168 | ||
3169 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); | |
3170 | #if defined SUPPORT_UTF && !defined COMPILE_PCRE32 | |
3171 | #if defined COMPILE_PCRE8 | |
3172 | if (common->utf) | |
3173 | { | |
3174 | singlechar = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0); | |
3175 | OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0); | |
3176 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); | |
3177 | JUMPHERE(singlechar); | |
3178 | } | |
3179 | #elif defined COMPILE_PCRE16 | |
3180 | if (common->utf) | |
3181 | { | |
3182 | singlechar = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xd800); | |
3183 | OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00); | |
3184 | OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800); | |
3185 | OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_EQUAL); | |
3186 | OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1); | |
3187 | OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0); | |
3188 | JUMPHERE(singlechar); | |
3189 | } | |
3190 | #endif /* COMPILE_PCRE[8|16] */ | |
3191 | #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */ | |
3192 | JUMPHERE(start); | |
3193 | ||
3194 | if (newlinecheck) | |
3195 | { | |
3196 | JUMPHERE(end); | |
3197 | JUMPHERE(nl); | |
3198 | } | |
3199 | ||
3200 | return mainloop; | |
3201 | } | |
3202 | ||
3203 | #define MAX_N_CHARS 16 | |
3204 | #define MAX_N_BYTES 8 | |
3205 | ||
3206 | static SLJIT_INLINE void add_prefix_byte(pcre_uint8 byte, pcre_uint8 *bytes) | |
3207 | { | |
3208 | pcre_uint8 len = bytes[0]; | |
3209 | int i; | |
3210 | ||
3211 | if (len == 255) | |
3212 | return; | |
3213 | ||
3214 | if (len == 0) | |
3215 | { | |
3216 | bytes[0] = 1; | |
3217 | bytes[1] = byte; | |
3218 | return; | |
3219 | } | |
3220 | ||
3221 | for (i = len; i > 0; i--) | |
3222 | if (bytes[i] == byte) | |
3223 | return; | |
3224 | ||
3225 | if (len >= MAX_N_BYTES - 1) | |
3226 | { | |
3227 | bytes[0] = 255; | |
3228 | return; | |
3229 | } | |
3230 | ||
3231 | len++; | |
3232 | bytes[len] = byte; | |
3233 | bytes[0] = len; | |
3234 | } | |
3235 | ||
3236 | static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, pcre_uint8 *bytes, int max_chars, pcre_uint32 *rec_count) | |
3237 | { | |
3238 | /* Recursive function, which scans prefix literals. */ | |
3239 | BOOL last, any, caseless; | |
3240 | int len, repeat, len_save, consumed = 0; | |
3241 | pcre_uint32 chr, mask; | |
3242 | pcre_uchar *alternative, *cc_save, *oc; | |
3243 | #if defined SUPPORT_UTF && defined COMPILE_PCRE8 | |
3244 | pcre_uchar othercase[8]; | |
3245 | #elif defined SUPPORT_UTF && defined COMPILE_PCRE16 | |
3246 | pcre_uchar othercase[2]; | |
3247 | #else | |
3248 | pcre_uchar othercase[1]; | |
3249 | #endif | |
3250 | ||
3251 | repeat = 1; | |
3252 | while (TRUE) | |
3253 | { | |
3254 | if (*rec_count == 0) | |
3255 | return 0; | |
3256 | (*rec_count)--; | |
3257 | ||
3258 | last = TRUE; | |
3259 | any = FALSE; | |
3260 | caseless = FALSE; | |
3261 | ||
3262 | switch (*cc) | |
3263 | { | |
3264 | case OP_CHARI: | |
3265 | caseless = TRUE; | |
3266 | case OP_CHAR: | |
3267 | last = FALSE; | |
3268 | cc++; | |
3269 | break; | |
3270 | ||
3271 | case OP_SOD: | |
3272 | case OP_SOM: | |
3273 | case OP_SET_SOM: | |
3274 | case OP_NOT_WORD_BOUNDARY: | |
3275 | case OP_WORD_BOUNDARY: | |
3276 | case OP_EODN: | |
3277 | case OP_EOD: | |
3278 | case OP_CIRC: | |
3279 | case OP_CIRCM: | |
3280 | case OP_DOLL: | |
3281 | case OP_DOLLM: | |
3282 | /* Zero width assertions. */ | |
3283 | cc++; | |
3284 | continue; | |
3285 | ||
3286 | case OP_ASSERT: | |
3287 | case OP_ASSERT_NOT: | |
3288 | case OP_ASSERTBACK: | |
3289 | case OP_ASSERTBACK_NOT: | |
3290 | cc = bracketend(cc); | |
3291 | continue; | |
3292 | ||
3293 | case OP_PLUSI: | |
3294 | case OP_MINPLUSI: | |
3295 | case OP_POSPLUSI: | |
3296 | caseless = TRUE; | |
3297 | case OP_PLUS: | |
3298 | case OP_MINPLUS: | |
3299 | case OP_POSPLUS: | |
3300 | cc++; | |
3301 | break; | |
3302 | ||
3303 | case OP_EXACTI: | |
3304 | caseless = TRUE; | |
3305 | case OP_EXACT: | |
3306 | repeat = GET2(cc, 1); | |
3307 | last = FALSE; | |
3308 | cc += 1 + IMM2_SIZE; | |
3309 | break; | |
3310 | ||
3311 | case OP_QUERYI: | |
3312 | case OP_MINQUERYI: | |
3313 | case OP_POSQUERYI: | |
3314 | caseless = TRUE; | |
3315 | case OP_QUERY: | |
3316 | case OP_MINQUERY: | |
3317 | case OP_POSQUERY: | |
3318 | len = 1; | |
3319 | cc++; | |
3320 | #ifdef SUPPORT_UTF | |
3321 | if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc); | |
3322 | #endif | |
3323 | max_chars = scan_prefix(common, cc + len, chars, bytes, max_chars, rec_count); | |
3324 | if (max_chars == 0) | |
3325 | return consumed; | |
3326 | last = FALSE; | |
3327 | break; | |
3328 | ||
3329 | case OP_KET: | |
3330 | cc += 1 + LINK_SIZE; | |
3331 | continue; | |
3332 | ||
3333 | case OP_ALT: | |
3334 | cc += GET(cc, 1); | |
3335 | continue; | |
3336 | ||
3337 | case OP_ONCE: | |
3338 | case OP_ONCE_NC: | |
3339 | case OP_BRA: | |
3340 | case OP_BRAPOS: | |
3341 | case OP_CBRA: | |
3342 | case OP_CBRAPOS: | |
3343 | alternative = cc + GET(cc, 1); | |
3344 | while (*alternative == OP_ALT) | |
3345 | { | |
3346 | max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, bytes, max_chars, rec_count); | |
3347 | if (max_chars == 0) | |
3348 | return consumed; | |
3349 | alternative += GET(alternative, 1); | |
3350 | } | |
3351 | ||
3352 | if (*cc == OP_CBRA || *cc == OP_CBRAPOS) | |
3353 | cc += IMM2_SIZE; | |
3354 | cc += 1 + LINK_SIZE; | |
3355 | continue; | |
3356 | ||
3357 | case OP_CLASS: | |
3358 | #if defined SUPPORT_UTF && defined COMPILE_PCRE8 | |
3359 | if (common->utf && !is_char7_bitset((const pcre_uint8 *)(cc + 1), FALSE)) return consumed; | |
3360 | #endif | |
3361 | any = TRUE; | |
3362 | cc += 1 + 32 / sizeof(pcre_uchar); | |
3363 | break; | |
3364 | ||
3365 | case OP_NCLASS: | |
3366 | #if defined SUPPORT_UTF && !defined COMPILE_PCRE32 | |
3367 | if (common->utf) return consumed; | |
3368 | #endif | |
3369 | any = TRUE; | |
3370 | cc += 1 + 32 / sizeof(pcre_uchar); | |
3371 | break; | |
3372 | ||
3373 | #if defined SUPPORT_UTF || !defined COMPILE_PCRE8 | |
3374 | case OP_XCLASS: | |
3375 | #if defined SUPPORT_UTF && !defined COMPILE_PCRE32 | |
3376 | if (common->utf) return consumed; | |
3377 | #endif | |
3378 | any = TRUE; | |
3379 | cc += GET(cc, 1); | |
3380 | break; | |
3381 | #endif | |
3382 | ||
3383 | case OP_DIGIT: | |
3384 | #if defined SUPPORT_UTF && defined COMPILE_PCRE8 | |
3385 | if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_digit, FALSE)) | |
3386 | return consumed; | |
3387 | #endif | |
3388 | any = TRUE; | |
3389 | cc++; | |
3390 | break; | |
3391 | ||
3392 | case OP_WHITESPACE: | |
3393 | #if defined SUPPORT_UTF && defined COMPILE_PCRE8 | |
3394 | if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_space, FALSE)) | |
3395 | return consumed; | |
3396 | #endif | |
3397 | any = TRUE; | |
3398 | cc++; | |
3399 | break; | |
3400 | ||
3401 | case OP_WORDCHAR: | |
3402 | #if defined SUPPORT_UTF && defined COMPILE_PCRE8 | |
3403 | if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_word, FALSE)) | |
3404 | return consumed; | |
3405 | #endif | |
3406 | any = TRUE; | |
3407 | cc++; | |
3408 | break; | |
3409 | ||
3410 | case OP_NOT: | |
3411 | case OP_NOTI: | |
3412 | cc++; | |
3413 | /* Fall through. */ | |
3414 | case OP_NOT_DIGIT: | |
3415 | case OP_NOT_WHITESPACE: | |
3416 | case OP_NOT_WORDCHAR: | |
3417 | case OP_ANY: | |
3418 | case OP_ALLANY: | |
3419 | #if defined SUPPORT_UTF && !defined COMPILE_PCRE32 | |
3420 | if (common->utf) return consumed; | |
3421 | #endif | |
3422 | any = TRUE; | |
3423 | cc++; | |
3424 | break; | |
3425 | ||
3426 | #ifdef SUPPORT_UCP | |
3427 | case OP_NOTPROP: | |
3428 | case OP_PROP: | |
3429 | #if defined SUPPORT_UTF && !defined COMPILE_PCRE32 | |
3430 | if (common->utf) return consumed; | |
3431 | #endif | |
3432 | any = TRUE; | |
3433 | cc += 1 + 2; | |
3434 | break; | |
3435 | #endif | |
3436 | ||
3437 | case OP_TYPEEXACT: | |
3438 | repeat = GET2(cc, 1); | |
3439 | cc += 1 + IMM2_SIZE; | |
3440 | continue; | |
3441 | ||
3442 | case OP_NOTEXACT: | |
3443 | case OP_NOTEXACTI: | |
3444 | #if defined SUPPORT_UTF && !defined COMPILE_PCRE32 | |
3445 | if (common->utf) return consumed; | |
3446 | #endif | |
3447 | any = TRUE; | |
3448 | repeat = GET2(cc, 1); | |
3449 | cc += 1 + IMM2_SIZE + 1; | |
3450 | break; | |
3451 | ||
3452 | default: | |
3453 | return consumed; | |
3454 | } | |
3455 | ||
3456 | if (any) | |
3457 | { | |
3458 | #if defined COMPILE_PCRE8 | |
3459 | mask = 0xff; | |
3460 | #elif defined COMPILE_PCRE16 | |
3461 | mask = 0xffff; | |
3462 | #elif defined COMPILE_PCRE32 | |
3463 | mask = 0xffffffff; | |
3464 | #else | |
3465 | SLJIT_ASSERT_STOP(); | |
3466 | #endif | |
3467 | ||
3468 | do | |
3469 | { | |
3470 | chars[0] = mask; | |
3471 | chars[1] = mask; | |
3472 | bytes[0] = 255; | |
3473 | ||
3474 | consumed++; | |
3475 | if (--max_chars == 0) | |
3476 | return consumed; | |
3477 | chars += 2; | |
3478 | bytes += MAX_N_BYTES; | |
3479 | } | |
3480 | while (--repeat > 0); | |
3481 | ||
3482 | repeat = 1; | |
3483 | continue; | |
3484 | } | |
3485 | ||
3486 | len = 1; | |
3487 | #ifdef SUPPORT_UTF | |
3488 | if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc); | |
3489 | #endif | |
3490 | ||
3491 | if (caseless && char_has_othercase(common, cc)) | |
3492 | { | |
3493 | #ifdef SUPPORT_UTF | |
3494 | if (common->utf) | |
3495 | { | |
3496 | GETCHAR(chr, cc); | |
3497 | if ((int)PRIV(ord2utf)(char_othercase(common, chr), othercase) != len) | |
3498 | return consumed; | |
3499 | } | |
3500 | else | |
3501 | #endif | |
3502 | { | |
3503 | chr = *cc; | |
3504 | othercase[0] = TABLE_GET(chr, common->fcc, chr); | |
3505 | } | |
3506 | } | |
3507 | else | |
3508 | caseless = FALSE; | |
3509 | ||
3510 | len_save = len; | |
3511 | cc_save = cc; | |
3512 | while (TRUE) | |
3513 | { | |
3514 | oc = othercase; | |
3515 | do | |
3516 | { | |
3517 | chr = *cc; | |
3518 | #ifdef COMPILE_PCRE32 | |
3519 | if (SLJIT_UNLIKELY(chr == NOTACHAR)) | |
3520 | return consumed; | |
3521 | #endif | |
3522 | add_prefix_byte((pcre_uint8)chr, bytes); | |
3523 | ||
3524 | mask = 0; | |
3525 | if (caseless) | |
3526 | { | |
3527 | add_prefix_byte((pcre_uint8)*oc, bytes); | |
3528 | mask = *cc ^ *oc; | |
3529 | chr |= mask; | |
3530 | } | |
3531 | ||
3532 | #ifdef COMPILE_PCRE32 | |
3533 | if (chars[0] == NOTACHAR && chars[1] == 0) | |
3534 | #else | |
3535 | if (chars[0] == NOTACHAR) | |
3536 | #endif | |
3537 | { | |
3538 | chars[0] = chr; | |
3539 | chars[1] = mask; | |
3540 | } | |
3541 | else | |
3542 | { | |
3543 | mask |= chars[0] ^ chr; | |
3544 | chr |= mask; | |
3545 | chars[0] = chr; | |
3546 | chars[1] |= mask; | |
3547 | } | |
3548 | ||
3549 | len--; | |
3550 | consumed++; | |