/[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 1195 by zherczeg, Thu Nov 1 15:21:27 2012 UTC revision 1476 by zherczeg, Mon Apr 28 06:49:36 2014 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 168  typedef struct jit_arguments { Line 179  typedef struct jit_arguments {
179    
180  typedef struct executable_functions {  typedef struct executable_functions {
181    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
182      sljit_uw *read_only_data[JIT_NUMBER_OF_COMPILE_MODES];
183      sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
184    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
185    void *userdata;    void *userdata;
186    pcre_uint32 top_bracket;    pcre_uint32 top_bracket;
187    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    pcre_uint32 limit_match;
188  } executable_functions;  } executable_functions;
189    
190  typedef struct jump_list {  typedef struct jump_list {
# Line 179  typedef struct jump_list { Line 192  typedef struct jump_list {
192    struct jump_list *next;    struct jump_list *next;
193  } jump_list;  } jump_list;
194    
 enum stub_types { stack_alloc };  
   
195  typedef struct stub_list {  typedef struct stub_list {
   enum stub_types type;  
   int data;  
196    struct sljit_jump *start;    struct sljit_jump *start;
197    struct sljit_label *quit;    struct sljit_label *quit;
198    struct stub_list *next;    struct stub_list *next;
199  } stub_list;  } stub_list;
200    
201    typedef struct label_addr_list {
202      struct sljit_label *label;
203      sljit_uw *update_addr;
204      struct label_addr_list *next;
205    } label_addr_list;
206    
207    enum frame_types {
208      no_frame = -1,
209      no_stack = -2
210    };
211    
212    enum control_types {
213      type_mark = 0,
214      type_then_trap = 1
215    };
216    
217  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
218    
219  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
220  code generator. It is allocated by compile_matchingpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
221  the aguments for compile_backtrackingpath. Must be the first member  the arguments for compile_backtrackingpath. Must be the first member
222  of its descendants. */  of its descendants. */
223  typedef struct backtrack_common {  typedef struct backtrack_common {
224    /* Concatenation stack. */    /* Concatenation stack. */
# Line 209  typedef struct backtrack_common { Line 234  typedef struct backtrack_common {
234  typedef struct assert_backtrack {  typedef struct assert_backtrack {
235    backtrack_common common;    backtrack_common common;
236    jump_list *condfailed;    jump_list *condfailed;
237    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
238    int framesize;    int framesize;
239    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
240    int private_data_ptr;    int private_data_ptr;
# Line 230  typedef struct bracket_backtrack { Line 255  typedef struct bracket_backtrack {
255      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
256      jump_list *condfailed;      jump_list *condfailed;
257      assert_backtrack *assert;      assert_backtrack *assert;
258      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
259      int framesize;      int framesize;
260    } u;    } u;
261    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
# Line 265  typedef struct recurse_entry { Line 290  typedef struct recurse_entry {
290    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
291    jump_list *calls;    jump_list *calls;
292    /* Points to the starting opcode. */    /* Points to the starting opcode. */
293    int start;    sljit_sw start;
294  } recurse_entry;  } recurse_entry;
295    
296  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
297    backtrack_common common;    backtrack_common common;
298      BOOL inlined_pattern;
299  } recurse_backtrack;  } recurse_backtrack;
300    
301  #define MAX_RANGE_SIZE 6  #define OP_THEN_TRAP OP_TABLE_LENGTH
302    
303    typedef struct then_trap_backtrack {
304      backtrack_common common;
305      /* If then_trap is not NULL, this structure contains the real
306      then_trap for the backtracking path. */
307      struct then_trap_backtrack *then_trap;
308      /* Points to the starting opcode. */
309      sljit_sw start;
310      /* Exit point for the then opcodes of this alternative. */
311      jump_list *quit;
312      /* Frame size of the current alternative. */
313      int framesize;
314    } then_trap_backtrack;
315    
316    #define MAX_RANGE_SIZE 4
317    
318  typedef struct compiler_common {  typedef struct compiler_common {
319      /* The sljit ceneric compiler. */
320    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
321      /* First byte code. */
322    pcre_uchar *start;    pcre_uchar *start;
   
323    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
324    int *private_data_ptrs;    sljit_si *private_data_ptrs;
325      /* This read-only data is available during runtime. */
326      sljit_uw *read_only_data;
327      /* The total size of the read-only data. */
328      sljit_uw read_only_data_size;
329      /* The next free entry of the read_only_data. */
330      sljit_uw *read_only_data_ptr;
331    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
332    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
333      /* Tells whether the starting offset is a target of then. */
334      pcre_uint8 *then_offsets;
335      /* Current position where a THEN must jump. */
336      then_trap_backtrack *then_trap;
337    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
338    int cbraptr;    int cbra_ptr;
339    /* OVector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
340    int ovector_start;    int ovector_start;
341    /* Last known position of the requested byte. */    /* Last known position of the requested byte. */
342    int req_char_ptr;    int req_char_ptr;
343    /* Head of the last recursion. */    /* Head of the last recursion. */
344    int recursive_head;    int recursive_head_ptr;
345    /* First inspected character for partial matching. */    /* First inspected character for partial matching. */
346    int start_used_ptr;    int start_used_ptr;
347    /* Starting pointer for partial soft matches. */    /* Starting pointer for partial soft matches. */
# Line 298  typedef struct compiler_common { Line 350  typedef struct compiler_common {
350    int first_line_end;    int first_line_end;
351    /* Points to the marked string. */    /* Points to the marked string. */
352    int mark_ptr;    int mark_ptr;
353      /* Recursive control verb management chain. */
354      int control_head_ptr;
355      /* Points to the last matched capture block index. */
356      int capture_last_ptr;
357      /* Points to the starting position of the current match. */
358      int start_ptr;
359    
360    /* Flipped and lower case tables. */    /* Flipped and lower case tables. */
361    const pcre_uint8 *fcc;    const pcre_uint8 *fcc;
362    sljit_sw lcc;    sljit_sw lcc;
363    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
364    int mode;    int mode;
365      /* TRUE, when minlength is greater than 0. */
366      BOOL might_be_empty;
367      /* \K is found in the pattern. */
368      BOOL has_set_som;
369      /* (*SKIP:arg) is found in the pattern. */
370      BOOL has_skip_arg;
371      /* (*THEN) is found in the pattern. */
372      BOOL has_then;
373      /* Needs to know the start position anytime. */
374      BOOL needs_start_ptr;
375      /* Currently in recurse or negative assert. */
376      BOOL local_exit;
377      /* Currently in a positive assert. */
378      BOOL positive_assert;
379    /* Newline control. */    /* Newline control. */
380    int nltype;    int nltype;
381      pcre_uint32 nlmax;
382      pcre_uint32 nlmin;
383    int newline;    int newline;
384    int bsr_nltype;    int bsr_nltype;
385      pcre_uint32 bsr_nlmax;
386      pcre_uint32 bsr_nlmin;
387    /* Dollar endonly. */    /* Dollar endonly. */
388    int endonly;    int endonly;
   BOOL has_set_som;  
389    /* Tables. */    /* Tables. */
390    sljit_sw ctypes;    sljit_sw ctypes;
   int digits[2 + MAX_RANGE_SIZE];  
391    /* Named capturing brackets. */    /* Named capturing brackets. */
392    sljit_uw name_table;    pcre_uchar *name_table;
393    sljit_sw name_count;    sljit_sw name_count;
394    sljit_sw name_entry_size;    sljit_sw name_entry_size;
395    
396    /* Labels and jump lists. */    /* Labels and jump lists. */
397    struct sljit_label *partialmatchlabel;    struct sljit_label *partialmatchlabel;
398    struct sljit_label *quitlabel;    struct sljit_label *quit_label;
399    struct sljit_label *acceptlabel;    struct sljit_label *forced_quit_label;
400      struct sljit_label *accept_label;
401      struct sljit_label *ff_newline_shortcut;
402    stub_list *stubs;    stub_list *stubs;
403      label_addr_list *label_addrs;
404    recurse_entry *entries;    recurse_entry *entries;
405    recurse_entry *currententry;    recurse_entry *currententry;
406    jump_list *partialmatch;    jump_list *partialmatch;
407    jump_list *quit;    jump_list *quit;
408      jump_list *positive_assert_quit;
409      jump_list *forced_quit;
410    jump_list *accept;    jump_list *accept;
411    jump_list *calllimit;    jump_list *calllimit;
412    jump_list *stackalloc;    jump_list *stackalloc;
# Line 338  typedef struct compiler_common { Line 417  typedef struct compiler_common {
417    jump_list *vspace;    jump_list *vspace;
418    jump_list *casefulcmp;    jump_list *casefulcmp;
419    jump_list *caselesscmp;    jump_list *caselesscmp;
420      jump_list *reset_match;
421    BOOL jscript_compat;    BOOL jscript_compat;
422  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
423    BOOL utf;    BOOL utf;
424  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
425    BOOL use_ucp;    BOOL use_ucp;
426  #endif  #endif
 #ifndef COMPILE_PCRE32  
   jump_list *utfreadchar;  
 #endif  
427  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
428      jump_list *utfreadchar;
429      jump_list *utfreadchar16;
430    jump_list *utfreadtype8;    jump_list *utfreadtype8;
431  #endif  #endif
432  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
# Line 390  typedef struct compare_context { Line 469  typedef struct compare_context {
469  #endif  #endif
470  } compare_context;  } compare_context;
471    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
472  /* Undefine sljit macros. */  /* Undefine sljit macros. */
473  #undef CMP  #undef CMP
474    
475  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
476  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
477    
478  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
479  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
480  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
481  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
482  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
483  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
484  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
485  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
486  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define COUNT_MATCH   SLJIT_SAVED_EREG2
487  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
488    
489  /* Local space layout. */  /* Local space layout. */
# Line 421  enum { Line 494  enum {
494  #define POSSESSIVE0      (2 * sizeof(sljit_sw))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
495  #define POSSESSIVE1      (3 * sizeof(sljit_sw))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
496  /* Max limit of recursions. */  /* Max limit of recursions. */
497  #define CALL_LIMIT       (4 * sizeof(sljit_sw))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
498  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
499  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
500  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
501  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. */
502  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
503  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))  #define OVECTOR(i)       (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw))
504  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_sw))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
505  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
506    
507  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
# Line 459  the start pointers when the end of the c Line 532  the start pointers when the end of the c
532    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
533  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
534    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
535    #define SET_LABEL(jump, label) \
536      sljit_set_label((jump), (label))
537  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
538    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
539  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
540    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))
541  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
542    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
543  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
544    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
545    
546    #define READ_CHAR_MAX 0x7fffffff
547    
548  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
549  {  {
550  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));  SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
# Line 477  cc += 1 + LINK_SIZE; Line 554  cc += 1 + LINK_SIZE;
554  return cc;  return cc;
555  }  }
556    
557    static int no_alternatives(pcre_uchar* cc)
558    {
559    int count = 0;
560    SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
561    do
562      {
563      cc += GET(cc, 1);
564      count++;
565      }
566    while (*cc == OP_ALT);
567    SLJIT_ASSERT(*cc >= OP_KET && *cc <= OP_KETRPOS);
568    return count;
569    }
570    
571    static int ones_in_half_byte[16] = {
572      /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
573      /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
574    };
575    
576  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
577   next_opcode   next_opcode
578   get_private_data_length   check_opcode_types
579   set_private_data_ptrs   set_private_data_ptrs
580   get_framesize   get_framesize
581   init_frame   init_frame
582   get_private_data_length_for_copy   get_private_data_copy_length
583   copy_private_data   copy_private_data
584   compile_matchingpath   compile_matchingpath
585   compile_backtrackingpath   compile_backtrackingpath
# Line 507  switch(*cc) Line 603  switch(*cc)
603    case OP_WORDCHAR:    case OP_WORDCHAR:
604    case OP_ANY:    case OP_ANY:
605    case OP_ALLANY:    case OP_ALLANY:
606      case OP_NOTPROP:
607      case OP_PROP:
608    case OP_ANYNL:    case OP_ANYNL:
609    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
610    case OP_HSPACE:    case OP_HSPACE:
# Line 519  switch(*cc) Line 617  switch(*cc)
617    case OP_CIRCM:    case OP_CIRCM:
618    case OP_DOLL:    case OP_DOLL:
619    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:  
620    case OP_CRSTAR:    case OP_CRSTAR:
621    case OP_CRMINSTAR:    case OP_CRMINSTAR:
622    case OP_CRPLUS:    case OP_CRPLUS:
623    case OP_CRMINPLUS:    case OP_CRMINPLUS:
624    case OP_CRQUERY:    case OP_CRQUERY:
625    case OP_CRMINQUERY:    case OP_CRMINQUERY:
626      case OP_CRRANGE:
627      case OP_CRMINRANGE:
628      case OP_CRPOSSTAR:
629      case OP_CRPOSPLUS:
630      case OP_CRPOSQUERY:
631      case OP_CRPOSRANGE:
632      case OP_CLASS:
633      case OP_NCLASS:
634      case OP_REF:
635      case OP_REFI:
636      case OP_DNREF:
637      case OP_DNREFI:
638      case OP_RECURSE:
639      case OP_CALLOUT:
640      case OP_ALT:
641      case OP_KET:
642      case OP_KETRMAX:
643      case OP_KETRMIN:
644      case OP_KETRPOS:
645      case OP_REVERSE:
646      case OP_ASSERT:
647      case OP_ASSERT_NOT:
648      case OP_ASSERTBACK:
649      case OP_ASSERTBACK_NOT:
650      case OP_ONCE:
651      case OP_ONCE_NC:
652      case OP_BRA:
653      case OP_BRAPOS:
654      case OP_CBRA:
655      case OP_CBRAPOS:
656      case OP_COND:
657      case OP_SBRA:
658      case OP_SBRAPOS:
659      case OP_SCBRA:
660      case OP_SCBRAPOS:
661      case OP_SCOND:
662      case OP_CREF:
663      case OP_DNCREF:
664      case OP_RREF:
665      case OP_DNRREF:
666    case OP_DEF:    case OP_DEF:
667    case OP_BRAZERO:    case OP_BRAZERO:
668    case OP_BRAMINZERO:    case OP_BRAMINZERO:
669    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
670      case OP_PRUNE:
671      case OP_SKIP:
672      case OP_THEN:
673    case OP_COMMIT:    case OP_COMMIT:
674    case OP_FAIL:    case OP_FAIL:
675    case OP_ACCEPT:    case OP_ACCEPT:
676    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
677      case OP_CLOSE:
678    case OP_SKIPZERO:    case OP_SKIPZERO:
679    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
680    
681    case OP_CHAR:    case OP_CHAR:
682    case OP_CHARI:    case OP_CHARI:
# Line 561  switch(*cc) Line 688  switch(*cc)
688    case OP_MINPLUS:    case OP_MINPLUS:
689    case OP_QUERY:    case OP_QUERY:
690    case OP_MINQUERY:    case OP_MINQUERY:
691      case OP_UPTO:
692      case OP_MINUPTO:
693      case OP_EXACT:
694    case OP_POSSTAR:    case OP_POSSTAR:
695    case OP_POSPLUS:    case OP_POSPLUS:
696    case OP_POSQUERY:    case OP_POSQUERY:
697      case OP_POSUPTO:
698    case OP_STARI:    case OP_STARI:
699    case OP_MINSTARI:    case OP_MINSTARI:
700    case OP_PLUSI:    case OP_PLUSI:
701    case OP_MINPLUSI:    case OP_MINPLUSI:
702    case OP_QUERYI:    case OP_QUERYI:
703    case OP_MINQUERYI:    case OP_MINQUERYI:
704      case OP_UPTOI:
705      case OP_MINUPTOI:
706      case OP_EXACTI:
707    case OP_POSSTARI:    case OP_POSSTARI:
708    case OP_POSPLUSI:    case OP_POSPLUSI:
709    case OP_POSQUERYI:    case OP_POSQUERYI:
710      case OP_POSUPTOI:
711    case OP_NOTSTAR:    case OP_NOTSTAR:
712    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
713    case OP_NOTPLUS:    case OP_NOTPLUS:
714    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
715    case OP_NOTQUERY:    case OP_NOTQUERY:
716    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
717      case OP_NOTUPTO:
718      case OP_NOTMINUPTO:
719      case OP_NOTEXACT:
720    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
721    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
722    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
723      case OP_NOTPOSUPTO:
724    case OP_NOTSTARI:    case OP_NOTSTARI:
725    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
726    case OP_NOTPLUSI:    case OP_NOTPLUSI:
727    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
728    case OP_NOTQUERYI:    case OP_NOTQUERYI:
729    case OP_NOTMINQUERYI:    case OP_NOTMINQUERYI:
   case OP_NOTPOSSTARI:  
   case OP_NOTPOSPLUSI:  
   case OP_NOTPOSQUERYI:  
   cc += 2;  
 #ifdef SUPPORT_UTF  
   if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
   return cc;  
   
   case OP_UPTO:  
   case OP_MINUPTO:  
   case OP_EXACT:  
   case OP_POSUPTO:  
   case OP_UPTOI:  
   case OP_MINUPTOI:  
   case OP_EXACTI:  
   case OP_POSUPTOI:  
   case OP_NOTUPTO:  
   case OP_NOTMINUPTO:  
   case OP_NOTEXACT:  
   case OP_NOTPOSUPTO:  
730    case OP_NOTUPTOI:    case OP_NOTUPTOI:
731    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
732    case OP_NOTEXACTI:    case OP_NOTEXACTI:
733      case OP_NOTPOSSTARI:
734      case OP_NOTPOSPLUSI:
735      case OP_NOTPOSQUERYI:
736    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
737    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
738  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
739    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
740  #endif  #endif
741    return cc;    return cc;
742    
743    case OP_NOTPROP:    /* Special cases. */
744    case OP_PROP:    case OP_TYPESTAR:
745    return cc + 1 + 2;    case OP_TYPEMINSTAR:
746      case OP_TYPEPLUS:
747      case OP_TYPEMINPLUS:
748      case OP_TYPEQUERY:
749      case OP_TYPEMINQUERY:
750    case OP_TYPEUPTO:    case OP_TYPEUPTO:
751    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
752    case OP_TYPEEXACT:    case OP_TYPEEXACT:
753      case OP_TYPEPOSSTAR:
754      case OP_TYPEPOSPLUS:
755      case OP_TYPEPOSQUERY:
756    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
757    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;  
758    
759    case OP_CRRANGE:    case OP_ANYBYTE:
760    case OP_CRMINRANGE:  #ifdef SUPPORT_UTF
761    return cc + 1 + 2 * IMM2_SIZE;    if (common->utf) return NULL;
762    #endif
763    case OP_CLASS:    return cc + 1;
   case OP_NCLASS:  
   return cc + 1 + 32 / sizeof(pcre_uchar);  
764    
765  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
766    case OP_XCLASS:    case OP_XCLASS:
767    return cc + GET(cc, 1);    return cc + GET(cc, 1);
768  #endif  #endif
769    
   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;  
   
770    case OP_MARK:    case OP_MARK:
771      case OP_PRUNE_ARG:
772      case OP_SKIP_ARG:
773      case OP_THEN_ARG:
774    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
775    
776    default:    default:
777      /* All opcodes are supported now! */
778      SLJIT_ASSERT_STOP();
779    return NULL;    return NULL;
780    }    }
781  }  }
782    
783  #define CASE_ITERATOR_PRIVATE_DATA_1 \  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
784      case OP_MINSTAR: \  {
785      case OP_MINPLUS: \  int count;
786      case OP_QUERY: \  pcre_uchar *slot;
     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:  
787    
788  #define CASE_ITERATOR_PRIVATE_DATA_2A \  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
789      case OP_STAR: \  while (cc < ccend)
790      case OP_PLUS: \    {
791      case OP_STARI: \    switch(*cc)
792      case OP_PLUSI: \      {
793      case OP_NOTSTAR: \      case OP_SET_SOM:
794      case OP_NOTPLUS: \      common->has_set_som = TRUE;
795      case OP_NOTSTARI: \      common->might_be_empty = TRUE;
796      case OP_NOTPLUSI:      cc += 1;
797        break;
798    
799  #define CASE_ITERATOR_PRIVATE_DATA_2B \      case OP_REF:
800      case OP_UPTO: \      case OP_REFI:
801      case OP_MINUPTO: \      common->optimized_cbracket[GET2(cc, 1)] = 0;
802      case OP_UPTOI: \      cc += 1 + IMM2_SIZE;
803      case OP_MINUPTOI: \      break;
     case OP_NOTUPTO: \  
     case OP_NOTMINUPTO: \  
     case OP_NOTUPTOI: \  
     case OP_NOTMINUPTOI:  
804    
805  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \      case OP_BRA:
806      case OP_TYPEMINSTAR: \      case OP_CBRA:
807      case OP_TYPEMINPLUS: \      case OP_SBRA:
808      case OP_TYPEQUERY: \      case OP_SCBRA:
809      case OP_TYPEMINQUERY:      count = no_alternatives(cc);
810        if (count > 4)
811          common->read_only_data_size += count * sizeof(sljit_uw);
812        cc += 1 + LINK_SIZE + (*cc == OP_CBRA || *cc == OP_SCBRA ? IMM2_SIZE : 0);
813        break;
814    
815  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \      case OP_CBRAPOS:
816      case OP_TYPESTAR: \      case OP_SCBRAPOS:
817      case OP_TYPEPLUS:      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
818        cc += 1 + LINK_SIZE + IMM2_SIZE;
819        break;
820    
821  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \      case OP_COND:
822      case OP_TYPEUPTO: \      case OP_SCOND:
823      case OP_TYPEMINUPTO:      /* Only AUTO_CALLOUT can insert this opcode. We do
824           not intend to support this case. */
825        if (cc[1 + LINK_SIZE] == OP_CALLOUT)
826          return FALSE;
827        cc += 1 + LINK_SIZE;
828        break;
829    
830  static int get_class_iterator_size(pcre_uchar *cc)      case OP_CREF:
831  {      common->optimized_cbracket[GET2(cc, 1)] = 0;
832        cc += 1 + IMM2_SIZE;
833        break;
834    
835        case OP_DNREF:
836        case OP_DNREFI:
837        case OP_DNCREF:
838        count = GET2(cc, 1 + IMM2_SIZE);
839        slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
840        while (count-- > 0)
841          {
842          common->optimized_cbracket[GET2(slot, 0)] = 0;
843          slot += common->name_entry_size;
844          }
845        cc += 1 + 2 * IMM2_SIZE;
846        break;
847    
848        case OP_RECURSE:
849        /* Set its value only once. */
850        if (common->recursive_head_ptr == 0)
851          {
852          common->recursive_head_ptr = common->ovector_start;
853          common->ovector_start += sizeof(sljit_sw);
854          }
855        cc += 1 + LINK_SIZE;
856        break;
857    
858        case OP_CALLOUT:
859        if (common->capture_last_ptr == 0)
860          {
861          common->capture_last_ptr = common->ovector_start;
862          common->ovector_start += sizeof(sljit_sw);
863          }
864        cc += 2 + 2 * LINK_SIZE;
865        break;
866    
867        case OP_THEN_ARG:
868        common->has_then = TRUE;
869        common->control_head_ptr = 1;
870        /* Fall through. */
871    
872        case OP_PRUNE_ARG:
873        common->needs_start_ptr = TRUE;
874        /* Fall through. */
875    
876        case OP_MARK:
877        if (common->mark_ptr == 0)
878          {
879          common->mark_ptr = common->ovector_start;
880          common->ovector_start += sizeof(sljit_sw);
881          }
882        cc += 1 + 2 + cc[1];
883        break;
884    
885        case OP_THEN:
886        common->has_then = TRUE;
887        common->control_head_ptr = 1;
888        /* Fall through. */
889    
890        case OP_PRUNE:
891        case OP_SKIP:
892        common->needs_start_ptr = TRUE;
893        cc += 1;
894        break;
895    
896        case OP_SKIP_ARG:
897        common->control_head_ptr = 1;
898        common->has_skip_arg = TRUE;
899        cc += 1 + 2 + cc[1];
900        break;
901    
902        default:
903        cc = next_opcode(common, cc);
904        if (cc == NULL)
905          return FALSE;
906        break;
907        }
908      }
909    return TRUE;
910    }
911    
912    static int get_class_iterator_size(pcre_uchar *cc)
913    {
914  switch(*cc)  switch(*cc)
915    {    {
916    case OP_CRSTAR:    case OP_CRSTAR:
# Line 762  switch(*cc) Line 934  switch(*cc)
934    }    }
935  }  }
936    
937  static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
938  {  {
939  int private_data_length = 0;  pcre_uchar *end = bracketend(begin);
940  pcre_uchar *alternative;  pcre_uchar *next;
941  pcre_uchar *name;  pcre_uchar *next_end;
942  pcre_uchar *end = NULL;  pcre_uchar *max_end;
943  int space, size, i;  pcre_uchar type;
944  pcre_uint32 bracketlen;  sljit_sw length = end - begin;
945    int min, max, i;
946    
947  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  /* Detect fixed iterations first. */
948  while (cc < ccend)  if (end[-(1 + LINK_SIZE)] != OP_KET)
949      return FALSE;
950    
951    /* Already detected repeat. */
952    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
953      return TRUE;
954    
955    next = end;
956    min = 1;
957    while (1)
958    {    {
959    space = 0;    if (*next != *begin)
   size = 0;  
   bracketlen = 0;  
   switch(*cc)  
     {  
     case OP_SET_SOM:  
     common->has_set_som = TRUE;  
     cc += 1;  
960      break;      break;
961      next_end = bracketend(next);
962      case OP_REF:    if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
     case OP_REFI:  
     common->optimized_cbracket[GET2(cc, 1)] = 0;  
     cc += 1 + IMM2_SIZE;  
963      break;      break;
964      next = next_end;
965      min++;
966      }
967    
968      case OP_ASSERT:  if (min == 2)
969      case OP_ASSERT_NOT:    return FALSE;
     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_sw);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
970    
971      case OP_CBRAPOS:  max = 0;
972      case OP_SCBRAPOS:  max_end = next;
973      private_data_length += sizeof(sljit_sw);  if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
974      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;    {
975      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;    type = *next;
976      break;    while (1)
977        {
978        if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
979          break;
980        next_end = bracketend(next + 2 + LINK_SIZE);
981        if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
982          break;
983        next = next_end;
984        max++;
985        }
986    
987      case OP_COND:    if (next[0] == type && next[1] == *begin && max >= 1)
988      case OP_SCOND:      {
989      bracketlen = cc[1 + LINK_SIZE];      next_end = bracketend(next + 1);
990      if (bracketlen == OP_CREF)      if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
       {  
       bracketlen = GET2(cc, 1 + LINK_SIZE + 1);  
       common->optimized_cbracket[bracketlen] = 0;  
       }  
     else if (bracketlen == OP_NCREF)  
991        {        {
992        bracketlen = GET2(cc, 1 + LINK_SIZE + 1);        for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
993        name = (pcre_uchar *)common->name_table;          if (*next_end != OP_KET)
994        alternative = name;            break;
       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);  
995    
996        for (i = 0; i < common->name_count; i++)        if (i == max)
997          {          {
998          if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)          common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
999            common->optimized_cbracket[GET2(alternative, 0)] = 0;          common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
1000          alternative += common->name_entry_size;          /* +2 the original and the last. */
1001            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
1002            if (min == 1)
1003              return TRUE;
1004            min--;
1005            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
1006          }          }
1007        }        }
1008        }
1009      }
1010    
1011      if (*cc == OP_COND)  if (min >= 3)
1012        {    {
1013        /* Might be a hidden SCOND. */    common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
1014        alternative = cc + GET(cc, 1);    common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
1015        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)    common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
1016          private_data_length += sizeof(sljit_sw);    return TRUE;
1017        }    }
     else  
       private_data_length += sizeof(sljit_sw);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_BRA:  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_CBRA:  
     case OP_SCBRA:  
     bracketlen = 1 + LINK_SIZE + IMM2_SIZE;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_1  
     space = 1;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_2A  
     space = 2;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_2B  
     space = 2;  
     size = -(2 + IMM2_SIZE);  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_1  
     space = 1;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_2A  
     if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)  
       space = 2;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_2B  
     if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)  
       space = 2;  
     size = 1 + IMM2_SIZE;  
     break;  
   
     case OP_CLASS:  
     case OP_NCLASS:  
     size += 1 + 32 / sizeof(pcre_uchar);  
     space = get_class_iterator_size(cc + size);  
     break;  
1018    
1019  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  return FALSE;
1020      case OP_XCLASS:  }
     size = GET(cc, 1);  
     space = get_class_iterator_size(cc + size);  
     break;  
 #endif  
1021    
1022      case OP_RECURSE:  #define CASE_ITERATOR_PRIVATE_DATA_1 \
1023      /* Set its value only once. */      case OP_MINSTAR: \
1024      if (common->recursive_head == 0)      case OP_MINPLUS: \
1025        {      case OP_QUERY: \
1026        common->recursive_head = common->ovector_start;      case OP_MINQUERY: \
1027        common->ovector_start += sizeof(sljit_sw);      case OP_MINSTARI: \
1028        }      case OP_MINPLUSI: \
1029      cc += 1 + LINK_SIZE;      case OP_QUERYI: \
1030      break;      case OP_MINQUERYI: \
1031        case OP_NOTMINSTAR: \
1032        case OP_NOTMINPLUS: \
1033        case OP_NOTQUERY: \
1034        case OP_NOTMINQUERY: \
1035        case OP_NOTMINSTARI: \
1036        case OP_NOTMINPLUSI: \
1037        case OP_NOTQUERYI: \
1038        case OP_NOTMINQUERYI:
1039    
1040      case OP_MARK:  #define CASE_ITERATOR_PRIVATE_DATA_2A \
1041      if (common->mark_ptr == 0)      case OP_STAR: \
1042        {      case OP_PLUS: \
1043        common->mark_ptr = common->ovector_start;      case OP_STARI: \
1044        common->ovector_start += sizeof(sljit_sw);      case OP_PLUSI: \
1045        }      case OP_NOTSTAR: \
1046      cc += 1 + 2 + cc[1];      case OP_NOTPLUS: \
1047      break;      case OP_NOTSTARI: \
1048        case OP_NOTPLUSI:
1049    
1050      default:  #define CASE_ITERATOR_PRIVATE_DATA_2B \
1051      cc = next_opcode(common, cc);      case OP_UPTO: \
1052      if (cc == NULL)      case OP_MINUPTO: \
1053        return -1;      case OP_UPTOI: \
1054      break;      case OP_MINUPTOI: \
1055      }      case OP_NOTUPTO: \
1056        case OP_NOTMINUPTO: \
1057        case OP_NOTUPTOI: \
1058        case OP_NOTMINUPTOI:
1059    
1060    if (space > 0 && cc >= end)  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1061      private_data_length += sizeof(sljit_sw) * space;      case OP_TYPEMINSTAR: \
1062        case OP_TYPEMINPLUS: \
1063        case OP_TYPEQUERY: \
1064        case OP_TYPEMINQUERY:
1065    
1066    if (size != 0)  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1067      {      case OP_TYPESTAR: \
1068      if (size < 0)      case OP_TYPEPLUS:
       {  
       cc += -size;  
 #ifdef SUPPORT_UTF  
       if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);  
 #endif  
       }  
     else  
       cc += size;  
     }  
1069    
1070    if (bracketlen != 0)  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1071      {      case OP_TYPEUPTO: \
1072      if (cc >= end)      case OP_TYPEMINUPTO:
       {  
       end = bracketend(cc);  
       if (end[-1 - LINK_SIZE] == OP_KET)  
         end = NULL;  
       }  
     cc += bracketlen;  
     }  
   }  
 return private_data_length;  
 }  
1073    
1074  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)  static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1075  {  {
1076  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1077  pcre_uchar *alternative;  pcre_uchar *alternative;
1078  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1079    int private_data_ptr = *private_data_start;
1080  int space, size, bracketlen;  int space, size, bracketlen;
1081    
1082  while (cc < ccend)  while (cc < ccend)
# Line 972  while (cc < ccend) Line 1084  while (cc < ccend)
1084    space = 0;    space = 0;
1085    size = 0;    size = 0;
1086    bracketlen = 0;    bracketlen = 0;
1087      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1088        return;
1089    
1090      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1091        if (detect_repeat(common, cc))
1092          {
1093          /* These brackets are converted to repeats, so no global
1094          based single character repeat is allowed. */
1095          if (cc >= end)
1096            end = bracketend(cc);
1097          }
1098    
1099    switch(*cc)    switch(*cc)
1100      {      {
1101        case OP_KET:
1102        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1103          {
1104          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1105          private_data_ptr += sizeof(sljit_sw);
1106          cc += common->private_data_ptrs[cc + 1 - common->start];
1107          }
1108        cc += 1 + LINK_SIZE;
1109        break;
1110    
1111      case OP_ASSERT:      case OP_ASSERT:
1112      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1113      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1067  while (cc < ccend) Line 1201  while (cc < ccend)
1201      break;      break;
1202      }      }
1203    
1204      /* Character iterators, which are not inside a repeated bracket,
1205         gets a private slot instead of allocating it on the stack. */
1206    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1207      {      {
1208      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
# Line 1097  while (cc < ccend) Line 1233  while (cc < ccend)
1233      cc += bracketlen;      cc += bracketlen;
1234      }      }
1235    }    }
1236    *private_data_start = private_data_ptr;
1237  }  }
1238    
1239  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1240  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)
1241  {  {
 pcre_uchar *ccend = bracketend(cc);  
1242  int length = 0;  int length = 0;
1243  BOOL possessive = FALSE;  int possessive = 0;
1244    BOOL stack_restore = FALSE;
1245  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1246  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1247    /* The last capture is a local variable even for recursions. */
1248    BOOL capture_last_found = FALSE;
1249    
1250  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1251    SLJIT_ASSERT(common->control_head_ptr != 0);
1252    *needs_control_head = TRUE;
1253    #else
1254    *needs_control_head = FALSE;
1255    #endif
1256    
1257    if (ccend == NULL)
1258    {    {
1259    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1260    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1261        {
1262        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1263        /* This is correct regardless of common->capture_last_ptr. */
1264        capture_last_found = TRUE;
1265        }
1266      cc = next_opcode(common, cc);
1267    }    }
1268    
 cc = next_opcode(common, cc);  
1269  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1270  while (cc < ccend)  while (cc < ccend)
1271    switch(*cc)    switch(*cc)
1272      {      {
1273      case OP_SET_SOM:      case OP_SET_SOM:
1274      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1275        stack_restore = TRUE;
1276      if (!setsom_found)      if (!setsom_found)
1277        {        {
1278        length += 2;        length += 2;
# Line 1130  while (cc < ccend) Line 1282  while (cc < ccend)
1282      break;      break;
1283    
1284      case OP_MARK:      case OP_MARK:
1285        case OP_PRUNE_ARG:
1286        case OP_THEN_ARG:
1287      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1288        stack_restore = TRUE;
1289      if (!setmark_found)      if (!setmark_found)
1290        {        {
1291        length += 2;        length += 2;
1292        setmark_found = TRUE;        setmark_found = TRUE;
1293        }        }
1294        if (common->control_head_ptr != 0)
1295          *needs_control_head = TRUE;
1296      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1297      break;      break;
1298    
1299      case OP_RECURSE:      case OP_RECURSE:
1300        stack_restore = TRUE;
1301      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1302        {        {
1303        length += 2;        length += 2;
# Line 1150  while (cc < ccend) Line 1308  while (cc < ccend)
1308        length += 2;        length += 2;
1309        setmark_found = TRUE;        setmark_found = TRUE;
1310        }        }
1311        if (common->capture_last_ptr != 0 && !capture_last_found)
1312          {
1313          length += 2;
1314          capture_last_found = TRUE;
1315          }
1316      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1317      break;      break;
1318    
# Line 1157  while (cc < ccend) Line 1320  while (cc < ccend)
1320      case OP_CBRAPOS:      case OP_CBRAPOS:
1321      case OP_SCBRA:      case OP_SCBRA:
1322      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1323        stack_restore = TRUE;
1324        if (common->capture_last_ptr != 0 && !capture_last_found)
1325          {
1326          length += 2;
1327          capture_last_found = TRUE;
1328          }
1329      length += 3;      length += 3;
1330      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1331      break;      break;
1332    
1333      default:      default:
1334        stack_restore = TRUE;
1335        /* Fall through. */
1336    
1337        case OP_NOT_WORD_BOUNDARY:
1338        case OP_WORD_BOUNDARY:
1339        case OP_NOT_DIGIT:
1340        case OP_DIGIT:
1341        case OP_NOT_WHITESPACE:
1342        case OP_WHITESPACE:
1343        case OP_NOT_WORDCHAR:
1344        case OP_WORDCHAR:
1345        case OP_ANY:
1346        case OP_ALLANY:
1347        case OP_ANYBYTE:
1348        case OP_NOTPROP:
1349        case OP_PROP:
1350        case OP_ANYNL:
1351        case OP_NOT_HSPACE:
1352        case OP_HSPACE:
1353        case OP_NOT_VSPACE:
1354        case OP_VSPACE:
1355        case OP_EXTUNI:
1356        case OP_EODN:
1357        case OP_EOD:
1358        case OP_CIRC:
1359        case OP_CIRCM:
1360        case OP_DOLL:
1361        case OP_DOLLM:
1362        case OP_CHAR:
1363        case OP_CHARI:
1364        case OP_NOT:
1365        case OP_NOTI:
1366    
1367        case OP_EXACT:
1368        case OP_POSSTAR:
1369        case OP_POSPLUS:
1370        case OP_POSQUERY:
1371        case OP_POSUPTO:
1372    
1373        case OP_EXACTI:
1374        case OP_POSSTARI:
1375        case OP_POSPLUSI:
1376        case OP_POSQUERYI:
1377        case OP_POSUPTOI:
1378    
1379        case OP_NOTEXACT:
1380        case OP_NOTPOSSTAR:
1381        case OP_NOTPOSPLUS:
1382        case OP_NOTPOSQUERY:
1383        case OP_NOTPOSUPTO:
1384    
1385        case OP_NOTEXACTI:
1386        case OP_NOTPOSSTARI:
1387        case OP_NOTPOSPLUSI:
1388        case OP_NOTPOSQUERYI:
1389        case OP_NOTPOSUPTOI:
1390    
1391        case OP_TYPEEXACT:
1392        case OP_TYPEPOSSTAR:
1393        case OP_TYPEPOSPLUS:
1394        case OP_TYPEPOSQUERY:
1395        case OP_TYPEPOSUPTO:
1396    
1397        case OP_CLASS:
1398        case OP_NCLASS:
1399        case OP_XCLASS:
1400    
1401      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1402      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1403      break;      break;
1404      }      }
1405    
1406  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1407  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1408    return -1;    return stack_restore ? no_frame : no_stack;
1409    
1410  if (length > 0)  if (length > 0)
1411    return length + 1;    return length + 1;
1412  return -1;  return stack_restore ? no_frame : no_stack;
1413  }  }
1414    
1415  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)
1416  {  {
1417  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1418  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1419  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1420    /* The last capture is a local variable even for recursions. */
1421    BOOL capture_last_found = FALSE;
1422  int offset;  int offset;
1423    
1424  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1189  SLJIT_UNUSED_ARG(stacktop); Line 1426  SLJIT_UNUSED_ARG(stacktop);
1426  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1427    
1428  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1429  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1430    cc = next_opcode(common, cc);    {
1431      ccend = bracketend(cc) - (1 + LINK_SIZE);
1432      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1433        cc = next_opcode(common, cc);
1434      }
1435    
1436  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1437  while (cc < ccend)  while (cc < ccend)
1438    switch(*cc)    switch(*cc)
# Line 1200  while (cc < ccend) Line 1442  while (cc < ccend)
1442      if (!setsom_found)      if (!setsom_found)
1443        {        {
1444        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1445        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1446        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1447        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1448        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1210  while (cc < ccend) Line 1452  while (cc < ccend)
1452      break;      break;
1453    
1454      case OP_MARK:      case OP_MARK:
1455        case OP_PRUNE_ARG:
1456        case OP_THEN_ARG:
1457      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1458      if (!setmark_found)      if (!setmark_found)
1459        {        {
1460        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);
1461        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);
1462        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1463        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1464        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1227  while (cc < ccend) Line 1471  while (cc < ccend)
1471      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1472        {        {
1473        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1474        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1475        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1476        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1477        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
# Line 1236  while (cc < ccend) Line 1480  while (cc < ccend)
1480      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1481        {        {
1482        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);
1483        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);
1484        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1485        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1486        stackpos += (int)sizeof(sljit_sw);        stackpos += (int)sizeof(sljit_sw);
1487        setmark_found = TRUE;        setmark_found = TRUE;
1488        }        }
1489        if (common->capture_last_ptr != 0 && !capture_last_found)
1490          {
1491          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1492          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1493          stackpos += (int)sizeof(sljit_sw);
1494          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1495          stackpos += (int)sizeof(sljit_sw);
1496          capture_last_found = TRUE;
1497          }
1498      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1499      break;      break;
1500    
# Line 1249  while (cc < ccend) Line 1502  while (cc < ccend)
1502      case OP_CBRAPOS:      case OP_CBRAPOS:
1503      case OP_SCBRA:      case OP_SCBRA:
1504      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1505        if (common->capture_last_ptr != 0 && !capture_last_found)
1506          {
1507          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1508          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1509          stackpos += (int)sizeof(sljit_sw);
1510          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1511          stackpos += (int)sizeof(sljit_sw);
1512          capture_last_found = TRUE;
1513          }
1514      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1515      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1516      stackpos += (int)sizeof(sljit_sw);      stackpos += (int)sizeof(sljit_sw);
# Line 1268  while (cc < ccend) Line 1530  while (cc < ccend)
1530      break;      break;
1531      }      }
1532    
1533  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1534  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1535  }  }
1536    
1537  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)
1538  {  {
1539  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1540  int size;  int size;
1541  pcre_uchar *alternative;  pcre_uchar *alternative;
1542  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1283  while (cc < ccend) Line 1545  while (cc < ccend)
1545    size = 0;    size = 0;
1546    switch(*cc)    switch(*cc)
1547      {      {
1548        case OP_KET:
1549        if (PRIVATE_DATA(cc) != 0)
1550          private_data_length++;
1551        cc += 1 + LINK_SIZE;
1552        break;
1553    
1554      case OP_ASSERT:      case OP_ASSERT:
1555      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1556      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1387  return private_data_length; Line 1655  return private_data_length;
1655  }  }
1656    
1657  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,
1658    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1659  {  {
1660  DEFINE_COMPILER;  DEFINE_COMPILER;
1661  int srcw[2];  int srcw[2];
# Line 1408  stacktop = STACK(stacktop - 1); Line 1676  stacktop = STACK(stacktop - 1);
1676    
1677  if (!save)  if (!save)
1678    {    {
1679    stackptr += sizeof(sljit_sw);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1680    if (stackptr < stacktop)    if (stackptr < stacktop)
1681      {      {
1682      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
# Line 1424  if (!save) Line 1692  if (!save)
1692    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1693    }    }
1694    
1695  while (status != end)  do
1696    {    {
1697    count = 0;    count = 0;
1698    switch(status)    switch(status)
1699      {      {
1700      case start:      case start:
1701      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1702      count = 1;      count = 1;
1703      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1704        if (needs_control_head)
1705          {
1706          SLJIT_ASSERT(common->control_head_ptr != 0);
1707          count = 2;
1708          srcw[1] = common->control_head_ptr;
1709          }
1710      status = loop;      status = loop;
1711      break;      break;
1712    
# Line 1445  while (status != end) Line 1719  while (status != end)
1719    
1720      switch(*cc)      switch(*cc)
1721        {        {
1722          case OP_KET:
1723          if (PRIVATE_DATA(cc) != 0)
1724            {
1725            count = 1;
1726            srcw[0] = PRIVATE_DATA(cc);
1727            }
1728          cc += 1 + LINK_SIZE;
1729          break;
1730    
1731        case OP_ASSERT:        case OP_ASSERT:
1732        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1733        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1657  while (status != end) Line 1940  while (status != end)
1940        }        }
1941      }      }
1942    }    }
1943    while (status != end);
1944    
1945  if (save)  if (save)
1946    {    {
# Line 1675  if (save) Line 1959  if (save)
1959      }      }
1960    else    else
1961      {      {
1962      if (!tmp2empty)      if (!tmp2empty)
1963        {        {
1964        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1965        stackptr += sizeof(sljit_sw);        stackptr += sizeof(sljit_sw);
1966        }        }
1967      if (!tmp1empty)      if (!tmp1empty)
1968        {        {
1969        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1970        stackptr += sizeof(sljit_sw);        stackptr += sizeof(sljit_sw);
1971        }        }
1972        }
1973      }
1974    SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1975    }
1976    
1977    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1978    {
1979    pcre_uchar *end = bracketend(cc);
1980    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1981    
1982    /* Assert captures then. */
1983    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1984      current_offset = NULL;
1985    /* Conditional block does not. */
1986    if (*cc == OP_COND || *cc == OP_SCOND)
1987      has_alternatives = FALSE;
1988    
1989    cc = next_opcode(common, cc);
1990    if (has_alternatives)
1991      current_offset = common->then_offsets + (cc - common->start);
1992    
1993    while (cc < end)
1994      {
1995      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1996        cc = set_then_offsets(common, cc, current_offset);
1997      else
1998        {
1999        if (*cc == OP_ALT && has_alternatives)
2000          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
2001        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
2002          *current_offset = 1;
2003        cc = next_opcode(common, cc);
2004      }      }
2005    }    }
2006  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  
2007    return end;
2008  }  }
2009    
2010  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
# Line 1708  while (list) Line 2025  while (list)
2025    {    {
2026    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
2027    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
2028    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
2029    list = list->next;    list = list->next;
2030    }    }
2031  }  }
# Line 1724  if (list_item) Line 2041  if (list_item)
2041    }    }
2042  }  }
2043    
2044  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)
2045  {  {
2046  DEFINE_COMPILER;  DEFINE_COMPILER;
2047  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
2048    
2049  if (list_item)  if (list_item)
2050    {    {
   list_item->type = type;  
   list_item->data = data;  
2051    list_item->start = start;    list_item->start = start;
2052    list_item->quit = LABEL();    list_item->quit = LABEL();
2053    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1748  stub_list* list_item = common->stubs; Line 2063  stub_list* list_item = common->stubs;
2063  while (list_item)  while (list_item)
2064    {    {
2065    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2066    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;  
     }  
2067    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2068    list_item = list_item->next;    list_item = list_item->next;
2069    }    }
2070  common->stubs = NULL;  common->stubs = NULL;
2071  }  }
2072    
2073  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static void add_label_addr(compiler_common *common, sljit_uw *update_addr)
2074    {
2075    DEFINE_COMPILER;
2076    label_addr_list *label_addr;
2077    
2078    label_addr = sljit_alloc_memory(compiler, sizeof(label_addr_list));
2079    if (label_addr == NULL)
2080      return;
2081    label_addr->label = LABEL();
2082    label_addr->update_addr = update_addr;
2083    label_addr->next = common->label_addrs;
2084    common->label_addrs = label_addr;
2085    }
2086    
2087    static SLJIT_INLINE void count_match(compiler_common *common)
2088  {  {
2089  DEFINE_COMPILER;  DEFINE_COMPILER;
2090    
2091  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);
2092  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2093  }  }
2094    
# Line 1781  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0); Line 2105  OP1(SLJIT_MOV, RETURN_ADDR, 0, TMP1, 0);
2105  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, TMP1, 0);
2106  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP1, 0);
2107  #endif  #endif
2108  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));
2109  }  }
2110    
2111  static SLJIT_INLINE void free_stack(compiler_common *common, int size)  static SLJIT_INLINE void free_stack(compiler_common *common, int size)
# Line 1795  static SLJIT_INLINE void reset_ovector(c Line 2119  static SLJIT_INLINE void reset_ovector(c
2119  DEFINE_COMPILER;  DEFINE_COMPILER;
2120  struct sljit_label *loop;  struct sljit_label *loop;
2121  int i;  int i;
2122    
2123  /* At this point we can freely use all temporary registers. */  /* At this point we can freely use all temporary registers. */
2124    SLJIT_ASSERT(length > 1);
2125  /* TMP1 returns with begin - 1. */  /* TMP1 returns with begin - 1. */
2126  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));
2127    if (length < 8)
2128      {
2129      for (i = 1; i < length; i++)
2130        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(i), SLJIT_SCRATCH_REG1, 0);
2131      }
2132    else
2133      {
2134      GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, OVECTOR_START);
2135      OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, length - 1);
2136      loop = LABEL();
2137      OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_SCRATCH_REG2), sizeof(sljit_sw), SLJIT_SCRATCH_REG1, 0);
2138      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 1);
2139      JUMPTO(SLJIT_C_NOT_ZERO, loop);
2140      }
2141    }
2142    
2143    static SLJIT_INLINE void do_reset_match(compiler_common *common, int length)
2144    {
2145    DEFINE_COMPILER;
2146    struct sljit_label *loop;
2147    int i;
2148    
2149    SLJIT_ASSERT(length > 1);
2150    /* OVECTOR(1) contains the "string begin - 1" constant. */
2151    if (length > 2)
2152      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
2153  if (length < 8)  if (length < 8)
2154    {    {
2155    for (i = 0; i < length; i++)    for (i = 2; i < length; i++)
2156      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);
2157    }    }
2158  else  else
2159    {    {
2160    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG2, 0, OVECTOR_START - sizeof(sljit_sw));    GET_LOCAL_BASE(TMP2, 0, OVECTOR_START + sizeof(sljit_sw));
2161    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, length);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, length - 2);
2162    loop = LABEL();    loop = LABEL();
2163    OP1(SLJIT_MOVU, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), sizeof(sljit_sw), SLJIT_TEMPORARY_REG1, 0);    OP1(SLJIT_MOVU, SLJIT_MEM1(TMP2), sizeof(sljit_sw), TMP1, 0);
2164    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);
2165    JUMPTO(SLJIT_C_NOT_ZERO, loop);    JUMPTO(SLJIT_C_NOT_ZERO, loop);
2166    }    }
2167    
2168    OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2169    if (common->mark_ptr != 0)
2170      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2171    if (common->control_head_ptr != 0)
2172      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2173    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2174    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2175    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2176    }
2177    
2178    static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2179    {
2180    while (current != NULL)
2181      {
2182      switch (current[-2])
2183        {
2184        case type_then_trap:
2185        break;
2186    
2187        case type_mark:
2188        if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2189          return current[-4];
2190        break;
2191    
2192        default:
2193        SLJIT_ASSERT_STOP();
2194        break;
2195        }
2196      current = (sljit_sw*)current[-1];
2197      }
2198    return -1;
2199  }  }
2200    
2201  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
2202  {  {
2203  DEFINE_COMPILER;  DEFINE_COMPILER;
2204  struct sljit_label *loop;  struct sljit_label *loop;
2205  struct sljit_jump *earlyexit;  struct sljit_jump *early_quit;
2206    
2207  /* At this point we can freely use all registers. */  /* At this point we can freely use all registers. */
2208  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));
2209  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);
2210    
2211  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, ARGUMENTS, 0);
2212  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2213    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);
2214  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));
2215  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2216    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);
2217  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));
2218  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));
2219  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);  GET_LOCAL_BASE(SLJIT_SAVED_REG1, 0, OVECTOR_START);
2220  /* Unlikely, but possible */  /* Unlikely, but possible */
2221  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);
2222  loop = LABEL();  loop = LABEL();
2223  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);
2224  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));  OP2(SLJIT_ADD, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0, SLJIT_IMM, sizeof(sljit_sw));
2225  /* Copy the integer value to the output buffer */  /* Copy the integer value to the output buffer */
2226  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2227  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);
2228  #endif  #endif
2229  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);
2230  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);
2231  JUMPTO(SLJIT_C_NOT_ZERO, loop);  JUMPTO(SLJIT_C_NOT_ZERO, loop);
2232  JUMPHERE(earlyexit);  JUMPHERE(early_quit);
2233    
2234  /* Calculate the return value, which is the maximum ovector value. */  /* Calculate the return value, which is the maximum ovector value. */
2235  if (topbracket > 1)  if (topbracket > 1)
2236    {    {
2237    GET_LOCAL_BASE(SLJIT_TEMPORARY_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));    GET_LOCAL_BASE(SLJIT_SCRATCH_REG1, 0, OVECTOR_START + topbracket * 2 * sizeof(sljit_sw));
2238    OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, topbracket + 1);    OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_IMM, topbracket + 1);
2239    
2240    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */    /* OVECTOR(0) is never equal to SLJIT_SAVED_REG3. */
2241    loop = LABEL();    loop = LABEL();
2242    OP1(SLJIT_MOVU, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), -(2 * (sljit_sw)sizeof(sljit_sw)));    OP1(SLJIT_MOVU, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG1), -(2 * (sljit_sw)sizeof(sljit_sw)));
2243    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);
2244    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);
2245    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_TEMPORARY_REG2, 0);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_SCRATCH_REG2, 0);
2246    }    }
2247  else  else
2248    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
# Line 1867  else Line 2251  else
2251  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)
2252  {  {
2253  DEFINE_COMPILER;  DEFINE_COMPILER;
2254    struct sljit_jump *jump;
2255    
2256  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);
2257  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
2258      && (common->mode == JIT_PARTIAL_SOFT_COMPILE ? common->hit_start != 0 : common->hit_start == 0));
2259    
2260  OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, ARGUMENTS, 0);
2261  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);  OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_PARTIAL);
2262  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));
2263  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);
2264    
2265  /* Store match begin and end. */  /* Store match begin and end. */
2266  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));
2267  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));
2268  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);  
2269    jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2270    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);
2271    #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2272    OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2273    #endif
2274    OP1(SLJIT_MOV_SI, SLJIT_MEM1(SLJIT_SCRATCH_REG2), 2 * sizeof(int), SLJIT_SCRATCH_REG3, 0);
2275    JUMPHERE(jump);
2276    
2277    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);
2278  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);
2279  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2280  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);
2281  #endif  #endif
2282  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);
2283    
2284  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);
2285  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2286  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);
2287  #endif  #endif
2288  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);
2289    
2290  JUMPTO(SLJIT_JUMP, quit);  JUMPTO(SLJIT_JUMP, quit);
2291  }  }
# Line 2040  return (bit < 256) ? ((0 << 8) | bit) : Line 2435  return (bit < 256) ? ((0 << 8) | bit) :
2435    
2436  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2437  {  {
2438  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2439  DEFINE_COMPILER;  DEFINE_COMPILER;
2440  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2441    
# Line 2055  else if (common->mode == JIT_PARTIAL_SOF Line 2450  else if (common->mode == JIT_PARTIAL_SOF
2450    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);
2451    
2452  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2453    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);
2454  else  else
2455    {    {
2456    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
# Line 2068  if (jump != NULL) Line 2463  if (jump != NULL)
2463    JUMPHERE(jump);    JUMPHERE(jump);
2464  }  }
2465    
2466  static struct sljit_jump *check_str_end(compiler_common *common)  static void check_str_end(compiler_common *common, jump_list **end_reached)
2467  {  {
2468  /* Does not affect registers. Usually used in a tight spot. */  /* Does not affect registers. Usually used in a tight spot. */
2469  DEFINE_COMPILER;  DEFINE_COMPILER;
2470  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *nohit;  
 struct sljit_jump *return_value;  
2471    
2472  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2473    return CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    {
2474      add_jump(compiler, end_reached, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2475      return;
2476      }
2477    
2478  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2479  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2480    {    {
2481    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));
2482    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);
2483    JUMPHERE(nohit);    add_jump(compiler, end_reached, JUMP(SLJIT_JUMP));
   return_value = JUMP(SLJIT_JUMP);  
2484    }    }
2485  else  else
2486    {    {
2487    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));
2488    if (common->partialmatchlabel != NULL)    if (common->partialmatchlabel != NULL)
2489      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);      JUMPTO(SLJIT_JUMP, common->partialmatchlabel);
2490    else    else
2491      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));      add_jump(compiler, &common->partialmatch, JUMP(SLJIT_JUMP));
2492    }    }
2493  JUMPHERE(jump);  JUMPHERE(jump);
 return return_value;  
2494  }  }
2495    
2496  static void detect_partial_match(compiler_common *common, jump_list **backtracks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
# Line 2115  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR Line 2509  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR
2509  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));
2510  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2511    {    {
2512    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);
2513    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2514    }    }
2515  else  else
# Line 2128  else Line 2522  else
2522  JUMPHERE(jump);  JUMPHERE(jump);
2523  }  }
2524    
2525  static void read_char(compiler_common *common)  static void peek_char(compiler_common *common, pcre_uint32 max)
2526  {  {
2527  /* Reads the character into TMP1, updates STR_PTR.  /* Reads the character into TMP1, keeps STR_PTR.
2528  Does not check STR_END. TMP2 Destroyed. */  Does not check STR_END. TMP2 Destroyed. */
2529  DEFINE_COMPILER;  DEFINE_COMPILER;
2530  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2531  struct sljit_jump *jump;  struct sljit_jump *jump;
2532  #endif  #endif
2533    
2534    SLJIT_UNUSED_ARG(max);
2535    
2536  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2537  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2538  if (common->utf)  if (common->utf)
2539    {    {
2540  #if defined COMPILE_PCRE8    if (max < 128) return;
2541    
2542    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2543  #elif defined COMPILE_PCRE16    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
   jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);  
 #endif /* COMPILE_PCRE[8|16] */  
2544    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2545      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2546    JUMPHERE(jump);    JUMPHERE(jump);
2547    }    }
2548  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
2549    
2550    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2551    if (common->utf)
2552      {
2553      if (max < 0xd800) return;
2554    
2555      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2556      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2557      /* TMP2 contains the high surrogate. */
2558      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2559      OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2560      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2561      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2562      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2563      JUMPHERE(jump);
2564      }
2565    #endif
2566    }
2567    
2568    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2569    
2570    static BOOL is_char7_bitset(const pcre_uint8 *bitset, BOOL nclass)
2571    {
2572    /* Tells whether the character codes below 128 are enough
2573    to determine a match. */
2574    const pcre_uint8 value = nclass ? 0xff : 0;
2575    const pcre_uint8* end = bitset + 32;
2576    
2577    bitset += 16;
2578    do
2579      {
2580      if (*bitset++ != value)
2581        return FALSE;
2582      }
2583    while (bitset < end);
2584    return TRUE;
2585    }
2586    
2587    static void read_char7_type(compiler_common *common, BOOL full_read)
2588    {
2589    /* Reads the precise character type of a character into TMP1, if the character
2590    is less than 128. Otherwise it returns with zero. Does not check STR_END. The
2591    full_read argument tells whether characters above max are accepted or not. */
2592    DEFINE_COMPILER;
2593    struct sljit_jump *jump;
2594    
2595    SLJIT_ASSERT(common->utf);
2596    
2597    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2598  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));
2599    
2600    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2601    
2602    if (full_read)
2603      {
2604      jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2605      OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2606      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2607      JUMPHERE(jump);
2608      }
2609  }  }
2610    
2611  static void peek_char(compiler_common *common)  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2612    
2613    static void read_char_range(compiler_common *common, pcre_uint32 min, pcre_uint32 max, BOOL update_str_ptr)
2614  {  {
2615  /* Reads the character into TMP1, keeps STR_PTR.  /* Reads the precise value of a character into TMP1, if the character is
2616  Does not check STR_END. TMP2 Destroyed. */  between min and max (c >= min && c <= max). Otherwise it returns with a value
2617    outside the range. Does not check STR_END. */
2618  DEFINE_COMPILER;  DEFINE_COMPILER;
2619  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2620  struct sljit_jump *jump;  struct sljit_jump *jump;
2621  #endif  #endif
2622    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2623    struct sljit_jump *jump2;
2624    #endif
2625    
2626  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  SLJIT_UNUSED_ARG(update_str_ptr);
2627  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  SLJIT_UNUSED_ARG(min);
2628    SLJIT_UNUSED_ARG(max);
2629    SLJIT_ASSERT(min <= max);
2630    
2631    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2632    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2633    
2634    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2635  if (common->utf)  if (common->utf)
2636    {    {
2637  #if defined COMPILE_PCRE8    if (max < 128 && !update_str_ptr) return;
2638    
2639    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
2640  #elif defined COMPILE_PCRE16    if (min >= 0x10000)
2641    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      {
2642  #endif /* COMPILE_PCRE[8|16] */      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xf0);
2643    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));      if (update_str_ptr)
2644    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);        OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2645        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2646        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x7);
2647        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2648        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2649        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2650        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2651        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2652        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2653        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2654        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2655        if (!update_str_ptr)
2656          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2657        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2658        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2659        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2660        JUMPHERE(jump2);
2661        if (update_str_ptr)
2662          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2663        }
2664      else if (min >= 0x800 && max <= 0xffff)
2665        {
2666        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xe0);
2667        if (update_str_ptr)
2668          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2669        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2670        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xf);
2671        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2672        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2673        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2674        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2675        if (!update_str_ptr)
2676          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2677        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2678        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2679        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2680        JUMPHERE(jump2);
2681        if (update_str_ptr)
2682          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2683        }
2684      else if (max >= 0x800)
2685        add_jump(compiler, (max < 0x10000) ? &common->utfreadchar16 : &common->utfreadchar, JUMP(SLJIT_FAST_CALL));
2686      else if (max < 128)
2687        {
2688        OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2689        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2690        }
2691      else
2692        {
2693        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2694        if (!update_str_ptr)
2695          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2696        else
2697          OP1(SLJIT_MOV_UB, RETURN_ADDR, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2698        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2699        OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2700        OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2701        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2702        if (update_str_ptr)
2703          OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, RETURN_ADDR, 0);
2704        }
2705    JUMPHERE(jump);    JUMPHERE(jump);
2706    }    }
2707  #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */  #endif
2708    
2709    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2710    if (common->utf)
2711      {
2712      if (max >= 0x10000)
2713        {
2714        OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2715        jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2716        /* TMP2 contains the high surrogate. */
2717        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2718        OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x40);
2719        OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 10);
2720        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2721        OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);
2722        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2723        JUMPHERE(jump);
2724        return;
2725        }
2726    
2727      if (max < 0xd800 && !update_str_ptr) return;
2728    
2729      /* Skip low surrogate if necessary. */
2730      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xd800);
2731      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2732      if (update_str_ptr)
2733        OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2734      if (max >= 0xd800)
2735        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0x10000);
2736      JUMPHERE(jump);
2737      }
2738    #endif
2739    }
2740    
2741    static SLJIT_INLINE void read_char(compiler_common *common)
2742    {
2743    read_char_range(common, 0, READ_CHAR_MAX, TRUE);
2744  }  }
2745    
2746  static void read_char8_type(compiler_common *common)  static void read_char8_type(compiler_common *common, BOOL update_str_ptr)
2747  {  {
2748  /* 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. */
2749  DEFINE_COMPILER;  DEFINE_COMPILER;
2750  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2751  struct sljit_jump *jump;  struct sljit_jump *jump;
2752  #endif  #endif
2753    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2754    struct sljit_jump *jump2;
2755    #endif
2756    
2757  #ifdef SUPPORT_UTF  SLJIT_UNUSED_ARG(update_str_ptr);
2758    
2759    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2760    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2761    
2762    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2763  if (common->utf)  if (common->utf)
2764    {    {
   OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 #if defined COMPILE_PCRE8  
2765    /* This can be an extra read in some situations, but hopefully    /* This can be an extra read in some situations, but hopefully
2766    it is needed in most cases. */    it is needed in most cases. */
2767    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2768    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);    jump = CMP(SLJIT_C_LESS, TMP2, 0, SLJIT_IMM, 0xc0);
2769    add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));    if (!update_str_ptr)
2770    JUMPHERE(jump);      {
2771  #elif defined COMPILE_PCRE16      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2772    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2773    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2774    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2775    JUMPHERE(jump);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2776    /* Skip low surrogate if necessary. */      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
2777    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2778    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);      jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2779    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2780    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);      JUMPHERE(jump2);
2781    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);      }
2782  #elif defined COMPILE_PCRE32    else
2783    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);      add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
   jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  
2784    JUMPHERE(jump);    JUMPHERE(jump);
 #endif /* COMPILE_PCRE[8|16|32] */  
2785    return;    return;
2786    }    }
2787  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF && COMPILE_PCRE8 */
2788  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
2789  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  #if !defined COMPILE_PCRE8
 #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  
2790  /* The ctypes array contains only 256 values. */  /* The ctypes array contains only 256 values. */
2791  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2792  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2793  #endif  #endif
2794  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2795  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if !defined COMPILE_PCRE8
2796  JUMPHERE(jump);  JUMPHERE(jump);
2797  #endif  #endif
2798    
2799    #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2800    if (common->utf && update_str_ptr)
2801      {
2802      /* Skip low surrogate if necessary. */
2803      OP2(SLJIT_SUB, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xd800);
2804      jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0xdc00 - 0xd800 - 1);
2805      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2806      JUMPHERE(jump);
2807      }
2808    #endif /* SUPPORT_UTF && COMPILE_PCRE16 */
2809  }  }
2810    
2811  static void skip_char_back(compiler_common *common)  static void skip_char_back(compiler_common *common)
# Line 2256  if (common->utf) Line 2833  if (common->utf)
2833    /* Skip low surrogate if necessary. */    /* Skip low surrogate if necessary. */
2834    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
2835    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);
2836    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
2837    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
2838    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
2839    return;    return;
# Line 2266  if (common->utf) Line 2843  if (common->utf)
2843  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));
2844  }  }
2845    
2846  static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpiftrue)  static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpifmatch)
2847  {  {
2848  /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */  /* Character comes in TMP1. Checks if it is a newline. TMP2 may be destroyed. */
2849  DEFINE_COMPILER;  DEFINE_COMPILER;
2850    struct sljit_jump *jump;
2851    
2852  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2853    {    {
2854    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2855    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpifmatch ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2856    }    }
2857  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2858    {    {
2859    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_CR);    if (jumpifmatch)
2860    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      {
2861    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, CHAR_NL);      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR));
2862    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2863    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));      }
2864      else
2865        {
2866        jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
2867        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
2868        JUMPHERE(jump);
2869        }
2870    }    }
2871  else  else
2872    {    {
2873    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2874    add_jump(compiler, backtracks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));    add_jump(compiler, backtracks, CMP(jumpifmatch ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
2875    }    }
2876  }  }
2877    
# Line 2297  else Line 2881  else
2881  static void do_utfreadchar(compiler_common *common)  static void do_utfreadchar(compiler_common *common)
2882  {  {
2883  /* Fast decoding a UTF-8 character. TMP1 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2884  of the character (>= 0xc0). Return char value in TMP1, length - 1 in TMP2. */  of the character (>= 0xc0). Return char value in TMP1, length in TMP2. */
2885  DEFINE_COMPILER;  DEFINE_COMPILER;
2886  struct sljit_jump *jump;  struct sljit_jump *jump;
2887    
2888  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2889    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2890    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2891    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2892    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2893    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2894    
2895  /* Searching for the first zero. */  /* Searching for the first zero. */
2896  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x20);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2897  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2898  /* Two byte sequence. */  /* Two byte sequence. */
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
2899  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));
2900  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1f);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));
2901    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2902    
2903    JUMPHERE(jump);
2904    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2905    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2906  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2907  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2908  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 JUMPHERE(jump);  
2909    
2910  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10);  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2911  jump = JUMP(SLJIT_C_NOT_ZERO);  jump = JUMP(SLJIT_C_NOT_ZERO);
2912  /* Three byte sequence. */  /* Three byte sequence. */
2913  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2914  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));
2915  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2916    
2917    /* Four byte sequence. */
2918    JUMPHERE(jump);
2919    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2920    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2921    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2922    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));
2923  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
2924  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2925  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(4));
2926  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2927    }
2928    
2929    static void do_utfreadchar16(compiler_common *common)
2930    {
2931    /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2932    of the character (>= 0xc0). Return value in TMP1. */
2933    DEFINE_COMPILER;
2934    struct sljit_jump *jump;
2935    
2936    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2937    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2938    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2939    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2940  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2941  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2942  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));  
2943    /* Searching for the first zero. */
2944    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x800);
2945    jump = JUMP(SLJIT_C_NOT_ZERO);
2946    /* Two byte sequence. */
2947    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2948  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2949    
2950  /* Four byte sequence. */  JUMPHERE(jump);
2951    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x400);
2952    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
2953    /* This code runs only in 8 bit mode. No need to shift the value. */
2954    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2955  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2956  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2957  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 12);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(3));  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));  
2958  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2959  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2960  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));  /* Three byte sequence. */
2961    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2962  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2963  }  }
2964    
# Line 2368  jump = JUMP(SLJIT_C_NOT_ZERO); Line 2978  jump = JUMP(SLJIT_C_NOT_ZERO);
2978  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2979  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));
2980  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);
2981    /* The upper 5 bits are known at this point. */
2982    compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 0x3);
2983  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2984  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2985  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);  
2986  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2987  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2988    
2989  JUMPHERE(compare);  JUMPHERE(compare);
2990  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2991  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2992    
2993  /* We only have types for characters less than 256. */  /* We only have types for characters less than 256. */
 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);  
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
 OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
 }  
   
 #elif defined COMPILE_PCRE16  
   
 static void do_utfreadchar(compiler_common *common)  
 {  
 /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char  
 of the character (>= 0xd800). Return char value in TMP1, length - 1 in TMP2. */  
 DEFINE_COMPILER;  
 struct sljit_jump *jump;  
   
 sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  
 jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);  
 /* Do nothing, only return. */  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
   
2994  JUMPHERE(jump);  JUMPHERE(jump);
2995  /* Combine two 16 bit characters. */  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(utf8_table4) - 0xc0);
2996  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2997  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3ff);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 10);  
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3ff);  
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(1));  
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);  
2998  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2999  }  }
3000    
3001  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE8 */
3002    
3003  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3004    
# Line 2489  if (firstline) Line 3073  if (firstline)
3073      mainloop = LABEL();      mainloop = LABEL();
3074      /* Continual stores does not cause data dependency. */      /* Continual stores does not cause data dependency. */
3075      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, STR_PTR, 0);
3076      read_char(common);      read_char_range(common, common->nlmin, common->nlmax, TRUE);
3077      check_newlinechar(common, common->nltype, &newline, TRUE);      check_newlinechar(common, common->nltype, &newline, TRUE);
3078      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);      CMPTO(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0, mainloop);
3079      JUMPHERE(end);      JUMPHERE(end);
# Line 2509  if (newlinecheck) Line 3093  if (newlinecheck)
3093    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    end = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3094    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3095    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);
3096    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3097  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3098    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3099  #endif  #endif
# Line 2547  if (common->utf) Line 3131  if (common->utf)
3131    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);
3132    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3133    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);
3134    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3135    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3136    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3137    JUMPHERE(singlechar);    JUMPHERE(singlechar);
# Line 2562  if (newlinecheck) Line 3146  if (newlinecheck)
3146    JUMPHERE(nl);    JUMPHERE(nl);
3147    }    }
3148    
3149  return mainloop;  return mainloop;
3150  }  }
3151    
3152    #define MAX_N_CHARS 16
3153    #define MAX_N_BYTES 8
3154    
3155    static SLJIT_INLINE void add_prefix_byte(pcre_uint8 byte, pcre_uint8 *bytes)
3156    {
3157    pcre_uint8 len = bytes[0];
3158    int i;
3159    
3160    if (len == 255)
3161      return;
3162    
3163    if (len == 0)
3164      {
3165      bytes[0] = 1;
3166      bytes[1] = byte;
3167      return;
3168      }
3169    
3170    for (i = len; i > 0; i--)
3171      if (bytes[i] == byte)
3172        return;
3173    
3174    if (len >= MAX_N_BYTES - 1)
3175      {
3176      bytes[0] = 255;
3177      return;
3178      }
3179    
3180    len++;
3181    bytes[len] = byte;
3182    bytes[0] = len;
3183    }
3184    
3185    static int scan_prefix(compiler_common *common, pcre_uchar *cc, pcre_uint32 *chars, pcre_uint8 *bytes, int max_chars)
3186    {
3187    /* Recursive function, which scans prefix literals. */
3188    BOOL last, any, caseless;
3189    int len, repeat, len_save, consumed = 0;
3190    pcre_uint32 chr, mask;
3191    pcre_uchar *alternative, *cc_save, *oc;
3192    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3193    pcre_uchar othercase[8];
3194    #elif defined SUPPORT_UTF && defined COMPILE_PCRE16
3195    pcre_uchar othercase[2];
3196    #else
3197    pcre_uchar othercase[1];
3198    #endif
3199    
3200    repeat = 1;
3201    while (TRUE)
3202      {
3203      last = TRUE;
3204      any = FALSE;
3205      caseless = FALSE;
3206      switch (*cc)
3207        {
3208        case OP_CHARI:
3209        caseless = TRUE;
3210        case OP_CHAR:
3211        last = FALSE;
3212        cc++;
3213        break;
3214    
3215        case OP_SOD:
3216        case OP_SOM:
3217        case OP_SET_SOM:
3218        case OP_NOT_WORD_BOUNDARY:
3219        case OP_WORD_BOUNDARY:
3220        case OP_EODN:
3221        case OP_EOD:
3222        case OP_CIRC:
3223        case OP_CIRCM:
3224        case OP_DOLL:
3225        case OP_DOLLM:
3226        /* Zero width assertions. */
3227        cc++;
3228        continue;
3229    
3230        case OP_ASSERT:
3231        case OP_ASSERT_NOT:
3232        case OP_ASSERTBACK:
3233        case OP_ASSERTBACK_NOT:
3234        cc = bracketend(cc);
3235        continue;
3236    
3237        case OP_PLUSI:
3238        case OP_MINPLUSI:
3239        case OP_POSPLUSI:
3240        caseless = TRUE;
3241        case OP_PLUS:
3242        case OP_MINPLUS:
3243        case OP_POSPLUS:
3244        cc++;
3245        break;
3246    
3247        case OP_EXACTI:
3248        caseless = TRUE;
3249        case OP_EXACT:
3250        repeat = GET2(cc, 1);
3251        last = FALSE;
3252        cc += 1 + IMM2_SIZE;
3253        break;
3254    
3255        case OP_QUERYI:
3256        case OP_MINQUERYI:
3257        case OP_POSQUERYI:
3258        caseless = TRUE;
3259        case OP_QUERY:
3260        case OP_MINQUERY:
3261        case OP_POSQUERY:
3262        len = 1;
3263        cc++;
3264    #ifdef SUPPORT_UTF
3265        if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3266    #endif
3267        max_chars = scan_prefix(common, cc + len, chars, bytes, max_chars);
3268        if (max_chars == 0)
3269          return consumed;
3270        last = FALSE;
3271        break;
3272    
3273        case OP_KET:
3274        cc += 1 + LINK_SIZE;
3275        continue;
3276    
3277        case OP_ALT:
3278        cc += GET(cc, 1);
3279        continue;
3280    
3281        case OP_ONCE:
3282        case OP_ONCE_NC:
3283        case OP_BRA:
3284        case OP_BRAPOS:
3285        case OP_CBRA:
3286        case OP_CBRAPOS:
3287        alternative = cc + GET(cc, 1);
3288        while (*alternative == OP_ALT)
3289          {
3290          max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, bytes, max_chars);
3291          if (max_chars == 0)
3292            return consumed;
3293          alternative += GET(alternative, 1);
3294          }
3295    
3296        if (*cc == OP_CBRA || *cc == OP_CBRAPOS)
3297          cc += IMM2_SIZE;
3298        cc += 1 + LINK_SIZE;
3299        continue;
3300    
3301        case OP_CLASS:
3302    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3303        if (common->utf && !is_char7_bitset((const pcre_uint8 *)(cc + 1), FALSE)) return consumed;
3304    #endif
3305        any = TRUE;
3306        cc += 1 + 32 / sizeof(pcre_uchar);
3307        break;
3308    
3309        case OP_NCLASS:
3310    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3311        if (common->utf) return consumed;
3312    #endif
3313        any = TRUE;
3314        cc += 1 + 32 / sizeof(pcre_uchar);
3315        break;
3316    
3317    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3318        case OP_XCLASS:
3319    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3320        if (common->utf) return consumed;
3321    #endif
3322        any = TRUE;
3323        cc += GET(cc, 1);
3324        break;
3325    #endif
3326    
3327        case OP_DIGIT:
3328    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3329        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_digit, FALSE))
3330          return consumed;
3331    #endif
3332        any = TRUE;
3333        cc++;
3334        break;
3335    
3336        case OP_WHITESPACE:
3337    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3338        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_space, FALSE))
3339          return consumed;
3340    #endif
3341        any = TRUE;
3342        cc++;
3343        break;
3344    
3345        case OP_WORDCHAR:
3346    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3347        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_word, FALSE))
3348          return consumed;
3349    #endif
3350        any = TRUE;
3351        cc++;
3352        break;
3353    
3354        case OP_NOT:
3355        case OP_NOTI:
3356        cc++;
3357        /* Fall through. */
3358        case OP_NOT_DIGIT:
3359        case OP_NOT_WHITESPACE:
3360        case OP_NOT_WORDCHAR:
3361        case OP_ANY:
3362        case OP_ALLANY:
3363    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3364        if (common->utf) return consumed;
3365    #endif
3366        any = TRUE;
3367        cc++;
3368        break;
3369    
3370    #ifdef SUPPORT_UCP
3371        case OP_NOTPROP:
3372        case OP_PROP:
3373    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3374        if (common->utf) return consumed;
3375    #endif
3376        any = TRUE;
3377        cc += 1 + 2;
3378        break;
3379    #endif
3380    
3381        case OP_TYPEEXACT:
3382        repeat = GET2(cc, 1);
3383        cc += 1 + IMM2_SIZE;
3384        continue;
3385    
3386        case OP_NOTEXACT:
3387        case OP_NOTEXACTI:
3388    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3389        if (common->utf) return consumed;
3390    #endif
3391        any = TRUE;
3392        repeat = GET2(cc, 1);
3393        cc += 1 + IMM2_SIZE + 1;
3394        break;
3395    
3396        default:
3397        return consumed;
3398        }
3399    
3400      if (any)
3401        {
3402    #if defined COMPILE_PCRE8
3403        mask = 0xff;
3404    #elif defined COMPILE_PCRE16
3405        mask = 0xffff;
3406    #elif defined COMPILE_PCRE32
3407        mask = 0xffffffff;
3408    #else
3409        SLJIT_ASSERT_STOP();
3410    #endif
3411    
3412        do
3413          {
3414          chars[0] = mask;
3415          chars[1] = mask;
3416          bytes[0] = 255;
3417    
3418          consumed++;
3419          if (--max_chars == 0)
3420            return consumed;
3421          chars += 2;
3422          bytes += MAX_N_BYTES;
3423          }
3424        while (--repeat > 0);
3425    
3426        repeat = 1;
3427        continue;
3428        }
3429    
3430      len = 1;
3431    #ifdef SUPPORT_UTF
3432      if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3433    #endif
3434    
3435      if (caseless && char_has_othercase(common, cc))
3436        {
3437    #ifdef SUPPORT_UTF
3438        if (common->utf)
3439          {
3440          GETCHAR(chr, cc);
3441          if ((int)PRIV(ord2utf)(char_othercase(common, chr), othercase) != len)
3442            return consumed;
3443          }
3444        else
3445    #endif
3446          {
3447          chr = *cc;
3448          othercase[0] = TABLE_GET(chr, common->fcc, chr);
3449          }
3450        }
3451      else
3452        caseless = FALSE;
3453    
3454      len_save = len;
3455      cc_save = cc;
3456      while (TRUE)
3457        {
3458        oc = othercase;
3459        do
3460          {
3461          chr = *cc;
3462    #ifdef COMPILE_PCRE32
3463          if (SLJIT_UNLIKELY(chr == NOTACHAR))
3464            return consumed;
3465    #endif
3466          add_prefix_byte((pcre_uint8)chr, bytes);
3467    
3468          mask = 0;
3469          if (caseless)
3470            {
3471            add_prefix_byte((pcre_uint8)*oc, bytes);
3472            mask = *cc ^ *oc;
3473            chr |= mask;
3474            }
3475    
3476    #ifdef COMPILE_PCRE32
3477          if (chars[0] == NOTACHAR && chars[1] == 0)
3478    #else
3479          if (chars[0] == NOTACHAR)
3480    #endif
3481            {
3482            chars[0] = chr;
3483            chars[1] = mask;
3484            }
3485          else
3486            {
3487            mask |= chars[0] ^ chr;
3488            chr |= mask;
3489            chars[0] = chr;
3490            chars[1] |= mask;
3491            }
3492    
3493          len--;
3494          consumed++;
3495          if (--max_chars == 0)
3496            return consumed;
3497          chars += 2;
3498          bytes += MAX_N_BYTES;
3499          cc++;
3500          oc++;
3501          }
3502        while (len > 0);
3503    
3504        if (--repeat == 0)
3505          break;
3506    
3507        len = len_save;
3508        cc = cc_save;
3509        }
3510    
3511  #define MAX_N_CHARS 3    repeat = 1;
3512      if (last)
3513        return consumed;
3514      }
3515    }
3516    
3517  static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)  static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3518  {  {
# Line 2573  DEFINE_COMPILER; Line 3520  DEFINE_COMPILER;
3520  struct sljit_label *start;  struct sljit_label *start;
3521  struct sljit_jump *quit;  struct sljit_jump *quit;
3522  pcre_uint32 chars[MAX_N_CHARS * 2];  pcre_uint32 chars[MAX_N_CHARS * 2];
3523  pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  pcre_uint8 bytes[MAX_N_CHARS * MAX_N_BYTES];
3524  int location = 0;  pcre_uint8 ones[MAX_N_CHARS];
3525  pcre_int32 len, c, bit, caseless;  int offsets[3];
3526  int must_stop;  pcre_uint32 mask;
3527    pcre_uint8 *byte_set, *byte_set_end;
3528    int i, max, from;
3529    int range_right = -1, range_len = 3 - 1;
3530    sljit_ub *update_table = NULL;
3531    BOOL in_range;
3532    
3533    /* This is even TRUE, if both are NULL. */
3534    SLJIT_ASSERT(common->read_only_data_ptr == common->read_only_data);
3535    
3536    for (i = 0; i < MAX_N_CHARS; i++)
3537      {
3538      chars[i << 1] = NOTACHAR;
3539      chars[(i << 1) + 1] = 0;
3540      bytes[i * MAX_N_BYTES] = 0;
3541      }
3542    
3543  /* We do not support alternatives now. */  max = scan_prefix(common, common->start, chars, bytes, MAX_N_CHARS);
3544  if (*(common->start + GET(common->start, 1)) == OP_ALT)  
3545    if (max <= 1)
3546    return FALSE;    return FALSE;
3547    
3548  while (TRUE)  for (i = 0; i < max; i++)
3549    {    {
3550    caseless = 0;    mask = chars[(i << 1) + 1];
3551    must_stop = 1;    ones[i] = ones_in_half_byte[mask & 0xf];
3552    switch(*cc)    mask >>= 4;
3553      while (mask != 0)
3554      {      {
3555      case OP_CHAR:      ones[i] += ones_in_half_byte[mask & 0xf];
3556      must_stop = 0;      mask >>= 4;
3557      cc++;      }
3558      break;    }
3559    
3560      case OP_CHARI:  in_range = FALSE;
3561      caseless = 1;  from = 0;   /* Prevent compiler "uninitialized" warning */
3562      must_stop = 0;  for (i = 0; i <= max; i++)
3563      cc++;    {
3564      break;    if (in_range && (i - from) > range_len && (bytes[(i - 1) * MAX_N_BYTES] <= 4))
3565        {
3566        range_len = i - from;
3567        range_right = i - 1;
3568        }
3569    
3570      case OP_SOD:    if (i < max && bytes[i * MAX_N_BYTES] < 255)
3571      case OP_SOM:      {
3572      case OP_SET_SOM:      if (!in_range)
3573      case OP_NOT_WORD_BOUNDARY:        {
3574      case OP_WORD_BOUNDARY:        in_range = TRUE;
3575      case OP_EODN:        from = i;
3576      case OP_EOD:        }
3577      case OP_CIRC:      }
3578      case OP_CIRCM:    else if (in_range)
3579      case OP_DOLL:      in_range = FALSE;
3580      case OP_DOLLM:    }
     /* Zero width assertions. */  
     cc++;  
     continue;  
3581    
3582      case OP_PLUS:  if (range_right >= 0)
3583      case OP_MINPLUS:    {
3584      case OP_POSPLUS:    /* Since no data is consumed (see the assert in the beginning
3585      cc++;    of this function), this space can be reallocated. */
3586      break;    if (common->read_only_data)
3587        SLJIT_FREE(common->read_only_data);
3588    
3589      case OP_EXACT:    common->read_only_data_size += 256;
3590      cc += 1 + IMM2_SIZE;    common->read_only_data = (sljit_uw *)SLJIT_MALLOC(common->read_only_data_size);
3591      break;    if (common->read_only_data == NULL)
3592        return TRUE;
3593    
3594      case OP_PLUSI:    update_table = (sljit_ub *)common->read_only_data;
3595      case OP_MINPLUSI:    common->read_only_data_ptr = (sljit_uw *)(update_table + 256);
3596      case OP_POSPLUSI:    memset(update_table, IN_UCHARS(range_len), 256);
     caseless = 1;  
     cc++;  
     break;  
3597    
3598      case OP_EXACTI:    for (i = 0; i < range_len; i++)
3599      caseless = 1;      {
3600      cc += 1 + IMM2_SIZE;      byte_set = bytes + ((range_right - i) * MAX_N_BYTES);
3601      break;      SLJIT_ASSERT(byte_set[0] > 0 && byte_set[0] < 255);
3602        byte_set_end = byte_set + byte_set[0];
3603        byte_set++;
3604        while (byte_set <= byte_set_end)
3605          {
3606          if (update_table[*byte_set] > IN_UCHARS(i))
3607            update_table[*byte_set] = IN_UCHARS(i);
3608          byte_set++;
3609          }
3610        }
3611      }
3612    
3613      default:  offsets[0] = -1;
3614      must_stop = 2;  /* Scan forward. */
3615    for (i = 0; i < max; i++)
3616      if (ones[i] <= 2) {
3617        offsets[0] = i;
3618      break;      break;
3619      }    }
3620    
3621    if (offsets[0] < 0 && range_right < 0)
3622      return FALSE;
3623    
3624    if (must_stop == 2)  if (offsets[0] >= 0)
3625      {
3626      /* Scan backward. */
3627      offsets[1] = -1;
3628      for (i = max - 1; i > offsets[0]; i--)
3629        if (ones[i] <= 2 && i != range_right)
3630          {
3631          offsets[1] = i;
3632        break;        break;
3633          }
3634    
3635    len = 1;    /* This case is handled better by fast_forward_first_char. */
3636  #ifdef SUPPORT_UTF    if (offsets[1] == -1 && offsets[0] == 0 && range_right < 0)
3637    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);      return FALSE;
 #endif  
3638    
3639    if (caseless && char_has_othercase(common, cc))    offsets[2] = -1;
3640      {    /* We only search for a middle character if there is no range check. */
3641      caseless = char_get_othercase_bit(common, cc);    if (offsets[1] >= 0 && range_right == -1)
3642      if (caseless == 0)      {
3643        return FALSE;      /* Scan from middle. */
3644  #ifdef COMPILE_PCRE8      for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3645      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));        if (ones[i] <= 2)
3646  #else          {
3647      if ((caseless & 0x100) != 0)          offsets[2] = i;
3648        caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));          break;
3649      else          }
       caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));  
 #endif  
     }  
   else  
     caseless = 0;  
3650    
3651    while (len > 0 && location < MAX_N_CHARS * 2)      if (offsets[2] == -1)
     {  
     c = *cc;  
     bit = 0;  
     if (len == (caseless & 0xff))  
3652        {        {
3653        bit = caseless >> 8;        for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3654        c |= bit;          if (ones[i] <= 2)
3655              {
3656              offsets[2] = i;
3657              break;
3658              }
3659        }        }
3660        }
3661    
3662      chars[location] = c;    SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3663      chars[location + 1] = bit;    SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3664    
3665      len--;    chars[0] = chars[offsets[0] << 1];
3666      location += 2;    chars[1] = chars[(offsets[0] << 1) + 1];
3667      cc++;    if (offsets[2] >= 0)
3668        {
3669        chars[2] = chars[offsets[2] << 1];
3670        chars[3] = chars[(offsets[2] << 1) + 1];
3671        }
3672      if (offsets[1] >= 0)
3673        {
3674        chars[4] = chars[offsets[1] << 1];
3675        chars[5] = chars[(offsets[1] << 1) + 1];
3676      }      }
   
   if (location >= MAX_N_CHARS * 2 || must_stop != 0)  
     break;  
3677    }    }
3678    
3679  /* At least two characters are required. */  max -= 1;
 if (location < 2 * 2)  
     return FALSE;  
   
3680  if (firstline)  if (firstline)
3681    {    {
3682    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3683      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3684    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3685    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, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3686      quit = CMP(SLJIT_C_LESS_EQUAL, STR_END, 0, TMP1, 0);
3687      OP1(SLJIT_MOV, STR_END, 0, TMP1, 0);
3688      JUMPHERE(quit);
3689    }    }
3690  else  else
3691    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));
3692    
3693    #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3694    if (range_right >= 0)
3695      OP1(SLJIT_MOV, RETURN_ADDR, 0, SLJIT_IMM, (sljit_sw)update_table);
3696    #endif
3697    
3698  start = LABEL();  start = LABEL();
3699  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3700    
3701  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  SLJIT_ASSERT(range_right >= 0 || offsets[0] >= 0);
3702  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
3703  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  if (range_right >= 0)
3704  if (chars[1] != 0)    {
3705    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);  #if defined COMPILE_PCRE8 || (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
3706  CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right));
3707  if (location > 2 * 2)  #else
3708    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right + 1) - 1);
3709  if (chars[3] != 0)  #endif
3710    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[3]);  
3711  CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[2], start);  #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3712  if (location > 2 * 2)    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(RETURN_ADDR, TMP1), 0);
3713    {  #else
3714    if (chars[5] != 0)    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)update_table);
3715      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[5]);  #endif
3716    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[4], start);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3717      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, start);
3718      }
3719    
3720    if (offsets[0] >= 0)
3721      {
3722      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
3723      if (offsets[1] >= 0)
3724        OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3725      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3726    
3727      if (chars[1] != 0)
3728        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3729      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3730      if (offsets[2] >= 0)
3731        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));
3732    
3733      if (offsets[1] >= 0)
3734        {
3735        if (chars[5] != 0)
3736          OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3737        CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
3738        }
3739    
3740      if (offsets[2] >= 0)
3741        {
3742        if (chars[3] != 0)
3743          OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3744        CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3745        }
3746      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3747    }    }
 OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
3748    
3749  JUMPHERE(quit);  JUMPHERE(quit);
3750    
3751  if (firstline)  if (firstline)
3752      {
3753      if (range_right >= 0)
3754        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3755    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3756      if (range_right >= 0)
3757        {
3758        quit = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
3759        OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
3760        JUMPHERE(quit);
3761        }
3762      }
3763  else  else
3764    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));
3765  return TRUE;  return TRUE;
3766  }  }
3767    
3768  #undef MAX_N_CHARS  #undef MAX_N_CHARS
3769    #undef MAX_N_BYTES
3770    
3771  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar first_char, BOOL caseless, BOOL firstline)
3772  {  {
# Line 2775  else Line 3809  else
3809    else    else
3810      {      {
3811      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);
3812      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3813      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);
3814      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);
3815      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3816      }      }
3817    }    }
# Line 2819  if (common->nltype == NLTYPE_FIXED && co Line 3853  if (common->nltype == NLTYPE_FIXED && co
3853    
3854    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3855    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);
3856    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3857  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3858    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3859  #endif  #endif
# Line 2838  if (common->nltype == NLTYPE_FIXED && co Line 3872  if (common->nltype == NLTYPE_FIXED && co
3872    JUMPHERE(lastchar);    JUMPHERE(lastchar);
3873    
3874    if (firstline)    if (firstline)
3875      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);      OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3876    return;    return;
3877    }    }
3878    
# Line 2848  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_ Line 3882  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_
3882  skip_char_back(common);  skip_char_back(common);
3883    
3884  loop = LABEL();  loop = LABEL();
3885  read_char(common);  common->ff_newline_shortcut = loop;
3886    
3887    read_char_range(common, common->nlmin, common->nlmax, TRUE);
3888  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3889  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3890    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
# Line 2862  if (common->nltype == NLTYPE_ANY || comm Line 3898  if (common->nltype == NLTYPE_ANY || comm
3898    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3899    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3900    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);
3901    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3902  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3903    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3904  #endif  #endif
# Line 2877  if (firstline) Line 3913  if (firstline)
3913    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3914  }  }
3915    
3916  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);
3917    
3918    static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, pcre_uint8 *start_bits, BOOL firstline)
3919  {  {
3920  DEFINE_COMPILER;  DEFINE_COMPILER;
3921  struct sljit_label *start;  struct sljit_label *start;
3922  struct sljit_jump *quit;  struct sljit_jump *quit;
3923  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3924    jump_list *matches = NULL;
3925  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3926  struct sljit_jump *jump;  struct sljit_jump *jump;
3927  #endif  #endif
# Line 2901  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 3940  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3940  if (common->utf)  if (common->utf)
3941    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3942  #endif  #endif
3943    
3944    if (!check_class_ranges(common, start_bits, (start_bits[31] & 0x80) != 0, TRUE, &matches))
3945      {
3946  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3947  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3948  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3949  JUMPHERE(jump);    JUMPHERE(jump);
3950  #endif  #endif
3951  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3952  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3953  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
3954  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3955  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);
3956  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3957      }
3958    
3959  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3960  if (common->utf)  if (common->utf)
# Line 2932  if (common->utf) Line 3975  if (common->utf)
3975    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3976    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3977    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);
3978    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3979    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3980    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3981    }    }
3982  #endif /* COMPILE_PCRE[8|16] */  #endif /* COMPILE_PCRE[8|16] */
3983  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
3984  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3985  JUMPHERE(found);  if (found != NULL)
3986      JUMPHERE(found);
3987    if (matches != NULL)
3988      set_jumps(matches, LABEL());
3989  JUMPHERE(quit);  JUMPHERE(quit);
3990    
3991  if (firstline)  if (firstline)
# Line 3022  GET_LOCAL_BASE(TMP3, 0, 0); Line 4068  GET_LOCAL_BASE(TMP3, 0, 0);
4068  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
4069  mainloop = LABEL();  mainloop = LABEL();
4070  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
4071  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);
4072    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
4073    
4074  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
4075  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
4076  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
# Line 3030  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_I Line 4078  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_I
4078  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
4079    
4080  JUMPHERE(jump);  JUMPHERE(jump);
4081  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
4082  /* End of dropping frames. */  /* End of dropping frames. */
4083  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
4084    
4085  JUMPHERE(jump);  JUMPHERE(jump);
4086  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
4087  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
4088  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
 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_sw));  
   OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));  
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);  
   JUMPTO(SLJIT_JUMP, mainloop);  
   
   JUMPHERE(jump);  
   }  
   
 /* Unknown command. */  
4089  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
4090  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
4091  }  }
# Line 3063  static void check_wordboundary(compiler_ Line 4094  static void check_wordboundary(compiler_
4094  {  {
4095  DEFINE_COMPILER;  DEFINE_COMPILER;
4096  struct sljit_jump *skipread;  struct sljit_jump *skipread;
4097    jump_list *skipread_list = NULL;
4098  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
4099  struct sljit_jump *jump;  struct sljit_jump *jump;
4100  #endif  #endif
# Line 3088  if (common->use_ucp) Line 4120  if (common->use_ucp)
4120    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4121    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
4122    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);
4123    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4124    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);
4125    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);
4126    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4127    JUMPHERE(jump);    JUMPHERE(jump);
4128    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
4129    }    }
# Line 3120  else Line 4152  else
4152  JUMPHERE(skipread);  JUMPHERE(skipread);
4153    
4154  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
4155  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
4156  peek_char(common);  peek_char(common, READ_CHAR_MAX);
4157    
4158  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
4159  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 3132  if (common->use_ucp) Line 4164  if (common->use_ucp)
4164    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4165    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
4166    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);
4167    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4168    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);
4169    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);
4170    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4171    JUMPHERE(jump);    JUMPHERE(jump);
4172    }    }
4173  else  else
# Line 3161  else Line 4193  else
4193      JUMPHERE(jump);      JUMPHERE(jump);
4194  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
4195    }    }
4196  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
4197    
4198  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);
4199  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
4200  }  }
4201    
4202  /*  static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, BOOL invert, jump_list **backtracks)
   range format:  
   
   ranges[0] = length of the range (max MAX_RANGE_SIZE, -1 means invalid range).  
   ranges[1] = first bit (0 or 1)  
   ranges[2-length] = position of the bit change (when the current bit is not equal to the previous)  
 */  
   
 static BOOL check_ranges(compiler_common *common, int *ranges, jump_list **backtracks, BOOL readch)  
4203  {  {
4204  DEFINE_COMPILER;  DEFINE_COMPILER;
4205  struct sljit_jump *jump;  int ranges[MAX_RANGE_SIZE];
4206    pcre_uint8 bit, cbit, all;
4207    int i, byte, length = 0;
4208    
4209    bit = bits[0] & 0x1;
4210    /* All bits will be zero or one (since bit is zero or one). */
4211    all = -bit;
4212    
4213    for (i = 0; i < 256; )
4214      {
4215      byte = i >> 3;
4216      if ((i & 0x7) == 0 && bits[byte] == all)
4217        i += 8;
4218      else
4219        {
4220        cbit = (bits[byte] >> (i & 0x7)) & 0x1;
4221        if (cbit != bit)
4222          {
4223          if (length >= MAX_RANGE_SIZE)
4224            return FALSE;
4225          ranges[length] = i;
4226          length++;
4227          bit = cbit;
4228          all = -cbit;
4229          }
4230        i++;
4231        }
4232      }
4233    
4234    if (((bit == 0) && nclass) || ((bit == 1) && !nclass))
4235      {
4236      if (length >= MAX_RANGE_SIZE)
4237        return FALSE;
4238      ranges[length] = 256;
4239      length++;
4240      }
4241    
4242  if (ranges[0] < 0)  if (length < 0 || length > 4)
4243    return FALSE;    return FALSE;
4244    
4245  switch(ranges[0])  bit = bits[0] & 0x1;
4246    if (invert) bit ^= 0x1;
4247    
4248    /* No character is accepted. */
4249    if (length == 0 && bit == 0)
4250      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4251    
4252    switch(length)
4253    {    {
4254      case 0:
4255      /* When bit != 0, all characters are accepted. */
4256      return TRUE;
4257    
4258    case 1:    case 1:
4259    if (readch)    add_jump(compiler, backtracks, CMP(bit == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
     read_char(common);  
   add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));  
4260    return TRUE;    return TRUE;
4261    
4262    case 2:    case 2:
4263    if (readch)    if (ranges[0] + 1 != ranges[1])
4264      read_char(common);      {
4265    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
4266    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(bit != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
4267        }
4268      else
4269        add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
4270    return TRUE;    return TRUE;
4271    
4272    case 4:    case 3:
4273    if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])    if (bit != 0)
4274      {      {
4275      if (readch)      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
4276        read_char(common);      if (ranges[0] + 1 != ranges[1])
     if (ranges[1] != 0)  
4277        {        {
4278        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
4279        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[1] - ranges[0]));
4280        }        }
4281      else      else
4282        {        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
       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);  
       }  
4283      return TRUE;      return TRUE;
4284      }      }
4285    if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && is_powerof2(ranges[4] - ranges[2]))  
4286      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[0]));
4287      if (ranges[1] + 1 != ranges[2])
4288      {      {
4289      if (readch)      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1]);
4290        read_char(common);      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1]));
     OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4] - ranges[2]);  
     OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[4]);  
     add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[5] - ranges[4]));  
     return TRUE;  
4291      }      }
4292    return FALSE;    else
4293        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1]));
4294    default:    return TRUE;
   return FALSE;  
   }  
 }  
   
 static void get_ctype_ranges(compiler_common *common, int flag, int *ranges)  
 {  
 int i, bit, length;  
 const pcre_uint8 *ctypes = (const pcre_uint8*)common->ctypes;  
   
 bit = ctypes[0] & flag;  
 ranges[0] = -1;  
 ranges[1] = bit != 0 ? 1 : 0;  
 length = 0;  
4295    
4296  for (i = 1; i < 256; i++)    case 4:
4297    if ((ctypes[i] & flag) != bit)    if ((ranges[1] - ranges[0]) == (ranges[3] - ranges[2])
4298          && (ranges[0] | (ranges[2] - ranges[0])) == ranges[2]
4299          && is_powerof2(ranges[2] - ranges[0]))
4300      {      {
4301      if (length >= MAX_RANGE_SIZE)      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[0]);
4302        return;      if (ranges[2] + 1 != ranges[3])
4303      ranges[2 + length] = i;        {
4304      length++;        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);
4305      bit ^= flag;        add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
4306          }
4307        else
4308          add_jump(compiler, backtracks, CMP(bit != 0 ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));
4309        return TRUE;
4310      }      }
4311    
4312  if (bit != 0)    if (bit != 0)
   {  
   if (length >= MAX_RANGE_SIZE)  
     return;  
   ranges[2 + length] = 256;  
   length++;  
   }  
 ranges[0] = length;  
 }  
   
 static BOOL check_class_ranges(compiler_common *common, const pcre_uint8 *bits, BOOL nclass, jump_list **backtracks)  
 {  
 int ranges[2 + MAX_RANGE_SIZE];  
 pcre_uint8 bit, cbit, all;  
 int i, byte, length = 0;  
   
 bit = bits[0] & 0x1;  
 ranges[1] = bit;  
 /* Can be 0 or 255. */  
 all = -bit;  
   
 for (i = 0; i < 256; )  
   {  
   byte = i >> 3;  
   if ((i & 0x7) == 0 && bits[byte] == all)  
     i += 8;  
   else  
4313      {      {
4314      cbit = (bits[byte] >> (i & 0x7)) & 0x1;      i = 0;
4315      if (cbit != bit)      if (ranges[0] + 1 != ranges[1])
4316          {
4317          OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
4318          add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
4319          i = ranges[0];
4320          }
4321        else
4322          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[0]));
4323    
4324        if (ranges[2] + 1 != ranges[3])
4325        {        {
4326        if (length >= MAX_RANGE_SIZE)        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2] - i);
4327          return FALSE;        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));
       ranges[2 + length] = i;  
       length++;  
       bit = cbit;  
       all = -cbit;  
4328        }        }
4329      i++;      else
4330          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2] - i));
4331        return TRUE;
4332      }      }
   }  
4333    
4334  if (((bit == 0) && nclass) || ((bit == 1) && !nclass))    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[0]);
4335    {    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[0]));
4336    if (length >= MAX_RANGE_SIZE)    if (ranges[1] + 1 != ranges[2])
4337      return FALSE;      {
4338    ranges[2 + length] = 256;      OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]);
4339    length++;      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, ranges[2] - ranges[1]));
4340    }      }
4341  ranges[0] = length;    else
4342        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[1] - ranges[0]));
4343      return TRUE;
4344    
4345  return check_ranges(common, ranges, backtracks, FALSE);    default:
4346      SLJIT_ASSERT_STOP();
4347      return FALSE;
4348      }
4349  }  }
4350    
4351  static void check_anynewline(compiler_common *common)  static void check_anynewline(compiler_common *common)
# Line 3315  sljit_emit_fast_enter(compiler, RETURN_A Line 4357  sljit_emit_fast_enter(compiler, RETURN_A
4357    
4358  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
4359  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);
4360  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4361  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);
4362  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4363  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4364  if (common->utf)  if (common->utf)
4365    {    {
4366  #endif  #endif
4367    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4368    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
4369    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);
4370  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4371    }    }
4372  #endif  #endif
4373  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
4374  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);
4375  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
4376  }  }
4377    
# Line 3341  DEFINE_COMPILER; Line 4383  DEFINE_COMPILER;
4383  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
4384    
4385  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);
4386  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
4387  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);
4388  COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);  OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4389  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);
4390  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4391  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4392  if (common->utf)  if (common->utf)
4393    {    {
4394  #endif  #endif
4395    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4396    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);
4397    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4398    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);
4399    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4400    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x2000);
4401    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);
4402    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4403    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);
4404    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4405    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x205f - 0x2000);
4406    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_EQUAL);
4407    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);
4408  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4409    }    }
4410  #endif  #endif
4411  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
4412  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);
4413    
4414  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
4415  }  }
# Line 3381  sljit_emit_fast_enter(compiler, RETURN_A Line 4423  sljit_emit_fast_enter(compiler, RETURN_A
4423    
4424  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);  OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0a);
4425  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);
4426  COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4427  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);
4428  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4429  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4430  if (common->utf)  if (common->utf)
4431    {    {
4432  #endif  #endif
4433    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);
4434    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x1);
4435    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);
4436  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
4437    }    }
4438  #endif  #endif
4439  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */  #endif /* SUPPORT_UTF || COMPILE_PCRE16 || COMPILE_PCRE32 */
4440  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);
4441    
4442  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
4443  }  }
# Line 3481  sljit_emit_fast_return(compiler, RETURN_ Line 4523  sljit_emit_fast_return(compiler, RETURN_
4523    
4524  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
4525    
4526  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)
4527  {  {
4528  /* This function would be ineffective to do in JIT level. */  /* This function would be ineffective to do in JIT level. */
4529  pcre_uint32 c1, c2;  pcre_uint32 c1, c2;
# Line 3532  if (caseless && char_has_othercase(commo Line 4574  if (caseless && char_has_othercase(commo
4574    othercasebit &= 0xff;    othercasebit &= 0xff;
4575  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
4576    /* Note that this code only handles characters in the BMP. If there    /* Note that this code only handles characters in the BMP. If there
4577    ever are characters outside the BMP whose othercase differs in only one    ever are characters outside the BMP whose othercase differs in only one
4578    bit from itself (there currently are none), this code will need to be    bit from itself (there currently are none), this code will need to be
4579    revised for COMPILE_PCRE32. */    revised for COMPILE_PCRE32. */
4580    othercasechar = cc + (othercasebit >> 9);    othercasechar = cc + (othercasebit >> 9);
# Line 3577  do Line 4619  do
4619  #endif  #endif
4620    
4621    context->length -= IN_UCHARS(1);    context->length -= IN_UCHARS(1);
4622  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
4623    
4624    /* Unaligned read is supported. */    /* Unaligned read is supported. */
4625    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
# Line 3594  do Line 4636  do
4636    
4637  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
4638    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))
4639  #elif defined COMPILE_PCRE16  #else
4640    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 */)  
4641  #endif  #endif
4642      {      {
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
4643      if (context->length >= 4)      if (context->length >= 4)
4644        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  
4645      else if (context->length >= 2)      else if (context->length >= 2)
4646        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);
4647    #if defined COMPILE_PCRE8
4648      else if (context->length >= 1)      else if (context->length >= 1)
4649        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);
4650  #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] */  
4651      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;      context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
4652    
4653      switch(context->ucharptr)      switch(context->ucharptr)
# Line 3625  do Line 4658  do
4658        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));
4659        break;        break;
4660    
 #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16  
4661        case 2 / sizeof(pcre_uchar):        case 2 / sizeof(pcre_uchar):
4662        if (context->oc.asushort != 0)        if (context->oc.asushort != 0)
4663          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 3640  do Line 4672  do
4672        break;        break;
4673  #endif  #endif
4674    
 #endif /* COMPILE_PCRE[8|16] */  
   
4675        default:        default:
4676        SLJIT_ASSERT_STOP();        SLJIT_ASSERT_STOP();
4677        break;        break;
# Line 3651  do Line 4681  do
4681    
4682  #else  #else
4683    
4684    /* Unaligned read is unsupported. */    /* Unaligned read is unsupported or in 32 bit mode. */
4685    if (context->length > 0)    if (context->length >= 1)
4686      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);      OP1(MOV_UCHAR, context->sourcereg, 0, SLJIT_MEM1(STR_PTR), -context->length);
4687    
4688    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;    context->sourcereg = context->sourcereg == TMP1 ? TMP2 : TMP1;
# Line 3682  return cc; Line 4712  return cc;
4712  #define SET_TYPE_OFFSET(value) \  #define SET_TYPE_OFFSET(value) \
4713    if ((value) != typeoffset) \    if ((value) != typeoffset) \
4714      { \      { \
4715      if ((value) > typeoffset) \      if ((value) < typeoffset) \
       OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \  
     else \  
4716        OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \        OP2(SLJIT_ADD, typereg, 0, typereg, 0, SLJIT_IMM, typeoffset - (value)); \
4717        else \
4718          OP2(SLJIT_SUB, typereg, 0, typereg, 0, SLJIT_IMM, (value) - typeoffset); \
4719      } \      } \
4720    typeoffset = (value);    typeoffset = (value);
4721    
4722  #define SET_CHAR_OFFSET(value) \  #define SET_CHAR_OFFSET(value) \
4723    if ((value) != charoffset) \    if ((value) != charoffset) \
4724      { \      { \
4725      if ((value) > charoffset) \      if ((value) < charoffset) \
4726        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (value) - charoffset); \        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)(charoffset - (value))); \
4727      else \      else \
4728        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, charoffset - (value)); \        OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, (sljit_sw)((value) - charoffset)); \
4729      } \      } \
4730    charoffset = (value);    charoffset = (value);
4731    
# Line 3703  static void compile_xclass_matchingpath( Line 4733  static void compile_xclass_matchingpath(
4733  {  {
4734  DEFINE_COMPILER;  DEFINE_COMPILER;
4735  jump_list *found = NULL;  jump_list *found = NULL;
4736  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;  jump_list **list = (cc[0] & XCL_NOT) == 0 ? &found : backtracks;
4737  pcre_int32 c, charoffset;  sljit_uw c, charoffset, max = 256, min = READ_CHAR_MAX;
 const pcre_uint32 *other_cases;  
4738  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
4739  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4740  int compares, invertcmp, numberofcmps;  int compares, invertcmp, numberofcmps;
4741    #if defined SUPPORT_UTF && (defined COMPILE_PCRE8 || defined COMPILE_PCRE16)
4742    BOOL utf = common->utf;
4743    #endif
4744    
4745  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4746  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;  BOOL needstype = FALSE, needsscript = FALSE, needschar = FALSE;
4747  BOOL charsaved = FALSE;  BOOL charsaved = FALSE;
4748  int typereg = TMP1, scriptreg = TMP1;  int typereg = TMP1, scriptreg = TMP1;
4749  pcre_int32 typeoffset;  const pcre_uint32 *other_cases;
4750    sljit_uw typeoffset;
4751  #endif  #endif
4752    
4753  /* Although SUPPORT_UTF must be defined, we are  /* Scanning the necessary info. */
4754     not necessary in utf mode even in 8 bit mode. */  cc++;
4755  detect_partial_match(common, backtracks);  ccbegin = cc;
4756  read_char(common);  compares = 0;
4757    if (cc[-1] & XCL_MAP)
 if ((*cc++ & XCL_MAP) != 0)  
4758    {    {
4759    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    min = 0;
 #ifndef COMPILE_PCRE8  
   jump = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);  
 #elif defined SUPPORT_UTF  
   if (common->utf)