/[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 1195 by zherczeg, Thu Nov 1 15:21:27 2012 UTC revision 1279 by zherczeg, Tue Mar 12 17:27:34 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 bytecode_flag_types {
200      flag_optimized_cbracket = 1,
201      flag_then_start = 2,
202    };
203    
204    enum frame_types {
205      no_frame = -1,
206      no_stack = -2
207    };
208    
209    enum control_types {
210      type_commit = 0,
211      type_prune = 1,
212      type_skip = 2,
213      type_skip_arg = 3,
214      type_mark = 4,
215      type_then_trap = 5
216    };
217    
218  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
219    
220  /* 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 235  typedef struct backtrack_common {
235  typedef struct assert_backtrack {  typedef struct assert_backtrack {
236    backtrack_common common;    backtrack_common common;
237    jump_list *condfailed;    jump_list *condfailed;
238    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
239    int framesize;    int framesize;
240    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
241    int private_data_ptr;    int private_data_ptr;
# Line 230  typedef struct bracket_backtrack { Line 256  typedef struct bracket_backtrack {
256      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
257      jump_list *condfailed;      jump_list *condfailed;
258      assert_backtrack *assert;      assert_backtrack *assert;
259      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
260      int framesize;      int framesize;
261    } u;    } u;
262    /* 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 296  typedef struct recurse_entry {
296    
297  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
298    backtrack_common common;    backtrack_common common;
299      BOOL inlined_pattern;
300  } recurse_backtrack;  } recurse_backtrack;
301    
302    typedef struct then_trap_backtrack {
303      backtrack_common common;
304      struct then_trap_backtrack *then_trap;
305      jump_list *quit;
306      int framesize;
307    } then_trap_backtrack;
308    
309  #define MAX_RANGE_SIZE 6  #define MAX_RANGE_SIZE 6
310    
311  typedef struct compiler_common {  typedef struct compiler_common {
312      /* The sljit ceneric compiler. */
313    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
314      /* First byte code. */
315    pcre_uchar *start;    pcre_uchar *start;
   
316    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
317    int *private_data_ptrs;    int *private_data_ptrs;
318    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
319    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
320      /* Tells whether the starting offset is a target of then. */
321      pcre_uint8 *then_offsets;
322      /* Current position where a THEN must jump. */
323      then_trap_backtrack *then_trap;
324    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
325    int cbraptr;    int cbra_ptr;
326    /* OVector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
327    int ovector_start;    int ovector_start;
328    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
329    int req_char_ptr;    int req_char_ptr;
330    /* Head of the last recursion. */    /* Head of the last recursion. */
331    int recursive_head;    int recursive_head_ptr;
332    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
333    int start_used_ptr;    int start_used_ptr;
334    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 298  typedef struct compiler_common { Line 337  typedef struct compiler_common {
337    int first_line_end;    int first_line_end;
338    /* Points to the marked string. */    /* Points to the marked string. */
339    int mark_ptr;    int mark_ptr;
340      /* Recursive control verb management chain. */
341      int control_head_ptr;
342      /* Points to the last matched capture block index. */
343      int capture_last_ptr;
344      /* Points to the starting position of the current match. */
345      int start_ptr;
346    
347    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
348    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
349    sljit_sw lcc;    sljit_sw lcc;
350    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
351    int mode;    int mode;
352      /* \K is found in the pattern. */
353      BOOL has_set_som;
354      /* (*SKIP:arg) is found in the pattern. */
355      BOOL has_skip_arg;
356      /* (*THEN) is found in the pattern. */
357      BOOL has_then;
358      /* Needs to know the start position anytime. */
359      BOOL needs_start_ptr;
360      /* Currently in recurse or assert. */
361      BOOL local_exit;
362    /* Newline control. */    /* Newline control. */
363    int nltype;    int nltype;
364    int newline;    int newline;
365    int bsr_nltype;    int bsr_nltype;
366    /* Dollar endonly. */    /* Dollar endonly. */
367    int endonly;    int endonly;
   BOOL has_set_som;  
368    /* Tables. */    /* Tables. */
369    sljit_sw ctypes;    sljit_sw ctypes;
370    int digits[2 + MAX_RANGE_SIZE];    int digits[2 + MAX_RANGE_SIZE];
# Line 321  typedef struct compiler_common { Line 375  typedef struct compiler_common {
375    
376    /* Labels and jump lists. */    /* Labels and jump lists. */
377    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
378    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
379    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
380      struct sljit_label *accept_label;
381    stub_list *stubs;    stub_list *stubs;
382    recurse_entry *entries;    recurse_entry *entries;
383    recurse_entry *currententry;    recurse_entry *currententry;
384    jump_list *partialmatch;    jump_list *partialmatch;
385    jump_list *quit;    jump_list *quit;
386      jump_list *forced_quit;
387    jump_list *accept;    jump_list *accept;
388    jump_list *calllimit;    jump_list *calllimit;
389    jump_list *stackalloc;    jump_list *stackalloc;
# Line 338  typedef struct compiler_common { Line 394  typedef struct compiler_common {
394    jump_list *vspace;    jump_list *vspace;
395    jump_list *casefulcmp;    jump_list *casefulcmp;
396    jump_list *caselesscmp;    jump_list *caselesscmp;
397      jump_list *reset_match;
398    BOOL jscript_compat;    BOOL jscript_compat;
399  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
400    BOOL utf;    BOOL utf;
# Line 390  typedef struct compare_context { Line 447  typedef struct compare_context {
447  #endif  #endif
448  } compare_context;  } compare_context;
449    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
450  /* Undefine sljit macros. */  /* Undefine sljit macros. */
451  #undef CMP  #undef CMP
452    
453  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
454  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
455    
456  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
457  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
458  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
459  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
460  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
461  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
462  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
463  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
464  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
# Line 428  group contains the start / end character Line 479  group contains the start / end character
479  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. */
480  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
481  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
482  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_sw))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * sizeof(sljit_sw))
483  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
484    
485  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
# Line 459  the start pointers when the end of the c Line 510  the start pointers when the end of the c
510    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
511  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
512    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
513    #define SET_LABEL(jump, label) \
514      sljit_set_label((jump), (label))
515  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
516    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
517  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
518    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))    sljit_set_label(sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w)), (label))
519  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
520    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
521  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
522    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
523    
# Line 483  return cc; Line 536  return cc;
536   set_private_data_ptrs   set_private_data_ptrs
537   get_framesize   get_framesize
538   init_frame   init_frame
539   get_private_data_length_for_copy   get_private_data_copy_length
540   copy_private_data   copy_private_data
541   compile_matchingpath   compile_matchingpath
542   compile_backtrackingpath   compile_backtrackingpath
# Line 507  switch(*cc) Line 560  switch(*cc)
560    case OP_WORDCHAR:    case OP_WORDCHAR:
561    case OP_ANY:    case OP_ANY:
562    case OP_ALLANY:    case OP_ALLANY:
563      case OP_NOTPROP:
564      case OP_PROP:
565    case OP_ANYNL:    case OP_ANYNL:
566    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
567    case OP_HSPACE:    case OP_HSPACE:
# Line 519  switch(*cc) Line 574  switch(*cc)
574    case OP_CIRCM:    case OP_CIRCM:
575    case OP_DOLL:    case OP_DOLL:
576    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:  
577    case OP_CRSTAR:    case OP_CRSTAR:
578    case OP_CRMINSTAR:    case OP_CRMINSTAR:
579    case OP_CRPLUS:    case OP_CRPLUS:
580    case OP_CRMINPLUS:    case OP_CRMINPLUS:
581    case OP_CRQUERY:    case OP_CRQUERY:
582    case OP_CRMINQUERY:    case OP_CRMINQUERY:
583      case OP_CRRANGE:
584      case OP_CRMINRANGE:
585      case OP_CLASS:
586      case OP_NCLASS:
587      case OP_REF:
588      case OP_REFI:
589      case OP_RECURSE:
590      case OP_CALLOUT:
591      case OP_ALT:
592      case OP_KET:
593      case OP_KETRMAX:
594      case OP_KETRMIN:
595      case OP_KETRPOS:
596      case OP_REVERSE:
597      case OP_ASSERT:
598      case OP_ASSERT_NOT:
599      case OP_ASSERTBACK:
600      case OP_ASSERTBACK_NOT:
601      case OP_ONCE:
602      case OP_ONCE_NC:
603      case OP_BRA:
604      case OP_BRAPOS:
605      case OP_CBRA:
606      case OP_CBRAPOS:
607      case OP_COND:
608      case OP_SBRA:
609      case OP_SBRAPOS:
610      case OP_SCBRA:
611      case OP_SCBRAPOS:
612      case OP_SCOND:
613      case OP_CREF:
614      case OP_NCREF:
615      case OP_RREF:
616      case OP_NRREF:
617    case OP_DEF:    case OP_DEF:
618    case OP_BRAZERO:    case OP_BRAZERO:
619    case OP_BRAMINZERO:    case OP_BRAMINZERO:
620    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
621      case OP_PRUNE:
622      case OP_SKIP:
623      case OP_THEN:
624    case OP_COMMIT:    case OP_COMMIT:
625    case OP_FAIL:    case OP_FAIL:
626    case OP_ACCEPT:    case OP_ACCEPT:
627    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
628      case OP_CLOSE:
629    case OP_SKIPZERO:    case OP_SKIPZERO:
630    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
631    
632    case OP_CHAR:    case OP_CHAR:
633    case OP_CHARI:    case OP_CHARI:
# Line 561  switch(*cc) Line 639  switch(*cc)
639    case OP_MINPLUS:    case OP_MINPLUS:
640    case OP_QUERY:    case OP_QUERY:
641    case OP_MINQUERY:    case OP_MINQUERY:
642      case OP_UPTO:
643      case OP_MINUPTO:
644      case OP_EXACT:
645    case OP_POSSTAR:    case OP_POSSTAR:
646    case OP_POSPLUS:    case OP_POSPLUS:
647    case OP_POSQUERY:    case OP_POSQUERY:
648      case OP_POSUPTO:
649    case OP_STARI:    case OP_STARI:
650    case OP_MINSTARI:    case OP_MINSTARI:
651    case OP_PLUSI:    case OP_PLUSI:
652    case OP_MINPLUSI:    case OP_MINPLUSI:
653    case OP_QUERYI:    case OP_QUERYI:
654    case OP_MINQUERYI:    case OP_MINQUERYI:
655      case OP_UPTOI:
656      case OP_MINUPTOI:
657      case OP_EXACTI:
658    case OP_POSSTARI:    case OP_POSSTARI:
659    case OP_POSPLUSI:    case OP_POSPLUSI:
660    case OP_POSQUERYI:    case OP_POSQUERYI:
661      case OP_POSUPTOI:
662    case OP_NOTSTAR:    case OP_NOTSTAR:
663    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
664    case OP_NOTPLUS:    case OP_NOTPLUS:
665    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
666    case OP_NOTQUERY:    case OP_NOTQUERY:
667    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
668      case OP_NOTUPTO:
669      case OP_NOTMINUPTO:
670      case OP_NOTEXACT:
671    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
672    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
673    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
674      case OP_NOTPOSUPTO:
675    case OP_NOTSTARI:    case OP_NOTSTARI:
676    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
677    case OP_NOTPLUSI:    case OP_NOTPLUSI:
678    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
679    case OP_NOTQUERYI:    case OP_NOTQUERYI:
680    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:  
681    case OP_NOTUPTOI:    case OP_NOTUPTOI:
682    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
683    case OP_NOTEXACTI:    case OP_NOTEXACTI:
684      case OP_NOTPOSSTARI:
685      case OP_NOTPOSPLUSI:
686      case OP_NOTPOSQUERYI:
687    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
688    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
689  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
690    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
691  #endif  #endif
692    return cc;    return cc;
693    
694    case OP_NOTPROP:    /* Special cases. */
695    case OP_PROP:    case OP_TYPESTAR:
696    return cc + 1 + 2;    case OP_TYPEMINSTAR:
697      case OP_TYPEPLUS:
698      case OP_TYPEMINPLUS:
699      case OP_TYPEQUERY:
700      case OP_TYPEMINQUERY:
701    case OP_TYPEUPTO:    case OP_TYPEUPTO:
702    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
703    case OP_TYPEEXACT:    case OP_TYPEEXACT:
704      case OP_TYPEPOSSTAR:
705      case OP_TYPEPOSPLUS:
706      case OP_TYPEPOSQUERY:
707    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
708    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;  
709    
710    case OP_CRRANGE:    case OP_ANYBYTE:
711    case OP_CRMINRANGE:  #ifdef SUPPORT_UTF
712    return cc + 1 + 2 * IMM2_SIZE;    if (common->utf) return NULL;
713    #endif
714    case OP_CLASS:    return cc + 1;
   case OP_NCLASS:  
   return cc + 1 + 32 / sizeof(pcre_uchar);  
715    
716  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
717    case OP_XCLASS:    case OP_XCLASS:
718    return cc + GET(cc, 1);    return cc + GET(cc, 1);
719  #endif  #endif
720    
   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;  
   
721    case OP_MARK:    case OP_MARK:
722      case OP_PRUNE_ARG:
723      case OP_SKIP_ARG:
724      case OP_THEN_ARG:
725    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
726    
727    default:    default:
# Line 812  while (cc < ccend) Line 856  while (cc < ccend)
856    
857      case OP_COND:      case OP_COND:
858      case OP_SCOND:      case OP_SCOND:
859      bracketlen = cc[1 + LINK_SIZE];      /* Only AUTO_CALLOUT can insert this opcode. We do
860      if (bracketlen == OP_CREF)         not intend to support this case. */
861        {      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
862        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;  
         }  
       }  
863    
864      if (*cc == OP_COND)      if (*cc == OP_COND)
865        {        {
# Line 850  while (cc < ccend) Line 873  while (cc < ccend)
873      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
874      break;      break;
875    
876        case OP_CREF:
877        i = GET2(cc, 1);
878        common->optimized_cbracket[i] = 0;
879        cc += 1 + IMM2_SIZE;
880        break;
881    
882        case OP_NCREF:
883        bracketlen = GET2(cc, 1);
884        name = (pcre_uchar *)common->name_table;
885        alternative = name;
886        for (i = 0; i < common->name_count; i++)
887          {
888          if (GET2(name, 0) == bracketlen) break;
889          name += common->name_entry_size;
890          }
891        SLJIT_ASSERT(i != common->name_count);
892    
893        for (i = 0; i < common->name_count; i++)
894          {
895          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
896            common->optimized_cbracket[GET2(alternative, 0)] = 0;
897          alternative += common->name_entry_size;
898          }
899        bracketlen = 0;
900        cc += 1 + IMM2_SIZE;
901        break;
902    
903      case OP_BRA:      case OP_BRA:
904      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
905      break;      break;
# Line 906  while (cc < ccend) Line 956  while (cc < ccend)
956    
957      case OP_RECURSE:      case OP_RECURSE:
958      /* Set its value only once. */      /* Set its value only once. */
959      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
960        {        {
961        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
962        common->ovector_start += sizeof(sljit_sw);        common->ovector_start += sizeof(sljit_sw);
963        }        }
964      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
965      break;      break;
966    
967        case OP_CALLOUT:
968        if (common->capture_last_ptr == 0)
969          {
970          common->capture_last_ptr = common->ovector_start;
971          common->ovector_start += sizeof(sljit_sw);
972          }
973        cc += 2 + 2 * LINK_SIZE;
974        break;
975    
976        case OP_THEN_ARG:
977        common->has_then = TRUE;
978        /* Fall through. */
979    
980        case OP_PRUNE_ARG:
981        common->needs_start_ptr = TRUE;
982        common->control_head_ptr = 1;
983        /* Fall through. */
984    
985      case OP_MARK:      case OP_MARK:
986      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
987        {        {
# Line 923  while (cc < ccend) Line 991  while (cc < ccend)
991      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
992      break;      break;
993    
994        case OP_THEN:
995        common->has_then = TRUE;
996        /* Fall through. */
997    
998        case OP_PRUNE:
999        case OP_SKIP:
1000        common->needs_start_ptr = TRUE;
1001        common->control_head_ptr = 1;
1002        cc += 1;
1003        break;
1004    
1005        case OP_SKIP_ARG:
1006        common->control_head_ptr = 1;
1007        common->has_skip_arg = TRUE;
1008        cc += 1 + 2 + cc[1];
1009        break;
1010    
1011      default:      default:
1012      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1013      if (cc == NULL)      if (cc == NULL)
# Line 1099  while (cc < ccend) Line 1184  while (cc < ccend)
1184    }    }
1185  }  }
1186    
1187  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1188  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL* needs_control_head)
1189  {  {
 pcre_uchar *ccend = bracketend(cc);  
1190  int length = 0;  int length = 0;
1191  BOOL possessive = FALSE;  int possessive = 0;
1192    BOOL stack_restore = FALSE;
1193  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1194  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1195    /* The last capture is a local variable even for recursions. */
1196    BOOL capture_last_found = FALSE;
1197    
1198    #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1199    SLJIT_ASSERT(common->control_head_ptr != 0);
1200    *needs_control_head = TRUE;
1201    #else
1202    *needs_control_head = FALSE;
1203    #endif
1204    
1205  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (ccend == NULL)
1206    {    {
1207    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1208    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1209        {
1210        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1211        /* This is correct regardless of common->capture_last_ptr. */
1212        capture_last_found = TRUE;
1213        }
1214      cc = next_opcode(common, cc);
1215    }    }
1216    
 cc = next_opcode(common, cc);  
1217  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1218  while (cc < ccend)  while (cc < ccend)
1219    switch(*cc)    switch(*cc)
1220      {      {
1221      case OP_SET_SOM:      case OP_SET_SOM:
1222      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1223        stack_restore = TRUE;
1224      if (!setsom_found)      if (!setsom_found)
1225        {        {
1226        length += 2;        length += 2;
# Line 1130  while (cc < ccend) Line 1230  while (cc < ccend)
1230      break;      break;
1231    
1232      case OP_MARK:      case OP_MARK:
1233        case OP_PRUNE_ARG:
1234        case OP_THEN_ARG:
1235      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1236        stack_restore = TRUE;
1237      if (!setmark_found)      if (!setmark_found)
1238        {        {
1239        length += 2;        length += 2;
1240        setmark_found = TRUE;        setmark_found = TRUE;
1241        }        }
1242        if (common->control_head_ptr != 0)
1243          *needs_control_head = TRUE;
1244      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1245      break;      break;
1246    
1247      case OP_RECURSE:      case OP_RECURSE:
1248        stack_restore = TRUE;
1249      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1250        {        {
1251        length += 2;        length += 2;
# Line 1150  while (cc < ccend) Line 1256  while (cc < ccend)
1256        length += 2;        length += 2;
1257        setmark_found = TRUE;        setmark_found = TRUE;
1258        }        }
1259        if (common->capture_last_ptr != 0 && !capture_last_found)
1260          {
1261          length += 2;
1262          capture_last_found = TRUE;
1263          }
1264      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1265      break;      break;
1266    
# Line 1157  while (cc < ccend) Line 1268  while (cc < ccend)
1268      case OP_CBRAPOS:      case OP_CBRAPOS:
1269      case OP_SCBRA:      case OP_SCBRA:
1270      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1271        stack_restore = TRUE;
1272        if (common->capture_last_ptr != 0 && !capture_last_found)
1273          {
1274          length += 2;
1275          capture_last_found = TRUE;
1276          }
1277      length += 3;      length += 3;
1278      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1279      break;      break;
1280    
1281        case OP_PRUNE:
1282        case OP_SKIP:
1283        case OP_SKIP_ARG:
1284        case OP_COMMIT:
1285        if (common->control_head_ptr != 0)
1286          *needs_control_head = TRUE;
1287        /* Fall through. */
1288    
1289      default:      default:
1290        stack_restore = TRUE;
1291        /* Fall through. */
1292    
1293        case OP_NOT_WORD_BOUNDARY:
1294        case OP_WORD_BOUNDARY:
1295        case OP_NOT_DIGIT:
1296        case OP_DIGIT:
1297        case OP_NOT_WHITESPACE:
1298        case OP_WHITESPACE:
1299        case OP_NOT_WORDCHAR:
1300        case OP_WORDCHAR:
1301        case OP_ANY:
1302        case OP_ALLANY:
1303        case OP_ANYBYTE:
1304        case OP_NOTPROP:
1305        case OP_PROP:
1306        case OP_ANYNL:
1307        case OP_NOT_HSPACE:
1308        case OP_HSPACE:
1309        case OP_NOT_VSPACE:
1310        case OP_VSPACE:
1311        case OP_EXTUNI:
1312        case OP_EODN:
1313        case OP_EOD:
1314        case OP_CIRC:
1315        case OP_CIRCM:
1316        case OP_DOLL:
1317        case OP_DOLLM:
1318        case OP_CHAR:
1319        case OP_CHARI:
1320        case OP_NOT:
1321        case OP_NOTI:
1322    
1323        case OP_EXACT:
1324        case OP_POSSTAR:
1325        case OP_POSPLUS:
1326        case OP_POSQUERY:
1327        case OP_POSUPTO:
1328    
1329        case OP_EXACTI:
1330        case OP_POSSTARI:
1331        case OP_POSPLUSI:
1332        case OP_POSQUERYI:
1333        case OP_POSUPTOI:
1334    
1335        case OP_NOTEXACT:
1336        case OP_NOTPOSSTAR:
1337        case OP_NOTPOSPLUS:
1338        case OP_NOTPOSQUERY:
1339        case OP_NOTPOSUPTO:
1340    
1341        case OP_NOTEXACTI:
1342        case OP_NOTPOSSTARI:
1343        case OP_NOTPOSPLUSI:
1344        case OP_NOTPOSQUERYI:
1345        case OP_NOTPOSUPTOI:
1346    
1347        case OP_TYPEEXACT:
1348        case OP_TYPEPOSSTAR:
1349        case OP_TYPEPOSPLUS:
1350        case OP_TYPEPOSQUERY:
1351        case OP_TYPEPOSUPTO:
1352    
1353        case OP_CLASS:
1354        case OP_NCLASS:
1355        case OP_XCLASS:
1356    
1357      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1358      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1359      break;      break;
1360      }      }
1361    
1362  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1363  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1364    return -1;    return stack_restore ? no_frame : no_stack;
1365    
1366  if (length > 0)  if (length > 0)
1367    return length + 1;    return length + 1;
1368  return -1;  return stack_restore ? no_frame : no_stack;
1369  }  }
1370    
1371  static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive)  static void init_frame(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, int stackpos, int stacktop, BOOL recursive)
1372  {  {
1373  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1374  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1375  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1376    /* The last capture is a local variable even for recursions. */
1377    BOOL capture_last_found = FALSE;
1378  int offset;  int offset;
1379    
1380  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1189  SLJIT_UNUSED_ARG(stacktop); Line 1382  SLJIT_UNUSED_ARG(stacktop);
1382  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1383    
1384  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1385  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1386    cc = next_opcode(common, cc);    {
1387      ccend = bracketend(cc) - (1 + LINK_SIZE);
1388      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1389        cc = next_opcode(common, cc);
1390      }
1391    
1392  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1393  while (cc < ccend)  while (cc < ccend)
1394    switch(*cc)    switch(*cc)
# Line 1200  while (cc < ccend) Line 1398  while (cc < ccend)
1398      if (!setsom_found)      if (!setsom_found)
1399        {        {
1400        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1401        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1402        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1403        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1404        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1210  while (cc < ccend) Line 1408  while (cc < ccend)
1408      break;      break;
1409    
1410      case OP_MARK:      case OP_MARK:
1411        case OP_PRUNE_ARG:
1412        case OP_THEN_ARG:
1413      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1414      if (!setmark_found)      if (!setmark_found)
1415        {        {
1416        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);
1417        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);
1418        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1419        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1420        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1227  while (cc < ccend) Line 1427  while (cc < ccend)
1427      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1428        {        {
1429        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1430        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1431        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1432        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1433        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1236  while (cc < ccend) Line 1436  while (cc < ccend)
1436      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1437        {        {
1438        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);
1439        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);
1440        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1441        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1442        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1443        setmark_found = TRUE;        setmark_found = TRUE;
1444        }        }
1445        if (common->capture_last_ptr != 0 && !capture_last_found)
1446          {
1447          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1448          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1449          stackpos += (int)sizeof(sljit_sw);
1450          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1451          stackpos += (int)sizeof(sljit_sw);
1452          capture_last_found = TRUE;
1453          }
1454      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1455      break;      break;
1456    
# Line 1249  while (cc < ccend) Line 1458  while (cc < ccend)
1458      case OP_CBRAPOS:      case OP_CBRAPOS:
1459      case OP_SCBRA:      case OP_SCBRA:
1460      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1461        if (common->capture_last_ptr != 0 && !capture_last_found)
1462          {
1463          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1464          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1465          stackpos += (int)sizeof(sljit_sw);
1466          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1467          stackpos += (int)sizeof(sljit_sw);
1468          capture_last_found = TRUE;
1469          }
1470      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1471      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1472      stackpos += (int)sizeof(sljit_sw);      stackpos += (int)sizeof(sljit_sw);
# Line 1268  while (cc < ccend) Line 1486  while (cc < ccend)
1486      break;      break;
1487      }      }
1488    
1489  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1490  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1491  }  }
1492    
1493  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)
1494  {  {
1495  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1496  int size;  int size;
1497  pcre_uchar *alternative;  pcre_uchar *alternative;
1498  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1387  return private_data_length; Line 1605  return private_data_length;
1605  }  }
1606    
1607  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,
1608    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1609  {  {
1610  DEFINE_COMPILER;  DEFINE_COMPILER;
1611  int srcw[2];  int srcw[2];
# Line 1408  stacktop = STACK(stacktop - 1); Line 1626  stacktop = STACK(stacktop - 1);
1626    
1627  if (!save)  if (!save)
1628    {    {
1629    stackptr += sizeof(sljit_sw);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1630    if (stackptr < stacktop)    if (stackptr < stacktop)
1631      {      {
1632      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 1642  if (!save)
1642    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1643    }    }
1644    
1645  while (status != end)  do
1646    {    {
1647    count = 0;    count = 0;
1648    switch(status)    switch(status)
1649      {      {
1650      case start:      case start:
1651      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1652      count = 1;      count = 1;
1653      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1654        if (needs_control_head)
1655          {
1656          SLJIT_ASSERT(common->control_head_ptr != 0);
1657          count = 2;
1658          srcw[1] = common->control_head_ptr;
1659          }
1660      status = loop;      status = loop;
1661      break;      break;
1662    
# Line 1657  while (status != end) Line 1881  while (status != end)
1881        }        }
1882      }      }
1883    }    }
1884    while (status != end);
1885    
1886  if (save)  if (save)
1887    {    {
# Line 1690  if (save) Line 1915  if (save)
1915  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1916  }  }
1917    
1918    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1919    {
1920    pcre_uchar *end = bracketend(cc);
1921    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1922    
1923    /* Assert captures then. */
1924    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1925      current_offset = NULL;
1926    /* Conditional block does not. */
1927    if (*cc == OP_COND || *cc == OP_SCOND)
1928      has_alternatives = FALSE;
1929    
1930    cc = next_opcode(common, cc);
1931    if (has_alternatives)
1932      current_offset = common->then_offsets + (cc - common->start);
1933    
1934    while (cc < end)
1935      {
1936      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1937        cc = set_then_offsets(common, cc, current_offset);
1938      else
1939        {
1940        if (*cc == OP_ALT && has_alternatives)
1941          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1942        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1943          *current_offset = 1;
1944        cc = next_opcode(common, cc);
1945        }
1946      }
1947    
1948    return end;
1949    }
1950    
1951  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
1952  #undef CASE_ITERATOR_PRIVATE_DATA_2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
1953  #undef CASE_ITERATOR_PRIVATE_DATA_2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
# Line 1708  while (list) Line 1966  while (list)
1966    {    {
1967    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1968    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
1969    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1970    list = list->next;    list = list->next;
1971    }    }
1972  }  }
# Line 1724  if (list_item) Line 1982  if (list_item)
1982    }    }
1983  }  }
1984    
1985  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)
1986  {  {
1987  DEFINE_COMPILER;  DEFINE_COMPILER;
1988  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1989    
1990  if (list_item)  if (list_item)
1991    {    {
   list_item->type = type;  
   list_item->data = data;  
1992    list_item->start = start;    list_item->start = start;
1993    list_item->quit = LABEL();    list_item->quit = LABEL();
1994    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1748  stub_list* list_item = common->stubs; Line 2004  stub_list* list_item = common->stubs;
2004  while (list_item)  while (list_item)
2005    {    {
2006    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2007    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;  
     }  
2008    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2009    list_item = list_item->next;    list_item = list_item->next;
2010    }    }
# Line 1781  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 2032  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2032  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2033  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2034  #endif  #endif
2035  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));
2036  }  }
2037    
2038  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 2046  static SLJIT_INLINE void reset_ovector(c
2046  DEFINE_COMPILER;  DEFINE_COMPILER;
2047  struct sljit_label *loop;  struct sljit_label *loop;
2048  int i;  int i;
2049    
2050  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2051    SLJIT_ASSERT(length > 1);
2052  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2053  OP2(SLJIT_SUB, SLJIT_TEMPORARY_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));
2054  if (length < 8)  if (length < 8)
2055    {    {
2056    for (i = 0; i < length; i++)    for (i = 1; i < length; i++)
2057      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_TEMPORARY_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2058    }    }
2059  else  else
2060    {    {
2061    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_sw));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2062    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2063    loop = LABEL();    loop = LABEL();
2064    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_sw), SLJIT_TEMPORARY_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2065    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2066    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2067    }    }
2068  }  }
2069    
2070    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2071    {
2072    DEFINE_COMPILER;
2073    struct sljit_label *loop;
2074    int i;
2075    
2076    SLJIT_ASSERT(length > 1);
2077    /* OVECTOR(1) contains the "string begin - 1" constant. */
2078    if (length > 2)
2079      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2080    if (length < 8)
2081      {
2082      for (i = 2; i < length; i++)
2083        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
2084      }
2085    else
2086      {
2087      GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2088      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2089      loop = LABEL();
2090      OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2091      OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
2092      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2093      }
2094    
2095    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2096    if (common->mark_ptr != 0)
2097      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2098    SLJIT_ASSERT(common->control_head_ptr != 0);
2099    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2100    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2101    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2102    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2103    }
2104    
2105    static sljit_sw SLJIT_CALL do_check_control_chain(sljit_sw *current)
2106    {
2107    sljit_sw return_value = 0;
2108    const pcre_uchar *skip_arg = NULL;
2109    
2110    SLJIT_ASSERT(current != NULL);
2111    do
2112      {
2113      switch (current[-2])
2114        {
2115        case type_commit:
2116        /* Commit overwrites all. */
2117        return -1;
2118    
2119        case type_prune:
2120        case type_then_trap:
2121        break;
2122    
2123        case type_skip:
2124        /* Overwrites prune, but not other skips. */
2125        if (return_value == 0 && skip_arg == NULL)
2126          return_value = current[-3];
2127        break;
2128    
2129        case type_skip_arg:
2130        if (return_value == 0 && skip_arg == NULL)
2131          skip_arg = (pcre_uchar *)current[-3];
2132        break;
2133    
2134        case type_mark:
2135        if (return_value == 0 && skip_arg != NULL)
2136          if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2137            return_value = current[-4];
2138        break;
2139    
2140        default:
2141        SLJIT_ASSERT_STOP();
2142        break;
2143        }
2144      current = (sljit_sw*)current[-1];
2145      }
2146    while (current != NULL);
2147    return (return_value != 0 || skip_arg == NULL) ? return_value : -2;
2148    }
2149    
2150    static sljit_sw SLJIT_CALL do_search_then_trap(sljit_sw *current)
2151    {
2152    do
2153      {
2154      switch (current[-2])
2155        {
2156        case type_commit:
2157        /* Commit overwrites all. */
2158        return 0;
2159    
2160        case type_then_trap:
2161        return (sljit_sw)current;
2162    
2163        case type_prune:
2164        case type_skip:
2165        case type_skip_arg:
2166        case type_mark:
2167        break;
2168    
2169        default:
2170        SLJIT_ASSERT_STOP();
2171        break;
2172        }
2173      current = (sljit_sw*)current[-1];
2174      SLJIT_ASSERT(current != NULL);
2175      }
2176    while (TRUE);
2177    }
2178    
2179  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2180  {  {
2181  DEFINE_COMPILER;  DEFINE_COMPILER;
2182  struct sljit_label *loop;  struct sljit_label *loop;
2183  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2184    
2185  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2186  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));
2187  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1), STR_PTR, 0);
2188    
2189  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2190  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2191    OP1(SLJIT_MOV, SLJIT_TEMPORARY_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);
2192  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_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));
2193  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2194    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_TEMPORARY_REG3, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), SLJIT_SCRATCH_REG3, 0);
2195  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_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));
2196  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), SLJIT_OFFSETOF(jit_arguments, begin));
2197  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2198  /* Unlikely, but possible */  /* Unlikely, but possible */
2199  earlyexit = CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0);  early_quit = CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);
2200  loop = LABEL();  loop = LABEL();
2201  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
2202  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));
2203  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2204  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2205  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2206  #endif  #endif
2207  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOVU_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG3), sizeof(int), SLJIT_SAVED_REG2, 0);
2208  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
2209  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2210  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2211    
2212  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2213  if (topbracket > 1)  if (topbracket > 1)
2214    {    {
2215    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));
2216    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2217    
2218    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2219    loop = LABEL();    loop = LABEL();
2220    OP1(SLJIT_MOVU, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), -(2 * (sljit_sw)sizeof(sljit_sw)));    OP1(SLJIT_MOVU, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), -(2 * (sljit_sw)sizeof(sljit_sw)));
2221    OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 1);
2222    CMPTO(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG3, 0, loop);    CMPTO(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG3, 0, loop);
2223    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2224    }    }
2225  else  else
2226    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1867  else Line 2229  else
2229  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)
2230  {  {
2231  DEFINE_COMPILER;  DEFINE_COMPILER;
2232    struct sljit_jump *jump;
2233    
2234  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);
2235  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
2236      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2237    
2238  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2239  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2240  OP1(SLJIT_MOV_SI, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_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));
2241  CMPTO(SLJIT_C_LESS, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 2, quit);  CMPTO(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 2, quit);
2242    
2243  /* Store match begin and end. */  /* Store match begin and end. */
2244  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, begin));  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, begin));
2245  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));
2246  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);  
2247    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2248    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);
2249    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2250    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2251    #endif
2252    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2253    JUMPHERE(jump);
2254    
2255    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);
2256  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);
2257  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2258  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, UCHAR_SHIFT);
2259  #endif  #endif
2260  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(int), SLJIT_SAVED_REG2, 0);
2261    
2262  OP2(SLJIT_SUB, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_SAVED_REG1, 0);
2263  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2264  OP2(SLJIT_ASHR, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);  OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2265  #endif  #endif
2266  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), 0, SLJIT_TEMPORARY_REG3, 0);  OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 0, SLJIT_SCRATCH_REG3, 0);
2267    
2268  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2269  }  }
# Line 2055  else if (common->mode == JIT_PARTIAL_SOF Line 2428  else if (common->mode == JIT_PARTIAL_SOF
2428    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);
2429    
2430  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2431    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);
2432  else  else
2433    {    {
2434    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2068  if (jump != NULL) Line 2441  if (jump != NULL)
2441    JUMPHERE(jump);    JUMPHERE(jump);
2442  }  }
2443    
2444  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2445  {  {
2446  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2447  DEFINE_COMPILER;  DEFINE_COMPILER;
2448  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2449    
2450  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2451    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2452      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2453      return;
2454      }
2455    
2456  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2457  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2458    {    {
2459    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));
2460    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);
2461    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2462    }    }
2463  else  else
2464    {    {
2465    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));
2466    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2467      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2468    else    else
2469      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2470    }    }
2471  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2472  }  }
2473    
2474  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 2487  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2487  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));
2488  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2489    {    {
2490    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);
2491    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2492    }    }
2493  else  else
# Line 2206  if (common->utf) Line 2578  if (common->utf)
2578    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2579    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2580    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2581    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2582    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2583    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2584  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
# Line 2256  if (common->utf) Line 2628  if (common->utf)
2628    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2629    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2630    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xdc00);
2631    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2632    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2633    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2634    return;    return;
# Line 2279  if (nltype == NLTYPE_ANY) Line 2651  if (nltype == NLTYPE_ANY)
2651  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2652    {    {
2653    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);
2654    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2655    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);
2656    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
2657    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2658    }    }
2659  else  else
# Line 2509  if (newlinecheck) Line 2881  if (newlinecheck)
2881    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2882    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2883    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, common->newline & 0xff);
2884    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2885  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2886    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2887  #endif  #endif
# Line 2547  if (common->utf) Line 2919  if (common->utf)
2919    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2920    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2921    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2922    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2923    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2924    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2925    JUMPHERE(singlechar);    JUMPHERE(singlechar);
# Line 2573  DEFINE_COMPILER; Line 2945  DEFINE_COMPILER;
2945  struct sljit_label *start;  struct sljit_label *start;
2946  struct sljit_jump *quit;  struct sljit_jump *quit;
2947  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uint32 chars[MAX_N_CHARS * 2];
2948  pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  pcre_uchar *cc = common->start + 1 + LINK_SIZE;
2949  int location = 0;  int location = 0;
2950  pcre_int32 len, c, bit, caseless;  pcre_int32 len, c, bit, caseless;
2951  int must_stop;  int must_stop;
# Line 2696  if (firstline) Line 3068  if (firstline)
3068    {    {
3069    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3070    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3071    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));
3072    }    }
3073  else  else
3074    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));
3075    
3076  start = LABEL();  start = LABEL();
3077  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 3100  JUMPHERE(quit);
3100  if (firstline)  if (firstline)
3101    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3102  else  else
3103    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));
3104  return TRUE;  return TRUE;
3105  }  }
3106    
# Line 2775  else Line 3147  else
3147    else    else
3148      {      {
3149      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, first_char);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, first_char);
3150      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3151      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);
3152      COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3153      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3154      }      }
3155    }    }
# Line 2819  if (common->nltype == NLTYPE_FIXED && co Line 3191  if (common->nltype == NLTYPE_FIXED && co
3191    
3192    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3193    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, STR_PTR, 0, TMP1, 0);
3194    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3195  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3196    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3197  #endif  #endif
# Line 2862  if (common->nltype == NLTYPE_ANY || comm Line 3234  if (common->nltype == NLTYPE_ANY || comm
3234    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3235    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3236    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);
3237    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3238  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3239    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3240  #endif  #endif
# Line 2877  if (firstline) Line 3249  if (firstline)
3249    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3250  }  }
3251    
3252    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3253    
3254  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)
3255  {  {
3256  DEFINE_COMPILER;  DEFINE_COMPILER;
3257  struct sljit_label *start;  struct sljit_label *start;
3258  struct sljit_jump *quit;  struct sljit_jump *quit;
3259  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3260    jump_list *matches = NULL;
3261    pcre_uint8 inverted_start_bits[32];
3262    int i;
3263  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3264  struct sljit_jump *jump;  struct sljit_jump *jump;
3265  #endif  #endif
3266    
3267    for (i = 0; i < 32; ++i)
3268      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3269    
3270  if (firstline)  if (firstline)
3271    {    {
3272    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 3281  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3281  if (common->utf)  if (common->utf)
3282    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3283  #endif  #endif
3284    
3285    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3286      {
3287  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3288  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3289  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3290  JUMPHERE(jump);    JUMPHERE(jump);
3291  #endif  #endif
3292  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3293  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3294  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3295  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3296  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);
3297  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3298      }
3299    
3300  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3301  if (common->utf)  if (common->utf)
# Line 2932  if (common->utf) Line 3316  if (common->utf)
3316    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3317    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3318    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
3319    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3320    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3321    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3322    }    }
3323  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE[8|16] */
3324  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3325  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3326  JUMPHERE(found);  if (found != NULL)
3327      JUMPHERE(found);
3328    if (matches != NULL)
3329      set_jumps(matches, LABEL());
3330  JUMPHERE(quit);  JUMPHERE(quit);
3331    
3332  if (firstline)  if (firstline)
# Line 3022  GET_LOCAL_BASE(TMP3, 0, 0); Line 3409  GET_LOCAL_BASE(TMP3, 0, 0);
3409  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3410  mainloop = LABEL();  mainloop = LABEL();
3411  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3412  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);
3413    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3414    
3415  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3416  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));
3417  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 3419  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_I
3419  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3420    
3421  JUMPHERE(jump);  JUMPHERE(jump);
3422  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3423  /* End of dropping frames. */  /* End of dropping frames. */
3424  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3425    
3426  JUMPHERE(jump);  JUMPHERE(jump);
3427  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3428  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3429  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. */  
3430  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));
3431  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3432  }  }
# Line 3063  static void check_wordboundary(compiler_ Line 3435  static void check_wordboundary(compiler_
3435  {  {
3436  DEFINE_COMPILER;  DEFINE_COMPILER;
3437  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3438    jump_list *skipread_list = NULL;
3439  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3440  struct sljit_jump *jump;  struct sljit_jump *jump;
3441  #endif  #endif
# Line 3088  if (common->use_ucp) Line 3461  if (common->use_ucp)
3461    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3462    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3463    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
3464    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3465    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);
3466    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);
3467    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3468    JUMPHERE(jump);    JUMPHERE(jump);
3469    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3470    }    }
# Line 3120  else Line 3493  else
3493  JUMPHERE(skipread);  JUMPHERE(skipread);
3494    
3495  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3496  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3497  peek_char(common);  peek_char(common);
3498    
3499  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 3132  if (common->use_ucp) Line 3505  if (common->use_ucp)
3505    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3506    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3507    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
3508    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3509    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Nd - ucp_Ll);
3510    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ucp_No - ucp_Nd);
3511    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3512    JUMPHERE(jump);    JUMPHERE(jump);
3513    }    }
3514  else  else
# Line 3161  else Line 3534  else
3534      JUMPHERE(jump);      JUMPHERE(jump);
3535  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3536    }    }
3537  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3538    
3539  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);
3540  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
# Line 3315  sljit_emit_fast_enter(compiler, RETURN_A Line 3688  sljit_emit_fast_enter(compiler, RETURN_A
3688    
3689  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3690  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);
3691  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3692  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);
3693  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3694  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3695  if (common->utf)  if (common->utf)
3696    {    {
3697  #endif  #endif
3698    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3699    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3700    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);
3701  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3702    }    }
3703  #endif  #endif
3704  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3705  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3706  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3707  }  }
3708    
# Line 3341  DEFINE_COMPILER; Line 3714  DEFINE_COMPILER;
3714  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3715    
3716  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x09);
3717  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3718  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
3719  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3720  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xa0);
3721  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3722  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3723  if (common->utf)  if (common->utf)
3724    {    {
3725  #endif  #endif
3726    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3727    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x1680);
3728    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3729    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e);
3730    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3731    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3732    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x200A - 0x2000);
3733    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3734    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x202f - 0x2000);
3735    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3736    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);
3737    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3738    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x3000 - 0x2000);
3739  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3740    }    }
3741  #endif  #endif
3742  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3743  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3744    
3745  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3746  }  }
# Line 3381  sljit_emit_fast_enter(compiler, RETURN_A Line 3754  sljit_emit_fast_enter(compiler, RETURN_A
3754    
3755  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3756  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x0d - 0x0a);
3757  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3758  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);  OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x0a);
3759  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3760  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3761  if (common->utf)  if (common->utf)
3762    {    {
3763  #endif  #endif
3764    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3765    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3766    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2029 - 0x0a);
3767  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3768    }    }
3769  #endif  #endif
3770  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3771  COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3772    
3773  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3774  }  }
# Line 3481  sljit_emit_fast_return(compiler, RETURN_ Line 3854  sljit_emit_fast_return(compiler, RETURN_
3854    
3855  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3856    
3857  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)
3858  {  {
3859  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3860  pcre_uint32 c1, c2;  pcre_uint32 c1, c2;
# Line 3532  if (caseless && char_has_othercase(commo Line 3905  if (caseless && char_has_othercase(commo
3905    othercasebit &= 0xff;    othercasebit &= 0xff;
3906  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3907    /* Note that this code only handles characters in the BMP. If there    /* Note that this code only handles characters in the BMP. If there
3908    ever are characters outside the BMP whose othercase differs in only one    ever are characters outside the BMP whose othercase differs in only one
3909    bit from itself (there currently are none), this code will need to be    bit from itself (there currently are none), this code will need to be
3910    revised for COMPILE_PCRE32. */    revised for COMPILE_PCRE32. */
3911    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
# Line 3577  do Line 3950  do
3950  #endif  #endif
3951    
3952    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3953  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3954    
3955    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3956    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3594  do Line 3967  do
3967    
3968  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
3969    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))
3970  #elif defined COMPILE_PCRE16  #else
3971    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 */)  
3972  #endif  #endif
3973      {      {
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
3974      if (context->length >= 4)      if (context->length >= 4)
3975        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  
3976      else if (context->length >= 2)      else if (context->length >= 2)
3977        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);
3978    #if defined COMPILE_PCRE8
3979      else if (context->length >= 1)      else if (context->length >= 1)
3980        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);
3981  #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] */  
3982      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3983    
3984      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3625  do Line 3989  do
3989        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));
3990        break;        break;
3991    
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
3992        case 2 / sizeof(pcre_uchar):        case 2 / sizeof(pcre_uchar):
3993        if (context->oc.asushort != 0)        if (context->oc.asushort != 0)
3994          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 4003  do
4003        break;        break;
4004  #endif  #endif
4005    
 #endif /* COMPILE_PCRE[8|16] */  
   
4006        default:        default:
4007        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
4008        break;        break;
# Line 3651  do Line 4012  do
4012    
4013  #else  #else
4014    
4015    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
4016    if (context->length > 0)    if (context->length >= 1)
4017      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
4018    
4019    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
# Line 3813  while (*cc != XCL_END) Line 4174  while (*cc != XCL_END)
4174        break;        break;
4175    
4176        case PT_CLIST:        case PT_CLIST:
4177          case PT_UCNC:
4178        needschar = TRUE;        needschar = TRUE;
4179        break;        break;
4180    
# Line 3894  while (*cc != XCL_END) Line 4256  while (*cc != XCL_END)
4256      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4257        {        {
4258        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
4259        COND_VALUE(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, numberofcmps == 0 ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_EQUAL);
4260        numberofcmps++;        numberofcmps++;
4261        }        }
4262      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4263        {        {
4264        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
4265        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4266        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4267        numberofcmps = 0;        numberofcmps = 0;
4268        }        }
# Line 3933  while (*cc != XCL_END) Line 4295  while (*cc != XCL_END)
4295      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4296        {        {
4297        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
4298        COND_VALUE(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(numberofcmps == 0 ? SLJIT_MOV : SLJIT_OR, TMP2, 0, numberofcmps == 0 ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_LESS_EQUAL);
4299        numberofcmps++;        numberofcmps++;
4300        }        }
4301      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4302        {        {
4303        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c - charoffset);
4304        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4305        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4306        numberofcmps = 0;        numberofcmps = 0;
4307        }        }
# Line 3970  while (*cc != XCL_END) Line 4332  while (*cc != XCL_END)
4332    
4333        case PT_LAMP:        case PT_LAMP:
4334        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - typeoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - typeoffset);
4335        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4336        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ll - typeoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ll - typeoffset);
4337        COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4338        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lt - typeoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lt - typeoffset);
4339        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4340        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4341        break;        break;
4342    
# Line 4001  while (*cc != XCL_END) Line 4363  while (*cc != XCL_END)
4363          }          }
4364        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4365        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 13 - 9);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 13 - 9);
4366        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4367        if (*cc == PT_SPACE)        if (*cc == PT_SPACE)
4368          JUMPHERE(jump);          JUMPHERE(jump);
4369    
4370        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4371        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl);
4372        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4373        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4374        break;        break;
4375    
4376        case PT_WORD:        case PT_WORD:
4377        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);
4378        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4379        /* ... fall through */        /* Fall through. */
4380    
4381        case PT_ALNUM:        case PT_ALNUM:
4382        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
4383        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Lu - ucp_Ll);
4384        COND_VALUE((*cc == PT_ALNUM) ? SLJIT_MOV : SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS((*cc == PT_ALNUM) ? SLJIT_MOV : SLJIT_OR, TMP2, 0, (*cc == PT_ALNUM) ? SLJIT_UNUSED : TMP2, 0, SLJIT_C_LESS_EQUAL);
4385        SET_TYPE_OFFSET(ucp_Nd);        SET_TYPE_OFFSET(ucp_Nd);
4386        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_No - ucp_Nd);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_No - ucp_Nd);
4387        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4388        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4389        break;        break;
4390    
# Line 4045  while (*cc != XCL_END) Line 4407  while (*cc != XCL_END)
4407            OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);            OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4408            }            }
4409          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[1]);          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[1]);
4410          COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4411          other_cases += 2;          other_cases += 2;
4412          }          }
4413        else if (is_powerof2(other_cases[2] ^ other_cases[1]))        else if (is_powerof2(other_cases[2] ^ other_cases[1]))
# Line 4058  while (*cc != XCL_END) Line 4420  while (*cc != XCL_END)
4420            OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);            OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4421            }            }
4422          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[2]);          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, other_cases[2]);
4423          COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4424    
4425          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, other_cases[0] - charoffset);          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, other_cases[0] - charoffset);
4426          COND_VALUE(SLJIT_OR | ((other_cases[3] == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_OR | ((other_cases[3] == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4427    
4428          other_cases += 3;          other_cases += 3;
4429          }          }
4430        else        else
4431          {          {
4432          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4433          COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4434          }          }
4435    
4436        while (*other_cases != NOTACHAR)        while (*other_cases != NOTACHAR)
4437          {          {
4438          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, *other_cases++ - charoffset);
4439          COND_VALUE(SLJIT_OR | ((*other_cases == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_OR | ((*other_cases == NOTACHAR) ? SLJIT_SET_E : 0), TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4440          }          }
4441        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4442        break;        break;
4443    
4444          case PT_UCNC:
4445          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);
4446          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4447          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);
4448          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4449          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);
4450          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4451    
4452          SET_CHAR_OFFSET(0xa0);
4453          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);
4454          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4455          SET_CHAR_OFFSET(0);
4456          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
4457          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4458          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4459          break;
4460        }        }
4461      cc += 2;      cc += 2;
4462      }      }
# Line 4103  int length; Line 4482  int length;
4482  unsigned int c, oc, bit;  unsigned int c, oc, bit;
4483  compare_context context;  compare_context context;
4484  struct sljit_jump *jump[4];  struct sljit_jump *jump[4];
4485    jump_list *end_list;
4486  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4487  struct sljit_label *label;  struct sljit_label *label;
4488  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4171  switch(type) Line 4551  switch(type)
4551    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4552      {      {
4553      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);
4554        end_list = NULL;
4555      if (common->mode != JIT_PARTIAL_HARD_COMPILE)      if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4556        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));
4557      else      else
4558        jump[1] = check_str_end(common);        check_str_end(common, &end_list);
4559    
4560      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4561      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));
4562      if (jump[1] != NULL)      set_jumps(end_list, LABEL());
       JUMPHERE(jump[1]);  
4563      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4564      }      }
4565    else    else
# Line 4202  switch(type) Line 4582  switch(type)
4582      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
4583      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
4584      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);
4585      COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4586      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4587      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4588  #endif  #endif
# Line 4238  switch(type) Line 4618  switch(type)
4618    read_char(common);    read_char(common);
4619    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);
4620    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
4621      end_list = NULL;
4622    if (common->mode != JIT_PARTIAL_HARD_COMPILE)    if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4623      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));
4624    else    else
4625      jump[1] = check_str_end(common);      check_str_end(common, &end_list);
4626    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4627    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);
4628    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));
4629    jump[3] = JUMP(SLJIT_JUMP);    jump[2] = JUMP(SLJIT_JUMP);
4630    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4631    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);
4632      set_jumps(end_list, LABEL());
4633    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
4634    JUMPHERE(jump[2]);    JUMPHERE(jump[2]);
   JUMPHERE(jump[3]);  
4635    return cc;    return cc;
4636    
4637    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
# Line 4321  switch(type) Line 4702  switch(type)
4702        {        {
4703        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);
4704        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP2, 0, STR_END, 0);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP2, 0, STR_END, 0);
4705        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS);
4706        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);
4707        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_NOT_EQUAL);        OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_NOT_EQUAL);
4708        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));
4709        check_partial(common, TRUE);        check_partial(common, TRUE);
4710        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
# Line 4510  switch(type) Line 4891  switch(type)
4891      return cc + length;      return cc + length;
4892      }      }
4893    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c);
4894    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4895    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);
4896    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4897    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
4898    return cc + length;    return cc + length;
4899    
# Line 4726  if (!common->jscript_compat) Line 5107  if (!common->jscript_compat)
5107      {      {
5108      /* OVECTOR(1) contains the "string begin - 1" constant. */      /* OVECTOR(1) contains the "string begin - 1" constant. */
5109      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
5110      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
5111      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5112      COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
5113      return JUMP(SLJIT_C_NOT_ZERO);      return JUMP(SLJIT_C_NOT_ZERO);
5114      }      }
5115    add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));    add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
# Line 4784  if (withchecks && !common->jscript_compa Line 5165  if (withchecks && !common->jscript_compa
5165  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5166  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5167    {    {
5168    SLJIT_ASSERT(TMP1 == SLJIT_TEMPORARY_REG1 && STACK_TOP == SLJIT_TEMPORARY_REG2 && TMP2 == SLJIT_TEMPORARY_REG3);    SLJIT_ASSERT(TMP1 == SLJIT_SCRATCH_REG1 && STACK_TOP == SLJIT_SCRATCH_REG2 && TMP2 == SLJIT_SCRATCH_REG3);
5169    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));
5170    if (withchecks)    if (withchecks)
5171      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5172    
5173    /* Needed to save important temporary registers. */    /* Needed to save important temporary registers. */
5174    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5175    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
5176    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), SLJIT_OFFSETOF(jit_arguments, uchar_ptr), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, uchar_ptr), STR_PTR, 0);
5177    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_utf_caselesscmp));    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_utf_caselesscmp));
5178    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5179    if (common->mode == JIT_COMPILE)    if (common->mode == JIT_COMPILE)
# Line 5001  backtrack_common *backtrack; Line 5382  backtrack_common *backtrack;
5382  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5383  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5384  int start = GET(cc, 1);  int start = GET(cc, 1);
5385    pcre_uchar *start_cc;
5386    BOOL needs_control_head;
5387    
5388  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5389    
5390    /* Inlining simple patterns. */
5391    if (get_framesize(common, common->start + start, NULL, TRUE, &needs_control_head) == no_stack)
5392      {
5393      start_cc = common->start + start;
5394      compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
5395      BACKTRACK_AS(recurse_backtrack)->inlined_pattern = TRUE;
5396      return cc + 1 + LINK_SIZE;
5397      }
5398    
5399  while (entry != NULL)  while (entry != NULL)
5400    {    {
5401    if (entry->start == start)    if (entry->start == start)
# Line 5042  else if (common->has_set_som || common-> Line 5435  else if (common->has_set_som || common->
5435    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
5436    }    }
5437    
5438  if (entry->entry == NULL)  if (entry->entry == NULL)
5439    add_jump(compiler, &entry->calls, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &entry->calls, JUMP(SLJIT_FAST_CALL));
5440    else
5441      JUMPTO(SLJIT_FAST_CALL, entry->entry);
5442    /* Leave if the match is failed. */
5443    add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0));
5444    return cc + 1 + LINK_SIZE;
5445    }
5446    
5447    static int SLJIT_CALL do_callout(struct jit_arguments* arguments, PUBL(callout_block) *callout_block, pcre_uchar **jit_ovector)
5448    {
5449    const pcre_uchar *begin = arguments->begin;
5450    int *offset_vector = arguments->offsets;
5451    int offset_count = arguments->offset_count;
5452    int i;
5453    
5454    if (PUBL(callout) == NULL)
5455      return 0;
5456    
5457    callout_block->version = 2;
5458    callout_block->callout_data = arguments->callout_data;
5459    
5460    /* Offsets in subject. */
5461    callout_block->subject_length = arguments->end - arguments->begin;
5462    callout_block->start_match = (pcre_uchar*)callout_block->subject - arguments->begin;
5463    callout_block->current_position = (pcre_uchar*)callout_block->offset_vector - arguments->begin;
5464    #if defined COMPILE_PCRE8
5465    callout_block->subject = (PCRE_SPTR)begin;
5466    #elif defined COMPILE_PCRE16
5467    callout_block->subject = (PCRE_SPTR16)begin;
5468    #elif defined COMPILE_PCRE32
5469    callout_block->subject = (PCRE_SPTR32)begin;
5470    #endif
5471    
5472    /* Convert and copy the JIT offset vector to the offset_vector array. */
5473    callout_block->capture_top = 0;
5474    callout_block->offset_vector = offset_vector;
5475    for (i = 2; i < offset_count; i += 2)
5476      {
5477      offset_vector[i] = jit_ovector[i] - begin;
5478      offset_vector[i + 1] = jit_ovector[i + 1] - begin;
5479      if (jit_ovector[i] >= begin)
5480        callout_block->capture_top = i;
5481      }
5482    
5483    callout_block->capture_top = (callout_block->capture_top >> 1) + 1;
5484    if (offset_count > 0)
5485      offset_vector[0] = -1;
5486    if (offset_count > 1)
5487      offset_vector[1] = -1;
5488    return (*PUBL(callout))(callout_block);
5489    }
5490    
5491    /* Aligning to 8 byte. */
5492    #define CALLOUT_ARG_SIZE \
5493        (((int)sizeof(PUBL(callout_block)) + 7) & ~7)
5494    
5495    #define CALLOUT_ARG_OFFSET(arg) \
5496        (-CALLOUT_ARG_SIZE + SLJIT_OFFSETOF(PUBL(callout_block), arg))
5497    
5498    static SLJIT_INLINE pcre_uchar *compile_callout_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5499    {
5500    DEFINE_COMPILER;
5501    backtrack_common *backtrack;
5502    
5503    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
5504    
5505    allocate_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5506    
5507    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
5508    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
5509    SLJIT_ASSERT(common->capture_last_ptr != 0);
5510    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);
5511    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);
5512    
5513    /* These pointer sized fields temporarly stores internal variables. */
5514    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
5515    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(offset_vector), STR_PTR, 0);
5516    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(subject), TMP2, 0);
5517    
5518    if (common->mark_ptr != 0)
5519      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr));
5520    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 2));
5521    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 2 + LINK_SIZE));
5522    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);
5523    
5524    /* Needed to save important temporary registers. */
5525    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5526    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, STACK_TOP, 0, SLJIT_IMM, CALLOUT_ARG_SIZE);
5527    GET_LOCAL_BASE(SLJIT_SCRATCH_REG3, 0, OVECTOR_START);
5528    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_callout));
5529    OP1(SLJIT_MOV_SI, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0);
5530    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5531    free_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5532    
5533    /* Check return value. */
5534    OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
5535    add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_C_SIG_GREATER));
5536    if (common->forced_quit_label == NULL)
5537      add_jump(compiler, &common->forced_quit, JUMP(SLJIT_C_SIG_LESS));
5538  else  else
5539    JUMPTO(SLJIT_FAST_CALL, entry->entry);    JUMPTO(SLJIT_C_SIG_LESS, common->forced_quit_label);
5540  /* Leave if the match is failed. */  return cc + 2 + 2 * LINK_SIZE;
 add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0));  
 return cc + 1 + LINK_SIZE;  
5541  }  }
5542    
5543    #undef CALLOUT_ARG_SIZE
5544    #undef CALLOUT_ARG_OFFSET
5545    
5546  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)
5547  {  {
5548  DEFINE_COMPILER;  DEFINE_COMPILER;
5549  int framesize;  int framesize;
5550    int extrasize;
5551    BOOL needs_control_head;
5552  int private_data_ptr;  int private_data_ptr;
5553  backtrack_common altbacktrack;  backtrack_common altbacktrack;
5554  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
# Line 5064  jump_list *tmp = NULL; Line 5558  jump_list *tmp = NULL;
5558  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5559  jump_list **found;  jump_list **found;
5560  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5561  struct sljit_label *save_quitlabel = common->quitlabel;  BOOL save_local_exit = common->local_exit;
5562  struct sljit_label *save_acceptlabel = common->acceptlabel;  then_trap_backtrack *save_then_trap = common->then_trap;
5563    struct sljit_label *save_quit_label = common->quit_label;
5564    struct sljit_label *save_accept_label = common->accept_label;
5565  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
5566  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
5567  struct sljit_jump *jump;  struct sljit_jump *jump;
5568  struct sljit_jump *brajump = NULL;  struct sljit_jump *brajump = NULL;
5569    
5570    /* Assert captures then. */
5571    common->then_trap = NULL;
5572    
5573  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
5574    {    {
5575    SLJIT_ASSERT(!conditional);    SLJIT_ASSERT(!conditional);
# Line 5079  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 5578  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
5578    }    }
5579  private_data_ptr = PRIVATE_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
5580  SLJIT_ASSERT(private_data_ptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
5581  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
5582  backtrack->framesize = framesize;  backtrack->framesize = framesize;
5583  backtrack->private_data_ptr = private_data_ptr;  backtrack->private_data_ptr = private_data_ptr;
5584  opcode = *cc;  opcode = *cc;
# Line 5098  if (bra == OP_BRAMINZERO) Line 5597  if (bra == OP_BRAMINZERO)
5597    
5598  if (framesize < 0)  if (framesize < 0)
5599    {    {
5600    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    extrasize = needs_control_head ? 2 : 1;
5601    allocate_stack(common, 1);    if (framesize == no_frame)
5602        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
5603      allocate_stack(common, extrasize);
5604      if (needs_control_head)
5605        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5606    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5607      if (needs_control_head)
5608        {
5609        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5610        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5611        }
5612    }    }
5613  else  else
5614    {    {
5615    allocate_stack(common, framesize + 2);    extrasize = needs_control_head ? 3 : 2;
5616      allocate_stack(common, framesize + extrasize);
5617    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);
5618    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));
5619    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);
5620      if (needs_control_head)
5621        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5622    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5623    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    if (needs_control_head)
5624    init_frame(common, ccbegin, framesize + 1, 2, FALSE);      {
5625        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
5626        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
5627        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5628        }
5629      else
5630        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5631      init_frame(common, ccbegin, NULL, framesize + extrasize - 1, extrasize, FALSE);
5632    }    }
5633    
5634  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
5635  common->quitlabel = NULL;  common->local_exit = TRUE;
5636    common->quit_label = NULL;
5637  common->quit = NULL;  common->quit = NULL;
5638  while (1)  while (1)
5639    {    {
5640    common->acceptlabel = NULL;    common->accept_label = NULL;
5641    common->accept = NULL;    common->accept = NULL;
5642    altbacktrack.top = NULL;    altbacktrack.top = NULL;
5643    altbacktrack.topbacktracks = NULL;    altbacktrack.topbacktracks = NULL;
# Line 5130  while (1) Line 5649  while (1)
5649    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
5650    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5651      {      {
5652      common->quitlabel = save_quitlabel;      common->local_exit = save_local_exit;
5653      common->acceptlabel = save_acceptlabel;      common->then_trap = save_then_trap;
5654        common->quit_label = save_quit_label;
5655        common->accept_label = save_accept_label;
5656      common->quit = save_quit;      common->quit = save_quit;
5657      common->accept = save_accept;      common->accept = save_accept;
5658      return NULL;      return NULL;
5659      }      }
5660    common->acceptlabel = LABEL();    common->accept_label = LABEL();
5661    if (common->accept != NULL)    if (common->accept != NULL)
5662      set_jumps(common->accept, common->acceptlabel);      set_jumps(common->accept, common->accept_label);
5663    
5664    /* Reset stack. */    /* Reset stack. */
5665    if (framesize < 0)    if (framesize < 0)
5666      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      {
5667    else {      if (framesize == no_frame)
5668          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5669        else
5670          free_stack(common, extrasize);
5671        if (needs_control_head)
5672          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5673        }
5674      else
5675        {
5676      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)
5677        {        {
5678        /* 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. */
5679        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));
5680          if (needs_control_head)
5681            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5682        }        }
5683      else      else
5684        {        {
5685        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);
5686          if (needs_control_head)
5687            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));
5688        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5689        }        }
5690    }      }
5691    
5692    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5693      {      {
5694      /* 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. */
5695      if (conditional)      if (conditional)
5696        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);
5697      else if (bra == OP_BRAZERO)      else if (bra == OP_BRAZERO)
5698        {        {
5699        if (framesize < 0)        if (framesize < 0)
5700          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));
5701        else        else
5702          {          {
5703          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));
5704          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));
5705          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);
5706          }          }
5707        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 5718  while (1)
5718    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
5719    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5720      {      {
5721      common->quitlabel = save_quitlabel;      common->local_exit = save_local_exit;
5722      common->acceptlabel = save_acceptlabel;      common->then_trap = save_then_trap;
5723        common->quit_label = save_quit_label;
5724        common->accept_label = save_accept_label;
5725      common->quit = save_quit;      common->quit = save_quit;
5726      common->accept = save_accept;      common->accept = save_accept;
5727      return NULL;      return NULL;
# Line 5199  while (1) Line 5734  while (1)
5734    ccbegin = cc;    ccbegin = cc;
5735    cc += GET(cc, 1);    cc += GET(cc, 1);
5736    }    }
5737    
5738  /* None of them matched. */  /* None of them matched. */
5739  if (common->quit != NULL)  if (common->quit != NULL)
5740      {
5741      jump = JUMP(SLJIT_JUMP);
5742    set_jumps(common->quit, LABEL());    set_jumps(common->quit, LABEL());
5743      SLJIT_ASSERT(framesize != no_stack);
5744      if (framesize < 0)
5745        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));
5746      else
5747        {
5748        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5749        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5750        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
5751        }
5752      JUMPHERE(jump);
5753      }
5754    
5755    if (needs_control_head)
5756      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(1));
5757    
5758  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)
5759    {    {
# Line 5213  if (opcode == OP_ASSERT || opcode == OP_ Line 5765  if (opcode == OP_ASSERT || opcode == OP_
5765      {      {
5766      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5767      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5768          {
5769          if (extrasize == 2)
5770            free_stack(common, 1);
5771        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5772          }
5773      else      else
5774        free_stack(common, 1);        free_stack(common, extrasize);
5775      }      }
5776    else    else
5777      {      {
5778      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
5779      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5780      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5781        {        {
5782        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
5783        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5784        }        }
5785      else      else
5786        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
5787      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);
5788      }      }
5789    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
# Line 5239  if (opcode == OP_ASSERT || opcode == OP_ Line 5795  if (opcode == OP_ASSERT || opcode == OP_
5795    if (framesize < 0)    if (framesize < 0)
5796      {      {
5797      /* 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. */
5798      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));
5799      /* Keep the STR_PTR on the top of the stack. */      /* Keep the STR_PTR on the top of the stack. */
5800      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5801          {
5802        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));
5803          if (extrasize == 2)
5804            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5805          }
5806      else if (bra == OP_BRAMINZERO)      else if (bra == OP_BRAMINZERO)
5807        {        {
5808        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 5815  if (opcode == OP_ASSERT || opcode == OP_
5815        {        {
5816        /* 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. */
5817        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));
5818        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));
5819        }        }
5820      else      else
5821        {        {
5822        /* 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. */
5823        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));
5824        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        if (extrasize == 2)
5825        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);          {
5826            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5827            if (bra == OP_BRAMINZERO)
5828              OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5829            }
5830          else
5831            {
5832            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
5833            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);
5834            }
5835        }        }
5836      }      }
5837    
5838    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
5839      {      {
5840      backtrack->matchingpath = LABEL();      backtrack->matchingpath = LABEL();
5841      sljit_set_label(jump, backtrack->matchingpath);      SET_LABEL(jump, backtrack->matchingpath);
5842      }      }
5843    else if (bra == OP_BRAMINZERO)    else if (bra == OP_BRAMINZERO)
5844      {      {
# Line 5291  else Line 5860  else
5860      {      {
5861      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5862      if (bra != OP_BRA)      if (bra != OP_BRA)
5863          {
5864          if (extrasize == 2)
5865            free_stack(common, 1);
5866        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5867          }
5868      else      else
5869        free_stack(common, 1);        free_stack(common, extrasize);
5870      }      }
5871    else    else
5872      {      {
5873      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5874      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
5875      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5876      if (bra != OP_BRA)      if (bra != OP_BRA)
5877        {        {
5878        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
5879        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5880        }        }
5881      else      else
5882        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
5883      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);
5884      }      }
5885    
# Line 5326  else Line 5899  else
5899      }      }
5900    }    }
5901    
5902  common->quitlabel = save_quitlabel;  common->local_exit = save_local_exit;
5903  common->acceptlabel = save_acceptlabel;  common->then_trap = save_then_trap;
5904    common->quit_label = save_quit_label;
5905    common->accept_label = save_accept_label;
5906  common->quit = save_quit;  common->quit = save_quit;
5907  common->accept = save_accept;  common->accept = save_accept;
5908  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
# Line 5443  if (i < name_count) Line 6018  if (i < name_count)
6018  return condition;  return condition;
6019  }  }
6020    
6021    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)
6022    {
6023    DEFINE_COMPILER;
6024    int stacksize;
6025    
6026    if (framesize < 0)
6027      {
6028      if (framesize == no_frame)
6029        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6030      else
6031        {
6032        stacksize = needs_control_head ? 1 : 0;
6033        if (ket != OP_KET || has_alternatives)
6034          stacksize++;
6035        free_stack(common, stacksize);
6036        }
6037    
6038      if (needs_control_head)
6039        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), (ket != OP_KET || has_alternatives) ? sizeof(sljit_sw) : 0);
6040    
6041      /* TMP2 which is set here used by OP_KETRMAX below. */
6042      if (ket == OP_KETRMAX)
6043        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);
6044      else if (ket == OP_KETRMIN)
6045        {
6046        /* Move the STR_PTR to the private_data_ptr. */
6047        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);
6048        }
6049      }
6050    else
6051      {
6052      stacksize = (ket != OP_KET || has_alternatives) ? 2 : 1;
6053      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + stacksize) * sizeof(sljit_sw));
6054      if (needs_control_head)
6055        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 0);
6056    
6057      if (ket == OP_KETRMAX)
6058        {
6059        /* TMP2 which is set here used by OP_KETRMAX below. */
6060        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6061        }
6062      }
6063    if (needs_control_head)
6064      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP1, 0);
6065    }
6066    
6067    static SLJIT_INLINE int match_capture_common(compiler_common *common, int stacksize, int offset, int private_data_ptr)
6068    {
6069    DEFINE_COMPILER;
6070    
6071    if (common->capture_last_ptr != 0)
6072      {
6073      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6074      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6075      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6076      stacksize++;
6077      }
6078    if (common->optimized_cbracket[offset >> 1] == 0)
6079      {
6080      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6081      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
6082      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6083      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6084      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6085      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
6086      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6087      stacksize += 2;
6088      }
6089    return stacksize;
6090    }
6091    
6092  /*  /*
6093    Handling bracketed expressions is probably the most complex part.    Handling bracketed expressions is probably the most complex part.
6094    
# Line 5511  pcre_uchar bra = OP_BRA; Line 6157  pcre_uchar bra = OP_BRA;
6157  pcre_uchar ket;  pcre_uchar ket;
6158  assert_backtrack *assert;  assert_backtrack *assert;
6159  BOOL has_alternatives;  BOOL has_alternatives;
6160    BOOL needs_control_head = FALSE;
6161  struct sljit_jump *jump;  struct sljit_jump *jump;
6162  struct sljit_jump *skip;  struct sljit_jump *skip;
6163  struct sljit_label *rmaxlabel = NULL;  struct sljit_label *rmaxlabel = NULL;
# Line 5586  else if (opcode == OP_ONCE || opcode == Line 6233  else if (opcode == OP_ONCE || opcode ==
6233    SLJIT_ASSERT(private_data_ptr != 0);    SLJIT_ASSERT(private_data_ptr != 0);
6234    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;
6235    if (opcode == OP_ONCE)    if (opcode == OP_ONCE)
6236      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, FALSE);      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, NULL, FALSE, &needs_control_head);
6237    }    }
6238    
6239  /* Instructions before the first alternative. */  /* Instructions before the first alternative. */
6240  stacksize = 0;  stacksize = 0;
6241  if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))  if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
6242    stacksize++;    stacksize++;
6243  if (bra == OP_BRAZERO)  if (bra == OP_BRAZERO)
6244    stacksize++;    stacksize++;
# Line 5600  if (stacksize > 0) Line 6247  if (stacksize > 0)
6247    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6248    
6249  stacksize = 0;  stacksize = 0;
6250  if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))  if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
6251    {    {
6252    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
6253    stacksize++;    stacksize++;
# Line 5663  if (ket == OP_KETRMAX) Line 6310  if (ket == OP_KETRMAX)
6310  /* Handling capturing brackets and alternatives. */  /* Handling capturing brackets and alternatives. */
6311  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
6312    {    {
6313      stacksize = 0;
6314      if (needs_control_head)
6315        {
6316        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6317        stacksize++;
6318        }
6319    
6320    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
6321      {      {
6322      /* Neither capturing brackets nor recursions are not found in the block. */      /* Neither capturing brackets nor recursions are found in the block. */
6323      if (ket == OP_KETRMIN)      if (ket == OP_KETRMIN)
6324        {        {
6325        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        stacksize += 2;
6326        allocate_stack(common, 2);        if (!needs_control_head)
6327        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));  
6328        }        }
6329      else if (ket == OP_KETRMAX || has_alternatives)      else
6330        {        {
6331        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);        if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)
6332        allocate_stack(common, 1);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6333        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);        if (ket == OP_KETRMAX || has_alternatives)
6334            stacksize++;
6335        }        }
6336      else  
6337        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);      if (stacksize > 0)
6338          allocate_stack(common, stacksize);
6339    
6340        stacksize = 0;
6341        if (needs_control_head)
6342          {
6343          stacksize++;
6344          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6345          }
6346    
6347        if (ket == OP_KETRMIN)
6348          {
6349          if (needs_control_head)
6350            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6351          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6352          if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)
6353            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));
6354          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6355          }
6356        else if (ket == OP_KETRMAX || has_alternatives)
6357          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6358      }      }
6359    else    else
6360      {      {
6361      if (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives)      if (ket != OP_KET || has_alternatives)
6362          stacksize++;
6363    
6364        stacksize += BACKTRACK_AS(bracket_backtrack)->u.framesize + 1;
6365        allocate_stack(common, stacksize);
6366    
6367        if (needs_control_head)
6368          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6369    
6370        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6371        OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, stacksize * sizeof(sljit_sw));
6372    
6373        stacksize = needs_control_head ? 1 : 0;
6374        if (ket != OP_KET || has_alternatives)
6375        {        {
6376        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);  
6377        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);
6378        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);        stacksize++;
6379        init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize + 1, 2, FALSE);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6380        }        }
6381      else      else
6382        {        {
       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));  
6383        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);
6384        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);  
6385        }        }
6386        init_frame(common, ccbegin, NULL, BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize, stacksize + 1, FALSE);
6387      }      }
6388    }    }
6389  else if (opcode == OP_CBRA || opcode == OP_SCBRA)  else if (opcode == OP_CBRA || opcode == OP_SCBRA)
6390    {    {
6391    /* Saving the previous values. */    /* Saving the previous values. */
6392    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  
6393      {      {
6394      SLJIT_ASSERT(private_data_ptr == OVECTOR(offset));      SLJIT_ASSERT(private_data_ptr == OVECTOR(offset));
6395      allocate_stack(common, 2);      allocate_stack(common, 2);
# Line 5730  else if (opcode == OP_CBRA || opcode == Line 6399  else if (opcode == OP_CBRA || opcode ==
6399      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
6400      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6401      }      }
6402      else
6403        {
6404        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6405        allocate_stack(common, 1);
6406        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);
6407        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6408        }
6409    }    }
6410  else if (opcode == OP_SBRA || opcode == OP_SCOND)  else if (opcode == OP_SBRA || opcode == OP_SCOND)
6411    {    {
# Line 5765  if (opcode == OP_COND || opcode == OP_SC Line 6441  if (opcode == OP_COND || opcode == OP_SC
6441      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);
6442      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);
6443      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);
6444      OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, (stacksize << 8) | (common->ovector_start / sizeof(sljit_sw)));      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (stacksize << 8) | (common->ovector_start / sizeof(sljit_sw)));
6445      GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, 0);      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, 0);
6446      OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, common->name_table);      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);
6447      sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchovector));      sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchovector));
6448      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
6449      add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0));      add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0));
6450    
6451      JUMPHERE(jump);      JUMPHERE(jump);
6452      matchingpath += 1 + IMM2_SIZE;      matchingpath += 1 + IMM2_SIZE;
# Line 5815  if (opcode == OP_COND || opcode == OP_SC Line 6491  if (opcode == OP_COND || opcode == OP_SC
6491        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);
6492        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);
6493        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, GET2(common->start, common->currententry->start + 1 + LINK_SIZE));        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, GET2(common->start, common->currententry->start + 1 + LINK_SIZE));
6494        OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, stacksize);        OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, stacksize);
6495        GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, 0);        GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, 0);
6496        OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, common->name_table);        OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);
6497        sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchgroups));        sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchgroups));
6498        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
6499        add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0));        add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0));
6500        matchingpath += 1 + IMM2_SIZE;        matchingpath += 1 + IMM2_SIZE;
6501        }        }
6502      }      }
# Line 5843  if (SLJIT_UNLIKELY(sljit_get_compiler_er Line 6519  if (SLJIT_UNLIKELY(sljit_get_compiler_er
6519    return NULL;    return NULL;
6520    
6521  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
6522    {    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));  
       }  
     }  
   }  
6523    
6524  stacksize = 0;  stacksize = 0;
6525  if (ket != OP_KET || bra != OP_BRA)  if (ket != OP_KET || bra != OP_BRA)
6526    stacksize++;    stacksize++;
6527    if (offset != 0)
6528      {
6529      if (common->capture_last_ptr != 0)
6530        stacksize++;
6531      if (common->optimized_cbracket[offset >> 1] == 0)
6532        stacksize += 2;
6533      }
6534  if (has_alternatives && opcode != OP_ONCE)  if (has_alternatives && opcode != OP_ONCE)
6535    stacksize++;    stacksize++;
6536    
# Line 5878  if (stacksize > 0) Line 6538  if (stacksize > 0)
6538    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6539    
6540  stacksize = 0;  stacksize = 0;
6541  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)  
6542    {    {
6543    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);    if (ket != OP_KET)
6544        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6545      else
6546        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
6547    stacksize++;    stacksize++;
6548    }    }
6549    
6550    if (offset != 0)
6551      stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);
6552    
6553  if (has_alternatives)  if (has_alternatives)
6554    {    {
6555    if (opcode != OP_ONCE)    if (opcode != OP_ONCE)
# Line 5898  if (has_alternatives) Line 6559  if (has_alternatives)
6559    }    }
6560    
6561  /* Must be after the matchingpath label. */  /* Must be after the matchingpath label. */
6562  if (offset != 0)  if (offset != 0 && common->optimized_cbracket[offset >> 1] != 0)
6563    {    {
6564    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    SLJIT_ASSERT(private_data_ptr == OVECTOR(offset + 0));
6565    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);  
6566    }    }
6567    
6568  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
# Line 5959  if ((ket != OP_KET && bra != OP_BRAMINZE Line 6619  if ((ket != OP_KET && bra != OP_BRAMINZE
6619  while (*cc == OP_ALT)  while (*cc == OP_ALT)
6620    cc += GET(cc, 1);    cc += GET(cc, 1);
6621  cc += 1 + LINK_SIZE;  cc += 1 + LINK_SIZE;
6622    
6623    /* Temporarily encoding the needs_control_head in framesize. */
6624    if (opcode == OP_ONCE)
6625      BACKTRACK_AS(bracket_backtrack)->u.framesize = (BACKTRACK_AS(bracket_backtrack)->u.framesize << 1) | (needs_control_head ? 1 : 0);
6626  return cc;  return cc;
6627  }  }
6628    
# Line 5969  backtrack_common *backtrack; Line 6633  backtrack_common *backtrack;
6633  pcre_uchar opcode;  pcre_uchar opcode;
6634  int private_data_ptr;  int private_data_ptr;
6635  int cbraprivptr = 0;  int cbraprivptr = 0;
6636    BOOL needs_control_head;
6637  int framesize;  int framesize;
6638  int stacksize;  int stacksize;
6639  int offset = 0;  int offset = 0;
6640  BOOL zero = FALSE;  BOOL zero = FALSE;
6641  pcre_uchar *ccbegin = NULL;  pcre_uchar *ccbegin = NULL;
6642  int stack;  int stack; /* Also contains the offset of control head. */
6643  struct sljit_label *loop = NULL;  struct sljit_label *loop = NULL;
6644  struct jump_list *emptymatch = NULL;  struct jump_list *emptymatch = NULL;
6645    
# Line 6012  switch(opcode) Line 6677  switch(opcode)
6677    break;    break;
6678    }    }
6679    
6680  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
6681  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;
6682  if (framesize < 0)  if (framesize < 0)
6683    {    {
6684    stacksize = (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS) ? 2 : 1;    if (offset != 0)
6685        {
6686        stacksize = 2;
6687        if (common->capture_last_ptr != 0)
6688          stacksize++;
6689        }
6690      else
6691        stacksize = 1;
6692    
6693      if (needs_control_head)
6694        stacksize++;
6695    if (!zero)    if (!zero)
6696      stacksize++;      stacksize++;
6697    
6698    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
6699    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6700    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    if (framesize == no_frame)
6701        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6702    
6703    if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)    stack = 0;
6704      if (offset != 0)
6705      {      {
6706        stack = 2;
6707      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6708      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));
6709      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
6710        if (common->capture_last_ptr != 0)
6711          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6712      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6713        if (needs_control_head)
6714          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6715        if (common->capture_last_ptr != 0)
6716          {
6717          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
6718          stack = 3;
6719          }
6720      }      }
6721    else    else
6722        {
6723        if (needs_control_head)
6724          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6725      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6726        stack = 1;
6727        }
6728    
6729      if (needs_control_head)
6730        stack++;
6731    if (!zero)    if (!zero)
6732      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);
6733      if (needs_control_head)
6734        {
6735        stack--;
6736        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP2, 0);
6737        }
6738    }    }
6739  else  else
6740    {    {
6741    stacksize = framesize + 1;    stacksize = framesize + 1;
6742    if (!zero)    if (!zero)
6743      stacksize++;      stacksize++;
6744    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)    if (needs_control_head)
6745        stacksize++;
6746      if (offset == 0)
6747      stacksize++;      stacksize++;
6748    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
   allocate_stack(common, stacksize);  
6749    
6750      allocate_stack(common, stacksize);
6751    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);
6752    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));    if (needs_control_head)
6753    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);
6754      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));
6755    
6756    stack = 0;    stack = 0;
6757    if (!zero)    if (!zero)
6758      {      {
6759      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 1);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 1);
6760        stack = 1;
6761        }
6762      if (needs_control_head)
6763        {
6764        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP2, 0);
6765      stack++;      stack++;
6766      }      }
6767    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)    if (offset == 0)
6768      {      {
6769      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), STR_PTR, 0);
6770      stack++;      stack++;
6771      }      }
6772    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP1, 0);
6773    init_frame(common, cc, stacksize - 1, stacksize - framesize, FALSE);    init_frame(common, cc, NULL, stacksize - 1, stacksize - framesize, FALSE);
6774      stack -= 1 + (offset == 0);
6775    }    }
6776    
6777  if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)  if (offset != 0)
6778    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6779    
6780  loop = LABEL();  loop = LABEL();
# Line 6080  while (*cc != OP_KETRPOS) Line 6790  while (*cc != OP_KETRPOS)
6790    
6791    if (framesize < 0)    if (framesize < 0)
6792      {      {
6793      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      if (framesize == no_frame)
6794          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6795    
6796      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6797        {        {
6798        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6799        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);
6800        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6801          if (common->capture_last_ptr != 0)
6802            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6803        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6804        }        }
6805      else      else
# Line 6104  while (*cc != OP_KETRPOS) Line 6817  while (*cc != OP_KETRPOS)
6817      }      }
6818    else    else
6819      {      {
6820      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6821        {        {
6822        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));
6823        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6824        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);
6825        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6826          if (common->capture_last_ptr != 0)
6827            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6828        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6829        }        }
6830      else      else
# Line 6132  while (*cc != OP_KETRPOS) Line 6847  while (*cc != OP_KETRPOS)
6847          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6848        }        }
6849      }      }
6850    
6851      if (needs_control_head)
6852        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(stack));
6853    
6854    JUMPTO(SLJIT_JUMP, loop);    JUMPTO(SLJIT_JUMP, loop);
6855    flush_stubs(common);    flush_stubs(common);
6856    
# Line 6142  while (*cc != OP_KETRPOS) Line 6861  while (*cc != OP_KETRPOS)
6861    
6862    if (framesize < 0)    if (framesize < 0)
6863      {      {
6864      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6865        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6866      else      else
6867        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6868      }      }
6869    else    else
6870      {      {
6871      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6872        {        {
6873        /* Last alternative. */        /* Last alternative. */
6874        if (*cc == OP_KETRPOS)        if (*cc == OP_KETRPOS)
# Line 6168  while (*cc != OP_KETRPOS) Line 6887  while (*cc != OP_KETRPOS)
6887    ccbegin = cc + 1 + LINK_SIZE;    ccbegin = cc + 1 + LINK_SIZE;
6888    }    }
6889    
6890    /* We don't have to restore the control head in case of a failed match. */
6891    
6892  backtrack->topbacktracks = NULL;  backtrack->topbacktracks = NULL;
6893  if (!zero)  if (!zero)
6894    {    {
# Line 6296  PUSH_BACKTRACK(sizeof(iterator_backtrack Line 7017  PUSH_BACKTRACK(sizeof(iterator_backtrack
7017    
7018  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);
7019    
7020  switch (type)  switch(type)
7021    {    {
7022    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
7023    case OP_DIGIT:    case OP_DIGIT:
# Line 6498  static SLJIT_INLINE pcre_uchar *compile_ Line 7219  static SLJIT_INLINE pcre_uchar *compile_
7219  DEFINE_COMPILER;  DEFINE_COMPILER;
7220  backtrack_common *backtrack;  backtrack_common *backtrack;
7221    
7222  PUSH_BACKTRACK(sizeof(bracket_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
7223    
7224  if (*cc == OP_FAIL)  if (*cc == OP_FAIL)
7225    {    {
# Line 6509  if (*cc == OP_FAIL) Line 7230  if (*cc == OP_FAIL)
7230  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL)  if (*cc == OP_ASSERT_ACCEPT || common->currententry != NULL)
7231    {    {
7232    /* No need to check notempty conditions. */    /* No need to check notempty conditions. */
7233    if (common->acceptlabel == NULL)    if (common->accept_label == NULL)
7234      add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP));
7235    else    else
7236      JUMPTO(SLJIT_JUMP, common->acceptlabel);      JUMPTO(SLJIT_JUMP, common->accept_label);
7237    return cc + 1;    return cc + 1;
7238    }    }
7239    
7240  if (common->acceptlabel == NULL)  if (common->accept_label == NULL)
7241    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)));
7242  else  else
7243    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);
7244  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
7245  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));
7246  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));
7247  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));
7248  if (common->acceptlabel == NULL)  if (common->accept_label == NULL)
7249    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));
7250  else  else
7251    CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, common->acceptlabel);    CMPTO(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0, common->accept_label);
7252  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));
7253  if (common->acceptlabel == NULL)  if (common->accept_label == NULL)
7254    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));
7255  else  else
7256    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);
7257  add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_JUMP));  add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_JUMP));
7258  return cc + 1;  return cc + 1;
7259  }  }
7260    
7261  static SLJIT_INLINE pcre_uchar *compile_close_matchingpath(compiler_common *common, pcre_uchar *cc)  static SLJIT_INLINE pcre_uchar *compile_close_matchingpath(compiler_common *common, pcre_uchar *cc)
7262    {
7263    DEFINE_COMPILER;
7264    int offset = GET2(cc, 1);
7265    BOOL optimized_cbracket = common->optimized_cbracket[offset] != 0;
7266    
7267    /* Data will be discarded anyway... */
7268    if (common->currententry != NULL)
7269      return cc + 1 + IMM2_SIZE;
7270    
7271    if (!optimized_cbracket)
7272      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR_PRIV(offset));
7273    offset <<= 1;
7274    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
7275    if (!optimized_cbracket)
7276      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
7277    return cc + 1 + IMM2_SIZE;
7278    }
7279    
7280    static SLJIT_INLINE pcre_uchar *compile_control_verb_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
7281    {
7282    DEFINE_COMPILER;
7283    backtrack_common *backtrack;
7284    pcre_uchar opcode = *cc;
7285    pcre_uchar *ccend = cc + 1;
7286    
7287    SLJIT_ASSERT(common->control_head_ptr != 0 || *cc == OP_COMMIT);
7288    
7289    if (opcode == OP_PRUNE_ARG || opcode == OP_SKIP_ARG || opcode == OP_THEN_ARG)
7290      ccend += 2 + cc[1];
7291    
7292    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
7293    
7294    if (opcode == OP_SKIP || opcode == OP_SKIP_ARG)
7295      {
7296      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
7297      allocate_stack(common, 3);
7298      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);
7299      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, *cc == OP_SKIP ? type_skip : type_skip_arg);
7300      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), (opcode == OP_SKIP) ? STR_PTR : SLJIT_IMM, (opcode == OP_SKIP) ? 0 : (sljit_sw)(cc + 2));
7301      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
7302      return ccend;
7303      }
7304    
7305    if (opcode == OP_PRUNE_ARG || opcode == OP_THEN_ARG)
7306      {
7307      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
7308      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));
7309      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);
7310      OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);
7311      }
7312    
7313    if (common->control_head_ptr != 0 && ((opcode != OP_THEN && opcode != OP_THEN_ARG) || common->then_trap == NULL))
7314      {
7315      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
7316      allocate_stack(common, 2);
7317      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);
7318      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, *cc == OP_COMMIT ? type_commit : type_prune);
7319      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
7320      }
7321    
7322    return ccend;
7323    }
7324    
7325    static pcre_uchar then_trap_opcode[1] = { OP_TABLE_LENGTH };
7326    
7327    static SLJIT_INLINE void compile_then_trap_matchingpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, backtrack_common *parent)
7328  {  {
7329  DEFINE_COMPILER;  DEFINE_COMPILER;
7330  int offset = GET2(cc, 1);  backtrack_common *backtrack;
7331  BOOL optimized_cbracket = common->optimized_cbracket[offset] != 0;  BOOL needs_control_head;
7332    int size;
 /* Data will be discarded anyway... */  
 if (common->currententry != NULL)  
   return cc + 1 + IMM2_SIZE;  
7333    
7334  if (!optimized_cbracket)  PUSH_BACKTRACK_NOVALUE(sizeof(then_trap_backtrack), cc);
7335    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR_PRIV(offset));  common->then_trap = BACKTRACK_AS(then_trap_backtrack);
7336  offset <<= 1;  BACKTRACK_AS(then_trap_backtrack)->common.cc = then_trap_opcode;
7337  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);  BACKTRACK_AS(then_trap_backtrack)->framesize = get_framesize(common, cc, ccend, FALSE, &needs_control_head);
7338  if (!optimized_cbracket)  
7339    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);  size = BACKTRACK_AS(then_trap_backtrack)->framesize;
7340  return cc + 1 + IMM2_SIZE;  size = 2 + (size < 0 ? 0 : size);
7341    
7342    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
7343    allocate_stack(common, size);
7344    if (size > 2)
7345      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0, SLJIT_IMM, (size - 2) * sizeof(sljit_sw));
7346    else
7347      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);
7348    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 1), SLJIT_IMM, type_then_trap);
7349    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 2), TMP2, 0);
7350    
7351    size = BACKTRACK_AS(then_trap_backtrack)->framesize;
7352    if (size >= 0)
7353      init_frame(common, cc, ccend, size - 1, 0, FALSE);
7354  }  }
7355    
7356  static void compile_matchingpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, backtrack_common *parent)  static void compile_matchingpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, backtrack_common *parent)
7357  {  {
7358  DEFINE_COMPILER;  DEFINE_COMPILER;
7359  backtrack_common *backtrack;  backtrack_common *backtrack;
7360    BOOL has_then_trap = FALSE;
7361    then_trap_backtrack *save_then_trap = NULL;
7362    
7363    SLJIT_ASSERT(*ccend == OP_END || (*ccend >= OP_ALT && *ccend <= OP_KETRPOS));
7364    
7365    if (common->has_then && common->then_offsets[cc - common->start] != 0)
7366      {
7367      SLJIT_ASSERT(*ccend != OP_END && common->control_head_ptr != 0);
7368      has_then_trap = TRUE;
7369      save_then_trap = common->then_trap;
7370      /* Tail item on backtrack. */
7371      compile_then_trap_matchingpath(common, cc, ccend, parent);
7372      }
7373    
7374  while (cc < ccend)  while (cc < ccend)
7375    {    {
# Line 6712  while (cc < ccend) Line 7522  while (cc < ccend)
7522      cc = compile_recurse_matchingpath(common, cc, parent);      cc = compile_recurse_matchingpath(common, cc, parent);
7523      break;      break;
7524    
7525        case OP_CALLOUT:
7526        cc = compile_callout_matchingpath(common, cc, parent);
7527        break;
7528    
7529      case OP_ASSERT:      case OP_ASSERT:
7530      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
7531      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 6772  while (cc < ccend) Line 7586  while (cc < ccend)
7586      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);
7587      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
7588      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
7589      allocate_stack(common, 1);      allocate_stack(common, common->has_skip_arg ? 5 : 1);
7590      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
7591      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(common->has_skip_arg ? 4 : 0), TMP2, 0);
7592      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));
7593      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);
7594      OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);
7595        if (common->has_skip_arg)
7596          {
7597          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
7598          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);
7599          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, type_mark);
7600          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), SLJIT_IMM, (sljit_sw)(cc + 2));
7601          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(3), STR_PTR, 0);
7602          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
7603          }
7604      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
7605      break;      break;
7606    
7607        case OP_PRUNE:
7608        case OP_PRUNE_ARG:
7609        case OP_SKIP:
7610        case OP_SKIP_ARG:
7611        case OP_THEN:
7612        case OP_THEN_ARG:
7613      case OP_COMMIT:      case OP_COMMIT:
7614      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);      cc = compile_control_verb_matchingpath(common, cc, parent);
     cc += 1;  
7615      break;      break;
7616    
7617      case OP_FAIL:      case OP_FAIL:
# Line 6807  while (cc < ccend) Line 7635  while (cc < ccend)
7635    if (cc == NULL)    if (cc == NULL)
7636      return;      return;
7637    }    }
7638    
7639    if (has_then_trap)
7640      {
7641      /* Head item on backtrack. */
7642      PUSH_BACKTRACK_NOVALUE(sizeof(then_trap_backtrack), cc);
7643      BACKTRACK_AS(then_trap_backtrack)->common.cc = then_trap_opcode;
7644      BACKTRACK_AS(then_trap_backtrack)->then_trap = common->then_trap;
7645      common->then_trap = save_then_trap;
7646      }
7647  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
7648  }  }
7649    
# Line 6968  switch(opcode) Line 7805  switch(opcode)
7805    }    }
7806  }  }
7807    
7808  static void compile_ref_iterator_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static SLJIT_INLINE void compile_ref_iterator_backtrackingpath(compiler_common *common, struct backtrack_common *current)
7809  {  {
7810  DEFINE_COMPILER;  DEFINE_COMPILER;
7811  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
# Line 6990  set_jumps(current->topbacktracks, LABEL( Line 7827  set_jumps(current->topbacktracks, LABEL(
7827  free_stack(common, 2);  free_stack(common, 2);
7828  }  }
7829    
7830  static void compile_recurse_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static SLJIT_INLINE void compile_recurse_backtrackingpath(compiler_common *common, struct backtrack_common *current)
7831  {  {
7832  DEFINE_COMPILER;  DEFINE_COMPILER;
7833    
7834    if (CURRENT_AS(recurse_backtrack)->inlined_pattern)
7835      compile_backtrackingpath(common, current->top);
7836  set_jumps(current->topbacktracks, LABEL());  set_jumps(current->topbacktracks, LABEL());
7837    if (CURRENT_AS(recurse_backtrack)->inlined_pattern)
7838      return;
7839    
7840  if (common->has_set_som && common->mark_ptr != 0)  if (common->has_set_som && common->mark_ptr != 0)
7841    {    {
# Line 7096  pcre_uchar bra = OP_BRA; Line 7937  pcre_uchar bra = OP_BRA;
7937  pcre_uchar ket;  pcre_uchar ket;
7938  assert_backtrack *assert;  assert_backtrack *assert;
7939  BOOL has_alternatives;  BOOL has_alternatives;
7940    BOOL needs_control_head = FALSE;
7941  struct sljit_jump *brazero = NULL;  struct sljit_jump *brazero = NULL;
7942  struct sljit_jump *once = NULL;  struct sljit_jump *once = NULL;
7943  struct sljit_jump *cond = NULL;  struct sljit_jump *cond = NULL;
# Line 7121  if (SLJIT_UNLIKELY(opcode == OP_COND) && Line 7963  if (SLJIT_UNLIKELY(opcode == OP_COND) &&
7963  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))
7964    opcode = OP_ONCE;    opcode = OP_ONCE;
7965    
7966    /* Decoding the needs_control_head in framesize. */
7967    if (opcode == OP_ONCE)
7968      {
7969      needs_control_head = (CURRENT_AS(bracket_backtrack)->u.framesize & 0x1) != 0;
7970      CURRENT_AS(bracket_backtrack)->u.framesize >>= 1;
7971      }
7972    
7973  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
7974    {    {
7975    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
# Line 7160  else if (bra == OP_BRAZERO) Line 8009  else if (bra == OP_BRAZERO)
8009    brazero = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0);    brazero = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0);
8010    }    }
8011    
8012    if (offset != 0)
8013      {
8014      if (common->capture_last_ptr != 0)
8015        {
8016        SLJIT_ASSERT(common->optimized_cbracket[offset >> 1] == 0);
8017        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8018        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
8019        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, TMP1, 0);
8020        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
8021        free_stack(common, 3);
8022        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP2, 0);
8023        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
8024        }
8025      else if (common->optimized_cbracket[offset >> 1] == 0)
8026        {
8027        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8028        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
8029        free_stack(common, 2);
8030        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
8031        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);
8032        }
8033      }
8034    
8035  if (SLJIT_UNLIKELY(opcode == OP_ONCE))  if (SLJIT_UNLIKELY(opcode == OP_ONCE))
8036    {    {
8037    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
# Line 7255  if (has_alternatives) Line 8127  if (has_alternatives)
8127      current->top = NULL;      current->top = NULL;
8128      current->topbacktracks = NULL;      current->topbacktracks = NULL;
8129      current->nextbacktracks = NULL;      current->nextbacktracks = NULL;
8130        /* Conditional blocks always have an additional alternative, even if it is empty. */
8131      if (*cc == OP_ALT)      if (*cc == OP_ALT)
8132        {        {
8133        ccprev = cc + 1 + LINK_SIZE;        ccprev = cc + 1 + LINK_SIZE;
8134        cc += GET(cc, 1);        cc += GET(cc, 1);
8135        if (opcode != OP_COND && opcode != OP_SCOND)        if (opcode != OP_COND && opcode != OP_SCOND)
8136          {          {
8137          if (private_data_ptr != 0 && opcode != OP_ONCE)          if (opcode != OP_ONCE)
8138            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);            {
8139              if (private_data_ptr != 0)
8140                OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
8141              else
8142                OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8143              }
8144          else          else
8145            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));
8146          }          }
8147        compile_matchingpath(common, ccprev, cc, current);        compile_matchingpath(common, ccprev, cc, current);
8148        if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))        if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
# Line 7274  if (has_alternatives) Line 8152  if (has_alternatives)
8152      /* Instructions after the current alternative is succesfully matched. */      /* Instructions after the current alternative is succesfully matched. */
8153      /* There is a similar code in compile_bracket_matchingpath. */      /* There is a similar code in compile_bracket_matchingpath. */
8154      if (opcode == OP_ONCE)      if (opcode == OP_ONCE)
8155        {        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));  
           }  
         }  
       }  
8156    
8157      stacksize = 0;      stacksize = 0;
     if (opcode != OP_ONCE)  
       stacksize++;  
8158      if (ket != OP_KET || bra != OP_BRA)      if (ket != OP_KET || bra != OP_BRA)
8159        stacksize++;        stacksize++;
8160        if (offset != 0)
8161          {
8162          if (common->capture_last_ptr != 0)
8163            stacksize++;
8164          if (common->optimized_cbracket[offset >> 1] == 0)
8165            stacksize += 2;
8166          }
8167        if (opcode != OP_ONCE)
8168          stacksize++;
8169    
8170      if (stacksize > 0) {      if (stacksize > 0)
8171          {
8172        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize >= 0)        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
8173          allocate_stack(common, stacksize);          allocate_stack(common, stacksize);
8174        else        else
# Line 7313  if (has_alternatives) Line 8177  if (has_alternatives)
8177          SLJIT_ASSERT(stacksize == 1);          SLJIT_ASSERT(stacksize == 1);
8178          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));
8179          }          }
8180      }        }
8181    
8182      stacksize = 0;      stacksize = 0;
8183      if (ket != OP_KET || bra != OP_BRA)      if (ket != OP_KET || bra != OP_BRA)
# Line 7325  if (has_alternatives) Line 8189  if (has_alternatives)
8189        stacksize++;        stacksize++;
8190        }        }
8191    
8192        if (offset != 0)
8193          stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);
8194    
8195      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
8196        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, count++);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, count++);
8197    
8198      if (offset != 0)      if (offset != 0 && ket == OP_KETRMAX && common->optimized_cbracket[offset >> 1] != 0)
8199        {        {
8200        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. */
8201          SLJIT_ASSERT(private_data_ptr == OVECTOR(offset + 0));
8202        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);  
8203        }        }
8204    
8205      JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->alternative_matchingpath);      JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->alternative_matchingpath);
# Line 7357  if (has_alternatives) Line 8224  if (has_alternatives)
8224      SLJIT_ASSERT(opcode == OP_COND || opcode == OP_SCOND);      SLJIT_ASSERT(opcode == OP_COND || opcode == OP_SCOND);
8225      assert = CURRENT_AS(bracket_backtrack)->u.assert;      assert = CURRENT_AS(bracket_backtrack)->u.assert;
8226      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)
   
8227        {        {
8228        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);
8229        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
# Line 7374  if (has_alternatives) Line 8240  if (has_alternatives)
8240  if (offset != 0)  if (offset != 0)
8241    {    {
8242    /* Using both tmp register is better for instruction scheduling. */    /* Using both tmp register is better for instruction scheduling. */
8243    if (common->optimized_cbracket[offset >> 1] == 0)    if (common->optimized_cbracket[offset >> 1] != 0)
8244      {      {
8245      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8246      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
8247        free_stack(common, 2);
8248      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);  
8249      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);  
8250      }      }
8251    else    else
8252      {      {
8253      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8254      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      free_stack(common, 1);
8255      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);  
8256      }      }
8257    }    }
8258  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 8263  else if (opcode == OP_SBRA || opcode ==
8263  else if (opcode == OP_ONCE)  else if (opcode == OP_ONCE)
8264    {    {
8265    cc = ccbegin + GET(ccbegin, 1);    cc = ccbegin + GET(ccbegin, 1);
8266      stacksize = needs_control_head ? 1 : 0;
8267    
8268    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
8269      {      {
8270      /* Reset head and drop saved frame. */      /* Reset head and drop saved frame. */
8271      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);  
8272      }      }
8273    else if (ket == OP_KETRMAX || (*cc == OP_ALT && ket != OP_KETRMIN))    else if (ket == OP_KETRMAX || (*cc == OP_ALT && ket != OP_KETRMIN))
8274      {      {
8275      /* The STR_PTR must be released. */      /* The STR_PTR must be released. */
8276      free_stack(common, 1);      stacksize++;
8277      }      }
8278      free_stack(common, stacksize);
8279    
8280    JUMPHERE(once);    JUMPHERE(once);
8281    /* Restore previous private_data_ptr */    /* Restore previous private_data_ptr */
# Line 7463  else if (bra == OP_BRAZERO) Line 8327  else if (bra == OP_BRAZERO)
8327