/[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 1310 by zherczeg, Sat Apr 6 06:51:09 2013 UTC revision 1415 by zherczeg, Sun Dec 22 20:47:08 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 584  switch(*cc) Line 585  switch(*cc)
585    case OP_CRMINQUERY:    case OP_CRMINQUERY:
586    case OP_CRRANGE:    case OP_CRRANGE:
587    case OP_CRMINRANGE:    case OP_CRMINRANGE:
588      case OP_CRPOSSTAR:
589      case OP_CRPOSPLUS:
590      case OP_CRPOSQUERY:
591      case OP_CRPOSRANGE:
592    case OP_CLASS:    case OP_CLASS:
593    case OP_NCLASS:    case OP_NCLASS:
594    case OP_REF:    case OP_REF:
595    case OP_REFI:    case OP_REFI:
596      case OP_DNREF:
597      case OP_DNREFI:
598    case OP_RECURSE:    case OP_RECURSE:
599    case OP_CALLOUT:    case OP_CALLOUT:
600    case OP_ALT:    case OP_ALT:
# Line 613  switch(*cc) Line 620  switch(*cc)
620    case OP_SCBRAPOS:    case OP_SCBRAPOS:
621    case OP_SCOND:    case OP_SCOND:
622    case OP_CREF:    case OP_CREF:
623    case OP_NCREF:    case OP_DNCREF:
624    case OP_RREF:    case OP_RREF:
625    case OP_NRREF:    case OP_DNRREF:
626    case OP_DEF:    case OP_DEF:
627    case OP_BRAZERO:    case OP_BRAZERO:
628    case OP_BRAMINZERO:    case OP_BRAMINZERO:
# Line 735  switch(*cc) Line 742  switch(*cc)
742    
743  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)
744  {  {
745  pcre_uchar *name;  int count;
746  pcre_uchar *name2;  pcre_uchar *slot;
 unsigned int cbra_index;  
 int i;  
747    
748  /* 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. */
749  while (cc < ccend)  while (cc < ccend)
# Line 772  while (cc < ccend) Line 777  while (cc < ccend)
777      break;      break;
778    
779      case OP_CREF:      case OP_CREF:
780      i = GET2(cc, 1);      common->optimized_cbracket[GET2(cc, 1)] = 0;
     common->optimized_cbracket[i] = 0;  
781      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
782      break;      break;
783    
784      case OP_NCREF:      case OP_DNREF:
785      cbra_index = GET2(cc, 1);      case OP_DNREFI:
786      name = (pcre_uchar *)common->name_table;      case OP_DNCREF:
787      name2 = name;      count = GET2(cc, 1 + IMM2_SIZE);
788      for (i = 0; i < common->name_count; i++)      slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
789        {      while (count-- > 0)
790        if (GET2(name, 0) == cbra_index) break;        {
791        name += common->name_entry_size;        common->optimized_cbracket[GET2(slot, 0)] = 0;
792        }        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;  
793        }        }
794      cc += 1 + IMM2_SIZE;      cc += 1 + 2 * IMM2_SIZE;
795      break;      break;
796    
797      case OP_RECURSE:      case OP_RECURSE:
# Line 2022  while (list_item) Line 2019  while (list_item)
2019  common->stubs = NULL;  common->stubs = NULL;
2020  }  }
2021    
2022  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2023  {  {
2024  DEFINE_COMPILER;  DEFINE_COMPILER;
2025    
2026  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);
2027  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2028  }  }
2029    
# Line 2373  return (bit < 256) ? ((0 << 8) | bit) : Line 2370  return (bit < 256) ? ((0 << 8) | bit) :
2370    
2371  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2372  {  {
2373  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2374  DEFINE_COMPILER;  DEFINE_COMPILER;
2375  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2376    
# Line 3209  if (firstline) Line 3206  if (firstline)
3206    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3207  }  }
3208    
3209  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);
3210    
3211  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)
3212  {  {
3213  DEFINE_COMPILER;  DEFINE_COMPILER;
3214  struct sljit_label *start;  struct sljit_label *start;
3215  struct sljit_jump *quit;  struct sljit_jump *quit;
3216  struct sljit_jump *found = NULL;  struct sljit_jump *found = NULL;
3217  jump_list *matches = NULL;  jump_list *matches = NULL;
 pcre_uint8 inverted_start_bits[32];  
 int i;  
3218  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3219  struct sljit_jump *jump;  struct sljit_jump *jump;
3220  #endif  #endif
3221    
 for (i = 0; i < 32; ++i)  
   inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);  
   
3222  if (firstline)  if (firstline)
3223    {    {
3224    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
# Line 3242  if (common->utf) Line 3234  if (common->utf)
3234    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3235  #endif  #endif
3236    
3237  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))
3238    {    {
3239  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3240    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
# Line 3251  if (!check_class_ranges(common, inverted Line 3243  if (!check_class_ranges(common, inverted
3243  #endif  #endif
3244    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3245    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3246    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
3247    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3248    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);
3249    found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
# Line 3511  sljit_emit_fast_return(compiler, SLJIT_M Line 3503  sljit_emit_fast_return(compiler, SLJIT_M
3503  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)
3504  {  {
3505  DEFINE_COMPILER;  DEFINE_COMPILER;
 struct sljit_jump *jump;  
3506    
3507  if (ranges[0] < 0)  if (ranges[0] < 0 || ranges[0] > 4)
3508    return FALSE;    return FALSE;
3509    
3510    /* No character is accepted. */
3511    if (ranges[0] == 0 && ranges[1] == 0)
3512      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
3513    
3514    if (readch)
3515      read_char(common);
3516    
3517  switch(ranges[0])  switch(ranges[0])
3518    {    {
3519      case 0:
3520      /* When ranges[1] != 0, all characters are accepted. */
3521      return TRUE;
3522    
3523    case 1:    case 1:
   if (readch)  
     read_char(common);  
3524    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]));
3525    return TRUE;    return TRUE;
3526    
3527    case 2:    case 2:
3528    if (readch)    if (ranges[2] + 1 != ranges[3])
3529      read_char(common);      {
3530    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3531    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]));
3532        }
3533      else
3534        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3535    return TRUE;    return TRUE;
3536    
3537    case 4:    case 3:
3538    if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])    if (ranges[1] != 0)
3539      {      {
3540      if (readch)      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3541        read_char(common);      if (ranges[2] + 1 != ranges[3])
     if (ranges[1] != 0)  
3542        {        {
3543        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]);
3544        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]));
3545        }        }
3546      else      else
3547          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3548        return TRUE;
3549        }
3550    
3551      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2]));
3552      if (ranges[3] + 1 != ranges[4])
3553        {
3554        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[3]);
3555        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[3]));
3556        }
3557      else
3558        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3]));
3559      return TRUE;
3560    
3561      case 4:
3562      if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4])
3563          && (ranges[2] | (ranges[4] - ranges[2])) == ranges[4]
3564          && is_powerof2(ranges[4] - ranges[2]))
3565        {
3566        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);
3567        if (ranges[4] + 1 != ranges[5])
3568        {        {
3569        jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3570        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);  
3571        }        }
3572        else
3573          add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3574      return TRUE;      return TRUE;
3575      }      }
3576    if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))  
3577      if (ranges[1] != 0)
3578      {      {
3579      if (readch)      if (ranges[2] + 1 != ranges[3])
3580        read_char(common);        {
3581      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3582      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]));
3583      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];
3584          ranges[5] -= ranges[2];
3585          }
3586        else
3587          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3588    
3589        if (ranges[4] + 1 != ranges[5])
3590          {
3591          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3592          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3593          }
3594        else
3595          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3596      return TRUE;      return TRUE;
3597      }      }
3598    return FALSE;  
3599      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3600      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[2]));
3601      if (ranges[3] + 1 != ranges[4])
3602        {
3603        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]);
3604        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[3]));
3605        }
3606      else
3607        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3608      return TRUE;
3609    
3610    default:    default:
3611      SLJIT_ASSERT_STOP();
3612    return FALSE;    return FALSE;
3613    }    }
3614  }  }
# Line 3595  if (bit != 0) Line 3643  if (bit != 0)
3643  ranges[0] = length;  ranges[0] = length;
3644  }  }
3645    
3646  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)
3647  {  {
3648  int ranges[2 + MAX_RANGE_SIZE];  int ranges[2 + MAX_RANGE_SIZE];
3649  pcre_uint8 bit, cbit, all;  pcre_uint8 bit, cbit, all;
3650  int i, byte, length = 0;  int i, byte, length = 0;
3651    
3652  bit = bits[0] & 0x1;  bit = bits[0] & 0x1;
3653  ranges[1] = bit;  ranges[1] = !invert ? bit : (bit ^ 0x1);
3654  /* Can be 0 or 255. */  /* All bits will be zero or one (since bit is zero or one). */
3655  all = -bit;  all = -bit;
3656    
3657  for (i = 0; i < 256; )  for (i = 0; i < 256; )
# Line 4024  static void compile_xclass_matchingpath( Line 4072  static void compile_xclass_matchingpath(
4072  {  {
4073  DEFINE_COMPILER;  DEFINE_COMPILER;
4074  jump_list *found = NULL;  jump_list *found = NULL;
4075  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;
4076  pcre_int32 c, charoffset;  pcre_int32 c, charoffset;
 const pcre_uint32 *other_cases;  
4077  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4078  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4079  int compares, invertcmp, numberofcmps;  int compares, invertcmp, numberofcmps;
4080    
4081  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4082  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4083  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4084  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4085    const pcre_uint32 *other_cases;
4086  pcre_int32 typeoffset;  pcre_int32 typeoffset;
4087  #endif  #endif
4088    
# Line 4042  pcre_int32 typeoffset; Line 4091  pcre_int32 typeoffset;
4091  detect_partial_match(common, backtracks);  detect_partial_match(common, backtracks);
4092  read_char(common);  read_char(common);
4093    
4094  if ((*cc++ & XCL_MAP) != 0)  cc++;
4095    if ((cc[-1] & XCL_HASPROP) == 0)
4096    {    {
4097    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    if ((cc[-1] & XCL_MAP) != 0)
4098  #ifndef COMPILE_PCRE8      {
4099    jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4100  #elif defined SUPPORT_UTF  #ifdef SUPPORT_UCP
4101    if (common->utf)      charsaved = TRUE;
     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
4102  #endif  #endif
4103        if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, FALSE, backtracks))
4104          {
4105          jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4106    
4107          OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4108          OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4109          OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4110          OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4111          OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4112          add_jump(compiler, &found, JUMP(SLJIT_C_NOT_ZERO));
4113          add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4114    
4115    if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, list))        JUMPHERE(jump);
4116          }
4117        else
4118          add_jump(compiler, &found, CMP(SLJIT_C_LESS_EQUAL, TMP3, 0, SLJIT_IMM, 0xff));
4119    
4120        OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
4121        cc += 32 / sizeof(pcre_uchar);
4122        }
4123      else
4124        add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0xff));
4125      }
4126    else if ((cc[-1] & XCL_MAP) != 0)
4127      {
4128      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4129    #ifdef SUPPORT_UCP
4130      charsaved = TRUE;
4131    #endif
4132      if (!check_class_ranges(common, (const pcre_uint8 *)cc, FALSE, TRUE, list))
4133      {      {
4134    #ifdef COMPILE_PCRE8
4135        SLJIT_ASSERT(common->utf);
4136    #endif
4137        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4138    
4139      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4140      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4141      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4142      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4143      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);
4144      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
     }  
4145    
 #ifndef COMPILE_PCRE8  
   JUMPHERE(jump);  
 #elif defined SUPPORT_UTF  
   if (common->utf)  
4146      JUMPHERE(jump);      JUMPHERE(jump);
4147  #endif      }
4148    
4149    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
 #ifdef SUPPORT_UCP  
   charsaved = TRUE;  
 #endif  
4150    cc += 32 / sizeof(pcre_uchar);    cc += 32 / sizeof(pcre_uchar);
4151    }    }
4152    
# Line 4129  while (*cc != XCL_END) Line 4204  while (*cc != XCL_END)
4204        case PT_SPACE:        case PT_SPACE:
4205        case PT_PXSPACE:        case PT_PXSPACE:
4206        case PT_WORD:        case PT_WORD:
4207          case PT_PXGRAPH:
4208          case PT_PXPRINT:
4209          case PT_PXPUNCT:
4210        needstype = TRUE;        needstype = TRUE;
4211        needschar = TRUE;        needschar = TRUE;
4212        break;        break;
# Line 4316  while (*cc != XCL_END) Line 4394  while (*cc != XCL_END)
4394    
4395        case PT_SPACE:        case PT_SPACE:
4396        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);  
         }  
4397        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4398        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);
4399        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);
4400        if (*cc == PT_SPACE)  
4401          JUMPHERE(jump);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x9);
4402          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4403    
4404          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x9);
4405          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4406    
4407        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4408        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 4417  while (*cc != XCL_END) Line 4494  while (*cc != XCL_END)
4494        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);
4495        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4496        break;        break;
4497    
4498          case PT_PXGRAPH:
4499          /* C and Z groups are the farthest two groups. */
4500          SET_TYPE_OFFSET(ucp_Ll);
4501          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4502          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4503    
4504          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4505    
4506          /* In case of ucp_Cf, we overwrite the result. */
4507          SET_CHAR_OFFSET(0x2066);
4508          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4509          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4510    
4511          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4512          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4513    
4514          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x2066);
4515          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4516    
4517          JUMPHERE(jump);
4518          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4519          break;
4520    
4521          case PT_PXPRINT:
4522          /* C and Z groups are the farthest two groups. */
4523          SET_TYPE_OFFSET(ucp_Ll);
4524          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4525          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4526    
4527          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Ll);
4528          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_NOT_EQUAL);
4529    
4530          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4531    
4532          /* In case of ucp_Cf, we overwrite the result. */
4533          SET_CHAR_OFFSET(0x2066);
4534          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4535          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4536    
4537          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4538          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4539    
4540          JUMPHERE(jump);
4541          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4542          break;
4543    
4544          case PT_PXPUNCT:
4545          SET_TYPE_OFFSET(ucp_Sc);
4546          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Sc);
4547          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4548    
4549          SET_CHAR_OFFSET(0);
4550          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xff);
4551          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4552    
4553          SET_TYPE_OFFSET(ucp_Pc);
4554          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ps - ucp_Pc);
4555          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4556          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4557          break;
4558        }        }
4559      cc += 2;      cc += 2;
4560      }      }
# Line 4563  switch(type) Line 4701  switch(type)
4701  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4702    case OP_NOTPROP:    case OP_NOTPROP:
4703    case OP_PROP:    case OP_PROP:
4704    propdata[0] = 0;    propdata[0] = XCL_HASPROP;
4705    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;
4706    propdata[2] = cc[0];    propdata[2] = cc[0];
4707    propdata[3] = cc[1];    propdata[3] = cc[1];
# Line 4922  switch(type) Line 5060  switch(type)
5060    case OP_NCLASS:    case OP_NCLASS:
5061    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5062    read_char(common);    read_char(common);
5063    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))
5064      return cc + 32 / sizeof(pcre_uchar);      return cc + 32 / sizeof(pcre_uchar);
5065    
5066  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
# Line 5055  if (context.length > 0) Line 5193  if (context.length > 0)
5193  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);
5194  }  }
5195    
 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));  
 }  
   
5196  /* Forward definitions. */  /* Forward definitions. */
5197  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);
5198  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);
# Line 5109  static void compile_backtrackingpath(com Line 5225  static void compile_backtrackingpath(com
5225    
5226  #define BACKTRACK_AS(type) ((type *)backtrack)  #define BACKTRACK_AS(type) ((type *)backtrack)
5227    
5228  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)
5229    {
5230    /* The OVECTOR offset goes to TMP2. */
5231    DEFINE_COMPILER;
5232    int count = GET2(cc, 1 + IMM2_SIZE);
5233    pcre_uchar *slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
5234    unsigned int offset;
5235    jump_list *found = NULL;
5236    
5237    SLJIT_ASSERT(*cc == OP_DNREF || *cc == OP_DNREFI);
5238    
5239    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
5240    
5241    count--;
5242    while (count-- > 0)
5243      {
5244      offset = GET2(slot, 0) << 1;
5245      GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5246      add_jump(compiler, &found, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5247      slot += common->name_entry_size;
5248      }
5249    
5250    offset = GET2(slot, 0) << 1;
5251    GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5252    if (backtracks != NULL && !common->jscript_compat)
5253      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5254    
5255    set_jumps(found, LABEL());
5256    }
5257    
5258    static void compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)
5259  {  {
5260  DEFINE_COMPILER;  DEFINE_COMPILER;
5261  int offset = GET2(cc, 1) << 1;  BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5262    int offset = 0;
5263  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
5264  struct sljit_jump *partial;  struct sljit_jump *partial;
5265  struct sljit_jump *nopartial;  struct sljit_jump *nopartial;
5266    
5267  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  if (ref)
5268  /* OVECTOR(1) contains the "string begin - 1" constant. */    {
5269  if (withchecks && !common->jscript_compat)    offset = GET2(cc, 1) << 1;
5270    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));
5271      /* OVECTOR(1) contains the "string begin - 1" constant. */
5272      if (withchecks && !common->jscript_compat)
5273        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5274      }
5275    else
5276      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5277    
5278  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5279  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5280    {    {
5281    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);
5282    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));    if (ref)
5283        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5284      else
5285        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5286    
5287    if (withchecks)    if (withchecks)
5288      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5289    
# Line 5151  if (common->utf && *cc == OP_REFI) Line 5308  if (common->utf && *cc == OP_REFI)
5308  else  else
5309  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
5310    {    {
5311    OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);    if (ref)
5312        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
5313      else
5314        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
5315    
5316    if (withchecks)    if (withchecks)
5317      jump = JUMP(SLJIT_C_ZERO);      jump = JUMP(SLJIT_C_ZERO);
5318    
# Line 5188  if (jump != NULL) Line 5349  if (jump != NULL)
5349    else    else
5350      JUMPHERE(jump);      JUMPHERE(jump);
5351    }    }
 return cc + 1 + IMM2_SIZE;  
5352  }  }
5353    
5354  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)
5355  {  {
5356  DEFINE_COMPILER;  DEFINE_COMPILER;
5357    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5358  backtrack_common *backtrack;  backtrack_common *backtrack;
5359  pcre_uchar type;  pcre_uchar type;
5360    int offset = 0;
5361  struct sljit_label *label;  struct sljit_label *label;
5362  struct sljit_jump *zerolength;  struct sljit_jump *zerolength;
5363  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 5205  BOOL minimize; Line 5367  BOOL minimize;
5367    
5368  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
5369    
5370    if (ref)
5371      offset = GET2(cc, 1) << 1;
5372    else
5373      cc += IMM2_SIZE;
5374  type = cc[1 + IMM2_SIZE];  type = cc[1 + IMM2_SIZE];
5375    
5376    SLJIT_COMPILE_ASSERT((OP_CRSTAR & 0x1) == 0, crstar_opcode_must_be_even);
5377  minimize = (type & 0x1) != 0;  minimize = (type & 0x1) != 0;
5378  switch(type)  switch(type)
5379    {    {
# Line 5243  if (!minimize) Line 5411  if (!minimize)
5411    if (min == 0)    if (min == 0)
5412      {      {
5413      allocate_stack(common, 2);      allocate_stack(common, 2);
5414        if (ref)
5415          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5416      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5417      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5418      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5419      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));
5420      zerolength = compile_ref_checks(common, ccbegin, NULL);      /* Handles both invalid and empty cases. Since the minimum repeat,
5421        is zero the invalid case is basically the same as an empty case. */
5422        if (ref)
5423          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5424        else
5425          {
5426          compile_dnref_search(common, ccbegin, NULL);
5427          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5428          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5429          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5430          }
5431      /* Restore if not zero length. */      /* Restore if not zero length. */
5432      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));
5433      }      }
5434    else    else
5435      {      {
5436      allocate_stack(common, 1);      allocate_stack(common, 1);
5437        if (ref)
5438          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5439      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5440      zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);      if (ref)
5441          {
5442          add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5443          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5444          }
5445        else
5446          {
5447          compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5448          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5449          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5450          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5451          }
5452      }      }
5453    
5454    if (min > 1 || max > 1)    if (min > 1 || max > 1)
5455      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
5456    
5457    label = LABEL();    label = LABEL();
5458      if (!ref)
5459        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
5460    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);
5461    
5462    if (min > 1 || max > 1)    if (min > 1 || max > 1)
# Line 5292  if (!minimize) Line 5487  if (!minimize)
5487    JUMPHERE(zerolength);    JUMPHERE(zerolength);
5488    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5489    
5490    decrease_call_count(common);    count_match(common);
5491    return cc;    return cc;
5492    }    }
5493    
5494  allocate_stack(common, 2);  allocate_stack(common, ref ? 2 : 3);
5495    if (ref)
5496      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5497  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5498  if (type != OP_CRMINSTAR)  if (type != OP_CRMINSTAR)
5499    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5500    
5501  if (min == 0)  if (min == 0)
5502    {    {
5503    zerolength = compile_ref_checks(common, ccbegin, NULL);    /* Handles both invalid and empty cases. Since the minimum repeat,
5504      is zero the invalid case is basically the same as an empty case. */
5505      if (ref)
5506        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5507      else
5508        {
5509        compile_dnref_search(common, ccbegin, NULL);
5510        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5511        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5512        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5513        }
5514      /* Length is non-zero, we can match real repeats. */
5515    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5516    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
5517    }    }
5518  else  else
5519    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);    {
5520      if (ref)
5521        {
5522        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5523        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5524        }
5525      else
5526        {
5527        compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5528        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5529        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5530        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5531        }
5532      }
5533    
5534  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5535  if (max > 0)  if (max > 0)
5536    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));
5537    
5538    if (!ref)
5539      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
5540  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);
5541  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5542    
# Line 5331  if (jump != NULL) Line 5554  if (jump != NULL)
5554    JUMPHERE(jump);    JUMPHERE(jump);
5555  JUMPHERE(zerolength);  JUMPHERE(zerolength);
5556    
5557  decrease_call_count(common);  count_match(common);
5558  return cc;  return cc;
5559  }  }
5560    
# Line 5901  common->accept = save_accept; Line 6124  common->accept = save_accept;
6124  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
6125  }  }
6126    
 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;  
 }  
   
6127  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)
6128  {  {
6129  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 6143  backtrack_common *backtrack; Line 6256  backtrack_common *backtrack;
6256  pcre_uchar opcode;  pcre_uchar opcode;
6257  int private_data_ptr = 0;  int private_data_ptr = 0;
6258  int offset = 0;  int offset = 0;
6259  int stacksize;  int i, stacksize;
6260  int repeat_ptr = 0, repeat_length = 0;  int repeat_ptr = 0, repeat_length = 0;
6261  int repeat_type = 0, repeat_count = 0;  int repeat_type = 0, repeat_count = 0;
6262  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
6263  pcre_uchar *matchingpath;  pcre_uchar *matchingpath;
6264    pcre_uchar *slot;
6265  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
6266  pcre_uchar ket;  pcre_uchar ket;
6267  assert_backtrack *assert;  assert_backtrack *assert;
# Line 6197  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket Line 6311  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket
6311  cc += GET(cc, 1);  cc += GET(cc, 1);
6312    
6313  has_alternatives = *cc == OP_ALT;  has_alternatives = *cc == OP_ALT;
6314  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))  if (SLJIT_UNLIKELY(opcode == OP_COND || opcode == OP_SCOND))
6315    {    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);  
     }  
   }  
6316    
6317  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))
6318    opcode = OP_SCOND;    opcode = OP_SCOND;
# Line 6447  if (opcode == OP_COND || opcode == OP_SC Line 6549  if (opcode == OP_COND || opcode == OP_SC
6549        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)));
6550      matchingpath += 1 + IMM2_SIZE;      matchingpath += 1 + IMM2_SIZE;
6551      }      }
6552    else if (*matchingpath == OP_NCREF)    else if (*matchingpath == OP_DNCREF)
6553      {      {
6554      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));  
6555    
6556      JUMPHERE(jump);      i = GET2(matchingpath, 1 + IMM2_SIZE);
6557      matchingpath += 1 + IMM2_SIZE;      slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;
6558        OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
6559        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
6560        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
6561        slot += common->name_entry_size;
6562        i--;
6563        while (i-- > 0)
6564          {
6565          OP2(SLJIT_SUB, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
6566          OP2(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, STR_PTR, 0);
6567          slot += common->name_entry_size;
6568          }
6569        OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
6570        add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), JUMP(SLJIT_C_ZERO));
6571        matchingpath += 1 + 2 * IMM2_SIZE;
6572      }      }
6573    else if (*matchingpath == OP_RREF || *matchingpath == OP_NRREF)    else if (*matchingpath == OP_RREF || *matchingpath == OP_DNRREF)
6574      {      {
6575      /* Never has other case. */      /* Never has other case. */
6576      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;
6577        SLJIT_ASSERT(!has_alternatives);
6578    
6579      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)  
6580        {        {
6581        SLJIT_ASSERT(!has_alternatives);        stacksize = GET2(matchingpath, 1);
6582          if (common->currententry == NULL)
6583            stacksize = 0;
6584          else if (stacksize == RREF_ANY)
6585            stacksize = 1;
6586          else if (common->currententry->start == 0)
6587            stacksize = stacksize == 0;
6588          else
6589            stacksize = stacksize == (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6590    
6591        if (stacksize != 0)        if (stacksize != 0)
6592          matchingpath += 1 + IMM2_SIZE;          matchingpath += 1 + IMM2_SIZE;
6593          }
6594        else
6595          {
6596          if (common->currententry == NULL || common->currententry->start == 0)
6597            stacksize = 0;
6598        else        else
6599          {          {
6600            stacksize = GET2(matchingpath, 1 + IMM2_SIZE);
6601            slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;
6602            i = (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6603            while (stacksize > 0)
6604              {
6605              if ((int)GET2(slot, 0) == i)
6606                break;
6607              slot += common->name_entry_size;
6608              stacksize--;
6609              }
6610            }
6611    
6612          if (stacksize != 0)
6613            matchingpath += 1 + 2 * IMM2_SIZE;
6614          }
6615    
6616          /* The stacksize == 0 is a common "else" case. */
6617          if (stacksize == 0)
6618            {
6619          if (*cc == OP_ALT)          if (*cc == OP_ALT)
6620            {            {
6621            matchingpath = cc + 1 + LINK_SIZE;            matchingpath = cc + 1 + LINK_SIZE;
# Line 6496  if (opcode == OP_COND || opcode == OP_SC Line 6624  if (opcode == OP_COND || opcode == OP_SC
6624          else          else
6625            matchingpath = cc;            matchingpath = cc;
6626          }          }
       }  
     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;  
       }  
6627      }      }
6628    else    else
6629      {      {
# Line 6664  if (bra == OP_BRAMINZERO) Line 6774  if (bra == OP_BRAMINZERO)
6774    }    }
6775    
6776  if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)  if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)
6777    decrease_call_count(common);    count_match(common);
6778    
6779  /* Skip the other alternatives. */  /* Skip the other alternatives. */
6780  while (*cc == OP_ALT)  while (*cc == OP_ALT)
# Line 6951  if (!zero) Line 7061  if (!zero)
7061    
7062  /* None of them matched. */  /* None of them matched. */
7063  set_jumps(emptymatch, LABEL());  set_jumps(emptymatch, LABEL());
7064  decrease_call_count(common);  count_match(common);
7065  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
7066  }  }
7067    
7068  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)
7069  {  {
7070  int class_len;  int class_len;
7071    
# Line 6991  else if (*opcode >= OP_TYPESTAR && *opco Line 7101  else if (*opcode >= OP_TYPESTAR && *opco
7101    }    }
7102  else  else
7103    {    {
7104    SLJIT_ASSERT(*opcode >= OP_CLASS || *opcode <= OP_XCLASS);    SLJIT_ASSERT(*opcode == OP_CLASS || *opcode == OP_NCLASS || *opcode == OP_XCLASS);
7105    *type = *opcode;    *type = *opcode;
7106    cc++;    cc++;
7107    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 7002  else Line 7112  else
7112      if (end != NULL)      if (end != NULL)
7113        *end = cc + class_len;        *end = cc + class_len;
7114      }      }
7115      else if (*opcode >= OP_CRPOSSTAR && *opcode <= OP_CRPOSQUERY)
7116        {
7117        *opcode -= OP_CRPOSSTAR - OP_POSSTAR;
7118        if (end != NULL)
7119          *end = cc + class_len;
7120        }
7121    else    else
7122      {      {
7123      SLJIT_ASSERT(*opcode == OP_CRRANGE || *opcode == OP_CRMINRANGE);      SLJIT_ASSERT(*opcode == OP_CRRANGE || *opcode == OP_CRMINRANGE || *opcode == OP_CRPOSRANGE);
7124      *arg1 = GET2(cc, (class_len + IMM2_SIZE));      *max = GET2(cc, (class_len + IMM2_SIZE));
7125      *arg2 = GET2(cc, class_len);      *min = GET2(cc, class_len);
7126    
7127      if (*arg2 == 0)      if (*min == 0)
7128        {        {
7129        SLJIT_ASSERT(*arg1 != 0);        SLJIT_ASSERT(*max != 0);
7130        *opcode = (*opcode == OP_CRRANGE) ? OP_UPTO : OP_MINUPTO;        *opcode = (*opcode == OP_CRRANGE) ? OP_UPTO : (*opcode == OP_CRMINRANGE ? OP_MINUPTO : OP_POSUPTO);
7131        }        }
7132      if (*arg1 == *arg2)      if (*max == *min)
7133        *opcode = OP_EXACT;        *opcode = OP_EXACT;
7134    
7135      if (end != NULL)      if (end != NULL)
# Line 7024  else Line 7140  else
7140    
7141  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)
7142    {    {
7143    *arg1 = GET2(cc, 0);    *max = GET2(cc, 0);
7144    cc += IMM2_SIZE;    cc += IMM2_SIZE;
7145    }    }
7146    
# Line 7053  DEFINE_COMPILER; Line 7169  DEFINE_COMPILER;
7169  backtrack_common *backtrack;  backtrack_common *backtrack;
7170  pcre_uchar opcode;  pcre_uchar opcode;
7171  pcre_uchar type;  pcre_uchar type;
7172  int arg1 = -1, arg2 = -1;  int max = -1, min = -1;
7173  pcre_uchar* end;  pcre_uchar* end;
7174  jump_list *nomatch = NULL;  jump_list *nomatch = NULL;
7175  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 7066  int tmp_base, tmp_offset; Line 7182  int tmp_base, tmp_offset;
7182    
7183  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
7184    
7185  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);  cc = get_iterator_parameters(common, cc, &opcode, &type, &max, &min, &end);
7186    
7187  switch(type)  switch(type)
7188    {    {
# Line 7137  switch(opcode) Line 7253  switch(opcode)
7253        {        {
7254        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);
7255        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
7256        if (opcode == OP_CRRANGE && arg2 > 0)        if (opcode == OP_CRRANGE && min > 0)
7257          CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg2, label);          CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min, label);
7258        if (opcode == OP_UPTO || (opcode == OP_CRRANGE && arg1 > 0))        if (opcode == OP_UPTO || (opcode == OP_CRRANGE && max > 0))
7259          jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, arg1);          jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, max);
7260        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);
7261        }        }
7262    
# Line 7167  switch(opcode) Line 7283  switch(opcode)
7283      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
7284      if (opcode <= OP_PLUS)      if (opcode <= OP_PLUS)
7285        JUMPTO(SLJIT_JUMP, label);        JUMPTO(SLJIT_JUMP, label);
7286      else if (opcode == OP_CRRANGE && arg1 == 0)      else if (opcode == OP_CRRANGE && max == 0)
7287        {        {
7288        OP2(SLJIT_ADD, base, offset1, base, offset1, SLJIT_IMM, 1);        OP2(SLJIT_ADD, base, offset1, base, offset1, SLJIT_IMM, 1);
7289        JUMPTO(SLJIT_JUMP, label);        JUMPTO(SLJIT_JUMP, label);
# Line 7177  switch(opcode) Line 7293  switch(opcode)
7293        OP1(SLJIT_MOV, TMP1, 0, base, offset1);        OP1(SLJIT_MOV, TMP1, 0, base, offset1);
7294        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
7295        OP1(SLJIT_MOV, base, offset1, TMP1, 0);        OP1(SLJIT_MOV, base, offset1, TMP1, 0);
7296        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg1 + 1, label);        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, max + 1, label);
7297        }        }
7298      set_jumps(nomatch, LABEL());      set_jumps(nomatch, LABEL());
7299      if (opcode == OP_CRRANGE)      if (opcode == OP_CRRANGE)
7300        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));
7301      OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);      OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
7302      }      }
7303    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
# Line 7219  switch(opcode) Line 7335  switch(opcode)
7335    break;    break;
7336    
7337    case OP_EXACT:    case OP_EXACT:
7338    OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, arg1);    OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, max);
7339    label = LABEL();    label = LABEL();
7340    compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);    compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7341    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 7232  switch(opcode) Line 7348  switch(opcode)
7348    if (opcode == OP_POSPLUS)    if (opcode == OP_POSPLUS)
7349      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7350    if (opcode == OP_POSUPTO)    if (opcode == OP_POSUPTO)
7351      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, arg1);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, max);
7352    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7353    label = LABEL();    label = LABEL();
7354    compile_char1_matchingpath(common, type, cc, &nomatch);    compile_char1_matchingpath(common, type, cc, &nomatch);
# Line 7256  switch(opcode) Line 7372  switch(opcode)
7372    OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);    OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);
7373    break;    break;
7374    
7375      case OP_CRPOSRANGE:
7376      /* Combination of OP_EXACT and OP_POSSTAR or OP_POSUPTO */
7377      OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, min);
7378      label = LABEL();
7379      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7380      OP2(SLJIT_SUB | SLJIT_SET_E, tmp_base, tmp_offset, tmp_base, tmp_offset, SLJIT_IMM, 1);
7381      JUMPTO(SLJIT_C_NOT_ZERO, label);
7382    
7383      if (max != 0)
7384        {
7385        SLJIT_ASSERT(max - min > 0);
7386        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, max - min);
7387        }
7388      OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7389      label = LABEL();
7390      compile_char1_matchingpath(common, type, cc, &nomatch);
7391      OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7392      if (max == 0)
7393        JUMPTO(SLJIT_JUMP, label);
7394      else
7395        {
7396        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, 1);
7397        JUMPTO(SLJIT_C_NOT_ZERO, label);
7398        }
7399      set_jumps(nomatch, LABEL());
7400      OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);
7401      break;
7402    
7403    default:    default:
7404    SLJIT_ASSERT_STOP();    SLJIT_ASSERT_STOP();
7405    break;    break;
7406    }    }
7407    
7408  decrease_call_count(common);  count_match(common);
7409  return end;  return end;
7410  }  }
7411    
# Line 7533  while (cc < ccend) Line 7677  while (cc < ccend)
7677    
7678      case OP_CLASS:      case OP_CLASS:
7679      case OP_NCLASS:      case OP_NCLASS:
7680      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)
7681        cc = compile_iterator_matchingpath(common, cc, parent);        cc = compile_iterator_matchingpath(common, cc, parent);
7682      else      else
7683        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 7541  while (cc < ccend) Line 7685  while (cc < ccend)
7685    
7686  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
7687      case OP_XCLASS:      case OP_XCLASS:
7688      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)
7689        cc = compile_iterator_matchingpath(common, cc, parent);        cc = compile_iterator_matchingpath(common, cc, parent);
7690      else      else
7691        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 7550  while (cc < ccend) Line 7694  while (cc < ccend)
7694    
7695      case OP_REF:      case OP_REF:
7696      case OP_REFI:      case OP_REFI:
7697      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)
7698        cc = compile_ref_iterator_matchingpath(common, cc, parent);        cc = compile_ref_iterator_matchingpath(common, cc, parent);
7699      else      else
7700        cc = compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);        {
7701          compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);
7702          cc += 1 + IMM2_SIZE;
7703          }
7704        break;
7705    
7706        case OP_DNREF:
7707        case OP_DNREFI:
7708        if (cc[1 + 2 * IMM2_SIZE] >= OP_CRSTAR && cc[1 + 2 * IMM2_SIZE] <= OP_CRPOSRANGE)
7709          cc = compile_ref_iterator_matchingpath(common, cc, parent);
7710        else
7711          {
7712          compile_dnref_search(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);
7713          compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);
7714          cc += 1 + 2 * IMM2_SIZE;
7715          }
7716      break;      break;
7717    
7718      case OP_RECURSE:      case OP_RECURSE:
# Line 7588  while (cc < ccend) Line 7747  while (cc < ccend)
7747        }        }
7748      BACKTRACK_AS(braminzero_backtrack)->matchingpath = LABEL();      BACKTRACK_AS(braminzero_backtrack)->matchingpath = LABEL();
7749      if (cc[1] > OP_ASSERTBACK_NOT)      if (cc[1] > OP_ASSERTBACK_NOT)
7750        decrease_call_count(common);        count_match(common);
7751      break;      break;
7752    
7753      case OP_ONCE:      case OP_ONCE:
# Line 7706  DEFINE_COMPILER; Line 7865  DEFINE_COMPILER;
7865  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
7866  pcre_uchar opcode;  pcre_uchar opcode;
7867  pcre_uchar type;  pcre_uchar type;
7868  int arg1 = -1, arg2 = -1;  int max = -1, min = -1;
7869  struct sljit_label *label = NULL;  struct sljit_label *label = NULL;
7870  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
7871  jump_list *jumplist = NULL;  jump_list *jumplist = NULL;
# Line 7715  int base = (private_data_ptr == 0) ? SLJ Line 7874  int base = (private_data_ptr == 0) ? SLJ
7874  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;
7875  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);
7876    
7877  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, NULL);  cc = get_iterator_parameters(common, cc, &opcode, &type, &max, &min, NULL);
7878    
7879  switch(opcode)  switch(opcode)
7880    {    {
# Line 7734  switch(opcode) Line 7893  switch(opcode)
7893    else    else
7894      {      {
7895      if (opcode == OP_UPTO)      if (opcode == OP_UPTO)
7896        arg2 = 0;        min = 0;
7897      if (opcode <= OP_PLUS)      if (opcode <= OP_PLUS)
7898        {        {
7899        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
# Line 7744  switch(opcode) Line 7903  switch(opcode)
7903        {        {
7904        OP1(SLJIT_MOV, TMP1, 0, base, offset1);        OP1(SLJIT_MOV, TMP1, 0, base, offset1);
7905        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
7906        jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, arg2 + 1);        jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, min + 1);
7907        OP2(SLJIT_SUB, base, offset1, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_SUB, base, offset1, TMP1, 0, SLJIT_IMM, 1);
7908        }        }
7909      skip_char_back(common);      skip_char_back(common);
# Line 7789  switch(opcode) Line 7948  switch(opcode)
7948    OP1(SLJIT_MOV, base, offset1, TMP1, 0);    OP1(SLJIT_MOV, base, offset1, TMP1, 0);
7949    
7950    if (opcode == OP_CRMINRANGE)    if (opcode == OP_CRMINRANGE)
7951      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg2 + 1, label);      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min + 1, label);
7952    
7953    if (opcode == OP_CRMINRANGE && arg1 == 0)    if (opcode == OP_CRMINRANGE && max == 0)
7954      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->matchingpath);      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->matchingpath);
7955    else    else
7956      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);
7957    
7958    set_jumps(jumplist, LABEL());    set_jumps(jumplist, LABEL());
7959    if (private_data_ptr == 0)    if (private_data_ptr == 0)
# Line 7829  switch(opcode) Line 7988  switch(opcode)
7988    
7989    case OP_EXACT:    case OP_EXACT:
7990    case OP_POSPLUS:    case OP_POSPLUS:
7991      case OP_CRPOSRANGE:
7992    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
7993    break;    break;
7994    
# Line 7847  static SLJIT_INLINE void compile_ref_ite Line 8007  static SLJIT_INLINE void compile_ref_ite
8007  {  {
8008  DEFINE_COMPILER;  DEFINE_COMPILER;
8009  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
8010    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
8011  pcre_uchar type;  pcre_uchar type;
8012    
8013  type = cc[1 + IMM2_SIZE];  type = cc[ref ? 1 + IMM2_SIZE : 1 + 2 * IMM2_SIZE];
8014    
8015  if ((type & 0x1) == 0)  if ((type & 0x1) == 0)
8016    {    {
8017      /* Maximize case. */
8018    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
8019    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8020    free_stack(common, 1);    free_stack(common, 1);
# Line 7862  if ((type & 0x1) == 0) Line 8025  if ((type & 0x1) == 0)
8025  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8026  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);
8027  set_jumps(current->topbacktracks, LABEL());  set_jumps(current->topbacktracks, LABEL());
8028  free_stack(common, 2);  free_stack(common, ref ? 2 : 3);
8029  }  }
8030    
8031  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 8226  if (has_alternatives) Line 8389  if (has_alternatives)
8389          return;          return;
8390        }        }
8391    
8392      /* Instructions after the current alternative is succesfully matched. */      /* Instructions after the current alternative is successfully matched. */
8393      /* There is a similar code in compile_bracket_matchingpath. */      /* There is a similar code in compile_bracket_matchingpath. */
8394      if (opcode == OP_ONCE)      if (opcode == OP_ONCE)
8395        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 8663  while (current) Line 8826  while (current)
8826    
8827      case OP_REF:      case OP_REF:
8828      case OP_REFI:      case OP_REFI:
8829        case OP_DNREF:
8830        case OP_DNREFI:
8831      compile_ref_iterator_backtrackingpath(common, current);      compile_ref_iterator_backtrackingpath(common, current);
8832      break;      break;
8833    
# Line 8957  else Line 9122  else
9122  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
9123  common->ctypes = (sljit_sw)(tables + ctypes_offset);  common->ctypes = (sljit_sw)(tables + ctypes_offset);
9124  common->digits[0] = -2;  common->digits[0] = -2;
9125  common->name_table = (sljit_sw)((pcre_uchar *)re + re->name_table_offset);  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;
9126  common->name_count = re->name_count;  common->name_count = re->name_count;
9127  common->name_entry_size = re->name_entry_size;  common->name_entry_size = re->name_entry_size;
9128  common->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;  common->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
# Line 8971  common->use_ucp = (re->options & PCRE_UC Line 9136  common->use_ucp = (re->options & PCRE_UC
9136  ccend = bracketend(rootbacktrack.cc);  ccend = bracketend(rootbacktrack.cc);
9137    
9138  /* Calculate the local space size on the stack. */  /* Calculate the local space size on the stack. */
9139  common->ovector_start = CALL_LIMIT + sizeof(sljit_sw);  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);
9140  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);
9141  if (!common->optimized_cbracket)  if (!common->optimized_cbracket)
9142    return;    return;
# Line 9103  OP1(SLJIT_MOV, TMP1, 0, SLJIT_SAVED_REG1 Line 9268  OP1(SLJIT_MOV, TMP1, 0, SLJIT_SAVED_REG1
9268  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));
9269  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));
9270  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));
9271  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));
9272  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));
9273  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));
9274  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CALL_LIMIT, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LIMIT_MATCH, TMP1, 0);
9275    
9276  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
9277    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 9130  if ((re->options & PCRE_ANCHORED) == 0) Line 9295  if ((re->options & PCRE_ANCHORED) == 0)
9295      else if ((re->flags & PCRE_STARTLINE) != 0)      else if ((re->flags & PCRE_STARTLINE) != 0)
9296        fast_forward_newline(common, (re->options & PCRE_FIRSTLINE) != 0);        fast_forward_newline(common, (re->options & PCRE_FIRSTLINE) != 0);
9297      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)
9298        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);
9299      }      }
9300    }    }
9301  else  else
# Line 9148  if (common->req_char_ptr != 0) Line 9313  if (common->req_char_ptr != 0)
9313  /* Store the current STR_PTR in OVECTOR(0). */  /* Store the current STR_PTR in OVECTOR(0). */
9314  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);
9315  /* Copy the limit of allowed recursions. */  /* Copy the limit of allowed recursions. */
9316  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);
9317  if (common->capture_last_ptr != 0)  if (common->capture_last_ptr != 0)
9318    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);
9319    
# Line 9426  else Line 9591  else
9591      }      }
9592    memset(functions, 0, sizeof(executable_functions));    memset(functions, 0, sizeof(executable_functions));
9593    functions->top_bracket = (re->top_bracket + 1) * 2;    functions->top_bracket = (re->top_bracket + 1) * 2;
9594      functions->limit_match = (re->flags & PCRE_MLSET) != 0 ? re->limit_match : 0;
9595    extra->executable_jit = functions;    extra->executable_jit = functions;
9596    extra->flags |= PCRE_EXTRA_EXECUTABLE_JIT;    extra->flags |= PCRE_EXTRA_EXECUTABLE_JIT;
9597    }    }
# Line 9480  arguments.begin = subject; Line 9646  arguments.begin = subject;
9646  arguments.end = subject + length;  arguments.end = subject + length;
9647  arguments.mark_ptr = NULL;  arguments.mark_ptr = NULL;
9648  /* JIT decreases this value less frequently than the interpreter. */  /* JIT decreases this value less frequently than the interpreter. */
9649  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);
9650    if (functions->limit_match != 0 && functions->limit_match < arguments.limit_match)
9651      arguments.limit_match = functions->limit_match;
9652  arguments.notbol = (options & PCRE_NOTBOL) != 0;  arguments.notbol = (options & PCRE_NOTBOL) != 0;
9653  arguments.noteol = (options & PCRE_NOTEOL) != 0;  arguments.noteol = (options & PCRE_NOTEOL) != 0;
9654  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
# Line 9571  arguments.begin = subject_ptr; Line 9739  arguments.begin = subject_ptr;
9739  arguments.end = subject_ptr + length;  arguments.end = subject_ptr + length;
9740  arguments.mark_ptr = NULL;  arguments.mark_ptr = NULL;
9741  /* JIT decreases this value less frequently than the interpreter. */  /* JIT decreases this value less frequently than the interpreter. */
9742  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);
9743    if (functions->limit_match != 0 && functions->limit_match < arguments.limit_match)
9744      arguments.limit_match = functions->limit_match;
9745  arguments.notbol = (options & PCRE_NOTBOL) != 0;  arguments.notbol = (options & PCRE_NOTBOL) != 0;
9746  arguments.noteol = (options & PCRE_NOTEOL) != 0;  arguments.noteol = (options & PCRE_NOTEOL) != 0;
9747  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
# Line 9690  if (extra != NULL && Line 9860  if (extra != NULL &&
9860    }    }
9861  }  }
9862    
9863    #if defined COMPILE_PCRE8
9864    PCRE_EXP_DECL void
9865    pcre_jit_free_unused_memory(void)
9866    #elif defined COMPILE_PCRE16
9867    PCRE_EXP_DECL void
9868    pcre16_jit_free_unused_memory(void)
9869    #elif defined COMPILE_PCRE32
9870    PCRE_EXP_DECL void
9871    pcre32_jit_free_unused_memory(void)
9872    #endif
9873    {
9874    sljit_free_unused_memory_exec();
9875    }
9876    
9877  #else  /* SUPPORT_JIT */  #else  /* SUPPORT_JIT */
9878    
9879  /* 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 9741  pcre32_assign_jit_stack(pcre32_extra *ex Line 9925  pcre32_assign_jit_stack(pcre32_extra *ex
9925  (void)userdata;  (void)userdata;
9926  }  }
9927    
9928    #if defined COMPILE_PCRE8
9929    PCRE_EXP_DECL void
9930    pcre_jit_free_unused_memory(void)
9931    #elif defined COMPILE_PCRE16
9932    PCRE_EXP_DECL void
9933    pcre16_jit_free_unused_memory(void)
9934    #elif defined COMPILE_PCRE32
9935    PCRE_EXP_DECL void
9936    pcre32_jit_free_unused_memory(void)
9937    #endif
9938    {
9939    }
9940    
9941  #endif  #endif
9942    
9943  /* End of pcre_jit_compile.c */  /* End of pcre_jit_compile.c */

Legend:
Removed from v.1310  
changed lines
  Added in v.1415

  ViewVC Help
Powered by ViewVC 1.1.5