/[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 1015 by ph10, Sun Aug 26 16:07:14 2012 UTC revision 1447 by zherczeg, Mon Jan 13 20:18:33 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 46  POSSIBILITY OF SUCH DAMAGE. Line 46  POSSIBILITY OF SUCH DAMAGE.
46    
47  #include "pcre_internal.h"  #include "pcre_internal.h"
48    
49  #ifdef SUPPORT_JIT  #if defined SUPPORT_JIT
50    
51  /* All-in-one: Since we use the JIT compiler only from here,  /* All-in-one: Since we use the JIT compiler only from here,
52  we just include it. This way we don't need to touch the build  we just include it. This way we don't need to touch the build
# 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    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    pcre_uint32 top_bracket;
187      pcre_uint32 limit_match;
188  } executable_functions;  } executable_functions;
189    
190  typedef struct jump_list {  typedef struct jump_list {
# Line 178  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 *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 208  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 229  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 264  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 297  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_w 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_w 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_w name_count;    sljit_sw name_count;
394    sljit_w 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    stub_list *stubs;    stub_list *stubs;
402      label_addr_list *label_addrs;
403    recurse_entry *entries;    recurse_entry *entries;
404    recurse_entry *currententry;    recurse_entry *currententry;
405    jump_list *partialmatch;    jump_list *partialmatch;
406    jump_list *quit;    jump_list *quit;
407      jump_list *positive_assert_quit;
408      jump_list *forced_quit;
409    jump_list *accept;    jump_list *accept;
410    jump_list *calllimit;    jump_list *calllimit;
411    jump_list *stackalloc;    jump_list *stackalloc;
# Line 337  typedef struct compiler_common { Line 416  typedef struct compiler_common {
416    jump_list *vspace;    jump_list *vspace;
417    jump_list *casefulcmp;    jump_list *casefulcmp;
418    jump_list *caselesscmp;    jump_list *caselesscmp;
419      jump_list *reset_match;
420    BOOL jscript_compat;    BOOL jscript_compat;
421  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
422    BOOL utf;    BOOL utf;
423  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
424    BOOL use_ucp;    BOOL use_ucp;
425  #endif  #endif
   jump_list *utfreadchar;  
426  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
427      jump_list *utfreadchar;
428      jump_list *utfreadchar16;
429    jump_list *utfreadtype8;    jump_list *utfreadtype8;
430  #endif  #endif
431  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
# Line 361  typedef struct compare_context { Line 442  typedef struct compare_context {
442  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
443    int ucharptr;    int ucharptr;
444    union {    union {
445      sljit_i asint;      sljit_si asint;
446      sljit_uh asushort;      sljit_uh asushort;
447  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
448      sljit_ub asbyte;      sljit_ub asbyte;
449      sljit_ub asuchars[4];      sljit_ub asuchars[4];
450  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
451      sljit_uh asuchars[2];      sljit_uh asuchars[2];
452  #endif  #elif defined COMPILE_PCRE32
453        sljit_ui asuchars[1];
454  #endif  #endif
455    } c;    } c;
456    union {    union {
457      sljit_i asint;      sljit_si asint;
458      sljit_uh asushort;      sljit_uh asushort;
459  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
460      sljit_ub asbyte;      sljit_ub asbyte;
461      sljit_ub asuchars[4];      sljit_ub asuchars[4];
462  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
463      sljit_uh asuchars[2];      sljit_uh asuchars[2];
464  #endif  #elif defined COMPILE_PCRE32
465        sljit_ui asuchars[1];
466  #endif  #endif
467    } oc;    } oc;
468  #endif  #endif
469  } compare_context;  } compare_context;
470    
 enum {  
   frame_end = 0,  
   frame_setstrbegin = -1,  
   frame_setmark = -2  
 };  
   
471  /* Undefine sljit macros. */  /* Undefine sljit macros. */
472  #undef CMP  #undef CMP
473    
474  /* Used for accessing the elements of the stack. */  /* Used for accessing the elements of the stack. */
475  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_w))  #define STACK(i)      ((-(i) - 1) * (int)sizeof(sljit_sw))
476    
477  #define TMP1          SLJIT_TEMPORARY_REG1  #define TMP1          SLJIT_SCRATCH_REG1
478  #define TMP2          SLJIT_TEMPORARY_REG3  #define TMP2          SLJIT_SCRATCH_REG3
479  #define TMP3          SLJIT_TEMPORARY_EREG2  #define TMP3          SLJIT_TEMPORARY_EREG2
480  #define STR_PTR       SLJIT_SAVED_REG1  #define STR_PTR       SLJIT_SAVED_REG1
481  #define STR_END       SLJIT_SAVED_REG2  #define STR_END       SLJIT_SAVED_REG2
482  #define STACK_TOP     SLJIT_TEMPORARY_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
483  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
484  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
485  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define COUNT_MATCH   SLJIT_SAVED_EREG2
486  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
487    
488  /* Local space layout. */  /* Local space layout. */
489  /* These two locals can be used by the current opcode. */  /* These two locals can be used by the current opcode. */
490  #define LOCALS0          (0 * sizeof(sljit_w))  #define LOCALS0          (0 * sizeof(sljit_sw))
491  #define LOCALS1          (1 * sizeof(sljit_w))  #define LOCALS1          (1 * sizeof(sljit_sw))
492  /* Two local variables for possessive quantifiers (char1 cannot use them). */  /* Two local variables for possessive quantifiers (char1 cannot use them). */
493  #define POSSESSIVE0      (2 * sizeof(sljit_w))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
494  #define POSSESSIVE1      (3 * sizeof(sljit_w))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
495  /* Max limit of recursions. */  /* Max limit of recursions. */
496  #define CALL_LIMIT       (4 * sizeof(sljit_w))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
497  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
498  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
499  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
500  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. */
501  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
502  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_w))  #define OVECTOR(i)       (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw))
503  #define OVECTOR_PRIV(i)  (common->cbraptr + (i) * sizeof(sljit_w))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
504  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
505    
506  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
507  #define MOV_UCHAR  SLJIT_MOV_UB  #define MOV_UCHAR  SLJIT_MOV_UB
508  #define MOVU_UCHAR SLJIT_MOVU_UB  #define MOVU_UCHAR SLJIT_MOVU_UB
509  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
510  #define MOV_UCHAR  SLJIT_MOV_UH  #define MOV_UCHAR  SLJIT_MOV_UH
511  #define MOVU_UCHAR SLJIT_MOVU_UH  #define MOVU_UCHAR SLJIT_MOVU_UH
512    #elif defined COMPILE_PCRE32
513    #define MOV_UCHAR  SLJIT_MOV_UI
514    #define MOVU_UCHAR SLJIT_MOVU_UI
515  #else  #else
516  #error Unsupported compiling mode  #error Unsupported compiling mode
517  #endif  #endif
 #endif  
518    
519  /* Shortcuts. */  /* Shortcuts. */
520  #define DEFINE_COMPILER \  #define DEFINE_COMPILER \
# Line 455  the start pointers when the end of the c Line 531  the start pointers when the end of the c
531    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))    sljit_set_label(sljit_emit_jump(compiler, (type)), (label))
532  #define JUMPHERE(jump) \  #define JUMPHERE(jump) \
533    sljit_set_label((jump), sljit_emit_label(compiler))    sljit_set_label((jump), sljit_emit_label(compiler))
534    #define SET_LABEL(jump, label) \
535      sljit_set_label((jump), (label))
536  #define CMP(type, src1, src1w, src2, src2w) \  #define CMP(type, src1, src1w, src2, src2w) \
537    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))    sljit_emit_cmp(compiler, (type), (src1), (src1w), (src2), (src2w))
538  #define CMPTO(type, src1, src1w, src2, src2w, label) \  #define CMPTO(type, src1, src1w, src2, src2w, label) \
539    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))
540  #define COND_VALUE(op, dst, dstw, type) \  #define OP_FLAGS(op, dst, dstw, src, srcw, type) \
541    sljit_emit_cond_value(compiler, (op), (dst), (dstw), (type))    sljit_emit_op_flags(compiler, (op), (dst), (dstw), (src), (srcw), (type))
542  #define GET_LOCAL_BASE(dst, dstw, offset) \  #define GET_LOCAL_BASE(dst, dstw, offset) \
543    sljit_get_local_base(compiler, (dst), (dstw), (offset))    sljit_get_local_base(compiler, (dst), (dstw), (offset))
544    
545    #define READ_CHAR_MAX 0x7fffffff
546    
547  static pcre_uchar* bracketend(pcre_uchar* cc)  static pcre_uchar* bracketend(pcre_uchar* cc)
548  {  {
549  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 473  cc += 1 + LINK_SIZE; Line 553  cc += 1 + LINK_SIZE;
553  return cc;  return cc;
554  }  }
555    
556    static int no_alternatives(pcre_uchar* cc)
557    {
558    int count = 0;
559    SLJIT_ASSERT((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND));
560    do
561      {
562      cc += GET(cc, 1);
563      count++;
564      }
565    while (*cc == OP_ALT);
566    SLJIT_ASSERT(*cc >= OP_KET && *cc <= OP_KETRPOS);
567    return count;
568    }
569    
570    static int ones_in_half_byte[16] = {
571      /* 0 */ 0, 1, 1, 2, /* 4 */ 1, 2, 2, 3,
572      /* 8 */ 1, 2, 2, 3, /* 12 */ 2, 3, 3, 4
573    };
574    
575  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
576   next_opcode   next_opcode
577   get_private_data_length   check_opcode_types
578   set_private_data_ptrs   set_private_data_ptrs
579   get_framesize   get_framesize
580   init_frame   init_frame
581   get_private_data_length_for_copy   get_private_data_copy_length
582   copy_private_data   copy_private_data
583   compile_matchingpath   compile_matchingpath
584   compile_backtrackingpath   compile_backtrackingpath
# Line 503  switch(*cc) Line 602  switch(*cc)
602    case OP_WORDCHAR:    case OP_WORDCHAR:
603    case OP_ANY:    case OP_ANY:
604    case OP_ALLANY:    case OP_ALLANY:
605      case OP_NOTPROP:
606      case OP_PROP:
607    case OP_ANYNL:    case OP_ANYNL:
608    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
609    case OP_HSPACE:    case OP_HSPACE:
# Line 515  switch(*cc) Line 616  switch(*cc)
616    case OP_CIRCM:    case OP_CIRCM:
617    case OP_DOLL:    case OP_DOLL:
618    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:  
619    case OP_CRSTAR:    case OP_CRSTAR:
620    case OP_CRMINSTAR:    case OP_CRMINSTAR:
621    case OP_CRPLUS:    case OP_CRPLUS:
622    case OP_CRMINPLUS:    case OP_CRMINPLUS:
623    case OP_CRQUERY:    case OP_CRQUERY:
624    case OP_CRMINQUERY:    case OP_CRMINQUERY:
625      case OP_CRRANGE:
626      case OP_CRMINRANGE:
627      case OP_CRPOSSTAR:
628      case OP_CRPOSPLUS:
629      case OP_CRPOSQUERY:
630      case OP_CRPOSRANGE:
631      case OP_CLASS:
632      case OP_NCLASS:
633      case OP_REF:
634      case OP_REFI:
635      case OP_DNREF:
636      case OP_DNREFI:
637      case OP_RECURSE:
638      case OP_CALLOUT:
639      case OP_ALT:
640      case OP_KET:
641      case OP_KETRMAX:
642      case OP_KETRMIN:
643      case OP_KETRPOS:
644      case OP_REVERSE:
645      case OP_ASSERT:
646      case OP_ASSERT_NOT:
647      case OP_ASSERTBACK:
648      case OP_ASSERTBACK_NOT:
649      case OP_ONCE:
650      case OP_ONCE_NC:
651      case OP_BRA:
652      case OP_BRAPOS:
653      case OP_CBRA:
654      case OP_CBRAPOS:
655      case OP_COND:
656      case OP_SBRA:
657      case OP_SBRAPOS:
658      case OP_SCBRA:
659      case OP_SCBRAPOS:
660      case OP_SCOND:
661      case OP_CREF:
662      case OP_DNCREF:
663      case OP_RREF:
664      case OP_DNRREF:
665    case OP_DEF:    case OP_DEF:
666    case OP_BRAZERO:    case OP_BRAZERO:
667    case OP_BRAMINZERO:    case OP_BRAMINZERO:
668    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
669      case OP_PRUNE:
670      case OP_SKIP:
671      case OP_THEN:
672    case OP_COMMIT:    case OP_COMMIT:
673    case OP_FAIL:    case OP_FAIL:
674    case OP_ACCEPT:    case OP_ACCEPT:
675    case OP_ASSERT_ACCEPT:    case OP_ASSERT_ACCEPT:
676      case OP_CLOSE:
677    case OP_SKIPZERO:    case OP_SKIPZERO:
678    return cc + 1;    return cc + PRIV(OP_lengths)[*cc];
   
   case OP_ANYBYTE:  
 #ifdef SUPPORT_UTF  
   if (common->utf) return NULL;  
 #endif  
   return cc + 1;  
679    
680    case OP_CHAR:    case OP_CHAR:
681    case OP_CHARI:    case OP_CHARI:
# Line 557  switch(*cc) Line 687  switch(*cc)
687    case OP_MINPLUS:    case OP_MINPLUS:
688    case OP_QUERY:    case OP_QUERY:
689    case OP_MINQUERY:    case OP_MINQUERY:
690      case OP_UPTO:
691      case OP_MINUPTO:
692      case OP_EXACT:
693    case OP_POSSTAR:    case OP_POSSTAR:
694    case OP_POSPLUS:    case OP_POSPLUS:
695    case OP_POSQUERY:    case OP_POSQUERY:
696      case OP_POSUPTO:
697    case OP_STARI:    case OP_STARI:
698    case OP_MINSTARI:    case OP_MINSTARI:
699    case OP_PLUSI:    case OP_PLUSI:
700    case OP_MINPLUSI:    case OP_MINPLUSI:
701    case OP_QUERYI:    case OP_QUERYI:
702    case OP_MINQUERYI:    case OP_MINQUERYI:
703      case OP_UPTOI:
704      case OP_MINUPTOI:
705      case OP_EXACTI:
706    case OP_POSSTARI:    case OP_POSSTARI:
707    case OP_POSPLUSI:    case OP_POSPLUSI:
708    case OP_POSQUERYI:    case OP_POSQUERYI:
709      case OP_POSUPTOI:
710    case OP_NOTSTAR:    case OP_NOTSTAR:
711    case OP_NOTMINSTAR:    case OP_NOTMINSTAR:
712    case OP_NOTPLUS:    case OP_NOTPLUS:
713    case OP_NOTMINPLUS:    case OP_NOTMINPLUS:
714    case OP_NOTQUERY:    case OP_NOTQUERY:
715    case OP_NOTMINQUERY:    case OP_NOTMINQUERY:
716      case OP_NOTUPTO:
717      case OP_NOTMINUPTO:
718      case OP_NOTEXACT:
719    case OP_NOTPOSSTAR:    case OP_NOTPOSSTAR:
720    case OP_NOTPOSPLUS:    case OP_NOTPOSPLUS:
721    case OP_NOTPOSQUERY:    case OP_NOTPOSQUERY:
722      case OP_NOTPOSUPTO:
723    case OP_NOTSTARI:    case OP_NOTSTARI:
724    case OP_NOTMINSTARI:    case OP_NOTMINSTARI:
725    case OP_NOTPLUSI:    case OP_NOTPLUSI:
726    case OP_NOTMINPLUSI:    case OP_NOTMINPLUSI:
727    case OP_NOTQUERYI:    case OP_NOTQUERYI:
728    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:  
729    case OP_NOTUPTOI:    case OP_NOTUPTOI:
730    case OP_NOTMINUPTOI:    case OP_NOTMINUPTOI:
731    case OP_NOTEXACTI:    case OP_NOTEXACTI:
732      case OP_NOTPOSSTARI:
733      case OP_NOTPOSPLUSI:
734      case OP_NOTPOSQUERYI:
735    case OP_NOTPOSUPTOI:    case OP_NOTPOSUPTOI:
736    cc += 2 + IMM2_SIZE;    cc += PRIV(OP_lengths)[*cc];
737  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
738    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);    if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
739  #endif  #endif
740    return cc;    return cc;
741    
742    case OP_NOTPROP:    /* Special cases. */
743    case OP_PROP:    case OP_TYPESTAR:
744    return cc + 1 + 2;    case OP_TYPEMINSTAR:
745      case OP_TYPEPLUS:
746      case OP_TYPEMINPLUS:
747      case OP_TYPEQUERY:
748      case OP_TYPEMINQUERY:
749    case OP_TYPEUPTO:    case OP_TYPEUPTO:
750    case OP_TYPEMINUPTO:    case OP_TYPEMINUPTO:
751    case OP_TYPEEXACT:    case OP_TYPEEXACT:
752      case OP_TYPEPOSSTAR:
753      case OP_TYPEPOSPLUS:
754      case OP_TYPEPOSQUERY:
755    case OP_TYPEPOSUPTO:    case OP_TYPEPOSUPTO:
756    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;  
757    
758    case OP_CRRANGE:    case OP_ANYBYTE:
759    case OP_CRMINRANGE:  #ifdef SUPPORT_UTF
760    return cc + 1 + 2 * IMM2_SIZE;    if (common->utf) return NULL;
761    #endif
762    case OP_CLASS:    return cc + 1;
   case OP_NCLASS:  
   return cc + 1 + 32 / sizeof(pcre_uchar);  
763    
764  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
765    case OP_XCLASS:    case OP_XCLASS:
766    return cc + GET(cc, 1);    return cc + GET(cc, 1);
767  #endif  #endif
768    
   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;  
   
769    case OP_MARK:    case OP_MARK:
770      case OP_PRUNE_ARG:
771      case OP_SKIP_ARG:
772      case OP_THEN_ARG:
773    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
774    
775    default:    default:
776      /* All opcodes are supported now! */
777      SLJIT_ASSERT_STOP();
778    return NULL;    return NULL;
779    }    }
780  }  }
781    
782  #define CASE_ITERATOR_PRIVATE_DATA_1 \  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
783      case OP_MINSTAR: \  {
784      case OP_MINPLUS: \  int count;
785      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:  
786    
787  #define CASE_ITERATOR_PRIVATE_DATA_2A \  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
788      case OP_STAR: \  while (cc < ccend)
789      case OP_PLUS: \    {
790      case OP_STARI: \    switch(*cc)
791      case OP_PLUSI: \      {
792      case OP_NOTSTAR: \      case OP_SET_SOM:
793      case OP_NOTPLUS: \      common->has_set_som = TRUE;
794      case OP_NOTSTARI: \      common->might_be_empty = TRUE;
795      case OP_NOTPLUSI:      cc += 1;
796        break;
797    
798  #define CASE_ITERATOR_PRIVATE_DATA_2B \      case OP_REF:
799      case OP_UPTO: \      case OP_REFI:
800      case OP_MINUPTO: \      common->optimized_cbracket[GET2(cc, 1)] = 0;
801      case OP_UPTOI: \      cc += 1 + IMM2_SIZE;
802      case OP_MINUPTOI: \      break;
     case OP_NOTUPTO: \  
     case OP_NOTMINUPTO: \  
     case OP_NOTUPTOI: \  
     case OP_NOTMINUPTOI:  
803    
804  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \      case OP_BRA:
805      case OP_TYPEMINSTAR: \      case OP_CBRA:
806      case OP_TYPEMINPLUS: \      case OP_SBRA:
807      case OP_TYPEQUERY: \      case OP_SCBRA:
808      case OP_TYPEMINQUERY:      count = no_alternatives(cc);
809        if (count > 4)
810          common->read_only_data_size += count * sizeof(sljit_uw);
811        cc += 1 + LINK_SIZE + (*cc == OP_CBRA || *cc == OP_SCBRA ? IMM2_SIZE : 0);
812        break;
813    
814  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \      case OP_CBRAPOS:
815      case OP_TYPESTAR: \      case OP_SCBRAPOS:
816      case OP_TYPEPLUS:      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
817        cc += 1 + LINK_SIZE + IMM2_SIZE;
818        break;
819    
820  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \      case OP_COND:
821      case OP_TYPEUPTO: \      case OP_SCOND:
822      case OP_TYPEMINUPTO:      /* Only AUTO_CALLOUT can insert this opcode. We do
823           not intend to support this case. */
824        if (cc[1 + LINK_SIZE] == OP_CALLOUT)
825          return FALSE;
826        cc += 1 + LINK_SIZE;
827        break;
828    
829        case OP_CREF:
830        common->optimized_cbracket[GET2(cc, 1)] = 0;
831        cc += 1 + IMM2_SIZE;
832        break;
833    
834        case OP_DNREF:
835        case OP_DNREFI:
836        case OP_DNCREF:
837        count = GET2(cc, 1 + IMM2_SIZE);
838        slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
839        while (count-- > 0)
840          {
841          common->optimized_cbracket[GET2(slot, 0)] = 0;
842          slot += common->name_entry_size;
843          }
844        cc += 1 + 2 * IMM2_SIZE;
845        break;
846    
847        case OP_RECURSE:
848        /* Set its value only once. */
849        if (common->recursive_head_ptr == 0)
850          {
851          common->recursive_head_ptr = common->ovector_start;
852          common->ovector_start += sizeof(sljit_sw);
853          }
854        cc += 1 + LINK_SIZE;
855        break;
856    
857        case OP_CALLOUT:
858        if (common->capture_last_ptr == 0)
859          {
860          common->capture_last_ptr = common->ovector_start;
861          common->ovector_start += sizeof(sljit_sw);
862          }
863        cc += 2 + 2 * LINK_SIZE;
864        break;
865    
866        case OP_THEN_ARG:
867        common->has_then = TRUE;
868        common->control_head_ptr = 1;
869        /* Fall through. */
870    
871        case OP_PRUNE_ARG:
872        common->needs_start_ptr = TRUE;
873        /* Fall through. */
874    
875        case OP_MARK:
876        if (common->mark_ptr == 0)
877          {
878          common->mark_ptr = common->ovector_start;
879          common->ovector_start += sizeof(sljit_sw);
880          }
881        cc += 1 + 2 + cc[1];
882        break;
883    
884        case OP_THEN:
885        common->has_then = TRUE;
886        common->control_head_ptr = 1;
887        /* Fall through. */
888    
889        case OP_PRUNE:
890        case OP_SKIP:
891        common->needs_start_ptr = TRUE;
892        cc += 1;
893        break;
894    
895        case OP_SKIP_ARG:
896        common->control_head_ptr = 1;
897        common->has_skip_arg = TRUE;
898        cc += 1 + 2 + cc[1];
899        break;
900    
901        default:
902        cc = next_opcode(common, cc);
903        if (cc == NULL)
904          return FALSE;
905        break;
906        }
907      }
908    return TRUE;
909    }
910    
911  static int get_class_iterator_size(pcre_uchar *cc)  static int get_class_iterator_size(pcre_uchar *cc)
912  {  {
# Line 758  switch(*cc) Line 933  switch(*cc)
933    }    }
934  }  }
935    
936  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)
937  {  {
938  int private_data_length = 0;  pcre_uchar *end = bracketend(begin);
939  pcre_uchar *alternative;  pcre_uchar *next;
940  pcre_uchar *name;  pcre_uchar *next_end;
941  pcre_uchar *end = NULL;  pcre_uchar *max_end;
942  int space, size, bracketlen, i;  pcre_uchar type;
943    sljit_sw length = end - begin;
944    int min, max, i;
945    
946  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  /* Detect fixed iterations first. */
947  while (cc < ccend)  if (end[-(1 + LINK_SIZE)] != OP_KET)
948      return FALSE;
949    
950    /* Already detected repeat. */
951    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
952      return TRUE;
953    
954    next = end;
955    min = 1;
956    while (1)
957    {    {
958    space = 0;    if (*next != *begin)
   size = 0;  
   bracketlen = 0;  
   switch(*cc)  
     {  
     case OP_SET_SOM:  
     common->has_set_som = TRUE;  
     cc += 1;  
959      break;      break;
960      next_end = bracketend(next);
961      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;  
962      break;      break;
963      next = next_end;
964      min++;
965      }
966    
967      case OP_ASSERT:  if (min == 2)
968      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_w);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
969    
970      case OP_CBRAPOS:  max = 0;
971      case OP_SCBRAPOS:  max_end = next;
972      private_data_length += sizeof(sljit_w);  if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
973      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;    {
974      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;    type = *next;
975      break;    while (1)
976        {
977        if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
978          break;
979        next_end = bracketend(next + 2 + LINK_SIZE);
980        if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
981          break;
982        next = next_end;
983        max++;
984        }
985    
986      case OP_COND:    if (next[0] == type && next[1] == *begin && max >= 1)
987      case OP_SCOND:      {
988      bracketlen = cc[1 + LINK_SIZE];      next_end = bracketend(next + 1);
989      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)  
990        {        {
991        bracketlen = GET2(cc, 1 + LINK_SIZE + 1);        for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
992        name = (pcre_uchar *)common->name_table;          if (*next_end != OP_KET)
993        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);  
994    
995        for (i = 0; i < common->name_count; i++)        if (i == max)
996          {          {
997          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;
998            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;
999          alternative += common->name_entry_size;          /* +2 the original and the last. */
1000            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
1001            if (min == 1)
1002              return TRUE;
1003            min--;
1004            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
1005          }          }
1006        }        }
1007        }
1008      }
1009    
1010      if (*cc == OP_COND)  if (min >= 3)
1011        {    {
1012        /* Might be a hidden SCOND. */    common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
1013        alternative = cc + GET(cc, 1);    common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
1014        if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)    common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
1015          private_data_length += sizeof(sljit_w);    return TRUE;
1016        }    }
     else  
       private_data_length += sizeof(sljit_w);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_BRA:  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
     case OP_CBRA:  
     case OP_SCBRA:  
     bracketlen = 1 + LINK_SIZE + IMM2_SIZE;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_1  
     space = 1;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_2A  
     space = 2;  
     size = -2;  
     break;  
   
     CASE_ITERATOR_PRIVATE_DATA_2B  
     space = 2;  
     size = -(2 + IMM2_SIZE);  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_1  
     space = 1;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_2A  
     if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)  
       space = 2;  
     size = 1;  
     break;  
   
     CASE_ITERATOR_TYPE_PRIVATE_DATA_2B  
     if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)  
       space = 2;  
     size = 1 + IMM2_SIZE;  
     break;  
   
     case OP_CLASS:  
     case OP_NCLASS:  
     size += 1 + 32 / sizeof(pcre_uchar);  
     space = get_class_iterator_size(cc + size);  
     break;  
1017    
1018  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  return FALSE;
1019      case OP_XCLASS:  }
     size = GET(cc, 1);  
     space = get_class_iterator_size(cc + size);  
     break;  
 #endif  
1020    
1021      case OP_RECURSE:  #define CASE_ITERATOR_PRIVATE_DATA_1 \
1022      /* Set its value only once. */      case OP_MINSTAR: \
1023      if (common->recursive_head == 0)      case OP_MINPLUS: \
1024        {      case OP_QUERY: \
1025        common->recursive_head = common->ovector_start;      case OP_MINQUERY: \
1026        common->ovector_start += sizeof(sljit_w);      case OP_MINSTARI: \
1027        }      case OP_MINPLUSI: \
1028      cc += 1 + LINK_SIZE;      case OP_QUERYI: \
1029      break;      case OP_MINQUERYI: \
1030        case OP_NOTMINSTAR: \
1031        case OP_NOTMINPLUS: \
1032        case OP_NOTQUERY: \
1033        case OP_NOTMINQUERY: \
1034        case OP_NOTMINSTARI: \
1035        case OP_NOTMINPLUSI: \
1036        case OP_NOTQUERYI: \
1037        case OP_NOTMINQUERYI:
1038    
1039      case OP_MARK:  #define CASE_ITERATOR_PRIVATE_DATA_2A \
1040      if (common->mark_ptr == 0)      case OP_STAR: \
1041        {      case OP_PLUS: \
1042        common->mark_ptr = common->ovector_start;      case OP_STARI: \
1043        common->ovector_start += sizeof(sljit_w);      case OP_PLUSI: \
1044        }      case OP_NOTSTAR: \
1045      cc += 1 + 2 + cc[1];      case OP_NOTPLUS: \
1046      break;      case OP_NOTSTARI: \
1047        case OP_NOTPLUSI:
1048    
1049      default:  #define CASE_ITERATOR_PRIVATE_DATA_2B \
1050      cc = next_opcode(common, cc);      case OP_UPTO: \
1051      if (cc == NULL)      case OP_MINUPTO: \
1052        return -1;      case OP_UPTOI: \
1053      break;      case OP_MINUPTOI: \
1054      }      case OP_NOTUPTO: \
1055        case OP_NOTMINUPTO: \
1056        case OP_NOTUPTOI: \
1057        case OP_NOTMINUPTOI:
1058    
1059    if (space > 0 && cc >= end)  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1060      private_data_length += sizeof(sljit_w) * space;      case OP_TYPEMINSTAR: \
1061        case OP_TYPEMINPLUS: \
1062        case OP_TYPEQUERY: \
1063        case OP_TYPEMINQUERY:
1064    
1065    if (size != 0)  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1066      {      case OP_TYPESTAR: \
1067      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;  
     }  
1068    
1069    if (bracketlen > 0)  #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1070      {      case OP_TYPEUPTO: \
1071      if (cc >= end)      case OP_TYPEMINUPTO:
       {  
       end = bracketend(cc);  
       if (end[-1 - LINK_SIZE] == OP_KET)  
         end = NULL;  
       }  
     cc += bracketlen;  
     }  
   }  
 return private_data_length;  
 }  
1072    
1073  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)
1074  {  {
1075  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1076  pcre_uchar *alternative;  pcre_uchar *alternative;
1077  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1078    int private_data_ptr = *private_data_start;
1079  int space, size, bracketlen;  int space, size, bracketlen;
1080    
1081  while (cc < ccend)  while (cc < ccend)
# Line 967  while (cc < ccend) Line 1083  while (cc < ccend)
1083    space = 0;    space = 0;
1084    size = 0;    size = 0;
1085    bracketlen = 0;    bracketlen = 0;
1086      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1087        return;
1088    
1089      if (*cc == OP_ONCE || *cc == OP_ONCE_NC || *cc == OP_BRA || *cc == OP_CBRA || *cc == OP_COND)
1090        if (detect_repeat(common, cc))
1091          {
1092          /* These brackets are converted to repeats, so no global
1093          based single character repeat is allowed. */
1094          if (cc >= end)
1095            end = bracketend(cc);
1096          }
1097    
1098    switch(*cc)    switch(*cc)
1099      {      {
1100        case OP_KET:
1101        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1102          {
1103          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1104          private_data_ptr += sizeof(sljit_sw);
1105          cc += common->private_data_ptrs[cc + 1 - common->start];
1106          }
1107        cc += 1 + LINK_SIZE;
1108        break;
1109    
1110      case OP_ASSERT:      case OP_ASSERT:
1111      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1112      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 980  while (cc < ccend) Line 1118  while (cc < ccend)
1118      case OP_SBRAPOS:      case OP_SBRAPOS:
1119      case OP_SCOND:      case OP_SCOND:
1120      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1121      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1122      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1123      break;      break;
1124    
1125      case OP_CBRAPOS:      case OP_CBRAPOS:
1126      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1127      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1128      private_data_ptr += sizeof(sljit_w);      private_data_ptr += sizeof(sljit_sw);
1129      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
1130      break;      break;
1131    
# Line 997  while (cc < ccend) Line 1135  while (cc < ccend)
1135      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
1136        {        {
1137        common->private_data_ptrs[cc - common->start] = private_data_ptr;        common->private_data_ptrs[cc - common->start] = private_data_ptr;
1138        private_data_ptr += sizeof(sljit_w);        private_data_ptr += sizeof(sljit_sw);
1139        }        }
1140      bracketlen = 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
1141      break;      break;
# Line 1062  while (cc < ccend) Line 1200  while (cc < ccend)
1200      break;      break;
1201      }      }
1202    
1203      /* Character iterators, which are not inside a repeated bracket,
1204         gets a private slot instead of allocating it on the stack. */
1205    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1206      {      {
1207      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
1208      private_data_ptr += sizeof(sljit_w) * space;      private_data_ptr += sizeof(sljit_sw) * space;
1209      }      }
1210    
1211    if (size != 0)    if (size != 0)
# Line 1092  while (cc < ccend) Line 1232  while (cc < ccend)
1232      cc += bracketlen;      cc += bracketlen;
1233      }      }
1234    }    }
1235    *private_data_start = private_data_ptr;
1236  }  }
1237    
1238  /* Returns with -1 if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1239  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)
1240  {  {
 pcre_uchar *ccend = bracketend(cc);  
1241  int length = 0;  int length = 0;
1242  BOOL possessive = FALSE;  int possessive = 0;
1243    BOOL stack_restore = FALSE;
1244  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1245  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1246    /* The last capture is a local variable even for recursions. */
1247    BOOL capture_last_found = FALSE;
1248    
1249    #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1250    SLJIT_ASSERT(common->control_head_ptr != 0);
1251    *needs_control_head = TRUE;
1252    #else
1253    *needs_control_head = FALSE;
1254    #endif
1255    
1256  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (ccend == NULL)
1257    {    {
1258    length = 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1259    possessive = TRUE;    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1260        {
1261        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1262        /* This is correct regardless of common->capture_last_ptr. */
1263        capture_last_found = TRUE;
1264        }
1265      cc = next_opcode(common, cc);
1266    }    }
1267    
 cc = next_opcode(common, cc);  
1268  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1269  while (cc < ccend)  while (cc < ccend)
1270    switch(*cc)    switch(*cc)
1271      {      {
1272      case OP_SET_SOM:      case OP_SET_SOM:
1273      SLJIT_ASSERT(common->has_set_som);      SLJIT_ASSERT(common->has_set_som);
1274        stack_restore = TRUE;
1275      if (!setsom_found)      if (!setsom_found)
1276        {        {
1277        length += 2;        length += 2;
# Line 1125  while (cc < ccend) Line 1281  while (cc < ccend)
1281      break;      break;
1282    
1283      case OP_MARK:      case OP_MARK:
1284        case OP_PRUNE_ARG:
1285        case OP_THEN_ARG:
1286      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1287        stack_restore = TRUE;
1288      if (!setmark_found)      if (!setmark_found)
1289        {        {
1290        length += 2;        length += 2;
1291        setmark_found = TRUE;        setmark_found = TRUE;
1292        }        }
1293        if (common->control_head_ptr != 0)
1294          *needs_control_head = TRUE;
1295      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1296      break;      break;
1297    
1298      case OP_RECURSE:      case OP_RECURSE:
1299        stack_restore = TRUE;
1300      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1301        {        {
1302        length += 2;        length += 2;
# Line 1145  while (cc < ccend) Line 1307  while (cc < ccend)
1307        length += 2;        length += 2;
1308        setmark_found = TRUE;        setmark_found = TRUE;
1309        }        }
1310        if (common->capture_last_ptr != 0 && !capture_last_found)
1311          {
1312          length += 2;
1313          capture_last_found = TRUE;
1314          }
1315      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1316      break;      break;
1317    
# Line 1152  while (cc < ccend) Line 1319  while (cc < ccend)
1319      case OP_CBRAPOS:      case OP_CBRAPOS:
1320      case OP_SCBRA:      case OP_SCBRA:
1321      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1322        stack_restore = TRUE;
1323        if (common->capture_last_ptr != 0 && !capture_last_found)
1324          {
1325          length += 2;
1326          capture_last_found = TRUE;
1327          }
1328      length += 3;      length += 3;
1329      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1330      break;      break;
1331    
1332      default:      default:
1333        stack_restore = TRUE;
1334        /* Fall through. */
1335    
1336        case OP_NOT_WORD_BOUNDARY:
1337        case OP_WORD_BOUNDARY:
1338        case OP_NOT_DIGIT:
1339        case OP_DIGIT:
1340        case OP_NOT_WHITESPACE:
1341        case OP_WHITESPACE:
1342        case OP_NOT_WORDCHAR:
1343        case OP_WORDCHAR:
1344        case OP_ANY:
1345        case OP_ALLANY:
1346        case OP_ANYBYTE:
1347        case OP_NOTPROP:
1348        case OP_PROP:
1349        case OP_ANYNL:
1350        case OP_NOT_HSPACE:
1351        case OP_HSPACE:
1352        case OP_NOT_VSPACE:
1353        case OP_VSPACE:
1354        case OP_EXTUNI:
1355        case OP_EODN:
1356        case OP_EOD:
1357        case OP_CIRC:
1358        case OP_CIRCM:
1359        case OP_DOLL:
1360        case OP_DOLLM:
1361        case OP_CHAR:
1362        case OP_CHARI:
1363        case OP_NOT:
1364        case OP_NOTI:
1365    
1366        case OP_EXACT:
1367        case OP_POSSTAR:
1368        case OP_POSPLUS:
1369        case OP_POSQUERY:
1370        case OP_POSUPTO:
1371    
1372        case OP_EXACTI:
1373        case OP_POSSTARI:
1374        case OP_POSPLUSI:
1375        case OP_POSQUERYI:
1376        case OP_POSUPTOI:
1377    
1378        case OP_NOTEXACT:
1379        case OP_NOTPOSSTAR:
1380        case OP_NOTPOSPLUS:
1381        case OP_NOTPOSQUERY:
1382        case OP_NOTPOSUPTO:
1383    
1384        case OP_NOTEXACTI:
1385        case OP_NOTPOSSTARI:
1386        case OP_NOTPOSPLUSI:
1387        case OP_NOTPOSQUERYI:
1388        case OP_NOTPOSUPTOI:
1389    
1390        case OP_TYPEEXACT:
1391        case OP_TYPEPOSSTAR:
1392        case OP_TYPEPOSPLUS:
1393        case OP_TYPEPOSQUERY:
1394        case OP_TYPEPOSUPTO:
1395    
1396        case OP_CLASS:
1397        case OP_NCLASS:
1398        case OP_XCLASS:
1399    
1400      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1401      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1402      break;      break;
1403      }      }
1404    
1405  /* Possessive quantifiers can use a special case. */  /* Possessive quantifiers can use a special case. */
1406  if (SLJIT_UNLIKELY(possessive) && length == 3)  if (SLJIT_UNLIKELY(possessive == length))
1407    return -1;    return stack_restore ? no_frame : no_stack;
1408    
1409  if (length > 0)  if (length > 0)
1410    return length + 1;    return length + 1;
1411  return -1;  return stack_restore ? no_frame : no_stack;
1412  }  }
1413    
1414  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)
1415  {  {
1416  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc);  
1417  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1418  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1419    /* The last capture is a local variable even for recursions. */
1420    BOOL capture_last_found = FALSE;
1421  int offset;  int offset;
1422    
1423  /* >= 1 + shortest item size (2) */  /* >= 1 + shortest item size (2) */
# Line 1184  SLJIT_UNUSED_ARG(stacktop); Line 1425  SLJIT_UNUSED_ARG(stacktop);
1425  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1426    
1427  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1428  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1429    cc = next_opcode(common, cc);    {
1430      ccend = bracketend(cc) - (1 + LINK_SIZE);
1431      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1432        cc = next_opcode(common, cc);
1433      }
1434    
1435  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1436  while (cc < ccend)  while (cc < ccend)
1437    switch(*cc)    switch(*cc)
# Line 1195  while (cc < ccend) Line 1441  while (cc < ccend)
1441      if (!setsom_found)      if (!setsom_found)
1442        {        {
1443        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1444        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1445        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1446        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1447        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1448        setsom_found = TRUE;        setsom_found = TRUE;
1449        }        }
1450      cc += 1;      cc += 1;
1451      break;      break;
1452    
1453      case OP_MARK:      case OP_MARK:
1454        case OP_PRUNE_ARG:
1455        case OP_THEN_ARG:
1456      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1457      if (!setmark_found)      if (!setmark_found)
1458        {        {
1459        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);
1460        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);
1461        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1462        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1463        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1464        setmark_found = TRUE;        setmark_found = TRUE;
1465        }        }
1466      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
# Line 1222  while (cc < ccend) Line 1470  while (cc < ccend)
1470      if (common->has_set_som && !setsom_found)      if (common->has_set_som && !setsom_found)
1471        {        {
1472        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
1473        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_setstrbegin);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -OVECTOR(0));
1474        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1475        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1476        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1477        setsom_found = TRUE;        setsom_found = TRUE;
1478        }        }
1479      if (common->mark_ptr != 0 && !setmark_found)      if (common->mark_ptr != 0 && !setmark_found)
1480        {        {
1481        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);
1482        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);
1483        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1484        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1485        stackpos += (int)sizeof(sljit_w);        stackpos += (int)sizeof(sljit_sw);
1486        setmark_found = TRUE;        setmark_found = TRUE;
1487        }        }
1488        if (common->capture_last_ptr != 0 && !capture_last_found)
1489          {
1490          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1491          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1492          stackpos += (int)sizeof(sljit_sw);
1493          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1494          stackpos += (int)sizeof(sljit_sw);
1495          capture_last_found = TRUE;
1496          }
1497      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1498      break;      break;
1499    
# Line 1244  while (cc < ccend) Line 1501  while (cc < ccend)
1501      case OP_CBRAPOS:      case OP_CBRAPOS:
1502      case OP_SCBRA:      case OP_SCBRA:
1503      case OP_SCBRAPOS:      case OP_SCBRAPOS:
1504        if (common->capture_last_ptr != 0 && !capture_last_found)
1505          {
1506          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
1507          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, -common->capture_last_ptr);
1508          stackpos += (int)sizeof(sljit_sw);
1509          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1510          stackpos += (int)sizeof(sljit_sw);
1511          capture_last_found = TRUE;
1512          }
1513      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;      offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
1514      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, OVECTOR(offset));
1515      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1516      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
1517      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
1518      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP1, 0);
1519      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1520      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, TMP2, 0);
1521      stackpos += (int)sizeof(sljit_w);      stackpos += (int)sizeof(sljit_sw);
1522    
1523      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1524      break;      break;
# Line 1263  while (cc < ccend) Line 1529  while (cc < ccend)
1529      break;      break;
1530      }      }
1531    
1532  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, frame_end);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackpos, SLJIT_IMM, 0);
1533  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1534  }  }
1535    
1536  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)
1537  {  {
1538  int private_data_length = 2;  int private_data_length = needs_control_head ? 3 : 2;
1539  int size;  int size;
1540  pcre_uchar *alternative;  pcre_uchar *alternative;
1541  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1278  while (cc < ccend) Line 1544  while (cc < ccend)
1544    size = 0;    size = 0;
1545    switch(*cc)    switch(*cc)
1546      {      {
1547        case OP_KET:
1548        if (PRIVATE_DATA(cc) != 0)
1549          private_data_length++;
1550        cc += 1 + LINK_SIZE;
1551        break;
1552    
1553      case OP_ASSERT:      case OP_ASSERT:
1554      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1555      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1382  return private_data_length; Line 1654  return private_data_length;
1654  }  }
1655    
1656  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,
1657    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1658  {  {
1659  DEFINE_COMPILER;  DEFINE_COMPILER;
1660  int srcw[2];  int srcw[2];
# Line 1403  stacktop = STACK(stacktop - 1); Line 1675  stacktop = STACK(stacktop - 1);
1675    
1676  if (!save)  if (!save)
1677    {    {
1678    stackptr += sizeof(sljit_w);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1679    if (stackptr < stacktop)    if (stackptr < stacktop)
1680      {      {
1681      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1682      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1683      tmp1empty = FALSE;      tmp1empty = FALSE;
1684      }      }
1685    if (stackptr < stacktop)    if (stackptr < stacktop)
1686      {      {
1687      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1688      stackptr += sizeof(sljit_w);      stackptr += sizeof(sljit_sw);
1689      tmp2empty = FALSE;      tmp2empty = FALSE;
1690      }      }
1691    /* The tmp1next must be TRUE in either way. */    /* The tmp1next must be TRUE in either way. */
1692    }    }
1693    
1694  while (status != end)  do
1695    {    {
1696    count = 0;    count = 0;
1697    switch(status)    switch(status)
1698      {      {
1699      case start:      case start:
1700      SLJIT_ASSERT(save && common->recursive_head != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1701      count = 1;      count = 1;
1702      srcw[0] = common->recursive_head;      srcw[0] = common->recursive_head_ptr;
1703        if (needs_control_head)
1704          {
1705          SLJIT_ASSERT(common->control_head_ptr != 0);
1706          count = 2;
1707          srcw[1] = common->control_head_ptr;
1708          }
1709      status = loop;      status = loop;
1710      break;      break;
1711    
# Line 1440  while (status != end) Line 1718  while (status != end)
1718    
1719      switch(*cc)      switch(*cc)
1720        {        {
1721          case OP_KET:
1722          if (PRIVATE_DATA(cc) != 0)
1723            {
1724            count = 1;
1725            srcw[0] = PRIVATE_DATA(cc);
1726            }
1727          cc += 1 + LINK_SIZE;
1728          break;
1729    
1730        case OP_ASSERT:        case OP_ASSERT:
1731        case OP_ASSERT_NOT:        case OP_ASSERT_NOT:
1732        case OP_ASSERTBACK:        case OP_ASSERTBACK:
# Line 1504  while (status != end) Line 1791  while (status != end)
1791          {          {
1792          count = 2;          count = 2;
1793          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1794          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1795          }          }
1796        cc += 2;        cc += 2;
1797  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1517  while (status != end) Line 1804  while (status != end)
1804          {          {
1805          count = 2;          count = 2;
1806          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1807          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_w);          srcw[1] = PRIVATE_DATA(cc) + sizeof(sljit_sw);
1808          }          }
1809        cc += 2 + IMM2_SIZE;        cc += 2 + IMM2_SIZE;
1810  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 1539  while (status != end) Line 1826  while (status != end)
1826          {          {
1827          count = 2;          count = 2;
1828          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1829          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1830          }          }
1831        cc += 1;        cc += 1;
1832        break;        break;
# Line 1549  while (status != end) Line 1836  while (status != end)
1836          {          {
1837          count = 2;          count = 2;
1838          srcw[0] = PRIVATE_DATA(cc);          srcw[0] = PRIVATE_DATA(cc);
1839          srcw[1] = srcw[0] + sizeof(sljit_w);          srcw[1] = srcw[0] + sizeof(sljit_sw);
1840          }          }
1841        cc += 1 + IMM2_SIZE;        cc += 1 + IMM2_SIZE;
1842        break;        break;
# Line 1573  while (status != end) Line 1860  while (status != end)
1860            case 2:            case 2:
1861            count = 2;            count = 2;
1862            srcw[0] = PRIVATE_DATA(cc);            srcw[0] = PRIVATE_DATA(cc);
1863            srcw[1] = srcw[0] + sizeof(sljit_w);            srcw[1] = srcw[0] + sizeof(sljit_sw);
1864            break;            break;
1865    
1866            default:            default:
# Line 1605  while (status != end) Line 1892  while (status != end)
1892          if (!tmp1empty)          if (!tmp1empty)
1893            {            {
1894            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1895            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1896            }            }
1897          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1898          tmp1empty = FALSE;          tmp1empty = FALSE;
# Line 1616  while (status != end) Line 1903  while (status != end)
1903          if (!tmp2empty)          if (!tmp2empty)
1904            {            {
1905            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);            OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1906            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1907            }            }
1908          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), srcw[count]);
1909          tmp2empty = FALSE;          tmp2empty = FALSE;
# Line 1633  while (status != end) Line 1920  while (status != end)
1920          if (!tmp1empty)          if (!tmp1empty)
1921            {            {
1922            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1923            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1924            }            }
1925          tmp1next = FALSE;          tmp1next = FALSE;
1926          }          }
# Line 1645  while (status != end) Line 1932  while (status != end)
1932          if (!tmp2empty)          if (!tmp2empty)
1933            {            {
1934            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), stackptr);
1935            stackptr += sizeof(sljit_w);            stackptr += sizeof(sljit_sw);
1936            }            }
1937          tmp1next = TRUE;          tmp1next = TRUE;
1938          }          }
1939        }        }
1940      }      }
1941    }    }
1942    while (status != end);
1943    
1944  if (save)  if (save)
1945    {    {
# Line 1660  if (save) Line 1948  if (save)
1948      if (!tmp1empty)      if (!tmp1empty)
1949        {        {
1950        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1951        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1952        }        }
1953      if (!tmp2empty)      if (!tmp2empty)
1954        {        {
1955        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1956        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1957        }        }
1958      }      }
1959    else    else
# Line 1673  if (save) Line 1961  if (save)
1961      if (!tmp2empty)      if (!tmp2empty)
1962        {        {
1963        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP2, 0);
1964        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1965        }        }
1966      if (!tmp1empty)      if (!tmp1empty)
1967        {        {
1968        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), stackptr, TMP1, 0);
1969        stackptr += sizeof(sljit_w);        stackptr += sizeof(sljit_sw);
1970        }        }
1971      }      }
1972    }    }
1973  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1974  }  }
1975    
1976    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1977    {
1978    pcre_uchar *end = bracketend(cc);
1979    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1980    
1981    /* Assert captures then. */
1982    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1983      current_offset = NULL;
1984    /* Conditional block does not. */
1985    if (*cc == OP_COND || *cc == OP_SCOND)
1986      has_alternatives = FALSE;
1987    
1988    cc = next_opcode(common, cc);
1989    if (has_alternatives)
1990      current_offset = common->then_offsets + (cc - common->start);
1991    
1992    while (cc < end)
1993      {
1994      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1995        cc = set_then_offsets(common, cc, current_offset);
1996      else
1997        {
1998        if (*cc == OP_ALT && has_alternatives)
1999          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
2000        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
2001          *current_offset = 1;
2002        cc = next_opcode(common, cc);
2003        }
2004      }
2005    
2006    return end;
2007    }
2008    
2009  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
2010  #undef CASE_ITERATOR_PRIVATE_DATA_2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
2011  #undef CASE_ITERATOR_PRIVATE_DATA_2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
# Line 1692  SLJIT_ASSERT(cc == ccend && stackptr == Line 2013  SLJIT_ASSERT(cc == ccend && stackptr ==
2013  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2A
2014  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B  #undef CASE_ITERATOR_TYPE_PRIVATE_DATA_2B
2015    
2016  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  static SLJIT_INLINE BOOL is_powerof2(unsigned int value)
2017  {  {
2018  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
2019  }  }
# Line 1703  while (list) Line 2024  while (list)
2024    {    {
2025    /* sljit_set_label is clever enough to do nothing    /* sljit_set_label is clever enough to do nothing
2026    if either the jump or the label is NULL. */    if either the jump or the label is NULL. */
2027    sljit_set_label(list->jump, label);    SET_LABEL(list->jump, label);
2028    list = list->next;    list = list->next;
2029    }    }
2030  }  }
# Line 1719  if (list_item) Line 2040  if (list_item)
2040    }    }
2041  }  }
2042    
2043  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)
2044  {  {
2045  DEFINE_COMPILER;  DEFINE_COMPILER;
2046  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));  stub_list* list_item = sljit_alloc_memory(compiler, sizeof(stub_list));
2047    
2048  if (list_item)  if (list_item)
2049    {    {
   list_item->type = type;  
   list_item->data = data;  
2050    list_item->start = start;    list_item->start = start;
2051    list_item->quit = LABEL();    list_item->quit = LABEL();
2052    list_item->next = common->stubs;    list_item->next = common->stubs;
# Line 1743  stub_list* list_item = common->stubs; Line 2062  stub_list* list_item = common->stubs;
2062  while (list_item)  while (list_item)
2063    {    {
2064    JUMPHERE(list_item->start);    JUMPHERE(list_item->start);
2065    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;  
     }  
2066    JUMPTO(SLJIT_JUMP, list_item->quit);    JUMPTO(SLJIT_JUMP, list_item->quit);
2067    list_item = list_item->next;    list_item = list_item->next;
2068    }    }
2069  common->stubs = NULL;  common->stubs = NULL;
2070  }  }
2071    
2072  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static void add_label_addr(compiler_common *common)
2073  {  {
2074  DEFINE_COMPILER;  DEFINE_COMPILER;
2075    label_addr_list *label_addr;
2076    
2077  OP2(SLJIT_SUB | SLJIT_SET_E, CALL_COUNT, 0, CALL_COUNT, 0, SLJIT_IMM, 1);  label_addr = sljit_alloc_memory(compiler, sizeof(label_addr_list));
2078    if (label_addr == NULL)
2079      return;
2080    label_addr->label = LABEL();
2081    label_addr->addr = common->read_only_data_ptr;
2082    label_addr->next = common->label_addrs;
2083    common->label_addrs = label_addr;
2084    common->read_only_data_ptr++;
2085    }
2086    
2087    static SLJIT_INLINE void count_match(compiler_common *common)
2088    {
2089    DEFINE_COMPILER;
2090    
2091    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 1768  static SLJIT_INLINE void allocate_stack( Line 2097  static SLJIT_INLINE void allocate_stack(
2097  /* May destroy all locals and registers except TMP2. */  /* May destroy all locals and registers except TMP2. */
2098  DEFINE_COMPILER;  DEFINE_COMPILER;
2099    
2100  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w));  OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
2101  #ifdef DESTROY_REGISTERS  #ifdef DESTROY_REGISTERS
2102  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 12345);
2103  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);  OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
# Line 1776  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)
2112  {  {
2113  DEFINE_COMPILER;  DEFINE_COMPILER;
2114  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_w));  OP2(SLJIT_SUB, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, size * sizeof(sljit_sw));
2115  }  }
2116    
2117  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)  static SLJIT_INLINE void reset_ovector(compiler_common *common, int length)
# Line 1790  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_w));    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_w), 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_w));  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  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2227  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1);  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_w));    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_w)sizeof(sljit_w)));    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 1862  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  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2280  OP2(SLJIT_ASHR, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG2, 0, SLJIT_IMM, 1);  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  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2286  OP2(SLJIT_ASHR, SLJIT_TEMPORARY_REG3, 0, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, 1);  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 1998  if (c <= 127 && bit == 0x20) Line 2398  if (c <= 127 && bit == 0x20)
2398    return (0 << 8) | 0x20;    return (0 << 8) | 0x20;
2399    
2400  /* Since c != oc, they must have at least 1 bit difference. */  /* Since c != oc, they must have at least 1 bit difference. */
2401  if (!ispowerof2(bit))  if (!is_powerof2(bit))
2402    return 0;    return 0;
2403    
2404  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
2405    
2406  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2407  if (common->utf && c > 127)  if (common->utf && c > 127)
# Line 2017  if (common->utf && c > 127) Line 2417  if (common->utf && c > 127)
2417  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2418  return (0 << 8) | bit;  return (0 << 8) | bit;
2419    
2420  #else /* COMPILE_PCRE8 */  #elif defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2421    
 #ifdef COMPILE_PCRE16  
2422  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2423  if (common->utf && c > 65535)  if (common->utf && c > 65535)
2424    {    {
# Line 2030  if (common->utf && c > 65535) Line 2429  if (common->utf && c > 65535)
2429    }    }
2430  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
2431  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));  return (bit < 256) ? ((0 << 8) | bit) : ((1 << 8) | (bit >> 8));
 #endif /* COMPILE_PCRE16 */  
2432    
2433  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE[8|16|32] */
2434  }  }
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 2052  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 2065  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 2112  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 2125  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  #ifdef SUPPORT_UTF  #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  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && defined COMPILE_PCRE8
2538  if (common->utf)  if (common->utf)
2539    {    {
2540  #ifdef 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  #else    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
 #ifdef COMPILE_PCRE16  
   jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);  
 #endif  
 #endif /* COMPILE_PCRE8 */  
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);
2547      }
2548    #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);    JUMPHERE(jump);
2564    }    }
2565  #endif  #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  #ifdef SUPPORT_UTF  #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  #ifdef SUPPORT_UTF  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  #ifdef 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  #else    if (min >= 0x10000)
2641  #ifdef COMPILE_PCRE16      {
2642    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800);      OP2(SLJIT_SUB, TMP2, 0, TMP1, 0, SLJIT_IMM, 0xf0);
2643        if (update_str_ptr)
2644          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);
2706      }
2707  #endif  #endif
2708  #endif /* COMPILE_PCRE8 */  
2709    add_jump(compiler, &common->utfreadchar, JUMP(SLJIT_FAST_CALL));  #if defined SUPPORT_UTF && defined COMPILE_PCRE16
2710    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  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);    JUMPHERE(jump);
2737    }    }
2738  #endif  #endif
2739  }  }
2740    
2741  static void read_char8_type(compiler_common *common)  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, 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  #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));  
 #ifdef 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  #else      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
2772  #ifdef COMPILE_PCRE16      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2773    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);      OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2774    jump = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);      OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);
2775    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);      OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2776        OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
2777        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
2778        jump2 = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);
2779        OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2780        JUMPHERE(jump2);
2781        }
2782      else
2783        add_jump(compiler, &common->utfreadtype8, JUMP(SLJIT_FAST_CALL));
2784    JUMPHERE(jump);    JUMPHERE(jump);
   /* Skip low surrogate if necessary. */  
   OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0xfc00);  
   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0xd800);  
   COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);  
   OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);  
 #endif  
 #endif /* COMPILE_PCRE8 */  
2785    return;    return;
2786    }    }
2787  #endif  #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
 #ifdef COMPILE_PCRE16  
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  #ifdef COMPILE_PCRE16  #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)
2812  {  {
2813  /* Goes one character back. Affects STR_PTR and TMP1. Does not check begin. */  /* Goes one character back. Affects STR_PTR and TMP1. Does not check begin. */
2814  DEFINE_COMPILER;  DEFINE_COMPILER;
2815  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2816    #if defined COMPILE_PCRE8
2817  struct sljit_label *label;  struct sljit_label *label;
2818    
2819  if (common->utf)  if (common->utf)
# Line 2245  if (common->utf) Line 2825  if (common->utf)
2825    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0x80, label);
2826    return;    return;
2827    }    }
2828  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
2829  if (common->utf)  if (common->utf)
2830    {    {
2831    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), -IN_UCHARS(1));
# Line 2254  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;
2840    }    }
2841  #endif  #endif /* COMPILE_PCRE[8|16] */
2842    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
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    
2878  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2879    
2880  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
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. */
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x0f);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 12);  
 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(2));  
2913  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
2914  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
 OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(2));  
2915  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
 JUMPHERE(jump);  
2916    
2917  /* Four byte sequence. */  /* Four byte sequence. */
2918  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  JUMPHERE(jump);
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x07);  
 OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 18);  
 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);  
2919  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(2));
2920  OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);  OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x10000);
2921  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  OP2(SLJIT_SHL, TMP1, 0, TMP1, 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));  
2922  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(3));  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);
2924  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2925  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(3));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, IN_UCHARS(4));
2926  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2927  }  }
2928    
2929  static void do_utfreadtype8(compiler_common *common)  static void do_utfreadchar16(compiler_common *common)
2930  {  {
2931  /* Fast decoding a UTF-8 character type. TMP2 contains the first byte  /* Fast decoding a UTF-8 character. TMP1 contains the first byte
2932  of the character (>= 0xc0). Return value in TMP1. */  of the character (>= 0xc0). Return value in TMP1. */
2933  DEFINE_COMPILER;  DEFINE_COMPILER;
2934  struct sljit_jump *jump;  struct sljit_jump *jump;
 struct sljit_jump *compare;  
2935    
2936  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  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);
2941    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2942    
2943  OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20);  /* 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);  jump = JUMP(SLJIT_C_NOT_ZERO);
2946  /* Two byte sequence. */  /* Two byte sequence. */
 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));  
2947  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));
 OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x1f);  
 OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 6);  
 OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);  
 OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);  
 compare = CMP(SLJIT_C_GREATER, TMP2, 0, SLJIT_IMM, 255);  
 OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);  
2948  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2949    
 JUMPHERE(compare);  
 OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  
 sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  
2950  JUMPHERE(jump);  JUMPHERE(jump);
2951    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0x400);
2952  /* We only have types for characters less than 256. */  OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_NOT_ZERO);
2953  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(utf8_table4) - 0xc0);  /* This code runs only in 8 bit mode. No need to shift the value. */
2954  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
2955  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);  OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2956    OP2(SLJIT_XOR, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x800);
2957    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 6);
2958    OP2(SLJIT_AND, TMP2, 0, TMP2, 0, SLJIT_IMM, 0x3f);
2959    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2960    /* 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    
2965  #else /* COMPILE_PCRE8 */  static void do_utfreadtype8(compiler_common *common)
   
 #ifdef COMPILE_PCRE16  
 static void do_utfreadchar(compiler_common *common)  
2966  {  {
2967  /* Fast decoding a UTF-16 character. TMP1 contains the first 16 bit char  /* Fast decoding a UTF-8 character type. TMP2 contains the first byte
2968  of the character (>= 0xd800). Return char value in TMP1, length - 1 in TMP2. */  of the character (>= 0xc0). Return value in TMP1. */
2969  DEFINE_COMPILER;  DEFINE_COMPILER;
2970  struct sljit_jump *jump;  struct sljit_jump *jump;
2971    struct sljit_jump *compare;
2972    
2973    sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
2974    
2975    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP2, 0, SLJIT_IMM, 0x20);
2976    jump = JUMP(SLJIT_C_NOT_ZERO);
2977    /* Two byte sequence. */
2978    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));
2980    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);
2984    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0x3f);
2985    OP2(SLJIT_OR, TMP2, 0, TMP2, 0, TMP1, 0);
2986    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP2), common->ctypes);
2987    sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2988    
2989  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  JUMPHERE(compare);
2990  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xdc00);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 0);
 /* Do nothing, only return. */  
2991  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
2992    
2993    /* We only have types for characters less than 256. */
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  }  }
 #endif /* COMPILE_PCRE16 */  
3000    
3001  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
3002    
# Line 2433  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si Line 3018  SLJIT_ASSERT(UCD_BLOCK_SIZE == 128 && si
3018    
3019  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);  sljit_emit_fast_enter(compiler, RETURN_ADDR, 0);
3020  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_LSHR, TMP2, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
3021  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_w)PRIV(ucd_stage1));  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), (sljit_sw)PRIV(ucd_stage1));
3022  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);  OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, UCD_BLOCK_MASK);
3023  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCD_BLOCK_SHIFT);
3024  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, TMP2, 0);
3025  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_stage2));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_stage2));
3026  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);  OP1(SLJIT_MOV_UH, TMP2, 0, SLJIT_MEM2(TMP2, TMP1), 1);
3027  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_w)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, (sljit_sw)PRIV(ucd_records) + SLJIT_OFFSETOF(ucd_record, chartype));
3028  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(TMP1, TMP2), 3);
3029  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
3030  }  }
# Line 2453  struct sljit_label *newlinelabel = NULL; Line 3038  struct sljit_label *newlinelabel = NULL;
3038  struct sljit_jump *start;  struct sljit_jump *start;
3039  struct sljit_jump *end = NULL;  struct sljit_jump *end = NULL;
3040  struct sljit_jump *nl = NULL;  struct sljit_jump *nl = NULL;
3041  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3042  struct sljit_jump *singlechar;  struct sljit_jump *singlechar;
3043  #endif  #endif
3044  jump_list *newline = NULL;  jump_list *newline = NULL;
# Line 2488  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 2508  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  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3098    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3099  #endif  #endif
3100    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3101    nl = JUMP(SLJIT_JUMP);    nl = JUMP(SLJIT_JUMP);
# Line 2531  if (newlinecheck) Line 3116  if (newlinecheck)
3116    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);    CMPTO(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff, newlinelabel);
3117    
3118  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));
3119  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3120    #if defined COMPILE_PCRE8
3121  if (common->utf)  if (common->utf)
3122    {    {
3123    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);    singlechar = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0);
3124    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
3125    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3126    JUMPHERE(singlechar);    JUMPHERE(singlechar);
3127    }    }
3128  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3129  if (common->utf)  if (common->utf)
3130    {    {
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);
3138    }    }
3139  #endif  #endif /* COMPILE_PCRE[8|16] */
3140    #endif /* SUPPORT_UTF && !COMPILE_PCRE32 */
3141  JUMPHERE(start);  JUMPHERE(start);
3142    
3143  if (newlinecheck)  if (newlinecheck)
# Line 2563  if (newlinecheck) Line 3149  if (newlinecheck)
3149  return mainloop;  return mainloop;
3150  }  }
3151    
3152  static SLJIT_INLINE BOOL fast_forward_first_two_chars(compiler_common *common, BOOL firstline)  #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  DEFINE_COMPILER;  pcre_uint8 len = bytes[0];
3158  struct sljit_label *start;  int i;
 struct sljit_jump *quit;  
 struct sljit_jump *found;  
 pcre_int32 chars[4];  
 pcre_uchar *cc = common->start + 1 + IMM2_SIZE;  
 int location = 0;  
 pcre_int32 len, c, bit, caseless;  
 BOOL must_end;  
3159    
3160  #ifdef COMPILE_PCRE8  if (len == 255)
3161  union {    return;
3162      sljit_uh ascombined;  
3163      sljit_ub asuchars[2];  if (len == 0)
3164  } pair;    {
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  #else
3197  union {  pcre_uchar othercase[1];
     sljit_ui ascombined;  
     sljit_uh asuchars[2];  
 } pair;  
3198  #endif  #endif
3199    
3200  if (*(common->start + GET(common->start, 1)) == OP_ALT)  repeat = 1;
   return FALSE;  
   
3201  while (TRUE)  while (TRUE)
3202    {    {
3203    caseless = 0;    last = TRUE;
3204    must_end = TRUE;    any = FALSE;
3205    switch(*cc)    caseless = FALSE;
3206      switch (*cc)
3207      {      {
     case OP_CHAR:  
     must_end = FALSE;  
     cc++;  
     break;  
   
3208      case OP_CHARI:      case OP_CHARI:
3209      caseless = 1;      caseless = TRUE;
3210      must_end = FALSE;      case OP_CHAR:
3211        last = FALSE;
3212      cc++;      cc++;
3213      break;      break;
3214    
# Line 2622  while (TRUE) Line 3227  while (TRUE)
3227      cc++;      cc++;
3228      continue;      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_PLUS:      case OP_PLUS:
3238      case OP_MINPLUS:      case OP_MINPLUS:
3239      case OP_POSPLUS:      case OP_POSPLUS:
3240      cc++;      cc++;
3241      break;      break;
3242    
3243        case OP_EXACTI:
3244        caseless = TRUE;
3245      case OP_EXACT:      case OP_EXACT:
3246        repeat = GET2(cc, 1);
3247        last = FALSE;
3248      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
3249      break;      break;
3250    
3251      case OP_PLUSI:      case OP_PLUSI:
3252      case OP_MINPLUSI:      case OP_MINPLUSI:
3253      case OP_POSPLUSI:      case OP_POSPLUSI:
3254      caseless = 1;      caseless = TRUE;
3255      cc++;      cc++;
3256      break;      break;
3257    
3258      case OP_EXACTI:      case OP_KET:
3259      caseless = 1;      cc += 1 + LINK_SIZE;
3260      cc += 1 + IMM2_SIZE;      continue;
3261    
3262        case OP_ALT:
3263        cc += GET(cc, 1);
3264        continue;
3265    
3266        case OP_ONCE:
3267        case OP_ONCE_NC:
3268        case OP_BRA:
3269        case OP_BRAPOS:
3270        case OP_CBRA:
3271        case OP_CBRAPOS:
3272        alternative = cc + GET(cc, 1);
3273        while (*alternative == OP_ALT)
3274          {
3275          max_chars = scan_prefix(common, alternative + 1 + LINK_SIZE, chars, bytes, max_chars);
3276          if (max_chars == 0)
3277            return consumed;
3278          alternative += GET(alternative, 1);
3279          }
3280    
3281        if (*cc == OP_CBRA || *cc == OP_CBRAPOS)
3282          cc += IMM2_SIZE;
3283        cc += 1 + LINK_SIZE;
3284        continue;
3285    
3286        case OP_CLASS:
3287    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3288        if (common->utf && !is_char7_bitset((const pcre_uint8 *)(cc + 1), FALSE)) return consumed;
3289    #endif
3290        any = TRUE;
3291        cc += 1 + 32 / sizeof(pcre_uchar);
3292        break;
3293    
3294        case OP_NCLASS:
3295    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3296        if (common->utf) return consumed;
3297    #endif
3298        any = TRUE;
3299        cc += 1 + 32 / sizeof(pcre_uchar);
3300        break;
3301    
3302    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3303        case OP_XCLASS:
3304    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3305        if (common->utf) return consumed;
3306    #endif
3307        any = TRUE;
3308        cc += GET(cc, 1);
3309        break;
3310    #endif
3311    
3312        case OP_DIGIT:
3313    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3314        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_digit, FALSE))
3315          return consumed;
3316    #endif
3317        any = TRUE;
3318        cc++;
3319        break;
3320    
3321        case OP_WHITESPACE:
3322    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3323        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_space, FALSE))
3324          return consumed;
3325    #endif
3326        any = TRUE;
3327        cc++;
3328        break;
3329    
3330        case OP_WORDCHAR:
3331    #if defined SUPPORT_UTF && defined COMPILE_PCRE8
3332        if (common->utf && !is_char7_bitset((const pcre_uint8 *)common->ctypes - cbit_length + cbit_word, FALSE))
3333          return consumed;
3334    #endif
3335        any = TRUE;
3336        cc++;
3337        break;
3338    
3339        case OP_NOT_DIGIT:
3340        case OP_NOT_WHITESPACE:
3341        case OP_NOT_WORDCHAR:
3342        case OP_ANY:
3343        case OP_ALLANY:
3344    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3345        if (common->utf) return consumed;
3346    #endif
3347        any = TRUE;
3348        cc++;
3349      break;      break;
3350    
3351    #ifdef SUPPORT_UCP
3352        case OP_NOTPROP:
3353        case OP_PROP:
3354    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
3355        if (common->utf) return consumed;
3356    #endif
3357        any = TRUE;
3358        cc += 1 + 2;
3359        break;
3360    #endif
3361    
3362        case OP_TYPEEXACT:
3363        repeat = GET2(cc, 1);
3364        cc += 1 + IMM2_SIZE;
3365        continue;
3366    
3367      default:      default:
3368      return FALSE;      return consumed;
3369        }
3370    
3371      if (any)
3372        {
3373    #if defined COMPILE_PCRE8
3374        mask = 0xff;
3375    #elif defined COMPILE_PCRE16
3376        mask = 0xffff;
3377    #elif defined COMPILE_PCRE32
3378        mask = 0xffffffff;
3379    #else
3380        SLJIT_ASSERT_STOP();
3381    #endif
3382    
3383        do
3384          {
3385          chars[0] = mask;
3386          chars[1] = mask;
3387          bytes[0] = 255;
3388    
3389          consumed++;
3390          if (--max_chars == 0)
3391            return consumed;
3392          chars += 2;
3393          bytes += MAX_N_BYTES;
3394          }
3395        while (--repeat > 0);
3396    
3397        repeat = 1;
3398        continue;
3399      }      }
3400    
3401    len = 1;    len = 1;
3402  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3403    if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);    if (common->utf && HAS_EXTRALEN(*cc)) len += GET_EXTRALEN(*cc);
3404  #endif  #endif
3405    
3406    if (caseless && char_has_othercase(common, cc))    if (caseless && char_has_othercase(common, cc))
3407      {      {
3408      caseless = char_get_othercase_bit(common, cc);  #ifdef SUPPORT_UTF
3409      if (caseless == 0)      if (common->utf)
3410        return FALSE;        {
3411  #ifdef COMPILE_PCRE8        GETCHAR(chr, cc);
3412      caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));        if ((int)PRIV(ord2utf)(char_othercase(common, chr), othercase) != len)
3413  #else          return consumed;
3414      if ((caseless & 0x100) != 0)        }
       caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));  
3415      else      else
       caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));  
3416  #endif  #endif
3417          {
3418          chr = *cc;
3419          othercase[0] = TABLE_GET(chr, common->fcc, chr);
3420          }
3421      }      }
3422    else    else
3423      caseless = 0;      caseless = FALSE;
3424    
3425    while (len > 0 && location < 2 * 2)    len_save = len;
3426      cc_save = cc;
3427      while (TRUE)
3428      {      {
3429      c = *cc;      oc = othercase;
3430      bit = 0;      do
     if (len == (caseless & 0xff))  
3431        {        {
3432        bit = caseless >> 8;        chr = *cc;
3433        c |= bit;  #ifdef COMPILE_PCRE32
3434          if (SLJIT_UNLIKELY(chr == NOTACHAR))
3435            return consumed;
3436    #endif
3437          add_prefix_byte((pcre_uint8)chr, bytes);
3438    
3439          mask = 0;
3440          if (caseless)
3441            {
3442            add_prefix_byte((pcre_uint8)*oc, bytes);
3443            mask = *cc ^ *oc;
3444            chr |= mask;
3445            }
3446    
3447    #ifdef COMPILE_PCRE32
3448          if (chars[0] == NOTACHAR && chars[1] == 0)
3449    #else
3450          if (chars[0] == NOTACHAR)
3451    #endif
3452            {
3453            chars[0] = chr;
3454            chars[1] = mask;
3455            }
3456          else
3457            {
3458            mask |= chars[0] ^ chr;
3459            chr |= mask;
3460            chars[0] = chr;
3461            chars[1] |= mask;
3462            }
3463    
3464          len--;
3465          consumed++;
3466          if (--max_chars == 0)
3467            return consumed;
3468          chars += 2;
3469          bytes += MAX_N_BYTES;
3470          cc++;
3471          oc++;
3472        }        }
3473        while (len > 0);
3474    
3475        if (--repeat == 0)
3476          break;
3477    
3478      chars[location] = c;      len = len_save;
3479      chars[location + 1] = bit;      cc = cc_save;
3480        }
3481    
3482      len--;    repeat = 1;
3483      location += 2;    if (last)
3484      cc++;      return consumed;
3485      }
3486    }
3487    
3488    static SLJIT_INLINE BOOL fast_forward_first_n_chars(compiler_common *common, BOOL firstline)
3489    {
3490    DEFINE_COMPILER;
3491    struct sljit_label *start;
3492    struct sljit_jump *quit;
3493    pcre_uint32 chars[MAX_N_CHARS * 2];
3494    pcre_uint8 bytes[MAX_N_CHARS * MAX_N_BYTES];
3495    pcre_uint8 ones[MAX_N_CHARS];
3496    int offsets[3];
3497    pcre_uint32 mask;
3498    pcre_uint8 *byte_set, *byte_set_end;
3499    int i, max, from;
3500    int range_right = -1, range_len = 4 - 1;
3501    sljit_ub *update_table = NULL;
3502    BOOL in_range;
3503    
3504    /* This is even TRUE, if both are NULL. */
3505    SLJIT_ASSERT(common->read_only_data_ptr == common->read_only_data);
3506    
3507    for (i = 0; i < MAX_N_CHARS; i++)
3508      {
3509      chars[i << 1] = NOTACHAR;
3510      chars[(i << 1) + 1] = 0;
3511      bytes[i * MAX_N_BYTES] = 0;
3512      }
3513    
3514    max = scan_prefix(common, common->start, chars, bytes, MAX_N_CHARS);
3515    
3516    if (max <= 1)
3517      return FALSE;
3518    
3519    for (i = 0; i < max; i++)
3520      {
3521      mask = chars[(i << 1) + 1];
3522      ones[i] = ones_in_half_byte[mask & 0xf];
3523      mask >>= 4;
3524      while (mask != 0)
3525        {
3526        ones[i] += ones_in_half_byte[mask & 0xf];
3527        mask >>= 4;
3528        }
3529      }
3530    
3531    in_range = FALSE;
3532    for (i = 0; i <= max; i++)
3533      {
3534      if (in_range && (i - from) > range_len && (bytes[(i - 1) * MAX_N_BYTES] <= 4))
3535        {
3536        range_len = i - from;
3537        range_right = i - 1;
3538        }
3539    
3540      if (i < max && bytes[i * MAX_N_BYTES] < 255)
3541        {
3542        if (!in_range)
3543          {
3544          in_range = TRUE;
3545          from = i;
3546          }
3547        }
3548      else if (in_range)
3549        in_range = FALSE;
3550      }
3551    
3552    if (range_right >= 0)
3553      {
3554      /* Since no data is consumed (see the assert in the beginning
3555      of this function), this space can be reallocated. */
3556      if (common->read_only_data)
3557        SLJIT_FREE(common->read_only_data);
3558    
3559      common->read_only_data_size += 256;
3560      common->read_only_data = (sljit_uw *)SLJIT_MALLOC(common->read_only_data_size);
3561      if (common->read_only_data == NULL)
3562        return TRUE;
3563    
3564      update_table = (sljit_ub *)common->read_only_data;
3565      common->read_only_data_ptr = (sljit_uw *)(update_table + 256);
3566      memset(update_table, IN_UCHARS(range_len), 256);
3567    
3568      for (i = 0; i < range_len; i++)
3569        {
3570        byte_set = bytes + ((range_right - i) * MAX_N_BYTES);
3571        SLJIT_ASSERT(byte_set[0] > 0 && byte_set[0] < 255);
3572        byte_set_end = byte_set + byte_set[0];
3573        byte_set++;
3574        while (byte_set <= byte_set_end)
3575          {
3576          if (update_table[*byte_set] > IN_UCHARS(i))
3577            update_table[*byte_set] = IN_UCHARS(i);
3578          byte_set++;
3579          }
3580      }      }
3581      }
3582    
3583    if (location == 2 * 2)  offsets[0] = -1;
3584    /* Scan forward. */
3585    for (i = 0; i < max; i++)
3586      if (ones[i] <= 2) {
3587        offsets[0] = i;
3588      break;      break;
3589    else if (must_end)    }
3590    
3591    if (offsets[0] < 0 && range_right < 0)
3592      return FALSE;
3593    
3594    if (offsets[0] >= 0)
3595      {
3596      /* Scan backward. */
3597      offsets[1] = -1;
3598      for (i = max - 1; i > offsets[0]; i--)
3599        if (ones[i] <= 2 && i != range_right)
3600          {
3601          offsets[1] = i;
3602          break;
3603          }
3604    
3605      /* This case is handled better by fast_forward_first_char. */
3606      if (offsets[1] == -1 && offsets[0] == 0 && range_right < 0)
3607      return FALSE;      return FALSE;
3608    
3609      offsets[2] = -1;
3610      /* We only search for a middle character if there is no range check. */
3611      if (offsets[1] >= 0 && range_right == -1)
3612        {
3613        /* Scan from middle. */
3614        for (i = (offsets[0] + offsets[1]) / 2 + 1; i < offsets[1]; i++)
3615          if (ones[i] <= 2)
3616            {
3617            offsets[2] = i;
3618            break;
3619            }
3620    
3621        if (offsets[2] == -1)
3622          {
3623          for (i = (offsets[0] + offsets[1]) / 2; i > offsets[0]; i--)
3624            if (ones[i] <= 2)
3625              {
3626              offsets[2] = i;
3627              break;
3628              }
3629          }
3630        }
3631    
3632      SLJIT_ASSERT(offsets[1] == -1 || (offsets[0] < offsets[1]));
3633      SLJIT_ASSERT(offsets[2] == -1 || (offsets[0] < offsets[2] && offsets[1] > offsets[2]));
3634    
3635      chars[0] = chars[offsets[0] << 1];
3636      chars[1] = chars[(offsets[0] << 1) + 1];
3637      if (offsets[2] >= 0)
3638        {
3639        chars[2] = chars[offsets[2] << 1];
3640        chars[3] = chars[(offsets[2] << 1) + 1];
3641        }
3642      if (offsets[1] >= 0)
3643        {
3644        chars[4] = chars[offsets[1] << 1];
3645        chars[5] = chars[(offsets[1] << 1) + 1];
3646        }
3647    }    }
3648    
3649    max -= 1;
3650  if (firstline)  if (firstline)
3651    {    {
3652    SLJIT_ASSERT(common->first_line_end != 0);    SLJIT_ASSERT(common->first_line_end != 0);
3653      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3654    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);    OP1(SLJIT_MOV, TMP3, 0, STR_END, 0);
3655    OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, 1);    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3656      quit = CMP(SLJIT_C_LESS_EQUAL, STR_END, 0, TMP1, 0);
3657      OP1(SLJIT_MOV, STR_END, 0, TMP1, 0);
3658      JUMPHERE(quit);
3659    }    }
3660  else  else
3661    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, 1);    OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3662    
3663  start = LABEL();  #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3664  quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  if (range_right >= 0)
3665  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED    OP1(SLJIT_MOV, RETURN_ADDR, 0, SLJIT_IMM, (sljit_sw)update_table);
 #ifdef COMPILE_PCRE8  
 OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #else /* COMPILE_PCRE8 */  
 OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
3666  #endif  #endif
3667    
3668  #else /* SLJIT_UNALIGNED */  start = LABEL();
3669    quit = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3670    
3671  #if defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN  SLJIT_ASSERT(range_right >= 0 || offsets[0] >= 0);
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);  
 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 #else /* SLJIT_BIG_ENDIAN */  
 OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));  
 OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  
 #endif /* SLJIT_BIG_ENDIAN */  
3672    
3673  #ifdef COMPILE_PCRE8  if (range_right >= 0)
3674  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 8);    {
3675  #else /* COMPILE_PCRE8 */  #if defined COMPILE_PCRE8 || (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
3676  OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 16);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right));
3677    #else
3678      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(range_right + 1) - 1);
3679  #endif  #endif
 OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);  
3680    
3681    #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3682      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM2(RETURN_ADDR, TMP1), 0);
3683    #else
3684      OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)update_table);
3685  #endif  #endif
3686      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3687      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, start);
3688      }
3689    
3690  if (chars[1] != 0 || chars[3] != 0)  if (offsets[0] >= 0)
3691    {    {
3692    pair.asuchars[0] = chars[1];    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[0]));
3693    pair.asuchars[1] = chars[3];    if (offsets[1] >= 0)
3694    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, pair.ascombined);      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[1]));
3695      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3696    
3697      if (chars[1] != 0)
3698        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[1]);
3699      CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[0], start);
3700      if (offsets[2] >= 0)
3701        OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(offsets[2] - 1));
3702    
3703      if (offsets[1] >= 0)
3704        {
3705        if (chars[5] != 0)
3706          OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, chars[5]);
3707        CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, chars[4], start);
3708        }
3709    
3710      if (offsets[2] >= 0)
3711        {
3712        if (chars[3] != 0)
3713          OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, chars[3]);
3714        CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, chars[2], start);
3715        }
3716      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
3717    }    }
3718    
 pair.asuchars[0] = chars[0];  
 pair.asuchars[1] = chars[2];  
 found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, pair.ascombined);  
   
 OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));  
 JUMPTO(SLJIT_JUMP, start);  
 JUMPHERE(found);  
3719  JUMPHERE(quit);  JUMPHERE(quit);
3720    
3721  if (firstline)  if (firstline)
3722      {
3723      if (range_right >= 0)
3724        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end);
3725    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3726      if (range_right >= 0)
3727        {
3728        quit = CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP1, 0);
3729        OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
3730        JUMPHERE(quit);
3731        }
3732      }
3733  else  else
3734    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, IN_UCHARS(max));
3735  return TRUE;  return TRUE;
3736  }  }
3737    
3738    #undef MAX_N_CHARS
3739    #undef MAX_N_BYTES
3740    
3741  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)
3742  {  {
3743  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2787  if (first_char == oc) Line 3771  if (first_char == oc)
3771  else  else
3772    {    {
3773    bit = first_char ^ oc;    bit = first_char ^ oc;
3774    if (ispowerof2(bit))    if (is_powerof2(bit))
3775      {      {
3776      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
3777      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, first_char | bit);
# Line 2795  else Line 3779  else
3779    else    else
3780      {      {
3781      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);
3782      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3783      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);
3784      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);
3785      found = JUMP(SLJIT_C_NOT_ZERO);      found = JUMP(SLJIT_C_NOT_ZERO);
3786      }      }
3787    }    }
# Line 2839  if (common->nltype == NLTYPE_FIXED && co Line 3823  if (common->nltype == NLTYPE_FIXED && co
3823    
3824    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, IN_UCHARS(2));
3825    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);
3826    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_GREATER_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_GREATER_EQUAL);
3827  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3828    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, UCHAR_SHIFT);
3829  #endif  #endif
3830    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
3831    
# Line 2868  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_ Line 3852  firstchar = CMP(SLJIT_C_LESS_EQUAL, STR_
3852  skip_char_back(common);  skip_char_back(common);
3853    
3854  loop = LABEL();  loop = LABEL();
3855  read_char(common);  read_char_range(common, common->nlmin, common->nlmax, TRUE);
3856  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  lastchar = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3857  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)  if (common->nltype == NLTYPE_ANY || common->nltype == NLTYPE_ANYCRLF)
3858    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    foundcr = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
# Line 2882  if (common->nltype == NLTYPE_ANY || comm Line 3866  if (common->nltype == NLTYPE_ANY || comm
3866    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    notfoundnl = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
3867    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3868    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);
3869    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3870  #ifdef COMPILE_PCRE16  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
3871    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, UCHAR_SHIFT);
3872  #endif  #endif
3873    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3874    JUMPHERE(notfoundnl);    JUMPHERE(notfoundnl);
# Line 2897  if (firstline) Line 3881  if (firstline)
3881    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);    OP1(SLJIT_MOV, STR_END, 0, TMP3, 0);
3882  }  }
3883    
3884  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);
3885    
3886    static SLJIT_INLINE void fast_forward_start_bits(compiler_common *common, pcre_uint8 *start_bits, BOOL firstline)
3887  {  {
3888  DEFINE_COMPILER;  DEFINE_COMPILER;
3889  struct sljit_label *start;  struct sljit_label *start;
3890  struct sljit_jump *quit;  struct sljit_jump *quit;
3891  struct sljit_jump *found;  struct sljit_jump *found = NULL;
3892    jump_list *matches = NULL;
3893  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3894  struct sljit_jump *jump;  struct sljit_jump *jump;
3895  #endif  #endif
# Line 2921  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P Line 3908  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_P
3908  if (common->utf)  if (common->utf)
3909    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);    OP1(SLJIT_MOV, TMP3, 0, TMP1, 0);
3910  #endif  #endif
3911    
3912    if (!check_class_ranges(common, start_bits, (start_bits[31] & 0x80) != 0, TRUE, &matches))
3913      {
3914  #ifndef COMPILE_PCRE8  #ifndef COMPILE_PCRE8
3915  jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);    jump = CMP(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 255);
3916  OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, 255);
3917  JUMPHERE(jump);    JUMPHERE(jump);
3918  #endif  #endif
3919  OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);    OP2(SLJIT_AND, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x7);
3920  OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);    OP2(SLJIT_LSHR, TMP1, 0, TMP1, 0, SLJIT_IMM, 3);
3921  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), start_bits);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)start_bits);
3922  OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
3923  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);
3924  found = JUMP(SLJIT_C_NOT_ZERO);    found = JUMP(SLJIT_C_NOT_ZERO);
3925      }
3926    
3927  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3928  if (common->utf)  if (common->utf)
3929    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);    OP1(SLJIT_MOV, TMP1, 0, TMP3, 0);
3930  #endif  #endif
3931  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));
3932  #if defined SUPPORT_UTF && defined COMPILE_PCRE8  #ifdef SUPPORT_UTF
3933    #if defined COMPILE_PCRE8
3934  if (common->utf)  if (common->utf)
3935    {    {
3936    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);
3937    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_sw)PRIV(utf8_table4) - 0xc0);
3938    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3939    }    }
3940  #endif  #elif defined COMPILE_PCRE16
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
3941  if (common->utf)  if (common->utf)
3942    {    {
3943    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);
3944    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);    OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);
3945    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);
3946    COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP1, 0, SLJIT_UNUSED, 0, SLJIT_C_EQUAL);
3947    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
3948    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);
3949    }    }
3950  #endif  #endif /* COMPILE_PCRE[8|16] */
3951    #endif /* SUPPORT_UTF */
3952  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
3953  JUMPHERE(found);  if (found != NULL)
3954      JUMPHERE(found);
3955    if (matches != NULL)
3956      set_jumps(matches, LABEL());
3957  JUMPHERE(quit);  JUMPHERE(quit);
3958    
3959  if (firstline)  if (firstline)
# Line 2974  struct sljit_jump *alreadyfound; Line 3969  struct sljit_jump *alreadyfound;
3969  struct sljit_jump *found;  struct sljit_jump *found;
3970  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
3971  struct sljit_jump *notfound;  struct sljit_jump *notfound;
3972  pcre_uchar oc, bit;  pcre_uint32 oc, bit;
3973    
3974  SLJIT_ASSERT(common->req_char_ptr != 0);  SLJIT_ASSERT(common->req_char_ptr != 0);
3975  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->req_char_ptr);
# Line 3005  if (req_char == oc) Line 4000  if (req_char == oc)
4000  else  else
4001    {    {
4002    bit = req_char ^ oc;    bit = req_char ^ oc;
4003    if (ispowerof2(bit))    if (is_powerof2(bit))
4004      {      {
4005      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
4006      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, req_char | bit);
# Line 3041  GET_LOCAL_BASE(TMP3, 0, 0); Line 4036  GET_LOCAL_BASE(TMP3, 0, 0);
4036  /* Drop frames until we reach STACK_TOP. */  /* Drop frames until we reach STACK_TOP. */
4037  mainloop = LABEL();  mainloop = LABEL();
4038  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), 0);
4039  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);
4040    jump = JUMP(SLJIT_C_SIG_LESS_EQUAL);
4041    
4042  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
4043  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
4044  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_w), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), sizeof(sljit_sw), SLJIT_MEM1(TMP1), 2 * sizeof(sljit_sw));
4045  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 3 * sizeof(sljit_sw));
4046  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
4047    
4048  JUMPHERE(jump);  JUMPHERE(jump);
4049  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_end);  jump = JUMP(SLJIT_C_SIG_LESS);
4050  /* End of dropping frames. */  /* End of dropping frames. */
4051  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);  sljit_emit_fast_return(compiler, RETURN_ADDR, 0);
4052    
4053  JUMPHERE(jump);  JUMPHERE(jump);
4054  jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setstrbegin);  OP1(SLJIT_NEG, TMP2, 0, TMP2, 0);
4055  /* Set string begin. */  OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP3, 0);
4056  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(TMP2), 0, SLJIT_MEM1(TMP1), sizeof(sljit_sw));
4057  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
 OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), TMP2, 0);  
 JUMPTO(SLJIT_JUMP, mainloop);  
   
 JUMPHERE(jump);  
 if (common->mark_ptr != 0)  
   {  
   jump = CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, frame_setmark);  
   OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), sizeof(sljit_w));  
   OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  
   OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);  
   JUMPTO(SLJIT_JUMP, mainloop);  
   
   JUMPHERE(jump);  
   }  
   
 /* Unknown command. */  
 OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 2 * sizeof(sljit_w));  
4058  JUMPTO(SLJIT_JUMP, mainloop);  JUMPTO(SLJIT_JUMP, mainloop);
4059  }  }
4060    
# Line 3082  static void check_wordboundary(compiler_ Line 4062  static void check_wordboundary(compiler_
4062  {  {
4063  DEFINE_COMPILER;  DEFINE_COMPILER;
4064  struct sljit_jump *skipread;  struct sljit_jump *skipread;
4065    jump_list *skipread_list = NULL;
4066  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF  #if !(defined COMPILE_PCRE8) || defined SUPPORT_UTF
4067  struct sljit_jump *jump;  struct sljit_jump *jump;
4068  #endif  #endif
# Line 3107  if (common->use_ucp) Line 4088  if (common->use_ucp)
4088    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4089    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
4090    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);
4091    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4092    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);
4093    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);
4094    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4095    JUMPHERE(jump);    JUMPHERE(jump);
4096    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, TMP2, 0);
4097    }    }
# Line 3139  else Line 4120  else
4120  JUMPHERE(skipread);  JUMPHERE(skipread);
4121    
4122  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);
4123  skipread = check_str_end(common);  check_str_end(common, &skipread_list);
4124  peek_char(common);  peek_char(common, READ_CHAR_MAX);
4125    
4126  /* Testing char type. This is a code duplication. */  /* Testing char type. This is a code duplication. */
4127  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 3151  if (common->use_ucp) Line 4132  if (common->use_ucp)
4132    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4133    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Ll);
4134    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);
4135    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
4136    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);
4137    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);
4138    COND_VALUE(SLJIT_OR, TMP2, 0, SLJIT_C_LESS_EQUAL);    OP_FLAGS(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_C_LESS_EQUAL);
4139    JUMPHERE(jump);    JUMPHERE(jump);
4140    }    }
4141  else  else
# Line 3180  else Line 4161  else
4161      JUMPHERE(jump);      JUMPHERE(jump);
4162  #endif /* COMPILE_PCRE8 */  #endif /* COMPILE_PCRE8 */
4163    }    }
4164  JUMPHERE(skipread);  set_jumps(skipread_list, LABEL());
4165    
4166  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);
4167  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
4168  }  }
4169    
4170  /*  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)  
4171  {  {
4172  DEFINE_COMPILER;  DEFINE_COMPILER;
4173  struct sljit_jump *jump;  int ranges[MAX_RANGE_SIZE];
   
 if (ranges[0] < 0)  
   return FALSE;  
   
 switch(ranges[0])  
   {  
   case 1:  
   if (readch)  
     read_char(common);  
   add_jump(compiler, backtracks, CMP(ranges[1] == 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));  
   return TRUE;  
   
   case 2:  
   if (readch)  
     read_char(common);  
   OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ranges[2]);  
   add_jump(compiler, backtracks, CMP(ranges[1] != 0 ? SLJIT_C_LESS : SLJIT_C_GREATER_EQUAL, TMP1, 0, SLJIT_IMM, ranges[3] - ranges[2]));  
   return TRUE;  
   
   case 4:  
   if (ranges[2] + 1 == ranges[3] && ranges[4] + 1 == ranges[5])  
     {  
     if (readch)  
       read_char(common);  
     if (ranges[1] != 0)  
       {  
       add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[2]));  
       add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, ranges[4]));  
       }  
     else  
       {  
       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);  
       }  
     return TRUE;  
     }  
   if ((ranges[3] - ranges[2]) == (ranges[5] - ranges[4]) && ispowerof2(ranges[4] - ranges[2]))  
     {  
     if (readch)  
       read_char(common);  
     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;  
     }  
   return FALSE;  
   
   default:  
   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;  
   
 for (i = 1; i < 256; i++)  
   if ((ctypes[i] & flag) != bit)  
     {  
     if (length >= MAX_RANGE_SIZE)  
       return;  
     ranges[2 + length] = i;  
     length++;  
     bit ^= flag;  
     }  
   
 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];  
4174  pcre_uint8 bit, cbit, all;  pcre_uint8 bit, cbit, all;
4175  int i, byte, length = 0;  int i, byte, length = 0;
4176    
4177  bit = bits[0] & 0x1;  bit = bits[0] & 0x1;
4178  ranges[1] = bit;  /* All bits will be zero or one (since bit is zero or one). */
 /* Can be 0 or 255. */  
4179  all = -bit;  all = -bit;
4180    
4181  for (i = 0; i < 256; )  for (i = 0; i < 256; )
# Line 3304  for (i = 0; i < 256; ) Line 4190  for (i = 0; i < 256; )
4190        {        {
4191        if (length >= MAX_RANGE_SIZE)        if (length >= MAX_RANGE_SIZE)
4192          return FALSE;          return FALSE;
4193        ranges[2 + length] = i;        ranges[length] = i;
4194        length++;        length++;
4195        bit = cbit;        bit = cbit;
4196        all = -cbit;        all = -cbit;
# Line 3317  if (((bit == 0) && nclass) || ((bit == 1 Line 4203  if (((bit == 0) && nclass) || ((bit == 1
4203    {    {
4204    if (length >= MAX_RANGE_SIZE)    if (length >= MAX_RANGE_SIZE)
4205      return FALSE;      return FALSE;
4206    ranges[2 + length] = 256;    ranges[length] = 256;
4207    length++;    length++;
4208    }    }
 ranges[0] = length;  
4209    
4210  return check_ranges(common, ranges, backtracks, FALSE);  if (length < 0 || length > 4)