/[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 1411 by ph10, Fri Dec 6 17:11:44 2013 UTC revision 1414 by zherczeg, Sun Dec 22 16:27:35 2013 UTC
# Line 3206  if (firstline) Line 3206  if (firstline)
3206    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3207  }  }
3208    
3209  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks);
3210    
3211  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, pcre_uint8 *start_bits, BOOL firstline)
3212  {  {
3213  DEFINE_COMPILER;  DEFINE_COMPILER;
3214  struct sljit_label *start;  struct sljit_label *start;
3215  struct sljit_jump *quit;  struct sljit_jump *quit;
3216  struct sljit_jump *found = NULL;  struct sljit_jump *found = NULL;
3217  jump_list *matches = NULL;  jump_list *matches = NULL;
 pcre_uint8 inverted_start_bits[32];  
 int i;  
3218  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3219  struct sljit_jump *jump;  struct sljit_jump *jump;
3220  #endif  #endif
3221    
 for (i = 0; i < 32; ++i)  
   inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);  
   
3222  if (firstline)  if (firstline)
3223    {    {
3224    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
# Line 3239  if (common->utf) Line 3234  if (common->utf)
3234    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3235  #endif  #endif
3236    
3237  if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))  if (!check_class_ranges(common, start_bits, (start_bits[31] & 0x80) != 0, TRUE, &matches))
3238    {    {
3239  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3240    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
# Line 3248  if (!check_class_ranges(common, inverted Line 3243  if (!check_class_ranges(common, inverted
3243  #endif  #endif
3244    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3245    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3246    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
3247    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3248    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
3249    found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
# Line 3524  switch(ranges[0]) Line 3519  switch(ranges[0])
3519    case 2:    case 2:
3520    if (readch)    if (readch)
3521      read_char(common);      read_char(common);
3522    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);    if (ranges[2] + 1 != ranges[3])
3523    add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));      {
3524        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3525        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3526        }
3527      else
3528        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3529      return TRUE;
3530    
3531      case 3:
3532      if (readch)
3533        read_char(common);
3534      if (ranges[1] != 0)
3535        {
3536        add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3537        if (ranges[2] + 1 != ranges[3])
3538          {
3539          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3540          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3541          }
3542        else
3543          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3544        }
3545      else
3546        {
3547        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2]));
3548        if (ranges[3] + 1 != ranges[4])
3549          {
3550          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[3]);
3551          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[3]));
3552          }
3553        else
3554          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3]));
3555        }
3556    return TRUE;    return TRUE;
3557    
3558    case 4:    case 4:
# Line 3592  if (bit != 0) Line 3619  if (bit != 0)
3619  ranges[0] = length;  ranges[0] = length;
3620  }  }
3621    
3622  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks)
3623  {  {
3624  int ranges[2 + MAX_RANGE_SIZE];  int ranges[2 + MAX_RANGE_SIZE];
3625  pcre_uint8 bit, cbit, all;  pcre_uint8 bit, cbit, all;
3626  int i, byte, length = 0;  int i, byte, length = 0;
3627    
3628  bit = bits[0] & 0x1;  bit = bits[0] & 0x1;
3629  ranges[1] = bit;  ranges[1] = !invert ? bit : (bit ^ 0x1);
3630  /* Can be 0 or 255. */  /* All bits will be zero or one (since bit is zero or one). */
3631  all = -bit;  all = -bit;
3632    
3633  for (i = 0; i < 256; )  for (i = 0; i < 256; )
# Line 4021  static void compile_xclass_matchingpath( Line 4048  static void compile_xclass_matchingpath(
4048  {  {
4049  DEFINE_COMPILER;  DEFINE_COMPILER;
4050  jump_list *found = NULL;  jump_list *found = NULL;
4051  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;
4052  pcre_int32 c, charoffset;  pcre_int32 c, charoffset;
4053  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4054  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
# Line 4040  pcre_int32 typeoffset; Line 4067  pcre_int32 typeoffset;
4067  detect_partial_match(common, backtracks);  detect_partial_match(common, backtracks);
4068  read_char(common);  read_char(common);
4069    
4070  if ((*cc++ & XCL_MAP) != 0)  cc++;
4071    if ((cc[-1] & XCL_HASPROP) == 0)
4072    {    {
4073    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    if ((cc[-1] & XCL_MAP) != 0)
4074  #ifndef COMPILE_PCRE8      {
4075    jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4076  #elif defined SUPPORT_UTF  #ifdef SUPPORT_UCP
4077    if (common->utf)      charsaved = TRUE;
     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
4078  #endif  #endif
4079        if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, FALSE, backtracks))
4080          {
4081          jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4082    
4083    if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, list))        OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4084          OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4085          OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4086          OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4087          OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4088          add_jump(compiler, &found, JUMP(SLJIT_C_NOT_ZERO));
4089          add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4090    
4091          JUMPHERE(jump);
4092          }
4093        else
4094          add_jump(compiler, &found, CMP(SLJIT_C_LESS_EQUAL, TMP3, 0, SLJIT_IMM, 0xff));
4095    
4096        OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
4097        cc += 32 / sizeof(pcre_uchar);
4098        }
4099      else
4100        add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0xff));
4101      }
4102    else if ((cc[-1] & XCL_MAP) != 0)
4103      {
4104      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4105    #ifdef SUPPORT_UCP
4106      charsaved = TRUE;
4107    #endif
4108      if (!check_class_ranges(common, (const pcre_uint8 *)cc, FALSE, TRUE, list))
4109      {      {
4110    #ifdef COMPILE_PCRE8
4111        SLJIT_ASSERT(common->utf);
4112    #endif
4113        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4114    
4115      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4116      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4117      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4118      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4119      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4120      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
     }  
4121    
 #ifndef COMPILE_PCRE8  
   JUMPHERE(jump);  
 #elif defined SUPPORT_UTF  
   if (common->utf)  
4122      JUMPHERE(jump);      JUMPHERE(jump);
4123  #endif      }
4124    
4125    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
 #ifdef SUPPORT_UCP  
   charsaved = TRUE;  
 #endif  
4126    cc += 32 / sizeof(pcre_uchar);    cc += 32 / sizeof(pcre_uchar);
4127    }    }
4128    
# Line 4624  switch(type) Line 4677  switch(type)
4677  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4678    case OP_NOTPROP:    case OP_NOTPROP:
4679    case OP_PROP:    case OP_PROP:
4680    propdata[0] = 0;    propdata[0] = XCL_HASPROP;
4681    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;
4682    propdata[2] = cc[0];    propdata[2] = cc[0];
4683    propdata[3] = cc[1];    propdata[3] = cc[1];
# Line 4983  switch(type) Line 5036  switch(type)
5036    case OP_NCLASS:    case OP_NCLASS:
5037    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5038    read_char(common);    read_char(common);
5039    if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, backtracks))    if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, FALSE, backtracks))
5040      return cc + 32 / sizeof(pcre_uchar);      return cc + 32 / sizeof(pcre_uchar);
5041    
5042  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
# Line 9218  if ((re->options & PCRE_ANCHORED) == 0) Line 9271  if ((re->options & PCRE_ANCHORED) == 0)
9271      else if ((re->flags & PCRE_STARTLINE) != 0)      else if ((re->flags & PCRE_STARTLINE) != 0)
9272        fast_forward_newline(common, (re->options & PCRE_FIRSTLINE) != 0);        fast_forward_newline(common, (re->options & PCRE_FIRSTLINE) != 0);
9273      else if ((re->flags & PCRE_STARTLINE) == 0 && study != NULL && (study->flags & PCRE_STUDY_MAPPED) != 0)      else if ((re->flags & PCRE_STARTLINE) == 0 && study != NULL && (study->flags & PCRE_STUDY_MAPPED) != 0)
9274        fast_forward_start_bits(common, (sljit_uw)study->start_bits, (re->options & PCRE_FIRSTLINE) != 0);        fast_forward_start_bits(common, study->start_bits, (re->options & PCRE_FIRSTLINE) != 0);
9275      }      }
9276    }    }
9277  else  else

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

  ViewVC Help
Powered by ViewVC 1.1.5