/[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 1420 by zherczeg, Sun Dec 29 11:43:10 2013 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 171  typedef struct executable_functions { Line 182  typedef struct executable_functions {
182    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184    pcre_uint32 top_bracket;    pcre_uint32 top_bracket;
185      pcre_uint32 limit_match;
186    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
187  } executable_functions;  } executable_functions;
188    
# Line 179  typedef struct jump_list { Line 191  typedef struct jump_list {
191    struct jump_list *next;    struct jump_list *next;
192  } jump_list;  } jump_list;
193    
 enum stub_types { stack_alloc };  
   
194  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
195    struct sljit_jump *start;    struct sljit_jump *start;
196    struct sljit_label *quit;    struct sljit_label *quit;
197    struct stub_list *next;    struct stub_list *next;
198  } stub_list;  } stub_list;
199    
200    enum frame_types {
201      no_frame = -1,
202      no_stack = -2
203    };
204    
205    enum control_types {
206      type_mark = 0,
207      type_then_trap = 1
208    };
209    
210  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
213  code generator. It is allocated by compile_matchingpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
214  the aguments for compile_backtrackingpath. Must be the first member  the arguments for compile_backtrackingpath. Must be the first member
215  of its descendants. */  of its descendants. */
216  typedef struct backtrack_common {  typedef struct backtrack_common {
217    /* Concatenation stack. */    /* Concatenation stack. */
# Line 209  typedef struct backtrack_common { Line 227  typedef struct backtrack_common {
227  typedef struct assert_backtrack {  typedef struct assert_backtrack {
228    backtrack_common common;    backtrack_common common;
229    jump_list *condfailed;    jump_list *condfailed;
230    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
231    int framesize;    int framesize;
232    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
233    int private_data_ptr;    int private_data_ptr;
# Line 230  typedef struct bracket_backtrack { Line 248  typedef struct bracket_backtrack {
248      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
249      jump_list *condfailed;      jump_list *condfailed;
250      assert_backtrack *assert;      assert_backtrack *assert;
251      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
252      int framesize;      int framesize;
253    } u;    } u;
254    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
# Line 265  typedef struct recurse_entry { Line 283  typedef struct recurse_entry {
283    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
284    jump_list *calls;    jump_list *calls;
285    /* Points to the starting opcode. */    /* Points to the starting opcode. */
286    int start;    sljit_sw start;
287  } recurse_entry;  } recurse_entry;
288    
289  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
290    backtrack_common common;    backtrack_common common;
291      BOOL inlined_pattern;
292  } recurse_backtrack;  } recurse_backtrack;
293    
294  #define MAX_RANGE_SIZE 6  #define OP_THEN_TRAP OP_TABLE_LENGTH
295    
296    typedef struct then_trap_backtrack {
297      backtrack_common common;
298      /* If then_trap is not NULL, this structure contains the real
299      then_trap for the backtracking path. */
300      struct then_trap_backtrack *then_trap;
301      /* Points to the starting opcode. */
302      sljit_sw start;
303      /* Exit point for the then opcodes of this alternative. */
304      jump_list *quit;
305      /* Frame size of the current alternative. */
306      int framesize;
307    } then_trap_backtrack;
308    
309    #define MAX_RANGE_SIZE 4
310    
311  typedef struct compiler_common {  typedef struct compiler_common {
312      /* The sljit ceneric compiler. */
313    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
314      /* First byte code. */
315    pcre_uchar *start;    pcre_uchar *start;
   
316    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
317    int *private_data_ptrs;    sljit_si *private_data_ptrs;
318    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
319    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
320      /* Tells whether the starting offset is a target of then. */
321      pcre_uint8 *then_offsets;
322      /* Current position where a THEN must jump. */
323      then_trap_backtrack *then_trap;
324    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
325    int cbraptr;    int cbra_ptr;
326    /* OVector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
327    int ovector_start;    int ovector_start;
328    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
329    int req_char_ptr;    int req_char_ptr;
330    /* Head of the last recursion. */    /* Head of the last recursion. */
331    int recursive_head;    int recursive_head_ptr;
332    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
333    int start_used_ptr;    int start_used_ptr;
334    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 298  typedef struct compiler_common { Line 337  typedef struct compiler_common {
337    int first_line_end;    int first_line_end;
338    /* Points to the marked string. */    /* Points to the marked string. */
339    int mark_ptr;    int mark_ptr;
340      /* Recursive control verb management chain. */
341      int control_head_ptr;
342      /* Points to the last matched capture block index. */
343      int capture_last_ptr;
344      /* Points to the starting position of the current match. */
345      int start_ptr;
346    
347    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
348    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
349    sljit_sw lcc;    sljit_sw lcc;
350    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
351    int mode;    int mode;
352      /* \K is found in the pattern. */
353      BOOL has_set_som;
354      /* (*SKIP:arg) is found in the pattern. */
355      BOOL has_skip_arg;
356      /* (*THEN) is found in the pattern. */
357      BOOL has_then;
358      /* Needs to know the start position anytime. */
359      BOOL needs_start_ptr;
360      /* Currently in recurse or negative assert. */
361      BOOL local_exit;
362      /* Currently in a positive assert. */
363      BOOL positive_assert;
364    /* Newline control. */    /* Newline control. */
365    int nltype;    int nltype;
366    int newline;    int newline;
367    int bsr_nltype;    int bsr_nltype;
368    /* Dollar endonly. */    /* Dollar endonly. */
369    int endonly;    int endonly;
   BOOL has_set_som;  
370    /* Tables. */    /* Tables. */
371    sljit_sw ctypes;    sljit_sw ctypes;
   int digits[2 + MAX_RANGE_SIZE];  
372    /* Named capturing brackets. */    /* Named capturing brackets. */
373    sljit_uw name_table;    pcre_uchar *name_table;
374    sljit_sw name_count;    sljit_sw name_count;
375    sljit_sw name_entry_size;    sljit_sw name_entry_size;
376    
377    /* Labels and jump lists. */    /* Labels and jump lists. */
378    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
379    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
380    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
381      struct sljit_label *accept_label;
382    stub_list *stubs;    stub_list *stubs;
383    recurse_entry *entries;    recurse_entry *entries;
384    recurse_entry *currententry;    recurse_entry *currententry;
385    jump_list *partialmatch;    jump_list *partialmatch;
386    jump_list *quit;    jump_list *quit;
387      jump_list *positive_assert_quit;
388      jump_list *forced_quit;
389    jump_list *accept;    jump_list *accept;
390    jump_list *calllimit;    jump_list *calllimit;
391    jump_list *stackalloc;    jump_list *stackalloc;
# Line 338  typedef struct compiler_common { Line 396  typedef struct compiler_common {
396    jump_list *vspace;    jump_list *vspace;
397    jump_list *casefulcmp;    jump_list *casefulcmp;
398    jump_list *caselesscmp;    jump_list *caselesscmp;
399      jump_list *reset_match;
400    BOOL jscript_compat;    BOOL jscript_compat;
401  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
402    BOOL utf;    BOOL utf;
# Line 348  typedef struct compiler_common { Line 407  typedef struct compiler_common {
407    jump_list *utfreadchar;    jump_list *utfreadchar;
408  #endif  #endif
409  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
410      jump_list *utfreadchar8;
411    jump_list *utfreadtype8;    jump_list *utfreadtype8;
412  #endif  #endif
413  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
# Line 390  typedef struct compare_context { Line 450  typedef struct compare_context {
450  #endif  #endif
451  } compare_context;  } compare_context;
452    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
453  /* Undefine sljit macros. */  /* Undefine sljit macros. */
454  #undef CMP  #undef CMP
455    
# Line 410  enum { Line 464  enum {
464  #define STACK_TOP     SLJIT_SCRATCH_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
465  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
466  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
467  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define COUNT_MATCH   SLJIT_SAVED_EREG2
468  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
469    
470  /* Local space layout. */  /* Local space layout. */
# Line 421  enum { Line 475  enum {
475  #define POSSESSIVE0      (2 * sizeof(sljit_sw))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
476  #define POSSESSIVE1      (3 * sizeof(sljit_sw))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
477  /* Max limit of recursions. */  /* Max limit of recursions. */
478  #define CALL_LIMIT       (4 * sizeof(sljit_sw))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
479  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
480  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
481  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
482  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. */
483  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
484  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))  #define OVECTOR(i)       (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw))
485  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_sw))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
486  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
487    
488  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
# Line 459  the start pointers when the end of the c Line 513  the start pointers when the end of the c
513    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
514  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
515    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
516    #define SET_LABEL(jump, label) \
517      sljit_set_label((jump), (label))
518  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
519    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
520  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
# Line 477  cc += 1 + LINK_SIZE; Line 533  cc += 1 + LINK_SIZE;
533  return cc;  return cc;
534  }  }
535    
536    static int ones_in_half_byte[16] = {
537      /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
538      /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
539    };
540    
541  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
542   next_opcode   next_opcode
543   get_private_data_length   check_opcode_types
544   set_private_data_ptrs   set_private_data_ptrs
545   get_framesize   get_framesize
546   init_frame   init_frame
547   get_private_data_length_for_copy   get_private_data_copy_length
548   copy_private_data   copy_private_data
549   compile_matchingpath   compile_matchingpath
550   compile_backtrackingpath   compile_backtrackingpath
# Line 507  switch(*cc) Line 568  switch(*cc)
568    case OP_WORDCHAR:    case OP_WORDCHAR:
569    case OP_ANY:    case OP_ANY:
570    case OP_ALLANY:    case OP_ALLANY:
571      case OP_NOTPROP:
572      case OP_PROP:
573    case OP_ANYNL:    case OP_ANYNL:
574    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
575    case OP_HSPACE:    case OP_HSPACE:
# Line 519  switch(*cc) Line 582  switch(*cc)
582    case OP_CIRCM:    case OP_CIRCM:
583    case OP_DOLL:    case OP_DOLL:
584    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:  
585    case OP_CRSTAR:    case OP_CRSTAR:
586    case OP_CRMINSTAR:    case OP_CRMINSTAR:
587    case OP_CRPLUS:    case OP_CRPLUS:
588    case OP_CRMINPLUS:    case OP_CRMINPLUS:
589    case OP_CRQUERY:    case OP_CRQUERY:
590    case OP_CRMINQUERY:    case OP_CRMINQUERY:
591      case OP_CRRANGE:
592      case OP_CRMINRANGE:
593      case OP_CRPOSSTAR:
594      case OP_CRPOSPLUS:
595      case OP_CRPOSQUERY:
596      case OP_CRPOSRANGE:
597      case OP_CLASS:
598      case OP_NCLASS:
599      case OP_REF:
600      case OP_REFI:
601      case OP_DNREF:
602      case OP_DNREFI:
603      case OP_RECURSE:
604      case OP_CALLOUT:
605      case OP_ALT:
606      case OP_KET:
607      case OP_KETRMAX:
608      case OP_KETRMIN:
609      case OP_KETRPOS:
610      case OP_REVERSE:
611      case OP_ASSERT:
612      case OP_ASSERT_NOT:
613      case OP_ASSERTBACK:
614      case OP_ASSERTBACK_NOT:
615      case OP_ONCE:
616      case OP_ONCE_NC:
617      case OP_BRA:
618      case OP_BRAPOS:
619      case OP_CBRA:
620      case OP_CBRAPOS:
621      case OP_COND:
622      case OP_SBRA:
623      case OP_SBRAPOS:
624      case OP_SCBRA:
625      case OP_SCBRAPOS:
626      case OP_SCOND:
627      case OP_CREF:
628      case OP_DNCREF:
629      case OP_RREF:
630      case OP_DNRREF:
631    case OP_DEF:    case OP_DEF:
632    case OP_BRAZERO:    case OP_BRAZERO:
633    case OP_BRAMINZERO:    case OP_BRAMINZERO:
634    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
635      case OP_PRUNE:
636      case OP_SKIP:
637      case OP_THEN:
638    case OP_COMMIT:    case OP_COMMIT:
639    case OP_FAIL:    case OP_FAIL:
640    case OP_ACCEPT:    case OP_ACCEPT:
641    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
642      case OP_CLOSE:
643    case OP_SKIPZERO:    case OP_SKIPZERO:
644    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
645    
646    case OP_CHAR:    case OP_CHAR:
647    case OP_CHARI:    case OP_CHARI:
# Line 561  switch(*cc) Line 653  switch(*cc)
653    case OP_MINPLUS:    case OP_MINPLUS:
654    case OP_QUERY:    case OP_QUERY:
655    case OP_MINQUERY:    case OP_MINQUERY:
656      case OP_UPTO:
657      case OP_MINUPTO:
658      case OP_EXACT:
659    case OP_POSSTAR:    case OP_POSSTAR:
660    case OP_POSPLUS:    case OP_POSPLUS:
661    case OP_POSQUERY:    case OP_POSQUERY:
662      case OP_POSUPTO:
663    case OP_STARI:    case OP_STARI:
664    case OP_MINSTARI:    case OP_MINSTARI:
665    case OP_PLUSI:    case OP_PLUSI:
666    case OP_MINPLUSI:    case OP_MINPLUSI:
667    case OP_QUERYI:    case OP_QUERYI:
668    case OP_MINQUERYI:    case OP_MINQUERYI:
669      case OP_UPTOI:
670      case OP_MINUPTOI:
671      case OP_EXACTI:
672    case OP_POSSTARI:    case OP_POSSTARI:
673    case OP_POSPLUSI:    case OP_POSPLUSI:
674    case OP_POSQUERYI:    case OP_POSQUERYI:
675      case OP_POSUPTOI:
676    case OP_NOTSTAR:    case OP_NOTSTAR:
677    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
678    case OP_NOTPLUS:    case OP_NOTPLUS:
679    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
680    case OP_NOTQUERY:    case OP_NOTQUERY:
681    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
682      case OP_NOTUPTO:
683      case OP_NOTMINUPTO:
684      case OP_NOTEXACT:
685    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
686    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
687    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
688      case OP_NOTPOSUPTO:
689    case OP_NOTSTARI:    case OP_NOTSTARI:
690    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
691    case OP_NOTPLUSI:    case OP_NOTPLUSI:
692    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
693    case OP_NOTQUERYI:    case OP_NOTQUERYI:
694    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:  
695    case OP_NOTUPTOI:    case OP_NOTUPTOI:
696    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
697    case OP_NOTEXACTI:    case OP_NOTEXACTI:
698      case OP_NOTPOSSTARI:
699      case OP_NOTPOSPLUSI:
700      case OP_NOTPOSQUERYI:
701    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
702    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
703  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
704    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
705  #endif  #endif
706    return cc;    return cc;
707    
708    case OP_NOTPROP:    /* Special cases. */
709    case OP_PROP:    case OP_TYPESTAR:
710    return cc + 1 + 2;    case OP_TYPEMINSTAR:
711      case OP_TYPEPLUS:
712      case OP_TYPEMINPLUS:
713      case OP_TYPEQUERY:
714      case OP_TYPEMINQUERY:
715    case OP_TYPEUPTO:    case OP_TYPEUPTO:
716    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
717    case OP_TYPEEXACT:    case OP_TYPEEXACT:
718      case OP_TYPEPOSSTAR:
719      case OP_TYPEPOSPLUS:
720      case OP_TYPEPOSQUERY:
721    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
722    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;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   return cc + 1 + 2 * IMM2_SIZE;  
723    
724    case OP_CLASS:    case OP_ANYBYTE:
725    case OP_NCLASS:  #ifdef SUPPORT_UTF
726    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
727    #endif
728      return cc + 1;
729    
730  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
731    case OP_XCLASS:    case OP_XCLASS:
732    return cc + GET(cc, 1);    return cc + GET(cc, 1);
733  #endif  #endif
734    
   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;  
   
735    case OP_MARK:    case OP_MARK:
736      case OP_PRUNE_ARG:
737      case OP_SKIP_ARG:
738      case OP_THEN_ARG:
739    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
740    
741    default:    default:
742      /* All opcodes are supported now! */
743      SLJIT_ASSERT_STOP();
744    return NULL;    return NULL;
745    }    }
746  }  }
747    
748  #define CASE_ITERATOR_PRIVATE_DATA_1 \  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
     case OP_MINSTAR: \  
     case OP_MINPLUS: \  
     case OP_QUERY: \  
     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:  
   
 #define CASE_ITERATOR_PRIVATE_DATA_2A \  
     case OP_STAR: \  
     case OP_PLUS: \  
     case OP_STARI: \  
     case OP_PLUSI: \  
     case OP_NOTSTAR: \  
     case OP_NOTPLUS: \  
     case OP_NOTSTARI: \  
     case OP_NOTPLUSI:  
   
 #define CASE_ITERATOR_PRIVATE_DATA_2B \  
     case OP_UPTO: \  
     case OP_MINUPTO: \  
     case OP_UPTOI: \  
     case OP_MINUPTOI: \  
     case OP_NOTUPTO: \  
     case OP_NOTMINUPTO: \  
     case OP_NOTUPTOI: \  
     case OP_NOTMINUPTOI:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \  
     case OP_TYPEMINSTAR: \  
     case OP_TYPEMINPLUS: \  
     case OP_TYPEQUERY: \  
     case OP_TYPEMINQUERY:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \  
     case OP_TYPESTAR: \  
     case OP_TYPEPLUS:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \  
     case OP_TYPEUPTO: \  
     case OP_TYPEMINUPTO:  
   
 static int get_class_iterator_size(pcre_uchar *cc)  
 {  
 switch(*cc)  
   {  
   case OP_CRSTAR:  
   case OP_CRPLUS:  
   return 2;  
   
   case OP_CRMINSTAR:  
   case OP_CRMINPLUS:  
   case OP_CRQUERY:  
   case OP_CRMINQUERY:  
   return 1;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))  
     return 0;  
   return 2;  
   
   default:  
   return 0;  
   }  
 }  
   
 static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  
749  {  {
750  int private_data_length = 0;  int count;
751  pcre_uchar *alternative;  pcre_uchar *slot;
 pcre_uchar *name;  
 pcre_uchar *end = NULL;  
 int space, size, i;  
 pcre_uint32 bracketlen;  
752    
753  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
754  while (cc < ccend)  while (cc < ccend)
755    {    {
   space = 0;  
   size = 0;  
   bracketlen = 0;  
756    switch(*cc)    switch(*cc)
757      {      {
758      case OP_SET_SOM:      case OP_SET_SOM:
# Line 790  while (cc < ccend) Line 766  while (cc < ccend)
766      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
767      break;      break;
768    
     case OP_ASSERT:  
     case OP_ASSERT_NOT:  
     case OP_ASSERTBACK:  
     case OP_ASSERTBACK_NOT:  
     case OP_ONCE:  
     case OP_ONCE_NC:  
     case OP_BRAPOS:  
     case OP_SBRA:  
     case OP_SBRAPOS:  
     private_data_length += sizeof(sljit_sw);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
769      case OP_CBRAPOS:      case OP_CBRAPOS:
770      case OP_SCBRAPOS:      case OP_SCBRAPOS:
     private_data_length += sizeof(sljit_sw);  
771      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
772      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
773      break;      break;
774    
775      case OP_COND:      case OP_COND:
776      case OP_SCOND:      case OP_SCOND:
777      bracketlen = cc[1 + LINK_SIZE];      /* Only AUTO_CALLOUT can insert this opcode. We do
778      if (bracketlen == OP_CREF)         not intend to support this case. */
779        {      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
780        bracketlen = GET2(cc, 1 + LINK_SIZE + 1);        return FALSE;
781        common->optimized_cbracket[bracketlen] = 0;      cc += 1 + LINK_SIZE;
       }  
     else if (bracketlen == OP_NCREF)  
       {  
       bracketlen = GET2(cc, 1 + LINK_SIZE + 1);  
       name = (pcre_uchar *)common->name_table;  
       alternative = name;  
       for (i = 0; i < common->name_count; i++)  
         {  
         if (GET2(name, 0) == bracketlen) break;  
         name += common->name_entry_size;  
         }  
       SLJIT_ASSERT(i != common->name_count);  
   
       for (i = 0; i < common->name_count; i++)  
         {  
         if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)  
           common->optimized_cbracket[GET2(alternative, 0)] = 0;  
         alternative += common->name_entry_size;  
         }  
       }  
   
     if (*cc == OP_COND)  
       {  
       /* Might be a hidden SCOND. */  
       alternative = cc + GET(cc, 1);  
       if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)  
         private_data_length += sizeof(sljit_sw);  
       }  
     else  
       private_data_length += sizeof(sljit_sw);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_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;  
782      break;      break;
783    
784      case OP_CLASS:      case OP_CREF:
785      case OP_NCLASS:      common->optimized_cbracket[GET2(cc, 1)] = 0;
786      size += 1 + 32 / sizeof(pcre_uchar);      cc += 1 + IMM2_SIZE;
     space = get_class_iterator_size(cc + size);  
787      break;      break;
788    
789  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8      case OP_DNREF:
790      case OP_XCLASS:      case OP_DNREFI:
791      size = GET(cc, 1);      case OP_DNCREF:
792      space = get_class_iterator_size(cc + size);      count = GET2(cc, 1 + IMM2_SIZE);
793        slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
794        while (count-- > 0)
795          {
796          common->optimized_cbracket[GET2(slot, 0)] = 0;
797          slot += common->name_entry_size;
798          }
799        cc += 1 + 2 * IMM2_SIZE;
800      break;      break;
 #endif  
801    
802      case OP_RECURSE:      case OP_RECURSE:
803      /* Set its value only once. */      /* Set its value only once. */
804      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
805        {        {
806        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
807        common->ovector_start += sizeof(sljit_sw);        common->ovector_start += sizeof(sljit_sw);
808        }        }
809      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
810      break;      break;
811    
812        case OP_CALLOUT:
813        if (common->capture_last_ptr == 0)
814          {
815          common->capture_last_ptr = common->ovector_start;
816          common->ovector_start += sizeof(sljit_sw);
817          }
818        cc += 2 + 2 * LINK_SIZE;
819        break;
820    
821        case OP_THEN_ARG:
822        common->has_then = TRUE;
823        common->control_head_ptr = 1;
824        /* Fall through. */
825    
826        case OP_PRUNE_ARG:
827        common->needs_start_ptr = TRUE;
828        /* Fall through. */
829    
830      case OP_MARK:      case OP_MARK:
831      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
832        {        {
# Line 923  while (cc < ccend) Line 836  while (cc < ccend)
836      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
837      break;      break;
838    
839        case OP_THEN:
840        common->has_then = TRUE;
841        common->control_head_ptr = 1;
842        /* Fall through. */
843    
844        case OP_PRUNE:
845        case OP_SKIP:
846        common->needs_start_ptr = TRUE;
847        cc += 1;
848        break;
849    
850        case OP_SKIP_ARG:
851        common->control_head_ptr = 1;
852        common->has_skip_arg = TRUE;
853        cc += 1 + 2 + cc[1];
854        break;
855    
856      default:      default:
857      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
858      if (cc == NULL)      if (cc == NULL)
859        return -1;        return FALSE;
860      break;      break;
861      }      }
862      }
863    return TRUE;
864    }
865    
866    if (space > 0 && cc >= end)  static int get_class_iterator_size(pcre_uchar *cc)
867      private_data_length += sizeof(sljit_sw) * space;  {
868    switch(*cc)
869      {
870      case OP_CRSTAR:
871      case OP_CRPLUS:
872      return 2;
873    
874    if (size != 0)    case OP_CRMINSTAR:
875      case OP_CRMINPLUS:
876      case OP_CRQUERY:
877      case OP_CRMINQUERY:
878      return 1;
879    
880      case OP_CRRANGE:
881      case OP_CRMINRANGE:
882      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
883        return 0;
884      return 2;
885    
886      default:
887      return 0;
888      }
889    }
890    
891    static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
892    {
893    pcre_uchar *end = bracketend(begin);
894    pcre_uchar *next;
895    pcre_uchar *next_end;
896    pcre_uchar *max_end;
897    pcre_uchar type;
898    sljit_sw length = end - begin;
899    int min, max, i;
900    
901    /* Detect fixed iterations first. */
902    if (end[-(1 + LINK_SIZE)] != OP_KET)
903      return FALSE;
904    
905    /* Already detected repeat. */
906    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
907      return TRUE;
908    
909    next = end;
910    min = 1;
911    while (1)
912      {
913      if (*next != *begin)
914        break;
915      next_end = bracketend(next);
916      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
917        break;
918      next = next_end;
919      min++;
920      }
921    
922    if (min == 2)
923      return FALSE;
924    
925    max = 0;
926    max_end = next;
927    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
928      {
929      type = *next;
930      while (1)
931      {      {
932      if (size < 0)      if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
933        {        break;
934        cc += -size;      next_end = bracketend(next + 2 + LINK_SIZE);
935  #ifdef SUPPORT_UTF      if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
936        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        break;
937  #endif      next = next_end;
938        }      max++;
     else  
       cc += size;  
939      }      }
940    
941    if (bracketlen != 0)    if (next[0] == type && next[1] == *begin && max >= 1)
942      {      {
943      if (cc >= end)      next_end = bracketend(next + 1);
944        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
945        {        {
946        end = bracketend(cc);        for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
947        if (end[-1 - LINK_SIZE] == OP_KET)          if (*next_end != OP_KET)
948          end = NULL;            break;
949    
950          if (i == max)
951            {
952            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
953            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
954            /* +2 the original and the last. */
955            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
956            if (min == 1)
957              return TRUE;
958            min--;
959            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
960            }
961        }        }
     cc += bracketlen;  
962      }      }
963    }    }
964  return private_data_length;  
965    if (min >= 3)
966      {
967      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
968      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
969      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
970      return TRUE;
971      }
972    
973    return FALSE;
974  }  }
975    
976  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
977        case OP_MINSTAR: \
978        case OP_MINPLUS: \
979        case OP_QUERY: \
980        case OP_MINQUERY: \
981        case OP_MINSTARI: \
982        case OP_MINPLUSI: \
983        case OP_QUERYI: \
984        case OP_MINQUERYI: \
985        case OP_NOTMINSTAR: \
986        case OP_NOTMINPLUS: \
987        case OP_NOTQUERY: \
988        case OP_NOTMINQUERY: \
989        case OP_NOTMINSTARI: \
990        case OP_NOTMINPLUSI: \
991        case OP_NOTQUERYI: \
992        case OP_NOTMINQUERYI:
993    
994    #define CASE_ITERATOR_PRIVATE_DATA_2A \
995        case OP_STAR: \
996        case OP_PLUS: \
997        case OP_STARI: \
998        case OP_PLUSI: \
999        case OP_NOTSTAR: \
1000        case OP_NOTPLUS: \
1001        case OP_NOTSTARI: \
1002        case OP_NOTPLUSI:
1003    
1004    #define CASE_ITERATOR_PRIVATE_DATA_2B \
1005        case OP_UPTO: \
1006        case OP_MINUPTO: \
1007        case OP_UPTOI: \
1008        case OP_MINUPTOI: \
1009        case OP_NOTUPTO: \
1010        case OP_NOTMINUPTO: \
1011        case OP_NOTUPTOI: \
1012        case OP_NOTMINUPTOI:
1013    
1014    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1015        case OP_TYPEMINSTAR: \
1016        case OP_TYPEMINPLUS: \
1017        case OP_TYPEQUERY: \
1018        case OP_TYPEMINQUERY:
1019    
1020    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1021        case OP_TYPESTAR: \
1022        case OP_TYPEPLUS:
1023    
1024    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1025        case OP_TYPEUPTO: \
1026        case OP_TYPEMINUPTO:
1027    
1028    static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1029  {  {
1030  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1031  pcre_uchar *alternative;  pcre_uchar *alternative;
1032  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1033    int private_data_ptr = *private_data_start;
1034  int space, size, bracketlen;  int space, size, bracketlen;
1035    
1036  while (cc < ccend)  while (cc < ccend)
# Line 972  while (cc < ccend) Line 1038  while (cc < ccend)
1038    space = 0;    space = 0;
1039    size = 0;    size = 0;
1040    bracketlen = 0;    bracketlen = 0;
1041      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1042        return;
1043    
1044      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1045        if (detect_repeat(common, cc))
1046          {
1047          /* These brackets are converted to repeats, so no global
1048          based single character repeat is allowed. */
1049          if (cc >= end)
1050            end = bracketend(cc);
1051          }
1052    
1053    switch(*cc)    switch(*cc)
1054      {      {
1055        case OP_KET:
1056        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1057          {
1058          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1059          private_data_ptr += sizeof(sljit_sw);
1060          cc += common->private_data_ptrs[cc + 1 - common->start];
1061          }
1062        cc += 1 + LINK_SIZE;
1063        break;
1064    
1065      case OP_ASSERT:      case OP_ASSERT:
1066      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1067      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1067  while (cc < ccend) Line 1155  while (cc < ccend)
1155      break;      break;
1156      }      }
1157    
1158      /* Character iterators, which are not inside a repeated bracket,
1159         gets a private slot instead of allocating it on the stack. */
1160    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1161      {      {
1162      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 1187  while (cc < ccend)
1187      cc += bracketlen;      cc += bracketlen;
1188      }      }
1189    }    }
1190    *private_data_start = private_data_ptr;
1191  }  }
1192    
1193  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1194  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)
1195  {  {
 pcre_uchar *ccend = bracketend(cc);  
1196  int length = 0;  int length = 0;
1197  BOOL possessive = FALSE;  int possessive = 0;
1198    BOOL stack_restore = FALSE;
1199  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1200  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1201    /* The last capture is a local variable even for recursions. */
1202    BOOL capture_last_found = FALSE;
1203    
1204  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1205    SLJIT_ASSERT(common->control_head_ptr != 0);
1206    *needs_control_head = TRUE;
1207    #else
1208    *needs_control_head = FALSE;
1209    #endif
1210    
1211    if (ccend == NULL)
1212    {    {
1213    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1214    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1215        {
1216        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1217        /* This is correct regardless of common->capture_last_ptr. */
1218        capture_last_found = TRUE;
1219        }
1220      cc = next_opcode(common, cc);
1221    }    }
1222    
 cc = next_opcode(common, cc);  
1223  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1224  while (cc < ccend)  while (cc < ccend)
1225    switch(*cc)    switch(*cc)
1226      {      {
1227      case OP_SET_SOM:      case OP_SET_SOM:
1228      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1229        stack_restore = TRUE;
1230      if (!setsom_found)      if (!setsom_found)
1231        {        {
1232        length += 2;        length += 2;
# Line 1130  while (cc < ccend) Line 1236  while (cc < ccend)
1236      break;      break;
1237    
1238      case OP_MARK:      case OP_MARK:
1239        case OP_PRUNE_ARG:
1240        case OP_THEN_ARG:
1241      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1242        stack_restore = TRUE;
1243      if (!setmark_found)      if (!setmark_found)
1244        {        {
1245        length += 2;        length += 2;
1246        setmark_found = TRUE;        setmark_found = TRUE;
1247        }        }
1248        if (common->control_head_ptr != 0)
1249          *needs_control_head = TRUE;
1250      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1251      break;      break;
1252    
1253      case OP_RECURSE:      case OP_RECURSE:
1254      if (common->has_set_som && !setsom_found)      stack_restore = TRUE;
1255        {      if (common->has_set_som && !setsom_found)
1256        length += 2;        {
1257        setsom_found = TRUE;        length += 2;
1258        }        setsom_found = TRUE;
1259      if (common->mark_ptr != 0 && !setmark_found)        }
1260        {      if (common->mark_ptr != 0 && !setmark_found)
1261        length += 2;        {
1262        setmark_found = TRUE;        length += 2;
1263        }        setmark_found = TRUE;
1264      cc += 1 + LINK_SIZE;        }
1265      break;      if (common->capture_last_ptr != 0 && !capture_last_found)
1266          {
1267          length += 2;
1268          capture_last_found = TRUE;
1269          }
1270        cc += 1 + LINK_SIZE;
1271        break;
1272    
1273        case OP_CBRA:
1274        case OP_CBRAPOS:
1275        case OP_SCBRA:
1276        case OP_SCBRAPOS:
1277        stack_restore = TRUE;
1278        if (common->capture_last_ptr != 0 && !capture_last_found)
1279          {
1280          length += 2;
1281          capture_last_found = TRUE;
1282          }
1283        length += 3;
1284        cc += 1 + LINK_SIZE + IMM2_SIZE;
1285        break;
1286    
1287        default:
1288        stack_restore = TRUE;
1289        /* Fall through. */
1290    
1291        case OP_NOT_WORD_BOUNDARY:
1292        case OP_WORD_BOUNDARY:
1293        case OP_NOT_DIGIT:
1294        case OP_DIGIT:
1295        case OP_NOT_WHITESPACE:
1296        case OP_WHITESPACE:
1297        case OP_NOT_WORDCHAR:
1298        case OP_WORDCHAR:
1299        case OP_ANY:
1300        case OP_ALLANY:
1301        case OP_ANYBYTE:
1302        case OP_NOTPROP:
1303        case OP_PROP:
1304        case OP_ANYNL:
1305        case OP_NOT_HSPACE:
1306        case OP_HSPACE:
1307        case OP_NOT_VSPACE:
1308        case OP_VSPACE:
1309        case OP_EXTUNI:
1310        case OP_EODN:
1311        case OP_EOD:
1312        case OP_CIRC:
1313        case OP_CIRCM:
1314        case OP_DOLL:
1315        case OP_DOLLM:
1316        case OP_CHAR:
1317        case OP_CHARI:
1318        case OP_NOT:
1319        case OP_NOTI:
1320    
1321        case OP_EXACT:
1322        case OP_POSSTAR:
1323        case OP_POSPLUS:
1324        case OP_POSQUERY:
1325        case OP_POSUPTO:
1326    
1327        case OP_EXACTI:
1328        case OP_POSSTARI:
1329        case OP_POSPLUSI:
1330        case OP_POSQUERYI:
1331        case OP_POSUPTOI:
1332    
1333        case OP_NOTEXACT:
1334        case OP_NOTPOSSTAR:
1335        case OP_NOTPOSPLUS:
1336        case OP_NOTPOSQUERY:
1337        case OP_NOTPOSUPTO:
1338    
1339        case OP_NOTEXACTI:
1340        case OP_NOTPOSSTARI:
1341        case OP_NOTPOSPLUSI:
1342        case OP_NOTPOSQUERYI:
1343        case OP_NOTPOSUPTOI:
1344    
1345      case OP_CBRA:      case OP_TYPEEXACT:
1346      case OP_CBRAPOS:      case OP_TYPEPOSSTAR:
1347      case OP_SCBRA:      case OP_TYPEPOSPLUS:
1348      case OP_SCBRAPOS:      case OP_TYPEPOSQUERY:
1349      length += 3;      case OP_TYPEPOSUPTO:
1350      cc += 1 + LINK_SIZE + IMM2_SIZE;  
1351      break;      case OP_CLASS:
1352        case OP_NCLASS:
1353        case OP_XCLASS:
1354    
     default:  
1355      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1356      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1357      break;      break;
1358      }      }
1359    
1360  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1361  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1362    return -1;    return stack_restore ? no_frame : no_stack;
1363    
1364  if (length > 0)  if (length > 0)
1365    return length + 1;    return length + 1;
1366  return -1;  return stack_restore ? no_frame : no_stack;
1367  }  }
1368    
1369  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)
1370  {  {
1371  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1372  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1373  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1374    /* The last capture is a local variable even for recursions. */
1375    BOOL capture_last_found = FALSE;
1376  int offset;  int offset;
1377    
1378  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1189  SLJIT_UNUSED_ARG(stacktop); Line 1380  SLJIT_UNUSED_ARG(stacktop);
1380  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1381    
1382  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1383  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1384    cc = next_opcode(common, cc);    {
1385      ccend = bracketend(cc) - (1 + LINK_SIZE);
1386      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1387        cc = next_opcode(common, cc);
1388      }
1389    
1390  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1391  while (cc < ccend)  while (cc < ccend)
1392    switch(*cc)    switch(*cc)
# Line 1200  while (cc < ccend) Line 1396  while (cc < ccend)
1396      if (!setsom_found)      if (!setsom_found)
1397        {        {
1398        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1399        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1400        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1401        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1402        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1210  while (cc < ccend) Line 1406  while (cc < ccend)
1406      break;      break;
1407    
1408      case OP_MARK:      case OP_MARK:
1409        case OP_PRUNE_ARG:
1410        case OP_THEN_ARG:
1411      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1412      if (!setmark_found)      if (!setmark_found)
1413        {        {
1414        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);
1415        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);
1416        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1417        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1418        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1227  while (cc < ccend) Line 1425  while (cc < ccend)
1425      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1426        {        {
1427        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1428        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1429        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1430        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1431        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1236  while (cc < ccend) Line 1434  while (cc < ccend)
1434      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1435        {        {
1436        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);
1437        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);
1438        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1439        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1440        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1441        setmark_found = TRUE;        setmark_found = TRUE;
1442        }        }
1443        if (common->capture_last_ptr != 0 && !capture_last_found)
1444          {
1445          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1446          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1447          stackpos += (int)sizeof(sljit_sw);
1448          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1449          stackpos += (int)sizeof(sljit_sw);
1450          capture_last_found = TRUE;
1451          }
1452      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1453      break;      break;
1454    
# Line 1249  while (cc < ccend) Line 1456  while (cc < ccend)
1456      case OP_CBRAPOS:      case OP_CBRAPOS:
1457      case OP_SCBRA:      case OP_SCBRA:
1458      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1459        if (common->capture_last_ptr != 0 && !capture_last_found)
1460          {
1461          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1462          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1463          stackpos += (int)sizeof(sljit_sw);
1464          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1465          stackpos += (int)sizeof(sljit_sw);
1466          capture_last_found = TRUE;
1467          }
1468      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1469      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1470      stackpos += (int)sizeof(sljit_sw);      stackpos += (int)sizeof(sljit_sw);
# Line 1268  while (cc < ccend) Line 1484  while (cc < ccend)
1484      break;      break;
1485      }      }
1486    
1487  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1488  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1489  }  }
1490    
1491  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)
1492  {  {
1493  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1494  int size;  int size;
1495  pcre_uchar *alternative;  pcre_uchar *alternative;
1496  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1283  while (cc < ccend) Line 1499  while (cc < ccend)
1499    size = 0;    size = 0;
1500    switch(*cc)    switch(*cc)
1501      {      {
1502        case OP_KET:
1503        if (PRIVATE_DATA(cc) != 0)
1504          private_data_length++;
1505        cc += 1 + LINK_SIZE;
1506        break;
1507    
1508      case OP_ASSERT:      case OP_ASSERT:
1509      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1510      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1387  return private_data_length; Line 1609  return private_data_length;
1609  }  }
1610    
1611  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,
1612    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1613  {  {
1614  DEFINE_COMPILER;  DEFINE_COMPILER;
1615  int srcw[2];  int srcw[2];
# Line 1408  stacktop = STACK(stacktop - 1); Line 1630  stacktop = STACK(stacktop - 1);
1630    
1631  if (!save)  if (!save)
1632    {    {
1633    stackptr += sizeof(sljit_sw);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1634    if (stackptr < stacktop)    if (stackptr < stacktop)
1635      {      {
1636      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 1646  if (!save)
1646    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1647    }    }
1648    
1649  while (status != end)  do
1650    {    {
1651    count = 0;    count = 0;
1652    switch(status)    switch(status)
1653      {      {
1654      case start:      case start:
1655      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1656      count = 1;      count = 1;
1657      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1658        if (needs_control_head)
1659          {
1660          SLJIT_ASSERT(common->control_head_ptr != 0);
1661          count = 2;
1662          srcw[1] = common->control_head_ptr;
1663          }
1664      status = loop;      status = loop;
1665      break;      break;
1666    
# Line 1445  while (status != end) Line 1673  while (status != end)
1673    
1674      switch(*cc)      switch(*cc)
1675        {        {
1676          case OP_KET:
1677          if (PRIVATE_DATA(cc) != 0)
1678            {
1679            count = 1;
1680            srcw[0] = PRIVATE_DATA(cc);
1681            }
1682          cc += 1 + LINK_SIZE;
1683          break;
1684    
1685        case OP_ASSERT:        case OP_ASSERT:
1686        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1687        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1657  while (status != end) Line 1894  while (status != end)
1894        }        }
1895      }      }
1896    }    }
1897    while (status != end);
1898    
1899  if (save)  if (save)
1900    {    {
# Line 1690  if (save) Line 1928  if (save)
1928  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1929  }  }
1930    
1931    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1932    {
1933    pcre_uchar *end = bracketend(cc);
1934    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1935    
1936    /* Assert captures then. */
1937    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1938      current_offset = NULL;
1939    /* Conditional block does not. */
1940    if (*cc == OP_COND || *cc == OP_SCOND)
1941      has_alternatives = FALSE;
1942    
1943    cc = next_opcode(common, cc);
1944    if (has_alternatives)
1945      current_offset = common->then_offsets + (cc - common->start);
1946    
1947    while (cc < end)
1948      {
1949      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1950        cc = set_then_offsets(common, cc, current_offset);
1951      else
1952        {
1953        if (*cc == OP_ALT && has_alternatives)
1954          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1955        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1956          *current_offset = 1;
1957        cc = next_opcode(common, cc);
1958        }
1959      }
1960    
1961    return end;
1962    }
1963    
1964  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
1965  #undef CASE_ITERATOR_PRIVATE_DATA_2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
1966  #undef CASE_ITERATOR_PRIVATE_DATA_2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
# Line 1708  while (list) Line 1979  while (list)
1979    {    {
1980    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1981    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
1982    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1983    list = list->next;    list = list->next;
1984    }    }
1985  }  }
# Line 1724  if (list_item) Line 1995  if (list_item)
1995    }    }
1996  }  }
1997    
1998  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)
1999  {  {
2000  DEFINE_COMPILER;  DEFINE_COMPILER;
2001  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
2002    
2003  if (list_item)  if (list_item)
2004    {    {
   list_item->type = type;  
   list_item->data = data;  
2005    list_item->start = start;    list_item->start = start;
2006    list_item->quit = LABEL();    list_item->quit = LABEL();
2007    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1748  stub_list* list_item = common->stubs; Line 2017  stub_list* list_item = common->stubs;
2017  while (list_item)  while (list_item)
2018    {    {
2019    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2020    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;  
     }  
2021    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2022    list_item = list_item->next;    list_item = list_item->next;
2023    }    }
2024  common->stubs = NULL;  common->stubs = NULL;
2025  }  }
2026    
2027  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2028  {  {
2029  DEFINE_COMPILER;  DEFINE_COMPILER;
2030    
2031  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);
2032  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2033  }  }
2034    
# Line 1781  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 2045  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2045  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2046  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2047  #endif  #endif
2048  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));
2049  }  }
2050    
2051  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 2059  static SLJIT_INLINE void reset_ovector(c
2059  DEFINE_COMPILER;  DEFINE_COMPILER;
2060  struct sljit_label *loop;  struct sljit_label *loop;
2061  int i;  int i;
2062    
2063  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2064    SLJIT_ASSERT(length > 1);
2065  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2066  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));
2067  if (length < 8)  if (length < 8)
2068    {    {
2069    for (i = 0; i < length; i++)    for (i = 1; i < length; i++)
2070      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);
2071    }    }
2072  else  else
2073    {    {
2074    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START - sizeof(sljit_sw));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2075    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2076    loop = LABEL();    loop = LABEL();
2077    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);
2078    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 2080  else
2080    }    }
2081  }  }
2082    
2083    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2084    {
2085    DEFINE_COMPILER;
2086    struct sljit_label *loop;
2087    int i;
2088    
2089    SLJIT_ASSERT(length > 1);
2090    /* OVECTOR(1) contains the "string begin - 1" constant. */
2091    if (length > 2)
2092      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2093    if (length < 8)
2094      {
2095      for (i = 2; i < length; i++)
2096        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
2097      }
2098    else
2099      {
2100      GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2101      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2102      loop = LABEL();
2103      OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2104      OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
2105      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2106      }
2107    
2108    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2109    if (common->mark_ptr != 0)
2110      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2111    if (common->control_head_ptr != 0)
2112      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2113    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2114    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2115    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2116    }
2117    
2118    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2119    {
2120    while (current != NULL)
2121      {
2122      switch (current[-2])
2123        {
2124        case type_then_trap:
2125        break;
2126    
2127        case type_mark:
2128        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2129          return current[-4];
2130        break;
2131    
2132        default:
2133        SLJIT_ASSERT_STOP();
2134        break;
2135        }
2136      current = (sljit_sw*)current[-1];
2137      }
2138    return -1;
2139    }
2140    
2141  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2142  {  {
2143  DEFINE_COMPILER;  DEFINE_COMPILER;
2144  struct sljit_label *loop;  struct sljit_label *loop;
2145  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2146    
2147  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2148  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 2151  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_R
2151  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2152  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2153    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);
2154  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));
2155  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2156    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);
2157  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));
2158  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));
2159  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2160  /* Unlikely, but possible */  /* Unlikely, but possible */
2161  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);
2162  loop = LABEL();  loop = LABEL();
2163  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);
2164  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 2169  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJ
2169  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);
2170  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);
2171  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2172  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2173    
2174  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2175  if (topbracket > 1)  if (topbracket > 1)
# Line 1867  else Line 2191  else
2191  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)
2192  {  {
2193  DEFINE_COMPILER;  DEFINE_COMPILER;
2194    struct sljit_jump *jump;
2195    
2196  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);
2197  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
2198      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2199    
2200  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2201  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2202  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));
2203  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);
2204    
2205  /* Store match begin and end. */  /* Store match begin and end. */
2206  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));
2207  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));
2208    
2209    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2210    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);
2211    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2212    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2213    #endif
2214    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2215    JUMPHERE(jump);
2216    
2217  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);
2218  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);
2219  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
# Line 2040  return (bit < 256) ? ((0 << 8) | bit) : Line 2375  return (bit < 256) ? ((0 << 8) | bit) :
2375    
2376  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2377  {  {
2378  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2379  DEFINE_COMPILER;  DEFINE_COMPILER;
2380  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2381    
# Line 2055  else if (common->mode == JIT_PARTIAL_SOF Line 2390  else if (common->mode == JIT_PARTIAL_SOF
2390    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);
2391    
2392  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2393    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);
2394  else  else
2395    {    {
2396    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2068  if (jump != NULL) Line 2403  if (jump != NULL)
2403    JUMPHERE(jump);    JUMPHERE(jump);
2404  }  }
2405    
2406  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2407  {  {
2408  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2409  DEFINE_COMPILER;  DEFINE_COMPILER;
2410  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2411    
2412  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2413    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2414      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2415      return;
2416      }
2417    
2418  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2419  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2420    {    {
2421    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));
2422    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);
2423    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2424    }    }
2425  else  else
2426    {    {
2427    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));
2428    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2429      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2430    else    else
2431      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2432    }    }
2433  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2434  }  }
2435    
2436  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 2449  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2449  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));
2450  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2451    {    {
2452    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);
2453    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2454    }    }
2455  else  else
# Line 2178  if (common->utf) Line 2512  if (common->utf)
2512  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2513  }  }
2514    
2515    static void read_char8(compiler_common *common)
2516    {
2517    /* Reads the precise value of a character into TMP1, if the character is
2518    less than 256. Otherwise it returns with a value greater or equal than 256. */
2519    DEFINE_COMPILER;
2520    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2521    struct sljit_jump *jump;
2522    #endif
2523    
2524    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2525    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2526    
2527    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2528    if (common->utf)
2529      {
2530    #if defined COMPILE_PCRE8
2531      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2532      add_jump(compiler, &common->utfreadchar8, JUMP(SLJIT_FAST_CALL));
2533      JUMPHERE(jump);
2534    #elif defined COMPILE_PCRE16
2535      /* Skip low surrogate if necessary. */
2536      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2537      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2538      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2539      JUMPHERE(jump);
2540    #endif /* COMPILE_PCRE[8|16] */
2541      }
2542    #endif
2543    }
2544    
2545  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2546  {  {
2547  /* 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. */
# Line 2204  if (common->utf) Line 2568  if (common->utf)
2568    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2569    JUMPHERE(jump);    JUMPHERE(jump);
2570    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2571    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2572    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2573    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2574    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    JUMPHERE(jump);
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  
2575  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
2576    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2577    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
# Line 2352  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC Line 2715  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC
2715  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2716  }  }
2717    
2718    static void do_utfreadchar8(compiler_common *common)
2719    {
2720    /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2721    of the character (>= 0xc0). Return value in TMP1. */
2722    DEFINE_COMPILER;
2723    struct sljit_jump *jump;
2724    
2725    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2726    
2727    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
2728    jump = JUMP(SLJIT_C_NOT_ZERO);
2729    /* Two byte sequence. */
2730    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2731    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2732    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);
2733    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2734    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2735    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2736    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2737    
2738    JUMPHERE(jump);
2739    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2740    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x800);
2741    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2742    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2743    }
2744    
2745  static void do_utfreadtype8(compiler_common *common)  static void do_utfreadtype8(compiler_common *common)
2746  {  {
2747  /* Fast decoding a UTF-8 character type. TMP2 contains the first byte  /* Fast decoding a UTF-8 character type. TMP2 contains the first byte
# Line 2368  jump = JUMP(SLJIT_C_NOT_ZERO); Line 2758  jump = JUMP(SLJIT_C_NOT_ZERO);
2758  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2759  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));
2760  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
2761    /* The upper 5 bits are known at this point. */
2762    compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x3);
2763  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2764  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2765  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);  
2766  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2767  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2768    
2769  JUMPHERE(compare);  JUMPHERE(compare);
2770  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2771  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2772    
2773  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2774  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);  JUMPHERE(jump);
2775  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2776  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2777    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2778  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2779  }  }
2780    
# Line 2565  if (newlinecheck) Line 2956  if (newlinecheck)
2956  return mainloop;  return mainloop;
2957  }  }
2958    
2959  #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)  
2960  {  {
2961  DEFINE_COMPILER;  /* Recursive function, which scans prefix literals. */
2962  struct sljit_label *start;  int len, repeat, len_save, consumed = 0;
2963  struct sljit_jump *quit;  pcre_int32 caseless, chr, mask;
2964  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uchar *alternative, *cc_save;
2965  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;  
2966    
2967    repeat = 1;
2968  while (TRUE)  while (TRUE)
2969    {    {
2970      last = TRUE;
2971      any = FALSE;
2972    caseless = 0;    caseless = 0;
2973    must_stop = 1;    switch (*cc)
   switch(*cc)  
2974      {      {
     case OP_CHAR:  
     must_stop = 0;  
     cc++;  
     break;  
   
2975      case OP_CHARI:      case OP_CHARI:
2976      caseless = 1;      caseless = 1;
2977      must_stop = 0;      case OP_CHAR:
2978        last = FALSE;
2979      cc++;      cc++;
2980      break;      break;
2981    
# Line 2620  while (TRUE) Line 3000  while (TRUE)
3000      cc++;      cc++;
3001      break;      break;
3002    
3003        case OP_EXACTI:
3004        caseless = 1;
3005      case OP_EXACT:      case OP_EXACT:
3006        repeat = GET2(cc, 1);
3007        last = FALSE;
3008      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
3009      break;      break;
3010    
3011      case OP_PLUSI:      case OP_PLUSI:
3012      case OP_MINPLUSI:      case OP_MINPLUSI:
3013      case OP_POSPLUSI:      case OP_POSPLUSI:
3014      caseless = 1;      caseless = 1;
3015      cc++;      cc++;
3016        break;
3017    
3018        case OP_KET:
3019        cc += 1 + LINK_SIZE;
3020        continue;
3021    
3022        case OP_ALT:
3023        cc += GET(cc, 1);
3024        continue;
3025    
3026        case OP_ONCE:
3027        case OP_ONCE_NC:
3028        case OP_BRA:
3029        case OP_BRAPOS:
3030        case OP_CBRA:
3031        case OP_CBRAPOS:
3032        alternative = cc + GET(cc, 1);
3033        while (*alternative == OP_ALT)
3034          {
3035          max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, max_chars);
3036          if (max_chars == 0)
3037            return consumed;
3038          alternative += GET(alternative, 1);
3039          }
3040    
3041        if (*cc == OP_CBRA || *cc == OP_CBRAPOS)
3042          cc += IMM2_SIZE;
3043        cc += 1 + LINK_SIZE;
3044        continue;
3045    
3046        case OP_CLASS:
3047        case OP_NCLASS:
3048        any = TRUE;
3049        cc += 1 + 32 / sizeof(pcre_uchar);
3050        break;
3051    
3052    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3053        case OP_XCLASS:
3054        any = TRUE;
3055        cc += GET(cc, 1);
3056        break;
3057    #endif
3058    
3059        case OP_NOT_DIGIT:
3060        case OP_DIGIT:
3061        case OP_NOT_WHITESPACE:
3062        case OP_WHITESPACE:
3063        case OP_NOT_WORDCHAR:
3064        case OP_WORDCHAR:
3065        case OP_ANY:
3066        case OP_ALLANY:
3067        any = TRUE;
3068        cc++;
3069        break;
3070    
3071    #ifdef SUPPORT_UCP
3072        case OP_NOTPROP:
3073        case OP_PROP:
3074        any = TRUE;
3075        cc += 1 + 2;
3076      break;      break;
3077    #endif
3078    
3079      case OP_EXACTI:      case OP_TYPEEXACT:
3080      caseless = 1;      repeat = GET2(cc, 1);
3081      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
3082      break;      continue;
3083    
3084      default:      default:
3085      must_stop = 2;      return consumed;
     break;  
3086      }      }
3087    
3088    if (must_stop == 2)    if (any)
3089        break;      {
3090    #ifdef SUPPORT_UTF
3091        if (common->utf) return consumed;
3092    #endif
3093    #if defined COMPILE_PCRE8
3094        mask = 0xff;
3095    #elif defined COMPILE_PCRE16
3096        mask = 0xffff;
3097    #elif defined COMPILE_PCRE32
3098        mask = 0xffffffff;
3099    #else
3100        SLJIT_ASSERT_STOP();
3101    #endif
3102    
3103        do
3104          {
3105          chars[0] = mask;
3106          chars[1] = mask;
3107    
3108          if (--max_chars == 0)
3109            return consumed;
3110          consumed++;
3111          chars += 2;
3112          }
3113        while (--repeat > 0);
3114    
3115        repeat = 1;
3116        continue;
3117        }
3118    
3119    len = 1;    len = 1;
3120  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3121    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3122  #endif  #endif
3123    
3124    if (caseless && char_has_othercase(common, cc))    if (caseless != 0 && char_has_othercase(common, cc))
3125      {      {
3126      caseless = char_get_othercase_bit(common, cc);      caseless = char_get_othercase_bit(common, cc);
3127      if (caseless == 0)      if (caseless == 0)
3128        return FALSE;        return consumed;
3129  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3130      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
3131  #else  #else
# Line 2666  while (TRUE) Line 3138  while (TRUE)
3138    else    else
3139      caseless = 0;      caseless = 0;
3140    
3141    while (len > 0 && location < MAX_N_CHARS * 2)    len_save = len;
3142      {    cc_save = cc;
3143      c = *cc;    while (TRUE)
3144      bit = 0;      {
3145      if (len == (caseless & 0xff))      do
3146        {        {
3147        bit = caseless >> 8;        chr = *cc;
3148        c |= bit;  #ifdef COMPILE_PCRE32
3149          if (SLJIT_UNLIKELY(chr == NOTACHAR))
3150            return consumed;
3151    #endif
3152          mask = 0;
3153          if (len == (caseless & 0xff))
3154            {
3155            mask = caseless >> 8;
3156            chr |= mask;
3157            }
3158    
3159          if (chars[0] == NOTACHAR)
3160            {
3161            chars[0] = chr;
3162            chars[1] = mask;
3163            }
3164          else
3165            {
3166            mask |= chars[0] ^ chr;
3167            chr |= mask;
3168            chars[0] = chr;
3169            chars[1] |= mask;
3170            }
3171    
3172          len--;
3173          if (--max_chars == 0)
3174            return consumed;
3175          consumed++;
3176          chars += 2;
3177          cc++;
3178        }        }
3179        while (len > 0);
3180    
3181      chars[location] = c;      if (--repeat == 0)
3182      chars[location + 1] = bit;        break;
3183    
3184      len--;      len = len_save;
3185      location += 2;      cc = cc_save;
3186      cc++;      }
3187    
3188      repeat = 1;
3189      if (last)
3190        return consumed;
3191      }
3192    }
3193    
3194    #define MAX_N_CHARS 16
3195    
3196    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3197    {
3198    DEFINE_COMPILER;
3199    struct sljit_label *start;
3200    struct sljit_jump *quit;
3201    pcre_uint32 chars[MAX_N_CHARS * 2];
3202    pcre_uint8 ones[MAX_N_CHARS];
3203    pcre_uint32 mask;
3204    int i, max;
3205    int offsets[3];
3206    
3207    for (i = 0; i < MAX_N_CHARS; i++)
3208      {
3209      chars[i << 1] = NOTACHAR;
3210      chars[(i << 1) + 1] = 0;
3211      }
3212    
3213    max = scan_prefix(common, common->start, chars, MAX_N_CHARS);
3214    
3215    if (max <= 1)
3216      return FALSE;
3217    
3218    for (i = 0; i < max; i++)
3219      {
3220      mask = chars[(i << 1) + 1];
3221      ones[i] = ones_in_half_byte[mask & 0xf];
3222      mask >>= 4;
3223      while (mask != 0)
3224        {
3225        ones[i] += ones_in_half_byte[mask & 0xf];
3226        mask >>= 4;
3227      }      }
3228      }
3229    
3230    if (location >= MAX_N_CHARS * 2 || must_stop != 0)  offsets[0] = -1;
3231    /* Scan forward. */
3232    for (i = 0; i < max; i++)
3233      if (ones[i] <= 2) {
3234        offsets[0] = i;
3235      break;      break;
3236    }    }
3237    
3238  /* At least two characters are required. */  if (offsets[0] == -1)
3239  if (location < 2 * 2)    return FALSE;
3240      return FALSE;  
3241    /* Scan backward. */
3242    offsets[1] = -1;
3243    for (i = max - 1; i > offsets[0]; i--)
3244      if (ones[i] <= 2) {
3245        offsets[1] = i;
3246        break;
3247      }
3248    
3249    offsets[2] = -1;
3250    if (offsets[1] >= 0)
3251      {
3252      /* Scan from middle. */
3253      for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3254        if (ones[i] <= 2)
3255          {
3256          offsets[2] = i;
3257          break;
3258          }
3259    
3260      if (offsets[2] == -1)
3261        {
3262        for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3263          if (ones[i] <= 2)
3264            {
3265            offsets[2] = i;
3266            break;
3267            }
3268        }
3269      }
3270    
3271    SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3272    SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3273    
3274    chars[0] = chars[offsets[0] << 1];
3275    chars[1] = chars[(offsets[0] << 1) + 1];
3276    if (offsets[2] >= 0)
3277      {
3278      chars[2] = chars[offsets[2] << 1];
3279      chars[3] = chars[(offsets[2] << 1) + 1];
3280      }
3281    if (offsets[1] >= 0)
3282      {
3283      chars[4] = chars[offsets[1] << 1];
3284      chars[5] = chars[(offsets[1] << 1) + 1];
3285      }
3286    
3287    max -= 1;
3288  if (firstline)  if (firstline)
3289    {    {
3290    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3291    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3292    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));
3293    }    }
3294  else  else
3295    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));
3296    
3297  start = LABEL();  start = LABEL();
3298  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3299    
3300  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]));
3301  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  if (offsets[1] >= 0)
3302      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3303  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));
3304    
3305  if (chars[1] != 0)  if (chars[1] != 0)
3306    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3307  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3308  if (location > 2 * 2)  if (offsets[2] >= 0)
3309    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));
3310  if (chars[3] != 0)  
3311    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)  
3312    {    {
3313    if (chars[5] != 0)    if (chars[5] != 0)
3314      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3315    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
3316      }
3317    
3318    if (offsets[2] >= 0)
3319      {
3320      if (chars[3] != 0)
3321        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3322      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3323    }    }
3324  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));
3325    
# Line 2728  JUMPHERE(quit); Line 3328  JUMPHERE(quit);
3328  if (firstline)  if (firstline)
3329    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3330  else  else
3331    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));
3332  return TRUE;  return TRUE;
3333  }  }
3334    
# Line 2877  if (firstline) Line 3477  if (firstline)
3477    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3478  }  }
3479    
3480  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);
3481    
3482    static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, pcre_uint8 *start_bits, BOOL firstline)
3483  {  {
3484  DEFINE_COMPILER;  DEFINE_COMPILER;
3485  struct sljit_label *start;  struct sljit_label *start;
3486  struct sljit_jump *quit;  struct sljit_jump *quit;
3487  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3488    jump_list *matches = NULL;
3489  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3490  struct sljit_jump *jump;  struct sljit_jump *jump;
3491  #endif  #endif
# Line 2901  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 3504  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3504  if (common->utf)  if (common->utf)
3505    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3506  #endif  #endif
3507    
3508    if (!check_class_ranges(common, start_bits, (start_bits[31] & 0x80) != 0, TRUE, &matches))
3509      {
3510  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3511  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3512  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3513  JUMPHERE(jump);    JUMPHERE(jump);
3514  #endif  #endif
3515  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3516  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3517  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
3518  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3519  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);
3520  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3521      }
3522    
3523  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3524  if (common->utf)  if (common->utf)
# Line 2939  if (common->utf) Line 3546  if (common->utf)
3546  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE[8|16] */
3547  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3548  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3549  JUMPHERE(found);  if (found != NULL)
3550      JUMPHERE(found);
3551    if (matches != NULL)
3552      set_jumps(matches, LABEL());
3553  JUMPHERE(quit);  JUMPHERE(quit);
3554    
3555  if (firstline)  if (firstline)
# Line 3022  GET_LOCAL_BASE(TMP3, 0, 0); Line 3632  GET_LOCAL_BASE(TMP3, 0, 0);
3632  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3633  mainloop = LABEL();  mainloop = LABEL();
3634  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3635  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);
3636    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3637    
3638  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3639  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));
3640  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 3642  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_I
3642  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3643    
3644  JUMPHERE(jump);  JUMPHERE(jump);
3645  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3646  /* End of dropping frames. */  /* End of dropping frames. */
3647  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3648    
3649  JUMPHERE(jump);  JUMPHERE(jump);
3650  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3651  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3652  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. */  
3653  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));
3654  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3655  }  }
# Line 3063  static void check_wordboundary(compiler_ Line 3658  static void check_wordboundary(compiler_
3658  {  {
3659  DEFINE_COMPILER;  DEFINE_COMPILER;
3660  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3661    jump_list *skipread_list = NULL;
3662  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3663  struct sljit_jump *jump;  struct sljit_jump *jump;
3664  #endif  #endif
# Line 3120  else Line 3716  else
3716  JUMPHERE(skipread);  JUMPHERE(skipread);
3717    
3718  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3719  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3720  peek_char(common);  peek_char(common);
3721    
3722  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 3161  else Line 3757  else
3757      JUMPHERE(jump);      JUMPHERE(jump);
3758  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3759    }    }
3760  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3761    
3762  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);
3763  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
# Line 3178  sljit_emit_fast_return(compiler, SLJIT_M Line 3774  sljit_emit_fast_return(compiler, SLJIT_M
3774  static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)  static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)
3775  {  {
3776  DEFINE_COMPILER;  DEFINE_COMPILER;
3777  struct sljit_jump *jump;  int offset;
3778    
3779  if (ranges[0] < 0)  if (ranges[0] < 0 || ranges[0] > 4)
3780    return FALSE;    return FALSE;
3781    
3782    /* No character is accepted. */
3783    if (ranges[0] == 0 && ranges[1] == 0)
3784      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
3785    
3786    if (readch)
3787      read_char8(common);
3788    
3789  switch(ranges[0])  switch(ranges[0])
3790    {    {
3791      case 0:
3792      /* When ranges[1] != 0, all characters are accepted. */
3793      return TRUE;
3794    
3795    case 1:    case 1:
   if (readch)  
     read_char(common);  
3796    add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, 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[2]));
3797    return TRUE;    return TRUE;
3798    
3799    case 2:    case 2:
3800    if (readch)    if (ranges[2] + 1 != ranges[3])
3801      read_char(common);      {
3802    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3803    add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - 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]));
3804        }
3805      else
3806        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3807    return TRUE;    return TRUE;
3808    
3809    case 4:    case 3:
3810    if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])    if (ranges[1] != 0)
3811      {      {
3812      if (readch)      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3813        read_char(common);      if (ranges[2] + 1 != ranges[3])
     if (ranges[1] != 0)  
3814        {        {
3815        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3816        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3817        }        }
3818      else      else
3819        {        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
       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);  
       }  
3820      return TRUE;      return TRUE;
3821      }      }
3822    if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))  
3823      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2]));
3824      if (ranges[3] + 1 != ranges[4])
3825        {
3826        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[3]);
3827        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[3]));
3828        }
3829      else
3830        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3]));
3831      return TRUE;
3832    
3833      case 4:
3834      if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4])
3835          && (ranges[2] | (ranges[4] - ranges[2])) == ranges[4]
3836          && is_powerof2(ranges[4] - ranges[2]))
3837      {      {
     if (readch)  
       read_char(common);  
3838      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);
3839      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);      if (ranges[4] + 1 != ranges[5])
3840      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));        {
3841          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3842          add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3843          }
3844        else
3845          add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3846      return TRUE;      return TRUE;
3847      }      }
   return FALSE;  
3848    
3849    default:    if (ranges[1] != 0)
3850    return FALSE;      {
3851    }      offset = 0;
3852  }      if (ranges[2] + 1 != ranges[3])
3853          {
3854  static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3855  {        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3856  int i, bit, length;        offset = ranges[2];
3857  const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;        }
3858        else
3859          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3860    
3861  bit = ctypes[0] & flag;      if (ranges[4] + 1 != ranges[5])
3862  ranges[0] = -1;        {
3863  ranges[1] = bit != 0 ? 1 : 0;        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - offset);
3864  length = 0;        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3865          }
3866        else
3867          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4] - offset));
3868        return TRUE;
3869        }
3870    
3871  for (i = 1; i < 256; i++)    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3872    if ((ctypes[i] & flag) != bit)    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[2]));
3873      if (ranges[3] + 1 != ranges[4])
3874      {      {
3875      if (length >= MAX_RANGE_SIZE)      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]);
3876        return;      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[3]));
     ranges[2 + length] = i;  
     length++;  
     bit ^= flag;  
3877      }      }
3878      else
3879        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3880      return TRUE;
3881    
3882  if (bit != 0)    default:
3883    {    SLJIT_ASSERT_STOP();
3884    if (length >= MAX_RANGE_SIZE)    return FALSE;
     return;  
   ranges[2 + length] = 256;  
   length++;  
3885    }    }
 ranges[0] = length;  
3886  }  }
3887    
3888  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks)
3889  {  {
3890  int ranges[2 + MAX_RANGE_SIZE];  int ranges[2 + MAX_RANGE_SIZE];
3891  pcre_uint8 bit, cbit, all;  pcre_uint8 bit, cbit, all;
3892  int i, byte, length = 0;  int i, byte, length = 0;
3893    
3894  bit = bits[0] & 0x1;  bit = bits[0] & 0x1;
3895  ranges[1] = bit;  ranges[1] = !invert ? bit : (bit ^ 0x1);
3896  /* Can be 0 or 255. */  /* All bits will be zero or one (since bit is zero or one). */
3897  all = -bit;  all = -bit;
3898    
3899  for (i = 0; i < 256; )  for (i = 0; i < 256; )
# Line 3481  sljit_emit_fast_return(compiler, RETURN_ Line 4104  sljit_emit_fast_return(compiler, RETURN_
4104    
4105  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
4106    
4107  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)
4108  {  {
4109  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
4110  pcre_uint32 c1, c2;  pcre_uint32 c1, c2;
# Line 3577  do Line 4200  do
4200  #endif  #endif
4201    
4202    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
4203  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
4204    
4205    /* Unaligned read is supported. */    /* Unaligned read is supported. */
4206    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3594  do Line 4217  do
4217    
4218  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
4219    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))
4220  #elif defined COMPILE_PCRE16  #else
4221    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 */)  
4222  #endif  #endif
4223      {      {
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
4224      if (context->length >= 4)      if (context->length >= 4)
4225        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  
4226      else if (context->length >= 2)      else if (context->length >= 2)
4227        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);
4228    #if defined COMPILE_PCRE8
4229      else if (context->length >= 1)      else if (context->length >= 1)
4230        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);
4231  #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] */  
4232      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
4233    
4234      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3625  do Line 4239  do
4239        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));
4240        break;        break;
4241    
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
4242        case 2 / sizeof(pcre_uchar):        case 2 / sizeof(pcre_uchar):
4243        if (context->oc.asushort != 0)        if (context->oc.asushort != 0)
4244          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 4253  do
4253        break;        break;
4254  #endif  #endif
4255    
 #endif /* COMPILE_PCRE[8|16] */  
   
4256        default:        default:
4257        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
4258        break;        break;
# Line 3651  do Line 4262  do
4262    
4263  #else  #else
4264    
4265    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
4266    if (context->length > 0)    if (context->length >= 1)
4267      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
4268    
4269    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
# Line 3703  static void compile_xclass_matchingpath( Line 4314  static void compile_xclass_matchingpath(
4314  {  {
4315  DEFINE_COMPILER;  DEFINE_COMPILER;
4316  jump_list *found = NULL;  jump_list *found = NULL;
4317  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;
4318  pcre_int32 c, charoffset;  pcre_int32 c, charoffset;
 const pcre_uint32 *other_cases;  
4319  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4320  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4321  int compares, invertcmp, numberofcmps;  int compares, invertcmp, numberofcmps;
4322    
4323  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4324  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4325  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4326  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4327    const pcre_uint32 *other_cases;
4328  pcre_int32 typeoffset;  pcre_int32 typeoffset;
4329  #endif  #endif
4330    
# Line 3721  pcre_int32 typeoffset; Line 4333  pcre_int32 typeoffset;
4333  detect_partial_match(common, backtracks);  detect_partial_match(common, backtracks);
4334  read_char(common);  read_char(common);
4335    
4336  if ((*cc++ & XCL_MAP) != 0)  cc++;
4337    if ((cc[-1] & XCL_HASPROP) == 0)
4338    {    {
4339    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    if ((cc[-1] & XCL_MAP) != 0)
4340  #ifndef COMPILE_PCRE8      {
4341    jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4342  #elif defined SUPPORT_UTF  #ifdef SUPPORT_UCP
4343    if (common->utf)      charsaved = TRUE;
     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
4344  #endif  #endif
4345        if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, FALSE, backtracks))
4346          {
4347          jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4348    
4349          OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4350          OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4351          OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4352          OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4353          OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4354          add_jump(compiler, &found, JUMP(SLJIT_C_NOT_ZERO));
4355          add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4356    
4357          JUMPHERE(jump);
4358          }
4359        else
4360          add_jump(compiler, &found, CMP(SLJIT_C_LESS_EQUAL, TMP3, 0, SLJIT_IMM, 0xff));
4361    
4362    if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, list))      OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
4363        cc += 32 / sizeof(pcre_uchar);
4364        }
4365      else
4366        add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0xff));
4367      }
4368    else if ((cc[-1] & XCL_MAP) != 0)
4369      {
4370      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4371    #ifdef SUPPORT_UCP
4372      charsaved = TRUE;
4373    #endif
4374      if (!check_class_ranges(common, (const pcre_uint8 *)cc, FALSE, TRUE, list))
4375      {      {
4376    #ifdef COMPILE_PCRE8
4377        SLJIT_ASSERT(common->utf);
4378    #endif
4379        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4380    
4381      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4382      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4383      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4384      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4385      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);
4386      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
     }  
4387    
 #ifndef COMPILE_PCRE8  
   JUMPHERE(jump);  
 #elif defined SUPPORT_UTF  
   if (common->utf)  
4388      JUMPHERE(jump);      JUMPHERE(jump);
4389  #endif      }
4390    
4391    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
 #ifdef SUPPORT_UCP  
   charsaved = TRUE;  
 #endif  
4392    cc += 32 / sizeof(pcre_uchar);    cc += 32 / sizeof(pcre_uchar);
4393    }    }
4394    
# Line 3808  while (*cc != XCL_END) Line 4446  while (*cc != XCL_END)
4446        case PT_SPACE:        case PT_SPACE:
4447        case PT_PXSPACE:        case PT_PXSPACE:
4448        case PT_WORD:        case PT_WORD:
4449          case PT_PXGRAPH:
4450          case PT_PXPRINT:
4451          case PT_PXPUNCT:
4452        needstype = TRUE;        needstype = TRUE;
4453        needschar = TRUE;        needschar = TRUE;
4454        break;        break;
4455    
4456        case PT_CLIST:        case PT_CLIST:
4457          case PT_UCNC:
4458        needschar = TRUE;        needschar = TRUE;
4459        break;        break;
4460    
# Line 3994  while (*cc != XCL_END) Line 4636  while (*cc != XCL_END)
4636    
4637        case PT_SPACE:        case PT_SPACE:
4638        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);  
         }  
4639        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4640        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);
4641        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);
4642        if (*cc == PT_SPACE)  
4643          JUMPHERE(jump);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x9);
4644          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4645    
4646          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x9);
4647          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4648    
4649        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4650        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 4014  while (*cc != XCL_END) Line 4655  while (*cc != XCL_END)
4655        case PT_WORD:        case PT_WORD:
4656        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, CHAR_UNDERSCORE - charoffset);
4657        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4658        /* ... fall through */        /* Fall through. */
4659    
4660        case PT_ALNUM:        case PT_ALNUM:
4661        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
# Line 4078  while (*cc != XCL_END) Line 4719  while (*cc != XCL_END)
4719          }          }
4720        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4721        break;        break;
4722    
4723          case PT_UCNC:
4724          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);
4725          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4726          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);
4727          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4728          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);
4729          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4730    
4731          SET_CHAR_OFFSET(0xa0);
4732          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);
4733          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4734          SET_CHAR_OFFSET(0);
4735          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
4736          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4737          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4738          break;
4739    
4740          case PT_PXGRAPH:
4741          /* C and Z groups are the farthest two groups. */
4742          SET_TYPE_OFFSET(ucp_Ll);
4743          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4744          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4745    
4746          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4747    
4748          /* In case of ucp_Cf, we overwrite the result. */
4749          SET_CHAR_OFFSET(0x2066);
4750          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4751          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4752    
4753          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4754          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4755    
4756          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x2066);
4757          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4758    
4759          JUMPHERE(jump);
4760          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4761          break;
4762    
4763          case PT_PXPRINT:
4764          /* C and Z groups are the farthest two groups. */
4765          SET_TYPE_OFFSET(ucp_Ll);
4766          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4767          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4768    
4769          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Ll);
4770          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_NOT_EQUAL);
4771    
4772          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4773    
4774          /* In case of ucp_Cf, we overwrite the result. */
4775          SET_CHAR_OFFSET(0x2066);
4776          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4777          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4778    
4779          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4780          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4781    
4782          JUMPHERE(jump);
4783          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4784          break;
4785    
4786          case PT_PXPUNCT:
4787          SET_TYPE_OFFSET(ucp_Sc);
4788          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Sc);
4789          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4790    
4791          SET_CHAR_OFFSET(0);
4792          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xff);
4793          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4794    
4795          SET_TYPE_OFFSET(ucp_Pc);
4796          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ps - ucp_Pc);
4797          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4798          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4799          break;
4800        }        }
4801      cc += 2;      cc += 2;
4802      }      }
# Line 4103  int length; Line 4822  int length;
4822  unsigned int c, oc, bit;  unsigned int c, oc, bit;
4823  compare_context context;  compare_context context;
4824  struct sljit_jump *jump[4];  struct sljit_jump *jump[4];
4825    jump_list *end_list;
4826  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4827  struct sljit_label *label;  struct sljit_label *label;
4828  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4133  switch(type) Line 4853  switch(type)
4853    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
4854    case OP_DIGIT:    case OP_DIGIT:
4855    /* 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);  
4856    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4857    /* Flip the starting bit in the negative case. */    /* Flip the starting bit in the negative case. */
4858    if (type == OP_NOT_DIGIT)    read_char8_type(common);
4859      common->digits[1] ^= 1;    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);
4860    if (!check_ranges(common, common->digits, backtracks, TRUE))    add_jump(compiler, backtracks, JUMP(type == OP_DIGIT ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
     {  
     read_char8_type(common);  
     OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);  
     add_jump(compiler, backtracks, JUMP(type == OP_DIGIT ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));  
     }  
   if (type == OP_NOT_DIGIT)  
     common->digits[1] ^= 1;  
4861    return cc;    return cc;
4862    
4863    case OP_NOT_WHITESPACE:    case OP_NOT_WHITESPACE:
# Line 4171  switch(type) Line 4882  switch(type)
4882    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4883      {      {
4884      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);
4885        end_list = NULL;
4886      if (common->mode != JIT_PARTIAL_HARD_COMPILE)      if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4887        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));
4888      else      else
4889        jump[1] = check_str_end(common);        check_str_end(common, &end_list);
4890    
4891      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4892      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));
4893      if (jump[1] != NULL)      set_jumps(end_list, LABEL());
       JUMPHERE(jump[1]);  
4894      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4895      }      }
4896    else    else
# Line 4223  switch(type) Line 4934  switch(type)
4934  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4935    case OP_NOTPROP:    case OP_NOTPROP:
4936    case OP_PROP:    case OP_PROP:
4937    propdata[0] = 0;    propdata[0] = XCL_HASPROP;
4938    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;
4939    propdata[2] = cc[0];    propdata[2] = cc[0];
4940    propdata[3] = cc[1];    propdata[3] = cc[1];
# Line 4238  switch(type) Line 4949  switch(type)
4949    read_char(common);    read_char(common);
4950    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);
4951    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
4952      end_list = NULL;
4953    if (common->mode != JIT_PARTIAL_HARD_COMPILE)    if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4954      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));
4955    else    else
4956      jump[1] = check_str_end(common);      check_str_end(common, &end_list);
4957    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4958    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);
4959    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));
4960    jump[3] = JUMP(SLJIT_JUMP);    jump[2] = JUMP(SLJIT_JUMP);
4961    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4962    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);
4963      set_jumps(end_list, LABEL());
4964    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
4965    JUMPHERE(jump[2]);    JUMPHERE(jump[2]);
   JUMPHERE(jump[3]);  
4966    return cc;    return cc;
4967    
4968    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
# Line 4580  switch(type) Line 5292  switch(type)
5292    case OP_CLASS:    case OP_CLASS:
5293    case OP_NCLASS:    case OP_NCLASS:
5294    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
5295    read_char(common);    read_char8(common);
5296    if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, backtracks))    if (check_class_ranges(common, (const pcre_uint8 *)cc, type == OP_NCLASS, FALSE, backtracks))
5297      return cc + 32 / sizeof(pcre_uchar);      return cc + 32 / sizeof(pcre_uchar);
5298    
5299  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
# Line 4714  if (context.length > 0) Line 5426  if (context.length > 0)
5426  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);
5427  }  }
5428    
 static struct sljit_jump *compile_ref_checks(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)  
 {  
 DEFINE_COMPILER;  
 int offset = GET2(cc, 1) << 1;  
   
 OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  
 if (!common->jscript_compat)  
   {  
   if (backtracks == NULL)  
     {  
     /* OVECTOR(1) contains the "string begin - 1" constant. */  
     OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  
     OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);  
     OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
     OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);  
     return JUMP(SLJIT_C_NOT_ZERO);  
     }  
   add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));  
   }  
 return CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
 }  
   
5429  /* Forward definitions. */  /* Forward definitions. */
5430  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);
5431  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);
# Line 4768  static void compile_backtrackingpath(com Line 5458  static void compile_backtrackingpath(com
5458    
5459  #define BACKTRACK_AS(type) ((type *)backtrack)  #define BACKTRACK_AS(type) ((type *)backtrack)
5460    
5461  static pcre_uchar *compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)  static void compile_dnref_search(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)
5462    {
5463    /* The OVECTOR offset goes to TMP2. */
5464    DEFINE_COMPILER;
5465    int count = GET2(cc, 1 + IMM2_SIZE);
5466    pcre_uchar *slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
5467    unsigned int offset;
5468    jump_list *found = NULL;
5469    
5470    SLJIT_ASSERT(*cc == OP_DNREF || *cc == OP_DNREFI);
5471    
5472    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
5473    
5474    count--;
5475    while (count-- > 0)
5476      {
5477      offset = GET2(slot, 0) << 1;
5478      GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5479      add_jump(compiler, &found, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5480      slot += common->name_entry_size;
5481      }
5482    
5483    offset = GET2(slot, 0) << 1;
5484    GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5485    if (backtracks != NULL && !common->jscript_compat)
5486      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5487    
5488    set_jumps(found, LABEL());
5489    }
5490    
5491    static void compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)
5492  {  {
5493  DEFINE_COMPILER;  DEFINE_COMPILER;
5494  int offset = GET2(cc, 1) << 1;  BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5495    int offset = 0;
5496  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
5497  struct sljit_jump *partial;  struct sljit_jump *partial;
5498  struct sljit_jump *nopartial;  struct sljit_jump *nopartial;
5499    
5500  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  if (ref)
5501  /* OVECTOR(1) contains the "string begin - 1" constant. */    {
5502  if (withchecks && !common->jscript_compat)    offset = GET2(cc, 1) << 1;
5503    add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5504      /* OVECTOR(1) contains the "string begin - 1" constant. */
5505      if (withchecks && !common->jscript_compat)
5506        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5507      }
5508    else
5509      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5510    
5511  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5512  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5513    {    {
5514    SLJIT_ASSERT(TMP1 == SLJIT_SCRATCH_REG1 && STACK_TOP == SLJIT_SCRATCH_REG2 && TMP2 == SLJIT_SCRATCH_REG3);    SLJIT_ASSERT(TMP1 == SLJIT_SCRATCH_REG1 && STACK_TOP == SLJIT_SCRATCH_REG2 && TMP2 == SLJIT_SCRATCH_REG3);
5515    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));    if (ref)
5516        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5517      else
5518        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5519    
5520    if (withchecks)    if (withchecks)
5521      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5522    
# Line 4810  if (common->utf && *cc == OP_REFI) Line 5541  if (common->utf && *cc == OP_REFI)
5541  else  else
5542  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
5543    {    {
5544    OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);    if (ref)
5545        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
5546      else
5547        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
5548    
5549    if (withchecks)    if (withchecks)
5550      jump = JUMP(SLJIT_C_ZERO);      jump = JUMP(SLJIT_C_ZERO);
5551    
# Line 4847  if (jump != NULL) Line 5582  if (jump != NULL)
5582    else    else
5583      JUMPHERE(jump);      JUMPHERE(jump);
5584    }    }
 return cc + 1 + IMM2_SIZE;  
5585  }  }
5586    
5587  static SLJIT_INLINE pcre_uchar *compile_ref_iterator_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)  static SLJIT_INLINE pcre_uchar *compile_ref_iterator_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5588  {  {
5589  DEFINE_COMPILER;  DEFINE_COMPILER;
5590    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5591  backtrack_common *backtrack;  backtrack_common *backtrack;
5592  pcre_uchar type;  pcre_uchar type;
5593    int offset = 0;
5594  struct sljit_label *label;  struct sljit_label *label;
5595  struct sljit_jump *zerolength;  struct sljit_jump *zerolength;
5596  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 4864  BOOL minimize; Line 5600  BOOL minimize;
5600    
5601  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
5602    
5603    if (ref)
5604      offset = GET2(cc, 1) << 1;
5605    else
5606      cc += IMM2_SIZE;
5607  type = cc[1 + IMM2_SIZE];  type = cc[1 + IMM2_SIZE];
5608    
5609    SLJIT_COMPILE_ASSERT((OP_CRSTAR & 0x1) == 0, crstar_opcode_must_be_even);
5610  minimize = (type & 0x1) != 0;  minimize = (type & 0x1) != 0;
5611  switch(type)  switch(type)
5612    {    {
# Line 4902  if (!minimize) Line 5644  if (!minimize)
5644    if (min == 0)    if (min == 0)
5645      {      {
5646      allocate_stack(common, 2);      allocate_stack(common, 2);
5647        if (ref)
5648          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5649      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5650      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5651      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5652      OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));      OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5653      zerolength = compile_ref_checks(common, ccbegin, NULL);      /* Handles both invalid and empty cases. Since the minimum repeat,
5654        is zero the invalid case is basically the same as an empty case. */
5655        if (ref)
5656          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5657        else
5658          {
5659          compile_dnref_search(common, ccbegin, NULL);
5660          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5661          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5662          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5663          }
5664      /* Restore if not zero length. */      /* Restore if not zero length. */
5665      OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));      OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5666      }      }
5667    else    else
5668      {      {
5669      allocate_stack(common, 1);      allocate_stack(common, 1);
5670        if (ref)
5671          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5672      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5673      zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);      if (ref)
5674          {
5675          add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5676          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5677          }
5678        else
5679          {
5680          compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5681          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5682          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5683          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5684          }
5685      }      }
5686    
5687    if (min > 1 || max > 1)    if (min > 1 || max > 1)
5688      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
5689    
5690    label = LABEL();    label = LABEL();
5691      if (!ref)
5692        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
5693    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);
5694    
5695    if (min > 1 || max > 1)    if (min > 1 || max > 1)
# Line 4951  if (!minimize) Line 5720  if (!minimize)
5720    JUMPHERE(zerolength);    JUMPHERE(zerolength);
5721    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5722    
5723    decrease_call_count(common);    count_match(common);
5724    return cc;    return cc;
5725    }    }
5726    
5727  allocate_stack(common, 2);  allocate_stack(common, ref ? 2 : 3);
5728    if (ref)
5729      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5730  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5731  if (type != OP_CRMINSTAR)  if (type != OP_CRMINSTAR)
5732    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5733    
5734  if (min == 0)  if (min == 0)
5735    {    {
5736    zerolength = compile_ref_checks(common, ccbegin, NULL);    /* Handles both invalid and empty cases. Since the minimum repeat,
5737      is zero the invalid case is basically the same as an empty case. */
5738      if (ref)
5739        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5740      else
5741        {
5742        compile_dnref_search(common, ccbegin, NULL);
5743        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5744        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5745        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5746        }
5747      /* Length is non-zero, we can match real repeats. */
5748    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5749    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
5750    }    }
5751  else  else
5752    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);    {
5753      if (ref)
5754        {
5755        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5756        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5757        }
5758      else
5759        {
5760        compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5761        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5762        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5763        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5764        }
5765      }
5766    
5767  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5768  if (max > 0)  if (max > 0)
5769    add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, max));    add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, max));
5770    
5771    if (!ref)
5772      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
5773  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);
5774  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5775    
# Line 4990  if (jump != NULL) Line 5787  if (jump != NULL)
5787    JUMPHERE(jump);    JUMPHERE(jump);
5788  JUMPHERE(zerolength);  JUMPHERE(zerolength);
5789    
5790  decrease_call_count(common);  count_match(common);
5791  return cc;  return cc;
5792  }  }
5793    
# Line 5000  DEFINE_COMPILER; Line 5797  DEFINE_COMPILER;
5797  backtrack_common *backtrack;  backtrack_common *backtrack;
5798  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5799  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5800  int start = GET(cc, 1);  sljit_sw start = GET(cc, 1);
5801    pcre_uchar *start_cc;
5802    BOOL needs_control_head;
5803    
5804  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5805    
5806    /* Inlining simple patterns. */
5807    if (get_framesize(common, common->start + start, NULL, TRUE, &needs_control_head) == no_stack)
5808      {
5809      start_cc = common->start + start;
5810      compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
5811      BACKTRACK_AS(recurse_backtrack)->inlined_pattern = TRUE;
5812      return cc + 1 + LINK_SIZE;
5813      }
5814    
5815  while (entry != NULL)  while (entry != NULL)
5816    {    {
5817    if (entry->start == start)    if (entry->start == start)
# Line 5051  add_jump(compiler, &backtrack->topbacktr Line 5860  add_jump(compiler, &backtrack->topbacktr
5860  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5861  }  }
5862    
5863    static int SLJIT_CALL do_callout(struct jit_arguments* arguments, PUBL(callout_block) *callout_block, pcre_uchar **jit_ovector)
5864    {
5865    const pcre_uchar *begin = arguments->begin;
5866    int *offset_vector = arguments->offsets;
5867    int offset_count = arguments->offset_count;
5868    int i;
5869    
5870    if (PUBL(callout) == NULL)
5871      return 0;
5872    
5873    callout_block->version = 2;
5874    callout_block->callout_data = arguments->callout_data;
5875    
5876    /* Offsets in subject. */
5877    callout_block->subject_length = arguments->end - arguments->begin;
5878    callout_block->start_match = (pcre_uchar*)callout_block->subject - arguments->begin;
5879    callout_block->current_position = (pcre_uchar*)callout_block->offset_vector - arguments->begin;
5880    #if defined COMPILE_PCRE8
5881    callout_block->subject = (PCRE_SPTR)begin;
5882    #elif defined COMPILE_PCRE16
5883    callout_block->subject = (PCRE_SPTR16)begin;
5884    #elif defined COMPILE_PCRE32
5885    callout_block->subject = (PCRE_SPTR32)begin;
5886    #endif
5887    
5888    /* Convert and copy the JIT offset vector to the offset_vector array. */
5889    callout_block->capture_top = 0;
5890    callout_block->offset_vector = offset_vector;
5891    for (i = 2; i < offset_count; i += 2)
5892      {
5893      offset_vector[i] = jit_ovector[i] - begin;
5894      offset_vector[i + 1] = jit_ovector[i + 1] - begin;
5895      if (jit_ovector[i] >= begin)
5896        callout_block->capture_top = i;
5897      }
5898    
5899    callout_block->capture_top = (callout_block->capture_top >> 1) + 1;
5900    if (offset_count > 0)
5901      offset_vector[0] = -1;
5902    if (offset_count > 1)
5903      offset_vector[1] = -1;
5904    return (*PUBL(callout))(callout_block);
5905    }
5906    
5907    /* Aligning to 8 byte. */
5908    #define CALLOUT_ARG_SIZE \
5909        (((int)sizeof(PUBL(callout_block)) + 7) & ~7)
5910    
5911    #define CALLOUT_ARG_OFFSET(arg) \
5912        (-CALLOUT_ARG_SIZE + SLJIT_OFFSETOF(PUBL(callout_block), arg))
5913    
5914    static SLJIT_INLINE pcre_uchar *compile_callout_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5915    {
5916    DEFINE_COMPILER;
5917    backtrack_common *backtrack;
5918    
5919    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
5920    
5921    allocate_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5922    
5923    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
5924    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
5925    SLJIT_ASSERT(common->capture_last_ptr != 0);
5926    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);
5927    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);
5928    
5929    /* These pointer sized fields temporarly stores internal variables. */
5930    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
5931    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(offset_vector), STR_PTR, 0);
5932    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(subject), TMP2, 0);
5933    
5934    if (common->mark_ptr != 0)
5935      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr));
5936    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 2));
5937    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 2 + LINK_SIZE));
5938    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);
5939    
5940    /* Needed to save important temporary registers. */
5941    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5942    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, STACK_TOP, 0, SLJIT_IMM, CALLOUT_ARG_SIZE);
5943    GET_LOCAL_BASE(SLJIT_SCRATCH_REG3, 0, OVECTOR_START);
5944    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_callout));
5945    OP1(SLJIT_MOV_SI, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0);
5946    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5947    free_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5948    
5949    /* Check return value. */
5950    OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
5951    add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_C_SIG_GREATER));
5952    if (common->forced_quit_label == NULL)
5953      add_jump(compiler, &common->forced_quit, JUMP(SLJIT_C_SIG_LESS));
5954    else
5955      JUMPTO(SLJIT_C_SIG_LESS, common->forced_quit_label);
5956    return cc + 2 + 2 * LINK_SIZE;
5957    }
5958    
5959    #undef CALLOUT_ARG_SIZE
5960    #undef CALLOUT_ARG_OFFSET
5961    
5962  static pcre_uchar *compile_assert_matchingpath(compiler_common *common, pcre_uchar *cc, assert_backtrack *backtrack, BOOL conditional)  static pcre_uchar *compile_assert_matchingpath(compiler_common *common, pcre_uchar *cc, assert_backtrack *backtrack, BOOL conditional)
5963  {  {
5964  DEFINE_COMPILER;  DEFINE_COMPILER;
5965  int framesize;  int framesize;
5966    int extrasize;
5967    BOOL needs_control_head;
5968  int private_data_ptr;  int private_data_ptr;
5969  backtrack_common altbacktrack;  backtrack_common altbacktrack;
5970  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
# Line 5064  jump_list *tmp = NULL; Line 5974  jump_list *tmp = NULL;
5974  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5975  jump_list **found;  jump_list **found;
5976  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5977  struct sljit_label *save_quitlabel = common->quitlabel;  BOOL save_local_exit = common->local_exit;
5978  struct sljit_label *save_acceptlabel = common->acceptlabel;  BOOL save_positive_assert = common->positive_assert;
5979    then_trap_backtrack *save_then_trap = common->then_trap;
5980    struct sljit_label *save_quit_label = common->quit_label;
5981    struct sljit_label *save_accept_label = common->accept_label;
5982  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
5983    jump_list *save_positive_assert_quit = common->positive_assert_quit;
5984  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
5985  struct sljit_jump *jump;  struct sljit_jump *jump;
5986  struct sljit_jump *brajump = NULL;  struct sljit_jump *brajump = NULL;
5987    
5988    /* Assert captures then. */
5989    common->then_trap = NULL;
5990    
5991  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
5992    {    {
5993    SLJIT_ASSERT(!conditional);    SLJIT_ASSERT(!conditional);
# Line 5079  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 5996  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
5996    }    }
5997  private_data_ptr = PRIVATE_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
5998  SLJIT_ASSERT(private_data_ptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
5999  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
6000  backtrack->framesize = framesize;  backtrack->framesize = framesize;
6001  backtrack->private_data_ptr = private_data_ptr;  backtrack->private_data_ptr = private_data_ptr;
6002  opcode = *cc;  opcode = *cc;
# Line 5098  if (bra == OP_BRAMINZERO) Line 6015  if (bra == OP_BRAMINZERO)
6015    
6016  if (framesize < 0)  if (framesize < 0)
6017    {    {
6018    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    extrasize = needs_control_head ? 2 : 1;
6019    allocate_stack(common, 1);    if (framesize == no_frame)
6020        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6021      allocate_stack(common, extrasize);
6022      if (needs_control_head)
6023        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6024    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6025      if (needs_control_head)
6026        {
6027        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
6028        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
6029        }
6030    }    }
6031  else  else
6032    {    {
6033    allocate_stack(common, framesize + 2);    extrasize = needs_control_head ? 3 : 2;
6034      allocate_stack(common, framesize + extrasize);
6035    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6036    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(framesize + 1));    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
6037    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);
6038      if (needs_control_head)
6039        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6040    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6041    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    if (needs_control_head)
6042    init_frame(common, ccbegin, framesize + 1, 2, FALSE);      {
6043        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
6044        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6045        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
6046        }
6047      else
6048        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
6049      init_frame(common, ccbegin, NULL, framesize + extrasize - 1, extrasize, FALSE);
6050    }    }
6051    
6052  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
6053  common->quitlabel = NULL;  if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6054  common->quit = NULL;    {
6055      /* Negative assert is stronger than positive assert. */
6056      common->local_exit = TRUE;
6057      common->quit_label = NULL;
6058      common->quit = NULL;
6059      common->positive_assert = FALSE;
6060      }
6061    else
6062      common->positive_assert = TRUE;
6063    common->positive_assert_quit = NULL;
6064    
6065  while (1)  while (1)
6066    {    {
6067    common->acceptlabel = NULL;    common->accept_label = NULL;
6068    common->accept = NULL;    common->accept = NULL;
6069    altbacktrack.top = NULL;    altbacktrack.top = NULL;
6070    altbacktrack.topbacktracks = NULL;    altbacktrack.topbacktracks = NULL;
# Line 5130  while (1) Line 6076  while (1)
6076    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
6077    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
6078      {      {
6079      common->quitlabel = save_quitlabel;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6080      common->acceptlabel = save_acceptlabel;        {
6081      common->quit = save_quit;        common->local_exit = save_local_exit;
6082          common->quit_label = save_quit_label;
6083          common->quit = save_quit;
6084          }
6085        common->positive_assert = save_positive_assert;
6086        common->then_trap = save_then_trap;
6087        common->accept_label = save_accept_label;
6088        common->positive_assert_quit = save_positive_assert_quit;
6089      common->accept = save_accept;      common->accept = save_accept;
6090      return NULL;      return NULL;
6091      }      }
6092    common->acceptlabel = LABEL();    common->accept_label = LABEL();
6093    if (common->accept != NULL)    if (common->accept != NULL)
6094      set_jumps(common->accept, common->acceptlabel);      set_jumps(common->accept, common->accept_label);
6095    
6096    /* Reset stack. */    /* Reset stack. */
6097    if (framesize < 0)    if (framesize < 0)
6098      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      {
6099    else {      if (framesize == no_frame)
6100          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6101        else
6102          free_stack(common, extrasize);
6103        if (needs_control_head)
6104          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
6105        }
6106      else
6107        {
6108      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)
6109        {        {
6110        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
6111        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));
6112          if (needs_control_head)
6113            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
6114        }        }
6115      else      else
6116        {        {
6117        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6118          if (needs_control_head)
6119            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));
6120        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
6121        }        }
6122    }      }
6123    
6124    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6125      {      {
6126      /* We know that STR_PTR was stored on the top of the stack. */      /* We know that STR_PTR was stored on the top of the stack. */
6127      if (conditional)      if (conditional)
6128        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), needs_control_head ? sizeof(sljit_sw) : 0);
6129      else if (bra == OP_BRAZERO)      else if (bra == OP_BRAZERO)
6130        {        {
6131        if (framesize < 0)        if (framesize < 0)
6132          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 1) * sizeof(sljit_sw));
6133        else        else
6134          {          {
6135          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));
6136          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (framesize + extrasize - 1) * sizeof(sljit_sw));
6137          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
6138          }          }
6139        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
# Line 5185  while (1) Line 6150  while (1)
6150    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
6151    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
6152      {      {
6153      common->quitlabel = save_quitlabel;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6154      common->acceptlabel = save_acceptlabel;        {
6155      common->quit = save_quit;        common->local_exit = save_local_exit;
6156          common->quit_label = save_quit_label;
6157          common->quit = save_quit;
6158          }
6159        common->positive_assert = save_positive_assert;
6160        common->then_trap = save_then_trap;
6161        common->accept_label = save_accept_label;
6162        common->positive_assert_quit = save_positive_assert_quit;
6163      common->accept = save_accept;      common->accept = save_accept;
6164      return NULL;      return NULL;
6165      }      }
# Line 5199  while (1) Line 6171  while (1)
6171    ccbegin = cc;    ccbegin = cc;
6172    cc += GET(cc, 1);    cc += GET(cc, 1);
6173    }    }
6174    
6175    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6176      {
6177      SLJIT_ASSERT(common->positive_assert_quit == NULL);
6178      /* Makes the check less complicated below. */
6179      common->positive_assert_quit = common->quit;
6180      }
6181    
6182  /* None of them matched. */  /* None of them matched. */
6183  if (common->quit != NULL)  if (common->positive_assert_quit != NULL)
6184    set_jumps(common->quit, LABEL());    {
6185      jump = JUMP(SLJIT_JUMP);
6186      set_jumps(common->positive_assert_quit, LABEL());
6187      SLJIT_ASSERT(framesize != no_stack);
6188      if (framesize < 0)
6189        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));
6190      else
6191        {
6192        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6193        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
6194        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
6195        }
6196      JUMPHERE(jump);
6197      }
6198    
6199    if (needs_control_head)
6200      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(1));
6201    
6202  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)
6203    {    {
# Line 5213  if (opcode == OP_ASSERT || opcode == OP_ Line 6209  if (opcode == OP_ASSERT || opcode == OP_
6209      {      {
6210      /* The topmost item should be 0. */      /* The topmost item should be 0. */
6211      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
6212          {
6213          if (extrasize == 2)
6214            free_stack(common, 1);
6215        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6216          }
6217      else      else
6218        free_stack(common, 1);        free_stack(common, extrasize);
6219      }      }
6220    else    else
6221      {      {
6222      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
6223      /* The topmost item should be 0. */      /* The topmost item should be 0. */
6224      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
6225        {        {
6226        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
6227        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6228        }        }
6229      else      else
6230        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
6231      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
6232      }      }
6233    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
# Line 5239  if (opcode == OP_ASSERT || opcode == OP_ Line 6239  if (opcode == OP_ASSERT || opcode == OP_
6239    if (framesize < 0)    if (framesize < 0)
6240      {      {
6241      /* We know that STR_PTR was stored on the top of the stack. */      /* We know that STR_PTR was stored on the top of the stack. */
6242      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 1) * sizeof(sljit_sw));
6243      /* Keep the STR_PTR on the top of the stack. */      /* Keep the STR_PTR on the top of the stack. */
6244      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
6245          {
6246        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
6247          if (extrasize == 2)
6248            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6249          }
6250      else if (bra == OP_BRAMINZERO)      else if (bra == OP_BRAMINZERO)
6251        {        {
6252        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
# Line 5255  if (opcode == OP_ASSERT || opcode == OP_ Line 6259  if (opcode == OP_ASSERT || opcode == OP_
6259        {        {
6260        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
6261        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));
6262        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 2) * sizeof(sljit_sw));
6263        }        }
6264      else      else
6265        {        {
6266        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
6267        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 2) * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 2) * sizeof(sljit_sw));
6268        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        if (extrasize == 2)
6269        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);          {
6270            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6271            if (bra == OP_BRAMINZERO)
6272              OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6273            }
6274          else
6275            {
6276            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
6277            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);
6278            }
6279        }        }
6280      }      }
6281    
6282    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
6283      {      {
6284      backtrack->matchingpath = LABEL();      backtrack->matchingpath = LABEL();
6285      sljit_set_label(jump, backtrack->matchingpath);      SET_LABEL(jump, backtrack->matchingpath);
6286      }      }
6287    else if (bra == OP_BRAMINZERO)    else if (bra == OP_BRAMINZERO)
6288      {      {
# Line 5291  else Line 6304  else
6304      {      {
6305      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6306      if (bra != OP_BRA)      if (bra != OP_BRA)
6307          {
6308          if (extrasize == 2)
6309            free_stack(common, 1);
6310        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6311          }
6312      else      else
6313        free_stack(common, 1);        free_stack(common, extrasize);
6314      }      }
6315    else    else
6316      {      {
6317      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6318      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
6319      /* The topmost item should be 0. */      /* The topmost item should be 0. */
6320      if (bra != OP_BRA)      if (bra != OP_BRA)
6321        {        {
6322        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
6323        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6324        }        }
6325      else      else
6326        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
6327      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
6328      }      }
6329    
# Line 5326  else Line 6343  else
6343      }      }
6344    }    }
6345    
6346  common->quitlabel = save_quitlabel;  if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
6347  common->acceptlabel = save_acceptlabel;    {
6348  common->quit = save_quit;    common->local_exit = save_local_exit;
6349      common->quit_label = save_quit_label;
6350      common->quit = save_quit;
6351      }
6352    common->positive_assert = save_positive_assert;
6353    common->then_trap = save_then_trap;
6354    common->accept_label = save_accept_label;
6355    common->positive_assert_quit = save_positive_assert_quit;
6356  common->accept = save_accept;  common->accept = save_accept;
6357  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
6358  }  }
6359    
6360  static sljit_sw SLJIT_CALL do_searchovector(sljit_uw refno, sljit_sw* locals, pcre_uchar *name_table)  static SLJIT_INLINE void match_once_common(compiler_common *common, pcre_uchar ket, int framesize, int private_data_ptr, BOOL has_alternatives, BOOL needs_control_head)
6361  {  {
6362  int condition = FALSE;  DEFINE_COMPILER;
6363  pcre_uchar *slotA = name_table;  int stacksize;
 pcre_uchar *slotB;  
 sljit_sw name_count = locals[LOCALS0 / sizeof(sljit_sw)];  
 sljit_sw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];  
 sljit_sw no_capture;  
 int i;  
   
 locals += refno & 0xff;  
 refno >>= 8;  
 no_capture = locals[1];  
6364    
6365  for (i = 0; i < name_count; i++)  if (framesize < 0)
6366    {    {
6367    if (GET2(slotA, 0) == refno) break;    if (framesize == no_frame)
6368    slotA += name_entry_size;      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6369    }    else
6370        {
6371        stacksize = needs_control_head ? 1 : 0;
6372        if (ket != OP_KET || has_alternatives)
6373