/[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 995 by zherczeg, Wed Jul 11 11:05:30 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 *quit;    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  #define MAX_RANGE_SIZE 6
# Line 274  typedef struct compiler_common { Line 284  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 291  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    /* Flipped and lower case tables. */    /* 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. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
314    int mode;    int mode;
315    /* Newline control. */    /* Newline control. */
# Line 305  typedef struct compiler_common { Line 320  typedef struct compiler_common {
320    int endonly;    int endonly;
321    BOOL has_set_som;    BOOL has_set_som;
322    /* Tables. */    /* Tables. */
323    sljit_w ctypes;    sljit_sw ctypes;
324    int digits[2 + MAX_RANGE_SIZE];    int digits[2 + MAX_RANGE_SIZE];
325    /* Named capturing brackets. */    /* 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 *quitlabel;    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 *quit;    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 337  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 355  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 449  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 469  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 497  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 509  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 532  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 551  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;  
659    
660    case OP_CRRANGE:    case OP_ANYBYTE:
661    case OP_CRMINRANGE:  #ifdef SUPPORT_UTF
662    return cc + 1 + 2 * IMM2_SIZE;    if (common->utf) return NULL;
663    #endif
664    case OP_CLASS:    return cc + 1;
   case OP_NCLASS:  
   return cc + 1 + 32 / sizeof(pcre_uchar);  
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 675  switch(*cc) Line 676  switch(*cc)
676    }    }
677  }  }
678    
679  #define CASE_ITERATOR_LOCAL1 \  #define CASE_ITERATOR_PRIVATE_DATA_1 \
680      case OP_MINSTAR: \      case OP_MINSTAR: \
681      case OP_MINPLUS: \      case OP_MINPLUS: \
682      case OP_QUERY: \      case OP_QUERY: \
# Line 693  switch(*cc) Line 694  switch(*cc)
694      case OP_NOTQUERYI: \      case OP_NOTQUERYI: \
695      case OP_NOTMINQUERYI:      case OP_NOTMINQUERYI:
696    
697  #define CASE_ITERATOR_LOCAL2A \  #define CASE_ITERATOR_PRIVATE_DATA_2A \
698      case OP_STAR: \      case OP_STAR: \
699      case OP_PLUS: \      case OP_PLUS: \
700      case OP_STARI: \      case OP_STARI: \
# Line 703  switch(*cc) Line 704  switch(*cc)
704      case OP_NOTSTARI: \      case OP_NOTSTARI: \
705      case OP_NOTPLUSI:      case OP_NOTPLUSI:
706    
707  #define CASE_ITERATOR_LOCAL2B \  #define CASE_ITERATOR_PRIVATE_DATA_2B \
708      case OP_UPTO: \      case OP_UPTO: \
709      case OP_MINUPTO: \      case OP_MINUPTO: \
710      case OP_UPTOI: \      case OP_UPTOI: \
# Line 713  switch(*cc) Line 714  switch(*cc)
714      case OP_NOTUPTOI: \      case OP_NOTUPTOI: \
715      case OP_NOTMINUPTOI:      case OP_NOTMINUPTOI:
716    
717  #define CASE_ITERATOR_TYPE_LOCAL1 \  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
718      case OP_TYPEMINSTAR: \      case OP_TYPEMINSTAR: \
719      case OP_TYPEMINPLUS: \      case OP_TYPEMINPLUS: \
720      case OP_TYPEQUERY: \      case OP_TYPEQUERY: \
721      case OP_TYPEMINQUERY:      case OP_TYPEMINQUERY:
722    
723  #define CASE_ITERATOR_TYPE_LOCAL2A \  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
724      case OP_TYPESTAR: \      case OP_TYPESTAR: \
725      case OP_TYPEPLUS:      case OP_TYPEPLUS:
726    
727  #define CASE_ITERATOR_TYPE_LOCAL2B \  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
728      case OP_TYPEUPTO: \      case OP_TYPEUPTO: \
729      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
730    
# Line 752  switch(*cc) Line 753  switch(*cc)
753    }    }
754  }  }
755    
756  static int get_localspace(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
757  {  {
758  int localspace = 0;  int private_data_length = 0;
759  pcre_uchar *alternative;  pcre_uchar *alternative;
760    pcre_uchar *name;
761  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
762  int space, size, bracketlen;  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)
# Line 772  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 781  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);
     localspace += sizeof(sljit_w);  
794      bracketlen = 1 + LINK_SIZE;      bracketlen = 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        common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
801      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      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          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;      bracketlen = 1 + LINK_SIZE;
821      break;      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;
849    
850      case OP_BRA:      case OP_BRA:
851      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
852      break;      break;
# Line 809  while (cc < ccend) Line 856  while (cc < ccend)
856      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
857      break;      break;
858    
859      CASE_ITERATOR_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
860      space = 1;      space = 1;
861      size = -2;      size = -2;
862      break;      break;
863    
864      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
865      space = 2;      space = 2;
866      size = -2;      size = -2;
867      break;      break;
868    
869      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
870      space = 2;      space = 2;
871      size = -(2 + IMM2_SIZE);      size = -(2 + IMM2_SIZE);
872      break;      break;
873    
874      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
875      space = 1;      space = 1;
876      size = 1;      size = 1;
877      break;      break;
878    
879      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
880      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
881        space = 2;        space = 2;
882      size = 1;      size = 1;
883      break;      break;
884    
885      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
886      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
887        space = 2;        space = 2;
888      size = 1 + IMM2_SIZE;      size = 1 + IMM2_SIZE;
# Line 856  while (cc < ccend) Line 903  while (cc < ccend)
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 881  while (cc < ccend) Line 937  while (cc < ccend)
937      }      }
938    
939    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
940      localspace += sizeof(sljit_w) * space;      private_data_length += sizeof(sljit_sw) * space;
941    
942    if (size != 0)    if (size != 0)
943      {      {
# Line 896  while (cc < ccend) Line 952  while (cc < ccend)
952        cc += size;        cc += size;
953      }      }
954    
955    if (bracketlen > 0)    if (bracketlen != 0)
956      {      {
957      if (cc >= end)      if (cc >= end)
958        {        {
# Line 907  while (cc < ccend) Line 963  while (cc < ccend)
963      cc += bracketlen;      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;
# Line 934  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      bracketlen = 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      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1003      break;      break;
1004    
# Line 951  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      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1014      break;      break;
# Line 966  while (cc < ccend) Line 1022  while (cc < ccend)
1022      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1023      break;      break;
1024    
1025      CASE_ITERATOR_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
1026      space = 1;      space = 1;
1027      size = -2;      size = -2;
1028      break;      break;
1029    
1030      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
1031      space = 2;      space = 2;
1032      size = -2;      size = -2;
1033      break;      break;
1034    
1035      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
1036      space = 2;      space = 2;
1037      size = -(2 + IMM2_SIZE);      size = -(2 + IMM2_SIZE);
1038      break;      break;
1039    
1040      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1041      space = 1;      space = 1;
1042      size = 1;      size = 1;
1043      break;      break;
1044    
1045      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1046      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1047        space = 2;        space = 2;
1048      size = 1;      size = 1;
1049      break;      break;
1050    
1051      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1052      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1053        space = 2;        space = 2;
1054      size = 1 + IMM2_SIZE;      size = 1 + IMM2_SIZE;
# Line 1019  while (cc < ccend) Line 1075  while (cc < ccend)
1075    
1076    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1077      {      {
1078      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1079      localptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1080      }      }
1081    
1082    if (size != 0)    if (size != 0)
# Line 1049  while (cc < ccend) Line 1105  while (cc < ccend)
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 1071  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 1081  while (cc < ccend) Line 1142  while (cc < ccend)
1142    
1143      case OP_MARK:      case OP_MARK:
1144      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1145        stack_restore = TRUE;
1146      if (!setmark_found)      if (!setmark_found)
1147        {        {
1148        length += 2;        length += 2;
# Line 1090  while (cc < ccend) Line 1152  while (cc < ccend)
1152      break;      break;
1153    
1154      case OP_RECURSE:      case OP_RECURSE:
1155        stack_restore = TRUE;
1156      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1157        {        {
1158        length += 2;        length += 2;
# Line 1100  while (cc < ccend) Line 1163  while (cc < ccend)
1163        length += 2;        length += 2;
1164        setmark_found = TRUE;        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;      cc += 1 + LINK_SIZE;
1172      break;      break;
1173    
# Line 1107  while (cc < ccend) Line 1175  while (cc < ccend)
1175      case OP_CBRAPOS:      case OP_CBRAPOS:
1176      case OP_SCBRA:      case OP_SCBRA:
1177      case OP_SCBRAPOS:      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;      length += 3;
1185      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1186      break;      break;
1187    
1188      default:      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_TYPEEXACT:
1247        case OP_TYPEPOSSTAR:
1248        case OP_TYPEPOSPLUS:
1249        case OP_TYPEPOSQUERY:
1250        case OP_TYPEPOSUPTO:
1251    
1252        case OP_CLASS:
1253        case OP_NCLASS:
1254        case OP_XCLASS:
1255    
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 1150  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 1164  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 1177  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 1199  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 1218  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;  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;    size = 0;
# Line 1243  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 1263  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_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
1433      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1434        localsize++;        private_data_length++;
1435      cc += 2;      cc += 2;
1436  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1437      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1438  #endif  #endif
1439      break;      break;
1440    
1441      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
1442      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1443        localsize += 2;        private_data_length += 2;
1444      cc += 2;      cc += 2;
1445  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1446      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1447  #endif  #endif
1448      break;      break;
1449    
1450      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
1451      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1452        localsize += 2;        private_data_length += 2;
1453      cc += 2 + IMM2_SIZE;      cc += 2 + IMM2_SIZE;
1454  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1455      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1456  #endif  #endif
1457      break;      break;
1458    
1459      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1460      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1461        localsize++;        private_data_length++;
1462      cc += 1;      cc += 1;
1463      break;      break;
1464    
1465      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1466      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1467        localsize += 2;        private_data_length += 2;
1468      cc += 1;      cc += 1;
1469      break;      break;
1470    
1471      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1472      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1473        localsize += 2;        private_data_length += 2;
1474      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
1475      break;      break;
1476    
# Line 1320  while (cc < ccend) Line 1482  while (cc < ccend)
1482  #else  #else
1483      size = 1 + 32 / (int)sizeof(pcre_uchar);      size = 1 + 32 / (int)sizeof(pcre_uchar);
1484  #endif  #endif
1485      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1486        localsize += get_class_iterator_size(cc + size);        private_data_length += get_class_iterator_size(cc + size);
1487      cc += size;      cc += size;
1488      break;      break;
1489    
# Line 1332  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;
# Line 1357  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 1379  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 1405  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] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[0] = PRIVATE_DATA(cc);
1589        srcw[1] = PRIV_DATA(cc);        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1590        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
1591        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1592        break;        break;
1593    
# Line 1432  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_LOCAL1        CASE_ITERATOR_PRIVATE_DATA_1
1607        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1608          {          {
1609          count = 1;          count = 1;
1610          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1611          }          }
1612        cc += 2;        cc += 2;
1613  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1450  while (status != end) Line 1615  while (status != end)
1615  #endif  #endif
1616        break;        break;
1617    
1618        CASE_ITERATOR_LOCAL2A        CASE_ITERATOR_PRIVATE_DATA_2A
1619        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1620          {          {
1621          count = 2;          count = 2;
1622          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1623          srcw[1] = PRIV_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1624          }          }
1625        cc += 2;        cc += 2;
1626  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1463  while (status != end) Line 1628  while (status != end)
1628  #endif  #endif
1629        break;        break;
1630    
1631        CASE_ITERATOR_LOCAL2B        CASE_ITERATOR_PRIVATE_DATA_2B
1632        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1633          {          {
1634          count = 2;          count = 2;
1635          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1636          srcw[1] = PRIV_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1637          }          }
1638        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1639  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1476  while (status != end) Line 1641  while (status != end)
1641  #endif  #endif
1642        break;        break;
1643    
1644        CASE_ITERATOR_TYPE_LOCAL1        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1645        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1646          {          {
1647          count = 1;          count = 1;
1648          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1649          }          }
1650        cc += 1;        cc += 1;
1651        break;        break;
1652    
1653        CASE_ITERATOR_TYPE_LOCAL2A        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1654        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1655          {          {
1656          count = 2;          count = 2;
1657          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1658          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1659          }          }
1660        cc += 1;        cc += 1;
1661        break;        break;
1662    
1663        CASE_ITERATOR_TYPE_LOCAL2B        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1664        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1665          {          {
1666          count = 2;          count = 2;
1667          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1668          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1669          }          }
1670        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1671        break;        break;
# Line 1513  while (status != end) Line 1678  while (status != end)
1678  #else  #else
1679        size = 1 + 32 / (int)sizeof(pcre_uchar);        size = 1 + 32 / (int)sizeof(pcre_uchar);
1680  #endif  #endif
1681        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1682          switch(get_class_iterator_size(cc + size))          switch(get_class_iterator_size(cc + size))
1683            {            {
1684            case 1:            case 1:
1685            count = 1;            count = 1;
1686            srcw[0] = PRIV_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1687            break;            break;
1688    
1689            case 2:            case 2:
1690            count = 2;            count = 2;
1691            srcw[0] = PRIV_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1692            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1693            break;            break;
1694    
1695            default:            default:
# Line 1556  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 1567  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 1584  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 1596  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 1611  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 1624  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  #undef CASE_ITERATOR_LOCAL1  #undef CASE_ITERATOR_PRIVATE_DATA_1
1805  #undef CASE_ITERATOR_LOCAL2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
1806  #undef CASE_ITERATOR_LOCAL2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
1807  #undef CASE_ITERATOR_TYPE_LOCAL1  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1808  #undef CASE_ITERATOR_TYPE_LOCAL2A  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1809  #undef CASE_ITERATOR_TYPE_LOCAL2B  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1810    
1811  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1812  {  {
1813  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1814  }  }
# Line 1653  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 1670  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->quit = LABEL();    list_item->quit = LABEL();
1847    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1694  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));
     {  
     case stack_alloc:  
     add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));  
     break;  
     }  
1861    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
1862    list_item = list_item->next;    list_item = list_item->next;
1863    }    }
# Line 1719  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 1727  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 1743  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 1764  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);
# Line 1817  DEFINE_COMPILER; Line 1975  DEFINE_COMPILER;
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, quit);  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, quit);  JUMPTO(SLJIT_JUMP, quit);
2000  }  }
# Line 1949  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 1968  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 1981  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 2081  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 2108  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 2143  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 2159  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 2184  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 2196  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 2205  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 2227  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 2241  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 2329  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 2362  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 2384  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 2404  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 2459  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 2482  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)
# Line 2514  if (newlinecheck) Line 2669  if (newlinecheck)
2669  return mainloop;  return mainloop;
2670  }  }
2671    
2672  static SLJIT_INLINE BOOL fast_forward_first_two_chars(compiler_common *common, BOOL firstline)  #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;  DEFINE_COMPILER;
2677  struct sljit_label *start;  struct sljit_label *start;
2678  struct sljit_jump *quit;  struct sljit_jump *quit;
2679  struct sljit_jump *found;  pcre_uint32 chars[MAX_N_CHARS * 2];
2680  pcre_int32 chars[4];  pcre_uchar *cc = common->start + 1 + LINK_SIZE;
 pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  
2681  int location = 0;  int location = 0;
2682  pcre_int32 len, c, bit, caseless;  pcre_int32 len, c, bit, caseless;
2683  BOOL must_end;  int must_stop;
   
 #ifdef COMPILE_PCRE8  
 union {  
     sljit_uh ascombined;  
     sljit_ub asuchars[2];  
 } pair;  
 #else  
 union {  
     sljit_ui ascombined;  
     sljit_uh asuchars[2];  
 } pair;  
 #endif  
2684    
2685    /* We do not support alternatives now. */
2686  if (*(common->start + GET(common->start, 1)) == OP_ALT)  if (*(common->start + GET(common->start, 1)) == OP_ALT)
2687    return FALSE;    return FALSE;
2688    
2689  while (TRUE)  while (TRUE)
2690    {    {
2691    caseless = 0;    caseless = 0;
2692    must_end = TRUE;    must_stop = 1;
2693    switch(*cc)    switch(*cc)
2694      {      {
2695      case OP_CHAR:      case OP_CHAR:
2696      must_end = FALSE;      must_stop = 0;
2697      cc++;      cc++;
2698      break;      break;
2699    
2700      case OP_CHARI:      case OP_CHARI:
2701      caseless = 1;      caseless = 1;
2702      must_end = FALSE;      must_stop = 0;
2703      cc++;      cc++;
2704      break;      break;
2705    
# Line 2596  while (TRUE) Line 2741  while (TRUE)
2741      break;      break;
2742    
2743      default:      default:
2744      return FALSE;      must_stop = 2;
2745        break;
2746      }      }
2747    
2748      if (must_stop == 2)
2749          break;
2750    
2751    len = 1;    len = 1;
2752  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2753    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
# Line 2621  while (TRUE) Line 2770  while (TRUE)
2770    else    else
2771      caseless = 0;      caseless = 0;
2772    
2773    while (len > 0 && location < 2 * 2)    while (len > 0 && location < MAX_N_CHARS * 2)
2774      {      {
2775      c = *cc;      c = *cc;
2776      bit = 0;      bit = 0;
# Line 2639  while (TRUE) Line 2788  while (TRUE)
2788      cc++;      cc++;
2789      }      }
2790    
2791    if (location == 2 * 2)    if (location >= MAX_N_CHARS * 2 || must_stop != 0)
2792      break;      break;
   else if (must_end)  
     return FALSE;  
2793    }    }
2794    
2795    /* At least two characters are required. */
2796    if (location < 2 * 2)
2797        return FALSE;
2798    
2799  if (firstline)  if (firstline)
2800    {    {
2801    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
2802    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    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, 1);    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  else
2806    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2807    
2808  start = LABEL();  start = LABEL();
2809  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  
 #ifdef COMPILE_PCRE8  
 OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #else /* COMPILE_PCRE8 */  
 OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #endif  
2810    
2811  #else /* SLJIT_UNALIGNED */  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
   
 #if defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 #else /* SLJIT_BIG_ENDIAN */  
2812  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2813  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2814  #endif /* SLJIT_BIG_ENDIAN */  if (chars[1] != 0)
2815      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
2816  #ifdef COMPILE_PCRE8  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
2817  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 8);  if (location > 2 * 2)
2818  #else /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2819  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 16);  if (chars[3] != 0)
2820  #endif    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
2821  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
2822    if (location > 2 * 2)
2823  #endif    {
2824      if (chars[5] != 0)
2825  if (chars[1] != 0 || chars[3] != 0)      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
2826    {    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);
   pair.asuchars[0] = chars[1];  
   pair.asuchars[1] = chars[3];  
   OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, pair.ascombined);  
2827    }    }
2828    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2829    
 pair.asuchars[0] = chars[0];  
 pair.asuchars[1] = chars[2];  
 found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, pair.ascombined);  
   
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 JUMPTO(SLJIT_JUMP, start);  
 JUMPHERE(found);  
2830  JUMPHERE(quit);  JUMPHERE(quit);
2831    
2832  if (firstline)  if (firstline)
2833    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2834  else  else
2835    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2836  return TRUE;  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;
# Line 2738  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 2746  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    }    }
# Line 2790  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    
# Line 2833  if (common->nltype == NLTYPE_ANY || comm Line 2966  if (common->nltype == NLTYPE_ANY || comm
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);
# Line 2848  if (firstline) Line 2981  if (firstline)
2981    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    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 *quit;  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    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
# Line 2872  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 3013  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
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(found);
3060    if (matches != NULL)
3061      set_jumps(matches, LABEL());
3062  JUMPHERE(quit);  JUMPHERE(quit);
3063    
3064  if (firstline)  if (firstline)
# Line 2925  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 2956  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 2992  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 3058  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 3102  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 3186  switch(ranges[0]) Line 3320  switch(ranges[0])
3320        }        }
3321      return TRUE;      return TRUE;
3322      }      }
3323    if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && ispowerof2(ranges[4] - ranges[2]))    if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))
3324      {      {
3325      if (readch)      if (readch)
3326        read_char(common);        read_char(common);
# Line 3285  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 3311  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 3351  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 3451  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 3464  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 3486  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 3511  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 3534  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 3549  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 3557  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 3599  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 3651  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  /* Although SUPPORT_UTF must be defined, we are
3812     not necessary in utf mode even in 8 bit mode. */     not necessary in utf mode even in 8 bit mode. */
# Line 3688  if ((*cc++ & XCL_MAP) != 0) Line 3827  if ((*cc++ & XCL_MAP) != 0)
3827      {      {
3828      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3829      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3830      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
3831      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3832      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);
3833      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
# Line 3765  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 3801  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 3843  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 3882  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 3919  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 3950  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 3992  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 4089  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 4124  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 4170  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 4206  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 4308  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 4388  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, oc);    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 4424  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 4449  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 4487  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 4497  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 4533  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 4596  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 4611  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 4622  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 4653  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 4669  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 4735  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;
# Line 4790  if (!minimize) Line 4997  if (!minimize)
4997      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
4998      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
4999      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5000      OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));      OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5001      zerolength = compile_ref_checks(common, ccbegin, NULL);      zerolength = compile_ref_checks(common, ccbegin, NULL);
5002      /* Restore if not zero length. */      /* Restore if not zero length. */
5003      OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));      OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5004      }      }
5005    else    else
5006      {      {
# Line 4806  if (!minimize) Line 5013  if (!minimize)
5013      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
5014    
5015    label = LABEL();    label = LABEL();
5016    compile_ref_trypath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);
5017    
5018    if (min > 1 || max > 1)    if (min > 1 || max > 1)
5019      {      {
# Line 4834  if (!minimize) Line 5041  if (!minimize)
5041      }      }
5042    
5043    JUMPHERE(zerolength);    JUMPHERE(zerolength);
5044    BACKTRACK_AS(iterator_backtrack)->trypath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5045    
5046    decrease_call_count(common);    decrease_call_count(common);
5047    return cc;    return cc;
# Line 4854  if (min == 0) Line 5061  if (min == 0)
5061  else  else
5062    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);
5063    
5064  BACKTRACK_AS(iterator_backtrack)->trypath = LABEL();  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5065  if (max > 0)  if (max > 0)
5066    add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, max));    add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, max));
5067    
5068  compile_ref_trypath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);
5069  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5070    
5071  if (min > 1)  if (min > 1)
# Line 4866  if (min > 1) Line 5073  if (min > 1)
5073    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
5074    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
5075    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5076    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min, BACKTRACK_AS(iterator_backtrack)->trypath);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min, BACKTRACK_AS(iterator_backtrack)->matchingpath);
5077    }    }
5078  else if (max > 0)  else if (max > 0)
5079    OP2(SLJIT_ADD, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 1);    OP2(SLJIT_ADD, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 1);
# Line 4879  decrease_call_count(common); Line 5086  decrease_call_count(common);
5086  return cc;  return cc;
5087  }  }
5088    
5089  static SLJIT_INLINE pcre_uchar *compile_recurse_trypath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)  static SLJIT_INLINE pcre_uchar *compile_recurse_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5090  {  {
5091  DEFINE_COMPILER;  DEFINE_COMPILER;
5092  backtrack_common *backtrack;  backtrack_common *backtrack;
5093  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5094  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5095  int start = GET(cc, 1);  int start = GET(cc, 1);
5096    pcre_uchar *start_cc;
5097    
5098  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5099    
5100    /* Inlining simple patterns. */
5101    if (get_framesize(common, common->start + start, TRUE) == no_stack)
5102      {
5103      start_cc = common->start + start;
5104      compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
5105      BACKTRACK_AS(recurse_backtrack)->inlined_pattern = TRUE;
5106      return cc + 1 + LINK_SIZE;
5107      }
5108    
5109  while (entry != NULL)  while (entry != NULL)
5110    {    {
5111    if (entry->start == start)    if (entry->start == start)
# Line 4936  add_jump(compiler, &backtrack->topbacktr Line 5154  add_jump(compiler, &backtrack->topbacktr
5154  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5155  }  }
5156    
5157  static pcre_uchar *compile_assert_trypath(compiler_common *common, pcre_uchar *cc, assert_backtrack *backtrack, BOOL conditional)  static int SLJIT_CALL do_callout(struct jit_arguments* arguments, PUBL(callout_block) *callout_block, pcre_uchar **jit_ovector)
5158    {
5159    const pcre_uchar *begin = arguments->begin;
5160    int *offset_vector = arguments->offsets;
5161    int offset_count = arguments->offset_count;
5162    int i;
5163    
5164    if (PUBL(callout) == NULL)
5165      return 0;
5166    
5167    callout_block->version = 2;
5168    callout_block->callout_data = arguments->callout_data;
5169    
5170    /* Offsets in subject. */
5171    callout_block->subject_length = arguments->end - arguments->begin;
5172    callout_block->start_match = (pcre_uchar*)callout_block->subject - arguments->begin;
5173    callout_block->current_position = (pcre_uchar*)callout_block->offset_vector - arguments->begin;
5174    #if defined COMPILE_PCRE8
5175    callout_block->subject = (PCRE_SPTR)begin;
5176    #elif defined COMPILE_PCRE16
5177    callout_block->subject = (PCRE_SPTR16)begin;
5178    #elif defined COMPILE_PCRE32
5179    callout_block->subject = (PCRE_SPTR32)begin;
5180    #endif
5181    
5182    /* Convert and copy the JIT offset vector to the offset_vector array. */
5183    callout_block->capture_top = 0;
5184    callout_block->offset_vector = offset_vector;
5185    for (i = 2; i < offset_count; i += 2)
5186      {
5187      offset_vector[i] = jit_ovector[i] - begin;
5188      offset_vector[i + 1] = jit_ovector[i + 1] - begin;
5189      if (jit_ovector[i] >= begin)
5190        callout_block->capture_top = i;
5191      }
5192    
5193    callout_block->capture_top = (callout_block->capture_top >> 1) + 1;
5194    if (offset_count > 0)
5195      offset_vector[0] = -1;
5196    if (offset_count > 1)
5197      offset_vector[1] = -1;
5198    return (*PUBL(callout))(callout_block);
5199    }
5200    
5201    /* Aligning to 8 byte. */
5202    #define CALLOUT_ARG_SIZE \
5203        (((int)sizeof(PUBL(callout_block)) + 7) & ~7)
5204    
5205    #define CALLOUT_ARG_OFFSET(arg) \
5206        (-CALLOUT_ARG_SIZE + SLJIT_OFFSETOF(PUBL(callout_block), arg))
5207    
5208    static SLJIT_INLINE pcre_uchar *compile_callout_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5209    {
5210    DEFINE_COMPILER;
5211    backtrack_common *backtrack;
5212    
5213    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
5214    
5215    allocate_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5216    
5217    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
5218    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
5219    SLJIT_ASSERT(common->capture_last_ptr != 0);
5220    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);
5221    OP1(SLJIT_MOV_UI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);
5222    
5223    /* These pointer sized fields temporarly stores internal variables. */
5224    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
5225    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(offset_vector), STR_PTR, 0);
5226    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(subject), TMP2, 0);
5227    
5228    if (common->mark_ptr != 0)
5229      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr));
5230    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 2));
5231    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 2 + LINK_SIZE));
5232    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);
5233    
5234    /* Needed to save important temporary registers. */
5235    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5236    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, STACK_TOP, 0, SLJIT_IMM, CALLOUT_ARG_SIZE);
5237    GET_LOCAL_BASE(SLJIT_SCRATCH_REG3, 0, OVECTOR_START);
5238    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_callout));
5239    OP1(SLJIT_MOV_SI, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0);
5240    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5241    free_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5242    
5243    /* Check return value. */
5244    OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
5245    add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_C_SIG_GREATER));
5246    if (common->forced_quit_label == NULL)
5247      add_jump(compiler, &common->forced_quit, JUMP(SLJIT_C_SIG_LESS));
5248    else
5249      JUMPTO(SLJIT_C_SIG_LESS, common->forced_quit_label);
5250    return cc + 2 + 2 * LINK_SIZE;
5251    }
5252    
5253    #undef CALLOUT_ARG_SIZE
5254    #undef CALLOUT_ARG_OFFSET
5255    
5256    static pcre_uchar *compile_assert_matchingpath(compiler_common *common, pcre_uchar *cc, assert_backtrack *backtrack, BOOL conditional)
5257  {  {
5258  DEFINE_COMPILER;  DEFINE_COMPILER;
5259  int framesize;  int framesize;
5260  int localptr;  int private_data_ptr;
5261  backtrack_common altbacktrack;  backtrack_common altbacktrack;
5262  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
5263  pcre_uchar opcode;  pcre_uchar opcode;
# Line 4949  jump_list *tmp = NULL; Line 5266  jump_list *tmp = NULL;
5266  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5267  jump_list **found;  jump_list **found;
5268  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5269  struct sljit_label *save_quitlabel = common->quitlabel;  struct sljit_label *save_quit_label = common->quit_label;
5270  struct sljit_label *save_acceptlabel = common->acceptlabel;  struct sljit_label *save_accept_label = common->accept_label;
5271  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
5272  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
5273  struct sljit_jump *jump;  struct sljit_jump *jump;
# Line 4962  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 5279  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
5279    bra = *cc;    bra = *cc;
5280    cc++;    cc++;
5281    }    }
5282  localptr = PRIV_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
5283  SLJIT_ASSERT(localptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
5284  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, FALSE);
5285  backtrack->framesize = framesize;  backtrack->framesize = framesize;
5286  backtrack->localptr = localptr;  backtrack->private_data_ptr = private_data_ptr;
5287  opcode = *cc;  opcode = *cc;
5288  SLJIT_ASSERT(opcode >= OP_ASSERT && opcode <= OP_ASSERTBACK_NOT);  SLJIT_ASSERT(opcode >= OP_ASSERT && opcode <= OP_ASSERTBACK_NOT);
5289  found = (opcode == OP_ASSERT || opcode == OP_ASSERTBACK) ? &tmp : target;  found = (opcode == OP_ASSERT || opcode == OP_ASSERTBACK) ? &tmp : target;
# Line 4983  if (bra == OP_BRAMINZERO) Line 5300  if (bra == OP_BRAMINZERO)
5300    
5301  if (framesize < 0)  if (framesize < 0)
5302    {    {
5303    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
5304    allocate_stack(common, 1);    allocate_stack(common, 1);
5305    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5306    }    }
5307  else  else
5308    {    {
5309    allocate_stack(common, framesize + 2);    allocate_stack(common, framesize + 2);
5310    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5311    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(framesize + 1));    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(framesize + 1));
5312    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);
5313    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5314    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5315    init_frame(common, ccbegin, framesize + 1, 2, FALSE);    init_frame(common, ccbegin, framesize + 1, 2, FALSE);
5316    }    }
5317    
5318  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
5319  common->quitlabel = NULL;  common->quit_label = NULL;
5320  common->quit = NULL;  common->quit = NULL;
5321  while (1)  while (1)
5322    {    {
5323    common->acceptlabel = NULL;    common->accept_label = NULL;
5324    common->accept = NULL;    common->accept = NULL;
5325    altbacktrack.top = NULL;    altbacktrack.top = NULL;
5326    altbacktrack.topbacktracks = NULL;    altbacktrack.topbacktracks = NULL;
# Line 5012  while (1) Line 5329  while (1)
5329      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5330    
5331    altbacktrack.cc = ccbegin;    altbacktrack.cc = ccbegin;
5332    compile_trypath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
5333    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5334      {      {
5335      common->quitlabel = save_quitlabel;      common->quit_label = save_quit_label;
5336      common->acceptlabel = save_acceptlabel;      common->accept_label = save_accept_label;
5337      common->quit = save_quit;      common->quit = save_quit;
5338      common->accept = save_accept;      common->accept = save_accept;
5339      return NULL;      return NULL;
5340      }      }
5341    common->acceptlabel = LABEL();    common->accept_label = LABEL();
5342    if (common->accept != NULL)    if (common->accept != NULL)
5343      set_jumps(common->accept, common->acceptlabel);      set_jumps(common->accept, common->accept_label);
5344    
5345    /* Reset stack. */    /* Reset stack. */
5346    if (framesize < 0)    if (framesize < 0)
5347      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5348    else {    else {
5349      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)
5350        {        {
5351        /* We don't need to keep the STR_PTR, only the previous localptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
5352        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_w));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));
5353        }        }
5354      else      else
5355        {        {
5356        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5357        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5358        }        }
5359    }    }
# Line 5052  while (1) Line 5369  while (1)
5369          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
5370        else        else
5371          {          {
5372          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_w));          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));
5373          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_w));          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));
5374          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP1, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
5375          }          }
5376        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5377        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5378        }        }
5379      else if (framesize >= 0)      else if (framesize >= 0)
5380        {        {
5381        /* For OP_BRA and OP_BRAMINZERO. */        /* For OP_BRA and OP_BRAMINZERO. */
5382        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_w));        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));
5383        }        }
5384      }      }
5385    add_jump(compiler, found, JUMP(SLJIT_JUMP));    add_jump(compiler, found, JUMP(SLJIT_JUMP));
5386    
5387    compile_backtrackpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
5388    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5389      {      {
5390      common->quitlabel = save_quitlabel;      common->quit_label = save_quit_label;
5391      common->acceptlabel = save_acceptlabel;      common->accept_label = save_accept_label;
5392      common->quit = save_quit;      common->quit = save_quit;
5393      common->accept = save_accept;      common->accept = save_accept;
5394      return NULL;      return NULL;
# Line 5113  if (opcode == OP_ASSERT || opcode == OP_ Line 5430  if (opcode == OP_ASSERT || opcode == OP_
5430        }        }
5431      else      else
5432        free_stack(common, framesize + 2);        free_stack(common, framesize + 2);
5433      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
5434      }      }
5435    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
5436    if (bra != OP_BRAZERO)    if (bra != OP_BRAZERO)
# Line 5127  if (opcode == OP_ASSERT || opcode == OP_ Line 5444  if (opcode == OP_ASSERT || opcode == OP_
5444      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
5445      /* Keep the STR_PTR on the top of the stack. */      /* Keep the STR_PTR on the top of the stack. */
5446      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5447        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5448      else if (bra == OP_BRAMINZERO)      else if (bra == OP_BRAMINZERO)
5449        {        {
5450        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5451        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5452        }        }
5453      }      }
# Line 5138  if (opcode == OP_ASSERT || opcode == OP_ Line 5455  if (opcode == OP_ASSERT || opcode == OP_
5455      {      {
5456      if (bra == OP_BRA)      if (bra == OP_BRA)
5457        {        {
5458        /* We don't need to keep the STR_PTR, only the previous localptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
5459        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_w));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));
5460        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
5461        }        }
5462      else      else
5463        {        {
5464        /* We don't need to keep the STR_PTR, only the previous localptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
5465        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_IMM, (framesize + 2) * sizeof(sljit_w));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 2) * sizeof(sljit_sw));
5466        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5467        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);
5468        }        }
# Line 5153  if (opcode == OP_ASSERT || opcode == OP_ Line 5470  if (opcode == OP_ASSERT || opcode == OP_
5470    
5471    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
5472      {      {
5473      backtrack->trypath = LABEL();      backtrack->matchingpath = LABEL();
5474      sljit_set_label(jump, backtrack->trypath);      SET_LABEL(jump, backtrack->matchingpath);
5475      }      }
5476    else if (bra == OP_BRAMINZERO)    else if (bra == OP_BRAMINZERO)
5477      {      {
5478      JUMPTO(SLJIT_JUMP, backtrack->trypath);      JUMPTO(SLJIT_JUMP, backtrack->matchingpath);
5479      JUMPHERE(brajump);      JUMPHERE(brajump);
5480      if (framesize >= 0)      if (framesize >= 0)
5481        {        {
5482        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5483        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5484        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_w));        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));
5485        }        }
5486      set_jumps(backtrack->common.topbacktracks, LABEL());      set_jumps(backtrack->common.topbacktracks, LABEL());
5487      }      }
# Line 5192  else Line 5509  else
5509        }        }
5510      else      else
5511        free_stack(common, framesize + 2);        free_stack(common, framesize + 2);
5512      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
5513      }      }
5514    
5515    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
5516      backtrack->trypath = LABEL();      backtrack->matchingpath = LABEL();
5517    else if (bra == OP_BRAMINZERO)    else if (bra == OP_BRAMINZERO)
5518      {      {
5519      JUMPTO(SLJIT_JUMP, backtrack->trypath);      JUMPTO(SLJIT_JUMP, backtrack->matchingpath);
5520      JUMPHERE(brajump);      JUMPHERE(brajump);
5521      }      }
5522    
# Line 5211  else Line 5528  else
5528      }      }
5529    }    }
5530    
5531  common->quitlabel = save_quitlabel;  common->quit_label = save_quit_label;
5532  common->acceptlabel = save_acceptlabel;  common->accept_label = save_accept_label;
5533  common->quit = save_quit;  common->quit = save_quit;
5534  common->accept = save_accept;  common->accept = save_accept;
5535  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5536  }  }
5537    
5538  static sljit_w SLJIT_CALL do_searchovector(sljit_w refno, sljit_w* locals, pcre_uchar *name_table)  static sljit_sw SLJIT_CALL do_searchovector(sljit_uw refno, sljit_sw* locals, pcre_uchar *name_table)
5539  {  {
5540  int condition = FALSE;  int condition = FALSE;
5541  pcre_uchar *slotA = name_table;  pcre_uchar *slotA = name_table;
5542  pcre_uchar *slotB;  pcre_uchar *slotB;
5543  sljit_w name_count = locals[LOCALS0 / sizeof(sljit_w)];  sljit_sw name_count = locals[LOCALS0 / sizeof(sljit_sw)];
5544  sljit_w name_entry_size = locals[LOCALS1 / sizeof(sljit_w)];  sljit_sw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];
5545  sljit_w no_capture;  sljit_sw no_capture;
5546  int i;  int i;
5547    
5548  locals += refno & 0xff;  locals += refno & 0xff;
# Line 5275  if (i < name_count) Line 5592  if (i < name_count)
5592  return condition;  return condition;
5593  }  }
5594    
5595  static sljit_w SLJIT_CALL do_searchgroups(sljit_w recno, sljit_w* locals, pcre_uchar *name_table)  static sljit_sw SLJIT_CALL do_searchgroups(sljit_uw recno, sljit_uw* locals, pcre_uchar *name_table)
5596  {  {
5597  int condition = FALSE;  int condition = FALSE;
5598  pcre_uchar *slotA = name_table;  pcre_uchar *slotA = name_table;
5599  pcre_uchar *slotB;  pcre_uchar *slotB;
5600  sljit_w name_count = locals[LOCALS0 / sizeof(sljit_w)];  sljit_uw name_count = locals[LOCALS0 / sizeof(sljit_sw)];
5601  sljit_w name_entry_size = locals[LOCALS1 / sizeof(sljit_w)];  sljit_uw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];
5602  sljit_w group_num = locals[POSSESSIVE0 / sizeof(sljit_w)];  sljit_uw group_num = locals[POSSESSIVE0 / sizeof(sljit_sw)];
5603  int i;  sljit_uw i;
5604    
5605  for (i = 0; i < name_count; i++)  for (i = 0; i < name_count; i++)
5606    {    {
# Line 5382  return condition; Line 5699  return condition;
5699                                            Or nothing, if trace is unnecessary                                            Or nothing, if trace is unnecessary
5700  */  */
5701    
5702  static pcre_uchar *compile_bracket_trypath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)  static pcre_uchar *compile_bracket_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5703  {  {
5704  DEFINE_COMPILER;  DEFINE_COMPILER;
5705  backtrack_common *backtrack;  backtrack_common *backtrack;
5706  pcre_uchar opcode;  pcre_uchar opcode;
5707  int localptr = 0;  int private_data_ptr = 0;
5708  int offset = 0;  int offset = 0;
5709  int stacksize;  int stacksize;
5710  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
5711  pcre_uchar *trypath;  pcre_uchar *matchingpath;
5712  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
5713  pcre_uchar ket;  pcre_uchar ket;
5714  assert_backtrack *assert;  assert_backtrack *assert;
# Line 5412  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 5729  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
5729    
5730  opcode = *cc;  opcode = *cc;
5731  ccbegin = cc;  ccbegin = cc;
5732  trypath = ccbegin + 1 + LINK_SIZE;  matchingpath = ccbegin + 1 + LINK_SIZE;
5733    
5734  if ((opcode == OP_COND || opcode == OP_SCOND) && cc[1 + LINK_SIZE] == OP_DEF)  if ((opcode == OP_COND || opcode == OP_SCOND) && cc[1 + LINK_SIZE] == OP_DEF)
5735    {    {
# Line 5429  cc += GET(cc, 1); Line 5746  cc += GET(cc, 1);
5746  has_alternatives = *cc == OP_ALT;  has_alternatives = *cc == OP_ALT;
5747  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))
5748    {    {
5749    has_alternatives = (*trypath == OP_RREF) ? FALSE : TRUE;    has_alternatives = (*matchingpath == OP_RREF) ? FALSE : TRUE;
5750    if (*trypath == OP_NRREF)    if (*matchingpath ==