/[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 1055 by chpe, Tue Oct 16 15:53:30 2012 UTC revision 1277 by zherczeg, Mon Mar 11 09:50:29 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11    The machine code generator part (this module) was written by Zoltan Herczeg    The machine code generator part (this module) was written by Zoltan Herczeg
12                        Copyright (c) 2010-2012                        Copyright (c) 2010-2013
13    
14  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
15  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 65  system files. */ Line 65  system files. */
65  #error Unsupported architecture  #error Unsupported architecture
66  #endif  #endif
67    
68    /* Defines for debugging purposes. */
69    
70    /* 1 - Use unoptimized capturing brackets.
71       2 - Enable capture_last_ptr (includes option 1). */
72    /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */
73    
74    /* 1 - Always have a control head. */
75    /* #define DEBUG_FORCE_CONTROL_HEAD 1 */
76    
77  /* Allocate memory for the regex stack on the real machine stack.  /* Allocate memory for the regex stack on the real machine stack.
78  Fast, but limited size. */  Fast, but limited size. */
79  #define MACHINE_STACK_SIZE 32768  #define MACHINE_STACK_SIZE 32768
# Line 157  typedef struct jit_arguments { Line 166  typedef struct jit_arguments {
166    int *offsets;    int *offsets;
167    pcre_uchar *uchar_ptr;    pcre_uchar *uchar_ptr;
168    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
169      void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171    int offsetcount;    int real_offset_count;
172    int calllimit;    int offset_count;
173      int call_limit;
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 170  typedef struct executable_functions { Line 181  typedef struct executable_functions {
181    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184      pcre_uint32 top_bracket;
185    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
186  } executable_functions;  } executable_functions;
187    
# Line 178  typedef struct jump_list { Line 190  typedef struct jump_list {
190    struct jump_list *next;    struct jump_list *next;
191  } jump_list;  } jump_list;
192    
 enum stub_types { stack_alloc };  
   
193  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
194    struct sljit_jump *start;    struct sljit_jump *start;
195    struct sljit_label *quit;    struct sljit_label *quit;
196    struct stub_list *next;    struct stub_list *next;
197  } stub_list;  } stub_list;
198    
199    enum frame_types {
200      no_frame = -1,
201      no_stack = -2
202    };
203    
204    enum control_types {
205      type_commit = 0,
206      type_prune = 1,
207      type_skip = 2
208    };
209    
210  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
# Line 208  typedef struct backtrack_common { Line 227  typedef struct backtrack_common {
227  typedef struct assert_backtrack {  typedef struct assert_backtrack {
228    backtrack_common common;    backtrack_common common;
229    jump_list *condfailed;    jump_list *condfailed;
230    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
231    int framesize;    int framesize;
232    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
233    int private_data_ptr;    int private_data_ptr;
# Line 229  typedef struct bracket_backtrack { Line 248  typedef struct bracket_backtrack {
248      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
249      jump_list *condfailed;      jump_list *condfailed;
250      assert_backtrack *assert;      assert_backtrack *assert;
251      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
252      int framesize;      int framesize;
253    } u;    } u;
254    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
# Line 269  typedef struct recurse_entry { Line 288  typedef struct recurse_entry {
288    
289  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
290    backtrack_common common;    backtrack_common common;
291      BOOL inlined_pattern;
292  } recurse_backtrack;  } recurse_backtrack;
293    
294  #define MAX_RANGE_SIZE 6  #define MAX_RANGE_SIZE 6
295    
296  typedef struct compiler_common {  typedef struct compiler_common {
297      /* The sljit ceneric compiler. */
298    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
299      /* First byte code. */
300    pcre_uchar *start;    pcre_uchar *start;
   
301    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
302    int *private_data_ptrs;    int *private_data_ptrs;
303    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
304    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
305    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
306    int cbraptr;    int cbra_ptr;
307    /* OVector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
308    int ovector_start;    int ovector_start;
309    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
310    int req_char_ptr;    int req_char_ptr;
311    /* Head of the last recursion. */    /* Head of the last recursion. */
312    int recursive_head;    int recursive_head_ptr;
313    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
314    int start_used_ptr;    int start_used_ptr;
315    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 297  typedef struct compiler_common { Line 318  typedef struct compiler_common {
318    int first_line_end;    int first_line_end;
319    /* Points to the marked string. */    /* Points to the marked string. */
320    int mark_ptr;    int mark_ptr;
321      /* Recursive control verb management chain. */
322      int control_head_ptr;
323      /* Points to the last matched capture block index. */
324      int capture_last_ptr;
325      /* Points to the starting position of the current match. */
326      int start_ptr;
327    
328    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
329    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
330    sljit_w lcc;    sljit_sw lcc;
331    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
332    int mode;    int mode;
333      /* \K is in the pattern. */
334      BOOL has_set_som;
335      /* Needs to know the start position anytime. */
336      BOOL needs_start_ptr;
337      /* Currently in recurse or assert. */
338      BOOL local_exit;
339    /* Newline control. */    /* Newline control. */
340    int nltype;    int nltype;
341    int newline;    int newline;
342    int bsr_nltype;    int bsr_nltype;
343    /* Dollar endonly. */    /* Dollar endonly. */
344    int endonly;    int endonly;
   BOOL has_set_som;  
345    /* Tables. */    /* Tables. */
346    sljit_w ctypes;    sljit_sw ctypes;
347    int digits[2 + MAX_RANGE_SIZE];    int digits[2 + MAX_RANGE_SIZE];
348    /* Named capturing brackets. */    /* Named capturing brackets. */
349    sljit_uw name_table;    sljit_uw name_table;
350    sljit_w name_count;    sljit_sw name_count;
351    sljit_w name_entry_size;    sljit_sw name_entry_size;
352    
353    /* Labels and jump lists. */    /* Labels and jump lists. */
354    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
355    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
356    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
357      struct sljit_label *accept_label;
358    stub_list *stubs;    stub_list *stubs;
359    recurse_entry *entries;    recurse_entry *entries;
360    recurse_entry *currententry;    recurse_entry *currententry;
361    jump_list *partialmatch;    jump_list *partialmatch;
362    jump_list *quit;    jump_list *quit;
363      jump_list *forced_quit;
364    jump_list *accept;    jump_list *accept;
365    jump_list *calllimit;    jump_list *calllimit;
366    jump_list *stackalloc;    jump_list *stackalloc;
# Line 337  typedef struct compiler_common { Line 371  typedef struct compiler_common {
371    jump_list *vspace;    jump_list *vspace;
372    jump_list *casefulcmp;    jump_list *casefulcmp;
373    jump_list *caselesscmp;    jump_list *caselesscmp;
374      jump_list *reset_match;
375    BOOL jscript_compat;    BOOL jscript_compat;
376  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
377    BOOL utf;    BOOL utf;
# Line 363  typedef struct compare_context { Line 398  typedef struct compare_context {
398  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
399    int ucharptr;    int ucharptr;
400    union {    union {
401      sljit_i asint;      sljit_si asint;
402      sljit_uh asushort;      sljit_uh asushort;
403  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
404      sljit_ub asbyte;      sljit_ub asbyte;
# Line 375  typedef struct compare_context { Line 410  typedef struct compare_context {
410  #endif  #endif
411    } c;    } c;
412    union {    union {
413      sljit_i asint;      sljit_si asint;
414      sljit_uh asushort;      sljit_uh asushort;
415  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
416      sljit_ub asbyte;      sljit_ub asbyte;
# Line 389  typedef struct compare_context { Line 424  typedef struct compare_context {
424  #endif  #endif
425  } compare_context;  } compare_context;
426    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
427  /* Undefine sljit macros. */  /* Undefine sljit macros. */
428  #undef CMP  #undef CMP
429    
430  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
431  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
432    
433  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
434  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
435  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
436  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
437  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
438  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
439  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
440  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
441  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define CALL_COUNT    SLJIT_SAVED_EREG2
# Line 414  enum { Line 443  enum {
443    
444  /* Local space layout. */  /* Local space layout. */
445  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
446  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
447  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
448  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
449  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
450  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
451  /* Max limit of recursions. */  /* Max limit of recursions. */
452  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define CALL_LIMIT       (4 * sizeof(sljit_sw))
453  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
454  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
455  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
456  the start pointers when the end of the capturing group has not yet reached. */  the start pointers when the end of the capturing group has not yet reached. */
457  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
458  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
459  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * sizeof(sljit_sw))
460  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
461    
462  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
# Line 458  the start pointers when the end of the c Line 487  the start pointers when the end of the c
487    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
488  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
489    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
490    #define SET_LABEL(jump, label) \
491      sljit_set_label((jump), (label))
492  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
493    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
494  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
495    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))
496  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
497    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
498  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
499    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
500    
# Line 482  return cc; Line 513  return cc;
513   set_private_data_ptrs   set_private_data_ptrs
514   get_framesize   get_framesize
515   init_frame   init_frame
516   get_private_data_length_for_copy   get_private_data_copy_length
517   copy_private_data   copy_private_data
518   compile_matchingpath   compile_matchingpath
519   compile_backtrackingpath   compile_backtrackingpath
# Line 506  switch(*cc) Line 537  switch(*cc)
537    case OP_WORDCHAR:    case OP_WORDCHAR:
538    case OP_ANY:    case OP_ANY:
539    case OP_ALLANY:    case OP_ALLANY:
540      case OP_NOTPROP:
541      case OP_PROP:
542    case OP_ANYNL:    case OP_ANYNL:
543    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
544    case OP_HSPACE:    case OP_HSPACE:
# Line 518  switch(*cc) Line 551  switch(*cc)
551    case OP_CIRCM:    case OP_CIRCM:
552    case OP_DOLL:    case OP_DOLL:
553    case OP_DOLLM:    case OP_DOLLM:
   case OP_TYPESTAR:  
   case OP_TYPEMINSTAR:  
   case OP_TYPEPLUS:  
   case OP_TYPEMINPLUS:  
   case OP_TYPEQUERY:  
   case OP_TYPEMINQUERY:  
   case OP_TYPEPOSSTAR:  
   case OP_TYPEPOSPLUS:  
   case OP_TYPEPOSQUERY:  
554    case OP_CRSTAR:    case OP_CRSTAR:
555    case OP_CRMINSTAR:    case OP_CRMINSTAR:
556    case OP_CRPLUS:    case OP_CRPLUS:
557    case OP_CRMINPLUS:    case OP_CRMINPLUS:
558    case OP_CRQUERY:    case OP_CRQUERY:
559    case OP_CRMINQUERY:    case OP_CRMINQUERY:
560      case OP_CRRANGE:
561      case OP_CRMINRANGE:
562      case OP_CLASS:
563      case OP_NCLASS:
564      case OP_REF:
565      case OP_REFI:
566      case OP_RECURSE:
567      case OP_CALLOUT:
568      case OP_ALT:
569      case OP_KET:
570      case OP_KETRMAX:
571      case OP_KETRMIN:
572      case OP_KETRPOS:
573      case OP_REVERSE:
574      case OP_ASSERT:
575      case OP_ASSERT_NOT:
576      case OP_ASSERTBACK:
577      case OP_ASSERTBACK_NOT:
578      case OP_ONCE:
579      case OP_ONCE_NC:
580      case OP_BRA:
581      case OP_BRAPOS:
582      case OP_CBRA:
583      case OP_CBRAPOS:
584      case OP_COND:
585      case OP_SBRA:
586      case OP_SBRAPOS:
587      case OP_SCBRA:
588      case OP_SCBRAPOS:
589      case OP_SCOND:
590      case OP_CREF:
591      case OP_NCREF:
592      case OP_RREF:
593      case OP_NRREF:
594    case OP_DEF:    case OP_DEF:
595    case OP_BRAZERO:    case OP_BRAZERO:
596    case OP_BRAMINZERO:    case OP_BRAMINZERO:
597    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
598      case OP_PRUNE:
599      case OP_SKIP:
600    case OP_COMMIT:    case OP_COMMIT:
601    case OP_FAIL:    case OP_FAIL:
602    case OP_ACCEPT:    case OP_ACCEPT:
603    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
604      case OP_CLOSE:
605    case OP_SKIPZERO:    case OP_SKIPZERO:
606    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
607    
608    case OP_CHAR:    case OP_CHAR:
609    case OP_CHARI:    case OP_CHARI:
# Line 560  switch(*cc) Line 615  switch(*cc)
615    case OP_MINPLUS:    case OP_MINPLUS:
616    case OP_QUERY:    case OP_QUERY:
617    case OP_MINQUERY:    case OP_MINQUERY:
618      case OP_UPTO:
619      case OP_MINUPTO:
620      case OP_EXACT:
621    case OP_POSSTAR:    case OP_POSSTAR:
622    case OP_POSPLUS:    case OP_POSPLUS:
623    case OP_POSQUERY:    case OP_POSQUERY:
624      case OP_POSUPTO:
625    case OP_STARI:    case OP_STARI:
626    case OP_MINSTARI:    case OP_MINSTARI:
627    case OP_PLUSI:    case OP_PLUSI:
628    case OP_MINPLUSI:    case OP_MINPLUSI:
629    case OP_QUERYI:    case OP_QUERYI:
630    case OP_MINQUERYI:    case OP_MINQUERYI:
631      case OP_UPTOI:
632      case OP_MINUPTOI:
633      case OP_EXACTI:
634    case OP_POSSTARI:    case OP_POSSTARI:
635    case OP_POSPLUSI:    case OP_POSPLUSI:
636    case OP_POSQUERYI:    case OP_POSQUERYI:
637      case OP_POSUPTOI:
638    case OP_NOTSTAR:    case OP_NOTSTAR:
639    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
640    case OP_NOTPLUS:    case OP_NOTPLUS:
641    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
642    case OP_NOTQUERY:    case OP_NOTQUERY:
643    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
644      case OP_NOTUPTO:
645      case OP_NOTMINUPTO:
646      case OP_NOTEXACT:
647    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
648    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
649    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
650      case OP_NOTPOSUPTO:
651    case OP_NOTSTARI:    case OP_NOTSTARI:
652    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
653    case OP_NOTPLUSI:    case OP_NOTPLUSI:
654    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
655    case OP_NOTQUERYI:    case OP_NOTQUERYI:
656    case OP_NOTMINQUERYI:    case OP_NOTMINQUERYI:
   case OP_NOTPOSSTARI:  
   case OP_NOTPOSPLUSI:  
   case OP_NOTPOSQUERYI:  
   cc += 2;  
 #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  
   if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
   return cc;  
   
   case OP_UPTO:  
   case OP_MINUPTO:  
   case OP_EXACT:  
   case OP_POSUPTO:  
   case OP_UPTOI:  
   case OP_MINUPTOI:  
   case OP_EXACTI:  
   case OP_POSUPTOI:  
   case OP_NOTUPTO:  
   case OP_NOTMINUPTO:  
   case OP_NOTEXACT:  
   case OP_NOTPOSUPTO:  
657    case OP_NOTUPTOI:    case OP_NOTUPTOI:
658    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
659    case OP_NOTEXACTI:    case OP_NOTEXACTI:
660      case OP_NOTPOSSTARI:
661      case OP_NOTPOSPLUSI:
662      case OP_NOTPOSQUERYI:
663    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
664    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
665  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
666    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
667  #endif  #endif
668    return cc;    return cc;
669    
670    case OP_NOTPROP:    /* Special cases. */
671    case OP_PROP:    case OP_TYPESTAR:
672    return cc + 1 + 2;    case OP_TYPEMINSTAR:
673      case OP_TYPEPLUS:
674      case OP_TYPEMINPLUS:
675      case OP_TYPEQUERY:
676      case OP_TYPEMINQUERY:
677    case OP_TYPEUPTO:    case OP_TYPEUPTO:
678    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
679    case OP_TYPEEXACT:    case OP_TYPEEXACT:
680      case OP_TYPEPOSSTAR:
681      case OP_TYPEPOSPLUS:
682      case OP_TYPEPOSQUERY:
683    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
684    case OP_REF:    return cc + PRIV(OP_lengths)[*cc] - 1;
   case OP_REFI:  
   case OP_CREF:  
   case OP_NCREF:  
   case OP_RREF:  
   case OP_NRREF:  
   case OP_CLOSE:  
   cc += 1 + IMM2_SIZE;  
   return cc;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   return cc + 1 + 2 * IMM2_SIZE;  
685    
686    case OP_CLASS:    case OP_ANYBYTE:
687    case OP_NCLASS:  #ifdef SUPPORT_UTF
688    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
689    #endif
690      return cc + 1;
691    
692  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
693    case OP_XCLASS:    case OP_XCLASS:
694    return cc + GET(cc, 1);    return cc + GET(cc, 1);
695  #endif  #endif
696    
   case OP_RECURSE:  
   case OP_ASSERT:  
   case OP_ASSERT_NOT:  
   case OP_ASSERTBACK:  
   case OP_ASSERTBACK_NOT:  
   case OP_REVERSE:  
   case OP_ONCE:  
   case OP_ONCE_NC:  
   case OP_BRA:  
   case OP_BRAPOS:  
   case OP_COND:  
   case OP_SBRA:  
   case OP_SBRAPOS:  
   case OP_SCOND:  
   case OP_ALT:  
   case OP_KET:  
   case OP_KETRMAX:  
   case OP_KETRMIN:  
   case OP_KETRPOS:  
   return cc + 1 + LINK_SIZE;  
   
   case OP_CBRA:  
   case OP_CBRAPOS:  
   case OP_SCBRA:  
   case OP_SCBRAPOS:  
   return cc + 1 + LINK_SIZE + IMM2_SIZE;  
   
697    case OP_MARK:    case OP_MARK:
698      case OP_PRUNE_ARG:
699    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
700    
701    default:    default:
# Line 767  int private_data_length = 0; Line 786  int private_data_length = 0;
786  pcre_uchar *alternative;  pcre_uchar *alternative;
787  pcre_uchar *name;  pcre_uchar *name;
788  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
789  int space, size, bracketlen, i;  int space, size, i;
790    pcre_uint32 bracketlen;
791    
792  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
793  while (cc < ccend)  while (cc < ccend)
# Line 797  while (cc < ccend) Line 817  while (cc < ccend)
817      case OP_BRAPOS:      case OP_BRAPOS:
818      case OP_SBRA:      case OP_SBRA:
819      case OP_SBRAPOS:      case OP_SBRAPOS:
820      private_data_length += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
821      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
822      break;      break;
823    
824      case OP_CBRAPOS:      case OP_CBRAPOS:
825      case OP_SCBRAPOS:      case OP_SCBRAPOS:
826      private_data_length += sizeof(sljit_w);      private_data_length += sizeof(sljit_sw);
827      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
828      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
829      break;      break;
830    
831      case OP_COND:      case OP_COND:
832      case OP_SCOND:      case OP_SCOND:
833      bracketlen = cc[1 + LINK_SIZE];      /* Only AUTO_CALLOUT can insert this opcode. We do
834      if (bracketlen == OP_CREF)         not intend to support this case. */
835        {      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
836        bracketlen = GET2(cc, 1 + LINK_SIZE + 1);        return -1;
       common->optimized_cbracket[bracketlen] = 0;  
       }  
     else if (bracketlen == OP_NCREF)  
       {  
       bracketlen = GET2(cc, 1 + LINK_SIZE + 1);  
       name = (pcre_uchar *)common->name_table;  
       alternative = name;  
       for (i = 0; i < common->name_count; i++)  
         {  
         if (GET2(name, 0) == bracketlen) break;  
         name += common->name_entry_size;  
         }  
       SLJIT_ASSERT(i != common->name_count);  
   
       for (i = 0; i < common->name_count; i++)  
         {  
         if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)  
           common->optimized_cbracket[GET2(alternative, 0)] = 0;  
         alternative += common->name_entry_size;  
         }  
       }  
837    
838      if (*cc == OP_COND)      if (*cc == OP_COND)
839        {        {
840        /* Might be a hidden SCOND. */        /* Might be a hidden SCOND. */
841        alternative = cc + GET(cc, 1);        alternative = cc + GET(cc, 1);
842        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
843          private_data_length += sizeof(sljit_w);          private_data_length += sizeof(sljit_sw);
844        }        }
845      else      else
846        private_data_length += sizeof(sljit_w);        private_data_length += sizeof(sljit_sw);
847      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
848      break;      break;
849    
850        case OP_CREF:
851        i = GET2(cc, 1);
852        common->optimized_cbracket[i] = 0;
853        cc += 1 + IMM2_SIZE;
854        break;
855    
856        case OP_NCREF:
857        bracketlen = GET2(cc, 1);
858        name = (pcre_uchar *)common->name_table;
859        alternative = name;
860        for (i = 0; i < common->name_count; i++)
861          {
862          if (GET2(name, 0) == bracketlen) break;
863          name += common->name_entry_size;
864          }
865        SLJIT_ASSERT(i != common->name_count);
866    
867        for (i = 0; i < common->name_count; i++)
868          {
869          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)
870            common->optimized_cbracket[GET2(alternative, 0)] = 0;
871          alternative += common->name_entry_size;
872          }
873        bracketlen = 0;
874        cc += 1 + IMM2_SIZE;
875        break;
876    
877      case OP_BRA:      case OP_BRA:
878      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
879      break;      break;
# Line 904  while (cc < ccend) Line 930  while (cc < ccend)
930    
931      case OP_RECURSE:      case OP_RECURSE:
932      /* Set its value only once. */      /* Set its value only once. */
933      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
934        {        {
935        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
936        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
937        }        }
938      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
939      break;      break;
940    
941        case OP_CALLOUT:
942        if (common->capture_last_ptr == 0)
943          {
944          common->capture_last_ptr = common->ovector_start;
945          common->ovector_start += sizeof(sljit_sw);
946          }
947        cc += 2 + 2 * LINK_SIZE;
948        break;
949    
950        case OP_PRUNE_ARG:
951        common->needs_start_ptr = TRUE;
952        common->control_head_ptr = 1;
953        /* Fall through. */
954    
955      case OP_MARK:      case OP_MARK:
956      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
957        {        {
958        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
959        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
960        }        }
961      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
962      break;      break;
963    
964        case OP_PRUNE:
965        case OP_SKIP:
966        common->needs_start_ptr = TRUE;
967        /* Fall through. */
968    
969        case OP_COMMIT:
970        common->control_head_ptr = 1;
971        cc += 1;
972        break;
973    
974      default:      default:
975      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
976      if (cc == NULL)      if (cc == NULL)
# Line 929  while (cc < ccend) Line 979  while (cc < ccend)
979      }      }
980    
981    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
982      private_data_length += sizeof(sljit_w) * space;      private_data_length += sizeof(sljit_sw) * space;
983    
984    if (size != 0)    if (size != 0)
985      {      {
986      if (size < 0)      if (size < 0)
987        {        {
988        cc += -size;        cc += -size;
989  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
990        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
991  #endif  #endif
992        }        }
# Line 944  while (cc < ccend) Line 994  while (cc < ccend)
994        cc += size;        cc += size;
995      }      }
996    
997    if (bracketlen > 0)    if (bracketlen != 0)
998      {      {
999      if (cc >= end)      if (cc >= end)
1000        {        {
# Line 983  while (cc < ccend) Line 1033  while (cc < ccend)
1033      case OP_SBRAPOS:      case OP_SBRAPOS:
1034      case OP_SCOND:      case OP_SCOND:
1035      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1036      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1037      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1038      break;      break;
1039    
1040      case OP_CBRAPOS:      case OP_CBRAPOS:
1041      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1042      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1043      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1044      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1045      break;      break;
1046    
# Line 1000  while (cc < ccend) Line 1050  while (cc < ccend)
1050      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1051        {        {
1052        common->private_data_ptrs[cc - common->start] = private_data_ptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1053        private_data_ptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1054        }        }
1055      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1056      break;      break;
# Line 1068  while (cc < ccend) Line 1118  while (cc < ccend)
1118    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1119      {      {
1120      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1121      private_data_ptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1122      }      }
1123    
1124    if (size != 0)    if (size != 0)
# Line 1076  while (cc < ccend) Line 1126  while (cc < ccend)
1126      if (size < 0)      if (size < 0)
1127        {        {
1128        cc += -size;        cc += -size;
1129  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1130        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1131  #endif  #endif
1132        }        }
# Line 1097  while (cc < ccend) Line 1147  while (cc < ccend)
1147    }    }
1148  }  }
1149    
1150  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1151  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive, BOOL* needs_control_head)
1152  {  {
1153  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1154  int length = 0;  int length = 0;
1155  BOOL possessive = FALSE;  int possessive = 0;
1156    BOOL stack_restore = FALSE;
1157  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1158  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1159    /* The last capture is a local variable even for recursions. */
1160    BOOL capture_last_found = FALSE;
1161    
1162    #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1163    SLJIT_ASSERT(common->control_head_ptr != 0);
1164    *needs_control_head = TRUE;
1165    #else
1166    *needs_control_head = FALSE;
1167    #endif
1168    
1169  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1170    {    {
1171    length = 3;    possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1172    possessive = TRUE;    /* This is correct regardless of common->capture_last_ptr. */
1173      capture_last_found = TRUE;
1174    }    }
1175    
1176  cc = next_opcode(common, cc);  cc = next_opcode(common, cc);
# Line 1119  while (cc < ccend) Line 1180  while (cc < ccend)
1180      {      {
1181      case OP_SET_SOM:      case OP_SET_SOM:
1182      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1183        stack_restore = TRUE;
1184      if (!setsom_found)      if (!setsom_found)
1185        {        {
1186        length += 2;        length += 2;
# Line 1128  while (cc < ccend) Line 1190  while (cc < ccend)
1190      break;      break;
1191    
1192      case OP_MARK:      case OP_MARK:
1193        case OP_PRUNE_ARG:
1194      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1195        stack_restore = TRUE;
1196      if (!setmark_found)      if (!setmark_found)
1197        {        {
1198        length += 2;        length += 2;
1199        setmark_found = TRUE;        setmark_found = TRUE;
1200        }        }
1201        if (common->control_head_ptr != 0)
1202          *needs_control_head = TRUE;
1203      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1204      break;      break;
1205    
1206      case OP_RECURSE:      case OP_RECURSE:
1207        stack_restore = TRUE;
1208      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1209        {        {
1210        length += 2;        length += 2;
# Line 1148  while (cc < ccend) Line 1215  while (cc < ccend)
1215        length += 2;        length += 2;
1216        setmark_found = TRUE;        setmark_found = TRUE;
1217        }        }
1218        if (common->capture_last_ptr != 0 && !capture_last_found)
1219          {
1220          length += 2;
1221          capture_last_found = TRUE;
1222          }
1223      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1224      break;      break;
1225    
# Line 1155  while (cc < ccend) Line 1227  while (cc < ccend)
1227      case OP_CBRAPOS:      case OP_CBRAPOS:
1228      case OP_SCBRA:      case OP_SCBRA:
1229      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1230        stack_restore = TRUE;
1231        if (common->capture_last_ptr != 0 && !capture_last_found)
1232          {
1233          length += 2;
1234          capture_last_found = TRUE;
1235          }
1236      length += 3;      length += 3;
1237      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1238      break;      break;
1239    
1240        case OP_PRUNE:
1241        case OP_SKIP:
1242        case OP_COMMIT:
1243        if (common->control_head_ptr != 0)
1244          *needs_control_head = TRUE;
1245        /* Fall through. */
1246    
1247      default:      default:
1248        stack_restore = TRUE;
1249        /* Fall through. */
1250    
1251        case OP_NOT_WORD_BOUNDARY:
1252        case OP_WORD_BOUNDARY:
1253        case OP_NOT_DIGIT:
1254        case OP_DIGIT:
1255        case OP_NOT_WHITESPACE:
1256        case OP_WHITESPACE:
1257        case OP_NOT_WORDCHAR:
1258        case OP_WORDCHAR:
1259        case OP_ANY:
1260        case OP_ALLANY:
1261        case OP_ANYBYTE:
1262        case OP_NOTPROP:
1263        case OP_PROP:
1264        case OP_ANYNL:
1265        case OP_NOT_HSPACE:
1266        case OP_HSPACE:
1267        case OP_NOT_VSPACE:
1268        case OP_VSPACE:
1269        case OP_EXTUNI:
1270        case OP_EODN:
1271        case OP_EOD:
1272        case OP_CIRC:
1273        case OP_CIRCM:
1274        case OP_DOLL:
1275        case OP_DOLLM:
1276        case OP_CHAR:
1277        case OP_CHARI:
1278        case OP_NOT:
1279        case OP_NOTI:
1280    
1281        case OP_EXACT:
1282        case OP_POSSTAR:
1283        case OP_POSPLUS:
1284        case OP_POSQUERY:
1285        case OP_POSUPTO:
1286    
1287        case OP_EXACTI:
1288        case OP_POSSTARI:
1289        case OP_POSPLUSI:
1290        case OP_POSQUERYI:
1291        case OP_POSUPTOI:
1292    
1293        case OP_NOTEXACT:
1294        case OP_NOTPOSSTAR:
1295        case OP_NOTPOSPLUS:
1296        case OP_NOTPOSQUERY:
1297        case OP_NOTPOSUPTO:
1298    
1299        case OP_NOTEXACTI:
1300        case OP_NOTPOSSTARI:
1301        case OP_NOTPOSPLUSI:
1302        case OP_NOTPOSQUERYI:
1303        case OP_NOTPOSUPTOI:
1304    
1305        case OP_TYPEEXACT:
1306        case OP_TYPEPOSSTAR:
1307        case OP_TYPEPOSPLUS:
1308        case OP_TYPEPOSQUERY:
1309        case OP_TYPEPOSUPTO:
1310    
1311        case OP_CLASS:
1312        case OP_NCLASS:
1313        case OP_XCLASS:
1314    
1315      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1316      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1317      break;      break;
1318      }      }
1319    
1320  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1321  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1322    return -1;    return stack_restore ? no_frame : no_stack;
1323    
1324  if (length > 0)  if (length > 0)
1325    return length + 1;    return length + 1;
1326  return -1;  return stack_restore ? no_frame : no_stack;
1327  }  }
1328    
1329  static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive)  static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive)
1330  {  {
1331  DEFINE_COMPILER;  DEFINE_COMPILER;
1332  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);
1333  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1334  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1335    /* The last capture is a local variable even for recursions. */
1336    BOOL capture_last_found = FALSE;
1337  int offset;  int offset;
1338    
1339  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1198  while (cc < ccend) Line 1352  while (cc < ccend)
1352      if (!setsom_found)      if (!setsom_found)
1353        {        {
1354        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1355        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1356        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1357        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1358        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1359        setsom_found = TRUE;        setsom_found = TRUE;
1360        }        }
1361      cc += 1;      cc += 1;
1362      break;      break;
1363    
1364      case OP_MARK:      case OP_MARK:
1365        case OP_PRUNE_ARG:
1366      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1367      if (!setmark_found)      if (!setmark_found)
1368        {        {
1369        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1370        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setmark);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1371        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1372        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1373        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1374        setmark_found = TRUE;        setmark_found = TRUE;
1375        }        }
1376      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 1225  while (cc < ccend) Line 1380  while (cc < ccend)
1380      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1381        {        {
1382        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1383        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1384        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1385        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1386        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1387        setsom_found = TRUE;        setsom_found = TRUE;
1388        }        }
1389      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1390        {        {
1391        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
1392        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setmark);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->mark_ptr);
1393        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1394        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1395        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1396        setmark_found = TRUE;        setmark_found = TRUE;
1397        }        }
1398        if (common->capture_last_ptr != 0 && !capture_last_found)
1399          {
1400          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1401          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1402          stackpos += (int)sizeof(sljit_sw);
1403          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1404          stackpos += (int)sizeof(sljit_sw);
1405          capture_last_found = TRUE;
1406          }
1407      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1408      break;      break;
1409    
# Line 1247  while (cc < ccend) Line 1411  while (cc < ccend)
1411      case OP_CBRAPOS:      case OP_CBRAPOS:
1412      case OP_SCBRA:      case OP_SCBRA:
1413      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1414        if (common->capture_last_ptr != 0 && !capture_last_found)
1415          {
1416          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1417          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1418          stackpos += (int)sizeof(sljit_sw);
1419          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1420          stackpos += (int)sizeof(sljit_sw);
1421          capture_last_found = TRUE;
1422          }
1423      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1424      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1425      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1426      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1427      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));
1428      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1429      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1430      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1431      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1432    
1433      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1434      break;      break;
# Line 1266  while (cc < ccend) Line 1439  while (cc < ccend)
1439      break;      break;
1440      }      }
1441    
1442  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1443  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1444  }  }
1445    
1446  static SLJIT_INLINE int get_private_data_length_for_copy(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static SLJIT_INLINE int get_private_data_copy_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL needs_control_head)
1447  {  {
1448  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1449  int size;  int size;
1450  pcre_uchar *alternative;  pcre_uchar *alternative;
1451  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1320  while (cc < ccend) Line 1493  while (cc < ccend)
1493      if (PRIVATE_DATA(cc))      if (PRIVATE_DATA(cc))
1494        private_data_length++;        private_data_length++;
1495      cc += 2;      cc += 2;
1496  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1497      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1498  #endif  #endif
1499      break;      break;
# Line 1329  while (cc < ccend) Line 1502  while (cc < ccend)
1502      if (PRIVATE_DATA(cc))      if (PRIVATE_DATA(cc))
1503        private_data_length += 2;        private_data_length += 2;
1504      cc += 2;      cc += 2;
1505  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1506      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1507  #endif  #endif
1508      break;      break;
# Line 1338  while (cc < ccend) Line 1511  while (cc < ccend)
1511      if (PRIVATE_DATA(cc))      if (PRIVATE_DATA(cc))
1512        private_data_length += 2;        private_data_length += 2;
1513      cc += 2 + IMM2_SIZE;      cc += 2 + IMM2_SIZE;
1514  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1515      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1516  #endif  #endif
1517      break;      break;
# Line 1385  return private_data_length; Line 1558  return private_data_length;
1558  }  }
1559    
1560  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,
1561    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1562  {  {
1563  DEFINE_COMPILER;  DEFINE_COMPILER;
1564  int srcw[2];  int srcw[2];
# Line 1406  stacktop = STACK(stacktop - 1); Line 1579  stacktop = STACK(stacktop - 1);
1579    
1580  if (!save)  if (!save)
1581    {    {
1582    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1583    if (stackptr < stacktop)    if (stackptr < stacktop)
1584      {      {
1585      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1586      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1587      tmp1empty = FALSE;      tmp1empty = FALSE;
1588      }      }
1589    if (stackptr < stacktop)    if (stackptr < stacktop)
1590      {      {
1591      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1592      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1593      tmp2empty = FALSE;      tmp2empty = FALSE;
1594      }      }
1595    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1596    }    }
1597    
1598  while (status != end)  do
1599    {    {
1600    count = 0;    count = 0;
1601    switch(status)    switch(status)
1602      {      {
1603      case start:      case start:
1604      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1605      count = 1;      count = 1;
1606      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1607        if (needs_control_head)
1608          {
1609          SLJIT_ASSERT(common->control_head_ptr != 0);
1610          count = 2;
1611          srcw[1] = common->control_head_ptr;
1612          }
1613      status = loop;      status = loop;
1614      break;      break;
1615    
# Line 1497  while (status != end) Line 1676  while (status != end)
1676          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1677          }          }
1678        cc += 2;        cc += 2;
1679  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1680        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1681  #endif  #endif
1682        break;        break;
# Line 1507  while (status != end) Line 1686  while (status != end)
1686          {          {
1687          count = 2;          count = 2;
1688          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1689          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1690          }          }
1691        cc += 2;        cc += 2;
1692  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1693        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1694  #endif  #endif
1695        break;        break;
# Line 1520  while (status != end) Line 1699  while (status != end)
1699          {          {
1700          count = 2;          count = 2;
1701          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1702          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1703          }          }
1704        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1705  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1706        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1707  #endif  #endif
1708        break;        break;
# Line 1542  while (status != end) Line 1721  while (status != end)
1721          {          {
1722          count = 2;          count = 2;
1723          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1724          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1725          }          }
1726        cc += 1;        cc += 1;
1727        break;        break;
# Line 1552  while (status != end) Line 1731  while (status != end)
1731          {          {
1732          count = 2;          count = 2;
1733          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1734          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1735          }          }
1736        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1737        break;        break;
# Line 1576  while (status != end) Line 1755  while (status != end)
1755            case 2:            case 2:
1756            count = 2;            count = 2;
1757            srcw[0] = PRIVATE_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1758            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1759            break;            break;
1760    
1761            default:            default:
# Line 1608  while (status != end) Line 1787  while (status != end)
1787          if (!tmp1empty)          if (!tmp1empty)
1788            {            {
1789            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1790            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1791            }            }
1792          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1793          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1619  while (status != end) Line 1798  while (status != end)
1798          if (!tmp2empty)          if (!tmp2empty)
1799            {            {
1800            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1801            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1802            }            }
1803          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1804          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1636  while (status != end) Line 1815  while (status != end)
1815          if (!tmp1empty)          if (!tmp1empty)
1816            {            {
1817            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1818            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1819            }            }
1820          tmp1next = FALSE;          tmp1next = FALSE;
1821          }          }
# Line 1648  while (status != end) Line 1827  while (status != end)
1827          if (!tmp2empty)          if (!tmp2empty)
1828            {            {
1829            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1830            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1831            }            }
1832          tmp1next = TRUE;          tmp1next = TRUE;
1833          }          }
1834        }        }
1835      }      }
1836    }    }
1837    while (status != end);
1838    
1839  if (save)  if (save)
1840    {    {
# Line 1663  if (save) Line 1843  if (save)
1843      if (!tmp1empty)      if (!tmp1empty)
1844        {        {
1845        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1846        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1847        }        }
1848      if (!tmp2empty)      if (!tmp2empty)
1849        {        {
1850        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1851        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1852        }        }
1853      }      }
1854    else    else
# Line 1676  if (save) Line 1856  if (save)
1856      if (!tmp2empty)      if (!tmp2empty)
1857        {        {
1858        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1859        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1860        }        }
1861      if (!tmp1empty)      if (!tmp1empty)
1862        {        {
1863        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1864        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1865        }        }
1866      }      }
1867    }    }
# Line 1706  while (list) Line 1886  while (list)
1886    {    {
1887    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1888    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
1889    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1890    list = list->next;    list = list->next;
1891    }    }
1892  }  }
# Line 1722  if (list_item) Line 1902  if (list_item)
1902    }    }
1903  }  }
1904    
1905  static void add_stub(compiler_common *common, enum stub_types type, int data, struct sljit_jump *start)  static void add_stub(compiler_common *common, struct sljit_jump *start)
1906  {  {
1907  DEFINE_COMPILER;  DEFINE_COMPILER;
1908  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1909    
1910  if (list_item)  if (list_item)
1911    {    {
   list_item->type = type;  
   list_item->data = data;  
1912    list_item->start = start;    list_item->start = start;
1913    list_item->quit = LABEL();    list_item->quit = LABEL();
1914    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1746  stub_list* list_item = common->stubs; Line 1924  stub_list* list_item = common->stubs;
1924  while (list_item)  while (list_item)
1925    {    {
1926    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
1927    switch(list_item->type)    add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));
     {  
     case stack_alloc:  
     add_jump(compiler, &common->stackalloc, JUMP(SLJIT_FAST_CALL));  
     break;  
     }  
1928    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
1929    list_item = list_item->next;    list_item = list_item->next;
1930    }    }
# Line 1771  static SLJIT_INLINE void allocate_stack( Line 1944  static SLJIT_INLINE void allocate_stack(
1944  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
1945  DEFINE_COMPILER;  DEFINE_COMPILER;
1946    
1947  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w));  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
1948  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
1949  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
1950  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1779  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 1952  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
1952  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
1953  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
1954  #endif  #endif
1955  add_stub(common, stack_alloc, 0, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));  add_stub(common, CMP(SLJIT_C_GREATER, STACK_TOP, 0, STACK_LIMIT, 0));
1956  }  }
1957    
1958  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
1959  {  {
1960  DEFINE_COMPILER;  DEFINE_COMPILER;
1961  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w));  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
1962  }  }
1963    
1964  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1793  static SLJIT_INLINE void reset_ovector(c Line 1966  static SLJIT_INLINE void reset_ovector(c
1966  DEFINE_COMPILER;  DEFINE_COMPILER;
1967  struct sljit_label *loop;  struct sljit_label *loop;
1968  int i;  int i;
1969    
1970  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
1971    SLJIT_ASSERT(length > 1);
1972  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
1973  OP2(SLJIT_SUB, SLJIT_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));
1974  if (length < 8)  if (length < 8)
1975    {    {
1976    for (i = 0; i < length; i++)    for (i = 1; i < length; i++)
1977      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_TEMPORARY_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
1978    }    }
1979  else  else
1980    {    {
1981    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
1982    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
1983    loop = LABEL();    loop = LABEL();
1984    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
1985    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);
1986    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
1987    }    }
1988  }  }
1989    
1990    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
1991    {
1992    DEFINE_COMPILER;
1993    struct sljit_label *loop;
1994    int i;
1995    
1996    SLJIT_ASSERT(length > 1);
1997    /* OVECTOR(1) contains the "string begin - 1" constant. */
1998    if (length > 2)
1999      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2000    if (length < 8)
2001      {
2002      for (i = 2; i < length; i++)
2003        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
2004      }
2005    else
2006      {
2007      GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2008      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2009      loop = LABEL();
2010      OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2011      OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
2012      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2013      }
2014    
2015    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2016    if (common->mark_ptr != 0)
2017      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2018    SLJIT_ASSERT(common->control_head_ptr != 0);
2019    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2020    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2021    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2022    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2023    }
2024    
2025    static sljit_sw SLJIT_CALL do_check_control_chain(sljit_sw *current)
2026    {
2027    sljit_sw return_value = 0;
2028    
2029    SLJIT_ASSERT(current != NULL);
2030    do
2031      {
2032      switch (current[-2])
2033        {
2034        case type_commit:
2035        /* Commit overwrites all. */
2036        return -1;
2037    
2038        case type_prune:
2039        break;
2040    
2041        case type_skip:
2042        /* Overwrites prune, but not other skips. */
2043        if (return_value == 0)
2044          return_value = current[-3];
2045        break;
2046    
2047        default:
2048        SLJIT_ASSERT_STOP();
2049        break;
2050        }
2051      current = (sljit_sw*)current[-1];
2052      }
2053    while (current != NULL);
2054    return return_value;
2055    }
2056    
2057  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2058  {  {
2059  DEFINE_COMPILER;  DEFINE_COMPILER;
2060  struct sljit_label *loop;  struct sljit_label *loop;
2061  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2062    
2063  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2064  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  OP1(SLJIT_MOV, SLJIT_SAVED_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2065  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);
2066    
2067  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2068  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2069    OP1(SLJIT_MOV, SLJIT_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);
2070  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));
2071  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2072    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);
2073  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));
2074  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));
2075  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2076  /* Unlikely, but possible */  /* Unlikely, but possible */
2077  earlyexit = CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 0);  early_quit = CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, 0);
2078  loop = LABEL();  loop = LABEL();
2079  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_TEMPORARY_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0, SLJIT_SCRATCH_REG1, 0);
2080  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_w));  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));
2081  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2082  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2083  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);
2084  #endif  #endif
2085  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);
2086  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);
2087  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2088  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2089    
2090  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2091  if (topbracket > 1)  if (topbracket > 1)
2092    {    {
2093    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_w));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));
2094    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2095    
2096    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2097    loop = LABEL();    loop = LABEL();
2098    OP1(SLJIT_MOVU, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), -(2 * (sljit_w)sizeof(sljit_w)));    OP1(SLJIT_MOVU, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), -(2 * (sljit_sw)sizeof(sljit_sw)));
2099    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);
2100    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);
2101    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2102    }    }
2103  else  else
2104    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1865  else Line 2107  else
2107  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)  static SLJIT_INLINE void return_with_partial_match(compiler_common *common, struct sljit_label *quit)
2108  {  {
2109  DEFINE_COMPILER;  DEFINE_COMPILER;
2110    struct sljit_jump *jump;
2111    
2112  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);  SLJIT_COMPILE_ASSERT(STR_END == SLJIT_SAVED_REG2, str_end_must_be_saved_reg2);
2113  SLJIT_ASSERT(common->start_used_ptr != 0 && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));  SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0
2114      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2115    
2116  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2117  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2118  OP1(SLJIT_MOV_SI, SLJIT_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));
2119  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);
2120    
2121  /* Store match begin and end. */  /* Store match begin and end. */
2122  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));
2123  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));
2124  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);  
2125    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2126    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + (int)sizeof(sljit_sw)), SLJIT_SAVED_REG1, 0);
2127    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2128    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2129    #endif
2130    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2131    JUMPHERE(jump);
2132    
2133    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_used_ptr : common->hit_start);
2134  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SAVED_REG2, 0, STR_END, 0, SLJIT_SAVED_REG1, 0);
2135  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2136  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);
2137  #endif  #endif
2138  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);
2139    
2140  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);
2141  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2142  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);
2143  #endif  #endif
2144  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);
2145    
2146  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2147  }  }
# Line 2053  else if (common->mode == JIT_PARTIAL_SOF Line 2306  else if (common->mode == JIT_PARTIAL_SOF
2306    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);    jump = CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, SLJIT_IMM, -1);
2307    
2308  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2309    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2310  else  else
2311    {    {
2312    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2066  if (jump != NULL) Line 2319  if (jump != NULL)
2319    JUMPHERE(jump);    JUMPHERE(jump);
2320  }  }
2321    
2322  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2323  {  {
2324  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2325  DEFINE_COMPILER;  DEFINE_COMPILER;
2326  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2327    
2328  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2329    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2330      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2331      return;
2332      }
2333    
2334  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2335  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2336    {    {
2337    nohit = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2338    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2339    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2340    }    }
2341  else  else
2342    {    {
2343    return_value = CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0);    add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2344    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2345      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2346    else    else
2347      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2348    }    }
2349  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2350  }  }
2351    
2352  static void detect_partial_match(compiler_common *common, jump_list **backtracks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
# Line 2113  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR Line 2365  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2365  add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));  add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_used_ptr, STR_PTR, 0));
2366  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2367    {    {
2368    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->hit_start, SLJIT_IMM, 0);
2369    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2370    }    }
2371  else  else
# Line 2204  if (common->utf) Line 2456  if (common->utf)
2456    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2457    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2458    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);
2459    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2460    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2461    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2462  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
# Line 2254  if (common->utf) Line 2506  if (common->utf)
2506    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2507    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2508    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);
2509    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2510    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2511    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2512    return;    return;
# Line 2277  if (nltype == NLTYPE_ANY) Line 2529  if (nltype == NLTYPE_ANY)
2529  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2530    {    {
2531    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);
2532    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2533    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);
2534    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);
2535    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));
2536    }    }
2537  else  else
# Line 2379  sljit_emit_fast_return(compiler, RETURN_ Line 2631  sljit_emit_fast_return(compiler, RETURN_
2631  JUMPHERE(jump);  JUMPHERE(jump);
2632    
2633  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2634  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(utf8_table4) - 0xc0);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2635  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2636  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2637  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
# Line 2432  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 2684  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2684    
2685  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2686  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2687  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(ucd_stage1));  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(ucd_stage1));
2688  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2689  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2690  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2691  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2692  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2693  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));
2694  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2695  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2696  }  }
# Line 2452  struct sljit_label *newlinelabel = NULL; Line 2704  struct sljit_label *newlinelabel = NULL;
2704  struct sljit_jump *start;  struct sljit_jump *start;
2705  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2706  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2707  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2708  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2709  #endif  #endif
2710  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 2507  if (newlinecheck) Line 2759  if (newlinecheck)
2759    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2760    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2761    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);
2762    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2763  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2764    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2765  #endif  #endif
# Line 2535  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S Line 2787  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S
2787  if (common->utf)  if (common->utf)
2788    {    {
2789    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2790    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2791    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2792    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2793    }    }
# Line 2545  if (common->utf) Line 2797  if (common->utf)
2797    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2798    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2799    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);
2800    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2801    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2802    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2803    JUMPHERE(singlechar);    JUMPHERE(singlechar);
# Line 2571  DEFINE_COMPILER; Line 2823  DEFINE_COMPILER;
2823  struct sljit_label *start;  struct sljit_label *start;
2824  struct sljit_jump *quit;  struct sljit_jump *quit;
2825  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uint32 chars[MAX_N_CHARS * 2];
2826  pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  pcre_uchar *cc = common->start + 1 + LINK_SIZE;
2827  int location = 0;  int location = 0;
2828  pcre_int32 len, c, bit, caseless;  pcre_int32 len, c, bit, caseless;
2829  int must_stop;  int must_stop;
# Line 2643  while (TRUE) Line 2895  while (TRUE)
2895        break;        break;
2896    
2897    len = 1;    len = 1;
2898  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
2899    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
2900  #endif  #endif
2901    
# Line 2694  if (firstline) Line 2946  if (firstline)
2946    {    {
2947    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
2948    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
2949    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, (location >> 1) - 1);    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2950    }    }
2951  else  else
2952    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, (location >> 1) - 1);    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2953    
2954  start = LABEL();  start = LABEL();
2955  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
# Line 2726  JUMPHERE(quit); Line 2978  JUMPHERE(quit);
2978  if (firstline)  if (firstline)
2979    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
2980  else  else
2981    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, (location >> 1) - 1);    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS((location >> 1) - 1));
2982  return TRUE;  return TRUE;
2983  }  }
2984    
# Line 2773  else Line 3025  else
3025    else    else
3026      {      {
3027      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);
3028      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3029      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);
3030      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);
3031      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3032      }      }
3033    }    }
# Line 2817  if (common->nltype == NLTYPE_FIXED && co Line 3069  if (common->nltype == NLTYPE_FIXED && co
3069    
3070    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3071    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);
3072    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3073  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3074    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3075  #endif  #endif
# Line 2860  if (common->nltype == NLTYPE_ANY || comm Line 3112  if (common->nltype == NLTYPE_ANY || comm
3112    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3113    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3114    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);
3115    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3116  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3117    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3118  #endif  #endif
# Line 2875  if (firstline) Line 3127  if (firstline)
3127    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3128  }  }
3129    
3130    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3131    
3132  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)
3133  {  {
3134  DEFINE_COMPILER;  DEFINE_COMPILER;
3135  struct sljit_label *start;  struct sljit_label *start;
3136  struct sljit_jump *quit;  struct sljit_jump *quit;
3137  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3138    jump_list *matches = NULL;
3139    pcre_uint8 inverted_start_bits[32];
3140    int i;
3141  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3142  struct sljit_jump *jump;  struct sljit_jump *jump;
3143  #endif  #endif
3144    
3145    for (i = 0; i < 32; ++i)
3146      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3147    
3148  if (firstline)  if (firstline)
3149    {    {
3150    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
# Line 2899  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 3159  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3159  if (common->utf)  if (common->utf)
3160    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3161  #endif  #endif
3162    
3163    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3164      {
3165  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3166  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3167  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3168  JUMPHERE(jump);    JUMPHERE(jump);
3169  #endif  #endif
3170  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3171  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3172  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3173  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3174  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
3175  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3176      }
3177    
3178  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3179  if (common->utf)  if (common->utf)
# Line 2921  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S Line 3185  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S
3185  if (common->utf)  if (common->utf)
3186    {    {
3187    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3188    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
3189    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3190    }    }
3191  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
# Line 2930  if (common->utf) Line 3194  if (common->utf)
3194    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3195    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3196    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);
3197    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3198    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3199    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3200    }    }
3201  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE[8|16] */
3202  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3203  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3204  JUMPHERE(found);  if (found != NULL)
3205      JUMPHERE(found);
3206    if (matches != NULL)
3207      set_jumps(matches, LABEL());
3208  JUMPHERE(quit);  JUMPHERE(quit);
3209    
3210  if (firstline)  if (firstline)
# Line 2953  struct sljit_jump *alreadyfound; Line 3220  struct sljit_jump *alreadyfound;
3220  struct sljit_jump *found;  struct sljit_jump *found;
3221  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3222  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3223  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3224    
3225  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3226  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
# Line 3020  GET_LOCAL_BASE(TMP3, 0, 0); Line 3287  GET_LOCAL_BASE(TMP3, 0, 0);
3287  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3288  mainloop = LABEL();  mainloop = LABEL();
3289  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3290  jump = CMP(SLJIT_C_SIG_LESS_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0);
3291    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3292    
3293  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3294  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3295  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_w), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
3296  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw));
3297  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3298    
3299  JUMPHERE(jump);  JUMPHERE(jump);
3300  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3301  /* End of dropping frames. */  /* End of dropping frames. */
3302  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3303    
3304  JUMPHERE(jump);  JUMPHERE(jump);
3305  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3306  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3307  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3308  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  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_w));  
   OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);  
   JUMPTO(SLJIT_JUMP, mainloop);  
   
   JUMPHERE(jump);  
   }  
   
 /* Unknown command. */  
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  
3309  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3310  }  }
3311    
# Line 3061  static void check_wordboundary(compiler_ Line 3313  static void check_wordboundary(compiler_
3313  {  {
3314  DEFINE_COMPILER;  DEFINE_COMPILER;
3315  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3316    jump_list *skipread_list = NULL;
3317  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3318  struct sljit_jump *jump;  struct sljit_jump *jump;
3319  #endif  #endif
# Line 3086  if (common->use_ucp) Line 3339  if (common->use_ucp)
3339    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3340    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3341    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);
3342    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3343    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);
3344    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);
3345    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3346    JUMPHERE(jump);    JUMPHERE(jump);
3347    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3348    }    }
# Line 3118  else Line 3371  else
3371  JUMPHERE(skipread);  JUMPHERE(skipread);
3372    
3373  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3374  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3375  peek_char(common);  peek_char(common);
3376    
3377  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 3130  if (common->use_ucp) Line 3383  if (common->use_ucp)
3383    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3384    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3385    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);
3386    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3387    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);
3388    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);
3389    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3390    JUMPHERE(jump);    JUMPHERE(jump);
3391    }    }
3392  else  else
# Line 3159  else Line 3412  else
3412      JUMPHERE(jump);      JUMPHERE(jump);
3413  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3414    }    }
3415  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3416    
3417  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);  OP2(SLJIT_XOR | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
3418  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
# Line 3313  sljit_emit_fast_enter(compiler, RETURN_A Line 3566  sljit_emit_fast_enter(compiler, RETURN_A
3566    
3567  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3568  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);
3569  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3570  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);
3571  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3572  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3573  if (common->utf)  if (common->utf)
3574    {    {
3575  #endif  #endif
3576    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3577    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3578    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);
3579  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3580    }    }
3581  #endif  #endif
3582  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3583  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);
3584  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3585  }  }
3586    
# Line 3339  DEFINE_COMPILER; Line 3592  DEFINE_COMPILER;
3592  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3593    
3594  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);
3595  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3596  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);
3597  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3598  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);
3599  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3600  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3601  if (common->utf)  if (common->utf)
3602    {    {
3603  #endif  #endif
3604    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3605    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);
3606    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3607    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);
3608    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3609    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3610    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);
3611    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3612    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);
3613    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3614    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);
3615    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3616    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);
3617  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3618    }    }
3619  #endif  #endif
3620  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3621  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);
3622    
3623  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3624  }  }
# Line 3379  sljit_emit_fast_enter(compiler, RETURN_A Line 3632  sljit_emit_fast_enter(compiler, RETURN_A
3632    
3633  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3634  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);
3635  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3636  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);
3637  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3638  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3639  if (common->utf)  if (common->utf)
3640    {    {
3641  #endif  #endif
3642    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);
3643    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3644    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);
3645  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3646    }    }
3647  #endif  #endif
3648  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3649  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);
3650    
3651  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3652  }  }
# Line 3479  sljit_emit_fast_return(compiler, RETURN_ Line 3732  sljit_emit_fast_return(compiler, RETURN_
3732    
3733  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3734    
3735  static const pcre_uchar *SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1)  static const pcre_uchar * SLJIT_CALL do_utf_caselesscmp(pcre_uchar *src1, jit_arguments *args, pcre_uchar *end1)
3736  {  {
3737  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3738  pcre_uint32 c1, c2;  pcre_uint32 c1, c2;
# Line 3529  if (caseless && char_has_othercase(commo Line 3782  if (caseless && char_has_othercase(commo
3782    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
3783    othercasebit &= 0xff;    othercasebit &= 0xff;
3784  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3785      /* Note that this code only handles characters in the BMP. If there
3786      ever are characters outside the BMP whose othercase differs in only one
3787      bit from itself (there currently are none), this code will need to be
3788      revised for COMPILE_PCRE32. */
3789    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
3790    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
3791      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
# Line 3563  if (context->sourcereg == -1) Line 3820  if (context->sourcereg == -1)
3820    
3821  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3822  utflength = 1;  utflength = 1;
 #ifndef COMPILE_PCRE32  
3823  if (common->utf && HAS_EXTRALEN(*cc))  if (common->utf && HAS_EXTRALEN(*cc))
3824    utflength += GET_EXTRALEN(*cc);    utflength += GET_EXTRALEN(*cc);
 #endif  
3825    
3826  do  do
3827    {    {
3828  #endif  #endif
3829    
3830    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3831  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3832    
3833    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3834    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3590  do Line 3845  do
3845    
3846  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
3847    if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1))    if (context->ucharptr >= 4 || context->length == 0 || (context->ucharptr == 2 && context->length == 1))
3848  #elif defined COMPILE_PCRE16  #else
3849    if (context->ucharptr >= 2 || context->length == 0)    if (context->ucharptr >= 2 || context->length == 0)
 #elif defined COMPILE_PCRE32  
   if (1 /* context->ucharptr >= 1 || context->length == 0 */)  
3850  #endif  #endif
3851      {      {
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
3852      if (context->length >= 4)      if (context->length >= 4)
3853        OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_SI, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
 #if defined COMPILE_PCRE8  
3854      else if (context->length >= 2)      else if (context->length >= 2)
3855        OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3856    #if defined COMPILE_PCRE8
3857      else if (context->length >= 1)      else if (context->length >= 1)
3858        OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);        OP1(SLJIT_MOV_UB, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3859  #elif defined COMPILE_PCRE16  #endif /* COMPILE_PCRE8 */
     else if (context->length >= 2)  
       OP1(SLJIT_MOV_UH, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif /* COMPILE_PCRE[8|16] */  
 #elif defined COMPILE_PCRE32  
     OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);  
 #endif /* COMPILE_PCRE[8|16|32] */  
3860      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3861    
3862      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3621  do Line 3867  do
3867        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asint | context->oc.asint));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asint | context->oc.asint));
3868        break;        break;
3869    
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
3870        case 2 / sizeof(pcre_uchar):        case 2 / sizeof(pcre_uchar):
3871        if (context->oc.asushort != 0)        if (context->oc.asushort != 0)
3872          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asushort);          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asushort);
# Line 3636  do Line 3881  do
3881        break;        break;
3882  #endif  #endif
3883    
 #endif /* COMPILE_PCRE[8|16] */  
   
3884        default:        default:
3885        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
3886        break;        break;
# Line 3647  do Line 3890  do
3890    
3891  #else  #else
3892    
3893    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3894    if (context->length > 0)    if (context->length >= 1)
3895      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3896    
3897    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
# Line 3731  if ((*cc++ & XCL_MAP) != 0) Line 3974  if ((*cc++ & XCL_MAP) != 0)
3974      {      {
3975      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3976      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3977      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
3978      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3979      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);
3980      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
# Line 3759  while (*cc != XCL_END) Line 4002  while (*cc != XCL_END)
4002    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
4003      {      {
4004      cc += 2;      cc += 2;
4005  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
4006      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
4007  #endif  #endif
4008  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 3769  while (*cc != XCL_END) Line 4012  while (*cc != XCL_END)
4012    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
4013      {      {
4014      cc += 2;      cc += 2;
4015  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
4016      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
4017  #endif  #endif
4018      cc++;      cc++;
4019  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
4020      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
4021  #endif  #endif
4022  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 3809  while (*cc != XCL_END) Line 4052  while (*cc != XCL_END)
4052        break;        break;
4053    
4054        case PT_CLIST:        case PT_CLIST:
4055          case PT_UCNC:
4056        needschar = TRUE;        needschar = TRUE;
4057        break;        break;
4058    
# Line 3848  if (needstype || needsscript) Line 4092  if (needstype || needsscript)
4092      {      {
4093      if (scriptreg == TMP1)      if (scriptreg == TMP1)
4094        {        {
4095        OP1(SLJIT_MOV, scriptreg, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));        OP1(SLJIT_MOV, scriptreg, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));
4096        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
4097        }        }
4098      else      else
4099        {        {
4100        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
4101        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, script));
4102        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
4103        }        }
4104      }      }
# Line 3890  while (*cc != XCL_END) Line 4134  while (*cc != XCL_END)
4134      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4135        {        {
4136        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);
4137        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);
4138        numberofcmps++;        numberofcmps++;
4139        }        }
4140      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4141        {        {
4142        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);
4143        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);
4144        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4145        numberofcmps = 0;        numberofcmps = 0;
4146        }        }
# Line 3929  while (*cc != XCL_END) Line 4173  while (*cc != XCL_END)
4173      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4174        {        {
4175        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);
4176        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);
4177        numberofcmps++;        numberofcmps++;
4178        }        }
4179      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4180        {        {
4181        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);
4182        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);
4183        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4184        numberofcmps = 0;        numberofcmps = 0;
4185        }        }
# Line 3966  while (*cc != XCL_END) Line 4210  while (*cc != XCL_END)
4210    
4211        case PT_LAMP:        case PT_LAMP:
4212        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);
4213        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4214        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);
4215        COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4216        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);
4217        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);
4218        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4219        break;        break;
4220    
# Line 3997  while (*cc != XCL_END) Line 4241  while (*cc != XCL_END)
4241          }          }
4242        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4243        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);
4244        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4245        if (*cc == PT_SPACE)        if (*cc == PT_SPACE)
4246          JUMPHERE(jump);          JUMPHERE(jump);
4247    
4248        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4249        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);
4250        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);
4251        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4252        break;        break;
4253    
4254        case PT_WORD:        case PT_WORD:
4255        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE - charoffset);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_UNDERSCORE - charoffset);
4256        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4257        /* ... fall through */        /* Fall through. */
4258    
4259        case PT_ALNUM:        case PT_ALNUM:
4260        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
4261        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);
4262        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);
4263        SET_TYPE_OFFSET(ucp_Nd);        SET_TYPE_OFFSET(ucp_Nd);
4264        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);
4265        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);
4266        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4267        break;        break;
4268    
# Line 4037  while (*cc != XCL_END) Line 4281  while (*cc != XCL_END)
4281            OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);            OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[1] ^ other_cases[0]);
4282          else          else
4283            {            {
4284            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_w)charoffset);            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4285            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]);
4286            }            }
4287          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]);
4288          COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4289          other_cases += 2;          other_cases += 2;
4290          }          }
4291        else if (is_powerof2(other_cases[2] ^ other_cases[1]))        else if (is_powerof2(other_cases[2] ^ other_cases[1]))
# Line 4050  while (*cc != XCL_END) Line 4294  while (*cc != XCL_END)
4294            OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[2] ^ other_cases[1]);            OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, other_cases[2] ^ other_cases[1]);
4295          else          else
4296            {            {
4297            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_w)charoffset);            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4298            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]);
4299            }            }
4300          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]);
4301          COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4302    
4303          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);
4304          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);
4305    
4306          other_cases += 3;          other_cases += 3;
4307          }          }
4308        else        else
4309          {          {
4310          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);
4311          COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4312          }          }
4313    
4314        while (*other_cases != NOTACHAR)        while (*other_cases != NOTACHAR)
4315          {          {
4316          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);
4317          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);
4318          }          }
4319        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4320        break;        break;
4321    
4322          case PT_UCNC:
4323          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);
4324          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4325          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);
4326          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4327          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);
4328          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4329    
4330          SET_CHAR_OFFSET(0xa0);
4331          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);
4332          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4333          SET_CHAR_OFFSET(0);
4334          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
4335          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4336          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4337          break;
4338        }        }
4339      cc += 2;      cc += 2;
4340      }      }
# Line 4099  int length; Line 4360  int length;
4360  unsigned int c, oc, bit;  unsigned int c, oc, bit;
4361  compare_context context;  compare_context context;
4362  struct sljit_jump *jump[4];  struct sljit_jump *jump[4];
4363    jump_list *end_list;
4364  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4365  struct sljit_label *label;  struct sljit_label *label;
4366  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4167  switch(type) Line 4429  switch(type)
4429    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4430      {      {
4431      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);      jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);
4432        end_list = NULL;
4433      if (common->mode != JIT_PARTIAL_HARD_COMPILE)      if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4434        jump[1] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);        add_jump(compiler, &end_list, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
4435      else      else
4436        jump[1] = check_str_end(common);        check_str_end(common, &end_list);
4437    
4438      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4439      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff));      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff));
4440      if (jump[1] != NULL)      set_jumps(end_list, LABEL());
       JUMPHERE(jump[1]);  
4441      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4442      }      }
4443    else    else
# Line 4192  switch(type) Line 4454  switch(type)
4454  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16
4455  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
4456      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4457      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
4458      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4459  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
4460      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
4461      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
4462      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);
4463      COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4464      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4465      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4466  #endif  #endif
# Line 4234  switch(type) Line 4496  switch(type)
4496    read_char(common);    read_char(common);
4497    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
4498    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
4499      end_list = NULL;
4500    if (common->mode != JIT_PARTIAL_HARD_COMPILE)    if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4501      jump[1] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);      add_jump(compiler, &end_list, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
4502    else    else
4503      jump[1] = check_str_end(common);      check_str_end(common, &end_list);
4504    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4505    jump[2] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL);    jump[1] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL);
4506    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
4507    jump[3] = JUMP(SLJIT_JUMP);    jump[2] = JUMP(SLJIT_JUMP);
4508    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4509    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);
4510      set_jumps(end_list, LABEL());
4511    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
4512    JUMPHERE(jump[2]);    JUMPHERE(jump[2]);
   JUMPHERE(jump[3]);  
4513    return cc;    return cc;
4514    
4515    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
# Line 4270  switch(type) Line 4533  switch(type)
4533    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4534    read_char(common);    read_char(common);
4535    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4536    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));
4537    /* Optimize register allocation: use a real register. */    /* Optimize register allocation: use a real register. */
4538    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
4539    OP1(SLJIT_MOV_UB, STACK_TOP, 0, SLJIT_MEM2(TMP1, TMP2), 3);    OP1(SLJIT_MOV_UB, STACK_TOP, 0, SLJIT_MEM2(TMP1, TMP2), 3);
# Line 4280  switch(type) Line 4543  switch(type)
4543    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
4544    read_char(common);    read_char(common);
4545    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4546    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, gbprop));
4547    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4548    
4549    OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);    OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);
4550    OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STACK_TOP), (sljit_w)PRIV(ucp_gbtable));    OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STACK_TOP), (sljit_sw)PRIV(ucp_gbtable));
4551    OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);    OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);
4552    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4553    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);
# Line 4317  switch(type) Line 4580  switch(type)
4580        {        {
4581        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);
4582        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);
4583        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS);
4584        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);
4585        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);
4586        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));
4587        check_partial(common, TRUE);        check_partial(common, TRUE);
4588        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
# Line 4467  switch(type) Line 4730  switch(type)
4730    case OP_CHAR:    case OP_CHAR:
4731    case OP_CHARI:    case OP_CHARI:
4732    length = 1;    length = 1;
4733  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
4734    if (common->utf && HAS_EXTRALEN(*cc)) length += GET_EXTRALEN(*cc);    if (common->utf && HAS_EXTRALEN(*cc)) length += GET_EXTRALEN(*cc);
4735  #endif  #endif
4736    if (common->mode == JIT_COMPILE && (type == OP_CHAR || !char_has_othercase(common, cc) || char_get_othercase_bit(common, cc) != 0))    if (common->mode == JIT_COMPILE && (type == OP_CHAR || !char_has_othercase(common, cc) || char_get_othercase_bit(common, cc) != 0))
# Line 4506  switch(type) Line 4769  switch(type)
4769      return cc + length;      return cc + length;
4770      }      }
4771    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);
4772    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4773    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);
4774    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);
4775    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
4776    return cc + length;    return cc + length;
4777    
# Line 4535  switch(type) Line 4798  switch(type)
4798        /* Skip the variable-length character. */        /* Skip the variable-length character. */
4799        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));
4800        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4801        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
4802        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4803        JUMPHERE(jump[0]);        JUMPHERE(jump[0]);
4804        return cc + 1;        return cc + 1;
# Line 4598  switch(type) Line 4861  switch(type)
4861  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4862    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4863    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4864    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4865    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4866    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);
4867    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 4662  do Line 4925  do
4925    if (*cc == OP_CHAR)    if (*cc == OP_CHAR)
4926      {      {
4927      size = 1;      size = 1;
4928  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
4929      if (common->utf && HAS_EXTRALEN(cc[1]))      if (common->utf && HAS_EXTRALEN(cc[1]))
4930        size += GET_EXTRALEN(cc[1]);        size += GET_EXTRALEN(cc[1]);
4931  #endif  #endif
# Line 4675  do Line 4938  do
4938        {        {
4939        if (char_has_othercase(common, cc + 1) && char_get_othercase_bit(common, cc + 1) == 0)        if (char_has_othercase(common, cc + 1) && char_get_othercase_bit(common, cc + 1) == 0)
4940          size = 0;          size = 0;
 #ifndef COMPILE_PCRE32  
4941        else if (HAS_EXTRALEN(cc[1]))        else if (HAS_EXTRALEN(cc[1]))
4942          size += GET_EXTRALEN(cc[1]);          size += GET_EXTRALEN(cc[1]);
 #endif  
4943        }        }
4944      else      else
4945  #endif  #endif
# Line 4724  if (!common->jscript_compat) Line 4985  if (!common->jscript_compat)
4985      {      {
4986      /* OVECTOR(1) contains the "string begin - 1" constant. */      /* OVECTOR(1) contains the "string begin - 1" constant. */
4987      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));
4988      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4989      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));
4990      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);
4991      return JUMP(SLJIT_C_NOT_ZERO);      return JUMP(SLJIT_C_NOT_ZERO);
4992      }      }
4993    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 4782  if (withchecks && !common->jscript_compa Line 5043  if (withchecks && !common->jscript_compa
5043  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5044  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5045    {    {
5046    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);
5047    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));
5048    if (withchecks)    if (withchecks)
5049      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5050    
5051    /* Needed to save important temporary registers. */    /* Needed to save important temporary registers. */
5052    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5053    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
5054    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);
5055    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));
5056    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5057    if (common->mode == JIT_COMPILE)    if (common->mode == JIT_COMPILE)
# Line 4903  if (!minimize) Line 5164  if (!minimize)
5164      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5165      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5166      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5167      OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));      OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5168      zerolength = compile_ref_checks(common, ccbegin, NULL);      zerolength = compile_ref_checks(common, ccbegin, NULL);
5169      /* Restore if not zero length. */      /* Restore if not zero length. */
5170      OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));      OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5171      }      }
5172    else    else
5173      {      {
# Line 4999  backtrack_common *backtrack; Line 5260  backtrack_common *backtrack;
5260  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5261  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5262  int start = GET(cc, 1);  int start = GET(cc, 1);
5263    pcre_uchar *start_cc;
5264    BOOL needs_control_head;
5265    
5266  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5267    
5268    /* Inlining simple patterns. */
5269    if (get_framesize(common, common->start + start, TRUE, &needs_control_head) == no_stack)
5270      {
5271      start_cc = common->start + start;
5272      compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
5273      BACKTRACK_AS(recurse_backtrack)->inlined_pattern = TRUE;
5274      return cc + 1 + LINK_SIZE;
5275      }
5276    
5277  while (entry != NULL)  while (entry != NULL)
5278    {    {
5279    if (entry->start == start)    if (entry->start == start)
# Line 5049  add_jump(compiler, &backtrack->topbacktr Line 5322  add_jump(compiler, &backtrack->topbacktr
5322  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5323  }  }
5324    
5325    static int SLJIT_CALL do_callout(struct jit_arguments* arguments, PUBL(callout_block) *callout_block, pcre_uchar **jit_ovector)
5326    {
5327    const pcre_uchar *begin = arguments->begin;
5328    int *offset_vector = arguments->offsets;
5329    int offset_count = arguments->offset_count;
5330    int i;
5331    
5332    if (PUBL(callout) == NULL)
5333      return 0;
5334    
5335    callout_block->version = 2;
5336    callout_block->callout_data = arguments->callout_data;
5337    
5338    /* Offsets in subject. */
5339    callout_block->subject_length = arguments->end - arguments->begin;
5340    callout_block->start_match = (pcre_uchar*)callout_block->subject - arguments->begin;
5341    callout_block->current_position = (pcre_uchar*)callout_block->offset_vector - arguments->begin;
5342    #if defined COMPILE_PCRE8
5343    callout_block->subject = (PCRE_SPTR)begin;
5344    #elif defined COMPILE_PCRE16
5345    callout_block->subject = (PCRE_SPTR16)begin;
5346    #elif defined COMPILE_PCRE32
5347    callout_block->subject = (PCRE_SPTR32)begin;
5348    #endif
5349    
5350    /* Convert and copy the JIT offset vector to the offset_vector array. */
5351    callout_block->capture_top = 0;
5352    callout_block->offset_vector = offset_vector;
5353    for (i = 2; i < offset_count; i += 2)
5354      {
5355      offset_vector[i] = jit_ovector[i] - begin;
5356      offset_vector[i + 1] = jit_ovector[i + 1] - begin;
5357      if (jit_ovector[i] >= begin)
5358        callout_block->capture_top = i;
5359      }
5360    
5361    callout_block->capture_top = (callout_block->capture_top >> 1) + 1;
5362    if (offset_count > 0)
5363      offset_vector[0] = -1;
5364    if (offset_count > 1)
5365      offset_vector[1] = -1;
5366    return (*PUBL(callout))(callout_block);
5367    }
5368    
5369    /* Aligning to 8 byte. */
5370    #define CALLOUT_ARG_SIZE \
5371        (((int)sizeof(PUBL(callout_block)) + 7) & ~7)
5372    
5373    #define CALLOUT_ARG_OFFSET(arg) \
5374        (-CALLOUT_ARG_SIZE + SLJIT_OFFSETOF(PUBL(callout_block), arg))
5375    
5376    static SLJIT_INLINE pcre_uchar *compile_callout_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5377    {
5378    DEFINE_COMPILER;
5379    backtrack_common *backtrack;
5380    
5381    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
5382    
5383    allocate_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5384    
5385    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
5386    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
5387    SLJIT_ASSERT(common->capture_last_ptr != 0);
5388    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);
5389    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);
5390    
5391    /* These pointer sized fields temporarly stores internal variables. */
5392    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
5393    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(offset_vector), STR_PTR, 0);
5394    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(subject), TMP2, 0);
5395    
5396    if (common->mark_ptr != 0)
5397      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr));
5398    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 2));
5399    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 2 + LINK_SIZE));
5400    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);
5401    
5402    /* Needed to save important temporary registers. */
5403    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5404    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, STACK_TOP, 0, SLJIT_IMM, CALLOUT_ARG_SIZE);
5405    GET_LOCAL_BASE(SLJIT_SCRATCH_REG3, 0, OVECTOR_START);
5406    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_callout));
5407    OP1(SLJIT_MOV_SI, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0);
5408    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5409    free_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5410    
5411    /* Check return value. */
5412    OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
5413    add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_C_SIG_GREATER));
5414    if (common->forced_quit_label == NULL)
5415      add_jump(compiler, &common->forced_quit, JUMP(SLJIT_C_SIG_LESS));
5416    else
5417      JUMPTO(SLJIT_C_SIG_LESS, common->forced_quit_label);
5418    return cc + 2 + 2 * LINK_SIZE;
5419    }
5420    
5421    #undef CALLOUT_ARG_SIZE
5422    #undef CALLOUT_ARG_OFFSET
5423    
5424  static pcre_uchar *compile_assert_matchingpath(compiler_common *common, pcre_uchar *cc, assert_backtrack *backtrack, BOOL conditional)  static pcre_uchar *compile_assert_matchingpath(compiler_common *common, pcre_uchar *cc, assert_backtrack *backtrack, BOOL conditional)
5425  {  {
5426  DEFINE_COMPILER;  DEFINE_COMPILER;
5427  int framesize;  int framesize;
5428    int extrasize;
5429    BOOL needs_control_head;
5430  int private_data_ptr;  int private_data_ptr;
5431  backtrack_common altbacktrack;  backtrack_common altbacktrack;
5432  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
# Line 5062  jump_list *tmp = NULL; Line 5436  jump_list *tmp = NULL;
5436  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5437  jump_list **found;  jump_list **found;
5438  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5439  struct sljit_label *save_quitlabel = common->quitlabel;  struct sljit_label *save_quit_label = common->quit_label;
5440  struct sljit_label *save_acceptlabel = common->acceptlabel;  struct sljit_label *save_accept_label = common->accept_label;
5441  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
5442  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
5443    BOOL save_local_exit = common->local_exit;
5444  struct sljit_jump *jump;  struct sljit_jump *jump;
5445  struct sljit_jump *brajump = NULL;  struct sljit_jump *brajump = NULL;
5446    
# Line 5077  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 5452  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
5452    }    }
5453  private_data_ptr = PRIVATE_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
5454  SLJIT_ASSERT(private_data_ptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
5455  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, FALSE, &needs_control_head);
5456  backtrack->framesize = framesize;  backtrack->framesize = framesize;
5457  backtrack->private_data_ptr = private_data_ptr;  backtrack->private_data_ptr = private_data_ptr;
5458  opcode = *cc;  opcode = *cc;
# Line 5096  if (bra == OP_BRAMINZERO) Line 5471  if (bra == OP_BRAMINZERO)
5471    
5472  if (framesize < 0)  if (framesize < 0)
5473    {    {
5474    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    extrasize = needs_control_head ? 2 : 1;
5475    allocate_stack(common, 1);    if (framesize == no_frame)
5476        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
5477      allocate_stack(common, extrasize);
5478      if (needs_control_head)
5479        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5480    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5481      if (needs_control_head)
5482        {
5483        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5484        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5485        }
5486    }    }
5487  else  else
5488    {    {
5489    allocate_stack(common, framesize + 2);    extrasize = needs_control_head ? 3 : 2;
5490      allocate_stack(common, framesize + extrasize);
5491    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5492    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(framesize + 1));    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
5493    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);
5494      if (needs_control_head)
5495        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5496    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5497    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    if (needs_control_head)
5498    init_frame(common, ccbegin, framesize + 1, 2, FALSE);      {
5499        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
5500        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
5501        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5502        }
5503      else
5504        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5505      init_frame(common, ccbegin, framesize + extrasize - 1, extrasize, FALSE);
5506    }    }
5507    
5508  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
5509  common->quitlabel = NULL;  common->local_exit = TRUE;
5510    common->quit_label = NULL;
5511  common->quit = NULL;  common->quit = NULL;
5512  while (1)  while (1)
5513    {    {
5514    common->acceptlabel = NULL;    common->accept_label = NULL;
5515    common->accept = NULL;    common->accept = NULL;
5516    altbacktrack.top = NULL;    altbacktrack.top = NULL;
5517    altbacktrack.topbacktracks = NULL;    altbacktrack.topbacktracks = NULL;
# Line 5128  while (1) Line 5523  while (1)
5523    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
5524    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5525      {      {
5526      common->quitlabel = save_quitlabel;      common->local_exit = save_local_exit;
5527      common->acceptlabel = save_acceptlabel;      common->quit_label = save_quit_label;
5528        common->accept_label = save_accept_label;
5529      common->quit = save_quit;      common->quit = save_quit;
5530      common->accept = save_accept;      common->accept = save_accept;
5531      return NULL;      return NULL;
5532      }      }
5533    common->acceptlabel = LABEL();    common->accept_label = LABEL();
5534    if (common->accept != NULL)    if (common->accept != NULL)
5535      set_jumps(common->accept, common->acceptlabel);      set_jumps(common->accept, common->accept_label);
5536    
5537    /* Reset stack. */    /* Reset stack. */
5538    if (framesize < 0)    if (framesize < 0)
5539      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      {
5540    else {      if (framesize == no_frame)
5541          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5542        else
5543          free_stack(common, extrasize);
5544        if (needs_control_head)
5545          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5546        }
5547      else
5548        {
5549      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)
5550        {        {
5551        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
5552        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_w));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));
5553          if (needs_control_head)
5554            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5555        }        }
5556      else      else
5557        {        {
5558        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5559          if (needs_control_head)
5560            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));
5561        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5562        }        }
5563    }      }
5564    
5565    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5566      {      {
5567      /* We know that STR_PTR was stored on the top of the stack. */      /* We know that STR_PTR was stored on the top of the stack. */
5568      if (conditional)      if (conditional)
5569        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), needs_control_head ? sizeof(sljit_sw) : 0);
5570      else if (bra == OP_BRAZERO)      else if (bra == OP_BRAZERO)
5571        {        {
5572        if (framesize < 0)        if (framesize < 0)
5573          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 1) * sizeof(sljit_sw));
5574        else        else
5575          {          {
5576          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_w));          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));
5577          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_w));          OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (framesize + extrasize - 1) * sizeof(sljit_sw));
5578          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
5579          }          }
5580        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5581        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5582        }        }
5583      else if (framesize >= 0)      else if (framesize >= 0)
5584        {        {
5585        /* For OP_BRA and OP_BRAMINZERO. */        /* For OP_BRA and OP_BRAMINZERO. */
5586        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_w));        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));
5587        }        }
5588      }      }
5589    add_jump(compiler, found, JUMP(SLJIT_JUMP));    add_jump(compiler, found, JUMP(SLJIT_JUMP));
# Line 5183  while (1) Line 5591  while (1)
5591    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
5592    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5593      {      {
5594      common->quitlabel = save_quitlabel;      common->local_exit = save_local_exit;
5595      common->acceptlabel = save_acceptlabel;      common->quit_label = save_quit_label;
5596        common->accept_label = save_accept_label;
5597      common->quit = save_quit;      common->quit = save_quit;
5598      common->accept = save_accept;      common->accept = save_accept;
5599      return NULL;      return NULL;
# Line 5197  while (1) Line 5606  while (1)
5606    ccbegin = cc;    ccbegin = cc;
5607    cc += GET(cc, 1);    cc += GET(cc, 1);
5608    }    }
5609    
5610  /* None of them matched. */  /* None of them matched. */
5611  if (common->quit != NULL)  if (common->quit != NULL)
5612      {
5613      jump = JUMP(SLJIT_JUMP);
5614    set_jumps(common->quit, LABEL());    set_jumps(common->quit, LABEL());
5615      SLJIT_ASSERT(framesize != no_stack);
5616      if (framesize < 0)
5617        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));
5618      else
5619        {
5620        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5621        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5622        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
5623        }
5624      JUMPHERE(jump);
5625      }
5626    
5627    if (needs_control_head)
5628      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(1));
5629    
5630  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)
5631    {    {
# Line 5211  if (opcode == OP_ASSERT || opcode == OP_ Line 5637  if (opcode == OP_ASSERT || opcode == OP_
5637      {      {
5638      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5639      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5640          {
5641          if (extrasize == 2)
5642            free_stack(common, 1);
5643        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5644          }
5645      else      else
5646        free_stack(common, 1);        free_stack(common, extrasize);
5647      }      }
5648    else    else
5649      {      {
5650      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
5651      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5652      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5653        {        {
5654        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
5655        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5656        }        }
5657      else      else
5658        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
5659      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
5660      }      }
5661    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
# Line 5237  if (opcode == OP_ASSERT || opcode == OP_ Line 5667  if (opcode == OP_ASSERT || opcode == OP_
5667    if (framesize < 0)    if (framesize < 0)
5668      {      {
5669      /* We know that STR_PTR was stored on the top of the stack. */      /* We know that STR_PTR was stored on the top of the stack. */
5670      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 1) * sizeof(sljit_sw));
5671      /* Keep the STR_PTR on the top of the stack. */      /* Keep the STR_PTR on the top of the stack. */
5672      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5673        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));        {
5674          OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5675          if (extrasize == 2)
5676            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5677          }
5678      else if (bra == OP_BRAMINZERO)      else if (bra == OP_BRAMINZERO)
5679        {        {
5680        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5681        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5682        }        }
5683      }      }
# Line 5252  if (opcode == OP_ASSERT || opcode == OP_ Line 5686  if (opcode == OP_ASSERT || opcode == OP_
5686      if (bra == OP_BRA)      if (bra == OP_BRA)
5687        {        {
5688        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
5689        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_w));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 1) * sizeof(sljit_sw));
5690        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), (extrasize - 2) * sizeof(sljit_sw));
5691        }        }
5692      else      else
5693        {        {
5694        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */        /* We don't need to keep the STR_PTR, only the previous private_data_ptr. */
5695        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 2) * sizeof(sljit_w));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + 2) * sizeof(sljit_sw));
5696        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        if (extrasize == 2)
5697        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);          {
5698            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5699            if (bra == OP_BRAMINZERO)
5700              OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5701            }
5702          else
5703            {
5704            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
5705            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);
5706            }
5707        }        }
5708      }      }
5709    
5710    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
5711      {      {
5712      backtrack->matchingpath = LABEL();      backtrack->matchingpath = LABEL();
5713      sljit_set_label(jump, backtrack->matchingpath);      SET_LABEL(jump, backtrack->matchingpath);
5714      }      }
5715    else if (bra == OP_BRAMINZERO)    else if (bra == OP_BRAMINZERO)
5716      {      {
# Line 5277  if (opcode == OP_ASSERT || opcode == OP_ Line 5720  if (opcode == OP_ASSERT || opcode == OP_
5720        {        {
5721        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);
5722        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5723        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_w));        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_sw));
5724        }        }
5725      set_jumps(backtrack->common.topbacktracks, LABEL());      set_jumps(backtrack->common.topbacktracks, LABEL());
5726      }      }
# Line 5289  else Line 5732  else
5732      {      {
5733      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5734      if (bra != OP_BRA)      if (bra != OP_BRA)
5735          {
5736          if (extrasize == 2)
5737            free_stack(common, 1);
5738        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5739          }
5740      else      else
5741        free_stack(common, 1);        free_stack(common, extrasize);
5742      }      }
5743    else    else
5744      {      {
5745      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5746      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
5747      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5748      if (bra != OP_BRA)      if (bra != OP_BRA)
5749        {        {
5750        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
5751        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5752        }        }
5753      else      else
5754        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
5755      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP1, 0);
5756      }      }
5757    
# Line 5324  else Line 5771  else
5771      }      }
5772    }    }
5773    
5774  common->quitlabel = save_quitlabel;  common->local_exit = save_local_exit;
5775  common->acceptlabel = save_acceptlabel;  common->quit_label = save_quit_label;
5776    common->accept_label = save_accept_label;
5777  common->quit = save_quit;  common->quit = save_quit;
5778  common->accept = save_accept;  common->accept = save_accept;
5779  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5780  }  }
5781    
5782  static sljit_w SLJIT_CALL do_searchovector(sljit_w refno, sljit_w* locals, pcre_uchar *name_table)  static sljit_sw SLJIT_CALL do_searchovector(sljit_uw refno, sljit_sw* locals, pcre_uchar *name_table)
5783  {  {
5784  int condition = FALSE;  int condition = FALSE;
5785  pcre_uchar *slotA = name_table;  pcre_uchar *slotA = name_table;
5786  pcre_uchar *slotB;  pcre_uchar *slotB;
5787  sljit_w name_count = locals[LOCALS0 / sizeof(sljit_w)];  sljit_sw name_count = locals[LOCALS0 / sizeof(sljit_sw)];
5788  sljit_w name_entry_size = locals[LOCALS1 / sizeof(sljit_w)];  sljit_sw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];
5789  sljit_w no_capture;  sljit_sw no_capture;
5790  int i;  int i;
5791    
5792  locals += refno & 0xff;  locals += refno & 0xff;
# Line 5388  if (i < name_count) Line 5836  if (i < name_count)
5836  return condition;  return condition;
5837  }  }
5838    
5839  static sljit_w SLJIT_CALL do_searchgroups(sljit_w recno, sljit_w* locals, pcre_uchar *name_table)  static sljit_sw SLJIT_CALL do_searchgroups(sljit_uw recno, sljit_uw* locals, pcre_uchar *name_table)
5840  {  {
5841  int condition = FALSE;  int condition = FALSE;
5842  pcre_uchar *slotA = name_table;  pcre_uchar *slotA = name_table;
5843  pcre_uchar *slotB;  pcre_uchar *slotB;
5844  sljit_w name_count = locals[LOCALS0 / sizeof(sljit_w)];  sljit_uw name_count = locals[LOCALS0 / sizeof(sljit_sw)];
5845  sljit_w name_entry_size = locals[LOCALS1 / sizeof(sljit_w)];  sljit_uw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];
5846  sljit_w group_num = locals[POSSESSIVE0 / sizeof(sljit_w)];  sljit_uw group_num = locals[POSSESSIVE0 / sizeof(sljit_sw)];
5847  int i;  sljit_uw i;
5848    
5849  for (i = 0; i < name_count; i++)  for (i = 0; i < name_count; i++)
5850    {    {
# Line 5441  if (i < name_count) Line 5889  if (i < name_count)
5889  return condition;  return condition;
5890  }  }
5891    
5892    static SLJIT_INLINE void match_once_common(compiler_common *common, pcre_uchar ket, int framesize, int private_data_ptr, BOOL has_alternatives, BOOL needs_control_head)
5893    {
5894    DEFINE_COMPILER;
5895    int stacksize;
5896    
5897    if (framesize < 0)
5898      {
5899      if (framesize == no_frame)
5900        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5901      else
5902        {
5903        stacksize = needs_control_head ? 1 : 0;
5904        if (ket != OP_KET || has_alternatives)
5905          stacksize++;
5906        free_stack(common, stacksize);
5907        }
5908    
5909      if (needs_control_head)
5910        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), (ket != OP_KET || has_alternatives) ? sizeof(sljit_sw) : 0);
5911    
5912      /* TMP2 which is set here used by OP_KETRMAX below. */
5913      if (ket == OP_KETRMAX)
5914        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);
5915      else if (ket == OP_KETRMIN)
5916        {
5917        /* Move the STR_PTR to the private_data_ptr. */
5918        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);
5919        }
5920      }
5921    else
5922      {
5923      stacksize = (ket != OP_KET || has_alternatives) ? 2 : 1;
5924      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + stacksize) * sizeof(sljit_sw));
5925      if (needs_control_head)
5926        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 0);
5927    
5928      if (ket == OP_KETRMAX)
5929        {
5930        /* TMP2 which is set here used by OP_KETRMAX below. */
5931        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5932        }
5933      }
5934    if (needs_control_head)
5935      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP1, 0);
5936    }
5937    
5938    static SLJIT_INLINE int match_capture_common(compiler_common *common, int stacksize, int offset, int private_data_ptr)
5939    {
5940    DEFINE_COMPILER;
5941    
5942    if (common->capture_last_ptr != 0)
5943      {
5944      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
5945      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
5946      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
5947      stacksize++;
5948      }
5949    if (common->optimized_cbracket[offset >> 1] == 0)
5950      {
5951      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5952      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5953      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
5954      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5955      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
5956      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
5957      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
5958      stacksize += 2;
5959      }
5960    return stacksize;
5961    }
5962    
5963  /*  /*
5964    Handling bracketed expressions is probably the most complex part.    Handling bracketed expressions is probably the most complex part.
5965    
# Line 5509  pcre_uchar bra = OP_BRA; Line 6028  pcre_uchar bra = OP_BRA;
6028  pcre_uchar ket;  pcre_uchar ket;
6029  assert_backtrack *assert;  assert_backtrack *assert;
6030  BOOL has_alternatives;  BOOL has_alternatives;
6031    BOOL needs_control_head = FALSE;
6032  struct sljit_jump *jump;  struct sljit_jump *jump;
6033  struct sljit_jump *skip;  struct sljit_jump *skip;
6034  struct sljit_label *rmaxlabel = NULL;  struct sljit_label *rmaxlabel = NULL;
# Line 5551  if (SLJIT_UNLIKELY(opcode == OP_COND) || Line 6071  if (SLJIT_UNLIKELY(opcode == OP_COND) ||
6071      else if (common->currententry->start == 0)      else if (common->currententry->start == 0)
6072        has_alternatives = stacksize != 0;        has_alternatives = stacksize != 0;
6073      else      else
6074        has_alternatives = stacksize != GET2(common->start, common->currententry->start + 1 + LINK_SIZE);        has_alternatives = stacksize != (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6075      }      }
6076    }    }
6077    
# Line 5584  else if (opcode == OP_ONCE || opcode == Line 6104  else if (opcode == OP_ONCE || opcode ==
6104    SLJIT_ASSERT(private_data_ptr != 0);    SLJIT_ASSERT(private_data_ptr != 0);
6105    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;
6106    if (opcode == OP_ONCE)    if (opcode == OP_ONCE)
6107      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, FALSE);      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, FALSE, &needs_control_head);
6108    }    }
6109    
6110  /* Instructions before the first alternative. */  /* Instructions before the first alternative. */
6111  stacksize = 0;  stacksize = 0;
6112  if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))  if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
6113    stacksize++;    stacksize++;
6114  if (bra == OP_BRAZERO)  if (bra == OP_BRAZERO)
6115    stacksize++;    stacksize++;
# Line 5598  if (stacksize > 0) Line 6118  if (stacksize > 0)
6118    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6119    
6120  stacksize = 0;  stacksize = 0;
6121  if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))  if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
6122    {    {
6123    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
6124    stacksize++;    stacksize++;
# Line 5635  if (bra == OP_BRAMINZERO) Line 6155  if (bra == OP_BRAMINZERO)
6155          {          {
6156          /* Except when the whole stack frame must be saved. */          /* Except when the whole stack frame must be saved. */
6157          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);
6158          braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (BACKTRACK_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_w));          braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (BACKTRACK_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_sw));
6159          }          }
6160        JUMPHERE(skip);        JUMPHERE(skip);
6161        }        }
# Line 5661  if (ket == OP_KETRMAX) Line 6181  if (ket == OP_KETRMAX)
6181  /* Handling capturing brackets and alternatives. */  /* Handling capturing brackets and alternatives. */
6182  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
6183    {    {
6184      stacksize = 0;
6185      if (needs_control_head)
6186        {
6187        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6188        stacksize++;
6189        }
6190    
6191    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
6192      {      {
6193      /* Neither capturing brackets nor recursions are not found in the block. */      /* Neither capturing brackets nor recursions are found in the block. */
6194      if (ket == OP_KETRMIN)      if (ket == OP_KETRMIN)
6195        {        {
6196        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        stacksize += 2;
6197        allocate_stack(common, 2);        if (!needs_control_head)
6198        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);  
       OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));  
6199        }        }
6200      else if (ket == OP_KETRMAX || has_alternatives)      else
6201        {        {
6202        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);        if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)
6203        allocate_stack(common, 1);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6204        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);        if (ket == OP_KETRMAX || has_alternatives)
6205            stacksize++;
6206        }        }
6207      else  
6208        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);      if (stacksize > 0)
6209          allocate_stack(common, stacksize);
6210    
6211        stacksize = 0;
6212        if (needs_control_head)
6213          {
6214          stacksize++;
6215          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6216          }
6217    
6218        if (ket == OP_KETRMIN)
6219          {
6220          if (needs_control_head)
6221            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6222          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6223          if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)
6224            OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, needs_control_head ? (2 * sizeof(sljit_sw)) : sizeof(sljit_sw));
6225          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6226          }
6227        else if (ket == OP_KETRMAX || has_alternatives)
6228          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6229      }      }
6230    else    else
6231      {      {
6232      if (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives)      if (ket != OP_KET || has_alternatives)
6233          stacksize++;
6234    
6235        stacksize += BACKTRACK_AS(bracket_backtrack)->u.framesize + 1;
6236        allocate_stack(common, stacksize);
6237    
6238        if (needs_control_head)
6239          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6240    
6241        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6242        OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, stacksize * sizeof(sljit_sw));
6243    
6244        stacksize = needs_control_head ? 1 : 0;
6245        if (ket != OP_KET || has_alternatives)
6246        {        {
6247        allocate_stack(common, BACKTRACK_AS(bracket_backtrack)->u.framesize + 2);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
       OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
       OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(BACKTRACK_AS(bracket_backtrack)->u.framesize + 1));  
       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  
6248        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);
6249        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);        stacksize++;
6250        init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize + 1, 2, FALSE);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6251        }        }
6252      else      else
6253        {        {
       allocate_stack(common, BACKTRACK_AS(bracket_backtrack)->u.framesize + 1);  
       OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
       OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(BACKTRACK_AS(bracket_backtrack)->u.framesize));  
6254        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);
6255        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
       init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize, 1, FALSE);  
6256        }        }
6257        init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize, stacksize + 1, FALSE);
6258      }      }
6259    }    }
6260  else if (opcode == OP_CBRA || opcode == OP_SCBRA)  else if (opcode == OP_CBRA || opcode == OP_SCBRA)
6261    {    {
6262    /* Saving the previous values. */    /* Saving the previous values. */
6263    if (common->optimized_cbracket[offset >> 1] == 0)    if (common->optimized_cbracket[offset >> 1] != 0)
     {  
     allocate_stack(common, 3);  
     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  
     OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);  
     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);  
     }  
   else  
6264      {      {
6265      SLJIT_ASSERT(private_data_ptr == OVECTOR(offset));      SLJIT_ASSERT(private_data_ptr == OVECTOR(offset));
6266      allocate_stack(common, 2);      allocate_stack(common, 2);
6267      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);
6268      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr + sizeof(sljit_w));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr + sizeof(sljit_sw));
6269      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);
6270      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
6271      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6272      }      }
6273      else
6274        {
6275        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6276        allocate_stack(common, 1);
6277        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0);
6278        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6279        }
6280    }    }
6281  else if (opcode == OP_SBRA || opcode == OP_SCOND)  else if (opcode == OP_SBRA || opcode == OP_SCOND)
6282    {    {
# Line 5763  if (opcode == OP_COND || opcode == OP_SC Line 6312  if (opcode == OP_COND || opcode == OP_SC
6312      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);
6313      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);
6314      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);
6315      OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, (stacksize << 8) | (common->ovector_start / sizeof(sljit_w)));      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (stacksize << 8) | (common->ovector_start / sizeof(sljit_sw)));
6316      GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, 0);      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, 0);
6317      OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, common->name_table);      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);
6318      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));
6319      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
6320      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));
6321    
6322      JUMPHERE(jump);      JUMPHERE(jump);
6323      matchingpath += 1 + IMM2_SIZE;      matchingpath += 1 + IMM2_SIZE;
# Line 5786  if (opcode == OP_COND || opcode == OP_SC Line 6335  if (opcode == OP_COND || opcode == OP_SC
6335      else if (common->currententry->start == 0)      else if (common->currententry->start == 0)
6336        stacksize = stacksize == 0;        stacksize = stacksize == 0;
6337      else      else
6338        stacksize = stacksize == GET2(common->start, common->currententry->start + 1 + LINK_SIZE);        stacksize = stacksize == (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6339    
6340      if (*matchingpath == OP_RREF || stacksize || common->currententry == NULL)      if (*matchingpath == OP_RREF || stacksize || common->currententry == NULL)
6341        {        {
# Line 5813  if (opcode == OP_COND || opcode == OP_SC Line 6362  if (opcode == OP_COND || opcode == OP_SC
6362        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);
6363        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);
6364        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));
6365        OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, stacksize);        OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, stacksize);
6366        GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, 0);        GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, 0);
6367        OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, common->name_table);        OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);
6368        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));
6369        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
6370        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));
6371        matchingpath += 1 + IMM2_SIZE;        matchingpath += 1 + IMM2_SIZE;
6372        }        }
6373      }      }
# Line 5841  if (SLJIT_UNLIKELY(sljit_get_compiler_er Line 6390  if (SLJIT_UNLIKELY(sljit_get_compiler_er
6390    return NULL;    return NULL;
6391    
6392  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
6393    {    match_once_common(common, ket, BACKTRACK_AS(bracket_backtrack)->u.framesize, private_data_ptr, has_alternatives, needs_control_head);
   if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)  
     {  
     OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
     /* TMP2 which is set here used by OP_KETRMAX below. */  
     if (ket == OP_KETRMAX)  
       OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);  
     else if (ket == OP_KETRMIN)  
       {  
       /* Move the STR_PTR to the private_data_ptr. */  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);  
       }  
     }  
   else  
     {  
     stacksize = (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives) ? 2 : 1;  
     OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize) * sizeof(sljit_w));  
     if (ket == OP_KETRMAX)  
       {  
       /* TMP2 which is set here used by OP_KETRMAX below. */  
       OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));  
       }  
     }  
   }  
6394    
6395  stacksize = 0;  stacksize = 0;
6396  if (ket != OP_KET || bra != OP_BRA)  if (ket != OP_KET || bra != OP_BRA)
6397    stacksize++;    stacksize++;
6398    if (offset != 0)
6399      {
6400      if (common->capture_last_ptr != 0)
6401        stacksize++;
6402      if (common->optimized_cbracket[offset >> 1] == 0)
6403        stacksize += 2;
6404      }
6405  if (has_alternatives && opcode != OP_ONCE)  if (has_alternatives && opcode != OP_ONCE)
6406    stacksize++;    stacksize++;
6407    
6408  if (stacksize > 0)  if (stacksize > 0)
6409    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6410    
6411  stacksize = 0;  stacksize = 0;
6412  if (ket != OP_KET)  if (ket != OP_KET || bra != OP_BRA)
   {  
   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);  
   stacksize++;  
   }  
 else if (bra != OP_BRA)  
6413    {    {
6414    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);    if (ket != OP_KET)
6415        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6416      else
6417        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
6418    stacksize++;    stacksize++;
6419    }    }
6420    
6421    if (offset != 0)
6422      stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);
6423    
6424  if (has_alternatives)  if (has_alternatives)
6425    {    {
6426    if (opcode != OP_ONCE)    if (opcode != OP_ONCE)
# Line 5896  if (has_alternatives) Line 6430  if (has_alternatives)
6430    }    }
6431    
6432  /* Must be after the matchingpath label. */  /* Must be after the matchingpath label. */
6433  if (offset != 0)  if (offset != 0 && common->optimized_cbracket[offset >> 1] != 0)
6434    {    {
6435    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    SLJIT_ASSERT(private_data_ptr == OVECTOR(offset + 0));
6436    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 0), TMP1, 0);  
6437    }    }
6438    
6439  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
# Line 5957  if ((ket != OP_KET && bra != OP_BRAMINZE Line 6490  if ((ket != OP_KET && bra != OP_BRAMINZE
6490  while (*cc == OP_ALT)  while (*cc == OP_ALT)
6491    cc += GET(cc, 1);    cc += GET(cc, 1);
6492  cc += 1 + LINK_SIZE;  cc += 1 + LINK_SIZE;
6493    
6494    /* Temporarily encoding the needs_control_head in framesize. */
6495    if (opcode == OP_ONCE)
6496      BACKTRACK_AS(bracket_backtrack)->u.framesize = (BACKTRACK_AS(bracket_backtrack)->u.framesize << 1) | (needs_control_head ? 1 : 0);
6497  return cc;  return cc;
6498  }  }
6499    
# Line 5967  backtrack_common *backtrack; Line 6504  backtrack_common *backtrack;
6504  pcre_uchar opcode;  pcre_uchar opcode;
6505  int private_data_ptr;  int private_data_ptr;
6506  int cbraprivptr = 0;  int cbraprivptr = 0;
6507    BOOL needs_control_head;
6508  int framesize;  int framesize;
6509  int stacksize;  int stacksize;
6510  int offset = 0;  int offset = 0;
6511  BOOL zero = FALSE;  BOOL zero = FALSE;
6512  pcre_uchar *ccbegin = NULL;  pcre_uchar *ccbegin = NULL;
6513  int stack;  int stack; /* Also contains the offset of control head. */
6514  struct sljit_label *loop = NULL;  struct sljit_label *loop = NULL;
6515  struct jump_list *emptymatch = NULL;  struct jump_list *emptymatch = NULL;
6516    
# Line 6010  switch(opcode) Line 6548  switch(opcode)
6548    break;    break;
6549    }    }
6550    
6551  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, FALSE, &needs_control_head);
6552  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;
6553  if (framesize < 0)  if (framesize < 0)
6554    {    {
6555    stacksize = (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS) ? 2 : 1;    if (offset != 0)
6556        {
6557        stacksize = 2;
6558        if (common->capture_last_ptr != 0)
6559          stacksize++;
6560        }
6561      else
6562        stacksize = 1;
6563    
6564      if (needs_control_head)
6565        stacksize++;
6566    if (!zero)    if (!zero)
6567      stacksize++;      stacksize++;
6568    
6569    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
6570    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6571    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    if (framesize == no_frame)
6572        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6573    
6574    if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)    stack = 0;
6575      if (offset != 0)
6576      {      {
6577        stack = 2;
6578      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6579      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
6580      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
6581        if (common->capture_last_ptr != 0)
6582          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6583      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6584        if (needs_control_head)
6585          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6586        if (common->capture_last_ptr != 0)
6587          {
6588          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
6589          stack = 3;
6590          }
6591      }      }
6592    else    else
6593        {
6594        if (needs_control_head)
6595          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6596      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6597        stack = 1;
6598        }
6599    
6600      if (needs_control_head)
6601        stack++;
6602    if (!zero)    if (!zero)
6603      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize - 1), SLJIT_IMM, 1);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), SLJIT_IMM, 1);
6604      if (needs_control_head)
6605        {
6606        stack--;
6607        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP2, 0);
6608        }
6609    }    }
6610  else  else
6611    {    {
6612    stacksize = framesize + 1;    stacksize = framesize + 1;
6613    if (!zero)    if (!zero)
6614      stacksize++;      stacksize++;
6615    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)    if (needs_control_head)
6616        stacksize++;
6617      if (offset == 0)
6618      stacksize++;      stacksize++;
6619    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
   allocate_stack(common, stacksize);  
6620    
6621      allocate_stack(common, stacksize);
6622    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6623    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));    if (needs_control_head)
6624    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6625      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));
6626    
6627    stack = 0;    stack = 0;
6628    if (!zero)    if (!zero)
6629      {      {
6630      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 1);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 1);
6631        stack = 1;
6632        }
6633      if (needs_control_head)
6634        {
6635        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP2, 0);
6636      stack++;      stack++;
6637      }      }
6638    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)    if (offset == 0)
6639      {      {
6640      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), STR_PTR, 0);
6641      stack++;      stack++;
6642      }      }
6643    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP1, 0);
6644    init_frame(common, cc, stacksize - 1, stacksize - framesize, FALSE);    init_frame(common, cc, stacksize - 1, stacksize - framesize, FALSE);
6645      stack -= 1 + (offset == 0);
6646    }    }
6647    
6648  if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)  if (offset != 0)
6649    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6650    
6651  loop = LABEL();  loop = LABEL();
# Line 6078  while (*cc != OP_KETRPOS) Line 6661  while (*cc != OP_KETRPOS)
6661    
6662    if (framesize < 0)    if (framesize < 0)
6663      {      {
6664      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      if (framesize == no_frame)
6665          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6666    
6667      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6668        {        {
6669        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr);
6670        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
6671        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), cbraprivptr, STR_PTR, 0);
6672          if (common->capture_last_ptr != 0)
6673            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6674        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6675        }        }
6676      else      else
# Line 6102  while (*cc != OP_KETRPOS) Line 6688  while (*cc != OP_KETRPOS)
6688      }      }
6689    else    else
6690      {      {
6691      if (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS)      if (offset != 0)
6692        {        {
6693        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, stacksize * sizeof(sljit_w));        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, stacksize * sizeof(sljit_sw));
6694