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

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

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

revision 999 by zherczeg, Mon Aug 6 07:36:49 2012 UTC revision 1427 by zherczeg, Wed Jan 1 15:15:09 2014 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11    The machine code generator part (this module) was written by Zoltan Herczeg    The machine code generator part (this module) was written by Zoltan Herczeg
12                        Copyright (c) 2010-2012                        Copyright (c) 2010-2013
13    
14  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
15  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 46  POSSIBILITY OF SUCH DAMAGE. Line 46  POSSIBILITY OF SUCH DAMAGE.
46    
47  #include "pcre_internal.h"  #include "pcre_internal.h"
48    
49  #ifdef SUPPORT_JIT  #if defined SUPPORT_JIT
50    
51  /* All-in-one: Since we use the JIT compiler only from here,  /* All-in-one: Since we use the JIT compiler only from here,
52  we just include it. This way we don't need to touch the build  we just include it. This way we don't need to touch the build
# Line 65  system files. */ Line 65  system files. */
65  #error Unsupported architecture  #error Unsupported architecture
66  #endif  #endif
67    
68  /* Allocate memory on the stack. Fast, but limited size. */  /* Defines for debugging purposes. */
 #define LOCAL_SPACE_SIZE 32768  
69    
70    /* 1 - Use unoptimized capturing brackets.
71       2 - Enable capture_last_ptr (includes option 1). */
72    /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */
73    
74    /* 1 - Always have a control head. */
75    /* #define DEBUG_FORCE_CONTROL_HEAD 1 */
76    
77    /* Allocate memory for the regex stack on the real machine stack.
78    Fast, but limited size. */
79    #define MACHINE_STACK_SIZE 32768
80    
81    /* Growth rate for stack allocated by the OS. Should be the multiply
82    of page size. */
83  #define STACK_GROWTH_RATE 8192  #define STACK_GROWTH_RATE 8192
84    
85  /* Enable to check that the allocation could destroy temporaries. */  /* Enable to check that the allocation could destroy temporaries. */
# Line 134  The generated code will be the following Line 146  The generated code will be the following
146  /*  /*
147  Saved stack frames:  Saved stack frames:
148    
149  Atomic blocks and asserts require reloading the values of local variables  Atomic blocks and asserts require reloading the values of private data
150  when the backtrack mechanism performed. Because of OP_RECURSE, the locals  when the backtrack mechanism performed. Because of OP_RECURSE, the data
151  are not necessarly known in compile time, thus we need a dynamic restore  are not necessarly known in compile time, thus we need a dynamic restore
152  mechanism.  mechanism.
153    
154  The stack frames are stored in a chain list, and have the following format:  The stack frames are stored in a chain list, and have the following format:
155  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]  ([ capturing bracket offset ][ start value ][ end value ])+ ... [ 0 ] [ previous head ]
156    
157  Thus we can restore the locals to a particular point in the stack.  Thus we can restore the private data to a particular point in the stack.
158  */  */
159    
160  typedef struct jit_arguments {  typedef struct jit_arguments {
# Line 154  typedef struct jit_arguments { Line 166  typedef struct jit_arguments {
166    int *offsets;    int *offsets;
167    pcre_uchar *uchar_ptr;    pcre_uchar *uchar_ptr;
168    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
169      void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171    int offsetcount;    pcre_uint32 limit_match;
172    int calllimit;    int real_offset_count;
173      int offset_count;
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 167  typedef struct executable_functions { Line 181  typedef struct executable_functions {
181    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184      pcre_uint32 top_bracket;
185      pcre_uint32 limit_match;
186    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
187  } executable_functions;  } executable_functions;
188    
# Line 175  typedef struct jump_list { Line 191  typedef struct jump_list {
191    struct jump_list *next;    struct jump_list *next;
192  } jump_list;  } jump_list;
193    
 enum stub_types { stack_alloc };  
   
194  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
195    struct sljit_jump *start;    struct sljit_jump *start;
196    struct sljit_label *quit;    struct sljit_label *quit;
197    struct stub_list *next;    struct stub_list *next;
198  } stub_list;  } stub_list;
199    
200    enum frame_types {
201      no_frame = -1,
202      no_stack = -2
203    };
204    
205    enum control_types {
206      type_mark = 0,
207      type_then_trap = 1
208    };
209    
210  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
213  code generator. It is allocated by compile_matchingpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
214  the aguments for compile_backtrackingpath. Must be the first member  the arguments for compile_backtrackingpath. Must be the first member
215  of its descendants. */  of its descendants. */
216  typedef struct backtrack_common {  typedef struct backtrack_common {
217    /* Concatenation stack. */    /* Concatenation stack. */
# Line 205  typedef struct backtrack_common { Line 227  typedef struct backtrack_common {
227  typedef struct assert_backtrack {  typedef struct assert_backtrack {
228    backtrack_common common;    backtrack_common common;
229    jump_list *condfailed;    jump_list *condfailed;
230    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
231    int framesize;    int framesize;
232    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
233    int localptr;    int private_data_ptr;
234    /* For iterators. */    /* For iterators. */
235    struct sljit_label *matchingpath;    struct sljit_label *matchingpath;
236  } assert_backtrack;  } assert_backtrack;
# Line 226  typedef struct bracket_backtrack { Line 248  typedef struct bracket_backtrack {
248      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
249      jump_list *condfailed;      jump_list *condfailed;
250      assert_backtrack *assert;      assert_backtrack *assert;
251      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
252      int framesize;      int framesize;
253    } u;    } u;
254    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
255    int localptr;    int private_data_ptr;
256  } bracket_backtrack;  } bracket_backtrack;
257    
258  typedef struct bracketpos_backtrack {  typedef struct bracketpos_backtrack {
259    backtrack_common common;    backtrack_common common;
260    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
261    int localptr;    int private_data_ptr;
262    /* Reverting stack is needed. */    /* Reverting stack is needed. */
263    int framesize;    int framesize;
264    /* Allocated stack size. */    /* Allocated stack size. */
# Line 261  typedef struct recurse_entry { Line 283  typedef struct recurse_entry {
283    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
284    jump_list *calls;    jump_list *calls;
285    /* Points to the starting opcode. */    /* Points to the starting opcode. */
286    int start;    sljit_sw start;
287  } recurse_entry;  } recurse_entry;
288    
289  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
290    backtrack_common common;    backtrack_common common;
291      BOOL inlined_pattern;
292  } recurse_backtrack;  } recurse_backtrack;
293    
294  #define MAX_RANGE_SIZE 6  #define OP_THEN_TRAP OP_TABLE_LENGTH
295    
296    typedef struct then_trap_backtrack {
297      backtrack_common common;
298      /* If then_trap is not NULL, this structure contains the real
299      then_trap for the backtracking path. */
300      struct then_trap_backtrack *then_trap;
301      /* Points to the starting opcode. */
302      sljit_sw start;
303      /* Exit point for the then opcodes of this alternative. */
304      jump_list *quit;
305      /* Frame size of the current alternative. */
306      int framesize;
307    } then_trap_backtrack;
308    
309    #define MAX_RANGE_SIZE 4
310    
311  typedef struct compiler_common {  typedef struct compiler_common {
312      /* The sljit ceneric compiler. */
313    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
314      /* First byte code. */
315    pcre_uchar *start;    pcre_uchar *start;
316      /* Maps private data offset to each opcode. */
317    /* Opcode local area direct map. */    sljit_si *private_data_ptrs;
318    int *localptrs;    /* Tells whether the capturing bracket is optimized. */
319    int cbraptr;    pcre_uint8 *optimized_cbracket;
320    /* OVector starting point. Must be divisible by 2. */    /* Tells whether the starting offset is a target of then. */
321      pcre_uint8 *then_offsets;
322      /* Current position where a THEN must jump. */
323      then_trap_backtrack *then_trap;
324      /* Starting offset of private data for capturing brackets. */
325      int cbra_ptr;
326      /* Output vector starting point. Must be divisible by 2. */
327    int ovector_start;    int ovector_start;
328    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
329    int req_char_ptr;    int req_char_ptr;
330    /* Head of the last recursion. */    /* Head of the last recursion. */
331    int recursive_head;    int recursive_head_ptr;
332    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
333    int start_used_ptr;    int start_used_ptr;
334    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 291  typedef struct compiler_common { Line 337  typedef struct compiler_common {
337    int first_line_end;    int first_line_end;
338    /* Points to the marked string. */    /* Points to the marked string. */
339    int mark_ptr;    int mark_ptr;
340      /* Recursive control verb management chain. */
341      int control_head_ptr;
342      /* Points to the last matched capture block index. */
343      int capture_last_ptr;
344      /* Points to the starting position of the current match. */
345      int start_ptr;
346    
347    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
348    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
349    sljit_w lcc;    sljit_sw lcc;
350    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
351    int mode;    int mode;
352      /* \K is found in the pattern. */
353      BOOL has_set_som;
354      /* (*SKIP:arg) is found in the pattern. */
355      BOOL has_skip_arg;
356      /* (*THEN) is found in the pattern. */
357      BOOL has_then;
358      /* Needs to know the start position anytime. */
359      BOOL needs_start_ptr;
360      /* Currently in recurse or negative assert. */
361      BOOL local_exit;
362      /* Currently in a positive assert. */
363      BOOL positive_assert;
364    /* Newline control. */    /* Newline control. */
365    int nltype;    int nltype;
366      pcre_uint32 nlmax;
367      pcre_uint32 nlmin;
368    int newline;    int newline;
369    int bsr_nltype;    int bsr_nltype;
370      pcre_uint32 bsr_nlmax;
371      pcre_uint32 bsr_nlmin;
372    /* Dollar endonly. */    /* Dollar endonly. */
373    int endonly;    int endonly;
   BOOL has_set_som;  
374    /* Tables. */    /* Tables. */
375    sljit_w ctypes;    sljit_sw ctypes;
   int digits[2 + MAX_RANGE_SIZE];  
376    /* Named capturing brackets. */    /* Named capturing brackets. */
377    sljit_uw name_table;    pcre_uchar *name_table;
378    sljit_w name_count;    sljit_sw name_count;
379    sljit_w name_entry_size;    sljit_sw name_entry_size;
380    
381    /* Labels and jump lists. */    /* Labels and jump lists. */
382    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
383    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
384    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
385      struct sljit_label *accept_label;
386    stub_list *stubs;    stub_list *stubs;
387    recurse_entry *entries;    recurse_entry *entries;
388    recurse_entry *currententry;    recurse_entry *currententry;
389    jump_list *partialmatch;    jump_list *partialmatch;
390    jump_list *quit;    jump_list *quit;
391      jump_list *positive_assert_quit;
392      jump_list *forced_quit;
393    jump_list *accept;    jump_list *accept;
394    jump_list *calllimit;    jump_list *calllimit;
395    jump_list *stackalloc;    jump_list *stackalloc;
# Line 331  typedef struct compiler_common { Line 400  typedef struct compiler_common {
400    jump_list *vspace;    jump_list *vspace;
401    jump_list *casefulcmp;    jump_list *casefulcmp;
402    jump_list *caselesscmp;    jump_list *caselesscmp;
403      jump_list *reset_match;
404    BOOL jscript_compat;    BOOL jscript_compat;
405  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
406    BOOL utf;    BOOL utf;
407  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
408    BOOL use_ucp;    BOOL use_ucp;
409  #endif  #endif
   jump_list *utfreadchar;  
410  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
411      jump_list *utfreadchar;
412      jump_list *utfreadchar16;
413    jump_list *utfreadtype8;    jump_list *utfreadtype8;
414  #endif  #endif
415  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
# Line 355  typedef struct compare_context { Line 426  typedef struct compare_context {
426  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
427    int ucharptr;    int ucharptr;
428    union {    union {
429      sljit_i asint;      sljit_si asint;
430      sljit_uh asushort;      sljit_uh asushort;
431  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
432      sljit_ub asbyte;      sljit_ub asbyte;
433      sljit_ub asuchars[4];      sljit_ub asuchars[4];
434  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
435      sljit_uh asuchars[2];      sljit_uh asuchars[2];
436  #endif  #elif defined COMPILE_PCRE32
437        sljit_ui asuchars[1];
438  #endif  #endif
439    } c;    } c;
440    union {    union {
441      sljit_i asint;      sljit_si asint;
442      sljit_uh asushort;      sljit_uh asushort;
443  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
444      sljit_ub asbyte;      sljit_ub asbyte;
445      sljit_ub asuchars[4];      sljit_ub asuchars[4];
446  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
447      sljit_uh asuchars[2];      sljit_uh asuchars[2];
448  #endif  #elif defined COMPILE_PCRE32
449        sljit_ui asuchars[1];
450  #endif  #endif
451    } oc;    } oc;
452  #endif  #endif
453  } compare_context;  } compare_context;
454    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
455  /* Undefine sljit macros. */  /* Undefine sljit macros. */
456  #undef CMP  #undef CMP
457    
458  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
459  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
460    
461  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
462  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
463  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
464  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
465  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
466  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
467  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
468  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
469  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define COUNT_MATCH   SLJIT_SAVED_EREG2
470  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
471    
472  /* Locals layout. */  /* Local space layout. */
473  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
474  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
475  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
476  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
477  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
478  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
479  /* Max limit of recursions. */  /* Max limit of recursions. */
480  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
481  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
482  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
483  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
484  the start pointers when the end of the capturing group has not yet reached. */  the start pointers when the end of the capturing group has not yet reached. */
485  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
486  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw))
487  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
488  #define PRIV_DATA(cc)    (common->localptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
489    
490  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
491  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
492  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
493  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
494  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
495  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
496    #elif defined COMPILE_PCRE32
497    #define MOV_UCHAR  SLJIT_MOV_UI
498    #define MOVU_UCHAR SLJIT_MOVU_UI
499  #else  #else
500  #error Unsupported compiling mode  #error Unsupported compiling mode
501  #endif  #endif
 #endif  
502    
503  /* Shortcuts. */  /* Shortcuts. */
504  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 449  the start pointers when the end of the c Line 515  the start pointers when the end of the c
515    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
516  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
517    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
518    #define SET_LABEL(jump, label) \
519      sljit_set_label((jump), (label))
520  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
521    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
522  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
523    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))
524  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
525    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
526  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
527    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
528    
529    #define READ_CHAR_MAX 0x7fffffff
530    
531  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
532  {  {
533  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
# Line 467  cc += 1 + LINK_SIZE; Line 537  cc += 1 + LINK_SIZE;
537  return cc;  return cc;
538  }  }
539    
540    static int ones_in_half_byte[16] = {
541      /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
542      /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
543    };
544    
545  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
546   next_opcode   next_opcode
547   get_localspace   check_opcode_types
548   set_localptrs   set_private_data_ptrs
549   get_framesize   get_framesize
550   init_frame   init_frame
551   get_localsize   get_private_data_copy_length
552   copy_locals   copy_private_data
553   compile_matchingpath   compile_matchingpath
554   compile_backtrackingpath   compile_backtrackingpath
555  */  */
# Line 497  switch(*cc) Line 572  switch(*cc)
572    case OP_WORDCHAR:    case OP_WORDCHAR:
573    case OP_ANY:    case OP_ANY:
574    case OP_ALLANY:    case OP_ALLANY:
575      case OP_NOTPROP:
576      case OP_PROP:
577    case OP_ANYNL:    case OP_ANYNL:
578    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
579    case OP_HSPACE:    case OP_HSPACE:
# Line 509  switch(*cc) Line 586  switch(*cc)
586    case OP_CIRCM:    case OP_CIRCM:
587    case OP_DOLL:    case OP_DOLL:
588    case OP_DOLLM:    case OP_DOLLM:
   case OP_TYPESTAR:  
   case OP_TYPEMINSTAR:  
   case OP_TYPEPLUS:  
   case OP_TYPEMINPLUS:  
   case OP_TYPEQUERY:  
   case OP_TYPEMINQUERY:  
   case OP_TYPEPOSSTAR:  
   case OP_TYPEPOSPLUS:  
   case OP_TYPEPOSQUERY:  
589    case OP_CRSTAR:    case OP_CRSTAR:
590    case OP_CRMINSTAR:    case OP_CRMINSTAR:
591    case OP_CRPLUS:    case OP_CRPLUS:
592    case OP_CRMINPLUS:    case OP_CRMINPLUS:
593    case OP_CRQUERY:    case OP_CRQUERY:
594    case OP_CRMINQUERY:    case OP_CRMINQUERY:
595      case OP_CRRANGE:
596      case OP_CRMINRANGE:
597      case OP_CRPOSSTAR:
598      case OP_CRPOSPLUS:
599      case OP_CRPOSQUERY:
600      case OP_CRPOSRANGE:
601      case OP_CLASS:
602      case OP_NCLASS:
603      case OP_REF:
604      case OP_REFI:
605      case OP_DNREF:
606      case OP_DNREFI:
607      case OP_RECURSE:
608      case OP_CALLOUT:
609      case OP_ALT:
610      case OP_KET:
611      case OP_KETRMAX:
612      case OP_KETRMIN:
613      case OP_KETRPOS:
614      case OP_REVERSE:
615      case OP_ASSERT:
616      case OP_ASSERT_NOT:
617      case OP_ASSERTBACK:
618      case OP_ASSERTBACK_NOT:
619      case OP_ONCE:
620      case OP_ONCE_NC:
621      case OP_BRA:
622      case OP_BRAPOS:
623      case OP_CBRA:
624      case OP_CBRAPOS:
625      case OP_COND:
626      case OP_SBRA:
627      case OP_SBRAPOS:
628      case OP_SCBRA:
629      case OP_SCBRAPOS:
630      case OP_SCOND:
631      case OP_CREF:
632      case OP_DNCREF:
633      case OP_RREF:
634      case OP_DNRREF:
635    case OP_DEF:    case OP_DEF:
636    case OP_BRAZERO:    case OP_BRAZERO:
637    case OP_BRAMINZERO:    case OP_BRAMINZERO:
638    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
639      case OP_PRUNE:
640      case OP_SKIP:
641      case OP_THEN:
642    case OP_COMMIT:    case OP_COMMIT:
643    case OP_FAIL:    case OP_FAIL:
644    case OP_ACCEPT:    case OP_ACCEPT:
645    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
646      case OP_CLOSE:
647    case OP_SKIPZERO:    case OP_SKIPZERO:
648    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
649    
650    case OP_CHAR:    case OP_CHAR:
651    case OP_CHARI:    case OP_CHARI:
# Line 551  switch(*cc) Line 657  switch(*cc)
657    case OP_MINPLUS:    case OP_MINPLUS:
658    case OP_QUERY:    case OP_QUERY:
659    case OP_MINQUERY:    case OP_MINQUERY:
660      case OP_UPTO:
661      case OP_MINUPTO:
662      case OP_EXACT:
663    case OP_POSSTAR:    case OP_POSSTAR:
664    case OP_POSPLUS:    case OP_POSPLUS:
665    case OP_POSQUERY:    case OP_POSQUERY:
666      case OP_POSUPTO:
667    case OP_STARI:    case OP_STARI:
668    case OP_MINSTARI:    case OP_MINSTARI:
669    case OP_PLUSI:    case OP_PLUSI:
670    case OP_MINPLUSI:    case OP_MINPLUSI:
671    case OP_QUERYI:    case OP_QUERYI:
672    case OP_MINQUERYI:    case OP_MINQUERYI:
673      case OP_UPTOI:
674      case OP_MINUPTOI:
675      case OP_EXACTI:
676    case OP_POSSTARI:    case OP_POSSTARI:
677    case OP_POSPLUSI:    case OP_POSPLUSI:
678    case OP_POSQUERYI:    case OP_POSQUERYI:
679      case OP_POSUPTOI:
680    case OP_NOTSTAR:    case OP_NOTSTAR:
681    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
682    case OP_NOTPLUS:    case OP_NOTPLUS:
683    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
684    case OP_NOTQUERY:    case OP_NOTQUERY:
685    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
686      case OP_NOTUPTO:
687      case OP_NOTMINUPTO:
688      case OP_NOTEXACT:
689    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
690    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
691    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
692      case OP_NOTPOSUPTO:
693    case OP_NOTSTARI:    case OP_NOTSTARI:
694    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
695    case OP_NOTPLUSI:    case OP_NOTPLUSI:
696    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
697    case OP_NOTQUERYI:    case OP_NOTQUERYI:
698    case OP_NOTMINQUERYI:    case OP_NOTMINQUERYI:
   case OP_NOTPOSSTARI:  
   case OP_NOTPOSPLUSI:  
   case OP_NOTPOSQUERYI:  
   cc += 2;  
 #ifdef SUPPORT_UTF  
   if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
   return cc;  
   
   case OP_UPTO:  
   case OP_MINUPTO:  
   case OP_EXACT:  
   case OP_POSUPTO:  
   case OP_UPTOI:  
   case OP_MINUPTOI:  
   case OP_EXACTI:  
   case OP_POSUPTOI:  
   case OP_NOTUPTO:  
   case OP_NOTMINUPTO:  
   case OP_NOTEXACT:  
   case OP_NOTPOSUPTO:  
699    case OP_NOTUPTOI:    case OP_NOTUPTOI:
700    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
701    case OP_NOTEXACTI:    case OP_NOTEXACTI:
702      case OP_NOTPOSSTARI:
703      case OP_NOTPOSPLUSI:
704      case OP_NOTPOSQUERYI:
705    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
706    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
707  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
708    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
709  #endif  #endif
710    return cc;    return cc;
711    
712    case OP_NOTPROP:    /* Special cases. */
713    case OP_PROP:    case OP_TYPESTAR:
714    return cc + 1 + 2;    case OP_TYPEMINSTAR:
715      case OP_TYPEPLUS:
716      case OP_TYPEMINPLUS:
717      case OP_TYPEQUERY:
718      case OP_TYPEMINQUERY:
719    case OP_TYPEUPTO:    case OP_TYPEUPTO:
720    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
721    case OP_TYPEEXACT:    case OP_TYPEEXACT:
722      case OP_TYPEPOSSTAR:
723      case OP_TYPEPOSPLUS:
724      case OP_TYPEPOSQUERY:
725    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
726    case OP_REF:    return cc + PRIV(OP_lengths)[*cc] - 1;
   case OP_REFI:  
   case OP_CREF:  
   case OP_NCREF:  
   case OP_RREF:  
   case OP_NRREF:  
   case OP_CLOSE:  
   cc += 1 + IMM2_SIZE;  
   return cc;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   return cc + 1 + 2 * IMM2_SIZE;  
727    
728    case OP_CLASS:    case OP_ANYBYTE:
729    case OP_NCLASS:  #ifdef SUPPORT_UTF
730    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
731    #endif
732      return cc + 1;
733    
734  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
735    case OP_XCLASS:    case OP_XCLASS:
736    return cc + GET(cc, 1);    return cc + GET(cc, 1);
737  #endif  #endif
738    
   case OP_RECURSE:  
   case OP_ASSERT:  
   case OP_ASSERT_NOT:  
   case OP_ASSERTBACK:  
   case OP_ASSERTBACK_NOT:  
   case OP_REVERSE:  
   case OP_ONCE:  
   case OP_ONCE_NC:  
   case OP_BRA:  
   case OP_BRAPOS:  
   case OP_COND:  
   case OP_SBRA:  
   case OP_SBRAPOS:  
   case OP_SCOND:  
   case OP_ALT:  
   case OP_KET:  
   case OP_KETRMAX:  
   case OP_KETRMIN:  
   case OP_KETRPOS:  
   return cc + 1 + LINK_SIZE;  
   
   case OP_CBRA:  
   case OP_CBRAPOS:  
   case OP_SCBRA:  
   case OP_SCBRAPOS:  
   return cc + 1 + LINK_SIZE + IMM2_SIZE;  
   
739    case OP_MARK:    case OP_MARK:
740      case OP_PRUNE_ARG:
741      case OP_SKIP_ARG:
742      case OP_THEN_ARG:
743    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
744    
745    default:    default:
746      /* All opcodes are supported now! */
747      SLJIT_ASSERT_STOP();
748    return NULL;    return NULL;
749    }    }
750  }  }
751    
752  #define CASE_ITERATOR_LOCAL1 \  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
     case OP_MINSTAR: \  
     case OP_MINPLUS: \  
     case OP_QUERY: \  
     case OP_MINQUERY: \  
     case OP_MINSTARI: \  
     case OP_MINPLUSI: \  
     case OP_QUERYI: \  
     case OP_MINQUERYI: \  
     case OP_NOTMINSTAR: \  
     case OP_NOTMINPLUS: \  
     case OP_NOTQUERY: \  
     case OP_NOTMINQUERY: \  
     case OP_NOTMINSTARI: \  
     case OP_NOTMINPLUSI: \  
     case OP_NOTQUERYI: \  
     case OP_NOTMINQUERYI:  
   
 #define CASE_ITERATOR_LOCAL2A \  
     case OP_STAR: \  
     case OP_PLUS: \  
     case OP_STARI: \  
     case OP_PLUSI: \  
     case OP_NOTSTAR: \  
     case OP_NOTPLUS: \  
     case OP_NOTSTARI: \  
     case OP_NOTPLUSI:  
   
 #define CASE_ITERATOR_LOCAL2B \  
     case OP_UPTO: \  
     case OP_MINUPTO: \  
     case OP_UPTOI: \  
     case OP_MINUPTOI: \  
     case OP_NOTUPTO: \  
     case OP_NOTMINUPTO: \  
     case OP_NOTUPTOI: \  
     case OP_NOTMINUPTOI:  
   
 #define CASE_ITERATOR_TYPE_LOCAL1 \  
     case OP_TYPEMINSTAR: \  
     case OP_TYPEMINPLUS: \  
     case OP_TYPEQUERY: \  
     case OP_TYPEMINQUERY:  
   
 #define CASE_ITERATOR_TYPE_LOCAL2A \  
     case OP_TYPESTAR: \  
     case OP_TYPEPLUS:  
   
 #define CASE_ITERATOR_TYPE_LOCAL2B \  
     case OP_TYPEUPTO: \  
     case OP_TYPEMINUPTO:  
   
 static int get_class_iterator_size(pcre_uchar *cc)  
 {  
 switch(*cc)  
   {  
   case OP_CRSTAR:  
   case OP_CRPLUS:  
   return 2;  
   
   case OP_CRMINSTAR:  
   case OP_CRMINPLUS:  
   case OP_CRQUERY:  
   case OP_CRMINQUERY:  
   return 1;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))  
     return 0;  
   return 2;  
   
   default:  
   return 0;  
   }  
 }  
   
 static int get_localspace(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  
753  {  {
754  int localspace = 0;  int count;
755  pcre_uchar *alternative;  pcre_uchar *slot;
 pcre_uchar *end = NULL;  
 int space, size, bracketlen;  
756    
757  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
758  while (cc < ccend)  while (cc < ccend)
759    {    {
   space = 0;  
   size = 0;  
   bracketlen = 0;  
760    switch(*cc)    switch(*cc)
761      {      {
762      case OP_SET_SOM:      case OP_SET_SOM:
# Line 772  while (cc < ccend) Line 764  while (cc < ccend)
764      cc += 1;      cc += 1;
765      break;      break;
766    
767      case OP_ASSERT:      case OP_REF:
768      case OP_ASSERT_NOT:      case OP_REFI:
769      case OP_ASSERTBACK:      common->optimized_cbracket[GET2(cc, 1)] = 0;
770      case OP_ASSERTBACK_NOT:      cc += 1 + IMM2_SIZE;
     case OP_ONCE:  
     case OP_ONCE_NC:  
     case OP_BRAPOS:  
     case OP_SBRA:  
     case OP_SBRAPOS:  
     case OP_SCOND:  
     localspace += sizeof(sljit_w);  
     bracketlen = 1 + LINK_SIZE;  
771      break;      break;
772    
773      case OP_CBRAPOS:      case OP_CBRAPOS:
774      case OP_SCBRAPOS:      case OP_SCBRAPOS:
775      localspace += sizeof(sljit_w);      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
776      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
777      break;      break;
778    
779      case OP_COND:      case OP_COND:
780      /* Might be a hidden SCOND. */      case OP_SCOND:
781      alternative = cc + GET(cc, 1);      /* Only AUTO_CALLOUT can insert this opcode. We do
782      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)         not intend to support this case. */
783        localspace += sizeof(sljit_w);      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
784      bracketlen = 1 + LINK_SIZE;        return FALSE;
785      break;      cc += 1 + LINK_SIZE;
   
     case OP_BRA:  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_CBRA:  
     case OP_SCBRA:  
     bracketlen = 1 + LINK_SIZE + IMM2_SIZE;  
     break;  
   
     CASE_ITERATOR_LOCAL1  
     space = 1;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_LOCAL2A  
     space = 2;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_LOCAL2B  
     space = 2;  
     size = -(2 + IMM2_SIZE);  
     break;  
   
     CASE_ITERATOR_TYPE_LOCAL1  
     space = 1;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_LOCAL2A  
     if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)  
       space = 2;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_LOCAL2B  
     if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)  
       space = 2;  
     size = 1 + IMM2_SIZE;  
786      break;      break;
787    
788      case OP_CLASS:      case OP_CREF:
789      case OP_NCLASS:      common->optimized_cbracket[GET2(cc, 1)] = 0;
790      size += 1 + 32 / sizeof(pcre_uchar);      cc += 1 + IMM2_SIZE;
     space = get_class_iterator_size(cc + size);  
791      break;      break;
792    
793  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8      case OP_DNREF:
794      case OP_XCLASS:      case OP_DNREFI:
795      size = GET(cc, 1);      case OP_DNCREF:
796      space = get_class_iterator_size(cc + size);      count = GET2(cc, 1 + IMM2_SIZE);
797        slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
798        while (count-- > 0)
799          {
800          common->optimized_cbracket[GET2(slot, 0)] = 0;
801          slot += common->name_entry_size;
802          }
803        cc += 1 + 2 * IMM2_SIZE;
804      break;      break;
 #endif  
805    
806      case OP_RECURSE:      case OP_RECURSE:
807      /* Set its value only once. */      /* Set its value only once. */
808      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
809        {        {
810        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
811        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
812        }        }
813      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
814      break;      break;
815    
816        case OP_CALLOUT:
817        if (common->capture_last_ptr == 0)
818          {
819          common->capture_last_ptr = common->ovector_start;
820          common->ovector_start += sizeof(sljit_sw);
821          }
822        cc += 2 + 2 * LINK_SIZE;
823        break;
824    
825        case OP_THEN_ARG:
826        common->has_then = TRUE;
827        common->control_head_ptr = 1;
828        /* Fall through. */
829    
830        case OP_PRUNE_ARG:
831        common->needs_start_ptr = TRUE;
832        /* Fall through. */
833    
834      case OP_MARK:      case OP_MARK:
835      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
836        {        {
837        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
838        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
839        }        }
840      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
841      break;      break;
842    
843        case OP_THEN:
844        common->has_then = TRUE;
845        common->control_head_ptr = 1;
846        /* Fall through. */
847    
848        case OP_PRUNE:
849        case OP_SKIP:
850        common->needs_start_ptr = TRUE;
851        cc += 1;
852        break;
853    
854        case OP_SKIP_ARG:
855        common->control_head_ptr = 1;
856        common->has_skip_arg = TRUE;
857        cc += 1 + 2 + cc[1];
858        break;
859    
860      default:      default:
861      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
862      if (cc == NULL)      if (cc == NULL)
863        return -1;        return FALSE;
864      break;      break;
865      }      }
866      }
867    return TRUE;
868    }
869    
870    if (space > 0 && cc >= end)  static int get_class_iterator_size(pcre_uchar *cc)
871      localspace += sizeof(sljit_w) * space;  {
872    switch(*cc)
873      {
874      case OP_CRSTAR:
875      case OP_CRPLUS:
876      return 2;
877    
878    if (size != 0)    case OP_CRMINSTAR:
879      case OP_CRMINPLUS:
880      case OP_CRQUERY:
881      case OP_CRMINQUERY:
882      return 1;
883    
884      case OP_CRRANGE:
885      case OP_CRMINRANGE:
886      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
887        return 0;
888      return 2;
889    
890      default:
891      return 0;
892      }
893    }
894    
895    static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
896    {
897    pcre_uchar *end = bracketend(begin);
898    pcre_uchar *next;
899    pcre_uchar *next_end;
900    pcre_uchar *max_end;
901    pcre_uchar type;
902    sljit_sw length = end - begin;
903    int min, max, i;
904    
905    /* Detect fixed iterations first. */
906    if (end[-(1 + LINK_SIZE)] != OP_KET)
907      return FALSE;
908    
909    /* Already detected repeat. */
910    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
911      return TRUE;
912    
913    next = end;
914    min = 1;
915    while (1)
916      {
917      if (*next != *begin)
918        break;
919      next_end = bracketend(next);
920      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
921        break;
922      next = next_end;
923      min++;
924      }
925    
926    if (min == 2)
927      return FALSE;
928    
929    max = 0;
930    max_end = next;
931    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
932      {
933      type = *next;
934      while (1)
935      {      {
936      if (size < 0)      if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
937        {        break;
938        cc += -size;      next_end = bracketend(next + 2 + LINK_SIZE);
939  #ifdef SUPPORT_UTF      if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
940        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        break;
941  #endif      next = next_end;
942        }      max++;
     else  
       cc += size;  
943      }      }
944    
945    if (bracketlen > 0)    if (next[0] == type && next[1] == *begin && max >= 1)
946      {      {
947      if (cc >= end)      next_end = bracketend(next + 1);
948        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
949        {        {
950        end = bracketend(cc);        for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
951        if (end[-1 - LINK_SIZE] == OP_KET)          if (*next_end != OP_KET)
952          end = NULL;            break;
953    
954          if (i == max)
955            {
956            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
957            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
958            /* +2 the original and the last. */
959            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
960            if (min == 1)
961              return TRUE;
962            min--;
963            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
964            }
965        }        }
     cc += bracketlen;  
966      }      }
967    }    }
968  return localspace;  
969    if (min >= 3)
970      {
971      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
972      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
973      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
974      return TRUE;
975      }
976    
977    return FALSE;
978  }  }
979    
980  static void set_localptrs(compiler_common *common, int localptr, pcre_uchar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
981        case OP_MINSTAR: \
982        case OP_MINPLUS: \
983        case OP_QUERY: \
984        case OP_MINQUERY: \
985        case OP_MINSTARI: \
986        case OP_MINPLUSI: \
987        case OP_QUERYI: \
988        case OP_MINQUERYI: \
989        case OP_NOTMINSTAR: \
990        case OP_NOTMINPLUS: \
991        case OP_NOTQUERY: \
992        case OP_NOTMINQUERY: \
993        case OP_NOTMINSTARI: \
994        case OP_NOTMINPLUSI: \
995        case OP_NOTQUERYI: \
996        case OP_NOTMINQUERYI:
997    
998    #define CASE_ITERATOR_PRIVATE_DATA_2A \
999        case OP_STAR: \
1000        case OP_PLUS: \
1001        case OP_STARI: \
1002        case OP_PLUSI: \
1003        case OP_NOTSTAR: \
1004        case OP_NOTPLUS: \
1005        case OP_NOTSTARI: \
1006        case OP_NOTPLUSI:
1007    
1008    #define CASE_ITERATOR_PRIVATE_DATA_2B \
1009        case OP_UPTO: \
1010        case OP_MINUPTO: \
1011        case OP_UPTOI: \
1012        case OP_MINUPTOI: \
1013        case OP_NOTUPTO: \
1014        case OP_NOTMINUPTO: \
1015        case OP_NOTUPTOI: \
1016        case OP_NOTMINUPTOI:
1017    
1018    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1019        case OP_TYPEMINSTAR: \
1020        case OP_TYPEMINPLUS: \
1021        case OP_TYPEQUERY: \
1022        case OP_TYPEMINQUERY:
1023    
1024    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1025        case OP_TYPESTAR: \
1026        case OP_TYPEPLUS:
1027    
1028    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1029        case OP_TYPEUPTO: \
1030        case OP_TYPEMINUPTO:
1031    
1032    static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1033  {  {
1034  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1035  pcre_uchar *alternative;  pcre_uchar *alternative;
1036  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1037    int private_data_ptr = *private_data_start;
1038  int space, size, bracketlen;  int space, size, bracketlen;
1039    
1040  while (cc < ccend)  while (cc < ccend)
# Line 922  while (cc < ccend) Line 1042  while (cc < ccend)
1042    space = 0;    space = 0;
1043    size = 0;    size = 0;
1044    bracketlen = 0;    bracketlen = 0;
1045      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1046        return;
1047    
1048      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1049        if (detect_repeat(common, cc))
1050          {
1051          /* These brackets are converted to repeats, so no global
1052          based single character repeat is allowed. */
1053          if (cc >= end)
1054            end = bracketend(cc);
1055          }
1056    
1057    switch(*cc)    switch(*cc)
1058      {      {
1059        case OP_KET:
1060        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1061          {
1062          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1063          private_data_ptr += sizeof(sljit_sw);
1064          cc += common->private_data_ptrs[cc + 1 - common->start];
1065          }
1066        cc += 1 + LINK_SIZE;
1067        break;
1068    
1069      case OP_ASSERT:      case OP_ASSERT:
1070      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1071      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 934  while (cc < ccend) Line 1076  while (cc < ccend)
1076      case OP_SBRA:      case OP_SBRA:
1077      case OP_SBRAPOS:      case OP_SBRAPOS:
1078      case OP_SCOND:      case OP_SCOND:
1079      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1080      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1081      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1082      break;      break;
1083    
1084      case OP_CBRAPOS:      case OP_CBRAPOS:
1085      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1086      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1087      localptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1088      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1089      break;      break;
1090    
# Line 951  while (cc < ccend) Line 1093  while (cc < ccend)
1093      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1094      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1095        {        {
1096        common->localptrs[cc - common->start] = localptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1097        localptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1098        }        }
1099      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1100      break;      break;
# Line 966  while (cc < ccend) Line 1108  while (cc < ccend)
1108      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1109      break;      break;
1110    
1111      CASE_ITERATOR_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
1112      space = 1;      space = 1;
1113      size = -2;      size = -2;
1114      break;      break;
1115    
1116      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
1117      space = 2;      space = 2;
1118      size = -2;      size = -2;
1119      break;      break;
1120    
1121      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
1122      space = 2;      space = 2;
1123      size = -(2 + IMM2_SIZE);      size = -(2 + IMM2_SIZE);
1124      break;      break;
1125    
1126      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1127      space = 1;      space = 1;
1128      size = 1;      size = 1;
1129      break;      break;
1130    
1131      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1132      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
1133        space = 2;        space = 2;
1134      size = 1;      size = 1;
1135      break;      break;
1136    
1137      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1138      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
1139        space = 2;        space = 2;
1140      size = 1 + IMM2_SIZE;      size = 1 + IMM2_SIZE;
# Line 1017  while (cc < ccend) Line 1159  while (cc < ccend)
1159      break;      break;
1160      }      }
1161    
1162      /* Character iterators, which are not inside a repeated bracket,
1163         gets a private slot instead of allocating it on the stack. */
1164    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1165      {      {
1166      common->localptrs[cc - common->start] = localptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1167      localptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1168      }      }
1169    
1170    if (size != 0)    if (size != 0)
# Line 1047  while (cc < ccend) Line 1191  while (cc < ccend)
1191      cc += bracketlen;      cc += bracketlen;
1192      }      }
1193    }    }
1194    *private_data_start = private_data_ptr;
1195  }  }
1196    
1197  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1198  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL* needs_control_head)
1199  {  {
 pcre_uchar *ccend = bracketend(cc);  
1200  int length = 0;  int length = 0;
1201  BOOL possessive = FALSE;  int possessive = 0;
1202    BOOL stack_restore = FALSE;
1203  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1204  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1205    /* The last capture is a local variable even for recursions. */
1206    BOOL capture_last_found = FALSE;
1207    
1208  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1209    SLJIT_ASSERT(common->control_head_ptr != 0);
1210    *needs_control_head = TRUE;
1211    #else
1212    *needs_control_head = FALSE;
1213    #endif
1214    
1215    if (ccend == NULL)
1216    {    {
1217    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1218    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1219        {
1220        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1221        /* This is correct regardless of common->capture_last_ptr. */
1222        capture_last_found = TRUE;
1223        }
1224      cc = next_opcode(common, cc);
1225    }    }
1226    
 cc = next_opcode(common, cc);  
1227  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1228  while (cc < ccend)  while (cc < ccend)
1229    switch(*cc)    switch(*cc)
1230      {      {
1231      case OP_SET_SOM:      case OP_SET_SOM:
1232      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1233        stack_restore = TRUE;
1234      if (!setsom_found)      if (!setsom_found)
1235        {        {
1236        length += 2;        length += 2;
# Line 1080  while (cc < ccend) Line 1240  while (cc < ccend)
1240      break;      break;
1241    
1242      case OP_MARK:      case OP_MARK:
1243        case OP_PRUNE_ARG:
1244        case OP_THEN_ARG:
1245      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1246        stack_restore = TRUE;
1247      if (!setmark_found)      if (!setmark_found)
1248        {        {
1249        length += 2;        length += 2;
1250        setmark_found = TRUE;        setmark_found = TRUE;
1251        }        }
1252        if (common->control_head_ptr != 0)
1253          *needs_control_head = TRUE;
1254      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1255      break;      break;
1256    
1257      case OP_RECURSE:      case OP_RECURSE:
1258        stack_restore = TRUE;
1259      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1260        {        {
1261        length += 2;        length += 2;
# Line 1100  while (cc < ccend) Line 1266  while (cc < ccend)
1266        length += 2;        length += 2;
1267        setmark_found = TRUE;        setmark_found = TRUE;
1268        }        }
1269        if (common->capture_last_ptr != 0 && !capture_last_found)
1270          {
1271          length += 2;
1272          capture_last_found = TRUE;
1273          }
1274      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1275      break;      break;
1276    
# Line 1107  while (cc < ccend) Line 1278  while (cc < ccend)
1278      case OP_CBRAPOS:      case OP_CBRAPOS:
1279      case OP_SCBRA:      case OP_SCBRA:
1280      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1281        stack_restore = TRUE;
1282        if (common->capture_last_ptr != 0 && !capture_last_found)
1283          {
1284          length += 2;
1285          capture_last_found = TRUE;
1286          }
1287      length += 3;      length += 3;
1288      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1289      break;      break;
1290    
1291      default:      default:
1292        stack_restore = TRUE;
1293        /* Fall through. */
1294    
1295        case OP_NOT_WORD_BOUNDARY:
1296        case OP_WORD_BOUNDARY:
1297        case OP_NOT_DIGIT:
1298        case OP_DIGIT:
1299        case OP_NOT_WHITESPACE:
1300        case OP_WHITESPACE:
1301        case OP_NOT_WORDCHAR:
1302        case OP_WORDCHAR:
1303        case OP_ANY:
1304        case OP_ALLANY:
1305        case OP_ANYBYTE:
1306        case OP_NOTPROP:
1307        case OP_PROP:
1308        case OP_ANYNL:
1309        case OP_NOT_HSPACE:
1310        case OP_HSPACE:
1311        case OP_NOT_VSPACE:
1312        case OP_VSPACE:
1313        case OP_EXTUNI:
1314        case OP_EODN:
1315        case OP_EOD:
1316        case OP_CIRC:
1317        case OP_CIRCM:
1318        case OP_DOLL:
1319        case OP_DOLLM:
1320        case OP_CHAR:
1321        case OP_CHARI:
1322        case OP_NOT:
1323        case OP_NOTI:
1324    
1325        case OP_EXACT:
1326        case OP_POSSTAR:
1327        case OP_POSPLUS:
1328        case OP_POSQUERY:
1329        case OP_POSUPTO:
1330    
1331        case OP_EXACTI:
1332        case OP_POSSTARI:
1333        case OP_POSPLUSI:
1334        case OP_POSQUERYI:
1335        case OP_POSUPTOI:
1336    
1337        case OP_NOTEXACT:
1338        case OP_NOTPOSSTAR:
1339        case OP_NOTPOSPLUS:
1340        case OP_NOTPOSQUERY:
1341        case OP_NOTPOSUPTO:
1342    
1343        case OP_NOTEXACTI:
1344        case OP_NOTPOSSTARI:
1345        case OP_NOTPOSPLUSI:
1346        case OP_NOTPOSQUERYI:
1347        case OP_NOTPOSUPTOI:
1348    
1349        case OP_TYPEEXACT:
1350        case OP_TYPEPOSSTAR:
1351        case OP_TYPEPOSPLUS:
1352        case OP_TYPEPOSQUERY:
1353        case OP_TYPEPOSUPTO:
1354    
1355        case OP_CLASS:
1356        case OP_NCLASS:
1357        case OP_XCLASS:
1358    
1359      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1360      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1361      break;      break;
1362      }      }
1363    
1364  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1365  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1366    return -1;    return stack_restore ? no_frame : no_stack;
1367    
1368  if (length > 0)  if (length > 0)
1369    return length + 1;    return length + 1;
1370  return -1;  return stack_restore ? no_frame : no_stack;
1371  }  }
1372    
1373  static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive)  static void init_frame(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, int stackpos, int stacktop, BOOL recursive)
1374  {  {
1375  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1376  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1377  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1378    /* The last capture is a local variable even for recursions. */
1379    BOOL capture_last_found = FALSE;
1380  int offset;  int offset;
1381    
1382  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1139  SLJIT_UNUSED_ARG(stacktop); Line 1384  SLJIT_UNUSED_ARG(stacktop);
1384  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1385    
1386  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1387  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1388    cc = next_opcode(common, cc);    {
1389      ccend = bracketend(cc) - (1 + LINK_SIZE);
1390      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1391        cc = next_opcode(common, cc);
1392      }
1393    
1394  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1395  while (cc < ccend)  while (cc < ccend)
1396    switch(*cc)    switch(*cc)
# Line 1150  while (cc < ccend) Line 1400  while (cc < ccend)
1400      if (!setsom_found)      if (!setsom_found)
1401        {        {
1402        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1403        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1404        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1405        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1406        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1407        setsom_found = TRUE;        setsom_found = TRUE;
1408        }        }
1409      cc += 1;      cc += 1;
1410      break;      break;
1411    
1412      case OP_MARK:      case OP_MARK:
1413        case OP_PRUNE_ARG:
1414        case OP_THEN_ARG:
1415      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1416      if (!setmark_found)      if (!setmark_found)
1417        {        {
1418        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1419        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setmark);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1420        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1421        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1422        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1423        setmark_found = TRUE;        setmark_found = TRUE;
1424        }        }
1425      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 1177  while (cc < ccend) Line 1429  while (cc < ccend)
1429      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1430        {        {
1431        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1432        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1433        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1434        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1435        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1436        setsom_found = TRUE;        setsom_found = TRUE;
1437        }        }
1438      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1439        {        {
1440        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1441        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setmark);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1442        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1443        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1444        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1445        setmark_found = TRUE;        setmark_found = TRUE;
1446        }        }
1447        if (common->capture_last_ptr != 0 && !capture_last_found)
1448          {
1449          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1450          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1451          stackpos += (int)sizeof(sljit_sw);
1452          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1453          stackpos += (int)sizeof(sljit_sw);
1454          capture_last_found = TRUE;
1455          }
1456      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1457      break;      break;
1458    
# Line 1199  while (cc < ccend) Line 1460  while (cc < ccend)
1460      case OP_CBRAPOS:      case OP_CBRAPOS:
1461      case OP_SCBRA:      case OP_SCBRA:
1462      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1463        if (common->capture_last_ptr != 0 && !capture_last_found)
1464          {
1465          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1466          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1467          stackpos += (int)sizeof(sljit_sw);
1468          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1469          stackpos += (int)sizeof(sljit_sw);
1470          capture_last_found = TRUE;
1471          }
1472      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1473      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1474      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1475      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1476      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
1477      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1478      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1479      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1480      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1481    
1482      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1483      break;      break;
# Line 1218  while (cc < ccend) Line 1488  while (cc < ccend)
1488      break;      break;
1489      }      }
1490    
1491  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1492  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1493  }  }
1494    
1495  static SLJIT_INLINE int get_localsize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static SLJIT_INLINE int get_private_data_copy_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL needs_control_head)
1496  {  {
1497  int localsize = 2;  int private_data_length = needs_control_head ? 3 : 2;
1498  int size;  int size;
1499  pcre_uchar *alternative;  pcre_uchar *alternative;
1500  /* Calculate the sum of the local variables. */  /* Calculate the sum of the private machine words. */
1501  while (cc < ccend)  while (cc < ccend)
1502    {    {
1503    size = 0;    size = 0;
1504    switch(*cc)    switch(*cc)
1505      {      {
1506        case OP_KET:
1507        if (PRIVATE_DATA(cc) != 0)
1508          private_data_length++;
1509        cc += 1 + LINK_SIZE;
1510        break;
1511    
1512      case OP_ASSERT:      case OP_ASSERT:
1513      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1514      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1243  while (cc < ccend) Line 1519  while (cc < ccend)
1519      case OP_SBRA:      case OP_SBRA:
1520      case OP_SBRAPOS:      case OP_SBRAPOS:
1521      case OP_SCOND:      case OP_SCOND:
1522      localsize++;      private_data_length++;
1523      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1524      break;      break;
1525    
1526      case OP_CBRA:      case OP_CBRA:
1527      case OP_SCBRA:      case OP_SCBRA:
1528      localsize++;      if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1529          private_data_length++;
1530      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1531      break;      break;
1532    
1533      case OP_CBRAPOS:      case OP_CBRAPOS:
1534      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1535      localsize += 2;      private_data_length += 2;
1536      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1537      break;      break;
1538    
# Line 1263  while (cc < ccend) Line 1540  while (cc < ccend)
1540      /* Might be a hidden SCOND. */      /* Might be a hidden SCOND. */
1541      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
1542      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1543        localsize++;        private_data_length++;
1544      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1545      break;      break;
1546    
1547      CASE_ITERATOR_LOCAL1      CASE_ITERATOR_PRIVATE_DATA_1
1548      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1549        localsize++;        private_data_length++;
1550      cc += 2;      cc += 2;
1551  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1552      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1553  #endif  #endif
1554      break;      break;
1555    
1556      CASE_ITERATOR_LOCAL2A      CASE_ITERATOR_PRIVATE_DATA_2A
1557      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1558        localsize += 2;        private_data_length += 2;
1559      cc += 2;      cc += 2;
1560  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1561      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1562  #endif  #endif
1563      break;      break;
1564    
1565      CASE_ITERATOR_LOCAL2B      CASE_ITERATOR_PRIVATE_DATA_2B
1566      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1567        localsize += 2;        private_data_length += 2;
1568      cc += 2 + IMM2_SIZE;      cc += 2 + IMM2_SIZE;
1569  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1570      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1571  #endif  #endif
1572      break;      break;
1573    
1574      CASE_ITERATOR_TYPE_LOCAL1      CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1575      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1576        localsize++;        private_data_length++;
1577      cc += 1;      cc += 1;
1578      break;      break;
1579    
1580      CASE_ITERATOR_TYPE_LOCAL2A      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1581      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1582        localsize += 2;        private_data_length += 2;
1583      cc += 1;      cc += 1;
1584      break;      break;
1585    
1586      CASE_ITERATOR_TYPE_LOCAL2B      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1587      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1588        localsize += 2;        private_data_length += 2;
1589      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
1590      break;      break;
1591    
# Line 1320  while (cc < ccend) Line 1597  while (cc < ccend)
1597  #else  #else
1598      size = 1 + 32 / (int)sizeof(pcre_uchar);      size = 1 + 32 / (int)sizeof(pcre_uchar);
1599  #endif  #endif
1600      if (PRIV_DATA(cc))      if (PRIVATE_DATA(cc))
1601        localsize += get_class_iterator_size(cc + size);        private_data_length += get_class_iterator_size(cc + size);
1602      cc += size;      cc += size;
1603      break;      break;
1604    
# Line 1332  while (cc < ccend) Line 1609  while (cc < ccend)
1609      }      }
1610    }    }
1611  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
1612  return localsize;  return private_data_length;
1613  }  }
1614    
1615  static void copy_locals(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,
1616    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1617  {  {
1618  DEFINE_COMPILER;  DEFINE_COMPILER;
1619  int srcw[2];  int srcw[2];
# Line 1357  stacktop = STACK(stacktop - 1); Line 1634  stacktop = STACK(stacktop - 1);
1634    
1635  if (!save)  if (!save)
1636    {    {
1637    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1638    if (stackptr < stacktop)    if (stackptr < stacktop)
1639      {      {
1640      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1641      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1642      tmp1empty = FALSE;      tmp1empty = FALSE;
1643      }      }
1644    if (stackptr < stacktop)    if (stackptr < stacktop)
1645      {      {
1646      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1647      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1648      tmp2empty = FALSE;      tmp2empty = FALSE;
1649      }      }
1650    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1651    }    }
1652    
1653  while (status != end)  do
1654    {    {
1655    count = 0;    count = 0;
1656    switch(status)    switch(status)
1657      {      {
1658      case start:      case start:
1659      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1660      count = 1;      count = 1;
1661      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1662        if (needs_control_head)
1663          {
1664          SLJIT_ASSERT(common->control_head_ptr != 0);
1665          count = 2;
1666          srcw[1] = common->control_head_ptr;
1667          }
1668      status = loop;      status = loop;
1669      break;      break;
1670    
# Line 1394  while (status != end) Line 1677  while (status != end)
1677    
1678      switch(*cc)      switch(*cc)
1679        {        {
1680          case OP_KET:
1681          if (PRIVATE_DATA(cc) != 0)
1682            {
1683            count = 1;
1684            srcw[0] = PRIVATE_DATA(cc);
1685            }
1686          cc += 1 + LINK_SIZE;
1687          break;
1688    
1689        case OP_ASSERT:        case OP_ASSERT:
1690        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1691        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1405  while (status != end) Line 1697  while (status != end)
1697        case OP_SBRAPOS:        case OP_SBRAPOS:
1698        case OP_SCOND:        case OP_SCOND:
1699        count = 1;        count = 1;
1700        srcw[0] = PRIV_DATA(cc);        srcw[0] = PRIVATE_DATA(cc);
1701        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1702        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1703        break;        break;
1704    
1705        case OP_CBRA:        case OP_CBRA:
1706        case OP_SCBRA:        case OP_SCBRA:
1707        count = 1;        if (common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] == 0)
1708        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));          {
1709            count = 1;
1710            srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1711            }
1712        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1713        break;        break;
1714    
1715        case OP_CBRAPOS:        case OP_CBRAPOS:
1716        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1717        count = 2;        count = 2;
1718        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[0] = PRIVATE_DATA(cc);
1719        srcw[1] = PRIV_DATA(cc);        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1720        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0 && srcw[1] != 0);
1721        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1722        break;        break;
1723    
# Line 1432  while (status != end) Line 1727  while (status != end)
1727        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1728          {          {
1729          count = 1;          count = 1;
1730          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1731          SLJIT_ASSERT(srcw[0] != 0);          SLJIT_ASSERT(srcw[0] != 0);
1732          }          }
1733        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1734        break;        break;
1735    
1736        CASE_ITERATOR_LOCAL1        CASE_ITERATOR_PRIVATE_DATA_1
1737        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1738          {          {
1739          count = 1;          count = 1;
1740          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1741          }          }
1742        cc += 2;        cc += 2;
1743  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1450  while (status != end) Line 1745  while (status != end)
1745  #endif  #endif
1746        break;        break;
1747    
1748        CASE_ITERATOR_LOCAL2A        CASE_ITERATOR_PRIVATE_DATA_2A
1749        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1750          {          {
1751          count = 2;          count = 2;
1752          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1753          srcw[1] = PRIV_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1754          }          }
1755        cc += 2;        cc += 2;
1756  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1463  while (status != end) Line 1758  while (status != end)
1758  #endif  #endif
1759        break;        break;
1760    
1761        CASE_ITERATOR_LOCAL2B        CASE_ITERATOR_PRIVATE_DATA_2B
1762        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1763          {          {
1764          count = 2;          count = 2;
1765          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1766          srcw[1] = PRIV_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1767          }          }
1768        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1769  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1476  while (status != end) Line 1771  while (status != end)
1771  #endif  #endif
1772        break;        break;
1773    
1774        CASE_ITERATOR_TYPE_LOCAL1        CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1775        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1776          {          {
1777          count = 1;          count = 1;
1778          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1779          }          }
1780        cc += 1;        cc += 1;
1781        break;        break;
1782    
1783        CASE_ITERATOR_TYPE_LOCAL2A        CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1784        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1785          {          {
1786          count = 2;          count = 2;
1787          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1788          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1789          }          }
1790        cc += 1;        cc += 1;
1791        break;        break;
1792    
1793        CASE_ITERATOR_TYPE_LOCAL2B        CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1794        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1795          {          {
1796          count = 2;          count = 2;
1797          srcw[0] = PRIV_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1798          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1799          }          }
1800        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1801        break;        break;
# Line 1513  while (status != end) Line 1808  while (status != end)
1808  #else  #else
1809        size = 1 + 32 / (int)sizeof(pcre_uchar);        size = 1 + 32 / (int)sizeof(pcre_uchar);
1810  #endif  #endif
1811        if (PRIV_DATA(cc))        if (PRIVATE_DATA(cc))
1812          switch(get_class_iterator_size(cc + size))          switch(get_class_iterator_size(cc + size))
1813            {            {
1814            case 1:            case 1:
1815            count = 1;            count = 1;
1816            srcw[0] = PRIV_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1817            break;            break;
1818    
1819            case 2:            case 2:
1820            count = 2;            count = 2;
1821            srcw[0] = PRIV_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1822            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1823            break;            break;
1824    
1825            default:            default:
# Line 1556  while (status != end) Line 1851  while (status != end)
1851          if (!tmp1empty)          if (!tmp1empty)
1852            {            {
1853            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1854            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1855            }            }
1856          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1857          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1567  while (status != end) Line 1862  while (status != end)
1862          if (!tmp2empty)          if (!tmp2empty)
1863            {            {
1864            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1865            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1866            }            }
1867          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1868          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1584  while (status != end) Line 1879  while (status != end)
1879          if (!tmp1empty)          if (!tmp1empty)
1880            {            {
1881            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1882            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1883            }            }
1884          tmp1next = FALSE;          tmp1next = FALSE;
1885          }          }
# Line 1596  while (status != end) Line 1891  while (status != end)
1891          if (!tmp2empty)          if (!tmp2empty)
1892            {            {
1893            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1894            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1895            }            }
1896          tmp1next = TRUE;          tmp1next = TRUE;
1897          }          }
1898        }        }
1899      }      }
1900    }    }
1901    while (status != end);
1902    
1903  if (save)  if (save)
1904    {    {
# Line 1611  if (save) Line 1907  if (save)
1907      if (!tmp1empty)      if (!tmp1empty)
1908        {        {
1909        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1910        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1911        }        }
1912      if (!tmp2empty)      if (!tmp2empty)
1913        {        {
1914        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1915        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1916        }        }
1917      }      }
1918    else    else
# Line 1624  if (save) Line 1920  if (save)
1920      if (!tmp2empty)      if (!tmp2empty)
1921        {        {
1922        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1923        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1924        }        }
1925      if (!tmp1empty)      if (!tmp1empty)
1926        {        {
1927        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1928        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1929        }        }
1930      }      }
1931    }    }
1932  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1933  }  }
1934    
1935  #undef CASE_ITERATOR_LOCAL1  static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1936  #undef CASE_ITERATOR_LOCAL2A  {
1937  #undef CASE_ITERATOR_LOCAL2B  pcre_uchar *end = bracketend(cc);
1938  #undef CASE_ITERATOR_TYPE_LOCAL1  BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1939  #undef CASE_ITERATOR_TYPE_LOCAL2A  
1940  #undef CASE_ITERATOR_TYPE_LOCAL2B  /* Assert captures then. */
1941    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1942      current_offset = NULL;
1943    /* Conditional block does not. */
1944    if (*cc == OP_COND || *cc == OP_SCOND)
1945      has_alternatives = FALSE;
1946    
1947    cc = next_opcode(common, cc);
1948    if (has_alternatives)
1949      current_offset = common->then_offsets + (cc - common->start);
1950    
1951    while (cc < end)
1952      {
1953      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1954        cc = set_then_offsets(common, cc, current_offset);
1955      else
1956        {
1957        if (*cc == OP_ALT && has_alternatives)
1958          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1959        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1960          *current_offset = 1;
1961        cc = next_opcode(common, cc);
1962        }
1963      }
1964    
1965    return end;
1966    }
1967    
1968    #undef CASE_ITERATOR_PRIVATE_DATA_1
1969    #undef CASE_ITERATOR_PRIVATE_DATA_2A
1970    #undef CASE_ITERATOR_PRIVATE_DATA_2B
1971    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_1
1972    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
1973    #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
1974    
1975  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
1976  {  {
1977  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
1978  }  }
# Line 1654  while (list) Line 1983  while (list)
1983    {    {
1984    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1985    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
1986    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1987    list = list->next;    list = list->next;
1988    }    }
1989  }  }
# Line 1670  if (list_item) Line 1999  if (list_item)
1999    }    }
2000  }  }
2001    
2002  static void add_stub(compiler_common *common, enum stub_types type, int data, struct sljit_jump *start)  static void add_stub(compiler_common *common, struct sljit_jump *start)
2003  {  {
2004  DEFINE_COMPILER;  DEFINE_COMPILER;
2005  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
2006    
2007  if (list_item)  if (list_item)
2008    {    {
   list_item->type = type;  
   list_item->data = data;  
2009    list_item->start = start;    list_item->start = start;
2010    list_item->quit = LABEL();    list_item->quit = LABEL();
2011    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1694  stub_list* list_item = common->stubs; Line 2021  stub_list* list_item = common->stubs;
2021  while (list_item)  while (list_item)
2022    {    {
2023    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2024    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
     {  
     case stack_alloc:  
     add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));  
     break;  
     }  
2025    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2026    list_item = list_item->next;    list_item = list_item->next;
2027    }    }
2028  common->stubs = NULL;  common->stubs = NULL;
2029  }  }
2030    
2031  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2032  {  {
2033  DEFINE_COMPILER;  DEFINE_COMPILER;
2034    
2035  OP2(SLJIT_SUB | SLJIT_SET_E, CALL_COUNT, 0, CALL_COUNT, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, COUNT_MATCH, 0, COUNT_MATCH, 0, SLJIT_IMM, 1);
2036  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2037  }  }
2038    
# Line 1719  static SLJIT_INLINE void allocate_stack( Line 2041  static SLJIT_INLINE void allocate_stack(
2041  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2042  DEFINE_COMPILER;  DEFINE_COMPILER;
2043    
2044  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w));  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
2045  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2046  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2047  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1727  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 2049  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2049  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2050  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2051  #endif  #endif
2052  add_stub(common, stack_alloc, 0, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));  add_stub(common, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));
2053  }  }
2054    
2055  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2056  {  {
2057  DEFINE_COMPILER;  DEFINE_COMPILER;
2058  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w));  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
2059  }  }
2060    
2061  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1741  static SLJIT_INLINE void reset_ovector(c Line 2063  static SLJIT_INLINE void reset_ovector(c
2063  DEFINE_COMPILER;  DEFINE_COMPILER;
2064  struct sljit_label *loop;  struct sljit_label *loop;
2065  int i;  int i;
2066    
2067  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2068    SLJIT_ASSERT(length > 1);
2069  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2070  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
2071    if (length < 8)
2072      {
2073      for (i = 1; i < length; i++)
2074        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2075      }
2076    else
2077      {
2078      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2079      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2080      loop = LABEL();
2081      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2082      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2083      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2084      }
2085    }
2086    
2087    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2088    {
2089    DEFINE_COMPILER;
2090    struct sljit_label *loop;
2091    int i;
2092    
2093    SLJIT_ASSERT(length > 1);
2094    /* OVECTOR(1) contains the "string begin - 1" constant. */
2095    if (length > 2)
2096      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2097  if (length < 8)  if (length < 8)
2098    {    {
2099    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
2100      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_TEMPORARY_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
2101    }    }
2102  else  else
2103    {    {
2104    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2105    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2106    loop = LABEL();    loop = LABEL();
2107    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2108    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
2109    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2110    }    }
2111    
2112    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2113    if (common->mark_ptr != 0)
2114      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2115    if (common->control_head_ptr != 0)
2116      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2117    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2118    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2119    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2120    }
2121    
2122    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2123    {
2124    while (current != NULL)
2125      {
2126      switch (current[-2])
2127        {
2128        case type_then_trap:
2129        break;
2130    
2131        case type_mark:
2132        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2133          return current[-4];
2134        break;
2135    
2136        default:
2137        SLJIT_ASSERT_STOP();
2138        break;
2139        }
2140      current = (sljit_sw*)current[-1];
2141      }
2142    return -1;
2143  }  }
2144    
2145  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2146  {  {
2147  DEFINE_COMPILER;  DEFINE_COMPILER;
2148  struct sljit_label *loop;  struct sljit_label *loop;
2149  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2150    
2151  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2152  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2153  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);
2154    
2155  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2156  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2157    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
2158  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offset_count));
2159  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2160    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_TEMPORARY_REG3, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);
2161  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
2162  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));
2163  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2164  /* Unlikely, but possible */  /* Unlikely, but possible */
2165  earlyexit = CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0);  early_quit = CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);
2166  loop = LABEL();  loop = LABEL();
2167  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
2168  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_w));  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));
2169  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2170  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2171  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2172  #endif  #endif
2173  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);
2174  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
2175  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2176  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2177    
2178  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2179  if (topbracket > 1)  if (topbracket > 1)
2180    {    {
2181    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));
2182    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2183    
2184    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2185    loop = LABEL();    loop = LABEL();
2186    OP1(SLJIT_MOVU, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), -(2 * (sljit_w)sizeof(sljit_w)));    OP1(SLJIT_MOVU, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), -(2 * (sljit_sw)sizeof(sljit_sw)));
2187    OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
2188    CMPTO(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG3, 0, loop);    CMPTO(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG3, 0, loop);
2189    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2190    }    }
2191  else  else
2192    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1813  else Line 2195  else
2195  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)
2196  {  {
2197  DEFINE_COMPILER;  DEFINE_COMPILER;
2198    struct sljit_jump *jump;
2199    
2200  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);
2201  SLJIT_ASSERT(common->start_used_ptr != 0 && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));  SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0
2202      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2203    
2204  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2205  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2206  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, offsetcount));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, real_offset_count));
2207  CMPTO(SLJIT_C_LESS, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2, quit);  CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
2208    
2209  /* Store match begin and end. */  /* Store match begin and end. */
2210  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));
2211  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));
2212  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);  
2213    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2214    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + (int)sizeof(sljit_sw)), SLJIT_SAVED_REG1, 0);
2215    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2216    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2217    #endif
2218    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2219    JUMPHERE(jump);
2220    
2221    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);
2222  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);
2223  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2224  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2225  #endif  #endif
2226  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);
2227    
2228  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG1, 0);
2229  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2230  OP2(SLJIT_ASHR, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);  OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2231  #endif  #endif
2232  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), 0, SLJIT_TEMPORARY_REG3, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0, SLJIT_SCRATCH_REG3, 0);
2233    
2234  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2235  }  }
# Line 1949  if (c <= 127 && bit == 0x20) Line 2342  if (c <= 127 && bit == 0x20)
2342    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2343    
2344  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2345  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2346    return 0;    return 0;
2347    
2348  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2349    
2350  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2351  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 1968  if (common->utf && c > 127) Line 2361  if (common->utf && c > 127)
2361  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2362  return (0 << 8) | bit;  return (0 << 8) | bit;
2363    
2364  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2365    
 #ifdef COMPILE_PCRE16  
2366  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2367  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2368    {    {
# Line 1981  if (common->utf && c > 65535) Line 2373  if (common->utf && c > 65535)
2373    }    }
2374  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2375  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2376    
2377  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2378  }  }
2379    
2380  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2381  {  {
2382  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2383  DEFINE_COMPILER;  DEFINE_COMPILER;
2384  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2385    
# Line 2003  else if (common->mode == JIT_PARTIAL_SOF Line 2394  else if (common->mode == JIT_PARTIAL_SOF
2394    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2395    
2396  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2397    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2398  else  else
2399    {    {
2400    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2016  if (jump != NULL) Line 2407  if (jump != NULL)
2407    JUMPHERE(jump);    JUMPHERE(jump);
2408  }  }
2409    
2410  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2411  {  {
2412  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2413  DEFINE_COMPILER;  DEFINE_COMPILER;
2414  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2415    
2416  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2417    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2418      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2419      return;
2420      }
2421    
2422  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2423  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2424    {    {
2425    nohit = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2426    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2427    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2428    }    }
2429  else  else
2430    {    {
2431    return_value = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2432    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2433      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2434    else    else
2435      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2436    }    }
2437  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2438  }  }
2439    
2440  static void detect_partial_match(compiler_common *common, jump_list **backtracks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
# Line 2063  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR Line 2453  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2453  add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));  add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2454  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2455    {    {
2456    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2457    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2458    }    }
2459  else  else
# Line 2076  else Line 2466  else
2466  JUMPHERE(jump);  JUMPHERE(jump);
2467  }  }
2468    
2469  static void read_char(compiler_common *common)  static void peek_char(compiler_common *common, pcre_uint32 max)
2470  {  {
2471  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2472  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2473  DEFINE_COMPILER;  DEFINE_COMPILER;
2474  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2475  struct sljit_jump *jump;  struct sljit_jump *jump;
2476  #endif  #endif
2477    
2478    SLJIT_UNUSED_ARG(max);
2479    
2480  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2481  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2482  if (common->utf)  if (common->utf)
2483    {    {
2484  #ifdef COMPILE_PCRE8    if (max < 128) return;
2485    
2486    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2487  #else    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 #ifdef COMPILE_PCRE16  
   jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);  
 #endif  
 #endif /* COMPILE_PCRE8 */  
2488    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2489      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2490      JUMPHERE(jump);
2491      }
2492    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2493    
2494    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2495    if (common->utf)
2496      {
2497      if (max < 0xd800) return;
2498    
2499      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2500      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2501      /* TMP2 contains the high surrogate. */
2502      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2503      OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2504      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2505      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2506      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2507      JUMPHERE(jump);
2508      }
2509    #endif
2510    }
2511    
2512    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2513    
2514    static BOOL is_char7_bitset(const pcre_uint8* bitset, BOOL nclass)
2515    {
2516    /* Tells whether the character codes below 128 are enough
2517    to determine a match. */
2518    const pcre_uint8 value = nclass ? 0xff : 0;
2519    const pcre_uint8* end = bitset + 32;
2520    
2521    bitset += 16;
2522    do
2523      {
2524      if (*bitset++ != value)
2525        return FALSE;
2526      }
2527    while (bitset < end);
2528    return TRUE;
2529    }
2530    
2531    static void read_char7_type(compiler_common *common, BOOL full_read)
2532    {
2533    /* Reads the precise character type of a character into TMP1, if the character
2534    is less than 128. Otherwise it returns with zero. Does not check STR_END. The
2535    full_read argument tells whether characters above max are accepted or not. */
2536    DEFINE_COMPILER;
2537    struct sljit_jump *jump;
2538    
2539    SLJIT_ASSERT(common->utf);
2540    
2541    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2542    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2543    
2544    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2545    
2546    if (full_read)
2547      {
2548      jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2549      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2550      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2551    JUMPHERE(jump);    JUMPHERE(jump);
2552    }    }
 #endif  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
2553  }  }
2554    
2555  static void peek_char(compiler_common *common)  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2556    
2557    static void read_char_range(compiler_common *common, pcre_uint32 min, pcre_uint32 max, BOOL update_str_ptr)
2558  {  {
2559  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the precise value of a character into TMP1, if the character is
2560  Does not check STR_END. TMP2 Destroyed. */  between min and max (c >= min && c <= max). Otherwise it returns with a value
2561    outside the range. Does not check STR_END. */
2562  DEFINE_COMPILER;  DEFINE_COMPILER;
2563  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2564  struct sljit_jump *jump;  struct sljit_jump *jump;
2565  #endif  #endif
2566    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2567    struct sljit_jump *jump2;
2568    #endif
2569    
2570  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  SLJIT_UNUSED_ARG(update_str_ptr);
2571  #ifdef SUPPORT_UTF  SLJIT_UNUSED_ARG(min);
2572    SLJIT_UNUSED_ARG(max);
2573    SLJIT_ASSERT(min <= max);
2574    
2575    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2576    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2577    
2578    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2579  if (common->utf)  if (common->utf)
2580    {    {
2581  #ifdef COMPILE_PCRE8    if (max < 128 && !update_str_ptr) return;
2582    
2583    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2584  #else    if (min >= 0x10000)
2585  #ifdef COMPILE_PCRE16      {
2586    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xf0);
2587        if (update_str_ptr)
2588          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2589        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2590        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x7);
2591        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2592        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2593        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2594        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2595        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2596        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2597        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2598        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2599        if (!update_str_ptr)
2600          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2601        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2602        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2603        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2604        JUMPHERE(jump2);
2605        if (update_str_ptr)
2606          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2607        }
2608      else if (min >= 0x800 && max <= 0xffff)
2609        {
2610        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xe0);
2611        if (update_str_ptr)
2612          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2613        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2614        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xf);
2615        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2616        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2617        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2618        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2619        if (!update_str_ptr)
2620          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2621        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2622        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2623        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2624        JUMPHERE(jump2);
2625        if (update_str_ptr)
2626          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2627        }
2628      else if (max >= 0x800)
2629        add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2630      else if (max < 128)
2631        {
2632        OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2633        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2634        }
2635      else
2636        {
2637        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2638        if (!update_str_ptr)
2639          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2640        else
2641          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2642        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2643        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2644        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2645        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2646        if (update_str_ptr)
2647          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2648        }
2649      JUMPHERE(jump);
2650      }
2651  #endif  #endif
2652  #endif /* COMPILE_PCRE8 */  
2653    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));  #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2654    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  if (common->utf)
2655      {
2656      if (max >= 0x10000)
2657        {
2658        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2659        jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2660        /* TMP2 contains the high surrogate. */
2661        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2662        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2663        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2664        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2665        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2666        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2667        JUMPHERE(jump);
2668        return;
2669        }
2670    
2671      if (max < 0xd800 && !update_str_ptr) return;
2672    
2673      /* Skip low surrogate if necessary. */
2674      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2675      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2676      if (update_str_ptr)
2677        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2678      if (max >= 0xd800)
2679        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);
2680    JUMPHERE(jump);    JUMPHERE(jump);
2681    }    }
2682  #endif  #endif
2683  }  }
2684    
2685  static void read_char8_type(compiler_common *common)  static SLJIT_INLINE void read_char(compiler_common *common)
2686    {
2687    read_char_range(common, 0, READ_CHAR_MAX, TRUE);
2688    }
2689    
2690    static void read_char8_type(compiler_common *common, BOOL update_str_ptr)
2691  {  {
2692  /* 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. */
2693  DEFINE_COMPILER;  DEFINE_COMPILER;
2694  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2695  struct sljit_jump *jump;  struct sljit_jump *jump;
2696  #endif  #endif
2697    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2698    struct sljit_jump *jump2;
2699    #endif
2700    
2701  #ifdef SUPPORT_UTF  SLJIT_UNUSED_ARG(update_str_ptr);
2702    
2703    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2704    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2705    
2706    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2707  if (common->utf)  if (common->utf)
2708    {    {
   OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 #ifdef COMPILE_PCRE8  
2709    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2710    it is needed in most cases. */    it is needed in most cases. */
2711    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2712    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2713    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    if (!update_str_ptr)
2714    JUMPHERE(jump);      {
2715  #else      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2716  #ifdef COMPILE_PCRE16      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2717    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2718    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2719    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2720        OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
2721        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2722        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2723        OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2724        JUMPHERE(jump2);
2725        }
2726      else
2727        add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2728    JUMPHERE(jump);    JUMPHERE(jump);
   /* Skip low surrogate if necessary. */  
   OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);  
   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);  
   COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  
   OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  
 #endif  
 #endif /* COMPILE_PCRE8 */  
2729    return;    return;
2730    }    }
2731  #endif  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2732  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
2733  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  #if !defined COMPILE_PCRE8
 #ifdef COMPILE_PCRE16  
2734  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2735  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2736  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2737  #endif  #endif
2738  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2739  #ifdef COMPILE_PCRE16  #if !defined COMPILE_PCRE8
2740  JUMPHERE(jump);  JUMPHERE(jump);
2741  #endif  #endif
2742    
2743    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2744    if (common->utf && update_str_ptr)
2745      {
2746      /* Skip low surrogate if necessary. */
2747      OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2748      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2749      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2750      JUMPHERE(jump);
2751      }
2752    #endif /* SUPPORT_UTF && COMPILE_PCRE16 */
2753  }  }
2754    
2755  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
2756  {  {
2757  /* 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. */
2758  DEFINE_COMPILER;  DEFINE_COMPILER;
2759  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2760    #if defined COMPILE_PCRE8
2761  struct sljit_label *label;  struct sljit_label *label;
2762    
2763  if (common->utf)  if (common->utf)
# Line 2196  if (common->utf) Line 2769  if (common->utf)
2769    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2770    return;    return;
2771    }    }
2772  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2773  if (common->utf)  if (common->utf)
2774    {    {
2775    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
# Line 2205  if (common->utf) Line 2777  if (common->utf)
2777    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2778    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2779    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);
2780    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2781    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2782    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2783    return;    return;
2784    }    }
2785  #endif  #endif /* COMPILE_PCRE[8|16] */
2786    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2787  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));
2788  }  }
2789    
2790  static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpiftrue)  static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpifmatch)
2791  {  {
2792  /* 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. */
2793  DEFINE_COMPILER;  DEFINE_COMPILER;
2794    struct sljit_jump *jump;
2795    
2796  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2797    {    {
2798    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2799    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpifmatch ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2800    }    }
2801  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2802    {    {
2803    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    if (jumpifmatch)
2804    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      {
2805    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR));
2806    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2807    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));      }
2808      else
2809        {
2810        jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
2811        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2812        JUMPHERE(jump);
2813        }
2814    }    }
2815  else  else
2816    {    {
2817    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2818    add_jump(compiler, backtracks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));    add_jump(compiler, backtracks, CMP(jumpifmatch ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
2819    }    }
2820  }  }
2821    
2822  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2823    
2824  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2825  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2826  {  {
2827  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2828  of the character (>= 0xc0). Return char value in TMP1, length - 1 in TMP2. */  of the character (>= 0xc0). Return char value in TMP1, length in TMP2. */
2829  DEFINE_COMPILER;  DEFINE_COMPILER;
2830  struct sljit_jump *jump;  struct sljit_jump *jump;
2831    
2832  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2833    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2834    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2835    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2836    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2837    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2838    
2839  /* Searching for the first zero. */  /* Searching for the first zero. */
2840  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2841  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2842  /* Two byte sequence. */  /* Two byte sequence. */
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
2843  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));
2844  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2845    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2846    
2847    JUMPHERE(jump);
2848    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2849    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2850  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2851  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2852  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 JUMPHERE(jump);  
2853    
2854  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2855  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2856  /* Three byte sequence. */  /* Three byte sequence. */
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  
2857  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2858  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));  
2859  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2860    
2861  /* Four byte sequence. */  /* Four byte sequence. */
2862  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  JUMPHERE(jump);
2863  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2864  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2865    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2866    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2867  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  
2868  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2869  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(4));
2870    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2871    }
2872    
2873    static void do_utfreadchar16(compiler_common *common)
2874    {
2875    /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2876    of the character (>= 0xc0). Return value in TMP1. */
2877    DEFINE_COMPILER;
2878    struct sljit_jump *jump;
2879    
2880    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2881    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2882    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2883    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2884  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
2885  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2886  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));  
2887  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));  /* Searching for the first zero. */
2888    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2889    jump = JUMP(SLJIT_C_NOT_ZERO);
2890    /* Two byte sequence. */
2891    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2892    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2893    
2894    JUMPHERE(jump);
2895    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x400);
2896    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
2897    /* This code runs only in 8 bit mode. No need to shift the value. */
2898    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2899    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2900    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2901    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2902  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2903  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2904  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));  /* Three byte sequence. */
2905    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2906  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2907  }  }
2908    
# Line 2316  jump = JUMP(SLJIT_C_NOT_ZERO); Line 2922  jump = JUMP(SLJIT_C_NOT_ZERO);
2922  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2923  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));
2924  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
2925    /* The upper 5 bits are known at this point. */
2926    compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x3);
2927  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2928  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2929  OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);  OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
 compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  
2930  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2931  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2932    
2933  JUMPHERE(compare);  JUMPHERE(compare);
2934  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2935  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2936    
2937  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(utf8_table4) - 0xc0);  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
 OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 }  
   
 #else /* COMPILE_PCRE8 */  
   
 #ifdef COMPILE_PCRE16  
 static void do_utfreadchar(compiler_common *common)  
 {  
 /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char  
 of the character (>= 0xd800). Return char value in TMP1, length - 1 in TMP2. */  
 DEFINE_COMPILER;  
 struct sljit_jump *jump;  
   
 sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  
 jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);  
 /* Do nothing, only return. */  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
   
2938  JUMPHERE(jump);  JUMPHERE(jump);
2939  /* Combine two 16 bit characters. */  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2940  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2941  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3ff);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  
2942  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2943  }  }
 #endif /* COMPILE_PCRE16 */  
2944    
2945  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
2946    
# Line 2384  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 2962  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2962    
2963  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2964  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2965  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));
2966  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2967  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2968  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2969  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2970  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2971  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));
2972  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2973  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2974  }  }
# Line 2404  struct sljit_label *newlinelabel = NULL; Line 2982  struct sljit_label *newlinelabel = NULL;
2982  struct sljit_jump *start;  struct sljit_jump *start;
2983  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2984  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2985  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2986  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2987  #endif  #endif
2988  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 2439  if (firstline) Line 3017  if (firstline)
3017      mainloop = LABEL();      mainloop = LABEL();
3018      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
3019      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
3020      read_char(common);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
3021      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
3022      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
3023      JUMPHERE(end);      JUMPHERE(end);
# Line 2459  if (newlinecheck) Line 3037  if (newlinecheck)
3037    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3038    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3039    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);
3040    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3041  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3042    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3043  #endif  #endif
3044    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3045    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 2482  if (newlinecheck) Line 3060  if (newlinecheck)
3060    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);
3061    
3062  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));
3063  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3064    #if defined COMPILE_PCRE8
3065  if (common->utf)  if (common->utf)
3066    {    {
3067    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
3068    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);
3069    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3070    JUMPHERE(singlechar);    JUMPHERE(singlechar);
3071    }    }
3072  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3073  if (common->utf)  if (common->utf)
3074    {    {
3075    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
3076    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3077    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);
3078    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3079    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3080    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3081    JUMPHERE(singlechar);    JUMPHERE(singlechar);
3082    }    }
3083  #endif  #endif /* COMPILE_PCRE[8|16] */
3084    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
3085  JUMPHERE(start);  JUMPHERE(start);
3086    
3087  if (newlinecheck)  if (newlinecheck)
# Line 2514  if (newlinecheck) Line 3093  if (newlinecheck)
3093  return mainloop;  return mainloop;
3094  }  }
3095    
3096  static SLJIT_INLINE BOOL fast_forward_first_two_chars(compiler_common *common, BOOL firstline)  static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, int max_chars)
3097  {  {
3098  DEFINE_COMPILER;  /* Recursive function, which scans prefix literals. */
3099  struct sljit_label *start;  int len, repeat, len_save, consumed = 0;
3100  struct sljit_jump *quit;  pcre_uint32 caseless, chr, mask;
3101  struct sljit_jump *found;  pcre_uchar *alternative, *cc_save;
3102  pcre_int32 chars[4];  BOOL last, any;
 pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  
 int location = 0;  
 pcre_int32 len, c, bit, caseless;  
 BOOL must_end;  
   
 #ifdef COMPILE_PCRE8  
 union {  
     sljit_uh ascombined;  
     sljit_ub asuchars[2];  
 } pair;  
 #else  
 union {  
     sljit_ui ascombined;  
     sljit_uh asuchars[2];  
 } pair;  
 #endif  
   
 if (*(common->start + GET(common->start, 1)) == OP_ALT)  
   return FALSE;  
3103    
3104    repeat = 1;
3105  while (TRUE)  while (TRUE)
3106    {    {
3107      last = TRUE;
3108      any = FALSE;
3109    caseless = 0;    caseless = 0;
3110    must_end = TRUE;    switch (*cc)
   switch(*cc)  
3111      {      {
     case OP_CHAR:  
     must_end = FALSE;  
     cc++;  
     break;  
   
3112      case OP_CHARI:      case OP_CHARI:
3113      caseless = 1;      caseless = 1;
3114      must_end = FALSE;      case OP_CHAR:
3115        last = FALSE;
3116      cc++;      cc++;
3117      break;      break;
3118    
# Line 2579  while (TRUE) Line 3137  while (TRUE)
3137      cc++;      cc++;
3138      break;      break;
3139    
3140      case OP_EXACT:      case OP_EXACTI:
3141      cc += 1 + IMM2_SIZE;      caseless = 1;
3142      break;      case OP_EXACT:
3143        repeat = GET2(cc, 1);
3144      case OP_PLUSI:      last = FALSE;
3145      case OP_MINPLUSI:      cc += 1 + IMM2_SIZE;
3146      case OP_POSPLUSI:      break;
3147      caseless = 1;  
3148      cc++;      case OP_PLUSI:
3149        case OP_MINPLUSI:
3150        case OP_POSPLUSI:
3151        caseless = 1;
3152        cc++;
3153        break;
3154    
3155        case OP_KET:
3156        cc += 1 + LINK_SIZE;
3157        continue;
3158    
3159        case OP_ALT:
3160        cc += GET(cc, 1);
3161        continue;
3162    
3163        case OP_ONCE:
3164        case OP_ONCE_NC:
3165        case OP_BRA:
3166        case OP_BRAPOS:
3167        case OP_CBRA:
3168        case OP_CBRAPOS:
3169        alternative = cc + GET(cc, 1);
3170        while (*alternative == OP_ALT)
3171          {
3172          max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, max_chars);
3173          if (max_chars == 0)
3174            return consumed;
3175          alternative += GET(alternative, 1);
3176          }
3177    
3178        if (*cc == OP_CBRA || *cc == OP_CBRAPOS)
3179          cc += IMM2_SIZE;
3180        cc += 1 + LINK_SIZE;
3181        continue;
3182    
3183        case OP_CLASS:
3184        case OP_NCLASS:
3185        any = TRUE;
3186        cc += 1 + 32 / sizeof(pcre_uchar);
3187        break;
3188    
3189    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3190        case OP_XCLASS:
3191        any = TRUE;
3192        cc += GET(cc, 1);
3193        break;
3194    #endif
3195    
3196        case OP_NOT_DIGIT:
3197        case OP_DIGIT:
3198        case OP_NOT_WHITESPACE:
3199        case OP_WHITESPACE:
3200        case OP_NOT_WORDCHAR:
3201        case OP_WORDCHAR:
3202        case OP_ANY:
3203        case OP_ALLANY:
3204        any = TRUE;
3205        cc++;
3206        break;
3207    
3208    #ifdef SUPPORT_UCP
3209        case OP_NOTPROP:
3210        case OP_PROP:
3211        any = TRUE;
3212        cc += 1 + 2;
3213      break;      break;
3214    #endif
3215    
3216      case OP_EXACTI:      case OP_TYPEEXACT:
3217      caseless = 1;      repeat = GET2(cc, 1);
3218      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
3219      break;      continue;
3220    
3221      default:      default:
3222      return FALSE;      return consumed;
3223        }
3224    
3225      if (any)
3226        {
3227    #ifdef SUPPORT_UTF
3228        if (common->utf) return consumed;
3229    #endif
3230    #if defined COMPILE_PCRE8
3231        mask = 0xff;
3232    #elif defined COMPILE_PCRE16
3233        mask = 0xffff;
3234    #elif defined COMPILE_PCRE32
3235        mask = 0xffffffff;
3236    #else
3237        SLJIT_ASSERT_STOP();
3238    #endif
3239    
3240        do
3241          {
3242          chars[0] = mask;
3243          chars[1] = mask;
3244    
3245          if (--max_chars == 0)
3246            return consumed;
3247          consumed++;
3248          chars += 2;
3249          }
3250        while (--repeat > 0);
3251    
3252        repeat = 1;
3253        continue;
3254      }      }
3255    
3256    len = 1;    len = 1;
3257  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3258    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3259  #endif  #endif
3260    
3261    if (caseless && char_has_othercase(common, cc))    if (caseless != 0 && char_has_othercase(common, cc))
3262      {      {
3263      caseless = char_get_othercase_bit(common, cc);      caseless = char_get_othercase_bit(common, cc);
3264      if (caseless == 0)      if (caseless == 0)
3265        return FALSE;        return consumed;
3266  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3267      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
3268  #else  #else
# Line 2621  while (TRUE) Line 3275  while (TRUE)
3275    else    else
3276      caseless = 0;      caseless = 0;
3277    
3278    while (len > 0 && location < 2 * 2)    len_save = len;
3279      {    cc_save = cc;
3280      c = *cc;    while (TRUE)
3281      bit = 0;      {
3282      if (len == (caseless & 0xff))      do
3283        {        {
3284        bit = caseless >> 8;        chr = *cc;
3285        c |= bit;  #ifdef COMPILE_PCRE32
3286          if (SLJIT_UNLIKELY(chr == NOTACHAR))
3287            return consumed;
3288    #endif
3289          mask = 0;
3290          if ((pcre_uint32)len == (caseless & 0xff))
3291            {
3292            mask = caseless >> 8;
3293            chr |= mask;
3294            }
3295    
3296          if (chars[0] == NOTACHAR)
3297            {
3298            chars[0] = chr;
3299            chars[1] = mask;
3300            }
3301          else
3302            {
3303            mask |= chars[0] ^ chr;
3304            chr |= mask;
3305            chars[0] = chr;
3306            chars[1] |= mask;
3307            }
3308    
3309          len--;
3310          if (--max_chars == 0)
3311            return consumed;
3312          consumed++;
3313          chars += 2;
3314          cc++;
3315        }        }
3316        while (len > 0);
3317    
3318      chars[location] = c;      if (--repeat == 0)
3319      chars[location + 1] = bit;        break;
3320    
3321      len--;      len = len_save;
3322      location += 2;      cc = cc_save;
3323      cc++;      }
3324    
3325      repeat = 1;
3326      if (last)
3327        return consumed;
3328      }
3329    }
3330    
3331    #define MAX_N_CHARS 16
3332    
3333    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3334    {
3335    DEFINE_COMPILER;
3336    struct sljit_label *start;
3337    struct sljit_jump *quit;
3338    pcre_uint32 chars[MAX_N_CHARS * 2];
3339    pcre_uint8 ones[MAX_N_CHARS];
3340    pcre_uint32 mask;
3341    int i, max;
3342    int offsets[3];
3343    
3344    for (i = 0; i < MAX_N_CHARS; i++)
3345      {
3346      chars[i << 1] = NOTACHAR;
3347      chars[(i << 1) + 1] = 0;
3348      }
3349    
3350    max = scan_prefix(common, common->start, chars, MAX_N_CHARS);
3351    
3352    if (max <= 1)
3353      return FALSE;
3354    
3355    for (i = 0; i < max; i++)
3356      {
3357      mask = chars[(i << 1) + 1];
3358      ones[i] = ones_in_half_byte[mask & 0xf];
3359      mask >>= 4;
3360      while (mask != 0)
3361        {
3362        ones[i] += ones_in_half_byte[mask & 0xf];
3363        mask >>= 4;
3364      }      }
3365      }
3366    
3367    if (location == 2 * 2)  offsets[0] = -1;
3368    /* Scan forward. */
3369    for (i = 0; i < max; i++)
3370      if (ones[i] <= 2) {
3371        offsets[0] = i;
3372      break;      break;
   else if (must_end)  
     return FALSE;  
3373    }    }
3374    
3375    if (offsets[0] == -1)
3376      return FALSE;
3377    
3378    /* Scan backward. */
3379    offsets[1] = -1;
3380    for (i = max - 1; i > offsets[0]; i--)
3381      if (ones[i] <= 2) {
3382        offsets[1] = i;
3383        break;
3384      }
3385    
3386    offsets[2] = -1;
3387    if (offsets[1] >= 0)
3388      {
3389      /* Scan from middle. */
3390      for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3391        if (ones[i] <= 2)
3392          {
3393          offsets[2] = i;
3394          break;
3395          }
3396    
3397      if (offsets[2] == -1)
3398        {
3399        for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3400          if (ones[i] <= 2)
3401            {
3402            offsets[2] = i;
3403            break;
3404            }
3405        }
3406      }
3407    
3408    SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3409    SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3410    
3411    chars[0] = chars[offsets[0] << 1];
3412    chars[1] = chars[(offsets[0] << 1) + 1];
3413    if (offsets[2] >= 0)
3414      {
3415      chars[2] = chars[offsets[2] << 1];
3416      chars[3] = chars[(offsets[2] << 1) + 1];
3417      }
3418    if (offsets[1] >= 0)
3419      {
3420      chars[4] = chars[offsets[1] << 1];
3421      chars[5] = chars[(offsets[1] << 1) + 1];
3422      }
3423    
3424    max -= 1;
3425  if (firstline)  if (firstline)
3426    {    {
3427    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3428    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3429    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, 1);    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS(max));
3430    }    }
3431  else  else
3432    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3433    
3434  start = LABEL();  start = LABEL();
3435  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
 #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  
 #ifdef COMPILE_PCRE8  
 OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #else /* COMPILE_PCRE8 */  
 OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #endif  
3436    
3437  #else /* SLJIT_UNALIGNED */  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
3438    if (offsets[1] >= 0)
3439  #if defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3440  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 #else /* SLJIT_BIG_ENDIAN */  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #endif /* SLJIT_BIG_ENDIAN */  
   
 #ifdef COMPILE_PCRE8  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 8);  
 #else /* COMPILE_PCRE8 */  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 16);  
 #endif  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
3441    
3442  #endif  if (chars[1] != 0)
3443      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3444    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3445    if (offsets[2] >= 0)
3446      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));
3447    
3448  if (chars[1] != 0 || chars[3] != 0)  if (offsets[1] >= 0)
3449    {    {
3450    pair.asuchars[0] = chars[1];    if (chars[5] != 0)
3451    pair.asuchars[1] = chars[3];      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3452    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, pair.ascombined);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
3453    }    }
3454    
3455  pair.asuchars[0] = chars[0];  if (offsets[2] >= 0)
3456  pair.asuchars[1] = chars[2];    {
3457  found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, pair.ascombined);    if (chars[3] != 0)
3458        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3459      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3460      }
3461    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3462    
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 JUMPTO(SLJIT_JUMP, start);  
 JUMPHERE(found);  
3463  JUMPHERE(quit);  JUMPHERE(quit);
3464    
3465  if (firstline)  if (firstline)
3466    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3467  else  else
3468    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3469  return TRUE;  return TRUE;
3470  }  }
3471    
3472    #undef MAX_N_CHARS
3473    
3474  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)
3475  {  {
3476  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2738  if (first_char == oc) Line 3504  if (first_char == oc)
3504  else  else
3505    {    {
3506    bit = first_char ^ oc;    bit = first_char ^ oc;
3507    if (ispowerof2(bit))    if (is_powerof2(bit))
3508      {      {
3509      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3510      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
# Line 2746  else Line 3512  else
3512    else    else
3513      {      {
3514      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);
3515      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3516      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);
3517      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);
3518      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3519      }      }
3520    }    }
# Line 2790  if (common->nltype == NLTYPE_FIXED && co Line 3556  if (common->nltype == NLTYPE_FIXED && co
3556    
3557    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3558    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);
3559    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3560  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3561    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3562  #endif  #endif
3563    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3564    
# Line 2819  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_ Line 3585  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_
3585  skip_char_back(common);  skip_char_back(common);
3586    
3587  loop = LABEL();  loop = LABEL();
3588  read_char(common);  read_char_range(common, common->nlmin, common->nlmax, TRUE);
3589  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3590  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3591    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
# Line 2833  if (common->nltype == NLTYPE_ANY || comm Line 3599  if (common->nltype == NLTYPE_ANY || comm
3599    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3600    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3601    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);
3602    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3603  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3604    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3605  #endif  #endif
3606    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3607    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
# Line 2848  if (firstline) Line 3614  if (firstline)
3614    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3615  }  }
3616    
3617  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks);
3618    
3619    static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, pcre_uint8 *start_bits, BOOL firstline)
3620  {  {
3621  DEFINE_COMPILER;  DEFINE_COMPILER;
3622  struct sljit_label *start;  struct sljit_label *start;
3623  struct sljit_jump *quit;  struct sljit_jump *quit;
3624  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3625    jump_list *matches = NULL;
3626  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3627  struct sljit_jump *jump;  struct sljit_jump *jump;
3628  #endif  #endif
# Line 2872  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 3641  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3641  if (common->utf)  if (common->utf)
3642    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3643  #endif  #endif
3644    
3645    if (!check_class_ranges(common, start_bits, (start_bits[31] & 0x80) != 0, TRUE, &matches))
3646      {
3647  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3648  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3649  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3650  JUMPHERE(jump);    JUMPHERE(jump);
3651  #endif  #endif
3652  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3653  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3654  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
3655  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3656  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);
3657  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3658      }
3659    
3660  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3661  if (common->utf)  if (common->utf)
3662    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3663  #endif  #endif
3664  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));
3665  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3666    #if defined COMPILE_PCRE8
3667  if (common->utf)  if (common->utf)
3668    {    {
3669    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3670    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);
3671    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3672    }    }
3673  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3674  if (common->utf)  if (common->utf)
3675    {    {
3676    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3677    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3678    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);
3679    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3680    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3681    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3682    }    }
3683  #endif  #endif /* COMPILE_PCRE[8|16] */
3684    #endif /* SUPPORT_UTF */
3685  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3686  JUMPHERE(found);  if (found != NULL)
3687      JUMPHERE(found);
3688    if (matches != NULL)
3689      set_jumps(matches, LABEL());
3690  JUMPHERE(quit);  JUMPHERE(quit);
3691    
3692  if (firstline)  if (firstline)
# Line 2925  struct sljit_jump *alreadyfound; Line 3702  struct sljit_jump *alreadyfound;
3702  struct sljit_jump *found;  struct sljit_jump *found;
3703  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3704  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3705  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3706    
3707  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3708  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
# Line 2956  if (req_char == oc) Line 3733  if (req_char == oc)
3733  else  else
3734    {    {
3735    bit = req_char ^ oc;    bit = req_char ^ oc;
3736    if (ispowerof2(bit))    if (is_powerof2(bit))
3737      {      {
3738      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
3739      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
# Line 2992  GET_LOCAL_BASE(TMP3, 0, 0); Line 3769  GET_LOCAL_BASE(TMP3, 0, 0);
3769  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3770  mainloop = LABEL();  mainloop = LABEL();
3771  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3772  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);
3773    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3774    
3775  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3776  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3777  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_w), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
3778  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw));
3779  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3780    
3781  JUMPHERE(jump);  JUMPHERE(jump);
3782  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3783  /* End of dropping frames. */  /* End of dropping frames. */
3784  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3785    
3786  JUMPHERE(jump);  JUMPHERE(jump);
3787  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3788  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3789  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3790  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), TMP2, 0);  
 JUMPTO(SLJIT_JUMP, mainloop);  
   
 JUMPHERE(jump);  
 if (common->mark_ptr != 0)  
   {  
   jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setmark);  
   OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  
   OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);  
   JUMPTO(SLJIT_JUMP, mainloop);  
   
   JUMPHERE(jump);  
   }  
   
 /* Unknown command. */  
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  
3791  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3792  }  }
3793    
# Line 3033  static void check_wordboundary(compiler_ Line 3795  static void check_wordboundary(compiler_
3795  {  {
3796  DEFINE_COMPILER;  DEFINE_COMPILER;
3797  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3798    jump_list *skipread_list = NULL;
3799  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3800  struct sljit_jump *jump;  struct sljit_jump *jump;
3801  #endif  #endif
# Line 3058  if (common->use_ucp) Line 3821  if (common->use_ucp)
3821    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3822    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3823    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);
3824    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3825    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);
3826    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);
3827    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3828    JUMPHERE(jump);    JUMPHERE(jump);
3829    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3830    }    }
# Line 3090  else Line 3853  else
3853  JUMPHERE(skipread);  JUMPHERE(skipread);
3854    
3855  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3856  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3857  peek_char(common);  peek_char(common, READ_CHAR_MAX);
3858    
3859  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
3860  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 3102  if (common->use_ucp) Line 3865  if (common->use_ucp)
3865    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3866    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3867    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);
3868    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3869    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);
3870    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);
3871    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3872    JUMPHERE(jump);    JUMPHERE(jump);
3873    }    }
3874  else  else
# Line 3131  else Line 3894  else
3894      JUMPHERE(jump);      JUMPHERE(jump);
3895  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3896    }    }
3897  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3898    
3899  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);
3900  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3901  }  }
3902    
3903  /*  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks)
   range format:  
   
   ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).  
   ranges[1] = first bit (0 or 1)  
   ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)  
 */  
   
 static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)  
3904  {  {
3905  DEFINE_COMPILER;  DEFINE_COMPILER;
3906  struct sljit_jump *jump;  int ranges[MAX_RANGE_SIZE];
   
 if (ranges[0] < 0)  
   return FALSE;  
   
 switch(ranges[0])  
   {  
   case 1:  
   if (readch)  
     read_char(common);  
   add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));  
   return TRUE;  
   
   case 2:  
   if (readch)  
     read_char(common);  
   OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);  
   add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));  
   return TRUE;  
   
   case 4:  
   if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])  
     {  
     if (readch)  
       read_char(common);  
     if (ranges[1] != 0)  
       {  
       add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));  
       add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));  
       }  
     else  
       {  
       jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);  
       add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));  
       JUMPHERE(jump);  
       }  
     return TRUE;  
     }  
   if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && ispowerof2(ranges[4] - ranges[2]))  
     {  
     if (readch)  
       read_char(common);  
     OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);  
     OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);  
     add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));  
     return TRUE;  
     }  
   return FALSE;  
   
   default:  
   return FALSE;  
   }  
 }  
   
 static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)  
 {  
 int i, bit, length;  
 const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;  
   
 bit = ctypes[0] & flag;  
 ranges[0] = -1;  
 ranges[1] = bit != 0 ? 1 : 0;  
 length = 0;  
   
 for (i = 1; i < 256; i++)  
   if ((ctypes[i] & flag) != bit)  
     {  
     if (length >= MAX_RANGE_SIZE)  
       return;  
     ranges[2 + length] = i;  
     length++;  
     bit ^= flag;  
     }  
   
 if (bit != 0)  
   {  
   if (length >= MAX_RANGE_SIZE)  
     return;  
   ranges[2 + length] = 256;  
   length++;  
   }  
 ranges[0] = length;  
 }  
   
 static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)  
 {  
 int ranges[2 + MAX_RANGE_SIZE];  
3907  pcre_uint8 bit, cbit, all;  pcre_uint8 bit, cbit, all;
3908  int i, byte, length = 0;  int i, byte, length = 0;
3909    
3910  bit = bits[0] & 0x1;  bit = bits[0] & 0x1;
3911  ranges[1] = bit;  /* All bits will be zero or one (since bit is zero or one). */
 /* Can be 0 or 255. */  
3912  all = -bit;  all = -bit;
3913    
3914  for (i = 0; i < 256; )  for (i = 0; i < 256; )
# Line 3255  for (i = 0; i < 256; ) Line 3923  for (i = 0; i < 256; )
3923        {        {
3924        if (length >= MAX_RANGE_SIZE)        if (length >= MAX_RANGE_SIZE)
3925          return FALSE;          return FALSE;
3926        ranges[2 + length] = i;        ranges[length] = i;
3927        length++;        length++;
3928        bit = cbit;        bit = cbit;
3929        all = -cbit;        all = -cbit;
# Line 3268  if (((bit == 0) && nclass) || ((bit == 1 Line 3936  if (((bit == 0) && nclass) || ((bit == 1
3936    {    {
3937    if (length >= MAX_RANGE_SIZE)    if (length >= MAX_RANGE_SIZE)
3938      return FALSE;      return FALSE;
3939    ranges[2 + length] = 256;    ranges[length] = 256;
3940    length++;    length++;
3941    }    }
3942  ranges[0] = length;  
3943    if (length < 0 || length > 4)
3944  return check_ranges(common, ranges, backtracks, FALSE);    return FALSE;
3945    
3946    bit = bits[0] & 0x1;
3947