/[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 1422 by zherczeg, Mon Dec 30 19:05:36 2013 UTC revision 1423 by zherczeg, Tue Dec 31 07:57:56 2013 UTC
# Line 363  typedef struct compiler_common { Line 363  typedef struct compiler_common {
363    BOOL positive_assert;    BOOL positive_assert;
364    /* Newline control. */    /* Newline control. */
365    int nltype;    int nltype;
366      pcre_uint32 nlmax;
367    int newline;    int newline;
368    int bsr_nltype;    int bsr_nltype;
369      pcre_uint32 bsr_nlmax;
370    /* Dollar endonly. */    /* Dollar endonly. */
371    int endonly;    int endonly;
372    /* Tables. */    /* Tables. */
# Line 522  the start pointers when the end of the c Line 524  the start pointers when the end of the c
524  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
525    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
526    
527    #define READ_CHAR_ANY 0x7fffffff
528    
529  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
530  {  {
531  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
# Line 2626  if (common->utf) Line 2630  if (common->utf)
2630    
2631  static SLJIT_INLINE void read_char(compiler_common *common)  static SLJIT_INLINE void read_char(compiler_common *common)
2632  {  {
2633  read_char_max(common, 0x7fffffff, TRUE);  read_char_max(common, READ_CHAR_ANY, TRUE);
2634  }  }
2635    
2636  static void read_char8_type(compiler_common *common, BOOL full_read)  static void read_char8_type(compiler_common *common, BOOL full_read)
# Line 2730  if (common->utf) Line 2734  if (common->utf)
2734  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2735  }  }
2736    
2737  static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpiftrue)  static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpifmatch)
2738  {  {
2739  /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */  /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */
2740  DEFINE_COMPILER;  DEFINE_COMPILER;
2741    struct sljit_jump *jump;
2742    
2743  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2744    {    {
2745    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2746    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpifmatch ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2747    }    }
2748  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2749    {    {
2750    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    if (jumpifmatch)
2751    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);      {
2752    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR));
2753    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2754    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));      }
2755      else
2756        {
2757        jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
2758        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2759        JUMPHERE(jump);
2760        }
2761    }    }
2762  else  else
2763    {    {
2764    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2765    add_jump(compiler, backtracks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));    add_jump(compiler, backtracks, CMP(jumpifmatch ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
2766    }    }
2767  }  }
2768    
# Line 2828  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S Line 2839  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S
2839  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2840    
2841  JUMPHERE(jump);  JUMPHERE(jump);
2842    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x400);
2843    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
2844    /* This code runs only in 8 bit mode. No need to shift the value. */
2845    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2846  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2847  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2848  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
# Line 2949  if (firstline) Line 2964  if (firstline)
2964      mainloop = LABEL();      mainloop = LABEL();
2965      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
2966      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
2967      read_char(common);      read_char_max(common, common->nlmax, TRUE);
2968      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
2969      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
2970      JUMPHERE(end);      JUMPHERE(end);
# Line 3517  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_ Line 3532  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_
3532  skip_char_back(common);  skip_char_back(common);
3533    
3534  loop = LABEL();  loop = LABEL();
3535  read_char(common);  read_char_max(common, common->nlmax, TRUE);
3536  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3537  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3538    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
# Line 4945  switch(type) Line 4960  switch(type)
4960    
4961    case OP_ANY:    case OP_ANY:
4962    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4963    read_char(common);    read_char_max(common, common->nlmax, TRUE);
4964    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4965      {      {
4966      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);
# Line 5013  switch(type) Line 5028  switch(type)
5028    
5029    case OP_ANYNL:    case OP_ANYNL:
5030    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5031    read_char(common);    read_char_max(common, common->bsr_nlmax, FALSE);
5032    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
5033    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
5034    end_list = NULL;    end_list = NULL;
# Line 5035  switch(type) Line 5050  switch(type)
5050    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
5051    case OP_HSPACE:    case OP_HSPACE:
5052    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5053    read_char(common);    read_char_max(common, 0x3000, type == OP_NOT_HSPACE);
5054    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));
5055    add_jump(compiler, backtracks, JUMP(type == OP_NOT_HSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_NOT_HSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
5056    return cc;    return cc;
# Line 5043  switch(type) Line 5058  switch(type)
5058    case OP_NOT_VSPACE:    case OP_NOT_VSPACE:
5059    case OP_VSPACE:    case OP_VSPACE:
5060    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5061    read_char(common);    read_char_max(common, 0x2029, type == OP_NOT_VSPACE);
5062    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));
5063    add_jump(compiler, backtracks, JUMP(type == OP_NOT_VSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_NOT_VSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
5064    return cc;    return cc;
# Line 5142  switch(type) Line 5157  switch(type)
5157      else      else
5158        {        {
5159        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);
5160        read_char(common);        read_char_max(common, common->nlmax, TRUE);
5161        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, STR_END, 0));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, STR_END, 0));
5162        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
5163        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 5190  switch(type) Line 5205  switch(type)
5205    else    else
5206      {      {
5207      skip_char_back(common);      skip_char_back(common);
5208      read_char(common);      read_char_max(common, common->nlmax, TRUE);
5209      check_newlinechar(common, common->nltype, backtracks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
5210      }      }
5211    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
# Line 5265  switch(type) Line 5280  switch(type)
5280  #endif  #endif
5281      return byte_sequence_compare(common, type == OP_CHARI, cc, &context, backtracks);      return byte_sequence_compare(common, type == OP_CHARI, cc, &context, backtracks);
5282      }      }
5283    
5284    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
   read_char(common);  
5285  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
5286    if (common->utf)    if (common->utf)
5287      {      {
# Line 5275  switch(type) Line 5290  switch(type)
5290    else    else
5291  #endif  #endif
5292      c = *cc;      c = *cc;
5293    
5294    if (type == OP_CHAR || !char_has_othercase(common, cc))    if (type == OP_CHAR || !char_has_othercase(common, cc))
5295      {      {
5296        read_char_max(common, c, FALSE);
5297      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c));
5298      return cc + length;      return cc + length;
5299      }      }
5300    oc = char_othercase(common, c);    oc = char_othercase(common, c);
5301      read_char_max(common, c > oc ? c : oc, FALSE);
5302    bit = c ^ oc;    bit = c ^ oc;
5303    if (is_powerof2(bit))    if (is_powerof2(bit))
5304      {      {
# Line 5288  switch(type) Line 5306  switch(type)
5306      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));
5307      return cc + length;      return cc + length;
5308      }      }
5309    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c);    jump[0] = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c);
5310    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);    add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, oc));
5311    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);    JUMPHERE(jump[0]);
   OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);  
   add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));  
5312    return cc + length;    return cc + length;
5313    
5314    case OP_NOT:    case OP_NOT:
# Line 9420  switch(re->options & PCRE_NEWLINE_BITS) Line 9436  switch(re->options & PCRE_NEWLINE_BITS)
9436    case PCRE_NEWLINE_ANYCRLF: common->newline = (CHAR_CR << 8) | CHAR_NL; common->nltype = NLTYPE_ANYCRLF; break;    case PCRE_NEWLINE_ANYCRLF: common->newline = (CHAR_CR << 8) | CHAR_NL; common->nltype = NLTYPE_ANYCRLF; break;
9437    default: return;    default: return;
9438    }    }
9439    common->nlmax = READ_CHAR_ANY;
9440  if ((re->options & PCRE_BSR_ANYCRLF) != 0)  if ((re->options & PCRE_BSR_ANYCRLF) != 0)
9441    common->bsr_nltype = NLTYPE_ANYCRLF;    common->bsr_nltype = NLTYPE_ANYCRLF;
9442  else if ((re->options & PCRE_BSR_UNICODE) != 0)  else if ((re->options & PCRE_BSR_UNICODE) != 0)
# Line 9432  else Line 9449  else
9449    common->bsr_nltype = NLTYPE_ANY;    common->bsr_nltype = NLTYPE_ANY;
9450  #endif  #endif
9451    }    }
9452    common->bsr_nlmax = READ_CHAR_ANY;
9453  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
9454  common->ctypes = (sljit_sw)(tables + ctypes_offset);  common->ctypes = (sljit_sw)(tables + ctypes_offset);
9455  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;
# Line 9444  common->utf = (re->options & PCRE_UTF8) Line 9462  common->utf = (re->options & PCRE_UTF8)
9462  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
9463  common->use_ucp = (re->options & PCRE_UCP) != 0;  common->use_ucp = (re->options & PCRE_UCP) != 0;
9464  #endif  #endif
9465    if (common->utf)
9466      {
9467      if (common->nltype == NLTYPE_ANY)
9468        common->nlmax = 0x2029;
9469      else if (common->nltype == NLTYPE_ANYCRLF)
9470        common->nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL;
9471      else
9472        {
9473        /* We only care about the first newline character. */
9474        common->nlmax = common->newline & 0xff;
9475        }
9476    
9477      if (common->bsr_nltype == NLTYPE_ANY)
9478        common->bsr_nlmax = 0x2029;
9479      else
9480        common->bsr_nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL;
9481      }
9482  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
9483  ccend = bracketend(rootbacktrack.cc);  ccend = bracketend(rootbacktrack.cc);
9484    

Legend:
Removed from v.1422  
changed lines
  Added in v.1423

  ViewVC Help
Powered by ViewVC 1.1.5