/[pcre]/code/tags/pcre-8.37/pcre_jit_compile.c
ViewVC logotype

Diff of /code/tags/pcre-8.37/pcre_jit_compile.c

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

revision 715 by zherczeg, Sat Oct 1 06:42:38 2011 UTC revision 1411 by ph10, Fri Dec 6 17:11:44 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2008 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-2011                        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
53  system files. */  system files. */
54    
55    #define SLJIT_MALLOC(size) (PUBL(malloc))(size)
56    #define SLJIT_FREE(ptr) (PUBL(free))(ptr)
57  #define SLJIT_CONFIG_AUTO 1  #define SLJIT_CONFIG_AUTO 1
58    #define SLJIT_CONFIG_STATIC 1
59  #define SLJIT_VERBOSE 0  #define SLJIT_VERBOSE 0
60  #define SLJIT_DEBUG 0  #define SLJIT_DEBUG 0
61    
62  #include "sljit/sljitLir.c"  #include "sljit/sljitLir.c"
63    
64  #if defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED  #if defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED
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 79  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 105  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 {
161    /* Pointers first. */    /* Pointers first. */
162    struct sljit_stack *stack;    struct sljit_stack *stack;
163    PCRE_SPTR str;    const pcre_uchar *str;
164    PCRE_SPTR begin;    const pcre_uchar *begin;
165    PCRE_SPTR end;    const pcre_uchar *end;
166    int *offsets;    int *offsets;
167    uschar *ptr;    pcre_uchar *uchar_ptr;
168      pcre_uchar *mark_ptr;
169      void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171    int offsetcount;    pcre_uint32 limit_match;
172    int calllimit;    int real_offset_count;
173    uschar notbol;    int offset_count;
174    uschar noteol;    pcre_uint8 notbol;
175    uschar notempty;    pcre_uint8 noteol;
176    uschar notempty_atstart;    pcre_uint8 notempty;
177      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    pcre_jit_callback callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184  } executable_function;    pcre_uint32 top_bracket;
185      pcre_uint32 limit_match;
186      sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
187    } executable_functions;
188    
189  typedef struct jump_list {  typedef struct jump_list {
190    struct sljit_jump *jump;    struct sljit_jump *jump;
191    struct jump_list *next;    struct jump_list *next;
192  } jump_list;  } jump_list;
193    
 enum stub_types { stack_alloc };  
   
194  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
195    struct sljit_jump *start;    struct sljit_jump *start;
196    struct sljit_label *leave;    struct sljit_label *quit;
197    struct stub_list *next;    struct stub_list *next;
198  } stub_list;  } stub_list;
199    
200    enum frame_types {
201      no_frame = -1,
202      no_stack = -2
203    };
204    
205    enum control_types {
206      type_mark = 0,
207      type_then_trap = 1
208    };
209    
210  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
213  code generator. It is allocated by compile_hotpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
214  the aguments for compile_fallbackpath. Must be the first member  the arguments for compile_backtrackingpath. Must be the first member
215  of its descendants. */  of its descendants. */
216  typedef struct fallback_common {  typedef struct backtrack_common {
217    /* Concatenation stack. */    /* Concatenation stack. */
218    struct fallback_common *prev;    struct backtrack_common *prev;
219    jump_list *nextfallbacks;    jump_list *nextbacktracks;
220    /* Internal stack (for component operators). */    /* Internal stack (for component operators). */
221    struct fallback_common *top;    struct backtrack_common *top;
222    jump_list *topfallbacks;    jump_list *topbacktracks;
223    /* Opcode pointer. */    /* Opcode pointer. */
224    uschar *cc;    pcre_uchar *cc;
225  } fallback_common;  } backtrack_common;
226    
227  typedef struct assert_fallback {  typedef struct assert_backtrack {
228    fallback_common common;    backtrack_common common;
229    jump_list *condfailed;    jump_list *condfailed;
230    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
231    int framesize;    int framesize;
232    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
233    int localptr;    int private_data_ptr;
234    /* For iterators. */    /* For iterators. */
235    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
236  } assert_fallback;  } assert_backtrack;
237    
238  typedef struct bracket_fallback {  typedef struct bracket_backtrack {
239    fallback_common common;    backtrack_common common;
240    /* Where to coninue if an alternative is successfully matched. */    /* Where to coninue if an alternative is successfully matched. */
241    struct sljit_label *althotpath;    struct sljit_label *alternative_matchingpath;
242    /* For rmin and rmax iterators. */    /* For rmin and rmax iterators. */
243    struct sljit_label *recursivehotpath;    struct sljit_label *recursive_matchingpath;
244    /* For greedy ? operator. */    /* For greedy ? operator. */
245    struct sljit_label *zerohotpath;    struct sljit_label *zero_matchingpath;
246    /* Contains the branches of a failed condition. */    /* Contains the branches of a failed condition. */
247    union {    union {
248      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
249      jump_list *condfailed;      jump_list *condfailed;
250      assert_fallback *assert;      assert_backtrack *assert;
251      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
252      int framesize;      int framesize;
253    } u;    } u;
254    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
255    int localptr;    int private_data_ptr;
256  } bracket_fallback;  } bracket_backtrack;
257    
258  typedef struct bracketpos_fallback {  typedef struct bracketpos_backtrack {
259    fallback_common common;    backtrack_common common;
260    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
261    int localptr;    int private_data_ptr;
262    /* Reverting stack is needed. */    /* Reverting stack is needed. */
263    int framesize;    int framesize;
264    /* Allocated stack size. */    /* Allocated stack size. */
265    int stacksize;    int stacksize;
266  } bracketpos_fallback;  } bracketpos_backtrack;
267    
268  typedef struct braminzero_fallback {  typedef struct braminzero_backtrack {
269    fallback_common common;    backtrack_common common;
270    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
271  } braminzero_fallback;  } braminzero_backtrack;
272    
273  typedef struct iterator_fallback {  typedef struct iterator_backtrack {
274    fallback_common common;    backtrack_common common;
275    /* Next iteration. */    /* Next iteration. */
276    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
277  } iterator_fallback;  } iterator_backtrack;
278    
279  typedef struct recurse_entry {  typedef struct recurse_entry {
280    struct recurse_entry *next;    struct recurse_entry *next;
# Line 256  typedef struct recurse_entry { Line 283  typedef struct recurse_entry {
283    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
284    jump_list *calls;    jump_list *calls;
285    /* Points to the starting opcode. */    /* Points to the starting opcode. */
286    int start;    sljit_sw start;
287  } recurse_entry;  } recurse_entry;
288    
289  typedef struct recurse_fallback {  typedef struct recurse_backtrack {
290    fallback_common common;    backtrack_common common;
291  } recurse_fallback;    BOOL inlined_pattern;
292    } recurse_backtrack;
293    
294    #define OP_THEN_TRAP OP_TABLE_LENGTH
295    
296    typedef struct then_trap_backtrack {
297      backtrack_common common;
298      /* If then_trap is not NULL, this structure contains the real
299      then_trap for the backtracking path. */
300      struct then_trap_backtrack *then_trap;
301      /* Points to the starting opcode. */
302      sljit_sw start;
303      /* Exit point for the then opcodes of this alternative. */
304      jump_list *quit;
305      /* Frame size of the current alternative. */
306      int framesize;
307    } then_trap_backtrack;
308    
309    #define MAX_RANGE_SIZE 6
310    
311  typedef struct compiler_common {  typedef struct compiler_common {
312      /* The sljit ceneric compiler. */
313    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
314    uschar *start;    /* First byte code. */
315    int localsize;    pcre_uchar *start;
316    int *localptrs;    /* Maps private data offset to each opcode. */
317    const uschar *fcc;    sljit_si *private_data_ptrs;
318    sljit_w lcc;    /* Tells whether the capturing bracket is optimized. */
319    int cbraptr;    pcre_uint8 *optimized_cbracket;
320      /* Tells whether the starting offset is a target of then. */
321      pcre_uint8 *then_offsets;
322      /* Current position where a THEN must jump. */
323      then_trap_backtrack *then_trap;
324      /* Starting offset of private data for capturing brackets. */
325      int cbra_ptr;
326      /* Output vector starting point. Must be divisible by 2. */
327      int ovector_start;
328      /* Last known position of the requested byte. */
329      int req_char_ptr;
330      /* Head of the last recursion. */
331      int recursive_head_ptr;
332      /* First inspected character for partial matching. */
333      int start_used_ptr;
334      /* Starting pointer for partial soft matches. */
335      int hit_start;
336      /* End pointer of the first line. */
337      int first_line_end;
338      /* Points to the marked string. */
339      int mark_ptr;
340      /* Recursive control verb management chain. */
341      int control_head_ptr;
342      /* Points to the last matched capture block index. */
343      int capture_last_ptr;
344      /* Points to the starting position of the current match. */
345      int start_ptr;
346    
347      /* Flipped and lower case tables. */
348      const pcre_uint8 *fcc;
349      sljit_sw lcc;
350      /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
351      int mode;
352      /* \K is found in the pattern. */
353      BOOL has_set_som;
354      /* (*SKIP:arg) is found in the pattern. */
355      BOOL has_skip_arg;
356      /* (*THEN) is found in the pattern. */
357      BOOL has_then;
358      /* Needs to know the start position anytime. */
359      BOOL needs_start_ptr;
360      /* Currently in recurse or negative assert. */
361      BOOL local_exit;
362      /* Currently in a positive assert. */
363      BOOL positive_assert;
364      /* Newline control. */
365    int nltype;    int nltype;
366    int newline;    int newline;
367    int bsr_nltype;    int bsr_nltype;
368      /* Dollar endonly. */
369    int endonly;    int endonly;
370    sljit_w ctypes;    /* Tables. */
371    struct sljit_label *acceptlabel;    sljit_sw ctypes;
372      int digits[2 + MAX_RANGE_SIZE];
373      /* Named capturing brackets. */
374      pcre_uchar *name_table;
375      sljit_sw name_count;
376      sljit_sw name_entry_size;
377    
378      /* Labels and jump lists. */
379      struct sljit_label *partialmatchlabel;
380      struct sljit_label *quit_label;
381      struct sljit_label *forced_quit_label;
382      struct sljit_label *accept_label;
383    stub_list *stubs;    stub_list *stubs;
384    recurse_entry *entries;    recurse_entry *entries;
385    recurse_entry *currententry;    recurse_entry *currententry;
386      jump_list *partialmatch;
387      jump_list *quit;
388      jump_list *positive_assert_quit;
389      jump_list *forced_quit;
390    jump_list *accept;    jump_list *accept;
391    jump_list *calllimit;    jump_list *calllimit;
392    jump_list *stackalloc;    jump_list *stackalloc;
# Line 290  typedef struct compiler_common { Line 397  typedef struct compiler_common {
397    jump_list *vspace;    jump_list *vspace;
398    jump_list *casefulcmp;    jump_list *casefulcmp;
399    jump_list *caselesscmp;    jump_list *caselesscmp;
400      jump_list *reset_match;
401    BOOL jscript_compat;    BOOL jscript_compat;
402  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
403    BOOL utf8;    BOOL utf;
404  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
405    BOOL useucp;    BOOL use_ucp;
406  #endif  #endif
407    jump_list *utf8readchar;  #ifndef COMPILE_PCRE32
408    jump_list *utf8readtype8;    jump_list *utfreadchar;
409  #endif  #endif
410    #ifdef COMPILE_PCRE8
411      jump_list *utfreadtype8;
412    #endif
413    #endif /* SUPPORT_UTF */
414  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
415    jump_list *getucd;    jump_list *getucd;
416  #endif  #endif
# Line 310  typedef struct compare_context { Line 422  typedef struct compare_context {
422    int length;    int length;
423    int sourcereg;    int sourcereg;
424  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
425    int byteptr;    int ucharptr;
426    union {    union {
427      int asint;      sljit_si asint;
428      short asshort;      sljit_uh asushort;
429    #if defined COMPILE_PCRE8
430      sljit_ub asbyte;      sljit_ub asbyte;
431      sljit_ub asbytes[4];      sljit_ub asuchars[4];
432    #elif defined COMPILE_PCRE16
433        sljit_uh asuchars[2];
434    #elif defined COMPILE_PCRE32
435        sljit_ui asuchars[1];
436    #endif
437    } c;    } c;
438    union {    union {
439      int asint;      sljit_si asint;
440      short asshort;      sljit_uh asushort;
441    #if defined COMPILE_PCRE8
442      sljit_ub asbyte;      sljit_ub asbyte;
443      sljit_ub asbytes[4];      sljit_ub asuchars[4];
444    #elif defined COMPILE_PCRE16
445        sljit_uh asuchars[2];
446    #elif defined COMPILE_PCRE32
447        sljit_ui asuchars[1];
448    #endif
449    } oc;    } oc;
450  #endif  #endif
451  } compare_context;  } compare_context;
452    
453  enum {  /* Undefine sljit macros. */
454    frame_end = 0,  #undef CMP
   frame_setstrbegin = -1  
 };  
455    
456  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
457  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
458    
459  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
460  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
461  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
462  #define STR_PTR       SLJIT_GENERAL_REG1  #define STR_PTR       SLJIT_SAVED_REG1
463  #define STR_END       SLJIT_GENERAL_REG2  #define STR_END       SLJIT_SAVED_REG2
464  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
465  #define STACK_LIMIT   SLJIT_GENERAL_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
466  #define ARGUMENTS     SLJIT_GENERAL_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
467  #define CALL_COUNT    SLJIT_GENERAL_EREG2  #define COUNT_MATCH   SLJIT_SAVED_EREG2
468  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
469    
470  /* Locals layout. */  /* Local space layout. */
471  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
472  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
473  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
474  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
475  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
476  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
 /* Head of the saved local variables */  
 #define LOCALS_HEAD      (4 * sizeof(sljit_w))  
 /* Head of the last recursion. */  
 #define RECURSIVE_HEAD   (5 * sizeof(sljit_w))  
477  /* Max limit of recursions. */  /* Max limit of recursions. */
478  #define CALL_LIMIT       (7 * sizeof(sljit_w))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
 /* Last known position of the requested byte. */  
 #define REQ_BYTE_PTR     (8 * sizeof(sljit_w))  
 /* End pointer of the first line. */  
 #define FIRSTLINE_END    (9 * sizeof(sljit_w))  
479  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
480  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
481  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
482  the start pointers when the end of the capturing group has not yet reached. */  the start pointers when the end of the capturing group has not yet reached. */
483  #define OVECTOR_START    (10 * sizeof(sljit_w))  #define OVECTOR_START    (common->ovector_start)
484  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw))
485  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
486  #define PRIV(cc)         (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
487    
488    #if defined COMPILE_PCRE8
489    #define MOV_UCHAR  SLJIT_MOV_UB
490    #define MOVU_UCHAR SLJIT_MOVU_UB
491    #elif defined COMPILE_PCRE16
492    #define MOV_UCHAR  SLJIT_MOV_UH
493    #define MOVU_UCHAR SLJIT_MOVU_UH
494    #elif defined COMPILE_PCRE32
495    #define MOV_UCHAR  SLJIT_MOV_UI
496    #define MOVU_UCHAR SLJIT_MOVU_UI
497    #else
498    #error Unsupported compiling mode
499    #endif
500    
501  /* Shortcuts. */  /* Shortcuts. */
502  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 386  the start pointers when the end of the c Line 513  the start pointers when the end of the c
513    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
514  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
515    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
516    #define SET_LABEL(jump, label) \
517      sljit_set_label((jump), (label))
518  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
519    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
520  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
521    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))
522  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
523    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
524    #define GET_LOCAL_BASE(dst, dstw, offset) \
525      sljit_get_local_base(compiler, (dst), (dstw), (offset))
526    
527  static uschar* bracketend(uschar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
528  {  {
529  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
530  do cc += GET(cc, 1); while (*cc == OP_ALT);  do cc += GET(cc, 1); while (*cc == OP_ALT);
# Line 404  return cc; Line 535  return cc;
535    
536  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
537   next_opcode   next_opcode
538   get_localspace   check_opcode_types
539   set_localptrs   set_private_data_ptrs
540   get_framesize   get_framesize
541   init_frame   init_frame
542   get_localsize   get_private_data_copy_length
543   copy_locals   copy_private_data
544   compile_hotpath   compile_matchingpath
545   compile_fallbackpath   compile_backtrackingpath
546  */  */
547    
548  static uschar *next_opcode(compiler_common *common, uschar *cc)  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
549  {  {
550  SLJIT_UNUSED_ARG(common);  SLJIT_UNUSED_ARG(common);
551  switch(*cc)  switch(*cc)
# Line 432  switch(*cc) Line 563  switch(*cc)
563    case OP_WORDCHAR:    case OP_WORDCHAR:
564    case OP_ANY:    case OP_ANY:
565    case OP_ALLANY:    case OP_ALLANY:
566      case OP_NOTPROP:
567      case OP_PROP:
568    case OP_ANYNL:    case OP_ANYNL:
569    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
570    case OP_HSPACE:    case OP_HSPACE:
# Line 444  switch(*cc) Line 577  switch(*cc)
577    case OP_CIRCM:    case OP_CIRCM:
578    case OP_DOLL:    case OP_DOLL:
579    case OP_DOLLM:    case OP_DOLLM:
   case OP_TYPESTAR:  
   case OP_TYPEMINSTAR:  
   case OP_TYPEPLUS:  
   case OP_TYPEMINPLUS:  
   case OP_TYPEQUERY:  
   case OP_TYPEMINQUERY:  
   case OP_TYPEPOSSTAR:  
   case OP_TYPEPOSPLUS:  
   case OP_TYPEPOSQUERY:  
580    case OP_CRSTAR:    case OP_CRSTAR:
581    case OP_CRMINSTAR:    case OP_CRMINSTAR:
582    case OP_CRPLUS:    case OP_CRPLUS:
583    case OP_CRMINPLUS:    case OP_CRMINPLUS:
584    case OP_CRQUERY:    case OP_CRQUERY:
585    case OP_CRMINQUERY:    case OP_CRMINQUERY:
586      case OP_CRRANGE:
587      case OP_CRMINRANGE:
588      case OP_CRPOSSTAR:
589      case OP_CRPOSPLUS:
590      case OP_CRPOSQUERY:
591      case OP_CRPOSRANGE:
592      case OP_CLASS:
593      case OP_NCLASS:
594      case OP_REF:
595      case OP_REFI:
596      case OP_DNREF:
597      case OP_DNREFI:
598      case OP_RECURSE:
599      case OP_CALLOUT:
600      case OP_ALT:
601      case OP_KET:
602      case OP_KETRMAX:
603      case OP_KETRMIN:
604      case OP_KETRPOS:
605      case OP_REVERSE:
606      case OP_ASSERT:
607      case OP_ASSERT_NOT:
608      case OP_ASSERTBACK:
609      case OP_ASSERTBACK_NOT:
610      case OP_ONCE:
611      case OP_ONCE_NC:
612      case OP_BRA:
613      case OP_BRAPOS:
614      case OP_CBRA:
615      case OP_CBRAPOS:
616      case OP_COND:
617      case OP_SBRA:
618      case OP_SBRAPOS:
619      case OP_SCBRA:
620      case OP_SCBRAPOS:
621      case OP_SCOND:
622      case OP_CREF:
623      case OP_DNCREF:
624      case OP_RREF:
625      case OP_DNRREF:
626    case OP_DEF:    case OP_DEF:
627    case OP_BRAZERO:    case OP_BRAZERO:
628    case OP_BRAMINZERO:    case OP_BRAMINZERO:
629    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
630      case OP_PRUNE:
631      case OP_SKIP:
632      case OP_THEN:
633      case OP_COMMIT:
634    case OP_FAIL:    case OP_FAIL:
635    case OP_ACCEPT:    case OP_ACCEPT:
636    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
637      case OP_CLOSE:
638    case OP_SKIPZERO:    case OP_SKIPZERO:
639    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
640    
641    case OP_CHAR:    case OP_CHAR:
642    case OP_CHARI:    case OP_CHARI:
643    case OP_NOT:    case OP_NOT:
644    case OP_NOTI:    case OP_NOTI:
   
645    case OP_STAR:    case OP_STAR:
646    case OP_MINSTAR:    case OP_MINSTAR:
647    case OP_PLUS:    case OP_PLUS:
648    case OP_MINPLUS:    case OP_MINPLUS:
649    case OP_QUERY:    case OP_QUERY:
650    case OP_MINQUERY:    case OP_MINQUERY:
651      case OP_UPTO:
652      case OP_MINUPTO:
653      case OP_EXACT:
654    case OP_POSSTAR:    case OP_POSSTAR:
655    case OP_POSPLUS:    case OP_POSPLUS:
656    case OP_POSQUERY:    case OP_POSQUERY:
657      case OP_POSUPTO:
658    case OP_STARI:    case OP_STARI:
659    case OP_MINSTARI:    case OP_MINSTARI:
660    case OP_PLUSI:    case OP_PLUSI:
661    case OP_MINPLUSI:    case OP_MINPLUSI:
662    case OP_QUERYI:    case OP_QUERYI:
663    case OP_MINQUERYI:    case OP_MINQUERYI:
664      case OP_UPTOI:
665      case OP_MINUPTOI:
666      case OP_EXACTI:
667    case OP_POSSTARI:    case OP_POSSTARI:
668    case OP_POSPLUSI:    case OP_POSPLUSI:
669    case OP_POSQUERYI:    case OP_POSQUERYI:
670      case OP_POSUPTOI:
671    case OP_NOTSTAR:    case OP_NOTSTAR:
672    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
673    case OP_NOTPLUS:    case OP_NOTPLUS:
674    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
675    case OP_NOTQUERY:    case OP_NOTQUERY:
676    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
677      case OP_NOTUPTO:
678      case OP_NOTMINUPTO:
679      case OP_NOTEXACT:
680    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
681    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
682    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
683      case OP_NOTPOSUPTO:
684    case OP_NOTSTARI:    case OP_NOTSTARI:
685    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
686    case OP_NOTPLUSI:    case OP_NOTPLUSI:
687    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
688    case OP_NOTQUERYI:    case OP_NOTQUERYI:
689    case OP_NOTMINQUERYI:    case OP_NOTMINQUERYI:
   case OP_NOTPOSSTARI:  
   case OP_NOTPOSPLUSI:  
   case OP_NOTPOSQUERYI:  
   cc += 2;  
 #ifdef SUPPORT_UTF8  
   if (common->utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];  
 #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:  
690    case OP_NOTUPTOI:    case OP_NOTUPTOI:
691    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
692    case OP_NOTEXACTI:    case OP_NOTEXACTI:
693      case OP_NOTPOSSTARI:
694      case OP_NOTPOSPLUSI:
695      case OP_NOTPOSQUERYI:
696    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
697    cc += 4;    cc += PRIV(OP_lengths)[*cc];
698  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
699    if (common->utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
700  #endif  #endif
701    return cc;    return cc;
702    
703    case OP_NOTPROP:    /* Special cases. */
704    case OP_PROP:    case OP_TYPESTAR:
705      case OP_TYPEMINSTAR:
706      case OP_TYPEPLUS:
707      case OP_TYPEMINPLUS:
708      case OP_TYPEQUERY:
709      case OP_TYPEMINQUERY:
710    case OP_TYPEUPTO:    case OP_TYPEUPTO:
711    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
712    case OP_TYPEEXACT:    case OP_TYPEEXACT:
713      case OP_TYPEPOSSTAR:
714      case OP_TYPEPOSPLUS:
715      case OP_TYPEPOSQUERY:
716    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
717    case OP_REF:    return cc + PRIV(OP_lengths)[*cc] - 1;
   case OP_REFI:  
   case OP_CREF:  
   case OP_CLOSE:  
   cc += 3;  
   return cc;  
718    
719    case OP_CRRANGE:    case OP_ANYBYTE:
720    case OP_CRMINRANGE:  #ifdef SUPPORT_UTF
721    return cc + 5;    if (common->utf) return NULL;
722    #endif
723    case OP_CLASS:    return cc + 1;
   case OP_NCLASS:  
   return cc + 33;  
724    
725  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
726    case OP_XCLASS:    case OP_XCLASS:
727    return cc + GET(cc, 1);    return cc + GET(cc, 1);
728  #endif  #endif
729    
730    case OP_RECURSE:    case OP_MARK:
731    case OP_ASSERT:    case OP_PRUNE_ARG:
732    case OP_ASSERT_NOT:    case OP_SKIP_ARG:
733    case OP_ASSERTBACK:    case OP_THEN_ARG:
734    case OP_ASSERTBACK_NOT:    return cc + 1 + 2 + cc[1];
   case OP_REVERSE:  
   case OP_ONCE:  
   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 + 2;  
735    
736    default:    default:
737      /* All opcodes are supported now! */
738      SLJIT_ASSERT_STOP();
739    return NULL;    return NULL;
740    }    }
741  }  }
742    
743  static int get_localspace(compiler_common *common, uschar *cc, uschar *ccend)  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
744  {  {
745  int localspace = 0;  int count;
746  uschar *alternative;  pcre_uchar *slot;
747    
748  /* 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. */
749  while (cc < ccend)  while (cc < ccend)
750    {    {
751    switch(*cc)    switch(*cc)
752      {      {
753      case OP_ASSERT:      case OP_SET_SOM:
754      case OP_ASSERT_NOT:      common->has_set_som = TRUE;
755      case OP_ASSERTBACK:      cc += 1;
756      case OP_ASSERTBACK_NOT:      break;
757      case OP_ONCE:  
758      case OP_BRAPOS:      case OP_REF:
759      case OP_SBRA:      case OP_REFI:
760      case OP_SBRAPOS:      common->optimized_cbracket[GET2(cc, 1)] = 0;
761      case OP_SCOND:      cc += 1 + IMM2_SIZE;
     localspace += sizeof(sljit_w);  
     cc += 1 + LINK_SIZE;  
762      break;      break;
763    
764      case OP_CBRAPOS:      case OP_CBRAPOS:
765      case OP_SCBRAPOS:      case OP_SCBRAPOS:
766      localspace += sizeof(sljit_w);      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
767      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
768      break;      break;
769    
770      case OP_COND:      case OP_COND:
771      /* Might be a hidden SCOND. */      case OP_SCOND:
772      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
773      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
774        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
775          return FALSE;
776        cc += 1 + LINK_SIZE;
777        break;
778    
779        case OP_CREF:
780        common->optimized_cbracket[GET2(cc, 1)] = 0;
781        cc += 1 + IMM2_SIZE;
782        break;
783    
784        case OP_DNREF:
785        case OP_DNREFI:
786        case OP_DNCREF:
787        count = GET2(cc, 1 + IMM2_SIZE);
788        slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
789        while (count-- > 0)
790          {
791          common->optimized_cbracket[GET2(slot, 0)] = 0;
792          slot += common->name_entry_size;
793          }
794        cc += 1 + 2 * IMM2_SIZE;
795        break;
796    
797        case OP_RECURSE:
798        /* Set its value only once. */
799        if (common->recursive_head_ptr == 0)
800          {
801          common->recursive_head_ptr = common->ovector_start;
802          common->ovector_start += sizeof(sljit_sw);
803          }
804      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
805      break;      break;
806    
807        case OP_CALLOUT:
808        if (common->capture_last_ptr == 0)
809          {
810          common->capture_last_ptr = common->ovector_start;
811          common->ovector_start += sizeof(sljit_sw);
812          }
813        cc += 2 + 2 * LINK_SIZE;
814        break;
815    
816        case OP_THEN_ARG:
817        common->has_then = TRUE;
818        common->control_head_ptr = 1;
819        /* Fall through. */
820    
821        case OP_PRUNE_ARG:
822        common->needs_start_ptr = TRUE;
823        /* Fall through. */
824    
825        case OP_MARK:
826        if (common->mark_ptr == 0)
827          {
828          common->mark_ptr = common->ovector_start;
829          common->ovector_start += sizeof(sljit_sw);
830          }
831        cc += 1 + 2 + cc[1];
832        break;
833    
834        case OP_THEN:
835        common->has_then = TRUE;
836        common->control_head_ptr = 1;
837        /* Fall through. */
838    
839        case OP_PRUNE:
840        case OP_SKIP:
841        common->needs_start_ptr = TRUE;
842        cc += 1;
843        break;
844    
845        case OP_SKIP_ARG:
846        common->control_head_ptr = 1;
847        common->has_skip_arg = TRUE;
848        cc += 1 + 2 + cc[1];
849        break;
850    
851      default:      default:
852      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
853      if (cc == NULL)      if (cc == NULL)
854        return -1;        return FALSE;
855      break;      break;
856      }      }
857    }    }
858  return localspace;  return TRUE;
859    }
860    
861    static int get_class_iterator_size(pcre_uchar *cc)
862    {
863    switch(*cc)
864      {
865      case OP_CRSTAR:
866      case OP_CRPLUS:
867      return 2;
868    
869      case OP_CRMINSTAR:
870      case OP_CRMINPLUS:
871      case OP_CRQUERY:
872      case OP_CRMINQUERY:
873      return 1;
874    
875      case OP_CRRANGE:
876      case OP_CRMINRANGE:
877      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
878        return 0;
879      return 2;
880    
881      default:
882      return 0;
883      }
884  }  }
885    
886  static void set_localptrs(compiler_common *common, int localptr, uschar *ccend)  static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
887  {  {
888  uschar *cc = common->start;  pcre_uchar *end = bracketend(begin);
889  uschar *alternative;  pcre_uchar *next;
890    pcre_uchar *next_end;
891    pcre_uchar *max_end;
892    pcre_uchar type;
893    sljit_sw length = end - begin;
894    int min, max, i;
895    
896    /* Detect fixed iterations first. */
897    if (end[-(1 + LINK_SIZE)] != OP_KET)
898      return FALSE;
899    
900    /* Already detected repeat. */
901    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
902      return TRUE;
903    
904    next = end;
905    min = 1;
906    while (1)
907      {
908      if (*next != *begin)
909        break;
910      next_end = bracketend(next);
911      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
912        break;
913      next = next_end;
914      min++;
915      }
916    
917    if (min == 2)
918      return FALSE;
919    
920    max = 0;
921    max_end = next;
922    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
923      {
924      type = *next;
925      while (1)
926        {
927        if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
928          break;
929        next_end = bracketend(next + 2 + LINK_SIZE);
930        if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
931          break;
932        next = next_end;
933        max++;
934        }
935    
936      if (next[0] == type && next[1] == *begin && max >= 1)
937        {
938        next_end = bracketend(next + 1);
939        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
940          {
941          for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
942            if (*next_end != OP_KET)
943              break;
944    
945          if (i == max)
946            {
947            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
948            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
949            /* +2 the original and the last. */
950            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
951            if (min == 1)
952              return TRUE;
953            min--;
954            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
955            }
956          }
957        }
958      }
959    
960    if (min >= 3)
961      {
962      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
963      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
964      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
965      return TRUE;
966      }
967    
968    return FALSE;
969    }
970    
971    #define CASE_ITERATOR_PRIVATE_DATA_1 \
972        case OP_MINSTAR: \
973        case OP_MINPLUS: \
974        case OP_QUERY: \
975        case OP_MINQUERY: \
976        case OP_MINSTARI: \
977        case OP_MINPLUSI: \
978        case OP_QUERYI: \
979        case OP_MINQUERYI: \
980        case OP_NOTMINSTAR: \
981        case OP_NOTMINPLUS: \
982        case OP_NOTQUERY: \
983        case OP_NOTMINQUERY: \
984        case OP_NOTMINSTARI: \
985        case OP_NOTMINPLUSI: \
986        case OP_NOTQUERYI: \
987        case OP_NOTMINQUERYI:
988    
989    #define CASE_ITERATOR_PRIVATE_DATA_2A \
990        case OP_STAR: \
991        case OP_PLUS: \
992        case OP_STARI: \
993        case OP_PLUSI: \
994        case OP_NOTSTAR: \
995        case OP_NOTPLUS: \
996        case OP_NOTSTARI: \
997        case OP_NOTPLUSI:
998    
999    #define CASE_ITERATOR_PRIVATE_DATA_2B \
1000        case OP_UPTO: \
1001        case OP_MINUPTO: \
1002        case OP_UPTOI: \
1003        case OP_MINUPTOI: \
1004        case OP_NOTUPTO: \
1005        case OP_NOTMINUPTO: \
1006        case OP_NOTUPTOI: \
1007        case OP_NOTMINUPTOI:
1008    
1009    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1010        case OP_TYPEMINSTAR: \
1011        case OP_TYPEMINPLUS: \
1012        case OP_TYPEQUERY: \
1013        case OP_TYPEMINQUERY:
1014    
1015    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1016        case OP_TYPESTAR: \
1017        case OP_TYPEPLUS:
1018    
1019    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1020        case OP_TYPEUPTO: \
1021        case OP_TYPEMINUPTO:
1022    
1023    static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1024    {
1025    pcre_uchar *cc = common->start;
1026    pcre_uchar *alternative;
1027    pcre_uchar *end = NULL;
1028    int private_data_ptr = *private_data_start;
1029    int space, size, bracketlen;
1030    
1031  while (cc < ccend)  while (cc < ccend)
1032    {    {
1033      space = 0;
1034      size = 0;
1035      bracketlen = 0;
1036      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1037        return;
1038    
1039      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1040        if (detect_repeat(common, cc))
1041          {
1042          /* These brackets are converted to repeats, so no global
1043          based single character repeat is allowed. */
1044          if (cc >= end)
1045            end = bracketend(cc);
1046          }
1047    
1048    switch(*cc)    switch(*cc)
1049      {      {
1050        case OP_KET:
1051        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1052          {
1053          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1054          private_data_ptr += sizeof(sljit_sw);
1055          cc += common->private_data_ptrs[cc + 1 - common->start];
1056          }
1057        cc += 1 + LINK_SIZE;
1058        break;
1059    
1060      case OP_ASSERT:      case OP_ASSERT:
1061      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1062      case OP_ASSERTBACK:      case OP_ASSERTBACK:
1063      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1064      case OP_ONCE:      case OP_ONCE:
1065        case OP_ONCE_NC:
1066      case OP_BRAPOS:      case OP_BRAPOS:
1067      case OP_SBRA:      case OP_SBRA:
1068      case OP_SBRAPOS:      case OP_SBRAPOS:
1069      case OP_SCOND:      case OP_SCOND:
1070      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1071      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1072      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1073      break;      break;
1074    
1075      case OP_CBRAPOS:      case OP_CBRAPOS:
1076      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1077      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1078      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1079      cc += 1 + LINK_SIZE + 2;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1080      break;      break;
1081    
1082      case OP_COND:      case OP_COND:
# Line 675  while (cc < ccend) Line 1084  while (cc < ccend)
1084      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1085      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1086        {        {
1087        common->localptrs[cc - common->start] = localptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1088        localptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1089        }        }
1090      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1091        break;
1092    
1093        case OP_BRA:
1094        bracketlen = 1 + LINK_SIZE;
1095        break;
1096    
1097        case OP_CBRA:
1098        case OP_SCBRA:
1099        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1100        break;
1101    
1102        CASE_ITERATOR_PRIVATE_DATA_1
1103        space = 1;
1104        size = -2;
1105        break;
1106    
1107        CASE_ITERATOR_PRIVATE_DATA_2A
1108        space = 2;
1109        size = -2;
1110        break;
1111    
1112        CASE_ITERATOR_PRIVATE_DATA_2B
1113        space = 2;
1114        size = -(2 + IMM2_SIZE);
1115        break;
1116    
1117        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1118        space = 1;
1119        size = 1;
1120        break;
1121    
1122        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1123        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1124          space = 2;
1125        size = 1;
1126      break;      break;
1127    
1128        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1129        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1130          space = 2;
1131        size = 1 + IMM2_SIZE;
1132        break;
1133    
1134        case OP_CLASS:
1135        case OP_NCLASS:
1136        size += 1 + 32 / sizeof(pcre_uchar);
1137        space = get_class_iterator_size(cc + size);
1138        break;
1139    
1140    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1141        case OP_XCLASS:
1142        size = GET(cc, 1);
1143        space = get_class_iterator_size(cc + size);
1144        break;
1145    #endif
1146    
1147      default:      default:
1148      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1149      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1150      break;      break;
1151      }      }
1152    
1153      /* Character iterators, which are not inside a repeated bracket,
1154         gets a private slot instead of allocating it on the stack. */
1155      if (space > 0 && cc >= end)
1156        {
1157        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1158        private_data_ptr += sizeof(sljit_sw) * space;
1159        }
1160    
1161      if (size != 0)
1162        {
1163        if (size < 0)
1164          {
1165          cc += -size;
1166    #ifdef SUPPORT_UTF
1167          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1168    #endif
1169          }
1170        else
1171          cc += size;
1172        }
1173    
1174      if (bracketlen > 0)
1175        {
1176        if (cc >= end)
1177          {
1178          end = bracketend(cc);
1179          if (end[-1 - LINK_SIZE] == OP_KET)
1180            end = NULL;
1181          }
1182        cc += bracketlen;
1183        }
1184    }    }
1185    *private_data_start = private_data_ptr;
1186  }  }
1187    
1188  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1189  static int get_framesize(compiler_common *common, uschar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL* needs_control_head)
1190  {  {
 uschar *ccend = bracketend(cc);  
 uschar *end;  
1191  int length = 0;  int length = 0;
1192  BOOL possessive = FALSE;  int possessive = 0;
1193  BOOL needs_frame = FALSE;  BOOL stack_restore = FALSE;
1194  BOOL setsom_found = FALSE;  BOOL setsom_found = recursive;
1195    BOOL setmark_found = recursive;
1196    /* The last capture is a local variable even for recursions. */
1197    BOOL capture_last_found = FALSE;
1198    
1199    #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1200    SLJIT_ASSERT(common->control_head_ptr != 0);
1201    *needs_control_head = TRUE;
1202    #else
1203    *needs_control_head = FALSE;
1204    #endif
1205    
1206  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (ccend == NULL)
1207    {    {
1208    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1209    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1210        {
1211        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1212        /* This is correct regardless of common->capture_last_ptr. */
1213        capture_last_found = TRUE;
1214        }
1215      cc = next_opcode(common, cc);
1216    }    }
1217    
 cc = next_opcode(common, cc);  
1218  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1219  while (cc < ccend)  while (cc < ccend)
1220    switch(*cc)    switch(*cc)
1221      {      {
1222      case OP_SET_SOM:      case OP_SET_SOM:
1223      case OP_RECURSE:      SLJIT_ASSERT(common->has_set_som);
1224        stack_restore = TRUE;
1225      if (!setsom_found)      if (!setsom_found)
1226        {        {
1227        length += 2;        length += 2;
1228        setsom_found = TRUE;        setsom_found = TRUE;
1229        }        }
1230      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      cc += 1;
1231      break;      break;
1232    
1233      case OP_ASSERT:      case OP_MARK:
1234      case OP_ASSERT_NOT:      case OP_PRUNE_ARG:
1235      case OP_ASSERTBACK:      case OP_THEN_ARG:
1236      case OP_ASSERTBACK_NOT:      SLJIT_ASSERT(common->mark_ptr != 0);
1237      case OP_ONCE:      stack_restore = TRUE;
1238      if (needs_frame || length > 0)      if (!setmark_found)
1239        {        {
1240        cc = bracketend(cc);        length += 2;
1241        break;        setmark_found = TRUE;
1242        }        }
1243      /* Check whether a frame must be created. */      if (common->control_head_ptr != 0)
1244      end = bracketend(cc);        *needs_control_head = TRUE;
1245      while (cc < end)      cc += 1 + 2 + cc[1];
1246        {      break;
1247        if (*cc == OP_SET_SOM || *cc == OP_CBRA || *cc == OP_CBRAPOS  
1248            || *cc == OP_SCBRA || *cc == OP_SCBRAPOS || *cc == OP_RECURSE)      case OP_RECURSE:
1249          needs_frame = TRUE;      stack_restore = TRUE;
1250        cc = next_opcode(common, cc);      if (common->has_set_som && !setsom_found)
1251        SLJIT_ASSERT(cc != NULL);        {
1252          length += 2;
1253          setsom_found = TRUE;
1254          }
1255        if (common->mark_ptr != 0 && !setmark_found)
1256          {
1257          length += 2;
1258          setmark_found = TRUE;
1259          }
1260        if (common->capture_last_ptr != 0 && !capture_last_found)
1261          {
1262          length += 2;
1263          capture_last_found = TRUE;
1264        }        }
1265        cc += 1 + LINK_SIZE;
1266      break;      break;
1267    
1268      case OP_CBRA:      case OP_CBRA:
1269      case OP_CBRAPOS:      case OP_CBRAPOS:
1270      case OP_SCBRA:      case OP_SCBRA:
1271      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1272        stack_restore = TRUE;
1273        if (common->capture_last_ptr != 0 && !capture_last_found)
1274          {
1275          length += 2;
1276          capture_last_found = TRUE;
1277          }
1278      length += 3;      length += 3;
1279      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1280      break;      break;
1281    
1282      default:      default:
1283        stack_restore = TRUE;
1284        /* Fall through. */
1285    
1286        case OP_NOT_WORD_BOUNDARY:
1287        case OP_WORD_BOUNDARY:
1288        case OP_NOT_DIGIT:
1289        case OP_DIGIT:
1290        case OP_NOT_WHITESPACE:
1291        case OP_WHITESPACE:
1292        case OP_NOT_WORDCHAR:
1293        case OP_WORDCHAR:
1294        case OP_ANY:
1295        case OP_ALLANY:
1296        case OP_ANYBYTE:
1297        case OP_NOTPROP:
1298        case OP_PROP:
1299        case OP_ANYNL:
1300        case OP_NOT_HSPACE:
1301        case OP_HSPACE:
1302        case OP_NOT_VSPACE:
1303        case OP_VSPACE:
1304        case OP_EXTUNI:
1305        case OP_EODN:
1306        case OP_EOD:
1307        case OP_CIRC:
1308        case OP_CIRCM:
1309        case OP_DOLL:
1310        case OP_DOLLM:
1311        case OP_CHAR:
1312        case OP_CHARI:
1313        case OP_NOT:
1314        case OP_NOTI:
1315    
1316        case OP_EXACT:
1317        case OP_POSSTAR:
1318        case OP_POSPLUS:
1319        case OP_POSQUERY:
1320        case OP_POSUPTO:
1321    
1322        case OP_EXACTI:
1323        case OP_POSSTARI:
1324        case OP_POSPLUSI:
1325        case OP_POSQUERYI:
1326        case OP_POSUPTOI:
1327    
1328        case OP_NOTEXACT:
1329        case OP_NOTPOSSTAR:
1330        case OP_NOTPOSPLUS:
1331        case OP_NOTPOSQUERY:
1332        case OP_NOTPOSUPTO:
1333    
1334        case OP_NOTEXACTI:
1335        case OP_NOTPOSSTARI:
1336        case OP_NOTPOSPLUSI:
1337        case OP_NOTPOSQUERYI:
1338        case OP_NOTPOSUPTOI:
1339    
1340        case OP_TYPEEXACT:
1341        case OP_TYPEPOSSTAR:
1342        case OP_TYPEPOSPLUS:
1343        case OP_TYPEPOSQUERY:
1344        case OP_TYPEPOSUPTO:
1345    
1346        case OP_CLASS:
1347        case OP_NCLASS:
1348        case OP_XCLASS:
1349    
1350      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1351      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1352      break;      break;
1353      }      }
1354    
1355  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1356  if (SLJIT_UNLIKELY(possessive) && !needs_frame && length == 3 + 2)  if (SLJIT_UNLIKELY(possessive == length))
1357    return -1;    return stack_restore ? no_frame : no_stack;
1358    
1359  if (length > 0)  if (length > 0)
1360    return length + 2;    return length + 1;
1361  return needs_frame ? 0 : -1;  return stack_restore ? no_frame : no_stack;
1362  }  }
1363    
1364  static void init_frame(compiler_common *common, uschar *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)
1365  {  {
 /* TMP2 must contain STACK_TOP - (-STACK(stackpos)) */  
1366  DEFINE_COMPILER;  DEFINE_COMPILER;
1367  uschar *ccend = bracketend(cc);  BOOL setsom_found = recursive;
1368  BOOL setsom_found = FALSE;  BOOL setmark_found = recursive;
1369    /* The last capture is a local variable even for recursions. */
1370    BOOL capture_last_found = FALSE;
1371  int offset;  int offset;
1372    
1373  if (stackpos < stacktop)  /* >= 1 + shortest item size (2) */
1374    {  SLJIT_UNUSED_ARG(stacktop);
1375    SLJIT_ASSERT(stackpos + 1 == stacktop);  SLJIT_ASSERT(stackpos >= stacktop + 2);
   return;  
   }  
1376    
1377  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1378  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS_HEAD);  if (ccend == NULL)
1379  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS_HEAD, TMP2, 0);    {
1380  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacktop), TMP1, 0);    ccend = bracketend(cc) - (1 + LINK_SIZE);
1381      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1382        cc = next_opcode(common, cc);
1383      }
1384    
 if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  
   cc = next_opcode(common, cc);  
1385  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1386  while (cc < ccend)  while (cc < ccend)
1387    switch(*cc)    switch(*cc)
1388      {      {
1389      case OP_SET_SOM:      case OP_SET_SOM:
1390      case OP_RECURSE:      SLJIT_ASSERT(common->has_set_som);
1391      if (!setsom_found)      if (!setsom_found)
1392        {        {
1393        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1394        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1395        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1396          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1397          stackpos += (int)sizeof(sljit_sw);
1398          setsom_found = TRUE;
1399          }
1400        cc += 1;
1401        break;
1402    
1403        case OP_MARK:
1404        case OP_PRUNE_ARG:
1405        case OP_THEN_ARG:
1406        SLJIT_ASSERT(common->mark_ptr != 0);
1407        if (!setmark_found)
1408          {
1409          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1410          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1411          stackpos += (int)sizeof(sljit_sw);
1412          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1413          stackpos += (int)sizeof(sljit_sw);
1414          setmark_found = TRUE;
1415          }
1416        cc += 1 + 2 + cc[1];
1417        break;
1418    
1419        case OP_RECURSE:
1420        if (common->has_set_som && !setsom_found)
1421          {
1422          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1423          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1424          stackpos += (int)sizeof(sljit_sw);
1425          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1426          stackpos += (int)sizeof(sljit_sw);
1427          setsom_found = TRUE;
1428          }
1429        if (common->mark_ptr != 0 && !setmark_found)
1430          {
1431          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1432          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1433          stackpos += (int)sizeof(sljit_sw);
1434          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1435          stackpos += (int)sizeof(sljit_sw);
1436          setmark_found = TRUE;
1437          }
1438        if (common->capture_last_ptr != 0 && !capture_last_found)
1439          {
1440          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1441          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1442          stackpos += (int)sizeof(sljit_sw);
1443        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1444        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1445        setsom_found = TRUE;        capture_last_found = TRUE;
1446        }        }
1447      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
     break;  
   
     case OP_ASSERT:  
     case OP_ASSERT_NOT:  
     case OP_ASSERTBACK:  
     case OP_ASSERTBACK_NOT:  
     case OP_ONCE:  
     cc = bracketend(cc);  
1448      break;      break;
1449    
1450      case OP_CBRA:      case OP_CBRA:
1451      case OP_CBRAPOS:      case OP_CBRAPOS:
1452      case OP_SCBRA:      case OP_SCBRA:
1453      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1454        if (common->capture_last_ptr != 0 && !capture_last_found)
1455          {
1456          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1457          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1458          stackpos += (int)sizeof(sljit_sw);
1459          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1460          stackpos += (int)sizeof(sljit_sw);
1461          capture_last_found = TRUE;
1462          }
1463      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1464      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1465      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1466      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1467      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));
1468      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1469      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1470      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1471      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1472    
1473      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1474      break;      break;
1475    
1476      default:      default:
# Line 835  while (cc < ccend) Line 1479  while (cc < ccend)
1479      break;      break;
1480      }      }
1481    
1482  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1483  SLJIT_ASSERT(stackpos == STACK(stacktop + 1));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1484  }  }
1485    
1486  static SLJIT_INLINE int get_localsize(compiler_common *common, uschar *cc, uschar *ccend)  static SLJIT_INLINE int get_private_data_copy_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL needs_control_head)
1487  {  {
1488  int localsize = 2;  int private_data_length = needs_control_head ? 3 : 2;
1489  uschar *alternative;  int size;
1490  /* Calculate the sum of the local variables. */  pcre_uchar *alternative;
1491    /* Calculate the sum of the private machine words. */
1492  while (cc < ccend)  while (cc < ccend)
1493    {    {
1494      size = 0;
1495    switch(*cc)    switch(*cc)
1496      {      {
1497        case OP_KET:
1498        if (PRIVATE_DATA(cc) != 0)
1499          private_data_length++;
1500        cc += 1 + LINK_SIZE;
1501        break;
1502    
1503      case OP_ASSERT:      case OP_ASSERT:
1504      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1505      case OP_ASSERTBACK:      case OP_ASSERTBACK:
1506      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1507      case OP_ONCE:      case OP_ONCE:
1508        case OP_ONCE_NC:
1509      case OP_BRAPOS:      case OP_BRAPOS:
1510      case OP_SBRA:      case OP_SBRA:
1511      case OP_SBRAPOS:      case OP_SBRAPOS:
1512      case OP_SCOND:      case OP_SCOND:
1513      localsize++;      private_data_length++;
1514      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1515      break;      break;
1516    
1517      case OP_CBRA:      case OP_CBRA:
1518      case OP_SCBRA:      case OP_SCBRA:
1519      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1520      cc += 1 + LINK_SIZE + 2;        private_data_length++;
1521        cc += 1 + LINK_SIZE + IMM2_SIZE;
1522      break;      break;
1523    
1524      case OP_CBRAPOS:      case OP_CBRAPOS:
1525      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1526      localsize += 2;      private_data_length += 2;
1527      cc += 1 + LINK_SIZE + 2;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1528      break;      break;
1529    
1530      case OP_COND:      case OP_COND:
1531      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1532      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1533      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1534        localsize++;        private_data_length++;
1535      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1536      break;      break;
1537    
1538        CASE_ITERATOR_PRIVATE_DATA_1
1539        if (PRIVATE_DATA(cc))
1540          private_data_length++;
1541        cc += 2;
1542    #ifdef SUPPORT_UTF
1543        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1544    #endif
1545        break;
1546    
1547        CASE_ITERATOR_PRIVATE_DATA_2A
1548        if (PRIVATE_DATA(cc))
1549          private_data_length += 2;
1550        cc += 2;
1551    #ifdef SUPPORT_UTF
1552        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1553    #endif
1554        break;
1555    
1556        CASE_ITERATOR_PRIVATE_DATA_2B
1557        if (PRIVATE_DATA(cc))
1558          private_data_length += 2;
1559        cc += 2 + IMM2_SIZE;
1560    #ifdef SUPPORT_UTF
1561        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1562    #endif
1563        break;
1564    
1565        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1566        if (PRIVATE_DATA(cc))
1567          private_data_length++;
1568        cc += 1;
1569        break;
1570    
1571        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1572        if (PRIVATE_DATA(cc))
1573          private_data_length += 2;
1574        cc += 1;
1575        break;
1576    
1577        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1578        if (PRIVATE_DATA(cc))
1579          private_data_length += 2;
1580        cc += 1 + IMM2_SIZE;
1581        break;
1582    
1583        case OP_CLASS:
1584        case OP_NCLASS:
1585    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1586        case OP_XCLASS:
1587        size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1588    #else
1589        size = 1 + 32 / (int)sizeof(pcre_uchar);
1590    #endif
1591        if (PRIVATE_DATA(cc))
1592          private_data_length += get_class_iterator_size(cc + size);
1593        cc += size;
1594        break;
1595    
1596      default:      default:
1597      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1598      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
# Line 888  while (cc < ccend) Line 1600  while (cc < ccend)
1600      }      }
1601    }    }
1602  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1603  return localsize;  return private_data_length;
1604  }  }
1605    
1606  static void copy_locals(compiler_common *common, uschar *cc, uschar *ccend,  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,
1607    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1608  {  {
1609  DEFINE_COMPILER;  DEFINE_COMPILER;
1610  int srcw[2];  int srcw[2];
1611  int count;  int count, size;
1612  BOOL tmp1next = TRUE;  BOOL tmp1next = TRUE;
1613  BOOL tmp1empty = TRUE;  BOOL tmp1empty = TRUE;
1614  BOOL tmp2empty = TRUE;  BOOL tmp2empty = TRUE;
1615  uschar *alternative;  pcre_uchar *alternative;
1616  enum {  enum {
1617    start,    start,
1618    loop,    loop,
# Line 913  stacktop = STACK(stacktop - 1); Line 1625  stacktop = STACK(stacktop - 1);
1625    
1626  if (!save)  if (!save)
1627    {    {
1628    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1629    if (stackptr < stacktop)    if (stackptr < stacktop)
1630      {      {
1631      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1632      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1633      tmp1empty = FALSE;      tmp1empty = FALSE;
1634      }      }
1635    if (stackptr < stacktop)    if (stackptr < stacktop)
1636      {      {
1637      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1638      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1639      tmp2empty = FALSE;      tmp2empty = FALSE;
1640      }      }
1641    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1642    }    }
1643    
1644  while (status != end)  do
1645    {    {
1646    count = 0;    count = 0;
1647    switch(status)    switch(status)
1648      {      {
1649      case start:      case start:
1650      SLJIT_ASSERT(save);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1651      count = 1;      count = 1;
1652      srcw[0] = RECURSIVE_HEAD;      srcw[0] = common->recursive_head_ptr;
1653        if (needs_control_head)
1654          {
1655          SLJIT_ASSERT(common->control_head_ptr != 0);
1656          count = 2;
1657          srcw[1] = common->control_head_ptr;
1658          }
1659      status = loop;      status = loop;
1660      break;      break;
1661    
# Line 950  while (status != end) Line 1668  while (status != end)
1668    
1669      switch(*cc)      switch(*cc)
1670        {        {
1671          case OP_KET:
1672          if (PRIVATE_DATA(cc) != 0)
1673            {
1674            count = 1;
1675            srcw[0] = PRIVATE_DATA(cc);
1676            }
1677          cc += 1 + LINK_SIZE;
1678          break;
1679    
1680        case OP_ASSERT:        case OP_ASSERT:
1681        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1682        case OP_ASSERTBACK:        case OP_ASSERTBACK:
1683        case OP_ASSERTBACK_NOT:        case OP_ASSERTBACK_NOT:
1684        case OP_ONCE:        case OP_ONCE:
1685          case OP_ONCE_NC:
1686        case OP_BRAPOS:        case OP_BRAPOS:
1687        case OP_SBRA:        case OP_SBRA:
1688        case OP_SBRAPOS:        case OP_SBRAPOS:
1689        case OP_SCOND:        case OP_SCOND:
1690        count = 1;        count = 1;
1691        srcw[0] = PRIV(cc);        srcw[0] = PRIVATE_DATA(cc);
1692        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1693        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1694        break;        break;
1695    
1696        case OP_CBRA:        case OP_CBRA:
1697        case OP_SCBRA:        case OP_SCBRA:
1698        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1699        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1700        cc += 1 + LINK_SIZE + 2;          count = 1;
1701            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1702            }
1703          cc += 1 + LINK_SIZE + IMM2_SIZE;
1704        break;        break;
1705    
1706        case OP_CBRAPOS:        case OP_CBRAPOS:
1707        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1708        count = 2;        count = 2;
1709          srcw[0] = PRIVATE_DATA(cc);
1710        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1711        srcw[0] = PRIV(cc);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
1712        SLJIT_ASSERT(srcw[0] != 0);        cc += 1 + LINK_SIZE + IMM2_SIZE;
       cc += 1 + LINK_SIZE + 2;  
1713        break;        break;
1714    
1715        case OP_COND:        case OP_COND:
# Line 987  while (status != end) Line 1718  while (status != end)
1718        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1719          {          {
1720          count = 1;          count = 1;
1721          srcw[0] = PRIV(cc);          srcw[0] = PRIVATE_DATA(cc);
1722          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1723          }          }
1724        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1725        break;        break;
1726    
1727          CASE_ITERATOR_PRIVATE_DATA_1
1728          if (PRIVATE_DATA(cc))
1729            {
1730            count = 1;
1731            srcw[0] = PRIVATE_DATA(cc);
1732            }
1733          cc += 2;
1734    #ifdef SUPPORT_UTF
1735          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1736    #endif
1737          break;
1738    
1739          CASE_ITERATOR_PRIVATE_DATA_2A
1740          if (PRIVATE_DATA(cc))
1741            {
1742            count = 2;
1743            srcw[0] = PRIVATE_DATA(cc);
1744            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1745            }
1746          cc += 2;
1747    #ifdef SUPPORT_UTF
1748          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1749    #endif
1750          break;
1751    
1752          CASE_ITERATOR_PRIVATE_DATA_2B
1753          if (PRIVATE_DATA(cc))
1754            {
1755            count = 2;
1756            srcw[0] = PRIVATE_DATA(cc);
1757            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1758            }
1759          cc += 2 + IMM2_SIZE;
1760    #ifdef SUPPORT_UTF
1761          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1762    #endif
1763          break;
1764    
1765          CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1766          if (PRIVATE_DATA(cc))
1767            {
1768            count = 1;
1769            srcw[0] = PRIVATE_DATA(cc);
1770            }
1771          cc += 1;
1772          break;
1773    
1774          CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1775          if (PRIVATE_DATA(cc))
1776            {
1777            count = 2;
1778            srcw[0] = PRIVATE_DATA(cc);
1779            srcw[1] = srcw[0] + sizeof(sljit_sw);
1780            }
1781          cc += 1;
1782          break;
1783    
1784          CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1785          if (PRIVATE_DATA(cc))
1786            {
1787            count = 2;
1788            srcw[0] = PRIVATE_DATA(cc);
1789            srcw[1] = srcw[0] + sizeof(sljit_sw);
1790            }
1791          cc += 1 + IMM2_SIZE;
1792          break;
1793    
1794          case OP_CLASS:
1795          case OP_NCLASS:
1796    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1797          case OP_XCLASS:
1798          size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1799    #else
1800          size = 1 + 32 / (int)sizeof(pcre_uchar);
1801    #endif
1802          if (PRIVATE_DATA(cc))
1803            switch(get_class_iterator_size(cc + size))
1804              {
1805              case 1:
1806              count = 1;
1807              srcw[0] = PRIVATE_DATA(cc);
1808              break;
1809    
1810              case 2:
1811              count = 2;
1812              srcw[0] = PRIVATE_DATA(cc);
1813              srcw[1] = srcw[0] + sizeof(sljit_sw);
1814              break;
1815    
1816              default:
1817              SLJIT_ASSERT_STOP();
1818              break;
1819              }
1820          cc += size;
1821          break;
1822    
1823        default:        default:
1824        cc = next_opcode(common, cc);        cc = next_opcode(common, cc);
1825        SLJIT_ASSERT(cc != NULL);        SLJIT_ASSERT(cc != NULL);
# Line 1015  while (status != end) Line 1842  while (status != end)
1842          if (!tmp1empty)          if (!tmp1empty)
1843            {            {
1844            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1845            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1846            }            }
1847          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1848          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1026  while (status != end) Line 1853  while (status != end)
1853          if (!tmp2empty)          if (!tmp2empty)
1854            {            {
1855            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1856            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1857            }            }
1858          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1859          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1043  while (status != end) Line 1870  while (status != end)
1870          if (!tmp1empty)          if (!tmp1empty)
1871            {            {
1872            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1873            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1874            }            }
1875          tmp1next = FALSE;          tmp1next = FALSE;
1876          }          }
# Line 1055  while (status != end) Line 1882  while (status != end)
1882          if (!tmp2empty)          if (!tmp2empty)
1883            {            {
1884            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1885            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1886            }            }
1887          tmp1next = TRUE;          tmp1next = TRUE;
1888          }          }
1889        }        }
1890      }      }
1891    }    }
1892    while (status != end);
1893    
1894  if (save)  if (save)
1895    {    {
# Line 1070  if (save) Line 1898  if (save)
1898      if (!tmp1empty)      if (!tmp1empty)
1899        {        {
1900        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1901        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1902        }        }
1903      if (!tmp2empty)      if (!tmp2empty)
1904        {        {
1905        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1906        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1907        }        }
1908      }      }
1909    else    else
# Line 1083  if (save) Line 1911  if (save)
1911      if (!tmp2empty)      if (!tmp2empty)
1912        {        {
1913        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1914        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1915        }        }
1916      if (!tmp1empty)      if (!tmp1empty)
1917        {        {
1918        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1919        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1920        }        }
1921      }      }
1922    }    }
1923  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1924  }  }
1925    
1926  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)
1927    {
1928    pcre_uchar *end = bracketend(cc);
1929    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1930    
1931    /* Assert captures then. */
1932    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1933      current_offset = NULL;
1934    /* Conditional block does not. */
1935    if (*cc == OP_COND || *cc == OP_SCOND)
1936      has_alternatives = FALSE;
1937    
1938    cc = next_opcode(common, cc);
1939    if (has_alternatives)
1940      current_offset = common->then_offsets + (cc - common->start);
1941    
1942    while (cc < end)
1943      {
1944      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1945        cc = set_then_offsets(common, cc, current_offset);
1946      else
1947        {
1948        if (*cc == OP_ALT && has_alternatives)
1949          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1950        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1951          *current_offset = 1;
1952        cc = next_opcode(common, cc);
1953        }
1954      }
1955    
1956    return end;
1957    }
1958    
1959    #undef CASE_ITERATOR_PRIVATE_DATA_1
1960    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1961    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1962    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1963    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1964    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1965    
1966    static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1967  {  {
1968  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1969  }  }
# Line 1105  static SLJIT_INLINE void set_jumps(jump_ Line 1973  static SLJIT_INLINE void set_jumps(jump_
1973  while (list)  while (list)
1974    {    {
1975    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1976    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1977    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1978    list = list->next;    list = list->next;
1979    }    }
1980  }  }
# Line 1122  if (list_item) Line 1990  if (list_item)
1990    }    }
1991  }  }
1992    
1993  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)
1994  {  {
1995  DEFINE_COMPILER;  DEFINE_COMPILER;
1996  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1997    
1998  if (list_item)  if (list_item)
1999    {    {
   list_item->type = type;  
   list_item->data = data;  
2000    list_item->start = start;    list_item->start = start;
2001    list_item->leave = LABEL();    list_item->quit = LABEL();
2002    list_item->next = common->stubs;    list_item->next = common->stubs;
2003    common->stubs = list_item;    common->stubs = list_item;
2004    }    }
# Line 1146  stub_list* list_item = common->stubs; Line 2012  stub_list* list_item = common->stubs;
2012  while (list_item)  while (list_item)
2013    {    {
2014    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2015    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
2016      {    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);  
2017    list_item = list_item->next;    list_item = list_item->next;
2018    }    }
2019  common->stubs = NULL;  common->stubs = NULL;
2020  }  }
2021    
2022  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2023  {  {
2024  DEFINE_COMPILER;  DEFINE_COMPILER;
2025    
2026  OP2(SLJIT_SUB | SLJIT_SET_E, CALL_COUNT, 0, CALL_COUNT, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, COUNT_MATCH, 0, COUNT_MATCH, 0, SLJIT_IMM, 1);
2027  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2028  }  }
2029    
# Line 1171  static SLJIT_INLINE void allocate_stack( Line 2032  static SLJIT_INLINE void allocate_stack(
2032  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2033  DEFINE_COMPILER;  DEFINE_COMPILER;
2034    
2035  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));
2036  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2037  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2038  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1179  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 2040  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2040  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2041  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2042  #endif  #endif
2043  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));
2044  }  }
2045    
2046  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2047  {  {
2048  DEFINE_COMPILER;  DEFINE_COMPILER;
2049  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));
2050  }  }
2051    
2052  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1193  static SLJIT_INLINE void reset_ovector(c Line 2054  static SLJIT_INLINE void reset_ovector(c
2054  DEFINE_COMPILER;  DEFINE_COMPILER;
2055  struct sljit_label *loop;  struct sljit_label *loop;
2056  int i;  int i;
2057    
2058  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2059    SLJIT_ASSERT(length > 1);
2060  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2061  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_GENERAL_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, 1);  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
2062    if (length < 8)
2063      {
2064      for (i = 1; i < length; i++)
2065        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2066      }
2067    else
2068      {
2069      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2070      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2071      loop = LABEL();
2072      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2073      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2074      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2075      }
2076    }
2077    
2078    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2079    {
2080    DEFINE_COMPILER;
2081    struct sljit_label *loop;
2082    int i;
2083    
2084    SLJIT_ASSERT(length > 1);
2085    /* OVECTOR(1) contains the "string begin - 1" constant. */
2086    if (length > 2)
2087      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2088  if (length < 8)  if (length < 8)
2089    {    {
2090    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
2091      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);
2092    }    }
2093  else  else
2094    {    {
2095    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));
2096    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2097    loop = LABEL();    loop = LABEL();
2098    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);
2099    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);
2100    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2101    }    }
2102    
2103    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2104    if (common->mark_ptr != 0)
2105      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2106    if (common->control_head_ptr != 0)
2107      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2108    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2109    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2110    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2111    }
2112    
2113    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2114    {
2115    while (current != NULL)
2116      {
2117      switch (current[-2])
2118        {
2119        case type_then_trap:
2120        break;
2121    
2122        case type_mark:
2123        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2124          return current[-4];
2125        break;
2126    
2127        default:
2128        SLJIT_ASSERT_STOP();
2129        break;
2130        }
2131      current = (sljit_sw*)current[-1];
2132      }
2133    return -1;
2134  }  }
2135    
2136  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2137  {  {
2138  DEFINE_COMPILER;  DEFINE_COMPILER;
2139  struct sljit_label *loop;  struct sljit_label *loop;
2140  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2141    
2142  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2143  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));
2144  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);
2145    
2146  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2147  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));  if (common->mark_ptr != 0)
2148  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);
2149  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));
2150  OP2(SLJIT_ADD, SLJIT_GENERAL_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START);  if (common->mark_ptr != 0)
2151      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);
2152    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
2153    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));
2154    GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2155  /* Unlikely, but possible */  /* Unlikely, but possible */
2156  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);
2157  loop = LABEL();  loop = LABEL();
2158  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);
2159  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));
2160  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2161  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), sizeof(int), SLJIT_GENERAL_REG2, 0);  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2162  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2163    #endif
2164    OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);
2165    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
2166  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2167  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2168    
2169  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2170  if (topbracket > 1)  if (topbracket > 1)
2171    {    {
2172    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));
2173    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2174    
2175    /* OVECTOR(0) is never equal to SLJIT_GENERAL_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2176    loop = LABEL();    loop = LABEL();
2177    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)));
2178    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);
2179    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);
2180    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2181    }    }
2182  else  else
2183    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
2184  }  }
2185    
2186  static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, uschar* cc)  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)
2187    {
2188    DEFINE_COMPILER;
2189    struct sljit_jump *jump;
2190    
2191    SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);
2192    SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0
2193      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2194    
2195    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2196    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2197    OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, real_offset_count));
2198    CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
2199    
2200    /* Store match begin and end. */
2201    OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));
2202    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));
2203    
2204    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2205    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);
2206    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2207    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2208    #endif
2209    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2210    JUMPHERE(jump);
2211    
2212    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);
2213    OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);
2214    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2215    OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2216    #endif
2217    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);
2218    
2219    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG1, 0);
2220    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2221    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2222    #endif
2223    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0, SLJIT_SCRATCH_REG3, 0);
2224    
2225    JUMPTO(SLJIT_JUMP, quit);
2226    }
2227    
2228    static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)
2229    {
2230    /* May destroy TMP1. */
2231    DEFINE_COMPILER;
2232    struct sljit_jump *jump;
2233    
2234    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2235      {
2236      /* The value of -1 must be kept for start_used_ptr! */
2237      OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, 1);
2238      /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting
2239      is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */
2240      jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, STR_PTR, 0);
2241      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2242      JUMPHERE(jump);
2243      }
2244    else if (common->mode == JIT_PARTIAL_HARD_COMPILE)
2245      {
2246      jump = CMP(SLJIT_C_LESS_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2247      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2248      JUMPHERE(jump);
2249      }
2250    }
2251    
2252    static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar* cc)
2253  {  {
2254  /* Detects if the character has an othercase. */  /* Detects if the character has an othercase. */
2255  unsigned int c;  unsigned int c;
2256    
2257  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2258  if (common->utf8)  if (common->utf)
2259    {    {
2260    GETCHAR(c, cc);    GETCHAR(c, cc);
2261    if (c > 127)    if (c > 127)
# Line 1272  if (common->utf8) Line 2266  if (common->utf8)
2266      return FALSE;      return FALSE;
2267  #endif  #endif
2268      }      }
2269    #ifndef COMPILE_PCRE8
2270      return common->fcc[c] != c;
2271    #endif
2272    }    }
2273  else  else
2274  #endif  #endif
2275    c = *cc;    c = *cc;
2276  return common->fcc[c] != c;  return MAX_255(c) ? common->fcc[c] != c : FALSE;
2277  }  }
2278    
2279  static SLJIT_INLINE unsigned int char_othercase(compiler_common *common, unsigned int c)  static SLJIT_INLINE unsigned int char_othercase(compiler_common *common, unsigned int c)
2280  {  {
2281  /* Returns with the othercase. */  /* Returns with the othercase. */
2282  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2283  if (common->utf8 && c > 127)  if (common->utf && c > 127)
2284    {    {
2285  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2286    return UCD_OTHERCASE(c);    return UCD_OTHERCASE(c);
# Line 1292  if (common->utf8 && c > 127) Line 2289  if (common->utf8 && c > 127)
2289  #endif  #endif
2290    }    }
2291  #endif  #endif
2292  return common->fcc[c];  return TABLE_GET(c, common->fcc, c);
2293  }  }
2294    
2295  static unsigned int char_get_othercase_bit(compiler_common *common, uschar* cc)  static unsigned int char_get_othercase_bit(compiler_common *common, pcre_uchar* cc)
2296  {  {
2297  /* Detects if the character and its othercase has only 1 bit difference. */  /* Detects if the character and its othercase has only 1 bit difference. */
2298  unsigned int c, oc, bit;  unsigned int c, oc, bit;
2299  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2300  int n;  int n;
2301  #endif  #endif
2302    
2303  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2304  if (common->utf8)  if (common->utf)
2305    {    {
2306    GETCHAR(c, cc);    GETCHAR(c, cc);
2307    if (c <= 127)    if (c <= 127)
# Line 1321  if (common->utf8) Line 2318  if (common->utf8)
2318  else  else
2319    {    {
2320    c = *cc;    c = *cc;
2321    oc = common->fcc[c];    oc = TABLE_GET(c, common->fcc, c);
2322    }    }
2323  #else  #else
2324  c = *cc;  c = *cc;
2325  oc = common->fcc[c];  oc = TABLE_GET(c, common->fcc, c);
2326  #endif  #endif
2327    
2328  SLJIT_ASSERT(c != oc);  SLJIT_ASSERT(c != oc);
# Line 1336  if (c <= 127 && bit == 0x20) Line 2333  if (c <= 127 && bit == 0x20)
2333    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2334    
2335  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2336  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2337    return 0;    return 0;
2338    
2339  #ifdef SUPPORT_UTF8  #if defined COMPILE_PCRE8
2340  if (common->utf8 && c > 127)  
2341    #ifdef SUPPORT_UTF
2342    if (common->utf && c > 127)
2343    {    {
2344    n = _pcre_utf8_table4[*cc & 0x3f];    n = GET_EXTRALEN(*cc);
2345    while ((bit & 0x3f) == 0)    while ((bit & 0x3f) == 0)
2346      {      {
2347      n--;      n--;
# Line 1350  if (common->utf8 && c > 127) Line 2349  if (common->utf8 && c > 127)
2349      }      }
2350    return (n << 8) | bit;    return (n << 8) | bit;
2351    }    }
2352  #endif  #endif /* SUPPORT_UTF */
2353  return (0 << 8) | bit;  return (0 << 8) | bit;
2354    
2355    #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2356    
2357    #ifdef SUPPORT_UTF
2358    if (common->utf && c > 65535)
2359      {
2360      if (bit >= (1 << 10))
2361        bit >>= 10;
2362      else
2363        return (bit < 256) ? ((2 << 8) | bit) : ((3 << 8) | (bit >> 8));
2364      }
2365    #endif /* SUPPORT_UTF */
2366    return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
2367    
2368    #endif /* COMPILE_PCRE[8|16|32] */
2369    }
2370    
2371    static void check_partial(compiler_common *common, BOOL force)
2372    {
2373    /* Checks whether a partial matching is occurred. Does not modify registers. */
2374    DEFINE_COMPILER;
2375    struct sljit_jump *jump = NULL;
2376    
2377    SLJIT_ASSERT(!force || common->mode != JIT_COMPILE);
2378    
2379    if (common->mode == JIT_COMPILE)
2380      return;
2381    
2382    if (!force)
2383      jump = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2384    else if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2385      jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2386    
2387    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2388      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2389    else
2390      {
2391      if (common->partialmatchlabel != NULL)
2392        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2393      else
2394        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2395      }
2396    
2397    if (jump != NULL)
2398      JUMPHERE(jump);
2399    }
2400    
2401    static void check_str_end(compiler_common *common, jump_list **end_reached)
2402    {
2403    /* Does not affect registers. Usually used in a tight spot. */
2404    DEFINE_COMPILER;
2405    struct sljit_jump *jump;
2406    
2407    if (common->mode == JIT_COMPILE)
2408      {
2409      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2410      return;
2411      }
2412    
2413    jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2414    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2415      {
2416      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2417      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2418      add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
2419      }
2420    else
2421      {
2422      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2423      if (common->partialmatchlabel != NULL)
2424        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2425      else
2426        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2427      }
2428    JUMPHERE(jump);
2429  }  }
2430    
2431  static SLJIT_INLINE void check_input_end(compiler_common *common, jump_list **fallbacks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
2432  {  {
2433  DEFINE_COMPILER;  DEFINE_COMPILER;
2434  add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));  struct sljit_jump *jump;
2435    
2436    if (common->mode == JIT_COMPILE)
2437      {
2438      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2439      return;
2440      }
2441    
2442    /* Partial matching mode. */
2443    jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2444    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2445    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2446      {
2447      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2448      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2449      }
2450    else
2451      {
2452      if (common->partialmatchlabel != NULL)
2453        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2454      else
2455        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2456      }
2457    JUMPHERE(jump);
2458  }  }
2459    
2460  static void read_char(compiler_common *common)  static void read_char(compiler_common *common)
# Line 1365  static void read_char(compiler_common *c Line 2462  static void read_char(compiler_common *c
2462  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2463  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2464  DEFINE_COMPILER;  DEFINE_COMPILER;
2465  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2466  struct sljit_jump *jump;  struct sljit_jump *jump;
2467  #endif  #endif
2468    
2469  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2470  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2471  if (common->utf8)  if (common->utf)
2472    {    {
2473    /* Should not found a value between 128 and 192 here. */  #if defined COMPILE_PCRE8
2474    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 192);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2475    add_jump(compiler, &common->utf8readchar, JUMP(SLJIT_FAST_CALL));  #elif defined COMPILE_PCRE16
2476      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2477    #endif /* COMPILE_PCRE[8|16] */
2478      add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2479    JUMPHERE(jump);    JUMPHERE(jump);
2480    }    }
2481  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2482  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2483  }  }
2484    
2485  static void peek_char(compiler_common *common)  static void peek_char(compiler_common *common)
# Line 1387  static void peek_char(compiler_common *c Line 2487  static void peek_char(compiler_common *c
2487  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2488  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2489  DEFINE_COMPILER;  DEFINE_COMPILER;
2490  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2491  struct sljit_jump *jump;  struct sljit_jump *jump;
2492  #endif  #endif
2493    
2494  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2495  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2496  if (common->utf8)  if (common->utf)
2497    {    {
2498    /* Should not found a value between 128 and 192 here. */  #if defined COMPILE_PCRE8
2499    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 192);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2500    add_jump(compiler, &common->utf8readchar, JUMP(SLJIT_FAST_CALL));  #elif defined COMPILE_PCRE16
2501      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2502    #endif /* COMPILE_PCRE[8|16] */
2503      add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2504    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2505    JUMPHERE(jump);    JUMPHERE(jump);
2506    }    }
2507  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2508  }  }
2509    
2510  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2511  {  {
2512  /* 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. */
2513  DEFINE_COMPILER;  DEFINE_COMPILER;
2514  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2515  struct sljit_jump *jump;  struct sljit_jump *jump;
2516  #endif  #endif
2517    
2518  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2519  if (common->utf8)  if (common->utf)
2520    {    {
2521    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2522    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2523    #if defined COMPILE_PCRE8
2524    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2525    it is a clever early read in most cases. */    it is needed in most cases. */
2526      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2527      jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2528      add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2529      JUMPHERE(jump);
2530    #elif defined COMPILE_PCRE16
2531      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2532      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2533      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2534      JUMPHERE(jump);
2535      /* Skip low surrogate if necessary. */
2536      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2537      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2538      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2539      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2540      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2541    #elif defined COMPILE_PCRE32
2542      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2543      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2544    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
   /* Should not found a value between 128 and 192 here. */  
   jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 192);  
   add_jump(compiler, &common->utf8readtype8, JUMP(SLJIT_FAST_CALL));  
2545    JUMPHERE(jump);    JUMPHERE(jump);
2546    #endif /* COMPILE_PCRE[8|16|32] */
2547    return;    return;
2548    }    }
2549    #endif /* SUPPORT_UTF */
2550    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2551    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2552    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2553    /* The ctypes array contains only 256 values. */
2554    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2555    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2556    #endif
2557    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2558    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2559    JUMPHERE(jump);
2560  #endif  #endif
 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  
 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);  
2561  }  }
2562    
2563  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
2564  {  {
2565  /* Goes one character back. Only affects STR_PTR. Does not check begin. */  /* Goes one character back. Affects STR_PTR and TMP1. Does not check begin. */
2566  DEFINE_COMPILER;  DEFINE_COMPILER;
2567  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2568    #if defined COMPILE_PCRE8
2569  struct sljit_label *label;  struct sljit_label *label;
2570    
2571  if (common->utf8)  if (common->utf)
2572    {    {
2573    label = LABEL();    label = LABEL();
2574    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
2575    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2576    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);
2577    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2578    return;    return;
2579    }    }
2580  #endif  #elif defined COMPILE_PCRE16
2581  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  if (common->utf)
2582      {
2583      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
2584      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2585      /* Skip low surrogate if necessary. */
2586      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2587      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00);
2588      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2589      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2590      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2591      return;
2592      }
2593    #endif /* COMPILE_PCRE[8|16] */
2594    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2595    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2596  }  }
2597    
2598  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)
2599  {  {
2600  /* 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. */
2601  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1460  DEFINE_COMPILER; Line 2603  DEFINE_COMPILER;
2603  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2604    {    {
2605    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2606    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));
2607    }    }
2608  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2609    {    {
2610    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);
2611    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2612    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);
2613    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);
2614    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));
2615    }    }
2616  else  else
2617    {    {
2618    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline <= 255);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2619    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));
2620    }    }
2621  }  }
2622    
2623  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2624  static void do_utf8readchar(compiler_common *common)  
2625    #if defined COMPILE_PCRE8
2626    static void do_utfreadchar(compiler_common *common)
2627  {  {
2628  /* Fast decoding an utf8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2629  of the character (>= 192). Return char value in TMP1, length - 1 in TMP2. */  of the character (>= 0xc0). Return char value in TMP1, length - 1 in TMP2. */
2630  DEFINE_COMPILER;  DEFINE_COMPILER;
2631  struct sljit_jump *jump;  struct sljit_jump *jump;
2632    
2633  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2634  /* Searching for the first zero. */  /* Searching for the first zero. */
2635  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);
2636  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2637  /* 2 byte sequence */  /* Two byte sequence. */
2638  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2639  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2640  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);
2641  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2642  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2643  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2644  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
2645  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2646  JUMPHERE(jump);  JUMPHERE(jump);
2647    
2648  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);
2649  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2650  /* 3 byte sequence */  /* Three byte sequence. */
2651  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2652  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);
2653  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);
2654  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2655  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2656  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2657  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 2);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2658  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 2);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 2);  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 JUMPHERE(jump);  
   
 OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x08);  
 jump = JUMP(SLJIT_C_NOT_ZERO);  
 /* 4 byte sequence */  
 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 2);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 3);  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 3);  
2659  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2660  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2661  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 3);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2662  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2663  JUMPHERE(jump);  JUMPHERE(jump);
2664    
2665  /* 5 byte sequence */  /* Four byte sequence. */
2666  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 1);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2667  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x03);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);
2668  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 24);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 18);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 2);  
2669  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2670  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);
2671  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2672  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 3);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2673  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2674  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2675  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2676  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 4);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));
2677  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 4);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2678  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2679  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2680  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 4);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));
2681  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2682  }  }
2683    
2684  static void do_utf8readtype8(compiler_common *common)  static void do_utfreadtype8(compiler_common *common)
2685  {  {
2686  /* Fast decoding an utf8 character type. TMP2 contains the first byte  /* Fast decoding a UTF-8 character type. TMP2 contains the first byte
2687  of the character (>= 192) and TMP1 is destroyed. Return value in TMP1. */  of the character (>= 0xc0). Return value in TMP1. */
2688  DEFINE_COMPILER;  DEFINE_COMPILER;
2689  struct sljit_jump *jump;  struct sljit_jump *jump;
2690  struct sljit_jump *compare;  struct sljit_jump *compare;
2691    
2692  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2693    
2694  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);
2695  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2696  /* 2 byte sequence */  /* Two byte sequence. */
2697  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2698  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2699  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
2700  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2701  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
# Line 1590  sljit_emit_fast_return(compiler, RETURN_ Line 2710  sljit_emit_fast_return(compiler, RETURN_
2710  JUMPHERE(jump);  JUMPHERE(jump);
2711    
2712  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2713  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)_pcre_utf8_char_sizes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
 OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  
2714  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2715  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2716  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2717  }  }
2718    
2719  #endif  #elif defined COMPILE_PCRE16
2720    
2721    static void do_utfreadchar(compiler_common *common)
2722    {
2723    /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char
2724    of the character (>= 0xd800). Return char value in TMP1, length - 1 in TMP2. */
2725    DEFINE_COMPILER;
2726    struct sljit_jump *jump;
2727    
2728    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2729    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);
2730    /* Do nothing, only return. */
2731    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2732    
2733    JUMPHERE(jump);
2734    /* Combine two 16 bit characters. */
2735    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2736    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2737    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2738    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10);
2739    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3ff);
2740    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2741    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));
2742    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2743    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2744    }
2745    
2746    #endif /* COMPILE_PCRE[8|16] */
2747    
2748    #endif /* SUPPORT_UTF */
2749    
2750  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2751    
# Line 1613  DEFINE_COMPILER; Line 2761  DEFINE_COMPILER;
2761    
2762  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);
2763    
2764  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2765  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2766  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_w)_pcre_ucd_stage1);  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(ucd_stage1));
2767  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2768  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2769  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2770  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)_pcre_ucd_stage2);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2771  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2772  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_w)_pcre_ucd_records + SLJIT_OFFSETOF(ucd_record, chartype));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));
2773  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2774  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2775  }  }
# Line 1635  struct sljit_label *newlinelabel = NULL; Line 2783  struct sljit_label *newlinelabel = NULL;
2783  struct sljit_jump *start;  struct sljit_jump *start;
2784  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2785  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2786    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2787    struct sljit_jump *singlechar;
2788    #endif
2789  jump_list *newline = NULL;  jump_list *newline = NULL;
2790  BOOL newlinecheck = FALSE;  BOOL newlinecheck = FALSE;
2791  BOOL readbyte = FALSE;  BOOL readuchar = FALSE;
2792    
2793  if (!(hascrorlf || firstline) && (common->nltype == NLTYPE_ANY ||  if (!(hascrorlf || firstline) && (common->nltype == NLTYPE_ANY ||
2794      common->nltype == NLTYPE_ANYCRLF || common->newline > 255))      common->nltype == NLTYPE_ANYCRLF || common->newline > 255))
# Line 1646  if (!(hascrorlf || firstline) && (common Line 2797  if (!(hascrorlf || firstline) && (common
2797  if (firstline)  if (firstline)
2798    {    {
2799    /* Search for the end of the first line. */    /* Search for the end of the first line. */
2800    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2801    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
2802    
2803    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
2804      {      {
2805      mainloop = LABEL();      mainloop = LABEL();
2806      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2807      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2808      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -1);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
2809      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2810      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);
2811      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);
2812      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0, SLJIT_IMM, 1);      JUMPHERE(end);
2813        OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2814      }      }
2815    else    else
2816      {      {
2817      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2818      mainloop = LABEL();      mainloop = LABEL();
2819      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
2820      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2821      read_char(common);      read_char(common);
2822      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
2823      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2824      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);      JUMPHERE(end);
2825        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2826      set_jumps(newline, LABEL());      set_jumps(newline, LABEL());
2827      }      }
2828    
2829    JUMPHERE(end);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
   OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  
2830    }    }
2831    
2832  start = JUMP(SLJIT_JUMP);  start = JUMP(SLJIT_JUMP);
# Line 1682  start = JUMP(SLJIT_JUMP); Line 2834  start = JUMP(SLJIT_JUMP);
2834  if (newlinecheck)  if (newlinecheck)
2835    {    {
2836    newlinelabel = LABEL();    newlinelabel = LABEL();
2837    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2838    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2839    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2840    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);
2841    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2842    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2843      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2844    #endif
2845    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2846    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
2847    }    }
# Line 1694  if (newlinecheck) Line 2849  if (newlinecheck)
2849  mainloop = LABEL();  mainloop = LABEL();
2850    
2851  /* Increasing the STR_PTR here requires one less jump in the most common case. */  /* Increasing the STR_PTR here requires one less jump in the most common case. */
2852  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2853  if (common->utf8) readbyte = TRUE;  if (common->utf) readuchar = TRUE;
2854  #endif  #endif
2855  if (newlinecheck) readbyte = TRUE;  if (newlinecheck) readuchar = TRUE;
2856    
2857  if (readbyte)  if (readuchar)
2858    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2859    
2860  if (newlinecheck)  if (newlinecheck)
2861    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);
2862    
2863  #ifdef SUPPORT_UTF8  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2864  if (common->utf8)  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2865    #if defined COMPILE_PCRE8
2866    if (common->utf)
2867    {    {
2868    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)_pcre_utf8_char_sizes);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2869      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2870    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2871      JUMPHERE(singlechar);
2872    }    }
2873  else  #elif defined COMPILE_PCRE16
2874    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  if (common->utf)
2875  #else    {
2876  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2877  #endif    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2878      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2879      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2880      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2881      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2882      JUMPHERE(singlechar);
2883      }
2884    #endif /* COMPILE_PCRE[8|16] */
2885    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2886  JUMPHERE(start);  JUMPHERE(start);
2887    
2888  if (newlinecheck)  if (newlinecheck)
# Line 1727  if (newlinecheck) Line 2894  if (newlinecheck)
2894  return mainloop;  return mainloop;
2895  }  }
2896    
2897  static SLJIT_INLINE void fast_forward_first_byte(compiler_common *common, pcre_uint16 firstbyte, BOOL firstline)  #define MAX_N_CHARS 3
2898    
2899    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2900    {
2901    DEFINE_COMPILER;
2902    struct sljit_label *start;
2903    struct sljit_jump *quit;
2904    pcre_uint32 chars[MAX_N_CHARS * 2];
2905    pcre_uchar *cc = common->start + 1 + LINK_SIZE;
2906    int location = 0;
2907    pcre_int32 len, c, bit, caseless;
2908    int must_stop;
2909    
2910    /* We do not support alternatives now. */
2911    if (*(common->start + GET(common->start, 1)) == OP_ALT)
2912      return FALSE;
2913    
2914    while (TRUE)
2915      {
2916      caseless = 0;
2917      must_stop = 1;
2918      switch(*cc)
2919        {
2920        case OP_CHAR:
2921        must_stop = 0;
2922        cc++;
2923        break;
2924    
2925        case OP_CHARI:
2926        caseless = 1;
2927        must_stop = 0;
2928        cc++;
2929        break;
2930    
2931        case OP_SOD:
2932        case OP_SOM:
2933        case OP_SET_SOM:
2934        case OP_NOT_WORD_BOUNDARY:
2935        case OP_WORD_BOUNDARY:
2936        case OP_EODN:
2937        case OP_EOD:
2938        case OP_CIRC:
2939        case OP_CIRCM:
2940        case OP_DOLL:
2941        case OP_DOLLM:
2942        /* Zero width assertions. */
2943        cc++;
2944        continue;
2945    
2946        case OP_PLUS:
2947        case OP_MINPLUS:
2948        case OP_POSPLUS:
2949        cc++;
2950        break;
2951    
2952        case OP_EXACT:
2953        cc += 1 + IMM2_SIZE;
2954        break;
2955    
2956        case OP_PLUSI:
2957        case OP_MINPLUSI:
2958        case OP_POSPLUSI:
2959        caseless = 1;
2960        cc++;
2961        break;
2962    
2963        case OP_EXACTI:
2964        caseless = 1;
2965        cc += 1 + IMM2_SIZE;
2966        break;
2967    
2968        default:
2969        must_stop = 2;
2970        break;
2971        }
2972    
2973      if (must_stop == 2)
2974          break;
2975    
2976      len = 1;
2977    #ifdef SUPPORT_UTF
2978      if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
2979    #endif
2980    
2981      if (caseless && char_has_othercase(common, cc))
2982        {
2983        caseless = char_get_othercase_bit(common, cc);
2984        if (caseless == 0)
2985          return FALSE;
2986    #ifdef COMPILE_PCRE8
2987        caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
2988    #else
2989        if ((caseless & 0x100) != 0)
2990          caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));
2991        else
2992          caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));
2993    #endif
2994        }
2995      else
2996        caseless = 0;
2997    
2998      while (len > 0 && location < MAX_N_CHARS * 2)
2999        {
3000        c = *cc;
3001        bit = 0;
3002        if (len == (caseless & 0xff))
3003          {
3004          bit = caseless >> 8;
3005          c |= bit;
3006          }
3007    
3008        chars[location] = c;
3009        chars[location + 1] = bit;
3010    
3011        len--;
3012        location += 2;
3013        cc++;
3014        }
3015    
3016      if (location >= MAX_N_CHARS * 2 || must_stop != 0)
3017        break;
3018      }
3019    
3020    /* At least two characters are required. */
3021    if (location < 2 * 2)
3022        return FALSE;
3023    
3024    if (firstline)
3025      {
3026      SLJIT_ASSERT(common->first_line_end != 0);
3027      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3028      OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
3029      }
3030    else
3031      OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
3032    
3033    start = LABEL();
3034    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3035    
3036    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
3037    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3038    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3039    if (chars[1] != 0)
3040      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3041    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3042    if (location > 2 * 2)
3043      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
3044    if (chars[3] != 0)
3045      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
3046    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
3047    if (location > 2 * 2)
3048      {
3049      if (chars[5] != 0)
3050        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
3051      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);
3052      }
3053    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3054    
3055    JUMPHERE(quit);
3056    
3057    if (firstline)
3058      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3059    else
3060      OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
3061    return TRUE;
3062    }
3063    
3064    #undef MAX_N_CHARS
3065    
3066    static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)
3067  {  {
3068  DEFINE_COMPILER;  DEFINE_COMPILER;
3069  struct sljit_label *start;  struct sljit_label *start;
3070  struct sljit_jump *leave;  struct sljit_jump *quit;
3071  struct sljit_jump *found;  struct sljit_jump *found;
3072  pcre_uint16 oc, bit;  pcre_uchar oc, bit;
3073    
3074  if (firstline)  if (firstline)
3075    {    {
3076    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3077    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3078      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3079    }    }
3080    
3081  start = LABEL();  start = LABEL();
3082  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3083  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3084    
3085  if ((firstbyte & REQ_CASELESS) == 0)  oc = first_char;
3086    found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, firstbyte & 0xff);  if (caseless)
3087      {
3088      oc = TABLE_GET(first_char, common->fcc, first_char);
3089    #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
3090      if (first_char > 127 && common->utf)
3091        oc = UCD_OTHERCASE(first_char);
3092    #endif
3093      }
3094    if (first_char == oc)
3095      found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, first_char);
3096  else  else
3097    {    {
3098    firstbyte &= 0xff;    bit = first_char ^ oc;
3099    oc = common->fcc[firstbyte];    if (is_powerof2(bit))
   bit = firstbyte ^ oc;  
   if (ispowerof2(bit))  
3100      {      {
3101      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3102      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, firstbyte | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
3103      }      }
3104    else    else
3105      {      {
3106      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, firstbyte);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, first_char);
3107      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3108      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);
3109      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);
3110      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3111      }      }
3112    }    }
3113    
3114  #ifdef SUPPORT_UTF8  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 if (common->utf8)  
   {  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)_pcre_utf8_char_sizes);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   }  
 else  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  
 #else  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);  
 #endif  
3115  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3116  JUMPHERE(found);  JUMPHERE(found);
3117  JUMPHERE(leave);  JUMPHERE(quit);
3118    
3119  if (firstline)  if (firstline)
3120    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3121  }  }
3122    
3123  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 1792  DEFINE_COMPILER; Line 3126  DEFINE_COMPILER;
3126  struct sljit_label *loop;  struct sljit_label *loop;
3127  struct sljit_jump *lastchar;  struct sljit_jump *lastchar;
3128  struct sljit_jump *firstchar;  struct sljit_jump *firstchar;
3129  struct sljit_jump *leave;  struct sljit_jump *quit;
3130  struct sljit_jump *foundcr = NULL;  struct sljit_jump *foundcr = NULL;
3131  struct sljit_jump *notfoundnl;  struct sljit_jump *notfoundnl;
3132  jump_list *newline = NULL;  jump_list *newline = NULL;
3133    
3134  if (firstline)  if (firstline)
3135    {    {
3136    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3137    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3138      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3139    }    }
3140    
3141  if (common->nltype == NLTYPE_FIXED && common->newline > 255)  if (common->nltype == NLTYPE_FIXED && common->newline > 255)
# Line 1811  if (common->nltype == NLTYPE_FIXED && co Line 3146  if (common->nltype == NLTYPE_FIXED && co
3146    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));
3147    firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP2, 0);    firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP2, 0);
3148    
3149    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2);    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3150    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);
3151    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3152    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3153      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3154    #endif
3155    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3156    
3157    loop = LABEL();    loop = LABEL();
3158    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3159    leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3160    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -2);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
3161    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(STR_PTR), -1);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
3162    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);
3163    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);
3164    
3165    JUMPHERE(leave);    JUMPHERE(quit);
3166    JUMPHERE(firstchar);    JUMPHERE(firstchar);
3167    JUMPHERE(lastchar);    JUMPHERE(lastchar);
3168    
# Line 1848  set_jumps(newline, loop); Line 3186  set_jumps(newline, loop);
3186    
3187  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3188    {    {
3189    leave = JUMP(SLJIT_JUMP);    quit = JUMP(SLJIT_JUMP);
3190    JUMPHERE(foundcr);    JUMPHERE(foundcr);
3191    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3192    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3193    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);
3194    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3195    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3196      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3197    #endif
3198    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3199    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
3200    JUMPHERE(leave);    JUMPHERE(quit);
3201    }    }
3202  JUMPHERE(lastchar);  JUMPHERE(lastchar);
3203  JUMPHERE(firstchar);  JUMPHERE(firstchar);
3204    
3205  if (firstline)  if (firstline)
3206    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3207  }  }
3208    
3209    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3210    
3211  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)
3212  {  {
3213  DEFINE_COMPILER;  DEFINE_COMPILER;
3214  struct sljit_label *start;  struct sljit_label *start;
3215  struct sljit_jump *leave;  struct sljit_jump *quit;
3216  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3217    jump_list *matches = NULL;
3218    pcre_uint8 inverted_start_bits[32];
3219    int i;
3220    #ifndef COMPILE_PCRE8
3221    struct sljit_jump *jump;
3222    #endif
3223    
3224    for (i = 0; i < 32; ++i)
3225      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3226    
3227  if (firstline)  if (firstline)
3228    {    {
3229    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3230    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
3231      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3232    }    }
3233    
3234  start = LABEL();  start = LABEL();
3235  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3236  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3237  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3238  if (common->utf8)  if (common->utf)
3239    OP1(SLJIT_MOV_UB, TMP3, 0, SLJIT_MEM1(TMP1), (sljit_w)_pcre_utf8_char_sizes);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3240  #endif  #endif
3241  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);  
3242  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);  if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3243  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    {
3244  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);  #ifndef COMPILE_PCRE8
3245  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3246  found = JUMP(SLJIT_C_NOT_ZERO);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3247      JUMPHERE(jump);
3248  #ifdef SUPPORT_UTF8  #endif
3249  if (common->utf8)    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3250    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP3, 0);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3251  else    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3252    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3253  #else    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
3254  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, 1);    found = JUMP(SLJIT_C_NOT_ZERO);
3255      }
3256    
3257    #ifdef SUPPORT_UTF
3258    if (common->utf)
3259      OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3260  #endif  #endif
3261    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3262    #ifdef SUPPORT_UTF
3263    #if defined COMPILE_PCRE8
3264    if (common->utf)
3265      {
3266      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3267      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
3268      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3269      }
3270    #elif defined COMPILE_PCRE16
3271    if (common->utf)
3272      {
3273      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3274      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3275      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
3276      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3277      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3278      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3279      }
3280    #endif /* COMPILE_PCRE[8|16] */
3281    #endif /* SUPPORT_UTF */
3282  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3283  JUMPHERE(found);  if (found != NULL)
3284  JUMPHERE(leave);    JUMPHERE(found);
3285    if (matches != NULL)
3286      set_jumps(matches, LABEL());
3287    JUMPHERE(quit);
3288    
3289  if (firstline)  if (firstline)
3290    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0);
3291  }  }
3292    
3293  static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uint16 reqbyte, BOOL has_firstbyte)  static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uchar req_char, BOOL caseless, BOOL has_firstchar)
3294  {  {
3295  DEFINE_COMPILER;  DEFINE_COMPILER;
3296  struct sljit_label *loop;  struct sljit_label *loop;
# Line 1917  struct sljit_jump *alreadyfound; Line 3299  struct sljit_jump *alreadyfound;
3299  struct sljit_jump *found;  struct sljit_jump *found;
3300  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3301  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3302  pcre_uint16 oc, bit;  pcre_uint32 oc, bit;
3303    
3304  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_BYTE_PTR);  SLJIT_ASSERT(common->req_char_ptr != 0);
3305    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
3306  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);
3307  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);
3308  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);
3309    
3310  if (has_firstbyte)  if (has_firstchar)
3311    OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3312  else  else
3313    OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);
3314    
3315  loop = LABEL();  loop = LABEL();
3316  notfound = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, STR_END, 0);  notfound = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, STR_END, 0);
3317    
3318  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3319  if ((reqbyte & REQ_CASELESS) == 0)  oc = req_char;
3320    found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte & 0xff);  if (caseless)
3321      {
3322      oc = TABLE_GET(req_char, common->fcc, req_char);
3323    #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
3324      if (req_char > 127 && common->utf)
3325        oc = UCD_OTHERCASE(req_char);
3326    #endif
3327      }
3328    if (req_char == oc)
3329      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char);
3330  else  else
3331    {    {
3332    reqbyte &= 0xff;    bit = req_char ^ oc;
3333    oc = common->fcc[reqbyte];    if (is_powerof2(bit))
   bit = reqbyte ^ oc;  
   if (ispowerof2(bit))  
3334      {      {
3335      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3336      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
3337      }      }
3338    else    else
3339      {      {
3340      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char);
3341      foundoc = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, oc);      foundoc = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, oc);
3342      }      }
3343    }    }
3344  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
3345  JUMPTO(SLJIT_JUMP, loop);  JUMPTO(SLJIT_JUMP, loop);
3346    
3347  JUMPHERE(found);  JUMPHERE(found);
3348  if (foundoc)  if (foundoc)
3349    JUMPHERE(foundoc);    JUMPHERE(foundoc);
3350  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_BYTE_PTR, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr, TMP1, 0);
3351  JUMPHERE(alreadyfound);  JUMPHERE(alreadyfound);
3352  JUMPHERE(toolong);  JUMPHERE(toolong);
3353  return notfound;  return notfound;
# Line 1966  return notfound; Line 3356  return notfound;
3356  static void do_revertframes(compiler_common *common)  static void do_revertframes(compiler_common *common)
3357  {  {
3358  DEFINE_COMPILER;  DEFINE_COMPILER;
 struct sljit_jump *earlyexit;  
3359  struct sljit_jump *jump;  struct sljit_jump *jump;
3360  struct sljit_label *mainloop;  struct sljit_label *mainloop;
3361    
3362  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3363  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS_HEAD);  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);
3364    GET_LOCAL_BASE(TMP3, 0, 0);
3365    
3366  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
 earlyexit = CMP(SLJIT_C_LESS, TMP1, 0, STACK_TOP, 0);  
3367  mainloop = LABEL();  mainloop = LABEL();
3368  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3369  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);
3370  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_LOCALS_REG, 0);  jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3371  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  
3372  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);
3373  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));
3374    OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
3375    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw));
3376  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3377    
3378  JUMPHERE(jump);  JUMPHERE(jump);
3379  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3380  /* End of dropping frames. */  /* End of dropping frames. */
 OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  
 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS_HEAD, TMP1, 0);  
 CMPTO(SLJIT_C_GREATER_EQUAL, TMP1, 0, STACK_TOP, 0, mainloop);  
 JUMPHERE(earlyexit);  
3381  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3382    
3383  JUMPHERE(jump);  JUMPHERE(jump);
3384  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3385  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3386  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3387  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));  
3388  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3389  }  }
3390    
3391  static void check_wordboundary(compiler_common *common)  static void check_wordboundary(compiler_common *common)
3392  {  {
3393  DEFINE_COMPILER;  DEFINE_COMPILER;
3394  struct sljit_jump *beginend;  struct sljit_jump *skipread;
3395  #ifdef SUPPORT_UTF8  jump_list *skipread_list = NULL;
3396    #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3397  struct sljit_jump *jump;  struct sljit_jump *jump;
3398  #endif  #endif
3399    
3400  SLJIT_ASSERT(ctype_word == 0x10);  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);
3401    
3402  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);
3403  /* Get type of the previous char, and put it to LOCALS1. */  /* Get type of the previous char, and put it to LOCALS1. */
3404  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
3405  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));
3406  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);
3407  beginend = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);  skipread = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
3408  skip_char_back(common);  skip_char_back(common);
3409    check_start_used_ptr(common);
3410  read_char(common);  read_char(common);
3411    
3412  /* Testing char type. */  /* Testing char type. */
3413  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3414  if (common->useucp)  if (common->use_ucp)
3415    {    {
3416    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
3417    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
3418    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3419    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3420    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);
3421    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3422    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);
3423    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);
3424    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3425    JUMPHERE(jump);    JUMPHERE(jump);
3426    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3427    }    }
3428  else  else
3429  #endif  #endif
3430    {    {
3431  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3432      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3433    #elif defined SUPPORT_UTF
3434    /* Here LOCALS1 has already been zeroed. */    /* Here LOCALS1 has already been zeroed. */
3435    jump = NULL;    jump = NULL;
3436    if (common->utf8)    if (common->utf)
3437      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3438  #endif  #endif /* COMPILE_PCRE8 */
3439    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), common->ctypes);
3440    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 4 /* ctype_word */);
3441    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3442    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
3443  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3444      JUMPHERE(jump);
3445    #elif defined SUPPORT_UTF
3446    if (jump != NULL)    if (jump != NULL)
3447      JUMPHERE(jump);      JUMPHERE(jump);
3448  #endif  #endif /* COMPILE_PCRE8 */
3449    }    }
3450  JUMPHERE(beginend);  JUMPHERE(skipread);
3451    
3452  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3453  beginend = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  check_str_end(common, &skipread_list);
3454  peek_char(common);  peek_char(common);
3455    
3456  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
3457  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3458  if (common->useucp)  if (common->use_ucp)
3459    {    {
3460    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 1);
3461    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);    jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE);
3462    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3463    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3464    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);
3465    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3466    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);
3467    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);
3468    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3469    JUMPHERE(jump);    JUMPHERE(jump);
3470    }    }
3471  else  else
3472  #endif  #endif
3473    {    {
3474  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3475      /* TMP2 may be destroyed by peek_char. */
3476      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3477      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3478    #elif defined SUPPORT_UTF
3479    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3480    jump = NULL;    jump = NULL;
3481    if (common->utf8)    if (common->utf)
3482      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
3483  #endif  #endif
3484    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), common->ctypes);
3485    OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);    OP2(SLJIT_LSHR, TMP2, 0, TMP2, 0, SLJIT_IMM, 4 /* ctype_word */);
3486    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
3487  #ifdef SUPPORT_UTF8  #ifndef COMPILE_PCRE8
3488      JUMPHERE(jump);
3489    #elif defined SUPPORT_UTF
3490    if (jump != NULL)    if (jump != NULL)
3491      JUMPHERE(jump);      JUMPHERE(jump);
3492  #endif  #endif /* COMPILE_PCRE8 */
3493    }    }
3494  JUMPHERE(beginend);  set_jumps(skipread_list, LABEL());