/[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 1379 by ph10, Mon Oct 14 13:54:07 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_CRPOSSTAR:
589      case OP_CRPOSPLUS:
590      case OP_CRPOSQUERY:
591      case OP_CRPOSRANGE:
592      case OP_CLASS:
593      case OP_NCLASS:
594      case OP_REF:
595      case OP_REFI:
596      case OP_DNREF:
597      case OP_DNREFI:
598      case OP_RECURSE:
599      case OP_CALLOUT:
600      case OP_ALT:
601      case OP_KET:
602      case OP_KETRMAX:
603      case OP_KETRMIN:
604      case OP_KETRPOS:
605      case OP_REVERSE:
606      case OP_ASSERT:
607      case OP_ASSERT_NOT:
608      case OP_ASSERTBACK:
609      case OP_ASSERTBACK_NOT:
610      case OP_ONCE:
611      case OP_ONCE_NC:
612      case OP_BRA:
613      case OP_BRAPOS:
614      case OP_CBRA:
615      case OP_CBRAPOS:
616      case OP_COND:
617      case OP_SBRA:
618      case OP_SBRAPOS:
619      case OP_SCBRA:
620      case OP_SCBRAPOS:
621      case OP_SCOND:
622      case OP_CREF:
623      case OP_DNCREF:
624      case OP_RREF:
625      case OP_DNRREF:
626    case OP_DEF:    case OP_DEF:
627    case OP_BRAZERO:    case OP_BRAZERO:
628    case OP_BRAMINZERO:    case OP_BRAMINZERO:
629    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
630      case OP_PRUNE:
631      case OP_SKIP:
632      case OP_THEN:
633    case OP_COMMIT:    case OP_COMMIT:
634    case OP_FAIL:    case OP_FAIL:
635    case OP_ACCEPT:    case OP_ACCEPT:
636    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
637      case OP_CLOSE:
638    case OP_SKIPZERO:    case OP_SKIPZERO:
639    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
640    
641    case OP_CHAR:    case OP_CHAR:
642    case OP_CHARI:    case OP_CHARI:
# Line 560  switch(*cc) Line 648  switch(*cc)
648    case OP_MINPLUS:    case OP_MINPLUS:
649    case OP_QUERY:    case OP_QUERY:
650    case OP_MINQUERY:    case OP_MINQUERY:
651      case OP_UPTO:
652      case OP_MINUPTO:
653      case OP_EXACT:
654    case OP_POSSTAR:    case OP_POSSTAR:
655    case OP_POSPLUS:    case OP_POSPLUS:
656    case OP_POSQUERY:    case OP_POSQUERY:
657      case OP_POSUPTO:
658    case OP_STARI:    case OP_STARI:
659    case OP_MINSTARI:    case OP_MINSTARI:
660    case OP_PLUSI:    case OP_PLUSI:
661    case OP_MINPLUSI:    case OP_MINPLUSI:
662    case OP_QUERYI:    case OP_QUERYI:
663    case OP_MINQUERYI:    case OP_MINQUERYI:
664      case OP_UPTOI:
665      case OP_MINUPTOI:
666      case OP_EXACTI:
667    case OP_POSSTARI:    case OP_POSSTARI:
668    case OP_POSPLUSI:    case OP_POSPLUSI:
669    case OP_POSQUERYI:    case OP_POSQUERYI:
670      case OP_POSUPTOI:
671    case OP_NOTSTAR:    case OP_NOTSTAR:
672    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
673    case OP_NOTPLUS:    case OP_NOTPLUS:
674    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
675    case OP_NOTQUERY:    case OP_NOTQUERY:
676    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
677      case OP_NOTUPTO:
678      case OP_NOTMINUPTO:
679      case OP_NOTEXACT:
680    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
681    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
682    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
683      case OP_NOTPOSUPTO:
684    case OP_NOTSTARI:    case OP_NOTSTARI:
685    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
686    case OP_NOTPLUSI:    case OP_NOTPLUSI:
687    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
688    case OP_NOTQUERYI:    case OP_NOTQUERYI:
689    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:  
690    case OP_NOTUPTOI:    case OP_NOTUPTOI:
691    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
692    case OP_NOTEXACTI:    case OP_NOTEXACTI:
693      case OP_NOTPOSSTARI:
694      case OP_NOTPOSPLUSI:
695      case OP_NOTPOSQUERYI:
696    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
697    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
698  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
699    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
700  #endif  #endif
701    return cc;    return cc;
702    
703    case OP_NOTPROP:    /* Special cases. */
704    case OP_PROP:    case OP_TYPESTAR:
705    return cc + 1 + 2;    case OP_TYPEMINSTAR:
706      case OP_TYPEPLUS:
707      case OP_TYPEMINPLUS:
708      case OP_TYPEQUERY:
709      case OP_TYPEMINQUERY:
710    case OP_TYPEUPTO:    case OP_TYPEUPTO:
711    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
712    case OP_TYPEEXACT:    case OP_TYPEEXACT:
713      case OP_TYPEPOSSTAR:
714      case OP_TYPEPOSPLUS:
715      case OP_TYPEPOSQUERY:
716    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
717    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;  
718    
719    case OP_CLASS:    case OP_ANYBYTE:
720    case OP_NCLASS:  #ifdef SUPPORT_UTF
721    return cc + 1 + 32 / sizeof(pcre_uchar);    if (common->utf) return NULL;
722    #endif
723      return cc + 1;
724    
725  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
726    case OP_XCLASS:    case OP_XCLASS:
727    return cc + GET(cc, 1);    return cc + GET(cc, 1);
728  #endif  #endif
729    
   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;  
   
730    case OP_MARK:    case OP_MARK:
731      case OP_PRUNE_ARG:
732      case OP_SKIP_ARG:
733      case OP_THEN_ARG:
734    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
735    
736    default:    default:
737      /* All opcodes are supported now! */
738      SLJIT_ASSERT_STOP();
739    return NULL;    return NULL;
740    }    }
741  }  }
742    
743  #define CASE_ITERATOR_PRIVATE_DATA_1 \  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
     case OP_MINSTAR: \  
     case OP_MINPLUS: \  
     case OP_QUERY: \  
     case OP_MINQUERY: \  
     case OP_MINSTARI: \  
     case OP_MINPLUSI: \  
     case OP_QUERYI: \  
     case OP_MINQUERYI: \  
     case OP_NOTMINSTAR: \  
     case OP_NOTMINPLUS: \  
     case OP_NOTQUERY: \  
     case OP_NOTMINQUERY: \  
     case OP_NOTMINSTARI: \  
     case OP_NOTMINPLUSI: \  
     case OP_NOTQUERYI: \  
     case OP_NOTMINQUERYI:  
   
 #define CASE_ITERATOR_PRIVATE_DATA_2A \  
     case OP_STAR: \  
     case OP_PLUS: \  
     case OP_STARI: \  
     case OP_PLUSI: \  
     case OP_NOTSTAR: \  
     case OP_NOTPLUS: \  
     case OP_NOTSTARI: \  
     case OP_NOTPLUSI:  
   
 #define CASE_ITERATOR_PRIVATE_DATA_2B \  
     case OP_UPTO: \  
     case OP_MINUPTO: \  
     case OP_UPTOI: \  
     case OP_MINUPTOI: \  
     case OP_NOTUPTO: \  
     case OP_NOTMINUPTO: \  
     case OP_NOTUPTOI: \  
     case OP_NOTMINUPTOI:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \  
     case OP_TYPEMINSTAR: \  
     case OP_TYPEMINPLUS: \  
     case OP_TYPEQUERY: \  
     case OP_TYPEMINQUERY:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \  
     case OP_TYPESTAR: \  
     case OP_TYPEPLUS:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \  
     case OP_TYPEUPTO: \  
     case OP_TYPEMINUPTO:  
   
 static int get_class_iterator_size(pcre_uchar *cc)  
 {  
 switch(*cc)  
   {  
   case OP_CRSTAR:  
   case OP_CRPLUS:  
   return 2;  
   
   case OP_CRMINSTAR:  
   case OP_CRMINPLUS:  
   case OP_CRQUERY:  
   case OP_CRMINQUERY:  
   return 1;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))  
     return 0;  
   return 2;  
   
   default:  
   return 0;  
   }  
 }  
   
 static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  
744  {  {
745  int private_data_length = 0;  int count;
746  pcre_uchar *alternative;  pcre_uchar *slot;
 pcre_uchar *name;  
 pcre_uchar *end = NULL;  
 int space, size, bracketlen, i;  
747    
748  /* 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. */
749  while (cc < ccend)  while (cc < ccend)
750    {    {
   space = 0;  
   size = 0;  
   bracketlen = 0;  
751    switch(*cc)    switch(*cc)
752      {      {
753      case OP_SET_SOM:      case OP_SET_SOM:
# Line 788  while (cc < ccend) Line 761  while (cc < ccend)
761      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
762      break;      break;
763    
     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;  
   
764      case OP_CBRAPOS:      case OP_CBRAPOS:
765      case OP_SCBRAPOS:      case OP_SCBRAPOS:
     private_data_length += sizeof(sljit_w);  
766      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
767      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
768      break;      break;
769    
770      case OP_COND:      case OP_COND:
771      case OP_SCOND:      case OP_SCOND:
772      bracketlen = cc[1 + LINK_SIZE];      /* Only AUTO_CALLOUT can insert this opcode. We do
773      if (bracketlen == OP_CREF)         not intend to support this case. */
774        {      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
775        bracketlen = GET2(cc, 1 + LINK_SIZE + 1);        return FALSE;
776        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;  
777      break;      break;
778    
779      case OP_CLASS:      case OP_CREF:
780      case OP_NCLASS:      common->optimized_cbracket[GET2(cc, 1)] = 0;
781      size += 1 + 32 / sizeof(pcre_uchar);      cc += 1 + IMM2_SIZE;
     space = get_class_iterator_size(cc + size);  
782      break;      break;
783    
784  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8      case OP_DNREF:
785      case OP_XCLASS:      case OP_DNREFI:
786      size = GET(cc, 1);      case OP_DNCREF:
787      space = get_class_iterator_size(cc + size);      count = GET2(cc, 1 + IMM2_SIZE);
788        slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
789        while (count-- > 0)
790          {
791          common->optimized_cbracket[GET2(slot, 0)] = 0;
792          slot += common->name_entry_size;
793          }
794        cc += 1 + 2 * IMM2_SIZE;
795      break;      break;
 #endif  
796    
797      case OP_RECURSE:      case OP_RECURSE:
798      /* Set its value only once. */      /* Set its value only once. */
799      if (common->recursive_head == 0)      if (common->recursive_head_ptr == 0)
800        {        {
801        common->recursive_head = common->ovector_start;        common->recursive_head_ptr = common->ovector_start;
802        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
803        }        }
804      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
805      break;      break;
806    
807        case OP_CALLOUT:
808        if (common->capture_last_ptr == 0)
809          {
810          common->capture_last_ptr = common->ovector_start;
811          common->ovector_start += sizeof(sljit_sw);
812          }
813        cc += 2 + 2 * LINK_SIZE;
814        break;
815    
816        case OP_THEN_ARG:
817        common->has_then = TRUE;
818        common->control_head_ptr = 1;
819        /* Fall through. */
820    
821        case OP_PRUNE_ARG:
822        common->needs_start_ptr = TRUE;
823        /* Fall through. */
824    
825      case OP_MARK:      case OP_MARK:
826      if (common->mark_ptr == 0)      if (common->mark_ptr == 0)
827        {        {
828        common->mark_ptr = common->ovector_start;        common->mark_ptr = common->ovector_start;
829        common->ovector_start += sizeof(sljit_w);        common->ovector_start += sizeof(sljit_sw);
830        }        }
831      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
832      break;      break;
833    
834        case OP_THEN:
835        common->has_then = TRUE;
836        common->control_head_ptr = 1;
837        /* Fall through. */
838    
839        case OP_PRUNE:
840        case OP_SKIP:
841        common->needs_start_ptr = TRUE;
842        cc += 1;
843        break;
844    
845        case OP_SKIP_ARG:
846        common->control_head_ptr = 1;
847        common->has_skip_arg = TRUE;
848        cc += 1 + 2 + cc[1];
849        break;
850    
851      default:      default:
852      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
853      if (cc == NULL)      if (cc == NULL)
854        return -1;        return FALSE;
855      break;      break;
856      }      }
857      }
858    return TRUE;
859    }
860    
861    if (space > 0 && cc >= end)  static int get_class_iterator_size(pcre_uchar *cc)
862      private_data_length += sizeof(sljit_w) * space;  {
863    switch(*cc)
864      {
865      case OP_CRSTAR:
866      case OP_CRPLUS:
867      return 2;
868    
869    if (size != 0)    case OP_CRMINSTAR:
870      case OP_CRMINPLUS:
871      case OP_CRQUERY:
872      case OP_CRMINQUERY:
873      return 1;
874    
875      case OP_CRRANGE:
876      case OP_CRMINRANGE:
877      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
878        return 0;
879      return 2;
880    
881      default:
882      return 0;
883      }
884    }
885    
886    static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
887    {
888    pcre_uchar *end = bracketend(begin);
889    pcre_uchar *next;
890    pcre_uchar *next_end;
891    pcre_uchar *max_end;
892    pcre_uchar type;
893    sljit_sw length = end - begin;
894    int min, max, i;
895    
896    /* Detect fixed iterations first. */
897    if (end[-(1 + LINK_SIZE)] != OP_KET)
898      return FALSE;
899    
900    /* Already detected repeat. */
901    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
902      return TRUE;
903    
904    next = end;
905    min = 1;
906    while (1)
907      {
908      if (*next != *begin)
909        break;
910      next_end = bracketend(next);
911      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
912        break;
913      next = next_end;
914      min++;
915      }
916    
917    if (min == 2)
918      return FALSE;
919    
920    max = 0;
921    max_end = next;
922    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
923      {
924      type = *next;
925      while (1)
926      {      {
927      if (size < 0)      if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
928        {        break;
929        cc += -size;      next_end = bracketend(next + 2 + LINK_SIZE);
930  #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)
931        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        break;
932  #endif      next = next_end;
933        }      max++;
     else  
       cc += size;  
934      }      }
935    
936    if (bracketlen > 0)    if (next[0] == type && next[1] == *begin && max >= 1)
937      {      {
938      if (cc >= end)      next_end = bracketend(next + 1);
939        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
940        {        {
941        end = bracketend(cc);        for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
942        if (end[-1 - LINK_SIZE] == OP_KET)          if (*next_end != OP_KET)
943          end = NULL;            break;
944    
945          if (i == max)
946            {
947            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
948            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
949            /* +2 the original and the last. */
950            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
951            if (min == 1)
952              return TRUE;
953            min--;
954            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
955            }
956        }        }
     cc += bracketlen;  
957      }      }
958    }    }
959  return private_data_length;  
960    if (min >= 3)
961      {
962      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
963      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
964      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
965      return TRUE;
966      }
967    
968    return FALSE;
969  }  }
970    
971  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
972        case OP_MINSTAR: \
973        case OP_MINPLUS: \
974        case OP_QUERY: \
975        case OP_MINQUERY: \
976        case OP_MINSTARI: \
977        case OP_MINPLUSI: \
978        case OP_QUERYI: \
979        case OP_MINQUERYI: \
980        case OP_NOTMINSTAR: \
981        case OP_NOTMINPLUS: \
982        case OP_NOTQUERY: \
983        case OP_NOTMINQUERY: \
984        case OP_NOTMINSTARI: \
985        case OP_NOTMINPLUSI: \
986        case OP_NOTQUERYI: \
987        case OP_NOTMINQUERYI:
988    
989    #define CASE_ITERATOR_PRIVATE_DATA_2A \
990        case OP_STAR: \
991        case OP_PLUS: \
992        case OP_STARI: \
993        case OP_PLUSI: \
994        case OP_NOTSTAR: \
995        case OP_NOTPLUS: \
996        case OP_NOTSTARI: \
997        case OP_NOTPLUSI:
998    
999    #define CASE_ITERATOR_PRIVATE_DATA_2B \
1000        case OP_UPTO: \
1001        case OP_MINUPTO: \
1002        case OP_UPTOI: \
1003        case OP_MINUPTOI: \
1004        case OP_NOTUPTO: \
1005        case OP_NOTMINUPTO: \
1006        case OP_NOTUPTOI: \
1007        case OP_NOTMINUPTOI:
1008    
1009    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1010        case OP_TYPEMINSTAR: \
1011        case OP_TYPEMINPLUS: \
1012        case OP_TYPEQUERY: \
1013        case OP_TYPEMINQUERY:
1014    
1015    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1016        case OP_TYPESTAR: \
1017        case OP_TYPEPLUS:
1018    
1019    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1020        case OP_TYPEUPTO: \
1021        case OP_TYPEMINUPTO:
1022    
1023    static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1024  {  {
1025  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1026  pcre_uchar *alternative;  pcre_uchar *alternative;
1027  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1028    int private_data_ptr = *private_data_start;
1029  int space, size, bracketlen;  int space, size, bracketlen;
1030    
1031  while (cc < ccend)  while (cc < ccend)
# Line 970  while (cc < ccend) Line 1033  while (cc < ccend)
1033    space = 0;    space = 0;
1034    size = 0;    size = 0;
1035    bracketlen = 0;    bracketlen = 0;
1036      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1037        return;
1038    
1039      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1040        if (detect_repeat(common, cc))
1041          {
1042          /* These brackets are converted to repeats, so no global
1043          based single character repeat is allowed. */
1044          if (cc >= end)
1045            end = bracketend(cc);
1046          }
1047    
1048    switch(*cc)    switch(*cc)
1049      {      {
1050        case OP_KET:
1051        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1052          {
1053          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1054          private_data_ptr += sizeof(sljit_sw);
1055          cc += common->private_data_ptrs[cc + 1 - common->start];
1056          }
1057        cc += 1 + LINK_SIZE;
1058        break;
1059    
1060      case OP_ASSERT:      case OP_ASSERT:
1061      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1062      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 983  while (cc < ccend) Line 1068  while (cc < ccend)
1068      case OP_SBRAPOS:      case OP_SBRAPOS:
1069      case OP_SCOND:      case OP_SCOND:
1070      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1071      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1072      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1073      break;      break;
1074    
1075      case OP_CBRAPOS:      case OP_CBRAPOS:
1076      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1077      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1078      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1079      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1080      break;      break;
1081    
# Line 1000  while (cc < ccend) Line 1085  while (cc < ccend)
1085      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1086        {        {
1087        common->private_data_ptrs[cc - common->start] = private_data_ptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1088        private_data_ptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1089        }        }
1090      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1091      break;      break;
# Line 1065  while (cc < ccend) Line 1150  while (cc < ccend)
1150      break;      break;
1151      }      }
1152    
1153      /* Character iterators, which are not inside a repeated bracket,
1154         gets a private slot instead of allocating it on the stack. */
1155    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1156      {      {
1157      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1158      private_data_ptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1159      }      }
1160    
1161    if (size != 0)    if (size != 0)
# Line 1076  while (cc < ccend) Line 1163  while (cc < ccend)
1163      if (size < 0)      if (size < 0)
1164        {        {
1165        cc += -size;        cc += -size;
1166  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1167        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1168  #endif  #endif
1169        }        }
# Line 1095  while (cc < ccend) Line 1182  while (cc < ccend)
1182      cc += bracketlen;      cc += bracketlen;
1183      }      }
1184    }    }
1185    *private_data_start = private_data_ptr;
1186  }  }
1187    
1188  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1189  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)
1190  {  {
 pcre_uchar *ccend = bracketend(cc);  
1191  int length = 0;  int length = 0;
1192  BOOL possessive = FALSE;  int possessive = 0;
1193    BOOL stack_restore = FALSE;
1194  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1195  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1196    /* The last capture is a local variable even for recursions. */
1197    BOOL capture_last_found = FALSE;
1198    
1199  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1200    SLJIT_ASSERT(common->control_head_ptr != 0);
1201    *needs_control_head = TRUE;
1202    #else
1203    *needs_control_head = FALSE;
1204    #endif
1205    
1206    if (ccend == NULL)
1207    {    {
1208    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1209    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1210        {
1211        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1212        /* This is correct regardless of common->capture_last_ptr. */
1213        capture_last_found = TRUE;
1214        }
1215      cc = next_opcode(common, cc);
1216    }    }
1217    
1218  cc = next_opcode(common, cc);  SLJIT_ASSERT(cc != NULL);
1219  SLJIT_ASSERT(cc != NULL);  while (cc < ccend)
1220  while (cc < ccend)    switch(*cc)
1221    switch(*cc)      {
1222      {      case OP_SET_SOM:
1223      case OP_SET_SOM:      SLJIT_ASSERT(common->has_set_som);
1224      SLJIT_ASSERT(common->has_set_som);      stack_restore = TRUE;
1225      if (!setsom_found)      if (!setsom_found)
1226        {        {
1227        length += 2;        length += 2;
1228        setsom_found = TRUE;        setsom_found = TRUE;
1229        }        }
1230      cc += 1;      cc += 1;
1231      break;      break;
1232    
1233        case OP_MARK:
1234        case OP_PRUNE_ARG:
1235        case OP_THEN_ARG:
1236        SLJIT_ASSERT(common->mark_ptr != 0);
1237        stack_restore = TRUE;
1238        if (!setmark_found)
1239          {
1240          length += 2;
1241          setmark_found = TRUE;
1242          }
1243        if (common->control_head_ptr != 0)
1244          *needs_control_head = TRUE;
1245        cc += 1 + 2 + cc[1];
1246        break;
1247    
1248        case OP_RECURSE:
1249        stack_restore = TRUE;
1250        if (common->has_set_som && !setsom_found)
1251          {
1252          length += 2;
1253          setsom_found = TRUE;
1254          }
1255        if (common->mark_ptr != 0 && !setmark_found)
1256          {
1257          length += 2;
1258          setmark_found = TRUE;
1259          }
1260        if (common->capture_last_ptr != 0 && !capture_last_found)
1261          {
1262          length += 2;
1263          capture_last_found = TRUE;
1264          }
1265        cc += 1 + LINK_SIZE;
1266        break;
1267    
1268        case OP_CBRA:
1269        case OP_CBRAPOS:
1270        case OP_SCBRA:
1271        case OP_SCBRAPOS:
1272        stack_restore = TRUE;
1273        if (common->capture_last_ptr != 0 && !capture_last_found)
1274          {
1275          length += 2;
1276          capture_last_found = TRUE;
1277          }
1278        length += 3;
1279        cc += 1 + LINK_SIZE + IMM2_SIZE;
1280        break;
1281    
1282        default:
1283        stack_restore = TRUE;
1284        /* Fall through. */
1285    
1286        case OP_NOT_WORD_BOUNDARY:
1287        case OP_WORD_BOUNDARY:
1288        case OP_NOT_DIGIT:
1289        case OP_DIGIT:
1290        case OP_NOT_WHITESPACE:
1291        case OP_WHITESPACE:
1292        case OP_NOT_WORDCHAR:
1293        case OP_WORDCHAR:
1294        case OP_ANY:
1295        case OP_ALLANY:
1296        case OP_ANYBYTE:
1297        case OP_NOTPROP:
1298        case OP_PROP:
1299        case OP_ANYNL:
1300        case OP_NOT_HSPACE:
1301        case OP_HSPACE:
1302        case OP_NOT_VSPACE:
1303        case OP_VSPACE:
1304        case OP_EXTUNI:
1305        case OP_EODN:
1306        case OP_EOD:
1307        case OP_CIRC:
1308        case OP_CIRCM:
1309        case OP_DOLL:
1310        case OP_DOLLM:
1311        case OP_CHAR:
1312        case OP_CHARI:
1313        case OP_NOT:
1314        case OP_NOTI:
1315    
1316        case OP_EXACT:
1317        case OP_POSSTAR:
1318        case OP_POSPLUS:
1319        case OP_POSQUERY:
1320        case OP_POSUPTO:
1321    
1322        case OP_EXACTI:
1323        case OP_POSSTARI:
1324        case OP_POSPLUSI:
1325        case OP_POSQUERYI:
1326        case OP_POSUPTOI:
1327    
1328        case OP_NOTEXACT:
1329        case OP_NOTPOSSTAR:
1330        case OP_NOTPOSPLUS:
1331        case OP_NOTPOSQUERY:
1332        case OP_NOTPOSUPTO:
1333    
1334      case OP_MARK:      case OP_NOTEXACTI:
1335      SLJIT_ASSERT(common->mark_ptr != 0);      case OP_NOTPOSSTARI:
1336      if (!setmark_found)      case OP_NOTPOSPLUSI:
1337        {      case OP_NOTPOSQUERYI:
1338        length += 2;      case OP_NOTPOSUPTOI:
       setmark_found = TRUE;  
       }  
     cc += 1 + 2 + cc[1];  
     break;  
1339    
1340      case OP_RECURSE:      case OP_TYPEEXACT:
1341      if (common->has_set_som && !setsom_found)      case OP_TYPEPOSSTAR:
1342        {      case OP_TYPEPOSPLUS:
1343        length += 2;      case OP_TYPEPOSQUERY:
1344        setsom_found = TRUE;      case OP_TYPEPOSUPTO:
       }  
     if (common->mark_ptr != 0 && !setmark_found)  
       {  
       length += 2;  
       setmark_found = TRUE;  
       }  
     cc += 1 + LINK_SIZE;  
     break;  
1345    
1346      case OP_CBRA:      case OP_CLASS:
1347      case OP_CBRAPOS:      case OP_NCLASS:
1348      case OP_SCBRA:      case OP_XCLASS:
     case OP_SCBRAPOS:  
     length += 3;  
     cc += 1 + LINK_SIZE + IMM2_SIZE;  
     break;  
1349    
     default:  
1350      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1351      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1352      break;      break;
1353      }      }
1354    
1355  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1356  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1357    return -1;    return stack_restore ? no_frame : no_stack;
1358    
1359  if (length > 0)  if (length > 0)
1360    return length + 1;    return length + 1;
1361  return -1;  return stack_restore ? no_frame : no_stack;
1362  }  }
1363    
1364  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)
1365  {  {
1366  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1367  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1368  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1369    /* The last capture is a local variable even for recursions. */
1370    BOOL capture_last_found = FALSE;
1371  int offset;  int offset;
1372    
1373  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1187  SLJIT_UNUSED_ARG(stacktop); Line 1375  SLJIT_UNUSED_ARG(stacktop);
1375  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1376    
1377  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1378  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1379    cc = next_opcode(common, cc);    {
1380      ccend = bracketend(cc) - (1 + LINK_SIZE);
1381      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1382        cc = next_opcode(common, cc);
1383      }
1384    
1385  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1386  while (cc < ccend)  while (cc < ccend)
1387    switch(*cc)    switch(*cc)
# Line 1198  while (cc < ccend) Line 1391  while (cc < ccend)
1391      if (!setsom_found)      if (!setsom_found)
1392        {        {
1393        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1394        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1395        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1396        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1397        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1398        setsom_found = TRUE;        setsom_found = TRUE;
1399        }        }
1400      cc += 1;      cc += 1;
1401      break;      break;
1402    
1403      case OP_MARK:      case OP_MARK:
1404        case OP_PRUNE_ARG:
1405        case OP_THEN_ARG:
1406      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1407      if (!setmark_found)      if (!setmark_found)
1408        {        {
1409        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);
1410        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);
1411        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1412        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1413        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1414        setmark_found = TRUE;        setmark_found = TRUE;
1415        }        }
1416      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 1225  while (cc < ccend) Line 1420  while (cc < ccend)
1420      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1421        {        {
1422        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1423        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1424        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1425        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1426        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1427        setsom_found = TRUE;        setsom_found = TRUE;
1428        }        }
1429      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1430        {        {
1431        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);
1432        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);
1433        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1434        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1435        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1436        setmark_found = TRUE;        setmark_found = TRUE;
1437        }        }
1438        if (common->capture_last_ptr != 0 && !capture_last_found)
1439          {
1440          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1441          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1442          stackpos += (int)sizeof(sljit_sw);
1443          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1444          stackpos += (int)sizeof(sljit_sw);
1445          capture_last_found = TRUE;
1446          }
1447      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1448      break;      break;
1449    
# Line 1247  while (cc < ccend) Line 1451  while (cc < ccend)
1451      case OP_CBRAPOS:      case OP_CBRAPOS:
1452      case OP_SCBRA:      case OP_SCBRA:
1453      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1454        if (common->capture_last_ptr != 0 && !capture_last_found)
1455          {
1456          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1457          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1458          stackpos += (int)sizeof(sljit_sw);
1459          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1460          stackpos += (int)sizeof(sljit_sw);
1461          capture_last_found = TRUE;
1462          }
1463      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1464      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1465      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1466      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1467      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));
1468      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1469      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1470      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1471      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1472    
1473      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1474      break;      break;
# Line 1266  while (cc < ccend) Line 1479  while (cc < ccend)
1479      break;      break;
1480      }      }
1481    
1482  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1483  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1484  }  }
1485    
1486  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)
1487  {  {
1488  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1489  int size;  int size;
1490  pcre_uchar *alternative;  pcre_uchar *alternative;
1491  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1281  while (cc < ccend) Line 1494  while (cc < ccend)
1494    size = 0;    size = 0;
1495    switch(*cc)    switch(*cc)
1496      {      {
1497        case OP_KET:
1498        if (PRIVATE_DATA(cc) != 0)
1499          private_data_length++;
1500        cc += 1 + LINK_SIZE;
1501        break;
1502    
1503      case OP_ASSERT:      case OP_ASSERT:
1504      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1505      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1320  while (cc < ccend) Line 1539  while (cc < ccend)
1539      if (PRIVATE_DATA(cc))      if (PRIVATE_DATA(cc))
1540        private_data_length++;        private_data_length++;
1541      cc += 2;      cc += 2;
1542  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1543      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1544  #endif  #endif
1545      break;      break;
# Line 1329  while (cc < ccend) Line 1548  while (cc < ccend)
1548      if (PRIVATE_DATA(cc))      if (PRIVATE_DATA(cc))
1549        private_data_length += 2;        private_data_length += 2;
1550      cc += 2;      cc += 2;
1551  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1552      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1553  #endif  #endif
1554      break;      break;
# Line 1338  while (cc < ccend) Line 1557  while (cc < ccend)
1557      if (PRIVATE_DATA(cc))      if (PRIVATE_DATA(cc))
1558        private_data_length += 2;        private_data_length += 2;
1559      cc += 2 + IMM2_SIZE;      cc += 2 + IMM2_SIZE;
1560  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1561      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1562  #endif  #endif
1563      break;      break;
# Line 1385  return private_data_length; Line 1604  return private_data_length;
1604  }  }
1605    
1606  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,
1607    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1608  {  {
1609  DEFINE_COMPILER;  DEFINE_COMPILER;
1610  int srcw[2];  int srcw[2];
# Line 1406  stacktop = STACK(stacktop - 1); Line 1625  stacktop = STACK(stacktop - 1);
1625    
1626  if (!save)  if (!save)
1627    {    {
1628    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1629    if (stackptr < stacktop)    if (stackptr < stacktop)
1630      {      {
1631      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1632      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1633      tmp1empty = FALSE;      tmp1empty = FALSE;
1634      }      }
1635    if (stackptr < stacktop)    if (stackptr < stacktop)
1636      {      {
1637      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1638      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1639      tmp2empty = FALSE;      tmp2empty = FALSE;
1640      }      }
1641    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1642    }    }
1643    
1644  while (status != end)  do
1645    {    {
1646    count = 0;    count = 0;
1647    switch(status)    switch(status)
1648      {      {
1649      case start:      case start:
1650      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1651      count = 1;      count = 1;
1652      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1653        if (needs_control_head)
1654          {
1655          SLJIT_ASSERT(common->control_head_ptr != 0);
1656          count = 2;
1657          srcw[1] = common->control_head_ptr;
1658          }
1659      status = loop;      status = loop;
1660      break;      break;
1661    
# Line 1443  while (status != end) Line 1668  while (status != end)
1668    
1669      switch(*cc)      switch(*cc)
1670        {        {
1671          case OP_KET:
1672          if (PRIVATE_DATA(cc) != 0)
1673            {
1674            count = 1;
1675            srcw[0] = PRIVATE_DATA(cc);
1676            }
1677          cc += 1 + LINK_SIZE;
1678          break;
1679    
1680        case OP_ASSERT:        case OP_ASSERT:
1681        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1682        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1497  while (status != end) Line 1731  while (status != end)
1731          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1732          }          }
1733        cc += 2;        cc += 2;
1734  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1735        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1736  #endif  #endif
1737        break;        break;
# Line 1507  while (status != end) Line 1741  while (status != end)
1741          {          {
1742          count = 2;          count = 2;
1743          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1744          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1745          }          }
1746        cc += 2;        cc += 2;
1747  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1748        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1749  #endif  #endif
1750        break;        break;
# Line 1520  while (status != end) Line 1754  while (status != end)
1754          {          {
1755          count = 2;          count = 2;
1756          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1757          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1758          }          }
1759        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1760  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1761        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1762  #endif  #endif
1763        break;        break;
# Line 1542  while (status != end) Line 1776  while (status != end)
1776          {          {
1777          count = 2;          count = 2;
1778          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1779          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1780          }          }
1781        cc += 1;        cc += 1;
1782        break;        break;
# Line 1552  while (status != end) Line 1786  while (status != end)
1786          {          {
1787          count = 2;          count = 2;
1788          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1789          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1790          }          }
1791        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1792        break;        break;
# Line 1576  while (status != end) Line 1810  while (status != end)
1810            case 2:            case 2:
1811            count = 2;            count = 2;
1812            srcw[0] = PRIVATE_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1813            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1814            break;            break;
1815    
1816            default:            default:
# Line 1608  while (status != end) Line 1842  while (status != end)
1842          if (!tmp1empty)          if (!tmp1empty)
1843            {            {
1844            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1845            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1846            }            }
1847          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1848          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1619  while (status != end) Line 1853  while (status != end)
1853          if (!tmp2empty)          if (!tmp2empty)
1854            {            {
1855            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1856            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1857            }            }
1858          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1859          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1636  while (status != end) Line 1870  while (status != end)
1870          if (!tmp1empty)          if (!tmp1empty)
1871            {            {
1872            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1873            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1874            }            }
1875          tmp1next = FALSE;          tmp1next = FALSE;
1876          }          }
# Line 1648  while (status != end) Line 1882  while (status != end)
1882          if (!tmp2empty)          if (!tmp2empty)
1883            {            {
1884            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1885            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1886            }            }
1887          tmp1next = TRUE;          tmp1next = TRUE;
1888          }          }
1889        }        }
1890      }      }
1891    }    }
1892    while (status != end);
1893    
1894  if (save)  if (save)
1895    {    {
# Line 1663  if (save) Line 1898  if (save)
1898      if (!tmp1empty)      if (!tmp1empty)
1899        {        {
1900        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1901        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1902        }        }
1903      if (!tmp2empty)      if (!tmp2empty)
1904        {        {
1905        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1906        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1907        }        }
1908      }      }
1909    else    else
# Line 1676  if (save) Line 1911  if (save)
1911      if (!tmp2empty)      if (!tmp2empty)
1912        {        {
1913        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1914        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1915        }        }
1916      if (!tmp1empty)      if (!tmp1empty)
1917        {        {
1918        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1919        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1920        }        }
1921      }      }
1922    }    }
1923  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1924  }  }
1925    
1926    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1927    {
1928    pcre_uchar *end = bracketend(cc);
1929    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1930    
1931    /* Assert captures then. */
1932    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1933      current_offset = NULL;
1934    /* Conditional block does not. */
1935    if (*cc == OP_COND || *cc == OP_SCOND)
1936      has_alternatives = FALSE;
1937    
1938    cc = next_opcode(common, cc);
1939    if (has_alternatives)
1940      current_offset = common->then_offsets + (cc - common->start);
1941    
1942    while (cc < end)
1943      {
1944      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1945        cc = set_then_offsets(common, cc, current_offset);
1946      else
1947        {
1948        if (*cc == OP_ALT && has_alternatives)
1949          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1950        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1951          *current_offset = 1;
1952        cc = next_opcode(common, cc);
1953        }
1954      }
1955    
1956    return end;
1957    }
1958    
1959  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
1960  #undef CASE_ITERATOR_PRIVATE_DATA_2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
1961  #undef CASE_ITERATOR_PRIVATE_DATA_2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
# Line 1706  while (list) Line 1974  while (list)
1974    {    {
1975    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1976    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
1977    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1978    list = list->next;    list = list->next;
1979    }    }
1980  }  }
# Line 1722  if (list_item) Line 1990  if (list_item)
1990    }    }
1991  }  }
1992    
1993  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)
1994  {  {
1995  DEFINE_COMPILER;  DEFINE_COMPILER;
1996  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
1997    
1998  if (list_item)  if (list_item)
1999    {    {
   list_item->type = type;  
   list_item->data = data;  
2000    list_item->start = start;    list_item->start = start;
2001    list_item->quit = LABEL();    list_item->quit = LABEL();
2002    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1746  stub_list* list_item = common->stubs; Line 2012  stub_list* list_item = common->stubs;
2012  while (list_item)  while (list_item)
2013    {    {
2014    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2015    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;  
     }  
2016    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2017    list_item = list_item->next;    list_item = list_item->next;
2018    }    }
2019  common->stubs = NULL;  common->stubs = NULL;
2020  }  }
2021    
2022  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2023  {  {
2024  DEFINE_COMPILER;  DEFINE_COMPILER;
2025    
2026  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);
2027  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2028  }  }
2029    
# Line 1771  static SLJIT_INLINE void allocate_stack( Line 2032  static SLJIT_INLINE void allocate_stack(
2032  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2033  DEFINE_COMPILER;  DEFINE_COMPILER;
2034    
2035  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));
2036  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2037  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2038  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 2040  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2040  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2041  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2042  #endif  #endif
2043  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));
2044  }  }
2045    
2046  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2047  {  {
2048  DEFINE_COMPILER;  DEFINE_COMPILER;
2049  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));
2050  }  }
2051    
2052  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 2054  static SLJIT_INLINE void reset_ovector(c
2054  DEFINE_COMPILER;  DEFINE_COMPILER;
2055  struct sljit_label *loop;  struct sljit_label *loop;
2056  int i;  int i;
2057    
2058  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2059    SLJIT_ASSERT(length > 1);
2060  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2061  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));
2062    if (length < 8)
2063      {
2064      for (i = 1; i < length; i++)
2065        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2066      }
2067    else
2068      {
2069      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2070      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2071      loop = LABEL();
2072      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2073      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2074      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2075      }
2076    }
2077    
2078    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2079    {
2080    DEFINE_COMPILER;
2081    struct sljit_label *loop;
2082    int i;
2083    
2084    SLJIT_ASSERT(length > 1);
2085    /* OVECTOR(1) contains the "string begin - 1" constant. */
2086    if (length > 2)
2087      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2088  if (length < 8)  if (length < 8)
2089    {    {
2090    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
2091      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);
2092    }    }
2093  else  else
2094    {    {
2095    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2096    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2097    loop = LABEL();    loop = LABEL();
2098    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);
2099    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);
2100    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2101    }    }
2102    
2103    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2104    if (common->mark_ptr != 0)
2105      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2106    if (common->control_head_ptr != 0)
2107      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2108    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2109    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2110    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2111    }
2112    
2113    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2114    {
2115    while (current != NULL)
2116      {
2117      switch (current[-2])
2118        {
2119        case type_then_trap:
2120        break;
2121    
2122        case type_mark:
2123        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2124          return current[-4];
2125        break;
2126    
2127        default:
2128        SLJIT_ASSERT_STOP();
2129        break;
2130        }
2131      current = (sljit_sw*)current[-1];
2132      }
2133    return -1;
2134  }  }
2135    
2136  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2137  {  {
2138  DEFINE_COMPILER;  DEFINE_COMPILER;
2139  struct sljit_label *loop;  struct sljit_label *loop;
2140  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2141    
2142  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2143  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));
2144  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);
2145    
2146  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2147  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2148    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);
2149  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));
2150  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2151    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);
2152  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));
2153  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));
2154  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2155  /* Unlikely, but possible */  /* Unlikely, but possible */
2156  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);
2157  loop = LABEL();  loop = LABEL();
2158  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);
2159  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));
2160  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2161  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2162  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);
2163  #endif  #endif
2164  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);
2165  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);
2166  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2167  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2168    
2169  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2170  if (topbracket > 1)  if (topbracket > 1)
2171    {    {
2172    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));
2173    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2174    
2175    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2176    loop = LABEL();    loop = LABEL();
2177    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)));
2178    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);
2179    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);
2180    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2181    }    }
2182  else  else
2183    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1865  else Line 2186  else
2186  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)
2187  {  {
2188  DEFINE_COMPILER;  DEFINE_COMPILER;
2189    struct sljit_jump *jump;
2190    
2191  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);
2192  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
2193      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2194    
2195  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2196  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2197  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));
2198  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);
2199    
2200  /* Store match begin and end. */  /* Store match begin and end. */
2201  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));
2202  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));
2203  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);  
2204    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2205    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);
2206    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2207    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2208    #endif
2209    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2210    JUMPHERE(jump);
2211    
2212    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);
2213  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);
2214  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2215  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);
2216  #endif  #endif
2217  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);
2218    
2219  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);
2220  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2221  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);
2222  #endif  #endif
2223  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);
2224    
2225  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2226  }  }
# Line 2038  return (bit < 256) ? ((0 << 8) | bit) : Line 2370  return (bit < 256) ? ((0 << 8) | bit) :
2370    
2371  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2372  {  {
2373  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2374  DEFINE_COMPILER;  DEFINE_COMPILER;
2375  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2376    
# Line 2053  else if (common->mode == JIT_PARTIAL_SOF Line 2385  else if (common->mode == JIT_PARTIAL_SOF
2385    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);
2386    
2387  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2388    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);
2389  else  else
2390    {    {
2391    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2066  if (jump != NULL) Line 2398  if (jump != NULL)
2398    JUMPHERE(jump);    JUMPHERE(jump);
2399  }  }
2400    
2401  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2402  {  {
2403  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2404  DEFINE_COMPILER;  DEFINE_COMPILER;
2405  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2406    
2407  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2408    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2409      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2410      return;
2411      }
2412    
2413  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2414  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2415    {    {
2416    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));
2417    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);
2418    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2419    }    }
2420  else  else
2421    {    {
2422    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));
2423    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2424      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2425    else    else
2426      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2427    }    }
2428  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2429  }  }
2430    
2431  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 2444  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2444  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));
2445  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2446    {    {
2447    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);
2448    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2449    }    }
2450  else  else
# Line 2204  if (common->utf) Line 2535  if (common->utf)
2535    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2536    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);
2537    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);
2538    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2539    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
2540    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2541  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
# Line 2254  if (common->utf) Line 2585  if (common->utf)
2585    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2586    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2587    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);
2588    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2589    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2590    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2591    return;    return;
# Line 2277  if (nltype == NLTYPE_ANY) Line 2608  if (nltype == NLTYPE_ANY)
2608  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2609    {    {
2610    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);
2611    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2612    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);
2613    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);
2614    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));
2615    }    }
2616  else  else
# Line 2379  sljit_emit_fast_return(compiler, RETURN_ Line 2710  sljit_emit_fast_return(compiler, RETURN_
2710  JUMPHERE(jump);  JUMPHERE(jump);
2711    
2712  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2713  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);
2714  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2715  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2716  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 2763  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2763    
2764  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2765  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2766  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));
2767  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2768  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2769  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2770  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2771  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2772  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));
2773  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2774  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2775  }  }
# Line 2452  struct sljit_label *newlinelabel = NULL; Line 2783  struct sljit_label *newlinelabel = NULL;
2783  struct sljit_jump *start;  struct sljit_jump *start;
2784  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2785  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2786  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2787  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2788  #endif  #endif
2789  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 2507  if (newlinecheck) Line 2838  if (newlinecheck)
2838    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2839    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2840    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);
2841    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2842  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2843    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2844  #endif  #endif
# Line 2535  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S Line 2866  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S
2866  if (common->utf)  if (common->utf)
2867    {    {
2868    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2869    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);
2870    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2871    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2872    }    }
# Line 2545  if (common->utf) Line 2876  if (common->utf)
2876    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2877    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2878    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);
2879    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2880    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2881    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2882    JUMPHERE(singlechar);    JUMPHERE(singlechar);
# Line 2571  DEFINE_COMPILER; Line 2902  DEFINE_COMPILER;
2902  struct sljit_label *start;  struct sljit_label *start;
2903  struct sljit_jump *quit;  struct sljit_jump *quit;
2904  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uint32 chars[MAX_N_CHARS * 2];
2905  pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  pcre_uchar *cc = common->start + 1 + LINK_SIZE;
2906  int location = 0;  int location = 0;
2907  pcre_int32 len, c, bit, caseless;  pcre_int32 len, c, bit, caseless;
2908  int must_stop;  int must_stop;
# Line 2643  while (TRUE) Line 2974  while (TRUE)
2974        break;        break;
2975    
2976    len = 1;    len = 1;
2977  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
2978    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
2979  #endif  #endif
2980    
# Line 2694  if (firstline) Line 3025  if (firstline)
3025    {    {
3026    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3027    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3028    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));
3029    }    }
3030  else  else
3031    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));
3032    
3033  start = LABEL();  start = LABEL();
3034  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 3057  JUMPHERE(quit);
3057  if (firstline)  if (firstline)
3058    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3059  else  else
3060    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));
3061  return TRUE;  return TRUE;
3062  }  }
3063    
# Line 2773  else Line 3104  else
3104    else    else
3105      {      {
3106      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);
3107      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3108      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);
3109      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);
3110      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3111      }      }
3112    }    }
# Line 2817  if (common->nltype == NLTYPE_FIXED && co Line 3148  if (common->nltype == NLTYPE_FIXED && co
3148    
3149    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3150    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);
3151    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3152  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3153    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3154  #endif  #endif
# Line 2860  if (common->nltype == NLTYPE_ANY || comm Line 3191  if (common->nltype == NLTYPE_ANY || comm
3191    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3192    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3193    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);
3194    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3195  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3196    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3197  #endif  #endif
# Line 2875  if (firstline) Line 3206  if (firstline)
3206    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3207  }  }
3208    
3209    static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks);
3210    
3211  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)
3212  {  {
3213  DEFINE_COMPILER;  DEFINE_COMPILER;
3214  struct sljit_label *start;  struct sljit_label *start;
3215  struct sljit_jump *quit;  struct sljit_jump *quit;
3216  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3217    jump_list *matches = NULL;
3218    pcre_uint8 inverted_start_bits[32];
3219    int i;
3220  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3221  struct sljit_jump *jump;  struct sljit_jump *jump;
3222  #endif  #endif
3223    
3224    for (i = 0; i < 32; ++i)
3225      inverted_start_bits[i] = ~(((pcre_uint8*)start_bits)[i]);
3226    
3227  if (firstline)  if (firstline)
3228    {    {
3229    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 3238  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3238  if (common->utf)  if (common->utf)
3239    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3240  #endif  #endif
3241    
3242    if (!check_class_ranges(common, inverted_start_bits, (inverted_start_bits[31] & 0x80) != 0, &matches))
3243      {
3244  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3245  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3246  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3247  JUMPHERE(jump);    JUMPHERE(jump);
3248  #endif  #endif
3249  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3250  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3251  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);
3252  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3253  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);
3254  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3255      }
3256    
3257  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3258  if (common->utf)  if (common->utf)
# Line 2921  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S Line 3264  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S
3264  if (common->utf)  if (common->utf)
3265    {    {
3266    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3267    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);
3268    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3269    }    }
3270  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
# Line 2930  if (common->utf) Line 3273  if (common->utf)
3273    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3274    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3275    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);
3276    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3277    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3278    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3279    }    }
3280  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE[8|16] */
3281  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3282  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3283  JUMPHERE(found);  if (found != NULL)
3284      JUMPHERE(found);
3285    if (matches != NULL)
3286      set_jumps(matches, LABEL());
3287  JUMPHERE(quit);  JUMPHERE(quit);
3288    
3289  if (firstline)  if (firstline)
# Line 3020  GET_LOCAL_BASE(TMP3, 0, 0); Line 3366  GET_LOCAL_BASE(TMP3, 0, 0);
3366  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3367  mainloop = LABEL();  mainloop = LABEL();
3368  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3369  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);
3370    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3371    
3372  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3373  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));
3374  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));
3375  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));
3376  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3377    
3378  JUMPHERE(jump);  JUMPHERE(jump);
3379  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3380  /* End of dropping frames. */  /* End of dropping frames. */
3381  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3382    
3383  JUMPHERE(jump);  JUMPHERE(jump);
3384  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3385  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3386  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3387  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));  
3388  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3389  }  }
3390    
# Line 3061  static void check_wordboundary(compiler_ Line 3392  static void check_wordboundary(compiler_
3392  {  {
3393  DEFINE_COMPILER;  DEFINE_COMPILER;
3394  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3395    jump_list *skipread_list = NULL;
3396  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3397  struct sljit_jump *jump;  struct sljit_jump *jump;
3398  #endif  #endif
# Line 3086  if (common->use_ucp) Line 3418  if (common->use_ucp)
3418    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3419    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3420    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);
3421    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3422    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);
3423    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);
3424    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3425    JUMPHERE(jump);    JUMPHERE(jump);
3426    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3427    }    }
# Line 3118  else Line 3450  else
3450  JUMPHERE(skipread);  JUMPHERE(skipread);
3451    
3452  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3453  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3454  peek_char(common);  peek_char(common);
3455    
3456  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 3130  if (common->use_ucp) Line 3462  if (common->use_ucp)
3462    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3463    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3464    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);
3465    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3466    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);
3467    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);
3468    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3469    JUMPHERE(jump);    JUMPHERE(jump);
3470    }    }
3471  else  else
# Line 3159  else Line 3491  else
3491      JUMPHERE(jump);      JUMPHERE(jump);
3492  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3493    }    }
3494  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3495    
3496  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);
3497  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 3645  sljit_emit_fast_enter(compiler, RETURN_A
3645    
3646  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3647  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);
3648  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3649  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);
3650  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3651  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3652  if (common->utf)  if (common->utf)
3653    {    {
3654  #endif  #endif
3655    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3656    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3657    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);
3658  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3659    }    }
3660  #endif  #endif
3661  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3662  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);
3663  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3664  }  }
3665    
# Line 3339  DEFINE_COMPILER; Line 3671  DEFINE_COMPILER;
3671  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3672    
3673  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);
3674  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3675  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);
3676  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3677  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);
3678  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3679  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3680  if (common->utf)  if (common->utf)
3681    {    {
3682  #endif  #endif
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 | 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);
3685    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3686    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);
3687    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3688    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3689    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);
3690    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3691    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);
3692    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3693    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);
3694    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3695    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);
3696  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3697    }    }
3698  #endif  #endif
3699  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3700  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);
3701    
3702  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3703  }  }
# Line 3379  sljit_emit_fast_enter(compiler, RETURN_A Line 3711  sljit_emit_fast_enter(compiler, RETURN_A
3711    
3712  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3713  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);
3714  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3715  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);
3716  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3717  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3718  if (common->utf)  if (common->utf)
3719    {    {
3720  #endif  #endif
3721    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);
3722    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3723    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);
3724  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3725    }    }
3726  #endif  #endif
3727  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3728  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);
3729    
3730  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3731  }  }
# Line 3479  sljit_emit_fast_return(compiler, RETURN_ Line 3811  sljit_emit_fast_return(compiler, RETURN_
3811    
3812  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
3813    
3814  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)
3815  {  {
3816  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
3817  pcre_uint32 c1, c2;  pcre_uint32 c1, c2;
# Line 3529  if (caseless && char_has_othercase(commo Line 3861  if (caseless && char_has_othercase(commo
3861    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
3862    othercasebit &= 0xff;    othercasebit &= 0xff;
3863  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3864      /* Note that this code only handles characters in the BMP. If there
3865      ever are characters outside the BMP whose othercase differs in only one
3866      bit from itself (there currently are none), this code will need to be
3867      revised for COMPILE_PCRE32. */
3868    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
3869    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
3870      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
# Line 3563  if (context->sourcereg == -1) Line 3899  if (context->sourcereg == -1)
3899    
3900  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3901  utflength = 1;  utflength = 1;
 #ifndef COMPILE_PCRE32  
3902  if (common->utf && HAS_EXTRALEN(*cc))  if (common->utf && HAS_EXTRALEN(*cc))
3903    utflength += GET_EXTRALEN(*cc);    utflength += GET_EXTRALEN(*cc);
 #endif  
3904    
3905  do  do
3906    {    {
3907  #endif  #endif
3908    
3909    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
3910  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
3911    
3912    /* Unaligned read is supported. */    /* Unaligned read is supported. */
3913    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3590  do Line 3924  do
3924    
3925  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
3926    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))
3927  #elif defined COMPILE_PCRE16  #else
3928    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 */)  
3929  #endif  #endif
3930      {      {
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
3931      if (context->length >= 4)      if (context->length >= 4)
3932        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  
3933      else if (context->length >= 2)      else if (context->length >= 2)
3934        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);
3935    #if defined COMPILE_PCRE8
3936      else if (context->length >= 1)      else if (context->length >= 1)
3937        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);
3938  #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] */  
3939      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
3940    
3941      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3621  do Line 3946  do
3946        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));
3947        break;        break;
3948    
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
3949        case 2 / sizeof(pcre_uchar):        case 2 / sizeof(pcre_uchar):
3950        if (context->oc.asushort != 0)        if (context->oc.asushort != 0)
3951          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 3960  do
3960        break;        break;
3961  #endif  #endif
3962    
 #endif /* COMPILE_PCRE[8|16] */  
   
3963        default:        default:
3964        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
3965        break;        break;
# Line 3647  do Line 3969  do
3969    
3970  #else  #else
3971    
3972    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
3973    if (context->length > 0)    if (context->length >= 1)
3974      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
3975    
3976    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
# Line 3731  if ((*cc++ & XCL_MAP) != 0) Line 4053  if ((*cc++ & XCL_MAP) != 0)
4053      {      {
4054      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4055      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4056      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4057      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4058      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);
4059      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 4081  while (*cc != XCL_END)
4081    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
4082      {      {
4083      cc += 2;      cc += 2;
4084  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
4085      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
4086  #endif  #endif
4087  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 3769  while (*cc != XCL_END) Line 4091  while (*cc != XCL_END)
4091    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
4092      {      {
4093      cc += 2;      cc += 2;
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      cc++;      cc++;
4098  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
4099      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
4100  #endif  #endif
4101  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 3809  while (*cc != XCL_END) Line 4131  while (*cc != XCL_END)
4131        break;        break;
4132    
4133        case PT_CLIST:        case PT_CLIST:
4134          case PT_UCNC:
4135        needschar = TRUE;        needschar = TRUE;
4136        break;        break;
4137    
# Line 3848  if (needstype || needsscript) Line 4171  if (needstype || needsscript)
4171      {      {
4172      if (scriptreg == TMP1)      if (scriptreg == TMP1)
4173        {        {
4174        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));
4175        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
4176        }        }
4177      else      else
4178        {        {
4179        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
4180        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));
4181        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
4182        }        }
4183      }      }
# Line 3890  while (*cc != XCL_END) Line 4213  while (*cc != XCL_END)
4213      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4214        {        {
4215        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);
4216        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);
4217        numberofcmps++;        numberofcmps++;
4218        }        }
4219      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4220        {        {
4221        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);
4222        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);
4223        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4224        numberofcmps = 0;        numberofcmps = 0;
4225        }        }
# Line 3929  while (*cc != XCL_END) Line 4252  while (*cc != XCL_END)
4252      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4253        {        {
4254        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);
4255        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);
4256        numberofcmps++;        numberofcmps++;
4257        }        }
4258      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4259        {        {
4260        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);
4261        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);
4262        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4263        numberofcmps = 0;        numberofcmps = 0;
4264        }        }
# Line 3966  while (*cc != XCL_END) Line 4289  while (*cc != XCL_END)
4289    
4290        case PT_LAMP:        case PT_LAMP:
4291        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);
4292        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4293        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);
4294        COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4295        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);
4296        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);
4297        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4298        break;        break;
4299    
# Line 3990  while (*cc != XCL_END) Line 4313  while (*cc != XCL_END)
4313    
4314        case PT_SPACE:        case PT_SPACE:
4315        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);  
         }  
4316        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4317        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, 0xd - 0x9);
4318        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4319        if (*cc == PT_SPACE)  
4320          JUMPHERE(jump);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x9);
4321          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4322    
4323          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x9);
4324          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4325    
4326        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4327        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);
4328        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);
4329        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4330        break;        break;
4331    
4332        case PT_WORD:        case PT_WORD:
4333        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);
4334        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4335        /* ... fall through */        /* Fall through. */
4336    
4337        case PT_ALNUM:        case PT_ALNUM:
4338        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
4339        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);
4340        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);
4341        SET_TYPE_OFFSET(ucp_Nd);        SET_TYPE_OFFSET(ucp_Nd);
4342        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);
4343        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);
4344        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4345        break;        break;
4346    
# Line 4037  while (*cc != XCL_END) Line 4359  while (*cc != XCL_END)
4359            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]);
4360          else          else
4361            {            {
4362            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_w)charoffset);            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4363            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]);
4364            }            }
4365          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]);
4366          COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4367          other_cases += 2;          other_cases += 2;
4368          }          }
4369        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 4372  while (*cc != XCL_END)
4372            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]);
4373          else          else
4374            {            {
4375            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_w)charoffset);            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4376            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]);
4377            }            }
4378          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]);
4379          COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4380    
4381          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);
4382          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);
4383    
4384          other_cases += 3;          other_cases += 3;
4385          }          }
4386        else        else
4387          {          {
4388          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);
4389          COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4390          }          }
4391    
4392        while (*other_cases != NOTACHAR)        while (*other_cases != NOTACHAR)
4393          {          {
4394          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);
4395          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);
4396          }          }
4397        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4398        break;        break;
4399    
4400          case PT_UCNC:
4401          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);
4402          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4403          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);
4404          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4405          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);
4406          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4407    
4408          SET_CHAR_OFFSET(0xa0);
4409          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);
4410          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4411          SET_CHAR_OFFSET(0);
4412          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
4413          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4414          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4415          break;
4416        }        }
4417      cc += 2;      cc += 2;
4418      }      }
# Line 4099  int length; Line 4438  int length;
4438  unsigned int c, oc, bit;  unsigned int c, oc, bit;
4439  compare_context context;  compare_context context;
4440  struct sljit_jump *jump[4];  struct sljit_jump *jump[4];
4441    jump_list *end_list;
4442  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4443  struct sljit_label *label;  struct sljit_label *label;
4444  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4167  switch(type) Line 4507  switch(type)
4507    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4508      {      {
4509      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);
4510        end_list = NULL;
4511      if (common->mode != JIT_PARTIAL_HARD_COMPILE)      if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4512        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));
4513      else      else
4514        jump[1] = check_str_end(common);        check_str_end(common, &end_list);
4515    
4516      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4517      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));
4518      if (jump[1] != NULL)      set_jumps(end_list, LABEL());
       JUMPHERE(jump[1]);  
4519      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4520      }      }
4521    else    else
# Line 4192  switch(type) Line 4532  switch(type)
4532  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16
4533  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
4534      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4535      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);
4536      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4537  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
4538      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
4539      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
4540      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);
4541      COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4542      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4543      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4544  #endif  #endif
# Line 4234  switch(type) Line 4574  switch(type)
4574    read_char(common);    read_char(common);
4575    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);
4576    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
4577      end_list = NULL;
4578    if (common->mode != JIT_PARTIAL_HARD_COMPILE)    if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4579      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));
4580    else    else
4581      jump[1] = check_str_end(common);      check_str_end(common, &end_list);
4582    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4583    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);
4584    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));
4585    jump[3] = JUMP(SLJIT_JUMP);    jump[2] = JUMP(SLJIT_JUMP);
4586    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4587    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);
4588      set_jumps(end_list, LABEL());
4589    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
4590    JUMPHERE(jump[2]);    JUMPHERE(jump[2]);
   JUMPHERE(jump[3]);  
4591    return cc;    return cc;
4592    
4593    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
# Line 4270  switch(type) Line 4611  switch(type)
4611    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
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    /* Optimize register allocation: use a real register. */    /* Optimize register allocation: use a real register. */
4616    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
4617    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 4621  switch(type)
4621    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
4622    read_char(common);    read_char(common);
4623    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4624    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));
4625    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);
4626    
4627    OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);    OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);
4628    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));
4629    OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);    OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);
4630    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4631    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 4658  switch(type)
4658        {        {
4659        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);
4660        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);
4661        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS);
4662        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);
4663        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);
4664        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));
4665        check_partial(common, TRUE);        check_partial(common, TRUE);
4666        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
# Line 4467  switch(type) Line 4808  switch(type)
4808    case OP_CHAR:    case OP_CHAR:
4809    case OP_CHARI:    case OP_CHARI:
4810    length = 1;    length = 1;
4811  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
4812    if (common->utf && HAS_EXTRALEN(*cc)) length += GET_EXTRALEN(*cc);    if (common->utf && HAS_EXTRALEN(*cc)) length += GET_EXTRALEN(*cc);
4813  #endif  #endif
4814    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 4847  switch(type)
4847      return cc + length;      return cc + length;
4848      }      }
4849    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);
4850    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4851    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);
4852    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);
4853    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
4854    return cc + length;    return cc + length;
4855    
# Line 4535  switch(type) Line 4876  switch(type)
4876        /* Skip the variable-length character. */        /* Skip the variable-length character. */
4877        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));
4878        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);        jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4879        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);
4880        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4881        JUMPHERE(jump[0]);        JUMPHERE(jump[0]);
4882        return cc + 1;        return cc + 1;
# Line 4598  switch(type) Line 4939  switch(type)
4939  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */  #endif /* SUPPORT_UTF || !COMPILE_PCRE8 */
4940    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4941    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4942    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4943    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4944    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);
4945    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
# Line 4662  do Line 5003  do
5003    if (*cc == OP_CHAR)    if (*cc == OP_CHAR)
5004      {      {
5005      size = 1;      size = 1;
5006  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
5007      if (common->utf && HAS_EXTRALEN(cc[1]))      if (common->utf && HAS_EXTRALEN(cc[1]))
5008        size += GET_EXTRALEN(cc[1]);        size += GET_EXTRALEN(cc[1]);
5009  #endif  #endif
# Line 4675  do Line 5016  do
5016        {        {
5017        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)
5018          size = 0;          size = 0;
 #ifndef COMPILE_PCRE32  
5019        else if (HAS_EXTRALEN(cc[1]))        else if (HAS_EXTRALEN(cc[1]))
5020          size += GET_EXTRALEN(cc[1]);          size += GET_EXTRALEN(cc[1]);
 #endif  
5021        }        }
5022      else      else
5023  #endif  #endif
# Line 4705  if (context.length > 0) Line 5044  if (context.length > 0)
5044    context.ucharptr = 0;    context.ucharptr = 0;
5045  #endif  #endif
5046    do cc = byte_sequence_compare(common, *cc == OP_CHARI, cc + 1, &context, backtracks); while (context.length > 0);    do cc = byte_sequence_compare(common, *cc == OP_CHARI, cc + 1, &context, backtracks); while (context.length > 0);
5047    return cc;    return cc;
   }  
   
 /* A non-fixed length character will be checked if length == 0. */  
 return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);  
 }  
   
 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)));  
5048    }    }
5049  return CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
5050    /* A non-fixed length character will be checked if length == 0. */
5051    return compile_char1_matchingpath(common, *cc, cc + 1, backtracks);
5052  }  }
5053    
5054  /* Forward definitions. */  /* Forward definitions. */
# Line 4766  static void compile_backtrackingpath(com Line 5083  static void compile_backtrackingpath(com
5083    
5084  #define BACKTRACK_AS(type) ((type *)backtrack)  #define BACKTRACK_AS(type) ((type *)backtrack)
5085    
5086  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)
5087    {
5088    /* The OVECTOR offset goes to TMP2. */
5089    DEFINE_COMPILER;
5090    int count = GET2(cc, 1 + IMM2_SIZE);
5091    pcre_uchar *slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
5092    unsigned int offset;
5093    jump_list *found = NULL;
5094    
5095    SLJIT_ASSERT(*cc == OP_DNREF || *cc == OP_DNREFI);
5096    
5097    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
5098    
5099    count--;
5100    while (count-- > 0)
5101      {
5102      offset = GET2(slot, 0) << 1;
5103      GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5104      add_jump(compiler, &found, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5105      slot += common->name_entry_size;
5106      }
5107    
5108    offset = GET2(slot, 0) << 1;
5109    GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset));
5110    if (backtracks != NULL && !common->jscript_compat)
5111      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0));
5112    
5113    set_jumps(found, LABEL());
5114    }
5115    
5116    static void compile_ref_matchingpath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)
5117  {  {
5118  DEFINE_COMPILER;  DEFINE_COMPILER;
5119  int offset = GET2(cc, 1) << 1;  BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5120    int offset = 0;
5121  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
5122  struct sljit_jump *partial;  struct sljit_jump *partial;
5123  struct sljit_jump *nopartial;  struct sljit_jump *nopartial;
5124    
5125  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  if (ref)
5126  /* OVECTOR(1) contains the "string begin - 1" constant. */    {
5127  if (withchecks && !common->jscript_compat)    offset = GET2(cc, 1) << 1;
5128    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));
5129      /* OVECTOR(1) contains the "string begin - 1" constant. */
5130      if (withchecks && !common->jscript_compat)
5131        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5132      }
5133    else
5134      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5135    
5136  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
5137  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
5138    {    {
5139    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);
5140    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));    if (ref)
5141        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5142      else
5143        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5144    
5145    if (withchecks)    if (withchecks)
5146      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);      jump = CMP(SLJIT_C_EQUAL, TMP1, 0, TMP2, 0);
5147    
5148    /* Needed to save important temporary registers. */    /* Needed to save important temporary registers. */
5149    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5150    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
5151    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);
5152    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));
5153    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5154    if (common->mode == JIT_COMPILE)    if (common->mode == JIT_COMPILE)
# Line 4808  if (common->utf && *cc == OP_REFI) Line 5166  if (common->utf && *cc == OP_REFI)
5166  else  else
5167  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
5168    {    {
5169    OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);    if (ref)
5170        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP1, 0);
5171      else
5172        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
5173    
5174    if (withchecks)    if (withchecks)
5175      jump = JUMP(SLJIT_C_ZERO);      jump = JUMP(SLJIT_C_ZERO);
5176    
# Line 4845  if (jump != NULL) Line 5207  if (jump != NULL)
5207    else    else
5208      JUMPHERE(jump);      JUMPHERE(jump);
5209    }    }
 return cc + 1 + IMM2_SIZE;  
5210  }  }
5211    
5212  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)
5213  {  {
5214  DEFINE_COMPILER;  DEFINE_COMPILER;
5215    BOOL ref = (*cc == OP_REF || *cc == OP_REFI);
5216  backtrack_common *backtrack;  backtrack_common *backtrack;
5217  pcre_uchar type;  pcre_uchar type;
5218    int offset = 0;
5219  struct sljit_label *label;  struct sljit_label *label;
5220  struct sljit_jump *zerolength;  struct sljit_jump *zerolength;
5221  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 4862  BOOL minimize; Line 5225  BOOL minimize;
5225    
5226  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
5227    
5228    if (ref)
5229      offset = GET2(cc, 1) << 1;
5230    else
5231      cc += IMM2_SIZE;
5232  type = cc[1 + IMM2_SIZE];  type = cc[1 + IMM2_SIZE];
5233    
5234    SLJIT_COMPILE_ASSERT((OP_CRSTAR & 0x1) == 0, crstar_opcode_must_be_even);
5235  minimize = (type & 0x1) != 0;  minimize = (type & 0x1) != 0;
5236  switch(type)  switch(type)
5237    {    {
# Line 4900  if (!minimize) Line 5269  if (!minimize)
5269    if (min == 0)    if (min == 0)
5270      {      {
5271      allocate_stack(common, 2);      allocate_stack(common, 2);
5272        if (ref)
5273          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5274      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5275      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5276      /* Temporary release of STR_PTR. */      /* Temporary release of STR_PTR. */
5277      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));
5278      zerolength = compile_ref_checks(common, ccbegin, NULL);      /* Handles both invalid and empty cases. Since the minimum repeat,
5279        is zero the invalid case is basically the same as an empty case. */
5280        if (ref)
5281          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5282        else
5283          {
5284          compile_dnref_search(common, ccbegin, NULL);
5285          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5286          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5287          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5288          }
5289      /* Restore if not zero length. */      /* Restore if not zero length. */
5290      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));
5291      }      }
5292    else    else
5293      {      {
5294      allocate_stack(common, 1);      allocate_stack(common, 1);
5295        if (ref)
5296          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5297      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5298      zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);      if (ref)
5299          {
5300          add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5301          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5302          }
5303        else
5304          {
5305          compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5306          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5307          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, TMP2, 0);
5308          zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5309          }
5310      }      }
5311    
5312    if (min > 1 || max > 1)    if (min > 1 || max > 1)
5313      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
5314    
5315    label = LABEL();    label = LABEL();
5316      if (!ref)
5317        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
5318    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);    compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);
5319    
5320    if (min > 1 || max > 1)    if (min > 1 || max > 1)
# Line 4949  if (!minimize) Line 5345  if (!minimize)
5345    JUMPHERE(zerolength);    JUMPHERE(zerolength);
5346    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5347    
5348    decrease_call_count(common);    count_match(common);
5349    return cc;    return cc;
5350    }    }
5351    
5352  allocate_stack(common, 2);  allocate_stack(common, ref ? 2 : 3);
5353    if (ref)
5354      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
5355  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5356  if (type != OP_CRMINSTAR)  if (type != OP_CRMINSTAR)
5357    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 0);
5358    
5359  if (min == 0)  if (min == 0)
5360    {    {
5361    zerolength = compile_ref_checks(common, ccbegin, NULL);    /* Handles both invalid and empty cases. Since the minimum repeat,
5362      is zero the invalid case is basically the same as an empty case. */
5363      if (ref)
5364        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5365      else
5366        {
5367        compile_dnref_search(common, ccbegin, NULL);
5368        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5369        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5370        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5371        }
5372      /* Length is non-zero, we can match real repeats. */
5373    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5374    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
5375    }    }
5376  else  else
5377    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);    {
5378      if (ref)
5379        {
5380        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5381        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
5382        }
5383      else
5384        {
5385        compile_dnref_search(common, ccbegin, &backtrack->topbacktracks);
5386        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), 0);
5387        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP2, 0);
5388        zerolength = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(TMP2), sizeof(sljit_sw));
5389        }
5390      }
5391    
5392  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();  BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5393  if (max > 0)  if (max > 0)
5394    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));
5395    
5396    if (!ref)
5397      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(2));
5398  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);  compile_ref_matchingpath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);
5399  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5400    
# Line 4988  if (jump != NULL) Line 5412  if (jump != NULL)
5412    JUMPHERE(jump);    JUMPHERE(jump);
5413  JUMPHERE(zerolength);  JUMPHERE(zerolength);
5414    
5415  decrease_call_count(common);  count_match(common);
5416  return cc;  return cc;
5417  }  }
5418    
# Line 4998  DEFINE_COMPILER; Line 5422  DEFINE_COMPILER;
5422  backtrack_common *backtrack;  backtrack_common *backtrack;
5423  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5424  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5425  int start = GET(cc, 1);  sljit_sw start = GET(cc, 1);
5426    pcre_uchar *start_cc;
5427    BOOL needs_control_head;
5428    
5429  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5430    
5431    /* Inlining simple patterns. */
5432    if (get_framesize(common, common->start + start, NULL, TRUE, &needs_control_head) == no_stack)
5433      {
5434      start_cc = common->start + start;
5435      compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
5436      BACKTRACK_AS(recurse_backtrack)->inlined_pattern = TRUE;
5437      return cc + 1 + LINK_SIZE;
5438      }
5439    
5440  while (entry != NULL)  while (entry != NULL)
5441    {    {
5442    if (entry->start == start)    if (entry->start == start)
# Line 5049  add_jump(compiler, &backtrack->topbacktr Line 5485  add_jump(compiler, &backtrack->topbacktr
5485  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5486  }  }
5487    
5488    static int SLJIT_CALL do_callout(struct jit_arguments* arguments, PUBL(callout_block) *callout_block, pcre_uchar **jit_ovector)
5489    {
5490    const pcre_uchar *begin = arguments->begin;
5491    int *offset_vector = arguments->offsets;
5492    int offset_count = arguments->offset_count;
5493    int i;
5494    
5495    if (PUBL(callout) == NULL)
5496      return 0;
5497    
5498    callout_block->version = 2;
5499    callout_block->callout_data = arguments->callout_data;
5500    
5501    /* Offsets in subject. */
5502    callout_block->subject_length = arguments->end - arguments->begin;
5503    callout_block->start_match = (pcre_uchar*)callout_block->subject - arguments->begin;
5504    callout_block->current_position = (pcre_uchar*)callout_block->offset_vector - arguments->begin;
5505    #if defined COMPILE_PCRE8
5506    callout_block->subject = (PCRE_SPTR)begin;
5507    #elif defined COMPILE_PCRE16
5508    callout_block->subject = (PCRE_SPTR16)begin;
5509    #elif defined COMPILE_PCRE32
5510    callout_block->subject = (PCRE_SPTR32)begin;
5511    #endif
5512    
5513    /* Convert and copy the JIT offset vector to the offset_vector array. */
5514    callout_block->capture_top = 0;
5515    callout_block->offset_vector = offset_vector;
5516    for (i = 2; i < offset_count; i += 2)
5517      {
5518      offset_vector[i] = jit_ovector[i] - begin;
5519      offset_vector[i + 1] = jit_ovector[i + 1] - begin;
5520      if (jit_ovector[i] >= begin)
5521        callout_block->capture_top = i;
5522      }
5523    
5524    callout_block->capture_top = (callout_block->capture_top >> 1) + 1;
5525    if (offset_count > 0)
5526      offset_vector[0] = -1;
5527    if (offset_count > 1)
5528      offset_vector[1] = -1;
5529    return (*PUBL(callout))(callout_block);
5530    }
5531    
5532    /* Aligning to 8 byte. */
5533    #define CALLOUT_ARG_SIZE \
5534        (((int)sizeof(PUBL(callout_block)) + 7) & ~7)
5535    
5536    #define CALLOUT_ARG_OFFSET(arg) \
5537        (-CALLOUT_ARG_SIZE + SLJIT_OFFSETOF(PUBL(callout_block), arg))
5538    
5539    static SLJIT_INLINE pcre_uchar *compile_callout_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5540    {
5541    DEFINE_COMPILER;
5542    backtrack_common *backtrack;
5543    
5544    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
5545    
5546    allocate_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5547    
5548    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
5549    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
5550    SLJIT_ASSERT(common->capture_last_ptr != 0);
5551    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, cc[1]);
5552    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0);
5553    
5554    /* These pointer sized fields temporarly stores internal variables. */
5555    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
5556    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(offset_vector), STR_PTR, 0);
5557    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(subject), TMP2, 0);
5558    
5559    if (common->mark_ptr != 0)
5560      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr));
5561    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 2));
5562    OP1(SLJIT_MOV_SI, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, GET(cc, 2 + LINK_SIZE));
5563    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(mark), (common->mark_ptr != 0) ? TMP2 : SLJIT_IMM, 0);
5564    
5565    /* Needed to save important temporary registers. */
5566    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
5567    OP2(SLJIT_SUB, SLJIT_SCRATCH_REG2, 0, STACK_TOP, 0, SLJIT_IMM, CALLOUT_ARG_SIZE);
5568    GET_LOCAL_BASE(SLJIT_SCRATCH_REG3, 0, OVECTOR_START);
5569    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_callout));
5570    OP1(SLJIT_MOV_SI, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0);
5571    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
5572    free_stack(common, CALLOUT_ARG_SIZE / sizeof(sljit_sw));
5573    
5574    /* Check return value. */
5575    OP2(SLJIT_SUB | SLJIT_SET_S, SLJIT_UNUSED, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
5576    add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_C_SIG_GREATER));
5577    if (common->forced_quit_label == NULL)
5578      add_jump(compiler, &common->forced_quit, JUMP(SLJIT_C_SIG_LESS));
5579    else
5580      JUMPTO(SLJIT_C_SIG_LESS, common->forced_quit_label);
5581    return cc + 2 + 2 * LINK_SIZE;
5582    }
5583    
5584    #undef CALLOUT_ARG_SIZE
5585    #undef CALLOUT_ARG_OFFSET
5586    
5587  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)
5588  {  {
5589  DEFINE_COMPILER;  DEFINE_COMPILER;
5590  int framesize;  int framesize;
5591    int extrasize;
5592    BOOL needs_control_head;
5593  int private_data_ptr;  int private_data_ptr;
5594  backtrack_common altbacktrack;  backtrack_common altbacktrack;
5595  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
# Line 5062  jump_list *tmp = NULL; Line 5599  jump_list *tmp = NULL;
5599  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5600  jump_list **found;  jump_list **found;
5601  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5602  struct sljit_label *save_quitlabel = common->quitlabel;  BOOL save_local_exit = common->local_exit;
5603  struct sljit_label *save_acceptlabel = common->acceptlabel;  BOOL save_positive_assert = common->positive_assert;
5604    then_trap_backtrack *save_then_trap = common->then_trap;
5605    struct sljit_label *save_quit_label = common->quit_label;
5606    struct sljit_label *save_accept_label = common->accept_label;
5607  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
5608    jump_list *save_positive_assert_quit = common->positive_assert_quit;
5609  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
5610  struct sljit_jump *jump;  struct sljit_jump *jump;
5611  struct sljit_jump *brajump = NULL;  struct sljit_jump *brajump = NULL;
5612    
5613    /* Assert captures then. */
5614    common->then_trap = NULL;
5615    
5616  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
5617    {    {
5618    SLJIT_ASSERT(!conditional);    SLJIT_ASSERT(!conditional);
# Line 5077  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 5621  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
5621    }    }
5622  private_data_ptr = PRIVATE_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
5623  SLJIT_ASSERT(private_data_ptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
5624  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
5625  backtrack->framesize = framesize;  backtrack->framesize = framesize;
5626  backtrack->private_data_ptr = private_data_ptr;  backtrack->private_data_ptr = private_data_ptr;
5627  opcode = *cc;  opcode = *cc;
# Line 5096  if (bra == OP_BRAMINZERO) Line 5640  if (bra == OP_BRAMINZERO)
5640    
5641  if (framesize < 0)  if (framesize < 0)
5642    {    {
5643    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);    extrasize = needs_control_head ? 2 : 1;
5644    allocate_stack(common, 1);    if (framesize == no_frame)
5645        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
5646      allocate_stack(common, extrasize);
5647      if (needs_control_head)
5648        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5649    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5650      if (needs_control_head)
5651        {
5652        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5653        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5654        }
5655    }    }
5656  else  else
5657    {    {
5658    allocate_stack(common, framesize + 2);    extrasize = needs_control_head ? 3 : 2;
5659      allocate_stack(common, framesize + extrasize);
5660    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);
5661    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));
5662    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);
5663      if (needs_control_head)
5664        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
5665    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5666    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    if (needs_control_head)
5667    init_frame(common, ccbegin, framesize + 1, 2, FALSE);      {
5668        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
5669        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
5670        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
5671        }
5672      else
5673        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5674      init_frame(common, ccbegin, NULL, framesize + extrasize - 1, extrasize, FALSE);
5675    }    }
5676    
5677  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
5678  common->quitlabel = NULL;  if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5679  common->quit = NULL;    {
5680      /* Negative assert is stronger than positive assert. */
5681      common->local_exit = TRUE;
5682      common->quit_label = NULL;
5683      common->quit = NULL;
5684      common->positive_assert = FALSE;
5685      }
5686    else
5687      common->positive_assert = TRUE;
5688    common->positive_assert_quit = NULL;
5689    
5690  while (1)  while (1)
5691    {    {
5692    common->acceptlabel = NULL;    common->accept_label = NULL;
5693    common->accept = NULL;    common->accept = NULL;
5694    altbacktrack.top = NULL;    altbacktrack.top = NULL;
5695    altbacktrack.topbacktracks = NULL;    altbacktrack.topbacktracks = NULL;
# Line 5128  while (1) Line 5701  while (1)
5701    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
5702    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5703      {      {
5704      common->quitlabel = save_quitlabel;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5705      common->acceptlabel = save_acceptlabel;        {
5706      common->quit = save_quit;        common->local_exit = save_local_exit;
5707          common->quit_label = save_quit_label;
5708          common->quit = save_quit;
5709          }
5710        common->positive_assert = save_positive_assert;
5711        common->then_trap = save_then_trap;
5712        common->accept_label = save_accept_label;
5713        common->positive_assert_quit = save_positive_assert_quit;
5714      common->accept = save_accept;      common->accept = save_accept;
5715      return NULL;      return NULL;
5716      }      }
5717    common->acceptlabel = LABEL();    common->accept_label = LABEL();
5718    if (common->accept != NULL)    if (common->accept != NULL)
5719      set_jumps(common->accept, common->acceptlabel);      set_jumps(common->accept, common->accept_label);
5720    
5721    /* Reset stack. */    /* Reset stack. */
5722    if (framesize < 0)    if (framesize < 0)
5723      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);      {
5724    else {      if (framesize == no_frame)
5725          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5726        else
5727          free_stack(common, extrasize);
5728        if (needs_control_head)
5729          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5730        }
5731      else
5732        {
5733      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)      if ((opcode != OP_ASSERT_NOT && opcode != OP_ASSERTBACK_NOT) || conditional)
5734        {        {
5735        /* 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. */
5736        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));
5737          if (needs_control_head)
5738            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), 0);
5739        }        }
5740      else      else
5741        {        {
5742        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);
5743          if (needs_control_head)
5744            OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), (framesize + 1) * sizeof(sljit_sw));
5745        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5746        }        }
5747    }      }
5748    
5749    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5750      {      {
5751      /* 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. */
5752      if (conditional)      if (conditional)
5753        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);
5754      else if (bra == OP_BRAZERO)      else if (bra == OP_BRAZERO)
5755        {        {
5756        if (framesize < 0)        if (framesize < 0)
5757          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));
5758        else        else
5759          {          {
5760          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));
5761          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));
5762          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);
5763          }          }
5764        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));
5765        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5766        }        }
5767      else if (framesize >= 0)      else if (framesize >= 0)
5768        {        {
5769        /* For OP_BRA and OP_BRAMINZERO. */        /* For OP_BRA and OP_BRAMINZERO. */
5770        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));
5771        }        }
5772      }      }
5773    add_jump(compiler, found, JUMP(SLJIT_JUMP));    add_jump(compiler, found, JUMP(SLJIT_JUMP));
# Line 5183  while (1) Line 5775  while (1)
5775    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
5776    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5777      {      {
5778      common->quitlabel = save_quitlabel;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5779      common->acceptlabel = save_acceptlabel;        {
5780      common->quit = save_quit;        common->local_exit = save_local_exit;
5781          common->quit_label = save_quit_label;
5782          common->quit = save_quit;
5783          }
5784        common->positive_assert = save_positive_assert;
5785        common->then_trap = save_then_trap;
5786        common->accept_label = save_accept_label;
5787        common->positive_assert_quit = save_positive_assert_quit;
5788      common->accept = save_accept;      common->accept = save_accept;
5789      return NULL;      return NULL;
5790      }      }
# Line 5197  while (1) Line 5796  while (1)
5796    ccbegin = cc;    ccbegin = cc;
5797    cc += GET(cc, 1);    cc += GET(cc, 1);
5798    }    }
5799    
5800    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5801      {
5802      SLJIT_ASSERT(common->positive_assert_quit == NULL);
5803      /* Makes the check less complicated below. */
5804      common->positive_assert_quit = common->quit;
5805      }
5806    
5807  /* None of them matched. */  /* None of them matched. */
5808  if (common->quit != NULL)  if (common->positive_assert_quit != NULL)
5809    set_jumps(common->quit, LABEL());    {
5810      jump = JUMP(SLJIT_JUMP);
5811      set_jumps(common->positive_assert_quit, LABEL());
5812      SLJIT_ASSERT(framesize != no_stack);
5813      if (framesize < 0)
5814        OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));
5815      else
5816        {
5817        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5818        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
5819        OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, (framesize + extrasize) * sizeof(sljit_sw));
5820        }
5821      JUMPHERE(jump);
5822      }
5823    
5824    if (needs_control_head)
5825      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(1));
5826    
5827  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)  if (opcode == OP_ASSERT || opcode == OP_ASSERTBACK)
5828    {    {
# Line 5211  if (opcode == OP_ASSERT || opcode == OP_ Line 5834  if (opcode == OP_ASSERT || opcode == OP_
5834      {      {
5835      /* The topmost item should be 0. */      /* The topmost item should be 0. */
5836      if (bra == OP_BRAZERO)      if (bra == OP_BRAZERO)
5837          {
5838          if (extrasize == 2)
5839            free_stack(common, 1);
5840        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
5841          }
5842      else      else
5843        free_stack(common, 1);        free_stack(common, extrasize);
5844      }      }
5845    else    else
5846      {      {
5847      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(extrasize - 1));
5848      /* The topmost item should be 0. */      /* The topmost item should be 0. */