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

Diff of /code/trunk/pcre_jit_compile.c

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

revision 1270 by zherczeg, Tue Mar 5 08:05:17 2013 UTC revision 1423 by zherczeg, Tue Dec 31 07:57:56 2013 UTC
# Line 71  system files. */ Line 71  system files. */
71     2 - Enable capture_last_ptr (includes option 1). */     2 - Enable capture_last_ptr (includes option 1). */
72  /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */  /* #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 165  typedef struct jit_arguments { Line 168  typedef struct jit_arguments {
168    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
169    void *callout_data;    void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171      pcre_uint32 limit_match;
172    int real_offset_count;    int real_offset_count;
173    int offset_count;    int offset_count;
   int call_limit;  
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 179  typedef struct executable_functions { Line 182  typedef struct executable_functions {
182    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184    pcre_uint32 top_bracket;    pcre_uint32 top_bracket;
185      pcre_uint32 limit_match;
186    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
187  } executable_functions;  } executable_functions;
188    
# Line 193  typedef struct stub_list { Line 197  typedef struct stub_list {
197    struct stub_list *next;    struct stub_list *next;
198  } stub_list;  } stub_list;
199    
200  enum frame_types { no_frame = -1, no_stack = -2 };  enum frame_types {
201      no_frame = -1,
202      no_stack = -2
203    };
204    
205    enum control_types {
206      type_mark = 0,
207      type_then_trap = 1
208    };
209    
210  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
213  code generator. It is allocated by compile_matchingpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
214  the aguments for compile_backtrackingpath. Must be the first member  the arguments for compile_backtrackingpath. Must be the first member
215  of its descendants. */  of its descendants. */
216  typedef struct backtrack_common {  typedef struct backtrack_common {
217    /* Concatenation stack. */    /* Concatenation stack. */
# Line 215  typedef struct backtrack_common { Line 227  typedef struct backtrack_common {
227  typedef struct assert_backtrack {  typedef struct assert_backtrack {
228    backtrack_common common;    backtrack_common common;
229    jump_list *condfailed;    jump_list *condfailed;
230    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
231    int framesize;    int framesize;
232    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
233    int private_data_ptr;    int private_data_ptr;
# Line 236  typedef struct bracket_backtrack { Line 248  typedef struct bracket_backtrack {
248      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
249      jump_list *condfailed;      jump_list *condfailed;
250      assert_backtrack *assert;      assert_backtrack *assert;
251      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
252      int framesize;      int framesize;
253    } u;    } u;
254    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
# Line 271  typedef struct recurse_entry { Line 283  typedef struct recurse_entry {
283    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
284    jump_list *calls;    jump_list *calls;
285    /* Points to the starting opcode. */    /* Points to the starting opcode. */
286    int start;    sljit_sw start;
287  } recurse_entry;  } recurse_entry;
288    
289  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
# Line 279  typedef struct recurse_backtrack { Line 291  typedef struct recurse_backtrack {
291    BOOL inlined_pattern;    BOOL inlined_pattern;
292  } recurse_backtrack;  } recurse_backtrack;
293    
294  #define MAX_RANGE_SIZE 6  #define OP_THEN_TRAP OP_TABLE_LENGTH
295    
296    typedef struct then_trap_backtrack {
297      backtrack_common common;
298      /* If then_trap is not NULL, this structure contains the real
299      then_trap for the backtracking path. */
300      struct then_trap_backtrack *then_trap;
301      /* Points to the starting opcode. */
302      sljit_sw start;
303      /* Exit point for the then opcodes of this alternative. */
304      jump_list *quit;
305      /* Frame size of the current alternative. */
306      int framesize;
307    } then_trap_backtrack;
308    
309    #define MAX_RANGE_SIZE 4
310    
311  typedef struct compiler_common {  typedef struct compiler_common {
312      /* The sljit ceneric compiler. */
313    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
314      /* First byte code. */
315    pcre_uchar *start;    pcre_uchar *start;
   
316    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
317    int *private_data_ptrs;    sljit_si *private_data_ptrs;
318    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
319    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
320      /* Tells whether the starting offset is a target of then. */
321      pcre_uint8 *then_offsets;
322      /* Current position where a THEN must jump. */
323      then_trap_backtrack *then_trap;
324    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
325    int cbraptr;    int cbra_ptr;
326    /* OVector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
327    int ovector_start;    int ovector_start;
328    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
329    int req_char_ptr;    int req_char_ptr;
# Line 305  typedef struct compiler_common { Line 337  typedef struct compiler_common {
337    int first_line_end;    int first_line_end;
338    /* Points to the marked string. */    /* Points to the marked string. */
339    int mark_ptr;    int mark_ptr;
340      /* Recursive control verb management chain. */
341      int control_head_ptr;
342    /* Points to the last matched capture block index. */    /* Points to the last matched capture block index. */
343    int capture_last_ptr;    int capture_last_ptr;
344      /* Points to the starting position of the current match. */
345      int start_ptr;
346    
347    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
348    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
349    sljit_sw lcc;    sljit_sw lcc;
350    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
351    int mode;    int mode;
352      /* \K is found in the pattern. */
353      BOOL has_set_som;
354      /* (*SKIP:arg) is found in the pattern. */
355      BOOL has_skip_arg;
356      /* (*THEN) is found in the pattern. */
357      BOOL has_then;
358      /* Needs to know the start position anytime. */
359      BOOL needs_start_ptr;
360      /* Currently in recurse or negative assert. */
361      BOOL local_exit;
362      /* Currently in a positive assert. */
363      BOOL positive_assert;
364    /* Newline control. */    /* Newline control. */
365    int nltype;    int nltype;
366      pcre_uint32 nlmax;
367    int newline;    int newline;
368    int bsr_nltype;    int bsr_nltype;
369      pcre_uint32 bsr_nlmax;
370    /* Dollar endonly. */    /* Dollar endonly. */
371    int endonly;    int endonly;
   BOOL has_set_som;  
372    /* Tables. */    /* Tables. */
373    sljit_sw ctypes;    sljit_sw ctypes;
   int digits[2 + MAX_RANGE_SIZE];  
374    /* Named capturing brackets. */    /* Named capturing brackets. */
375    sljit_uw name_table;    pcre_uchar *name_table;
376    sljit_sw name_count;    sljit_sw name_count;
377    sljit_sw name_entry_size;    sljit_sw name_entry_size;
378    
# Line 338  typedef struct compiler_common { Line 386  typedef struct compiler_common {
386    recurse_entry *currententry;    recurse_entry *currententry;
387    jump_list *partialmatch;    jump_list *partialmatch;
388    jump_list *quit;    jump_list *quit;
389      jump_list *positive_assert_quit;
390    jump_list *forced_quit;    jump_list *forced_quit;
391    jump_list *accept;    jump_list *accept;
392    jump_list *calllimit;    jump_list *calllimit;
# Line 349  typedef struct compiler_common { Line 398  typedef struct compiler_common {
398    jump_list *vspace;    jump_list *vspace;
399    jump_list *casefulcmp;    jump_list *casefulcmp;
400    jump_list *caselesscmp;    jump_list *caselesscmp;
401      jump_list *reset_match;
402    BOOL jscript_compat;    BOOL jscript_compat;
403  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
404    BOOL utf;    BOOL utf;
405  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
406    BOOL use_ucp;    BOOL use_ucp;
407  #endif  #endif
 #ifndef COMPILE_PCRE32  
   jump_list *utfreadchar;  
 #endif  
408  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
409      jump_list *utfreadchar;
410      jump_list *utfreadchar16;
411    jump_list *utfreadtype8;    jump_list *utfreadtype8;
412  #endif  #endif
413  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
# Line 415  typedef struct compare_context { Line 464  typedef struct compare_context {
464  #define STACK_TOP     SLJIT_SCRATCH_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
465  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
466  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
467  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define COUNT_MATCH   SLJIT_SAVED_EREG2
468  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
469    
470  /* Local space layout. */  /* Local space layout. */
# Line 426  typedef struct compare_context { Line 475  typedef struct compare_context {
475  #define POSSESSIVE0      (2 * sizeof(sljit_sw))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
476  #define POSSESSIVE1      (3 * sizeof(sljit_sw))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
477  /* Max limit of recursions. */  /* Max limit of recursions. */
478  #define CALL_LIMIT       (4 * sizeof(sljit_sw))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
479  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
480  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
481  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
482  the start pointers when the end of the capturing group has not yet reached. */  the start pointers when the end of the capturing group has not yet reached. */
483  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
484  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))  #define OVECTOR(i)       (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw))
485  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_sw))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
486  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
487    
488  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
# Line 475  the start pointers when the end of the c Line 524  the start pointers when the end of the c
524  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
525    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
526    
527    #define READ_CHAR_ANY 0x7fffffff
528    
529  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
530  {  {
531  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
# Line 484  cc += 1 + LINK_SIZE; Line 535  cc += 1 + LINK_SIZE;
535  return cc;  return cc;
536  }  }
537    
538    static int ones_in_half_byte[16] = {
539      /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
540      /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
541    };
542    
543  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
544   next_opcode   next_opcode
545   get_private_data_length   check_opcode_types
546   set_private_data_ptrs   set_private_data_ptrs
547   get_framesize   get_framesize
548   init_frame   init_frame
549   get_private_data_length_for_copy   get_private_data_copy_length
550   copy_private_data   copy_private_data
551   compile_matchingpath   compile_matchingpath
552   compile_backtrackingpath   compile_backtrackingpath
# Line 536  switch(*cc) Line 592  switch(*cc)
592    case OP_CRMINQUERY:    case OP_CRMINQUERY:
593    case OP_CRRANGE:    case OP_CRRANGE:
594    case OP_CRMINRANGE:    case OP_CRMINRANGE:
595      case OP_CRPOSSTAR:
596      case OP_CRPOSPLUS:
597      case OP_CRPOSQUERY:
598      case OP_CRPOSRANGE:
599    case OP_CLASS:    case OP_CLASS:
600    case OP_NCLASS:    case OP_NCLASS:
601    case OP_REF:    case OP_REF:
602    case OP_REFI:    case OP_REFI:
603      case OP_DNREF:
604      case OP_DNREFI:
605    case OP_RECURSE:    case OP_RECURSE:
606    case OP_CALLOUT:    case OP_CALLOUT:
607    case OP_ALT:    case OP_ALT:
# Line 565  switch(*cc) Line 627  switch(*cc)
627    case OP_SCBRAPOS:    case OP_SCBRAPOS:
628    case OP_SCOND:    case OP_SCOND:
629    case OP_CREF:    case OP_CREF:
630    case OP_NCREF:    case OP_DNCREF:
631    case OP_RREF:    case OP_RREF:
632    case OP_NRREF:    case OP_DNRREF:
633    case OP_DEF:    case OP_DEF:
634    case OP_BRAZERO:    case OP_BRAZERO:
635    case OP_BRAMINZERO:    case OP_BRAMINZERO:
636    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
637      case OP_PRUNE:
638      case OP_SKIP:
639      case OP_THEN:
640    case OP_COMMIT:    case OP_COMMIT:
641    case OP_FAIL:    case OP_FAIL:
642    case OP_ACCEPT:    case OP_ACCEPT:
# Line 670  switch(*cc) Line 735  switch(*cc)
735  #endif  #endif
736    
737    case OP_MARK:    case OP_MARK:
738      case OP_PRUNE_ARG:
739      case OP_SKIP_ARG:
740      case OP_THEN_ARG:
741    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
742    
743    default:    default:
744      /* All opcodes are supported now! */
745      SLJIT_ASSERT_STOP();
746    return NULL;    return NULL;
747    }    }
748  }  }
749    
750    static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
751    {
752    int count;
753    pcre_uchar *slot;
754    
755    /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
756    while (cc < ccend)
757      {
758      switch(*cc)
759        {
760        case OP_SET_SOM:
761        common->has_set_som = TRUE;
762        cc += 1;
763        break;
764    
765        case OP_REF:
766        case OP_REFI:
767        common->optimized_cbracket[GET2(cc, 1)] = 0;
768        cc += 1 + IMM2_SIZE;
769        break;
770    
771        case OP_CBRAPOS:
772        case OP_SCBRAPOS:
773        common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
774        cc += 1 + LINK_SIZE + IMM2_SIZE;
775        break;
776    
777        case OP_COND:
778        case OP_SCOND:
779        /* Only AUTO_CALLOUT can insert this opcode. We do
780           not intend to support this case. */
781        if (cc[1 + LINK_SIZE] == OP_CALLOUT)
782          return FALSE;
783        cc += 1 + LINK_SIZE;
784        break;
785    
786        case OP_CREF:
787        common->optimized_cbracket[GET2(cc, 1)] = 0;
788        cc += 1 + IMM2_SIZE;
789        break;
790    
791        case OP_DNREF:
792        case OP_DNREFI:
793        case OP_DNCREF:
794        count = GET2(cc, 1 + IMM2_SIZE);
795        slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
796        while (count-- > 0)
797          {
798          common->optimized_cbracket[GET2(slot, 0)] = 0;
799          slot += common->name_entry_size;
800          }
801        cc += 1 + 2 * IMM2_SIZE;
802        break;
803    
804        case OP_RECURSE:
805        /* Set its value only once. */
806        if (common->recursive_head_ptr == 0)
807          {
808          common->recursive_head_ptr = common->ovector_start;
809          common->ovector_start += sizeof(sljit_sw);
810          }
811        cc += 1 + LINK_SIZE;
812        break;
813    
814        case OP_CALLOUT:
815        if (common->capture_last_ptr == 0)
816          {
817          common->capture_last_ptr = common->ovector_start;
818          common->ovector_start += sizeof(sljit_sw);
819          }
820        cc += 2 + 2 * LINK_SIZE;
821        break;
822    
823        case OP_THEN_ARG:
824        common->has_then = TRUE;
825        common->control_head_ptr = 1;
826        /* Fall through. */
827    
828        case OP_PRUNE_ARG:
829        common->needs_start_ptr = TRUE;
830        /* Fall through. */
831    
832        case OP_MARK:
833        if (common->mark_ptr == 0)
834          {
835          common->mark_ptr = common->ovector_start;
836          common->ovector_start += sizeof(sljit_sw);
837          }
838        cc += 1 + 2 + cc[1];
839        break;
840    
841        case OP_THEN:
842        common->has_then = TRUE;
843        common->control_head_ptr = 1;
844        /* Fall through. */
845    
846        case OP_PRUNE:
847        case OP_SKIP:
848        common->needs_start_ptr = TRUE;
849        cc += 1;
850        break;
851    
852        case OP_SKIP_ARG:
853        common->control_head_ptr = 1;
854        common->has_skip_arg = TRUE;
855        cc += 1 + 2 + cc[1];
856        break;
857    
858        default:
859        cc = next_opcode(common, cc);
860        if (cc == NULL)
861          return FALSE;
862        break;
863        }
864      }
865    return TRUE;
866    }
867    
868    static int get_class_iterator_size(pcre_uchar *cc)
869    {
870    switch(*cc)
871      {
872      case OP_CRSTAR:
873      case OP_CRPLUS:
874      return 2;
875    
876      case OP_CRMINSTAR:
877      case OP_CRMINPLUS:
878      case OP_CRQUERY:
879      case OP_CRMINQUERY:
880      return 1;
881    
882      case OP_CRRANGE:
883      case OP_CRMINRANGE:
884      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
885        return 0;
886      return 2;
887    
888      default:
889      return 0;
890      }
891    }
892    
893    static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
894    {
895    pcre_uchar *end = bracketend(begin);
896    pcre_uchar *next;
897    pcre_uchar *next_end;
898    pcre_uchar *max_end;
899    pcre_uchar type;
900    sljit_sw length = end - begin;
901    int min, max, i;
902    
903    /* Detect fixed iterations first. */
904    if (end[-(1 + LINK_SIZE)] != OP_KET)
905      return FALSE;
906    
907    /* Already detected repeat. */
908    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
909      return TRUE;
910    
911    next = end;
912    min = 1;
913    while (1)
914      {
915      if (*next != *begin)
916        break;
917      next_end = bracketend(next);
918      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
919        break;
920      next = next_end;
921      min++;
922      }
923    
924    if (min == 2)
925      return FALSE;
926    
927    max = 0;
928    max_end = next;
929    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
930      {
931      type = *next;
932      while (1)
933        {
934        if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
935          break;
936        next_end = bracketend(next + 2 + LINK_SIZE);
937        if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
938          break;
939        next = next_end;
940        max++;
941        }
942    
943      if (next[0] == type && next[1] == *begin && max >= 1)
944        {
945        next_end = bracketend(next + 1);
946        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
947          {
948          for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
949            if (*next_end != OP_KET)
950              break;
951    
952          if (i == max)
953            {
954            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
955            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
956            /* +2 the original and the last. */
957            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
958            if (min == 1)
959              return TRUE;
960            min--;
961            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
962            }
963          }
964        }
965      }
966    
967    if (min >= 3)
968      {
969      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
970      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
971      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
972      return TRUE;
973      }
974    
975    return FALSE;
976    }
977    
978  #define CASE_ITERATOR_PRIVATE_DATA_1 \  #define CASE_ITERATOR_PRIVATE_DATA_1 \
979      case OP_MINSTAR: \      case OP_MINSTAR: \
980      case OP_MINPLUS: \      case OP_MINPLUS: \
# Line 729  switch(*cc) Line 1027  switch(*cc)
1027      case OP_TYPEUPTO: \      case OP_TYPEUPTO: \
1028      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
1029    
1030  static int get_class_iterator_size(pcre_uchar *cc)  static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
 {  
 switch(*cc)  
   {  
   case OP_CRSTAR:  
   case OP_CRPLUS:  
   return 2;  
   
   case OP_CRMINSTAR:  
   case OP_CRMINPLUS:  
   case OP_CRQUERY:  
   case OP_CRMINQUERY:  
   return 1;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))  
     return 0;  
   return 2;  
   
   default:  
   return 0;  
   }  
 }  
   
 static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  
1031  {  {
1032  int private_data_length = 0;  pcre_uchar *cc = common->start;
1033  pcre_uchar *alternative;  pcre_uchar *alternative;
 pcre_uchar *name;  
1034  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1035  int space, size, i;  int private_data_ptr = *private_data_start;
1036  pcre_uint32 bracketlen;  int space, size, bracketlen;
1037    
 /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  
1038  while (cc < ccend)  while (cc < ccend)
1039    {    {
1040    space = 0;    space = 0;
1041    size = 0;    size = 0;
1042    bracketlen = 0;    bracketlen = 0;
1043      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1044        return;
1045    
1046      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1047        if (detect_repeat(common, cc))
1048          {
1049          /* These brackets are converted to repeats, so no global
1050          based single character repeat is allowed. */
1051          if (cc >= end)
1052            end = bracketend(cc);
1053          }
1054    
1055    switch(*cc)    switch(*cc)
1056      {      {
1057      case OP_SET_SOM:      case OP_KET:
1058      common->has_set_som = TRUE;      if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1059      cc += 1;        {
1060      break;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1061          private_data_ptr += sizeof(sljit_sw);
1062      case OP_REF:        cc += common->private_data_ptrs[cc + 1 - common->start];
1063      case OP_REFI:        }
1064      common->optimized_cbracket[GET2(cc, 1)] = 0;      cc += 1 + LINK_SIZE;
     cc += 1 + IMM2_SIZE;  
1065      break;      break;
1066    
1067      case OP_ASSERT:      case OP_ASSERT:
# Line 791  while (cc < ccend) Line 1073  while (cc < ccend)
1073      case OP_BRAPOS:      case OP_BRAPOS:
1074      case OP_SBRA:      case OP_SBRA:
1075      case OP_SBRAPOS:      case OP_SBRAPOS:
1076      private_data_length += sizeof(sljit_sw);      case OP_SCOND:
1077        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1078        private_data_ptr += sizeof(sljit_sw);
1079      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1080      break;      break;
1081    
1082      case OP_CBRAPOS:      case OP_CBRAPOS:
1083      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1084      private_data_length += sizeof(sljit_sw);      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1085      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      private_data_ptr += sizeof(sljit_sw);
1086      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1087      break;      break;
1088    
1089      case OP_COND:      case OP_COND:
1090      case OP_SCOND:      /* Might be a hidden SCOND. */
1091      /* Only AUTO_CALLOUT can insert this opcode. We do      alternative = cc + GET(cc, 1);
1092         not intend to support this case. */      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
     if (cc[1 + LINK_SIZE] == OP_CALLOUT)  
       return -1;  
   
     if (*cc == OP_COND)  
1093        {        {
1094        /* Might be a hidden SCOND. */        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1095        alternative = cc + GET(cc, 1);        private_data_ptr += sizeof(sljit_sw);
       if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)  
         private_data_length += sizeof(sljit_sw);  
       }  
     else  
       private_data_length += sizeof(sljit_sw);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_CREF:  
     i = GET2(cc, 1);  
     common->optimized_cbracket[i] = 0;  
     cc += 1 + IMM2_SIZE;  
     break;  
   
     case OP_NCREF:  
     bracketlen = GET2(cc, 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;  
       }  
     bracketlen = 0;  
     cc += 1 + IMM2_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  
   
     case OP_RECURSE:  
     /* Set its value only once. */  
     if (common->recursive_head_ptr == 0)  
       {  
       common->recursive_head_ptr = common->ovector_start;  
       common->ovector_start += sizeof(sljit_sw);  
       }  
     cc += 1 + LINK_SIZE;  
     break;  
   
     case OP_CALLOUT:  
     if (common->capture_last_ptr == 0)  
       {  
       common->capture_last_ptr = common->ovector_start;  
       common->ovector_start += sizeof(sljit_sw);  
       }  
     cc += 2 + 2 * 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;  
   
     default:  
     cc = next_opcode(common, cc);  
     if (cc == NULL)  
       return -1;  
     break;  
     }  
   
   if (space > 0 && cc >= end)  
     private_data_length += 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;  
     }  
   }  
 return private_data_length;  
 }  
   
 static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)  
 {  
 pcre_uchar *cc = common->start;  
 pcre_uchar *alternative;  
 pcre_uchar *end = NULL;  
 int space, size, bracketlen;  
   
 while (cc < ccend)  
   {  
   space = 0;  
   size = 0;  
   bracketlen = 0;  
   switch(*cc)  
     {  
     case OP_ASSERT:  
     case OP_ASSERT_NOT:  
     case OP_ASSERTBACK:  
     case OP_ASSERTBACK_NOT:  
     case OP_ONCE:  
     case OP_ONCE_NC:  
     case OP_BRAPOS:  
     case OP_SBRA:  
     case OP_SBRAPOS:  
     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);  
1096        }        }
1097      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1098      break;      break;
# Line 1074  while (cc < ccend) Line 1157  while (cc < ccend)
1157      break;      break;
1158      }      }
1159    
1160      /* Character iterators, which are not inside a repeated bracket,
1161         gets a private slot instead of allocating it on the stack. */
1162    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1163      {      {
1164      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
# Line 1104  while (cc < ccend) Line 1189  while (cc < ccend)
1189      cc += bracketlen;      cc += bracketlen;
1190      }      }
1191    }    }
1192    *private_data_start = private_data_ptr;
1193  }  }
1194    
1195  /* Returns with a frame_types (always < 0) if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1196  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL* needs_control_head)
1197  {  {
 pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);  
1198  int length = 0;  int length = 0;
1199  int possessive = 0;  int possessive = 0;
1200  BOOL stack_restore = FALSE;  BOOL stack_restore = FALSE;
# Line 1118  BOOL setmark_found = recursive; Line 1203  BOOL setmark_found = recursive;
1203  /* The last capture is a local variable even for recursions. */  /* The last capture is a local variable even for recursions. */
1204  BOOL capture_last_found = FALSE;  BOOL capture_last_found = FALSE;
1205    
1206  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1207    SLJIT_ASSERT(common->control_head_ptr != 0);
1208    *needs_control_head = TRUE;
1209    #else
1210    *needs_control_head = FALSE;
1211    #endif
1212    
1213    if (ccend == NULL)
1214    {    {
1215    possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1216    /* This is correct regardless of common->capture_last_ptr. */    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1217    capture_last_found = TRUE;      {
1218        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1219        /* This is correct regardless of common->capture_last_ptr. */
1220        capture_last_found = TRUE;
1221        }
1222      cc = next_opcode(common, cc);
1223    }    }
1224    
 cc = next_opcode(common, cc);  
1225  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1226  while (cc < ccend)  while (cc < ccend)
1227    switch(*cc)    switch(*cc)
# Line 1142  while (cc < ccend) Line 1238  while (cc < ccend)
1238      break;      break;
1239    
1240      case OP_MARK:      case OP_MARK:
1241        case OP_PRUNE_ARG:
1242        case OP_THEN_ARG:
1243      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1244      stack_restore = TRUE;      stack_restore = TRUE;
1245      if (!setmark_found)      if (!setmark_found)
# Line 1149  while (cc < ccend) Line 1247  while (cc < ccend)
1247        length += 2;        length += 2;
1248        setmark_found = TRUE;        setmark_found = TRUE;
1249        }        }
1250        if (common->control_head_ptr != 0)
1251          *needs_control_head = TRUE;
1252      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1253      break;      break;
1254    
# Line 1268  if (length > 0) Line 1368  if (length > 0)
1368  return stack_restore ? no_frame : no_stack;  return stack_restore ? no_frame : no_stack;
1369  }  }
1370    
1371  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)
1372  {  {
1373  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);  
1374  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1375  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1376  /* The last capture is a local variable even for recursions. */  /* The last capture is a local variable even for recursions. */
# Line 1283  SLJIT_UNUSED_ARG(stacktop); Line 1382  SLJIT_UNUSED_ARG(stacktop);
1382  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1383    
1384  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1385  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1386    cc = next_opcode(common, cc);    {
1387      ccend = bracketend(cc) - (1 + LINK_SIZE);
1388      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1389        cc = next_opcode(common, cc);
1390      }
1391    
1392  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1393  while (cc < ccend)  while (cc < ccend)
1394    switch(*cc)    switch(*cc)
# Line 1304  while (cc < ccend) Line 1408  while (cc < ccend)
1408      break;      break;
1409    
1410      case OP_MARK:      case OP_MARK:
1411        case OP_PRUNE_ARG:
1412        case OP_THEN_ARG:
1413      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1414      if (!setmark_found)      if (!setmark_found)
1415        {        {
# Line 1384  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), st Line 1490  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), st
1490  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1491  }  }
1492    
1493  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)
1494  {  {
1495  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1496  int size;  int size;
1497  pcre_uchar *alternative;  pcre_uchar *alternative;
1498  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1395  while (cc < ccend) Line 1501  while (cc < ccend)
1501    size = 0;    size = 0;
1502    switch(*cc)    switch(*cc)
1503      {      {
1504        case OP_KET:
1505        if (PRIVATE_DATA(cc) != 0)
1506          private_data_length++;
1507        cc += 1 + LINK_SIZE;
1508        break;
1509    
1510      case OP_ASSERT:      case OP_ASSERT:
1511      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1512      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1499  return private_data_length; Line 1611  return private_data_length;
1611  }  }
1612    
1613  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,
1614    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1615  {  {
1616  DEFINE_COMPILER;  DEFINE_COMPILER;
1617  int srcw[2];  int srcw[2];
# Line 1520  stacktop = STACK(stacktop - 1); Line 1632  stacktop = STACK(stacktop - 1);
1632    
1633  if (!save)  if (!save)
1634    {    {
1635    stackptr += sizeof(sljit_sw);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1636    if (stackptr < stacktop)    if (stackptr < stacktop)
1637      {      {
1638      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
# Line 1536  if (!save) Line 1648  if (!save)
1648    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1649    }    }
1650    
1651  while (status != end)  do
1652    {    {
1653    count = 0;    count = 0;
1654    switch(status)    switch(status)
# Line 1545  while (status != end) Line 1657  while (status != end)
1657      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1658      count = 1;      count = 1;
1659      srcw[0] = common->recursive_head_ptr;      srcw[0] = common->recursive_head_ptr;
1660        if (needs_control_head)
1661          {
1662          SLJIT_ASSERT(common->control_head_ptr != 0);
1663          count = 2;
1664          srcw[1] = common->control_head_ptr;
1665          }
1666      status = loop;      status = loop;
1667      break;      break;
1668    
# Line 1557  while (status != end) Line 1675  while (status != end)
1675    
1676      switch(*cc)      switch(*cc)
1677        {        {
1678          case OP_KET:
1679          if (PRIVATE_DATA(cc) != 0)
1680            {
1681            count = 1;
1682            srcw[0] = PRIVATE_DATA(cc);
1683            }
1684          cc += 1 + LINK_SIZE;
1685          break;
1686    
1687        case OP_ASSERT:        case OP_ASSERT:
1688        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1689        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1769  while (status != end) Line 1896  while (status != end)
1896        }        }
1897      }      }
1898    }    }
1899    while (status != end);
1900    
1901  if (save)  if (save)
1902    {    {
# Line 1802  if (save) Line 1930  if (save)
1930  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1931  }  }
1932    
1933    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1934    {
1935    pcre_uchar *end = bracketend(cc);
1936    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1937    
1938    /* Assert captures then. */
1939    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1940      current_offset = NULL;
1941    /* Conditional block does not. */
1942    if (*cc == OP_COND || *cc == OP_SCOND)
1943      has_alternatives = FALSE;
1944    
1945    cc = next_opcode(common, cc);
1946    if (has_alternatives)
1947      current_offset = common->then_offsets + (cc - common->start);
1948    
1949    while (cc < end)
1950      {
1951      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1952        cc = set_then_offsets(common, cc, current_offset);
1953      else
1954        {
1955        if (*cc == OP_ALT && has_alternatives)
1956          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1957        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1958          *current_offset = 1;
1959        cc = next_opcode(common, cc);
1960        }
1961      }
1962    
1963    return end;
1964    }
1965    
1966  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
1967  #undef CASE_ITERATOR_PRIVATE_DATA_2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
1968  #undef CASE_ITERATOR_PRIVATE_DATA_2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
# Line 1865  while (list_item) Line 2026  while (list_item)
2026  common->stubs = NULL;  common->stubs = NULL;
2027  }  }
2028    
2029  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2030  {  {
2031  DEFINE_COMPILER;  DEFINE_COMPILER;
2032    
2033  OP2(SLJIT_SUB | SLJIT_SET_E, CALL_COUNT, 0, CALL_COUNT, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, COUNT_MATCH, 0, COUNT_MATCH, 0, SLJIT_IMM, 1);
2034  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2035  }  }
2036    
# Line 1900  static SLJIT_INLINE void reset_ovector(c Line 2061  static SLJIT_INLINE void reset_ovector(c
2061  DEFINE_COMPILER;  DEFINE_COMPILER;
2062  struct sljit_label *loop;  struct sljit_label *loop;
2063  int i;  int i;
2064    
2065  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2066    SLJIT_ASSERT(length > 1);
2067  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2068  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_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
2069  if (length < 8)  if (length < 8)
2070    {    {
2071    for (i = 0; i < length; i++)    for (i = 1; i < length; i++)
2072      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2073    }    }
2074  else  else
2075    {    {
2076    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START - sizeof(sljit_sw));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2077    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2078    loop = LABEL();    loop = LABEL();
2079    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2080    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
# Line 1919  else Line 2082  else
2082    }    }
2083  }  }
2084    
2085    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2086    {
2087    DEFINE_COMPILER;
2088    struct sljit_label *loop;
2089    int i;
2090    
2091    SLJIT_ASSERT(length > 1);
2092    /* OVECTOR(1) contains the "string begin - 1" constant. */
2093    if (length > 2)
2094      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2095    if (length < 8)
2096      {
2097      for (i = 2; i < length; i++)
2098        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
2099      }
2100    else
2101      {
2102      GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2103      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2104      loop = LABEL();
2105      OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2106      OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
2107      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2108      }
2109    
2110    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2111    if (common->mark_ptr != 0)
2112      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2113    if (common->control_head_ptr != 0)
2114      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2115    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2116    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2117    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2118    }
2119    
2120    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2121    {
2122    while (current != NULL)
2123      {
2124      switch (current[-2])
2125        {
2126        case type_then_trap:
2127        break;
2128    
2129        case type_mark:
2130        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2131          return current[-4];
2132        break;
2133    
2134        default:
2135        SLJIT_ASSERT_STOP();
2136        break;
2137        }
2138      current = (sljit_sw*)current[-1];
2139      }
2140    return -1;
2141    }
2142    
2143  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2144  {  {
2145  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1975  DEFINE_COMPILER; Line 2196  DEFINE_COMPILER;
2196  struct sljit_jump *jump;  struct sljit_jump *jump;
2197    
2198  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);
2199  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
2200      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2201    
2202  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2203  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
# Line 1987  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJI Line 2209  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJI
2209  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));
2210    
2211  jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);  jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2212  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr + sizeof(sljit_sw), SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + (int)sizeof(sljit_sw)), SLJIT_SAVED_REG1, 0);
2213  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2214  OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);  OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2215  #endif  #endif
# Line 2155  return (bit < 256) ? ((0 << 8) | bit) : Line 2377  return (bit < 256) ? ((0 << 8) | bit) :
2377    
2378  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2379  {  {
2380  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2381  DEFINE_COMPILER;  DEFINE_COMPILER;
2382  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2383    
# Line 2242  else Line 2464  else
2464  JUMPHERE(jump);  JUMPHERE(jump);
2465  }  }
2466    
2467  static void read_char(compiler_common *common)  static void peek_char(compiler_common *common)
2468  {  {
2469  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2470  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2471  DEFINE_COMPILER;  DEFINE_COMPILER;
2472  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
# Line 2252  struct sljit_jump *jump; Line 2474  struct sljit_jump *jump;
2474  #endif  #endif
2475    
2476  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2477  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2478  if (common->utf)  if (common->utf)
2479    {    {
 #if defined COMPILE_PCRE8  
2480    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2481  #elif defined COMPILE_PCRE16    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
   jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);  
 #endif /* COMPILE_PCRE[8|16] */  
2482    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2483      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2484    JUMPHERE(jump);    JUMPHERE(jump);
2485    }    }
2486  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 }  
   
 static void peek_char(compiler_common *common)  
 {  
 /* Reads the character into TMP1, keeps STR_PTR.  
 Does not check STR_END. TMP2 Destroyed. */  
 DEFINE_COMPILER;  
 #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  
 struct sljit_jump *jump;  
 #endif  
2487    
2488  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  #if defined SUPPORT_UTF && defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  
2489  if (common->utf)  if (common->utf)
2490    {    {
2491  #if defined COMPILE_PCRE8    OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2492      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2493      /* TMP2 contains the high surrogate. */
2494      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2495      OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2496      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2497      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2498      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2499      JUMPHERE(jump);
2500      }
2501    #endif
2502    }
2503    
2504    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2505    
2506    static BOOL is_char7_bitset(const pcre_uint8* bitset, BOOL nclass)
2507    {
2508    /* Tells whether the character codes below 128 are enough
2509    to determine a match. */
2510    const pcre_uint8 value = nclass ? 0xff : 0;
2511    const pcre_uint8* end = bitset + 32;
2512    
2513    bitset += 16;
2514    do
2515      {
2516      if (*bitset++ != value)
2517        return FALSE;
2518      }
2519    while (bitset < end);
2520    return TRUE;
2521    }
2522    
2523    static void read_char7_type(compiler_common *common, BOOL full_read)
2524    {
2525    /* Reads the precise character type of a character into TMP1, if the character
2526    is less than 128. Otherwise it returns with zero. Does not check STR_END. The
2527    full_read argument tells whether characters above max are accepted or not. */
2528    DEFINE_COMPILER;
2529    struct sljit_jump *jump;
2530    
2531    SLJIT_ASSERT(common->utf);
2532    
2533    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2534    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2535    
2536    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2537    
2538    if (full_read)
2539      {
2540      jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2541      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2542      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2543      JUMPHERE(jump);
2544      }
2545    }
2546    
2547    #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2548    
2549    static void read_char_max(compiler_common *common, pcre_uint32 max, BOOL full_read)
2550    {
2551    /* Reads the precise value of a character into TMP1, if the character is
2552    less than or equal to max. Otherwise it returns with a value greater than max.
2553    Does not check STR_END. The full_read argument tells whether characters above
2554    max are accepted or not. */
2555    DEFINE_COMPILER;
2556    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2557    struct sljit_jump *jump;
2558    #endif
2559    
2560    SLJIT_UNUSED_ARG(full_read);
2561    SLJIT_UNUSED_ARG(max);
2562    
2563    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2564    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2565    
2566    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2567    if (common->utf)
2568      {
2569      if (max < 128 && !full_read)
2570        return;
2571    
2572    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2573  #elif defined COMPILE_PCRE16    if (max >= 0x800)
2574    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2575  #endif /* COMPILE_PCRE[8|16] */    else if (max < 128)
2576    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));      {
2577    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2578        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2579        }
2580      else
2581        {
2582        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2583        if (!full_read)
2584          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2585        else
2586          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2587        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2588        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2589        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2590        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2591        if (full_read)
2592          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2593        }
2594    JUMPHERE(jump);    JUMPHERE(jump);
2595    }    }
2596  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  #endif
2597    
2598    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2599    if (common->utf)
2600      {
2601      if (max >= 0x10000)
2602        {
2603        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2604        jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2605        /* TMP2 contains the high surrogate. */
2606        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2607        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2608        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2609        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2610        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2611        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2612        JUMPHERE(jump);
2613        return;
2614        }
2615    
2616      if (max < 0xd800 && !full_read)
2617        return;
2618    
2619      /* Skip low surrogate if necessary. */
2620      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2621      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2622      if (full_read)
2623        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2624      if (max >= 0xd800)
2625        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);
2626      JUMPHERE(jump);
2627      }
2628    #endif
2629    }
2630    
2631    static SLJIT_INLINE void read_char(compiler_common *common)
2632    {
2633    read_char_max(common, READ_CHAR_ANY, TRUE);
2634  }  }
2635    
2636  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common, BOOL full_read)
2637  {  {
2638  /* 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.
2639    The full_read argument tells whether characters above max are accepted or not. */
2640  DEFINE_COMPILER;  DEFINE_COMPILER;
2641  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2642  struct sljit_jump *jump;  struct sljit_jump *jump;
2643  #endif  #endif
2644    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2645    struct sljit_jump *jump2;
2646    #endif
2647    
2648  #ifdef SUPPORT_UTF  SLJIT_UNUSED_ARG(full_read);
2649    
2650    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2651    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2652    
2653    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2654  if (common->utf)  if (common->utf)
2655    {    {
   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  
2656    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2657    it is needed in most cases. */    it is needed in most cases. */
2658    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2659    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2660    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    if (!full_read)
2661    JUMPHERE(jump);      {
2662  #elif defined COMPILE_PCRE16      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2663    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2664    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2665    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2666    JUMPHERE(jump);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2667    /* Skip low surrogate if necessary. */      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
2668    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2669    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);      jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2670    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2671    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);      JUMPHERE(jump2);
2672    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);      }
2673  #elif defined COMPILE_PCRE32    else
2674    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);  
2675    JUMPHERE(jump);    JUMPHERE(jump);
 #endif /* COMPILE_PCRE[8|16|32] */  
2676    return;    return;
2677    }    }
2678  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2679  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
2680  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  
2681  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2682  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2683  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2684  #endif  #endif
2685  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2686  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if !defined COMPILE_PCRE8
2687  JUMPHERE(jump);  JUMPHERE(jump);
2688  #endif  #endif
2689    
2690    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2691    if (common->utf && full_read)
2692      {
2693      /* Skip low surrogate if necessary. */
2694      OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2695      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2696      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2697      JUMPHERE(jump);
2698      }
2699    #endif /* SUPPORT_UTF && COMPILE_PCRE16 */
2700  }  }
2701    
2702  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
# Line 2380  if (common->utf) Line 2734  if (common->utf)
2734  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));
2735  }  }
2736    
2737  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)
2738  {  {
2739  /* 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. */
2740  DEFINE_COMPILER;  DEFINE_COMPILER;
2741    struct sljit_jump *jump;
2742    
2743  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2744    {    {
2745    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2746    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpifmatch ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2747    }    }
2748  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2749    {    {
2750    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    if (jumpifmatch)
2751    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);      {
2752    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR));
2753    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2754    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));      }
2755      else
2756        {
2757        jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
2758        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2759        JUMPHERE(jump);
2760        }
2761    }    }
2762  else  else
2763    {    {
2764    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2765    add_jump(compiler, backtracks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));    add_jump(compiler, backtracks, CMP(jumpifmatch ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
2766    }    }
2767  }  }
2768    
# Line 2411  else Line 2772  else
2772  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2773  {  {
2774  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2775  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. */
2776  DEFINE_COMPILER;  DEFINE_COMPILER;
2777  struct sljit_jump *jump;  struct sljit_jump *jump;
2778    
2779  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2780    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2781    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2782    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2783    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2784    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2785    
2786  /* Searching for the first zero. */  /* Searching for the first zero. */
2787  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2788  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2789  /* Two byte sequence. */  /* Two byte sequence. */
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
2790  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));
2791  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2792    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2793    
2794    JUMPHERE(jump);
2795    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2796    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2797  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2798  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2799  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 JUMPHERE(jump);  
2800    
2801  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2802  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2803  /* Three byte sequence. */  /* Three byte sequence. */
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  
2804  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));
2805  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));  
2806  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2807    
2808  /* Four byte sequence. */  /* Four byte sequence. */
2809  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  JUMPHERE(jump);
2810  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2811  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2812    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2813    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2814  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  
2815  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2816  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(4));
2817    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2818    }
2819    
2820    static void do_utfreadchar16(compiler_common *common)
2821    {
2822    /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2823    of the character (>= 0xc0). Return value in TMP1. */
2824    DEFINE_COMPILER;
2825    struct sljit_jump *jump;
2826    
2827    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2828    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2829    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2830    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2831  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);  
2832  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2833  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));  
2834  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));  /* Searching for the first zero. */
2835    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2836    jump = JUMP(SLJIT_C_NOT_ZERO);
2837    /* Two byte sequence. */
2838    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2839    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2840    
2841    JUMPHERE(jump);
2842    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x400);
2843    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
2844    /* This code runs only in 8 bit mode. No need to shift the value. */
2845    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2846    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2847    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2848    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2849  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2850  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2851  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));  /* Three byte sequence. */
2852    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2853  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2854  }  }
2855    
# Line 2482  jump = JUMP(SLJIT_C_NOT_ZERO); Line 2869  jump = JUMP(SLJIT_C_NOT_ZERO);
2869  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2870  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));
2871  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
2872    /* The upper 5 bits are known at this point. */
2873    compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x3);
2874  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2875  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2876  OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);  OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
 compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  
2877  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2878  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2879    
2880  JUMPHERE(compare);  JUMPHERE(compare);
2881  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2882  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2883    
2884  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
 OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 }  
   
 #elif defined COMPILE_PCRE16  
   
 static void do_utfreadchar(compiler_common *common)  
 {  
 /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char  
 of the character (>= 0xd800). Return char value in TMP1, length - 1 in TMP2. */  
 DEFINE_COMPILER;  
 struct sljit_jump *jump;  
   
 sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  
 jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);  
 /* Do nothing, only return. */  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
   
2885  JUMPHERE(jump);  JUMPHERE(jump);
2886  /* Combine two 16 bit characters. */  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2887  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2888  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);  
2889  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2890  }  }
2891    
2892  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE8 */
2893    
2894  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2895    
# Line 2603  if (firstline) Line 2964  if (firstline)
2964      mainloop = LABEL();      mainloop = LABEL();
2965      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
2966      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2967      read_char(common);      read_char_max(common, common->nlmax, TRUE);
2968      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
2969      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2970      JUMPHERE(end);      JUMPHERE(end);
# Line 2679  if (newlinecheck) Line 3040  if (newlinecheck)
3040  return mainloop;  return mainloop;
3041  }  }
3042    
3043  #define MAX_N_CHARS 3  static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, int max_chars)
   
 static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)  
3044  {  {
3045  DEFINE_COMPILER;  /* Recursive function, which scans prefix literals. */
3046  struct sljit_label *start;  int len, repeat, len_save, consumed = 0;
3047  struct sljit_jump *quit;  pcre_uint32 caseless, chr, mask;
3048  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uchar *alternative, *cc_save;
3049  pcre_uchar *cc = common->start + 1 + LINK_SIZE;  BOOL last, any;
 int location = 0;  
 pcre_int32 len, c, bit, caseless;  
 int must_stop;  
   
 /* We do not support alternatives now. */  
 if (*(common->start + GET(common->start, 1)) == OP_ALT)  
   return FALSE;  
3050    
3051    repeat = 1;
3052  while (TRUE)  while (TRUE)
3053    {    {
3054      last = TRUE;
3055      any = FALSE;
3056    caseless = 0;    caseless = 0;
3057    must_stop = 1;    switch (*cc)
   switch(*cc)  
3058      {      {
     case OP_CHAR:  
     must_stop = 0;  
     cc++;  
     break;  
   
3059      case OP_CHARI:      case OP_CHARI:
3060      caseless = 1;      caseless = 1;
3061      must_stop = 0;      case OP_CHAR:
3062        last = FALSE;
3063      cc++;      cc++;
3064      break;      break;
3065    
# Line 2734  while (TRUE) Line 3084  while (TRUE)
3084      cc++;      cc++;
3085      break;      break;
3086    
3087        case OP_EXACTI:
3088        caseless = 1;
3089      case OP_EXACT:      case OP_EXACT:
3090        repeat = GET2(cc, 1);
3091        last = FALSE;
3092      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
3093      break;      break;
3094    
# Line 2745  while (TRUE) Line 3099  while (TRUE)
3099      cc++;      cc++;
3100      break;      break;
3101    
3102      case OP_EXACTI:      case OP_KET:
3103      caseless = 1;      cc += 1 + LINK_SIZE;
3104      cc += 1 + IMM2_SIZE;      continue;
3105    
3106        case OP_ALT:
3107        cc += GET(cc, 1);
3108        continue;
3109    
3110        case OP_ONCE:
3111        case OP_ONCE_NC:
3112        case OP_BRA:
3113        case OP_BRAPOS:
3114        case OP_CBRA:
3115        case OP_CBRAPOS:
3116        alternative = cc + GET(cc, 1);
3117        while (*alternative == OP_ALT)
3118          {
3119          max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, max_chars);
3120          if (max_chars == 0)
3121            return consumed;
3122          alternative += GET(alternative, 1);
3123          }
3124    
3125        if (*cc == OP_CBRA || *cc == OP_CBRAPOS)
3126          cc += IMM2_SIZE;
3127        cc += 1 + LINK_SIZE;
3128        continue;
3129    
3130        case OP_CLASS:
3131        case OP_NCLASS:
3132        any = TRUE;
3133        cc += 1 + 32 / sizeof(pcre_uchar);
3134      break;      break;
3135    
3136      default:  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3137      must_stop = 2;      case OP_XCLASS:
3138        any = TRUE;
3139        cc += GET(cc, 1);
3140      break;      break;
3141    #endif
3142    
3143        case OP_NOT_DIGIT:
3144        case OP_DIGIT:
3145        case OP_NOT_WHITESPACE:
3146        case OP_WHITESPACE:
3147        case OP_NOT_WORDCHAR:
3148        case OP_WORDCHAR:
3149        case OP_ANY:
3150        case OP_ALLANY:
3151        any = TRUE;
3152        cc++;
3153        break;
3154    
3155    #ifdef SUPPORT_UCP
3156        case OP_NOTPROP:
3157        case OP_PROP:
3158        any = TRUE;
3159        cc += 1 + 2;
3160        break;
3161    #endif
3162    
3163        case OP_TYPEEXACT:
3164        repeat = GET2(cc, 1);
3165        cc += 1 + IMM2_SIZE;
3166        continue;
3167    
3168        default:
3169        return consumed;
3170      }      }
3171    
3172    if (must_stop == 2)    if (any)
3173        break;      {
3174    #ifdef SUPPORT_UTF
3175        if (common->utf) return consumed;
3176    #endif
3177    #if defined COMPILE_PCRE8
3178        mask = 0xff;
3179    #elif defined COMPILE_PCRE16
3180        mask = 0xffff;
3181    #elif defined COMPILE_PCRE32
3182        mask = 0xffffffff;
3183    #else
3184        SLJIT_ASSERT_STOP();
3185    #endif
3186    
3187        do
3188          {
3189          chars[0] = mask;
3190          chars[1] = mask;
3191    
3192          if (--max_chars == 0)
3193            return consumed;
3194          consumed++;
3195          chars += 2;
3196          }
3197        while (--repeat > 0);
3198    
3199        repeat = 1;
3200        continue;
3201        }
3202    
3203    len = 1;    len = 1;
3204  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3205    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3206  #endif  #endif
3207    
3208    if (caseless && char_has_othercase(common, cc))    if (caseless != 0 && char_has_othercase(common, cc))
3209      {      {
3210      caseless = char_get_othercase_bit(common, cc);      caseless = char_get_othercase_bit(common, cc);
3211      if (caseless == 0)      if (caseless == 0)
3212        return FALSE;        return consumed;
3213  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3214      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
3215  #else  #else
# Line 2780  while (TRUE) Line 3222  while (TRUE)
3222    else    else
3223      caseless = 0;      caseless = 0;
3224    
3225    while (len > 0 && location < MAX_N_CHARS * 2)    len_save = len;
3226      {    cc_save = cc;
3227      c = *cc;    while (TRUE)
3228      bit = 0;      {
3229      if (len == (caseless & 0xff))      do
3230        {        {
3231        bit = caseless >> 8;        chr = *cc;
3232        c |= bit;  #ifdef COMPILE_PCRE32
3233          if (SLJIT_UNLIKELY(chr == NOTACHAR))
3234            return consumed;
3235    #endif
3236          mask = 0;
3237          if (len == (caseless & 0xff))
3238            {
3239            mask = caseless >> 8;
3240            chr |= mask;
3241            }
3242    
3243          if (chars[0] == NOTACHAR)
3244            {
3245            chars[0] = chr;
3246            chars[1] = mask;
3247            }
3248          else
3249            {
3250            mask |= chars[0] ^ chr;
3251            chr |= mask;
3252            chars[0] = chr;
3253            chars[1] |= mask;
3254            }
3255    
3256          len--;
3257          if (--max_chars == 0)
3258            return consumed;
3259          consumed++;
3260          chars += 2;
3261          cc++;
3262        }        }
3263        while (len > 0);
3264    
3265      chars[location] = c;      if (--repeat == 0)
3266      chars[location + 1] = bit;        break;
3267    
3268      len--;      len = len_save;
3269      location += 2;      cc = cc_save;
     cc++;  
3270      }      }
3271    
3272    if (location >= MAX_N_CHARS * 2 || must_stop != 0)    repeat = 1;
3273      if (last)
3274        return consumed;
3275      }
3276    }
3277    
3278    #define MAX_N_CHARS 16
3279    
3280    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3281    {
3282    DEFINE_COMPILER;
3283    struct sljit_label *start;
3284    struct sljit_jump *quit;
3285    pcre_uint32 chars[MAX_N_CHARS * 2];
3286    pcre_uint8 ones[MAX_N_CHARS];
3287    pcre_uint32 mask;
3288    int i, max;
3289    int offsets[3];
3290    
3291    for (i = 0; i < MAX_N_CHARS; i++)
3292      {
3293      chars[i << 1] = NOTACHAR;
3294      chars[(i << 1) + 1] = 0;
3295      }
3296    
3297    max = scan_prefix(common, common->start, chars, MAX_N_CHARS);
3298    
3299    if (max <= 1)
3300      return FALSE;
3301    
3302    for (i = 0; i < max; i++)
3303      {
3304      mask = chars[(i << 1) + 1];
3305      ones[i] = ones_in_half_byte[mask & 0xf];
3306      mask >>= 4;
3307      while (mask != 0)
3308        {
3309        ones[i] += ones_in_half_byte[mask & 0xf];
3310        mask >>= 4;
3311        }
3312      }
3313    
3314    offsets[0] = -1;
3315    /* Scan forward. */
3316    for (i = 0; i < max; i++)
3317      if (ones[i] <= 2) {
3318        offsets[0] = i;
3319      break;      break;
3320    }    }
3321    
3322  /* At least two characters are required. */  if (offsets[0] == -1)
3323  if (location < 2 * 2)    return FALSE;
3324      return FALSE;  
3325    /* Scan backward. */
3326    offsets[1] = -1;
3327    for (i = max - 1; i > offsets[0]; i--)
3328      if (ones[i] <= 2) {
3329        offsets[1] = i;
3330        break;
3331      }
3332    
3333    offsets[2] = -1;
3334    if (offsets[1] >= 0)
3335      {
3336      /* Scan from middle. */
3337      for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3338        if (ones[i] <= 2)
3339          {
3340          offsets[2] = i;
3341          break;
3342          }
3343    
3344      if (offsets[2] == -1)
3345        {
3346        for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3347          if (ones[i] <= 2)
3348            {
3349            offsets[2] = i;
3350            break;
3351            }
3352        }
3353      }
3354    
3355    SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3356    SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3357    
3358    chars[0] = chars[offsets[0] << 1];
3359    chars[1] = chars[(offsets[0] << 1) + 1];
3360    if (offsets[2] >= 0)
3361      {
3362      chars[2] = chars[offsets[2] << 1];
3363      chars[3] = chars[(offsets[2] << 1) + 1];
3364      }
3365    if (offsets[1] >= 0)
3366      {
3367      chars[4] = chars[offsets[1] << 1];
3368      chars[5] = chars[(offsets[1] << 1) + 1];
3369      }
3370    
3371    max -= 1;
3372  if (firstline)  if (firstline)
3373    {    {
3374    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3375    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3376    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS(max));
3377    }    }
3378  else  else
3379    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3380    
3381  start = LABEL();  start = LABEL();
3382  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3383    
3384  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
3385  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  if (offsets[1] >= 0)
3386      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3387  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));
3388    
3389  if (chars[1] != 0)  if (chars[1] != 0)
3390    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3391  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3392  if (location > 2 * 2)  if (offsets[2] >= 0)
3393    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));
3394  if (chars[3] != 0)  
3395    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);  if (offsets[1] >= 0)
 CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);  
 if (location > 2 * 2)  
3396    {    {
3397    if (chars[5] != 0)    if (chars[5] != 0)
3398      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3399    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
3400      }
3401    
3402    if (offsets[2] >= 0)
3403      {
3404      if (chars[3] != 0)
3405        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3406      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3407    }    }
3408  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));
3409    
# Line 2842  JUMPHERE(quit); Line 3412  JUMPHERE(quit);
3412  if (firstline)  if (firstline)
3413    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3414  else  else
3415    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3416  return TRUE;  return TRUE;
3417  }  }
3418    
# Line 2962  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_ Line 3532  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_
3532  skip_char_back(common);  skip_char_back(common);
3533    
3534  loop = LABEL();  loop = LABEL();
3535  read_char(common);  read_char_max(common, common->nlmax, TRUE);
3536  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3537  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3538    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
# Line 2991  if (firstline) Line 3561  if (firstline)
3561    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3562  }  }
3563    
3564  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks);
3565    
3566  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, pcre_uint8 *start_bits, BOOL firstline)
3567  {  {
3568  DEFINE_COMPILER;  DEFINE_COMPILER;
3569  struct sljit_label *start;  struct sljit_label *start;
3570  struct sljit_jump *quit;  struct sljit_jump *quit;
3571  struct sljit_jump *found = NULL;  struct sljit_jump *found = NULL;
3572  jump_list *matches = NULL;  jump_list *matches = NULL;
 pcre_uint8 inverted_start_bits[32];  
 int i;  
3573  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3574  struct sljit_jump *jump;  struct sljit_jump *jump;
3575  #endif  #endif
3576    
 for (i = 0; i < 32; ++i)  
   inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);  
   
3577  if (firstline)  if (firstline)
3578    {    {
3579    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
# Line 3024  if (common->utf) Line 3589  if (common->utf)
3589    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3590  #endif  #endif
3591    
3592  if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))  if (!check_class_ranges(common, start_bits, (start_bits[31] & 0x80) != 0, TRUE, &matches))
3593    {    {
3594  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3595    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
# Line 3033  if (!check_class_ranges(common, inverted Line 3598  if (!check_class_ranges(common, inverted
3598  #endif  #endif
3599    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3600    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3601    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
3602    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3603    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);
3604    found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
# Line 3282  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSE Line 3847  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSE
3847  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3848  }  }
3849    
3850  /*  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks)
   range format:  
   
   ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).  
   ranges[1] = first bit (0 or 1)  
   ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)  
 */  
   
 static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)  
3851  {  {
3852  DEFINE_COMPILER;  DEFINE_COMPILER;
3853  struct sljit_jump *jump;  int ranges[MAX_RANGE_SIZE];
3854    pcre_uint8 bit, cbit, all;
3855    int i, byte, length = 0;
3856    
3857    bit = bits[0] & 0x1;
3858    /* All bits will be zero or one (since bit is zero or one). */
3859    all = -bit;
3860    
3861    for (i = 0; i < 256; )
3862      {
3863      byte = i >> 3;
3864      if ((i & 0x7) == 0 && bits[byte] == all)
3865        i += 8;
3866      else
3867        {
3868        cbit = (bits[byte] >> (i & 0x7)) & 0x1;
3869        if (cbit != bit)
3870          {
3871          if (length >= MAX_RANGE_SIZE)
3872            return FALSE;
3873          ranges[length] = i;
3874          length++;
3875          bit = cbit;
3876          all = -cbit;
3877          }
3878        i++;
3879        }
3880      }
3881    
3882    if (((bit == 0) && nclass) || ((bit == 1) && !nclass))
3883      {
3884      if (length >= MAX_RANGE_SIZE)
3885        return FALSE;
3886      ranges[length] = 256;
3887      length++;
3888      }
3889    
3890  if (ranges[0] < 0)  if (length < 0 || length > 4)
3891    return FALSE;    return FALSE;
3892    
3893  switch(ranges[0])  bit = bits[0] & 0x1;
3894    if (invert) bit ^= 0x1;
3895    
3896    /* No character is accepted. */
3897    if (length == 0 && bit == 0)
3898      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
3899    
3900    switch(length)
3901    {    {
3902      case 0:
3903      /* When bit != 0, all characters are accepted. */
3904      return TRUE;
3905    
3906    case 1:    case 1:
3907    if (readch)    add_jump(compiler, backtracks, CMP(bit == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
     read_char(common);  
   add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));  
3908    return TRUE;    return TRUE;
3909    
3910    case 2:    case 2:
3911    if (readch)    if (ranges[0] + 1 != ranges[1])
3912      read_char(common);      {
3913    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
3914    add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));      add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
3915        }
3916      else
3917        add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
3918    return TRUE;    return TRUE;
3919    
3920    case 4:    case 3:
3921    if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])    if (bit != 0)
3922      {      {
3923      if (readch)      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3924        read_char(common);      if (ranges[0] + 1 != ranges[1])
     if (ranges[1] != 0)  
3925        {        {
3926        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
3927        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
3928        }        }
3929      else      else
3930        {        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
       jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);  
       add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));  
       JUMPHERE(jump);  
       }  
3931      return TRUE;      return TRUE;
3932      }      }
3933    if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))  
3934      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[0]));
3935      if (ranges[1] + 1 != ranges[2])
3936      {      {
3937      if (readch)      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1]);
3938        read_char(common);      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1]));
     OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);  
     OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);  
     add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));  
     return TRUE;  
3939      }      }
3940    return FALSE;    else
3941        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1]));
3942    default:    return TRUE;
   return FALSE;  
   }  
 }  
   
 static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)  
 {  
 int i, bit, length;  
 const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;  
   
 bit = ctypes[0] & flag;  
 ranges[0] = -1;  
 ranges[1] = bit != 0 ? 1 : 0;  
 length = 0;  
3943    
3944  for (i = 1; i < 256; i++)    case 4:
3945    if ((ctypes[i] & flag) != bit)    if ((ranges[1] - ranges[0]) == (ranges[3] - ranges[2])
3946          && (ranges[0] | (ranges[2] - ranges[0])) == ranges[2]
3947          && is_powerof2(ranges[2] - ranges[0]))
3948      {      {
3949      if (length >= MAX_RANGE_SIZE)      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[0]);
3950        return;      if (ranges[2] + 1 != ranges[3])
3951      ranges[2 + length] = i;        {
3952      length++;        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3953      bit ^= flag;        add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3954          }
3955        else
3956          add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3957        return TRUE;
3958      }      }
3959    
3960  if (bit != 0)    if (bit != 0)
   {  
   if (length >= MAX_RANGE_SIZE)  
     return;  
   ranges[2 + length] = 256;  
   length++;  
   }  
 ranges[0] = length;  
 }  
   
 static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)  
 {  
 int ranges[2 + MAX_RANGE_SIZE];  
 pcre_uint8 bit, cbit, all;  
 int i, byte, length = 0;  
   
 bit = bits[0] & 0x1;  
 ranges[1] = bit;  
 /* Can be 0 or 255. */  
 all = -bit;  
   
 for (i = 0; i < 256; )  
   {  
   byte = i >> 3;  
   if ((i & 0x7) == 0 && bits[byte] == all)  
     i += 8;  
   else  
3961      {      {
3962      cbit = (bits[byte] >> (i & 0x7)) & 0x1;      i = 0;
3963      if (cbit != bit)      if (ranges[0] + 1 != ranges[1])
3964          {
3965          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
3966          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
3967          i = ranges[0];
3968          }
3969        else
3970          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
3971    
3972        if (ranges[2] + 1 != ranges[3])
3973        {        {
3974        if (length >= MAX_RANGE_SIZE)        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - i);
3975          return FALSE;        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
       ranges[2 + length] = i;  
       length++;  
       bit = cbit;  
       all = -cbit;  
3976        }        }
3977      i++;      else
3978          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2] - i));
3979        return TRUE;
3980      }      }
   }  
3981    
3982  if (((bit == 0) && nclass) || ((bit == 1) && !nclass))    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
3983    {    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[0]));
3984    if (length >= MAX_RANGE_SIZE)    if (ranges[1] + 1 != ranges[2])
3985      return FALSE;      {
3986    ranges[2 + length] = 256;      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]);
3987    length++;      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1]));
3988    }      }
3989  ranges[0] = length;    else
3990        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
3991      return TRUE;
3992    
3993  return check_ranges(common, ranges, backtracks, FALSE);    default:
3994      SLJIT_ASSERT_STOP();
3995      return FALSE;
3996      }
3997  }  }
3998    
3999  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
# Line 3806  static void compile_xclass_matchingpath( Line 4381  static void compile_xclass_matchingpath(
4381  {  {
4382  DEFINE_COMPILER;  DEFINE_COMPILER;
4383  jump_list *found = NULL;  jump_list *found = NULL;
4384  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;
4385  pcre_int32 c, charoffset;  pcre_int32 c, charoffset;
 const pcre_uint32 *other_cases;  
4386  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4387  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4388  int compares, invertcmp, numberofcmps;  int compares, invertcmp, numberofcmps;
4389    
4390  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4391  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4392  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4393  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4394    const pcre_uint32 *other_cases;
4395  pcre_int32 typeoffset;  pcre_int32 typeoffset;
4396  #endif  #endif
4397    
# Line 3824  pcre_int32 typeoffset; Line 4400  pcre_int32 typeoffset;
4400  detect_partial_match(common, backtracks);  detect_partial_match(common, backtracks);
4401  read_char(common);  read_char(common);
4402    
4403  if ((*cc++ & XCL_MAP) != 0)  cc++;
4404    if ((cc[-1] & XCL_HASPROP) == 0)
4405    {    {
4406    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    if ((cc[-1] & XCL_MAP) != 0)
4407  #ifndef COMPILE_PCRE8      {
4408    jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4409  #elif defined SUPPORT_UTF  #ifdef SUPPORT_UCP
4410    if (common->utf)      charsaved = TRUE;
     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
4411  #endif  #endif
4412        if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, FALSE, backtracks))
4413          {
4414          jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4415    
4416          OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4417          OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4418          OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4419          OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4420          OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4421          add_jump(compiler, &found, JUMP(SLJIT_C_NOT_ZERO));
4422          add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4423    
4424          JUMPHERE(jump);
4425          }
4426        else
4427          add_jump(compiler, &found, CMP(SLJIT_C_LESS_EQUAL, TMP3, 0, SLJIT_IMM, 0xff));
4428    
4429    if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, list))      OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
4430        cc += 32 / sizeof(pcre_uchar);
4431        }
4432      else
4433        add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0xff));
4434      }
4435    else if ((cc[-1] & XCL_MAP) != 0)
4436      {
4437      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4438    #ifdef SUPPORT_UCP
4439      charsaved = TRUE;
4440    #endif
4441      if (!check_class_ranges(common, (const pcre_uint8 *)cc, FALSE, TRUE, list))
4442      {      {
4443    #ifdef COMPILE_PCRE8
4444        SLJIT_ASSERT(common->utf);
4445    #endif
4446        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4447    
4448      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4449      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4450      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4451      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4452      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);
4453      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
     }  
4454    
 #ifndef COMPILE_PCRE8  
   JUMPHERE(jump);  
 #elif defined SUPPORT_UTF  
   if (common->utf)  
4455      JUMPHERE(jump);      JUMPHERE(jump);
4456  #endif      }
4457    
4458    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
 #ifdef SUPPORT_UCP  
   charsaved = TRUE;  
 #endif  
4459    cc += 32 / sizeof(pcre_uchar);    cc += 32 / sizeof(pcre_uchar);
4460    }    }
4461    
# Line 3911  while (*cc != XCL_END) Line 4513  while (*cc != XCL_END)
4513        case PT_SPACE:        case PT_SPACE:
4514        case PT_PXSPACE:        case PT_PXSPACE:
4515        case PT_WORD:        case PT_WORD:
4516          case PT_PXGRAPH:
4517          case PT_PXPRINT:
4518          case PT_PXPUNCT:
4519        needstype = TRUE;        needstype = TRUE;
4520        needschar = TRUE;        needschar = TRUE;
4521        break;        break;
# Line 4098  while (*cc != XCL_END) Line 4703  while (*cc != XCL_END)
4703    
4704        case PT_SPACE:        case PT_SPACE:
4705        case PT_PXSPACE:        case PT_PXSPACE:
       if (*cc == PT_SPACE)  
         {  
         OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  
         jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 11 - charoffset);  
         }  
4706        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4707        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 13 - 9);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd - 0x9);
4708        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4709        if (*cc == PT_SPACE)  
4710          JUMPHERE(jump);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x9);
4711          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4712    
4713          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x9);
4714          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4715    
4716        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4717        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl);
# Line 4199  while (*cc != XCL_END) Line 4803  while (*cc != XCL_END)
4803        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4804        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4805        break;        break;
4806    
4807          case PT_PXGRAPH:
4808          /* C and Z groups are the farthest two groups. */
4809          SET_TYPE_OFFSET(ucp_Ll);
4810          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4811          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4812    
4813          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4814    
4815          /* In case of ucp_Cf, we overwrite the result. */
4816          SET_CHAR_OFFSET(0x2066);
4817          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4818          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4819    
4820          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4821          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4822    
4823          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x2066);
4824          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4825    
4826          JUMPHERE(jump);
4827          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4828          break;
4829    
4830          case PT_PXPRINT:
4831          /* C and Z groups are the farthest two groups. */
4832          SET_TYPE_OFFSET(ucp_Ll);
4833          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4834          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4835    
4836          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Ll);
4837          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_NOT_EQUAL);
4838    
4839          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4840    
4841          /* In case of ucp_Cf, we overwrite the result. */
4842          SET_CHAR_OFFSET(0x2066);
4843          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4844          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4845    
4846          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4847          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4848    
4849          JUMPHERE(jump);
4850          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4851          break;
4852    
4853          case PT_PXPUNCT:
4854          SET_TYPE_OFFSET(ucp_Sc);
4855          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Sc);
4856          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4857    
4858          SET_CHAR_OFFSET(0);
4859          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xff);
4860          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4861    
4862          SET_TYPE_OFFSET(ucp_Pc);
4863          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ps - ucp_Pc);
4864          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4865          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4866          break;
4867        }        }
4868      cc += 2;      cc += 2;
4869      }      }
# Line 4230  struct sljit_label *label; Line 4895  struct sljit_label *label;
4895  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4896  pcre_uchar propdata[5];  pcre_uchar propdata[5];
4897  #endif  #endif
4898  #endif  #endif /* SUPPORT_UTF */
4899    
4900  switch(type)  switch(type)
4901    {    {
# Line 4255  switch(type) Line 4920  switch(type)
4920    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
4921    case OP_DIGIT:    case OP_DIGIT:
4922    /* Digits are usually 0-9, so it is worth to optimize them. */    /* Digits are usually 0-9, so it is worth to optimize them. */
   if (common->digits[0] == -2)  
     get_ctype_ranges(common, ctype_digit, common->digits);  
4923    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4924    /* Flip the starting bit in the negative case. */  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
4925    if (type == OP_NOT_DIGIT)    if (common->utf && is_char7_bitset((const pcre_uint8*)common->ctypes - cbit_length + cbit_digit, FALSE))
4926      common->digits[1] ^= 1;      read_char7_type(common, type == OP_NOT_DIGIT);
4927    if (!check_ranges(common, common->digits, backtracks, TRUE))    else
4928      {  #endif
4929      read_char8_type(common);      read_char8_type(common, type == OP_NOT_DIGIT);
4930      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);      /* Flip the starting bit in the negative case. */
4931      add_jump(compiler, backtracks, JUMP(type == OP_DIGIT ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);
4932      }    add_jump(compiler, backtracks, JUMP(type == OP_DIGIT ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
   if (type == OP_NOT_DIGIT)  
     common->digits[1] ^= 1;  
4933    return cc;    return cc;
4934    
4935    case OP_NOT_WHITESPACE:    case OP_NOT_WHITESPACE:
4936    case OP_WHITESPACE:    case OP_WHITESPACE:
4937    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4938    read_char8_type(common);  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
4939      if (common->utf && is_char7_bitset((const pcre_uint8*)common->ctypes - cbit_length + cbit_space, FALSE))
4940        read_char7_type(common, type == OP_NOT_WHITESPACE);
4941      else
4942    #endif
4943        read_char8_type(common, type == OP_NOT_WHITESPACE);
4944    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_space);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_space);
4945    add_jump(compiler, backtracks, JUMP(type == OP_WHITESPACE ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_WHITESPACE ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
4946    return cc;    return cc;
# Line 4282  switch(type) Line 4948  switch(type)
4948    case OP_NOT_WORDCHAR:    case OP_NOT_WORDCHAR:
4949    case OP_WORDCHAR:    case OP_WORDCHAR:
4950    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4951    read_char8_type(common);  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
4952      if (common->utf && is_char7_bitset((const pcre_uint8*)common->ctypes - cbit_length + cbit_word, FALSE))
4953        read_char7_type(common, type == OP_NOT_WORDCHAR);
4954      else
4955    #endif
4956        read_char8_type(common, type == OP_NOT_WORDCHAR);
4957    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_word);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_word);
4958    add_jump(compiler, backtracks, JUMP(type == OP_WORDCHAR ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_WORDCHAR ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
4959    return cc;    return cc;
4960    
4961    case OP_ANY:    case OP_ANY:
4962    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4963    read_char(common);    read_char_max(common, common->nlmax, TRUE);
4964    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4965      {      {
4966      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);
# Line 4345  switch(type) Line 5016  switch(type)
5016  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
5017    case OP_NOTPROP:    case OP_NOTPROP:
5018    case OP_PROP:    case OP_PROP:
5019    propdata[0] = 0;    propdata[0] = XCL_HASPROP;
5020    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;
5021    propdata[2] = cc[0];    propdata[2] = cc[0];
5022    propdata[3] = cc[1];    propdata[3] = cc[1];
# Line 4357  switch(type) Line 5028  switch(type)
5028    
5029    case OP_ANYNL:    case OP_ANYNL:
5030    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5031    read_char(common);    read_char_max(common, common->bsr_nlmax, FALSE);
5032    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
5033    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
5034    end_list = NULL;    end_list = NULL;
# Line 4379  switch(type) Line 5050  switch(type)
5050    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
5051    case OP_HSPACE:    case OP_HSPACE:
5052    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5053    read_char(common);    read_char_max(common, 0x3000, type == OP_NOT_HSPACE);
5054    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));
5055    add_jump(compiler, backtracks, JUMP(type == OP_NOT_HSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_NOT_HSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
5056    return cc;    return cc;
# Line 4387  switch(type) Line 5058  switch(type)
5058    case OP_NOT_VSPACE:    case OP_NOT_VSPACE:
5059    case OP_VSPACE:    case OP_VSPACE:
5060    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5061    read_char(common);    read_char_max(common, 0x2029, type == OP_NOT_VSPACE);
5062    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));
5063    add_jump(compiler, backtracks, JUMP(type == OP_NOT_VSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_NOT_VSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
5064    return cc;    return cc;
# Line 4486  switch(type) Line 5157  switch(type)
5157      else      else
5158        {        {
5159        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);
5160        read_char(common);        read_char_max(common, common->nlmax, TRUE);
5161        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, STR_END, 0));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, STR_END, 0));
5162        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
5163        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 4534  switch(type) Line 5205  switch(type)
5205    else    else
5206      {      {
5207      skip_char_back(common);      skip_char_back(common);
5208      read_char(common);      read_char_max(common, common->nlmax, TRUE);
5209      check_newlinechar(common, common->nltype, backtracks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
5210      }      }
5211    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
# Line 4609  switch(type) Line 5280  switch(type)
5280  #endif  #endif
5281      return byte_sequence_compare(common, type == OP_CHARI, cc, &context, backtracks);      return byte_sequence_compare(common, type == OP_CHARI, cc, &context, backtracks);
5282      }      }
5283    
5284    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
   read_char(common);  
5285  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
5286    if (common->utf)    if (common->utf)
5287      {      {
# Line 4619  switch(type) Line 5290  switch(type)
5290    else    else
5291  #endif  #endif
5292      c = *cc;      c = *cc;
5293    
5294    if (type == OP_CHAR || !char_has_othercase(common, cc))    if (type == OP_CHAR || !char_has_othercase(common, cc))
5295      {      {
5296        read_char_max(common, c, FALSE);
5297      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c));
5298      return cc + length;      return cc + length;
5299      }      }
5300    oc = char_othercase(common, c);    oc = char_othercase(common, c);
5301      read_char_max(common, c > oc ? c : oc, FALSE);
5302    bit = c ^ oc;    bit = c ^ oc;
5303    if (is_powerof2(bit))    if (is_powerof2(bit))
5304      {      {
# Line 4632  switch(type) Line 5306  switch(type)
5306      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));
5307      return cc + length;      return cc + length;
5308      }      }
5309    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c);    jump[0] = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c);
5310    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);    add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, oc));
5311    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);    JUMPHERE(jump[0]);
   OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);  
   add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));  
5312    return cc + length;    return cc + length;
5313    
5314    case OP_NOT:    case OP_NOT:
# Line 4671  switch(type) Line 5343  switch(type)
5343  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
5344        {        {
5345        GETCHARLEN(c, cc, length);        GETCHARLEN(c, cc, length);
       read_char(common);  
5346        }        }
5347      }      }
5348    else    else
5349  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
     {  
     read_char(common);  
5350      c = *cc;      c = *cc;
     }  
5351    
5352    if (type == OP_NOT || !char_has_othercase(common, cc))    if (type == OP_NOT || !char_has_othercase(common, cc))
5353        {
5354        read_char_max(common, c, TRUE);
5355      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c));      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c));
5356        }
5357    else    else
5358      {      {
5359      oc = char_othercase(common, c);      oc = char_othercase(common, c);
5360        read_char_max(common, c > oc ? c : oc, TRUE);
5361      bit = c ^ oc;      bit = c ^ oc;
5362      if (is_powerof2(bit))      if (is_powerof2(bit))
5363        {        {
# Line 4703  switch(type) Line 5375  switch(type)
5375    case OP_CLASS:    case OP_CLASS:
5376    case OP_NCLASS:    case OP_NCLASS:
5377    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5378    read_char(common);  
5379    if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, backtracks))  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5380      bit = (common->utf && is_char7_bitset((const pcre_uint8 *)cc, type == OP_NCLASS)) ? 127 : 255;
5381      read_char_max(common, bit, type == OP_NCLASS);
5382    #else
5383      read_char_max(common, 255, type == OP_NCLASS);
5384    #endif
5385    
5386      if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, FALSE, backtracks))
5387      return cc + 32 / sizeof(pcre_uchar);      return cc + 32 / sizeof(pcre_uchar);
5388    
5389  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5390    jump[0] = NULL;    jump[0] = NULL;
 #ifdef COMPILE_PCRE8  
   /* This check only affects 8 bit mode. In other modes, we  
   always need to compare the value with 255. */  
5391    if (common->utf)    if (common->utf)
 #endif /* COMPILE_PCRE8 */  
5392      {      {
5393      jump[0] = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump[0] = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, bit);
5394      if (type == OP_CLASS)      if (type == OP_CLASS)
5395        {        {
5396        add_jump(compiler, backtracks, jump[0]);        add_jump(compiler, backtracks, jump[0]);
5397        jump[0] = NULL;        jump[0] = NULL;
5398        }        }
5399      }      }
5400  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #elif !defined COMPILE_PCRE8
5401      jump[0] = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
5402      if (type == OP_CLASS)
5403        {
5404        add_jump(compiler, backtracks, jump[0]);
5405        jump[0] = NULL;
5406        }
5407    #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
5408    
5409    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
5410    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
5411    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
5412    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
5413    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);
5414    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
5415    
5416  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
5417    if (jump[0] != NULL)    if (jump[0] != NULL)
5418      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
5419  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif
5420    
5421    return cc + 32 / sizeof(pcre_uchar);    return cc + 32 / sizeof(pcre_uchar);
5422    
5423  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
# Line 4837  if (context.length > 0) Line 5522  if (context.length > 0)
5522  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);
5523  }  }
5524    
 static struct sljit_jump *compile_ref_checks(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)  
 {  
 DEFINE_COMPILER;  
 int offset = GET2(cc, 1) << 1;  
   
 OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  
 if (!common->jscript_compat)  
   {  
   if (backtracks == NULL)  
     {  
     /* OVECTOR(1) contains the "string begin - 1" constant. */  
     OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  
     OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);  
     OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
     OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);  
     return JUMP(SLJIT_C_NOT_ZERO);  
     }  
   add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));  
   }  
 return CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
 }  
   
5525  /* Forward definitions. */  /* Forward definitions. */
5526  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);
5527  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);
# Line 4891  static void compile_backtrackingpath(com Line 5554  static void compile_backtrackingpath(com
5554    
5555  #define BACKTRACK_AS(type) ((type *)backtrack)  #define BACKTRACK_AS(type) ((type *)backtrack)
5556    
5557  static pcre_uchar *compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)  static void compile_dnref_search(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)
5558    {
5559    /* The OVECTOR offset goes to TMP2. */
5560    DEFINE_COMPILER;
5561    int count = GET2(cc, 1 + IMM2_SIZE);
5562    pcre_uchar *slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
5563    unsigned int offset;
5564    jump_list *found = NULL;
5565    
5566    SLJIT_ASSERT(*cc == OP_DNREF || *cc == OP_DNREFI);
5567    
5568    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
5569    
5570    count--;
5571    while (count-- > 0)
5572      {
5573      offset = GET2(slot, 0) << 1;
5574      GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5575      add_jump(compiler, &found, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5576      slot += common->name_entry_size;
5577      }
5578    
5579    offset = GET2(slot, 0) << 1;
5580    GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5581    if (backtracks != NULL && !common->jscript_compat)
5582      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5583    
5584    set_jumps(found, LABEL());
5585    }
5586    
5587    static void compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)
5588  {  {
5589  DEFINE_COMPILER;  DEFINE_COMPILER;
5590  int offset = GET2(cc, 1) << 1;  BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5591    int offset = 0;
5592  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
5593  struct sljit_jump *partial;  struct sljit_jump *partial;
5594  struct sljit_jump *nopartial;  struct sljit_jump *nopartial;
5595    
5596  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  if (ref)
5597  /* OVECTOR(1) contains the "string begin - 1" constant. */    {
5598  if (withchecks && !common->jscript_compat)    offset = GET2(cc, 1) << 1;
5599    add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5600      /* OVECTOR(1) contains the "string begin - 1" constant. */
5601      if (withchecks && !common->jscript_compat)
5602        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5603      }
5604    else
5605      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5606    
5607  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5608  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5609    {    {
5610    SLJIT_ASSERT(TMP1 == SLJIT_SCRATCH_REG1 && STACK_TOP == SLJIT_SCRATCH_REG2 && TMP2 == SLJIT_SCRATCH_REG3);    SLJIT_ASSERT(TMP1 == SLJIT_SCRATCH_REG1 && STACK_TOP == SLJIT_SCRATCH_REG2 && TMP2 == SLJIT_SCRATCH_REG3);
5611    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));    if (ref)
5612        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5613      else
5614        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5615    
5616    if (withchecks)    if (withchecks)
5617      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5618    
# Line 4933  if (common->utf && *cc == OP_REFI) Line 5637  if (common->utf && *cc == OP_REFI)
5637  else  else
5638  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
5639    {    {
5640    OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);    if (ref)
5641        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
5642      else
5643        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
5644    
5645    if (withchecks)    if (withchecks)
5646      jump = JUMP(SLJIT_C_ZERO);      jump = JUMP(SLJIT_C_ZERO);
5647    
# Line 4970  if (jump != NULL) Line 5678  if (jump != NULL)
5678    else    else
5679      JUMPHERE(jump);      JUMPHERE(jump);
5680    }    }
 return cc + 1 + IMM2_SIZE;  
5681  }  }
5682    
5683  static SLJIT_INLINE pcre_uchar *compile_ref_iterator_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)  static SLJIT_INLINE pcre_uchar *compile_ref_iterator_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5684  {  {
5685  DEFINE_COMPILER;  DEFINE_COMPILER;
5686    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5687  backtrack_common *backtrack;  backtrack_common *backtrack;
5688  pcre_uchar type;  pcre_uchar type;
5689    int offset = 0;
5690  struct sljit_label *label;  struct sljit_label *label;
5691  struct sljit_jump *zerolength;  struct sljit_jump *zerolength;
5692  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 4987  BOOL minimize; Line 5696  BOOL minimize;
5696    
5697  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
5698    
5699    if (ref)
5700      offset = GET2(cc, 1) << 1;
5701    else
5702      cc += IMM2_SIZE;
5703  type = cc[1 + IMM2_SIZE];  type = cc[1 + IMM2_SIZE];
5704    
5705    SLJIT_COMPILE_ASSERT((OP_CRSTAR & 0x1) == 0, crstar_opcode_must_be_even);
5706  minimize = (type & 0x1) != 0;  minimize = (type & 0x1) != 0;
5707  switch(type)  switch(type)
5708    {    {
# Line 5025  if (!minimize) Line 5740  if (!minimize)
5740    if (min == 0)    if (min == 0)
5741      {      {
5742      allocate_stack(common, 2);      allocate_stack(common, 2);
5743        if (ref)
5744          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5745      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5746      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5747      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5748      OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));      OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5749      zerolength = compile_ref_checks(common, ccbegin, NULL);      /* Handles both invalid and empty cases. Since the minimum repeat,
5750        is zero the invalid case is basically the same as an empty case. */
5751        if (ref)
5752          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5753        else
5754          {
5755          compile_dnref_search(common, ccbegin, NULL);
5756          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5757          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5758          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5759          }
5760      /* Restore if not zero length. */      /* Restore if not zero length. */
5761      OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));      OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5762      }      }
5763    else    else
5764      {      {
5765      allocate_stack(common, 1);      allocate_stack(common, 1);
5766        if (ref)
5767          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5768      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5769      zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);      if (ref)
5770          {
5771          add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5772          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5773          }
5774        else
5775          {
5776          compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5777          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5778          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5779          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5780          }
5781      }      }
5782    
5783    if (min > 1 || max > 1)    if (min > 1 || max > 1)
5784      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
5785    
5786    label = LABEL();    label = LABEL();
5787      if (!ref)
5788        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
5789    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);
5790    
5791    if (min > 1 || max > 1)    if (min > 1 || max > 1)
# Line 5074  if (!minimize) Line 5816  if (!minimize)
5816    JUMPHERE(zerolength);    JUMPHERE(zerolength);
5817    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5818    
5819    decrease_call_count(common);    count_match(common);
5820    return cc;    return cc;
5821    }    }
5822    
5823  allocate_stack(common, 2);  allocate_stack(common, ref ? 2 : 3);
5824    if (ref)
5825      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5826  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5827  if (type != OP_CRMINSTAR)  if (type != OP_CRMINSTAR)
5828    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5829    
5830  if (min == 0)  if (min == 0)
5831    {    {
5832    zerolength = compile_ref_checks(common, ccbegin, NULL);    /* Handles both invalid and empty cases. Since the minimum repeat,
5833      is zero the invalid case is basically the same as an empty case. */
5834      if (ref)
5835        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5836      else
5837        {
5838        compile_dnref_search(common, ccbegin, NULL);
5839        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5840        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5841        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5842        }
5843      /* Length is non-zero, we can match real repeats. */
5844    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5845    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
5846    }    }
5847  else  else
5848    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);    {
5849      if (ref)
5850        {
5851        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5852        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5853        }
5854      else
5855        {
5856        compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5857        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5858        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5859        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5860        }
5861      }
5862    
5863  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5864  if (max > 0)  if (max > 0)
5865    add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, max));    add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, max));
5866    
5867    if (!ref)
5868      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
5869  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);
5870  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5871    
# Line 5113  if (jump != NULL) Line 5883  if (jump != NULL)
5883    JUMPHERE(jump);    JUMPHERE(jump);
5884  JUMPHERE(zerolength);  JUMPHERE(zerolength);
5885    
5886  decrease_call_count(common);  count_match(common);
5887  return cc;  return cc;
5888  }  }
5889    
# Line 5123  DEFINE_COMPILER; Line 5893  DEFINE_COMPILER;
5893  backtrack_common *backtrack;  backtrack_common *backtrack;
5894  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5895  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5896  int start = GET(cc, 1);  sljit_sw start = GET(cc, 1);
5897  pcre_uchar *start_cc;  pcre_uchar *start_cc;
5898    BOOL needs_control_head;
5899    
5900  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5901    
5902  /* Inlining simple patterns. */  /* Inlining simple patterns. */
5903  if (get_framesize(common, common->start + start, TRUE) == no_stack)  if (get_framesize(common, common->start + start, NULL, TRUE, &needs_control_head) == no_stack)
5904    {    {
5905    start_cc = common->start + start;    start_cc = common->start + start;
5906    compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);    compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
# Line 5288  static pcre_uchar *compile_assert_matchi Line 6059  static pcre_uchar *compile_assert_matchi
6059  {  {
6060  DEFINE_COMPILER;  DEFINE_COMPILER;
6061  int framesize;  int framesize;
6062    int extrasize;
6063    BOOL needs_control_head;
6064  int private_data_ptr;  int private_data_ptr;
6065  backtrack_common altbacktrack;  backtrack_common altbacktrack;
6066  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
# Line 5297  jump_list *tmp = NULL; Line 6070  jump_list *tmp = NULL;
6070  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
6071  jump_list **found;  jump_list **found;
6072  /* Saving previous accept variables. */  /* Saving previous accept variables. */
6073    BOOL save_local_exit = common->local_exit;
6074    BOOL save_positive_assert = common->positive_assert;
6075    then_trap_backtrack *save_then_trap = common->then_trap;
6076  struct sljit_label *save_quit_label = common->quit_label;  struct sljit_label *save_quit_label = common->quit_label;
6077  struct sljit_label *save_accept_label = common->accept_label;  struct sljit_label *save_accept_label = common->accept_label;
6078  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
6079    jump_list *save_positive_assert_quit = common->positive_assert_quit;
6080  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
6081  struct sljit_jump *jump;  struct sljit_jump *jump;
6082  struct sljit_jump *brajump = NULL;  struct sljit_jump *brajump = NULL;
6083    
6084    /* Assert captures then. */
6085    common->then_trap = NULL;
6086    
6087  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
6088    {    {
6089    SLJIT_ASSERT(!conditional);    SLJIT_ASSERT(!conditional);
# Line 5312  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 6092  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
6092    }    }
6093  private_data_ptr = PRIVATE_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
6094  SLJIT_ASSERT(private_data_ptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
6095  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
6096  backtrack->framesize = framesize;  backtrack->framesize = framesize;
6097  backtrack->private_data_ptr = private_data_ptr;  backtrack->private_data_ptr = private_data_ptr;
6098  opcode = *cc;  opcode = *cc;
# Line 5331  if (bra == OP_BRAMINZERO) Line 6111  if (bra == OP_BRAMINZERO)
6111    
6112  if (framesize < 0)  if (framesize < 0)
6113    {    {
6114    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    extrasize = needs_control_head ? 2 : 1;
6115    allocate_stack(common, 1);    if (framesize == no_frame)
6116        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6117      allocate_stack(common, extrasize);
6118      if (needs_control_head)
6119        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6120    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6121      if (needs_control_head)
6122        {
6123        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
6124        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
6125        }
6126    }    }
6127  else  else
6128    {    {
6129    allocate_stack(common, framesize + 2);    extrasize = needs_control_head ? 3 : 2;
6130      allocate_stack(common, framesize + extrasize);
6131    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6132    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(framesize + 1));    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
6133    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);
6134      if (needs_control_head)
6135        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6136    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6137    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    if (needs_control_head)
6138    init_frame(common, ccbegin, framesize + 1, 2, FALSE);      {
6139        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
6140        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6141        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
6142        }
6143      else
6144        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
6145      init_frame(common, ccbegin, NULL, framesize + extrasize - 1, extrasize, FALSE);
6146    }    }
6147    
6148  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
6149  common->quit_label = NULL;  if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6150  common->quit = NULL;    {
6151      /* Negative assert is stronger than positive assert. */
6152      common->local_exit = TRUE;
6153      common->quit_label = NULL;
6154      common->quit = NULL;
6155      common->positive_assert = FALSE;
6156      }
6157    else
6158      common->positive_assert = TRUE;
6159    common->positive_assert_quit = NULL;
6160    
6161  while (1)  while (1)
6162    {    {
6163    common->accept_label = NULL;    common->accept_label = NULL;
# Line 5363  while (1) Line 6172  while (1)
6172    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
6173    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
6174      {      {
6175      common->quit_label = save_quit_label;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6176          {
6177          common->local_exit = save_local_exit;
6178          common->quit_label = save_quit_label;
6179          common->quit = save_quit;
6180          }
6181        common->positive_assert = save_positive_assert;
6182        common->then_trap = save_then_trap;
6183      common->accept_label = save_accept_label;      common->accept_label = save_accept_label;
6184      common->quit = save_quit;      common->positive_assert_quit = save_positive_assert_quit;
6185      common->accept = save_accept;      common->accept = save_accept;
6186      return NULL;      return NULL;
6187      }      }
# Line 5375  while (1) Line 6191  while (1)
6191    
6192    /* Reset stack. */    /* Reset stack. */
6193    if (framesize < 0)    if (framesize < 0)
6194      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      {
6195    else {      if (framesize == no_frame)
6196          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6197        else
6198          free_stack(common, extrasize);
6199        if (needs_control_head)
6200          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
6201        }
6202      else
6203        {
6204      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)
6205        {        {
6206        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
6207        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));
6208          if (needs_control_head)
6209            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
6210        }        }
6211      else      else
6212        {        {
6213        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6214          if (needs_control_head)
6215            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));
6216        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
6217        }        }
6218    }      }
6219    
6220    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6221      {      {
6222      /* We know that STR_PTR was stored on the top of the stack. */      /* We know that STR_PTR was stored on the top of the stack. */
6223      if (conditional)      if (conditional)
6224        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), needs_control_head ? sizeof(sljit_sw) : 0);
6225      else if (bra == OP_BRAZERO)      else if (bra == OP_BRAZERO)
6226        {        {
6227        if (framesize < 0)        if (framesize < 0)
6228          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 1) * sizeof(sljit_sw));
6229        else        else
6230          {          {
6231          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));
6232          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (framesize + extrasize - 1) * sizeof(sljit_sw));
6233          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
6234          }          }
6235        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
# Line 5418  while (1) Line 6246  while (1)
6246    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
6247    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
6248      {      {
6249      common->quit_label = save_quit_label;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6250          {
6251          common->local_exit = save_local_exit;
6252          common->quit_label = save_quit_label;
6253          common->quit = save_quit;
6254          }
6255        common->positive_assert = save_positive_assert;
6256        common->then_trap = save_then_trap;
6257      common->accept_label = save_accept_label;      common->accept_label = save_accept_label;
6258      common->quit = save_quit;      common->positive_assert_quit = save_positive_assert_quit;
6259      common->accept = save_accept;      common->accept = save_accept;
6260      return NULL;      return NULL;
6261      }      }
# Line 5432  while (1) Line 6267  while (1)
6267    ccbegin = cc;    ccbegin = cc;
6268    cc += GET(cc, 1);    cc += GET(cc, 1);
6269    }    }
6270    
6271    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6272      {
6273      SLJIT_ASSERT(common->positive_assert_quit == NULL);
6274      /* Makes the check less complicated below. */
6275      common->positive_assert_quit = common->quit;
6276      }
6277    
6278  /* None of them matched. */  /* None of them matched. */
6279  if (common->quit != NULL)  if (common->positive_assert_quit != NULL)
6280    set_jumps(common->quit, LABEL());    {
6281      jump = JUMP(SLJIT_JUMP);
6282      set_jumps(common->positive_assert_quit, LABEL());
6283      SLJIT_ASSERT(framesize != no_stack);
6284      if (framesize < 0)
6285        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));
6286      else
6287        {
6288        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6289        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
6290        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
6291        }
6292      JUMPHERE(jump);
6293      }
6294    
6295    if (needs_control_head)
6296      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(1));
6297    
6298  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)
6299    {    {
# Line 5446  if (opcode == OP_ASSERT || opcode == OP_ Line 6305  if (opcode == OP_ASSERT || opcode == OP_
6305      {      {
6306      /* The topmost item should be 0. */      /* The topmost item should be 0. */
6307      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
6308          {
6309          if (extrasize == 2)
6310            free_stack(common, 1);
6311        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6312          }
6313      else      else
6314        free_stack(common, 1);        free_stack(common, extrasize);
6315      }      }
6316    else    else
6317      {      {
6318      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
6319      /* The topmost item should be 0. */      /* The topmost item should be 0. */
6320      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
6321        {        {
6322        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
6323        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6324        }        }
6325      else      else
6326        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
6327      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
6328      }      }
6329    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
# Line 5472  if (opcode == OP_ASSERT || opcode == OP_ Line 6335  if (opcode == OP_ASSERT || opcode == OP_
6335    if (framesize < 0)    if (framesize < 0)
6336      {      {
6337      /* We know that STR_PTR was stored on the top of the stack. */      /* We know that STR_PTR was stored on the top of the stack. */
6338      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 1) * sizeof(sljit_sw));
6339      /* Keep the STR_PTR on the top of the stack. */      /* Keep the STR_PTR on the top of the stack. */
6340      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
6341          {
6342        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
6343          if (extrasize == 2)
6344            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6345          }
6346      else if (bra == OP_BRAMINZERO)      else if (bra == OP_BRAMINZERO)
6347        {        {
6348        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
# Line 5488  if (opcode == OP_ASSERT || opcode == OP_ Line 6355  if (opcode == OP_ASSERT || opcode == OP_
6355        {        {
6356        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
6357        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));
6358        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 2) * sizeof(sljit_sw));
6359        }        }
6360      else      else
6361        {        {
6362        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
6363        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 2) * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 2) * sizeof(sljit_sw));
6364        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        if (extrasize == 2)
6365        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);          {
6366            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6367            if (bra == OP_BRAMINZERO)
6368              OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6369            }
6370          else
6371            {
6372            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
6373            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);
6374            }
6375        }        }
6376      }      }
6377    
# Line 5524  else Line 6400  else
6400      {      {
6401      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6402      if (bra != OP_BRA)      if (bra != OP_BRA)
6403          {
6404          if (extrasize == 2)
6405            free_stack(common, 1);
6406        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6407          }
6408      else      else
6409        free_stack(common, 1);        free_stack(common, extrasize);
6410      }      }
6411    else    else
6412      {      {
6413      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6414      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
6415      /* The topmost item should be 0. */      /* The topmost item should be 0. */
6416      if (bra != OP_BRA)      if (bra != OP_BRA)
6417        {        {
6418        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
6419        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6420        }        }
6421      else      else
6422        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
6423      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
6424      }      }
6425    
# Line 5559  else Line 6439  else
6439      }      }
6440    }    }
6441    
6442  common->quit_label = save_quit_label;  if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6443      {
6444      common->local_exit = save_local_exit;
6445      common->quit_label = save_quit_label;
6446      common->quit = save_quit;
6447      }
6448    common->positive_assert = save_positive_assert;
6449    common->then_trap = save_then_trap;
6450  common->accept_label = save_accept_label;  common->accept_label = save_accept_label;
6451  common->quit = save_quit;  common->positive_assert_quit = save_positive_assert_quit;
6452  common->accept = save_accept;  common->accept = save_accept;
6453  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
6454  }  }
6455    
6456  static sljit_sw SLJIT_CALL do_searchovector(sljit_uw refno, sljit_sw* locals, pcre_uchar *name_table)  static SLJIT_INLINE void match_once_common(compiler_common *common, pcre_uchar ket, int framesize, int private_data_ptr, BOOL has_alternatives, BOOL needs_control_head)
6457  {  {
6458  int condition = FALSE;  DEFINE_COMPILER;
6459  pcre_uchar *slotA = name_table;  int stacksize;
 pcre_uchar *slotB;  
 sljit_sw name_count = locals[LOCALS0 / sizeof(sljit_sw)];  
 sljit_sw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];  
 sljit_sw no_capture;  
 int i;  
   
 locals += refno & 0xff;  
 refno >>= 8;  
 no_capture = locals[1];  
6460    
6461  for (i = 0; i < name_count; i++)  if (framesize < 0)
6462    {    {
6463    if (GET2(slotA, 0) == refno) break;    if (framesize == no_frame)
6464    slotA += name_entry_size;      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6465    }    else
6466        {
6467        stacksize = needs_control_head ? 1 : 0;
6468        if (ket != OP_KET || has_alternatives)
6469          stacksize++;
6470        free_stack(common, stacksize);
6471        }
6472    
6473  if (i < name_count)    if (needs_control_head)
6474    {      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), (ket != OP_KET || has_alternatives) ? sizeof(sljit_sw) : 0);
   /* Found a name for the number - there can be only one; duplicate names  
   for different numbers are allowed, but not vice versa. First scan down  
   for duplicates. */  
6475    
6476    slotB = slotA;    /* TMP2 which is set here used by OP_KETRMAX below. */
6477    while (slotB > name_table)    if (ket == OP_KETRMAX)
6478        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);
6479      else if (ket == OP_KETRMIN)
6480      {      {
6481      slotB -= name_entry_size;      /* Move the STR_PTR to the private_data_ptr. */
6482      if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);
       {  
       condition = locals[GET2(slotB, 0) << 1] != no_capture;  
       if (condition) break;  
       }  
     else break;  
6483      }      }
6484      }
6485    else
6486      {
6487      stacksize = (ket != OP_KET || has_alternatives) ? 2 : 1;
6488      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + stacksize) * sizeof(sljit_sw));
6489      if (needs_control_head)
6490        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 0);
6491    
6492    /* Scan up for duplicates */    if (ket == OP_KETRMAX)
   if (!condition)  
6493      {      {
6494      slotB = slotA;      /* TMP2 which is set here used by OP_KETRMAX below. */
6495      for (i++; i < name_count; i++)      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
       {  
       slotB += name_entry_size;  
       if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)  
         {  
         condition = locals[GET2(slotB, 0) << 1] != no_capture;  
         if (condition) break;  
         }  
       else break;  
       }  
6496      }      }
6497    }    }
6498  return condition;  if (needs_control_head)
6499      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP1, 0);
6500  }  }
6501    
6502  static sljit_sw SLJIT_CALL do_searchgroups(sljit_uw recno, sljit_uw* locals, pcre_uchar *name_table)  static SLJIT_INLINE int match_capture_common(compiler_common *common, int stacksize, int offset, int private_data_ptr)
6503  {  {
6504  int condition = FALSE;  DEFINE_COMPILER;
 pcre_uchar *slotA = name_table;  
 pcre_uchar *slotB;  
 sljit_uw name_count = locals[LOCALS0 / sizeof(sljit_sw)];  
 sljit_uw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];  
 sljit_uw group_num = locals[POSSESSIVE0 / sizeof(sljit_sw)];  
 sljit_uw i;  
6505    
6506  for (i = 0; i < name_count; i++)  if (common->capture_last_ptr != 0)
6507    {    {
6508    if (GET2(slotA, 0) == recno) break;    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6509    slotA += name_entry_size;    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6510      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6511      stacksize++;
6512    }    }
6513    if (common->optimized_cbracket[offset >> 1] == 0)
 if (i < name_count)  
6514    {    {
6515    /* Found a name for the number - there can be only one; duplicate    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6516    names for different numbers are allowed, but not vice versa. First    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
6517    scan down for duplicates. */    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6518      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6519    slotB = slotA;    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6520    while (slotB > name_table)    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
6521      {    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6522      slotB -= name_entry_size;    stacksize += 2;
     if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)  
       {  
       condition = GET2(slotB, 0) == group_num;  
       if (condition) break;  
       }  
     else break;  
     }  
   
   /* Scan up for duplicates */  
   if (!condition)  
     {  
     slotB = slotA;  
     for (i++; i < name_count; i++)  
       {  
       slotB += name_entry_size;  
       if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)  
         {  
         condition = GET2(slotB, 0) == group_num;  
         if (condition) break;  
         }  
       else break;  
       }  
     }  
6523    }    }
6524  return condition;  return stacksize;
6525  }  }
6526    
6527  /*  /*
# Line 5737  backtrack_common *backtrack; Line 6585  backtrack_common *backtrack;
6585  pcre_uchar opcode;  pcre_uchar opcode;
6586  int private_data_ptr = 0;  int private_data_ptr = 0;
6587  int offset = 0;  int offset = 0;
6588  int stacksize;  int i, stacksize;
6589    int repeat_ptr = 0, repeat_length = 0;
6590    int repeat_type = 0, repeat_count = 0;
6591  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
6592  pcre_uchar *matchingpath;  pcre_uchar *matchingpath;
6593    pcre_uchar *slot;
6594  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
6595  pcre_uchar ket;  pcre_uchar ket;
6596  assert_backtrack *assert;  assert_backtrack *assert;
6597  BOOL has_alternatives;  BOOL has_alternatives;
6598    BOOL needs_control_head = FALSE;
6599  struct sljit_jump *jump;  struct sljit_jump *jump;
6600  struct sljit_jump *skip;  struct sljit_jump *skip;
6601  struct sljit_label *rmaxlabel = NULL;  struct sljit_label *rmax_label = NULL;
6602  struct sljit_jump *braminzerojump = NULL;  struct sljit_jump *braminzero = NULL;
6603    
6604  PUSH_BACKTRACK(sizeof(bracket_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(bracket_backtrack), cc, NULL);
6605    
# Line 5760  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 6612  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
6612    
6613  opcode = *cc;  opcode = *cc;
6614  ccbegin = cc;  ccbegin = cc;
6615  matchingpath = ccbegin + 1 + LINK_SIZE;  matchingpath = bracketend(cc) - 1 - LINK_SIZE;
6616    ket = *matchingpath;
6617    if (ket == OP_KET && PRIVATE_DATA(matchingpath) != 0)
6618      {
6619      repeat_ptr = PRIVATE_DATA(matchingpath);
6620      repeat_length = PRIVATE_DATA(matchingpath + 1);
6621      repeat_type = PRIVATE_DATA(matchingpath + 2);
6622      repeat_count = PRIVATE_DATA(matchingpath + 3);
6623      SLJIT_ASSERT(repeat_length != 0 && repeat_type != 0 && repeat_count != 0);
6624      if (repeat_type == OP_UPTO)
6625        ket = OP_KETRMAX;
6626      if (repeat_type == OP_MINUPTO)
6627        ket = OP_KETRMIN;
6628      }
6629    
6630  if ((opcode == OP_COND || opcode == OP_SCOND) && cc[1 + LINK_SIZE] == OP_DEF)  if ((opcode == OP_COND || opcode == OP_SCOND) && cc[1 + LINK_SIZE] == OP_DEF)
6631    {    {
6632    /* Drop this bracket_backtrack. */    /* Drop this bracket_backtrack. */
6633    parent->top = backtrack->prev;    parent->top = backtrack->prev;
6634    return bracketend(cc);    return matchingpath + 1 + LINK_SIZE + repeat_length;
6635    }    }
6636    
6637  ket = *(bracketend(cc) - 1 - LINK_SIZE);  matchingpath = ccbegin + 1 + LINK_SIZE;
6638  SLJIT_ASSERT(ket == OP_KET || ket == OP_KETRMAX || ket == OP_KETRMIN);  SLJIT_ASSERT(ket == OP_KET || ket == OP_KETRMAX || ket == OP_KETRMIN);
6639  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket == OP_KETRMIN) || (bra == OP_BRAMINZERO && ket == OP_KETRMAX)));  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket == OP_KETRMIN) || (bra == OP_BRAMINZERO && ket == OP_KETRMAX)));
6640  cc += GET(cc, 1);  cc += GET(cc, 1);
6641    
6642  has_alternatives = *cc == OP_ALT;  has_alternatives = *cc == OP_ALT;
6643  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))  if (SLJIT_UNLIKELY(opcode == OP_COND || opcode == OP_SCOND))
6644    {    has_alternatives = (*matchingpath == OP_RREF || *matchingpath == OP_DNRREF) ? FALSE : TRUE;
   has_alternatives = (*matchingpath == OP_RREF) ? FALSE : TRUE;  
   if (*matchingpath == OP_NRREF)  
     {  
     stacksize = GET2(matchingpath, 1);  
     if (common->currententry == NULL || stacksize == RREF_ANY)  
       has_alternatives = FALSE;  
     else if (common->currententry->start == 0)  
       has_alternatives = stacksize != 0;  
     else  
       has_alternatives = stacksize != (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);  
     }  
   }  
6645    
6646  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))
6647    opcode = OP_SCOND;    opcode = OP_SCOND;
# Line 5819  else if (opcode == OP_ONCE || opcode == Line 6672  else if (opcode == OP_ONCE || opcode ==
6672    SLJIT_ASSERT(private_data_ptr != 0);    SLJIT_ASSERT(private_data_ptr != 0);
6673    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;
6674    if (opcode == OP_ONCE)    if (opcode == OP_ONCE)
6675      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, FALSE);      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, NULL, FALSE, &needs_control_head);
6676    }    }
6677    
6678  /* Instructions before the first alternative. */  /* Instructions before the first alternative. */
6679  stacksize = 0;  stacksize = 0;
6680  if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))  if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
6681    stacksize++;    stacksize++;
6682  if (bra == OP_BRAZERO)  if (bra == OP_BRAZERO)
6683    stacksize++;    stacksize++;
# Line 5833  if (stacksize > 0) Line 6686  if (stacksize > 0)
6686    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6687    
6688  stacksize = 0;  stacksize = 0;
6689  if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))  if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
6690    {    {
6691    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
6692    stacksize++;    stacksize++;
# Line 5849  if (bra == OP_BRAMINZERO) Line 6702  if (bra == OP_BRAMINZERO)
6702    if (ket != OP_KETRMIN)    if (ket != OP_KETRMIN)
6703      {      {
6704      free_stack(common, 1);      free_stack(common, 1);
6705      braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);      braminzero = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);
6706      }      }
6707    else    else
6708      {      {
# Line 5864  if (bra == OP_BRAMINZERO) Line 6717  if (bra == OP_BRAMINZERO)
6717        if (opcode != OP_ONCE || BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)        if (opcode != OP_ONCE || BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
6718          {          {
6719          /* When we come from outside, private_data_ptr contains the previous STR_PTR. */          /* When we come from outside, private_data_ptr contains the previous STR_PTR. */
6720          braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);          braminzero = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6721          }          }
6722        else        else
6723          {          {
6724          /* Except when the whole stack frame must be saved. */          /* Except when the whole stack frame must be saved. */
6725          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6726          braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (BACKTRACK_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_sw));          braminzero = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (BACKTRACK_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_sw));
6727          }          }
6728        JUMPHERE(skip);        JUMPHERE(skip);
6729        }        }
# Line 5883  if (bra == OP_BRAMINZERO) Line 6736  if (bra == OP_BRAMINZERO)
6736      }      }
6737    }    }
6738    
6739    if (repeat_type != 0)
6740      {
6741      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, repeat_count);
6742      if (repeat_type == OP_EXACT)
6743        rmax_label = LABEL();
6744      }
6745    
6746  if (ket == OP_KETRMIN)  if (ket == OP_KETRMIN)
6747    BACKTRACK_AS(bracket_backtrack)->recursive_matchingpath = LABEL();    BACKTRACK_AS(bracket_backtrack)->recursive_matchingpath = LABEL();
6748    
6749  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
6750    {    {
6751    rmaxlabel = LABEL();    rmax_label = LABEL();
6752    if (has_alternatives && opcode != OP_ONCE && opcode < OP_SBRA)    if (has_alternatives && opcode != OP_ONCE && opcode < OP_SBRA && repeat_type == 0)
6753      BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = rmaxlabel;      BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = rmax_label;
6754    }    }
6755    
6756  /* Handling capturing brackets and alternatives. */  /* Handling capturing brackets and alternatives. */
6757  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
6758    {    {
6759      stacksize = 0;
6760      if (needs_control_head)
6761        {
6762        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6763        stacksize++;
6764        }
6765    
6766    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
6767      {      {
6768      /* Neither capturing brackets nor recursions are not found in the block. */      /* Neither capturing brackets nor recursions are found in the block. */
6769      if (ket == OP_KETRMIN)      if (ket == OP_KETRMIN)
6770        {        {
6771        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        stacksize += 2;
6772        allocate_stack(common, 2);        if (!needs_control_head)
6773        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);  
       OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));  
6774        }        }
6775      else if (ket == OP_KETRMAX || has_alternatives)      else
6776        {        {
6777        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);        if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)
6778        allocate_stack(common, 1);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6779        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);        if (ket == OP_KETRMAX || has_alternatives)
6780            stacksize++;
6781        }        }
6782      else  
6783        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);      if (stacksize > 0)
6784          allocate_stack(common, stacksize);
6785    
6786        stacksize = 0;
6787        if (needs_control_head)
6788          {
6789          stacksize++;
6790          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6791          }
6792    
6793        if (ket == OP_KETRMIN)
6794          {
6795          if (needs_control_head)
6796            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6797          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6798          if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)
6799            OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, needs_control_head ? (2 * sizeof(sljit_sw)) : sizeof(sljit_sw));
6800          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6801          }
6802        else if (ket == OP_KETRMAX || has_alternatives)
6803          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6804      }      }
6805    else    else
6806      {      {
6807      if (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives)      if (ket != OP_KET || has_alternatives)
6808          stacksize++;
6809    
6810        stacksize += BACKTRACK_AS(bracket_backtrack)->u.framesize + 1;
6811        allocate_stack(common, stacksize);
6812    
6813        if (needs_control_head)
6814          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6815