/[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 993 by zherczeg, Tue Jul 10 04:33:00 2012 UTC revision 1426 by zherczeg, Wed Jan 1 13:14:19 2014 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 *quit;    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 MAX_RANGE_SIZE 6  #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 4
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 291  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    /* Flipped and lower case tables. */    /* 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. */    /* 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. */    /* Newline control. */
365    int nltype;    int nltype;
366      pcre_uint32 nlmax;
367      pcre_uint32 nlmin;
368    int newline;    int newline;
369    int bsr_nltype;    int bsr_nltype;
370      pcre_uint32 bsr_nlmax;
371      pcre_uint32 bsr_nlmin;
372    /* Dollar endonly. */    /* Dollar endonly. */
373    int endonly;    int endonly;
   BOOL has_set_som;  
374    /* Tables. */    /* Tables. */
375    sljit_w ctypes;    sljit_sw ctypes;
   int digits[2 + MAX_RANGE_SIZE];  
376    /* Named capturing brackets. */    /* Named capturing brackets. */
377    sljit_uw name_table;    pcre_uchar *name_table;
378    sljit_w name_count;    sljit_sw name_count;
379    sljit_w name_entry_size;    sljit_sw name_entry_size;
380    
381    /* Labels and jump lists. */    /* Labels and jump lists. */
382    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
383    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
384    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
385      struct sljit_label *accept_label;
386    stub_list *stubs;    stub_list *stubs;
387    recurse_entry *entries;    recurse_entry *entries;
388    recurse_entry *currententry;    recurse_entry *currententry;
389    jump_list *partialmatch;    jump_list *partialmatch;
390    jump_list *quit;    jump_list *quit;
391      jump_list *positive_assert_quit;
392      jump_list *forced_quit;
393    jump_list *accept;    jump_list *accept;
394    jump_list *calllimit;    jump_list *calllimit;
395    jump_list *stackalloc;    jump_list *stackalloc;
# Line 331  typedef struct compiler_common { Line 400  typedef struct compiler_common {
400    jump_list *vspace;    jump_list *vspace;
401    jump_list *casefulcmp;    jump_list *casefulcmp;
402    jump_list *caselesscmp;    jump_list *caselesscmp;
403      jump_list *reset_match;
404    BOOL jscript_compat;    BOOL jscript_compat;
405  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
406    BOOL utf;    BOOL utf;
407  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
408    BOOL use_ucp;    BOOL use_ucp;
409  #endif  #endif
   jump_list *utfreadchar;  
410  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
411      jump_list *utfreadchar;
412      jump_list *utfreadchar16;
413    jump_list *utfreadtype8;    jump_list *utfreadtype8;
414  #endif  #endif
415  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
# Line 355  typedef struct compare_context { Line 426  typedef struct compare_context {
426  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
427    int ucharptr;    int ucharptr;
428    union {    union {
429      sljit_i asint;      sljit_si asint;
430      sljit_uh asushort;      sljit_uh asushort;
431  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
432      sljit_ub asbyte;      sljit_ub asbyte;
433      sljit_ub asuchars[4];      sljit_ub asuchars[4];
434  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
435      sljit_uh asuchars[2];      sljit_uh asuchars[2];
436  #endif  #elif defined COMPILE_PCRE32
437        sljit_ui asuchars[1];
438  #endif  #endif
439    } c;    } c;
440    union {    union {
441      sljit_i asint;      sljit_si asint;
442      sljit_uh asushort;      sljit_uh asushort;
443  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
444      sljit_ub asbyte;      sljit_ub asbyte;
445      sljit_ub asuchars[4];      sljit_ub asuchars[4];
446  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
447      sljit_uh asuchars[2];      sljit_uh asuchars[2];
448  #endif  #elif defined COMPILE_PCRE32
449        sljit_ui asuchars[1];
450  #endif  #endif
451    } oc;    } oc;
452  #endif  #endif
453  } compare_context;  } compare_context;
454    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
455  /* Undefine sljit macros. */  /* Undefine sljit macros. */
456  #undef CMP  #undef CMP
457    
458  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
459  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
460    
461  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
462  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
463  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
464  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
465  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
466  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
467  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
468  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
469  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define COUNT_MATCH   SLJIT_SAVED_EREG2
470  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
471    
472  /* Locals layout. */  /* Local space layout. */
473  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
474  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
475  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
476  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
477  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
478  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
479  /* Max limit of recursions. */  /* Max limit of recursions. */
480  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
481  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
482  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
483  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
484  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. */
485  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
486  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw))
487  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
488  #define PRIV_DATA(cc)    (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
489    
490  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
491  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
492  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
493  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
494  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
495  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
496    #elif defined COMPILE_PCRE32
497    #define MOV_UCHAR  SLJIT_MOV_UI
498    #define MOVU_UCHAR SLJIT_MOVU_UI
499  #else  #else
500  #error Unsupported compiling mode  #error Unsupported compiling mode
501  #endif  #endif
 #endif  
502    
503  /* Shortcuts. */  /* Shortcuts. */
504  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 449  the start pointers when the end of the c Line 515  the start pointers when the end of the c
515    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
516  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
517    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
518    #define SET_LABEL(jump, label) \
519      sljit_set_label((jump), (label))
520  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
521    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
522  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
523    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))
524  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
525    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
526  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
527    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
528    
529    #define READ_CHAR_MAX 0x7fffffff
530    
531  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
532  {  {
533  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
# Line 467  cc += 1 + LINK_SIZE; Line 537  cc += 1 + LINK_SIZE;
537  return cc;  return cc;
538  }  }
539    
540    static int ones_in_half_byte[16] = {
541      /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
542      /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
543    };
544    
545  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
546   next_opcode   next_opcode
547   get_localspace   check_opcode_types
548   set_localptrs   set_private_data_ptrs
549   get_framesize   get_framesize
550   init_frame   init_frame
551   get_localsize   get_private_data_copy_length
552   copy_locals   copy_private_data
553   compile_trypath   compile_matchingpath
554   compile_backtrackpath   compile_backtrackingpath
555  */  */
556    
557  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
# Line 497  switch(*cc) Line 572  switch(*cc)
572    case OP_WORDCHAR:    case OP_WORDCHAR:
573    case OP_ANY:    case OP_ANY:
574    case OP_ALLANY:    case OP_ALLANY:
575      case OP_NOTPROP:
576      case OP_PROP:
577    case OP_ANYNL:    case OP_ANYNL:
578    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
579    case OP_HSPACE:    case OP_HSPACE:
# Line 509  switch(*cc) Line 586  switch(*cc)
586    case OP_CIRCM:    case OP_CIRCM:
587    case OP_DOLL:    case OP_DOLL:
588    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:  
589    case OP_CRSTAR:    case OP_CRSTAR:
590    case OP_CRMINSTAR:    case OP_CRMINSTAR:
591    case OP_CRPLUS:    case OP_CRPLUS:
592    case OP_CRMINPLUS:    case OP_CRMINPLUS:
593    case OP_CRQUERY:    case OP_CRQUERY:
594    case OP_CRMINQUERY:    case OP_CRMINQUERY:
595      case OP_CRRANGE:
596      case OP_CRMINRANGE:
597      case OP_CRPOSSTAR:
598      case OP_CRPOSPLUS:
599      case OP_CRPOSQUERY:
600      case OP_CRPOSRANGE:
601      case OP_CLASS:
602      case OP_NCLASS:
603      case OP_REF:
604      case OP_REFI:
605      case OP_DNREF:
606      case OP_DNREFI:
607      case OP_RECURSE:
608      case OP_CALLOUT:
609      case OP_ALT:
610      case OP_KET:
611      case OP_KETRMAX:
612      case OP_KETRMIN:
613      case OP_KETRPOS:
614      case OP_REVERSE:
615      case OP_ASSERT:
616      case OP_ASSERT_NOT:
617      case OP_ASSERTBACK:
618      case OP_ASSERTBACK_NOT:
619      case OP_ONCE:
620      case OP_ONCE_NC:
621      case OP_BRA:
622      case OP_BRAPOS:
623      case OP_CBRA:
624      case OP_CBRAPOS:
625      case OP_COND:
626      case OP_SBRA:
627      case OP_SBRAPOS:
628      case OP_SCBRA:
629      case OP_SCBRAPOS:
630      case OP_SCOND:
631      case OP_CREF:
632      case OP_DNCREF:
633      case OP_RREF:
634      case OP_DNRREF:
635    case OP_DEF:    case OP_DEF:
636    case OP_BRAZERO:    case OP_BRAZERO:
637    case OP_BRAMINZERO:    case OP_BRAMINZERO:
638    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
639      case OP_PRUNE:
640      case OP_SKIP:
641      case OP_THEN:
642    case OP_COMMIT:    case OP_COMMIT:
643    case OP_FAIL:    case OP_FAIL:
644    case OP_ACCEPT:    case OP_ACCEPT:
645    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
646      case OP_CLOSE:
647    case OP_SKIPZERO:    case OP_SKIPZERO:
648    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
649    
650    case OP_CHAR:    case OP_CHAR:
651    case OP_CHARI:    case OP_CHARI:
# Line 551  switch(*cc) Line 657  switch(*cc)
657    case OP_MINPLUS:    case OP_MINPLUS:
658    case OP_QUERY:    case OP_QUERY:
659    case OP_MINQUERY:    case OP_MINQUERY:
660      case OP_UPTO:
661      case OP_MINUPTO:
662      case OP_EXACT:
663    case OP_POSSTAR:    case OP_POSSTAR:
664    case OP_POSPLUS:    case OP_POSPLUS:
665    case OP_POSQUERY:    case OP_POSQUERY:
666      case OP_POSUPTO:
667    case OP_STARI:    case OP_STARI:
668    case OP_MINSTARI:    case OP_MINSTARI:
669    case OP_PLUSI:    case OP_PLUSI:
670    case OP_MINPLUSI:    case OP_MINPLUSI:
671    case OP_QUERYI:    case OP_QUERYI:
672    case OP_MINQUERYI:    case OP_MINQUERYI:
673      case OP_UPTOI:
674      case OP_MINUPTOI:
675      case OP_EXACTI:
676    case OP_POSSTARI:    case OP_POSSTARI:
677    case OP_POSPLUSI:    case OP_POSPLUSI:
678    case OP_POSQUERYI:    case OP_POSQUERYI:
679      case OP_POSUPTOI:
680    case OP_NOTSTAR:    case OP_NOTSTAR:
681    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
682    case OP_NOTPLUS:    case OP_NOTPLUS:
683    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
684    case OP_NOTQUERY:    case OP_NOTQUERY:
685    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
686      case OP_NOTUPTO:
687      case OP_NOTMINUPTO:
688      case OP_NOTEXACT:
689    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
690    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
691    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
692      case OP_NOTPOSUPTO:
693    case OP_NOTSTARI:    case OP_NOTSTARI:
694    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
695    case OP_NOTPLUSI:    case OP_NOTPLUSI:
696    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
697    case OP_NOTQUERYI:    case OP_NOTQUERYI:
698    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:  
699    case OP_NOTUPTOI:    case OP_NOTUPTOI:
700    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
701    case OP_NOTEXACTI:    case OP_NOTEXACTI:
702      case OP_NOTPOSSTARI:
703      case OP_NOTPOSPLUSI:
704      case OP_NOTPOSQUERYI:
705    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
706    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
707  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
708    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
709  #endif  #endif
710    return cc;    return cc;
711    
712    case OP_NOTPROP:    /* Special cases. */
713    case OP_PROP:    case OP_TYPESTAR:
714    return cc + 1 + 2;    case OP_TYPEMINSTAR:
715      case OP_TYPEPLUS:
716      case OP_TYPEMINPLUS:
717      case OP_TYPEQUERY:
718      case OP_TYPEMINQUERY:
719    case OP_TYPEUPTO:    case OP_TYPEUPTO:
720    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
721    case OP_TYPEEXACT:    case OP_TYPEEXACT:
722      case OP_TYPEPOSSTAR:
723      case OP_TYPEPOSPLUS:
724      case OP_TYPEPOSQUERY:
725    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
726    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;  
727    
728    case OP_CLASS:    case OP_ANYBYTE:
729    case OP_NCLASS:  #ifdef SUPPORT_UTF
730    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
731    #endif
732      return cc + 1;
733    
734  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
735    case OP_XCLASS:    case OP_XCLASS:
736    return cc + GET(cc, 1);    return cc + GET(cc, 1);
737  #endif  #endif
738    
   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;  
   
739    case OP_MARK:    case OP_MARK:
740      case OP_PRUNE_ARG:
741      case OP_SKIP_ARG:
742      case OP_THEN_ARG:
743    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
744    
745    default:    default:
746      /* All opcodes are supported now! */
747      SLJIT_ASSERT_STOP();
748    return NULL;    return NULL;
749    }    }
750  }  }
751    
752  #define CASE_ITERATOR_LOCAL1 \  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
     case OP_MINSTAR: \  
     case OP_MINPLUS: \  
     case OP_QUERY: \  
     case OP_MINQUERY: \  
     case OP_MINSTARI: \  
     case OP_MINPLUSI: \  
     case OP_QUERYI: \  
     case OP_MINQUERYI: \  
     case OP_NOTMINSTAR: \  
     case OP_NOTMINPLUS: \  
     case OP_NOTQUERY: \  
     case OP_NOTMINQUERY: \  
     case OP_NOTMINSTARI: \  
     case OP_NOTMINPLUSI: \  
     case OP_NOTQUERYI: \  
     case OP_NOTMINQUERYI:  
   
 #define CASE_ITERATOR_LOCAL2A \  
     case OP_STAR: \  
     case OP_PLUS: \  
     case OP_STARI: \  
     case OP_PLUSI: \  
     case OP_NOTSTAR: \  
     case OP_NOTPLUS: \  
     case OP_NOTSTARI: \  
     case OP_NOTPLUSI:  
   
 #define CASE_ITERATOR_LOCAL2B \  
     case OP_UPTO: \  
     case OP_MINUPTO: \  
     case OP_UPTOI: \  
     case OP_MINUPTOI: \  
     case OP_NOTUPTO: \  
     case OP_NOTMINUPTO: \  
     case OP_NOTUPTOI: \  
     case OP_NOTMINUPTOI:  
   
 #define CASE_ITERATOR_TYPE_LOCAL1 \  
     case OP_TYPEMINSTAR: \  
     case OP_TYPEMINPLUS: \  
     case OP_TYPEQUERY: \  
     case OP_TYPEMINQUERY:  
   
 #define CASE_ITERATOR_TYPE_LOCAL2A \  
     case OP_TYPESTAR: \  
     case OP_TYPEPLUS:  
   
 #define CASE_ITERATOR_TYPE_LOCAL2B \  
     case OP_TYPEUPTO: \  
     case OP_TYPEMINUPTO:  
   
 static int get_class_iterator_size(pcre_uchar *cc)  
 {  
 switch(*cc)  
   {  
   case OP_CRSTAR:  
   case OP_CRPLUS:  
   return 2;  
   
   case OP_CRMINSTAR:  
   case OP_CRMINPLUS:  
   case OP_CRQUERY:  
   case OP_CRMINQUERY:  
   return 1;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))  
     return 0;  
   return 2;  
   
   default:  
   return 0;  
   }  
 }  
   
 static int get_localspace(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  
753  {  {
754  int localspace = 0;  int count;
755  pcre_uchar *alternative;  pcre_uchar *slot;
 pcre_uchar *end = NULL;  
 int space, size, bracketlen;  
756    
757  /* 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. */
758  while (cc < ccend)  while (cc < ccend)
759    {    {
   space = 0;  
   size = 0;  
   bracketlen = 0;  
760    switch(*cc)    switch(*cc)
761      {      {
762      case OP_SET_SOM:      case OP_SET_SOM:
# Line 772  while (cc < ccend) Line 764  while (cc < ccend)
764      cc += 1;      cc += 1;
765      break;      break;
766    
767      case OP_ASSERT:      case OP_REF:
768      case OP_ASSERT_NOT:      case OP_REFI:
769      case OP_ASSERTBACK:      common->optimized_cbracket[GET2(cc, 1)] = 0;
770      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);  
     bracketlen = 1 + LINK_SIZE;  
771      break;      break;
772    
773      case OP_CBRAPOS:      case OP_CBRAPOS:
774      case OP_SCBRAPOS:      case OP_SCBRAPOS:
775      localspace += sizeof(sljit_w);      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
776      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
777      break;      break;
778    
779      case OP_COND:      case OP_COND:
780      /* Might be a hidden SCOND. */      case OP_SCOND:
781      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
782      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
783        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
784      bracketlen = 1 + LINK_SIZE;        return FALSE;
785      break;      cc += 1 + LINK_SIZE;
   
     case OP_BRA:  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_CBRA:  
     case OP_SCBRA:  
     bracketlen = 1 + LINK_SIZE + IMM2_SIZE;  
     break;  
   
     CASE_ITERATOR_LOCAL1  
     space = 1;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_LOCAL2A  
     space = 2;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_LOCAL2B  
     space = 2;  
     size = -(2 + IMM2_SIZE);  
     break;  
   
     CASE_ITERATOR_TYPE_LOCAL1  
     space = 1;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_LOCAL2A  
     if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)  
       space = 2;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_LOCAL2B  
     if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)  
       space = 2;  
     size = 1 + IMM2_SIZE;  
786      break;      break;
787    
788      case OP_CLASS:      case OP_CREF:
789      case OP_NCLASS:      common->optimized_cbracket[GET2(cc, 1)] = 0;
790      size += 1 + 32 / sizeof(pcre_uchar);      cc += 1 + IMM2_SIZE;
     space = get_class_iterator_size(cc + size);  
791      break;      break;
792    
793  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8      case OP_DNREF:
794      case OP_XCLASS:      case OP_DNREFI:
795      size = GET(cc, 1);      case OP_DNCREF:
796      space = get_class_iterator_size(cc + size);      count = GET2(cc, 1 + IMM2_SIZE);
797        slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
798        while (count-- > 0)
799          {
800          common->optimized_cbracket[GET2(slot, 0)] = 0;
801          slot += common->name_entry_size;
802          }
803        cc += 1 + 2 * IMM2_SIZE;
804      break;      break;
 #endif  
805    
806      case OP_RECURSE:      case OP_RECURSE:
807      /* Set its value only once. */      /* Set its value only once. */
808      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
809        {        {
810        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
811        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
812        }        }
813      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
814      break;      break;
815    
816        case OP_CALLOUT:
817        if (common->capture_last_ptr == 0)
818          {
819          common->capture_last_ptr = common->ovector_start;
820          common->ovector_start += sizeof(sljit_sw);
821          }
822        cc += 2 + 2 * LINK_SIZE;
823        break;
824    
825        case OP_THEN_ARG:
826        common->has_then = TRUE;
827        common->control_head_ptr = 1;
828        /* Fall through. */
829    
830        case OP_PRUNE_ARG:
831        common->needs_start_ptr = TRUE;
832        /* Fall through. */
833    
834      case OP_MARK:      case OP_MARK:
835      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
836        {        {
837        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
838        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
839        }        }
840      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
841      break;      break;
842    
843        case OP_THEN:
844        common->has_then = TRUE;
845        common->control_head_ptr = 1;
846        /* Fall through. */
847    
848        case OP_PRUNE:
849        case OP_SKIP:
850        common->needs_start_ptr = TRUE;
851        cc += 1;
852        break;
853    
854        case OP_SKIP_ARG:
855        common->control_head_ptr = 1;
856        common->has_skip_arg = TRUE;
857        cc += 1 + 2 + cc[1];
858        break;
859    
860      default:      default:
861      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
862      if (cc == NULL)      if (cc == NULL)
863        return -1;        return FALSE;
864      break;      break;
865      }      }
866      }
867    return TRUE;
868    }
869    
870    if (space > 0 && cc >= end)  static int get_class_iterator_size(pcre_uchar *cc)
871      localspace += sizeof(sljit_w) * space;  {
872    switch(*cc)
873      {
874      case OP_CRSTAR:
875      case OP_CRPLUS:
876      return 2;
877    
878    if (size != 0)    case OP_CRMINSTAR:
879      case OP_CRMINPLUS:
880      case OP_CRQUERY:
881      case OP_CRMINQUERY:
882      return 1;
883    
884      case OP_CRRANGE:
885      case OP_CRMINRANGE:
886      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
887        return 0;
888      return 2;
889    
890      default:
891      return 0;
892      }
893    }
894    
895    static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
896    {
897    pcre_uchar *end = bracketend(begin);
898    pcre_uchar *next;
899    pcre_uchar *next_end;
900    pcre_uchar *max_end;
901    pcre_uchar type;
902    sljit_sw length = end - begin;
903    int min, max, i;
904    
905    /* Detect fixed iterations first. */
906    if (end[-(1 + LINK_SIZE)] != OP_KET)
907      return FALSE;
908    
909    /* Already detected repeat. */
910    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
911      return TRUE;
912    
913    next = end;
914    min = 1;
915    while (1)
916      {
917      if (*next != *begin)
918        break;
919      next_end = bracketend(next);
920      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
921        break;
922      next = next_end;
923      min++;
924      }
925    
926    if (min == 2)
927      return FALSE;
928    
929    max = 0;
930    max_end = next;
931    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
932      {
933      type = *next;
934      while (1)
935      {      {
936      if (size < 0)      if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
937        {        break;
938        cc += -size;      next_end = bracketend(next + 2 + LINK_SIZE);
939  #ifdef SUPPORT_UTF      if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
940        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        break;
941  #endif      next = next_end;
942        }      max++;
     else  
       cc += size;  
943      }      }
944    
945    if (bracketlen > 0)    if (next[0] == type && next[1] == *begin && max >= 1)
946      {      {
947      if (cc >= end)      next_end = bracketend(next + 1);
948        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
949        {        {
950        end = bracketend(cc);        for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
951        if (end[-1 - LINK_SIZE] == OP_KET)          if (*next_end != OP_KET)
952          end = NULL;            break;
953    
954          if (i == max)
955            {
956            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
957            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
958            /* +2 the original and the last. */
959            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
960            if (min == 1)
961              return TRUE;
962            min--;
963            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
964            }
965        }        }
     cc += bracketlen;  
966      }      }
967    }    }
968  return localspace;  
969    if (min >= 3)
970      {
971      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
972      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
973      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
974      return TRUE;
975      }
976    
977    return FALSE;
978  }  }
979    
980  static void set_localptrs(compiler_common *common, int localptr, pcre_uchar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
981        case OP_MINSTAR: \
982        case OP_MINPLUS: \
983        case OP_QUERY: \
984        case OP_MINQUERY: \
985        case OP_MINSTARI: \
986        case OP_MINPLUSI: \
987        case OP_QUERYI: \
988        case OP_MINQUERYI: \
989        case OP_NOTMINSTAR: \
990        case OP_NOTMINPLUS: \
991        case OP_NOTQUERY: \
992        case OP_NOTMINQUERY: \
993        case OP_NOTMINSTARI: \
994        case OP_NOTMINPLUSI: \
995        case OP_NOTQUERYI: \
996        case OP_NOTMINQUERYI:
997    
998    #define CASE_ITERATOR_PRIVATE_DATA_2A \
999        case OP_STAR: \
1000        case OP_PLUS: \
1001        case OP_STARI: \
1002        case OP_PLUSI: \
1003        case OP_NOTSTAR: \
1004        case OP_NOTPLUS: \
1005        case OP_NOTSTARI: \
1006        case OP_NOTPLUSI:
1007    
1008    #define CASE_ITERATOR_PRIVATE_DATA_2B \
1009        case OP_UPTO: \
1010        case OP_MINUPTO: \
1011        case OP_UPTOI: \
1012        case OP_MINUPTOI: \
1013        case OP_NOTUPTO: \
1014        case OP_NOTMINUPTO: \
1015        case OP_NOTUPTOI: \
1016        case OP_NOTMINUPTOI:
1017    
1018    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1019        case OP_TYPEMINSTAR: \
1020        case OP_TYPEMINPLUS: \
1021        case OP_TYPEQUERY: \
1022        case OP_TYPEMINQUERY:
1023    
1024    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1025        case OP_TYPESTAR: \
1026        case OP_TYPEPLUS:
1027    
1028    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1029        case OP_TYPEUPTO: \
1030        case OP_TYPEMINUPTO:
1031    
1032    static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1033  {  {
1034  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1035  pcre_uchar *alternative;  pcre_uchar *alternative;
1036  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1037    int private_data_ptr = *private_data_start;
1038  int space, size, bracketlen;  int space, size, bracketlen;
1039    
1040  while (cc < ccend)  while (cc < ccend)
# Line 922  while (cc < ccend) Line 1042  while (cc < ccend)
1042    space = 0;    space = 0;
1043    size = 0;    size = 0;
1044    bracketlen = 0;    bracketlen = 0;
1045      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1046        return;
1047    
1048      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1049        if (detect_repeat(common, cc))
1050          {
1051          /* These brackets are converted to repeats, so no global
1052          based single character repeat is allowed. */
1053          if (cc >= end)
1054            end = bracketend(cc);
1055          }
1056    
1057    switch(*cc)    switch(*cc)
1058      {      {
1059        case OP_KET:
1060        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1061          {
1062          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1063          private_data_ptr += sizeof(sljit_sw);
1064          cc += common->private_data_ptrs[cc + 1 - common->start];
1065          }
1066        cc += 1 + LINK_SIZE;
1067        break;
1068    
1069      case OP_ASSERT:      case OP_ASSERT:
1070      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1071      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 934  while (cc < ccend) Line 1076  while (cc < ccend)
1076      case OP_SBRA:      case OP_SBRA:
1077      case OP_SBRAPOS:      case OP_SBRAPOS:
1078      case OP_SCOND:      case OP_SCOND:
1079      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1080      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1081      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1082      break;      break;
1083    
1084      case OP_CBRAPOS:      case OP_CBRAPOS:
1085      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1086      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1087      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1088      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1089      break;      break;
1090    
# Line 951  while (cc < ccend) Line 1093  while (cc < ccend)
1093      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1094      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1095        {        {
1096        common->localptrs[cc - common->start] = localptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1097        localptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1098        }        }
1099      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1100      break;      break;
# Line 966  while (cc < ccend) Line 1108  while (cc < ccend)
1108      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1109      break;      break;
1110    
1111      CASE_ITERATOR_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
1112      space = 1;      space = 1;
1113      size = -2;      size = -2;
1114      break;      break;
1115    
1116      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
1117      space = 2;      space = 2;
1118      size = -2;      size = -2;
1119      break;      break;
1120    
1121      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
1122      space = 2;      space = 2;
1123      size = -(2 + IMM2_SIZE);      size = -(2 + IMM2_SIZE);
1124      break;      break;
1125    
1126      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1127      space = 1;      space = 1;
1128      size = 1;      size = 1;
1129      break;      break;
1130    
1131      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1132      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1133        space = 2;        space = 2;
1134      size = 1;      size = 1;
1135      break;      break;
1136    
1137      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1138      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1139        space = 2;        space = 2;
1140      size = 1 + IMM2_SIZE;      size = 1 + IMM2_SIZE;
# Line 1017  while (cc < ccend) Line 1159  while (cc < ccend)
1159      break;      break;
1160      }      }
1161    
1162      /* Character iterators, which are not inside a repeated bracket,
1163         gets a private slot instead of allocating it on the stack. */
1164    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1165      {      {
1166      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1167      localptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1168      }      }
1169    
1170    if (size != 0)    if (size != 0)
# Line 1047  while (cc < ccend) Line 1191  while (cc < ccend)
1191      cc += bracketlen;      cc += bracketlen;
1192      }      }
1193    }    }
1194    *private_data_start = private_data_ptr;
1195  }  }
1196    
1197  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1198  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)
1199  {  {
 pcre_uchar *ccend = bracketend(cc);  
1200  int length = 0;  int length = 0;
1201  BOOL possessive = FALSE;  int possessive = 0;
1202    BOOL stack_restore = FALSE;
1203  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1204  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1205    /* The last capture is a local variable even for recursions. */
1206    BOOL capture_last_found = FALSE;
1207    
1208  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1209    SLJIT_ASSERT(common->control_head_ptr != 0);
1210    *needs_control_head = TRUE;
1211    #else
1212    *needs_control_head = FALSE;
1213    #endif
1214    
1215    if (ccend == NULL)
1216    {    {
1217    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1218    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1219        {
1220        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1221        /* This is correct regardless of common->capture_last_ptr. */
1222        capture_last_found = TRUE;
1223        }
1224      cc = next_opcode(common, cc);
1225    }    }
1226    
 cc = next_opcode(common, cc);  
1227  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1228  while (cc < ccend)  while (cc < ccend)
1229    switch(*cc)    switch(*cc)
1230      {      {
1231      case OP_SET_SOM:      case OP_SET_SOM:
1232      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1233        stack_restore = TRUE;
1234      if (!setsom_found)      if (!setsom_found)
1235        {        {
1236        length += 2;        length += 2;
# Line 1080  while (cc < ccend) Line 1240  while (cc < ccend)
1240      break;      break;
1241    
1242      case OP_MARK:      case OP_MARK:
1243        case OP_PRUNE_ARG:
1244        case OP_THEN_ARG:
1245      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1246        stack_restore = TRUE;
1247      if (!setmark_found)      if (!setmark_found)
1248        {        {
1249        length += 2;        length += 2;
1250        setmark_found = TRUE;        setmark_found = TRUE;
1251        }        }
1252        if (common->control_head_ptr != 0)
1253          *needs_control_head = TRUE;
1254      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1255      break;      break;
1256    
1257      case OP_RECURSE:      case OP_RECURSE:
1258        stack_restore = TRUE;
1259      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1260        {        {
1261        length += 2;        length += 2;
# Line 1100  while (cc < ccend) Line 1266  while (cc < ccend)
1266        length += 2;        length += 2;
1267        setmark_found = TRUE;        setmark_found = TRUE;
1268        }        }
1269        if (common->capture_last_ptr != 0 && !capture_last_found)
1270          {
1271          length += 2;
1272          capture_last_found = TRUE;
1273          }
1274      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1275      break;      break;
1276    
# Line 1107  while (cc < ccend) Line 1278  while (cc < ccend)
1278      case OP_CBRAPOS:      case OP_CBRAPOS:
1279      case OP_SCBRA:      case OP_SCBRA:
1280      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1281        stack_restore = TRUE;
1282        if (common->capture_last_ptr != 0 && !capture_last_found)
1283          {
1284          length += 2;
1285          capture_last_found = TRUE;
1286          }
1287      length += 3;      length += 3;
1288      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1289      break;      break;
1290    
1291      default:      default:
1292        stack_restore = TRUE;
1293        /* Fall through. */
1294    
1295        case OP_NOT_WORD_BOUNDARY:
1296        case OP_WORD_BOUNDARY:
1297        case OP_NOT_DIGIT:
1298        case OP_DIGIT:
1299        case OP_NOT_WHITESPACE:
1300        case OP_WHITESPACE:
1301        case OP_NOT_WORDCHAR:
1302        case OP_WORDCHAR:
1303        case OP_ANY:
1304        case OP_ALLANY:
1305        case OP_ANYBYTE:
1306        case OP_NOTPROP:
1307        case OP_PROP:
1308        case OP_ANYNL:
1309        case OP_NOT_HSPACE:
1310        case OP_HSPACE:
1311        case OP_NOT_VSPACE:
1312        case OP_VSPACE:
1313        case OP_EXTUNI:
1314        case OP_EODN:
1315        case OP_EOD:
1316        case OP_CIRC:
1317        case OP_CIRCM:
1318        case OP_DOLL:
1319        case OP_DOLLM:
1320        case OP_CHAR:
1321        case OP_CHARI:
1322        case OP_NOT:
1323        case OP_NOTI:
1324    
1325        case OP_EXACT:
1326        case OP_POSSTAR:
1327        case OP_POSPLUS:
1328        case OP_POSQUERY:
1329        case OP_POSUPTO:
1330    
1331        case OP_EXACTI:
1332        case OP_POSSTARI:
1333        case OP_POSPLUSI:
1334        case OP_POSQUERYI:
1335        case OP_POSUPTOI:
1336    
1337        case OP_NOTEXACT:
1338        case OP_NOTPOSSTAR:
1339        case OP_NOTPOSPLUS:
1340        case OP_NOTPOSQUERY:
1341        case OP_NOTPOSUPTO:
1342    
1343        case OP_NOTEXACTI:
1344        case OP_NOTPOSSTARI:
1345        case OP_NOTPOSPLUSI:
1346        case OP_NOTPOSQUERYI:
1347        case OP_NOTPOSUPTOI:
1348    
1349        case OP_TYPEEXACT:
1350        case OP_TYPEPOSSTAR:
1351        case OP_TYPEPOSPLUS:
1352        case OP_TYPEPOSQUERY:
1353        case OP_TYPEPOSUPTO:
1354    
1355        case OP_CLASS:
1356        case OP_NCLASS:
1357        case OP_XCLASS:
1358    
1359      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1360      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1361      break;      break;
1362      }      }
1363    
1364  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1365  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1366    return -1;    return stack_restore ? no_frame : no_stack;
1367    
1368  if (length > 0)  if (length > 0)
1369    return length + 1;    return length + 1;
1370  return -1;  return stack_restore ? no_frame : no_stack;
1371  }  }
1372    
1373  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)
1374  {  {
1375  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1376  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1377  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1378    /* The last capture is a local variable even for recursions. */
1379    BOOL capture_last_found = FALSE;
1380  int offset;  int offset;
1381    
1382  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1139  SLJIT_UNUSED_ARG(stacktop); Line 1384  SLJIT_UNUSED_ARG(stacktop);
1384  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1385    
1386  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1387  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1388    cc = next_opcode(common, cc);    {
1389      ccend = bracketend(cc) - (1 + LINK_SIZE);
1390      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1391        cc = next_opcode(common, cc);
1392      }
1393    
1394  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1395  while (cc < ccend)  while (cc < ccend)
1396    switch(*cc)    switch(*cc)
# Line 1150  while (cc < ccend) Line 1400  while (cc < ccend)
1400      if (!setsom_found)      if (!setsom_found)
1401        {        {
1402        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1403        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
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        setsom_found = TRUE;        setsom_found = TRUE;
1408        }        }
1409      cc += 1;      cc += 1;
1410      break;      break;
1411    
1412      case OP_MARK:      case OP_MARK:
1413        case OP_PRUNE_ARG:
1414        case OP_THEN_ARG:
1415      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1416      if (!setmark_found)      if (!setmark_found)
1417        {        {
1418        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);
1419        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);
1420        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1421        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1422        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1423        setmark_found = TRUE;        setmark_found = TRUE;
1424        }        }
1425      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 1177  while (cc < ccend) Line 1429  while (cc < ccend)
1429      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1430        {        {
1431        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1432        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1433        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1434        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1435        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1436        setsom_found = TRUE;        setsom_found = TRUE;
1437        }        }
1438      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1439        {        {
1440        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);
1441        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);
1442        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1443        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1444        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1445        setmark_found = TRUE;        setmark_found = TRUE;
1446        }        }
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      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1457      break;      break;
1458    
# Line 1199  while (cc < ccend) Line 1460  while (cc < ccend)
1460      case OP_CBRAPOS:      case OP_CBRAPOS:
1461      case OP_SCBRA:      case OP_SCBRA:
1462      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1463        if (common->capture_last_ptr != 0 && !capture_last_found)
1464          {
1465          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1466          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1467          stackpos += (int)sizeof(sljit_sw);
1468          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1469          stackpos += (int)sizeof(sljit_sw);
1470          capture_last_found = TRUE;
1471          }
1472      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1473      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1474      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1475      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1476      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));
1477      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1478      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1479      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1480      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1481    
1482      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1483      break;      break;
# Line 1218  while (cc < ccend) Line 1488  while (cc < ccend)
1488      break;      break;
1489      }      }
1490    
1491  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1492  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1493  }  }
1494    
1495  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)
1496  {  {
1497  int localsize = 2;  int private_data_length = needs_control_head ? 3 : 2;
1498  int size;  int size;
1499  pcre_uchar *alternative;  pcre_uchar *alternative;
1500  /* Calculate the sum of the local variables. */  /* Calculate the sum of the private machine words. */
1501  while (cc < ccend)  while (cc < ccend)
1502    {    {
1503    size = 0;    size = 0;
1504    switch(*cc)    switch(*cc)
1505      {      {
1506        case OP_KET:
1507        if (PRIVATE_DATA(cc) != 0)
1508          private_data_length++;
1509        cc += 1 + LINK_SIZE;
1510        break;
1511    
1512      case OP_ASSERT:      case OP_ASSERT:
1513      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1514      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1243  while (cc < ccend) Line 1519  while (cc < ccend)
1519      case OP_SBRA:      case OP_SBRA:
1520      case OP_SBRAPOS:      case OP_SBRAPOS:
1521      case OP_SCOND:      case OP_SCOND:
1522      localsize++;      private_data_length++;
1523      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1524      break;      break;
1525    
1526      case OP_CBRA:      case OP_CBRA:
1527      case OP_SCBRA:      case OP_SCBRA:
1528      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1529          private_data_length++;
1530      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1531      break;      break;
1532    
1533      case OP_CBRAPOS:      case OP_CBRAPOS:
1534      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1535      localsize += 2;      private_data_length += 2;
1536      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1537      break;      break;
1538    
# Line 1263  while (cc < ccend) Line 1540  while (cc < ccend)
1540      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1541      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1542      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1543        localsize++;        private_data_length++;
1544      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1545      break;      break;
1546    
1547      CASE_ITERATOR_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
1548      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1549        localsize++;        private_data_length++;
1550      cc += 2;      cc += 2;
1551  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1552      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1553  #endif  #endif
1554      break;      break;
1555    
1556      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
1557      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1558        localsize += 2;        private_data_length += 2;
1559      cc += 2;      cc += 2;
1560  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1561      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1562  #endif  #endif
1563      break;      break;
1564    
1565      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
1566      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1567        localsize += 2;        private_data_length += 2;
1568      cc += 2 + IMM2_SIZE;      cc += 2 + IMM2_SIZE;
1569  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1570      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1571  #endif  #endif
1572      break;      break;
1573    
1574      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1575      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1576        localsize++;        private_data_length++;
1577      cc += 1;      cc += 1;
1578      break;      break;
1579    
1580      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1581      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1582        localsize += 2;        private_data_length += 2;
1583      cc += 1;      cc += 1;
1584      break;      break;
1585    
1586      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1587      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1588        localsize += 2;        private_data_length += 2;
1589      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
1590      break;      break;
1591    
# Line 1320  while (cc < ccend) Line 1597  while (cc < ccend)
1597  #else  #else
1598      size = 1 + 32 / (int)sizeof(pcre_uchar);      size = 1 + 32 / (int)sizeof(pcre_uchar);
1599  #endif  #endif
1600      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1601        localsize += get_class_iterator_size(cc + size);        private_data_length += get_class_iterator_size(cc + size);
1602      cc += size;      cc += size;
1603      break;      break;
1604    
# Line 1332  while (cc < ccend) Line 1609  while (cc < ccend)
1609      }      }
1610    }    }
1611  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1612  return localsize;  return private_data_length;
1613  }  }
1614    
1615  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,
1616    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1617  {  {
1618  DEFINE_COMPILER;  DEFINE_COMPILER;
1619  int srcw[2];  int srcw[2];
# Line 1357  stacktop = STACK(stacktop - 1); Line 1634  stacktop = STACK(stacktop - 1);
1634    
1635  if (!save)  if (!save)
1636    {    {
1637    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1638    if (stackptr < stacktop)    if (stackptr < stacktop)
1639      {      {
1640      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1641      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1642      tmp1empty = FALSE;      tmp1empty = FALSE;
1643      }      }
1644    if (stackptr < stacktop)    if (stackptr < stacktop)
1645      {      {
1646      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1647      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1648      tmp2empty = FALSE;      tmp2empty = FALSE;
1649      }      }
1650    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1651    }    }
1652    
1653  while (status != end)  do
1654    {    {
1655    count = 0;    count = 0;
1656    switch(status)    switch(status)
1657      {      {
1658      case start:      case start:
1659      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1660      count = 1;      count = 1;
1661      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1662        if (needs_control_head)
1663          {
1664          SLJIT_ASSERT(common->control_head_ptr != 0);
1665          count = 2;
1666          srcw[1] = common->control_head_ptr;
1667          }
1668      status = loop;      status = loop;
1669      break;      break;
1670    
# Line 1394  while (status != end) Line 1677  while (status != end)
1677    
1678      switch(*cc)      switch(*cc)
1679        {        {
1680          case OP_KET:
1681          if (PRIVATE_DATA(cc) != 0)
1682            {
1683            count = 1;
1684            srcw[0] = PRIVATE_DATA(cc);
1685            }
1686          cc += 1 + LINK_SIZE;
1687          break;
1688    
1689        case OP_ASSERT:        case OP_ASSERT:
1690        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1691        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1405  while (status != end) Line 1697  while (status != end)
1697        case OP_SBRAPOS:        case OP_SBRAPOS:
1698        case OP_SCOND:        case OP_SCOND:
1699        count = 1;        count = 1;
1700        srcw[0] = PRIV_DATA(cc);        srcw[0] = PRIVATE_DATA(cc);
1701        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1702        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1703        break;        break;
1704    
1705        case OP_CBRA:        case OP_CBRA:
1706        case OP_SCBRA:        case OP_SCBRA:
1707        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1708        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1709            count = 1;
1710            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1711            }
1712        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1713        break;        break;
1714    
1715        case OP_CBRAPOS:        case OP_CBRAPOS:
1716        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1717        count = 2;        count = 2;
1718        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[0] = PRIVATE_DATA(cc);
1719        srcw[1] = PRIV_DATA(cc);        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1720        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
1721        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1722        break;        break;
1723    
# Line 1432  while (status != end) Line 1727  while (status != end)
1727        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1728          {          {
1729          count = 1;          count = 1;
1730          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1731          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1732          }          }
1733        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1734        break;        break;
1735    
1736        CASE_ITERATOR_LOCAL1        CASE_ITERATOR_PRIVATE_DATA_1
1737        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1738          {          {
1739          count = 1;          count = 1;
1740          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1741          }          }
1742        cc += 2;        cc += 2;
1743  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1450  while (status != end) Line 1745  while (status != end)
1745  #endif  #endif
1746        break;        break;
1747    
1748        CASE_ITERATOR_LOCAL2A        CASE_ITERATOR_PRIVATE_DATA_2A
1749        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1750          {          {
1751          count = 2;          count = 2;
1752          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1753          srcw[1] = PRIV_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1754          }          }
1755        cc += 2;        cc += 2;
1756  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1463  while (status != end) Line 1758  while (status != end)
1758  #endif  #endif
1759        break;        break;
1760    
1761        CASE_ITERATOR_LOCAL2B        CASE_ITERATOR_PRIVATE_DATA_2B
1762        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1763          {          {
1764          count = 2;          count = 2;
1765          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1766          srcw[1] = PRIV_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1767          }          }
1768        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1769  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1476  while (status != end) Line 1771  while (status != end)
1771  #endif  #endif
1772        break;        break;
1773    
1774        CASE_ITERATOR_TYPE_LOCAL1        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1775        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1776          {          {
1777          count = 1;          count = 1;
1778          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1779          }          }
1780        cc += 1;        cc += 1;
1781        break;        break;
1782    
1783        CASE_ITERATOR_TYPE_LOCAL2A        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1784        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1785          {          {
1786          count = 2;          count = 2;
1787          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1788          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1789          }          }
1790        cc += 1;        cc += 1;
1791        break;        break;
1792    
1793        CASE_ITERATOR_TYPE_LOCAL2B        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1794        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1795          {          {
1796          count = 2;          count = 2;
1797          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1798          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1799          }          }
1800        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1801        break;        break;
# Line 1513  while (status != end) Line 1808  while (status != end)
1808  #else  #else
1809        size = 1 + 32 / (int)sizeof(pcre_uchar);        size = 1 + 32 / (int)sizeof(pcre_uchar);
1810  #endif  #endif
1811        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1812          switch(get_class_iterator_size(cc + size))          switch(get_class_iterator_size(cc + size))
1813            {            {
1814            case 1:            case 1:
1815            count = 1;            count = 1;
1816            srcw[0] = PRIV_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1817            break;            break;
1818    
1819            case 2:            case 2:
1820            count = 2;            count = 2;
1821            srcw[0] = PRIV_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1822            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1823            break;            break;
1824    
1825            default:            default:
# Line 1556  while (status != end) Line 1851  while (status != end)
1851          if (!tmp1empty)          if (!tmp1empty)
1852            {            {
1853            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1854            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1855            }            }
1856          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1857          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1567  while (status != end) Line 1862  while (status != end)
1862          if (!tmp2empty)          if (!tmp2empty)
1863            {            {
1864            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1865            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1866            }            }
1867          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1868          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1584  while (status != end) Line 1879  while (status != end)
1879          if (!tmp1empty)          if (!tmp1empty)
1880            {            {
1881            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1882            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1883            }            }
1884          tmp1next = FALSE;          tmp1next = FALSE;
1885          }          }
# Line 1596  while (status != end) Line 1891  while (status != end)
1891          if (!tmp2empty)          if (!tmp2empty)
1892            {            {
1893            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1894            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1895            }            }
1896          tmp1next = TRUE;          tmp1next = TRUE;
1897          }          }
1898        }        }
1899      }      }
1900    }    }
1901    while (status != end);
1902    
1903  if (save)  if (save)
1904    {    {
# Line 1611  if (save) Line 1907  if (save)
1907      if (!tmp1empty)      if (!tmp1empty)
1908        {        {
1909        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1910        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1911        }        }
1912      if (!tmp2empty)      if (!tmp2empty)
1913        {        {
1914        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1915        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1916        }        }
1917      }      }
1918    else    else
# Line 1624  if (save) Line 1920  if (save)
1920      if (!tmp2empty)      if (!tmp2empty)
1921        {        {
1922        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1923        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1924        }        }
1925      if (!tmp1empty)      if (!tmp1empty)
1926        {        {
1927        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1928        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1929        }        }
1930      }      }
1931    }    }
1932  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1933  }  }
1934    
1935  #undef CASE_ITERATOR_LOCAL1  static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1936  #undef CASE_ITERATOR_LOCAL2A  {
1937  #undef CASE_ITERATOR_LOCAL2B  pcre_uchar *end = bracketend(cc);
1938  #undef CASE_ITERATOR_TYPE_LOCAL1  BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
 #undef CASE_ITERATOR_TYPE_LOCAL2A  
 #undef CASE_ITERATOR_TYPE_LOCAL2B  
1939    
1940  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  /* Assert captures then. */
1941    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1942      current_offset = NULL;
1943    /* Conditional block does not. */
1944    if (*cc == OP_COND || *cc == OP_SCOND)
1945      has_alternatives = FALSE;
1946    
1947    cc = next_opcode(common, cc);
1948    if (has_alternatives)
1949      current_offset = common->then_offsets + (cc - common->start);
1950    
1951    while (cc < end)
1952      {
1953      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1954        cc = set_then_offsets(common, cc, current_offset);
1955      else
1956        {
1957        if (*cc == OP_ALT && has_alternatives)
1958          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1959        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1960          *current_offset = 1;
1961        cc = next_opcode(common, cc);
1962        }
1963      }
1964    
1965    return end;
1966    }
1967    
1968    #undef CASE_ITERATOR_PRIVATE_DATA_1
1969    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1970    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1971    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1972    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1973    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1974    
1975    static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1976  {  {
1977  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1978  }  }
# Line 1653  static SLJIT_INLINE void set_jumps(jump_ Line 1982  static SLJIT_INLINE void set_jumps(jump_
1982  while (list)  while (list)
1983    {    {
1984    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1985    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1986    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1987    list = list->next;    list = list->next;
1988    }    }
1989  }  }
# Line 1670  if (list_item) Line 1999  if (list_item)
1999    }    }
2000  }  }
2001    
2002  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)
2003  {  {
2004  DEFINE_COMPILER;  DEFINE_COMPILER;
2005  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
2006    
2007  if (list_item)  if (list_item)
2008    {    {
   list_item->type = type;  
   list_item->data = data;  
2009    list_item->start = start;    list_item->start = start;
2010    list_item->quit = LABEL();    list_item->quit = LABEL();
2011    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1694  stub_list* list_item = common->stubs; Line 2021  stub_list* list_item = common->stubs;
2021  while (list_item)  while (list_item)
2022    {    {
2023    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2024    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
     {  
     case stack_alloc:  
     add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));  
     break;  
     }  
2025    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2026    list_item = list_item->next;    list_item = list_item->next;
2027    }    }
2028  common->stubs = NULL;  common->stubs = NULL;
2029  }  }
2030    
2031  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2032  {  {
2033  DEFINE_COMPILER;  DEFINE_COMPILER;
2034    
2035  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);
2036  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2037  }  }
2038    
# Line 1719  static SLJIT_INLINE void allocate_stack( Line 2041  static SLJIT_INLINE void allocate_stack(
2041  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2042  DEFINE_COMPILER;  DEFINE_COMPILER;
2043    
2044  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));
2045  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2046  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2047  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1727  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 2049  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2049  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2050  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2051  #endif  #endif
2052  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));
2053  }  }
2054    
2055  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2056  {  {
2057  DEFINE_COMPILER;  DEFINE_COMPILER;
2058  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));
2059  }  }
2060    
2061  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1741  static SLJIT_INLINE void reset_ovector(c Line 2063  static SLJIT_INLINE void reset_ovector(c
2063  DEFINE_COMPILER;  DEFINE_COMPILER;
2064  struct sljit_label *loop;  struct sljit_label *loop;
2065  int i;  int i;
2066    
2067  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2068    SLJIT_ASSERT(length > 1);
2069  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2070  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));
2071    if (length < 8)
2072      {
2073      for (i = 1; i < length; i++)
2074        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2075      }
2076    else
2077      {
2078      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2079      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2080      loop = LABEL();
2081      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2082      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2083      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2084      }
2085    }
2086    
2087    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2088    {
2089    DEFINE_COMPILER;
2090    struct sljit_label *loop;
2091    int i;
2092    
2093    SLJIT_ASSERT(length > 1);
2094    /* OVECTOR(1) contains the "string begin - 1" constant. */
2095    if (length > 2)
2096      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2097  if (length < 8)  if (length < 8)
2098    {    {
2099    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
2100      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);
2101    }    }
2102  else  else
2103    {    {
2104    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2105    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2106    loop = LABEL();    loop = LABEL();
2107    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);
2108    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);
2109    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2110    }    }
2111    
2112    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2113    if (common->mark_ptr != 0)
2114      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2115    if (common->control_head_ptr != 0)
2116      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2117    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2118    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2119    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2120    }
2121    
2122    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2123    {
2124    while (current != NULL)
2125      {
2126      switch (current[-2])
2127        {
2128        case type_then_trap:
2129        break;
2130    
2131        case type_mark:
2132        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2133          return current[-4];
2134        break;
2135    
2136        default:
2137        SLJIT_ASSERT_STOP();
2138        break;
2139        }
2140      current = (sljit_sw*)current[-1];
2141      }
2142    return -1;
2143  }  }
2144    
2145  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2146  {  {
2147  DEFINE_COMPILER;  DEFINE_COMPILER;
2148  struct sljit_label *loop;  struct sljit_label *loop;
2149  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2150    
2151  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2152  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));
2153  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);
2154    
2155  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2156  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2157    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);
2158  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));
2159  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2160    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);
2161  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));
2162  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));
2163  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2164  /* Unlikely, but possible */  /* Unlikely, but possible */
2165  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);
2166  loop = LABEL();  loop = LABEL();
2167  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);
2168  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));
2169  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2170  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2171  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);
2172  #endif  #endif
2173  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);
2174  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);
2175  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2176  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2177    
2178  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2179  if (topbracket > 1)  if (topbracket > 1)
2180    {    {
2181    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));
2182    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2183    
2184    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2185    loop = LABEL();    loop = LABEL();
2186    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)));
2187    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);
2188    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);
2189    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2190    }    }
2191  else  else
2192    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1813  else Line 2195  else
2195  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)
2196  {  {
2197  DEFINE_COMPILER;  DEFINE_COMPILER;
2198    struct sljit_jump *jump;
2199    
2200  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);
2201  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
2202      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2203    
2204  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2205  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2206  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));
2207  CMPTO(SLJIT_C_LESS, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2, quit);  CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
2208    
2209  /* Store match begin and end. */  /* Store match begin and end. */
2210  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));
2211  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));
2212  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);  
2213    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2214    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);
2215    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2216    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2217    #endif
2218    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2219    JUMPHERE(jump);
2220    
2221    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);
2222  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);
2223  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2224  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);
2225  #endif  #endif
2226  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);
2227    
2228  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);
2229  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2230  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);
2231  #endif  #endif
2232  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);
2233    
2234  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2235  }  }
# Line 1949  if (c <= 127 && bit == 0x20) Line 2342  if (c <= 127 && bit == 0x20)
2342    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2343    
2344  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2345  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2346    return 0;    return 0;
2347    
2348  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2349    
2350  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2351  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 1968  if (common->utf && c > 127) Line 2361  if (common->utf && c > 127)
2361  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2362  return (0 << 8) | bit;  return (0 << 8) | bit;
2363    
2364  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2365    
 #ifdef COMPILE_PCRE16  
2366  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2367  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2368    {    {
# Line 1981  if (common->utf && c > 65535) Line 2373  if (common->utf && c > 65535)
2373    }    }
2374  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2375  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2376    
2377  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2378  }  }
2379    
2380  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2381  {  {
2382  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2383  DEFINE_COMPILER;  DEFINE_COMPILER;
2384  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2385    
# Line 2003  else if (common->mode == JIT_PARTIAL_SOF Line 2394  else if (common->mode == JIT_PARTIAL_SOF
2394    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);
2395    
2396  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2397    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);
2398  else  else
2399    {    {
2400    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2016  if (jump != NULL) Line 2407  if (jump != NULL)
2407    JUMPHERE(jump);    JUMPHERE(jump);
2408  }  }
2409    
2410  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2411  {  {
2412  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2413  DEFINE_COMPILER;  DEFINE_COMPILER;
2414  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2415    
2416  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2417    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2418      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2419      return;
2420      }
2421    
2422  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2423  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2424    {    {
2425    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));
2426    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);
2427    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2428    }    }
2429  else  else
2430    {    {
2431    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));
2432    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2433      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2434    else    else
2435      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2436    }    }
2437  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2438  }  }
2439    
2440  static void detect_partial_match(compiler_common *common, jump_list **backtracks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
# Line 2063  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR Line 2453  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2453  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));
2454  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2455    {    {
2456    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);
2457    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2458    }    }
2459  else  else
# Line 2073  else Line 2463  else
2463    else    else
2464      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2465    }    }
2466  JUMPHERE(jump);  JUMPHERE(jump);
2467    }
2468    
2469    static void peek_char(compiler_common *common, pcre_uint32 max)
2470    {
2471    /* Reads the character into TMP1, keeps STR_PTR.
2472    Does not check STR_END. TMP2 Destroyed. */
2473    DEFINE_COMPILER;
2474    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2475    struct sljit_jump *jump;
2476    #endif
2477    
2478    SLJIT_UNUSED_ARG(max);
2479    
2480    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2481    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2482    if (common->utf)
2483      {
2484      if (max < 128) return;
2485    
2486      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2487      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2488      add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2489      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2490      JUMPHERE(jump);
2491      }
2492    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2493    
2494    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2495    if (common->utf)
2496      {
2497      if (max < 0xd800) return;
2498    
2499      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2500      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2501      /* TMP2 contains the high surrogate. */
2502      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2503      OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2504      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2505      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2506      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2507      JUMPHERE(jump);
2508      }
2509    #endif
2510    }
2511    
2512    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2513    
2514    static BOOL is_char7_bitset(const pcre_uint8* bitset, BOOL nclass)
2515    {
2516    /* Tells whether the character codes below 128 are enough
2517    to determine a match. */
2518    const pcre_uint8 value = nclass ? 0xff : 0;
2519    const pcre_uint8* end = bitset + 32;
2520    
2521    bitset += 16;
2522    do
2523      {
2524      if (*bitset++ != value)
2525        return FALSE;
2526      }
2527    while (bitset < end);
2528    return TRUE;
2529    }
2530    
2531    static void read_char7_type(compiler_common *common, BOOL full_read)
2532    {
2533    /* Reads the precise character type of a character into TMP1, if the character
2534    is less than 128. Otherwise it returns with zero. Does not check STR_END. The
2535    full_read argument tells whether characters above max are accepted or not. */
2536    DEFINE_COMPILER;
2537    struct sljit_jump *jump;
2538    
2539    SLJIT_ASSERT(common->utf);
2540    
2541    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2542    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2543    
2544    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2545    
2546    if (full_read)
2547      {
2548      jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2549      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2550      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2551      JUMPHERE(jump);
2552      }
2553  }  }
2554    
2555  static void read_char(compiler_common *common)  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2556    
2557    static void read_char_range(compiler_common *common, pcre_uint32 min, pcre_uint32 max, BOOL update_str_ptr)
2558  {  {
2559  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the precise value of a character into TMP1, if the character is
2560  Does not check STR_END. TMP2 Destroyed. */  between min and max (c >= min && c <= max). Otherwise it returns with a value
2561    outside the range. Does not check STR_END. */
2562  DEFINE_COMPILER;  DEFINE_COMPILER;
2563  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2564  struct sljit_jump *jump;  struct sljit_jump *jump;
2565  #endif  #endif
2566    
2567    SLJIT_UNUSED_ARG(update_str_ptr);
2568    SLJIT_UNUSED_ARG(min);
2569    SLJIT_UNUSED_ARG(max);
2570    SLJIT_ASSERT(min <= max);
2571    
2572  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2573  #ifdef SUPPORT_UTF  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2574    
2575    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2576  if (common->utf)  if (common->utf)
2577    {    {
2578  #ifdef COMPILE_PCRE8    if (max < 128 && !update_str_ptr) return;
2579    
2580    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2581  #else    if (max >= 0x800)
2582  #ifdef COMPILE_PCRE16      add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2583    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    else if (max < 128)
2584  #endif      {
2585  #endif /* COMPILE_PCRE8 */      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2586    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2587        }
2588      else
2589        {
2590        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2591        if (!update_str_ptr)
2592          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2593        else
2594          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2595        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2596        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2597        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2598        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2599        if (update_str_ptr)
2600          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2601        }
2602    JUMPHERE(jump);    JUMPHERE(jump);
2603    }    }
2604  #endif  #endif
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 }  
   
 static void peek_char(compiler_common *common)  
 {  
 /* Reads the character into TMP1, keeps STR_PTR.  
 Does not check STR_END. TMP2 Destroyed. */  
 DEFINE_COMPILER;  
 #ifdef SUPPORT_UTF  
 struct sljit_jump *jump;  
 #endif  
2605    
2606  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  #if defined SUPPORT_UTF && defined COMPILE_PCRE16
 #ifdef SUPPORT_UTF  
2607  if (common->utf)  if (common->utf)
2608    {    {
2609  #ifdef COMPILE_PCRE8    if (max >= 0x10000)
2610    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);      {
2611  #else      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2612  #ifdef COMPILE_PCRE16      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2613    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      /* TMP2 contains the high surrogate. */
2614  #endif      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2615  #endif /* COMPILE_PCRE8 */      OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2616    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2617    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2618        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2619        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2620        JUMPHERE(jump);
2621        return;
2622        }
2623    
2624      if (max < 0xd800 && !update_str_ptr) return;
2625    
2626      /* Skip low surrogate if necessary. */
2627      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2628      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2629      if (update_str_ptr)
2630        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2631      if (max >= 0xd800)
2632        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);
2633    JUMPHERE(jump);    JUMPHERE(jump);
2634    }    }
2635  #endif  #endif
2636  }  }
2637    
2638  static void read_char8_type(compiler_common *common)  static SLJIT_INLINE void read_char(compiler_common *common)
2639    {
2640    read_char_range(common, 0, READ_CHAR_MAX, TRUE);
2641    }
2642    
2643    static void read_char8_type(compiler_common *common, BOOL update_str_ptr)
2644  {  {
2645  /* 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. */
2646  DEFINE_COMPILER;  DEFINE_COMPILER;
2647  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2648  struct sljit_jump *jump;  struct sljit_jump *jump;
2649  #endif  #endif
2650    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2651    struct sljit_jump *jump2;
2652    #endif
2653    
2654  #ifdef SUPPORT_UTF  SLJIT_UNUSED_ARG(update_str_ptr);
2655    
2656    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2657    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2658    
2659    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2660  if (common->utf)  if (common->utf)
2661    {    {
   OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 #ifdef COMPILE_PCRE8  
2662    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2663    it is needed in most cases. */    it is needed in most cases. */
2664    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2665    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2666    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    if (!update_str_ptr)
2667    JUMPHERE(jump);      {
2668  #else      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2669  #ifdef COMPILE_PCRE16      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2670    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2671    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2672    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2673        OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
2674        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2675        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2676        OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2677        JUMPHERE(jump2);
2678        }
2679      else
2680        add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2681    JUMPHERE(jump);    JUMPHERE(jump);
   /* Skip low surrogate if necessary. */  
   OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);  
   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);  
   COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  
   OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  
 #endif  
 #endif /* COMPILE_PCRE8 */  
2682    return;    return;
2683    }    }
2684  #endif  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2685  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
2686  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  #if !defined COMPILE_PCRE8
 #ifdef COMPILE_PCRE16  
2687  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2688  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2689  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2690  #endif  #endif
2691  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2692  #ifdef COMPILE_PCRE16  #if !defined COMPILE_PCRE8
2693  JUMPHERE(jump);  JUMPHERE(jump);
2694  #endif  #endif
2695    
2696    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2697    if (common->utf && update_str_ptr)
2698      {
2699      /* Skip low surrogate if necessary. */
2700      OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2701      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2702      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2703      JUMPHERE(jump);
2704      }
2705    #endif /* SUPPORT_UTF && COMPILE_PCRE16 */
2706  }  }
2707    
2708  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
2709  {  {
2710  /* 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. */
2711  DEFINE_COMPILER;  DEFINE_COMPILER;
2712  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2713    #if defined COMPILE_PCRE8
2714  struct sljit_label *label;  struct sljit_label *label;
2715    
2716  if (common->utf)  if (common->utf)
# Line 2196  if (common->utf) Line 2722  if (common->utf)
2722    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2723    return;    return;
2724    }    }
2725  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2726  if (common->utf)  if (common->utf)
2727    {    {
2728    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
# Line 2205  if (common->utf) Line 2730  if (common->utf)
2730    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2731    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2732    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);
2733    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2734    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2735    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2736    return;    return;
2737    }    }
2738  #endif  #endif /* COMPILE_PCRE[8|16] */
2739    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2740  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));
2741  }  }
2742    
2743  static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpiftrue)  static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpifmatch)
2744  {  {
2745  /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */  /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */
2746  DEFINE_COMPILER;  DEFINE_COMPILER;
2747    struct sljit_jump *jump;
2748    
2749  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2750    {    {
2751    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2752    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpifmatch ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2753    }    }
2754  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2755    {    {
2756    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    if (jumpifmatch)
2757    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      {
2758    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR));
2759    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2760    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));      }
2761      else
2762        {
2763        jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
2764        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2765        JUMPHERE(jump);
2766        }
2767    }    }
2768  else  else
2769    {    {
2770    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2771    add_jump(compiler, backtracks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));    add_jump(compiler, backtracks, CMP(jumpifmatch ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
2772    }    }
2773  }  }
2774    
2775  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2776    
2777  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2778  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2779  {  {
2780  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2781  of the character (>= 0xc0). Return char value in TMP1, length - 1 in TMP2. */  of the character (>= 0xc0). Return char value in TMP1, length in TMP2. */
2782  DEFINE_COMPILER;  DEFINE_COMPILER;
2783  struct sljit_jump *jump;  struct sljit_jump *jump;
2784    
2785  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2786    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2787    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2788    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2789    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2790    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2791    
2792  /* Searching for the first zero. */  /* Searching for the first zero. */
2793  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2794  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2795  /* Two byte sequence. */  /* Two byte sequence. */
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
2796  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));
2797  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2798    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2799    
2800    JUMPHERE(jump);
2801    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2802    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2803  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2804  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2805  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 JUMPHERE(jump);  
2806    
2807  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2808  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2809  /* Three byte sequence. */  /* Three byte sequence. */
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  
2810  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2811  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));  
2812  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2813    
2814  /* Four byte sequence. */  /* Four byte sequence. */
2815  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  JUMPHERE(jump);
2816  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2817  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2818    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2819    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2820  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  
2821  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2822  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(4));
2823    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2824    }
2825    
2826    static void do_utfreadchar16(compiler_common *common)
2827    {
2828    /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2829    of the character (>= 0xc0). Return value in TMP1. */
2830    DEFINE_COMPILER;
2831    struct sljit_jump *jump;
2832    
2833    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2834    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2835    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2836    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2837  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
2838  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2839  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));  
2840  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));  /* Searching for the first zero. */
2841    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2842    jump = JUMP(SLJIT_C_NOT_ZERO);
2843    /* Two byte sequence. */
2844    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2845    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2846    
2847    JUMPHERE(jump);
2848    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x400);
2849    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
2850    /* This code runs only in 8 bit mode. No need to shift the value. */
2851    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2852    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2853    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2854    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2855  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2856  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2857  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));  /* Three byte sequence. */
2858    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2859  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2860  }  }
2861    
# Line 2316  jump = JUMP(SLJIT_C_NOT_ZERO); Line 2875  jump = JUMP(SLJIT_C_NOT_ZERO);
2875  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2876  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));
2877  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
2878    /* The upper 5 bits are known at this point. */
2879    compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x3);
2880  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2881  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2882  OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);  OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
 compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  
2883  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2884  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2885    
2886  JUMPHERE(compare);  JUMPHERE(compare);
2887  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2888  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2889    
2890  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(utf8_table4) - 0xc0);  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
 OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 }  
   
 #else /* COMPILE_PCRE8 */  
   
 #ifdef COMPILE_PCRE16  
 static void do_utfreadchar(compiler_common *common)  
 {  
 /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char  
 of the character (>= 0xd800). Return char value in TMP1, length - 1 in TMP2. */  
 DEFINE_COMPILER;  
 struct sljit_jump *jump;  
   
 sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  
 jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);  
 /* Do nothing, only return. */  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
   
2891  JUMPHERE(jump);  JUMPHERE(jump);
2892  /* Combine two 16 bit characters. */  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2893  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2894  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3ff);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  
2895  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2896  }  }
 #endif /* COMPILE_PCRE16 */  
2897    
2898  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
2899    
# Line 2384  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 2915  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2915    
2916  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2917  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2918  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));
2919  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2920  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2921  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2922  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2923  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2924  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));
2925  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2926  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2927  }  }
# Line 2404  struct sljit_label *newlinelabel = NULL; Line 2935  struct sljit_label *newlinelabel = NULL;
2935  struct sljit_jump *start;  struct sljit_jump *start;
2936  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2937  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2938  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2939  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2940  #endif  #endif
2941  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 2420  if (firstline) Line 2951  if (firstline)
2951    /* Search for the end of the first line. */    /* Search for the end of the first line. */
2952    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
2953    OP1(SLJIT_MOV, TMP3, 0, 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);  
2954    
2955    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
2956      {      {
# Line 2431  if (firstline) Line 2961  if (firstline)
2961      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2962      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);
2963      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);
2964        JUMPHERE(end);
2965      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));
2966      }      }
2967    else    else
# Line 2439  if (firstline) Line 2970  if (firstline)
2970      mainloop = LABEL();      mainloop = LABEL();
2971      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
2972      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);
2973      read_char(common);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
2974      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
2975      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2976        JUMPHERE(end);
2977      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);
2978      set_jumps(newline, LABEL());      set_jumps(newline, LABEL());
2979      }      }
2980    
   JUMPHERE(end);  
2981    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
2982    }    }
2983    
# Line 2459  if (newlinecheck) Line 2990  if (newlinecheck)
2990    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2991    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2992    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);
2993    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2994  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2995    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2996  #endif  #endif
2997    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2998    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 2482  if (newlinecheck) Line 3013  if (newlinecheck)
3013    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);
3014    
3015  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));
3016  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3017    #if defined COMPILE_PCRE8
3018  if (common->utf)  if (common->utf)
3019    {    {
3020    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
3021    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);
3022    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3023    JUMPHERE(singlechar);    JUMPHERE(singlechar);
3024    }    }
3025  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3026  if (common->utf)  if (common->utf)
3027    {    {
3028    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
3029    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3030    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);
3031    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3032    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3033    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3034    JUMPHERE(singlechar);    JUMPHERE(singlechar);
3035    }    }
3036  #endif  #endif /* COMPILE_PCRE[8|16] */
3037    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
3038  JUMPHERE(start);  JUMPHERE(start);
3039    
3040  if (newlinecheck)  if (newlinecheck)
# Line 2514  if (newlinecheck) Line 3046  if (newlinecheck)
3046  return mainloop;  return mainloop;
3047  }  }
3048    
3049  static SLJIT_INLINE BOOL fast_forward_first_two_chars(compiler_common *common, BOOL firstline)  static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, int max_chars)
3050  {  {
3051  DEFINE_COMPILER;  /* Recursive function, which scans prefix literals. */
3052  struct sljit_label *start;  int len, repeat, len_save, consumed = 0;
3053  struct sljit_jump *quit;  pcre_uint32 caseless, chr, mask;
3054  struct sljit_jump *found;  pcre_uchar *alternative, *cc_save;
3055  pcre_int32 chars[4];  BOOL last, any;
 pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  
 int location = 0;  
 pcre_int32 len, c, bit, caseless;  
 BOOL must_end;  
   
 #ifdef COMPILE_PCRE8  
 union {  
     sljit_uh ascombined;  
     sljit_ub asuchars[2];  
 } pair;  
 #else  
 union {  
     sljit_ui ascombined;  
     sljit_uh asuchars[2];  
 } pair;  
 #endif  
   
 if (*(common->start + GET(common->start, 1)) == OP_ALT)  
   return FALSE;  
3056    
3057    repeat = 1;
3058  while (TRUE)  while (TRUE)
3059    {    {
3060      last = TRUE;
3061      any = FALSE;
3062    caseless = 0;    caseless = 0;
3063    must_end = TRUE;    switch (*cc)
   switch(*cc)  
3064      {      {
     case OP_CHAR:  
     must_end = FALSE;  
     cc++;  
     break;  
   
3065      case OP_CHARI:      case OP_CHARI:
3066      caseless = 1;      caseless = 1;
3067      must_end = FALSE;      case OP_CHAR:
3068        last = FALSE;
3069      cc++;      cc++;
3070      break;      break;
3071    
# Line 2579  while (TRUE) Line 3090  while (TRUE)
3090      cc++;      cc++;
3091      break;      break;
3092    
3093      case OP_EXACT:      case OP_EXACTI:
3094      cc += 1 + IMM2_SIZE;      caseless = 1;
3095      break;      case OP_EXACT:
3096        repeat = GET2(cc, 1);
3097      case OP_PLUSI:      last = FALSE;
3098      case OP_MINPLUSI:      cc += 1 + IMM2_SIZE;
3099      case OP_POSPLUSI:      break;
3100      caseless = 1;  
3101      cc++;      case OP_PLUSI:
3102        case OP_MINPLUSI:
3103        case OP_POSPLUSI:
3104        caseless = 1;
3105        cc++;
3106        break;
3107    
3108        case OP_KET:
3109        cc += 1 + LINK_SIZE;
3110        continue;
3111    
3112        case OP_ALT:
3113        cc += GET(cc, 1);
3114        continue;
3115    
3116        case OP_ONCE:
3117        case OP_ONCE_NC:
3118        case OP_BRA:
3119        case OP_BRAPOS:
3120        case OP_CBRA:
3121        case OP_CBRAPOS:
3122        alternative = cc + GET(cc, 1);
3123        while (*alternative == OP_ALT)
3124          {
3125          max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, max_chars);
3126          if (max_chars == 0)
3127            return consumed;
3128          alternative += GET(alternative, 1);
3129          }
3130    
3131        if (*cc == OP_CBRA || *cc == OP_CBRAPOS)
3132          cc += IMM2_SIZE;
3133        cc += 1 + LINK_SIZE;
3134        continue;
3135    
3136        case OP_CLASS:
3137        case OP_NCLASS:
3138        any = TRUE;
3139        cc += 1 + 32 / sizeof(pcre_uchar);
3140        break;
3141    
3142    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3143        case OP_XCLASS:
3144        any = TRUE;
3145        cc += GET(cc, 1);
3146        break;
3147    #endif
3148    
3149        case OP_NOT_DIGIT:
3150        case OP_DIGIT:
3151        case OP_NOT_WHITESPACE:
3152        case OP_WHITESPACE:
3153        case OP_NOT_WORDCHAR:
3154        case OP_WORDCHAR:
3155        case OP_ANY:
3156        case OP_ALLANY:
3157        any = TRUE;
3158        cc++;
3159        break;
3160    
3161    #ifdef SUPPORT_UCP
3162        case OP_NOTPROP:
3163        case OP_PROP:
3164        any = TRUE;
3165        cc += 1 + 2;
3166      break;      break;
3167    #endif
3168    
3169      case OP_EXACTI:      case OP_TYPEEXACT:
3170      caseless = 1;      repeat = GET2(cc, 1);
3171      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
3172      break;      continue;
3173    
3174      default:      default:
3175      return FALSE;      return consumed;
3176        }
3177    
3178      if (any)
3179        {
3180    #ifdef SUPPORT_UTF
3181        if (common->utf) return consumed;
3182    #endif
3183    #if defined COMPILE_PCRE8
3184        mask = 0xff;
3185    #elif defined COMPILE_PCRE16
3186        mask = 0xffff;
3187    #elif defined COMPILE_PCRE32
3188        mask = 0xffffffff;
3189    #else
3190        SLJIT_ASSERT_STOP();
3191    #endif
3192    
3193        do
3194          {
3195          chars[0] = mask;
3196          chars[1] = mask;
3197    
3198          if (--max_chars == 0)
3199            return consumed;
3200          consumed++;
3201          chars += 2;
3202          }
3203        while (--repeat > 0);
3204    
3205        repeat = 1;
3206        continue;
3207      }      }
3208    
3209    len = 1;    len = 1;
3210  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3211    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3212  #endif  #endif
3213    
3214    if (caseless && char_has_othercase(common, cc))    if (caseless != 0 && char_has_othercase(common, cc))
3215      {      {
3216      caseless = char_get_othercase_bit(common, cc);      caseless = char_get_othercase_bit(common, cc);
3217      if (caseless == 0)      if (caseless == 0)
3218        return FALSE;        return consumed;
3219  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3220      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
3221  #else  #else
# Line 2621  while (TRUE) Line 3228  while (TRUE)
3228    else    else
3229      caseless = 0;      caseless = 0;
3230    
3231    while (len > 0 && location < 2 * 2)    len_save = len;
3232      {    cc_save = cc;
3233      c = *cc;    while (TRUE)
3234      bit = 0;      {
3235      if (len == (caseless & 0xff))      do
3236        {        {
3237        bit = caseless >> 8;        chr = *cc;
3238        c |= bit;  #ifdef COMPILE_PCRE32
3239          if (SLJIT_UNLIKELY(chr == NOTACHAR))
3240            return consumed;
3241    #endif
3242          mask = 0;
3243          if ((pcre_uint32)len == (caseless & 0xff))
3244            {
3245            mask = caseless >> 8;
3246            chr |= mask;
3247            }
3248    
3249          if (chars[0] == NOTACHAR)
3250            {
3251            chars[0] = chr;
3252            chars[1] = mask;
3253            }
3254          else
3255            {
3256            mask |= chars[0] ^ chr;
3257            chr |= mask;
3258            chars[0] = chr;
3259            chars[1] |= mask;
3260            }
3261    
3262          len--;
3263          if (--max_chars == 0)
3264            return consumed;
3265          consumed++;
3266          chars += 2;
3267          cc++;
3268        }        }
3269        while (len > 0);
3270    
3271      chars[location] = c;      if (--repeat == 0)
3272      chars[location + 1] = bit;        break;
3273    
3274      len--;      len = len_save;
3275      location += 2;      cc = cc_save;
3276      cc++;      }
3277    
3278      repeat = 1;
3279      if (last)
3280        return consumed;
3281      }
3282    }
3283    
3284    #define MAX_N_CHARS 16
3285    
3286    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3287    {
3288    DEFINE_COMPILER;
3289    struct sljit_label *start;
3290    struct sljit_jump *quit;
3291    pcre_uint32 chars[MAX_N_CHARS * 2];
3292    pcre_uint8 ones[MAX_N_CHARS];
3293    pcre_uint32 mask;
3294    int i, max;
3295    int offsets[3];
3296    
3297    for (i = 0; i < MAX_N_CHARS; i++)
3298      {
3299      chars[i << 1] = NOTACHAR;
3300      chars[(i << 1) + 1] = 0;
3301      }
3302    
3303    max = scan_prefix(common, common->start, chars, MAX_N_CHARS);
3304    
3305    if (max <= 1)
3306      return FALSE;
3307    
3308    for (i = 0; i < max; i++)
3309      {
3310      mask = chars[(i << 1) + 1];
3311      ones[i] = ones_in_half_byte[mask & 0xf];
3312      mask >>= 4;
3313      while (mask != 0)
3314        {
3315        ones[i] += ones_in_half_byte[mask & 0xf];
3316        mask >>= 4;
3317      }      }
3318      }
3319    
3320    if (location == 2 * 2)  offsets[0] = -1;
3321    /* Scan forward. */
3322    for (i = 0; i < max; i++)
3323      if (ones[i] <= 2) {
3324        offsets[0] = i;
3325      break;      break;
   else if (must_end)  
     return FALSE;  
3326    }    }
3327    
3328    if (offsets[0] == -1)
3329      return FALSE;
3330    
3331    /* Scan backward. */
3332    offsets[1] = -1;
3333    for (i = max - 1; i > offsets[0]; i--)
3334      if (ones[i] <= 2) {
3335        offsets[1] = i;
3336        break;
3337      }
3338    
3339    offsets[2] = -1;
3340    if (offsets[1] >= 0)
3341      {
3342      /* Scan from middle. */
3343      for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3344        if (ones[i] <= 2)
3345          {
3346          offsets[2] = i;
3347          break;
3348          }
3349    
3350      if (offsets[2] == -1)
3351        {
3352        for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3353          if (ones[i] <= 2)
3354            {
3355            offsets[2] = i;
3356            break;
3357            }
3358        }
3359      }
3360    
3361    SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3362    SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3363    
3364    chars[0] = chars[offsets[0] << 1];
3365    chars[1] = chars[(offsets[0] << 1) + 1];
3366    if (offsets[2] >= 0)
3367      {
3368      chars[2] = chars[offsets[2] << 1];
3369      chars[3] = chars[(offsets[2] << 1) + 1];
3370      }
3371    if (offsets[1] >= 0)
3372      {
3373      chars[4] = chars[offsets[1] << 1];
3374      chars[5] = chars[(offsets[1] << 1) + 1];
3375      }
3376    
3377    max -= 1;
3378  if (firstline)  if (firstline)
3379    {    {
3380    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3381    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3382    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, 1);    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS(max));
3383    }    }
3384  else  else
3385    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3386    
3387  start = LABEL();  start = LABEL();
3388  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  
 #ifdef COMPILE_PCRE8  
 OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #else /* COMPILE_PCRE8 */  
 OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #endif  
3389    
3390  #else /* SLJIT_UNALIGNED */  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
3391    if (offsets[1] >= 0)
3392  #if defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3393  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 #else /* SLJIT_BIG_ENDIAN */  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #endif /* SLJIT_BIG_ENDIAN */  
   
 #ifdef COMPILE_PCRE8  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 8);  
 #else /* COMPILE_PCRE8 */  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 16);  
 #endif  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
3394    
3395  #endif  if (chars[1] != 0)
3396      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3397    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3398    if (offsets[2] >= 0)
3399      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));
3400    
3401  if (chars[1] != 0 || chars[3] != 0)  if (offsets[1] >= 0)
3402    {    {
3403    pair.asuchars[0] = chars[1];    if (chars[5] != 0)
3404    pair.asuchars[1] = chars[3];      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3405    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, pair.ascombined);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
3406    }    }
3407    
3408  pair.asuchars[0] = chars[0];  if (offsets[2] >= 0)
3409  pair.asuchars[1] = chars[2];    {
3410  found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, pair.ascombined);    if (chars[3] != 0)
3411        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3412      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3413      }
3414    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3415    
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 JUMPTO(SLJIT_JUMP, start);  
 JUMPHERE(found);  
3416  JUMPHERE(quit);  JUMPHERE(quit);
3417    
3418  if (firstline)  if (firstline)
3419    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3420  else  else
3421    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3422  return TRUE;  return TRUE;
3423  }  }
3424    
3425    #undef MAX_N_CHARS
3426    
3427  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)
3428  {  {
3429  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2738  if (first_char == oc) Line 3457  if (first_char == oc)
3457  else  else
3458    {    {
3459    bit = first_char ^ oc;    bit = first_char ^ oc;
3460    if (ispowerof2(bit))    if (is_powerof2(bit))
3461      {      {
3462      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3463      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
# Line 2746  else Line 3465  else
3465    else    else
3466      {      {
3467      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);
3468      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3469      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);
3470      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);
3471      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3472      }      }
3473    }    }
# Line 2790  if (common->nltype == NLTYPE_FIXED && co Line 3509  if (common->nltype == NLTYPE_FIXED && co
3509    
3510    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3511    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);
3512    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3513  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3514    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3515  #endif  #endif
3516    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3517    
# Line 2819  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_ Line 3538  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_
3538  skip_char_back(common);  skip_char_back(common);
3539    
3540  loop = LABEL();  loop = LABEL();
3541  read_char(common);  read_char_range(common, common->nlmin, common->nlmax, TRUE);
3542  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3543  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3544    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
# Line 2833  if (common->nltype == NLTYPE_ANY || comm Line 3552  if (common->nltype == NLTYPE_ANY || comm
3552    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3553    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3554    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);
3555    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3556  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3557    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3558  #endif  #endif
3559    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3560    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
# Line 2848  if (firstline) Line 3567  if (firstline)
3567    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3568  }  }
3569    
3570  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks);
3571    
3572    static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, pcre_uint8 *start_bits, BOOL firstline)
3573  {  {
3574  DEFINE_COMPILER;  DEFINE_COMPILER;
3575  struct sljit_label *start;  struct sljit_label *start;
3576  struct sljit_jump *quit;  struct sljit_jump *quit;
3577  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3578    jump_list *matches = NULL;
3579  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3580  struct sljit_jump *jump;  struct sljit_jump *jump;
3581  #endif  #endif
# Line 2861  struct sljit_jump *jump; Line 3583  struct sljit_jump *jump;
3583  if (firstline)  if (firstline)
3584    {    {
3585    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3586    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
3587    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);
3588    }    }
3589    
# Line 2872  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 3594  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3594  if (common->utf)  if (common->utf)
3595    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3596  #endif  #endif
3597    
3598    if (!check_class_ranges(common, start_bits, (start_bits[31] & 0x80) != 0, TRUE, &matches))
3599      {
3600  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3601  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3602  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3603  JUMPHERE(jump);    JUMPHERE(jump);
3604  #endif  #endif
3605  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3606  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3607  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
3608  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3609  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);
3610  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3611      }
3612    
3613  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3614  if (common->utf)  if (common->utf)
3615    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3616  #endif  #endif
3617  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));
3618  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3619    #if defined COMPILE_PCRE8
3620  if (common->utf)  if (common->utf)
3621    {    {
3622    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3623    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);
3624    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3625    }    }
3626  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3627  if (common->utf)  if (common->utf)
3628    {    {
3629    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3630    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3631    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);
3632    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3633    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3634    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3635    }    }
3636  #endif  #endif /* COMPILE_PCRE[8|16] */
3637    #endif /* SUPPORT_UTF */
3638  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3639  JUMPHERE(found);  if (found != NULL)
3640      JUMPHERE(found);
3641    if (matches != NULL)
3642      set_jumps(matches, LABEL());
3643  JUMPHERE(quit);  JUMPHERE(quit);
3644    
3645  if (firstline)  if (firstline)
3646    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0);
3647  }  }
3648    
3649  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 2925  struct sljit_jump *alreadyfound; Line 3655  struct sljit_jump *alreadyfound;
3655  struct sljit_jump *found;  struct sljit_jump *found;
3656  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3657  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3658  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3659    
3660  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3661  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
# Line 2956  if (req_char == oc) Line 3686  if (req_char == oc)
3686  else  else
3687    {    {
3688    bit = req_char ^ oc;    bit = req_char ^ oc;
3689    if (ispowerof2(bit))    if (is_powerof2(bit))
3690      {      {
3691      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3692      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
# Line 2992  GET_LOCAL_BASE(TMP3, 0, 0); Line 3722  GET_LOCAL_BASE(TMP3, 0, 0);
3722  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3723  mainloop = LABEL();  mainloop = LABEL();
3724  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3725  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);
3726    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3727    
3728  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3729  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));
3730  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));
3731  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));
3732  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3733    
3734  JUMPHERE(jump);  JUMPHERE(jump);
3735  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3736  /* End of dropping frames. */  /* End of dropping frames. */
3737  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3738    
3739  JUMPHERE(jump);  JUMPHERE(jump);
3740  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3741  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3742  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3743  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));  
3744  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3745  }  }
3746    
# Line 3033  static void check_wordboundary(compiler_ Line 3748  static void check_wordboundary(compiler_
3748  {  {
3749  DEFINE_COMPILER;  DEFINE_COMPILER;
3750  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3751    jump_list *skipread_list = NULL;
3752  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3753  struct sljit_jump *jump;  struct sljit_jump *jump;
3754  #endif  #endif
# Line 3058  if (common->use_ucp) Line 3774  if (common->use_ucp)
3774    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3775    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3776    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);
3777    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3778    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);
3779    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);
3780    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3781    JUMPHERE(jump);    JUMPHERE(jump);
3782    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3783    }    }
# Line 3090  else Line 3806  else
3806  JUMPHERE(skipread);  JUMPHERE(skipread);
3807    
3808  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3809  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3810  peek_char(common);  peek_char(common, READ_CHAR_MAX);
3811    
3812  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
3813  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 3102  if (common->use_ucp) Line 3818  if (common->use_ucp)
3818    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3819    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3820    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);
3821    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3822    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);
3823    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);
3824    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3825    JUMPHERE(jump);