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