/[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 1437 by zherczeg, Fri Jan 10 08:52: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 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;
# Line 3517  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_ Line 3688  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_
3688  skip_char_back(common);  skip_char_back(common);
3689    
3690  loop = LABEL();  loop = LABEL();
3691  read_char(common);  read_char_range(common, common->nlmin, common->nlmax, TRUE);
3692  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3693  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3694    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 3957  JUMPHERE(skipread);
3957    
3958  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3959  check_str_end(common, &skipread_list);  check_str_end(common, &skipread_list);
3960  peek_char(common);  peek_char(common, READ_CHAR_MAX);
3961    
3962  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
3963  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4345  return cc; Line 4516  return cc;
4516  #define SET_TYPE_OFFSET(value) \  #define SET_TYPE_OFFSET(value) \
4517    if ((value) != typeoffset) \    if ((value) != typeoffset) \
4518      { \      { \
4519      if ((value) > typeoffset) \      if ((value) < typeoffset) \
       OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \  
     else \  
4520        OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \        OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \
4521        else \
4522          OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \
4523      } \      } \
4524    typeoffset = (value);    typeoffset = (value);
4525    
4526  #define SET_CHAR_OFFSET(value) \  #define SET_CHAR_OFFSET(value) \
4527    if ((value) != charoffset) \    if ((value) != charoffset) \
4528      { \      { \
4529      if ((value) > charoffset) \      if ((value) < charoffset) \
4530        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (value) - charoffset); \        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(charoffset - (value))); \
4531      else \      else \
4532        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, charoffset - (value)); \        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)((value) - charoffset)); \
4533      } \      } \
4534    charoffset = (value);    charoffset = (value);
4535    
# Line 4367  static void compile_xclass_matchingpath( Line 4538  static void compile_xclass_matchingpath(
4538  DEFINE_COMPILER;  DEFINE_COMPILER;
4539  jump_list *found = NULL;  jump_list *found = NULL;
4540  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;
4541  pcre_int32 c, charoffset;  sljit_uw c, charoffset, max = 256, min = READ_CHAR_MAX;
4542  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4543  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4544  int compares, invertcmp, numberofcmps;  int compares, invertcmp, numberofcmps;
4545    #if defined SUPPORT_UTF && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
4546    BOOL utf = common->utf;
4547    #endif
4548    
4549  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4550  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4551  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4552  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4553  const pcre_uint32 *other_cases;  const pcre_uint32 *other_cases;
4554  pcre_int32 typeoffset;  sljit_uw typeoffset;
4555  #endif  #endif
4556    
4557  /* 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);  
   
4558  cc++;  cc++;
4559  if ((cc[-1] & XCL_HASPROP) == 0)  ccbegin = cc;
4560    {  compares = 0;
4561    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)  
4562    {    {
4563    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);  
4564    cc += 32 / sizeof(pcre_uchar);    cc += 32 / sizeof(pcre_uchar);
4565    }    }
4566    
 /* Scanning the necessary info. */  
 ccbegin = cc;  
 compares = 0;  
4567  while (*cc != XCL_END)  while (*cc != XCL_END)
4568    {    {
4569    compares++;    compares++;
4570    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
4571      {      {
4572      cc += 2;      cc ++;
4573  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4574      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (c > max) max = c;
4575  #endif      if (c < min) min = c;
4576  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4577      needschar = TRUE;      needschar = TRUE;
4578  #endif  #endif
4579      }      }
4580    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
4581      {      {
4582      cc += 2;      cc ++;
4583  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4584      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (c < min) min = c;
4585  #endif      GETCHARINCTEST(c, cc);
4586      cc++;      if (c > max) max = c;
 #ifdef SUPPORT_UTF  
     if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
4587  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4588      needschar = TRUE;      needschar = TRUE;
4589  #endif  #endif
# Line 4479  while (*cc != XCL_END) Line 4593  while (*cc != XCL_END)
4593      {      {
4594      SLJIT_ASSERT(*cc == XCL_PROP || *cc == XCL_NOTPROP);      SLJIT_ASSERT(*cc == XCL_PROP || *cc == XCL_NOTPROP);
4595      cc++;      cc++;
4596        if (*cc == PT_CLIST)
4597          {
4598          other_cases = PRIV(ucd_caseless_sets) + cc[1];
4599          while (*other_cases != NOTACHAR)
4600            {
4601            if (*other_cases > max) max = *other_cases;
4602            if (*other_cases < min) min = *other_cases;
4603            other_cases++;
4604            }
4605          }
4606        else
4607          {
4608          max = READ_CHAR_MAX;
4609          min = 0;
4610          }
4611    
4612      switch(*cc)      switch(*cc)
4613        {        {
4614        case PT_ANY:        case PT_ANY:
# Line 4519  while (*cc != XCL_END) Line 4649  while (*cc != XCL_END)
4649  #endif  #endif
4650    }    }
4651    
4652    /* We are not necessary in utf mode even in 8 bit mode. */
4653    cc = ccbegin;
4654    detect_partial_match(common, backtracks);
4655    read_char_range(common, min, max, (cc[-1] & XCL_NOT) != 0);
4656    
4657    if ((cc[-1] & XCL_HASPROP) == 0)
4658      {
4659      if ((cc[-1] & XCL_MAP) != 0)
4660        {
4661        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4662        if (!check_class_ranges(common, (const pcre_uint8 *)cc, (((const pcre_uint8 *)cc)[31] & 0x80) != 0, TRUE, &found))
4663          {
4664          OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4665          OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4666          OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4667          OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4668          OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4669          add_jump(compiler, &found, JUMP(SLJIT_C_NOT_ZERO));
4670          }
4671    
4672        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4673        JUMPHERE(jump);
4674    
4675        cc += 32 / sizeof(pcre_uchar);
4676        }
4677      else
4678        {
4679        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, min);
4680        add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, max - min));
4681        }
4682      }
4683    else if ((cc[-1] & XCL_MAP) != 0)
4684      {
4685      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4686    #ifdef SUPPORT_UCP
4687      charsaved = TRUE;
4688    #endif
4689      if (!check_class_ranges(common, (const pcre_uint8 *)cc, FALSE, TRUE, list))
4690        {
4691    #ifdef COMPILE_PCRE8
4692        SLJIT_ASSERT(common->utf);
4693    #endif
4694        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4695    
4696        OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4697        OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4698        OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4699        OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4700        OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4701        add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
4702    
4703        JUMPHERE(jump);
4704        }
4705    
4706      OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
4707      cc += 32 / sizeof(pcre_uchar);
4708      }
4709    
4710  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4711  /* Simple register allocation. TMP1 is preferred if possible. */  /* Simple register allocation. TMP1 is preferred if possible. */
4712  if (needstype || needsscript)  if (needstype || needsscript)
# Line 4560  if (needstype || needsscript) Line 4748  if (needstype || needsscript)
4748  #endif  #endif
4749    
4750  /* Generating code. */  /* Generating code. */
 cc = ccbegin;  
4751  charoffset = 0;  charoffset = 0;
4752  numberofcmps = 0;  numberofcmps = 0;
4753  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4576  while (*cc != XCL_END) Line 4763  while (*cc != XCL_END)
4763    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
4764      {      {
4765      cc ++;      cc ++;
4766  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
     if (common->utf)  
       {  
       GETCHARINC(c, cc);  
       }  
     else  
 #endif  
       c = *cc++;  
4767    
4768      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4769        {        {
4770        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));
4771        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);
4772        numberofcmps++;        numberofcmps++;
4773        }        }
4774      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4775        {        {
4776        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));
4777        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);
4778        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4779        numberofcmps = 0;        numberofcmps = 0;
4780        }        }
4781      else      else
4782        {        {
4783        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));
4784        numberofcmps = 0;        numberofcmps = 0;
4785        }        }
4786      }      }
4787    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
4788      {      {
4789      cc ++;      cc ++;
4790  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
     if (common->utf)  
       {  
       GETCHARINC(c, cc);  
       }  
     else  
 #endif  
       c = *cc++;  
4791      SET_CHAR_OFFSET(c);      SET_CHAR_OFFSET(c);
4792  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4793      if (common->utf)  
       {  
       GETCHARINC(c, cc);  
       }  
     else  
 #endif  
       c = *cc++;  
4794      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4795        {        {
4796        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));
4797        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);
4798        numberofcmps++;        numberofcmps++;
4799        }        }
4800      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4801        {        {
4802        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));
4803        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);
4804        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4805        numberofcmps = 0;        numberofcmps = 0;
4806        }        }
4807      else      else
4808        {        {
4809        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));
4810        numberofcmps = 0;        numberofcmps = 0;
4811        }        }
4812      }      }
# Line 4705  while (*cc != XCL_END) Line 4872  while (*cc != XCL_END)
4872        break;        break;
4873    
4874        case PT_WORD:        case PT_WORD:
4875        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));
4876        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4877        /* Fall through. */        /* Fall through. */
4878    
# Line 4753  while (*cc != XCL_END) Line 4920  while (*cc != XCL_END)
4920          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]);
4921          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4922    
4923          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));
4924          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);
4925    
4926          other_cases += 3;          other_cases += 3;
4927          }          }
4928        else        else
4929          {          {
4930          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));
4931          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4932          }          }
4933    
4934        while (*other_cases != NOTACHAR)        while (*other_cases != NOTACHAR)
4935          {          {
4936          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));
4937          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);
4938          }          }
4939        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4940        break;        break;
4941    
4942        case PT_UCNC:        case PT_UCNC:
4943        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));
4944        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4945        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));
4946        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4947        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));
4948        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4949    
4950        SET_CHAR_OFFSET(0xa0);        SET_CHAR_OFFSET(0xa0);
4951        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));
4952        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4953        SET_CHAR_OFFSET(0);        SET_CHAR_OFFSET(0);
4954        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 5112  switch(type)
5112    
5113    case OP_ANY:    case OP_ANY:
5114    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5115    read_char(common);    read_char_range(common, common->nlmin, common->nlmax, TRUE);
5116    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
5117      {      {
5118      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 5180  switch(type)
5180    
5181    case OP_ANYNL:    case OP_ANYNL:
5182    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5183    read_char(common);    read_char_range(common, common->bsr_nlmin, common->bsr_nlmax, FALSE);
5184    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);
5185    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
5186    end_list = NULL;    end_list = NULL;
# Line 5035  switch(type) Line 5202  switch(type)
5202    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
5203    case OP_HSPACE:    case OP_HSPACE:
5204    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5205    read_char(common);    read_char_range(common, 0x9, 0x3000, type == OP_NOT_HSPACE);
5206    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));
5207    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));
5208    return cc;    return cc;
# Line 5043  switch(type) Line 5210  switch(type)
5210    case OP_NOT_VSPACE:    case OP_NOT_VSPACE:
5211    case OP_VSPACE:    case OP_VSPACE:
5212    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5213    read_char(common);    read_char_range(common, 0xa, 0x2029, type == OP_NOT_VSPACE);
5214    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));
5215    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));
5216    return cc;    return cc;
# Line 5142  switch(type) Line 5309  switch(type)
5309      else      else
5310        {        {
5311        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);
5312        read_char(common);        read_char_range(common, common->nlmin, common->nlmax, TRUE);
5313        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));
5314        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
5315        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 5190  switch(type) Line 5357  switch(type)
5357    else    else
5358      {      {
5359      skip_char_back(common);      skip_char_back(common);
5360      read_char(common);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
5361      check_newlinechar(common, common->nltype, backtracks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
5362      }      }
5363    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
# Line 5241  switch(type) Line 5408  switch(type)
5408      }      }
5409    else    else
5410      {      {
5411      peek_char(common);      peek_char(common, common->nlmax);
5412      check_newlinechar(common, common->nltype, backtracks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
5413      }      }
5414    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
# Line 5265  switch(type) Line 5432  switch(type)
5432  #endif  #endif
5433      return byte_sequence_compare(common, type == OP_CHARI, cc, &context, backtracks);      return byte_sequence_compare(common, type == OP_CHARI, cc, &context, backtracks);
5434      }      }
5435    
5436    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
   read_char(common);  
5437  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
5438    if (common->utf)    if (common->utf)
5439      {      {
# Line 5275  switch(type) Line 5442  switch(type)
5442    else    else
5443  #endif  #endif
5444      c = *cc;      c = *cc;
5445    
5446    if (type == OP_CHAR || !char_has_othercase(common, cc))    if (type == OP_CHAR || !char_has_othercase(common, cc))
5447      {      {
5448        read_char_range(common, c, c, FALSE);
5449      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));
5450      return cc + length;      return cc + length;
5451      }      }
5452    oc = char_othercase(common, c);    oc = char_othercase(common, c);
5453      read_char_range(common, c < oc ? c : oc, c > oc ? c : oc, FALSE);
5454    bit = c ^ oc;    bit = c ^ oc;
5455    if (is_powerof2(bit))    if (is_powerof2(bit))
5456      {      {
# Line 5288  switch(type) Line 5458  switch(type)
5458      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));
5459      return cc + length;      return cc + length;
5460      }      }
5461    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);
5462    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));
5463    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));  
5464    return cc + length;    return cc + length;
5465    
5466    case OP_NOT:    case OP_NOT:
# Line 5335  switch(type) Line 5503  switch(type)
5503    
5504    if (type == OP_NOT || !char_has_othercase(common, cc))    if (type == OP_NOT || !char_has_othercase(common, cc))
5505      {      {
5506      read_char_max(common, c, TRUE);      read_char_range(common, c, c, TRUE);
5507      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));
5508      }      }
5509    else    else
5510      {      {
5511      oc = char_othercase(common, c);      oc = char_othercase(common, c);
5512      read_char_max(common, c > oc ? c : oc, TRUE);      read_char_range(common, c < oc ? c : oc, c > oc ? c : oc, TRUE);
5513      bit = c ^ oc;      bit = c ^ oc;
5514      if (is_powerof2(bit))      if (is_powerof2(bit))
5515        {        {
# Line 5362  switch(type) Line 5530  switch(type)
5530    
5531  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5532    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;
5533    read_char_max(common, bit, type == OP_NCLASS);    read_char_range(common, 0, bit, type == OP_NCLASS);
5534  #else  #else
5535    read_char_max(common, 255, type == OP_NCLASS);    read_char_range(common, 0, 255, type == OP_NCLASS);
5536  #endif  #endif
5537    
5538    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 7903  if (*cc == OP_FAIL)
7903    return cc + 1;    return cc + 1;
7904    }    }
7905    
7906  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL)  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL || !common->might_be_empty)
7907    {    {
7908    /* No need to check notempty conditions. */    /* No need to check notempty conditions. */
7909    if (common->accept_label == NULL)    if (common->accept_label == NULL)
# Line 8437  if (bra == OP_BRAZERO) Line 8605  if (bra == OP_BRAZERO)
8605  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8606  {  {
8607  DEFINE_COMPILER;  DEFINE_COMPILER;
8608  int opcode, stacksize, count;  int opcode, stacksize, alt_count, alt_max;
8609  int offset = 0;  int offset = 0;
8610  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;
8611  int repeat_ptr = 0, repeat_type = 0, repeat_count = 0;  int repeat_ptr = 0, repeat_type = 0, repeat_count = 0;
8612  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
8613  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
8614  pcre_uchar *ccprev;  pcre_uchar *ccprev;
 jump_list *jumplist = NULL;  
 jump_list *jumplistitem = NULL;  
8615  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
8616  pcre_uchar ket;  pcre_uchar ket;
8617  assert_backtrack *assert;  assert_backtrack *assert;
8618  BOOL has_alternatives;  BOOL has_alternatives;
8619  BOOL needs_control_head = FALSE;  BOOL needs_control_head = FALSE;
8620  struct sljit_jump *brazero = NULL;  struct sljit_jump *brazero = NULL;
8621    struct sljit_jump *alt1 = NULL;
8622    struct sljit_jump *alt2 = NULL;
8623  struct sljit_jump *once = NULL;  struct sljit_jump *once = NULL;
8624  struct sljit_jump *cond = NULL;  struct sljit_jump *cond = NULL;
8625  struct sljit_label *rmin_label = NULL;  struct sljit_label *rmin_label = NULL;
# Line 8489  if (SLJIT_UNLIKELY(opcode == OP_COND) && Line 8657  if (SLJIT_UNLIKELY(opcode == OP_COND) &&
8657  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))
8658    opcode = OP_ONCE;    opcode = OP_ONCE;
8659    
8660    alt_max = has_alternatives ? no_alternatives(ccbegin) : 0;
8661    
8662  /* Decoding the needs_control_head in framesize. */  /* Decoding the needs_control_head in framesize. */
8663  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
8664    {    {
# Line 8602  else if (SLJIT_UNLIKELY(opcode == OP_CON Line 8772  else if (SLJIT_UNLIKELY(opcode == OP_CON
8772      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8773      free_stack(common, 1);      free_stack(common, 1);
8774    
8775      jumplistitem = sljit_alloc_memory(compiler, sizeof(jump_list));      alt_max = 2;
8776      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);  
8777      }      }
8778    }    }
8779  else if (*cc == OP_ALT)  else if (has_alternatives)
8780    {    {
   /* Build a jump list. Get the last successfully matched branch index. */  
8781    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8782    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;  
       }  
   
     if (SLJIT_UNLIKELY(!jumplistitem))  
       return;  
8783    
8784      jumplistitem->next = NULL;    if (alt_max > 4)
8785      jumplistitem->jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, count++);      {
8786      cc += GET(cc, 1);      /* Table jump if alt_max is greater than 4. */
8787        sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_MEM1(TMP1), (sljit_sw)common->read_only_data_ptr);
8788        add_label_addr(common);
8789        }
8790      else
8791        {
8792        if (alt_max == 4)
8793          alt2 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_uw));
8794        alt1 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, sizeof(sljit_uw));
8795      }      }
   while (*cc == OP_ALT);  
   
   cc = ccbegin + GET(ccbegin, 1);  
8796    }    }
8797    
8798  COMPILE_BACKTRACKINGPATH(current->top);  COMPILE_BACKTRACKINGPATH(current->top);
# Line 8674  if (SLJIT_UNLIKELY(opcode == OP_COND) || Line 8827  if (SLJIT_UNLIKELY(opcode == OP_COND) ||
8827    
8828  if (has_alternatives)  if (has_alternatives)
8829    {    {
8830    count = 1;    alt_count = sizeof(sljit_uw);
8831    do    do
8832      {      {
8833      current->top = NULL;      current->top = NULL;
# Line 8750  if (has_alternatives) Line 8903  if (has_alternatives)
8903        stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);        stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);
8904    
8905      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
8906        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);
8907    
8908      if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0)      if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0)
8909        {        {
# Line 8763  if (has_alternatives) Line 8916  if (has_alternatives)
8916    
8917      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
8918        {        {
8919        SLJIT_ASSERT(jumplist);        if (alt_max > 4)
8920        JUMPHERE(jumplist->jump);          add_label_addr(common);
8921        jumplist = jumplist->next;        else
8922            {
8923            if (alt_count != 2 * sizeof(sljit_uw))
8924              {
8925              JUMPHERE(alt1);
8926              if (alt_max == 3 && alt_count == sizeof(sljit_uw))
8927                alt2 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_uw));
8928              }
8929            else
8930              {
8931              JUMPHERE(alt2);
8932              if (alt_max == 4)
8933                alt1 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_uw));
8934              }
8935            }
8936          alt_count += sizeof(sljit_uw);
8937        }        }
8938    
8939      COMPILE_BACKTRACKINGPATH(current->top);      COMPILE_BACKTRACKINGPATH(current->top);
# Line 8774  if (has_alternatives) Line 8942  if (has_alternatives)
8942      SLJIT_ASSERT(!current->nextbacktracks);      SLJIT_ASSERT(!current->nextbacktracks);
8943      }      }
8944    while (*cc == OP_ALT);    while (*cc == OP_ALT);
   SLJIT_ASSERT(!jumplist);  
8945    
8946    if (cond != NULL)    if (cond != NULL)
8947      {      {
# Line 9375  pcre_uchar *ccend; Line 9542  pcre_uchar *ccend;
9542  executable_functions *functions;  executable_functions *functions;
9543  void *executable_func;  void *executable_func;
9544  sljit_uw executable_size;  sljit_uw executable_size;
9545    sljit_uw total_length;
9546    label_addr_list *label_addr;
9547  struct sljit_label *mainloop_label = NULL;  struct sljit_label *mainloop_label = NULL;
9548  struct sljit_label *continue_match_label;  struct sljit_label *continue_match_label;
9549  struct sljit_label *empty_match_found_label;  struct sljit_label *empty_match_found_label = NULL;
9550  struct sljit_label *empty_match_backtrack_label;  struct sljit_label *empty_match_backtrack_label = NULL;
9551  struct sljit_label *reset_match_label;  struct sljit_label *reset_match_label;
9552    struct sljit_label *quit_label;
9553  struct sljit_jump *jump;  struct sljit_jump *jump;
9554  struct sljit_jump *minlength_check_failed = NULL;  struct sljit_jump *minlength_check_failed = NULL;
9555  struct sljit_jump *reqbyte_notfound = NULL;  struct sljit_jump *reqbyte_notfound = NULL;
9556  struct sljit_jump *empty_match;  struct sljit_jump *empty_match = NULL;
 struct sljit_label *quit_label;  
9557    
9558  SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);  SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);
9559  study = extra->study_data;  study = extra->study_data;
# Line 9397  memset(common, 0, sizeof(compiler_common Line 9566  memset(common, 0, sizeof(compiler_common
9566  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;
9567    
9568  common->start = rootbacktrack.cc;  common->start = rootbacktrack.cc;
9569    common->read_only_data = NULL;
9570    common->read_only_data_size = 0;
9571    common->read_only_data_ptr = NULL;
9572  common->fcc = tables + fcc_offset;  common->fcc = tables + fcc_offset;
9573  common->lcc = (sljit_sw)(tables + lcc_offset);  common->lcc = (sljit_sw)(tables + lcc_offset);
9574  common->mode = mode;  common->mode = mode;
9575    common->might_be_empty = study->minlength == 0;
9576  common->nltype = NLTYPE_FIXED;  common->nltype = NLTYPE_FIXED;
9577  switch(re->options & PCRE_NEWLINE_BITS)  switch(re->options & PCRE_NEWLINE_BITS)
9578    {    {
# Line 9420  switch(re->options & PCRE_NEWLINE_BITS) Line 9593  switch(re->options & PCRE_NEWLINE_BITS)
9593    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;
9594    default: return;    default: return;
9595    }    }
9596    common->nlmax = READ_CHAR_MAX;
9597    common->nlmin = 0;
9598  if ((re->options & PCRE_BSR_ANYCRLF) != 0)  if ((re->options & PCRE_BSR_ANYCRLF) != 0)
9599    common->bsr_nltype = NLTYPE_ANYCRLF;    common->bsr_nltype = NLTYPE_ANYCRLF;
9600  else if ((re->options & PCRE_BSR_UNICODE) != 0)  else if ((re->options & PCRE_BSR_UNICODE) != 0)
# Line 9432  else Line 9607  else
9607    common->bsr_nltype = NLTYPE_ANY;    common->bsr_nltype = NLTYPE_ANY;
9608  #endif  #endif
9609    }    }
9610    common->bsr_nlmax = READ_CHAR_MAX;
9611    common->bsr_nlmin = 0;
9612  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
9613  common->ctypes = (sljit_sw)(tables + ctypes_offset);  common->ctypes = (sljit_sw)(tables + ctypes_offset);
9614  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 9621  common->utf = (re->options & PCRE_UTF8)
9621  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
9622  common->use_ucp = (re->options & PCRE_UCP) != 0;  common->use_ucp = (re->options & PCRE_UCP) != 0;
9623  #endif  #endif
9624    if (common->utf)
9625      {
9626      if (common->nltype == NLTYPE_ANY)
9627        common->nlmax = 0x2029;
9628      else if (common->nltype == NLTYPE_ANYCRLF)
9629        common->nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL;
9630      else
9631        {
9632        /* We only care about the first newline character. */
9633        common->nlmax = common->newline & 0xff;
9634        }
9635    
9636      if (common->nltype == NLTYPE_FIXED)
9637        common->nlmin = common->newline & 0xff;
9638      else
9639        common->nlmin = (CHAR_CR < CHAR_NL) ? CHAR_CR : CHAR_NL;
9640    
9641      if (common->bsr_nltype == NLTYPE_ANY)
9642        common->bsr_nlmax = 0x2029;
9643      else
9644        common->bsr_nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL;
9645      common->bsr_nlmin = (CHAR_CR < CHAR_NL) ? CHAR_CR : CHAR_NL;
9646      }
9647  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
9648  ccend = bracketend(rootbacktrack.cc);  ccend = bracketend(common->start);
9649    
9650  /* Calculate the local space size on the stack. */  /* Calculate the local space size on the stack. */
9651  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 9658  memset(common->optimized_cbracket, 0, re
9658  memset(common->optimized_cbracket, 1, re->top_bracket + 1);  memset(common->optimized_cbracket, 1, re->top_bracket + 1);
9659  #endif  #endif
9660    
9661  SLJIT_ASSERT(*rootbacktrack.cc == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);  SLJIT_ASSERT(*common->start == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);
9662  #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2  #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2
9663  common->capture_last_ptr = common->ovector_start;  common->capture_last_ptr = common->ovector_start;
9664  common->ovector_start += sizeof(sljit_sw);  common->ovector_start += sizeof(sljit_sw);
9665  #endif  #endif
9666  if (!check_opcode_types(common, rootbacktrack.cc, ccend))  if (!check_opcode_types(common, common->start, ccend))
9667    {    {
9668    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9669    return;    return;
# Line 9526  if (common->capture_last_ptr != 0) Line 9726  if (common->capture_last_ptr != 0)
9726  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));
9727  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);
9728    
9729  common->private_data_ptrs = (int *)SLJIT_MALLOC((ccend - rootbacktrack.cc) * sizeof(sljit_si));  total_length = ccend - common->start;
9730    common->private_data_ptrs = (sljit_si *)SLJIT_MALLOC(total_length * (sizeof(sljit_si) + (common->has_then ? 1 : 0)));
9731  if (!common->private_data_ptrs)  if (!common->private_data_ptrs)
9732    {    {
9733    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9734    return;    return;
9735    }    }
9736  memset(common->private_data_ptrs, 0, (ccend - rootbacktrack.cc) * sizeof(int));  memset(common->private_data_ptrs, 0, total_length * sizeof(sljit_si));
9737    
9738  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);
9739  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 9746  if (private_data_size > SLJIT_MAX_LOCAL_
9746    
9747  if (common->has_then)  if (common->has_then)
9748    {    {
9749    common->then_offsets = (pcre_uint8 *)SLJIT_MALLOC(ccend - rootbacktrack.cc);    common->then_offsets = (pcre_uint8 *)(common->private_data_ptrs + total_length);
9750    if (!common->then_offsets)    memset(common->then_offsets, 0, total_length);
9751      set_then_offsets(common, common->start, NULL);
9752      }
9753    
9754    if (common->read_only_data_size > 0)
9755      {
9756      common->read_only_data = (sljit_uw *)SLJIT_MALLOC(common->read_only_data_size);
9757      if (common->read_only_data == NULL)
9758      {      {
9759      SLJIT_FREE(common->optimized_cbracket);      SLJIT_FREE(common->optimized_cbracket);
9760      SLJIT_FREE(common->private_data_ptrs);      SLJIT_FREE(common->private_data_ptrs);
9761      return;      return;
9762      }      }
9763    memset(common->then_offsets, 0, ccend - rootbacktrack.cc);    common->read_only_data_ptr = common->read_only_data;
   set_then_offsets(common, rootbacktrack.cc, NULL);  
9764    }    }
9765    
9766  compiler = sljit_create_compiler();  compiler = sljit_create_compiler();
# Line 9561  if (!compiler) Line 9768  if (!compiler)
9768    {    {
9769    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9770    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
9771    if (common->has_then)    if (common->read_only_data)
9772      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
9773    return;    return;
9774    }    }
9775  common->compiler = compiler;  common->compiler = compiler;
# Line 9648  if (mode == JIT_PARTIAL_SOFT_COMPILE) Line 9855  if (mode == JIT_PARTIAL_SOFT_COMPILE)
9855  else if (mode == JIT_PARTIAL_HARD_COMPILE)  else if (mode == JIT_PARTIAL_HARD_COMPILE)
9856    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);
9857    
9858  compile_matchingpath(common, rootbacktrack.cc, ccend, &rootbacktrack);  compile_matchingpath(common, common->start, ccend, &rootbacktrack);
9859  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
9860    {    {
9861    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
9862    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9863    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
9864    if (common->has_then)    if (common->read_only_data)
9865      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
9866    return;    return;
9867    }    }
9868    
9869  empty_match = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));  if (common->might_be_empty)
9870  empty_match_found_label = LABEL();    {
9871      empty_match = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
9872      empty_match_found_label = LABEL();
9873      }
9874    
9875  common->accept_label = LABEL();  common->accept_label = LABEL();
9876  if (common->accept != NULL)  if (common->accept != NULL)
# Line 9684  if (mode != JIT_COMPILE) Line 9894  if (mode != JIT_COMPILE)
9894    return_with_partial_match(common, common->quit_label);    return_with_partial_match(common, common->quit_label);
9895    }    }
9896    
9897  empty_match_backtrack_label = LABEL();  if (common->might_be_empty)
9898      empty_match_backtrack_label = LABEL();
9899  compile_backtrackingpath(common, rootbacktrack.top);  compile_backtrackingpath(common, rootbacktrack.top);
9900  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
9901    {    {
9902    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
9903    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9904    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
9905    if (common->has_then)    if (common->read_only_data)
9906      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
9907    return;    return;
9908    }    }
9909    
# Line 9738  JUMPTO(SLJIT_JUMP, common->quit_label); Line 9949  JUMPTO(SLJIT_JUMP, common->quit_label);
9949    
9950  flush_stubs(common);  flush_stubs(common);
9951    
9952  JUMPHERE(empty_match);  if (common->might_be_empty)
9953  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);    {
9954  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));    JUMPHERE(empty_match);
9955  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_backtrack_label);    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
9956  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));
9957  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);
9958  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));
9959  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);
9960  JUMPTO(SLJIT_JUMP, empty_match_backtrack_label);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
9961      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, empty_match_found_label);
9962      JUMPTO(SLJIT_JUMP, empty_match_backtrack_label);
9963      }
9964    
9965  common->currententry = common->entries;  common->currententry = common->entries;
9966  common->local_exit = TRUE;  common->local_exit = TRUE;
# Line 9760  while (common->currententry != NULL) Line 9974  while (common->currententry != NULL)
9974      sljit_free_compiler(compiler);      sljit_free_compiler(compiler);
9975      SLJIT_FREE(common->optimized_cbracket);      SLJIT_FREE(common->optimized_cbracket);
9976      SLJIT_FREE(common->private_data_ptrs);      SLJIT_FREE(common->private_data_ptrs);
9977      if (common->has_then)      if (common->read_only_data)
9978        SLJIT_FREE(common->then_offsets);        SLJIT_FREE(common->read_only_data);
9979      return;      return;
9980      }      }
9981    flush_stubs(common);    flush_stubs(common);
# Line 9871  if (common->getucd != NULL) Line 10085  if (common->getucd != NULL)
10085    }    }
10086  #endif  #endif
10087    
10088    SLJIT_ASSERT(common->read_only_data + (common->read_only_data_size >> SLJIT_WORD_SHIFT) == common->read_only_data_ptr);
10089  SLJIT_FREE(common->optimized_cbracket);  SLJIT_FREE(common->optimized_cbracket);
10090  SLJIT_FREE(common->private_data_ptrs);  SLJIT_FREE(common->private_data_ptrs);
 if (common->has_then)  
   SLJIT_FREE(common->then_offsets);  
10091    
10092  executable_func = sljit_generate_code(compiler);  executable_func = sljit_generate_code(compiler);
10093  executable_size = sljit_get_generated_code_size(compiler);  executable_size = sljit_get_generated_code_size(compiler);
10094    label_addr = common->label_addrs;
10095    while (label_addr != NULL)
10096      {
10097      *label_addr->addr = sljit_get_label_addr(label_addr->label);
10098      label_addr = label_addr->next;
10099      }
10100  sljit_free_compiler(compiler);  sljit_free_compiler(compiler);
10101  if (executable_func == NULL)  if (executable_func == NULL)
10102      {
10103      if (common->read_only_data)
10104        SLJIT_FREE(common->read_only_data);
10105    return;    return;
10106      }
10107    
10108  /* Reuse the function descriptor if possible. */  /* Reuse the function descriptor if possible. */
10109  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 10123  else
10123    if (functions == NULL)    if (functions == NULL)
10124      {      {
10125      /* This case is highly unlikely since we just recently      /* This case is highly unlikely since we just recently
10126      freed a lot of memory. Although not impossible. */      freed a lot of memory. Not impossible though. */
10127      sljit_free_code(executable_func);      sljit_free_code(executable_func);
10128        if (common->read_only_data)
10129          SLJIT_FREE(common->read_only_data);
10130      return;      return;
10131      }      }
10132    memset(functions, 0, sizeof(executable_functions));    memset(functions, 0, sizeof(executable_functions));
# Line 9912  else Line 10137  else
10137    }    }
10138    
10139  functions->executable_funcs[mode] = executable_func;  functions->executable_funcs[mode] = executable_func;
10140    functions->read_only_data[mode] = common->read_only_data;
10141  functions->executable_sizes[mode] = executable_size;  functions->executable_sizes[mode] = executable_size;
10142  }  }
10143    
# Line 10098  for (i = 0; i < JIT_NUMBER_OF_COMPILE_MO Line 10324  for (i = 0; i < JIT_NUMBER_OF_COMPILE_MO
10324    {    {
10325    if (functions->executable_funcs[i] != NULL)    if (functions->executable_funcs[i] != NULL)
10326      sljit_free_code(functions->executable_funcs[i]);      sljit_free_code(functions->executable_funcs[i]);
10327      if (functions->read_only_data[i] != NULL)
10328        SLJIT_FREE(functions->read_only_data[i]);
10329    }    }
10330  SLJIT_FREE(functions);  SLJIT_FREE(functions);
10331  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.5