/[pcre]/code/tags/pcre-8.37/pcre_jit_compile.c
ViewVC logotype

Diff of /code/tags/pcre-8.37/pcre_jit_compile.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1338 by zherczeg, Fri Jun 14 07:54:36 2013 UTC revision 1424 by zherczeg, Tue Dec 31 11:22:31 2013 UTC
# Line 306  typedef struct then_trap_backtrack { Line 306  typedef struct then_trap_backtrack {
306    int framesize;    int framesize;
307  } then_trap_backtrack;  } then_trap_backtrack;
308    
309  #define MAX_RANGE_SIZE 6  #define MAX_RANGE_SIZE 4
310    
311  typedef struct compiler_common {  typedef struct compiler_common {
312    /* The sljit ceneric compiler. */    /* The sljit ceneric compiler. */
# 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. */
373    sljit_sw ctypes;    sljit_sw ctypes;
   int digits[2 + MAX_RANGE_SIZE];  
374    /* Named capturing brackets. */    /* Named capturing brackets. */
375    sljit_uw name_table;    pcre_uchar *name_table;
376    sljit_sw name_count;    sljit_sw name_count;
377    sljit_sw name_entry_size;    sljit_sw name_entry_size;
378    
# Line 404  typedef struct compiler_common { Line 405  typedef struct compiler_common {
405  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
406    BOOL use_ucp;    BOOL use_ucp;
407  #endif  #endif
 #ifndef COMPILE_PCRE32  
   jump_list *utfreadchar;  
 #endif  
408  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
409      jump_list *utfreadchar;
410      jump_list *utfreadchar16;
411    jump_list *utfreadtype8;    jump_list *utfreadtype8;
412  #endif  #endif
413  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
# 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 524  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 533  cc += 1 + LINK_SIZE; Line 535  cc += 1 + LINK_SIZE;
535  return cc;  return cc;
536  }  }
537    
538    static int ones_in_half_byte[16] = {
539      /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
540      /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
541    };
542    
543  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
544   next_opcode   next_opcode
545   check_opcode_types   check_opcode_types
# Line 585  switch(*cc) Line 592  switch(*cc)
592    case OP_CRMINQUERY:    case OP_CRMINQUERY:
593    case OP_CRRANGE:    case OP_CRRANGE:
594    case OP_CRMINRANGE:    case OP_CRMINRANGE:
595      case OP_CRPOSSTAR:
596      case OP_CRPOSPLUS:
597      case OP_CRPOSQUERY:
598      case OP_CRPOSRANGE:
599    case OP_CLASS:    case OP_CLASS:
600    case OP_NCLASS:    case OP_NCLASS:
601    case OP_REF:    case OP_REF:
602    case OP_REFI:    case OP_REFI:
603      case OP_DNREF:
604      case OP_DNREFI:
605    case OP_RECURSE:    case OP_RECURSE:
606    case OP_CALLOUT:    case OP_CALLOUT:
607    case OP_ALT:    case OP_ALT:
# Line 614  switch(*cc) Line 627  switch(*cc)
627    case OP_SCBRAPOS:    case OP_SCBRAPOS:
628    case OP_SCOND:    case OP_SCOND:
629    case OP_CREF:    case OP_CREF:
630    case OP_NCREF:    case OP_DNCREF:
631    case OP_RREF:    case OP_RREF:
632    case OP_NRREF:    case OP_DNRREF:
633    case OP_DEF:    case OP_DEF:
634    case OP_BRAZERO:    case OP_BRAZERO:
635    case OP_BRAMINZERO:    case OP_BRAMINZERO:
# Line 736  switch(*cc) Line 749  switch(*cc)
749    
750  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)
751  {  {
752  pcre_uchar *name;  int count;
753  pcre_uchar *name2;  pcre_uchar *slot;
 unsigned int cbra_index;  
 int i;  
754    
755  /* 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. */
756  while (cc < ccend)  while (cc < ccend)
# Line 773  while (cc < ccend) Line 784  while (cc < ccend)
784      break;      break;
785    
786      case OP_CREF:      case OP_CREF:
787      i = GET2(cc, 1);      common->optimized_cbracket[GET2(cc, 1)] = 0;
     common->optimized_cbracket[i] = 0;  
788      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
789      break;      break;
790    
791      case OP_NCREF:      case OP_DNREF:
792      cbra_index = GET2(cc, 1);      case OP_DNREFI:
793      name = (pcre_uchar *)common->name_table;      case OP_DNCREF:
794      name2 = name;      count = GET2(cc, 1 + IMM2_SIZE);
795      for (i = 0; i < common->name_count; i++)      slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
796        {      while (count-- > 0)
797        if (GET2(name, 0) == cbra_index) break;        {
798        name += common->name_entry_size;        common->optimized_cbracket[GET2(slot, 0)] = 0;
799        }        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;  
800        }        }
801      cc += 1 + IMM2_SIZE;      cc += 1 + 2 * IMM2_SIZE;
802      break;      break;
803    
804      case OP_RECURSE:      case OP_RECURSE:
# Line 2461  else Line 2464  else
2464  JUMPHERE(jump);  JUMPHERE(jump);
2465  }  }
2466    
2467  static void read_char(compiler_common *common)  static void peek_char(compiler_common *common)
2468  {  {
2469  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2470  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2471  DEFINE_COMPILER;  DEFINE_COMPILER;
2472  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
# Line 2471  struct sljit_jump *jump; Line 2474  struct sljit_jump *jump;
2474  #endif  #endif
2475    
2476  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2477  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2478  if (common->utf)  if (common->utf)
2479    {    {
 #if defined COMPILE_PCRE8  
2480    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2481  #elif defined COMPILE_PCRE16    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
   jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);  
 #endif /* COMPILE_PCRE[8|16] */  
2482    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2483      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2484    JUMPHERE(jump);    JUMPHERE(jump);
2485    }    }
2486  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2487    
2488    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2489    if (common->utf)
2490      {
2491      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2492      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2493      /* TMP2 contains the high surrogate. */
2494      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2495      OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2496      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2497      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2498      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2499      JUMPHERE(jump);
2500      }
2501    #endif
2502    }
2503    
2504    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2505    
2506    static BOOL is_char7_bitset(const pcre_uint8* bitset, BOOL nclass)
2507    {
2508    /* Tells whether the character codes below 128 are enough
2509    to determine a match. */
2510    const pcre_uint8 value = nclass ? 0xff : 0;
2511    const pcre_uint8* end = bitset + 32;
2512    
2513    bitset += 16;
2514    do
2515      {
2516      if (*bitset++ != value)
2517        return FALSE;
2518      }
2519    while (bitset < end);
2520    return TRUE;
2521    }
2522    
2523    static void read_char7_type(compiler_common *common, BOOL full_read)
2524    {
2525    /* Reads the precise character type of a character into TMP1, if the character
2526    is less than 128. Otherwise it returns with zero. Does not check STR_END. The
2527    full_read argument tells whether characters above max are accepted or not. */
2528    DEFINE_COMPILER;
2529    struct sljit_jump *jump;
2530    
2531    SLJIT_ASSERT(common->utf);
2532    
2533    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2534  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2535    
2536    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2537    
2538    if (full_read)
2539      {
2540      jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2541      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2542      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2543      JUMPHERE(jump);
2544      }
2545  }  }
2546    
2547  static void peek_char(compiler_common *common)  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2548    
2549    static void read_char_max(compiler_common *common, pcre_uint32 max, BOOL full_read)
2550  {  {
2551  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the precise value of a character into TMP1, if the character is
2552  Does not check STR_END. TMP2 Destroyed. */  less than or equal to max. Otherwise it returns with a value greater than max.
2553    Does not check STR_END. The full_read argument tells whether characters above
2554    max are accepted or not. */
2555  DEFINE_COMPILER;  DEFINE_COMPILER;
2556  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2557  struct sljit_jump *jump;  struct sljit_jump *jump;
2558  #endif  #endif
2559    
2560    SLJIT_UNUSED_ARG(full_read);
2561    SLJIT_UNUSED_ARG(max);
2562    
2563  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2564  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2565    
2566    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2567  if (common->utf)  if (common->utf)
2568    {    {
2569  #if defined COMPILE_PCRE8    if (max < 128 && !full_read)
2570        return;
2571    
2572    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2573  #elif defined COMPILE_PCRE16    if (max >= 0x800)
2574    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2575  #endif /* COMPILE_PCRE[8|16] */    else if (max < 128)
2576    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));      {
2577    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2578        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2579        }
2580      else
2581        {
2582        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2583        if (!full_read)
2584          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2585        else
2586          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2587        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2588        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2589        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2590        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2591        if (full_read)
2592          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2593        }
2594    JUMPHERE(jump);    JUMPHERE(jump);
2595    }    }
2596  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  #endif
2597    
2598    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2599    if (common->utf)
2600      {
2601      if (max >= 0x10000)
2602        {
2603        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2604        jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2605        /* TMP2 contains the high surrogate. */
2606        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2607        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2608        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2609        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2610        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2611        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2612        JUMPHERE(jump);
2613        return;
2614        }
2615    
2616      if (max < 0xd800 && !full_read)
2617        return;
2618    
2619      /* Skip low surrogate if necessary. */
2620      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2621      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2622      if (full_read)
2623        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2624      if (max >= 0xd800)
2625        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);
2626      JUMPHERE(jump);
2627      }
2628    #endif
2629    }
2630    
2631    static SLJIT_INLINE void read_char(compiler_common *common)
2632    {
2633    read_char_max(common, READ_CHAR_ANY, TRUE);
2634  }  }
2635    
2636  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common, BOOL full_read)
2637  {  {
2638  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END.
2639    The full_read argument tells whether characters above max are accepted or not. */
2640  DEFINE_COMPILER;  DEFINE_COMPILER;
2641  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2642  struct sljit_jump *jump;  struct sljit_jump *jump;
2643  #endif  #endif
2644    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2645    struct sljit_jump *jump2;
2646    #endif
2647    
2648  #ifdef SUPPORT_UTF  SLJIT_UNUSED_ARG(full_read);
2649    
2650    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2651    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2652    
2653    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2654  if (common->utf)  if (common->utf)
2655    {    {
   OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 #if defined COMPILE_PCRE8  
2656    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2657    it is needed in most cases. */    it is needed in most cases. */
2658    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2659    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2660    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    if (!full_read)
2661    JUMPHERE(jump);      {
2662  #elif defined COMPILE_PCRE16      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2663    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2664    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2665    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2666    JUMPHERE(jump);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2667    /* Skip low surrogate if necessary. */      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
2668    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2669    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);      jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2670    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2671    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);      JUMPHERE(jump2);
2672    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);      }
2673  #elif defined COMPILE_PCRE32    else
2674    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);      add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
   jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  
2675    JUMPHERE(jump);    JUMPHERE(jump);
 #endif /* COMPILE_PCRE[8|16|32] */  
2676    return;    return;
2677    }    }
2678  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2679  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
2680  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  #if !defined COMPILE_PCRE8
 #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  
2681  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2682  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2683  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2684  #endif  #endif
2685  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2686  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if !defined COMPILE_PCRE8
2687  JUMPHERE(jump);  JUMPHERE(jump);
2688  #endif  #endif
2689    
2690    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2691    if (common->utf && full_read)
2692      {
2693      /* Skip low surrogate if necessary. */
2694      OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2695      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2696      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2697      JUMPHERE(jump);
2698      }
2699    #endif /* SUPPORT_UTF && COMPILE_PCRE16 */
2700  }  }
2701    
2702  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
# Line 2599  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 2630  else Line 2772  else
2772  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2773  {  {
2774  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2775  of the character (>= 0xc0). Return char value in TMP1, length - 1 in TMP2. */  of the character (>= 0xc0). Return char value in TMP1, length in TMP2. */
2776  DEFINE_COMPILER;  DEFINE_COMPILER;
2777  struct sljit_jump *jump;  struct sljit_jump *jump;
2778    
2779  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2780    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2781    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2782    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2783    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2784    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2785    
2786  /* Searching for the first zero. */  /* Searching for the first zero. */
2787  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2788  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2789  /* Two byte sequence. */  /* Two byte sequence. */
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
2790  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2791  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2792    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2793    
2794    JUMPHERE(jump);
2795    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2796    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2797  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2798  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2799  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 JUMPHERE(jump);  
2800    
2801  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2802  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2803  /* Three byte sequence. */  /* Three byte sequence. */
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  
2804  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2805  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));  
2806  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2807    
2808  /* Four byte sequence. */  /* Four byte sequence. */
2809  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  JUMPHERE(jump);
2810  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2811  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2812    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2813    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2814  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  
2815  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2816  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(4));
2817    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2818    }
2819    
2820    static void do_utfreadchar16(compiler_common *common)
2821    {
2822    /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2823    of the character (>= 0xc0). Return value in TMP1. */
2824    DEFINE_COMPILER;
2825    struct sljit_jump *jump;
2826    
2827    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2828    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2829    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2830    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2831  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
2832  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2833  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));  
2834  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));  /* Searching for the first zero. */
2835    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2836    jump = JUMP(SLJIT_C_NOT_ZERO);
2837    /* Two byte sequence. */
2838    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2839    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2840    
2841    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));
2847    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2848    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2849  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2850  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2851  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));  /* Three byte sequence. */
2852    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2853  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2854  }  }
2855    
# Line 2701  jump = JUMP(SLJIT_C_NOT_ZERO); Line 2869  jump = JUMP(SLJIT_C_NOT_ZERO);
2869  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2870  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2871  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
2872    /* The upper 5 bits are known at this point. */
2873    compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x3);
2874  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2875  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2876  OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);  OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
 compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  
2877  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2878  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2879    
2880  JUMPHERE(compare);  JUMPHERE(compare);
2881  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2882  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2883    
2884  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
 OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 }  
   
 #elif defined COMPILE_PCRE16  
   
 static void do_utfreadchar(compiler_common *common)  
 {  
 /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char  
 of the character (>= 0xd800). Return char value in TMP1, length - 1 in TMP2. */  
 DEFINE_COMPILER;  
 struct sljit_jump *jump;  
   
 sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  
 jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);  
 /* Do nothing, only return. */  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
   
2885  JUMPHERE(jump);  JUMPHERE(jump);
2886  /* Combine two 16 bit characters. */  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2887  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2888  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3ff);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  
2889  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2890  }  }
2891    
2892  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE8 */
2893    
2894  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2895    
# Line 2822  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 2898  if (newlinecheck) Line 3040  if (newlinecheck)
3040  return mainloop;  return mainloop;
3041  }  }
3042    
3043  #define MAX_N_CHARS 3  static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, int max_chars)
   
 static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)  
3044  {  {
3045  DEFINE_COMPILER;  /* Recursive function, which scans prefix literals. */
3046  struct sljit_label *start;  int len, repeat, len_save, consumed = 0;
3047  struct sljit_jump *quit;  pcre_uint32 caseless, chr, mask;
3048  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uchar *alternative, *cc_save;
3049  pcre_uchar *cc = common->start + 1 + LINK_SIZE;  BOOL last, any;
 int location = 0;  
 pcre_int32 len, c, bit, caseless;  
 int must_stop;  
   
 /* We do not support alternatives now. */  
 if (*(common->start + GET(common->start, 1)) == OP_ALT)  
   return FALSE;  
3050    
3051    repeat = 1;
3052  while (TRUE)  while (TRUE)
3053    {    {
3054      last = TRUE;
3055      any = FALSE;
3056    caseless = 0;    caseless = 0;
3057    must_stop = 1;    switch (*cc)
   switch(*cc)  
3058      {      {
     case OP_CHAR:  
     must_stop = 0;  
     cc++;  
     break;  
   
3059      case OP_CHARI:      case OP_CHARI:
3060      caseless = 1;      caseless = 1;
3061      must_stop = 0;      case OP_CHAR:
3062        last = FALSE;
3063      cc++;      cc++;
3064      break;      break;
3065    
# Line 2953  while (TRUE) Line 3084  while (TRUE)
3084      cc++;      cc++;
3085      break;      break;
3086    
3087        case OP_EXACTI:
3088        caseless = 1;
3089      case OP_EXACT:      case OP_EXACT:
3090        repeat = GET2(cc, 1);
3091        last = FALSE;
3092      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
3093      break;      break;
3094    
# Line 2964  while (TRUE) Line 3099  while (TRUE)
3099      cc++;      cc++;
3100      break;      break;
3101    
3102      case OP_EXACTI:      case OP_KET:
3103      caseless = 1;      cc += 1 + LINK_SIZE;
3104      cc += 1 + IMM2_SIZE;      continue;
     break;  
   
     default:  
     must_stop = 2;  
     break;  
     }  
   
   if (must_stop == 2)  
       break;  
3105    
3106    len = 1;      case OP_ALT:
3107  #ifdef SUPPORT_UTF      cc += GET(cc, 1);
3108    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);      continue;
 #endif  
3109    
3110    if (caseless && char_has_othercase(common, cc))      case OP_ONCE:
3111      {      case OP_ONCE_NC:
3112        case OP_BRA:
3113        case OP_BRAPOS:
3114        case OP_CBRA:
3115        case OP_CBRAPOS:
3116        alternative = cc + GET(cc, 1);
3117        while (*alternative == OP_ALT)
3118          {
3119          max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, max_chars);
3120          if (max_chars == 0)
3121            return consumed;
3122          alternative += GET(alternative, 1);
3123          }
3124    
3125        if (*cc == OP_CBRA || *cc == OP_CBRAPOS)
3126          cc += IMM2_SIZE;
3127        cc += 1 + LINK_SIZE;
3128        continue;
3129    
3130        case OP_CLASS:
3131        case OP_NCLASS:
3132        any = TRUE;
3133        cc += 1 + 32 / sizeof(pcre_uchar);
3134        break;
3135    
3136    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3137        case OP_XCLASS:
3138        any = TRUE;
3139        cc += GET(cc, 1);
3140        break;
3141    #endif
3142    
3143        case OP_NOT_DIGIT:
3144        case OP_DIGIT:
3145        case OP_NOT_WHITESPACE:
3146        case OP_WHITESPACE:
3147        case OP_NOT_WORDCHAR:
3148        case OP_WORDCHAR:
3149        case OP_ANY:
3150        case OP_ALLANY:
3151        any = TRUE;
3152        cc++;
3153        break;
3154    
3155    #ifdef SUPPORT_UCP
3156        case OP_NOTPROP:
3157        case OP_PROP:
3158        any = TRUE;
3159        cc += 1 + 2;
3160        break;
3161    #endif
3162    
3163        case OP_TYPEEXACT:
3164        repeat = GET2(cc, 1);
3165        cc += 1 + IMM2_SIZE;
3166        continue;
3167    
3168        default:
3169        return consumed;
3170        }
3171    
3172      if (any)
3173        {
3174    #ifdef SUPPORT_UTF
3175        if (common->utf) return consumed;
3176    #endif
3177    #if defined COMPILE_PCRE8
3178        mask = 0xff;
3179    #elif defined COMPILE_PCRE16
3180        mask = 0xffff;
3181    #elif defined COMPILE_PCRE32
3182        mask = 0xffffffff;
3183    #else
3184        SLJIT_ASSERT_STOP();
3185    #endif
3186    
3187        do
3188          {
3189          chars[0] = mask;
3190          chars[1] = mask;
3191    
3192          if (--max_chars == 0)
3193            return consumed;
3194          consumed++;
3195          chars += 2;
3196          }
3197        while (--repeat > 0);
3198    
3199        repeat = 1;
3200        continue;
3201        }
3202    
3203      len = 1;
3204    #ifdef SUPPORT_UTF
3205      if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3206    #endif
3207    
3208      if (caseless != 0 && char_has_othercase(common, cc))
3209        {
3210      caseless = char_get_othercase_bit(common, cc);      caseless = char_get_othercase_bit(common, cc);
3211      if (caseless == 0)      if (caseless == 0)
3212        return FALSE;        return consumed;
3213  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3214      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
3215  #else  #else
# Line 2999  while (TRUE) Line 3222  while (TRUE)
3222    else    else
3223      caseless = 0;      caseless = 0;
3224    
3225    while (len > 0 && location < MAX_N_CHARS * 2)    len_save = len;
3226      {    cc_save = cc;
3227      c = *cc;    while (TRUE)
3228      bit = 0;      {
3229      if (len == (caseless & 0xff))      do
3230        {        {
3231        bit = caseless >> 8;        chr = *cc;
3232        c |= bit;  #ifdef COMPILE_PCRE32
3233          if (SLJIT_UNLIKELY(chr == NOTACHAR))
3234            return consumed;
3235    #endif
3236          mask = 0;
3237          if ((pcre_uint32)len == (caseless & 0xff))
3238            {
3239            mask = caseless >> 8;
3240            chr |= mask;
3241            }
3242    
3243          if (chars[0] == NOTACHAR)
3244            {
3245            chars[0] = chr;
3246            chars[1] = mask;
3247            }
3248          else
3249            {
3250            mask |= chars[0] ^ chr;
3251            chr |= mask;
3252            chars[0] = chr;
3253            chars[1] |= mask;
3254            }
3255    
3256          len--;
3257          if (--max_chars == 0)
3258            return consumed;
3259          consumed++;
3260          chars += 2;
3261          cc++;
3262        }        }
3263        while (len > 0);
3264    
3265      chars[location] = c;      if (--repeat == 0)
3266      chars[location + 1] = bit;        break;
3267    
3268      len--;      len = len_save;
3269      location += 2;      cc = cc_save;
3270      cc++;      }
3271    
3272      repeat = 1;
3273      if (last)
3274        return consumed;
3275      }
3276    }
3277    
3278    #define MAX_N_CHARS 16
3279    
3280    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3281    {
3282    DEFINE_COMPILER;
3283    struct sljit_label *start;
3284    struct sljit_jump *quit;
3285    pcre_uint32 chars[MAX_N_CHARS * 2];
3286    pcre_uint8 ones[MAX_N_CHARS];
3287    pcre_uint32 mask;
3288    int i, max;
3289    int offsets[3];
3290    
3291    for (i = 0; i < MAX_N_CHARS; i++)
3292      {
3293      chars[i << 1] = NOTACHAR;
3294      chars[(i << 1) + 1] = 0;
3295      }
3296    
3297    max = scan_prefix(common, common->start, chars, MAX_N_CHARS);
3298    
3299    if (max <= 1)
3300      return FALSE;
3301    
3302    for (i = 0; i < max; i++)
3303      {
3304      mask = chars[(i << 1) + 1];
3305      ones[i] = ones_in_half_byte[mask & 0xf];
3306      mask >>= 4;
3307      while (mask != 0)
3308        {
3309        ones[i] += ones_in_half_byte[mask & 0xf];
3310        mask >>= 4;
3311      }      }
3312      }
3313    
3314    if (location >= MAX_N_CHARS * 2 || must_stop != 0)  offsets[0] = -1;
3315    /* Scan forward. */
3316    for (i = 0; i < max; i++)
3317      if (ones[i] <= 2) {
3318        offsets[0] = i;
3319      break;      break;
3320    }    }
3321    
3322  /* At least two characters are required. */  if (offsets[0] == -1)
3323  if (location < 2 * 2)    return FALSE;
3324      return FALSE;  
3325    /* Scan backward. */
3326    offsets[1] = -1;
3327    for (i = max - 1; i > offsets[0]; i--)
3328      if (ones[i] <= 2) {
3329        offsets[1] = i;
3330        break;
3331      }
3332    
3333    offsets[2] = -1;
3334    if (offsets[1] >= 0)
3335      {
3336      /* Scan from middle. */
3337      for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3338        if (ones[i] <= 2)
3339          {
3340          offsets[2] = i;
3341          break;
3342          }
3343    
3344      if (offsets[2] == -1)
3345        {
3346        for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3347          if (ones[i] <= 2)
3348            {
3349            offsets[2] = i;
3350            break;
3351            }
3352        }
3353      }
3354    
3355    SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3356    SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3357    
3358    chars[0] = chars[offsets[0] << 1];
3359    chars[1] = chars[(offsets[0] << 1) + 1];
3360    if (offsets[2] >= 0)
3361      {
3362      chars[2] = chars[offsets[2] << 1];
3363      chars[3] = chars[(offsets[2] << 1) + 1];
3364      }
3365    if (offsets[1] >= 0)
3366      {
3367      chars[4] = chars[offsets[1] << 1];
3368      chars[5] = chars[(offsets[1] << 1) + 1];
3369      }
3370    
3371    max -= 1;
3372  if (firstline)  if (firstline)
3373    {    {
3374    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3375    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3376    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS(max));
3377    }    }
3378  else  else
3379    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3380    
3381  start = LABEL();  start = LABEL();
3382  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3383    
3384  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
3385  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  if (offsets[1] >= 0)
3386      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3387  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3388    
3389  if (chars[1] != 0)  if (chars[1] != 0)
3390    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3391  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3392  if (location > 2 * 2)  if (offsets[2] >= 0)
3393    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));
3394  if (chars[3] != 0)  
3395    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);  if (offsets[1] >= 0)
 CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);  
 if (location > 2 * 2)  
3396    {    {
3397    if (chars[5] != 0)    if (chars[5] != 0)
3398      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3399    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
3400      }
3401    
3402    if (offsets[2] >= 0)
3403      {
3404      if (chars[3] != 0)
3405        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3406      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3407    }    }
3408  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));
3409    
# Line 3061  JUMPHERE(quit); Line 3412  JUMPHERE(quit);
3412  if (firstline)  if (firstline)
3413    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3414  else  else
3415    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3416  return TRUE;  return TRUE;
3417  }  }
3418    
# Line 3181  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 3210  if (firstline) Line 3561  if (firstline)
3561    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3562  }  }
3563    
3564  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);
3565    
3566  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)
3567  {  {
3568  DEFINE_COMPILER;  DEFINE_COMPILER;
3569  struct sljit_label *start;  struct sljit_label *start;
3570  struct sljit_jump *quit;  struct sljit_jump *quit;
3571  struct sljit_jump *found = NULL;  struct sljit_jump *found = NULL;
3572  jump_list *matches = NULL;  jump_list *matches = NULL;
 pcre_uint8 inverted_start_bits[32];  
 int i;  
3573  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3574  struct sljit_jump *jump;  struct sljit_jump *jump;
3575  #endif  #endif
3576    
 for (i = 0; i < 32; ++i)  
   inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);  
   
3577  if (firstline)  if (firstline)
3578    {    {
3579    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
# Line 3243  if (common->utf) Line 3589  if (common->utf)
3589    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3590  #endif  #endif
3591    
3592  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))
3593    {    {
3594  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3595    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
# Line 3252  if (!check_class_ranges(common, inverted Line 3598  if (!check_class_ranges(common, inverted
3598  #endif  #endif
3599    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3600    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3601    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
3602    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3603    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);
3604    found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
# Line 3501  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSE Line 3847  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSE
3847  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3848  }  }
3849    
3850  /*  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks)
   range format:  
   
   ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).  
   ranges[1] = first bit (0 or 1)  
   ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)  
 */  
   
 static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)  
3851  {  {
3852  DEFINE_COMPILER;  DEFINE_COMPILER;
3853  struct sljit_jump *jump;  int ranges[MAX_RANGE_SIZE];
   
 if (ranges[0] < 0)  
   return FALSE;  
   
 switch(ranges[0])  
   {  
   case 1:  
   if (readch)  
     read_char(common);  
   add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));  
   return TRUE;  
   
   case 2:  
   if (readch)  
     read_char(common);  
   OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);  
   add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));  
   return TRUE;  
   
   case 4:  
   if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])  
     {  
     if (readch)  
       read_char(common);  
     if (ranges[1] != 0)  
       {  
       add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));  
       add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));  
       }  
     else  
       {  
       jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);  
       add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));  
       JUMPHERE(jump);  
       }  
     return TRUE;  
     }  
   if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))  
     {  
     if (readch)  
       read_char(common);  
     OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);  
     OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);  
     add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));  
     return TRUE;  
     }  
   return FALSE;  
   
   default:  
   return FALSE;  
   }  
 }  
   
 static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)  
 {  
 int i, bit, length;  
 const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;  
   
 bit = ctypes[0] & flag;  
 ranges[0] = -1;  
 ranges[1] = bit != 0 ? 1 : 0;  
 length = 0;  
   
 for (i = 1; i < 256; i++)  
   if ((ctypes[i] & flag) != bit)  
     {  
     if (length >= MAX_RANGE_SIZE)  
       return;  
     ranges[2 + length] = i;  
     length++;  
     bit ^= flag;  
     }  
   
 if (bit != 0)  
   {  
   if (length >= MAX_RANGE_SIZE)  
     return;  
   ranges[2 + length] = 256;  
   length++;  
   }  
 ranges[0] = length;  
 }  
   
 static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)  
 {  
 int ranges[2 + MAX_RANGE_SIZE];  
3854  pcre_uint8 bit, cbit, all;  pcre_uint8 bit, cbit, all;
3855  int i, byte, length = 0;  int i, byte, length = 0;
3856    
3857  bit = bits[0] & 0x1;  bit = bits[0] & 0x1;
3858  ranges[1] = bit;  /* All bits will be zero or one (since bit is zero or one). */
 /* Can be 0 or 255. */  
3859  all = -bit;  all = -bit;
3860    
3861  for (i = 0; i < 256; )  for (i = 0; i < 256; )
# Line 3619  for (i = 0; i < 256; ) Line 3870  for (i = 0; i < 256; )
3870        {        {
3871        if (length >= MAX_RANGE_SIZE)        if (length >= MAX_RANGE_SIZE)
3872          return FALSE;          return FALSE;
3873        ranges[2 + length] = i;        ranges[length] = i;
3874        length++;        length++;
3875        bit = cbit;        bit = cbit;
3876        all = -cbit;        all = -cbit;
# Line 3632  if (((bit == 0) && nclass) || ((bit == 1 Line 3883  if (((bit == 0) && nclass) || ((bit == 1
3883    {    {
3884    if (length >= MAX_RANGE_SIZE)    if (length >= MAX_RANGE_SIZE)
3885      return FALSE;      return FALSE;
3886    ranges[2 + length] = 256;    ranges[length] = 256;
3887    length++;    length++;
3888    }    }
 ranges[0] = length;  
3889    
3890  return check_ranges(common, ranges, backtracks, FALSE);  if (length < 0 || length > 4)
3891      return FALSE;
3892    
3893    bit = bits[0] & 0x1;
3894    if (invert) bit ^= 0x1;
3895    
3896    /* No character is accepted. */
3897    if (length == 0 && bit == 0)
3898      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
3899    
3900    switch(length)
3901      {
3902      case 0:
3903      /* When bit != 0, all characters are accepted. */
3904      return TRUE;
3905    
3906      case 1:
3907      add_jump(compiler, backtracks, CMP(bit == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
3908      return TRUE;
3909    
3910      case 2:
3911      if (ranges[0] + 1 != ranges[1])
3912        {
3913        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
3914        add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
3915        }
3916      else
3917        add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
3918      return TRUE;
3919    
3920      case 3:
3921      if (bit != 0)
3922        {
3923        add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3924        if (ranges[0] + 1 != ranges[1])
3925          {
3926          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
3927          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
3928          }
3929        else
3930          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
3931        return TRUE;
3932        }
3933    
3934      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[0]));
3935      if (ranges[1] + 1 != ranges[2])
3936        {
3937        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1]);
3938        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1]));
3939        }
3940      else
3941        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1]));
3942      return TRUE;
3943    
3944      case 4:
3945      if ((ranges[1] - ranges[0]) == (ranges[3] - ranges[2])
3946          && (ranges[0] | (ranges[2] - ranges[0])) == ranges[2]
3947          && is_powerof2(ranges[2] - ranges[0]))
3948        {
3949        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[0]);
3950        if (ranges[2] + 1 != ranges[3])
3951          {
3952          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3953          add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3954          }
3955        else
3956          add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3957        return TRUE;
3958        }
3959    
3960      if (bit != 0)
3961        {
3962        i = 0;
3963        if (ranges[0] + 1 != ranges[1])
3964          {
3965          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
3966          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
3967          i = ranges[0];
3968          }
3969        else
3970          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
3971    
3972        if (ranges[2] + 1 != ranges[3])
3973          {
3974          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - i);
3975          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3976          }
3977        else
3978          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2] - i));
3979        return TRUE;
3980        }
3981    
3982      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
3983      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[0]));
3984      if (ranges[1] + 1 != ranges[2])
3985        {
3986        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]);
3987        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1]));
3988        }
3989      else
3990        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
3991      return TRUE;
3992    
3993      default:
3994      SLJIT_ASSERT_STOP();
3995      return FALSE;
3996      }
3997  }  }
3998    
3999  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
# Line 4015  return cc; Line 4371  return cc;
4371    if ((value) != charoffset) \    if ((value) != charoffset) \
4372      { \      { \
4373      if ((value) > charoffset) \      if ((value) > charoffset) \
4374        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (value) - charoffset); \        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)((value) - charoffset)); \
4375      else \      else \
4376        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, charoffset - (value)); \        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(charoffset - (value))); \
4377      } \      } \
4378    charoffset = (value);    charoffset = (value);
4379    
# Line 4025  static void compile_xclass_matchingpath( Line 4381  static void compile_xclass_matchingpath(
4381  {  {
4382  DEFINE_COMPILER;  DEFINE_COMPILER;
4383  jump_list *found = NULL;  jump_list *found = NULL;
4384  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;
4385  pcre_int32 c, charoffset;  sljit_uw c, charoffset, max = 0;
 const pcre_uint32 *other_cases;  
4386  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4387  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4388  int compares, invertcmp, numberofcmps;  int compares, invertcmp, numberofcmps;
4389    #if defined SUPPORT_UTF && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
4390    BOOL utf = common->utf;
4391    #endif
4392    
4393  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4394  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4395  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4396  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4397    const pcre_uint32 *other_cases;
4398  pcre_int32 typeoffset;  pcre_int32 typeoffset;
4399  #endif  #endif
4400    
 /* Although SUPPORT_UTF must be defined, we are  
    not necessary in utf mode even in 8 bit mode. */  
 detect_partial_match(common, backtracks);  
 read_char(common);  
   
 if ((*cc++ & XCL_MAP) != 0)  
   {  
   OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  
 #ifndef COMPILE_PCRE8  
   jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
 #elif defined SUPPORT_UTF  
   if (common->utf)  
     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
 #endif  
   
   if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, list))  
     {  
     OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);  
     OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);  
     OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);  
     OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);  
     OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);  
     add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));  
     }  
   
 #ifndef COMPILE_PCRE8  
   JUMPHERE(jump);  
 #elif defined SUPPORT_UTF  
   if (common->utf)  
     JUMPHERE(jump);  
 #endif  
   OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);  
 #ifdef SUPPORT_UCP  
   charsaved = TRUE;  
 #endif  
   cc += 32 / sizeof(pcre_uchar);  
   }  
   
4401  /* Scanning the necessary info. */  /* Scanning the necessary info. */
4402    cc++;
4403  ccbegin = cc;  ccbegin = cc;
4404  compares = 0;  compares = 0;
4405    if (cc[-1] & XCL_MAP) cc += 32 / sizeof(pcre_uchar);
4406    
4407  while (*cc != XCL_END)  while (*cc != XCL_END)
4408    {    {
4409    compares++;    compares++;
4410    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
4411      {      {
4412      cc += 2;      cc ++;
4413  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4414      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (c > max) max = c;
 #endif  
4415  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4416      needschar = TRUE;      needschar = TRUE;
4417  #endif  #endif
# Line 4098  while (*cc != XCL_END) Line 4422  while (*cc != XCL_END)
4422  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4423      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
4424  #endif  #endif
4425      cc++;      GETCHARINCTEST(c, cc);
4426  #ifdef SUPPORT_UTF      if (c > max) max = c;
     if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
4427  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4428      needschar = TRUE;      needschar = TRUE;
4429  #endif  #endif
# Line 4111  while (*cc != XCL_END) Line 4433  while (*cc != XCL_END)
4433      {      {
4434      SLJIT_ASSERT(*cc == XCL_PROP || *cc == XCL_NOTPROP);      SLJIT_ASSERT(*cc == XCL_PROP || *cc == XCL_NOTPROP);
4435      cc++;      cc++;
4436        if (*cc == PT_CLIST)
4437          {
4438          other_cases = PRIV(ucd_caseless_sets) + cc[1];
4439          while (*other_cases != NOTACHAR)
4440            {
4441            if (*other_cases > max) max = *other_cases;
4442            other_cases++;
4443            }
4444          }
4445        else
4446          max = READ_CHAR_ANY;
4447    
4448      switch(*cc)      switch(*cc)
4449        {        {
4450        case PT_ANY:        case PT_ANY:
# Line 4130  while (*cc != XCL_END) Line 4464  while (*cc != XCL_END)
4464        case PT_SPACE:        case PT_SPACE:
4465        case PT_PXSPACE:        case PT_PXSPACE:
4466        case PT_WORD:        case PT_WORD:
4467          case PT_PXGRAPH:
4468          case PT_PXPRINT:
4469          case PT_PXPUNCT:
4470        needstype = TRUE;        needstype = TRUE;
4471        needschar = TRUE;        needschar = TRUE;
4472        break;        break;
# Line 4148  while (*cc != XCL_END) Line 4485  while (*cc != XCL_END)
4485  #endif  #endif
4486    }    }
4487    
4488    /* We are not necessary in utf mode even in 8 bit mode. */
4489    cc = ccbegin;
4490    detect_partial_match(common, backtracks);
4491    read_char_max(common, max, (cc[0] & XCL_NOT) != 0);
4492    
4493    if ((cc[-1] & XCL_HASPROP) == 0)
4494      {
4495      if ((cc[-1] & XCL_MAP) != 0)
4496        {
4497        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4498        if (!check_class_ranges(common, (const pcre_uint8 *)cc, (((const pcre_uint8 *)cc)[31] & 0x80) != 0, TRUE, &found))
4499          {
4500          OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4501          OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4502          OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4503          OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4504          OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4505          add_jump(compiler, &found, JUMP(SLJIT_C_NOT_ZERO));
4506          }
4507    
4508        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4509        JUMPHERE(jump);
4510    
4511        cc += 32 / sizeof(pcre_uchar);
4512        }
4513      else
4514        add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0xff));
4515      }
4516    else if ((cc[-1] & XCL_MAP) != 0)
4517      {
4518      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4519    #ifdef SUPPORT_UCP
4520      charsaved = TRUE;
4521    #endif
4522      if (!check_class_ranges(common, (const pcre_uint8 *)cc, FALSE, TRUE, list))
4523        {
4524    #ifdef COMPILE_PCRE8
4525        SLJIT_ASSERT(common->utf);
4526    #endif
4527        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4528    
4529        OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4530        OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4531        OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4532        OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4533        OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4534        add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
4535    
4536        JUMPHERE(jump);
4537        }
4538    
4539      OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
4540      cc += 32 / sizeof(pcre_uchar);
4541      }
4542    
4543  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4544  /* Simple register allocation. TMP1 is preferred if possible. */  /* Simple register allocation. TMP1 is preferred if possible. */
4545  if (needstype || needsscript)  if (needstype || needsscript)
# Line 4189  if (needstype || needsscript) Line 4581  if (needstype || needsscript)
4581  #endif  #endif
4582    
4583  /* Generating code. */  /* Generating code. */
 cc = ccbegin;  
4584  charoffset = 0;  charoffset = 0;
4585  numberofcmps = 0;  numberofcmps = 0;
4586  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4205  while (*cc != XCL_END) Line 4596  while (*cc != XCL_END)
4596    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
4597      {      {
4598      cc ++;      cc ++;
4599  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
     if (common->utf)  
       {  
       GETCHARINC(c, cc);  
       }  
     else  
 #endif  
       c = *cc++;  
4600    
4601      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4602        {        {
4603        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(c - charoffset));
4604        OP_FLAGS(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, numberofcmps == 0 ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, numberofcmps == 0 ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_EQUAL);
4605        numberofcmps++;        numberofcmps++;
4606        }        }
4607      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4608        {        {
4609        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(c - charoffset));
4610        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4611        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4612        numberofcmps = 0;        numberofcmps = 0;
4613        }        }
4614      else      else
4615        {        {
4616        jump = CMP(SLJIT_C_EQUAL ^ invertcmp, TMP1, 0, SLJIT_IMM, c - charoffset);        jump = CMP(SLJIT_C_EQUAL ^ invertcmp, TMP1, 0, SLJIT_IMM, (sljit_sw)(c - charoffset));
4617        numberofcmps = 0;        numberofcmps = 0;
4618        }        }
4619      }      }
4620    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
4621      {      {
4622      cc ++;      cc ++;
4623  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
     if (common->utf)  
       {  
       GETCHARINC(c, cc);  
       }  
     else  
 #endif  
       c = *cc++;  
4624      SET_CHAR_OFFSET(c);      SET_CHAR_OFFSET(c);
4625  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4626      if (common->utf)  
       {  
       GETCHARINC(c, cc);  
       }  
     else  
 #endif  
       c = *cc++;  
4627      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4628        {        {
4629        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(c - charoffset));
4630        OP_FLAGS(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, numberofcmps == 0 ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, numberofcmps == 0 ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_LESS_EQUAL);
4631        numberofcmps++;        numberofcmps++;
4632        }        }
4633      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4634        {        {
4635        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(c - charoffset));
4636        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4637        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4638        numberofcmps = 0;        numberofcmps = 0;
4639        }        }
4640      else      else
4641        {        {
4642        jump = CMP(SLJIT_C_LESS_EQUAL ^ invertcmp, TMP1, 0, SLJIT_IMM, c - charoffset);        jump = CMP(SLJIT_C_LESS_EQUAL ^ invertcmp, TMP1, 0, SLJIT_IMM, (sljit_sw)(c - charoffset));
4643        numberofcmps = 0;        numberofcmps = 0;
4644        }        }
4645      }      }
# Line 4317  while (*cc != XCL_END) Line 4688  while (*cc != XCL_END)
4688    
4689        case PT_SPACE:        case PT_SPACE:
4690        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);  
         }  
4691        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4692        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);
4693        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);
4694        if (*cc == PT_SPACE)  
4695          JUMPHERE(jump);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x9);
4696          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4697    
4698          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x9);
4699          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4700    
4701        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4702        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 4335  while (*cc != XCL_END) Line 4705  while (*cc != XCL_END)
4705        break;        break;
4706    
4707        case PT_WORD:        case PT_WORD:
4708        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(CHAR_UNDERSCORE - charoffset));
4709        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4710        /* Fall through. */        /* Fall through. */
4711    
# Line 4383  while (*cc != XCL_END) Line 4753  while (*cc != XCL_END)
4753          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[2]);          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[2]);
4754          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4755    
4756          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, other_cases[0] - charoffset);          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(other_cases[0] - charoffset));
4757          OP_FLAGS(SLJIT_OR | ((other_cases[3] == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_OR | ((other_cases[3] == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4758    
4759            other_cases += 3;
4760            }
4761          else
4762            {
4763            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(*other_cases++ - charoffset));
4764            OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4765            }
4766    
4767          while (*other_cases != NOTACHAR)
4768            {
4769            OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(*other_cases++ - charoffset));
4770            OP_FLAGS(SLJIT_OR | ((*other_cases == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4771            }
4772          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4773          break;
4774    
4775          case PT_UCNC:
4776          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(CHAR_DOLLAR_SIGN - charoffset));
4777          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4778          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(CHAR_COMMERCIAL_AT - charoffset));
4779          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4780          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(CHAR_GRAVE_ACCENT - charoffset));
4781          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4782    
4783          SET_CHAR_OFFSET(0xa0);
4784          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(0xd7ff - charoffset));
4785          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4786          SET_CHAR_OFFSET(0);
4787          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
4788          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4789          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4790          break;
4791    
4792          case PT_PXGRAPH:
4793          /* C and Z groups are the farthest two groups. */
4794          SET_TYPE_OFFSET(ucp_Ll);
4795          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4796          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4797    
4798          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4799    
4800          /* In case of ucp_Cf, we overwrite the result. */
4801          SET_CHAR_OFFSET(0x2066);
4802          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4803          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4804    
4805          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4806          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4807    
4808          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x2066);
4809          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4810    
4811          JUMPHERE(jump);
4812          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4813          break;
4814    
4815          case PT_PXPRINT:
4816          /* C and Z groups are the farthest two groups. */
4817          SET_TYPE_OFFSET(ucp_Ll);
4818          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4819          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4820    
4821          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Ll);
4822          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_NOT_EQUAL);
4823    
4824          other_cases += 3;        jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
         }  
       else  
         {  
         OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);  
         OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);  
         }  
4825    
4826        while (*other_cases != NOTACHAR)        /* In case of ucp_Cf, we overwrite the result. */
4827          {        SET_CHAR_OFFSET(0x2066);
4828          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4829          OP_FLAGS(SLJIT_OR | ((*other_cases == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
         }  
       jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);  
       break;  
4830    
4831        case PT_UCNC:        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
       OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);  
       OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);  
       OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);  
       OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);  
       OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);  
4832        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4833    
4834        SET_CHAR_OFFSET(0xa0);        JUMPHERE(jump);
4835        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);        jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4836        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);        break;
4837    
4838          case PT_PXPUNCT:
4839          SET_TYPE_OFFSET(ucp_Sc);
4840          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Sc);
4841          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4842    
4843        SET_CHAR_OFFSET(0);        SET_CHAR_OFFSET(0);
4844        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xff);
4845        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);        OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4846    
4847          SET_TYPE_OFFSET(ucp_Pc);
4848          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ps - ucp_Pc);
4849          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4850        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4851        break;        break;
4852        }        }
# Line 4449  struct sljit_label *label; Line 4880  struct sljit_label *label;
4880  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4881  pcre_uchar propdata[5];  pcre_uchar propdata[5];
4882  #endif  #endif
4883  #endif  #endif /* SUPPORT_UTF */
4884    
4885  switch(type)  switch(type)
4886    {    {
# Line 4474  switch(type) Line 4905  switch(type)
4905    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
4906    case OP_DIGIT:    case OP_DIGIT:
4907    /* Digits are usually 0-9, so it is worth to optimize them. */    /* Digits are usually 0-9, so it is worth to optimize them. */
   if (common->digits[0] == -2)  
     get_ctype_ranges(common, ctype_digit, common->digits);  
4908    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4909    /* Flip the starting bit in the negative case. */  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
4910    if (type == OP_NOT_DIGIT)    if (common->utf && is_char7_bitset((const pcre_uint8*)common->ctypes - cbit_length + cbit_digit, FALSE))
4911      common->digits[1] ^= 1;      read_char7_type(common, type == OP_NOT_DIGIT);
4912    if (!check_ranges(common, common->digits, backtracks, TRUE))    else
4913      {  #endif
4914      read_char8_type(common);      read_char8_type(common, type == OP_NOT_DIGIT);
4915      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);      /* Flip the starting bit in the negative case. */
4916      add_jump(compiler, backtracks, JUMP(type == OP_DIGIT ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);
4917      }    add_jump(compiler, backtracks, JUMP(type == OP_DIGIT ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
   if (type == OP_NOT_DIGIT)  
     common->digits[1] ^= 1;  
4918    return cc;    return cc;
4919    
4920    case OP_NOT_WHITESPACE:    case OP_NOT_WHITESPACE:
4921    case OP_WHITESPACE:    case OP_WHITESPACE:
4922    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4923    read_char8_type(common);  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
4924      if (common->utf && is_char7_bitset((const pcre_uint8*)common->ctypes - cbit_length + cbit_space, FALSE))
4925        read_char7_type(common, type == OP_NOT_WHITESPACE);
4926      else
4927    #endif
4928        read_char8_type(common, type == OP_NOT_WHITESPACE);
4929    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_space);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_space);
4930    add_jump(compiler, backtracks, JUMP(type == OP_WHITESPACE ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_WHITESPACE ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
4931    return cc;    return cc;
# Line 4501  switch(type) Line 4933  switch(type)
4933    case OP_NOT_WORDCHAR:    case OP_NOT_WORDCHAR:
4934    case OP_WORDCHAR:    case OP_WORDCHAR:
4935    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4936    read_char8_type(common);  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
4937      if (common->utf && is_char7_bitset((const pcre_uint8*)common->ctypes - cbit_length + cbit_word, FALSE))
4938        read_char7_type(common, type == OP_NOT_WORDCHAR);
4939      else
4940    #endif
4941        read_char8_type(common, type == OP_NOT_WORDCHAR);
4942    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_word);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_word);
4943    add_jump(compiler, backtracks, JUMP(type == OP_WORDCHAR ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_WORDCHAR ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
4944    return cc;    return cc;
4945    
4946    case OP_ANY:    case OP_ANY:
4947    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4948    read_char(common);    read_char_max(common, common->nlmax, TRUE);
4949    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4950      {      {
4951      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 4564  switch(type) Line 5001  switch(type)
5001  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
5002    case OP_NOTPROP:    case OP_NOTPROP:
5003    case OP_PROP:    case OP_PROP:
5004    propdata[0] = 0;    propdata[0] = XCL_HASPROP;
5005    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;
5006    propdata[2] = cc[0];    propdata[2] = cc[0];
5007    propdata[3] = cc[1];    propdata[3] = cc[1];
# Line 4576  switch(type) Line 5013  switch(type)
5013    
5014    case OP_ANYNL:    case OP_ANYNL:
5015    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5016    read_char(common);    read_char_max(common, common->bsr_nlmax, FALSE);
5017    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);
5018    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
5019    end_list = NULL;    end_list = NULL;
# Line 4598  switch(type) Line 5035  switch(type)
5035    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
5036    case OP_HSPACE:    case OP_HSPACE:
5037    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5038    read_char(common);    read_char_max(common, 0x3000, type == OP_NOT_HSPACE);
5039    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));
5040    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));
5041    return cc;    return cc;
# Line 4606  switch(type) Line 5043  switch(type)
5043    case OP_NOT_VSPACE:    case OP_NOT_VSPACE:
5044    case OP_VSPACE:    case OP_VSPACE:
5045    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5046    read_char(common);    read_char_max(common, 0x2029, type == OP_NOT_VSPACE);
5047    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));
5048    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));
5049    return cc;    return cc;
# Line 4705  switch(type) Line 5142  switch(type)
5142      else      else
5143        {        {
5144        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);
5145        read_char(common);        read_char_max(common, common->nlmax, TRUE);
5146        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));
5147        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
5148        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 4753  switch(type) Line 5190  switch(type)
5190    else    else
5191      {      {
5192      skip_char_back(common);      skip_char_back(common);
5193      read_char(common);      read_char_max(common, common->nlmax, TRUE);
5194      check_newlinechar(common, common->nltype, backtracks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
5195      }      }
5196    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
# Line 4828  switch(type) Line 5265  switch(type)
5265  #endif  #endif
5266      return byte_sequence_compare(common, type == OP_CHARI, cc, &context, backtracks);      return byte_sequence_compare(common, type == OP_CHARI, cc, &context, backtracks);
5267      }      }
5268    
5269    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
   read_char(common);  
5270  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
5271    if (common->utf)    if (common->utf)
5272      {      {
# Line 4838  switch(type) Line 5275  switch(type)
5275    else    else
5276  #endif  #endif
5277      c = *cc;      c = *cc;
5278    
5279    if (type == OP_CHAR || !char_has_othercase(common, cc))    if (type == OP_CHAR || !char_has_othercase(common, cc))
5280      {      {
5281        read_char_max(common, c, FALSE);
5282      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));
5283      return cc + length;      return cc + length;
5284      }      }
5285    oc = char_othercase(common, c);    oc = char_othercase(common, c);
5286      read_char_max(common, c > oc ? c : oc, FALSE);
5287    bit = c ^ oc;    bit = c ^ oc;
5288    if (is_powerof2(bit))    if (is_powerof2(bit))
5289      {      {
# Line 4851  switch(type) Line 5291  switch(type)
5291      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));
5292      return cc + length;      return cc + length;
5293      }      }
5294    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);
5295    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));
5296    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));  
5297    return cc + length;    return cc + length;
5298    
5299    case OP_NOT:    case OP_NOT:
# Line 4890  switch(type) Line 5328  switch(type)
5328  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
5329        {        {
5330        GETCHARLEN(c, cc, length);        GETCHARLEN(c, cc, length);
       read_char(common);  
5331        }        }
5332      }      }
5333    else    else
5334  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
     {  
     read_char(common);  
5335      c = *cc;      c = *cc;
     }  
5336    
5337    if (type == OP_NOT || !char_has_othercase(common, cc))    if (type == OP_NOT || !char_has_othercase(common, cc))
5338        {
5339        read_char_max(common, c, TRUE);
5340      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c));      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c));
5341        }
5342    else    else
5343      {      {
5344      oc = char_othercase(common, c);      oc = char_othercase(common, c);
5345        read_char_max(common, c > oc ? c : oc, TRUE);
5346      bit = c ^ oc;      bit = c ^ oc;
5347      if (is_powerof2(bit))      if (is_powerof2(bit))
5348        {        {
# Line 4922  switch(type) Line 5360  switch(type)
5360    case OP_CLASS:    case OP_CLASS:
5361    case OP_NCLASS:    case OP_NCLASS:
5362    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5363    read_char(common);  
5364    if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, backtracks))  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5365      bit = (common->utf && is_char7_bitset((const pcre_uint8 *)cc, type == OP_NCLASS)) ? 127 : 255;
5366      read_char_max(common, bit, type == OP_NCLASS);
5367    #else
5368      read_char_max(common, 255, type == OP_NCLASS);
5369    #endif
5370    
5371      if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, FALSE, backtracks))
5372      return cc + 32 / sizeof(pcre_uchar);      return cc + 32 / sizeof(pcre_uchar);
5373    
5374  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5375    jump[0] = NULL;    jump[0] = NULL;
 #ifdef COMPILE_PCRE8  
   /* This check only affects 8 bit mode. In other modes, we  
   always need to compare the value with 255. */  
5376    if (common->utf)    if (common->utf)
 #endif /* COMPILE_PCRE8 */  
5377      {      {
5378      jump[0] = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump[0] = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, bit);
5379      if (type == OP_CLASS)      if (type == OP_CLASS)
5380        {        {
5381        add_jump(compiler, backtracks, jump[0]);        add_jump(compiler, backtracks, jump[0]);
5382        jump[0] = NULL;        jump[0] = NULL;
5383        }        }
5384      }      }
5385  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #elif !defined COMPILE_PCRE8
5386      jump[0] = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
5387      if (type == OP_CLASS)
5388        {
5389        add_jump(compiler, backtracks, jump[0]);
5390        jump[0] = NULL;
5391        }
5392    #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
5393    
5394    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
5395    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
5396    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
5397    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
5398    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);
5399    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
5400    
5401  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
5402    if (jump[0] != NULL)    if (jump[0] != NULL)
5403      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
5404  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif
5405    
5406    return cc + 32 / sizeof(pcre_uchar);    return cc + 32 / sizeof(pcre_uchar);
5407    
5408  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
# Line 5056  if (context.length > 0) Line 5507  if (context.length > 0)
5507  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);
5508  }  }
5509    
 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));  
 }  
   
5510  /* Forward definitions. */  /* Forward definitions. */
5511  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);
5512  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 5539  static void compile_backtrackingpath(com
5539    
5540  #define BACKTRACK_AS(type) ((type *)backtrack)  #define BACKTRACK_AS(type) ((type *)backtrack)
5541    
5542  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)
5543    {
5544    /* The OVECTOR offset goes to TMP2. */
5545    DEFINE_COMPILER;
5546    int count = GET2(cc, 1 + IMM2_SIZE);
5547    pcre_uchar *slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
5548    unsigned int offset;
5549    jump_list *found = NULL;
5550    
5551    SLJIT_ASSERT(*cc == OP_DNREF || *cc == OP_DNREFI);
5552    
5553    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
5554    
5555    count--;
5556    while (count-- > 0)
5557      {
5558      offset = GET2(slot, 0) << 1;
5559      GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5560      add_jump(compiler, &found, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5561      slot += common->name_entry_size;
5562      }
5563    
5564    offset = GET2(slot, 0) << 1;
5565    GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5566    if (backtracks != NULL && !common->jscript_compat)
5567      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5568    
5569    set_jumps(found, LABEL());
5570    }
5571    
5572    static void compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)
5573  {  {
5574  DEFINE_COMPILER;  DEFINE_COMPILER;
5575  int offset = GET2(cc, 1) << 1;  BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5576    int offset = 0;
5577  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
5578  struct sljit_jump *partial;  struct sljit_jump *partial;
5579  struct sljit_jump *nopartial;  struct sljit_jump *nopartial;
5580    
5581  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  if (ref)
5582  /* OVECTOR(1) contains the "string begin - 1" constant. */    {
5583  if (withchecks && !common->jscript_compat)    offset = GET2(cc, 1) << 1;
5584    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));
5585      /* OVECTOR(1) contains the "string begin - 1" constant. */
5586      if (withchecks && !common->jscript_compat)
5587        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5588      }
5589    else
5590      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5591    
5592  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5593  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5594    {    {
5595    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);
5596    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));    if (ref)
5597        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5598      else
5599        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5600    
5601    if (withchecks)    if (withchecks)
5602      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5603    
# Line 5152  if (common->utf && *cc == OP_REFI) Line 5622  if (common->utf && *cc == OP_REFI)
5622  else  else
5623  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
5624    {    {
5625    OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);    if (ref)
5626        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
5627      else
5628        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
5629    
5630    if (withchecks)    if (withchecks)
5631      jump = JUMP(SLJIT_C_ZERO);      jump = JUMP(SLJIT_C_ZERO);
5632    
# Line 5189  if (jump != NULL) Line 5663  if (jump != NULL)
5663    else    else
5664      JUMPHERE(jump);      JUMPHERE(jump);
5665    }    }
 return cc + 1 + IMM2_SIZE;  
5666  }  }
5667    
5668  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)
5669  {  {
5670  DEFINE_COMPILER;  DEFINE_COMPILER;
5671    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5672  backtrack_common *backtrack;  backtrack_common *backtrack;
5673  pcre_uchar type;  pcre_uchar type;
5674    int offset = 0;
5675  struct sljit_label *label;  struct sljit_label *label;
5676  struct sljit_jump *zerolength;  struct sljit_jump *zerolength;
5677  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 5206  BOOL minimize; Line 5681  BOOL minimize;
5681    
5682  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
5683    
5684    if (ref)
5685      offset = GET2(cc, 1) << 1;
5686    else
5687      cc += IMM2_SIZE;
5688  type = cc[1 + IMM2_SIZE];  type = cc[1 + IMM2_SIZE];
5689    
5690    SLJIT_COMPILE_ASSERT((OP_CRSTAR & 0x1) == 0, crstar_opcode_must_be_even);
5691  minimize = (type & 0x1) != 0;  minimize = (type & 0x1) != 0;
5692  switch(type)  switch(type)
5693    {    {
# Line 5244  if (!minimize) Line 5725  if (!minimize)
5725    if (min == 0)    if (min == 0)
5726      {      {
5727      allocate_stack(common, 2);      allocate_stack(common, 2);
5728        if (ref)
5729          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5730      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5731      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5732      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5733      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));
5734      zerolength = compile_ref_checks(common, ccbegin, NULL);      /* Handles both invalid and empty cases. Since the minimum repeat,
5735        is zero the invalid case is basically the same as an empty case. */
5736        if (ref)
5737          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5738        else
5739          {
5740          compile_dnref_search(common, ccbegin, NULL);
5741          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5742          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5743          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5744          }
5745      /* Restore if not zero length. */      /* Restore if not zero length. */
5746      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));
5747      }      }
5748    else    else
5749      {      {
5750      allocate_stack(common, 1);      allocate_stack(common, 1);
5751        if (ref)
5752          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5753      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5754      zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);      if (ref)
5755          {
5756          add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5757          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5758          }
5759        else
5760          {
5761          compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5762          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5763          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5764          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5765          }
5766      }      }
5767    
5768    if (min > 1 || max > 1)    if (min > 1 || max > 1)
5769      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
5770    
5771    label = LABEL();    label = LABEL();
5772      if (!ref)
5773        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
5774    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);
5775    
5776    if (min > 1 || max > 1)    if (min > 1 || max > 1)
# Line 5297  if (!minimize) Line 5805  if (!minimize)
5805    return cc;    return cc;
5806    }    }
5807    
5808  allocate_stack(common, 2);  allocate_stack(common, ref ? 2 : 3);
5809    if (ref)
5810      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5811  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5812  if (type != OP_CRMINSTAR)  if (type != OP_CRMINSTAR)
5813    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5814    
5815  if (min == 0)  if (min == 0)
5816    {    {
5817    zerolength = compile_ref_checks(common, ccbegin, NULL);    /* Handles both invalid and empty cases. Since the minimum repeat,
5818      is zero the invalid case is basically the same as an empty case. */
5819      if (ref)
5820        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5821      else
5822        {
5823        compile_dnref_search(common, ccbegin, NULL);
5824        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5825        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5826        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5827        }
5828      /* Length is non-zero, we can match real repeats. */
5829    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5830    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
5831    }    }
5832  else  else
5833    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);    {
5834      if (ref)
5835        {
5836        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5837        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5838        }
5839      else
5840        {
5841        compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5842        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5843        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5844        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5845        }
5846      }
5847    
5848  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5849  if (max > 0)  if (max > 0)
5850    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));
5851    
5852    if (!ref)
5853      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
5854  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);
5855  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5856    
# Line 5902  common->accept = save_accept; Line 6438  common->accept = save_accept;
6438  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
6439  }  }
6440    
 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;  
 }  
   
6441  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)
6442  {  {
6443  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 6144  backtrack_common *backtrack; Line 6570  backtrack_common *backtrack;
6570  pcre_uchar opcode;  pcre_uchar opcode;
6571  int private_data_ptr = 0;  int private_data_ptr = 0;
6572  int offset = 0;  int offset = 0;
6573  int stacksize;  int i, stacksize;
6574  int repeat_ptr = 0, repeat_length = 0;  int repeat_ptr = 0, repeat_length = 0;
6575  int repeat_type = 0, repeat_count = 0;  int repeat_type = 0, repeat_count = 0;
6576  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
6577  pcre_uchar *matchingpath;  pcre_uchar *matchingpath;
6578    pcre_uchar *slot;
6579  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
6580  pcre_uchar ket;  pcre_uchar ket;
6581  assert_backtrack *assert;  assert_backtrack *assert;
# Line 6198  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket Line 6625  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket
6625  cc += GET(cc, 1);  cc += GET(cc, 1);
6626    
6627  has_alternatives = *cc == OP_ALT;  has_alternatives = *cc == OP_ALT;
6628  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))  if (SLJIT_UNLIKELY(opcode == OP_COND || opcode == OP_SCOND))
6629    {    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);  
     }  
   }  
6630    
6631  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))
6632    opcode = OP_SCOND;    opcode = OP_SCOND;
# Line 6448  if (opcode == OP_COND || opcode == OP_SC Line 6863  if (opcode == OP_COND || opcode == OP_SC
6863        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)));
6864      matchingpath += 1 + IMM2_SIZE;      matchingpath += 1 + IMM2_SIZE;
6865      }      }
6866    else if (*matchingpath == OP_NCREF)    else if (*matchingpath == OP_DNCREF)
6867      {      {
6868      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));  
6869    
6870      JUMPHERE(jump);      i = GET2(matchingpath, 1 + IMM2_SIZE);
6871      matchingpath += 1 + IMM2_SIZE;      slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;
6872        OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
6873        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
6874        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
6875        slot += common->name_entry_size;
6876        i--;
6877        while (i-- > 0)
6878          {
6879          OP2(SLJIT_SUB, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
6880          OP2(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, STR_PTR, 0);
6881          slot += common->name_entry_size;
6882          }
6883        OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
6884        add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), JUMP(SLJIT_C_ZERO));
6885        matchingpath += 1 + 2 * IMM2_SIZE;
6886      }      }
6887    else if (*matchingpath == OP_RREF || *matchingpath == OP_NRREF)    else if (*matchingpath == OP_RREF || *matchingpath == OP_DNRREF)
6888      {      {
6889      /* Never has other case. */      /* Never has other case. */
6890      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;
6891        SLJIT_ASSERT(!has_alternatives);
6892    
6893      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)  
6894        {        {
6895        SLJIT_ASSERT(!has_alternatives);        stacksize = GET2(matchingpath, 1);
6896          if (common->currententry == NULL)
6897            stacksize = 0;
6898          else if (stacksize == RREF_ANY)
6899            stacksize = 1;
6900          else if (common->currententry->start == 0)
6901            stacksize = stacksize == 0;
6902          else
6903            stacksize = stacksize == (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6904    
6905        if (stacksize != 0)        if (stacksize != 0)
6906          matchingpath += 1 + IMM2_SIZE;          matchingpath += 1 + IMM2_SIZE;
6907          }
6908        else
6909          {
6910          if (common->currententry == NULL || common->currententry->start == 0)
6911            stacksize = 0;
6912        else        else
6913          {          {
6914            stacksize = GET2(matchingpath, 1 + IMM2_SIZE);
6915            slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;
6916            i = (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6917            while (stacksize > 0)
6918              {
6919              if ((int)GET2(slot, 0) == i)
6920                break;
6921              slot += common->name_entry_size;
6922              stacksize--;
6923              }
6924            }
6925    
6926          if (stacksize != 0)
6927            matchingpath += 1 + 2 * IMM2_SIZE;
6928          }
6929    
6930          /* The stacksize == 0 is a common "else" case. */
6931          if (stacksize == 0)
6932            {
6933          if (*cc == OP_ALT)          if (*cc == OP_ALT)
6934            {            {
6935            matchingpath = cc + 1 + LINK_SIZE;            matchingpath = cc + 1 + LINK_SIZE;
# Line 6497  if (opcode == OP_COND || opcode == OP_SC Line 6938  if (opcode == OP_COND || opcode == OP_SC
6938          else          else
6939            matchingpath = cc;            matchingpath = cc;
6940          }          }
       }  
     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;  
       }  
6941      }      }
6942    else    else
6943      {      {
# Line 6956  count_match(common); Line 7379  count_match(common);
7379  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
7380  }  }
7381    
7382  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)
7383  {  {
7384  int class_len;  int class_len;
7385    
# Line 6992  else if (*opcode >= OP_TYPESTAR && *opco Line 7415  else if (*opcode >= OP_TYPESTAR && *opco
7415    }    }
7416  else  else
7417    {    {
7418    SLJIT_ASSERT(*opcode >= OP_CLASS || *opcode <= OP_XCLASS);    SLJIT_ASSERT(*opcode == OP_CLASS || *opcode == OP_NCLASS || *opcode == OP_XCLASS);
7419    *type = *opcode;    *type = *opcode;
7420    cc++;    cc++;
7421    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 7426  else
7426      if (end != NULL)      if (end != NULL)
7427        *end = cc + class_len;        *end = cc + class_len;
7428      }      }
7429      else if (*opcode >= OP_CRPOSSTAR && *opcode <= OP_CRPOSQUERY)
7430        {
7431        *opcode -= OP_CRPOSSTAR - OP_POSSTAR;
7432        if (end != NULL)
7433          *end = cc + class_len;
7434        }
7435    else    else
7436      {      {
7437      SLJIT_ASSERT(*opcode == OP_CRRANGE || *opcode == OP_CRMINRANGE);      SLJIT_ASSERT(*opcode == OP_CRRANGE || *opcode == OP_CRMINRANGE || *opcode == OP_CRPOSRANGE);
7438      *arg1 = GET2(cc, (class_len + IMM2_SIZE));      *max = GET2(cc, (class_len + IMM2_SIZE));
7439      *arg2 = GET2(cc, class_len);      *min = GET2(cc, class_len);
7440    
7441      if (*arg2 == 0)      if (*min == 0)
7442        {        {
7443        SLJIT_ASSERT(*arg1 != 0);        SLJIT_ASSERT(*max != 0);
7444        *opcode = (*opcode == OP_CRRANGE) ? OP_UPTO : OP_MINUPTO;        *opcode = (*opcode == OP_CRRANGE) ? OP_UPTO : (*opcode == OP_CRMINRANGE ? OP_MINUPTO : OP_POSUPTO);
7445        }        }
7446      if (*arg1 == *arg2)      if (*max == *min)
7447        *opcode = OP_EXACT;        *opcode = OP_EXACT;
7448    
7449      if (end != NULL)      if (end != NULL)
# Line 7025  else Line 7454  else
7454    
7455  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)
7456    {    {
7457    *arg1 = GET2(cc, 0);    *max = GET2(cc, 0);
7458    cc += IMM2_SIZE;    cc += IMM2_SIZE;
7459    }    }
7460    
# Line 7054  DEFINE_COMPILER; Line 7483  DEFINE_COMPILER;
7483  backtrack_common *backtrack;  backtrack_common *backtrack;
7484  pcre_uchar opcode;  pcre_uchar opcode;
7485  pcre_uchar type;  pcre_uchar type;
7486  int arg1 = -1, arg2 = -1;  int max = -1, min = -1;
7487  pcre_uchar* end;  pcre_uchar* end;
7488  jump_list *nomatch = NULL;  jump_list *nomatch = NULL;
7489  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 7067  int tmp_base, tmp_offset; Line 7496  int tmp_base, tmp_offset;
7496    
7497  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
7498    
7499  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);  cc = get_iterator_parameters(common, cc, &opcode, &type, &max, &min, &end);
7500    
7501  switch(type)  switch(type)
7502    {    {
# Line 7138  switch(opcode) Line 7567  switch(opcode)
7567        {        {
7568        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);
7569        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
7570        if (opcode == OP_CRRANGE && arg2 > 0)        if (opcode == OP_CRRANGE && min > 0)
7571          CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg2, label);          CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min, label);
7572        if (opcode == OP_UPTO || (opcode == OP_CRRANGE && arg1 > 0))        if (opcode == OP_UPTO || (opcode == OP_CRRANGE && max > 0))
7573          jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, arg1);          jump = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, max);
7574        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);
7575        }        }
7576    
# Line 7168  switch(opcode) Line 7597  switch(opcode)
7597      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
7598      if (opcode <= OP_PLUS)      if (opcode <= OP_PLUS)
7599        JUMPTO(SLJIT_JUMP, label);        JUMPTO(SLJIT_JUMP, label);
7600      else if (opcode == OP_CRRANGE && arg1 == 0)      else if (opcode == OP_CRRANGE && max == 0)
7601        {        {
7602        OP2(SLJIT_ADD, base, offset1, base, offset1, SLJIT_IMM, 1);        OP2(SLJIT_ADD, base, offset1, base, offset1, SLJIT_IMM, 1);
7603        JUMPTO(SLJIT_JUMP, label);        JUMPTO(SLJIT_JUMP, label);
# Line 7178  switch(opcode) Line 7607  switch(opcode)
7607        OP1(SLJIT_MOV, TMP1, 0, base, offset1);        OP1(SLJIT_MOV, TMP1, 0, base, offset1);
7608        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
7609        OP1(SLJIT_MOV, base, offset1, TMP1, 0);        OP1(SLJIT_MOV, base, offset1, TMP1, 0);
7610        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg1 + 1, label);        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, max + 1, label);
7611        }        }
7612      set_jumps(nomatch, LABEL());      set_jumps(nomatch, LABEL());
7613      if (opcode == OP_CRRANGE)      if (opcode == OP_CRRANGE)
7614        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));
7615      OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);      OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
7616      }      }
7617    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
# Line 7220  switch(opcode) Line 7649  switch(opcode)
7649    break;    break;
7650    
7651    case OP_EXACT:    case OP_EXACT:
7652    OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, arg1);    OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, max);
7653    label = LABEL();    label = LABEL();
7654    compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);    compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7655    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 7662  switch(opcode)
7662    if (opcode == OP_POSPLUS)    if (opcode == OP_POSPLUS)
7663      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7664    if (opcode == OP_POSUPTO)    if (opcode == OP_POSUPTO)
7665      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, arg1);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, max);
7666    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);    OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7667    label = LABEL();    label = LABEL();
7668    compile_char1_matchingpath(common, type, cc, &nomatch);    compile_char1_matchingpath(common, type, cc, &nomatch);
# Line 7257  switch(opcode) Line 7686  switch(opcode)
7686    OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);    OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);
7687    break;    break;
7688    
7689      case OP_CRPOSRANGE:
7690      /* Combination of OP_EXACT and OP_POSSTAR or OP_POSUPTO */
7691      OP1(SLJIT_MOV, tmp_base, tmp_offset, SLJIT_IMM, min);
7692      label = LABEL();
7693      compile_char1_matchingpath(common, type, cc, &backtrack->topbacktracks);
7694      OP2(SLJIT_SUB | SLJIT_SET_E, tmp_base, tmp_offset, tmp_base, tmp_offset, SLJIT_IMM, 1);
7695      JUMPTO(SLJIT_C_NOT_ZERO, label);
7696    
7697      if (max != 0)
7698        {
7699        SLJIT_ASSERT(max - min > 0);
7700        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, max - min);
7701        }
7702      OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7703      label = LABEL();
7704      compile_char1_matchingpath(common, type, cc, &nomatch);
7705      OP1(SLJIT_MOV, tmp_base, tmp_offset, STR_PTR, 0);
7706      if (max == 0)
7707        JUMPTO(SLJIT_JUMP, label);
7708      else
7709        {
7710        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, SLJIT_IMM, 1);
7711        JUMPTO(SLJIT_C_NOT_ZERO, label);
7712        }
7713      set_jumps(nomatch, LABEL());
7714      OP1(SLJIT_MOV, STR_PTR, 0, tmp_base, tmp_offset);
7715      break;
7716    
7717    default:    default:
7718    SLJIT_ASSERT_STOP();    SLJIT_ASSERT_STOP();
7719    break;    break;
# Line 7534  while (cc < ccend) Line 7991  while (cc < ccend)
7991    
7992      case OP_CLASS:      case OP_CLASS:
7993      case OP_NCLASS:      case OP_NCLASS:
7994      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)
7995        cc = compile_iterator_matchingpath(common, cc, parent);        cc = compile_iterator_matchingpath(common, cc, parent);
7996      else      else
7997        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 7999  while (cc < ccend)
7999    
8000  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
8001      case OP_XCLASS:      case OP_XCLASS:
8002      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)
8003        cc = compile_iterator_matchingpath(common, cc, parent);        cc = compile_iterator_matchingpath(common, cc, parent);
8004      else      else
8005        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 8008  while (cc < ccend)
8008    
8009      case OP_REF:      case OP_REF:
8010      case OP_REFI:      case OP_REFI:
8011      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)
8012          cc = compile_ref_iterator_matchingpath(common, cc, parent);
8013        else
8014          {
8015          compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);
8016          cc += 1 + IMM2_SIZE;
8017          }
8018        break;
8019    
8020        case OP_DNREF:
8021        case OP_DNREFI:
8022        if (cc[1 + 2 * IMM2_SIZE] >= OP_CRSTAR && cc[1 + 2 * IMM2_SIZE] <= OP_CRPOSRANGE)
8023        cc = compile_ref_iterator_matchingpath(common, cc, parent);        cc = compile_ref_iterator_matchingpath(common, cc, parent);
8024      else      else
8025        cc = compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);        {
8026          compile_dnref_search(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);
8027          compile_ref_matchingpath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);
8028          cc += 1 + 2 * IMM2_SIZE;
8029          }
8030      break;      break;
8031    
8032      case OP_RECURSE:      case OP_RECURSE:
# Line 7707  DEFINE_COMPILER; Line 8179  DEFINE_COMPILER;
8179  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
8180  pcre_uchar opcode;  pcre_uchar opcode;
8181  pcre_uchar type;  pcre_uchar type;
8182  int arg1 = -1, arg2 = -1;  int max = -1, min = -1;
8183  struct sljit_label *label = NULL;  struct sljit_label *label = NULL;
8184  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
8185  jump_list *jumplist = NULL;  jump_list *jumplist = NULL;
# Line 7716  int base = (private_data_ptr == 0) ? SLJ Line 8188  int base = (private_data_ptr == 0) ? SLJ
8188  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;  int offset0 = (private_data_ptr == 0) ? STACK(0) : private_data_ptr;
8189  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);
8190    
8191  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, NULL);  cc = get_iterator_parameters(common, cc, &opcode, &type, &max, &min, NULL);
8192    
8193  switch(opcode)  switch(opcode)
8194    {    {
# Line 7735  switch(opcode) Line 8207  switch(opcode)
8207    else    else
8208      {      {
8209      if (opcode == OP_UPTO)      if (opcode == OP_UPTO)
8210        arg2 = 0;        min = 0;
8211      if (opcode <= OP_PLUS)      if (opcode <= OP_PLUS)
8212        {        {
8213        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
# Line 7745  switch(opcode) Line 8217  switch(opcode)
8217        {        {
8218        OP1(SLJIT_MOV, TMP1, 0, base, offset1);        OP1(SLJIT_MOV, TMP1, 0, base, offset1);
8219        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);        OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
8220        jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, arg2 + 1);        jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, min + 1);
8221        OP2(SLJIT_SUB, base, offset1, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_SUB, base, offset1, TMP1, 0, SLJIT_IMM, 1);
8222        }        }
8223      skip_char_back(common);      skip_char_back(common);
# Line 7790  switch(opcode) Line 8262  switch(opcode)
8262    OP1(SLJIT_MOV, base, offset1, TMP1, 0);    OP1(SLJIT_MOV, base, offset1, TMP1, 0);
8263    
8264    if (opcode == OP_CRMINRANGE)    if (opcode == OP_CRMINRANGE)
8265      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg2 + 1, label);      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min + 1, label);
8266    
8267    if (opcode == OP_CRMINRANGE && arg1 == 0)    if (opcode == OP_CRMINRANGE && max == 0)
8268      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->matchingpath);      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->matchingpath);
8269    else    else
8270      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);
8271    
8272    set_jumps(jumplist, LABEL());    set_jumps(jumplist, LABEL());
8273    if (private_data_ptr == 0)    if (private_data_ptr == 0)
# Line 7830  switch(opcode) Line 8302  switch(opcode)
8302    
8303    case OP_EXACT:    case OP_EXACT:
8304    case OP_POSPLUS:    case OP_POSPLUS:
8305      case OP_CRPOSRANGE:
8306    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
8307    break;    break;
8308    
# Line 7848  static SLJIT_INLINE void compile_ref_ite Line 8321  static SLJIT_INLINE void compile_ref_ite
8321  {  {
8322  DEFINE_COMPILER;  DEFINE_COMPILER;
8323  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
8324    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
8325  pcre_uchar type;  pcre_uchar type;
8326    
8327  type = cc[1 + IMM2_SIZE];  type = cc[ref ? 1 + IMM2_SIZE : 1 + 2 * IMM2_SIZE];
8328    
8329  if ((type & 0x1) == 0)  if ((type & 0x1) == 0)
8330    {    {
8331      /* Maximize case. */
8332    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
8333    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8334    free_stack(common, 1);    free_stack(common, 1);
# Line 7863  if ((type & 0x1) == 0) Line 8339  if ((type & 0x1) == 0)
8339  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8340  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);
8341  set_jumps(current->topbacktracks, LABEL());  set_jumps(current->topbacktracks, LABEL());
8342  free_stack(common, 2);  free_stack(common, ref ? 2 : 3);
8343  }  }
8344    
8345  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 9140  while (current)
9140    
9141      case OP_REF:      case OP_REF:
9142      case OP_REFI:      case OP_REFI:
9143        case OP_DNREF:
9144        case OP_DNREFI:
9145      compile_ref_iterator_backtrackingpath(common, current);      compile_ref_iterator_backtrackingpath(common, current);
9146      break;      break;
9147    
# Line 8943  switch(re->options & PCRE_NEWLINE_BITS) Line 9421  switch(re->options & PCRE_NEWLINE_BITS)
9421    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;
9422    default: return;    default: return;
9423    }    }
9424    common->nlmax = READ_CHAR_ANY;
9425  if ((re->options & PCRE_BSR_ANYCRLF) != 0)  if ((re->options & PCRE_BSR_ANYCRLF) != 0)
9426    common->bsr_nltype = NLTYPE_ANYCRLF;    common->bsr_nltype = NLTYPE_ANYCRLF;
9427  else if ((re->options & PCRE_BSR_UNICODE) != 0)  else if ((re->options & PCRE_BSR_UNICODE) != 0)
# Line 8955  else Line 9434  else
9434    common->bsr_nltype = NLTYPE_ANY;    common->bsr_nltype = NLTYPE_ANY;
9435  #endif  #endif
9436    }    }
9437    common->bsr_nlmax = READ_CHAR_ANY;
9438  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
9439  common->ctypes = (sljit_sw)(tables + ctypes_offset);  common->ctypes = (sljit_sw)(tables + ctypes_offset);
9440  common->digits[0] = -2;  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;
 common->name_table = (sljit_sw)((pcre_uchar *)re + re->name_table_offset);  
9441  common->name_count = re->name_count;  common->name_count = re->name_count;
9442  common->name_entry_size = re->name_entry_size;  common->name_entry_size = re->name_entry_size;
9443  common->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;  common->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
# Line 8968  common->utf = (re->options & PCRE_UTF8) Line 9447  common->utf = (re->options & PCRE_UTF8)
9447  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
9448  common->use_ucp = (re->options & PCRE_UCP) != 0;  common->use_ucp = (re->options & PCRE_UCP) != 0;
9449  #endif  #endif
9450    if (common->utf)
9451      {
9452      if (common->nltype == NLTYPE_ANY)
9453        common->nlmax = 0x2029;
9454      else if (common->nltype == NLTYPE_ANYCRLF)
9455        common->nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL;
9456      else
9457        {
9458        /* We only care about the first newline character. */
9459        common->nlmax = common->newline & 0xff;
9460        }
9461    
9462      if (common->bsr_nltype == NLTYPE_ANY)
9463        common->bsr_nlmax = 0x2029;
9464      else
9465        common->bsr_nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL;
9466      }
9467  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
9468  ccend = bracketend(rootbacktrack.cc);  ccend = bracketend(rootbacktrack.cc);
9469    
# Line 9131  if ((re->options & PCRE_ANCHORED) == 0) Line 9627  if ((re->options & PCRE_ANCHORED) == 0)
9627      else if ((re->flags & PCRE_STARTLINE) != 0)      else if ((re->flags & PCRE_STARTLINE) != 0)
9628        fast_forward_newline(common, (re->options & PCRE_FIRSTLINE) != 0);        fast_forward_newline(common, (re->options & PCRE_FIRSTLINE) != 0);
9629      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)
9630        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);
9631      }      }
9632    }    }
9633  else  else
# Line 9369  if (common->reset_match != NULL) Line 9865  if (common->reset_match != NULL)
9865    JUMPTO(SLJIT_JUMP, reset_match_label);    JUMPTO(SLJIT_JUMP, reset_match_label);
9866    }    }
9867  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
9868  #ifndef COMPILE_PCRE32  #ifdef COMPILE_PCRE8
9869  if (common->utfreadchar != NULL)  if (common->utfreadchar != NULL)
9870    {    {
9871    set_jumps(common->utfreadchar, LABEL());    set_jumps(common->utfreadchar, LABEL());
9872    do_utfreadchar(common);    do_utfreadchar(common);
9873    }    }
9874  #endif /* !COMPILE_PCRE32 */  if (common->utfreadchar16 != NULL)
9875  #ifdef COMPILE_PCRE8    {
9876      set_jumps(common->utfreadchar16, LABEL());
9877      do_utfreadchar16(common);
9878      }
9879  if (common->utfreadtype8 != NULL)  if (common->utfreadtype8 != NULL)
9880    {    {
9881    set_jumps(common->utfreadtype8, LABEL());    set_jumps(common->utfreadtype8, LABEL());

Legend:
Removed from v.1338  
changed lines
  Added in v.1424

  ViewVC Help
Powered by ViewVC 1.1.5