/[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 1377 by zherczeg, Sun Oct 13 20:44:30 2013 UTC revision 1379 by ph10, Mon Oct 14 13:54:07 2013 UTC
# 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:
# Line 6919  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 6955  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 6966  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 6988  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 7017  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 7030  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 7101  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 7131  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 7141  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 7183  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 7196  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 7220  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 7497  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 7505  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 7514  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);        cc = compile_ref_iterator_matchingpath(common, cc, parent);
7557      else      else
7558        {        {
# Line 7525  while (cc < ccend) Line 7563  while (cc < ccend)
7563    
7564      case OP_DNREF:      case OP_DNREF:
7565      case OP_DNREFI:      case OP_DNREFI:
7566      if (cc[1 + 2 * IMM2_SIZE] >= OP_CRSTAR && cc[1 + 2 * IMM2_SIZE] <= OP_CRMINRANGE)      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        {        {
# Line 7685  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 7694  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 7713  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 7723  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 7768  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 7808  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    

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

  ViewVC Help
Powered by ViewVC 1.1.5