/[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 1402 by zherczeg, Fri Nov 15 12:04:55 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 4029  const pcre_uint32 *other_cases; Line 4027  const pcre_uint32 *other_cases;
4027  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4028  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4029  int compares, invertcmp, numberofcmps;  int compares, invertcmp, numberofcmps;
4030    
4031  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4032  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4033  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
# Line 4128  while (*cc != XCL_END) Line 4127  while (*cc != XCL_END)
4127        case PT_SPACE:        case PT_SPACE:
4128        case PT_PXSPACE:        case PT_PXSPACE:
4129        case PT_WORD:        case PT_WORD:
4130          case PT_PXGRAPH:
4131          case PT_PXPRINT:
4132          case PT_PXPUNCT:
4133        needstype = TRUE;        needstype = TRUE;
4134        needschar = TRUE;        needschar = TRUE;
4135        break;        break;
# Line 4315  while (*cc != XCL_END) Line 4317  while (*cc != XCL_END)
4317    
4318        case PT_SPACE:        case PT_SPACE:
4319        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);  
         }  
4320        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4321        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);
4322        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);
4323        if (*cc == PT_SPACE)  
4324          JUMPHERE(jump);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x9);
4325          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4326    
4327          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x9);
4328          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4329    
4330        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4331        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 4417  while (*cc != XCL_END)
4417        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);
4418        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4419        break;        break;
4420    
4421          case PT_PXGRAPH:
4422          /* C and Z groups are the farthest two groups. */
4423          SET_TYPE_OFFSET(ucp_Ll);
4424          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4425          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4426    
4427          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4428    
4429          /* In case of ucp_Cf, we overwrite the result. */
4430          SET_CHAR_OFFSET(0x2066);
4431          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4432          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4433    
4434          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4435          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4436    
4437          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x2066);
4438          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4439    
4440          JUMPHERE(jump);
4441          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4442          break;
4443    
4444          case PT_PXPRINT:
4445          /* C and Z groups are the farthest two groups. */
4446          SET_TYPE_OFFSET(ucp_Ll);
4447          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4448          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4449    
4450          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Ll);
4451          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_NOT_EQUAL);
4452    
4453          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4454    
4455          /* In case of ucp_Cf, we overwrite the result. */
4456          SET_CHAR_OFFSET(0x2066);
4457          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4458          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4459    
4460          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4461          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4462    
4463          JUMPHERE(jump);
4464          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4465          break;
4466    
4467          case PT_PXPUNCT:
4468          SET_TYPE_OFFSET(ucp_Sc);
4469          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Sc);
4470          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4471    
4472          SET_CHAR_OFFSET(0);
4473          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xff);
4474          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4475    
4476          SET_TYPE_OFFSET(ucp_Pc);
4477          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ps - ucp_Pc);
4478          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4479          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4480          break;
4481        }        }
4482      cc += 2;      cc += 2;
4483      }      }
# Line 5054  if (context.length > 0) Line 5116  if (context.length > 0)
5116  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);
5117  }  }
5118    
 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));  
 }  
   
5119  /* Forward definitions. */  /* Forward definitions. */
5120  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);
5121  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 5148  static void compile_backtrackingpath(com
5148    
5149  #define BACKTRACK_AS(type) ((type *)backtrack)  #define BACKTRACK_AS(type) ((type *)backtrack)
5150    
5151  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)
5152  {  {
5153    /* The OVECTOR offset goes to TMP2. */
5154  DEFINE_COMPILER;  DEFINE_COMPILER;
5155  int offset = GET2(cc, 1) << 1;  int count = GET2(cc, 1 + IMM2_SIZE);
5156    pcre_uchar *slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
5157    unsigned int offset;
5158    jump_list *found = NULL;
5159    
5160    SLJIT_ASSERT(*cc == OP_DNREF || *cc == OP_DNREFI);
5161    
5162    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
5163    
5164    count--;
5165    while (count-- > 0)
5166      {
5167      offset = GET2(slot, 0) << 1;
5168      GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5169      add_jump(compiler, &found, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5170      slot += common->name_entry_size;
5171      }
5172    
5173    offset = GET2(slot, 0) << 1;
5174    GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5175    if (backtracks != NULL && !common->jscript_compat)
5176      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5177    
5178    set_jumps(found, LABEL());
5179    }
5180    
5181    static void compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)
5182    {
5183    DEFINE_COMPILER;
5184    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5185    int offset = 0;
5186  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
5187  struct sljit_jump *partial;  struct sljit_jump *partial;
5188  struct sljit_jump *nopartial;  struct sljit_jump *nopartial;
5189    
5190  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  if (ref)
5191  /* OVECTOR(1) contains the "string begin - 1" constant. */    {
5192  if (withchecks && !common->jscript_compat)    offset = GET2(cc, 1) << 1;
5193    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));
5194      /* OVECTOR(1) contains the "string begin - 1" constant. */
5195      if (withchecks && !common->jscript_compat)
5196        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5197      }
5198    else
5199      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5200    
5201  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5202  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5203    {    {
5204    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);
5205    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));    if (ref)
5206        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5207      else
5208        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5209    
5210    if (withchecks)    if (withchecks)
5211      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5212    
# Line 5150  if (common->utf && *cc == OP_REFI) Line 5231  if (common->utf && *cc == OP_REFI)
5231  else  else
5232  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
5233    {    {
5234    OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);    if (ref)
5235        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
5236      else
5237        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
5238    
5239    if (withchecks)    if (withchecks)
5240      jump = JUMP(SLJIT_C_ZERO);      jump = JUMP(SLJIT_C_ZERO);
5241    
# Line 5187  if (jump != NULL) Line 5272  if (jump != NULL)
5272    else    else
5273      JUMPHERE(jump);      JUMPHERE(jump);
5274    }    }
 return cc + 1 + IMM2_SIZE;  
5275  }  }
5276    
5277  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)
5278  {  {
5279  DEFINE_COMPILER;  DEFINE_COMPILER;
5280    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5281  backtrack_common *backtrack;  backtrack_common *backtrack;
5282  pcre_uchar type;  pcre_uchar type;
5283    int offset = 0;
5284  struct sljit_label *label;  struct sljit_label *label;
5285  struct sljit_jump *zerolength;  struct sljit_jump *zerolength;
5286  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 5204  BOOL minimize; Line 5290  BOOL minimize;
5290    
5291  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
5292    
5293    if (ref)
5294      offset = GET2(cc, 1) << 1;
5295    else
5296      cc += IMM2_SIZE;
5297  type = cc[1 + IMM2_SIZE];  type = cc[1 + IMM2_SIZE];
5298    
5299    SLJIT_COMPILE_ASSERT((OP_CRSTAR & 0x1) == 0, crstar_opcode_must_be_even);
5300  minimize = (type & 0x1) != 0;  minimize = (type & 0x1) != 0;
5301  switch(type)  switch(type)
5302    {    {
# Line 5242  if (!minimize) Line 5334  if (!minimize)
5334    if (min == 0)    if (min == 0)
5335      {      {
5336      allocate_stack(common, 2);      allocate_stack(common, 2);
5337        if (ref)
5338          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5339      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5340      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5341      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5342      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));
5343      zerolength = compile_ref_checks(common, ccbegin, NULL);      /* Handles both invalid and empty cases. Since the minimum repeat,
5344        is zero the invalid case is basically the same as an empty case. */
5345        if (ref)
5346          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5347        else
5348          {
5349          compile_dnref_search(common, ccbegin, NULL);
5350          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5351          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5352          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5353          }
5354      /* Restore if not zero length. */      /* Restore if not zero length. */
5355      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));
5356      }      }
5357    else    else
5358      {      {
5359      allocate_stack(common, 1);      allocate_stack(common, 1);
5360        if (ref)
5361          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5362      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5363      zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);      if (ref)
5364          {
5365          add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5366          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5367          }
5368        else
5369          {
5370          compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5371          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5372          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5373          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5374          }
5375      }      }
5376    
5377    if (min > 1 || max > 1)    if (min > 1 || max > 1)
5378      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
5379    
5380    label = LABEL();    label = LABEL();
5381      if (!ref)
5382        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
5383    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);
5384    
5385    if (min > 1 || max > 1)    if (min > 1 || max > 1)
# Line 5291  if (!minimize) Line 5410  if (!minimize)
5410    JUMPHERE(zerolength);    JUMPHERE(zerolength);
5411    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5412    
5413    decrease_call_count(common);    count_match(common);
5414    return cc;    return cc;
5415    }    }
5416    
5417  allocate_stack(common, 2);  allocate_stack(common, ref ? 2 : 3);
5418    if (ref)
5419      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5420  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5421  if (type != OP_CRMINSTAR)  if (type != OP_CRMINSTAR)
5422    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5423    
5424  if (min == 0)  if (min == 0)
5425    {    {
5426    zerolength = compile_ref_checks(common, ccbegin, NULL);    /* Handles both invalid and empty cases. Since the minimum repeat,
5427      is zero the invalid case is basically the same as an empty case. */
5428      if (ref)
5429        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5430      else
5431        {
5432        compile_dnref_search(common, ccbegin, NULL);
5433        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5434        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5435        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5436        }
5437      /* Length is non-zero, we can match real repeats. */
5438    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5439    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
5440    }    }
5441  else  else
5442    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);    {
5443      if (ref)
5444        {
5445        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5446        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5447        }
5448      else
5449        {
5450        compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5451        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5452        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5453        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5454        }
5455      }
5456    
5457  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5458  if (max > 0)  if (max > 0)
5459    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));
5460    
5461    if (!ref)
5462      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
5463  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);
5464  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5465    
# Line 5330  if (jump != NULL) Line 5477  if (jump != NULL)
5477    JUMPHERE(jump);    JUMPHERE(jump);
5478  JUMPHERE(zerolength);  JUMPHERE(zerolength);
5479    
5480  decrease_call_count(common);  count_match(common);
5481  return cc;  return cc;
5482  }  }
5483    
# Line 5900  common->accept = save_accept; Line 6047  common->accept = save_accept;
6047  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
6048  }  }
6049    
 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;  
 }  
   
6050  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)
6051  {  {
6052  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 6142  backtrack_common *backtrack; Line 6179  backtrack_common *backtrack;
6179  pcre_uchar opcode;  pcre_uchar opcode;
6180  int private_data_ptr = 0;  int private_data_ptr = 0;
6181  int offset = 0;  int offset = 0;
6182  int stacksize;  int i, stacksize;
6183  int repeat_ptr = 0, repeat_length = 0;  int repeat_ptr = 0, repeat_length = 0;
6184  int repeat_type = 0, repeat_count = 0;  int repeat_type = 0, repeat_count = 0;
6185  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
6186  pcre_uchar *matchingpath;  pcre_uchar *matchingpath;
6187    pcre_uchar *slot;
6188  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
6189  pcre_uchar ket;  pcre_uchar ket;
6190  assert_backtrack *assert;  assert_backtrack *assert;
# Line 6196  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket Line 6234  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket
6234  cc += GET(cc, 1);  cc += GET(cc, 1);
6235    
6236  has_alternatives = *cc == OP_ALT;  has_alternatives = *cc == OP_ALT;
6237  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))  if (SLJIT_UNLIKELY(opcode == OP_COND || opcode == OP_SCOND))
6238    {    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);  
     }  
   }  
6239    
6240  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))
6241    opcode = OP_SCOND;    opcode = OP_SCOND;
# Line 6446  if (opcode == OP_COND || opcode == OP_SC Line 6472  if (opcode == OP_COND || opcode == OP_SC
6472        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)));
6473      matchingpath += 1 + IMM2_SIZE;      matchingpath += 1 + IMM2_SIZE;
6474      }      }
6475    else if (*matchingpath == OP_NCREF)    else if (*matchingpath == OP_DNCREF)
6476      {      {
6477      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));  
6478    
6479      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);      i = GET2(matchingpath, 1 + IMM2_SIZE);
6480      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;
6481      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);      OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
6482      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));
6483      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);
6484      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);      slot += common->name_entry_size;
6485      sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchovector));      i--;
6486      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);      while (i-- > 0)
6487      add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0));        {
6488          OP2(SLJIT_SUB, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
6489      JUMPHERE(jump);        OP2(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, STR_PTR, 0);
6490      matchingpath += 1 + IMM2_SIZE;        slot += common->name_entry_size;
6491          }
6492        OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
6493        add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), JUMP(SLJIT_C_ZERO));
6494        matchingpath += 1 + 2 * IMM2_SIZE;
6495      }      }
6496    else if (*matchingpath == OP_RREF || *matchingpath == OP_NRREF)    else if (*matchingpath == OP_RREF || *matchingpath == OP_DNRREF)
6497      {      {
6498      /* Never has other case. */      /* Never has other case. */
6499      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;
6500        SLJIT_ASSERT(!has_alternatives);
6501    
6502      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)  
6503        {        {
6504        SLJIT_ASSERT(!has_alternatives);        stacksize = GET2(matchingpath, 1);
6505          if (common->currententry == NULL)
6506            stacksize = 0;
6507          else if (stacksize == RREF_ANY)
6508            stacksize = 1;
6509          else if (common->currententry->start == 0)
6510            stacksize = stacksize == 0;
6511          else
6512            stacksize = stacksize == (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6513    
6514        if (stacksize != 0)        if (stacksize != 0)
6515          matchingpath += 1 + IMM2_SIZE;          matchingpath += 1 + IMM2_SIZE;
6516          }
6517        else
6518          {
6519          if (common->currententry == NULL || common->currententry->start == 0)
6520            stacksize = 0;
6521        else        else
6522          {          {
6523            stacksize = GET2(matchingpath, 1 + IMM2_SIZE);
6524            slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;
6525            i = (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6526            while (stacksize > 0)
6527              {
6528              if ((int)GET2(slot, 0) == i)
6529                break;
6530              slot += common->name_entry_size;
6531              stacksize--;
6532              }
6533            }
6534    
6535          if (stacksize != 0)
6536            matchingpath += 1 + 2 * IMM2_SIZE;
6537          }
6538    
6539          /* The stacksize == 0 is a common "else" case. */
6540          if (stacksize == 0)
6541            {
6542          if (*cc == OP_ALT)          if (*cc == OP_ALT)
6543            {            {
6544            matchingpath = cc + 1 + LINK_SIZE;            matchingpath = cc + 1 + LINK_SIZE;
# Line 6495  if (opcode == OP_COND || opcode == OP_SC Line 6547  if (opcode == OP_COND || opcode == OP_SC
6547          else          else
6548            matchingpath = cc;            matchingpath = cc;
6549          }          }
       }  
     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;  
       }  
6550      }      }
6551    else    else
6552      {      {
# Line 6663  if (bra == OP_BRAMINZERO) Line 6697  if (bra == OP_BRAMINZERO)
6697    }    }
6698    
6699  if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)  if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)
6700    decrease_call_count(common);    count_match(common);
6701    
6702  /* Skip the other alternatives. */  /* Skip the other alternatives. */
6703  while (*cc == OP_ALT)  while (*cc == OP_ALT)
# Line 6950  if (!zero) Line 6984  if (!zero)
6984    
6985  /* None of them matched. */  /* None of them matched. */
6986  set_jumps(emptymatch, LABEL());  set_jumps(emptymatch, LABEL());
6987  decrease_call_count(common);  count_match(common);
6988  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
6989  }  }
6990    
6991  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)
6992  {  {
6993  int class_len;  int class_len;
6994    
# Line 6990  else if (*opcode >= OP_TYPESTAR && *opco Line 7024  else if (*opcode >= OP_TYPESTAR && *opco
7024    }    }
7025  else  else
7026    {    {
7027    SLJIT_ASSERT(*opcode >= OP_CLASS || *opcode <= OP_XCLASS);    SLJIT_ASSERT(*opcode == OP_CLASS || *opcode == OP_NCLASS || *opcode == OP_XCLASS);
7028    *type = *opcode;    *type = *opcode;
7029    cc++;    cc++;
7030    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 7035  else
7035      if (end != NULL)      if (end != NULL)
7036        *end = cc + class_len;        *end = cc + class_len;
7037      }      }
7038      else if (*opcode >= OP_CRPOSSTAR && *opcode <= OP_CRPOSQUERY)
7039        {
7040        *opcode -= OP_CRPOSSTAR - OP_POSSTAR;
7041        if (end != NULL)
7042          *end = cc + class_len;
7043        }
7044    else    else
7045      {      {
7046      SLJIT_ASSERT(*opcode == OP_CRRANGE || *opcode == OP_CRMINRANGE);      SLJIT_ASSERT(*opcode == OP_CRRANGE || *opcode == OP_CRMINRANGE || *opcode == OP_CRPOSRANGE);
7047      *arg1 = GET2(cc, (class_len + IMM2_SIZE));      *max = GET2(cc, (class_len + IMM2_SIZE));
7048      *arg2 = GET2(cc, class_len);      *min = GET2(cc, class_len);
7049    
7050      if (*arg2 == 0)      if (*min == 0)
7051        {        {
7052        SLJIT_ASSERT(*arg1 != 0);        SLJIT_ASSERT(*max != 0);
7053        *opcode = (*opcode == OP_CRRANGE) ? OP_UPTO : OP_MINUPTO;        *opcode = (*opcode == OP_CRRANGE) ? OP_UPTO : (*opcode == OP_CRMINRANGE ? OP_MINUPTO : OP_POSUPTO);
7054        }        }
7055      if (*arg1 == *arg2)      if (*max == *min)
7056        *opcode = OP_EXACT;        *opcode = OP_EXACT;
7057    
7058      if (end != NULL)      if (end != NULL)
# Line 7023  else Line 7063  else
7063    
7064  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)
7065    {    {
7066    *arg1 = GET2(cc, 0);    *max = GET2(cc, 0);
7067    cc += IMM2_SIZE;    cc += IMM2_SIZE;
7068    }    }
7069    
# Line 7052  DEFINE_COMPILER; Line 7092  DEFINE_COMPILER;
7092  backtrack_common *backtrack;  backtrack_common *backtrack;
7093  pcre_uchar opcode;  pcre_uchar opcode;
7094  pcre_uchar type;  pcre_uchar type;
7095  int arg1 = -1, arg2 = -1;  int max = -1, min = -1;
7096  pcre_uchar* end;  pcre_uchar* end;
7097  jump_list *nomatch = NULL;  jump_list *nomatch = NULL;
7098  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 7065  int tmp_base, tmp_offset; Line 7105  int tmp_base, tmp_offset;
7105    
7106  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
7107    
7108  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);  cc = get_iterator_parameters(common, cc, &opcode, &type, &max, &min, &end);
7109    
7110  switch(type)  switch(type)
7111    {    {
# Line 7136  switch(opcode) Line 7176  switch(opcode)
7176        {        {
7177        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);
7178        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
7179        if (opcode == OP_CRRANGE && arg2 > 0)        if (opcode == OP_CRRANGE && min > 0)
7180          CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg2, label);          CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min, label);
7181        if (opcode == OP_UPTO || (opcode == OP_CRRANGE && arg1 > 0))        if (opcode == OP_UPTO || (opcode == OP_CRRANGE && max > 0))
7182          jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, arg1);          jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, max);
7183        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);
7184        }        }
7185    
# Line 7166  switch(opcode) Line 7206  switch(opcode)
7206      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
7207      if (opcode <= OP_PLUS)      if (opcode <= OP_PLUS)
7208        JUMPTO(SLJIT_JUMP, label);        JUMPTO(SLJIT_JUMP, label);
7209      else if (opcode == OP_CRRANGE && arg1 == 0)      else if (opcode == OP_CRRANGE && max == 0)
7210        {        {
7211        OP2(SLJIT_ADD, base, offset1, base, offset1, SLJIT_IMM, 1);        OP2(SLJIT_ADD, base, offset1, base, offset1, SLJIT_IMM, 1);
7212        JUMPTO(SLJIT_JUMP, label);        JUMPTO(SLJIT_JUMP, label);
# Line 7176  switch(opcode) Line 7216  switch(opcode)
7216        OP1(SLJIT_MOV, TMP1, 0, base, offset1);        OP1(SLJIT_MOV, TMP1, 0, base, offset1);
7217        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
7218        OP1(SLJIT_MOV, base, offset1, TMP1, 0);        OP1(SLJIT_MOV, base, offset1, TMP1, 0);
7219        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg1 + 1, label);        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, max + 1, label);
7220        }        }
7221      set_jumps(nomatch, LABEL());      set_jumps(nomatch, LABEL());
7222      if (opcode == OP_CRRANGE)      if (opcode == OP_CRRANGE)
7223        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));
7224      OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);      OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
7225      }      }
7226    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
# Line 7218  switch(opcode) Line 7258  switch(opcode)
7258    break;    break;
7259    
7260    case OP_EXACT:    case OP_EXACT:
7261    OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, arg1);    OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, max);
7262    label = LABEL();    label = LABEL();
7263    compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);    compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7264    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 7271  switch(opcode)
7271    if (opcode == OP_POSPLUS)    if (opcode == OP_POSPLUS)
7272      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7273    if (opcode == OP_POSUPTO)    if (opcode == OP_POSUPTO)
7274      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, arg1);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, max);
7275    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7276    label = LABEL();    label = LABEL();
7277    compile_char1_matchingpath(common, type, cc, &nomatch);    compile_char1_matchingpath(common, type, cc, &nomatch);
# Line 7255  switch(opcode) Line 7295  switch(opcode)
7295    OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);    OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);
7296    break;    break;
7297    
7298      case OP_CRPOSRANGE:
7299      /* Combination of OP_EXACT and OP_POSSTAR or OP_POSUPTO */
7300      OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, min);
7301      label = LABEL();
7302      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7303      OP2(SLJIT_SUB | SLJIT_SET_E, tmp_base, tmp_offset, tmp_base, tmp_offset, SLJIT_IMM, 1);
7304      JUMPTO(SLJIT_C_NOT_ZERO, label);
7305    
7306      if (max != 0)
7307        {
7308        SLJIT_ASSERT(max - min > 0);
7309        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, max - min);
7310        }
7311      OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7312      label = LABEL();
7313      compile_char1_matchingpath(common, type, cc, &nomatch);
7314      OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7315      if (max == 0)
7316        JUMPTO(SLJIT_JUMP, label);
7317      else
7318        {
7319        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, 1);
7320        JUMPTO(SLJIT_C_NOT_ZERO, label);
7321        }
7322      set_jumps(nomatch, LABEL());
7323      OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);
7324      break;
7325    
7326    default:    default:
7327    SLJIT_ASSERT_STOP();    SLJIT_ASSERT_STOP();
7328    break;    break;
7329    }    }
7330    
7331  decrease_call_count(common);  count_match(common);
7332  return end;  return end;
7333  }  }
7334    
# Line 7532  while (cc < ccend) Line 7600  while (cc < ccend)
7600    
7601      case OP_CLASS:      case OP_CLASS:
7602      case OP_NCLASS:      case OP_NCLASS:
7603      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)
7604        cc = compile_iterator_matchingpath(common, cc, parent);        cc = compile_iterator_matchingpath(common, cc, parent);
7605      else      else
7606        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 7608  while (cc < ccend)
7608    
7609  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
7610      case OP_XCLASS:      case OP_XCLASS:
7611      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)
7612        cc = compile_iterator_matchingpath(common, cc, parent);        cc = compile_iterator_matchingpath(common, cc, parent);
7613      else      else
7614        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 7617  while (cc < ccend)
7617    
7618      case OP_REF:      case OP_REF:
7619      case OP_REFI:      case OP_REFI:
7620      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)
7621          cc = compile_ref_iterator_matchingpath(common, cc, parent);
7622        else
7623          {
7624          compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);
7625          cc += 1 + IMM2_SIZE;
7626          }
7627        break;
7628    
7629        case OP_DNREF:
7630        case OP_DNREFI:
7631        if (cc[1 + 2 * IMM2_SIZE] >= OP_CRSTAR && cc[1 + 2 * IMM2_SIZE] <= OP_CRPOSRANGE)
7632        cc = compile_ref_iterator_matchingpath(common, cc, parent);        cc = compile_ref_iterator_matchingpath(common, cc, parent);
7633      else      else
7634        cc = compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);        {
7635          compile_dnref_search(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);
7636          compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);
7637          cc += 1 + 2 * IMM2_SIZE;
7638          }
7639      break;      break;
7640    
7641      case OP_RECURSE:      case OP_RECURSE:
# Line 7587  while (cc < ccend) Line 7670  while (cc < ccend)
7670        }        }
7671      BACKTRACK_AS(braminzero_backtrack)->matchingpath = LABEL();      BACKTRACK_AS(braminzero_backtrack)->matchingpath = LABEL();
7672      if (cc[1] > OP_ASSERTBACK_NOT)      if (cc[1] > OP_ASSERTBACK_NOT)
7673        decrease_call_count(common);        count_match(common);
7674      break;      break;
7675    
7676      case OP_ONCE:      case OP_ONCE:
# Line 7705  DEFINE_COMPILER; Line 7788  DEFINE_COMPILER;
7788  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
7789  pcre_uchar opcode;  pcre_uchar opcode;
7790  pcre_uchar type;  pcre_uchar type;
7791  int arg1 = -1, arg2 = -1;  int max = -1, min = -1;
7792  struct sljit_label *label = NULL;  struct sljit_label *label = NULL;
7793  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
7794  jump_list *jumplist = NULL;  jump_list *jumplist = NULL;
# Line 7714  int base = (private_data_ptr == 0) ? SLJ Line 7797  int base = (private_data_ptr == 0) ? SLJ
7797  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;
7798  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);
7799    
7800  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, NULL);  cc = get_iterator_parameters(common, cc, &opcode, &type, &max, &min, NULL);
7801    
7802  switch(opcode)  switch(opcode)
7803    {    {
# Line 7733  switch(opcode) Line 7816  switch(opcode)
7816    else    else
7817      {      {
7818      if (opcode == OP_UPTO)      if (opcode == OP_UPTO)
7819        arg2 = 0;        min = 0;
7820      if (opcode <= OP_PLUS)      if (opcode <= OP_PLUS)
7821        {        {
7822        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
# Line 7743  switch(opcode) Line 7826  switch(opcode)
7826        {        {
7827        OP1(SLJIT_MOV, TMP1, 0, base, offset1);        OP1(SLJIT_MOV, TMP1, 0, base, offset1);
7828        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
7829        jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, arg2 + 1);        jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, min + 1);
7830        OP2(SLJIT_SUB, base, offset1, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_SUB, base, offset1, TMP1, 0, SLJIT_IMM, 1);
7831        }        }
7832      skip_char_back(common);      skip_char_back(common);
# Line 7788  switch(opcode) Line 7871  switch(opcode)
7871    OP1(SLJIT_MOV, base, offset1, TMP1, 0);    OP1(SLJIT_MOV, base, offset1, TMP1, 0);
7872    
7873    if (opcode == OP_CRMINRANGE)    if (opcode == OP_CRMINRANGE)
7874      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg2 + 1, label);      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min + 1, label);
7875    
7876    if (opcode == OP_CRMINRANGE && arg1 == 0)    if (opcode == OP_CRMINRANGE && max == 0)
7877      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->matchingpath);      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->matchingpath);
7878    else    else
7879      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);
7880    
7881    set_jumps(jumplist, LABEL());    set_jumps(jumplist, LABEL());
7882    if (private_data_ptr == 0)    if (private_data_ptr == 0)
# Line 7828  switch(opcode) Line 7911  switch(opcode)
7911    
7912    case OP_EXACT:    case OP_EXACT:
7913    case OP_POSPLUS:    case OP_POSPLUS:
7914      case OP_CRPOSRANGE:
7915    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
7916    break;    break;
7917    
# Line 7846  static SLJIT_INLINE void compile_ref_ite Line 7930  static SLJIT_INLINE void compile_ref_ite
7930  {  {
7931  DEFINE_COMPILER;  DEFINE_COMPILER;
7932  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
7933    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
7934  pcre_uchar type;  pcre_uchar type;
7935    
7936  type = cc[1 + IMM2_SIZE];  type = cc[ref ? 1 + IMM2_SIZE : 1 + 2 * IMM2_SIZE];
7937    
7938  if ((type & 0x1) == 0)  if ((type & 0x1) == 0)
7939    {    {
7940      /* Maximize case. */
7941    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
7942    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7943    free_stack(common, 1);    free_stack(common, 1);
# Line 7861  if ((type & 0x1) == 0) Line 7948  if ((type & 0x1) == 0)
7948  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7949  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);
7950  set_jumps(current->topbacktracks, LABEL());  set_jumps(current->topbacktracks, LABEL());
7951  free_stack(common, 2);  free_stack(common, ref ? 2 : 3);
7952  }  }
7953    
7954  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 8312  if (has_alternatives)
8312          return;          return;
8313        }        }
8314    
8315      /* Instructions after the current alternative is succesfully matched. */      /* Instructions after the current alternative is successfully matched. */
8316      /* There is a similar code in compile_bracket_matchingpath. */      /* There is a similar code in compile_bracket_matchingpath. */
8317      if (opcode == OP_ONCE)      if (opcode == OP_ONCE)
8318        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 8749  while (current)
8749    
8750      case OP_REF:      case OP_REF:
8751      case OP_REFI:      case OP_REFI:
8752        case OP_DNREF:
8753        case OP_DNREFI:
8754      compile_ref_iterator_backtrackingpath(common, current);      compile_ref_iterator_backtrackingpath(common, current);
8755      break;      break;
8756    
# Line 8956  else Line 9045  else
9045  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
9046  common->ctypes = (sljit_sw)(tables + ctypes_offset);  common->ctypes = (sljit_sw)(tables + ctypes_offset);
9047  common->digits[0] = -2;  common->digits[0] = -2;
9048  common->name_table = (sljit_sw)((pcre_uchar *)re + re->name_table_offset);  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;
9049  common->name_count = re->name_count;  common->name_count = re->name_count;
9050  common->name_entry_size = re->name_entry_size;  common->name_entry_size = re->name_entry_size;
9051  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 9059  common->use_ucp = (re->options & PCRE_UC
9059  ccend = bracketend(rootbacktrack.cc);  ccend = bracketend(rootbacktrack.cc);
9060    
9061  /* Calculate the local space size on the stack. */  /* Calculate the local space size on the stack. */
9062  common->ovector_start = CALL_LIMIT + sizeof(sljit_sw);  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);
9063  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);
9064  if (!common->optimized_cbracket)  if (!common->optimized_cbracket)
9065    return;    return;
# Line 9102  OP1(SLJIT_MOV, TMP1, 0, SLJIT_SAVED_REG1 Line 9191  OP1(SLJIT_MOV, TMP1, 0, SLJIT_SAVED_REG1
9191  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));
9192  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));
9193  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));
9194  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));
9195  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));
9196  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));
9197  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CALL_LIMIT, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LIMIT_MATCH, TMP1, 0);
9198    
9199  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
9200    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 9147  if (common->req_char_ptr != 0) Line 9236  if (common->req_char_ptr != 0)
9236  /* Store the current STR_PTR in OVECTOR(0). */  /* Store the current STR_PTR in OVECTOR(0). */
9237  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);
9238  /* Copy the limit of allowed recursions. */  /* Copy the limit of allowed recursions. */
9239  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);
9240  if (common->capture_last_ptr != 0)  if (common->capture_last_ptr != 0)
9241    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);
9242    
# Line 9425  else Line 9514  else
9514      }      }
9515    memset(functions, 0, sizeof(executable_functions));    memset(functions, 0, sizeof(executable_functions));
9516    functions->top_bracket = (re->top_bracket + 1) * 2;    functions->top_bracket = (re->top_bracket + 1) * 2;
9517      functions->limit_match = (re->flags & PCRE_MLSET) != 0 ? re->limit_match : 0;
9518    extra->executable_jit = functions;    extra->executable_jit = functions;
9519    extra->flags |= PCRE_EXTRA_EXECUTABLE_JIT;    extra->flags |= PCRE_EXTRA_EXECUTABLE_JIT;
9520    }    }
# Line 9479  arguments.begin = subject; Line 9569  arguments.begin = subject;
9569  arguments.end = subject + length;  arguments.end = subject + length;
9570  arguments.mark_ptr = NULL;  arguments.mark_ptr = NULL;
9571  /* JIT decreases this value less frequently than the interpreter. */  /* JIT decreases this value less frequently than the interpreter. */
9572  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);
9573    if (functions->limit_match != 0 && functions->limit_match < arguments.limit_match)
9574      arguments.limit_match = functions->limit_match;
9575  arguments.notbol = (options & PCRE_NOTBOL) != 0;  arguments.notbol = (options & PCRE_NOTBOL) != 0;
9576  arguments.noteol = (options & PCRE_NOTEOL) != 0;  arguments.noteol = (options & PCRE_NOTEOL) != 0;
9577  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
# Line 9570  arguments.begin = subject_ptr; Line 9662  arguments.begin = subject_ptr;
9662  arguments.end = subject_ptr + length;  arguments.end = subject_ptr + length;
9663  arguments.mark_ptr = NULL;  arguments.mark_ptr = NULL;
9664  /* JIT decreases this value less frequently than the interpreter. */  /* JIT decreases this value less frequently than the interpreter. */
9665  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);
9666    if (functions->limit_match != 0 && functions->limit_match < arguments.limit_match)
9667      arguments.limit_match = functions->limit_match;
9668  arguments.notbol = (options & PCRE_NOTBOL) != 0;  arguments.notbol = (options & PCRE_NOTBOL) != 0;
9669  arguments.noteol = (options & PCRE_NOTEOL) != 0;  arguments.noteol = (options & PCRE_NOTEOL) != 0;
9670  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
# Line 9689  if (extra != NULL && Line 9783  if (extra != NULL &&
9783    }    }
9784  }  }
9785    
9786    #if defined COMPILE_PCRE8
9787    PCRE_EXP_DECL void
9788    pcre_jit_free_unused_memory(void)
9789    #elif defined COMPILE_PCRE16
9790    PCRE_EXP_DECL void
9791    pcre16_jit_free_unused_memory(void)
9792    #elif defined COMPILE_PCRE32
9793    PCRE_EXP_DECL void
9794    pcre32_jit_free_unused_memory(void)
9795    #endif
9796    {
9797    sljit_free_unused_memory_exec();
9798    }
9799    
9800  #else  /* SUPPORT_JIT */  #else  /* SUPPORT_JIT */
9801    
9802  /* 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 9848  pcre32_assign_jit_stack(pcre32_extra *ex
9848  (void)userdata;  (void)userdata;
9849  }  }
9850    
9851    #if defined COMPILE_PCRE8
9852    PCRE_EXP_DECL void
9853    pcre_jit_free_unused_memory(void)
9854    #elif defined COMPILE_PCRE16
9855    PCRE_EXP_DECL void
9856    pcre16_jit_free_unused_memory(void)
9857    #elif defined COMPILE_PCRE32
9858    PCRE_EXP_DECL void
9859    pcre32_jit_free_unused_memory(void)
9860    #endif
9861    {
9862    }
9863    
9864  #endif  #endif
9865    
9866  /* End of pcre_jit_compile.c */  /* End of pcre_jit_compile.c */

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

  ViewVC Help
Powered by ViewVC 1.1.5