/[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 977 by zherczeg, Sun Jun 17 06:20:52 2012 UTC revision 1249 by zherczeg, Mon Feb 18 09:55:43 2013 UTC
# 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    /* Allocate memory for the regex stack on the real machine stack.
75    Fast, but limited size. */
76    #define MACHINE_STACK_SIZE 32768
77    
78    /* Growth rate for stack allocated by the OS. Should be the multiply
79    of page size. */
80  #define STACK_GROWTH_RATE 8192  #define STACK_GROWTH_RATE 8192
81    
82  /* Enable to check that the allocation could destroy temporaries. */  /* Enable to check that the allocation could destroy temporaries. */
# Line 89  vertical (sub-expression) (See struct ba Line 98  vertical (sub-expression) (See struct ba
98    
99  The condition checkers are boolean (true/false) checkers. Machine code is generated  The condition checkers are boolean (true/false) checkers. Machine code is generated
100  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.
101  The 'true' case is called as the try path (expected path), and the other is called as  The 'true' case is called as the matching path (expected path), and the other is called as
102  the 'backtrack' path. Branch instructions are expesive for all CPUs, so we avoid taken  the 'backtrack' path. Branch instructions are expesive for all CPUs, so we avoid taken
103  branches on the try path.  branches on the matching path.
104    
105   Greedy star operator (*) :   Greedy star operator (*) :
106     Try path: match happens.     Matching path: match happens.
107     Backtrack path: match failed.     Backtrack path: match failed.
108   Non-greedy star operator (*?) :   Non-greedy star operator (*?) :
109     Try path: no need to perform a match.     Matching path: no need to perform a match.
110     Backtrack path: match is required.     Backtrack path: match is required.
111    
112  The following example shows how the code generated for a capturing bracket  The following example shows how the code generated for a capturing bracket
# Line 108  we have the following regular expression Line 117  we have the following regular expression
117    
118  The generated code will be the following:  The generated code will be the following:
119    
120   A try path   A matching path
121   '(' try path (pushing arguments to the stack)   '(' matching path (pushing arguments to the stack)
122   B try path   B matching path
123   ')' try path (pushing arguments to the stack)   ')' matching path (pushing arguments to the stack)
124   D try path   D matching path
125   return with successful match   return with successful match
126    
127   D backtrack path   D backtrack path
128   ')' backtrack path (If we arrived from "C" jump to the backtrack of "C")   ')' backtrack path (If we arrived from "C" jump to the backtrack of "C")
129   B backtrack path   B backtrack path
130   C expected path   C expected path
131   jump to D try path   jump to D matching path
132   C backtrack path   C backtrack path
133   A backtrack path   A backtrack path
134    
# Line 127  The generated code will be the following Line 136  The generated code will be the following
136   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
137   to the current backtrack code path. The backtrack path must check   to the current backtrack code path. The backtrack path must check
138   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
139   the try path eventually. Otherwise it needs to clear out its own stack   the matching path eventually. Otherwise it needs to clear out its own stack
140   frame and continue the execution on the backtrack code paths.   frame and continue the execution on the backtrack code paths.
141  */  */
142    
143  /*  /*
144  Saved stack frames:  Saved stack frames:
145    
146  Atomic blocks and asserts require reloading the values of local variables  Atomic blocks and asserts require reloading the values of private data
147  when the backtrack mechanism performed. Because of OP_RECURSE, the locals  when the backtrack mechanism performed. Because of OP_RECURSE, the data
148  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
149  mechanism.  mechanism.
150    
151  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:
152  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]
153    
154  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.
155  */  */
156    
157  typedef struct jit_arguments {  typedef struct jit_arguments {
# Line 154  typedef struct jit_arguments { Line 163  typedef struct jit_arguments {
163    int *offsets;    int *offsets;
164    pcre_uchar *uchar_ptr;    pcre_uchar *uchar_ptr;
165    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
166      void *callout_data;
167    /* Everything else after. */    /* Everything else after. */
168    int offsetcount;    int offset_count;
169    int calllimit;    int call_limit;
170    pcre_uint8 notbol;    pcre_uint8 notbol;
171    pcre_uint8 noteol;    pcre_uint8 noteol;
172    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 167  typedef struct executable_functions { Line 177  typedef struct executable_functions {
177    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
178    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
179    void *userdata;    void *userdata;
180      pcre_uint32 top_bracket;
181    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
182  } executable_functions;  } executable_functions;
183    
# Line 175  typedef struct jump_list { Line 186  typedef struct jump_list {
186    struct jump_list *next;    struct jump_list *next;
187  } jump_list;  } jump_list;
188    
 enum stub_types { stack_alloc };  
   
189  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
190    struct sljit_jump *start;    struct sljit_jump *start;
191    struct sljit_label *leave;    struct sljit_label *quit;
192    struct stub_list *next;    struct stub_list *next;
193  } stub_list;  } stub_list;
194    
195    enum frame_types { no_frame = -1, no_stack = -2 };
196    
197  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
198    
199  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
200  code generator. It is allocated by compile_trypath, and contains  code generator. It is allocated by compile_matchingpath, and contains
201  the aguments for compile_backtrackpath. Must be the first member  the aguments for compile_backtrackingpath. Must be the first member
202  of its descendants. */  of its descendants. */
203  typedef struct backtrack_common {  typedef struct backtrack_common {
204    /* Concatenation stack. */    /* Concatenation stack. */
# Line 208  typedef struct assert_backtrack { Line 217  typedef struct assert_backtrack {
217    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 (-1) if a frame is not needed. */
218    int framesize;    int framesize;
219    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
220    int localptr;    int private_data_ptr;
221    /* For iterators. */    /* For iterators. */
222    struct sljit_label *trypath;    struct sljit_label *matchingpath;
223  } assert_backtrack;  } assert_backtrack;
224    
225  typedef struct bracket_backtrack {  typedef struct bracket_backtrack {
226    backtrack_common common;    backtrack_common common;
227    /* Where to coninue if an alternative is successfully matched. */    /* Where to coninue if an alternative is successfully matched. */
228    struct sljit_label *alttrypath;    struct sljit_label *alternative_matchingpath;
229    /* For rmin and rmax iterators. */    /* For rmin and rmax iterators. */
230    struct sljit_label *recursivetrypath;    struct sljit_label *recursive_matchingpath;
231    /* For greedy ? operator. */    /* For greedy ? operator. */
232    struct sljit_label *zerotrypath;    struct sljit_label *zero_matchingpath;
233    /* Contains the branches of a failed condition. */    /* Contains the branches of a failed condition. */
234    union {    union {
235      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
# Line 230  typedef struct bracket_backtrack { Line 239  typedef struct bracket_backtrack {
239      int framesize;      int framesize;
240    } u;    } u;
241    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
242    int localptr;    int private_data_ptr;
243  } bracket_backtrack;  } bracket_backtrack;
244    
245  typedef struct bracketpos_backtrack {  typedef struct bracketpos_backtrack {
246    backtrack_common common;    backtrack_common common;
247    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
248    int localptr;    int private_data_ptr;
249    /* Reverting stack is needed. */    /* Reverting stack is needed. */
250    int framesize;    int framesize;
251    /* Allocated stack size. */    /* Allocated stack size. */
# Line 245  typedef struct bracketpos_backtrack { Line 254  typedef struct bracketpos_backtrack {
254    
255  typedef struct braminzero_backtrack {  typedef struct braminzero_backtrack {
256    backtrack_common common;    backtrack_common common;
257    struct sljit_label *trypath;    struct sljit_label *matchingpath;
258  } braminzero_backtrack;  } braminzero_backtrack;
259    
260  typedef struct iterator_backtrack {  typedef struct iterator_backtrack {
261    backtrack_common common;    backtrack_common common;
262    /* Next iteration. */    /* Next iteration. */
263    struct sljit_label *trypath;    struct sljit_label *matchingpath;
264  } iterator_backtrack;  } iterator_backtrack;
265    
266  typedef struct recurse_entry {  typedef struct recurse_entry {
# Line 266  typedef struct recurse_entry { Line 275  typedef struct recurse_entry {
275    
276  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
277    backtrack_common common;    backtrack_common common;
278      BOOL inlined_pattern;
279  } recurse_backtrack;  } recurse_backtrack;
280    
281    #define MAX_RANGE_SIZE 6
282    
283  typedef struct compiler_common {  typedef struct compiler_common {
284    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
285    pcre_uchar *start;    pcre_uchar *start;
286    
287    /* Opcode local area direct map. */    /* Maps private data offset to each opcode. */
288    int *localptrs;    int *private_data_ptrs;
289      /* Tells whether the capturing bracket is optimized. */
290      pcre_uint8 *optimized_cbracket;
291      /* Starting offset of private data for capturing brackets. */
292    int cbraptr;    int cbraptr;
293    /* OVector starting point. Must be divisible by 2. */    /* OVector starting point. Must be divisible by 2. */
294    int ovector_start;    int ovector_start;
295    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
296    int req_char_ptr;    int req_char_ptr;
297    /* Head of the last recursion. */    /* Head of the last recursion. */
298    int recursive_head;    int recursive_head_ptr;
299    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
300    int start_used_ptr;    int start_used_ptr;
301    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 289  typedef struct compiler_common { Line 304  typedef struct compiler_common {
304    int first_line_end;    int first_line_end;
305    /* Points to the marked string. */    /* Points to the marked string. */
306    int mark_ptr;    int mark_ptr;
307      /* Points to the last matched capture block index. */
308      int capture_last_ptr;
309    
310    /* Other  */    /* Flipped and lower case tables. */
311    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
312    sljit_w lcc;    sljit_sw lcc;
313      /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
314    int mode;    int mode;
315      /* Newline control. */
316    int nltype;    int nltype;
317    int newline;    int newline;
318    int bsr_nltype;    int bsr_nltype;
319      /* Dollar endonly. */
320    int endonly;    int endonly;
321    BOOL has_set_som;    BOOL has_set_som;
322    sljit_w ctypes;    /* Tables. */
323      sljit_sw ctypes;
324      int digits[2 + MAX_RANGE_SIZE];
325      /* Named capturing brackets. */
326    sljit_uw name_table;    sljit_uw name_table;
327    sljit_w name_count;    sljit_sw name_count;
328    sljit_w name_entry_size;    sljit_sw name_entry_size;
329    
330    /* Labels and jump lists. */    /* Labels and jump lists. */
331    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
332    struct sljit_label *leavelabel;    struct sljit_label *quit_label;
333    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
334      struct sljit_label *accept_label;
335    stub_list *stubs;    stub_list *stubs;
336    recurse_entry *entries;    recurse_entry *entries;
337    recurse_entry *currententry;    recurse_entry *currententry;
338    jump_list *partialmatch;    jump_list *partialmatch;
339    jump_list *leave;    jump_list *quit;
340      jump_list *forced_quit;
341    jump_list *accept;    jump_list *accept;
342    jump_list *calllimit;    jump_list *calllimit;
343    jump_list *stackalloc;    jump_list *stackalloc;
# Line 329  typedef struct compiler_common { Line 354  typedef struct compiler_common {
354  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
355    BOOL use_ucp;    BOOL use_ucp;
356  #endif  #endif
357    #ifndef COMPILE_PCRE32
358    jump_list *utfreadchar;    jump_list *utfreadchar;
359    #endif
360  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
361    jump_list *utfreadtype8;    jump_list *utfreadtype8;
362  #endif  #endif
# Line 347  typedef struct compare_context { Line 374  typedef struct compare_context {
374  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
375    int ucharptr;    int ucharptr;
376    union {    union {
377      sljit_i asint;      sljit_si asint;
378      sljit_uh asushort;      sljit_uh asushort;
379  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
380      sljit_ub asbyte;      sljit_ub asbyte;
381      sljit_ub asuchars[4];      sljit_ub asuchars[4];
382  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
383      sljit_uh asuchars[2];      sljit_uh asuchars[2];
384  #endif  #elif defined COMPILE_PCRE32
385        sljit_ui asuchars[1];
386  #endif  #endif
387    } c;    } c;
388    union {    union {
389      sljit_i asint;      sljit_si asint;
390      sljit_uh asushort;      sljit_uh asushort;
391  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
392      sljit_ub asbyte;      sljit_ub asbyte;
393      sljit_ub asuchars[4];      sljit_ub asuchars[4];
394  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
395      sljit_uh asuchars[2];      sljit_uh asuchars[2];
396  #endif  #elif defined COMPILE_PCRE32
397        sljit_ui asuchars[1];
398  #endif  #endif
399    } oc;    } oc;
400  #endif  #endif
401  } compare_context;  } compare_context;
402    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
403  /* Undefine sljit macros. */  /* Undefine sljit macros. */
404  #undef CMP  #undef CMP
405    
406  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
407  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
408    
409  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
410  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
411  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
412  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
413  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
414  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
415  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
416  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
417  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
418  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
419    
420  /* Locals layout. */  /* Local space layout. */
421  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
422  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
423  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
424  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
425  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
426  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
427  /* Max limit of recursions. */  /* Max limit of recursions. */
428  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define CALL_LIMIT       (4 * sizeof(sljit_sw))
429  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
430  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
431  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
432  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. */
433  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
434  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
435  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_sw))
436  #define PRIV_DATA(cc)    (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
437    
438  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
439  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
440  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
441  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
442  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
443  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
444    #elif defined COMPILE_PCRE32
445    #define MOV_UCHAR  SLJIT_MOV_UI
446    #define MOVU_UCHAR SLJIT_MOVU_UI
447  #else  #else
448  #error Unsupported compiling mode  #error Unsupported compiling mode
449  #endif  #endif
 #endif  
450    
451  /* Shortcuts. */  /* Shortcuts. */
452  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 441  the start pointers when the end of the c Line 463  the start pointers when the end of the c
463    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
464  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
465    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
466    #define SET_LABEL(jump, label) \
467      sljit_set_label((jump), (label))
468  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
469    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
470  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
471    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))
472  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
473    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
474  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
475    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
476    
# Line 461  return cc; Line 485  return cc;
485    
486  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
487   next_opcode   next_opcode
488   get_localspace   get_private_data_length
489   set_localptrs   set_private_data_ptrs
490   get_framesize   get_framesize
491   init_frame   init_frame
492   get_localsize   get_private_data_length_for_copy
493   copy_locals   copy_private_data
494   compile_trypath   compile_matchingpath
495   compile_backtrackpath   compile_backtrackingpath
496  */  */
497    
498  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
# Line 489  switch(*cc) Line 513  switch(*cc)
513    case OP_WORDCHAR:    case OP_WORDCHAR:
514    case OP_ANY:    case OP_ANY:
515    case OP_ALLANY:    case OP_ALLANY:
516      case OP_NOTPROP:
517      case OP_PROP:
518    case OP_ANYNL:    case OP_ANYNL:
519    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
520    case OP_HSPACE:    case OP_HSPACE:
# Line 501  switch(*cc) Line 527  switch(*cc)
527    case OP_CIRCM:    case OP_CIRCM:
528    case OP_DOLL:    case OP_DOLL:
529    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:  
530    case OP_CRSTAR:    case OP_CRSTAR:
531    case OP_CRMINSTAR:    case OP_CRMINSTAR:
532    case OP_CRPLUS:    case OP_CRPLUS:
533    case OP_CRMINPLUS:    case OP_CRMINPLUS:
534    case OP_CRQUERY:    case OP_CRQUERY:
535    case OP_CRMINQUERY:    case OP_CRMINQUERY:
536      case OP_CRRANGE:
537      case OP_CRMINRANGE:
538      case OP_CLASS:
539      case OP_NCLASS:
540      case OP_REF:
541      case OP_REFI:
542      case OP_RECURSE:
543      case OP_CALLOUT:
544      case OP_ALT:
545      case OP_KET:
546      case OP_KETRMAX:
547      case OP_KETRMIN:
548      case OP_KETRPOS:
549      case OP_REVERSE:
550      case OP_ASSERT:
551      case OP_ASSERT_NOT:
552      case OP_ASSERTBACK:
553      case OP_ASSERTBACK_NOT:
554      case OP_ONCE:
555      case OP_ONCE_NC:
556      case OP_BRA:
557      case OP_BRAPOS:
558      case OP_CBRA:
559      case OP_CBRAPOS:
560      case OP_COND:
561      case OP_SBRA:
562      case OP_SBRAPOS:
563      case OP_SCBRA:
564      case OP_SCBRAPOS:
565      case OP_SCOND:
566      case OP_CREF:
567      case OP_NCREF:
568      case OP_RREF:
569      case OP_NRREF:
570    case OP_DEF:    case OP_DEF:
571    case OP_BRAZERO:    case OP_BRAZERO:
572    case OP_BRAMINZERO:    case OP_BRAMINZERO:
# Line 524  switch(*cc) Line 575  switch(*cc)
575    case OP_FAIL:    case OP_FAIL:
576    case OP_ACCEPT:    case OP_ACCEPT:
577    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
578      case OP_CLOSE:
579    case OP_SKIPZERO:    case OP_SKIPZERO:
580    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
581    
582    case OP_CHAR:    case OP_CHAR:
583    case OP_CHARI:    case OP_CHARI:
# Line 543  switch(*cc) Line 589  switch(*cc)
589    case OP_MINPLUS:    case OP_MINPLUS:
590    case OP_QUERY:    case OP_QUERY:
591    case OP_MINQUERY:    case OP_MINQUERY:
592      case OP_UPTO:
593      case OP_MINUPTO:
594      case OP_EXACT:
595    case OP_POSSTAR:    case OP_POSSTAR:
596    case OP_POSPLUS:    case OP_POSPLUS:
597    case OP_POSQUERY:    case OP_POSQUERY:
598      case OP_POSUPTO:
599    case OP_STARI:    case OP_STARI:
600    case OP_MINSTARI:    case OP_MINSTARI:
601    case OP_PLUSI:    case OP_PLUSI:
602    case OP_MINPLUSI:    case OP_MINPLUSI:
603    case OP_QUERYI:    case OP_QUERYI:
604    case OP_MINQUERYI:    case OP_MINQUERYI:
605      case OP_UPTOI:
606      case OP_MINUPTOI:
607      case OP_EXACTI:
608    case OP_POSSTARI:    case OP_POSSTARI:
609    case OP_POSPLUSI:    case OP_POSPLUSI:
610    case OP_POSQUERYI:    case OP_POSQUERYI:
611      case OP_POSUPTOI:
612    case OP_NOTSTAR:    case OP_NOTSTAR:
613    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
614    case OP_NOTPLUS:    case OP_NOTPLUS:
615    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
616    case OP_NOTQUERY:    case OP_NOTQUERY:
617    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
618      case OP_NOTUPTO:
619      case OP_NOTMINUPTO:
620      case OP_NOTEXACT:
621    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
622    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
623    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
624      case OP_NOTPOSUPTO:
625    case OP_NOTSTARI:    case OP_NOTSTARI:
626    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
627    case OP_NOTPLUSI:    case OP_NOTPLUSI:
628    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
629    case OP_NOTQUERYI:    case OP_NOTQUERYI:
630    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:  
631    case OP_NOTUPTOI:    case OP_NOTUPTOI:
632    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
633    case OP_NOTEXACTI:    case OP_NOTEXACTI:
634      case OP_NOTPOSSTARI:
635      case OP_NOTPOSPLUSI:
636      case OP_NOTPOSQUERYI:
637    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
638    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
639  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
640    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
641  #endif  #endif
642    return cc;    return cc;
643    
644    case OP_NOTPROP:    /* Special cases. */
645    case OP_PROP:    case OP_TYPESTAR:
646    return cc + 1 + 2;    case OP_TYPEMINSTAR:
647      case OP_TYPEPLUS:
648      case OP_TYPEMINPLUS:
649      case OP_TYPEQUERY:
650      case OP_TYPEMINQUERY:
651    case OP_TYPEUPTO:    case OP_TYPEUPTO:
652    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
653    case OP_TYPEEXACT:    case OP_TYPEEXACT:
654      case OP_TYPEPOSSTAR:
655      case OP_TYPEPOSPLUS:
656      case OP_TYPEPOSQUERY:
657    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
658    case OP_REF:    return cc + PRIV(OP_lengths)[*cc] - 1;
   case OP_REFI:  
   case OP_CREF:  
   case OP_NCREF:  
   case OP_RREF:  
   case OP_NRREF:  
   case OP_CLOSE:  
   cc += 1 + IMM2_SIZE;  
   return cc;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   return cc + 1 + 2 * IMM2_SIZE;  
659    
660    case OP_CLASS:    case OP_ANYBYTE:
661    case OP_NCLASS:  #ifdef SUPPORT_UTF
662    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
663    #endif
664      return cc + 1;
665    
666  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
667    case OP_XCLASS:    case OP_XCLASS:
668    return cc + GET(cc, 1);    return cc + GET(cc, 1);
669  #endif  #endif
670    
   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;  
   
671    case OP_MARK:    case OP_MARK:
672    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
673    
# Line 667  switch(*cc) Line 676  switch(*cc)
676    }    }
677  }  }
678    
679  static int get_localspace(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
680        case OP_MINSTAR: \
681        case OP_MINPLUS: \
682        case OP_QUERY: \
683        case OP_MINQUERY: \
684        case OP_MINSTARI: \
685        case OP_MINPLUSI: \
686        case OP_QUERYI: \
687        case OP_MINQUERYI: \
688        case OP_NOTMINSTAR: \
689        case OP_NOTMINPLUS: \
690        case OP_NOTQUERY: \
691        case OP_NOTMINQUERY: \
692        case OP_NOTMINSTARI: \
693        case OP_NOTMINPLUSI: \
694        case OP_NOTQUERYI: \
695        case OP_NOTMINQUERYI:
696    
697    #define CASE_ITERATOR_PRIVATE_DATA_2A \
698        case OP_STAR: \
699        case OP_PLUS: \
700        case OP_STARI: \
701        case OP_PLUSI: \
702        case OP_NOTSTAR: \
703        case OP_NOTPLUS: \
704        case OP_NOTSTARI: \
705        case OP_NOTPLUSI:
706    
707    #define CASE_ITERATOR_PRIVATE_DATA_2B \
708        case OP_UPTO: \
709        case OP_MINUPTO: \
710        case OP_UPTOI: \
711        case OP_MINUPTOI: \
712        case OP_NOTUPTO: \
713        case OP_NOTMINUPTO: \
714        case OP_NOTUPTOI: \
715        case OP_NOTMINUPTOI:
716    
717    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
718        case OP_TYPEMINSTAR: \
719        case OP_TYPEMINPLUS: \
720        case OP_TYPEQUERY: \
721        case OP_TYPEMINQUERY:
722    
723    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
724        case OP_TYPESTAR: \
725        case OP_TYPEPLUS:
726    
727    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
728        case OP_TYPEUPTO: \
729        case OP_TYPEMINUPTO:
730    
731    static int get_class_iterator_size(pcre_uchar *cc)
732  {  {
733  int localspace = 0;  switch(*cc)
734      {
735      case OP_CRSTAR:
736      case OP_CRPLUS:
737      return 2;
738    
739      case OP_CRMINSTAR:
740      case OP_CRMINPLUS:
741      case OP_CRQUERY:
742      case OP_CRMINQUERY:
743      return 1;
744    
745      case OP_CRRANGE:
746      case OP_CRMINRANGE:
747      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
748        return 0;
749      return 2;
750    
751      default:
752      return 0;
753      }
754    }
755    
756    static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
757    {
758    int private_data_length = 0;
759  pcre_uchar *alternative;  pcre_uchar *alternative;
760    pcre_uchar *name;
761    pcre_uchar *end = NULL;
762    int space, size, i;
763    pcre_uint32 bracketlen;
764    
765  /* 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. */
766  while (cc < ccend)  while (cc < ccend)
767    {    {
768      space = 0;
769      size = 0;
770      bracketlen = 0;
771    switch(*cc)    switch(*cc)
772      {      {
773      case OP_SET_SOM:      case OP_SET_SOM:
# Line 681  while (cc < ccend) Line 775  while (cc < ccend)
775      cc += 1;      cc += 1;
776      break;      break;
777    
778        case OP_REF:
779        case OP_REFI:
780        common->optimized_cbracket[GET2(cc, 1)] = 0;
781        cc += 1 + IMM2_SIZE;
782        break;
783    
784      case OP_ASSERT:      case OP_ASSERT:
785      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
786      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 690  while (cc < ccend) Line 790  while (cc < ccend)
790      case OP_BRAPOS:      case OP_BRAPOS:
791      case OP_SBRA:      case OP_SBRA:
792      case OP_SBRAPOS:      case OP_SBRAPOS:
793      case OP_SCOND:      private_data_length += sizeof(sljit_sw);
794      localspace += sizeof(sljit_w);      bracketlen = 1 + LINK_SIZE;
     cc += 1 + LINK_SIZE;  
795      break;      break;
796    
797      case OP_CBRAPOS:      case OP_CBRAPOS:
798      case OP_SCBRAPOS:      case OP_SCBRAPOS:
799      localspace += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
800      cc += 1 + LINK_SIZE + IMM2_SIZE;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
801        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
802      break;      break;
803    
804      case OP_COND:      case OP_COND:
805      /* Might be a hidden SCOND. */      case OP_SCOND:
806      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
807      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
808        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
809      cc += 1 + LINK_SIZE;        return -1;
810    
811        if (*cc == OP_COND)
812          {
813          /* Might be a hidden SCOND. */
814          alternative = cc + GET(cc, 1);
815          if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
816            private_data_length += sizeof(sljit_sw);
817          }
818        else
819          private_data_length += sizeof(sljit_sw);
820        bracketlen = 1 + LINK_SIZE;
821        break;
822    
823        case OP_CREF:
824        i = GET2(cc, 1);
825        common->optimized_cbracket[i] = 0;
826        cc += 1 + IMM2_SIZE;
827        break;
828    
829        case OP_NCREF:
830        bracketlen = GET2(cc, 1);
831        name = (pcre_uchar *)common->name_table;
832        alternative = name;
833        for (i = 0; i < common->name_count; i++)
834          {
835          if (GET2(name, 0) == bracketlen) break;
836          name += common->name_entry_size;
837          }
838        SLJIT_ASSERT(i != common->name_count);
839    
840        for (i = 0; i < common->name_count; i++)
841          {
842          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
843            common->optimized_cbracket[GET2(alternative, 0)] = 0;
844          alternative += common->name_entry_size;
845          }
846        bracketlen = 0;
847        cc += 1 + IMM2_SIZE;
848      break;      break;
849    
850        case OP_BRA:
851        bracketlen = 1 + LINK_SIZE;
852        break;
853    
854        case OP_CBRA:
855        case OP_SCBRA:
856        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
857        break;
858    
859        CASE_ITERATOR_PRIVATE_DATA_1
860        space = 1;
861        size = -2;
862        break;
863    
864        CASE_ITERATOR_PRIVATE_DATA_2A
865        space = 2;
866        size = -2;
867        break;
868    
869        CASE_ITERATOR_PRIVATE_DATA_2B
870        space = 2;
871        size = -(2 + IMM2_SIZE);
872        break;
873    
874        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
875        space = 1;
876        size = 1;
877        break;
878    
879        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
880        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
881          space = 2;
882        size = 1;
883        break;
884    
885        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
886        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
887          space = 2;
888        size = 1 + IMM2_SIZE;
889        break;
890    
891        case OP_CLASS:
892        case OP_NCLASS:
893        size += 1 + 32 / sizeof(pcre_uchar);
894        space = get_class_iterator_size(cc + size);
895        break;
896    
897    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
898        case OP_XCLASS:
899        size = GET(cc, 1);
900        space = get_class_iterator_size(cc + size);
901        break;
902    #endif
903    
904      case OP_RECURSE:      case OP_RECURSE:
905      /* Set its value only once. */      /* Set its value only once. */
906      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
907        {        {
908        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
909        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
910        }        }
911      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
912      break;      break;
913    
914        case OP_CALLOUT:
915        if (common->capture_last_ptr == 0)
916          {
917          common->capture_last_ptr = common->ovector_start;
918          common->ovector_start += sizeof(sljit_sw);
919          }
920        cc += 2 + 2 * LINK_SIZE;
921        break;
922    
923      case OP_MARK:      case OP_MARK:
924      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
925        {        {
926        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
927        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
928        }        }
929      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
930      break;      break;
# Line 734  while (cc < ccend) Line 935  while (cc < ccend)
935        return -1;        return -1;
936      break;      break;
937      }      }
938    
939      if (space > 0 && cc >= end)
940        private_data_length += sizeof(sljit_sw) * space;
941    
942      if (size != 0)
943        {
944        if (size < 0)
945          {
946          cc += -size;
947    #ifdef SUPPORT_UTF
948          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
949    #endif
950          }
951        else
952          cc += size;
953        }
954    
955      if (bracketlen != 0)
956        {
957        if (cc >= end)
958          {
959          end = bracketend(cc);
960          if (end[-1 - LINK_SIZE] == OP_KET)
961            end = NULL;
962          }
963        cc += bracketlen;
964        }
965    }    }
966  return localspace;  return private_data_length;
967  }  }
968    
969  static void set_localptrs(compiler_common *common, int localptr, pcre_uchar *ccend)  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)
970  {  {
971  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
972  pcre_uchar *alternative;  pcre_uchar *alternative;
973    pcre_uchar *end = NULL;
974    int space, size, bracketlen;
975    
976  while (cc < ccend)  while (cc < ccend)
977    {    {
978      space = 0;
979      size = 0;
980      bracketlen = 0;
981    switch(*cc)    switch(*cc)
982      {      {
983      case OP_ASSERT:      case OP_ASSERT:
# Line 756  while (cc < ccend) Line 990  while (cc < ccend)
990      case OP_SBRA:      case OP_SBRA:
991      case OP_SBRAPOS:      case OP_SBRAPOS:
992      case OP_SCOND:      case OP_SCOND:
993      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
994      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
995      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
996      break;      break;
997    
998      case OP_CBRAPOS:      case OP_CBRAPOS:
999      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1000      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1001      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1002      cc += 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1003      break;      break;
1004    
1005      case OP_COND:      case OP_COND:
# Line 773  while (cc < ccend) Line 1007  while (cc < ccend)
1007      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1008      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1009        {        {
1010        common->localptrs[cc - common->start] = localptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1011        localptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1012        }        }
1013      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1014        break;
1015    
1016        case OP_BRA:
1017        bracketlen = 1 + LINK_SIZE;
1018        break;
1019    
1020        case OP_CBRA:
1021        case OP_SCBRA:
1022        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1023        break;
1024    
1025        CASE_ITERATOR_PRIVATE_DATA_1
1026        space = 1;
1027        size = -2;
1028      break;      break;
1029    
1030        CASE_ITERATOR_PRIVATE_DATA_2A
1031        space = 2;
1032        size = -2;
1033        break;
1034    
1035        CASE_ITERATOR_PRIVATE_DATA_2B
1036        space = 2;
1037        size = -(2 + IMM2_SIZE);
1038        break;
1039    
1040        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1041        space = 1;
1042        size = 1;
1043        break;
1044    
1045        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1046        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1047          space = 2;
1048        size = 1;
1049        break;
1050    
1051        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1052        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1053          space = 2;
1054        size = 1 + IMM2_SIZE;
1055        break;
1056    
1057        case OP_CLASS:
1058        case OP_NCLASS:
1059        size += 1 + 32 / sizeof(pcre_uchar);
1060        space = get_class_iterator_size(cc + size);
1061        break;
1062    
1063    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1064        case OP_XCLASS:
1065        size = GET(cc, 1);
1066        space = get_class_iterator_size(cc + size);
1067        break;
1068    #endif
1069    
1070      default:      default:
1071      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1072      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1073      break;      break;
1074      }      }
1075    
1076      if (space > 0 && cc >= end)
1077        {
1078        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1079        private_data_ptr += sizeof(sljit_sw) * space;
1080        }
1081    
1082      if (size != 0)
1083        {
1084        if (size < 0)
1085          {
1086          cc += -size;
1087    #ifdef SUPPORT_UTF
1088          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1089    #endif
1090          }
1091        else
1092          cc += size;
1093        }
1094    
1095      if (bracketlen > 0)
1096        {
1097        if (cc >= end)
1098          {
1099          end = bracketend(cc);
1100          if (end[-1 - LINK_SIZE] == OP_KET)
1101            end = NULL;
1102          }
1103        cc += bracketlen;
1104        }
1105    }    }
1106  }  }
1107    
1108  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1109  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)
1110  {  {
1111  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1112  int length = 0;  int length = 0;
1113  BOOL possessive = FALSE;  int possessive = 0;
1114    BOOL stack_restore = FALSE;
1115  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1116  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1117    /* The last capture is a local variable even for recursions. */
1118    BOOL capture_last_found = FALSE;
1119    
1120  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1121    {    {
1122    length = 3;    possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1123    possessive = TRUE;    /* This is correct regardless of common->capture_last_ptr. */
1124      capture_last_found = TRUE;
1125    }    }
1126    
1127  cc = next_opcode(common, cc);  cc = next_opcode(common, cc);
# Line 809  while (cc < ccend) Line 1131  while (cc < ccend)
1131      {      {
1132      case OP_SET_SOM:      case OP_SET_SOM:
1133      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1134        stack_restore = TRUE;
1135      if (!setsom_found)      if (!setsom_found)
1136        {        {
1137        length += 2;        length += 2;
# Line 817  while (cc < ccend) Line 1140  while (cc < ccend)
1140      cc += 1;      cc += 1;
1141      break;      break;
1142    
1143      case OP_MARK:      case OP_MARK:
1144      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1145      if (!setmark_found)      stack_restore = TRUE;
1146        {      if (!setmark_found)
1147        length += 2;        {
1148        setmark_found = TRUE;        length += 2;
1149        }        setmark_found = TRUE;
1150      cc += 1 + 2 + cc[1];        }
1151      break;      cc += 1 + 2 + cc[1];
1152        break;
1153    
1154        case OP_RECURSE:
1155        stack_restore = TRUE;
1156        if (common->has_set_som && !setsom_found)
1157          {
1158          length += 2;
1159          setsom_found = TRUE;
1160          }
1161        if (common->mark_ptr != 0 && !setmark_found)
1162          {
1163          length += 2;
1164          setmark_found = TRUE;
1165          }
1166        if (common->capture_last_ptr != 0 && !capture_last_found)
1167          {
1168          length += 2;
1169          capture_last_found = TRUE;
1170          }
1171        cc += 1 + LINK_SIZE;
1172        break;
1173    
1174        case OP_CBRA:
1175        case OP_CBRAPOS:
1176        case OP_SCBRA:
1177        case OP_SCBRAPOS:
1178        stack_restore = TRUE;
1179        if (common->capture_last_ptr != 0 && !capture_last_found)
1180          {
1181          length += 2;
1182          capture_last_found = TRUE;
1183          }
1184        length += 3;
1185        cc += 1 + LINK_SIZE + IMM2_SIZE;
1186        break;
1187    
1188        default:
1189        stack_restore = TRUE;
1190        /* Fall through. */
1191    
1192        case OP_NOT_WORD_BOUNDARY:
1193        case OP_WORD_BOUNDARY:
1194        case OP_NOT_DIGIT:
1195        case OP_DIGIT:
1196        case OP_NOT_WHITESPACE:
1197        case OP_WHITESPACE:
1198        case OP_NOT_WORDCHAR:
1199        case OP_WORDCHAR:
1200        case OP_ANY:
1201        case OP_ALLANY:
1202        case OP_ANYBYTE:
1203        case OP_NOTPROP:
1204        case OP_PROP:
1205        case OP_ANYNL:
1206        case OP_NOT_HSPACE:
1207        case OP_HSPACE:
1208        case OP_NOT_VSPACE:
1209        case OP_VSPACE:
1210        case OP_EXTUNI:
1211        case OP_EODN:
1212        case OP_EOD:
1213        case OP_CIRC:
1214        case OP_CIRCM:
1215        case OP_DOLL:
1216        case OP_DOLLM:
1217        case OP_CHAR:
1218        case OP_CHARI:
1219        case OP_NOT:
1220        case OP_NOTI:
1221    
1222        case OP_EXACT:
1223        case OP_POSSTAR:
1224        case OP_POSPLUS:
1225        case OP_POSQUERY:
1226        case OP_POSUPTO:
1227    
1228        case OP_EXACTI:
1229        case OP_POSSTARI:
1230        case OP_POSPLUSI:
1231        case OP_POSQUERYI:
1232        case OP_POSUPTOI:
1233    
1234        case OP_NOTEXACT:
1235        case OP_NOTPOSSTAR:
1236        case OP_NOTPOSPLUS:
1237        case OP_NOTPOSQUERY:
1238        case OP_NOTPOSUPTO:
1239    
1240        case OP_NOTEXACTI:
1241        case OP_NOTPOSSTARI:
1242        case OP_NOTPOSPLUSI:
1243        case OP_NOTPOSQUERYI:
1244        case OP_NOTPOSUPTOI:
1245    
1246      case OP_RECURSE:      case OP_TYPEEXACT:
1247      if (common->has_set_som && !setsom_found)      case OP_TYPEPOSSTAR:
1248        {      case OP_TYPEPOSPLUS:
1249        length += 2;      case OP_TYPEPOSQUERY:
1250        setsom_found = TRUE;      case OP_TYPEPOSUPTO:
       }  
     if (common->mark_ptr != 0 && !setmark_found)  
       {  
       length += 2;  
       setmark_found = TRUE;  
       }  
     cc += 1 + LINK_SIZE;  
     break;  
1251    
1252      case OP_CBRA:      case OP_CLASS:
1253      case OP_CBRAPOS:      case OP_NCLASS:
1254      case OP_SCBRA:      case OP_XCLASS:
     case OP_SCBRAPOS:  
     length += 3;  
     cc += 1 + LINK_SIZE + IMM2_SIZE;  
     break;  
1255    
     default:  
1256      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1257      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1258      break;      break;
1259      }      }
1260    
1261  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1262  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1263    return -1;    return stack_restore ? no_frame : no_stack;
1264    
1265  if (length > 0)  if (length > 0)
1266    return length + 1;    return length + 1;
1267  return -1;  return stack_restore ? no_frame : no_stack;
1268  }  }
1269    
1270  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, int stackpos, int stacktop, BOOL recursive)
1271  {  {
1272  DEFINE_COMPILER;  DEFINE_COMPILER;
1273  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1274  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1275  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1276    /* The last capture is a local variable even for recursions. */
1277    BOOL capture_last_found = FALSE;
1278  int offset;  int offset;
1279    
1280  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 888  while (cc < ccend) Line 1293  while (cc < ccend)
1293      if (!setsom_found)      if (!setsom_found)
1294        {        {
1295        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1296        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1297        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1298        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1299        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1300        setsom_found = TRUE;        setsom_found = TRUE;
1301        }        }
1302      cc += 1;      cc += 1;
# Line 902  while (cc < ccend) Line 1307  while (cc < ccend)
1307      if (!setmark_found)      if (!setmark_found)
1308        {        {
1309        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);
1310        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);
1311        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1312        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1313        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1314        setmark_found = TRUE;        setmark_found = TRUE;
1315        }        }
1316      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 915  while (cc < ccend) Line 1320  while (cc < ccend)
1320      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1321        {        {
1322        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1323        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1324        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1325        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1326        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1327        setsom_found = TRUE;        setsom_found = TRUE;
1328        }        }
1329      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1330        {        {
1331        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);
1332        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);
1333        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1334        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1335        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1336        setmark_found = TRUE;        setmark_found = TRUE;
1337        }        }
1338        if (common->capture_last_ptr != 0 && !capture_last_found)
1339          {
1340          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1341          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1342          stackpos += (int)sizeof(sljit_sw);
1343          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1344          stackpos += (int)sizeof(sljit_sw);
1345          capture_last_found = TRUE;
1346          }
1347      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1348      break;      break;
1349    
# Line 937  while (cc < ccend) Line 1351  while (cc < ccend)
1351      case OP_CBRAPOS:      case OP_CBRAPOS:
1352      case OP_SCBRA:      case OP_SCBRA:
1353      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1354        if (common->capture_last_ptr != 0 && !capture_last_found)
1355          {
1356          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1357          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1358          stackpos += (int)sizeof(sljit_sw);
1359          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1360          stackpos += (int)sizeof(sljit_sw);
1361          capture_last_found = TRUE;
1362          }
1363      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1364      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1365      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1366      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1367      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));
1368      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1369      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1370      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1371      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1372    
1373      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1374      break;      break;
# Line 956  while (cc < ccend) Line 1379  while (cc < ccend)
1379      break;      break;
1380      }      }
1381    
1382  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1383  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1384  }  }
1385    
1386  static SLJIT_INLINE int get_localsize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static SLJIT_INLINE int get_private_data_length_for_copy(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
1387  {  {
1388  int localsize = 2;  int private_data_length = 2;
1389    int size;
1390  pcre_uchar *alternative;  pcre_uchar *alternative;
1391  /* Calculate the sum of the local variables. */  /* Calculate the sum of the private machine words. */
1392  while (cc < ccend)  while (cc < ccend)
1393    {    {
1394      size = 0;
1395    switch(*cc)    switch(*cc)
1396      {      {
1397      case OP_ASSERT:      case OP_ASSERT:
# Line 979  while (cc < ccend) Line 1404  while (cc < ccend)
1404      case OP_SBRA:      case OP_SBRA:
1405      case OP_SBRAPOS:      case OP_SBRAPOS:
1406      case OP_SCOND:      case OP_SCOND:
1407      localsize++;      private_data_length++;
1408      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1409      break;      break;
1410    
1411      case OP_CBRA:      case OP_CBRA:
1412      case OP_SCBRA:      case OP_SCBRA:
1413      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1414          private_data_length++;
1415      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1416      break;      break;
1417    
1418      case OP_CBRAPOS:      case OP_CBRAPOS:
1419      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1420      localsize += 2;      private_data_length += 2;
1421      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1422      break;      break;
1423    
# Line 999  while (cc < ccend) Line 1425  while (cc < ccend)
1425      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1426      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1427      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1428        localsize++;        private_data_length++;
1429      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1430      break;      break;
1431    
1432        CASE_ITERATOR_PRIVATE_DATA_1
1433        if (PRIVATE_DATA(cc))
1434          private_data_length++;
1435        cc += 2;
1436    #ifdef SUPPORT_UTF
1437        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1438    #endif
1439        break;
1440    
1441        CASE_ITERATOR_PRIVATE_DATA_2A
1442        if (PRIVATE_DATA(cc))
1443          private_data_length += 2;
1444        cc += 2;
1445    #ifdef SUPPORT_UTF
1446        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1447    #endif
1448        break;
1449    
1450        CASE_ITERATOR_PRIVATE_DATA_2B
1451        if (PRIVATE_DATA(cc))
1452          private_data_length += 2;
1453        cc += 2 + IMM2_SIZE;
1454    #ifdef SUPPORT_UTF
1455        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1456    #endif
1457        break;
1458    
1459        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1460        if (PRIVATE_DATA(cc))
1461          private_data_length++;
1462        cc += 1;
1463        break;
1464    
1465        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1466        if (PRIVATE_DATA(cc))
1467          private_data_length += 2;
1468        cc += 1;
1469        break;
1470    
1471        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1472        if (PRIVATE_DATA(cc))
1473          private_data_length += 2;
1474        cc += 1 + IMM2_SIZE;
1475        break;
1476    
1477        case OP_CLASS:
1478        case OP_NCLASS:
1479    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1480        case OP_XCLASS:
1481        size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1482    #else
1483        size = 1 + 32 / (int)sizeof(pcre_uchar);
1484    #endif
1485        if (PRIVATE_DATA(cc))
1486          private_data_length += get_class_iterator_size(cc + size);
1487        cc += size;
1488        break;
1489    
1490      default:      default:
1491      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1492      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
# Line 1010  while (cc < ccend) Line 1494  while (cc < ccend)
1494      }      }
1495    }    }
1496  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1497  return localsize;  return private_data_length;
1498  }  }
1499    
1500  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,
1501    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop)
1502  {  {
1503  DEFINE_COMPILER;  DEFINE_COMPILER;
1504  int srcw[2];  int srcw[2];
1505  int count;  int count, size;
1506  BOOL tmp1next = TRUE;  BOOL tmp1next = TRUE;
1507  BOOL tmp1empty = TRUE;  BOOL tmp1empty = TRUE;
1508  BOOL tmp2empty = TRUE;  BOOL tmp2empty = TRUE;
# Line 1035  stacktop = STACK(stacktop - 1); Line 1519  stacktop = STACK(stacktop - 1);
1519    
1520  if (!save)  if (!save)
1521    {    {
1522    stackptr += sizeof(sljit_w);    stackptr += sizeof(sljit_sw);
1523    if (stackptr < stacktop)    if (stackptr < stacktop)
1524      {      {
1525      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1526      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1527      tmp1empty = FALSE;      tmp1empty = FALSE;
1528      }      }
1529    if (stackptr < stacktop)    if (stackptr < stacktop)
1530      {      {
1531      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1532      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1533      tmp2empty = FALSE;      tmp2empty = FALSE;
1534      }      }
1535    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
# Line 1057  while (status != end) Line 1541  while (status != end)
1541    switch(status)    switch(status)
1542      {      {
1543      case start:      case start:
1544      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1545      count = 1;      count = 1;
1546      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1547      status = loop;      status = loop;
1548      break;      break;
1549    
# Line 1083  while (status != end) Line 1567  while (status != end)
1567        case OP_SBRAPOS:        case OP_SBRAPOS:
1568        case OP_SCOND:        case OP_SCOND:
1569        count = 1;        count = 1;
1570        srcw[0] = PRIV_DATA(cc);        srcw[0] = PRIVATE_DATA(cc);
1571        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1572        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1573        break;        break;
1574    
1575        case OP_CBRA:        case OP_CBRA:
1576        case OP_SCBRA:        case OP_SCBRA:
1577        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1578        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1579            count = 1;
1580            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1581            }
1582        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1583        break;        break;
1584    
1585        case OP_CBRAPOS:        case OP_CBRAPOS:
1586        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1587        count = 2;        count = 2;
1588          srcw[0] = PRIVATE_DATA(cc);
1589        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1590        srcw[0] = PRIV_DATA(cc);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
       SLJIT_ASSERT(srcw[0] != 0);  
1591        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1592        break;        break;
1593    
# Line 1110  while (status != end) Line 1597  while (status != end)
1597        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1598          {          {
1599          count = 1;          count = 1;
1600          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1601          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1602          }          }
1603        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1604        break;        break;
1605    
1606          CASE_ITERATOR_PRIVATE_DATA_1
1607          if (PRIVATE_DATA(cc))
1608            {
1609            count = 1;
1610            srcw[0] = PRIVATE_DATA(cc);
1611            }
1612          cc += 2;
1613    #ifdef SUPPORT_UTF
1614          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1615    #endif
1616          break;
1617    
1618          CASE_ITERATOR_PRIVATE_DATA_2A
1619          if (PRIVATE_DATA(cc))
1620            {
1621            count = 2;
1622            srcw[0] = PRIVATE_DATA(cc);
1623            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1624            }
1625          cc += 2;
1626    #ifdef SUPPORT_UTF
1627          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1628    #endif
1629          break;
1630    
1631          CASE_ITERATOR_PRIVATE_DATA_2B
1632          if (PRIVATE_DATA(cc))
1633            {
1634            count = 2;
1635            srcw[0] = PRIVATE_DATA(cc);
1636            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1637            }
1638          cc += 2 + IMM2_SIZE;
1639    #ifdef SUPPORT_UTF
1640          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1641    #endif
1642          break;
1643    
1644          CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1645          if (PRIVATE_DATA(cc))
1646            {
1647            count = 1;
1648            srcw[0] = PRIVATE_DATA(cc);
1649            }
1650          cc += 1;
1651          break;
1652    
1653          CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1654          if (PRIVATE_DATA(cc))
1655            {
1656            count = 2;
1657            srcw[0] = PRIVATE_DATA(cc);
1658            srcw[1] = srcw[0] + sizeof(sljit_sw);
1659            }
1660          cc += 1;
1661          break;
1662    
1663          CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1664          if (PRIVATE_DATA(cc))
1665            {
1666            count = 2;
1667            srcw[0] = PRIVATE_DATA(cc);
1668            srcw[1] = srcw[0] + sizeof(sljit_sw);
1669            }
1670          cc += 1 + IMM2_SIZE;
1671          break;
1672    
1673          case OP_CLASS:
1674          case OP_NCLASS:
1675    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1676          case OP_XCLASS:
1677          size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1678    #else
1679          size = 1 + 32 / (int)sizeof(pcre_uchar);
1680    #endif
1681          if (PRIVATE_DATA(cc))
1682            switch(get_class_iterator_size(cc + size))
1683              {
1684              case 1:
1685              count = 1;
1686              srcw[0] = PRIVATE_DATA(cc);
1687              break;
1688    
1689              case 2:
1690              count = 2;
1691              srcw[0] = PRIVATE_DATA(cc);
1692              srcw[1] = srcw[0] + sizeof(sljit_sw);
1693              break;
1694    
1695              default:
1696              SLJIT_ASSERT_STOP();
1697              break;
1698              }
1699          cc += size;
1700          break;
1701    
1702        default:        default:
1703        cc = next_opcode(common, cc);        cc = next_opcode(common, cc);
1704        SLJIT_ASSERT(cc != NULL);        SLJIT_ASSERT(cc != NULL);
# Line 1138  while (status != end) Line 1721  while (status != end)
1721          if (!tmp1empty)          if (!tmp1empty)
1722            {            {
1723            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1724            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1725            }            }
1726          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1727          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1149  while (status != end) Line 1732  while (status != end)
1732          if (!tmp2empty)          if (!tmp2empty)
1733            {            {
1734            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1735            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1736            }            }
1737          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1738          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1166  while (status != end) Line 1749  while (status != end)
1749          if (!tmp1empty)          if (!tmp1empty)
1750            {            {
1751            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1752            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1753            }            }
1754          tmp1next = FALSE;          tmp1next = FALSE;
1755          }          }
# Line 1178  while (status != end) Line 1761  while (status != end)
1761          if (!tmp2empty)          if (!tmp2empty)
1762            {            {
1763            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1764            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1765            }            }
1766          tmp1next = TRUE;          tmp1next = TRUE;
1767          }          }
# Line 1193  if (save) Line 1776  if (save)
1776      if (!tmp1empty)      if (!tmp1empty)
1777        {        {
1778        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1779        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1780        }        }
1781      if (!tmp2empty)      if (!tmp2empty)
1782        {        {
1783        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1784        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1785        }        }
1786      }      }
1787    else    else
# Line 1206  if (save) Line 1789  if (save)
1789      if (!tmp2empty)      if (!tmp2empty)
1790        {        {
1791        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1792        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1793        }        }
1794      if (!tmp1empty)      if (!tmp1empty)
1795        {        {
1796        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1797        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1798        }        }
1799      }      }
1800    }    }
1801  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1802  }  }
1803    
1804  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  #undef CASE_ITERATOR_PRIVATE_DATA_1
1805    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1806    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1807    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1808    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1809    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1810    
1811    static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1812  {  {
1813  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1814  }  }
# Line 1228  static SLJIT_INLINE void set_jumps(jump_ Line 1818  static SLJIT_INLINE void set_jumps(jump_
1818  while (list)  while (list)
1819    {    {
1820    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1821    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1822    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1823    list = list->next;    list = list->next;
1824    }    }
1825  }  }
# Line 1245  if (list_item) Line 1835  if (list_item)
1835    }    }
1836  }  }
1837    
1838  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)
1839  {  {
1840  DEFINE_COMPILER;  DEFINE_COMPILER;
1841  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1842    
1843  if (list_item)  if (list_item)
1844    {    {
   list_item->type = type;  
   list_item->data = data;  
1845    list_item->start = start;    list_item->start = start;
1846    list_item->leave = LABEL();    list_item->quit = LABEL();
1847    list_item->next = common->stubs;    list_item->next = common->stubs;
1848    common->stubs = list_item;    common->stubs = list_item;
1849    }    }
# Line 1269  stub_list* list_item = common->stubs; Line 1857  stub_list* list_item = common->stubs;
1857  while (list_item)  while (list_item)
1858    {    {
1859    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
1860    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
1861      {    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);  
1862    list_item = list_item->next;    list_item = list_item->next;
1863    }    }
1864  common->stubs = NULL;  common->stubs = NULL;
# Line 1294  static SLJIT_INLINE void allocate_stack( Line 1877  static SLJIT_INLINE void allocate_stack(
1877  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
1878  DEFINE_COMPILER;  DEFINE_COMPILER;
1879    
1880  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));
1881  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
1882  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
1883  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1302  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 1885  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
1885  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
1886  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
1887  #endif  #endif
1888  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));
1889  }  }
1890    
1891  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
1892  {  {
1893  DEFINE_COMPILER;  DEFINE_COMPILER;
1894  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));
1895  }  }
1896    
1897  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1318  struct sljit_label *loop; Line 1901  struct sljit_label *loop;
1901  int i;  int i;
1902  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
1903  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
1904  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));
1905  if (length < 8)  if (length < 8)
1906    {    {
1907    for (i = 0; i < length; i++)    for (i = 0; i < length; i++)
1908      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);
1909    }    }
1910  else  else
1911    {    {
1912    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START - sizeof(sljit_sw));
1913    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length);
1914    loop = LABEL();    loop = LABEL();
1915    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);
1916    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);
1917    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
1918    }    }
1919  }  }
# Line 1339  static SLJIT_INLINE void copy_ovector(co Line 1922  static SLJIT_INLINE void copy_ovector(co
1922  {  {
1923  DEFINE_COMPILER;  DEFINE_COMPILER;
1924  struct sljit_label *loop;  struct sljit_label *loop;
1925  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
1926    
1927  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
1928  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));
1929  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);
1930    
1931  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
1932  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
1933    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);
1934  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));
1935  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
1936    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);
1937  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));
1938  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));
1939  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
1940  /* Unlikely, but possible */  /* Unlikely, but possible */
1941  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);
1942  loop = LABEL();  loop = LABEL();
1943  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);
1944  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));
1945  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
1946  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1947  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);
1948  #endif  #endif
1949  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);
1950  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);
1951  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
1952  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
1953    
1954  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
1955  if (topbracket > 1)  if (topbracket > 1)
1956    {    {
1957    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));
1958    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
1959    
1960    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
1961    loop = LABEL();    loop = LABEL();
1962    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)));
1963    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);
1964    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);
1965    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
1966    }    }
1967  else  else
1968    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
1969  }  }
1970    
1971  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)
1972  {  {
1973  DEFINE_COMPILER;  DEFINE_COMPILER;
1974    
1975  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);
1976  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->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
1977    
1978  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
1979  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
1980  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, offset_count));
1981  CMPTO(SLJIT_C_LESS, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2, leave);  CMPTO(SLJIT_C_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
1982    
1983  /* Store match begin and end. */  /* Store match begin and end. */
1984  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));
1985  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));
1986  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);  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);
1987  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);
1988  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1989  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);
1990  #endif  #endif
1991  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);
1992    
1993  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);
1994  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1995  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);
1996  #endif  #endif
1997  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);
1998    
1999  JUMPTO(SLJIT_JUMP, leave);  JUMPTO(SLJIT_JUMP, quit);
2000  }  }
2001    
2002  static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)  static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)
# Line 1524  if (c <= 127 && bit == 0x20) Line 2107  if (c <= 127 && bit == 0x20)
2107    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2108    
2109  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2110  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2111    return 0;    return 0;
2112    
2113  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2114    
2115  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2116  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 1543  if (common->utf && c > 127) Line 2126  if (common->utf && c > 127)
2126  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2127  return (0 << 8) | bit;  return (0 << 8) | bit;
2128    
2129  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2130    
 #ifdef COMPILE_PCRE16  
2131  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2132  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2133    {    {
# Line 1556  if (common->utf && c > 65535) Line 2138  if (common->utf && c > 65535)
2138    }    }
2139  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2140  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2141    
2142  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2143  }  }
2144    
2145  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
# Line 1656  static void read_char(compiler_common *c Line 2237  static void read_char(compiler_common *c
2237  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2238  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2239  DEFINE_COMPILER;  DEFINE_COMPILER;
2240  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2241  struct sljit_jump *jump;  struct sljit_jump *jump;
2242  #endif  #endif
2243    
2244  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2245  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2246  if (common->utf)  if (common->utf)
2247    {    {
2248  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2249    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2250  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2251    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2252  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2253    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2254    JUMPHERE(jump);    JUMPHERE(jump);
2255    }    }
2256  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2257  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));
2258  }  }
2259    
# Line 1683  static void peek_char(compiler_common *c Line 2262  static void peek_char(compiler_common *c
2262  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2263  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2264  DEFINE_COMPILER;  DEFINE_COMPILER;
2265  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2266  struct sljit_jump *jump;  struct sljit_jump *jump;
2267  #endif  #endif
2268    
2269  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2270  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2271  if (common->utf)  if (common->utf)
2272    {    {
2273  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2274    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2275  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2276    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2277  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2278    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2279    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2280    JUMPHERE(jump);    JUMPHERE(jump);
2281    }    }
2282  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2283  }  }
2284    
2285  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2286  {  {
2287  /* 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. */
2288  DEFINE_COMPILER;  DEFINE_COMPILER;
2289  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2290  struct sljit_jump *jump;  struct sljit_jump *jump;
2291  #endif  #endif
2292    
# Line 1718  if (common->utf) Line 2295  if (common->utf)
2295    {    {
2296    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2297    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));
2298  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2299    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2300    it is needed in most cases. */    it is needed in most cases. */
2301    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2302    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2303    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2304    JUMPHERE(jump);    JUMPHERE(jump);
2305  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2306    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2307    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2308    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
# Line 1734  if (common->utf) Line 2310  if (common->utf)
2310    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2311    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2312    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);
2313    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2314    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2315    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2316  #endif  #elif defined COMPILE_PCRE32
2317  #endif /* COMPILE_PCRE8 */    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2318      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2319      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2320      JUMPHERE(jump);
2321    #endif /* COMPILE_PCRE[8|16|32] */
2322    return;    return;
2323    }    }
2324  #endif  #endif /* SUPPORT_UTF */
2325  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2326  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));
2327  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2328  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2329  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2330  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2331  #endif  #endif
2332  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2333  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2334  JUMPHERE(jump);  JUMPHERE(jump);
2335  #endif  #endif
2336  }  }
# Line 1759  static void skip_char_back(compiler_comm Line 2339  static void skip_char_back(compiler_comm
2339  {  {
2340  /* 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. */
2341  DEFINE_COMPILER;  DEFINE_COMPILER;
2342  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2343    #if defined COMPILE_PCRE8
2344  struct sljit_label *label;  struct sljit_label *label;
2345    
2346  if (common->utf)  if (common->utf)
# Line 1771  if (common->utf) Line 2352  if (common->utf)
2352    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2353    return;    return;
2354    }    }
2355  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2356  if (common->utf)  if (common->utf)
2357    {    {
2358    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
# Line 1780  if (common->utf) Line 2360  if (common->utf)
2360    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2361    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2362    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);
2363    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2364    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2365    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2366    return;    return;
2367    }    }
2368  #endif  #endif /* COMPILE_PCRE[8|16] */
2369    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2370  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));
2371  }  }
2372    
# Line 1802  if (nltype == NLTYPE_ANY) Line 2383  if (nltype == NLTYPE_ANY)
2383  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2384    {    {
2385    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);
2386    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2387    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);
2388    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);
2389    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2390    }    }
2391  else  else
# Line 1816  else Line 2397  else
2397    
2398  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2399    
2400  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2401  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2402  {  {
2403  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
# Line 1904  sljit_emit_fast_return(compiler, RETURN_ Line 2485  sljit_emit_fast_return(compiler, RETURN_
2485  JUMPHERE(jump);  JUMPHERE(jump);
2486    
2487  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2488  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);
2489  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2490  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2491  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2492  }  }
2493    
2494  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
2495    
 #ifdef COMPILE_PCRE16  
2496  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2497  {  {
2498  /* 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 1937  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC Line 2517  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC
2517  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2518  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2519  }  }
 #endif /* COMPILE_PCRE16 */  
2520    
2521  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16] */
2522    
2523  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2524    
# Line 1959  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 2538  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2538    
2539  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2540  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2541  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));
2542  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2543  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2544  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2545  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2546  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2547  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));
2548  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2549  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2550  }  }
# Line 1979  struct sljit_label *newlinelabel = NULL; Line 2558  struct sljit_label *newlinelabel = NULL;
2558  struct sljit_jump *start;  struct sljit_jump *start;
2559  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2560  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2561  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2562  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2563  #endif  #endif
2564  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 1994  if (firstline) Line 2573  if (firstline)
2573    {    {
2574    /* Search for the end of the first line. */    /* Search for the end of the first line. */
2575    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
2576    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);  
2577    
2578    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
2579      {      {
# Line 2006  if (firstline) Line 2584  if (firstline)
2584      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2585      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);
2586      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);
2587        JUMPHERE(end);
2588      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));
2589      }      }
2590    else    else
# Line 2017  if (firstline) Line 2596  if (firstline)
2596      read_char(common);      read_char(common);
2597      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
2598      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2599        JUMPHERE(end);
2600      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);
2601      set_jumps(newline, LABEL());      set_jumps(newline, LABEL());
2602      }      }
2603    
2604    JUMPHERE(end);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
   OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  
2605    }    }
2606    
2607  start = JUMP(SLJIT_JUMP);  start = JUMP(SLJIT_JUMP);
# Line 2034  if (newlinecheck) Line 2613  if (newlinecheck)
2613    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2614    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2615    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);
2616    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2617  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2618    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2619  #endif  #endif
2620    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2621    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 2057  if (newlinecheck) Line 2636  if (newlinecheck)
2636    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);
2637    
2638  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));
2639  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2640    #if defined COMPILE_PCRE8
2641  if (common->utf)  if (common->utf)
2642    {    {
2643    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2644    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);
2645    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2646    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2647    }    }
2648  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2649  if (common->utf)  if (common->utf)
2650    {    {
2651    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2652    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2653    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);
2654    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2655    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2656    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2657    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2658    }    }
2659  #endif  #endif /* COMPILE_PCRE[8|16] */
2660    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2661  JUMPHERE(start);  JUMPHERE(start);
2662    
2663  if (newlinecheck)  if (newlinecheck)
2664      {
2665      JUMPHERE(end);
2666      JUMPHERE(nl);
2667      }
2668    
2669    return mainloop;
2670    }
2671    
2672    #define MAX_N_CHARS 3
2673    
2674    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2675    {
2676    DEFINE_COMPILER;
2677    struct sljit_label *start;
2678    struct sljit_jump *quit;
2679    pcre_uint32 chars[MAX_N_CHARS * 2];
2680    pcre_uchar *cc = common->start + 1 + LINK_SIZE;
2681    int location = 0;
2682    pcre_int32 len, c, bit, caseless;
2683    int must_stop;
2684    
2685    /* We do not support alternatives now. */
2686    if (*(common->start + GET(common->start, 1)) == OP_ALT)
2687      return FALSE;
2688    
2689    while (TRUE)
2690      {
2691      caseless = 0;
2692      must_stop = 1;
2693      switch(*cc)
2694        {
2695        case OP_CHAR:
2696        must_stop = 0;
2697        cc++;
2698        break;
2699    
2700        case OP_CHARI:
2701        caseless = 1;
2702        must_stop = 0;
2703        cc++;
2704        break;
2705    
2706        case OP_SOD:
2707        case OP_SOM:
2708        case OP_SET_SOM:
2709        case OP_NOT_WORD_BOUNDARY:
2710        case OP_WORD_BOUNDARY:
2711        case OP_EODN:
2712        case OP_EOD:
2713        case OP_CIRC:
2714        case OP_CIRCM:
2715        case OP_DOLL:
2716        case OP_DOLLM:
2717        /* Zero width assertions. */
2718        cc++;
2719        continue;
2720    
2721        case OP_PLUS:
2722        case OP_MINPLUS:
2723        case OP_POSPLUS:
2724        cc++;
2725        break;
2726    
2727        case OP_EXACT:
2728        cc += 1 + IMM2_SIZE;
2729        break;
2730    
2731        case OP_PLUSI:
2732        case OP_MINPLUSI:
2733        case OP_POSPLUSI:
2734        caseless = 1;
2735        cc++;
2736        break;
2737    
2738        case OP_EXACTI:
2739        caseless = 1;
2740        cc += 1 + IMM2_SIZE;
2741        break;
2742    
2743        default:
2744        must_stop = 2;
2745        break;
2746        }
2747    
2748      if (must_stop == 2)
2749          break;
2750    
2751      len = 1;
2752    #ifdef SUPPORT_UTF
2753      if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
2754    #endif
2755    
2756      if (caseless && char_has_othercase(common, cc))
2757        {
2758        caseless = char_get_othercase_bit(common, cc);
2759        if (caseless == 0)
2760          return FALSE;
2761    #ifdef COMPILE_PCRE8
2762        caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
2763    #else
2764        if ((caseless & 0x100) != 0)
2765          caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));
2766        else
2767          caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));
2768    #endif
2769        }
2770      else
2771        caseless = 0;
2772    
2773      while (len > 0 && location < MAX_N_CHARS * 2)
2774        {
2775        c = *cc;
2776        bit = 0;
2777        if (len == (caseless & 0xff))
2778          {
2779          bit = caseless >> 8;
2780          c |= bit;
2781          }
2782    
2783        chars[location] = c;
2784        chars[location + 1] = bit;
2785    
2786        len--;
2787        location += 2;
2788        cc++;
2789        }
2790    
2791      if (location >= MAX_N_CHARS * 2 || must_stop != 0)
2792        break;
2793      }
2794    
2795    /* At least two characters are required. */
2796    if (location < 2 * 2)
2797        return FALSE;
2798    
2799    if (firstline)
2800    {    {
2801    JUMPHERE(end);    SLJIT_ASSERT(common->first_line_end != 0);
2802    JUMPHERE(nl);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2803      OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2804    }    }
2805    else
2806      OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2807    
2808  return mainloop;  start = LABEL();
2809    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2810    
2811    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2812    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2813    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2814    if (chars[1] != 0)
2815      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
2816    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
2817    if (location > 2 * 2)
2818      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2819    if (chars[3] != 0)
2820      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
2821    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
2822    if (location > 2 * 2)
2823      {
2824      if (chars[5] != 0)
2825        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
2826      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);
2827      }
2828    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2829    
2830    JUMPHERE(quit);
2831    
2832    if (firstline)
2833      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2834    else
2835      OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2836    return TRUE;
2837  }  }
2838    
2839    #undef MAX_N_CHARS
2840    
2841  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)
2842  {  {
2843  DEFINE_COMPILER;  DEFINE_COMPILER;
2844  struct sljit_label *start;  struct sljit_label *start;
2845  struct sljit_jump *leave;  struct sljit_jump *quit;
2846  struct sljit_jump *found;  struct sljit_jump *found;
2847  pcre_uchar oc, bit;  pcre_uchar oc, bit;
2848    
2849  if (firstline)  if (firstline)
2850    {    {
2851    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2852      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2853    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);
2854    }    }
2855    
2856  start = LABEL();  start = LABEL();
2857  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2858  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2859    
2860  oc = first_char;  oc = first_char;
# Line 2121  if (first_char == oc) Line 2871  if (first_char == oc)
2871  else  else
2872    {    {
2873    bit = first_char ^ oc;    bit = first_char ^ oc;
2874    if (ispowerof2(bit))    if (is_powerof2(bit))
2875      {      {
2876      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
2877      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 2129  else Line 2879  else
2879    else    else
2880      {      {
2881      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);
2882      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2883      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);
2884      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);
2885      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
2886      }      }
2887    }    }
2888    
2889  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  
2890  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
2891  JUMPHERE(found);  JUMPHERE(found);
2892  JUMPHERE(leave);  JUMPHERE(quit);
2893    
2894  if (firstline)  if (firstline)
2895    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2896  }  }
2897    
2898  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 2170  DEFINE_COMPILER; Line 2901  DEFINE_COMPILER;
2901  struct sljit_label *loop;  struct sljit_label *loop;
2902  struct sljit_jump *lastchar;  struct sljit_jump *lastchar;
2903  struct sljit_jump *firstchar;  struct sljit_jump *firstchar;
2904  struct sljit_jump *leave;  struct sljit_jump *quit;
2905  struct sljit_jump *foundcr = NULL;  struct sljit_jump *foundcr = NULL;
2906  struct sljit_jump *notfoundnl;  struct sljit_jump *notfoundnl;
2907  jump_list *newline = NULL;  jump_list *newline = NULL;
2908    
2909  if (firstline)  if (firstline)
2910    {    {
2911    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2912      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2913    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);
2914    }    }
2915    
# Line 2191  if (common->nltype == NLTYPE_FIXED && co Line 2923  if (common->nltype == NLTYPE_FIXED && co
2923    
2924    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
2925    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);
2926    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
2927  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2928    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
2929  #endif  #endif
2930    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2931    
2932    loop = LABEL();    loop = LABEL();
2933    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));
2934    leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2935    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
2936    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
2937    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);
2938    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);
2939    
2940    JUMPHERE(leave);    JUMPHERE(quit);
2941    JUMPHERE(firstchar);    JUMPHERE(firstchar);
2942    JUMPHERE(lastchar);    JUMPHERE(lastchar);
2943    
# Line 2229  set_jumps(newline, loop); Line 2961  set_jumps(newline, loop);
2961    
2962  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
2963    {    {
2964    leave = JUMP(SLJIT_JUMP);    quit = JUMP(SLJIT_JUMP);
2965    JUMPHERE(foundcr);    JUMPHERE(foundcr);
2966    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2967    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2968    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);
2969    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2970  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2971    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2972  #endif  #endif
2973    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2974    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
2975    JUMPHERE(leave);    JUMPHERE(quit);
2976    }    }
2977  JUMPHERE(lastchar);  JUMPHERE(lastchar);
2978  JUMPHERE(firstchar);  JUMPHERE(firstchar);
2979    
2980  if (firstline)  if (firstline)
2981    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2982  }  }
2983    
2984    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
2985    
2986  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)
2987  {  {
2988  DEFINE_COMPILER;  DEFINE_COMPILER;
2989  struct sljit_label *start;  struct sljit_label *start;
2990  struct sljit_jump *leave;  struct sljit_jump *quit;
2991  struct sljit_jump *found;  struct sljit_jump *found = NULL;
2992    jump_list *matches = NULL;
2993    pcre_uint8 inverted_start_bits[32];
2994    int i;
2995  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
2996  struct sljit_jump *jump;  struct sljit_jump *jump;
2997  #endif  #endif
2998    
2999    for (i = 0; i < 32; ++i)
3000      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3001    
3002  if (firstline)  if (firstline)
3003    {    {
3004    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3005      OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
3006    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);
3007    }    }
3008    
3009  start = LABEL();  start = LABEL();
3010  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3011  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3012  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3013  if (common->utf)  if (common->utf)
3014    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3015  #endif  #endif
3016    
3017    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3018      {
3019  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3020  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3021  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3022  JUMPHERE(jump);    JUMPHERE(jump);
3023  #endif  #endif
3024  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3025  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3026  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3027  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3028  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);
3029  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3030      }
3031    
3032  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3033  if (common->utf)  if (common->utf)
3034    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3035  #endif  #endif
3036  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));
3037  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3038    #if defined COMPILE_PCRE8
3039  if (common->utf)  if (common->utf)
3040    {    {
3041    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3042    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);
3043    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3044    }    }
3045  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3046  if (common->utf)  if (common->utf)
3047    {    {
3048    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3049    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3050    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);
3051    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3052    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3053    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3054    }    }
3055  #endif  #endif /* COMPILE_PCRE[8|16] */
3056    #endif /* SUPPORT_UTF */
3057  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3058  JUMPHERE(found);  if (found != NULL)
3059  JUMPHERE(leave);    JUMPHERE(found);
3060    if (matches != NULL)
3061      set_jumps(matches, LABEL());
3062    JUMPHERE(quit);
3063    
3064  if (firstline)  if (firstline)
3065    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0);
3066  }  }
3067    
3068  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 2325  struct sljit_jump *alreadyfound; Line 3074  struct sljit_jump *alreadyfound;
3074  struct sljit_jump *found;  struct sljit_jump *found;
3075  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3076  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3077  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3078    
3079  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3080  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 2356  if (req_char == oc) Line 3105  if (req_char == oc)
3105  else  else
3106    {    {
3107    bit = req_char ^ oc;    bit = req_char ^ oc;
3108    if (ispowerof2(bit))    if (is_powerof2(bit))
3109      {      {
3110      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3111      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 2392  GET_LOCAL_BASE(TMP3, 0, 0); Line 3141  GET_LOCAL_BASE(TMP3, 0, 0);
3141  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3142  mainloop = LABEL();  mainloop = LABEL();
3143  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3144  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);
3145    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3146    
3147  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3148  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3149  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_w), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
3150  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw));
3151  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3152    
3153  JUMPHERE(jump);  JUMPHERE(jump);
3154  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3155  /* End of dropping frames. */  /* End of dropping frames. */
3156  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3157    
3158  JUMPHERE(jump);  JUMPHERE(jump);
3159  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3160  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3161  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3162  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));  
3163  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3164  }  }
3165    
# Line 2458  if (common->use_ucp) Line 3192  if (common->use_ucp)
3192    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3193    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3194    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);
3195    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3196    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);
3197    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);
3198    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3199    JUMPHERE(jump);    JUMPHERE(jump);
3200    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3201    }    }
# Line 2502  if (common->use_ucp) Line 3236  if (common->use_ucp)
3236    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3237    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3238    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);
3239    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3240    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);
3241    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);
3242    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3243    JUMPHERE(jump);    JUMPHERE(jump);
3244    }    }
3245  else  else
# Line 2537  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSE Line 3271  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSE
3271  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3272  }  }
3273    
3274    /*
3275      range format:
3276    
3277      ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).
3278      ranges[1] = first bit (0 or 1)
3279      ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)
3280    */
3281    
3282    static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)
3283    {
3284    DEFINE_COMPILER;
3285    struct sljit_jump *jump;
3286    
3287    if (ranges[0] < 0)
3288      return FALSE;
3289    
3290    switch(ranges[0])
3291      {
3292      case 1:
3293      if (readch)
3294        read_char(common);
3295      add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3296      return TRUE;
3297    
3298      case 2:
3299      if (readch)
3300        read_char(common);
3301      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3302      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3303      return TRUE;
3304    
3305      case 4:
3306      if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])
3307        {
3308        if (readch)
3309          read_char(common);
3310        if (ranges[1] != 0)
3311          {
3312          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3313          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3314          }
3315        else
3316          {
3317          jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);
3318          add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3319          JUMPHERE(jump);
3320          }
3321        return TRUE;
3322        }
3323      if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))
3324        {
3325        if (readch)
3326          read_char(common);
3327        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);
3328        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3329        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3330        return TRUE;
3331        }
3332      return FALSE;
3333    
3334      default:
3335      return FALSE;
3336      }
3337    }
3338    
3339    static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)
3340    {
3341    int i, bit, length;
3342    const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;
3343    
3344    bit = ctypes[0] & flag;
3345    ranges[0] = -1;
3346    ranges[1] = bit != 0 ? 1 : 0;
3347    length = 0;
3348    
3349    for (i = 1; i < 256; i++)
3350      if ((ctypes[i] & flag) != bit)
3351        {
3352        if (length >= MAX_RANGE_SIZE)
3353          return;
3354        ranges[2 + length] = i;
3355        length++;
3356        bit ^= flag;
3357        }
3358    
3359    if (bit != 0)
3360      {
3361      if (length >= MAX_RANGE_SIZE)
3362        return;
3363      ranges[2 + length] = 256;
3364      length++;
3365      }
3366    ranges[0] = length;
3367    }
3368    
3369    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)
3370    {
3371    int ranges[2 + MAX_RANGE_SIZE];
3372    pcre_uint8 bit, cbit, all;
3373    int i, byte, length = 0;
3374    
3375    bit = bits[0] & 0x1;
3376    ranges[1] = bit;
3377    /* Can be 0 or 255. */
3378    all = -bit;
3379    
3380    for (i = 0; i < 256; )
3381      {
3382      byte = i >> 3;
3383      if ((i & 0x7) == 0 && bits[byte] == all)
3384        i += 8;
3385      else
3386        {
3387        cbit = (bits[byte] >> (i & 0x7)) & 0x1;
3388        if (cbit != bit)
3389          {
3390          if (length >= MAX_RANGE_SIZE)
3391            return FALSE;
3392          ranges[2 + length] = i;
3393          length++;
3394          bit = cbit;
3395          all = -cbit;
3396          }
3397        i++;
3398        }
3399      }
3400    
3401    if (((bit == 0) && nclass) || ((bit == 1) && !nclass))
3402      {
3403      if (length >= MAX_RANGE_SIZE)
3404        return FALSE;
3405      ranges[2 + length] = 256;
3406      length++;
3407      }
3408    ranges[0] = length;
3409    
3410    return check_ranges(common, ranges, backtracks, FALSE);
3411    }
3412    
3413  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
3414  {  {
3415  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
# Line 2546  sljit_emit_fast_enter(compiler, RETURN_A Line 3419  sljit_emit_fast_enter(compiler, RETURN_A
3419    
3420  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3421  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);
3422  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3423  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);
3424  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3425  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3426  if (common->utf)  if (common->utf)
3427    {    {
3428  #endif  #endif
3429    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3430    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3431    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);
3432  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3433    }    }
3434  #endif  #endif
3435  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3436  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);
3437  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3438  }  }
3439    
# Line 2572  DEFINE_COMPILER; Line 3445  DEFINE_COMPILER;
3445  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3446    
3447  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09);
3448  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3449  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
3450  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3451  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0);
3452  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3453  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3454  if (common->utf)  if (common->utf)
3455    {    {
3456  #endif  #endif
3457    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3458    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680);
3459    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3460    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e);
3461    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3462    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3463    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000);
3464    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3465    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000);
3466    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3467    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);
3468    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3469    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000);
3470  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3471    }    }
3472  #endif  #endif
3473  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3474  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);
3475    
3476  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3477  }  }
# Line 2612  sljit_emit_fast_enter(compiler, RETURN_A Line 3485  sljit_emit_fast_enter(compiler, RETURN_A
3485    
3486  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3487  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);
3488  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3489  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);
3490  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3491  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3492  if (common->utf)  if (common->utf)
3493    {    {
3494  #endif  #endif
3495    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);
3496    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3497    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);
3498  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3499    }    }
3500  #endif  #endif
3501  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3502  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);
3503    
3504  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3505  }  }
# Line 2712  sljit_emit_fast_return(compiler, RETURN_ Line 3585  sljit_emit_fast_return(compiler, RETURN_
3585    
3586  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3587    
3588  static const pcre_uchar *SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1)  static const pcre_uchar * SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1)
3589  {  {
3590  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3591  int c1, c2;  pcre_uint32 c1, c2;
3592  const pcre_uchar *src2 = args->uchar_ptr;  const pcre_uchar *src2 = args->uchar_ptr;
3593  const pcre_uchar *end2 = args->end;  const pcre_uchar *end2 = args->end;
3594    const ucd_record *ur;
3595    const pcre_uint32 *pp;
3596    
3597  while (src1 < end1)  while (src1 < end1)
3598    {    {
# Line 2725  while (src1 < end1) Line 3600  while (src1 < end1)
3600      return (pcre_uchar*)1;      return (pcre_uchar*)1;
3601    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
3602    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
3603    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return NULL;    ur = GET_UCD(c2);
3604      if (c1 != c2 && c1 != c2 + ur->other_case)
3605        {
3606        pp = PRIV(ucd_caseless_sets) + ur->caseset;
3607        for (;;)
3608          {
3609          if (c1 < *pp) return NULL;
3610          if (c1 == *pp++) break;
3611          }
3612        }
3613    }    }
3614  return src2;  return src2;
3615  }  }
# Line 2747  if (caseless && char_has_othercase(commo Line 3631  if (caseless && char_has_othercase(commo
3631    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
3632    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
3633    /* Extracting bit difference info. */    /* Extracting bit difference info. */
3634  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3635    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
3636    othercasebit &= 0xff;    othercasebit &= 0xff;
3637  #else  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3638  #ifdef COMPILE_PCRE16    /* Note that this code only handles characters in the BMP. If there
3639      ever are characters outside the BMP whose othercase differs in only one
3640      bit from itself (there currently are none), this code will need to be
3641      revised for COMPILE_PCRE32. */
3642    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
3643    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
3644      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
3645    else    else
3646      othercasebit &= 0xff;      othercasebit &= 0xff;
3647  #endif  #endif /* COMPILE_PCRE[8|16|32] */
 #endif  
3648    }    }
3649    
3650  if (context->sourcereg == -1)  if (context->sourcereg == -1)
3651    {    {
3652  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3653  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3654    if (context->length >= 4)    if (context->length >= 4)
3655      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
# Line 2772  if (context->sourcereg == -1) Line 3658  if (context->sourcereg == -1)
3658    else    else
3659  #endif  #endif
3660      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3661  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
3662  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3663    if (context->length >= 4)    if (context->length >= 4)
3664      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3665    else    else
3666  #endif  #endif
3667      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3668  #endif  #elif defined COMPILE_PCRE32
3669  #endif /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3670    #endif /* COMPILE_PCRE[8|16|32] */
3671    context->sourcereg = TMP2;    context->sourcereg = TMP2;
3672    }    }
3673    
# Line 2795  do Line 3681  do
3681  #endif  #endif
3682    
3683    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3684  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3685    
3686    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3687    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 2810  do Line 3696  do
3696      }      }
3697    context->ucharptr++;    context->ucharptr++;
3698    
3699  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3700    if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1))    if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1))
3701  #else  #else
3702    if (context->ucharptr >= 2 || context->length == 0)    if (context->ucharptr >= 2 || context->length == 0)
# Line 2818  do Line 3704  do
3704      {      {
3705      if (context->length >= 4)      if (context->length >= 4)
3706        OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
 #ifdef COMPILE_PCRE8  
3707      else if (context->length >= 2)      else if (context->length >= 2)
3708        OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3709    #if defined COMPILE_PCRE8
3710      else if (context->length >= 1)      else if (context->length >= 1)
3711        OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3712  #else  #endif /* COMPILE_PCRE8 */
     else if (context->length >= 2)  
       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
3713      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3714    
3715      switch(context->ucharptr)      switch(context->ucharptr)
# Line 2860  do Line 3743  do
3743    
3744  #else  #else
3745    
3746    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3747  #ifdef COMPILE_PCRE8    if (context->length >= 1)
3748    if (context->length > 0)      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3749      OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #else  
   if (context->length > 0)  
     OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
3750    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3751    
3752    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 2912  return cc; Line 3791  return cc;
3791      } \      } \
3792    charoffset = (value);    charoffset = (value);
3793    
3794  static void compile_xclass_trypath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)  static void compile_xclass_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)
3795  {  {
3796  DEFINE_COMPILER;  DEFINE_COMPILER;
3797  jump_list *found = NULL;  jump_list *found = NULL;
3798  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;
3799  unsigned int c;  pcre_int32 c, charoffset;
3800  int compares;  const pcre_uint32 *other_cases;
3801  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
3802  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
3803    int compares, invertcmp, numberofcmps;
3804  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3805  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
3806  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
3807  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
3808  unsigned int typeoffset;  pcre_int32 typeoffset;
3809  #endif  #endif
 int invertcmp, numberofcmps;  
 unsigned int charoffset;  
3810    
3811  /* Although SUPPORT_UTF must be defined, we are not necessary in utf mode. */  /* Although SUPPORT_UTF must be defined, we are
3812       not necessary in utf mode even in 8 bit mode. */
3813  detect_partial_match(common, backtracks);  detect_partial_match(common, backtracks);
3814  read_char(common);  read_char(common);
3815    
# Line 2944  if ((*cc++ & XCL_MAP) != 0) Line 3823  if ((*cc++ & XCL_MAP) != 0)
3823      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3824  #endif  #endif
3825    
3826    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, list))
3827    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      {
3828    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3829    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3830    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
3831    add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3832        OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
3833        add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
3834        }
3835    
3836  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3837    JUMPHERE(jump);    JUMPHERE(jump);
# Line 3022  while (*cc != XCL_END) Line 3904  while (*cc != XCL_END)
3904        needschar = TRUE;        needschar = TRUE;
3905        break;        break;
3906    
3907          case PT_CLIST:
3908          needschar = TRUE;
3909          break;
3910    
3911        default:        default:
3912        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
3913        break;        break;
# Line 3058  if (needstype || needsscript) Line 3944  if (needstype || needsscript)
3944      {      {
3945      if (scriptreg == TMP1)      if (scriptreg == TMP1)
3946        {        {
3947        OP1(SLJIT_MOV, scriptreg, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));        OP1(SLJIT_MOV, scriptreg, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));
3948        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
3949        }        }
3950      else      else
3951        {        {
3952        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
3953        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));
3954        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
3955        }        }
3956      }      }
# Line 3100  while (*cc != XCL_END) Line 3986  while (*cc != XCL_END)
3986      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
3987        {        {
3988        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
3989        COND_VALUE(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, numberofcmps == 0 ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_EQUAL);
3990        numberofcmps++;        numberofcmps++;
3991        }        }
3992      else if (numberofcmps > 0)      else if (numberofcmps > 0)
3993        {        {
3994        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
3995        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);
3996        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
3997        numberofcmps = 0;        numberofcmps = 0;
3998        }        }
# Line 3139  while (*cc != XCL_END) Line 4025  while (*cc != XCL_END)
4025      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4026        {        {
4027        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
4028        COND_VALUE(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, numberofcmps == 0 ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_LESS_EQUAL);
4029        numberofcmps++;        numberofcmps++;
4030        }        }
4031      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4032        {        {
4033        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
4034        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4035        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4036        numberofcmps = 0;        numberofcmps = 0;
4037        }        }
# Line 3176  while (*cc != XCL_END) Line 4062  while (*cc != XCL_END)
4062    
4063        case PT_LAMP:        case PT_LAMP:
4064        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - typeoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - typeoffset);
4065        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4066        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ll - typeoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ll - typeoffset);
4067        COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4068        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lt - typeoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lt - typeoffset);
4069        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);
4070        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4071        break;        break;
4072    
# Line 3207  while (*cc != XCL_END) Line 4093  while (*cc != XCL_END)
4093          }          }
4094        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4095        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 13 - 9);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 13 - 9);
4096        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4097        if (*cc == PT_SPACE)        if (*cc == PT_SPACE)
4098          JUMPHERE(jump);          JUMPHERE(jump);
4099    
4100        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4101        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl);
4102        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4103        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4104        break;        break;
4105    
4106        case PT_WORD:        case PT_WORD:
4107        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE - charoffset);
4108        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4109        /* ... fall through */        /* Fall through. */
4110    
4111        case PT_ALNUM:        case PT_ALNUM:
4112        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
4113        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
4114        COND_VALUE((*cc == PT_ALNUM) ? SLJIT_MOV : SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS((*cc == PT_ALNUM) ? SLJIT_MOV : SLJIT_OR, TMP2, 0, (*cc == PT_ALNUM) ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_LESS_EQUAL);
4115        SET_TYPE_OFFSET(ucp_Nd);        SET_TYPE_OFFSET(ucp_Nd);
4116        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_No - ucp_Nd);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_No - ucp_Nd);
4117        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4118          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4119          break;
4120    
4121          case PT_CLIST:
4122          other_cases = PRIV(ucd_caseless_sets) + cc[1];
4123    
4124          /* At least three characters are required.
4125             Otherwise this case would be handled by the normal code path. */
4126          SLJIT_ASSERT(other_cases[0] != NOTACHAR && other_cases[1] != NOTACHAR && other_cases[2] != NOTACHAR);
4127          SLJIT_ASSERT(other_cases[0] < other_cases[1] && other_cases[1] < other_cases[2]);
4128    
4129          /* Optimizing character pairs, if their difference is power of 2. */
4130          if (is_powerof2(other_cases[1] ^ other_cases[0]))
4131            {
4132            if (charoffset == 0)
4133              OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4134            else
4135              {
4136              OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4137              OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4138              }
4139            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[1]);
4140            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4141            other_cases += 2;
4142            }
4143          else if (is_powerof2(other_cases[2] ^ other_cases[1]))
4144            {
4145            if (charoffset == 0)
4146              OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[2] ^ other_cases[1]);
4147            else
4148              {
4149              OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4150              OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4151              }
4152            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[2]);
4153            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4154    
4155            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, other_cases[0] - charoffset);
4156            OP_FLAGS(SLJIT_OR | ((other_cases[3] == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4157    
4158            other_cases += 3;
4159            }
4160          else
4161            {
4162            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4163            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4164            }
4165    
4166          while (*other_cases != NOTACHAR)
4167            {
4168            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4169            OP_FLAGS(SLJIT_OR | ((*other_cases == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4170            }
4171        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4172        break;        break;
4173        }        }
# Line 3249  if (found != NULL) Line 4188  if (found != NULL)
4188    
4189  #endif  #endif
4190    
4191  static pcre_uchar *compile_char1_trypath(compiler_common *common, pcre_uchar type, pcre_uchar *cc, jump_list **backtracks)  static pcre_uchar *compile_char1_matchingpath(compiler_common *common, pcre_uchar type, pcre_uchar *cc, jump_list **backtracks)
4192  {  {
4193  DEFINE_COMPILER;  DEFINE_COMPILER;
4194  int length;  int length;
# Line 3285  switch(type) Line 4224  switch(type)
4224    
4225    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
4226    case OP_DIGIT:    case OP_DIGIT:
4227      /* Digits are usually 0-9, so it is worth to optimize them. */
4228      if (common->digits[0] == -2)
4229        get_ctype_ranges(common, ctype_digit, common->digits);
4230    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4231    read_char8_type(common);    /* Flip the starting bit in the negative case. */
4232    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);    if (type == OP_NOT_DIGIT)
4233    add_jump(compiler, backtracks, JUMP(type == OP_DIGIT ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));      common->digits[1] ^= 1;
4234      if (!check_ranges(common, common->digits, backtracks, TRUE))
4235        {
4236        read_char8_type(common);
4237        OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);
4238        add_jump(compiler, backtracks, JUMP(type == OP_DIGIT ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
4239        }
4240      if (type == OP_NOT_DIGIT)
4241        common->digits[1] ^= 1;
4242    return cc;    return cc;
4243    
4244    case OP_NOT_WHITESPACE:    case OP_NOT_WHITESPACE:
# Line 3335  switch(type) Line 4285  switch(type)
4285      {      {
4286      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4287      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));
4288  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16
4289    #if defined COMPILE_PCRE8
4290      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4291      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);
4292      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4293  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
4294      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
4295      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
4296      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);
4297      COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4298      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4299      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4300  #endif /* COMPILE_PCRE16 */  #endif
 #endif /* COMPILE_PCRE8 */  
4301      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4302    #endif /* COMPILE_PCRE[8|16] */
4303      return cc;      return cc;
4304      }      }
4305  #endif  #endif
# Line 3370  switch(type) Line 4320  switch(type)
4320    propdata[2] = cc[0];    propdata[2] = cc[0];
4321    propdata[3] = cc[1];    propdata[3] = cc[1];
4322    propdata[4] = XCL_END;    propdata[4] = XCL_END;
4323    compile_xclass_trypath(common, propdata, backtracks);    compile_xclass_matchingpath(common, propdata, backtracks);
4324    return cc + 2;    return cc + 2;
4325  #endif  #endif
4326  #endif  #endif
# Line 3416  switch(type) Line 4366  switch(type)
4366    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4367    read_char(common);    read_char(common);
4368    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4369    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Mc);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));
4370    add_jump(compiler, backtracks, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, ucp_Mn - ucp_Mc));    /* Optimize register allocation: use a real register. */
4371      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
4372      OP1(SLJIT_MOV_UB, STACK_TOP, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4373    
4374    label = LABEL();    label = LABEL();
4375    jump[0] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    jump[0] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
4376    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
4377    read_char(common);    read_char(common);
4378    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4379    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Mc);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));
4380    CMPTO(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, ucp_Mn - ucp_Mc, label);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4381    
4382      OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);
4383      OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STACK_TOP), (sljit_sw)PRIV(ucp_gbtable));
4384      OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);
4385      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4386      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4387      JUMPTO(SLJIT_C_NOT_ZERO, label);
4388    
4389    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
4390    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4391      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
4392    
4393    if (common->mode == JIT_PARTIAL_HARD_COMPILE)    if (common->mode == JIT_PARTIAL_HARD_COMPILE)
4394      {      {
4395      jump[0] = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);      jump[0] = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
# Line 3452  switch(type) Line 4413  switch(type)
4413        {        {
4414        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);
4415        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP2, 0, STR_END, 0);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP2, 0, STR_END, 0);
4416        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS);
4417        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);
4418        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_NOT_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_NOT_EQUAL);
4419        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));
4420        check_partial(common, TRUE);        check_partial(common, TRUE);
4421        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
# Line 3554  switch(type) Line 4515  switch(type)
4515    add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));    add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
4516    
4517    if (!common->endonly)    if (!common->endonly)
4518      compile_char1_trypath(common, OP_EODN, cc, backtracks);      compile_char1_matchingpath(common, OP_EODN, cc, backtracks);
4519    else    else
4520      {      {
4521      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0));      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0));
# Line 3634  switch(type) Line 4595  switch(type)
4595      }      }
4596    oc = char_othercase(common, c);    oc = char_othercase(common, c);
4597    bit = c ^ oc;    bit = c ^ oc;
4598    if (ispowerof2(bit))    if (is_powerof2(bit))
4599      {      {
4600      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4601      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));
4602      return cc + length;      return cc + length;
4603      }      }
4604    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c);
4605    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4606    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, char_othercase(common, c));    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);
4607    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);
4608    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
4609    return cc + length;    return cc + length;
4610    
# Line 3670  switch(type) Line 4631  switch(type)
4631        /* Skip the variable-length character. */        /* Skip the variable-length character. */
4632        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));
4633        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4634        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
4635        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4636        JUMPHERE(jump[0]);        JUMPHERE(jump[0]);
4637        return cc + 1;        return cc + 1;
# Line 3695  switch(type) Line 4656  switch(type)
4656      {      {
4657      oc = char_othercase(common, c);      oc = char_othercase(common, c);
4658      bit = c ^ oc;      bit = c ^ oc;
4659      if (ispowerof2(bit))      if (is_powerof2(bit))
4660        {        {
4661        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4662        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));
# Line 3712  switch(type) Line 4673  switch(type)
4673    case OP_NCLASS:    case OP_NCLASS:
4674    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4675    read_char(common);    read_char(common);
4676      if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, backtracks))
4677        return cc + 32 / sizeof(pcre_uchar);
4678    
4679  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4680    jump[0] = NULL;    jump[0] = NULL;
4681  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
# Line 3730  switch(type) Line 4694  switch(type)
4694  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4695    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4696    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4697    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4698    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4699    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);
4700    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 3740  switch(type) Line 4704  switch(type)
4704  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4705    return cc + 32 / sizeof(pcre_uchar);    return cc + 32 / sizeof(pcre_uchar);
4706    
4707  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4708    case OP_XCLASS:    case OP_XCLASS:
4709    compile_xclass_trypath(common, cc + LINK_SIZE, backtracks);    compile_xclass_matchingpath(common, cc + LINK_SIZE, backtracks);
4710    return cc + GET(cc, 0) - 1;    return cc + GET(cc, 0) - 1;
4711  #endif  #endif
4712    
# Line 3776  SLJIT_ASSERT_STOP(); Line 4740  SLJIT_ASSERT_STOP();
4740  return cc;  return cc;
4741  }  }
4742    
4743  static SLJIT_INLINE pcre_uchar *compile_charn_trypath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, jump_list **backtracks)  static SLJIT_INLINE pcre_uchar *compile_charn_matchingpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, jump_list **backtracks)
4744  {  {
4745  /* This function consumes at least one input character. */  /* This function consumes at least one input character. */
4746  /* To decrease the number of length checks, we try to concatenate the fixed length character sequences. */  /* To decrease the number of length checks, we try to concatenate the fixed length character sequences. */
# Line 3839  if (context.length > 0) Line 4803  if (context.length > 0)
4803    }    }
4804    
4805  /* A non-fixed length character will be checked if length == 0. */  /* A non-fixed length character will be checked if length == 0. */
4806  return compile_char1_trypath(common, *cc, cc + 1, backtracks);  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);
4807  }  }
4808    
4809  static struct sljit_jump *compile_ref_checks(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)  static struct sljit_jump *compile_ref_checks(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)
# Line 3854  if (!common->jscript_compat) Line 4818  if (!common->jscript_compat)
4818      {      {
4819      /* OVECTOR(1) contains the "string begin - 1" constant. */      /* OVECTOR(1) contains the "string begin - 1" constant. */
4820      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
4821      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4822      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
4823      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);
4824      return JUMP(SLJIT_C_NOT_ZERO);      return JUMP(SLJIT_C_NOT_ZERO);
4825      }      }
4826    add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));    add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
# Line 3865  return CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT Line 4829  return CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT
4829  }  }
4830    
4831  /* Forward definitions. */  /* Forward definitions. */
4832  static void compile_trypath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);
4833  static void compile_backtrackpath(compiler_common *, struct backtrack_common *);  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);
4834    
4835  #define PUSH_BACKTRACK(size, ccstart, error) \  #define PUSH_BACKTRACK(size, ccstart, error) \
4836    do \    do \
# Line 3896  static void compile_backtrackpath(compil Line 4860  static void compile_backtrackpath(compil
4860    
4861  #define BACKTRACK_AS(type) ((type *)backtrack)  #define BACKTRACK_AS(type) ((type *)backtrack)
4862    
4863  static pcre_uchar *compile_ref_trypath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)  static pcre_uchar *compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)
4864  {  {
4865  DEFINE_COMPILER;  DEFINE_COMPILER;
4866  int offset = GET2(cc, 1) << 1;  int offset = GET2(cc, 1) << 1;
# Line 3912  if (withchecks && !common->jscript_compa Line 4876  if (withchecks && !common->jscript_compa
4876  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
4877  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
4878    {    {
4879    SLJIT_ASSERT(TMP1 == SLJIT_TEMPORARY_REG1 && STACK_TOP == SLJIT_TEMPORARY_REG2 && TMP2 == SLJIT_TEMPORARY_REG3);    SLJIT_ASSERT(TMP1 == SLJIT_SCRATCH_REG1 && STACK_TOP == SLJIT_SCRATCH_REG2 && TMP2 == SLJIT_SCRATCH_REG3);
4880    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));
4881    if (withchecks)    if (withchecks)
4882      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
4883    
4884    /* Needed to save important temporary registers. */    /* Needed to save important temporary registers. */
4885    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
4886    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
4887    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, uchar_ptr), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, uchar_ptr), STR_PTR, 0);
4888    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_utf_caselesscmp));    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_utf_caselesscmp));
4889    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
4890    if (common->mode == JIT_COMPILE)    if (common->mode == JIT_COMPILE)
# Line 3978  if (jump != NULL) Line 4942  if (jump != NULL)
4942  return cc + 1 + IMM2_SIZE;  return cc + 1 + IMM2_SIZE;
4943  }  }
4944    
4945  static SLJIT_INLINE pcre_uchar *compile_ref_iterator_trypath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)  static SLJIT_INLINE pcre_uchar *compile_ref_iterator_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
4946  {  {
4947  DEFINE_COMPILER;  DEFINE_COMPILER;
4948  backtrack_common *backtrack;  backtrack_common *backtrack;