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

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

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

revision 1221 by ph10, Sun Nov 11 20:27:03 2012 UTC revision 1434 by zherczeg, Mon Jan 6 20:04:50 2014 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11    The machine code generator part (this module) was written by Zoltan Herczeg    The machine code generator part (this module) was written by Zoltan Herczeg
12                        Copyright (c) 2010-2012                        Copyright (c) 2010-2013
13    
14  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
15  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 65  system files. */ Line 65  system files. */
65  #error Unsupported architecture  #error Unsupported architecture
66  #endif  #endif
67    
68    /* Defines for debugging purposes. */
69    
70    /* 1 - Use unoptimized capturing brackets.
71       2 - Enable capture_last_ptr (includes option 1). */
72    /* #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 157  typedef struct jit_arguments { Line 166  typedef struct jit_arguments {
166    int *offsets;    int *offsets;
167    pcre_uchar *uchar_ptr;    pcre_uchar *uchar_ptr;
168    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
169      void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171    int offsetcount;    pcre_uint32 limit_match;
172    int calllimit;    int real_offset_count;
173      int offset_count;
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 168  typedef struct jit_arguments { Line 179  typedef struct jit_arguments {
179    
180  typedef struct executable_functions {  typedef struct executable_functions {
181    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182      sljit_uw *read_only_data[JIT_NUMBER_OF_COMPILE_MODES];
183      sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
184    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
185    void *userdata;    void *userdata;
186    pcre_uint32 top_bracket;    pcre_uint32 top_bracket;
187    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    pcre_uint32 limit_match;
188  } executable_functions;  } executable_functions;
189    
190  typedef struct jump_list {  typedef struct jump_list {
# Line 179  typedef struct jump_list { Line 192  typedef struct jump_list {
192    struct jump_list *next;    struct jump_list *next;
193  } jump_list;  } jump_list;
194    
 enum stub_types { stack_alloc };  
   
195  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
196    struct sljit_jump *start;    struct sljit_jump *start;
197    struct sljit_label *quit;    struct sljit_label *quit;
198    struct stub_list *next;    struct stub_list *next;
199  } stub_list;  } stub_list;
200    
201    typedef struct label_addr_list {
202      struct sljit_label *label;
203      sljit_uw *addr;
204      struct label_addr_list *next;
205    } label_addr_list;
206    
207    enum frame_types {
208      no_frame = -1,
209      no_stack = -2
210    };
211    
212    enum control_types {
213      type_mark = 0,
214      type_then_trap = 1
215    };
216    
217  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
218    
219  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
220  code generator. It is allocated by compile_matchingpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
221  the aguments for compile_backtrackingpath. Must be the first member  the arguments for compile_backtrackingpath. Must be the first member
222  of its descendants. */  of its descendants. */
223  typedef struct backtrack_common {  typedef struct backtrack_common {
224    /* Concatenation stack. */    /* Concatenation stack. */
# Line 209  typedef struct backtrack_common { Line 234  typedef struct backtrack_common {
234  typedef struct assert_backtrack {  typedef struct assert_backtrack {
235    backtrack_common common;    backtrack_common common;
236    jump_list *condfailed;    jump_list *condfailed;
237    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
238    int framesize;    int framesize;
239    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
240    int private_data_ptr;    int private_data_ptr;
# Line 230  typedef struct bracket_backtrack { Line 255  typedef struct bracket_backtrack {
255      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
256      jump_list *condfailed;      jump_list *condfailed;
257      assert_backtrack *assert;      assert_backtrack *assert;
258      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
259      int framesize;      int framesize;
260    } u;    } u;
261    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
# Line 265  typedef struct recurse_entry { Line 290  typedef struct recurse_entry {
290    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
291    jump_list *calls;    jump_list *calls;
292    /* Points to the starting opcode. */    /* Points to the starting opcode. */
293    int start;    sljit_sw start;
294  } recurse_entry;  } recurse_entry;
295    
296  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
297    backtrack_common common;    backtrack_common common;
298      BOOL inlined_pattern;
299  } recurse_backtrack;  } recurse_backtrack;
300    
301  #define MAX_RANGE_SIZE 6  #define OP_THEN_TRAP OP_TABLE_LENGTH
302    
303    typedef struct then_trap_backtrack {
304      backtrack_common common;
305      /* If then_trap is not NULL, this structure contains the real
306      then_trap for the backtracking path. */
307      struct then_trap_backtrack *then_trap;
308      /* Points to the starting opcode. */
309      sljit_sw start;
310      /* Exit point for the then opcodes of this alternative. */
311      jump_list *quit;
312      /* Frame size of the current alternative. */
313      int framesize;
314    } then_trap_backtrack;
315    
316    #define MAX_RANGE_SIZE 4
317    
318  typedef struct compiler_common {  typedef struct compiler_common {
319      /* The sljit ceneric compiler. */
320    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
321      /* First byte code. */
322    pcre_uchar *start;    pcre_uchar *start;
   
323    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
324    int *private_data_ptrs;    sljit_si *private_data_ptrs;
325      /* This read-only data is available during runtime. */
326      sljit_uw *read_only_data;
327      /* The total size of the read-only data. */
328      sljit_uw read_only_data_size;
329      /* The next free entry of the read_only_data. */
330      sljit_uw *read_only_data_ptr;
331    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
332    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
333      /* Tells whether the starting offset is a target of then. */
334      pcre_uint8 *then_offsets;
335      /* Current position where a THEN must jump. */
336      then_trap_backtrack *then_trap;
337    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
338    int cbraptr;    int cbra_ptr;
339    /* OVector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
340    int ovector_start;    int ovector_start;
341    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
342    int req_char_ptr;    int req_char_ptr;
343    /* Head of the last recursion. */    /* Head of the last recursion. */
344    int recursive_head;    int recursive_head_ptr;
345    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
346    int start_used_ptr;    int start_used_ptr;
347    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 298  typedef struct compiler_common { Line 350  typedef struct compiler_common {
350    int first_line_end;    int first_line_end;
351    /* Points to the marked string. */    /* Points to the marked string. */
352    int mark_ptr;    int mark_ptr;
353      /* Recursive control verb management chain. */
354      int control_head_ptr;
355      /* Points to the last matched capture block index. */
356      int capture_last_ptr;
357      /* Points to the starting position of the current match. */
358      int start_ptr;
359    
360    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
361    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
362    sljit_sw lcc;    sljit_sw lcc;
363    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
364    int mode;    int mode;
365      /* \K is found in the pattern. */
366      BOOL has_set_som;
367      /* (*SKIP:arg) is found in the pattern. */
368      BOOL has_skip_arg;
369      /* (*THEN) is found in the pattern. */
370      BOOL has_then;
371      /* Needs to know the start position anytime. */
372      BOOL needs_start_ptr;
373      /* Currently in recurse or negative assert. */
374      BOOL local_exit;
375      /* Currently in a positive assert. */
376      BOOL positive_assert;
377    /* Newline control. */    /* Newline control. */
378    int nltype;    int nltype;
379      pcre_uint32 nlmax;
380      pcre_uint32 nlmin;
381    int newline;    int newline;
382    int bsr_nltype;    int bsr_nltype;
383      pcre_uint32 bsr_nlmax;
384      pcre_uint32 bsr_nlmin;
385    /* Dollar endonly. */    /* Dollar endonly. */
386    int endonly;    int endonly;
   BOOL has_set_som;  
387    /* Tables. */    /* Tables. */
388    sljit_sw ctypes;    sljit_sw ctypes;
   int digits[2 + MAX_RANGE_SIZE];  
389    /* Named capturing brackets. */    /* Named capturing brackets. */
390    sljit_uw name_table;    pcre_uchar *name_table;
391    sljit_sw name_count;    sljit_sw name_count;
392    sljit_sw name_entry_size;    sljit_sw name_entry_size;
393    
394    /* Labels and jump lists. */    /* Labels and jump lists. */
395    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
396    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
397    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
398      struct sljit_label *accept_label;
399    stub_list *stubs;    stub_list *stubs;
400      label_addr_list *label_addrs;
401    recurse_entry *entries;    recurse_entry *entries;
402    recurse_entry *currententry;    recurse_entry *currententry;
403    jump_list *partialmatch;    jump_list *partialmatch;
404    jump_list *quit;    jump_list *quit;
405      jump_list *positive_assert_quit;
406      jump_list *forced_quit;
407    jump_list *accept;    jump_list *accept;
408    jump_list *calllimit;    jump_list *calllimit;
409    jump_list *stackalloc;    jump_list *stackalloc;
# Line 338  typedef struct compiler_common { Line 414  typedef struct compiler_common {
414    jump_list *vspace;    jump_list *vspace;
415    jump_list *casefulcmp;    jump_list *casefulcmp;
416    jump_list *caselesscmp;    jump_list *caselesscmp;
417      jump_list *reset_match;
418    BOOL jscript_compat;    BOOL jscript_compat;
419  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
420    BOOL utf;    BOOL utf;
421  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
422    BOOL use_ucp;    BOOL use_ucp;
423  #endif  #endif
 #ifndef COMPILE_PCRE32  
   jump_list *utfreadchar;  
 #endif  
424  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
425      jump_list *utfreadchar;
426      jump_list *utfreadchar16;
427    jump_list *utfreadtype8;    jump_list *utfreadtype8;
428  #endif  #endif
429  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
# Line 390  typedef struct compare_context { Line 466  typedef struct compare_context {
466  #endif  #endif
467  } compare_context;  } compare_context;
468    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
469  /* Undefine sljit macros. */  /* Undefine sljit macros. */
470  #undef CMP  #undef CMP
471    
# Line 410  enum { Line 480  enum {
480  #define STACK_TOP     SLJIT_SCRATCH_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
481  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
482  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
483  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define COUNT_MATCH   SLJIT_SAVED_EREG2
484  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
485    
486  /* Local space layout. */  /* Local space layout. */
# Line 421  enum { Line 491  enum {
491  #define POSSESSIVE0      (2 * sizeof(sljit_sw))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
492  #define POSSESSIVE1      (3 * sizeof(sljit_sw))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
493  /* Max limit of recursions. */  /* Max limit of recursions. */
494  #define CALL_LIMIT       (4 * sizeof(sljit_sw))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
495  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
496  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
497  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
498  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. */
499  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
500  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))  #define OVECTOR(i)       (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw))
501  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_sw))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
502  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
503    
504  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
# Line 459  the start pointers when the end of the c Line 529  the start pointers when the end of the c
529    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
530  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
531    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
532    #define SET_LABEL(jump, label) \
533      sljit_set_label((jump), (label))
534  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
535    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
536  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
# Line 468  the start pointers when the end of the c Line 540  the start pointers when the end of the c
540  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
541    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
542    
543    #define READ_CHAR_MAX 0x7fffffff
544    
545  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
546  {  {
547  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 477  cc += 1 + LINK_SIZE; Line 551  cc += 1 + LINK_SIZE;
551  return cc;  return cc;
552  }  }
553    
554    static int no_alternatives(pcre_uchar* cc)
555    {
556    int count = 0;
557    SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
558    do
559      {
560      cc += GET(cc, 1);
561      count++;
562      }
563    while (*cc == OP_ALT);
564    SLJIT_ASSERT(*cc >= OP_KET && *cc <= OP_KETRPOS);
565    return count;
566    }
567    
568    static int ones_in_half_byte[16] = {
569      /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
570      /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
571    };
572    
573  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
574   next_opcode   next_opcode
575   get_private_data_length   check_opcode_types
576   set_private_data_ptrs   set_private_data_ptrs
577   get_framesize   get_framesize
578   init_frame   init_frame
579   get_private_data_length_for_copy   get_private_data_copy_length
580   copy_private_data   copy_private_data
581   compile_matchingpath   compile_matchingpath
582   compile_backtrackingpath   compile_backtrackingpath
# Line 507  switch(*cc) Line 600  switch(*cc)
600    case OP_WORDCHAR:    case OP_WORDCHAR:
601    case OP_ANY:    case OP_ANY:
602    case OP_ALLANY:    case OP_ALLANY:
603      case OP_NOTPROP:
604      case OP_PROP:
605    case OP_ANYNL:    case OP_ANYNL:
606    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
607    case OP_HSPACE:    case OP_HSPACE:
# Line 519  switch(*cc) Line 614  switch(*cc)
614    case OP_CIRCM:    case OP_CIRCM:
615    case OP_DOLL:    case OP_DOLL:
616    case OP_DOLLM:    case OP_DOLLM:
   case OP_TYPESTAR:  
   case OP_TYPEMINSTAR:  
   case OP_TYPEPLUS:  
   case OP_TYPEMINPLUS:  
   case OP_TYPEQUERY:  
   case OP_TYPEMINQUERY:  
   case OP_TYPEPOSSTAR:  
   case OP_TYPEPOSPLUS:  
   case OP_TYPEPOSQUERY:  
617    case OP_CRSTAR:    case OP_CRSTAR:
618    case OP_CRMINSTAR:    case OP_CRMINSTAR:
619    case OP_CRPLUS:    case OP_CRPLUS:
620    case OP_CRMINPLUS:    case OP_CRMINPLUS:
621    case OP_CRQUERY:    case OP_CRQUERY:
622    case OP_CRMINQUERY:    case OP_CRMINQUERY:
623      case OP_CRRANGE:
624      case OP_CRMINRANGE:
625      case OP_CRPOSSTAR:
626      case OP_CRPOSPLUS:
627      case OP_CRPOSQUERY:
628      case OP_CRPOSRANGE:
629      case OP_CLASS:
630      case OP_NCLASS:
631      case OP_REF:
632      case OP_REFI:
633      case OP_DNREF:
634      case OP_DNREFI:
635      case OP_RECURSE:
636      case OP_CALLOUT:
637      case OP_ALT:
638      case OP_KET:
639      case OP_KETRMAX:
640      case OP_KETRMIN:
641      case OP_KETRPOS:
642      case OP_REVERSE:
643      case OP_ASSERT:
644      case OP_ASSERT_NOT:
645      case OP_ASSERTBACK:
646      case OP_ASSERTBACK_NOT:
647      case OP_ONCE:
648      case OP_ONCE_NC:
649      case OP_BRA:
650      case OP_BRAPOS:
651      case OP_CBRA:
652      case OP_CBRAPOS:
653      case OP_COND:
654      case OP_SBRA:
655      case OP_SBRAPOS:
656      case OP_SCBRA:
657      case OP_SCBRAPOS:
658      case OP_SCOND:
659      case OP_CREF:
660      case OP_DNCREF:
661      case OP_RREF:
662      case OP_DNRREF:
663    case OP_DEF:    case OP_DEF:
664    case OP_BRAZERO:    case OP_BRAZERO:
665    case OP_BRAMINZERO:    case OP_BRAMINZERO:
666    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
667      case OP_PRUNE:
668      case OP_SKIP:
669      case OP_THEN:
670    case OP_COMMIT:    case OP_COMMIT:
671    case OP_FAIL:    case OP_FAIL:
672    case OP_ACCEPT:    case OP_ACCEPT:
673    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
674      case OP_CLOSE:
675    case OP_SKIPZERO:    case OP_SKIPZERO:
676    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
677    
678    case OP_CHAR:    case OP_CHAR:
679    case OP_CHARI:    case OP_CHARI:
# Line 561  switch(*cc) Line 685  switch(*cc)
685    case OP_MINPLUS:    case OP_MINPLUS:
686    case OP_QUERY:    case OP_QUERY:
687    case OP_MINQUERY:    case OP_MINQUERY:
688      case OP_UPTO:
689      case OP_MINUPTO:
690      case OP_EXACT:
691    case OP_POSSTAR:    case OP_POSSTAR:
692    case OP_POSPLUS:    case OP_POSPLUS:
693    case OP_POSQUERY:    case OP_POSQUERY:
694      case OP_POSUPTO:
695    case OP_STARI:    case OP_STARI:
696    case OP_MINSTARI:    case OP_MINSTARI:
697    case OP_PLUSI:    case OP_PLUSI:
698    case OP_MINPLUSI:    case OP_MINPLUSI:
699    case OP_QUERYI:    case OP_QUERYI:
700    case OP_MINQUERYI:    case OP_MINQUERYI:
701      case OP_UPTOI:
702      case OP_MINUPTOI:
703      case OP_EXACTI:
704    case OP_POSSTARI:    case OP_POSSTARI:
705    case OP_POSPLUSI:    case OP_POSPLUSI:
706    case OP_POSQUERYI:    case OP_POSQUERYI:
707      case OP_POSUPTOI:
708    case OP_NOTSTAR:    case OP_NOTSTAR:
709    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
710    case OP_NOTPLUS:    case OP_NOTPLUS:
711    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
712    case OP_NOTQUERY:    case OP_NOTQUERY:
713    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
714      case OP_NOTUPTO:
715      case OP_NOTMINUPTO:
716      case OP_NOTEXACT:
717    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
718    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
719    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
720      case OP_NOTPOSUPTO:
721    case OP_NOTSTARI:    case OP_NOTSTARI:
722    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
723    case OP_NOTPLUSI:    case OP_NOTPLUSI:
724    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
725    case OP_NOTQUERYI:    case OP_NOTQUERYI:
726    case OP_NOTMINQUERYI:    case OP_NOTMINQUERYI:
   case OP_NOTPOSSTARI:  
   case OP_NOTPOSPLUSI:  
   case OP_NOTPOSQUERYI:  
   cc += 2;  
 #ifdef SUPPORT_UTF  
   if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
   return cc;  
   
   case OP_UPTO:  
   case OP_MINUPTO:  
   case OP_EXACT:  
   case OP_POSUPTO:  
   case OP_UPTOI:  
   case OP_MINUPTOI:  
   case OP_EXACTI:  
   case OP_POSUPTOI:  
   case OP_NOTUPTO:  
   case OP_NOTMINUPTO:  
   case OP_NOTEXACT:  
   case OP_NOTPOSUPTO:  
727    case OP_NOTUPTOI:    case OP_NOTUPTOI:
728    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
729    case OP_NOTEXACTI:    case OP_NOTEXACTI:
730      case OP_NOTPOSSTARI:
731      case OP_NOTPOSPLUSI:
732      case OP_NOTPOSQUERYI:
733    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
734    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
735  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
736    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
737  #endif  #endif
738    return cc;    return cc;
739    
740    case OP_NOTPROP:    /* Special cases. */
741    case OP_PROP:    case OP_TYPESTAR:
742    return cc + 1 + 2;    case OP_TYPEMINSTAR:
743      case OP_TYPEPLUS:
744      case OP_TYPEMINPLUS:
745      case OP_TYPEQUERY:
746      case OP_TYPEMINQUERY:
747    case OP_TYPEUPTO:    case OP_TYPEUPTO:
748    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
749    case OP_TYPEEXACT:    case OP_TYPEEXACT:
750      case OP_TYPEPOSSTAR:
751      case OP_TYPEPOSPLUS:
752      case OP_TYPEPOSQUERY:
753    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
754    case OP_REF:    return cc + PRIV(OP_lengths)[*cc] - 1;
   case OP_REFI:  
   case OP_CREF:  
   case OP_NCREF:  
   case OP_RREF:  
   case OP_NRREF:  
   case OP_CLOSE:  
   cc += 1 + IMM2_SIZE;  
   return cc;  
755    
756    case OP_CRRANGE:    case OP_ANYBYTE:
757    case OP_CRMINRANGE:  #ifdef SUPPORT_UTF
758    return cc + 1 + 2 * IMM2_SIZE;    if (common->utf) return NULL;
759    #endif
760    case OP_CLASS:    return cc + 1;
   case OP_NCLASS:  
   return cc + 1 + 32 / sizeof(pcre_uchar);  
761    
762  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
763    case OP_XCLASS:    case OP_XCLASS:
764    return cc + GET(cc, 1);    return cc + GET(cc, 1);
765  #endif  #endif
766    
   case OP_RECURSE:  
   case OP_ASSERT:  
   case OP_ASSERT_NOT:  
   case OP_ASSERTBACK:  
   case OP_ASSERTBACK_NOT:  
   case OP_REVERSE:  
   case OP_ONCE:  
   case OP_ONCE_NC:  
   case OP_BRA:  
   case OP_BRAPOS:  
   case OP_COND:  
   case OP_SBRA:  
   case OP_SBRAPOS:  
   case OP_SCOND:  
   case OP_ALT:  
   case OP_KET:  
   case OP_KETRMAX:  
   case OP_KETRMIN:  
   case OP_KETRPOS:  
   return cc + 1 + LINK_SIZE;  
   
   case OP_CBRA:  
   case OP_CBRAPOS:  
   case OP_SCBRA:  
   case OP_SCBRAPOS:  
   return cc + 1 + LINK_SIZE + IMM2_SIZE;  
   
767    case OP_MARK:    case OP_MARK:
768      case OP_PRUNE_ARG:
769      case OP_SKIP_ARG:
770      case OP_THEN_ARG:
771    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
772    
773    default:    default:
774      /* All opcodes are supported now! */
775      SLJIT_ASSERT_STOP();
776    return NULL;    return NULL;
777    }    }
778  }  }
779    
780  #define CASE_ITERATOR_PRIVATE_DATA_1 \  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
781      case OP_MINSTAR: \  {
782      case OP_MINPLUS: \  int count;
783      case OP_QUERY: \  pcre_uchar *slot;
     case OP_MINQUERY: \  
     case OP_MINSTARI: \  
     case OP_MINPLUSI: \  
     case OP_QUERYI: \  
     case OP_MINQUERYI: \  
     case OP_NOTMINSTAR: \  
     case OP_NOTMINPLUS: \  
     case OP_NOTQUERY: \  
     case OP_NOTMINQUERY: \  
     case OP_NOTMINSTARI: \  
     case OP_NOTMINPLUSI: \  
     case OP_NOTQUERYI: \  
     case OP_NOTMINQUERYI:  
784    
785  #define CASE_ITERATOR_PRIVATE_DATA_2A \  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
786      case OP_STAR: \  while (cc < ccend)
787      case OP_PLUS: \    {
788      case OP_STARI: \    switch(*cc)
789      case OP_PLUSI: \      {
790      case OP_NOTSTAR: \      case OP_SET_SOM:
791      case OP_NOTPLUS: \      common->has_set_som = TRUE;
792      case OP_NOTSTARI: \      cc += 1;
793      case OP_NOTPLUSI:      break;
794    
795  #define CASE_ITERATOR_PRIVATE_DATA_2B \      case OP_REF:
796      case OP_UPTO: \      case OP_REFI:
797      case OP_MINUPTO: \      common->optimized_cbracket[GET2(cc, 1)] = 0;
798      case OP_UPTOI: \      cc += 1 + IMM2_SIZE;
799      case OP_MINUPTOI: \      break;
     case OP_NOTUPTO: \  
     case OP_NOTMINUPTO: \  
     case OP_NOTUPTOI: \  
     case OP_NOTMINUPTOI:  
800    
801  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \      case OP_BRA:
802      case OP_TYPEMINSTAR: \      case OP_CBRA:
803      case OP_TYPEMINPLUS: \      case OP_SBRA:
804      case OP_TYPEQUERY: \      case OP_SCBRA:
805      case OP_TYPEMINQUERY:      count = no_alternatives(cc);
806        if (count > 4)
807          common->read_only_data_size += count * sizeof(sljit_uw);
808        cc += 1 + LINK_SIZE + (*cc == OP_CBRA || *cc == OP_SCBRA ? IMM2_SIZE : 0);
809        break;
810    
811  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \      case OP_CBRAPOS:
812      case OP_TYPESTAR: \      case OP_SCBRAPOS:
813      case OP_TYPEPLUS:      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
814        cc += 1 + LINK_SIZE + IMM2_SIZE;
815        break;
816    
817  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \      case OP_COND:
818      case OP_TYPEUPTO: \      case OP_SCOND:
819      case OP_TYPEMINUPTO:      /* Only AUTO_CALLOUT can insert this opcode. We do
820           not intend to support this case. */
821        if (cc[1 + LINK_SIZE] == OP_CALLOUT)
822          return FALSE;
823        cc += 1 + LINK_SIZE;
824        break;
825    
826  static int get_class_iterator_size(pcre_uchar *cc)      case OP_CREF:
827  {      common->optimized_cbracket[GET2(cc, 1)] = 0;
828        cc += 1 + IMM2_SIZE;
829        break;
830    
831        case OP_DNREF:
832        case OP_DNREFI:
833        case OP_DNCREF:
834        count = GET2(cc, 1 + IMM2_SIZE);
835        slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
836        while (count-- > 0)
837          {
838          common->optimized_cbracket[GET2(slot, 0)] = 0;
839          slot += common->name_entry_size;
840          }
841        cc += 1 + 2 * IMM2_SIZE;
842        break;
843    
844        case OP_RECURSE:
845        /* Set its value only once. */
846        if (common->recursive_head_ptr == 0)
847          {
848          common->recursive_head_ptr = common->ovector_start;
849          common->ovector_start += sizeof(sljit_sw);
850          }
851        cc += 1 + LINK_SIZE;
852        break;
853    
854        case OP_CALLOUT:
855        if (common->capture_last_ptr == 0)
856          {
857          common->capture_last_ptr = common->ovector_start;
858          common->ovector_start += sizeof(sljit_sw);
859          }
860        cc += 2 + 2 * LINK_SIZE;
861        break;
862    
863        case OP_THEN_ARG:
864        common->has_then = TRUE;
865        common->control_head_ptr = 1;
866        /* Fall through. */
867    
868        case OP_PRUNE_ARG:
869        common->needs_start_ptr = TRUE;
870        /* Fall through. */
871    
872        case OP_MARK:
873        if (common->mark_ptr == 0)
874          {
875          common->mark_ptr = common->ovector_start;
876          common->ovector_start += sizeof(sljit_sw);
877          }
878        cc += 1 + 2 + cc[1];
879        break;
880    
881        case OP_THEN:
882        common->has_then = TRUE;
883        common->control_head_ptr = 1;
884        /* Fall through. */
885    
886        case OP_PRUNE:
887        case OP_SKIP:
888        common->needs_start_ptr = TRUE;
889        cc += 1;
890        break;
891    
892        case OP_SKIP_ARG:
893        common->control_head_ptr = 1;
894        common->has_skip_arg = TRUE;
895        cc += 1 + 2 + cc[1];
896        break;
897    
898        default:
899        cc = next_opcode(common, cc);
900        if (cc == NULL)
901          return FALSE;
902        break;
903        }
904      }
905    return TRUE;
906    }
907    
908    static int get_class_iterator_size(pcre_uchar *cc)
909    {
910  switch(*cc)  switch(*cc)
911    {    {
912    case OP_CRSTAR:    case OP_CRSTAR:
# Line 762  switch(*cc) Line 930  switch(*cc)
930    }    }
931  }  }
932    
933  static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
934  {  {
935  int private_data_length = 0;  pcre_uchar *end = bracketend(begin);
936  pcre_uchar *alternative;  pcre_uchar *next;
937  pcre_uchar *name;  pcre_uchar *next_end;
938  pcre_uchar *end = NULL;  pcre_uchar *max_end;
939  int space, size, i;  pcre_uchar type;
940  pcre_uint32 bracketlen;  sljit_sw length = end - begin;
941    int min, max, i;
942    
943  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  /* Detect fixed iterations first. */
944  while (cc < ccend)  if (end[-(1 + LINK_SIZE)] != OP_KET)
945      return FALSE;
946    
947    /* Already detected repeat. */
948    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
949      return TRUE;
950    
951    next = end;
952    min = 1;
953    while (1)
954    {    {
955    space = 0;    if (*next != *begin)
   size = 0;  
   bracketlen = 0;  
   switch(*cc)  
     {  
     case OP_SET_SOM:  
     common->has_set_som = TRUE;  
     cc += 1;  
956      break;      break;
957      next_end = bracketend(next);
958      case OP_REF:    if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
     case OP_REFI:  
     common->optimized_cbracket[GET2(cc, 1)] = 0;  
     cc += 1 + IMM2_SIZE;  
959      break;      break;
960      next = next_end;
961      min++;
962      }
963    
964      case OP_ASSERT:  if (min == 2)
965      case OP_ASSERT_NOT:    return FALSE;
     case OP_ASSERTBACK:  
     case OP_ASSERTBACK_NOT:  
     case OP_ONCE:  
     case OP_ONCE_NC:  
     case OP_BRAPOS:  
     case OP_SBRA:  
     case OP_SBRAPOS:  
     private_data_length += sizeof(sljit_sw);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
966    
967      case OP_CBRAPOS:  max = 0;
968      case OP_SCBRAPOS:  max_end = next;
969      private_data_length += sizeof(sljit_sw);  if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
970      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;    {
971      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;    type = *next;
972      break;    while (1)
973        {
974        if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
975          break;
976        next_end = bracketend(next + 2 + LINK_SIZE);
977        if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
978          break;
979        next = next_end;
980        max++;
981        }
982    
983      case OP_COND:    if (next[0] == type && next[1] == *begin && max >= 1)
984      case OP_SCOND:      {
985      bracketlen = cc[1 + LINK_SIZE];      next_end = bracketend(next + 1);
986      if (bracketlen == OP_CREF)      if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
       {  
       bracketlen = GET2(cc, 1 + LINK_SIZE + 1);  
       common->optimized_cbracket[bracketlen] = 0;  
       }  
     else if (bracketlen == OP_NCREF)  
987        {        {
988        bracketlen = GET2(cc, 1 + LINK_SIZE + 1);        for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
989        name = (pcre_uchar *)common->name_table;          if (*next_end != OP_KET)
990        alternative = name;            break;
       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);  
991    
992        for (i = 0; i < common->name_count; i++)        if (i == max)
993          {          {
994          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)          common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
995            common->optimized_cbracket[GET2(alternative, 0)] = 0;          common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
996          alternative += common->name_entry_size;          /* +2 the original and the last. */
997            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
998            if (min == 1)
999              return TRUE;
1000            min--;
1001            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
1002          }          }
1003        }        }
1004        }
1005      }
1006    
1007      if (*cc == OP_COND)  if (min >= 3)
1008        {    {
1009        /* Might be a hidden SCOND. */    common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
1010        alternative = cc + GET(cc, 1);    common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
1011        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)    common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
1012          private_data_length += sizeof(sljit_sw);    return TRUE;
1013        }    }
     else  
       private_data_length += sizeof(sljit_sw);  
     bracketlen = 1 + LINK_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;  
1014    
1015  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  return FALSE;
1016      case OP_XCLASS:  }
     size = GET(cc, 1);  
     space = get_class_iterator_size(cc + size);  
     break;  
 #endif  
1017    
1018      case OP_RECURSE:  #define CASE_ITERATOR_PRIVATE_DATA_1 \
1019      /* Set its value only once. */      case OP_MINSTAR: \
1020      if (common->recursive_head == 0)      case OP_MINPLUS: \
1021        {      case OP_QUERY: \
1022        common->recursive_head = common->ovector_start;      case OP_MINQUERY: \
1023        common->ovector_start += sizeof(sljit_sw);      case OP_MINSTARI: \
1024        }      case OP_MINPLUSI: \
1025      cc += 1 + LINK_SIZE;      case OP_QUERYI: \
1026      break;      case OP_MINQUERYI: \
1027        case OP_NOTMINSTAR: \
1028        case OP_NOTMINPLUS: \
1029        case OP_NOTQUERY: \
1030        case OP_NOTMINQUERY: \
1031        case OP_NOTMINSTARI: \
1032        case OP_NOTMINPLUSI: \
1033        case OP_NOTQUERYI: \
1034        case OP_NOTMINQUERYI:
1035    
1036      case OP_MARK:  #define CASE_ITERATOR_PRIVATE_DATA_2A \
1037      if (common->mark_ptr == 0)      case OP_STAR: \
1038        {      case OP_PLUS: \
1039        common->mark_ptr = common->ovector_start;      case OP_STARI: \
1040        common->ovector_start += sizeof(sljit_sw);      case OP_PLUSI: \
1041        }      case OP_NOTSTAR: \
1042      cc += 1 + 2 + cc[1];      case OP_NOTPLUS: \
1043      break;      case OP_NOTSTARI: \
1044        case OP_NOTPLUSI:
1045    
1046      default:  #define CASE_ITERATOR_PRIVATE_DATA_2B \
1047      cc = next_opcode(common, cc);      case OP_UPTO: \
1048      if (cc == NULL)      case OP_MINUPTO: \
1049        return -1;      case OP_UPTOI: \
1050      break;      case OP_MINUPTOI: \
1051      }      case OP_NOTUPTO: \
1052        case OP_NOTMINUPTO: \
1053        case OP_NOTUPTOI: \
1054        case OP_NOTMINUPTOI:
1055    
1056    if (space > 0 && cc >= end)  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1057      private_data_length += sizeof(sljit_sw) * space;      case OP_TYPEMINSTAR: \
1058        case OP_TYPEMINPLUS: \
1059        case OP_TYPEQUERY: \
1060        case OP_TYPEMINQUERY:
1061    
1062    if (size != 0)  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1063      {      case OP_TYPESTAR: \
1064      if (size < 0)      case OP_TYPEPLUS:
       {  
       cc += -size;  
 #ifdef SUPPORT_UTF  
       if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
       }  
     else  
       cc += size;  
     }  
1065    
1066    if (bracketlen != 0)  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1067      {      case OP_TYPEUPTO: \
1068      if (cc >= end)      case OP_TYPEMINUPTO:
       {  
       end = bracketend(cc);  
       if (end[-1 - LINK_SIZE] == OP_KET)  
         end = NULL;  
       }  
     cc += bracketlen;  
     }  
   }  
 return private_data_length;  
 }  
1069    
1070  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)  static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1071  {  {
1072  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1073  pcre_uchar *alternative;  pcre_uchar *alternative;
1074  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1075    int private_data_ptr = *private_data_start;
1076  int space, size, bracketlen;  int space, size, bracketlen;
1077    
1078  while (cc < ccend)  while (cc < ccend)
# Line 972  while (cc < ccend) Line 1080  while (cc < ccend)
1080    space = 0;    space = 0;
1081    size = 0;    size = 0;
1082    bracketlen = 0;    bracketlen = 0;
1083      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1084        return;
1085    
1086      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1087        if (detect_repeat(common, cc))
1088          {
1089          /* These brackets are converted to repeats, so no global
1090          based single character repeat is allowed. */
1091          if (cc >= end)
1092            end = bracketend(cc);
1093          }
1094    
1095    switch(*cc)    switch(*cc)
1096      {      {
1097        case OP_KET:
1098        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1099          {
1100          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1101          private_data_ptr += sizeof(sljit_sw);
1102          cc += common->private_data_ptrs[cc + 1 - common->start];
1103          }
1104        cc += 1 + LINK_SIZE;
1105        break;
1106    
1107      case OP_ASSERT:      case OP_ASSERT:
1108      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1109      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1067  while (cc < ccend) Line 1197  while (cc < ccend)
1197      break;      break;
1198      }      }
1199    
1200      /* Character iterators, which are not inside a repeated bracket,
1201         gets a private slot instead of allocating it on the stack. */
1202    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1203      {      {
1204      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
# Line 1097  while (cc < ccend) Line 1229  while (cc < ccend)
1229      cc += bracketlen;      cc += bracketlen;
1230      }      }
1231    }    }
1232    *private_data_start = private_data_ptr;
1233  }  }
1234    
1235  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1236  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)
1237  {  {
 pcre_uchar *ccend = bracketend(cc);  
1238  int length = 0;  int length = 0;
1239  BOOL possessive = FALSE;  int possessive = 0;
1240    BOOL stack_restore = FALSE;
1241  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1242  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1243    /* The last capture is a local variable even for recursions. */
1244    BOOL capture_last_found = FALSE;
1245    
1246    #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1247    SLJIT_ASSERT(common->control_head_ptr != 0);
1248    *needs_control_head = TRUE;
1249    #else
1250    *needs_control_head = FALSE;
1251    #endif
1252    
1253  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (ccend == NULL)
1254    {    {
1255    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1256    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1257        {
1258        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1259        /* This is correct regardless of common->capture_last_ptr. */
1260        capture_last_found = TRUE;
1261        }
1262      cc = next_opcode(common, cc);
1263    }    }
1264    
 cc = next_opcode(common, cc);  
1265  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1266  while (cc < ccend)  while (cc < ccend)
1267    switch(*cc)    switch(*cc)
1268      {      {
1269      case OP_SET_SOM:      case OP_SET_SOM:
1270      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1271        stack_restore = TRUE;
1272      if (!setsom_found)      if (!setsom_found)
1273        {        {
1274        length += 2;        length += 2;
# Line 1130  while (cc < ccend) Line 1278  while (cc < ccend)
1278      break;      break;
1279    
1280      case OP_MARK:      case OP_MARK:
1281        case OP_PRUNE_ARG:
1282        case OP_THEN_ARG:
1283      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1284        stack_restore = TRUE;
1285      if (!setmark_found)      if (!setmark_found)
1286        {        {
1287        length += 2;        length += 2;
1288        setmark_found = TRUE;        setmark_found = TRUE;
1289        }        }
1290        if (common->control_head_ptr != 0)
1291          *needs_control_head = TRUE;
1292      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1293      break;      break;
1294    
1295      case OP_RECURSE:      case OP_RECURSE:
1296        stack_restore = TRUE;
1297      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1298        {        {
1299        length += 2;        length += 2;
# Line 1150  while (cc < ccend) Line 1304  while (cc < ccend)
1304        length += 2;        length += 2;
1305        setmark_found = TRUE;        setmark_found = TRUE;
1306        }        }
1307        if (common->capture_last_ptr != 0 && !capture_last_found)
1308          {
1309          length += 2;
1310          capture_last_found = TRUE;
1311          }
1312      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1313      break;      break;
1314    
# Line 1157  while (cc < ccend) Line 1316  while (cc < ccend)
1316      case OP_CBRAPOS:      case OP_CBRAPOS:
1317      case OP_SCBRA:      case OP_SCBRA:
1318      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1319        stack_restore = TRUE;
1320        if (common->capture_last_ptr != 0 && !capture_last_found)
1321          {
1322          length += 2;
1323          capture_last_found = TRUE;
1324          }
1325      length += 3;      length += 3;
1326      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1327      break;      break;
1328    
1329      default:      default:
1330        stack_restore = TRUE;
1331        /* Fall through. */
1332    
1333        case OP_NOT_WORD_BOUNDARY:
1334        case OP_WORD_BOUNDARY:
1335        case OP_NOT_DIGIT:
1336        case OP_DIGIT:
1337        case OP_NOT_WHITESPACE:
1338        case OP_WHITESPACE:
1339        case OP_NOT_WORDCHAR:
1340        case OP_WORDCHAR:
1341        case OP_ANY:
1342        case OP_ALLANY:
1343        case OP_ANYBYTE:
1344        case OP_NOTPROP:
1345        case OP_PROP:
1346        case OP_ANYNL:
1347        case OP_NOT_HSPACE:
1348        case OP_HSPACE:
1349        case OP_NOT_VSPACE:
1350        case OP_VSPACE:
1351        case OP_EXTUNI:
1352        case OP_EODN:
1353        case OP_EOD:
1354        case OP_CIRC:
1355        case OP_CIRCM:
1356        case OP_DOLL:
1357        case OP_DOLLM:
1358        case OP_CHAR:
1359        case OP_CHARI:
1360        case OP_NOT:
1361        case OP_NOTI:
1362    
1363        case OP_EXACT:
1364        case OP_POSSTAR:
1365        case OP_POSPLUS:
1366        case OP_POSQUERY:
1367        case OP_POSUPTO:
1368    
1369        case OP_EXACTI:
1370        case OP_POSSTARI:
1371        case OP_POSPLUSI:
1372        case OP_POSQUERYI:
1373        case OP_POSUPTOI:
1374    
1375        case OP_NOTEXACT:
1376        case OP_NOTPOSSTAR:
1377        case OP_NOTPOSPLUS:
1378        case OP_NOTPOSQUERY:
1379        case OP_NOTPOSUPTO:
1380    
1381        case OP_NOTEXACTI:
1382        case OP_NOTPOSSTARI:
1383        case OP_NOTPOSPLUSI:
1384        case OP_NOTPOSQUERYI:
1385        case OP_NOTPOSUPTOI:
1386    
1387        case OP_TYPEEXACT:
1388        case OP_TYPEPOSSTAR:
1389        case OP_TYPEPOSPLUS:
1390        case OP_TYPEPOSQUERY:
1391        case OP_TYPEPOSUPTO:
1392    
1393        case OP_CLASS:
1394        case OP_NCLASS:
1395        case OP_XCLASS:
1396    
1397      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1398      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1399      break;      break;
1400      }      }
1401    
1402  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1403  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1404    return -1;    return stack_restore ? no_frame : no_stack;
1405    
1406  if (length > 0)  if (length > 0)
1407    return length + 1;    return length + 1;
1408  return -1;  return stack_restore ? no_frame : no_stack;
1409  }  }
1410    
1411  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)
1412  {  {
1413  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1414  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1415  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1416    /* The last capture is a local variable even for recursions. */
1417    BOOL capture_last_found = FALSE;
1418  int offset;  int offset;
1419    
1420  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1189  SLJIT_UNUSED_ARG(stacktop); Line 1422  SLJIT_UNUSED_ARG(stacktop);
1422  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1423    
1424  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1425  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1426    cc = next_opcode(common, cc);    {
1427      ccend = bracketend(cc) - (1 + LINK_SIZE);
1428      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1429        cc = next_opcode(common, cc);
1430      }
1431    
1432  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1433  while (cc < ccend)  while (cc < ccend)
1434    switch(*cc)    switch(*cc)
# Line 1200  while (cc < ccend) Line 1438  while (cc < ccend)
1438      if (!setsom_found)      if (!setsom_found)
1439        {        {
1440        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1441        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1442        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1443        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1444        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1210  while (cc < ccend) Line 1448  while (cc < ccend)
1448      break;      break;
1449    
1450      case OP_MARK:      case OP_MARK:
1451        case OP_PRUNE_ARG:
1452        case OP_THEN_ARG:
1453      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1454      if (!setmark_found)      if (!setmark_found)
1455        {        {
1456        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1457        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setmark);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1458        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1459        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1460        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1227  while (cc < ccend) Line 1467  while (cc < ccend)
1467      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1468        {        {
1469        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1470        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1471        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1472        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1473        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1236  while (cc < ccend) Line 1476  while (cc < ccend)
1476      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1477        {        {
1478        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1479        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setmark);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1480        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1481        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1482        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1483        setmark_found = TRUE;        setmark_found = TRUE;
1484        }        }
1485        if (common->capture_last_ptr != 0 && !capture_last_found)
1486          {
1487          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1488          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1489          stackpos += (int)sizeof(sljit_sw);
1490          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1491          stackpos += (int)sizeof(sljit_sw);
1492          capture_last_found = TRUE;
1493          }
1494      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1495      break;      break;
1496    
# Line 1249  while (cc < ccend) Line 1498  while (cc < ccend)
1498      case OP_CBRAPOS:      case OP_CBRAPOS:
1499      case OP_SCBRA:      case OP_SCBRA:
1500      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1501        if (common->capture_last_ptr != 0 && !capture_last_found)
1502          {
1503          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1504          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1505          stackpos += (int)sizeof(sljit_sw);
1506          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1507          stackpos += (int)sizeof(sljit_sw);
1508          capture_last_found = TRUE;
1509          }
1510      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1511      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1512      stackpos += (int)sizeof(sljit_sw);      stackpos += (int)sizeof(sljit_sw);
# Line 1268  while (cc < ccend) Line 1526  while (cc < ccend)
1526      break;      break;
1527      }      }
1528    
1529  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1530  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1531  }  }
1532    
1533  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)
1534  {  {
1535  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1536  int size;  int size;
1537  pcre_uchar *alternative;  pcre_uchar *alternative;
1538  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1283  while (cc < ccend) Line 1541  while (cc < ccend)
1541    size = 0;    size = 0;
1542    switch(*cc)    switch(*cc)
1543      {      {
1544        case OP_KET:
1545        if (PRIVATE_DATA(cc) != 0)
1546          private_data_length++;
1547        cc += 1 + LINK_SIZE;
1548        break;
1549    
1550      case OP_ASSERT:      case OP_ASSERT:
1551      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1552      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1387  return private_data_length; Line 1651  return private_data_length;
1651  }  }
1652    
1653  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,
1654    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1655  {  {
1656  DEFINE_COMPILER;  DEFINE_COMPILER;
1657  int srcw[2];  int srcw[2];
# Line 1408  stacktop = STACK(stacktop - 1); Line 1672  stacktop = STACK(stacktop - 1);
1672    
1673  if (!save)  if (!save)
1674    {    {
1675    stackptr += sizeof(sljit_sw);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1676    if (stackptr < stacktop)    if (stackptr < stacktop)
1677      {      {
1678      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
# Line 1424  if (!save) Line 1688  if (!save)
1688    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1689    }    }
1690    
1691  while (status != end)  do
1692    {    {
1693    count = 0;    count = 0;
1694    switch(status)    switch(status)
1695      {      {
1696      case start:      case start:
1697      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1698      count = 1;      count = 1;
1699      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1700        if (needs_control_head)
1701          {
1702          SLJIT_ASSERT(common->control_head_ptr != 0);
1703          count = 2;
1704          srcw[1] = common->control_head_ptr;
1705          }
1706      status = loop;      status = loop;
1707      break;      break;
1708    
# Line 1445  while (status != end) Line 1715  while (status != end)
1715    
1716      switch(*cc)      switch(*cc)
1717        {        {
1718          case OP_KET:
1719          if (PRIVATE_DATA(cc) != 0)
1720            {
1721            count = 1;
1722            srcw[0] = PRIVATE_DATA(cc);
1723            }
1724          cc += 1 + LINK_SIZE;
1725          break;
1726    
1727        case OP_ASSERT:        case OP_ASSERT:
1728        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1729        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1657  while (status != end) Line 1936  while (status != end)
1936        }        }
1937      }      }
1938    }    }
1939    while (status != end);
1940    
1941  if (save)  if (save)
1942    {    {
# Line 1690  if (save) Line 1970  if (save)
1970  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1971  }  }
1972    
1973    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1974    {
1975    pcre_uchar *end = bracketend(cc);
1976    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1977    
1978    /* Assert captures then. */
1979    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1980      current_offset = NULL;
1981    /* Conditional block does not. */
1982    if (*cc == OP_COND || *cc == OP_SCOND)
1983      has_alternatives = FALSE;
1984    
1985    cc = next_opcode(common, cc);
1986    if (has_alternatives)
1987      current_offset = common->then_offsets + (cc - common->start);
1988    
1989    while (cc < end)
1990      {
1991      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1992        cc = set_then_offsets(common, cc, current_offset);
1993      else
1994        {
1995        if (*cc == OP_ALT && has_alternatives)
1996          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1997        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1998          *current_offset = 1;
1999        cc = next_opcode(common, cc);
2000        }
2001      }
2002    
2003    return end;
2004    }
2005    
2006  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
2007  #undef CASE_ITERATOR_PRIVATE_DATA_2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
2008  #undef CASE_ITERATOR_PRIVATE_DATA_2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
# Line 1708  while (list) Line 2021  while (list)
2021    {    {
2022    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
2023    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
2024    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
2025    list = list->next;    list = list->next;
2026    }    }
2027  }  }
# Line 1724  if (list_item) Line 2037  if (list_item)
2037    }    }
2038  }  }
2039    
2040  static void add_stub(compiler_common *common, enum stub_types type, int data, struct sljit_jump *start)  static void add_stub(compiler_common *common, struct sljit_jump *start)
2041  {  {
2042  DEFINE_COMPILER;  DEFINE_COMPILER;
2043  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
2044    
2045  if (list_item)  if (list_item)
2046    {    {
   list_item->type = type;  
   list_item->data = data;  
2047    list_item->start = start;    list_item->start = start;
2048    list_item->quit = LABEL();    list_item->quit = LABEL();
2049    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1748  stub_list* list_item = common->stubs; Line 2059  stub_list* list_item = common->stubs;
2059  while (list_item)  while (list_item)
2060    {    {
2061    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2062    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
     {  
     case stack_alloc:  
     add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));  
     break;  
     }  
2063    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2064    list_item = list_item->next;    list_item = list_item->next;
2065    }    }
2066  common->stubs = NULL;  common->stubs = NULL;
2067  }  }
2068    
2069  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static void add_label_addr(compiler_common *common)
2070    {
2071    DEFINE_COMPILER;
2072    label_addr_list *label_addr;
2073    
2074    label_addr = sljit_alloc_memory(compiler, sizeof(label_addr_list));
2075    if (label_addr == NULL)
2076      return;
2077    label_addr->label = LABEL();
2078    label_addr->addr = common->read_only_data_ptr;
2079    label_addr->next = common->label_addrs;
2080    common->label_addrs = label_addr;
2081    common->read_only_data_ptr++;
2082    }
2083    
2084    static SLJIT_INLINE void count_match(compiler_common *common)
2085  {  {
2086  DEFINE_COMPILER;  DEFINE_COMPILER;
2087    
2088  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);
2089  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2090  }  }
2091    
# Line 1781  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 2102  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2102  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2103  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2104  #endif  #endif
2105  add_stub(common, stack_alloc, 0, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));  add_stub(common, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));
2106  }  }
2107    
2108  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
# Line 1795  static SLJIT_INLINE void reset_ovector(c Line 2116  static SLJIT_INLINE void reset_ovector(c
2116  DEFINE_COMPILER;  DEFINE_COMPILER;
2117  struct sljit_label *loop;  struct sljit_label *loop;
2118  int i;  int i;
2119    
2120  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2121    SLJIT_ASSERT(length > 1);
2122  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2123  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));
2124  if (length < 8)  if (length < 8)
2125    {    {
2126    for (i = 0; i < length; i++)    for (i = 1; i < length; i++)
2127      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);
2128    }    }
2129  else  else
2130    {    {
2131    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START - sizeof(sljit_sw));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2132    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2133    loop = LABEL();    loop = LABEL();
2134    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);
2135    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 1814  else Line 2137  else
2137    }    }
2138  }  }
2139    
2140    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2141    {
2142    DEFINE_COMPILER;
2143    struct sljit_label *loop;
2144    int i;
2145    
2146    SLJIT_ASSERT(length > 1);
2147    /* OVECTOR(1) contains the "string begin - 1" constant. */
2148    if (length > 2)
2149      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2150    if (length < 8)
2151      {
2152      for (i = 2; i < length; i++)
2153        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
2154      }
2155    else
2156      {
2157      GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2158      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2159      loop = LABEL();
2160      OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2161      OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
2162      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2163      }
2164    
2165    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2166    if (common->mark_ptr != 0)
2167      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2168    if (common->control_head_ptr != 0)
2169      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2170    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2171    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2172    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2173    }
2174    
2175    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2176    {
2177    while (current != NULL)
2178      {
2179      switch (current[-2])
2180        {
2181        case type_then_trap:
2182        break;
2183    
2184        case type_mark:
2185        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2186          return current[-4];
2187        break;
2188    
2189        default:
2190        SLJIT_ASSERT_STOP();
2191        break;
2192        }
2193      current = (sljit_sw*)current[-1];
2194      }
2195    return -1;
2196    }
2197    
2198  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2199  {  {
2200  DEFINE_COMPILER;  DEFINE_COMPILER;
2201  struct sljit_label *loop;  struct sljit_label *loop;
2202  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2203    
2204  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2205  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
# Line 1827  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_R Line 2208  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_R
2208  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2209  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2210    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
2211  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsetcount));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offset_count));
2212  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2213    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);
2214  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, offsets), SLJIT_IMM, sizeof(int));
2215  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));
2216  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2217  /* Unlikely, but possible */  /* Unlikely, but possible */
2218  earlyexit = CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);  early_quit = CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);
2219  loop = LABEL();  loop = LABEL();
2220  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
2221  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));
# Line 1845  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJ Line 2226  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJ
2226  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);
2227  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
2228  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2229  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2230    
2231  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2232  if (topbracket > 1)  if (topbracket > 1)
# Line 1867  else Line 2248  else
2248  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)
2249  {  {
2250  DEFINE_COMPILER;  DEFINE_COMPILER;
2251    struct sljit_jump *jump;
2252    
2253  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);
2254  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
2255      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2256    
2257  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2258  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2259  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsetcount));  OP1(SLJIT_MOV_SI, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, real_offset_count));
2260  CMPTO(SLJIT_C_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);  CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
2261    
2262  /* Store match begin and end. */  /* Store match begin and end. */
2263  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));
2264  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));
2265    
2266    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2267    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);
2268    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2269    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2270    #endif
2271    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2272    JUMPHERE(jump);
2273    
2274  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);
2275  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);
2276  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
# Line 2040  return (bit < 256) ? ((0 << 8) | bit) : Line 2432  return (bit < 256) ? ((0 << 8) | bit) :
2432    
2433  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2434  {  {
2435  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2436  DEFINE_COMPILER;  DEFINE_COMPILER;
2437  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2438    
# Line 2055  else if (common->mode == JIT_PARTIAL_SOF Line 2447  else if (common->mode == JIT_PARTIAL_SOF
2447    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2448    
2449  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2450    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2451  else  else
2452    {    {
2453    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2068  if (jump != NULL) Line 2460  if (jump != NULL)
2460    JUMPHERE(jump);    JUMPHERE(jump);
2461  }  }
2462    
2463  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2464  {  {
2465  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2466  DEFINE_COMPILER;  DEFINE_COMPILER;
2467  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2468    
2469  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2470    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2471      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2472      return;
2473      }
2474    
2475  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2476  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2477    {    {
2478    nohit = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2479    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2480    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2481    }    }
2482  else  else
2483    {    {
2484    return_value = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2485    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2486      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2487    else    else
2488      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2489    }    }
2490  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2491  }  }
2492    
2493  static void detect_partial_match(compiler_common *common, jump_list **backtracks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
# Line 2115  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR Line 2506  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2506  add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));  add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2507  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2508    {    {
2509    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2510    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2511    }    }
2512  else  else
2513    {    {
2514    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2515      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2516    else    else
2517      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2518      }
2519    JUMPHERE(jump);
2520    }
2521    
2522    static void peek_char(compiler_common *common, pcre_uint32 max)
2523    {
2524    /* Reads the character into TMP1, keeps STR_PTR.
2525    Does not check STR_END. TMP2 Destroyed. */
2526    DEFINE_COMPILER;
2527    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2528    struct sljit_jump *jump;
2529    #endif
2530    
2531    SLJIT_UNUSED_ARG(max);
2532    
2533    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2534    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2535    if (common->utf)
2536      {
2537      if (max < 128) return;
2538    
2539      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2540      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2541      add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2542      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2543      JUMPHERE(jump);
2544      }
2545    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2546    
2547    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2548    if (common->utf)
2549      {
2550      if (max < 0xd800) return;
2551    
2552      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2553      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2554      /* TMP2 contains the high surrogate. */
2555      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2556      OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2557      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2558      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2559      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2560      JUMPHERE(jump);
2561      }
2562    #endif
2563    }
2564    
2565    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2566    
2567    static BOOL is_char7_bitset(const pcre_uint8* bitset, BOOL nclass)
2568    {
2569    /* Tells whether the character codes below 128 are enough
2570    to determine a match. */
2571    const pcre_uint8 value = nclass ? 0xff : 0;
2572    const pcre_uint8* end = bitset + 32;
2573    
2574    bitset += 16;
2575    do
2576      {
2577      if (*bitset++ != value)
2578        return FALSE;
2579    }    }
2580  JUMPHERE(jump);  while (bitset < end);
2581    return TRUE;
2582  }  }
2583    
2584  static void read_char(compiler_common *common)  static void read_char7_type(compiler_common *common, BOOL full_read)
2585  {  {
2586  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the precise character type of a character into TMP1, if the character
2587  Does not check STR_END. TMP2 Destroyed. */  is less than 128. Otherwise it returns with zero. Does not check STR_END. The
2588    full_read argument tells whether characters above max are accepted or not. */
2589  DEFINE_COMPILER;  DEFINE_COMPILER;
 #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  
2590  struct sljit_jump *jump;  struct sljit_jump *jump;
 #endif  
2591    
2592  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  SLJIT_ASSERT(common->utf);
2593  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  
2594  if (common->utf)  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2595    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2596    
2597    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2598    
2599    if (full_read)
2600    {    {
2601  #if defined COMPILE_PCRE8    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2602    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2603  #elif defined COMPILE_PCRE16    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
   jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);  
 #endif /* COMPILE_PCRE[8|16] */  
   add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));  
2604    JUMPHERE(jump);    JUMPHERE(jump);
2605    }    }
 #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
2606  }  }
2607    
2608  static void peek_char(compiler_common *common)  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2609    
2610    static void read_char_range(compiler_common *common, pcre_uint32 min, pcre_uint32 max, BOOL update_str_ptr)
2611  {  {
2612  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the precise value of a character into TMP1, if the character is
2613  Does not check STR_END. TMP2 Destroyed. */  between min and max (c >= min && c <= max). Otherwise it returns with a value
2614    outside the range. Does not check STR_END. */
2615  DEFINE_COMPILER;  DEFINE_COMPILER;
2616  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2617  struct sljit_jump *jump;  struct sljit_jump *jump;
2618  #endif  #endif
2619    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2620    struct sljit_jump *jump2;
2621    #endif
2622    
2623  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  SLJIT_UNUSED_ARG(update_str_ptr);
2624  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  SLJIT_UNUSED_ARG(min);
2625    SLJIT_UNUSED_ARG(max);
2626    SLJIT_ASSERT(min <= max);
2627    
2628    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2629    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2630    
2631    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2632  if (common->utf)  if (common->utf)
2633    {    {
2634  #if defined COMPILE_PCRE8    if (max < 128 && !update_str_ptr) return;
2635    
2636    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2637  #elif defined COMPILE_PCRE16    if (min >= 0x10000)
2638    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      {
2639  #endif /* COMPILE_PCRE[8|16] */      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xf0);
2640    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));      if (update_str_ptr)
2641    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);
2642        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2643        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x7);
2644        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2645        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2646        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2647        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2648        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2649        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2650        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2651        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2652        if (!update_str_ptr)
2653          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2654        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2655        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2656        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2657        JUMPHERE(jump2);
2658        if (update_str_ptr)
2659          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2660        }
2661      else if (min >= 0x800 && max <= 0xffff)
2662        {
2663        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xe0);
2664        if (update_str_ptr)
2665          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2666        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2667        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xf);
2668        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2669        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2670        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2671        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2672        if (!update_str_ptr)
2673          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2674        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2675        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2676        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2677        JUMPHERE(jump2);
2678        if (update_str_ptr)
2679          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2680        }
2681      else if (max >= 0x800)
2682        add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2683      else if (max < 128)
2684        {
2685        OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2686        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2687        }
2688      else
2689        {
2690        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2691        if (!update_str_ptr)
2692          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2693        else
2694          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2695        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2696        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2697        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2698        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2699        if (update_str_ptr)
2700          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2701        }
2702    JUMPHERE(jump);    JUMPHERE(jump);
2703    }    }
2704  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  #endif
2705    
2706    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2707    if (common->utf)
2708      {
2709      if (max >= 0x10000)
2710        {
2711        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2712        jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2713        /* TMP2 contains the high surrogate. */
2714        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2715        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2716        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2717        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2718        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2719        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2720        JUMPHERE(jump);
2721        return;
2722        }
2723    
2724      if (max < 0xd800 && !update_str_ptr) return;
2725    
2726      /* Skip low surrogate if necessary. */
2727      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2728      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2729      if (update_str_ptr)
2730        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2731      if (max >= 0xd800)
2732        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);
2733      JUMPHERE(jump);
2734      }
2735    #endif
2736    }
2737    
2738    static SLJIT_INLINE void read_char(compiler_common *common)
2739    {
2740    read_char_range(common, 0, READ_CHAR_MAX, TRUE);
2741  }  }
2742    
2743  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common, BOOL update_str_ptr)
2744  {  {
2745  /* 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. */
2746  DEFINE_COMPILER;  DEFINE_COMPILER;
2747  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2748  struct sljit_jump *jump;  struct sljit_jump *jump;
2749  #endif  #endif
2750    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2751    struct sljit_jump *jump2;
2752    #endif
2753    
2754  #ifdef SUPPORT_UTF  SLJIT_UNUSED_ARG(update_str_ptr);
2755    
2756    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2757    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2758    
2759    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2760  if (common->utf)  if (common->utf)
2761    {    {
   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  
2762    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2763    it is needed in most cases. */    it is needed in most cases. */
2764    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2765    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2766    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    if (!update_str_ptr)
2767    JUMPHERE(jump);      {
2768  #elif defined COMPILE_PCRE16      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2769    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2770    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2771    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2772    JUMPHERE(jump);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2773    /* Skip low surrogate if necessary. */      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
2774    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2775    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);      jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2776    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2777    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);      JUMPHERE(jump2);
2778    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);      }
2779  #elif defined COMPILE_PCRE32    else
2780    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);  
2781    JUMPHERE(jump);    JUMPHERE(jump);
 #endif /* COMPILE_PCRE[8|16|32] */  
2782    return;    return;
2783    }    }
2784  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2785  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
2786  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  
2787  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2788  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2789  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2790  #endif  #endif
2791  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2792  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if !defined COMPILE_PCRE8
2793  JUMPHERE(jump);  JUMPHERE(jump);
2794  #endif  #endif
2795    
2796    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2797    if (common->utf && update_str_ptr)
2798      {
2799      /* Skip low surrogate if necessary. */
2800      OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2801      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2802      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2803      JUMPHERE(jump);
2804      }
2805    #endif /* SUPPORT_UTF && COMPILE_PCRE16 */
2806  }  }
2807    
2808  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
# Line 2266  if (common->utf) Line 2840  if (common->utf)
2840  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));
2841  }  }
2842    
2843  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)
2844  {  {
2845  /* 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. */
2846  DEFINE_COMPILER;  DEFINE_COMPILER;
2847    struct sljit_jump *jump;
2848    
2849  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2850    {    {
2851    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2852    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));
2853    }    }
2854  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2855    {    {
2856    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    if (jumpifmatch)
2857    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);      {
2858    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));
2859    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));
2860    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));      }
2861      else
2862        {
2863        jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
2864        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2865        JUMPHERE(jump);
2866        }
2867    }    }
2868  else  else
2869    {    {
2870    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2871    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));
2872    }    }
2873  }  }
2874    
# Line 2297  else Line 2878  else
2878  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2879  {  {
2880  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2881  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. */
2882  DEFINE_COMPILER;  DEFINE_COMPILER;
2883  struct sljit_jump *jump;  struct sljit_jump *jump;
2884    
2885  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2886    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2887    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2888    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2889    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2890    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2891    
2892  /* Searching for the first zero. */  /* Searching for the first zero. */
2893  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);
2894  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2895  /* Two byte sequence. */  /* Two byte sequence. */
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
2896  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));
2897  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2898    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2899    
2900    JUMPHERE(jump);
2901    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2902    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2903  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2904  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2905  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);  
2906    
2907  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);
2908  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2909  /* 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));  
2910  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));
2911  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));  
2912  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2913    
2914  /* Four byte sequence. */  /* Four byte sequence. */
2915  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  JUMPHERE(jump);
2916  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2917  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2918    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2919    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2920  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);  
2921  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2922  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(4));
2923    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2924    }
2925    
2926    static void do_utfreadchar16(compiler_common *common)
2927    {
2928    /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2929    of the character (>= 0xc0). Return value in TMP1. */
2930    DEFINE_COMPILER;
2931    struct sljit_jump *jump;
2932    
2933    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2934    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2935    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2936    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2937  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);  
2938  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2939  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));  
2940  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));  /* Searching for the first zero. */
2941    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2942    jump = JUMP(SLJIT_C_NOT_ZERO);
2943    /* Two byte sequence. */
2944    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2945    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2946    
2947    JUMPHERE(jump);
2948    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x400);
2949    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
2950    /* This code runs only in 8 bit mode. No need to shift the value. */
2951    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2952    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2953    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2954    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2955  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2956  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2957  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));  /* Three byte sequence. */
2958    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2959  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2960  }  }
2961    
# Line 2368  jump = JUMP(SLJIT_C_NOT_ZERO); Line 2975  jump = JUMP(SLJIT_C_NOT_ZERO);
2975  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2976  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));
2977  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
2978    /* The upper 5 bits are known at this point. */
2979    compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x3);
2980  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2981  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2982  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);  
2983  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2984  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2985    
2986  JUMPHERE(compare);  JUMPHERE(compare);
2987  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2988  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2989    
2990  /* 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);  
   
2991  JUMPHERE(jump);  JUMPHERE(jump);
2992  /* Combine two 16 bit characters. */  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2993  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2994  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);  
2995  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2996  }  }
2997    
2998  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE8 */
2999    
3000  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3001    
# Line 2489  if (firstline) Line 3070  if (firstline)
3070      mainloop = LABEL();      mainloop = LABEL();
3071      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
3072      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);
3073      read_char(common);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
3074      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
3075      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
3076      JUMPHERE(end);      JUMPHERE(end);
# Line 2565  if (newlinecheck) Line 3146  if (newlinecheck)
3146  return mainloop;  return mainloop;
3147  }  }
3148    
3149  #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)  
3150  {  {
3151  DEFINE_COMPILER;  /* Recursive function, which scans prefix literals. */
3152  struct sljit_label *start;  int len, repeat, len_save, consumed = 0;
3153  struct sljit_jump *quit;  pcre_uint32 caseless, chr, mask;
3154  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uchar *alternative, *cc_save;
3155  pcre_uchar *cc = common->start + 1 + IMM2_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;  
3156    
3157    repeat = 1;
3158  while (TRUE)  while (TRUE)
3159    {    {
3160      last = TRUE;
3161      any = FALSE;
3162    caseless = 0;    caseless = 0;
3163    must_stop = 1;    switch (*cc)
   switch(*cc)  
3164      {      {
     case OP_CHAR:  
     must_stop = 0;  
     cc++;  
     break;  
   
3165      case OP_CHARI:      case OP_CHARI:
3166      caseless = 1;      caseless = 1;
3167      must_stop = 0;      case OP_CHAR:
3168        last = FALSE;
3169      cc++;      cc++;
3170      break;      break;
3171    
# Line 2614  while (TRUE) Line 3184  while (TRUE)
3184      cc++;      cc++;
3185      continue;      continue;
3186    
3187      case OP_PLUS:      case OP_PLUS:
3188      case OP_MINPLUS:      case OP_MINPLUS:
3189      case OP_POSPLUS:      case OP_POSPLUS:
3190      cc++;      cc++;
3191        break;
3192    
3193        case OP_EXACTI:
3194        caseless = 1;
3195        case OP_EXACT:
3196        repeat = GET2(cc, 1);
3197        last = FALSE;
3198        cc += 1 + IMM2_SIZE;
3199        break;
3200    
3201        case OP_PLUSI:
3202        case OP_MINPLUSI:
3203        case OP_POSPLUSI:
3204        caseless = 1;
3205        cc++;
3206        break;
3207    
3208        case OP_KET:
3209        cc += 1 + LINK_SIZE;
3210        continue;
3211    
3212        case OP_ALT:
3213        cc += GET(cc, 1);
3214        continue;
3215    
3216        case OP_ONCE:
3217        case OP_ONCE_NC:
3218        case OP_BRA:
3219        case OP_BRAPOS:
3220        case OP_CBRA:
3221        case OP_CBRAPOS:
3222        alternative = cc + GET(cc, 1);
3223        while (*alternative == OP_ALT)
3224          {
3225          max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, max_chars);
3226          if (max_chars == 0)
3227            return consumed;
3228          alternative += GET(alternative, 1);
3229          }
3230    
3231        if (*cc == OP_CBRA || *cc == OP_CBRAPOS)
3232          cc += IMM2_SIZE;
3233        cc += 1 + LINK_SIZE;
3234        continue;
3235    
3236        case OP_CLASS:
3237        case OP_NCLASS:
3238        any = TRUE;
3239        cc += 1 + 32 / sizeof(pcre_uchar);
3240      break;      break;
3241    
3242      case OP_EXACT:  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3243      cc += 1 + IMM2_SIZE;      case OP_XCLASS:
3244        any = TRUE;
3245        cc += GET(cc, 1);
3246      break;      break;
3247    #endif
3248    
3249      case OP_PLUSI:      case OP_NOT_DIGIT:
3250      case OP_MINPLUSI:      case OP_DIGIT:
3251      case OP_POSPLUSI:      case OP_NOT_WHITESPACE:
3252      caseless = 1;      case OP_WHITESPACE:
3253        case OP_NOT_WORDCHAR:
3254        case OP_WORDCHAR:
3255        case OP_ANY:
3256        case OP_ALLANY:
3257        any = TRUE;
3258      cc++;      cc++;
3259      break;      break;
3260    
3261      case OP_EXACTI:  #ifdef SUPPORT_UCP
3262      caseless = 1;      case OP_NOTPROP:
3263      cc += 1 + IMM2_SIZE;      case OP_PROP:
3264        any = TRUE;
3265        cc += 1 + 2;
3266      break;      break;
3267    #endif
3268    
3269        case OP_TYPEEXACT:
3270        repeat = GET2(cc, 1);
3271        cc += 1 + IMM2_SIZE;
3272        continue;
3273    
3274      default:      default:
3275      must_stop = 2;      return consumed;
     break;  
3276      }      }
3277    
3278    if (must_stop == 2)    if (any)
3279        break;      {
3280    #ifdef SUPPORT_UTF
3281        if (common->utf) return consumed;
3282    #endif
3283    #if defined COMPILE_PCRE8
3284        mask = 0xff;
3285    #elif defined COMPILE_PCRE16
3286        mask = 0xffff;
3287    #elif defined COMPILE_PCRE32
3288        mask = 0xffffffff;
3289    #else
3290        SLJIT_ASSERT_STOP();
3291    #endif
3292    
3293        do
3294          {
3295          chars[0] = mask;
3296          chars[1] = mask;
3297    
3298          if (--max_chars == 0)
3299            return consumed;
3300          consumed++;
3301          chars += 2;
3302          }
3303        while (--repeat > 0);
3304    
3305        repeat = 1;
3306        continue;
3307        }
3308    
3309    len = 1;    len = 1;
3310  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3311    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3312  #endif  #endif
3313    
3314    if (caseless && char_has_othercase(common, cc))    if (caseless != 0 && char_has_othercase(common, cc))
3315      {      {
3316      caseless = char_get_othercase_bit(common, cc);      caseless = char_get_othercase_bit(common, cc);
3317      if (caseless == 0)      if (caseless == 0)
3318        return FALSE;        return consumed;
3319  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3320      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
3321  #else  #else
# Line 2666  while (TRUE) Line 3328  while (TRUE)
3328    else    else
3329      caseless = 0;      caseless = 0;
3330    
3331    while (len > 0 && location < MAX_N_CHARS * 2)    len_save = len;
3332      {    cc_save = cc;
3333      c = *cc;    while (TRUE)
3334      bit = 0;      {
3335      if (len == (caseless & 0xff))      do
3336        {        {
3337        bit = caseless >> 8;        chr = *cc;
3338        c |= bit;  #ifdef COMPILE_PCRE32
3339          if (SLJIT_UNLIKELY(chr == NOTACHAR))
3340            return consumed;
3341    #endif
3342          mask = 0;
3343          if ((pcre_uint32)len == (caseless & 0xff))
3344            {
3345            mask = caseless >> 8;
3346            chr |= mask;
3347            }
3348    
3349          if (chars[0] == NOTACHAR)
3350            {
3351            chars[0] = chr;
3352            chars[1] = mask;
3353            }
3354          else
3355            {
3356            mask |= chars[0] ^ chr;
3357            chr |= mask;
3358            chars[0] = chr;
3359            chars[1] |= mask;
3360            }
3361    
3362          len--;
3363          if (--max_chars == 0)
3364            return consumed;
3365          consumed++;
3366          chars += 2;
3367          cc++;
3368        }        }
3369        while (len > 0);
3370    
3371        if (--repeat == 0)
3372          break;
3373    
3374      chars[location] = c;      len = len_save;
3375      chars[location + 1] = bit;      cc = cc_save;
3376        }
3377    
3378      len--;    repeat = 1;
3379      location += 2;    if (last)
3380      cc++;      return consumed;
3381      }
3382    }
3383    
3384    #define MAX_N_CHARS 16
3385    
3386    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3387    {
3388    DEFINE_COMPILER;
3389    struct sljit_label *start;
3390    struct sljit_jump *quit;
3391    pcre_uint32 chars[MAX_N_CHARS * 2];
3392    pcre_uint8 ones[MAX_N_CHARS];
3393    pcre_uint32 mask;
3394    int i, max;
3395    int offsets[3];
3396    
3397    for (i = 0; i < MAX_N_CHARS; i++)
3398      {
3399      chars[i << 1] = NOTACHAR;
3400      chars[(i << 1) + 1] = 0;
3401      }
3402    
3403    max = scan_prefix(common, common->start, chars, MAX_N_CHARS);
3404    
3405    if (max <= 1)
3406      return FALSE;
3407    
3408    for (i = 0; i < max; i++)
3409      {
3410      mask = chars[(i << 1) + 1];
3411      ones[i] = ones_in_half_byte[mask & 0xf];
3412      mask >>= 4;
3413      while (mask != 0)
3414        {
3415        ones[i] += ones_in_half_byte[mask & 0xf];
3416        mask >>= 4;
3417      }      }
3418      }
3419    
3420    if (location >= MAX_N_CHARS * 2 || must_stop != 0)  offsets[0] = -1;
3421    /* Scan forward. */
3422    for (i = 0; i < max; i++)
3423      if (ones[i] <= 2) {
3424        offsets[0] = i;
3425      break;      break;
3426    }    }
3427    
3428  /* At least two characters are required. */  if (offsets[0] == -1)
3429  if (location < 2 * 2)    return FALSE;
3430      return FALSE;  
3431    /* Scan backward. */
3432    offsets[1] = -1;
3433    for (i = max - 1; i > offsets[0]; i--)
3434      if (ones[i] <= 2) {
3435        offsets[1] = i;
3436        break;
3437      }
3438    
3439    offsets[2] = -1;
3440    if (offsets[1] >= 0)
3441      {
3442      /* Scan from middle. */
3443      for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3444        if (ones[i] <= 2)
3445          {
3446          offsets[2] = i;
3447          break;
3448          }
3449    
3450      if (offsets[2] == -1)
3451        {
3452        for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3453          if (ones[i] <= 2)
3454            {
3455            offsets[2] = i;
3456            break;
3457            }
3458        }
3459      }
3460    
3461    SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3462    SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3463    
3464    chars[0] = chars[offsets[0] << 1];
3465    chars[1] = chars[(offsets[0] << 1) + 1];
3466    if (offsets[2] >= 0)
3467      {
3468      chars[2] = chars[offsets[2] << 1];
3469      chars[3] = chars[(offsets[2] << 1) + 1];
3470      }
3471    if (offsets[1] >= 0)
3472      {
3473      chars[4] = chars[offsets[1] << 1];
3474      chars[5] = chars[(offsets[1] << 1) + 1];
3475      }
3476    
3477    max -= 1;
3478  if (firstline)  if (firstline)
3479    {    {
3480    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3481    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3482    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, (location >> 1) - 1);    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS(max));
3483    }    }
3484  else  else
3485    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, (location >> 1) - 1);    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3486    
3487  start = LABEL();  start = LABEL();
3488  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3489    
3490  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]));
3491  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  if (offsets[1] >= 0)
3492      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3493  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));
3494    
3495  if (chars[1] != 0)  if (chars[1] != 0)
3496    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3497  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3498  if (location > 2 * 2)  if (offsets[2] >= 0)
3499    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));
3500  if (chars[3] != 0)  
3501    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)  
3502    {    {
3503    if (chars[5] != 0)    if (chars[5] != 0)
3504      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3505    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
3506      }
3507    
3508    if (offsets[2] >= 0)
3509      {
3510      if (chars[3] != 0)
3511        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3512      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3513    }    }
3514  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));
3515    
# Line 2728  JUMPHERE(quit); Line 3518  JUMPHERE(quit);
3518  if (firstline)  if (firstline)
3519    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3520  else  else
3521    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, (location >> 1) - 1);    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3522  return TRUE;  return TRUE;
3523  }  }
3524    
# Line 2848  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_ Line 3638  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_
3638  skip_char_back(common);  skip_char_back(common);
3639    
3640  loop = LABEL();  loop = LABEL();
3641  read_char(common);  read_char_range(common, common->nlmin, common->nlmax, TRUE);
3642  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3643  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3644    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
# Line 2877  if (firstline) Line 3667  if (firstline)
3667    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3668  }  }
3669    
3670  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks);
3671    
3672    static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, pcre_uint8 *start_bits, BOOL firstline)
3673  {  {
3674  DEFINE_COMPILER;  DEFINE_COMPILER;
3675  struct sljit_label *start;  struct sljit_label *start;
3676  struct sljit_jump *quit;  struct sljit_jump *quit;
3677  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3678    jump_list *matches = NULL;
3679  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3680  struct sljit_jump *jump;  struct sljit_jump *jump;
3681  #endif  #endif
# Line 2901  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 3694  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3694  if (common->utf)  if (common->utf)
3695    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3696  #endif  #endif
3697    
3698    if (!check_class_ranges(common, start_bits, (start_bits[31] & 0x80) != 0, TRUE, &matches))
3699      {
3700  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3701  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3702  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3703  JUMPHERE(jump);    JUMPHERE(jump);
3704  #endif  #endif
3705  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3706  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3707  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
3708  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3709  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);
3710  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3711      }
3712    
3713  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3714  if (common->utf)  if (common->utf)
# Line 2939  if (common->utf) Line 3736  if (common->utf)
3736  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE[8|16] */
3737  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3738  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3739  JUMPHERE(found);  if (found != NULL)
3740      JUMPHERE(found);
3741    if (matches != NULL)
3742      set_jumps(matches, LABEL());
3743  JUMPHERE(quit);  JUMPHERE(quit);
3744    
3745  if (firstline)  if (firstline)
# Line 3022  GET_LOCAL_BASE(TMP3, 0, 0); Line 3822  GET_LOCAL_BASE(TMP3, 0, 0);
3822  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3823  mainloop = LABEL();  mainloop = LABEL();
3824  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3825  jump = CMP(SLJIT_C_SIG_LESS_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0);
3826    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3827    
3828  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3829  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3830  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
# Line 3030  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_I Line 3832  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_I
3832  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3833    
3834  JUMPHERE(jump);  JUMPHERE(jump);
3835  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3836  /* End of dropping frames. */  /* End of dropping frames. */
3837  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3838    
3839  JUMPHERE(jump);  JUMPHERE(jump);
3840  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3841  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3842  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));  
 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), TMP2, 0);  
 JUMPTO(SLJIT_JUMP, mainloop);  
   
 JUMPHERE(jump);  
 if (common->mark_ptr != 0)  
   {  
   jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setmark);  
   OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));  
   OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));  
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);  
   JUMPTO(SLJIT_JUMP, mainloop);  
   
   JUMPHERE(jump);  
   }  
   
 /* Unknown command. */  
3843  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
3844  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3845  }  }
# Line 3063  static void check_wordboundary(compiler_ Line 3848  static void check_wordboundary(compiler_
3848  {  {
3849  DEFINE_COMPILER;  DEFINE_COMPILER;
3850  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3851    jump_list *skipread_list = NULL;
3852  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3853  struct sljit_jump *jump;  struct sljit_jump *jump;
3854  #endif  #endif
# Line 3120  else Line 3906  else
3906  JUMPHERE(skipread);  JUMPHERE(skipread);
3907    
3908  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3909  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3910  peek_char(common);  peek_char(common, READ_CHAR_MAX);
3911    
3912  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
3913  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 3161  else Line 3947  else
3947      JUMPHERE(jump);      JUMPHERE(jump);
3948  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3949    }    }
3950  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3951    
3952  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3953  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
3954  }  }
3955    
3956  /*  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)  
3957  {  {
3958  DEFINE_COMPILER;  DEFINE_COMPILER;
3959  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];  
3960  pcre_uint8 bit, cbit, all;  pcre_uint8 bit, cbit, all;
3961  int i, byte, length = 0;  int i, byte, length = 0;
3962    
3963  bit = bits[0] & 0x1;  bit = bits[0] & 0x1;
3964  ranges[1] = bit;  /* All bits will be zero or one (since bit is zero or one). */
 /* Can be 0 or 255. */  
3965  all = -bit;  all = -bit;
3966    
3967  for (i = 0; i < 256; )  for (i = 0; i < 256; )
# Line 3285  for (i = 0; i < 256; ) Line 3976  for (i = 0; i < 256; )
3976        {        {
3977        if (length >= MAX_RANGE_SIZE)        if (length >= MAX_RANGE_SIZE)
3978          return FALSE;          return FALSE;
3979        ranges[2 + length] = i;        ranges[length] = i;
3980        length++;        length++;
3981        bit = cbit;        bit = cbit;
3982        all = -cbit;        all = -cbit;
# Line 3298  if (((bit == 0) && nclass) || ((bit == 1 Line 3989  if (((bit == 0) && nclass) || ((bit == 1
3989    {    {
3990    if (length >= MAX_RANGE_SIZE)    if (length >= MAX_RANGE_SIZE)
3991      return FALSE;      return FALSE;
3992    ranges[2 + length] = 256;    ranges[length] = 256;
3993    length++;    length++;
3994    }    }
3995  ranges[0] = length;  
3996    if (length < 0 || length > 4)
3997  return check_ranges(common, ranges, backtracks, FALSE);    return FALSE;
3998    
3999    bit = bits[0] & 0x1;
4000    if (invert) bit ^= 0x1;
4001    
4002    /* No character is accepted. */
4003    if (length == 0 && bit == 0)
4004      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4005    
4006    switch(length)
4007      {
4008      case 0:
4009      /* When bit != 0, all characters are accepted. */
4010      return TRUE;
4011    
4012      case 1:
4013      add_jump(compiler, backtracks, CMP(bit == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
4014      return TRUE;
4015    
4016      case 2:
4017      if (ranges[0] + 1 != ranges[1])
4018        {
4019        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
4020        add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
4021        }
4022      else
4023        add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
4024      return TRUE;
4025    
4026      case 3:
4027      if (bit != 0)
4028        {
4029        add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
4030        if (ranges[0] + 1 != ranges[1])
4031          {
4032          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
4033          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
4034          }
4035        else
4036          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
4037        return TRUE;
4038        }
4039    
4040      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[0]));
4041      if (ranges[1] + 1 != ranges[2])
4042        {
4043        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1]);
4044        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1]));
4045        }
4046      else
4047        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1]));
4048      return TRUE;
4049    
4050      case 4:
4051      if ((ranges[1] - ranges[0]) == (ranges[3] - ranges[2])
4052          && (ranges[0] | (ranges[2] - ranges[0])) == ranges[2]
4053          && is_powerof2(ranges[2] - ranges[0]))
4054        {
4055        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[0]);
4056        if (ranges[2] + 1 != ranges[3])
4057          {
4058          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
4059          add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
4060          }
4061        else
4062          add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
4063        return TRUE;
4064        }
4065    
4066      if (bit != 0)
4067        {
4068        i = 0;
4069        if (ranges[0] + 1 != ranges[1])
4070          {
4071          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
4072          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
4073          i = ranges[0];
4074          }
4075        else
4076          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
4077    
4078        if (ranges[2] + 1 != ranges[3])
4079          {
4080          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - i);
4081          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
4082          }
4083        else
4084          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2] - i));
4085        return TRUE;
4086        }
4087    
4088      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
4089      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[0]));
4090      if (ranges[1] + 1 != ranges[2])
4091        {
4092        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]);
4093        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1]));
4094        }
4095      else
4096        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
4097      return TRUE;
4098    
4099      default:
4100      SLJIT_ASSERT_STOP();
4101      return FALSE;
4102      }
4103  }  }
4104    
4105  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
# Line 3481  sljit_emit_fast_return(compiler, RETURN_ Line 4277  sljit_emit_fast_return(compiler, RETURN_
4277    
4278  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
4279    
4280  static const pcre_uchar *SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1)  static const pcre_uchar * SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1)
4281  {  {
4282  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
4283  pcre_uint32 c1, c2;  pcre_uint32 c1, c2;
# Line 3577  do Line 4373  do
4373  #endif  #endif
4374    
4375    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
4376  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
4377    
4378    /* Unaligned read is supported. */    /* Unaligned read is supported. */
4379    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3594  do Line 4390  do
4390    
4391  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
4392    if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1))    if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1))
4393  #elif defined COMPILE_PCRE16  #else
4394    if (context->ucharptr >= 2 || context->length == 0)    if (context->ucharptr >= 2 || context->length == 0)
 #elif defined COMPILE_PCRE32  
   if (1 /* context->ucharptr >= 1 || context->length == 0 */)  
4395  #endif  #endif
4396      {      {
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
4397      if (context->length >= 4)      if (context->length >= 4)
4398        OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
 #if defined COMPILE_PCRE8  
4399      else if (context->length >= 2)      else if (context->length >= 2)
4400        OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
4401    #if defined COMPILE_PCRE8
4402      else if (context->length >= 1)      else if (context->length >= 1)
4403        OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
4404  #elif defined COMPILE_PCRE16  #endif /* COMPILE_PCRE8 */
     else if (context->length >= 2)  
       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif /* COMPILE_PCRE[8|16] */  
 #elif defined COMPILE_PCRE32  
     OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif /* COMPILE_PCRE[8|16|32] */  
4405      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
4406    
4407      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3625  do Line 4412  do
4412        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asint | context->oc.asint));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asint | context->oc.asint));
4413        break;        break;
4414    
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
4415        case 2 / sizeof(pcre_uchar):        case 2 / sizeof(pcre_uchar):
4416        if (context->oc.asushort != 0)        if (context->oc.asushort != 0)
4417          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asushort);          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asushort);
# Line 3640  do Line 4426  do
4426        break;        break;
4427  #endif  #endif
4428    
 #endif /* COMPILE_PCRE[8|16] */  
   
4429        default:        default:
4430        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
4431        break;        break;
# Line 3651  do Line 4435  do
4435    
4436  #else  #else
4437    
4438    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
4439    if (context->length > 0)    if (context->length >= 1)
4440      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
4441    
4442    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
# Line 3682  return cc; Line 4466  return cc;
4466  #define SET_TYPE_OFFSET(value) \  #define SET_TYPE_OFFSET(value) \
4467    if ((value) != typeoffset) \    if ((value) != typeoffset) \
4468      { \      { \
4469      if ((value) > typeoffset) \      if ((value) < typeoffset) \
       OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \  
     else \  
4470        OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \        OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \
4471        else \
4472          OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \
4473      } \      } \
4474    typeoffset = (value);    typeoffset = (value);
4475    
4476  #define SET_CHAR_OFFSET(value) \  #define SET_CHAR_OFFSET(value) \
4477    if ((value) != charoffset) \    if ((value) != charoffset) \
4478      { \      { \
4479      if ((value) > charoffset) \      if ((value) < charoffset) \
4480        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (value) - charoffset); \        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(charoffset - (value))); \
4481      else \      else \
4482        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, charoffset - (value)); \        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)((value) - charoffset)); \
4483      } \      } \
4484    charoffset = (value);    charoffset = (value);
4485    
# Line 3703  static void compile_xclass_matchingpath( Line 4487  static void compile_xclass_matchingpath(
4487  {  {
4488  DEFINE_COMPILER;  DEFINE_COMPILER;
4489  jump_list *found = NULL;  jump_list *found = NULL;
4490  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;
4491  pcre_int32 c, charoffset;  sljit_uw c, charoffset, max = 256, min = READ_CHAR_MAX;
 const pcre_uint32 *other_cases;  
4492  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4493  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4494  int compares, invertcmp, numberofcmps;  int compares, invertcmp, numberofcmps;
4495    #if defined SUPPORT_UTF && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
4496    BOOL utf = common->utf;
4497    #endif
4498    
4499  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4500  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4501  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4502  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4503  pcre_int32 typeoffset;  const pcre_uint32 *other_cases;
4504    sljit_uw typeoffset;
4505  #endif  #endif
4506    
4507  /* Although SUPPORT_UTF must be defined, we are  /* Scanning the necessary info. */
4508     not necessary in utf mode even in 8 bit mode. */  cc++;
4509  detect_partial_match(common, backtracks);  ccbegin = cc;
4510  read_char(common);  compares = 0;
4511    if (cc[-1] & XCL_MAP)
 if ((*cc++ & XCL_MAP) != 0)  
4512    {    {
4513    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  
4514    cc += 32 / sizeof(pcre_uchar);    cc += 32 / sizeof(pcre_uchar);
4515    }    }
4516    
 /* Scanning the necessary info. */  
 ccbegin = cc;  
 compares = 0;  
4517  while (*cc != XCL_END)  while (*cc != XCL_END)
4518    {    {
4519    compares++;    compares++;
4520    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
4521      {      {
4522      cc += 2;      cc ++;
4523  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4524      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (c > max) max = c;
4525  #endif      if (c < min) min = c;
4526  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4527      needschar = TRUE;      needschar = TRUE;
4528  #endif  #endif
4529      }      }
4530    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
4531      {      {
4532      cc += 2;      cc ++;
4533  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4534      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (c < min) min = c;
4535  #endif      GETCHARINCTEST(c, cc);
4536      cc++;      if (c > max) max = c;
 #ifdef SUPPORT_UTF  
     if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
4537  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4538      needschar = TRUE;      needschar = TRUE;
4539  #endif  #endif
# Line 3789  while (*cc != XCL_END) Line 4543  while (*cc != XCL_END)
4543      {      {
4544      SLJIT_ASSERT(*cc == XCL_PROP || *cc == XCL_NOTPROP);      SLJIT_ASSERT(*cc == XCL_PROP || *cc == XCL_NOTPROP);
4545      cc++;      cc++;
4546        if (*cc == PT_CLIST)
4547          {
4548          other_cases = PRIV(ucd_caseless_sets) + cc[1];
4549          while (*other_cases != NOTACHAR)
4550            {
4551            if (*other_cases > max) max = *other_cases;
4552            if (*other_cases < min) min = *other_cases;
4553            other_cases++;
4554            }
4555          }
4556        else
4557          {
4558          max = READ_CHAR_MAX;
4559          min = 0;
4560          }
4561    
4562      switch(*cc)      switch(*cc)
4563        {        {
4564        case PT_ANY:        case PT_ANY:
# Line 3808  while (*cc != XCL_END) Line 4578  while (*cc != XCL_END)
4578        case PT_SPACE:        case PT_SPACE:
4579        case PT_PXSPACE:        case PT_PXSPACE:
4580        case PT_WORD:        case PT_WORD:
4581          case PT_PXGRAPH:
4582          case PT_PXPRINT:
4583          case PT_PXPUNCT:
4584        needstype = TRUE;        needstype = TRUE;
4585        needschar = TRUE;        needschar = TRUE;
4586        break;        break;
4587    
4588        case PT_CLIST:        case PT_CLIST:
4589          case PT_UCNC:
4590        needschar = TRUE;        needschar = TRUE;
4591        break;        break;
4592    
# Line 3825  while (*cc != XCL_END) Line 4599  while (*cc != XCL_END)
4599  #endif  #endif
4600    }    }
4601    
4602    /* We are not necessary in utf mode even in 8 bit mode. */
4603    cc = ccbegin;
4604    detect_partial_match(common, backtracks);
4605    read_char_range(common, min, max, (cc[-1] & XCL_NOT) != 0);
4606    
4607    if ((cc[-1] & XCL_HASPROP) == 0)
4608      {
4609      if ((cc[-1] & XCL_MAP) != 0)
4610        {
4611        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4612        if (!check_class_ranges(common, (const pcre_uint8 *)cc, (((const pcre_uint8 *)cc)[31] & 0x80) != 0, TRUE, &found))
4613          {
4614          OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4615          OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4616          OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4617          OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4618          OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4619          add_jump(compiler, &found, JUMP(SLJIT_C_NOT_ZERO));
4620          }
4621    
4622        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4623        JUMPHERE(jump);
4624    
4625        cc += 32 / sizeof(pcre_uchar);
4626        }
4627      else
4628        {
4629        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, min);
4630        add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, max - min));
4631        }
4632      }
4633    else if ((cc[-1] & XCL_MAP) != 0)
4634      {
4635      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4636    #ifdef SUPPORT_UCP
4637      charsaved = TRUE;
4638    #endif
4639      if (!check_class_ranges(common, (const pcre_uint8 *)cc, FALSE, TRUE, list))
4640        {
4641    #ifdef COMPILE_PCRE8
4642        SLJIT_ASSERT(common->utf);
4643    #endif
4644        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4645    
4646        OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4647        OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4648        OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4649        OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4650        OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4651        add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
4652    
4653        JUMPHERE(jump);
4654        }
4655    
4656      OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
4657      cc += 32 / sizeof(pcre_uchar);
4658      }
4659    
4660  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4661  /* Simple register allocation. TMP1 is preferred if possible. */  /* Simple register allocation. TMP1 is preferred if possible. */
4662  if (needstype || needsscript)  if (needstype || needsscript)
# Line 3866  if (needstype || needsscript) Line 4698  if (needstype || needsscript)
4698  #endif  #endif
4699    
4700  /* Generating code. */  /* Generating code. */
 cc = ccbegin;  
4701  charoffset = 0;  charoffset = 0;
4702  numberofcmps = 0;  numberofcmps = 0;
4703  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 3882  while (*cc != XCL_END) Line 4713  while (*cc != XCL_END)
4713    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
4714      {      {
4715      cc ++;      cc ++;
4716  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
     if (common->utf)  
       {  
       GETCHARINC(c, cc);  
       }  
     else  
 #endif  
       c = *cc++;  
4717    
4718      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4719        {        {
4720        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));
4721        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);
4722        numberofcmps++;        numberofcmps++;
4723        }        }
4724      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4725        {        {
4726        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));
4727        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);
4728        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4729        numberofcmps = 0;        numberofcmps = 0;
4730        }        }
4731      else      else
4732        {        {
4733        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));
4734        numberofcmps = 0;        numberofcmps = 0;
4735        }        }
4736      }      }
4737    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
4738      {      {
4739      cc ++;      cc ++;
4740  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
     if (common->utf)  
       {  
       GETCHARINC(c, cc);  
       }  
     else  
 #endif  
       c = *cc++;  
4741      SET_CHAR_OFFSET(c);      SET_CHAR_OFFSET(c);
4742  #ifdef SUPPORT_UTF      GETCHARINCTEST(c, cc);
4743      if (common->utf)  
       {  
       GETCHARINC(c, cc);  
       }  
     else  
 #endif  
       c = *cc++;  
4744      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4745        {        {
4746        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));
4747        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);
4748        numberofcmps++;        numberofcmps++;
4749        }        }
4750      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4751        {        {
4752        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));
4753        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);
4754        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4755        numberofcmps = 0;        numberofcmps = 0;
4756        }        }
4757      else      else
4758        {        {
4759        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));
4760        numberofcmps = 0;        numberofcmps = 0;
4761        }        }
4762      }      }
# Line 3994  while (*cc != XCL_END) Line 4805  while (*cc != XCL_END)
4805    
4806        case PT_SPACE:        case PT_SPACE:
4807        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);  
         }  
4808        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4809        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);
4810        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);
4811        if (*cc == PT_SPACE)  
4812          JUMPHERE(jump);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x9);
4813          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4814    
4815          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x9);
4816          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4817    
4818        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4819        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 4012  while (*cc != XCL_END) Line 4822  while (*cc != XCL_END)
4822        break;        break;
4823    
4824        case PT_WORD:        case PT_WORD:
4825        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));
4826        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4827        /* ... fall through */        /* Fall through. */
4828    
4829        case PT_ALNUM:        case PT_ALNUM:
4830        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
# Line 4060  while (*cc != XCL_END) Line 4870  while (*cc != XCL_END)
4870          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]);
4871          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4872    
4873          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));
4874          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);
4875    
4876          other_cases += 3;          other_cases += 3;
4877          }          }
4878        else        else
4879          {          {
4880          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));
4881          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4882          }          }
4883    
4884        while (*other_cases != NOTACHAR)        while (*other_cases != NOTACHAR)
4885          {          {
4886          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));
4887          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);
4888          }          }
4889        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4890        break;        break;
4891    
4892          case PT_UCNC:
4893          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(CHAR_DOLLAR_SIGN - charoffset));
4894          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4895          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(CHAR_COMMERCIAL_AT - charoffset));
4896          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4897          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(CHAR_GRAVE_ACCENT - charoffset));
4898          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4899    
4900          SET_CHAR_OFFSET(0xa0);
4901          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(0xd7ff - charoffset));
4902          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4903          SET_CHAR_OFFSET(0);
4904          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
4905          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4906          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4907          break;
4908    
4909          case PT_PXGRAPH:
4910          /* C and Z groups are the farthest two groups. */
4911          SET_TYPE_OFFSET(ucp_Ll);
4912          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4913          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4914    
4915          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4916    
4917          /* In case of ucp_Cf, we overwrite the result. */
4918          SET_CHAR_OFFSET(0x2066);
4919          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4920          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4921    
4922          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4923          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4924    
4925          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x2066);
4926          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4927    
4928          JUMPHERE(jump);
4929          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4930          break;
4931    
4932          case PT_PXPRINT:
4933          /* C and Z groups are the farthest two groups. */
4934          SET_TYPE_OFFSET(ucp_Ll);
4935          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4936          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4937    
4938          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Ll);
4939          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_NOT_EQUAL);
4940    
4941          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4942    
4943          /* In case of ucp_Cf, we overwrite the result. */
4944          SET_CHAR_OFFSET(0x2066);
4945          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4946          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4947    
4948          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4949          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4950    
4951          JUMPHERE(jump);
4952          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4953          break;
4954    
4955          case PT_PXPUNCT:
4956          SET_TYPE_OFFSET(ucp_Sc);
4957          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Sc);
4958          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4959    
4960          SET_CHAR_OFFSET(0);
4961          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xff);
4962          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4963    
4964          SET_TYPE_OFFSET(ucp_Pc);
4965          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ps - ucp_Pc);
4966          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4967          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4968          break;
4969        }        }
4970      cc += 2;      cc += 2;
4971      }      }
# Line 4103  int length; Line 4991  int length;
4991  unsigned int c, oc, bit;  unsigned int c, oc, bit;
4992  compare_context context;  compare_context context;
4993  struct sljit_jump *jump[4];  struct sljit_jump *jump[4];
4994    jump_list *end_list;
4995  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4996  struct sljit_label *label;  struct sljit_label *label;
4997  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4998  pcre_uchar propdata[5];  pcre_uchar propdata[5];
4999  #endif  #endif
5000  #endif  #endif /* SUPPORT_UTF */
5001    
5002  switch(type)  switch(type)
5003    {    {
# Line 4133  switch(type) Line 5022  switch(type)
5022    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
5023    case OP_DIGIT:    case OP_DIGIT:
5024    /* 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);  
5025    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5026    /* Flip the starting bit in the negative case. */  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5027    if (type == OP_NOT_DIGIT)    if (common->utf && is_char7_bitset((const pcre_uint8*)common->ctypes - cbit_length + cbit_digit, FALSE))
5028      common->digits[1] ^= 1;      read_char7_type(common, type == OP_NOT_DIGIT);
5029    if (!check_ranges(common, common->digits, backtracks, TRUE))    else
5030      {  #endif
5031      read_char8_type(common);      read_char8_type(common, type == OP_NOT_DIGIT);
5032      OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);      /* Flip the starting bit in the negative case. */
5033      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);
5034      }    add_jump(compiler, backtracks, JUMP(type == OP_DIGIT ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
   if (type == OP_NOT_DIGIT)  
     common->digits[1] ^= 1;  
5035    return cc;    return cc;
5036    
5037    case OP_NOT_WHITESPACE:    case OP_NOT_WHITESPACE:
5038    case OP_WHITESPACE:    case OP_WHITESPACE:
5039    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5040    read_char8_type(common);  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5041      if (common->utf && is_char7_bitset((const pcre_uint8*)common->ctypes - cbit_length + cbit_space, FALSE))
5042        read_char7_type(common, type == OP_NOT_WHITESPACE);
5043      else
5044    #endif
5045        read_char8_type(common, type == OP_NOT_WHITESPACE);
5046    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);
5047    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));
5048    return cc;    return cc;
# Line 4160  switch(type) Line 5050  switch(type)
5050    case OP_NOT_WORDCHAR:    case OP_NOT_WORDCHAR:
5051    case OP_WORDCHAR:    case OP_WORDCHAR:
5052    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5053    read_char8_type(common);  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
5054      if (common->utf && is_char7_bitset((const pcre_uint8*)common->ctypes - cbit_length + cbit_word, FALSE))
5055        read_char7_type(common, type == OP_NOT_WORDCHAR);
5056      else
5057    #endif
5058        read_char8_type(common, type == OP_NOT_WORDCHAR);
5059    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);
5060    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));
5061    return cc;    return cc;
5062    
5063    case OP_ANY:    case OP_ANY:
5064    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5065    read_char(common);    read_char_range(common, common->nlmin, common->nlmax, TRUE);
5066    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
5067      {      {
5068      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);
5069        end_list = NULL;
5070      if (common->mode != JIT_PARTIAL_HARD_COMPILE)      if (common->mode != JIT_PARTIAL_HARD_COMPILE)
5071        jump[1] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);        add_jump(compiler, &end_list, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
5072      else      else
5073        jump[1] = check_str_end(common);        check_str_end(common, &end_list);
5074    
5075      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
5076      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff));      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff));
5077      if (jump[1] != NULL)      set_jumps(end_list, LABEL());
       JUMPHERE(jump[1]);  
5078      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
5079      }      }
5080    else    else
# Line 4223  switch(type) Line 5118  switch(type)
5118  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
5119    case OP_NOTPROP:    case OP_NOTPROP:
5120    case OP_PROP:    case OP_PROP:
5121    propdata[0] = 0;    propdata[0] = XCL_HASPROP;
5122    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;
5123    propdata[2] = cc[0];    propdata[2] = cc[0];
5124    propdata[3] = cc[1];    propdata[3] = cc[1];
# Line 4235  switch(type) Line 5130  switch(type)
5130    
5131    case OP_ANYNL:    case OP_ANYNL:
5132    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5133    read_char(common);    read_char_range(common, common->bsr_nlmin, common->bsr_nlmax, FALSE);
5134    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);
5135    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
5136      end_list = NULL;
5137    if (common->mode != JIT_PARTIAL_HARD_COMPILE)    if (common->mode != JIT_PARTIAL_HARD_COMPILE)
5138      jump[1] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      add_jump(compiler, &end_list, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
5139    else    else
5140      jump[1] = check_str_end(common);      check_str_end(common, &end_list);
5141    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
5142    jump[2] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL);    jump[1] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL);
5143    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));
5144    jump[3] = JUMP(SLJIT_JUMP);    jump[2] = JUMP(SLJIT_JUMP);
5145    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
5146    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);
5147      set_jumps(end_list, LABEL());
5148    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
5149    JUMPHERE(jump[2]);    JUMPHERE(jump[2]);
   JUMPHERE(jump[3]);  
5150    return cc;    return cc;
5151    
5152    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
5153    case OP_HSPACE:    case OP_HSPACE:
5154    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5155    read_char(common);    read_char_range(common, 0x9, 0x3000, type == OP_NOT_HSPACE);
5156    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));
5157    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));
5158    return cc;    return cc;
# Line 4264  switch(type) Line 5160  switch(type)
5160    case OP_NOT_VSPACE:    case OP_NOT_VSPACE:
5161    case OP_VSPACE:    case OP_VSPACE:
5162    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5163    read_char(common);    read_char_range(common, 0xa, 0x2029, type == OP_NOT_VSPACE);
5164    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));
5165    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));
5166    return cc;    return cc;
# Line 4363  switch(type) Line 5259  switch(type)
5259      else      else
5260        {        {
5261        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);
5262        read_char(common);        read_char_range(common, common->nlmin, common->nlmax, TRUE);
5263        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));
5264        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
5265        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 4411  switch(type) Line 5307  switch(type)
5307    else    else
5308      {      {
5309      skip_char_back(common);      skip_char_back(common);
5310      read_char(common);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
5311      check_newlinechar(common, common->nltype, backtracks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
5312      }      }
5313    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
# Line 4462  switch(type) Line 5358  switch(type)