/[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 1414 by zherczeg, Sun Dec 22 16:27:35 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 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;
 int i, cbra_index;  
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 771  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 892  pcre_uchar *next; Line 890  pcre_uchar *next;
890  pcre_uchar *next_end;  pcre_uchar *next_end;
891  pcre_uchar *max_end;  pcre_uchar *max_end;
892  pcre_uchar type;  pcre_uchar type;
893  sljit_uw length = end - begin;  sljit_sw length = end - begin;
894  int min, max, i;  int min, max, i;
895    
896  /* Detect fixed iterations first. */  /* Detect fixed iterations first. */
# Line 2021  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 2372  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 3208  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 3241  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 3250  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 3526  switch(ranges[0]) Line 3519  switch(ranges[0])
3519    case 2:    case 2:
3520    if (readch)    if (readch)
3521      read_char(common);      read_char(common);
3522    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);    if (ranges[2] + 1 != ranges[3])
3523    add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));      {
3524        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3525        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3526        }
3527      else
3528        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3529      return TRUE;
3530    
3531      case 3:
3532      if (readch)
3533        read_char(common);
3534      if (ranges[1] != 0)
3535        {
3536        add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3537        if (ranges[2] + 1 != ranges[3])
3538          {
3539          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3540          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3541          }
3542        else
3543          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3544        }
3545      else
3546        {
3547        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2]));
3548        if (ranges[3] + 1 != ranges[4])
3549          {
3550          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[3]);
3551          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[3]));
3552          }
3553        else
3554          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3]));
3555        }
3556    return TRUE;    return TRUE;
3557    
3558    case 4:    case 4:
# Line 3594  if (bit != 0) Line 3619  if (bit != 0)
3619  ranges[0] = length;  ranges[0] = length;
3620  }  }
3621    
3622  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)
3623  {  {
3624  int ranges[2 + MAX_RANGE_SIZE];  int ranges[2 + MAX_RANGE_SIZE];
3625  pcre_uint8 bit, cbit, all;  pcre_uint8 bit, cbit, all;
3626  int i, byte, length = 0;  int i, byte, length = 0;
3627    
3628  bit = bits[0] & 0x1;  bit = bits[0] & 0x1;
3629  ranges[1] = bit;  ranges[1] = !invert ? bit : (bit ^ 0x1);
3630  /* Can be 0 or 255. */  /* All bits will be zero or one (since bit is zero or one). */
3631  all = -bit;  all = -bit;
3632    
3633  for (i = 0; i < 256; )  for (i = 0; i < 256; )
# Line 4023  static void compile_xclass_matchingpath( Line 4048  static void compile_xclass_matchingpath(
4048  {  {
4049  DEFINE_COMPILER;  DEFINE_COMPILER;
4050  jump_list *found = NULL;  jump_list *found = NULL;
4051  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;
4052  pcre_int32 c, charoffset;  pcre_int32 c, charoffset;
 const pcre_uint32 *other_cases;  
4053  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4054  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4055  int compares, invertcmp, numberofcmps;  int compares, invertcmp, numberofcmps;
4056    
4057  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4058  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4059  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4060  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4061    const pcre_uint32 *other_cases;
4062  pcre_int32 typeoffset;  pcre_int32 typeoffset;
4063  #endif  #endif
4064    
# Line 4041  pcre_int32 typeoffset; Line 4067  pcre_int32 typeoffset;
4067  detect_partial_match(common, backtracks);  detect_partial_match(common, backtracks);
4068  read_char(common);  read_char(common);
4069    
4070  if ((*cc++ & XCL_MAP) != 0)  cc++;
4071    if ((cc[-1] & XCL_HASPROP) == 0)
4072    {    {
4073    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    if ((cc[-1] & XCL_MAP) != 0)
4074  #ifndef COMPILE_PCRE8      {
4075    jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4076  #elif defined SUPPORT_UTF  #ifdef SUPPORT_UCP
4077    if (common->utf)      charsaved = TRUE;
     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
4078  #endif  #endif
4079        if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, FALSE, backtracks))
4080          {
4081          jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4082    
4083    if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, list))        OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4084          OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4085          OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4086          OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4087          OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4088          add_jump(compiler, &found, JUMP(SLJIT_C_NOT_ZERO));
4089          add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4090    
4091          JUMPHERE(jump);
4092          }
4093        else
4094          add_jump(compiler, &found, CMP(SLJIT_C_LESS_EQUAL, TMP3, 0, SLJIT_IMM, 0xff));
4095    
4096        OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
4097        cc += 32 / sizeof(pcre_uchar);
4098        }
4099      else
4100        add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0xff));
4101      }
4102    else if ((cc[-1] & XCL_MAP) != 0)
4103      {
4104      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4105    #ifdef SUPPORT_UCP
4106      charsaved = TRUE;
4107    #endif
4108      if (!check_class_ranges(common, (const pcre_uint8 *)cc, FALSE, TRUE, list))
4109      {      {
4110    #ifdef COMPILE_PCRE8
4111        SLJIT_ASSERT(common->utf);
4112    #endif
4113        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4114    
4115      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4116      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4117      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4118      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4119      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);
4120      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
     }  
4121    
 #ifndef COMPILE_PCRE8  
   JUMPHERE(jump);  
 #elif defined SUPPORT_UTF  
   if (common->utf)  
4122      JUMPHERE(jump);      JUMPHERE(jump);
4123  #endif      }
4124    
4125    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
 #ifdef SUPPORT_UCP  
   charsaved = TRUE;  
 #endif  
4126    cc += 32 / sizeof(pcre_uchar);    cc += 32 / sizeof(pcre_uchar);
4127    }    }
4128    
# Line 4128  while (*cc != XCL_END) Line 4180  while (*cc != XCL_END)
4180        case PT_SPACE:        case PT_SPACE:
4181        case PT_PXSPACE:        case PT_PXSPACE:
4182        case PT_WORD:        case PT_WORD:
4183          case PT_PXGRAPH:
4184          case PT_PXPRINT:
4185          case PT_PXPUNCT:
4186        needstype = TRUE;        needstype = TRUE;
4187        needschar = TRUE;        needschar = TRUE;
4188        break;        break;
# Line 4315  while (*cc != XCL_END) Line 4370  while (*cc != XCL_END)
4370    
4371        case PT_SPACE:        case PT_SPACE:
4372        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);  
         }  
4373        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4374        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);
4375        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);
4376        if (*cc == PT_SPACE)  
4377          JUMPHERE(jump);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x9);
4378          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4379    
4380          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x9);
4381          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4382    
4383        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4384        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 4470  while (*cc != XCL_END)
4470        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);
4471        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4472        break;        break;
4473    
4474          case PT_PXGRAPH:
4475          /* C and Z groups are the farthest two groups. */
4476          SET_TYPE_OFFSET(ucp_Ll);
4477          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4478          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4479    
4480          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4481    
4482          /* In case of ucp_Cf, we overwrite the result. */
4483          SET_CHAR_OFFSET(0x2066);
4484          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4485          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4486    
4487          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4488          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4489    
4490          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x2066);
4491          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4492    
4493          JUMPHERE(jump);
4494          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4495          break;
4496    
4497          case PT_PXPRINT:
4498          /* C and Z groups are the farthest two groups. */
4499          SET_TYPE_OFFSET(ucp_Ll);
4500          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4501          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4502    
4503          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Ll);
4504          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_NOT_EQUAL);
4505    
4506          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4507    
4508          /* In case of ucp_Cf, we overwrite the result. */
4509          SET_CHAR_OFFSET(0x2066);
4510          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4511          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4512    
4513          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4514          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4515    
4516          JUMPHERE(jump);
4517          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4518          break;
4519    
4520          case PT_PXPUNCT:
4521          SET_TYPE_OFFSET(ucp_Sc);
4522          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Sc);
4523          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4524    
4525          SET_CHAR_OFFSET(0);
4526          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xff);
4527          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4528    
4529          SET_TYPE_OFFSET(ucp_Pc);
4530          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ps - ucp_Pc);
4531          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4532          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4533          break;
4534        }        }
4535      cc += 2;      cc += 2;
4536      }      }
# Line 4562  switch(type) Line 4677  switch(type)
4677  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4678    case OP_NOTPROP:    case OP_NOTPROP:
4679    case OP_PROP:    case OP_PROP:
4680    propdata[0] = 0;    propdata[0] = XCL_HASPROP;
4681    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;
4682    propdata[2] = cc[0];    propdata[2] = cc[0];
4683    propdata[3] = cc[1];    propdata[3] = cc[1];
# Line 4921  switch(type) Line 5036  switch(type)
5036    case OP_NCLASS:    case OP_NCLASS:
5037    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5038    read_char(common);    read_char(common);
5039    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))
5040      return cc + 32 / sizeof(pcre_uchar);      return cc + 32 / sizeof(pcre_uchar);
5041    
5042  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
# Line 5054  if (context.length > 0) Line 5169  if (context.length > 0)
5169  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);
5170  }  }
5171    
 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));  
 }  
   
5172  /* Forward definitions. */  /* Forward definitions. */
5173  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);
5174  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 5201  static void compile_backtrackingpath(com
5201    
5202  #define BACKTRACK_AS(type) ((type *)backtrack)  #define BACKTRACK_AS(type) ((type *)backtrack)
5203    
5204  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)
5205  {  {
5206    /* The OVECTOR offset goes to TMP2. */
5207  DEFINE_COMPILER;  DEFINE_COMPILER;
5208  int offset = GET2(cc, 1) << 1;  int count = GET2(cc, 1 + IMM2_SIZE);
5209    pcre_uchar *slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
5210    unsigned int offset;
5211    jump_list *found = NULL;
5212    
5213    SLJIT_ASSERT(*cc == OP_DNREF || *cc == OP_DNREFI);
5214    
5215    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
5216    
5217    count--;
5218    while (count-- > 0)
5219      {
5220      offset = GET2(slot, 0) << 1;
5221      GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5222      add_jump(compiler, &found, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5223      slot += common->name_entry_size;
5224      }
5225    
5226    offset = GET2(slot, 0) << 1;
5227    GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5228    if (backtracks != NULL && !common->jscript_compat)
5229      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5230    
5231    set_jumps(found, LABEL());
5232    }
5233    
5234    static void compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)
5235    {
5236    DEFINE_COMPILER;
5237    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5238    int offset = 0;
5239  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
5240  struct sljit_jump *partial;  struct sljit_jump *partial;
5241  struct sljit_jump *nopartial;  struct sljit_jump *nopartial;
5242    
5243  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  if (ref)
5244  /* OVECTOR(1) contains the "string begin - 1" constant. */    {
5245  if (withchecks && !common->jscript_compat)    offset = GET2(cc, 1) << 1;
5246    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));
5247      /* OVECTOR(1) contains the "string begin - 1" constant. */
5248      if (withchecks && !common->jscript_compat)
5249        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5250      }
5251    else
5252      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5253    
5254  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5255  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5256    {    {
5257    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);
5258    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));    if (ref)
5259        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5260      else
5261        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5262    
5263    if (withchecks)    if (withchecks)
5264      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5265    
# Line 5150  if (common->utf && *cc == OP_REFI) Line 5284  if (common->utf && *cc == OP_REFI)
5284  else  else
5285  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
5286    {    {
5287    OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);    if (ref)
5288        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
5289      else
5290        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
5291    
5292    if (withchecks)    if (withchecks)
5293      jump = JUMP(SLJIT_C_ZERO);      jump = JUMP(SLJIT_C_ZERO);
5294    
# Line 5187  if (jump != NULL) Line 5325  if (jump != NULL)
5325    else    else
5326      JUMPHERE(jump);      JUMPHERE(jump);
5327    }    }
 return cc + 1 + IMM2_SIZE;  
5328  }  }
5329    
5330  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)
5331  {  {
5332  DEFINE_COMPILER;  DEFINE_COMPILER;
5333    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5334  backtrack_common *backtrack;  backtrack_common *backtrack;
5335  pcre_uchar type;  pcre_uchar type;
5336    int offset = 0;
5337  struct sljit_label *label;  struct sljit_label *label;
5338  struct sljit_jump *zerolength;  struct sljit_jump *zerolength;
5339  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 5204  BOOL minimize; Line 5343  BOOL minimize;
5343    
5344  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
5345    
5346    if (ref)
5347      offset = GET2(cc, 1) << 1;
5348    else
5349      cc += IMM2_SIZE;
5350  type = cc[1 + IMM2_SIZE];  type = cc[1 + IMM2_SIZE];
5351    
5352    SLJIT_COMPILE_ASSERT((OP_CRSTAR & 0x1) == 0, crstar_opcode_must_be_even);
5353  minimize = (type & 0x1) != 0;  minimize = (type & 0x1) != 0;
5354  switch(type)  switch(type)
5355    {    {
# Line 5242  if (!minimize) Line 5387  if (!minimize)
5387    if (min == 0)    if (min == 0)
5388      {      {
5389      allocate_stack(common, 2);      allocate_stack(common, 2);
5390        if (ref)
5391          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5392      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5393      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5394      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5395      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));
5396      zerolength = compile_ref_checks(common, ccbegin, NULL);      /* Handles both invalid and empty cases. Since the minimum repeat,
5397        is zero the invalid case is basically the same as an empty case. */
5398        if (ref)
5399          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5400        else
5401          {
5402          compile_dnref_search(common, ccbegin, NULL);
5403          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5404          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5405          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5406          }
5407      /* Restore if not zero length. */      /* Restore if not zero length. */
5408      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));
5409      }      }
5410    else    else
5411      {      {
5412      allocate_stack(common, 1);      allocate_stack(common, 1);
5413        if (ref)
5414          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5415      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5416      zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);      if (ref)
5417          {
5418          add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5419          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5420          }
5421        else
5422          {
5423          compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5424          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5425          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5426          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5427          }
5428      }      }
5429    
5430    if (min > 1 || max > 1)    if (min > 1 || max > 1)
5431      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
5432    
5433    label = LABEL();    label = LABEL();
5434      if (!ref)
5435        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
5436    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);
5437    
5438    if (min > 1 || max > 1)    if (min > 1 || max > 1)
# Line 5291  if (!minimize) Line 5463  if (!minimize)
5463    JUMPHERE(zerolength);    JUMPHERE(zerolength);
5464    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5465    
5466    decrease_call_count(common);    count_match(common);
5467    return cc;    return cc;
5468    }    }
5469    
5470  allocate_stack(common, 2);  allocate_stack(common, ref ? 2 : 3);
5471    if (ref)
5472      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5473  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5474  if (type != OP_CRMINSTAR)  if (type != OP_CRMINSTAR)
5475    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5476    
5477  if (min == 0)  if (min == 0)
5478    {    {
5479    zerolength = compile_ref_checks(common, ccbegin, NULL);    /* Handles both invalid and empty cases. Since the minimum repeat,
5480      is zero the invalid case is basically the same as an empty case. */
5481      if (ref)
5482        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5483      else
5484        {
5485        compile_dnref_search(common, ccbegin, NULL);
5486        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5487        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5488        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5489        }
5490      /* Length is non-zero, we can match real repeats. */
5491    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5492    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
5493    }    }
5494  else  else
5495    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);    {
5496      if (ref)
5497        {
5498        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5499        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5500        }
5501      else
5502        {
5503        compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5504        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5505        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5506        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5507        }
5508      }
5509    
5510  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5511  if (max > 0)  if (max > 0)
5512    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));
5513    
5514    if (!ref)
5515      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
5516  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);
5517  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5518    
# Line 5330  if (jump != NULL) Line 5530  if (jump != NULL)
5530    JUMPHERE(jump);    JUMPHERE(jump);
5531  JUMPHERE(zerolength);  JUMPHERE(zerolength);
5532    
5533  decrease_call_count(common);  count_match(common);
5534  return cc;  return cc;
5535  }  }
5536    
# Line 5900  common->accept = save_accept; Line 6100  common->accept = save_accept;
6100  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
6101  }  }
6102    
 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;  
 }  
   
6103  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)
6104  {  {
6105  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 6142  backtrack_common *backtrack; Line 6232  backtrack_common *backtrack;
6232  pcre_uchar opcode;  pcre_uchar opcode;
6233  int private_data_ptr = 0;  int private_data_ptr = 0;
6234  int offset = 0;  int offset = 0;
6235  int stacksize;  int i, stacksize;
6236  int repeat_ptr = 0, repeat_length = 0;  int repeat_ptr = 0, repeat_length = 0;
6237  int repeat_type = 0, repeat_count = 0;  int repeat_type = 0, repeat_count = 0;
6238  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
6239  pcre_uchar *matchingpath;  pcre_uchar *matchingpath;
6240    pcre_uchar *slot;
6241  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
6242  pcre_uchar ket;  pcre_uchar ket;
6243  assert_backtrack *assert;  assert_backtrack *assert;
# Line 6196  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket Line 6287  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket
6287  cc += GET(cc, 1);  cc += GET(cc, 1);
6288    
6289  has_alternatives = *cc == OP_ALT;  has_alternatives = *cc == OP_ALT;
6290  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))  if (SLJIT_UNLIKELY(opcode == OP_COND || opcode == OP_SCOND))
6291    {    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);  
     }  
   }  
6292    
6293  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))
6294    opcode = OP_SCOND;    opcode = OP_SCOND;
# Line 6446  if (opcode == OP_COND || opcode == OP_SC Line 6525  if (opcode == OP_COND || opcode == OP_SC
6525        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)));
6526      matchingpath += 1 + IMM2_SIZE;      matchingpath += 1 + IMM2_SIZE;
6527      }      }
6528    else if (*matchingpath == OP_NCREF)    else if (*matchingpath == OP_DNCREF)
6529      {      {
6530      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));  
6531    
6532      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);      i = GET2(matchingpath, 1 + IMM2_SIZE);
6533      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);      slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;
6534      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);      OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
6535      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (stacksize << 8) | (common->ovector_start / sizeof(sljit_sw)));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
6536      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, 0);      OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
6537      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);      slot += common->name_entry_size;
6538      sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchovector));      i--;
6539      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);      while (i-- > 0)
6540      add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0));        {
6541          OP2(SLJIT_SUB, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
6542      JUMPHERE(jump);        OP2(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, STR_PTR, 0);
6543      matchingpath += 1 + IMM2_SIZE;        slot += common->name_entry_size;
6544          }
6545        OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
6546        add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), JUMP(SLJIT_C_ZERO));
6547        matchingpath += 1 + 2 * IMM2_SIZE;
6548      }      }
6549    else if (*matchingpath == OP_RREF || *matchingpath == OP_NRREF)    else if (*matchingpath == OP_RREF || *matchingpath == OP_DNRREF)
6550      {      {
6551      /* Never has other case. */      /* Never has other case. */
6552      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;
6553        SLJIT_ASSERT(!has_alternatives);
6554    
6555      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)  
6556        {        {
6557        SLJIT_ASSERT(!has_alternatives);        stacksize = GET2(matchingpath, 1);
6558          if (common->currententry == NULL)
6559            stacksize = 0;
6560          else if (stacksize == RREF_ANY)
6561            stacksize = 1;
6562          else if (common->currententry->start == 0)
6563            stacksize = stacksize == 0;
6564          else
6565            stacksize = stacksize == (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6566    
6567        if (stacksize != 0)        if (stacksize != 0)
6568          matchingpath += 1 + IMM2_SIZE;          matchingpath += 1 + IMM2_SIZE;
6569          }
6570        else
6571          {
6572          if (common->currententry == NULL || common->currententry->start == 0)
6573            stacksize = 0;
6574        else        else
6575          {          {
6576            stacksize = GET2(matchingpath, 1 + IMM2_SIZE);
6577            slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;
6578            i = (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6579            while (stacksize > 0)
6580              {
6581              if ((int)GET2(slot, 0) == i)
6582                break;
6583              slot += common->name_entry_size;
6584              stacksize--;
6585              }
6586            }
6587    
6588          if (stacksize != 0)
6589            matchingpath += 1 + 2 * IMM2_SIZE;
6590          }
6591    
6592          /* The stacksize == 0 is a common "else" case. */
6593          if (stacksize == 0)
6594            {
6595          if (*cc == OP_ALT)          if (*cc == OP_ALT)
6596            {            {
6597            matchingpath = cc + 1 + LINK_SIZE;            matchingpath = cc + 1 + LINK_SIZE;
# Line 6495  if (opcode == OP_COND || opcode == OP_SC Line 6600  if (opcode == OP_COND || opcode == OP_SC
6600          else          else
6601            matchingpath = cc;            matchingpath = cc;
6602          }          }
       }  
     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;  
       }  
6603      }      }
6604    else    else
6605      {      {
# Line 6663  if (bra == OP_BRAMINZERO) Line 6750  if (bra == OP_BRAMINZERO)
6750    }    }
6751    
6752  if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)  if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)
6753    decrease_call_count(common);    count_match(common);
6754    
6755  /* Skip the other alternatives. */  /* Skip the other alternatives. */
6756  while (*cc == OP_ALT)  while (*cc == OP_ALT)
# Line 6950  if (!zero) Line 7037  if (!zero)
7037    
7038  /* None of them matched. */  /* None of them matched. */
7039  set_jumps(emptymatch, LABEL());  set_jumps(emptymatch, LABEL());
7040  decrease_call_count(common);  count_match(common);
7041  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
7042  }  }
7043    
7044  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)
7045  {  {
7046  int class_len;  int class_len;
7047    
# Line 6990  else if (*opcode >= OP_TYPESTAR && *opco Line 7077  else if (*opcode >= OP_TYPESTAR && *opco
7077    }    }
7078  else  else
7079    {    {
7080    SLJIT_ASSERT(*opcode >= OP_CLASS || *opcode <= OP_XCLASS);    SLJIT_ASSERT(*opcode == OP_CLASS || *opcode == OP_NCLASS || *opcode == OP_XCLASS);
7081    *type = *opcode;    *type = *opcode;
7082    cc++;    cc++;
7083    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 7088  else
7088      if (end != NULL)      if (end != NULL)
7089        *end = cc + class_len;        *end = cc + class_len;
7090      }      }
7091      else if (*opcode >= OP_CRPOSSTAR && *opcode <= OP_CRPOSQUERY)
7092        {
7093        *opcode -= OP_CRPOSSTAR - OP_POSSTAR;
7094        if (end != NULL)
7095          *end = cc + class_len;
7096        }
7097    else    else
7098      {      {
7099      SLJIT_ASSERT(*opcode == OP_CRRANGE || *opcode == OP_CRMINRANGE);      SLJIT_ASSERT(*opcode == OP_CRRANGE || *opcode == OP_CRMINRANGE || *opcode == OP_CRPOSRANGE);
7100      *arg1 = GET2(cc, (class_len + IMM2_SIZE));      *max = GET2(cc, (class_len + IMM2_SIZE));
7101      *arg2 = GET2(cc, class_len);      *min = GET2(cc, class_len);
7102    
7103      if (*arg2 == 0)      if (*min == 0)
7104        {        {
7105        SLJIT_ASSERT(*arg1 != 0);        SLJIT_ASSERT(*max != 0);
7106        *opcode = (*opcode == OP_CRRANGE) ? OP_UPTO : OP_MINUPTO;        *opcode = (*opcode == OP_CRRANGE) ? OP_UPTO : (*opcode == OP_CRMINRANGE ? OP_MINUPTO : OP_POSUPTO);
7107        }        }
7108      if (*arg1 == *arg2)      if (*max == *min)
7109        *opcode = OP_EXACT;        *opcode = OP_EXACT;
7110    
7111      if (end != NULL)      if (end != NULL)
# Line 7023  else Line 7116  else
7116    
7117  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)
7118    {    {
7119    *arg1 = GET2(cc, 0);    *max = GET2(cc, 0);
7120    cc += IMM2_SIZE;    cc += IMM2_SIZE;
7121    }    }
7122    
# Line 7052  DEFINE_COMPILER; Line 7145  DEFINE_COMPILER;
7145  backtrack_common *backtrack;  backtrack_common *backtrack;
7146  pcre_uchar opcode;  pcre_uchar opcode;
7147  pcre_uchar type;  pcre_uchar type;
7148  int arg1 = -1, arg2 = -1;  int max = -1, min = -1;
7149  pcre_uchar* end;  pcre_uchar* end;
7150  jump_list *nomatch = NULL;  jump_list *nomatch = NULL;
7151  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 7065  int tmp_base, tmp_offset; Line 7158  int tmp_base, tmp_offset;
7158    
7159  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
7160    
7161  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);  cc = get_iterator_parameters(common, cc, &opcode, &type, &max, &min, &end);
7162    
7163  switch(type)  switch(type)
7164    {    {
# Line 7136  switch(opcode) Line 7229  switch(opcode)
7229        {        {
7230        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);
7231        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
7232        if (opcode == OP_CRRANGE && arg2 > 0)        if (opcode == OP_CRRANGE && min > 0)
7233          CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg2, label);          CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min, label);
7234        if (opcode == OP_UPTO || (opcode == OP_CRRANGE && arg1 > 0))        if (opcode == OP_UPTO || (opcode == OP_CRRANGE && max > 0))
7235          jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, arg1);          jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, max);
7236        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);
7237        }        }
7238    
# Line 7166  switch(opcode) Line 7259  switch(opcode)
7259      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
7260      if (opcode <= OP_PLUS)      if (opcode <= OP_PLUS)
7261        JUMPTO(SLJIT_JUMP, label);        JUMPTO(SLJIT_JUMP, label);
7262      else if (opcode == OP_CRRANGE && arg1 == 0)      else if (opcode == OP_CRRANGE && max == 0)
7263        {        {
7264        OP2(SLJIT_ADD, base, offset1, base, offset1, SLJIT_IMM, 1);        OP2(SLJIT_ADD, base, offset1, base, offset1, SLJIT_IMM, 1);
7265        JUMPTO(SLJIT_JUMP, label);        JUMPTO(SLJIT_JUMP, label);
# Line 7176  switch(opcode) Line 7269  switch(opcode)
7269        OP1(SLJIT_MOV, TMP1, 0, base, offset1);        OP1(SLJIT_MOV, TMP1, 0, base, offset1);
7270        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
7271        OP1(SLJIT_MOV, base, offset1, TMP1, 0);        OP1(SLJIT_MOV, base, offset1, TMP1, 0);
7272        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg1 + 1, label);        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, max + 1, label);
7273        }        }
7274      set_jumps(nomatch, LABEL());      set_jumps(nomatch, LABEL());
7275      if (opcode == OP_CRRANGE)      if (opcode == OP_CRRANGE)
7276        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));
7277      OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);      OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
7278      }      }
7279    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
# Line 7218  switch(opcode) Line 7311  switch(opcode)
7311    break;    break;
7312    
7313    case OP_EXACT:    case OP_EXACT:
7314    OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, arg1);    OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, max);
7315    label = LABEL();    label = LABEL();
7316    compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);    compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7317    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 7324  switch(opcode)
7324    if (opcode == OP_POSPLUS)    if (opcode == OP_POSPLUS)
7325      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7326    if (opcode == OP_POSUPTO)    if (opcode == OP_POSUPTO)
7327      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, arg1);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, max);
7328    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7329    label = LABEL();    label = LABEL();
7330    compile_char1_matchingpath(common, type, cc, &nomatch);    compile_char1_matchingpath(common, type, cc, &nomatch);
# Line 7255  switch(opcode) Line 7348  switch(opcode)
7348    OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);    OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);
7349    break;    break;
7350    
7351      case OP_CRPOSRANGE:
7352      /* Combination of OP_EXACT and OP_POSSTAR or OP_POSUPTO */
7353      OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, min);
7354      label = LABEL();
7355      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7356      OP2(SLJIT_SUB | SLJIT_SET_E, tmp_base, tmp_offset, tmp_base, tmp_offset, SLJIT_IMM, 1);
7357      JUMPTO(SLJIT_C_NOT_ZERO, label);
7358    
7359      if (max != 0)
7360        {
7361        SLJIT_ASSERT(max - min > 0);
7362        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, max - min);
7363        }
7364      OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7365      label = LABEL();
7366      compile_char1_matchingpath(common, type, cc, &nomatch);
7367      OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7368      if (max == 0)
7369        JUMPTO(SLJIT_JUMP, label);
7370      else
7371        {
7372        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, 1);
7373        JUMPTO(SLJIT_C_NOT_ZERO, label);
7374        }
7375      set_jumps(nomatch, LABEL());
7376      OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);
7377      break;
7378    
7379    default:    default:
7380    SLJIT_ASSERT_STOP();    SLJIT_ASSERT_STOP();
7381    break;    break;
7382    }    }
7383    
7384  decrease_call_count(common);  count_match(common);
7385  return end;  return end;
7386  }  }
7387    
# Line 7532  while (cc < ccend) Line 7653  while (cc < ccend)
7653    
7654      case OP_CLASS:      case OP_CLASS:
7655      case OP_NCLASS:      case OP_NCLASS:
7656      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)
7657        cc = compile_iterator_matchingpath(common, cc, parent);        cc = compile_iterator_matchingpath(common, cc, parent);
7658      else      else
7659        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 7661  while (cc < ccend)
7661    
7662  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
7663      case OP_XCLASS:      case OP_XCLASS:
7664      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)
7665        cc = compile_iterator_matchingpath(common, cc, parent);        cc = compile_iterator_matchingpath(common, cc, parent);
7666      else      else
7667        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 7670  while (cc < ccend)
7670    
7671      case OP_REF:      case OP_REF:
7672      case OP_REFI:      case OP_REFI:
7673      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)
7674        cc = compile_ref_iterator_matchingpath(common, cc, parent);        cc = compile_ref_iterator_matchingpath(common, cc, parent);
7675      else      else
7676        cc = compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);        {
7677          compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);
7678          cc += 1 + IMM2_SIZE;
7679          }
7680        break;
7681    
7682        case OP_DNREF:
7683        case OP_DNREFI:
7684        if (cc[1 + 2 * IMM2_SIZE] >= OP_CRSTAR && cc[1 + 2 * IMM2_SIZE] <= OP_CRPOSRANGE)
7685          cc = compile_ref_iterator_matchingpath(common, cc, parent);
7686        else
7687          {
7688          compile_dnref_search(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);
7689          compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);
7690          cc += 1 + 2 * IMM2_SIZE;
7691          }
7692      break;      break;
7693    
7694      case OP_RECURSE:      case OP_RECURSE:
# Line 7587  while (cc < ccend) Line 7723  while (cc < ccend)
7723        }        }
7724      BACKTRACK_AS(braminzero_backtrack)->matchingpath = LABEL();      BACKTRACK_AS(braminzero_backtrack)->matchingpath = LABEL();
7725      if (cc[1] > OP_ASSERTBACK_NOT)      if (cc[1] > OP_ASSERTBACK_NOT)
7726        decrease_call_count(common);        count_match(common);
7727      break;      break;
7728    
7729      case OP_ONCE:      case OP_ONCE:
# Line 7705  DEFINE_COMPILER; Line 7841  DEFINE_COMPILER;
7841  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
7842  pcre_uchar opcode;  pcre_uchar opcode;
7843  pcre_uchar type;  pcre_uchar type;
7844  int arg1 = -1, arg2 = -1;  int max = -1, min = -1;
7845  struct sljit_label *label = NULL;  struct sljit_label *label = NULL;
7846  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
7847  jump_list *jumplist = NULL;  jump_list *jumplist = NULL;
# Line 7714  int base = (private_data_ptr == 0) ? SLJ Line 7850  int base = (private_data_ptr == 0) ? SLJ
7850  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;
7851  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);
7852    
7853  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, NULL);  cc = get_iterator_parameters(common, cc, &opcode, &type, &max, &min, NULL);
7854    
7855  switch(opcode)  switch(opcode)
7856    {    {
# Line 7733  switch(opcode) Line 7869  switch(opcode)
7869    else    else
7870      {      {
7871      if (opcode == OP_UPTO)      if (opcode == OP_UPTO)
7872        arg2 = 0;        min = 0;
7873      if (opcode <= OP_PLUS)      if (opcode <= OP_PLUS)
7874        {        {
7875        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
# Line 7743  switch(opcode) Line 7879  switch(opcode)
7879        {        {
7880        OP1(SLJIT_MOV, TMP1, 0, base, offset1);        OP1(SLJIT_MOV, TMP1, 0, base, offset1);
7881        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
7882        jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, arg2 + 1);        jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, min + 1);
7883        OP2(SLJIT_SUB, base, offset1, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_SUB, base, offset1, TMP1, 0, SLJIT_IMM, 1);
7884        }        }
7885      skip_char_back(common);      skip_char_back(common);
# Line 7788  switch(opcode) Line 7924  switch(opcode)
7924    OP1(SLJIT_MOV, base, offset1, TMP1, 0);    OP1(SLJIT_MOV, base, offset1, TMP1, 0);
7925    
7926    if (opcode == OP_CRMINRANGE)    if (opcode == OP_CRMINRANGE)
7927      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg2 + 1, label);      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min + 1, label);
7928    
7929    if (opcode == OP_CRMINRANGE && arg1 == 0)    if (opcode == OP_CRMINRANGE && max == 0)
7930      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->matchingpath);      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->matchingpath);
7931    else    else
7932      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);
7933    
7934    set_jumps(jumplist, LABEL());    set_jumps(jumplist, LABEL());
7935    if (private_data_ptr == 0)    if (private_data_ptr == 0)
# Line 7828  switch(opcode) Line 7964  switch(opcode)
7964    
7965    case OP_EXACT:    case OP_EXACT:
7966    case OP_POSPLUS:    case OP_POSPLUS:
7967      case OP_CRPOSRANGE:
7968    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
7969    break;    break;
7970    
# Line 7846  static SLJIT_INLINE void compile_ref_ite Line 7983  static SLJIT_INLINE void compile_ref_ite
7983  {  {
7984  DEFINE_COMPILER;  DEFINE_COMPILER;
7985  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
7986    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
7987  pcre_uchar type;  pcre_uchar type;
7988    
7989  type = cc[1 + IMM2_SIZE];  type = cc[ref ? 1 + IMM2_SIZE : 1 + 2 * IMM2_SIZE];
7990    
7991  if ((type & 0x1) == 0)  if ((type & 0x1) == 0)
7992    {    {
7993      /* Maximize case. */
7994    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
7995    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7996    free_stack(common, 1);    free_stack(common, 1);
# Line 7861  if ((type & 0x1) == 0) Line 8001  if ((type & 0x1) == 0)
8001  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8002  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);
8003  set_jumps(current->topbacktracks, LABEL());  set_jumps(current->topbacktracks, LABEL());
8004  free_stack(common, 2);  free_stack(common, ref ? 2 : 3);
8005  }  }
8006    
8007  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 8365  if (has_alternatives)
8365          return;          return;
8366        }        }
8367    
8368      /* Instructions after the current alternative is succesfully matched. */      /* Instructions after the current alternative is successfully matched. */
8369      /* There is a similar code in compile_bracket_matchingpath. */      /* There is a similar code in compile_bracket_matchingpath. */
8370      if (opcode == OP_ONCE)      if (opcode == OP_ONCE)
8371        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 8802  while (current)
8802    
8803      case OP_REF:      case OP_REF:
8804      case OP_REFI:      case OP_REFI:
8805        case OP_DNREF:
8806        case OP_DNREFI:
8807      compile_ref_iterator_backtrackingpath(common, current);      compile_ref_iterator_backtrackingpath(common, current);
8808      break;      break;
8809    
# Line 8956  else Line 9098  else
9098  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
9099  common->ctypes = (sljit_sw)(tables + ctypes_offset);  common->ctypes = (sljit_sw)(tables + ctypes_offset);
9100  common->digits[0] = -2;  common->digits[0] = -2;
9101  common->name_table = (sljit_sw)((pcre_uchar *)re + re->name_table_offset);  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;
9102  common->name_count = re->name_count;  common->name_count = re->name_count;
9103  common->name_entry_size = re->name_entry_size;  common->name_entry_size = re->name_entry_size;
9104  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 9112  common->use_ucp = (re->options & PCRE_UC
9112  ccend = bracketend(rootbacktrack.cc);  ccend = bracketend(rootbacktrack.cc);
9113    
9114  /* Calculate the local space size on the stack. */  /* Calculate the local space size on the stack. */
9115  common->ovector_start = CALL_LIMIT + sizeof(sljit_sw);  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);
9116  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);
9117  if (!common->optimized_cbracket)  if (!common->optimized_cbracket)
9118    return;    return;
# Line 9102  OP1(SLJIT_MOV, TMP1, 0, SLJIT_SAVED_REG1 Line 9244  OP1(SLJIT_MOV, TMP1, 0, SLJIT_SAVED_REG1
9244  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));
9245  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));
9246  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));
9247  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));
9248  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));
9249  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));
9250  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CALL_LIMIT, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LIMIT_MATCH, TMP1, 0);
9251    
9252  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
9253    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 9271  if ((re->options & PCRE_ANCHORED) == 0)
9271      else if ((re->flags & PCRE_STARTLINE) != 0)      else if ((re->flags & PCRE_STARTLINE) != 0)
9272        fast_forward_newline(common, (re->options & PCRE_FIRSTLINE) != 0);        fast_forward_newline(common, (re->options & PCRE_FIRSTLINE) != 0);
9273      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)
9274        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);
9275      }      }
9276    }    }
9277  else  else
# Line 9147  if (common->req_char_ptr != 0) Line 9289  if (common->req_char_ptr != 0)
9289  /* Store the current STR_PTR in OVECTOR(0). */  /* Store the current STR_PTR in OVECTOR(0). */
9290  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);
9291  /* Copy the limit of allowed recursions. */  /* Copy the limit of allowed recursions. */
9292  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);
9293  if (common->capture_last_ptr != 0)  if (common->capture_last_ptr != 0)
9294    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);
9295    
# Line 9425  else Line 9567  else
9567      }      }
9568    memset(functions, 0, sizeof(executable_functions));    memset(functions, 0, sizeof(executable_functions));
9569    functions->top_bracket = (re->top_bracket + 1) * 2;    functions->top_bracket = (re->top_bracket + 1) * 2;
9570      functions->limit_match = (re->flags & PCRE_MLSET) != 0 ? re->limit_match : 0;
9571    extra->executable_jit = functions;    extra->executable_jit = functions;
9572    extra->flags |= PCRE_EXTRA_EXECUTABLE_JIT;    extra->flags |= PCRE_EXTRA_EXECUTABLE_JIT;
9573    }    }
# Line 9479  arguments.begin = subject; Line 9622  arguments.begin = subject;
9622  arguments.end = subject + length;  arguments.end = subject + length;
9623  arguments.mark_ptr = NULL;  arguments.mark_ptr = NULL;
9624  /* JIT decreases this value less frequently than the interpreter. */  /* JIT decreases this value less frequently than the interpreter. */
9625  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);
9626    if (functions->limit_match != 0 && functions->limit_match < arguments.limit_match)
9627      arguments.limit_match = functions->limit_match;
9628  arguments.notbol = (options & PCRE_NOTBOL) != 0;  arguments.notbol = (options & PCRE_NOTBOL) != 0;
9629  arguments.noteol = (options & PCRE_NOTEOL) != 0;  arguments.noteol = (options & PCRE_NOTEOL) != 0;
9630  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
# Line 9570  arguments.begin = subject_ptr; Line 9715  arguments.begin = subject_ptr;
9715  arguments.end = subject_ptr + length;  arguments.end = subject_ptr + length;
9716  arguments.mark_ptr = NULL;  arguments.mark_ptr = NULL;
9717  /* JIT decreases this value less frequently than the interpreter. */  /* JIT decreases this value less frequently than the interpreter. */
9718  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);
9719    if (functions->limit_match != 0 && functions->limit_match < arguments.limit_match)
9720      arguments.limit_match = functions->limit_match;
9721  arguments.notbol = (options & PCRE_NOTBOL) != 0;  arguments.notbol = (options & PCRE_NOTBOL) != 0;
9722  arguments.noteol = (options & PCRE_NOTEOL) != 0;  arguments.noteol = (options & PCRE_NOTEOL) != 0;
9723  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
# Line 9689  if (extra != NULL && Line 9836  if (extra != NULL &&
9836    }    }
9837  }  }
9838    
9839    #if defined COMPILE_PCRE8
9840    PCRE_EXP_DECL void
9841    pcre_jit_free_unused_memory(void)
9842    #elif defined COMPILE_PCRE16
9843    PCRE_EXP_DECL void
9844    pcre16_jit_free_unused_memory(void)
9845    #elif defined COMPILE_PCRE32
9846    PCRE_EXP_DECL void
9847    pcre32_jit_free_unused_memory(void)
9848    #endif
9849    {
9850    sljit_free_unused_memory_exec();
9851    }
9852    
9853  #else  /* SUPPORT_JIT */  #else  /* SUPPORT_JIT */
9854    
9855  /* 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 9901  pcre32_assign_jit_stack(pcre32_extra *ex
9901  (void)userdata;  (void)userdata;
9902  }  }
9903    
9904    #if defined COMPILE_PCRE8
9905    PCRE_EXP_DECL void
9906    pcre_jit_free_unused_memory(void)
9907    #elif defined COMPILE_PCRE16
9908    PCRE_EXP_DECL void
9909    pcre16_jit_free_unused_memory(void)
9910    #elif defined COMPILE_PCRE32
9911    PCRE_EXP_DECL void
9912    pcre32_jit_free_unused_memory(void)
9913    #endif
9914    {
9915    }
9916    
9917  #endif  #endif
9918    
9919  /* End of pcre_jit_compile.c */  /* End of pcre_jit_compile.c */

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

  ViewVC Help
Powered by ViewVC 1.1.5