/[pcre]/code/trunk/pcre_jit_compile.c
ViewVC logotype

Diff of /code/trunk/pcre_jit_compile.c

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

revision 1422 by zherczeg, Mon Dec 30 19:05:36 2013 UTC revision 1440 by zherczeg, Sat Jan 11 21:54:20 2014 UTC
# Line 179  typedef struct jit_arguments { Line 179  typedef struct jit_arguments {
179    
180  typedef struct executable_functions {  typedef struct executable_functions {
181    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182      sljit_uw *read_only_data[JIT_NUMBER_OF_COMPILE_MODES];
183      sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
184    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
185    void *userdata;    void *userdata;
186    pcre_uint32 top_bracket;    pcre_uint32 top_bracket;
187    pcre_uint32 limit_match;    pcre_uint32 limit_match;
   sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];  
188  } executable_functions;  } executable_functions;
189    
190  typedef struct jump_list {  typedef struct jump_list {
# Line 197  typedef struct stub_list { Line 198  typedef struct stub_list {
198    struct stub_list *next;    struct stub_list *next;
199  } stub_list;  } stub_list;
200    
201    typedef struct label_addr_list {
202      struct sljit_label *label;
203      sljit_uw *addr;
204      struct label_addr_list *next;
205    } label_addr_list;
206    
207  enum frame_types {  enum frame_types {
208    no_frame = -1,    no_frame = -1,
209    no_stack = -2    no_stack = -2
# Line 315  typedef struct compiler_common { Line 322  typedef struct compiler_common {
322    pcre_uchar *start;    pcre_uchar *start;
323    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
324    sljit_si *private_data_ptrs;    sljit_si *private_data_ptrs;
325      /* This read-only data is available during runtime. */
326      sljit_uw *read_only_data;
327      /* The total size of the read-only data. */
328      sljit_uw read_only_data_size;
329      /* The next free entry of the read_only_data. */
330      sljit_uw *read_only_data_ptr;
331    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
332    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
333    /* Tells whether the starting offset is a target of then. */    /* Tells whether the starting offset is a target of then. */
# Line 349  typedef struct compiler_common { Line 362  typedef struct compiler_common {
362    sljit_sw lcc;    sljit_sw lcc;
363    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
364    int mode;    int mode;
365      /* TRUE, when minlength is greater than 0. */
366      BOOL might_be_empty;
367    /* \K is found in the pattern. */    /* \K is found in the pattern. */
368    BOOL has_set_som;    BOOL has_set_som;
369    /* (*SKIP:arg) is found in the pattern. */    /* (*SKIP:arg) is found in the pattern. */
# Line 363  typedef struct compiler_common { Line 378  typedef struct compiler_common {
378    BOOL positive_assert;    BOOL positive_assert;
379    /* Newline control. */    /* Newline control. */
380    int nltype;    int nltype;
381      pcre_uint32 nlmax;
382      pcre_uint32 nlmin;
383    int newline;    int newline;
384    int bsr_nltype;    int bsr_nltype;
385      pcre_uint32 bsr_nlmax;
386      pcre_uint32 bsr_nlmin;
387    /* Dollar endonly. */    /* Dollar endonly. */
388    int endonly;    int endonly;
389    /* Tables. */    /* Tables. */
# Line 380  typedef struct compiler_common { Line 399  typedef struct compiler_common {
399    struct sljit_label *forced_quit_label;    struct sljit_label *forced_quit_label;
400    struct sljit_label *accept_label;    struct sljit_label *accept_label;
401    stub_list *stubs;    stub_list *stubs;
402      label_addr_list *label_addrs;
403    recurse_entry *entries;    recurse_entry *entries;
404    recurse_entry *currententry;    recurse_entry *currententry;
405    jump_list *partialmatch;    jump_list *partialmatch;
# Line 522  the start pointers when the end of the c Line 542  the start pointers when the end of the c
542  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
543    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
544    
545    #define READ_CHAR_MAX 0x7fffffff
546    
547  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
548  {  {
549  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 531  cc += 1 + LINK_SIZE; Line 553  cc += 1 + LINK_SIZE;
553  return cc;  return cc;
554  }  }
555    
556    static int no_alternatives(pcre_uchar* cc)
557    {
558    int count = 0;
559    SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
560    do
561      {
562      cc += GET(cc, 1);
563      count++;
564      }
565    while (*cc == OP_ALT);
566    SLJIT_ASSERT(*cc >= OP_KET && *cc <= OP_KETRPOS);
567    return count;
568    }
569    
570  static int ones_in_half_byte[16] = {  static int ones_in_half_byte[16] = {
571    /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,    /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
572    /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4    /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
# Line 755  while (cc < ccend) Line 791  while (cc < ccend)
791      {      {
792      case OP_SET_SOM:      case OP_SET_SOM:
793      common->has_set_som = TRUE;      common->has_set_som = TRUE;
794        common->might_be_empty = TRUE;
795      cc += 1;      cc += 1;
796      break;      break;
797    
# Line 764  while (cc < ccend) Line 801  while (cc < ccend)
801      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
802      break;      break;
803    
804        case OP_BRA:
805        case OP_CBRA:
806        case OP_SBRA:
807        case OP_SCBRA:
808        count = no_alternatives(cc);
809        if (count > 4)
810          common->read_only_data_size += count * sizeof(sljit_uw);
811        cc += 1 + LINK_SIZE + (*cc == OP_CBRA || *cc == OP_SCBRA ? IMM2_SIZE : 0);
812        break;
813    
814      case OP_CBRAPOS:      case OP_CBRAPOS:
815      case OP_SCBRAPOS:      case OP_SCBRAPOS:
816      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
# Line 2022  while (list_item) Line 2069  while (list_item)
2069  common->stubs = NULL;  common->stubs = NULL;
2070  }  }
2071    
2072    static void add_label_addr(compiler_common *common)
2073    {
2074    DEFINE_COMPILER;
2075    label_addr_list *label_addr;
2076    
2077    label_addr = sljit_alloc_memory(compiler, sizeof(label_addr_list));
2078    if (label_addr == NULL)
2079      return;
2080    label_addr->label = LABEL();
2081    label_addr->addr = common->read_only_data_ptr;
2082    label_addr->next = common->label_addrs;
2083    common->label_addrs = label_addr;
2084    common->read_only_data_ptr++;
2085    }
2086    
2087  static SLJIT_INLINE void count_match(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2088  {  {
2089  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2460  else Line 2522  else
2522  JUMPHERE(jump);  JUMPHERE(jump);
2523  }  }
2524    
2525  static void peek_char(compiler_common *common)  static void peek_char(compiler_common *common, pcre_uint32 max)
2526  {  {
2527  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2528  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
# Line 2469  DEFINE_COMPILER; Line 2531  DEFINE_COMPILER;
2531  struct sljit_jump *jump;  struct sljit_jump *jump;
2532  #endif  #endif
2533    
2534    SLJIT_UNUSED_ARG(max);
2535    
2536  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2537  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2538  if (common->utf)  if (common->utf)
2539    {    {
2540      if (max < 128) return;
2541    
2542    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2543    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));
2544    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
# Line 2484  if (common->utf) Line 2550  if (common->utf)
2550  #if defined SUPPORT_UTF && defined COMPILE_PCRE16  #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2551  if (common->utf)  if (common->utf)
2552    {    {
2553      if (max < 0xd800) return;
2554    
2555    OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2556    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2557    /* TMP2 contains the high surrogate. */    /* TMP2 contains the high surrogate. */
# Line 2499  if (common->utf) Line 2567  if (common->utf)
2567    
2568  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2569    
2570  static BOOL is_char7_bitset(const pcre_uint8* bitset, BOOL nclass)  static BOOL is_char7_bitset(const pcre_uint8 *bitset, BOOL nclass)
2571  {  {
2572  /* Tells whether the character codes below 128 are enough  /* Tells whether the character codes below 128 are enough
2573  to determine a match. */  to determine a match. */
# Line 2542  if (full_read) Line 2610  if (full_read)
2610    
2611  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2612    
2613  static void read_char_max(compiler_common *common, pcre_uint32 max, BOOL full_read)  static void read_char_range(compiler_common *common, pcre_uint32 min, pcre_uint32 max, BOOL update_str_ptr)
2614  {  {
2615  /* Reads the precise value of a character into TMP1, if the character is  /* Reads the precise value of a character into TMP1, if the character is
2616  less than or equal to max. Otherwise it returns with a value greater than max.  between min and max (c >= min && c <= max). Otherwise it returns with a value
2617  Does not check STR_END. The full_read argument tells whether characters above  outside the range. Does not check STR_END. */
 max are accepted or not. */  
2618  DEFINE_COMPILER;  DEFINE_COMPILER;
2619  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2620  struct sljit_jump *jump;  struct sljit_jump *jump;
2621  #endif  #endif
2622    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2623    struct sljit_jump *jump2;
2624    #endif
2625    
2626  SLJIT_UNUSED_ARG(full_read);  SLJIT_UNUSED_ARG(update_str_ptr);
2627    SLJIT_UNUSED_ARG(min);
2628  SLJIT_UNUSED_ARG(max);  SLJIT_UNUSED_ARG(max);
2629    SLJIT_ASSERT(min <= max);
2630    
2631  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2632  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));
2633    
2634  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2635  if (common->utf)  if (common->utf)
2636    {    {
2637    if (max < 128 && !full_read)    if (max < 128 && !update_str_ptr) return;
     return;  
2638    
2639    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2640    if (max >= 0x800)    if (min >= 0x10000)
2641        {
2642        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xf0);
2643        if (update_str_ptr)
2644          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2645        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2646        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x7);
2647        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2648        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2649        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2650        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2651        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2652        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2653        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2654        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2655        if (!update_str_ptr)
2656          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2657        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2658        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2659        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2660        JUMPHERE(jump2);
2661        if (update_str_ptr)
2662          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2663        }
2664      else if (min >= 0x800 && max <= 0xffff)
2665        {
2666        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xe0);
2667        if (update_str_ptr)
2668          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2669        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2670        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xf);
2671        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2672        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2673        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2674        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2675        if (!update_str_ptr)
2676          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2677        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2678        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2679        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2680        JUMPHERE(jump2);
2681        if (update_str_ptr)
2682          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2683        }
2684      else if (max >= 0x800)
2685      add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));      add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2686    else if (max < 128)    else if (max < 128)
2687      {      {
# Line 2576  if (common->utf) Line 2691  if (common->utf)
2691    else    else
2692      {      {
2693      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2694      if (!full_read)      if (!update_str_ptr)
2695        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));
2696      else      else
2697        OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);        OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
# Line 2584  if (common->utf) Line 2699  if (common->utf)
2699      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2700      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2701      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2702      if (full_read)      if (update_str_ptr)
2703        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2704      }      }
2705    JUMPHERE(jump);    JUMPHERE(jump);
# Line 2609  if (common->utf) Line 2724  if (common->utf)
2724      return;      return;
2725      }      }
2726    
2727    if (max < 0xd800 && !full_read)    if (max < 0xd800 && !update_str_ptr) return;
     return;  
2728    
2729    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2730    OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2731    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2732    if (full_read)    if (update_str_ptr)
2733      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));
2734    if (max >= 0xd800)    if (max >= 0xd800)
2735      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);
# Line 2626  if (common->utf) Line 2740  if (common->utf)
2740    
2741  static SLJIT_INLINE void read_char(compiler_common *common)  static SLJIT_INLINE void read_char(compiler_common *common)
2742  {  {
2743  read_char_max(common, 0x7fffffff, TRUE);  read_char_range(common, 0, READ_CHAR_MAX, TRUE);
2744  }  }
2745    
2746  static void read_char8_type(compiler_common *common, BOOL full_read)  static void read_char8_type(compiler_common *common, BOOL update_str_ptr)
2747  {  {
2748  /* 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. */
 The full_read argument tells whether characters above max are accepted or not. */  
2749  DEFINE_COMPILER;  DEFINE_COMPILER;
2750  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2751  struct sljit_jump *jump;  struct sljit_jump *jump;
# Line 2641  struct sljit_jump *jump; Line 2754  struct sljit_jump *jump;
2754  struct sljit_jump *jump2;  struct sljit_jump *jump2;
2755  #endif  #endif
2756    
2757  SLJIT_UNUSED_ARG(full_read);  SLJIT_UNUSED_ARG(update_str_ptr);
2758    
2759  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2760  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));
# Line 2653  if (common->utf) Line 2766  if (common->utf)
2766    it is needed in most cases. */    it is needed in most cases. */
2767    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2768    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2769    if (!full_read)    if (!update_str_ptr)
2770      {      {
2771      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2772      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));
# Line 2684  JUMPHERE(jump); Line 2797  JUMPHERE(jump);
2797  #endif  #endif
2798    
2799  #if defined SUPPORT_UTF && defined COMPILE_PCRE16  #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2800  if (common->utf && full_read)  if (common->utf && update_str_ptr)
2801    {    {
2802    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2803    OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
# Line 2730  if (common->utf) Line 2843  if (common->utf)
2843  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));
2844  }  }
2845    
2846  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)
2847  {  {
2848  /* 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. */
2849  DEFINE_COMPILER;  DEFINE_COMPILER;
2850    struct sljit_jump *jump;
2851    
2852  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2853    {    {
2854    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2855    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));
2856    }    }
2857  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2858    {    {
2859    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    if (jumpifmatch)
2860    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);      {
2861    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));
2862    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));
2863    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));      }
2864      else
2865        {
2866        jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
2867        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2868        JUMPHERE(jump);
2869        }
2870    }    }
2871  else  else
2872    {    {
2873    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2874    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));
2875    }    }
2876  }  }
2877    
# Line 2828  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S Line 2948  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S
2948  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2949    
2950  JUMPHERE(jump);  JUMPHERE(jump);
2951    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x400);
2952    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
2953    /* This code runs only in 8 bit mode. No need to shift the value. */
2954    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2955  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2956  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2957  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
# Line 2949  if (firstline) Line 3073  if (firstline)
3073      mainloop = LABEL();      mainloop = LABEL();
3074      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
3075      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);
3076      read_char(common);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
3077      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
3078      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
3079      JUMPHERE(end);      JUMPHERE(end);
# Line 3063  while (TRUE) Line 3187  while (TRUE)
3187      cc++;      cc++;
3188      continue;      continue;
3189    
3190        case OP_ASSERT:
3191        case OP_ASSERT_NOT:
3192        case OP_ASSERTBACK:
3193        case OP_ASSERTBACK_NOT:
3194        cc = bracketend(cc);
3195        continue;
3196    
3197      case OP_PLUS:      case OP_PLUS:
3198      case OP_MINPLUS:      case OP_MINPLUS:
3199      case OP_POSPLUS:      case OP_POSPLUS:
# Line 3113  while (TRUE) Line 3244  while (TRUE)
3244      continue;      continue;
3245    
3246      case OP_CLASS:      case OP_CLASS:
3247    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3248        if (common->utf && !is_char7_bitset((const pcre_uint8 *)(cc + 1), FALSE)) return consumed;
3249    #endif
3250        any = TRUE;
3251        cc += 1 + 32 / sizeof(pcre_uchar);
3252        break;
3253    
3254      case OP_NCLASS:      case OP_NCLASS:
3255    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3256        if (common->utf) return consumed;
3257    #endif
3258      any = TRUE;      any = TRUE;
3259      cc += 1 + 32 / sizeof(pcre_uchar);      cc += 1 + 32 / sizeof(pcre_uchar);
3260      break;      break;
3261    
3262  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3263      case OP_XCLASS:      case OP_XCLASS:
3264    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3265        if (common->utf) return consumed;
3266    #endif
3267      any = TRUE;      any = TRUE;
3268      cc += GET(cc, 1);      cc += GET(cc, 1);
3269      break;      break;
3270  #endif  #endif
3271    
     case OP_NOT_DIGIT:  
3272      case OP_DIGIT:      case OP_DIGIT:
3273      case OP_NOT_WHITESPACE:  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3274        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_digit, FALSE))
3275          return consumed;
3276    #endif
3277        any = TRUE;
3278        cc++;
3279        break;
3280    
3281      case OP_WHITESPACE:      case OP_WHITESPACE:
3282      case OP_NOT_WORDCHAR:  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3283        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_space, FALSE))
3284          return consumed;
3285    #endif
3286        any = TRUE;
3287        cc++;
3288        break;
3289    
3290      case OP_WORDCHAR:      case OP_WORDCHAR:
3291    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3292        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_word, FALSE))
3293          return consumed;
3294    #endif
3295        any = TRUE;
3296        cc++;
3297        break;
3298    
3299        case OP_NOT_DIGIT:
3300        case OP_NOT_WHITESPACE:
3301        case OP_NOT_WORDCHAR:
3302      case OP_ANY:      case OP_ANY:
3303      case OP_ALLANY:      case OP_ALLANY:
3304    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3305        if (common->utf) return consumed;
3306    #endif
3307      any = TRUE;      any = TRUE;
3308      cc++;      cc++;
3309      break;      break;
# Line 3140  while (TRUE) Line 3311  while (TRUE)
3311  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3312      case OP_NOTPROP:      case OP_NOTPROP:
3313      case OP_PROP:      case OP_PROP:
3314    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3315        if (common->utf) return consumed;
3316    #endif
3317      any = TRUE;      any = TRUE;
3318      cc += 1 + 2;      cc += 1 + 2;
3319      break;      break;
# Line 3156  while (TRUE) Line 3330  while (TRUE)
3330    
3331    if (any)    if (any)
3332      {      {
 #ifdef SUPPORT_UTF  
     if (common->utf) return consumed;  
 #endif  
3333  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
3334      mask = 0xff;      mask = 0xff;
3335  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
# Line 3174  while (TRUE) Line 3345  while (TRUE)
3345        chars[0] = mask;        chars[0] = mask;
3346        chars[1] = mask;        chars[1] = mask;
3347    
3348          consumed++;
3349        if (--max_chars == 0)        if (--max_chars == 0)
3350          return consumed;          return consumed;
       consumed++;  
3351        chars += 2;        chars += 2;
3352        }        }
3353      while (--repeat > 0);      while (--repeat > 0);
# Line 3219  while (TRUE) Line 3390  while (TRUE)
3390          return consumed;          return consumed;
3391  #endif  #endif
3392        mask = 0;        mask = 0;
3393        if (len == (caseless & 0xff))        if ((pcre_uint32)len == (caseless & 0xff))
3394          {          {
3395          mask = caseless >> 8;          mask = caseless >> 8;
3396          chr |= mask;          chr |= mask;
3397          }          }
3398    
3399    #ifdef COMPILE_PCRE32
3400          if (chars[0] == NOTACHAR && chars[1] == 0)
3401    #else
3402        if (chars[0] == NOTACHAR)        if (chars[0] == NOTACHAR)
3403    #endif
3404          {          {
3405          chars[0] = chr;          chars[0] = chr;
3406          chars[1] = mask;          chars[1] = mask;
# Line 3239  while (TRUE) Line 3414  while (TRUE)
3414          }          }
3415    
3416        len--;        len--;
3417          consumed++;
3418        if (--max_chars == 0)        if (--max_chars == 0)
3419          return consumed;          return consumed;
       consumed++;  
3420        chars += 2;        chars += 2;
3421        cc++;        cc++;
3422        }        }
# Line 3261  while (TRUE) Line 3436  while (TRUE)
3436  }  }
3437    
3438  #define MAX_N_CHARS 16  #define MAX_N_CHARS 16
3439    #define MIN_RANGE_SIZE 4
3440    
3441  static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)  static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3442  {  {
# Line 3269  struct sljit_label *start; Line 3445  struct sljit_label *start;
3445  struct sljit_jump *quit;  struct sljit_jump *quit;
3446  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uint32 chars[MAX_N_CHARS * 2];
3447  pcre_uint8 ones[MAX_N_CHARS];  pcre_uint8 ones[MAX_N_CHARS];
 pcre_uint32 mask;  
 int i, max;  
3448  int offsets[3];  int offsets[3];
3449    pcre_uint32 mask, byte;
3450    int i, max, from;
3451    int range_right = -1, range_len = -1;
3452    sljit_ub *update_table = NULL;
3453    BOOL in_range;
3454    
3455    /* This is even TRUE, if both are NULL. */
3456    SLJIT_ASSERT(common->read_only_data_ptr == common->read_only_data);
3457    
3458  for (i = 0; i < MAX_N_CHARS; i++)  for (i = 0; i < MAX_N_CHARS; i++)
3459    {    {
# Line 3296  for (i = 0; i < max; i++) Line 3478  for (i = 0; i < max; i++)
3478      }      }
3479    }    }
3480    
3481    in_range = FALSE;
3482    for (i = 0; i <= max; i++)
3483      {
3484      if (i < max && ones[i] <= 1)
3485        {
3486        if (!in_range)
3487          {
3488          in_range = TRUE;
3489          from = i;
3490          }
3491        }
3492      else if (in_range)
3493        {
3494        if (range_len == -1 || (i - from) > range_len)
3495          {
3496          range_len = i - from;
3497          range_right = i - 1;
3498          }
3499        in_range = FALSE;
3500        }
3501      }
3502    
3503    if (range_len >= MIN_RANGE_SIZE)
3504      {
3505      /* Since no data is consumed (see the assert in the beginning
3506      of this function), this space can be reallocated. */
3507      if (common->read_only_data)
3508        SLJIT_FREE(common->read_only_data);
3509    
3510      common->read_only_data_size += 256;
3511      common->read_only_data = (sljit_uw *)SLJIT_MALLOC(common->read_only_data_size);
3512      if (common->read_only_data == NULL)
3513        return TRUE;
3514    
3515      update_table = (sljit_ub *)common->read_only_data;
3516      common->read_only_data_ptr = (sljit_uw *)(update_table + 256);
3517      memset(update_table, IN_UCHARS(range_len), 256);
3518    
3519      for (i = 0; i < range_len; i++)
3520        {
3521        byte = chars[(range_right - i) << 1] & 0xff;
3522        if (update_table[byte] > IN_UCHARS(i))
3523          update_table[byte] = IN_UCHARS(i);
3524        mask = chars[((range_right - i) << 1) + 1] & 0xff;
3525        if (mask != 0)
3526          {
3527          byte ^= mask;
3528          if (update_table[byte] > IN_UCHARS(i))
3529            update_table[byte] = IN_UCHARS(i);
3530          }
3531        }
3532      }
3533    
3534  offsets[0] = -1;  offsets[0] = -1;
3535  /* Scan forward. */  /* Scan forward. */
3536  for (i = 0; i < max; i++)  for (i = 0; i < max; i++)
# Line 3310  if (offsets[0] == -1) Line 3545  if (offsets[0] == -1)
3545  /* Scan backward. */  /* Scan backward. */
3546  offsets[1] = -1;  offsets[1] = -1;
3547  for (i = max - 1; i > offsets[0]; i--)  for (i = max - 1; i > offsets[0]; i--)
3548    if (ones[i] <= 2) {    if (ones[i] <= 2 && i != range_right)
3549        {
3550      offsets[1] = i;      offsets[1] = i;
3551      break;      break;
3552    }      }
3553    
3554    /* This case is handled better by fast_forward_first_char. */
3555    if (offsets[1] == -1 && offsets[0] == 0)
3556      return FALSE;
3557    
3558  offsets[2] = -1;  offsets[2] = -1;
3559  if (offsets[1] >= 0)  if (offsets[1] >= 0 && range_right == -1)
3560    {    {
3561    /* Scan from middle. */    /* Scan from middle. */
3562    for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)    for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
# Line 3357  max -= 1; Line 3597  max -= 1;
3597  if (firstline)  if (firstline)
3598    {    {
3599    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3600      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3601    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3602    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS(max));    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3603      quit = CMP(SLJIT_C_LESS_EQUAL, STR_END, 0, TMP1, 0);
3604      OP1(SLJIT_MOV, STR_END, 0, TMP1, 0);
3605      JUMPHERE(quit);
3606    }    }
3607  else  else
3608    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3609    
3610    #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3611    if (range_len >= MIN_RANGE_SIZE)
3612      OP1(SLJIT_MOV, RETURN_ADDR, 0, SLJIT_IMM, (sljit_sw)update_table);
3613    #endif
3614    
3615  start = LABEL();  start = LABEL();
3616  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3617    
3618    if (range_len >= MIN_RANGE_SIZE)
3619      {
3620    #if defined COMPILE_PCRE8 || (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
3621      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right));
3622    #else
3623      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right + 1) - 1);
3624    #endif
3625    
3626    #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3627      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(RETURN_ADDR, TMP1), 0);
3628    #else
3629      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)update_table);
3630    #endif
3631      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3632      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, start);
3633      }
3634    
3635  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
3636  if (offsets[1] >= 0)  if (offsets[1] >= 0)
3637    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
# Line 3395  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, S Line 3661  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, S
3661  JUMPHERE(quit);  JUMPHERE(quit);
3662    
3663  if (firstline)  if (firstline)
3664      {
3665      if (range_len >= MIN_RANGE_SIZE)
3666        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3667    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3668      if (range_len >= MIN_RANGE_SIZE)
3669        {
3670        quit = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
3671        OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
3672        JUMPHERE(quit);
3673        }
3674      }
3675  else  else
3676    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3677  return TRUE;  return TRUE;
3678  }  }
3679    
3680  #undef MAX_N_CHARS  #undef MAX_N_CHARS
3681    #undef MIN_RANGE_SIZE
3682    
3683  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)
3684  {  {
# Line 3517  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_ Line 3794  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_
3794  skip_char_back(common);  skip_char_back(common);
3795    
3796  loop = LABEL();  loop = LABEL();
3797  read_char(common);  read_char_range(common, common->nlmin, common->nlmax, TRUE);
3798  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3799  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3800    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
# Line 3786  JUMPHERE(skipread); Line 4063  JUMPHERE(skipread);
4063    
4064  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
4065  check_str_end(common, &skipread_list);  check_str_end(common, &skipread_list);
4066  peek_char(common);  peek_char(common, READ_CHAR_MAX);
4067    
4068  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
4069  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4345  return cc; Line 4622  return cc;
4622  #define SET_TYPE_OFFSET(value) \  #define SET_TYPE_OFFSET(value) \
4623    if ((value) != typeoffset) \    if ((value) != typeoffset) \
4624      { \      { \
4625      if ((value) > typeoffset) \      if ((value) < typeoffset) \
       OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \  
     else \  
4626        OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \        OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \
4627        else \
4628          OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \
4629      } \      } \
4630    typeoffset = (value);    typeoffset = (value);
4631    
4632  #define SET_CHAR_OFFSET(value) \  #define SET_CHAR_OFFSET(value) \
4633    if ((value) != charoffset) \    if ((value) != charoffset) \
4634      { \      { \
4635      if ((value) > charoffset) \      if ((value) < charoffset) \
4636        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (value) - charoffset); \        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(charoffset - (value))); \
4637      else \      else \
4638        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, charoffset - (value)); \        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)((value) - charoffset)); \
4639      } \      } \
4640    charoffset = (value);    charoffset = (value);
4641    
# Line 4367  static void compile_xclass_matchingpath( Line 4644  static void compile_xclass_matchingpath(
4644  DEFINE_COMPILER;  DEFINE_COMPILER;
4645  jump_list *found = NULL;  jump_list *found = NULL;
4646  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;
4647  pcre_int32 c, charoffset;  sljit_uw c, charoffset, max = 256, min = READ_CHAR_MAX;
4648  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4649  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4650  int compares, invertcmp, numberofcmps;  int compares, invertcmp, numberofcmps;
4651    #if defined SUPPORT_UTF && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
4652    BOOL utf = common->utf;
4653    #endif
4654    
4655  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4656  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4657  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4658  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4659  const pcre_uint32 *other_cases;  const pcre_uint32 *other_cases;
4660  pcre_int32 typeoffset;  sljit_uw typeoffset;
4661  #endif  #endif
4662    
4663  /* Although SUPPORT_UTF must be defined, we are  /* Scanning the necessary info. */
    not necessary in utf mode even in 8 bit mode. */  
 detect_partial_match(common, backtracks);  
 read_char(common);  
   
4664  cc++;  cc++;
4665  if ((cc[-1] & XCL_HASPROP) == 0)  ccbegin = cc;
4666    {  compares = 0;
4667    if ((cc[-1] & XCL_MAP) != 0)  if (cc[-1] & XCL_MAP)
     {  
     OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  
 #ifdef SUPPORT_UCP  
     charsaved = TRUE;  
 #endif  
     if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, FALSE, backtracks))  
       {  
       jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
   
       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, &found, JUMP(SLJIT_C_NOT_ZERO));  
       add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));  
   
       JUMPHERE(jump);  
       }  
     else  
       add_jump(compiler, &found, CMP(SLJIT_C_LESS_EQUAL, TMP3, 0, SLJIT_IMM, 0xff));  
   
     OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);  
     cc += 32 / sizeof(pcre_uchar);  
     }  
   else  
     add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0xff));  
   }  
 else if ((cc[-1] & XCL_MAP) != 0)  
4668    {    {
4669    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    min = 0;
 #ifdef SUPPORT_UCP  
   charsaved = TRUE;  
 #endif  
   if (!check_class_ranges(common, (const pcre_uint8 *)cc, FALSE, TRUE, list))  
     {  
 #ifdef COMPILE_PCRE8  
     SLJIT_ASSERT(common->utf);  
 #endif  
     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
   
     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));  
   
     JUMPHERE(jump);  
     }  
   
   OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);  
4670    cc += 32 / sizeof(pcre_uchar);    cc += 32 / sizeof(pcre_uchar);
4671    }    }
4672    
 /* Scanning the necessary info. */  
 ccbegin = cc;  
 compares = 0;  
4673  while (*cc != XCL_END)  while (*cc != XCL_END)
4674    {    {
4675    compares++;    compares++;
4676    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
4677      {      {
4678      cc += 2;      cc ++;
4679  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4680      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (c > max) max = c;
4681  #endif      if (c < min) min = c;
4682  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4683      needschar = TRUE;      needschar = TRUE;
4684  #endif  #endif
4685      }      }
4686    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
4687      {      {
4688      cc += 2;      cc ++;
4689  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4690      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (c < min) min = c;
4691  #endif      GETCHARINCTEST(c, cc);
4692      cc++;      if (c > max) max = c;
 #ifdef SUPPORT_UTF  
     if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
4693  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4694      needschar = TRUE;      needschar = TRUE;
4695  #endif  #endif
# Line 4479  while (*cc != XCL_END) Line 4699  while (*cc != XCL_END)
4699      {      {
4700      SLJIT_ASSERT(*cc == XCL_PROP || *cc == XCL_NOTPROP);      SLJIT_ASSERT(*cc == XCL_PROP || *cc == XCL_NOTPROP);
4701      cc++;      cc++;
4702        if (*cc == PT_CLIST)
4703          {
4704          other_cases = PRIV(ucd_caseless_sets) + cc[1];
4705          while (*other_cases != NOTACHAR)
4706            {
4707            if (*other_cases > max) max = *other_cases;
4708            if (*other_cases < min) min = *other_cases;
4709            other_cases++;
4710            }
4711          }
4712        else
4713          {
4714          max = READ_CHAR_MAX;
4715          min = 0;
4716          }
4717    
4718      switch(*cc)      switch(*cc)
4719        {        {
4720        case PT_ANY:        case PT_ANY:
# Line 4519  while (*cc != XCL_END) Line 4755  while (*cc != XCL_END)
4755  #endif  #endif
4756    }    }
4757    
4758    /* We are not necessary in utf mode even in 8 bit mode. */
4759    cc = ccbegin;
4760    detect_partial_match(common, backtracks);
4761    read_char_range(common, min, max, (cc[-1] & XCL_NOT) != 0);
4762    
4763    if ((cc[-1] & XCL_HASPROP) == 0)
4764      {
4765      if ((cc[-1] & XCL_MAP) != 0)
4766        {
4767        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4768        if (!check_class_ranges(common, (const pcre_uint8 *)cc, (((const pcre_uint8 *)cc)[31] & 0x80) != 0, TRUE, &found))
4769          {
4770          OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4771          OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4772          OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4773          OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4774          OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4775          add_jump(compiler, &found, JUMP(SLJIT_C_NOT_ZERO));
4776          }
4777    
4778        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4779        JUMPHERE(jump);
4780    
4781        cc += 32 / sizeof(pcre_uchar);
4782        }
4783      else
4784        {
4785        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, min);
4786        add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, max - min));
4787        }
4788      }
4789    else if ((cc[-1] & XCL_MAP) != 0)
4790      {
4791      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4792    #ifdef SUPPORT_UCP
4793      charsaved = TRUE;
4794    #endif
4795      if (!check_class_ranges(common, (const pcre_uint8 *)cc, FALSE, TRUE, list))
4796        {
4797    #ifdef COMPILE_PCRE8
4798        SLJIT_ASSERT(common->utf);
4799    #endif
4800        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4801    
4802        OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4803        OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4804        OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4805        OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4806        OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4807        add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
4808    
4809        JUMPHERE(jump);
4810        }
4811    
4812      OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
4813      cc += 32 / sizeof(pcre_uchar);
4814      }
4815    
4816  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4817  /* Simple register allocation. TMP1 is preferred if possible. */  /* Simple register allocation. TMP1 is preferred if possible. */
4818  if (needstype || needsscript)  if (needstype || needsscript)
# Line 4560  if (needstype || needsscript) Line 4854  if (needstype || needsscript)
4854  #endif  #endif
4855    
4856  /* Generating code. */  /* Generating code. */
 cc = ccbegin;  
4857  charoffset = 0;  charoffset = 0;
4858  numberofcmps = 0;  numberofcmps = 0;
4859  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4576  while (*cc != XCL_END) Line 4869  while (*cc != XCL_END)
4869    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
4870      {      {
4871      cc ++;      cc ++;
4872  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
     if (common->utf)  
       {  
       GETCHARINC(c, cc);  
       }  
     else  
 #endif  
       c = *cc++;  
4873    
4874      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4875        {        {
4876        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));
4877        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);
4878        numberofcmps++;        numberofcmps++;
4879        }        }
4880      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4881        {        {
4882        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));
4883        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);
4884        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4885        numberofcmps = 0;        numberofcmps = 0;
4886        }        }
4887      else      else
4888        {        {
4889        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));
4890        numberofcmps = 0;        numberofcmps = 0;
4891        }        }
4892      }      }
4893    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
4894      {      {
4895      cc ++;      cc ++;
4896  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
     if (common->utf)  
       {  
       GETCHARINC(c, cc);  
       }  
     else  
 #endif  
       c = *cc++;  
4897      SET_CHAR_OFFSET(c);      SET_CHAR_OFFSET(c);
4898  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4899      if (common->utf)  
       {  
       GETCHARINC(c, cc);  
       }  
     else  
 #endif  
       c = *cc++;  
4900      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4901        {        {
4902        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));
4903        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);
4904        numberofcmps++;        numberofcmps++;
4905        }        }
4906      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4907        {        {
4908        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));
4909        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);
4910        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4911        numberofcmps = 0;        numberofcmps = 0;
4912        }        }
4913      else      else
4914        {        {
4915        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));
4916        numberofcmps = 0;        numberofcmps = 0;
4917        }        }
4918      }      }
# Line 4705  while (*cc != XCL_END) Line 4978  while (*cc != XCL_END)
4978        break;        break;
4979    
4980        case PT_WORD:        case PT_WORD:
4981        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));
4982        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4983        /* Fall through. */        /* Fall through. */
4984    
# Line 4753  while (*cc != XCL_END) Line 5026  while (*cc != XCL_END)
5026          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]);
5027          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
5028    
5029          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));
5030          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);
5031    
5032          other_cases += 3;          other_cases += 3;
5033          }          }
5034        else        else
5035          {          {
5036          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(*other_cases++ - charoffset));
5037          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
5038          }          }
5039    
5040        while (*other_cases != NOTACHAR)        while (*other_cases != NOTACHAR)
5041          {          {
5042          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(*other_cases++ - charoffset));
5043          OP_FLAGS(SLJIT_OR | ((*other_cases == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_OR | ((*other_cases == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
5044          }          }
5045        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
5046        break;        break;
5047    
5048        case PT_UCNC:        case PT_UCNC:
5049        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(CHAR_DOLLAR_SIGN - charoffset));
5050        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
5051        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(CHAR_COMMERCIAL_AT - charoffset));
5052        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
5053        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(CHAR_GRAVE_ACCENT - charoffset));
5054        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
5055    
5056        SET_CHAR_OFFSET(0xa0);        SET_CHAR_OFFSET(0xa0);
5057        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(0xd7ff - charoffset));
5058        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
5059        SET_CHAR_OFFSET(0);        SET_CHAR_OFFSET(0);
5060        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, 0xe000 - 0);
# Line 4945  switch(type) Line 5218  switch(type)
5218    
5219    case OP_ANY:    case OP_ANY:
5220    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5221    read_char(common);    read_char_range(common, common->nlmin, common->nlmax, TRUE);
5222    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
5223      {      {
5224      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);
# Line 5013  switch(type) Line 5286  switch(type)
5286    
5287    case OP_ANYNL:    case OP_ANYNL:
5288    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5289    read_char(common);    read_char_range(common, common->bsr_nlmin, common->bsr_nlmax, FALSE);
5290    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);
5291    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
5292    end_list = NULL;    end_list = NULL;
# Line 5035  switch(type) Line 5308  switch(type)
5308    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
5309    case OP_HSPACE:    case OP_HSPACE:
5310    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5311    read_char(common);    read_char_range(common, 0x9, 0x3000, type == OP_NOT_HSPACE);
5312    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));
5313    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));
5314    return cc;    return cc;
# Line 5043  switch(type) Line 5316  switch(type)
5316    case OP_NOT_VSPACE:    case OP_NOT_VSPACE:
5317    case OP_VSPACE:    case OP_VSPACE:
5318    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5319    read_char(common);    read_char_range(common, 0xa, 0x2029, type == OP_NOT_VSPACE);
5320    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));
5321    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));
5322    return cc;    return cc;
# Line 5142  switch(type) Line 5415  switch(type)
5415      else      else
5416        {        {
5417        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);
5418        read_char(common);        read_char_range(common, common->nlmin, common->nlmax, TRUE);
5419        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));
5420        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
5421        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 5190  switch(type) Line 5463  switch(type)
5463    else    else
5464      {      {
5465      skip_char_back(common);      skip_char_back(common);
5466      read_char(common);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
5467      check_newlinechar(common, common->nltype, backtracks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
5468      }      }
5469    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
# Line 5241  switch(type) Line 5514  switch(type)
5514      }      }
5515    else    else
5516      {      {
5517      peek_char(common);      peek_char(common, common->nlmax);
5518      check_newlinechar(common, common->nltype, backtracks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
5519      }      }
5520    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
# Line 5265  switch(type) Line 5538  switch(type)
5538  #endif  #endif
5539      return byte_sequence_compare(common, type == OP_CHARI, cc, &context, backtracks);      return byte_sequence_compare(common, type == OP_CHARI, cc, &context, backtracks);
5540      }      }
5541    
5542    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
   read_char(common);  
5543  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
5544    if (common->utf)    if (common->utf)
5545      {      {
# Line 5275  switch(type) Line 5548  switch(type)
5548    else    else
5549  #endif  #endif
5550      c = *cc;      c = *cc;
5551    
5552    if (type == OP_CHAR || !char_has_othercase(common, cc))    if (type == OP_CHAR || !char_has_othercase(common, cc))
5553      {      {
5554        read_char_range(common, c, c, FALSE);
5555      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));
5556      return cc + length;      return cc + length;
5557      }      }
5558    oc = char_othercase(common, c);    oc = char_othercase(common, c);
5559      read_char_range(common, c < oc ? c : oc, c > oc ? c : oc, FALSE);
5560    bit = c ^ oc;    bit = c ^ oc;
5561    if (is_powerof2(bit))    if (is_powerof2(bit))
5562      {      {
# Line 5288  switch(type) Line 5564  switch(type)
5564      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));
5565      return cc + length;      return cc + length;
5566      }      }
5567    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);
5568    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));
5569    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));  
5570    return cc + length;    return cc + length;
5571    
5572    case OP_NOT:    case OP_NOT:
# Line 5335  switch(type) Line 5609  switch(type)
5609    
5610    if (type == OP_NOT || !char_has_othercase(common, cc))    if (type == OP_NOT || !char_has_othercase(common, cc))
5611      {      {
5612      read_char_max(common, c, TRUE);      read_char_range(common, c, c, TRUE);
5613      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));
5614      }      }
5615    else    else
5616      {      {
5617      oc = char_othercase(common, c);      oc = char_othercase(common, c);
5618      read_char_max(common, c > oc ? c : oc, TRUE);      read_char_range(common, c < oc ? c : oc, c > oc ? c : oc, TRUE);
5619      bit = c ^ oc;      bit = c ^ oc;
5620      if (is_powerof2(bit))      if (is_powerof2(bit))
5621        {        {
# Line 5362  switch(type) Line 5636  switch(type)
5636    
5637  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5638    bit = (common->utf && is_char7_bitset((const pcre_uint8 *)cc, type == OP_NCLASS)) ? 127 : 255;    bit = (common->utf && is_char7_bitset((const pcre_uint8 *)cc, type == OP_NCLASS)) ? 127 : 255;
5639    read_char_max(common, bit, type == OP_NCLASS);    read_char_range(common, 0, bit, type == OP_NCLASS);
5640  #else  #else
5641    read_char_max(common, 255, type == OP_NCLASS);    read_char_range(common, 0, 255, type == OP_NCLASS);
5642  #endif  #endif
5643    
5644    if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, FALSE, backtracks))    if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, FALSE, backtracks))
# Line 7735  if (*cc == OP_FAIL) Line 8009  if (*cc == OP_FAIL)
8009    return cc + 1;    return cc + 1;
8010    }    }
8011    
8012  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL)  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL || !common->might_be_empty)
8013    {    {
8014    /* No need to check notempty conditions. */    /* No need to check notempty conditions. */
8015    if (common->accept_label == NULL)    if (common->accept_label == NULL)
# Line 8437  if (bra == OP_BRAZERO) Line 8711  if (bra == OP_BRAZERO)
8711  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8712  {  {
8713  DEFINE_COMPILER;  DEFINE_COMPILER;
8714  int opcode, stacksize, count;  int opcode, stacksize, alt_count, alt_max;
8715  int offset = 0;  int offset = 0;
8716  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;
8717  int repeat_ptr = 0, repeat_type = 0, repeat_count = 0;  int repeat_ptr = 0, repeat_type = 0, repeat_count = 0;
8718  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
8719  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
8720  pcre_uchar *ccprev;  pcre_uchar *ccprev;
 jump_list *jumplist = NULL;  
 jump_list *jumplistitem = NULL;  
8721  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
8722  pcre_uchar ket;  pcre_uchar ket;
8723  assert_backtrack *assert;  assert_backtrack *assert;
8724  BOOL has_alternatives;  BOOL has_alternatives;
8725  BOOL needs_control_head = FALSE;  BOOL needs_control_head = FALSE;
8726  struct sljit_jump *brazero = NULL;  struct sljit_jump *brazero = NULL;
8727    struct sljit_jump *alt1 = NULL;
8728    struct sljit_jump *alt2 = NULL;
8729  struct sljit_jump *once = NULL;  struct sljit_jump *once = NULL;
8730  struct sljit_jump *cond = NULL;  struct sljit_jump *cond = NULL;
8731  struct sljit_label *rmin_label = NULL;  struct sljit_label *rmin_label = NULL;
# Line 8489  if (SLJIT_UNLIKELY(opcode == OP_COND) && Line 8763  if (SLJIT_UNLIKELY(opcode == OP_COND) &&
8763  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))
8764    opcode = OP_ONCE;    opcode = OP_ONCE;
8765    
8766    alt_max = has_alternatives ? no_alternatives(ccbegin) : 0;
8767    
8768  /* Decoding the needs_control_head in framesize. */  /* Decoding the needs_control_head in framesize. */
8769  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
8770    {    {
# Line 8602  else if (SLJIT_UNLIKELY(opcode == OP_CON Line 8878  else if (SLJIT_UNLIKELY(opcode == OP_CON
8878      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8879      free_stack(common, 1);      free_stack(common, 1);
8880    
8881      jumplistitem = sljit_alloc_memory(compiler, sizeof(jump_list));      alt_max = 2;
8882      if (SLJIT_UNLIKELY(!jumplistitem))      alt1 = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, sizeof(sljit_uw));
       return;  
     jumplist = jumplistitem;  
     jumplistitem->next = NULL;  
     jumplistitem->jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 1);  
8883      }      }
8884    }    }
8885  else if (*cc == OP_ALT)  else if (has_alternatives)
8886    {    {
   /* Build a jump list. Get the last successfully matched branch index. */  
8887    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8888    free_stack(common, 1);    free_stack(common, 1);
   count = 1;  
   do  
     {  
     /* Append as the last item. */  
     if (jumplist != NULL)  
       {  
       jumplistitem->next = sljit_alloc_memory(compiler, sizeof(jump_list));  
       jumplistitem = jumplistitem->next;  
       }  
     else  
       {  
       jumplistitem = sljit_alloc_memory(compiler, sizeof(jump_list));  
       jumplist = jumplistitem;  
       }  
8889    
8890      if (SLJIT_UNLIKELY(!jumplistitem))    if (alt_max > 4)
8891        return;      {
8892        /* Table jump if alt_max is greater than 4. */
8893      jumplistitem->next = NULL;      sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_MEM1(TMP1), (sljit_sw)common->read_only_data_ptr);
8894      jumplistitem->jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, count++);      add_label_addr(common);
8895      cc += GET(cc, 1);      }
8896      else
8897        {
8898        if (alt_max == 4)
8899          alt2 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_uw));
8900        alt1 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, sizeof(sljit_uw));
8901      }      }
   while (*cc == OP_ALT);  
   
   cc = ccbegin + GET(ccbegin, 1);  
8902    }    }
8903    
8904  COMPILE_BACKTRACKINGPATH(current->top);  COMPILE_BACKTRACKINGPATH(current->top);
# Line 8674  if (SLJIT_UNLIKELY(opcode == OP_COND) || Line 8933  if (SLJIT_UNLIKELY(opcode == OP_COND) ||
8933    
8934  if (has_alternatives)  if (has_alternatives)
8935    {    {
8936    count = 1;    alt_count = sizeof(sljit_uw);
8937    do    do
8938      {      {
8939      current->top = NULL;      current->top = NULL;
# Line 8750  if (has_alternatives) Line 9009  if (has_alternatives)
9009        stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);        stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);
9010    
9011      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
9012        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, count++);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, alt_count);
9013    
9014      if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0)      if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0)
9015        {        {
# Line 8763  if (has_alternatives) Line 9022  if (has_alternatives)
9022    
9023      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
9024        {        {
9025        SLJIT_ASSERT(jumplist);        if (alt_max > 4)
9026        JUMPHERE(jumplist->jump);          add_label_addr(common);
9027        jumplist = jumplist->next;        else
9028            {
9029            if (alt_count != 2 * sizeof(sljit_uw))
9030              {
9031              JUMPHERE(alt1);
9032              if (alt_max == 3 && alt_count == sizeof(sljit_uw))
9033                alt2 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_uw));
9034              }
9035            else
9036              {
9037              JUMPHERE(alt2);
9038              if (alt_max == 4)
9039                alt1 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_uw));
9040              }
9041            }
9042          alt_count += sizeof(sljit_uw);
9043        }        }
9044    
9045      COMPILE_BACKTRACKINGPATH(current->top);      COMPILE_BACKTRACKINGPATH(current->top);
# Line 8774  if (has_alternatives) Line 9048  if (has_alternatives)
9048      SLJIT_ASSERT(!current->nextbacktracks);      SLJIT_ASSERT(!current->nextbacktracks);
9049      }      }
9050    while (*cc == OP_ALT);    while (*cc == OP_ALT);
   SLJIT_ASSERT(!jumplist);  
9051    
9052    if (cond != NULL)    if (cond != NULL)
9053      {      {
# Line 9375  pcre_uchar *ccend; Line 9648  pcre_uchar *ccend;
9648  executable_functions *functions;  executable_functions *functions;
9649  void *executable_func;  void *executable_func;
9650  sljit_uw executable_size;  sljit_uw executable_size;
9651    sljit_uw total_length;
9652    label_addr_list *label_addr;
9653  struct sljit_label *mainloop_label = NULL;  struct sljit_label *mainloop_label = NULL;
9654  struct sljit_label *continue_match_label;  struct sljit_label *continue_match_label;
9655  struct sljit_label *empty_match_found_label;  struct sljit_label *empty_match_found_label = NULL;
9656  struct sljit_label *empty_match_backtrack_label;  struct sljit_label *empty_match_backtrack_label = NULL;
9657  struct sljit_label *reset_match_label;  struct sljit_label *reset_match_label;
9658    struct sljit_label *quit_label;
9659  struct sljit_jump *jump;  struct sljit_jump *jump;
9660  struct sljit_jump *minlength_check_failed = NULL;  struct sljit_jump *minlength_check_failed = NULL;
9661  struct sljit_jump *reqbyte_notfound = NULL;  struct sljit_jump *reqbyte_notfound = NULL;
9662  struct sljit_jump *empty_match;  struct sljit_jump *empty_match = NULL;
 struct sljit_label *quit_label;  
9663    
9664  SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);  SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);
9665  study = extra->study_data;  study = extra->study_data;
# Line 9397  memset(common, 0, sizeof(compiler_common Line 9672  memset(common, 0, sizeof(compiler_common
9672  rootbacktrack.cc = (pcre_uchar *)re + re->name_table_offset + re->name_count * re->name_entry_size;  rootbacktrack.cc = (pcre_uchar *)re + re->name_table_offset + re->name_count * re->name_entry_size;
9673    
9674  common->start = rootbacktrack.cc;  common->start = rootbacktrack.cc;
9675    common->read_only_data = NULL;
9676    common->read_only_data_size = 0;
9677    common->read_only_data_ptr = NULL;
9678  common->fcc = tables + fcc_offset;  common->fcc = tables + fcc_offset;
9679  common->lcc = (sljit_sw)(tables + lcc_offset);  common->lcc = (sljit_sw)(tables + lcc_offset);
9680  common->mode = mode;  common->mode = mode;
9681    common->might_be_empty = study->minlength == 0;
9682  common->nltype = NLTYPE_FIXED;  common->nltype = NLTYPE_FIXED;
9683  switch(re->options & PCRE_NEWLINE_BITS)  switch(re->options & PCRE_NEWLINE_BITS)
9684    {    {
# Line 9420  switch(re->options & PCRE_NEWLINE_BITS) Line 9699  switch(re->options & PCRE_NEWLINE_BITS)
9699    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;
9700    default: return;    default: return;
9701    }    }
9702    common->nlmax = READ_CHAR_MAX;
9703    common->nlmin = 0;
9704  if ((re->options & PCRE_BSR_ANYCRLF) != 0)  if ((re->options & PCRE_BSR_ANYCRLF) != 0)
9705    common->bsr_nltype = NLTYPE_ANYCRLF;    common->bsr_nltype = NLTYPE_ANYCRLF;
9706  else if ((re->options & PCRE_BSR_UNICODE) != 0)  else if ((re->options & PCRE_BSR_UNICODE) != 0)
# Line 9432  else Line 9713  else
9713    common->bsr_nltype = NLTYPE_ANY;    common->bsr_nltype = NLTYPE_ANY;
9714  #endif  #endif
9715    }    }
9716    common->bsr_nlmax = READ_CHAR_MAX;
9717    common->bsr_nlmin = 0;
9718  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
9719  common->ctypes = (sljit_sw)(tables + ctypes_offset);  common->ctypes = (sljit_sw)(tables + ctypes_offset);
9720  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;
# Line 9444  common->utf = (re->options & PCRE_UTF8) Line 9727  common->utf = (re->options & PCRE_UTF8)
9727  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
9728  common->use_ucp = (re->options & PCRE_UCP) != 0;  common->use_ucp = (re->options & PCRE_UCP) != 0;
9729  #endif  #endif
9730    if (common->utf)
9731      {
9732      if (common->nltype == NLTYPE_ANY)
9733        common->nlmax = 0x2029;
9734      else if (common->nltype == NLTYPE_ANYCRLF)
9735        common->nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL;
9736      else
9737        {
9738        /* We only care about the first newline character. */
9739        common->nlmax = common->newline & 0xff;
9740        }
9741    
9742      if (common->nltype == NLTYPE_FIXED)
9743        common->nlmin = common->newline & 0xff;
9744      else
9745        common->nlmin = (CHAR_CR < CHAR_NL) ? CHAR_CR : CHAR_NL;
9746    
9747      if (common->bsr_nltype == NLTYPE_ANY)
9748        common->bsr_nlmax = 0x2029;
9749      else
9750        common->bsr_nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL;
9751      common->bsr_nlmin = (CHAR_CR < CHAR_NL) ? CHAR_CR : CHAR_NL;
9752      }
9753  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
9754  ccend = bracketend(rootbacktrack.cc);  ccend = bracketend(common->start);
9755    
9756  /* Calculate the local space size on the stack. */  /* Calculate the local space size on the stack. */
9757  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);
# Line 9458  memset(common->optimized_cbracket, 0, re Line 9764  memset(common->optimized_cbracket, 0, re
9764  memset(common->optimized_cbracket, 1, re->top_bracket + 1);  memset(common->optimized_cbracket, 1, re->top_bracket + 1);
9765  #endif  #endif
9766    
9767  SLJIT_ASSERT(*rootbacktrack.cc == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);  SLJIT_ASSERT(*common->start == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);
9768  #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2  #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2
9769  common->capture_last_ptr = common->ovector_start;  common->capture_last_ptr = common->ovector_start;
9770  common->ovector_start += sizeof(sljit_sw);  common->ovector_start += sizeof(sljit_sw);
9771  #endif  #endif
9772  if (!check_opcode_types(common, rootbacktrack.cc, ccend))  if (!check_opcode_types(common, common->start, ccend))
9773    {    {
9774    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9775    return;    return;
# Line 9526  if (common->capture_last_ptr != 0) Line 9832  if (common->capture_last_ptr != 0)
9832  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));
9833  common->cbra_ptr = OVECTOR_START + (re->top_bracket + 1) * 2 * sizeof(sljit_sw);  common->cbra_ptr = OVECTOR_START + (re->top_bracket + 1) * 2 * sizeof(sljit_sw);
9834    
9835  common->private_data_ptrs = (int *)SLJIT_MALLOC((ccend - rootbacktrack.cc) * sizeof(sljit_si));  total_length = ccend - common->start;
9836    common->private_data_ptrs = (sljit_si *)SLJIT_MALLOC(total_length * (sizeof(sljit_si) + (common->has_then ? 1 : 0)));
9837  if (!common->private_data_ptrs)  if (!common->private_data_ptrs)
9838    {    {
9839    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9840    return;    return;
9841    }    }
9842  memset(common->private_data_ptrs, 0, (ccend - rootbacktrack.cc) * sizeof(int));  memset(common->private_data_ptrs, 0, total_length * sizeof(sljit_si));
9843    
9844  private_data_size = common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw);  private_data_size = common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw);
9845  set_private_data_ptrs(common, &private_data_size, ccend);  set_private_data_ptrs(common, &private_data_size, ccend);
# Line 9545  if (private_data_size > SLJIT_MAX_LOCAL_ Line 9852  if (private_data_size > SLJIT_MAX_LOCAL_
9852    
9853  if (common->has_then)  if (common->has_then)
9854    {    {
9855    common->then_offsets = (pcre_uint8 *)SLJIT_MALLOC(ccend - rootbacktrack.cc);    common->then_offsets = (pcre_uint8 *)(common->private_data_ptrs + total_length);
9856    if (!common->then_offsets)    memset(common->then_offsets, 0, total_length);
9857      set_then_offsets(common, common->start, NULL);
9858      }
9859    
9860    if (common->read_only_data_size > 0)
9861      {
9862      common->read_only_data = (sljit_uw *)SLJIT_MALLOC(common->read_only_data_size);
9863      if (common->read_only_data == NULL)
9864      {      {
9865      SLJIT_FREE(common->optimized_cbracket);      SLJIT_FREE(common->optimized_cbracket);
9866      SLJIT_FREE(common->private_data_ptrs);      SLJIT_FREE(common->private_data_ptrs);
9867      return;      return;
9868      }      }
9869    memset(common->then_offsets, 0, ccend - rootbacktrack.cc);    common->read_only_data_ptr = common->read_only_data;
   set_then_offsets(common, rootbacktrack.cc, NULL);  
9870    }    }
9871    
9872  compiler = sljit_create_compiler();  compiler = sljit_create_compiler();
# Line 9561  if (!compiler) Line 9874  if (!compiler)
9874    {    {
9875    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9876    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
9877    if (common->has_then)    if (common->read_only_data)
9878      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
9879    return;    return;
9880    }    }
9881  common->compiler = compiler;  common->compiler = compiler;
# Line 9601  if ((re->options & PCRE_ANCHORED) == 0) Line 9914  if ((re->options & PCRE_ANCHORED) == 0)
9914    if ((re->options & PCRE_NO_START_OPTIMIZE) == 0)    if ((re->options & PCRE_NO_START_OPTIMIZE) == 0)
9915      {      {
9916      if (mode == JIT_COMPILE && fast_forward_first_n_chars(common, (re->options & PCRE_FIRSTLINE) != 0))      if (mode == JIT_COMPILE && fast_forward_first_n_chars(common, (re->options & PCRE_FIRSTLINE) != 0))
9917        { /* Do nothing */ }        {
9918          /* If read_only_data is reallocated, we might have an allocation failure. */
9919          if (common->read_only_data_size > 0 && common->read_only_data == NULL)
9920            {
9921            sljit_free_compiler(compiler);
9922            SLJIT_FREE(common->optimized_cbracket);
9923            SLJIT_FREE(common->private_data_ptrs);
9924            return;
9925            }
9926          }
9927      else if ((re->flags & PCRE_FIRSTSET) != 0)      else if ((re->flags & PCRE_FIRSTSET) != 0)
9928        fast_forward_first_char(common, (pcre_uchar)re->first_char, (re->flags & PCRE_FCH_CASELESS) != 0, (re->options & PCRE_FIRSTLINE) != 0);        fast_forward_first_char(common, (pcre_uchar)re->first_char, (re->flags & PCRE_FCH_CASELESS) != 0, (re->options & PCRE_FIRSTLINE) != 0);
9929      else if ((re->flags & PCRE_STARTLINE) != 0)      else if ((re->flags & PCRE_STARTLINE) != 0)
# Line 9648  if (mode == JIT_PARTIAL_SOFT_COMPILE) Line 9970  if (mode == JIT_PARTIAL_SOFT_COMPILE)
9970  else if (mode == JIT_PARTIAL_HARD_COMPILE)  else if (mode == JIT_PARTIAL_HARD_COMPILE)
9971    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
9972    
9973  compile_matchingpath(common, rootbacktrack.cc, ccend, &rootbacktrack);  compile_matchingpath(common, common->start, ccend, &rootbacktrack);
9974  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
9975    {    {
9976    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
9977    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9978    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
9979    if (common->has_then)    if (common->read_only_data)
9980      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
9981    return;    return;
9982    }    }
9983    
9984  empty_match = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));  if (common->might_be_empty)
9985  empty_match_found_label = LABEL();    {
9986      empty_match = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
9987      empty_match_found_label = LABEL();
9988      }
9989    
9990  common->accept_label = LABEL();  common->accept_label = LABEL();
9991  if (common->accept != NULL)  if (common->accept != NULL)
# Line 9684  if (mode != JIT_COMPILE) Line 10009  if (mode != JIT_COMPILE)
10009    return_with_partial_match(common, common->quit_label);    return_with_partial_match(common, common->quit_label);
10010    }    }
10011    
10012  empty_match_backtrack_label = LABEL();  if (common->might_be_empty)
10013      empty_match_backtrack_label = LABEL();
10014  compile_backtrackingpath(common, rootbacktrack.top);  compile_backtrackingpath(common, rootbacktrack.top);
10015  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
10016    {    {
10017    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
10018    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
10019    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
10020    if (common->has_then)    if (common->read_only_data)
10021      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
10022    return;    return;
10023    }    }
10024    
# Line 9738  JUMPTO(SLJIT_JUMP, common->quit_label); Line 10064  JUMPTO(SLJIT_JUMP, common->quit_label);
10064    
10065  flush_stubs(common);  flush_stubs(common);
10066    
10067  JUMPHERE(empty_match);  if (common->might_be_empty)
10068  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);    {
10069  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));    JUMPHERE(empty_match);
10070  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_backtrack_label);    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
10071  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty_atstart));    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));
10072  CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_found_label);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_backtrack_label);
10073  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty_atstart));
10074  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, empty_match_found_label);    CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_found_label);
10075  JUMPTO(SLJIT_JUMP, empty_match_backtrack_label);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
10076      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, empty_match_found_label);
10077      JUMPTO(SLJIT_JUMP, empty_match_backtrack_label);
10078      }
10079    
10080  common->currententry = common->entries;  common->currententry = common->entries;
10081  common->local_exit = TRUE;  common->local_exit = TRUE;
# Line 9760  while (common->currententry != NULL) Line 10089  while (common->currententry != NULL)
10089      sljit_free_compiler(compiler);      sljit_free_compiler(compiler);
10090      SLJIT_FREE(common->optimized_cbracket);      SLJIT_FREE(common->optimized_cbracket);
10091      SLJIT_FREE(common->private_data_ptrs);      SLJIT_FREE(common->private_data_ptrs);
10092      if (common->has_then)      if (common->read_only_data)
10093        SLJIT_FREE(common->then_offsets);        SLJIT_FREE(common->read_only_data);
10094      return;      return;
10095      }      }
10096    flush_stubs(common);    flush_stubs(common);
# Line 9871  if (common->getucd != NULL) Line 10200  if (common->getucd != NULL)
10200    }    }
10201  #endif  #endif
10202    
10203    SLJIT_ASSERT(common->read_only_data + (common->read_only_data_size >> SLJIT_WORD_SHIFT) == common->read_only_data_ptr);
10204  SLJIT_FREE(common->optimized_cbracket);  SLJIT_FREE(common->optimized_cbracket);
10205  SLJIT_FREE(common->private_data_ptrs);  SLJIT_FREE(common->private_data_ptrs);
 if (common->has_then)  
   SLJIT_FREE(common->then_offsets);  
10206    
10207  executable_func = sljit_generate_code(compiler);  executable_func = sljit_generate_code(compiler);
10208  executable_size = sljit_get_generated_code_size(compiler);  executable_size = sljit_get_generated_code_size(compiler);
10209    label_addr = common->label_addrs;
10210    while (label_addr != NULL)
10211      {
10212      *label_addr->addr = sljit_get_label_addr(label_addr->label);
10213      label_addr = label_addr->next;
10214      }
10215  sljit_free_compiler(compiler);  sljit_free_compiler(compiler);
10216  if (executable_func == NULL)  if (executable_func == NULL)
10217      {
10218      if (common->read_only_data)
10219        SLJIT_FREE(common->read_only_data);
10220    return;    return;
10221      }
10222    
10223  /* Reuse the function descriptor if possible. */  /* Reuse the function descriptor if possible. */
10224  if ((extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 && extra->executable_jit != NULL)  if ((extra->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 && extra->executable_jit != NULL)
# Line 9900  else Line 10238  else
10238    if (functions == NULL)    if (functions == NULL)
10239      {      {
10240      /* This case is highly unlikely since we just recently      /* This case is highly unlikely since we just recently
10241      freed a lot of memory. Although not impossible. */      freed a lot of memory. Not impossible though. */
10242      sljit_free_code(executable_func);      sljit_free_code(executable_func);
10243        if (common->read_only_data)
10244          SLJIT_FREE(common->read_only_data);
10245      return;      return;
10246      }      }
10247    memset(functions, 0, sizeof(executable_functions));    memset(functions, 0, sizeof(executable_functions));
# Line 9912  else Line 10252  else
10252    }    }
10253    
10254  functions->executable_funcs[mode] = executable_func;  functions->executable_funcs[mode] = executable_func;
10255    functions->read_only_data[mode] = common->read_only_data;
10256  functions->executable_sizes[mode] = executable_size;  functions->executable_sizes[mode] = executable_size;
10257  }  }
10258    
# Line 10098  for (i = 0; i < JIT_NUMBER_OF_COMPILE_MO Line 10439  for (i = 0; i < JIT_NUMBER_OF_COMPILE_MO
10439    {    {
10440    if (functions->executable_funcs[i] != NULL)    if (functions->executable_funcs[i] != NULL)
10441      sljit_free_code(functions->executable_funcs[i]);      sljit_free_code(functions->executable_funcs[i]);
10442      if (functions->read_only_data[i] != NULL)
10443        SLJIT_FREE(functions->read_only_data[i]);
10444    }    }
10445  SLJIT_FREE(functions);  SLJIT_FREE(functions);
10446  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.5