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

Diff of /code/trunk/pcre_jit_compile.c

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

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