/[pcre]/code/trunk/pcre_jit_compile.c
ViewVC logotype

Diff of /code/trunk/pcre_jit_compile.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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