/[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 1308 by zherczeg, Tue Apr 2 06:58:55 2013 UTC revision 1419 by zherczeg, Sun Dec 29 04:42:14 2013 UTC
# Line 168  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 182  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 210  typedef int (SLJIT_CALL *jit_function)(j Line 211  typedef int (SLJIT_CALL *jit_function)(j
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 305  typedef struct then_trap_backtrack { Line 306  typedef struct then_trap_backtrack {
306    int framesize;    int framesize;
307  } then_trap_backtrack;  } then_trap_backtrack;
308    
309  #define MAX_RANGE_SIZE 6  #define MAX_RANGE_SIZE 4
310    
311  typedef struct compiler_common {  typedef struct compiler_common {
312    /* The sljit ceneric compiler. */    /* The sljit ceneric compiler. */
# Line 370  typedef struct compiler_common { Line 371  typedef struct compiler_common {
371    sljit_sw ctypes;    sljit_sw ctypes;
372    int digits[2 + MAX_RANGE_SIZE];    int digits[2 + MAX_RANGE_SIZE];
373    /* Named capturing brackets. */    /* Named capturing brackets. */
374    sljit_uw name_table;    pcre_uchar *name_table;
375    sljit_sw name_count;    sljit_sw name_count;
376    sljit_sw name_entry_size;    sljit_sw name_entry_size;
377    
# Line 463  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 474  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->cbra_ptr + (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 532  cc += 1 + LINK_SIZE; Line 533  cc += 1 + LINK_SIZE;
533  return cc;  return cc;
534  }  }
535    
536    static int ones_in_half_byte[16] = {
537      /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
538      /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
539    };
540    
541  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
542   next_opcode   next_opcode
543   check_opcode_types   check_opcode_types
# Line 584  switch(*cc) Line 590  switch(*cc)
590    case OP_CRMINQUERY:    case OP_CRMINQUERY:
591    case OP_CRRANGE:    case OP_CRRANGE:
592    case OP_CRMINRANGE:    case OP_CRMINRANGE:
593      case OP_CRPOSSTAR:
594      case OP_CRPOSPLUS:
595      case OP_CRPOSQUERY:
596      case OP_CRPOSRANGE:
597    case OP_CLASS:    case OP_CLASS:
598    case OP_NCLASS:    case OP_NCLASS:
599    case OP_REF:    case OP_REF:
600    case OP_REFI:    case OP_REFI:
601      case OP_DNREF:
602      case OP_DNREFI:
603    case OP_RECURSE:    case OP_RECURSE:
604    case OP_CALLOUT:    case OP_CALLOUT:
605    case OP_ALT:    case OP_ALT:
# Line 613  switch(*cc) Line 625  switch(*cc)
625    case OP_SCBRAPOS:    case OP_SCBRAPOS:
626    case OP_SCOND:    case OP_SCOND:
627    case OP_CREF:    case OP_CREF:
628    case OP_NCREF:    case OP_DNCREF:
629    case OP_RREF:    case OP_RREF:
630    case OP_NRREF:    case OP_DNRREF:
631    case OP_DEF:    case OP_DEF:
632    case OP_BRAZERO:    case OP_BRAZERO:
633    case OP_BRAMINZERO:    case OP_BRAMINZERO:
# Line 735  switch(*cc) Line 747  switch(*cc)
747    
748  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
749  {  {
750  pcre_uchar *name;  int count;
751  pcre_uchar *name2;  pcre_uchar *slot;
 int i, cbra_index;  
752    
753  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
754  while (cc < ccend)  while (cc < ccend)
# Line 771  while (cc < ccend) Line 782  while (cc < ccend)
782      break;      break;
783    
784      case OP_CREF:      case OP_CREF:
785      i = GET2(cc, 1);      common->optimized_cbracket[GET2(cc, 1)] = 0;
     common->optimized_cbracket[i] = 0;  
786      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
787      break;      break;
788    
789      case OP_NCREF:      case OP_DNREF:
790      cbra_index = GET2(cc, 1);      case OP_DNREFI:
791      name = (pcre_uchar *)common->name_table;      case OP_DNCREF:
792      name2 = name;      count = GET2(cc, 1 + IMM2_SIZE);
793      for (i = 0; i < common->name_count; i++)      slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
794        {      while (count-- > 0)
795        if (GET2(name, 0) == cbra_index) break;        {
796        name += common->name_entry_size;        common->optimized_cbracket[GET2(slot, 0)] = 0;
797        }        slot += common->name_entry_size;
     SLJIT_ASSERT(i != common->name_count);  
   
     for (i = 0; i < common->name_count; i++)  
       {  
       if (STRCMP_UC_UC(name2 + IMM2_SIZE, name + IMM2_SIZE) == 0)  
         common->optimized_cbracket[GET2(name2, 0)] = 0;  
       name2 += common->name_entry_size;  
798        }        }
799      cc += 1 + IMM2_SIZE;      cc += 1 + 2 * IMM2_SIZE;
800      break;      break;
801    
802      case OP_RECURSE:      case OP_RECURSE:
# Line 892  pcre_uchar *next; Line 895  pcre_uchar *next;
895  pcre_uchar *next_end;  pcre_uchar *next_end;
896  pcre_uchar *max_end;  pcre_uchar *max_end;
897  pcre_uchar type;  pcre_uchar type;
898  sljit_uw length = end - begin;  sljit_sw length = end - begin;
899  int min, max, i;  int min, max, i;
900    
901  /* Detect fixed iterations first. */  /* Detect fixed iterations first. */
# Line 2021  while (list_item) Line 2024  while (list_item)
2024  common->stubs = NULL;  common->stubs = NULL;
2025  }  }
2026    
2027  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2028  {  {
2029  DEFINE_COMPILER;  DEFINE_COMPILER;
2030    
2031  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);
2032  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2033  }  }
2034    
# Line 2372  return (bit < 256) ? ((0 << 8) | bit) : Line 2375  return (bit < 256) ? ((0 << 8) | bit) :
2375    
2376  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2377  {  {
2378  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2379  DEFINE_COMPILER;  DEFINE_COMPILER;
2380  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2381    
# Line 2896  if (newlinecheck) Line 2899  if (newlinecheck)
2899  return mainloop;  return mainloop;
2900  }  }
2901    
2902  #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)  
2903  {  {
2904  DEFINE_COMPILER;  /* Recursive function, which scans prefix literals. */
2905  struct sljit_label *start;  int len, repeat, len_save, consumed = 0;
2906  struct sljit_jump *quit;  pcre_int32 caseless, chr, mask;
2907  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uchar *alternative, *cc_save;
2908  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;  
2909    
2910    repeat = 1;
2911  while (TRUE)  while (TRUE)
2912    {    {
2913      last = TRUE;
2914      any = FALSE;
2915    caseless = 0;    caseless = 0;
2916    must_stop = 1;    switch (*cc)
   switch(*cc)  
2917      {      {
     case OP_CHAR:  
     must_stop = 0;  
     cc++;  
     break;  
   
2918      case OP_CHARI:      case OP_CHARI:
2919      caseless = 1;      caseless = 1;
2920      must_stop = 0;      case OP_CHAR:
2921        last = FALSE;
2922      cc++;      cc++;
2923      break;      break;
2924    
# Line 2951  while (TRUE) Line 2943  while (TRUE)
2943      cc++;      cc++;
2944      break;      break;
2945    
2946        case OP_EXACTI:
2947        caseless = 1;
2948      case OP_EXACT:      case OP_EXACT:
2949        repeat = GET2(cc, 1);
2950        last = FALSE;
2951      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
2952      break;      break;
2953    
# Line 2962  while (TRUE) Line 2958  while (TRUE)
2958      cc++;      cc++;
2959      break;      break;
2960    
2961      case OP_EXACTI:      case OP_KET:
2962      caseless = 1;      cc += 1 + LINK_SIZE;
2963      cc += 1 + IMM2_SIZE;      continue;
2964    
2965        case OP_ALT:
2966        cc += GET(cc, 1);
2967        continue;
2968    
2969        case OP_ONCE:
2970        case OP_ONCE_NC:
2971        case OP_BRA:
2972        case OP_BRAPOS:
2973        case OP_CBRA:
2974        case OP_CBRAPOS:
2975        alternative = cc + GET(cc, 1);
2976        while (*alternative == OP_ALT)
2977          {
2978          max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, max_chars);
2979          if (max_chars == 0)
2980            return consumed;
2981          alternative += GET(alternative, 1);
2982          }
2983    
2984        if (*cc == OP_CBRA || *cc == OP_CBRAPOS)
2985          cc += IMM2_SIZE;
2986        cc += 1 + LINK_SIZE;
2987        continue;
2988    
2989        case OP_CLASS:
2990        case OP_NCLASS:
2991        any = TRUE;
2992        cc += 1 + 32 / sizeof(pcre_uchar);
2993      break;      break;
2994    
2995      default:  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2996      must_stop = 2;      case OP_XCLASS:
2997        any = TRUE;
2998        cc += GET(cc, 1);
2999        break;
3000    #endif
3001    
3002        case OP_NOT_DIGIT:
3003        case OP_DIGIT:
3004        case OP_NOT_WHITESPACE:
3005        case OP_WHITESPACE:
3006        case OP_NOT_WORDCHAR:
3007        case OP_WORDCHAR:
3008        case OP_ANY:
3009        case OP_ALLANY:
3010        any = TRUE;
3011        cc++;
3012        break;
3013    
3014    #ifdef SUPPORT_UCP
3015        case OP_NOTPROP:
3016        case OP_PROP:
3017        any = TRUE;
3018        cc += 1 + 2;
3019      break;      break;
3020    #endif
3021    
3022        case OP_TYPEEXACT:
3023        repeat = GET2(cc, 1);
3024        cc += 1 + IMM2_SIZE;
3025        continue;
3026    
3027        default:
3028        return consumed;
3029      }      }
3030    
3031    if (must_stop == 2)    if (any)
3032        break;      {
3033    #ifdef SUPPORT_UTF
3034        if (common->utf) return consumed;
3035    #endif
3036    #if defined COMPILE_PCRE8
3037        mask = 0xff;
3038    #elif defined COMPILE_PCRE16
3039        mask = 0xffff;
3040    #elif defined COMPILE_PCRE32
3041        mask = 0xffffffff;
3042    #else
3043        SLJIT_ASSERT_STOP();
3044    #endif
3045    
3046        do
3047          {
3048          chars[0] = mask;
3049          chars[1] = mask;
3050    
3051          if (--max_chars == 0)
3052            return consumed;
3053          consumed++;
3054          chars += 2;
3055          }
3056        while (--repeat > 0);
3057    
3058        repeat = 1;
3059        continue;
3060        }
3061    
3062    len = 1;    len = 1;
3063  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3064    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3065  #endif  #endif
3066    
3067    if (caseless && char_has_othercase(common, cc))    if (caseless != 0 && char_has_othercase(common, cc))
3068      {      {
3069      caseless = char_get_othercase_bit(common, cc);      caseless = char_get_othercase_bit(common, cc);
3070      if (caseless == 0)      if (caseless == 0)
3071        return FALSE;        return consumed;
3072  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3073      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
3074  #else  #else
# Line 2997  while (TRUE) Line 3081  while (TRUE)
3081    else    else
3082      caseless = 0;      caseless = 0;
3083    
3084    while (len > 0 && location < MAX_N_CHARS * 2)    len_save = len;
3085      {    cc_save = cc;
3086      c = *cc;    while (TRUE)
3087      bit = 0;      {
3088      if (len == (caseless & 0xff))      do
3089        {        {
3090        bit = caseless >> 8;        chr = *cc;
3091        c |= bit;  #ifdef COMPILE_PCRE32
3092          if (SLJIT_UNLIKELY(chr == NOTACHAR))
3093            return consumed;
3094    #endif
3095          mask = 0;
3096          if (len == (caseless & 0xff))
3097            {
3098            mask = caseless >> 8;
3099            chr |= mask;
3100            }
3101    
3102          if (chars[0] == NOTACHAR)
3103            {
3104            chars[0] = chr;
3105            chars[1] = mask;
3106            }
3107          else
3108            {
3109            mask |= chars[0] ^ chr;
3110            chr |= mask;
3111            chars[0] = chr;
3112            chars[1] |= mask;
3113            }
3114    
3115          len--;
3116          if (--max_chars == 0)
3117            return consumed;
3118          consumed++;
3119          chars += 2;
3120          cc++;
3121        }        }
3122        while (len > 0);
3123    
3124      chars[location] = c;      if (--repeat == 0)
3125      chars[location + 1] = bit;        break;
3126    
3127      len--;      len = len_save;
3128      location += 2;      cc = cc_save;
     cc++;  
3129      }      }
3130    
3131    if (location >= MAX_N_CHARS * 2 || must_stop != 0)    repeat = 1;
3132      if (last)
3133        return consumed;
3134      }
3135    }
3136    
3137    #define MAX_N_CHARS 16
3138    
3139    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3140    {
3141    DEFINE_COMPILER;
3142    struct sljit_label *start;
3143    struct sljit_jump *quit;
3144    pcre_uint32 chars[MAX_N_CHARS * 2];
3145    pcre_uint8 ones[MAX_N_CHARS];
3146    pcre_uint32 mask;
3147    int i, max;
3148    int offsets[3];
3149    
3150    for (i = 0; i < MAX_N_CHARS; i++)
3151      {
3152      chars[i << 1] = NOTACHAR;
3153      chars[(i << 1) + 1] = 0;
3154      }
3155    
3156    max = scan_prefix(common, common->start, chars, MAX_N_CHARS);
3157    
3158    if (max <= 1)
3159      return FALSE;
3160    
3161    for (i = 0; i < max; i++)
3162      {
3163      mask = chars[(i << 1) + 1];
3164      ones[i] = ones_in_half_byte[mask & 0xf];
3165      mask >>= 4;
3166      while (mask != 0)
3167        {
3168        ones[i] += ones_in_half_byte[mask & 0xf];
3169        mask >>= 4;
3170        }
3171      }
3172    
3173    offsets[0] = -1;
3174    /* Scan forward. */
3175    for (i = 0; i < max; i++)
3176      if (ones[i] <= 2) {
3177        offsets[0] = i;
3178      break;      break;
3179    }    }
3180    
3181  /* At least two characters are required. */  if (offsets[0] == -1)
3182  if (location < 2 * 2)    return FALSE;
3183      return FALSE;  
3184    /* Scan backward. */
3185    offsets[1] = -1;
3186    for (i = max - 1; i > offsets[0]; i--)
3187      if (ones[i] <= 2) {
3188        offsets[1] = i;
3189        break;
3190      }
3191    
3192    offsets[2] = -1;
3193    if (offsets[1] >= 0)
3194      {
3195      /* Scan from middle. */
3196      for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3197        if (ones[i] <= 2)
3198          {
3199          offsets[2] = i;
3200          break;
3201          }
3202    
3203      if (offsets[2] == -1)
3204        {
3205        for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3206          if (ones[i] <= 2)
3207            {
3208            offsets[2] = i;
3209            break;
3210            }
3211        }
3212      }
3213    
3214    SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3215    SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3216    
3217    chars[0] = chars[offsets[0] << 1];
3218    chars[1] = chars[(offsets[0] << 1) + 1];
3219    if (offsets[2] >= 0)
3220      {
3221      chars[2] = chars[offsets[2] << 1];
3222      chars[3] = chars[(offsets[2] << 1) + 1];
3223      }
3224    if (offsets[1] >= 0)
3225      {
3226      chars[4] = chars[offsets[1] << 1];
3227      chars[5] = chars[(offsets[1] << 1) + 1];
3228      }
3229    
3230    max -= 1;
3231  if (firstline)  if (firstline)
3232    {    {
3233    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3234    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3235    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));
3236    }    }
3237  else  else
3238    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));
3239    
3240  start = LABEL();  start = LABEL();
3241  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3242    
3243  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]));
3244  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  if (offsets[1] >= 0)
3245      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3246  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));
3247    
3248  if (chars[1] != 0)  if (chars[1] != 0)
3249    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3250  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3251  if (location > 2 * 2)  if (offsets[2] >= 0)
3252    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));
3253  if (chars[3] != 0)  
3254    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)  
3255    {    {
3256    if (chars[5] != 0)    if (chars[5] != 0)
3257      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3258    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
3259      }
3260    
3261    if (offsets[2] >= 0)
3262      {
3263      if (chars[3] != 0)
3264        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3265      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3266    }    }
3267  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));
3268    
# Line 3059  JUMPHERE(quit); Line 3271  JUMPHERE(quit);
3271  if (firstline)  if (firstline)
3272    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3273  else  else
3274    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));
3275  return TRUE;  return TRUE;
3276  }  }
3277    
# Line 3208  if (firstline) Line 3420  if (firstline)
3420    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3421  }  }
3422    
3423  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);
3424    
3425  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)
3426  {  {
3427  DEFINE_COMPILER;  DEFINE_COMPILER;
3428  struct sljit_label *start;  struct sljit_label *start;
3429  struct sljit_jump *quit;  struct sljit_jump *quit;
3430  struct sljit_jump *found = NULL;  struct sljit_jump *found = NULL;
3431  jump_list *matches = NULL;  jump_list *matches = NULL;
 pcre_uint8 inverted_start_bits[32];  
 int i;  
3432  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3433  struct sljit_jump *jump;  struct sljit_jump *jump;
3434  #endif  #endif
3435    
 for (i = 0; i < 32; ++i)  
   inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);  
   
3436  if (firstline)  if (firstline)
3437    {    {
3438    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
# Line 3241  if (common->utf) Line 3448  if (common->utf)
3448    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3449  #endif  #endif
3450    
3451  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))
3452    {    {
3453  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3454    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
# Line 3250  if (!check_class_ranges(common, inverted Line 3457  if (!check_class_ranges(common, inverted
3457  #endif  #endif
3458    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3459    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3460    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
3461    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3462    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);
3463    found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
# Line 3510  sljit_emit_fast_return(compiler, SLJIT_M Line 3717  sljit_emit_fast_return(compiler, SLJIT_M
3717  static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)  static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)
3718  {  {
3719  DEFINE_COMPILER;  DEFINE_COMPILER;
 struct sljit_jump *jump;  
3720    
3721  if (ranges[0] < 0)  if (ranges[0] < 0 || ranges[0] > 4)
3722    return FALSE;    return FALSE;
3723    
3724    /* No character is accepted. */
3725    if (ranges[0] == 0 && ranges[1] == 0)
3726      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
3727    
3728    if (readch)
3729      read_char(common);
3730    
3731  switch(ranges[0])  switch(ranges[0])
3732    {    {
3733      case 0:
3734      /* When ranges[1] != 0, all characters are accepted. */
3735      return TRUE;
3736    
3737    case 1:    case 1:
   if (readch)  
     read_char(common);  
3738    add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));    add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3739    return TRUE;    return TRUE;
3740    
3741    case 2:    case 2:
3742    if (readch)    if (ranges[2] + 1 != ranges[3])
3743      read_char(common);      {
3744    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3745    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(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3746        }
3747      else
3748        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3749    return TRUE;    return TRUE;
3750    
3751    case 4:    case 3:
3752    if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])    if (ranges[1] != 0)
3753      {      {
3754      if (readch)      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3755        read_char(common);      if (ranges[2] + 1 != ranges[3])
     if (ranges[1] != 0)  
3756        {        {
3757        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3758        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[3] - ranges[2]));
3759        }        }
3760      else      else
3761          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3762        return TRUE;
3763        }
3764    
3765      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2]));
3766      if (ranges[3] + 1 != ranges[4])
3767        {
3768        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[3]);
3769        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[3]));
3770        }
3771      else
3772        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3]));
3773      return TRUE;
3774    
3775      case 4:
3776      if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4])
3777          && (ranges[2] | (ranges[4] - ranges[2])) == ranges[4]
3778          && is_powerof2(ranges[4] - ranges[2]))
3779        {
3780        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);
3781        if (ranges[4] + 1 != ranges[5])
3782        {        {
3783        jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3784        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, 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]));
       JUMPHERE(jump);  
3785        }        }
3786        else
3787          add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3788      return TRUE;      return TRUE;
3789      }      }
3790    if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))  
3791      if (ranges[1] != 0)
3792      {      {
3793      if (readch)      if (ranges[2] + 1 != ranges[3])
3794        read_char(common);        {
3795      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3796      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3797      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));        ranges[4] -= ranges[2];
3798          ranges[5] -= ranges[2];
3799          }
3800        else
3801          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3802    
3803        if (ranges[4] + 1 != ranges[5])
3804          {
3805          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3806          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3807          }
3808        else
3809          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3810      return TRUE;      return TRUE;
3811      }      }
3812    return FALSE;  
3813      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3814      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[2]));
3815      if (ranges[3] + 1 != ranges[4])
3816        {
3817        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]);
3818        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[3]));
3819        }
3820      else
3821        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3822      return TRUE;
3823    
3824    default:    default:
3825      SLJIT_ASSERT_STOP();
3826    return FALSE;    return FALSE;
3827    }    }
3828  }  }
# Line 3594  if (bit != 0) Line 3857  if (bit != 0)
3857  ranges[0] = length;  ranges[0] = length;
3858  }  }
3859    
3860  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)
3861  {  {
3862  int ranges[2 + MAX_RANGE_SIZE];  int ranges[2 + MAX_RANGE_SIZE];
3863  pcre_uint8 bit, cbit, all;  pcre_uint8 bit, cbit, all;
3864  int i, byte, length = 0;  int i, byte, length = 0;
3865    
3866  bit = bits[0] & 0x1;  bit = bits[0] & 0x1;
3867  ranges[1] = bit;  ranges[1] = !invert ? bit : (bit ^ 0x1);
3868  /* Can be 0 or 255. */  /* All bits will be zero or one (since bit is zero or one). */
3869  all = -bit;  all = -bit;
3870    
3871  for (i = 0; i < 256; )  for (i = 0; i < 256; )
# Line 4023  static void compile_xclass_matchingpath( Line 4286  static void compile_xclass_matchingpath(
4286  {  {
4287  DEFINE_COMPILER;  DEFINE_COMPILER;
4288  jump_list *found = NULL;  jump_list *found = NULL;
4289  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;
4290  pcre_int32 c, charoffset;  pcre_int32 c, charoffset;
 const pcre_uint32 *other_cases;  
4291  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4292  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4293  int compares, invertcmp, numberofcmps;  int compares, invertcmp, numberofcmps;
4294    
4295  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4296  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4297  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4298  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4299    const pcre_uint32 *other_cases;
4300  pcre_int32 typeoffset;  pcre_int32 typeoffset;
4301  #endif  #endif
4302    
# Line 4041  pcre_int32 typeoffset; Line 4305  pcre_int32 typeoffset;
4305  detect_partial_match(common, backtracks);  detect_partial_match(common, backtracks);
4306  read_char(common);  read_char(common);
4307    
4308  if ((*cc++ & XCL_MAP) != 0)  cc++;
4309    if ((cc[-1] & XCL_HASPROP) == 0)
4310    {    {
4311    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    if ((cc[-1] & XCL_MAP) != 0)
4312  #ifndef COMPILE_PCRE8      {
4313    jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4314  #elif defined SUPPORT_UTF  #ifdef SUPPORT_UCP
4315    if (common->utf)      charsaved = TRUE;
     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
4316  #endif  #endif
4317        if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, FALSE, backtracks))
4318          {
4319          jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4320    
4321          OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4322          OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4323          OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4324          OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4325          OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4326          add_jump(compiler, &found, JUMP(SLJIT_C_NOT_ZERO));
4327          add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4328    
4329          JUMPHERE(jump);
4330          }
4331        else
4332          add_jump(compiler, &found, CMP(SLJIT_C_LESS_EQUAL, TMP3, 0, SLJIT_IMM, 0xff));
4333    
4334    if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, list))      OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
4335        cc += 32 / sizeof(pcre_uchar);
4336        }
4337      else
4338        add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0xff));
4339      }
4340    else if ((cc[-1] & XCL_MAP) != 0)
4341      {
4342      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4343    #ifdef SUPPORT_UCP
4344      charsaved = TRUE;
4345    #endif
4346      if (!check_class_ranges(common, (const pcre_uint8 *)cc, FALSE, TRUE, list))
4347      {      {
4348    #ifdef COMPILE_PCRE8
4349        SLJIT_ASSERT(common->utf);
4350    #endif
4351        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4352    
4353      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4354      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4355      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4356      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4357      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);
4358      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
     }  
4359    
 #ifndef COMPILE_PCRE8  
   JUMPHERE(jump);  
 #elif defined SUPPORT_UTF  
   if (common->utf)  
4360      JUMPHERE(jump);      JUMPHERE(jump);
4361  #endif      }
4362    
4363    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
 #ifdef SUPPORT_UCP  
   charsaved = TRUE;  
 #endif  
4364    cc += 32 / sizeof(pcre_uchar);    cc += 32 / sizeof(pcre_uchar);
4365    }    }
4366    
# Line 4128  while (*cc != XCL_END) Line 4418  while (*cc != XCL_END)
4418        case PT_SPACE:        case PT_SPACE:
4419        case PT_PXSPACE:        case PT_PXSPACE:
4420        case PT_WORD:        case PT_WORD:
4421          case PT_PXGRAPH:
4422          case PT_PXPRINT:
4423          case PT_PXPUNCT:
4424        needstype = TRUE;        needstype = TRUE;
4425        needschar = TRUE;        needschar = TRUE;
4426        break;        break;
# Line 4315  while (*cc != XCL_END) Line 4608  while (*cc != XCL_END)
4608    
4609        case PT_SPACE:        case PT_SPACE:
4610        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);  
         }  
4611        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4612        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);
4613        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);
4614        if (*cc == PT_SPACE)  
4615          JUMPHERE(jump);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x9);
4616          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4617    
4618          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x9);
4619          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4620    
4621        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4622        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 4416  while (*cc != XCL_END) Line 4708  while (*cc != XCL_END)
4708        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);
4709        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4710        break;        break;
4711    
4712          case PT_PXGRAPH:
4713          /* C and Z groups are the farthest two groups. */
4714          SET_TYPE_OFFSET(ucp_Ll);
4715          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4716          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4717    
4718          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4719    
4720          /* In case of ucp_Cf, we overwrite the result. */
4721          SET_CHAR_OFFSET(0x2066);
4722          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4723          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4724    
4725          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4726          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4727    
4728          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x2066);
4729          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4730    
4731          JUMPHERE(jump);
4732          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4733          break;
4734    
4735          case PT_PXPRINT:
4736          /* C and Z groups are the farthest two groups. */
4737          SET_TYPE_OFFSET(ucp_Ll);
4738          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4739          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4740    
4741          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Ll);
4742          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_NOT_EQUAL);
4743    
4744          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4745    
4746          /* In case of ucp_Cf, we overwrite the result. */
4747          SET_CHAR_OFFSET(0x2066);
4748          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4749          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4750    
4751          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4752          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4753    
4754          JUMPHERE(jump);
4755          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4756          break;
4757    
4758          case PT_PXPUNCT:
4759          SET_TYPE_OFFSET(ucp_Sc);
4760          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Sc);
4761          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4762    
4763          SET_CHAR_OFFSET(0);
4764          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xff);
4765          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4766    
4767          SET_TYPE_OFFSET(ucp_Pc);
4768          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ps - ucp_Pc);
4769          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4770          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4771          break;
4772        }        }
4773      cc += 2;      cc += 2;
4774      }      }
# Line 4562  switch(type) Line 4915  switch(type)
4915  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4916    case OP_NOTPROP:    case OP_NOTPROP:
4917    case OP_PROP:    case OP_PROP:
4918    propdata[0] = 0;    propdata[0] = XCL_HASPROP;
4919    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;
4920    propdata[2] = cc[0];    propdata[2] = cc[0];
4921    propdata[3] = cc[1];    propdata[3] = cc[1];
# Line 4921  switch(type) Line 5274  switch(type)
5274    case OP_NCLASS:    case OP_NCLASS:
5275    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5276    read_char(common);    read_char(common);
5277    if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, backtracks))    if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, FALSE, backtracks))
5278      return cc + 32 / sizeof(pcre_uchar);      return cc + 32 / sizeof(pcre_uchar);
5279    
5280  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
# Line 5054  if (context.length > 0) Line 5407  if (context.length > 0)
5407  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);
5408  }  }
5409    
 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));  
 }  
   
5410  /* Forward definitions. */  /* Forward definitions. */
5411  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);
5412  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);
# Line 5108  static void compile_backtrackingpath(com Line 5439  static void compile_backtrackingpath(com
5439    
5440  #define BACKTRACK_AS(type) ((type *)backtrack)  #define BACKTRACK_AS(type) ((type *)backtrack)
5441    
5442  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)
5443  {  {
5444    /* The OVECTOR offset goes to TMP2. */
5445  DEFINE_COMPILER;  DEFINE_COMPILER;
5446  int offset = GET2(cc, 1) << 1;  int count = GET2(cc, 1 + IMM2_SIZE);
5447    pcre_uchar *slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
5448    unsigned int offset;
5449    jump_list *found = NULL;
5450    
5451    SLJIT_ASSERT(*cc == OP_DNREF || *cc == OP_DNREFI);
5452    
5453    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
5454    
5455    count--;
5456    while (count-- > 0)
5457      {
5458      offset = GET2(slot, 0) << 1;
5459      GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5460      add_jump(compiler, &found, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5461      slot += common->name_entry_size;
5462      }
5463    
5464    offset = GET2(slot, 0) << 1;
5465    GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5466    if (backtracks != NULL && !common->jscript_compat)
5467      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5468    
5469    set_jumps(found, LABEL());
5470    }
5471    
5472    static void compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)
5473    {
5474    DEFINE_COMPILER;
5475    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5476    int offset = 0;
5477  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
5478  struct sljit_jump *partial;  struct sljit_jump *partial;
5479  struct sljit_jump *nopartial;  struct sljit_jump *nopartial;
5480    
5481  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  if (ref)
5482  /* OVECTOR(1) contains the "string begin - 1" constant. */    {
5483  if (withchecks && !common->jscript_compat)    offset = GET2(cc, 1) << 1;
5484    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));
5485      /* OVECTOR(1) contains the "string begin - 1" constant. */
5486      if (withchecks && !common->jscript_compat)
5487        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5488      }
5489    else
5490      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5491    
5492  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5493  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5494    {    {
5495    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);
5496    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));    if (ref)
5497        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5498      else
5499        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5500    
5501    if (withchecks)    if (withchecks)
5502      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5503    
# Line 5150  if (common->utf && *cc == OP_REFI) Line 5522  if (common->utf && *cc == OP_REFI)
5522  else  else
5523  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
5524    {    {
5525    OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);    if (ref)
5526        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
5527      else
5528        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
5529    
5530    if (withchecks)    if (withchecks)
5531      jump = JUMP(SLJIT_C_ZERO);      jump = JUMP(SLJIT_C_ZERO);
5532    
# Line 5187  if (jump != NULL) Line 5563  if (jump != NULL)
5563    else    else
5564      JUMPHERE(jump);      JUMPHERE(jump);
5565    }    }
 return cc + 1 + IMM2_SIZE;  
5566  }  }
5567    
5568  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)
5569  {  {
5570  DEFINE_COMPILER;  DEFINE_COMPILER;
5571    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5572  backtrack_common *backtrack;  backtrack_common *backtrack;
5573  pcre_uchar type;  pcre_uchar type;
5574    int offset = 0;
5575  struct sljit_label *label;  struct sljit_label *label;
5576  struct sljit_jump *zerolength;  struct sljit_jump *zerolength;
5577  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 5204  BOOL minimize; Line 5581  BOOL minimize;
5581    
5582  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
5583    
5584    if (ref)
5585      offset = GET2(cc, 1) << 1;
5586    else
5587      cc += IMM2_SIZE;
5588  type = cc[1 + IMM2_SIZE];  type = cc[1 + IMM2_SIZE];
5589    
5590    SLJIT_COMPILE_ASSERT((OP_CRSTAR & 0x1) == 0, crstar_opcode_must_be_even);
5591  minimize = (type & 0x1) != 0;  minimize = (type & 0x1) != 0;
5592  switch(type)  switch(type)
5593    {    {
# Line 5242  if (!minimize) Line 5625  if (!minimize)
5625    if (min == 0)    if (min == 0)
5626      {      {
5627      allocate_stack(common, 2);      allocate_stack(common, 2);
5628        if (ref)
5629          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5630      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5631      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5632      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5633      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));
5634      zerolength = compile_ref_checks(common, ccbegin, NULL);      /* Handles both invalid and empty cases. Since the minimum repeat,
5635        is zero the invalid case is basically the same as an empty case. */
5636        if (ref)
5637          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5638        else
5639          {
5640          compile_dnref_search(common, ccbegin, NULL);
5641          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5642          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5643          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5644          }
5645      /* Restore if not zero length. */      /* Restore if not zero length. */
5646      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));
5647      }      }
5648    else    else
5649      {      {
5650      allocate_stack(common, 1);      allocate_stack(common, 1);
5651        if (ref)
5652          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5653      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5654      zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);      if (ref)
5655          {
5656          add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5657          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5658          }
5659        else
5660          {
5661          compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5662          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5663          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5664          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5665          }
5666      }      }
5667    
5668    if (min > 1 || max > 1)    if (min > 1 || max > 1)
5669      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
5670    
5671    label = LABEL();    label = LABEL();
5672      if (!ref)
5673        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
5674    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);
5675    
5676    if (min > 1 || max > 1)    if (min > 1 || max > 1)
# Line 5291  if (!minimize) Line 5701  if (!minimize)
5701    JUMPHERE(zerolength);    JUMPHERE(zerolength);
5702    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5703    
5704    decrease_call_count(common);    count_match(common);
5705    return cc;    return cc;
5706    }    }
5707    
5708  allocate_stack(common, 2);  allocate_stack(common, ref ? 2 : 3);
5709    if (ref)
5710      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5711  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5712  if (type != OP_CRMINSTAR)  if (type != OP_CRMINSTAR)
5713    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5714    
5715  if (min == 0)  if (min == 0)
5716    {    {
5717    zerolength = compile_ref_checks(common, ccbegin, NULL);    /* Handles both invalid and empty cases. Since the minimum repeat,
5718      is zero the invalid case is basically the same as an empty case. */
5719      if (ref)
5720        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5721      else
5722        {
5723        compile_dnref_search(common, ccbegin, NULL);
5724        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5725        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5726        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5727        }
5728      /* Length is non-zero, we can match real repeats. */
5729    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5730    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
5731    }    }
5732  else  else
5733    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);    {
5734      if (ref)
5735        {
5736        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5737        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5738        }
5739      else
5740        {
5741        compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5742        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5743        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5744        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5745        }
5746      }
5747    
5748  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5749  if (max > 0)  if (max > 0)
5750    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));
5751    
5752    if (!ref)
5753      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
5754  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);
5755  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5756    
# Line 5330  if (jump != NULL) Line 5768  if (jump != NULL)
5768    JUMPHERE(jump);    JUMPHERE(jump);
5769  JUMPHERE(zerolength);  JUMPHERE(zerolength);
5770    
5771  decrease_call_count(common);  count_match(common);
5772  return cc;  return cc;
5773  }  }
5774    
# Line 5900  common->accept = save_accept; Line 6338  common->accept = save_accept;
6338  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
6339  }  }
6340    
 static sljit_sw SLJIT_CALL do_searchovector(sljit_uw refno, sljit_sw* locals, pcre_uchar *name_table)  
 {  
 int condition = FALSE;  
 pcre_uchar *slotA = name_table;  
 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];  
   
 for (i = 0; i < name_count; i++)  
   {  
   if (GET2(slotA, 0) == refno) break;  
   slotA += name_entry_size;  
   }  
   
 if (i < name_count)  
   {  
   /* 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. */  
   
   slotB = slotA;  
   while (slotB > name_table)  
     {  
     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;  
     }  
   
   /* 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 = locals[GET2(slotB, 0) << 1] != no_capture;  
         if (condition) break;  
         }  
       else break;  
       }  
     }  
   }  
 return condition;  
 }  
   
 static sljit_sw SLJIT_CALL do_searchgroups(sljit_uw recno, sljit_uw* locals, pcre_uchar *name_table)  
 {  
 int condition = FALSE;  
 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;  
   
 for (i = 0; i < name_count; i++)  
   {  
   if (GET2(slotA, 0) == recno) break;  
   slotA += name_entry_size;  
   }  
   
 if (i < name_count)  
   {  
   /* 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. */  
   
   slotB = slotA;  
   while (slotB > name_table)  
     {  
     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;  
     }  
   
   /* 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;  
       }  
     }  
   }  
 return condition;  
 }  
   
6341  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)  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)
6342  {  {
6343  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 6142  backtrack_common *backtrack; Line 6470  backtrack_common *backtrack;
6470  pcre_uchar opcode;  pcre_uchar opcode;
6471  int private_data_ptr = 0;  int private_data_ptr = 0;
6472  int offset = 0;  int offset = 0;
6473  int stacksize;  int i, stacksize;
6474  int repeat_ptr = 0, repeat_length = 0;  int repeat_ptr = 0, repeat_length = 0;
6475  int repeat_type = 0, repeat_count = 0;  int repeat_type = 0, repeat_count = 0;
6476  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
6477  pcre_uchar *matchingpath;  pcre_uchar *matchingpath;
6478    pcre_uchar *slot;
6479  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
6480  pcre_uchar ket;  pcre_uchar ket;
6481  assert_backtrack *assert;  assert_backtrack *assert;
# Line 6196  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket Line 6525  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket
6525  cc += GET(cc, 1);  cc += GET(cc, 1);
6526    
6527  has_alternatives = *cc == OP_ALT;  has_alternatives = *cc == OP_ALT;
6528  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))  if (SLJIT_UNLIKELY(opcode == OP_COND || opcode == OP_SCOND))
6529    {    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);  
     }  
   }  
6530    
6531  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))
6532    opcode = OP_SCOND;    opcode = OP_SCOND;
# Line 6446  if (opcode == OP_COND || opcode == OP_SC Line 6763  if (opcode == OP_COND || opcode == OP_SC
6763        CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(matchingpath, 1) << 1), SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));        CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(matchingpath, 1) << 1), SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
6764      matchingpath += 1 + IMM2_SIZE;      matchingpath += 1 + IMM2_SIZE;
6765      }      }
6766    else if (*matchingpath == OP_NCREF)    else if (*matchingpath == OP_DNCREF)
6767      {      {
6768      SLJIT_ASSERT(has_alternatives);      SLJIT_ASSERT(has_alternatives);
     stacksize = GET2(matchingpath, 1);  
     jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(stacksize << 1), SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  
   
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);  
     OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (stacksize << 8) | (common->ovector_start / sizeof(sljit_sw)));  
     GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, 0);  
     OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);  
     sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchovector));  
     OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);  
     add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0));  
6769    
6770      JUMPHERE(jump);      i = GET2(matchingpath, 1 + IMM2_SIZE);
6771      matchingpath += 1 + IMM2_SIZE;      slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;
6772        OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
6773        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
6774        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
6775        slot += common->name_entry_size;
6776        i--;
6777        while (i-- > 0)
6778          {
6779          OP2(SLJIT_SUB, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
6780          OP2(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, STR_PTR, 0);
6781          slot += common->name_entry_size;
6782          }
6783        OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
6784        add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), JUMP(SLJIT_C_ZERO));
6785        matchingpath += 1 + 2 * IMM2_SIZE;
6786      }      }
6787    else if (*matchingpath == OP_RREF || *matchingpath == OP_NRREF)    else if (*matchingpath == OP_RREF || *matchingpath == OP_DNRREF)
6788      {      {
6789      /* Never has other case. */      /* Never has other case. */
6790      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;
6791        SLJIT_ASSERT(!has_alternatives);
6792    
6793      stacksize = GET2(matchingpath, 1);      if (*matchingpath == OP_RREF)
     if (common->currententry == NULL)  
       stacksize = 0;  
     else if (stacksize == RREF_ANY)  
       stacksize = 1;  
     else if (common->currententry->start == 0)  
       stacksize = stacksize == 0;  
     else  
       stacksize = stacksize == (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);  
   
     if (*matchingpath == OP_RREF || stacksize || common->currententry == NULL)  
6794        {        {
6795        SLJIT_ASSERT(!has_alternatives);        stacksize = GET2(matchingpath, 1);
6796          if (common->currententry == NULL)
6797            stacksize = 0;
6798          else if (stacksize == RREF_ANY)
6799            stacksize = 1;
6800          else if (common->currententry->start == 0)
6801            stacksize = stacksize == 0;
6802          else
6803            stacksize = stacksize == (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6804    
6805        if (stacksize != 0)        if (stacksize != 0)
6806          matchingpath += 1 + IMM2_SIZE;          matchingpath += 1 + IMM2_SIZE;
6807          }
6808        else
6809          {
6810          if (common->currententry == NULL || common->currententry->start == 0)
6811            stacksize = 0;
6812        else        else
6813          {          {
6814            stacksize = GET2(matchingpath, 1 + IMM2_SIZE);
6815            slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;
6816            i = (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6817            while (stacksize > 0)
6818              {
6819              if ((int)GET2(slot, 0) == i)
6820                break;
6821              slot += common->name_entry_size;
6822              stacksize--;
6823              }
6824            }
6825    
6826          if (stacksize != 0)
6827            matchingpath += 1 + 2 * IMM2_SIZE;
6828          }
6829    
6830          /* The stacksize == 0 is a common "else" case. */
6831          if (stacksize == 0)
6832            {
6833          if (*cc == OP_ALT)          if (*cc == OP_ALT)
6834            {            {
6835            matchingpath = cc + 1 + LINK_SIZE;            matchingpath = cc + 1 + LINK_SIZE;
# Line 6495  if (opcode == OP_COND || opcode == OP_SC Line 6838  if (opcode == OP_COND || opcode == OP_SC
6838          else          else
6839            matchingpath = cc;            matchingpath = cc;
6840          }          }
       }  
     else  
       {  
       SLJIT_ASSERT(has_alternatives);  
   
       stacksize = GET2(matchingpath, 1);  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, GET2(common->start, common->currententry->start + 1 + LINK_SIZE));  
       OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, stacksize);  
       GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, 0);  
       OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);  
       sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchgroups));  
       OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);  
       add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0));  
       matchingpath += 1 + IMM2_SIZE;  
       }  
6841      }      }
6842    else    else
6843      {      {
# Line 6663  if (bra == OP_BRAMINZERO) Line 6988  if (bra == OP_BRAMINZERO)
6988    }    }
6989    
6990  if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)  if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)
6991    decrease_call_count(common);    count_match(common);
6992    
6993  /* Skip the other alternatives. */  /* Skip the other alternatives. */
6994  while (*cc == OP_ALT)  while (*cc == OP_ALT)
# Line 6950  if (!zero) Line 7275  if (!zero)
7275    
7276  /* None of them matched. */  /* None of them matched. */
7277  set_jumps(emptymatch, LABEL());  set_jumps(emptymatch, LABEL());
7278  decrease_call_count(common);  count_match(common);
7279  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
7280  }  }
7281    
7282  static SLJIT_INLINE pcre_uchar *get_iterator_parameters(compiler_common *common, pcre_uchar *cc, pcre_uchar *opcode, pcre_uchar *type, int *arg1, int *arg2, pcre_uchar **end)  static SLJIT_INLINE pcre_uchar *get_iterator_parameters(compiler_common *common, pcre_uchar *cc, pcre_uchar *opcode, pcre_uchar *type, int *max, int *min, pcre_uchar **end)
7283  {  {
7284  int class_len;  int class_len;
7285    
# Line 6990  else if (*opcode >= OP_TYPESTAR && *opco Line 7315  else if (*opcode >= OP_TYPESTAR && *opco
7315    }    }
7316  else  else
7317    {    {
7318    SLJIT_ASSERT(*opcode >= OP_CLASS || *opcode <= OP_XCLASS);    SLJIT_ASSERT(*opcode == OP_CLASS || *opcode == OP_NCLASS || *opcode == OP_XCLASS);
7319    *type = *opcode;    *type = *opcode;
7320    cc++;    cc++;
7321    class_len = (*type < OP_XCLASS) ? (int)(1 + (32 / sizeof(pcre_uchar))) : GET(cc, 0);    class_len = (*type < OP_XCLASS) ? (int)(1 + (32 / sizeof(pcre_uchar))) : GET(cc, 0);
# Line 7001  else Line 7326  else
7326      if (end != NULL)      if (end != NULL)
7327        *end = cc + class_len;        *end = cc + class_len;
7328      }      }
7329      else if (*opcode >= OP_CRPOSSTAR && *opcode <= OP_CRPOSQUERY)
7330        {
7331        *opcode -= OP_CRPOSSTAR - OP_POSSTAR;
7332        if (end != NULL)
7333          *end = cc + class_len;
7334        }
7335    else    else
7336      {      {
7337      SLJIT_ASSERT(*opcode == OP_CRRANGE || *opcode == OP_CRMINRANGE);      SLJIT_ASSERT(*opcode == OP_CRRANGE || *opcode == OP_CRMINRANGE || *opcode == OP_CRPOSRANGE);
7338      *arg1 = GET2(cc, (class_len + IMM2_SIZE));      *max = GET2(cc, (class_len + IMM2_SIZE));
7339      *arg2 = GET2(cc, class_len);      *min = GET2(cc, class_len);
7340    
7341      if (*arg2 == 0)      if (*min == 0)
7342        {        {
7343        SLJIT_ASSERT(*arg1 != 0);        SLJIT_ASSERT(*max != 0);
7344        *opcode = (*opcode == OP_CRRANGE) ? OP_UPTO : OP_MINUPTO;        *opcode = (*opcode == OP_CRRANGE) ? OP_UPTO : (*opcode == OP_CRMINRANGE ? OP_MINUPTO : OP_POSUPTO);
7345        }        }
7346      if (*arg1 == *arg2)      if (*max == *min)
7347        *opcode = OP_EXACT;        *opcode = OP_EXACT;
7348    
7349      if (end != NULL)      if (end != NULL)
# Line 7023  else Line 7354  else
7354    
7355  if (*opcode == OP_UPTO || *opcode == OP_MINUPTO || *opcode == OP_EXACT || *opcode == OP_POSUPTO)  if (*opcode == OP_UPTO || *opcode == OP_MINUPTO || *opcode == OP_EXACT || *opcode == OP_POSUPTO)
7356    {    {
7357    *arg1 = GET2(cc, 0);    *max = GET2(cc, 0);
7358    cc += IMM2_SIZE;    cc += IMM2_SIZE;
7359    }    }
7360    
# Line 7052  DEFINE_COMPILER; Line 7383  DEFINE_COMPILER;
7383  backtrack_common *backtrack;  backtrack_common *backtrack;
7384  pcre_uchar opcode;  pcre_uchar opcode;
7385  pcre_uchar type;  pcre_uchar type;
7386  int arg1 = -1, arg2 = -1;  int max = -1, min = -1;
7387  pcre_uchar* end;  pcre_uchar* end;
7388  jump_list *nomatch = NULL;  jump_list *nomatch = NULL;
7389  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 7065  int tmp_base, tmp_offset; Line 7396  int tmp_base, tmp_offset;
7396    
7397  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
7398    
7399  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);  cc = get_iterator_parameters(common, cc, &opcode, &type, &max, &min, &end);
7400    
7401  switch(type)  switch(type)
7402    {    {
# Line 7136  switch(opcode) Line 7467  switch(opcode)
7467        {        {
7468        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);
7469        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
7470        if (opcode == OP_CRRANGE && arg2 > 0)        if (opcode == OP_CRRANGE && min > 0)
7471          CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg2, label);          CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min, label);
7472        if (opcode == OP_UPTO || (opcode == OP_CRRANGE && arg1 > 0))        if (opcode == OP_UPTO || (opcode == OP_CRRANGE && max > 0))
7473          jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, arg1);          jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, max);
7474        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);
7475        }        }
7476    
# Line 7166  switch(opcode) Line 7497  switch(opcode)
7497      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
7498      if (opcode <= OP_PLUS)      if (opcode <= OP_PLUS)
7499        JUMPTO(SLJIT_JUMP, label);        JUMPTO(SLJIT_JUMP, label);
7500      else if (opcode == OP_CRRANGE && arg1 == 0)      else if (opcode == OP_CRRANGE && max == 0)
7501        {        {
7502        OP2(SLJIT_ADD, base, offset1, base, offset1, SLJIT_IMM, 1);        OP2(SLJIT_ADD, base, offset1, base, offset1, SLJIT_IMM, 1);
7503        JUMPTO(SLJIT_JUMP, label);        JUMPTO(SLJIT_JUMP, label);
# Line 7176  switch(opcode) Line 7507  switch(opcode)
7507        OP1(SLJIT_MOV, TMP1, 0, base, offset1);        OP1(SLJIT_MOV, TMP1, 0, base, offset1);
7508        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
7509        OP1(SLJIT_MOV, base, offset1, TMP1, 0);        OP1(SLJIT_MOV, base, offset1, TMP1, 0);
7510        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg1 + 1, label);        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, max + 1, label);
7511        }        }
7512      set_jumps(nomatch, LABEL());      set_jumps(nomatch, LABEL());
7513      if (opcode == OP_CRRANGE)      if (opcode == OP_CRRANGE)
7514        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_LESS, base, offset1, SLJIT_IMM, arg2 + 1));        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_LESS, base, offset1, SLJIT_IMM, min + 1));
7515      OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);      OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
7516      }      }
7517    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
# Line 7218  switch(opcode) Line 7549  switch(opcode)
7549    break;    break;
7550    
7551    case OP_EXACT:    case OP_EXACT:
7552    OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, arg1);    OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, max);
7553    label = LABEL();    label = LABEL();
7554    compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);    compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7555    OP2(SLJIT_SUB | SLJIT_SET_E, tmp_base, tmp_offset, tmp_base, tmp_offset, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, tmp_base, tmp_offset, tmp_base, tmp_offset, SLJIT_IMM, 1);
# Line 7231  switch(opcode) Line 7562  switch(opcode)
7562    if (opcode == OP_POSPLUS)    if (opcode == OP_POSPLUS)
7563      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7564    if (opcode == OP_POSUPTO)    if (opcode == OP_POSUPTO)
7565      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, arg1);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, max);
7566    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7567    label = LABEL();    label = LABEL();
7568    compile_char1_matchingpath(common, type, cc, &nomatch);    compile_char1_matchingpath(common, type, cc, &nomatch);
# Line 7255  switch(opcode) Line 7586  switch(opcode)
7586    OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);    OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);
7587    break;    break;
7588    
7589      case OP_CRPOSRANGE:
7590      /* Combination of OP_EXACT and OP_POSSTAR or OP_POSUPTO */
7591      OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, min);
7592      label = LABEL();
7593      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7594      OP2(SLJIT_SUB | SLJIT_SET_E, tmp_base, tmp_offset, tmp_base, tmp_offset, SLJIT_IMM, 1);
7595      JUMPTO(SLJIT_C_NOT_ZERO, label);
7596    
7597      if (max != 0)
7598        {
7599        SLJIT_ASSERT(max - min > 0);
7600        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, max - min);
7601        }
7602      OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7603      label = LABEL();
7604      compile_char1_matchingpath(common, type, cc, &nomatch);
7605      OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7606      if (max == 0)
7607        JUMPTO(SLJIT_JUMP, label);
7608      else
7609        {
7610        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, 1);
7611        JUMPTO(SLJIT_C_NOT_ZERO, label);
7612        }
7613      set_jumps(nomatch, LABEL());
7614      OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);
7615      break;
7616    
7617    default:    default:
7618    SLJIT_ASSERT_STOP();    SLJIT_ASSERT_STOP();
7619    break;    break;
7620    }    }
7621    
7622  decrease_call_count(common);  count_match(common);
7623  return end;  return end;
7624  }  }
7625    
# Line 7532  while (cc < ccend) Line 7891  while (cc < ccend)
7891    
7892      case OP_CLASS:      case OP_CLASS:
7893      case OP_NCLASS:      case OP_NCLASS:
7894      if (cc[1 + (32 / sizeof(pcre_uchar))] >= OP_CRSTAR && cc[1 + (32 / sizeof(pcre_uchar))] <= OP_CRMINRANGE)      if (cc[1 + (32 / sizeof(pcre_uchar))] >= OP_CRSTAR && cc[1 + (32 / sizeof(pcre_uchar))] <= OP_CRPOSRANGE)
7895        cc = compile_iterator_matchingpath(common, cc, parent);        cc = compile_iterator_matchingpath(common, cc, parent);
7896      else      else
7897        cc = compile_char1_matchingpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);        cc = compile_char1_matchingpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);
# Line 7540  while (cc < ccend) Line 7899  while (cc < ccend)
7899    
7900  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
7901      case OP_XCLASS:      case OP_XCLASS:
7902      if (*(cc + GET(cc, 1)) >= OP_CRSTAR && *(cc + GET(cc, 1)) <= OP_CRMINRANGE)      if (*(cc + GET(cc, 1)) >= OP_CRSTAR && *(cc + GET(cc, 1)) <= OP_CRPOSRANGE)
7903        cc = compile_iterator_matchingpath(common, cc, parent);        cc = compile_iterator_matchingpath(common, cc, parent);
7904      else      else
7905        cc = compile_char1_matchingpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);        cc = compile_char1_matchingpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);
# Line 7549  while (cc < ccend) Line 7908  while (cc < ccend)
7908    
7909      case OP_REF:      case OP_REF:
7910      case OP_REFI:      case OP_REFI:
7911      if (cc[1 + IMM2_SIZE] >= OP_CRSTAR && cc[1 + IMM2_SIZE] <= OP_CRMINRANGE)      if (cc[1 + IMM2_SIZE] >= OP_CRSTAR && cc[1 + IMM2_SIZE] <= OP_CRPOSRANGE)
7912          cc = compile_ref_iterator_matchingpath(common, cc, parent);
7913        else
7914          {
7915          compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);
7916          cc += 1 + IMM2_SIZE;
7917          }
7918        break;
7919    
7920        case OP_DNREF:
7921        case OP_DNREFI:
7922        if (cc[1 + 2 * IMM2_SIZE] >= OP_CRSTAR && cc[1 + 2 * IMM2_SIZE] <= OP_CRPOSRANGE)
7923        cc = compile_ref_iterator_matchingpath(common, cc, parent);        cc = compile_ref_iterator_matchingpath(common, cc, parent);
7924      else      else
7925        cc = compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);        {
7926          compile_dnref_search(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);
7927          compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);
7928          cc += 1 + 2 * IMM2_SIZE;
7929          }
7930      break;      break;
7931    
7932      case OP_RECURSE:      case OP_RECURSE:
# Line 7587  while (cc < ccend) Line 7961  while (cc < ccend)
7961        }        }
7962      BACKTRACK_AS(braminzero_backtrack)->matchingpath = LABEL();      BACKTRACK_AS(braminzero_backtrack)->matchingpath = LABEL();
7963      if (cc[1] > OP_ASSERTBACK_NOT)      if (cc[1] > OP_ASSERTBACK_NOT)
7964        decrease_call_count(common);        count_match(common);
7965      break;      break;
7966    
7967      case OP_ONCE:      case OP_ONCE:
# Line 7705  DEFINE_COMPILER; Line 8079  DEFINE_COMPILER;
8079  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
8080  pcre_uchar opcode;  pcre_uchar opcode;
8081  pcre_uchar type;  pcre_uchar type;
8082  int arg1 = -1, arg2 = -1;  int max = -1, min = -1;
8083  struct sljit_label *label = NULL;  struct sljit_label *label = NULL;
8084  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
8085  jump_list *jumplist = NULL;  jump_list *jumplist = NULL;
# Line 7714  int base = (private_data_ptr == 0) ? SLJ Line 8088  int base = (private_data_ptr == 0) ? SLJ
8088  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;
8089  int offset1 = (private_data_ptr == 0) ? STACK(1) : private_data_ptr + (int)sizeof(sljit_sw);  int offset1 = (private_data_ptr == 0) ? STACK(1) : private_data_ptr + (int)sizeof(sljit_sw);
8090    
8091  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, NULL);  cc = get_iterator_parameters(common, cc, &opcode, &type, &max, &min, NULL);
8092    
8093  switch(opcode)  switch(opcode)
8094    {    {
# Line 7733  switch(opcode) Line 8107  switch(opcode)
8107    else    else
8108      {      {
8109      if (opcode == OP_UPTO)      if (opcode == OP_UPTO)
8110        arg2 = 0;        min = 0;
8111      if (opcode <= OP_PLUS)      if (opcode <= OP_PLUS)
8112        {        {
8113        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
# Line 7743  switch(opcode) Line 8117  switch(opcode)
8117        {        {
8118        OP1(SLJIT_MOV, TMP1, 0, base, offset1);        OP1(SLJIT_MOV, TMP1, 0, base, offset1);
8119        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
8120        jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, arg2 + 1);        jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, min + 1);
8121        OP2(SLJIT_SUB, base, offset1, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_SUB, base, offset1, TMP1, 0, SLJIT_IMM, 1);
8122        }        }
8123      skip_char_back(common);      skip_char_back(common);
# Line 7788  switch(opcode) Line 8162  switch(opcode)
8162    OP1(SLJIT_MOV, base, offset1, TMP1, 0);    OP1(SLJIT_MOV, base, offset1, TMP1, 0);
8163    
8164    if (opcode == OP_CRMINRANGE)    if (opcode == OP_CRMINRANGE)
8165      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg2 + 1, label);      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min + 1, label);
8166    
8167    if (opcode == OP_CRMINRANGE && arg1 == 0)    if (opcode == OP_CRMINRANGE && max == 0)
8168      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->matchingpath);      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->matchingpath);
8169    else    else
8170      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg1 + 2, CURRENT_AS(iterator_backtrack)->matchingpath);      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, max + 2, CURRENT_AS(iterator_backtrack)->matchingpath);
8171    
8172    set_jumps(jumplist, LABEL());    set_jumps(jumplist, LABEL());
8173    if (private_data_ptr == 0)    if (private_data_ptr == 0)
# Line 7828  switch(opcode) Line 8202  switch(opcode)
8202    
8203    case OP_EXACT:    case OP_EXACT:
8204    case OP_POSPLUS:    case OP_POSPLUS:
8205      case OP_CRPOSRANGE:
8206    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
8207    break;    break;
8208    
# Line 7846  static SLJIT_INLINE void compile_ref_ite Line 8221  static SLJIT_INLINE void compile_ref_ite
8221  {  {
8222  DEFINE_COMPILER;  DEFINE_COMPILER;
8223  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
8224    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
8225  pcre_uchar type;  pcre_uchar type;
8226    
8227  type = cc[1 + IMM2_SIZE];  type = cc[ref ? 1 + IMM2_SIZE : 1 + 2 * IMM2_SIZE];
8228    
8229  if ((type & 0x1) == 0)  if ((type & 0x1) == 0)
8230    {    {
8231      /* Maximize case. */
8232    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
8233    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8234    free_stack(common, 1);    free_stack(common, 1);
# Line 7861  if ((type & 0x1) == 0) Line 8239  if ((type & 0x1) == 0)
8239  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8240  CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(iterator_backtrack)->matchingpath);  CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(iterator_backtrack)->matchingpath);
8241  set_jumps(current->topbacktracks, LABEL());  set_jumps(current->topbacktracks, LABEL());
8242  free_stack(common, 2);  free_stack(common, ref ? 2 : 3);
8243  }  }
8244    
8245  static SLJIT_INLINE void compile_recurse_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static SLJIT_INLINE void compile_recurse_backtrackingpath(compiler_common *common, struct backtrack_common *current)
# Line 8225  if (has_alternatives) Line 8603  if (has_alternatives)
8603          return;          return;
8604        }        }
8605    
8606      /* Instructions after the current alternative is succesfully matched. */      /* Instructions after the current alternative is successfully matched. */
8607      /* There is a similar code in compile_bracket_matchingpath. */      /* There is a similar code in compile_bracket_matchingpath. */
8608      if (opcode == OP_ONCE)      if (opcode == OP_ONCE)
8609        match_once_common(common, ket, CURRENT_AS(bracket_backtrack)->u.framesize, private_data_ptr, has_alternatives, needs_control_head);        match_once_common(common, ket, CURRENT_AS(bracket_backtrack)->u.framesize, private_data_ptr, has_alternatives, needs_control_head);
# Line 8662  while (current) Line 9040  while (current)
9040    
9041      case OP_REF:      case OP_REF:
9042      case OP_REFI:      case OP_REFI:
9043        case OP_DNREF:
9044        case OP_DNREFI:
9045      compile_ref_iterator_backtrackingpath(common, current);      compile_ref_iterator_backtrackingpath(common, current);
9046      break;      break;
9047    
# Line 8956  else Line 9336  else
9336  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
9337  common->ctypes = (sljit_sw)(tables + ctypes_offset);  common->ctypes = (sljit_sw)(tables + ctypes_offset);
9338  common->digits[0] = -2;  common->digits[0] = -2;
9339  common->name_table = (sljit_sw)((pcre_uchar *)re + re->name_table_offset);  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;
9340  common->name_count = re->name_count;  common->name_count = re->name_count;
9341  common->name_entry_size = re->name_entry_size;  common->name_entry_size = re->name_entry_size;
9342  common->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;  common->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
# Line 8970  common->use_ucp = (re->options & PCRE_UC Line 9350  common->use_ucp = (re->options & PCRE_UC
9350  ccend = bracketend(rootbacktrack.cc);  ccend = bracketend(rootbacktrack.cc);
9351    
9352  /* Calculate the local space size on the stack. */  /* Calculate the local space size on the stack. */
9353  common->ovector_start = CALL_LIMIT + sizeof(sljit_sw);  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);
9354  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);
9355  if (!common->optimized_cbracket)  if (!common->optimized_cbracket)
9356    return;    return;
# Line 9102  OP1(SLJIT_MOV, TMP1, 0, SLJIT_SAVED_REG1 Line 9482  OP1(SLJIT_MOV, TMP1, 0, SLJIT_SAVED_REG1
9482  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
9483  OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, end));  OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, end));
9484  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, stack));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, stack));
9485  OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, call_limit));  OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, limit_match));
9486  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, base));  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, base));
9487  OP1(SLJIT_MOV, STACK_LIMIT, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, limit));  OP1(SLJIT_MOV, STACK_LIMIT, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, limit));
9488  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CALL_LIMIT, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LIMIT_MATCH, TMP1, 0);
9489    
9490  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
9491    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
# Line 9129  if ((re->options & PCRE_ANCHORED) == 0) Line 9509  if ((re->options & PCRE_ANCHORED) == 0)
9509      else if ((re->flags & PCRE_STARTLINE) != 0)      else if ((re->flags & PCRE_STARTLINE) != 0)
9510        fast_forward_newline(common, (re->options & PCRE_FIRSTLINE) != 0);        fast_forward_newline(common, (re->options & PCRE_FIRSTLINE) != 0);
9511      else if ((re->flags & PCRE_STARTLINE) == 0 && study != NULL && (study->flags & PCRE_STUDY_MAPPED) != 0)      else if ((re->flags & PCRE_STARTLINE) == 0 && study != NULL && (study->flags & PCRE_STUDY_MAPPED) != 0)
9512        fast_forward_start_bits(common, (sljit_uw)study->start_bits, (re->options & PCRE_FIRSTLINE) != 0);        fast_forward_start_bits(common, study->start_bits, (re->options & PCRE_FIRSTLINE) != 0);
9513      }      }
9514    }    }
9515  else  else
# Line 9147  if (common->req_char_ptr != 0) Line 9527  if (common->req_char_ptr != 0)
9527  /* Store the current STR_PTR in OVECTOR(0). */  /* Store the current STR_PTR in OVECTOR(0). */
9528  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), STR_PTR, 0);
9529  /* Copy the limit of allowed recursions. */  /* Copy the limit of allowed recursions. */
9530  OP1(SLJIT_MOV, CALL_COUNT, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), CALL_LIMIT);  OP1(SLJIT_MOV, COUNT_MATCH, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LIMIT_MATCH);
9531  if (common->capture_last_ptr != 0)  if (common->capture_last_ptr != 0)
9532    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, -1);
9533    
# Line 9425  else Line 9805  else
9805      }      }
9806    memset(functions, 0, sizeof(executable_functions));    memset(functions, 0, sizeof(executable_functions));
9807    functions->top_bracket = (re->top_bracket + 1) * 2;    functions->top_bracket = (re->top_bracket + 1) * 2;
9808      functions->limit_match = (re->flags & PCRE_MLSET) != 0 ? re->limit_match : 0;
9809    extra->executable_jit = functions;    extra->executable_jit = functions;
9810    extra->flags |= PCRE_EXTRA_EXECUTABLE_JIT;    extra->flags |= PCRE_EXTRA_EXECUTABLE_JIT;
9811    }    }
# Line 9479  arguments.begin = subject; Line 9860  arguments.begin = subject;
9860  arguments.end = subject + length;  arguments.end = subject + length;
9861  arguments.mark_ptr = NULL;  arguments.mark_ptr = NULL;
9862  /* JIT decreases this value less frequently than the interpreter. */  /* JIT decreases this value less frequently than the interpreter. */
9863  arguments.call_limit = ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0) ? MATCH_LIMIT : extra_data->match_limit;  arguments.limit_match = ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0) ? MATCH_LIMIT : (pcre_uint32)(extra_data->match_limit);
9864    if (functions->limit_match != 0 && functions->limit_match < arguments.limit_match)
9865      arguments.limit_match = functions->limit_match;
9866  arguments.notbol = (options & PCRE_NOTBOL) != 0;  arguments.notbol = (options & PCRE_NOTBOL) != 0;
9867  arguments.noteol = (options & PCRE_NOTEOL) != 0;  arguments.noteol = (options & PCRE_NOTEOL) != 0;
9868  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
# Line 9570  arguments.begin = subject_ptr; Line 9953  arguments.begin = subject_ptr;
9953  arguments.end = subject_ptr + length;  arguments.end = subject_ptr + length;
9954  arguments.mark_ptr = NULL;  arguments.mark_ptr = NULL;
9955  /* JIT decreases this value less frequently than the interpreter. */  /* JIT decreases this value less frequently than the interpreter. */
9956  arguments.call_limit = ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0) ? MATCH_LIMIT : extra_data->match_limit;  arguments.limit_match = ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0) ? MATCH_LIMIT : (pcre_uint32)(extra_data->match_limit);
9957    if (functions->limit_match != 0 && functions->limit_match < arguments.limit_match)
9958      arguments.limit_match = functions->limit_match;
9959  arguments.notbol = (options & PCRE_NOTBOL) != 0;  arguments.notbol = (options & PCRE_NOTBOL) != 0;
9960  arguments.noteol = (options & PCRE_NOTEOL) != 0;  arguments.noteol = (options & PCRE_NOTEOL) != 0;
9961  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
# Line 9689  if (extra != NULL && Line 10074  if (extra != NULL &&
10074    }    }
10075  }  }
10076    
10077    #if defined COMPILE_PCRE8
10078    PCRE_EXP_DECL void
10079    pcre_jit_free_unused_memory(void)
10080    #elif defined COMPILE_PCRE16
10081    PCRE_EXP_DECL void
10082    pcre16_jit_free_unused_memory(void)
10083    #elif defined COMPILE_PCRE32
10084    PCRE_EXP_DECL void
10085    pcre32_jit_free_unused_memory(void)
10086    #endif
10087    {
10088    sljit_free_unused_memory_exec();
10089    }
10090    
10091  #else  /* SUPPORT_JIT */  #else  /* SUPPORT_JIT */
10092    
10093  /* These are dummy functions to avoid linking errors when JIT support is not  /* These are dummy functions to avoid linking errors when JIT support is not
# Line 9740  pcre32_assign_jit_stack(pcre32_extra *ex Line 10139  pcre32_assign_jit_stack(pcre32_extra *ex
10139  (void)userdata;  (void)userdata;
10140  }  }
10141    
10142    #if defined COMPILE_PCRE8
10143    PCRE_EXP_DECL void
10144    pcre_jit_free_unused_memory(void)
10145    #elif defined COMPILE_PCRE16
10146    PCRE_EXP_DECL void
10147    pcre16_jit_free_unused_memory(void)
10148    #elif defined COMPILE_PCRE32
10149    PCRE_EXP_DECL void
10150    pcre32_jit_free_unused_memory(void)
10151    #endif
10152    {
10153    }
10154    
10155  #endif  #endif
10156    
10157  /* End of pcre_jit_compile.c */  /* End of pcre_jit_compile.c */

Legend:
Removed from v.1308  
changed lines
  Added in v.1419

  ViewVC Help
Powered by ViewVC 1.1.5