/[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 1276 by zherczeg, Sun Mar 10 17:35:23 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11    The machine code generator part (this module) was written by Zoltan Herczeg    The machine code generator part (this module) was written by Zoltan Herczeg
12                        Copyright (c) 2010-2012                        Copyright (c) 2010-2013
13    
14  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
15  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 46  POSSIBILITY OF SUCH DAMAGE. Line 46  POSSIBILITY OF SUCH DAMAGE.
46    
47  #include "pcre_internal.h"  #include "pcre_internal.h"
48    
49  #ifdef SUPPORT_JIT  #if defined SUPPORT_JIT
50    
51  /* All-in-one: Since we use the JIT compiler only from here,  /* All-in-one: Since we use the JIT compiler only from here,
52  we just include it. This way we don't need to touch the build  we just include it. This way we don't need to touch the build
# Line 65  system files. */ Line 65  system files. */
65  #error Unsupported architecture  #error Unsupported architecture
66  #endif  #endif
67    
68  /* Allocate memory on the stack. Fast, but limited size. */  /* Defines for debugging purposes. */
 #define LOCAL_SPACE_SIZE 32768  
69    
70    /* 1 - Use unoptimized capturing brackets.
71       2 - Enable capture_last_ptr (includes option 1). */
72    /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */
73    
74    /* 1 - Always have a control head. */
75    /* #define DEBUG_FORCE_CONTROL_HEAD 1 */
76    
77    /* Allocate memory for the regex stack on the real machine stack.
78    Fast, but limited size. */
79    #define MACHINE_STACK_SIZE 32768
80    
81    /* Growth rate for stack allocated by the OS. Should be the multiply
82    of page size. */
83  #define STACK_GROWTH_RATE 8192  #define STACK_GROWTH_RATE 8192
84    
85  /* Enable to check that the allocation could destroy temporaries. */  /* Enable to check that the allocation could destroy temporaries. */
# Line 89  vertical (sub-expression) (See struct ba Line 101  vertical (sub-expression) (See struct ba
101    
102  The condition checkers are boolean (true/false) checkers. Machine code is generated  The condition checkers are boolean (true/false) checkers. Machine code is generated
103  for the checker itself and for the actions depending on the result of the checker.  for the checker itself and for the actions depending on the result of the checker.
104  The 'true' case is called as the 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
105  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
106  branches on the try path.  branches on the matching path.
107    
108   Greedy star operator (*) :   Greedy star operator (*) :
109     Try path: match happens.     Matching path: match happens.
110     Backtrack path: match failed.     Backtrack path: match failed.
111   Non-greedy star operator (*?) :   Non-greedy star operator (*?) :
112     Try path: no need to perform a match.     Matching path: no need to perform a match.
113     Backtrack path: match is required.     Backtrack path: match is required.
114    
115  The following example shows how the code generated for a capturing bracket  The following example shows how the code generated for a capturing bracket
# Line 108  we have the following regular expression Line 120  we have the following regular expression
120    
121  The generated code will be the following:  The generated code will be the following:
122    
123   A try path   A matching path
124   '(' try path (pushing arguments to the stack)   '(' matching path (pushing arguments to the stack)
125   B try path   B matching path
126   ')' try path (pushing arguments to the stack)   ')' matching path (pushing arguments to the stack)
127   D try path   D matching path
128   return with successful match   return with successful match
129    
130   D backtrack path   D backtrack path
131   ')' 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")
132   B backtrack path   B backtrack path
133   C expected path   C expected path
134   jump to D try path   jump to D matching path
135   C backtrack path   C backtrack path
136   A backtrack path   A backtrack path
137    
# Line 127  The generated code will be the following Line 139  The generated code will be the following
139   code paths. In this way the topmost value on the stack is always belong   code paths. In this way the topmost value on the stack is always belong
140   to the current backtrack code path. The backtrack path must check   to the current backtrack code path. The backtrack path must check
141   whether there is a next alternative. If so, it needs to jump back to   whether there is a next alternative. If so, it needs to jump back to
142   the 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
143   frame and continue the execution on the backtrack code paths.   frame and continue the execution on the backtrack code paths.
144  */  */
145    
146  /*  /*
147  Saved stack frames:  Saved stack frames:
148    
149  Atomic blocks and asserts require reloading the values of local variables  Atomic blocks and asserts require reloading the values of private data
150  when the backtrack mechanism performed. Because of OP_RECURSE, the locals  when the backtrack mechanism performed. Because of OP_RECURSE, the data
151  are not necessarly known in compile time, thus we need a dynamic restore  are not necessarly known in compile time, thus we need a dynamic restore
152  mechanism.  mechanism.
153    
154  The stack frames are stored in a chain list, and have the following format:  The stack frames are stored in a chain list, and have the following format:
155  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]
156    
157  Thus we can restore the locals to a particular point in the stack.  Thus we can restore the private data to a particular point in the stack.
158  */  */
159    
160  typedef struct jit_arguments {  typedef struct jit_arguments {
# Line 154  typedef struct jit_arguments { Line 166  typedef struct jit_arguments {
166    int *offsets;    int *offsets;
167    pcre_uchar *uchar_ptr;    pcre_uchar *uchar_ptr;
168    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
169      void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171    int offsetcount;    int real_offset_count;
172    int calllimit;    int offset_count;
173      int call_limit;
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 167  typedef struct executable_functions { Line 181  typedef struct executable_functions {
181    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184      pcre_uint32 top_bracket;
185    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
186  } executable_functions;  } executable_functions;
187    
# Line 175  typedef struct jump_list { Line 190  typedef struct jump_list {
190    struct jump_list *next;    struct jump_list *next;
191  } jump_list;  } jump_list;
192    
 enum stub_types { stack_alloc };  
   
193  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
194    struct sljit_jump *start;    struct sljit_jump *start;
195    struct sljit_label *quit;    struct sljit_label *quit;
196    struct stub_list *next;    struct stub_list *next;
197  } stub_list;  } stub_list;
198    
199    enum frame_types {
200      no_frame = -1,
201      no_stack = -2
202    };
203    
204    enum control_types {
205      type_commit = 0,
206      type_prune = 1,
207      type_skip = 2
208    };
209    
210  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
213  code generator. It is allocated by compile_trypath, and contains  code generator. It is allocated by compile_matchingpath, and contains
214  the aguments for compile_backtrackpath. Must be the first member  the aguments for compile_backtrackingpath. Must be the first member
215  of its descendants. */  of its descendants. */
216  typedef struct backtrack_common {  typedef struct backtrack_common {
217    /* Concatenation stack. */    /* Concatenation stack. */
# Line 205  typedef struct backtrack_common { Line 227  typedef struct backtrack_common {
227  typedef struct assert_backtrack {  typedef struct assert_backtrack {
228    backtrack_common common;    backtrack_common common;
229    jump_list *condfailed;    jump_list *condfailed;
230    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
231    int framesize;    int framesize;
232    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
233    int localptr;    int private_data_ptr;
234    /* For iterators. */    /* For iterators. */
235    struct sljit_label *trypath;    struct sljit_label *matchingpath;
236  } assert_backtrack;  } assert_backtrack;
237    
238  typedef struct bracket_backtrack {  typedef struct bracket_backtrack {
239    backtrack_common common;    backtrack_common common;
240    /* Where to coninue if an alternative is successfully matched. */    /* Where to coninue if an alternative is successfully matched. */
241    struct sljit_label *alttrypath;    struct sljit_label *alternative_matchingpath;
242    /* For rmin and rmax iterators. */    /* For rmin and rmax iterators. */
243    struct sljit_label *recursivetrypath;    struct sljit_label *recursive_matchingpath;
244    /* For greedy ? operator. */    /* For greedy ? operator. */
245    struct sljit_label *zerotrypath;    struct sljit_label *zero_matchingpath;
246    /* Contains the branches of a failed condition. */    /* Contains the branches of a failed condition. */
247    union {    union {
248      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
249      jump_list *condfailed;      jump_list *condfailed;
250      assert_backtrack *assert;      assert_backtrack *assert;
251      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
252      int framesize;      int framesize;
253    } u;    } u;
254    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
255    int localptr;    int private_data_ptr;
256  } bracket_backtrack;  } bracket_backtrack;
257    
258  typedef struct bracketpos_backtrack {  typedef struct bracketpos_backtrack {
259    backtrack_common common;    backtrack_common common;
260    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
261    int localptr;    int private_data_ptr;
262    /* Reverting stack is needed. */    /* Reverting stack is needed. */
263    int framesize;    int framesize;
264    /* Allocated stack size. */    /* Allocated stack size. */
# Line 245  typedef struct bracketpos_backtrack { Line 267  typedef struct bracketpos_backtrack {
267    
268  typedef struct braminzero_backtrack {  typedef struct braminzero_backtrack {
269    backtrack_common common;    backtrack_common common;
270    struct sljit_label *trypath;    struct sljit_label *matchingpath;
271  } braminzero_backtrack;  } braminzero_backtrack;
272    
273  typedef struct iterator_backtrack {  typedef struct iterator_backtrack {
274    backtrack_common common;    backtrack_common common;
275    /* Next iteration. */    /* Next iteration. */
276    struct sljit_label *trypath;    struct sljit_label *matchingpath;
277  } iterator_backtrack;  } iterator_backtrack;
278    
279  typedef struct recurse_entry {  typedef struct recurse_entry {
# Line 266  typedef struct recurse_entry { Line 288  typedef struct recurse_entry {
288    
289  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
290    backtrack_common common;    backtrack_common common;
291      BOOL inlined_pattern;
292  } recurse_backtrack;  } recurse_backtrack;
293    
294  #define MAX_RANGE_SIZE 6  #define MAX_RANGE_SIZE 6
295    
296  typedef struct compiler_common {  typedef struct compiler_common {
297      /* The sljit ceneric compiler. */
298    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
299      /* First byte code. */
300    pcre_uchar *start;    pcre_uchar *start;
301      /* Maps private data offset to each opcode. */
302    /* Opcode local area direct map. */    int *private_data_ptrs;
303    int *localptrs;    /* Tells whether the capturing bracket is optimized. */
304    int cbraptr;    pcre_uint8 *optimized_cbracket;
305    /* OVector starting point. Must be divisible by 2. */    /* Starting offset of private data for capturing brackets. */
306      int cbra_ptr;
307      /* Output vector starting point. Must be divisible by 2. */
308    int ovector_start;    int ovector_start;
309    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
310    int req_char_ptr;    int req_char_ptr;
311    /* Head of the last recursion. */    /* Head of the last recursion. */
312    int recursive_head;    int recursive_head_ptr;
313    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
314    int start_used_ptr;    int start_used_ptr;
315    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 291  typedef struct compiler_common { Line 318  typedef struct compiler_common {
318    int first_line_end;    int first_line_end;
319    /* Points to the marked string. */    /* Points to the marked string. */
320    int mark_ptr;    int mark_ptr;
321      /* Recursive control verb management chain. */
322      int control_head_ptr;
323      /* Points to the last matched capture block index. */
324      int capture_last_ptr;
325      /* Points to the starting position of the current match. */
326      int start_ptr;
327    
328    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
329    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
330    sljit_w lcc;    sljit_sw lcc;
331    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
332    int mode;    int mode;
333      /* \K is in the pattern. */
334      BOOL has_set_som;
335      /* Needs to know the start position anytime. */
336      BOOL needs_start_ptr;
337      /* Currently in recurse or assert. */
338      BOOL local_exit;
339    /* Newline control. */    /* Newline control. */
340    int nltype;    int nltype;
341    int newline;    int newline;
342    int bsr_nltype;    int bsr_nltype;
343    /* Dollar endonly. */    /* Dollar endonly. */
344    int endonly;    int endonly;
   BOOL has_set_som;  
345    /* Tables. */    /* Tables. */
346    sljit_w ctypes;    sljit_sw ctypes;
347    int digits[2 + MAX_RANGE_SIZE];    int digits[2 + MAX_RANGE_SIZE];
348    /* Named capturing brackets. */    /* Named capturing brackets. */
349    sljit_uw name_table;    sljit_uw name_table;
350    sljit_w name_count;    sljit_sw name_count;
351    sljit_w name_entry_size;    sljit_sw name_entry_size;
352    
353    /* Labels and jump lists. */    /* Labels and jump lists. */
354    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
355    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
356    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
357      struct sljit_label *accept_label;
358    stub_list *stubs;    stub_list *stubs;
359    recurse_entry *entries;    recurse_entry *entries;
360    recurse_entry *currententry;    recurse_entry *currententry;
361    jump_list *partialmatch;    jump_list *partialmatch;
362    jump_list *quit;    jump_list *quit;
363      jump_list *forced_quit;
364    jump_list *accept;    jump_list *accept;
365    jump_list *calllimit;    jump_list *calllimit;
366    jump_list *stackalloc;    jump_list *stackalloc;
# Line 331  typedef struct compiler_common { Line 371  typedef struct compiler_common {
371    jump_list *vspace;    jump_list *vspace;
372    jump_list *casefulcmp;    jump_list *casefulcmp;
373    jump_list *caselesscmp;    jump_list *caselesscmp;
374      jump_list *reset_match;
375    BOOL jscript_compat;    BOOL jscript_compat;
376  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
377    BOOL utf;    BOOL utf;
378  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
379    BOOL use_ucp;    BOOL use_ucp;
380  #endif  #endif
381    #ifndef COMPILE_PCRE32
382    jump_list *utfreadchar;    jump_list *utfreadchar;
383    #endif
384  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
385    jump_list *utfreadtype8;    jump_list *utfreadtype8;
386  #endif  #endif
# Line 355  typedef struct compare_context { Line 398  typedef struct compare_context {
398  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
399    int ucharptr;    int ucharptr;
400    union {    union {
401      sljit_i asint;      sljit_si asint;
402      sljit_uh asushort;      sljit_uh asushort;
403  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
404      sljit_ub asbyte;      sljit_ub asbyte;
405      sljit_ub asuchars[4];      sljit_ub asuchars[4];
406  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
407      sljit_uh asuchars[2];      sljit_uh asuchars[2];
408  #endif  #elif defined COMPILE_PCRE32
409        sljit_ui asuchars[1];
410  #endif  #endif
411    } c;    } c;
412    union {    union {
413      sljit_i asint;      sljit_si asint;
414      sljit_uh asushort;      sljit_uh asushort;
415  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
416      sljit_ub asbyte;      sljit_ub asbyte;
417      sljit_ub asuchars[4];      sljit_ub asuchars[4];
418  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
419      sljit_uh asuchars[2];      sljit_uh asuchars[2];
420  #endif  #elif defined COMPILE_PCRE32
421        sljit_ui asuchars[1];
422  #endif  #endif
423    } oc;    } oc;
424  #endif  #endif
425  } compare_context;  } compare_context;
426    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
427  /* Undefine sljit macros. */  /* Undefine sljit macros. */
428  #undef CMP  #undef CMP
429    
430  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
431  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
432    
433  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
434  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
435  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
436  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
437  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
438  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
439  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
440  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
441  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
442  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
443    
444  /* Locals layout. */  /* Local space layout. */
445  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
446  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
447  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
448  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
449  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
450  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
451  /* Max limit of recursions. */  /* Max limit of recursions. */
452  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define CALL_LIMIT       (4 * sizeof(sljit_sw))
453  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
454  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
455  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
456  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. */
457  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
458  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
459  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * sizeof(sljit_sw))
460  #define PRIV_DATA(cc)    (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
461    
462  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
463  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
464  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
465  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
466  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
467  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
468    #elif defined COMPILE_PCRE32
469    #define MOV_UCHAR  SLJIT_MOV_UI
470    #define MOVU_UCHAR SLJIT_MOVU_UI
471  #else  #else
472  #error Unsupported compiling mode  #error Unsupported compiling mode
473  #endif  #endif
 #endif  
474    
475  /* Shortcuts. */  /* Shortcuts. */
476  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 449  the start pointers when the end of the c Line 487  the start pointers when the end of the c
487    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
488  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
489    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
490    #define SET_LABEL(jump, label) \
491      sljit_set_label((jump), (label))
492  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
493    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
494  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
495    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))
496  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
497    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
498  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
499    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
500    
# Line 469  return cc; Line 509  return cc;
509    
510  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
511   next_opcode   next_opcode
512   get_localspace   get_private_data_length
513   set_localptrs   set_private_data_ptrs
514   get_framesize   get_framesize
515   init_frame   init_frame
516   get_localsize   get_private_data_copy_length
517   copy_locals   copy_private_data
518   compile_trypath   compile_matchingpath
519   compile_backtrackpath   compile_backtrackingpath
520  */  */
521    
522  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 537  switch(*cc)
537    case OP_WORDCHAR:    case OP_WORDCHAR:
538    case OP_ANY:    case OP_ANY:
539    case OP_ALLANY:    case OP_ALLANY:
540      case OP_NOTPROP:
541      case OP_PROP:
542    case OP_ANYNL:    case OP_ANYNL:
543    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
544    case OP_HSPACE:    case OP_HSPACE:
# Line 509  switch(*cc) Line 551  switch(*cc)
551    case OP_CIRCM:    case OP_CIRCM:
552    case OP_DOLL:    case OP_DOLL:
553    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:  
554    case OP_CRSTAR:    case OP_CRSTAR:
555    case OP_CRMINSTAR:    case OP_CRMINSTAR:
556    case OP_CRPLUS:    case OP_CRPLUS:
557    case OP_CRMINPLUS:    case OP_CRMINPLUS:
558    case OP_CRQUERY:    case OP_CRQUERY:
559    case OP_CRMINQUERY:    case OP_CRMINQUERY:
560      case OP_CRRANGE:
561      case OP_CRMINRANGE:
562      case OP_CLASS:
563      case OP_NCLASS:
564      case OP_REF:
565      case OP_REFI:
566      case OP_RECURSE:
567      case OP_CALLOUT:
568      case OP_ALT:
569      case OP_KET:
570      case OP_KETRMAX:
571      case OP_KETRMIN:
572      case OP_KETRPOS:
573      case OP_REVERSE:
574      case OP_ASSERT:
575      case OP_ASSERT_NOT:
576      case OP_ASSERTBACK:
577      case OP_ASSERTBACK_NOT:
578      case OP_ONCE:
579      case OP_ONCE_NC:
580      case OP_BRA:
581      case OP_BRAPOS:
582      case OP_CBRA:
583      case OP_CBRAPOS:
584      case OP_COND:
585      case OP_SBRA:
586      case OP_SBRAPOS:
587      case OP_SCBRA:
588      case OP_SCBRAPOS:
589      case OP_SCOND:
590      case OP_CREF:
591      case OP_NCREF:
592      case OP_RREF:
593      case OP_NRREF:
594    case OP_DEF:    case OP_DEF:
595    case OP_BRAZERO:    case OP_BRAZERO:
596    case OP_BRAMINZERO:    case OP_BRAMINZERO:
597    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
598      case OP_PRUNE:
599      case OP_SKIP:
600    case OP_COMMIT:    case OP_COMMIT:
601    case OP_FAIL:    case OP_FAIL:
602    case OP_ACCEPT:    case OP_ACCEPT:
603    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
604      case OP_CLOSE:
605    case OP_SKIPZERO:    case OP_SKIPZERO:
606    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
607    
608    case OP_CHAR:    case OP_CHAR:
609    case OP_CHARI:    case OP_CHARI:
# Line 551  switch(*cc) Line 615  switch(*cc)
615    case OP_MINPLUS:    case OP_MINPLUS:
616    case OP_QUERY:    case OP_QUERY:
617    case OP_MINQUERY:    case OP_MINQUERY:
618      case OP_UPTO:
619      case OP_MINUPTO:
620      case OP_EXACT:
621    case OP_POSSTAR:    case OP_POSSTAR:
622    case OP_POSPLUS:    case OP_POSPLUS:
623    case OP_POSQUERY:    case OP_POSQUERY:
624      case OP_POSUPTO:
625    case OP_STARI:    case OP_STARI:
626    case OP_MINSTARI:    case OP_MINSTARI:
627    case OP_PLUSI:    case OP_PLUSI:
628    case OP_MINPLUSI:    case OP_MINPLUSI:
629    case OP_QUERYI:    case OP_QUERYI:
630    case OP_MINQUERYI:    case OP_MINQUERYI:
631      case OP_UPTOI:
632      case OP_MINUPTOI:
633      case OP_EXACTI:
634    case OP_POSSTARI:    case OP_POSSTARI:
635    case OP_POSPLUSI:    case OP_POSPLUSI:
636    case OP_POSQUERYI:    case OP_POSQUERYI:
637      case OP_POSUPTOI:
638    case OP_NOTSTAR:    case OP_NOTSTAR:
639    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
640    case OP_NOTPLUS:    case OP_NOTPLUS:
641    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
642    case OP_NOTQUERY:    case OP_NOTQUERY:
643    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
644      case OP_NOTUPTO:
645      case OP_NOTMINUPTO:
646      case OP_NOTEXACT:
647    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
648    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
649    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
650      case OP_NOTPOSUPTO:
651    case OP_NOTSTARI:    case OP_NOTSTARI:
652    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
653    case OP_NOTPLUSI:    case OP_NOTPLUSI:
654    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
655    case OP_NOTQUERYI:    case OP_NOTQUERYI:
656    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:  
657    case OP_NOTUPTOI:    case OP_NOTUPTOI:
658    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
659    case OP_NOTEXACTI:    case OP_NOTEXACTI:
660      case OP_NOTPOSSTARI:
661      case OP_NOTPOSPLUSI:
662      case OP_NOTPOSQUERYI:
663    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
664    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
665  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
666    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
667  #endif  #endif
668    return cc;    return cc;
669    
670    case OP_NOTPROP:    /* Special cases. */
671    case OP_PROP:    case OP_TYPESTAR:
672    return cc + 1 + 2;    case OP_TYPEMINSTAR:
673      case OP_TYPEPLUS:
674      case OP_TYPEMINPLUS:
675      case OP_TYPEQUERY:
676      case OP_TYPEMINQUERY:
677    case OP_TYPEUPTO:    case OP_TYPEUPTO:
678    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
679    case OP_TYPEEXACT:    case OP_TYPEEXACT:
680      case OP_TYPEPOSSTAR:
681      case OP_TYPEPOSPLUS:
682      case OP_TYPEPOSQUERY:
683    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
684    case OP_REF:    return cc + PRIV(OP_lengths)[*cc] - 1;
   case OP_REFI:  
   case OP_CREF:  
   case OP_NCREF:  
   case OP_RREF:  
   case OP_NRREF:  
   case OP_CLOSE:  
   cc += 1 + IMM2_SIZE;  
   return cc;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   return cc + 1 + 2 * IMM2_SIZE;  
685    
686    case OP_CLASS:    case OP_ANYBYTE:
687    case OP_NCLASS:  #ifdef SUPPORT_UTF
688    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
689    #endif
690      return cc + 1;
691    
692  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
693    case OP_XCLASS:    case OP_XCLASS:
694    return cc + GET(cc, 1);    return cc + GET(cc, 1);
695  #endif  #endif
696    
   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;  
   
697    case OP_MARK:    case OP_MARK:
698      case OP_PRUNE_ARG:
699    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
700    
701    default:    default:
# Line 675  switch(*cc) Line 703  switch(*cc)
703    }    }
704  }  }
705    
706  #define CASE_ITERATOR_LOCAL1 \  #define CASE_ITERATOR_PRIVATE_DATA_1 \
707      case OP_MINSTAR: \      case OP_MINSTAR: \
708      case OP_MINPLUS: \      case OP_MINPLUS: \
709      case OP_QUERY: \      case OP_QUERY: \
# Line 693  switch(*cc) Line 721  switch(*cc)
721      case OP_NOTQUERYI: \      case OP_NOTQUERYI: \
722      case OP_NOTMINQUERYI:      case OP_NOTMINQUERYI:
723    
724  #define CASE_ITERATOR_LOCAL2A \  #define CASE_ITERATOR_PRIVATE_DATA_2A \
725      case OP_STAR: \      case OP_STAR: \
726      case OP_PLUS: \      case OP_PLUS: \
727      case OP_STARI: \      case OP_STARI: \
# Line 703  switch(*cc) Line 731  switch(*cc)
731      case OP_NOTSTARI: \      case OP_NOTSTARI: \
732      case OP_NOTPLUSI:      case OP_NOTPLUSI:
733    
734  #define CASE_ITERATOR_LOCAL2B \  #define CASE_ITERATOR_PRIVATE_DATA_2B \
735      case OP_UPTO: \      case OP_UPTO: \
736      case OP_MINUPTO: \      case OP_MINUPTO: \
737      case OP_UPTOI: \      case OP_UPTOI: \
# Line 713  switch(*cc) Line 741  switch(*cc)
741      case OP_NOTUPTOI: \      case OP_NOTUPTOI: \
742      case OP_NOTMINUPTOI:      case OP_NOTMINUPTOI:
743    
744  #define CASE_ITERATOR_TYPE_LOCAL1 \  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
745      case OP_TYPEMINSTAR: \      case OP_TYPEMINSTAR: \
746      case OP_TYPEMINPLUS: \      case OP_TYPEMINPLUS: \
747      case OP_TYPEQUERY: \      case OP_TYPEQUERY: \
748      case OP_TYPEMINQUERY:      case OP_TYPEMINQUERY:
749    
750  #define CASE_ITERATOR_TYPE_LOCAL2A \  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
751      case OP_TYPESTAR: \      case OP_TYPESTAR: \
752      case OP_TYPEPLUS:      case OP_TYPEPLUS:
753    
754  #define CASE_ITERATOR_TYPE_LOCAL2B \  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
755      case OP_TYPEUPTO: \      case OP_TYPEUPTO: \
756      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
757    
# Line 752  switch(*cc) Line 780  switch(*cc)
780    }    }
781  }  }
782    
783  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)
784  {  {
785  int localspace = 0;  int private_data_length = 0;
786  pcre_uchar *alternative;  pcre_uchar *alternative;
787    pcre_uchar *name;
788  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
789  int space, size, bracketlen;  int space, size, i;
790    pcre_uint32 bracketlen;
791    
792  /* 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. */
793  while (cc < ccend)  while (cc < ccend)
# Line 772  while (cc < ccend) Line 802  while (cc < ccend)
802      cc += 1;      cc += 1;
803      break;      break;
804    
805        case OP_REF:
806        case OP_REFI:
807        common->optimized_cbracket[GET2(cc, 1)] = 0;
808        cc += 1 + IMM2_SIZE;
809        break;
810    
811      case OP_ASSERT:      case OP_ASSERT:
812      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
813      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 781  while (cc < ccend) Line 817  while (cc < ccend)
817      case OP_BRAPOS:      case OP_BRAPOS:
818      case OP_SBRA:      case OP_SBRA:
819      case OP_SBRAPOS:      case OP_SBRAPOS:
820      case OP_SCOND:      private_data_length += sizeof(sljit_sw);
     localspace += sizeof(sljit_w);  
821      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
822      break;      break;
823    
824      case OP_CBRAPOS:      case OP_CBRAPOS:
825      case OP_SCBRAPOS:      case OP_SCBRAPOS:
826      localspace += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
827        common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
828      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
829      break;      break;
830    
831      case OP_COND:      case OP_COND:
832      /* Might be a hidden SCOND. */      case OP_SCOND:
833      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
834      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
835        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
836          return -1;
837    
838        if (*cc == OP_COND)
839          {
840          /* Might be a hidden SCOND. */
841          alternative = cc + GET(cc, 1);
842          if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
843            private_data_length += sizeof(sljit_sw);
844          }
845        else
846          private_data_length += sizeof(sljit_sw);
847      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
848      break;      break;
849    
850        case OP_CREF:
851        i = GET2(cc, 1);
852        common->optimized_cbracket[i] = 0;
853        cc += 1 + IMM2_SIZE;
854        break;
855    
856        case OP_NCREF:
857        bracketlen = GET2(cc, 1);
858        name = (pcre_uchar *)common->name_table;
859        alternative = name;
860        for (i = 0; i < common->name_count; i++)
861          {
862          if (GET2(name, 0) == bracketlen) break;
863          name += common->name_entry_size;
864          }
865        SLJIT_ASSERT(i != common->name_count);
866    
867        for (i = 0; i < common->name_count; i++)
868          {
869          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
870            common->optimized_cbracket[GET2(alternative, 0)] = 0;
871          alternative += common->name_entry_size;
872          }
873        bracketlen = 0;
874        cc += 1 + IMM2_SIZE;
875        break;
876    
877      case OP_BRA:      case OP_BRA:
878      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
879      break;      break;
# Line 809  while (cc < ccend) Line 883  while (cc < ccend)
883      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
884      break;      break;
885    
886      CASE_ITERATOR_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
887      space = 1;      space = 1;
888      size = -2;      size = -2;
889      break;      break;
890    
891      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
892      space = 2;      space = 2;
893      size = -2;      size = -2;
894      break;      break;
895    
896      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
897      space = 2;      space = 2;
898      size = -(2 + IMM2_SIZE);      size = -(2 + IMM2_SIZE);
899      break;      break;
900    
901      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
902      space = 1;      space = 1;
903      size = 1;      size = 1;
904      break;      break;
905    
906      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
907      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
908        space = 2;        space = 2;
909      size = 1;      size = 1;
910      break;      break;
911    
912      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
913      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)
914        space = 2;        space = 2;
915      size = 1 + IMM2_SIZE;      size = 1 + IMM2_SIZE;
# Line 856  while (cc < ccend) Line 930  while (cc < ccend)
930    
931      case OP_RECURSE:      case OP_RECURSE:
932      /* Set its value only once. */      /* Set its value only once. */
933      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
934        {        {
935        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
936        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
937        }        }
938      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
939      break;      break;
940    
941        case OP_CALLOUT:
942        if (common->capture_last_ptr == 0)
943          {
944          common->capture_last_ptr = common->ovector_start;
945          common->ovector_start += sizeof(sljit_sw);
946          }
947        cc += 2 + 2 * LINK_SIZE;
948        break;
949    
950        case OP_PRUNE_ARG:
951        common->needs_start_ptr = TRUE;
952        common->control_head_ptr = 1;
953        /* Fall through. */
954    
955      case OP_MARK:      case OP_MARK:
956      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
957        {        {
958        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
959        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
960        }        }
961      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
962      break;      break;
963    
964        case OP_PRUNE:
965        case OP_SKIP:
966        common->needs_start_ptr = TRUE;
967        /* Fall through. */
968    
969        case OP_COMMIT:
970        common->control_head_ptr = 1;
971        cc += 1;
972        break;
973    
974      default:      default:
975      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
976      if (cc == NULL)      if (cc == NULL)
# Line 881  while (cc < ccend) Line 979  while (cc < ccend)
979      }      }
980    
981    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
982      localspace += sizeof(sljit_w) * space;      private_data_length += sizeof(sljit_sw) * space;
983    
984    if (size != 0)    if (size != 0)
985      {      {
# Line 896  while (cc < ccend) Line 994  while (cc < ccend)
994        cc += size;        cc += size;
995      }      }
996    
997    if (bracketlen > 0)    if (bracketlen != 0)
998      {      {
999      if (cc >= end)      if (cc >= end)
1000        {        {
# Line 907  while (cc < ccend) Line 1005  while (cc < ccend)
1005      cc += bracketlen;      cc += bracketlen;
1006      }      }
1007    }    }
1008  return localspace;  return private_data_length;
1009  }  }
1010    
1011  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)
1012  {  {
1013  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1014  pcre_uchar *alternative;  pcre_uchar *alternative;
# Line 934  while (cc < ccend) Line 1032  while (cc < ccend)
1032      case OP_SBRA:      case OP_SBRA:
1033      case OP_SBRAPOS:      case OP_SBRAPOS:
1034      case OP_SCOND:      case OP_SCOND:
1035      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1036      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1037      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1038      break;      break;
1039    
1040      case OP_CBRAPOS:      case OP_CBRAPOS:
1041      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1042      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1043      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1044      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1045      break;      break;
1046    
# Line 951  while (cc < ccend) Line 1049  while (cc < ccend)
1049      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1050      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1051        {        {
1052        common->localptrs[cc - common->start] = localptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1053        localptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1054        }        }
1055      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1056      break;      break;
# Line 966  while (cc < ccend) Line 1064  while (cc < ccend)
1064      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1065      break;      break;
1066    
1067      CASE_ITERATOR_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
1068      space = 1;      space = 1;
1069      size = -2;      size = -2;
1070      break;      break;
1071    
1072      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
1073      space = 2;      space = 2;
1074      size = -2;      size = -2;
1075      break;      break;
1076    
1077      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
1078      space = 2;      space = 2;
1079      size = -(2 + IMM2_SIZE);      size = -(2 + IMM2_SIZE);
1080      break;      break;
1081    
1082      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1083      space = 1;      space = 1;
1084      size = 1;      size = 1;
1085      break;      break;
1086    
1087      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1088      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1089        space = 2;        space = 2;
1090      size = 1;      size = 1;
1091      break;      break;
1092    
1093      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1094      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)
1095        space = 2;        space = 2;
1096      size = 1 + IMM2_SIZE;      size = 1 + IMM2_SIZE;
# Line 1019  while (cc < ccend) Line 1117  while (cc < ccend)
1117    
1118    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1119      {      {
1120      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1121      localptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1122      }      }
1123    
1124    if (size != 0)    if (size != 0)
# Line 1049  while (cc < ccend) Line 1147  while (cc < ccend)
1147    }    }
1148  }  }
1149    
1150  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1151  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)
1152  {  {
1153  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1154  int length = 0;  int length = 0;
1155  BOOL possessive = FALSE;  int possessive = 0;
1156    BOOL stack_restore = FALSE;
1157  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1158  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1159    /* The last capture is a local variable even for recursions. */
1160    BOOL capture_last_found = FALSE;
1161    
1162  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1163    {    {
1164    length = 3;    possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1165    possessive = TRUE;    /* This is correct regardless of common->capture_last_ptr. */
1166      capture_last_found = TRUE;
1167    }    }
1168    
1169  cc = next_opcode(common, cc);  cc = next_opcode(common, cc);
# Line 1071  while (cc < ccend) Line 1173  while (cc < ccend)
1173      {      {
1174      case OP_SET_SOM:      case OP_SET_SOM:
1175      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1176        stack_restore = TRUE;
1177      if (!setsom_found)      if (!setsom_found)
1178        {        {
1179        length += 2;        length += 2;
# Line 1080  while (cc < ccend) Line 1183  while (cc < ccend)
1183      break;      break;
1184    
1185      case OP_MARK:      case OP_MARK:
1186        case OP_PRUNE_ARG:
1187      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1188        stack_restore = TRUE;
1189      if (!setmark_found)      if (!setmark_found)
1190        {        {
1191        length += 2;        length += 2;
# Line 1090  while (cc < ccend) Line 1195  while (cc < ccend)
1195      break;      break;
1196    
1197      case OP_RECURSE:      case OP_RECURSE:
1198        stack_restore = TRUE;
1199      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1200        {        {
1201        length += 2;        length += 2;
# Line 1100  while (cc < ccend) Line 1206  while (cc < ccend)
1206        length += 2;        length += 2;
1207        setmark_found = TRUE;        setmark_found = TRUE;
1208        }        }
1209        if (common->capture_last_ptr != 0 && !capture_last_found)
1210          {
1211          length += 2;
1212          capture_last_found = TRUE;
1213          }
1214      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1215      break;      break;
1216    
# Line 1107  while (cc < ccend) Line 1218  while (cc < ccend)
1218      case OP_CBRAPOS:      case OP_CBRAPOS:
1219      case OP_SCBRA:      case OP_SCBRA:
1220      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1221        stack_restore = TRUE;
1222        if (common->capture_last_ptr != 0 && !capture_last_found)
1223          {
1224          length += 2;
1225          capture_last_found = TRUE;
1226          }
1227      length += 3;      length += 3;
1228      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1229      break;      break;
1230    
1231      default:      default:
1232        stack_restore = TRUE;
1233        /* Fall through. */
1234    
1235        case OP_NOT_WORD_BOUNDARY:
1236        case OP_WORD_BOUNDARY:
1237        case OP_NOT_DIGIT:
1238        case OP_DIGIT:
1239        case OP_NOT_WHITESPACE:
1240        case OP_WHITESPACE:
1241        case OP_NOT_WORDCHAR:
1242        case OP_WORDCHAR:
1243        case OP_ANY:
1244        case OP_ALLANY:
1245        case OP_ANYBYTE:
1246        case OP_NOTPROP:
1247        case OP_PROP:
1248        case OP_ANYNL:
1249        case OP_NOT_HSPACE:
1250        case OP_HSPACE:
1251        case OP_NOT_VSPACE:
1252        case OP_VSPACE:
1253        case OP_EXTUNI:
1254        case OP_EODN:
1255        case OP_EOD:
1256        case OP_CIRC:
1257        case OP_CIRCM:
1258        case OP_DOLL:
1259        case OP_DOLLM:
1260        case OP_CHAR:
1261        case OP_CHARI:
1262        case OP_NOT:
1263        case OP_NOTI:
1264    
1265        case OP_EXACT:
1266        case OP_POSSTAR:
1267        case OP_POSPLUS:
1268        case OP_POSQUERY:
1269        case OP_POSUPTO:
1270    
1271        case OP_EXACTI:
1272        case OP_POSSTARI:
1273        case OP_POSPLUSI:
1274        case OP_POSQUERYI:
1275        case OP_POSUPTOI:
1276    
1277        case OP_NOTEXACT:
1278        case OP_NOTPOSSTAR:
1279        case OP_NOTPOSPLUS:
1280        case OP_NOTPOSQUERY:
1281        case OP_NOTPOSUPTO:
1282    
1283        case OP_NOTEXACTI:
1284        case OP_NOTPOSSTARI:
1285        case OP_NOTPOSPLUSI:
1286        case OP_NOTPOSQUERYI:
1287        case OP_NOTPOSUPTOI:
1288    
1289        case OP_TYPEEXACT:
1290        case OP_TYPEPOSSTAR:
1291        case OP_TYPEPOSPLUS:
1292        case OP_TYPEPOSQUERY:
1293        case OP_TYPEPOSUPTO:
1294    
1295        case OP_CLASS:
1296        case OP_NCLASS:
1297        case OP_XCLASS:
1298    
1299      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1300      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1301      break;      break;
1302      }      }
1303    
1304  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1305  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1306    return -1;    return stack_restore ? no_frame : no_stack;
1307    
1308  if (length > 0)  if (length > 0)
1309    return length + 1;    return length + 1;
1310  return -1;  return stack_restore ? no_frame : no_stack;
1311  }  }
1312    
1313  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)
1314  {  {
1315  DEFINE_COMPILER;  DEFINE_COMPILER;
1316  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1317  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1318  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1319    /* The last capture is a local variable even for recursions. */
1320    BOOL capture_last_found = FALSE;
1321  int offset;  int offset;
1322    
1323  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1150  while (cc < ccend) Line 1336  while (cc < ccend)
1336      if (!setsom_found)      if (!setsom_found)
1337        {        {
1338        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1339        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1340        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1341        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1342        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1343        setsom_found = TRUE;        setsom_found = TRUE;
1344        }        }
1345      cc += 1;      cc += 1;
1346      break;      break;
1347    
1348      case OP_MARK:      case OP_MARK:
1349        case OP_PRUNE_ARG:
1350      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1351      if (!setmark_found)      if (!setmark_found)
1352        {        {
1353        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);
1354        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);
1355        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1356        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1357        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1358        setmark_found = TRUE;        setmark_found = TRUE;
1359        }        }
1360      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 1177  while (cc < ccend) Line 1364  while (cc < ccend)
1364      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1365        {        {
1366        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1367        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1368        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1369        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1370        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1371        setsom_found = TRUE;        setsom_found = TRUE;
1372        }        }
1373      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1374        {        {
1375        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);
1376        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);
1377        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1378        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1379        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1380        setmark_found = TRUE;        setmark_found = TRUE;
1381        }        }
1382        if (common->capture_last_ptr != 0 && !capture_last_found)
1383          {
1384          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1385          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1386          stackpos += (int)sizeof(sljit_sw);
1387          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1388          stackpos += (int)sizeof(sljit_sw);
1389          capture_last_found = TRUE;
1390          }
1391      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1392      break;      break;
1393    
# Line 1199  while (cc < ccend) Line 1395  while (cc < ccend)
1395      case OP_CBRAPOS:      case OP_CBRAPOS:
1396      case OP_SCBRA:      case OP_SCBRA:
1397      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1398        if (common->capture_last_ptr != 0 && !capture_last_found)
1399          {
1400          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1401          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1402          stackpos += (int)sizeof(sljit_sw);
1403          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1404          stackpos += (int)sizeof(sljit_sw);
1405          capture_last_found = TRUE;
1406          }
1407      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1408      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1409      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1410      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1411      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));
1412      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1413      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1414      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1415      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1416    
1417      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1418      break;      break;
# Line 1218  while (cc < ccend) Line 1423  while (cc < ccend)
1423      break;      break;
1424      }      }
1425    
1426  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1427  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1428  }  }
1429    
1430  static SLJIT_INLINE int get_localsize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static SLJIT_INLINE int get_private_data_copy_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL needs_control_head)
1431  {  {
1432  int localsize = 2;  int private_data_length = needs_control_head ? 3 : 2;
1433  int size;  int size;
1434  pcre_uchar *alternative;  pcre_uchar *alternative;
1435  /* Calculate the sum of the local variables. */  /* Calculate the sum of the private machine words. */
1436  while (cc < ccend)  while (cc < ccend)
1437    {    {
1438    size = 0;    size = 0;
# Line 1243  while (cc < ccend) Line 1448  while (cc < ccend)
1448      case OP_SBRA:      case OP_SBRA:
1449      case OP_SBRAPOS:      case OP_SBRAPOS:
1450      case OP_SCOND:      case OP_SCOND:
1451      localsize++;      private_data_length++;
1452      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1453      break;      break;
1454    
1455      case OP_CBRA:      case OP_CBRA:
1456      case OP_SCBRA:      case OP_SCBRA:
1457      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1458          private_data_length++;
1459      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1460      break;      break;
1461    
1462      case OP_CBRAPOS:      case OP_CBRAPOS:
1463      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1464      localsize += 2;      private_data_length += 2;
1465      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1466      break;      break;
1467    
# Line 1263  while (cc < ccend) Line 1469  while (cc < ccend)
1469      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1470      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1471      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1472        localsize++;        private_data_length++;
1473      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1474      break;      break;
1475    
1476      CASE_ITERATOR_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
1477      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1478        localsize++;        private_data_length++;
1479      cc += 2;      cc += 2;
1480  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1481      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1482  #endif  #endif
1483      break;      break;
1484    
1485      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
1486      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1487        localsize += 2;        private_data_length += 2;
1488      cc += 2;      cc += 2;
1489  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1490      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1491  #endif  #endif
1492      break;      break;
1493    
1494      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
1495      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1496        localsize += 2;        private_data_length += 2;
1497      cc += 2 + IMM2_SIZE;      cc += 2 + IMM2_SIZE;
1498  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1499      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1500  #endif  #endif
1501      break;      break;
1502    
1503      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1504      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1505        localsize++;        private_data_length++;
1506      cc += 1;      cc += 1;
1507      break;      break;
1508    
1509      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1510      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1511        localsize += 2;        private_data_length += 2;
1512      cc += 1;      cc += 1;
1513      break;      break;
1514    
1515      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1516      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1517        localsize += 2;        private_data_length += 2;
1518      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
1519      break;      break;
1520    
# Line 1320  while (cc < ccend) Line 1526  while (cc < ccend)
1526  #else  #else
1527      size = 1 + 32 / (int)sizeof(pcre_uchar);      size = 1 + 32 / (int)sizeof(pcre_uchar);
1528  #endif  #endif
1529      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1530        localsize += get_class_iterator_size(cc + size);        private_data_length += get_class_iterator_size(cc + size);
1531      cc += size;      cc += size;
1532      break;      break;
1533    
# Line 1332  while (cc < ccend) Line 1538  while (cc < ccend)
1538      }      }
1539    }    }
1540  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1541  return localsize;  return private_data_length;
1542  }  }
1543    
1544  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,
1545    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1546  {  {
1547  DEFINE_COMPILER;  DEFINE_COMPILER;
1548  int srcw[2];  int srcw[2];
# Line 1357  stacktop = STACK(stacktop - 1); Line 1563  stacktop = STACK(stacktop - 1);
1563    
1564  if (!save)  if (!save)
1565    {    {
1566    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1567    if (stackptr < stacktop)    if (stackptr < stacktop)
1568      {      {
1569      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1570      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1571      tmp1empty = FALSE;      tmp1empty = FALSE;
1572      }      }
1573    if (stackptr < stacktop)    if (stackptr < stacktop)
1574      {      {
1575      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1576      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1577      tmp2empty = FALSE;      tmp2empty = FALSE;
1578      }      }
1579    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1580    }    }
1581    
1582  while (status != end)  do
1583    {    {
1584    count = 0;    count = 0;
1585    switch(status)    switch(status)
1586      {      {
1587      case start:      case start:
1588      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1589      count = 1;      count = 1;
1590      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1591        if (needs_control_head)
1592          {
1593          SLJIT_ASSERT(common->control_head_ptr != 0);
1594          count = 2;
1595          srcw[1] = common->control_head_ptr;
1596          }
1597      status = loop;      status = loop;
1598      break;      break;
1599    
# Line 1405  while (status != end) Line 1617  while (status != end)
1617        case OP_SBRAPOS:        case OP_SBRAPOS:
1618        case OP_SCOND:        case OP_SCOND:
1619        count = 1;        count = 1;
1620        srcw[0] = PRIV_DATA(cc);        srcw[0] = PRIVATE_DATA(cc);
1621        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1622        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1623        break;        break;
1624    
1625        case OP_CBRA:        case OP_CBRA:
1626        case OP_SCBRA:        case OP_SCBRA:
1627        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1628        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1629            count = 1;
1630            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1631            }
1632        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1633        break;        break;
1634    
1635        case OP_CBRAPOS:        case OP_CBRAPOS:
1636        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1637        count = 2;        count = 2;
1638        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[0] = PRIVATE_DATA(cc);
1639        srcw[1] = PRIV_DATA(cc);        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1640        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
1641        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1642        break;        break;
1643    
# Line 1432  while (status != end) Line 1647  while (status != end)
1647        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1648          {          {
1649          count = 1;          count = 1;
1650          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1651          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1652          }          }
1653        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1654        break;        break;
1655    
1656        CASE_ITERATOR_LOCAL1        CASE_ITERATOR_PRIVATE_DATA_1
1657        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1658          {          {
1659          count = 1;          count = 1;
1660          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1661          }          }
1662        cc += 2;        cc += 2;
1663  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1450  while (status != end) Line 1665  while (status != end)
1665  #endif  #endif
1666        break;        break;
1667    
1668        CASE_ITERATOR_LOCAL2A        CASE_ITERATOR_PRIVATE_DATA_2A
1669        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1670          {          {
1671          count = 2;          count = 2;
1672          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1673          srcw[1] = PRIV_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1674          }          }
1675        cc += 2;        cc += 2;
1676  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1463  while (status != end) Line 1678  while (status != end)
1678  #endif  #endif
1679        break;        break;
1680    
1681        CASE_ITERATOR_LOCAL2B        CASE_ITERATOR_PRIVATE_DATA_2B
1682        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1683          {          {
1684          count = 2;          count = 2;
1685          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1686          srcw[1] = PRIV_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1687          }          }
1688        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1689  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1476  while (status != end) Line 1691  while (status != end)
1691  #endif  #endif
1692        break;        break;
1693    
1694        CASE_ITERATOR_TYPE_LOCAL1        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1695        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1696          {          {
1697          count = 1;          count = 1;
1698          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1699          }          }
1700        cc += 1;        cc += 1;
1701        break;        break;
1702    
1703        CASE_ITERATOR_TYPE_LOCAL2A        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1704        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1705          {          {
1706          count = 2;          count = 2;
1707          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1708          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1709          }          }
1710        cc += 1;        cc += 1;
1711        break;        break;
1712    
1713        CASE_ITERATOR_TYPE_LOCAL2B        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1714        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1715          {          {
1716          count = 2;          count = 2;
1717          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1718          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1719          }          }
1720        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1721        break;        break;
# Line 1513  while (status != end) Line 1728  while (status != end)
1728  #else  #else
1729        size = 1 + 32 / (int)sizeof(pcre_uchar);        size = 1 + 32 / (int)sizeof(pcre_uchar);
1730  #endif  #endif
1731        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1732          switch(get_class_iterator_size(cc + size))          switch(get_class_iterator_size(cc + size))
1733            {            {
1734            case 1:            case 1:
1735            count = 1;            count = 1;
1736            srcw[0] = PRIV_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1737            break;            break;
1738    
1739            case 2:            case 2:
1740            count = 2;            count = 2;
1741            srcw[0] = PRIV_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1742            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1743            break;            break;
1744    
1745            default:            default:
# Line 1556  while (status != end) Line 1771  while (status != end)
1771          if (!tmp1empty)          if (!tmp1empty)
1772            {            {
1773            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1774            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1775            }            }
1776          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1777          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1567  while (status != end) Line 1782  while (status != end)
1782          if (!tmp2empty)          if (!tmp2empty)
1783            {            {
1784            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1785            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1786            }            }
1787          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1788          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1584  while (status != end) Line 1799  while (status != end)
1799          if (!tmp1empty)          if (!tmp1empty)
1800            {            {
1801            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1802            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1803            }            }
1804          tmp1next = FALSE;          tmp1next = FALSE;
1805          }          }
# Line 1596  while (status != end) Line 1811  while (status != end)
1811          if (!tmp2empty)          if (!tmp2empty)
1812            {            {
1813            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1814            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1815            }            }
1816          tmp1next = TRUE;          tmp1next = TRUE;
1817          }          }
1818        }        }
1819      }      }
1820    }    }
1821    while (status != end);
1822    
1823  if (save)  if (save)
1824    {    {
# Line 1611  if (save) Line 1827  if (save)
1827      if (!tmp1empty)      if (!tmp1empty)
1828        {        {
1829        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1830        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1831        }        }
1832      if (!tmp2empty)      if (!tmp2empty)
1833        {        {
1834        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1835        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1836        }        }
1837      }      }
1838    else    else
# Line 1624  if (save) Line 1840  if (save)
1840      if (!tmp2empty)      if (!tmp2empty)
1841        {        {
1842        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1843        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1844        }        }
1845      if (!tmp1empty)      if (!tmp1empty)
1846        {        {
1847        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1848        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1849        }        }
1850      }      }
1851    }    }
1852  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1853  }  }
1854    
1855  #undef CASE_ITERATOR_LOCAL1  #undef CASE_ITERATOR_PRIVATE_DATA_1
1856  #undef CASE_ITERATOR_LOCAL2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
1857  #undef CASE_ITERATOR_LOCAL2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
1858  #undef CASE_ITERATOR_TYPE_LOCAL1  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1859  #undef CASE_ITERATOR_TYPE_LOCAL2A  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1860  #undef CASE_ITERATOR_TYPE_LOCAL2B  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1861    
1862  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1863  {  {
1864  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1865  }  }
# Line 1653  static SLJIT_INLINE void set_jumps(jump_ Line 1869  static SLJIT_INLINE void set_jumps(jump_
1869  while (list)  while (list)
1870    {    {
1871    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1872    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1873    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1874    list = list->next;    list = list->next;
1875    }    }
1876  }  }
# Line 1670  if (list_item) Line 1886  if (list_item)
1886    }    }
1887  }  }
1888    
1889  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)
1890  {  {
1891  DEFINE_COMPILER;  DEFINE_COMPILER;
1892  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1893    
1894  if (list_item)  if (list_item)
1895    {    {
   list_item->type = type;  
   list_item->data = data;  
1896    list_item->start = start;    list_item->start = start;
1897    list_item->quit = LABEL();    list_item->quit = LABEL();
1898    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1694  stub_list* list_item = common->stubs; Line 1908  stub_list* list_item = common->stubs;
1908  while (list_item)  while (list_item)
1909    {    {
1910    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
1911    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;  
     }  
1912    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
1913    list_item = list_item->next;    list_item = list_item->next;
1914    }    }
# Line 1719  static SLJIT_INLINE void allocate_stack( Line 1928  static SLJIT_INLINE void allocate_stack(
1928  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
1929  DEFINE_COMPILER;  DEFINE_COMPILER;
1930    
1931  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));
1932  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
1933  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
1934  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 1936  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
1936  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
1937  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
1938  #endif  #endif
1939  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));
1940  }  }
1941    
1942  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
1943  {  {
1944  DEFINE_COMPILER;  DEFINE_COMPILER;
1945  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));
1946  }  }
1947    
1948  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1741  static SLJIT_INLINE void reset_ovector(c Line 1950  static SLJIT_INLINE void reset_ovector(c
1950  DEFINE_COMPILER;  DEFINE_COMPILER;
1951  struct sljit_label *loop;  struct sljit_label *loop;
1952  int i;  int i;
1953    
1954  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
1955    SLJIT_ASSERT(length > 1);
1956  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
1957  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));
1958    if (length < 8)
1959      {
1960      for (i = 1; i < length; i++)
1961        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
1962      }
1963    else
1964      {
1965      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
1966      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
1967      loop = LABEL();
1968      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
1969      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
1970      JUMPTO(SLJIT_C_NOT_ZERO, loop);
1971      }
1972    }
1973    
1974    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
1975    {
1976    DEFINE_COMPILER;
1977    struct sljit_label *loop;
1978    int i;
1979    
1980    SLJIT_ASSERT(length > 1);
1981    /* OVECTOR(1) contains the "string begin - 1" constant. */
1982    if (length > 2)
1983      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
1984  if (length < 8)  if (length < 8)
1985    {    {
1986    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
1987      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_TEMPORARY_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
1988    }    }
1989  else  else
1990    {    {
1991    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
1992    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
1993    loop = LABEL();    loop = LABEL();
1994    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
1995    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
1996    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
1997    }    }
1998    
1999    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2000    if (common->mark_ptr != 0)
2001      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2002    SLJIT_ASSERT(common->control_head_ptr != 0);
2003    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2004    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2005    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2006    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2007    }
2008    
2009    static sljit_sw SLJIT_CALL do_check_control_chain(sljit_sw *current)
2010    {
2011    sljit_sw return_value = 0;
2012    
2013    SLJIT_ASSERT(current != NULL);
2014    do
2015      {
2016      switch (current[-2])
2017        {
2018        case type_commit:
2019        /* Commit overwrites all. */
2020        return -1;
2021    
2022        case type_prune:
2023        break;
2024    
2025        case type_skip:
2026        /* Overwrites prune, but not other skips. */
2027        if (return_value == 0)
2028          return_value = current[-3];
2029        break;
2030    
2031        default:
2032        SLJIT_ASSERT_STOP();
2033        break;
2034        }
2035      current = (sljit_sw*)current[-1];
2036      }
2037    while (current != NULL);
2038    return return_value;
2039  }  }
2040    
2041  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2042  {  {
2043  DEFINE_COMPILER;  DEFINE_COMPILER;
2044  struct sljit_label *loop;  struct sljit_label *loop;
2045  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2046    
2047  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2048  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));
2049  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);
2050    
2051  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2052  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2053    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);
2054  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));
2055  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2056    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);
2057  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));
2058  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));
2059  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2060  /* Unlikely, but possible */  /* Unlikely, but possible */
2061  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);
2062  loop = LABEL();  loop = LABEL();
2063  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);
2064  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));
2065  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2066  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2067  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);
2068  #endif  #endif
2069  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);
2070  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);
2071  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2072  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2073    
2074  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2075  if (topbracket > 1)  if (topbracket > 1)
2076    {    {
2077    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));
2078    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2079    
2080    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2081    loop = LABEL();    loop = LABEL();
2082    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)));
2083    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);
2084    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);
2085    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2086    }    }
2087  else  else
2088    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1813  else Line 2091  else
2091  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)
2092  {  {
2093  DEFINE_COMPILER;  DEFINE_COMPILER;
2094    struct sljit_jump *jump;
2095    
2096  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);
2097  SLJIT_ASSERT(common->start_used_ptr != 0 && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));  SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0
2098      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2099    
2100  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2101  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2102  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, offsetcount));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, real_offset_count));
2103  CMPTO(SLJIT_C_LESS, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2, quit);  CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
2104    
2105  /* Store match begin and end. */  /* Store match begin and end. */
2106  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));
2107  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));
2108  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);  
2109    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2110    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + (int)sizeof(sljit_sw)), SLJIT_SAVED_REG1, 0);
2111    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2112    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2113    #endif
2114    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2115    JUMPHERE(jump);
2116    
2117    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);
2118  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);
2119  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2120  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);
2121  #endif  #endif
2122  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);
2123    
2124  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);
2125  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2126  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);
2127  #endif  #endif
2128  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);
2129    
2130  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2131  }  }
# Line 1949  if (c <= 127 && bit == 0x20) Line 2238  if (c <= 127 && bit == 0x20)
2238    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2239    
2240  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2241  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2242    return 0;    return 0;
2243    
2244  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2245    
2246  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2247  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 1968  if (common->utf && c > 127) Line 2257  if (common->utf && c > 127)
2257  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2258  return (0 << 8) | bit;  return (0 << 8) | bit;
2259    
2260  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2261    
 #ifdef COMPILE_PCRE16  
2262  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2263  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2264    {    {
# Line 1981  if (common->utf && c > 65535) Line 2269  if (common->utf && c > 65535)
2269    }    }
2270  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2271  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2272    
2273  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2274  }  }
2275    
2276  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
# Line 2003  else if (common->mode == JIT_PARTIAL_SOF Line 2290  else if (common->mode == JIT_PARTIAL_SOF
2290    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2291    
2292  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2293    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2294  else  else
2295    {    {
2296    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2016  if (jump != NULL) Line 2303  if (jump != NULL)
2303    JUMPHERE(jump);    JUMPHERE(jump);
2304  }  }
2305    
2306  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2307  {  {
2308  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2309  DEFINE_COMPILER;  DEFINE_COMPILER;
2310  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2311    
2312  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2313    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2314      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2315      return;
2316      }
2317    
2318  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2319  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2320    {    {
2321    nohit = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2322    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2323    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2324    }    }
2325  else  else
2326    {    {
2327    return_value = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2328    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2329      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2330    else    else
2331      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2332    }    }
2333  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2334  }  }
2335    
2336  static void detect_partial_match(compiler_common *common, jump_list **backtracks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
# Line 2063  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR Line 2349  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2349  add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));  add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2350  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2351    {    {
2352    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2353    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2354    }    }
2355  else  else
# Line 2081  static void read_char(compiler_common *c Line 2367  static void read_char(compiler_common *c
2367  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2368  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2369  DEFINE_COMPILER;  DEFINE_COMPILER;
2370  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2371  struct sljit_jump *jump;  struct sljit_jump *jump;
2372  #endif  #endif
2373    
2374  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2375  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2376  if (common->utf)  if (common->utf)
2377    {    {
2378  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2379    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2380  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2381    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2382  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2383    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2384    JUMPHERE(jump);    JUMPHERE(jump);
2385    }    }
2386  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2387  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));
2388  }  }
2389    
# Line 2108  static void peek_char(compiler_common *c Line 2392  static void peek_char(compiler_common *c
2392  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2393  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2394  DEFINE_COMPILER;  DEFINE_COMPILER;
2395  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2396  struct sljit_jump *jump;  struct sljit_jump *jump;
2397  #endif  #endif
2398    
2399  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2400  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2401  if (common->utf)  if (common->utf)
2402    {    {
2403  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2404    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2405  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2406    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2407  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2408    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2409    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2410    JUMPHERE(jump);    JUMPHERE(jump);
2411    }    }
2412  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2413  }  }
2414    
2415  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2416  {  {
2417  /* 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. */
2418  DEFINE_COMPILER;  DEFINE_COMPILER;
2419  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2420  struct sljit_jump *jump;  struct sljit_jump *jump;
2421  #endif  #endif
2422    
# Line 2143  if (common->utf) Line 2425  if (common->utf)
2425    {    {
2426    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2427    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));
2428  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2429    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2430    it is needed in most cases. */    it is needed in most cases. */
2431    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2432    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2433    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2434    JUMPHERE(jump);    JUMPHERE(jump);
2435  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2436    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2437    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2438    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 2440  if (common->utf)
2440    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2441    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2442    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);
2443    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2444    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2445    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2446  #endif  #elif defined COMPILE_PCRE32
2447  #endif /* COMPILE_PCRE8 */    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2448      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2449      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2450      JUMPHERE(jump);
2451    #endif /* COMPILE_PCRE[8|16|32] */
2452    return;    return;
2453    }    }
2454  #endif  #endif /* SUPPORT_UTF */
2455  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2456  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));
2457  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2458  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2459  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2460  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2461  #endif  #endif
2462  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2463  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2464  JUMPHERE(jump);  JUMPHERE(jump);
2465  #endif  #endif
2466  }  }
# Line 2184  static void skip_char_back(compiler_comm Line 2469  static void skip_char_back(compiler_comm
2469  {  {
2470  /* 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. */
2471  DEFINE_COMPILER;  DEFINE_COMPILER;
2472  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2473    #if defined COMPILE_PCRE8
2474  struct sljit_label *label;  struct sljit_label *label;
2475    
2476  if (common->utf)  if (common->utf)
# Line 2196  if (common->utf) Line 2482  if (common->utf)
2482    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2483    return;    return;
2484    }    }
2485  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2486  if (common->utf)  if (common->utf)
2487    {    {
2488    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 2490  if (common->utf)
2490    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2491    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2492    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);
2493    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2494    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2495    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2496    return;    return;
2497    }    }
2498  #endif  #endif /* COMPILE_PCRE[8|16] */
2499    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2500  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));
2501  }  }
2502    
# Line 2227  if (nltype == NLTYPE_ANY) Line 2513  if (nltype == NLTYPE_ANY)
2513  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2514    {    {
2515    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);
2516    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2517    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);
2518    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);
2519    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));
2520    }    }
2521  else  else
# Line 2241  else Line 2527  else
2527    
2528  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2529    
2530  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2531  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2532  {  {
2533  /* 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 2615  sljit_emit_fast_return(compiler, RETURN_
2615  JUMPHERE(jump);  JUMPHERE(jump);
2616    
2617  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2618  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);
2619  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2620  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2621  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2622  }  }
2623    
2624  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
2625    
 #ifdef COMPILE_PCRE16  
2626  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2627  {  {
2628  /* 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 2647  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC
2647  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2648  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2649  }  }
 #endif /* COMPILE_PCRE16 */  
2650    
2651  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16] */
2652    
2653  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2654    
# Line 2384  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 2668  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2668    
2669  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2670  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2671  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));
2672  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2673  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2674  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2675  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2676  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2677  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));
2678  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2679  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2680  }  }
# Line 2404  struct sljit_label *newlinelabel = NULL; Line 2688  struct sljit_label *newlinelabel = NULL;
2688  struct sljit_jump *start;  struct sljit_jump *start;
2689  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2690  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2691  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2692  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2693  #endif  #endif
2694  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 2459  if (newlinecheck) Line 2743  if (newlinecheck)
2743    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2744    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2745    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);
2746    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2747  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2748    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2749  #endif  #endif
2750    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2751    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 2482  if (newlinecheck) Line 2766  if (newlinecheck)
2766    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);
2767    
2768  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));
2769  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2770    #if defined COMPILE_PCRE8
2771  if (common->utf)  if (common->utf)
2772    {    {
2773    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2774    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);
2775    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2776    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2777    }    }
2778  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2779  if (common->utf)  if (common->utf)
2780    {    {
2781    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2782    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2783    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);
2784    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2785    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2786    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2787    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2788    }    }
2789  #endif  #endif /* COMPILE_PCRE[8|16] */
2790    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2791  JUMPHERE(start);  JUMPHERE(start);
2792    
2793  if (newlinecheck)  if (newlinecheck)
# Line 2514  if (newlinecheck) Line 2799  if (newlinecheck)
2799  return mainloop;  return mainloop;
2800  }  }
2801    
2802  static SLJIT_INLINE BOOL fast_forward_first_two_chars(compiler_common *common, BOOL firstline)  #define MAX_N_CHARS 3
2803    
2804    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2805  {  {
2806  DEFINE_COMPILER;  DEFINE_COMPILER;
2807  struct sljit_label *start;  struct sljit_label *start;
2808  struct sljit_jump *quit;  struct sljit_jump *quit;
2809  struct sljit_jump *found;  pcre_uint32 chars[MAX_N_CHARS * 2];
2810  pcre_int32 chars[4];  pcre_uchar *cc = common->start + 1 + LINK_SIZE;
 pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  
2811  int location = 0;  int location = 0;
2812  pcre_int32 len, c, bit, caseless;  pcre_int32 len, c, bit, caseless;
2813  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  
2814    
2815    /* We do not support alternatives now. */
2816  if (*(common->start + GET(common->start, 1)) == OP_ALT)  if (*(common->start + GET(common->start, 1)) == OP_ALT)
2817    return FALSE;    return FALSE;
2818    
2819  while (TRUE)  while (TRUE)
2820    {    {
2821    caseless = 0;    caseless = 0;
2822    must_end = TRUE;    must_stop = 1;
2823    switch(*cc)    switch(*cc)
2824      {      {
2825      case OP_CHAR:      case OP_CHAR:
2826      must_end = FALSE;      must_stop = 0;
2827      cc++;      cc++;
2828      break;      break;
2829    
2830      case OP_CHARI:      case OP_CHARI:
2831      caseless = 1;      caseless = 1;
2832      must_end = FALSE;      must_stop = 0;
2833      cc++;      cc++;
2834      break;      break;
2835    
# Line 2596  while (TRUE) Line 2871  while (TRUE)
2871      break;      break;
2872    
2873      default:      default:
2874      return FALSE;      must_stop = 2;
2875        break;
2876      }      }
2877    
2878      if (must_stop == 2)
2879          break;
2880    
2881    len = 1;    len = 1;
2882  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2883    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 2900  while (TRUE)
2900    else    else
2901      caseless = 0;      caseless = 0;
2902    
2903    while (len > 0 && location < 2 * 2)    while (len > 0 && location < MAX_N_CHARS * 2)
2904      {      {
2905      c = *cc;      c = *cc;
2906      bit = 0;      bit = 0;
# Line 2639  while (TRUE) Line 2918  while (TRUE)
2918      cc++;      cc++;
2919      }      }
2920    
2921    if (location == 2 * 2)    if (location >= MAX_N_CHARS * 2 || must_stop != 0)
2922      break;      break;
   else if (must_end)  
     return FALSE;  
2923    }    }
2924    
2925    /* At least two characters are required. */
2926    if (location < 2 * 2)
2927        return FALSE;
2928    
2929  if (firstline)  if (firstline)
2930    {    {
2931    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
2932    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2933    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));
2934    }    }
2935  else  else
2936    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));
2937    
2938  start = LABEL();  start = LABEL();
2939  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  
   
 #else /* SLJIT_UNALIGNED */  
2940    
2941  #if defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
 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 */  
2942  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2943  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2944  #endif /* SLJIT_BIG_ENDIAN */  if (chars[1] != 0)
2945      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
2946  #ifdef COMPILE_PCRE8  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
2947  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 8);  if (location > 2 * 2)
2948  #else /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2949  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 16);  if (chars[3] != 0)
2950  #endif    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
2951  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
2952    if (location > 2 * 2)
2953  #endif    {
2954      if (chars[5] != 0)
2955  if (chars[1] != 0 || chars[3] != 0)      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
2956    {    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);  
2957    }    }
2958    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2959    
 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);  
2960  JUMPHERE(quit);  JUMPHERE(quit);
2961    
2962  if (firstline)  if (firstline)
2963    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2964  else  else
2965    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));
2966  return TRUE;  return TRUE;
2967  }  }
2968    
2969    #undef MAX_N_CHARS
2970    
2971  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)
2972  {  {
2973  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2738  if (first_char == oc) Line 3001  if (first_char == oc)
3001  else  else
3002    {    {
3003    bit = first_char ^ oc;    bit = first_char ^ oc;
3004    if (ispowerof2(bit))    if (is_powerof2(bit))
3005      {      {
3006      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3007      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 3009  else
3009    else    else
3010      {      {
3011      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);
3012      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3013      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);
3014      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);
3015      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3016      }      }
3017    }    }
# Line 2790  if (common->nltype == NLTYPE_FIXED && co Line 3053  if (common->nltype == NLTYPE_FIXED && co
3053    
3054    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3055    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);
3056    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3057  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3058    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3059  #endif  #endif
3060    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3061    
# Line 2833  if (common->nltype == NLTYPE_ANY || comm Line 3096  if (common->nltype == NLTYPE_ANY || comm
3096    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3097    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3098    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);
3099    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3100  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3101    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3102  #endif  #endif
3103    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3104    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
# Line 2848  if (firstline) Line 3111  if (firstline)
3111    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3112  }  }
3113    
3114    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3115    
3116  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)
3117  {  {
3118  DEFINE_COMPILER;  DEFINE_COMPILER;
3119  struct sljit_label *start;  struct sljit_label *start;
3120  struct sljit_jump *quit;  struct sljit_jump *quit;
3121  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3122    jump_list *matches = NULL;
3123    pcre_uint8 inverted_start_bits[32];
3124    int i;
3125  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3126  struct sljit_jump *jump;  struct sljit_jump *jump;
3127  #endif  #endif
3128    
3129    for (i = 0; i < 32; ++i)
3130      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3131    
3132  if (firstline)  if (firstline)
3133    {    {
3134    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 3143  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3143  if (common->utf)  if (common->utf)
3144    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3145  #endif  #endif
3146    
3147    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3148      {
3149  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3150  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3151  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3152  JUMPHERE(jump);    JUMPHERE(jump);
3153  #endif  #endif
3154  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3155  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3156  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3157  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3158  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);
3159  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3160      }
3161    
3162  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3163  if (common->utf)  if (common->utf)
3164    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3165  #endif  #endif
3166  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));
3167  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3168    #if defined COMPILE_PCRE8
3169  if (common->utf)  if (common->utf)
3170    {    {
3171    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3172    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);
3173    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3174    }    }
3175  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3176  if (common->utf)  if (common->utf)
3177    {    {
3178    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3179    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3180    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);
3181    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3182    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3183    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3184    }    }
3185  #endif  #endif /* COMPILE_PCRE[8|16] */
3186    #endif /* SUPPORT_UTF */
3187  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3188  JUMPHERE(found);  if (found != NULL)
3189      JUMPHERE(found);
3190    if (matches != NULL)
3191      set_jumps(matches, LABEL());
3192  JUMPHERE(quit);  JUMPHERE(quit);
3193    
3194  if (firstline)  if (firstline)
# Line 2925  struct sljit_jump *alreadyfound; Line 3204  struct sljit_jump *alreadyfound;
3204  struct sljit_jump *found;  struct sljit_jump *found;
3205  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3206  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3207  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3208    
3209  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3210  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 3235  if (req_char == oc)
3235  else  else
3236    {    {
3237    bit = req_char ^ oc;    bit = req_char ^ oc;
3238    if (ispowerof2(bit))    if (is_powerof2(bit))
3239      {      {
3240      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3241      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 3271  GET_LOCAL_BASE(TMP3, 0, 0);
3271  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3272  mainloop = LABEL();  mainloop = LABEL();
3273  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3274  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);
3275    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3276    
3277  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3278  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));
3279  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));
3280  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));
3281  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3282    
3283  JUMPHERE(jump);  JUMPHERE(jump);
3284  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3285  /* End of dropping frames. */  /* End of dropping frames. */
3286  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3287    
3288  JUMPHERE(jump);  JUMPHERE(jump);
3289  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3290  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3291  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3292  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));  
3293  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3294  }  }
3295    
# Line 3033  static void check_wordboundary(compiler_ Line 3297  static void check_wordboundary(compiler_
3297  {  {
3298  DEFINE_COMPILER;  DEFINE_COMPILER;
3299  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3300    jump_list *skipread_list = NULL;
3301  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3302  struct sljit_jump *jump;  struct sljit_jump *jump;
3303  #endif  #endif
# Line 3058  if (common->use_ucp) Line 3323  if (common->use_ucp)
3323    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3324    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3325    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);
3326    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3327    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);
3328    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);
3329    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3330    JUMPHERE(jump);    JUMPHERE(jump);
3331    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3332    }    }
# Line 3090  else Line 3355  else
3355  JUMPHERE(skipread);  JUMPHERE(skipread);
3356    
3357  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3358  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3359  peek_char(common);  peek_char(common);
3360    
3361  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 3102  if (common->use_ucp) Line 3367  if (common->use_ucp)
3367    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3368    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3369    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);
3370    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3371    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);
3372    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);
3373    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3374    JUMPHERE(jump);    JUMPHERE(jump);
3375    }    }
3376  else  else
# Line 3131  else Line 3396  else
3396      JUMPHERE(jump);      JUMPHERE(jump);
3397  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3398    }    }
3399  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3400    
3401  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3402  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
# Line 3186  switch(ranges[0]) Line 3451  switch(ranges[0])
3451        }        }
3452      return TRUE;      return TRUE;
3453      }      }
3454    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]))
3455      {      {
3456      if (readch)      if (readch)
3457        read_char(common);        read_char(common);
# Line 3285  sljit_emit_fast_enter(compiler, RETURN_A Line 3550  sljit_emit_fast_enter(compiler, RETURN_A
3550    
3551  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3552  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);
3553  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3554  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);
3555  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3556  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3557  if (common->utf)  if (common->utf)
3558    {    {
3559  #endif  #endif
3560    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3561    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3562    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);
3563  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3564    }    }
3565  #endif  #endif
3566  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3567  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);
3568  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3569  }  }
3570    
# Line 3311  DEFINE_COMPILER; Line 3576  DEFINE_COMPILER;
3576  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3577    
3578  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);
3579  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3580  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);
3581  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3582  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);
3583  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3584  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3585  if (common->utf)  if (common->utf)
3586    {    {
3587  #endif  #endif
3588    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3589    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);
3590    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3591    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);
3592    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3593    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3594    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);
3595    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3596    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);
3597    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3598    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);
3599    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3600    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);
3601  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3602    }    }
3603  #endif  #endif
3604  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3605  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);
3606    
3607  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3608  }  }
# Line 3351  sljit_emit_fast_enter(compiler, RETURN_A Line 3616  sljit_emit_fast_enter(compiler, RETURN_A
3616    
3617  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3618  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);
3619  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3620  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);
3621  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3622  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3623  if (common->utf)  if (common->utf)
3624    {    {
3625  #endif  #endif
3626    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);
3627    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3628    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);
3629  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3630    }    }
3631  #endif  #endif
3632  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3633  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);
3634    
3635  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3636  }  }
# Line 3451  sljit_emit_fast_return(compiler, RETURN_ Line 3716  sljit_emit_fast_return(compiler, RETURN_
3716    
3717  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3718    
3719  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)
3720  {  {
3721  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3722  int c1, c2;  pcre_uint32 c1, c2;
3723  const pcre_uchar *src2 = args->uchar_ptr;  const pcre_uchar *src2 = args->uchar_ptr;
3724  const pcre_uchar *end2 = args->end;  const pcre_uchar *end2 = args->end;
3725    const ucd_record *ur;
3726    const pcre_uint32 *pp;
3727    
3728  while (src1 < end1)  while (src1 < end1)
3729    {    {
# Line 3464  while (src1 < end1) Line 3731  while (src1 < end1)
3731      return (pcre_uchar*)1;      return (pcre_uchar*)1;
3732    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
3733    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
3734    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return NULL;    ur = GET_UCD(c2);
3735      if (c1 != c2 && c1 != c2 + ur->other_case)
3736        {
3737        pp = PRIV(ucd_caseless_sets) + ur->caseset;
3738        for (;;)
3739          {
3740          if (c1 < *pp) return NULL;
3741          if (c1 == *pp++) break;
3742          }
3743        }
3744    }    }
3745  return src2;  return src2;
3746  }  }
# Line 3486  if (caseless && char_has_othercase(commo Line 3762  if (caseless && char_has_othercase(commo
3762    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
3763    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
3764    /* Extracting bit difference info. */    /* Extracting bit difference info. */
3765  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3766    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
3767    othercasebit &= 0xff;    othercasebit &= 0xff;
3768  #else  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3769  #ifdef COMPILE_PCRE16    /* Note that this code only handles characters in the BMP. If there
3770      ever are characters outside the BMP whose othercase differs in only one
3771      bit from itself (there currently are none), this code will need to be
3772      revised for COMPILE_PCRE32. */
3773    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
3774    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
3775      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
3776    else    else
3777      othercasebit &= 0xff;      othercasebit &= 0xff;
3778  #endif  #endif /* COMPILE_PCRE[8|16|32] */
 #endif  
3779    }    }
3780    
3781  if (context->sourcereg == -1)  if (context->sourcereg == -1)
3782    {    {
3783  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3784  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3785    if (context->length >= 4)    if (context->length >= 4)
3786      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 3789  if (context->sourcereg == -1)
3789    else    else
3790  #endif  #endif
3791      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3792  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
3793  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3794    if (context->length >= 4)    if (context->length >= 4)
3795      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3796    else    else
3797  #endif  #endif
3798      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3799  #endif  #elif defined COMPILE_PCRE32
3800  #endif /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3801    #endif /* COMPILE_PCRE[8|16|32] */
3802    context->sourcereg = TMP2;    context->sourcereg = TMP2;
3803    }    }
3804    
# Line 3534  do Line 3812  do
3812  #endif  #endif
3813    
3814    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3815  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3816    
3817    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3818    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3549  do Line 3827  do
3827      }      }
3828    context->ucharptr++;    context->ucharptr++;
3829    
3830  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3831    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))
3832  #else  #else
3833    if (context->ucharptr >= 2 || context->length == 0)    if (context->ucharptr >= 2 || context->length == 0)
# Line 3557  do Line 3835  do
3835      {      {
3836      if (context->length >= 4)      if (context->length >= 4)
3837        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  
3838      else if (context->length >= 2)      else if (context->length >= 2)
3839        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);
3840    #if defined COMPILE_PCRE8
3841      else if (context->length >= 1)      else if (context->length >= 1)
3842        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);
3843  #else  #endif /* COMPILE_PCRE8 */
     else if (context->length >= 2)  
       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
3844      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3845    
3846      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3599  do Line 3874  do
3874    
3875  #else  #else
3876    
3877    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3878  #ifdef COMPILE_PCRE8    if (context->length >= 1)
3879    if (context->length > 0)      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3880      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  
3881    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3882    
3883    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3651  return cc; Line 3922  return cc;
3922      } \      } \
3923    charoffset = (value);    charoffset = (value);
3924    
3925  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)
3926  {  {
3927  DEFINE_COMPILER;  DEFINE_COMPILER;
3928  jump_list *found = NULL;  jump_list *found = NULL;
3929  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;
3930  unsigned int c;  pcre_int32 c, charoffset;
3931  int compares;  const pcre_uint32 *other_cases;
3932  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
3933  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
3934    int compares, invertcmp, numberofcmps;
3935  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3936  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
3937  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
3938  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
3939  unsigned int typeoffset;  pcre_int32 typeoffset;
3940  #endif  #endif
 int invertcmp, numberofcmps;  
 unsigned int charoffset;  
3941    
3942  /* Although SUPPORT_UTF must be defined, we are  /* Although SUPPORT_UTF must be defined, we are
3943     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 3958  if ((*cc++ & XCL_MAP) != 0)
3958      {      {
3959      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3960      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3961      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
3962      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3963      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);
3964      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 4035  while (*cc != XCL_END)
4035        needschar = TRUE;        needschar = TRUE;
4036        break;        break;
4037    
4038          case PT_CLIST:
4039          case PT_UCNC:
4040          needschar = TRUE;
4041          break;
4042    
4043        default:        default:
4044        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
4045        break;        break;
# Line 3801  if (needstype || needsscript) Line 4076  if (needstype || needsscript)
4076      {      {
4077      if (scriptreg == TMP1)      if (scriptreg == TMP1)
4078        {        {
4079        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));
4080        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
4081        }        }
4082      else      else
4083        {        {
4084        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
4085        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));
4086        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
4087        }        }
4088      }      }
# Line 3843  while (*cc != XCL_END) Line 4118  while (*cc != XCL_END)
4118      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4119        {        {
4120        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);
4121        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);
4122        numberofcmps++;        numberofcmps++;
4123        }        }
4124      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4125        {        {
4126        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);
4127        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);
4128        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4129        numberofcmps = 0;        numberofcmps = 0;
4130        }        }
# Line 3882  while (*cc != XCL_END) Line 4157  while (*cc != XCL_END)
4157      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4158        {        {
4159        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);
4160        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);
4161        numberofcmps++;        numberofcmps++;
4162        }        }
4163      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4164        {        {
4165        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);
4166        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);
4167        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4168        numberofcmps = 0;        numberofcmps = 0;
4169        }        }
# Line 3919  while (*cc != XCL_END) Line 4194  while (*cc != XCL_END)
4194    
4195        case PT_LAMP:        case PT_LAMP:
4196        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);
4197        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4198        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);
4199        COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4200        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);
4201        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);
4202        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4203        break;        break;
4204    
# Line 3950  while (*cc != XCL_END) Line 4225  while (*cc != XCL_END)
4225          }          }
4226        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4227        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);
4228        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4229        if (*cc == PT_SPACE)        if (*cc == PT_SPACE)
4230          JUMPHERE(jump);          JUMPHERE(jump);
4231    
4232        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4233        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);
4234        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);
4235        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4236        break;        break;
4237    
4238        case PT_WORD:        case PT_WORD:
4239        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);
4240        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4241        /* ... fall through */        /* Fall through. */
4242    
4243        case PT_ALNUM:        case PT_ALNUM:
4244        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
4245        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);
4246        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);
4247        SET_TYPE_OFFSET(ucp_Nd);        SET_TYPE_OFFSET(ucp_Nd);
4248        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);
4249        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);
4250          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4251          break;
4252    
4253          case PT_CLIST:
4254          other_cases = PRIV(ucd_caseless_sets) + cc[1];
4255    
4256          /* At least three characters are required.
4257             Otherwise this case would be handled by the normal code path. */
4258          SLJIT_ASSERT(other_cases[0] != NOTACHAR && other_cases[1] != NOTACHAR && other_cases[2] != NOTACHAR);
4259          SLJIT_ASSERT(other_cases[0] < other_cases[1] && other_cases[1] < other_cases[2]);
4260    
4261          /* Optimizing character pairs, if their difference is power of 2. */
4262          if (is_powerof2(other_cases[1] ^ other_cases[0]))
4263            {
4264            if (charoffset == 0)
4265              OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4266            else
4267              {
4268              OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4269              OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4270              }
4271            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[1]);
4272            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4273            other_cases += 2;
4274            }
4275          else if (is_powerof2(other_cases[2] ^ other_cases[1]))
4276            {
4277            if (charoffset == 0)
4278              OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[2] ^ other_cases[1]);
4279            else
4280              {
4281              OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4282              OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4283              }
4284            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[2]);
4285            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4286    
4287            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, other_cases[0] - charoffset);
4288            OP_FLAGS(SLJIT_OR | ((other_cases[3] == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4289    
4290            other_cases += 3;
4291            }
4292          else
4293            {
4294            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4295            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4296            }
4297    
4298          while (*other_cases != NOTACHAR)
4299            {
4300            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4301            OP_FLAGS(SLJIT_OR | ((*other_cases == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4302            }
4303          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4304          break;
4305    
4306          case PT_UCNC:
4307          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);
4308          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4309          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);
4310          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4311          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);
4312          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4313    
4314          SET_CHAR_OFFSET(0xa0);
4315          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);
4316          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4317          SET_CHAR_OFFSET(0);
4318          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
4319          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4320        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4321        break;        break;
4322        }        }
# Line 3992  if (found != NULL) Line 4337  if (found != NULL)
4337    
4338  #endif  #endif
4339    
4340  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)
4341  {  {
4342  DEFINE_COMPILER;  DEFINE_COMPILER;
4343  int length;  int length;
4344  unsigned int c, oc, bit;  unsigned int c, oc, bit;
4345  compare_context context;  compare_context context;
4346  struct sljit_jump *jump[4];  struct sljit_jump *jump[4];
4347    jump_list *end_list;
4348  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4349  struct sljit_label *label;  struct sljit_label *label;
4350  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4067  switch(type) Line 4413  switch(type)
4413    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4414      {      {
4415      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);
4416        end_list = NULL;
4417      if (common->mode != JIT_PARTIAL_HARD_COMPILE)      if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4418        jump[1] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);        add_jump(compiler, &end_list, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
4419      else      else
4420        jump[1] = check_str_end(common);        check_str_end(common, &end_list);
4421    
4422      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4423      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff));      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff));
4424      if (jump[1] != NULL)      set_jumps(end_list, LABEL());
       JUMPHERE(jump[1]);  
4425      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4426      }      }
4427    else    else
# Line 4089  switch(type) Line 4435  switch(type)
4435      {      {
4436      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4437      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));
4438  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16
4439    #if defined COMPILE_PCRE8
4440      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4441      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);
4442      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4443  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
4444      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
4445      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
4446      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);
4447      COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4448      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4449      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4450  #endif /* COMPILE_PCRE16 */  #endif
 #endif /* COMPILE_PCRE8 */  
4451      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4452    #endif /* COMPILE_PCRE[8|16] */
4453      return cc;      return cc;
4454      }      }
4455  #endif  #endif
# Line 4124  switch(type) Line 4470  switch(type)
4470    propdata[2] = cc[0];    propdata[2] = cc[0];
4471    propdata[3] = cc[1];    propdata[3] = cc[1];
4472    propdata[4] = XCL_END;    propdata[4] = XCL_END;
4473    compile_xclass_trypath(common, propdata, backtracks);    compile_xclass_matchingpath(common, propdata, backtracks);
4474    return cc + 2;    return cc + 2;
4475  #endif  #endif
4476  #endif  #endif
# Line 4134  switch(type) Line 4480  switch(type)
4480    read_char(common);    read_char(common);
4481    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
4482    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
4483      end_list = NULL;
4484    if (common->mode != JIT_PARTIAL_HARD_COMPILE)    if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4485      jump[1] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      add_jump(compiler, &end_list, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
4486    else    else
4487      jump[1] = check_str_end(common);      check_str_end(common, &end_list);
4488    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4489    jump[2] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL);    jump[1] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL);
4490    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));
4491    jump[3] = JUMP(SLJIT_JUMP);    jump[2] = JUMP(SLJIT_JUMP);
4492    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4493    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);
4494      set_jumps(end_list, LABEL());
4495    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
4496    JUMPHERE(jump[2]);    JUMPHERE(jump[2]);
   JUMPHERE(jump[3]);  
4497    return cc;    return cc;
4498    
4499    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
# Line 4170  switch(type) Line 4517  switch(type)
4517    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4518    read_char(common);    read_char(common);
4519    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4520    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));
4521    add_jump(compiler, backtracks, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, ucp_Mn - ucp_Mc));    /* Optimize register allocation: use a real register. */
4522      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
4523      OP1(SLJIT_MOV_UB, STACK_TOP, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4524    
4525    label = LABEL();    label = LABEL();
4526    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);
4527    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
4528    read_char(common);    read_char(common);
4529    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4530    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));
4531    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);
4532    
4533      OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);
4534      OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STACK_TOP), (sljit_sw)PRIV(ucp_gbtable));
4535      OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);
4536      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4537      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4538      JUMPTO(SLJIT_C_NOT_ZERO, label);
4539    
4540    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
4541    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4542      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
4543    
4544    if (common->mode == JIT_PARTIAL_HARD_COMPILE)    if (common->mode == JIT_PARTIAL_HARD_COMPILE)
4545      {      {
4546      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 4564  switch(type)
4564        {        {
4565        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);
4566        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);
4567        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS);
4568        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);
4569        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);
4570        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));
4571        check_partial(common, TRUE);        check_partial(common, TRUE);
4572        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
# Line 4308  switch(type) Line 4666  switch(type)
4666    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));
4667    
4668    if (!common->endonly)    if (!common->endonly)
4669      compile_char1_trypath(common, OP_EODN, cc, backtracks);      compile_char1_matchingpath(common, OP_EODN, cc, backtracks);
4670    else    else
4671      {      {
4672      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 4746  switch(type)
4746      }      }
4747    oc = char_othercase(common, c);    oc = char_othercase(common, c);
4748    bit = c ^ oc;    bit = c ^ oc;
4749    if (ispowerof2(bit))    if (is_powerof2(bit))
4750      {      {
4751      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4752      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));
4753      return cc + length;      return cc + length;
4754      }      }
4755    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);
4756    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4757    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);
4758    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);
4759    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
4760    return cc + length;    return cc + length;
4761    
# Line 4424  switch(type) Line 4782  switch(type)
4782        /* Skip the variable-length character. */        /* Skip the variable-length character. */
4783        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));
4784        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4785        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);
4786        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4787        JUMPHERE(jump[0]);        JUMPHERE(jump[0]);
4788        return cc + 1;        return cc + 1;
# Line 4449  switch(type) Line 4807  switch(type)
4807      {      {
4808      oc = char_othercase(common, c);      oc = char_othercase(common, c);
4809      bit = c ^ oc;      bit = c ^ oc;
4810      if (ispowerof2(bit))      if (is_powerof2(bit))
4811        {        {
4812        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4813        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 4845  switch(type)
4845  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4846    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4847    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4848    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4849    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4850    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);
4851    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 4497  switch(type) Line 4855  switch(type)
4855  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4856    return cc + 32 / sizeof(pcre_uchar);    return cc + 32 / sizeof(pcre_uchar);
4857    
4858  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4859    case OP_XCLASS:    case OP_XCLASS:
4860    compile_xclass_trypath(common, cc + LINK_SIZE, backtracks);    compile_xclass_matchingpath(common, cc + LINK_SIZE, backtracks);
4861    return cc + GET(cc, 0) - 1;    return cc + GET(cc, 0) - 1;
4862  #endif  #endif
4863    
# Line 4533  SLJIT_ASSERT_STOP(); Line 4891  SLJIT_ASSERT_STOP();
4891  return cc;  return cc;
4892  }  }
4893    
4894  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)
4895  {  {
4896  /* This function consumes at least one input character. */  /* This function consumes at least one input character. */
4897  /* 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 4954  if (context.length > 0)
4954    }    }
4955    
4956  /* A non-fixed length character will be checked if length == 0. */  /* A non-fixed length character will be checked if length == 0. */
4957  return compile_char1_trypath(common, *cc, cc + 1, backtracks);  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);
4958  }  }
4959    
4960  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 4969  if (!common->jscript_compat)
4969      {      {
4970      /* OVECTOR(1) contains the "string begin - 1" constant. */      /* OVECTOR(1) contains the "string begin - 1" constant. */
4971      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));
4972      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4973      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));
4974      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);
4975      return JUMP(SLJIT_C_NOT_ZERO);      return JUMP(SLJIT_C_NOT_ZERO);
4976      }      }
4977    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 4980  return CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT
4980  }  }
4981    
4982  /* Forward definitions. */  /* Forward definitions. */
4983  static void compile_trypath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);
4984  static void compile_backtrackpath(compiler_common *, struct backtrack_common *);  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);
4985    
4986  #define PUSH_BACKTRACK(size, ccstart, error) \  #define PUSH_BACKTRACK(size, ccstart, error) \
4987    do \    do \
# Line 4653  static void compile_backtrackpath(compil Line 5011  static void compile_backtrackpath(compil
5011    
5012  #define BACKTRACK_AS(type) ((type *)backtrack)  #define BACKTRACK_AS(type) ((type *)backtrack)
5013    
5014  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)
5015  {  {
5016  DEFINE_COMPILER;  DEFINE_COMPILER;
5017  int offset = GET2(cc, 1) << 1;  int offset = GET2(cc, 1) << 1;
# Line 4669  if (withchecks && !common->jscript_compa Line 5027  if (withchecks && !common->jscript_compa
5027  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5028  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5029    {    {
5030    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);
5031    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));
5032    if (withchecks)    if (withchecks)
5033      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5034    
5035    /* Needed to save important temporary registers. */    /* Needed to save important temporary registers. */
5036    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5037    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
5038    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);
5039    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));
5040    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5041    if (common->mode == JIT_COMPILE)    if (common->mode == JIT_COMPILE)
# Line 4735  if (jump != NULL) Line 5093  if (jump != NULL)
5093  return cc + 1 + IMM2_SIZE;  return cc + 1 + IMM2_SIZE;
5094  }  }
5095    
5096  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)
5097  {  {
5098  DEFINE_COMPILER;  DEFINE_COMPILER;
5099  backtrack_common *backtrack;  backtrack_common *backtrack;
# Line 4790  if (!minimize) Line 5148  if (!minimize)
5148      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5149      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5150      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5151      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));
5152      zerolength = compile_ref_checks(common, ccbegin, NULL);      zerolength = compile_ref_checks(common, ccbegin, NULL);
5153      /* Restore if not zero length. */      /* Restore if not zero length. */
5154      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));
5155      }      }
5156    else    else
5157      {      {
# Line 4806  if (!minimize) Line 5164  if (!minimize)
5164      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
5165    
5166    label = LABEL();    label = LABEL();
5167    compile_ref_trypath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);
5168    
5169    if (min > 1 || max > 1)    if (min > 1 || max > 1)
5170      {      {
# Line 4834  if (!minimize) Line 5192  if (!minimize)
5192      }      }
5193    
5194    JUMPHERE(zerolength);    JUMPHERE(zerolength);
5195    BACKTRACK_AS(iterator_backtrack)->trypath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5196    
5197    decrease_call_count(common);    decrease_call_count(common);
5198    return cc;    return cc;
# Line 4854  if (min == 0) Line 5212  if (min == 0)
5212  else  else
5213    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);
5214    
5215  BACKTRACK_AS(iterator_backtrack)->trypath = LABEL();  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5216  if (max > 0)  if (max > 0)
5217    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));
5218    
5219  compile_ref_trypath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);
5220  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5221    
5222  if (min > 1)  if (min > 1)
# Line 4866  if (min > 1) Line 5224  if (min > 1)
5224    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
5225    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
5226    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5227    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);
5228    }    }
5229  else if (max > 0)  else if (max > 0)
5230    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 5237  decrease_call_count(common);
5237  return cc;  return cc;
5238  }  }
5239    
5240  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)
5241  {  {
5242  DEFINE_COMPILER;  DEFINE_COMPILER;
5243  backtrack_common *backtrack;  backtrack_common *backtrack;
5244  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5245  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5246  int start = GET(cc, 1);  int start = GET(cc, 1);
5247    pcre_uchar *start_cc;
5248    
5249  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5250    
5251    /* Inlining simple patterns. */
5252    if (get_framesize(common, common->start + start, TRUE) == no_stack)
5253      {
5254      start_cc = common->start + start;
5255      compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
5256      BACKTRACK_AS(recurse_backtrack)->inlined_pattern = TRUE;
5257      return cc + 1 + LINK_SIZE;
5258      }
5259    
5260  while (entry != NULL)  while (entry != NULL)
5261    {    {
5262    if (entry->start == start)    if (entry->start == start)
# Line 4936  add_jump(compiler, &backtrack->topbacktr Line 5305  add_jump(compiler, &backtrack->topbacktr
5305  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5306  }  }
5307    
5308  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)
5309    {
5310    const pcre_uchar *begin = arguments->begin;
5311    int *offset_vector = arguments->offsets;
5312    int offset_count = arguments->offset_count;
5313    int i;
5314    
5315    if (PUBL(callout) == NULL)
5316      return 0;
5317    
5318    callout_block->version = 2;
5319    callout_block->callout_data = arguments->callout_data;
5320    
5321    /* Offsets in subject. */
5322    callout_block->subject_length = arguments->end - arguments->begin;
5323    callout_block->start_match = (pcre_uchar*)callout_block->subject - arguments->begin;
5324    callout_block->current_position = (pcre_uchar*)callout_block->offset_vector - arguments->begin;
5325    #if defined COMPILE_PCRE8
5326    callout_block->subject = (PCRE_SPTR)begin;
5327    #elif defined COMPILE_PCRE16
5328    callout_block->subject = (PCRE_SPTR16)begin;
5329    #elif defined COMPILE_PCRE32
5330    callout_block->subject = (PCRE_SPTR32)begin;
5331    #endif
5332    
5333    /* Convert and copy the JIT offset vector to the offset_vector array. */
5334    callout_block->capture_top = 0;
5335    callout_block->offset_vector = offset_vector;
5336    for (i = 2; i < offset_count; i += 2)
5337      {
5338      offset_vector[i] = jit_ovector[i] - begin;
5339      offset_vector[i + 1] = jit_ovector[i + 1] - begin;
5340      if (jit_ovector[i] >= begin)
5341        callout_block->capture_top = i;
5342      }
5343    
5344    callout_block->capture_top = (callout_block->capture_top >> 1) + 1;
5345    if (offset_count > 0)
5346      offset_vector[0] = -1;
5347    if (offset_count > 1)
5348      offset_vector[1] = -1;
5349    return (*PUBL(callout))(callout_block);
5350    }
5351    
5352    /* Aligning to 8 byte. */
5353    #define CALLOUT_ARG_SIZE \
5354        (((int)sizeof(PUBL(callout_block)) + 7) & ~7)
5355    
5356    #define CALLOUT_ARG_OFFSET(arg) \
5357        (-CALLOUT_ARG_SIZE + SLJIT_OFFSETOF(PUBL(callout_block), arg))
5358    
5359    static SLJIT_INLINE pcre_uchar *compile_callout_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5360    {
5361