/[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 1269 by zherczeg, Mon Mar 4 10:47:12 2013 UTC revision 1427 by zherczeg, Wed Jan 1 15:15:09 2014 UTC
# Line 71  system files. */ Line 71  system files. */
71     2 - Enable capture_last_ptr (includes option 1). */     2 - Enable capture_last_ptr (includes option 1). */
72  /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */  /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */
73    
74    /* 1 - Always have a control head. */
75    /* #define DEBUG_FORCE_CONTROL_HEAD 1 */
76    
77  /* Allocate memory for the regex stack on the real machine stack.  /* Allocate memory for the regex stack on the real machine stack.
78  Fast, but limited size. */  Fast, but limited size. */
79  #define MACHINE_STACK_SIZE 32768  #define MACHINE_STACK_SIZE 32768
# Line 165  typedef struct jit_arguments { Line 168  typedef struct jit_arguments {
168    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
169    void *callout_data;    void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171      pcre_uint32 limit_match;
172    int real_offset_count;    int real_offset_count;
173    int offset_count;    int offset_count;
   int call_limit;  
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 179  typedef struct executable_functions { Line 182  typedef struct executable_functions {
182    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184    pcre_uint32 top_bracket;    pcre_uint32 top_bracket;
185      pcre_uint32 limit_match;
186    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
187  } executable_functions;  } executable_functions;
188    
# Line 193  typedef struct stub_list { Line 197  typedef struct stub_list {
197    struct stub_list *next;    struct stub_list *next;
198  } stub_list;  } stub_list;
199    
200  enum frame_types { no_frame = -1, no_stack = -2 };  enum frame_types {
201      no_frame = -1,
202      no_stack = -2
203    };
204    
205    enum control_types {
206      type_mark = 0,
207      type_then_trap = 1
208    };
209    
210  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
213  code generator. It is allocated by compile_matchingpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
214  the aguments for compile_backtrackingpath. Must be the first member  the arguments for compile_backtrackingpath. Must be the first member
215  of its descendants. */  of its descendants. */
216  typedef struct backtrack_common {  typedef struct backtrack_common {
217    /* Concatenation stack. */    /* Concatenation stack. */
# Line 215  typedef struct backtrack_common { Line 227  typedef struct backtrack_common {
227  typedef struct assert_backtrack {  typedef struct assert_backtrack {
228    backtrack_common common;    backtrack_common common;
229    jump_list *condfailed;    jump_list *condfailed;
230    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
231    int framesize;    int framesize;
232    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
233    int private_data_ptr;    int private_data_ptr;
# Line 236  typedef struct bracket_backtrack { Line 248  typedef struct bracket_backtrack {
248      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
249      jump_list *condfailed;      jump_list *condfailed;
250      assert_backtrack *assert;      assert_backtrack *assert;
251      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
252      int framesize;      int framesize;
253    } u;    } u;
254    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
# Line 271  typedef struct recurse_entry { Line 283  typedef struct recurse_entry {
283    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
284    jump_list *calls;    jump_list *calls;
285    /* Points to the starting opcode. */    /* Points to the starting opcode. */
286    int start;    sljit_sw start;
287  } recurse_entry;  } recurse_entry;
288    
289  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
# Line 279  typedef struct recurse_backtrack { Line 291  typedef struct recurse_backtrack {
291    BOOL inlined_pattern;    BOOL inlined_pattern;
292  } recurse_backtrack;  } recurse_backtrack;
293    
294  #define MAX_RANGE_SIZE 6  #define OP_THEN_TRAP OP_TABLE_LENGTH
295    
296    typedef struct then_trap_backtrack {
297      backtrack_common common;
298      /* If then_trap is not NULL, this structure contains the real
299      then_trap for the backtracking path. */
300      struct then_trap_backtrack *then_trap;
301      /* Points to the starting opcode. */
302      sljit_sw start;
303      /* Exit point for the then opcodes of this alternative. */
304      jump_list *quit;
305      /* Frame size of the current alternative. */
306      int framesize;
307    } then_trap_backtrack;
308    
309    #define MAX_RANGE_SIZE 4
310    
311  typedef struct compiler_common {  typedef struct compiler_common {
312      /* The sljit ceneric compiler. */
313    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
314      /* First byte code. */
315    pcre_uchar *start;    pcre_uchar *start;
   
316    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
317    int *private_data_ptrs;    sljit_si *private_data_ptrs;
318    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
319    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
320      /* Tells whether the starting offset is a target of then. */
321      pcre_uint8 *then_offsets;
322      /* Current position where a THEN must jump. */
323      then_trap_backtrack *then_trap;
324    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
325    int cbraptr;    int cbra_ptr;
326    /* OVector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
327    int ovector_start;    int ovector_start;
328    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
329    int req_char_ptr;    int req_char_ptr;
# Line 305  typedef struct compiler_common { Line 337  typedef struct compiler_common {
337    int first_line_end;    int first_line_end;
338    /* Points to the marked string. */    /* Points to the marked string. */
339    int mark_ptr;    int mark_ptr;
340      /* Recursive control verb management chain. */
341      int control_head_ptr;
342    /* Points to the last matched capture block index. */    /* Points to the last matched capture block index. */
343    int capture_last_ptr;    int capture_last_ptr;
344      /* Points to the starting position of the current match. */
345      int start_ptr;
346    
347    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
348    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
349    sljit_sw lcc;    sljit_sw lcc;
350    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
351    int mode;    int mode;
352      /* \K is found in the pattern. */
353      BOOL has_set_som;
354      /* (*SKIP:arg) is found in the pattern. */
355      BOOL has_skip_arg;
356      /* (*THEN) is found in the pattern. */
357      BOOL has_then;
358      /* Needs to know the start position anytime. */
359      BOOL needs_start_ptr;
360      /* Currently in recurse or negative assert. */
361      BOOL local_exit;
362      /* Currently in a positive assert. */
363      BOOL positive_assert;
364    /* Newline control. */    /* Newline control. */
365    int nltype;    int nltype;
366      pcre_uint32 nlmax;
367      pcre_uint32 nlmin;
368    int newline;    int newline;
369    int bsr_nltype;    int bsr_nltype;
370      pcre_uint32 bsr_nlmax;
371      pcre_uint32 bsr_nlmin;
372    /* Dollar endonly. */    /* Dollar endonly. */
373    int endonly;    int endonly;
   BOOL has_set_som;  
374    /* Tables. */    /* Tables. */
375    sljit_sw ctypes;    sljit_sw ctypes;
   int digits[2 + MAX_RANGE_SIZE];  
376    /* Named capturing brackets. */    /* Named capturing brackets. */
377    sljit_uw name_table;    pcre_uchar *name_table;
378    sljit_sw name_count;    sljit_sw name_count;
379    sljit_sw name_entry_size;    sljit_sw name_entry_size;
380    
# Line 338  typedef struct compiler_common { Line 388  typedef struct compiler_common {
388    recurse_entry *currententry;    recurse_entry *currententry;
389    jump_list *partialmatch;    jump_list *partialmatch;
390    jump_list *quit;    jump_list *quit;
391      jump_list *positive_assert_quit;
392    jump_list *forced_quit;    jump_list *forced_quit;
393    jump_list *accept;    jump_list *accept;
394    jump_list *calllimit;    jump_list *calllimit;
# Line 349  typedef struct compiler_common { Line 400  typedef struct compiler_common {
400    jump_list *vspace;    jump_list *vspace;
401    jump_list *casefulcmp;    jump_list *casefulcmp;
402    jump_list *caselesscmp;    jump_list *caselesscmp;
403      jump_list *reset_match;
404    BOOL jscript_compat;    BOOL jscript_compat;
405  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
406    BOOL utf;    BOOL utf;
407  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
408    BOOL use_ucp;    BOOL use_ucp;
409  #endif  #endif
 #ifndef COMPILE_PCRE32  
   jump_list *utfreadchar;  
 #endif  
410  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
411      jump_list *utfreadchar;
412      jump_list *utfreadchar16;
413    jump_list *utfreadtype8;    jump_list *utfreadtype8;
414  #endif  #endif
415  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
# Line 415  typedef struct compare_context { Line 466  typedef struct compare_context {
466  #define STACK_TOP     SLJIT_SCRATCH_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
467  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
468  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
469  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define COUNT_MATCH   SLJIT_SAVED_EREG2
470  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
471    
472  /* Local space layout. */  /* Local space layout. */
# Line 426  typedef struct compare_context { Line 477  typedef struct compare_context {
477  #define POSSESSIVE0      (2 * sizeof(sljit_sw))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
478  #define POSSESSIVE1      (3 * sizeof(sljit_sw))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
479  /* Max limit of recursions. */  /* Max limit of recursions. */
480  #define CALL_LIMIT       (4 * sizeof(sljit_sw))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
481  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
482  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
483  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
484  the start pointers when the end of the capturing group has not yet reached. */  the start pointers when the end of the capturing group has not yet reached. */
485  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
486  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))  #define OVECTOR(i)       (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw))
487  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_sw))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
488  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
489    
490  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
# Line 475  the start pointers when the end of the c Line 526  the start pointers when the end of the c
526  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
527    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
528    
529    #define READ_CHAR_MAX 0x7fffffff
530    
531  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
532  {  {
533  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 484  cc += 1 + LINK_SIZE; Line 537  cc += 1 + LINK_SIZE;
537  return cc;  return cc;
538  }  }
539    
540    static int ones_in_half_byte[16] = {
541      /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
542      /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
543    };
544    
545  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
546   next_opcode   next_opcode
547   get_private_data_length   check_opcode_types
548   set_private_data_ptrs   set_private_data_ptrs
549   get_framesize   get_framesize
550   init_frame   init_frame
551   get_private_data_length_for_copy   get_private_data_copy_length
552   copy_private_data   copy_private_data
553   compile_matchingpath   compile_matchingpath
554   compile_backtrackingpath   compile_backtrackingpath
# Line 536  switch(*cc) Line 594  switch(*cc)
594    case OP_CRMINQUERY:    case OP_CRMINQUERY:
595    case OP_CRRANGE:    case OP_CRRANGE:
596    case OP_CRMINRANGE:    case OP_CRMINRANGE:
597      case OP_CRPOSSTAR:
598      case OP_CRPOSPLUS:
599      case OP_CRPOSQUERY:
600      case OP_CRPOSRANGE:
601    case OP_CLASS:    case OP_CLASS:
602    case OP_NCLASS:    case OP_NCLASS:
603    case OP_REF:    case OP_REF:
604    case OP_REFI:    case OP_REFI:
605      case OP_DNREF:
606      case OP_DNREFI:
607    case OP_RECURSE:    case OP_RECURSE:
608    case OP_CALLOUT:    case OP_CALLOUT:
609    case OP_ALT:    case OP_ALT:
# Line 565  switch(*cc) Line 629  switch(*cc)
629    case OP_SCBRAPOS:    case OP_SCBRAPOS:
630    case OP_SCOND:    case OP_SCOND:
631    case OP_CREF:    case OP_CREF:
632    case OP_NCREF:    case OP_DNCREF:
633    case OP_RREF:    case OP_RREF:
634    case OP_NRREF:    case OP_DNRREF:
635    case OP_DEF:    case OP_DEF:
636    case OP_BRAZERO:    case OP_BRAZERO:
637    case OP_BRAMINZERO:    case OP_BRAMINZERO:
638    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
639      case OP_PRUNE:
640      case OP_SKIP:
641      case OP_THEN:
642    case OP_COMMIT:    case OP_COMMIT:
643    case OP_FAIL:    case OP_FAIL:
644    case OP_ACCEPT:    case OP_ACCEPT:
# Line 670  switch(*cc) Line 737  switch(*cc)
737  #endif  #endif
738    
739    case OP_MARK:    case OP_MARK:
740      case OP_PRUNE_ARG:
741      case OP_SKIP_ARG:
742      case OP_THEN_ARG:
743    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
744    
745    default:    default:
746      /* All opcodes are supported now! */
747      SLJIT_ASSERT_STOP();
748    return NULL;    return NULL;
749    }    }
750  }  }
751    
752    static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
753    {
754    int count;
755    pcre_uchar *slot;
756    
757    /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
758    while (cc < ccend)
759      {
760      switch(*cc)
761        {
762        case OP_SET_SOM:
763        common->has_set_som = TRUE;
764        cc += 1;
765        break;
766    
767        case OP_REF:
768        case OP_REFI:
769        common->optimized_cbracket[GET2(cc, 1)] = 0;
770        cc += 1 + IMM2_SIZE;
771        break;
772    
773        case OP_CBRAPOS:
774        case OP_SCBRAPOS:
775        common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
776        cc += 1 + LINK_SIZE + IMM2_SIZE;
777        break;
778    
779        case OP_COND:
780        case OP_SCOND:
781        /* Only AUTO_CALLOUT can insert this opcode. We do
782           not intend to support this case. */
783        if (cc[1 + LINK_SIZE] == OP_CALLOUT)
784          return FALSE;
785        cc += 1 + LINK_SIZE;
786        break;
787    
788        case OP_CREF:
789        common->optimized_cbracket[GET2(cc, 1)] = 0;
790        cc += 1 + IMM2_SIZE;
791        break;
792    
793        case OP_DNREF:
794        case OP_DNREFI:
795        case OP_DNCREF:
796        count = GET2(cc, 1 + IMM2_SIZE);
797        slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
798        while (count-- > 0)
799          {
800          common->optimized_cbracket[GET2(slot, 0)] = 0;
801          slot += common->name_entry_size;
802          }
803        cc += 1 + 2 * IMM2_SIZE;
804        break;
805    
806        case OP_RECURSE:
807        /* Set its value only once. */
808        if (common->recursive_head_ptr == 0)
809          {
810          common->recursive_head_ptr = common->ovector_start;
811          common->ovector_start += sizeof(sljit_sw);
812          }
813        cc += 1 + LINK_SIZE;
814        break;
815    
816        case OP_CALLOUT:
817        if (common->capture_last_ptr == 0)
818          {
819          common->capture_last_ptr = common->ovector_start;
820          common->ovector_start += sizeof(sljit_sw);
821          }
822        cc += 2 + 2 * LINK_SIZE;
823        break;
824    
825        case OP_THEN_ARG:
826        common->has_then = TRUE;
827        common->control_head_ptr = 1;
828        /* Fall through. */
829    
830        case OP_PRUNE_ARG:
831        common->needs_start_ptr = TRUE;
832        /* Fall through. */
833    
834        case OP_MARK:
835        if (common->mark_ptr == 0)
836          {
837          common->mark_ptr = common->ovector_start;
838          common->ovector_start += sizeof(sljit_sw);
839          }
840        cc += 1 + 2 + cc[1];
841        break;
842    
843        case OP_THEN:
844        common->has_then = TRUE;
845        common->control_head_ptr = 1;
846        /* Fall through. */
847    
848        case OP_PRUNE:
849        case OP_SKIP:
850        common->needs_start_ptr = TRUE;
851        cc += 1;
852        break;
853    
854        case OP_SKIP_ARG:
855        common->control_head_ptr = 1;
856        common->has_skip_arg = TRUE;
857        cc += 1 + 2 + cc[1];
858        break;
859    
860        default:
861        cc = next_opcode(common, cc);
862        if (cc == NULL)
863          return FALSE;
864        break;
865        }
866      }
867    return TRUE;
868    }
869    
870    static int get_class_iterator_size(pcre_uchar *cc)
871    {
872    switch(*cc)
873      {
874      case OP_CRSTAR:
875      case OP_CRPLUS:
876      return 2;
877    
878      case OP_CRMINSTAR:
879      case OP_CRMINPLUS:
880      case OP_CRQUERY:
881      case OP_CRMINQUERY:
882      return 1;
883    
884      case OP_CRRANGE:
885      case OP_CRMINRANGE:
886      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
887        return 0;
888      return 2;
889    
890      default:
891      return 0;
892      }
893    }
894    
895    static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
896    {
897    pcre_uchar *end = bracketend(begin);
898    pcre_uchar *next;
899    pcre_uchar *next_end;
900    pcre_uchar *max_end;
901    pcre_uchar type;
902    sljit_sw length = end - begin;
903    int min, max, i;
904    
905    /* Detect fixed iterations first. */
906    if (end[-(1 + LINK_SIZE)] != OP_KET)
907      return FALSE;
908    
909    /* Already detected repeat. */
910    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
911      return TRUE;
912    
913    next = end;
914    min = 1;
915    while (1)
916      {
917      if (*next != *begin)
918        break;
919      next_end = bracketend(next);
920      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
921        break;
922      next = next_end;
923      min++;
924      }
925    
926    if (min == 2)
927      return FALSE;
928    
929    max = 0;
930    max_end = next;
931    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
932      {
933      type = *next;
934      while (1)
935        {
936        if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
937          break;
938        next_end = bracketend(next + 2 + LINK_SIZE);
939        if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
940          break;
941        next = next_end;
942        max++;
943        }
944    
945      if (next[0] == type && next[1] == *begin && max >= 1)
946        {
947        next_end = bracketend(next + 1);
948        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
949          {
950          for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
951            if (*next_end != OP_KET)
952              break;
953    
954          if (i == max)
955            {
956            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
957            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
958            /* +2 the original and the last. */
959            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
960            if (min == 1)
961              return TRUE;
962            min--;
963            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
964            }
965          }
966        }
967      }
968    
969    if (min >= 3)
970      {
971      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
972      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
973      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
974      return TRUE;
975      }
976    
977    return FALSE;
978    }
979    
980  #define CASE_ITERATOR_PRIVATE_DATA_1 \  #define CASE_ITERATOR_PRIVATE_DATA_1 \
981      case OP_MINSTAR: \      case OP_MINSTAR: \
982      case OP_MINPLUS: \      case OP_MINPLUS: \
# Line 729  switch(*cc) Line 1029  switch(*cc)
1029      case OP_TYPEUPTO: \      case OP_TYPEUPTO: \
1030      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
1031    
1032  static int get_class_iterator_size(pcre_uchar *cc)  static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
 {  
 switch(*cc)  
   {  
   case OP_CRSTAR:  
   case OP_CRPLUS:  
   return 2;  
   
   case OP_CRMINSTAR:  
   case OP_CRMINPLUS:  
   case OP_CRQUERY:  
   case OP_CRMINQUERY:  
   return 1;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))  
     return 0;  
   return 2;  
   
   default:  
   return 0;  
   }  
 }  
   
 static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  
1033  {  {
1034  int private_data_length = 0;  pcre_uchar *cc = common->start;
1035  pcre_uchar *alternative;  pcre_uchar *alternative;
 pcre_uchar *name;  
1036  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1037  int space, size, i;  int private_data_ptr = *private_data_start;
1038  pcre_uint32 bracketlen;  int space, size, bracketlen;
1039    
 /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  
1040  while (cc < ccend)  while (cc < ccend)
1041    {    {
1042    space = 0;    space = 0;
1043    size = 0;    size = 0;
1044    bracketlen = 0;    bracketlen = 0;
1045      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1046        return;
1047    
1048      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1049        if (detect_repeat(common, cc))
1050          {
1051          /* These brackets are converted to repeats, so no global
1052          based single character repeat is allowed. */
1053          if (cc >= end)
1054            end = bracketend(cc);
1055          }
1056    
1057    switch(*cc)    switch(*cc)
1058      {      {
1059      case OP_SET_SOM:      case OP_KET:
1060      common->has_set_som = TRUE;      if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1061      cc += 1;        {
1062      break;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1063          private_data_ptr += sizeof(sljit_sw);
1064      case OP_REF:        cc += common->private_data_ptrs[cc + 1 - common->start];
1065      case OP_REFI:        }
1066      common->optimized_cbracket[GET2(cc, 1)] = 0;      cc += 1 + LINK_SIZE;
     cc += 1 + IMM2_SIZE;  
1067      break;      break;
1068    
1069      case OP_ASSERT:      case OP_ASSERT:
# Line 791  while (cc < ccend) Line 1075  while (cc < ccend)
1075      case OP_BRAPOS:      case OP_BRAPOS:
1076      case OP_SBRA:      case OP_SBRA:
1077      case OP_SBRAPOS:      case OP_SBRAPOS:
1078      private_data_length += sizeof(sljit_sw);      case OP_SCOND:
1079        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1080        private_data_ptr += sizeof(sljit_sw);
1081      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1082      break;      break;
1083    
1084      case OP_CBRAPOS:      case OP_CBRAPOS:
1085      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1086      private_data_length += sizeof(sljit_sw);      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1087      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      private_data_ptr += sizeof(sljit_sw);
1088      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1089      break;      break;
1090    
1091      case OP_COND:      case OP_COND:
1092      case OP_SCOND:      /* Might be a hidden SCOND. */
1093      /* Only AUTO_CALLOUT can insert this opcode. We do      alternative = cc + GET(cc, 1);
1094         not intend to support this case. */      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
     if (cc[1 + LINK_SIZE] == OP_CALLOUT)  
       return -1;  
   
     if (*cc == OP_COND)  
1095        {        {
1096        /* Might be a hidden SCOND. */        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1097        alternative = cc + GET(cc, 1);        private_data_ptr += sizeof(sljit_sw);
       if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)  
         private_data_length += sizeof(sljit_sw);  
       }  
     else  
       private_data_length += sizeof(sljit_sw);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_CREF:  
     i = GET2(cc, 1);  
     common->optimized_cbracket[i] = 0;  
     cc += 1 + IMM2_SIZE;  
     break;  
   
     case OP_NCREF:  
     bracketlen = GET2(cc, 1);  
     name = (pcre_uchar *)common->name_table;  
     alternative = name;  
     for (i = 0; i < common->name_count; i++)  
       {  
       if (GET2(name, 0) == bracketlen) break;  
       name += common->name_entry_size;  
       }  
     SLJIT_ASSERT(i != common->name_count);  
   
     for (i = 0; i < common->name_count; i++)  
       {  
       if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)  
         common->optimized_cbracket[GET2(alternative, 0)] = 0;  
       alternative += common->name_entry_size;  
       }  
     bracketlen = 0;  
     cc += 1 + IMM2_SIZE;  
     break;  
   
     case OP_BRA:  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_CBRA:  
     case OP_SCBRA:  
     bracketlen = 1 + LINK_SIZE + IMM2_SIZE;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_1  
     space = 1;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_2A  
     space = 2;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_2B  
     space = 2;  
     size = -(2 + IMM2_SIZE);  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_1  
     space = 1;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_2A  
     if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)  
       space = 2;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_2B  
     if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)  
       space = 2;  
     size = 1 + IMM2_SIZE;  
     break;  
   
     case OP_CLASS:  
     case OP_NCLASS:  
     size += 1 + 32 / sizeof(pcre_uchar);  
     space = get_class_iterator_size(cc + size);  
     break;  
   
 #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  
     case OP_XCLASS:  
     size = GET(cc, 1);  
     space = get_class_iterator_size(cc + size);  
     break;  
 #endif  
   
     case OP_RECURSE:  
     /* Set its value only once. */  
     if (common->recursive_head_ptr == 0)  
       {  
       common->recursive_head_ptr = common->ovector_start;  
       common->ovector_start += sizeof(sljit_sw);  
       }  
     cc += 1 + LINK_SIZE;  
     break;  
   
     case OP_CALLOUT:  
     if (common->capture_last_ptr == 0)  
       {  
       common->capture_last_ptr = common->ovector_start;  
       common->ovector_start += sizeof(sljit_sw);  
       }  
     cc += 2 + 2 * LINK_SIZE;  
     break;  
   
     case OP_MARK:  
     if (common->mark_ptr == 0)  
       {  
       common->mark_ptr = common->ovector_start;  
       common->ovector_start += sizeof(sljit_sw);  
       }  
     cc += 1 + 2 + cc[1];  
     break;  
   
     default:  
     cc = next_opcode(common, cc);  
     if (cc == NULL)  
       return -1;  
     break;  
     }  
   
   if (space > 0 && cc >= end)  
     private_data_length += sizeof(sljit_sw) * space;  
   
   if (size != 0)  
     {  
     if (size < 0)  
       {  
       cc += -size;  
 #ifdef SUPPORT_UTF  
       if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
       }  
     else  
       cc += size;  
     }  
   
   if (bracketlen != 0)  
     {  
     if (cc >= end)  
       {  
       end = bracketend(cc);  
       if (end[-1 - LINK_SIZE] == OP_KET)  
         end = NULL;  
       }  
     cc += bracketlen;  
     }  
   }  
 return private_data_length;  
 }  
   
 static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)  
 {  
 pcre_uchar *cc = common->start;  
 pcre_uchar *alternative;  
 pcre_uchar *end = NULL;  
 int space, size, bracketlen;  
   
 while (cc < ccend)  
   {  
   space = 0;  
   size = 0;  
   bracketlen = 0;  
   switch(*cc)  
     {  
     case OP_ASSERT:  
     case OP_ASSERT_NOT:  
     case OP_ASSERTBACK:  
     case OP_ASSERTBACK_NOT:  
     case OP_ONCE:  
     case OP_ONCE_NC:  
     case OP_BRAPOS:  
     case OP_SBRA:  
     case OP_SBRAPOS:  
     case OP_SCOND:  
     common->private_data_ptrs[cc - common->start] = private_data_ptr;  
     private_data_ptr += sizeof(sljit_sw);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_CBRAPOS:  
     case OP_SCBRAPOS:  
     common->private_data_ptrs[cc - common->start] = private_data_ptr;  
     private_data_ptr += sizeof(sljit_sw);  
     bracketlen = 1 + LINK_SIZE + IMM2_SIZE;  
     break;  
   
     case OP_COND:  
     /* Might be a hidden SCOND. */  
     alternative = cc + GET(cc, 1);  
     if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)  
       {  
       common->private_data_ptrs[cc - common->start] = private_data_ptr;  
       private_data_ptr += sizeof(sljit_sw);  
1098        }        }
1099      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1100      break;      break;
# Line 1074  while (cc < ccend) Line 1159  while (cc < ccend)
1159      break;      break;
1160      }      }
1161    
1162      /* Character iterators, which are not inside a repeated bracket,
1163         gets a private slot instead of allocating it on the stack. */
1164    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1165      {      {
1166      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
# Line 1104  while (cc < ccend) Line 1191  while (cc < ccend)
1191      cc += bracketlen;      cc += bracketlen;
1192      }      }
1193    }    }
1194    *private_data_start = private_data_ptr;
1195  }  }
1196    
1197  /* Returns with a frame_types (always < 0) if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1198  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL* needs_control_head)
1199  {  {
 pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);  
1200  int length = 0;  int length = 0;
1201  int possessive = 0;  int possessive = 0;
1202  BOOL stack_restore = FALSE;  BOOL stack_restore = FALSE;
# Line 1118  BOOL setmark_found = recursive; Line 1205  BOOL setmark_found = recursive;
1205  /* The last capture is a local variable even for recursions. */  /* The last capture is a local variable even for recursions. */
1206  BOOL capture_last_found = FALSE;  BOOL capture_last_found = FALSE;
1207    
1208  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1209    SLJIT_ASSERT(common->control_head_ptr != 0);
1210    *needs_control_head = TRUE;
1211    #else
1212    *needs_control_head = FALSE;
1213    #endif
1214    
1215    if (ccend == NULL)
1216    {    {
1217    possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1218    /* This is correct regardless of common->capture_last_ptr. */    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1219    capture_last_found = TRUE;      {
1220        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1221        /* This is correct regardless of common->capture_last_ptr. */
1222        capture_last_found = TRUE;
1223        }
1224      cc = next_opcode(common, cc);
1225    }    }
1226    
 cc = next_opcode(common, cc);  
1227  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1228  while (cc < ccend)  while (cc < ccend)
1229    switch(*cc)    switch(*cc)
# Line 1142  while (cc < ccend) Line 1240  while (cc < ccend)
1240      break;      break;
1241    
1242      case OP_MARK:      case OP_MARK:
1243        case OP_PRUNE_ARG:
1244        case OP_THEN_ARG:
1245      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1246      stack_restore = TRUE;      stack_restore = TRUE;
1247      if (!setmark_found)      if (!setmark_found)
# Line 1149  while (cc < ccend) Line 1249  while (cc < ccend)
1249        length += 2;        length += 2;
1250        setmark_found = TRUE;        setmark_found = TRUE;
1251        }        }
1252        if (common->control_head_ptr != 0)
1253          *needs_control_head = TRUE;
1254      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1255      break;      break;
1256    
# Line 1268  if (length > 0) Line 1370  if (length > 0)
1370  return stack_restore ? no_frame : no_stack;  return stack_restore ? no_frame : no_stack;
1371  }  }
1372    
1373  static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive)  static void init_frame(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, int stackpos, int stacktop, BOOL recursive)
1374  {  {
1375  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);  
1376  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1377  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1378  /* The last capture is a local variable even for recursions. */  /* The last capture is a local variable even for recursions. */
# Line 1283  SLJIT_UNUSED_ARG(stacktop); Line 1384  SLJIT_UNUSED_ARG(stacktop);
1384  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1385    
1386  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1387  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1388    cc = next_opcode(common, cc);    {
1389      ccend = bracketend(cc) - (1 + LINK_SIZE);
1390      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1391        cc = next_opcode(common, cc);
1392      }
1393    
1394  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1395  while (cc < ccend)  while (cc < ccend)
1396    switch(*cc)    switch(*cc)
# Line 1304  while (cc < ccend) Line 1410  while (cc < ccend)
1410      break;      break;
1411    
1412      case OP_MARK:      case OP_MARK:
1413        case OP_PRUNE_ARG:
1414        case OP_THEN_ARG:
1415      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1416      if (!setmark_found)      if (!setmark_found)
1417        {        {
# Line 1384  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), st Line 1492  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), st
1492  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1493  }  }
1494    
1495  static SLJIT_INLINE int get_private_data_length_for_copy(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static SLJIT_INLINE int get_private_data_copy_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL needs_control_head)
1496  {  {
1497  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1498  int size;  int size;
1499  pcre_uchar *alternative;  pcre_uchar *alternative;
1500  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1395  while (cc < ccend) Line 1503  while (cc < ccend)
1503    size = 0;    size = 0;
1504    switch(*cc)    switch(*cc)
1505      {      {
1506        case OP_KET:
1507        if (PRIVATE_DATA(cc) != 0)
1508          private_data_length++;
1509        cc += 1 + LINK_SIZE;
1510        break;
1511    
1512      case OP_ASSERT:      case OP_ASSERT:
1513      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1514      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1499  return private_data_length; Line 1613  return private_data_length;
1613  }  }
1614    
1615  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,
1616    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1617  {  {
1618  DEFINE_COMPILER;  DEFINE_COMPILER;
1619  int srcw[2];  int srcw[2];
# Line 1520  stacktop = STACK(stacktop - 1); Line 1634  stacktop = STACK(stacktop - 1);
1634    
1635  if (!save)  if (!save)
1636    {    {
1637    stackptr += sizeof(sljit_sw);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1638    if (stackptr < stacktop)    if (stackptr < stacktop)
1639      {      {
1640      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
# Line 1536  if (!save) Line 1650  if (!save)
1650    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1651    }    }
1652    
1653  while (status != end)  do
1654    {    {
1655    count = 0;    count = 0;
1656    switch(status)    switch(status)
# Line 1545  while (status != end) Line 1659  while (status != end)
1659      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1660      count = 1;      count = 1;
1661      srcw[0] = common->recursive_head_ptr;      srcw[0] = common->recursive_head_ptr;
1662        if (needs_control_head)
1663          {
1664          SLJIT_ASSERT(common->control_head_ptr != 0);
1665          count = 2;
1666          srcw[1] = common->control_head_ptr;
1667          }
1668      status = loop;      status = loop;
1669      break;      break;
1670    
# Line 1557  while (status != end) Line 1677  while (status != end)
1677    
1678      switch(*cc)      switch(*cc)
1679        {        {
1680          case OP_KET:
1681          if (PRIVATE_DATA(cc) != 0)
1682            {
1683            count = 1;
1684            srcw[0] = PRIVATE_DATA(cc);
1685            }
1686          cc += 1 + LINK_SIZE;
1687          break;
1688    
1689        case OP_ASSERT:        case OP_ASSERT:
1690        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1691        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1769  while (status != end) Line 1898  while (status != end)
1898        }        }
1899      }      }
1900    }    }
1901    while (status != end);
1902    
1903  if (save)  if (save)
1904    {    {
# Line 1802  if (save) Line 1932  if (save)
1932  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1933  }  }
1934    
1935    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1936    {
1937    pcre_uchar *end = bracketend(cc);
1938    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1939    
1940    /* Assert captures then. */
1941    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1942      current_offset = NULL;
1943    /* Conditional block does not. */
1944    if (*cc == OP_COND || *cc == OP_SCOND)
1945      has_alternatives = FALSE;
1946    
1947    cc = next_opcode(common, cc);
1948    if (has_alternatives)
1949      current_offset = common->then_offsets + (cc - common->start);
1950    
1951    while (cc < end)
1952      {
1953      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1954        cc = set_then_offsets(common, cc, current_offset);
1955      else
1956        {
1957        if (*cc == OP_ALT && has_alternatives)
1958          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1959        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1960          *current_offset = 1;
1961        cc = next_opcode(common, cc);
1962        }
1963      }
1964    
1965    return end;
1966    }
1967    
1968  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
1969  #undef CASE_ITERATOR_PRIVATE_DATA_2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
1970  #undef CASE_ITERATOR_PRIVATE_DATA_2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
# Line 1865  while (list_item) Line 2028  while (list_item)
2028  common->stubs = NULL;  common->stubs = NULL;
2029  }  }
2030    
2031  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2032  {  {
2033  DEFINE_COMPILER;  DEFINE_COMPILER;
2034    
2035  OP2(SLJIT_SUB | SLJIT_SET_E, CALL_COUNT, 0, CALL_COUNT, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, COUNT_MATCH, 0, COUNT_MATCH, 0, SLJIT_IMM, 1);
2036  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2037  }  }
2038    
# Line 1900  static SLJIT_INLINE void reset_ovector(c Line 2063  static SLJIT_INLINE void reset_ovector(c
2063  DEFINE_COMPILER;  DEFINE_COMPILER;
2064  struct sljit_label *loop;  struct sljit_label *loop;
2065  int i;  int i;
2066    
2067  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2068    SLJIT_ASSERT(length > 1);
2069  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2070  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), SLJIT_OFFSETOF(jit_arguments, begin), SLJIT_IMM, IN_UCHARS(1));
2071  if (length < 8)  if (length < 8)
2072    {    {
2073    for (i = 0; i < length; i++)    for (i = 1; i < length; i++)
2074      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2075    }    }
2076  else  else
2077    {    {
2078    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START - sizeof(sljit_sw));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2079    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2080    loop = LABEL();    loop = LABEL();
2081    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2082    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
# Line 1919  else Line 2084  else
2084    }    }
2085  }  }
2086    
2087    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2088    {
2089    DEFINE_COMPILER;
2090    struct sljit_label *loop;
2091    int i;
2092    
2093    SLJIT_ASSERT(length > 1);
2094    /* OVECTOR(1) contains the "string begin - 1" constant. */
2095    if (length > 2)
2096      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2097    if (length < 8)
2098      {
2099      for (i = 2; i < length; i++)
2100        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
2101      }
2102    else
2103      {
2104      GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2105      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2106      loop = LABEL();
2107      OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2108      OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
2109      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2110      }
2111    
2112    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2113    if (common->mark_ptr != 0)
2114      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2115    if (common->control_head_ptr != 0)
2116      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2117    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2118    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2119    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2120    }
2121    
2122    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2123    {
2124    while (current != NULL)
2125      {
2126      switch (current[-2])
2127        {
2128        case type_then_trap:
2129        break;
2130    
2131        case type_mark:
2132        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2133          return current[-4];
2134        break;
2135    
2136        default:
2137        SLJIT_ASSERT_STOP();
2138        break;
2139        }
2140      current = (sljit_sw*)current[-1];
2141      }
2142    return -1;
2143    }
2144    
2145  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2146  {  {
2147  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1975  DEFINE_COMPILER; Line 2198  DEFINE_COMPILER;
2198  struct sljit_jump *jump;  struct sljit_jump *jump;
2199    
2200  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);
2201  SLJIT_ASSERT(common->start_used_ptr != 0 && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));  SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0
2202      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2203    
2204  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2205  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
# Line 1987  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJI Line 2211  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJI
2211  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));
2212    
2213  jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);  jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2214  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr + sizeof(sljit_sw), SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + (int)sizeof(sljit_sw)), SLJIT_SAVED_REG1, 0);
2215  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2216  OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);  OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2217  #endif  #endif
# Line 2155  return (bit < 256) ? ((0 << 8) | bit) : Line 2379  return (bit < 256) ? ((0 << 8) | bit) :
2379    
2380  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2381  {  {
2382  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2383  DEFINE_COMPILER;  DEFINE_COMPILER;
2384  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2385    
# Line 2242  else Line 2466  else
2466  JUMPHERE(jump);  JUMPHERE(jump);
2467  }  }
2468    
2469  static void read_char(compiler_common *common)  static void peek_char(compiler_common *common, pcre_uint32 max)
2470  {  {
2471  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2472  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2473  DEFINE_COMPILER;  DEFINE_COMPILER;
2474  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2475  struct sljit_jump *jump;  struct sljit_jump *jump;
2476  #endif  #endif
2477    
2478    SLJIT_UNUSED_ARG(max);
2479    
2480  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2481  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2482  if (common->utf)  if (common->utf)
2483    {    {
2484  #if defined COMPILE_PCRE8    if (max < 128) return;
2485    
2486    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2487  #elif defined COMPILE_PCRE16    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
   jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);  
 #endif /* COMPILE_PCRE[8|16] */  
2488    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2489      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2490    JUMPHERE(jump);    JUMPHERE(jump);
2491    }    }
2492  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 }  
   
 static void peek_char(compiler_common *common)  
 {  
 /* Reads the character into TMP1, keeps STR_PTR.  
 Does not check STR_END. TMP2 Destroyed. */  
 DEFINE_COMPILER;  
 #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  
 struct sljit_jump *jump;  
 #endif  
2493    
2494  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  #if defined SUPPORT_UTF && defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  
2495  if (common->utf)  if (common->utf)
2496    {    {
2497  #if defined COMPILE_PCRE8    if (max < 0xd800) return;
2498    
2499      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2500      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2501      /* TMP2 contains the high surrogate. */
2502      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2503      OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2504      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2505      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2506      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2507      JUMPHERE(jump);
2508      }
2509    #endif
2510    }
2511    
2512    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2513    
2514    static BOOL is_char7_bitset(const pcre_uint8* bitset, BOOL nclass)
2515    {
2516    /* Tells whether the character codes below 128 are enough
2517    to determine a match. */
2518    const pcre_uint8 value = nclass ? 0xff : 0;
2519    const pcre_uint8* end = bitset + 32;
2520    
2521    bitset += 16;
2522    do
2523      {
2524      if (*bitset++ != value)
2525        return FALSE;
2526      }
2527    while (bitset < end);
2528    return TRUE;
2529    }
2530    
2531    static void read_char7_type(compiler_common *common, BOOL full_read)
2532    {
2533    /* Reads the precise character type of a character into TMP1, if the character
2534    is less than 128. Otherwise it returns with zero. Does not check STR_END. The
2535    full_read argument tells whether characters above max are accepted or not. */
2536    DEFINE_COMPILER;
2537    struct sljit_jump *jump;
2538    
2539    SLJIT_ASSERT(common->utf);
2540    
2541    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2542    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2543    
2544    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2545    
2546    if (full_read)
2547      {
2548      jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2549      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2550      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2551      JUMPHERE(jump);
2552      }
2553    }
2554    
2555    #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2556    
2557    static void read_char_range(compiler_common *common, pcre_uint32 min, pcre_uint32 max, BOOL update_str_ptr)
2558    {
2559    /* Reads the precise value of a character into TMP1, if the character is
2560    between min and max (c >= min && c <= max). Otherwise it returns with a value
2561    outside the range. Does not check STR_END. */
2562    DEFINE_COMPILER;
2563    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2564    struct sljit_jump *jump;
2565    #endif
2566    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2567    struct sljit_jump *jump2;
2568    #endif
2569    
2570    SLJIT_UNUSED_ARG(update_str_ptr);
2571    SLJIT_UNUSED_ARG(min);
2572    SLJIT_UNUSED_ARG(max);
2573    SLJIT_ASSERT(min <= max);
2574    
2575    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2576    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2577    
2578    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2579    if (common->utf)
2580      {
2581      if (max < 128 && !update_str_ptr) return;
2582    
2583    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2584  #elif defined COMPILE_PCRE16    if (min >= 0x10000)
2585    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      {
2586  #endif /* COMPILE_PCRE[8|16] */      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xf0);
2587    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));      if (update_str_ptr)
2588    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);        OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2589        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2590        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x7);
2591        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2592        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2593        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2594        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2595        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2596        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2597        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2598        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2599        if (!update_str_ptr)
2600          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2601        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2602        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2603        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2604        JUMPHERE(jump2);
2605        if (update_str_ptr)
2606          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2607        }
2608      else if (min >= 0x800 && max <= 0xffff)
2609        {
2610        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xe0);
2611        if (update_str_ptr)
2612          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2613        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2614        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xf);
2615        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2616        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2617        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2618        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2619        if (!update_str_ptr)
2620          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2621        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2622        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2623        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2624        JUMPHERE(jump2);
2625        if (update_str_ptr)
2626          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2627        }
2628      else if (max >= 0x800)
2629        add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2630      else if (max < 128)
2631        {
2632        OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2633        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2634        }
2635      else
2636        {
2637        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2638        if (!update_str_ptr)
2639          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2640        else
2641          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2642        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2643        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2644        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2645        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2646        if (update_str_ptr)
2647          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2648        }
2649    JUMPHERE(jump);    JUMPHERE(jump);
2650    }    }
2651  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  #endif
2652    
2653    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2654    if (common->utf)
2655      {
2656      if (max >= 0x10000)
2657        {
2658        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2659        jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2660        /* TMP2 contains the high surrogate. */
2661        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2662        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2663        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2664        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2665        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2666        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2667        JUMPHERE(jump);
2668        return;
2669        }
2670    
2671      if (max < 0xd800 && !update_str_ptr) return;
2672    
2673      /* Skip low surrogate if necessary. */
2674      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2675      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2676      if (update_str_ptr)
2677        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2678      if (max >= 0xd800)
2679        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);
2680      JUMPHERE(jump);
2681      }
2682    #endif
2683  }  }
2684    
2685  static void read_char8_type(compiler_common *common)  static SLJIT_INLINE void read_char(compiler_common *common)
2686    {
2687    read_char_range(common, 0, READ_CHAR_MAX, TRUE);
2688    }
2689    
2690    static void read_char8_type(compiler_common *common, BOOL update_str_ptr)
2691  {  {
2692  /* 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. */
2693  DEFINE_COMPILER;  DEFINE_COMPILER;
2694  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2695  struct sljit_jump *jump;  struct sljit_jump *jump;
2696  #endif  #endif
2697    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2698    struct sljit_jump *jump2;
2699    #endif
2700    
2701  #ifdef SUPPORT_UTF  SLJIT_UNUSED_ARG(update_str_ptr);
2702    
2703    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2704    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2705    
2706    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2707  if (common->utf)  if (common->utf)
2708    {    {
   OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 #if defined COMPILE_PCRE8  
2709    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2710    it is needed in most cases. */    it is needed in most cases. */
2711    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2712    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2713    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    if (!update_str_ptr)
2714    JUMPHERE(jump);      {
2715  #elif defined COMPILE_PCRE16      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2716    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2717    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2718    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2719    JUMPHERE(jump);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2720    /* Skip low surrogate if necessary. */      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
2721    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2722    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);      jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2723    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2724    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);      JUMPHERE(jump2);
2725    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);      }
2726  #elif defined COMPILE_PCRE32    else
2727    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);      add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
   jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  
2728    JUMPHERE(jump);    JUMPHERE(jump);
 #endif /* COMPILE_PCRE[8|16|32] */  
2729    return;    return;
2730    }    }
2731  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2732  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
2733  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  #if !defined COMPILE_PCRE8
 #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  
2734  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2735  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2736  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2737  #endif  #endif
2738  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2739  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if !defined COMPILE_PCRE8
2740  JUMPHERE(jump);  JUMPHERE(jump);
2741  #endif  #endif
2742    
2743    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2744    if (common->utf && update_str_ptr)
2745      {
2746      /* Skip low surrogate if necessary. */
2747      OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2748      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2749      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2750      JUMPHERE(jump);
2751      }
2752    #endif /* SUPPORT_UTF && COMPILE_PCRE16 */
2753  }  }
2754    
2755  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
# Line 2380  if (common->utf) Line 2787  if (common->utf)
2787  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));
2788  }  }
2789    
2790  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)
2791  {  {
2792  /* 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. */
2793  DEFINE_COMPILER;  DEFINE_COMPILER;
2794    struct sljit_jump *jump;
2795    
2796  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2797    {    {
2798    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2799    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));
2800    }    }
2801  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2802    {    {
2803    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    if (jumpifmatch)
2804    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);      {
2805    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));
2806    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));
2807    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));      }
2808      else
2809        {
2810        jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
2811        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2812        JUMPHERE(jump);
2813        }
2814    }    }
2815  else  else
2816    {    {
2817    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2818    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));
2819    }    }
2820  }  }
2821    
# Line 2411  else Line 2825  else
2825  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2826  {  {
2827  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2828  of the character (>= 0xc0). Return char value in TMP1, length - 1 in TMP2. */  of the character (>= 0xc0). Return char value in TMP1, length in TMP2. */
2829  DEFINE_COMPILER;  DEFINE_COMPILER;
2830  struct sljit_jump *jump;  struct sljit_jump *jump;
2831    
2832  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2833    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2834    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2835    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2836    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2837    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2838    
2839  /* Searching for the first zero. */  /* Searching for the first zero. */
2840  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2841  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2842  /* Two byte sequence. */  /* Two byte sequence. */
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
2843  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));
2844  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2845    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2846    
2847    JUMPHERE(jump);
2848    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2849    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2850  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2851  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2852  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 JUMPHERE(jump);  
2853    
2854  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2855  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2856  /* Three byte sequence. */  /* Three byte sequence. */
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  
2857  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2858  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));  
2859  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2860    
2861  /* Four byte sequence. */  /* Four byte sequence. */
2862  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  JUMPHERE(jump);
2863  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2864  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2865    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2866    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2867  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  
2868  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2869  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(4));
2870    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2871    }
2872    
2873    static void do_utfreadchar16(compiler_common *common)
2874    {
2875    /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2876    of the character (>= 0xc0). Return value in TMP1. */
2877    DEFINE_COMPILER;
2878    struct sljit_jump *jump;
2879    
2880    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2881    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2882    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2883    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2884  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
2885  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2886  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));  
2887  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));  /* Searching for the first zero. */
2888    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2889    jump = JUMP(SLJIT_C_NOT_ZERO);
2890    /* Two byte sequence. */
2891    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2892    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2893    
2894    JUMPHERE(jump);
2895    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x400);
2896    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
2897    /* This code runs only in 8 bit mode. No need to shift the value. */
2898    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2899    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2900    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2901    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2902  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2903  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2904  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));  /* Three byte sequence. */
2905    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2906  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2907  }  }
2908    
# Line 2482  jump = JUMP(SLJIT_C_NOT_ZERO); Line 2922  jump = JUMP(SLJIT_C_NOT_ZERO);
2922  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2923  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));
2924  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
2925    /* The upper 5 bits are known at this point. */
2926    compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x3);
2927  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2928  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2929  OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);  OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
 compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  
2930  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2931  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2932    
2933  JUMPHERE(compare);  JUMPHERE(compare);
2934  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2935  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2936    
2937  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
 OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 }  
   
 #elif defined COMPILE_PCRE16  
   
 static void do_utfreadchar(compiler_common *common)  
 {  
 /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char  
 of the character (>= 0xd800). Return char value in TMP1, length - 1 in TMP2. */  
 DEFINE_COMPILER;  
 struct sljit_jump *jump;  
   
 sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  
 jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);  
 /* Do nothing, only return. */  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
   
2938  JUMPHERE(jump);  JUMPHERE(jump);
2939  /* Combine two 16 bit characters. */  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2940  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2941  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3ff);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  
2942  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2943  }  }
2944    
2945  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE8 */
2946    
2947  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2948    
# Line 2603  if (firstline) Line 3017  if (firstline)
3017      mainloop = LABEL();      mainloop = LABEL();
3018      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
3019      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);
3020      read_char(common);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
3021      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
3022      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
3023      JUMPHERE(end);      JUMPHERE(end);
# Line 2679  if (newlinecheck) Line 3093  if (newlinecheck)
3093  return mainloop;  return mainloop;
3094  }  }
3095    
3096  #define MAX_N_CHARS 3  static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, int max_chars)
   
 static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)  
3097  {  {
3098  DEFINE_COMPILER;  /* Recursive function, which scans prefix literals. */
3099  struct sljit_label *start;  int len, repeat, len_save, consumed = 0;
3100  struct sljit_jump *quit;  pcre_uint32 caseless, chr, mask;
3101  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uchar *alternative, *cc_save;
3102  pcre_uchar *cc = common->start + 1 + LINK_SIZE;  BOOL last, any;
 int location = 0;  
 pcre_int32 len, c, bit, caseless;  
 int must_stop;  
   
 /* We do not support alternatives now. */  
 if (*(common->start + GET(common->start, 1)) == OP_ALT)  
   return FALSE;  
3103    
3104    repeat = 1;
3105  while (TRUE)  while (TRUE)
3106    {    {
3107      last = TRUE;
3108      any = FALSE;
3109    caseless = 0;    caseless = 0;
3110    must_stop = 1;    switch (*cc)
   switch(*cc)  
3111      {      {
     case OP_CHAR:  
     must_stop = 0;  
     cc++;  
     break;  
   
3112      case OP_CHARI:      case OP_CHARI:
3113      caseless = 1;      caseless = 1;
3114      must_stop = 0;      case OP_CHAR:
3115        last = FALSE;
3116      cc++;      cc++;
3117      break;      break;
3118    
# Line 2734  while (TRUE) Line 3137  while (TRUE)
3137      cc++;      cc++;
3138      break;      break;
3139    
3140        case OP_EXACTI:
3141        caseless = 1;
3142      case OP_EXACT:      case OP_EXACT:
3143        repeat = GET2(cc, 1);
3144        last = FALSE;
3145      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
3146      break;      break;
3147    
# Line 2745  while (TRUE) Line 3152  while (TRUE)
3152      cc++;      cc++;
3153      break;      break;
3154    
3155      case OP_EXACTI:      case OP_KET:
3156      caseless = 1;      cc += 1 + LINK_SIZE;
3157      cc += 1 + IMM2_SIZE;      continue;
3158      break;  
3159        case OP_ALT:
3160        cc += GET(cc, 1);
3161        continue;
3162    
3163        case OP_ONCE:
3164        case OP_ONCE_NC:
3165        case OP_BRA:
3166        case OP_BRAPOS:
3167        case OP_CBRA:
3168        case OP_CBRAPOS:
3169        alternative = cc + GET(cc, 1);
3170        while (*alternative == OP_ALT)
3171          {
3172          max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, max_chars);
3173          if (max_chars == 0)
3174            return consumed;
3175          alternative += GET(alternative, 1);
3176          }
3177    
3178        if (*cc == OP_CBRA || *cc == OP_CBRAPOS)
3179          cc += IMM2_SIZE;
3180        cc += 1 + LINK_SIZE;
3181        continue;
3182    
3183        case OP_CLASS:
3184        case OP_NCLASS:
3185        any = TRUE;
3186        cc += 1 + 32 / sizeof(pcre_uchar);
3187        break;
3188    
3189    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3190        case OP_XCLASS:
3191        any = TRUE;
3192        cc += GET(cc, 1);
3193        break;
3194    #endif
3195    
3196        case OP_NOT_DIGIT:
3197        case OP_DIGIT:
3198        case OP_NOT_WHITESPACE:
3199        case OP_WHITESPACE:
3200        case OP_NOT_WORDCHAR:
3201        case OP_WORDCHAR:
3202        case OP_ANY:
3203        case OP_ALLANY:
3204        any = TRUE;
3205        cc++;
3206        break;
3207    
3208    #ifdef SUPPORT_UCP
3209        case OP_NOTPROP:
3210        case OP_PROP:
3211        any = TRUE;
3212        cc += 1 + 2;
3213        break;
3214    #endif
3215    
3216        case OP_TYPEEXACT:
3217        repeat = GET2(cc, 1);
3218        cc += 1 + IMM2_SIZE;
3219        continue;
3220    
3221        default:
3222        return consumed;
3223        }
3224    
3225      if (any)
3226        {
3227    #ifdef SUPPORT_UTF
3228        if (common->utf) return consumed;
3229    #endif
3230    #if defined COMPILE_PCRE8
3231        mask = 0xff;
3232    #elif defined COMPILE_PCRE16
3233        mask = 0xffff;
3234    #elif defined COMPILE_PCRE32
3235        mask = 0xffffffff;
3236    #else
3237        SLJIT_ASSERT_STOP();
3238    #endif
3239    
3240        do
3241          {
3242          chars[0] = mask;
3243          chars[1] = mask;
3244    
3245      default:        if (--max_chars == 0)
3246      must_stop = 2;          return consumed;
3247      break;        consumed++;
3248      }        chars += 2;
3249          }
3250        while (--repeat > 0);
3251    
3252    if (must_stop == 2)      repeat = 1;
3253        break;      continue;
3254        }
3255    
3256    len = 1;    len = 1;
3257  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3258    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3259  #endif  #endif
3260    
3261    if (caseless && char_has_othercase(common, cc))    if (caseless != 0 && char_has_othercase(common, cc))
3262      {      {
3263      caseless = char_get_othercase_bit(common, cc);      caseless = char_get_othercase_bit(common, cc);
3264      if (caseless == 0)      if (caseless == 0)
3265        return FALSE;        return consumed;
3266  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3267      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
3268  #else  #else
# Line 2780  while (TRUE) Line 3275  while (TRUE)
3275    else    else
3276      caseless = 0;      caseless = 0;
3277    
3278    while (len > 0 && location < MAX_N_CHARS * 2)    len_save = len;
3279      {    cc_save = cc;
3280      c = *cc;    while (TRUE)
3281      bit = 0;      {
3282      if (len == (caseless & 0xff))      do
3283        {        {
3284        bit = caseless >> 8;        chr = *cc;
3285        c |= bit;  #ifdef COMPILE_PCRE32
3286          if (SLJIT_UNLIKELY(chr == NOTACHAR))
3287            return consumed;
3288    #endif
3289          mask = 0;
3290          if ((pcre_uint32)len == (caseless & 0xff))
3291            {
3292            mask = caseless >> 8;
3293            chr |= mask;
3294            }
3295    
3296          if (chars[0] == NOTACHAR)
3297            {
3298            chars[0] = chr;
3299            chars[1] = mask;
3300            }
3301          else
3302            {
3303            mask |= chars[0] ^ chr;
3304            chr |= mask;
3305            chars[0] = chr;
3306            chars[1] |= mask;
3307            }
3308    
3309          len--;
3310          if (--max_chars == 0)
3311            return consumed;
3312          consumed++;
3313          chars += 2;
3314          cc++;
3315        }        }
3316        while (len > 0);
3317    
3318      chars[location] = c;      if (--repeat == 0)
3319      chars[location + 1] = bit;        break;
3320    
3321      len--;      len = len_save;
3322      location += 2;      cc = cc_save;
3323      cc++;      }
3324    
3325      repeat = 1;
3326      if (last)
3327        return consumed;
3328      }
3329    }
3330    
3331    #define MAX_N_CHARS 16
3332    
3333    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3334    {
3335    DEFINE_COMPILER;
3336    struct sljit_label *start;
3337    struct sljit_jump *quit;
3338    pcre_uint32 chars[MAX_N_CHARS * 2];
3339    pcre_uint8 ones[MAX_N_CHARS];
3340    pcre_uint32 mask;
3341    int i, max;
3342    int offsets[3];
3343    
3344    for (i = 0; i < MAX_N_CHARS; i++)
3345      {
3346      chars[i << 1] = NOTACHAR;
3347      chars[(i << 1) + 1] = 0;
3348      }
3349    
3350    max = scan_prefix(common, common->start, chars, MAX_N_CHARS);
3351    
3352    if (max <= 1)
3353      return FALSE;
3354    
3355    for (i = 0; i < max; i++)
3356      {
3357      mask = chars[(i << 1) + 1];
3358      ones[i] = ones_in_half_byte[mask & 0xf];
3359      mask >>= 4;
3360      while (mask != 0)
3361        {
3362        ones[i] += ones_in_half_byte[mask & 0xf];
3363        mask >>= 4;
3364      }      }
3365      }
3366    
3367    if (location >= MAX_N_CHARS * 2 || must_stop != 0)  offsets[0] = -1;
3368    /* Scan forward. */
3369    for (i = 0; i < max; i++)
3370      if (ones[i] <= 2) {
3371        offsets[0] = i;
3372      break;      break;
3373    }    }
3374    
3375  /* At least two characters are required. */  if (offsets[0] == -1)
3376  if (location < 2 * 2)    return FALSE;
3377      return FALSE;  
3378    /* Scan backward. */
3379    offsets[1] = -1;
3380    for (i = max - 1; i > offsets[0]; i--)
3381      if (ones[i] <= 2) {
3382        offsets[1] = i;
3383        break;
3384      }
3385    
3386    offsets[2] = -1;
3387    if (offsets[1] >= 0)
3388      {
3389      /* Scan from middle. */
3390      for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3391        if (ones[i] <= 2)
3392          {
3393          offsets[2] = i;
3394          break;
3395          }
3396    
3397      if (offsets[2] == -1)
3398        {
3399        for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3400          if (ones[i] <= 2)
3401            {
3402            offsets[2] = i;
3403            break;
3404            }
3405        }
3406      }
3407    
3408    SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3409    SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3410    
3411    chars[0] = chars[offsets[0] << 1];
3412    chars[1] = chars[(offsets[0] << 1) + 1];
3413    if (offsets[2] >= 0)
3414      {
3415      chars[2] = chars[offsets[2] << 1];
3416      chars[3] = chars[(offsets[2] << 1) + 1];
3417      }
3418    if (offsets[1] >= 0)
3419      {
3420      chars[4] = chars[offsets[1] << 1];
3421      chars[5] = chars[(offsets[1] << 1) + 1];
3422      }
3423    
3424    max -= 1;
3425  if (firstline)  if (firstline)
3426    {    {
3427    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3428    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3429    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS(max));
3430    }    }
3431  else  else
3432    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3433    
3434  start = LABEL();  start = LABEL();
3435  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3436    
3437  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
3438  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  if (offsets[1] >= 0)
3439      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3440  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));
3441    
3442  if (chars[1] != 0)  if (chars[1] != 0)
3443    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3444  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3445  if (location > 2 * 2)  if (offsets[2] >= 0)
3446    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));
3447  if (chars[3] != 0)  
3448    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);  if (offsets[1] >= 0)
 CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);  
 if (location > 2 * 2)  
3449    {    {
3450    if (chars[5] != 0)    if (chars[5] != 0)
3451      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3452    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
3453      }
3454    
3455    if (offsets[2] >= 0)
3456      {
3457      if (chars[3] != 0)
3458        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3459      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3460    }    }
3461  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));
3462    
# Line 2842  JUMPHERE(quit); Line 3465  JUMPHERE(quit);
3465  if (firstline)  if (firstline)
3466    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3467  else  else
3468    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3469  return TRUE;  return TRUE;
3470  }  }
3471    
# Line 2962  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_ Line 3585  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_
3585  skip_char_back(common);  skip_char_back(common);
3586    
3587  loop = LABEL();  loop = LABEL();
3588  read_char(common);  read_char_range(common, common->nlmin, common->nlmax, TRUE);
3589  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3590  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3591    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
# Line 2991  if (firstline) Line 3614  if (firstline)
3614    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3615  }  }
3616    
3617  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks);
3618    
3619  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, pcre_uint8 *start_bits, BOOL firstline)
3620  {  {
3621  DEFINE_COMPILER;  DEFINE_COMPILER;
3622  struct sljit_label *start;  struct sljit_label *start;
3623  struct sljit_jump *quit;  struct sljit_jump *quit;
3624  struct sljit_jump *found = NULL;  struct sljit_jump *found = NULL;
3625  jump_list *matches = NULL;  jump_list *matches = NULL;
 pcre_uint8 inverted_start_bits[32];  
 int i;  
3626  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3627  struct sljit_jump *jump;  struct sljit_jump *jump;
3628  #endif  #endif
3629    
 for (i = 0; i < 32; ++i)  
   inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);  
   
3630  if (firstline)  if (firstline)
3631    {    {
3632    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
# Line 3024  if (common->utf) Line 3642  if (common->utf)
3642    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3643  #endif  #endif
3644    
3645  if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))  if (!check_class_ranges(common, start_bits, (start_bits[31] & 0x80) != 0, TRUE, &matches))
3646    {    {
3647  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3648    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
# Line 3033  if (!check_class_ranges(common, inverted Line 3651  if (!check_class_ranges(common, inverted
3651  #endif  #endif
3652    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3653    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3654    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
3655    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3656    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
3657    found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
# Line 3236  JUMPHERE(skipread); Line 3854  JUMPHERE(skipread);
3854    
3855  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3856  check_str_end(common, &skipread_list);  check_str_end(common, &skipread_list);
3857  peek_char(common);  peek_char(common, READ_CHAR_MAX);
3858    
3859  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
3860  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 3282  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSE Line 3900  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSE
3900  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3901  }  }
3902    
3903  /*  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks)
   range format:  
   
   ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).  
   ranges[1] = first bit (0 or 1)  
   ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)  
 */  
   
 static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)  
3904  {  {
3905  DEFINE_COMPILER;  DEFINE_COMPILER;
3906  struct sljit_jump *jump;  int ranges[MAX_RANGE_SIZE];
   
 if (ranges[0] < 0)  
   return FALSE;  
   
 switch(ranges[0])  
   {  
   case 1:  
   if (readch)  
     read_char(common);  
   add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));  
   return TRUE;  
   
   case 2:  
   if (readch)  
     read_char(common);  
   OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);  
   add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));  
   return TRUE;  
   
   case 4:  
   if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])  
     {  
     if (readch)  
       read_char(common);  
     if (ranges[1] != 0)  
       {  
       add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));  
       add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));  
       }  
     else  
       {  
       jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);  
       add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));  
       JUMPHERE(jump);  
       }  
     return TRUE;  
     }  
   if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))  
     {  
     if (readch)  
       read_char(common);  
     OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);  
     OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);  
     add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));  
     return TRUE;  
     }  
   return FALSE;  
   
   default:  
   return FALSE;  
   }  
 }  
   
 static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)  
 {  
 int i, bit, length;  
 const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;  
   
 bit = ctypes[0] & flag;  
 ranges[0] = -1;  
 ranges[1] = bit != 0 ? 1 : 0;  
 length = 0;  
   
 for (i = 1; i < 256; i++)  
   if ((ctypes[i] & flag) != bit)  
     {  
     if (length >= MAX_RANGE_SIZE)  
       return;  
     ranges[2 + length] = i;  
     length++;  
     bit ^= flag;  
     }  
   
 if (bit != 0)  
   {  
   if (length >= MAX_RANGE_SIZE)  
     return;  
   ranges[2 + length] = 256;  
   length++;  
   }  
 ranges[0] = length;  
 }  
   
 static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)  
 {  
 int ranges[2 + MAX_RANGE_SIZE];  
3907  pcre_uint8 bit, cbit, all;  pcre_uint8 bit, cbit, all;
3908  int i, byte, length = 0;  int i, byte, length = 0;
3909    
3910  bit = bits[0] & 0x1;  bit = bits[0] & 0x1;
3911  ranges[1] = bit;  /* All bits will be zero or one (since bit is zero or one). */
 /* Can be 0 or 255. */  
3912  all = -bit;  all = -bit;
3913    
3914  for (i = 0; i < 256; )  for (i = 0; i < 256; )
# Line 3400  for (i = 0; i < 256; ) Line 3923  for (i = 0; i < 256; )
3923        {        {
3924        if (length >= MAX_RANGE_SIZE)        if (length >= MAX_RANGE_SIZE)
3925          return FALSE;          return FALSE;
3926        ranges[2 + length] = i;        ranges[length] = i;
3927        length++;        length++;
3928        bit = cbit;        bit = cbit;
3929        all = -cbit;        all = -cbit;
# Line 3413  if (((bit == 0) && nclass) || ((bit == 1 Line 3936  if (((bit == 0) && nclass) || ((bit == 1
3936    {    {
3937    if (length >= MAX_RANGE_SIZE)    if (length >= MAX_RANGE_SIZE)
3938      return FALSE;      return FALSE;
3939    ranges[2 + length] = 256;    ranges[length] = 256;
3940    length++;    length++;
3941    }    }
 ranges[0] = length;  
3942    
3943  return check_ranges(common, ranges, backtracks, FALSE);  if (length < 0 || length > 4)
3944      return FALSE;
3945    
3946    bit = bits[0] & 0x1;
3947    if (invert) bit ^= 0x1;
3948    
3949    /* No character is accepted. */
3950    if (length == 0 && bit == 0)
3951      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
3952    
3953    switch(length)
3954      {
3955      case 0:
3956      /* When bit != 0, all characters are accepted. */
3957      return TRUE;
3958    
3959      case 1:
3960      add_jump(compiler, backtracks, CMP(bit == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
3961      return TRUE;
3962    
3963      case 2:
3964      if (ranges[0] + 1 != ranges[1])
3965        {
3966        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
3967        add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
3968        }
3969      else
3970        add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
3971      return TRUE;
3972    
3973      case 3:
3974      if (bit != 0)
3975        {
3976        add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3977        if (ranges[0] + 1 != ranges[1])
3978          {
3979          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
3980          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
3981          }
3982        else
3983          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
3984        return TRUE;
3985        }
3986    
3987      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[0]));
3988      if (ranges[1] + 1 != ranges[2])
3989        {
3990        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1]);
3991        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1]));
3992        }
3993      else
3994        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1]));
3995      return TRUE;
3996    
3997      case 4:
3998      if ((ranges[1] - ranges[0]) == (ranges[3] - ranges[2])
3999          && (ranges[0] | (ranges[2] - ranges[0])) == ranges[2]
4000          && is_powerof2(ranges[2] - ranges[0]))
4001        {
4002        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[0]);
4003        if (ranges[2] + 1 != ranges[3])
4004          {
4005          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
4006          add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
4007          }
4008        else
4009          add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
4010        return TRUE;
4011        }
4012    
4013      if (bit != 0)
4014        {
4015        i = 0;
4016        if (ranges[0] + 1 != ranges[1])
4017          {
4018          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
4019          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
4020          i = ranges[0];
4021          }
4022        else
4023          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
4024    
4025        if (ranges[2] + 1 != ranges[3])
4026          {
4027          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - i);
4028          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
4029          }
4030        else
4031          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2] - i));
4032        return TRUE;
4033        }
4034    
4035      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
4036      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[0]));
4037      if (ranges[1] + 1 != ranges[2])
4038        {
4039        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]);
4040        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1]));
4041        }
4042      else
4043        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
4044      return TRUE;
4045    
4046      default:
4047      SLJIT_ASSERT_STOP();
4048      return FALSE;
4049      }
4050  }  }
4051    
4052  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
# Line 3785  return cc; Line 4413  return cc;
4413  #define SET_TYPE_OFFSET(value) \  #define SET_TYPE_OFFSET(value) \
4414    if ((value) != typeoffset) \    if ((value) != typeoffset) \
4415      { \      { \
4416      if ((value) > typeoffset) \      if ((value) < typeoffset) \
       OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \  
     else \  
4417        OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \        OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \
4418        else \
4419          OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \
4420      } \      } \
4421    typeoffset = (value);    typeoffset = (value);
4422    
4423  #define SET_CHAR_OFFSET(value) \  #define SET_CHAR_OFFSET(value) \
4424    if ((value) != charoffset) \    if ((value) != charoffset) \
4425      { \      { \
4426      if ((value) > charoffset) \      if ((value) < charoffset) \
4427        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (value) - charoffset); \        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(charoffset - (value))); \
4428      else \      else \
4429        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, charoffset - (value)); \        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)((value) - charoffset)); \
4430      } \      } \
4431    charoffset = (value);    charoffset = (value);
4432    
# Line 3806  static void compile_xclass_matchingpath( Line 4434  static void compile_xclass_matchingpath(
4434  {  {
4435  DEFINE_COMPILER;  DEFINE_COMPILER;
4436  jump_list *found = NULL;  jump_list *found = NULL;
4437  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;
4438  pcre_int32 c, charoffset;  sljit_uw c, charoffset, max = 256, min = READ_CHAR_MAX;
 const pcre_uint32 *other_cases;  
4439  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4440  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4441  int compares, invertcmp, numberofcmps;  int compares, invertcmp, numberofcmps;
4442    #if defined SUPPORT_UTF && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
4443    BOOL utf = common->utf;
4444    #endif
4445    
4446  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4447  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4448  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4449  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4450  pcre_int32 typeoffset;  const pcre_uint32 *other_cases;
4451    sljit_uw typeoffset;
4452  #endif  #endif
4453    
4454  /* Although SUPPORT_UTF must be defined, we are  /* Scanning the necessary info. */
4455     not necessary in utf mode even in 8 bit mode. */  cc++;
4456  detect_partial_match(common, backtracks);  ccbegin = cc;
4457  read_char(common);  compares = 0;
4458    if (cc[-1] & XCL_MAP)
 if ((*cc++ & XCL_MAP) != 0)  
4459    {    {
4460    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    min = 0;
 #ifndef COMPILE_PCRE8  
   jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
 #elif defined SUPPORT_UTF  
   if (common->utf)  
     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
 #endif  
   
   if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, list))  
     {  
     OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);  
     OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);  
     OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);  
     OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);  
     OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);  
     add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));  
     }  
   
 #ifndef COMPILE_PCRE8  
   JUMPHERE(jump);  
 #elif defined SUPPORT_UTF  
   if (common->utf)  
     JUMPHERE(jump);  
 #endif  
   OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);  
 #ifdef SUPPORT_UCP  
   charsaved = TRUE;  
 #endif  
4461    cc += 32 / sizeof(pcre_uchar);    cc += 32 / sizeof(pcre_uchar);
4462    }    }
4463    
 /* Scanning the necessary info. */  
 ccbegin = cc;  
 compares = 0;  
4464  while (*cc != XCL_END)  while (*cc != XCL_END)
4465    {    {
4466    compares++;    compares++;
4467    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
4468      {      {
4469      cc += 2;      cc ++;
4470  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4471      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (c > max) max = c;
4472  #endif      if (c < min) min = c;
4473  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4474      needschar = TRUE;      needschar = TRUE;
4475  #endif  #endif
4476      }      }
4477    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
4478      {      {
4479      cc += 2;      cc ++;
4480  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4481      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (c < min) min = c;
4482  #endif      GETCHARINCTEST(c, cc);
4483      cc++;      if (c > max) max = c;
 #ifdef SUPPORT_UTF  
     if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
4484  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4485      needschar = TRUE;      needschar = TRUE;
4486  #endif  #endif
# Line 3892  while (*cc != XCL_END) Line 4490  while (*cc != XCL_END)
4490      {      {
4491      SLJIT_ASSERT(*cc == XCL_PROP || *cc == XCL_NOTPROP);      SLJIT_ASSERT(*cc == XCL_PROP || *cc == XCL_NOTPROP);
4492      cc++;      cc++;
4493        if (*cc == PT_CLIST)
4494          {
4495          other_cases = PRIV(ucd_caseless_sets) + cc[1];
4496          while (*other_cases != NOTACHAR)
4497            {
4498            if (*other_cases > max) max = *other_cases;
4499            if (*other_cases < min) min = *other_cases;
4500            other_cases++;
4501            }
4502          }
4503        else
4504          {
4505          max = READ_CHAR_MAX;
4506          min = 0;
4507          }
4508    
4509      switch(*cc)      switch(*cc)
4510        {        {
4511        case PT_ANY:        case PT_ANY:
# Line 3911  while (*cc != XCL_END) Line 4525  while (*cc != XCL_END)
4525        case PT_SPACE:        case PT_SPACE:
4526        case PT_PXSPACE:        case PT_PXSPACE:
4527        case PT_WORD:        case PT_WORD:
4528          case PT_PXGRAPH:
4529          case PT_PXPRINT:
4530          case PT_PXPUNCT:
4531        needstype = TRUE;        needstype = TRUE;
4532        needschar = TRUE;        needschar = TRUE;
4533        break;        break;
# Line 3929  while (*cc != XCL_END) Line 4546  while (*cc != XCL_END)
4546  #endif  #endif
4547    }    }
4548    
4549    /* We are not necessary in utf mode even in 8 bit mode. */
4550    cc = ccbegin;
4551    detect_partial_match(common, backtracks);
4552    read_char_range(common, min, max, (cc[-1] & XCL_NOT) != 0);
4553    
4554    if ((cc[-1] & XCL_HASPROP) == 0)
4555      {
4556      if ((cc[-1] & XCL_MAP) != 0)
4557        {
4558        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4559        if (!check_class_ranges(common, (const pcre_uint8 *)cc, (((const pcre_uint8 *)cc)[31] & 0x80) != 0, TRUE, &found))
4560          {
4561          OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4562          OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4563          OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4564          OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4565          OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4566          add_jump(compiler, &found, JUMP(SLJIT_C_NOT_ZERO));
4567          }
4568    
4569        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4570        JUMPHERE(jump);
4571    
4572        cc += 32 / sizeof(pcre_uchar);
4573        }
4574      else
4575        {
4576        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, min);
4577        add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, max - min));
4578        }
4579      }
4580    else if ((cc[-1] & XCL_MAP) != 0)
4581      {
4582      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4583    #ifdef SUPPORT_UCP
4584      charsaved = TRUE;
4585    #endif
4586      if (!check_class_ranges(common, (const pcre_uint8 *)cc, FALSE, TRUE, list))
4587        {
4588    #ifdef COMPILE_PCRE8
4589        SLJIT_ASSERT(common->utf);
4590    #endif
4591        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4592    
4593        OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4594        OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4595        OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4596        OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4597        OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4598        add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
4599    
4600        JUMPHERE(jump);
4601        }
4602    
4603      OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
4604      cc += 32 / sizeof(pcre_uchar);
4605      }
4606    
4607  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4608  /* Simple register allocation. TMP1 is preferred if possible. */  /* Simple register allocation. TMP1 is preferred if possible. */
4609  if (needstype || needsscript)  if (needstype || needsscript)
# Line 3970  if (needstype || needsscript) Line 4645  if (needstype || needsscript)
4645  #endif  #endif
4646    
4647  /* Generating code. */  /* Generating code. */
 cc = ccbegin;  
4648  charoffset = 0;  charoffset = 0;
4649  numberofcmps = 0;  numberofcmps = 0;
4650  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 3986  while (*cc != XCL_END) Line 4660  while (*cc != XCL_END)
4660    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
4661      {      {
4662      cc ++;      cc ++;
4663  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
     if (common->utf)  
       {  
       GETCHARINC(c, cc);  
       }  
     else  
 #endif  
       c = *cc++;  
4664    
4665      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4666        {        {
4667        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));
4668        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);
4669        numberofcmps++;        numberofcmps++;
4670        }        }
4671      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4672        {        {
4673        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));
4674        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);
4675        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4676        numberofcmps = 0;        numberofcmps = 0;
4677        }        }
4678      else      else
4679        {        {
4680        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));
4681        numberofcmps = 0;        numberofcmps = 0;
4682        }        }
4683      }      }
4684    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
4685      {      {
4686      cc ++;      cc ++;
4687  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
     if (common->utf)  
       {  
       GETCHARINC(c, cc);  
       }  
     else  
 #endif  
       c = *cc++;  
4688      SET_CHAR_OFFSET(c);      SET_CHAR_OFFSET(c);
4689  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4690      if (common->utf)  
       {  
       GETCHARINC(c, cc);  
       }  
     else  
 #endif  
       c = *cc++;  
4691      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4692        {        {
4693        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));
4694        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);
4695        numberofcmps++;        numberofcmps++;
4696        }        }
4697      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4698        {        {
4699        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));
4700        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);
4701        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4702        numberofcmps = 0;        numberofcmps = 0;
4703        }        }
4704      else      else
4705        {        {
4706        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));
4707        numberofcmps = 0;        numberofcmps = 0;
4708        }        }
4709      }      }
# Line 4098  while (*cc != XCL_END) Line 4752  while (*cc != XCL_END)
4752    
4753        case PT_SPACE:        case PT_SPACE:
4754        case PT_PXSPACE:        case PT_PXSPACE:
       if (*cc == PT_SPACE)  
         {  
         OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  
         jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 11 - charoffset);  
         }  
4755        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4756        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 13 - 9);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd - 0x9);
4757        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4758        if (*cc == PT_SPACE)  
4759          JUMPHERE(jump);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x9);
4760          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4761    
4762          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x9);
4763          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4764    
4765        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4766        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl);
# Line 4116  while (*cc != XCL_END) Line 4769  while (*cc != XCL_END)
4769        break;        break;
4770    
4771        case PT_WORD:        case PT_WORD:
4772        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));
4773        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4774        /* Fall through. */        /* Fall through. */
4775    
# Line 4164  while (*cc != XCL_END) Line 4817  while (*cc != XCL_END)
4817          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]);
4818          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4819    
4820          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));
4821          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);
4822    
4823          other_cases += 3;          other_cases += 3;
4824          }          }
4825        else        else
4826          {          {
4827          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));
4828          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4829          }          }
4830    
4831        while (*other_cases != NOTACHAR)        while (*other_cases != NOTACHAR)
4832          {          {
4833          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));
4834          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);
4835          }          }
4836        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4837        break;        break;
4838    
4839        case PT_UCNC:        case PT_UCNC:
4840        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));
4841        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4842        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));
4843        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4844        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));
4845        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4846    
4847        SET_CHAR_OFFSET(0xa0);        SET_CHAR_OFFSET(0xa0);
4848        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));
4849        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4850        SET_CHAR_OFFSET(0);        SET_CHAR_OFFSET(0);
4851        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);
4852        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4853        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4854        break;        break;
4855    
4856          case PT_PXGRAPH:
4857          /* C and Z groups are the farthest two groups. */
4858          SET_TYPE_OFFSET(ucp_Ll);
4859          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4860          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4861    
4862          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4863    
4864          /* In case of ucp_Cf, we overwrite the result. */
4865          SET_CHAR_OFFSET(0x2066);
4866          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4867          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4868    
4869          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4870          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4871    
4872          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x2066);
4873          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4874    
4875          JUMPHERE(jump);
4876          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4877          break;
4878    
4879          case PT_PXPRINT:
4880          /* C and Z groups are the farthest two groups. */
4881          SET_TYPE_OFFSET(ucp_Ll);
4882          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4883          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4884    
4885          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Ll);
4886          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_NOT_EQUAL);
4887    
4888          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4889    
4890          /* In case of ucp_Cf, we overwrite the result. */
4891          SET_CHAR_OFFSET(0x2066);
4892          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4893          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4894    
4895          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4896          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4897    
4898          JUMPHERE(jump);
4899          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4900          break;
4901    
4902          case PT_PXPUNCT:
4903          SET_TYPE_OFFSET(ucp_Sc);
4904          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Sc);
4905          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4906    
4907          SET_CHAR_OFFSET(0);
4908          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xff);
4909          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4910    
4911          SET_TYPE_OFFSET(ucp_Pc);
4912          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ps - ucp_Pc);
4913          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4914          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4915          break;
4916        }        }
4917      cc += 2;      cc += 2;
4918      }      }
# Line 4230  struct sljit_label *label; Line 4944  struct sljit_label *label;
4944  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4945  pcre_uchar propdata[5];  pcre_uchar propdata[5];
4946  #endif  #endif
4947  #endif  #endif /* SUPPORT_UTF */
4948    
4949  switch(type)  switch(type)
4950    {    {
# Line 4255  switch(type) Line 4969  switch(type)
4969    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
4970    case OP_DIGIT:    case OP_DIGIT:
4971    /* Digits are usually 0-9, so it is worth to optimize them. */    /* Digits are usually 0-9, so it is worth to optimize them. */
   if (common->digits[0] == -2)  
     get_ctype_ranges(common, ctype_digit, common->digits);  
4972    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4973    /* Flip the starting bit in the negative case. */  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
4974    if (type == OP_NOT_DIGIT)    if (common->utf && is_char7_bitset((const pcre_uint8*)common->ctypes - cbit_length + cbit_digit, FALSE))
4975      common->digits[1] ^= 1;      read_char7_type(common, type == OP_NOT_DIGIT);
4976    if (!check_ranges(common, common->digits, backtracks, TRUE))    else
4977      {  #endif
4978      read_char8_type(common);      read_char8_type(common, type == OP_NOT_DIGIT);
4979      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);      /* Flip the starting bit in the negative case. */
4980      add_jump(compiler, backtracks, JUMP(type == OP_DIGIT ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);
4981      }    add_jump(compiler, backtracks, JUMP(type == OP_DIGIT ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
   if (type == OP_NOT_DIGIT)  
     common->digits[1] ^= 1;  
4982    return cc;    return cc;
4983    
4984    case OP_NOT_WHITESPACE:    case OP_NOT_WHITESPACE:
4985    case OP_WHITESPACE:    case OP_WHITESPACE:
4986    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4987    read_char8_type(common);  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
4988      if (common->utf && is_char7_bitset((const pcre_uint8*)common->ctypes - cbit_length + cbit_space, FALSE))
4989        read_char7_type(common, type == OP_NOT_WHITESPACE);
4990      else
4991    #endif
4992        read_char8_type(common, type == OP_NOT_WHITESPACE);
4993    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_space);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_space);
4994    add_jump(compiler, backtracks, JUMP(type == OP_WHITESPACE ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_WHITESPACE ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
4995    return cc;    return cc;
# Line 4282  switch(type) Line 4997  switch(type)
4997    case OP_NOT_WORDCHAR:    case OP_NOT_WORDCHAR:
4998    case OP_WORDCHAR:    case OP_WORDCHAR:
4999    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5000    read_char8_type(common);  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5001      if (common->utf && is_char7_bitset((const pcre_uint8*)common->ctypes - cbit_length + cbit_word, FALSE))
5002        read_char7_type(common, type == OP_NOT_WORDCHAR);
5003      else
5004    #endif
5005        read_char8_type(common, type == OP_NOT_WORDCHAR);
5006    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_word);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_word);
5007    add_jump(compiler, backtracks, JUMP(type == OP_WORDCHAR ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_WORDCHAR ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
5008    return cc;    return cc;
5009    
5010    case OP_ANY:    case OP_ANY:
5011    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5012    read_char(common);    read_char_range(common, common->nlmin, common->nlmax, TRUE);
5013    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
5014      {      {
5015      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 4345  switch(type) Line 5065  switch(type)
5065  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
5066    case OP_NOTPROP:    case OP_NOTPROP:
5067    case OP_PROP:    case OP_PROP:
5068    propdata[0] = 0;    propdata[0] = XCL_HASPROP;
5069    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;
5070    propdata[2] = cc[0];    propdata[2] = cc[0];
5071    propdata[3] = cc[1];    propdata[3] = cc[1];
# Line 4357  switch(type) Line 5077  switch(type)
5077    
5078    case OP_ANYNL:    case OP_ANYNL:
5079    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5080    read_char(common);    read_char_range(common, common->bsr_nlmin, common->bsr_nlmax, FALSE);
5081    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);
5082    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
5083    end_list = NULL;    end_list = NULL;
# Line 4379  switch(type) Line 5099  switch(type)
5099    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
5100    case OP_HSPACE:    case OP_HSPACE:
5101    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5102    read_char(common);    read_char_range(common, 0x9, 0x3000, type == OP_NOT_HSPACE);
5103    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));
5104    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));
5105    return cc;    return cc;
# Line 4387  switch(type) Line 5107  switch(type)
5107    case OP_NOT_VSPACE:    case OP_NOT_VSPACE:
5108    case OP_VSPACE:    case OP_VSPACE:
5109    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5110    read_char(common);    read_char_range(common, 0xa, 0x2029, type == OP_NOT_VSPACE);
5111    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));
5112    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));
5113    return cc;    return cc;
# Line 4486  switch(type) Line 5206  switch(type)
5206      else      else
5207        {        {
5208        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);
5209        read_char(common);        read_char_range(common, common->nlmin, common->nlmax, TRUE);
5210        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));
5211        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
5212        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 4534  switch(type) Line 5254  switch(type)
5254    else    else
5255      {      {
5256      skip_char_back(common);      skip_char_back(common);
5257      read_char(common);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
5258      check_newlinechar(common, common->nltype, backtracks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
5259      }      }
5260    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
# Line 4585  switch(type) Line 5305  switch(type)
5305      }      }
5306    else    else
5307      {      {
5308      peek_char(common);      peek_char(common, common->nlmax);
5309      check_newlinechar(common, common->nltype, backtracks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
5310      }      }
5311    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
# Line 4609  switch(type) Line 5329  switch(type)
5329  #endif  #endif
5330      return byte_sequence_compare(common, type == OP_CHARI, cc, &context, backtracks);      return byte_sequence_compare(common, type == OP_CHARI, cc, &context, backtracks);
5331      }      }
5332    
5333    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
   read_char(common);  
5334  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
5335    if (common->utf)    if (common->utf)
5336      {      {
# Line 4619  switch(type) Line 5339  switch(type)
5339    else    else
5340  #endif  #endif
5341      c = *cc;      c = *cc;
5342    
5343    if (type == OP_CHAR || !char_has_othercase(common, cc))    if (type == OP_CHAR || !char_has_othercase(common, cc))
5344      {      {
5345        read_char_range(common, c, c, FALSE);
5346      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));
5347      return cc + length;      return cc + length;
5348      }      }
5349    oc = char_othercase(common, c);    oc = char_othercase(common, c);
5350      read_char_range(common, c < oc ? c : oc, c > oc ? c : oc, FALSE);
5351    bit = c ^ oc;    bit = c ^ oc;
5352    if (is_powerof2(bit))    if (is_powerof2(bit))
5353      {      {
# Line 4632  switch(type) Line 5355  switch(type)
5355      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));
5356      return cc + length;      return cc + length;
5357      }      }
5358    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);
5359    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));
5360    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));  
5361    return cc + length;    return cc + length;
5362    
5363    case OP_NOT:    case OP_NOT:
# Line 4671  switch(type) Line 5392  switch(type)
5392  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
5393        {        {
5394        GETCHARLEN(c, cc, length);        GETCHARLEN(c, cc, length);
       read_char(common);  
5395        }        }
5396      }      }
5397    else    else
5398  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
     {  
     read_char(common);  
5399      c = *cc;      c = *cc;
     }  
5400    
5401    if (type == OP_NOT || !char_has_othercase(common, cc))    if (type == OP_NOT || !char_has_othercase(common, cc))
5402        {
5403        read_char_range(common, c, c, TRUE);
5404      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));
5405        }
5406    else    else
5407      {      {
5408      oc = char_othercase(common, c);      oc = char_othercase(common, c);
5409        read_char_range(common, c < oc ? c : oc, c > oc ? c : oc, TRUE);
5410      bit = c ^ oc;      bit = c ^ oc;
5411      if (is_powerof2(bit))      if (is_powerof2(bit))
5412        {        {
# Line 4703  switch(type) Line 5424  switch(type)
5424    case OP_CLASS:    case OP_CLASS:
5425    case OP_NCLASS:    case OP_NCLASS:
5426    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5427    read_char(common);  
5428    if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, backtracks))  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5429      bit = (common->utf && is_char7_bitset((const pcre_uint8 *)cc, type == OP_NCLASS)) ? 127 : 255;
5430      read_char_range(common, 0, bit, type == OP_NCLASS);
5431    #else
5432      read_char_range(common, 0, 255, type == OP_NCLASS);
5433    #endif
5434    
5435      if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, FALSE, backtracks))
5436      return cc + 32 / sizeof(pcre_uchar);      return cc + 32 / sizeof(pcre_uchar);
5437    
5438  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5439    jump[0] = NULL;    jump[0] = NULL;
 #ifdef COMPILE_PCRE8  
   /* This check only affects 8 bit mode. In other modes, we  
   always need to compare the value with 255. */  
5440    if (common->utf)    if (common->utf)
 #endif /* COMPILE_PCRE8 */  
5441      {      {
5442      jump[0] = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump[0] = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, bit);
5443      if (type == OP_CLASS)      if (type == OP_CLASS)
5444        {        {
5445        add_jump(compiler, backtracks, jump[0]);        add_jump(compiler, backtracks, jump[0]);
5446        jump[0] = NULL;        jump[0] = NULL;
5447        }        }
5448      }      }
5449  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #elif !defined COMPILE_PCRE8
5450      jump[0] = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
5451      if (type == OP_CLASS)
5452        {
5453        add_jump(compiler, backtracks, jump[0]);
5454        jump[0] = NULL;
5455        }
5456    #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
5457    
5458    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
5459    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
5460    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
5461    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
5462    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
5463    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
5464    
5465  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
5466    if (jump[0] != NULL)    if (jump[0] != NULL)
5467      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
5468  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif
5469    
5470    return cc + 32 / sizeof(pcre_uchar);    return cc + 32 / sizeof(pcre_uchar);
5471    
5472  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
# Line 4837  if (context.length > 0) Line 5571  if (context.length > 0)
5571  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);
5572  }  }
5573    
 static struct sljit_jump *compile_ref_checks(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)  
 {  
 DEFINE_COMPILER;  
 int offset = GET2(cc, 1) << 1;  
   
 OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  
 if (!common->jscript_compat)  
   {  
   if (backtracks == NULL)  
     {  
     /* OVECTOR(1) contains the "string begin - 1" constant. */  
     OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  
     OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);  
     OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
     OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);  
     return JUMP(SLJIT_C_NOT_ZERO);  
     }  
   add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));  
   }  
 return CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
 }  
   
5574  /* Forward definitions. */  /* Forward definitions. */
5575  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);
5576  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);
# Line 4891  static void compile_backtrackingpath(com Line 5603  static void compile_backtrackingpath(com
5603    
5604  #define BACKTRACK_AS(type) ((type *)backtrack)  #define BACKTRACK_AS(type) ((type *)backtrack)
5605    
5606  static pcre_uchar *compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)  static void compile_dnref_search(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)
5607    {
5608    /* The OVECTOR offset goes to TMP2. */
5609    DEFINE_COMPILER;
5610    int count = GET2(cc, 1 + IMM2_SIZE);
5611    pcre_uchar *slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
5612    unsigned int offset;
5613    jump_list *found = NULL;
5614    
5615    SLJIT_ASSERT(*cc == OP_DNREF || *cc == OP_DNREFI);
5616    
5617    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
5618    
5619    count--;
5620    while (count-- > 0)
5621      {
5622      offset = GET2(slot, 0) << 1;
5623      GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5624      add_jump(compiler, &found, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5625      slot += common->name_entry_size;
5626      }
5627    
5628    offset = GET2(slot, 0) << 1;
5629    GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5630    if (backtracks != NULL && !common->jscript_compat)
5631      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5632    
5633    set_jumps(found, LABEL());
5634    }
5635    
5636    static void compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)
5637  {  {
5638  DEFINE_COMPILER;  DEFINE_COMPILER;
5639  int offset = GET2(cc, 1) << 1;  BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5640    int offset = 0;
5641  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
5642  struct sljit_jump *partial;  struct sljit_jump *partial;
5643  struct sljit_jump *nopartial;  struct sljit_jump *nopartial;
5644    
5645  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  if (ref)
5646  /* OVECTOR(1) contains the "string begin - 1" constant. */    {
5647  if (withchecks && !common->jscript_compat)    offset = GET2(cc, 1) << 1;
5648    add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5649      /* OVECTOR(1) contains the "string begin - 1" constant. */
5650      if (withchecks && !common->jscript_compat)
5651        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5652      }
5653    else
5654      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5655    
5656  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5657  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5658    {    {
5659    SLJIT_ASSERT(TMP1 == SLJIT_SCRATCH_REG1 && STACK_TOP == SLJIT_SCRATCH_REG2 && TMP2 == SLJIT_SCRATCH_REG3);    SLJIT_ASSERT(TMP1 == SLJIT_SCRATCH_REG1 && STACK_TOP == SLJIT_SCRATCH_REG2 && TMP2 == SLJIT_SCRATCH_REG3);
5660    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));    if (ref)
5661        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5662      else
5663        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5664    
5665    if (withchecks)    if (withchecks)
5666      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5667    
# Line 4933  if (common->utf && *cc == OP_REFI) Line 5686  if (common->utf && *cc == OP_REFI)
5686  else  else
5687  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
5688    {    {
5689    OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);    if (ref)
5690        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
5691      else
5692        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
5693    
5694    if (withchecks)    if (withchecks)
5695      jump = JUMP(SLJIT_C_ZERO);      jump = JUMP(SLJIT_C_ZERO);
5696    
# Line 4970  if (jump != NULL) Line 5727  if (jump != NULL)
5727    else    else
5728      JUMPHERE(jump);      JUMPHERE(jump);
5729    }    }
 return cc + 1 + IMM2_SIZE;  
5730  }  }
5731    
5732  static SLJIT_INLINE pcre_uchar *compile_ref_iterator_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)  static SLJIT_INLINE pcre_uchar *compile_ref_iterator_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5733  {  {
5734  DEFINE_COMPILER;  DEFINE_COMPILER;
5735    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5736  backtrack_common *backtrack;  backtrack_common *backtrack;
5737  pcre_uchar type;  pcre_uchar type;
5738    int offset = 0;
5739  struct sljit_label *label;  struct sljit_label *label;
5740  struct sljit_jump *zerolength;  struct sljit_jump *zerolength;
5741  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 4987  BOOL minimize; Line 5745  BOOL minimize;
5745    
5746  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
5747    
5748    if (ref)
5749      offset = GET2(cc, 1) << 1;
5750    else
5751      cc += IMM2_SIZE;
5752  type = cc[1 + IMM2_SIZE];  type = cc[1 + IMM2_SIZE];
5753    
5754    SLJIT_COMPILE_ASSERT((OP_CRSTAR & 0x1) == 0, crstar_opcode_must_be_even);
5755  minimize = (type & 0x1) != 0;  minimize = (type & 0x1) != 0;
5756  switch(type)  switch(type)
5757    {    {
# Line 5025  if (!minimize) Line 5789  if (!minimize)
5789    if (min == 0)    if (min == 0)
5790      {      {
5791      allocate_stack(common, 2);      allocate_stack(common, 2);
5792        if (ref)
5793          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5794      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5795      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5796      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5797      OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));      OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5798      zerolength = compile_ref_checks(common, ccbegin, NULL);      /* Handles both invalid and empty cases. Since the minimum repeat,
5799        is zero the invalid case is basically the same as an empty case. */
5800        if (ref)
5801          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5802        else
5803          {
5804          compile_dnref_search(common, ccbegin, NULL);
5805          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5806          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5807          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5808          }
5809      /* Restore if not zero length. */      /* Restore if not zero length. */
5810      OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));      OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5811      }      }
5812    else    else
5813      {      {
5814      allocate_stack(common, 1);      allocate_stack(common, 1);
5815        if (ref)
5816          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5817      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5818      zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);      if (ref)
5819          {
5820          add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5821          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5822          }
5823        else
5824          {
5825          compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5826          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5827          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5828          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5829          }
5830      }      }
5831    
5832    if (min > 1 || max > 1)    if (min > 1 || max > 1)
5833      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
5834    
5835    label = LABEL();    label = LABEL();
5836      if (!ref)
5837        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
5838    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);
5839    
5840    if (min > 1 || max > 1)    if (min > 1 || max > 1)
# Line 5074  if (!minimize) Line 5865  if (!minimize)
5865    JUMPHERE(zerolength);    JUMPHERE(zerolength);
5866    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5867    
5868    decrease_call_count(common);    count_match(common);
5869    return cc;    return cc;
5870    }    }
5871    
5872  allocate_stack(common, 2);  allocate_stack(common, ref ? 2 : 3);
5873    if (ref)
5874      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5875  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5876  if (type != OP_CRMINSTAR)  if (type != OP_CRMINSTAR)
5877    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5878    
5879  if (min == 0)  if (min == 0)
5880    {    {
5881    zerolength = compile_ref_checks(common, ccbegin, NULL);    /* Handles both invalid and empty cases. Since the minimum repeat,
5882      is zero the invalid case is basically the same as an empty case. */
5883      if (ref)
5884        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5885      else
5886        {
5887        compile_dnref_search(common, ccbegin, NULL);
5888        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5889        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5890        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5891        }
5892      /* Length is non-zero, we can match real repeats. */
5893    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5894    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
5895    }    }
5896  else  else
5897    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);    {
5898      if (ref)
5899        {
5900        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5901        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5902        }
5903      else
5904        {
5905        compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5906        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5907        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5908        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5909        }
5910      }
5911    
5912  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5913  if (max > 0)  if (max > 0)
5914    add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, max));    add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, max));
5915    
5916    if (!ref)
5917      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
5918  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);
5919  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5920    
# Line 5113  if (jump != NULL) Line 5932  if (jump != NULL)
5932    JUMPHERE(jump);    JUMPHERE(jump);
5933  JUMPHERE(zerolength);  JUMPHERE(zerolength);
5934    
5935  decrease_call_count(common);  count_match(common);
5936  return cc;  return cc;
5937  }  }
5938    
# Line 5123  DEFINE_COMPILER; Line 5942  DEFINE_COMPILER;
5942  backtrack_common *backtrack;  backtrack_common *backtrack;
5943  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5944  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5945  int start = GET(cc, 1);  sljit_sw start = GET(cc, 1);
5946  pcre_uchar *start_cc;  pcre_uchar *start_cc;
5947    BOOL needs_control_head;
5948    
5949  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5950    
5951  /* Inlining simple patterns. */  /* Inlining simple patterns. */
5952  if (get_framesize(common, common->start + start, TRUE) == no_stack)  if (get_framesize(common, common->start + start, NULL, TRUE, &needs_control_head) == no_stack)
5953    {    {
5954    start_cc = common->start + start;    start_cc = common->start + start;
5955    compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);    compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
# Line 5248  allocate_stack(common, CALLOUT_ARG_SIZE Line 6068  allocate_stack(common, CALLOUT_ARG_SIZE
6068  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6069  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
6070  SLJIT_ASSERT(common->capture_last_ptr != 0);  SLJIT_ASSERT(common->capture_last_ptr != 0);
6071  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);
6072  OP1(SLJIT_MOV_UI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);
6073    
6074  /* These pointer sized fields temporarly stores internal variables. */  /* These pointer sized fields temporarly stores internal variables. */
6075  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
# Line 5258  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CA Line 6078  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CA
6078    
6079  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
6080    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr));    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr));
6081  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 2));  OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 2));
6082  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 2 + LINK_SIZE));  OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 2 + LINK_SIZE));
6083  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);
6084    
6085  /* Needed to save important temporary registers. */  /* Needed to save important temporary registers. */
# Line 5288  static pcre_uchar *compile_assert_matchi Line 6108  static pcre_uchar *compile_assert_matchi
6108  {  {
6109  DEFINE_COMPILER;  DEFINE_COMPILER;
6110  int framesize;  int framesize;
6111    int extrasize;
6112    BOOL needs_control_head;
6113  int private_data_ptr;  int private_data_ptr;
6114  backtrack_common altbacktrack;  backtrack_common altbacktrack;
6115  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
# Line 5297  jump_list *tmp = NULL; Line 6119  jump_list *tmp = NULL;
6119  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
6120  jump_list **found;  jump_list **found;
6121  /* Saving previous accept variables. */  /* Saving previous accept variables. */
6122    BOOL save_local_exit = common->local_exit;
6123    BOOL save_positive_assert = common->positive_assert;
6124    then_trap_backtrack *save_then_trap = common->then_trap;
6125  struct sljit_label *save_quit_label = common->quit_label;  struct sljit_label *save_quit_label = common->quit_label;
6126  struct sljit_label *save_accept_label = common->accept_label;  struct sljit_label *save_accept_label = common->accept_label;
6127  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
6128    jump_list *save_positive_assert_quit = common->positive_assert_quit;
6129  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
6130  struct sljit_jump *jump;  struct sljit_jump *jump;
6131  struct sljit_jump *brajump = NULL;  struct sljit_jump *brajump = NULL;
6132    
6133    /* Assert captures then. */
6134    common->then_trap = NULL;
6135    
6136  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
6137    {    {
6138    SLJIT_ASSERT(!conditional);    SLJIT_ASSERT(!conditional);
# Line 5312  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 6141  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
6141    }    }
6142  private_data_ptr = PRIVATE_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
6143  SLJIT_ASSERT(private_data_ptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
6144  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
6145  backtrack->framesize = framesize;  backtrack->framesize = framesize;
6146  backtrack->private_data_ptr = private_data_ptr;  backtrack->private_data_ptr = private_data_ptr;
6147  opcode = *cc;  opcode = *cc;
# Line 5331  if (bra == OP_BRAMINZERO) Line 6160  if (bra == OP_BRAMINZERO)
6160    
6161  if (framesize < 0)  if (framesize < 0)
6162    {    {
6163    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    extrasize = needs_control_head ? 2 : 1;
6164    allocate_stack(common, 1);    if (framesize == no_frame)
6165        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6166      allocate_stack(common, extrasize);
6167      if (needs_control_head)
6168        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6169    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6170      if (needs_control_head)
6171        {
6172        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
6173        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
6174        }
6175    }    }
6176  else  else
6177    {    {
6178    allocate_stack(common, framesize + 2);    extrasize = needs_control_head ? 3 : 2;
6179      allocate_stack(common, framesize + extrasize);
6180    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6181    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(framesize + 1));    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
6182    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);
6183      if (needs_control_head)
6184        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6185    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6186    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    if (needs_control_head)
6187    init_frame(common, ccbegin, framesize + 1, 2, FALSE);      {
6188        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
6189        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6190        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
6191        }
6192      else
6193        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
6194      init_frame(common, ccbegin, NULL, framesize + extrasize - 1, extrasize, FALSE);
6195    }    }
6196    
6197  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
6198  common->quit_label = NULL;  if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6199  common->quit = NULL;    {
6200      /* Negative assert is stronger than positive assert. */
6201      common->local_exit = TRUE;
6202      common->quit_label = NULL;
6203      common->quit = NULL;
6204      common->positive_assert = FALSE;
6205      }
6206    else
6207      common->positive_assert = TRUE;
6208    common->positive_assert_quit = NULL;
6209    
6210  while (1)  while (1)
6211    {    {
6212    common->accept_label = NULL;    common->accept_label = NULL;
# Line 5363  while (1) Line 6221  while (1)
6221    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
6222    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
6223      {      {
6224      common->quit_label = save_quit_label;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6225          {
6226          common->local_exit = save_local_exit;
6227          common->quit_label = save_quit_label;
6228          common->quit = save_quit;
6229          }
6230        common->positive_assert = save_positive_assert;
6231        common->then_trap = save_then_trap;
6232      common->accept_label = save_accept_label;      common->accept_label = save_accept_label;
6233      common->quit = save_quit;      common->positive_assert_quit = save_positive_assert_quit;
6234      common->accept = save_accept;      common->accept = save_accept;
6235      return NULL;      return NULL;
6236      }      }
# Line 5375  while (1) Line 6240  while (1)
6240    
6241    /* Reset stack. */    /* Reset stack. */
6242    if (framesize < 0)    if (framesize < 0)
6243      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      {
6244    else {      if (framesize == no_frame)
6245          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6246        else
6247          free_stack(common, extrasize);
6248        if (needs_control_head)
6249          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
6250        }
6251      else
6252        {
6253      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)
6254        {        {
6255        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
6256        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));
6257          if (needs_control_head)
6258            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
6259        }        }
6260      else      else
6261        {        {
6262        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6263          if (needs_control_head)
6264            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));
6265        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
6266        }        }
6267    }      }
6268    
6269    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6270      {      {
6271      /* We know that STR_PTR was stored on the top of the stack. */      /* We know that STR_PTR was stored on the top of the stack. */
6272      if (conditional)      if (conditional)
6273        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), needs_control_head ? sizeof(sljit_sw) : 0);
6274      else if (bra == OP_BRAZERO)      else if (bra == OP_BRAZERO)
6275        {        {
6276        if (framesize < 0)        if (framesize < 0)
6277          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 1) * sizeof(sljit_sw));
6278        else        else
6279          {          {
6280          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));
6281          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (framesize + extrasize - 1) * sizeof(sljit_sw));
6282          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
6283          }          }
6284        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
# Line 5418  while (1) Line 6295  while (1)
6295    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
6296    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
6297      {      {
6298      common->quit_label = save_quit_label;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6299          {
6300          common->local_exit = save_local_exit;
6301          common->quit_label = save_quit_label;
6302          common->quit = save_quit;
6303          }
6304        common->positive_assert = save_positive_assert;
6305        common->then_trap = save_then_trap;
6306      common->accept_label = save_accept_label;      common->accept_label = save_accept_label;
6307      common->quit = save_quit;      common->positive_assert_quit = save_positive_assert_quit;
6308      common->accept = save_accept;      common->accept = save_accept;
6309      return NULL;      return NULL;
6310      }      }
# Line 5432  while (1) Line 6316  while (1)
6316    ccbegin = cc;    ccbegin = cc;
6317    cc += GET(cc, 1);    cc += GET(cc, 1);
6318    }    }
6319    
6320    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6321      {
6322      SLJIT_ASSERT(common->positive_assert_quit == NULL);
6323      /* Makes the check less complicated below. */
6324      common->positive_assert_quit = common->quit;
6325      }
6326    
6327  /* None of them matched. */  /* None of them matched. */
6328  if (common->quit != NULL)  if (common->positive_assert_quit != NULL)
6329    set_jumps(common->quit, LABEL());    {
6330      jump = JUMP(SLJIT_JUMP);
6331      set_jumps(common->positive_assert_quit, LABEL());
6332      SLJIT_ASSERT(framesize != no_stack);
6333      if (framesize < 0)
6334        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));
6335      else
6336        {
6337        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6338        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
6339        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
6340        }
6341      JUMPHERE(jump);
6342      }
6343    
6344    if (needs_control_head)
6345      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(1));
6346    
6347  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)
6348    {    {
# Line 5446  if (opcode == OP_ASSERT || opcode == OP_ Line 6354  if (opcode == OP_ASSERT || opcode == OP_
6354      {      {
6355      /* The topmost item should be 0. */      /* The topmost item should be 0. */
6356      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
6357          {
6358          if (extrasize == 2)
6359            free_stack(common, 1);
6360        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6361          }
6362      else      else
6363        free_stack(common, 1);        free_stack(common, extrasize);
6364      }      }
6365    else    else
6366      {      {
6367      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
6368      /* The topmost item should be 0. */      /* The topmost item should be 0. */
6369      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
6370        {        {
6371        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
6372        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6373        }        }
6374      else      else
6375        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
6376      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
6377      }      }
6378    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
# Line 5472  if (opcode == OP_ASSERT || opcode == OP_ Line 6384  if (opcode == OP_ASSERT || opcode == OP_
6384    if (framesize < 0)    if (framesize < 0)
6385      {      {
6386      /* We know that STR_PTR was stored on the top of the stack. */      /* We know that STR_PTR was stored on the top of the stack. */
6387      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 1) * sizeof(sljit_sw));
6388      /* Keep the STR_PTR on the top of the stack. */      /* Keep the STR_PTR on the top of the stack. */
6389      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
6390          {
6391        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
6392          if (extrasize == 2)
6393            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6394          }
6395      else if (bra == OP_BRAMINZERO)      else if (bra == OP_BRAMINZERO)
6396        {        {
6397        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
# Line 5488  if (opcode == OP_ASSERT || opcode == OP_ Line 6404  if (opcode == OP_ASSERT || opcode == OP_
6404        {        {
6405        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
6406        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));
6407        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 2) * sizeof(sljit_sw));
6408        }        }
6409      else      else
6410        {        {
6411        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
6412        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 2) * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 2) * sizeof(sljit_sw));
6413        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        if (extrasize == 2)
6414        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);          {
6415            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6416            if (bra == OP_BRAMINZERO)
6417              OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6418            }
6419          else
6420            {
6421            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
6422            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);
6423            }
6424        }        }
6425      }      }
6426    
# Line 5524  else Line 6449  else
6449      {      {
6450      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6451      if (bra != OP_BRA)      if (bra != OP_BRA)
6452          {
6453          if (extrasize == 2)
6454            free_stack(common, 1);
6455        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6456          }
6457      else      else
6458        free_stack(common, 1);        free_stack(common, extrasize);
6459      }      }
6460    else    else
6461      {      {
6462      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6463      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
6464      /* The topmost item should be 0. */      /* The topmost item should be 0. */
6465      if (bra != OP_BRA)      if (bra != OP_BRA)
6466        {        {
6467        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
6468        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6469        }        }
6470      else      else
6471        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
6472      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
6473      }      }
6474    
# Line 5559  else Line 6488  else
6488      }      }
6489 &n