/[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 1084 by chpe, Tue Oct 16 15:55:28 2012 UTC revision 1371 by zherczeg, Fri Oct 11 10:59:41 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
213  code generator. It is allocated by compile_matchingpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
214  the aguments for compile_backtrackingpath. Must be the first member  the arguments for compile_backtrackingpath. Must be the first member
215  of its descendants. */  of its descendants. */
216  typedef struct backtrack_common {  typedef struct backtrack_common {
217    /* Concatenation stack. */    /* Concatenation stack. */
# Line 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;    pcre_uchar *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) * (sljit_sw)sizeof(sljit_sw))
485  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
486  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
487    
488  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
# Line 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_DNREF:
593      case OP_DNREFI:
594      case OP_RECURSE:
595      case OP_CALLOUT:
596      case OP_ALT:
597      case OP_KET:
598      case OP_KETRMAX:
599      case OP_KETRMIN:
600      case OP_KETRPOS:
601      case OP_REVERSE:
602      case OP_ASSERT:
603      case OP_ASSERT_NOT:
604      case OP_ASSERTBACK:
605      case OP_ASSERTBACK_NOT:
606      case OP_ONCE:
607      case OP_ONCE_NC:
608      case OP_BRA:
609      case OP_BRAPOS:
610      case OP_CBRA:
611      case OP_CBRAPOS:
612      case OP_COND:
613      case OP_SBRA:
614      case OP_SBRAPOS:
615      case OP_SCBRA:
616      case OP_SCBRAPOS:
617      case OP_SCOND:
618      case OP_CREF:
619      case OP_DNCREF:
620      case OP_RREF:
621      case OP_DNRREF:
622    case OP_DEF:    case OP_DEF:
623    case OP_BRAZERO:    case OP_BRAZERO:
624    case OP_BRAMINZERO:    case OP_BRAMINZERO:
625    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
626      case OP_PRUNE:
627      case OP_SKIP:
628      case OP_THEN:
629    case OP_COMMIT:    case OP_COMMIT:
630    case OP_FAIL:    case OP_FAIL:
631    case OP_ACCEPT:    case OP_ACCEPT:
632    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
633      case OP_CLOSE:
634    case OP_SKIPZERO:    case OP_SKIPZERO:
635    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
636    
637    case OP_CHAR:    case OP_CHAR:
638    case OP_CHARI:    case OP_CHARI:
# Line 560  switch(*cc) Line 644  switch(*cc)
644    case OP_MINPLUS:    case OP_MINPLUS:
645    case OP_QUERY:    case OP_QUERY:
646    case OP_MINQUERY:    case OP_MINQUERY:
647      case OP_UPTO:
648      case OP_MINUPTO:
649      case OP_EXACT:
650    case OP_POSSTAR:    case OP_POSSTAR:
651    case OP_POSPLUS:    case OP_POSPLUS:
652    case OP_POSQUERY:    case OP_POSQUERY:
653      case OP_POSUPTO:
654    case OP_STARI:    case OP_STARI:
655    case OP_MINSTARI:    case OP_MINSTARI:
656    case OP_PLUSI:    case OP_PLUSI:
657    case OP_MINPLUSI:    case OP_MINPLUSI:
658    case OP_QUERYI:    case OP_QUERYI:
659    case OP_MINQUERYI:    case OP_MINQUERYI:
660      case OP_UPTOI:
661      case OP_MINUPTOI:
662      case OP_EXACTI:
663    case OP_POSSTARI:    case OP_POSSTARI:
664    case OP_POSPLUSI:    case OP_POSPLUSI:
665    case OP_POSQUERYI:    case OP_POSQUERYI:
666      case OP_POSUPTOI:
667    case OP_NOTSTAR:    case OP_NOTSTAR:
668    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
669    case OP_NOTPLUS:    case OP_NOTPLUS:
670    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
671    case OP_NOTQUERY:    case OP_NOTQUERY:
672    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
673      case OP_NOTUPTO:
674      case OP_NOTMINUPTO:
675      case OP_NOTEXACT:
676    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
677    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
678    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
679      case OP_NOTPOSUPTO:
680    case OP_NOTSTARI:    case OP_NOTSTARI:
681    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
682    case OP_NOTPLUSI:    case OP_NOTPLUSI:
683    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
684    case OP_NOTQUERYI:    case OP_NOTQUERYI:
685    case OP_NOTMINQUERYI:    case OP_NOTMINQUERYI:
   case OP_NOTPOSSTARI:  
   case OP_NOTPOSPLUSI:  
   case OP_NOTPOSQUERYI:  
   cc += 2;  
 #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  
   if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
   return cc;  
   
   case OP_UPTO:  
   case OP_MINUPTO:  
   case OP_EXACT:  
   case OP_POSUPTO:  
   case OP_UPTOI:  
   case OP_MINUPTOI:  
   case OP_EXACTI:  
   case OP_POSUPTOI:  
   case OP_NOTUPTO:  
   case OP_NOTMINUPTO:  
   case OP_NOTEXACT:  
   case OP_NOTPOSUPTO:  
686    case OP_NOTUPTOI:    case OP_NOTUPTOI:
687    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
688    case OP_NOTEXACTI:    case OP_NOTEXACTI:
689      case OP_NOTPOSSTARI:
690      case OP_NOTPOSPLUSI:
691      case OP_NOTPOSQUERYI:
692    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
693    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
694  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
695    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
696  #endif  #endif
697    return cc;    return cc;
698    
699    case OP_NOTPROP:    /* Special cases. */
700    case OP_PROP:    case OP_TYPESTAR:
701    return cc + 1 + 2;    case OP_TYPEMINSTAR:
702      case OP_TYPEPLUS:
703      case OP_TYPEMINPLUS:
704      case OP_TYPEQUERY:
705      case OP_TYPEMINQUERY:
706    case OP_TYPEUPTO:    case OP_TYPEUPTO:
707    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
708    case OP_TYPEEXACT:    case OP_TYPEEXACT:
709      case OP_TYPEPOSSTAR:
710      case OP_TYPEPOSPLUS:
711      case OP_TYPEPOSQUERY:
712    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
713    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;  
714    
715    case OP_CLASS:    case OP_ANYBYTE:
716    case OP_NCLASS:  #ifdef SUPPORT_UTF
717    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
718    #endif
719      return cc + 1;
720    
721  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
722    case OP_XCLASS:    case OP_XCLASS:
723    return cc + GET(cc, 1);    return cc + GET(cc, 1);
724  #endif  #endif
725    
   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;  
   
726    case OP_MARK:    case OP_MARK:
727      case OP_PRUNE_ARG:
728      case OP_SKIP_ARG:
729      case OP_THEN_ARG:
730    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
731    
732    default:    default:
733      /* All opcodes are supported now! */
734      SLJIT_ASSERT_STOP();
735    return NULL;    return NULL;
736    }    }
737  }  }
738    
739  #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)  
740  {  {
741  switch(*cc)  int count;
742    {  pcre_uchar *slot;
   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)  
 {  
 int private_data_length = 0;  
 pcre_uchar *alternative;  
 pcre_uchar *name;  
 pcre_uchar *end = NULL;  
 int space, size, bracketlen, 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 788  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:      common->optimized_cbracket[GET2(cc, 1)] = 0;
777      size += 1 + 32 / sizeof(pcre_uchar);      cc += 1 + IMM2_SIZE;
     space = get_class_iterator_size(cc + size);  
778      break;      break;
779    
780  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8      case OP_DNREF:
781      case OP_XCLASS:      case OP_DNREFI:
782      size = GET(cc, 1);      case OP_DNCREF:
783      space = get_class_iterator_size(cc + size);      count = GET2(cc, 1 + IMM2_SIZE);
784        slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
785        while (count-- > 0)
786          {
787          common->optimized_cbracket[GET2(slot, 0)] = 0;
788          slot += common->name_entry_size;
789          }
790        cc += 1 + 2 * IMM2_SIZE;
791      break;      break;
 #endif  
792    
793      case OP_RECURSE:      case OP_RECURSE:
794      /* Set its value only once. */      /* Set its value only once. */
795      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
796        {        {
797        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
798        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
799        }        }
800      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
801      break;      break;
802    
803        case OP_CALLOUT:
804        if (common->capture_last_ptr == 0)
805          {
806          common->capture_last_ptr = common->ovector_start;
807          common->ovector_start += sizeof(sljit_sw);
808          }
809        cc += 2 + 2 * LINK_SIZE;
810        break;
811    
812        case OP_THEN_ARG:
813        common->has_then = TRUE;
814        common->control_head_ptr = 1;
815        /* Fall through. */
816    
817        case OP_PRUNE_ARG:
818        common->needs_start_ptr = TRUE;
819        /* Fall through. */
820    
821      case OP_MARK:      case OP_MARK:
822      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
823        {        {
824        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
825        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
826        }        }
827      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
828      break;      break;
829    
830        case OP_THEN:
831        common->has_then = TRUE;
832        common->control_head_ptr = 1;
833        /* Fall through. */
834    
835        case OP_PRUNE:
836        case OP_SKIP:
837        common->needs_start_ptr = TRUE;
838        cc += 1;
839        break;
840    
841        case OP_SKIP_ARG:
842        common->control_head_ptr = 1;
843        common->has_skip_arg = TRUE;
844        cc += 1 + 2 + cc[1];
845        break;
846    
847      default:      default:
848      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
849      if (cc == NULL)      if (cc == NULL)
850        return -1;        return FALSE;
851      break;      break;
852      }      }
853      }
854    return TRUE;
855    }
856    
857    if (space > 0 && cc >= end)  static int get_class_iterator_size(pcre_uchar *cc)
858      private_data_length += sizeof(sljit_w) * space;  {
859    switch(*cc)
860      {
861      case OP_CRSTAR:
862      case OP_CRPLUS:
863      return 2;
864    
865    if (size != 0)    case OP_CRMINSTAR:
866      case OP_CRMINPLUS:
867      case OP_CRQUERY:
868      case OP_CRMINQUERY:
869      return 1;
870    
871      case OP_CRRANGE:
872      case OP_CRMINRANGE:
873      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
874        return 0;
875      return 2;
876    
877      default:
878      return 0;
879      }
880    }
881    
882    static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
883    {
884    pcre_uchar *end = bracketend(begin);
885    pcre_uchar *next;
886    pcre_uchar *next_end;
887    pcre_uchar *max_end;
888    pcre_uchar type;
889    sljit_sw length = end - begin;
890    int min, max, i;
891    
892    /* Detect fixed iterations first. */
893    if (end[-(1 + LINK_SIZE)] != OP_KET)
894      return FALSE;
895    
896    /* Already detected repeat. */
897    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
898      return TRUE;
899    
900    next = end;
901    min = 1;
902    while (1)
903      {
904      if (*next != *begin)
905        break;
906      next_end = bracketend(next);
907      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
908        break;
909      next = next_end;
910      min++;
911      }
912    
913    if (min == 2)
914      return FALSE;
915    
916    max = 0;
917    max_end = next;
918    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
919      {
920      type = *next;
921      while (1)
922      {      {
923      if (size < 0)      if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
924        {        break;
925        cc += -size;      next_end = bracketend(next + 2 + LINK_SIZE);
926  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32      if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
927        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        break;
928  #endif      next = next_end;
929        }      max++;
     else  
       cc += size;  
930      }      }
931    
932    if (bracketlen > 0)    if (next[0] == type && next[1] == *begin && max >= 1)
933      {      {
934      if (cc >= end)      next_end = bracketend(next + 1);
935        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
936        {        {
937        end = bracketend(cc);        for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
938        if (end[-1 - LINK_SIZE] == OP_KET)          if (*next_end != OP_KET)
939          end = NULL;            break;
940    
941          if (i == max)
942            {
943            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
944            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
945            /* +2 the original and the last. */
946            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
947            if (min == 1)
948              return TRUE;
949            min--;
950            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
951            }
952        }        }
     cc += bracketlen;  
953      }      }
954    }    }
955  return private_data_length;  
956    if (min >= 3)
957      {
958      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
959      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
960      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
961      return TRUE;
962      }
963    
964    return FALSE;
965  }  }
966    
967  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
968        case OP_MINSTAR: \
969        case OP_MINPLUS: \
970        case OP_QUERY: \
971        case OP_MINQUERY: \
972        case OP_MINSTARI: \
973        case OP_MINPLUSI: \
974        case OP_QUERYI: \
975        case OP_MINQUERYI: \
976        case OP_NOTMINSTAR: \
977        case OP_NOTMINPLUS: \
978        case OP_NOTQUERY: \
979        case OP_NOTMINQUERY: \
980        case OP_NOTMINSTARI: \
981        case OP_NOTMINPLUSI: \
982        case OP_NOTQUERYI: \
983        case OP_NOTMINQUERYI:
984    
985    #define CASE_ITERATOR_PRIVATE_DATA_2A \
986        case OP_STAR: \
987        case OP_PLUS: \
988        case OP_STARI: \
989        case OP_PLUSI: \
990        case OP_NOTSTAR: \
991        case OP_NOTPLUS: \
992        case OP_NOTSTARI: \
993        case OP_NOTPLUSI:
994    
995    #define CASE_ITERATOR_PRIVATE_DATA_2B \
996        case OP_UPTO: \
997        case OP_MINUPTO: \
998        case OP_UPTOI: \
999        case OP_MINUPTOI: \
1000        case OP_NOTUPTO: \
1001        case OP_NOTMINUPTO: \
1002        case OP_NOTUPTOI: \
1003        case OP_NOTMINUPTOI:
1004    
1005    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1006        case OP_TYPEMINSTAR: \
1007        case OP_TYPEMINPLUS: \
1008        case OP_TYPEQUERY: \
1009        case OP_TYPEMINQUERY:
1010    
1011    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1012        case OP_TYPESTAR: \
1013        case OP_TYPEPLUS:
1014    
1015    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1016        case OP_TYPEUPTO: \
1017        case OP_TYPEMINUPTO:
1018    
1019    static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1020  {  {
1021  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1022  pcre_uchar *alternative;  pcre_uchar *alternative;
1023  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1024    int private_data_ptr = *private_data_start;
1025  int space, size, bracketlen;  int space, size, bracketlen;
1026    
1027  while (cc < ccend)  while (cc < ccend)
# Line 970  while (cc < ccend) Line 1029  while (cc < ccend)
1029    space = 0;    space = 0;
1030    size = 0;    size = 0;
1031    bracketlen = 0;    bracketlen = 0;
1032      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1033        return;
1034    
1035      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1036        if (detect_repeat(common, cc))
1037          {
1038          /* These brackets are converted to repeats, so no global
1039          based single character repeat is allowed. */
1040          if (cc >= end)
1041            end = bracketend(cc);
1042          }
1043    
1044    switch(*cc)    switch(*cc)
1045      {      {
1046        case OP_KET:
1047        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1048          {
1049          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1050          private_data_ptr += sizeof(sljit_sw);
1051          cc += common->private_data_ptrs[cc + 1 - common->start];
1052          }
1053        cc += 1 + LINK_SIZE;
1054        break;
1055    
1056      case OP_ASSERT:      case OP_ASSERT:
1057      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1058      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 983  while (cc < ccend) Line 1064  while (cc < ccend)
1064      case OP_SBRAPOS:      case OP_SBRAPOS:
1065      case OP_SCOND:      case OP_SCOND:
1066      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1067      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1068      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1069      break;      break;
1070    
1071      case OP_CBRAPOS:      case OP_CBRAPOS:
1072      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1073      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1074      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1075      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1076      break;      break;
1077    
# Line 1000  while (cc < ccend) Line 1081  while (cc < ccend)
1081      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1082        {        {
1083        common->private_data_ptrs[cc - common->start] = private_data_ptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1084        private_data_ptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1085        }        }
1086      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1087      break;      break;
# Line 1065  while (cc < ccend) Line 1146  while (cc < ccend)
1146      break;      break;
1147      }      }
1148    
1149      /* Character iterators, which are not inside a repeated bracket,
1150         gets a private slot instead of allocating it on the stack. */
1151    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1152      {      {
1153      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1154      private_data_ptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1155      }      }
1156    
1157    if (size != 0)    if (size != 0)
# Line 1076  while (cc < ccend) Line 1159  while (cc < ccend)
1159      if (size < 0)      if (size < 0)
1160        {        {
1161        cc += -size;        cc += -size;
1162  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1163        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1164  #endif  #endif
1165        }        }
# Line 1095  while (cc < ccend) Line 1178  while (cc < ccend)
1178      cc += bracketlen;      cc += bracketlen;
1179      }      }
1180    }    }
1181    *private_data_start = private_data_ptr;
1182  }  }
1183    
1184  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1185  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)
1186  {  {
 pcre_uchar *ccend = bracketend(cc);  
1187  int length = 0;  int length = 0;
1188  BOOL possessive = FALSE;  int possessive = 0;
1189    BOOL stack_restore = FALSE;
1190  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1191  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1192    /* The last capture is a local variable even for recursions. */
1193    BOOL capture_last_found = FALSE;
1194    
1195  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1196    SLJIT_ASSERT(common->control_head_ptr != 0);
1197    *needs_control_head = TRUE;
1198    #else
1199    *needs_control_head = FALSE;
1200    #endif
1201    
1202    if (ccend == NULL)
1203    {    {
1204    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1205    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1206        {
1207        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1208        /* This is correct regardless of common->capture_last_ptr. */
1209        capture_last_found = TRUE;
1210        }
1211      cc = next_opcode(common, cc);
1212    }    }
1213    
 cc = next_opcode(common, cc);  
1214  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1215  while (cc < ccend)  while (cc < ccend)
1216    switch(*cc)    switch(*cc)
1217      {      {
1218      case OP_SET_SOM:      case OP_SET_SOM:
1219      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1220        stack_restore = TRUE;
1221      if (!setsom_found)      if (!setsom_found)
1222        {        {
1223        length += 2;        length += 2;
# Line 1128  while (cc < ccend) Line 1227  while (cc < ccend)
1227      break;      break;
1228    
1229      case OP_MARK:      case OP_MARK:
1230        case OP_PRUNE_ARG:
1231        case OP_THEN_ARG:
1232      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1233        stack_restore = TRUE;
1234      if (!setmark_found)      if (!setmark_found)
1235        {        {
1236        length += 2;        length += 2;
1237        setmark_found = TRUE;        setmark_found = TRUE;
1238        }        }
1239        if (common->control_head_ptr != 0)
1240          *needs_control_head = TRUE;
1241      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1242      break;      break;
1243    
1244      case OP_RECURSE:      case OP_RECURSE:
1245        stack_restore = TRUE;
1246      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1247        {        {
1248        length += 2;        length += 2;
# Line 1148  while (cc < ccend) Line 1253  while (cc < ccend)
1253        length += 2;        length += 2;
1254        setmark_found = TRUE;        setmark_found = TRUE;
1255        }        }
1256        if (common->capture_last_ptr != 0 && !capture_last_found)
1257          {
1258          length += 2;
1259          capture_last_found = TRUE;
1260          }
1261      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1262      break;      break;
1263    
# Line 1155  while (cc < ccend) Line 1265  while (cc < ccend)
1265      case OP_CBRAPOS:      case OP_CBRAPOS:
1266      case OP_SCBRA:      case OP_SCBRA:
1267      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1268        stack_restore = TRUE;
1269        if (common->capture_last_ptr != 0 && !capture_last_found)
1270          {
1271          length += 2;
1272          capture_last_found = TRUE;
1273          }
1274      length += 3;      length += 3;
1275      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1276      break;      break;
1277    
1278      default:      default:
1279        stack_restore = TRUE;
1280        /* Fall through. */
1281    
1282        case OP_NOT_WORD_BOUNDARY:
1283        case OP_WORD_BOUNDARY:
1284        case OP_NOT_DIGIT:
1285        case OP_DIGIT:
1286        case OP_NOT_WHITESPACE:
1287        case OP_WHITESPACE:
1288        case OP_NOT_WORDCHAR:
1289        case OP_WORDCHAR:
1290        case OP_ANY:
1291        case OP_ALLANY:
1292        case OP_ANYBYTE:
1293        case OP_NOTPROP:
1294        case OP_PROP:
1295        case OP_ANYNL:
1296        case OP_NOT_HSPACE:
1297        case OP_HSPACE:
1298        case OP_NOT_VSPACE:
1299        case OP_VSPACE:
1300        case OP_EXTUNI:
1301        case OP_EODN:
1302        case OP_EOD:
1303        case OP_CIRC:
1304        case OP_CIRCM:
1305        case OP_DOLL:
1306        case OP_DOLLM:
1307        case OP_CHAR:
1308        case OP_CHARI:
1309        case OP_NOT:
1310        case OP_NOTI:
1311    
1312        case OP_EXACT:
1313        case OP_POSSTAR:
1314        case OP_POSPLUS:
1315        case OP_POSQUERY:
1316        case OP_POSUPTO:
1317    
1318        case OP_EXACTI:
1319        case OP_POSSTARI:
1320        case OP_POSPLUSI:
1321        case OP_POSQUERYI:
1322        case OP_POSUPTOI:
1323    
1324        case OP_NOTEXACT:
1325        case OP_NOTPOSSTAR:
1326        case OP_NOTPOSPLUS:
1327        case OP_NOTPOSQUERY:
1328        case OP_NOTPOSUPTO:
1329    
1330        case OP_NOTEXACTI:
1331        case OP_NOTPOSSTARI:
1332        case OP_NOTPOSPLUSI:
1333        case OP_NOTPOSQUERYI:
1334        case OP_NOTPOSUPTOI:
1335    
1336        case OP_TYPEEXACT:
1337        case OP_TYPEPOSSTAR:
1338        case OP_TYPEPOSPLUS:
1339        case OP_TYPEPOSQUERY:
1340        case OP_TYPEPOSUPTO:
1341    
1342        case OP_CLASS:
1343        case OP_NCLASS:
1344        case OP_XCLASS:
1345    
1346      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1347      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1348      break;      break;
1349      }      }
1350    
1351  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1352  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1353    return -1;    return stack_restore ? no_frame : no_stack;
1354    
1355  if (length > 0)  if (length > 0)
1356    return length + 1;    return length + 1;
1357  return -1;  return stack_restore ? no_frame : no_stack;
1358  }  }
1359    
1360  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)
1361  {  {
1362  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1363  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1364  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1365    /* The last capture is a local variable even for recursions. */
1366    BOOL capture_last_found = FALSE;
1367  int offset;  int offset;
1368    
1369  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1187  SLJIT_UNUSED_ARG(stacktop); Line 1371  SLJIT_UNUSED_ARG(stacktop);
1371  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1372    
1373  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1374  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1375    cc = next_opcode(common, cc);    {
1376      ccend = bracketend(cc) - (1 + LINK_SIZE);
1377      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1378        cc = next_opcode(common, cc);
1379      }
1380    
1381  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1382  while (cc < ccend)  while (cc < ccend)
1383    switch(*cc)    switch(*cc)
# Line 1198  while (cc < ccend) Line 1387  while (cc < ccend)
1387      if (!setsom_found)      if (!setsom_found)
1388        {        {
1389        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1390        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1391        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1392        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1393        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1394        setsom_found = TRUE;        setsom_found = TRUE;
1395        }        }
1396      cc += 1;      cc += 1;
1397      break;      break;
1398    
1399      case OP_MARK:      case OP_MARK:
1400        case OP_PRUNE_ARG:
1401        case OP_THEN_ARG:
1402      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1403      if (!setmark_found)      if (!setmark_found)
1404        {        {
1405        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);
1406        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);
1407        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1408        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1409        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1410        setmark_found = TRUE;        setmark_found = TRUE;
1411        }        }
1412      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 1225  while (cc < ccend) Line 1416  while (cc < ccend)
1416      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1417        {        {
1418        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1419        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1420        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1421        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1422        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1423        setsom_found = TRUE;        setsom_found = TRUE;
1424        }        }
1425      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1426        {        {
1427        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);
1428        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);
1429        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1430        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1431        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1432        setmark_found = TRUE;        setmark_found = TRUE;
1433        }        }
1434        if (common->capture_last_ptr != 0 && !capture_last_found)
1435          {
1436          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1437          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1438          stackpos += (int)sizeof(sljit_sw);
1439          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1440          stackpos += (int)sizeof(sljit_sw);
1441          capture_last_found = TRUE;
1442          }
1443      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1444      break;      break;
1445    
# Line 1247  while (cc < ccend) Line 1447  while (cc < ccend)
1447      case OP_CBRAPOS:      case OP_CBRAPOS:
1448      case OP_SCBRA:      case OP_SCBRA:
1449      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1450        if (common->capture_last_ptr != 0 && !capture_last_found)
1451          {
1452          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1453          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1454          stackpos += (int)sizeof(sljit_sw);
1455          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1456          stackpos += (int)sizeof(sljit_sw);
1457          capture_last_found = TRUE;
1458          }
1459      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1460      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1461      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1462      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1463      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));
1464      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1465      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1466      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1467      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1468    
1469      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1470      break;      break;
# Line 1266  while (cc < ccend) Line 1475  while (cc < ccend)
1475      break;      break;
1476      }      }
1477    
1478  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1479  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1480  }  }
1481    
1482  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)
1483  {  {
1484  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1485  int size;  int size;
1486  pcre_uchar *alternative;  pcre_uchar *alternative;
1487  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1281  while (cc < ccend) Line 1490  while (cc < ccend)
1490    size = 0;    size = 0;
1491    switch(*cc)    switch(*cc)
1492      {      {
1493        case OP_KET:
1494        if (PRIVATE_DATA(cc) != 0)
1495          private_data_length++;
1496        cc += 1 + LINK_SIZE;
1497        break;
1498    
1499      case OP_ASSERT:      case OP_ASSERT:
1500      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1501      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1320  while (cc < ccend) Line 1535  while (cc < ccend)
1535      if (PRIVATE_DATA(cc))      if (PRIVATE_DATA(cc))
1536        private_data_length++;        private_data_length++;
1537      cc += 2;      cc += 2;
1538  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1539      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1540  #endif  #endif
1541      break;      break;
# Line 1329  while (cc < ccend) Line 1544  while (cc < ccend)
1544      if (PRIVATE_DATA(cc))      if (PRIVATE_DATA(cc))
1545        private_data_length += 2;        private_data_length += 2;
1546      cc += 2;      cc += 2;
1547  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1548      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1549  #endif  #endif
1550      break;      break;
# Line 1338  while (cc < ccend) Line 1553  while (cc < ccend)
1553      if (PRIVATE_DATA(cc))      if (PRIVATE_DATA(cc))
1554        private_data_length += 2;        private_data_length += 2;
1555      cc += 2 + IMM2_SIZE;      cc += 2 + IMM2_SIZE;
1556  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1557      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1558  #endif  #endif
1559      break;      break;
# Line 1385  return private_data_length; Line 1600  return private_data_length;
1600  }  }
1601    
1602  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,
1603    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1604  {  {
1605  DEFINE_COMPILER;  DEFINE_COMPILER;
1606  int srcw[2];  int srcw[2];
# Line 1406  stacktop = STACK(stacktop - 1); Line 1621  stacktop = STACK(stacktop - 1);
1621    
1622  if (!save)  if (!save)
1623    {    {
1624    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1625    if (stackptr < stacktop)    if (stackptr < stacktop)
1626      {      {
1627      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1628      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1629      tmp1empty = FALSE;      tmp1empty = FALSE;
1630      }      }
1631    if (stackptr < stacktop)    if (stackptr < stacktop)
1632      {      {
1633      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1634      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1635      tmp2empty = FALSE;      tmp2empty = FALSE;
1636      }      }
1637    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1638    }    }
1639    
1640  while (status != end)  do
1641    {    {
1642    count = 0;    count = 0;
1643    switch(status)    switch(status)
1644      {      {
1645      case start:      case start:
1646      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1647      count = 1;      count = 1;
1648      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1649        if (needs_control_head)
1650          {
1651          SLJIT_ASSERT(common->control_head_ptr != 0);
1652          count = 2;
1653          srcw[1] = common->control_head_ptr;
1654          }
1655      status = loop;      status = loop;
1656      break;      break;
1657    
# Line 1443  while (status != end) Line 1664  while (status != end)
1664    
1665      switch(*cc)      switch(*cc)
1666        {        {
1667          case OP_KET:
1668          if (PRIVATE_DATA(cc) != 0)
1669            {
1670            count = 1;
1671            srcw[0] = PRIVATE_DATA(cc);
1672            }
1673          cc += 1 + LINK_SIZE;
1674          break;
1675    
1676        case OP_ASSERT:        case OP_ASSERT:
1677        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1678        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1497  while (status != end) Line 1727  while (status != end)
1727          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1728          }          }
1729        cc += 2;        cc += 2;
1730  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1731        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1732  #endif  #endif
1733        break;        break;
# Line 1507  while (status != end) Line 1737  while (status != end)
1737          {          {
1738          count = 2;          count = 2;
1739          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1740          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1741          }          }
1742        cc += 2;        cc += 2;
1743  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1744        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1745  #endif  #endif
1746        break;        break;
# Line 1520  while (status != end) Line 1750  while (status != end)
1750          {          {
1751          count = 2;          count = 2;
1752          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1753          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1754          }          }
1755        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1756  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1757        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1758  #endif  #endif
1759        break;        break;
# Line 1542  while (status != end) Line 1772  while (status != end)
1772          {          {
1773          count = 2;          count = 2;
1774          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1775          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1776          }          }
1777        cc += 1;        cc += 1;
1778        break;        break;
# Line 1552  while (status != end) Line 1782  while (status != end)
1782          {          {
1783          count = 2;          count = 2;
1784          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1785          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1786          }          }
1787        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1788        break;        break;
# Line 1576  while (status != end) Line 1806  while (status != end)
1806            case 2:            case 2:
1807            count = 2;            count = 2;
1808            srcw[0] = PRIVATE_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1809            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1810            break;            break;
1811    
1812            default:            default:
# Line 1608  while (status != end) Line 1838  while (status != end)
1838          if (!tmp1empty)          if (!tmp1empty)
1839            {            {
1840            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1841            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1842            }            }
1843          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1844          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1619  while (status != end) Line 1849  while (status != end)
1849          if (!tmp2empty)          if (!tmp2empty)
1850            {            {
1851            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1852            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1853            }            }
1854          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1855          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1636  while (status != end) Line 1866  while (status != end)
1866          if (!tmp1empty)          if (!tmp1empty)
1867            {            {
1868            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1869            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1870            }            }
1871          tmp1next = FALSE;          tmp1next = FALSE;
1872          }          }
# Line 1648  while (status != end) Line 1878  while (status != end)
1878          if (!tmp2empty)          if (!tmp2empty)
1879            {            {
1880            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1881            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1882            }            }
1883          tmp1next = TRUE;          tmp1next = TRUE;
1884          }          }
1885        }        }
1886      }      }
1887    }    }
1888    while (status != end);
1889    
1890  if (save)  if (save)
1891    {    {
# Line 1663  if (save) Line 1894  if (save)
1894      if (!tmp1empty)      if (!tmp1empty)
1895        {        {
1896        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1897        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1898        }        }
1899      if (!tmp2empty)      if (!tmp2empty)
1900        {        {
1901        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1902        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1903        }        }
1904      }      }
1905    else    else
# Line 1676  if (save) Line 1907  if (save)
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      if (!tmp1empty)      if (!tmp1empty)
1913        {        {
1914        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1915        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1916        }        }
1917      }      }
1918    }    }
1919  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1920  }  }
1921    
1922    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1923    {
1924    pcre_uchar *end = bracketend(cc);
1925    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1926    
1927    /* Assert captures then. */
1928    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1929      current_offset = NULL;
1930    /* Conditional block does not. */
1931    if (*cc == OP_COND || *cc == OP_SCOND)
1932      has_alternatives = FALSE;
1933    
1934    cc = next_opcode(common, cc);
1935    if (has_alternatives)
1936      current_offset = common->then_offsets + (cc - common->start);
1937    
1938    while (cc < end)
1939      {
1940      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1941        cc = set_then_offsets(common, cc, current_offset);
1942      else
1943        {
1944        if (*cc == OP_ALT && has_alternatives)
1945          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1946        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1947          *current_offset = 1;
1948        cc = next_opcode(common, cc);
1949        }
1950      }
1951    
1952    return end;
1953    }
1954    
1955  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
1956  #undef CASE_ITERATOR_PRIVATE_DATA_2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
1957  #undef CASE_ITERATOR_PRIVATE_DATA_2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
# Line 1706  while (list) Line 1970  while (list)
1970    {    {
1971    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1972    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
1973    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1974    list = list->next;    list = list->next;
1975    }    }
1976  }  }
# Line 1722  if (list_item) Line 1986  if (list_item)
1986    }    }
1987  }  }
1988    
1989  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)
1990  {  {
1991  DEFINE_COMPILER;  DEFINE_COMPILER;
1992  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1993    
1994  if (list_item)  if (list_item)
1995    {    {
   list_item->type = type;  
   list_item->data = data;  
1996    list_item->start = start;    list_item->start = start;
1997    list_item->quit = LABEL();    list_item->quit = LABEL();
1998    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1746  stub_list* list_item = common->stubs; Line 2008  stub_list* list_item = common->stubs;
2008  while (list_item)  while (list_item)
2009    {    {
2010    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2011    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;  
     }  
2012    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2013    list_item = list_item->next;    list_item = list_item->next;
2014    }    }
2015  common->stubs = NULL;  common->stubs = NULL;
2016  }  }
2017    
2018  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2019  {  {
2020  DEFINE_COMPILER;  DEFINE_COMPILER;
2021    
2022  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);
2023  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2024  }  }
2025    
# Line 1771  static SLJIT_INLINE void allocate_stack( Line 2028  static SLJIT_INLINE void allocate_stack(
2028  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2029  DEFINE_COMPILER;  DEFINE_COMPILER;
2030    
2031  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));
2032  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2033  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2034  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1779  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 2036  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2036  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2037  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2038  #endif  #endif
2039  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));
2040  }  }
2041    
2042  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2043  {  {
2044  DEFINE_COMPILER;  DEFINE_COMPILER;
2045  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));
2046  }  }
2047    
2048  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1793  static SLJIT_INLINE void reset_ovector(c Line 2050  static SLJIT_INLINE void reset_ovector(c
2050  DEFINE_COMPILER;  DEFINE_COMPILER;
2051  struct sljit_label *loop;  struct sljit_label *loop;
2052  int i;  int i;
2053    
2054  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2055    SLJIT_ASSERT(length > 1);
2056  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2057  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));
2058    if (length < 8)
2059      {
2060      for (i = 1; i < length; i++)
2061        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2062      }
2063    else
2064      {
2065      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2066      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2067      loop = LABEL();
2068      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2069      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2070      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2071      }
2072    }
2073    
2074    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2075    {
2076    DEFINE_COMPILER;
2077    struct sljit_label *loop;
2078    int i;
2079    
2080    SLJIT_ASSERT(length > 1);
2081    /* OVECTOR(1) contains the "string begin - 1" constant. */
2082    if (length > 2)
2083      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2084  if (length < 8)  if (length < 8)
2085    {    {
2086    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
2087      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);
2088    }    }
2089  else  else
2090    {    {
2091    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2092    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2093    loop = LABEL();    loop = LABEL();
2094    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);
2095    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);
2096    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2097    }    }
2098    
2099    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2100    if (common->mark_ptr != 0)
2101      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2102    if (common->control_head_ptr != 0)
2103      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2104    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2105    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2106    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2107    }
2108    
2109    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2110    {
2111    while (current != NULL)
2112      {
2113      switch (current[-2])
2114        {
2115        case type_then_trap:
2116        break;
2117    
2118        case type_mark:
2119        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2120          return current[-4];
2121        break;
2122    
2123        default:
2124        SLJIT_ASSERT_STOP();
2125        break;
2126        }
2127      current = (sljit_sw*)current[-1];
2128      }
2129    return -1;
2130  }  }
2131    
2132  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2133  {  {
2134  DEFINE_COMPILER;  DEFINE_COMPILER;
2135  struct sljit_label *loop;  struct sljit_label *loop;
2136  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2137    
2138  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2139  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));
2140  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);
2141    
2142  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2143  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2144    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);
2145  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));
2146  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2147    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);
2148  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));
2149  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));
2150  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2151  /* Unlikely, but possible */  /* Unlikely, but possible */
2152  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);
2153  loop = LABEL();  loop = LABEL();
2154  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);
2155  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));
2156  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2157  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2158  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);
2159  #endif  #endif
2160  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);
2161  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);
2162  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2163  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2164    
2165  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2166  if (topbracket > 1)  if (topbracket > 1)
2167    {    {
2168    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));
2169    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2170    
2171    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2172    loop = LABEL();    loop = LABEL();
2173    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)));
2174    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);
2175    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);
2176    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2177    }    }
2178  else  else
2179    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1865  else Line 2182  else
2182  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)
2183  {  {
2184  DEFINE_COMPILER;  DEFINE_COMPILER;
2185    struct sljit_jump *jump;
2186    
2187  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);
2188  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
2189      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2190    
2191  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2192  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2193  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));
2194  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);
2195    
2196  /* Store match begin and end. */  /* Store match begin and end. */
2197  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));
2198  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));
2199  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);  
2200    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2201    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);
2202    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2203    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2204    #endif
2205    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2206    JUMPHERE(jump);
2207    
2208    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);
2209  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);
2210  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2211  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);
2212  #endif  #endif
2213  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);
2214    
2215  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);
2216  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2217  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);
2218  #endif  #endif
2219  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);
2220    
2221  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2222  }  }
# Line 2038  return (bit < 256) ? ((0 << 8) | bit) : Line 2366  return (bit < 256) ? ((0 << 8) | bit) :
2366    
2367  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2368  {  {
2369  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2370  DEFINE_COMPILER;  DEFINE_COMPILER;
2371  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2372    
# Line 2053  else if (common->mode == JIT_PARTIAL_SOF Line 2381  else if (common->mode == JIT_PARTIAL_SOF
2381    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);
2382    
2383  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2384    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);
2385  else  else
2386    {    {
2387    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2066  if (jump != NULL) Line 2394  if (jump != NULL)
2394    JUMPHERE(jump);    JUMPHERE(jump);
2395  }  }
2396    
2397  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2398  {  {
2399  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2400  DEFINE_COMPILER;  DEFINE_COMPILER;
2401  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2402    
2403  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2404    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2405      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2406      return;
2407      }
2408    
2409  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2410  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2411    {    {
2412    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));
2413    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);
2414    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2415    }    }
2416  else  else
2417    {    {
2418    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));
2419    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2420      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2421    else    else
2422      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2423    }    }
2424  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2425  }  }
2426    
2427  static void detect_partial_match(compiler_common *common, jump_list **backtracks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
# Line 2113  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR Line 2440  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2440  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));
2441  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2442    {    {
2443    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);
2444    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2445    }    }
2446  else  else
# Line 2204  if (common->utf) Line 2531  if (common->utf)
2531    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2532    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2533    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);
2534    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2535    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2536    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2537  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
# Line 2254  if (common->utf) Line 2581  if (common->utf)
2581    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2582    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2583    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);
2584    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2585    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2586    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2587    return;    return;
# Line 2277  if (nltype == NLTYPE_ANY) Line 2604  if (nltype == NLTYPE_ANY)
2604  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2605    {    {
2606    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);
2607    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2608    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);
2609    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);
2610    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));
2611    }    }
2612  else  else
# Line 2379  sljit_emit_fast_return(compiler, RETURN_ Line 2706  sljit_emit_fast_return(compiler, RETURN_
2706  JUMPHERE(jump);  JUMPHERE(jump);
2707    
2708  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2709  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);
2710  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2711  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2712  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
# Line 2432  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 2759  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2759    
2760  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2761  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2762  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));
2763  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2764  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2765  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2766  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2767  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2768  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));
2769  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2770  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2771  }  }
# Line 2452  struct sljit_label *newlinelabel = NULL; Line 2779  struct sljit_label *newlinelabel = NULL;
2779  struct sljit_jump *start;  struct sljit_jump *start;
2780  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2781  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2782  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2783  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2784  #endif  #endif
2785  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 2507  if (newlinecheck) Line 2834  if (newlinecheck)
2834    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2835    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2836    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);
2837    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2838  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2839    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2840  #endif  #endif
# Line 2535  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S Line 2862  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S
2862  if (common->utf)  if (common->utf)
2863    {    {
2864    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2865    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);
2866    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2867    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2868    }    }
# Line 2545  if (common->utf) Line 2872  if (common->utf)
2872    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2873    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2874    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);
2875    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2876    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2877    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2878    JUMPHERE(singlechar);    JUMPHERE(singlechar);
# Line 2571  DEFINE_COMPILER; Line 2898  DEFINE_COMPILER;
2898  struct sljit_label *start;  struct sljit_label *start;
2899  struct sljit_jump *quit;  struct sljit_jump *quit;
2900  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uint32 chars[MAX_N_CHARS * 2];
2901  pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  pcre_uchar *cc = common->start + 1 + LINK_SIZE;
2902  int location = 0;  int location = 0;
2903  pcre_int32 len, c, bit, caseless;  pcre_int32 len, c, bit, caseless;
2904  int must_stop;  int must_stop;
# Line 2643  while (TRUE) Line 2970  while (TRUE)
2970        break;        break;
2971    
2972    len = 1;    len = 1;
2973  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
2974    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
2975  #endif  #endif
2976    
# Line 2694  if (firstline) Line 3021  if (firstline)
3021    {    {
3022    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3023    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3024    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));
3025    }    }
3026  else  else
3027    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));
3028    
3029  start = LABEL();  start = LABEL();
3030  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
# Line 2726  JUMPHERE(quit); Line 3053  JUMPHERE(quit);
3053  if (firstline)  if (firstline)
3054    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3055  else  else
3056    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));
3057  return TRUE;  return TRUE;
3058  }  }
3059    
# Line 2773  else Line 3100  else
3100    else    else
3101      {      {
3102      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);
3103      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3104      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);
3105      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);
3106      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3107      }      }
3108    }    }
# Line 2817  if (common->nltype == NLTYPE_FIXED && co Line 3144  if (common->nltype == NLTYPE_FIXED && co
3144    
3145    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3146    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);
3147    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3148  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3149    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3150  #endif  #endif
# Line 2860  if (common->nltype == NLTYPE_ANY || comm Line 3187  if (common->nltype == NLTYPE_ANY || comm
3187    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3188    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3189    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);
3190    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3191  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3192    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3193  #endif  #endif
# Line 2875  if (firstline) Line 3202  if (firstline)
3202    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3203  }  }
3204    
3205    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3206    
3207  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)
3208  {  {
3209  DEFINE_COMPILER;  DEFINE_COMPILER;
3210  struct sljit_label *start;  struct sljit_label *start;
3211  struct sljit_jump *quit;  struct sljit_jump *quit;
3212  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3213    jump_list *matches = NULL;
3214    pcre_uint8 inverted_start_bits[32];
3215    int i;
3216  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3217  struct sljit_jump *jump;  struct sljit_jump *jump;
3218  #endif  #endif
3219    
3220    for (i = 0; i < 32; ++i)
3221      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3222    
3223  if (firstline)  if (firstline)
3224    {    {
3225    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
# Line 2899  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 3234  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3234  if (common->utf)  if (common->utf)
3235    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3236  #endif  #endif
3237    
3238    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3239      {
3240  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3241  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3242  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3243  JUMPHERE(jump);    JUMPHERE(jump);
3244  #endif  #endif
3245  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3246  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3247  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3248  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3249  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);
3250  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3251      }
3252    
3253  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3254  if (common->utf)  if (common->utf)
# Line 2921  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S Line 3260  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S
3260  if (common->utf)  if (common->utf)
3261    {    {
3262    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3263    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);
3264    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3265    }    }
3266  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
# Line 2930  if (common->utf) Line 3269  if (common->utf)
3269    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3270    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3271    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);
3272    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3273    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3274    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3275    }    }
3276  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE[8|16] */
3277  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3278  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3279  JUMPHERE(found);  if (found != NULL)
3280      JUMPHERE(found);
3281    if (matches != NULL)
3282      set_jumps(matches, LABEL());
3283  JUMPHERE(quit);  JUMPHERE(quit);
3284    
3285  if (firstline)  if (firstline)
# Line 3020  GET_LOCAL_BASE(TMP3, 0, 0); Line 3362  GET_LOCAL_BASE(TMP3, 0, 0);
3362  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3363  mainloop = LABEL();  mainloop = LABEL();
3364  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3365  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);
3366    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3367    
3368  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3369  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));
3370  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));
3371  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));
3372  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3373    
3374  JUMPHERE(jump);  JUMPHERE(jump);
3375  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3376  /* End of dropping frames. */  /* End of dropping frames. */
3377  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3378    
3379  JUMPHERE(jump);  JUMPHERE(jump);
3380  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3381  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3382  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3383  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));  
3384  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3385  }  }
3386    
# Line 3061  static void check_wordboundary(compiler_ Line 3388  static void check_wordboundary(compiler_
3388  {  {
3389  DEFINE_COMPILER;  DEFINE_COMPILER;
3390  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3391    jump_list *skipread_list = NULL;
3392  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3393  struct sljit_jump *jump;  struct sljit_jump *jump;
3394  #endif  #endif
# Line 3086  if (common->use_ucp) Line 3414  if (common->use_ucp)
3414    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3415    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3416    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);
3417    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3418    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);
3419    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);
3420    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3421    JUMPHERE(jump);    JUMPHERE(jump);
3422    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3423    }    }
# Line 3118  else Line 3446  else
3446  JUMPHERE(skipread);  JUMPHERE(skipread);
3447    
3448  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3449  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3450  peek_char(common);  peek_char(common);
3451    
3452  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 3130  if (common->use_ucp) Line 3458  if (common->use_ucp)
3458    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3459    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3460    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);
3461    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3462    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);
3463    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);
3464    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3465    JUMPHERE(jump);    JUMPHERE(jump);
3466    }    }
3467  else  else
# Line 3159  else Line 3487  else
3487      JUMPHERE(jump);      JUMPHERE(jump);
3488  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3489    }    }
3490  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3491    
3492  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);
3493  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
# Line 3313  sljit_emit_fast_enter(compiler, RETURN_A Line 3641  sljit_emit_fast_enter(compiler, RETURN_A
3641    
3642  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3643  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);
3644  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3645  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);
3646  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3647  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3648  if (common->utf)  if (common->utf)
3649    {    {
3650  #endif  #endif
3651    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3652    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3653    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);
3654  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3655    }    }
3656  #endif  #endif
3657  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3658  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);
3659  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3660  }  }
3661    
# Line 3339  DEFINE_COMPILER; Line 3667  DEFINE_COMPILER;
3667  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3668    
3669  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);
3670  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3671  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);
3672  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3673  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);
3674  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3675  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3676  if (common->utf)  if (common->utf)
3677    {    {
3678  #endif  #endif
3679    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3680    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);
3681    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3682    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);
3683    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3684    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3685    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);
3686    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3687    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);
3688    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3689    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);
3690    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3691    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);
3692  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3693    }    }
3694  #endif  #endif
3695  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3696  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);
3697    
3698  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3699  }  }
# Line 3379  sljit_emit_fast_enter(compiler, RETURN_A Line 3707  sljit_emit_fast_enter(compiler, RETURN_A
3707    
3708  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3709  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);
3710  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3711  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);
3712  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3713  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3714  if (common->utf)  if (common->utf)
3715    {    {
3716  #endif  #endif
3717    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);
3718    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3719    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);
3720  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3721    }    }
3722  #endif  #endif
3723  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3724  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);
3725    
3726  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3727  }  }
# Line 3479  sljit_emit_fast_return(compiler, RETURN_ Line 3807  sljit_emit_fast_return(compiler, RETURN_
3807    
3808  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3809    
3810  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)
3811  {  {
3812  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3813  pcre_uint32 c1, c2;  pcre_uint32 c1, c2;
# Line 3529  if (caseless && char_has_othercase(commo Line 3857  if (caseless && char_has_othercase(commo
3857    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
3858    othercasebit &= 0xff;    othercasebit &= 0xff;
3859  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3860      /* Note that this code only handles characters in the BMP. If there
3861      ever are characters outside the BMP whose othercase differs in only one
3862      bit from itself (there currently are none), this code will need to be
3863      revised for COMPILE_PCRE32. */
3864    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
3865    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
3866      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
# Line 3563  if (context->sourcereg == -1) Line 3895  if (context->sourcereg == -1)
3895    
3896  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3897  utflength = 1;  utflength = 1;
 #ifndef COMPILE_PCRE32  
3898  if (common->utf && HAS_EXTRALEN(*cc))  if (common->utf && HAS_EXTRALEN(*cc))
3899    utflength += GET_EXTRALEN(*cc);    utflength += GET_EXTRALEN(*cc);
 #endif  
3900    
3901  do  do
3902    {    {
3903  #endif  #endif
3904    
3905    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3906  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3907    
3908    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3909    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3590  do Line 3920  do
3920    
3921  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
3922    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))
3923  #elif defined COMPILE_PCRE16  #else
3924    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 */)  
3925  #endif  #endif
3926      {      {
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
3927      if (context->length >= 4)      if (context->length >= 4)
3928        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  
3929      else if (context->length >= 2)      else if (context->length >= 2)
3930        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);
3931    #if defined COMPILE_PCRE8
3932      else if (context->length >= 1)      else if (context->length >= 1)
3933        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);
3934  #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] */  
3935      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3936    
3937      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3621  do Line 3942  do
3942        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));
3943        break;        break;
3944    
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
3945        case 2 / sizeof(pcre_uchar):        case 2 / sizeof(pcre_uchar):
3946        if (context->oc.asushort != 0)        if (context->oc.asushort != 0)
3947          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asushort);          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asushort);
# Line 3636  do Line 3956  do
3956        break;        break;
3957  #endif  #endif
3958    
 #endif /* COMPILE_PCRE[8|16] */  
   
3959        default:        default:
3960        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
3961        break;        break;
# Line 3647  do Line 3965  do
3965    
3966  #else  #else
3967    
3968    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3969    if (context->length > 0)    if (context->length >= 1)
3970      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3971    
3972    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
# Line 3731  if ((*cc++ & XCL_MAP) != 0) Line 4049  if ((*cc++ & XCL_MAP) != 0)
4049      {      {
4050      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4051      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4052      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4053      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4054      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);
4055      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
# Line 3759  while (*cc != XCL_END) Line 4077  while (*cc != XCL_END)
4077    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
4078      {      {
4079      cc += 2;      cc += 2;
4080  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
4081      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
4082  #endif  #endif
4083  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 3769  while (*cc != XCL_END) Line 4087  while (*cc != XCL_END)
4087    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
4088      {      {
4089      cc += 2;      cc += 2;
4090  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
4091      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
4092  #endif  #endif
4093      cc++;      cc++;
4094  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
4095      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
4096  #endif  #endif
4097  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 3809  while (*cc != XCL_END) Line 4127  while (*cc != XCL_END)
4127        break;        break;
4128    
4129        case PT_CLIST:        case PT_CLIST:
4130          case PT_UCNC:
4131        needschar = TRUE;        needschar = TRUE;
4132        break;        break;
4133    
# Line 3848  if (needstype || needsscript) Line 4167  if (needstype || needsscript)
4167      {      {
4168      if (scriptreg == TMP1)      if (scriptreg == TMP1)
4169        {        {
4170        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));
4171        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
4172        }        }
4173      else      else
4174        {        {
4175        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
4176        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));
4177        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
4178        }        }
4179      }      }
# Line 3890  while (*cc != XCL_END) Line 4209  while (*cc != XCL_END)
4209      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4210        {        {
4211        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);
4212        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);
4213        numberofcmps++;        numberofcmps++;
4214        }        }
4215      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4216        {        {
4217        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);
4218        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);
4219        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4220        numberofcmps = 0;        numberofcmps = 0;
4221        }        }
# Line 3929  while (*cc != XCL_END) Line 4248  while (*cc != XCL_END)
4248      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4249        {        {
4250        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);
4251        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);
4252        numberofcmps++;        numberofcmps++;
4253        }        }
4254      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4255        {        {
4256        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);
4257        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);
4258        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4259        numberofcmps = 0;        numberofcmps = 0;
4260        }        }
# Line 3966  while (*cc != XCL_END) Line 4285  while (*cc != XCL_END)
4285    
4286        case PT_LAMP:        case PT_LAMP:
4287        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);
4288        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4289        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);
4290        COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4291        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);
4292        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);
4293        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4294        break;        break;
4295    
# Line 3990  while (*cc != XCL_END) Line 4309  while (*cc != XCL_END)
4309    
4310        case PT_SPACE:        case PT_SPACE:
4311        case PT_PXSPACE:        case PT_PXSPACE:
       if (*cc == PT_SPACE)  
         {  
         OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  
         jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 11 - charoffset);  
         }  
4312        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4313        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);
4314        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
       if (*cc == PT_SPACE)  
         JUMPHERE(jump);  
4315    
4316        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4317        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);
4318        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);
4319        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4320        break;        break;
4321    
4322        case PT_WORD:        case PT_WORD:
4323        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);
4324        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4325        /* ... fall through */        /* Fall through. */
4326    
4327        case PT_ALNUM:        case PT_ALNUM:
4328        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
4329        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);
4330        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);
4331        SET_TYPE_OFFSET(ucp_Nd);        SET_TYPE_OFFSET(ucp_Nd);
4332        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);
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    
# Line 4037  while (*cc != XCL_END) Line 4349  while (*cc != XCL_END)
4349            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]);
4350          else          else
4351            {            {
4352            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_w)charoffset);            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4353            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]);
4354            }            }
4355          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]);
4356          COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4357          other_cases += 2;          other_cases += 2;
4358          }          }
4359        else if (is_powerof2(other_cases[2] ^ other_cases[1]))        else if (is_powerof2(other_cases[2] ^ other_cases[1]))
# Line 4050  while (*cc != XCL_END) Line 4362  while (*cc != XCL_END)
4362            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]);
4363          else          else
4364            {            {
4365            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_w)charoffset);            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4366            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]);
4367            }            }
4368          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]);
4369          COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4370    
4371          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);
4372          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);
4373    
4374          other_cases += 3;          other_cases += 3;
4375          }          }
4376        else        else
4377          {          {
4378          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);
4379          COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4380          }          }
4381    
4382        while (*other_cases != NOTACHAR)        while (*other_cases != NOTACHAR)
4383          {          {
4384          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);
4385          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);
4386          }          }
4387        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4388        break;        break;
4389    
4390          case PT_UCNC:
4391          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);
4392          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4393          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);
4394          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4395          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);
4396          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4397    
4398          SET_CHAR_OFFSET(0xa0);
4399          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);
4400          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4401          SET_CHAR_OFFSET(0);
4402          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
4403          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4404          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4405          break;
4406        }        }
4407      cc += 2;      cc += 2;
4408      }      }
# Line 4099  int length; Line 4428  int length;
4428  unsigned int c, oc, bit;  unsigned int c, oc, bit;
4429  compare_context context;  compare_context context;
4430  struct sljit_jump *jump[4];  struct sljit_jump *jump[4];
4431    jump_list *end_list;
4432  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4433  struct sljit_label *label;  struct sljit_label *label;
4434  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4167  switch(type) Line 4497  switch(type)
4497    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4498      {      {
4499      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);
4500        end_list = NULL;
4501      if (common->mode != JIT_PARTIAL_HARD_COMPILE)      if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4502        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));
4503      else      else
4504        jump[1] = check_str_end(common);        check_str_end(common, &end_list);
4505    
4506      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4507      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));
4508      if (jump[1] != NULL)      set_jumps(end_list, LABEL());
       JUMPHERE(jump[1]);  
4509      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4510      }      }
4511    else    else
# Line 4192  switch(type) Line 4522  switch(type)
4522  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16
4523  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
4524      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4525      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);
4526      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4527  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
4528      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
4529      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
4530      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);
4531      COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4532      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4533      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4534  #endif  #endif
# Line 4234  switch(type) Line 4564  switch(type)
4564    read_char(common);    read_char(common);
4565    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);
4566    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
4567      end_list = NULL;
4568    if (common->mode != JIT_PARTIAL_HARD_COMPILE)    if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4569      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));
4570    else    else
4571      jump[1] = check_str_end(common);      check_str_end(common, &end_list);
4572    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4573    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);
4574    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));
4575    jump[3] = JUMP(SLJIT_JUMP);    jump[2] = JUMP(SLJIT_JUMP);
4576    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4577    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);
4578      set_jumps(end_list, LABEL());
4579    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
4580    JUMPHERE(jump[2]);    JUMPHERE(jump[2]);
   JUMPHERE(jump[3]);  
4581    return cc;    return cc;
4582    
4583    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
# Line 4270  switch(type) Line 4601  switch(type)
4601    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4602    read_char(common);    read_char(common);
4603    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4604    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));
4605    /* Optimize register allocation: use a real register. */    /* Optimize register allocation: use a real register. */
4606    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
4607    OP1(SLJIT_MOV_UB, STACK_TOP, 0, SLJIT_MEM2(TMP1, TMP2), 3);    OP1(SLJIT_MOV_UB, STACK_TOP, 0, SLJIT_MEM2(TMP1, TMP2), 3);
# Line 4280  switch(type) Line 4611  switch(type)
4611    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
4612    read_char(common);    read_char(common);
4613    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4614    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));
4615    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4616    
4617    OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);    OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);
4618    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));
4619    OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);    OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);
4620    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4621    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
# Line 4317  switch(type) Line 4648  switch(type)
4648        {        {
4649        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);
4650        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);
4651        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS);
4652        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);
4653        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);
4654        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));
4655        check_partial(common, TRUE);        check_partial(common, TRUE);
4656        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
# Line 4467  switch(type) Line 4798  switch(type)
4798    case OP_CHAR:    case OP_CHAR:
4799    case OP_CHARI:    case OP_CHARI:
4800    length = 1;    length = 1;
4801  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
4802    if (common->utf && HAS_EXTRALEN(*cc)) length += GET_EXTRALEN(*cc);    if (common->utf && HAS_EXTRALEN(*cc)) length += GET_EXTRALEN(*cc);
4803  #endif  #endif
4804    if (common->mode == JIT_COMPILE && (type == OP_CHAR || !char_has_othercase(common, cc) || char_get_othercase_bit(common, cc) != 0))    if (common->mode == JIT_COMPILE && (type == OP_CHAR || !char_has_othercase(common, cc) || char_get_othercase_bit(common, cc) != 0))
# Line 4506  switch(type) Line 4837  switch(type)
4837      return cc + length;      return cc + length;
4838      }      }
4839    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);
4840    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4841    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);
4842    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);
4843    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
4844    return cc + length;    return cc + length;
4845    
# Line 4535  switch(type) Line 4866  switch(type)
4866        /* Skip the variable-length character. */        /* Skip the variable-length character. */
4867        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));
4868        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4869        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);
4870        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4871        JUMPHERE(jump[0]);        JUMPHERE(jump[0]);
4872        return cc + 1;        return cc + 1;
# Line 4598  switch(type) Line 4929  switch(type)
4929  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4930    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4931    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4932    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4933    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4934    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);
4935    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 4662  do Line 4993  do
4993    if (*cc == OP_CHAR)    if (*cc == OP_CHAR)
4994      {      {
4995      size = 1;      size = 1;
4996  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
4997      if (common->utf && HAS_EXTRALEN(cc[1]))      if (common->utf && HAS_EXTRALEN(cc[1]))
4998        size += GET_EXTRALEN(cc[1]);        size += GET_EXTRALEN(cc[1]);
4999  #endif  #endif
# Line 4675  do Line 5006  do
5006        {        {
5007        if (char_has_othercase(common, cc + 1) && char_get_othercase_bit(common, cc + 1) == 0)        if (char_has_othercase(common, cc + 1) && char_get_othercase_bit(common, cc + 1) == 0)
5008          size = 0;          size = 0;
 #ifndef COMPILE_PCRE32  
5009        else if (HAS_EXTRALEN(cc[1]))        else if (HAS_EXTRALEN(cc[1]))
5010          size += GET_EXTRALEN(cc[1]);          size += GET_EXTRALEN(cc[1]);
 #endif  
5011        }        }
5012      else      else
5013  #endif  #endif
# Line 4712  if (context.length > 0) Line 5041  if (context.length > 0)
5041  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);  return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);
5042  }  }
5043    
 static struct sljit_jump *compile_ref_checks(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)  
 {  
 DEFINE_COMPILER;  
 int offset = GET2(cc, 1) << 1;  
   
 OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  
 if (!common->jscript_compat)  
   {  
   if (backtracks == NULL)  
     {  
     /* OVECTOR(1) contains the "string begin - 1" constant. */  
     OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  
     COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  
     OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
     COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);  
     return JUMP(SLJIT_C_NOT_ZERO);  
     }  
   add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));  
   }  
 return CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
 }  
   
5044  /* Forward definitions. */  /* Forward definitions. */
5045  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);  static void compile_matchingpath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);
5046  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);  static void compile_backtrackingpath(compiler_common *, struct backtrack_common *);
# Line 4766  static void compile_backtrackingpath(com Line 5073  static void compile_backtrackingpath(com
5073    
5074  #define BACKTRACK_AS(type) ((type *)backtrack)  #define BACKTRACK_AS(type) ((type *)backtrack)
5075    
5076  static pcre_uchar *compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)  static void compile_dnref_search(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)
5077  {  {
5078    /* The OVECTOR offset goes to TMP2. */
5079  DEFINE_COMPILER;  DEFINE_COMPILER;
5080  int offset = GET2(cc, 1) << 1;  int count = GET2(cc, 1 + IMM2_SIZE);
5081    pcre_uchar *slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
5082    unsigned int offset;
5083    jump_list *found = NULL;
5084    
5085    SLJIT_ASSERT(*cc == OP_DNREF || *cc == OP_DNREFI);
5086    
5087    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
5088    
5089    count--;
5090    while (count-- > 0)
5091      {
5092      offset = GET2(slot, 0) << 1;
5093      GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5094      add_jump(compiler, &found, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5095      slot += common->name_entry_size;
5096      }
5097    
5098    offset = GET2(slot, 0) << 1;
5099    GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5100    if (backtracks != NULL && !common->jscript_compat)
5101      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5102    
5103    set_jumps(found, LABEL());
5104    }
5105    
5106    static void compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)
5107    {
5108    DEFINE_COMPILER;
5109    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5110    int offset = 0;
5111  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
5112  struct sljit_jump *partial;  struct sljit_jump *partial;
5113  struct sljit_jump *nopartial;  struct sljit_jump *nopartial;
5114    
5115  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  if (ref)
5116  /* OVECTOR(1) contains the "string begin - 1" constant. */    {
5117  if (withchecks && !common->jscript_compat)    offset = GET2(cc, 1) << 1;
5118    add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5119      /* OVECTOR(1) contains the "string begin - 1" constant. */
5120      if (withchecks && !common->jscript_compat)
5121        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5122      }
5123    else
5124      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5125    
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));    if (ref)
5131        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5132      else
5133        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5134    
5135    if (withchecks)    if (withchecks)
5136      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5137    
5138    /* Needed to save important temporary registers. */    /* Needed to save important temporary registers. */
5139    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5140    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
5141    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);
5142    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));
5143    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5144    if (common->mode == JIT_COMPILE)    if (common->mode == JIT_COMPILE)
# Line 4808  if (common->utf && *cc == OP_REFI) Line 5156  if (common->utf && *cc == OP_REFI)
5156  else  else
5157  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
5158    {    {
5159    OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);    if (ref)
5160        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
5161      else
5162        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
5163    
5164    if (withchecks)    if (withchecks)
5165      jump = JUMP(SLJIT_C_ZERO);      jump = JUMP(SLJIT_C_ZERO);
5166    
# Line 4845  if (jump != NULL) Line 5197  if (jump != NULL)
5197    else    else
5198      JUMPHERE(jump);      JUMPHERE(jump);
5199    }    }
 return cc + 1 + IMM2_SIZE;  
5200  }  }
5201    
5202  static SLJIT_INLINE pcre_uchar *compile_ref_iterator_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)  static SLJIT_INLINE pcre_uchar *compile_ref_iterator_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5203  {  {
5204  DEFINE_COMPILER;  DEFINE_COMPILER;
5205    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5206  backtrack_common *backtrack;  backtrack_common *backtrack;
5207  pcre_uchar type;  pcre_uchar type;
5208    int offset = 0;
5209  struct sljit_label *label;  struct sljit_label *label;
5210  struct sljit_jump *zerolength;  struct sljit_jump *zerolength;
5211  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 4862  BOOL minimize; Line 5215  BOOL minimize;
5215    
5216  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
5217    
5218    if (ref)
5219      offset = GET2(cc, 1) << 1;
5220    else
5221      cc += IMM2_SIZE;
5222  type = cc[1 + IMM2_SIZE];  type = cc[1 + IMM2_SIZE];
5223    
5224    SLJIT_COMPILE_ASSERT((OP_CRSTAR & 0x1) == 0, crstar_opcode_must_be_even);
5225  minimize = (type & 0x1) != 0;  minimize = (type & 0x1) != 0;
5226  switch(type)  switch(type)
5227    {    {
# Line 4900  if (!minimize) Line 5259  if (!minimize)
5259    if (min == 0)    if (min == 0)
5260      {      {
5261      allocate_stack(common, 2);      allocate_stack(common, 2);
5262        if (ref)
5263          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5264      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5265      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5266      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5267      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));
5268      zerolength = compile_ref_checks(common, ccbegin, NULL);      /* Handles both invalid and empty cases. Since the minimum repeat,
5269        is zero the invalid case is basically the same as an empty case. */
5270        if (ref)
5271          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5272        else
5273          {
5274          compile_dnref_search(common, ccbegin, NULL);
5275          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5276          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5277          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5278          }
5279      /* Restore if not zero length. */      /* Restore if not zero length. */
5280      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));
5281      }      }
5282    else    else
5283      {      {
5284      allocate_stack(common, 1);      allocate_stack(common, 1);
5285        if (ref)
5286          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5287      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5288      zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);      if (ref)
5289          {
5290          add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5291          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5292          }
5293        else
5294          {
5295          compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5296          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5297          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5298          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5299          }
5300      }      }
5301    
5302    if (min > 1 || max > 1)    if (min > 1 || max > 1)
5303      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
5304    
5305    label = LABEL();    label = LABEL();
5306      if (!ref)
5307        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
5308    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);
5309    
5310    if (min > 1 || max > 1)    if (min > 1 || max > 1)
# Line 4949  if (!minimize) Line 5335  if (!minimize)
5335    JUMPHERE(zerolength);    JUMPHERE(zerolength);
5336    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5337    
5338    decrease_call_count(common);    count_match(common);
5339    return cc;    return cc;
5340    }    }
5341    
5342  allocate_stack(common, 2);  allocate_stack(common, ref ? 2 : 3);
5343    if (ref)
5344      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5345  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5346  if (type != OP_CRMINSTAR)  if (type != OP_CRMINSTAR)
5347    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5348    
5349  if (min == 0)  if (min == 0)
5350    {    {
5351    zerolength = compile_ref_checks(common, ccbegin, NULL);    /* Handles both invalid and empty cases. Since the minimum repeat,
5352      is zero the invalid case is basically the same as an empty case. */
5353      if (ref)
5354        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5355      else
5356        {
5357        compile_dnref_search(common, ccbegin, NULL);
5358        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5359        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5360        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5361        }
5362      /* Length is non-zero, we can match real repeats. */
5363    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5364    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
5365    }    }
5366  else  else
5367    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);    {
5368      if (ref)
5369        {
5370        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5371        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5372        }
5373      else
5374        {
5375        compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5376        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5377        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5378        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5379        }
5380      }
5381    
5382  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5383  if (max > 0)  if (max > 0)
5384    add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, max));    add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, max));
5385    
5386    if (!ref)
5387      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
5388  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);
5389  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5390    
# Line 4988  if (jump != NULL) Line 5402  if (jump != NULL)
5402    JUMPHERE(jump);    JUMPHERE(jump);
5403  JUMPHERE(zerolength);  JUMPHERE(zerolength);
5404    
5405  decrease_call_count(common);  count_match(common);
5406  return cc;  return cc;
5407  }  }
5408    
# Line 4998  DEFINE_COMPILER; Line 5412  DEFINE_COMPILER;
5412  backtrack_common *backtrack;  backtrack_common *backtrack;
5413  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5414  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5415  int start = GET(cc, 1);  sljit_sw start = GET(cc, 1);
5416    pcre_uchar *start_cc;
5417    BOOL needs_control_head;
5418    
5419  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5420    
5421    /* Inlining simple patterns. */
5422    if (get_framesize(common, common->start + start, NULL, TRUE, &needs_control_head) == no_stack)
5423      {
5424      start_cc = common->start + start;
5425      compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
5426      BACKTRACK_AS(recurse_backtrack)->inlined_pattern = TRUE;
5427      return cc + 1 + LINK_SIZE;
5428      }
5429    
5430  while (entry != NULL)  while (entry != NULL)
5431    {    {
5432    if (entry->start == start)    if (entry->start == start)
# Line 5049  add_jump(compiler, &backtrack->topbacktr Line 5475  add_jump(compiler, &backtrack->topbacktr
5475  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5476  }  }
5477    
5478    static int SLJIT_CALL do_callout(struct jit_arguments* arguments, PUBL(callout_block) *callout_block, pcre_uchar **jit_ovector)
5479    {
5480    const pcre_uchar *begin = arguments->begin;
5481    int *offset_vector = arguments->offsets;
5482    int offset_count = arguments->offset_count;
5483    int i;
5484    
5485    if (PUBL(callout) == NULL)
5486      return 0;
5487    
5488    callout_block->version = 2;
5489    callout_block->callout_data = arguments->callout_data;
5490    
5491    /* Offsets in subject. */
5492    callout_block->subject_length = arguments->end - arguments->begin;
5493    callout_block->start_match = (pcre_uchar*)callout_block->subject - arguments->begin;
5494    callout_block->current_position = (pcre_uchar*)callout_block->offset_vector - arguments->begin;
5495    #if defined COMPILE_PCRE8
5496    callout_block->subject = (PCRE_SPTR)begin;
5497    #elif defined COMPILE_PCRE16
5498    callout_block->subject = (PCRE_SPTR16)begin;
5499    #elif defined COMPILE_PCRE32
5500    callout_block->subject = (PCRE_SPTR32)begin;
5501    #endif
5502    
5503    /* Convert and copy the JIT offset vector to the offset_vector array. */
5504    callout_block->capture_top = 0;
5505    callout_block->offset_vector = offset_vector;
5506    for (i = 2; i < offset_count; i += 2)
5507      {
5508      offset_vector[i] = jit_ovector[i] - begin;
5509      offset_vector[i + 1] = jit_ovector[i + 1] - begin;
5510      if (jit_ovector[i] >= begin)
5511        callout_block->capture_top = i;
5512      }
5513    
5514    callout_block->capture_top = (callout_block->capture_top >> 1) + 1;
5515    if (offset_count > 0)
5516      offset_vector[0] = -1;
5517    if (offset_count > 1)
5518      offset_vector[1] = -1;
5519    return (*PUBL(callout))(callout_block);
5520    }
5521    
5522    /* Aligning to 8 byte. */
5523    #define CALLOUT_ARG_SIZE \
5524        (((int)sizeof(PUBL(callout_block)) + 7) & ~7)
5525    
5526    #define CALLOUT_ARG_OFFSET(arg) \
5527        (-CALLOUT_ARG_SIZE + SLJIT_OFFSETOF(PUBL(callout_block), arg))
5528    
5529    static SLJIT_INLINE pcre_uchar *compile_callout_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5530    {
5531    DEFINE_COMPILER;
5532    backtrack_common *backtrack;
5533    
5534    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
5535    
5536    allocate_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5537    
5538    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
5539    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
5540    SLJIT_ASSERT(common->capture_last_ptr != 0);
5541    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);
5542    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);
5543    
5544    /* These pointer sized fields temporarly stores internal variables. */
5545    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
5546    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(offset_vector), STR_PTR, 0);
5547    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(subject), TMP2, 0);
5548    
5549    if (common->mark_ptr != 0)
5550      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr));
5551    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 2));
5552    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 2 + LINK_SIZE));
5553    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);
5554    
5555    /* Needed to save important temporary registers. */
5556    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5557    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, STACK_TOP, 0, SLJIT_IMM, CALLOUT_ARG_SIZE);
5558    GET_LOCAL_BASE(SLJIT_SCRATCH_REG3, 0, OVECTOR_START);
5559    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_callout));
5560    OP1(SLJIT_MOV_SI, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0);
5561    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5562    free_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5563    
5564    /* Check return value. */
5565    OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
5566    add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_C_SIG_GREATER));
5567    if (common->forced_quit_label == NULL)
5568      add_jump(compiler, &common->forced_quit, JUMP(SLJIT_C_SIG_LESS));
5569    else
5570      JUMPTO(SLJIT_C_SIG_LESS, common->forced_quit_label);
5571    return cc + 2 + 2 * LINK_SIZE;
5572    }
5573    
5574    #undef CALLOUT_ARG_SIZE
5575    #undef CALLOUT_ARG_OFFSET
5576    
5577  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)
5578  {  {
5579  DEFINE_COMPILER;  DEFINE_COMPILER;
5580  int framesize;  int framesize;
5581    int extrasize;
5582    BOOL needs_control_head;
5583  int private_data_ptr;  int private_data_ptr;
5584  backtrack_common altbacktrack;  backtrack_common altbacktrack;
5585  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
# Line 5062  jump_list *tmp = NULL; Line 5589  jump_list *tmp = NULL;
5589  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5590  jump_list **found;  jump_list **found;
5591  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5592  struct sljit_label *save_quitlabel = common->quitlabel;  BOOL save_local_exit = common->local_exit;
5593  struct sljit_label *save_acceptlabel = common->acceptlabel;  BOOL save_positive_assert = common->positive_assert;
5594    then_trap_backtrack *save_then_trap = common->then_trap;
5595    struct sljit_label *save_quit_label = common->quit_label;
5596    struct sljit_label *save_accept_label = common->accept_label;
5597  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
5598    jump_list *save_positive_assert_quit = common->positive_assert_quit;
5599  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
5600  struct sljit_jump *jump;  struct sljit_jump *jump;
5601  struct sljit_jump *brajump = NULL;  struct sljit_jump *brajump = NULL;
5602    
5603    /* Assert captures then. */
5604    common->then_trap = NULL;
5605    
5606  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
5607    {    {
5608    SLJIT_ASSERT(!conditional);    SLJIT_ASSERT(!conditional);
# Line 5077  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 5611  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
5611    }    }
5612  private_data_ptr = PRIVATE_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
5613  SLJIT_ASSERT(private_data_ptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
5614  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
5615  backtrack->framesize = framesize;  backtrack->framesize = framesize;
5616  backtrack->private_data_ptr = private_data_ptr;  backtrack->private_data_ptr = private_data_ptr;
5617  opcode = *cc;  opcode = *cc;
# Line 5096  if (bra == OP_BRAMINZERO) Line 5630  if (bra == OP_BRAMINZERO)
5630    
5631  if (framesize < 0)  if (framesize < 0)
5632    {    {
5633    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    extrasize = needs_control_head ? 2 : 1;
5634    allocate_stack(common, 1);    if (framesize == no_frame)
5635        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
5636      allocate_stack(common, extrasize);
5637      if (needs_control_head)
5638        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5639    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5640      if (needs_control_head)
5641        {
5642        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5643        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5644        }
5645    }    }
5646  else  else
5647    {    {
5648    allocate_stack(common, framesize + 2);    extrasize = needs_control_head ? 3 : 2;
5649      allocate_stack(common, framesize + extrasize);
5650    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);
5651    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));
5652    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);
5653      if (needs_control_head)
5654        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5655    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5656    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    if (needs_control_head)
5657    init_frame(common, ccbegin, framesize + 1, 2, FALSE);      {
5658        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
5659        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
5660        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5661        }
5662      else
5663        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5664      init_frame(common, ccbegin, NULL, framesize + extrasize - 1, extrasize, FALSE);
5665    }    }
5666    
5667  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
5668  common->quitlabel = NULL;  if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5669  common->quit = NULL;    {
5670      /* Negative assert is stronger than positive assert. */
5671      common->local_exit = TRUE;
5672      common->quit_label = NULL;
5673      common->quit = NULL;
5674      common->positive_assert = FALSE;
5675      }
5676    else
5677      common->positive_assert = TRUE;
5678    common->positive_assert_quit = NULL;
5679    
5680  while (1)  while (1)
5681    {    {
5682    common->acceptlabel = NULL;    common->accept_label = NULL;
5683    common->accept = NULL;    common->accept = NULL;
5684    altbacktrack.top = NULL;    altbacktrack.top = NULL;
5685    altbacktrack.topbacktracks = NULL;    altbacktrack.topbacktracks = NULL;
# Line 5128  while (1) Line 5691  while (1)
5691    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
5692    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5693      {      {
5694      common->quitlabel = save_quitlabel;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5695      common->acceptlabel = save_acceptlabel;        {
5696      common->quit = save_quit;        common->local_exit = save_local_exit;
5697          common->quit_label = save_quit_label;
5698          common->quit = save_quit;
5699          }
5700        common->positive_assert = save_positive_assert;
5701        common->then_trap = save_then_trap;
5702        common->accept_label = save_accept_label;
5703        common->positive_assert_quit = save_positive_assert_quit;
5704      common->accept = save_accept;      common->accept = save_accept;
5705      return NULL;      return NULL;
5706      }      }
5707    common->acceptlabel = LABEL();    common->accept_label = LABEL();
5708    if (common->accept != NULL)    if (common->accept != NULL)
5709      set_jumps(common->accept, common->acceptlabel);      set_jumps(common->accept, common->accept_label);
5710    
5711    /* Reset stack. */    /* Reset stack. */
5712    if (framesize < 0)    if (framesize < 0)
5713      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      {
5714    else {      if (framesize == no_frame)
5715          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5716        else
5717          free_stack(common, extrasize);
5718        if (needs_control_head)
5719          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5720        }
5721      else
5722        {
5723      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)
5724        {        {
5725        /* 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. */
5726        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));
5727          if (needs_control_head)
5728            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5729        }        }
5730      else      else
5731        {        {
5732        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);
5733          if (needs_control_head)
5734            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));
5735        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5736        }        }
5737    }      }
5738    
5739    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5740      {      {
5741      /* 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. */
5742      if (conditional)      if (conditional)
5743        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);
5744      else if (bra == OP_BRAZERO)      else if (bra == OP_BRAZERO)
5745        {        {
5746        if (framesize < 0)        if (framesize < 0)
5747          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));
5748        else        else
5749          {          {
5750          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));
5751          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));
5752          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);
5753          }          }
5754        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));
5755        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5756        }        }
5757      else if (framesize >= 0)      else if (framesize >= 0)
5758        {        {
5759        /* For OP_BRA and OP_BRAMINZERO. */        /* For OP_BRA and OP_BRAMINZERO. */
5760        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));
5761        }        }
5762      }      }
5763    add_jump(compiler, found, JUMP(SLJIT_JUMP));    add_jump(compiler, found, JUMP(SLJIT_JUMP));
# Line 5183  while (1) Line 5765  while (1)
5765    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
5766    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5767      {      {
5768      common->quitlabel = save_quitlabel;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5769      common->acceptlabel = save_acceptlabel;        {
5770      common->quit = save_quit;        common->local_exit = save_local_exit;
5771          common->quit_label = save_quit_label;
5772          common->quit = save_quit;
5773          }
5774        common->positive_assert = save_positive_assert;
5775        common->then_trap = save_then_trap;
5776        common->accept_label = save_accept_label;
5777        common->positive_assert_quit = save_positive_assert_quit;
5778      common->accept = save_accept;      common->accept = save_accept;
5779      return NULL;      return NULL;
5780      }      }
# Line 5197  while (1) Line 5786  while (1)
5786    ccbegin = cc;    ccbegin = cc;
5787    cc += GET(cc, 1);    cc += GET(cc, 1);
5788    }    }
5789    
5790    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5791      {
5792      SLJIT_ASSERT(common->positive_assert_quit == NULL);
5793      /* Makes the check less complicated below. */
5794      common->positive_assert_quit = common->quit;
5795      }
5796    
5797  /* None of them matched. */  /* None of them matched. */
5798  if (common->quit != NULL)  if (common->positive_assert_quit != NULL)
5799    set_jumps(common->quit, LABEL());    {
5800      jump = JUMP(SLJIT_JUMP);
5801      set_jumps(common->positive_assert_quit, LABEL());
5802      SLJIT_ASSERT(framesize != no_stack);
5803      if (framesize < 0)
5804        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));
5805      else
5806        {
5807        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5808        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5809        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
5810        }
5811      JUMPHERE(jump);
5812      }
5813    
5814    if (needs_control_head)
5815      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(1));
5816    
5817  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)
5818    {    {
# Line 5211  if (opcode == OP_ASSERT || opcode == OP_ Line 5824  if (opcode == OP_ASSERT || opcode == OP_
5824      {      {
5825      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5826      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5827          {
5828          if (extrasize == 2)
5829            free_stack(common, 1);
5830        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5831          }
5832      else      else
5833        free_stack(common, 1);        free_stack(common, extrasize);
5834      }      }
5835    else    else
5836      {      {
5837      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
5838      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5839      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5840        {        {
5841        free_stack(common, framesize + 1);        free_stack(common, framesize + extrasize - 1);
5842        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5843        }        }
5844      else      else
5845        free_stack(common, framesize + 2);        free_stack(common, framesize + extrasize);
5846      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);
5847      }      }
5848    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
# Line 5237  if (opcode == OP_ASSERT || opcode == OP_ Line 5854  if (opcode == OP_ASSERT || opcode == OP_
5854    if (framesize < 0)    if (framesize < 0)
5855      {      {
5856      /* 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. */
5857      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));
5858      /* Keep the STR_PTR on the top of the stack. */      /* Keep the STR_PTR on the top of the stack. */
5859      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5860        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));        {
5861          OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
5862          if (extrasize == 2)
5863            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5864          }
5865      else if (bra == OP_BRAMINZERO)      else if (bra == OP_BRAMINZERO)
5866        {        {
5867        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));
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      }      }
# Line 5252