/[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 1176 by ph10, Sat Oct 27 15:46:35 2012 UTC revision 1316 by zherczeg, Sun Apr 28 08:54:42 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11    The machine code generator part (this module) was written by Zoltan Herczeg    The machine code generator part (this module) was written by Zoltan Herczeg
12                        Copyright (c) 2010-2012                        Copyright (c) 2010-2013
13    
14  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
15  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 65  system files. */ Line 65  system files. */
65  #error Unsupported architecture  #error Unsupported architecture
66  #endif  #endif
67    
68    /* Defines for debugging purposes. */
69    
70    /* 1 - Use unoptimized capturing brackets.
71       2 - Enable capture_last_ptr (includes option 1). */
72    /* #define DEBUG_FORCE_UNOPTIMIZED_CBRAS 2 */
73    
74    /* 1 - Always have a control head. */
75    /* #define DEBUG_FORCE_CONTROL_HEAD 1 */
76    
77  /* Allocate memory for the regex stack on the real machine stack.  /* Allocate memory for the regex stack on the real machine stack.
78  Fast, but limited size. */  Fast, but limited size. */
79  #define MACHINE_STACK_SIZE 32768  #define MACHINE_STACK_SIZE 32768
# Line 157  typedef struct jit_arguments { Line 166  typedef struct jit_arguments {
166    int *offsets;    int *offsets;
167    pcre_uchar *uchar_ptr;    pcre_uchar *uchar_ptr;
168    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
169      void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171    int offsetcount;    pcre_uint32 limit_match;
172    int calllimit;    int real_offset_count;
173      int offset_count;
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 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      pcre_uint32 limit_match;
186    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
187  } executable_functions;  } executable_functions;
188    
# Line 178  typedef struct jump_list { Line 191  typedef struct jump_list {
191    struct jump_list *next;    struct jump_list *next;
192  } jump_list;  } jump_list;
193    
 enum stub_types { stack_alloc };  
   
194  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
195    struct sljit_jump *start;    struct sljit_jump *start;
196    struct sljit_label *quit;    struct sljit_label *quit;
197    struct stub_list *next;    struct stub_list *next;
198  } stub_list;  } stub_list;
199    
200    enum frame_types {
201      no_frame = -1,
202      no_stack = -2
203    };
204    
205    enum control_types {
206      type_mark = 0,
207      type_then_trap = 1
208    };
209    
210  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
# 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 264  typedef struct recurse_entry { Line 283  typedef struct recurse_entry {
283    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
284    jump_list *calls;    jump_list *calls;
285    /* Points to the starting opcode. */    /* Points to the starting opcode. */
286    int start;    sljit_sw start;
287  } recurse_entry;  } recurse_entry;
288    
289  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
290    backtrack_common common;    backtrack_common common;
291      BOOL inlined_pattern;
292  } recurse_backtrack;  } recurse_backtrack;
293    
294    #define OP_THEN_TRAP OP_TABLE_LENGTH
295    
296    typedef struct then_trap_backtrack {
297      backtrack_common common;
298      /* If then_trap is not NULL, this structure contains the real
299      then_trap for the backtracking path. */
300      struct then_trap_backtrack *then_trap;
301      /* Points to the starting opcode. */
302      sljit_sw start;
303      /* Exit point for the then opcodes of this alternative. */
304      jump_list *quit;
305      /* Frame size of the current alternative. */
306      int framesize;
307    } then_trap_backtrack;
308    
309  #define MAX_RANGE_SIZE 6  #define MAX_RANGE_SIZE 6
310    
311  typedef struct compiler_common {  typedef struct compiler_common {
312      /* The sljit ceneric compiler. */
313    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
314      /* First byte code. */
315    pcre_uchar *start;    pcre_uchar *start;
   
316    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
317    int *private_data_ptrs;    sljit_si *private_data_ptrs;
318    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
319    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
320      /* Tells whether the starting offset is a target of then. */
321      pcre_uint8 *then_offsets;
322      /* Current position where a THEN must jump. */
323      then_trap_backtrack *then_trap;
324    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
325    int cbraptr;    int cbra_ptr;
326    /* OVector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
327    int ovector_start;    int ovector_start;
328    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
329    int req_char_ptr;    int req_char_ptr;
330    /* Head of the last recursion. */    /* Head of the last recursion. */
331    int recursive_head;    int recursive_head_ptr;
332    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
333    int start_used_ptr;    int start_used_ptr;
334    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 297  typedef struct compiler_common { Line 337  typedef struct compiler_common {
337    int first_line_end;    int first_line_end;
338    /* Points to the marked string. */    /* Points to the marked string. */
339    int mark_ptr;    int mark_ptr;
340      /* Recursive control verb management chain. */
341      int control_head_ptr;
342      /* Points to the last matched capture block index. */
343      int capture_last_ptr;
344      /* Points to the starting position of the current match. */
345      int start_ptr;
346    
347    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
348    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
349    sljit_w lcc;    sljit_sw lcc;
350    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
351    int mode;    int mode;
352      /* \K is found in the pattern. */
353      BOOL has_set_som;
354      /* (*SKIP:arg) is found in the pattern. */
355      BOOL has_skip_arg;
356      /* (*THEN) is found in the pattern. */
357      BOOL has_then;
358      /* Needs to know the start position anytime. */
359      BOOL needs_start_ptr;
360      /* Currently in recurse or negative assert. */
361      BOOL local_exit;
362      /* Currently in a positive assert. */
363      BOOL positive_assert;
364    /* Newline control. */    /* Newline control. */
365    int nltype;    int nltype;
366    int newline;    int newline;
367    int bsr_nltype;    int bsr_nltype;
368    /* Dollar endonly. */    /* Dollar endonly. */
369    int endonly;    int endonly;
   BOOL has_set_som;  
370    /* Tables. */    /* Tables. */
371    sljit_w ctypes;    sljit_sw ctypes;
372    int digits[2 + MAX_RANGE_SIZE];    int digits[2 + MAX_RANGE_SIZE];
373    /* Named capturing brackets. */    /* Named capturing brackets. */
374    sljit_uw name_table;    sljit_uw name_table;
375    sljit_w name_count;    sljit_sw name_count;
376    sljit_w name_entry_size;    sljit_sw name_entry_size;
377    
378    /* Labels and jump lists. */    /* Labels and jump lists. */
379    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
380    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
381    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
382      struct sljit_label *accept_label;
383    stub_list *stubs;    stub_list *stubs;
384    recurse_entry *entries;    recurse_entry *entries;
385    recurse_entry *currententry;    recurse_entry *currententry;
386    jump_list *partialmatch;    jump_list *partialmatch;
387    jump_list *quit;    jump_list *quit;
388      jump_list *positive_assert_quit;
389      jump_list *forced_quit;
390    jump_list *accept;    jump_list *accept;
391    jump_list *calllimit;    jump_list *calllimit;
392    jump_list *stackalloc;    jump_list *stackalloc;
# Line 337  typedef struct compiler_common { Line 397  typedef struct compiler_common {
397    jump_list *vspace;    jump_list *vspace;
398    jump_list *casefulcmp;    jump_list *casefulcmp;
399    jump_list *caselesscmp;    jump_list *caselesscmp;
400      jump_list *reset_match;
401    BOOL jscript_compat;    BOOL jscript_compat;
402  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
403    BOOL utf;    BOOL utf;
# Line 363  typedef struct compare_context { Line 424  typedef struct compare_context {
424  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
425    int ucharptr;    int ucharptr;
426    union {    union {
427      sljit_i asint;      sljit_si asint;
428      sljit_uh asushort;      sljit_uh asushort;
429  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
430      sljit_ub asbyte;      sljit_ub asbyte;
# Line 375  typedef struct compare_context { Line 436  typedef struct compare_context {
436  #endif  #endif
437    } c;    } c;
438    union {    union {
439      sljit_i asint;      sljit_si asint;
440      sljit_uh asushort;      sljit_uh asushort;
441  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
442      sljit_ub asbyte;      sljit_ub asbyte;
# Line 389  typedef struct compare_context { Line 450  typedef struct compare_context {
450  #endif  #endif
451  } compare_context;  } compare_context;
452    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
453  /* Undefine sljit macros. */  /* Undefine sljit macros. */
454  #undef CMP  #undef CMP
455    
456  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
457  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
458    
459  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
460  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
461  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
462  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
463  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
464  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
465  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
466  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
467  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define COUNT_MATCH   SLJIT_SAVED_EREG2
468  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
469    
470  /* Local space layout. */  /* Local space layout. */
471  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
472  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
473  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
474  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
475  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
476  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
477  /* Max limit of recursions. */  /* Max limit of recursions. */
478  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
479  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
480  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
481  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
482  the start pointers when the end of the capturing group has not yet reached. */  the start pointers when the end of the capturing group has not yet reached. */
483  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
484  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))
485  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * sizeof(sljit_sw))
486  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
487    
488  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
# Line 458  the start pointers when the end of the c Line 513  the start pointers when the end of the c
513    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
514  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
515    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
516    #define SET_LABEL(jump, label) \
517      sljit_set_label((jump), (label))
518  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
519    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
520  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
521    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))
522  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
523    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
524  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
525    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
526    
# Line 478  return cc; Line 535  return cc;
535    
536  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
537   next_opcode   next_opcode
538   get_private_data_length   check_opcode_types
539   set_private_data_ptrs   set_private_data_ptrs
540   get_framesize   get_framesize
541   init_frame   init_frame
542   get_private_data_length_for_copy   get_private_data_copy_length
543   copy_private_data   copy_private_data
544   compile_matchingpath   compile_matchingpath
545   compile_backtrackingpath   compile_backtrackingpath
# Line 506  switch(*cc) Line 563  switch(*cc)
563    case OP_WORDCHAR:    case OP_WORDCHAR:
564    case OP_ANY:    case OP_ANY:
565    case OP_ALLANY:    case OP_ALLANY:
566      case OP_NOTPROP:
567      case OP_PROP:
568    case OP_ANYNL:    case OP_ANYNL:
569    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
570    case OP_HSPACE:    case OP_HSPACE:
# Line 518  switch(*cc) Line 577  switch(*cc)
577    case OP_CIRCM:    case OP_CIRCM:
578    case OP_DOLL:    case OP_DOLL:
579    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:  
580    case OP_CRSTAR:    case OP_CRSTAR:
581    case OP_CRMINSTAR:    case OP_CRMINSTAR:
582    case OP_CRPLUS:    case OP_CRPLUS:
583    case OP_CRMINPLUS:    case OP_CRMINPLUS:
584    case OP_CRQUERY:    case OP_CRQUERY:
585    case OP_CRMINQUERY:    case OP_CRMINQUERY:
586      case OP_CRRANGE:
587      case OP_CRMINRANGE:
588      case OP_CLASS:
589      case OP_NCLASS:
590      case OP_REF:
591      case OP_REFI:
592      case OP_RECURSE:
593      case OP_CALLOUT:
594      case OP_ALT:
595      case OP_KET:
596      case OP_KETRMAX:
597      case OP_KETRMIN:
598      case OP_KETRPOS:
599      case OP_REVERSE:
600      case OP_ASSERT:
601      case OP_ASSERT_NOT:
602      case OP_ASSERTBACK:
603      case OP_ASSERTBACK_NOT:
604      case OP_ONCE:
605      case OP_ONCE_NC:
606      case OP_BRA:
607      case OP_BRAPOS:
608      case OP_CBRA:
609      case OP_CBRAPOS:
610      case OP_COND:
611      case OP_SBRA:
612      case OP_SBRAPOS:
613      case OP_SCBRA:
614      case OP_SCBRAPOS:
615      case OP_SCOND:
616      case OP_CREF:
617      case OP_NCREF:
618      case OP_RREF:
619      case OP_NRREF:
620    case OP_DEF:    case OP_DEF:
621    case OP_BRAZERO:    case OP_BRAZERO:
622    case OP_BRAMINZERO:    case OP_BRAMINZERO:
623    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
624      case OP_PRUNE:
625      case OP_SKIP:
626      case OP_THEN:
627    case OP_COMMIT:    case OP_COMMIT:
628    case OP_FAIL:    case OP_FAIL:
629    case OP_ACCEPT:    case OP_ACCEPT:
630    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
631      case OP_CLOSE:
632    case OP_SKIPZERO:    case OP_SKIPZERO:
633    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
634    
635    case OP_CHAR:    case OP_CHAR:
636    case OP_CHARI:    case OP_CHARI:
# Line 560  switch(*cc) Line 642  switch(*cc)
642    case OP_MINPLUS:    case OP_MINPLUS:
643    case OP_QUERY:    case OP_QUERY:
644    case OP_MINQUERY:    case OP_MINQUERY:
645      case OP_UPTO:
646      case OP_MINUPTO:
647      case OP_EXACT:
648    case OP_POSSTAR:    case OP_POSSTAR:
649    case OP_POSPLUS:    case OP_POSPLUS:
650    case OP_POSQUERY:    case OP_POSQUERY:
651      case OP_POSUPTO:
652    case OP_STARI:    case OP_STARI:
653    case OP_MINSTARI:    case OP_MINSTARI:
654    case OP_PLUSI:    case OP_PLUSI:
655    case OP_MINPLUSI:    case OP_MINPLUSI:
656    case OP_QUERYI:    case OP_QUERYI:
657    case OP_MINQUERYI:    case OP_MINQUERYI:
658      case OP_UPTOI:
659      case OP_MINUPTOI:
660      case OP_EXACTI:
661    case OP_POSSTARI:    case OP_POSSTARI:
662    case OP_POSPLUSI:    case OP_POSPLUSI:
663    case OP_POSQUERYI:    case OP_POSQUERYI:
664      case OP_POSUPTOI:
665    case OP_NOTSTAR:    case OP_NOTSTAR:
666    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
667    case OP_NOTPLUS:    case OP_NOTPLUS:
668    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
669    case OP_NOTQUERY:    case OP_NOTQUERY:
670    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
671      case OP_NOTUPTO:
672      case OP_NOTMINUPTO:
673      case OP_NOTEXACT:
674    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
675    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
676    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
677      case OP_NOTPOSUPTO:
678    case OP_NOTSTARI:    case OP_NOTSTARI:
679    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
680    case OP_NOTPLUSI:    case OP_NOTPLUSI:
681    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
682    case OP_NOTQUERYI:    case OP_NOTQUERYI:
683    case OP_NOTMINQUERYI:    case OP_NOTMINQUERYI:
   case OP_NOTPOSSTARI:  
   case OP_NOTPOSPLUSI:  
   case OP_NOTPOSQUERYI:  
   cc += 2;  
 #ifdef SUPPORT_UTF  
   if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
   return cc;  
   
   case OP_UPTO:  
   case OP_MINUPTO:  
   case OP_EXACT:  
   case OP_POSUPTO:  
   case OP_UPTOI:  
   case OP_MINUPTOI:  
   case OP_EXACTI:  
   case OP_POSUPTOI:  
   case OP_NOTUPTO:  
   case OP_NOTMINUPTO:  
   case OP_NOTEXACT:  
   case OP_NOTPOSUPTO:  
684    case OP_NOTUPTOI:    case OP_NOTUPTOI:
685    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
686    case OP_NOTEXACTI:    case OP_NOTEXACTI:
687      case OP_NOTPOSSTARI:
688      case OP_NOTPOSPLUSI:
689      case OP_NOTPOSQUERYI:
690    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
691    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
692  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
693    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
694  #endif  #endif
695    return cc;    return cc;
696    
697    case OP_NOTPROP:    /* Special cases. */
698    case OP_PROP:    case OP_TYPESTAR:
699    return cc + 1 + 2;    case OP_TYPEMINSTAR:
700      case OP_TYPEPLUS:
701      case OP_TYPEMINPLUS:
702      case OP_TYPEQUERY:
703      case OP_TYPEMINQUERY:
704    case OP_TYPEUPTO:    case OP_TYPEUPTO:
705    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
706    case OP_TYPEEXACT:    case OP_TYPEEXACT:
707      case OP_TYPEPOSSTAR:
708      case OP_TYPEPOSPLUS:
709      case OP_TYPEPOSQUERY:
710    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
711    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;  
712    
713    case OP_CLASS:    case OP_ANYBYTE:
714    case OP_NCLASS:  #ifdef SUPPORT_UTF
715    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
716    #endif
717      return cc + 1;
718    
719  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
720    case OP_XCLASS:    case OP_XCLASS:
721    return cc + GET(cc, 1);    return cc + GET(cc, 1);
722  #endif  #endif
723    
   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;  
   
724    case OP_MARK:    case OP_MARK:
725      case OP_PRUNE_ARG:
726      case OP_SKIP_ARG:
727      case OP_THEN_ARG:
728    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
729    
730    default:    default:
731      /* All opcodes are supported now! */
732      SLJIT_ASSERT_STOP();
733    return NULL;    return NULL;
734    }    }
735  }  }
736    
737  #define CASE_ITERATOR_PRIVATE_DATA_1 \  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
     case OP_MINSTAR: \  
     case OP_MINPLUS: \  
     case OP_QUERY: \  
     case OP_MINQUERY: \  
     case OP_MINSTARI: \  
     case OP_MINPLUSI: \  
     case OP_QUERYI: \  
     case OP_MINQUERYI: \  
     case OP_NOTMINSTAR: \  
     case OP_NOTMINPLUS: \  
     case OP_NOTQUERY: \  
     case OP_NOTMINQUERY: \  
     case OP_NOTMINSTARI: \  
     case OP_NOTMINPLUSI: \  
     case OP_NOTQUERYI: \  
     case OP_NOTMINQUERYI:  
   
 #define CASE_ITERATOR_PRIVATE_DATA_2A \  
     case OP_STAR: \  
     case OP_PLUS: \  
     case OP_STARI: \  
     case OP_PLUSI: \  
     case OP_NOTSTAR: \  
     case OP_NOTPLUS: \  
     case OP_NOTSTARI: \  
     case OP_NOTPLUSI:  
   
 #define CASE_ITERATOR_PRIVATE_DATA_2B \  
     case OP_UPTO: \  
     case OP_MINUPTO: \  
     case OP_UPTOI: \  
     case OP_MINUPTOI: \  
     case OP_NOTUPTO: \  
     case OP_NOTMINUPTO: \  
     case OP_NOTUPTOI: \  
     case OP_NOTMINUPTOI:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \  
     case OP_TYPEMINSTAR: \  
     case OP_TYPEMINPLUS: \  
     case OP_TYPEQUERY: \  
     case OP_TYPEMINQUERY:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \  
     case OP_TYPESTAR: \  
     case OP_TYPEPLUS:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \  
     case OP_TYPEUPTO: \  
     case OP_TYPEMINUPTO:  
   
 static int get_class_iterator_size(pcre_uchar *cc)  
 {  
 switch(*cc)  
   {  
   case OP_CRSTAR:  
   case OP_CRPLUS:  
   return 2;  
   
   case OP_CRMINSTAR:  
   case OP_CRMINPLUS:  
   case OP_CRQUERY:  
   case OP_CRMINQUERY:  
   return 1;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))  
     return 0;  
   return 2;  
   
   default:  
   return 0;  
   }  
 }  
   
 static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  
738  {  {
 int private_data_length = 0;  
 pcre_uchar *alternative;  
739  pcre_uchar *name;  pcre_uchar *name;
740  pcre_uchar *end = NULL;  pcre_uchar *name2;
741  int space, size, i;  unsigned int cbra_index;
742  pcre_uint32 bracketlen;  int i;
743    
744  /* 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. */
745  while (cc < ccend)  while (cc < ccend)
746    {    {
   space = 0;  
   size = 0;  
   bracketlen = 0;  
747    switch(*cc)    switch(*cc)
748      {      {
749      case OP_SET_SOM:      case OP_SET_SOM:
# Line 789  while (cc < ccend) Line 757  while (cc < ccend)
757      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
758      break;      break;
759    
     case OP_ASSERT:  
     case OP_ASSERT_NOT:  
     case OP_ASSERTBACK:  
     case OP_ASSERTBACK_NOT:  
     case OP_ONCE:  
     case OP_ONCE_NC:  
     case OP_BRAPOS:  
     case OP_SBRA:  
     case OP_SBRAPOS:  
     private_data_length += sizeof(sljit_w);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
760      case OP_CBRAPOS:      case OP_CBRAPOS:
761      case OP_SCBRAPOS:      case OP_SCBRAPOS:
     private_data_length += sizeof(sljit_w);  
762      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
763      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
764      break;      break;
765    
766      case OP_COND:      case OP_COND:
767      case OP_SCOND:      case OP_SCOND:
768      bracketlen = cc[1 + LINK_SIZE];      /* Only AUTO_CALLOUT can insert this opcode. We do
769      if (bracketlen == OP_CREF)         not intend to support this case. */
770        {      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
771        bracketlen = GET2(cc, 1 + LINK_SIZE + 1);        return FALSE;
772        common->optimized_cbracket[bracketlen] = 0;      cc += 1 + LINK_SIZE;
       }  
     else if (bracketlen == OP_NCREF)  
       {  
       bracketlen = GET2(cc, 1 + LINK_SIZE + 1);  
       name = (pcre_uchar *)common->name_table;  
       alternative = name;  
       for (i = 0; i < common->name_count; i++)  
         {  
         if (GET2(name, 0) == bracketlen) break;  
         name += common->name_entry_size;  
         }  
       SLJIT_ASSERT(i != common->name_count);  
   
       for (i = 0; i < common->name_count; i++)  
         {  
         if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)  
           common->optimized_cbracket[GET2(alternative, 0)] = 0;  
         alternative += common->name_entry_size;  
         }  
       }  
   
     if (*cc == OP_COND)  
       {  
       /* Might be a hidden SCOND. */  
       alternative = cc + GET(cc, 1);  
       if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)  
         private_data_length += sizeof(sljit_w);  
       }  
     else  
       private_data_length += sizeof(sljit_w);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_BRA:  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_CBRA:  
     case OP_SCBRA:  
     bracketlen = 1 + LINK_SIZE + IMM2_SIZE;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_1  
     space = 1;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_2A  
     space = 2;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_2B  
     space = 2;  
     size = -(2 + IMM2_SIZE);  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_1  
     space = 1;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_2A  
     if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)  
       space = 2;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_2B  
     if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)  
       space = 2;  
     size = 1 + IMM2_SIZE;  
773      break;      break;
774    
775      case OP_CLASS:      case OP_CREF:
776      case OP_NCLASS:      i = GET2(cc, 1);
777      size += 1 + 32 / sizeof(pcre_uchar);      common->optimized_cbracket[i] = 0;
778      space = get_class_iterator_size(cc + size);      cc += 1 + IMM2_SIZE;
779      break;      break;
780    
781  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8      case OP_NCREF:
782      case OP_XCLASS:      cbra_index = GET2(cc, 1);
783      size = GET(cc, 1);      name = (pcre_uchar *)common->name_table;
784      space = get_class_iterator_size(cc + size);      name2 = name;
785        for (i = 0; i < common->name_count; i++)
786          {
787          if (GET2(name, 0) == cbra_index) break;
788          name += common->name_entry_size;
789          }
790        SLJIT_ASSERT(i != common->name_count);
791    
792        for (i = 0; i < common->name_count; i++)
793          {
794          if (STRCMP_UC_UC(name2 + IMM2_SIZE, name + IMM2_SIZE) == 0)
795            common->optimized_cbracket[GET2(name2, 0)] = 0;
796          name2 += common->name_entry_size;
797          }
798        cc += 1 + IMM2_SIZE;
799      break;      break;
 #endif  
800    
801      case OP_RECURSE:      case OP_RECURSE:
802      /* Set its value only once. */      /* Set its value only once. */
803      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
804        {        {
805        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
806        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
807        }        }
808      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
809      break;      break;
810    
811        case OP_CALLOUT:
812        if (common->capture_last_ptr == 0)
813          {
814          common->capture_last_ptr = common->ovector_start;
815          common->ovector_start += sizeof(sljit_sw);
816          }
817        cc += 2 + 2 * LINK_SIZE;
818        break;
819    
820        case OP_THEN_ARG:
821        common->has_then = TRUE;
822        common->control_head_ptr = 1;
823        /* Fall through. */
824    
825        case OP_PRUNE_ARG:
826        common->needs_start_ptr = TRUE;
827        /* Fall through. */
828    
829      case OP_MARK:      case OP_MARK:
830      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
831        {        {
832        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
833        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
834        }        }
835      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
836      break;      break;
837    
838        case OP_THEN:
839        common->has_then = TRUE;
840        common->control_head_ptr = 1;
841        /* Fall through. */
842    
843        case OP_PRUNE:
844        case OP_SKIP:
845        common->needs_start_ptr = TRUE;
846        cc += 1;
847        break;
848    
849        case OP_SKIP_ARG:
850        common->control_head_ptr = 1;
851        common->has_skip_arg = TRUE;
852        cc += 1 + 2 + cc[1];
853        break;
854    
855      default:      default:
856      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
857      if (cc == NULL)      if (cc == NULL)
858        return -1;        return FALSE;
859      break;      break;
860      }      }
861      }
862    return TRUE;
863    }
864    
865    if (space > 0 && cc >= end)  static int get_class_iterator_size(pcre_uchar *cc)
866      private_data_length += sizeof(sljit_w) * space;  {
867    switch(*cc)
868      {
869      case OP_CRSTAR:
870      case OP_CRPLUS:
871      return 2;
872    
873    if (size != 0)    case OP_CRMINSTAR:
874      case OP_CRMINPLUS:
875      case OP_CRQUERY:
876      case OP_CRMINQUERY:
877      return 1;
878    
879      case OP_CRRANGE:
880      case OP_CRMINRANGE:
881      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
882        return 0;
883      return 2;
884    
885      default:
886      return 0;
887      }
888    }
889    
890    static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
891    {
892    pcre_uchar *end = bracketend(begin);
893    pcre_uchar *next;
894    pcre_uchar *next_end;
895    pcre_uchar *max_end;
896    pcre_uchar type;
897    sljit_sw length = end - begin;
898    int min, max, i;
899    
900    /* Detect fixed iterations first. */
901    if (end[-(1 + LINK_SIZE)] != OP_KET)
902      return FALSE;
903    
904    /* Already detected repeat. */
905    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
906      return TRUE;
907    
908    next = end;
909    min = 1;
910    while (1)
911      {
912      if (*next != *begin)
913        break;
914      next_end = bracketend(next);
915      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
916        break;
917      next = next_end;
918      min++;
919      }
920    
921    if (min == 2)
922      return FALSE;
923    
924    max = 0;
925    max_end = next;
926    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
927      {
928      type = *next;
929      while (1)
930      {      {
931      if (size < 0)      if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
932        {        break;
933        cc += -size;      next_end = bracketend(next + 2 + LINK_SIZE);
934  #ifdef SUPPORT_UTF      if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
935        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        break;
936  #endif      next = next_end;
937        }      max++;
     else  
       cc += size;  
938      }      }
939    
940    if (bracketlen != 0)    if (next[0] == type && next[1] == *begin && max >= 1)
941      {      {
942      if (cc >= end)      next_end = bracketend(next + 1);
943        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
944        {        {
945        end = bracketend(cc);        for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
946        if (end[-1 - LINK_SIZE] == OP_KET)          if (*next_end != OP_KET)
947          end = NULL;            break;
948    
949          if (i == max)
950            {
951            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
952            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
953            /* +2 the original and the last. */
954            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
955            if (min == 1)
956              return TRUE;
957            min--;
958            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
959            }
960        }        }
     cc += bracketlen;  
961      }      }
962    }    }
963  return private_data_length;  
964    if (min >= 3)
965      {
966      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
967      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
968      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
969      return TRUE;
970      }
971    
972    return FALSE;
973  }  }
974    
975  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
976        case OP_MINSTAR: \
977        case OP_MINPLUS: \
978        case OP_QUERY: \
979        case OP_MINQUERY: \
980        case OP_MINSTARI: \
981        case OP_MINPLUSI: \
982        case OP_QUERYI: \
983        case OP_MINQUERYI: \
984        case OP_NOTMINSTAR: \
985        case OP_NOTMINPLUS: \
986        case OP_NOTQUERY: \
987        case OP_NOTMINQUERY: \
988        case OP_NOTMINSTARI: \
989        case OP_NOTMINPLUSI: \
990        case OP_NOTQUERYI: \
991        case OP_NOTMINQUERYI:
992    
993    #define CASE_ITERATOR_PRIVATE_DATA_2A \
994        case OP_STAR: \
995        case OP_PLUS: \
996        case OP_STARI: \
997        case OP_PLUSI: \
998        case OP_NOTSTAR: \
999        case OP_NOTPLUS: \
1000        case OP_NOTSTARI: \
1001        case OP_NOTPLUSI:
1002    
1003    #define CASE_ITERATOR_PRIVATE_DATA_2B \
1004        case OP_UPTO: \
1005        case OP_MINUPTO: \
1006        case OP_UPTOI: \
1007        case OP_MINUPTOI: \
1008        case OP_NOTUPTO: \
1009        case OP_NOTMINUPTO: \
1010        case OP_NOTUPTOI: \
1011        case OP_NOTMINUPTOI:
1012    
1013    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1014        case OP_TYPEMINSTAR: \
1015        case OP_TYPEMINPLUS: \
1016        case OP_TYPEQUERY: \
1017        case OP_TYPEMINQUERY:
1018    
1019    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1020        case OP_TYPESTAR: \
1021        case OP_TYPEPLUS:
1022    
1023    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1024        case OP_TYPEUPTO: \
1025        case OP_TYPEMINUPTO:
1026    
1027    static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1028  {  {
1029  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1030  pcre_uchar *alternative;  pcre_uchar *alternative;
1031  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1032    int private_data_ptr = *private_data_start;
1033  int space, size, bracketlen;  int space, size, bracketlen;
1034    
1035  while (cc < ccend)  while (cc < ccend)
# Line 971  while (cc < ccend) Line 1037  while (cc < ccend)
1037    space = 0;    space = 0;
1038    size = 0;    size = 0;
1039    bracketlen = 0;    bracketlen = 0;
1040      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1041        return;
1042    
1043      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1044        if (detect_repeat(common, cc))
1045          {
1046          /* These brackets are converted to repeats, so no global
1047          based single character repeat is allowed. */
1048          if (cc >= end)
1049            end = bracketend(cc);
1050          }
1051    
1052    switch(*cc)    switch(*cc)
1053      {      {
1054        case OP_KET:
1055        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1056          {
1057          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1058          private_data_ptr += sizeof(sljit_sw);
1059          cc += common->private_data_ptrs[cc + 1 - common->start];
1060          }
1061        cc += 1 + LINK_SIZE;
1062        break;
1063    
1064      case OP_ASSERT:      case OP_ASSERT:
1065      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1066      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 984  while (cc < ccend) Line 1072  while (cc < ccend)
1072      case OP_SBRAPOS:      case OP_SBRAPOS:
1073      case OP_SCOND:      case OP_SCOND:
1074      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1075      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1076      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1077      break;      break;
1078    
1079      case OP_CBRAPOS:      case OP_CBRAPOS:
1080      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1081      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1082      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1083      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1084      break;      break;
1085    
# Line 1001  while (cc < ccend) Line 1089  while (cc < ccend)
1089      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1090        {        {
1091        common->private_data_ptrs[cc - common->start] = private_data_ptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1092        private_data_ptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1093        }        }
1094      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1095      break;      break;
# Line 1066  while (cc < ccend) Line 1154  while (cc < ccend)
1154      break;      break;
1155      }      }
1156    
1157      /* Character iterators, which are not inside a repeated bracket,
1158         gets a private slot instead of allocating it on the stack. */
1159    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1160      {      {
1161      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1162      private_data_ptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1163      }      }
1164    
1165    if (size != 0)    if (size != 0)
# Line 1096  while (cc < ccend) Line 1186  while (cc < ccend)
1186      cc += bracketlen;      cc += bracketlen;
1187      }      }
1188    }    }
1189    *private_data_start = private_data_ptr;
1190  }  }
1191    
1192  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1193  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL* needs_control_head)
1194  {  {
 pcre_uchar *ccend = bracketend(cc);  
1195  int length = 0;  int length = 0;
1196  BOOL possessive = FALSE;  int possessive = 0;
1197    BOOL stack_restore = FALSE;
1198  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1199  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1200    /* The last capture is a local variable even for recursions. */
1201    BOOL capture_last_found = FALSE;
1202    
1203  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1204    SLJIT_ASSERT(common->control_head_ptr != 0);
1205    *needs_control_head = TRUE;
1206    #else
1207    *needs_control_head = FALSE;
1208    #endif
1209    
1210    if (ccend == NULL)
1211    {    {
1212    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1213    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1214        {
1215        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1216        /* This is correct regardless of common->capture_last_ptr. */
1217        capture_last_found = TRUE;
1218        }
1219      cc = next_opcode(common, cc);
1220    }    }
1221    
 cc = next_opcode(common, cc);  
1222  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1223  while (cc < ccend)  while (cc < ccend)
1224    switch(*cc)    switch(*cc)
1225      {      {
1226      case OP_SET_SOM:      case OP_SET_SOM:
1227      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1228        stack_restore = TRUE;
1229      if (!setsom_found)      if (!setsom_found)
1230        {        {
1231        length += 2;        length += 2;
# Line 1129  while (cc < ccend) Line 1235  while (cc < ccend)
1235      break;      break;
1236    
1237      case OP_MARK:      case OP_MARK:
1238        case OP_PRUNE_ARG:
1239        case OP_THEN_ARG:
1240      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1241        stack_restore = TRUE;
1242      if (!setmark_found)      if (!setmark_found)
1243        {        {
1244        length += 2;        length += 2;
1245        setmark_found = TRUE;        setmark_found = TRUE;
1246        }        }
1247        if (common->control_head_ptr != 0)
1248          *needs_control_head = TRUE;
1249      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1250      break;      break;
1251    
1252      case OP_RECURSE:      case OP_RECURSE:
1253        stack_restore = TRUE;
1254      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1255        {        {
1256        length += 2;        length += 2;
# Line 1149  while (cc < ccend) Line 1261  while (cc < ccend)
1261        length += 2;        length += 2;
1262        setmark_found = TRUE;        setmark_found = TRUE;
1263        }        }
1264        if (common->capture_last_ptr != 0 && !capture_last_found)
1265          {
1266          length += 2;
1267          capture_last_found = TRUE;
1268          }
1269      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1270      break;      break;
1271    
# Line 1156  while (cc < ccend) Line 1273  while (cc < ccend)
1273      case OP_CBRAPOS:      case OP_CBRAPOS:
1274      case OP_SCBRA:      case OP_SCBRA:
1275      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1276        stack_restore = TRUE;
1277        if (common->capture_last_ptr != 0 && !capture_last_found)
1278          {
1279          length += 2;
1280          capture_last_found = TRUE;
1281          }
1282      length += 3;      length += 3;
1283      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1284      break;      break;
1285    
1286      default:      default:
1287        stack_restore = TRUE;
1288        /* Fall through. */
1289    
1290        case OP_NOT_WORD_BOUNDARY:
1291        case OP_WORD_BOUNDARY:
1292        case OP_NOT_DIGIT:
1293        case OP_DIGIT:
1294        case OP_NOT_WHITESPACE:
1295        case OP_WHITESPACE:
1296        case OP_NOT_WORDCHAR:
1297        case OP_WORDCHAR:
1298        case OP_ANY:
1299        case OP_ALLANY:
1300        case OP_ANYBYTE:
1301        case OP_NOTPROP:
1302        case OP_PROP:
1303        case OP_ANYNL:
1304        case OP_NOT_HSPACE:
1305        case OP_HSPACE:
1306        case OP_NOT_VSPACE:
1307        case OP_VSPACE:
1308        case OP_EXTUNI:
1309        case OP_EODN:
1310        case OP_EOD:
1311        case OP_CIRC:
1312        case OP_CIRCM:
1313        case OP_DOLL:
1314        case OP_DOLLM:
1315        case OP_CHAR:
1316        case OP_CHARI:
1317        case OP_NOT:
1318        case OP_NOTI:
1319    
1320        case OP_EXACT:
1321        case OP_POSSTAR:
1322        case OP_POSPLUS:
1323        case OP_POSQUERY:
1324        case OP_POSUPTO:
1325    
1326        case OP_EXACTI:
1327        case OP_POSSTARI:
1328        case OP_POSPLUSI:
1329        case OP_POSQUERYI:
1330        case OP_POSUPTOI:
1331    
1332        case OP_NOTEXACT:
1333        case OP_NOTPOSSTAR:
1334        case OP_NOTPOSPLUS:
1335        case OP_NOTPOSQUERY:
1336        case OP_NOTPOSUPTO:
1337    
1338        case OP_NOTEXACTI:
1339        case OP_NOTPOSSTARI:
1340        case OP_NOTPOSPLUSI:
1341        case OP_NOTPOSQUERYI:
1342        case OP_NOTPOSUPTOI:
1343    
1344        case OP_TYPEEXACT:
1345        case OP_TYPEPOSSTAR:
1346        case OP_TYPEPOSPLUS:
1347        case OP_TYPEPOSQUERY:
1348        case OP_TYPEPOSUPTO:
1349    
1350        case OP_CLASS:
1351        case OP_NCLASS:
1352        case OP_XCLASS:
1353    
1354      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1355      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1356      break;      break;
1357      }      }
1358    
1359  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1360  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1361    return -1;    return stack_restore ? no_frame : no_stack;
1362    
1363  if (length > 0)  if (length > 0)
1364    return length + 1;    return length + 1;
1365  return -1;  return stack_restore ? no_frame : no_stack;
1366  }  }
1367    
1368  static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive)  static void init_frame(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, int stackpos, int stacktop, BOOL recursive)
1369  {  {
1370  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1371  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1372  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1373    /* The last capture is a local variable even for recursions. */
1374    BOOL capture_last_found = FALSE;
1375  int offset;  int offset;
1376    
1377  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1188  SLJIT_UNUSED_ARG(stacktop); Line 1379  SLJIT_UNUSED_ARG(stacktop);
1379  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1380    
1381  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1382  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1383    cc = next_opcode(common, cc);    {
1384      ccend = bracketend(cc) - (1 + LINK_SIZE);
1385      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1386        cc = next_opcode(common, cc);
1387      }
1388    
1389  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1390  while (cc < ccend)  while (cc < ccend)
1391    switch(*cc)    switch(*cc)
# Line 1199  while (cc < ccend) Line 1395  while (cc < ccend)
1395      if (!setsom_found)      if (!setsom_found)
1396        {        {
1397        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1398        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1399        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1400        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1401        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1402        setsom_found = TRUE;        setsom_found = TRUE;
1403        }        }
1404      cc += 1;      cc += 1;
1405      break;      break;
1406    
1407      case OP_MARK:      case OP_MARK:
1408        case OP_PRUNE_ARG:
1409        case OP_THEN_ARG:
1410      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1411      if (!setmark_found)      if (!setmark_found)
1412        {        {
1413        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);
1414        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);
1415        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1416        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1417        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1418        setmark_found = TRUE;        setmark_found = TRUE;
1419        }        }
1420      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 1226  while (cc < ccend) Line 1424  while (cc < ccend)
1424      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1425        {        {
1426        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1427        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1428        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1429        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1430        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1431        setsom_found = TRUE;        setsom_found = TRUE;
1432        }        }
1433      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1434        {        {
1435        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);
1436        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);
1437        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1438        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1439        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1440        setmark_found = TRUE;        setmark_found = TRUE;
1441        }        }
1442        if (common->capture_last_ptr != 0 && !capture_last_found)
1443          {
1444          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1445          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1446          stackpos += (int)sizeof(sljit_sw);
1447          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1448          stackpos += (int)sizeof(sljit_sw);
1449          capture_last_found = TRUE;
1450          }
1451      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1452      break;      break;
1453    
# Line 1248  while (cc < ccend) Line 1455  while (cc < ccend)
1455      case OP_CBRAPOS:      case OP_CBRAPOS:
1456      case OP_SCBRA:      case OP_SCBRA:
1457      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1458        if (common->capture_last_ptr != 0 && !capture_last_found)
1459          {
1460          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1461          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1462          stackpos += (int)sizeof(sljit_sw);
1463          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1464          stackpos += (int)sizeof(sljit_sw);
1465          capture_last_found = TRUE;
1466          }
1467      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1468      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1469      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1470      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1471      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));
1472      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1473      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1474      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1475      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1476    
1477      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1478      break;      break;
# Line 1267  while (cc < ccend) Line 1483  while (cc < ccend)
1483      break;      break;
1484      }      }
1485    
1486  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1487  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1488  }  }
1489    
1490  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)
1491  {  {
1492  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1493  int size;  int size;
1494  pcre_uchar *alternative;  pcre_uchar *alternative;
1495  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1282  while (cc < ccend) Line 1498  while (cc < ccend)
1498    size = 0;    size = 0;
1499    switch(*cc)    switch(*cc)
1500      {      {
1501        case OP_KET:
1502        if (PRIVATE_DATA(cc) != 0)
1503          private_data_length++;
1504        cc += 1 + LINK_SIZE;
1505        break;
1506    
1507      case OP_ASSERT:      case OP_ASSERT:
1508      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1509      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1386  return private_data_length; Line 1608  return private_data_length;
1608  }  }
1609    
1610  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,
1611    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1612  {  {
1613  DEFINE_COMPILER;  DEFINE_COMPILER;
1614  int srcw[2];  int srcw[2];
# Line 1407  stacktop = STACK(stacktop - 1); Line 1629  stacktop = STACK(stacktop - 1);
1629    
1630  if (!save)  if (!save)
1631    {    {
1632    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1633    if (stackptr < stacktop)    if (stackptr < stacktop)
1634      {      {
1635      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1636      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1637      tmp1empty = FALSE;      tmp1empty = FALSE;
1638      }      }
1639    if (stackptr < stacktop)    if (stackptr < stacktop)
1640      {      {
1641      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1642      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1643      tmp2empty = FALSE;      tmp2empty = FALSE;
1644      }      }
1645    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1646    }    }
1647    
1648  while (status != end)  do
1649    {    {
1650    count = 0;    count = 0;
1651    switch(status)    switch(status)
1652      {      {
1653      case start:      case start:
1654      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1655      count = 1;      count = 1;
1656      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1657        if (needs_control_head)
1658          {
1659          SLJIT_ASSERT(common->control_head_ptr != 0);
1660          count = 2;
1661          srcw[1] = common->control_head_ptr;
1662          }
1663      status = loop;      status = loop;
1664      break;      break;
1665    
# Line 1442  while (status != end) Line 1670  while (status != end)
1670        break;        break;
1671        }        }
1672    
1673      switch(*cc)      switch(*cc)
1674        {        {
1675          case OP_KET:
1676          if (PRIVATE_DATA(cc) != 0)
1677            {
1678            count = 1;
1679            srcw[0] = PRIVATE_DATA(cc);
1680            }
1681          cc += 1 + LINK_SIZE;
1682          break;
1683    
1684        case OP_ASSERT:        case OP_ASSERT:
1685        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1686        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1508  while (status != end) Line 1745  while (status != end)
1745          {          {
1746          count = 2;          count = 2;
1747          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1748          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1749          }          }
1750        cc += 2;        cc += 2;
1751  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1521  while (status != end) Line 1758  while (status != end)
1758          {          {
1759          count = 2;          count = 2;
1760          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1761          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1762          }          }
1763        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1764  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1543  while (status != end) Line 1780  while (status != end)
1780          {          {
1781          count = 2;          count = 2;
1782          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1783          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1784          }          }
1785        cc += 1;        cc += 1;
1786        break;        break;
# Line 1553  while (status != end) Line 1790  while (status != end)
1790          {          {
1791          count = 2;          count = 2;
1792          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1793          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1794          }          }
1795        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1796        break;        break;
# Line 1577  while (status != end) Line 1814  while (status != end)
1814            case 2:            case 2:
1815            count = 2;            count = 2;
1816            srcw[0] = PRIVATE_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1817            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1818            break;            break;
1819    
1820            default:            default:
# Line 1609  while (status != end) Line 1846  while (status != end)
1846          if (!tmp1empty)          if (!tmp1empty)
1847            {            {
1848            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1849            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1850            }            }
1851          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1852          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1620  while (status != end) Line 1857  while (status != end)
1857          if (!tmp2empty)          if (!tmp2empty)
1858            {            {
1859            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1860            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1861            }            }
1862          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1863          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1637  while (status != end) Line 1874  while (status != end)
1874          if (!tmp1empty)          if (!tmp1empty)
1875            {            {
1876            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1877            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1878            }            }
1879          tmp1next = FALSE;          tmp1next = FALSE;
1880          }          }
# Line 1649  while (status != end) Line 1886  while (status != end)
1886          if (!tmp2empty)          if (!tmp2empty)
1887            {            {
1888            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1889            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1890            }            }
1891          tmp1next = TRUE;          tmp1next = TRUE;
1892          }          }
1893        }        }
1894      }      }
1895    }    }
1896    while (status != end);
1897    
1898  if (save)  if (save)
1899    {    {
# Line 1664  if (save) Line 1902  if (save)
1902      if (!tmp1empty)      if (!tmp1empty)
1903        {        {
1904        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1905        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1906        }        }
1907      if (!tmp2empty)      if (!tmp2empty)
1908        {        {
1909        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1910        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1911        }        }
1912      }      }
1913    else    else
# Line 1677  if (save) Line 1915  if (save)
1915      if (!tmp2empty)      if (!tmp2empty)
1916        {        {
1917        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1918        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1919        }        }
1920      if (!tmp1empty)      if (!tmp1empty)
1921        {        {
1922        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1923        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1924        }        }
1925      }      }
1926    }    }
1927  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1928  }  }
1929    
1930    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1931    {
1932    pcre_uchar *end = bracketend(cc);
1933    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1934    
1935    /* Assert captures then. */
1936    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1937      current_offset = NULL;
1938    /* Conditional block does not. */
1939    if (*cc == OP_COND || *cc == OP_SCOND)
1940      has_alternatives = FALSE;
1941    
1942    cc = next_opcode(common, cc);
1943    if (has_alternatives)
1944      current_offset = common->then_offsets + (cc - common->start);
1945    
1946    while (cc < end)
1947      {
1948      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1949        cc = set_then_offsets(common, cc, current_offset);
1950      else
1951        {
1952        if (*cc == OP_ALT && has_alternatives)
1953          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1954        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1955          *current_offset = 1;
1956        cc = next_opcode(common, cc);
1957        }
1958      }
1959    
1960    return end;
1961    }
1962    
1963  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
1964  #undef CASE_ITERATOR_PRIVATE_DATA_2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
1965  #undef CASE_ITERATOR_PRIVATE_DATA_2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
# Line 1707  while (list) Line 1978  while (list)
1978    {    {
1979    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1980    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
1981    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1982    list = list->next;    list = list->next;
1983    }    }
1984  }  }
# Line 1723  if (list_item) Line 1994  if (list_item)
1994    }    }
1995  }  }
1996    
1997  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)
1998  {  {
1999  DEFINE_COMPILER;  DEFINE_COMPILER;
2000  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
2001    
2002  if (list_item)  if (list_item)
2003    {    {
   list_item->type = type;  
   list_item->data = data;  
2004    list_item->start = start;    list_item->start = start;
2005    list_item->quit = LABEL();    list_item->quit = LABEL();
2006    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1747  stub_list* list_item = common->stubs; Line 2016  stub_list* list_item = common->stubs;
2016  while (list_item)  while (list_item)
2017    {    {
2018    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2019    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;  
     }  
2020    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2021    list_item = list_item->next;    list_item = list_item->next;
2022    }    }
2023  common->stubs = NULL;  common->stubs = NULL;
2024  }  }
2025    
2026  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2027  {  {
2028  DEFINE_COMPILER;  DEFINE_COMPILER;
2029    
2030  OP2(SLJIT_SUB | SLJIT_SET_E, CALL_COUNT, 0, CALL_COUNT, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, COUNT_MATCH, 0, COUNT_MATCH, 0, SLJIT_IMM, 1);
2031  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2032  }  }
2033    
# Line 1772  static SLJIT_INLINE void allocate_stack( Line 2036  static SLJIT_INLINE void allocate_stack(
2036  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2037  DEFINE_COMPILER;  DEFINE_COMPILER;
2038    
2039  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));
2040  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2041  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2042  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1780  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 2044  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2044  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2045  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2046  #endif  #endif
2047  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));
2048  }  }
2049    
2050  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2051  {  {
2052  DEFINE_COMPILER;  DEFINE_COMPILER;
2053  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));
2054  }  }
2055    
2056  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1794  static SLJIT_INLINE void reset_ovector(c Line 2058  static SLJIT_INLINE void reset_ovector(c
2058  DEFINE_COMPILER;  DEFINE_COMPILER;
2059  struct sljit_label *loop;  struct sljit_label *loop;
2060  int i;  int i;
2061    
2062  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2063    SLJIT_ASSERT(length > 1);
2064  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2065  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));
2066    if (length < 8)
2067      {
2068      for (i = 1; i < length; i++)
2069        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2070      }
2071    else
2072      {
2073      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2074      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2075      loop = LABEL();
2076      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2077      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2078      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2079      }
2080    }
2081    
2082    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2083    {
2084    DEFINE_COMPILER;
2085    struct sljit_label *loop;
2086    int i;
2087    
2088    SLJIT_ASSERT(length > 1);
2089    /* OVECTOR(1) contains the "string begin - 1" constant. */
2090    if (length > 2)
2091      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2092  if (length < 8)  if (length < 8)
2093    {    {
2094    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
2095      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_TEMPORARY_REG1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), TMP1, 0);
2096    }    }
2097  else  else
2098    {    {
2099    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2100    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2101    loop = LABEL();    loop = LABEL();
2102    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2103    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB | SLJIT_SET_E, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 1);
2104    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2105    }    }
2106    
2107    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2108    if (common->mark_ptr != 0)
2109      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2110    if (common->control_head_ptr != 0)
2111      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2112    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2113    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2114    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2115    }
2116    
2117    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2118    {
2119    while (current != NULL)
2120      {
2121      switch (current[-2])
2122        {
2123        case type_then_trap:
2124        break;
2125    
2126        case type_mark:
2127        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2128          return current[-4];
2129        break;
2130    
2131        default:
2132        SLJIT_ASSERT_STOP();
2133        break;
2134        }
2135      current = (sljit_sw*)current[-1];
2136      }
2137    return -1;
2138  }  }
2139    
2140  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2141  {  {
2142  DEFINE_COMPILER;  DEFINE_COMPILER;
2143  struct sljit_label *loop;  struct sljit_label *loop;
2144  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2145    
2146  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2147  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));
2148  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);
2149    
2150  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2151  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2152    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);
2153  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));
2154  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2155    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);
2156  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));
2157  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));
2158  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2159  /* Unlikely, but possible */  /* Unlikely, but possible */
2160  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);
2161  loop = LABEL();  loop = LABEL();
2162  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);
2163  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));
2164  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2165  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2166  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);
2167  #endif  #endif
2168  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);
2169  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);
2170  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2171  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2172    
2173  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2174  if (topbracket > 1)  if (topbracket > 1)
2175    {    {
2176    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));
2177    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2178    
2179    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2180    loop = LABEL();    loop = LABEL();
2181    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)));
2182    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);
2183    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);
2184    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2185    }    }
2186  else  else
2187    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1866  else Line 2190  else
2190  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)
2191  {  {
2192  DEFINE_COMPILER;  DEFINE_COMPILER;
2193    struct sljit_jump *jump;
2194    
2195  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);
2196  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
2197      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2198    
2199  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2200  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2201  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));
2202  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);
2203    
2204  /* Store match begin and end. */  /* Store match begin and end. */
2205  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));
2206  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));
2207  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);  
2208    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2209    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);
2210    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2211    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2212    #endif
2213    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2214    JUMPHERE(jump);
2215    
2216    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);
2217  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);
2218  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2219  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);
2220  #endif  #endif
2221  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);
2222    
2223  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);
2224  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2225  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);
2226  #endif  #endif
2227  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);
2228    
2229  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2230  }  }
# Line 2054  else if (common->mode == JIT_PARTIAL_SOF Line 2389  else if (common->mode == JIT_PARTIAL_SOF
2389    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);
2390    
2391  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2392    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);
2393  else  else
2394    {    {
2395    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2067  if (jump != NULL) Line 2402  if (jump != NULL)
2402    JUMPHERE(jump);    JUMPHERE(jump);
2403  }  }
2404    
2405  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2406  {  {
2407  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2408  DEFINE_COMPILER;  DEFINE_COMPILER;
2409  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2410    
2411  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2412    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2413      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2414      return;
2415      }
2416    
2417  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2418  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2419    {    {
2420    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));
2421    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);
2422    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2423    }    }
2424  else  else
2425    {    {
2426    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));
2427    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2428      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2429    else    else
2430      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2431    }    }
2432  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2433  }  }
2434    
2435  static void detect_partial_match(compiler_common *common, jump_list **backtracks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
# Line 2114  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR Line 2448  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2448  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));
2449  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2450    {    {
2451    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);
2452    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2453    }    }
2454  else  else
# Line 2205  if (common->utf) Line 2539  if (common->utf)
2539    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2540    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2541    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);
2542    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2543    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2544    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2545  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
# Line 2255  if (common->utf) Line 2589  if (common->utf)
2589    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2590    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2591    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);
2592    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2593    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2594    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2595    return;    return;
# Line 2278  if (nltype == NLTYPE_ANY) Line 2612  if (nltype == NLTYPE_ANY)
2612  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2613    {    {
2614    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);
2615    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2616    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);
2617    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);
2618    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));
2619    }    }
2620  else  else
# Line 2380  sljit_emit_fast_return(compiler, RETURN_ Line 2714  sljit_emit_fast_return(compiler, RETURN_
2714  JUMPHERE(jump);  JUMPHERE(jump);
2715    
2716  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2717  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);
2718  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2719  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2720  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
# Line 2433  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 2767  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2767    
2768  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2769  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2770  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));
2771  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2772  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2773  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2774  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2775  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2776  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));
2777  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2778  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2779  }  }
# Line 2508  if (newlinecheck) Line 2842  if (newlinecheck)
2842    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2843    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2844    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);
2845    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2846  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2847    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2848  #endif  #endif
# Line 2536  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S Line 2870  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S
2870  if (common->utf)  if (common->utf)
2871    {    {
2872    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2873    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);
2874    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2875    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2876    }    }
# Line 2546  if (common->utf) Line 2880  if (common->utf)
2880    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2881    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2882    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);
2883    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2884    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2885    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2886    JUMPHERE(singlechar);    JUMPHERE(singlechar);
# Line 2572  DEFINE_COMPILER; Line 2906  DEFINE_COMPILER;
2906  struct sljit_label *start;  struct sljit_label *start;
2907  struct sljit_jump *quit;  struct sljit_jump *quit;
2908  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uint32 chars[MAX_N_CHARS * 2];
2909  pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  pcre_uchar *cc = common->start + 1 + LINK_SIZE;
2910  int location = 0;  int location = 0;
2911  pcre_int32 len, c, bit, caseless;  pcre_int32 len, c, bit, caseless;
2912  int must_stop;  int must_stop;
# Line 2695  if (firstline) Line 3029  if (firstline)
3029    {    {
3030    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3031    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3032    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));
3033    }    }
3034  else  else
3035    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));
3036    
3037  start = LABEL();  start = LABEL();
3038  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 2727  JUMPHERE(quit); Line 3061  JUMPHERE(quit);
3061  if (firstline)  if (firstline)
3062    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3063  else  else
3064    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));
3065  return TRUE;  return TRUE;
3066  }  }
3067    
# Line 2774  else Line 3108  else
3108    else    else
3109      {      {
3110      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);
3111      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3112      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);
3113      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);
3114      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3115      }      }
3116    }    }
# Line 2818  if (common->nltype == NLTYPE_FIXED && co Line 3152  if (common->nltype == NLTYPE_FIXED && co
3152    
3153    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3154    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);
3155    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3156  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3157    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3158  #endif  #endif
# Line 2861  if (common->nltype == NLTYPE_ANY || comm Line 3195  if (common->nltype == NLTYPE_ANY || comm
3195    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3196    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3197    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);
3198    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3199  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3200    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3201  #endif  #endif
# Line 2876  if (firstline) Line 3210  if (firstline)
3210    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3211  }  }
3212    
3213    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3214    
3215  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)
3216  {  {
3217  DEFINE_COMPILER;  DEFINE_COMPILER;
3218  struct sljit_label *start;  struct sljit_label *start;
3219  struct sljit_jump *quit;  struct sljit_jump *quit;
3220  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3221    jump_list *matches = NULL;
3222    pcre_uint8 inverted_start_bits[32];
3223    int i;
3224  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3225  struct sljit_jump *jump;  struct sljit_jump *jump;
3226  #endif  #endif
3227    
3228    for (i = 0; i < 32; ++i)
3229      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3230    
3231  if (firstline)  if (firstline)
3232    {    {
3233    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
# Line 2900  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 3242  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3242  if (common->utf)  if (common->utf)
3243    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3244  #endif  #endif
3245    
3246    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3247      {
3248  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3249  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3250  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3251  JUMPHERE(jump);    JUMPHERE(jump);
3252  #endif  #endif
3253  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3254  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3255  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3256  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3257  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);
3258  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3259      }
3260    
3261  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3262  if (common->utf)  if (common->utf)
# Line 2922  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S Line 3268  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S
3268  if (common->utf)  if (common->utf)
3269    {    {
3270    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3271    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);
3272    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3273    }    }
3274  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
# Line 2931  if (common->utf) Line 3277  if (common->utf)
3277    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3278    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3279    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);
3280    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3281    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3282    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3283    }    }
3284  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE[8|16] */
3285  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3286  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3287  JUMPHERE(found);  if (found != NULL)
3288      JUMPHERE(found);
3289    if (matches != NULL)
3290      set_jumps(matches, LABEL());
3291  JUMPHERE(quit);  JUMPHERE(quit);
3292    
3293  if (firstline)  if (firstline)
# Line 3021  GET_LOCAL_BASE(TMP3, 0, 0); Line 3370  GET_LOCAL_BASE(TMP3, 0, 0);
3370  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3371  mainloop = LABEL();  mainloop = LABEL();
3372  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3373  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);
3374    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3375    
3376  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3377  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));
3378  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));
3379  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));
3380  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3381    
3382  JUMPHERE(jump);  JUMPHERE(jump);
3383  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3384  /* End of dropping frames. */  /* End of dropping frames. */
3385  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3386    
3387  JUMPHERE(jump);  JUMPHERE(jump);
3388  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3389  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3390  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3391  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));  
3392  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3393  }  }
3394    
# Line 3062  static void check_wordboundary(compiler_ Line 3396  static void check_wordboundary(compiler_
3396  {  {
3397  DEFINE_COMPILER;  DEFINE_COMPILER;
3398  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3399    jump_list *skipread_list = NULL;
3400  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3401  struct sljit_jump *jump;  struct sljit_jump *jump;
3402  #endif  #endif
# Line 3087  if (common->use_ucp) Line 3422  if (common->use_ucp)
3422    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3423    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3424    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);
3425    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3426    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);
3427    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);
3428    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3429    JUMPHERE(jump);    JUMPHERE(jump);
3430    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3431    }    }
# Line 3119  else Line 3454  else
3454  JUMPHERE(skipread);  JUMPHERE(skipread);
3455    
3456  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3457  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3458  peek_char(common);  peek_char(common);
3459    
3460  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 3131  if (common->use_ucp) Line 3466  if (common->use_ucp)
3466    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3467    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3468    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);
3469    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3470    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);
3471    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);
3472    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3473    JUMPHERE(jump);    JUMPHERE(jump);
3474    }    }
3475  else  else
# Line 3160  else Line 3495  else
3495      JUMPHERE(jump);      JUMPHERE(jump);
3496  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3497    }    }
3498  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3499    
3500  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);
3501  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
# Line 3314  sljit_emit_fast_enter(compiler, RETURN_A Line 3649  sljit_emit_fast_enter(compiler, RETURN_A
3649    
3650  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3651  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);
3652  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3653  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);
3654  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3655  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3656  if (common->utf)  if (common->utf)
3657    {    {
3658  #endif  #endif
3659    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3660    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3661    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);
3662  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3663    }    }
3664  #endif  #endif
3665  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3666  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);
3667  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3668  }  }
3669    
# Line 3340  DEFINE_COMPILER; Line 3675  DEFINE_COMPILER;
3675  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3676    
3677  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);
3678  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3679  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);
3680  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3681  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);
3682  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3683  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3684  if (common->utf)  if (common->utf)
3685    {    {
3686  #endif  #endif
3687    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3688    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);
3689    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3690    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);
3691    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3692    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3693    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);
3694    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3695    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);
3696    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3697    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);
3698    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3699    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);
3700  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3701    }    }
3702  #endif  #endif
3703  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3704  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);
3705    
3706  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3707  }  }
# Line 3380  sljit_emit_fast_enter(compiler, RETURN_A Line 3715  sljit_emit_fast_enter(compiler, RETURN_A
3715    
3716  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3717  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);
3718  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3719  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);
3720  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3721  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3722  if (common->utf)  if (common->utf)
3723    {    {
3724  #endif  #endif
3725    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);
3726    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3727    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);
3728  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3729    }    }
3730  #endif  #endif
3731  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3732  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);
3733    
3734  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3735  }  }
# Line 3480  sljit_emit_fast_return(compiler, RETURN_ Line 3815  sljit_emit_fast_return(compiler, RETURN_
3815    
3816  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3817    
3818  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)
3819  {  {
3820  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3821  pcre_uint32 c1, c2;  pcre_uint32 c1, c2;
# Line 3531  if (caseless && char_has_othercase(commo Line 3866  if (caseless && char_has_othercase(commo
3866    othercasebit &= 0xff;    othercasebit &= 0xff;
3867  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3868    /* Note that this code only handles characters in the BMP. If there    /* Note that this code only handles characters in the BMP. If there
3869    ever are characters outside the BMP whose othercase differs in only one    ever are characters outside the BMP whose othercase differs in only one
3870    bit from itself (there currently are none), this code will need to be    bit from itself (there currently are none), this code will need to be
3871    revised for COMPILE_PCRE32. */    revised for COMPILE_PCRE32. */
3872    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
# Line 3576  do Line 3911  do
3911  #endif  #endif
3912    
3913    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3914  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3915    
3916    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3917    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3593  do Line 3928  do
3928    
3929  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
3930    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))
3931  #elif defined COMPILE_PCRE16  #else
3932    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 */)  
3933  #endif  #endif
3934      {      {
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
3935      if (context->length >= 4)      if (context->length >= 4)
3936        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  
3937      else if (context->length >= 2)      else if (context->length >= 2)
3938        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);
3939    #if defined COMPILE_PCRE8
3940      else if (context->length >= 1)      else if (context->length >= 1)
3941        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);
3942  #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] */  
3943      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3944    
3945      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3624  do Line 3950  do
3950        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));
3951        break;        break;
3952    
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
3953        case 2 / sizeof(pcre_uchar):        case 2 / sizeof(pcre_uchar):
3954        if (context->oc.asushort != 0)        if (context->oc.asushort != 0)
3955          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 3639  do Line 3964  do
3964        break;        break;
3965  #endif  #endif
3966    
 #endif /* COMPILE_PCRE[8|16] */  
   
3967        default:        default:
3968        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
3969        break;        break;
# Line 3650  do Line 3973  do
3973    
3974  #else  #else
3975    
3976    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3977    if (context->length > 0)    if (context->length >= 1)
3978      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3979    
3980    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
# Line 3734  if ((*cc++ & XCL_MAP) != 0) Line 4057  if ((*cc++ & XCL_MAP) != 0)
4057      {      {
4058      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4059      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4060      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4061      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4062      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);
4063      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
# Line 3812  while (*cc != XCL_END) Line 4135  while (*cc != XCL_END)
4135        break;        break;
4136    
4137        case PT_CLIST:        case PT_CLIST:
4138          case PT_UCNC:
4139        needschar = TRUE;        needschar = TRUE;
4140        break;        break;
4141    
# Line 3851  if (needstype || needsscript) Line 4175  if (needstype || needsscript)
4175      {      {
4176      if (scriptreg == TMP1)      if (scriptreg == TMP1)
4177        {        {
4178        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));
4179        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
4180        }        }
4181      else      else
4182        {        {
4183        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
4184        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));
4185        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
4186        }        }
4187      }      }
# Line 3893  while (*cc != XCL_END) Line 4217  while (*cc != XCL_END)
4217      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4218        {        {
4219        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);
4220        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);
4221        numberofcmps++;        numberofcmps++;
4222        }        }
4223      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4224        {        {
4225        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);
4226        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);
4227        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4228        numberofcmps = 0;        numberofcmps = 0;
4229        }        }
# Line 3932  while (*cc != XCL_END) Line 4256  while (*cc != XCL_END)
4256      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4257        {        {
4258        OP2(SLJIT_SUB | SLJIT_SET_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);
4259        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);
4260        numberofcmps++;        numberofcmps++;
4261        }        }
4262      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4263        {        {
4264        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);
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        numberofcmps = 0;        numberofcmps = 0;
4268        }        }
# Line 3969  while (*cc != XCL_END) Line 4293  while (*cc != XCL_END)
4293    
4294        case PT_LAMP:        case PT_LAMP:
4295        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);
4296        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4297        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);
4298        COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4299        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);
4300        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);
4301        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4302        break;        break;
4303    
# Line 4000  while (*cc != XCL_END) Line 4324  while (*cc != XCL_END)
4324          }          }
4325        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4326        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);
4327        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4328        if (*cc == PT_SPACE)        if (*cc == PT_SPACE)
4329          JUMPHERE(jump);          JUMPHERE(jump);
4330    
4331        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4332        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);
4333        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);
4334        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4335        break;        break;
4336    
4337        case PT_WORD:        case PT_WORD:
4338        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);
4339        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4340        /* ... fall through */        /* Fall through. */
4341    
4342        case PT_ALNUM:        case PT_ALNUM:
4343        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
4344        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);
4345        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);
4346        SET_TYPE_OFFSET(ucp_Nd);        SET_TYPE_OFFSET(ucp_Nd);
4347        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);
4348        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);
4349        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4350        break;        break;
4351    
# Line 4040  while (*cc != XCL_END) Line 4364  while (*cc != XCL_END)
4364            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]);
4365          else          else
4366            {            {
4367            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_w)charoffset);            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4368            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]);
4369            }            }
4370          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]);
4371          COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4372          other_cases += 2;          other_cases += 2;
4373          }          }
4374        else if (is_powerof2(other_cases[2] ^ other_cases[1]))        else if (is_powerof2(other_cases[2] ^ other_cases[1]))
# Line 4053  while (*cc != XCL_END) Line 4377  while (*cc != XCL_END)
4377            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]);
4378          else          else
4379            {            {
4380            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_w)charoffset);            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4381            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]);
4382            }            }
4383          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]);
4384          COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4385    
4386          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);
4387          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);
4388    
4389          other_cases += 3;          other_cases += 3;
4390          }          }
4391        else        else
4392          {          {
4393          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);
4394          COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4395          }          }
4396    
4397        while (*other_cases != NOTACHAR)        while (*other_cases != NOTACHAR)
4398          {          {
4399          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);
4400          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);
4401          }          }
4402        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4403        break;        break;
4404    
4405          case PT_UCNC:
4406          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);
4407          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4408          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);
4409          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4410          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);
4411          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4412    
4413          SET_CHAR_OFFSET(0xa0);
4414          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);
4415          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4416          SET_CHAR_OFFSET(0);
4417          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
4418          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4419          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4420          break;
4421        }        }
4422      cc += 2;      cc += 2;
4423      }      }
# Line 4102  int length; Line 4443  int length;
4443  unsigned int c, oc, bit;  unsigned int c, oc, bit;
4444  compare_context context;  compare_context context;
4445  struct sljit_jump *jump[4];  struct sljit_jump *jump[4];
4446    jump_list *end_list;
4447  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4448  struct sljit_label *label;  struct sljit_label *label;
4449  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4170  switch(type) Line 4512  switch(type)
4512    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4513      {      {
4514      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);
4515        end_list = NULL;
4516      if (common->mode != JIT_PARTIAL_HARD_COMPILE)      if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4517        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));
4518      else      else
4519        jump[1] = check_str_end(common);        check_str_end(common, &end_list);
4520    
4521      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4522      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));
4523      if (jump[1] != NULL)      set_jumps(end_list, LABEL());
       JUMPHERE(jump[1]);  
4524      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4525      }      }
4526    else    else
# Line 4195  switch(type) Line 4537  switch(type)
4537  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16
4538  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
4539      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4540      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);
4541      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4542  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
4543      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
4544      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
4545      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);
4546      COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4547      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4548      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4549  #endif  #endif
# Line 4237  switch(type) Line 4579  switch(type)
4579    read_char(common);    read_char(common);
4580    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);
4581    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
4582      end_list = NULL;
4583    if (common->mode != JIT_PARTIAL_HARD_COMPILE)    if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4584      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));
4585    else    else
4586      jump[1] = check_str_end(common);      check_str_end(common, &end_list);
4587    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4588    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);
4589    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));
4590    jump[3] = JUMP(SLJIT_JUMP);    jump[2] = JUMP(SLJIT_JUMP);
4591    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4592    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);
4593      set_jumps(end_list, LABEL());
4594    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
4595    JUMPHERE(jump[2]);    JUMPHERE(jump[2]);
   JUMPHERE(jump[3]);  
4596    return cc;    return cc;
4597    
4598    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
# Line 4273  switch(type) Line 4616  switch(type)
4616    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4617    read_char(common);    read_char(common);
4618    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4619    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));
4620    /* Optimize register allocation: use a real register. */    /* Optimize register allocation: use a real register. */
4621    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
4622    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 4283  switch(type) Line 4626  switch(type)
4626    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
4627    read_char(common);    read_char(common);
4628    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4629    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));
4630    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4631    
4632    OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);    OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);
4633    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));
4634    OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);    OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);
4635    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4636    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 4320  switch(type) Line 4663  switch(type)
4663        {        {
4664        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);
4665        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);
4666        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS);
4667        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);
4668        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);
4669        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));
4670        check_partial(common, TRUE);        check_partial(common, TRUE);
4671        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
# Line 4509  switch(type) Line 4852  switch(type)
4852      return cc + length;      return cc + length;
4853      }      }
4854    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);
4855    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4856    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);
4857    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);
4858    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
4859    return cc + length;    return cc + length;
4860    
# Line 4538  switch(type) Line 4881  switch(type)
4881        /* Skip the variable-length character. */        /* Skip the variable-length character. */
4882        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));
4883        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4884        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);
4885        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4886        JUMPHERE(jump[0]);        JUMPHERE(jump[0]);
4887        return cc + 1;        return cc + 1;
# Line 4601  switch(type) Line 4944  switch(type)
4944  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4945    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4946    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4947    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4948    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4949    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);
4950    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 4725  if (!common->jscript_compat) Line 5068  if (!common->jscript_compat)
5068      {      {
5069      /* OVECTOR(1) contains the "string begin - 1" constant. */      /* OVECTOR(1) contains the "string begin - 1" constant. */
5070      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));
5071      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
5072      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));
5073      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);
5074      return JUMP(SLJIT_C_NOT_ZERO);      return JUMP(SLJIT_C_NOT_ZERO);
5075      }      }
5076    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 4783  if (withchecks && !common->jscript_compa Line 5126  if (withchecks && !common->jscript_compa
5126  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5127  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5128    {    {
5129    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);
5130    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));
5131    if (withchecks)    if (withchecks)
5132      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5133    
5134    /* Needed to save important temporary registers. */    /* Needed to save important temporary registers. */
5135    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5136    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
5137    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);
5138    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));
5139    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5140    if (common->mode == JIT_COMPILE)    if (common->mode == JIT_COMPILE)
# Line 4904  if (!minimize) Line 5247  if (!minimize)
5247      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5248      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5249      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5250      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));
5251      zerolength = compile_ref_checks(common, ccbegin, NULL);      zerolength = compile_ref_checks(common, ccbegin, NULL);
5252      /* Restore if not zero length. */      /* Restore if not zero length. */
5253      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));
5254      }      }
5255    else    else
5256      {      {
# Line 4950  if (!minimize) Line 5293  if (!minimize)
5293    JUMPHERE(zerolength);    JUMPHERE(zerolength);
5294    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5295    
5296    decrease_call_count(common);    count_match(common);
5297    return cc;    return cc;
5298    }    }
5299    
# Line 4989  if (jump != NULL) Line 5332  if (jump != NULL)
5332    JUMPHERE(jump);    JUMPHERE(jump);
5333  JUMPHERE(zerolength);  JUMPHERE(zerolength);
5334    
5335  decrease_call_count(common);  count_match(common);
5336  return cc;  return cc;
5337  }  }
5338    
# Line 4999  DEFINE_COMPILER; Line 5342  DEFINE_COMPILER;
5342  backtrack_common *backtrack;  backtrack_common *backtrack;
5343  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5344  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5345  int start = GET(cc, 1);  sljit_sw start = GET(cc, 1);
5346    pcre_uchar *start_cc;
5347    BOOL needs_control_head;
5348    
5349  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5350    
5351    /* Inlining simple patterns. */
5352    if (get_framesize(common, common->start + start, NULL, TRUE, &needs_control_head) == no_stack)
5353      {
5354      start_cc = common->start + start;
5355      compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
5356      BACKTRACK_AS(recurse_backtrack)->inlined_pattern = TRUE;
5357      return cc + 1 + LINK_SIZE;
5358      }
5359    
5360  while (entry != NULL)  while (entry != NULL)
5361    {    {
5362    if (entry->start == start)    if (entry->start == start)
# Line 5050  add_jump(compiler, &backtrack->topbacktr Line 5405  add_jump(compiler, &backtrack->topbacktr
5405  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5406  }  }
5407    
5408    static int SLJIT_CALL do_callout(struct jit_arguments* arguments, PUBL(callout_block) *callout_block, pcre_uchar **jit_ovector)
5409    {
5410    const pcre_uchar *begin = arguments->begin;
5411    int *offset_vector = arguments->offsets;
5412    int offset_count = arguments->offset_count;
5413    int i;
5414    
5415    if (PUBL(callout) == NULL)
5416      return 0;
5417    
5418    callout_block->version = 2;
5419    callout_block->callout_data = arguments->callout_data;
5420    
5421    /* Offsets in subject. */
5422    callout_block->subject_length = arguments->end - arguments->begin;
5423    callout_block->start_match = (pcre_uchar*)callout_block->subject - arguments->begin;
5424    callout_block->current_position = (pcre_uchar*)callout_block->offset_vector - arguments->begin;
5425    #if defined COMPILE_PCRE8
5426    callout_block->subject = (PCRE_SPTR)begin;
5427    #elif defined COMPILE_PCRE16
5428    callout_block->subject = (PCRE_SPTR16)begin;
5429    #elif defined COMPILE_PCRE32
5430    callout_block->subject = (PCRE_SPTR32)begin;
5431    #endif
5432    
5433    /* Convert and copy the JIT offset vector to the offset_vector array. */
5434    callout_block->capture_top = 0;
5435    callout_block->offset_vector = offset_vector;
5436    for (i = 2; i < offset_count; i += 2)
5437      {
5438      offset_vector[i] = jit_ovector[i] - begin;
5439      offset_vector[i + 1] = jit_ovector[i + 1] - begin;
5440      if (jit_ovector[i] >= begin)
5441        callout_block->capture_top = i;
5442      }
5443    
5444    callout_block->capture_top = (callout_block->capture_top >> 1) + 1;
5445    if (offset_count > 0)
5446      offset_vector[0] = -1;
5447    if (offset_count > 1)
5448      offset_vector[1] = -1;
5449    return (*PUBL(callout))(callout_block);
5450    }
5451    
5452    /* Aligning to 8 byte. */
5453    #define CALLOUT_ARG_SIZE \
5454        (((int)sizeof(PUBL(callout_block)) + 7) & ~7)
5455    
5456    #define CALLOUT_ARG_OFFSET(arg) \
5457        (-CALLOUT_ARG_SIZE + SLJIT_OFFSETOF(PUBL(callout_block), arg))
5458    
5459    static SLJIT_INLINE pcre_uchar *compile_callout_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5460    {
5461    DEFINE_COMPILER;
5462    backtrack_common *backtrack;
5463    
5464    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
5465    
5466    allocate_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5467    
5468    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
5469    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
5470    SLJIT_ASSERT(common->capture_last_ptr != 0);
5471    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);
5472    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);
5473    
5474    /* These pointer sized fields temporarly stores internal variables. */
5475    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
5476    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(offset_vector), STR_PTR, 0);
5477    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(subject), TMP2, 0);
5478    
5479    if (common->mark_ptr != 0)
5480      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr));
5481    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 2));
5482    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 2 + LINK_SIZE));
5483    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);
5484    
5485    /* Needed to save important temporary registers. */
5486    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5487    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, STACK_TOP, 0, SLJIT_IMM, CALLOUT_ARG_SIZE);
5488    GET_LOCAL_BASE(SLJIT_SCRATCH_REG3, 0, OVECTOR_START);
5489    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_callout));
5490    OP1(SLJIT_MOV_SI, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0);
5491    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5492    free_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5493    
5494    /* Check return value. */
5495    OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
5496    add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_C_SIG_GREATER));
5497    if (common->forced_quit_label == NULL)
5498      add_jump(compiler, &common->forced_quit, JUMP(SLJIT_C_SIG_LESS));
5499    else
5500      JUMPTO(SLJIT_C_SIG_LESS, common->forced_quit_label);
5501    return cc + 2 + 2 * LINK_SIZE;
5502    }
5503    
5504    #undef CALLOUT_ARG_SIZE
5505    #undef CALLOUT_ARG_OFFSET
5506    
5507  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)
5508  {  {
5509  DEFINE_COMPILER;  DEFINE_COMPILER;
5510  int framesize;  int framesize;
5511    int extrasize;
5512    BOOL needs_control_head;
5513  int private_data_ptr;  int private_data_ptr;
5514  backtrack_common altbacktrack;  backtrack_common altbacktrack;
5515  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
# Line 5063  jump_list *tmp = NULL; Line 5519  jump_list *tmp = NULL;
5519  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5520  jump_list **found;  jump_list **found;
5521  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5522  struct sljit_label *save_quitlabel = common->quitlabel;  BOOL save_local_exit = common->local_exit;
5523  struct sljit_label *save_acceptlabel = common->acceptlabel;  BOOL save_positive_assert = common->positive_assert;
5524    then_trap_backtrack *save_then_trap = common->then_trap;
5525    struct sljit_label *save_quit_label = common->quit_label;
5526    struct sljit_label *save_accept_label = common->accept_label;
5527  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
5528    jump_list *save_positive_assert_quit = common->positive_assert_quit;
5529  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
5530  struct sljit_jump *jump;  struct sljit_jump *jump;
5531  struct sljit_jump *brajump = NULL;  struct sljit_jump *brajump = NULL;
5532    
5533    /* Assert captures then. */
5534    common->then_trap = NULL;
5535    
5536  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
5537    {    {
5538    SLJIT_ASSERT(!conditional);    SLJIT_ASSERT(!conditional);
# Line 5078  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 5541  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
5541    }    }
5542  private_data_ptr = PRIVATE_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
5543  SLJIT_ASSERT(private_data_ptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
5544  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
5545  backtrack->framesize = framesize;  backtrack->framesize = framesize;
5546  backtrack->private_data_ptr = private_data_ptr;  backtrack->private_data_ptr = private_data_ptr;
5547  opcode = *cc;  opcode = *cc;
# Line 5097  if (bra == OP_BRAMINZERO) Line 5560  if (bra == OP_BRAMINZERO)
5560    
5561  if (framesize < 0)  if (framesize < 0)
5562    {    {
5563    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    extrasize = needs_control_head ? 2 : 1;
5564    allocate_stack(common, 1);    if (framesize == no_frame)
5565        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
5566      allocate_stack(common, extrasize);
5567      if (needs_control_head)
5568        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5569    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5570      if (needs_control_head)
5571        {
5572        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5573        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5574        }
5575    }    }
5576  else  else
5577    {    {
5578    allocate_stack(common, framesize + 2);    extrasize = needs_control_head ? 3 : 2;
5579      allocate_stack(common, framesize + extrasize);
5580    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);
5581    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));
5582    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);
5583      if (needs_control_head)
5584        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5585    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5586    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    if (needs_control_head)
5587    init_frame(common, ccbegin, framesize + 1, 2, FALSE);      {
5588        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
5589        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
5590        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5591        }
5592      else
5593        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5594      init_frame(common, ccbegin, NULL, framesize + extrasize - 1, extrasize, FALSE);
5595    }    }
5596    
5597  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
5598  common->quitlabel = NULL;  if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5599  common->quit = NULL;    {
5600      /* Negative assert is stronger than positive assert. */
5601      common->local_exit = TRUE;
5602      common->quit_label = NULL;
5603      common->quit = NULL;
5604      common->positive_assert = FALSE;
5605      }
5606    else
5607      common->positive_assert = TRUE;
5608    common->positive_assert_quit = NULL;
5609    
5610  while (1)  while (1)
5611    {    {
5612    common->acceptlabel = NULL;    common->accept_label = NULL;
5613    common->accept = NULL;    common->accept = NULL;
5614    altbacktrack.top = NULL;    altbacktrack.top = NULL;
5615    altbacktrack.topbacktracks = NULL;    altbacktrack.topbacktracks = NULL;
# Line 5129  while (1) Line 5621  while (1)
5621    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
5622    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5623      {      {
5624      common->quitlabel = save_quitlabel;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5625      common->acceptlabel = save_acceptlabel;        {
5626      common->quit = save_quit;        common->local_exit = save_local_exit;
5627          common->quit_label = save_quit_label;
5628          common->quit = save_quit;
5629          }
5630        common->positive_assert = save_positive_assert;
5631        common->then_trap = save_then_trap;
5632        common->accept_label = save_accept_label;
5633        common->positive_assert_quit = save_positive_assert_quit;
5634      common->accept = save_accept;      common->accept = save_accept;
5635      return NULL;      return NULL;
5636      }      }
5637    common->acceptlabel = LABEL();    common->accept_label = LABEL();
5638    if (common->accept != NULL)    if (common->accept != NULL)
5639      set_jumps(common->accept, common->acceptlabel);      set_jumps(common->accept, common->accept_label);
5640    
5641    /* Reset stack. */    /* Reset stack. */
5642    if (framesize < 0)    if (framesize < 0)
5643      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      {
5644    else {      if (framesize == no_frame)
5645          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5646        else
5647          free_stack(common, extrasize);
5648        if (needs_control_head)
5649          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5650        }
5651      else
5652        {
5653      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)
5654        {        {
5655        /* 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. */
5656        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));
5657          if (needs_control_head)
5658            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5659        }        }
5660      else      else
5661        {        {
5662        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);
5663          if (needs_control_head)
5664            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));
5665        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5666        }        }
5667    }      }
5668    
5669    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5670      {      {
5671      /* 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. */
5672      if (conditional)      if (conditional)
5673        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);
5674      else if (bra == OP_BRAZERO)      else if (bra == OP_BRAZERO)
5675        {        {
5676        if (framesize < 0)        if (framesize < 0)
5677          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));
5678        else        else
5679          {          {
5680          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));
5681          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));
5682          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);
5683          }          }
5684        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));
5685        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5686        }        }
5687      else if (framesize >= 0)      else if (framesize >= 0)
5688        {        {
5689        /* For OP_BRA and OP_BRAMINZERO. */        /* For OP_BRA and OP_BRAMINZERO. */
5690        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));
5691        }        }
5692      }      }
5693    add_jump(compiler, found, JUMP(SLJIT_JUMP));    add_jump(compiler, found, JUMP(SLJIT_JUMP));
# Line 5184  while (1) Line 5695  while (1)
5695    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
5696    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5697      {      {
5698      common->quitlabel = save_quitlabel;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5699      common->acceptlabel = save_acceptlabel;        {
5700      common->quit = save_quit;        common->local_exit = save_local_exit;
5701          common->quit_label = save_quit_label;
5702          common->quit = save_quit;
5703          }
5704        common->positive_assert = save_positive_assert;
5705        common->then_trap = save_then_trap;
5706        common->accept_label = save_accept_label;
5707        common->positive_assert_quit = save_positive_assert_quit;
5708      common->accept = save_accept;      common->accept = save_accept;
5709      return NULL;      return NULL;
5710      }      }
# Line 5198  while (1) Line 5716  while (1)
5716    ccbegin = cc;    ccbegin = cc;
5717    cc += GET(cc, 1);    cc += GET(cc, 1);
5718    }    }
5719    
5720    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5721      {
5722      SLJIT_ASSERT(common->positive_assert_quit == NULL);
5723      /* Makes the check less complicated below. */
5724      common->positive_assert_quit = common->quit;
5725      }
5726    
5727  /* None of them matched. */  /* None of them matched. */
5728  if (common->quit != NULL)  if (common->positive_assert_quit != NULL)
5729    set_jumps(common->quit, LABEL());    {
5730      jump = JUMP(SLJIT_JUMP);
5731      set_jumps(common->positive_assert_quit, LABEL());
5732      SLJIT_ASSERT(framesize != no_stack);
5733      if (framesize < 0)
5734        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));
5735      else
5736        {
5737        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5738        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5739        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
5740        }
5741      JUMPHERE(jump);
5742      }
5743    
5744    if (needs_control_head)
5745      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(1));
5746    
5747  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)
5748    {    {
# Line 5212  if (opcode == OP_ASSERT || opcode == OP_ Line 5754  if (opcode == OP_ASSERT || opcode == OP_
5754      {      {
5755      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5756      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5757          {
5758          if (extrasize == 2)
5759            free_stack(common, 1);
5760        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5761          }
5762      else      else
5763        free_stack(common, 1);        free_stack(common, extrasize);
5764      }      }
5765    else    else
5766      {      {
5767      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
5768      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5769      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5770        {        {
5771        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
5772        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5773        }        }
5774      else      else
5775        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
5776      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);
5777      }      }
5778    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
# Line 5238  if (opcode == OP_ASSERT || opcode == OP_ Line 5784  if (opcode == OP_ASSERT || opcode == OP_
5784    if (framesize < 0)    if (framesize < 0)
5785      {      {
5786      /* 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. */
5787      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));
5788      /* Keep the STR_PTR on the top of the stack. */      /* Keep the STR_PTR on the top of the stack. */
5789      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5790        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));        {
5791          OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5792          if (extrasize == 2)
5793            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5794          }
5795      else if (bra == OP_BRAMINZERO)      else if (bra == OP_BRAMINZERO)
5796        {        {
5797        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));
5798        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5799        }        }
5800      }      }
# Line 5253  if (opcode == OP_ASSERT || opcode == OP_ Line 5803  if (opcode == OP_ASSERT || opcode == OP_
5803      if (bra == OP_BRA)      if (bra == OP_BRA)
5804        {        {
5805        /* 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. */
5806        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));
5807        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));
5808        }        }
5809      else      else
5810        {        {
5811        /* 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. */
5812        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));
5813        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));        if (extrasize == 2)
5814        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);          {
5815            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5816            if (bra == OP_BRAMINZERO)
5817              OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5818            }
5819          else
5820            {
5821            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), 0);
5822            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), bra == OP_BRAZERO ? STR_PTR : SLJIT_IMM, 0);
5823            }
5824        }        }
5825      }      }
5826    
5827    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
5828      {      {
5829      backtrack->matchingpath = LABEL();      backtrack->matchingpath = LABEL();
5830      sljit_set_label(jump, backtrack->matchingpath);      SET_LABEL(jump, backtrack->matchingpath);
5831      }      }
5832    else if (bra == OP_BRAMINZERO)    else if (bra == OP_BRAMINZERO)
5833      {      {
# Line 5278  if (opcode == OP_ASSERT || opcode == OP_ Line 5837  if (opcode == OP_ASSERT || opcode == OP_
5837        {        {
5838        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);
5839        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5840        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));
5841        }        }
5842      set_jumps(backtrack->common.topbacktracks, LABEL());      set_jumps(backtrack->common.topbacktracks, LABEL());
5843      }      }
# Line 5290  else Line 5849  else
5849      {      {
5850      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5851      if (bra != OP_BRA)      if (bra != OP_BRA)
5852          {
5853          if (extrasize == 2)
5854            free_stack(common, 1);
5855        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5856          }
5857      else      else
5858        free_stack(common, 1);        free_stack(common, extrasize);
5859      }      }
5860    else    else
5861      {      {
5862      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5863      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
5864      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5865      if (bra != OP_BRA)      if (bra != OP_BRA)
5866        {        {
5867        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
5868        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5869        }        }
5870      else      else
5871        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
5872      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);
5873      }      }
5874    
# Line 5325  else Line 5888  else
5888      }      }
5889    }    }
5890    
5891  common->quitlabel = save_quitlabel;  if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5892  common->acceptlabel = save_acceptlabel;    {
5893  common->quit = save_quit;    common->local_exit = save_local_exit;
5894      common->quit_label = save_quit_label;
5895      common->quit = save_quit;
5896      }
5897    common->positive_assert = save_positive_assert;
5898    common->then_trap = save_then_trap;
5899    common->accept_label = save_accept_label;
5900    common->positive_assert_quit = save_positive_assert_quit;
5901  common->accept = save_accept;  common->accept = save_accept;
5902  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5903  }  }
5904    
5905  static sljit_w SLJIT_CALL do_searchovector(sljit_uw 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)
5906  {  {
5907  int condition = FALSE;  int condition = FALSE;
5908  pcre_uchar *slotA = name_table;  pcre_uchar *slotA = name_table;
5909  pcre_uchar *slotB;  pcre_uchar *slotB;
5910  sljit_w name_count = locals[LOCALS0 / sizeof(sljit_w)];  sljit_sw name_count = locals[LOCALS0 / sizeof(sljit_sw)];
5911  sljit_w name_entry_size = locals[LOCALS1 / sizeof(sljit_w)];  sljit_sw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];
5912  sljit_w no_capture;  sljit_sw no_capture;
5913  int i;  int i;
5914    
5915  locals += refno & 0xff;  locals += refno & 0xff;
# Line 5389  if (i < name_count) Line 5959  if (i < name_count)
5959  return condition;  return condition;
5960  }  }
5961    
5962  static sljit_w SLJIT_CALL do_searchgroups(sljit_uw recno, sljit_uw* locals, pcre_uchar *name_table)  static sljit_sw SLJIT_CALL do_searchgroups(sljit_uw recno, sljit_uw* locals, pcre_uchar *name_table)
5963  {  {
5964  int condition = FALSE;  int condition = FALSE;
5965  pcre_uchar *slotA = name_table;  pcre_uchar *slotA = name_table;
5966  pcre_uchar *slotB;  pcre_uchar *slotB;
5967  sljit_uw name_count = locals[LOCALS0 / sizeof(sljit_w)];  sljit_uw name_count = locals[LOCALS0 / sizeof(sljit_sw)];
5968  sljit_uw name_entry_size = locals[LOCALS1 / sizeof(sljit_w)];  sljit_uw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];
5969  sljit_uw group_num = locals[POSSESSIVE0 / sizeof(sljit_w)];  sljit_uw group_num = locals[POSSESSIVE0 / sizeof(sljit_sw)];
5970  sljit_uw i;  sljit_uw i;
5971    
5972  for (i = 0; i < name_count; i++)  for (i = 0; i < name_count; i++)
# Line 5423  if (i < name_count) Line 5993  if (i < name_count)
5993      else break;      else break;
5994      }      }
5995    
5996    /* Scan up for duplicates */    /* Scan up for duplicates */
5997    if (!condition)    if (!condition)
5998        {
5999        slotB = slotA;
6000        for (i++; i < name_count; i++)
6001          {
6002          slotB += name_entry_size;
6003          if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
6004            {
6005            condition = GET2(slotB, 0) == group_num;
6006            if (condition) break;
6007            }
6008          else break;
6009          }
6010        }
6011      }
6012    return condition;
6013    }
6014    
6015    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)
6016    {
6017    DEFINE_COMPILER;
6018    int stacksize;
6019    
6020    if (framesize < 0)
6021      {
6022      if (framesize == no_frame)
6023        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6024      else
6025        {
6026        stacksize = needs_control_head ? 1 : 0;
6027        if (ket != OP_KET || has_alternatives)
6028          stacksize++;
6029        free_stack(common, stacksize);
6030        }
6031    
6032      if (needs_control_head)
6033        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), (ket != OP_KET || has_alternatives) ? sizeof(sljit_sw) : 0);
6034    
6035      /* TMP2 which is set here used by OP_KETRMAX below. */
6036      if (ket == OP_KETRMAX)
6037        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);
6038      else if (ket == OP_KETRMIN)
6039        {
6040        /* Move the STR_PTR to the private_data_ptr. */
6041        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);
6042        }
6043      }
6044    else
6045      {
6046      stacksize = (ket != OP_KET || has_alternatives) ? 2 : 1;
6047      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + stacksize) * sizeof(sljit_sw));
6048      if (needs_control_head)
6049        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 0);
6050    
6051      if (ket == OP_KETRMAX)
6052      {      {
6053      slotB = slotA;      /* TMP2 which is set here used by OP_KETRMAX below. */
6054      for (i++; i < name_count; i++)      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
       {  
       slotB += name_entry_size;  
       if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)  
         {  
         condition = GET2(slotB, 0) == group_num;  
         if (condition) break;  
         }  
       else break;  
       }  
6055      }      }
6056    }    }
6057  return condition;  if (needs_control_head)
6058      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP1, 0);
6059    }
6060    
6061    static SLJIT_INLINE int match_capture_common(compiler_common *common, int stacksize, int offset, int private_data_ptr)
6062    {
6063    DEFINE_COMPILER;
6064    
6065    if (common->capture_last_ptr != 0)
6066      {
6067      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6068      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6069      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6070      stacksize++;
6071      }
6072    if (common->optimized_cbracket[offset >> 1] == 0)
6073      {
6074      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6075      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
6076      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6077      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6078      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6079      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
6080      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6081      stacksize += 2;
6082      }
6083    return stacksize;
6084  }  }
6085    
6086  /*  /*
# Line 5504  pcre_uchar opcode; Line 6145  pcre_uchar opcode;
6145  int private_data_ptr = 0;  int private_data_ptr = 0;
6146  int offset = 0;  int offset = 0;
6147  int stacksize;  int stacksize;
6148    int repeat_ptr = 0, repeat_length = 0;
6149    int repeat_type = 0, repeat_count = 0;
6150  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
6151  pcre_uchar *matchingpath;  pcre_uchar *matchingpath;
6152  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
6153  pcre_uchar ket;  pcre_uchar ket;
6154  assert_backtrack *assert;  assert_backtrack *assert;
6155  BOOL has_alternatives;  BOOL has_alternatives;
6156    BOOL needs_control_head = FALSE;
6157  struct sljit_jump *jump;  struct sljit_jump *jump;
6158  struct sljit_jump *skip;  struct sljit_jump *skip;
6159  struct sljit_label *rmaxlabel = NULL;  struct sljit_label *rmax_label = NULL;
6160  struct sljit_jump *braminzerojump = NULL;  struct sljit_jump *braminzero = NULL;
6161    
6162  PUSH_BACKTRACK(sizeof(bracket_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(bracket_backtrack), cc, NULL);
6163    
# Line 5526  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 6170  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
6170    
6171  opcode = *cc;  opcode = *cc;
6172  ccbegin = cc;  ccbegin = cc;
6173  matchingpath = ccbegin + 1 + LINK_SIZE;  matchingpath = bracketend(cc) - 1 - LINK_SIZE;
6174    ket = *matchingpath;
6175    if (ket == OP_KET && PRIVATE_DATA(matchingpath) != 0)
6176      {
6177      repeat_ptr = PRIVATE_DATA(matchingpath);
6178      repeat_length = PRIVATE_DATA(matchingpath + 1);
6179      repeat_type = PRIVATE_DATA(matchingpath + 2);
6180      repeat_count = PRIVATE_DATA(matchingpath + 3);
6181      SLJIT_ASSERT(repeat_length != 0 && repeat_type != 0 && repeat_count != 0);
6182      if (repeat_type == OP_UPTO)
6183        ket = OP_KETRMAX;
6184      if (repeat_type == OP_MINUPTO)
6185        ket = OP_KETRMIN;
6186      }
6187    
6188  if ((opcode == OP_COND || opcode == OP_SCOND) && cc[1 + LINK_SIZE] == OP_DEF)  if ((opcode == OP_COND || opcode == OP_SCOND) && cc[1 + LINK_SIZE] == OP_DEF)
6189    {    {
6190    /* Drop this bracket_backtrack. */    /* Drop this bracket_backtrack. */
6191    parent->top = backtrack->prev;    parent->top = backtrack->prev;
6192    return bracketend(cc);    return matchingpath + 1 + LINK_SIZE + repeat_length;
6193    }    }
6194    
6195  ket = *(bracketend(cc) - 1 - LINK_SIZE);  matchingpath = ccbegin + 1 + LINK_SIZE;
6196  SLJIT_ASSERT(ket == OP_KET || ket == OP_KETRMAX || ket == OP_KETRMIN);  SLJIT_ASSERT(ket == OP_KET || ket == OP_KETRMAX || ket == OP_KETRMIN);
6197  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket == OP_KETRMIN) || (bra == OP_BRAMINZERO && ket == OP_KETRMAX)));  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket == OP_KETRMIN) || (bra == OP_BRAMINZERO && ket == OP_KETRMAX)));
6198  cc += GET(cc, 1);  cc += GET(cc, 1);
# Line 5585  else if (opcode == OP_ONCE || opcode == Line 6242  else if (opcode == OP_ONCE || opcode ==
6242    SLJIT_ASSERT(private_data_ptr != 0);    SLJIT_ASSERT(private_data_ptr != 0);
6243    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;
6244    if (opcode == OP_ONCE)    if (opcode == OP_ONCE)
6245      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, FALSE);      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, NULL, FALSE, &needs_control_head);
6246    }    }
6247    
6248  /* Instructions before the first alternative. */  /* Instructions before the first alternative. */
6249  stacksize = 0;  stacksize = 0;
6250  if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))  if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
6251    stacksize++;    stacksize++;
6252  if (bra == OP_BRAZERO)  if (bra == OP_BRAZERO)
6253    stacksize++;    stacksize++;
# Line 5599  if (stacksize > 0) Line 6256  if (stacksize > 0)
6256    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6257    
6258  stacksize = 0;  stacksize = 0;
6259  if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))  if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
6260    {    {
6261    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
6262    stacksize++;    stacksize++;
# Line 5615  if (bra == OP_BRAMINZERO) Line 6272  if (bra == OP_BRAMINZERO)
6272    if (ket != OP_KETRMIN)    if (ket != OP_KETRMIN)
6273      {      {
6274      free_stack(common, 1);      free_stack(common, 1);
6275      braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);      braminzero = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);
6276      }      }
6277    else    else
6278      {      {
# Line 5630  if (bra == OP_BRAMINZERO) Line 6287  if (bra == OP_BRAMINZERO)
6287        if (opcode != OP_ONCE || BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)        if (opcode != OP_ONCE || BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
6288          {          {
6289          /* When we come from outside, private_data_ptr contains the previous STR_PTR. */          /* When we come from outside, private_data_ptr contains the previous STR_PTR. */
6290          braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);          braminzero = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6291          }          }
6292        else        else
6293          {          {
6294          /* Except when the whole stack frame must be saved. */          /* Except when the whole stack frame must be saved. */
6295          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);
6296          braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (BACKTRACK_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_w));          braminzero = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (BACKTRACK_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_sw));
6297          }          }
6298        JUMPHERE(skip);        JUMPHERE(skip);
6299        }        }
# Line 5649  if (bra == OP_BRAMINZERO) Line 6306  if (bra == OP_BRAMINZERO)
6306      }      }
6307    }    }
6308    
6309    if (repeat_type != 0)
6310      {
6311      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, repeat_count);
6312      if (repeat_type == OP_EXACT)
6313        rmax_label = LABEL();
6314      }
6315    
6316  if (ket == OP_KETRMIN)  if (ket == OP_KETRMIN)
6317    BACKTRACK_AS(bracket_backtrack)->recursive_matchingpath = LABEL();    BACKTRACK_AS(bracket_backtrack)->recursive_matchingpath = LABEL();
6318    
6319  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
6320    {    {
6321    rmaxlabel = LABEL();    rmax_label = LABEL();
6322    if (has_alternatives && opcode != OP_ONCE && opcode < OP_SBRA)    if (has_alternatives && opcode != OP_ONCE && opcode < OP_SBRA && repeat_type == 0)
6323      BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = rmaxlabel;      BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = rmax_label;
6324    }    }
6325    
6326  /* Handling capturing brackets and alternatives. */  /* Handling capturing brackets and alternatives. */
6327  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
6328    {    {
6329      stacksize = 0;
6330      if (needs_control_head)
6331        {
6332        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);