/[pcre]/code/trunk/pcre_jit_compile.c
ViewVC logotype

Diff of /code/trunk/pcre_jit_compile.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 977 by zherczeg, Sun Jun 17 06:20:52 2012 UTC revision 1367 by zherczeg, Mon Oct 7 07:41:44 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;    pcre_uint32 limit_match;
172    int calllimit;    int real_offset_count;
173      int offset_count;
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 167  typedef struct executable_functions { Line 181  typedef struct executable_functions {
181    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184      pcre_uint32 top_bracket;
185      pcre_uint32 limit_match;
186    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
187  } executable_functions;  } executable_functions;
188    
# Line 175  typedef struct jump_list { Line 191  typedef struct jump_list {
191    struct jump_list *next;    struct jump_list *next;
192  } jump_list;  } jump_list;
193    
 enum stub_types { stack_alloc };  
   
194  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
195    struct sljit_jump *start;    struct sljit_jump *start;
196    struct sljit_label *leave;    struct sljit_label *quit;
197    struct stub_list *next;    struct stub_list *next;
198  } stub_list;  } stub_list;
199    
200    enum frame_types {
201      no_frame = -1,
202      no_stack = -2
203    };
204    
205    enum control_types {
206      type_mark = 0,
207      type_then_trap = 1
208    };
209    
210  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
213  code generator. It is allocated by compile_trypath, and contains  code generator. It is allocated by compile_matchingpath, and contains
214  the aguments for compile_backtrackpath. Must be the first member  the arguments for compile_backtrackingpath. Must be the first member
215  of its descendants. */  of its descendants. */
216  typedef struct backtrack_common {  typedef struct backtrack_common {
217    /* Concatenation stack. */    /* Concatenation stack. */
# Line 205  typedef struct backtrack_common { Line 227  typedef struct backtrack_common {
227  typedef struct assert_backtrack {  typedef struct assert_backtrack {
228    backtrack_common common;    backtrack_common common;
229    jump_list *condfailed;    jump_list *condfailed;
230    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
231    int framesize;    int framesize;
232    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
233    int localptr;    int private_data_ptr;
234    /* For iterators. */    /* For iterators. */
235    struct sljit_label *trypath;    struct sljit_label *matchingpath;
236  } assert_backtrack;  } assert_backtrack;
237    
238  typedef struct bracket_backtrack {  typedef struct bracket_backtrack {
239    backtrack_common common;    backtrack_common common;
240    /* Where to coninue if an alternative is successfully matched. */    /* Where to coninue if an alternative is successfully matched. */
241    struct sljit_label *alttrypath;    struct sljit_label *alternative_matchingpath;
242    /* For rmin and rmax iterators. */    /* For rmin and rmax iterators. */
243    struct sljit_label *recursivetrypath;    struct sljit_label *recursive_matchingpath;
244    /* For greedy ? operator. */    /* For greedy ? operator. */
245    struct sljit_label *zerotrypath;    struct sljit_label *zero_matchingpath;
246    /* Contains the branches of a failed condition. */    /* Contains the branches of a failed condition. */
247    union {    union {
248      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
249      jump_list *condfailed;      jump_list *condfailed;
250      assert_backtrack *assert;      assert_backtrack *assert;
251      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
252      int framesize;      int framesize;
253    } u;    } u;
254    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
255    int localptr;    int private_data_ptr;
256  } bracket_backtrack;  } bracket_backtrack;
257    
258  typedef struct bracketpos_backtrack {  typedef struct bracketpos_backtrack {
259    backtrack_common common;    backtrack_common common;
260    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
261    int localptr;    int private_data_ptr;
262    /* Reverting stack is needed. */    /* Reverting stack is needed. */
263    int framesize;    int framesize;
264    /* Allocated stack size. */    /* Allocated stack size. */
# Line 245  typedef struct bracketpos_backtrack { Line 267  typedef struct bracketpos_backtrack {
267    
268  typedef struct braminzero_backtrack {  typedef struct braminzero_backtrack {
269    backtrack_common common;    backtrack_common common;
270    struct sljit_label *trypath;    struct sljit_label *matchingpath;
271  } braminzero_backtrack;  } braminzero_backtrack;
272    
273  typedef struct iterator_backtrack {  typedef struct iterator_backtrack {
274    backtrack_common common;    backtrack_common common;
275    /* Next iteration. */    /* Next iteration. */
276    struct sljit_label *trypath;    struct sljit_label *matchingpath;
277  } iterator_backtrack;  } iterator_backtrack;
278    
279  typedef struct recurse_entry {  typedef struct recurse_entry {
# Line 261  typedef struct recurse_entry { Line 283  typedef struct recurse_entry {
283    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
284    jump_list *calls;    jump_list *calls;
285    /* Points to the starting opcode. */    /* Points to the starting opcode. */
286    int start;    sljit_sw start;
287  } recurse_entry;  } recurse_entry;
288    
289  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
290    backtrack_common common;    backtrack_common common;
291      BOOL inlined_pattern;
292  } recurse_backtrack;  } recurse_backtrack;
293    
294    #define OP_THEN_TRAP OP_TABLE_LENGTH
295    
296    typedef struct then_trap_backtrack {
297      backtrack_common common;
298      /* If then_trap is not NULL, this structure contains the real
299      then_trap for the backtracking path. */
300      struct then_trap_backtrack *then_trap;
301      /* Points to the starting opcode. */
302      sljit_sw start;
303      /* Exit point for the then opcodes of this alternative. */
304      jump_list *quit;
305      /* Frame size of the current alternative. */
306      int framesize;
307    } then_trap_backtrack;
308    
309    #define MAX_RANGE_SIZE 6
310    
311  typedef struct compiler_common {  typedef struct compiler_common {
312      /* The sljit ceneric compiler. */
313    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
314      /* First byte code. */
315    pcre_uchar *start;    pcre_uchar *start;
316      /* Maps private data offset to each opcode. */
317    /* Opcode local area direct map. */    sljit_si *private_data_ptrs;
318    int *localptrs;    /* Tells whether the capturing bracket is optimized. */
319    int cbraptr;    pcre_uint8 *optimized_cbracket;
320    /* OVector starting point. Must be divisible by 2. */    /* Tells whether the starting offset is a target of then. */
321      pcre_uint8 *then_offsets;
322      /* Current position where a THEN must jump. */
323      then_trap_backtrack *then_trap;
324      /* Starting offset of private data for capturing brackets. */
325      int cbra_ptr;
326      /* Output vector starting point. Must be divisible by 2. */
327    int ovector_start;    int ovector_start;
328    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
329    int req_char_ptr;    int req_char_ptr;
330    /* Head of the last recursion. */    /* Head of the last recursion. */
331    int recursive_head;    int recursive_head_ptr;
332    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
333    int start_used_ptr;    int start_used_ptr;
334    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 289  typedef struct compiler_common { Line 337  typedef struct compiler_common {
337    int first_line_end;    int first_line_end;
338    /* Points to the marked string. */    /* Points to the marked string. */
339    int mark_ptr;    int mark_ptr;
340      /* Recursive control verb management chain. */
341      int control_head_ptr;
342      /* Points to the last matched capture block index. */
343      int capture_last_ptr;
344      /* Points to the starting position of the current match. */
345      int start_ptr;
346    
347    /* Other  */    /* Flipped and lower case tables. */
348    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
349    sljit_w lcc;    sljit_sw lcc;
350      /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
351    int mode;    int mode;
352      /* \K is found in the pattern. */
353      BOOL has_set_som;
354      /* (*SKIP:arg) is found in the pattern. */
355      BOOL has_skip_arg;
356      /* (*THEN) is found in the pattern. */
357      BOOL has_then;
358      /* Needs to know the start position anytime. */
359      BOOL needs_start_ptr;
360      /* Currently in recurse or negative assert. */
361      BOOL local_exit;
362      /* Currently in a positive assert. */
363      BOOL positive_assert;
364      /* Newline control. */
365    int nltype;    int nltype;
366    int newline;    int newline;
367    int bsr_nltype;    int bsr_nltype;
368      /* Dollar endonly. */
369    int endonly;    int endonly;
370    BOOL has_set_som;    /* Tables. */
371    sljit_w ctypes;    sljit_sw ctypes;
372    sljit_uw name_table;    int digits[2 + MAX_RANGE_SIZE];
373    sljit_w name_count;    /* Named capturing brackets. */
374    sljit_w name_entry_size;    pcre_uchar *name_table;
375      sljit_sw name_count;
376      sljit_sw name_entry_size;
377    
378    /* Labels and jump lists. */    /* Labels and jump lists. */
379    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
380    struct sljit_label *leavelabel;    struct sljit_label *quit_label;
381    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
382      struct sljit_label *accept_label;
383    stub_list *stubs;    stub_list *stubs;
384    recurse_entry *entries;    recurse_entry *entries;
385    recurse_entry *currententry;    recurse_entry *currententry;
386    jump_list *partialmatch;    jump_list *partialmatch;
387    jump_list *leave;    jump_list *quit;
388      jump_list *positive_assert_quit;
389      jump_list *forced_quit;
390    jump_list *accept;    jump_list *accept;
391    jump_list *calllimit;    jump_list *calllimit;
392    jump_list *stackalloc;    jump_list *stackalloc;
# Line 323  typedef struct compiler_common { Line 397  typedef struct compiler_common {
397    jump_list *vspace;    jump_list *vspace;
398    jump_list *casefulcmp;    jump_list *casefulcmp;
399    jump_list *caselesscmp;    jump_list *caselesscmp;
400      jump_list *reset_match;
401    BOOL jscript_compat;    BOOL jscript_compat;
402  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
403    BOOL utf;    BOOL utf;
404  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
405    BOOL use_ucp;    BOOL use_ucp;
406  #endif  #endif
407    #ifndef COMPILE_PCRE32
408    jump_list *utfreadchar;    jump_list *utfreadchar;
409    #endif
410  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
411    jump_list *utfreadtype8;    jump_list *utfreadtype8;
412  #endif  #endif
# Line 347  typedef struct compare_context { Line 424  typedef struct compare_context {
424  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
425    int ucharptr;    int ucharptr;
426    union {    union {
427      sljit_i asint;      sljit_si asint;
428      sljit_uh asushort;      sljit_uh asushort;
429  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
430      sljit_ub asbyte;      sljit_ub asbyte;
431      sljit_ub asuchars[4];      sljit_ub asuchars[4];
432  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
433      sljit_uh asuchars[2];      sljit_uh asuchars[2];
434  #endif  #elif defined COMPILE_PCRE32
435        sljit_ui asuchars[1];
436  #endif  #endif
437    } c;    } c;
438    union {    union {
439      sljit_i asint;      sljit_si asint;
440      sljit_uh asushort;      sljit_uh asushort;
441  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
442      sljit_ub asbyte;      sljit_ub asbyte;
443      sljit_ub asuchars[4];      sljit_ub asuchars[4];
444  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
445      sljit_uh asuchars[2];      sljit_uh asuchars[2];
446  #endif  #elif defined COMPILE_PCRE32
447        sljit_ui asuchars[1];
448  #endif  #endif
449    } oc;    } oc;
450  #endif  #endif
451  } compare_context;  } compare_context;
452    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
453  /* Undefine sljit macros. */  /* Undefine sljit macros. */
454  #undef CMP  #undef CMP
455    
456  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
457  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
458    
459  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
460  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
461  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
462  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
463  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
464  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
465  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
466  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
467  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define COUNT_MATCH   SLJIT_SAVED_EREG2
468  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
469    
470  /* Locals layout. */  /* Local space layout. */
471  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
472  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
473  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
474  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
475  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
476  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
477  /* Max limit of recursions. */  /* Max limit of recursions. */
478  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
479  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
480  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
481  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
482  the start pointers when the end of the capturing group has not yet reached. */  the start pointers when the end of the capturing group has not yet reached. */
483  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
484  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw))
485  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
486  #define PRIV_DATA(cc)    (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
487    
488  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
489  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
490  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
491  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
492  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
493  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
494    #elif defined COMPILE_PCRE32
495    #define MOV_UCHAR  SLJIT_MOV_UI
496    #define MOVU_UCHAR SLJIT_MOVU_UI
497  #else  #else
498  #error Unsupported compiling mode  #error Unsupported compiling mode
499  #endif  #endif
 #endif  
500    
501  /* Shortcuts. */  /* Shortcuts. */
502  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 441  the start pointers when the end of the c Line 513  the start pointers when the end of the c
513    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
514  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
515    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
516    #define SET_LABEL(jump, label) \
517      sljit_set_label((jump), (label))
518  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
519    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
520  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
521    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))
522  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
523    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
524  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
525    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
526    
# Line 461  return cc; Line 535  return cc;
535    
536  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
537   next_opcode   next_opcode
538   get_localspace   check_opcode_types
539   set_localptrs   set_private_data_ptrs
540   get_framesize   get_framesize
541   init_frame   init_frame
542   get_localsize   get_private_data_copy_length
543   copy_locals   copy_private_data
544   compile_trypath   compile_matchingpath
545   compile_backtrackpath   compile_backtrackingpath
546  */  */
547    
548  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
# Line 489  switch(*cc) Line 563  switch(*cc)
563    case OP_WORDCHAR:    case OP_WORDCHAR:
564    case OP_ANY:    case OP_ANY:
565    case OP_ALLANY:    case OP_ALLANY:
566      case OP_NOTPROP:
567      case OP_PROP:
568    case OP_ANYNL:    case OP_ANYNL:
569    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
570    case OP_HSPACE:    case OP_HSPACE:
# Line 501  switch(*cc) Line 577  switch(*cc)
577    case OP_CIRCM:    case OP_CIRCM:
578    case OP_DOLL:    case OP_DOLL:
579    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:  
580    case OP_CRSTAR:    case OP_CRSTAR:
581    case OP_CRMINSTAR:    case OP_CRMINSTAR:
582    case OP_CRPLUS:    case OP_CRPLUS:
583    case OP_CRMINPLUS:    case OP_CRMINPLUS:
584    case OP_CRQUERY:    case OP_CRQUERY:
585    case OP_CRMINQUERY:    case OP_CRMINQUERY:
586      case OP_CRRANGE:
587      case OP_CRMINRANGE:
588      case OP_CLASS:
589      case OP_NCLASS:
590      case OP_REF:
591      case OP_REFI:
592      case OP_RECURSE:
593      case OP_CALLOUT:
594      case OP_ALT:
595      case OP_KET:
596      case OP_KETRMAX:
597      case OP_KETRMIN:
598      case OP_KETRPOS:
599      case OP_REVERSE:
600      case OP_ASSERT:
601      case OP_ASSERT_NOT:
602      case OP_ASSERTBACK:
603      case OP_ASSERTBACK_NOT:
604      case OP_ONCE:
605      case OP_ONCE_NC:
606      case OP_BRA:
607      case OP_BRAPOS:
608      case OP_CBRA:
609      case OP_CBRAPOS:
610      case OP_COND:
611      case OP_SBRA:
612      case OP_SBRAPOS:
613      case OP_SCBRA:
614      case OP_SCBRAPOS:
615      case OP_SCOND:
616      case OP_CREF:
617      case OP_DNCREF:
618      case OP_RREF:
619      case OP_DNRREF:
620    case OP_DEF:    case OP_DEF:
621    case OP_BRAZERO:    case OP_BRAZERO:
622    case OP_BRAMINZERO:    case OP_BRAMINZERO:
623    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
624      case OP_PRUNE:
625      case OP_SKIP:
626      case OP_THEN:
627    case OP_COMMIT:    case OP_COMMIT:
628    case OP_FAIL:    case OP_FAIL:
629    case OP_ACCEPT:    case OP_ACCEPT:
630    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
631      case OP_CLOSE:
632    case OP_SKIPZERO:    case OP_SKIPZERO:
633    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
634    
635    case OP_CHAR:    case OP_CHAR:
636    case OP_CHARI:    case OP_CHARI:
# Line 543  switch(*cc) Line 642  switch(*cc)
642    case OP_MINPLUS:    case OP_MINPLUS:
643    case OP_QUERY:    case OP_QUERY:
644    case OP_MINQUERY:    case OP_MINQUERY:
645      case OP_UPTO:
646      case OP_MINUPTO:
647      case OP_EXACT:
648    case OP_POSSTAR:    case OP_POSSTAR:
649    case OP_POSPLUS:    case OP_POSPLUS:
650    case OP_POSQUERY:    case OP_POSQUERY:
651      case OP_POSUPTO:
652    case OP_STARI:    case OP_STARI:
653    case OP_MINSTARI:    case OP_MINSTARI:
654    case OP_PLUSI:    case OP_PLUSI:
655    case OP_MINPLUSI:    case OP_MINPLUSI:
656    case OP_QUERYI:    case OP_QUERYI:
657    case OP_MINQUERYI:    case OP_MINQUERYI:
658      case OP_UPTOI:
659      case OP_MINUPTOI:
660      case OP_EXACTI:
661    case OP_POSSTARI:    case OP_POSSTARI:
662    case OP_POSPLUSI:    case OP_POSPLUSI:
663    case OP_POSQUERYI:    case OP_POSQUERYI:
664      case OP_POSUPTOI:
665    case OP_NOTSTAR:    case OP_NOTSTAR:
666    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
667    case OP_NOTPLUS:    case OP_NOTPLUS:
668    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
669    case OP_NOTQUERY:    case OP_NOTQUERY:
670    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
671      case OP_NOTUPTO:
672      case OP_NOTMINUPTO:
673      case OP_NOTEXACT:
674    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
675    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
676    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
677      case OP_NOTPOSUPTO:
678    case OP_NOTSTARI:    case OP_NOTSTARI:
679    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
680    case OP_NOTPLUSI:    case OP_NOTPLUSI:
681    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
682    case OP_NOTQUERYI:    case OP_NOTQUERYI:
683    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:  
684    case OP_NOTUPTOI:    case OP_NOTUPTOI:
685    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
686    case OP_NOTEXACTI:    case OP_NOTEXACTI:
687      case OP_NOTPOSSTARI:
688      case OP_NOTPOSPLUSI:
689      case OP_NOTPOSQUERYI:
690    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
691    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
692  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
693    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
694  #endif  #endif
695    return cc;    return cc;
696    
697    case OP_NOTPROP:    /* Special cases. */
698    case OP_PROP:    case OP_TYPESTAR:
699    return cc + 1 + 2;    case OP_TYPEMINSTAR:
700      case OP_TYPEPLUS:
701      case OP_TYPEMINPLUS:
702      case OP_TYPEQUERY:
703      case OP_TYPEMINQUERY:
704    case OP_TYPEUPTO:    case OP_TYPEUPTO:
705    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
706    case OP_TYPEEXACT:    case OP_TYPEEXACT:
707      case OP_TYPEPOSSTAR:
708      case OP_TYPEPOSPLUS:
709      case OP_TYPEPOSQUERY:
710    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
711    case OP_REF:    return cc + PRIV(OP_lengths)[*cc] - 1;
   case OP_REFI:  
   case OP_CREF:  
   case OP_NCREF:  
   case OP_RREF:  
   case OP_NRREF:  
   case OP_CLOSE:  
   cc += 1 + IMM2_SIZE;  
   return cc;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   return cc + 1 + 2 * IMM2_SIZE;  
712    
713    case OP_CLASS:    case OP_ANYBYTE:
714    case OP_NCLASS:  #ifdef SUPPORT_UTF
715    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
716    #endif
717      return cc + 1;
718    
719  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
720    case OP_XCLASS:    case OP_XCLASS:
721    return cc + GET(cc, 1);    return cc + GET(cc, 1);
722  #endif  #endif
723    
   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;  
   
724    case OP_MARK:    case OP_MARK:
725      case OP_PRUNE_ARG:
726      case OP_SKIP_ARG:
727      case OP_THEN_ARG:
728    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
729    
730    default:    default:
731      /* All opcodes are supported now! */
732      SLJIT_ASSERT_STOP();
733    return NULL;    return NULL;
734    }    }
735  }  }
736    
737  static int get_localspace(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
738  {  {
739  int localspace = 0;  pcre_uchar *slot;
740  pcre_uchar *alternative;  int i;
741    
742  /* 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. */
743  while (cc < ccend)  while (cc < ccend)
744    {    {
# Line 681  while (cc < ccend) Line 749  while (cc < ccend)
749      cc += 1;      cc += 1;
750      break;      break;
751    
752      case OP_ASSERT:      case OP_REF:
753      case OP_ASSERT_NOT:      case OP_REFI:
754      case OP_ASSERTBACK:      common->optimized_cbracket[GET2(cc, 1)] = 0;
755      case OP_ASSERTBACK_NOT:      cc += 1 + IMM2_SIZE;
     case OP_ONCE:  
     case OP_ONCE_NC:  
     case OP_BRAPOS:  
     case OP_SBRA:  
     case OP_SBRAPOS:  
     case OP_SCOND:  
     localspace += sizeof(sljit_w);  
     cc += 1 + LINK_SIZE;  
756      break;      break;
757    
758      case OP_CBRAPOS:      case OP_CBRAPOS:
759      case OP_SCBRAPOS:      case OP_SCBRAPOS:
760      localspace += sizeof(sljit_w);      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
761      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
762      break;      break;
763    
764      case OP_COND:      case OP_COND:
765      /* Might be a hidden SCOND. */      case OP_SCOND:
766      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
767      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
768        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
769          return FALSE;
770      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
771      break;      break;
772    
773        case OP_CREF:
774        i = GET2(cc, 1);
775        common->optimized_cbracket[i] = 0;
776        cc += 1 + IMM2_SIZE;
777        break;
778    
779        case OP_DNCREF:
780        i = GET2(cc, 1 + IMM2_SIZE);
781        slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
782        while (i-- > 0)
783          {
784          common->optimized_cbracket[GET2(slot, 0)] = 0;
785          slot += common->name_entry_size;
786          }
787        cc += 1 + 2 * IMM2_SIZE;
788        break;
789    
790      case OP_RECURSE:      case OP_RECURSE:
791      /* Set its value only once. */      /* Set its value only once. */
792      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
793        {        {
794        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
795        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
796        }        }
797      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
798      break;      break;
799    
800        case OP_CALLOUT:
801        if (common->capture_last_ptr == 0)
802          {
803          common->capture_last_ptr = common->ovector_start;
804          common->ovector_start += sizeof(sljit_sw);
805          }
806        cc += 2 + 2 * LINK_SIZE;
807        break;
808    
809        case OP_THEN_ARG:
810        common->has_then = TRUE;
811        common->control_head_ptr = 1;
812        /* Fall through. */
813    
814        case OP_PRUNE_ARG:
815        common->needs_start_ptr = TRUE;
816        /* Fall through. */
817    
818      case OP_MARK:      case OP_MARK:
819      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
820        {        {
821        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
822        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
823        }        }
824      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
825      break;      break;
826    
827        case OP_THEN:
828        common->has_then = TRUE;
829        common->control_head_ptr = 1;
830        /* Fall through. */
831    
832        case OP_PRUNE:
833        case OP_SKIP:
834        common->needs_start_ptr = TRUE;
835        cc += 1;
836        break;
837    
838        case OP_SKIP_ARG:
839        common->control_head_ptr = 1;
840        common->has_skip_arg = TRUE;
841        cc += 1 + 2 + cc[1];
842        break;
843    
844      default:      default:
845      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
846      if (cc == NULL)      if (cc == NULL)
847        return -1;        return FALSE;
848      break;      break;
849      }      }
850    }    }
851  return localspace;  return TRUE;
852    }
853    
854    static int get_class_iterator_size(pcre_uchar *cc)
855    {
856    switch(*cc)
857      {
858      case OP_CRSTAR:
859      case OP_CRPLUS:
860      return 2;
861    
862      case OP_CRMINSTAR:
863      case OP_CRMINPLUS:
864      case OP_CRQUERY:
865      case OP_CRMINQUERY:
866      return 1;
867    
868      case OP_CRRANGE:
869      case OP_CRMINRANGE:
870      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
871        return 0;
872      return 2;
873    
874      default:
875      return 0;
876      }
877  }  }
878    
879  static void set_localptrs(compiler_common *common, int localptr, pcre_uchar *ccend)  static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
880    {
881    pcre_uchar *end = bracketend(begin);
882    pcre_uchar *next;
883    pcre_uchar *next_end;
884    pcre_uchar *max_end;
885    pcre_uchar type;
886    sljit_sw length = end - begin;
887    int min, max, i;
888    
889    /* Detect fixed iterations first. */
890    if (end[-(1 + LINK_SIZE)] != OP_KET)
891      return FALSE;
892    
893    /* Already detected repeat. */
894    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
895      return TRUE;
896    
897    next = end;
898    min = 1;
899    while (1)
900      {
901      if (*next != *begin)
902        break;
903      next_end = bracketend(next);
904      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
905        break;
906      next = next_end;
907      min++;
908      }
909    
910    if (min == 2)
911      return FALSE;
912    
913    max = 0;
914    max_end = next;
915    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
916      {
917      type = *next;
918      while (1)
919        {
920        if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
921          break;
922        next_end = bracketend(next + 2 + LINK_SIZE);
923        if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
924          break;
925        next = next_end;
926        max++;
927        }
928    
929      if (next[0] == type && next[1] == *begin && max >= 1)
930        {
931        next_end = bracketend(next + 1);
932        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
933          {
934          for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
935            if (*next_end != OP_KET)
936              break;
937    
938          if (i == max)
939            {
940            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
941            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
942            /* +2 the original and the last. */
943            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
944            if (min == 1)
945              return TRUE;
946            min--;
947            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
948            }
949          }
950        }
951      }
952    
953    if (min >= 3)
954      {
955      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
956      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
957      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
958      return TRUE;
959      }
960    
961    return FALSE;
962    }
963    
964    #define CASE_ITERATOR_PRIVATE_DATA_1 \
965        case OP_MINSTAR: \
966        case OP_MINPLUS: \
967        case OP_QUERY: \
968        case OP_MINQUERY: \
969        case OP_MINSTARI: \
970        case OP_MINPLUSI: \
971        case OP_QUERYI: \
972        case OP_MINQUERYI: \
973        case OP_NOTMINSTAR: \
974        case OP_NOTMINPLUS: \
975        case OP_NOTQUERY: \
976        case OP_NOTMINQUERY: \
977        case OP_NOTMINSTARI: \
978        case OP_NOTMINPLUSI: \
979        case OP_NOTQUERYI: \
980        case OP_NOTMINQUERYI:
981    
982    #define CASE_ITERATOR_PRIVATE_DATA_2A \
983        case OP_STAR: \
984        case OP_PLUS: \
985        case OP_STARI: \
986        case OP_PLUSI: \
987        case OP_NOTSTAR: \
988        case OP_NOTPLUS: \
989        case OP_NOTSTARI: \
990        case OP_NOTPLUSI:
991    
992    #define CASE_ITERATOR_PRIVATE_DATA_2B \
993        case OP_UPTO: \
994        case OP_MINUPTO: \
995        case OP_UPTOI: \
996        case OP_MINUPTOI: \
997        case OP_NOTUPTO: \
998        case OP_NOTMINUPTO: \
999        case OP_NOTUPTOI: \
1000        case OP_NOTMINUPTOI:
1001    
1002    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1003        case OP_TYPEMINSTAR: \
1004        case OP_TYPEMINPLUS: \
1005        case OP_TYPEQUERY: \
1006        case OP_TYPEMINQUERY:
1007    
1008    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1009        case OP_TYPESTAR: \
1010        case OP_TYPEPLUS:
1011    
1012    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1013        case OP_TYPEUPTO: \
1014        case OP_TYPEMINUPTO:
1015    
1016    static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1017  {  {
1018  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1019  pcre_uchar *alternative;  pcre_uchar *alternative;
1020    pcre_uchar *end = NULL;
1021    int private_data_ptr = *private_data_start;
1022    int space, size, bracketlen;
1023    
1024  while (cc < ccend)  while (cc < ccend)
1025    {    {
1026      space = 0;
1027      size = 0;
1028      bracketlen = 0;
1029      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1030        return;
1031    
1032      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1033        if (detect_repeat(common, cc))
1034          {
1035          /* These brackets are converted to repeats, so no global
1036          based single character repeat is allowed. */
1037          if (cc >= end)
1038            end = bracketend(cc);
1039          }
1040    
1041    switch(*cc)    switch(*cc)
1042      {      {
1043        case OP_KET:
1044        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1045          {
1046          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1047          private_data_ptr += sizeof(sljit_sw);
1048          cc += common->private_data_ptrs[cc + 1 - common->start];
1049          }
1050        cc += 1 + LINK_SIZE;
1051        break;
1052    
1053      case OP_ASSERT:      case OP_ASSERT:
1054      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1055      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 756  while (cc < ccend) Line 1060  while (cc < ccend)
1060      case OP_SBRA:      case OP_SBRA:
1061      case OP_SBRAPOS:      case OP_SBRAPOS:
1062      case OP_SCOND:      case OP_SCOND:
1063      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1064      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1065      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1066      break;      break;
1067    
1068      case OP_CBRAPOS:      case OP_CBRAPOS:
1069      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1070      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1071      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1072      cc += 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1073      break;      break;
1074    
1075      case OP_COND:      case OP_COND:
# Line 773  while (cc < ccend) Line 1077  while (cc < ccend)
1077      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1078      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1079        {        {
1080        common->localptrs[cc - common->start] = localptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1081        localptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1082        }        }
1083      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1084        break;
1085    
1086        case OP_BRA:
1087        bracketlen = 1 + LINK_SIZE;
1088      break;      break;
1089    
1090        case OP_CBRA:
1091        case OP_SCBRA:
1092        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1093        break;
1094    
1095        CASE_ITERATOR_PRIVATE_DATA_1
1096        space = 1;
1097        size = -2;
1098        break;
1099    
1100        CASE_ITERATOR_PRIVATE_DATA_2A
1101        space = 2;
1102        size = -2;
1103        break;
1104    
1105        CASE_ITERATOR_PRIVATE_DATA_2B
1106        space = 2;
1107        size = -(2 + IMM2_SIZE);
1108        break;
1109    
1110        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1111        space = 1;
1112        size = 1;
1113        break;
1114    
1115        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1116        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1117          space = 2;
1118        size = 1;
1119        break;
1120    
1121        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1122        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1123          space = 2;
1124        size = 1 + IMM2_SIZE;
1125        break;
1126    
1127        case OP_CLASS:
1128        case OP_NCLASS:
1129        size += 1 + 32 / sizeof(pcre_uchar);
1130        space = get_class_iterator_size(cc + size);
1131        break;
1132    
1133    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1134        case OP_XCLASS:
1135        size = GET(cc, 1);
1136        space = get_class_iterator_size(cc + size);
1137        break;
1138    #endif
1139    
1140      default:      default:
1141      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1142      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1143      break;      break;
1144      }      }
1145    
1146      /* Character iterators, which are not inside a repeated bracket,
1147         gets a private slot instead of allocating it on the stack. */
1148      if (space > 0 && cc >= end)
1149        {
1150        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1151        private_data_ptr += sizeof(sljit_sw) * space;
1152        }
1153    
1154      if (size != 0)
1155        {
1156        if (size < 0)
1157          {
1158          cc += -size;
1159    #ifdef SUPPORT_UTF
1160          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1161    #endif
1162          }
1163        else
1164          cc += size;
1165        }
1166    
1167      if (bracketlen > 0)
1168        {
1169        if (cc >= end)
1170          {
1171          end = bracketend(cc);
1172          if (end[-1 - LINK_SIZE] == OP_KET)
1173            end = NULL;
1174          }
1175        cc += bracketlen;
1176        }
1177    }    }
1178    *private_data_start = private_data_ptr;
1179  }  }
1180    
1181  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1182  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)
1183  {  {
 pcre_uchar *ccend = bracketend(cc);  
1184  int length = 0;  int length = 0;
1185  BOOL possessive = FALSE;  int possessive = 0;
1186    BOOL stack_restore = FALSE;
1187  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1188  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1189    /* The last capture is a local variable even for recursions. */
1190    BOOL capture_last_found = FALSE;
1191    
1192  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1193    SLJIT_ASSERT(common->control_head_ptr != 0);
1194    *needs_control_head = TRUE;
1195    #else
1196    *needs_control_head = FALSE;
1197    #endif
1198    
1199    if (ccend == NULL)
1200    {    {
1201    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1202    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1203        {
1204        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1205        /* This is correct regardless of common->capture_last_ptr. */
1206        capture_last_found = TRUE;
1207        }
1208      cc = next_opcode(common, cc);
1209    }    }
1210    
 cc = next_opcode(common, cc);  
1211  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1212  while (cc < ccend)  while (cc < ccend)
1213    switch(*cc)    switch(*cc)
1214      {      {
1215      case OP_SET_SOM:      case OP_SET_SOM:
1216      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1217        stack_restore = TRUE;
1218      if (!setsom_found)      if (!setsom_found)
1219        {        {
1220        length += 2;        length += 2;
# Line 817  while (cc < ccend) Line 1223  while (cc < ccend)
1223      cc += 1;      cc += 1;
1224      break;      break;
1225    
1226      case OP_MARK:      case OP_MARK:
1227      SLJIT_ASSERT(common->mark_ptr != 0);      case OP_PRUNE_ARG:
1228      if (!setmark_found)      case OP_THEN_ARG:
1229        {      SLJIT_ASSERT(common->mark_ptr != 0);
1230        length += 2;      stack_restore = TRUE;
1231        setmark_found = TRUE;      if (!setmark_found)
1232        }        {
1233      cc += 1 + 2 + cc[1];        length += 2;
1234      break;        setmark_found = TRUE;
1235          }
1236        if (common->control_head_ptr != 0)
1237          *needs_control_head = TRUE;
1238        cc += 1 + 2 + cc[1];
1239        break;
1240    
1241        case OP_RECURSE:
1242        stack_restore = TRUE;
1243        if (common->has_set_som && !setsom_found)
1244          {
1245          length += 2;
1246          setsom_found = TRUE;
1247          }
1248        if (common->mark_ptr != 0 && !setmark_found)
1249          {
1250          length += 2;
1251          setmark_found = TRUE;
1252          }
1253        if (common->capture_last_ptr != 0 && !capture_last_found)
1254          {
1255          length += 2;
1256          capture_last_found = TRUE;
1257          }
1258        cc += 1 + LINK_SIZE;
1259        break;
1260    
1261        case OP_CBRA:
1262        case OP_CBRAPOS:
1263        case OP_SCBRA:
1264        case OP_SCBRAPOS:
1265        stack_restore = TRUE;
1266        if (common->capture_last_ptr != 0 && !capture_last_found)
1267          {
1268          length += 2;
1269          capture_last_found = TRUE;
1270          }
1271        length += 3;
1272        cc += 1 + LINK_SIZE + IMM2_SIZE;
1273        break;
1274    
1275        default:
1276        stack_restore = TRUE;
1277        /* Fall through. */
1278    
1279        case OP_NOT_WORD_BOUNDARY:
1280        case OP_WORD_BOUNDARY:
1281        case OP_NOT_DIGIT:
1282        case OP_DIGIT:
1283        case OP_NOT_WHITESPACE:
1284        case OP_WHITESPACE:
1285        case OP_NOT_WORDCHAR:
1286        case OP_WORDCHAR:
1287        case OP_ANY:
1288        case OP_ALLANY:
1289        case OP_ANYBYTE:
1290        case OP_NOTPROP:
1291        case OP_PROP:
1292        case OP_ANYNL:
1293        case OP_NOT_HSPACE:
1294        case OP_HSPACE:
1295        case OP_NOT_VSPACE:
1296        case OP_VSPACE:
1297        case OP_EXTUNI:
1298        case OP_EODN:
1299        case OP_EOD:
1300        case OP_CIRC:
1301        case OP_CIRCM:
1302        case OP_DOLL:
1303        case OP_DOLLM:
1304        case OP_CHAR:
1305        case OP_CHARI:
1306        case OP_NOT:
1307        case OP_NOTI:
1308    
1309        case OP_EXACT:
1310        case OP_POSSTAR:
1311        case OP_POSPLUS:
1312        case OP_POSQUERY:
1313        case OP_POSUPTO:
1314    
1315        case OP_EXACTI:
1316        case OP_POSSTARI:
1317        case OP_POSPLUSI:
1318        case OP_POSQUERYI:
1319        case OP_POSUPTOI:
1320    
1321        case OP_NOTEXACT:
1322        case OP_NOTPOSSTAR:
1323        case OP_NOTPOSPLUS:
1324        case OP_NOTPOSQUERY:
1325        case OP_NOTPOSUPTO:
1326    
1327      case OP_RECURSE:      case OP_NOTEXACTI:
1328      if (common->has_set_som && !setsom_found)      case OP_NOTPOSSTARI:
1329        {      case OP_NOTPOSPLUSI:
1330        length += 2;      case OP_NOTPOSQUERYI:
1331        setsom_found = TRUE;      case OP_NOTPOSUPTOI:
       }  
     if (common->mark_ptr != 0 && !setmark_found)  
       {  
       length += 2;  
       setmark_found = TRUE;  
       }  
     cc += 1 + LINK_SIZE;  
     break;  
1332    
1333      case OP_CBRA:      case OP_TYPEEXACT:
1334      case OP_CBRAPOS:      case OP_TYPEPOSSTAR:
1335      case OP_SCBRA:      case OP_TYPEPOSPLUS:
1336      case OP_SCBRAPOS:      case OP_TYPEPOSQUERY:
1337      length += 3;      case OP_TYPEPOSUPTO:
1338      cc += 1 + LINK_SIZE + IMM2_SIZE;  
1339      break;      case OP_CLASS:
1340        case OP_NCLASS:
1341        case OP_XCLASS:
1342    
     default:  
1343      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1344      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1345      break;      break;
1346      }      }
1347    
1348  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1349  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1350    return -1;    return stack_restore ? no_frame : no_stack;
1351    
1352  if (length > 0)  if (length > 0)
1353    return length + 1;    return length + 1;
1354  return -1;  return stack_restore ? no_frame : no_stack;
1355  }  }
1356    
1357  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)
1358  {  {
1359  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1360  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1361  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1362    /* The last capture is a local variable even for recursions. */
1363    BOOL capture_last_found = FALSE;
1364  int offset;  int offset;
1365    
1366  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 877  SLJIT_UNUSED_ARG(stacktop); Line 1368  SLJIT_UNUSED_ARG(stacktop);
1368  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1369    
1370  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1371  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1372    cc = next_opcode(common, cc);    {
1373      ccend = bracketend(cc) - (1 + LINK_SIZE);
1374      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1375        cc = next_opcode(common, cc);
1376      }
1377    
1378  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1379  while (cc < ccend)  while (cc < ccend)
1380    switch(*cc)    switch(*cc)
# Line 888  while (cc < ccend) Line 1384  while (cc < ccend)
1384      if (!setsom_found)      if (!setsom_found)
1385        {        {
1386        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1387        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1388        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1389        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1390        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1391        setsom_found = TRUE;        setsom_found = TRUE;
1392        }        }
1393      cc += 1;      cc += 1;
1394      break;      break;
1395    
1396      case OP_MARK:      case OP_MARK:
1397        case OP_PRUNE_ARG:
1398        case OP_THEN_ARG:
1399      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1400      if (!setmark_found)      if (!setmark_found)
1401        {        {
1402        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);
1403        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);
1404        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1405        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1406        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1407        setmark_found = TRUE;        setmark_found = TRUE;
1408        }        }
1409      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 915  while (cc < ccend) Line 1413  while (cc < ccend)
1413      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1414        {        {
1415        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1416        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1417        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1418        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1419        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1420        setsom_found = TRUE;        setsom_found = TRUE;
1421        }        }
1422      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1423        {        {
1424        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);
1425        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);
1426        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1427        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1428        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1429        setmark_found = TRUE;        setmark_found = TRUE;
1430        }        }
1431        if (common->capture_last_ptr != 0 && !capture_last_found)
1432          {
1433          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1434          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1435          stackpos += (int)sizeof(sljit_sw);
1436          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1437          stackpos += (int)sizeof(sljit_sw);
1438          capture_last_found = TRUE;
1439          }
1440      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1441      break;      break;
1442    
# Line 937  while (cc < ccend) Line 1444  while (cc < ccend)
1444      case OP_CBRAPOS:      case OP_CBRAPOS:
1445      case OP_SCBRA:      case OP_SCBRA:
1446      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1447        if (common->capture_last_ptr != 0 && !capture_last_found)
1448          {
1449          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1450          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1451          stackpos += (int)sizeof(sljit_sw);
1452          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1453          stackpos += (int)sizeof(sljit_sw);
1454          capture_last_found = TRUE;
1455          }
1456      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1457      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1458      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1459      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1460      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));
1461      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1462      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1463      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1464      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1465    
1466      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1467      break;      break;
# Line 956  while (cc < ccend) Line 1472  while (cc < ccend)
1472      break;      break;
1473      }      }
1474    
1475  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1476  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1477  }  }
1478    
1479  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)
1480  {  {
1481  int localsize = 2;  int private_data_length = needs_control_head ? 3 : 2;
1482    int size;
1483  pcre_uchar *alternative;  pcre_uchar *alternative;
1484  /* Calculate the sum of the local variables. */  /* Calculate the sum of the private machine words. */
1485  while (cc < ccend)  while (cc < ccend)
1486    {    {
1487      size = 0;
1488    switch(*cc)    switch(*cc)
1489      {      {
1490        case OP_KET:
1491        if (PRIVATE_DATA(cc) != 0)
1492          private_data_length++;
1493        cc += 1 + LINK_SIZE;
1494        break;
1495    
1496      case OP_ASSERT:      case OP_ASSERT:
1497      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1498      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 979  while (cc < ccend) Line 1503  while (cc < ccend)
1503      case OP_SBRA:      case OP_SBRA:
1504      case OP_SBRAPOS:      case OP_SBRAPOS:
1505      case OP_SCOND:      case OP_SCOND:
1506      localsize++;      private_data_length++;
1507      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1508      break;      break;
1509    
1510      case OP_CBRA:      case OP_CBRA:
1511      case OP_SCBRA:      case OP_SCBRA:
1512      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1513          private_data_length++;
1514      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1515      break;      break;
1516    
1517      case OP_CBRAPOS:      case OP_CBRAPOS:
1518      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1519      localsize += 2;      private_data_length += 2;
1520      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1521      break;      break;
1522    
# Line 999  while (cc < ccend) Line 1524  while (cc < ccend)
1524      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1525      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1526      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1527        localsize++;        private_data_length++;
1528      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1529      break;      break;
1530    
1531        CASE_ITERATOR_PRIVATE_DATA_1
1532        if (PRIVATE_DATA(cc))
1533          private_data_length++;
1534        cc += 2;
1535    #ifdef SUPPORT_UTF
1536        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1537    #endif
1538        break;
1539    
1540        CASE_ITERATOR_PRIVATE_DATA_2A
1541        if (PRIVATE_DATA(cc))
1542          private_data_length += 2;
1543        cc += 2;
1544    #ifdef SUPPORT_UTF
1545        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1546    #endif
1547        break;
1548    
1549        CASE_ITERATOR_PRIVATE_DATA_2B
1550        if (PRIVATE_DATA(cc))
1551          private_data_length += 2;
1552        cc += 2 + IMM2_SIZE;
1553    #ifdef SUPPORT_UTF
1554        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1555    #endif
1556        break;
1557    
1558        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1559        if (PRIVATE_DATA(cc))
1560          private_data_length++;
1561        cc += 1;
1562        break;
1563    
1564        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1565        if (PRIVATE_DATA(cc))
1566          private_data_length += 2;
1567        cc += 1;
1568        break;
1569    
1570        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1571        if (PRIVATE_DATA(cc))
1572          private_data_length += 2;
1573        cc += 1 + IMM2_SIZE;
1574        break;
1575    
1576        case OP_CLASS:
1577        case OP_NCLASS:
1578    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1579        case OP_XCLASS:
1580        size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1581    #else
1582        size = 1 + 32 / (int)sizeof(pcre_uchar);
1583    #endif
1584        if (PRIVATE_DATA(cc))
1585          private_data_length += get_class_iterator_size(cc + size);
1586        cc += size;
1587        break;
1588    
1589      default:      default:
1590      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1591      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
# Line 1010  while (cc < ccend) Line 1593  while (cc < ccend)
1593      }      }
1594    }    }
1595  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1596  return localsize;  return private_data_length;
1597  }  }
1598    
1599  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,
1600    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1601  {  {
1602  DEFINE_COMPILER;  DEFINE_COMPILER;
1603  int srcw[2];  int srcw[2];
1604  int count;  int count, size;
1605  BOOL tmp1next = TRUE;  BOOL tmp1next = TRUE;
1606  BOOL tmp1empty = TRUE;  BOOL tmp1empty = TRUE;
1607  BOOL tmp2empty = TRUE;  BOOL tmp2empty = TRUE;
# Line 1035  stacktop = STACK(stacktop - 1); Line 1618  stacktop = STACK(stacktop - 1);
1618    
1619  if (!save)  if (!save)
1620    {    {
1621    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1622    if (stackptr < stacktop)    if (stackptr < stacktop)
1623      {      {
1624      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1625      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1626      tmp1empty = FALSE;      tmp1empty = FALSE;
1627      }      }
1628    if (stackptr < stacktop)    if (stackptr < stacktop)
1629      {      {
1630      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1631      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1632      tmp2empty = FALSE;      tmp2empty = FALSE;
1633      }      }
1634    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1635    }    }
1636    
1637  while (status != end)  do
1638    {    {
1639    count = 0;    count = 0;
1640    switch(status)    switch(status)
1641      {      {
1642      case start:      case start:
1643      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1644      count = 1;      count = 1;
1645      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1646        if (needs_control_head)
1647          {
1648          SLJIT_ASSERT(common->control_head_ptr != 0);
1649          count = 2;
1650          srcw[1] = common->control_head_ptr;
1651          }
1652      status = loop;      status = loop;
1653      break;      break;
1654    
# Line 1072  while (status != end) Line 1661  while (status != end)
1661    
1662      switch(*cc)      switch(*cc)
1663        {        {
1664          case OP_KET:
1665          if (PRIVATE_DATA(cc) != 0)
1666            {
1667            count = 1;
1668            srcw[0] = PRIVATE_DATA(cc);
1669            }
1670          cc += 1 + LINK_SIZE;
1671          break;
1672    
1673        case OP_ASSERT:        case OP_ASSERT:
1674        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1675        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1083  while (status != end) Line 1681  while (status != end)
1681        case OP_SBRAPOS:        case OP_SBRAPOS:
1682        case OP_SCOND:        case OP_SCOND:
1683        count = 1;        count = 1;
1684        srcw[0] = PRIV_DATA(cc);        srcw[0] = PRIVATE_DATA(cc);
1685        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1686        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1687        break;        break;
1688    
1689        case OP_CBRA:        case OP_CBRA:
1690        case OP_SCBRA:        case OP_SCBRA:
1691        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1692        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1693            count = 1;
1694            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1695            }
1696        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1697        break;        break;
1698    
1699        case OP_CBRAPOS:        case OP_CBRAPOS:
1700        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1701        count = 2;        count = 2;
1702          srcw[0] = PRIVATE_DATA(cc);
1703        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1704        srcw[0] = PRIV_DATA(cc);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
       SLJIT_ASSERT(srcw[0] != 0);  
1705        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1706        break;        break;
1707    
# Line 1110  while (status != end) Line 1711  while (status != end)
1711        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1712          {          {
1713          count = 1;          count = 1;
1714          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1715          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1716          }          }
1717        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1718        break;        break;
1719    
1720          CASE_ITERATOR_PRIVATE_DATA_1
1721          if (PRIVATE_DATA(cc))
1722            {
1723            count = 1;
1724            srcw[0] = PRIVATE_DATA(cc);
1725            }
1726          cc += 2;
1727    #ifdef SUPPORT_UTF
1728          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1729    #endif
1730          break;
1731    
1732          CASE_ITERATOR_PRIVATE_DATA_2A
1733          if (PRIVATE_DATA(cc))
1734            {
1735            count = 2;
1736            srcw[0] = PRIVATE_DATA(cc);
1737            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1738            }
1739          cc += 2;
1740    #ifdef SUPPORT_UTF
1741          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1742    #endif
1743          break;
1744    
1745          CASE_ITERATOR_PRIVATE_DATA_2B
1746          if (PRIVATE_DATA(cc))
1747            {
1748            count = 2;
1749            srcw[0] = PRIVATE_DATA(cc);
1750            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1751            }
1752          cc += 2 + IMM2_SIZE;
1753    #ifdef SUPPORT_UTF
1754          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1755    #endif
1756          break;
1757    
1758          CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1759          if (PRIVATE_DATA(cc))
1760            {
1761            count = 1;
1762            srcw[0] = PRIVATE_DATA(cc);
1763            }
1764          cc += 1;
1765          break;
1766    
1767          CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1768          if (PRIVATE_DATA(cc))
1769            {
1770            count = 2;
1771            srcw[0] = PRIVATE_DATA(cc);
1772            srcw[1] = srcw[0] + sizeof(sljit_sw);
1773            }
1774          cc += 1;
1775          break;
1776    
1777          CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1778          if (PRIVATE_DATA(cc))
1779            {
1780            count = 2;
1781            srcw[0] = PRIVATE_DATA(cc);
1782            srcw[1] = srcw[0] + sizeof(sljit_sw);
1783            }
1784          cc += 1 + IMM2_SIZE;
1785          break;
1786    
1787          case OP_CLASS:
1788          case OP_NCLASS:
1789    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1790          case OP_XCLASS:
1791          size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1792    #else
1793          size = 1 + 32 / (int)sizeof(pcre_uchar);
1794    #endif
1795          if (PRIVATE_DATA(cc))
1796            switch(get_class_iterator_size(cc + size))
1797              {
1798              case 1:
1799              count = 1;
1800              srcw[0] = PRIVATE_DATA(cc);
1801              break;
1802    
1803              case 2:
1804              count = 2;
1805              srcw[0] = PRIVATE_DATA(cc);
1806              srcw[1] = srcw[0] + sizeof(sljit_sw);
1807              break;
1808    
1809              default:
1810              SLJIT_ASSERT_STOP();
1811              break;
1812              }
1813          cc += size;
1814          break;
1815    
1816        default:        default:
1817        cc = next_opcode(common, cc);        cc = next_opcode(common, cc);
1818        SLJIT_ASSERT(cc != NULL);        SLJIT_ASSERT(cc != NULL);
# Line 1138  while (status != end) Line 1835  while (status != end)
1835          if (!tmp1empty)          if (!tmp1empty)
1836            {            {
1837            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1838            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1839            }            }
1840          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1841          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1149  while (status != end) Line 1846  while (status != end)
1846          if (!tmp2empty)          if (!tmp2empty)
1847            {            {
1848            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1849            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1850            }            }
1851          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1852          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1166  while (status != end) Line 1863  while (status != end)
1863          if (!tmp1empty)          if (!tmp1empty)
1864            {            {
1865            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1866            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1867            }            }
1868          tmp1next = FALSE;          tmp1next = FALSE;
1869          }          }
# Line 1178  while (status != end) Line 1875  while (status != end)
1875          if (!tmp2empty)          if (!tmp2empty)
1876            {            {
1877            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1878            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1879            }            }
1880          tmp1next = TRUE;          tmp1next = TRUE;
1881          }          }
1882        }        }
1883      }      }
1884    }    }
1885    while (status != end);
1886    
1887  if (save)  if (save)
1888    {    {
# Line 1193  if (save) Line 1891  if (save)
1891      if (!tmp1empty)      if (!tmp1empty)
1892        {        {
1893        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1894        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1895        }        }
1896      if (!tmp2empty)      if (!tmp2empty)
1897        {        {
1898        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1899        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1900        }        }
1901      }      }
1902    else    else
# Line 1206  if (save) Line 1904  if (save)
1904      if (!tmp2empty)      if (!tmp2empty)
1905        {        {
1906        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1907        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1908        }        }
1909      if (!tmp1empty)      if (!tmp1empty)
1910        {        {
1911        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1912        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1913        }        }
1914      }      }
1915    }    }
1916  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1917  }  }
1918    
1919  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1920    {
1921    pcre_uchar *end = bracketend(cc);
1922    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1923    
1924    /* Assert captures then. */
1925    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1926      current_offset = NULL;
1927    /* Conditional block does not. */
1928    if (*cc == OP_COND || *cc == OP_SCOND)
1929      has_alternatives = FALSE;
1930    
1931    cc = next_opcode(common, cc);
1932    if (has_alternatives)
1933      current_offset = common->then_offsets + (cc - common->start);
1934    
1935    while (cc < end)
1936      {
1937      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1938        cc = set_then_offsets(common, cc, current_offset);
1939      else
1940        {
1941        if (*cc == OP_ALT && has_alternatives)
1942          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1943        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1944          *current_offset = 1;
1945        cc = next_opcode(common, cc);
1946        }
1947      }
1948    
1949    return end;
1950    }
1951    
1952    #undef CASE_ITERATOR_PRIVATE_DATA_1
1953    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1954    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1955    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1956    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1957    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1958    
1959    static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1960  {  {
1961  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1962  }  }
# Line 1228  static SLJIT_INLINE void set_jumps(jump_ Line 1966  static SLJIT_INLINE void set_jumps(jump_
1966  while (list)  while (list)
1967    {    {
1968    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1969    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1970    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1971    list = list->next;    list = list->next;
1972    }    }
1973  }  }
# Line 1245  if (list_item) Line 1983  if (list_item)
1983    }    }
1984  }  }
1985    
1986  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)
1987  {  {
1988  DEFINE_COMPILER;  DEFINE_COMPILER;
1989  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1990    
1991  if (list_item)  if (list_item)
1992    {    {
   list_item->type = type;  
   list_item->data = data;  
1993    list_item->start = start;    list_item->start = start;
1994    list_item->leave = LABEL();    list_item->quit = LABEL();
1995    list_item->next = common->stubs;    list_item->next = common->stubs;
1996    common->stubs = list_item;    common->stubs = list_item;
1997    }    }
# Line 1269  stub_list* list_item = common->stubs; Line 2005  stub_list* list_item = common->stubs;
2005  while (list_item)  while (list_item)
2006    {    {
2007    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2008    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
2009      {    JUMPTO(SLJIT_JUMP, list_item->quit);
     case stack_alloc:  
     add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));  
     break;  
     }  
   JUMPTO(SLJIT_JUMP, list_item->leave);  
2010    list_item = list_item->next;    list_item = list_item->next;
2011    }    }
2012  common->stubs = NULL;  common->stubs = NULL;
2013  }  }
2014    
2015  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2016  {  {
2017  DEFINE_COMPILER;  DEFINE_COMPILER;
2018    
2019  OP2(SLJIT_SUB | SLJIT_SET_E, CALL_COUNT, 0, CALL_COUNT, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, COUNT_MATCH, 0, COUNT_MATCH, 0, SLJIT_IMM, 1);
2020  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2021  }  }
2022    
# Line 1294  static SLJIT_INLINE void allocate_stack( Line 2025  static SLJIT_INLINE void allocate_stack(
2025  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2026  DEFINE_COMPILER;  DEFINE_COMPILER;
2027    
2028  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));
2029  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2030  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2031  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1302  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 2033  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2033  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2034  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2035  #endif  #endif
2036  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));
2037  }  }
2038    
2039  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2040  {  {
2041  DEFINE_COMPILER;  DEFINE_COMPILER;
2042  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));
2043  }  }
2044    
2045  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1316  static SLJIT_INLINE void reset_ovector(c Line 2047  static SLJIT_INLINE void reset_ovector(c
2047  DEFINE_COMPILER;  DEFINE_COMPILER;
2048  struct sljit_label *loop;  struct sljit_label *loop;
2049  int i;  int i;
2050    
2051  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2052    SLJIT_ASSERT(length > 1);
2053  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2054  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
2055    if (length < 8)
2056      {
2057      for (i = 1; i < length; i++)
2058        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2059      }
2060    else
2061      {
2062      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2063      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2064      loop = LABEL();
2065      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2066      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2067      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2068      }
2069    }
2070    
2071    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2072    {
2073    DEFINE_COMPILER;
2074    struct sljit_label *loop;
2075    int i;
2076    
2077    SLJIT_ASSERT(length > 1);
2078    /* OVECTOR(1) contains the "string begin - 1" constant. */
2079    if (length > 2)
2080      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2081  if (length < 8)  if (length < 8)
2082    {    {
2083    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
2084      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);
2085    }    }
2086  else  else
2087    {    {
2088    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2089    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2090    loop = LABEL();    loop = LABEL();
2091    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);
2092    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);
2093    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2094    }    }
2095    
2096    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2097    if (common->mark_ptr != 0)
2098      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2099    if (common->control_head_ptr != 0)
2100      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2101    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2102    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2103    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2104    }
2105    
2106    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2107    {
2108    while (current != NULL)
2109      {
2110      switch (current[-2])
2111        {
2112        case type_then_trap:
2113        break;
2114    
2115        case type_mark:
2116        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2117          return current[-4];
2118        break;
2119    
2120        default:
2121        SLJIT_ASSERT_STOP();
2122        break;
2123        }
2124      current = (sljit_sw*)current[-1];
2125      }
2126    return -1;
2127  }  }
2128    
2129  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2130  {  {
2131  DEFINE_COMPILER;  DEFINE_COMPILER;
2132  struct sljit_label *loop;  struct sljit_label *loop;
2133  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2134    
2135  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2136  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));
2137  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);
2138    
2139  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2140  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2141    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);
2142  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));
2143  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2144    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);
2145  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));
2146  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));
2147  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2148  /* Unlikely, but possible */  /* Unlikely, but possible */
2149  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);
2150  loop = LABEL();  loop = LABEL();
2151  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);
2152  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));
2153  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2154  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2155  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);
2156  #endif  #endif
2157  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);
2158  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);
2159  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2160  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2161    
2162  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2163  if (topbracket > 1)  if (topbracket > 1)
2164    {    {
2165    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));
2166    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2167    
2168    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2169    loop = LABEL();    loop = LABEL();
2170    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)));
2171    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);
2172    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);
2173    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2174    }    }
2175  else  else
2176    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
2177  }  }
2178    
2179  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *leave)  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)
2180  {  {
2181  DEFINE_COMPILER;  DEFINE_COMPILER;
2182    struct sljit_jump *jump;
2183    
2184  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);
2185  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
2186      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2187    
2188  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2189  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2190  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));
2191  CMPTO(SLJIT_C_LESS, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2, leave);  CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
2192    
2193  /* Store match begin and end. */  /* Store match begin and end. */
2194  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));
2195  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));
2196  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);  
2197    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2198    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);
2199    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2200    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2201    #endif
2202    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2203    JUMPHERE(jump);
2204    
2205    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);
2206  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);
2207  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2208  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);
2209  #endif  #endif
2210  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);
2211    
2212  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);
2213  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2214  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);
2215  #endif  #endif
2216  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);
2217    
2218  JUMPTO(SLJIT_JUMP, leave);  JUMPTO(SLJIT_JUMP, quit);
2219  }  }
2220    
2221  static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)  static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)
# Line 1524  if (c <= 127 && bit == 0x20) Line 2326  if (c <= 127 && bit == 0x20)
2326    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2327    
2328  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2329  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2330    return 0;    return 0;
2331    
2332  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2333    
2334  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2335  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 1543  if (common->utf && c > 127) Line 2345  if (common->utf && c > 127)
2345  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2346  return (0 << 8) | bit;  return (0 << 8) | bit;
2347    
2348  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2349    
 #ifdef COMPILE_PCRE16  
2350  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2351  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2352    {    {
# Line 1556  if (common->utf && c > 65535) Line 2357  if (common->utf && c > 65535)
2357    }    }
2358  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2359  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2360    
2361  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2362  }  }
2363    
2364  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2365  {  {
2366  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2367  DEFINE_COMPILER;  DEFINE_COMPILER;
2368  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2369    
# Line 1578  else if (common->mode == JIT_PARTIAL_SOF Line 2378  else if (common->mode == JIT_PARTIAL_SOF
2378    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);
2379    
2380  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2381    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);
2382  else  else
2383    {    {
2384    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 1591  if (jump != NULL) Line 2391  if (jump != NULL)
2391    JUMPHERE(jump);    JUMPHERE(jump);
2392  }  }
2393    
2394  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2395  {  {
2396  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2397  DEFINE_COMPILER;  DEFINE_COMPILER;
2398  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2399    
2400  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2401    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2402      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2403      return;
2404      }
2405    
2406  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2407  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2408    {    {
2409    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));
2410    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);
2411    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2412    }    }
2413  else  else
2414    {    {
2415    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));
2416    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2417      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2418    else    else
2419      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2420    }    }
2421  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2422  }  }
2423    
2424  static void detect_partial_match(compiler_common *common, jump_list **backtracks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
# Line 1638  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR Line 2437  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2437  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));
2438  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2439    {    {
2440    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);
2441    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2442    }    }
2443  else  else
# Line 1656  static void read_char(compiler_common *c Line 2455  static void read_char(compiler_common *c
2455  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2456  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2457  DEFINE_COMPILER;  DEFINE_COMPILER;
2458  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2459  struct sljit_jump *jump;  struct sljit_jump *jump;
2460  #endif  #endif
2461    
2462  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2463  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2464  if (common->utf)  if (common->utf)
2465    {    {
2466  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2467    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2468  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2469    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2470  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2471    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2472    JUMPHERE(jump);    JUMPHERE(jump);
2473    }    }
2474  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2475  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));
2476  }  }
2477    
# Line 1683  static void peek_char(compiler_common *c Line 2480  static void peek_char(compiler_common *c
2480  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2481  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2482  DEFINE_COMPILER;  DEFINE_COMPILER;
2483  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2484  struct sljit_jump *jump;  struct sljit_jump *jump;
2485  #endif  #endif
2486    
2487  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2488  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2489  if (common->utf)  if (common->utf)
2490    {    {
2491  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2492    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2493  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2494    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2495  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2496    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2497    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2498    JUMPHERE(jump);    JUMPHERE(jump);
2499    }    }
2500  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2501  }  }
2502    
2503  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2504  {  {
2505  /* 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. */
2506  DEFINE_COMPILER;  DEFINE_COMPILER;
2507  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2508  struct sljit_jump *jump;  struct sljit_jump *jump;
2509  #endif  #endif
2510    
# Line 1718  if (common->utf) Line 2513  if (common->utf)
2513    {    {
2514    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2515    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));
2516  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2517    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2518    it is needed in most cases. */    it is needed in most cases. */
2519    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2520    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2521    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2522    JUMPHERE(jump);    JUMPHERE(jump);
2523  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2524    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2525    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2526    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
# Line 1734  if (common->utf) Line 2528  if (common->utf)
2528    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2529    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2530    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);
2531    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2532    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2533    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2534  #endif  #elif defined COMPILE_PCRE32
2535  #endif /* COMPILE_PCRE8 */    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2536      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2537      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2538      JUMPHERE(jump);
2539    #endif /* COMPILE_PCRE[8|16|32] */
2540    return;    return;
2541    }    }
2542  #endif  #endif /* SUPPORT_UTF */
2543  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2544  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));
2545  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2546  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2547  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2548  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2549  #endif  #endif
2550  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2551  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2552  JUMPHERE(jump);  JUMPHERE(jump);
2553  #endif  #endif
2554  }  }
# Line 1759  static void skip_char_back(compiler_comm Line 2557  static void skip_char_back(compiler_comm
2557  {  {
2558  /* 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. */
2559  DEFINE_COMPILER;  DEFINE_COMPILER;
2560  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2561    #if defined COMPILE_PCRE8
2562  struct sljit_label *label;  struct sljit_label *label;
2563    
2564  if (common->utf)  if (common->utf)
# Line 1771  if (common->utf) Line 2570  if (common->utf)
2570    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2571    return;    return;
2572    }    }
2573  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2574  if (common->utf)  if (common->utf)
2575    {    {
2576    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
# Line 1780  if (common->utf) Line 2578  if (common->utf)
2578    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2579    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2580    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);
2581    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2582    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2583    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2584    return;    return;
2585    }    }
2586  #endif  #endif /* COMPILE_PCRE[8|16] */
2587    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2588  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));
2589  }  }
2590    
# Line 1802  if (nltype == NLTYPE_ANY) Line 2601  if (nltype == NLTYPE_ANY)
2601  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2602    {    {
2603    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);
2604    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2605    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);
2606    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);
2607    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));
2608    }    }
2609  else  else
# Line 1816  else Line 2615  else
2615    
2616  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2617    
2618  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2619  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2620  {  {
2621  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
# Line 1904  sljit_emit_fast_return(compiler, RETURN_ Line 2703  sljit_emit_fast_return(compiler, RETURN_
2703  JUMPHERE(jump);  JUMPHERE(jump);
2704    
2705  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2706  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);
2707  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2708  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2709  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2710  }  }
2711    
2712  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
2713    
 #ifdef COMPILE_PCRE16  
2714  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2715  {  {
2716  /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char  /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char
# Line 1937  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC Line 2735  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC
2735  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2736  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2737  }  }
 #endif /* COMPILE_PCRE16 */  
2738    
2739  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16] */
2740    
2741  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2742    
# Line 1959  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 2756  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2756    
2757  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2758  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2759  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));
2760  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2761  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2762  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2763  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2764  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2765  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));
2766  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2767  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2768  }  }
# Line 1979  struct sljit_label *newlinelabel = NULL; Line 2776  struct sljit_label *newlinelabel = NULL;
2776  struct sljit_jump *start;  struct sljit_jump *start;
2777  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2778  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2779  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2780  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2781  #endif  #endif
2782  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 1994  if (firstline) Line 2791  if (firstline)
2791    {    {
2792    /* Search for the end of the first line. */    /* Search for the end of the first line. */
2793    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
2794    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_END, 0);  
2795    
2796    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
2797      {      {
# Line 2006  if (firstline) Line 2802  if (firstline)
2802      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2803      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);
2804      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);
2805        JUMPHERE(end);
2806      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2807      }      }
2808    else    else
# Line 2017  if (firstline) Line 2814  if (firstline)
2814      read_char(common);      read_char(common);
2815      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
2816      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2817        JUMPHERE(end);
2818      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2819      set_jumps(newline, LABEL());      set_jumps(newline, LABEL());
2820      }      }
2821    
2822    JUMPHERE(end);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
   OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  
2823    }    }
2824    
2825  start = JUMP(SLJIT_JUMP);  start = JUMP(SLJIT_JUMP);
# Line 2034  if (newlinecheck) Line 2831  if (newlinecheck)
2831    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2832    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2833    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);
2834    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2835  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2836    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2837  #endif  #endif
2838    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2839    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 2057  if (newlinecheck) Line 2854  if (newlinecheck)
2854    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);
2855    
2856  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));
2857  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2858    #if defined COMPILE_PCRE8
2859  if (common->utf)  if (common->utf)
2860    {    {
2861    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2862    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);
2863    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2864    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2865    }    }
2866  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2867  if (common->utf)  if (common->utf)
2868    {    {
2869    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2870    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2871    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);
2872    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2873    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2874    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2875    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2876    }    }
2877  #endif  #endif /* COMPILE_PCRE[8|16] */
2878    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2879  JUMPHERE(start);  JUMPHERE(start);
2880    
2881  if (newlinecheck)  if (newlinecheck)
# Line 2089  if (newlinecheck) Line 2887  if (newlinecheck)
2887  return mainloop;  return mainloop;
2888  }  }
2889    
2890    #define MAX_N_CHARS 3
2891    
2892    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2893    {
2894    DEFINE_COMPILER;
2895    struct sljit_label *start;
2896    struct sljit_jump *quit;
2897    pcre_uint32 chars[MAX_N_CHARS * 2];
2898    pcre_uchar *cc = common->start + 1 + LINK_SIZE;
2899    int location = 0;
2900    pcre_int32 len, c, bit, caseless;
2901    int must_stop;
2902    
2903    /* We do not support alternatives now. */
2904    if (*(common->start + GET(common->start, 1)) == OP_ALT)
2905      return FALSE;
2906    
2907    while (TRUE)
2908      {
2909      caseless = 0;
2910      must_stop = 1;
2911      switch(*cc)
2912        {
2913        case OP_CHAR:
2914        must_stop = 0;
2915        cc++;
2916        break;
2917    
2918        case OP_CHARI:
2919        caseless = 1;
2920        must_stop = 0;
2921        cc++;
2922        break;
2923    
2924        case OP_SOD:
2925        case OP_SOM:
2926        case OP_SET_SOM:
2927        case OP_NOT_WORD_BOUNDARY:
2928        case OP_WORD_BOUNDARY:
2929        case OP_EODN:
2930        case OP_EOD:
2931        case OP_CIRC:
2932        case OP_CIRCM:
2933        case OP_DOLL:
2934        case OP_DOLLM:
2935        /* Zero width assertions. */
2936        cc++;
2937        continue;
2938    
2939        case OP_PLUS:
2940        case OP_MINPLUS:
2941        case OP_POSPLUS:
2942        cc++;
2943        break;
2944    
2945        case OP_EXACT:
2946        cc += 1 + IMM2_SIZE;
2947        break;
2948    
2949        case OP_PLUSI:
2950        case OP_MINPLUSI:
2951        case OP_POSPLUSI:
2952        caseless = 1;
2953        cc++;
2954        break;
2955    
2956        case OP_EXACTI:
2957        caseless = 1;
2958        cc += 1 + IMM2_SIZE;
2959        break;
2960    
2961        default:
2962        must_stop = 2;
2963        break;
2964        }
2965    
2966      if (must_stop == 2)
2967          break;
2968    
2969      len = 1;
2970    #ifdef SUPPORT_UTF
2971      if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
2972    #endif
2973    
2974      if (caseless && char_has_othercase(common, cc))
2975        {
2976        caseless = char_get_othercase_bit(common, cc);
2977        if (caseless == 0)
2978          return FALSE;
2979    #ifdef COMPILE_PCRE8
2980        caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
2981    #else
2982        if ((caseless & 0x100) != 0)
2983          caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));
2984        else
2985          caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));
2986    #endif
2987        }
2988      else
2989        caseless = 0;
2990    
2991      while (len > 0 && location < MAX_N_CHARS * 2)
2992        {
2993        c = *cc;
2994        bit = 0;
2995        if (len == (caseless & 0xff))
2996          {
2997          bit = caseless >> 8;
2998          c |= bit;
2999          }
3000    
3001        chars[location] = c;
3002        chars[location + 1] = bit;
3003    
3004        len--;
3005        location += 2;
3006        cc++;
3007        }
3008    
3009      if (location >= MAX_N_CHARS * 2 || must_stop != 0)
3010        break;
3011      }
3012    
3013    /* At least two characters are required. */
3014    if (location < 2 * 2)
3015        return FALSE;
3016    
3017    if (firstline)
3018      {
3019      SLJIT_ASSERT(common->first_line_end != 0);
3020      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3021      OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
3022      }
3023    else
3024      OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
3025    
3026    start = LABEL();
3027    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3028    
3029    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
3030    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3031    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3032    if (chars[1] != 0)
3033      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3034    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3035    if (location > 2 * 2)
3036      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3037    if (chars[3] != 0)
3038      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
3039    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
3040    if (location > 2 * 2)
3041      {
3042      if (chars[5] != 0)
3043        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
3044      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);
3045      }
3046    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3047    
3048    JUMPHERE(quit);
3049    
3050    if (firstline)
3051      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3052    else
3053      OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
3054    return TRUE;
3055    }
3056    
3057    #undef MAX_N_CHARS
3058    
3059  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)
3060  {  {
3061  DEFINE_COMPILER;  DEFINE_COMPILER;
3062  struct sljit_label *start;  struct sljit_label *start;
3063  struct sljit_jump *leave;  struct sljit_jump *quit;
3064  struct sljit_jump *found;  struct sljit_jump *found;
3065  pcre_uchar oc, bit;  pcre_uchar oc, bit;
3066    
3067  if (firstline)  if (firstline)
3068    {    {
3069    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3070      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3071    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3072    }    }
3073    
3074  start = LABEL();  start = LABEL();
3075  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3076  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3077    
3078  oc = first_char;  oc = first_char;
# Line 2121  if (first_char == oc) Line 3089  if (first_char == oc)
3089  else  else
3090    {    {
3091    bit = first_char ^ oc;    bit = first_char ^ oc;
3092    if (ispowerof2(bit))    if (is_powerof2(bit))
3093      {      {
3094      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3095      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
# Line 2129  else Line 3097  else
3097    else    else
3098      {      {
3099      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);
3100      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3101      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);
3102      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);
3103      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3104      }      }
3105    }    }
3106    
3107  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 #if defined SUPPORT_UTF && defined COMPILE_PCRE8  
 if (common->utf)  
   {  
   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   }  
 #endif  
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
 if (common->utf)  
   {  
   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);  
   OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);  
   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);  
   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);  
   OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   }  
 #endif  
3108  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3109  JUMPHERE(found);  JUMPHERE(found);
3110  JUMPHERE(leave);  JUMPHERE(quit);
3111    
3112  if (firstline)  if (firstline)
3113    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3114  }  }
3115    
3116  static SLJIT_INLINE void fast_forward_newline(compiler_common *common, BOOL firstline)  static SLJIT_INLINE void fast_forward_newline(compiler_common *common, BOOL firstline)
# Line 2170  DEFINE_COMPILER; Line 3119  DEFINE_COMPILER;
3119  struct sljit_label *loop;  struct sljit_label *loop;
3120  struct sljit_jump *lastchar;  struct sljit_jump *lastchar;
3121  struct sljit_jump *firstchar;  struct sljit_jump *firstchar;
3122  struct sljit_jump *leave;  struct sljit_jump *quit;
3123  struct sljit_jump *foundcr = NULL;  struct sljit_jump *foundcr = NULL;
3124  struct sljit_jump *notfoundnl;  struct sljit_jump *notfoundnl;
3125  jump_list *newline = NULL;  jump_list *newline = NULL;
3126    
3127  if (firstline)  if (firstline)
3128    {    {
3129    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3130      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3131    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3132    }    }
3133    
# Line 2191  if (common->nltype == NLTYPE_FIXED && co Line 3141  if (common->nltype == NLTYPE_FIXED && co
3141    
3142    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3143    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);
3144    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3145  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3146    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3147  #endif  #endif
3148    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3149    
3150    loop = LABEL();    loop = LABEL();
3151    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));
3152    leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3153    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
3154    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
3155    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);
3156    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);
3157    
3158    JUMPHERE(leave);    JUMPHERE(quit);
3159    JUMPHERE(firstchar);    JUMPHERE(firstchar);
3160    JUMPHERE(lastchar);    JUMPHERE(lastchar);
3161    
# Line 2229  set_jumps(newline, loop); Line 3179  set_jumps(newline, loop);
3179    
3180  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3181    {    {
3182    leave = JUMP(SLJIT_JUMP);    quit = JUMP(SLJIT_JUMP);
3183    JUMPHERE(foundcr);    JUMPHERE(foundcr);
3184    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3185    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3186    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);
3187    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3188  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3189    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3190  #endif  #endif
3191    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3192    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
3193    JUMPHERE(leave);    JUMPHERE(quit);
3194    }    }
3195  JUMPHERE(lastchar);  JUMPHERE(lastchar);
3196  JUMPHERE(firstchar);  JUMPHERE(firstchar);
3197    
3198  if (firstline)  if (firstline)
3199    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3200  }  }
3201    
3202    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3203    
3204  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)
3205  {  {
3206  DEFINE_COMPILER;  DEFINE_COMPILER;
3207  struct sljit_label *start;  struct sljit_label *start;
3208  struct sljit_jump *leave;  struct sljit_jump *quit;
3209  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3210    jump_list *matches = NULL;
3211    pcre_uint8 inverted_start_bits[32];
3212    int i;
3213  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3214  struct sljit_jump *jump;  struct sljit_jump *jump;
3215  #endif  #endif
3216    
3217    for (i = 0; i < 32; ++i)
3218      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3219    
3220  if (firstline)  if (firstline)
3221    {    {
3222    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3223      OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
3224    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3225    }    }
3226    
3227  start = LABEL();  start = LABEL();
3228  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3229  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3230  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3231  if (common->utf)  if (common->utf)
3232    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3233  #endif  #endif
3234    
3235    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3236      {
3237  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3238  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3239  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3240  JUMPHERE(jump);    JUMPHERE(jump);
3241  #endif  #endif
3242  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3243  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3244  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3245  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3246  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);
3247  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3248      }
3249    
3250  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3251  if (common->utf)  if (common->utf)
3252    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3253  #endif  #endif
3254  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));
3255  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3256    #if defined COMPILE_PCRE8
3257  if (common->utf)  if (common->utf)
3258    {    {
3259    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3260    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);
3261    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3262    }    }
3263  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3264  if (common->utf)  if (common->utf)
3265    {    {
3266    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3267    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3268    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);
3269    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3270    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3271    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3272    }    }
3273  #endif  #endif /* COMPILE_PCRE[8|16] */
3274    #endif /* SUPPORT_UTF */
3275  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3276  JUMPHERE(found);  if (found != NULL)
3277  JUMPHERE(leave);    JUMPHERE(found);
3278    if (matches != NULL)
3279      set_jumps(matches, LABEL());
3280    JUMPHERE(quit);
3281    
3282  if (firstline)  if (firstline)
3283    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0);
3284  }  }
3285    
3286  static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uchar req_char, BOOL caseless, BOOL has_firstchar)  static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uchar req_char, BOOL caseless, BOOL has_firstchar)
# Line 2325  struct sljit_jump *alreadyfound; Line 3292  struct sljit_jump *alreadyfound;
3292  struct sljit_jump *found;  struct sljit_jump *found;
3293  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3294  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3295  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3296    
3297  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3298  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
# Line 2356  if (req_char == oc) Line 3323  if (req_char == oc)
3323  else  else
3324    {    {
3325    bit = req_char ^ oc;    bit = req_char ^ oc;
3326    if (ispowerof2(bit))    if (is_powerof2(bit))
3327      {      {
3328      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3329      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
# Line 2392  GET_LOCAL_BASE(TMP3, 0, 0); Line 3359  GET_LOCAL_BASE(TMP3, 0, 0);
3359  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3360  mainloop = LABEL();  mainloop = LABEL();
3361  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3362  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);
3363    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3364    
3365  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3366  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));
3367  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));
3368  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));
3369  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3370    
3371  JUMPHERE(jump);  JUMPHERE(jump);
3372  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3373  /* End of dropping frames. */  /* End of dropping frames. */
3374  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3375    
3376  JUMPHERE(jump);  JUMPHERE(jump);
3377  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3378  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3379  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3380  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));  
3381  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3382  }  }
3383    
# Line 2433  static void check_wordboundary(compiler_ Line 3385  static void check_wordboundary(compiler_
3385  {  {
3386  DEFINE_COMPILER;  DEFINE_COMPILER;
3387  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3388    jump_list *skipread_list = NULL;
3389  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3390  struct sljit_jump *jump;  struct sljit_jump *jump;
3391  #endif  #endif
# Line 2458  if (common->use_ucp) Line 3411  if (common->use_ucp)
3411    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3412    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3413    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);
3414    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3415    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);
3416    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);
3417    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3418    JUMPHERE(jump);    JUMPHERE(jump);
3419    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3420    }    }
# Line 2490  else Line 3443  else
3443  JUMPHERE(skipread);  JUMPHERE(skipread);
3444    
3445  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3446  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3447  peek_char(common);  peek_char(common);
3448    
3449  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 2502  if (common->use_ucp) Line 3455  if (common->use_ucp)
3455    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3456    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3457    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);
3458    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3459    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);
3460    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);
3461    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3462    JUMPHERE(jump);    JUMPHERE(jump);
3463    }    }
3464  else  else
# Line 2531  else Line 3484  else
3484      JUMPHERE(jump);      JUMPHERE(jump);
3485  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3486    }    }
3487  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3488    
3489  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);
3490  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3491  }  }
3492    
3493    /*
3494      range format:
3495    
3496      ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).
3497      ranges[1] = first bit (0 or 1)
3498      ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)
3499    */
3500    
3501    static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)
3502    {
3503    DEFINE_COMPILER;
3504    struct sljit_jump *jump;
3505    
3506    if (ranges[0] < 0)
3507      return FALSE;
3508    
3509    switch(ranges[0])
3510      {
3511      case 1:
3512      if (readch)
3513        read_char(common);
3514      add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3515      return TRUE;
3516    
3517      case 2:
3518      if (readch)
3519        read_char(common);
3520      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3521      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3522      return TRUE;
3523    
3524      case 4:
3525      if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])
3526        {
3527        if (readch)
3528          read_char(common);
3529        if (ranges[1] != 0)
3530          {
3531          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3532          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3533          }
3534        else
3535          {
3536          jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);
3537          add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3538          JUMPHERE(jump);
3539          }
3540        return TRUE;
3541        }
3542      if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))
3543        {
3544        if (readch)
3545          read_char(common);
3546        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);
3547        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3548        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3549        return TRUE;
3550        }
3551      return FALSE;
3552    
3553      default:
3554      return FALSE;
3555      }
3556    }
3557    
3558    static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)
3559    {
3560    int i, bit, length;
3561    const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;
3562    
3563    bit = ctypes[0] & flag;
3564    ranges[0] = -1;
3565    ranges[1] = bit != 0 ? 1 : 0;
3566    length = 0;
3567    
3568    for (i = 1; i < 256; i++)
3569      if ((ctypes[i] & flag) != bit)
3570        {
3571        if (length >= MAX_RANGE_SIZE)
3572          return;
3573        ranges[2 + length] = i;
3574        length++;
3575        bit ^= flag;
3576        }
3577    
3578    if (bit != 0)
3579      {
3580      if (length >= MAX_RANGE_SIZE)
3581        return;
3582      ranges[2 + length] = 256;
3583      length++;
3584      }
3585    ranges[0] = length;
3586    }
3587    
3588    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)
3589    {
3590    int ranges[2 + MAX_RANGE_SIZE];
3591    pcre_uint8 bit, cbit, all;
3592    int i, byte, length = 0;
3593    
3594    bit = bits[0] & 0x1;
3595    ranges[1] = bit;
3596    /* Can be 0 or 255. */
3597    all = -bit;
3598    
3599    for (i = 0; i < 256; )
3600      {
3601      byte = i >> 3;
3602      if ((i & 0x7) == 0 && bits[byte] == all)
3603        i += 8;
3604      else
3605        {
3606        cbit = (bits[byte] >> (i & 0x7)) & 0x1;
3607        if (cbit != bit)
3608          {
3609          if (length >= MAX_RANGE_SIZE)
3610            return FALSE;
3611          ranges[2 + length] = i;
3612          length++;
3613          bit = cbit;
3614          all = -cbit;
3615          }
3616        i++;
3617        }
3618      }
3619    
3620    if (((bit == 0) && nclass) || ((bit == 1) && !nclass))
3621      {
3622      if (length >= MAX_RANGE_SIZE)
3623        return FALSE;
3624      ranges[2 + length] = 256;
3625      length++;
3626      }
3627    ranges[0] = length;
3628    
3629    return check_ranges(common, ranges, backtracks, FALSE);
3630    }
3631    
3632  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
3633  {  {
3634  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
# Line 2546  sljit_emit_fast_enter(compiler, RETURN_A Line 3638  sljit_emit_fast_enter(compiler, RETURN_A
3638    
3639  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3640  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);
3641  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3642  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);
3643  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3644  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3645  if (common->utf)  if (common->utf)
3646    {    {
3647  #endif  #endif
3648    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3649    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3650    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);
3651  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3652    }    }
3653  #endif  #endif
3654  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3655  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);
3656  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3657  }  }
3658    
# Line 2572  DEFINE_COMPILER; Line 3664  DEFINE_COMPILER;
3664  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3665    
3666  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);
3667  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3668  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);
3669  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3670  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);
3671  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3672  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3673  if (common->utf)  if (common->utf)
3674    {    {
3675  #endif  #endif
3676    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3677    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);
3678    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3679    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);
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, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3682    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);
3683    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3684    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);
3685    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3686    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);
3687    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3688    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);
3689  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3690    }    }
3691  #endif  #endif
3692  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3693  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);
3694    
3695  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3696  }  }
# Line 2612  sljit_emit_fast_enter(compiler, RETURN_A Line 3704  sljit_emit_fast_enter(compiler, RETURN_A
3704    
3705  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3706  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);
3707  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3708  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);
3709  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3710  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3711  if (common->utf)  if (common->utf)
3712    {    {
3713  #endif  #endif
3714    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);
3715    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3716    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);
3717  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3718    }    }
3719  #endif  #endif
3720  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3721  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);
3722    
3723  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3724  }  }
# Line 2712  sljit_emit_fast_return(compiler, RETURN_ Line 3804  sljit_emit_fast_return(compiler, RETURN_
3804    
3805  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3806    
3807  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)
3808  {  {
3809  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3810  int c1, c2;  pcre_uint32 c1, c2;
3811  const pcre_uchar *src2 = args->uchar_ptr;  const pcre_uchar *src2 = args->uchar_ptr;
3812  const pcre_uchar *end2 = args->end;  const pcre_uchar *end2 = args->end;
3813    const ucd_record *ur;
3814    const pcre_uint32 *pp;
3815    
3816  while (src1 < end1)  while (src1 < end1)
3817    {    {
# Line 2725  while (src1 < end1) Line 3819  while (src1 < end1)
3819      return (pcre_uchar*)1;      return (pcre_uchar*)1;
3820    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
3821    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
3822    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return NULL;    ur = GET_UCD(c2);
3823      if (c1 != c2 && c1 != c2 + ur->other_case)
3824        {
3825        pp = PRIV(ucd_caseless_sets) + ur->caseset;
3826        for (;;)
3827          {
3828          if (c1 < *pp) return NULL;
3829          if (c1 == *pp++) break;
3830          }
3831        }
3832    }    }
3833  return src2;  return src2;
3834  }  }
# Line 2747  if (caseless && char_has_othercase(commo Line 3850  if (caseless && char_has_othercase(commo
3850    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
3851    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
3852    /* Extracting bit difference info. */    /* Extracting bit difference info. */
3853  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3854    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
3855    othercasebit &= 0xff;    othercasebit &= 0xff;
3856  #else  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3857  #ifdef COMPILE_PCRE16    /* Note that this code only handles characters in the BMP. If there
3858      ever are characters outside the BMP whose othercase differs in only one
3859      bit from itself (there currently are none), this code will need to be
3860      revised for COMPILE_PCRE32. */
3861    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
3862    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
3863      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
3864    else    else
3865      othercasebit &= 0xff;      othercasebit &= 0xff;
3866  #endif  #endif /* COMPILE_PCRE[8|16|32] */
 #endif  
3867    }    }
3868    
3869  if (context->sourcereg == -1)  if (context->sourcereg == -1)
3870    {    {
3871  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3872  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3873    if (context->length >= 4)    if (context->length >= 4)
3874      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
# Line 2772  if (context->sourcereg == -1) Line 3877  if (context->sourcereg == -1)
3877    else    else
3878  #endif  #endif
3879      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3880  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
3881  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3882    if (context->length >= 4)    if (context->length >= 4)
3883      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3884    else    else
3885  #endif  #endif
3886      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3887  #endif  #elif defined COMPILE_PCRE32
3888  #endif /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3889    #endif /* COMPILE_PCRE[8|16|32] */
3890    context->sourcereg = TMP2;    context->sourcereg = TMP2;
3891    }    }
3892    
# Line 2795  do Line 3900  do
3900  #endif  #endif
3901    
3902    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3903  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3904    
3905    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3906    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 2810  do Line 3915  do
3915      }      }
3916    context->ucharptr++;    context->ucharptr++;
3917    
3918  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3919    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))
3920  #else  #else
3921    if (context->ucharptr >= 2 || context->length == 0)    if (context->ucharptr >= 2 || context->length == 0)
# Line 2818  do Line 3923  do
3923      {      {
3924      if (context->length >= 4)      if (context->length >= 4)
3925        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  
3926      else if (context->length >= 2)      else if (context->length >= 2)
3927        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);
3928    #if defined COMPILE_PCRE8
3929      else if (context->length >= 1)      else if (context->length >= 1)
3930        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);
3931  #else  #endif /* COMPILE_PCRE8 */
     else if (context->length >= 2)  
       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
3932      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3933    
3934      switch(context->ucharptr)      switch(context->ucharptr)
# Line 2860  do Line 3962  do
3962    
3963  #else  #else
3964    
3965    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3966  #ifdef COMPILE_PCRE8    if (context->length >= 1)
3967    if (context->length > 0)      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3968      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  
3969    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3970    
3971    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 2912  return cc; Line 4010  return cc;
4010      } \      } \
4011    charoffset = (value);    charoffset = (value);
4012    
4013  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)
4014  {  {
4015  DEFINE_COMPILER;  DEFINE_COMPILER;
4016  jump_list *found = NULL;  jump_list *found = NULL;
4017  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;
4018  unsigned int c;  pcre_int32 c, charoffset;
4019  int compares;  const pcre_uint32 *other_cases;
4020  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4021  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4022    int compares, invertcmp, numberofcmps;
4023  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4024  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4025  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4026  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4027  unsigned int typeoffset;  pcre_int32 typeoffset;
4028  #endif  #endif
 int invertcmp, numberofcmps;  
 unsigned int charoffset;  
4029    
4030  /* Although SUPPORT_UTF must be defined, we are not necessary in utf mode. */  /* Although SUPPORT_UTF must be defined, we are
4031       not necessary in utf mode even in 8 bit mode. */
4032  detect_partial_match(common, backtracks);  detect_partial_match(common, backtracks);
4033  read_char(common);  read_char(common);
4034    
# Line 2941  if ((*cc++ & XCL_MAP) != 0) Line 4039  if ((*cc++ & XCL_MAP) != 0)
4039    jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4040  #elif defined SUPPORT_UTF  #elif defined SUPPORT_UTF
4041    if (common->utf)    if (common->utf)
4042      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4043  #endif  #endif
4044    
4045    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, list))
4046    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      {
4047    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4048    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4049    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4050    add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4051        OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4052        add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
4053        }
4054    
4055  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
4056    JUMPHERE(jump);    JUMPHERE(jump);
# Line 3022  while (*cc != XCL_END) Line 4123  while (*cc != XCL_END)
4123        needschar = TRUE;        needschar = TRUE;
4124        break;        break;
4125    
4126          case PT_CLIST:
4127          case PT_UCNC:
4128          needschar = TRUE;
4129          break;
4130    
4131        default:        default:
4132        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
4133        break;        break;
# Line 3058  if (needstype || needsscript) Line 4164  if (needstype || needsscript)
4164      {      {
4165      if (scriptreg == TMP1)      if (scriptreg == TMP1)
4166        {        {
4167        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));
4168        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
4169        }        }
4170      else      else
4171        {        {
4172        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
4173        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));
4174        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
4175        }        }
4176      }      }
# Line 3100  while (*cc != XCL_END) Line 4206  while (*cc != XCL_END)
4206      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4207        {        {
4208        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);
4209        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);
4210        numberofcmps++;        numberofcmps++;
4211        }        }
4212      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4213        {        {
4214        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);
4215        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);
4216        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4217        numberofcmps = 0;        numberofcmps = 0;
4218        }        }
# Line 3139  while (*cc != XCL_END) Line 4245  while (*cc != XCL_END)
4245      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4246        {        {
4247        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);
4248        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);
4249        numberofcmps++;        numberofcmps++;
4250        }        }
4251      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4252        {        {
4253        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);
4254        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);
4255        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4256        numberofcmps = 0;        numberofcmps = 0;
4257        }        }
# Line 3176  while (*cc != XCL_END) Line 4282  while (*cc != XCL_END)
4282    
4283        case PT_LAMP:        case PT_LAMP:
4284        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);
4285        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4286        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);
4287        COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL); &n