/[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 1303 by zherczeg, Fri Mar 29 09:01:20 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_mark = 0,
206      type_then_trap = 1
207    };
208    
209  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
210    
211  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
212  code generator. It is allocated by compile_trypath, and contains  code generator. It is allocated by compile_matchingpath, and contains
213  the aguments for compile_backtrackpath. Must be the first member  the aguments for compile_backtrackingpath. Must be the first member
214  of its descendants. */  of its descendants. */
215  typedef struct backtrack_common {  typedef struct backtrack_common {
216    /* Concatenation stack. */    /* Concatenation stack. */
# Line 205  typedef struct backtrack_common { Line 226  typedef struct backtrack_common {
226  typedef struct assert_backtrack {  typedef struct assert_backtrack {
227    backtrack_common common;    backtrack_common common;
228    jump_list *condfailed;    jump_list *condfailed;
229    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
230    int framesize;    int framesize;
231    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
232    int localptr;    int private_data_ptr;
233    /* For iterators. */    /* For iterators. */
234    struct sljit_label *trypath;    struct sljit_label *matchingpath;
235  } assert_backtrack;  } assert_backtrack;
236    
237  typedef struct bracket_backtrack {  typedef struct bracket_backtrack {
238    backtrack_common common;    backtrack_common common;
239    /* Where to coninue if an alternative is successfully matched. */    /* Where to coninue if an alternative is successfully matched. */
240    struct sljit_label *alttrypath;    struct sljit_label *alternative_matchingpath;
241    /* For rmin and rmax iterators. */    /* For rmin and rmax iterators. */
242    struct sljit_label *recursivetrypath;    struct sljit_label *recursive_matchingpath;
243    /* For greedy ? operator. */    /* For greedy ? operator. */
244    struct sljit_label *zerotrypath;    struct sljit_label *zero_matchingpath;
245    /* Contains the branches of a failed condition. */    /* Contains the branches of a failed condition. */
246    union {    union {
247      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
248      jump_list *condfailed;      jump_list *condfailed;
249      assert_backtrack *assert;      assert_backtrack *assert;
250      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
251      int framesize;      int framesize;
252    } u;    } u;
253    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
254    int localptr;    int private_data_ptr;
255  } bracket_backtrack;  } bracket_backtrack;
256    
257  typedef struct bracketpos_backtrack {  typedef struct bracketpos_backtrack {
258    backtrack_common common;    backtrack_common common;
259    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
260    int localptr;    int private_data_ptr;
261    /* Reverting stack is needed. */    /* Reverting stack is needed. */
262    int framesize;    int framesize;
263    /* Allocated stack size. */    /* Allocated stack size. */
# Line 245  typedef struct bracketpos_backtrack { Line 266  typedef struct bracketpos_backtrack {
266    
267  typedef struct braminzero_backtrack {  typedef struct braminzero_backtrack {
268    backtrack_common common;    backtrack_common common;
269    struct sljit_label *trypath;    struct sljit_label *matchingpath;
270  } braminzero_backtrack;  } braminzero_backtrack;
271    
272  typedef struct iterator_backtrack {  typedef struct iterator_backtrack {
273    backtrack_common common;    backtrack_common common;
274    /* Next iteration. */    /* Next iteration. */
275    struct sljit_label *trypath;    struct sljit_label *matchingpath;
276  } iterator_backtrack;  } iterator_backtrack;
277    
278  typedef struct recurse_entry {  typedef struct recurse_entry {
# Line 261  typedef struct recurse_entry { Line 282  typedef struct recurse_entry {
282    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
283    jump_list *calls;    jump_list *calls;
284    /* Points to the starting opcode. */    /* Points to the starting opcode. */
285    int start;    sljit_sw start;
286  } recurse_entry;  } recurse_entry;
287    
288  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
289    backtrack_common common;    backtrack_common common;
290      BOOL inlined_pattern;
291  } recurse_backtrack;  } recurse_backtrack;
292    
293    #define OP_THEN_TRAP OP_TABLE_LENGTH
294    
295    typedef struct then_trap_backtrack {
296      backtrack_common common;
297      /* If then_trap is not NULL, this structure contains the real
298      then_trap for the backtracking path. */
299      struct then_trap_backtrack *then_trap;
300      /* Points to the starting opcode. */
301      sljit_sw start;
302      /* Exit point for the then opcodes of this alternative. */
303      jump_list *quit;
304      /* Frame size of the current alternative. */
305      int framesize;
306    } then_trap_backtrack;
307    
308  #define MAX_RANGE_SIZE 6  #define MAX_RANGE_SIZE 6
309    
310  typedef struct compiler_common {  typedef struct compiler_common {
311      /* The sljit ceneric compiler. */
312    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
313      /* First byte code. */
314    pcre_uchar *start;    pcre_uchar *start;
315      /* Maps private data offset to each opcode. */
316    /* Opcode local area direct map. */    int *private_data_ptrs;
317    int *localptrs;    /* Tells whether the capturing bracket is optimized. */
318    int cbraptr;    pcre_uint8 *optimized_cbracket;
319    /* OVector starting point. Must be divisible by 2. */    /* Tells whether the starting offset is a target of then. */
320      pcre_uint8 *then_offsets;
321      /* Current position where a THEN must jump. */
322      then_trap_backtrack *then_trap;
323      /* Starting offset of private data for capturing brackets. */
324      int cbra_ptr;
325      /* Output vector starting point. Must be divisible by 2. */
326    int ovector_start;    int ovector_start;
327    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
328    int req_char_ptr;    int req_char_ptr;
329    /* Head of the last recursion. */    /* Head of the last recursion. */
330    int recursive_head;    int recursive_head_ptr;
331    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
332    int start_used_ptr;    int start_used_ptr;
333    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 291  typedef struct compiler_common { Line 336  typedef struct compiler_common {
336    int first_line_end;    int first_line_end;
337    /* Points to the marked string. */    /* Points to the marked string. */
338    int mark_ptr;    int mark_ptr;
339      /* Recursive control verb management chain. */
340      int control_head_ptr;
341      /* Points to the last matched capture block index. */
342      int capture_last_ptr;
343      /* Points to the starting position of the current match. */
344      int start_ptr;
345    
346    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
347    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
348    sljit_w lcc;    sljit_sw lcc;
349    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
350    int mode;    int mode;
351      /* \K is found in the pattern. */
352      BOOL has_set_som;
353      /* (*SKIP:arg) is found in the pattern. */
354      BOOL has_skip_arg;
355      /* (*THEN) is found in the pattern. */
356      BOOL has_then;
357      /* Needs to know the start position anytime. */
358      BOOL needs_start_ptr;
359      /* Currently in recurse or negative assert. */
360      BOOL local_exit;
361      /* Currently in a positive assert. */
362      BOOL positive_assert;
363    /* Newline control. */    /* Newline control. */
364    int nltype;    int nltype;
365    int newline;    int newline;
366    int bsr_nltype;    int bsr_nltype;
367    /* Dollar endonly. */    /* Dollar endonly. */
368    int endonly;    int endonly;
   BOOL has_set_som;  
369    /* Tables. */    /* Tables. */
370    sljit_w ctypes;    sljit_sw ctypes;
371    int digits[2 + MAX_RANGE_SIZE];    int digits[2 + MAX_RANGE_SIZE];
372    /* Named capturing brackets. */    /* Named capturing brackets. */
373    sljit_uw name_table;    sljit_uw name_table;
374    sljit_w name_count;    sljit_sw name_count;
375    sljit_w name_entry_size;    sljit_sw name_entry_size;
376    
377    /* Labels and jump lists. */    /* Labels and jump lists. */
378    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
379    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
380    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
381      struct sljit_label *accept_label;
382    stub_list *stubs;    stub_list *stubs;
383    recurse_entry *entries;    recurse_entry *entries;
384    recurse_entry *currententry;    recurse_entry *currententry;
385    jump_list *partialmatch;    jump_list *partialmatch;
386    jump_list *quit;    jump_list *quit;
387      jump_list *positive_assert_quit;
388      jump_list *forced_quit;
389    jump_list *accept;    jump_list *accept;
390    jump_list *calllimit;    jump_list *calllimit;
391    jump_list *stackalloc;    jump_list *stackalloc;
# Line 331  typedef struct compiler_common { Line 396  typedef struct compiler_common {
396    jump_list *vspace;    jump_list *vspace;
397    jump_list *casefulcmp;    jump_list *casefulcmp;
398    jump_list *caselesscmp;    jump_list *caselesscmp;
399      jump_list *reset_match;
400    BOOL jscript_compat;    BOOL jscript_compat;
401  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
402    BOOL utf;    BOOL utf;
403  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
404    BOOL use_ucp;    BOOL use_ucp;
405  #endif  #endif
406    #ifndef COMPILE_PCRE32
407    jump_list *utfreadchar;    jump_list *utfreadchar;
408    #endif
409  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
410    jump_list *utfreadtype8;    jump_list *utfreadtype8;
411  #endif  #endif
# Line 355  typedef struct compare_context { Line 423  typedef struct compare_context {
423  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
424    int ucharptr;    int ucharptr;
425    union {    union {
426      sljit_i asint;      sljit_si asint;
427      sljit_uh asushort;      sljit_uh asushort;
428  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
429      sljit_ub asbyte;      sljit_ub asbyte;
430      sljit_ub asuchars[4];      sljit_ub asuchars[4];
431  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
432      sljit_uh asuchars[2];      sljit_uh asuchars[2];
433  #endif  #elif defined COMPILE_PCRE32
434        sljit_ui asuchars[1];
435  #endif  #endif
436    } c;    } c;
437    union {    union {
438      sljit_i asint;      sljit_si asint;
439      sljit_uh asushort;      sljit_uh asushort;
440  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
441      sljit_ub asbyte;      sljit_ub asbyte;
442      sljit_ub asuchars[4];      sljit_ub asuchars[4];
443  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
444      sljit_uh asuchars[2];      sljit_uh asuchars[2];
445  #endif  #elif defined COMPILE_PCRE32
446        sljit_ui asuchars[1];
447  #endif  #endif
448    } oc;    } oc;
449  #endif  #endif
450  } compare_context;  } compare_context;
451    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
452  /* Undefine sljit macros. */  /* Undefine sljit macros. */
453  #undef CMP  #undef CMP
454    
455  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
456  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
457    
458  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
459  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
460  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
461  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
462  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
463  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
464  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
465  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
466  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
467  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
468    
469  /* Locals layout. */  /* Local space layout. */
470  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
471  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
472  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
473  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
474  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
475  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
476  /* Max limit of recursions. */  /* Max limit of recursions. */
477  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define CALL_LIMIT       (4 * sizeof(sljit_sw))
478  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
479  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
480  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
481  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. */
482  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
483  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
484  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * sizeof(sljit_sw))
485  #define PRIV_DATA(cc)    (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
486    
487  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
488  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
489  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
490  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
491  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
492  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
493    #elif defined COMPILE_PCRE32
494    #define MOV_UCHAR  SLJIT_MOV_UI
495    #define MOVU_UCHAR SLJIT_MOVU_UI
496  #else  #else
497  #error Unsupported compiling mode  #error Unsupported compiling mode
498  #endif  #endif
 #endif  
499    
500  /* Shortcuts. */  /* Shortcuts. */
501  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 449  the start pointers when the end of the c Line 512  the start pointers when the end of the c
512    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
513  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
514    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
515    #define SET_LABEL(jump, label) \
516      sljit_set_label((jump), (label))
517  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
518    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
519  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
520    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))
521  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
522    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
523  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
524    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
525    
# Line 469  return cc; Line 534  return cc;
534    
535  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
536   next_opcode   next_opcode
537   get_localspace   get_private_data_length
538   set_localptrs   set_private_data_ptrs
539   get_framesize   get_framesize
540   init_frame   init_frame
541   get_localsize   get_private_data_copy_length
542   copy_locals   copy_private_data
543   compile_trypath   compile_matchingpath
544   compile_backtrackpath   compile_backtrackingpath
545  */  */
546    
547  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 562  switch(*cc)
562    case OP_WORDCHAR:    case OP_WORDCHAR:
563    case OP_ANY:    case OP_ANY:
564    case OP_ALLANY:    case OP_ALLANY:
565      case OP_NOTPROP:
566      case OP_PROP:
567    case OP_ANYNL:    case OP_ANYNL:
568    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
569    case OP_HSPACE:    case OP_HSPACE:
# Line 509  switch(*cc) Line 576  switch(*cc)
576    case OP_CIRCM:    case OP_CIRCM:
577    case OP_DOLL:    case OP_DOLL:
578    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:  
579    case OP_CRSTAR:    case OP_CRSTAR:
580    case OP_CRMINSTAR:    case OP_CRMINSTAR:
581    case OP_CRPLUS:    case OP_CRPLUS:
582    case OP_CRMINPLUS:    case OP_CRMINPLUS:
583    case OP_CRQUERY:    case OP_CRQUERY:
584    case OP_CRMINQUERY:    case OP_CRMINQUERY:
585      case OP_CRRANGE:
586      case OP_CRMINRANGE:
587      case OP_CLASS:
588      case OP_NCLASS:
589      case OP_REF:
590      case OP_REFI:
591      case OP_RECURSE:
592      case OP_CALLOUT:
593      case OP_ALT:
594      case OP_KET:
595      case OP_KETRMAX:
596      case OP_KETRMIN:
597      case OP_KETRPOS:
598      case OP_REVERSE:
599      case OP_ASSERT:
600      case OP_ASSERT_NOT:
601      case OP_ASSERTBACK:
602      case OP_ASSERTBACK_NOT:
603      case OP_ONCE:
604      case OP_ONCE_NC:
605      case OP_BRA:
606      case OP_BRAPOS:
607      case OP_CBRA:
608      case OP_CBRAPOS:
609      case OP_COND:
610      case OP_SBRA:
611      case OP_SBRAPOS:
612      case OP_SCBRA:
613      case OP_SCBRAPOS:
614      case OP_SCOND:
615      case OP_CREF:
616      case OP_NCREF:
617      case OP_RREF:
618      case OP_NRREF:
619    case OP_DEF:    case OP_DEF:
620    case OP_BRAZERO:    case OP_BRAZERO:
621    case OP_BRAMINZERO:    case OP_BRAMINZERO:
622    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
623      case OP_PRUNE:
624      case OP_SKIP:
625      case OP_THEN:
626    case OP_COMMIT:    case OP_COMMIT:
627    case OP_FAIL:    case OP_FAIL:
628    case OP_ACCEPT:    case OP_ACCEPT:
629    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
630      case OP_CLOSE:
631    case OP_SKIPZERO:    case OP_SKIPZERO:
632    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
633    
634    case OP_CHAR:    case OP_CHAR:
635    case OP_CHARI:    case OP_CHARI:
# Line 551  switch(*cc) Line 641  switch(*cc)
641    case OP_MINPLUS:    case OP_MINPLUS:
642    case OP_QUERY:    case OP_QUERY:
643    case OP_MINQUERY:    case OP_MINQUERY:
644      case OP_UPTO:
645      case OP_MINUPTO:
646      case OP_EXACT:
647    case OP_POSSTAR:    case OP_POSSTAR:
648    case OP_POSPLUS:    case OP_POSPLUS:
649    case OP_POSQUERY:    case OP_POSQUERY:
650      case OP_POSUPTO:
651    case OP_STARI:    case OP_STARI:
652    case OP_MINSTARI:    case OP_MINSTARI:
653    case OP_PLUSI:    case OP_PLUSI:
654    case OP_MINPLUSI:    case OP_MINPLUSI:
655    case OP_QUERYI:    case OP_QUERYI:
656    case OP_MINQUERYI:    case OP_MINQUERYI:
657      case OP_UPTOI:
658      case OP_MINUPTOI:
659      case OP_EXACTI:
660    case OP_POSSTARI:    case OP_POSSTARI:
661    case OP_POSPLUSI:    case OP_POSPLUSI:
662    case OP_POSQUERYI:    case OP_POSQUERYI:
663      case OP_POSUPTOI:
664    case OP_NOTSTAR:    case OP_NOTSTAR:
665    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
666    case OP_NOTPLUS:    case OP_NOTPLUS:
667    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
668    case OP_NOTQUERY:    case OP_NOTQUERY:
669    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
670      case OP_NOTUPTO:
671      case OP_NOTMINUPTO:
672      case OP_NOTEXACT:
673    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
674    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
675    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
676      case OP_NOTPOSUPTO:
677    case OP_NOTSTARI:    case OP_NOTSTARI:
678    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
679    case OP_NOTPLUSI:    case OP_NOTPLUSI:
680    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
681    case OP_NOTQUERYI:    case OP_NOTQUERYI:
682    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:  
683    case OP_NOTUPTOI:    case OP_NOTUPTOI:
684    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
685    case OP_NOTEXACTI:    case OP_NOTEXACTI:
686      case OP_NOTPOSSTARI:
687      case OP_NOTPOSPLUSI:
688      case OP_NOTPOSQUERYI:
689    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
690    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
691  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
692    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
693  #endif  #endif
694    return cc;    return cc;
695    
696    case OP_NOTPROP:    /* Special cases. */
697    case OP_PROP:    case OP_TYPESTAR:
698    return cc + 1 + 2;    case OP_TYPEMINSTAR:
699      case OP_TYPEPLUS:
700      case OP_TYPEMINPLUS:
701      case OP_TYPEQUERY:
702      case OP_TYPEMINQUERY:
703    case OP_TYPEUPTO:    case OP_TYPEUPTO:
704    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
705    case OP_TYPEEXACT:    case OP_TYPEEXACT:
706      case OP_TYPEPOSSTAR:
707      case OP_TYPEPOSPLUS:
708      case OP_TYPEPOSQUERY:
709    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
710    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;  
711    
712    case OP_CRRANGE:    case OP_ANYBYTE:
713    case OP_CRMINRANGE:  #ifdef SUPPORT_UTF
714    return cc + 1 + 2 * IMM2_SIZE;    if (common->utf) return NULL;
715    #endif
716    case OP_CLASS:    return cc + 1;
   case OP_NCLASS:  
   return cc + 1 + 32 / sizeof(pcre_uchar);  
717    
718  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
719    case OP_XCLASS:    case OP_XCLASS:
720    return cc + GET(cc, 1);    return cc + GET(cc, 1);
721  #endif  #endif
722    
   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;  
   
723    case OP_MARK:    case OP_MARK:
724      case OP_PRUNE_ARG:
725      case OP_SKIP_ARG:
726      case OP_THEN_ARG:
727    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
728    
729    default:    default:
730      /* All opcodes are supported now! */
731      SLJIT_ASSERT_STOP();
732    return NULL;    return NULL;
733    }    }
734  }  }
735    
736  #define CASE_ITERATOR_LOCAL1 \  #define CASE_ITERATOR_PRIVATE_DATA_1 \
737      case OP_MINSTAR: \      case OP_MINSTAR: \
738      case OP_MINPLUS: \      case OP_MINPLUS: \
739      case OP_QUERY: \      case OP_QUERY: \
# Line 693  switch(*cc) Line 751  switch(*cc)
751      case OP_NOTQUERYI: \      case OP_NOTQUERYI: \
752      case OP_NOTMINQUERYI:      case OP_NOTMINQUERYI:
753    
754  #define CASE_ITERATOR_LOCAL2A \  #define CASE_ITERATOR_PRIVATE_DATA_2A \
755      case OP_STAR: \      case OP_STAR: \
756      case OP_PLUS: \      case OP_PLUS: \
757      case OP_STARI: \      case OP_STARI: \
# Line 703  switch(*cc) Line 761  switch(*cc)
761      case OP_NOTSTARI: \      case OP_NOTSTARI: \
762      case OP_NOTPLUSI:      case OP_NOTPLUSI:
763    
764  #define CASE_ITERATOR_LOCAL2B \  #define CASE_ITERATOR_PRIVATE_DATA_2B \
765      case OP_UPTO: \      case OP_UPTO: \
766      case OP_MINUPTO: \      case OP_MINUPTO: \
767      case OP_UPTOI: \      case OP_UPTOI: \
# Line 713  switch(*cc) Line 771  switch(*cc)
771      case OP_NOTUPTOI: \      case OP_NOTUPTOI: \
772      case OP_NOTMINUPTOI:      case OP_NOTMINUPTOI:
773    
774  #define CASE_ITERATOR_TYPE_LOCAL1 \  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
775      case OP_TYPEMINSTAR: \      case OP_TYPEMINSTAR: \
776      case OP_TYPEMINPLUS: \      case OP_TYPEMINPLUS: \
777      case OP_TYPEQUERY: \      case OP_TYPEQUERY: \
778      case OP_TYPEMINQUERY:      case OP_TYPEMINQUERY:
779    
780  #define CASE_ITERATOR_TYPE_LOCAL2A \  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
781      case OP_TYPESTAR: \      case OP_TYPESTAR: \
782      case OP_TYPEPLUS:      case OP_TYPEPLUS:
783    
784  #define CASE_ITERATOR_TYPE_LOCAL2B \  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
785      case OP_TYPEUPTO: \      case OP_TYPEUPTO: \
786      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
787    
# Line 752  switch(*cc) Line 810  switch(*cc)
810    }    }
811  }  }
812    
813  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)
814  {  {
815  int localspace = 0;  int private_data_length = 0;
816  pcre_uchar *alternative;  pcre_uchar *alternative;
817    pcre_uchar *name;
818  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
819  int space, size, bracketlen;  int space, size, i;
820    pcre_uint32 bracketlen;
821    
822  /* 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. */
823  while (cc < ccend)  while (cc < ccend)
# Line 772  while (cc < ccend) Line 832  while (cc < ccend)
832      cc += 1;      cc += 1;
833      break;      break;
834    
835        case OP_REF:
836        case OP_REFI:
837        common->optimized_cbracket[GET2(cc, 1)] = 0;
838        cc += 1 + IMM2_SIZE;
839        break;
840    
841      case OP_ASSERT:      case OP_ASSERT:
842      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
843      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 781  while (cc < ccend) Line 847  while (cc < ccend)
847      case OP_BRAPOS:      case OP_BRAPOS:
848      case OP_SBRA:      case OP_SBRA:
849      case OP_SBRAPOS:      case OP_SBRAPOS:
850      case OP_SCOND:      private_data_length += sizeof(sljit_sw);
     localspace += sizeof(sljit_w);  
851      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
852      break;      break;
853    
854      case OP_CBRAPOS:      case OP_CBRAPOS:
855      case OP_SCBRAPOS:      case OP_SCBRAPOS:
856      localspace += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
857        common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
858      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
859      break;      break;
860    
861      case OP_COND:      case OP_COND:
862      /* Might be a hidden SCOND. */      case OP_SCOND:
863      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
864      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
865        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
866          return -1;
867    
868        if (*cc == OP_COND)
869          {
870          /* Might be a hidden SCOND. */
871          alternative = cc + GET(cc, 1);
872          if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
873            private_data_length += sizeof(sljit_sw);
874          }
875        else
876          private_data_length += sizeof(sljit_sw);
877      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
878      break;      break;
879    
880        case OP_CREF:
881        i = GET2(cc, 1);
882        common->optimized_cbracket[i] = 0;
883        cc += 1 + IMM2_SIZE;
884        break;
885    
886        case OP_NCREF:
887        bracketlen = GET2(cc, 1);
888        name = (pcre_uchar *)common->name_table;
889        alternative = name;
890        for (i = 0; i < common->name_count; i++)
891          {
892          if (GET2(name, 0) == bracketlen) break;
893          name += common->name_entry_size;
894          }
895        SLJIT_ASSERT(i != common->name_count);
896    
897        for (i = 0; i < common->name_count; i++)
898          {
899          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
900            common->optimized_cbracket[GET2(alternative, 0)] = 0;
901          alternative += common->name_entry_size;
902          }
903        bracketlen = 0;
904        cc += 1 + IMM2_SIZE;
905        break;
906    
907      case OP_BRA:      case OP_BRA:
908      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
909      break;      break;
# Line 809  while (cc < ccend) Line 913  while (cc < ccend)
913      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
914      break;      break;
915    
916      CASE_ITERATOR_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
917      space = 1;      space = 1;
918      size = -2;      size = -2;
919      break;      break;
920    
921      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
922      space = 2;      space = 2;
923      size = -2;      size = -2;
924      break;      break;
925    
926      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
927      space = 2;      space = 2;
928      size = -(2 + IMM2_SIZE);      size = -(2 + IMM2_SIZE);
929      break;      break;
930    
931      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
932      space = 1;      space = 1;
933      size = 1;      size = 1;
934      break;      break;
935    
936      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
937      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
938        space = 2;        space = 2;
939      size = 1;      size = 1;
940      break;      break;
941    
942      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
943      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)
944        space = 2;        space = 2;
945      size = 1 + IMM2_SIZE;      size = 1 + IMM2_SIZE;
# Line 856  while (cc < ccend) Line 960  while (cc < ccend)
960    
961      case OP_RECURSE:      case OP_RECURSE:
962      /* Set its value only once. */      /* Set its value only once. */
963      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
964        {        {
965        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
966        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
967        }        }
968      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
969      break;      break;
970    
971        case OP_CALLOUT:
972        if (common->capture_last_ptr == 0)
973          {
974          common->capture_last_ptr = common->ovector_start;
975          common->ovector_start += sizeof(sljit_sw);
976          }
977        cc += 2 + 2 * LINK_SIZE;
978        break;
979    
980        case OP_THEN_ARG:
981        common->has_then = TRUE;
982        common->control_head_ptr = 1;
983        /* Fall through. */
984    
985        case OP_PRUNE_ARG:
986        common->needs_start_ptr = TRUE;
987        /* Fall through. */
988    
989      case OP_MARK:      case OP_MARK:
990      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
991        {        {
992        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
993        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
994        }        }
995      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
996      break;      break;
997    
998        case OP_THEN:
999        common->has_then = TRUE;
1000        common->control_head_ptr = 1;
1001        /* Fall through. */
1002    
1003        case OP_PRUNE:
1004        case OP_SKIP:
1005        common->needs_start_ptr = TRUE;
1006        cc += 1;
1007        break;
1008    
1009        case OP_SKIP_ARG:
1010        common->control_head_ptr = 1;
1011        common->has_skip_arg = TRUE;
1012        cc += 1 + 2 + cc[1];
1013        break;
1014    
1015      default:      default:
1016      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1017      if (cc == NULL)      if (cc == NULL)
# Line 881  while (cc < ccend) Line 1020  while (cc < ccend)
1020      }      }
1021    
1022    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1023      localspace += sizeof(sljit_w) * space;      private_data_length += sizeof(sljit_sw) * space;
1024    
1025    if (size != 0)    if (size != 0)
1026      {      {
# Line 896  while (cc < ccend) Line 1035  while (cc < ccend)
1035        cc += size;        cc += size;
1036      }      }
1037    
1038    if (bracketlen > 0)    if (bracketlen != 0)
1039      {      {
1040      if (cc >= end)      if (cc >= end)
1041        {        {
# Line 907  while (cc < ccend) Line 1046  while (cc < ccend)
1046      cc += bracketlen;      cc += bracketlen;
1047      }      }
1048    }    }
1049  return localspace;  return private_data_length;
1050  }  }
1051    
1052  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)
1053  {  {
1054  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1055  pcre_uchar *alternative;  pcre_uchar *alternative;
# Line 934  while (cc < ccend) Line 1073  while (cc < ccend)
1073      case OP_SBRA:      case OP_SBRA:
1074      case OP_SBRAPOS:      case OP_SBRAPOS:
1075      case OP_SCOND:      case OP_SCOND:
1076      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1077      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1078      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1079      break;      break;
1080    
1081      case OP_CBRAPOS:      case OP_CBRAPOS:
1082      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1083      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1084      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1085      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1086      break;      break;
1087    
# Line 951  while (cc < ccend) Line 1090  while (cc < ccend)
1090      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1091      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1092        {        {
1093        common->localptrs[cc - common->start] = localptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1094        localptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1095        }        }
1096      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1097      break;      break;
# Line 966  while (cc < ccend) Line 1105  while (cc < ccend)
1105      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1106      break;      break;
1107    
1108      CASE_ITERATOR_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
1109      space = 1;      space = 1;
1110      size = -2;      size = -2;
1111      break;      break;
1112    
1113      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
1114      space = 2;      space = 2;
1115      size = -2;      size = -2;
1116      break;      break;
1117    
1118      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
1119      space = 2;      space = 2;
1120      size = -(2 + IMM2_SIZE);      size = -(2 + IMM2_SIZE);
1121      break;      break;
1122    
1123      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1124      space = 1;      space = 1;
1125      size = 1;      size = 1;
1126      break;      break;
1127    
1128      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1129      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1130        space = 2;        space = 2;
1131      size = 1;      size = 1;
1132      break;      break;
1133    
1134      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1135      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)
1136        space = 2;        space = 2;
1137      size = 1 + IMM2_SIZE;      size = 1 + IMM2_SIZE;
# Line 1019  while (cc < ccend) Line 1158  while (cc < ccend)
1158    
1159    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1160      {      {
1161      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1162      localptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1163      }      }
1164    
1165    if (size != 0)    if (size != 0)
# Line 1049  while (cc < ccend) Line 1188  while (cc < ccend)
1188    }    }
1189  }  }
1190    
1191  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1192  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL* needs_control_head)
1193  {  {
 pcre_uchar *ccend = bracketend(cc);  
1194  int length = 0;  int length = 0;
1195  BOOL possessive = FALSE;  int possessive = 0;
1196    BOOL stack_restore = FALSE;
1197  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1198  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1199    /* The last capture is a local variable even for recursions. */
1200    BOOL capture_last_found = FALSE;
1201    
1202    #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1203    SLJIT_ASSERT(common->control_head_ptr != 0);
1204    *needs_control_head = TRUE;
1205    #else
1206    *needs_control_head = FALSE;
1207    #endif
1208    
1209  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (ccend == NULL)
1210    {    {
1211    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1212    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1213        {
1214        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1215        /* This is correct regardless of common->capture_last_ptr. */
1216        capture_last_found = TRUE;
1217        }
1218      cc = next_opcode(common, cc);
1219    }    }
1220    
 cc = next_opcode(common, cc);  
1221  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1222  while (cc < ccend)  while (cc < ccend)
1223    switch(*cc)    switch(*cc)
1224      {      {
1225      case OP_SET_SOM:      case OP_SET_SOM:
1226      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1227        stack_restore = TRUE;
1228      if (!setsom_found)      if (!setsom_found)
1229        {        {
1230        length += 2;        length += 2;
# Line 1080  while (cc < ccend) Line 1234  while (cc < ccend)
1234      break;      break;
1235    
1236      case OP_MARK:      case OP_MARK:
1237        case OP_PRUNE_ARG:
1238        case OP_THEN_ARG:
1239      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1240        stack_restore = TRUE;
1241      if (!setmark_found)      if (!setmark_found)
1242        {        {
1243        length += 2;        length += 2;
1244        setmark_found = TRUE;        setmark_found = TRUE;
1245        }        }
1246        if (common->control_head_ptr != 0)
1247          *needs_control_head = TRUE;
1248      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1249      break;      break;
1250    
1251      case OP_RECURSE:      case OP_RECURSE:
1252        stack_restore = TRUE;
1253      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1254        {        {
1255        length += 2;        length += 2;
# Line 1100  while (cc < ccend) Line 1260  while (cc < ccend)
1260        length += 2;        length += 2;
1261        setmark_found = TRUE;        setmark_found = TRUE;
1262        }        }
1263        if (common->capture_last_ptr != 0 && !capture_last_found)
1264          {
1265          length += 2;
1266          capture_last_found = TRUE;
1267          }
1268      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1269      break;      break;
1270    
# Line 1107  while (cc < ccend) Line 1272  while (cc < ccend)
1272      case OP_CBRAPOS:      case OP_CBRAPOS:
1273      case OP_SCBRA:      case OP_SCBRA:
1274      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1275        stack_restore = TRUE;
1276        if (common->capture_last_ptr != 0 && !capture_last_found)
1277          {
1278          length += 2;
1279          capture_last_found = TRUE;
1280          }
1281      length += 3;      length += 3;
1282      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1283      break;      break;
1284    
1285      default:      default:
1286        stack_restore = TRUE;
1287        /* Fall through. */
1288    
1289        case OP_NOT_WORD_BOUNDARY:
1290        case OP_WORD_BOUNDARY:
1291        case OP_NOT_DIGIT:
1292        case OP_DIGIT:
1293        case OP_NOT_WHITESPACE:
1294        case OP_WHITESPACE:
1295        case OP_NOT_WORDCHAR:
1296        case OP_WORDCHAR:
1297        case OP_ANY:
1298        case OP_ALLANY:
1299        case OP_ANYBYTE:
1300        case OP_NOTPROP:
1301        case OP_PROP:
1302        case OP_ANYNL:
1303        case OP_NOT_HSPACE:
1304        case OP_HSPACE:
1305        case OP_NOT_VSPACE:
1306        case OP_VSPACE:
1307        case OP_EXTUNI:
1308        case OP_EODN:
1309        case OP_EOD:
1310        case OP_CIRC:
1311        case OP_CIRCM:
1312        case OP_DOLL:
1313        case OP_DOLLM:
1314        case OP_CHAR:
1315        case OP_CHARI:
1316        case OP_NOT:
1317        case OP_NOTI:
1318    
1319        case OP_EXACT:
1320        case OP_POSSTAR:
1321        case OP_POSPLUS:
1322        case OP_POSQUERY:
1323        case OP_POSUPTO:
1324    
1325        case OP_EXACTI:
1326        case OP_POSSTARI:
1327        case OP_POSPLUSI:
1328        case OP_POSQUERYI:
1329        case OP_POSUPTOI:
1330    
1331        case OP_NOTEXACT:
1332        case OP_NOTPOSSTAR:
1333        case OP_NOTPOSPLUS:
1334        case OP_NOTPOSQUERY:
1335        case OP_NOTPOSUPTO:
1336    
1337        case OP_NOTEXACTI:
1338        case OP_NOTPOSSTARI:
1339        case OP_NOTPOSPLUSI:
1340        case OP_NOTPOSQUERYI:
1341        case OP_NOTPOSUPTOI:
1342    
1343        case OP_TYPEEXACT:
1344        case OP_TYPEPOSSTAR:
1345        case OP_TYPEPOSPLUS:
1346        case OP_TYPEPOSQUERY:
1347        case OP_TYPEPOSUPTO:
1348    
1349        case OP_CLASS:
1350        case OP_NCLASS:
1351        case OP_XCLASS:
1352    
1353      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1354      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1355      break;      break;
1356      }      }
1357    
1358  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1359  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1360    return -1;    return stack_restore ? no_frame : no_stack;
1361    
1362  if (length > 0)  if (length > 0)
1363    return length + 1;    return length + 1;
1364  return -1;  return stack_restore ? no_frame : no_stack;
1365  }  }
1366    
1367  static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive)  static void init_frame(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, int stackpos, int stacktop, BOOL recursive)
1368  {  {
1369  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1370  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1371  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1372    /* The last capture is a local variable even for recursions. */
1373    BOOL capture_last_found = FALSE;
1374  int offset;  int offset;
1375    
1376  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1139  SLJIT_UNUSED_ARG(stacktop); Line 1378  SLJIT_UNUSED_ARG(stacktop);
1378  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1379    
1380  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1381  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1382    cc = next_opcode(common, cc);    {
1383      ccend = bracketend(cc) - (1 + LINK_SIZE);
1384      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1385        cc = next_opcode(common, cc);
1386      }
1387    
1388  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1389  while (cc < ccend)  while (cc < ccend)
1390    switch(*cc)    switch(*cc)
# Line 1150  while (cc < ccend) Line 1394  while (cc < ccend)
1394      if (!setsom_found)      if (!setsom_found)
1395        {        {
1396        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1397        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1398        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1399        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1400        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1401        setsom_found = TRUE;        setsom_found = TRUE;
1402        }        }
1403      cc += 1;      cc += 1;
1404      break;      break;
1405    
1406      case OP_MARK:      case OP_MARK:
1407        case OP_PRUNE_ARG:
1408        case OP_THEN_ARG:
1409      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1410      if (!setmark_found)      if (!setmark_found)
1411        {        {
1412        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);
1413        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);
1414        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1415        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1416        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1417        setmark_found = TRUE;        setmark_found = TRUE;
1418        }        }
1419      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 1177  while (cc < ccend) Line 1423  while (cc < ccend)
1423      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1424        {        {
1425        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1426        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1427        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1428        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1429        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1430        setsom_found = TRUE;        setsom_found = TRUE;
1431        }        }
1432      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1433        {        {
1434        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);
1435        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);
1436        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1437        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1438        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1439        setmark_found = TRUE;        setmark_found = TRUE;
1440        }        }
1441        if (common->capture_last_ptr != 0 && !capture_last_found)
1442          {
1443          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1444          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1445          stackpos += (int)sizeof(sljit_sw);
1446          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1447          stackpos += (int)sizeof(sljit_sw);
1448          capture_last_found = TRUE;
1449          }
1450      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1451      break;      break;
1452    
# Line 1199  while (cc < ccend) Line 1454  while (cc < ccend)
1454      case OP_CBRAPOS:      case OP_CBRAPOS:
1455      case OP_SCBRA:      case OP_SCBRA:
1456      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1457        if (common->capture_last_ptr != 0 && !capture_last_found)
1458          {
1459          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1460          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1461          stackpos += (int)sizeof(sljit_sw);
1462          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1463          stackpos += (int)sizeof(sljit_sw);
1464          capture_last_found = TRUE;
1465          }
1466      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1467      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1468      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1469      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1470      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));
1471      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1472      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1473      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1474      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1475    
1476      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1477      break;      break;
# Line 1218  while (cc < ccend) Line 1482  while (cc < ccend)
1482      break;      break;
1483      }      }
1484    
1485  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1486  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1487  }  }
1488    
1489  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)
1490  {  {
1491  int localsize = 2;  int private_data_length = needs_control_head ? 3 : 2;
1492  int size;  int size;
1493  pcre_uchar *alternative;  pcre_uchar *alternative;
1494  /* Calculate the sum of the local variables. */  /* Calculate the sum of the private machine words. */
1495  while (cc < ccend)  while (cc < ccend)
1496    {    {
1497    size = 0;    size = 0;
# Line 1243  while (cc < ccend) Line 1507  while (cc < ccend)
1507      case OP_SBRA:      case OP_SBRA:
1508      case OP_SBRAPOS:      case OP_SBRAPOS:
1509      case OP_SCOND:      case OP_SCOND:
1510      localsize++;      private_data_length++;
1511      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1512      break;      break;
1513    
1514      case OP_CBRA:      case OP_CBRA:
1515      case OP_SCBRA:      case OP_SCBRA:
1516      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1517          private_data_length++;
1518      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1519      break;      break;
1520    
1521      case OP_CBRAPOS:      case OP_CBRAPOS:
1522      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1523      localsize += 2;      private_data_length += 2;
1524      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1525      break;      break;
1526    
# Line 1263  while (cc < ccend) Line 1528  while (cc < ccend)
1528      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1529      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1530      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1531        localsize++;        private_data_length++;
1532      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1533      break;      break;
1534    
1535      CASE_ITERATOR_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
1536      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1537        localsize++;        private_data_length++;
1538      cc += 2;      cc += 2;
1539  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1540      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1541  #endif  #endif
1542      break;      break;
1543    
1544      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
1545      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1546        localsize += 2;        private_data_length += 2;
1547      cc += 2;      cc += 2;
1548  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1549      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1550  #endif  #endif
1551      break;      break;
1552    
1553      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
1554      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1555        localsize += 2;        private_data_length += 2;
1556      cc += 2 + IMM2_SIZE;      cc += 2 + IMM2_SIZE;
1557  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1558      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1559  #endif  #endif
1560      break;      break;
1561    
1562      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1563      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1564        localsize++;        private_data_length++;
1565      cc += 1;      cc += 1;
1566      break;      break;
1567    
1568      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1569      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1570        localsize += 2;        private_data_length += 2;
1571      cc += 1;      cc += 1;
1572      break;      break;
1573    
1574      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1575      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1576        localsize += 2;        private_data_length += 2;
1577      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
1578      break;      break;
1579    
# Line 1320  while (cc < ccend) Line 1585  while (cc < ccend)
1585  #else  #else
1586      size = 1 + 32 / (int)sizeof(pcre_uchar);      size = 1 + 32 / (int)sizeof(pcre_uchar);
1587  #endif  #endif
1588      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1589        localsize += get_class_iterator_size(cc + size);        private_data_length += get_class_iterator_size(cc + size);
1590      cc += size;      cc += size;
1591      break;      break;
1592    
# Line 1332  while (cc < ccend) Line 1597  while (cc < ccend)
1597      }      }
1598    }    }
1599  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1600  return localsize;  return private_data_length;
1601  }  }
1602    
1603  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,
1604    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1605  {  {
1606  DEFINE_COMPILER;  DEFINE_COMPILER;
1607  int srcw[2];  int srcw[2];
# Line 1357  stacktop = STACK(stacktop - 1); Line 1622  stacktop = STACK(stacktop - 1);
1622    
1623  if (!save)  if (!save)
1624    {    {
1625    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1626    if (stackptr < stacktop)    if (stackptr < stacktop)
1627      {      {
1628      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1629      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1630      tmp1empty = FALSE;      tmp1empty = FALSE;
1631      }      }
1632    if (stackptr < stacktop)    if (stackptr < stacktop)
1633      {      {
1634      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1635      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1636      tmp2empty = FALSE;      tmp2empty = FALSE;
1637      }      }
1638    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1639    }    }
1640    
1641  while (status != end)  do
1642    {    {
1643    count = 0;    count = 0;
1644    switch(status)    switch(status)
1645      {      {
1646      case start:      case start:
1647      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1648      count = 1;      count = 1;
1649      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1650        if (needs_control_head)
1651          {
1652          SLJIT_ASSERT(common->control_head_ptr != 0);
1653          count = 2;
1654          srcw[1] = common->control_head_ptr;
1655          }
1656      status = loop;      status = loop;
1657      break;      break;
1658    
# Line 1405  while (status != end) Line 1676  while (status != end)
1676        case OP_SBRAPOS:        case OP_SBRAPOS:
1677        case OP_SCOND:        case OP_SCOND:
1678        count = 1;        count = 1;
1679        srcw[0] = PRIV_DATA(cc);        srcw[0] = PRIVATE_DATA(cc);
1680        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1681        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1682        break;        break;
1683    
1684        case OP_CBRA:        case OP_CBRA:
1685        case OP_SCBRA:        case OP_SCBRA:
1686        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1687        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1688            count = 1;
1689            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1690            }
1691        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1692        break;        break;
1693    
1694        case OP_CBRAPOS:        case OP_CBRAPOS:
1695        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1696        count = 2;        count = 2;
1697        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[0] = PRIVATE_DATA(cc);
1698        srcw[1] = PRIV_DATA(cc);        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1699        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
1700        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1701        break;        break;
1702    
# Line 1432  while (status != end) Line 1706  while (status != end)
1706        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1707          {          {
1708          count = 1;          count = 1;
1709          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1710          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1711          }          }
1712        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1713        break;        break;
1714    
1715        CASE_ITERATOR_LOCAL1        CASE_ITERATOR_PRIVATE_DATA_1
1716        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1717          {          {
1718          count = 1;          count = 1;
1719          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1720          }          }
1721        cc += 2;        cc += 2;
1722  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1450  while (status != end) Line 1724  while (status != end)
1724  #endif  #endif
1725        break;        break;
1726    
1727        CASE_ITERATOR_LOCAL2A        CASE_ITERATOR_PRIVATE_DATA_2A
1728        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1729          {          {
1730          count = 2;          count = 2;
1731          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1732          srcw[1] = PRIV_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1733          }          }
1734        cc += 2;        cc += 2;
1735  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1463  while (status != end) Line 1737  while (status != end)
1737  #endif  #endif
1738        break;        break;
1739    
1740        CASE_ITERATOR_LOCAL2B        CASE_ITERATOR_PRIVATE_DATA_2B
1741        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1742          {          {
1743          count = 2;          count = 2;
1744          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1745          srcw[1] = PRIV_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1746          }          }
1747        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1748  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1476  while (status != end) Line 1750  while (status != end)
1750  #endif  #endif
1751        break;        break;
1752    
1753        CASE_ITERATOR_TYPE_LOCAL1        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1754        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1755          {          {
1756          count = 1;          count = 1;
1757          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1758          }          }
1759        cc += 1;        cc += 1;
1760        break;        break;
1761    
1762        CASE_ITERATOR_TYPE_LOCAL2A        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1763        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1764          {          {
1765          count = 2;          count = 2;
1766          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1767          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1768          }          }
1769        cc += 1;        cc += 1;
1770        break;        break;
1771    
1772        CASE_ITERATOR_TYPE_LOCAL2B        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1773        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1774          {          {
1775          count = 2;          count = 2;
1776          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1777          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1778          }          }
1779        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1780        break;        break;
# Line 1513  while (status != end) Line 1787  while (status != end)
1787  #else  #else
1788        size = 1 + 32 / (int)sizeof(pcre_uchar);        size = 1 + 32 / (int)sizeof(pcre_uchar);
1789  #endif  #endif
1790        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1791          switch(get_class_iterator_size(cc + size))          switch(get_class_iterator_size(cc + size))
1792            {            {
1793            case 1:            case 1:
1794            count = 1;            count = 1;
1795            srcw[0] = PRIV_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1796            break;            break;
1797    
1798            case 2:            case 2:
1799            count = 2;            count = 2;
1800            srcw[0] = PRIV_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1801            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1802            break;            break;
1803    
1804            default:            default:
# Line 1556  while (status != end) Line 1830  while (status != end)
1830          if (!tmp1empty)          if (!tmp1empty)
1831            {            {
1832            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1833            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1834            }            }
1835          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1836          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1567  while (status != end) Line 1841  while (status != end)
1841          if (!tmp2empty)          if (!tmp2empty)
1842            {            {
1843            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1844            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1845            }            }
1846          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1847          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1584  while (status != end) Line 1858  while (status != end)
1858          if (!tmp1empty)          if (!tmp1empty)
1859            {            {
1860            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1861            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1862            }            }
1863          tmp1next = FALSE;          tmp1next = FALSE;
1864          }          }
# Line 1596  while (status != end) Line 1870  while (status != end)
1870          if (!tmp2empty)          if (!tmp2empty)
1871            {            {
1872            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1873            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1874            }            }
1875          tmp1next = TRUE;          tmp1next = TRUE;
1876          }          }
1877        }        }
1878      }      }
1879    }    }
1880    while (status != end);
1881    
1882  if (save)  if (save)
1883    {    {
# Line 1611  if (save) Line 1886  if (save)
1886      if (!tmp1empty)      if (!tmp1empty)
1887        {        {
1888        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1889        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1890        }        }
1891      if (!tmp2empty)      if (!tmp2empty)
1892        {        {
1893        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1894        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1895        }        }
1896      }      }
1897    else    else
# Line 1624  if (save) Line 1899  if (save)
1899      if (!tmp2empty)      if (!tmp2empty)
1900        {        {
1901        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1902        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1903        }        }
1904      if (!tmp1empty)      if (!tmp1empty)
1905        {        {
1906        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1907        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1908        }        }
1909      }      }
1910    }    }
1911  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1912  }  }
1913    
1914  #undef CASE_ITERATOR_LOCAL1  static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1915  #undef CASE_ITERATOR_LOCAL2A  {
1916  #undef CASE_ITERATOR_LOCAL2B  pcre_uchar *end = bracketend(cc);
1917  #undef CASE_ITERATOR_TYPE_LOCAL1  BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1918  #undef CASE_ITERATOR_TYPE_LOCAL2A  
1919  #undef CASE_ITERATOR_TYPE_LOCAL2B  /* Assert captures then. */
1920    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1921      current_offset = NULL;
1922    /* Conditional block does not. */
1923    if (*cc == OP_COND || *cc == OP_SCOND)
1924      has_alternatives = FALSE;
1925    
1926    cc = next_opcode(common, cc);
1927    if (has_alternatives)
1928      current_offset = common->then_offsets + (cc - common->start);
1929    
1930    while (cc < end)
1931      {
1932      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1933        cc = set_then_offsets(common, cc, current_offset);
1934      else
1935        {
1936        if (*cc == OP_ALT && has_alternatives)
1937          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1938        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1939          *current_offset = 1;
1940        cc = next_opcode(common, cc);
1941        }
1942      }
1943    
1944    return end;
1945    }
1946    
1947    #undef CASE_ITERATOR_PRIVATE_DATA_1
1948    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1949    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1950    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1951    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1952    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1953    
1954  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1955  {  {
1956  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1957  }  }
# Line 1653  static SLJIT_INLINE void set_jumps(jump_ Line 1961  static SLJIT_INLINE void set_jumps(jump_
1961  while (list)  while (list)
1962    {    {
1963    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1964    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1965    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1966    list = list->next;    list = list->next;
1967    }    }
1968  }  }
# Line 1670  if (list_item) Line 1978  if (list_item)
1978    }    }
1979  }  }
1980    
1981  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)
1982  {  {
1983  DEFINE_COMPILER;  DEFINE_COMPILER;
1984  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1985    
1986  if (list_item)  if (list_item)
1987    {    {
   list_item->type = type;  
   list_item->data = data;  
1988    list_item->start = start;    list_item->start = start;
1989    list_item->quit = LABEL();    list_item->quit = LABEL();
1990    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1694  stub_list* list_item = common->stubs; Line 2000  stub_list* list_item = common->stubs;
2000  while (list_item)  while (list_item)
2001    {    {
2002    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2003    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;  
     }  
2004    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2005    list_item = list_item->next;    list_item = list_item->next;
2006    }    }
# Line 1719  static SLJIT_INLINE void allocate_stack( Line 2020  static SLJIT_INLINE void allocate_stack(
2020  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2021  DEFINE_COMPILER;  DEFINE_COMPILER;
2022    
2023  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));
2024  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2025  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2026  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 2028  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2028  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2029  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2030  #endif  #endif
2031  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));
2032  }  }
2033    
2034  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2035  {  {
2036  DEFINE_COMPILER;  DEFINE_COMPILER;
2037  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));
2038    }
2039    
2040    static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
2041    {
2042    DEFINE_COMPILER;
2043    struct sljit_label *loop;
2044    int i;
2045    
2046    /* At this point we can freely use all temporary registers. */
2047    SLJIT_ASSERT(length > 1);
2048    /* TMP1 returns with begin - 1. */
2049    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
2050    if (length < 8)
2051      {
2052      for (i = 1; i < length; i++)
2053        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2054      }
2055    else
2056      {
2057      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2058      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2059      loop = LABEL();
2060      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2061      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2062      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2063      }
2064  }  }
2065    
2066  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2067  {  {
2068  DEFINE_COMPILER;  DEFINE_COMPILER;
2069  struct sljit_label *loop;  struct sljit_label *loop;
2070  int i;  int i;
2071  /* At this point we can freely use all temporary registers. */  
2072  /* TMP1 returns with begin - 1. */  SLJIT_ASSERT(length > 1);
2073  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));  /* OVECTOR(1) contains the "string begin - 1" constant. */
2074    if (length > 2)
2075      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2076  if (length < 8)  if (length < 8)
2077    {    {
2078    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
2079      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);
2080    }    }
2081  else  else
2082    {    {
2083    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2084    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2085    loop = LABEL();    loop = LABEL();
2086    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);
2087    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);
2088    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2089    }    }
2090    
2091    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2092    if (common->mark_ptr != 0)
2093      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2094    if (common->control_head_ptr != 0)
2095      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2096    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2097    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2098    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2099    }
2100    
2101    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2102    {
2103    while (current != NULL)
2104      {
2105      switch (current[-2])
2106        {
2107        case type_then_trap:
2108        break;
2109    
2110        case type_mark:
2111        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2112          return current[-4];
2113        break;
2114    
2115        default:
2116        SLJIT_ASSERT_STOP();
2117        break;
2118        }
2119      current = (sljit_sw*)current[-1];
2120      }
2121    return -1;
2122  }  }
2123    
2124  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2125  {  {
2126  DEFINE_COMPILER;  DEFINE_COMPILER;
2127  struct sljit_label *loop;  struct sljit_label *loop;
2128  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2129    
2130  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2131  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));
2132  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);
2133    
2134  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2135  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2136    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);
2137  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));
2138  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2139    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);
2140  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));
2141  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));
2142  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2143  /* Unlikely, but possible */  /* Unlikely, but possible */
2144  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);
2145  loop = LABEL();  loop = LABEL();
2146  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);
2147  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));
2148  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2149  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2150  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);
2151  #endif  #endif
2152  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);
2153  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);
2154  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2155  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2156    
2157  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2158  if (topbracket > 1)  if (topbracket > 1)
2159    {    {
2160    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));
2161    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2162    
2163    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2164    loop = LABEL();    loop = LABEL();
2165    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)));
2166    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);
2167    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);
2168    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2169    }    }
2170  else  else
2171    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1813  else Line 2174  else
2174  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)
2175  {  {
2176  DEFINE_COMPILER;  DEFINE_COMPILER;
2177    struct sljit_jump *jump;
2178    
2179  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);
2180  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
2181      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2182    
2183  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2184  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2185  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));
2186  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);
2187    
2188  /* Store match begin and end. */  /* Store match begin and end. */
2189  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));
2190  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));
2191  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);  
2192    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2193    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);
2194    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2195    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2196    #endif
2197    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2198    JUMPHERE(jump);
2199    
2200    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);
2201  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);
2202  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2203  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);
2204  #endif  #endif
2205  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);
2206    
2207  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);
2208  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2209  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);
2210  #endif  #endif
2211  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);
2212    
2213  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2214  }  }
# Line 1949  if (c <= 127 && bit == 0x20) Line 2321  if (c <= 127 && bit == 0x20)
2321    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2322    
2323  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2324  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2325    return 0;    return 0;
2326    
2327  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2328    
2329  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2330  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 1968  if (common->utf && c > 127) Line 2340  if (common->utf && c > 127)
2340  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2341  return (0 << 8) | bit;  return (0 << 8) | bit;
2342    
2343  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2344    
 #ifdef COMPILE_PCRE16  
2345  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2346  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2347    {    {
# Line 1981  if (common->utf && c > 65535) Line 2352  if (common->utf && c > 65535)
2352    }    }
2353  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2354  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2355    
2356  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2357  }  }
2358    
2359  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 2373  else if (common->mode == JIT_PARTIAL_SOF
2373    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);
2374    
2375  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2376    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);
2377  else  else
2378    {    {
2379    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2016  if (jump != NULL) Line 2386  if (jump != NULL)
2386    JUMPHERE(jump);    JUMPHERE(jump);
2387  }  }
2388    
2389  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2390  {  {
2391  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2392  DEFINE_COMPILER;  DEFINE_COMPILER;
2393  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2394    
2395  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2396    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2397      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2398      return;
2399      }
2400    
2401  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2402  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2403    {    {
2404    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));
2405    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);
2406    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2407    }    }
2408  else  else
2409    {    {
2410    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));
2411    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2412      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2413    else    else
2414      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2415    }    }
2416  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2417  }  }
2418    
2419  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 2432  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2432  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));
2433  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2434    {    {
2435    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);
2436    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2437    }    }
2438  else  else
# Line 2081  static void read_char(compiler_common *c Line 2450  static void read_char(compiler_common *c
2450  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2451  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2452  DEFINE_COMPILER;  DEFINE_COMPILER;
2453  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2454  struct sljit_jump *jump;  struct sljit_jump *jump;
2455  #endif  #endif
2456    
2457  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2458  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2459  if (common->utf)  if (common->utf)
2460    {    {
2461  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2462    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2463  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2464    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2465  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2466    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2467    JUMPHERE(jump);    JUMPHERE(jump);
2468    }    }
2469  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2470  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));
2471  }  }
2472    
# Line 2108  static void peek_char(compiler_common *c Line 2475  static void peek_char(compiler_common *c
2475  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2476  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2477  DEFINE_COMPILER;  DEFINE_COMPILER;
2478  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2479  struct sljit_jump *jump;  struct sljit_jump *jump;
2480  #endif  #endif
2481    
2482  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2483  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2484  if (common->utf)  if (common->utf)
2485    {    {
2486  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2487    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2488  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2489    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2490  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2491    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2492    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2493    JUMPHERE(jump);    JUMPHERE(jump);
2494    }    }
2495  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2496  }  }
2497    
2498  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2499  {  {
2500  /* 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. */
2501  DEFINE_COMPILER;  DEFINE_COMPILER;
2502  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2503  struct sljit_jump *jump;  struct sljit_jump *jump;
2504  #endif  #endif
2505    
# Line 2143  if (common->utf) Line 2508  if (common->utf)
2508    {    {
2509    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2510    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));
2511  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2512    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2513    it is needed in most cases. */    it is needed in most cases. */
2514    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2515    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2516    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2517    JUMPHERE(jump);    JUMPHERE(jump);
2518  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2519    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2520    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2521    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 2523  if (common->utf)
2523    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2524    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2525    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);
2526    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2527    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2528    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2529  #endif  #elif defined COMPILE_PCRE32
2530  #endif /* COMPILE_PCRE8 */    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2531      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2532      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2533      JUMPHERE(jump);
2534    #endif /* COMPILE_PCRE[8|16|32] */
2535    return;    return;
2536    }    }
2537  #endif  #endif /* SUPPORT_UTF */
2538  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2539  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));
2540  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2541  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2542  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2543  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2544  #endif  #endif
2545  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2546  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2547  JUMPHERE(jump);  JUMPHERE(jump);
2548  #endif  #endif
2549  }  }
# Line 2184  static void skip_char_back(compiler_comm Line 2552  static void skip_char_back(compiler_comm
2552  {  {
2553  /* 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. */
2554  DEFINE_COMPILER;  DEFINE_COMPILER;
2555  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2556    #if defined COMPILE_PCRE8
2557  struct sljit_label *label;  struct sljit_label *label;
2558    
2559  if (common->utf)  if (common->utf)
# Line 2196  if (common->utf) Line 2565  if (common->utf)
2565    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2566    return;    return;
2567    }    }
2568  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2569  if (common->utf)  if (common->utf)
2570    {    {
2571    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 2573  if (common->utf)
2573    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2574    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2575    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);
2576    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2577    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2578    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2579    return;    return;
2580    }    }
2581  #endif  #endif /* COMPILE_PCRE[8|16] */
2582    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2583  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));
2584  }  }
2585    
# Line 2227  if (nltype == NLTYPE_ANY) Line 2596  if (nltype == NLTYPE_ANY)
2596  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2597    {    {
2598    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);
2599    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2600    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);
2601    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);
2602    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));
2603    }    }
2604  else  else
# Line 2241  else Line 2610  else
2610    
2611  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2612    
2613  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2614  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2615  {  {
2616  /* 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 2698  sljit_emit_fast_return(compiler, RETURN_
2698  JUMPHERE(jump);  JUMPHERE(jump);
2699    
2700  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2701  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);
2702  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2703  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2704  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2705  }  }
2706    
2707  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
2708    
 #ifdef COMPILE_PCRE16  
2709  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2710  {  {
2711  /* 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 2730  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC
2730  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2731  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2732  }  }
 #endif /* COMPILE_PCRE16 */  
2733    
2734  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16] */
2735    
2736  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2737    
# Line 2384  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 2751  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2751    
2752  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2753  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2754  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));
2755  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2756  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2757  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2758  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2759  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2760  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));
2761  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2762  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2763  }  }
# Line 2404  struct sljit_label *newlinelabel = NULL; Line 2771  struct sljit_label *newlinelabel = NULL;
2771  struct sljit_jump *start;  struct sljit_jump *start;
2772  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2773  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2774  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2775  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2776  #endif  #endif
2777  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 2459  if (newlinecheck) Line 2826  if (newlinecheck)
2826    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2827    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2828    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);
2829    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2830  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2831    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2832  #endif  #endif
2833    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2834    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 2482  if (newlinecheck) Line 2849  if (newlinecheck)
2849    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);
2850    
2851  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));
2852  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2853    #if defined COMPILE_PCRE8
2854  if (common->utf)  if (common->utf)
2855    {    {
2856    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2857    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);
2858    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2859    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2860    }    }
2861  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2862  if (common->utf)  if (common->utf)
2863    {    {
2864    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2865    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2866    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);
2867    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2868    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2869    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2870    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2871    }    }
2872  #endif  #endif /* COMPILE_PCRE[8|16] */
2873    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2874  JUMPHERE(start);  JUMPHERE(start);
2875    
2876  if (newlinecheck)  if (newlinecheck)
# Line 2514  if (newlinecheck) Line 2882  if (newlinecheck)
2882  return mainloop;  return mainloop;
2883  }  }
2884    
2885  static SLJIT_INLINE BOOL fast_forward_first_two_chars(compiler_common *common, BOOL firstline)  #define MAX_N_CHARS 3
2886    
2887    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2888  {  {
2889  DEFINE_COMPILER;  DEFINE_COMPILER;
2890  struct sljit_label *start;  struct sljit_label *start;
2891  struct sljit_jump *quit;  struct sljit_jump *quit;
2892  struct sljit_jump *found;  pcre_uint32 chars[MAX_N_CHARS * 2];
2893  pcre_int32 chars[4];  pcre_uchar *cc = common->start + 1 + LINK_SIZE;
 pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  
2894  int location = 0;  int location = 0;
2895  pcre_int32 len, c, bit, caseless;  pcre_int32 len, c, bit, caseless;
2896  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  
2897    
2898    /* We do not support alternatives now. */
2899  if (*(common->start + GET(common->start, 1)) == OP_ALT)  if (*(common->start + GET(common->start, 1)) == OP_ALT)
2900    return FALSE;    return FALSE;
2901    
2902  while (TRUE)  while (TRUE)
2903    {    {
2904    caseless = 0;    caseless = 0;
2905    must_end = TRUE;    must_stop = 1;
2906    switch(*cc)    switch(*cc)
2907      {      {
2908      case OP_CHAR:      case OP_CHAR:
2909      must_end = FALSE;      must_stop = 0;
2910      cc++;      cc++;
2911      break;      break;
2912    
2913      case OP_CHARI:      case OP_CHARI:
2914      caseless = 1;      caseless = 1;
2915      must_end = FALSE;      must_stop = 0;
2916      cc++;      cc++;
2917      break;      break;
2918    
# Line 2596  while (TRUE) Line 2954  while (TRUE)
2954      break;      break;
2955    
2956      default:      default:
2957      return FALSE;      must_stop = 2;
2958        break;
2959      }      }
2960    
2961      if (must_stop == 2)
2962          break;
2963    
2964    len = 1;    len = 1;
2965  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2966    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 2983  while (TRUE)
2983    else    else
2984      caseless = 0;      caseless = 0;
2985    
2986    while (len > 0 && location < 2 * 2)    while (len > 0 && location < MAX_N_CHARS * 2)
2987      {      {
2988      c = *cc;      c = *cc;
2989      bit = 0;      bit = 0;
# Line 2639  while (TRUE) Line 3001  while (TRUE)
3001      cc++;      cc++;
3002      }      }
3003    
3004    if (location == 2 * 2)    if (location >= MAX_N_CHARS * 2 || must_stop != 0)
3005      break;      break;
   else if (must_end)  
     return FALSE;  
3006    }    }
3007    
3008    /* At least two characters are required. */
3009    if (location < 2 * 2)
3010        return FALSE;
3011    
3012  if (firstline)  if (firstline)
3013    {    {
3014    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3015    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3016    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));
3017    }    }
3018  else  else
3019    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));
3020    
3021  start = LABEL();  start = LABEL();
3022  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 */  
3023    
3024  #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 */  
3025  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3026  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3027  #endif /* SLJIT_BIG_ENDIAN */  if (chars[1] != 0)
3028      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3029  #ifdef COMPILE_PCRE8  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3030  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 8);  if (location > 2 * 2)
3031  #else /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3032  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 16);  if (chars[3] != 0)
3033  #endif    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
3034  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
3035    if (location > 2 * 2)
3036  #endif    {
3037      if (chars[5] != 0)
3038  if (chars[1] != 0 || chars[3] != 0)      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
3039    {    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);  
3040    }    }
3041    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3042    
 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);  
3043  JUMPHERE(quit);  JUMPHERE(quit);
3044    
3045  if (firstline)  if (firstline)
3046    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3047  else  else
3048    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));
3049  return TRUE;  return TRUE;
3050  }  }
3051    
3052    #undef MAX_N_CHARS
3053    
3054  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)
3055  {  {
3056  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2738  if (first_char == oc) Line 3084  if (first_char == oc)
3084  else  else
3085    {    {
3086    bit = first_char ^ oc;    bit = first_char ^ oc;
3087    if (ispowerof2(bit))    if (is_powerof2(bit))
3088      {      {
3089      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3090      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 3092  else
3092    else    else
3093      {      {
3094      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);
3095      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3096      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);
3097      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);
3098      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3099      }      }
3100    }    }
# Line 2790  if (common->nltype == NLTYPE_FIXED && co Line 3136  if (common->nltype == NLTYPE_FIXED && co
3136    
3137    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3138    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);
3139    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3140  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3141    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3142  #endif  #endif
3143    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3144    
# Line 2833  if (common->nltype == NLTYPE_ANY || comm Line 3179  if (common->nltype == NLTYPE_ANY || comm
3179    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3180    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3181    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);
3182    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3183  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3184    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3185  #endif  #endif
3186    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3187    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
# Line 2848  if (firstline) Line 3194  if (firstline)
3194    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3195  }  }
3196    
3197    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3198    
3199  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)
3200  {  {
3201  DEFINE_COMPILER;  DEFINE_COMPILER;
3202  struct sljit_label *start;  struct sljit_label *start;
3203  struct sljit_jump *quit;  struct sljit_jump *quit;
3204  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3205    jump_list *matches = NULL;
3206    pcre_uint8 inverted_start_bits[32];
3207    int i;
3208  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3209  struct sljit_jump *jump;  struct sljit_jump *jump;
3210  #endif  #endif
3211    
3212    for (i = 0; i < 32; ++i)
3213      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3214    
3215  if (firstline)  if (firstline)
3216    {    {
3217    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 3226  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3226  if (common->utf)  if (common->utf)
3227    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3228  #endif  #endif
3229    
3230    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3231      {
3232  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3233  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3234  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3235  JUMPHERE(jump);    JUMPHERE(jump);
3236  #endif  #endif
3237  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3238  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3239  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3240  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3241  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);
3242  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3243      }
3244    
3245  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3246  if (common->utf)  if (common->utf)
3247    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3248  #endif  #endif
3249  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));
3250  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3251    #if defined COMPILE_PCRE8
3252  if (common->utf)  if (common->utf)
3253    {    {
3254    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3255    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);
3256    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3257    }    }
3258  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3259  if (common->utf)  if (common->utf)
3260    {    {
3261    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3262    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3263    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);
3264    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3265    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3266    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3267    }    }
3268  #endif  #endif /* COMPILE_PCRE[8|16] */
3269    #endif /* SUPPORT_UTF */
3270  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3271  JUMPHERE(found);  if (found != NULL)
3272      JUMPHERE(found);
3273    if (matches != NULL)
3274      set_jumps(matches, LABEL());
3275  JUMPHERE(quit);  JUMPHERE(quit);
3276    
3277  if (firstline)  if (firstline)
# Line 2925  struct sljit_jump *alreadyfound; Line 3287  struct sljit_jump *alreadyfound;
3287  struct sljit_jump *found;  struct sljit_jump *found;
3288  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3289  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3290  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3291    
3292  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3293  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 3318  if (req_char == oc)
3318  else  else
3319    {    {
3320    bit = req_char ^ oc;    bit = req_char ^ oc;
3321    if (ispowerof2(bit))    if (is_powerof2(bit))
3322      {      {
3323      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3324      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 3354  GET_LOCAL_BASE(TMP3, 0, 0);
3354  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3355  mainloop = LABEL();  mainloop = LABEL();
3356  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3357  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);
3358    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3359    
3360  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3361  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));
3362  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));
3363  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));
3364  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3365    
3366  JUMPHERE(jump);  JUMPHERE(jump);
3367  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3368  /* End of dropping frames. */  /* End of dropping frames. */
3369  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3370    
3371  JUMPHERE(jump);  JUMPHERE(jump);
3372  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3373  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3374  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3375  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));  
3376  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3377  }  }
3378    
# Line 3033  static void check_wordboundary(compiler_ Line 3380  static void check_wordboundary(compiler_
3380  {  {
3381  DEFINE_COMPILER;  DEFINE_COMPILER;
3382  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3383    jump_list *skipread_list = NULL;
3384  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3385  struct sljit_jump *jump;  struct sljit_jump *jump;
3386  #endif  #endif
# Line 3058  if (common->use_ucp) Line 3406  if (common->use_ucp)
3406    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3407    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3408    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);
3409    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3410    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);
3411    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);
3412    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3413    JUMPHERE(jump);    JUMPHERE(jump);
3414    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3415    }    }
# Line 3090  else Line 3438  else
3438  JUMPHERE(skipread);  JUMPHERE(skipread);
3439    
3440  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3441  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3442  peek_char(common);  peek_char(common);
3443    
3444  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 3102  if (common->use_ucp) Line 3450  if (common->use_ucp)
3450    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3451    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3452    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);
3453    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3454    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);
3455    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);
3456    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3457    JUMPHERE(jump);    JUMPHERE(jump);
3458    }    }
3459  else  else
# Line 3131  else Line 3479  else
3479      JUMPHERE(jump);      JUMPHERE(jump);
3480  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3481    }    }
3482  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3483    
3484  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);
3485  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 3534  switch(ranges[0])
3534        }        }
3535      return TRUE;      return TRUE;
3536      }      }
3537    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]))
3538      {      {
3539      if (readch)      if (readch)
3540        read_char(common);        read_char(common);
# Line 3285  sljit_emit_fast_enter(compiler, RETURN_A Line 3633  sljit_emit_fast_enter(compiler, RETURN_A
3633    
3634  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3635  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);
3636  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3637  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);
3638  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3639  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3640  if (common->utf)  if (common->utf)
3641    {    {
3642  #endif  #endif
3643    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3644    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3645    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);
3646  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3647    }    }
3648  #endif  #endif
3649  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3650  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);
3651  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3652  }  }
3653    
# Line 3311  DEFINE_COMPILER; Line 3659  DEFINE_COMPILER;
3659  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3660    
3661  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);
3662  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3663  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);
3664  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3665  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);
3666  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3667  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3668  if (common->utf)  if (common->utf)
3669    {    {
3670  #endif  #endif
3671    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3672    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);
3673    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3674    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);
3675    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3676    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3677    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);
3678    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3679    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);
3680    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3681    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);
3682    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3683    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);
3684  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3685    }    }
3686  #endif  #endif
3687  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3688  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);
3689    
3690  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3691  }  }
# Line 3351  sljit_emit_fast_enter(compiler, RETURN_A Line 3699  sljit_emit_fast_enter(compiler, RETURN_A
3699    
3700  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3701  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);
3702  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3703  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);
3704  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3705  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3706  if (common->utf)  if (common->utf)
3707    {    {
3708  #endif  #endif
3709    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);
3710    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3711    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);
3712  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3713    }    }
3714  #endif  #endif
3715  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3716  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);
3717    
3718  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3719  }  }
# Line 3451  sljit_emit_fast_return(compiler, RETURN_ Line 3799  sljit_emit_fast_return(compiler, RETURN_
3799    
3800  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3801    
3802  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)
3803  {  {
3804  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3805  int c1, c2;  pcre_uint32 c1, c2;
3806  const pcre_uchar *src2 = args->uchar_ptr;  const pcre_uchar *src2 = args->uchar_ptr;
3807  const pcre_uchar *end2 = args->end;  const pcre_uchar *end2 = args->end;
3808    const ucd_record *ur;
3809    const pcre_uint32 *pp;
3810    
3811  while (src1 < end1)  while (src1 < end1)
3812    {    {
# Line 3464  while (src1 < end1) Line 3814  while (src1 < end1)
3814      return (pcre_uchar*)1;      return (pcre_uchar*)1;
3815    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
3816    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
3817    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return NULL;    ur = GET_UCD(c2);
3818      if (c1 != c2 && c1 != c2 + ur->other_case)
3819        {
3820        pp = PRIV(ucd_caseless_sets) + ur->caseset;
3821        for (;;)
3822          {
3823          if (c1 < *pp) return NULL;
3824          if (c1 == *pp++) break;
3825          }
3826        }
3827    }    }
3828  return src2;  return src2;
3829  }  }
# Line 3486  if (caseless && char_has_othercase(commo Line 3845  if (caseless && char_has_othercase(commo
3845    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
3846    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
3847    /* Extracting bit difference info. */    /* Extracting bit difference info. */
3848  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3849    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
3850    othercasebit &= 0xff;    othercasebit &= 0xff;
3851  #else  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3852  #ifdef COMPILE_PCRE16    /* Note that this code only handles characters in the BMP. If there
3853      ever are characters outside the BMP whose othercase differs in only one
3854      bit from itself (there currently are none), this code will need to be
3855      revised for COMPILE_PCRE32. */
3856    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
3857    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
3858      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
3859    else    else
3860      othercasebit &= 0xff;      othercasebit &= 0xff;
3861  #endif  #endif /* COMPILE_PCRE[8|16|32] */
 #endif  
3862    }    }
3863    
3864  if (context->sourcereg == -1)  if (context->sourcereg == -1)
3865    {    {
3866  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3867  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3868    if (context->length >= 4)    if (context->length >= 4)
3869      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 3872  if (context->sourcereg == -1)
3872    else    else
3873  #endif  #endif
3874      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3875  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
3876  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3877    if (context->length >= 4)    if (context->length >= 4)
3878      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3879    else    else
3880  #endif  #endif
3881      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3882  #endif  #elif defined COMPILE_PCRE32
3883  #endif /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3884    #endif /* COMPILE_PCRE[8|16|32] */
3885    context->sourcereg = TMP2;    context->sourcereg = TMP2;
3886    }    }
3887    
# Line 3534  do Line 3895  do
3895  #endif  #endif
3896    
3897    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3898  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3899    
3900    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3901    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3549  do Line 3910  do
3910      }      }
3911    context->ucharptr++;    context->ucharptr++;
3912    
3913  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3914    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))
3915  #else  #else
3916    if (context->ucharptr >= 2 || context->length == 0)    if (context->ucharptr >= 2 || context->length == 0)
# Line 3557  do Line 3918  do
3918      {      {
3919      if (context->length >= 4)      if (context->length >= 4)
3920        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  
3921      else if (context->length >= 2)      else if (context->length >= 2)
3922        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);
3923    #if defined COMPILE_PCRE8
3924      else if (context->length >= 1)      else if (context->length >= 1)
3925        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);
3926  #else  #endif /* COMPILE_PCRE8 */
     else if (context->length >= 2)  
       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
3927      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3928    
3929      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3599  do Line 3957  do
3957    
3958  #else  #else
3959    
3960    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3961  #ifdef COMPILE_PCRE8    if (context->length >= 1)
3962    if (context->length > 0)      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3963      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  
3964    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3965    
3966    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3651  return cc; Line 4005  return cc;
4005      } \      } \
4006    charoffset = (value);    charoffset = (value);
4007    
4008  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)
4009  {  {
4010  DEFINE_COMPILER;  DEFINE_COMPILER;
4011  jump_list *found = NULL;  jump_list *found = NULL;
4012  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;
4013  unsigned int c;  pcre_int32 c, charoffset;
4014  int compares;  const pcre_uint32 *other_cases;
4015  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4016  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4017    int compares, invertcmp, numberofcmps;
4018  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4019  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4020  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4021  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4022  unsigned int typeoffset;  pcre_int32 typeoffset;
4023  #endif  #endif
 int invertcmp, numberofcmps;  
 unsigned int charoffset;  
4024    
4025  /* Although SUPPORT_UTF must be defined, we are  /* Although SUPPORT_UTF must be defined, we are
4026     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 4041  if ((*cc++ & XCL_MAP) != 0)
4041      {      {
4042      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4043      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4044      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4045      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4046      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);
4047      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 4118  while (*cc != XCL_END)
4118        needschar = TRUE;        needschar = TRUE;
4119        break;        break;
4120    
4121          case PT_CLIST:
4122          case PT_UCNC:
4123          needschar = TRUE;
4124          break;
4125    
4126        default:        default:
4127        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
4128        break;        break;
# Line 3801  if (needstype || needsscript) Line 4159  if (needstype || needsscript)
4159      {      {
4160      if (scriptreg == TMP1)      if (scriptreg == TMP1)
4161        {        {
4162        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));
4163        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
4164        }        }
4165      else      else
4166        {        {
4167        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
4168        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));
4169        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
4170        }        }
4171      }      }
# Line 3843  while (*cc != XCL_END) Line 4201  while (*cc != XCL_END)
4201      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4202        {        {
4203        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);
4204        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);
4205        numberofcmps++;        numberofcmps++;
4206        }        }
4207      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4208        {        {
4209        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);
4210        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);
4211        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4212        numberofcmps = 0;        numberofcmps = 0;
4213        }        }
# Line 3882  while (*cc != XCL_END) Line 4240  while (*cc != XCL_END)
4240      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4241        {        {
4242        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);
4243        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);
4244        numberofcmps++;        numberofcmps++;
4245        }        }
4246      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4247        {        {
4248        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);
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);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4251        numberofcmps = 0;        numberofcmps = 0;
4252        }        }
# Line 3919  while (*cc != XCL_END) Line 4277  while (*cc != XCL_END)
4277    
4278        case PT_LAMP:        case PT_LAMP:
4279        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);
4280        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4281        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);
4282        COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4283        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);
4284        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);
4285        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4286        break;        break;
4287    
# Line 3950  while (*cc != XCL_END) Line 4308  while (*cc != XCL_END)
4308          }          }
4309        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4310        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);
4311        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4312        if (*cc == PT_SPACE)        if (*cc == PT_SPACE)
4313          JUMPHERE(jump);          JUMPHERE(jump);
4314    
4315        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4316        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);
4317        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);
4318        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4319        break;        break;
4320    
4321        case PT_WORD:        case PT_WORD:
4322        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);
4323        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4324        /* ... fall through */        /* Fall through. */
4325    
4326        case PT_ALNUM:        case PT_ALNUM:
4327        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
4328        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);
4329        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);
4330        SET_TYPE_OFFSET(ucp_Nd);        SET_TYPE_OFFSET(ucp_Nd);
4331        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);
4332        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);
4333          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4334          break;
4335    
4336          case PT_CLIST:
4337          other_cases = PRIV(ucd_caseless_sets) + cc[1];
4338    
4339          /* At least three characters are required.
4340             Otherwise this case would be handled by the normal code path. */
4341          SLJIT_ASSERT(other_cases[0] != NOTACHAR && other_cases[1] != NOTACHAR && other_cases[2] != NOTACHAR);
4342          SLJIT_ASSERT(other_cases[0] < other_cases[1] && other_cases[1] < other_cases[2]);
4343    
4344          /* Optimizing character pairs, if their difference is power of 2. */
4345          if (is_powerof2(other_cases[1] ^ other_cases[0]))
4346            {
4347            if (charoffset == 0)
4348              OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4349            else
4350              {
4351              OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4352              OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4353              }
4354            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[1]);
4355            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4356            other_cases += 2;
4357            }
4358          else if (is_powerof2(other_cases[2] ^ other_cases[1]))
4359            {
4360            if (charoffset == 0)
4361              OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[2] ^ other_cases[1]);
4362            else
4363              {
4364              OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4365              OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4366              }
4367            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[2]);
4368            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4369    
4370            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, other_cases[0] - charoffset);
4371            OP_FLAGS(SLJIT_OR | ((other_cases[3] == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4372    
4373            other_cases += 3;
4374            }
4375          else
4376            {
4377            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4378            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4379            }
4380    
4381          while (*other_cases != NOTACHAR)
4382            {
4383            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4384            OP_FLAGS(SLJIT_OR | ((*other_cases == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4385            }
4386          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4387          break;
4388    
4389          case PT_UCNC:
4390          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);
4391          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4392          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);
4393          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4394          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);
4395          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4396    
4397          SET_CHAR_OFFSET(0xa0);
4398          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);
4399          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4400          SET_CHAR_OFFSET(0);
4401          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
4402          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4403        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4404        break;        break;
4405        }        }
# Line 3992  if (found != NULL) Line 4420  if (found != NULL)
4420    
4421  #endif  #endif
4422    
4423  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)
4424  {  {
4425  DEFINE_COMPILER;  DEFINE_COMPILER;
4426  int length;  int length;
4427  unsigned int c, oc, bit;  unsigned int c, oc, bit;
4428  compare_context context;  compare_context context;
4429  struct sljit_jump *jump[4];  struct sljit_jump *jump[4];
4430    jump_list *end_list;
4431  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4432  struct sljit_label *label;  struct sljit_label *label;
4433  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4067  switch(type) Line 4496  switch(type)
4496    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4497      {      {
4498      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);
4499        end_list = NULL;
4500      if (common->mode != JIT_PARTIAL_HARD_COMPILE)      if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4501        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));
4502      else      else
4503        jump[1] = check_str_end(common);        check_str_end(common, &end_list);
4504    
4505      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4506      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));
4507      if (jump[1] != NULL)      set_jumps(end_list, LABEL());
       JUMPHERE(jump[1]);  
4508      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4509      }      }
4510    else    else
# Line 4089  switch(type) Line 4518  switch(type)
4518      {      {
4519      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4520      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));
4521  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16
4522    #if defined COMPILE_PCRE8
4523      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4524      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);
4525      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4526  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
4527      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
4528      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
4529      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);
4530      COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4531      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4532      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4533  #endif /* COMPILE_PCRE16 */  #endif
 #endif /* COMPILE_PCRE8 */  
4534      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4535    #endif /* COMPILE_PCRE[8|16] */
4536      return cc;      return cc;
4537      }      }
4538  #endif  #endif
# Line 4124  switch(type) Line 4553  switch(type)
4553    propdata[2] = cc[0];    propdata[2] = cc[0];
4554    propdata[3] = cc[1];    propdata[3] = cc[1];
4555    propdata[4] = XCL_END;    propdata[4] = XCL_END;
4556    compile_xclass_trypath(common, propdata, backtracks);    compile_xclass_matchingpath(common, propdata, backtracks);
4557    return cc + 2;    return cc + 2;
4558  #endif  #endif
4559  #endif  #endif
# Line 4134  switch(type) Line 4563  switch(type)
4563    read_char(common);    read_char(common);
4564    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);
4565    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
4566      end_list = NULL;
4567    if (common->mode != JIT_PARTIAL_HARD_COMPILE)    if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4568      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));
4569    else    else
4570      jump[1] = check_str_end(common);      check_str_end(common, &end_list);
4571    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4572    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);
4573    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));
4574    jump[3] = JUMP(SLJIT_JUMP);    jump[2] = JUMP(SLJIT_JUMP);
4575    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4576    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);
4577      set_jumps(end_list, LABEL());
4578    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
4579    JUMPHERE(jump[2]);    JUMPHERE(jump[2]);
   JUMPHERE(jump[3]);  
4580    return cc;    return cc;
4581    
4582    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
# Line 4170  switch(type) Line 4600  switch(type)
4600    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4601    read_char(common);    read_char(common);
4602    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4603    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));
4604    add_jump(compiler, backtracks, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, ucp_Mn - ucp_Mc));    /* Optimize register allocation: use a real register. */
4605      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
4606      OP1(SLJIT_MOV_UB, STACK_TOP, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4607    
4608    label = LABEL();    label = LABEL();
4609    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);
4610    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
4611    read_char(common);    read_char(common);
4612    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4613    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));
4614    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);
4615    
4616      OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);
4617      OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STACK_TOP), (sljit_sw)PRIV(ucp_gbtable));
4618      OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);
4619      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4620      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4621      JUMPTO(SLJIT_C_NOT_ZERO, label);
4622    
4623    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
4624    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4625      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
4626    
4627    if (common->mode == JIT_PARTIAL_HARD_COMPILE)    if (common->mode == JIT_PARTIAL_HARD_COMPILE)
4628      {      {
4629      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 4647  switch(type)
4647        {        {
4648        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);
4649        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);
4650        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS);
4651        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);
4652        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);
4653        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));
4654        check_partial(common, TRUE);        check_partial(common, TRUE);
4655        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
# Line 4308  switch(type) Line 4749  switch(type)
4749    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));
4750    
4751    if (!common->endonly)    if (!common->endonly)
4752      compile_char1_trypath(common, OP_EODN, cc, backtracks);      compile_char1_matchingpath(common, OP_EODN, cc, backtracks);
4753    else    else
4754      {      {
4755      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 4829  switch(type)
4829      }      }
4830    oc = char_othercase(common, c);    oc = char_othercase(common, c);
4831    bit = c ^ oc;    bit = c ^ oc;
4832    if (ispowerof2(bit))    if (is_powerof2(bit))
4833      {      {
4834      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4835      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));
4836      return cc + length;      return cc + length;
4837      }      }
4838    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);
4839    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4840    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);
4841    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);
4842    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
4843    return cc + length;    return cc + length;
4844    
# Line 4424  switch(type) Line 4865  switch(type)
4865        /* Skip the variable-length character. */        /* Skip the variable-length character. */
4866        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));
4867        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4868        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);
4869        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4870        JUMPHERE(jump[0]);        JUMPHERE(jump[0]);
4871        return cc + 1;        return cc + 1;
# Line 4449  switch(type) Line 4890  switch(type)
4890      {      {
4891      oc = char_othercase(common, c);      oc = char_othercase(common, c);
4892      bit = c ^ oc;      bit = c ^ oc;
4893      if (ispowerof2(bit))      if (is_powerof2(bit))
4894        {        {
4895        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4896        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 4928  switch(type)
4928  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4929    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4930    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4931    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4932    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4933    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);
4934    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 4497  switch(type) Line 4938  switch(type)
4938  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4939    return cc + 32 / sizeof(pcre_uchar);    return cc + 32 / sizeof(pcre_uchar);
4940    
4941  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4942    case OP_XCLASS:    case OP_XCLASS:
4943    compile_xclass_trypath(common, cc + LINK_SIZE, backtracks);    compile_xclass_matchingpath(common, cc + LINK_SIZE, backtracks);
4944    return cc + GET(cc, 0) - 1;    return cc + GET(cc, 0) - 1;
4945  #endif  #endif
4946    
# Line 4533  SLJIT_ASSERT_STOP(); Line 4974  SLJIT_ASSERT_STOP();
4974  return cc;  return cc;
4975  }  }
4976    
4977  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)
4978  {  {
4979  /* This function consumes at least one input character. */  /* This function consumes at least one input character. */
4980  /* 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 5037  if (context.length > 0)
5037    }    }
5038    
5039  /* A non-fixed length character will be checked if length == 0. */  /* A non-fixed length character will be checked if length == 0. */
5040  return compile_char1_trypath(common, *cc, cc + 1, backtracks);  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);
5041  }  }
5042    
5043  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 5052  if (!common->jscript_compat)
5052      {      {
5053      /* OVECTOR(1) contains the "string begin - 1" constant. */      /* OVECTOR(1) contains the "string begin - 1" constant. */
5054      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));
5055      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
5056      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));
5057      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);
5058      return JUMP(SLJIT_C_NOT_ZERO);      return JUMP(SLJIT_C_NOT_ZERO);
5059      }      }
5060    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 5063  return CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT
5063  }  }
5064    
5065  /* Forward definitions. */  /* Forward definitions. */
5066  static void compile_trypath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);
5067  static void compile_backtrackpath(compiler_common *, struct backtrack_common *);  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);
5068    
5069  #define PUSH_BACKTRACK(size, ccstart, error) \  #define PUSH_BACKTRACK(size, ccstart, error) \
5070    do \    do \
# Line 4653  static void compile_backtrackpath(compil Line 5094  static void compile_backtrackpath(compil
5094    
5095  #define BACKTRACK_AS(type) ((type *)backtrack)  #define BACKTRACK_AS(type) ((type *)backtrack)
5096    
5097  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)
5098  {  {
5099  DEFINE_COMPILER;  DEFINE_COMPILER;
5100  int offset = GET2(cc, 1) << 1;  int offset = GET2(cc, 1) << 1;
# Line 4669  if (withchecks && !common->jscript_compa Line 5110  if (withchecks && !common->jscript_compa
5110  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5111  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5112    {    {
5113    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);
5114    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));
5115    if (withchecks)    if (withchecks)
5116      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5117    
5118    /* Needed to save important temporary registers. */    /* Needed to save important temporary registers. */
5119    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5120    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
5121    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);
5122    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));
5123    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5124    if (common->mode == JIT_COMPILE)    if (common->mode == JIT_COMPILE)
# Line 4735  if (jump != NULL) Line 5176  if (jump != NULL)
5176  return cc + 1 + IMM2_SIZE;  return cc + 1 + IMM2_SIZE;
5177  }  }
5178    
5179  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)
5180  {  {
5181  DEFINE_COMPILER;  DEFINE_COMPILER;
5182  backtrack_common *backtrack;  backtrack_common *backtrack;
# Line 4790  if (!minimize) Line 5231  if (!minimize)
5231      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5232      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5233      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5234      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));
5235      zerolength = compile_ref_checks(common, ccbegin, NULL);      zerolength = compile_ref_checks(common, ccbegin, NULL);
5236      /* Restore if not zero length. */      /* Restore if not zero length. */
5237      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));
5238      }      }
5239    else    else
5240      {      {
# Line 4806  if (!minimize) Line 5247  if (!minimize)
5247      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
5248    
5249    label = LABEL();    label = LABEL();
5250    compile_ref_trypath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);
5251    
5252    if (min > 1 || max > 1)    if (min > 1 || max > 1)
5253      {      {
# Line 4834  if (!minimize) Line 5275  if (!minimize)
5275      }      }
5276    
5277    JUMPHERE(zerolength);    JUMPHERE(zerolength);
5278    BACKTRACK_AS(iterator_backtrack)->trypath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5279    
5280    decrease_call_count(common);    decrease_call_count(common);
5281    return cc;    return cc;
# Line 4854  if (min == 0) Line 5295  if (min == 0)
5295  else  else
5296    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);
5297    
5298  BACKTRACK_AS(iterator_backtrack)->trypath = LABEL();  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5299  if (max > 0)  if (max > 0)
5300    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));
5301    
5302  compile_