/[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 852 by zherczeg, Thu Jan 5 19:18:12 2012 UTC revision 1308 by zherczeg, Tue Apr 2 06:58:55 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11    The machine code generator part (this module) was written by Zoltan Herczeg    The machine code generator part (this module) was written by Zoltan Herczeg
12                        Copyright (c) 2010-2012                        Copyright (c) 2010-2013
13    
14  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
15  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 46  POSSIBILITY OF SUCH DAMAGE. Line 46  POSSIBILITY OF SUCH DAMAGE.
46    
47  #include "pcre_internal.h"  #include "pcre_internal.h"
48    
49  #ifdef SUPPORT_JIT  #if defined SUPPORT_JIT
50    
51  /* All-in-one: Since we use the JIT compiler only from here,  /* All-in-one: Since we use the JIT compiler only from here,
52  we just include it. This way we don't need to touch the build  we just include it. This way we don't need to touch the build
# Line 65  system files. */ Line 65  system files. */
65  #error Unsupported architecture  #error Unsupported architecture
66  #endif  #endif
67    
68  /* Allocate memory on the stack. Fast, but limited size. */  /* Defines for debugging purposes. */
 #define LOCAL_SPACE_SIZE 32768  
69    
70    /* 1 - Use unoptimized capturing brackets.
71       2 - Enable capture_last_ptr (includes option 1). */
72    /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */
73    
74    /* 1 - Always have a control head. */
75    /* #define DEBUG_FORCE_CONTROL_HEAD 1 */
76    
77    /* Allocate memory for the regex stack on the real machine stack.
78    Fast, but limited size. */
79    #define MACHINE_STACK_SIZE 32768
80    
81    /* Growth rate for stack allocated by the OS. Should be the multiply
82    of page size. */
83  #define STACK_GROWTH_RATE 8192  #define STACK_GROWTH_RATE 8192
84    
85  /* Enable to check that the allocation could destroy temporaries. */  /* Enable to check that the allocation could destroy temporaries. */
# Line 82  The code generator follows the recursive Line 94  The code generator follows the recursive
94  expressions. The basic blocks of regular expressions are condition checkers  expressions. The basic blocks of regular expressions are condition checkers
95  whose execute different commands depending on the result of the condition check.  whose execute different commands depending on the result of the condition check.
96  The relationship between the operators can be horizontal (concatenation) and  The relationship between the operators can be horizontal (concatenation) and
97  vertical (sub-expression) (See struct fallback_common for more details).  vertical (sub-expression) (See struct backtrack_common for more details).
98    
99    'ab' - 'a' and 'b' regexps are concatenated    'ab' - 'a' and 'b' regexps are concatenated
100    'a+' - 'a' is the sub-expression of the '+' operator    'a+' - 'a' is the sub-expression of the '+' operator
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 hot 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 'fallback' 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 hot path.  branches on the matching path.
107    
108   Greedy star operator (*) :   Greedy star operator (*) :
109     Hot path: match happens.     Matching path: match happens.
110     Fallback path: match failed.     Backtrack path: match failed.
111   Non-greedy star operator (*?) :   Non-greedy star operator (*?) :
112     Hot path: no need to perform a match.     Matching path: no need to perform a match.
113     Fallback 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
116  with two alternatives. Let A, B, C, D are arbirary regular expressions, and  with two alternatives. Let A, B, C, D are arbirary regular expressions, and
# 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 hot path   A matching path
124   '(' hot path (pushing arguments to the stack)   '(' matching path (pushing arguments to the stack)
125   B hot path   B matching path
126   ')' hot path (pushing arguments to the stack)   ')' matching path (pushing arguments to the stack)
127   D hot path   D matching path
128   return with successful match   return with successful match
129    
130   D fallback path   D backtrack path
131   ')' fallback path (If we arrived from "C" jump to the fallback of "C")   ')' backtrack path (If we arrived from "C" jump to the backtrack of "C")
132   B fallback path   B backtrack path
133   C expected path   C expected path
134   jump to D hot path   jump to D matching path
135   C fallback path   C backtrack path
136   A fallback path   A backtrack path
137    
138   Notice, that the order of fallback code paths are the opposite of the fast   Notice, that the order of backtrack code paths are the opposite of the fast
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 fallback code path. The fallback code 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 hot 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 fallback 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 fallback 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 152  typedef struct jit_arguments { Line 164  typedef struct jit_arguments {
164    const pcre_uchar *begin;    const pcre_uchar *begin;
165    const pcre_uchar *end;    const pcre_uchar *end;
166    int *offsets;    int *offsets;
167    pcre_uchar *ptr;    pcre_uchar *uchar_ptr;
168      pcre_uchar *mark_ptr;
169      void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171    int offsetcount;    int real_offset_count;
172    int calllimit;    int offset_count;
173      int call_limit;
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
177    pcre_uint8 notempty_atstart;    pcre_uint8 notempty_atstart;
178  } jit_arguments;  } jit_arguments;
179    
180  typedef struct executable_function {  typedef struct executable_functions {
181    void *executable_func;    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184    sljit_uw executable_size;    pcre_uint32 top_bracket;
185  } executable_function;    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
186    } executable_functions;
187    
188  typedef struct jump_list {  typedef struct jump_list {
189    struct sljit_jump *jump;    struct sljit_jump *jump;
190    struct jump_list *next;    struct jump_list *next;
191  } jump_list;  } jump_list;
192    
 enum stub_types { stack_alloc };  
   
193  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
194    struct sljit_jump *start;    struct sljit_jump *start;
195    struct sljit_label *leave;    struct sljit_label *quit;
196    struct stub_list *next;    struct stub_list *next;
197  } stub_list;  } stub_list;
198    
199    enum frame_types {
200      no_frame = -1,
201      no_stack = -2
202    };
203    
204    enum control_types {
205      type_mark = 0,
206      type_then_trap = 1
207    };
208    
209  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
210    
211  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
212  code generator. It is allocated by compile_hotpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
213  the aguments for compile_fallbackpath. Must be the first member  the aguments for compile_backtrackingpath. Must be the first member
214  of its descendants. */  of its descendants. */
215  typedef struct fallback_common {  typedef struct backtrack_common {
216    /* Concatenation stack. */    /* Concatenation stack. */
217    struct fallback_common *prev;    struct backtrack_common *prev;
218    jump_list *nextfallbacks;    jump_list *nextbacktracks;
219    /* Internal stack (for component operators). */    /* Internal stack (for component operators). */
220    struct fallback_common *top;    struct backtrack_common *top;
221    jump_list *topfallbacks;    jump_list *topbacktracks;
222    /* Opcode pointer. */    /* Opcode pointer. */
223    pcre_uchar *cc;    pcre_uchar *cc;
224  } fallback_common;  } backtrack_common;
225    
226  typedef struct assert_fallback {  typedef struct assert_backtrack {
227    fallback_common common;    backtrack_common common;
228    jump_list *condfailed;    jump_list *condfailed;
229    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
230    int framesize;    int framesize;
231    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
232    int localptr;    int private_data_ptr;
233    /* For iterators. */    /* For iterators. */
234    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
235  } assert_fallback;  } assert_backtrack;
236    
237  typedef struct bracket_fallback {  typedef struct bracket_backtrack {
238    fallback_common common;    backtrack_common common;
239    /* Where to coninue if an alternative is successfully matched. */    /* Where to coninue if an alternative is successfully matched. */
240    struct sljit_label *althotpath;    struct sljit_label *alternative_matchingpath;
241    /* For rmin and rmax iterators. */    /* For rmin and rmax iterators. */
242    struct sljit_label *recursivehotpath;    struct sljit_label *recursive_matchingpath;
243    /* For greedy ? operator. */    /* For greedy ? operator. */
244    struct sljit_label *zerohotpath;    struct sljit_label *zero_matchingpath;
245    /* Contains the branches of a failed condition. */    /* Contains the branches of a failed condition. */
246    union {    union {
247      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
248      jump_list *condfailed;      jump_list *condfailed;
249      assert_fallback *assert;      assert_backtrack *assert;
250      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
251      int framesize;      int framesize;
252    } u;    } u;
253    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
254    int localptr;    int private_data_ptr;
255  } bracket_fallback;  } bracket_backtrack;
256    
257  typedef struct bracketpos_fallback {  typedef struct bracketpos_backtrack {
258    fallback_common common;    backtrack_common common;
259    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
260    int localptr;    int private_data_ptr;
261    /* Reverting stack is needed. */    /* Reverting stack is needed. */
262    int framesize;    int framesize;
263    /* Allocated stack size. */    /* Allocated stack size. */
264    int stacksize;    int stacksize;
265  } bracketpos_fallback;  } bracketpos_backtrack;
266    
267  typedef struct braminzero_fallback {  typedef struct braminzero_backtrack {
268    fallback_common common;    backtrack_common common;
269    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
270  } braminzero_fallback;  } braminzero_backtrack;
271    
272  typedef struct iterator_fallback {  typedef struct iterator_backtrack {
273    fallback_common common;    backtrack_common common;
274    /* Next iteration. */    /* Next iteration. */
275    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
276  } iterator_fallback;  } iterator_backtrack;
277    
278  typedef struct recurse_entry {  typedef struct recurse_entry {
279    struct recurse_entry *next;    struct recurse_entry *next;
# Line 260  typedef struct recurse_entry { Line 282  typedef struct recurse_entry {
282    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
283    jump_list *calls;    jump_list *calls;
284    /* Points to the starting opcode. */    /* Points to the starting opcode. */
285    int start;    sljit_sw start;
286  } recurse_entry;  } recurse_entry;
287    
288  typedef struct recurse_fallback {  typedef struct recurse_backtrack {
289    fallback_common common;    backtrack_common common;
290  } recurse_fallback;    BOOL inlined_pattern;
291    } recurse_backtrack;
292    
293    #define OP_THEN_TRAP OP_TABLE_LENGTH
294    
295    typedef struct then_trap_backtrack {
296      backtrack_common common;
297      /* If then_trap is not NULL, this structure contains the real
298      then_trap for the backtracking path. */
299      struct then_trap_backtrack *then_trap;
300      /* Points to the starting opcode. */
301      sljit_sw start;
302      /* Exit point for the then opcodes of this alternative. */
303      jump_list *quit;
304      /* Frame size of the current alternative. */
305      int framesize;
306    } then_trap_backtrack;
307    
308    #define MAX_RANGE_SIZE 6
309    
310  typedef struct compiler_common {  typedef struct compiler_common {
311      /* The sljit ceneric compiler. */
312    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
313      /* First byte code. */
314    pcre_uchar *start;    pcre_uchar *start;
315    int localsize;    /* Maps private data offset to each opcode. */
316    int *localptrs;    sljit_si *private_data_ptrs;
317      /* Tells whether the capturing bracket is optimized. */
318      pcre_uint8 *optimized_cbracket;
319      /* Tells whether the starting offset is a target of then. */
320      pcre_uint8 *then_offsets;
321      /* Current position where a THEN must jump. */
322      then_trap_backtrack *then_trap;
323      /* Starting offset of private data for capturing brackets. */
324      int cbra_ptr;
325      /* Output vector starting point. Must be divisible by 2. */
326      int ovector_start;
327      /* Last known position of the requested byte. */
328      int req_char_ptr;
329      /* Head of the last recursion. */
330      int recursive_head_ptr;
331      /* First inspected character for partial matching. */
332      int start_used_ptr;
333      /* Starting pointer for partial soft matches. */
334      int hit_start;
335      /* End pointer of the first line. */
336      int first_line_end;
337      /* Points to the marked string. */
338      int mark_ptr;
339      /* Recursive control verb management chain. */
340      int control_head_ptr;
341      /* Points to the last matched capture block index. */
342      int capture_last_ptr;
343      /* Points to the starting position of the current match. */
344      int start_ptr;
345    
346      /* Flipped and lower case tables. */
347    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
348    sljit_w lcc;    sljit_sw lcc;
349    int cbraptr;    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
350      int mode;
351      /* \K is found in the pattern. */
352      BOOL has_set_som;
353      /* (*SKIP:arg) is found in the pattern. */
354      BOOL has_skip_arg;
355      /* (*THEN) is found in the pattern. */
356      BOOL has_then;
357      /* Needs to know the start position anytime. */
358      BOOL needs_start_ptr;
359      /* Currently in recurse or negative assert. */
360      BOOL local_exit;
361      /* Currently in a positive assert. */
362      BOOL positive_assert;
363      /* Newline control. */
364    int nltype;    int nltype;
365    int newline;    int newline;
366    int bsr_nltype;    int bsr_nltype;
367      /* Dollar endonly. */
368    int endonly;    int endonly;
369    sljit_w ctypes;    /* Tables. */
370      sljit_sw ctypes;
371      int digits[2 + MAX_RANGE_SIZE];
372      /* Named capturing brackets. */
373    sljit_uw name_table;    sljit_uw name_table;
374    sljit_w name_count;    sljit_sw name_count;
375    sljit_w name_entry_size;    sljit_sw name_entry_size;
376    struct sljit_label *acceptlabel;  
377      /* Labels and jump lists. */
378      struct sljit_label *partialmatchlabel;
379      struct sljit_label *quit_label;
380      struct sljit_label *forced_quit_label;
381      struct sljit_label *accept_label;
382    stub_list *stubs;    stub_list *stubs;
383    recurse_entry *entries;    recurse_entry *entries;
384    recurse_entry *currententry;    recurse_entry *currententry;
385      jump_list *partialmatch;
386      jump_list *quit;
387      jump_list *positive_assert_quit;
388      jump_list *forced_quit;
389    jump_list *accept;    jump_list *accept;
390    jump_list *calllimit;    jump_list *calllimit;
391    jump_list *stackalloc;    jump_list *stackalloc;
# Line 297  typedef struct compiler_common { Line 396  typedef struct compiler_common {
396    jump_list *vspace;    jump_list *vspace;
397    jump_list *casefulcmp;    jump_list *casefulcmp;
398    jump_list *caselesscmp;    jump_list *caselesscmp;
399      jump_list *reset_match;
400    BOOL jscript_compat;    BOOL jscript_compat;
401  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
402    BOOL utf;    BOOL utf;
403  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
404    BOOL use_ucp;    BOOL use_ucp;
405  #endif  #endif
406    #ifndef COMPILE_PCRE32
407    jump_list *utfreadchar;    jump_list *utfreadchar;
408    #endif
409  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
410    jump_list *utfreadtype8;    jump_list *utfreadtype8;
411  #endif  #endif
# Line 321  typedef struct compare_context { Line 423  typedef struct compare_context {
423  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
424    int ucharptr;    int ucharptr;
425    union {    union {
426      sljit_i asint;      sljit_si asint;
427      sljit_uh asushort;      sljit_uh asushort;
428  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
429      sljit_ub asbyte;      sljit_ub asbyte;
430      sljit_ub asuchars[4];      sljit_ub asuchars[4];
431  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
432      sljit_uh asuchars[2];      sljit_uh asuchars[2];
433  #endif  #elif defined COMPILE_PCRE32
434        sljit_ui asuchars[1];
435  #endif  #endif
436    } c;    } c;
437    union {    union {
438      sljit_i asint;      sljit_si asint;
439      sljit_uh asushort;      sljit_uh asushort;
440  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
441      sljit_ub asbyte;      sljit_ub asbyte;
442      sljit_ub asuchars[4];      sljit_ub asuchars[4];
443  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
444      sljit_uh asuchars[2];      sljit_uh asuchars[2];
445  #endif  #elif defined COMPILE_PCRE32
446        sljit_ui asuchars[1];
447  #endif  #endif
448    } oc;    } oc;
449  #endif  #endif
450  } compare_context;  } compare_context;
451    
452  enum {  /* Undefine sljit macros. */
453    frame_end = 0,  #undef CMP
   frame_setstrbegin = -1  
 };  
454    
455  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
456  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
457    
458  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
459  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
460  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
461  #define STR_PTR       SLJIT_GENERAL_REG1  #define STR_PTR       SLJIT_SAVED_REG1
462  #define STR_END       SLJIT_GENERAL_REG2  #define STR_END       SLJIT_SAVED_REG2
463  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
464  #define STACK_LIMIT   SLJIT_GENERAL_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
465  #define ARGUMENTS     SLJIT_GENERAL_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
466  #define CALL_COUNT    SLJIT_GENERAL_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
467  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
468    
469  /* Locals layout. */  /* Local space layout. */
470  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
471  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
472  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
473  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
474  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
475  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
 /* Head of the last recursion. */  
 #define RECURSIVE_HEAD   (4 * sizeof(sljit_w))  
476  /* Max limit of recursions. */  /* Max limit of recursions. */
477  #define CALL_LIMIT       (5 * sizeof(sljit_w))  #define CALL_LIMIT       (4 * sizeof(sljit_sw))
 /* Last known position of the requested byte. */  
 #define REQ_CHAR_PTR     (6 * sizeof(sljit_w))  
 /* End pointer of the first line. */  
 #define FIRSTLINE_END    (7 * sizeof(sljit_w))  
478  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
479  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
480  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
481  the start pointers when the end of the capturing group has not yet reached. */  the start pointers when the end of the capturing group has not yet reached. */
482  #define OVECTOR_START    (8 * sizeof(sljit_w))  #define OVECTOR_START    (common->ovector_start)
483  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
484  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * sizeof(sljit_sw))
485  #define PRIV_DATA(cc)    (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
486    
487  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
488  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
489  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
490  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
491  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
492  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
493    #elif defined COMPILE_PCRE32
494    #define MOV_UCHAR  SLJIT_MOV_UI
495    #define MOVU_UCHAR SLJIT_MOVU_UI
496  #else  #else
497  #error Unsupported compiling mode  #error Unsupported compiling mode
498  #endif  #endif
 #endif  
499    
500  /* Shortcuts. */  /* Shortcuts. */
501  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 417  the start pointers when the end of the c Line 512  the start pointers when the end of the c
512    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
513  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
514    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
515    #define SET_LABEL(jump, label) \
516      sljit_set_label((jump), (label))
517  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
518    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
519  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
520    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))
521  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
522    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
523    #define GET_LOCAL_BASE(dst, dstw, offset) \
524      sljit_get_local_base(compiler, (dst), (dstw), (offset))
525    
526  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
527  {  {
# Line 435  return cc; Line 534  return cc;
534    
535  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
536   next_opcode   next_opcode
537   get_localspace   check_opcode_types
538   set_localptrs   set_private_data_ptrs
539   get_framesize   get_framesize
540   init_frame   init_frame
541   get_localsize   get_private_data_copy_length
542   copy_locals   copy_private_data
543   compile_hotpath   compile_matchingpath
544   compile_fallbackpath   compile_backtrackingpath
545  */  */
546    
547  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
# Line 463  switch(*cc) Line 562  switch(*cc)
562    case OP_WORDCHAR:    case OP_WORDCHAR:
563    case OP_ANY:    case OP_ANY:
564    case OP_ALLANY:    case OP_ALLANY:
565      case OP_NOTPROP:
566      case OP_PROP:
567    case OP_ANYNL:    case OP_ANYNL:
568    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
569    case OP_HSPACE:    case OP_HSPACE:
# Line 475  switch(*cc) Line 576  switch(*cc)
576    case OP_CIRCM:    case OP_CIRCM:
577    case OP_DOLL:    case OP_DOLL:
578    case OP_DOLLM:    case OP_DOLLM:
   case OP_TYPESTAR:  
   case OP_TYPEMINSTAR:  
   case OP_TYPEPLUS:  
   case OP_TYPEMINPLUS:  
   case OP_TYPEQUERY:  
   case OP_TYPEMINQUERY:  
   case OP_TYPEPOSSTAR:  
   case OP_TYPEPOSPLUS:  
   case OP_TYPEPOSQUERY:  
579    case OP_CRSTAR:    case OP_CRSTAR:
580    case OP_CRMINSTAR:    case OP_CRMINSTAR:
581    case OP_CRPLUS:    case OP_CRPLUS:
582    case OP_CRMINPLUS:    case OP_CRMINPLUS:
583    case OP_CRQUERY:    case OP_CRQUERY:
584    case OP_CRMINQUERY:    case OP_CRMINQUERY:
585      case OP_CRRANGE:
586      case OP_CRMINRANGE:
587      case OP_CLASS:
588      case OP_NCLASS:
589      case OP_REF:
590      case OP_REFI:
591      case OP_RECURSE:
592      case OP_CALLOUT:
593      case OP_ALT:
594      case OP_KET:
595      case OP_KETRMAX:
596      case OP_KETRMIN:
597      case OP_KETRPOS:
598      case OP_REVERSE:
599      case OP_ASSERT:
600      case OP_ASSERT_NOT:
601      case OP_ASSERTBACK:
602      case OP_ASSERTBACK_NOT:
603      case OP_ONCE:
604      case OP_ONCE_NC:
605      case OP_BRA:
606      case OP_BRAPOS:
607      case OP_CBRA:
608      case OP_CBRAPOS:
609      case OP_COND:
610      case OP_SBRA:
611      case OP_SBRAPOS:
612      case OP_SCBRA:
613      case OP_SCBRAPOS:
614      case OP_SCOND:
615      case OP_CREF:
616      case OP_NCREF:
617      case OP_RREF:
618      case OP_NRREF:
619    case OP_DEF:    case OP_DEF:
620    case OP_BRAZERO:    case OP_BRAZERO:
621    case OP_BRAMINZERO:    case OP_BRAMINZERO:
622    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
623      case OP_PRUNE:
624      case OP_SKIP:
625      case OP_THEN:
626      case OP_COMMIT:
627    case OP_FAIL:    case OP_FAIL:
628    case OP_ACCEPT:    case OP_ACCEPT:
629    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
630      case OP_CLOSE:
631    case OP_SKIPZERO:    case OP_SKIPZERO:
632    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
633    
634    case OP_CHAR:    case OP_CHAR:
635    case OP_CHARI:    case OP_CHARI:
# Line 516  switch(*cc) Line 641  switch(*cc)
641    case OP_MINPLUS:    case OP_MINPLUS:
642    case OP_QUERY:    case OP_QUERY:
643    case OP_MINQUERY:    case OP_MINQUERY:
644      case OP_UPTO:
645      case OP_MINUPTO:
646      case OP_EXACT:
647    case OP_POSSTAR:    case OP_POSSTAR:
648    case OP_POSPLUS:    case OP_POSPLUS:
649    case OP_POSQUERY:    case OP_POSQUERY:
650      case OP_POSUPTO:
651    case OP_STARI:    case OP_STARI:
652    case OP_MINSTARI:    case OP_MINSTARI:
653    case OP_PLUSI:    case OP_PLUSI:
654    case OP_MINPLUSI:    case OP_MINPLUSI:
655    case OP_QUERYI:    case OP_QUERYI:
656    case OP_MINQUERYI:    case OP_MINQUERYI:
657      case OP_UPTOI:
658      case OP_MINUPTOI:
659      case OP_EXACTI:
660    case OP_POSSTARI:    case OP_POSSTARI:
661    case OP_POSPLUSI:    case OP_POSPLUSI:
662    case OP_POSQUERYI:    case OP_POSQUERYI:
663      case OP_POSUPTOI:
664    case OP_NOTSTAR:    case OP_NOTSTAR:
665    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
666    case OP_NOTPLUS:    case OP_NOTPLUS:
667    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
668    case OP_NOTQUERY:    case OP_NOTQUERY:
669    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
670      case OP_NOTUPTO:
671      case OP_NOTMINUPTO:
672      case OP_NOTEXACT:
673    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
674    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
675    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
676      case OP_NOTPOSUPTO:
677    case OP_NOTSTARI:    case OP_NOTSTARI:
678    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
679    case OP_NOTPLUSI:    case OP_NOTPLUSI:
680    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
681    case OP_NOTQUERYI:    case OP_NOTQUERYI:
682    case OP_NOTMINQUERYI:    case OP_NOTMINQUERYI:
   case OP_NOTPOSSTARI:  
   case OP_NOTPOSPLUSI:  
   case OP_NOTPOSQUERYI:  
   cc += 2;  
 #ifdef SUPPORT_UTF  
   if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
   return cc;  
   
   case OP_UPTO:  
   case OP_MINUPTO:  
   case OP_EXACT:  
   case OP_POSUPTO:  
   case OP_UPTOI:  
   case OP_MINUPTOI:  
   case OP_EXACTI:  
   case OP_POSUPTOI:  
   case OP_NOTUPTO:  
   case OP_NOTMINUPTO:  
   case OP_NOTEXACT:  
   case OP_NOTPOSUPTO:  
683    case OP_NOTUPTOI:    case OP_NOTUPTOI:
684    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
685    case OP_NOTEXACTI:    case OP_NOTEXACTI:
686      case OP_NOTPOSSTARI:
687      case OP_NOTPOSPLUSI:
688      case OP_NOTPOSQUERYI:
689    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
690    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
691  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
692    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
693  #endif  #endif
694    return cc;    return cc;
695    
696    case OP_NOTPROP:    /* Special cases. */
697    case OP_PROP:    case OP_TYPESTAR:
698    return cc + 1 + 2;    case OP_TYPEMINSTAR:
699      case OP_TYPEPLUS:
700      case OP_TYPEMINPLUS:
701      case OP_TYPEQUERY:
702      case OP_TYPEMINQUERY:
703    case OP_TYPEUPTO:    case OP_TYPEUPTO:
704    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
705    case OP_TYPEEXACT:    case OP_TYPEEXACT:
706      case OP_TYPEPOSSTAR:
707      case OP_TYPEPOSPLUS:
708      case OP_TYPEPOSQUERY:
709    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
710    case OP_REF:    return cc + PRIV(OP_lengths)[*cc] - 1;
   case OP_REFI:  
   case OP_CREF:  
   case OP_NCREF:  
   case OP_RREF:  
   case OP_NRREF:  
   case OP_CLOSE:  
   cc += 1 + IMM2_SIZE;  
   return cc;  
711    
712    case OP_CRRANGE:    case OP_ANYBYTE:
713    case OP_CRMINRANGE:  #ifdef SUPPORT_UTF
714    return cc + 1 + 2 * IMM2_SIZE;    if (common->utf) return NULL;
715    #endif
716    case OP_CLASS:    return cc + 1;
   case OP_NCLASS:  
   return cc + 1 + 32 / sizeof(pcre_uchar);  
717    
718  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
719    case OP_XCLASS:    case OP_XCLASS:
720    return cc + GET(cc, 1);    return cc + GET(cc, 1);
721  #endif  #endif
722    
723    case OP_RECURSE:    case OP_MARK:
724    case OP_ASSERT:    case OP_PRUNE_ARG:
725    case OP_ASSERT_NOT:    case OP_SKIP_ARG:
726    case OP_ASSERTBACK:    case OP_THEN_ARG:
727    case OP_ASSERTBACK_NOT:    return cc + 1 + 2 + cc[1];
   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;  
728    
729    default:    default:
730      /* All opcodes are supported now! */
731      SLJIT_ASSERT_STOP();
732    return NULL;    return NULL;
733    }    }
734  }  }
735    
736  static int get_localspace(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
737  {  {
738  int localspace = 0;  pcre_uchar *name;
739  pcre_uchar *alternative;  pcre_uchar *name2;
740    int i, cbra_index;
741    
742  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
743  while (cc < ccend)  while (cc < ccend)
744    {    {
745    switch(*cc)    switch(*cc)
746      {      {
747      case OP_ASSERT:      case OP_SET_SOM:
748      case OP_ASSERT_NOT:      common->has_set_som = TRUE;
749      case OP_ASSERTBACK:      cc += 1;
750      case OP_ASSERTBACK_NOT:      break;
751      case OP_ONCE:  
752      case OP_ONCE_NC:      case OP_REF:
753      case OP_BRAPOS:      case OP_REFI:
754      case OP_SBRA:      common->optimized_cbracket[GET2(cc, 1)] = 0;
755      case OP_SBRAPOS:      cc += 1 + IMM2_SIZE;
     case OP_SCOND:  
     localspace += sizeof(sljit_w);  
     cc += 1 + LINK_SIZE;  
756      break;      break;
757    
758      case OP_CBRAPOS:      case OP_CBRAPOS:
759      case OP_SCBRAPOS:      case OP_SCBRAPOS:
760      localspace += sizeof(sljit_w);      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
761      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
762      break;      break;
763    
764      case OP_COND:      case OP_COND:
765      /* Might be a hidden SCOND. */      case OP_SCOND:
766      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
767      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
768        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
769          return FALSE;
770      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
771      break;      break;
772    
773        case OP_CREF:
774        i = GET2(cc, 1);
775        common->optimized_cbracket[i] = 0;
776        cc += 1 + IMM2_SIZE;
777        break;
778    
779        case OP_NCREF:
780        cbra_index = GET2(cc, 1);
781        name = (pcre_uchar *)common->name_table;
782        name2 = name;
783        for (i = 0; i < common->name_count; i++)
784          {
785          if (GET2(name, 0) == cbra_index) break;
786          name += common->name_entry_size;
787          }
788        SLJIT_ASSERT(i != common->name_count);
789    
790        for (i = 0; i < common->name_count; i++)
791          {
792          if (STRCMP_UC_UC(name2 + IMM2_SIZE, name + IMM2_SIZE) == 0)
793            common->optimized_cbracket[GET2(name2, 0)] = 0;
794          name2 += common->name_entry_size;
795          }
796        cc += 1 + IMM2_SIZE;
797        break;
798    
799        case OP_RECURSE:
800        /* Set its value only once. */
801        if (common->recursive_head_ptr == 0)
802          {
803          common->recursive_head_ptr = common->ovector_start;
804          common->ovector_start += sizeof(sljit_sw);
805          }
806        cc += 1 + LINK_SIZE;
807        break;
808    
809        case OP_CALLOUT:
810        if (common->capture_last_ptr == 0)
811          {
812          common->capture_last_ptr = common->ovector_start;
813          common->ovector_start += sizeof(sljit_sw);
814          }
815        cc += 2 + 2 * LINK_SIZE;
816        break;
817    
818        case OP_THEN_ARG:
819        common->has_then = TRUE;
820        common->control_head_ptr = 1;
821        /* Fall through. */
822    
823        case OP_PRUNE_ARG:
824        common->needs_start_ptr = TRUE;
825        /* Fall through. */
826    
827        case OP_MARK:
828        if (common->mark_ptr == 0)
829          {
830          common->mark_ptr = common->ovector_start;
831          common->ovector_start += sizeof(sljit_sw);
832          }
833        cc += 1 + 2 + cc[1];
834        break;
835    
836        case OP_THEN:
837        common->has_then = TRUE;
838        common->control_head_ptr = 1;
839        /* Fall through. */
840    
841        case OP_PRUNE:
842        case OP_SKIP:
843        common->needs_start_ptr = TRUE;
844        cc += 1;
845        break;
846    
847        case OP_SKIP_ARG:
848        common->control_head_ptr = 1;
849        common->has_skip_arg = TRUE;
850        cc += 1 + 2 + cc[1];
851        break;
852    
853      default:      default:
854      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
855      if (cc == NULL)      if (cc == NULL)
856        return -1;        return FALSE;
857      break;      break;
858      }      }
859    }    }
860  return localspace;  return TRUE;
861    }
862    
863    static int get_class_iterator_size(pcre_uchar *cc)
864    {
865    switch(*cc)
866      {
867      case OP_CRSTAR:
868      case OP_CRPLUS:
869      return 2;
870    
871      case OP_CRMINSTAR:
872      case OP_CRMINPLUS:
873      case OP_CRQUERY:
874      case OP_CRMINQUERY:
875      return 1;
876    
877      case OP_CRRANGE:
878      case OP_CRMINRANGE:
879      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
880        return 0;
881      return 2;
882    
883      default:
884      return 0;
885      }
886  }  }
887    
888  static void set_localptrs(compiler_common *common, int localptr, pcre_uchar *ccend)  static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
889    {
890    pcre_uchar *end = bracketend(begin);
891    pcre_uchar *next;
892    pcre_uchar *next_end;
893    pcre_uchar *max_end;
894    pcre_uchar type;
895    sljit_uw length = end - begin;
896    int min, max, i;
897    
898    /* Detect fixed iterations first. */
899    if (end[-(1 + LINK_SIZE)] != OP_KET)
900      return FALSE;
901    
902    /* Already detected repeat. */
903    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
904      return TRUE;
905    
906    next = end;
907    min = 1;
908    while (1)
909      {
910      if (*next != *begin)
911        break;
912      next_end = bracketend(next);
913      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
914        break;
915      next = next_end;
916      min++;
917      }
918    
919    if (min == 2)
920      return FALSE;
921    
922    max = 0;
923    max_end = next;
924    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
925      {
926      type = *next;
927      while (1)
928        {
929        if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
930          break;
931        next_end = bracketend(next + 2 + LINK_SIZE);
932        if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
933          break;
934        next = next_end;
935        max++;
936        }
937    
938      if (next[0] == type && next[1] == *begin && max >= 1)
939        {
940        next_end = bracketend(next + 1);
941        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
942          {
943          for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
944            if (*next_end != OP_KET)
945              break;
946    
947          if (i == max)
948            {
949            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
950            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
951            /* +2 the original and the last. */
952            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
953            if (min == 1)
954              return TRUE;
955            min--;
956            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
957            }
958          }
959        }
960      }
961    
962    if (min >= 3)
963      {
964      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
965      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
966      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
967      return TRUE;
968      }
969    
970    return FALSE;
971    }
972    
973    #define CASE_ITERATOR_PRIVATE_DATA_1 \
974        case OP_MINSTAR: \
975        case OP_MINPLUS: \
976        case OP_QUERY: \
977        case OP_MINQUERY: \
978        case OP_MINSTARI: \
979        case OP_MINPLUSI: \
980        case OP_QUERYI: \
981        case OP_MINQUERYI: \
982        case OP_NOTMINSTAR: \
983        case OP_NOTMINPLUS: \
984        case OP_NOTQUERY: \
985        case OP_NOTMINQUERY: \
986        case OP_NOTMINSTARI: \
987        case OP_NOTMINPLUSI: \
988        case OP_NOTQUERYI: \
989        case OP_NOTMINQUERYI:
990    
991    #define CASE_ITERATOR_PRIVATE_DATA_2A \
992        case OP_STAR: \
993        case OP_PLUS: \
994        case OP_STARI: \
995        case OP_PLUSI: \
996        case OP_NOTSTAR: \
997        case OP_NOTPLUS: \
998        case OP_NOTSTARI: \
999        case OP_NOTPLUSI:
1000    
1001    #define CASE_ITERATOR_PRIVATE_DATA_2B \
1002        case OP_UPTO: \
1003        case OP_MINUPTO: \
1004        case OP_UPTOI: \
1005        case OP_MINUPTOI: \
1006        case OP_NOTUPTO: \
1007        case OP_NOTMINUPTO: \
1008        case OP_NOTUPTOI: \
1009        case OP_NOTMINUPTOI:
1010    
1011    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1012        case OP_TYPEMINSTAR: \
1013        case OP_TYPEMINPLUS: \
1014        case OP_TYPEQUERY: \
1015        case OP_TYPEMINQUERY:
1016    
1017    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1018        case OP_TYPESTAR: \
1019        case OP_TYPEPLUS:
1020    
1021    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1022        case OP_TYPEUPTO: \
1023        case OP_TYPEMINUPTO:
1024    
1025    static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1026  {  {
1027  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1028  pcre_uchar *alternative;  pcre_uchar *alternative;
1029    pcre_uchar *end = NULL;
1030    int private_data_ptr = *private_data_start;
1031    int space, size, bracketlen;
1032    
1033  while (cc < ccend)  while (cc < ccend)
1034    {    {
1035      space = 0;
1036      size = 0;
1037      bracketlen = 0;
1038      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1039        return;
1040    
1041      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1042        if (detect_repeat(common, cc))
1043          {
1044          /* These brackets are converted to repeats, so no global
1045          based single character repeat is allowed. */
1046          if (cc >= end)
1047            end = bracketend(cc);
1048          }
1049    
1050    switch(*cc)    switch(*cc)
1051      {      {
1052        case OP_KET:
1053        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1054          {
1055          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1056          private_data_ptr += sizeof(sljit_sw);
1057          cc += common->private_data_ptrs[cc + 1 - common->start];
1058          }
1059        cc += 1 + LINK_SIZE;
1060        break;
1061    
1062      case OP_ASSERT:      case OP_ASSERT:
1063      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1064      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 702  while (cc < ccend) Line 1069  while (cc < ccend)
1069      case OP_SBRA:      case OP_SBRA:
1070      case OP_SBRAPOS:      case OP_SBRAPOS:
1071      case OP_SCOND:      case OP_SCOND:
1072      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1073      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1074      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1075      break;      break;
1076    
1077      case OP_CBRAPOS:      case OP_CBRAPOS:
1078      case OP_SCBRAPOS:      case OP_SCBRAPOS:
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      cc += 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1082      break;      break;
1083    
1084      case OP_COND:      case OP_COND:
# Line 719  while (cc < ccend) Line 1086  while (cc < ccend)
1086      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1087      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1088        {        {
1089        common->localptrs[cc - common->start] = localptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1090        localptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1091          }
1092        bracketlen = 1 + LINK_SIZE;
1093        break;
1094    
1095        case OP_BRA:
1096        bracketlen = 1 + LINK_SIZE;
1097        break;
1098    
1099        case OP_CBRA:
1100        case OP_SCBRA:
1101        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1102        break;
1103    
1104        CASE_ITERATOR_PRIVATE_DATA_1
1105        space = 1;
1106        size = -2;
1107        break;
1108    
1109        CASE_ITERATOR_PRIVATE_DATA_2A
1110        space = 2;
1111        size = -2;
1112        break;
1113    
1114        CASE_ITERATOR_PRIVATE_DATA_2B
1115        space = 2;
1116        size = -(2 + IMM2_SIZE);
1117        break;
1118    
1119        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1120        space = 1;
1121        size = 1;
1122        break;
1123    
1124        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1125        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1126          space = 2;
1127        size = 1;
1128        break;
1129    
1130        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1131        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1132          space = 2;
1133        size = 1 + IMM2_SIZE;
1134        break;
1135    
1136        case OP_CLASS:
1137        case OP_NCLASS:
1138        size += 1 + 32 / sizeof(pcre_uchar);
1139        space = get_class_iterator_size(cc + size);
1140        break;
1141    
1142    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1143        case OP_XCLASS:
1144        size = GET(cc, 1);
1145        space = get_class_iterator_size(cc + size);
1146        break;
1147    #endif
1148    
1149        default:
1150        cc = next_opcode(common, cc);
1151        SLJIT_ASSERT(cc != NULL);
1152        break;
1153        }
1154    
1155      /* Character iterators, which are not inside a repeated bracket,
1156         gets a private slot instead of allocating it on the stack. */
1157      if (space > 0 && cc >= end)
1158        {
1159        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1160        private_data_ptr += sizeof(sljit_sw) * space;
1161        }
1162    
1163      if (size != 0)
1164        {
1165        if (size < 0)
1166          {
1167          cc += -size;
1168    #ifdef SUPPORT_UTF
1169          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1170    #endif
1171        }        }
1172      cc += 1 + LINK_SIZE;      else
1173      break;        cc += size;
1174        }
1175    
1176      default:    if (bracketlen > 0)
1177      cc = next_opcode(common, cc);      {
1178      SLJIT_ASSERT(cc != NULL);      if (cc >= end)
1179      break;        {
1180          end = bracketend(cc);
1181          if (end[-1 - LINK_SIZE] == OP_KET)
1182            end = NULL;
1183          }
1184        cc += bracketlen;
1185      }      }
1186    }    }
1187    *private_data_start = private_data_ptr;
1188  }  }
1189    
1190  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1191  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)
1192  {  {
 pcre_uchar *ccend = bracketend(cc);  
1193  int length = 0;  int length = 0;
1194  BOOL possessive = FALSE;  int possessive = 0;
1195  BOOL setsom_found = FALSE;  BOOL stack_restore = FALSE;
1196    BOOL setsom_found = recursive;
1197    BOOL setmark_found = recursive;
1198    /* The last capture is a local variable even for recursions. */
1199    BOOL capture_last_found = FALSE;
1200    
1201    #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1202    SLJIT_ASSERT(common->control_head_ptr != 0);
1203    *needs_control_head = TRUE;
1204    #else
1205    *needs_control_head = FALSE;
1206    #endif
1207    
1208  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (ccend == NULL)
1209    {    {
1210    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1211    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1212        {
1213        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1214        /* This is correct regardless of common->capture_last_ptr. */
1215        capture_last_found = TRUE;
1216        }
1217      cc = next_opcode(common, cc);
1218    }    }
1219    
 cc = next_opcode(common, cc);  
1220  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1221  while (cc < ccend)  while (cc < ccend)
1222    switch(*cc)    switch(*cc)
1223      {      {
1224      case OP_SET_SOM:      case OP_SET_SOM:
1225      case OP_RECURSE:      SLJIT_ASSERT(common->has_set_som);
1226        stack_restore = TRUE;
1227      if (!setsom_found)      if (!setsom_found)
1228        {        {
1229        length += 2;        length += 2;
1230        setsom_found = TRUE;        setsom_found = TRUE;
1231        }        }
1232      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      cc += 1;
1233        break;
1234    
1235        case OP_MARK:
1236        case OP_PRUNE_ARG:
1237        case OP_THEN_ARG:
1238        SLJIT_ASSERT(common->mark_ptr != 0);
1239        stack_restore = TRUE;
1240        if (!setmark_found)
1241          {
1242          length += 2;
1243          setmark_found = TRUE;
1244          }
1245        if (common->control_head_ptr != 0)
1246          *needs_control_head = TRUE;
1247        cc += 1 + 2 + cc[1];
1248        break;
1249    
1250        case OP_RECURSE:
1251        stack_restore = TRUE;
1252        if (common->has_set_som && !setsom_found)
1253          {
1254          length += 2;
1255          setsom_found = TRUE;
1256          }
1257        if (common->mark_ptr != 0 && !setmark_found)
1258          {
1259          length += 2;
1260          setmark_found = TRUE;
1261          }
1262        if (common->capture_last_ptr != 0 && !capture_last_found)
1263          {
1264          length += 2;
1265          capture_last_found = TRUE;
1266          }
1267        cc += 1 + LINK_SIZE;
1268      break;      break;
1269    
1270      case OP_CBRA:      case OP_CBRA:
1271      case OP_CBRAPOS:      case OP_CBRAPOS:
1272      case OP_SCBRA:      case OP_SCBRA:
1273      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1274        stack_restore = TRUE;
1275        if (common->capture_last_ptr != 0 && !capture_last_found)
1276          {
1277          length += 2;
1278          capture_last_found = TRUE;
1279          }
1280      length += 3;      length += 3;
1281      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1282      break;      break;
1283    
1284      default:      default:
1285        stack_restore = TRUE;
1286        /* Fall through. */
1287    
1288        case OP_NOT_WORD_BOUNDARY:
1289        case OP_WORD_BOUNDARY:
1290        case OP_NOT_DIGIT:
1291        case OP_DIGIT:
1292        case OP_NOT_WHITESPACE:
1293        case OP_WHITESPACE:
1294        case OP_NOT_WORDCHAR:
1295        case OP_WORDCHAR:
1296        case OP_ANY:
1297        case OP_ALLANY:
1298        case OP_ANYBYTE:
1299        case OP_NOTPROP:
1300        case OP_PROP:
1301        case OP_ANYNL:
1302        case OP_NOT_HSPACE:
1303        case OP_HSPACE:
1304        case OP_NOT_VSPACE:
1305        case OP_VSPACE:
1306        case OP_EXTUNI:
1307        case OP_EODN:
1308        case OP_EOD:
1309        case OP_CIRC:
1310        case OP_CIRCM:
1311        case OP_DOLL:
1312        case OP_DOLLM:
1313        case OP_CHAR:
1314        case OP_CHARI:
1315        case OP_NOT:
1316        case OP_NOTI:
1317    
1318        case OP_EXACT:
1319        case OP_POSSTAR:
1320        case OP_POSPLUS:
1321        case OP_POSQUERY:
1322        case OP_POSUPTO:
1323    
1324        case OP_EXACTI:
1325        case OP_POSSTARI:
1326        case OP_POSPLUSI:
1327        case OP_POSQUERYI:
1328        case OP_POSUPTOI:
1329    
1330        case OP_NOTEXACT:
1331        case OP_NOTPOSSTAR:
1332        case OP_NOTPOSPLUS:
1333        case OP_NOTPOSQUERY:
1334        case OP_NOTPOSUPTO:
1335    
1336        case OP_NOTEXACTI:
1337        case OP_NOTPOSSTARI:
1338        case OP_NOTPOSPLUSI:
1339        case OP_NOTPOSQUERYI:
1340        case OP_NOTPOSUPTOI:
1341    
1342        case OP_TYPEEXACT:
1343        case OP_TYPEPOSSTAR:
1344        case OP_TYPEPOSPLUS:
1345        case OP_TYPEPOSQUERY:
1346        case OP_TYPEPOSUPTO:
1347    
1348        case OP_CLASS:
1349        case OP_NCLASS:
1350        case OP_XCLASS:
1351    
1352      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1353      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1354      break;      break;
1355      }      }
1356    
1357  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1358  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1359    return -1;    return stack_restore ? no_frame : no_stack;
1360    
1361  if (length > 0)  if (length > 0)
1362    return length + 1;    return length + 1;
1363  return -1;  return stack_restore ? no_frame : no_stack;
1364  }  }
1365    
1366  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)
1367  {  {
1368  DEFINE_COMPILER;  DEFINE_COMPILER;
1369  pcre_uchar *ccend = bracketend(cc);  BOOL setsom_found = recursive;
1370  BOOL setsom_found = FALSE;  BOOL setmark_found = recursive;
1371    /* The last capture is a local variable even for recursions. */
1372    BOOL capture_last_found = FALSE;
1373  int offset;  int offset;
1374    
1375  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
1376    SLJIT_UNUSED_ARG(stacktop);
1377  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1378    
1379  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1380  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1381    cc = next_opcode(common, cc);    {
1382      ccend = bracketend(cc) - (1 + LINK_SIZE);
1383      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1384        cc = next_opcode(common, cc);
1385      }
1386    
1387  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1388  while (cc < ccend)  while (cc < ccend)
1389    switch(*cc)    switch(*cc)
1390      {      {
1391      case OP_SET_SOM:      case OP_SET_SOM:
1392      case OP_RECURSE:      SLJIT_ASSERT(common->has_set_som);
1393      if (!setsom_found)      if (!setsom_found)
1394        {        {
1395        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1396        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1397        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1398          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1399          stackpos += (int)sizeof(sljit_sw);
1400          setsom_found = TRUE;
1401          }
1402        cc += 1;
1403        break;
1404    
1405        case OP_MARK:
1406        case OP_PRUNE_ARG:
1407        case OP_THEN_ARG:
1408        SLJIT_ASSERT(common->mark_ptr != 0);
1409        if (!setmark_found)
1410          {
1411          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1412          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1413          stackpos += (int)sizeof(sljit_sw);
1414          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1415          stackpos += (int)sizeof(sljit_sw);
1416          setmark_found = TRUE;
1417          }
1418        cc += 1 + 2 + cc[1];
1419        break;
1420    
1421        case OP_RECURSE:
1422        if (common->has_set_som && !setsom_found)
1423          {
1424          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1425          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1426          stackpos += (int)sizeof(sljit_sw);
1427        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1428        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1429        setsom_found = TRUE;        setsom_found = TRUE;
1430        }        }
1431      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      if (common->mark_ptr != 0 && !setmark_found)
1432          {
1433          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1434          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1435          stackpos += (int)sizeof(sljit_sw);
1436          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1437          stackpos += (int)sizeof(sljit_sw);
1438          setmark_found = TRUE;
1439          }
1440        if (common->capture_last_ptr != 0 && !capture_last_found)
1441          {
1442          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1443          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1444          stackpos += (int)sizeof(sljit_sw);
1445          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1446          stackpos += (int)sizeof(sljit_sw);
1447          capture_last_found = TRUE;
1448          }
1449        cc += 1 + LINK_SIZE;
1450      break;      break;
1451    
1452      case OP_CBRA:      case OP_CBRA:
1453      case OP_CBRAPOS:      case OP_CBRAPOS:
1454      case OP_SCBRA:      case OP_SCBRA:
1455      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1456        if (common->capture_last_ptr != 0 && !capture_last_found)
1457          {
1458          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1459          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1460          stackpos += (int)sizeof(sljit_sw);
1461          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1462          stackpos += (int)sizeof(sljit_sw);
1463          capture_last_found = TRUE;
1464          }
1465      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1466      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1467      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1468      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1469      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));
1470      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1471      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1472      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1473      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1474    
1475      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1476      break;      break;
# Line 839  while (cc < ccend) Line 1481  while (cc < ccend)
1481      break;      break;
1482      }      }
1483    
1484  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1485  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1486  }  }
1487    
1488  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)
1489  {  {
1490  int localsize = 2;  int private_data_length = needs_control_head ? 3 : 2;
1491    int size;
1492  pcre_uchar *alternative;  pcre_uchar *alternative;
1493  /* Calculate the sum of the local variables. */  /* Calculate the sum of the private machine words. */
1494  while (cc < ccend)  while (cc < ccend)
1495    {    {
1496      size = 0;
1497    switch(*cc)    switch(*cc)
1498      {      {
1499        case OP_KET:
1500        if (PRIVATE_DATA(cc) != 0)
1501          private_data_length++;
1502        cc += 1 + LINK_SIZE;
1503        break;
1504    
1505      case OP_ASSERT:      case OP_ASSERT:
1506      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1507      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 862  while (cc < ccend) Line 1512  while (cc < ccend)
1512      case OP_SBRA:      case OP_SBRA:
1513      case OP_SBRAPOS:      case OP_SBRAPOS:
1514      case OP_SCOND:      case OP_SCOND:
1515      localsize++;      private_data_length++;
1516      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1517      break;      break;
1518    
1519      case OP_CBRA:      case OP_CBRA:
1520      case OP_SCBRA:      case OP_SCBRA:
1521      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1522          private_data_length++;
1523      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1524      break;      break;
1525    
1526      case OP_CBRAPOS:      case OP_CBRAPOS:
1527      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1528      localsize += 2;      private_data_length += 2;
1529      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1530      break;      break;
1531    
# Line 882  while (cc < ccend) Line 1533  while (cc < ccend)
1533      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1534      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1535      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1536        localsize++;        private_data_length++;
1537      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1538      break;      break;
1539    
1540        CASE_ITERATOR_PRIVATE_DATA_1
1541        if (PRIVATE_DATA(cc))
1542          private_data_length++;
1543        cc += 2;
1544    #ifdef SUPPORT_UTF
1545        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1546    #endif
1547        break;
1548    
1549        CASE_ITERATOR_PRIVATE_DATA_2A
1550        if (PRIVATE_DATA(cc))
1551          private_data_length += 2;
1552        cc += 2;
1553    #ifdef SUPPORT_UTF
1554        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1555    #endif
1556        break;
1557    
1558        CASE_ITERATOR_PRIVATE_DATA_2B
1559        if (PRIVATE_DATA(cc))
1560          private_data_length += 2;
1561        cc += 2 + IMM2_SIZE;
1562    #ifdef SUPPORT_UTF
1563        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1564    #endif
1565        break;
1566    
1567        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1568        if (PRIVATE_DATA(cc))
1569          private_data_length++;
1570        cc += 1;
1571        break;
1572    
1573        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1574        if (PRIVATE_DATA(cc))
1575          private_data_length += 2;
1576        cc += 1;
1577        break;
1578    
1579        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1580        if (PRIVATE_DATA(cc))
1581          private_data_length += 2;
1582        cc += 1 + IMM2_SIZE;
1583        break;
1584    
1585        case OP_CLASS:
1586        case OP_NCLASS:
1587    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1588        case OP_XCLASS:
1589        size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1590    #else
1591        size = 1 + 32 / (int)sizeof(pcre_uchar);
1592    #endif
1593        if (PRIVATE_DATA(cc))
1594          private_data_length += get_class_iterator_size(cc + size);
1595        cc += size;
1596        break;
1597    
1598      default:      default:
1599      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1600      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
# Line 893  while (cc < ccend) Line 1602  while (cc < ccend)
1602      }      }
1603    }    }
1604  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1605  return localsize;  return private_data_length;
1606  }  }
1607    
1608  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,
1609    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1610  {  {
1611  DEFINE_COMPILER;  DEFINE_COMPILER;
1612  int srcw[2];  int srcw[2];
1613  int count;  int count, size;
1614  BOOL tmp1next = TRUE;  BOOL tmp1next = TRUE;
1615  BOOL tmp1empty = TRUE;  BOOL tmp1empty = TRUE;
1616  BOOL tmp2empty = TRUE;  BOOL tmp2empty = TRUE;
# Line 918  stacktop = STACK(stacktop - 1); Line 1627  stacktop = STACK(stacktop - 1);
1627    
1628  if (!save)  if (!save)
1629    {    {
1630    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1631    if (stackptr < stacktop)    if (stackptr < stacktop)
1632      {      {
1633      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1634      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1635      tmp1empty = FALSE;      tmp1empty = FALSE;
1636      }      }
1637    if (stackptr < stacktop)    if (stackptr < stacktop)
1638      {      {
1639      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1640      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1641      tmp2empty = FALSE;      tmp2empty = FALSE;
1642      }      }
1643    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1644    }    }
1645    
1646  while (status != end)  do
1647    {    {
1648    count = 0;    count = 0;
1649    switch(status)    switch(status)
1650      {      {
1651      case start:      case start:
1652      SLJIT_ASSERT(save);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1653      count = 1;      count = 1;
1654      srcw[0] = RECURSIVE_HEAD;      srcw[0] = common->recursive_head_ptr;
1655        if (needs_control_head)
1656          {
1657          SLJIT_ASSERT(common->control_head_ptr != 0);
1658          count = 2;
1659          srcw[1] = common->control_head_ptr;
1660          }
1661      status = loop;      status = loop;
1662      break;      break;
1663    
# Line 955  while (status != end) Line 1670  while (status != end)
1670    
1671      switch(*cc)      switch(*cc)
1672        {        {
1673          case OP_KET:
1674          if (PRIVATE_DATA(cc) != 0)
1675            {
1676            count = 1;
1677            srcw[0] = PRIVATE_DATA(cc);
1678            }
1679          cc += 1 + LINK_SIZE;
1680          break;
1681    
1682        case OP_ASSERT:        case OP_ASSERT:
1683        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1684        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 966  while (status != end) Line 1690  while (status != end)
1690        case OP_SBRAPOS:        case OP_SBRAPOS:
1691        case OP_SCOND:        case OP_SCOND:
1692        count = 1;        count = 1;
1693        srcw[0] = PRIV_DATA(cc);        srcw[0] = PRIVATE_DATA(cc);
1694        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1695        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1696        break;        break;
1697    
1698        case OP_CBRA:        case OP_CBRA:
1699        case OP_SCBRA:        case OP_SCBRA:
1700        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1701        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1702            count = 1;
1703            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1704            }
1705        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1706        break;        break;
1707    
1708        case OP_CBRAPOS:        case OP_CBRAPOS:
1709        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1710        count = 2;        count = 2;
1711          srcw[0] = PRIVATE_DATA(cc);
1712        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1713        srcw[0] = PRIV_DATA(cc);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
       SLJIT_ASSERT(srcw[0] != 0);  
1714        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1715        break;        break;
1716    
# Line 993  while (status != end) Line 1720  while (status != end)
1720        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1721          {          {
1722          count = 1;          count = 1;
1723          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1724          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1725          }          }
1726        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1727        break;        break;
1728    
1729          CASE_ITERATOR_PRIVATE_DATA_1
1730          if (PRIVATE_DATA(cc))
1731            {
1732            count = 1;
1733            srcw[0] = PRIVATE_DATA(cc);
1734            }
1735          cc += 2;
1736    #ifdef SUPPORT_UTF
1737          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1738    #endif
1739          break;
1740    
1741          CASE_ITERATOR_PRIVATE_DATA_2A
1742          if (PRIVATE_DATA(cc))
1743            {
1744            count = 2;
1745            srcw[0] = PRIVATE_DATA(cc);
1746            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1747            }
1748          cc += 2;
1749    #ifdef SUPPORT_UTF
1750          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1751    #endif
1752          break;
1753    
1754          CASE_ITERATOR_PRIVATE_DATA_2B
1755          if (PRIVATE_DATA(cc))
1756            {
1757            count = 2;
1758            srcw[0] = PRIVATE_DATA(cc);
1759            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1760            }
1761          cc += 2 + IMM2_SIZE;
1762    #ifdef SUPPORT_UTF
1763          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1764    #endif
1765          break;
1766    
1767          CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1768          if (PRIVATE_DATA(cc))
1769            {
1770            count = 1;
1771            srcw[0] = PRIVATE_DATA(cc);
1772            }
1773          cc += 1;
1774          break;
1775    
1776          CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1777          if (PRIVATE_DATA(cc))
1778            {
1779            count = 2;
1780            srcw[0] = PRIVATE_DATA(cc);
1781            srcw[1] = srcw[0] + sizeof(sljit_sw);
1782            }
1783          cc += 1;
1784          break;
1785    
1786          CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1787          if (PRIVATE_DATA(cc))
1788            {
1789            count = 2;
1790            srcw[0] = PRIVATE_DATA(cc);
1791            srcw[1] = srcw[0] + sizeof(sljit_sw);
1792            }
1793          cc += 1 + IMM2_SIZE;
1794          break;
1795    
1796          case OP_CLASS:
1797          case OP_NCLASS:
1798    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1799          case OP_XCLASS:
1800          size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1801    #else
1802          size = 1 + 32 / (int)sizeof(pcre_uchar);
1803    #endif
1804          if (PRIVATE_DATA(cc))
1805            switch(get_class_iterator_size(cc + size))
1806              {
1807              case 1:
1808              count = 1;
1809              srcw[0] = PRIVATE_DATA(cc);
1810              break;
1811    
1812              case 2:
1813              count = 2;
1814              srcw[0] = PRIVATE_DATA(cc);
1815              srcw[1] = srcw[0] + sizeof(sljit_sw);
1816              break;
1817    
1818              default:
1819              SLJIT_ASSERT_STOP();
1820              break;
1821              }
1822          cc += size;
1823          break;
1824    
1825        default:        default:
1826        cc = next_opcode(common, cc);        cc = next_opcode(common, cc);
1827        SLJIT_ASSERT(cc != NULL);        SLJIT_ASSERT(cc != NULL);
# Line 1021  while (status != end) Line 1844  while (status != end)
1844          if (!tmp1empty)          if (!tmp1empty)
1845            {            {
1846            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1847            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1848            }            }
1849          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1850          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1032  while (status != end) Line 1855  while (status != end)
1855          if (!tmp2empty)          if (!tmp2empty)
1856            {            {
1857            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1858            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1859            }            }
1860          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1861          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1049  while (status != end) Line 1872  while (status != end)
1872          if (!tmp1empty)          if (!tmp1empty)
1873            {            {
1874            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1875            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1876            }            }
1877          tmp1next = FALSE;          tmp1next = FALSE;
1878          }          }
# Line 1061  while (status != end) Line 1884  while (status != end)
1884          if (!tmp2empty)          if (!tmp2empty)
1885            {            {
1886            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1887            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1888            }            }
1889          tmp1next = TRUE;          tmp1next = TRUE;
1890          }          }
1891        }        }
1892      }      }
1893    }    }
1894    while (status != end);
1895    
1896  if (save)  if (save)
1897    {    {
# Line 1076  if (save) Line 1900  if (save)
1900      if (!tmp1empty)      if (!tmp1empty)
1901        {        {
1902        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1903        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1904        }        }
1905      if (!tmp2empty)      if (!tmp2empty)
1906        {        {
1907        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1908        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1909        }        }
1910      }      }
1911    else    else
# Line 1089  if (save) Line 1913  if (save)
1913      if (!tmp2empty)      if (!tmp2empty)
1914        {        {
1915        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1916        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1917        }        }
1918      if (!tmp1empty)      if (!tmp1empty)
1919        {        {
1920        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1921        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1922        }        }
1923      }      }
1924    }    }
1925  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1926  }  }
1927    
1928  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1929    {
1930    pcre_uchar *end = bracketend(cc);
1931    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1932    
1933    /* Assert captures then. */
1934    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1935      current_offset = NULL;
1936    /* Conditional block does not. */
1937    if (*cc == OP_COND || *cc == OP_SCOND)
1938      has_alternatives = FALSE;
1939    
1940    cc = next_opcode(common, cc);
1941    if (has_alternatives)
1942      current_offset = common->then_offsets + (cc - common->start);
1943    
1944    while (cc < end)
1945      {
1946      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1947        cc = set_then_offsets(common, cc, current_offset);
1948      else
1949        {
1950        if (*cc == OP_ALT && has_alternatives)
1951          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1952        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1953          *current_offset = 1;
1954        cc = next_opcode(common, cc);
1955        }
1956      }
1957    
1958    return end;
1959    }
1960    
1961    #undef CASE_ITERATOR_PRIVATE_DATA_1
1962    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1963    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1964    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1965    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1966    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1967    
1968    static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1969  {  {
1970  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1971  }  }
# Line 1111  static SLJIT_INLINE void set_jumps(jump_ Line 1975  static SLJIT_INLINE void set_jumps(jump_
1975  while (list)  while (list)
1976    {    {
1977    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1978    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1979    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1980    list = list->next;    list = list->next;
1981    }    }
1982  }  }
# Line 1128  if (list_item) Line 1992  if (list_item)
1992    }    }
1993  }  }
1994    
1995  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)
1996  {  {
1997  DEFINE_COMPILER;  DEFINE_COMPILER;
1998  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1999    
2000  if (list_item)  if (list_item)
2001    {    {
   list_item->type = type;  
   list_item->data = data;  
2002    list_item->start = start;    list_item->start = start;
2003    list_item->leave = LABEL();    list_item->quit = LABEL();
2004    list_item->next = common->stubs;    list_item->next = common->stubs;
2005    common->stubs = list_item;    common->stubs = list_item;
2006    }    }
# Line 1152  stub_list* list_item = common->stubs; Line 2014  stub_list* list_item = common->stubs;
2014  while (list_item)  while (list_item)
2015    {    {
2016    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2017    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
2018      {    JUMPTO(SLJIT_JUMP, list_item->quit);
     case stack_alloc:  
     add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));  
     break;  
     }  
   JUMPTO(SLJIT_JUMP, list_item->leave);  
2019    list_item = list_item->next;    list_item = list_item->next;
2020    }    }
2021  common->stubs = NULL;  common->stubs = NULL;
# Line 1177  static SLJIT_INLINE void allocate_stack( Line 2034  static SLJIT_INLINE void allocate_stack(
2034  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2035  DEFINE_COMPILER;  DEFINE_COMPILER;
2036    
2037  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));
2038  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2039  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2040  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1185  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 2042  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2042  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2043  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2044  #endif  #endif
2045  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));
2046  }  }
2047    
2048  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2049  {  {
2050  DEFINE_COMPILER;  DEFINE_COMPILER;
2051  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));
2052  }  }
2053    
2054  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1199  static SLJIT_INLINE void reset_ovector(c Line 2056  static SLJIT_INLINE void reset_ovector(c
2056  DEFINE_COMPILER;  DEFINE_COMPILER;
2057  struct sljit_label *loop;  struct sljit_label *loop;
2058  int i;  int i;
2059    
2060  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2061    SLJIT_ASSERT(length > 1);
2062  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2063  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_GENERAL_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));
2064    if (length < 8)
2065      {
2066      for (i = 1; i < length; i++)
2067        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2068      }
2069    else
2070      {
2071      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2072      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2073      loop = LABEL();
2074      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2075      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2076      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2077      }
2078    }
2079    
2080    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2081    {
2082    DEFINE_COMPILER;
2083    struct sljit_label *loop;
2084    int i;
2085    
2086    SLJIT_ASSERT(length > 1);
2087    /* OVECTOR(1) contains the "string begin - 1" constant. */
2088    if (length > 2)
2089      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2090  if (length < 8)  if (length < 8)
2091    {    {
2092    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
2093      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);
2094    }    }
2095  else  else
2096    {    {
2097    OP2(SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2098    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2099    loop = LABEL();    loop = LABEL();
2100    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);
2101    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);
2102    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2103    }    }
2104    
2105    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2106    if (common->mark_ptr != 0)
2107      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2108    if (common->control_head_ptr != 0)
2109      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2110    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2111    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2112    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2113    }
2114    
2115    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2116    {
2117    while (current != NULL)
2118      {
2119      switch (current[-2])
2120        {
2121        case type_then_trap:
2122        break;
2123    
2124        case type_mark:
2125        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2126          return current[-4];
2127        break;
2128    
2129        default:
2130        SLJIT_ASSERT_STOP();
2131        break;
2132        }
2133      current = (sljit_sw*)current[-1];
2134      }
2135    return -1;
2136  }  }
2137    
2138  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2139  {  {
2140  DEFINE_COMPILER;  DEFINE_COMPILER;
2141  struct sljit_label *loop;  struct sljit_label *loop;
2142  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2143    
2144  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2145  OP1(SLJIT_MOV, SLJIT_GENERAL_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2146  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);
2147    
2148  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2149  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));  if (common->mark_ptr != 0)
2150  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
2151  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offset_count));
2152  OP2(SLJIT_ADD, SLJIT_GENERAL_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START);  if (common->mark_ptr != 0)
2153      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);
2154    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
2155    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));
2156    GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2157  /* Unlikely, but possible */  /* Unlikely, but possible */
2158  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);
2159  loop = LABEL();  loop = LABEL();
2160  OP2(SLJIT_SUB, SLJIT_GENERAL_REG2, 0, SLJIT_MEM1(SLJIT_GENERAL_REG1), 0, SLJIT_TEMPORARY_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
2161  OP2(SLJIT_ADD, SLJIT_GENERAL_REG1, 0, SLJIT_GENERAL_REG1, 0, SLJIT_IMM, sizeof(sljit_w));  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));
2162  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2163  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2164  OP2(SLJIT_ASHR, SLJIT_GENERAL_REG2, 0, SLJIT_GENERAL_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2165  #endif  #endif
2166  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), sizeof(int), SLJIT_GENERAL_REG2, 0);  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);
2167  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);
2168  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2169  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2170    
2171  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2172  if (topbracket > 1)  if (topbracket > 1)
2173    {    {
2174    OP2(SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START + topbracket * 2 * sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));
2175    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2176    
2177    /* OVECTOR(0) is never equal to SLJIT_GENERAL_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2178    loop = LABEL();    loop = LABEL();
2179    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)));
2180    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);
2181    CMPTO(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG3, 0, SLJIT_GENERAL_REG3, 0, loop);    CMPTO(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG3, 0, loop);
2182    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2183    }    }
2184  else  else
2185    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
2186  }  }
2187    
2188    static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)
2189    {
2190    DEFINE_COMPILER;
2191    struct sljit_jump *jump;
2192    
2193    SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);
2194    SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0
2195      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2196    
2197    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2198    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2199    OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, real_offset_count));
2200    CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
2201    
2202    /* Store match begin and end. */
2203    OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));
2204    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));
2205    
2206    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2207    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);
2208    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2209    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2210    #endif
2211    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2212    JUMPHERE(jump);
2213    
2214    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);
2215    OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);
2216    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2217    OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2218    #endif
2219    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);
2220    
2221    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG1, 0);
2222    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2223    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2224    #endif
2225    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0, SLJIT_SCRATCH_REG3, 0);
2226    
2227    JUMPTO(SLJIT_JUMP, quit);
2228    }
2229    
2230    static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)
2231    {
2232    /* May destroy TMP1. */
2233    DEFINE_COMPILER;
2234    struct sljit_jump *jump;
2235    
2236    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2237      {
2238      /* The value of -1 must be kept for start_used_ptr! */
2239      OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, 1);
2240      /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting
2241      is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */
2242      jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, STR_PTR, 0);
2243      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2244      JUMPHERE(jump);
2245      }
2246    else if (common->mode == JIT_PARTIAL_HARD_COMPILE)
2247      {
2248      jump = CMP(SLJIT_C_LESS_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2249      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2250      JUMPHERE(jump);
2251      }
2252    }
2253    
2254  static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar* cc)  static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar* cc)
2255  {  {
2256  /* Detects if the character has an othercase. */  /* Detects if the character has an othercase. */
# Line 1348  if (c <= 127 && bit == 0x20) Line 2335  if (c <= 127 && bit == 0x20)
2335    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2336    
2337  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2338  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2339    return 0;    return 0;
2340    
2341  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2342    
2343  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2344  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 1367  if (common->utf && c > 127) Line 2354  if (common->utf && c > 127)
2354  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2355  return (0 << 8) | bit;  return (0 << 8) | bit;
2356    
2357  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2358    
 #ifdef COMPILE_PCRE16  
2359  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2360  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2361    {    {
# Line 1380  if (common->utf && c > 65535) Line 2366  if (common->utf && c > 65535)
2366    }    }
2367  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2368  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2369    
2370  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2371    }
2372    
2373    static void check_partial(compiler_common *common, BOOL force)
2374    {
2375    /* Checks whether a partial matching is occured. Does not modify registers. */
2376    DEFINE_COMPILER;
2377    struct sljit_jump *jump = NULL;
2378    
2379    SLJIT_ASSERT(!force || common->mode != JIT_COMPILE);
2380    
2381    if (common->mode == JIT_COMPILE)
2382      return;
2383    
2384    if (!force)
2385      jump = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2386    else if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2387      jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2388    
2389    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2390      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2391    else
2392      {
2393      if (common->partialmatchlabel != NULL)
2394        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2395      else
2396        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2397      }
2398    
2399    if (jump != NULL)
2400      JUMPHERE(jump);
2401    }
2402    
2403    static void check_str_end(compiler_common *common, jump_list **end_reached)
2404    {
2405    /* Does not affect registers. Usually used in a tight spot. */
2406    DEFINE_COMPILER;
2407    struct sljit_jump *jump;
2408    
2409    if (common->mode == JIT_COMPILE)
2410      {
2411      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2412      return;
2413      }
2414    
2415    jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2416    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2417      {
2418      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2419      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2420      add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
2421      }
2422    else
2423      {
2424      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2425      if (common->partialmatchlabel != NULL)
2426        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2427      else
2428        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2429      }
2430    JUMPHERE(jump);
2431  }  }
2432    
2433  static SLJIT_INLINE void check_input_end(compiler_common *common, jump_list **fallbacks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
2434  {  {
2435  DEFINE_COMPILER;  DEFINE_COMPILER;
2436  add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));  struct sljit_jump *jump;
2437    
2438    if (common->mode == JIT_COMPILE)
2439      {
2440      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2441      return;
2442      }
2443    
2444    /* Partial matching mode. */
2445    jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2446    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2447    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2448      {
2449      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2450      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2451      }
2452    else
2453      {
2454      if (common->partialmatchlabel != NULL)
2455        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2456      else
2457        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2458      }
2459    JUMPHERE(jump);
2460  }  }
2461    
2462  static void read_char(compiler_common *common)  static void read_char(compiler_common *common)
# Line 1396  static void read_char(compiler_common *c Line 2464  static void read_char(compiler_common *c
2464  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2465  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2466  DEFINE_COMPILER;  DEFINE_COMPILER;
2467  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2468  struct sljit_jump *jump;  struct sljit_jump *jump;
2469  #endif  #endif
2470    
2471  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2472  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2473  if (common->utf)  if (common->utf)
2474    {    {
2475  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2476    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2477  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2478    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2479  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2480    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2481    JUMPHERE(jump);    JUMPHERE(jump);
2482    }    }
2483  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2484  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));
2485  }  }
2486    
# Line 1423  static void peek_char(compiler_common *c Line 2489  static void peek_char(compiler_common *c
2489  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2490  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2491  DEFINE_COMPILER;  DEFINE_COMPILER;
2492  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2493  struct sljit_jump *jump;  struct sljit_jump *jump;
2494  #endif  #endif
2495    
2496  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2497  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2498  if (common->utf)  if (common->utf)
2499    {    {
2500  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2501    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2502  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2503    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2504  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2505    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2506    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2507    JUMPHERE(jump);    JUMPHERE(jump);
2508    }    }
2509  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2510  }  }
2511    
2512  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2513  {  {
2514  /* 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. */
2515  DEFINE_COMPILER;  DEFINE_COMPILER;
2516  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2517  struct sljit_jump *jump;  struct sljit_jump *jump;
2518  #endif  #endif
2519    
# Line 1458  if (common->utf) Line 2522  if (common->utf)
2522    {    {
2523    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2524    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));
2525  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2526    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2527    it is needed in most cases. */    it is needed in most cases. */
2528    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2529    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2530    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2531    JUMPHERE(jump);    JUMPHERE(jump);
2532  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2533    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2534    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2535    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
# Line 1474  if (common->utf) Line 2537  if (common->utf)
2537    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2538    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2539    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2540    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2541    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2542    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2543  #endif  #elif defined COMPILE_PCRE32
2544  #endif /* COMPILE_PCRE8 */    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2545      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2546      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2547      JUMPHERE(jump);
2548    #endif /* COMPILE_PCRE[8|16|32] */
2549    return;    return;
2550    }    }
2551  #endif  #endif /* SUPPORT_UTF */
2552  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2553  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));
2554  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2555  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2556  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2557  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2558  #endif  #endif
2559  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2560  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2561  JUMPHERE(jump);  JUMPHERE(jump);
2562  #endif  #endif
2563  }  }
# Line 1499  static void skip_char_back(compiler_comm Line 2566  static void skip_char_back(compiler_comm
2566  {  {
2567  /* 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. */
2568  DEFINE_COMPILER;  DEFINE_COMPILER;
2569  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2570    #if defined COMPILE_PCRE8
2571  struct sljit_label *label;  struct sljit_label *label;
2572    
2573  if (common->utf)  if (common->utf)
# Line 1511  if (common->utf) Line 2579  if (common->utf)
2579    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2580    return;    return;
2581    }    }
2582  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2583  if (common->utf)  if (common->utf)
2584    {    {
2585    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 1520  if (common->utf) Line 2587  if (common->utf)
2587    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2588    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2589    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);
2590    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2591    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2592    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2593    return;    return;
2594    }    }
2595  #endif  #endif /* COMPILE_PCRE[8|16] */
2596    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2597  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));
2598  }  }
2599    
2600  static void check_newlinechar(compiler_common *common, int nltype, jump_list **fallbacks, BOOL jumpiftrue)  static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpiftrue)
2601  {  {
2602  /* 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. */
2603  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1537  DEFINE_COMPILER; Line 2605  DEFINE_COMPILER;
2605  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2606    {    {
2607    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2608    add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2609    }    }
2610  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2611    {    {
2612    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);
2613    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2614    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);
2615    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);
2616    add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2617    }    }
2618  else  else
2619    {    {
2620    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2621    add_jump(compiler, fallbacks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));    add_jump(compiler, backtracks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
2622    }    }
2623  }  }
2624    
2625  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2626    
2627  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2628  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2629  {  {
2630  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
# Line 1564  of the character (>= 0xc0). Return char Line 2632  of the character (>= 0xc0). Return char
2632  DEFINE_COMPILER;  DEFINE_COMPILER;
2633  struct sljit_jump *jump;  struct sljit_jump *jump;
2634    
2635  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2636  /* Searching for the first zero. */  /* Searching for the first zero. */
2637  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, 0x20);
2638  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
# Line 1623  DEFINE_COMPILER; Line 2691  DEFINE_COMPILER;
2691  struct sljit_jump *jump;  struct sljit_jump *jump;
2692  struct sljit_jump *compare;  struct sljit_jump *compare;
2693    
2694  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2695    
2696  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20);
2697  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
# Line 1644  sljit_emit_fast_return(compiler, RETURN_ Line 2712  sljit_emit_fast_return(compiler, RETURN_
2712  JUMPHERE(jump);  JUMPHERE(jump);
2713    
2714  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2715  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(utf8_table4) - 0xc0);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2716  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2717  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2718  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2719  }  }
2720    
2721  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
2722    
 #ifdef COMPILE_PCRE16  
2723  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2724  {  {
2725  /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char  /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char
# Line 1660  of the character (>= 0xd800). Return cha Line 2727  of the character (>= 0xd800). Return cha
2727  DEFINE_COMPILER;  DEFINE_COMPILER;
2728  struct sljit_jump *jump;  struct sljit_jump *jump;
2729    
2730  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2731  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);
2732  /* Do nothing, only return. */  /* Do nothing, only return. */
2733  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
# Line 1677  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC Line 2744  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC
2744  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2745  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2746  }  }
 #endif /* COMPILE_PCRE16 */  
2747    
2748  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16] */
2749    
2750  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2751    
# Line 1697  DEFINE_COMPILER; Line 2763  DEFINE_COMPILER;
2763    
2764  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);
2765    
2766  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2767  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2768  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));
2769  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2770  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2771  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2772  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2773  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2774  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));
2775  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2776  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2777  }  }
# Line 1719  struct sljit_label *newlinelabel = NULL; Line 2785  struct sljit_label *newlinelabel = NULL;
2785  struct sljit_jump *start;  struct sljit_jump *start;
2786  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2787  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2788  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2789  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2790  #endif  #endif
2791  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 1733  if (!(hascrorlf || firstline) && (common Line 2799  if (!(hascrorlf || firstline) && (common
2799  if (firstline)  if (firstline)
2800    {    {
2801    /* Search for the end of the first line. */    /* Search for the end of the first line. */
2802    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2803    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
2804    
2805      if (common->nltype == NLTYPE_FIXED && common->newline > 255)
2806        {
2807        mainloop = LABEL();
2808        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2809        end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2810        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
2811        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2812        CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);
2813        CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);
2814        JUMPHERE(end);
2815        OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2816        }
2817      else
2818        {
2819        end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2820        mainloop = LABEL();
2821        /* Continual stores does not cause data dependency. */
2822        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2823        read_char(common);
2824        check_newlinechar(common, common->nltype, &newline, TRUE);
2825        CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2826        JUMPHERE(end);
2827        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2828        set_jumps(newline, LABEL());
2829        }
2830    
2831      OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
2832      }
2833    
2834    start = JUMP(SLJIT_JUMP);
2835    
2836    if (newlinecheck)
2837      {
2838      newlinelabel = LABEL();
2839      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2840      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2841      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2842      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);
2843      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2844    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2845      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2846    #endif
2847      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2848      nl = JUMP(SLJIT_JUMP);
2849      }
2850    
2851    mainloop = LABEL();
2852    
2853    /* Increasing the STR_PTR here requires one less jump in the most common case. */
2854    #ifdef SUPPORT_UTF
2855    if (common->utf) readuchar = TRUE;
2856    #endif
2857    if (newlinecheck) readuchar = TRUE;
2858    
2859    if (readuchar)
2860      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2861    
2862    if (newlinecheck)
2863      CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);
2864    
2865    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2866    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2867    #if defined COMPILE_PCRE8
2868    if (common->utf)
2869      {
2870      singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2871      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2872      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2873      JUMPHERE(singlechar);
2874      }
2875    #elif defined COMPILE_PCRE16
2876    if (common->utf)
2877      {
2878      singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2879      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2880      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2881      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2882      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2883      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2884      JUMPHERE(singlechar);
2885      }
2886    #endif /* COMPILE_PCRE[8|16] */
2887    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2888    JUMPHERE(start);
2889    
2890    if (newlinecheck)
2891      {
2892      JUMPHERE(end);
2893      JUMPHERE(nl);
2894      }
2895    
2896    return mainloop;
2897    }
2898    
2899    #define MAX_N_CHARS 3
2900    
2901    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2902    {
2903    DEFINE_COMPILER;
2904    struct sljit_label *start;
2905    struct sljit_jump *quit;
2906    pcre_uint32 chars[MAX_N_CHARS * 2];
2907    pcre_uchar *cc = common->start + 1 + LINK_SIZE;
2908    int location = 0;
2909    pcre_int32 len, c, bit, caseless;
2910    int must_stop;
2911    
2912    /* We do not support alternatives now. */
2913    if (*(common->start + GET(common->start, 1)) == OP_ALT)
2914      return FALSE;
2915    
2916    while (TRUE)
2917      {
2918      caseless = 0;
2919      must_stop = 1;
2920      switch(*cc)
2921        {
2922        case OP_CHAR:
2923        must_stop = 0;
2924        cc++;
2925        break;
2926    
2927        case OP_CHARI:
2928        caseless = 1;
2929        must_stop = 0;
2930        cc++;
2931        break;
2932    
2933        case OP_SOD:
2934        case OP_SOM:
2935        case OP_SET_SOM:
2936        case OP_NOT_WORD_BOUNDARY:
2937        case OP_WORD_BOUNDARY:
2938        case OP_EODN:
2939        case OP_EOD:
2940        case OP_CIRC:
2941        case OP_CIRCM:
2942        case OP_DOLL:
2943        case OP_DOLLM:
2944        /* Zero width assertions. */
2945        cc++;
2946        continue;
2947    
2948        case OP_PLUS:
2949        case OP_MINPLUS:
2950        case OP_POSPLUS:
2951        cc++;
2952        break;
2953    
2954        case OP_EXACT:
2955        cc += 1 + IMM2_SIZE;
2956        break;
2957    
2958        case OP_PLUSI:
2959        case OP_MINPLUSI:
2960        case OP_POSPLUSI:
2961        caseless = 1;
2962        cc++;
2963        break;
2964    
2965        case OP_EXACTI:
2966        caseless = 1;
2967        cc += 1 + IMM2_SIZE;
2968        break;
2969    
2970        default:
2971        must_stop = 2;
2972        break;
2973        }
2974    
2975      if (must_stop == 2)
2976          break;
2977    
2978      len = 1;
2979    #ifdef SUPPORT_UTF
2980      if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
2981    #endif
2982    
2983    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (caseless && char_has_othercase(common, cc))
2984      {      {
2985      mainloop = LABEL();      caseless = char_get_othercase_bit(common, cc);
2986      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));      if (caseless == 0)
2987      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);        return FALSE;
2988      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));  #ifdef COMPILE_PCRE8
2989      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
2990      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);  #else
2991      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);      if ((caseless & 0x100) != 0)
2992      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));        caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));
2993        else
2994          caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));
2995    #endif
2996      }      }
2997    else    else
2998        caseless = 0;
2999    
3000      while (len > 0 && location < MAX_N_CHARS * 2)
3001      {      {
3002      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      c = *cc;
3003      mainloop = LABEL();      bit = 0;
3004      /* Continual stores does not cause data dependency. */      if (len == (caseless & 0xff))
3005      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);        {
3006      read_char(common);        bit = caseless >> 8;
3007      check_newlinechar(common, common->nltype, &newline, TRUE);        c |= bit;
3008      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);        }
3009      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);  
3010      set_jumps(newline, LABEL());      chars[location] = c;
3011        chars[location + 1] = bit;
3012    
3013        len--;
3014        location += 2;
3015        cc++;
3016      }      }
3017    
3018    JUMPHERE(end);    if (location >= MAX_N_CHARS * 2 || must_stop != 0)
3019    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);      break;
3020    }    }
3021    
3022  start = JUMP(SLJIT_JUMP);  /* At least two characters are required. */
3023    if (location < 2 * 2)
3024        return FALSE;
3025    
3026  if (newlinecheck)  if (firstline)
3027    {    {
3028    newlinelabel = LABEL();    SLJIT_ASSERT(common->first_line_end != 0);
3029    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3030    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
   OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);  
   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);  
 #ifdef COMPILE_PCRE16  
   OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  
 #endif  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   nl = JUMP(SLJIT_JUMP);  
3031    }    }
3032    else
3033      OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
3034    
3035  mainloop = LABEL();  start = LABEL();
3036    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 /* Increasing the STR_PTR here requires one less jump in the most common case. */  
 #ifdef SUPPORT_UTF  
 if (common->utf) readuchar = TRUE;  
 #endif  
 if (newlinecheck) readuchar = TRUE;  
   
 if (readuchar)  
   OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
   
 if (newlinecheck)  
   CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);  
3037    
3038    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
3039    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3040  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));
3041  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  if (chars[1] != 0)
3042  if (common->utf)    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3043    {  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3044    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);  if (location > 2 * 2)
3045    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3046    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  if (chars[3] != 0)
3047    JUMPHERE(singlechar);    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
3048    }  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
3049  #endif  if (location > 2 * 2)
3050  #if defined SUPPORT_UTF && defined COMPILE_PCRE16    {
3051  if (common->utf)    if (chars[5] != 0)
3052    {      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
3053    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);
   OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);  
   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);  
   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);  
   OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   JUMPHERE(singlechar);  
3054    }    }
3055  #endif  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 JUMPHERE(start);  
3056    
3057  if (newlinecheck)  JUMPHERE(quit);
   {  
   JUMPHERE(end);  
   JUMPHERE(nl);  
   }  
3058    
3059  return mainloop;  if (firstline)
3060      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3061    else
3062      OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
3063    return TRUE;
3064  }  }
3065    
3066    #undef MAX_N_CHARS
3067    
3068  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)
3069  {  {
3070  DEFINE_COMPILER;  DEFINE_COMPILER;
3071  struct sljit_label *start;  struct sljit_label *start;
3072  struct sljit_jump *leave;  struct sljit_jump *quit;
3073  struct sljit_jump *found;  struct sljit_jump *found;
3074  pcre_uchar oc, bit;  pcre_uchar oc, bit;
3075    
3076  if (firstline)  if (firstline)
3077    {    {
3078    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3079    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3080      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3081    }    }
3082    
3083  start = LABEL();  start = LABEL();
3084  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3085  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3086    
3087  oc = first_char;  oc = first_char;
# Line 1860  if (first_char == oc) Line 3098  if (first_char == oc)
3098  else  else
3099    {    {
3100    bit = first_char ^ oc;    bit = first_char ^ oc;
3101    if (ispowerof2(bit))    if (is_powerof2(bit))
3102      {      {
3103      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3104      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 1868  else Line 3106  else
3106    else    else
3107      {      {
3108      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);
3109      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3110      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);
3111      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);
3112      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3113      }      }
3114    }    }
3115    
3116  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 #if defined SUPPORT_UTF && defined COMPILE_PCRE8  
 if (common->utf)  
   {  
   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   }  
 #endif  
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
 if (common->utf)  
   {  
   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);  
   OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);  
   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);  
   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);  
   OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   }  
 #endif  
3117  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3118  JUMPHERE(found);  JUMPHERE(found);
3119  JUMPHERE(leave);  JUMPHERE(quit);
3120    
3121  if (firstline)  if (firstline)
3122    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3123  }  }
3124    
3125  static SLJIT_INLINE void fast_forward_newline(compiler_common *common, BOOL firstline)  static SLJIT_INLINE void fast_forward_newline(compiler_common *common, BOOL firstline)
# Line 1909  DEFINE_COMPILER; Line 3128  DEFINE_COMPILER;
3128  struct sljit_label *loop;  struct sljit_label *loop;
3129  struct sljit_jump *lastchar;  struct sljit_jump *lastchar;
3130  struct sljit_jump *firstchar;  struct sljit_jump *firstchar;
3131  struct sljit_jump *leave;  struct sljit_jump *quit;
3132  struct sljit_jump *foundcr = NULL;  struct sljit_jump *foundcr = NULL;
3133  struct sljit_jump *notfoundnl;  struct sljit_jump *notfoundnl;
3134  jump_list *newline = NULL;  jump_list *newline = NULL;
3135    
3136  if (firstline)  if (firstline)
3137    {    {
3138    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3139    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3140      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3141    }    }
3142    
3143  if (common->nltype == NLTYPE_FIXED && common->newline > 255)  if (common->nltype == NLTYPE_FIXED && common->newline > 255)
# Line 1930  if (common->nltype == NLTYPE_FIXED && co Line 3150  if (common->nltype == NLTYPE_FIXED && co
3150    
3151    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3152    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);
3153    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3154  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3155    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3156  #endif  #endif
3157    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3158    
3159    loop = LABEL();    loop = LABEL();
3160    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));
3161    leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3162    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
3163    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
3164    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);
3165    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);
3166    
3167    JUMPHERE(leave);    JUMPHERE(quit);
3168    JUMPHERE(firstchar);    JUMPHERE(firstchar);
3169    JUMPHERE(lastchar);    JUMPHERE(lastchar);
3170    
# Line 1968  set_jumps(newline, loop); Line 3188  set_jumps(newline, loop);
3188    
3189  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3190    {    {
3191    leave = JUMP(SLJIT_JUMP);    quit = JUMP(SLJIT_JUMP);
3192    JUMPHERE(foundcr);    JUMPHERE(foundcr);
3193    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3194    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3195    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);
3196    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3197  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3198    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3199  #endif  #endif
3200    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3201    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
3202    JUMPHERE(leave);    JUMPHERE(quit);
3203    }    }
3204  JUMPHERE(lastchar);  JUMPHERE(lastchar);
3205  JUMPHERE(firstchar);  JUMPHERE(firstchar);
3206    
3207  if (firstline)  if (firstline)
3208    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3209  }  }
3210    
3211    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3212    
3213  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)
3214  {  {
3215  DEFINE_COMPILER;  DEFINE_COMPILER;
3216  struct sljit_label *start;  struct sljit_label *start;
3217  struct sljit_jump *leave;  struct sljit_jump *quit;
3218  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3219    jump_list *matches = NULL;
3220    pcre_uint8 inverted_start_bits[32];
3221    int i;
3222  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3223  struct sljit_jump *jump;  struct sljit_jump *jump;
3224  #endif  #endif
3225    
3226    for (i = 0; i < 32; ++i)
3227      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3228    
3229  if (firstline)  if (firstline)
3230    {    {
3231    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3232    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
3233      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3234    }    }
3235    
3236  start = LABEL();  start = LABEL();
3237  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3238  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3239  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3240  if (common->utf)  if (common->utf)
3241    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3242  #endif  #endif
3243    
3244    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3245      {
3246  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3247  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3248  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3249  JUMPHERE(jump);    JUMPHERE(jump);
3250  #endif  #endif
3251  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3252  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3253  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3254  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3255  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);
3256  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3257      }
3258    
3259  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3260  if (common->utf)  if (common->utf)
3261    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3262  #endif  #endif
3263  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));
3264  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3265    #if defined COMPILE_PCRE8
3266  if (common->utf)  if (common->utf)
3267    {    {
3268    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3269    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);
3270    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3271    }    }
3272  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3273  if (common->utf)  if (common->utf)
3274    {    {
3275    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3276    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3277    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);
3278    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3279    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3280    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3281    }    }
3282  #endif  #endif /* COMPILE_PCRE[8|16] */
3283    #endif /* SUPPORT_UTF */
3284  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3285  JUMPHERE(found);  if (found != NULL)
3286  JUMPHERE(leave);    JUMPHERE(found);
3287    if (matches != NULL)
3288      set_jumps(matches, LABEL());
3289    JUMPHERE(quit);
3290    
3291  if (firstline)  if (firstline)
3292    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0);
3293  }  }
3294    
3295  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 2064  struct sljit_jump *alreadyfound; Line 3301  struct sljit_jump *alreadyfound;
3301  struct sljit_jump *found;  struct sljit_jump *found;
3302  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3303  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3304  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3305    
3306  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_CHAR_PTR);  SLJIT_ASSERT(common->req_char_ptr != 0);
3307    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
3308  OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, REQ_BYTE_MAX);  OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, REQ_BYTE_MAX);
3309  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);
3310  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);
# Line 2094  if (req_char == oc) Line 3332  if (req_char == oc)
3332  else  else
3333    {    {
3334    bit = req_char ^ oc;    bit = req_char ^ oc;
3335    if (ispowerof2(bit))    if (is_powerof2(bit))
3336      {      {
3337      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3338      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 2111  JUMPTO(SLJIT_JUMP, loop); Line 3349  JUMPTO(SLJIT_JUMP, loop);
3349  JUMPHERE(found);  JUMPHERE(found);
3350  if (foundoc)  if (foundoc)
3351    JUMPHERE(foundoc);    JUMPHERE(foundoc);
3352  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_CHAR_PTR, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr, TMP1, 0);
3353  JUMPHERE(alreadyfound);  JUMPHERE(alreadyfound);
3354  JUMPHERE(toolong);  JUMPHERE(toolong);
3355  return notfound;  return notfound;
# Line 2123  DEFINE_COMPILER; Line 3361  DEFINE_COMPILER;
3361  struct sljit_jump *jump;  struct sljit_jump *jump;
3362  struct sljit_label *mainloop;  struct sljit_label *mainloop;
3363    
3364  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3365  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);
3366    GET_LOCAL_BASE(TMP3, 0, 0);
3367    
3368  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3369  mainloop = LABEL();  mainloop = LABEL();
3370  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3371  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);
3372  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_LOCALS_REG, 0);  jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3373  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  
3374  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_w), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3375  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3376    OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
3377    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw));
3378  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3379    
3380  JUMPHERE(jump);  JUMPHERE(jump);
3381  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3382  /* End of dropping frames. */  /* End of dropping frames. */
3383  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3384    
3385  JUMPHERE(jump);  JUMPHERE(jump);
3386  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3387  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3388  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3389  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);  
 /* Unknown command. */  
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  
3390  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3391  }  }
3392    
3393  static void check_wordboundary(compiler_common *common)  static void check_wordboundary(compiler_common *common)
3394  {  {
3395  DEFINE_COMPILER;  DEFINE_COMPILER;
3396  struct sljit_jump *beginend;  struct sljit_jump *skipread;
3397    jump_list *skipread_list = NULL;
3398  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3399  struct sljit_jump *jump;  struct sljit_jump *jump;
3400  #endif  #endif
3401    
3402  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);
3403    
3404  sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3405  /* Get type of the previous char, and put it to LOCALS1. */  /* Get type of the previous char, and put it to LOCALS1. */
3406  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
3407  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
3408  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);
3409  beginend = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);  skipread = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
3410  skip_char_back(common);  skip_char_back(common);
3411    check_start_used_ptr(common);
3412  read_char(common);  read_char(common);
3413    
3414  /* Testing char type. */  /* Testing char type. */
# Line 2183  if (common->use_ucp) Line 3420  if (common->use_ucp)
3420    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3421    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3422    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);
3423    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3424    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);
3425    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);
3426    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3427    JUMPHERE(jump);    JUMPHERE(jump);
3428    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3429    }    }
# Line 2212  else Line 3449  else
3449      JUMPHERE(jump);      JUMPHERE(jump);
3450  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3451    }    }
3452  JUMPHERE(beginend);  JUMPHERE(skipread);
3453    
3454  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3455  beginend = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  check_str_end(common, &skipread_list);
3456  peek_char(common);  peek_char(common);
3457    
3458  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 2227  if (common->use_ucp) Line 3464  if (common->use_ucp)
3464    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3465    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3466    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);
3467    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3468    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);
3469    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);
3470    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3471    JUMPHERE(jump);    JUMPHERE(jump);
3472    }    }
3473  else  else
# Line 2256  else Line 3493  else
3493      JUMPHERE(jump);      JUMPHERE(jump);
3494  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3495    }    }
3496  JUMPHERE(beginend);  set_jumps(skipread_list, LABEL());
3497    
3498  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3499  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3500  }  }
3501    
3502    /*
3503      range format:
3504    
3505      ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).
3506      ranges[1] = first bit (0 or 1)
3507      ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)
3508    */
3509    
3510    static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)
3511    {
3512    DEFINE_COMPILER;
3513    struct sljit_jump *jump;
3514    
3515    if (ranges[0] < 0)
3516      return FALSE;
3517    
3518    switch(ranges[0])
3519      {
3520      case 1:
3521      if (readch)
3522        read_char(common);
3523      add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3524      return TRUE;
3525    
3526      case 2:
3527      if (readch)
3528        read_char(common);
3529      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3530      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3531      return TRUE;
3532    
3533      case 4:
3534      if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])
3535        {
3536        if (readch)
3537          read_char(common);
3538        if (ranges[1] != 0)
3539          {
3540          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3541          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3542          }
3543        else
3544          {
3545          jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);
3546          add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3547          JUMPHERE(jump);
3548          }
3549        return TRUE;
3550        }
3551      if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))
3552        {
3553        if (readch)
3554          read_char(common);
3555        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);
3556        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3557        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3558        return TRUE;
3559        }
3560      return FALSE;
3561    
3562      default:
3563      return FALSE;
3564      }
3565    }
3566    
3567    static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)
3568    {
3569    int i, bit, length;
3570    const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;
3571    
3572    bit = ctypes[0] & flag;
3573    ranges[0] = -1;
3574    ranges[1] = bit != 0 ? 1 : 0;
3575    length = 0;
3576    
3577    for (i = 1; i < 256; i++)
3578      if ((ctypes[i] & flag) != bit)
3579        {
3580        if (length >= MAX_RANGE_SIZE)
3581          return;
3582        ranges[2 + length] = i;
3583        length++;
3584        bit ^= flag;
3585        }
3586    
3587    if (bit != 0)
3588      {
3589      if (length >= MAX_RANGE_SIZE)
3590        return;
3591      ranges[2 + length] = 256;
3592      length++;
3593      }
3594    ranges[0] = length;
3595    }
3596    
3597    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)
3598    {
3599    int ranges[2 + MAX_RANGE_SIZE];
3600    pcre_uint8 bit, cbit, all;
3601    int i, byte, length = 0;
3602    
3603    bit = bits[0] & 0x1;
3604    ranges[1] = bit;
3605    /* Can be 0 or 255. */
3606    all = -bit;
3607    
3608    for (i = 0; i < 256; )
3609      {
3610      byte = i >> 3;
3611      if ((i & 0x7) == 0 && bits[byte] == all)
3612        i += 8;
3613      else
3614        {
3615        cbit = (bits[byte] >> (i & 0x7)) & 0x1;
3616        if (cbit != bit)
3617          {
3618          if (length >= MAX_RANGE_SIZE)
3619            return FALSE;
3620          ranges[2 + length] = i;
3621          length++;
3622          bit = cbit;
3623          all = -cbit;
3624          }
3625        i++;
3626        }
3627      }
3628    
3629    if (((bit == 0) && nclass) || ((bit == 1) && !nclass))
3630      {
3631      if (length >= MAX_RANGE_SIZE)
3632        return FALSE;
3633      ranges[2 + length] = 256;
3634      length++;
3635      }
3636    ranges[0] = length;
3637    
3638    return check_ranges(common, ranges, backtracks, FALSE);
3639    }
3640    
3641  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
3642  {  {
3643  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3644  DEFINE_COMPILER;  DEFINE_COMPILER;
3645    
3646  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3647    
3648  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3649  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);
3650  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3651  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);
3652  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3653  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3654  if (common->utf)  if (common->utf)
3655    {    {
3656  #endif  #endif
3657    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3658    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3659    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);
3660  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3661    }    }
3662  #endif  #endif
3663  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3664  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);
3665  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3666  }  }
3667    
# Line 2294  static void check_hspace(compiler_common Line 3670  static void check_hspace(compiler_common
3670  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3671  DEFINE_COMPILER;  DEFINE_COMPILER;
3672    
3673  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3674    
3675  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09);
3676  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3677  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
3678  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3679  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0);
3680  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3681  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3682  if (common->utf)  if (common->utf)
3683    {    {
3684  #endif  #endif
3685    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3686    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680);
3687    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3688    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e);
3689    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3690    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3691    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000);
3692    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3693    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000);
3694    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3695    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);
3696    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3697    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000);
3698  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3699    }    }
3700  #endif  #endif
3701  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3702  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);
3703    
3704  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3705  }  }
# Line 2333  static void check_vspace(compiler_common Line 3709  static void check_vspace(compiler_common
3709  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3710  DEFINE_COMPILER;  DEFINE_COMPILER;
3711    
3712  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3713    
3714  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3715  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);
3716  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3717  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);
3718  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3719  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3720  if (common->utf)  if (common->utf)
3721    {    {
3722  #endif  #endif
3723    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);
3724    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3725    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);
3726  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3727    }    }
3728  #endif  #endif
3729  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3730  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);
3731    
3732  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3733  }  }
# Line 2365  DEFINE_COMPILER; Line 3741  DEFINE_COMPILER;
3741  struct sljit_jump *jump;  struct sljit_jump *jump;
3742  struct sljit_label *label;  struct sljit_label *label;
3743    
3744  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3745  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3746  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);
3747  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);
# Line 2394  DEFINE_COMPILER; Line 3770  DEFINE_COMPILER;
3770  struct sljit_jump *jump;  struct sljit_jump *jump;
3771  struct sljit_label *label;  struct sljit_label *label;
3772    
3773  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3774  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3775    
3776  OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);  OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);
# Line 2437  sljit_emit_fast_return(compiler, RETURN_ Line 3813  sljit_emit_fast_return(compiler, RETURN_
3813    
3814  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3815    
3816  static const pcre_uchar *SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1)  static const pcre_uchar * SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1)
3817  {  {
3818  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3819  int c1, c2;  pcre_uint32 c1, c2;
3820  const pcre_uchar *src2 = args->ptr;  const pcre_uchar *src2 = args->uchar_ptr;
3821  const pcre_uchar *end2 = args->end;  const pcre_uchar *end2 = args->end;
3822    const ucd_record *ur;
3823    const pcre_uint32 *pp;
3824    
3825  while (src1 < end1)  while (src1 < end1)
3826    {    {
3827    if (src2 >= end2)    if (src2 >= end2)
3828      return 0;      return (pcre_uchar*)1;
3829    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
3830    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
3831    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return 0;    ur = GET_UCD(c2);
3832      if (c1 != c2 && c1 != c2 + ur->other_case)
3833        {
3834        pp = PRIV(ucd_caseless_sets) + ur->caseset;
3835        for (;;)
3836          {
3837          if (c1 < *pp) return NULL;
3838          if (c1 == *pp++) break;
3839          }
3840        }
3841    }    }
3842  return src2;  return src2;
3843  }  }
# Line 2458  return src2; Line 3845  return src2;
3845  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
3846    
3847  static pcre_uchar *byte_sequence_compare(compiler_common *common, BOOL caseless, pcre_uchar *cc,  static pcre_uchar *byte_sequence_compare(compiler_common *common, BOOL caseless, pcre_uchar *cc,
3848      compare_context* context, jump_list **fallbacks)