/[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 1420 by zherczeg, Sun Dec 29 11:43:10 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 MAX_RANGE_SIZE 6  #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 4
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;
   int digits[2 + MAX_RANGE_SIZE];  
372    /* Named capturing brackets. */    /* Named capturing brackets. */
373    sljit_uw name_table;    pcre_uchar *name_table;
374    sljit_w name_count;    sljit_sw name_count;
375    sljit_w name_entry_size;    sljit_sw name_entry_size;
376    
377    /* Labels and jump lists. */    /* Labels and jump lists. */
378    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
379    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
380    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
381      struct sljit_label *accept_label;
382    stub_list *stubs;    stub_list *stubs;
383    recurse_entry *entries;    recurse_entry *entries;
384    recurse_entry *currententry;    recurse_entry *currententry;
385    jump_list *partialmatch;    jump_list *partialmatch;
386    jump_list *quit;    jump_list *quit;
387      jump_list *positive_assert_quit;
388      jump_list *forced_quit;
389    jump_list *accept;    jump_list *accept;
390    jump_list *calllimit;    jump_list *calllimit;
391    jump_list *stackalloc;    jump_list *stackalloc;
# Line 337  typedef struct compiler_common { Line 396  typedef struct compiler_common {
396    jump_list *vspace;    jump_list *vspace;
397    jump_list *casefulcmp;    jump_list *casefulcmp;
398    jump_list *caselesscmp;    jump_list *caselesscmp;
399      jump_list *reset_match;
400    BOOL jscript_compat;    BOOL jscript_compat;
401  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
402    BOOL utf;    BOOL utf;
# Line 347  typedef struct compiler_common { Line 407  typedef struct compiler_common {
407    jump_list *utfreadchar;    jump_list *utfreadchar;
408  #endif  #endif
409  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
410      jump_list *utfreadchar8;
411    jump_list *utfreadtype8;    jump_list *utfreadtype8;
412  #endif  #endif
413  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_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 476  cc += 1 + LINK_SIZE; Line 533  cc += 1 + LINK_SIZE;
533  return cc;  return cc;
534  }  }
535    
536    static int ones_in_half_byte[16] = {
537      /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
538      /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
539    };
540    
541  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
542   next_opcode   next_opcode
543   get_private_data_length   check_opcode_types
544   set_private_data_ptrs   set_private_data_ptrs
545   get_framesize   get_framesize
546   init_frame   init_frame
547   get_private_data_length_for_copy   get_private_data_copy_length
548   copy_private_data   copy_private_data
549   compile_matchingpath   compile_matchingpath
550   compile_backtrackingpath   compile_backtrackingpath
# Line 506  switch(*cc) Line 568  switch(*cc)
568    case OP_WORDCHAR:    case OP_WORDCHAR:
569    case OP_ANY:    case OP_ANY:
570    case OP_ALLANY:    case OP_ALLANY:
571      case OP_NOTPROP:
572      case OP_PROP:
573    case OP_ANYNL:    case OP_ANYNL:
574    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
575    case OP_HSPACE:    case OP_HSPACE:
# Line 518  switch(*cc) Line 582  switch(*cc)
582    case OP_CIRCM:    case OP_CIRCM:
583    case OP_DOLL:    case OP_DOLL:
584    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:  
585    case OP_CRSTAR:    case OP_CRSTAR:
586    case OP_CRMINSTAR:    case OP_CRMINSTAR:
587    case OP_CRPLUS:    case OP_CRPLUS:
588    case OP_CRMINPLUS:    case OP_CRMINPLUS:
589    case OP_CRQUERY:    case OP_CRQUERY:
590    case OP_CRMINQUERY:    case OP_CRMINQUERY:
591      case OP_CRRANGE:
592      case OP_CRMINRANGE:
593      case OP_CRPOSSTAR:
594      case OP_CRPOSPLUS:
595      case OP_CRPOSQUERY:
596      case OP_CRPOSRANGE:
597      case OP_CLASS:
598      case OP_NCLASS:
599      case OP_REF:
600      case OP_REFI:
601      case OP_DNREF:
602      case OP_DNREFI:
603      case OP_RECURSE:
604      case OP_CALLOUT:
605      case OP_ALT:
606      case OP_KET:
607      case OP_KETRMAX:
608      case OP_KETRMIN:
609      case OP_KETRPOS:
610      case OP_REVERSE:
611      case OP_ASSERT:
612      case OP_ASSERT_NOT:
613      case OP_ASSERTBACK:
614      case OP_ASSERTBACK_NOT:
615      case OP_ONCE:
616      case OP_ONCE_NC:
617      case OP_BRA:
618      case OP_BRAPOS:
619      case OP_CBRA:
620      case OP_CBRAPOS:
621      case OP_COND:
622      case OP_SBRA:
623      case OP_SBRAPOS:
624      case OP_SCBRA:
625      case OP_SCBRAPOS:
626      case OP_SCOND:
627      case OP_CREF:
628      case OP_DNCREF:
629      case OP_RREF:
630      case OP_DNRREF:
631    case OP_DEF:    case OP_DEF:
632    case OP_BRAZERO:    case OP_BRAZERO:
633    case OP_BRAMINZERO:    case OP_BRAMINZERO:
634    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
635      case OP_PRUNE:
636      case OP_SKIP:
637      case OP_THEN:
638    case OP_COMMIT:    case OP_COMMIT:
639    case OP_FAIL:    case OP_FAIL:
640    case OP_ACCEPT:    case OP_ACCEPT:
641    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
642      case OP_CLOSE:
643    case OP_SKIPZERO:    case OP_SKIPZERO:
644    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
645    
646    case OP_CHAR:    case OP_CHAR:
647    case OP_CHARI:    case OP_CHARI:
# Line 560  switch(*cc) Line 653  switch(*cc)
653    case OP_MINPLUS:    case OP_MINPLUS:
654    case OP_QUERY:    case OP_QUERY:
655    case OP_MINQUERY:    case OP_MINQUERY:
656      case OP_UPTO:
657      case OP_MINUPTO:
658      case OP_EXACT:
659    case OP_POSSTAR:    case OP_POSSTAR:
660    case OP_POSPLUS:    case OP_POSPLUS:
661    case OP_POSQUERY:    case OP_POSQUERY:
662      case OP_POSUPTO:
663    case OP_STARI:    case OP_STARI:
664    case OP_MINSTARI:    case OP_MINSTARI:
665    case OP_PLUSI:    case OP_PLUSI:
666    case OP_MINPLUSI:    case OP_MINPLUSI:
667    case OP_QUERYI:    case OP_QUERYI:
668    case OP_MINQUERYI:    case OP_MINQUERYI:
669      case OP_UPTOI:
670      case OP_MINUPTOI:
671      case OP_EXACTI:
672    case OP_POSSTARI:    case OP_POSSTARI:
673    case OP_POSPLUSI:    case OP_POSPLUSI:
674    case OP_POSQUERYI:    case OP_POSQUERYI:
675      case OP_POSUPTOI:
676    case OP_NOTSTAR:    case OP_NOTSTAR:
677    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
678    case OP_NOTPLUS:    case OP_NOTPLUS:
679    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
680    case OP_NOTQUERY:    case OP_NOTQUERY:
681    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
682      case OP_NOTUPTO:
683      case OP_NOTMINUPTO:
684      case OP_NOTEXACT:
685    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
686    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
687    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
688      case OP_NOTPOSUPTO:
689    case OP_NOTSTARI:    case OP_NOTSTARI:
690    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
691    case OP_NOTPLUSI:    case OP_NOTPLUSI:
692    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
693    case OP_NOTQUERYI:    case OP_NOTQUERYI:
694    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:  
695    case OP_NOTUPTOI:    case OP_NOTUPTOI:
696    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
697    case OP_NOTEXACTI:    case OP_NOTEXACTI:
698      case OP_NOTPOSSTARI:
699      case OP_NOTPOSPLUSI:
700      case OP_NOTPOSQUERYI:
701    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
702    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
703  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
704    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
705  #endif  #endif
706    return cc;    return cc;
707    
708    case OP_NOTPROP:    /* Special cases. */
709    case OP_PROP:    case OP_TYPESTAR:
710    return cc + 1 + 2;    case OP_TYPEMINSTAR:
711      case OP_TYPEPLUS:
712      case OP_TYPEMINPLUS:
713      case OP_TYPEQUERY:
714      case OP_TYPEMINQUERY:
715    case OP_TYPEUPTO:    case OP_TYPEUPTO:
716    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
717    case OP_TYPEEXACT:    case OP_TYPEEXACT:
718      case OP_TYPEPOSSTAR:
719      case OP_TYPEPOSPLUS:
720      case OP_TYPEPOSQUERY:
721    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
722    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;  
723    
724    case OP_CRRANGE:    case OP_ANYBYTE:
725    case OP_CRMINRANGE:  #ifdef SUPPORT_UTF
726    return cc + 1 + 2 * IMM2_SIZE;    if (common->utf) return NULL;
727    #endif
728    case OP_CLASS:    return cc + 1;
   case OP_NCLASS:  
   return cc + 1 + 32 / sizeof(pcre_uchar);  
729    
730  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
731    case OP_XCLASS:    case OP_XCLASS:
732    return cc + GET(cc, 1);    return cc + GET(cc, 1);
733  #endif  #endif
734    
   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;  
   
735    case OP_MARK:    case OP_MARK:
736      case OP_PRUNE_ARG:
737      case OP_SKIP_ARG:
738      case OP_THEN_ARG:
739    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
740    
741    default:    default:
742      /* All opcodes are supported now! */
743      SLJIT_ASSERT_STOP();
744    return NULL;    return NULL;
745    }    }
746  }  }
747    
748  #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)  
749  {  {
750  switch(*cc)  int count;
751    {  pcre_uchar *slot;
   case OP_CRSTAR:  
   case OP_CRPLUS:  
   return 2;  
   
   case OP_CRMINSTAR:  
   case OP_CRMINPLUS:  
   case OP_CRQUERY:  
   case OP_CRMINQUERY:  
   return 1;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))  
     return 0;  
   return 2;  
   
   default:  
   return 0;  
   }  
 }  
   
 static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  
 {  
 int private_data_length = 0;  
 pcre_uchar *alternative;  
 pcre_uchar *name;  
 pcre_uchar *end = NULL;  
 int space, size, bracketlen, i;  
752    
753  /* 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. */
754  while (cc < ccend)  while (cc < ccend)
755    {    {
   space = 0;  
   size = 0;  
   bracketlen = 0;  
756    switch(*cc)    switch(*cc)
757      {      {
758      case OP_SET_SOM:      case OP_SET_SOM:
# Line 788  while (cc < ccend) Line 766  while (cc < ccend)
766      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
767      break;      break;
768    
     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;  
   
769      case OP_CBRAPOS:      case OP_CBRAPOS:
770      case OP_SCBRAPOS:      case OP_SCBRAPOS:
     private_data_length += sizeof(sljit_w);  
771      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
772      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
773      break;      break;
774    
775      case OP_COND:      case OP_COND:
776      case OP_SCOND:      case OP_SCOND:
777      bracketlen = cc[1 + LINK_SIZE];      /* Only AUTO_CALLOUT can insert this opcode. We do
778      if (bracketlen == OP_CREF)         not intend to support this case. */
779        if (cc[1 + LINK_SIZE] == OP_CALLOUT)
780          return FALSE;
781        cc += 1 + LINK_SIZE;
782        break;
783    
784        case OP_CREF:
785        common->optimized_cbracket[GET2(cc, 1)] = 0;
786        cc += 1 + IMM2_SIZE;
787        break;
788    
789        case OP_DNREF:
790        case OP_DNREFI:
791        case OP_DNCREF:
792        count = GET2(cc, 1 + IMM2_SIZE);
793        slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
794        while (count-- > 0)
795        {        {
796        bracketlen = GET2(cc, 1 + LINK_SIZE + 1);        common->optimized_cbracket[GET2(slot, 0)] = 0;
797        common->optimized_cbracket[bracketlen] = 0;        slot += common->name_entry_size;
798        }        }
799      else if (bracketlen == OP_NCREF)      cc += 1 + 2 * IMM2_SIZE;
800        {      break;
       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);  
801    
802        for (i = 0; i < common->name_count; i++)      case OP_RECURSE:
803          {      /* Set its value only once. */
804          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)      if (common->recursive_head_ptr == 0)
805            common->optimized_cbracket[GET2(alternative, 0)] = 0;        {
806          alternative += common->name_entry_size;        common->recursive_head_ptr = common->ovector_start;
807          }        common->ovector_start += sizeof(sljit_sw);
808        }        }
809        cc += 1 + LINK_SIZE;
810        break;
811    
812      if (*cc == OP_COND)      case OP_CALLOUT:
813        if (common->capture_last_ptr == 0)
814        {        {
815        /* Might be a hidden SCOND. */        common->capture_last_ptr = common->ovector_start;
816        alternative = cc + GET(cc, 1);        common->ovector_start += sizeof(sljit_sw);
       if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)  
         private_data_length += sizeof(sljit_w);  
817        }        }
818      else      cc += 2 + 2 * LINK_SIZE;
       private_data_length += sizeof(sljit_w);  
     bracketlen = 1 + LINK_SIZE;  
819      break;      break;
820    
821      case OP_BRA:      case OP_THEN_ARG:
822      bracketlen = 1 + LINK_SIZE;      common->has_then = TRUE;
823      break;      common->control_head_ptr = 1;
824        /* Fall through. */
825    
826      case OP_CBRA:      case OP_PRUNE_ARG:
827      case OP_SCBRA:      common->needs_start_ptr = TRUE;
828      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      /* Fall through. */
     break;  
829    
830      CASE_ITERATOR_PRIVATE_DATA_1      case OP_MARK:
831      space = 1;      if (common->mark_ptr == 0)
832      size = -2;        {
833          common->mark_ptr = common->ovector_start;
834          common->ovector_start += sizeof(sljit_sw);
835          }
836        cc += 1 + 2 + cc[1];
837      break;      break;
838    
839      CASE_ITERATOR_PRIVATE_DATA_2A      case OP_THEN:
840      space = 2;      common->has_then = TRUE;
841      size = -2;      common->control_head_ptr = 1;
842        /* Fall through. */
843    
844        case OP_PRUNE:
845        case OP_SKIP:
846        common->needs_start_ptr = TRUE;
847        cc += 1;
848      break;      break;
849    
850      CASE_ITERATOR_PRIVATE_DATA_2B      case OP_SKIP_ARG:
851      space = 2;      common->control_head_ptr = 1;
852      size = -(2 + IMM2_SIZE);      common->has_skip_arg = TRUE;
853        cc += 1 + 2 + cc[1];
854      break;      break;
855    
856      CASE_ITERATOR_TYPE_PRIVATE_DATA_1      default:
857      space = 1;      cc = next_opcode(common, cc);
858      size = 1;      if (cc == NULL)
859          return FALSE;
860      break;      break;
861        }
862      }
863    return TRUE;
864    }
865    
866      CASE_ITERATOR_TYPE_PRIVATE_DATA_2A  static int get_class_iterator_size(pcre_uchar *cc)
867      if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)  {
868        space = 2;  switch(*cc)
869      size = 1;    {
870      break;    case OP_CRSTAR:
871      case OP_CRPLUS:
872      return 2;
873    
874      CASE_ITERATOR_TYPE_PRIVATE_DATA_2B    case OP_CRMINSTAR:
875      if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)    case OP_CRMINPLUS:
876        space = 2;    case OP_CRQUERY:
877      size = 1 + IMM2_SIZE;    case OP_CRMINQUERY:
878      break;    return 1;
879    
880      case OP_CRRANGE:
881      case OP_CRMINRANGE:
882      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
883        return 0;
884      return 2;
885    
886      case OP_CLASS:    default:
887      case OP_NCLASS:    return 0;
888      size += 1 + 32 / sizeof(pcre_uchar);    }
889      space = get_class_iterator_size(cc + size);  }
     break;  
890    
891  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
892      case OP_XCLASS:  {
893      size = GET(cc, 1);  pcre_uchar *end = bracketend(begin);
894      space = get_class_iterator_size(cc + size);  pcre_uchar *next;
895      break;  pcre_uchar *next_end;
896  #endif  pcre_uchar *max_end;
897    pcre_uchar type;
898    sljit_sw length = end - begin;
899    int min, max, i;
900    
901      case OP_RECURSE:  /* Detect fixed iterations first. */
902      /* Set its value only once. */  if (end[-(1 + LINK_SIZE)] != OP_KET)
903      if (common->recursive_head == 0)    return FALSE;
       {  
       common->recursive_head = common->ovector_start;  
       common->ovector_start += sizeof(sljit_w);  
       }  
     cc += 1 + LINK_SIZE;  
     break;  
904    
905      case OP_MARK:  /* Already detected repeat. */
906      if (common->mark_ptr == 0)  if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
907        {    return TRUE;
       common->mark_ptr = common->ovector_start;  
       common->ovector_start += sizeof(sljit_w);  
       }  
     cc += 1 + 2 + cc[1];  
     break;  
908    
909      default:  next = end;
910      cc = next_opcode(common, cc);  min = 1;
911      if (cc == NULL)  while (1)
912        return -1;    {
913      if (*next != *begin)
914      break;      break;
915      }    next_end = bracketend(next);
916      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
917        break;
918      next = next_end;
919      min++;
920      }
921    
922    if (space > 0 && cc >= end)  if (min == 2)
923      private_data_length += sizeof(sljit_w) * space;    return FALSE;
924    
925    if (size != 0)  max = 0;
926    max_end = next;
927    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
928      {
929      type = *next;
930      while (1)
931      {      {
932      if (size < 0)      if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
933        {        break;
934        cc += -size;      next_end = bracketend(next + 2 + LINK_SIZE);
935  #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)
936        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        break;
937  #endif      next = next_end;
938        }      max++;
     else  
       cc += size;  
939      }      }
940    
941    if (bracketlen > 0)    if (next[0] == type && next[1] == *begin && max >= 1)
942      {      {
943      if (cc >= end)      next_end = bracketend(next + 1);
944        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
945        {        {
946        end = bracketend(cc);        for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
947        if (end[-1 - LINK_SIZE] == OP_KET)          if (*next_end != OP_KET)
948          end = NULL;            break;
949    
950          if (i == max)
951            {
952            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
953            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
954            /* +2 the original and the last. */
955            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
956            if (min == 1)
957              return TRUE;
958            min--;
959            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
960            }
961        }        }
     cc += bracketlen;  
962      }      }
963    }    }
964  return private_data_length;  
965    if (min >= 3)
966      {
967      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
968      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
969      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
970      return TRUE;
971      }
972    
973    return FALSE;
974  }  }
975    
976  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
977        case OP_MINSTAR: \
978        case OP_MINPLUS: \
979        case OP_QUERY: \
980        case OP_MINQUERY: \
981        case OP_MINSTARI: \
982        case OP_MINPLUSI: \
983        case OP_QUERYI: \
984        case OP_MINQUERYI: \
985        case OP_NOTMINSTAR: \
986        case OP_NOTMINPLUS: \
987        case OP_NOTQUERY: \
988        case OP_NOTMINQUERY: \
989        case OP_NOTMINSTARI: \
990        case OP_NOTMINPLUSI: \
991        case OP_NOTQUERYI: \
992        case OP_NOTMINQUERYI:
993    
994    #define CASE_ITERATOR_PRIVATE_DATA_2A \
995        case OP_STAR: \
996        case OP_PLUS: \
997        case OP_STARI: \
998        case OP_PLUSI: \
999        case OP_NOTSTAR: \
1000        case OP_NOTPLUS: \
1001        case OP_NOTSTARI: \
1002        case OP_NOTPLUSI:
1003    
1004    #define CASE_ITERATOR_PRIVATE_DATA_2B \
1005        case OP_UPTO: \
1006        case OP_MINUPTO: \
1007        case OP_UPTOI: \
1008        case OP_MINUPTOI: \
1009        case OP_NOTUPTO: \
1010        case OP_NOTMINUPTO: \
1011        case OP_NOTUPTOI: \
1012        case OP_NOTMINUPTOI:
1013    
1014    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1015        case OP_TYPEMINSTAR: \
1016        case OP_TYPEMINPLUS: \
1017        case OP_TYPEQUERY: \
1018        case OP_TYPEMINQUERY:
1019    
1020    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1021        case OP_TYPESTAR: \
1022        case OP_TYPEPLUS:
1023    
1024    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1025        case OP_TYPEUPTO: \
1026        case OP_TYPEMINUPTO:
1027    
1028    static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1029  {  {
1030  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1031  pcre_uchar *alternative;  pcre_uchar *alternative;
1032  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1033    int private_data_ptr = *private_data_start;
1034  int space, size, bracketlen;  int space, size, bracketlen;
1035    
1036  while (cc < ccend)  while (cc < ccend)
# Line 970  while (cc < ccend) Line 1038  while (cc < ccend)
1038    space = 0;    space = 0;
1039    size = 0;    size = 0;
1040    bracketlen = 0;    bracketlen = 0;
1041      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1042        return;
1043    
1044      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1045        if (detect_repeat(common, cc))
1046          {
1047          /* These brackets are converted to repeats, so no global
1048          based single character repeat is allowed. */
1049          if (cc >= end)
1050            end = bracketend(cc);
1051          }
1052    
1053    switch(*cc)    switch(*cc)
1054      {      {
1055        case OP_KET:
1056        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1057          {
1058          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1059          private_data_ptr += sizeof(sljit_sw);
1060          cc += common->private_data_ptrs[cc + 1 - common->start];
1061          }
1062        cc += 1 + LINK_SIZE;
1063        break;
1064    
1065      case OP_ASSERT:      case OP_ASSERT:
1066      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1067      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 983  while (cc < ccend) Line 1073  while (cc < ccend)
1073      case OP_SBRAPOS:      case OP_SBRAPOS:
1074      case OP_SCOND:      case OP_SCOND:
1075      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1076      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1077      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1078      break;      break;
1079    
1080      case OP_CBRAPOS:      case OP_CBRAPOS:
1081      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1082      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1083      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1084      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1085      break;      break;
1086    
# Line 1000  while (cc < ccend) Line 1090  while (cc < ccend)
1090      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1091        {        {
1092        common->private_data_ptrs[cc - common->start] = private_data_ptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1093        private_data_ptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1094        }        }
1095      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1096      break;      break;
# Line 1065  while (cc < ccend) Line 1155  while (cc < ccend)
1155      break;      break;
1156      }      }
1157    
1158      /* Character iterators, which are not inside a repeated bracket,
1159         gets a private slot instead of allocating it on the stack. */
1160    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1161      {      {
1162      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1163      private_data_ptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1164      }      }
1165    
1166    if (size != 0)    if (size != 0)
# Line 1076  while (cc < ccend) Line 1168  while (cc < ccend)
1168      if (size < 0)      if (size < 0)
1169        {        {
1170        cc += -size;        cc += -size;
1171  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1172        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1173  #endif  #endif
1174        }        }
# Line 1095  while (cc < ccend) Line 1187  while (cc < ccend)
1187      cc += bracketlen;      cc += bracketlen;
1188      }      }
1189    }    }
1190    *private_data_start = private_data_ptr;
1191  }  }
1192    
1193  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1194  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)
1195  {  {
 pcre_uchar *ccend = bracketend(cc);  
1196  int length = 0;  int length = 0;
1197  BOOL possessive = FALSE;  int possessive = 0;
1198    BOOL stack_restore = FALSE;
1199  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1200  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1201    /* The last capture is a local variable even for recursions. */
1202    BOOL capture_last_found = FALSE;
1203    
1204    #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1205    SLJIT_ASSERT(common->control_head_ptr != 0);
1206    *needs_control_head = TRUE;
1207    #else
1208    *needs_control_head = FALSE;
1209    #endif
1210    
1211  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (ccend == NULL)
1212    {    {
1213    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1214    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1215        {
1216        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1217        /* This is correct regardless of common->capture_last_ptr. */
1218        capture_last_found = TRUE;
1219        }
1220      cc = next_opcode(common, cc);
1221    }    }
1222    
 cc = next_opcode(common, cc);  
1223  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1224  while (cc < ccend)  while (cc < ccend)
1225    switch(*cc)    switch(*cc)
1226      {      {
1227      case OP_SET_SOM:      case OP_SET_SOM:
1228      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1229        stack_restore = TRUE;
1230      if (!setsom_found)      if (!setsom_found)
1231        {        {
1232        length += 2;        length += 2;
# Line 1128  while (cc < ccend) Line 1236  while (cc < ccend)
1236      break;      break;
1237    
1238      case OP_MARK:      case OP_MARK:
1239        case OP_PRUNE_ARG:
1240        case OP_THEN_ARG:
1241      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1242        stack_restore = TRUE;
1243      if (!setmark_found)      if (!setmark_found)
1244        {        {
1245        length += 2;        length += 2;
1246        setmark_found = TRUE;        setmark_found = TRUE;
1247        }        }
1248        if (common->control_head_ptr != 0)
1249          *needs_control_head = TRUE;
1250      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1251      break;      break;
1252    
1253      case OP_RECURSE:      case OP_RECURSE:
1254        stack_restore = TRUE;
1255      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1256        {        {
1257        length += 2;        length += 2;
# Line 1148  while (cc < ccend) Line 1262  while (cc < ccend)
1262        length += 2;        length += 2;
1263        setmark_found = TRUE;        setmark_found = TRUE;
1264        }        }
1265        if (common->capture_last_ptr != 0 && !capture_last_found)
1266          {
1267          length += 2;
1268          capture_last_found = TRUE;
1269          }
1270      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1271      break;      break;
1272    
# Line 1155  while (cc < ccend) Line 1274  while (cc < ccend)
1274      case OP_CBRAPOS:      case OP_CBRAPOS:
1275      case OP_SCBRA:      case OP_SCBRA:
1276      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1277        stack_restore = TRUE;
1278        if (common->capture_last_ptr != 0 && !capture_last_found)
1279          {
1280          length += 2;
1281          capture_last_found = TRUE;
1282          }
1283      length += 3;      length += 3;
1284      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1285      break;      break;
1286    
1287      default:      default:
1288        stack_restore = TRUE;
1289        /* Fall through. */
1290    
1291        case OP_NOT_WORD_BOUNDARY:
1292        case OP_WORD_BOUNDARY:
1293        case OP_NOT_DIGIT:
1294        case OP_DIGIT:
1295        case OP_NOT_WHITESPACE:
1296        case OP_WHITESPACE:
1297        case OP_NOT_WORDCHAR:
1298        case OP_WORDCHAR:
1299        case OP_ANY:
1300        case OP_ALLANY:
1301        case OP_ANYBYTE:
1302        case OP_NOTPROP:
1303        case OP_PROP:
1304        case OP_ANYNL:
1305        case OP_NOT_HSPACE:
1306        case OP_HSPACE:
1307        case OP_NOT_VSPACE:
1308        case OP_VSPACE:
1309        case OP_EXTUNI:
1310        case OP_EODN:
1311        case OP_EOD:
1312        case OP_CIRC:
1313        case OP_CIRCM:
1314        case OP_DOLL:
1315        case OP_DOLLM:
1316        case OP_CHAR:
1317        case OP_CHARI:
1318        case OP_NOT:
1319        case OP_NOTI:
1320    
1321        case OP_EXACT:
1322        case OP_POSSTAR:
1323        case OP_POSPLUS:
1324        case OP_POSQUERY:
1325        case OP_POSUPTO:
1326    
1327        case OP_EXACTI:
1328        case OP_POSSTARI:
1329        case OP_POSPLUSI:
1330        case OP_POSQUERYI:
1331        case OP_POSUPTOI:
1332    
1333        case OP_NOTEXACT:
1334        case OP_NOTPOSSTAR:
1335        case OP_NOTPOSPLUS:
1336        case OP_NOTPOSQUERY:
1337        case OP_NOTPOSUPTO:
1338    
1339        case OP_NOTEXACTI:
1340        case OP_NOTPOSSTARI:
1341        case OP_NOTPOSPLUSI:
1342        case OP_NOTPOSQUERYI:
1343        case OP_NOTPOSUPTOI:
1344    
1345        case OP_TYPEEXACT:
1346        case OP_TYPEPOSSTAR:
1347        case OP_TYPEPOSPLUS:
1348        case OP_TYPEPOSQUERY:
1349        case OP_TYPEPOSUPTO:
1350    
1351        case OP_CLASS:
1352        case OP_NCLASS:
1353        case OP_XCLASS:
1354    
1355      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1356      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1357      break;      break;
1358      }      }
1359    
1360  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1361  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1362    return -1;    return stack_restore ? no_frame : no_stack;
1363    
1364  if (length > 0)  if (length > 0)
1365    return length + 1;    return length + 1;
1366  return -1;  return stack_restore ? no_frame : no_stack;
1367  }  }
1368    
1369  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)
1370  {  {
1371  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1372  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1373  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1374    /* The last capture is a local variable even for recursions. */
1375    BOOL capture_last_found = FALSE;
1376  int offset;  int offset;
1377    
1378  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1187  SLJIT_UNUSED_ARG(stacktop); Line 1380  SLJIT_UNUSED_ARG(stacktop);
1380  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1381    
1382  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1383  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1384    cc = next_opcode(common, cc);    {
1385      ccend = bracketend(cc) - (1 + LINK_SIZE);
1386      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1387        cc = next_opcode(common, cc);
1388      }
1389    
1390  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1391  while (cc < ccend)  while (cc < ccend)
1392    switch(*cc)    switch(*cc)
# Line 1198  while (cc < ccend) Line 1396  while (cc < ccend)
1396      if (!setsom_found)      if (!setsom_found)
1397        {        {
1398        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1399        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1400        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1401        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1402        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1403        setsom_found = TRUE;        setsom_found = TRUE;
1404        }        }
1405      cc += 1;      cc += 1;
1406      break;      break;
1407    
1408      case OP_MARK:      case OP_MARK:
1409        case OP_PRUNE_ARG:
1410        case OP_THEN_ARG:
1411      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1412      if (!setmark_found)      if (!setmark_found)
1413        {        {
1414        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);
1415        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);
1416        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1417        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1418        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1419        setmark_found = TRUE;        setmark_found = TRUE;
1420        }        }
1421      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 1225  while (cc < ccend) Line 1425  while (cc < ccend)
1425      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1426        {        {
1427        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1428        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1429        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1430        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1431        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1432        setsom_found = TRUE;        setsom_found = TRUE;
1433        }        }
1434      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1435        {        {
1436        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);
1437        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);
1438        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1439        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1440        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1441        setmark_found = TRUE;        setmark_found = TRUE;
1442        }        }
1443        if (common->capture_last_ptr != 0 && !capture_last_found)
1444          {
1445          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1446          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1447          stackpos += (int)sizeof(sljit_sw);
1448          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1449          stackpos += (int)sizeof(sljit_sw);
1450          capture_last_found = TRUE;
1451          }
1452      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1453      break;      break;
1454    
# Line 1247  while (cc < ccend) Line 1456  while (cc < ccend)
1456      case OP_CBRAPOS:      case OP_CBRAPOS:
1457      case OP_SCBRA:      case OP_SCBRA:
1458      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1459        if (common->capture_last_ptr != 0 && !capture_last_found)
1460          {
1461          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1462          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1463          stackpos += (int)sizeof(sljit_sw);
1464          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1465          stackpos += (int)sizeof(sljit_sw);
1466          capture_last_found = TRUE;
1467          }
1468      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1469      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1470      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1471      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1472      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));
1473      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1474      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1475      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1476      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1477    
1478      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1479      break;      break;
# Line 1266  while (cc < ccend) Line 1484  while (cc < ccend)
1484      break;      break;
1485      }      }
1486    
1487  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1488  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1489  }  }
1490    
1491  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)
1492  {  {
1493  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1494  int size;  int size;
1495  pcre_uchar *alternative;  pcre_uchar *alternative;
1496  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1281  while (cc < ccend) Line 1499  while (cc < ccend)
1499    size = 0;    size = 0;
1500    switch(*cc)    switch(*cc)
1501      {      {
1502        case OP_KET:
1503        if (PRIVATE_DATA(cc) != 0)
1504          private_data_length++;
1505        cc += 1 + LINK_SIZE;
1506        break;
1507    
1508      case OP_ASSERT:      case OP_ASSERT:
1509      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1510      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1320  while (cc < ccend) Line 1544  while (cc < ccend)
1544      if (PRIVATE_DATA(cc))      if (PRIVATE_DATA(cc))
1545        private_data_length++;        private_data_length++;
1546      cc += 2;      cc += 2;
1547  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1548      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1549  #endif  #endif
1550      break;      break;
# Line 1329  while (cc < ccend) Line 1553  while (cc < ccend)
1553      if (PRIVATE_DATA(cc))      if (PRIVATE_DATA(cc))
1554        private_data_length += 2;        private_data_length += 2;
1555      cc += 2;      cc += 2;
1556  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1557      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1558  #endif  #endif
1559      break;      break;
# Line 1338  while (cc < ccend) Line 1562  while (cc < ccend)
1562      if (PRIVATE_DATA(cc))      if (PRIVATE_DATA(cc))
1563        private_data_length += 2;        private_data_length += 2;
1564      cc += 2 + IMM2_SIZE;      cc += 2 + IMM2_SIZE;
1565  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1566      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1567  #endif  #endif
1568      break;      break;
# Line 1385  return private_data_length; Line 1609  return private_data_length;
1609  }  }
1610    
1611  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,
1612    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1613  {  {
1614  DEFINE_COMPILER;  DEFINE_COMPILER;
1615  int srcw[2];  int srcw[2];
# Line 1406  stacktop = STACK(stacktop - 1); Line 1630  stacktop = STACK(stacktop - 1);
1630    
1631  if (!save)  if (!save)
1632    {    {
1633    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1634    if (stackptr < stacktop)    if (stackptr < stacktop)
1635      {      {
1636      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1637      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1638      tmp1empty = FALSE;      tmp1empty = FALSE;
1639      }      }
1640    if (stackptr < stacktop)    if (stackptr < stacktop)
1641      {      {
1642      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1643      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1644      tmp2empty = FALSE;      tmp2empty = FALSE;
1645      }      }
1646    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1647    }    }
1648    
1649  while (status != end)  do
1650    {    {
1651    count = 0;    count = 0;
1652    switch(status)    switch(status)
1653      {      {
1654      case start:      case start:
1655      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1656      count = 1;      count = 1;
1657      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1658        if (needs_control_head)
1659          {
1660          SLJIT_ASSERT(common->control_head_ptr != 0);
1661          count = 2;
1662          srcw[1] = common->control_head_ptr;
1663          }
1664      status = loop;      status = loop;
1665      break;      break;
1666    
# Line 1443  while (status != end) Line 1673  while (status != end)
1673    
1674      switch(*cc)      switch(*cc)
1675        {        {
1676          case OP_KET:
1677          if (PRIVATE_DATA(cc) != 0)
1678            {
1679            count = 1;
1680            srcw[0] = PRIVATE_DATA(cc);
1681            }
1682          cc += 1 + LINK_SIZE;
1683          break;
1684    
1685        case OP_ASSERT:        case OP_ASSERT:
1686        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1687        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1497  while (status != end) Line 1736  while (status != end)
1736          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1737          }          }
1738        cc += 2;        cc += 2;
1739  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1740        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1741  #endif  #endif
1742        break;        break;
# Line 1507  while (status != end) Line 1746  while (status != end)
1746          {          {
1747          count = 2;          count = 2;
1748          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1749          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1750          }          }
1751        cc += 2;        cc += 2;
1752  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1753        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1754  #endif  #endif
1755        break;        break;
# Line 1520  while (status != end) Line 1759  while (status != end)
1759          {          {
1760          count = 2;          count = 2;
1761          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1762          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1763          }          }
1764        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1765  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1766        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1767  #endif  #endif
1768        break;        break;
# Line 1542  while (status != end) Line 1781  while (status != end)
1781          {          {
1782          count = 2;          count = 2;
1783          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1784          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1785          }          }
1786        cc += 1;        cc += 1;
1787        break;        break;
# Line 1552  while (status != end) Line 1791  while (status != end)
1791          {          {
1792          count = 2;          count = 2;
1793          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1794          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1795          }          }
1796        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1797        break;        break;
# Line 1576  while (status != end) Line 1815  while (status != end)
1815            case 2:            case 2:
1816            count = 2;            count = 2;
1817            srcw[0] = PRIVATE_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1818            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1819            break;            break;
1820    
1821            default:            default:
# Line 1608  while (status != end) Line 1847  while (status != end)
1847          if (!tmp1empty)          if (!tmp1empty)
1848            {            {
1849            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1850            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1851            }            }
1852          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1853          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1619  while (status != end) Line 1858  while (status != end)
1858          if (!tmp2empty)          if (!tmp2empty)
1859            {            {
1860            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1861            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1862            }            }
1863          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1864          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1636  while (status != end) Line 1875  while (status != end)
1875          if (!tmp1empty)          if (!tmp1empty)
1876            {            {
1877            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1878            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1879            }            }
1880          tmp1next = FALSE;          tmp1next = FALSE;
1881          }          }
# Line 1648  while (status != end) Line 1887  while (status != end)
1887          if (!tmp2empty)          if (!tmp2empty)
1888            {            {
1889            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1890            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1891            }            }
1892          tmp1next = TRUE;          tmp1next = TRUE;
1893          }          }
1894        }        }
1895      }      }
1896    }    }
1897    while (status != end);
1898    
1899  if (save)  if (save)
1900    {    {
# Line 1663  if (save) Line 1903  if (save)
1903      if (!tmp1empty)      if (!tmp1empty)
1904        {        {
1905        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1906        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1907        }        }
1908      if (!tmp2empty)      if (!tmp2empty)
1909        {        {
1910        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1911        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1912        }        }
1913      }      }
1914    else    else
# Line 1676  if (save) Line 1916  if (save)
1916      if (!tmp2empty)      if (!tmp2empty)
1917        {        {
1918        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1919        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1920        }        }
1921      if (!tmp1empty)      if (!tmp1empty)
1922        {        {
1923        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1924        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1925        }        }
1926      }      }
1927    }    }
1928  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1929  }  }
1930    
1931    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1932    {
1933    pcre_uchar *end = bracketend(cc);
1934    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1935    
1936    /* Assert captures then. */
1937    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1938      current_offset = NULL;
1939    /* Conditional block does not. */
1940    if (*cc == OP_COND || *cc == OP_SCOND)
1941      has_alternatives = FALSE;
1942    
1943    cc = next_opcode(common, cc);
1944    if (has_alternatives)
1945      current_offset = common->then_offsets + (cc - common->start);
1946    
1947    while (cc < end)
1948      {
1949      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1950        cc = set_then_offsets(common, cc, current_offset);
1951      else
1952        {
1953        if (*cc == OP_ALT && has_alternatives)
1954          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1955        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1956          *current_offset = 1;
1957        cc = next_opcode(common, cc);
1958        }
1959      }
1960    
1961    return end;
1962    }
1963    
1964  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
1965  #undef CASE_ITERATOR_PRIVATE_DATA_2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
1966  #undef CASE_ITERATOR_PRIVATE_DATA_2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
# Line 1706  while (list) Line 1979  while (list)
1979    {    {
1980    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
1981    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
1982    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
1983    list = list->next;    list = list->next;
1984    }    }
1985  }  }
# Line 1722  if (list_item) Line 1995  if (list_item)
1995    }    }
1996  }  }
1997    
1998  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)
1999  {  {
2000  DEFINE_COMPILER;  DEFINE_COMPILER;
2001  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
2002    
2003  if (list_item)  if (list_item)
2004    {    {
   list_item->type = type;  
   list_item->data = data;  
2005    list_item->start = start;    list_item->start = start;
2006    list_item->quit = LABEL();    list_item->quit = LABEL();
2007    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1746  stub_list* list_item = common->stubs; Line 2017  stub_list* list_item = common->stubs;
2017  while (list_item)  while (list_item)
2018    {    {
2019    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2020    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;  
     }  
2021    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2022    list_item = list_item->next;    list_item = list_item->next;
2023    }    }
2024  common->stubs = NULL;  common->stubs = NULL;
2025  }  }
2026    
2027  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2028  {  {
2029  DEFINE_COMPILER;  DEFINE_COMPILER;
2030    
2031  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);
2032  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2033  }  }
2034    
# Line 1771  static SLJIT_INLINE void allocate_stack( Line 2037  static SLJIT_INLINE void allocate_stack(
2037  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2038  DEFINE_COMPILER;  DEFINE_COMPILER;
2039    
2040  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));
2041  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2042  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2043  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 2045  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2045  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2046  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2047  #endif  #endif
2048  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));
2049  }  }
2050    
2051  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
2052  {  {
2053  DEFINE_COMPILER;  DEFINE_COMPILER;
2054  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));
2055  }  }
2056    
2057  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 2059  static SLJIT_INLINE void reset_ovector(c
2059  DEFINE_COMPILER;  DEFINE_COMPILER;
2060  struct sljit_label *loop;  struct sljit_label *loop;
2061  int i;  int i;
2062    
2063  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2064    SLJIT_ASSERT(length > 1);
2065  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2066  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));
2067    if (length < 8)
2068      {
2069      for (i = 1; i < length; i++)
2070        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2071      }
2072    else
2073      {
2074      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2075      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2076      loop = LABEL();
2077      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2078      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2079      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2080      }
2081    }
2082    
2083    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2084    {
2085    DEFINE_COMPILER;
2086    struct sljit_label *loop;
2087    int i;
2088    
2089    SLJIT_ASSERT(length > 1);
2090    /* OVECTOR(1) contains the "string begin - 1" constant. */
2091    if (length > 2)
2092      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2093  if (length < 8)  if (length < 8)
2094    {    {
2095    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
2096      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);
2097    }    }
2098  else  else
2099    {    {
2100    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_w));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2101    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2102    loop = LABEL();    loop = LABEL();
2103    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);
2104    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);
2105    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2106    }    }
2107    
2108    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2109    if (common->mark_ptr != 0)
2110      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2111    if (common->control_head_ptr != 0)
2112      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2113    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2114    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2115    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2116    }
2117    
2118    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2119    {
2120    while (current != NULL)
2121      {
2122      switch (current[-2])
2123        {
2124        case type_then_trap:
2125        break;
2126    
2127        case type_mark:
2128        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2129          return current[-4];
2130        break;
2131    
2132        default:
2133        SLJIT_ASSERT_STOP();
2134        break;
2135        }
2136      current = (sljit_sw*)current[-1];
2137      }
2138    return -1;
2139  }  }
2140    
2141  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2142  {  {
2143  DEFINE_COMPILER;  DEFINE_COMPILER;
2144  struct sljit_label *loop;  struct sljit_label *loop;
2145  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2146    
2147  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2148  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));
2149  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);
2150    
2151  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2152  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2153    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);
2154  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));
2155  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2156    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);
2157  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));
2158  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));
2159  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2160  /* Unlikely, but possible */  /* Unlikely, but possible */
2161  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);
2162  loop = LABEL();  loop = LABEL();
2163  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);
2164  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));
2165  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2166  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2167  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);
2168  #endif  #endif
2169  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);
2170  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);
2171  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2172  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2173    
2174  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2175  if (topbracket > 1)  if (topbracket > 1)
2176    {    {
2177    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));
2178    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2179    
2180    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2181    loop = LABEL();    loop = LABEL();
2182    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)));
2183    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);
2184    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);
2185    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2186    }    }
2187  else  else
2188    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1865  else Line 2191  else
2191  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)
2192  {  {
2193  DEFINE_COMPILER;  DEFINE_COMPILER;
2194    struct sljit_jump *jump;
2195    
2196  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);
2197  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
2198      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2199    
2200  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2201  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2202  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));
2203  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);
2204    
2205  /* Store match begin and end. */  /* Store match begin and end. */
2206  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));
2207  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));
2208  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);  
2209    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2210    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);
2211    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2212    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2213    #endif
2214    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2215    JUMPHERE(jump);
2216    
2217    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);
2218  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);
2219  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2220  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);
2221  #endif  #endif
2222  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);
2223    
2224  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);
2225  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2226  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);
2227  #endif  #endif
2228  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);
2229    
2230  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2231  }  }
# Line 2038  return (bit < 256) ? ((0 << 8) | bit) : Line 2375  return (bit < 256) ? ((0 << 8) | bit) :
2375    
2376  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2377  {  {
2378  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2379  DEFINE_COMPILER;  DEFINE_COMPILER;
2380  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2381    
# Line 2053  else if (common->mode == JIT_PARTIAL_SOF Line 2390  else if (common->mode == JIT_PARTIAL_SOF
2390    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);
2391    
2392  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2393    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);
2394  else  else
2395    {    {
2396    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2066  if (jump != NULL) Line 2403  if (jump != NULL)
2403    JUMPHERE(jump);    JUMPHERE(jump);
2404  }  }
2405    
2406  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2407  {  {
2408  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2409  DEFINE_COMPILER;  DEFINE_COMPILER;
2410  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2411    
2412  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2413    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2414      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2415      return;
2416      }
2417    
2418  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2419  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2420    {    {
2421    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));
2422    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);
2423    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2424    }    }
2425  else  else
2426    {    {
2427    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));
2428    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2429      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2430    else    else
2431      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2432    }    }
2433  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2434  }  }
2435    
2436  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 2449  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2449  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));
2450  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2451    {    {
2452    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);
2453    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2454    }    }
2455  else  else
# Line 2176  if (common->utf) Line 2512  if (common->utf)
2512  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2513  }  }
2514    
2515    static void read_char8(compiler_common *common)
2516    {
2517    /* Reads the precise value of a character into TMP1, if the character is
2518    less than 256. Otherwise it returns with a value greater or equal than 256. */
2519    DEFINE_COMPILER;
2520    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2521    struct sljit_jump *jump;
2522    #endif
2523    
2524    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2525    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2526    
2527    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2528    if (common->utf)
2529      {
2530    #if defined COMPILE_PCRE8
2531      jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2532      add_jump(compiler, &common->utfreadchar8, JUMP(SLJIT_FAST_CALL));
2533      JUMPHERE(jump);
2534    #elif defined COMPILE_PCRE16
2535      /* Skip low surrogate if necessary. */
2536      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2537      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2538      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2539      JUMPHERE(jump);
2540    #endif /* COMPILE_PCRE[8|16] */
2541      }
2542    #endif
2543    }
2544    
2545  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common)
2546  {  {
2547  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */  /* Reads the character type into TMP1, updates STR_PTR. Does not check STR_END. */
# Line 2202  if (common->utf) Line 2568  if (common->utf)
2568    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2569    JUMPHERE(jump);    JUMPHERE(jump);
2570    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2571    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2572    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2573    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2574    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    JUMPHERE(jump);
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  
2575  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
2576    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2577    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
# Line 2254  if (common->utf) Line 2619  if (common->utf)
2619    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2620    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2621    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);
2622    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2623    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2624    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2625    return;    return;
# Line 2277  if (nltype == NLTYPE_ANY) Line 2642  if (nltype == NLTYPE_ANY)
2642  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2643    {    {
2644    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);
2645    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2646    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);
2647    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);
2648    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));
2649    }    }
2650  else  else
# Line 2350  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC Line 2715  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UC
2715  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2716  }  }
2717    
2718    static void do_utfreadchar8(compiler_common *common)
2719    {
2720    /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2721    of the character (>= 0xc0). Return value in TMP1. */
2722    DEFINE_COMPILER;
2723    struct sljit_jump *jump;
2724    
2725    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2726    
2727    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);
2728    jump = JUMP(SLJIT_C_NOT_ZERO);
2729    /* Two byte sequence. */
2730    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2731    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2732    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);
2733    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2734    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2735    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2736    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2737    
2738    JUMPHERE(jump);
2739    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2740    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x800);
2741    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2742    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2743    }
2744    
2745  static void do_utfreadtype8(compiler_common *common)  static void do_utfreadtype8(compiler_common *common)
2746  {  {
2747  /* Fast decoding a UTF-8 character type. TMP2 contains the first byte  /* Fast decoding a UTF-8 character type. TMP2 contains the first byte
# Line 2366  jump = JUMP(SLJIT_C_NOT_ZERO); Line 2758  jump = JUMP(SLJIT_C_NOT_ZERO);
2758  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2759  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));
2760  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
2761    /* The upper 5 bits are known at this point. */
2762    compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x3);
2763  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2764  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2765  OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);  OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
 compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  
2766  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2767  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2768    
2769  JUMPHERE(compare);  JUMPHERE(compare);
2770  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2771  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2772    
2773  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
2774  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(utf8_table4) - 0xc0);  JUMPHERE(jump);
2775  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2776  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2777    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2778  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2779  }  }
2780    
# Line 2432  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 2825  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
2825    
2826  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2827  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2828  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));
2829  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
2830  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
2831  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
2832  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
2833  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
2834  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));
2835  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
2836  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2837  }  }
# Line 2452  struct sljit_label *newlinelabel = NULL; Line 2845  struct sljit_label *newlinelabel = NULL;
2845  struct sljit_jump *start;  struct sljit_jump *start;
2846  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
2847  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
2848  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2849  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
2850  #endif  #endif
2851  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 2507  if (newlinecheck) Line 2900  if (newlinecheck)
2900    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2901    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2902    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);
2903    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2904  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2905    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
2906  #endif  #endif
# Line 2535  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S Line 2928  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S
2928  if (common->utf)  if (common->utf)
2929    {    {
2930    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2931    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);
2932    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2933    JUMPHERE(singlechar);    JUMPHERE(singlechar);
2934    }    }
# Line 2545  if (common->utf) Line 2938  if (common->utf)
2938    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
2939    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2940    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);
2941    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2942    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2943    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2944    JUMPHERE(singlechar);    JUMPHERE(singlechar);
# Line 2563  if (newlinecheck) Line 2956  if (newlinecheck)
2956  return mainloop;  return mainloop;
2957  }  }
2958    
2959  #define MAX_N_CHARS 3  static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, int max_chars)
   
 static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)  
2960  {  {
2961  DEFINE_COMPILER;  /* Recursive function, which scans prefix literals. */
2962  struct sljit_label *start;  int len, repeat, len_save, consumed = 0;
2963  struct sljit_jump *quit;  pcre_int32 caseless, chr, mask;
2964  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uchar *alternative, *cc_save;
2965  pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  BOOL last, any;
 int location = 0;  
 pcre_int32 len, c, bit, caseless;  
 int must_stop;  
   
 /* We do not support alternatives now. */  
 if (*(common->start + GET(common->start, 1)) == OP_ALT)  
   return FALSE;  
2966    
2967    repeat = 1;
2968  while (TRUE)  while (TRUE)
2969    {    {
2970      last = TRUE;
2971      any = FALSE;
2972    caseless = 0;    caseless = 0;
2973    must_stop = 1;    switch (*cc)
   switch(*cc)  
2974      {      {
     case OP_CHAR:  
     must_stop = 0;  
     cc++;  
     break;  
   
2975      case OP_CHARI:      case OP_CHARI:
2976      caseless = 1;      caseless = 1;
2977      must_stop = 0;      case OP_CHAR:
2978        last = FALSE;
2979      cc++;      cc++;
2980      break;      break;
2981    
# Line 2618  while (TRUE) Line 3000  while (TRUE)
3000      cc++;      cc++;
3001      break;      break;
3002    
3003        case OP_EXACTI:
3004        caseless = 1;
3005      case OP_EXACT:      case OP_EXACT:
3006        repeat = GET2(cc, 1);
3007        last = FALSE;
3008      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
3009      break;      break;
3010    
# Line 2629  while (TRUE) Line 3015  while (TRUE)
3015      cc++;      cc++;
3016      break;      break;
3017    
3018      case OP_EXACTI:      case OP_KET:
3019      caseless = 1;      cc += 1 + LINK_SIZE;
3020      cc += 1 + IMM2_SIZE;      continue;
3021    
3022        case OP_ALT:
3023        cc += GET(cc, 1);
3024        continue;
3025    
3026        case OP_ONCE:
3027        case OP_ONCE_NC:
3028        case OP_BRA:
3029        case OP_BRAPOS:
3030        case OP_CBRA:
3031        case OP_CBRAPOS:
3032        alternative = cc + GET(cc, 1);
3033        while (*alternative == OP_ALT)
3034          {
3035          max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, max_chars);
3036          if (max_chars == 0)
3037            return consumed;
3038          alternative += GET(alternative, 1);
3039          }
3040    
3041        if (*cc == OP_CBRA || *cc == OP_CBRAPOS)
3042          cc += IMM2_SIZE;
3043        cc += 1 + LINK_SIZE;
3044        continue;
3045    
3046        case OP_CLASS:
3047        case OP_NCLASS:
3048        any = TRUE;
3049        cc += 1 + 32 / sizeof(pcre_uchar);
3050      break;      break;
3051    
3052      default:  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3053      must_stop = 2;      case OP_XCLASS:
3054        any = TRUE;
3055        cc += GET(cc, 1);
3056        break;
3057    #endif
3058    
3059        case OP_NOT_DIGIT:
3060        case OP_DIGIT:
3061        case OP_NOT_WHITESPACE:
3062        case OP_WHITESPACE:
3063        case OP_NOT_WORDCHAR:
3064        case OP_WORDCHAR:
3065        case OP_ANY:
3066        case OP_ALLANY:
3067        any = TRUE;
3068        cc++;
3069        break;
3070    
3071    #ifdef SUPPORT_UCP
3072        case OP_NOTPROP:
3073        case OP_PROP:
3074        any = TRUE;
3075        cc += 1 + 2;
3076      break;      break;
3077    #endif
3078    
3079        case OP_TYPEEXACT:
3080        repeat = GET2(cc, 1);
3081        cc += 1 + IMM2_SIZE;
3082        continue;
3083    
3084        default:
3085        return consumed;
3086      }      }
3087    
3088    if (must_stop == 2)    if (any)
3089        break;      {
3090    #ifdef SUPPORT_UTF
3091        if (common->utf) return consumed;
3092    #endif
3093    #if defined COMPILE_PCRE8
3094        mask = 0xff;
3095    #elif defined COMPILE_PCRE16
3096        mask = 0xffff;
3097    #elif defined COMPILE_PCRE32
3098        mask = 0xffffffff;
3099    #else
3100        SLJIT_ASSERT_STOP();
3101    #endif
3102    
3103        do
3104          {
3105          chars[0] = mask;
3106          chars[1] = mask;
3107    
3108          if (--max_chars == 0)
3109            return consumed;
3110          consumed++;
3111          chars += 2;
3112          }
3113        while (--repeat > 0);
3114    
3115        repeat = 1;
3116        continue;
3117        }
3118    
3119    len = 1;    len = 1;
3120  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
3121    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3122    #endif
3123    
3124      if (caseless != 0 && char_has_othercase(common, cc))
3125        {
3126        caseless = char_get_othercase_bit(common, cc);
3127        if (caseless == 0)
3128          return consumed;
3129    #ifdef COMPILE_PCRE8
3130        caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
3131    #else
3132        if ((caseless & 0x100) != 0)
3133          caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));
3134        else
3135          caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));
3136    #endif
3137        }
3138      else
3139        caseless = 0;
3140    
3141      len_save = len;
3142      cc_save = cc;
3143      while (TRUE)
3144        {
3145        do
3146          {
3147          chr = *cc;
3148    #ifdef COMPILE_PCRE32
3149          if (SLJIT_UNLIKELY(chr == NOTACHAR))
3150            return consumed;
3151  #endif  #endif
3152          mask = 0;
3153          if (len == (caseless & 0xff))
3154            {
3155            mask = caseless >> 8;
3156            chr |= mask;
3157            }
3158    
3159          if (chars[0] == NOTACHAR)
3160            {
3161            chars[0] = chr;
3162            chars[1] = mask;
3163            }
3164          else
3165            {
3166            mask |= chars[0] ^ chr;
3167            chr |= mask;
3168            chars[0] = chr;
3169            chars[1] |= mask;
3170            }
3171    
3172          len--;
3173          if (--max_chars == 0)
3174            return consumed;
3175          consumed++;
3176          chars += 2;
3177          cc++;
3178          }
3179        while (len > 0);
3180    
3181        if (--repeat == 0)
3182          break;
3183    
3184        len = len_save;
3185        cc = cc_save;
3186        }
3187    
3188      repeat = 1;
3189      if (last)
3190        return consumed;
3191      }
3192    }
3193    
3194    #define MAX_N_CHARS 16
3195    
3196    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3197    {
3198    DEFINE_COMPILER;
3199    struct sljit_label *start;
3200    struct sljit_jump *quit;
3201    pcre_uint32 chars[MAX_N_CHARS * 2];
3202    pcre_uint8 ones[MAX_N_CHARS];
3203    pcre_uint32 mask;
3204    int i, max;
3205    int offsets[3];
3206    
3207    for (i = 0; i < MAX_N_CHARS; i++)
3208      {
3209      chars[i << 1] = NOTACHAR;
3210      chars[(i << 1) + 1] = 0;
3211      }
3212    
3213    max = scan_prefix(common, common->start, chars, MAX_N_CHARS);
3214    
3215    if (max <= 1)
3216      return FALSE;
3217    
3218    if (caseless && char_has_othercase(common, cc))  for (i = 0; i < max; i++)
3219      {
3220      mask = chars[(i << 1) + 1];
3221      ones[i] = ones_in_half_byte[mask & 0xf];
3222      mask >>= 4;
3223      while (mask != 0)
3224      {      {
3225      caseless = char_get_othercase_bit(common, cc);      ones[i] += ones_in_half_byte[mask & 0xf];
3226      if (caseless == 0)      mask >>= 4;
       return FALSE;  
 #ifdef COMPILE_PCRE8  
     caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));  
 #else  
     if ((caseless & 0x100) != 0)  
       caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));  
     else  
       caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));  
 #endif  
3227      }      }
3228    else    }
     caseless = 0;  
3229    
3230    while (len > 0 && location < MAX_N_CHARS * 2)  offsets[0] = -1;
3231      {  /* Scan forward. */
3232      c = *cc;  for (i = 0; i < max; i++)
3233      bit = 0;    if (ones[i] <= 2) {
3234      if (len == (caseless & 0xff))      offsets[0] = i;
3235        break;
3236      }
3237    
3238    if (offsets[0] == -1)
3239      return FALSE;
3240    
3241    /* Scan backward. */
3242    offsets[1] = -1;
3243    for (i = max - 1; i > offsets[0]; i--)
3244      if (ones[i] <= 2) {
3245        offsets[1] = i;
3246        break;
3247      }
3248    
3249    offsets[2] = -1;
3250    if (offsets[1] >= 0)
3251      {
3252      /* Scan from middle. */
3253      for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3254        if (ones[i] <= 2)
3255        {        {
3256        bit = caseless >> 8;        offsets[2] = i;
3257        c |= bit;        break;
3258        }        }
3259    
3260      chars[location] = c;    if (offsets[2] == -1)
3261      chars[location + 1] = bit;      {
3262        for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3263      len--;        if (ones[i] <= 2)
3264      location += 2;          {
3265      cc++;          offsets[2] = i;
3266            break;
3267            }
3268      }      }
   
   if (location >= MAX_N_CHARS * 2 || must_stop != 0)  
     break;  
3269    }    }
3270    
3271  /* At least two characters are required. */  SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3272  if (location < 2 * 2)  SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3273      return FALSE;  
3274    chars[0] = chars[offsets[0] << 1];
3275    chars[1] = chars[(offsets[0] << 1) + 1];
3276    if (offsets[2] >= 0)
3277      {
3278      chars[2] = chars[offsets[2] << 1];
3279      chars[3] = chars[(offsets[2] << 1) + 1];
3280      }
3281    if (offsets[1] >= 0)
3282      {
3283      chars[4] = chars[offsets[1] << 1];
3284      chars[5] = chars[(offsets[1] << 1) + 1];
3285      }
3286    
3287    max -= 1;
3288  if (firstline)  if (firstline)
3289    {    {
3290    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3291    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3292    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(max));
3293    }    }
3294  else  else
3295    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(max));
3296    
3297  start = LABEL();  start = LABEL();
3298  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3299    
3300  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
3301  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  if (offsets[1] >= 0)
3302      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3303  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));
3304    
3305  if (chars[1] != 0)  if (chars[1] != 0)
3306    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3307  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3308  if (location > 2 * 2)  if (offsets[2] >= 0)
3309    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));
3310  if (chars[3] != 0)  
3311    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);  if (offsets[1] >= 0)
 CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);  
 if (location > 2 * 2)  
3312    {    {
3313    if (chars[5] != 0)    if (chars[5] != 0)
3314      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3315    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
3316      }
3317    
3318    if (offsets[2] >= 0)
3319      {
3320      if (chars[3] != 0)
3321        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3322      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3323    }    }
3324  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3325    
# Line 2726  JUMPHERE(quit); Line 3328  JUMPHERE(quit);
3328  if (firstline)  if (firstline)
3329    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3330  else  else
3331    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(max));
3332  return TRUE;  return TRUE;
3333  }  }
3334    
# Line 2773  else Line 3375  else
3375    else    else
3376      {      {
3377      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);
3378      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3379      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);
3380      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);
3381      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3382      }      }
3383    }    }
# Line 2817  if (common->nltype == NLTYPE_FIXED && co Line 3419  if (common->nltype == NLTYPE_FIXED && co
3419    
3420    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3421    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);
3422    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3423  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3424    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3425  #endif  #endif
# Line 2860  if (common->nltype == NLTYPE_ANY || comm Line 3462  if (common->nltype == NLTYPE_ANY || comm
3462    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3463    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3464    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);
3465    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3466  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3467    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3468  #endif  #endif
# Line 2875  if (firstline) Line 3477  if (firstline)
3477    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3478  }  }
3479    
3480  static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, sljit_uw start_bits, BOOL firstline)  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks);
3481    
3482    static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, pcre_uint8 *start_bits, BOOL firstline)
3483  {  {
3484  DEFINE_COMPILER;  DEFINE_COMPILER;
3485  struct sljit_label *start;  struct sljit_label *start;
3486  struct sljit_jump *quit;  struct sljit_jump *quit;
3487  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3488    jump_list *matches = NULL;
3489  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3490  struct sljit_jump *jump;  struct sljit_jump *jump;
3491  #endif  #endif
# Line 2899  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 3504  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3504  if (common->utf)  if (common->utf)
3505    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3506  #endif  #endif
3507    
3508    if (!check_class_ranges(common, start_bits, (start_bits[31] & 0x80) != 0, TRUE, &matches))
3509      {
3510  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3511  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3512  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3513  JUMPHERE(jump);    JUMPHERE(jump);
3514  #endif  #endif
3515  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3516  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3517  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
3518  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3519  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);
3520  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3521      }
3522    
3523  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3524  if (common->utf)  if (common->utf)
# Line 2921  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S Line 3530  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, S
3530  if (common->utf)  if (common->utf)
3531    {    {
3532    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3533    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);
3534    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3535    }    }
3536  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
# Line 2930  if (common->utf) Line 3539  if (common->utf)
3539    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3540    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3541    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);
3542    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3543    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3544    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3545    }    }
3546  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE[8|16] */
3547  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3548  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3549  JUMPHERE(found);  if (found != NULL)
3550      JUMPHERE(found);
3551    if (matches != NULL)
3552      set_jumps(matches, LABEL());
3553  JUMPHERE(quit);  JUMPHERE(quit);
3554    
3555  if (firstline)  if (firstline)
# Line 3020  GET_LOCAL_BASE(TMP3, 0, 0); Line 3632  GET_LOCAL_BASE(TMP3, 0, 0);
3632  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
3633  mainloop = LABEL();  mainloop = LABEL();
3634  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
3635  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);
3636    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
3637    
3638  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3639  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));
3640  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));
3641  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));
3642  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3643    
3644  JUMPHERE(jump);  JUMPHERE(jump);
3645  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
3646  /* End of dropping frames. */  /* End of dropping frames. */
3647  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3648    
3649  JUMPHERE(jump);  JUMPHERE(jump);
3650  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
3651  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
3652  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
3653  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));  
3654  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
3655  }  }
3656    
# Line 3061  static void check_wordboundary(compiler_ Line 3658  static void check_wordboundary(compiler_
3658  {  {
3659  DEFINE_COMPILER;  DEFINE_COMPILER;
3660  struct sljit_jump *skipread;  struct sljit_jump *skipread;
3661    jump_list *skipread_list = NULL;
3662  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
3663  struct sljit_jump *jump;  struct sljit_jump *jump;
3664  #endif  #endif
# Line 3086  if (common->use_ucp) Line 3684  if (common->use_ucp)
3684    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3685    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3686    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);
3687    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3688    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);
3689    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);
3690    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3691    JUMPHERE(jump);    JUMPHERE(jump);
3692    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
3693    }    }
# Line 3118  else Line 3716  else
3716  JUMPHERE(skipread);  JUMPHERE(skipread);
3717    
3718  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
3719  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
3720  peek_char(common);  peek_char(common);
3721    
3722  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
# Line 3130  if (common->use_ucp) Line 3728  if (common->use_ucp)
3728    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
3729    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
3730    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);
3731    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3732    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);
3733    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);
3734    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3735    JUMPHERE(jump);    JUMPHERE(jump);
3736    }    }
3737  else  else
# Line 3159  else Line 3757  else
3757      JUMPHERE(jump);      JUMPHERE(jump);
3758  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3759    }    }
3760  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
3761    
3762  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);
3763  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
# Line 3176  sljit_emit_fast_return(compiler, SLJIT_M Line 3774  sljit_emit_fast_return(compiler, SLJIT_M
3774  static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)  static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)
3775  {  {
3776  DEFINE_COMPILER;  DEFINE_COMPILER;
3777  struct sljit_jump *jump;  int offset;
3778    
3779  if (ranges[0] < 0)  if (ranges[0] < 0 || ranges[0] > 4)
3780    return FALSE;    return FALSE;
3781    
3782    /* No character is accepted. */
3783    if (ranges[0] == 0 && ranges[1] == 0)
3784      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
3785    
3786    if (readch)
3787      read_char8(common);
3788    
3789  switch(ranges[0])  switch(ranges[0])
3790    {    {
3791      case 0:
3792      /* When ranges[1] != 0, all characters are accepted. */
3793      return TRUE;
3794    
3795    case 1:    case 1:
   if (readch)  
     read_char(common);  
3796    add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));    add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3797    return TRUE;    return TRUE;
3798    
3799    case 2:    case 2:
3800    if (readch)    if (ranges[2] + 1 != ranges[3])
3801      read_char(common);      {
3802    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3803    add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3804        }
3805      else
3806        add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3807    return TRUE;    return TRUE;
3808    
3809    case 4:    case 3:
3810    if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])    if (ranges[1] != 0)
3811      {      {
3812      if (readch)      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3813        read_char(common);      if (ranges[2] + 1 != ranges[3])
     if (ranges[1] != 0)  
3814        {        {
3815        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3816        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3817        }        }
3818      else      else
3819        {        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
       jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]);  
       add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));  
       JUMPHERE(jump);  
       }  
3820      return TRUE;      return TRUE;
3821      }      }
3822    if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))  
3823      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2]));
3824      if (ranges[3] + 1 != ranges[4])
3825        {
3826        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[3]);
3827        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[3]));
3828        }
3829      else
3830        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3]));
3831      return TRUE;
3832    
3833      case 4:
3834      if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4])
3835          && (ranges[2] | (ranges[4] - ranges[2])) == ranges[4]
3836          && is_powerof2(ranges[4] - ranges[2]))
3837      {      {
     if (readch)  
       read_char(common);  
3838      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);
3839      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);      if (ranges[4] + 1 != ranges[5])
3840      add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));        {
3841          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);
3842          add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3843          }
3844        else
3845          add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));
3846      return TRUE;      return TRUE;
3847      }      }
   return FALSE;  
   
   default:  
   return FALSE;  
   }  
 }  
3848    
3849  static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)    if (ranges[1] != 0)
3850  {      {
3851  int i, bit, length;      offset = 0;
3852  const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;      if (ranges[2] + 1 != ranges[3])
3853          {
3854          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3855          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3856          offset = ranges[2];
3857          }
3858        else
3859          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
3860    
3861  bit = ctypes[0] & flag;      if (ranges[4] + 1 != ranges[5])
3862  ranges[0] = -1;        {
3863  ranges[1] = bit != 0 ? 1 : 0;        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - offset);
3864  length = 0;        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));
3865          }
3866        else
3867          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4] - offset));
3868        return TRUE;
3869        }
3870    
3871  for (i = 1; i < 256; i++)    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
3872    if ((ctypes[i] & flag) != bit)    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[2]));
3873      if (ranges[3] + 1 != ranges[4])
3874      {      {
3875      if (length >= MAX_RANGE_SIZE)      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]);
3876        return;      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[3]));
     ranges[2 + length] = i;  
     length++;  
     bit ^= flag;  
3877      }      }
3878      else
3879        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
3880      return TRUE;
3881    
3882  if (bit != 0)    default:
3883    {    SLJIT_ASSERT_STOP();
3884    if (length >= MAX_RANGE_SIZE)    return FALSE;
     return;  
   ranges[2 + length] = 256;  
   length++;  
3885    }    }
 ranges[0] = length;  
3886  }  }
3887    
3888  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks)
3889  {  {
3890  int ranges[2 + MAX_RANGE_SIZE];  int ranges[2 + MAX_RANGE_SIZE];
3891  pcre_uint8 bit, cbit, all;  pcre_uint8 bit, cbit, all;
3892  int i, byte, length = 0;  int i, byte, length = 0;
3893    
3894  bit = bits[0] & 0x1;  bit = bits[0] & 0x1;
3895  ranges[1] = bit;  ranges[1] = !invert ? bit : (bit ^ 0x1);
3896  /* Can be 0 or 255. */  /* All bits will be zero or one (since bit is zero or one). */
3897  all = -bit;  all = -bit;
3898    
3899  for (i = 0; i < 256; )  for (i = 0; i < 256; )
# Line 3313  sljit_emit_fast_enter(compiler, RETURN_A Line 3938  sljit_emit_fast_enter(compiler, RETURN_A
3938    
3939  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
3940  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);
3941  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
3942  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);
3943  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3944  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3945  if (common->utf)  if (common->utf)
3946    {    {
3947  #endif  #endif
3948    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3949    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
3950    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);
3951  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3952    }    }
3953  #endif  #endif
3954  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3955  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);
3956  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3957  }  }
3958    
# Line 3339  DEFINE_COMPILER; Line 3964  DEFINE_COMPILER;
3964  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3965    
3966  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);
3967  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3968  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);
3969  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3970  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);
3971  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3972  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3973  if (common->utf)  if (common->utf)
3974    {    {
3975  #endif  #endif
3976    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3977    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);
3978    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3979    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);
3980    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3981    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
3982    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);
3983    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
3984    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);
3985    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3986    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);
3987    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
3988    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);
3989  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3990    }    }
3991  #endif  #endif
3992  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
3993  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);
3994    
3995  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3996  }  }
# Line 3379  sljit_emit_fast_enter(compiler, RETURN_A Line 4004  sljit_emit_fast_enter(compiler, RETURN_A
4004    
4005  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
4006  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);
4007  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4008  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);
4009  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4010  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4011  if (common->utf)  if (common->utf)
4012    {    {
4013  #endif  #endif
4014    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);
4015    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
4016    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);
4017  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4018    }    }
4019  #endif  #endif
4020  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
4021  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);
4022    
4023  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
4024  }  }
# Line 3479  sljit_emit_fast_return(compiler, RETURN_ Line 4104  sljit_emit_fast_return(compiler, RETURN_
4104    
4105  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
4106    
4107  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)
4108  {  {
4109  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
4110  pcre_uint32 c1, c2;  pcre_uint32 c1, c2;
# Line 3529  if (caseless && char_has_othercase(commo Line 4154  if (caseless && char_has_othercase(commo
4154    othercasechar = cc + (othercasebit >> 8);    othercasechar = cc + (othercasebit >> 8);
4155    othercasebit &= 0xff;    othercasebit &= 0xff;
4156  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4157      /* Note that this code only handles characters in the BMP. If there
4158      ever are characters outside the BMP whose othercase differs in only one
4159      bit from itself (there currently are none), this code will need to be
4160      revised for COMPILE_PCRE32. */
4161    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
4162    if ((othercasebit & 0x100) != 0)    if ((othercasebit & 0x100) != 0)
4163      othercasebit = (othercasebit & 0xff) << 8;      othercasebit = (othercasebit & 0xff) << 8;
# Line 3563  if (context->sourcereg == -1) Line 4192  if (context->sourcereg == -1)
4192    
4193  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4194  utflength = 1;  utflength = 1;
 #ifndef COMPILE_PCRE32  
4195  if (common->utf && HAS_EXTRALEN(*cc))  if (common->utf && HAS_EXTRALEN(*cc))
4196    utflength += GET_EXTRALEN(*cc);    utflength += GET_EXTRALEN(*cc);
 #endif  
4197    
4198  do  do
4199    {    {
4200  #endif  #endif
4201    
4202    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
4203  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
4204    
4205    /* Unaligned read is supported. */    /* Unaligned read is supported. */
4206    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3590  do Line 4217  do
4217    
4218  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
4219    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))
4220  #elif defined COMPILE_PCRE16  #else
4221    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 */)  
4222  #endif  #endif
4223      {      {
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
4224      if (context->length >= 4)      if (context->length >= 4)
4225        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  
4226      else if (context->length >= 2)      else if (context->length >= 2)
4227        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);
4228    #if defined COMPILE_PCRE8
4229      else if (context->length >= 1)      else if (context->length >= 1)
4230        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);
4231  #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] */  
4232      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
4233    
4234      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3621  do Line 4239  do
4239        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));
4240        break;        break;
4241    
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
4242        case 2 / sizeof(pcre_uchar):        case 2 / sizeof(pcre_uchar):
4243        if (context->oc.asushort != 0)        if (context->oc.asushort != 0)
4244          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 4253  do
4253        break;        break;
4254  #endif  #endif
4255    
 #endif /* COMPILE_PCRE[8|16] */  
   
4256        default:        default:
4257        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
4258        break;        break;
# Line 3647  do Line 4262  do
4262    
4263  #else  #else
4264    
4265    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
4266    if (context->length > 0)    if (context->length >= 1)
4267      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
4268    
4269    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
# Line 3699  static void compile_xclass_matchingpath( Line 4314  static void compile_xclass_matchingpath(
4314  {  {
4315  DEFINE_COMPILER;  DEFINE_COMPILER;
4316  jump_list *found = NULL;  jump_list *found = NULL;
4317  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;
4318  pcre_int32 c, charoffset;  pcre_int32 c, charoffset;
 const pcre_uint32 *other_cases;  
4319  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4320  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4321  int compares, invertcmp, numberofcmps;  int compares, invertcmp, numberofcmps;
4322    
4323  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4324  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4325  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4326  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4327    const pcre_uint32 *other_cases;
4328  pcre_int32 typeoffset;  pcre_int32 typeoffset;
4329  #endif  #endif
4330    
# Line 3717  pcre_int32 typeoffset; Line 4333  pcre_int32 typeoffset;
4333  detect_partial_match(common, backtracks);  detect_partial_match(common, backtracks);
4334  read_char(common);  read_char(common);
4335    
4336  if ((*cc++ & XCL_MAP) != 0)  cc++;
4337    if ((cc[-1] & XCL_HASPROP) == 0)
4338    {    {
4339    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    if ((cc[-1] & XCL_MAP) != 0)
4340  #ifndef COMPILE_PCRE8      {
4341    jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4342  #elif defined SUPPORT_UTF  #ifdef SUPPORT_UCP
4343    if (common->utf)      charsaved = TRUE;
     jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
4344  #endif  #endif
4345        if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, FALSE, backtracks))
4346          {
4347          jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4348    
4349          OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4350          OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4351          OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4352          OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4353          OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, TMP2, 0);
4354          add_jump(compiler, &found, JUMP(SLJIT_C_NOT_ZERO));
4355          add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4356    
4357          JUMPHERE(jump);
4358          }
4359        else
4360          add_jump(compiler, &found, CMP(SLJIT_C_LESS_EQUAL, TMP3, 0, SLJIT_IMM, 0xff));
4361    
4362    if (!check_class_ranges(common, (const pcre_uint8 *)cc, TRUE, list))      OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
4363        cc += 32 / sizeof(pcre_uchar);
4364        }
4365      else
4366        add_jump(compiler, (cc[-1] & XCL_NOT) == 0 ? backtracks : &found, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, 0xff));
4367      }
4368    else if ((cc[-1] & XCL_MAP) != 0)
4369      {
4370      OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
4371    #ifdef SUPPORT_UCP
4372      charsaved = TRUE;
4373    #endif
4374      if (!check_class_ranges(common, (const pcre_uint8 *)cc, FALSE, TRUE, list))
4375      {      {
4376    #ifdef COMPILE_PCRE8
4377        SLJIT_ASSERT(common->utf);
4378    #endif
4379        jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4380    
4381      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);      OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
4382      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);      OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
4383      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)cc);
4384      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);      OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4385      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);
4386      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));      add_jump(compiler, list, JUMP(SLJIT_C_NOT_ZERO));
     }  
4387    
 #ifndef COMPILE_PCRE8  
   JUMPHERE(jump);  
 #elif defined SUPPORT_UTF  
   if (common->utf)  
4388      JUMPHERE(jump);      JUMPHERE(jump);
4389  #endif      }
4390    
4391    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
 #ifdef SUPPORT_UCP  
   charsaved = TRUE;  
 #endif  
4392    cc += 32 / sizeof(pcre_uchar);    cc += 32 / sizeof(pcre_uchar);
4393    }    }
4394    
# Line 3759  while (*cc != XCL_END) Line 4401  while (*cc != XCL_END)
4401    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
4402      {      {
4403      cc += 2;      cc += 2;
4404  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
4405      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
4406  #endif  #endif
4407  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 3769  while (*cc != XCL_END) Line 4411  while (*cc != XCL_END)
4411    else if (*cc == XCL_RANGE)    else if (*cc == XCL_RANGE)
4412      {      {
4413      cc += 2;      cc += 2;
4414  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
4415      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
4416  #endif  #endif
4417      cc++;      cc++;
4418  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
4419      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
4420  #endif  #endif
4421  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 3804  while (*cc != XCL_END) Line 4446  while (*cc != XCL_END)
4446        case PT_SPACE:        case PT_SPACE:
4447        case PT_PXSPACE:        case PT_PXSPACE:
4448        case PT_WORD:        case PT_WORD:
4449          case PT_PXGRAPH:
4450          case PT_PXPRINT:
4451          case PT_PXPUNCT:
4452        needstype = TRUE;        needstype = TRUE;
4453        needschar = TRUE;        needschar = TRUE;
4454        break;        break;
4455    
4456        case PT_CLIST:        case PT_CLIST:
4457          case PT_UCNC:
4458        needschar = TRUE;        needschar = TRUE;
4459        break;        break;
4460    
# Line 3848  if (needstype || needsscript) Line 4494  if (needstype || needsscript)
4494      {      {
4495      if (scriptreg == TMP1)      if (scriptreg == TMP1)
4496        {        {
4497        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));
4498        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM2(scriptreg, TMP2), 3);
4499        }        }
4500      else      else
4501        {        {
4502        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 3);
4503        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));
4504        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);        OP1(SLJIT_MOV_UB, scriptreg, 0, SLJIT_MEM1(TMP2), 0);
4505        }        }
4506      }      }
# Line 3890  while (*cc != XCL_END) Line 4536  while (*cc != XCL_END)
4536      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4537        {        {
4538        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);
4539        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);
4540        numberofcmps++;        numberofcmps++;
4541        }        }
4542      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4543        {        {
4544        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);
4545        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);
4546        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4547        numberofcmps = 0;        numberofcmps = 0;
4548        }        }
# Line 3929  while (*cc != XCL_END) Line 4575  while (*cc != XCL_END)
4575      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))      if (numberofcmps < 3 && (*cc == XCL_SINGLE || *cc == XCL_RANGE))
4576        {        {
4577        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);
4578        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);
4579        numberofcmps++;        numberofcmps++;
4580        }        }
4581      else if (numberofcmps > 0)      else if (numberofcmps > 0)
4582        {        {
4583        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);
4584        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);
4585        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4586        numberofcmps = 0;        numberofcmps = 0;
4587        }        }
# Line 3966  while (*cc != XCL_END) Line 4612  while (*cc != XCL_END)
4612    
4613        case PT_LAMP:        case PT_LAMP:
4614        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);
4615        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4616        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);
4617        COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4618        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);
4619        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);
4620        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4621        break;        break;
4622    
# Line 3990  while (*cc != XCL_END) Line 4636  while (*cc != XCL_END)
4636    
4637        case PT_SPACE:        case PT_SPACE:
4638        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);  
         }  
4639        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4640        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);
4641        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4642        if (*cc == PT_SPACE)  
4643          JUMPHERE(jump);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x85 - 0x9);
4644          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4645    
4646          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x9);
4647          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4648    
4649        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4650        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);
4651        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);
4652        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4653        break;        break;
4654    
4655        case PT_WORD:        case PT_WORD:
4656        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);
4657        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4658        /* ... fall through */        /* Fall through. */
4659    
4660        case PT_ALNUM:        case PT_ALNUM:
4661        SET_TYPE_OFFSET(ucp_Ll);        SET_TYPE_OFFSET(ucp_Ll);
4662        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);
4663        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);
4664        SET_TYPE_OFFSET(ucp_Nd);        SET_TYPE_OFFSET(ucp_Nd);
4665        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);
4666        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);
4667        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4668        break;        break;
4669    
# Line 4037  while (*cc != XCL_END) Line 4682  while (*cc != XCL_END)
4682            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]);
4683          else          else
4684            {            {
4685            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_w)charoffset);            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4686            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]);
4687            }            }
4688          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]);
4689          COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4690          other_cases += 2;          other_cases += 2;
4691          }          }
4692        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 4695  while (*cc != XCL_END)
4695            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]);
4696          else          else
4697            {            {
4698            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_w)charoffset);            OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)charoffset);
4699            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]);
4700            }            }
4701          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]);
4702          COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4703    
4704          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);
4705          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);
4706    
4707          other_cases += 3;          other_cases += 3;
4708          }          }
4709        else        else
4710          {          {
4711          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);
4712          COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4713          }          }
4714    
4715        while (*other_cases != NOTACHAR)        while (*other_cases != NOTACHAR)
4716          {          {
4717          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);
4718          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);
4719          }          }
4720        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);        jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4721        break;        break;
4722    
4723          case PT_UCNC:
4724          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_DOLLAR_SIGN - charoffset);
4725          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4726          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_COMMERCIAL_AT - charoffset);
4727          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4728          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_GRAVE_ACCENT - charoffset);
4729          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4730    
4731          SET_CHAR_OFFSET(0xa0);
4732          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd7ff - charoffset);
4733          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4734          SET_CHAR_OFFSET(0);
4735          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xe000 - 0);
4736          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_GREATER_EQUAL);
4737          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4738          break;
4739    
4740          case PT_PXGRAPH:
4741          /* C and Z groups are the farthest two groups. */
4742          SET_TYPE_OFFSET(ucp_Ll);
4743          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4744          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4745    
4746          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4747    
4748          /* In case of ucp_Cf, we overwrite the result. */
4749          SET_CHAR_OFFSET(0x2066);
4750          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4751          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4752    
4753          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4754          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4755    
4756          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x180e - 0x2066);
4757          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4758    
4759          JUMPHERE(jump);
4760          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4761          break;
4762    
4763          case PT_PXPRINT:
4764          /* C and Z groups are the farthest two groups. */
4765          SET_TYPE_OFFSET(ucp_Ll);
4766          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Ll);
4767          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER);
4768    
4769          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Ll);
4770          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_NOT_EQUAL);
4771    
4772          jump = CMP(SLJIT_C_NOT_EQUAL, typereg, 0, SLJIT_IMM, ucp_Cf - ucp_Ll);
4773    
4774          /* In case of ucp_Cf, we overwrite the result. */
4775          SET_CHAR_OFFSET(0x2066);
4776          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x2069 - 0x2066);
4777          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4778    
4779          OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x061c - 0x2066);
4780          OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4781    
4782          JUMPHERE(jump);
4783          jump = CMP(SLJIT_C_ZERO ^ invertcmp, TMP2, 0, SLJIT_IMM, 0);
4784          break;
4785    
4786          case PT_PXPUNCT:
4787          SET_TYPE_OFFSET(ucp_Sc);
4788          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_So - ucp_Sc);
4789          OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4790    
4791          SET_CHAR_OFFSET(0);
4792          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xff);
4793          OP_FLAGS(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4794    
4795          SET_TYPE_OFFSET(ucp_Pc);
4796          OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Ps - ucp_Pc);
4797          OP_FLAGS(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4798          jump = JUMP(SLJIT_C_NOT_ZERO ^ invertcmp);
4799          break;
4800        }        }
4801      cc += 2;      cc += 2;
4802      }      }
# Line 4099  int length; Line 4822  int length;
4822  unsigned int c, oc, bit;  unsigned int c, oc, bit;
4823  compare_context context;  compare_context context;
4824  struct sljit_jump *jump[4];  struct sljit_jump *jump[4];
4825    jump_list *end_list;
4826  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4827  struct sljit_label *label;  struct sljit_label *label;
4828  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4129  switch(type) Line 4853  switch(type)
4853    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
4854    case OP_DIGIT:    case OP_DIGIT:
4855    /* Digits are usually 0-9, so it is worth to optimize them. */    /* Digits are usually 0-9, so it is worth to optimize them. */
   if (common->digits[0] == -2)  
     get_ctype_ranges(common, ctype_digit, common->digits);  
4856    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4857    /* Flip the starting bit in the negative case. */    /* Flip the starting bit in the negative case. */
4858    if (type == OP_NOT_DIGIT)    read_char8_type(common);
4859      common->digits[1] ^= 1;    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);
4860    if (!check_ranges(common, common->digits, backtracks, TRUE))    add_jump(compiler, backtracks, JUMP(type == OP_DIGIT ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
     {  
     read_char8_type(common);  
     OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);  
     add_jump(compiler, backtracks, JUMP(type == OP_DIGIT ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));  
     }  
   if (type == OP_NOT_DIGIT)  
     common->digits[1] ^= 1;  
4861    return cc;    return cc;
4862    
4863    case OP_NOT_WHITESPACE:    case OP_NOT_WHITESPACE:
# Line 4167  switch(type) Line 4882  switch(type)
4882    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4883      {      {
4884      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);
4885        end_list = NULL;
4886      if (common->mode != JIT_PARTIAL_HARD_COMPILE)      if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4887        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));
4888      else      else
4889        jump[1] = check_str_end(common);        check_str_end(common, &end_list);
4890    
4891      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4892      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));
4893      if (jump[1] != NULL)      set_jumps(end_list, LABEL());
       JUMPHERE(jump[1]);  
4894      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
4895      }      }
4896    else    else
# Line 4192  switch(type) Line 4907  switch(type)
4907  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16
4908  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
4909      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
4910      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);
4911      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4912  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
4913      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      jump[0] = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
4914      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
4915      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);
4916      COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4917      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);      OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4918      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
4919  #endif  #endif
# Line 4219  switch(type) Line 4934  switch(type)
4934  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4935    case OP_NOTPROP:    case OP_NOTPROP:
4936    case OP_PROP:    case OP_PROP:
4937    propdata[0] = 0;    propdata[0] = XCL_HASPROP;
4938    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;    propdata[1] = type == OP_NOTPROP ? XCL_NOTPROP : XCL_PROP;
4939    propdata[2] = cc[0];    propdata[2] = cc[0];
4940    propdata[3] = cc[1];    propdata[3] = cc[1];
# Line 4234  switch(type) Line 4949  switch(type)
4949    read_char(common);    read_char(common);
4950    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);
4951    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
4952      end_list = NULL;
4953    if (common->mode != JIT_PARTIAL_HARD_COMPILE)    if (common->mode != JIT_PARTIAL_HARD_COMPILE)
4954      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));
4955    else    else
4956      jump[1] = check_str_end(common);      check_str_end(common, &end_list);
4957    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4958    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);
4959    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));
4960    jump[3] = JUMP(SLJIT_JUMP);    jump[2] = JUMP(SLJIT_JUMP);
4961    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4962    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);
4963      set_jumps(end_list, LABEL());
4964    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
4965    JUMPHERE(jump[2]);    JUMPHERE(jump[2]);
   JUMPHERE(jump[3]);  
4966    return cc;    return cc;
4967    
4968    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
# Line 4270  switch(type) Line 4986  switch(type)
4986    detect_partial_match(common, backtracks);    detect_partial_match(common, backtracks);
4987    read_char(common);    read_char(common);
4988    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4989    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));
4990    /* Optimize register allocation: use a real register. */    /* Optimize register allocation: use a real register. */
4991    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
4992    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 4996  switch(type)
4996    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
4997    read_char(common);    read_char(common);
4998    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4999    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));
5000    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM2(TMP1, TMP2), 3);
5001    
5002    OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);    OP2(SLJIT_SHL, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, 2);
5003    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));
5004    OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);    OP1(SLJIT_MOV, STACK_TOP, 0, TMP2, 0);
5005    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
5006    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 5033  switch(type)
5033        {        {
5034        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);
5035        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);
5036        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS);
5037        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);
5038        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);
5039        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));
5040        check_partial(common, TRUE);        check_partial(common, TRUE);
5041        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
# Line 4467  switch(type) Line 5183  switch(type)
5183    case OP_CHAR:    case OP_CHAR:
5184    case OP_CHARI:    case OP_CHARI:
5185    length = 1;    length = 1;
5186  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
5187    if (common->utf && HAS_EXTRALEN(*cc)) length += GET_EXTRALEN(*cc);    if (common->utf && HAS_EXTRALEN(*cc)) length += GET_EXTRALEN(*cc);
5188  #endif  #endif