/[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 941 by zherczeg, Tue Feb 28 11:33:34 2012 UTC revision 1419 by zherczeg, Sun Dec 29 04:42:14 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11    The machine code generator part (this module) was written by Zoltan Herczeg    The machine code generator part (this module) was written by Zoltan Herczeg
12                        Copyright (c) 2010-2012                        Copyright (c) 2010-2013
13    
14  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
15  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 46  POSSIBILITY OF SUCH DAMAGE. Line 46  POSSIBILITY OF SUCH DAMAGE.
46    
47  #include "pcre_internal.h"  #include "pcre_internal.h"
48    
49  #ifdef SUPPORT_JIT  #if defined SUPPORT_JIT
50    
51  /* All-in-one: Since we use the JIT compiler only from here,  /* All-in-one: Since we use the JIT compiler only from here,
52  we just include it. This way we don't need to touch the build  we just include it. This way we don't need to touch the build
# Line 65  system files. */ Line 65  system files. */
65  #error Unsupported architecture  #error Unsupported architecture
66  #endif  #endif
67    
68  /* Allocate memory on the stack. Fast, but limited size. */  /* Defines for debugging purposes. */
 #define LOCAL_SPACE_SIZE 32768  
69    
70    /* 1 - Use unoptimized capturing brackets.
71       2 - Enable capture_last_ptr (includes option 1). */
72    /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */
73    
74    /* 1 - Always have a control head. */
75    /* #define DEBUG_FORCE_CONTROL_HEAD 1 */
76    
77    /* Allocate memory for the regex stack on the real machine stack.
78    Fast, but limited size. */
79    #define MACHINE_STACK_SIZE 32768
80    
81    /* Growth rate for stack allocated by the OS. Should be the multiply
82    of page size. */
83  #define STACK_GROWTH_RATE 8192  #define STACK_GROWTH_RATE 8192
84    
85  /* Enable to check that the allocation could destroy temporaries. */  /* Enable to check that the allocation could destroy temporaries. */
# Line 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 167  typedef struct executable_functions { Line 181  typedef struct executable_functions {
181    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184      pcre_uint32 top_bracket;
185      pcre_uint32 limit_match;
186    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
187  } executable_functions;  } executable_functions;
188    
# Line 175  typedef struct jump_list { Line 191  typedef struct jump_list {
191    struct jump_list *next;    struct jump_list *next;
192  } jump_list;  } jump_list;
193    
 enum stub_types { stack_alloc };  
   
194  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
195    struct sljit_jump *start;    struct sljit_jump *start;
196    struct sljit_label *leave;    struct sljit_label *quit;
197    struct stub_list *next;    struct stub_list *next;
198  } stub_list;  } stub_list;
199    
200    enum frame_types {
201      no_frame = -1,
202      no_stack = -2
203    };
204    
205    enum control_types {
206      type_mark = 0,
207      type_then_trap = 1
208    };
209    
210  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
213  code generator. It is allocated by compile_hotpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
214  the aguments for compile_fallbackpath. Must be the first member  the arguments for compile_backtrackingpath. Must be the first member
215  of its descendants. */  of its descendants. */
216  typedef struct fallback_common {  typedef struct backtrack_common {
217    /* Concatenation stack. */    /* Concatenation stack. */
218    struct fallback_common *prev;    struct backtrack_common *prev;
219    jump_list *nextfallbacks;    jump_list *nextbacktracks;
220    /* Internal stack (for component operators). */    /* Internal stack (for component operators). */
221    struct fallback_common *top;    struct backtrack_common *top;
222    jump_list *topfallbacks;    jump_list *topbacktracks;
223    /* Opcode pointer. */    /* Opcode pointer. */
224    pcre_uchar *cc;    pcre_uchar *cc;
225  } fallback_common;  } backtrack_common;
226    
227  typedef struct assert_fallback {  typedef struct assert_backtrack {
228    fallback_common common;    backtrack_common common;
229    jump_list *condfailed;    jump_list *condfailed;
230    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
231    int framesize;    int framesize;
232    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
233    int localptr;    int private_data_ptr;
234    /* For iterators. */    /* For iterators. */
235    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
236  } assert_fallback;  } assert_backtrack;
237    
238  typedef struct bracket_fallback {  typedef struct bracket_backtrack {
239    fallback_common common;    backtrack_common common;
240    /* Where to coninue if an alternative is successfully matched. */    /* Where to coninue if an alternative is successfully matched. */
241    struct sljit_label *althotpath;    struct sljit_label *alternative_matchingpath;
242    /* For rmin and rmax iterators. */    /* For rmin and rmax iterators. */
243    struct sljit_label *recursivehotpath;    struct sljit_label *recursive_matchingpath;
244    /* For greedy ? operator. */    /* For greedy ? operator. */
245    struct sljit_label *zerohotpath;    struct sljit_label *zero_matchingpath;
246    /* Contains the branches of a failed condition. */    /* Contains the branches of a failed condition. */
247    union {    union {
248      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
249      jump_list *condfailed;      jump_list *condfailed;
250      assert_fallback *assert;      assert_backtrack *assert;
251      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
252      int framesize;      int framesize;
253    } u;    } u;
254    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
255    int localptr;    int private_data_ptr;
256  } bracket_fallback;  } bracket_backtrack;
257    
258  typedef struct bracketpos_fallback {  typedef struct bracketpos_backtrack {
259    fallback_common common;    backtrack_common common;
260    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
261    int localptr;    int private_data_ptr;
262    /* Reverting stack is needed. */    /* Reverting stack is needed. */
263    int framesize;    int framesize;
264    /* Allocated stack size. */    /* Allocated stack size. */
265    int stacksize;    int stacksize;
266  } bracketpos_fallback;  } bracketpos_backtrack;
267    
268  typedef struct braminzero_fallback {  typedef struct braminzero_backtrack {
269    fallback_common common;    backtrack_common common;
270    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
271  } braminzero_fallback;  } braminzero_backtrack;
272    
273  typedef struct iterator_fallback {  typedef struct iterator_backtrack {
274    fallback_common common;    backtrack_common common;
275    /* Next iteration. */    /* Next iteration. */
276    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
277  } iterator_fallback;  } iterator_backtrack;
278    
279  typedef struct recurse_entry {  typedef struct recurse_entry {
280    struct recurse_entry *next;    struct recurse_entry *next;
# Line 261  typedef struct recurse_entry { Line 283  typedef struct recurse_entry {
283    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
284    jump_list *calls;    jump_list *calls;
285    /* Points to the starting opcode. */    /* Points to the starting opcode. */
286    int start;    sljit_sw start;
287  } recurse_entry;  } recurse_entry;
288    
289  typedef struct recurse_fallback {  typedef struct recurse_backtrack {
290    fallback_common common;    backtrack_common common;
291  } recurse_fallback;    BOOL inlined_pattern;
292    } recurse_backtrack;
293    
294    #define OP_THEN_TRAP OP_TABLE_LENGTH
295    
296    typedef struct then_trap_backtrack {
297      backtrack_common common;
298      /* If then_trap is not NULL, this structure contains the real
299      then_trap for the backtracking path. */
300      struct then_trap_backtrack *then_trap;
301      /* Points to the starting opcode. */
302      sljit_sw start;
303      /* Exit point for the then opcodes of this alternative. */
304      jump_list *quit;
305      /* Frame size of the current alternative. */
306      int framesize;
307    } then_trap_backtrack;
308    
309    #define MAX_RANGE_SIZE 4
310    
311  typedef struct compiler_common {  typedef struct compiler_common {
312      /* The sljit ceneric compiler. */
313    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
314      /* First byte code. */
315    pcre_uchar *start;    pcre_uchar *start;
316      /* Maps private data offset to each opcode. */
317    /* Local stack area size and variable pointers. */    sljit_si *private_data_ptrs;
318    int localsize;    /* Tells whether the capturing bracket is optimized. */
319    int *localptrs;    pcre_uint8 *optimized_cbracket;
320    int cbraptr;    /* Tells whether the starting offset is a target of then. */
321    /* OVector starting point. Must be divisible by 2. */    pcre_uint8 *then_offsets;
322      /* Current position where a THEN must jump. */
323      then_trap_backtrack *then_trap;
324      /* Starting offset of private data for capturing brackets. */
325      int cbra_ptr;
326      /* Output vector starting point. Must be divisible by 2. */
327    int ovector_start;    int ovector_start;
328    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
329    int req_char_ptr;    int req_char_ptr;
330    /* Head of the last recursion. */    /* Head of the last recursion. */
331    int recursive_head;    int recursive_head_ptr;
332    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
333    int start_used_ptr;    int start_used_ptr;
334    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 290  typedef struct compiler_common { Line 337  typedef struct compiler_common {
337    int first_line_end;    int first_line_end;
338    /* Points to the marked string. */    /* Points to the marked string. */
339    int mark_ptr;    int mark_ptr;
340      /* Recursive control verb management chain. */
341      int control_head_ptr;
342      /* Points to the last matched capture block index. */
343      int capture_last_ptr;
344      /* Points to the starting position of the current match. */
345      int start_ptr;
346    
347    /* Other  */    /* Flipped and lower case tables. */
348    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
349    sljit_w lcc;    sljit_sw lcc;
350      /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
351    int mode;    int mode;
352      /* \K is found in the pattern. */
353      BOOL has_set_som;
354      /* (*SKIP:arg) is found in the pattern. */
355      BOOL has_skip_arg;
356      /* (*THEN) is found in the pattern. */
357      BOOL has_then;
358      /* Needs to know the start position anytime. */
359      BOOL needs_start_ptr;
360      /* Currently in recurse or negative assert. */
361      BOOL local_exit;
362      /* Currently in a positive assert. */
363      BOOL positive_assert;
364      /* Newline control. */
365    int nltype;    int nltype;
366    int newline;    int newline;
367    int bsr_nltype;    int bsr_nltype;
368      /* Dollar endonly. */
369    int endonly;    int endonly;
370    BOOL has_set_som;    /* Tables. */
371    sljit_w ctypes;    sljit_sw ctypes;
372    sljit_uw name_table;    int digits[2 + MAX_RANGE_SIZE];
373    sljit_w name_count;    /* Named capturing brackets. */
374    sljit_w name_entry_size;    pcre_uchar *name_table;
375      sljit_sw name_count;
376      sljit_sw name_entry_size;
377    
378    /* Labels and jump lists. */    /* Labels and jump lists. */
379    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
380    struct sljit_label *leavelabel;    struct sljit_label *quit_label;
381    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
382      struct sljit_label *accept_label;
383    stub_list *stubs;    stub_list *stubs;
384    recurse_entry *entries;    recurse_entry *entries;
385    recurse_entry *currententry;    recurse_entry *currententry;
386    jump_list *partialmatch;    jump_list *partialmatch;
387    jump_list *leave;    jump_list *quit;
388      jump_list *positive_assert_quit;
389      jump_list *forced_quit;
390    jump_list *accept;    jump_list *accept;
391    jump_list *calllimit;    jump_list *calllimit;
392    jump_list *stackalloc;    jump_list *stackalloc;
# Line 324  typedef struct compiler_common { Line 397  typedef struct compiler_common {
397    jump_list *vspace;    jump_list *vspace;
398    jump_list *casefulcmp;    jump_list *casefulcmp;
399    jump_list *caselesscmp;    jump_list *caselesscmp;
400      jump_list *reset_match;
401    BOOL jscript_compat;    BOOL jscript_compat;
402  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
403    BOOL utf;    BOOL utf;
404  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
405    BOOL use_ucp;    BOOL use_ucp;
406  #endif  #endif
407    #ifndef COMPILE_PCRE32
408    jump_list *utfreadchar;    jump_list *utfreadchar;
409    #endif
410  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
411    jump_list *utfreadtype8;    jump_list *utfreadtype8;
412  #endif  #endif
# Line 348  typedef struct compare_context { Line 424  typedef struct compare_context {
424  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
425    int ucharptr;    int ucharptr;
426    union {    union {
427      sljit_i asint;      sljit_si asint;
428      sljit_uh asushort;      sljit_uh asushort;
429  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
430      sljit_ub asbyte;      sljit_ub asbyte;
431      sljit_ub asuchars[4];      sljit_ub asuchars[4];
432  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
433      sljit_uh asuchars[2];      sljit_uh asuchars[2];
434  #endif  #elif defined COMPILE_PCRE32
435        sljit_ui asuchars[1];
436  #endif  #endif
437    } c;    } c;
438    union {    union {
439      sljit_i asint;      sljit_si asint;
440      sljit_uh asushort;      sljit_uh asushort;
441  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
442      sljit_ub asbyte;      sljit_ub asbyte;
443      sljit_ub asuchars[4];      sljit_ub asuchars[4];
444  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
445      sljit_uh asuchars[2];      sljit_uh asuchars[2];
446  #endif  #elif defined COMPILE_PCRE32
447        sljit_ui asuchars[1];
448  #endif  #endif
449    } oc;    } oc;
450  #endif  #endif
451  } compare_context;  } compare_context;
452    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
453  /* Undefine sljit macros. */  /* Undefine sljit macros. */
454  #undef CMP  #undef CMP
455    
456  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
457  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
458    
459  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
460  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
461  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
462  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
463  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
464  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
465  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
466  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
467  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define COUNT_MATCH   SLJIT_SAVED_EREG2
468  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
469    
470  /* Locals layout. */  /* Local space layout. */
471  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
472  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
473  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
474  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
475  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
476  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
477  /* Max limit of recursions. */  /* Max limit of recursions. */
478  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
479  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
480  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
481  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
482  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. */
483  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
484  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw))
485  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
486  #define PRIV_DATA(cc)    (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
487    
488  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
489  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
490  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
491  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
492  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
493  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
494    #elif defined COMPILE_PCRE32
495    #define MOV_UCHAR  SLJIT_MOV_UI
496    #define MOVU_UCHAR SLJIT_MOVU_UI
497  #else  #else
498  #error Unsupported compiling mode  #error Unsupported compiling mode
499  #endif  #endif
 #endif  
500    
501  /* Shortcuts. */  /* Shortcuts. */
502  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 442  the start pointers when the end of the c Line 513  the start pointers when the end of the c
513    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
514  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
515    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
516    #define SET_LABEL(jump, label) \
517      sljit_set_label((jump), (label))
518  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
519    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
520  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
521    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))
522  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
523    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
524    #define GET_LOCAL_BASE(dst, dstw, offset) \
525      sljit_get_local_base(compiler, (dst), (dstw), (offset))
526    
527  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
528  {  {
# Line 458  cc += 1 + LINK_SIZE; Line 533  cc += 1 + LINK_SIZE;
533  return cc;  return cc;
534  }  }
535    
536    static int ones_in_half_byte[16] = {
537      /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
538      /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
539    };
540    
541  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
542   next_opcode   next_opcode
543   get_localspace   check_opcode_types
544   set_localptrs   set_private_data_ptrs
545   get_framesize   get_framesize
546   init_frame   init_frame
547   get_localsize   get_private_data_copy_length
548   copy_locals   copy_private_data
549   compile_hotpath   compile_matchingpath
550   compile_fallbackpath   compile_backtrackingpath
551  */  */
552    
553  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
# Line 488  switch(*cc) Line 568  switch(*cc)
568    case OP_WORDCHAR:    case OP_WORDCHAR:
569    case OP_ANY:    case OP_ANY:
570    case OP_ALLANY:    case OP_ALLANY:
571      case OP_NOTPROP:
572      case OP_PROP:
573    case OP_ANYNL:    case OP_ANYNL:
574    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
575    case OP_HSPACE:    case OP_HSPACE:
# Line 500  switch(*cc) Line 582  switch(*cc)
582    case OP_CIRCM:    case OP_CIRCM:
583    case OP_DOLL:    case OP_DOLL:
584    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:  
585    case OP_CRSTAR:    case OP_CRSTAR:
586    case OP_CRMINSTAR:    case OP_CRMINSTAR:
587    case OP_CRPLUS:    case OP_CRPLUS:
588    case OP_CRMINPLUS:    case OP_CRMINPLUS:
589    case OP_CRQUERY:    case OP_CRQUERY:
590    case OP_CRMINQUERY:    case OP_CRMINQUERY:
591      case OP_CRRANGE:
592      case OP_CRMINRANGE:
593      case OP_CRPOSSTAR:
594      case OP_CRPOSPLUS:
595      case OP_CRPOSQUERY:
596      case OP_CRPOSRANGE:
597      case OP_CLASS:
598      case OP_NCLASS:
599      case OP_REF:
600      case OP_REFI:
601      case OP_DNREF:
602      case OP_DNREFI:
603      case OP_RECURSE:
604      case OP_CALLOUT:
605      case OP_ALT:
606      case OP_KET:
607      case OP_KETRMAX:
608      case OP_KETRMIN:
609      case OP_KETRPOS:
610      case OP_REVERSE:
611      case OP_ASSERT:
612      case OP_ASSERT_NOT:
613      case OP_ASSERTBACK:
614      case OP_ASSERTBACK_NOT:
615      case OP_ONCE:
616      case OP_ONCE_NC:
617      case OP_BRA:
618      case OP_BRAPOS:
619      case OP_CBRA:
620      case OP_CBRAPOS:
621      case OP_COND:
622      case OP_SBRA:
623      case OP_SBRAPOS:
624      case OP_SCBRA:
625      case OP_SCBRAPOS:
626      case OP_SCOND:
627      case OP_CREF:
628      case OP_DNCREF:
629      case OP_RREF:
630      case OP_DNRREF:
631    case OP_DEF:    case OP_DEF:
632    case OP_BRAZERO:    case OP_BRAZERO:
633    case OP_BRAMINZERO:    case OP_BRAMINZERO:
634    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
635      case OP_PRUNE:
636      case OP_SKIP:
637      case OP_THEN:
638    case OP_COMMIT:    case OP_COMMIT:
639    case OP_FAIL:    case OP_FAIL:
640    case OP_ACCEPT:    case OP_ACCEPT:
641    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
642      case OP_CLOSE:
643    case OP_SKIPZERO:    case OP_SKIPZERO:
644    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
645    
646    case OP_CHAR:    case OP_CHAR:
647    case OP_CHARI:    case OP_CHARI:
# Line 542  switch(*cc) Line 653  switch(*cc)
653    case OP_MINPLUS:    case OP_MINPLUS:
654    case OP_QUERY:    case OP_QUERY:
655    case OP_MINQUERY:    case OP_MINQUERY:
656      case OP_UPTO:
657      case OP_MINUPTO:
658      case OP_EXACT:
659    case OP_POSSTAR:    case OP_POSSTAR:
660    case OP_POSPLUS:    case OP_POSPLUS:
661    case OP_POSQUERY:    case OP_POSQUERY:
662      case OP_POSUPTO:
663    case OP_STARI:    case OP_STARI:
664    case OP_MINSTARI:    case OP_MINSTARI:
665    case OP_PLUSI:    case OP_PLUSI:
666    case OP_MINPLUSI:    case OP_MINPLUSI:
667    case OP_QUERYI:    case OP_QUERYI:
668    case OP_MINQUERYI:    case OP_MINQUERYI:
669      case OP_UPTOI:
670      case OP_MINUPTOI:
671      case OP_EXACTI:
672    case OP_POSSTARI:    case OP_POSSTARI:
673    case OP_POSPLUSI:    case OP_POSPLUSI:
674    case OP_POSQUERYI:    case OP_POSQUERYI:
675      case OP_POSUPTOI:
676    case OP_NOTSTAR:    case OP_NOTSTAR:
677    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
678    case OP_NOTPLUS:    case OP_NOTPLUS:
679    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
680    case OP_NOTQUERY:    case OP_NOTQUERY:
681    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
682      case OP_NOTUPTO:
683      case OP_NOTMINUPTO:
684      case OP_NOTEXACT:
685    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
686    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
687    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
688      case OP_NOTPOSUPTO:
689    case OP_NOTSTARI:    case OP_NOTSTARI:
690    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
691    case OP_NOTPLUSI:    case OP_NOTPLUSI:
692    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
693    case OP_NOTQUERYI:    case OP_NOTQUERYI:
694    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:  
695    case OP_NOTUPTOI:    case OP_NOTUPTOI:
696    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
697    case OP_NOTEXACTI:    case OP_NOTEXACTI:
698      case OP_NOTPOSSTARI:
699      case OP_NOTPOSPLUSI:
700      case OP_NOTPOSQUERYI:
701    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
702    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
703  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
704    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
705  #endif  #endif
706    return cc;    return cc;
707    
708    case OP_NOTPROP:    /* Special cases. */
709    case OP_PROP:    case OP_TYPESTAR:
710    return cc + 1 + 2;    case OP_TYPEMINSTAR:
711      case OP_TYPEPLUS:
712      case OP_TYPEMINPLUS:
713      case OP_TYPEQUERY:
714      case OP_TYPEMINQUERY:
715    case OP_TYPEUPTO:    case OP_TYPEUPTO:
716    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
717    case OP_TYPEEXACT:    case OP_TYPEEXACT:
718      case OP_TYPEPOSSTAR:
719      case OP_TYPEPOSPLUS:
720      case OP_TYPEPOSQUERY:
721    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
722    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;  
723    
724    case OP_CRRANGE:    case OP_ANYBYTE:
725    case OP_CRMINRANGE:  #ifdef SUPPORT_UTF
726    return cc + 1 + 2 * IMM2_SIZE;    if (common->utf) return NULL;
727    #endif
728    case OP_CLASS:    return cc + 1;
   case OP_NCLASS:  
   return cc + 1 + 32 / sizeof(pcre_uchar);  
729    
730  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
731    case OP_XCLASS:    case OP_XCLASS:
732    return cc + GET(cc, 1);    return cc + GET(cc, 1);
733  #endif  #endif
734    
   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;  
   
735    case OP_MARK:    case OP_MARK:
736      case OP_PRUNE_ARG:
737      case OP_SKIP_ARG:
738      case OP_THEN_ARG:
739    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
740    
741    default:    default:
742      /* All opcodes are supported now! */
743      SLJIT_ASSERT_STOP();
744    return NULL;    return NULL;
745    }    }
746  }  }
747    
748  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)
749  {  {
750  int localspace = 0;  int count;
751  pcre_uchar *alternative;  pcre_uchar *slot;
752    
753  /* 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. */
754  while (cc < ccend)  while (cc < ccend)
755    {    {
# Line 680  while (cc < ccend) Line 760  while (cc < ccend)
760      cc += 1;      cc += 1;
761      break;      break;
762    
763      case OP_ASSERT:      case OP_REF:
764      case OP_ASSERT_NOT:      case OP_REFI:
765      case OP_ASSERTBACK:      common->optimized_cbracket[GET2(cc, 1)] = 0;
766      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;  
767      break;      break;
768    
769      case OP_CBRAPOS:      case OP_CBRAPOS:
770      case OP_SCBRAPOS:      case OP_SCBRAPOS:
771      localspace += sizeof(sljit_w);      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
772      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
773      break;      break;
774    
775      case OP_COND:      case OP_COND:
776      /* Might be a hidden SCOND. */      case OP_SCOND:
777      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
778      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
779        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
780          return FALSE;
781      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
782      break;      break;
783    
784        case OP_CREF:
785        common->optimized_cbracket[GET2(cc, 1)] = 0;
786        cc += 1 + IMM2_SIZE;
787        break;
788    
789        case OP_DNREF:
790        case OP_DNREFI:
791        case OP_DNCREF:
792        count = GET2(cc, 1 + IMM2_SIZE);
793        slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
794        while (count-- > 0)
795          {
796          common->optimized_cbracket[GET2(slot, 0)] = 0;
797          slot += common->name_entry_size;
798          }
799        cc += 1 + 2 * IMM2_SIZE;
800        break;
801    
802      case OP_RECURSE:      case OP_RECURSE:
803      /* Set its value only once. */      /* Set its value only once. */
804      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
805        {        {
806        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
807        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
808        }        }
809      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
810      break;      break;
811    
812        case OP_CALLOUT:
813        if (common->capture_last_ptr == 0)
814          {
815          common->capture_last_ptr = common->ovector_start;
816          common->ovector_start += sizeof(sljit_sw);
817          }
818        cc += 2 + 2 * LINK_SIZE;
819        break;
820    
821        case OP_THEN_ARG:
822        common->has_then = TRUE;
823        common->control_head_ptr = 1;
824        /* Fall through. */
825    
826        case OP_PRUNE_ARG:
827        common->needs_start_ptr = TRUE;
828        /* Fall through. */
829    
830      case OP_MARK:      case OP_MARK:
831      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
832        {        {
833        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
834        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
835        }        }
836      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
837      break;      break;
838    
839        case OP_THEN:
840        common->has_then = TRUE;
841        common->control_head_ptr = 1;
842        /* Fall through. */
843    
844        case OP_PRUNE:
845        case OP_SKIP:
846        common->needs_start_ptr = TRUE;
847        cc += 1;
848        break;
849    
850        case OP_SKIP_ARG:
851        common->control_head_ptr = 1;
852        common->has_skip_arg = TRUE;
853        cc += 1 + 2 + cc[1];
854        break;
855    
856      default:      default:
857      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
858      if (cc == NULL)      if (cc == NULL)
859        return -1;        return FALSE;
860      break;      break;
861      }      }
862    }    }
863  return localspace;  return TRUE;
864  }  }
865    
866  static void set_localptrs(compiler_common *common, int localptr, pcre_uchar *ccend)  static int get_class_iterator_size(pcre_uchar *cc)
867  {  {
868  pcre_uchar *cc = common->start;  switch(*cc)
 pcre_uchar *alternative;  
 while (cc < ccend)  
869    {    {
870    switch(*cc)    case OP_CRSTAR:
871      {    case OP_CRPLUS:
872      case OP_ASSERT:    return 2;
     case OP_ASSERT_NOT:  
     case OP_ASSERTBACK:  
     case OP_ASSERTBACK_NOT:  
     case OP_ONCE:  
     case OP_ONCE_NC:  
     case OP_BRAPOS:  
     case OP_SBRA:  
     case OP_SBRAPOS:  
     case OP_SCOND:  
     common->localptrs[cc - common->start] = localptr;  
     localptr += sizeof(sljit_w);  
     cc += 1 + LINK_SIZE;  
     break;  
873    
874      case OP_CBRAPOS:    case OP_CRMINSTAR:
875      case OP_SCBRAPOS:    case OP_CRMINPLUS:
876      common->localptrs[cc - common->start] = localptr;    case OP_CRQUERY:
877      localptr += sizeof(sljit_w);    case OP_CRMINQUERY:
878      cc += 1 + LINK_SIZE + IMM2_SIZE;    return 1;
     break;  
879    
880      case OP_COND:    case OP_CRRANGE:
881      /* Might be a hidden SCOND. */    case OP_CRMINRANGE:
882      alternative = cc + GET(cc, 1);    if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
883      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      return 0;
884        {    return 2;
       common->localptrs[cc - common->start] = localptr;  
       localptr += sizeof(sljit_w);  
       }  
     cc += 1 + LINK_SIZE;  
     break;  
885    
886      default:    default:
887      cc = next_opcode(common, cc);    return 0;
     SLJIT_ASSERT(cc != NULL);  
     break;  
     }  
888    }    }
889  }  }
890    
891  /* Returns with -1 if no need for frame. */  static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
 static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  
892  {  {
893  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *end = bracketend(begin);
894  int length = 0;  pcre_uchar *next;
895  BOOL possessive = FALSE;  pcre_uchar *next_end;
896  BOOL setsom_found = recursive;  pcre_uchar *max_end;
897  BOOL setmark_found = recursive;  pcre_uchar type;
898    sljit_sw length = end - begin;
899    int min, max, i;
900    
901  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  /* Detect fixed iterations first. */
902    {  if (end[-(1 + LINK_SIZE)] != OP_KET)
903    length = 3;    return FALSE;
904    possessive = TRUE;  
905    /* Already detected repeat. */
906    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
907      return TRUE;
908    
909    next = end;
910    min = 1;
911    while (1)
912      {
913      if (*next != *begin)
914        break;
915      next_end = bracketend(next);
916      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
917        break;
918      next = next_end;
919      min++;
920      }
921    
922    if (min == 2)
923      return FALSE;
924    
925    max = 0;
926    max_end = next;
927    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
928      {
929      type = *next;
930      while (1)
931        {
932        if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
933          break;
934        next_end = bracketend(next + 2 + LINK_SIZE);
935        if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
936          break;
937        next = next_end;
938        max++;
939        }
940    
941      if (next[0] == type && next[1] == *begin && max >= 1)
942        {
943        next_end = bracketend(next + 1);
944        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
945          {
946          for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
947            if (*next_end != OP_KET)
948              break;
949    
950          if (i == max)
951            {
952            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
953            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
954            /* +2 the original and the last. */
955            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
956            if (min == 1)
957              return TRUE;
958            min--;
959            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
960            }
961          }
962        }
963      }
964    
965    if (min >= 3)
966      {
967      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
968      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
969      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
970      return TRUE;
971      }
972    
973    return FALSE;
974    }
975    
976    #define CASE_ITERATOR_PRIVATE_DATA_1 \
977        case OP_MINSTAR: \
978        case OP_MINPLUS: \
979        case OP_QUERY: \
980        case OP_MINQUERY: \
981        case OP_MINSTARI: \
982        case OP_MINPLUSI: \
983        case OP_QUERYI: \
984        case OP_MINQUERYI: \
985        case OP_NOTMINSTAR: \
986        case OP_NOTMINPLUS: \
987        case OP_NOTQUERY: \
988        case OP_NOTMINQUERY: \
989        case OP_NOTMINSTARI: \
990        case OP_NOTMINPLUSI: \
991        case OP_NOTQUERYI: \
992        case OP_NOTMINQUERYI:
993    
994    #define CASE_ITERATOR_PRIVATE_DATA_2A \
995        case OP_STAR: \
996        case OP_PLUS: \
997        case OP_STARI: \
998        case OP_PLUSI: \
999        case OP_NOTSTAR: \
1000        case OP_NOTPLUS: \
1001        case OP_NOTSTARI: \
1002        case OP_NOTPLUSI:
1003    
1004    #define CASE_ITERATOR_PRIVATE_DATA_2B \
1005        case OP_UPTO: \
1006        case OP_MINUPTO: \
1007        case OP_UPTOI: \
1008        case OP_MINUPTOI: \
1009        case OP_NOTUPTO: \
1010        case OP_NOTMINUPTO: \
1011        case OP_NOTUPTOI: \
1012        case OP_NOTMINUPTOI:
1013    
1014    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1015        case OP_TYPEMINSTAR: \
1016        case OP_TYPEMINPLUS: \
1017        case OP_TYPEQUERY: \
1018        case OP_TYPEMINQUERY:
1019    
1020    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1021        case OP_TYPESTAR: \
1022        case OP_TYPEPLUS:
1023    
1024    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1025        case OP_TYPEUPTO: \
1026        case OP_TYPEMINUPTO:
1027    
1028    static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1029    {
1030    pcre_uchar *cc = common->start;
1031    pcre_uchar *alternative;
1032    pcre_uchar *end = NULL;
1033    int private_data_ptr = *private_data_start;
1034    int space, size, bracketlen;
1035    
1036    while (cc < ccend)
1037      {
1038      space = 0;
1039      size = 0;
1040      bracketlen = 0;
1041      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1042        return;
1043    
1044      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1045        if (detect_repeat(common, cc))
1046          {
1047          /* These brackets are converted to repeats, so no global
1048          based single character repeat is allowed. */
1049          if (cc >= end)
1050            end = bracketend(cc);
1051          }
1052    
1053      switch(*cc)
1054        {
1055        case OP_KET:
1056        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1057          {
1058          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1059          private_data_ptr += sizeof(sljit_sw);
1060          cc += common->private_data_ptrs[cc + 1 - common->start];
1061          }
1062        cc += 1 + LINK_SIZE;
1063        break;
1064    
1065        case OP_ASSERT:
1066        case OP_ASSERT_NOT:
1067        case OP_ASSERTBACK:
1068        case OP_ASSERTBACK_NOT:
1069        case OP_ONCE:
1070        case OP_ONCE_NC:
1071        case OP_BRAPOS:
1072        case OP_SBRA:
1073        case OP_SBRAPOS:
1074        case OP_SCOND:
1075        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1076        private_data_ptr += sizeof(sljit_sw);
1077        bracketlen = 1 + LINK_SIZE;
1078        break;
1079    
1080        case OP_CBRAPOS:
1081        case OP_SCBRAPOS:
1082        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1083        private_data_ptr += sizeof(sljit_sw);
1084        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1085        break;
1086    
1087        case OP_COND:
1088        /* Might be a hidden SCOND. */
1089        alternative = cc + GET(cc, 1);
1090        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1091          {
1092          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1093          private_data_ptr += sizeof(sljit_sw);
1094          }
1095        bracketlen = 1 + LINK_SIZE;
1096        break;
1097    
1098        case OP_BRA:
1099        bracketlen = 1 + LINK_SIZE;
1100        break;
1101    
1102        case OP_CBRA:
1103        case OP_SCBRA:
1104        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1105        break;
1106    
1107        CASE_ITERATOR_PRIVATE_DATA_1
1108        space = 1;
1109        size = -2;
1110        break;
1111    
1112        CASE_ITERATOR_PRIVATE_DATA_2A
1113        space = 2;
1114        size = -2;
1115        break;
1116    
1117        CASE_ITERATOR_PRIVATE_DATA_2B
1118        space = 2;
1119        size = -(2 + IMM2_SIZE);
1120        break;
1121    
1122        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1123        space = 1;
1124        size = 1;
1125        break;
1126    
1127        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1128        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1129          space = 2;
1130        size = 1;
1131        break;
1132    
1133        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1134        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1135          space = 2;
1136        size = 1 + IMM2_SIZE;
1137        break;
1138    
1139        case OP_CLASS:
1140        case OP_NCLASS:
1141        size += 1 + 32 / sizeof(pcre_uchar);
1142        space = get_class_iterator_size(cc + size);
1143        break;
1144    
1145    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1146        case OP_XCLASS:
1147        size = GET(cc, 1);
1148        space = get_class_iterator_size(cc + size);
1149        break;
1150    #endif
1151    
1152        default:
1153        cc = next_opcode(common, cc);
1154        SLJIT_ASSERT(cc != NULL);
1155        break;
1156        }
1157    
1158      /* Character iterators, which are not inside a repeated bracket,
1159         gets a private slot instead of allocating it on the stack. */
1160      if (space > 0 && cc >= end)
1161        {
1162        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1163        private_data_ptr += sizeof(sljit_sw) * space;
1164        }
1165    
1166      if (size != 0)
1167        {
1168        if (size < 0)
1169          {
1170          cc += -size;
1171    #ifdef SUPPORT_UTF
1172          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1173    #endif
1174          }
1175        else
1176          cc += size;
1177        }
1178    
1179      if (bracketlen > 0)
1180        {
1181        if (cc >= end)
1182          {
1183          end = bracketend(cc);
1184          if (end[-1 - LINK_SIZE] == OP_KET)
1185            end = NULL;
1186          }
1187        cc += bracketlen;
1188        }
1189      }
1190    *private_data_start = private_data_ptr;
1191    }
1192    
1193    /* Returns with a frame_types (always < 0) if no need for frame. */
1194    static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL* needs_control_head)
1195    {
1196    int length = 0;
1197    int possessive = 0;
1198    BOOL stack_restore = FALSE;
1199    BOOL setsom_found = recursive;
1200    BOOL setmark_found = recursive;
1201    /* The last capture is a local variable even for recursions. */
1202    BOOL capture_last_found = FALSE;
1203    
1204    #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1205    SLJIT_ASSERT(common->control_head_ptr != 0);
1206    *needs_control_head = TRUE;
1207    #else
1208    *needs_control_head = FALSE;
1209    #endif
1210    
1211    if (ccend == NULL)
1212      {
1213      ccend = bracketend(cc) - (1 + LINK_SIZE);
1214      if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1215        {
1216        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1217        /* This is correct regardless of common->capture_last_ptr. */
1218        capture_last_found = TRUE;
1219        }
1220      cc = next_opcode(common, cc);
1221    }    }
1222    
 cc = next_opcode(common, cc);  
1223  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1224  while (cc < ccend)  while (cc < ccend)
1225    switch(*cc)    switch(*cc)
1226      {      {
1227      case OP_SET_SOM:      case OP_SET_SOM:
1228      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1229        stack_restore = TRUE;
1230      if (!setsom_found)      if (!setsom_found)
1231        {        {
1232        length += 2;        length += 2;
# Line 817  while (cc < ccend) Line 1236  while (cc < ccend)
1236      break;      break;
1237    
1238      case OP_MARK:      case OP_MARK:
1239        case OP_PRUNE_ARG:
1240        case OP_THEN_ARG:
1241      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1242        stack_restore = TRUE;
1243      if (!setmark_found)      if (!setmark_found)
1244        {        {
1245        length += 2;        length += 2;
1246        setmark_found = TRUE;        setmark_found = TRUE;
1247        }        }
1248        if (common->control_head_ptr != 0)
1249          *needs_control_head = TRUE;
1250      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1251      break;      break;
1252    
1253      case OP_RECURSE:      case OP_RECURSE:
1254        stack_restore = TRUE;
1255      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1256        {        {
1257        length += 2;        length += 2;
# Line 837  while (cc < ccend) Line 1262  while (cc < ccend)
1262        length += 2;        length += 2;
1263        setmark_found = TRUE;        setmark_found = TRUE;
1264        }        }
1265        if (common->capture_last_ptr != 0 && !capture_last_found)
1266          {
1267          length += 2;
1268          capture_last_found = TRUE;
1269          }
1270      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1271      break;      break;
1272    
# Line 844  while (cc < ccend) Line 1274  while (cc < ccend)
1274      case OP_CBRAPOS:      case OP_CBRAPOS:
1275      case OP_SCBRA:      case OP_SCBRA:
1276      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1277        stack_restore = TRUE;
1278        if (common->capture_last_ptr != 0 && !capture_last_found)
1279          {
1280          length += 2;
1281          capture_last_found = TRUE;
1282          }
1283      length += 3;      length += 3;
1284      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1285      break;      break;
1286    
1287      default:      default:
1288        stack_restore = TRUE;
1289        /* Fall through. */
1290    
1291        case OP_NOT_WORD_BOUNDARY:
1292        case OP_WORD_BOUNDARY:
1293        case OP_NOT_DIGIT:
1294        case OP_DIGIT:
1295        case OP_NOT_WHITESPACE:
1296        case OP_WHITESPACE:
1297        case OP_NOT_WORDCHAR:
1298        case OP_WORDCHAR:
1299        case OP_ANY:
1300        case OP_ALLANY:
1301        case OP_ANYBYTE:
1302        case OP_NOTPROP:
1303        case OP_PROP:
1304        case OP_ANYNL:
1305        case OP_NOT_HSPACE:
1306        case OP_HSPACE:
1307        case OP_NOT_VSPACE:
1308        case OP_VSPACE:
1309        case OP_EXTUNI:
1310        case OP_EODN:
1311        case OP_EOD:
1312        case OP_CIRC:
1313        case OP_CIRCM:
1314        case OP_DOLL:
1315        case OP_DOLLM:
1316        case OP_CHAR:
1317        case OP_CHARI:
1318        case OP_NOT:
1319        case OP_NOTI:
1320    
1321        case OP_EXACT:
1322        case OP_POSSTAR:
1323        case OP_POSPLUS:
1324        case OP_POSQUERY:
1325        case OP_POSUPTO:
1326    
1327        case OP_EXACTI:
1328        case OP_POSSTARI:
1329        case OP_POSPLUSI:
1330        case OP_POSQUERYI:
1331        case OP_POSUPTOI:
1332    
1333        case OP_NOTEXACT:
1334        case OP_NOTPOSSTAR:
1335        case OP_NOTPOSPLUS:
1336        case OP_NOTPOSQUERY:
1337        case OP_NOTPOSUPTO:
1338    
1339        case OP_NOTEXACTI:
1340        case OP_NOTPOSSTARI:
1341        case OP_NOTPOSPLUSI:
1342        case OP_NOTPOSQUERYI:
1343        case OP_NOTPOSUPTOI:
1344    
1345        case OP_TYPEEXACT:
1346        case OP_TYPEPOSSTAR:
1347        case OP_TYPEPOSPLUS:
1348        case OP_TYPEPOSQUERY:
1349        case OP_TYPEPOSUPTO:
1350    
1351        case OP_CLASS:
1352        case OP_NCLASS:
1353        case OP_XCLASS:
1354    
1355      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1356      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1357      break;      break;
1358      }      }
1359    
1360  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1361  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1362    return -1;    return stack_restore ? no_frame : no_stack;
1363    
1364  if (length > 0)  if (length > 0)
1365    return length + 1;    return length + 1;
1366  return -1;  return stack_restore ? no_frame : no_stack;
1367  }  }
1368    
1369  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)
1370  {  {
1371  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1372  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1373  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1374    /* The last capture is a local variable even for recursions. */
1375    BOOL capture_last_found = FALSE;
1376  int offset;  int offset;
1377    
1378  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 876  SLJIT_UNUSED_ARG(stacktop); Line 1380  SLJIT_UNUSED_ARG(stacktop);
1380  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1381    
1382  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1383  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1384    cc = next_opcode(common, cc);    {
1385      ccend = bracketend(cc) - (1 + LINK_SIZE);
1386      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1387        cc = next_opcode(common, cc);
1388      }
1389    
1390  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1391  while (cc < ccend)  while (cc < ccend)
1392    switch(*cc)    switch(*cc)
# Line 887  while (cc < ccend) Line 1396  while (cc < ccend)
1396      if (!setsom_found)      if (!setsom_found)
1397        {        {
1398        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1399        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1400        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1401        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1402        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1403        setsom_found = TRUE;        setsom_found = TRUE;
1404        }        }
1405      cc += 1;      cc += 1;
1406      break;      break;
1407    
1408      case OP_MARK:      case OP_MARK:
1409        case OP_PRUNE_ARG:
1410        case OP_THEN_ARG:
1411      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1412      if (!setmark_found)      if (!setmark_found)
1413        {        {
1414        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1415        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);
1416        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1417        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1418        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1419        setmark_found = TRUE;        setmark_found = TRUE;
1420        }        }
1421      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 914  while (cc < ccend) Line 1425  while (cc < ccend)
1425      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1426        {        {
1427        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1428        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1429        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1430        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1431        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1432        setsom_found = TRUE;        setsom_found = TRUE;
1433        }        }
1434      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1435        {        {
1436        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1437        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);
1438        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1439        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1440        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1441        setmark_found = TRUE;        setmark_found = TRUE;
1442        }        }
1443        if (common->capture_last_ptr != 0 && !capture_last_found)
1444          {
1445          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1446          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1447          stackpos += (int)sizeof(sljit_sw);
1448          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1449          stackpos += (int)sizeof(sljit_sw);
1450          capture_last_found = TRUE;
1451          }
1452      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1453      break;      break;
1454    
# Line 936  while (cc < ccend) Line 1456  while (cc < ccend)
1456      case OP_CBRAPOS:      case OP_CBRAPOS:
1457      case OP_SCBRA:      case OP_SCBRA:
1458      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1459        if (common->capture_last_ptr != 0 && !capture_last_found)
1460          {
1461          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1462          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1463          stackpos += (int)sizeof(sljit_sw);
1464          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1465          stackpos += (int)sizeof(sljit_sw);
1466          capture_last_found = TRUE;
1467          }
1468      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1469      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1470      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1471      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1472      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
1473      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1474      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1475      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1476      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1477    
1478      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1479      break;      break;
# Line 955  while (cc < ccend) Line 1484  while (cc < ccend)
1484      break;      break;
1485      }      }
1486    
1487  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1488  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1489  }  }
1490    
1491  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)
1492  {  {
1493  int localsize = 2;  int private_data_length = needs_control_head ? 3 : 2;
1494    int size;
1495  pcre_uchar *alternative;  pcre_uchar *alternative;
1496  /* Calculate the sum of the local variables. */  /* Calculate the sum of the private machine words. */
1497  while (cc < ccend)  while (cc < ccend)
1498    {    {
1499      size = 0;
1500    switch(*cc)    switch(*cc)
1501      {      {
1502        case OP_KET:
1503        if (PRIVATE_DATA(cc) != 0)
1504          private_data_length++;
1505        cc += 1 + LINK_SIZE;
1506        break;
1507    
1508      case OP_ASSERT:      case OP_ASSERT:
1509      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1510      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 978  while (cc < ccend) Line 1515  while (cc < ccend)
1515      case OP_SBRA:      case OP_SBRA:
1516      case OP_SBRAPOS:      case OP_SBRAPOS:
1517      case OP_SCOND:      case OP_SCOND:
1518      localsize++;      private_data_length++;
1519      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1520      break;      break;
1521    
1522      case OP_CBRA:      case OP_CBRA:
1523      case OP_SCBRA:      case OP_SCBRA:
1524      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1525          private_data_length++;
1526      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1527      break;      break;
1528    
1529      case OP_CBRAPOS:      case OP_CBRAPOS:
1530      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1531      localsize += 2;      private_data_length += 2;
1532      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1533      break;      break;
1534    
# Line 998  while (cc < ccend) Line 1536  while (cc < ccend)
1536      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1537      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1538      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1539        localsize++;        private_data_length++;
1540      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1541      break;      break;
1542    
1543        CASE_ITERATOR_PRIVATE_DATA_1
1544        if (PRIVATE_DATA(cc))
1545          private_data_length++;
1546        cc += 2;
1547    #ifdef SUPPORT_UTF
1548        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1549    #endif
1550        break;
1551    
1552        CASE_ITERATOR_PRIVATE_DATA_2A
1553        if (PRIVATE_DATA(cc))
1554          private_data_length += 2;
1555        cc += 2;
1556    #ifdef SUPPORT_UTF
1557        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1558    #endif
1559        break;
1560    
1561        CASE_ITERATOR_PRIVATE_DATA_2B
1562        if (PRIVATE_DATA(cc))
1563          private_data_length += 2;
1564        cc += 2 + IMM2_SIZE;
1565    #ifdef SUPPORT_UTF
1566        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1567    #endif
1568        break;
1569    
1570        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1571        if (PRIVATE_DATA(cc))
1572          private_data_length++;
1573        cc += 1;
1574        break;
1575    
1576        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1577        if (PRIVATE_DATA(cc))
1578          private_data_length += 2;
1579        cc += 1;
1580        break;
1581    
1582        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1583        if (PRIVATE_DATA(cc))
1584          private_data_length += 2;
1585        cc += 1 + IMM2_SIZE;
1586        break;
1587    
1588        case OP_CLASS:
1589        case OP_NCLASS:
1590    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1591        case OP_XCLASS:
1592        size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1593    #else
1594        size = 1 + 32 / (int)sizeof(pcre_uchar);
1595    #endif
1596        if (PRIVATE_DATA(cc))
1597          private_data_length += get_class_iterator_size(cc + size);
1598        cc += size;
1599        break;
1600    
1601      default:      default:
1602      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1603      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
# Line 1009  while (cc < ccend) Line 1605  while (cc < ccend)
1605      }      }
1606    }    }
1607  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1608  return localsize;  return private_data_length;
1609  }  }
1610    
1611  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,
1612    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1613  {  {
1614  DEFINE_COMPILER;  DEFINE_COMPILER;
1615  int srcw[2];  int srcw[2];
1616  int count;  int count, size;
1617  BOOL tmp1next = TRUE;  BOOL tmp1next = TRUE;
1618  BOOL tmp1empty = TRUE;  BOOL tmp1empty = TRUE;
1619  BOOL tmp2empty = TRUE;  BOOL tmp2empty = TRUE;
# Line 1034  stacktop = STACK(stacktop - 1); Line 1630  stacktop = STACK(stacktop - 1);
1630    
1631  if (!save)  if (!save)
1632    {    {
1633    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1634    if (stackptr < stacktop)    if (stackptr < stacktop)
1635      {      {
1636      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1637      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1638      tmp1empty = FALSE;      tmp1empty = FALSE;
1639      }      }
1640    if (stackptr < stacktop)    if (stackptr < stacktop)
1641      {      {
1642      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1643      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1644      tmp2empty = FALSE;      tmp2empty = FALSE;
1645      }      }
1646    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1647    }    }
1648    
1649  while (status != end)  do
1650    {    {
1651    count = 0;    count = 0;
1652    switch(status)    switch(status)
1653      {      {
1654      case start:      case start:
1655      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1656      count = 1;      count = 1;
1657      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1658        if (needs_control_head)
1659          {
1660          SLJIT_ASSERT(common->control_head_ptr != 0);
1661          count = 2;
1662          srcw[1] = common->control_head_ptr;
1663          }
1664      status = loop;      status = loop;
1665      break;      break;
1666    
# Line 1071  while (status != end) Line 1673  while (status != end)
1673    
1674      switch(*cc)      switch(*cc)
1675        {        {
1676          case OP_KET:
1677          if (PRIVATE_DATA(cc) != 0)
1678            {
1679            count = 1;
1680            srcw[0] = PRIVATE_DATA(cc);
1681            }
1682          cc += 1 + LINK_SIZE;
1683          break;
1684    
1685        case OP_ASSERT:        case OP_ASSERT:
1686        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1687        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1082  while (status != end) Line 1693  while (status != end)
1693        case OP_SBRAPOS:        case OP_SBRAPOS:
1694        case OP_SCOND:        case OP_SCOND:
1695        count = 1;        count = 1;
1696        srcw[0] = PRIV_DATA(cc);        srcw[0] = PRIVATE_DATA(cc);
1697        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1698        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1699        break;        break;
1700    
1701        case OP_CBRA:        case OP_CBRA:
1702        case OP_SCBRA:        case OP_SCBRA:
1703        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1704        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1705            count = 1;
1706            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1707            }
1708        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1709        break;        break;
1710    
1711        case OP_CBRAPOS:        case OP_CBRAPOS:
1712        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1713        count = 2;        count = 2;
1714          srcw[0] = PRIVATE_DATA(cc);
1715        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1716        srcw[0] = PRIV_DATA(cc);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
       SLJIT_ASSERT(srcw[0] != 0);  
1717        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1718        break;        break;
1719    
# Line 1109  while (status != end) Line 1723  while (status != end)
1723        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1724          {          {
1725          count = 1;          count = 1;
1726          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1727          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1728          }          }
1729        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1730        break;        break;
1731    
1732          CASE_ITERATOR_PRIVATE_DATA_1
1733          if (PRIVATE_DATA(cc))
1734            {
1735            count = 1;
1736            srcw[0] = PRIVATE_DATA(cc);
1737            }
1738          cc += 2;
1739    #ifdef SUPPORT_UTF
1740          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1741    #endif
1742          break;
1743    
1744          CASE_ITERATOR_PRIVATE_DATA_2A
1745          if (PRIVATE_DATA(cc))
1746            {
1747            count = 2;
1748            srcw[0] = PRIVATE_DATA(cc);
1749            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1750            }
1751          cc += 2;
1752    #ifdef SUPPORT_UTF
1753          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1754    #endif
1755          break;
1756    
1757          CASE_ITERATOR_PRIVATE_DATA_2B
1758          if (PRIVATE_DATA(cc))
1759            {
1760            count = 2;
1761            srcw[0] = PRIVATE_DATA(cc);
1762            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1763            }
1764          cc += 2 + IMM2_SIZE;
1765    #ifdef SUPPORT_UTF
1766          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1767    #endif
1768          break;
1769    
1770          CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1771          if (PRIVATE_DATA(cc))
1772            {
1773            count = 1;
1774            srcw[0] = PRIVATE_DATA(cc);
1775            }
1776          cc += 1;
1777          break;
1778    
1779          CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1780          if (PRIVATE_DATA(cc))
1781            {
1782            count = 2;
1783            srcw[0] = PRIVATE_DATA(cc);
1784            srcw[1] = srcw[0] + sizeof(sljit_sw);
1785            }
1786          cc += 1;
1787          break;
1788    
1789          CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1790          if (PRIVATE_DATA(cc))
1791            {
1792            count = 2;
1793            srcw[0] = PRIVATE_DATA(cc);
1794            srcw[1] = srcw[0] + sizeof(sljit_sw);
1795            }
1796          cc += 1 + IMM2_SIZE;
1797          break;
1798    
1799          case OP_CLASS:
1800          case OP_NCLASS:
1801    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1802          case OP_XCLASS:
1803          size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1804    #else
1805          size = 1 + 32 / (int)sizeof(pcre_uchar);
1806    #endif
1807          if (PRIVATE_DATA(cc))
1808            switch(get_class_iterator_size(cc + size))
1809              {
1810              case 1:
1811              count = 1;
1812              srcw[0] = PRIVATE_DATA(cc);
1813              break;
1814    
1815              case 2:
1816              count = 2;
1817              srcw[0] = PRIVATE_DATA(cc);
1818              srcw[1] = srcw[0] + sizeof(sljit_sw);
1819              break;
1820    
1821              default:
1822              SLJIT_ASSERT_STOP();
1823              break;
1824              }
1825          cc += size;
1826          break;
1827    
1828        default:        default:
1829        cc = next_opcode(common, cc);        cc = next_opcode(common, cc);
1830        SLJIT_ASSERT(cc != NULL);        SLJIT_ASSERT(cc != NULL);
# Line 1137  while (status != end) Line 1847  while (status != end)
1847          if (!tmp1empty)          if (!tmp1empty)
1848            {            {
1849            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1850            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1851            }            }
1852          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1853          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1148  while (status != end) Line 1858  while (status != end)
1858          if (!tmp2empty)          if (!tmp2empty)
1859            {            {
1860            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1861            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1862            }            }
1863          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1864          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1165  while (status != end) Line 1875  while (status != end)
1875          if (!tmp1empty)          if (!tmp1empty)
1876            {            {
1877            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1878            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1879            }            }
1880          tmp1next = FALSE;          tmp1next = FALSE;
1881          }          }
# Line 1177  while (status != end) Line 1887  while (status != end)
1887          if (!tmp2empty)          if (!tmp2empty)
1888            {            {
1889            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1890            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1891            }            }
1892          tmp1next = TRUE;          tmp1next = TRUE;
1893          }          }
1894        }        }
1895      }      }
1896    }    }
1897    while (status != end);
1898    
1899  if (save)  if (save)
1900    {    {
# Line 1192  if (save) Line 1903  if (save)
1903      if (!tmp1empty)      if (!tmp1empty)
1904        {        {
1905        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1906        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1907        }        }
1908      if (!tmp2empty)      if (!tmp2empty)
1909        {        {
1910        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1911        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1912        }        }
1913      }      }
1914    else    else
# Line 1205  if (save) Line 1916  if (save)
1916      if (!tmp2empty)      if (!tmp2empty)
1917        {        {
1918        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1919        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1920        }        }
1921      if (!tmp1empty)      if (!tmp1empty)
1922        {        {
1923        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1924        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1925        }        }
1926      }      }
1927    }    }
1928  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1929  }  }
1930    
1931  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)
1932    {
1933    pcre_uchar *end = bracketend(cc);
1934    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1935    
1936    /* Assert captures then. */
1937    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1938      current_offset = NULL;
1939    /* Conditional block does not. */
1940    if (*cc == OP_COND || *cc == OP_SCOND)
1941      has_alternatives = FALSE;
1942    
1943    cc = next_opcode(common, cc);
1944    if (has_alternatives)
1945      current_offset = common->then_offsets + (cc - common->start);
1946    
1947    while (cc < end)
1948      {
1949      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1950        cc = set_then_offsets(common, cc, current_offset);
1951      else
1952        {
1953        if (*cc == OP_ALT && has_alternatives)
1954          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1955        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1956          *current_offset = 1;
1957        cc = next_opcode(common, cc);
1958        }
1959      }
1960    
1961    return end;
1962    }
1963    
1964    #undef CASE_ITERATOR_PRIVATE_DATA_1
1965    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1966    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1967    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1968    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1969    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1970    
1971    static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1972  {  {
1973  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1974  }  }
# Line 1227  static SLJIT_INLINE void set_jumps(jump_ Line 1978  static SLJIT_INLINE void set_jumps(jump_
1978  while (list)  while (list)
1979    {    {
1980    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1981    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1982    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1983    list = list->next;    list = list->next;
1984    }    }
1985  }  }
# Line 1244  if (list_item) Line 1995  if (list_item)
1995    }    }
1996  }  }
1997    
1998  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)
1999  {  {
2000  DEFINE_COMPILER;  DEFINE_COMPILER;
2001  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
2002    
2003  if (list_item)  if (list_item)
2004    {    {
   list_item->type = type;  
   list_item->data = data;  
2005    list_item->start = start;    list_item->start = start;
2006    list_item->leave = LABEL();    list_item->quit = LABEL();
2007    list_item->next = common->stubs;    list_item->next = common->stubs;
2008    common->stubs = list_item;    common->stubs = list_item;
2009    }    }
# Line 1268  stub_list* list_item = common->stubs; Line 2017  stub_list* list_item = common->stubs;
2017  while (list_item)  while (list_item)
2018    {    {
2019    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2020    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
2021      {    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);  
2022    list_item = list_item->next;    list_item = list_item->next;
2023    }    }
2024  common->stubs = NULL;  common->stubs = NULL;
2025  }  }
2026    
2027  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2028  {  {
2029  DEFINE_COMPILER;  DEFINE_COMPILER;
2030    
2031  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);
2032  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2033  }  }
2034    
# Line 1293  static SLJIT_INLINE void allocate_stack( Line 2037  static SLJIT_INLINE void allocate_stack(
2037  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2038  DEFINE_COMPILER;  DEFINE_COMPILER;
2039    
2040  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w));  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
2041  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2042  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2043  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1301  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 2045  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2045  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2046  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2047  #endif  #endif
2048  add_stub(common, stack_alloc, 0, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));  add_stub(common, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));
2049  }  }
2050    
2051  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2052  {  {
2053  DEFINE_COMPILER;  DEFINE_COMPILER;
2054  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w));  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
2055  }  }
2056    
2057  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1315  static SLJIT_INLINE void reset_ovector(c Line 2059  static SLJIT_INLINE void reset_ovector(c
2059  DEFINE_COMPILER;  DEFINE_COMPILER;
2060  struct sljit_label *loop;  struct sljit_label *loop;
2061  int i;  int i;
2062    
2063  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2064    SLJIT_ASSERT(length > 1);
2065  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2066  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
2067  if (length < 8)  if (length < 8)
2068    {    {
2069    for (i = 0; i < length; i++)    for (i = 1; i < length; i++)
2070      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_TEMPORARY_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2071    }    }
2072  else  else
2073    {    {
2074    OP2(SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2075    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2076    loop = LABEL();    loop = LABEL();
2077    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2078    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2079    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2080      }
2081    }
2082    
2083    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2084    {
2085    DEFINE_COMPILER;
2086    struct sljit_label *loop;
2087    int i;
2088    
2089    SLJIT_ASSERT(length > 1);
2090    /* OVECTOR(1) contains the "string begin - 1" constant. */
2091    if (length > 2)
2092      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2093    if (length < 8)
2094      {
2095      for (i = 2; i < length; i++)
2096        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
2097      }
2098    else
2099      {
2100      GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2101      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2102      loop = LABEL();
2103      OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2104      OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
2105      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2106      }
2107    
2108    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2109    if (common->mark_ptr != 0)
2110      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2111    if (common->control_head_ptr != 0)
2112      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2113    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2114    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2115    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2116    }
2117    
2118    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2119    {
2120    while (current != NULL)
2121      {
2122      switch (current[-2])
2123        {
2124        case type_then_trap:
2125        break;
2126    
2127        case type_mark:
2128        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2129          return current[-4];
2130        break;
2131    
2132        default:
2133        SLJIT_ASSERT_STOP();
2134        break;
2135        }
2136      current = (sljit_sw*)current[-1];
2137    }    }
2138    return -1;
2139  }  }
2140    
2141  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2142  {  {
2143  DEFINE_COMPILER;  DEFINE_COMPILER;
2144  struct sljit_label *loop;  struct sljit_label *loop;
2145  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2146    
2147  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2148  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2149  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);
2150    
2151  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2152  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2153    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
2154  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offset_count));
2155  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2156    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_TEMPORARY_REG3, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);
2157  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
2158  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));
2159  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2160  /* Unlikely, but possible */  /* Unlikely, but possible */
2161  earlyexit = CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0);  early_quit = CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);
2162  loop = LABEL();  loop = LABEL();
2163  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
2164  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_w));  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));
2165  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2166  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2167  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2168  #endif  #endif
2169  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);
2170  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
2171  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2172  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2173    
2174  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2175  if (topbracket > 1)  if (topbracket > 1)
2176    {    {
2177    OP2(SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START + topbracket * 2 * sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));
2178    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2179    
2180    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2181    loop = LABEL();    loop = LABEL();
2182    OP1(SLJIT_MOVU, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), -(2 * (sljit_w)sizeof(sljit_w)));    OP1(SLJIT_MOVU, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), -(2 * (sljit_sw)sizeof(sljit_sw)));
2183    OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
2184    CMPTO(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG3, 0, loop);    CMPTO(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG3, 0, loop);
2185    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2186    }    }
2187  else  else
2188    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
2189  }  }
2190    
2191  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)
2192  {  {
2193  DEFINE_COMPILER;  DEFINE_COMPILER;
2194    struct sljit_jump *jump;
2195    
2196  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);
2197  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
2198      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2199    
2200  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2201  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2202  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, offsetcount));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, real_offset_count));
2203  CMPTO(SLJIT_C_LESS, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2, leave);  CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
2204    
2205  /* Store match begin and end. */  /* Store match begin and end. */
2206  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));
2207  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));
2208  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);  
2209    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2210    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + (int)sizeof(sljit_sw)), SLJIT_SAVED_REG1, 0);
2211    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2212    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2213    #endif
2214    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2215    JUMPHERE(jump);
2216    
2217    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);
2218  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);
2219  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2220  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2221  #endif  #endif
2222  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);
2223    
2224  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG1, 0);
2225  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2226  OP2(SLJIT_ASHR, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);  OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2227  #endif  #endif
2228  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), 0, SLJIT_TEMPORARY_REG3, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0, SLJIT_SCRATCH_REG3, 0);
2229    
2230  JUMPTO(SLJIT_JUMP, leave);  JUMPTO(SLJIT_JUMP, quit);
2231  }  }
2232    
2233  static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)  static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)
# Line 1523  if (c <= 127 && bit == 0x20) Line 2338  if (c <= 127 && bit == 0x20)
2338    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2339    
2340  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2341  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2342    return 0;    return 0;
2343    
2344  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2345    
2346  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2347  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 1542  if (common->utf && c > 127) Line 2357  if (common->utf && c > 127)
2357  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2358  return (0 << 8) | bit;  return (0 << 8) | bit;
2359    
2360  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2361    
 #ifdef COMPILE_PCRE16  
2362  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2363  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2364    {    {
# Line 1555  if (common->utf && c > 65535) Line 2369  if (common->utf && c > 65535)
2369    }    }
2370  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2371  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2372    
2373  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2374  }  }
2375    
2376  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2377  {  {
2378  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2379  DEFINE_COMPILER;  DEFINE_COMPILER;
2380  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2381    
# Line 1577  else if (common->mode == JIT_PARTIAL_SOF Line 2390  else if (common->mode == JIT_PARTIAL_SOF
2390    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2391    
2392  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2393    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2394  else  else
2395    {    {
2396    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 1590  if (jump != NULL) Line 2403  if (jump != NULL)
2403    JUMPHERE(jump);    JUMPHERE(jump);
2404  }  }
2405    
2406  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2407  {  {
2408  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2409  DEFINE_COMPILER;  DEFINE_COMPILER;
2410  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2411    
2412  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2413    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2414      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2415      return;
2416      }
2417    
2418  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2419  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2420    {    {
2421    nohit = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2422    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2423    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2424    }    }
2425  else  else
2426    {    {
2427    return_value = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2428    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2429      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2430    else    else
2431      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2432    }    }
2433  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2434  }  }
2435    
2436  static void fallback_at_str_end(compiler_common *common, jump_list **fallbacks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
2437  {  {
2438  DEFINE_COMPILER;  DEFINE_COMPILER;
2439  struct sljit_jump *jump;  struct sljit_jump *jump;
2440    
2441  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2442    {    {
2443    add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2444    return;    return;
2445    }    }
2446    
2447  /* Partial matching mode. */  /* Partial matching mode. */
2448  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2449  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_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2450  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2451    {    {
2452    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2453    add_jump(compiler, fallbacks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2454    }    }
2455  else  else
2456    {    {
# Line 1655  static void read_char(compiler_common *c Line 2467  static void read_char(compiler_common *c
2467  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2468  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2469  DEFINE_COMPILER;  DEFINE_COMPILER;
2470  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2471  struct sljit_jump *jump;  struct sljit_jump *jump;
2472  #endif  #endif
2473    
2474  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2475  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2476  if (common->utf)  if (common->utf)
2477    {    {
2478  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2479    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2480  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2481    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2482  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2483    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2484    JUMPHERE(jump);    JUMPHERE(jump);
2485    }    }
2486  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2487  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));
2488  }  }
2489    
# Line 1682  static void peek_char(compiler_common *c Line 2492  static void peek_char(compiler_common *c
2492  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2493  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2494  DEFINE_COMPILER;  DEFINE_COMPILER;
2495  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2496  struct sljit_jump *jump;  struct sljit_jump *jump;
2497  #endif  #endif
2498    
2499  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2500  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2501  if (common->utf)  if (common->utf)
2502    {    {
2503  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2504    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2505  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2506    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2507  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2508    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2509    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2510    JUMPHERE(jump);    JUMPHERE(jump);
2511    }    }
2512  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2513  }  }
2514    
2515  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2516  {  {
2517  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */
2518  DEFINE_COMPILER;  DEFINE_COMPILER;
2519  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2520  struct sljit_jump *jump;  struct sljit_jump *jump;
2521  #endif  #endif
2522    
# Line 1717  if (common->utf) Line 2525  if (common->utf)
2525    {    {
2526    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2527    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));
2528  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2529    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2530    it is needed in most cases. */    it is needed in most cases. */
2531    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2532    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2533    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2534    JUMPHERE(jump);    JUMPHERE(jump);
2535  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2536    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2537    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2538    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
# Line 1733  if (common->utf) Line 2540  if (common->utf)
2540    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2541    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2542    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2543    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2544    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2545    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2546  #endif  #elif defined COMPILE_PCRE32
2547  #endif /* COMPILE_PCRE8 */    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2548      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2549      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2550      JUMPHERE(jump);
2551    #endif /* COMPILE_PCRE[8|16|32] */
2552    return;    return;
2553    }    }
2554  #endif  #endif /* SUPPORT_UTF */
2555  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2556  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));
2557  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2558  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2559  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2560  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2561  #endif  #endif
2562  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2563  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2564  JUMPHERE(jump);  JUMPHERE(jump);
2565  #endif  #endif
2566  }  }
# Line 1758  static void skip_char_back(compiler_comm Line 2569  static void skip_char_back(compiler_comm
2569  {  {
2570  /* 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. */
2571  DEFINE_COMPILER;  DEFINE_COMPILER;
2572  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2573    #if defined COMPILE_PCRE8
2574  struct sljit_label *label;  struct sljit_label *label;
2575    
2576  if (common->utf)  if (common->utf)
# Line 1770  if (common->utf) Line 2582  if (common->utf)
2582    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2583    return;    return;
2584    }    }
2585  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2586  if (common->utf)  if (common->utf)
2587    {    {
2588    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 1779  if (common->utf) Line 2590  if (common->utf)
2590    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2591    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2592    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);
2593    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2594    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2595    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2596    return;    return;
2597    }    }
2598  #endif  #endif /* COMPILE_PCRE[8|16] */
2599    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2600  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));
2601  }  }
2602    
2603  static void check_newlinechar(compiler_common *common, int nltype, jump_list **fallbacks, BOOL jumpiftrue)  static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpiftrue)
2604  {  {
2605  /* 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. */
2606  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1796  DEFINE_COMPILER; Line 2608  DEFINE_COMPILER;
2608  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2609    {    {
2610    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2611    add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2612    }    }
2613  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2614    {    {
2615    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);
2616    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2617    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);
2618    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
2619    add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2620    }    }
2621  else  else
2622    {    {
2623    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2624    add_jump(compiler, fallbacks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));    add_jump(compiler, backtracks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
2625    }    }
2626  }  }
2627    
2628  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2629    
2630  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2631  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2632  {  {
2633  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
# Line 1823  of the character (>= 0xc0). Return char Line 2635  of the character (>= 0xc0). Return char
2635  DEFINE_COMPILER;  DEFINE_COMPILER;
2636  struct sljit_jump *jump;  struct sljit_jump *jump;
2637    
2638  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2639  /* Searching for the first zero. */  /* Searching for the first zero. */
2640  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
2641  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
# Line 1882  DEFINE_COMPILER; Line 2694  DEFINE_COMPILER;
2694  struct sljit_jump *jump;  struct sljit_jump *jump;
2695  struct sljit_jump *compare;  struct sljit_jump *compare;
2696    
2697  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2698    
2699  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);
2700  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
# Line 1903  sljit_emit_fast_return(compiler, RETURN_ Line 2715  sljit_emit_fast_return(compiler, RETURN_
2715  JUMPHERE(jump);  JUMPHERE(jump);
2716    
2717  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2718  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(utf8_table4) - 0xc0);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2719  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2720  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2721  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2722  }  }
2723    
2724  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
2725    
 #ifdef COMPILE_PCRE16  
2726  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2727  {  {
2728  /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char  /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char
# Line 1919  of the character (>= 0xd800). Return cha Line 2730  of the character (>= 0xd800). Return cha
2730  DEFINE_COMPILER;  DEFINE_COMPILER;
2731  struct sljit_jump *jump;  struct sljit_jump *jump;
2732    
2733  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2734  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);
2735  /* Do nothing, only return. */  /* Do nothing, only return. */
2736  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
# Line 1936  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC Line 2747  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC
2747  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2748  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2749  }  }
 #endif /* COMPILE_PCRE16 */  
2750    
2751  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16] */
2752    
2753  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2754    
# Line 1956  DEFINE_COMPILER; Line 2766  DEFINE_COMPILER;
2766    
2767  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);
2768    
2769  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2770  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2771  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));
2772  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2773  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2774  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2775  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2776  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2777  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));
2778  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2779  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2780  }  }
# Line 1978  struct sljit_label *newlinelabel = NULL; Line 2788  struct sljit_label *newlinelabel = NULL;
2788  struct sljit_jump *start;  struct sljit_jump *start;
2789  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2790  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2791  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2792  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2793  #endif  #endif
2794  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 1993  if (firstline) Line 2803  if (firstline)
2803    {    {
2804    /* Search for the end of the first line. */    /* Search for the end of the first line. */
2805    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
2806    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);  
2807    
2808    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
2809      {      {
# Line 2005  if (firstline) Line 2814  if (firstline)
2814      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2815      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);
2816      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);
2817        JUMPHERE(end);
2818      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2819      }      }
2820    else    else
# Line 2016  if (firstline) Line 2826  if (firstline)
2826      read_char(common);      read_char(common);
2827      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
2828      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2829        JUMPHERE(end);
2830      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2831      set_jumps(newline, LABEL());      set_jumps(newline, LABEL());
2832      }      }
2833    
2834    JUMPHERE(end);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
2835    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    }
2836    
2837    start = JUMP(SLJIT_JUMP);
2838    
2839    if (newlinecheck)
2840      {
2841      newlinelabel = LABEL();
2842      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2843      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2844      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2845      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);
2846      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2847    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2848      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2849    #endif
2850      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2851      nl = JUMP(SLJIT_JUMP);
2852      }
2853    
2854    mainloop = LABEL();
2855    
2856    /* Increasing the STR_PTR here requires one less jump in the most common case. */
2857    #ifdef SUPPORT_UTF
2858    if (common->utf) readuchar = TRUE;
2859    #endif
2860    if (newlinecheck) readuchar = TRUE;
2861    
2862    if (readuchar)
2863      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2864    
2865    if (newlinecheck)
2866      CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);
2867    
2868    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2869    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2870    #if defined COMPILE_PCRE8
2871    if (common->utf)
2872      {
2873      singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2874      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2875      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2876      JUMPHERE(singlechar);
2877      }
2878    #elif defined COMPILE_PCRE16
2879    if (common->utf)
2880      {
2881      singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2882      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2883      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2884      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2885      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2886      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2887      JUMPHERE(singlechar);
2888      }
2889    #endif /* COMPILE_PCRE[8|16] */
2890    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2891    JUMPHERE(start);
2892    
2893    if (newlinecheck)
2894      {
2895      JUMPHERE(end);
2896      JUMPHERE(nl);
2897      }
2898    
2899    return mainloop;
2900    }
2901    
2902    static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, int max_chars)
2903    {
2904    /* Recursive function, which scans prefix literals. */
2905    int len, repeat, len_save, consumed = 0;
2906    pcre_int32 caseless, chr, mask;
2907    pcre_uchar *alternative, *cc_save;
2908    BOOL last, any;
2909    
2910    repeat = 1;
2911    while (TRUE)
2912      {
2913      last = TRUE;
2914      any = FALSE;
2915      caseless = 0;
2916      switch (*cc)
2917        {
2918        case OP_CHARI:
2919        caseless = 1;
2920        case OP_CHAR:
2921        last = FALSE;
2922        cc++;
2923        break;
2924    
2925        case OP_SOD:
2926        case OP_SOM:
2927        case OP_SET_SOM:
2928        case OP_NOT_WORD_BOUNDARY:
2929        case OP_WORD_BOUNDARY:
2930        case OP_EODN:
2931        case OP_EOD:
2932        case OP_CIRC:
2933        case OP_CIRCM:
2934        case OP_DOLL:
2935        case OP_DOLLM:
2936        /* Zero width assertions. */
2937        cc++;
2938        continue;
2939    
2940        case OP_PLUS:
2941        case OP_MINPLUS:
2942        case OP_POSPLUS:
2943        cc++;
2944        break;
2945    
2946        case OP_EXACTI:
2947        caseless = 1;
2948        case OP_EXACT:
2949        repeat = GET2(cc, 1);
2950        last = FALSE;
2951        cc += 1 + IMM2_SIZE;
2952        break;
2953    
2954        case OP_PLUSI:
2955        case OP_MINPLUSI:
2956        case OP_POSPLUSI:
2957        caseless = 1;
2958        cc++;
2959        break;
2960    
2961        case OP_KET:
2962        cc += 1 + LINK_SIZE;
2963        continue;
2964    
2965        case OP_ALT:
2966        cc += GET(cc, 1);
2967        continue;
2968    
2969        case OP_ONCE:
2970        case OP_ONCE_NC:
2971        case OP_BRA:
2972        case OP_BRAPOS:
2973        case OP_CBRA:
2974        case OP_CBRAPOS:
2975        alternative = cc + GET(cc, 1);
2976        while (*alternative == OP_ALT)
2977          {
2978          max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, max_chars);
2979          if (max_chars == 0)
2980            return consumed;
2981          alternative += GET(alternative, 1);
2982          }
2983    
2984        if (*cc == OP_CBRA || *cc == OP_CBRAPOS)
2985          cc += IMM2_SIZE;
2986        cc += 1 + LINK_SIZE;
2987        continue;
2988    
2989        case OP_CLASS:
2990        case OP_NCLASS:
2991        any = TRUE;
2992        cc += 1 + 32 / sizeof(pcre_uchar);
2993        break;
2994    
2995    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2996        case OP_XCLASS:
2997        any = TRUE;
2998        cc += GET(cc, 1);
2999        break;
3000    #endif
3001    
3002        case OP_NOT_DIGIT:
3003        case OP_DIGIT:
3004        case OP_NOT_WHITESPACE:
3005        case OP_WHITESPACE:
3006        case OP_NOT_WORDCHAR:
3007        case OP_WORDCHAR:
3008        case OP_ANY:
3009        case OP_ALLANY:
3010        any = TRUE;
3011        cc++;
3012        break;
3013    
3014    #ifdef SUPPORT_UCP
3015        case OP_NOTPROP:
3016        case OP_PROP:
3017        any = TRUE;
3018        cc += 1 + 2;
3019        break;
3020    #endif
3021    
3022        case OP_TYPEEXACT:
3023        repeat = GET2(cc, 1);
3024        cc += 1 + IMM2_SIZE;
3025        continue;
3026    
3027        default:
3028        return consumed;
3029        }
3030    
3031      if (any)
3032        {
3033    #ifdef SUPPORT_UTF
3034        if (common->utf) return consumed;
3035    #endif
3036    #if defined COMPILE_PCRE8
3037        mask = 0xff;
3038    #elif defined COMPILE_PCRE16
3039        mask = 0xffff;
3040    #elif defined COMPILE_PCRE32
3041        mask = 0xffffffff;
3042    #else
3043        SLJIT_ASSERT_STOP();
3044    #endif
3045    
3046        do
3047          {
3048          chars[0] = mask;
3049          chars[1] = mask;
3050    
3051          if (--max_chars == 0)
3052            return consumed;
3053          consumed++;
3054          chars += 2;
3055          }
3056        while (--repeat > 0);
3057    
3058        repeat = 1;
3059        continue;
3060        }
3061    
3062      len = 1;
3063    #ifdef SUPPORT_UTF
3064      if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3065    #endif
3066    
3067      if (caseless != 0 && char_has_othercase(common, cc))
3068        {
3069        caseless = char_get_othercase_bit(common, cc);
3070        if (caseless == 0)
3071          return consumed;
3072    #ifdef COMPILE_PCRE8
3073        caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
3074    #else
3075        if ((caseless & 0x100) != 0)
3076          caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));
3077        else
3078          caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));
3079    #endif
3080        }
3081      else
3082        caseless = 0;
3083    
3084      len_save = len;
3085      cc_save = cc;
3086      while (TRUE)
3087        {
3088        do
3089          {
3090          chr = *cc;
3091    #ifdef COMPILE_PCRE32
3092          if (SLJIT_UNLIKELY(chr == NOTACHAR))
3093            return consumed;
3094    #endif
3095          mask = 0;
3096          if (len == (caseless & 0xff))
3097            {
3098            mask = caseless >> 8;
3099            chr |= mask;
3100            }
3101    
3102          if (chars[0] == NOTACHAR)
3103            {
3104            chars[0] = chr;
3105            chars[1] = mask;
3106            }
3107          else
3108            {
3109            mask |= chars[0] ^ chr;
3110            chr |= mask;
3111            chars[0] = chr;
3112            chars[1] |= mask;
3113            }
3114    
3115          len--;
3116          if (--max_chars == 0)
3117            return consumed;
3118          consumed++;
3119          chars += 2;
3120          cc++;
3121          }
3122        while (len > 0);
3123    
3124        if (--repeat == 0)
3125          break;
3126    
3127        len = len_save;
3128        cc = cc_save;
3129        }
3130    
3131      repeat = 1;
3132      if (last)
3133        return consumed;
3134      }
3135    }
3136    
3137    #define MAX_N_CHARS 16
3138    
3139    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3140    {
3141    DEFINE_COMPILER;
3142    struct sljit_label *start;
3143    struct sljit_jump *quit;
3144    pcre_uint32 chars[MAX_N_CHARS * 2];
3145    pcre_uint8 ones[MAX_N_CHARS];
3146    pcre_uint32 mask;
3147    int i, max;
3148    int offsets[3];
3149    
3150    for (i = 0; i < MAX_N_CHARS; i++)
3151      {
3152      chars[i << 1] = NOTACHAR;
3153      chars[(i << 1) + 1] = 0;
3154      }
3155    
3156    max = scan_prefix(common, common->start, chars, MAX_N_CHARS);
3157    
3158    if (max <= 1)
3159      return FALSE;
3160    
3161    for (i = 0; i < max; i++)
3162      {
3163      mask = chars[(i << 1) + 1];
3164      ones[i] = ones_in_half_byte[mask & 0xf];
3165      mask >>= 4;
3166      while (mask != 0)
3167        {
3168        ones[i] += ones_in_half_byte[mask & 0xf];
3169        mask >>= 4;
3170        }
3171      }
3172    
3173    offsets[0] = -1;
3174    /* Scan forward. */
3175    for (i = 0; i < max; i++)
3176      if (ones[i] <= 2) {
3177        offsets[0] = i;
3178        break;
3179    }    }
3180    
3181  start = JUMP(SLJIT_JUMP);  if (offsets[0] == -1)
3182      return FALSE;
3183    
3184  if (newlinecheck)  /* Scan backward. */
3185    {  offsets[1] = -1;
3186    newlinelabel = LABEL();  for (i = max - 1; i > offsets[0]; i--)
3187    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));    if (ones[i] <= 2) {
3188    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      offsets[1] = i;
3189    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      break;
   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);  
   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);  
 #ifdef COMPILE_PCRE16  
   OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  
 #endif  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   nl = JUMP(SLJIT_JUMP);  
3190    }    }
3191    
3192  mainloop = LABEL();  offsets[2] = -1;
3193    if (offsets[1] >= 0)
3194      {
3195      /* Scan from middle. */
3196      for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3197        if (ones[i] <= 2)
3198          {
3199          offsets[2] = i;
3200          break;
3201          }
3202    
3203  /* Increasing the STR_PTR here requires one less jump in the most common case. */    if (offsets[2] == -1)
3204  #ifdef SUPPORT_UTF      {
3205  if (common->utf) readuchar = TRUE;      for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3206  #endif        if (ones[i] <= 2)
3207  if (newlinecheck) readuchar = TRUE;          {
3208            offsets[2] = i;
3209            break;
3210            }
3211        }
3212      }
3213    
3214  if (readuchar)  SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3215    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3216    
3217  if (newlinecheck)  chars[0] = chars[offsets[0] << 1];
3218    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);  chars[1] = chars[(offsets[0] << 1) + 1];
3219    if (offsets[2] >= 0)
3220      {
3221      chars[2] = chars[offsets[2] << 1];
3222      chars[3] = chars[(offsets[2] << 1) + 1];
3223      }
3224    if (offsets[1] >= 0)
3225      {
3226      chars[4] = chars[offsets[1] << 1];
3227      chars[5] = chars[(offsets[1] << 1) + 1];
3228      }
3229    
3230  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  max -= 1;
3231  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  if (firstline)
 if (common->utf)  
3232    {    {
3233    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    SLJIT_ASSERT(common->first_line_end != 0);
3234    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3235    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS(max));
   JUMPHERE(singlechar);  
3236    }    }
3237  #endif  else
3238  #if defined SUPPORT_UTF && defined COMPILE_PCRE16    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3239  if (common->utf)  
3240    start = LABEL();
3241    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3242    
3243    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
3244    if (offsets[1] >= 0)
3245      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3246    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3247    
3248    if (chars[1] != 0)
3249      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3250    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3251    if (offsets[2] >= 0)
3252      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));
3253    
3254    if (offsets[1] >= 0)
3255    {    {
3256    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    if (chars[5] != 0)
3257    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3258    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
   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);  
   JUMPHERE(singlechar);  
3259    }    }
 #endif  
 JUMPHERE(start);  
3260    
3261  if (newlinecheck)  if (offsets[2] >= 0)
3262    {    {
3263    JUMPHERE(end);    if (chars[3] != 0)
3264    JUMPHERE(nl);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3265      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3266    }    }
3267    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3268    
3269  return mainloop;  JUMPHERE(quit);
3270    
3271    if (firstline)
3272      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3273    else
3274      OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3275    return TRUE;
3276  }  }
3277    
3278    #undef MAX_N_CHARS
3279    
3280  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)
3281  {  {
3282  DEFINE_COMPILER;  DEFINE_COMPILER;
3283  struct sljit_label *start;  struct sljit_label *start;
3284  struct sljit_jump *leave;  struct sljit_jump *quit;
3285  struct sljit_jump *found;  struct sljit_jump *found;
3286  pcre_uchar oc, bit;  pcre_uchar oc, bit;
3287    
3288  if (firstline)  if (firstline)
3289    {    {
3290    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3291      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3292    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3293    }    }
3294    
3295  start = LABEL();  start = LABEL();
3296  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3297  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3298    
3299  oc = first_char;  oc = first_char;
# Line 2120  if (first_char == oc) Line 3310  if (first_char == oc)
3310  else  else
3311    {    {
3312    bit = first_char ^ oc;    bit = first_char ^ oc;
3313    if (ispowerof2(bit))    if (is_powerof2(bit))
3314      {      {
3315      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3316      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
# Line 2128  else Line 3318  else
3318    else    else
3319      {      {
3320      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, first_char);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, first_char);
3321      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3322      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);
3323      COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3324      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3325      }      }
3326    }    }
3327    
3328  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));
 #if defined SUPPORT_UTF && defined COMPILE_PCRE8  
 if (common->utf)  
   {  
   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);  
   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)  
   {  
   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);  
   OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);  
   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);  
   }  
 #endif  
3329  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3330  JUMPHERE(found);  JUMPHERE(found);
3331  JUMPHERE(leave);  JUMPHERE(quit);
3332    
3333  if (firstline)  if (firstline)
3334    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3335  }  }
3336    
3337  static SLJIT_INLINE void fast_forward_newline(compiler_common *common, BOOL firstline)  static SLJIT_INLINE void fast_forward_newline(compiler_common *common, BOOL firstline)
# Line 2169  DEFINE_COMPILER; Line 3340  DEFINE_COMPILER;
3340  struct sljit_label *loop;  struct sljit_label *loop;
3341  struct sljit_jump *lastchar;  struct sljit_jump *lastchar;
3342  struct sljit_jump *firstchar;  struct sljit_jump *firstchar;
3343  struct sljit_jump *leave;  struct sljit_jump *quit;
3344  struct sljit_jump *foundcr = NULL;  struct sljit_jump *foundcr = NULL;
3345  struct sljit_jump *notfoundnl;  struct sljit_jump *notfoundnl;
3346  jump_list *newline = NULL;  jump_list *newline = NULL;
3347    
3348  if (firstline)  if (firstline)
3349    {    {
3350    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3351      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3352    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3353    }    }
3354    
# Line 2190  if (common->nltype == NLTYPE_FIXED && co Line 3362  if (common->nltype == NLTYPE_FIXED && co
3362    
3363    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3364    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_PTR, 0, TMP1, 0);
3365    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3366  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3367    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3368  #endif  #endif
3369    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3370    
3371    loop = LABEL();    loop = LABEL();
3372    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));
3373    leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3374    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
3375    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
3376    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);
3377    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);
3378    
3379    JUMPHERE(leave);    JUMPHERE(quit);
3380    JUMPHERE(firstchar);    JUMPHERE(firstchar);
3381    JUMPHERE(lastchar);    JUMPHERE(lastchar);
3382    
# Line 2228  set_jumps(newline, loop); Line 3400  set_jumps(newline, loop);
3400    
3401  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3402    {    {
3403    leave = JUMP(SLJIT_JUMP);    quit = JUMP(SLJIT_JUMP);
3404    JUMPHERE(foundcr);    JUMPHERE(foundcr);
3405    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3406    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3407    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);
3408    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3409  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3410    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3411  #endif  #endif
3412    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3413    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
3414    JUMPHERE(leave);    JUMPHERE(quit);
3415    }    }
3416  JUMPHERE(lastchar);  JUMPHERE(lastchar);
3417  JUMPHERE(firstchar);  JUMPHERE(firstchar);
3418    
3419  if (firstline)  if (firstline)
3420    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3421  }  }
3422    
3423  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks);
3424    
3425    static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, pcre_uint8 *start_bits, BOOL firstline)
3426  {  {
3427  DEFINE_COMPILER;  DEFINE_COMPILER;
3428  struct sljit_label *start;  struct sljit_label *start;
3429  struct sljit_jump *leave;  struct sljit_jump *quit;
3430  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3431    jump_list *matches = NULL;
3432  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3433  struct sljit_jump *jump;  struct sljit_jump *jump;
3434  #endif  #endif
3435    
3436  if (firstline)  if (firstline)
3437    {    {
3438    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3439      OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
3440    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3441    }    }
3442    
3443  start = LABEL();  start = LABEL();
3444  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3445  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3446  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3447  if (common->utf)  if (common->utf)
3448    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3449  #endif  #endif
3450    
3451    if (!check_class_ranges(common, start_bits, (start_bits[31] & 0x80) != 0, TRUE, &matches))
3452      {
3453  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3454  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3455  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3456  JUMPHERE(jump);    JUMPHERE(jump);
3457  #endif  #endif
3458  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3459  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3460  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
3461  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3462  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
3463  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3464      }
3465    
3466  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3467  if (common->utf)  if (common->utf)
3468    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3469  #endif  #endif
3470  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));
3471  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3472    #if defined COMPILE_PCRE8
3473  if (common->utf)  if (common->utf)
3474    {    {
3475    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3476    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);
3477    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3478    }    }
3479  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3480  if (common->utf)  if (common->utf)
3481    {    {
3482    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3483    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3484    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);
3485    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3486    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3487    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3488    }    }
3489  #endif  #endif /* COMPILE_PCRE[8|16] */
3490    #endif /* SUPPORT_UTF */
3491  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3492  JUMPHERE(found);  if (found != NULL)
3493  JUMPHERE(leave);    JUMPHERE(found);
3494    if (matches != NULL)
3495      set_jumps(matches, LABEL());
3496    JUMPHERE(quit);
3497    
3498  if (firstline)  if (firstline)
3499    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0);
3500  }  }
3501    
3502  static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uchar req_char, BOOL caseless, BOOL has_firstchar)  static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uchar req_char, BOOL caseless, BOOL has_firstchar)
# Line 2324  struct sljit_jump *alreadyfound; Line 3508  struct sljit_jump *alreadyfound;
3508  struct sljit_jump *found;  struct sljit_jump *found;
3509  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3510  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3511  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3512    
3513  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3514  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
# Line 2355  if (req_char == oc) Line 3539  if (req_char == oc)
3539  else  else
3540    {    {
3541    bit = req_char ^ oc;    bit = req_char ^ oc;
3542    if (ispowerof2(bit))    if (is_powerof2(bit))
3543      {      {
3544      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3545      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
# Line 2384  DEFINE_COMPILER; Line 3568  DEFINE_COMPILER;
3568  struct sljit_jump *jump;  struct sljit_jump *jump;
3569  struct sljit_label *mainloop;  struct sljit_label *mainloop;
3570    
3571  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3572  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);
3573    GET_LOCAL_BASE(TMP3, 0, 0);
3574    
3575  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3576  mainloop = LABEL();  mainloop = LABEL();
3577  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3578  jump = CMP(SLJIT_C_SIG_LESS_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0);
3579  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_LOCALS_REG, 0);  jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3580  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  
3581  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_w), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3582  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3583    OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
3584    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw));
3585  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3586    
3587  JUMPHERE(jump);  JUMPHERE(jump);
3588  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3589  /* End of dropping frames. */  /* End of dropping frames. */
3590  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3591    
3592  JUMPHERE(jump);  JUMPHERE(jump);
3593  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3594  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3595  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3596  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), TMP2, 0);  
 JUMPTO(SLJIT_JUMP, mainloop);  
   
 JUMPHERE(jump);  
 if (common->mark_ptr != 0)  
   {  
   jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setmark);  
   OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  
   OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);  
   JUMPTO(SLJIT_JUMP, mainloop);  
   
   JUMPHERE(jump);  
   }  
   
 /* Unknown command. */  
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  
3597  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3598  }  }
3599    
# Line 2431  static void check_wordboundary(compiler_ Line 3601  static void check_wordboundary(compiler_
3601  {  {
3602  DEFINE_COMPILER;  DEFINE_COMPILER;
3603  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3604    jump_list *skipread_list = NULL;
3605  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3606  struct sljit_jump *jump;  struct sljit_jump *jump;
3607  #endif  #endif
3608    
3609  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);
3610    
3611  sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3612  /* Get type of the previous char, and put it to LOCALS1. */  /* Get type of the previous char, and put it to LOCALS1. */
3613  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
3614  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
# Line 2456  if (common->use_ucp) Line 3627  if (common->use_ucp)
3627    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3628    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3629    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
3630    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3631    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);
3632    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);
3633    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3634    JUMPHERE(jump);    JUMPHERE(jump);
3635    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3636    }    }
3637  else  else
3638  #endif  #endif
3639    {    {
3640  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3641    jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3642  #elif defined SUPPORT_UTF  #elif defined SUPPORT_UTF
3643    /* Here LOCALS1 has already been zeroed. */    /* Here LOCALS1 has already been zeroed. */
3644    jump = NULL;    jump = NULL;
3645    if (common->utf)    if (common->utf)
3646      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3647  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3648    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);
3649    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);
3650    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3651    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
3652  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3653    JUMPHERE(jump);    JUMPHERE(jump);
3654  #elif defined SUPPORT_UTF  #elif defined SUPPORT_UTF
3655    if (jump != NULL)    if (jump != NULL)
3656      JUMPHERE(jump);      JUMPHERE(jump);
3657  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3658      }
3659    JUMPHERE(skipread);
3660    
3661    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3662    check_str_end(common, &skipread_list);
3663    peek_char(common);
3664    
3665    /* Testing char type. This is a code duplication. */
3666    #ifdef SUPPORT_UCP
3667    if (common->use_ucp)
3668      {
3669      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
3670      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
3671      add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3672      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3673      OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
3674      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3675      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);
3676      OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);
3677      OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3678      JUMPHERE(jump);
3679      }
3680    else
3681    #endif
3682      {
3683    #ifndef COMPILE_PCRE8
3684      /* TMP2 may be destroyed by peek_char. */
3685      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3686      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3687    #elif defined SUPPORT_UTF
3688      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3689      jump = NULL;
3690      if (common->utf)
3691        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3692    #endif
3693      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);
3694      OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);
3695      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
3696    #ifndef COMPILE_PCRE8
3697      JUMPHERE(jump);
3698    #elif defined SUPPORT_UTF
3699      if (jump != NULL)
3700        JUMPHERE(jump);
3701    #endif /* COMPILE_PCRE8 */
3702      }
3703    set_jumps(skipread_list, LABEL());
3704    
3705    OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3706    sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3707    }
3708    
3709    /*
3710      range format:
3711    
3712      ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).
3713      ranges[1] = first bit (0 or 1)
3714      ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)
3715    */
3716    
3717    static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)
3718    {
3719    DEFINE_COMPILER;
3720    
3721    if (ranges[0] < 0 || ranges[0] > 4)
3722      return FALSE;
3723    
3724    /* No character is accepted. */
3725    if (ranges[0] == 0 && ranges[1] == 0)
3726      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
3727    
3728    if (readch)
3729      read_char(common);
3730    
3731    switch(ranges[0])
3732      {
3733      case 0:
3734      /* When ranges[1] != 0, all characters are accepted. */
3735      return TRUE;
3736    
3737      case 1:
3738      add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3739      return TRUE;
3740    
3741      case 2:
3742      if (ranges[2] + 1 != ranges[3])
3743        {
3744        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3745        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3746        }
3747      else
3748        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3749      return TRUE;
3750    
3751      case 3:
3752      if (ranges[1] != 0)
3753        {
3754        add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3755        if (ranges[2] + 1 != ranges[3])
3756          {
3757          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3758          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3759          }
3760        else
3761          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3762        return TRUE;
3763        }
3764    
3765      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2]));
3766      if (ranges[3] + 1 != ranges[4])
3767        {
3768        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[3]);
3769        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[3]));
3770        }