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

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

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

revision 1424 by zherczeg, Tue Dec 31 11:22:31 2013 UTC revision 1442 by zherczeg, Sun Jan 12 17:17:29 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 364  typedef struct compiler_common { Line 379  typedef struct compiler_common {
379    /* Newline control. */    /* Newline control. */
380    int nltype;    int nltype;
381    pcre_uint32 nlmax;    pcre_uint32 nlmax;
382      pcre_uint32 nlmin;
383    int newline;    int newline;
384    int bsr_nltype;    int bsr_nltype;
385    pcre_uint32 bsr_nlmax;    pcre_uint32 bsr_nlmax;
386      pcre_uint32 bsr_nlmin;
387    /* Dollar endonly. */    /* Dollar endonly. */
388    int endonly;    int endonly;
389    /* Tables. */    /* Tables. */
# Line 382  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 524  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_ANY 0x7fffffff  #define READ_CHAR_MAX 0x7fffffff
546    
547  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
548  {  {
# Line 535  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 759  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 768  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 2026  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 2464  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 2473  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 2488  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 2503  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 2546  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 2580  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 2588  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 2613  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 2630  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, READ_CHAR_ANY, 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 2645  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 2657  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 2688  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 2964  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_max(common, common->nlmax, TRUE);      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 3044  static int scan_prefix(compiler_common * Line 3153  static int scan_prefix(compiler_common *
3153  {  {
3154  /* Recursive function, which scans prefix literals. */  /* Recursive function, which scans prefix literals. */
3155  int len, repeat, len_save, consumed = 0;  int len, repeat, len_save, consumed = 0;
3156  pcre_uint32 caseless, chr, mask;  pcre_uint32 chr, mask;
3157  pcre_uchar *alternative, *cc_save;  pcre_uchar *alternative, *cc_save, *oc;
3158  BOOL last, any;  BOOL last, any, caseless;
3159    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3160    pcre_uchar othercase[8];
3161    #elif defined SUPPORT_UTF && defined COMPILE_PCRE16
3162    pcre_uchar othercase[2];
3163    #else
3164    pcre_uchar othercase[1];
3165    #endif
3166    
3167  repeat = 1;  repeat = 1;
3168  while (TRUE)  while (TRUE)
3169    {    {
3170    last = TRUE;    last = TRUE;
3171    any = FALSE;    any = FALSE;
3172    caseless = 0;    caseless = FALSE;
3173    switch (*cc)    switch (*cc)
3174      {      {
3175      case OP_CHARI:      case OP_CHARI:
3176      caseless = 1;      caseless = TRUE;
3177      case OP_CHAR:      case OP_CHAR:
3178      last = FALSE;      last = FALSE;
3179      cc++;      cc++;
# Line 3078  while (TRUE) Line 3194  while (TRUE)
3194      cc++;      cc++;
3195      continue;      continue;
3196    
3197        case OP_ASSERT:
3198        case OP_ASSERT_NOT:
3199        case OP_ASSERTBACK:
3200        case OP_ASSERTBACK_NOT:
3201        cc = bracketend(cc);
3202        continue;
3203    
3204      case OP_PLUS:      case OP_PLUS:
3205      case OP_MINPLUS:      case OP_MINPLUS:
3206      case OP_POSPLUS:      case OP_POSPLUS:
# Line 3085  while (TRUE) Line 3208  while (TRUE)
3208      break;      break;
3209    
3210      case OP_EXACTI:      case OP_EXACTI:
3211      caseless = 1;      caseless = TRUE;
3212      case OP_EXACT:      case OP_EXACT:
3213      repeat = GET2(cc, 1);      repeat = GET2(cc, 1);
3214      last = FALSE;      last = FALSE;
# Line 3095  while (TRUE) Line 3218  while (TRUE)
3218      case OP_PLUSI:      case OP_PLUSI:
3219      case OP_MINPLUSI:      case OP_MINPLUSI:
3220      case OP_POSPLUSI:      case OP_POSPLUSI:
3221      caseless = 1;      caseless = TRUE;
3222      cc++;      cc++;
3223      break;      break;
3224    
# Line 3128  while (TRUE) Line 3251  while (TRUE)
3251      continue;      continue;
3252    
3253      case OP_CLASS:      case OP_CLASS:
3254    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3255        if (common->utf && !is_char7_bitset((const pcre_uint8 *)(cc + 1), FALSE)) return consumed;
3256    #endif
3257        any = TRUE;
3258        cc += 1 + 32 / sizeof(pcre_uchar);
3259        break;
3260    
3261      case OP_NCLASS:      case OP_NCLASS:
3262    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3263        if (common->utf) return consumed;
3264    #endif
3265      any = TRUE;      any = TRUE;
3266      cc += 1 + 32 / sizeof(pcre_uchar);      cc += 1 + 32 / sizeof(pcre_uchar);
3267      break;      break;
3268    
3269  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3270      case OP_XCLASS:      case OP_XCLASS:
3271    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3272        if (common->utf) return consumed;
3273    #endif
3274      any = TRUE;      any = TRUE;
3275      cc += GET(cc, 1);      cc += GET(cc, 1);
3276      break;      break;
3277  #endif  #endif
3278    
     case OP_NOT_DIGIT:  
3279      case OP_DIGIT:      case OP_DIGIT:
3280      case OP_NOT_WHITESPACE:  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3281        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_digit, FALSE))
3282          return consumed;
3283    #endif
3284        any = TRUE;
3285        cc++;
3286        break;
3287    
3288      case OP_WHITESPACE:      case OP_WHITESPACE:
3289      case OP_NOT_WORDCHAR:  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3290        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_space, FALSE))
3291          return consumed;
3292    #endif
3293        any = TRUE;
3294        cc++;
3295        break;
3296    
3297      case OP_WORDCHAR:      case OP_WORDCHAR:
3298    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3299        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_word, FALSE))
3300          return consumed;
3301    #endif
3302        any = TRUE;
3303        cc++;
3304        break;
3305    
3306        case OP_NOT_DIGIT:
3307        case OP_NOT_WHITESPACE:
3308        case OP_NOT_WORDCHAR:
3309      case OP_ANY:      case OP_ANY:
3310      case OP_ALLANY:      case OP_ALLANY:
3311    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3312        if (common->utf) return consumed;
3313    #endif
3314      any = TRUE;      any = TRUE;
3315      cc++;      cc++;
3316      break;      break;
# Line 3155  while (TRUE) Line 3318  while (TRUE)
3318  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3319      case OP_NOTPROP:      case OP_NOTPROP:
3320      case OP_PROP:      case OP_PROP:
3321    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3322        if (common->utf) return consumed;
3323    #endif
3324      any = TRUE;      any = TRUE;
3325      cc += 1 + 2;      cc += 1 + 2;
3326      break;      break;
# Line 3171  while (TRUE) Line 3337  while (TRUE)
3337    
3338    if (any)    if (any)
3339      {      {
 #ifdef SUPPORT_UTF  
     if (common->utf) return consumed;  
 #endif  
3340  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
3341      mask = 0xff;      mask = 0xff;
3342  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
# Line 3189  while (TRUE) Line 3352  while (TRUE)
3352        chars[0] = mask;        chars[0] = mask;
3353        chars[1] = mask;        chars[1] = mask;
3354    
3355          consumed++;
3356        if (--max_chars == 0)        if (--max_chars == 0)
3357          return consumed;          return consumed;
       consumed++;  
3358        chars += 2;        chars += 2;
3359        }        }
3360      while (--repeat > 0);      while (--repeat > 0);
# Line 3205  while (TRUE) Line 3368  while (TRUE)
3368    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3369  #endif  #endif
3370    
3371    if (caseless != 0 && char_has_othercase(common, cc))    if (caseless && char_has_othercase(common, cc))
3372      {      {
3373      caseless = char_get_othercase_bit(common, cc);  #ifdef SUPPORT_UTF
3374      if (caseless == 0)      if (common->utf)
3375        return consumed;        {
3376  #ifdef COMPILE_PCRE8        GETCHAR(chr, cc);
3377      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));        if (PRIV(ord2utf)(char_othercase(common, chr), othercase) != len)
3378  #else          return consumed;
3379      if ((caseless & 0x100) != 0)        }
       caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));  
3380      else      else
       caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));  
3381  #endif  #endif
3382          {
3383          chr = *cc;
3384          othercase[0] = TABLE_GET(chr, common->fcc, chr);
3385          }
3386      }      }
3387    else    else
3388      caseless = 0;      caseless = FALSE;
3389    
3390    len_save = len;    len_save = len;
3391    cc_save = cc;    cc_save = cc;
3392    while (TRUE)    while (TRUE)
3393      {      {
3394        oc = othercase;
3395      do      do
3396        {        {
3397        chr = *cc;        chr = *cc;
# Line 3234  while (TRUE) Line 3400  while (TRUE)
3400          return consumed;          return consumed;
3401  #endif  #endif
3402        mask = 0;        mask = 0;
3403        if ((pcre_uint32)len == (caseless & 0xff))        if (caseless)
3404          {          {
3405          mask = caseless >> 8;          mask = *cc ^ *oc;
3406          chr |= mask;          chr |= mask;
3407          }          }
3408    
3409    #ifdef COMPILE_PCRE32
3410          if (chars[0] == NOTACHAR && chars[1] == 0)
3411    #else
3412        if (chars[0] == NOTACHAR)        if (chars[0] == NOTACHAR)
3413    #endif
3414          {          {
3415          chars[0] = chr;          chars[0] = chr;
3416          chars[1] = mask;          chars[1] = mask;
# Line 3254  while (TRUE) Line 3424  while (TRUE)
3424          }          }
3425    
3426        len--;        len--;
3427          consumed++;
3428        if (--max_chars == 0)        if (--max_chars == 0)
3429          return consumed;          return consumed;
       consumed++;  
3430        chars += 2;        chars += 2;
3431        cc++;        cc++;
3432          oc++;
3433        }        }
3434      while (len > 0);      while (len > 0);
3435    
# Line 3284  struct sljit_label *start; Line 3455  struct sljit_label *start;
3455  struct sljit_jump *quit;  struct sljit_jump *quit;
3456  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uint32 chars[MAX_N_CHARS * 2];
3457  pcre_uint8 ones[MAX_N_CHARS];  pcre_uint8 ones[MAX_N_CHARS];
 pcre_uint32 mask;  
 int i, max;  
3458  int offsets[3];  int offsets[3];
3459    pcre_uint32 mask, byte;
3460    int i, max, from;
3461    int range_right = -1, range_len = 4 - 1;
3462    sljit_ub *update_table = NULL;
3463    BOOL in_range;
3464    
3465    /* This is even TRUE, if both are NULL. */
3466    SLJIT_ASSERT(common->read_only_data_ptr == common->read_only_data);
3467    
3468  for (i = 0; i < MAX_N_CHARS; i++)  for (i = 0; i < MAX_N_CHARS; i++)
3469    {    {
# Line 3311  for (i = 0; i < max; i++) Line 3488  for (i = 0; i < max; i++)
3488      }      }
3489    }    }
3490    
3491    in_range = FALSE;
3492    for (i = 0; i <= max; i++)
3493      {
3494      if (i < max && ones[i] <= 1)
3495        {
3496        if (!in_range)
3497          {
3498          in_range = TRUE;
3499          from = i;
3500          }
3501        }
3502      else if (in_range)
3503        {
3504        if ((i - from) > range_len)
3505          {
3506          range_len = i - from;
3507          range_right = i - 1;
3508          }
3509        in_range = FALSE;
3510        }
3511      }
3512    
3513    if (range_right >= 0)
3514      {
3515      /* Since no data is consumed (see the assert in the beginning
3516      of this function), this space can be reallocated. */
3517      if (common->read_only_data)
3518        SLJIT_FREE(common->read_only_data);
3519    
3520      common->read_only_data_size += 256;
3521      common->read_only_data = (sljit_uw *)SLJIT_MALLOC(common->read_only_data_size);
3522      if (common->read_only_data == NULL)
3523        return TRUE;
3524    
3525      update_table = (sljit_ub *)common->read_only_data;
3526      common->read_only_data_ptr = (sljit_uw *)(update_table + 256);
3527      memset(update_table, IN_UCHARS(range_len), 256);
3528    
3529      for (i = 0; i < range_len; i++)
3530        {
3531        byte = chars[(range_right - i) << 1] & 0xff;
3532        if (update_table[byte] > IN_UCHARS(i))
3533          update_table[byte] = IN_UCHARS(i);
3534        mask = chars[((range_right - i) << 1) + 1] & 0xff;
3535        if (mask != 0)
3536          {
3537          byte ^= mask;
3538          if (update_table[byte] > IN_UCHARS(i))
3539            update_table[byte] = IN_UCHARS(i);
3540          }
3541        }
3542      }
3543    
3544  offsets[0] = -1;  offsets[0] = -1;
3545  /* Scan forward. */  /* Scan forward. */
3546  for (i = 0; i < max; i++)  for (i = 0; i < max; i++)
# Line 3325  if (offsets[0] == -1) Line 3555  if (offsets[0] == -1)
3555  /* Scan backward. */  /* Scan backward. */
3556  offsets[1] = -1;  offsets[1] = -1;
3557  for (i = max - 1; i > offsets[0]; i--)  for (i = max - 1; i > offsets[0]; i--)
3558    if (ones[i] <= 2) {    if (ones[i] <= 2 && i != range_right)
3559        {
3560      offsets[1] = i;      offsets[1] = i;
3561      break;      break;
3562    }      }
3563    
3564    /* This case is handled better by fast_forward_first_char. */
3565    if (offsets[1] == -1 && offsets[0] == 0)
3566      return FALSE;
3567    
3568  offsets[2] = -1;  offsets[2] = -1;
3569  if (offsets[1] >= 0)  if (offsets[1] >= 0 && range_right == -1)
3570    {    {
3571    /* Scan from middle. */    /* Scan from middle. */
3572    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 3372  max -= 1; Line 3607  max -= 1;
3607  if (firstline)  if (firstline)
3608    {    {
3609    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3610      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3611    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3612    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));
3613      quit = CMP(SLJIT_C_LESS_EQUAL, STR_END, 0, TMP1, 0);
3614      OP1(SLJIT_MOV, STR_END, 0, TMP1, 0);
3615      JUMPHERE(quit);
3616    }    }
3617  else  else
3618    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));
3619    
3620    #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3621    if (range_right >= 0)
3622      OP1(SLJIT_MOV, RETURN_ADDR, 0, SLJIT_IMM, (sljit_sw)update_table);
3623    #endif
3624    
3625  start = LABEL();  start = LABEL();
3626  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3627    
3628    if (range_right >= 0)
3629      {
3630    #if defined COMPILE_PCRE8 || (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
3631      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right));
3632    #else
3633      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right + 1) - 1);
3634    #endif
3635    
3636    #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3637      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(RETURN_ADDR, TMP1), 0);
3638    #else
3639      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)update_table);
3640    #endif
3641      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3642      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, start);
3643      }
3644    
3645  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]));
3646  if (offsets[1] >= 0)  if (offsets[1] >= 0)
3647    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 3410  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, S Line 3671  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, S
3671  JUMPHERE(quit);  JUMPHERE(quit);
3672    
3673  if (firstline)  if (firstline)
3674      {
3675      if (range_right >= 0)
3676        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3677    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3678      if (range_right >= 0)
3679        {
3680        quit = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
3681        OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
3682        JUMPHERE(quit);
3683        }
3684      }
3685  else  else
3686    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));
3687  return TRUE;  return TRUE;
# Line 3532  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_ Line 3803  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_
3803  skip_char_back(common);  skip_char_back(common);
3804    
3805  loop = LABEL();  loop = LABEL();
3806  read_char_max(common, common->nlmax, TRUE);  read_char_range(common, common->nlmin, common->nlmax, TRUE);
3807  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3808  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3809    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
# Line 3801  JUMPHERE(skipread); Line 4072  JUMPHERE(skipread);
4072    
4073  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
4074  check_str_end(common, &skipread_list);  check_str_end(common, &skipread_list);
4075  peek_char(common);  peek_char(common, READ_CHAR_MAX);
4076    
4077  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
4078  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4360  return cc; Line 4631  return cc;
4631  #define SET_TYPE_OFFSET(value) \  #define SET_TYPE_OFFSET(value) \
4632    if ((value) != typeoffset) \    if ((value) != typeoffset) \
4633      { \      { \
4634      if ((value) > typeoffset) \      if ((value) < typeoffset) \
       OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \  
     else \  
4635        OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \        OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \
4636        else \
4637          OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \
4638      } \      } \
4639    typeoffset = (value);    typeoffset = (value);
4640    
4641  #define SET_CHAR_OFFSET(value) \  #define SET_CHAR_OFFSET(value) \
4642    if ((value) != charoffset) \    if ((value) != charoffset) \
4643      { \      { \
4644      if ((value) > charoffset) \      if ((value) < charoffset) \
       OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)((value) - charoffset)); \  
     else \  
4645        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(charoffset - (value))); \        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(charoffset - (value))); \
4646        else \
4647          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)((value) - charoffset)); \
4648      } \      } \
4649    charoffset = (value);    charoffset = (value);
4650    
# Line 4382  static void compile_xclass_matchingpath( Line 4653  static void compile_xclass_matchingpath(
4653  DEFINE_COMPILER;  DEFINE_COMPILER;
4654  jump_list *found = NULL;  jump_list *found = NULL;
4655  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;
4656  sljit_uw c, charoffset, max = 0;  sljit_uw c, charoffset, max = 256, min = READ_CHAR_MAX;
4657  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4658  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4659  int compares, invertcmp, numberofcmps;  int compares, invertcmp, numberofcmps;
# Line 4395  BOOL needstype = FALSE, needsscript = FA Line 4666  BOOL needstype = FALSE, needsscript = FA
4666  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4667  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4668  const pcre_uint32 *other_cases;  const pcre_uint32 *other_cases;
4669  pcre_int32 typeoffset;  sljit_uw typeoffset;
4670  #endif  #endif
4671    
4672  /* Scanning the necessary info. */  /* Scanning the necessary info. */
4673  cc++;  cc++;
4674  ccbegin = cc;  ccbegin = cc;
4675  compares = 0;  compares = 0;
4676  if (cc[-1] & XCL_MAP) cc += 32 / sizeof(pcre_uchar);  if (cc[-1] & XCL_MAP)
4677      {
4678      min = 0;
4679      cc += 32 / sizeof(pcre_uchar);
4680      }
4681    
4682  while (*cc != XCL_END)  while (*cc != XCL_END)
4683    {    {
# Line 4412  while (*cc != XCL_END) Line 4687  while (*cc != XCL_END)
4687      cc ++;      cc ++;
4688      GETCHARINCTEST(c, cc);      GETCHARINCTEST(c, cc);
4689      if (c > max) max = c;      if (c > max) max = c;
4690        if (c < min) min = c;
4691  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4692      needschar = TRUE;      needschar = TRUE;
4693  #endif  #endif
4694      }      }
4695    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
4696      {      {
4697      cc += 2;      cc ++;
4698  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4699      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (c < min) min = c;
 #endif  
4700      GETCHARINCTEST(c, cc);      GETCHARINCTEST(c, cc);
4701      if (c > max) max = c;      if (c > max) max = c;
4702  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4439  while (*cc != XCL_END) Line 4714  while (*cc != XCL_END)
4714        while (*other_cases != NOTACHAR)        while (*other_cases != NOTACHAR)
4715          {          {
4716          if (*other_cases > max) max = *other_cases;          if (*other_cases > max) max = *other_cases;
4717            if (*other_cases < min) min = *other_cases;
4718          other_cases++;          other_cases++;
4719          }          }
4720        }        }
4721      else      else
4722        max = READ_CHAR_ANY;        {
4723          max = READ_CHAR_MAX;
4724          min = 0;
4725          }
4726    
4727      switch(*cc)      switch(*cc)
4728        {        {
# Line 4488  while (*cc != XCL_END) Line 4767  while (*cc != XCL_END)
4767  /* We are not necessary in utf mode even in 8 bit mode. */  /* We are not necessary in utf mode even in 8 bit mode. */
4768  cc = ccbegin;  cc = ccbegin;
4769  detect_partial_match(common, backtracks);  detect_partial_match(common, backtracks);
4770  read_char_max(common, max, (cc[0] & XCL_NOT) != 0);  read_char_range(common, min, max, (cc[-1] & XCL_NOT) != 0);
4771    
4772  if ((cc[-1] & XCL_HASPROP) == 0)  if ((cc[-1] & XCL_HASPROP) == 0)
4773    {    {
# Line 4511  if ((cc[-1] & XCL_HASPROP) == 0) Line 4790  if ((cc[-1] & XCL_HASPROP) == 0)
4790      cc += 32 / sizeof(pcre_uchar);      cc += 32 / sizeof(pcre_uchar);
4791      }      }
4792    else    else
4793      add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0xff));      {
4794        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, min);
4795        add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, max - min));
4796        }
4797    }    }
4798  else if ((cc[-1] & XCL_MAP) != 0)  else if ((cc[-1] & XCL_MAP) != 0)
4799    {    {
# Line 4945  switch(type) Line 5227  switch(type)
5227    
5228    case OP_ANY:    case OP_ANY:
5229    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5230    read_char_max(common, common->nlmax, TRUE);    read_char_range(common, common->nlmin, common->nlmax, TRUE);
5231    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
5232      {      {
5233      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 5295  switch(type)
5295    
5296    case OP_ANYNL:    case OP_ANYNL:
5297    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5298    read_char_max(common, common->bsr_nlmax, FALSE);    read_char_range(common, common->bsr_nlmin, common->bsr_nlmax, FALSE);
5299    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);
5300    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
5301    end_list = NULL;    end_list = NULL;
# Line 5035  switch(type) Line 5317  switch(type)
5317    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
5318    case OP_HSPACE:    case OP_HSPACE:
5319    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5320    read_char_max(common, 0x3000, type == OP_NOT_HSPACE);    read_char_range(common, 0x9, 0x3000, type == OP_NOT_HSPACE);
5321    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));
5322    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));
5323    return cc;    return cc;
# Line 5043  switch(type) Line 5325  switch(type)
5325    case OP_NOT_VSPACE:    case OP_NOT_VSPACE:
5326    case OP_VSPACE:    case OP_VSPACE:
5327    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5328    read_char_max(common, 0x2029, type == OP_NOT_VSPACE);    read_char_range(common, 0xa, 0x2029, type == OP_NOT_VSPACE);
5329    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));
5330    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));
5331    return cc;    return cc;
# Line 5142  switch(type) Line 5424  switch(type)
5424      else      else
5425        {        {
5426        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);
5427        read_char_max(common, common->nlmax, TRUE);        read_char_range(common, common->nlmin, common->nlmax, TRUE);
5428        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));
5429        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
5430        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 5190  switch(type) Line 5472  switch(type)
5472    else    else
5473      {      {
5474      skip_char_back(common);      skip_char_back(common);
5475      read_char_max(common, common->nlmax, TRUE);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
5476      check_newlinechar(common, common->nltype, backtracks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
5477      }      }
5478    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
# Line 5241  switch(type) Line 5523  switch(type)
5523      }      }
5524    else    else
5525      {      {
5526      peek_char(common);      peek_char(common, common->nlmax);
5527      check_newlinechar(common, common->nltype, backtracks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
5528      }      }
5529    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
# Line 5278  switch(type) Line 5560  switch(type)
5560    
5561    if (type == OP_CHAR || !char_has_othercase(common, cc))    if (type == OP_CHAR || !char_has_othercase(common, cc))
5562      {      {
5563      read_char_max(common, c, FALSE);      read_char_range(common, c, c, FALSE);
5564      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));
5565      return cc + length;      return cc + length;
5566      }      }
5567    oc = char_othercase(common, c);    oc = char_othercase(common, c);
5568    read_char_max(common, c > oc ? c : oc, FALSE);    read_char_range(common, c < oc ? c : oc, c > oc ? c : oc, FALSE);
5569    bit = c ^ oc;    bit = c ^ oc;
5570    if (is_powerof2(bit))    if (is_powerof2(bit))
5571      {      {
# Line 5336  switch(type) Line 5618  switch(type)
5618    
5619    if (type == OP_NOT || !char_has_othercase(common, cc))    if (type == OP_NOT || !char_has_othercase(common, cc))
5620      {      {
5621      read_char_max(common, c, TRUE);      read_char_range(common, c, c, TRUE);
5622      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));
5623      }      }
5624    else    else
5625      {      {
5626      oc = char_othercase(common, c);      oc = char_othercase(common, c);
5627      read_char_max(common, c > oc ? c : oc, TRUE);      read_char_range(common, c < oc ? c : oc, c > oc ? c : oc, TRUE);
5628      bit = c ^ oc;      bit = c ^ oc;
5629      if (is_powerof2(bit))      if (is_powerof2(bit))
5630        {        {
# Line 5363  switch(type) Line 5645  switch(type)
5645    
5646  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5647    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;
5648    read_char_max(common, bit, type == OP_NCLASS);    read_char_range(common, 0, bit, type == OP_NCLASS);
5649  #else  #else
5650    read_char_max(common, 255, type == OP_NCLASS);    read_char_range(common, 0, 255, type == OP_NCLASS);
5651  #endif  #endif
5652    
5653    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 7736  if (*cc == OP_FAIL) Line 8018  if (*cc == OP_FAIL)
8018    return cc + 1;    return cc + 1;
8019    }    }
8020    
8021  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL)  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL || !common->might_be_empty)
8022    {    {
8023    /* No need to check notempty conditions. */    /* No need to check notempty conditions. */
8024    if (common->accept_label == NULL)    if (common->accept_label == NULL)
# Line 8438  if (bra == OP_BRAZERO) Line 8720  if (bra == OP_BRAZERO)
8720  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8721  {  {
8722  DEFINE_COMPILER;  DEFINE_COMPILER;
8723  int opcode, stacksize, count;  int opcode, stacksize, alt_count, alt_max;
8724  int offset = 0;  int offset = 0;
8725  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;
8726  int repeat_ptr = 0, repeat_type = 0, repeat_count = 0;  int repeat_ptr = 0, repeat_type = 0, repeat_count = 0;
8727  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
8728  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
8729  pcre_uchar *ccprev;  pcre_uchar *ccprev;
 jump_list *jumplist = NULL;  
 jump_list *jumplistitem = NULL;  
8730  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
8731  pcre_uchar ket;  pcre_uchar ket;
8732  assert_backtrack *assert;  assert_backtrack *assert;
8733  BOOL has_alternatives;  BOOL has_alternatives;
8734  BOOL needs_control_head = FALSE;  BOOL needs_control_head = FALSE;
8735  struct sljit_jump *brazero = NULL;  struct sljit_jump *brazero = NULL;
8736    struct sljit_jump *alt1 = NULL;
8737    struct sljit_jump *alt2 = NULL;
8738  struct sljit_jump *once = NULL;  struct sljit_jump *once = NULL;
8739  struct sljit_jump *cond = NULL;  struct sljit_jump *cond = NULL;
8740  struct sljit_label *rmin_label = NULL;  struct sljit_label *rmin_label = NULL;
# Line 8490  if (SLJIT_UNLIKELY(opcode == OP_COND) && Line 8772  if (SLJIT_UNLIKELY(opcode == OP_COND) &&
8772  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))
8773    opcode = OP_ONCE;    opcode = OP_ONCE;
8774    
8775    alt_max = has_alternatives ? no_alternatives(ccbegin) : 0;
8776    
8777  /* Decoding the needs_control_head in framesize. */  /* Decoding the needs_control_head in framesize. */
8778  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
8779    {    {
# Line 8603  else if (SLJIT_UNLIKELY(opcode == OP_CON Line 8887  else if (SLJIT_UNLIKELY(opcode == OP_CON
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);
8889    
8890      jumplistitem = sljit_alloc_memory(compiler, sizeof(jump_list));      alt_max = 2;
8891      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);  
8892      }      }
8893    }    }
8894  else if (*cc == OP_ALT)  else if (has_alternatives)
8895    {    {
   /* Build a jump list. Get the last successfully matched branch index. */  
8896    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8897    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;  
       }  
8898    
8899      if (SLJIT_UNLIKELY(!jumplistitem))    if (alt_max > 4)
8900        return;      {
8901        /* Table jump if alt_max is greater than 4. */
8902      jumplistitem->next = NULL;      sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_MEM1(TMP1), (sljit_sw)common->read_only_data_ptr);
8903      jumplistitem->jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, count++);      add_label_addr(common);
8904      cc += GET(cc, 1);      }
8905      else
8906        {
8907        if (alt_max == 4)
8908          alt2 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_uw));
8909        alt1 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, sizeof(sljit_uw));
8910      }      }
   while (*cc == OP_ALT);  
   
   cc = ccbegin + GET(ccbegin, 1);  
8911    }    }
8912    
8913  COMPILE_BACKTRACKINGPATH(current->top);  COMPILE_BACKTRACKINGPATH(current->top);
# Line 8675  if (SLJIT_UNLIKELY(opcode == OP_COND) || Line 8942  if (SLJIT_UNLIKELY(opcode == OP_COND) ||
8942    
8943  if (has_alternatives)  if (has_alternatives)
8944    {    {
8945    count = 1;    alt_count = sizeof(sljit_uw);
8946    do    do
8947      {      {
8948      current->top = NULL;      current->top = NULL;
# Line 8751  if (has_alternatives) Line 9018  if (has_alternatives)
9018        stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);        stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);
9019    
9020      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
9021        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);
9022    
9023      if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0)      if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0)
9024        {        {
# Line 8764  if (has_alternatives) Line 9031  if (has_alternatives)
9031    
9032      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
9033        {        {
9034        SLJIT_ASSERT(jumplist);        if (alt_max > 4)
9035        JUMPHERE(jumplist->jump);          add_label_addr(common);
9036        jumplist = jumplist->next;        else
9037            {
9038            if (alt_count != 2 * sizeof(sljit_uw))
9039              {
9040              JUMPHERE(alt1);
9041              if (alt_max == 3 && alt_count == sizeof(sljit_uw))
9042                alt2 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_uw));
9043              }
9044            else
9045              {
9046              JUMPHERE(alt2);
9047              if (alt_max == 4)
9048                alt1 = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_uw));
9049              }
9050            }
9051          alt_count += sizeof(sljit_uw);
9052        }        }
9053    
9054      COMPILE_BACKTRACKINGPATH(current->top);      COMPILE_BACKTRACKINGPATH(current->top);
# Line 8775  if (has_alternatives) Line 9057  if (has_alternatives)
9057      SLJIT_ASSERT(!current->nextbacktracks);      SLJIT_ASSERT(!current->nextbacktracks);
9058      }      }
9059    while (*cc == OP_ALT);    while (*cc == OP_ALT);
   SLJIT_ASSERT(!jumplist);  
9060    
9061    if (cond != NULL)    if (cond != NULL)
9062      {      {
# Line 9376  pcre_uchar *ccend; Line 9657  pcre_uchar *ccend;
9657  executable_functions *functions;  executable_functions *functions;
9658  void *executable_func;  void *executable_func;
9659  sljit_uw executable_size;  sljit_uw executable_size;
9660    sljit_uw total_length;
9661    label_addr_list *label_addr;
9662  struct sljit_label *mainloop_label = NULL;  struct sljit_label *mainloop_label = NULL;
9663  struct sljit_label *continue_match_label;  struct sljit_label *continue_match_label;
9664  struct sljit_label *empty_match_found_label;  struct sljit_label *empty_match_found_label = NULL;
9665  struct sljit_label *empty_match_backtrack_label;  struct sljit_label *empty_match_backtrack_label = NULL;
9666  struct sljit_label *reset_match_label;  struct sljit_label *reset_match_label;
9667    struct sljit_label *quit_label;
9668  struct sljit_jump *jump;  struct sljit_jump *jump;
9669  struct sljit_jump *minlength_check_failed = NULL;  struct sljit_jump *minlength_check_failed = NULL;
9670  struct sljit_jump *reqbyte_notfound = NULL;  struct sljit_jump *reqbyte_notfound = NULL;
9671  struct sljit_jump *empty_match;  struct sljit_jump *empty_match = NULL;
 struct sljit_label *quit_label;  
9672    
9673  SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);  SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);
9674  study = extra->study_data;  study = extra->study_data;
# Line 9398  memset(common, 0, sizeof(compiler_common Line 9681  memset(common, 0, sizeof(compiler_common
9681  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;
9682    
9683  common->start = rootbacktrack.cc;  common->start = rootbacktrack.cc;
9684    common->read_only_data = NULL;
9685    common->read_only_data_size = 0;
9686    common->read_only_data_ptr = NULL;
9687  common->fcc = tables + fcc_offset;  common->fcc = tables + fcc_offset;
9688  common->lcc = (sljit_sw)(tables + lcc_offset);  common->lcc = (sljit_sw)(tables + lcc_offset);
9689  common->mode = mode;  common->mode = mode;
9690    common->might_be_empty = study->minlength == 0;
9691  common->nltype = NLTYPE_FIXED;  common->nltype = NLTYPE_FIXED;
9692  switch(re->options & PCRE_NEWLINE_BITS)  switch(re->options & PCRE_NEWLINE_BITS)
9693    {    {
# Line 9421  switch(re->options & PCRE_NEWLINE_BITS) Line 9708  switch(re->options & PCRE_NEWLINE_BITS)
9708    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;
9709    default: return;    default: return;
9710    }    }
9711  common->nlmax = READ_CHAR_ANY;  common->nlmax = READ_CHAR_MAX;
9712    common->nlmin = 0;
9713  if ((re->options & PCRE_BSR_ANYCRLF) != 0)  if ((re->options & PCRE_BSR_ANYCRLF) != 0)
9714    common->bsr_nltype = NLTYPE_ANYCRLF;    common->bsr_nltype = NLTYPE_ANYCRLF;
9715  else if ((re->options & PCRE_BSR_UNICODE) != 0)  else if ((re->options & PCRE_BSR_UNICODE) != 0)
# Line 9434  else Line 9722  else
9722    common->bsr_nltype = NLTYPE_ANY;    common->bsr_nltype = NLTYPE_ANY;
9723  #endif  #endif
9724    }    }
9725  common->bsr_nlmax = READ_CHAR_ANY;  common->bsr_nlmax = READ_CHAR_MAX;
9726    common->bsr_nlmin = 0;
9727  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
9728  common->ctypes = (sljit_sw)(tables + ctypes_offset);  common->ctypes = (sljit_sw)(tables + ctypes_offset);
9729  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;
# Line 9459  if (common->utf) Line 9748  if (common->utf)
9748      common->nlmax = common->newline & 0xff;      common->nlmax = common->newline & 0xff;
9749      }      }
9750    
9751      if (common->nltype == NLTYPE_FIXED)
9752        common->nlmin = common->newline & 0xff;
9753      else
9754        common->nlmin = (CHAR_CR < CHAR_NL) ? CHAR_CR : CHAR_NL;
9755    
9756    if (common->bsr_nltype == NLTYPE_ANY)    if (common->bsr_nltype == NLTYPE_ANY)
9757      common->bsr_nlmax = 0x2029;      common->bsr_nlmax = 0x2029;
9758    else    else
9759      common->bsr_nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL;      common->bsr_nlmax = (CHAR_CR > CHAR_NL) ? CHAR_CR : CHAR_NL;
9760      common->bsr_nlmin = (CHAR_CR < CHAR_NL) ? CHAR_CR : CHAR_NL;
9761    }    }
9762  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
9763  ccend = bracketend(rootbacktrack.cc);  ccend = bracketend(common->start);
9764    
9765  /* Calculate the local space size on the stack. */  /* Calculate the local space size on the stack. */
9766  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);
# Line 9478  memset(common->optimized_cbracket, 0, re Line 9773  memset(common->optimized_cbracket, 0, re
9773  memset(common->optimized_cbracket, 1, re->top_bracket + 1);  memset(common->optimized_cbracket, 1, re->top_bracket + 1);
9774  #endif  #endif
9775    
9776  SLJIT_ASSERT(*rootbacktrack.cc == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);  SLJIT_ASSERT(*common->start == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);
9777  #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2  #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2
9778  common->capture_last_ptr = common->ovector_start;  common->capture_last_ptr = common->ovector_start;
9779  common->ovector_start += sizeof(sljit_sw);  common->ovector_start += sizeof(sljit_sw);
9780  #endif  #endif
9781  if (!check_opcode_types(common, rootbacktrack.cc, ccend))  if (!check_opcode_types(common, common->start, ccend))
9782    {    {
9783    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9784    return;    return;
# Line 9546  if (common->capture_last_ptr != 0) Line 9841  if (common->capture_last_ptr != 0)
9841  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));
9842  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);
9843    
9844  common->private_data_ptrs = (int *)SLJIT_MALLOC((ccend - rootbacktrack.cc) * sizeof(sljit_si));  total_length = ccend - common->start;
9845    common->private_data_ptrs = (sljit_si *)SLJIT_MALLOC(total_length * (sizeof(sljit_si) + (common->has_then ? 1 : 0)));
9846  if (!common->private_data_ptrs)  if (!common->private_data_ptrs)
9847    {    {
9848    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9849    return;    return;
9850    }    }
9851  memset(common->private_data_ptrs, 0, (ccend - rootbacktrack.cc) * sizeof(int));  memset(common->private_data_ptrs, 0, total_length * sizeof(sljit_si));
9852    
9853  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);
9854  set_private_data_ptrs(common, &private_data_size, ccend);  set_private_data_ptrs(common, &private_data_size, ccend);
# Line 9565  if (private_data_size > SLJIT_MAX_LOCAL_ Line 9861  if (private_data_size > SLJIT_MAX_LOCAL_
9861    
9862  if (common->has_then)  if (common->has_then)
9863    {    {
9864    common->then_offsets = (pcre_uint8 *)SLJIT_MALLOC(ccend - rootbacktrack.cc);    common->then_offsets = (pcre_uint8 *)(common->private_data_ptrs + total_length);
9865    if (!common->then_offsets)    memset(common->then_offsets, 0, total_length);
9866      set_then_offsets(common, common->start, NULL);
9867      }
9868    
9869    if (common->read_only_data_size > 0)
9870      {
9871      common->read_only_data = (sljit_uw *)SLJIT_MALLOC(common->read_only_data_size);
9872      if (common->read_only_data == NULL)
9873      {      {
9874      SLJIT_FREE(common->optimized_cbracket);      SLJIT_FREE(common->optimized_cbracket);
9875      SLJIT_FREE(common->private_data_ptrs);      SLJIT_FREE(common->private_data_ptrs);
9876      return;      return;
9877      }      }
9878    memset(common->then_offsets, 0, ccend - rootbacktrack.cc);    common->read_only_data_ptr = common->read_only_data;
   set_then_offsets(common, rootbacktrack.cc, NULL);  
9879    }    }
9880    
9881  compiler = sljit_create_compiler();  compiler = sljit_create_compiler();
# Line 9581  if (!compiler) Line 9883  if (!compiler)
9883    {    {
9884    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9885    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
9886    if (common->has_then)    if (common->read_only_data)
9887      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
9888    return;    return;
9889    }    }
9890  common->compiler = compiler;  common->compiler = compiler;
# Line 9621  if ((re->options & PCRE_ANCHORED) == 0) Line 9923  if ((re->options & PCRE_ANCHORED) == 0)
9923    if ((re->options & PCRE_NO_START_OPTIMIZE) == 0)    if ((re->options & PCRE_NO_START_OPTIMIZE) == 0)
9924      {      {
9925      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))
9926        { /* Do nothing */ }        {
9927          /* If read_only_data is reallocated, we might have an allocation failure. */
9928          if (common->read_only_data_size > 0 && common->read_only_data == NULL)
9929            {
9930            sljit_free_compiler(compiler);
9931            SLJIT_FREE(common->optimized_cbracket);
9932            SLJIT_FREE(common->private_data_ptrs);
9933            return;
9934            }
9935          }
9936      else if ((re->flags & PCRE_FIRSTSET) != 0)      else if ((re->flags & PCRE_FIRSTSET) != 0)
9937        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);
9938      else if ((re->flags & PCRE_STARTLINE) != 0)      else if ((re->flags & PCRE_STARTLINE) != 0)
# Line 9668  if (mode == JIT_PARTIAL_SOFT_COMPILE) Line 9979  if (mode == JIT_PARTIAL_SOFT_COMPILE)
9979  else if (mode == JIT_PARTIAL_HARD_COMPILE)  else if (mode == JIT_PARTIAL_HARD_COMPILE)
9980    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);
9981    
9982  compile_matchingpath(common, rootbacktrack.cc, ccend, &rootbacktrack);  compile_matchingpath(common, common->start, ccend, &rootbacktrack);
9983  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
9984    {    {
9985    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
9986    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9987    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
9988    if (common->has_then)    if (common->read_only_data)
9989      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
9990    return;    return;
9991    }    }
9992    
9993  empty_match = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));  if (common->might_be_empty)
9994  empty_match_found_label = LABEL();    {
9995      empty_match = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
9996      empty_match_found_label = LABEL();
9997      }
9998    
9999  common->accept_label = LABEL();  common->accept_label = LABEL();
10000  if (common->accept != NULL)  if (common->accept != NULL)
# Line 9704  if (mode != JIT_COMPILE) Line 10018  if (mode != JIT_COMPILE)
10018    return_with_partial_match(common, common->quit_label);    return_with_partial_match(common, common->quit_label);
10019    }    }
10020    
10021  empty_match_backtrack_label = LABEL();  if (common->might_be_empty)
10022      empty_match_backtrack_label = LABEL();
10023  compile_backtrackingpath(common, rootbacktrack.top);  compile_backtrackingpath(common, rootbacktrack.top);
10024  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
10025    {    {
10026    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
10027    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
10028    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
10029    if (common->has_then)    if (common->read_only_data)
10030      SLJIT_FREE(common->then_offsets);      SLJIT_FREE(common->read_only_data);
10031    return;    return;
10032    }    }
10033    
# Line 9758  JUMPTO(SLJIT_JUMP, common->quit_label); Line 10073  JUMPTO(SLJIT_JUMP, common->quit_label);
10073    
10074  flush_stubs(common);  flush_stubs(common);
10075    
10076  JUMPHERE(empty_match);  if (common->might_be_empty)
10077  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);    {
10078  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));    JUMPHERE(empty_match);
10079  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_backtrack_label);    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
10080  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));
10081  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);
10082  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));
10083  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);
10084  JUMPTO(SLJIT_JUMP, empty_match_backtrack_label);    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
10085      CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, empty_match_found_label);
10086      JUMPTO(SLJIT_JUMP, empty_match_backtrack_label);
10087      }
10088    
10089  common->currententry = common->entries;  common->currententry = common->entries;
10090  common->local_exit = TRUE;  common->local_exit = TRUE;
# Line 9780  while (common->currententry != NULL) Line 10098  while (common->currententry != NULL)
10098      sljit_free_compiler(compiler);      sljit_free_compiler(compiler);
10099      SLJIT_FREE(common->optimized_cbracket);      SLJIT_FREE(common->optimized_cbracket);
10100      SLJIT_FREE(common->private_data_ptrs);      SLJIT_FREE(common->private_data_ptrs);
10101      if (common->has_then)      if (common->read_only_data)
10102        SLJIT_FREE(common->then_offsets);        SLJIT_FREE(common->read_only_data);
10103      return;      return;
10104      }      }
10105    flush_stubs(common);    flush_stubs(common);
# Line 9891  if (common->getucd != NULL) Line 10209  if (common->getucd != NULL)
10209    }    }
10210  #endif  #endif
10211    
10212    SLJIT_ASSERT(common->read_only_data + (common->read_only_data_size >> SLJIT_WORD_SHIFT) == common->read_only_data_ptr);
10213  SLJIT_FREE(common->optimized_cbracket);  SLJIT_FREE(common->optimized_cbracket);
10214  SLJIT_FREE(common->private_data_ptrs);  SLJIT_FREE(common->private_data_ptrs);
 if (common->has_then)  
   SLJIT_FREE(common->then_offsets);  
10215    
10216  executable_func = sljit_generate_code(compiler);  executable_func = sljit_generate_code(compiler);
10217  executable_size = sljit_get_generated_code_size(compiler);  executable_size = sljit_get_generated_code_size(compiler);
10218    label_addr = common->label_addrs;
10219    while (label_addr != NULL)
10220      {
10221      *label_addr->addr = sljit_get_label_addr(label_addr->label);
10222      label_addr = label_addr->next;
10223      }
10224  sljit_free_compiler(compiler);  sljit_free_compiler(compiler);
10225  if (executable_func == NULL)  if (executable_func == NULL)
10226      {
10227      if (common->read_only_data)
10228        SLJIT_FREE(common->read_only_data);
10229    return;    return;
10230      }
10231    
10232  /* Reuse the function descriptor if possible. */  /* Reuse the function descriptor if possible. */
10233  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 9920  else Line 10247  else
10247    if (functions == NULL)    if (functions == NULL)
10248      {      {
10249      /* This case is highly unlikely since we just recently      /* This case is highly unlikely since we just recently
10250      freed a lot of memory. Although not impossible. */      freed a lot of memory. Not impossible though. */
10251      sljit_free_code(executable_func);      sljit_free_code(executable_func);
10252        if (common->read_only_data)
10253          SLJIT_FREE(common->read_only_data);
10254      return;      return;
10255      }      }
10256    memset(functions, 0, sizeof(executable_functions));    memset(functions, 0, sizeof(executable_functions));
# Line 9932  else Line 10261  else
10261    }    }
10262    
10263  functions->executable_funcs[mode] = executable_func;  functions->executable_funcs[mode] = executable_func;
10264    functions->read_only_data[mode] = common->read_only_data;
10265  functions->executable_sizes[mode] = executable_size;  functions->executable_sizes[mode] = executable_size;
10266  }  }
10267    
# Line 10118  for (i = 0; i < JIT_NUMBER_OF_COMPILE_MO Line 10448  for (i = 0; i < JIT_NUMBER_OF_COMPILE_MO
10448    {    {
10449    if (functions->executable_funcs[i] != NULL)    if (functions->executable_funcs[i] != NULL)
10450      sljit_free_code(functions->executable_funcs[i]);      sljit_free_code(functions->executable_funcs[i]);
10451      if (functions->read_only_data[i] != NULL)
10452        SLJIT_FREE(functions->read_only_data[i]);
10453    }    }
10454  SLJIT_FREE(functions);  SLJIT_FREE(functions);
10455  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.5