/[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 884 by zherczeg, Tue Jan 17 11:52:43 2012 UTC revision 1277 by zherczeg, Mon Mar 11 09:50:29 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11    The machine code generator part (this module) was written by Zoltan Herczeg    The machine code generator part (this module) was written by Zoltan Herczeg
12                        Copyright (c) 2010-2012                        Copyright (c) 2010-2013
13    
14  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
15  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 46  POSSIBILITY OF SUCH DAMAGE. Line 46  POSSIBILITY OF SUCH DAMAGE.
46    
47  #include "pcre_internal.h"  #include "pcre_internal.h"
48    
49  #ifdef SUPPORT_JIT  #if defined SUPPORT_JIT
50    
51  /* All-in-one: Since we use the JIT compiler only from here,  /* All-in-one: Since we use the JIT compiler only from here,
52  we just include it. This way we don't need to touch the build  we just include it. This way we don't need to touch the build
# Line 65  system files. */ Line 65  system files. */
65  #error Unsupported architecture  #error Unsupported architecture
66  #endif  #endif
67    
68  /* Allocate memory on the stack. Fast, but limited size. */  /* Defines for debugging purposes. */
 #define LOCAL_SPACE_SIZE 32768  
69    
70    /* 1 - Use unoptimized capturing brackets.
71       2 - Enable capture_last_ptr (includes option 1). */
72    /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */
73    
74    /* 1 - Always have a control head. */
75    /* #define DEBUG_FORCE_CONTROL_HEAD 1 */
76    
77    /* Allocate memory for the regex stack on the real machine stack.
78    Fast, but limited size. */
79    #define MACHINE_STACK_SIZE 32768
80    
81    /* Growth rate for stack allocated by the OS. Should be the multiply
82    of page size. */
83  #define STACK_GROWTH_RATE 8192  #define STACK_GROWTH_RATE 8192
84    
85  /* Enable to check that the allocation could destroy temporaries. */  /* Enable to check that the allocation could destroy temporaries. */
# Line 82  The code generator follows the recursive Line 94  The code generator follows the recursive
94  expressions. The basic blocks of regular expressions are condition checkers  expressions. The basic blocks of regular expressions are condition checkers
95  whose execute different commands depending on the result of the condition check.  whose execute different commands depending on the result of the condition check.
96  The relationship between the operators can be horizontal (concatenation) and  The relationship between the operators can be horizontal (concatenation) and
97  vertical (sub-expression) (See struct fallback_common for more details).  vertical (sub-expression) (See struct backtrack_common for more details).
98    
99    'ab' - 'a' and 'b' regexps are concatenated    'ab' - 'a' and 'b' regexps are concatenated
100    'a+' - 'a' is the sub-expression of the '+' operator    'a+' - 'a' is the sub-expression of the '+' operator
101    
102  The condition checkers are boolean (true/false) checkers. Machine code is generated  The condition checkers are boolean (true/false) checkers. Machine code is generated
103  for the checker itself and for the actions depending on the result of the checker.  for the checker itself and for the actions depending on the result of the checker.
104  The 'true' case is called as the hot path (expected path), and the other is called as  The 'true' case is called as the matching path (expected path), and the other is called as
105  the 'fallback' path. Branch instructions are expesive for all CPUs, so we avoid taken  the 'backtrack' path. Branch instructions are expesive for all CPUs, so we avoid taken
106  branches on the hot path.  branches on the matching path.
107    
108   Greedy star operator (*) :   Greedy star operator (*) :
109     Hot path: match happens.     Matching path: match happens.
110     Fallback path: match failed.     Backtrack path: match failed.
111   Non-greedy star operator (*?) :   Non-greedy star operator (*?) :
112     Hot path: no need to perform a match.     Matching path: no need to perform a match.
113     Fallback path: match is required.     Backtrack path: match is required.
114    
115  The following example shows how the code generated for a capturing bracket  The following example shows how the code generated for a capturing bracket
116  with two alternatives. Let A, B, C, D are arbirary regular expressions, and  with two alternatives. Let A, B, C, D are arbirary regular expressions, and
# Line 108  we have the following regular expression Line 120  we have the following regular expression
120    
121  The generated code will be the following:  The generated code will be the following:
122    
123   A hot path   A matching path
124   '(' hot path (pushing arguments to the stack)   '(' matching path (pushing arguments to the stack)
125   B hot path   B matching path
126   ')' hot path (pushing arguments to the stack)   ')' matching path (pushing arguments to the stack)
127   D hot path   D matching path
128   return with successful match   return with successful match
129    
130   D fallback path   D backtrack path
131   ')' fallback path (If we arrived from "C" jump to the fallback of "C")   ')' backtrack path (If we arrived from "C" jump to the backtrack of "C")
132   B fallback path   B backtrack path
133   C expected path   C expected path
134   jump to D hot path   jump to D matching path
135   C fallback path   C backtrack path
136   A fallback path   A backtrack path
137    
138   Notice, that the order of fallback code paths are the opposite of the fast   Notice, that the order of backtrack code paths are the opposite of the fast
139   code paths. In this way the topmost value on the stack is always belong   code paths. In this way the topmost value on the stack is always belong
140   to the current fallback code path. The fallback code path must check   to the current backtrack code path. The backtrack path must check
141   whether there is a next alternative. If so, it needs to jump back to   whether there is a next alternative. If so, it needs to jump back to
142   the hot path eventually. Otherwise it needs to clear out its own stack   the matching path eventually. Otherwise it needs to clear out its own stack
143   frame and continue the execution on the fallback code paths.   frame and continue the execution on the backtrack code paths.
144  */  */
145    
146  /*  /*
147  Saved stack frames:  Saved stack frames:
148    
149  Atomic blocks and asserts require reloading the values of local variables  Atomic blocks and asserts require reloading the values of private data
150  when the fallback mechanism performed. Because of OP_RECURSE, the locals  when the backtrack mechanism performed. Because of OP_RECURSE, the data
151  are not necessarly known in compile time, thus we need a dynamic restore  are not necessarly known in compile time, thus we need a dynamic restore
152  mechanism.  mechanism.
153    
154  The stack frames are stored in a chain list, and have the following format:  The stack frames are stored in a chain list, and have the following format:
155  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]
156    
157  Thus we can restore the locals to a particular point in the stack.  Thus we can restore the private data to a particular point in the stack.
158  */  */
159    
160  typedef struct jit_arguments {  typedef struct jit_arguments {
# Line 152  typedef struct jit_arguments { Line 164  typedef struct jit_arguments {
164    const pcre_uchar *begin;    const pcre_uchar *begin;
165    const pcre_uchar *end;    const pcre_uchar *end;
166    int *offsets;    int *offsets;
167    pcre_uchar *ptr;    pcre_uchar *uchar_ptr;
168      pcre_uchar *mark_ptr;
169      void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171    int offsetcount;    int real_offset_count;
172    int calllimit;    int offset_count;
173      int call_limit;
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
177    pcre_uint8 notempty_atstart;    pcre_uint8 notempty_atstart;
178  } jit_arguments;  } jit_arguments;
179    
180  typedef struct executable_function {  typedef struct executable_functions {
181    void *executable_func;    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184    sljit_uw executable_size;    pcre_uint32 top_bracket;
185  } executable_function;    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
186    } executable_functions;
187    
188  typedef struct jump_list {  typedef struct jump_list {
189    struct sljit_jump *jump;    struct sljit_jump *jump;
190    struct jump_list *next;    struct jump_list *next;
191  } jump_list;  } jump_list;
192    
 enum stub_types { stack_alloc };  
   
193  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
194    struct sljit_jump *start;    struct sljit_jump *start;
195    struct sljit_label *leave;    struct sljit_label *quit;
196    struct stub_list *next;    struct stub_list *next;
197  } stub_list;  } stub_list;
198    
199    enum frame_types {
200      no_frame = -1,
201      no_stack = -2
202    };
203    
204    enum control_types {
205      type_commit = 0,
206      type_prune = 1,
207      type_skip = 2
208    };
209    
210  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
213  code generator. It is allocated by compile_hotpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
214  the aguments for compile_fallbackpath. Must be the first member  the aguments for compile_backtrackingpath. Must be the first member
215  of its descendants. */  of its descendants. */
216  typedef struct fallback_common {  typedef struct backtrack_common {
217    /* Concatenation stack. */    /* Concatenation stack. */
218    struct fallback_common *prev;    struct backtrack_common *prev;
219    jump_list *nextfallbacks;    jump_list *nextbacktracks;
220    /* Internal stack (for component operators). */    /* Internal stack (for component operators). */
221    struct fallback_common *top;    struct backtrack_common *top;
222    jump_list *topfallbacks;    jump_list *topbacktracks;
223    /* Opcode pointer. */    /* Opcode pointer. */
224    pcre_uchar *cc;    pcre_uchar *cc;
225  } fallback_common;  } backtrack_common;
226    
227  typedef struct assert_fallback {  typedef struct assert_backtrack {
228    fallback_common common;    backtrack_common common;
229    jump_list *condfailed;    jump_list *condfailed;
230    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
231    int framesize;    int framesize;
232    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
233    int localptr;    int private_data_ptr;
234    /* For iterators. */    /* For iterators. */
235    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
236  } assert_fallback;  } assert_backtrack;
237    
238  typedef struct bracket_fallback {  typedef struct bracket_backtrack {
239    fallback_common common;    backtrack_common common;
240    /* Where to coninue if an alternative is successfully matched. */    /* Where to coninue if an alternative is successfully matched. */
241    struct sljit_label *althotpath;    struct sljit_label *alternative_matchingpath;
242    /* For rmin and rmax iterators. */    /* For rmin and rmax iterators. */
243    struct sljit_label *recursivehotpath;    struct sljit_label *recursive_matchingpath;
244    /* For greedy ? operator. */    /* For greedy ? operator. */
245    struct sljit_label *zerohotpath;    struct sljit_label *zero_matchingpath;
246    /* Contains the branches of a failed condition. */    /* Contains the branches of a failed condition. */
247    union {    union {
248      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
249      jump_list *condfailed;      jump_list *condfailed;
250      assert_fallback *assert;      assert_backtrack *assert;
251      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
252      int framesize;      int framesize;
253    } u;    } u;
254    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
255    int localptr;    int private_data_ptr;
256  } bracket_fallback;  } bracket_backtrack;
257    
258  typedef struct bracketpos_fallback {  typedef struct bracketpos_backtrack {
259    fallback_common common;    backtrack_common common;
260    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
261    int localptr;    int private_data_ptr;
262    /* Reverting stack is needed. */    /* Reverting stack is needed. */
263    int framesize;    int framesize;
264    /* Allocated stack size. */    /* Allocated stack size. */
265    int stacksize;    int stacksize;
266  } bracketpos_fallback;  } bracketpos_backtrack;
267    
268  typedef struct braminzero_fallback {  typedef struct braminzero_backtrack {
269    fallback_common common;    backtrack_common common;
270    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
271  } braminzero_fallback;  } braminzero_backtrack;
272    
273  typedef struct iterator_fallback {  typedef struct iterator_backtrack {
274    fallback_common common;    backtrack_common common;
275    /* Next iteration. */    /* Next iteration. */
276    struct sljit_label *hotpath;    struct sljit_label *matchingpath;
277  } iterator_fallback;  } iterator_backtrack;
278    
279  typedef struct recurse_entry {  typedef struct recurse_entry {
280    struct recurse_entry *next;    struct recurse_entry *next;
# Line 263  typedef struct recurse_entry { Line 286  typedef struct recurse_entry {
286    int start;    int start;
287  } recurse_entry;  } recurse_entry;
288    
289  typedef struct recurse_fallback {  typedef struct recurse_backtrack {
290    fallback_common common;    backtrack_common common;
291  } recurse_fallback;    BOOL inlined_pattern;
292    } recurse_backtrack;
293    
294    #define MAX_RANGE_SIZE 6
295    
296  typedef struct compiler_common {  typedef struct compiler_common {
297      /* The sljit ceneric compiler. */
298    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
299      /* First byte code. */
300    pcre_uchar *start;    pcre_uchar *start;
301    int localsize;    /* Maps private data offset to each opcode. */
302    int *localptrs;    int *private_data_ptrs;
303      /* Tells whether the capturing bracket is optimized. */
304      pcre_uint8 *optimized_cbracket;
305      /* Starting offset of private data for capturing brackets. */
306      int cbra_ptr;
307      /* Output vector starting point. Must be divisible by 2. */
308      int ovector_start;
309      /* Last known position of the requested byte. */
310      int req_char_ptr;
311      /* Head of the last recursion. */
312      int recursive_head_ptr;
313      /* First inspected character for partial matching. */
314      int start_used_ptr;
315      /* Starting pointer for partial soft matches. */
316      int hit_start;
317      /* End pointer of the first line. */
318      int first_line_end;
319      /* Points to the marked string. */
320      int mark_ptr;
321      /* Recursive control verb management chain. */
322      int control_head_ptr;
323      /* Points to the last matched capture block index. */
324      int capture_last_ptr;
325      /* Points to the starting position of the current match. */
326      int start_ptr;
327    
328      /* Flipped and lower case tables. */
329    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
330    sljit_w lcc;    sljit_sw lcc;
331    int cbraptr;    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
332      int mode;
333      /* \K is in the pattern. */
334      BOOL has_set_som;
335      /* Needs to know the start position anytime. */
336      BOOL needs_start_ptr;
337      /* Currently in recurse or assert. */
338      BOOL local_exit;
339      /* Newline control. */
340    int nltype;    int nltype;
341    int newline;    int newline;
342    int bsr_nltype;    int bsr_nltype;
343      /* Dollar endonly. */
344    int endonly;    int endonly;
345    sljit_w ctypes;    /* Tables. */
346      sljit_sw ctypes;
347      int digits[2 + MAX_RANGE_SIZE];
348      /* Named capturing brackets. */
349    sljit_uw name_table;    sljit_uw name_table;
350    sljit_w name_count;    sljit_sw name_count;
351    sljit_w name_entry_size;    sljit_sw name_entry_size;
352    struct sljit_label *acceptlabel;  
353      /* Labels and jump lists. */
354      struct sljit_label *partialmatchlabel;
355      struct sljit_label *quit_label;
356      struct sljit_label *forced_quit_label;
357      struct sljit_label *accept_label;
358    stub_list *stubs;    stub_list *stubs;
359    recurse_entry *entries;    recurse_entry *entries;
360    recurse_entry *currententry;    recurse_entry *currententry;
361      jump_list *partialmatch;
362      jump_list *quit;
363      jump_list *forced_quit;
364    jump_list *accept;    jump_list *accept;
365    jump_list *calllimit;    jump_list *calllimit;
366    jump_list *stackalloc;    jump_list *stackalloc;
# Line 297  typedef struct compiler_common { Line 371  typedef struct compiler_common {
371    jump_list *vspace;    jump_list *vspace;
372    jump_list *casefulcmp;    jump_list *casefulcmp;
373    jump_list *caselesscmp;    jump_list *caselesscmp;
374      jump_list *reset_match;
375    BOOL jscript_compat;    BOOL jscript_compat;
376  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
377    BOOL utf;    BOOL utf;
378  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
379    BOOL use_ucp;    BOOL use_ucp;
380  #endif  #endif
381    #ifndef COMPILE_PCRE32
382    jump_list *utfreadchar;    jump_list *utfreadchar;
383    #endif
384  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
385    jump_list *utfreadtype8;    jump_list *utfreadtype8;
386  #endif  #endif
# Line 321  typedef struct compare_context { Line 398  typedef struct compare_context {
398  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
399    int ucharptr;    int ucharptr;
400    union {    union {
401      sljit_i asint;      sljit_si asint;
402      sljit_uh asushort;      sljit_uh asushort;
403  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
404      sljit_ub asbyte;      sljit_ub asbyte;
405      sljit_ub asuchars[4];      sljit_ub asuchars[4];
406  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
407      sljit_uh asuchars[2];      sljit_uh asuchars[2];
408  #endif  #elif defined COMPILE_PCRE32
409        sljit_ui asuchars[1];
410  #endif  #endif
411    } c;    } c;
412    union {    union {
413      sljit_i asint;      sljit_si asint;
414      sljit_uh asushort;      sljit_uh asushort;
415  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
416      sljit_ub asbyte;      sljit_ub asbyte;
417      sljit_ub asuchars[4];      sljit_ub asuchars[4];
418  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
419      sljit_uh asuchars[2];      sljit_uh asuchars[2];
420  #endif  #elif defined COMPILE_PCRE32
421        sljit_ui asuchars[1];
422  #endif  #endif
423    } oc;    } oc;
424  #endif  #endif
425  } compare_context;  } compare_context;
426    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1  
 };  
   
427  /* Undefine sljit macros. */  /* Undefine sljit macros. */
428  #undef CMP  #undef CMP
429    
430  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
431  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
432    
433  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
434  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
435  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
436  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
437  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
438  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
439  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
440  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
441  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
442  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
443    
444  /* Locals layout. */  /* Local space layout. */
445  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
446  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
447  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
448  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
449  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
450  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
 /* Head of the last recursion. */  
 #define RECURSIVE_HEAD   (4 * sizeof(sljit_w))  
451  /* Max limit of recursions. */  /* Max limit of recursions. */
452  #define CALL_LIMIT       (5 * sizeof(sljit_w))  #define CALL_LIMIT       (4 * sizeof(sljit_sw))
 /* Last known position of the requested byte. */  
 #define REQ_CHAR_PTR     (6 * sizeof(sljit_w))  
 /* End pointer of the first line. */  
 #define FIRSTLINE_END    (7 * sizeof(sljit_w))  
453  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
454  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
455  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
456  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. */
457  #define OVECTOR_START    (8 * sizeof(sljit_w))  #define OVECTOR_START    (common->ovector_start)
458  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
459  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * sizeof(sljit_sw))
460  #define PRIV_DATA(cc)    (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
461    
462  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
463  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
464  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
465  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
466  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
467  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
468    #elif defined COMPILE_PCRE32
469    #define MOV_UCHAR  SLJIT_MOV_UI
470    #define MOVU_UCHAR SLJIT_MOVU_UI
471  #else  #else
472  #error Unsupported compiling mode  #error Unsupported compiling mode
473  #endif  #endif
 #endif  
474    
475  /* Shortcuts. */  /* Shortcuts. */
476  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 420  the start pointers when the end of the c Line 487  the start pointers when the end of the c
487    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
488  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
489    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
490    #define SET_LABEL(jump, label) \
491      sljit_set_label((jump), (label))
492  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
493    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
494  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
495    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))
496  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
497    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
498    #define GET_LOCAL_BASE(dst, dstw, offset) \
499      sljit_get_local_base(compiler, (dst), (dstw), (offset))
500    
501  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
502  {  {
# Line 438  return cc; Line 509  return cc;
509    
510  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
511   next_opcode   next_opcode
512   get_localspace   get_private_data_length
513   set_localptrs   set_private_data_ptrs
514   get_framesize   get_framesize
515   init_frame   init_frame
516   get_localsize   get_private_data_copy_length
517   copy_locals   copy_private_data
518   compile_hotpath   compile_matchingpath
519   compile_fallbackpath   compile_backtrackingpath
520  */  */
521    
522  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
# Line 466  switch(*cc) Line 537  switch(*cc)
537    case OP_WORDCHAR:    case OP_WORDCHAR:
538    case OP_ANY:    case OP_ANY:
539    case OP_ALLANY:    case OP_ALLANY:
540      case OP_NOTPROP:
541      case OP_PROP:
542    case OP_ANYNL:    case OP_ANYNL:
543    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
544    case OP_HSPACE:    case OP_HSPACE:
# Line 478  switch(*cc) Line 551  switch(*cc)
551    case OP_CIRCM:    case OP_CIRCM:
552    case OP_DOLL:    case OP_DOLL:
553    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:  
554    case OP_CRSTAR:    case OP_CRSTAR:
555    case OP_CRMINSTAR:    case OP_CRMINSTAR:
556    case OP_CRPLUS:    case OP_CRPLUS:
557    case OP_CRMINPLUS:    case OP_CRMINPLUS:
558    case OP_CRQUERY:    case OP_CRQUERY:
559    case OP_CRMINQUERY:    case OP_CRMINQUERY:
560      case OP_CRRANGE:
561      case OP_CRMINRANGE:
562      case OP_CLASS:
563      case OP_NCLASS:
564      case OP_REF:
565      case OP_REFI:
566      case OP_RECURSE:
567      case OP_CALLOUT:
568      case OP_ALT:
569      case OP_KET:
570      case OP_KETRMAX:
571      case OP_KETRMIN:
572      case OP_KETRPOS:
573      case OP_REVERSE:
574      case OP_ASSERT:
575      case OP_ASSERT_NOT:
576      case OP_ASSERTBACK:
577      case OP_ASSERTBACK_NOT:
578      case OP_ONCE:
579      case OP_ONCE_NC:
580      case OP_BRA:
581      case OP_BRAPOS:
582      case OP_CBRA:
583      case OP_CBRAPOS:
584      case OP_COND:
585      case OP_SBRA:
586      case OP_SBRAPOS:
587      case OP_SCBRA:
588      case OP_SCBRAPOS:
589      case OP_SCOND:
590      case OP_CREF:
591      case OP_NCREF:
592      case OP_RREF:
593      case OP_NRREF:
594    case OP_DEF:    case OP_DEF:
595    case OP_BRAZERO:    case OP_BRAZERO:
596    case OP_BRAMINZERO:    case OP_BRAMINZERO:
597    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
598      case OP_PRUNE:
599      case OP_SKIP:
600      case OP_COMMIT:
601    case OP_FAIL:    case OP_FAIL:
602    case OP_ACCEPT:    case OP_ACCEPT:
603    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
604      case OP_CLOSE:
605    case OP_SKIPZERO:    case OP_SKIPZERO:
606    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
607    
608    case OP_CHAR:    case OP_CHAR:
609    case OP_CHARI:    case OP_CHARI:
# Line 519  switch(*cc) Line 615  switch(*cc)
615    case OP_MINPLUS:    case OP_MINPLUS:
616    case OP_QUERY:    case OP_QUERY:
617    case OP_MINQUERY:    case OP_MINQUERY:
618      case OP_UPTO:
619      case OP_MINUPTO:
620      case OP_EXACT:
621    case OP_POSSTAR:    case OP_POSSTAR:
622    case OP_POSPLUS:    case OP_POSPLUS:
623    case OP_POSQUERY:    case OP_POSQUERY:
624      case OP_POSUPTO:
625    case OP_STARI:    case OP_STARI:
626    case OP_MINSTARI:    case OP_MINSTARI:
627    case OP_PLUSI:    case OP_PLUSI:
628    case OP_MINPLUSI:    case OP_MINPLUSI:
629    case OP_QUERYI:    case OP_QUERYI:
630    case OP_MINQUERYI:    case OP_MINQUERYI:
631      case OP_UPTOI:
632      case OP_MINUPTOI:
633      case OP_EXACTI:
634    case OP_POSSTARI:    case OP_POSSTARI:
635    case OP_POSPLUSI:    case OP_POSPLUSI:
636    case OP_POSQUERYI:    case OP_POSQUERYI:
637      case OP_POSUPTOI:
638    case OP_NOTSTAR:    case OP_NOTSTAR:
639    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
640    case OP_NOTPLUS:    case OP_NOTPLUS:
641    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
642    case OP_NOTQUERY:    case OP_NOTQUERY:
643    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
644      case OP_NOTUPTO:
645      case OP_NOTMINUPTO:
646      case OP_NOTEXACT:
647    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
648    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
649    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
650      case OP_NOTPOSUPTO:
651    case OP_NOTSTARI:    case OP_NOTSTARI:
652    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
653    case OP_NOTPLUSI:    case OP_NOTPLUSI:
654    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
655    case OP_NOTQUERYI:    case OP_NOTQUERYI:
656    case OP_NOTMINQUERYI:    case OP_NOTMINQUERYI:
   case OP_NOTPOSSTARI:  
   case OP_NOTPOSPLUSI:  
   case OP_NOTPOSQUERYI:  
   cc += 2;  
 #ifdef SUPPORT_UTF  
   if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
   return cc;  
   
   case OP_UPTO:  
   case OP_MINUPTO:  
   case OP_EXACT:  
   case OP_POSUPTO:  
   case OP_UPTOI:  
   case OP_MINUPTOI:  
   case OP_EXACTI:  
   case OP_POSUPTOI:  
   case OP_NOTUPTO:  
   case OP_NOTMINUPTO:  
   case OP_NOTEXACT:  
   case OP_NOTPOSUPTO:  
657    case OP_NOTUPTOI:    case OP_NOTUPTOI:
658    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
659    case OP_NOTEXACTI:    case OP_NOTEXACTI:
660      case OP_NOTPOSSTARI:
661      case OP_NOTPOSPLUSI:
662      case OP_NOTPOSQUERYI:
663    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
664    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
665  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
666    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
667  #endif  #endif
668    return cc;    return cc;
669    
670    case OP_NOTPROP:    /* Special cases. */
671    case OP_PROP:    case OP_TYPESTAR:
672    return cc + 1 + 2;    case OP_TYPEMINSTAR:
673      case OP_TYPEPLUS:
674      case OP_TYPEMINPLUS:
675      case OP_TYPEQUERY:
676      case OP_TYPEMINQUERY:
677    case OP_TYPEUPTO:    case OP_TYPEUPTO:
678    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
679    case OP_TYPEEXACT:    case OP_TYPEEXACT:
680      case OP_TYPEPOSSTAR:
681      case OP_TYPEPOSPLUS:
682      case OP_TYPEPOSQUERY:
683    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
684    case OP_REF:    return cc + PRIV(OP_lengths)[*cc] - 1;
   case OP_REFI:  
   case OP_CREF:  
   case OP_NCREF:  
   case OP_RREF:  
   case OP_NRREF:  
   case OP_CLOSE:  
   cc += 1 + IMM2_SIZE;  
   return cc;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   return cc + 1 + 2 * IMM2_SIZE;  
685    
686    case OP_CLASS:    case OP_ANYBYTE:
687    case OP_NCLASS:  #ifdef SUPPORT_UTF
688    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
689    #endif
690      return cc + 1;
691    
692  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
693    case OP_XCLASS:    case OP_XCLASS:
694    return cc + GET(cc, 1);    return cc + GET(cc, 1);
695  #endif  #endif
696    
697    case OP_RECURSE:    case OP_MARK:
698    case OP_ASSERT:    case OP_PRUNE_ARG:
699    case OP_ASSERT_NOT:    return cc + 1 + 2 + cc[1];
   case OP_ASSERTBACK:  
   case OP_ASSERTBACK_NOT:  
   case OP_REVERSE:  
   case OP_ONCE:  
   case OP_ONCE_NC:  
   case OP_BRA:  
   case OP_BRAPOS:  
   case OP_COND:  
   case OP_SBRA:  
   case OP_SBRAPOS:  
   case OP_SCOND:  
   case OP_ALT:  
   case OP_KET:  
   case OP_KETRMAX:  
   case OP_KETRMIN:  
   case OP_KETRPOS:  
   return cc + 1 + LINK_SIZE;  
   
   case OP_CBRA:  
   case OP_CBRAPOS:  
   case OP_SCBRA:  
   case OP_SCBRAPOS:  
   return cc + 1 + LINK_SIZE + IMM2_SIZE;  
700    
701    default:    default:
702    return NULL;    return NULL;
703    }    }
704  }  }
705    
706  static int get_localspace(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
707        case OP_MINSTAR: \
708        case OP_MINPLUS: \
709        case OP_QUERY: \
710        case OP_MINQUERY: \
711        case OP_MINSTARI: \
712        case OP_MINPLUSI: \
713        case OP_QUERYI: \
714        case OP_MINQUERYI: \
715        case OP_NOTMINSTAR: \
716        case OP_NOTMINPLUS: \
717        case OP_NOTQUERY: \
718        case OP_NOTMINQUERY: \
719        case OP_NOTMINSTARI: \
720        case OP_NOTMINPLUSI: \
721        case OP_NOTQUERYI: \
722        case OP_NOTMINQUERYI:
723    
724    #define CASE_ITERATOR_PRIVATE_DATA_2A \
725        case OP_STAR: \
726        case OP_PLUS: \
727        case OP_STARI: \
728        case OP_PLUSI: \
729        case OP_NOTSTAR: \
730        case OP_NOTPLUS: \
731        case OP_NOTSTARI: \
732        case OP_NOTPLUSI:
733    
734    #define CASE_ITERATOR_PRIVATE_DATA_2B \
735        case OP_UPTO: \
736        case OP_MINUPTO: \
737        case OP_UPTOI: \
738        case OP_MINUPTOI: \
739        case OP_NOTUPTO: \
740        case OP_NOTMINUPTO: \
741        case OP_NOTUPTOI: \
742        case OP_NOTMINUPTOI:
743    
744    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
745        case OP_TYPEMINSTAR: \
746        case OP_TYPEMINPLUS: \
747        case OP_TYPEQUERY: \
748        case OP_TYPEMINQUERY:
749    
750    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
751        case OP_TYPESTAR: \
752        case OP_TYPEPLUS:
753    
754    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
755        case OP_TYPEUPTO: \
756        case OP_TYPEMINUPTO:
757    
758    static int get_class_iterator_size(pcre_uchar *cc)
759    {
760    switch(*cc)
761      {
762      case OP_CRSTAR:
763      case OP_CRPLUS:
764      return 2;
765    
766      case OP_CRMINSTAR:
767      case OP_CRMINPLUS:
768      case OP_CRQUERY:
769      case OP_CRMINQUERY:
770      return 1;
771    
772      case OP_CRRANGE:
773      case OP_CRMINRANGE:
774      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
775        return 0;
776      return 2;
777    
778      default:
779      return 0;
780      }
781    }
782    
783    static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
784  {  {
785  int localspace = 0;  int private_data_length = 0;
786  pcre_uchar *alternative;  pcre_uchar *alternative;
787    pcre_uchar *name;
788    pcre_uchar *end = NULL;
789    int space, size, i;
790    pcre_uint32 bracketlen;
791    
792  /* 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. */
793  while (cc < ccend)  while (cc < ccend)
794    {    {
795      space = 0;
796      size = 0;
797      bracketlen = 0;
798    switch(*cc)    switch(*cc)
799      {      {
800        case OP_SET_SOM:
801        common->has_set_som = TRUE;
802        cc += 1;
803        break;
804    
805        case OP_REF:
806        case OP_REFI:
807        common->optimized_cbracket[GET2(cc, 1)] = 0;
808        cc += 1 + IMM2_SIZE;
809        break;
810    
811      case OP_ASSERT:      case OP_ASSERT:
812      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
813      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 658  while (cc < ccend) Line 817  while (cc < ccend)
817      case OP_BRAPOS:      case OP_BRAPOS:
818      case OP_SBRA:      case OP_SBRA:
819      case OP_SBRAPOS:      case OP_SBRAPOS:
820      case OP_SCOND:      private_data_length += sizeof(sljit_sw);
821      localspace += sizeof(sljit_w);      bracketlen = 1 + LINK_SIZE;
     cc += 1 + LINK_SIZE;  
822      break;      break;
823    
824      case OP_CBRAPOS:      case OP_CBRAPOS:
825      case OP_SCBRAPOS:      case OP_SCBRAPOS:
826      localspace += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
827      cc += 1 + LINK_SIZE + IMM2_SIZE;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
828        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
829      break;      break;
830    
831      case OP_COND:      case OP_COND:
832      /* Might be a hidden SCOND. */      case OP_SCOND:
833      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
834      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
835        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
836          return -1;
837    
838        if (*cc == OP_COND)
839          {
840          /* Might be a hidden SCOND. */
841          alternative = cc + GET(cc, 1);
842          if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
843            private_data_length += sizeof(sljit_sw);
844          }
845        else
846          private_data_length += sizeof(sljit_sw);
847        bracketlen = 1 + LINK_SIZE;
848        break;
849    
850        case OP_CREF:
851        i = GET2(cc, 1);
852        common->optimized_cbracket[i] = 0;
853        cc += 1 + IMM2_SIZE;
854        break;
855    
856        case OP_NCREF:
857        bracketlen = GET2(cc, 1);
858        name = (pcre_uchar *)common->name_table;
859        alternative = name;
860        for (i = 0; i < common->name_count; i++)
861          {
862          if (GET2(name, 0) == bracketlen) break;
863          name += common->name_entry_size;
864          }
865        SLJIT_ASSERT(i != common->name_count);
866    
867        for (i = 0; i < common->name_count; i++)
868          {
869          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
870            common->optimized_cbracket[GET2(alternative, 0)] = 0;
871          alternative += common->name_entry_size;
872          }
873        bracketlen = 0;
874        cc += 1 + IMM2_SIZE;
875        break;
876    
877        case OP_BRA:
878        bracketlen = 1 + LINK_SIZE;
879        break;
880    
881        case OP_CBRA:
882        case OP_SCBRA:
883        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
884        break;
885    
886        CASE_ITERATOR_PRIVATE_DATA_1
887        space = 1;
888        size = -2;
889        break;
890    
891        CASE_ITERATOR_PRIVATE_DATA_2A
892        space = 2;
893        size = -2;
894        break;
895    
896        CASE_ITERATOR_PRIVATE_DATA_2B
897        space = 2;
898        size = -(2 + IMM2_SIZE);
899        break;
900    
901        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
902        space = 1;
903        size = 1;
904        break;
905    
906        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
907        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
908          space = 2;
909        size = 1;
910        break;
911    
912        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
913        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
914          space = 2;
915        size = 1 + IMM2_SIZE;
916        break;
917    
918        case OP_CLASS:
919        case OP_NCLASS:
920        size += 1 + 32 / sizeof(pcre_uchar);
921        space = get_class_iterator_size(cc + size);
922        break;
923    
924    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
925        case OP_XCLASS:
926        size = GET(cc, 1);
927        space = get_class_iterator_size(cc + size);
928        break;
929    #endif
930    
931        case OP_RECURSE:
932        /* Set its value only once. */
933        if (common->recursive_head_ptr == 0)
934          {
935          common->recursive_head_ptr = common->ovector_start;
936          common->ovector_start += sizeof(sljit_sw);
937          }
938      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
939      break;      break;
940    
941        case OP_CALLOUT:
942        if (common->capture_last_ptr == 0)
943          {
944          common->capture_last_ptr = common->ovector_start;
945          common->ovector_start += sizeof(sljit_sw);
946          }
947        cc += 2 + 2 * LINK_SIZE;
948        break;
949    
950        case OP_PRUNE_ARG:
951        common->needs_start_ptr = TRUE;
952        common->control_head_ptr = 1;
953        /* Fall through. */
954    
955        case OP_MARK:
956        if (common->mark_ptr == 0)
957          {
958          common->mark_ptr = common->ovector_start;
959          common->ovector_start += sizeof(sljit_sw);
960          }
961        cc += 1 + 2 + cc[1];
962        break;
963    
964        case OP_PRUNE:
965        case OP_SKIP:
966        common->needs_start_ptr = TRUE;
967        /* Fall through. */
968    
969        case OP_COMMIT:
970        common->control_head_ptr = 1;
971        cc += 1;
972        break;
973    
974      default:      default:
975      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
976      if (cc == NULL)      if (cc == NULL)
977        return -1;        return -1;
978      break;      break;
979      }      }
980    
981      if (space > 0 && cc >= end)
982        private_data_length += sizeof(sljit_sw) * space;
983    
984      if (size != 0)
985        {
986        if (size < 0)
987          {
988          cc += -size;
989    #ifdef SUPPORT_UTF
990          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
991    #endif
992          }
993        else
994          cc += size;
995        }
996    
997      if (bracketlen != 0)
998        {
999        if (cc >= end)
1000          {
1001          end = bracketend(cc);
1002          if (end[-1 - LINK_SIZE] == OP_KET)
1003            end = NULL;
1004          }
1005        cc += bracketlen;
1006        }
1007    }    }
1008  return localspace;  return private_data_length;
1009  }  }
1010    
1011  static void set_localptrs(compiler_common *common, int localptr, pcre_uchar *ccend)  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)
1012  {  {
1013  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1014  pcre_uchar *alternative;  pcre_uchar *alternative;
1015    pcre_uchar *end = NULL;
1016    int space, size, bracketlen;
1017    
1018  while (cc < ccend)  while (cc < ccend)
1019    {    {
1020      space = 0;
1021      size = 0;
1022      bracketlen = 0;
1023    switch(*cc)    switch(*cc)
1024      {      {
1025      case OP_ASSERT:      case OP_ASSERT:
# Line 705  while (cc < ccend) Line 1032  while (cc < ccend)
1032      case OP_SBRA:      case OP_SBRA:
1033      case OP_SBRAPOS:      case OP_SBRAPOS:
1034      case OP_SCOND:      case OP_SCOND:
1035      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1036      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1037      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1038        break;
1039    
1040        case OP_CBRAPOS:
1041        case OP_SCBRAPOS:
1042        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1043        private_data_ptr += sizeof(sljit_sw);
1044        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1045        break;
1046    
1047        case OP_COND:
1048        /* Might be a hidden SCOND. */
1049        alternative = cc + GET(cc, 1);
1050        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1051          {
1052          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1053          private_data_ptr += sizeof(sljit_sw);
1054          }
1055        bracketlen = 1 + LINK_SIZE;
1056        break;
1057    
1058        case OP_BRA:
1059        bracketlen = 1 + LINK_SIZE;
1060        break;
1061    
1062        case OP_CBRA:
1063        case OP_SCBRA:
1064        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1065        break;
1066    
1067        CASE_ITERATOR_PRIVATE_DATA_1
1068        space = 1;
1069        size = -2;
1070        break;
1071    
1072        CASE_ITERATOR_PRIVATE_DATA_2A
1073        space = 2;
1074        size = -2;
1075      break;      break;
1076    
1077      case OP_CBRAPOS:      CASE_ITERATOR_PRIVATE_DATA_2B
1078      case OP_SCBRAPOS:      space = 2;
1079      common->localptrs[cc - common->start] = localptr;      size = -(2 + IMM2_SIZE);
     localptr += sizeof(sljit_w);  
     cc += 1 + LINK_SIZE + IMM2_SIZE;  
1080      break;      break;
1081    
1082      case OP_COND:      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1083      /* Might be a hidden SCOND. */      space = 1;
1084      alternative = cc + GET(cc, 1);      size = 1;
1085      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      break;
1086        {  
1087        common->localptrs[cc - common->start] = localptr;      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1088        localptr += sizeof(sljit_w);      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1089        }        space = 2;
1090      cc += 1 + LINK_SIZE;      size = 1;
1091        break;
1092    
1093        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1094        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1095          space = 2;
1096        size = 1 + IMM2_SIZE;
1097        break;
1098    
1099        case OP_CLASS:
1100        case OP_NCLASS:
1101        size += 1 + 32 / sizeof(pcre_uchar);
1102        space = get_class_iterator_size(cc + size);
1103        break;
1104    
1105    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1106        case OP_XCLASS:
1107        size = GET(cc, 1);
1108        space = get_class_iterator_size(cc + size);
1109      break;      break;
1110    #endif
1111    
1112      default:      default:
1113      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1114      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1115      break;      break;
1116      }      }
1117    
1118      if (space > 0 && cc >= end)
1119        {
1120        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1121        private_data_ptr += sizeof(sljit_sw) * space;
1122        }
1123    
1124      if (size != 0)
1125        {
1126        if (size < 0)
1127          {
1128          cc += -size;
1129    #ifdef SUPPORT_UTF
1130          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1131    #endif
1132          }
1133        else
1134          cc += size;
1135        }
1136    
1137      if (bracketlen > 0)
1138        {
1139        if (cc >= end)
1140          {
1141          end = bracketend(cc);
1142          if (end[-1 - LINK_SIZE] == OP_KET)
1143            end = NULL;
1144          }
1145        cc += bracketlen;
1146        }
1147    }    }
1148  }  }
1149    
1150  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1151  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive, BOOL* needs_control_head)
1152  {  {
1153  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1154  int length = 0;  int length = 0;
1155  BOOL possessive = FALSE;  int possessive = 0;
1156  BOOL setsom_found = FALSE;  BOOL stack_restore = FALSE;
1157    BOOL setsom_found = recursive;
1158    BOOL setmark_found = recursive;
1159    /* The last capture is a local variable even for recursions. */
1160    BOOL capture_last_found = FALSE;
1161    
1162    #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1163    SLJIT_ASSERT(common->control_head_ptr != 0);
1164    *needs_control_head = TRUE;
1165    #else
1166    *needs_control_head = FALSE;
1167    #endif
1168    
1169  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1170    {    {
1171    length = 3;    possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1172    possessive = TRUE;    /* This is correct regardless of common->capture_last_ptr. */
1173      capture_last_found = TRUE;
1174    }    }
1175    
1176  cc = next_opcode(common, cc);  cc = next_opcode(common, cc);
# Line 756  while (cc < ccend) Line 1179  while (cc < ccend)
1179    switch(*cc)    switch(*cc)
1180      {      {
1181      case OP_SET_SOM:      case OP_SET_SOM:
1182      case OP_RECURSE:      SLJIT_ASSERT(common->has_set_som);
1183        stack_restore = TRUE;
1184      if (!setsom_found)      if (!setsom_found)
1185        {        {
1186        length += 2;        length += 2;
1187        setsom_found = TRUE;        setsom_found = TRUE;
1188        }        }
1189      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      cc += 1;
1190        break;
1191    
1192        case OP_MARK:
1193        case OP_PRUNE_ARG:
1194        SLJIT_ASSERT(common->mark_ptr != 0);
1195        stack_restore = TRUE;
1196        if (!setmark_found)
1197          {
1198          length += 2;
1199          setmark_found = TRUE;
1200          }
1201        if (common->control_head_ptr != 0)
1202          *needs_control_head = TRUE;
1203        cc += 1 + 2 + cc[1];
1204        break;
1205    
1206        case OP_RECURSE:
1207        stack_restore = TRUE;
1208        if (common->has_set_som && !setsom_found)
1209          {
1210          length += 2;
1211          setsom_found = TRUE;
1212          }
1213        if (common->mark_ptr != 0 && !setmark_found)
1214          {
1215          length += 2;
1216          setmark_found = TRUE;
1217          }
1218        if (common->capture_last_ptr != 0 && !capture_last_found)
1219          {
1220          length += 2;
1221          capture_last_found = TRUE;
1222          }
1223        cc += 1 + LINK_SIZE;
1224      break;      break;
1225    
1226      case OP_CBRA:      case OP_CBRA:
1227      case OP_CBRAPOS:      case OP_CBRAPOS:
1228      case OP_SCBRA:      case OP_SCBRA:
1229      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1230        stack_restore = TRUE;
1231        if (common->capture_last_ptr != 0 && !capture_last_found)
1232          {
1233          length += 2;
1234          capture_last_found = TRUE;
1235          }
1236      length += 3;      length += 3;
1237      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1238      break;      break;
1239    
1240        case OP_PRUNE:
1241        case OP_SKIP:
1242        case OP_COMMIT:
1243        if (common->control_head_ptr != 0)
1244          *needs_control_head = TRUE;
1245        /* Fall through. */
1246    
1247      default:      default:
1248        stack_restore = TRUE;
1249        /* Fall through. */
1250    
1251        case OP_NOT_WORD_BOUNDARY:
1252        case OP_WORD_BOUNDARY:
1253        case OP_NOT_DIGIT:
1254        case OP_DIGIT:
1255        case OP_NOT_WHITESPACE:
1256        case OP_WHITESPACE:
1257        case OP_NOT_WORDCHAR:
1258        case OP_WORDCHAR:
1259        case OP_ANY:
1260        case OP_ALLANY:
1261        case OP_ANYBYTE:
1262        case OP_NOTPROP:
1263        case OP_PROP:
1264        case OP_ANYNL:
1265        case OP_NOT_HSPACE:
1266        case OP_HSPACE:
1267        case OP_NOT_VSPACE:
1268        case OP_VSPACE:
1269        case OP_EXTUNI:
1270        case OP_EODN:
1271        case OP_EOD:
1272        case OP_CIRC:
1273        case OP_CIRCM:
1274        case OP_DOLL:
1275        case OP_DOLLM:
1276        case OP_CHAR:
1277        case OP_CHARI:
1278        case OP_NOT:
1279        case OP_NOTI:
1280    
1281        case OP_EXACT:
1282        case OP_POSSTAR:
1283        case OP_POSPLUS:
1284        case OP_POSQUERY:
1285        case OP_POSUPTO:
1286    
1287        case OP_EXACTI:
1288        case OP_POSSTARI:
1289        case OP_POSPLUSI:
1290        case OP_POSQUERYI:
1291        case OP_POSUPTOI:
1292    
1293        case OP_NOTEXACT:
1294        case OP_NOTPOSSTAR:
1295        case OP_NOTPOSPLUS:
1296        case OP_NOTPOSQUERY:
1297        case OP_NOTPOSUPTO:
1298    
1299        case OP_NOTEXACTI:
1300        case OP_NOTPOSSTARI:
1301        case OP_NOTPOSPLUSI:
1302        case OP_NOTPOSQUERYI:
1303        case OP_NOTPOSUPTOI:
1304    
1305        case OP_TYPEEXACT:
1306        case OP_TYPEPOSSTAR:
1307        case OP_TYPEPOSPLUS:
1308        case OP_TYPEPOSQUERY:
1309        case OP_TYPEPOSUPTO:
1310    
1311        case OP_CLASS:
1312        case OP_NCLASS:
1313        case OP_XCLASS:
1314    
1315      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1316      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1317      break;      break;
1318      }      }
1319    
1320  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1321  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1322    return -1;    return stack_restore ? no_frame : no_stack;
1323    
1324  if (length > 0)  if (length > 0)
1325    return length + 1;    return length + 1;
1326  return -1;  return stack_restore ? no_frame : no_stack;
1327  }  }
1328    
1329  static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive)  static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive)
1330  {  {
1331  DEFINE_COMPILER;  DEFINE_COMPILER;
1332  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1333  BOOL setsom_found = FALSE;  BOOL setsom_found = recursive;
1334    BOOL setmark_found = recursive;
1335    /* The last capture is a local variable even for recursions. */
1336    BOOL capture_last_found = FALSE;
1337  int offset;  int offset;
1338    
1339  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
1340    SLJIT_UNUSED_ARG(stacktop);
1341  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1342    
1343  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
# Line 806  while (cc < ccend) Line 1348  while (cc < ccend)
1348    switch(*cc)    switch(*cc)
1349      {      {
1350      case OP_SET_SOM:      case OP_SET_SOM:
1351      case OP_RECURSE:      SLJIT_ASSERT(common->has_set_som);
1352      if (!setsom_found)      if (!setsom_found)
1353        {        {
1354        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1355        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1356        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1357          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1358          stackpos += (int)sizeof(sljit_sw);
1359          setsom_found = TRUE;
1360          }
1361        cc += 1;
1362        break;
1363    
1364        case OP_MARK:
1365        case OP_PRUNE_ARG:
1366        SLJIT_ASSERT(common->mark_ptr != 0);
1367        if (!setmark_found)
1368          {
1369          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1370          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1371          stackpos += (int)sizeof(sljit_sw);
1372          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1373          stackpos += (int)sizeof(sljit_sw);
1374          setmark_found = TRUE;
1375          }
1376        cc += 1 + 2 + cc[1];
1377        break;
1378    
1379        case OP_RECURSE:
1380        if (common->has_set_som && !setsom_found)
1381          {
1382          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1383          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1384          stackpos += (int)sizeof(sljit_sw);
1385        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1386        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1387        setsom_found = TRUE;        setsom_found = TRUE;
1388        }        }
1389      cc += (*cc == OP_SET_SOM) ? 1 : 1 + LINK_SIZE;      if (common->mark_ptr != 0 && !setmark_found)
1390          {
1391          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1392          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1393          stackpos += (int)sizeof(sljit_sw);
1394          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1395          stackpos += (int)sizeof(sljit_sw);
1396          setmark_found = TRUE;
1397          }
1398        if (common->capture_last_ptr != 0 && !capture_last_found)
1399          {
1400          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1401          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1402          stackpos += (int)sizeof(sljit_sw);
1403          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1404          stackpos += (int)sizeof(sljit_sw);
1405          capture_last_found = TRUE;
1406          }
1407        cc += 1 + LINK_SIZE;
1408      break;      break;
1409    
1410      case OP_CBRA:      case OP_CBRA:
1411      case OP_CBRAPOS:      case OP_CBRAPOS:
1412      case OP_SCBRA:      case OP_SCBRA:
1413      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1414        if (common->capture_last_ptr != 0 && !capture_last_found)
1415          {
1416          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1417          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1418          stackpos += (int)sizeof(sljit_sw);
1419          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1420          stackpos += (int)sizeof(sljit_sw);
1421          capture_last_found = TRUE;
1422          }
1423      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1424      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1425      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1426      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1427      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));
1428      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1429      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1430      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1431      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1432    
1433      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1434      break;      break;
# Line 842  while (cc < ccend) Line 1439  while (cc < ccend)
1439      break;      break;
1440      }      }
1441    
1442  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1443  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1444  }  }
1445    
1446  static SLJIT_INLINE int get_localsize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static SLJIT_INLINE int get_private_data_copy_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL needs_control_head)
1447  {  {
1448  int localsize = 2;  int private_data_length = needs_control_head ? 3 : 2;
1449    int size;
1450  pcre_uchar *alternative;  pcre_uchar *alternative;
1451  /* Calculate the sum of the local variables. */  /* Calculate the sum of the private machine words. */
1452  while (cc < ccend)  while (cc < ccend)
1453    {    {
1454      size = 0;
1455    switch(*cc)    switch(*cc)
1456      {      {
1457      case OP_ASSERT:      case OP_ASSERT:
# Line 865  while (cc < ccend) Line 1464  while (cc < ccend)
1464      case OP_SBRA:      case OP_SBRA:
1465      case OP_SBRAPOS:      case OP_SBRAPOS:
1466      case OP_SCOND:      case OP_SCOND:
1467      localsize++;      private_data_length++;
1468      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1469      break;      break;
1470    
1471      case OP_CBRA:      case OP_CBRA:
1472      case OP_SCBRA:      case OP_SCBRA:
1473      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1474          private_data_length++;
1475      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1476      break;      break;
1477    
1478      case OP_CBRAPOS:      case OP_CBRAPOS:
1479      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1480      localsize += 2;      private_data_length += 2;
1481      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1482      break;      break;
1483    
# Line 885  while (cc < ccend) Line 1485  while (cc < ccend)
1485      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1486      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1487      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1488        localsize++;        private_data_length++;
1489      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1490      break;      break;
1491    
1492        CASE_ITERATOR_PRIVATE_DATA_1
1493        if (PRIVATE_DATA(cc))
1494          private_data_length++;
1495        cc += 2;
1496    #ifdef SUPPORT_UTF
1497        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1498    #endif
1499        break;
1500    
1501        CASE_ITERATOR_PRIVATE_DATA_2A
1502        if (PRIVATE_DATA(cc))
1503          private_data_length += 2;
1504        cc += 2;
1505    #ifdef SUPPORT_UTF
1506        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1507    #endif
1508        break;
1509    
1510        CASE_ITERATOR_PRIVATE_DATA_2B
1511        if (PRIVATE_DATA(cc))
1512          private_data_length += 2;
1513        cc += 2 + IMM2_SIZE;
1514    #ifdef SUPPORT_UTF
1515        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1516    #endif
1517        break;
1518    
1519        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1520        if (PRIVATE_DATA(cc))
1521          private_data_length++;
1522        cc += 1;
1523        break;
1524    
1525        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1526        if (PRIVATE_DATA(cc))
1527          private_data_length += 2;
1528        cc += 1;
1529        break;
1530    
1531        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1532        if (PRIVATE_DATA(cc))
1533          private_data_length += 2;
1534        cc += 1 + IMM2_SIZE;
1535        break;
1536    
1537        case OP_CLASS:
1538        case OP_NCLASS:
1539    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1540        case OP_XCLASS:
1541        size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1542    #else
1543        size = 1 + 32 / (int)sizeof(pcre_uchar);
1544    #endif
1545        if (PRIVATE_DATA(cc))
1546          private_data_length += get_class_iterator_size(cc + size);
1547        cc += size;
1548        break;
1549    
1550      default:      default:
1551      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1552      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
# Line 896  while (cc < ccend) Line 1554  while (cc < ccend)
1554      }      }
1555    }    }
1556  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1557  return localsize;  return private_data_length;
1558  }  }
1559    
1560  static void copy_locals(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,
1561    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1562  {  {
1563  DEFINE_COMPILER;  DEFINE_COMPILER;
1564  int srcw[2];  int srcw[2];
1565  int count;  int count, size;
1566  BOOL tmp1next = TRUE;  BOOL tmp1next = TRUE;
1567  BOOL tmp1empty = TRUE;  BOOL tmp1empty = TRUE;
1568  BOOL tmp2empty = TRUE;  BOOL tmp2empty = TRUE;
# Line 921  stacktop = STACK(stacktop - 1); Line 1579  stacktop = STACK(stacktop - 1);
1579    
1580  if (!save)  if (!save)
1581    {    {
1582    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1583    if (stackptr < stacktop)    if (stackptr < stacktop)
1584      {      {
1585      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1586      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1587      tmp1empty = FALSE;      tmp1empty = FALSE;
1588      }      }
1589    if (stackptr < stacktop)    if (stackptr < stacktop)
1590      {      {
1591      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1592      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1593      tmp2empty = FALSE;      tmp2empty = FALSE;
1594      }      }
1595    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1596    }    }
1597    
1598  while (status != end)  do
1599    {    {
1600    count = 0;    count = 0;
1601    switch(status)    switch(status)
1602      {      {
1603      case start:      case start:
1604      SLJIT_ASSERT(save);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1605      count = 1;      count = 1;
1606      srcw[0] = RECURSIVE_HEAD;      srcw[0] = common->recursive_head_ptr;
1607        if (needs_control_head)
1608          {
1609          SLJIT_ASSERT(common->control_head_ptr != 0);
1610          count = 2;
1611          srcw[1] = common->control_head_ptr;
1612          }
1613      status = loop;      status = loop;
1614      break;      break;
1615    
# Line 969  while (status != end) Line 1633  while (status != end)
1633        case OP_SBRAPOS:        case OP_SBRAPOS:
1634        case OP_SCOND:        case OP_SCOND:
1635        count = 1;        count = 1;
1636        srcw[0] = PRIV_DATA(cc);        srcw[0] = PRIVATE_DATA(cc);
1637        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1638        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1639        break;        break;
1640    
1641        case OP_CBRA:        case OP_CBRA:
1642        case OP_SCBRA:        case OP_SCBRA:
1643        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1644        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1645            count = 1;
1646            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1647            }
1648        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1649        break;        break;
1650    
1651        case OP_CBRAPOS:        case OP_CBRAPOS:
1652        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1653        count = 2;        count = 2;
1654          srcw[0] = PRIVATE_DATA(cc);
1655        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1656        srcw[0] = PRIV_DATA(cc);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
       SLJIT_ASSERT(srcw[0] != 0);  
1657        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1658        break;        break;
1659    
# Line 996  while (status != end) Line 1663  while (status != end)
1663        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1664          {          {
1665          count = 1;          count = 1;
1666          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1667          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1668          }          }
1669        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1670        break;        break;
1671    
1672          CASE_ITERATOR_PRIVATE_DATA_1
1673          if (PRIVATE_DATA(cc))
1674            {
1675            count = 1;
1676            srcw[0] = PRIVATE_DATA(cc);
1677            }
1678          cc += 2;
1679    #ifdef SUPPORT_UTF
1680          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1681    #endif
1682          break;
1683    
1684          CASE_ITERATOR_PRIVATE_DATA_2A
1685          if (PRIVATE_DATA(cc))
1686            {
1687            count = 2;
1688            srcw[0] = PRIVATE_DATA(cc);
1689            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1690            }
1691          cc += 2;
1692    #ifdef SUPPORT_UTF
1693          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1694    #endif
1695          break;
1696    
1697          CASE_ITERATOR_PRIVATE_DATA_2B
1698          if (PRIVATE_DATA(cc))
1699            {
1700            count = 2;
1701            srcw[0] = PRIVATE_DATA(cc);
1702            srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1703            }
1704          cc += 2 + IMM2_SIZE;
1705    #ifdef SUPPORT_UTF
1706          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1707    #endif
1708          break;
1709    
1710          CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1711          if (PRIVATE_DATA(cc))
1712            {
1713            count = 1;
1714            srcw[0] = PRIVATE_DATA(cc);
1715            }
1716          cc += 1;
1717          break;
1718    
1719          CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1720          if (PRIVATE_DATA(cc))
1721            {
1722            count = 2;
1723            srcw[0] = PRIVATE_DATA(cc);
1724            srcw[1] = srcw[0] + sizeof(sljit_sw);
1725            }
1726          cc += 1;
1727          break;
1728    
1729          CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1730          if (PRIVATE_DATA(cc))
1731            {
1732            count = 2;
1733            srcw[0] = PRIVATE_DATA(cc);
1734            srcw[1] = srcw[0] + sizeof(sljit_sw);
1735            }
1736          cc += 1 + IMM2_SIZE;
1737          break;
1738    
1739          case OP_CLASS:
1740          case OP_NCLASS:
1741    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1742          case OP_XCLASS:
1743          size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / (int)sizeof(pcre_uchar);
1744    #else
1745          size = 1 + 32 / (int)sizeof(pcre_uchar);
1746    #endif
1747          if (PRIVATE_DATA(cc))
1748            switch(get_class_iterator_size(cc + size))
1749              {
1750              case 1:
1751              count = 1;
1752              srcw[0] = PRIVATE_DATA(cc);
1753              break;
1754    
1755              case 2:
1756              count = 2;
1757              srcw[0] = PRIVATE_DATA(cc);
1758              srcw[1] = srcw[0] + sizeof(sljit_sw);
1759              break;
1760    
1761              default:
1762              SLJIT_ASSERT_STOP();
1763              break;
1764              }
1765          cc += size;
1766          break;
1767    
1768        default:        default:
1769        cc = next_opcode(common, cc);        cc = next_opcode(common, cc);
1770        SLJIT_ASSERT(cc != NULL);        SLJIT_ASSERT(cc != NULL);
# Line 1024  while (status != end) Line 1787  while (status != end)
1787          if (!tmp1empty)          if (!tmp1empty)
1788            {            {
1789            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1790            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1791            }            }
1792          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1793          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1035  while (status != end) Line 1798  while (status != end)
1798          if (!tmp2empty)          if (!tmp2empty)
1799            {            {
1800            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1801            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1802            }            }
1803          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1804          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1052  while (status != end) Line 1815  while (status != end)
1815          if (!tmp1empty)          if (!tmp1empty)
1816            {            {
1817            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1818            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1819            }            }
1820          tmp1next = FALSE;          tmp1next = FALSE;
1821          }          }
# Line 1064  while (status != end) Line 1827  while (status != end)
1827          if (!tmp2empty)          if (!tmp2empty)
1828            {            {
1829            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1830            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1831            }            }
1832          tmp1next = TRUE;          tmp1next = TRUE;
1833          }          }
1834        }        }
1835      }      }
1836    }    }
1837    while (status != end);
1838    
1839  if (save)  if (save)
1840    {    {
# Line 1079  if (save) Line 1843  if (save)
1843      if (!tmp1empty)      if (!tmp1empty)
1844        {        {
1845        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1846        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1847        }        }
1848      if (!tmp2empty)      if (!tmp2empty)
1849        {        {
1850        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1851        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1852        }        }
1853      }      }
1854    else    else
# Line 1092  if (save) Line 1856  if (save)
1856      if (!tmp2empty)      if (!tmp2empty)
1857        {        {
1858        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1859        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1860        }        }
1861      if (!tmp1empty)      if (!tmp1empty)
1862        {        {
1863        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1864        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1865        }        }
1866      }      }
1867    }    }
1868  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1869  }  }
1870    
1871  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  #undef CASE_ITERATOR_PRIVATE_DATA_1
1872    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1873    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1874    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1875    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1876    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1877    
1878    static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1879  {  {
1880  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1881  }  }
# Line 1114  static SLJIT_INLINE void set_jumps(jump_ Line 1885  static SLJIT_INLINE void set_jumps(jump_
1885  while (list)  while (list)
1886    {    {
1887    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1888    if either the jump or the label is NULL */    if either the jump or the label is NULL. */
1889    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1890    list = list->next;    list = list->next;
1891    }    }
1892  }  }
# Line 1131  if (list_item) Line 1902  if (list_item)
1902    }    }
1903  }  }
1904    
1905  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)
1906  {  {
1907  DEFINE_COMPILER;  DEFINE_COMPILER;
1908  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1909    
1910  if (list_item)  if (list_item)
1911    {    {
   list_item->type = type;  
   list_item->data = data;  
1912    list_item->start = start;    list_item->start = start;
1913    list_item->leave = LABEL();    list_item->quit = LABEL();
1914    list_item->next = common->stubs;    list_item->next = common->stubs;
1915    common->stubs = list_item;    common->stubs = list_item;
1916    }    }
# Line 1155  stub_list* list_item = common->stubs; Line 1924  stub_list* list_item = common->stubs;
1924  while (list_item)  while (list_item)
1925    {    {
1926    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
1927    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
1928      {    JUMPTO(SLJIT_JUMP, list_item->quit);
     case stack_alloc:  
     add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));  
     break;  
     }  
   JUMPTO(SLJIT_JUMP, list_item->leave);  
1929    list_item = list_item->next;    list_item = list_item->next;
1930    }    }
1931  common->stubs = NULL;  common->stubs = NULL;
# Line 1180  static SLJIT_INLINE void allocate_stack( Line 1944  static SLJIT_INLINE void allocate_stack(
1944  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
1945  DEFINE_COMPILER;  DEFINE_COMPILER;
1946    
1947  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));
1948  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
1949  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
1950  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 1952  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
1952  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
1953  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
1954  #endif  #endif
1955  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));
1956  }  }
1957    
1958  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
1959  {  {
1960  DEFINE_COMPILER;  DEFINE_COMPILER;
1961  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));
1962  }  }
1963    
1964  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 1966  static SLJIT_INLINE void reset_ovector(c
1966  DEFINE_COMPILER;  DEFINE_COMPILER;
1967  struct sljit_label *loop;  struct sljit_label *loop;
1968  int i;  int i;
1969    
1970  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
1971    SLJIT_ASSERT(length > 1);
1972  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
1973  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
1974    if (length < 8)
1975      {
1976      for (i = 1; i < length; i++)
1977        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
1978      }
1979    else
1980      {
1981      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
1982      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
1983      loop = LABEL();
1984      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
1985      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
1986      JUMPTO(SLJIT_C_NOT_ZERO, loop);
1987      }
1988    }
1989    
1990    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
1991    {
1992    DEFINE_COMPILER;
1993    struct sljit_label *loop;
1994    int i;
1995    
1996    SLJIT_ASSERT(length > 1);
1997    /* OVECTOR(1) contains the "string begin - 1" constant. */
1998    if (length > 2)
1999      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2000  if (length < 8)  if (length < 8)
2001    {    {
2002    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
2003      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);
2004    }    }
2005  else  else
2006    {    {
2007    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));
2008    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2009    loop = LABEL();    loop = LABEL();
2010    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);
2011    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);
2012    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2013    }    }
2014    
2015    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2016    if (common->mark_ptr != 0)
2017      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2018    SLJIT_ASSERT(common->control_head_ptr != 0);
2019    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2020    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2021    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2022    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2023    }
2024    
2025    static sljit_sw SLJIT_CALL do_check_control_chain(sljit_sw *current)
2026    {
2027    sljit_sw return_value = 0;
2028    
2029    SLJIT_ASSERT(current != NULL);
2030    do
2031      {
2032      switch (current[-2])
2033        {
2034        case type_commit:
2035        /* Commit overwrites all. */
2036        return -1;
2037    
2038        case type_prune:
2039        break;
2040    
2041        case type_skip:
2042        /* Overwrites prune, but not other skips. */
2043        if (return_value == 0)
2044          return_value = current[-3];
2045        break;
2046    
2047        default:
2048        SLJIT_ASSERT_STOP();
2049        break;
2050        }
2051      current = (sljit_sw*)current[-1];
2052      }
2053    while (current != NULL);
2054    return return_value;
2055  }  }
2056    
2057  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2058  {  {
2059  DEFINE_COMPILER;  DEFINE_COMPILER;
2060  struct sljit_label *loop;  struct sljit_label *loop;
2061  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2062    
2063  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2064  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2065  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);
2066    
2067  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2068  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));  if (common->mark_ptr != 0)
2069  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
2070  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offset_count));
2071  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START);  if (common->mark_ptr != 0)
2072      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);
2073    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
2074    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));
2075    GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2076  /* Unlikely, but possible */  /* Unlikely, but possible */
2077  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);
2078  loop = LABEL();  loop = LABEL();
2079  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
2080  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_w));  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));
2081  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2082  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2083  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2084  #endif  #endif
2085  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);
2086  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
2087  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2088  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2089    
2090  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2091  if (topbracket > 1)  if (topbracket > 1)
2092    {    {
2093    OP2(SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_LOCALS_REG, 0, SLJIT_IMM, OVECTOR_START + topbracket * 2 * sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));
2094    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2095    
2096    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2097    loop = LABEL();    loop = LABEL();
2098    OP1(SLJIT_MOVU, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), -(2 * (sljit_w)sizeof(sljit_w)));    OP1(SLJIT_MOVU, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), -(2 * (sljit_sw)sizeof(sljit_sw)));
2099    OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
2100    CMPTO(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG3, 0, loop);    CMPTO(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG3, 0, loop);
2101    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2102    }    }
2103  else  else
2104    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
2105  }  }
2106    
2107    static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)
2108    {
2109    DEFINE_COMPILER;
2110    struct sljit_jump *jump;
2111    
2112    SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);
2113    SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0
2114      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2115    
2116    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2117    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2118    OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, real_offset_count));
2119    CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
2120    
2121    /* Store match begin and end. */
2122    OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));
2123    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));
2124    
2125    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2126    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);
2127    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2128    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2129    #endif
2130    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2131    JUMPHERE(jump);
2132    
2133    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);
2134    OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);
2135    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2136    OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2137    #endif
2138    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);
2139    
2140    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG1, 0);
2141    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2142    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2143    #endif
2144    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0, SLJIT_SCRATCH_REG3, 0);
2145    
2146    JUMPTO(SLJIT_JUMP, quit);
2147    }
2148    
2149    static SLJIT_INLINE void check_start_used_ptr(compiler_common *common)
2150    {
2151    /* May destroy TMP1. */
2152    DEFINE_COMPILER;
2153    struct sljit_jump *jump;
2154    
2155    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2156      {
2157      /* The value of -1 must be kept for start_used_ptr! */
2158      OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, 1);
2159      /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting
2160      is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */
2161      jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, STR_PTR, 0);
2162      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2163      JUMPHERE(jump);
2164      }
2165    else if (common->mode == JIT_PARTIAL_HARD_COMPILE)
2166      {
2167      jump = CMP(SLJIT_C_LESS_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2168      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2169      JUMPHERE(jump);
2170      }
2171    }
2172    
2173  static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar* cc)  static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar* cc)
2174  {  {
2175  /* Detects if the character has an othercase. */  /* Detects if the character has an othercase. */
# Line 1351  if (c <= 127 && bit == 0x20) Line 2254  if (c <= 127 && bit == 0x20)
2254    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2255    
2256  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2257  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2258    return 0;    return 0;
2259    
2260  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2261    
2262  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2263  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 1370  if (common->utf && c > 127) Line 2273  if (common->utf && c > 127)
2273  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2274  return (0 << 8) | bit;  return (0 << 8) | bit;
2275    
2276  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2277    
 #ifdef COMPILE_PCRE16  
2278  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2279  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2280    {    {
# Line 1383  if (common->utf && c > 65535) Line 2285  if (common->utf && c > 65535)
2285    }    }
2286  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2287  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2288    
2289  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2290    }
2291    
2292    static void check_partial(compiler_common *common, BOOL force)
2293    {
2294    /* Checks whether a partial matching is occured. Does not modify registers. */
2295    DEFINE_COMPILER;
2296    struct sljit_jump *jump = NULL;
2297    
2298    SLJIT_ASSERT(!force || common->mode != JIT_COMPILE);
2299    
2300    if (common->mode == JIT_COMPILE)
2301      return;
2302    
2303    if (!force)
2304      jump = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
2305    else if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2306      jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2307    
2308    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2309      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2310    else
2311      {
2312      if (common->partialmatchlabel != NULL)
2313        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2314      else
2315        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2316      }
2317    
2318    if (jump != NULL)
2319      JUMPHERE(jump);
2320    }
2321    
2322    static void check_str_end(compiler_common *common, jump_list **end_reached)
2323    {
2324    /* Does not affect registers. Usually used in a tight spot. */
2325    DEFINE_COMPILER;
2326    struct sljit_jump *jump;
2327    
2328    if (common->mode == JIT_COMPILE)
2329      {
2330      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2331      return;
2332      }
2333    
2334    jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2335    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2336      {
2337      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2338      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2339      add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
2340      }
2341    else
2342      {
2343      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2344      if (common->partialmatchlabel != NULL)
2345        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2346      else
2347        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2348      }
2349    JUMPHERE(jump);
2350  }  }
2351    
2352  static SLJIT_INLINE void check_input_end(compiler_common *common, jump_list **fallbacks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
2353  {  {
2354  DEFINE_COMPILER;  DEFINE_COMPILER;
2355  add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));  struct sljit_jump *jump;
2356    
2357    if (common->mode == JIT_COMPILE)
2358      {
2359      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2360      return;
2361      }
2362    
2363    /* Partial matching mode. */
2364    jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2365    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2366    if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2367      {
2368      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2369      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2370      }
2371    else
2372      {
2373      if (common->partialmatchlabel != NULL)
2374        JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2375      else
2376        add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2377      }
2378    JUMPHERE(jump);
2379  }  }
2380    
2381  static void read_char(compiler_common *common)  static void read_char(compiler_common *common)
# Line 1399  static void read_char(compiler_common *c Line 2383  static void read_char(compiler_common *c
2383  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, updates STR_PTR.
2384  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2385  DEFINE_COMPILER;  DEFINE_COMPILER;
2386  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2387  struct sljit_jump *jump;  struct sljit_jump *jump;
2388  #endif  #endif
2389    
2390  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2391  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2392  if (common->utf)  if (common->utf)
2393    {    {
2394  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2395    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2396  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2397    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2398  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2399    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2400    JUMPHERE(jump);    JUMPHERE(jump);
2401    }    }
2402  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2403  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2404  }  }
2405    
# Line 1426  static void peek_char(compiler_common *c Line 2408  static void peek_char(compiler_common *c
2408  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2409  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2410  DEFINE_COMPILER;  DEFINE_COMPILER;
2411  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2412  struct sljit_jump *jump;  struct sljit_jump *jump;
2413  #endif  #endif
2414    
2415  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2416  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2417  if (common->utf)  if (common->utf)
2418    {    {
2419  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2420    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2421  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2422    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2423  #endif  #endif /* COMPILE_PCRE[8|16] */
 #endif /* COMPILE_PCRE8 */  
2424    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2425    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2426    JUMPHERE(jump);    JUMPHERE(jump);
2427    }    }
2428  #endif  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2429  }  }
2430    
2431  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2432  {  {
2433  /* 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. */
2434  DEFINE_COMPILER;  DEFINE_COMPILER;
2435  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2436  struct sljit_jump *jump;  struct sljit_jump *jump;
2437  #endif  #endif
2438    
# Line 1461  if (common->utf) Line 2441  if (common->utf)
2441    {    {
2442    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2443    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2444  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2445    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2446    it is needed in most cases. */    it is needed in most cases. */
2447    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2448    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2449    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2450    JUMPHERE(jump);    JUMPHERE(jump);
2451  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
2452    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2453    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2454    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
# Line 1477  if (common->utf) Line 2456  if (common->utf)
2456    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2457    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2458    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2459    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2460    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2461    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2462  #endif  #elif defined COMPILE_PCRE32
2463  #endif /* COMPILE_PCRE8 */    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2464      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2465      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2466      JUMPHERE(jump);
2467    #endif /* COMPILE_PCRE[8|16|32] */
2468    return;    return;
2469    }    }
2470  #endif  #endif /* SUPPORT_UTF */
2471  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2472  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2473  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2474  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2475  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2476  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2477  #endif  #endif
2478  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2479  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2480  JUMPHERE(jump);  JUMPHERE(jump);
2481  #endif  #endif
2482  }  }
# Line 1502  static void skip_char_back(compiler_comm Line 2485  static void skip_char_back(compiler_comm
2485  {  {
2486  /* Goes one character back. Affects STR_PTR and TMP1. Does not check begin. */  /* Goes one character back. Affects STR_PTR and TMP1. Does not check begin. */
2487  DEFINE_COMPILER;  DEFINE_COMPILER;
2488  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2489    #if defined COMPILE_PCRE8
2490  struct sljit_label *label;  struct sljit_label *label;
2491    
2492  if (common->utf)  if (common->utf)
# Line 1514  if (common->utf) Line 2498  if (common->utf)
2498    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2499    return;    return;
2500    }    }
2501  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2502  if (common->utf)  if (common->utf)
2503    {    {
2504    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
# Line 1523  if (common->utf) Line 2506  if (common->utf)
2506    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2507    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2508    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00);
2509    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2510    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2511    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2512    return;    return;
2513    }    }
2514  #endif  #endif /* COMPILE_PCRE[8|16] */
2515    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2516  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2517  }  }
2518    
2519  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)
2520  {  {
2521  /* 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. */
2522  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1540  DEFINE_COMPILER; Line 2524  DEFINE_COMPILER;
2524  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2525    {    {
2526    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2527    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));
2528    }    }
2529  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2530    {    {
2531    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);
2532    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2533    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);
2534    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);
2535    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));
2536    }    }
2537  else  else
2538    {    {
2539    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2540    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));
2541    }    }
2542  }  }
2543    
2544  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2545    
2546  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2547  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2548  {  {
2549  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
# Line 1567  of the character (>= 0xc0). Return char Line 2551  of the character (>= 0xc0). Return char
2551  DEFINE_COMPILER;  DEFINE_COMPILER;
2552  struct sljit_jump *jump;  struct sljit_jump *jump;
2553    
2554  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2555  /* Searching for the first zero. */  /* Searching for the first zero. */
2556  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);
2557  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
# Line 1626  DEFINE_COMPILER; Line 2610  DEFINE_COMPILER;
2610  struct sljit_jump *jump;  struct sljit_jump *jump;
2611  struct sljit_jump *compare;  struct sljit_jump *compare;
2612    
2613  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2614    
2615  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);
2616  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
# Line 1647  sljit_emit_fast_return(compiler, RETURN_ Line 2631  sljit_emit_fast_return(compiler, RETURN_
2631  JUMPHERE(jump);  JUMPHERE(jump);
2632    
2633  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2634  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(utf8_table4) - 0xc0);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2635  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2636  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2637  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2638  }  }
2639    
2640  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16
2641    
 #ifdef COMPILE_PCRE16  
2642  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2643  {  {
2644  /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char  /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char
# Line 1663  of the character (>= 0xd800). Return cha Line 2646  of the character (>= 0xd800). Return cha
2646  DEFINE_COMPILER;  DEFINE_COMPILER;
2647  struct sljit_jump *jump;  struct sljit_jump *jump;
2648    
2649  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2650  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);
2651  /* Do nothing, only return. */  /* Do nothing, only return. */
2652  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
# Line 1680  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC Line 2663  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC
2663  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2664  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2665  }  }
 #endif /* COMPILE_PCRE16 */  
2666    
2667  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16] */
2668    
2669  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2670    
# Line 1700  DEFINE_COMPILER; Line 2682  DEFINE_COMPILER;
2682    
2683  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && sizeof(ucd_record) == 8);
2684    
2685  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2686  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2687  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(ucd_stage1));  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(ucd_stage1));
2688  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2689  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2690  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2691  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2692  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2693  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));
2694  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2695  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2696  }  }
# Line 1722  struct sljit_label *newlinelabel = NULL; Line 2704  struct sljit_label *newlinelabel = NULL;
2704  struct sljit_jump *start;  struct sljit_jump *start;
2705  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2706  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2707  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2708  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2709  #endif  #endif
2710  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 1736  if (!(hascrorlf || firstline) && (common Line 2718  if (!(hascrorlf || firstline) && (common
2718  if (firstline)  if (firstline)
2719    {    {
2720    /* Search for the end of the first line. */    /* Search for the end of the first line. */
2721    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STR_PTR, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2722    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
2723    
2724    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
2725      {      {
# Line 1748  if (firstline) Line 2730  if (firstline)
2730      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2731      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);
2732      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);
2733      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));      JUMPHERE(end);
2734        OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2735      }      }
2736    else    else
2737      {      {
2738      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2739      mainloop = LABEL();      mainloop = LABEL();
2740      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
2741      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);
2742      read_char(common);      read_char(common);
2743      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
2744      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2745      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END, STR_PTR, 0);      JUMPHERE(end);
2746        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2747      set_jumps(newline, LABEL());      set_jumps(newline, LABEL());
2748      }      }
2749    
2750    JUMPHERE(end);    OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
   OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  
2751    }    }
2752    
2753  start = JUMP(SLJIT_JUMP);  start = JUMP(SLJIT_JUMP);
# Line 1776  if (newlinecheck) Line 2759  if (newlinecheck)
2759    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2760    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2761    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);
2762    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2763  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2764    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2765  #endif  #endif
2766    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2767    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 1799  if (newlinecheck) Line 2782  if (newlinecheck)
2782    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);
2783    
2784  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2785  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2786    #if defined COMPILE_PCRE8
2787  if (common->utf)  if (common->utf)
2788    {    {
2789    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2790    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2791    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2792    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2793    }    }
2794  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2795  if (common->utf)  if (common->utf)
2796    {    {
2797    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2798    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2799    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2800    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2801    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2802    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2803    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2804    }    }
2805  #endif  #endif /* COMPILE_PCRE[8|16] */
2806    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2807  JUMPHERE(start);  JUMPHERE(start);
2808    
2809  if (newlinecheck)  if (newlinecheck)
# Line 1831  if (newlinecheck) Line 2815  if (newlinecheck)
2815  return mainloop;  return mainloop;
2816  }  }
2817    
2818    #define MAX_N_CHARS 3
2819    
2820    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
2821    {
2822    DEFINE_COMPILER;
2823    struct sljit_label *start;
2824    struct sljit_jump *quit;
2825    pcre_uint32 chars[MAX_N_CHARS * 2];
2826    pcre_uchar *cc = common->start + 1 + LINK_SIZE;
2827    int location = 0;
2828    pcre_int32 len, c, bit, caseless;
2829    int must_stop;
2830    
2831    /* We do not support alternatives now. */
2832    if (*(common->start + GET(common->start, 1)) == OP_ALT)
2833      return FALSE;
2834    
2835    while (TRUE)
2836      {
2837      caseless = 0;
2838      must_stop = 1;
2839      switch(*cc)
2840        {
2841        case OP_CHAR:
2842        must_stop = 0;
2843        cc++;
2844        break;
2845    
2846        case OP_CHARI:
2847        caseless = 1;
2848        must_stop = 0;
2849        cc++;
2850        break;
2851    
2852        case OP_SOD:
2853        case OP_SOM:
2854        case OP_SET_SOM:
2855        case OP_NOT_WORD_BOUNDARY:
2856        case OP_WORD_BOUNDARY:
2857        case OP_EODN:
2858        case OP_EOD:
2859        case OP_CIRC:
2860        case OP_CIRCM:
2861        case OP_DOLL:
2862        case OP_DOLLM:
2863        /* Zero width assertions. */
2864        cc++;
2865        continue;
2866    
2867        case OP_PLUS:
2868        case OP_MINPLUS:
2869        case OP_POSPLUS:
2870        cc++;
2871        break;
2872    
2873        case OP_EXACT:
2874        cc += 1 + IMM2_SIZE;
2875        break;
2876    
2877        case OP_PLUSI:
2878        case OP_MINPLUSI:
2879        case OP_POSPLUSI:
2880        caseless = 1;
2881        cc++;
2882        break;
2883    
2884        case OP_EXACTI:
2885        caseless = 1;
2886        cc += 1 + IMM2_SIZE;
2887        break;
2888    
2889        default:
2890        must_stop = 2;
2891        break;
2892        }
2893    
2894      if (must_stop == 2)
2895          break;
2896    
2897      len = 1;
2898    #ifdef SUPPORT_UTF
2899      if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
2900    #endif
2901    
2902      if (caseless && char_has_othercase(common, cc))
2903        {
2904        caseless = char_get_othercase_bit(common, cc);
2905        if (caseless == 0)
2906          return FALSE;
2907    #ifdef COMPILE_PCRE8
2908        caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
2909    #else
2910        if ((caseless & 0x100) != 0)
2911          caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));
2912        else
2913          caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));
2914    #endif
2915        }
2916      else
2917        caseless = 0;
2918    
2919      while (len > 0 && location < MAX_N_CHARS * 2)
2920        {
2921        c = *cc;
2922        bit = 0;
2923        if (len == (caseless & 0xff))
2924          {
2925          bit = caseless >> 8;
2926          c |= bit;
2927          }
2928    
2929        chars[location] = c;
2930        chars[location + 1] = bit;
2931    
2932        len--;
2933        location += 2;
2934        cc++;
2935        }
2936    
2937      if (location >= MAX_N_CHARS * 2 || must_stop != 0)
2938        break;
2939      }
2940    
2941    /* At least two characters are required. */
2942    if (location < 2 * 2)
2943        return FALSE;
2944    
2945    if (firstline)
2946      {
2947      SLJIT_ASSERT(common->first_line_end != 0);
2948      OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2949      OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2950      }
2951    else
2952      OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2953    
2954    start = LABEL();
2955    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2956    
2957    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2958    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2959    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2960    if (chars[1] != 0)
2961      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
2962    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
2963    if (location > 2 * 2)
2964      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2965    if (chars[3] != 0)
2966      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);
2967    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);
2968    if (location > 2 * 2)
2969      {
2970      if (chars[5] != 0)
2971        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);
2972      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);
2973      }
2974    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2975    
2976    JUMPHERE(quit);
2977    
2978    if (firstline)
2979      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2980    else
2981      OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2982    return TRUE;
2983    }
2984    
2985    #undef MAX_N_CHARS
2986    
2987  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)
2988  {  {
2989  DEFINE_COMPILER;  DEFINE_COMPILER;
2990  struct sljit_label *start;  struct sljit_label *start;
2991  struct sljit_jump *leave;  struct sljit_jump *quit;
2992  struct sljit_jump *found;  struct sljit_jump *found;
2993  pcre_uchar oc, bit;  pcre_uchar oc, bit;
2994    
2995  if (firstline)  if (firstline)
2996    {    {
2997    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
2998    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2999      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3000    }    }
3001    
3002  start = LABEL();  start = LABEL();
3003  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3004  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3005    
3006  oc = first_char;  oc = first_char;
# Line 1863  if (first_char == oc) Line 3017  if (first_char == oc)
3017  else  else
3018    {    {
3019    bit = first_char ^ oc;    bit = first_char ^ oc;
3020    if (ispowerof2(bit))    if (is_powerof2(bit))
3021      {      {
3022      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3023      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
# Line 1871  else Line 3025  else
3025    else    else
3026      {      {
3027      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, first_char);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, first_char);
3028      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3029      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);
3030      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);
3031      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3032      }      }
3033    }    }
3034    
3035  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 #if defined SUPPORT_UTF && defined COMPILE_PCRE8  
 if (common->utf)  
   {  
   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   }  
 #endif  
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
 if (common->utf)  
   {  
   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);  
   OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);  
   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);  
   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);  
   OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   }  
 #endif  
3036  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3037  JUMPHERE(found);  JUMPHERE(found);
3038  JUMPHERE(leave);  JUMPHERE(quit);
3039    
3040  if (firstline)  if (firstline)
3041    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3042  }  }
3043    
3044  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 1912  DEFINE_COMPILER; Line 3047  DEFINE_COMPILER;
3047  struct sljit_label *loop;  struct sljit_label *loop;
3048  struct sljit_jump *lastchar;  struct sljit_jump *lastchar;
3049  struct sljit_jump *firstchar;  struct sljit_jump *firstchar;
3050  struct sljit_jump *leave;  struct sljit_jump *quit;
3051  struct sljit_jump *foundcr = NULL;  struct sljit_jump *foundcr = NULL;
3052  struct sljit_jump *notfoundnl;  struct sljit_jump *notfoundnl;
3053  jump_list *newline = NULL;  jump_list *newline = NULL;
3054    
3055  if (firstline)  if (firstline)
3056    {    {
3057    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3058    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3059      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3060    }    }
3061    
3062  if (common->nltype == NLTYPE_FIXED && common->newline > 255)  if (common->nltype == NLTYPE_FIXED && common->newline > 255)
# Line 1933  if (common->nltype == NLTYPE_FIXED && co Line 3069  if (common->nltype == NLTYPE_FIXED && co
3069    
3070    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3071    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);
3072    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3073  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3074    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3075  #endif  #endif
3076    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3077    
3078    loop = LABEL();    loop = LABEL();
3079    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3080    leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3081    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
3082    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
3083    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);
3084    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);
3085    
3086    JUMPHERE(leave);    JUMPHERE(quit);
3087    JUMPHERE(firstchar);    JUMPHERE(firstchar);
3088    JUMPHERE(lastchar);    JUMPHERE(lastchar);
3089    
# Line 1971  set_jumps(newline, loop); Line 3107  set_jumps(newline, loop);
3107    
3108  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3109    {    {
3110    leave = JUMP(SLJIT_JUMP);    quit = JUMP(SLJIT_JUMP);
3111    JUMPHERE(foundcr);    JUMPHERE(foundcr);
3112    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3113    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3114    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);
3115    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3116  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3117    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3118  #endif  #endif
3119    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3120    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
3121    JUMPHERE(leave);    JUMPHERE(quit);
3122    }    }
3123  JUMPHERE(lastchar);  JUMPHERE(lastchar);
3124  JUMPHERE(firstchar);  JUMPHERE(firstchar);
3125    
3126  if (firstline)  if (firstline)
3127    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3128  }  }
3129    
3130    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3131    
3132  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)
3133  {  {
3134  DEFINE_COMPILER;  DEFINE_COMPILER;
3135  struct sljit_label *start;  struct sljit_label *start;
3136  struct sljit_jump *leave;  struct sljit_jump *quit;
3137  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3138    jump_list *matches = NULL;
3139    pcre_uint8 inverted_start_bits[32];
3140    int i;
3141  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3142  struct sljit_jump *jump;  struct sljit_jump *jump;
3143  #endif  #endif
3144    
3145    for (i = 0; i < 32; ++i)
3146      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3147    
3148  if (firstline)  if (firstline)
3149    {    {
3150    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);    SLJIT_ASSERT(common->first_line_end != 0);
3151    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), FIRSTLINE_END);    OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
3152      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3153    }    }
3154    
3155  start = LABEL();  start = LABEL();
3156  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3157  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3158  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3159  if (common->utf)  if (common->utf)
3160    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3161  #endif  #endif
3162    
3163    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3164      {
3165  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3166  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3167  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3168  JUMPHERE(jump);    JUMPHERE(jump);
3169  #endif  #endif
3170  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3171  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3172  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3173  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3174  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
3175  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3176      }
3177    
3178  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3179  if (common->utf)  if (common->utf)
3180    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3181  #endif  #endif
3182  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3183  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3184    #if defined COMPILE_PCRE8
3185  if (common->utf)  if (common->utf)
3186    {    {
3187    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3188    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
3189    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3190    }    }
3191  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3192  if (common->utf)  if (common->utf)
3193    {    {
3194    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3195    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3196    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
3197    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3198    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3199    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3200    }    }
3201  #endif  #endif /* COMPILE_PCRE[8|16] */
3202    #endif /* SUPPORT_UTF */
3203  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3204  JUMPHERE(found);  if (found != NULL)
3205  JUMPHERE(leave);    JUMPHERE(found);
3206    if (matches != NULL)
3207      set_jumps(matches, LABEL());
3208    JUMPHERE(quit);
3209    
3210  if (firstline)  if (firstline)
3211    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, RETURN_ADDR, 0);
3212  }  }
3213    
3214  static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uchar req_char, BOOL caseless, BOOL has_firstchar)  static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uchar req_char, BOOL caseless, BOOL has_firstchar)
# Line 2067  struct sljit_jump *alreadyfound; Line 3220  struct sljit_jump *alreadyfound;
3220  struct sljit_jump *found;  struct sljit_jump *found;
3221  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3222  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3223  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3224    
3225  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_CHAR_PTR);  SLJIT_ASSERT(common->req_char_ptr != 0);
3226    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
3227  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);
3228  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);
3229  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);
# Line 2097  if (req_char == oc) Line 3251  if (req_char == oc)
3251  else  else
3252    {    {
3253    bit = req_char ^ oc;    bit = req_char ^ oc;
3254    if (ispowerof2(bit))    if (is_powerof2(bit))
3255      {      {
3256      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3257      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
# Line 2114  JUMPTO(SLJIT_JUMP, loop); Line 3268  JUMPTO(SLJIT_JUMP, loop);
3268  JUMPHERE(found);  JUMPHERE(found);
3269  if (foundoc)  if (foundoc)
3270    JUMPHERE(foundoc);    JUMPHERE(foundoc);
3271  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_CHAR_PTR, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr, TMP1, 0);
3272  JUMPHERE(alreadyfound);  JUMPHERE(alreadyfound);
3273  JUMPHERE(toolong);  JUMPHERE(toolong);
3274  return notfound;  return notfound;
# Line 2126  DEFINE_COMPILER; Line 3280  DEFINE_COMPILER;
3280  struct sljit_jump *jump;  struct sljit_jump *jump;
3281  struct sljit_label *mainloop;  struct sljit_label *mainloop;
3282    
3283  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3284  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);  OP1(SLJIT_MOV, TMP1, 0, STACK_TOP, 0);
3285    GET_LOCAL_BASE(TMP3, 0, 0);
3286    
3287  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3288  mainloop = LABEL();  mainloop = LABEL();
3289  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3290  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);
3291  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_LOCALS_REG, 0);  jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3292  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  
3293  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);
3294  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));
3295    OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
3296    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw));
3297  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3298    
3299  JUMPHERE(jump);  JUMPHERE(jump);
3300  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3301  /* End of dropping frames. */  /* End of dropping frames. */
3302  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3303    
3304  JUMPHERE(jump);  JUMPHERE(jump);
3305  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3306  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3307  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3308  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), TMP2, 0);  
 JUMPTO(SLJIT_JUMP, mainloop);  
   
 JUMPHERE(jump);  
 /* Unknown command. */  
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  
3309  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3310  }  }
3311    
3312  static void check_wordboundary(compiler_common *common)  static void check_wordboundary(compiler_common *common)
3313  {  {
3314  DEFINE_COMPILER;  DEFINE_COMPILER;
3315  struct sljit_jump *beginend;  struct sljit_jump *skipread;
3316    jump_list *skipread_list = NULL;
3317  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3318  struct sljit_jump *jump;  struct sljit_jump *jump;
3319  #endif  #endif
3320    
3321  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);
3322    
3323  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);
3324  /* Get type of the previous char, and put it to LOCALS1. */  /* Get type of the previous char, and put it to LOCALS1. */
3325  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
3326  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));
3327  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);
3328  beginend = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);  skipread = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
3329  skip_char_back(common);  skip_char_back(common);
3330    check_start_used_ptr(common);
3331  read_char(common);  read_char(common);
3332    
3333  /* Testing char type. */  /* Testing char type. */
# Line 2186  if (common->use_ucp) Line 3339  if (common->use_ucp)
3339    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3340    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3341    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);
3342    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3343    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);
3344    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);
3345    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3346    JUMPHERE(jump);    JUMPHERE(jump);
3347    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3348    }    }
# Line 2215  else Line 3368  else
3368      JUMPHERE(jump);      JUMPHERE(jump);
3369  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3370    }    }
3371  JUMPHERE(beginend);  JUMPHERE(skipread);
3372    
3373  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3374  beginend = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  check_str_end(common, &skipread_list);
3375  peek_char(common);  peek_char(common);
3376    
3377  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 2230  if (common->use_ucp) Line 3383  if (common->use_ucp)
3383    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3384    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3385    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);
3386    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3387    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);
3388    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);
3389    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3390    JUMPHERE(jump);    JUMPHERE(jump);
3391    }    }
3392  else  else
# Line 2259  else Line 3412  else
3412      JUMPHERE(jump);      JUMPHERE(jump);
3413  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3414    }    }
3415  JUMPHERE(beginend);  set_jumps(skipread_list, LABEL());
3416    
3417  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3418  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3419  }  }
3420    
3421    /*
3422      range format:
3423    
3424      ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).
3425      ranges[1] = first bit (0 or 1)
3426      ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)
3427    */
3428    
3429    static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)
3430    {
3431    DEFINE_COMPILER;
3432    struct sljit_jump *jump;
3433    
3434    if (ranges[0] < 0)
3435      return FALSE;
3436    
3437    switch(ranges[0])
3438      {
3439      case 1:
3440      if (readch)
3441        read_char(common);
3442      add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3443      return TRUE;
3444    
3445      case 2:
3446      if (readch)
3447        read_char(common);
3448      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3449      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3450      return TRUE;
3451    
3452      case 4:
3453      if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])
3454        {
3455        if (readch)
3456          read_char(common);
3457        if (ranges[1] != 0)
3458          {
3459          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3460          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3461          }
3462        else
3463          {
3464          jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);
3465          add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3466          JUMPHERE(jump);
3467          }
3468        return TRUE;
3469        }
3470      if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))
3471        {
3472        if (readch)
3473          read_char(common);
3474        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);
3475        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3476        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3477        return TRUE;
3478        }
3479      return FALSE;
3480    
3481      default:
3482      return FALSE;
3483      }
3484    }
3485    
3486    static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)
3487    {
3488    int i, bit, length;
3489    const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;
3490    
3491    bit = ctypes[0] & flag;
3492    ranges[0] = -1;
3493    ranges[1] = bit != 0 ? 1 : 0;
3494    length = 0;
3495    
3496    for (i = 1; i < 256; i++)
3497      if ((ctypes[i] & flag) != bit)
3498        {
3499        if (length >= MAX_RANGE_SIZE)
3500          return;
3501        ranges[2 + length] = i;
3502        length++;
3503        bit ^= flag;
3504        }
3505    
3506    if (bit != 0)
3507      {
3508      if (length >= MAX_RANGE_SIZE)
3509        return;
3510      ranges[2 + length] = 256;
3511      length++;
3512      }
3513    ranges[0] = length;
3514    }
3515    
3516    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)
3517    {
3518    int ranges[2 + MAX_RANGE_SIZE];
3519    pcre_uint8 bit, cbit, all;
3520    int i, byte, length = 0;
3521    
3522    bit = bits[0] & 0x1;
3523    ranges[1] = bit;
3524    /* Can be 0 or 255. */
3525    all = -bit;
3526    
3527    for (i = 0; i < 256; )
3528      {
3529      byte = i >> 3;
3530      if ((i & 0x7) == 0 && bits[byte] == all)
3531        i += 8;
3532      else
3533        {
3534        cbit = (bits[byte] >> (i & 0x7)) & 0x1;
3535        if (cbit != bit)
3536          {
3537          if (length >= MAX_RANGE_SIZE)
3538            return FALSE;
3539          ranges[2 + length] = i;
3540          length++;
3541          bit = cbit;
3542          all = -cbit;
3543          }
3544        i++;
3545        }
3546      }
3547    
3548    if (((bit == 0) && nclass) || ((bit == 1) && !nclass))
3549      {
3550      if (length >= MAX_RANGE_SIZE)
3551        return FALSE;
3552      ranges[2 + length] = 256;
3553      length++;
3554      }
3555    ranges[0] = length;
3556    
3557    return check_ranges(common, ranges, backtracks, FALSE);
3558    }
3559    
3560  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
3561  {  {
3562  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3563  DEFINE_COMPILER;  DEFINE_COMPILER;
3564    
3565  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3566    
3567  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3568  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);
3569  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3570  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);
3571  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3572  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3573  if (common->utf)  if (common->utf)
3574    {    {
3575  #endif  #endif
3576    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3577    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3578    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);
3579  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3580    }    }
3581  #endif  #endif
3582  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3583  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);
3584  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3585  }  }
3586    
# Line 2297  static void check_hspace(compiler_common Line 3589  static void check_hspace(compiler_common
3589  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3590  DEFINE_COMPILER;  DEFINE_COMPILER;
3591    
3592  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3593    
3594  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09);
3595  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3596  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
3597  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3598  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0);
3599  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3600  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3601  if (common->utf)  if (common->utf)
3602    {    {
3603  #endif  #endif
3604    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3605    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680);
3606    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3607    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e);
3608    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3609    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3610    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000);
3611    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3612    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000);
3613    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3614    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);
3615    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3616    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000);
3617  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3618    }    }
3619  #endif  #endif
3620  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3621  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);
3622    
3623  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3624  }  }
# Line 2336  static void check_vspace(compiler_common Line 3628  static void check_vspace(compiler_common
3628  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */  /* Check whether TMP1 contains a newline character. TMP2 destroyed. */
3629  DEFINE_COMPILER;  DEFINE_COMPILER;
3630    
3631  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3632    
3633  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3634  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);
3635  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3636  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);
3637  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3638  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3639  if (common->utf)  if (common->utf)
3640    {    {
3641  #endif  #endif
3642    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);
3643    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3644    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);
3645  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3646    }    }
3647  #endif  #endif
3648  #endif /* SUPPORT_UTF || COMPILE_PCRE16 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3649  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);
3650    
3651  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3652  }  }
# Line 2368  DEFINE_COMPILER; Line 3660  DEFINE_COMPILER;
3660  struct sljit_jump *jump;  struct sljit_jump *jump;
3661  struct sljit_label *label;  struct sljit_label *label;
3662    
3663  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3664  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3665  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);  OP1(SLJIT_MOV, TMP3, 0, CHAR1, 0);
3666  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, CHAR2, 0);
# Line 2397  DEFINE_COMPILER; Line 3689  DEFINE_COMPILER;
3689  struct sljit_jump *jump;  struct sljit_jump *jump;
3690  struct sljit_label *label;  struct sljit_label *label;
3691    
3692  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0, 1, 5, 5, common->localsize);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3693  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3694    
3695  OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);  OP1(SLJIT_MOV, TMP3, 0, LCC_TABLE, 0);
# Line 2440  sljit_emit_fast_return(compiler, RETURN_ Line 3732  sljit_emit_fast_return(compiler, RETURN_
3732    
3733  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3734    
3735  static const pcre_uchar *SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1)  static const pcre_uchar * SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1)
3736  {  {
3737  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3738  int c1, c2;  pcre_uint32 c1, c2;
3739  const pcre_uchar *src2 = args->ptr;  const pcre_uchar *src2 = args->uchar_ptr;
3740  const pcre_uchar *end2 = args->end;  const pcre_uchar *end2 = args->end;
3741    const ucd_record *ur;
3742    const pcre_uint32 *pp;
3743    
3744  while (src1 < end1)  while (src1 < end1)
3745    {    {
3746    if (src2 >= end2)    if (src2 >= end2)
3747      return 0;      return (pcre_uchar*)1;
3748    GETCHARINC(c1, src1);    GETCHARINC(c1, src1);
3749    GETCHARINC(c2, src2);    GETCHARINC(c2, src2);
3750    if (c1 != c2 && c1 != UCD_OTHERCASE(c2)) return 0;    ur = GET_UCD(c2);
3751      if (c1 != c2 && c1 != c2 + ur->other_case)
3752        {
3753        pp = PRIV(ucd_caseless_sets) + ur->caseset;
3754        for (;;)
3755          {
3756          if (c1 < *pp) return NULL;
3757          if (c1 == *pp++) break;
3758          }
3759        }
3760    }    }
3761  return src2;  return src2;
3762  }  }
# Line 2461  return src2; Line 3764  return src2;
3764  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
3765    
3766  static pcre_uchar *byte_sequence_compare(compiler_common *common, BOOL caseless, pcre_uchar *cc,  static pcre_uchar *byte_sequence_compare(compiler_common *common, BOOL caseless, pcre_uchar *cc,
3767      compare_context* context, jump_list **fallbacks)      compare_context* context, jump_list **backtracks)
3768  {  {
3769  DEFINE_COMPILER;  DEFINE_COMPILER;
3770  unsigned int othercasebit = 0;  unsigned int othercasebit = 0;
# Line 2475  if (caseless && char_has_othercase(commo Line 3778  if (caseless && char_has_othercase(commo
3778    othercasebit = char_get_othercase_bit(common, cc);    othercasebit = char_get_othercase_bit(common, cc);
3779    SLJIT_ASSERT(othercasebit);    SLJIT_ASSERT(othercasebit);
3780    /* Extracting bit difference info. */    /* Extracting bit difference info. */
3781  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3782    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
3783    othercasebit &= 0xff;    othercasebit &= 0xff;
3784  #else  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3785  #ifdef COMPILE_PCRE16    /* Note that this code only handles characters in the BMP. If there
3786      ever are characters outside the BMP whose othercase differs in only one
3787      bit from itself (there currently are none), this code will need to be
3788      revised for COMPILE_PCRE32. */
3789    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
3790    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
3791      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
3792    else    else
3793      othercasebit &= 0xff;      othercasebit &= 0xff;
3794  #endif  #endif /* COMPILE_PCRE[8|16|32] */
 #endif  
3795    }    }
3796    
3797  if (context->sourcereg == -1)  if (context->sourcereg == -1)
3798    {    {
3799  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3800  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3801    if (context->length >= 4)    if (context->length >= 4)
3802      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
# Line 2500  if (context->sourcereg == -1) Line 3805  if (context->sourcereg == -1)
3805    else    else
3806  #endif  #endif
3807      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3808  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
3809  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3810    if (context->length >= 4)    if (context->length >= 4)
3811      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3812    else    else
3813  #endif  #endif
3814      OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3815  #endif  #elif defined COMPILE_PCRE32
3816  #endif /* COMPILE_PCRE8 */    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -context->length);
3817    #endif /* COMPILE_PCRE[8|16|32] */
3818    context->sourcereg = TMP2;    context->sourcereg = TMP2;
3819    }    }
3820    
# Line 2523  do Line 3828  do
3828  #endif  #endif
3829    
3830    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3831  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3832    
3833    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3834    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 2538  do Line 3843  do
3843      }      }
3844    context->ucharptr++;    context->ucharptr++;
3845    
3846  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3847    if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1))    if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1))
3848  #else  #else
3849    if (context->ucharptr >= 2 || context->length == 0)    if (context->ucharptr >= 2 || context->length == 0)
# Line 2546  do Line 3851  do
3851      {      {
3852      if (context->length >= 4)      if (context->length >= 4)
3853        OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
 #ifdef COMPILE_PCRE8  
3854      else if (context->length >= 2)      else if (context->length >= 2)
3855        OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3856    #if defined COMPILE_PCRE8
3857      else if (context->length >= 1)      else if (context->length >= 1)
3858        OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3859  #else  #endif /* COMPILE_PCRE8 */
     else if (context->length >= 2)  
       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
3860      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3861    
3862      switch(context->ucharptr)      switch(context->ucharptr)
# Line 2562  do Line 3864  do
3864        case 4 / sizeof(pcre_uchar):        case 4 / sizeof(pcre_uchar):
3865        if (context->oc.asint != 0)        if (context->oc.asint != 0)
3866          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asint);          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asint);
3867        add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asint | context->oc.asint));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asint | context->oc.asint));
3868        break;        break;
3869    
3870        case 2 / sizeof(pcre_uchar):        case 2 / sizeof(pcre_uchar):
3871        if (context->oc.asushort != 0)        if (context->oc.asushort != 0)
3872          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asushort);          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asushort);
3873        add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asushort | context->oc.asushort));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asushort | context->oc.asushort));
3874        break;        break;
3875    
3876  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3877        case 1:        case 1:
3878        if (context->oc.asbyte != 0)        if (context->oc.asbyte != 0)
3879          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asbyte);          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asbyte);
3880        add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asbyte | context->oc.asbyte));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asbyte | context->oc.asbyte));
3881        break;        break;
3882  #endif  #endif
3883    
# Line 2588  do Line 3890  do
3890    
3891  #else  #else
3892    
3893    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3894  #ifdef COMPILE_PCRE8    if (context->length >= 1)
3895    if (context->length > 0)      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3896      OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #else  
   if (context->length > 0)  
     OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif  
3897    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3898    
3899    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
3900      {      {
3901      OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, othercasebit);      OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, othercasebit);
3902      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, *cc | othercasebit));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, *cc | othercasebit));
3903      }      }
3904    else    else
3905      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, *cc));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, *cc));
3906    
3907  #endif  #endif
3908    
# Line 2640  return cc; Line 3938  return cc;
3938      } \      } \
3939    charoffset = (value);    charoffset = (value);
3940    
3941  static void compile_xclass_hotpath(compiler_common *common, pcre_uchar *cc, jump_list **fallbacks)  static void compile_xclass_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)
3942  {  {
3943  DEFINE_COMPILER;  DEFINE_COMPILER;
3944  jump_list *found = NULL;  jump_list *found = NULL;
3945  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : fallbacks;  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;
3946  unsigned int