/[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 1325 by ph10, Fri May 10 14:03:18 2013 UTC revision 1379 by ph10, Mon Oct 14 13:54:07 2013 UTC
# Line 371  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 481  to characters. The vector data is divide Line 481  to characters. The vector data is divide
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 585  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 614  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 736  switch(*cc) Line 742  switch(*cc)
742    
743  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
744  {  {
745  pcre_uchar *name;  int count;
746  pcre_uchar *name2;  pcre_uchar *slot;
 unsigned int cbra_index;  
 int i;  
747    
748  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
749  while (cc < ccend)  while (cc < ccend)
# Line 773  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 4317  while (*cc != XCL_END) Line 4313  while (*cc != XCL_END)
4313    
4314        case PT_SPACE:        case PT_SPACE:
4315        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);  
         }  
4316        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4317        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);
4318        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);
4319        if (*cc == PT_SPACE)  
4320          JUMPHERE(jump);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x9);
4321          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4322    
4323          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x9);
4324          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4325    
4326        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4327        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 5056  if (context.length > 0) Line 5051  if (context.length > 0)
5051  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);
5052  }  }
5053    
 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));  
 }  
   
5054  /* Forward definitions. */  /* Forward definitions. */
5055  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);
5056  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);
# Line 5110  static void compile_backtrackingpath(com Line 5083  static void compile_backtrackingpath(com
5083    
5084  #define BACKTRACK_AS(type) ((type *)backtrack)  #define BACKTRACK_AS(type) ((type *)backtrack)
5085    
5086  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)
5087  {  {
5088    /* The OVECTOR offset goes to TMP2. */
5089  DEFINE_COMPILER;  DEFINE_COMPILER;
5090  int offset = GET2(cc, 1) << 1;  int count = GET2(cc, 1 + IMM2_SIZE);
5091    pcre_uchar *slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
5092    unsigned int offset;
5093    jump_list *found = NULL;
5094    
5095    SLJIT_ASSERT(*cc == OP_DNREF || *cc == OP_DNREFI);
5096    
5097    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
5098    
5099    count--;
5100    while (count-- > 0)
5101      {
5102      offset = GET2(slot, 0) << 1;
5103      GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5104      add_jump(compiler, &found, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5105      slot += common->name_entry_size;
5106      }
5107    
5108    offset = GET2(slot, 0) << 1;
5109    GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5110    if (backtracks != NULL && !common->jscript_compat)
5111      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5112    
5113    set_jumps(found, LABEL());
5114    }
5115    
5116    static void compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)
5117    {
5118    DEFINE_COMPILER;
5119    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5120    int offset = 0;
5121  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
5122  struct sljit_jump *partial;  struct sljit_jump *partial;
5123  struct sljit_jump *nopartial;  struct sljit_jump *nopartial;
5124    
5125  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  if (ref)
5126  /* OVECTOR(1) contains the "string begin - 1" constant. */    {
5127  if (withchecks && !common->jscript_compat)    offset = GET2(cc, 1) << 1;
5128    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));
5129      /* OVECTOR(1) contains the "string begin - 1" constant. */
5130      if (withchecks && !common->jscript_compat)
5131        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5132      }
5133    else
5134      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5135    
5136  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5137  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5138    {    {
5139    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);
5140    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));    if (ref)
5141        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5142      else
5143        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5144    
5145    if (withchecks)    if (withchecks)
5146      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5147    
# Line 5152  if (common->utf && *cc == OP_REFI) Line 5166  if (common->utf && *cc == OP_REFI)
5166  else  else
5167  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
5168    {    {
5169    OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);    if (ref)
5170        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
5171      else
5172        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
5173    
5174    if (withchecks)    if (withchecks)
5175      jump = JUMP(SLJIT_C_ZERO);      jump = JUMP(SLJIT_C_ZERO);
5176    
# Line 5189  if (jump != NULL) Line 5207  if (jump != NULL)
5207    else    else
5208      JUMPHERE(jump);      JUMPHERE(jump);
5209    }    }
 return cc + 1 + IMM2_SIZE;  
5210  }  }
5211    
5212  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)
5213  {  {
5214  DEFINE_COMPILER;  DEFINE_COMPILER;
5215    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5216  backtrack_common *backtrack;  backtrack_common *backtrack;
5217  pcre_uchar type;  pcre_uchar type;
5218    int offset = 0;
5219  struct sljit_label *label;  struct sljit_label *label;
5220  struct sljit_jump *zerolength;  struct sljit_jump *zerolength;
5221  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 5206  BOOL minimize; Line 5225  BOOL minimize;
5225    
5226  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
5227    
5228    if (ref)
5229      offset = GET2(cc, 1) << 1;
5230    else
5231      cc += IMM2_SIZE;
5232  type = cc[1 + IMM2_SIZE];  type = cc[1 + IMM2_SIZE];
5233    
5234    SLJIT_COMPILE_ASSERT((OP_CRSTAR & 0x1) == 0, crstar_opcode_must_be_even);
5235  minimize = (type & 0x1) != 0;  minimize = (type & 0x1) != 0;
5236  switch(type)  switch(type)
5237    {    {
# Line 5244  if (!minimize) Line 5269  if (!minimize)
5269    if (min == 0)    if (min == 0)
5270      {      {
5271      allocate_stack(common, 2);      allocate_stack(common, 2);
5272        if (ref)
5273          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5274      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5275      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5276      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5277      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));
5278      zerolength = compile_ref_checks(common, ccbegin, NULL);      /* Handles both invalid and empty cases. Since the minimum repeat,
5279        is zero the invalid case is basically the same as an empty case. */
5280        if (ref)
5281          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5282        else
5283          {
5284          compile_dnref_search(common, ccbegin, NULL);
5285          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5286          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5287          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5288          }
5289      /* Restore if not zero length. */      /* Restore if not zero length. */
5290      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));
5291      }      }
5292    else    else
5293      {      {
5294      allocate_stack(common, 1);      allocate_stack(common, 1);
5295        if (ref)
5296          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5297      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5298      zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);      if (ref)
5299          {
5300          add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5301          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5302          }
5303        else
5304          {
5305          compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5306          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5307          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5308          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5309          }
5310      }      }
5311    
5312    if (min > 1 || max > 1)    if (min > 1 || max > 1)
5313      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
5314    
5315    label = LABEL();    label = LABEL();
5316      if (!ref)
5317        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
5318    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);
5319    
5320    if (min > 1 || max > 1)    if (min > 1 || max > 1)
# Line 5297  if (!minimize) Line 5349  if (!minimize)
5349    return cc;    return cc;
5350    }    }
5351    
5352  allocate_stack(common, 2);  allocate_stack(common, ref ? 2 : 3);
5353    if (ref)
5354      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5355  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5356  if (type != OP_CRMINSTAR)  if (type != OP_CRMINSTAR)
5357    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5358    
5359  if (min == 0)  if (min == 0)
5360    {    {
5361    zerolength = compile_ref_checks(common, ccbegin, NULL);    /* Handles both invalid and empty cases. Since the minimum repeat,
5362      is zero the invalid case is basically the same as an empty case. */
5363      if (ref)
5364        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5365      else
5366        {
5367        compile_dnref_search(common, ccbegin, NULL);
5368        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5369        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5370        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5371        }
5372      /* Length is non-zero, we can match real repeats. */
5373    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5374    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
5375    }    }
5376  else  else
5377    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);    {
5378      if (ref)
5379        {
5380        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5381        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5382        }
5383      else
5384        {
5385        compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5386        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5387        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5388        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5389        }
5390      }
5391    
5392  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5393  if (max > 0)  if (max > 0)
5394    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));
5395    
5396    if (!ref)
5397      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
5398  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);
5399  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5400    
# Line 5902  common->accept = save_accept; Line 5982  common->accept = save_accept;
5982  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5983  }  }
5984    
 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;  
 }  
   
5985  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)
5986  {  {
5987  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 6144  backtrack_common *backtrack; Line 6114  backtrack_common *backtrack;
6114  pcre_uchar opcode;  pcre_uchar opcode;
6115  int private_data_ptr = 0;  int private_data_ptr = 0;
6116  int offset = 0;  int offset = 0;
6117  int stacksize;  int i, stacksize;
6118  int repeat_ptr = 0, repeat_length = 0;  int repeat_ptr = 0, repeat_length = 0;
6119  int repeat_type = 0, repeat_count = 0;  int repeat_type = 0, repeat_count = 0;
6120  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
6121  pcre_uchar *matchingpath;  pcre_uchar *matchingpath;
6122    pcre_uchar *slot;
6123  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
6124  pcre_uchar ket;  pcre_uchar ket;
6125  assert_backtrack *assert;  assert_backtrack *assert;
# Line 6198  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket Line 6169  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket
6169  cc += GET(cc, 1);  cc += GET(cc, 1);
6170    
6171  has_alternatives = *cc == OP_ALT;  has_alternatives = *cc == OP_ALT;
6172  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))  if (SLJIT_UNLIKELY(opcode == OP_COND || opcode == OP_SCOND))
6173    {    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);  
     }  
   }  
6174    
6175  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))
6176    opcode = OP_SCOND;    opcode = OP_SCOND;
# Line 6448  if (opcode == OP_COND || opcode == OP_SC Line 6407  if (opcode == OP_COND || opcode == OP_SC
6407        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)));
6408      matchingpath += 1 + IMM2_SIZE;      matchingpath += 1 + IMM2_SIZE;
6409      }      }
6410    else if (*matchingpath == OP_NCREF)    else if (*matchingpath == OP_DNCREF)
6411      {      {
6412      SLJIT_ASSERT(has_alternatives);      SLJIT_ASSERT(has_alternatives);
     stacksize = GET2(matchingpath, 1);  
     jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(stacksize << 1), SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  
   
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);  
     OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (stacksize << 8) | (common->ovector_start / sizeof(sljit_sw)));  
     GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, 0);  
     OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);  
     sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchovector));  
     OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);  
     add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0));  
6413    
6414      JUMPHERE(jump);      i = GET2(matchingpath, 1 + IMM2_SIZE);
6415      matchingpath += 1 + IMM2_SIZE;      slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;
6416        OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
6417        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
6418        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
6419        slot += common->name_entry_size;
6420        i--;
6421        while (i-- > 0)
6422          {
6423          OP2(SLJIT_SUB, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
6424          OP2(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, STR_PTR, 0);
6425          slot += common->name_entry_size;
6426          }
6427        OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
6428        add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), JUMP(SLJIT_C_ZERO));
6429        matchingpath += 1 + 2 * IMM2_SIZE;
6430      }      }
6431    else if (*matchingpath == OP_RREF || *matchingpath == OP_NRREF)    else if (*matchingpath == OP_RREF || *matchingpath == OP_DNRREF)
6432      {      {
6433      /* Never has other case. */      /* Never has other case. */
6434      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;
6435        SLJIT_ASSERT(!has_alternatives);
6436    
6437      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)  
6438        {        {
6439        SLJIT_ASSERT(!has_alternatives);        stacksize = GET2(matchingpath, 1);
6440          if (common->currententry == NULL)
6441            stacksize = 0;
6442          else if (stacksize == RREF_ANY)
6443            stacksize = 1;
6444          else if (common->currententry->start == 0)
6445            stacksize = stacksize == 0;
6446          else
6447            stacksize = stacksize == (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6448    
6449        if (stacksize != 0)        if (stacksize != 0)
6450          matchingpath += 1 + IMM2_SIZE;          matchingpath += 1 + IMM2_SIZE;
6451          }
6452        else
6453          {
6454          if (common->currententry == NULL || common->currententry->start == 0)
6455            stacksize = 0;
6456        else        else
6457          {          {
6458            stacksize = GET2(matchingpath, 1 + IMM2_SIZE);
6459            slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;
6460            i = (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6461            while (stacksize > 0)
6462              {
6463              if ((int)GET2(slot, 0) == i)
6464                break;
6465              slot += common->name_entry_size;
6466              stacksize--;
6467              }
6468            }
6469    
6470          if (stacksize != 0)
6471            matchingpath += 1 + 2 * IMM2_SIZE;
6472          }
6473    
6474          /* The stacksize == 0 is a common "else" case. */
6475          if (stacksize == 0)
6476            {
6477          if (*cc == OP_ALT)          if (*cc == OP_ALT)
6478            {            {
6479            matchingpath = cc + 1 + LINK_SIZE;            matchingpath = cc + 1 + LINK_SIZE;
# Line 6497  if (opcode == OP_COND || opcode == OP_SC Line 6482  if (opcode == OP_COND || opcode == OP_SC
6482          else          else
6483            matchingpath = cc;            matchingpath = cc;
6484          }          }
       }  
     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;  
       }  
6485      }      }
6486    else    else
6487      {      {
# Line 6956  count_match(common); Line 6923  count_match(common);
6923  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
6924  }  }
6925    
6926  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)
6927  {  {
6928  int class_len;  int class_len;
6929    
# Line 6992  else if (*opcode >= OP_TYPESTAR && *opco Line 6959  else if (*opcode >= OP_TYPESTAR && *opco
6959    }    }
6960  else  else
6961    {    {
6962    SLJIT_ASSERT(*opcode >= OP_CLASS || *opcode <= OP_XCLASS);    SLJIT_ASSERT(*opcode == OP_CLASS || *opcode == OP_NCLASS || *opcode == OP_XCLASS);
6963    *type = *opcode;    *type = *opcode;
6964    cc++;    cc++;
6965    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 7003  else Line 6970  else
6970      if (end != NULL)      if (end != NULL)
6971        *end = cc + class_len;        *end = cc + class_len;
6972      }      }
6973      else if (*opcode >= OP_CRPOSSTAR && *opcode <= OP_CRPOSQUERY)
6974        {
6975        *opcode -= OP_CRPOSSTAR - OP_POSSTAR;
6976        if (end != NULL)
6977          *end = cc + class_len;
6978        }
6979    else    else
6980      {      {
6981      SLJIT_ASSERT(*opcode == OP_CRRANGE || *opcode == OP_CRMINRANGE);      SLJIT_ASSERT(*opcode == OP_CRRANGE || *opcode == OP_CRMINRANGE || *opcode == OP_CRPOSRANGE);
6982      *arg1 = GET2(cc, (class_len + IMM2_SIZE));      *max = GET2(cc, (class_len + IMM2_SIZE));
6983      *arg2 = GET2(cc, class_len);      *min = GET2(cc, class_len);
6984    
6985      if (*arg2 == 0)      if (*min == 0)
6986        {        {
6987        SLJIT_ASSERT(*arg1 != 0);        SLJIT_ASSERT(*max != 0);
6988        *opcode = (*opcode == OP_CRRANGE) ? OP_UPTO : OP_MINUPTO;        *opcode = (*opcode == OP_CRRANGE) ? OP_UPTO : (*opcode == OP_CRMINRANGE ? OP_MINUPTO : OP_POSUPTO);
6989        }        }
6990      if (*arg1 == *arg2)      if (*max == *min)
6991        *opcode = OP_EXACT;        *opcode = OP_EXACT;
6992    
6993      if (end != NULL)      if (end != NULL)
# Line 7025  else Line 6998  else
6998    
6999  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)
7000    {    {
7001    *arg1 = GET2(cc, 0);    *max = GET2(cc, 0);
7002    cc += IMM2_SIZE;    cc += IMM2_SIZE;
7003    }    }
7004    
# Line 7054  DEFINE_COMPILER; Line 7027  DEFINE_COMPILER;
7027  backtrack_common *backtrack;  backtrack_common *backtrack;
7028  pcre_uchar opcode;  pcre_uchar opcode;
7029  pcre_uchar type;  pcre_uchar type;
7030  int arg1 = -1, arg2 = -1;  int max = -1, min = -1;
7031  pcre_uchar* end;  pcre_uchar* end;
7032  jump_list *nomatch = NULL;  jump_list *nomatch = NULL;
7033  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 7067  int tmp_base, tmp_offset; Line 7040  int tmp_base, tmp_offset;
7040    
7041  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
7042    
7043  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);  cc = get_iterator_parameters(common, cc, &opcode, &type, &max, &min, &end);
7044    
7045  switch(type)  switch(type)
7046    {    {
# Line 7138  switch(opcode) Line 7111  switch(opcode)
7111        {        {
7112        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);
7113        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
7114        if (opcode == OP_CRRANGE && arg2 > 0)        if (opcode == OP_CRRANGE && min > 0)
7115          CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg2, label);          CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min, label);
7116        if (opcode == OP_UPTO || (opcode == OP_CRRANGE && arg1 > 0))        if (opcode == OP_UPTO || (opcode == OP_CRRANGE && max > 0))
7117          jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, arg1);          jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, max);
7118        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);
7119        }        }
7120    
# Line 7168  switch(opcode) Line 7141  switch(opcode)
7141      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
7142      if (opcode <= OP_PLUS)      if (opcode <= OP_PLUS)
7143        JUMPTO(SLJIT_JUMP, label);        JUMPTO(SLJIT_JUMP, label);
7144      else if (opcode == OP_CRRANGE && arg1 == 0)      else if (opcode == OP_CRRANGE && max == 0)
7145        {        {
7146        OP2(SLJIT_ADD, base, offset1, base, offset1, SLJIT_IMM, 1);        OP2(SLJIT_ADD, base, offset1, base, offset1, SLJIT_IMM, 1);
7147        JUMPTO(SLJIT_JUMP, label);        JUMPTO(SLJIT_JUMP, label);
# Line 7178  switch(opcode) Line 7151  switch(opcode)
7151        OP1(SLJIT_MOV, TMP1, 0, base, offset1);        OP1(SLJIT_MOV, TMP1, 0, base, offset1);
7152        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
7153        OP1(SLJIT_MOV, base, offset1, TMP1, 0);        OP1(SLJIT_MOV, base, offset1, TMP1, 0);
7154        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg1 + 1, label);        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, max + 1, label);
7155        }        }
7156      set_jumps(nomatch, LABEL());      set_jumps(nomatch, LABEL());
7157      if (opcode == OP_CRRANGE)      if (opcode == OP_CRRANGE)
7158        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));
7159      OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);      OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
7160      }      }
7161    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
# Line 7220  switch(opcode) Line 7193  switch(opcode)
7193    break;    break;
7194    
7195    case OP_EXACT:    case OP_EXACT:
7196    OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, arg1);    OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, max);
7197    label = LABEL();    label = LABEL();
7198    compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);    compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7199    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 7233  switch(opcode) Line 7206  switch(opcode)
7206    if (opcode == OP_POSPLUS)    if (opcode == OP_POSPLUS)
7207      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7208    if (opcode == OP_POSUPTO)    if (opcode == OP_POSUPTO)
7209      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, arg1);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, max);
7210    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7211    label = LABEL();    label = LABEL();
7212    compile_char1_matchingpath(common, type, cc, &nomatch);    compile_char1_matchingpath(common, type, cc, &nomatch);
# Line 7257  switch(opcode) Line 7230  switch(opcode)
7230    OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);    OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);
7231    break;    break;
7232    
7233      case OP_CRPOSRANGE:
7234      /* Combination of OP_EXACT and OP_POSSTAR or OP_POSUPTO */
7235      OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, min);
7236      label = LABEL();
7237      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7238      OP2(SLJIT_SUB | SLJIT_SET_E, tmp_base, tmp_offset, tmp_base, tmp_offset, SLJIT_IMM, 1);
7239      JUMPTO(SLJIT_C_NOT_ZERO, label);
7240    
7241      if (max != 0)
7242        {
7243        SLJIT_ASSERT(max - min > 0);
7244        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, max - min);
7245        }
7246      OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7247      label = LABEL();
7248      compile_char1_matchingpath(common, type, cc, &nomatch);
7249      OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7250      if (max == 0)
7251        JUMPTO(SLJIT_JUMP, label);
7252      else
7253        {
7254        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, 1);
7255        JUMPTO(SLJIT_C_NOT_ZERO, label);
7256        }
7257      set_jumps(nomatch, LABEL());
7258      OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);
7259      break;
7260    
7261    default:    default:
7262    SLJIT_ASSERT_STOP();    SLJIT_ASSERT_STOP();
7263    break;    break;
# Line 7534  while (cc < ccend) Line 7535  while (cc < ccend)
7535    
7536      case OP_CLASS:      case OP_CLASS:
7537      case OP_NCLASS:      case OP_NCLASS:
7538      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)
7539        cc = compile_iterator_matchingpath(common, cc, parent);        cc = compile_iterator_matchingpath(common, cc, parent);
7540      else      else
7541        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 7542  while (cc < ccend) Line 7543  while (cc < ccend)
7543    
7544  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
7545      case OP_XCLASS:      case OP_XCLASS:
7546      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)
7547        cc = compile_iterator_matchingpath(common, cc, parent);        cc = compile_iterator_matchingpath(common, cc, parent);
7548      else      else
7549        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 7551  while (cc < ccend) Line 7552  while (cc < ccend)
7552    
7553      case OP_REF:      case OP_REF:
7554      case OP_REFI:      case OP_REFI:
7555      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)
7556          cc = compile_ref_iterator_matchingpath(common, cc, parent);
7557        else
7558          {
7559          compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);
7560          cc += 1 + IMM2_SIZE;
7561          }
7562        break;
7563    
7564        case OP_DNREF:
7565        case OP_DNREFI:
7566        if (cc[1 + 2 * IMM2_SIZE] >= OP_CRSTAR && cc[1 + 2 * IMM2_SIZE] <= OP_CRPOSRANGE)
7567        cc = compile_ref_iterator_matchingpath(common, cc, parent);        cc = compile_ref_iterator_matchingpath(common, cc, parent);
7568      else      else
7569        cc = compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);        {
7570          compile_dnref_search(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);
7571          compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);
7572          cc += 1 + 2 * IMM2_SIZE;
7573          }
7574      break;      break;
7575    
7576      case OP_RECURSE:      case OP_RECURSE:
# Line 7707  DEFINE_COMPILER; Line 7723  DEFINE_COMPILER;
7723  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
7724  pcre_uchar opcode;  pcre_uchar opcode;
7725  pcre_uchar type;  pcre_uchar type;
7726  int arg1 = -1, arg2 = -1;  int max = -1, min = -1;
7727  struct sljit_label *label = NULL;  struct sljit_label *label = NULL;
7728  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
7729  jump_list *jumplist = NULL;  jump_list *jumplist = NULL;
# Line 7716  int base = (private_data_ptr == 0) ? SLJ Line 7732  int base = (private_data_ptr == 0) ? SLJ
7732  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;
7733  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);
7734    
7735  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, NULL);  cc = get_iterator_parameters(common, cc, &opcode, &type, &max, &min, NULL);
7736    
7737  switch(opcode)  switch(opcode)
7738    {    {
# Line 7735  switch(opcode) Line 7751  switch(opcode)
7751    else    else
7752      {      {
7753      if (opcode == OP_UPTO)      if (opcode == OP_UPTO)
7754        arg2 = 0;        min = 0;
7755      if (opcode <= OP_PLUS)      if (opcode <= OP_PLUS)
7756        {        {
7757        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
# Line 7745  switch(opcode) Line 7761  switch(opcode)
7761        {        {
7762        OP1(SLJIT_MOV, TMP1, 0, base, offset1);        OP1(SLJIT_MOV, TMP1, 0, base, offset1);
7763        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
7764        jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, arg2 + 1);        jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, min + 1);
7765        OP2(SLJIT_SUB, base, offset1, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_SUB, base, offset1, TMP1, 0, SLJIT_IMM, 1);
7766        }        }
7767      skip_char_back(common);      skip_char_back(common);
# Line 7790  switch(opcode) Line 7806  switch(opcode)
7806    OP1(SLJIT_MOV, base, offset1, TMP1, 0);    OP1(SLJIT_MOV, base, offset1, TMP1, 0);
7807    
7808    if (opcode == OP_CRMINRANGE)    if (opcode == OP_CRMINRANGE)
7809      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg2 + 1, label);      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min + 1, label);
7810    
7811    if (opcode == OP_CRMINRANGE && arg1 == 0)    if (opcode == OP_CRMINRANGE && max == 0)
7812      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->matchingpath);      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->matchingpath);
7813    else    else
7814      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);
7815    
7816    set_jumps(jumplist, LABEL());    set_jumps(jumplist, LABEL());
7817    if (private_data_ptr == 0)    if (private_data_ptr == 0)
# Line 7830  switch(opcode) Line 7846  switch(opcode)
7846    
7847    case OP_EXACT:    case OP_EXACT:
7848    case OP_POSPLUS:    case OP_POSPLUS:
7849      case OP_CRPOSRANGE:
7850    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
7851    break;    break;
7852    
# Line 7848  static SLJIT_INLINE void compile_ref_ite Line 7865  static SLJIT_INLINE void compile_ref_ite
7865  {  {
7866  DEFINE_COMPILER;  DEFINE_COMPILER;
7867  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
7868    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
7869  pcre_uchar type;  pcre_uchar type;
7870    
7871  type = cc[1 + IMM2_SIZE];  type = cc[ref ? 1 + IMM2_SIZE : 1 + 2 * IMM2_SIZE];
7872    
7873  if ((type & 0x1) == 0)  if ((type & 0x1) == 0)
7874    {    {
7875      /* Maximize case. */
7876    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
7877    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7878    free_stack(common, 1);    free_stack(common, 1);
# Line 7863  if ((type & 0x1) == 0) Line 7883  if ((type & 0x1) == 0)
7883  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7884  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);
7885  set_jumps(current->topbacktracks, LABEL());  set_jumps(current->topbacktracks, LABEL());
7886  free_stack(common, 2);  free_stack(common, ref ? 2 : 3);
7887  }  }
7888    
7889  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 8664  while (current) Line 8684  while (current)
8684    
8685      case OP_REF:      case OP_REF:
8686      case OP_REFI:      case OP_REFI:
8687        case OP_DNREF:
8688        case OP_DNREFI:
8689      compile_ref_iterator_backtrackingpath(common, current);      compile_ref_iterator_backtrackingpath(common, current);
8690      break;      break;
8691    
# Line 8958  else Line 8980  else
8980  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
8981  common->ctypes = (sljit_sw)(tables + ctypes_offset);  common->ctypes = (sljit_sw)(tables + ctypes_offset);
8982  common->digits[0] = -2;  common->digits[0] = -2;
8983  common->name_table = (sljit_sw)((pcre_uchar *)re + re->name_table_offset);  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;
8984  common->name_count = re->name_count;  common->name_count = re->name_count;
8985  common->name_entry_size = re->name_entry_size;  common->name_entry_size = re->name_entry_size;
8986  common->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;  common->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
# Line 9696  if (extra != NULL && Line 9718  if (extra != NULL &&
9718    }    }
9719  }  }
9720    
9721    #if defined COMPILE_PCRE8
9722    PCRE_EXP_DECL void
9723    pcre_jit_free_unused_memory(void)
9724    #elif defined COMPILE_PCRE16
9725    PCRE_EXP_DECL void
9726    pcre16_jit_free_unused_memory(void)
9727    #elif defined COMPILE_PCRE32
9728    PCRE_EXP_DECL void
9729    pcre32_jit_free_unused_memory(void)
9730    #endif
9731    {
9732    sljit_free_unused_memory_exec();
9733    }
9734    
9735  #else  /* SUPPORT_JIT */  #else  /* SUPPORT_JIT */
9736    
9737  /* 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 9747  pcre32_assign_jit_stack(pcre32_extra *ex Line 9783  pcre32_assign_jit_stack(pcre32_extra *ex
9783  (void)userdata;  (void)userdata;
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    }
9798    
9799  #endif  #endif
9800    
9801  /* End of pcre_jit_compile.c */  /* End of pcre_jit_compile.c */

Legend:
Removed from v.1325  
changed lines
  Added in v.1379

  ViewVC Help
Powered by ViewVC 1.1.5