/[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 1221 by ph10, Sun Nov 11 20:27:03 2012 UTC revision 1549 by zherczeg, Tue Apr 21 07:13:00 2015 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 52  POSSIBILITY OF SUCH DAMAGE. Line 52  POSSIBILITY OF SUCH DAMAGE.
52  we just include it. This way we don't need to touch the build  we just include it. This way we don't need to touch the build
53  system files. */  system files. */
54    
55  #define SLJIT_MALLOC(size) (PUBL(malloc))(size)  #define SLJIT_MALLOC(size, allocator_data) (PUBL(malloc))(size)
56  #define SLJIT_FREE(ptr) (PUBL(free))(ptr)  #define SLJIT_FREE(ptr, allocator_data) (PUBL(free))(ptr)
57  #define SLJIT_CONFIG_AUTO 1  #define SLJIT_CONFIG_AUTO 1
58  #define SLJIT_CONFIG_STATIC 1  #define SLJIT_CONFIG_STATIC 1
59  #define SLJIT_VERBOSE 0  #define SLJIT_VERBOSE 0
# Line 65  system files. */ Line 65  system files. */
65  #error Unsupported architecture  #error Unsupported architecture
66  #endif  #endif
67    
68    /* Defines for debugging purposes. */
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.  /* Allocate memory for the regex stack on the real machine stack.
78  Fast, but limited size. */  Fast, but limited size. */
79  #define MACHINE_STACK_SIZE 32768  #define MACHINE_STACK_SIZE 32768
# Line 157  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 168  typedef struct jit_arguments { Line 179  typedef struct jit_arguments {
179    
180  typedef struct executable_functions {  typedef struct executable_functions {
181    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182      void *read_only_data_heads[JIT_NUMBER_OF_COMPILE_MODES];
183      sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
184    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
185    void *userdata;    void *userdata;
186    pcre_uint32 top_bracket;    pcre_uint32 top_bracket;
187    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    pcre_uint32 limit_match;
188  } executable_functions;  } executable_functions;
189    
190  typedef struct jump_list {  typedef struct jump_list {
# Line 179  typedef struct jump_list { Line 192  typedef struct jump_list {
192    struct jump_list *next;    struct jump_list *next;
193  } jump_list;  } jump_list;
194    
 enum stub_types { stack_alloc };  
   
195  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
196    struct sljit_jump *start;    struct sljit_jump *start;
197    struct sljit_label *quit;    struct sljit_label *quit;
198    struct stub_list *next;    struct stub_list *next;
199  } stub_list;  } stub_list;
200    
201    typedef struct label_addr_list {
202      struct sljit_label *label;
203      sljit_uw *update_addr;
204      struct label_addr_list *next;
205    } label_addr_list;
206    
207    enum frame_types {
208      no_frame = -1,
209      no_stack = -2
210    };
211    
212    enum control_types {
213      type_mark = 0,
214      type_then_trap = 1
215    };
216    
217  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
218    
219  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
220  code generator. It is allocated by compile_matchingpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
221  the aguments for compile_backtrackingpath. Must be the first member  the arguments for compile_backtrackingpath. Must be the first member
222  of its descendants. */  of its descendants. */
223  typedef struct backtrack_common {  typedef struct backtrack_common {
224    /* Concatenation stack. */    /* Concatenation stack. */
# Line 209  typedef struct backtrack_common { Line 234  typedef struct backtrack_common {
234  typedef struct assert_backtrack {  typedef struct assert_backtrack {
235    backtrack_common common;    backtrack_common common;
236    jump_list *condfailed;    jump_list *condfailed;
237    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
238    int framesize;    int framesize;
239    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
240    int private_data_ptr;    int private_data_ptr;
# Line 230  typedef struct bracket_backtrack { Line 255  typedef struct bracket_backtrack {
255      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
256      jump_list *condfailed;      jump_list *condfailed;
257      assert_backtrack *assert;      assert_backtrack *assert;
258      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
259      int framesize;      int framesize;
260    } u;    } u;
261    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
# Line 265  typedef struct recurse_entry { Line 290  typedef struct recurse_entry {
290    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
291    jump_list *calls;    jump_list *calls;
292    /* Points to the starting opcode. */    /* Points to the starting opcode. */
293    int start;    sljit_sw start;
294  } recurse_entry;  } recurse_entry;
295    
296  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
297    backtrack_common common;    backtrack_common common;
298      BOOL inlined_pattern;
299  } recurse_backtrack;  } recurse_backtrack;
300    
301  #define MAX_RANGE_SIZE 6  #define OP_THEN_TRAP OP_TABLE_LENGTH
302    
303    typedef struct then_trap_backtrack {
304      backtrack_common common;
305      /* If then_trap is not NULL, this structure contains the real
306      then_trap for the backtracking path. */
307      struct then_trap_backtrack *then_trap;
308      /* Points to the starting opcode. */
309      sljit_sw start;
310      /* Exit point for the then opcodes of this alternative. */
311      jump_list *quit;
312      /* Frame size of the current alternative. */
313      int framesize;
314    } then_trap_backtrack;
315    
316    #define MAX_RANGE_SIZE 4
317    
318  typedef struct compiler_common {  typedef struct compiler_common {
319      /* The sljit ceneric compiler. */
320    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
321      /* First byte code. */
322    pcre_uchar *start;    pcre_uchar *start;
   
323    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
324    int *private_data_ptrs;    sljit_si *private_data_ptrs;
325      /* Chain list of read-only data ptrs. */
326      void *read_only_data_head;
327    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
328    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
329      /* Tells whether the starting offset is a target of then. */
330      pcre_uint8 *then_offsets;
331      /* Current position where a THEN must jump. */
332      then_trap_backtrack *then_trap;
333    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
334    int cbraptr;    int cbra_ptr;
335    /* OVector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
336    int ovector_start;    int ovector_start;
337    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
338    int req_char_ptr;    int req_char_ptr;
339    /* Head of the last recursion. */    /* Head of the last recursion. */
340    int recursive_head;    int recursive_head_ptr;
341    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
342    int start_used_ptr;    int start_used_ptr;
343    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 298  typedef struct compiler_common { Line 346  typedef struct compiler_common {
346    int first_line_end;    int first_line_end;
347    /* Points to the marked string. */    /* Points to the marked string. */
348    int mark_ptr;    int mark_ptr;
349      /* Recursive control verb management chain. */
350      int control_head_ptr;
351      /* Points to the last matched capture block index. */
352      int capture_last_ptr;
353      /* Points to the starting position of the current match. */
354      int start_ptr;
355    
356    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
357    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
358    sljit_sw lcc;    sljit_sw lcc;
359    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
360    int mode;    int mode;
361      /* TRUE, when minlength is greater than 0. */
362      BOOL might_be_empty;
363      /* \K is found in the pattern. */
364      BOOL has_set_som;
365      /* (*SKIP:arg) is found in the pattern. */
366      BOOL has_skip_arg;
367      /* (*THEN) is found in the pattern. */
368      BOOL has_then;
369      /* Needs to know the start position anytime. */
370      BOOL needs_start_ptr;
371      /* Currently in recurse or negative assert. */
372      BOOL local_exit;
373      /* Currently in a positive assert. */
374      BOOL positive_assert;
375    /* Newline control. */    /* Newline control. */
376    int nltype;    int nltype;
377      pcre_uint32 nlmax;
378      pcre_uint32 nlmin;
379    int newline;    int newline;
380    int bsr_nltype;    int bsr_nltype;
381      pcre_uint32 bsr_nlmax;
382      pcre_uint32 bsr_nlmin;
383    /* Dollar endonly. */    /* Dollar endonly. */
384    int endonly;    int endonly;
   BOOL has_set_som;  
385    /* Tables. */    /* Tables. */
386    sljit_sw ctypes;    sljit_sw ctypes;
   int digits[2 + MAX_RANGE_SIZE];  
387    /* Named capturing brackets. */    /* Named capturing brackets. */
388    sljit_uw name_table;    pcre_uchar *name_table;
389    sljit_sw name_count;    sljit_sw name_count;
390    sljit_sw name_entry_size;    sljit_sw name_entry_size;
391    
392    /* Labels and jump lists. */    /* Labels and jump lists. */
393    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
394    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
395    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
396      struct sljit_label *accept_label;
397      struct sljit_label *ff_newline_shortcut;
398    stub_list *stubs;    stub_list *stubs;
399      label_addr_list *label_addrs;
400    recurse_entry *entries;    recurse_entry *entries;
401    recurse_entry *currententry;    recurse_entry *currententry;
402    jump_list *partialmatch;    jump_list *partialmatch;
403    jump_list *quit;    jump_list *quit;
404      jump_list *positive_assert_quit;
405      jump_list *forced_quit;
406    jump_list *accept;    jump_list *accept;
407    jump_list *calllimit;    jump_list *calllimit;
408    jump_list *stackalloc;    jump_list *stackalloc;
# Line 338  typedef struct compiler_common { Line 413  typedef struct compiler_common {
413    jump_list *vspace;    jump_list *vspace;
414    jump_list *casefulcmp;    jump_list *casefulcmp;
415    jump_list *caselesscmp;    jump_list *caselesscmp;
416      jump_list *reset_match;
417    BOOL jscript_compat;    BOOL jscript_compat;
418  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
419    BOOL utf;    BOOL utf;
420  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
421    BOOL use_ucp;    BOOL use_ucp;
422  #endif  #endif
 #ifndef COMPILE_PCRE32  
   jump_list *utfreadchar;  
 #endif  
423  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
424      jump_list *utfreadchar;
425      jump_list *utfreadchar16;
426    jump_list *utfreadtype8;    jump_list *utfreadtype8;
427  #endif  #endif
428  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
# Line 390  typedef struct compare_context { Line 465  typedef struct compare_context {
465  #endif  #endif
466  } compare_context;  } compare_context;
467    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
468  /* Undefine sljit macros. */  /* Undefine sljit macros. */
469  #undef CMP  #undef CMP
470    
471  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
472  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
473    
474  #define TMP1          SLJIT_SCRATCH_REG1  #define TMP1          SLJIT_R0
475  #define TMP2          SLJIT_SCRATCH_REG3  #define TMP2          SLJIT_R2
476  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_R3
477  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_S0
478  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_S1
479  #define STACK_TOP     SLJIT_SCRATCH_REG2  #define STACK_TOP     SLJIT_R1
480  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_S2
481  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define COUNT_MATCH   SLJIT_S3
482  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define ARGUMENTS     SLJIT_S4
483  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_R4
484    
485  /* Local space layout. */  /* Local space layout. */
486  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
# Line 421  enum { Line 490  enum {
490  #define POSSESSIVE0      (2 * sizeof(sljit_sw))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
491  #define POSSESSIVE1      (3 * sizeof(sljit_sw))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
492  /* Max limit of recursions. */  /* Max limit of recursions. */
493  #define CALL_LIMIT       (4 * sizeof(sljit_sw))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
494  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
495  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
496  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
497  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. */
498  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
499  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))  #define OVECTOR(i)       (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw))
500  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_sw))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
501  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
502    
503  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
# Line 459  the start pointers when the end of the c Line 528  the start pointers when the end of the c
528    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
529  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
530    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
531    #define SET_LABEL(jump, label) \
532      sljit_set_label((jump), (label))
533  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
534    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
535  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
# Line 468  the start pointers when the end of the c Line 539  the start pointers when the end of the c
539  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
540    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
541    
542  static pcre_uchar* bracketend(pcre_uchar* cc)  #define READ_CHAR_MAX 0x7fffffff
543    
544    static pcre_uchar *bracketend(pcre_uchar *cc)
545  {  {
546  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));
547  do cc += GET(cc, 1); while (*cc == OP_ALT);  do cc += GET(cc, 1); while (*cc == OP_ALT);
# Line 477  cc += 1 + LINK_SIZE; Line 550  cc += 1 + LINK_SIZE;
550  return cc;  return cc;
551  }  }
552    
553    static int no_alternatives(pcre_uchar *cc)
554    {
555    int count = 0;
556    SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
557    do
558      {
559      cc += GET(cc, 1);
560      count++;
561      }
562    while (*cc == OP_ALT);
563    SLJIT_ASSERT(*cc >= OP_KET && *cc <= OP_KETRPOS);
564    return count;
565    }
566    
567    static int ones_in_half_byte[16] = {
568      /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
569      /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
570    };
571    
572  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
573   next_opcode   next_opcode
574   get_private_data_length   check_opcode_types
575   set_private_data_ptrs   set_private_data_ptrs
576   get_framesize   get_framesize
577   init_frame   init_frame
578   get_private_data_length_for_copy   get_private_data_copy_length
579   copy_private_data   copy_private_data
580   compile_matchingpath   compile_matchingpath
581   compile_backtrackingpath   compile_backtrackingpath
# Line 507  switch(*cc) Line 599  switch(*cc)
599    case OP_WORDCHAR:    case OP_WORDCHAR:
600    case OP_ANY:    case OP_ANY:
601    case OP_ALLANY:    case OP_ALLANY:
602      case OP_NOTPROP:
603      case OP_PROP:
604    case OP_ANYNL:    case OP_ANYNL:
605    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
606    case OP_HSPACE:    case OP_HSPACE:
# Line 519  switch(*cc) Line 613  switch(*cc)
613    case OP_CIRCM:    case OP_CIRCM:
614    case OP_DOLL:    case OP_DOLL:
615    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:  
616    case OP_CRSTAR:    case OP_CRSTAR:
617    case OP_CRMINSTAR:    case OP_CRMINSTAR:
618    case OP_CRPLUS:    case OP_CRPLUS:
619    case OP_CRMINPLUS:    case OP_CRMINPLUS:
620    case OP_CRQUERY:    case OP_CRQUERY:
621    case OP_CRMINQUERY:    case OP_CRMINQUERY:
622      case OP_CRRANGE:
623      case OP_CRMINRANGE:
624      case OP_CRPOSSTAR:
625      case OP_CRPOSPLUS:
626      case OP_CRPOSQUERY:
627      case OP_CRPOSRANGE:
628      case OP_CLASS:
629      case OP_NCLASS:
630      case OP_REF:
631      case OP_REFI:
632      case OP_DNREF:
633      case OP_DNREFI:
634      case OP_RECURSE:
635      case OP_CALLOUT:
636      case OP_ALT:
637      case OP_KET:
638      case OP_KETRMAX:
639      case OP_KETRMIN:
640      case OP_KETRPOS:
641      case OP_REVERSE:
642      case OP_ASSERT:
643      case OP_ASSERT_NOT:
644      case OP_ASSERTBACK:
645      case OP_ASSERTBACK_NOT:
646      case OP_ONCE:
647      case OP_ONCE_NC:
648      case OP_BRA:
649      case OP_BRAPOS:
650      case OP_CBRA:
651      case OP_CBRAPOS:
652      case OP_COND:
653      case OP_SBRA:
654      case OP_SBRAPOS:
655      case OP_SCBRA:
656      case OP_SCBRAPOS:
657      case OP_SCOND:
658      case OP_CREF:
659      case OP_DNCREF:
660      case OP_RREF:
661      case OP_DNRREF:
662    case OP_DEF:    case OP_DEF:
663    case OP_BRAZERO:    case OP_BRAZERO:
664    case OP_BRAMINZERO:    case OP_BRAMINZERO:
665    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
666      case OP_PRUNE:
667      case OP_SKIP:
668      case OP_THEN:
669    case OP_COMMIT:    case OP_COMMIT:
670    case OP_FAIL:    case OP_FAIL:
671    case OP_ACCEPT:    case OP_ACCEPT:
672    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
673      case OP_CLOSE:
674    case OP_SKIPZERO:    case OP_SKIPZERO:
675    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
676    
677    case OP_CHAR:    case OP_CHAR:
678    case OP_CHARI:    case OP_CHARI:
# Line 561  switch(*cc) Line 684  switch(*cc)
684    case OP_MINPLUS:    case OP_MINPLUS:
685    case OP_QUERY:    case OP_QUERY:
686    case OP_MINQUERY:    case OP_MINQUERY:
687      case OP_UPTO:
688      case OP_MINUPTO:
689      case OP_EXACT:
690    case OP_POSSTAR:    case OP_POSSTAR:
691    case OP_POSPLUS:    case OP_POSPLUS:
692    case OP_POSQUERY:    case OP_POSQUERY:
693      case OP_POSUPTO:
694    case OP_STARI:    case OP_STARI:
695    case OP_MINSTARI:    case OP_MINSTARI:
696    case OP_PLUSI:    case OP_PLUSI:
697    case OP_MINPLUSI:    case OP_MINPLUSI:
698    case OP_QUERYI:    case OP_QUERYI:
699    case OP_MINQUERYI:    case OP_MINQUERYI:
700      case OP_UPTOI:
701      case OP_MINUPTOI:
702      case OP_EXACTI:
703    case OP_POSSTARI:    case OP_POSSTARI:
704    case OP_POSPLUSI:    case OP_POSPLUSI:
705    case OP_POSQUERYI:    case OP_POSQUERYI:
706      case OP_POSUPTOI:
707    case OP_NOTSTAR:    case OP_NOTSTAR:
708    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
709    case OP_NOTPLUS:    case OP_NOTPLUS:
710    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
711    case OP_NOTQUERY:    case OP_NOTQUERY:
712    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
713      case OP_NOTUPTO:
714      case OP_NOTMINUPTO:
715      case OP_NOTEXACT:
716    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
717    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
718    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
719      case OP_NOTPOSUPTO:
720    case OP_NOTSTARI:    case OP_NOTSTARI:
721    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
722    case OP_NOTPLUSI:    case OP_NOTPLUSI:
723    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
724    case OP_NOTQUERYI:    case OP_NOTQUERYI:
725    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:  
726    case OP_NOTUPTOI:    case OP_NOTUPTOI:
727    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
728    case OP_NOTEXACTI:    case OP_NOTEXACTI:
729      case OP_NOTPOSSTARI:
730      case OP_NOTPOSPLUSI:
731      case OP_NOTPOSQUERYI:
732    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
733    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
734  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
735    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
736  #endif  #endif
737    return cc;    return cc;
738    
739    case OP_NOTPROP:    /* Special cases. */
740    case OP_PROP:    case OP_TYPESTAR:
741    return cc + 1 + 2;    case OP_TYPEMINSTAR:
742      case OP_TYPEPLUS:
743      case OP_TYPEMINPLUS:
744      case OP_TYPEQUERY:
745      case OP_TYPEMINQUERY:
746    case OP_TYPEUPTO:    case OP_TYPEUPTO:
747    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
748    case OP_TYPEEXACT:    case OP_TYPEEXACT:
749      case OP_TYPEPOSSTAR:
750      case OP_TYPEPOSPLUS:
751      case OP_TYPEPOSQUERY:
752    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
753    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;  
754    
755    case OP_CRRANGE:    case OP_ANYBYTE:
756    case OP_CRMINRANGE:  #ifdef SUPPORT_UTF
757    return cc + 1 + 2 * IMM2_SIZE;    if (common->utf) return NULL;
758    #endif
759    case OP_CLASS:    return cc + 1;
   case OP_NCLASS:  
   return cc + 1 + 32 / sizeof(pcre_uchar);  
760    
761  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
762    case OP_XCLASS:    case OP_XCLASS:
763    return cc + GET(cc, 1);    return cc + GET(cc, 1);
764  #endif  #endif
765    
   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;  
   
766    case OP_MARK:    case OP_MARK:
767      case OP_PRUNE_ARG:
768      case OP_SKIP_ARG:
769      case OP_THEN_ARG:
770    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
771    
772    default:    default:
773      /* All opcodes are supported now! */
774      SLJIT_ASSERT_STOP();
775    return NULL;    return NULL;
776    }    }
777  }  }
778    
779  #define CASE_ITERATOR_PRIVATE_DATA_1 \  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
780      case OP_MINSTAR: \  {
781      case OP_MINPLUS: \  int count;
782      case OP_QUERY: \  pcre_uchar *slot;
     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:  
783    
784  #define CASE_ITERATOR_PRIVATE_DATA_2A \  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
785      case OP_STAR: \  while (cc < ccend)
786      case OP_PLUS: \    {
787      case OP_STARI: \    switch(*cc)
788      case OP_PLUSI: \      {
789      case OP_NOTSTAR: \      case OP_SET_SOM:
790      case OP_NOTPLUS: \      common->has_set_som = TRUE;
791      case OP_NOTSTARI: \      common->might_be_empty = TRUE;
792      case OP_NOTPLUSI:      cc += 1;
793        break;
794    
795  #define CASE_ITERATOR_PRIVATE_DATA_2B \      case OP_REF:
796      case OP_UPTO: \      case OP_REFI:
797      case OP_MINUPTO: \      common->optimized_cbracket[GET2(cc, 1)] = 0;
798      case OP_UPTOI: \      cc += 1 + IMM2_SIZE;
799      case OP_MINUPTOI: \      break;
     case OP_NOTUPTO: \  
     case OP_NOTMINUPTO: \  
     case OP_NOTUPTOI: \  
     case OP_NOTMINUPTOI:  
800    
801  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \      case OP_CBRAPOS:
802      case OP_TYPEMINSTAR: \      case OP_SCBRAPOS:
803      case OP_TYPEMINPLUS: \      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
804      case OP_TYPEQUERY: \      cc += 1 + LINK_SIZE + IMM2_SIZE;
805      case OP_TYPEMINQUERY:      break;
806    
807  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \      case OP_COND:
808      case OP_TYPESTAR: \      case OP_SCOND:
809      case OP_TYPEPLUS:      /* Only AUTO_CALLOUT can insert this opcode. We do
810           not intend to support this case. */
811        if (cc[1 + LINK_SIZE] == OP_CALLOUT)
812          return FALSE;
813        cc += 1 + LINK_SIZE;
814        break;
815    
816  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \      case OP_CREF:
817      case OP_TYPEUPTO: \      common->optimized_cbracket[GET2(cc, 1)] = 0;
818      case OP_TYPEMINUPTO:      cc += 1 + IMM2_SIZE;
819        break;
820    
821  static int get_class_iterator_size(pcre_uchar *cc)      case OP_DNREF:
822  {      case OP_DNREFI:
823  switch(*cc)      case OP_DNCREF:
824    {      count = GET2(cc, 1 + IMM2_SIZE);
825        slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
826        while (count-- > 0)
827          {
828          common->optimized_cbracket[GET2(slot, 0)] = 0;
829          slot += common->name_entry_size;
830          }
831        cc += 1 + 2 * IMM2_SIZE;
832        break;
833    
834        case OP_RECURSE:
835        /* Set its value only once. */
836        if (common->recursive_head_ptr == 0)
837          {
838          common->recursive_head_ptr = common->ovector_start;
839          common->ovector_start += sizeof(sljit_sw);
840          }
841        cc += 1 + LINK_SIZE;
842        break;
843    
844        case OP_CALLOUT:
845        if (common->capture_last_ptr == 0)
846          {
847          common->capture_last_ptr = common->ovector_start;
848          common->ovector_start += sizeof(sljit_sw);
849          }
850        cc += 2 + 2 * LINK_SIZE;
851        break;
852    
853        case OP_THEN_ARG:
854        common->has_then = TRUE;
855        common->control_head_ptr = 1;
856        /* Fall through. */
857    
858        case OP_PRUNE_ARG:
859        common->needs_start_ptr = TRUE;
860        /* Fall through. */
861    
862        case OP_MARK:
863        if (common->mark_ptr == 0)
864          {
865          common->mark_ptr = common->ovector_start;
866          common->ovector_start += sizeof(sljit_sw);
867          }
868        cc += 1 + 2 + cc[1];
869        break;
870    
871        case OP_THEN:
872        common->has_then = TRUE;
873        common->control_head_ptr = 1;
874        /* Fall through. */
875    
876        case OP_PRUNE:
877        case OP_SKIP:
878        common->needs_start_ptr = TRUE;
879        cc += 1;
880        break;
881    
882        case OP_SKIP_ARG:
883        common->control_head_ptr = 1;
884        common->has_skip_arg = TRUE;
885        cc += 1 + 2 + cc[1];
886        break;
887    
888        default:
889        cc = next_opcode(common, cc);
890        if (cc == NULL)
891          return FALSE;
892        break;
893        }
894      }
895    return TRUE;
896    }
897    
898    static int get_class_iterator_size(pcre_uchar *cc)
899    {
900    switch(*cc)
901      {
902    case OP_CRSTAR:    case OP_CRSTAR:
903    case OP_CRPLUS:    case OP_CRPLUS:
904    return 2;    return 2;
# Line 762  switch(*cc) Line 920  switch(*cc)
920    }    }
921  }  }
922    
923  static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
924    {
925    pcre_uchar *end = bracketend(begin);
926    pcre_uchar *next;
927    pcre_uchar *next_end;
928    pcre_uchar *max_end;
929    pcre_uchar type;
930    sljit_sw length = end - begin;
931    int min, max, i;
932    
933    /* Detect fixed iterations first. */
934    if (end[-(1 + LINK_SIZE)] != OP_KET)
935      return FALSE;
936    
937    /* Already detected repeat. */
938    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
939      return TRUE;
940    
941    next = end;
942    min = 1;
943    while (1)
944      {
945      if (*next != *begin)
946        break;
947      next_end = bracketend(next);
948      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
949        break;
950      next = next_end;
951      min++;
952      }
953    
954    if (min == 2)
955      return FALSE;
956    
957    max = 0;
958    max_end = next;
959    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
960      {
961      type = *next;
962      while (1)
963        {
964        if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
965          break;
966        next_end = bracketend(next + 2 + LINK_SIZE);
967        if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
968          break;
969        next = next_end;
970        max++;
971        }
972    
973      if (next[0] == type && next[1] == *begin && max >= 1)
974        {
975        next_end = bracketend(next + 1);
976        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
977          {
978          for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
979            if (*next_end != OP_KET)
980              break;
981    
982          if (i == max)
983            {
984            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
985            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
986            /* +2 the original and the last. */
987            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
988            if (min == 1)
989              return TRUE;
990            min--;
991            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
992            }
993          }
994        }
995      }
996    
997    if (min >= 3)
998      {
999      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
1000      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
1001      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
1002      return TRUE;
1003      }
1004    
1005    return FALSE;
1006    }
1007    
1008    #define CASE_ITERATOR_PRIVATE_DATA_1 \
1009        case OP_MINSTAR: \
1010        case OP_MINPLUS: \
1011        case OP_QUERY: \
1012        case OP_MINQUERY: \
1013        case OP_MINSTARI: \
1014        case OP_MINPLUSI: \
1015        case OP_QUERYI: \
1016        case OP_MINQUERYI: \
1017        case OP_NOTMINSTAR: \
1018        case OP_NOTMINPLUS: \
1019        case OP_NOTQUERY: \
1020        case OP_NOTMINQUERY: \
1021        case OP_NOTMINSTARI: \
1022        case OP_NOTMINPLUSI: \
1023        case OP_NOTQUERYI: \
1024        case OP_NOTMINQUERYI:
1025    
1026    #define CASE_ITERATOR_PRIVATE_DATA_2A \
1027        case OP_STAR: \
1028        case OP_PLUS: \
1029        case OP_STARI: \
1030        case OP_PLUSI: \
1031        case OP_NOTSTAR: \
1032        case OP_NOTPLUS: \
1033        case OP_NOTSTARI: \
1034        case OP_NOTPLUSI:
1035    
1036    #define CASE_ITERATOR_PRIVATE_DATA_2B \
1037        case OP_UPTO: \
1038        case OP_MINUPTO: \
1039        case OP_UPTOI: \
1040        case OP_MINUPTOI: \
1041        case OP_NOTUPTO: \
1042        case OP_NOTMINUPTO: \
1043        case OP_NOTUPTOI: \
1044        case OP_NOTMINUPTOI:
1045    
1046    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1047        case OP_TYPEMINSTAR: \
1048        case OP_TYPEMINPLUS: \
1049        case OP_TYPEQUERY: \
1050        case OP_TYPEMINQUERY:
1051    
1052    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1053        case OP_TYPESTAR: \
1054        case OP_TYPEPLUS:
1055    
1056    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1057        case OP_TYPEUPTO: \
1058        case OP_TYPEMINUPTO:
1059    
1060    static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1061  {  {
1062  int private_data_length = 0;  pcre_uchar *cc = common->start;
1063  pcre_uchar *alternative;  pcre_uchar *alternative;
 pcre_uchar *name;  
1064  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1065  int space, size, i;  int private_data_ptr = *private_data_start;
1066  pcre_uint32 bracketlen;  int space, size, bracketlen;
1067    
 /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  
1068  while (cc < ccend)  while (cc < ccend)
1069    {    {
1070    space = 0;    space = 0;
1071    size = 0;    size = 0;
1072    bracketlen = 0;    bracketlen = 0;
1073      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1074        return;
1075    
1076      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1077        if (detect_repeat(common, cc))
1078          {
1079          /* These brackets are converted to repeats, so no global
1080          based single character repeat is allowed. */
1081          if (cc >= end)
1082            end = bracketend(cc);
1083          }
1084    
1085    switch(*cc)    switch(*cc)
1086      {      {
1087      case OP_SET_SOM:      case OP_KET:
1088      common->has_set_som = TRUE;      if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1089      cc += 1;        {
1090      break;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1091          private_data_ptr += sizeof(sljit_sw);
1092      case OP_REF:        cc += common->private_data_ptrs[cc + 1 - common->start];
1093      case OP_REFI:        }
1094      common->optimized_cbracket[GET2(cc, 1)] = 0;      cc += 1 + LINK_SIZE;
     cc += 1 + IMM2_SIZE;  
1095      break;      break;
1096    
1097      case OP_ASSERT:      case OP_ASSERT:
# Line 799  while (cc < ccend) Line 1103  while (cc < ccend)
1103      case OP_BRAPOS:      case OP_BRAPOS:
1104      case OP_SBRA:      case OP_SBRA:
1105      case OP_SBRAPOS:      case OP_SBRAPOS:
1106      private_data_length += sizeof(sljit_sw);      case OP_SCOND:
1107        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1108        private_data_ptr += sizeof(sljit_sw);
1109      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1110      break;      break;
1111    
1112      case OP_CBRAPOS:      case OP_CBRAPOS:
1113      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1114      private_data_length += sizeof(sljit_sw);      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1115      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      private_data_ptr += sizeof(sljit_sw);
1116      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1117      break;      break;
1118    
1119      case OP_COND:      case OP_COND:
1120      case OP_SCOND:      /* Might be a hidden SCOND. */
1121      bracketlen = cc[1 + LINK_SIZE];      alternative = cc + GET(cc, 1);
1122      if (bracketlen == OP_CREF)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
       {  
       bracketlen = GET2(cc, 1 + LINK_SIZE + 1);  
       common->optimized_cbracket[bracketlen] = 0;  
       }  
     else if (bracketlen == OP_NCREF)  
       {  
       bracketlen = GET2(cc, 1 + LINK_SIZE + 1);  
       name = (pcre_uchar *)common->name_table;  
       alternative = name;  
       for (i = 0; i < common->name_count; i++)  
         {  
         if (GET2(name, 0) == bracketlen) break;  
         name += common->name_entry_size;  
         }  
       SLJIT_ASSERT(i != common->name_count);  
   
       for (i = 0; i < common->name_count; i++)  
         {  
         if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)  
           common->optimized_cbracket[GET2(alternative, 0)] = 0;  
         alternative += common->name_entry_size;  
         }  
       }  
   
     if (*cc == OP_COND)  
1123        {        {
1124        /* Might be a hidden SCOND. */        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1125        alternative = cc + GET(cc, 1);        private_data_ptr += sizeof(sljit_sw);
       if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)  
         private_data_length += sizeof(sljit_sw);  
1126        }        }
     else  
       private_data_length += sizeof(sljit_sw);  
1127      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1128      break;      break;
1129    
# Line 904  while (cc < ccend) Line 1181  while (cc < ccend)
1181      break;      break;
1182  #endif  #endif
1183    
     case OP_RECURSE:  
     /* Set its value only once. */  
     if (common->recursive_head == 0)  
       {  
       common->recursive_head = common->ovector_start;  
       common->ovector_start += sizeof(sljit_sw);  
       }  
     cc += 1 + LINK_SIZE;  
     break;  
   
     case OP_MARK:  
     if (common->mark_ptr == 0)  
       {  
       common->mark_ptr = common->ovector_start;  
       common->ovector_start += sizeof(sljit_sw);  
       }  
     cc += 1 + 2 + cc[1];  
     break;  
   
1184      default:      default:
1185      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1186      if (cc == NULL)      SLJIT_ASSERT(cc != NULL);
       return -1;  
1187      break;      break;
1188      }      }
1189    
1190      /* Character iterators, which are not inside a repeated bracket,
1191         gets a private slot instead of allocating it on the stack. */
1192    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1193      private_data_length += sizeof(sljit_sw) * space;      {
1194        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1195        private_data_ptr += sizeof(sljit_sw) * space;
1196        }
1197    
1198    if (size != 0)    if (size != 0)
1199      {      {
# Line 946  while (cc < ccend) Line 1208  while (cc < ccend)
1208        cc += size;        cc += size;
1209      }      }
1210    
1211    if (bracketlen != 0)    if (bracketlen > 0)
1212      {      {
1213      if (cc >= end)      if (cc >= end)
1214        {        {
# Line 957  while (cc < ccend) Line 1219  while (cc < ccend)
1219      cc += bracketlen;      cc += bracketlen;
1220      }      }
1221    }    }
1222  return private_data_length;  *private_data_start = private_data_ptr;
1223  }  }
1224    
1225  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)  /* Returns with a frame_types (always < 0) if no need for frame. */
1226    static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL *needs_control_head)
1227  {  {
1228  pcre_uchar *cc = common->start;  int length = 0;
1229  pcre_uchar *alternative;  int possessive = 0;
1230  pcre_uchar *end = NULL;  BOOL stack_restore = FALSE;
1231  int space, size, bracketlen;  BOOL setsom_found = recursive;
1232    BOOL setmark_found = recursive;
1233    /* The last capture is a local variable even for recursions. */
1234    BOOL capture_last_found = FALSE;
1235    
1236  while (cc < ccend)  #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1237    SLJIT_ASSERT(common->control_head_ptr != 0);
1238    *needs_control_head = TRUE;
1239    #else
1240    *needs_control_head = FALSE;
1241    #endif
1242    
1243    if (ccend == NULL)
1244    {    {
1245    space = 0;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1246    size = 0;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1247    bracketlen = 0;      {
1248        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1249        /* This is correct regardless of common->capture_last_ptr. */
1250        capture_last_found = TRUE;
1251        }
1252      cc = next_opcode(common, cc);
1253      }
1254    
1255    SLJIT_ASSERT(cc != NULL);
1256    while (cc < ccend)
1257    switch(*cc)    switch(*cc)
1258      {      {
1259      case OP_ASSERT:      case OP_SET_SOM:
1260      case OP_ASSERT_NOT:      SLJIT_ASSERT(common->has_set_som);
1261      case OP_ASSERTBACK:      stack_restore = TRUE;
1262      case OP_ASSERTBACK_NOT:      if (!setsom_found)
1263      case OP_ONCE:        {
1264      case OP_ONCE_NC:        length += 2;
1265      case OP_BRAPOS:        setsom_found = TRUE;
1266      case OP_SBRA:        }
1267      case OP_SBRAPOS:      cc += 1;
     case OP_SCOND:  
     common->private_data_ptrs[cc - common->start] = private_data_ptr;  
     private_data_ptr += sizeof(sljit_sw);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_CBRAPOS:  
     case OP_SCBRAPOS:  
     common->private_data_ptrs[cc - common->start] = private_data_ptr;  
     private_data_ptr += sizeof(sljit_sw);  
     bracketlen = 1 + LINK_SIZE + IMM2_SIZE;  
     break;  
   
     case OP_COND:  
     /* Might be a hidden SCOND. */  
     alternative = cc + GET(cc, 1);  
     if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)  
       {  
       common->private_data_ptrs[cc - common->start] = private_data_ptr;  
       private_data_ptr += sizeof(sljit_sw);  
       }  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_BRA:  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_CBRA:  
     case OP_SCBRA:  
     bracketlen = 1 + LINK_SIZE + IMM2_SIZE;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_1  
     space = 1;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_2A  
     space = 2;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_2B  
     space = 2;  
     size = -(2 + IMM2_SIZE);  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_1  
     space = 1;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_2A  
     if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)  
       space = 2;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_2B  
     if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)  
       space = 2;  
     size = 1 + IMM2_SIZE;  
     break;  
   
     case OP_CLASS:  
     case OP_NCLASS:  
     size += 1 + 32 / sizeof(pcre_uchar);  
     space = get_class_iterator_size(cc + size);  
     break;  
   
 #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  
     case OP_XCLASS:  
     size = GET(cc, 1);  
     space = get_class_iterator_size(cc + size);  
     break;  
 #endif  
   
     default:  
     cc = next_opcode(common, cc);  
     SLJIT_ASSERT(cc != NULL);  
     break;  
     }  
   
   if (space > 0 && cc >= end)  
     {  
     common->private_data_ptrs[cc - common->start] = private_data_ptr;  
     private_data_ptr += sizeof(sljit_sw) * space;  
     }  
   
   if (size != 0)  
     {  
     if (size < 0)  
       {  
       cc += -size;  
 #ifdef SUPPORT_UTF  
       if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
       }  
     else  
       cc += size;  
     }  
   
   if (bracketlen > 0)  
     {  
     if (cc >= end)  
       {  
       end = bracketend(cc);  
       if (end[-1 - LINK_SIZE] == OP_KET)  
         end = NULL;  
       }  
     cc += bracketlen;  
     }  
   }  
 }  
   
 /* Returns with -1 if no need for frame. */  
 static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  
 {  
 pcre_uchar *ccend = bracketend(cc);  
 int length = 0;  
 BOOL possessive = FALSE;  
 BOOL setsom_found = recursive;  
 BOOL setmark_found = recursive;  
   
 if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  
   {  
   length = 3;  
   possessive = TRUE;  
   }  
   
 cc = next_opcode(common, cc);  
 SLJIT_ASSERT(cc != NULL);  
 while (cc < ccend)  
   switch(*cc)  
     {  
     case OP_SET_SOM:  
     SLJIT_ASSERT(common->has_set_som);  
     if (!setsom_found)  
       {  
       length += 2;  
       setsom_found = TRUE;  
       }  
     cc += 1;  
1268      break;      break;
1269    
1270      case OP_MARK:      case OP_MARK:
1271        case OP_PRUNE_ARG:
1272        case OP_THEN_ARG:
1273      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1274        stack_restore = TRUE;
1275      if (!setmark_found)      if (!setmark_found)
1276        {        {
1277        length += 2;        length += 2;
1278        setmark_found = TRUE;        setmark_found = TRUE;
1279        }        }
1280        if (common->control_head_ptr != 0)
1281          *needs_control_head = TRUE;
1282      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1283      break;      break;
1284    
1285      case OP_RECURSE:      case OP_RECURSE:
1286        stack_restore = TRUE;
1287      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1288        {        {
1289        length += 2;        length += 2;
# Line 1150  while (cc < ccend) Line 1294  while (cc < ccend)
1294        length += 2;        length += 2;
1295        setmark_found = TRUE;        setmark_found = TRUE;
1296        }        }
1297        if (common->capture_last_ptr != 0 && !capture_last_found)
1298          {
1299          length += 2;
1300          capture_last_found = TRUE;
1301          }
1302      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1303      break;      break;
1304    
# Line 1157  while (cc < ccend) Line 1306  while (cc < ccend)
1306      case OP_CBRAPOS:      case OP_CBRAPOS:
1307      case OP_SCBRA:      case OP_SCBRA:
1308      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1309        stack_restore = TRUE;
1310        if (common->capture_last_ptr != 0 && !capture_last_found)
1311          {
1312          length += 2;
1313          capture_last_found = TRUE;
1314          }
1315      length += 3;      length += 3;
1316      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1317      break;      break;
1318    
1319      default:      default:
1320        stack_restore = TRUE;
1321        /* Fall through. */
1322    
1323        case OP_NOT_WORD_BOUNDARY:
1324        case OP_WORD_BOUNDARY:
1325        case OP_NOT_DIGIT:
1326        case OP_DIGIT:
1327        case OP_NOT_WHITESPACE:
1328        case OP_WHITESPACE:
1329        case OP_NOT_WORDCHAR:
1330        case OP_WORDCHAR:
1331        case OP_ANY:
1332        case OP_ALLANY:
1333        case OP_ANYBYTE:
1334        case OP_NOTPROP:
1335        case OP_PROP:
1336        case OP_ANYNL:
1337        case OP_NOT_HSPACE:
1338        case OP_HSPACE:
1339        case OP_NOT_VSPACE:
1340        case OP_VSPACE:
1341        case OP_EXTUNI:
1342        case OP_EODN:
1343        case OP_EOD:
1344        case OP_CIRC:
1345        case OP_CIRCM:
1346        case OP_DOLL:
1347        case OP_DOLLM:
1348        case OP_CHAR:
1349        case OP_CHARI:
1350        case OP_NOT:
1351        case OP_NOTI:
1352    
1353        case OP_EXACT:
1354        case OP_POSSTAR:
1355        case OP_POSPLUS:
1356        case OP_POSQUERY:
1357        case OP_POSUPTO:
1358    
1359        case OP_EXACTI:
1360        case OP_POSSTARI:
1361        case OP_POSPLUSI:
1362        case OP_POSQUERYI:
1363        case OP_POSUPTOI:
1364    
1365        case OP_NOTEXACT:
1366        case OP_NOTPOSSTAR:
1367        case OP_NOTPOSPLUS:
1368        case OP_NOTPOSQUERY:
1369        case OP_NOTPOSUPTO:
1370    
1371        case OP_NOTEXACTI:
1372        case OP_NOTPOSSTARI:
1373        case OP_NOTPOSPLUSI:
1374        case OP_NOTPOSQUERYI:
1375        case OP_NOTPOSUPTOI:
1376    
1377        case OP_TYPEEXACT:
1378        case OP_TYPEPOSSTAR:
1379        case OP_TYPEPOSPLUS:
1380        case OP_TYPEPOSQUERY:
1381        case OP_TYPEPOSUPTO:
1382    
1383        case OP_CLASS:
1384        case OP_NCLASS:
1385        case OP_XCLASS:
1386    
1387      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1388      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1389      break;      break;
1390      }      }
1391    
1392  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1393  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1394    return -1;    return stack_restore ? no_frame : no_stack;
1395    
1396  if (length > 0)  if (length > 0)
1397    return length + 1;    return length + 1;
1398  return -1;  return stack_restore ? no_frame : no_stack;
1399  }  }
1400    
1401  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)
1402  {  {
1403  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1404  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1405  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1406    /* The last capture is a local variable even for recursions. */
1407    BOOL capture_last_found = FALSE;
1408  int offset;  int offset;
1409    
1410  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1189  SLJIT_UNUSED_ARG(stacktop); Line 1412  SLJIT_UNUSED_ARG(stacktop);
1412  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1413    
1414  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1415  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1416    cc = next_opcode(common, cc);    {
1417      ccend = bracketend(cc) - (1 + LINK_SIZE);
1418      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1419        cc = next_opcode(common, cc);
1420      }
1421    
1422  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1423  while (cc < ccend)  while (cc < ccend)
1424    switch(*cc)    switch(*cc)
# Line 1199  while (cc < ccend) Line 1427  while (cc < ccend)
1427      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1428      if (!setsom_found)      if (!setsom_found)
1429        {        {
1430        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0));
1431        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1432        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1433        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1434        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1210  while (cc < ccend) Line 1438  while (cc < ccend)
1438      break;      break;
1439    
1440      case OP_MARK:      case OP_MARK:
1441        case OP_PRUNE_ARG:
1442        case OP_THEN_ARG:
1443      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1444      if (!setmark_found)      if (!setmark_found)
1445        {        {
1446        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr);
1447        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);
1448        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1449        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1450        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1226  while (cc < ccend) Line 1456  while (cc < ccend)
1456      case OP_RECURSE:      case OP_RECURSE:
1457      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1458        {        {
1459        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0));
1460        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1461        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1462        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1463        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1235  while (cc < ccend) Line 1465  while (cc < ccend)
1465        }        }
1466      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1467        {        {
1468        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr);
1469        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);
1470        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1471        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1472        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1473        setmark_found = TRUE;        setmark_found = TRUE;
1474        }        }
1475        if (common->capture_last_ptr != 0 && !capture_last_found)
1476          {
1477          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr);
1478          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1479          stackpos += (int)sizeof(sljit_sw);
1480          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1481          stackpos += (int)sizeof(sljit_sw);
1482          capture_last_found = TRUE;
1483          }
1484      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1485      break;      break;
1486    
# Line 1249  while (cc < ccend) Line 1488  while (cc < ccend)
1488      case OP_CBRAPOS:      case OP_CBRAPOS:
1489      case OP_SCBRA:      case OP_SCBRA:
1490      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1491        if (common->capture_last_ptr != 0 && !capture_last_found)
1492          {
1493          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr);
1494          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1495          stackpos += (int)sizeof(sljit_sw);
1496          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1497          stackpos += (int)sizeof(sljit_sw);
1498          capture_last_found = TRUE;
1499          }
1500      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1501      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1502      stackpos += (int)sizeof(sljit_sw);      stackpos += (int)sizeof(sljit_sw);
1503      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset));
1504      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset + 1));
1505      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1506      stackpos += (int)sizeof(sljit_sw);      stackpos += (int)sizeof(sljit_sw);
1507      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
# Line 1268  while (cc < ccend) Line 1516  while (cc < ccend)
1516      break;      break;
1517      }      }
1518    
1519  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1520  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1521  }  }
1522    
1523  static SLJIT_INLINE int get_private_data_length_for_copy(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)
1524  {  {
1525  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1526  int size;  int size;
1527  pcre_uchar *alternative;  pcre_uchar *alternative;
1528  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1283  while (cc < ccend) Line 1531  while (cc < ccend)
1531    size = 0;    size = 0;
1532    switch(*cc)    switch(*cc)
1533      {      {
1534        case OP_KET:
1535        if (PRIVATE_DATA(cc) != 0)
1536          {
1537          private_data_length++;
1538          SLJIT_ASSERT(PRIVATE_DATA(cc + 1) != 0);
1539          cc += PRIVATE_DATA(cc + 1);
1540          }
1541        cc += 1 + LINK_SIZE;
1542        break;
1543    
1544      case OP_ASSERT:      case OP_ASSERT:
1545      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1546      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1294  while (cc < ccend) Line 1552  while (cc < ccend)
1552      case OP_SBRAPOS:      case OP_SBRAPOS:
1553      case OP_SCOND:      case OP_SCOND:
1554      private_data_length++;      private_data_length++;
1555        SLJIT_ASSERT(PRIVATE_DATA(cc) != 0);
1556      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1557      break;      break;
1558    
# Line 1387  return private_data_length; Line 1646  return private_data_length;
1646  }  }
1647    
1648  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,
1649    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1650  {  {
1651  DEFINE_COMPILER;  DEFINE_COMPILER;
1652  int srcw[2];  int srcw[2];
# Line 1408  stacktop = STACK(stacktop - 1); Line 1667  stacktop = STACK(stacktop - 1);
1667    
1668  if (!save)  if (!save)
1669    {    {
1670    stackptr += sizeof(sljit_sw);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1671    if (stackptr < stacktop)    if (stackptr < stacktop)
1672      {      {
1673      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
# Line 1424  if (!save) Line 1683  if (!save)
1683    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1684    }    }
1685    
1686  while (status != end)  do
1687    {    {
1688    count = 0;    count = 0;
1689    switch(status)    switch(status)
1690      {      {
1691      case start:      case start:
1692      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1693      count = 1;      count = 1;
1694      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1695        if (needs_control_head)
1696          {
1697          SLJIT_ASSERT(common->control_head_ptr != 0);
1698          count = 2;
1699          srcw[1] = common->control_head_ptr;
1700          }
1701      status = loop;      status = loop;
1702      break;      break;
1703    
# Line 1445  while (status != end) Line 1710  while (status != end)
1710    
1711      switch(*cc)      switch(*cc)
1712        {        {
1713          case OP_KET:
1714          if (PRIVATE_DATA(cc) != 0)
1715            {
1716            count = 1;
1717            srcw[0] = PRIVATE_DATA(cc);
1718            SLJIT_ASSERT(PRIVATE_DATA(cc + 1) != 0);
1719            cc += PRIVATE_DATA(cc + 1);
1720            }
1721          cc += 1 + LINK_SIZE;
1722          break;
1723    
1724        case OP_ASSERT:        case OP_ASSERT:
1725        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1726        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1612  while (status != end) Line 1888  while (status != end)
1888            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1889            stackptr += sizeof(sljit_sw);            stackptr += sizeof(sljit_sw);
1890            }            }
1891          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), srcw[count]);
1892          tmp1empty = FALSE;          tmp1empty = FALSE;
1893          tmp1next = FALSE;          tmp1next = FALSE;
1894          }          }
# Line 1623  while (status != end) Line 1899  while (status != end)
1899            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1900            stackptr += sizeof(sljit_sw);            stackptr += sizeof(sljit_sw);
1901            }            }
1902          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), srcw[count]);
1903          tmp2empty = FALSE;          tmp2empty = FALSE;
1904          tmp1next = TRUE;          tmp1next = TRUE;
1905          }          }
# Line 1633  while (status != end) Line 1909  while (status != end)
1909        if (tmp1next)        if (tmp1next)
1910          {          {
1911          SLJIT_ASSERT(!tmp1empty);          SLJIT_ASSERT(!tmp1empty);
1912          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count], TMP1, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), srcw[count], TMP1, 0);
1913          tmp1empty = stackptr >= stacktop;          tmp1empty = stackptr >= stacktop;
1914          if (!tmp1empty)          if (!tmp1empty)
1915            {            {
# Line 1645  while (status != end) Line 1921  while (status != end)
1921        else        else
1922          {          {
1923          SLJIT_ASSERT(!tmp2empty);          SLJIT_ASSERT(!tmp2empty);
1924          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count], TMP2, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), srcw[count], TMP2, 0);
1925          tmp2empty = stackptr >= stacktop;          tmp2empty = stackptr >= stacktop;
1926          if (!tmp2empty)          if (!tmp2empty)
1927            {            {
# Line 1657  while (status != end) Line 1933  while (status != end)
1933        }        }
1934      }      }
1935    }    }
1936    while (status != end);
1937    
1938  if (save)  if (save)
1939    {    {
# Line 1690  if (save) Line 1967  if (save)
1967  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1968  }  }
1969    
1970    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1971    {
1972    pcre_uchar *end = bracketend(cc);
1973    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1974    
1975    /* Assert captures then. */
1976    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1977      current_offset = NULL;
1978    /* Conditional block does not. */
1979    if (*cc == OP_COND || *cc == OP_SCOND)
1980      has_alternatives = FALSE;
1981    
1982    cc = next_opcode(common, cc);
1983    if (has_alternatives)
1984      current_offset = common->then_offsets + (cc - common->start);
1985    
1986    while (cc < end)
1987      {
1988      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1989        cc = set_then_offsets(common, cc, current_offset);
1990      else
1991        {
1992        if (*cc == OP_ALT && has_alternatives)
1993          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1994        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1995          *current_offset = 1;
1996        cc = next_opcode(common, cc);
1997        }
1998      }
1999    
2000    return end;
2001    }
2002    
2003  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
2004  #undef CASE_ITERATOR_PRIVATE_DATA_2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
2005  #undef CASE_ITERATOR_PRIVATE_DATA_2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
# Line 1708  while (list) Line 2018  while (list)
2018    {    {
2019    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
2020    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
2021    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
2022    list = list->next;    list = list->next;
2023    }    }
2024  }  }
2025    
2026  static SLJIT_INLINE void add_jump(struct sljit_compiler *compiler, jump_list **list, struct sljit_jump* jump)  static SLJIT_INLINE void add_jump(struct sljit_compiler *compiler, jump_list **list, struct sljit_jump *jump)
2027  {  {
2028  jump_list *list_item = sljit_alloc_memory(compiler, sizeof(jump_list));  jump_list *list_item = sljit_alloc_memory(compiler, sizeof(jump_list));
2029  if (list_item)  if (list_item)
# Line 1724  if (list_item) Line 2034  if (list_item)
2034    }    }
2035  }  }
2036    
2037  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)
2038  {  {
2039  DEFINE_COMPILER;  DEFINE_COMPILER;
2040  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list *list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
2041    
2042  if (list_item)  if (list_item)
2043    {    {
   list_item->type = type;  
   list_item->data = data;  
2044    list_item->start = start;    list_item->start = start;
2045    list_item->quit = LABEL();    list_item->quit = LABEL();
2046    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1743  if (list_item) Line 2051  if (list_item)
2051  static void flush_stubs(compiler_common *common)  static void flush_stubs(compiler_common *common)
2052  {  {
2053  DEFINE_COMPILER;  DEFINE_COMPILER;
2054  stub_list* list_item = common->stubs;  stub_list *list_item = common->stubs;
2055    
2056  while (list_item)  while (list_item)
2057    {    {
2058    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2059    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;  
     }  
2060    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2061    list_item = list_item->next;    list_item = list_item->next;
2062    }    }
2063  common->stubs = NULL;  common->stubs = NULL;
2064  }  }
2065    
2066  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static void add_label_addr(compiler_common *common, sljit_uw *update_addr)
2067  {  {
2068  DEFINE_COMPILER;  DEFINE_COMPILER;
2069    label_addr_list *label_addr;
2070    
2071  OP2(SLJIT_SUB | SLJIT_SET_E, CALL_COUNT, 0, CALL_COUNT, 0, SLJIT_IMM, 1);  label_addr = sljit_alloc_memory(compiler, sizeof(label_addr_list));
2072  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  if (label_addr == NULL)
2073      return;
2074    label_addr->label = LABEL();
2075    label_addr->update_addr = update_addr;
2076    label_addr->next = common->label_addrs;
2077    common->label_addrs = label_addr;
2078  }  }
2079    
2080  static SLJIT_INLINE void allocate_stack(compiler_common *common, int size)  static SLJIT_INLINE void count_match(compiler_common *common)
2081    {
2082    DEFINE_COMPILER;
2083    
2084    OP2(SLJIT_SUB | SLJIT_SET_E, COUNT_MATCH, 0, COUNT_MATCH, 0, SLJIT_IMM, 1);
2085    add_jump(compiler, &common->calllimit, JUMP(SLJIT_ZERO));
2086    }
2087    
2088    static SLJIT_INLINE void allocate_stack(compiler_common *common, int size)
2089  {  {
2090  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2091  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1778  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, Line 2095  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP,
2095  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2096  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
2097  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2098  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS0, TMP1, 0);
2099  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, TMP1, 0);
2100  #endif  #endif
2101  add_stub(common, stack_alloc, 0, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));  add_stub(common, CMP(SLJIT_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));
2102  }  }
2103    
2104  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
# Line 1790  DEFINE_COMPILER; Line 2107  DEFINE_COMPILER;
2107  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
2108  }  }
2109    
2110    static sljit_uw * allocate_read_only_data(compiler_common *common, sljit_uw size)
2111    {
2112    DEFINE_COMPILER;
2113    sljit_uw *result;
2114    
2115    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
2116      return NULL;
2117    
2118    result = (sljit_uw *)SLJIT_MALLOC(size + sizeof(sljit_uw), compiler->allocator_data);
2119    if (SLJIT_UNLIKELY(result == NULL))
2120      {
2121      sljit_set_compiler_memory_error(compiler);
2122      return NULL;
2123      }
2124    
2125    *(void**)result = common->read_only_data_head;
2126    common->read_only_data_head = (void *)result;
2127    return result + 1;
2128    }
2129    
2130    static void free_read_only_data(void *current, void *allocator_data)
2131    {
2132    void *next;
2133    
2134    SLJIT_UNUSED_ARG(allocator_data);
2135    
2136    while (current != NULL)
2137      {
2138      next = *(void**)current;
2139      SLJIT_FREE(current, allocator_data);
2140      current = next;
2141      }
2142    }
2143    
2144  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
2145  {  {
2146  DEFINE_COMPILER;  DEFINE_COMPILER;
2147  struct sljit_label *loop;  struct sljit_label *loop;
2148  int i;  int i;
2149    
2150  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2151    SLJIT_ASSERT(length > 1);
2152  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2153  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
2154    if (length < 8)
2155      {
2156      for (i = 1; i < length; i++)
2157        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(i), SLJIT_R0, 0);
2158      }
2159    else
2160      {
2161      GET_LOCAL_BASE(SLJIT_R1, 0, OVECTOR_START);
2162      OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, length - 1);
2163      loop = LABEL();
2164      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_sw), SLJIT_R0, 0);
2165      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, 1);
2166      JUMPTO(SLJIT_NOT_ZERO, loop);
2167      }
2168    }
2169    
2170    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2171    {
2172    DEFINE_COMPILER;
2173    struct sljit_label *loop;
2174    int i;
2175    
2176    SLJIT_ASSERT(length > 1);
2177    /* OVECTOR(1) contains the "string begin - 1" constant. */
2178    if (length > 2)
2179      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1));
2180  if (length < 8)  if (length < 8)
2181    {    {
2182    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
2183      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(i), TMP1, 0);
2184    }    }
2185  else  else
2186    {    {
2187    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START - sizeof(sljit_sw));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2188    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2189    loop = LABEL();    loop = LABEL();
2190    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2191    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
2192    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_NOT_ZERO, loop);
2193      }
2194    
2195    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2196    if (common->mark_ptr != 0)
2197      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->mark_ptr, SLJIT_IMM, 0);
2198    if (common->control_head_ptr != 0)
2199      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr, SLJIT_IMM, 0);
2200    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2201    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->start_ptr);
2202    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2203    }
2204    
2205    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2206    {
2207    while (current != NULL)
2208      {
2209      switch (current[-2])
2210        {
2211        case type_then_trap:
2212        break;
2213    
2214        case type_mark:
2215        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2216          return current[-4];
2217        break;
2218    
2219        default:
2220        SLJIT_ASSERT_STOP();
2221        break;
2222        }
2223      current = (sljit_sw*)current[-1];
2224    }    }
2225    return -1;
2226  }  }
2227    
2228  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2229  {  {
2230  DEFINE_COMPILER;  DEFINE_COMPILER;
2231  struct sljit_label *loop;  struct sljit_label *loop;
2232  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2233    
2234  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2235  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  OP1(SLJIT_MOV, SLJIT_S2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1));
2236  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(1), STR_PTR, 0);
2237    
2238  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_R0, 0, ARGUMENTS, 0);
2239  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2240    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);    OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_SP), common->mark_ptr);
2241  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));  OP1(SLJIT_MOV_SI, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, offset_count));
2242  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2243    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_R2, 0);
2244  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));  OP2(SLJIT_SUB, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
2245  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_OFFSETOF(jit_arguments, begin));
2246  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_S0, 0, OVECTOR_START);
2247  /* Unlikely, but possible */  /* Unlikely, but possible */
2248  earlyexit = CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);  early_quit = CMP(SLJIT_EQUAL, SLJIT_R1, 0, SLJIT_IMM, 0);
2249  loop = LABEL();  loop = LABEL();
2250  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);  OP2(SLJIT_SUB, SLJIT_S1, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
2251  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));  OP2(SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, sizeof(sljit_sw));
2252  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2253  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2254  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);  OP2(SLJIT_ASHR, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, UCHAR_SHIFT);
2255  #endif  #endif
2256  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_R2), sizeof(int), SLJIT_S1, 0);
2257  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1);
2258  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_NOT_ZERO, loop);
2259  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2260    
2261  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2262  if (topbracket > 1)  if (topbracket > 1)
2263    {    {
2264    GET_LOCAL_BASE(SLJIT_SCRATCH_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));    GET_LOCAL_BASE(SLJIT_R0, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));
2265    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, topbracket + 1);
2266    
2267    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_S2. */
2268    loop = LABEL();    loop = LABEL();
2269    OP1(SLJIT_MOVU, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), -(2 * (sljit_sw)sizeof(sljit_sw)));    OP1(SLJIT_MOVU, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_R0), -(2 * (sljit_sw)sizeof(sljit_sw)));
2270    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1);
2271    CMPTO(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG3, 0, loop);    CMPTO(SLJIT_EQUAL, SLJIT_R2, 0, SLJIT_S2, 0, loop);
2272    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_R1, 0);
2273    }    }
2274  else  else
2275    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1867  else Line 2278  else
2278  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)
2279  {  {
2280  DEFINE_COMPILER;  DEFINE_COMPILER;
2281    struct sljit_jump *jump;
2282    
2283  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_S1, str_end_must_be_saved_reg2);
2284  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
2285      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2286    
2287  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_R1, 0, ARGUMENTS, 0);
2288  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2289  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsetcount));  OP1(SLJIT_MOV_SI, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_R1), SLJIT_OFFSETOF(jit_arguments, real_offset_count));
2290  CMPTO(SLJIT_C_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);  CMPTO(SLJIT_SIG_LESS, SLJIT_R2, 0, SLJIT_IMM, 2, quit);
2291    
2292  /* Store match begin and end. */  /* Store match begin and end. */
2293  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_S0, 0, SLJIT_MEM1(SLJIT_R1), SLJIT_OFFSETOF(jit_arguments, begin));
2294  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));  OP1(SLJIT_MOV, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R1), SLJIT_OFFSETOF(jit_arguments, offsets));
2295  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);  
2296  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);  jump = CMP(SLJIT_SIG_LESS, SLJIT_R2, 0, SLJIT_IMM, 3);
2297    OP2(SLJIT_SUB, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_SP), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + (int)sizeof(sljit_sw)), SLJIT_S0, 0);
2298    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2299    OP2(SLJIT_ASHR, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, UCHAR_SHIFT);
2300    #endif
2301    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_R1), 2 * sizeof(int), SLJIT_R2, 0);
2302    JUMPHERE(jump);
2303    
2304    OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_SP), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);
2305    OP2(SLJIT_SUB, SLJIT_S1, 0, STR_END, 0, SLJIT_S0, 0);
2306  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2307  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);  OP2(SLJIT_ASHR, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, UCHAR_SHIFT);
2308  #endif  #endif
2309  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_R1), sizeof(int), SLJIT_S1, 0);
2310    
2311  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_S0, 0);
2312  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2313  OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);  OP2(SLJIT_ASHR, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, UCHAR_SHIFT);
2314  #endif  #endif
2315  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0, SLJIT_SCRATCH_REG3, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_R1), 0, SLJIT_R2, 0);
2316    
2317  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2318  }  }
# Line 1904  struct sljit_jump *jump; Line 2326  struct sljit_jump *jump;
2326  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2327    {    {
2328    /* The value of -1 must be kept for start_used_ptr! */    /* The value of -1 must be kept for start_used_ptr! */
2329    OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, 1);    OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, SLJIT_IMM, 1);
2330    /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting    /* Jumps if start_used_ptr < STR_PTR, or start_used_ptr == -1. Although overwriting
2331    is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */    is not necessary if start_used_ptr == STR_PTR, it does not hurt as well. */
2332    jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, STR_PTR, 0);    jump = CMP(SLJIT_LESS_EQUAL, TMP1, 0, STR_PTR, 0);
2333    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0);
2334    JUMPHERE(jump);    JUMPHERE(jump);
2335    }    }
2336  else if (common->mode == JIT_PARTIAL_HARD_COMPILE)  else if (common->mode == JIT_PARTIAL_HARD_COMPILE)
2337    {    {
2338    jump = CMP(SLJIT_C_LESS_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    jump = CMP(SLJIT_LESS_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0);
2339    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0);
2340    JUMPHERE(jump);    JUMPHERE(jump);
2341    }    }
2342  }  }
2343    
2344  static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar* cc)  static SLJIT_INLINE BOOL char_has_othercase(compiler_common *common, pcre_uchar *cc)
2345  {  {
2346  /* Detects if the character has an othercase. */  /* Detects if the character has an othercase. */
2347  unsigned int c;  unsigned int c;
# Line 1962  if (common->utf && c > 127) Line 2384  if (common->utf && c > 127)
2384  return TABLE_GET(c, common->fcc, c);  return TABLE_GET(c, common->fcc, c);
2385  }  }
2386    
2387  static unsigned int char_get_othercase_bit(compiler_common *common, pcre_uchar* cc)  static unsigned int char_get_othercase_bit(compiler_common *common, pcre_uchar *cc)
2388  {  {
2389  /* Detects if the character and its othercase has only 1 bit difference. */  /* Detects if the character and its othercase has only 1 bit difference. */
2390  unsigned int c, oc, bit;  unsigned int c, oc, bit;
# Line 2040  return (bit < 256) ? ((0 << 8) | bit) : Line 2462  return (bit < 256) ? ((0 << 8) | bit) :
2462    
2463  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2464  {  {
2465  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2466  DEFINE_COMPILER;  DEFINE_COMPILER;
2467  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2468    
# Line 2050  if (common->mode == JIT_COMPILE) Line 2472  if (common->mode == JIT_COMPILE)
2472    return;    return;
2473    
2474  if (!force)  if (!force)
2475    jump = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    jump = CMP(SLJIT_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0);
2476  else if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  else if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2477    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);    jump = CMP(SLJIT_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, SLJIT_IMM, -1);
2478    
2479  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2480    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0);
2481  else  else
2482    {    {
2483    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2068  if (jump != NULL) Line 2490  if (jump != NULL)
2490    JUMPHERE(jump);    JUMPHERE(jump);
2491  }  }
2492    
2493  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2494  {  {
2495  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2496  DEFINE_COMPILER;  DEFINE_COMPILER;
2497  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2498    
2499  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2500    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2501      add_jump(compiler, end_reached, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2502      return;
2503      }
2504    
2505  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_LESS, STR_PTR, 0, STR_END, 0);
2506  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2507    {    {
2508    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_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0));
2509    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0);
2510    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2511    }    }
2512  else  else
2513    {    {
2514    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_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0));
2515    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2516      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2517    else    else
2518      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2519    }    }
2520  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2521  }  }
2522    
2523  static void detect_partial_match(compiler_common *common, jump_list **backtracks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
# Line 2106  struct sljit_jump *jump; Line 2527  struct sljit_jump *jump;
2527    
2528  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2529    {    {
2530    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));    add_jump(compiler, backtracks, CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2531    return;    return;
2532    }    }
2533    
2534  /* Partial matching mode. */  /* Partial matching mode. */
2535  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_LESS, STR_PTR, 0, STR_END, 0);
2536  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_GREATER_EQUAL, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0));
2537  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2538    {    {
2539    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0);
2540    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2541    }    }
2542  else  else
# Line 2128  else Line 2549  else
2549  JUMPHERE(jump);  JUMPHERE(jump);
2550  }  }
2551    
2552  static void read_char(compiler_common *common)  static void peek_char(compiler_common *common, pcre_uint32 max)
2553  {  {
2554  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2555  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2556  DEFINE_COMPILER;  DEFINE_COMPILER;
2557  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2558  struct sljit_jump *jump;  struct sljit_jump *jump;
2559  #endif  #endif
2560    
2561    SLJIT_UNUSED_ARG(max);
2562    
2563  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2564  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2565  if (common->utf)  if (common->utf)
2566    {    {
2567  #if defined COMPILE_PCRE8    if (max < 128) return;
2568    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);  
2569  #elif defined COMPILE_PCRE16    jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2570    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 #endif /* COMPILE_PCRE[8|16] */  
2571    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2572      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2573    JUMPHERE(jump);    JUMPHERE(jump);
2574    }    }
2575  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2576    
2577    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2578    if (common->utf)
2579      {
2580      if (max < 0xd800) return;
2581    
2582      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2583      jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2584      /* TMP2 contains the high surrogate. */
2585      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2586      OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2587      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2588      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2589      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2590      JUMPHERE(jump);
2591      }
2592    #endif
2593    }
2594    
2595    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2596    
2597    static BOOL is_char7_bitset(const pcre_uint8 *bitset, BOOL nclass)
2598    {
2599    /* Tells whether the character codes below 128 are enough
2600    to determine a match. */
2601    const pcre_uint8 value = nclass ? 0xff : 0;
2602    const pcre_uint8 *end = bitset + 32;
2603    
2604    bitset += 16;
2605    do
2606      {
2607      if (*bitset++ != value)
2608        return FALSE;
2609      }
2610    while (bitset < end);
2611    return TRUE;
2612    }
2613    
2614    static void read_char7_type(compiler_common *common, BOOL full_read)
2615    {
2616    /* Reads the precise character type of a character into TMP1, if the character
2617    is less than 128. Otherwise it returns with zero. Does not check STR_END. The
2618    full_read argument tells whether characters above max are accepted or not. */
2619    DEFINE_COMPILER;
2620    struct sljit_jump *jump;
2621    
2622    SLJIT_ASSERT(common->utf);
2623    
2624    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2625  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));
2626    
2627    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2628    
2629    if (full_read)
2630      {
2631      jump = CMP(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2632      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2633      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2634      JUMPHERE(jump);
2635      }
2636  }  }
2637    
2638  static void peek_char(compiler_common *common)  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2639    
2640    static void read_char_range(compiler_common *common, pcre_uint32 min, pcre_uint32 max, BOOL update_str_ptr)
2641  {  {
2642  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the precise value of a character into TMP1, if the character is
2643  Does not check STR_END. TMP2 Destroyed. */  between min and max (c >= min && c <= max). Otherwise it returns with a value
2644    outside the range. Does not check STR_END. */
2645  DEFINE_COMPILER;  DEFINE_COMPILER;
2646  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2647  struct sljit_jump *jump;  struct sljit_jump *jump;
2648  #endif  #endif
2649    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2650    struct sljit_jump *jump2;
2651    #endif
2652    
2653  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  SLJIT_UNUSED_ARG(update_str_ptr);
2654  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  SLJIT_UNUSED_ARG(min);
2655    SLJIT_UNUSED_ARG(max);
2656    SLJIT_ASSERT(min <= max);
2657    
2658    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2659    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2660    
2661    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2662  if (common->utf)  if (common->utf)
2663    {    {
2664  #if defined COMPILE_PCRE8    if (max < 128 && !update_str_ptr) return;
2665    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);  
2666  #elif defined COMPILE_PCRE16    jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2667    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    if (min >= 0x10000)
2668  #endif /* COMPILE_PCRE[8|16] */      {
2669    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xf0);
2670    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);      if (update_str_ptr)
2671          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2672        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2673        jump2 = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0x7);
2674        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2675        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2676        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2677        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2678        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2679        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2680        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2681        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2682        if (!update_str_ptr)
2683          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2684        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2685        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2686        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2687        JUMPHERE(jump2);
2688        if (update_str_ptr)
2689          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2690        }
2691      else if (min >= 0x800 && max <= 0xffff)
2692        {
2693        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xe0);
2694        if (update_str_ptr)
2695          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2696        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2697        jump2 = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xf);
2698        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2699        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2700        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2701        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2702        if (!update_str_ptr)
2703          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2704        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2705        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2706        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2707        JUMPHERE(jump2);
2708        if (update_str_ptr)
2709          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2710        }
2711      else if (max >= 0x800)
2712        add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2713      else if (max < 128)
2714        {
2715        OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2716        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2717        }
2718      else
2719        {
2720        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2721        if (!update_str_ptr)
2722          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2723        else
2724          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2725        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2726        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2727        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2728        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2729        if (update_str_ptr)
2730          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2731        }
2732    JUMPHERE(jump);    JUMPHERE(jump);
2733    }    }
2734  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  #endif
2735    
2736    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2737    if (common->utf)
2738      {
2739      if (max >= 0x10000)
2740        {
2741        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2742        jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2743        /* TMP2 contains the high surrogate. */
2744        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2745        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2746        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2747        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2748        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2749        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2750        JUMPHERE(jump);
2751        return;
2752        }
2753    
2754      if (max < 0xd800 && !update_str_ptr) return;
2755    
2756      /* Skip low surrogate if necessary. */
2757      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2758      jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2759      if (update_str_ptr)
2760        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2761      if (max >= 0xd800)
2762        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);
2763      JUMPHERE(jump);
2764      }
2765    #endif
2766    }
2767    
2768    static SLJIT_INLINE void read_char(compiler_common *common)
2769    {
2770    read_char_range(common, 0, READ_CHAR_MAX, TRUE);
2771  }  }
2772    
2773  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common, BOOL update_str_ptr)
2774  {  {
2775  /* 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. */
2776  DEFINE_COMPILER;  DEFINE_COMPILER;
2777  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2778  struct sljit_jump *jump;  struct sljit_jump *jump;
2779  #endif  #endif
2780    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2781    struct sljit_jump *jump2;
2782    #endif
2783    
2784  #ifdef SUPPORT_UTF  SLJIT_UNUSED_ARG(update_str_ptr);
2785    
2786    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2787    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2788    
2789    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2790  if (common->utf)  if (common->utf)
2791    {    {
   OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 #if defined COMPILE_PCRE8  
2792    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2793    it is needed in most cases. */    it is needed in most cases. */
2794    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2795    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2796    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    if (!update_str_ptr)
2797    JUMPHERE(jump);      {
2798  #elif defined COMPILE_PCRE16      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2799    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2800    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2801    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2802    JUMPHERE(jump);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2803    /* Skip low surrogate if necessary. */      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
2804    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2805    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);      jump2 = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 255);
2806    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2807    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);      JUMPHERE(jump2);
2808    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);      }
2809  #elif defined COMPILE_PCRE32    else
2810    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);      add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
   jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  
2811    JUMPHERE(jump);    JUMPHERE(jump);
 #endif /* COMPILE_PCRE[8|16|32] */  
2812    return;    return;
2813    }    }
2814  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2815  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
2816  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  #if !defined COMPILE_PCRE8
 #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  
2817  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2818  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2819  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 255);
2820  #endif  #endif
2821  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2822  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if !defined COMPILE_PCRE8
2823  JUMPHERE(jump);  JUMPHERE(jump);
2824  #endif  #endif
2825    
2826    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2827    if (common->utf && update_str_ptr)
2828      {
2829      /* Skip low surrogate if necessary. */
2830      OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2831      jump = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2832      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2833      JUMPHERE(jump);
2834      }
2835    #endif /* SUPPORT_UTF && COMPILE_PCRE16 */
2836  }  }
2837    
2838  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
# Line 2245  if (common->utf) Line 2849  if (common->utf)
2849    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
2850    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));
2851    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xc0);
2852    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2853    return;    return;
2854    }    }
2855  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
# Line 2256  if (common->utf) Line 2860  if (common->utf)
2860    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2861    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2862    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);
2863    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_EQUAL);
2864    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2865    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2866    return;    return;
# Line 2266  if (common->utf) Line 2870  if (common->utf)
2870  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));
2871  }  }
2872    
2873  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)
2874  {  {
2875  /* 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. */
2876  DEFINE_COMPILER;  DEFINE_COMPILER;
2877    struct sljit_jump *jump;
2878    
2879  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2880    {    {
2881    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2882    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpifmatch ? SLJIT_NOT_ZERO : SLJIT_ZERO));
2883    }    }
2884  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2885    {    {
2886    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    if (jumpifmatch)
2887    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);      {
2888    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);      add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR));
2889    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);      add_jump(compiler, backtracks, CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2890    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));      }
2891      else
2892        {
2893        jump = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
2894        add_jump(compiler, backtracks, CMP(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2895        JUMPHERE(jump);
2896        }
2897    }    }
2898  else  else
2899    {    {
2900    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2901    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_EQUAL : SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
2902    }    }
2903  }  }
2904    
# Line 2297  else Line 2908  else
2908  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2909  {  {
2910  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2911  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. */
2912  DEFINE_COMPILER;  DEFINE_COMPILER;
2913  struct sljit_jump *jump;  struct sljit_jump *jump;
2914    
2915  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2916  /* Searching for the first zero. */  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2917  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
 jump = JUMP(SLJIT_C_NOT_ZERO);  
 /* Two byte sequence. */  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  
2918  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2919  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2920  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2921  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  
2922    /* Searching for the first zero. */
2923    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2924    jump = JUMP(SLJIT_NOT_ZERO);
2925    /* Two byte sequence. */
2926    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2927    OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2928  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2929    
2930  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);  JUMPHERE(jump);
 jump = JUMP(SLJIT_C_NOT_ZERO);  
 /* Three byte sequence. */  
2931  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2932  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2933  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2934  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);  
2935  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2936  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  
2937    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2938    jump = JUMP(SLJIT_NOT_ZERO);
2939    /* Three byte sequence. */
2940  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));
2941  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));  
2942  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2943    
2944  /* Four byte sequence. */  /* Four byte sequence. */
2945  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  JUMPHERE(jump);
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
2946  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2947  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2948  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));  
2949  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2950  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2951  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2952  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(4));
2953  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2954  }  }
2955    
2956  static void do_utfreadtype8(compiler_common *common)  static void do_utfreadchar16(compiler_common *common)
2957  {  {
2958  /* Fast decoding a UTF-8 character type. TMP2 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2959  of the character (>= 0xc0). Return value in TMP1. */  of the character (>= 0xc0). Return value in TMP1. */
2960  DEFINE_COMPILER;  DEFINE_COMPILER;
2961  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *compare;  
2962    
2963  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2964    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2965    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2966    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2967    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2968    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2969    
2970  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20);  /* Searching for the first zero. */
2971  jump = JUMP(SLJIT_C_NOT_ZERO);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2972    jump = JUMP(SLJIT_NOT_ZERO);
2973  /* Two byte sequence. */  /* Two byte sequence. */
 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  
2974  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));
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);  
 compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  
 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  
2975  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2976    
 JUMPHERE(compare);  
 OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
2977  JUMPHERE(jump);  JUMPHERE(jump);
2978    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x400);
2979  /* We only have types for characters less than 256. */  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_NOT_ZERO);
2980  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);  /* This code runs only in 8 bit mode. No need to shift the value. */
2981  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2982  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2983    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2984    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2985    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2986    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2987    /* Three byte sequence. */
2988    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2989  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2990  }  }
2991    
2992  #elif defined COMPILE_PCRE16  static void do_utfreadtype8(compiler_common *common)
   
 static void do_utfreadchar(compiler_common *common)  
2993  {  {
2994  /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char  /* Fast decoding a UTF-8 character type. TMP2 contains the first byte
2995  of the character (>= 0xd800). Return char value in TMP1, length - 1 in TMP2. */  of the character (>= 0xc0). Return value in TMP1. */
2996  DEFINE_COMPILER;  DEFINE_COMPILER;
2997  struct sljit_jump *jump;  struct sljit_jump *jump;
2998    struct sljit_jump *compare;
2999    
3000  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3001  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);  
3002  /* Do nothing, only return. */  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20);
3003    jump = JUMP(SLJIT_NOT_ZERO);
3004    /* Two byte sequence. */
3005    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
3006    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3007    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
3008    /* The upper 5 bits are known at this point. */
3009    compare = CMP(SLJIT_GREATER, TMP2, 0, SLJIT_IMM, 0x3);
3010    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
3011    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
3012    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
3013    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
3014  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3015    
3016    JUMPHERE(compare);
3017    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
3018    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3019    
3020    /* We only have types for characters less than 256. */
3021  JUMPHERE(jump);  JUMPHERE(jump);
3022  /* Combine two 16 bit characters. */  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
3023  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
3024  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);  
3025  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3026  }  }
3027    
3028  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE8 */
3029    
3030  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3031    
# Line 2475  if (firstline) Line 3086  if (firstline)
3086      {      {
3087      mainloop = LABEL();      mainloop = LABEL();
3088      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));
3089      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      end = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3090      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
3091      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
3092      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);      CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, mainloop);
3093      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);      CMPTO(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, mainloop);
3094      JUMPHERE(end);      JUMPHERE(end);
3095      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_SP), common->first_line_end, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3096      }      }
3097    else    else
3098      {      {
3099      end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      end = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3100      mainloop = LABEL();      mainloop = LABEL();
3101      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
3102      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->first_line_end, STR_PTR, 0);
3103      read_char(common);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
3104      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
3105      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_LESS, STR_PTR, 0, STR_END, 0, mainloop);
3106      JUMPHERE(end);      JUMPHERE(end);
3107      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->first_line_end, STR_PTR, 0);
3108      set_jumps(newline, LABEL());      set_jumps(newline, LABEL());
3109      }      }
3110    
# Line 2506  if (newlinecheck) Line 3117  if (newlinecheck)
3117    {    {
3118    newlinelabel = LABEL();    newlinelabel = LABEL();
3119    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));
3120    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3121    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3122    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);
3123    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_EQUAL);
3124  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3125    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3126  #endif  #endif
# Line 2529  if (readuchar) Line 3140  if (readuchar)
3140    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3141    
3142  if (newlinecheck)  if (newlinecheck)
3143    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);    CMPTO(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);
3144    
3145    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3146    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3147    #if defined COMPILE_PCRE8
3148    if (common->utf)
3149      {
3150      singlechar = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
3151      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
3152      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3153      JUMPHERE(singlechar);
3154      }
3155    #elif defined COMPILE_PCRE16
3156    if (common->utf)
3157      {
3158      singlechar = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
3159      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3160      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
3161      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_EQUAL);
3162      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3163      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3164      JUMPHERE(singlechar);
3165      }
3166    #endif /* COMPILE_PCRE[8|16] */
3167    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
3168    JUMPHERE(start);
3169    
3170    if (newlinecheck)
3171      {
3172      JUMPHERE(end);
3173      JUMPHERE(nl);
3174      }
3175    
3176    return mainloop;
3177    }
3178    
3179    #define MAX_N_CHARS 16
3180    #define MAX_N_BYTES 8
3181    
3182    static SLJIT_INLINE void add_prefix_byte(pcre_uint8 byte, pcre_uint8 *bytes)
3183    {
3184    pcre_uint8 len = bytes[0];
3185    int i;
3186    
3187    if (len == 255)
3188      return;
3189    
3190    if (len == 0)
3191      {
3192      bytes[0] = 1;
3193      bytes[1] = byte;
3194      return;
3195      }
3196    
3197    for (i = len; i > 0; i--)
3198      if (bytes[i] == byte)
3199        return;
3200    
3201    if (len >= MAX_N_BYTES - 1)
3202      {
3203      bytes[0] = 255;
3204      return;
3205      }
3206    
3207    len++;
3208    bytes[len] = byte;
3209    bytes[0] = len;
3210    }
3211    
3212    static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, pcre_uint8 *bytes, int max_chars)
3213    {
3214    /* Recursive function, which scans prefix literals. */
3215    BOOL last, any, caseless;
3216    int len, repeat, len_save, consumed = 0;
3217    pcre_uint32 chr, mask;
3218    pcre_uchar *alternative, *cc_save, *oc;
3219    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3220    pcre_uchar othercase[8];
3221    #elif defined SUPPORT_UTF && defined COMPILE_PCRE16
3222    pcre_uchar othercase[2];
3223    #else
3224    pcre_uchar othercase[1];
3225    #endif
3226    
3227    repeat = 1;
3228    while (TRUE)
3229      {
3230      last = TRUE;
3231      any = FALSE;
3232      caseless = FALSE;
3233      switch (*cc)
3234        {
3235        case OP_CHARI:
3236        caseless = TRUE;
3237        case OP_CHAR:
3238        last = FALSE;
3239        cc++;
3240        break;
3241    
3242        case OP_SOD:
3243        case OP_SOM:
3244        case OP_SET_SOM:
3245        case OP_NOT_WORD_BOUNDARY:
3246        case OP_WORD_BOUNDARY:
3247        case OP_EODN:
3248        case OP_EOD:
3249        case OP_CIRC:
3250        case OP_CIRCM:
3251        case OP_DOLL:
3252        case OP_DOLLM:
3253        /* Zero width assertions. */
3254        cc++;
3255        continue;
3256    
3257        case OP_ASSERT:
3258        case OP_ASSERT_NOT:
3259        case OP_ASSERTBACK:
3260        case OP_ASSERTBACK_NOT:
3261        cc = bracketend(cc);
3262        continue;
3263    
3264        case OP_PLUSI:
3265        case OP_MINPLUSI:
3266        case OP_POSPLUSI:
3267        caseless = TRUE;
3268        case OP_PLUS:
3269        case OP_MINPLUS:
3270        case OP_POSPLUS:
3271        cc++;
3272        break;
3273    
3274        case OP_EXACTI:
3275        caseless = TRUE;
3276        case OP_EXACT:
3277        repeat = GET2(cc, 1);
3278        last = FALSE;
3279        cc += 1 + IMM2_SIZE;
3280        break;
3281    
3282        case OP_QUERYI:
3283        case OP_MINQUERYI:
3284        case OP_POSQUERYI:
3285        caseless = TRUE;
3286        case OP_QUERY:
3287        case OP_MINQUERY:
3288        case OP_POSQUERY:
3289        len = 1;
3290        cc++;
3291    #ifdef SUPPORT_UTF
3292        if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3293    #endif
3294        max_chars = scan_prefix(common, cc + len, chars, bytes, max_chars);
3295        if (max_chars == 0)
3296          return consumed;
3297        last = FALSE;
3298        break;
3299    
3300        case OP_KET:
3301        cc += 1 + LINK_SIZE;
3302        continue;
3303    
3304        case OP_ALT:
3305        cc += GET(cc, 1);
3306        continue;
3307    
3308        case OP_ONCE:
3309        case OP_ONCE_NC:
3310        case OP_BRA:
3311        case OP_BRAPOS:
3312        case OP_CBRA:
3313        case OP_CBRAPOS:
3314        alternative = cc + GET(cc, 1);
3315        while (*alternative == OP_ALT)
3316          {
3317          max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, bytes, max_chars);
3318          if (max_chars == 0)
3319            return consumed;
3320          alternative += GET(alternative, 1);
3321          }
3322    
3323        if (*cc == OP_CBRA || *cc == OP_CBRAPOS)
3324          cc += IMM2_SIZE;
3325        cc += 1 + LINK_SIZE;
3326        continue;
3327    
3328        case OP_CLASS:
3329    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3330        if (common->utf && !is_char7_bitset((const pcre_uint8 *)(cc + 1), FALSE)) return consumed;
3331    #endif
3332        any = TRUE;
3333        cc += 1 + 32 / sizeof(pcre_uchar);
3334        break;
3335    
3336        case OP_NCLASS:
3337    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3338        if (common->utf) return consumed;
3339    #endif
3340        any = TRUE;
3341        cc += 1 + 32 / sizeof(pcre_uchar);
3342        break;
3343    
3344    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3345        case OP_XCLASS:
3346    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3347        if (common->utf) return consumed;
3348    #endif
3349        any = TRUE;
3350        cc += GET(cc, 1);
3351        break;
3352    #endif
3353    
3354        case OP_DIGIT:
3355    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3356        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_digit, FALSE))
3357          return consumed;
3358    #endif
3359        any = TRUE;
3360        cc++;
3361        break;
3362    
3363        case OP_WHITESPACE:
3364    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3365        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_space, FALSE))
3366          return consumed;
3367    #endif
3368        any = TRUE;
3369        cc++;
3370        break;
3371    
3372        case OP_WORDCHAR:
3373    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3374        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_word, FALSE))
3375          return consumed;
3376    #endif
3377        any = TRUE;
3378        cc++;
3379        break;
3380    
3381        case OP_NOT:
3382        case OP_NOTI:
3383        cc++;
3384        /* Fall through. */
3385        case OP_NOT_DIGIT:
3386        case OP_NOT_WHITESPACE:
3387        case OP_NOT_WORDCHAR:
3388        case OP_ANY:
3389        case OP_ALLANY:
3390    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3391        if (common->utf) return consumed;
3392    #endif
3393        any = TRUE;
3394        cc++;
3395        break;
3396    
3397    #ifdef SUPPORT_UCP
3398        case OP_NOTPROP:
3399        case OP_PROP:
3400    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3401        if (common->utf) return consumed;
3402    #endif
3403        any = TRUE;
3404        cc += 1 + 2;
3405        break;
3406    #endif
3407    
3408        case OP_TYPEEXACT:
3409        repeat = GET2(cc, 1);
3410        cc += 1 + IMM2_SIZE;
3411        continue;
3412    
3413        case OP_NOTEXACT:
3414        case OP_NOTEXACTI:
3415    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3416        if (common->utf) return consumed;
3417    #endif
3418        any = TRUE;
3419        repeat = GET2(cc, 1);
3420        cc += 1 + IMM2_SIZE + 1;
3421        break;
3422    
3423        default:
3424        return consumed;
3425        }
3426    
3427      if (any)
3428        {
3429    #if defined COMPILE_PCRE8
3430        mask = 0xff;
3431    #elif defined COMPILE_PCRE16
3432        mask = 0xffff;
3433    #elif defined COMPILE_PCRE32
3434        mask = 0xffffffff;
3435    #else
3436        SLJIT_ASSERT_STOP();
3437    #endif
3438    
3439        do
3440          {
3441          chars[0] = mask;
3442          chars[1] = mask;
3443          bytes[0] = 255;
3444    
3445          consumed++;
3446          if (--max_chars == 0)
3447            return consumed;
3448          chars += 2;
3449          bytes += MAX_N_BYTES;
3450          }
3451        while (--repeat > 0);
3452    
3453        repeat = 1;
3454        continue;
3455        }
3456    
3457      len = 1;
3458    #ifdef SUPPORT_UTF
3459      if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3460    #endif
3461    
3462      if (caseless && char_has_othercase(common, cc))
3463        {
3464    #ifdef SUPPORT_UTF
3465        if (common->utf)
3466          {
3467          GETCHAR(chr, cc);
3468          if ((int)PRIV(ord2utf)(char_othercase(common, chr), othercase) != len)
3469            return consumed;
3470          }
3471        else
3472    #endif
3473          {
3474          chr = *cc;
3475          othercase[0] = TABLE_GET(chr, common->fcc, chr);
3476          }
3477        }
3478      else
3479        caseless = FALSE;
3480    
3481      len_save = len;
3482      cc_save = cc;
3483      while (TRUE)
3484        {
3485        oc = othercase;
3486        do
3487          {
3488          chr = *cc;
3489    #ifdef COMPILE_PCRE32
3490          if (SLJIT_UNLIKELY(chr == NOTACHAR))
3491            return consumed;
3492    #endif
3493          add_prefix_byte((pcre_uint8)chr, bytes);
3494    
3495          mask = 0;
3496          if (caseless)
3497            {
3498            add_prefix_byte((pcre_uint8)*oc, bytes);
3499            mask = *cc ^ *oc;
3500            chr |= mask;
3501            }
3502    
3503    #ifdef COMPILE_PCRE32
3504          if (chars[0] == NOTACHAR && chars[1] == 0)
3505    #else
3506          if (chars[0] == NOTACHAR)
3507    #endif
3508            {
3509            chars[0] = chr;
3510            chars[1] = mask;
3511            }
3512          else
3513            {
3514            mask |= chars[0] ^ chr;
3515            chr |= mask;
3516            chars[0] = chr;
3517            chars[1] |= mask;
3518            }
3519    
3520          len--;
3521          consumed++;
3522          if (--max_chars == 0)
3523            return consumed;
3524          chars += 2;
3525          bytes += MAX_N_BYTES;
3526          cc++;
3527          oc++;
3528          }
3529        while (len > 0);
3530    
3531        if (--repeat == 0)
3532          break;
3533    
3534  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));      len = len_save;
3535  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32      cc = cc_save;
3536  #if defined COMPILE_PCRE8      }
 if (common->utf)  
   {  
   singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   JUMPHERE(singlechar);  
   }  
 #elif defined COMPILE_PCRE16  
 if (common->utf)  
   {  
   singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);  
   OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);  
   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);  
   OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);  
   OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   JUMPHERE(singlechar);  
   }  
 #endif /* COMPILE_PCRE[8|16] */  
 #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  
 JUMPHERE(start);  
3537    
3538  if (newlinecheck)    repeat = 1;
3539    {    if (last)
3540    JUMPHERE(end);      return consumed;
   JUMPHERE(nl);  
3541    }    }
   
 return mainloop;  
3542  }  }
3543    
 #define MAX_N_CHARS 3  
   
3544  static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)  static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3545  {  {
3546  DEFINE_COMPILER;  DEFINE_COMPILER;
3547  struct sljit_label *start;  struct sljit_label *start;
3548  struct sljit_jump *quit;  struct sljit_jump *quit;
3549  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uint32 chars[MAX_N_CHARS * 2];
3550  pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  pcre_uint8 bytes[MAX_N_CHARS * MAX_N_BYTES];
3551  int location = 0;  pcre_uint8 ones[MAX_N_CHARS];
3552  pcre_int32 len, c, bit, caseless;  int offsets[3];
3553  int must_stop;  pcre_uint32 mask;
3554    pcre_uint8 *byte_set, *byte_set_end;
3555    int i, max, from;
3556    int range_right = -1, range_len = 3 - 1;
3557    sljit_ub *update_table = NULL;
3558    BOOL in_range;
3559    
3560    for (i = 0; i < MAX_N_CHARS; i++)
3561      {
3562      chars[i << 1] = NOTACHAR;
3563      chars[(i << 1) + 1] = 0;
3564      bytes[i * MAX_N_BYTES] = 0;
3565      }
3566    
3567    max = scan_prefix(common, common->start, chars, bytes, MAX_N_CHARS);
3568    
3569  /* We do not support alternatives now. */  if (max <= 1)
 if (*(common->start + GET(common->start, 1)) == OP_ALT)  
3570    return FALSE;    return FALSE;
3571    
3572  while (TRUE)  for (i = 0; i < max; i++)
3573    {    {
3574    caseless = 0;    mask = chars[(i << 1) + 1];
3575    must_stop = 1;    ones[i] = ones_in_half_byte[mask & 0xf];
3576    switch(*cc)    mask >>= 4;
3577      while (mask != 0)
3578      {      {
3579      case OP_CHAR:      ones[i] += ones_in_half_byte[mask & 0xf];
3580      must_stop = 0;      mask >>= 4;
3581      cc++;      }
3582      break;    }
   
     case OP_CHARI:  
     caseless = 1;  
     must_stop = 0;  
     cc++;  
     break;  
3583    
3584      case OP_SOD:  in_range = FALSE;
3585      case OP_SOM:  from = 0;   /* Prevent compiler "uninitialized" warning */
3586      case OP_SET_SOM:  for (i = 0; i <= max; i++)
3587      case OP_NOT_WORD_BOUNDARY:    {
3588      case OP_WORD_BOUNDARY:    if (in_range && (i - from) > range_len && (bytes[(i - 1) * MAX_N_BYTES] <= 4))
3589      case OP_EODN:      {
3590      case OP_EOD:      range_len = i - from;
3591      case OP_CIRC:      range_right = i - 1;
3592      case OP_CIRCM:      }
     case OP_DOLL:  
     case OP_DOLLM:  
     /* Zero width assertions. */  
     cc++;  
     continue;  
3593    
3594      case OP_PLUS:    if (i < max && bytes[i * MAX_N_BYTES] < 255)
3595      case OP_MINPLUS:      {
3596      case OP_POSPLUS:      if (!in_range)
3597      cc++;        {
3598      break;        in_range = TRUE;
3599          from = i;
3600          }
3601        }
3602      else if (in_range)
3603        in_range = FALSE;
3604      }
3605    
3606      case OP_EXACT:  if (range_right >= 0)
3607      cc += 1 + IMM2_SIZE;    {
3608      break;    update_table = (sljit_ub *)allocate_read_only_data(common, 256);
3609      if (update_table == NULL)
3610        return TRUE;
3611      memset(update_table, IN_UCHARS(range_len), 256);
3612    
3613      case OP_PLUSI:    for (i = 0; i < range_len; i++)
3614      case OP_MINPLUSI:      {
3615      case OP_POSPLUSI:      byte_set = bytes + ((range_right - i) * MAX_N_BYTES);
3616      caseless = 1;      SLJIT_ASSERT(byte_set[0] > 0 && byte_set[0] < 255);
3617      cc++;      byte_set_end = byte_set + byte_set[0];
3618      break;      byte_set++;
3619        while (byte_set <= byte_set_end)
3620          {
3621          if (update_table[*byte_set] > IN_UCHARS(i))
3622            update_table[*byte_set] = IN_UCHARS(i);
3623          byte_set++;
3624          }
3625        }
3626      }
3627    
3628      case OP_EXACTI:  offsets[0] = -1;
3629      caseless = 1;  /* Scan forward. */
3630      cc += 1 + IMM2_SIZE;  for (i = 0; i < max; i++)
3631      if (ones[i] <= 2) {
3632        offsets[0] = i;
3633      break;      break;
3634      }
3635    
3636      default:  if (offsets[0] < 0 && range_right < 0)
3637      must_stop = 2;    return FALSE;
     break;  
     }  
3638    
3639    if (must_stop == 2)  if (offsets[0] >= 0)
3640      {
3641      /* Scan backward. */
3642      offsets[1] = -1;
3643      for (i = max - 1; i > offsets[0]; i--)
3644        if (ones[i] <= 2 && i != range_right)
3645          {
3646          offsets[1] = i;
3647        break;        break;
3648          }
3649    
3650    len = 1;    /* This case is handled better by fast_forward_first_char. */
3651  #ifdef SUPPORT_UTF    if (offsets[1] == -1 && offsets[0] == 0 && range_right < 0)
3652    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);      return FALSE;
 #endif  
3653    
3654    if (caseless && char_has_othercase(common, cc))    offsets[2] = -1;
3655      {    /* We only search for a middle character if there is no range check. */
3656      caseless = char_get_othercase_bit(common, cc);    if (offsets[1] >= 0 && range_right == -1)
3657      if (caseless == 0)      {
3658        return FALSE;      /* Scan from middle. */
3659  #ifdef COMPILE_PCRE8      for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3660      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));        if (ones[i] <= 2)
3661  #else          {
3662      if ((caseless & 0x100) != 0)          offsets[2] = i;
3663        caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));          break;
3664      else          }
       caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));  
 #endif  
     }  
   else  
     caseless = 0;  
3665    
3666    while (len > 0 && location < MAX_N_CHARS * 2)      if (offsets[2] == -1)
     {  
     c = *cc;  
     bit = 0;  
     if (len == (caseless & 0xff))  
3667        {        {
3668        bit = caseless >> 8;        for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3669        c |= bit;          if (ones[i] <= 2)
3670              {
3671              offsets[2] = i;
3672              break;
3673              }
3674        }        }
3675        }
3676    
3677      chars[location] = c;    SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3678      chars[location + 1] = bit;    SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3679    
3680      len--;    chars[0] = chars[offsets[0] << 1];
3681      location += 2;    chars[1] = chars[(offsets[0] << 1) + 1];
3682      cc++;    if (offsets[2] >= 0)
3683        {
3684        chars[2] = chars[offsets[2] << 1];
3685        chars[3] = chars[(offsets[2] << 1) + 1];
3686        }
3687      if (offsets[1] >= 0)
3688        {
3689        chars[4] = chars[offsets[1] << 1];
3690        chars[5] = chars[(offsets[1] << 1) + 1];
3691      }      }
   
   if (location >= MAX_N_CHARS * 2 || must_stop != 0)  
     break;  
3692    }    }
3693    
3694  /* At least two characters are required. */  max -= 1;
 if (location < 2 * 2)  
     return FALSE;  
   
3695  if (firstline)  if (firstline)
3696    {    {
3697    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3698      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->first_line_end);
3699    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3700    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, (location >> 1) - 1);    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3701      quit = CMP(SLJIT_LESS_EQUAL, STR_END, 0, TMP1, 0);
3702      OP1(SLJIT_MOV, STR_END, 0, TMP1, 0);
3703      JUMPHERE(quit);
3704    }    }
3705  else  else
3706    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, (location >> 1) - 1);    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3707    
3708    #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3709    if (range_right >= 0)
3710      OP1(SLJIT_MOV, RETURN_ADDR, 0, SLJIT_IMM, (sljit_sw)update_table);
3711    #endif
3712    
3713  start = LABEL();  start = LABEL();
3714  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3715    
3716  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  SLJIT_ASSERT(range_right >= 0 || offsets[0] >= 0);
3717  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
3718  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  if (range_right >= 0)
3719  if (chars[1] != 0)    {
3720    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);  #if defined COMPILE_PCRE8 || (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
3721  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right));
3722  if (location > 2 * 2)  #else
3723    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right + 1) - 1);
3724  if (chars[3] != 0)  #endif
3725    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);  
3726  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);  #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3727  if (location > 2 * 2)    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(RETURN_ADDR, TMP1), 0);
3728    {  #else
3729    if (chars[5] != 0)    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)update_table);
3730      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);  #endif
3731    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3732      CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, start);
3733      }
3734    
3735    if (offsets[0] >= 0)
3736      {
3737      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
3738      if (offsets[1] >= 0)
3739        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3740      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3741    
3742      if (chars[1] != 0)
3743        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3744      CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3745      if (offsets[2] >= 0)
3746        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));
3747    
3748      if (offsets[1] >= 0)
3749        {
3750        if (chars[5] != 0)
3751          OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3752        CMPTO(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
3753        }
3754    
3755      if (offsets[2] >= 0)
3756        {
3757        if (chars[3] != 0)
3758          OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3759        CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3760        }
3761      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3762    }    }
 OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
3763    
3764  JUMPHERE(quit);  JUMPHERE(quit);
3765    
3766  if (firstline)  if (firstline)
3767      {
3768      if (range_right >= 0)
3769        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->first_line_end);
3770    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3771      if (range_right >= 0)
3772        {
3773        quit = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
3774        OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
3775        JUMPHERE(quit);
3776        }
3777      }
3778  else  else
3779    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, (location >> 1) - 1);    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3780  return TRUE;  return TRUE;
3781  }  }
3782    
3783  #undef MAX_N_CHARS  #undef MAX_N_CHARS
3784    #undef MAX_N_BYTES
3785    
3786  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)
3787  {  {
# Line 2746  if (firstline) Line 3795  if (firstline)
3795    {    {
3796    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3797    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3798    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), common->first_line_end);
3799    }    }
3800    
3801  start = LABEL();  start = LABEL();
3802  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3803  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3804    
3805  oc = first_char;  oc = first_char;
# Line 2763  if (caseless) Line 3812  if (caseless)
3812  #endif  #endif
3813    }    }
3814  if (first_char == oc)  if (first_char == oc)
3815    found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, first_char);    found = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, first_char);
3816  else  else
3817    {    {
3818    bit = first_char ^ oc;    bit = first_char ^ oc;
3819    if (is_powerof2(bit))    if (is_powerof2(bit))
3820      {      {
3821      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3822      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);      found = CMP(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
3823      }      }
3824    else    else
3825      {      {
3826      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);
3827      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_EQUAL);
3828      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);
3829      OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_EQUAL);
3830      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_NOT_ZERO);
3831      }      }
3832    }    }
3833    
# Line 2806  if (firstline) Line 3855  if (firstline)
3855    {    {
3856    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3857    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3858    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), common->first_line_end);
3859    }    }
3860    
3861  if (common->nltype == NLTYPE_FIXED && common->newline > 255)  if (common->nltype == NLTYPE_FIXED && common->newline > 255)
3862    {    {
3863    lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    lastchar = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3864    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
3865    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
3866    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
3867    firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP2, 0);    firstchar = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP2, 0);
3868    
3869    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3870    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);
3871    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_GREATER_EQUAL);
3872  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3873    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3874  #endif  #endif
# Line 2827  if (common->nltype == NLTYPE_FIXED && co Line 3876  if (common->nltype == NLTYPE_FIXED && co
3876    
3877    loop = LABEL();    loop = LABEL();
3878    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));
3879    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    quit = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3880    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
3881    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
3882    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);    CMPTO(SLJIT_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, loop);
3883    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);    CMPTO(SLJIT_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff, loop);
3884    
3885    JUMPHERE(quit);    JUMPHERE(quit);
3886    JUMPHERE(firstchar);    JUMPHERE(firstchar);
3887    JUMPHERE(lastchar);    JUMPHERE(lastchar);
3888    
3889    if (firstline)    if (firstline)
3890      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3891    return;    return;
3892    }    }
3893    
3894  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
3895  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
3896  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP2, 0);  firstchar = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP2, 0);
3897  skip_char_back(common);  skip_char_back(common);
3898    
3899  loop = LABEL();  loop = LABEL();
3900  read_char(common);  common->ff_newline_shortcut = loop;
3901  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  
3902    read_char_range(common, common->nlmin, common->nlmax, TRUE);
3903    lastchar = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3904  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3905    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    foundcr = CMP(SLJIT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
3906  check_newlinechar(common, common->nltype, &newline, FALSE);  check_newlinechar(common, common->nltype, &newline, FALSE);
3907  set_jumps(newline, loop);  set_jumps(newline, loop);
3908    
# Line 2859  if (common->nltype == NLTYPE_ANY || comm Line 3910  if (common->nltype == NLTYPE_ANY || comm
3910    {    {
3911    quit = JUMP(SLJIT_JUMP);    quit = JUMP(SLJIT_JUMP);
3912    JUMPHERE(foundcr);    JUMPHERE(foundcr);
3913    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3914    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3915    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);
3916    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_EQUAL);
3917  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3918    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3919  #endif  #endif
# Line 2877  if (firstline) Line 3928  if (firstline)
3928    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3929  }  }
3930    
3931  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);
3932    
3933    static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, pcre_uint8 *start_bits, BOOL firstline)
3934  {  {
3935  DEFINE_COMPILER;  DEFINE_COMPILER;
3936  struct sljit_label *start;  struct sljit_label *start;
3937  struct sljit_jump *quit;  struct sljit_jump *quit;
3938  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3939    jump_list *matches = NULL;
3940  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3941  struct sljit_jump *jump;  struct sljit_jump *jump;
3942  #endif  #endif
# Line 2891  if (firstline) Line 3945  if (firstline)
3945    {    {
3946    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3947    OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);    OP1(SLJIT_MOV, RETURN_ADDR, 0, STR_END, 0);
3948    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_SP), common->first_line_end);
3949    }    }
3950    
3951  start = LABEL();  start = LABEL();
3952  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3953  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3954  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3955  if (common->utf)  if (common->utf)
3956    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3957  #endif  #endif
3958    
3959    if (!check_class_ranges(common, start_bits, (start_bits[31] & 0x80) != 0, TRUE, &matches))
3960      {
3961  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3962  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 255);
3963  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3964  JUMPHERE(jump);    JUMPHERE(jump);
3965  #endif  #endif
3966  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3967  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3968  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
3969  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3970  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);
3971  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_NOT_ZERO);
3972      }
3973    
3974  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3975  if (common->utf)  if (common->utf)
# Line 2922  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S Line 3980  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S
3980  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
3981  if (common->utf)  if (common->utf)
3982    {    {
3983    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3984    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
3985    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3986    }    }
3987  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
3988  if (common->utf)  if (common->utf)
3989    {    {
3990    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3991    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3992    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);
3993    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_EQUAL);
3994    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3995    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3996    }    }
3997  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE[8|16] */
3998  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3999  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
4000  JUMPHERE(found);  if (found != NULL)
4001      JUMPHERE(found);
4002    if (matches != NULL)
4003      set_jumps(matches, LABEL());
4004  JUMPHERE(quit);  JUMPHERE(quit);
4005    
4006  if (firstline)  if (firstline)
# Line 2958  struct sljit_jump *notfound; Line 4019  struct sljit_jump *notfound;
4019  pcre_uint32 oc, bit;  pcre_uint32 oc, bit;
4020    
4021  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
4022  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->req_char_ptr);
4023  OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, REQ_BYTE_MAX);  OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, REQ_BYTE_MAX);
4024  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);  toolong = CMP(SLJIT_LESS, TMP1, 0, STR_END, 0);
4025  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);  alreadyfound = CMP(SLJIT_LESS, STR_PTR, 0, TMP2, 0);
4026    
4027  if (has_firstchar)  if (has_firstchar)
4028    OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));    OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
# Line 2969  else Line 4030  else
4030    OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);
4031    
4032  loop = LABEL();  loop = LABEL();
4033  notfound = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, STR_END, 0);  notfound = CMP(SLJIT_GREATER_EQUAL, TMP1, 0, STR_END, 0);
4034    
4035  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(TMP1), 0);
4036  oc = req_char;  oc = req_char;
# Line 2982  if (caseless) Line 4043  if (caseless)
4043  #endif  #endif
4044    }    }
4045  if (req_char == oc)  if (req_char == oc)
4046    found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char);    found = CMP(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, req_char);
4047  else  else
4048    {    {
4049    bit = req_char ^ oc;    bit = req_char ^ oc;
4050    if (is_powerof2(bit))    if (is_powerof2(bit))
4051      {      {
4052      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
4053      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);      found = CMP(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
4054      }      }
4055    else    else
4056      {      {
4057      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char);      found = CMP(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, req_char);
4058      foundoc = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, oc);      foundoc = CMP(SLJIT_EQUAL, TMP2, 0, SLJIT_IMM, oc);
4059      }      }
4060    }    }
4061  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(1));
# Line 3003  JUMPTO(SLJIT_JUMP, loop); Line 4064  JUMPTO(SLJIT_JUMP, loop);
4064  JUMPHERE(found);  JUMPHERE(found);
4065  if (foundoc)  if (foundoc)
4066    JUMPHERE(foundoc);    JUMPHERE(foundoc);
4067  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->req_char_ptr, TMP1, 0);
4068  JUMPHERE(alreadyfound);  JUMPHERE(alreadyfound);
4069  JUMPHERE(toolong);  JUMPHERE(toolong);
4070  return notfound;  return notfound;
# Line 3022  GET_LOCAL_BASE(TMP3, 0, 0); Line 4083  GET_LOCAL_BASE(TMP3, 0, 0);
4083  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
4084  mainloop = LABEL();  mainloop = LABEL();
4085  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
4086  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);
4087    jump = JUMP(SLJIT_SIG_LESS_EQUAL);
4088    
4089  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
4090  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
4091  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
# Line 3030  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_I Line 4093  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_I
4093  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
4094    
4095  JUMPHERE(jump);  JUMPHERE(jump);
4096  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_SIG_LESS);
4097  /* End of dropping frames. */  /* End of dropping frames. */
4098  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
4099    
4100  JUMPHERE(jump);  JUMPHERE(jump);
4101  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
4102  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
4103  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
 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_sw));  
   OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));  
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);  
   JUMPTO(SLJIT_JUMP, mainloop);  
   
   JUMPHERE(jump);  
   }  
   
 /* Unknown command. */  
4104  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
4105  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
4106  }  }
# Line 3063  static void check_wordboundary(compiler_ Line 4109  static void check_wordboundary(compiler_
4109  {  {
4110  DEFINE_COMPILER;  DEFINE_COMPILER;
4111  struct sljit_jump *skipread;  struct sljit_jump *skipread;
4112    jump_list *skipread_list = NULL;
4113  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
4114  struct sljit_jump *jump;  struct sljit_jump *jump;
4115  #endif  #endif
4116    
4117  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);  SLJIT_COMPILE_ASSERT(ctype_word == 0x10, ctype_word_must_be_16);
4118    
4119  sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SP), LOCALS0);
4120  /* Get type of the previous char, and put it to LOCALS1. */  /* Get type of the previous char, and put it to LOCALS1. */
4121  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
4122  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
4123  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCALS1, SLJIT_IMM, 0);
4124  skipread = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);  skipread = CMP(SLJIT_LESS_EQUAL, STR_PTR, 0, TMP1, 0);