/[pcre]/code/trunk/pcre_jit_compile.c
ViewVC logotype

Diff of /code/trunk/pcre_jit_compile.c

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

revision 1239 by zherczeg, Fri Jan 18 08:20:44 2013 UTC revision 1277 by zherczeg, Mon Mar 11 09:50:29 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;    int real_offset_count;
172    int calllimit;    int offset_count;
173      int call_limit;
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 179  typedef struct jump_list { Line 190  typedef struct jump_list {
190    struct jump_list *next;    struct jump_list *next;
191  } jump_list;  } jump_list;
192    
 enum stub_types { stack_alloc };  
   
193  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
194    struct sljit_jump *start;    struct sljit_jump *start;
195    struct sljit_label *quit;    struct sljit_label *quit;
196    struct stub_list *next;    struct stub_list *next;
197  } stub_list;  } stub_list;
198    
199    enum frame_types {
200      no_frame = -1,
201      no_stack = -2
202    };
203    
204    enum control_types {
205      type_commit = 0,
206      type_prune = 1,
207      type_skip = 2
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
# 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 270  typedef struct recurse_entry { Line 288  typedef struct 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 MAX_RANGE_SIZE 6
295    
296  typedef struct compiler_common {  typedef struct compiler_common {
297      /* The sljit ceneric compiler. */
298    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
299      /* First byte code. */
300    pcre_uchar *start;    pcre_uchar *start;
   
301    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
302    int *private_data_ptrs;    int *private_data_ptrs;
303    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
304    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
305    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
306    int cbraptr;    int cbra_ptr;
307    /* OVector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
308    int ovector_start;    int ovector_start;
309    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
310    int req_char_ptr;    int req_char_ptr;
311    /* Head of the last recursion. */    /* Head of the last recursion. */
312    int recursive_head;    int recursive_head_ptr;
313    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
314    int start_used_ptr;    int start_used_ptr;
315    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 298  typedef struct compiler_common { Line 318  typedef struct compiler_common {
318    int first_line_end;    int first_line_end;
319    /* Points to the marked string. */    /* Points to the marked string. */
320    int mark_ptr;    int mark_ptr;
321      /* Recursive control verb management chain. */
322      int control_head_ptr;
323      /* Points to the last matched capture block index. */
324      int capture_last_ptr;
325      /* Points to the starting position of the current match. */
326      int start_ptr;
327    
328    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
329    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
330    sljit_sw lcc;    sljit_sw lcc;
331    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
332    int mode;    int mode;
333      /* \K is in the pattern. */
334      BOOL has_set_som;
335      /* Needs to know the start position anytime. */
336      BOOL needs_start_ptr;
337      /* Currently in recurse or assert. */
338      BOOL local_exit;
339    /* Newline control. */    /* Newline control. */
340    int nltype;    int nltype;
341    int newline;    int newline;
342    int bsr_nltype;    int bsr_nltype;
343    /* Dollar endonly. */    /* Dollar endonly. */
344    int endonly;    int endonly;
   BOOL has_set_som;  
345    /* Tables. */    /* Tables. */
346    sljit_sw ctypes;    sljit_sw ctypes;
347    int digits[2 + MAX_RANGE_SIZE];    int digits[2 + MAX_RANGE_SIZE];
# Line 321  typedef struct compiler_common { Line 352  typedef struct compiler_common {
352    
353    /* Labels and jump lists. */    /* Labels and jump lists. */
354    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
355    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
356    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
357      struct sljit_label *accept_label;
358    stub_list *stubs;    stub_list *stubs;
359    recurse_entry *entries;    recurse_entry *entries;
360    recurse_entry *currententry;    recurse_entry *currententry;
361    jump_list *partialmatch;    jump_list *partialmatch;
362    jump_list *quit;    jump_list *quit;
363      jump_list *forced_quit;
364    jump_list *accept;    jump_list *accept;
365    jump_list *calllimit;    jump_list *calllimit;
366    jump_list *stackalloc;    jump_list *stackalloc;
# Line 338  typedef struct compiler_common { Line 371  typedef struct compiler_common {
371    jump_list *vspace;    jump_list *vspace;
372    jump_list *casefulcmp;    jump_list *casefulcmp;
373    jump_list *caselesscmp;    jump_list *caselesscmp;
374      jump_list *reset_match;
375    BOOL jscript_compat;    BOOL jscript_compat;
376  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
377    BOOL utf;    BOOL utf;
# Line 390  typedef struct compare_context { Line 424  typedef struct compare_context {
424  #endif  #endif
425  } compare_context;  } compare_context;
426    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
427  /* Undefine sljit macros. */  /* Undefine sljit macros. */
428  #undef CMP  #undef CMP
429    
# Line 428  group contains the start / end character Line 456  group contains the start / end character
456  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. */
457  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
458  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
459  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_sw))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * sizeof(sljit_sw))
460  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
461    
462  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
# Line 459  the start pointers when the end of the c Line 487  the start pointers when the end of the c
487    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
488  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
489    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
490    #define SET_LABEL(jump, label) \
491      sljit_set_label((jump), (label))
492  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
493    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
494  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
# Line 483  return cc; Line 513  return cc;
513   set_private_data_ptrs   set_private_data_ptrs
514   get_framesize   get_framesize
515   init_frame   init_frame
516   get_private_data_length_for_copy   get_private_data_copy_length
517   copy_private_data   copy_private_data
518   compile_matchingpath   compile_matchingpath
519   compile_backtrackingpath   compile_backtrackingpath
# Line 507  switch(*cc) Line 537  switch(*cc)
537    case OP_WORDCHAR:    case OP_WORDCHAR:
538    case OP_ANY:    case OP_ANY:
539    case OP_ALLANY:    case OP_ALLANY:
540      case OP_NOTPROP:
541      case OP_PROP:
542    case OP_ANYNL:    case OP_ANYNL:
543    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
544    case OP_HSPACE:    case OP_HSPACE:
# Line 519  switch(*cc) Line 551  switch(*cc)
551    case OP_CIRCM:    case OP_CIRCM:
552    case OP_DOLL:    case OP_DOLL:
553    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:  
554    case OP_CRSTAR:    case OP_CRSTAR:
555    case OP_CRMINSTAR:    case OP_CRMINSTAR:
556    case OP_CRPLUS:    case OP_CRPLUS:
557    case OP_CRMINPLUS:    case OP_CRMINPLUS:
558    case OP_CRQUERY:    case OP_CRQUERY:
559    case OP_CRMINQUERY:    case OP_CRMINQUERY:
560      case OP_CRRANGE:
561      case OP_CRMINRANGE:
562      case OP_CLASS:
563      case OP_NCLASS:
564      case OP_REF:
565      case OP_REFI:
566      case OP_RECURSE:
567      case OP_CALLOUT:
568      case OP_ALT:
569      case OP_KET:
570      case OP_KETRMAX:
571      case OP_KETRMIN:
572      case OP_KETRPOS:
573      case OP_REVERSE:
574      case OP_ASSERT:
575      case OP_ASSERT_NOT:
576      case OP_ASSERTBACK:
577      case OP_ASSERTBACK_NOT:
578      case OP_ONCE:
579      case OP_ONCE_NC:
580      case OP_BRA:
581      case OP_BRAPOS:
582      case OP_CBRA:
583      case OP_CBRAPOS:
584      case OP_COND:
585      case OP_SBRA:
586      case OP_SBRAPOS:
587      case OP_SCBRA:
588      case OP_SCBRAPOS:
589      case OP_SCOND:
590      case OP_CREF:
591      case OP_NCREF:
592      case OP_RREF:
593      case OP_NRREF:
594    case OP_DEF:    case OP_DEF:
595    case OP_BRAZERO:    case OP_BRAZERO:
596    case OP_BRAMINZERO:    case OP_BRAMINZERO:
597    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
598      case OP_PRUNE:
599      case OP_SKIP:
600    case OP_COMMIT:    case OP_COMMIT:
601    case OP_FAIL:    case OP_FAIL:
602    case OP_ACCEPT:    case OP_ACCEPT:
603    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
604      case OP_CLOSE:
605    case OP_SKIPZERO:    case OP_SKIPZERO:
606    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
607    
608    case OP_CHAR:    case OP_CHAR:
609    case OP_CHARI:    case OP_CHARI:
# Line 561  switch(*cc) Line 615  switch(*cc)
615    case OP_MINPLUS:    case OP_MINPLUS:
616    case OP_QUERY:    case OP_QUERY:
617    case OP_MINQUERY:    case OP_MINQUERY:
618      case OP_UPTO:
619      case OP_MINUPTO:
620      case OP_EXACT:
621    case OP_POSSTAR:    case OP_POSSTAR:
622    case OP_POSPLUS:    case OP_POSPLUS:
623    case OP_POSQUERY:    case OP_POSQUERY:
624      case OP_POSUPTO:
625    case OP_STARI:    case OP_STARI:
626    case OP_MINSTARI:    case OP_MINSTARI:
627    case OP_PLUSI:    case OP_PLUSI:
628    case OP_MINPLUSI:    case OP_MINPLUSI:
629    case OP_QUERYI:    case OP_QUERYI:
630    case OP_MINQUERYI:    case OP_MINQUERYI:
631      case OP_UPTOI:
632      case OP_MINUPTOI:
633      case OP_EXACTI:
634    case OP_POSSTARI:    case OP_POSSTARI:
635    case OP_POSPLUSI:    case OP_POSPLUSI:
636    case OP_POSQUERYI:    case OP_POSQUERYI:
637      case OP_POSUPTOI:
638    case OP_NOTSTAR:    case OP_NOTSTAR:
639    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
640    case OP_NOTPLUS:    case OP_NOTPLUS:
641    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
642    case OP_NOTQUERY:    case OP_NOTQUERY:
643    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
644      case OP_NOTUPTO:
645      case OP_NOTMINUPTO:
646      case OP_NOTEXACT:
647    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
648    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
649    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
650      case OP_NOTPOSUPTO:
651    case OP_NOTSTARI:    case OP_NOTSTARI:
652    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
653    case OP_NOTPLUSI:    case OP_NOTPLUSI:
654    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
655    case OP_NOTQUERYI:    case OP_NOTQUERYI:
656    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:  
657    case OP_NOTUPTOI:    case OP_NOTUPTOI:
658    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
659    case OP_NOTEXACTI:    case OP_NOTEXACTI:
660      case OP_NOTPOSSTARI:
661      case OP_NOTPOSPLUSI:
662      case OP_NOTPOSQUERYI:
663    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
664    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
665  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
666    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
667  #endif  #endif
668    return cc;    return cc;
669    
670    case OP_NOTPROP:    /* Special cases. */
671    case OP_PROP:    case OP_TYPESTAR:
672    return cc + 1 + 2;    case OP_TYPEMINSTAR:
673      case OP_TYPEPLUS:
674      case OP_TYPEMINPLUS:
675      case OP_TYPEQUERY:
676      case OP_TYPEMINQUERY:
677    case OP_TYPEUPTO:    case OP_TYPEUPTO:
678    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
679    case OP_TYPEEXACT:    case OP_TYPEEXACT:
680      case OP_TYPEPOSSTAR:
681      case OP_TYPEPOSPLUS:
682      case OP_TYPEPOSQUERY:
683    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
684    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;  
685    
686    case OP_CLASS:    case OP_ANYBYTE:
687    case OP_NCLASS:  #ifdef SUPPORT_UTF
688    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
689    #endif
690      return cc + 1;
691    
692  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
693    case OP_XCLASS:    case OP_XCLASS:
694    return cc + GET(cc, 1);    return cc + GET(cc, 1);
695  #endif  #endif
696    
   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;  
   
697    case OP_MARK:    case OP_MARK:
698      case OP_PRUNE_ARG:
699    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
700    
701    default:    default:
# Line 812  while (cc < ccend) Line 830  while (cc < ccend)
830    
831      case OP_COND:      case OP_COND:
832      case OP_SCOND:      case OP_SCOND:
833      bracketlen = cc[1 + LINK_SIZE];      /* Only AUTO_CALLOUT can insert this opcode. We do
834      if (bracketlen == OP_CREF)         not intend to support this case. */
835        {      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
836        bracketlen = GET2(cc, 1 + LINK_SIZE + 1);        return -1;
       common->optimized_cbracket[bracketlen] = 0;  
       }  
     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;  
         }  
       }  
837    
838      if (*cc == OP_COND)      if (*cc == OP_COND)
839        {        {
# Line 850  while (cc < ccend) Line 847  while (cc < ccend)
847      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
848      break;      break;
849    
850        case OP_CREF:
851        i = GET2(cc, 1);
852        common->optimized_cbracket[i] = 0;
853        cc += 1 + IMM2_SIZE;
854        break;
855    
856        case OP_NCREF:
857        bracketlen = GET2(cc, 1);
858        name = (pcre_uchar *)common->name_table;
859        alternative = name;
860        for (i = 0; i < common->name_count; i++)
861          {
862          if (GET2(name, 0) == bracketlen) break;
863          name += common->name_entry_size;
864          }
865        SLJIT_ASSERT(i != common->name_count);
866    
867        for (i = 0; i < common->name_count; i++)
868          {
869          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
870            common->optimized_cbracket[GET2(alternative, 0)] = 0;
871          alternative += common->name_entry_size;
872          }
873        bracketlen = 0;
874        cc += 1 + IMM2_SIZE;
875        break;
876    
877      case OP_BRA:      case OP_BRA:
878      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
879      break;      break;
# Line 906  while (cc < ccend) Line 930  while (cc < ccend)
930    
931      case OP_RECURSE:      case OP_RECURSE:
932      /* Set its value only once. */      /* Set its value only once. */
933      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
934        {        {
935        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
936        common->ovector_start += sizeof(sljit_sw);        common->ovector_start += sizeof(sljit_sw);
937        }        }
938      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
939      break;      break;
940    
941        case OP_CALLOUT:
942        if (common->capture_last_ptr == 0)
943          {
944          common->capture_last_ptr = common->ovector_start;
945          common->ovector_start += sizeof(sljit_sw);
946          }
947        cc += 2 + 2 * LINK_SIZE;
948        break;
949    
950        case OP_PRUNE_ARG:
951        common->needs_start_ptr = TRUE;
952        common->control_head_ptr = 1;
953        /* Fall through. */
954    
955      case OP_MARK:      case OP_MARK:
956      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
957        {        {
# Line 923  while (cc < ccend) Line 961  while (cc < ccend)
961      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
962      break;      break;
963    
964        case OP_PRUNE:
965        case OP_SKIP:
966        common->needs_start_ptr = TRUE;
967        /* Fall through. */
968    
969        case OP_COMMIT:
970        common->control_head_ptr = 1;
971        cc += 1;
972        break;
973    
974      default:      default:
975      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
976      if (cc == NULL)      if (cc == NULL)
# Line 1099  while (cc < ccend) Line 1147  while (cc < ccend)
1147    }    }
1148  }  }
1149    
1150  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1151  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive, BOOL* needs_control_head)
1152  {  {
1153  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1154  int length = 0;  int length = 0;
1155  BOOL possessive = FALSE;  int possessive = 0;
1156    BOOL stack_restore = FALSE;
1157  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1158  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1159    /* The last capture is a local variable even for recursions. */
1160    BOOL capture_last_found = FALSE;
1161    
1162    #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1163    SLJIT_ASSERT(common->control_head_ptr != 0);
1164    *needs_control_head = TRUE;
1165    #else
1166    *needs_control_head = FALSE;
1167    #endif
1168    
1169  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1170    {    {
1171    length = 3;    possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1172    possessive = TRUE;    /* This is correct regardless of common->capture_last_ptr. */
1173      capture_last_found = TRUE;
1174    }    }
1175    
1176  cc = next_opcode(common, cc);  cc = next_opcode(common, cc);
# Line 1121  while (cc < ccend) Line 1180  while (cc < ccend)
1180      {      {
1181      case OP_SET_SOM:      case OP_SET_SOM:
1182      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1183        stack_restore = TRUE;
1184      if (!setsom_found)      if (!setsom_found)
1185        {        {
1186        length += 2;        length += 2;
# Line 1130  while (cc < ccend) Line 1190  while (cc < ccend)
1190      break;      break;
1191    
1192      case OP_MARK:      case OP_MARK:
1193        case OP_PRUNE_ARG:
1194      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1195        stack_restore = TRUE;
1196      if (!setmark_found)      if (!setmark_found)
1197        {        {
1198        length += 2;        length += 2;
1199        setmark_found = TRUE;        setmark_found = TRUE;
1200        }        }
1201        if (common->control_head_ptr != 0)
1202          *needs_control_head = TRUE;
1203      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1204      break;      break;
1205    
1206      case OP_RECURSE:      case OP_RECURSE:
1207        stack_restore = TRUE;
1208      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1209        {        {
1210        length += 2;        length += 2;
# Line 1150  while (cc < ccend) Line 1215  while (cc < ccend)
1215        length += 2;        length += 2;
1216        setmark_found = TRUE;        setmark_found = TRUE;
1217        }        }
1218        if (common->capture_last_ptr != 0 && !capture_last_found)
1219          {
1220          length += 2;
1221          capture_last_found = TRUE;
1222          }
1223      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1224      break;      break;
1225    
# Line 1157  while (cc < ccend) Line 1227  while (cc < ccend)
1227      case OP_CBRAPOS:      case OP_CBRAPOS:
1228      case OP_SCBRA:      case OP_SCBRA:
1229      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1230        stack_restore = TRUE;
1231        if (common->capture_last_ptr != 0 && !capture_last_found)
1232          {
1233          length += 2;
1234          capture_last_found = TRUE;
1235          }
1236      length += 3;      length += 3;
1237      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1238      break;      break;
1239    
1240        case OP_PRUNE:
1241        case OP_SKIP:
1242        case OP_COMMIT:
1243        if (common->control_head_ptr != 0)
1244          *needs_control_head = TRUE;
1245        /* Fall through. */
1246    
1247      default:      default:
1248        stack_restore = TRUE;
1249        /* Fall through. */
1250    
1251        case OP_NOT_WORD_BOUNDARY:
1252        case OP_WORD_BOUNDARY:
1253        case OP_NOT_DIGIT:
1254        case OP_DIGIT:
1255        case OP_NOT_WHITESPACE:
1256        case OP_WHITESPACE:
1257        case OP_NOT_WORDCHAR:
1258        case OP_WORDCHAR:
1259        case OP_ANY:
1260        case OP_ALLANY:
1261        case OP_ANYBYTE:
1262        case OP_NOTPROP:
1263        case OP_PROP:
1264        case OP_ANYNL:
1265        case OP_NOT_HSPACE:
1266        case OP_HSPACE:
1267        case OP_NOT_VSPACE:
1268        case OP_VSPACE:
1269        case OP_EXTUNI:
1270        case OP_EODN:
1271        case OP_EOD:
1272        case OP_CIRC:
1273        case OP_CIRCM:
1274        case OP_DOLL:
1275        case OP_DOLLM:
1276        case OP_CHAR:
1277        case OP_CHARI:
1278        case OP_NOT:
1279        case OP_NOTI:
1280    
1281        case OP_EXACT:
1282        case OP_POSSTAR:
1283        case OP_POSPLUS:
1284        case OP_POSQUERY:
1285        case OP_POSUPTO:
1286    
1287        case OP_EXACTI:
1288        case OP_POSSTARI:
1289        case OP_POSPLUSI:
1290        case OP_POSQUERYI:
1291        case OP_POSUPTOI:
1292    
1293        case OP_NOTEXACT:
1294        case OP_NOTPOSSTAR:
1295        case OP_NOTPOSPLUS:
1296        case OP_NOTPOSQUERY:
1297        case OP_NOTPOSUPTO:
1298    
1299        case OP_NOTEXACTI:
1300        case OP_NOTPOSSTARI:
1301        case OP_NOTPOSPLUSI:
1302        case OP_NOTPOSQUERYI:
1303        case OP_NOTPOSUPTOI:
1304    
1305        case OP_TYPEEXACT:
1306        case OP_TYPEPOSSTAR:
1307        case OP_TYPEPOSPLUS:
1308        case OP_TYPEPOSQUERY:
1309        case OP_TYPEPOSUPTO:
1310    
1311        case OP_CLASS:
1312        case OP_NCLASS:
1313        case OP_XCLASS:
1314    
1315      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1316      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1317      break;      break;
1318      }      }
1319    
1320  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1321  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1322    return -1;    return stack_restore ? no_frame : no_stack;
1323    
1324  if (length > 0)  if (length > 0)
1325    return length + 1;    return length + 1;
1326  return -1;  return stack_restore ? no_frame : no_stack;
1327  }  }
1328    
1329  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, int stackpos, int stacktop, BOOL recursive)
1330  {  {
1331  DEFINE_COMPILER;  DEFINE_COMPILER;
1332  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1333  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1334  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1335    /* The last capture is a local variable even for recursions. */
1336    BOOL capture_last_found = FALSE;
1337  int offset;  int offset;
1338    
1339  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1200  while (cc < ccend) Line 1352  while (cc < ccend)
1352      if (!setsom_found)      if (!setsom_found)
1353        {        {
1354        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1355        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1356        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1357        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1358        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1210  while (cc < ccend) Line 1362  while (cc < ccend)
1362      break;      break;
1363    
1364      case OP_MARK:      case OP_MARK:
1365        case OP_PRUNE_ARG:
1366      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1367      if (!setmark_found)      if (!setmark_found)
1368        {        {
1369        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);
1370        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);
1371        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1372        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1373        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1227  while (cc < ccend) Line 1380  while (cc < ccend)
1380      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1381        {        {
1382        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1383        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1384        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1385        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1386        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1236  while (cc < ccend) Line 1389  while (cc < ccend)
1389      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1390        {        {
1391        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);
1392        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);
1393        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1394        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1395        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1396        setmark_found = TRUE;        setmark_found = TRUE;
1397        }        }
1398        if (common->capture_last_ptr != 0 && !capture_last_found)
1399          {
1400          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1401          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1402          stackpos += (int)sizeof(sljit_sw);
1403          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1404          stackpos += (int)sizeof(sljit_sw);
1405          capture_last_found = TRUE;
1406          }
1407      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1408      break;      break;
1409    
# Line 1249  while (cc < ccend) Line 1411  while (cc < ccend)
1411      case OP_CBRAPOS:      case OP_CBRAPOS:
1412      case OP_SCBRA:      case OP_SCBRA:
1413      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1414        if (common->capture_last_ptr != 0 && !capture_last_found)
1415          {
1416          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1417          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1418          stackpos += (int)sizeof(sljit_sw);
1419          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1420          stackpos += (int)sizeof(sljit_sw);
1421          capture_last_found = TRUE;
1422          }
1423      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1424      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1425      stackpos += (int)sizeof(sljit_sw);      stackpos += (int)sizeof(sljit_sw);
# Line 1268  while (cc < ccend) Line 1439  while (cc < ccend)
1439      break;      break;
1440      }      }
1441    
1442  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1443  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1444  }  }
1445    
1446  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)
1447  {  {
1448  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1449  int size;  int size;
1450  pcre_uchar *alternative;  pcre_uchar *alternative;
1451  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1387  return private_data_length; Line 1558  return private_data_length;
1558  }  }
1559    
1560  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,
1561    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1562  {  {
1563  DEFINE_COMPILER;  DEFINE_COMPILER;
1564  int srcw[2];  int srcw[2];
# Line 1408  stacktop = STACK(stacktop - 1); Line 1579  stacktop = STACK(stacktop - 1);
1579    
1580  if (!save)  if (!save)
1581    {    {
1582    stackptr += sizeof(sljit_sw);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1583    if (stackptr < stacktop)    if (stackptr < stacktop)
1584      {      {
1585      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 1595  if (!save)
1595    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1596    }    }
1597    
1598  while (status != end)  do
1599    {    {
1600    count = 0;    count = 0;
1601    switch(status)    switch(status)
1602      {      {
1603      case start:      case start:
1604      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1605      count = 1;      count = 1;
1606      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1607        if (needs_control_head)
1608          {
1609          SLJIT_ASSERT(common->control_head_ptr != 0);
1610          count = 2;
1611          srcw[1] = common->control_head_ptr;
1612          }
1613      status = loop;      status = loop;
1614      break;      break;
1615    
# Line 1657  while (status != end) Line 1834  while (status != end)
1834        }        }
1835      }      }
1836    }    }
1837    while (status != end);
1838    
1839  if (save)  if (save)
1840    {    {
# Line 1708  while (list) Line 1886  while (list)
1886    {    {
1887    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1888    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
1889    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1890    list = list->next;    list = list->next;
1891    }    }
1892  }  }
# Line 1724  if (list_item) Line 1902  if (list_item)
1902    }    }
1903  }  }
1904    
1905  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)
1906  {  {
1907  DEFINE_COMPILER;  DEFINE_COMPILER;
1908  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1909    
1910  if (list_item)  if (list_item)
1911    {    {
   list_item->type = type;  
   list_item->data = data;  
1912    list_item->start = start;    list_item->start = start;
1913    list_item->quit = LABEL();    list_item->quit = LABEL();
1914    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1748  stub_list* list_item = common->stubs; Line 1924  stub_list* list_item = common->stubs;
1924  while (list_item)  while (list_item)
1925    {    {
1926    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
1927    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;  
     }  
1928    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
1929    list_item = list_item->next;    list_item = list_item->next;
1930    }    }
# Line 1781  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 1952  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
1952  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
1953  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
1954  #endif  #endif
1955  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));
1956  }  }
1957    
1958  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 1966  static SLJIT_INLINE void reset_ovector(c
1966  DEFINE_COMPILER;  DEFINE_COMPILER;
1967  struct sljit_label *loop;  struct sljit_label *loop;
1968  int i;  int i;
1969    
1970  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
1971    SLJIT_ASSERT(length > 1);
1972  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
1973  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));
1974  if (length < 8)  if (length < 8)
1975    {    {
1976    for (i = 0; i < length; i++)    for (i = 1; i < length; i++)
1977      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);
1978      }
1979    else
1980      {
1981      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
1982      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
1983      loop = LABEL();
1984      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
1985      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
1986      JUMPTO(SLJIT_C_NOT_ZERO, loop);
1987      }
1988    }
1989    
1990    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
1991    {
1992    DEFINE_COMPILER;
1993    struct sljit_label *loop;
1994    int i;
1995    
1996    SLJIT_ASSERT(length > 1);
1997    /* OVECTOR(1) contains the "string begin - 1" constant. */
1998    if (length > 2)
1999      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2000    if (length < 8)
2001      {
2002      for (i = 2; i < length; i++)
2003        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
2004    }    }
2005  else  else
2006    {    {
2007    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START - sizeof(sljit_sw));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2008    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2009    loop = LABEL();    loop = LABEL();
2010    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2011    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
2012    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2013    }    }
2014    
2015    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2016    if (common->mark_ptr != 0)
2017      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2018    SLJIT_ASSERT(common->control_head_ptr != 0);
2019    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2020    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2021    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2022    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2023    }
2024    
2025    static sljit_sw SLJIT_CALL do_check_control_chain(sljit_sw *current)
2026    {
2027    sljit_sw return_value = 0;
2028    
2029    SLJIT_ASSERT(current != NULL);
2030    do
2031      {
2032      switch (current[-2])
2033        {
2034        case type_commit:
2035        /* Commit overwrites all. */
2036        return -1;
2037    
2038        case type_prune:
2039        break;
2040    
2041        case type_skip:
2042        /* Overwrites prune, but not other skips. */
2043        if (return_value == 0)
2044          return_value = current[-3];
2045        break;
2046    
2047        default:
2048        SLJIT_ASSERT_STOP();
2049        break;
2050        }
2051      current = (sljit_sw*)current[-1];
2052      }
2053    while (current != NULL);
2054    return return_value;
2055  }  }
2056    
2057  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2058  {  {
2059  DEFINE_COMPILER;  DEFINE_COMPILER;
2060  struct sljit_label *loop;  struct sljit_label *loop;
2061  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2062    
2063  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2064  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 2067  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_R
2067  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2068  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2069    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);
2070  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));
2071  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2072    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);
2073  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));
2074  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));
2075  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2076  /* Unlikely, but possible */  /* Unlikely, but possible */
2077  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);
2078  loop = LABEL();  loop = LABEL();
2079  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);
2080  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 2085  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJ
2085  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);
2086  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);
2087  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2088  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2089    
2090  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2091  if (topbracket > 1)  if (topbracket > 1)
# Line 1867  else Line 2107  else
2107  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)
2108  {  {
2109  DEFINE_COMPILER;  DEFINE_COMPILER;
2110    struct sljit_jump *jump;
2111    
2112  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);
2113  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
2114      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2115    
2116  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2117  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2118  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));
2119  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);
2120    
2121  /* Store match begin and end. */  /* Store match begin and end. */
2122  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));
2123  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));
2124    
2125    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2126    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);
2127    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2128    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2129    #endif
2130    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2131    JUMPHERE(jump);
2132    
2133  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);
2134  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);
2135  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
# Line 2055  else if (common->mode == JIT_PARTIAL_SOF Line 2306  else if (common->mode == JIT_PARTIAL_SOF
2306    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);
2307    
2308  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2309    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);
2310  else  else
2311    {    {
2312    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2068  if (jump != NULL) Line 2319  if (jump != NULL)
2319    JUMPHERE(jump);    JUMPHERE(jump);
2320  }  }
2321    
2322  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2323  {  {
2324  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2325  DEFINE_COMPILER;  DEFINE_COMPILER;
2326  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2327    
2328  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2329    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2330      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2331      return;
2332      }
2333    
2334  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2335  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2336    {    {
2337    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));
2338    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);
2339    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2340    }    }
2341  else  else
2342    {    {
2343    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));
2344    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2345      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2346    else    else
2347      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2348    }    }
2349  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2350  }  }
2351    
2352  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 2365  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2365  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));
2366  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2367    {    {
2368    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);
2369    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2370    }    }
2371  else  else
# Line 2696  if (firstline) Line 2946  if (firstline)
2946    {    {
2947    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
2948    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2949    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((location >> 1) - 1));
2950    }    }
2951  else  else
2952    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((location >> 1) - 1));
2953    
2954  start = LABEL();  start = LABEL();
2955  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
# Line 2728  JUMPHERE(quit); Line 2978  JUMPHERE(quit);
2978  if (firstline)  if (firstline)
2979    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2980  else  else
2981    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((location >> 1) - 1));
2982  return TRUE;  return TRUE;
2983  }  }
2984    
# Line 2877  if (firstline) Line 3127  if (firstline)
3127    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3128  }  }
3129    
3130    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3131    
3132  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)
3133  {  {
3134  DEFINE_COMPILER;  DEFINE_COMPILER;
3135  struct sljit_label *start;  struct sljit_label *start;
3136  struct sljit_jump *quit;  struct sljit_jump *quit;
3137  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3138    jump_list *matches = NULL;
3139    pcre_uint8 inverted_start_bits[32];
3140    int i;
3141  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3142  struct sljit_jump *jump;  struct sljit_jump *jump;
3143  #endif  #endif
3144    
3145    for (i = 0; i < 32; ++i)
3146      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3147    
3148  if (firstline)  if (firstline)
3149    {    {
3150    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
# Line 2901  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 3159  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3159  if (common->utf)  if (common->utf)
3160    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3161  #endif  #endif
3162    
3163    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3164      {
3165  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3166  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3167  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3168  JUMPHERE(jump);    JUMPHERE(jump);
3169  #endif  #endif
3170  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3171  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3172  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3173  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3174  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);
3175  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3176      }
3177    
3178  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3179  if (common->utf)  if (common->utf)
# Line 2939  if (common->utf) Line 3201  if (common->utf)
3201  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE[8|16] */
3202  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3203  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3204  JUMPHERE(found);  if (found != NULL)
3205      JUMPHERE(found);
3206    if (matches != NULL)
3207      set_jumps(matches, LABEL());
3208  JUMPHERE(quit);  JUMPHERE(quit);
3209    
3210  if (firstline)  if (firstline)
# Line 3022  GET_LOCAL_BASE(TMP3, 0, 0); Line 3287  GET_LOCAL_BASE(TMP3, 0, 0);
3287  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3288  mainloop = LABEL();  mainloop = LABEL();
3289  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3290  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);
3291    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3292    
3293  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3294  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));
3295  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 3297  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_I
3297  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3298    
3299  JUMPHERE(jump);  JUMPHERE(jump);
3300  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3301  /* End of dropping frames. */  /* End of dropping frames. */
3302  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3303    
3304  JUMPHERE(jump);  JUMPHERE(jump);
3305  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3306  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3307  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. */  
3308  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));
3309  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3310  }  }
# Line 3063  static void check_wordboundary(compiler_ Line 3313  static void check_wordboundary(compiler_
3313  {  {
3314  DEFINE_COMPILER;  DEFINE_COMPILER;
3315  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3316    jump_list *skipread_list = NULL;
3317  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3318  struct sljit_jump *jump;  struct sljit_jump *jump;
3319  #endif  #endif
# Line 3120  else Line 3371  else
3371  JUMPHERE(skipread);  JUMPHERE(skipread);
3372    
3373  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3374  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3375  peek_char(common);  peek_char(common);
3376    
3377  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 3161  else Line 3412  else
3412      JUMPHERE(jump);      JUMPHERE(jump);
3413  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3414    }    }
3415  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3416    
3417  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);
3418  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
# Line 3481  sljit_emit_fast_return(compiler, RETURN_ Line 3732  sljit_emit_fast_return(compiler, RETURN_
3732    
3733  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3734    
3735  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)
3736  {  {
3737  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3738  pcre_uint32 c1, c2;  pcre_uint32 c1, c2;
# Line 3577  do Line 3828  do
3828  #endif  #endif
3829    
3830    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3831  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3832    
3833    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3834    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3594  do Line 3845  do
3845    
3846  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
3847    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))
3848  #elif defined COMPILE_PCRE16  #else
3849    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 */)  
3850  #endif  #endif
3851      {      {
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
3852      if (context->length >= 4)      if (context->length >= 4)
3853        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  
3854      else if (context->length >= 2)      else if (context->length >= 2)
3855        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);
3856    #if defined COMPILE_PCRE8
3857      else if (context->length >= 1)      else if (context->length >= 1)
3858        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);
3859  #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] */  
3860      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3861    
3862      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3625  do Line 3867  do
3867        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));
3868        break;        break;
3869    
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
3870        case 2 / sizeof(pcre_uchar):        case 2 / sizeof(pcre_uchar):
3871        if (context->oc.asushort != 0)        if (context->oc.asushort != 0)
3872          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 3881  do
3881        break;        break;
3882  #endif  #endif
3883    
 #endif /* COMPILE_PCRE[8|16] */  
   
3884        default:        default:
3885        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
3886        break;        break;
# Line 3651  do Line 3890  do
3890    
3891  #else  #else
3892    
3893    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3894    if (context->length > 0)    if (context->length >= 1)
3895      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3896    
3897    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
# Line 3813  while (*cc != XCL_END) Line 4052  while (*cc != XCL_END)
4052        break;        break;
4053    
4054        case PT_CLIST:        case PT_CLIST:
4055          case PT_UCNC:
4056        needschar = TRUE;        needschar = TRUE;
4057        break;        break;
4058    
# Line 4014  while (*cc != XCL_END) Line 4254  while (*cc != XCL_END)
4254        case PT_WORD:        case PT_WORD:
4255        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);
4256        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4257        /* ... fall through */        /* Fall through. */
4258    
4259        case PT_ALNUM:        case PT_ALNUM:
4260        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
# Line 4078  while (*cc != XCL_END) Line 4318  while (*cc != XCL_END)
4318          }          }
4319        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4320        break;        break;
4321    
4322          case PT_UCNC:
4323          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);
4324          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4325          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);
4326          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4327          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);
4328          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4329    
4330          SET_CHAR_OFFSET(0xa0);
4331          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);
4332          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4333          SET_CHAR_OFFSET(0);
4334          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
4335          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4336          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4337          break;
4338        }        }
4339      cc += 2;      cc += 2;
4340      }      }
# Line 4103  int length; Line 4360  int length;
4360  unsigned int c, oc, bit;  unsigned int c, oc, bit;
4361  compare_context context;  compare_context context;
4362  struct sljit_jump *jump[4];  struct sljit_jump *jump[4];
4363    jump_list *end_list;
4364  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4365  struct sljit_label *label;  struct sljit_label *label;
4366  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4171  switch(type) Line 4429  switch(type)
4429    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4430      {      {
4431      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);
4432        end_list = NULL;
4433      if (common->mode != JIT_PARTIAL_HARD_COMPILE)      if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4434        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));
4435      else      else
4436        jump[1] = check_str_end(common);        check_str_end(common, &end_list);
4437    
4438      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4439      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));
4440      if (jump[1] != NULL)      set_jumps(end_list, LABEL());
       JUMPHERE(jump[1]);  
4441      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4442      }      }
4443    else    else
# Line 4238  switch(type) Line 4496  switch(type)
4496    read_char(common);    read_char(common);
4497    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);
4498    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
4499      end_list = NULL;
4500    if (common->mode != JIT_PARTIAL_HARD_COMPILE)    if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4501      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));
4502    else    else
4503      jump[1] = check_str_end(common);      check_str_end(common, &end_list);
4504    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4505    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);
4506    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));
4507    jump[3] = JUMP(SLJIT_JUMP);    jump[2] = JUMP(SLJIT_JUMP);
4508    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4509    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);
4510      set_jumps(end_list, LABEL());
4511    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
4512    JUMPHERE(jump[2]);    JUMPHERE(jump[2]);
   JUMPHERE(jump[3]);  
4513    return cc;    return cc;
4514    
4515    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
# Line 5001  backtrack_common *backtrack; Line 5260  backtrack_common *backtrack;
5260  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5261  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5262  int start = GET(cc, 1);  int start = GET(cc, 1);
5263    pcre_uchar *start_cc;
5264    BOOL needs_control_head;
5265    
5266  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5267    
5268    /* Inlining simple patterns. */
5269    if (get_framesize(common, common->start + start, TRUE, &needs_control_head) == no_stack)
5270      {
5271      start_cc = common->start + start;
5272      compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
5273      BACKTRACK_AS(recurse_backtrack)->inlined_pattern = TRUE;
5274      return cc + 1 + LINK_SIZE;
5275      }
5276    
5277  while (entry != NULL)  while (entry != NULL)
5278    {    {
5279    if (entry->start == start)    if (entry->start == start)
# Line 5051  add_jump(compiler, &backtrack->topbacktr Line 5322  add_jump(compiler, &backtrack->topbacktr
5322  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5323  }  }
5324    
5325    static int SLJIT_CALL do_callout(struct jit_arguments* arguments, PUBL(callout_block) *callout_block, pcre_uchar **jit_ovector)
5326    {
5327    const pcre_uchar *begin = arguments->begin;
5328    int *offset_vector = arguments->offsets;
5329    int offset_count = arguments->offset_count;
5330    int i;
5331    
5332    if (PUBL(callout) == NULL)
5333      return 0;
5334    
5335    callout_block->version = 2;
5336    callout_block->callout_data = arguments->callout_data;
5337    
5338    /* Offsets in subject. */
5339    callout_block->subject_length = arguments->end - arguments->begin;
5340    callout_block->start_match = (pcre_uchar*)callout_block->subject - arguments->begin;
5341    callout_block->current_position = (pcre_uchar*)callout_block->offset_vector - arguments->begin;
5342    #if defined COMPILE_PCRE8
5343    callout_block->subject = (PCRE_SPTR)begin;
5344    #elif defined COMPILE_PCRE16
5345    callout_block->subject = (PCRE_SPTR16)begin;
5346    #elif defined COMPILE_PCRE32
5347    callout_block->subject = (PCRE_SPTR32)begin;
5348    #endif
5349    
5350    /* Convert and copy the JIT offset vector to the offset_vector array. */
5351    callout_block->capture_top = 0;
5352    callout_block->offset_vector = offset_vector;
5353    for (i = 2; i < offset_count; i += 2)
5354      {
5355      offset_vector[i] = jit_ovector[i] - begin;
5356      offset_vector[i + 1] = jit_ovector[i + 1] - begin;
5357      if (jit_ovector[i] >= begin)
5358        callout_block->capture_top = i;
5359      }
5360    
5361    callout_block->capture_top = (callout_block->capture_top >> 1) + 1;
5362    if (offset_count > 0)
5363      offset_vector[0] = -1;
5364    if (offset_count > 1)
5365      offset_vector[1] = -1;
5366    return (*PUBL(callout))(callout_block);
5367    }
5368    
5369    /* Aligning to 8 byte. */
5370    #define CALLOUT_ARG_SIZE \
5371        (((int)sizeof(PUBL(callout_block)) + 7) & ~7)
5372    
5373    #define CALLOUT_ARG_OFFSET(arg) \
5374        (-CALLOUT_ARG_SIZE + SLJIT_OFFSETOF(PUBL(callout_block), arg))
5375    
5376    static SLJIT_INLINE pcre_uchar *compile_callout_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5377    {
5378    DEFINE_COMPILER;
5379    backtrack_common *backtrack;
5380    
5381    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
5382    
5383    allocate_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5384    
5385    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
5386    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
5387    SLJIT_ASSERT(common->capture_last_ptr != 0);
5388    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);
5389    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);
5390    
5391    /* These pointer sized fields temporarly stores internal variables. */
5392    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
5393    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(offset_vector), STR_PTR, 0);
5394    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(subject), TMP2, 0);
5395    
5396    if (common->mark_ptr != 0)
5397      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr));
5398    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 2));
5399    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 2 + LINK_SIZE));
5400    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);
5401    
5402    /* Needed to save important temporary registers. */
5403    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5404    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, STACK_TOP, 0, SLJIT_IMM, CALLOUT_ARG_SIZE);
5405    GET_LOCAL_BASE(SLJIT_SCRATCH_REG3, 0, OVECTOR_START);
5406    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_callout));
5407    OP1(SLJIT_MOV_SI, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0);
5408    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5409    free_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5410    
5411    /* Check return value. */
5412    OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
5413    add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_C_SIG_GREATER));
5414    if (common->forced_quit_label == NULL)
5415      add_jump(compiler, &common->forced_quit, JUMP(SLJIT_C_SIG_LESS));
5416    else
5417      JUMPTO(SLJIT_C_SIG_LESS, common->forced_quit_label);
5418    return cc + 2 + 2 * LINK_SIZE;
5419    }
5420    
5421    #undef CALLOUT_ARG_SIZE
5422    #undef CALLOUT_ARG_OFFSET
5423    
5424  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)
5425  {  {
5426  DEFINE_COMPILER;  DEFINE_COMPILER;
5427  int framesize;  int framesize;
5428    int extrasize;
5429    BOOL needs_control_head;
5430  int private_data_ptr;  int private_data_ptr;
5431  backtrack_common altbacktrack;  backtrack_common altbacktrack;
5432  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
# Line 5064  jump_list *tmp = NULL; Line 5436  jump_list *tmp = NULL;
5436  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5437  jump_list **found;  jump_list **found;
5438  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5439  struct sljit_label *save_quitlabel = common->quitlabel;  struct sljit_label *save_quit_label = common->quit_label;
5440  struct sljit_label *save_acceptlabel = common->acceptlabel;  struct sljit_label *save_accept_label = common->accept_label;
5441  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
5442  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
5443    BOOL save_local_exit = common->local_exit;
5444  struct sljit_jump *jump;  struct sljit_jump *jump;
5445  struct sljit_jump *brajump = NULL;  struct sljit_jump *brajump = NULL;
5446    
# Line 5079  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 5452  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
5452    }    }
5453  private_data_ptr = PRIVATE_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
5454  SLJIT_ASSERT(private_data_ptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
5455  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, FALSE, &needs_control_head);
5456  backtrack->framesize = framesize;  backtrack->framesize = framesize;
5457  backtrack->private_data_ptr = private_data_ptr;  backtrack->private_data_ptr = private_data_ptr;
5458  opcode = *cc;  opcode = *cc;
# Line 5098  if (bra == OP_BRAMINZERO) Line 5471  if (bra == OP_BRAMINZERO)
5471    
5472  if (framesize < 0)  if (framesize < 0)
5473    {    {
5474    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    extrasize = needs_control_head ? 2 : 1;
5475    allocate_stack(common, 1);    if (framesize == no_frame)
5476        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
5477      allocate_stack(common, extrasize);
5478      if (needs_control_head)
5479        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5480    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5481      if (needs_control_head)
5482        {
5483        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5484        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5485        }
5486    }    }
5487  else  else
5488    {    {
5489    allocate_stack(common, framesize + 2);    extrasize = needs_control_head ? 3 : 2;
5490      allocate_stack(common, framesize + extrasize);
5491    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);
5492    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));
5493    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);
5494      if (needs_control_head)
5495        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5496    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5497    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    if (needs_control_head)
5498    init_frame(common, ccbegin, framesize + 1, 2, FALSE);      {
5499        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
5500        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
5501        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5502        }
5503      else
5504        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5505      init_frame(common, ccbegin, framesize + extrasize - 1, extrasize, FALSE);
5506    }    }
5507    
5508  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
5509  common->quitlabel = NULL;  common->local_exit = TRUE;
5510    common->quit_label = NULL;
5511  common->quit = NULL;  common->quit = NULL;
5512  while (1)  while (1)
5513    {    {
5514    common->acceptlabel = NULL;    common->accept_label = NULL;
5515    common->accept = NULL;    common->accept = NULL;
5516    altbacktrack.top = NULL;    altbacktrack.top = NULL;
5517    altbacktrack.topbacktracks = NULL;    altbacktrack.topbacktracks = NULL;
# Line 5130  while (1) Line 5523  while (1)
5523    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
5524    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5525      {      {
5526      common->quitlabel = save_quitlabel;      common->local_exit = save_local_exit;
5527      common->acceptlabel = save_acceptlabel;      common->quit_label = save_quit_label;
5528        common->accept_label = save_accept_label;
5529      common->quit = save_quit;      common->quit = save_quit;
5530      common->accept = save_accept;      common->accept = save_accept;
5531      return NULL;      return NULL;
5532      }      }
5533    common->acceptlabel = LABEL();    common->accept_label = LABEL();
5534    if (common->accept != NULL)    if (common->accept != NULL)
5535      set_jumps(common->accept, common->acceptlabel);      set_jumps(common->accept, common->accept_label);
5536    
5537    /* Reset stack. */    /* Reset stack. */
5538    if (framesize < 0)    if (framesize < 0)
5539      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      {
5540    else {      if (framesize == no_frame)
5541          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5542        else
5543          free_stack(common, extrasize);
5544        if (needs_control_head)
5545          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5546        }
5547      else
5548        {
5549      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)
5550        {        {
5551        /* 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. */
5552        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));
5553          if (needs_control_head)
5554            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5555        }        }
5556      else      else
5557        {        {
5558        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);
5559          if (needs_control_head)
5560            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));
5561        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5562        }        }
5563    }      }
5564    
5565    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5566      {      {
5567      /* 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. */
5568      if (conditional)      if (conditional)
5569        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);
5570      else if (bra == OP_BRAZERO)      else if (bra == OP_BRAZERO)
5571        {        {
5572        if (framesize < 0)        if (framesize < 0)
5573          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));
5574        else        else
5575          {          {
5576          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));
5577          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));
5578          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);
5579          }          }
5580        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 5591  while (1)
5591    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
5592    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5593      {      {
5594      common->quitlabel = save_quitlabel;      common->local_exit = save_local_exit;
5595      common->acceptlabel = save_acceptlabel;      common->quit_label = save_quit_label;
5596        common->accept_label = save_accept_label;
5597      common->quit = save_quit;      common->quit = save_quit;
5598      common->accept = save_accept;      common->accept = save_accept;
5599      return NULL;      return NULL;
# Line 5199  while (1) Line 5606  while (1)
5606    ccbegin = cc;    ccbegin = cc;
5607    cc += GET(cc, 1);    cc += GET(cc, 1);
5608    }    }
5609    
5610  /* None of them matched. */  /* None of them matched. */
5611  if (common->quit != NULL)  if (common->quit != NULL)
5612      {
5613      jump = JUMP(SLJIT_JUMP);
5614    set_jumps(common->quit, LABEL());    set_jumps(common->quit, LABEL());
5615      SLJIT_ASSERT(framesize != no_stack);
5616      if (framesize < 0)
5617        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));
5618      else
5619        {
5620        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5621        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5622        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
5623        }
5624      JUMPHERE(jump);
5625      }
5626    
5627    if (needs_control_head)
5628      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(1));
5629    
5630  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)
5631    {    {
# Line 5213  if (opcode == OP_ASSERT || opcode == OP_ Line 5637  if (opcode == OP_ASSERT || opcode == OP_
5637      {      {
5638      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5639      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5640          {
5641          if (extrasize == 2)
5642            free_stack(common, 1);
5643        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5644          }
5645      else      else
5646        free_stack(common, 1);        free_stack(common, extrasize);
5647      }      }
5648    else    else
5649      {      {
5650      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
5651      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5652      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5653        {        {
5654        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
5655        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5656        }        }
5657      else      else
5658        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
5659      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);
5660      }      }
5661    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
# Line 5239  if (opcode == OP_ASSERT || opcode == OP_ Line 5667  if (opcode == OP_ASSERT || opcode == OP_
5667    if (framesize < 0)    if (framesize < 0)
5668      {      {
5669      /* 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. */
5670      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));
5671      /* Keep the STR_PTR on the top of the stack. */      /* Keep the STR_PTR on the top of the stack. */
5672      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5673          {
5674        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));
5675          if (extrasize == 2)
5676            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5677          }
5678      else if (bra == OP_BRAMINZERO)      else if (bra == OP_BRAMINZERO)
5679        {        {
5680        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 5687  if (opcode == OP_ASSERT || opcode == OP_
5687        {        {
5688        /* 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. */
5689        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));
5690        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));
5691        }        }
5692      else      else
5693        {        {
5694        /* 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. */
5695        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));
5696        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        if (extrasize == 2)
5697        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);          {
5698            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5699            if (bra == OP_BRAMINZERO)
5700              OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5701            }
5702          else
5703            {
5704            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
5705            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);
5706            }
5707        }        }
5708      }      }
5709    
5710    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
5711      {      {
5712      backtrack->matchingpath = LABEL();      backtrack->matchingpath = LABEL();
5713      sljit_set_label(jump, backtrack->matchingpath);      SET_LABEL(jump, backtrack->matchingpath);
5714      }      }
5715    else if (bra == OP_BRAMINZERO)    else if (bra == OP_BRAMINZERO)
5716      {      {
# Line 5291  else Line 5732  else
5732      {      {
5733      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5734      if (bra != OP_BRA)      if (bra != OP_BRA)
5735          {
5736          if (extrasize == 2)
5737            free_stack(common, 1);
5738        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5739          }
5740      else      else
5741        free_stack(common, 1);        free_stack(common, extrasize);
5742      }      }
5743    else    else
5744      {      {
5745      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5746      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
5747      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5748      if (bra != OP_BRA)      if (bra != OP_BRA)
5749        {        {
5750        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
5751        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5752        }        }
5753      else      else
5754        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
5755      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);
5756      }      }
5757    
# Line 5326  else Line 5771  else
5771      }      }
5772    }    }
5773    
5774  common->quitlabel = save_quitlabel;  common->local_exit = save_local_exit;
5775  common->acceptlabel = save_acceptlabel;  common->quit_label = save_quit_label;
5776    common->accept_label = save_accept_label;
5777  common->quit = save_quit;  common->quit = save_quit;
5778  common->accept = save_accept;  common->accept = save_accept;
5779  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
# Line 5443  if (i < name_count) Line 5889  if (i < name_count)
5889  return condition;  return condition;
5890  }  }
5891    
5892    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)
5893    {
5894    DEFINE_COMPILER;
5895    int stacksize;
5896    
5897    if (framesize < 0)
5898      {
5899      if (framesize == no_frame)
5900        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5901      else
5902        {
5903        stacksize = needs_control_head ? 1 : 0;
5904        if (ket != OP_KET || has_alternatives)
5905          stacksize++;
5906        free_stack(common, stacksize);
5907        }
5908    
5909      if (needs_control_head)
5910        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), (ket != OP_KET || has_alternatives) ? sizeof(sljit_sw) : 0);
5911    
5912      /* TMP2 which is set here used by OP_KETRMAX below. */
5913      if (ket == OP_KETRMAX)
5914        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);
5915      else if (ket == OP_KETRMIN)
5916        {
5917        /* Move the STR_PTR to the private_data_ptr. */
5918        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);
5919        }
5920      }
5921    else
5922      {
5923      stacksize = (ket != OP_KET || has_alternatives) ? 2 : 1;
5924      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + stacksize) * sizeof(sljit_sw));
5925      if (needs_control_head)
5926        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 0);
5927    
5928      if (ket == OP_KETRMAX)
5929        {
5930        /* TMP2 which is set here used by OP_KETRMAX below. */
5931        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5932        }
5933      }
5934    if (needs_control_head)
5935      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP1, 0);
5936    }
5937    
5938    static SLJIT_INLINE int match_capture_common(compiler_common *common, int stacksize, int offset, int private_data_ptr)
5939    {
5940    DEFINE_COMPILER;
5941    
5942    if (common->capture_last_ptr != 0)
5943      {
5944      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
5945      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
5946      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
5947      stacksize++;
5948      }
5949    if (common->optimized_cbracket[offset >> 1] == 0)
5950      {
5951      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5952      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5953      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
5954      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5955      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
5956      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
5957      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
5958      stacksize += 2;
5959      }
5960    return stacksize;
5961    }
5962    
5963  /*  /*
5964    Handling bracketed expressions is probably the most complex part.    Handling bracketed expressions is probably the most complex part.
5965    
# Line 5511  pcre_uchar bra = OP_BRA; Line 6028  pcre_uchar bra = OP_BRA;
6028  pcre_uchar ket;  pcre_uchar ket;
6029  assert_backtrack *assert;  assert_backtrack *assert;
6030  BOOL has_alternatives;  BOOL has_alternatives;
6031    BOOL needs_control_head = FALSE;
6032  struct sljit_jump *jump;  struct sljit_jump *jump;
6033  struct sljit_jump *skip;  struct sljit_jump *skip;
6034  struct sljit_label *rmaxlabel = NULL;  struct sljit_label *rmaxlabel = NULL;
# Line 5586  else if (opcode == OP_ONCE || opcode == Line 6104  else if (opcode == OP_ONCE || opcode ==
6104    SLJIT_ASSERT(private_data_ptr != 0);    SLJIT_ASSERT(private_data_ptr != 0);
6105    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;
6106    if (opcode == OP_ONCE)    if (opcode == OP_ONCE)
6107      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, FALSE);      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, FALSE, &needs_control_head);
6108    }    }
6109    
6110  /* Instructions before the first alternative. */  /* Instructions before the first alternative. */
6111  stacksize = 0;  stacksize = 0;
6112  if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))  if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
6113    stacksize++;    stacksize++;
6114  if (bra == OP_BRAZERO)  if (bra == OP_BRAZERO)
6115    stacksize++;    stacksize++;
# Line 5600  if (stacksize > 0) Line 6118  if (stacksize > 0)
6118    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6119    
6120  stacksize = 0;  stacksize = 0;
6121  if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))  if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
6122    {    {
6123    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
6124    stacksize++;    stacksize++;
# Line 5663  if (ket == OP_KETRMAX) Line 6181  if (ket == OP_KETRMAX)
6181  /* Handling capturing brackets and alternatives. */  /* Handling capturing brackets and alternatives. */
6182  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
6183    {    {
6184      stacksize = 0;
6185      if (needs_control_head)
6186        {
6187        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6188        stacksize++;
6189        }
6190    
6191    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
6192      {      {
6193      /* Neither capturing brackets nor recursions are not found in the block. */      /* Neither capturing brackets nor recursions are found in the block. */
6194      if (ket == OP_KETRMIN)      if (ket == OP_KETRMIN)
6195        {        {
6196        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        stacksize += 2;
6197        allocate_stack(common, 2);        if (!needs_control_head)
6198        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);  
       OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));  
6199        }        }
6200      else if (ket == OP_KETRMAX || has_alternatives)      else
6201        {        {
6202        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);        if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)
6203        allocate_stack(common, 1);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6204        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);        if (ket == OP_KETRMAX || has_alternatives)
6205            stacksize++;
6206        }        }
6207      else  
6208        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);      if (stacksize > 0)
6209          allocate_stack(common, stacksize);
6210    
6211        stacksize = 0;
6212        if (needs_control_head)
6213          {
6214          stacksize++;
6215          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6216          }
6217    
6218        if (ket == OP_KETRMIN)
6219          {
6220          if (needs_control_head)
6221            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6222          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6223          if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)
6224            OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, needs_control_head ? (2 * sizeof(sljit_sw)) : sizeof(sljit_sw));
6225          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6226          }
6227        else if (ket == OP_KETRMAX || has_alternatives)
6228          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6229      }      }
6230    else    else
6231      {      {
6232      if (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives)      if (ket != OP_KET || has_alternatives)
6233          stacksize++;
6234    
6235        stacksize += BACKTRACK_AS(bracket_backtrack)->u.framesize + 1;
6236        allocate_stack(common, stacksize);
6237    
6238        if (needs_control_head)
6239          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6240    
6241        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6242        OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, stacksize * sizeof(sljit_sw));
6243    
6244        stacksize = needs_control_head ? 1 : 0;
6245        if (ket != OP_KET || has_alternatives)
6246        {        {
6247        allocate_stack(common, BACKTRACK_AS(bracket_backtrack)->u.framesize + 2);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
       OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
       OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(BACKTRACK_AS(bracket_backtrack)->u.framesize + 1));  
       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  
6248        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);
6249        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);        stacksize++;
6250        init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize + 1, 2, FALSE);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6251        }        }
6252      else      else
6253        {        {
       allocate_stack(common, BACKTRACK_AS(bracket_backtrack)->u.framesize + 1);  
       OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
       OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(BACKTRACK_AS(bracket_backtrack)->u.framesize));  
6254        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);
6255        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
       init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize, 1, FALSE);  
6256        }        }
6257        init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize, stacksize + 1, FALSE);
6258      }      }
6259    }    }
6260  else if (opcode == OP_CBRA || opcode == OP_SCBRA)  else if (opcode == OP_CBRA || opcode == OP_SCBRA)
6261    {    {
6262    /* Saving the previous values. */    /* Saving the previous values. */
6263    if (common->optimized_cbracket[offset >> 1] == 0)    if (common->optimized_cbracket[offset >> 1] != 0)
     {  
     allocate_stack(common, 3);  
     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  
     OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);  
     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);  
     }  
   else  
6264      {      {
6265      SLJIT_ASSERT(private_data_ptr == OVECTOR(offset));      SLJIT_ASSERT(private_data_ptr == OVECTOR(offset));
6266      allocate_stack(common, 2);      allocate_stack(common, 2);
# Line 5730  else if (opcode == OP_CBRA || opcode == Line 6270  else if (opcode == OP_CBRA || opcode ==
6270      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
6271      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6272      }      }
6273      else
6274        {
6275        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6276        allocate_stack(common, 1);
6277        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);
6278        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6279        }
6280    }    }
6281  else if (opcode == OP_SBRA || opcode == OP_SCOND)  else if (opcode == OP_SBRA || opcode == OP_SCOND)
6282    {    {
# Line 5843  if (SLJIT_UNLIKELY(sljit_get_compiler_er Line 6390  if (SLJIT_UNLIKELY(sljit_get_compiler_er
6390    return NULL;    return NULL;
6391    
6392  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
6393    {    match_once_common(common, ket, BACKTRACK_AS(bracket_backtrack)->u.framesize, private_data_ptr, has_alternatives, needs_control_head);
   if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)  
     {  
     OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
     /* TMP2 which is set here used by OP_KETRMAX below. */  
     if (ket == OP_KETRMAX)  
       OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);  
     else if (ket == OP_KETRMIN)  
       {  
       /* Move the STR_PTR to the private_data_ptr. */  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);  
       }  
     }  
   else  
     {  
     stacksize = (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives) ? 2 : 1;  
     OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize) * sizeof(sljit_sw));  
     if (ket == OP_KETRMAX)  
       {  
       /* TMP2 which is set here used by OP_KETRMAX below. */  
       OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));  
       }  
     }  
   }  
6394    
6395  stacksize = 0;  stacksize = 0;
6396  if (ket != OP_KET || bra != OP_BRA)  if (ket != OP_KET || bra != OP_BRA)
6397    stacksize++;    stacksize++;
6398    if (offset != 0)
6399      {
6400      if (common->capture_last_ptr != 0)
6401        stacksize++;
6402      if (common->optimized_cbracket[offset >> 1] == 0)
6403        stacksize += 2;
6404      }
6405  if (has_alternatives && opcode != OP_ONCE)  if (has_alternatives && opcode != OP_ONCE)
6406    stacksize++;    stacksize++;
6407    
# Line 5878  if (stacksize > 0) Line 6409  if (stacksize > 0)
6409    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6410    
6411  stacksize = 0;  stacksize = 0;
6412  if (ket != OP_KET)  if (ket != OP_KET || bra != OP_BRA)
   {  
   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);  
   stacksize++;  
   }  
 else if (bra != OP_BRA)  
6413    {    {
6414    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);    if (ket != OP_KET)
6415        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6416      else
6417        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
6418    stacksize++;    stacksize++;
6419    }    }
6420    
6421    if (offset != 0)
6422      stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);
6423    
6424  if (has_alternatives)  if (has_alternatives)
6425    {    {
6426    if (opcode != OP_ONCE)    if (opcode != OP_ONCE)
# Line 5898  if (has_alternatives) Line 6430  if (has_alternatives)
6430    }    }
6431    
6432  /* Must be after the matchingpath label. */  /* Must be after the matchingpath label. */
6433  if (offset != 0)  if (offset != 0 && common->optimized_cbracket[offset >> 1] != 0)
6434    {    {
6435    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    SLJIT_ASSERT(private_data_ptr == OVECTOR(offset + 0));
6436    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 0), TMP1, 0);  
6437    }    }
6438    
6439  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
# Line 5959  if ((ket != OP_KET && bra != OP_BRAMINZE Line 6490  if ((ket != OP_KET && bra != OP_BRAMINZE
6490  while (*cc == OP_ALT)  while (*cc == OP_ALT)
6491    cc += GET(cc, 1);    cc += GET(cc, 1);
6492  cc += 1 + LINK_SIZE;  cc += 1 + LINK_SIZE;
6493    
6494    /* Temporarily encoding the needs_control_head in framesize. */
6495    if (opcode == OP_ONCE)
6496      BACKTRACK_AS(bracket_backtrack)->u.framesize = (BACKTRACK_AS(bracket_backtrack)->u.framesize << 1) | (needs_control_head ? 1 : 0);
6497  return cc;  return cc;
6498  }  }
6499    
# Line 5969  backtrack_common *backtrack; Line 6504  backtrack_common *backtrack;
6504  pcre_uchar opcode;  pcre_uchar opcode;
6505  int private_data_ptr;  int private_data_ptr;
6506  int cbraprivptr = 0;  int cbraprivptr = 0;
6507    BOOL needs_control_head;
6508  int framesize;  int framesize;
6509  int stacksize;  int stacksize;
6510  int offset = 0;  int offset = 0;
6511  BOOL zero = FALSE;  BOOL zero = FALSE;
6512  pcre_uchar *ccbegin = NULL;  pcre_uchar *ccbegin = NULL;
6513  int stack;  int stack; /* Also contains the offset of control head. */
6514  struct sljit_label *loop = NULL;  struct sljit_label *loop = NULL;
6515  struct jump_list *emptymatch = NULL;  struct jump_list *emptymatch = NULL;
6516    
# Line 6012  switch(opcode) Line 6548  switch(opcode)
6548    break;    break;
6549    }    }
6550    
6551  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, FALSE, &needs_control_head);
6552  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;
6553  if (framesize < 0)  if (framesize < 0)
6554    {    {
6555    stacksize = (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS) ? 2 : 1;    if (offset != 0)
6556        {
6557        stacksize = 2;
6558        if (common->capture_last_ptr != 0)
6559          stacksize++;
6560        }
6561      else
6562        stacksize = 1;
6563    
6564      if (needs_control_head)
6565        stacksize++;
6566    if (!zero)    if (!zero)
6567      stacksize++;      stacksize++;
6568    
6569    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
6570    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6571    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    if (framesize == no_frame)
6572        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6573    
6574    if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)    stack = 0;
6575      if (offset != 0)
6576      {      {
6577        stack = 2;
6578      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6579      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
6580      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
6581        if (common->capture_last_ptr != 0)
6582          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6583      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6584        if (needs_control_head)
6585          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6586        if (common->capture_last_ptr != 0)
6587          {
6588          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
6589          stack = 3;
6590          }
6591      }      }
6592    else    else
6593        {
6594        if (needs_control_head)
6595          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6596      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6597        stack = 1;
6598        }
6599    
6600      if (needs_control_head)
6601        stack++;
6602    if (!zero)    if (!zero)
6603      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize - 1), SLJIT_IMM, 1);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), SLJIT_IMM, 1);
6604      if (needs_control_head)
6605        {
6606        stack--;
6607        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP2, 0);
6608        }
6609    }    }
6610  else  else
6611    {    {
6612    stacksize = framesize + 1;    stacksize = framesize + 1;
6613    if (!zero)    if (!zero)
6614      stacksize++;      stacksize++;
6615    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)    if (needs_control_head)
6616        stacksize++;
6617      if (offset == 0)
6618      stacksize++;      stacksize++;
6619    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
   allocate_stack(common, stacksize);  
6620    
6621      allocate_stack(common, stacksize);
6622    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);
6623    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));    if (needs_control_head)
6624    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6625      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));
6626    
6627    stack = 0;    stack = 0;
6628    if (!zero)    if (!zero)
6629      {      {
6630      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 1);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 1);
6631        stack = 1;
6632        }
6633      if (needs_control_head)
6634        {
6635        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP2, 0);
6636      stack++;      stack++;
6637      }      }
6638    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)    if (offset == 0)
6639      {      {
6640      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), STR_PTR, 0);
6641      stack++;      stack++;
6642      }      }
6643    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP1, 0);
6644    init_frame(common, cc, stacksize - 1, stacksize - framesize, FALSE);    init_frame(common, cc, stacksize - 1, stacksize - framesize, FALSE);
6645      stack -= 1 + (offset == 0);
6646    }    }
6647    
6648  if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)  if (offset != 0)
6649    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6650    
6651  loop = LABEL();  loop = LABEL();
# Line 6080  while (*cc != OP_KETRPOS) Line 6661  while (*cc != OP_KETRPOS)
6661    
6662    if (framesize < 0)    if (framesize < 0)
6663      {      {
6664      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      if (framesize == no_frame)
6665          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6666    
6667      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6668        {        {
6669        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6670        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
6671        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6672          if (common->capture_last_ptr != 0)
6673            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6674        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6675        }        }
6676      else      else
# Line 6104  while (*cc != OP_KETRPOS) Line 6688  while (*cc != OP_KETRPOS)
6688      }      }
6689    else    else
6690      {      {
6691      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6692        {        {
6693        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, stacksize * sizeof(sljit_sw));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, stacksize * sizeof(sljit_sw));
6694        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6695        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
6696        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6697          if (common->capture_last_ptr != 0)
6698            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6699        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6700        }        }
6701      else      else
# Line 6132  while (*cc != OP_KETRPOS) Line 6718  while (*cc != OP_KETRPOS)
6718          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6719        }        }
6720      }      }
6721    
6722      if (needs_control_head)
6723        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(stack));
6724    
6725    JUMPTO(SLJIT_JUMP, loop);    JUMPTO(SLJIT_JUMP, loop);
6726    flush_stubs(common);    flush_stubs(common);
6727    
# Line 6142  while (*cc != OP_KETRPOS) Line 6732  while (*cc != OP_KETRPOS)
6732    
6733    if (framesize < 0)    if (framesize < 0)
6734      {      {
6735      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6736        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6737      else      else
6738        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6739      }      }
6740    else    else
6741      {      {
6742      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6743        {        {
6744        /* Last alternative. */        /* Last alternative. */
6745        if (*cc == OP_KETRPOS)        if (*cc == OP_KETRPOS)
# Line 6168  while (*cc != OP_KETRPOS) Line 6758  while (*cc != OP_KETRPOS)
6758    ccbegin = cc + 1 + LINK_SIZE;    ccbegin = cc + 1 + LINK_SIZE;
6759    }    }
6760    
6761    /* We don't have to restore the control head in case of a failed match. */
6762    
6763  backtrack->topbacktracks = NULL;  backtrack->topbacktracks = NULL;
6764  if (!zero)  if (!zero)
6765    {    {
# Line 6296  PUSH_BACKTRACK(sizeof(iterator_backtrack Line 6888  PUSH_BACKTRACK(sizeof(iterator_backtrack
6888    
6889  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);
6890    
6891  switch (type)  switch(type)
6892    {    {
6893    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
6894    case OP_DIGIT:    case OP_DIGIT:
# Line 6498  static SLJIT_INLINE pcre_uchar *compile_ Line 7090  static SLJIT_INLINE pcre_uchar *compile_
7090  DEFINE_COMPILER;  DEFINE_COMPILER;
7091  backtrack_common *backtrack;  backtrack_common *backtrack;
7092    
7093  PUSH_BACKTRACK(sizeof(bracket_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
7094    
7095  if (*cc == OP_FAIL)  if (*cc == OP_FAIL)
7096    {    {
# Line 6509  if (*cc == OP_FAIL) Line 7101  if (*cc == OP_FAIL)
7101  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL)  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL)
7102    {    {
7103    /* No need to check notempty conditions. */    /* No need to check notempty conditions. */
7104    if (common->acceptlabel == NULL)    if (common->accept_label == NULL)
7105      add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP));
7106    else    else
7107      JUMPTO(SLJIT_JUMP, common->acceptlabel);      JUMPTO(SLJIT_JUMP, common->accept_label);
7108    return cc + 1;    return cc + 1;
7109    }    }
7110    
7111  if (common->acceptlabel == NULL)  if (common->accept_label == NULL)
7112    add_jump(compiler, &common->accept, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0)));    add_jump(compiler, &common->accept, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0)));
7113  else  else
7114    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), common->acceptlabel);    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), common->accept_label);
7115  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
7116  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));
7117  add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));  add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
7118  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty_atstart));  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty_atstart));
7119  if (common->acceptlabel == NULL)  if (common->accept_label == NULL)
7120    add_jump(compiler, &common->accept, CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0));    add_jump(compiler, &common->accept, CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0));
7121  else  else
7122    CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, common->acceptlabel);    CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, common->accept_label);
7123  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
7124  if (common->acceptlabel == NULL)  if (common->accept_label == NULL)
7125    add_jump(compiler, &common->accept, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0));    add_jump(compiler, &common->accept, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0));
7126  else  else
7127    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, common->acceptlabel);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, common->accept_label);
7128  add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_JUMP));  add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_JUMP));
7129  return cc + 1;  return cc + 1;
7130  }  }
# Line 6712  while (cc < ccend) Line 7304  while (cc < ccend)
7304      cc = compile_recurse_matchingpath(common, cc, parent);      cc = compile_recurse_matchingpath(common, cc, parent);
7305      break;      break;
7306    
7307        case OP_CALLOUT:
7308        cc = compile_callout_matchingpath(common, cc, parent);
7309        break;
7310    
7311      case OP_ASSERT:      case OP_ASSERT:
7312      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
7313      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 6781  while (cc < ccend) Line 7377  while (cc < ccend)
7377      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
7378      break;      break;
7379    
7380        case OP_PRUNE_ARG:
7381        OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
7382        OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));
7383        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);
7384        OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);
7385        /* Fall through. */
7386    
7387        case OP_PRUNE:
7388      case OP_COMMIT:      case OP_COMMIT:
7389      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);
7390        SLJIT_ASSERT(common->control_head_ptr != 0);
7391        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
7392        allocate_stack(common, 2);
7393        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);
7394        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, *cc == OP_COMMIT ? type_commit : type_prune);
7395        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
7396        cc += (*cc == OP_PRUNE_ARG) ? (1 + 2 + cc[1]) : 1;
7397        break;
7398    
7399        case OP_SKIP:
7400        PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);
7401        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
7402        allocate_stack(common, 3);
7403        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);
7404        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, type_skip);
7405        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), STR_PTR, 0);
7406        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
7407      cc += 1;      cc += 1;
7408      break;      break;
7409    
# Line 6994  static void compile_recurse_backtracking Line 7615  static void compile_recurse_backtracking
7615  {  {
7616  DEFINE_COMPILER;  DEFINE_COMPILER;
7617    
7618    if (CURRENT_AS(recurse_backtrack)->inlined_pattern)
7619      compile_backtrackingpath(common, current->top);
7620  set_jumps(current->topbacktracks, LABEL());  set_jumps(current->topbacktracks, LABEL());
7621    if (CURRENT_AS(recurse_backtrack)->inlined_pattern)
7622      return;
7623    
7624  if (common->has_set_som && common->mark_ptr != 0)  if (common->has_set_som && common->mark_ptr != 0)
7625    {    {
# Line 7096  pcre_uchar bra = OP_BRA; Line 7721  pcre_uchar bra = OP_BRA;
7721  pcre_uchar ket;  pcre_uchar ket;
7722  assert_backtrack *assert;  assert_backtrack *assert;
7723  BOOL has_alternatives;  BOOL has_alternatives;
7724    BOOL needs_control_head = FALSE;
7725  struct sljit_jump *brazero = NULL;  struct sljit_jump *brazero = NULL;
7726  struct sljit_jump *once = NULL;  struct sljit_jump *once = NULL;
7727  struct sljit_jump *cond = NULL;  struct sljit_jump *cond = NULL;
# Line 7121  if (SLJIT_UNLIKELY(opcode == OP_COND) && Line 7747  if (SLJIT_UNLIKELY(opcode == OP_COND) &&
7747  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))
7748    opcode = OP_ONCE;    opcode = OP_ONCE;
7749    
7750    /* Decoding the needs_control_head in framesize. */
7751    if (opcode == OP_ONCE)
7752      {
7753      needs_control_head = (CURRENT_AS(bracket_backtrack)->u.framesize & 0x1) != 0;
7754      CURRENT_AS(bracket_backtrack)->u.framesize >>= 1;
7755      }
7756    
7757  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
7758    {    {
7759    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
# Line 7160  else if (bra == OP_BRAZERO) Line 7793  else if (bra == OP_BRAZERO)
7793    brazero = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0);    brazero = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0);
7794    }    }
7795    
7796    if (offset != 0)
7797      {
7798      if (common->capture_last_ptr != 0)
7799        {
7800        SLJIT_ASSERT(common->optimized_cbracket[offset >> 1] == 0);
7801        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7802        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
7803        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, TMP1, 0);
7804        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
7805        free_stack(common, 3);
7806        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP2, 0);
7807        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
7808        }
7809      else if (common->optimized_cbracket[offset >> 1] == 0)
7810        {
7811        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7812        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
7813        free_stack(common, 2);
7814        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
7815        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);
7816        }
7817      }
7818    
7819  if (SLJIT_UNLIKELY(opcode == OP_ONCE))  if (SLJIT_UNLIKELY(opcode == OP_ONCE))
7820    {    {
7821    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
# Line 7255  if (has_alternatives) Line 7911  if (has_alternatives)
7911      current->top = NULL;      current->top = NULL;
7912      current->topbacktracks = NULL;      current->topbacktracks = NULL;
7913      current->nextbacktracks = NULL;      current->nextbacktracks = NULL;
7914        /* Conditional blocks always have an additional alternative, even if it is empty. */
7915      if (*cc == OP_ALT)      if (*cc == OP_ALT)
7916        {        {
7917        ccprev = cc + 1 + LINK_SIZE;        ccprev = cc + 1 + LINK_SIZE;
7918        cc += GET(cc, 1);        cc += GET(cc, 1);
7919        if (opcode != OP_COND && opcode != OP_SCOND)        if (opcode != OP_COND && opcode != OP_SCOND)
7920          {          {
7921          if (private_data_ptr != 0 && opcode != OP_ONCE)          if (opcode != OP_ONCE)
7922            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);            {
7923              if (private_data_ptr != 0)
7924                OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
7925              else
7926                OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7927              }
7928          else          else
7929            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(needs_control_head ? 1 : 0));
7930          }          }
7931        compile_matchingpath(common, ccprev, cc, current);        compile_matchingpath(common, ccprev, cc, current);
7932        if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))        if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
# Line 7274  if (has_alternatives) Line 7936  if (has_alternatives)
7936      /* Instructions after the current alternative is succesfully matched. */      /* Instructions after the current alternative is succesfully matched. */
7937      /* There is a similar code in compile_bracket_matchingpath. */      /* There is a similar code in compile_bracket_matchingpath. */
7938      if (opcode == OP_ONCE)      if (opcode == OP_ONCE)
7939        {        match_once_common(common, ket, CURRENT_AS(bracket_backtrack)->u.framesize, private_data_ptr, has_alternatives, needs_control_head);
       if (CURRENT_AS(bracket_backtrack)->u.framesize < 0)  
         {  
         OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
         /* TMP2 which is set here used by OP_KETRMAX below. */  
         if (ket == OP_KETRMAX)  
           OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);  
         else if (ket == OP_KETRMIN)  
           {  
           /* Move the STR_PTR to the private_data_ptr. */  
           OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);  
           }  
         }  
       else  
         {  
         OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (CURRENT_AS(bracket_backtrack)->u.framesize + 2) * sizeof(sljit_sw));  
         if (ket == OP_KETRMAX)  
           {  
           /* TMP2 which is set here used by OP_KETRMAX below. */  
           OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));  
           }  
         }  
       }  
7940    
7941      stacksize = 0;      stacksize = 0;
     if (opcode != OP_ONCE)  
       stacksize++;  
7942      if (ket != OP_KET || bra != OP_BRA)      if (ket != OP_KET || bra != OP_BRA)
7943        stacksize++;        stacksize++;
7944        if (offset != 0)
7945          {
7946          if (common->capture_last_ptr != 0)
7947            stacksize++;
7948          if (common->optimized_cbracket[offset >> 1] == 0)
7949            stacksize += 2;
7950          }
7951        if (opcode != OP_ONCE)
7952          stacksize++;
7953    
7954      if (stacksize > 0) {      if (stacksize > 0)
7955          {
7956        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize >= 0)        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
7957          allocate_stack(common, stacksize);          allocate_stack(common, stacksize);
7958        else        else
# Line 7313  if (has_alternatives) Line 7961  if (has_alternatives)
7961          SLJIT_ASSERT(stacksize == 1);          SLJIT_ASSERT(stacksize == 1);
7962          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));
7963          }          }
7964      }        }
7965    
7966      stacksize = 0;      stacksize = 0;
7967      if (ket != OP_KET || bra != OP_BRA)      if (ket != OP_KET || bra != OP_BRA)
# Line 7325  if (has_alternatives) Line 7973  if (has_alternatives)
7973        stacksize++;        stacksize++;
7974        }        }
7975    
7976        if (offset != 0)
7977          stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);
7978    
7979      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
7980        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, count++);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, count++);
7981    
7982      if (offset != 0)      if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0)
7983        {        {
7984        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        /* If ket is not OP_KETRMAX, this code path is executed after the jump to alternative_matchingpath. */
7985          SLJIT_ASSERT(private_data_ptr == OVECTOR(offset + 0));
7986        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 0), TMP1, 0);  
7987        }        }
7988    
7989      JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->alternative_matchingpath);      JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->alternative_matchingpath);
# Line 7357  if (has_alternatives) Line 8008  if (has_alternatives)
8008      SLJIT_ASSERT(opcode == OP_COND || opcode == OP_SCOND);      SLJIT_ASSERT(opcode == OP_COND || opcode == OP_SCOND);
8009      assert = CURRENT_AS(bracket_backtrack)->u.assert;      assert = CURRENT_AS(bracket_backtrack)->u.assert;
8010      if ((ccbegin[1 + LINK_SIZE] == OP_ASSERT_NOT || ccbegin[1 + LINK_SIZE] == OP_ASSERTBACK_NOT) && assert->framesize >= 0)      if ((ccbegin[1 + LINK_SIZE] == OP_ASSERT_NOT || ccbegin[1 + LINK_SIZE] == OP_ASSERTBACK_NOT) && assert->framesize >= 0)
   
8011        {        {
8012        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->private_data_ptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->private_data_ptr);
8013        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
# Line 7374  if (has_alternatives) Line 8024  if (has_alternatives)
8024  if (offset != 0)  if (offset != 0)
8025    {    {
8026    /* Using both tmp register is better for instruction scheduling. */    /* Using both tmp register is better for instruction scheduling. */
8027    if (common->optimized_cbracket[offset >> 1] == 0)    if (common->optimized_cbracket[offset >> 1] != 0)
8028      {      {
8029      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8030      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
8031        free_stack(common, 2);
8032      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(2));  
     free_stack(common, 3);  
8033      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);  
8034      }      }
8035    else    else
8036      {      {
8037      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8038      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      free_stack(common, 1);
8039      free_stack(common, 2);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);  
8040      }      }
8041    }    }
8042  else if (opcode == OP_SBRA || opcode == OP_SCOND)  else if (opcode == OP_SBRA || opcode == OP_SCOND)
# Line 7401  else if (opcode == OP_SBRA || opcode == Line 8047  else if (opcode == OP_SBRA || opcode ==
8047  else if (opcode == OP_ONCE)  else if (opcode == OP_ONCE)
8048    {    {
8049    cc = ccbegin + GET(ccbegin, 1);    cc = ccbegin + GET(ccbegin, 1);
8050      stacksize = needs_control_head ? 1 : 0;
8051    
8052    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
8053      {      {
8054      /* Reset head and drop saved frame. */      /* Reset head and drop saved frame. */
8055      stacksize = (ket == OP_KETRMAX || ket == OP_KETRMIN || *cc == OP_ALT) ? 2 : 1;      stacksize += CURRENT_AS(bracket_backtrack)->u.framesize + ((ket != OP_KET || *cc == OP_ALT) ? 2 : 1);
     free_stack(common, CURRENT_AS(bracket_backtrack)->u.framesize + stacksize);  
8056      }      }
8057    else if (ket == OP_KETRMAX || (*cc == OP_ALT && ket != OP_KETRMIN))    else if (ket == OP_KETRMAX || (*cc == OP_ALT && ket != OP_KETRMIN))
8058      {      {
8059      /* The STR_PTR must be released. */      /* The STR_PTR must be released. */
8060      free_stack(common, 1);      stacksize++;
8061      }      }
8062      free_stack(common, stacksize);
8063    
8064    JUMPHERE(once);    JUMPHERE(once);
8065    /* Restore previous private_data_ptr */    /* Restore previous private_data_ptr */
# Line 7477  if (CURRENT_AS(bracketpos_backtrack)->fr Line 8125  if (CURRENT_AS(bracketpos_backtrack)->fr
8125      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8126      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
8127      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
8128        if (common->capture_last_ptr != 0)
8129          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
8130      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);
8131        if (common->capture_last_ptr != 0)
8132          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, TMP1, 0);
8133      }      }
8134    set_jumps(current->topbacktracks, LABEL());    set_jumps(current->topbacktracks, LABEL());
8135    free_stack(common, CURRENT_AS(bracketpos_backtrack)->stacksize);    free_stack(common, CURRENT_AS(bracketpos_backtrack)->stacksize);
# Line 7663  while (current) Line 8315  while (current)
8315      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP1, 0);
8316      break;      break;
8317    
8318        case OP_PRUNE:
8319        case OP_PRUNE_ARG:
8320        case OP_SKIP:
8321        if (!common->local_exit)
8322          {
8323          SLJIT_ASSERT(common->control_head_ptr != 0);
8324          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
8325          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
8326          sljit_emit_ijump(compiler, SLJIT_CALL1, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_check_control_chain));
8327          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
8328    
8329          OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
8330          add_jump(compiler, &common->reset_match, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, -1));
8331    
8332          OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);
8333          }
8334    
8335        /* Commit or in recurse or accept. */
8336        if (common->quit_label == NULL)
8337          add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));
8338        else
8339          JUMPTO(SLJIT_JUMP, common->quit_label);
8340        break;
8341    
8342      case OP_COMMIT:      case OP_COMMIT:
8343      OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);      if (!common->local_exit)
8344      if (common->quitlabel == NULL)        OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);
8345        if (common->quit_label == NULL)
8346        add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));        add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));
8347      else      else
8348        JUMPTO(SLJIT_JUMP, common->quitlabel);        JUMPTO(SLJIT_JUMP, common->quit_label);
8349      break;      break;
8350    
8351        case OP_CALLOUT:
8352      case OP_FAIL:      case OP_FAIL:
8353      case OP_ACCEPT:      case OP_ACCEPT:
8354      case OP_ASSERT_ACCEPT:      case OP_ASSERT_ACCEPT:
# Line 7691  DEFINE_COMPILER; Line 8369  DEFINE_COMPILER;
8369  pcre_uchar *cc = common->start + common->currententry->start;  pcre_uchar *cc = common->start + common->currententry->start;
8370  pcre_uchar *ccbegin = cc + 1 + LINK_SIZE + (*cc == OP_BRA ? 0 : IMM2_SIZE);  pcre_uchar *ccbegin = cc + 1 + LINK_SIZE + (*cc == OP_BRA ? 0 : IMM2_SIZE);
8371  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc);
8372  int private_data_size = get_private_data_length_for_copy(common, ccbegin, ccend);  BOOL needs_control_head;
8373  int framesize = get_framesize(common, cc, TRUE);  int framesize = get_framesize(common, cc, TRUE, &needs_control_head);
8374    int private_data_size = get_private_data_copy_length(common, ccbegin, ccend, needs_control_head);
8375  int alternativesize;  int alternativesize;
8376  BOOL needsframe;  BOOL needs_frame;
8377  backtrack_common altbacktrack;  backtrack_common altbacktrack;
 struct sljit_label *save_quitlabel = common->quitlabel;  
 jump_list *save_quit = common->quit;  
8378  struct sljit_jump *jump;  struct sljit_jump *jump;
8379    
8380  SLJIT_ASSERT(*cc == OP_BRA || *cc == OP_CBRA || *cc == OP_CBRAPOS || *cc == OP_SCBRA || *cc == OP_SCBRAPOS);  SLJIT_ASSERT(*cc == OP_BRA || *cc == OP_CBRA || *cc == OP_CBRAPOS || *cc == OP_SCBRA || *cc == OP_SCBRAPOS);
8381  needsframe = framesize >= 0;  needs_frame = framesize >= 0;
8382  if (!needsframe)  if (!needs_frame)
8383    framesize = 0;    framesize = 0;
8384  alternativesize = *(cc + GET(cc, 1)) == OP_ALT ? 1 : 0;  alternativesize = *(cc + GET(cc, 1)) == OP_ALT ? 1 : 0;
8385    
8386  SLJIT_ASSERT(common->currententry->entry == NULL && common->recursive_head != 0);  SLJIT_ASSERT(common->currententry->entry == NULL && common->recursive_head_ptr != 0);
8387  common->currententry->entry = LABEL();  common->currententry->entry = LABEL();
8388  set_jumps(common->currententry->calls, common->currententry->entry);  set_jumps(common->currententry->calls, common->currententry->entry);
8389    
8390  sljit_emit_fast_enter(compiler, TMP2, 0);  sljit_emit_fast_enter(compiler, TMP2, 0);
8391  allocate_stack(common, private_data_size + framesize + alternativesize);  allocate_stack(common, private_data_size + framesize + alternativesize);
8392  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(private_data_size + framesize + alternativesize - 1), TMP2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(private_data_size + framesize + alternativesize - 1), TMP2, 0);
8393  copy_private_data(common, ccbegin, ccend, TRUE, private_data_size + framesize + alternativesize, framesize + alternativesize);  copy_private_data(common, ccbegin, ccend, TRUE, private_data_size + framesize + alternativesize, framesize + alternativesize, needs_control_head);
8394  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head, STACK_TOP, 0);  if (needs_control_head)
8395  if (needsframe)    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
8396    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr, STACK_TOP, 0);
8397    if (needs_frame)
8398    init_frame(common, cc, framesize + alternativesize - 1, alternativesize, TRUE);    init_frame(common, cc, framesize + alternativesize - 1, alternativesize, TRUE);
8399    
8400  if (alternativesize > 0)  if (alternativesize > 0)
8401    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
8402    
8403  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
8404  common->quitlabel = NULL;  common->quit_label = NULL;
8405  common->acceptlabel = NULL;  common->accept_label = NULL;
8406  common->quit = NULL;  common->quit = NULL;
8407  common->accept = NULL;  common->accept = NULL;
8408  altbacktrack.cc = ccbegin;  altbacktrack.cc = ccbegin;
# Line 7738  while (1) Line 8417  while (1)
8417    
8418    compile_matchingpath(common, altbacktrack.cc, cc, &altbacktrack);    compile_matchingpath(common, altbacktrack.cc, cc, &altbacktrack);
8419    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
     {  
     common->quitlabel = save_quitlabel;  
     common->quit = save_quit;  
8420      return;      return;
     }  
8421    
8422    add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP));    add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP));
8423    
8424    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
8425    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
     {  
     common->quitlabel = save_quitlabel;  
     common->quit = save_quit;  
8426      return;      return;
     }  
8427    set_jumps(altbacktrack.topbacktracks, LABEL());    set_jumps(altbacktrack.topbacktracks, LABEL());
8428    
8429    if (*cc != OP_ALT)    if (*cc != OP_ALT)
# Line 7761  while (1) Line 8432  while (1)
8432    altbacktrack.cc = cc + 1 + LINK_SIZE;    altbacktrack.cc = cc + 1 + LINK_SIZE;
8433    cc += GET(cc, 1);    cc += GET(cc, 1);
8434    }    }
 /* None of them matched. */  
 if (common->quit != NULL)  
   set_jumps(common->quit, LABEL());  
8435    
8436    /* None of them matched. */
8437  OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 0);
8438  jump = JUMP(SLJIT_JUMP);  jump = JUMP(SLJIT_JUMP);
8439    
8440    if (common->quit != NULL)
8441      {
8442      set_jumps(common->quit, LABEL());
8443      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr);
8444      if (needs_frame)
8445        {
8446        OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + alternativesize) * sizeof(sljit_sw));
8447        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
8448        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + alternativesize) * sizeof(sljit_sw));
8449        }
8450      OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 0);
8451      common->quit = NULL;
8452      add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));
8453      }
8454    
8455  set_jumps(common->accept, LABEL());  set_jumps(common->accept, LABEL());
8456  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head);  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr);
8457  if (needsframe)  if (needs_frame)
8458    {    {
8459    OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + alternativesize) * sizeof(sljit_sw));    OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + alternativesize) * sizeof(sljit_sw));
8460    add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
# Line 7779  if (needsframe) Line 8463  if (needsframe)
8463  OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 1);  OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 1);
8464    
8465  JUMPHERE(jump);  JUMPHERE(jump);
8466  copy_private_data(common, ccbegin, ccend, FALSE, private_data_size + framesize + alternativesize, framesize + alternativesize);  if (common->quit != NULL)
8467      set_jumps(common->quit, LABEL());
8468    copy_private_data(common, ccbegin, ccend, FALSE, private_data_size + framesize + alternativesize, framesize + alternativesize, needs_control_head);
8469  free_stack(common, private_data_size + framesize + alternativesize);  free_stack(common, private_data_size + framesize + alternativesize);
8470  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), sizeof(sljit_sw));  if (needs_control_head)
8471  OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    {
8472  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head, TMP2, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 2 * sizeof(sljit_sw));
8473      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), sizeof(sljit_sw));
8474      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr, TMP1, 0);
8475      OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
8476      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP2, 0);
8477      }
8478    else
8479      {
8480      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), sizeof(sljit_sw));
8481      OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
8482      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr, TMP2, 0);
8483      }
8484  sljit_emit_fast_return(compiler, SLJIT_MEM1(STACK_TOP), 0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(STACK_TOP), 0);
   
 common->quitlabel = save_quitlabel;  
 common->quit = save_quit;  
8485  }  }
8486    
8487  #undef COMPILE_BACKTRACKINGPATH  #undef COMPILE_BACKTRACKINGPATH
# Line 7807  pcre_uchar *ccend; Line 8501  pcre_uchar *ccend;
8501  executable_functions *functions;  executable_functions *functions;
8502  void *executable_func;  void *executable_func;
8503  sljit_uw executable_size;  sljit_uw executable_size;
8504  struct sljit_label *mainloop = NULL;  struct sljit_label *mainloop_label = NULL;
8505  struct sljit_label *empty_match_found;  struct sljit_label *continue_match_label;
8506  struct sljit_label *empty_match_backtrack;  struct sljit_label *empty_match_found_label;
8507    struct sljit_label *empty_match_backtrack_label;
8508    struct sljit_label *reset_match_label;
8509  struct sljit_jump *jump;  struct sljit_jump *jump;
8510    struct sljit_jump *minlength_check_failed = NULL;
8511  struct sljit_jump *reqbyte_notfound = NULL;  struct sljit_jump *reqbyte_notfound = NULL;
8512  struct sljit_jump *empty_match;  struct sljit_jump *empty_match;
8513    struct sljit_label *quit_label;
8514    
8515  SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);  SLJIT_ASSERT((extra->flags & PCRE_EXTRA_STUDY_DATA) != 0);
8516  study = extra->study_data;  study = extra->study_data;
# Line 7881  common->ovector_start = CALL_LIMIT + siz Line 8579  common->ovector_start = CALL_LIMIT + siz
8579  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);
8580  if (!common->optimized_cbracket)  if (!common->optimized_cbracket)
8581    return;    return;
8582    #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 1
8583    memset(common->optimized_cbracket, 0, re->top_bracket + 1);
8584    #else
8585  memset(common->optimized_cbracket, 1, re->top_bracket + 1);  memset(common->optimized_cbracket, 1, re->top_bracket + 1);
8586    #endif
8587    
8588  SLJIT_ASSERT(*rootbacktrack.cc == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);  SLJIT_ASSERT(*rootbacktrack.cc == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);
8589    #if defined DEBUG_FORCE_UNOPTIMIZED_CBRAS && DEBUG_FORCE_UNOPTIMIZED_CBRAS == 2
8590    common->capture_last_ptr = common->ovector_start;
8591    common->ovector_start += sizeof(sljit_sw);
8592    #endif
8593  private_data_size = get_private_data_length(common, rootbacktrack.cc, ccend);  private_data_size = get_private_data_length(common, rootbacktrack.cc, ccend);
8594  if (private_data_size < 0)  if (private_data_size < 0)
8595    {    {
# Line 7904  if (mode != JIT_COMPILE) Line 8610  if (mode != JIT_COMPILE)
8610    if (mode == JIT_PARTIAL_SOFT_COMPILE)    if (mode == JIT_PARTIAL_SOFT_COMPILE)
8611      {      {
8612      common->hit_start = common->ovector_start;      common->hit_start = common->ovector_start;
8613      common->ovector_start += sizeof(sljit_sw);      common->ovector_start += 2 * sizeof(sljit_sw);
8614        }
8615      else
8616        {
8617        SLJIT_ASSERT(mode == JIT_PARTIAL_HARD_COMPILE);
8618        common->needs_start_ptr = TRUE;
8619      }      }
8620    }    }
8621  if ((re->options & PCRE_FIRSTLINE) != 0)  if ((re->options & PCRE_FIRSTLINE) != 0)
# Line 7912  if ((re->options & PCRE_FIRSTLINE) != 0) Line 8623  if ((re->options & PCRE_FIRSTLINE) != 0)
8623    common->first_line_end = common->ovector_start;    common->first_line_end = common->ovector_start;
8624    common->ovector_start += sizeof(sljit_sw);    common->ovector_start += sizeof(sljit_sw);
8625    }    }
8626    #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
8627    common->control_head_ptr = 1;
8628    #endif
8629    if (common->control_head_ptr != 0)
8630      {
8631      common->control_head_ptr = common->ovector_start;
8632      common->ovector_start += sizeof(sljit_sw);
8633      }
8634    if (common->needs_start_ptr && common->has_set_som)
8635      {
8636      /* Saving the real start pointer is necessary. */
8637      common->start_ptr = common->ovector_start;
8638      common->ovector_start += sizeof(sljit_sw);
8639      }
8640    else
8641      common->needs_start_ptr = FALSE;
8642    
8643  /* Aligning ovector to even number of sljit words. */  /* Aligning ovector to even number of sljit words. */
8644  if ((common->ovector_start & sizeof(sljit_sw)) != 0)  if ((common->ovector_start & sizeof(sljit_sw)) != 0)
8645    common->ovector_start += sizeof(sljit_sw);    common->ovector_start += sizeof(sljit_sw);
8646    
8647    if (common->start_ptr == 0)
8648      common->start_ptr = OVECTOR(0);
8649    
8650    /* Capturing brackets cannot be optimized if callouts are allowed. */
8651    if (common->capture_last_ptr != 0)
8652      memset(common->optimized_cbracket, 0, re->top_bracket + 1);
8653    
8654  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));
8655  common->cbraptr = OVECTOR_START + (re->top_bracket + 1) * 2 * sizeof(sljit_sw);  common->cbra_ptr = OVECTOR_START + (re->top_bracket + 1) * 2 * sizeof(sljit_sw);
8656  private_data_size += common->cbraptr + (re->top_bracket + 1) * sizeof(sljit_sw);  private_data_size += common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw);
8657  if (private_data_size > SLJIT_MAX_LOCAL_SIZE)  if (private_data_size > SLJIT_MAX_LOCAL_SIZE)
8658    {    {
8659    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
# Line 7932  if (!common->private_data_ptrs) Line 8666  if (!common->private_data_ptrs)
8666    return;    return;
8667    }    }
8668  memset(common->private_data_ptrs, 0, (ccend - rootbacktrack.cc) * sizeof(int));  memset(common->private_data_ptrs, 0, (ccend - rootbacktrack.cc) * sizeof(int));
8669  set_private_data_ptrs(common, common->cbraptr + (re->top_bracket + 1) * sizeof(sljit_sw), ccend);  set_private_data_ptrs(common, common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw), ccend);
8670    
8671  compiler = sljit_create_compiler();  compiler = sljit_create_compiler();
8672  if (!compiler)  if (!compiler)
# Line 7956  OP1(SLJIT_MOV, TMP1, 0, SLJIT_SAVED_REG1 Line 8690  OP1(SLJIT_MOV, TMP1, 0, SLJIT_SAVED_REG1
8690  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
8691  OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, end));  OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, end));
8692  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, stack));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, stack));
8693  OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, calllimit));  OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, call_limit));
8694  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, base));  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, base));
8695  OP1(SLJIT_MOV, STACK_LIMIT, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, limit));  OP1(SLJIT_MOV, STACK_LIMIT, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, limit));
8696  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CALL_LIMIT, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CALL_LIMIT, TMP1, 0);
8697    
8698  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
8699    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
8700    if (common->mark_ptr != 0)
8701      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
8702    if (common->control_head_ptr != 0)
8703      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
8704    
8705  /* Main part of the matching */  /* Main part of the matching */
8706  if ((re->options & PCRE_ANCHORED) == 0)  if ((re->options & PCRE_ANCHORED) == 0)
8707    {    {
8708    mainloop = mainloop_entry(common, (re->flags & PCRE_HASCRORLF) != 0, (re->options & PCRE_FIRSTLINE) != 0);    mainloop_label = mainloop_entry(common, (re->flags & PCRE_HASCRORLF) != 0, (re->options & PCRE_FIRSTLINE) != 0);
8709      continue_match_label = LABEL();
8710    /* Forward search if possible. */    /* Forward search if possible. */
8711    if ((re->options & PCRE_NO_START_OPTIMIZE) == 0)    if ((re->options & PCRE_NO_START_OPTIMIZE) == 0)
8712      {      {
# Line 7981  if ((re->options & PCRE_ANCHORED) == 0) Line 8720  if ((re->options & PCRE_ANCHORED) == 0)
8720        fast_forward_start_bits(common, (sljit_uw)study->start_bits, (re->options & PCRE_FIRSTLINE) != 0);        fast_forward_start_bits(common, (sljit_uw)study->start_bits, (re->options & PCRE_FIRSTLINE) != 0);
8721      }      }
8722    }    }
8723    else
8724      continue_match_label = LABEL();
8725    
8726    if (mode == JIT_COMPILE && study->minlength > 0 && (re->options & PCRE_NO_START_OPTIMIZE) == 0)
8727      {
8728      OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);
8729      OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(study->minlength));
8730      minlength_check_failed = CMP(SLJIT_C_GREATER, TMP2, 0, STR_END, 0);
8731      }
8732  if (common->req_char_ptr != 0)  if (common->req_char_ptr != 0)
8733    reqbyte_notfound = search_requested_char(common, (pcre_uchar)re->req_char, (re->flags & PCRE_RCH_CASELESS) != 0, (re->flags & PCRE_FIRSTSET) != 0);    reqbyte_notfound = search_requested_char(common, (pcre_uchar)re->req_char, (re->flags & PCRE_RCH_CASELESS) != 0, (re->flags & PCRE_FIRSTSET) != 0);
8734    
# Line 7988  if (common->req_char_ptr != 0) Line 8736  if (common->req_char_ptr != 0)
8736  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), STR_PTR, 0);
8737  /* Copy the limit of allowed recursions. */  /* Copy the limit of allowed recursions. */
8738  OP1(SLJIT_MOV, CALL_COUNT, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), CALL_LIMIT);  OP1(SLJIT_MOV, CALL_COUNT, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), CALL_LIMIT);
8739  if (common->mark_ptr != 0)  if (common->capture_last_ptr != 0)
8740    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, -1);
8741    
8742    if (common->needs_start_ptr)
8743      {
8744      SLJIT_ASSERT(common->start_ptr != OVECTOR(0));
8745      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr, STR_PTR, 0);
8746      }
8747    else
8748      SLJIT_ASSERT(common->start_ptr == OVECTOR(0));
8749    
8750  /* Copy the beginning of the string. */  /* Copy the beginning of the string. */
8751  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
8752    {    {
8753    jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);    jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);
8754    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);
8755      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start + sizeof(sljit_sw), STR_PTR, 0);
8756    JUMPHERE(jump);    JUMPHERE(jump);
8757    }    }
8758  else if (mode == JIT_PARTIAL_HARD_COMPILE)  else if (mode == JIT_PARTIAL_HARD_COMPILE)
# Line 8010  if (SLJIT_UNLIKELY(sljit_get_compiler_er Line 8768  if (SLJIT_UNLIKELY(sljit_get_compiler_er
8768    }    }
8769    
8770  empty_match = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));  empty_match = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
8771  empty_match_found = LABEL();  empty_match_found_label = LABEL();
8772    
8773  common->acceptlabel = LABEL();  common->accept_label = LABEL();
8774  if (common->accept != NULL)  if (common->accept != NULL)
8775    set_jumps(common->accept, common->acceptlabel);    set_jumps(common->accept, common->accept_label);
8776    
8777  /* This means we have a match. Update the ovector. */  /* This means we have a match. Update the ovector. */
8778  copy_ovector(common, re->top_bracket + 1);  copy_ovector(common, re->top_bracket + 1);
8779  common->quitlabel = LABEL();  common->quit_label = common->forced_quit_label = LABEL();
8780  if (common->quit != NULL)  if (common->quit != NULL)
8781    set_jumps(common->quit, common->quitlabel);    set_jumps(common->quit, common->quit_label);
8782    if (common->forced_quit != NULL)
8783      set_jumps(common->forced_quit, common->forced_quit_label);
8784    if (minlength_check_failed != NULL)
8785      SET_LABEL(minlength_check_failed, common->forced_quit_label);
8786  sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);  sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
8787    
8788  if (mode != JIT_COMPILE)  if (mode != JIT_COMPILE)
8789    {    {
8790    common->partialmatchlabel = LABEL();    common->partialmatchlabel = LABEL();
8791    set_jumps(common->partialmatch, common->partialmatchlabel);    set_jumps(common->partialmatch, common->partialmatchlabel);
8792    return_with_partial_match(common, common->quitlabel);    return_with_partial_match(common, common->quit_label);
8793    }    }
8794    
8795  empty_match_backtrack = LABEL();  empty_match_backtrack_label = LABEL();
8796  compile_backtrackingpath(common, rootbacktrack.top);  compile_backtrackingpath(common, rootbacktrack.top);
8797  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
8798    {    {
# Line 8041  if (SLJIT_UNLIKELY(sljit_get_compiler_er Line 8803  if (SLJIT_UNLIKELY(sljit_get_compiler_er
8803    }    }
8804    
8805  SLJIT_ASSERT(rootbacktrack.prev == NULL);  SLJIT_ASSERT(rootbacktrack.prev == NULL);
8806    reset_match_label = LABEL();
8807    
8808  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
8809    {    {
8810    /* Update hit_start only in the first time. */    /* Update hit_start only in the first time. */
8811    jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
8812    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr);
8813    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
8814    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, TMP1, 0);
# Line 8053  if (mode == JIT_PARTIAL_SOFT_COMPILE) Line 8816  if (mode == JIT_PARTIAL_SOFT_COMPILE)
8816    }    }
8817    
8818  /* Check we have remaining characters. */  /* Check we have remaining characters. */
8819  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));  if ((re->options & PCRE_ANCHORED) == 0 && (re->options & PCRE_FIRSTLINE) != 0)
8820      {
8821      SLJIT_ASSERT(common->first_line_end != 0);
8822      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
8823      }
8824    
8825    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
8826    
8827  if ((re->options & PCRE_ANCHORED) == 0)  if ((re->options & PCRE_ANCHORED) == 0)
8828    {    {
8829    if ((re->options & PCRE_FIRSTLINE) == 0)    if ((re->options & PCRE_FIRSTLINE) == 0)
8830      {      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop_label);
     if (mode == JIT_COMPILE && study != NULL && study->minlength > 1 && (re->options & PCRE_NO_START_OPTIMIZE) == 0)  
       {  
       OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(study->minlength + 1));  
       CMPTO(SLJIT_C_LESS_EQUAL, TMP1, 0, STR_END, 0, mainloop);  
       }  
     else  
       CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);  
     }  
8831    else    else
8832      {      CMPTO(SLJIT_C_LESS, STR_PTR, 0, TMP1, 0, mainloop_label);
     SLJIT_ASSERT(common->first_line_end != 0);  
     if (mode == JIT_COMPILE && study != NULL && study->minlength > 1 && (re->options & PCRE_NO_START_OPTIMIZE) == 0)  
       {  
       OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(study->minlength + 1));  
       OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, STR_END, 0);  
       OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);  
       OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);  
       OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);  
       JUMPTO(SLJIT_C_ZERO, mainloop);  
       }  
     else  
       CMPTO(SLJIT_C_LESS, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, mainloop);  
     }  
8833    }    }
8834    
8835  /* No more remaining characters. */  /* No more remaining characters. */
# Line 8089  if (reqbyte_notfound != NULL) Line 8837  if (reqbyte_notfound != NULL)
8837    JUMPHERE(reqbyte_notfound);    JUMPHERE(reqbyte_notfound);
8838    
8839  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
8840    CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0, common->partialmatchlabel);    CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1, common->partialmatchlabel);
8841    
8842  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);
8843  JUMPTO(SLJIT_JUMP, common->quitlabel);  JUMPTO(SLJIT_JUMP, common->quit_label);
8844    
8845  flush_stubs(common);  flush_stubs(common);
8846    
8847  JUMPHERE(empty_match);  JUMPHERE(empty_match);
8848  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
8849  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));
8850  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_backtrack);  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_backtrack_label);
8851  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty_atstart));  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty_atstart));
8852  CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_found);  CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, empty_match_found_label);
8853  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
8854  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, empty_match_found);  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, empty_match_found_label);
8855  JUMPTO(SLJIT_JUMP, empty_match_backtrack);  JUMPTO(SLJIT_JUMP, empty_match_backtrack_label);
8856    
8857  common->currententry = common->entries;  common->currententry = common->entries;
8858    common->local_exit = TRUE;
8859    quit_label = common->quit_label;
8860  while (common->currententry != NULL)  while (common->currententry != NULL)
8861    {    {
8862    /* Might add new entries. */    /* Might add new entries. */
# Line 8121  while (common->currententry != NULL) Line 8871  while (common->currententry != NULL)
8871    flush_stubs(common);    flush_stubs(common);
8872    common->currententry = common->currententry->next;    common->currententry = common->currententry->next;
8873    }    }
8874    common->local_exit = FALSE;
8875    common->quit_label = quit_label;
8876    
8877  /* Allocating stack, returns with PCRE_ERROR_JIT_STACKLIMIT if fails. */  /* Allocating stack, returns with PCRE_ERROR_JIT_STACKLIMIT if fails. */
8878  /* This is a (really) rare case. */  /* This is a (really) rare case. */
# Line 8146  sljit_emit_fast_return(compiler, SLJIT_M Line 8898  sljit_emit_fast_return(compiler, SLJIT_M
8898  JUMPHERE(jump);  JUMPHERE(jump);
8899  /* We break the return address cache here, but this is a really rare case. */  /* We break the return address cache here, but this is a really rare case. */
8900  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_JIT_STACKLIMIT);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_JIT_STACKLIMIT);
8901  JUMPTO(SLJIT_JUMP, common->quitlabel);  JUMPTO(SLJIT_JUMP, common->quit_label);
8902    
8903  /* Call limit reached. */  /* Call limit reached. */
8904  set_jumps(common->calllimit, LABEL());  set_jumps(common->calllimit, LABEL());
8905  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_MATCHLIMIT);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_MATCHLIMIT);
8906  JUMPTO(SLJIT_JUMP, common->quitlabel);  JUMPTO(SLJIT_JUMP, common->quit_label);
8907    
8908  if (common->revertframes != NULL)  if (common->revertframes != NULL)
8909    {    {
# Line 8188  if (common->caselesscmp != NULL) Line 8940  if (common->caselesscmp != NULL)
8940    set_jumps(common->caselesscmp, LABEL());    set_jumps(common->caselesscmp, LABEL());
8941    do_caselesscmp(common);    do_caselesscmp(common);
8942    }    }
8943    if (common->reset_match != NULL)
8944      {
8945      set_jumps(common->reset_match, LABEL());
8946      do_reset_match(common, (re->top_bracket + 1) * 2);
8947      CMPTO(SLJIT_C_GREATER, STR_PTR, 0, TMP1, 0, continue_match_label);
8948      OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
8949      JUMPTO(SLJIT_JUMP, reset_match_label);
8950      }
8951  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
8952  #ifndef COMPILE_PCRE32  #ifndef COMPILE_PCRE32
8953  if (common->utfreadchar != NULL)  if (common->utfreadchar != NULL)
# Line 8272  return convert_executable_func.call_exec Line 9032  return convert_executable_func.call_exec
9032    
9033  int  int
9034  PRIV(jit_exec)(const PUBL(extra) *extra_data, const pcre_uchar *subject,  PRIV(jit_exec)(const PUBL(extra) *extra_data, const pcre_uchar *subject,
9035    int length, int start_offset, int options, int *offsets, int offsetcount)    int length, int start_offset, int options, int *offsets, int offset_count)
9036  {  {
9037  executable_functions *functions = (executable_functions *)extra_data->executable_jit;  executable_functions *functions = (executable_functions *)extra_data->executable_jit;
9038  union {  union {
# Line 8280  union { Line 9040  union {
9040     jit_function call_executable_func;     jit_function call_executable_func;
9041  } convert_executable_func;  } convert_executable_func;
9042  jit_arguments arguments;  jit_arguments arguments;
9043  int maxoffsetcount;  int max_offset_count;
9044  int retval;  int retval;
9045  int mode = JIT_COMPILE;  int mode = JIT_COMPILE;
9046    
# Line 8298  arguments.begin = subject; Line 9058  arguments.begin = subject;
9058  arguments.end = subject + length;  arguments.end = subject + length;
9059  arguments.mark_ptr = NULL;  arguments.mark_ptr = NULL;
9060  /* JIT decreases this value less frequently than the interpreter. */  /* JIT decreases this value less frequently than the interpreter. */
9061  arguments.calllimit = ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0) ? MATCH_LIMIT : extra_data->match_limit;  arguments.call_limit = ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0) ? MATCH_LIMIT : extra_data->match_limit;
9062  arguments.notbol = (options & PCRE_NOTBOL) != 0;  arguments.notbol = (options & PCRE_NOTBOL) != 0;
9063  arguments.noteol = (options & PCRE_NOTEOL) != 0;  arguments.noteol = (options & PCRE_NOTEOL) != 0;
9064  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
9065  arguments.notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;  arguments.notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;
9066  arguments.offsets = offsets;  arguments.offsets = offsets;
9067    arguments.callout_data = (extra_data->flags & PCRE_EXTRA_CALLOUT_DATA) != 0 ? extra_data->callout_data : NULL;
9068    arguments.real_offset_count = offset_count;
9069    
9070  /* pcre_exec() rounds offsetcount to a multiple of 3, and then uses only 2/3 of  /* pcre_exec() rounds offset_count to a multiple of 3, and then uses only 2/3 of
9071  the output vector for storing captured strings, with the remainder used as  the output vector for storing captured strings, with the remainder used as
9072  workspace. We don't need the workspace here. For compatibility, we limit the  workspace. We don't need the workspace here. For compatibility, we limit the
9073  number of captured strings in the same way as pcre_exec(), so that the user  number of captured strings in the same way as pcre_exec(), so that the user
9074  gets the same result with and without JIT. */  gets the same result with and without JIT. */
9075    
9076  if (offsetcount != 2)  if (offset_count != 2)
9077    offsetcount = ((offsetcount - (offsetcount % 3)) * 2) / 3;    offset_count = ((offset_count - (offset_count % 3)) * 2) / 3;
9078  maxoffsetcount = functions->top_bracket;  max_offset_count = functions->top_bracket;
9079  if (offsetcount > maxoffsetcount)  if (offset_count > max_offset_count)
9080    offsetcount = maxoffsetcount;    offset_count = max_offset_count;
9081  arguments.offsetcount = offsetcount;  arguments.offset_count = offset_count;
9082    
9083  if (functions->callback)  if (functions->callback)
9084    arguments.stack = (struct sljit_stack *)functions->callback(functions->userdata);    arguments.stack = (struct sljit_stack *)functions->callback(functions->userdata);
# Line 8331  else Line 9093  else
9093    retval = convert_executable_func.call_executable_func(&arguments);    retval = convert_executable_func.call_executable_func(&arguments);
9094    }    }
9095    
9096  if (retval * 2 > offsetcount)  if (retval * 2 > offset_count)
9097    retval = 0;    retval = 0;
9098  if ((extra_data->flags & PCRE_EXTRA_MARK) != 0)  if ((extra_data->flags & PCRE_EXTRA_MARK) != 0)
9099    *(extra_data->mark) = arguments.mark_ptr;    *(extra_data->mark) = arguments.mark_ptr;
# Line 8343  return retval; Line 9105  return retval;
9105  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
9106  pcre_jit_exec(const pcre *argument_re, const pcre_extra *extra_data,  pcre_jit_exec(const pcre *argument_re, const pcre_extra *extra_data,
9107    PCRE_SPTR subject, int length, int start_offset, int options,    PCRE_SPTR subject, int length, int start_offset, int options,
9108    int *offsets, int offsetcount, pcre_jit_stack *stack)    int *offsets, int offset_count, pcre_jit_stack *stack)
9109  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
9110  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
9111  pcre16_jit_exec(const pcre16 *argument_re, const pcre16_extra *extra_data,  pcre16_jit_exec(const pcre16 *argument_re, const pcre16_extra *extra_data,
9112    PCRE_SPTR16 subject, int length, int start_offset, int options,    PCRE_SPTR16 subject, int length, int start_offset, int options,
9113    int *offsets, int offsetcount, pcre16_jit_stack *stack)    int *offsets, int offset_count, pcre16_jit_stack *stack)
9114  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
9115  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
9116  pcre32_jit_exec(const pcre32 *argument_re, const pcre32_extra *extra_data,  pcre32_jit_exec(const pcre32 *argument_re, const pcre32_extra *extra_data,
9117    PCRE_SPTR32 subject, int length, int start_offset, int options,    PCRE_SPTR32 subject, int length, int start_offset, int options,
9118    int *offsets, int offsetcount, pcre32_jit_stack *stack)    int *offsets, int offset_count, pcre32_jit_stack *stack)
9119  #endif  #endif
9120  {  {
9121  pcre_uchar *subject_ptr = (pcre_uchar *)subject;  pcre_uchar *subject_ptr = (pcre_uchar *)subject;
# Line 8363  union { Line 9125  union {
9125     jit_function call_executable_func;     jit_function call_executable_func;
9126  } convert_executable_func;  } convert_executable_func;
9127  jit_arguments arguments;  jit_arguments arguments;
9128  int maxoffsetcount;  int max_offset_count;
9129  int retval;  int retval;
9130  int mode = JIT_COMPILE;  int mode = JIT_COMPILE;
9131    
# Line 8387  arguments.begin = subject_ptr; Line 9149  arguments.begin = subject_ptr;
9149  arguments.end = subject_ptr + length;  arguments.end = subject_ptr + length;
9150  arguments.mark_ptr = NULL;  arguments.mark_ptr = NULL;
9151  /* JIT decreases this value less frequently than the interpreter. */  /* JIT decreases this value less frequently than the interpreter. */
9152  arguments.calllimit = ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0) ? MATCH_LIMIT : extra_data->match_limit;  arguments.call_limit = ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0) ? MATCH_LIMIT : extra_data->match_limit;
9153  arguments.notbol = (options & PCRE_NOTBOL) != 0;  arguments.notbol = (options & PCRE_NOTBOL) != 0;
9154  arguments.noteol = (options & PCRE_NOTEOL) != 0;  arguments.noteol = (options & PCRE_NOTEOL) != 0;
9155  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
9156  arguments.notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;  arguments.notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;
9157  arguments.offsets = offsets;  arguments.offsets = offsets;
9158    arguments.callout_data = (extra_data->flags & PCRE_EXTRA_CALLOUT_DATA) != 0 ? extra_data->callout_data : NULL;
9159    arguments.real_offset_count = offset_count;
9160    
9161  /* pcre_exec() rounds offsetcount to a multiple of 3, and then uses only 2/3 of  /* pcre_exec() rounds offset_count to a multiple of 3, and then uses only 2/3 of
9162  the output vector for storing captured strings, with the remainder used as  the output vector for storing captured strings, with the remainder used as
9163  workspace. We don't need the workspace here. For compatibility, we limit the  workspace. We don't need the workspace here. For compatibility, we limit the
9164  number of captured strings in the same way as pcre_exec(), so that the user  number of captured strings in the same way as pcre_exec(), so that the user
9165  gets the same result with and without JIT. */  gets the same result with and without JIT. */
9166    
9167  if (offsetcount != 2)  if (offset_count != 2)
9168    offsetcount = ((offsetcount - (offsetcount % 3)) * 2) / 3;    offset_count = ((offset_count - (offset_count % 3)) * 2) / 3;
9169  maxoffsetcount = functions->top_bracket;  max_offset_count = functions->top_bracket;
9170  if (offsetcount > maxoffsetcount)  if (offset_count > max_offset_count)
9171    offsetcount = maxoffsetcount;    offset_count = max_offset_count;
9172  arguments.offsetcount = offsetcount;  arguments.offset_count = offset_count;
9173    
9174  convert_executable_func.executable_func = functions->executable_funcs[mode];  convert_executable_func.executable_func = functions->executable_funcs[mode];
9175  retval = convert_executable_func.call_executable_func(&arguments);  retval = convert_executable_func.call_executable_func(&arguments);
9176    
9177  if (retval * 2 > offsetcount)  if (retval * 2 > offset_count)
9178    retval = 0;    retval = 0;
9179  if ((extra_data->flags & PCRE_EXTRA_MARK) != 0)  if ((extra_data->flags & PCRE_EXTRA_MARK) != 0)
9180    *(extra_data->mark) = arguments.mark_ptr;    *(extra_data->mark) = arguments.mark_ptr;

Legend:
Removed from v.1239  
changed lines
  Added in v.1277

  ViewVC Help
Powered by ViewVC 1.1.5