/[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 1277 by zherczeg, Mon Mar 11 09:50:29 2013 UTC revision 1307 by zherczeg, Mon Apr 1 17:13:00 2013 UTC
# Line 202  enum frame_types { Line 202  enum frame_types {
202  };  };
203    
204  enum control_types {  enum control_types {
205    type_commit = 0,    type_mark = 0,
206    type_prune = 1,    type_then_trap = 1
   type_skip = 2  
207  };  };
208    
209  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
# Line 283  typedef struct recurse_entry { Line 282  typedef struct recurse_entry {
282    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
283    jump_list *calls;    jump_list *calls;
284    /* Points to the starting opcode. */    /* Points to the starting opcode. */
285    int start;    sljit_sw start;
286  } recurse_entry;  } recurse_entry;
287    
288  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
# Line 291  typedef struct recurse_backtrack { Line 290  typedef struct recurse_backtrack {
290    BOOL inlined_pattern;    BOOL inlined_pattern;
291  } recurse_backtrack;  } recurse_backtrack;
292    
293    #define OP_THEN_TRAP OP_TABLE_LENGTH
294    
295    typedef struct then_trap_backtrack {
296      backtrack_common common;
297      /* If then_trap is not NULL, this structure contains the real
298      then_trap for the backtracking path. */
299      struct then_trap_backtrack *then_trap;
300      /* Points to the starting opcode. */
301      sljit_sw start;
302      /* Exit point for the then opcodes of this alternative. */
303      jump_list *quit;
304      /* Frame size of the current alternative. */
305      int framesize;
306    } then_trap_backtrack;
307    
308  #define MAX_RANGE_SIZE 6  #define MAX_RANGE_SIZE 6
309    
310  typedef struct compiler_common {  typedef struct compiler_common {
# Line 299  typedef struct compiler_common { Line 313  typedef struct compiler_common {
313    /* First byte code. */    /* First byte code. */
314    pcre_uchar *start;    pcre_uchar *start;
315    /* Maps private data offset to each opcode. */    /* Maps private data offset to each opcode. */
316    int *private_data_ptrs;    sljit_si *private_data_ptrs;
317    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
318    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
319      /* Tells whether the starting offset is a target of then. */
320      pcre_uint8 *then_offsets;
321      /* Current position where a THEN must jump. */
322      then_trap_backtrack *then_trap;
323    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
324    int cbra_ptr;    int cbra_ptr;
325    /* Output vector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
# Line 330  typedef struct compiler_common { Line 348  typedef struct compiler_common {
348    sljit_sw lcc;    sljit_sw lcc;
349    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
350    int mode;    int mode;
351    /* \K is in the pattern. */    /* \K is found in the pattern. */
352    BOOL has_set_som;    BOOL has_set_som;
353      /* (*SKIP:arg) is found in the pattern. */
354      BOOL has_skip_arg;
355      /* (*THEN) is found in the pattern. */
356      BOOL has_then;
357    /* Needs to know the start position anytime. */    /* Needs to know the start position anytime. */
358    BOOL needs_start_ptr;    BOOL needs_start_ptr;
359    /* Currently in recurse or assert. */    /* Currently in recurse or negative assert. */
360    BOOL local_exit;    BOOL local_exit;
361      /* Currently in a positive assert. */
362      BOOL positive_assert;
363    /* Newline control. */    /* Newline control. */
364    int nltype;    int nltype;
365    int newline;    int newline;
# Line 360  typedef struct compiler_common { Line 384  typedef struct compiler_common {
384    recurse_entry *currententry;    recurse_entry *currententry;
385    jump_list *partialmatch;    jump_list *partialmatch;
386    jump_list *quit;    jump_list *quit;
387      jump_list *positive_assert_quit;
388    jump_list *forced_quit;    jump_list *forced_quit;
389    jump_list *accept;    jump_list *accept;
390    jump_list *calllimit;    jump_list *calllimit;
# Line 509  return cc; Line 534  return cc;
534    
535  /* Functions whose might need modification for all new supported opcodes:  /* Functions whose might need modification for all new supported opcodes:
536   next_opcode   next_opcode
537   get_private_data_length   check_opcode_types
538   set_private_data_ptrs   set_private_data_ptrs
539   get_framesize   get_framesize
540   init_frame   init_frame
# Line 597  switch(*cc) Line 622  switch(*cc)
622    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
623    case OP_PRUNE:    case OP_PRUNE:
624    case OP_SKIP:    case OP_SKIP:
625      case OP_THEN:
626    case OP_COMMIT:    case OP_COMMIT:
627    case OP_FAIL:    case OP_FAIL:
628    case OP_ACCEPT:    case OP_ACCEPT:
# Line 696  switch(*cc) Line 722  switch(*cc)
722    
723    case OP_MARK:    case OP_MARK:
724    case OP_PRUNE_ARG:    case OP_PRUNE_ARG:
725      case OP_SKIP_ARG:
726      case OP_THEN_ARG:
727    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
728    
729    default:    default:
730      /* All opcodes are supported now! */
731      SLJIT_ASSERT_STOP();
732    return NULL;    return NULL;
733    }    }
734  }  }
735    
736  #define CASE_ITERATOR_PRIVATE_DATA_1 \  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
     case OP_MINSTAR: \  
     case OP_MINPLUS: \  
     case OP_QUERY: \  
     case OP_MINQUERY: \  
     case OP_MINSTARI: \  
     case OP_MINPLUSI: \  
     case OP_QUERYI: \  
     case OP_MINQUERYI: \  
     case OP_NOTMINSTAR: \  
     case OP_NOTMINPLUS: \  
     case OP_NOTQUERY: \  
     case OP_NOTMINQUERY: \  
     case OP_NOTMINSTARI: \  
     case OP_NOTMINPLUSI: \  
     case OP_NOTQUERYI: \  
     case OP_NOTMINQUERYI:  
   
 #define CASE_ITERATOR_PRIVATE_DATA_2A \  
     case OP_STAR: \  
     case OP_PLUS: \  
     case OP_STARI: \  
     case OP_PLUSI: \  
     case OP_NOTSTAR: \  
     case OP_NOTPLUS: \  
     case OP_NOTSTARI: \  
     case OP_NOTPLUSI:  
   
 #define CASE_ITERATOR_PRIVATE_DATA_2B \  
     case OP_UPTO: \  
     case OP_MINUPTO: \  
     case OP_UPTOI: \  
     case OP_MINUPTOI: \  
     case OP_NOTUPTO: \  
     case OP_NOTMINUPTO: \  
     case OP_NOTUPTOI: \  
     case OP_NOTMINUPTOI:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \  
     case OP_TYPEMINSTAR: \  
     case OP_TYPEMINPLUS: \  
     case OP_TYPEQUERY: \  
     case OP_TYPEMINQUERY:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \  
     case OP_TYPESTAR: \  
     case OP_TYPEPLUS:  
   
 #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \  
     case OP_TYPEUPTO: \  
     case OP_TYPEMINUPTO:  
   
 static int get_class_iterator_size(pcre_uchar *cc)  
737  {  {
 switch(*cc)  
   {  
   case OP_CRSTAR:  
   case OP_CRPLUS:  
   return 2;  
   
   case OP_CRMINSTAR:  
   case OP_CRMINPLUS:  
   case OP_CRQUERY:  
   case OP_CRMINQUERY:  
   return 1;  
   
   case OP_CRRANGE:  
   case OP_CRMINRANGE:  
   if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))  
     return 0;  
   return 2;  
   
   default:  
   return 0;  
   }  
 }  
   
 static int get_private_data_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  
 {  
 int private_data_length = 0;  
 pcre_uchar *alternative;  
738  pcre_uchar *name;  pcre_uchar *name;
739  pcre_uchar *end = NULL;  pcre_uchar *name2;
740  int space, size, i;  int i, cbra_index;
 pcre_uint32 bracketlen;  
741    
742  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
743  while (cc < ccend)  while (cc < ccend)
744    {    {
   space = 0;  
   size = 0;  
   bracketlen = 0;  
745    switch(*cc)    switch(*cc)
746      {      {
747      case OP_SET_SOM:      case OP_SET_SOM:
# Line 808  while (cc < ccend) Line 755  while (cc < ccend)
755      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
756      break;      break;
757    
     case OP_ASSERT:  
     case OP_ASSERT_NOT:  
     case OP_ASSERTBACK:  
     case OP_ASSERTBACK_NOT:  
     case OP_ONCE:  
     case OP_ONCE_NC:  
     case OP_BRAPOS:  
     case OP_SBRA:  
     case OP_SBRAPOS:  
     private_data_length += sizeof(sljit_sw);  
     bracketlen = 1 + LINK_SIZE;  
     break;  
   
758      case OP_CBRAPOS:      case OP_CBRAPOS:
759      case OP_SCBRAPOS:      case OP_SCBRAPOS:
     private_data_length += sizeof(sljit_sw);  
760      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;      common->optimized_cbracket[GET2(cc, 1 + LINK_SIZE)] = 0;
761      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
762      break;      break;
763    
764      case OP_COND:      case OP_COND:
# Line 833  while (cc < ccend) Line 766  while (cc < ccend)
766      /* Only AUTO_CALLOUT can insert this opcode. We do      /* Only AUTO_CALLOUT can insert this opcode. We do
767         not intend to support this case. */         not intend to support this case. */
768      if (cc[1 + LINK_SIZE] == OP_CALLOUT)      if (cc[1 + LINK_SIZE] == OP_CALLOUT)
769        return -1;        return FALSE;
770        cc += 1 + LINK_SIZE;
     if (*cc == OP_COND)  
       {  
       /* Might be a hidden SCOND. */  
       alternative = cc + GET(cc, 1);  
       if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)  
         private_data_length += sizeof(sljit_sw);  
       }  
     else  
       private_data_length += sizeof(sljit_sw);  
     bracketlen = 1 + LINK_SIZE;  
771      break;      break;
772    
773      case OP_CREF:      case OP_CREF:
# Line 854  while (cc < ccend) Line 777  while (cc < ccend)
777      break;      break;
778    
779      case OP_NCREF:      case OP_NCREF:
780      bracketlen = GET2(cc, 1);      cbra_index = GET2(cc, 1);
781      name = (pcre_uchar *)common->name_table;      name = (pcre_uchar *)common->name_table;
782      alternative = name;      name2 = name;
783      for (i = 0; i < common->name_count; i++)      for (i = 0; i < common->name_count; i++)
784        {        {
785        if (GET2(name, 0) == bracketlen) break;        if (GET2(name, 0) == cbra_index) break;
786        name += common->name_entry_size;        name += common->name_entry_size;
787        }        }
788      SLJIT_ASSERT(i != common->name_count);      SLJIT_ASSERT(i != common->name_count);
789    
790      for (i = 0; i < common->name_count; i++)      for (i = 0; i < common->name_count; i++)
791        {        {
792        if (STRCMP_UC_UC(alternative + IMM2_SIZE, name + IMM2_SIZE) == 0)        if (STRCMP_UC_UC(name2 + IMM2_SIZE, name + IMM2_SIZE) == 0)
793          common->optimized_cbracket[GET2(alternative, 0)] = 0;          common->optimized_cbracket[GET2(name2, 0)] = 0;
794        alternative += common->name_entry_size;        name2 += common->name_entry_size;
795        }        }
     bracketlen = 0;  
796      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
797      break;      break;
798    
     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;  
   
 #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  
     case OP_XCLASS:  
     size = GET(cc, 1);  
     space = get_class_iterator_size(cc + size);  
     break;  
 #endif  
   
799      case OP_RECURSE:      case OP_RECURSE:
800      /* Set its value only once. */      /* Set its value only once. */
801      if (common->recursive_head_ptr == 0)      if (common->recursive_head_ptr == 0)
# Line 947  while (cc < ccend) Line 815  while (cc < ccend)
815      cc += 2 + 2 * LINK_SIZE;      cc += 2 + 2 * LINK_SIZE;
816      break;      break;
817    
818        case OP_THEN_ARG:
819        common->has_then = TRUE;
820        common->control_head_ptr = 1;
821        /* Fall through. */
822    
823      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
824      common->needs_start_ptr = TRUE;      common->needs_start_ptr = TRUE;
     common->control_head_ptr = 1;  
825      /* Fall through. */      /* Fall through. */
826    
827      case OP_MARK:      case OP_MARK:
# Line 961  while (cc < ccend) Line 833  while (cc < ccend)
833      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
834      break;      break;
835    
836        case OP_THEN:
837        common->has_then = TRUE;
838        common->control_head_ptr = 1;
839        /* Fall through. */
840    
841      case OP_PRUNE:      case OP_PRUNE:
842      case OP_SKIP:      case OP_SKIP:
843      common->needs_start_ptr = TRUE;      common->needs_start_ptr = TRUE;
844      /* Fall through. */      cc += 1;
845        break;
846    
847      case OP_COMMIT:      case OP_SKIP_ARG:
848      common->control_head_ptr = 1;      common->control_head_ptr = 1;
849      cc += 1;      common->has_skip_arg = TRUE;
850        cc += 1 + 2 + cc[1];
851      break;      break;
852    
853      default:      default:
854      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
855      if (cc == NULL)      if (cc == NULL)
856        return -1;        return FALSE;
857      break;      break;
858      }      }
859      }
860    return TRUE;
861    }
862    
863    if (space > 0 && cc >= end)  static int get_class_iterator_size(pcre_uchar *cc)
864      private_data_length += sizeof(sljit_sw) * space;  {
865    switch(*cc)
866      {
867      case OP_CRSTAR:
868      case OP_CRPLUS:
869      return 2;
870    
871    if (size != 0)    case OP_CRMINSTAR:
872      case OP_CRMINPLUS:
873      case OP_CRQUERY:
874      case OP_CRMINQUERY:
875      return 1;
876    
877      case OP_CRRANGE:
878      case OP_CRMINRANGE:
879      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
880        return 0;
881      return 2;
882    
883      default:
884      return 0;
885      }
886    }
887    
888    static BOOL detect_repeat(compiler_common *common, pcre_uchar *begin)
889    {
890    pcre_uchar *end = bracketend(begin);
891    pcre_uchar *next;
892    pcre_uchar *next_end;
893    pcre_uchar *max_end;
894    pcre_uchar type;
895    sljit_uw length = end - begin;
896    int min, max, i;
897    
898    /* Detect fixed iterations first. */
899    if (end[-(1 + LINK_SIZE)] != OP_KET)
900      return FALSE;
901    
902    /* Already detected repeat. */
903    if (common->private_data_ptrs[end - common->start - LINK_SIZE] != 0)
904      return TRUE;
905    
906    next = end;
907    min = 1;
908    while (1)
909      {
910      if (*next != *begin)
911        break;
912      next_end = bracketend(next);
913      if (next_end - next != length || memcmp(begin, next, IN_UCHARS(length)) != 0)
914        break;
915      next = next_end;
916      min++;
917      }
918    
919    if (min == 2)
920      return FALSE;
921    
922    max = 0;
923    max_end = next;
924    if (*next == OP_BRAZERO || *next == OP_BRAMINZERO)
925      {
926      type = *next;
927      while (1)
928      {      {
929      if (size < 0)      if (next[0] != type || next[1] != OP_BRA || next[2 + LINK_SIZE] != *begin)
930        {        break;
931        cc += -size;      next_end = bracketend(next + 2 + LINK_SIZE);
932  #ifdef SUPPORT_UTF      if (next_end - next != (length + 2 + LINK_SIZE) || memcmp(begin, next + 2 + LINK_SIZE, IN_UCHARS(length)) != 0)
933        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);        break;
934  #endif      next = next_end;
935        }      max++;
     else  
       cc += size;  
936      }      }
937    
938    if (bracketlen != 0)    if (next[0] == type && next[1] == *begin && max >= 1)
939      {      {
940      if (cc >= end)      next_end = bracketend(next + 1);
941        if (next_end - next == (length + 1) && memcmp(begin, next + 1, IN_UCHARS(length)) == 0)
942        {        {
943        end = bracketend(cc);        for (i = 0; i < max; i++, next_end += 1 + LINK_SIZE)
944        if (end[-1 - LINK_SIZE] == OP_KET)          if (*next_end != OP_KET)
945          end = NULL;            break;
946    
947          if (i == max)
948            {
949            common->private_data_ptrs[max_end - common->start - LINK_SIZE] = next_end - max_end;
950            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 1] = (type == OP_BRAZERO) ? OP_UPTO : OP_MINUPTO;
951            /* +2 the original and the last. */
952            common->private_data_ptrs[max_end - common->start - LINK_SIZE + 2] = max + 2;
953            if (min == 1)
954              return TRUE;
955            min--;
956            max_end -= (1 + LINK_SIZE) + GET(max_end, -LINK_SIZE);
957            }
958        }        }
     cc += bracketlen;  
959      }      }
960    }    }
961  return private_data_length;  
962    if (min >= 3)
963      {
964      common->private_data_ptrs[end - common->start - LINK_SIZE] = max_end - end;
965      common->private_data_ptrs[end - common->start - LINK_SIZE + 1] = OP_EXACT;
966      common->private_data_ptrs[end - common->start - LINK_SIZE + 2] = min;
967      return TRUE;
968      }
969    
970    return FALSE;
971  }  }
972    
973  static void set_private_data_ptrs(compiler_common *common, int private_data_ptr, pcre_uchar *ccend)  #define CASE_ITERATOR_PRIVATE_DATA_1 \
974        case OP_MINSTAR: \
975        case OP_MINPLUS: \
976        case OP_QUERY: \
977        case OP_MINQUERY: \
978        case OP_MINSTARI: \
979        case OP_MINPLUSI: \
980        case OP_QUERYI: \
981        case OP_MINQUERYI: \
982        case OP_NOTMINSTAR: \
983        case OP_NOTMINPLUS: \
984        case OP_NOTQUERY: \
985        case OP_NOTMINQUERY: \
986        case OP_NOTMINSTARI: \
987        case OP_NOTMINPLUSI: \
988        case OP_NOTQUERYI: \
989        case OP_NOTMINQUERYI:
990    
991    #define CASE_ITERATOR_PRIVATE_DATA_2A \
992        case OP_STAR: \
993        case OP_PLUS: \
994        case OP_STARI: \
995        case OP_PLUSI: \
996        case OP_NOTSTAR: \
997        case OP_NOTPLUS: \
998        case OP_NOTSTARI: \
999        case OP_NOTPLUSI:
1000    
1001    #define CASE_ITERATOR_PRIVATE_DATA_2B \
1002        case OP_UPTO: \
1003        case OP_MINUPTO: \
1004        case OP_UPTOI: \
1005        case OP_MINUPTOI: \
1006        case OP_NOTUPTO: \
1007        case OP_NOTMINUPTO: \
1008        case OP_NOTUPTOI: \
1009        case OP_NOTMINUPTOI:
1010    
1011    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_1 \
1012        case OP_TYPEMINSTAR: \
1013        case OP_TYPEMINPLUS: \
1014        case OP_TYPEQUERY: \
1015        case OP_TYPEMINQUERY:
1016    
1017    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2A \
1018        case OP_TYPESTAR: \
1019        case OP_TYPEPLUS:
1020    
1021    #define CASE_ITERATOR_TYPE_PRIVATE_DATA_2B \
1022        case OP_TYPEUPTO: \
1023        case OP_TYPEMINUPTO:
1024    
1025    static void set_private_data_ptrs(compiler_common *common, int *private_data_start, pcre_uchar *ccend)
1026  {  {
1027  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
1028  pcre_uchar *alternative;  pcre_uchar *alternative;
1029  pcre_uchar *end = NULL;  pcre_uchar *end = NULL;
1030    int private_data_ptr = *private_data_start;
1031  int space, size, bracketlen;  int space, size, bracketlen;
1032    
1033  while (cc < ccend)  while (cc < ccend)
# Line 1020  while (cc < ccend) Line 1035  while (cc < ccend)
1035    space = 0;    space = 0;
1036    size = 0;    size = 0;
1037    bracketlen = 0;    bracketlen = 0;
1038      if (private_data_ptr > SLJIT_MAX_LOCAL_SIZE)
1039        return;
1040    
1041      if (*cc == OP_BRA || *cc == OP_CBRA || *cc == OP_ONCE || *cc == OP_ONCE_NC)
1042        if (detect_repeat(common, cc))
1043          {
1044          /* These brackets are converted to repeats, so no global
1045          based single character repeat is allowed. */
1046          if (cc >= end)
1047            end = bracketend(cc);
1048          }
1049    
1050    switch(*cc)    switch(*cc)
1051      {      {
1052        case OP_KET:
1053        if (common->private_data_ptrs[cc + 1 - common->start] != 0)
1054          {
1055          common->private_data_ptrs[cc - common->start] = private_data_ptr;
1056          private_data_ptr += sizeof(sljit_sw);
1057          cc += common->private_data_ptrs[cc + 1 - common->start];
1058          }
1059        cc += 1 + LINK_SIZE;
1060        break;
1061    
1062      case OP_ASSERT:      case OP_ASSERT:
1063      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1064      case OP_ASSERTBACK:      case OP_ASSERTBACK:
# Line 1115  while (cc < ccend) Line 1152  while (cc < ccend)
1152      break;      break;
1153      }      }
1154    
1155      /* Character iterators, which are not inside a repeated bracket,
1156         gets a private slot instead of allocating it on the stack. */
1157    if (space > 0 && cc >= end)    if (space > 0 && cc >= end)
1158      {      {
1159      common->private_data_ptrs[cc - common->start] = private_data_ptr;      common->private_data_ptrs[cc - common->start] = private_data_ptr;
# Line 1145  while (cc < ccend) Line 1184  while (cc < ccend)
1184      cc += bracketlen;      cc += bracketlen;
1185      }      }
1186    }    }
1187    *private_data_start = private_data_ptr;
1188  }  }
1189    
1190  /* Returns with a frame_types (always < 0) if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1191  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive, BOOL* needs_control_head)  static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL* needs_control_head)
1192  {  {
 pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);  
1193  int length = 0;  int length = 0;
1194  int possessive = 0;  int possessive = 0;
1195  BOOL stack_restore = FALSE;  BOOL stack_restore = FALSE;
# Line 1166  SLJIT_ASSERT(common->control_head_ptr != Line 1205  SLJIT_ASSERT(common->control_head_ptr !=
1205  *needs_control_head = FALSE;  *needs_control_head = FALSE;
1206  #endif  #endif
1207    
1208  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  if (ccend == NULL)
1209    {    {
1210    possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1211    /* This is correct regardless of common->capture_last_ptr. */    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1212    capture_last_found = TRUE;      {
1213        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1214        /* This is correct regardless of common->capture_last_ptr. */
1215        capture_last_found = TRUE;
1216        }
1217      cc = next_opcode(common, cc);
1218    }    }
1219    
 cc = next_opcode(common, cc);  
1220  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1221  while (cc < ccend)  while (cc < ccend)
1222    switch(*cc)    switch(*cc)
# Line 1191  while (cc < ccend) Line 1234  while (cc < ccend)
1234    
1235      case OP_MARK:      case OP_MARK:
1236      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
1237        case OP_THEN_ARG:
1238      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1239      stack_restore = TRUE;      stack_restore = TRUE;
1240      if (!setmark_found)      if (!setmark_found)
# Line 1234  while (cc < ccend) Line 1278  while (cc < ccend)
1278        capture_last_found = TRUE;        capture_last_found = TRUE;
1279        }        }
1280      length += 3;      length += 3;
1281      cc += 1 + LINK_SIZE + IMM2_SIZE;      cc += 1 + LINK_SIZE + IMM2_SIZE;
1282      break;      break;
   
     case OP_PRUNE:  
     case OP_SKIP:  
     case OP_COMMIT:  
     if (common->control_head_ptr != 0)  
       *needs_control_head = TRUE;  
     /* Fall through. */  
1283    
1284      default:      default:
1285      stack_restore = TRUE;      stack_restore = TRUE;
# Line 1326  if (length > 0) Line 1363  if (length > 0)
1363  return stack_restore ? no_frame : no_stack;  return stack_restore ? no_frame : no_stack;
1364  }  }
1365    
1366  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)
1367  {  {
1368  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);  
1369  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1370  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1371  /* The last capture is a local variable even for recursions. */  /* The last capture is a local variable even for recursions. */
# Line 1341  SLJIT_UNUSED_ARG(stacktop); Line 1377  SLJIT_UNUSED_ARG(stacktop);
1377  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1378    
1379  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1380  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1381    cc = next_opcode(common, cc);    {
1382      ccend = bracketend(cc) - (1 + LINK_SIZE);
1383      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1384        cc = next_opcode(common, cc);
1385      }
1386    
1387  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1388  while (cc < ccend)  while (cc < ccend)
1389    switch(*cc)    switch(*cc)
# Line 1363  while (cc < ccend) Line 1404  while (cc < ccend)
1404    
1405      case OP_MARK:      case OP_MARK:
1406      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
1407        case OP_THEN_ARG:
1408      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1409      if (!setmark_found)      if (!setmark_found)
1410        {        {
# Line 1868  if (save) Line 1910  if (save)
1910  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1911  }  }
1912    
1913    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1914    {
1915    pcre_uchar *end = bracketend(cc);
1916    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1917    
1918    /* Assert captures then. */
1919    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1920      current_offset = NULL;
1921    /* Conditional block does not. */
1922    if (*cc == OP_COND || *cc == OP_SCOND)
1923      has_alternatives = FALSE;
1924    
1925    cc = next_opcode(common, cc);
1926    if (has_alternatives)
1927      current_offset = common->then_offsets + (cc - common->start);
1928    
1929    while (cc < end)
1930      {
1931      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1932        cc = set_then_offsets(common, cc, current_offset);
1933      else
1934        {
1935        if (*cc == OP_ALT && has_alternatives)
1936          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1937        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1938          *current_offset = 1;
1939        cc = next_opcode(common, cc);
1940        }
1941      }
1942    
1943    return end;
1944    }
1945    
1946  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
1947  #undef CASE_ITERATOR_PRIVATE_DATA_2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
1948  #undef CASE_ITERATOR_PRIVATE_DATA_2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
# Line 2015  else Line 2090  else
2090  OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2091  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2092    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2093  SLJIT_ASSERT(common->control_head_ptr != 0);  if (common->control_head_ptr != 0)
2094  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2095  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2096  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2097  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2098  }  }
2099    
2100  static sljit_sw SLJIT_CALL do_check_control_chain(sljit_sw *current)  static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2101  {  {
2102  sljit_sw return_value = 0;  while (current != NULL)
   
 SLJIT_ASSERT(current != NULL);  
 do  
2103    {    {
2104    switch (current[-2])    switch (current[-2])
2105      {      {
2106      case type_commit:      case type_then_trap:
     /* Commit overwrites all. */  
     return -1;  
   
     case type_prune:  
2107      break;      break;
2108    
2109      case type_skip:      case type_mark:
2110      /* Overwrites prune, but not other skips. */      if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2111      if (return_value == 0)        return current[-4];
       return_value = current[-3];  
2112      break;      break;
2113    
2114      default:      default:
# Line 2050  do Line 2117  do
2117      }      }
2118    current = (sljit_sw*)current[-1];    current = (sljit_sw*)current[-1];
2119    }    }
2120  while (current != NULL);  return -1;
 return return_value;  
2121  }  }
2122    
2123  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
# Line 5259  DEFINE_COMPILER; Line 5325  DEFINE_COMPILER;
5325  backtrack_common *backtrack;  backtrack_common *backtrack;
5326  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5327  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5328  int start = GET(cc, 1);  sljit_sw start = GET(cc, 1);
5329  pcre_uchar *start_cc;  pcre_uchar *start_cc;
5330  BOOL needs_control_head;  BOOL needs_control_head;
5331    
5332  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5333    
5334  /* Inlining simple patterns. */  /* Inlining simple patterns. */
5335  if (get_framesize(common, common->start + start, TRUE, &needs_control_head) == no_stack)  if (get_framesize(common, common->start + start, NULL, TRUE, &needs_control_head) == no_stack)
5336    {    {
5337    start_cc = common->start + start;    start_cc = common->start + start;
5338    compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);    compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
# Line 5436  jump_list *tmp = NULL; Line 5502  jump_list *tmp = NULL;
5502  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5503  jump_list **found;  jump_list **found;
5504  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5505    BOOL save_local_exit = common->local_exit;
5506    BOOL save_positive_assert = common->positive_assert;
5507    then_trap_backtrack *save_then_trap = common->then_trap;
5508  struct sljit_label *save_quit_label = common->quit_label;  struct sljit_label *save_quit_label = common->quit_label;
5509  struct sljit_label *save_accept_label = common->accept_label;  struct sljit_label *save_accept_label = common->accept_label;
5510  jump_list *save_quit = common->quit;  jump_list *save_quit = common->quit;
5511    jump_list *save_positive_assert_quit = common->positive_assert_quit;
5512  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
 BOOL save_local_exit = common->local_exit;  
5513  struct sljit_jump *jump;  struct sljit_jump *jump;
5514  struct sljit_jump *brajump = NULL;  struct sljit_jump *brajump = NULL;
5515    
5516    /* Assert captures then. */
5517    common->then_trap = NULL;
5518    
5519  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
5520    {    {
5521    SLJIT_ASSERT(!conditional);    SLJIT_ASSERT(!conditional);
# Line 5452  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 5524  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
5524    }    }
5525  private_data_ptr = PRIVATE_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
5526  SLJIT_ASSERT(private_data_ptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
5527  framesize = get_framesize(common, cc, FALSE, &needs_control_head);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
5528  backtrack->framesize = framesize;  backtrack->framesize = framesize;
5529  backtrack->private_data_ptr = private_data_ptr;  backtrack->private_data_ptr = private_data_ptr;
5530  opcode = *cc;  opcode = *cc;
# Line 5502  else Line 5574  else
5574      }      }
5575    else    else
5576      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5577    init_frame(common, ccbegin, framesize + extrasize - 1, extrasize, FALSE);    init_frame(common, ccbegin, NULL, framesize + extrasize - 1, extrasize, FALSE);
5578    }    }
5579    
5580  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
5581  common->local_exit = TRUE;  if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5582  common->quit_label = NULL;    {
5583  common->quit = NULL;    /* Negative assert is stronger than positive assert. */
5584      common->local_exit = TRUE;
5585      common->quit_label = NULL;
5586      common->quit = NULL;
5587      common->positive_assert = FALSE;
5588      }
5589    else
5590      common->positive_assert = TRUE;
5591    common->positive_assert_quit = NULL;
5592    
5593  while (1)  while (1)
5594    {    {
5595    common->accept_label = NULL;    common->accept_label = NULL;
# Line 5523  while (1) Line 5604  while (1)
5604    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
5605    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5606      {      {
5607      common->local_exit = save_local_exit;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5608      common->quit_label = save_quit_label;        {
5609          common->local_exit = save_local_exit;
5610          common->quit_label = save_quit_label;
5611          common->quit = save_quit;
5612          }
5613        common->positive_assert = save_positive_assert;
5614        common->then_trap = save_then_trap;
5615      common->accept_label = save_accept_label;      common->accept_label = save_accept_label;
5616      common->quit = save_quit;      common->positive_assert_quit = save_positive_assert_quit;
5617      common->accept = save_accept;      common->accept = save_accept;
5618      return NULL;      return NULL;
5619      }      }
# Line 5591  while (1) Line 5678  while (1)
5678    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
5679    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5680      {      {
5681      common->local_exit = save_local_exit;      if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5682      common->quit_label = save_quit_label;        {
5683          common->local_exit = save_local_exit;
5684          common->quit_label = save_quit_label;
5685          common->quit = save_quit;
5686          }
5687        common->positive_assert = save_positive_assert;
5688        common->then_trap = save_then_trap;
5689      common->accept_label = save_accept_label;      common->accept_label = save_accept_label;
5690      common->quit = save_quit;      common->positive_assert_quit = save_positive_assert_quit;
5691      common->accept = save_accept;      common->accept = save_accept;
5692      return NULL;      return NULL;
5693      }      }
# Line 5607  while (1) Line 5700  while (1)
5700    cc += GET(cc, 1);    cc += GET(cc, 1);
5701    }    }
5702    
5703    if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5704      {
5705      SLJIT_ASSERT(common->positive_assert_quit == NULL);
5706      /* Makes the check less complicated below. */
5707      common->positive_assert_quit = common->quit;
5708      }
5709    
5710  /* None of them matched. */  /* None of them matched. */
5711  if (common->quit != NULL)  if (common->positive_assert_quit != NULL)
5712    {    {
5713    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
5714    set_jumps(common->quit, LABEL());    set_jumps(common->positive_assert_quit, LABEL());
5715    SLJIT_ASSERT(framesize != no_stack);    SLJIT_ASSERT(framesize != no_stack);
5716    if (framesize < 0)    if (framesize < 0)
5717      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));
# Line 5771  else Line 5871  else
5871      }      }
5872    }    }
5873    
5874  common->local_exit = save_local_exit;  if (opcode == OP_ASSERT_NOT || opcode == OP_ASSERTBACK_NOT)
5875  common->quit_label = save_quit_label;    {
5876      common->local_exit = save_local_exit;
5877      common->quit_label = save_quit_label;
5878      common->quit = save_quit;
5879      }
5880    common->positive_assert = save_positive_assert;
5881    common->then_trap = save_then_trap;
5882  common->accept_label = save_accept_label;  common->accept_label = save_accept_label;
5883  common->quit = save_quit;  common->positive_assert_quit = save_positive_assert_quit;
5884  common->accept = save_accept;  common->accept = save_accept;
5885  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5886  }  }
# Line 6022  pcre_uchar opcode; Line 6128  pcre_uchar opcode;
6128  int private_data_ptr = 0;  int private_data_ptr = 0;
6129  int offset = 0;  int offset = 0;
6130  int stacksize;  int stacksize;
6131    int repeat_ptr = 0, repeat_length = 0;
6132    int repeat_type = 0, repeat_count = 0;
6133  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
6134  pcre_uchar *matchingpath;  pcre_uchar *matchingpath;
6135  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
# Line 6031  BOOL has_alternatives; Line 6139  BOOL has_alternatives;
6139  BOOL needs_control_head = FALSE;  BOOL needs_control_head = FALSE;
6140  struct sljit_jump *jump;  struct sljit_jump *jump;
6141  struct sljit_jump *skip;  struct sljit_jump *skip;
6142  struct sljit_label *rmaxlabel = NULL;  struct sljit_label *rmax_label = NULL;
6143  struct sljit_jump *braminzerojump = NULL;  struct sljit_jump *braminzero = NULL;
6144    
6145  PUSH_BACKTRACK(sizeof(bracket_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(bracket_backtrack), cc, NULL);
6146    
# Line 6045  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 6153  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
6153    
6154  opcode = *cc;  opcode = *cc;
6155  ccbegin = cc;  ccbegin = cc;
6156  matchingpath = ccbegin + 1 + LINK_SIZE;  matchingpath = bracketend(cc) - 1 - LINK_SIZE;
6157    ket = *matchingpath;
6158    if (ket == OP_KET && PRIVATE_DATA(matchingpath) != 0)
6159      {
6160      repeat_ptr = PRIVATE_DATA(matchingpath);
6161      repeat_length = PRIVATE_DATA(matchingpath + 1);
6162      repeat_type = PRIVATE_DATA(matchingpath + 2);
6163      repeat_count = PRIVATE_DATA(matchingpath + 3);
6164      SLJIT_ASSERT(repeat_length != 0 && repeat_type != 0 && repeat_count != 0);
6165      if (repeat_type == OP_UPTO)
6166        ket = OP_KETRMAX;
6167      if (repeat_type == OP_MINUPTO)
6168        ket = OP_KETRMIN;
6169      }
6170    
6171  if ((opcode == OP_COND || opcode == OP_SCOND) && cc[1 + LINK_SIZE] == OP_DEF)  if ((opcode == OP_COND || opcode == OP_SCOND) && cc[1 + LINK_SIZE] == OP_DEF)
6172    {    {
6173    /* Drop this bracket_backtrack. */    /* Drop this bracket_backtrack. */
6174    parent->top = backtrack->prev;    parent->top = backtrack->prev;
6175    return bracketend(cc);    return matchingpath + 1 + LINK_SIZE + repeat_length;
6176    }    }
6177    
6178  ket = *(bracketend(cc) - 1 - LINK_SIZE);  matchingpath = ccbegin + 1 + LINK_SIZE;
6179  SLJIT_ASSERT(ket == OP_KET || ket == OP_KETRMAX || ket == OP_KETRMIN);  SLJIT_ASSERT(ket == OP_KET || ket == OP_KETRMAX || ket == OP_KETRMIN);
6180  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket == OP_KETRMIN) || (bra == OP_BRAMINZERO && ket == OP_KETRMAX)));  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket == OP_KETRMIN) || (bra == OP_BRAMINZERO && ket == OP_KETRMAX)));
6181  cc += GET(cc, 1);  cc += GET(cc, 1);
# Line 6104  else if (opcode == OP_ONCE || opcode == Line 6225  else if (opcode == OP_ONCE || opcode ==
6225    SLJIT_ASSERT(private_data_ptr != 0);    SLJIT_ASSERT(private_data_ptr != 0);
6226    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;
6227    if (opcode == OP_ONCE)    if (opcode == OP_ONCE)
6228      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, FALSE, &needs_control_head);      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, NULL, FALSE, &needs_control_head);
6229    }    }
6230    
6231  /* Instructions before the first alternative. */  /* Instructions before the first alternative. */
# Line 6134  if (bra == OP_BRAMINZERO) Line 6255  if (bra == OP_BRAMINZERO)
6255    if (ket != OP_KETRMIN)    if (ket != OP_KETRMIN)
6256      {      {
6257      free_stack(common, 1);      free_stack(common, 1);
6258      braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);      braminzero = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);
6259      }      }
6260    else    else
6261      {      {
# Line 6149  if (bra == OP_BRAMINZERO) Line 6270  if (bra == OP_BRAMINZERO)
6270        if (opcode != OP_ONCE || BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)        if (opcode != OP_ONCE || BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
6271          {          {
6272          /* When we come from outside, private_data_ptr contains the previous STR_PTR. */          /* When we come from outside, private_data_ptr contains the previous STR_PTR. */
6273          braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);          braminzero = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6274          }          }
6275        else        else
6276          {          {
6277          /* Except when the whole stack frame must be saved. */          /* Except when the whole stack frame must be saved. */
6278          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6279          braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (BACKTRACK_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_sw));          braminzero = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (BACKTRACK_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_sw));
6280          }          }
6281        JUMPHERE(skip);        JUMPHERE(skip);
6282        }        }
# Line 6168  if (bra == OP_BRAMINZERO) Line 6289  if (bra == OP_BRAMINZERO)
6289      }      }
6290    }    }
6291    
6292    if (repeat_type != 0)
6293      {
6294      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, repeat_count);
6295      if (repeat_type == OP_EXACT)
6296        rmax_label = LABEL();
6297      }
6298    
6299  if (ket == OP_KETRMIN)  if (ket == OP_KETRMIN)
6300    BACKTRACK_AS(bracket_backtrack)->recursive_matchingpath = LABEL();    BACKTRACK_AS(bracket_backtrack)->recursive_matchingpath = LABEL();
6301    
6302  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
6303    {    {
6304    rmaxlabel = LABEL();    rmax_label = LABEL();
6305    if (has_alternatives && opcode != OP_ONCE && opcode < OP_SBRA)    if (has_alternatives && opcode != OP_ONCE && opcode < OP_SBRA && repeat_type == 0)
6306      BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = rmaxlabel;      BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = rmax_label;
6307    }    }
6308    
6309  /* Handling capturing brackets and alternatives. */  /* Handling capturing brackets and alternatives. */
# Line 6254  if (opcode == OP_ONCE) Line 6382  if (opcode == OP_ONCE)
6382        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);
6383        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6384        }        }
6385      init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize, stacksize + 1, FALSE);      init_frame(common, ccbegin, NULL, BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize, stacksize + 1, FALSE);
6386      }      }
6387    }    }
6388  else if (opcode == OP_CBRA || opcode == OP_SCBRA)  else if (opcode == OP_CBRA || opcode == OP_SCBRA)
# Line 6393  if (opcode == OP_ONCE) Line 6521  if (opcode == OP_ONCE)
6521    match_once_common(common, ket, BACKTRACK_AS(bracket_backtrack)->u.framesize, private_data_ptr, has_alternatives, needs_control_head);    match_once_common(common, ket, BACKTRACK_AS(bracket_backtrack)->u.framesize, private_data_ptr, has_alternatives, needs_control_head);
6522    
6523  stacksize = 0;  stacksize = 0;
6524    if (repeat_type == OP_MINUPTO)
6525      {
6526      /* We need to preserve the counter. TMP2 will be used below. */
6527      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr);
6528      stacksize++;
6529      }
6530  if (ket != OP_KET || bra != OP_BRA)  if (ket != OP_KET || bra != OP_BRA)
6531    stacksize++;    stacksize++;
6532  if (offset != 0)  if (offset != 0)
# Line 6409  if (stacksize > 0) Line 6543  if (stacksize > 0)
6543    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6544    
6545  stacksize = 0;  stacksize = 0;
6546    if (repeat_type == OP_MINUPTO)
6547      {
6548      /* TMP2 was set above. */
6549      OP2(SLJIT_SUB, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP2, 0, SLJIT_IMM, 1);
6550      stacksize++;
6551      }
6552    
6553  if (ket != OP_KET || bra != OP_BRA)  if (ket != OP_KET || bra != OP_BRA)
6554    {    {
6555    if (ket != OP_KET)    if (ket != OP_KET)
# Line 6438  if (offset != 0 && common->optimized_cbr Line 6579  if (offset != 0 && common->optimized_cbr
6579    
6580  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
6581    {    {
6582    if (opcode == OP_ONCE || opcode >= OP_SBRA)    if (repeat_type != 0)
6583        {
6584        if (has_alternatives)
6585          BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = LABEL();
6586        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);
6587        JUMPTO(SLJIT_C_NOT_ZERO, rmax_label);
6588        /* Drop STR_PTR for greedy plus quantifier. */
6589        if (opcode != OP_ONCE)
6590          free_stack(common, 1);
6591        }
6592      else if (opcode == OP_ONCE || opcode >= OP_SBRA)
6593      {      {
6594      if (has_alternatives)      if (has_alternatives)
6595        BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = LABEL();        BACKTRACK_AS(bracket_backtrack)->alternative_matchingpath = LABEL();
6596      /* Checking zero-length iteration. */      /* Checking zero-length iteration. */
6597      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
6598        {        {
6599        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0, rmaxlabel);        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STR_PTR, 0, rmax_label);
6600        /* Drop STR_PTR for greedy plus quantifier. */        /* Drop STR_PTR for greedy plus quantifier. */
6601        if (bra != OP_BRAZERO)        if (bra != OP_BRAZERO)
6602          free_stack(common, 1);          free_stack(common, 1);
6603        }        }
6604      else      else
6605        /* TMP2 must contain the starting STR_PTR. */        /* TMP2 must contain the starting STR_PTR. */
6606        CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, rmaxlabel);        CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, rmax_label);
6607      }      }
6608    else    else
6609      JUMPTO(SLJIT_JUMP, rmaxlabel);      JUMPTO(SLJIT_JUMP, rmax_label);
6610    BACKTRACK_AS(bracket_backtrack)->recursive_matchingpath = LABEL();    BACKTRACK_AS(bracket_backtrack)->recursive_matchingpath = LABEL();
6611    }    }
6612    
6613    if (repeat_type == OP_EXACT)
6614      {
6615      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);
6616      JUMPTO(SLJIT_C_NOT_ZERO, rmax_label);
6617      }
6618    else if (repeat_type == OP_UPTO)
6619      {
6620      /* We need to preserve the counter. */
6621      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr);
6622      allocate_stack(common, 1);
6623      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6624      }
6625    
6626  if (bra == OP_BRAZERO)  if (bra == OP_BRAZERO)
6627    BACKTRACK_AS(bracket_backtrack)->zero_matchingpath = LABEL();    BACKTRACK_AS(bracket_backtrack)->zero_matchingpath = LABEL();
6628    
# Line 6466  if (bra == OP_BRAMINZERO) Line 6630  if (bra == OP_BRAMINZERO)
6630    {    {
6631    /* This is a backtrack path! (From the viewpoint of OP_BRAMINZERO) */    /* This is a backtrack path! (From the viewpoint of OP_BRAMINZERO) */
6632    JUMPTO(SLJIT_JUMP, ((braminzero_backtrack *)parent)->matchingpath);    JUMPTO(SLJIT_JUMP, ((braminzero_backtrack *)parent)->matchingpath);
6633    if (braminzerojump != NULL)    if (braminzero != NULL)
6634      {      {
6635      JUMPHERE(braminzerojump);      JUMPHERE(braminzero);
6636      /* We need to release the end pointer to perform the      /* We need to release the end pointer to perform the
6637      backtrack for the zero-length iteration. When      backtrack for the zero-length iteration. When
6638      framesize is < 0, OP_ONCE will do the release itself. */      framesize is < 0, OP_ONCE will do the release itself. */
# Line 6494  cc += 1 + LINK_SIZE; Line 6658  cc += 1 + LINK_SIZE;
6658  /* Temporarily encoding the needs_control_head in framesize. */  /* Temporarily encoding the needs_control_head in framesize. */
6659  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
6660    BACKTRACK_AS(bracket_backtrack)->u.framesize = (BACKTRACK_AS(bracket_backtrack)->u.framesize << 1) | (needs_control_head ? 1 : 0);    BACKTRACK_AS(bracket_backtrack)->u.framesize = (BACKTRACK_AS(bracket_backtrack)->u.framesize << 1) | (needs_control_head ? 1 : 0);
6661  return cc;  return cc + repeat_length;
6662  }  }
6663    
6664  static pcre_uchar *compile_bracketpos_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)  static pcre_uchar *compile_bracketpos_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
# Line 6548  switch(opcode) Line 6712  switch(opcode)
6712    break;    break;
6713    }    }
6714    
6715  framesize = get_framesize(common, cc, FALSE, &needs_control_head);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
6716  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;
6717  if (framesize < 0)  if (framesize < 0)
6718    {    {
# Line 6641  else Line 6805  else
6805      stack++;      stack++;
6806      }      }
6807    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP1, 0);
6808    init_frame(common, cc, stacksize - 1, stacksize - framesize, FALSE);    init_frame(common, cc, NULL, stacksize - 1, stacksize - framesize, FALSE);
6809    stack -= 1 + (offset == 0);    stack -= 1 + (offset == 0);
6810    }    }
6811    
# Line 7148  if (!optimized_cbracket) Line 7312  if (!optimized_cbracket)
7312  return cc + 1 + IMM2_SIZE;  return cc + 1 + IMM2_SIZE;
7313  }  }
7314    
7315    static SLJIT_INLINE pcre_uchar *compile_control_verb_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
7316    {
7317    DEFINE_COMPILER;
7318    backtrack_common *backtrack;
7319    pcre_uchar opcode = *cc;
7320    pcre_uchar *ccend = cc + 1;
7321    
7322    if (opcode == OP_PRUNE_ARG || opcode == OP_SKIP_ARG || opcode == OP_THEN_ARG)
7323      ccend += 2 + cc[1];
7324    
7325    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
7326    
7327    if (opcode == OP_SKIP)
7328      {
7329      allocate_stack(common, 1);
7330      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
7331      return ccend;
7332      }
7333    
7334    if (opcode == OP_PRUNE_ARG || opcode == OP_THEN_ARG)
7335      {
7336      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
7337      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));
7338      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);
7339      OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);
7340      }
7341    
7342    return ccend;
7343    }
7344    
7345    static pcre_uchar then_trap_opcode[1] = { OP_THEN_TRAP };
7346    
7347    static SLJIT_INLINE void compile_then_trap_matchingpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, backtrack_common *parent)
7348    {
7349    DEFINE_COMPILER;
7350    backtrack_common *backtrack;
7351    BOOL needs_control_head;
7352    int size;
7353    
7354    PUSH_BACKTRACK_NOVALUE(sizeof(then_trap_backtrack), cc);
7355    common->then_trap = BACKTRACK_AS(then_trap_backtrack);
7356    BACKTRACK_AS(then_trap_backtrack)->common.cc = then_trap_opcode;
7357    BACKTRACK_AS(then_trap_backtrack)->start = (sljit_sw)(cc - common->start);
7358    BACKTRACK_AS(then_trap_backtrack)->framesize = get_framesize(common, cc, ccend, FALSE, &needs_control_head);
7359    
7360    size = BACKTRACK_AS(then_trap_backtrack)->framesize;
7361    size = 3 + (size < 0 ? 0 : size);
7362    
7363    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
7364    allocate_stack(common, size);
7365    if (size > 3)
7366      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0, SLJIT_IMM, (size - 3) * sizeof(sljit_sw));
7367    else
7368      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);
7369    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 1), SLJIT_IMM, BACKTRACK_AS(then_trap_backtrack)->start);
7370    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 2), SLJIT_IMM, type_then_trap);
7371    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 3), TMP2, 0);
7372    
7373    size = BACKTRACK_AS(then_trap_backtrack)->framesize;
7374    if (size >= 0)
7375      init_frame(common, cc, ccend, size - 1, 0, FALSE);
7376    }
7377    
7378  static void compile_matchingpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, backtrack_common *parent)  static void compile_matchingpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, backtrack_common *parent)
7379  {  {
7380  DEFINE_COMPILER;  DEFINE_COMPILER;
7381  backtrack_common *backtrack;  backtrack_common *backtrack;
7382    BOOL has_then_trap = FALSE;
7383    then_trap_backtrack *save_then_trap = NULL;
7384    
7385    SLJIT_ASSERT(*ccend == OP_END || (*ccend >= OP_ALT && *ccend <= OP_KETRPOS));
7386    
7387    if (common->has_then && common->then_offsets[cc - common->start] != 0)
7388      {
7389      SLJIT_ASSERT(*ccend != OP_END && common->control_head_ptr != 0);
7390      has_then_trap = TRUE;
7391      save_then_trap = common->then_trap;
7392      /* Tail item on backtrack. */
7393      compile_then_trap_matchingpath(common, cc, ccend, parent);
7394      }
7395    
7396  while (cc < ccend)  while (cc < ccend)
7397    {    {
# Line 7368  while (cc < ccend) Line 7608  while (cc < ccend)
7608      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);
7609      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
7610      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr);
7611      allocate_stack(common, 1);      allocate_stack(common, common->has_skip_arg ? 5 : 1);
7612      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
7613      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(common->has_skip_arg ? 4 : 0), TMP2, 0);
7614      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));
7615      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);
7616      OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);
7617        if (common->has_skip_arg)
7618          {
7619          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
7620          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);
7621          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, type_mark);
7622          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), SLJIT_IMM, (sljit_sw)(cc + 2));
7623          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(3), STR_PTR, 0);
7624          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
7625          }
7626      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
7627      break;      break;
7628    
     case OP_PRUNE_ARG:  
     OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  
     OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);  
     /* Fall through. */  
   
7629      case OP_PRUNE:      case OP_PRUNE:
7630      case OP_COMMIT:      case OP_PRUNE_ARG:
     PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);  
     SLJIT_ASSERT(common->control_head_ptr != 0);  
     OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);  
     allocate_stack(common, 2);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, *cc == OP_COMMIT ? type_commit : type_prune);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);  
     cc += (*cc == OP_PRUNE_ARG) ? (1 + 2 + cc[1]) : 1;  
     break;  
   
7631      case OP_SKIP:      case OP_SKIP:
7632      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);      case OP_SKIP_ARG:
7633      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);      case OP_THEN:
7634      allocate_stack(common, 3);      case OP_THEN_ARG:
7635      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);      case OP_COMMIT:
7636      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, type_skip);      cc = compile_control_verb_matchingpath(common, cc, parent);
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), STR_PTR, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);  
     cc += 1;  
7637      break;      break;
7638    
7639      case OP_FAIL:      case OP_FAIL:
# Line 7428  while (cc < ccend) Line 7657  while (cc < ccend)
7657    if (cc == NULL)    if (cc == NULL)
7658      return;      return;
7659    }    }
7660    
7661    if (has_then_trap)
7662      {
7663      /* Head item on backtrack. */
7664      PUSH_BACKTRACK_NOVALUE(sizeof(then_trap_backtrack), cc);
7665      BACKTRACK_AS(then_trap_backtrack)->common.cc = then_trap_opcode;
7666      BACKTRACK_AS(then_trap_backtrack)->then_trap = common->then_trap;
7667      common->then_trap = save_then_trap;
7668      }
7669  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
7670  }  }
7671    
# Line 7589  switch(opcode) Line 7827  switch(opcode)
7827    }    }
7828  }  }
7829    
7830  static void compile_ref_iterator_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static SLJIT_INLINE void compile_ref_iterator_backtrackingpath(compiler_common *common, struct backtrack_common *current)
7831  {  {
7832  DEFINE_COMPILER;  DEFINE_COMPILER;
7833  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
# Line 7611  set_jumps(current->topbacktracks, LABEL( Line 7849  set_jumps(current->topbacktracks, LABEL(
7849  free_stack(common, 2);  free_stack(common, 2);
7850  }  }
7851    
7852  static void compile_recurse_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static SLJIT_INLINE void compile_recurse_backtrackingpath(compiler_common *common, struct backtrack_common *current)
7853  {  {
7854  DEFINE_COMPILER;  DEFINE_COMPILER;
7855    
# Line 7707  if (bra == OP_BRAZERO) Line 7945  if (bra == OP_BRAZERO)
7945  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static void compile_bracket_backtrackingpath(compiler_common *common, struct backtrack_common *current)
7946  {  {
7947  DEFINE_COMPILER;  DEFINE_COMPILER;
7948  int opcode;  int opcode, stacksize, count;
7949  int offset = 0;  int offset = 0;
7950  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;  int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr;
7951  int stacksize;  int repeat_ptr = 0, repeat_type = 0, repeat_count = 0;
 int count;  
7952  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
7953  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
7954  pcre_uchar *ccprev;  pcre_uchar *ccprev;
# Line 7725  BOOL needs_control_head = FALSE; Line 7962  BOOL needs_control_head = FALSE;
7962  struct sljit_jump *brazero = NULL;  struct sljit_jump *brazero = NULL;
7963  struct sljit_jump *once = NULL;  struct sljit_jump *once = NULL;
7964  struct sljit_jump *cond = NULL;  struct sljit_jump *cond = NULL;
7965  struct sljit_label *rminlabel = NULL;  struct sljit_label *rmin_label = NULL;
7966    struct sljit_label *exact_label = NULL;
7967    
7968  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
7969    {    {
# Line 7734  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 7972  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
7972    }    }
7973    
7974  opcode = *cc;  opcode = *cc;
7975    ccbegin = bracketend(cc) - 1 - LINK_SIZE;
7976    ket = *ccbegin;
7977    if (ket == OP_KET && PRIVATE_DATA(ccbegin) != 0)
7978      {
7979      repeat_ptr = PRIVATE_DATA(ccbegin);
7980      repeat_type = PRIVATE_DATA(ccbegin + 2);
7981      repeat_count = PRIVATE_DATA(ccbegin + 3);
7982      SLJIT_ASSERT(repeat_type != 0 && repeat_count != 0);
7983      if (repeat_type == OP_UPTO)
7984        ket = OP_KETRMAX;
7985      if (repeat_type == OP_MINUPTO)
7986        ket = OP_KETRMIN;
7987      }
7988  ccbegin = cc;  ccbegin = cc;
 ket = *(bracketend(ccbegin) - 1 - LINK_SIZE);  
7989  cc += GET(cc, 1);  cc += GET(cc, 1);
7990  has_alternatives = *cc == OP_ALT;  has_alternatives = *cc == OP_ALT;
7991  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))
# Line 7754  if (opcode == OP_ONCE) Line 8004  if (opcode == OP_ONCE)
8004    CURRENT_AS(bracket_backtrack)->u.framesize >>= 1;    CURRENT_AS(bracket_backtrack)->u.framesize >>= 1;
8005    }    }
8006    
8007    if (ket != OP_KET && repeat_type != 0)
8008      {
8009      /* TMP1 is used in OP_KETRMIN below. */
8010      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8011      free_stack(common, 1);
8012      if (repeat_type == OP_UPTO)
8013        OP2(SLJIT_ADD, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, TMP1, 0, SLJIT_IMM, 1);
8014      else
8015        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, TMP1, 0);
8016      }
8017    
8018  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
8019    {    {
8020    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
# Line 7768  else if (ket == OP_KETRMIN) Line 8029  else if (ket == OP_KETRMIN)
8029    if (bra != OP_BRAMINZERO)    if (bra != OP_BRAMINZERO)
8030      {      {
8031      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8032      if (opcode >= OP_SBRA || opcode == OP_ONCE)      if (repeat_type != 0)
8033          {
8034          /* TMP1 was set a few lines above. */
8035          CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, CURRENT_AS(bracket_backtrack)->recursive_matchingpath);
8036          /* Drop STR_PTR for non-greedy plus quantifier. */
8037          if (opcode != OP_ONCE)
8038            free_stack(common, 1);
8039          }
8040        else if (opcode >= OP_SBRA || opcode == OP_ONCE)
8041        {        {
8042        /* Checking zero-length iteration. */        /* Checking zero-length iteration. */
8043        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize < 0)        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize < 0)
# Line 7778  else if (ket == OP_KETRMIN) Line 8047  else if (ket == OP_KETRMIN)
8047          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
8048          CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (CURRENT_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_sw), CURRENT_AS(bracket_backtrack)->recursive_matchingpath);          CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (CURRENT_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_sw), CURRENT_AS(bracket_backtrack)->recursive_matchingpath);
8049          }          }
8050          /* Drop STR_PTR for non-greedy plus quantifier. */
8051        if (opcode != OP_ONCE)        if (opcode != OP_ONCE)
8052          free_stack(common, 1);          free_stack(common, 1);
8053        }        }
8054      else      else
8055        JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->recursive_matchingpath);        JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->recursive_matchingpath);
8056      }      }
8057    rminlabel = LABEL();    rmin_label = LABEL();
8058      if (repeat_type != 0)
8059        OP2(SLJIT_ADD, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);
8060    }    }
8061  else if (bra == OP_BRAZERO)  else if (bra == OP_BRAZERO)
8062    {    {
# Line 7792  else if (bra == OP_BRAZERO) Line 8064  else if (bra == OP_BRAZERO)
8064    free_stack(common, 1);    free_stack(common, 1);
8065    brazero = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0);    brazero = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0);
8066    }    }
8067    else if (repeat_type == OP_EXACT)
8068      {
8069      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);
8070      exact_label = LABEL();
8071      }
8072    
8073  if (offset != 0)  if (offset != 0)
8074    {    {
# Line 7939  if (has_alternatives) Line 8216  if (has_alternatives)
8216        match_once_common(common, ket, CURRENT_AS(bracket_backtrack)->u.framesize, private_data_ptr, has_alternatives, needs_control_head);        match_once_common(common, ket, CURRENT_AS(bracket_backtrack)->u.framesize, private_data_ptr, has_alternatives, needs_control_head);
8217    
8218      stacksize = 0;      stacksize = 0;
8219        if (repeat_type == OP_MINUPTO)
8220          {
8221          /* We need to preserve the counter. TMP2 will be used below. */
8222          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr);
8223          stacksize++;
8224          }
8225      if (ket != OP_KET || bra != OP_BRA)      if (ket != OP_KET || bra != OP_BRA)
8226        stacksize++;        stacksize++;
8227      if (offset != 0)      if (offset != 0)
# Line 7952  if (has_alternatives) Line 8235  if (has_alternatives)
8235        stacksize++;        stacksize++;
8236    
8237      if (stacksize > 0)      if (stacksize > 0)
8238          allocate_stack(common, stacksize);
8239    
8240        stacksize = 0;
8241        if (repeat_type == OP_MINUPTO)
8242        {        {
8243        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize >= 0)        /* TMP2 was set above. */
8244          allocate_stack(common, stacksize);        OP2(SLJIT_SUB, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP2, 0, SLJIT_IMM, 1);
8245        else        stacksize++;
         {  
         /* We know we have place at least for one item on the top of the stack. */  
         SLJIT_ASSERT(stacksize == 1);  
         OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));  
         }  
8246        }        }
8247    
     stacksize = 0;  
8248      if (ket != OP_KET || bra != OP_BRA)      if (ket != OP_KET || bra != OP_BRA)
8249        {        {
8250        if (ket != OP_KET)        if (ket != OP_KET)
# Line 8074  else if (opcode == OP_ONCE) Line 8355  else if (opcode == OP_ONCE)
8355      }      }
8356    }    }
8357    
8358  if (ket == OP_KETRMAX)  if (repeat_type == OP_EXACT)
8359      {
8360      OP2(SLJIT_ADD, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, SLJIT_IMM, 1);
8361      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), repeat_ptr, TMP1, 0);
8362      CMPTO(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, repeat_count, exact_label);
8363      }
8364    else if (ket == OP_KETRMAX)
8365    {    {
8366    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8367    if (bra != OP_BRAZERO)    if (bra != OP_BRAZERO)
8368      free_stack(common, 1);      free_stack(common, 1);
8369    
8370    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(bracket_backtrack)->recursive_matchingpath);    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(bracket_backtrack)->recursive_matchingpath);
8371    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
8372      {      {
# Line 8097  else if (ket == OP_KETRMIN) Line 8385  else if (ket == OP_KETRMIN)
8385    affect badly the free_stack(2) above. */    affect badly the free_stack(2) above. */
8386    if (opcode != OP_ONCE)    if (opcode != OP_ONCE)
8387      free_stack(common, 1);      free_stack(common, 1);
8388    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, rminlabel);    CMPTO(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, 0, rmin_label);
8389    if (opcode == OP_ONCE)    if (opcode == OP_ONCE)
8390      free_stack(common, bra == OP_BRAMINZERO ? 2 : 1);      free_stack(common, bra == OP_BRAMINZERO ? 2 : 1);
8391    else if (bra == OP_BRAMINZERO)    else if (bra == OP_BRAMINZERO)
# Line 8111  else if (bra == OP_BRAZERO) Line 8399  else if (bra == OP_BRAZERO)
8399    }    }
8400  }  }
8401    
8402  static void compile_bracketpos_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static SLJIT_INLINE void compile_bracketpos_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8403  {  {
8404  DEFINE_COMPILER;  DEFINE_COMPILER;
8405  int offset;  int offset;
# Line 8150  if (current->topbacktracks) Line 8438  if (current->topbacktracks)
8438  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(bracketpos_backtrack)->private_data_ptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(bracketpos_backtrack)->framesize * sizeof(sljit_sw));  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(bracketpos_backtrack)->private_data_ptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(bracketpos_backtrack)->framesize * sizeof(sljit_sw));
8439  }  }
8440    
8441  static void compile_braminzero_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static SLJIT_INLINE void compile_braminzero_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8442  {  {
8443  assert_backtrack backtrack;  assert_backtrack backtrack;
8444    
# Line 8174  else Line 8462  else
8462  SLJIT_ASSERT(!current->nextbacktracks && !current->topbacktracks);  SLJIT_ASSERT(!current->nextbacktracks && !current->topbacktracks);
8463  }  }
8464    
8465    static SLJIT_INLINE void compile_control_verb_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8466    {
8467    DEFINE_COMPILER;
8468    pcre_uchar opcode = *current->cc;
8469    struct sljit_label *loop;
8470    struct sljit_jump *jump;
8471    
8472    if (opcode == OP_THEN || opcode == OP_THEN_ARG)
8473      {
8474      if (common->then_trap != NULL)
8475        {
8476        SLJIT_ASSERT(common->control_head_ptr != 0);
8477    
8478        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
8479        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, type_then_trap);
8480        OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, common->then_trap->start);
8481        jump = JUMP(SLJIT_JUMP);
8482    
8483        loop = LABEL();
8484        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), -(int)sizeof(sljit_sw));
8485        JUMPHERE(jump);
8486        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(STACK_TOP), -(int)(2 * sizeof(sljit_sw)), TMP1, 0, loop);
8487        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(STACK_TOP), -(int)(3 * sizeof(sljit_sw)), TMP2, 0, loop);
8488        add_jump(compiler, &common->then_trap->quit, JUMP(SLJIT_JUMP));
8489        return;
8490        }
8491      else if (common->positive_assert)
8492        {
8493        add_jump(compiler, &common->positive_assert_quit, JUMP(SLJIT_JUMP));
8494        return;
8495        }
8496      }
8497    
8498    if (common->local_exit)
8499      {
8500      if (common->quit_label == NULL)
8501        add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));
8502      else
8503        JUMPTO(SLJIT_JUMP, common->quit_label);
8504      return;
8505      }
8506    
8507    if (opcode == OP_SKIP_ARG)
8508      {
8509      SLJIT_ASSERT(common->control_head_ptr != 0);
8510      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
8511      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
8512      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, (sljit_sw)(current->cc + 2));
8513      sljit_emit_ijump(compiler, SLJIT_CALL2, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_search_mark));
8514      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
8515    
8516      OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
8517      add_jump(compiler, &common->reset_match, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, -1));
8518      return;
8519      }
8520    
8521    if (opcode == OP_SKIP)
8522      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8523    else
8524      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_IMM, 0);
8525    add_jump(compiler, &common->reset_match, JUMP(SLJIT_JUMP));
8526    }
8527    
8528    static SLJIT_INLINE void compile_then_trap_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8529    {
8530    DEFINE_COMPILER;
8531    struct sljit_jump *jump;
8532    int size;
8533    
8534    if (CURRENT_AS(then_trap_backtrack)->then_trap)
8535      {
8536      common->then_trap = CURRENT_AS(then_trap_backtrack)->then_trap;
8537      return;
8538      }
8539    
8540    size = CURRENT_AS(then_trap_backtrack)->framesize;
8541    size = 3 + (size < 0 ? 0 : size);
8542    
8543    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(size - 3));
8544    free_stack(common, size);
8545    jump = JUMP(SLJIT_JUMP);
8546    
8547    set_jumps(CURRENT_AS(then_trap_backtrack)->quit, LABEL());
8548    /* STACK_TOP is set by THEN. */
8549    if (CURRENT_AS(then_trap_backtrack)->framesize >= 0)
8550      add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
8551    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8552    free_stack(common, 3);
8553    
8554    JUMPHERE(jump);
8555    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP1, 0);
8556    }
8557    
8558  static void compile_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static void compile_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8559  {  {
8560  DEFINE_COMPILER;  DEFINE_COMPILER;
8561    then_trap_backtrack *save_then_trap = common->then_trap;
8562    
8563  while (current)  while (current)
8564    {    {
# Line 8310  while (current) Line 8692  while (current)
8692      break;      break;
8693    
8694      case OP_MARK:      case OP_MARK:
8695      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(common->has_skip_arg ? 4 : 0));
8696      free_stack(common, 1);      if (common->has_skip_arg)
8697          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8698        free_stack(common, common->has_skip_arg ? 5 : 1);
8699      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP1, 0);
8700        if (common->has_skip_arg)
8701          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP2, 0);
8702      break;      break;
8703    
8704        case OP_THEN:
8705        case OP_THEN_ARG:
8706      case OP_PRUNE:      case OP_PRUNE:
8707      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
8708      case OP_SKIP:      case OP_SKIP:
8709      if (!common->local_exit)      case OP_SKIP_ARG:
8710        {      compile_control_verb_backtrackingpath(common, current);
       SLJIT_ASSERT(common->control_head_ptr != 0);  
       OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);  
       sljit_emit_ijump(compiler, SLJIT_CALL1, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_check_control_chain));  
       OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  
   
       OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);  
       add_jump(compiler, &common->reset_match, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, -1));  
   
       OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);  
       }  
   
     /* Commit or in recurse or accept. */  
     if (common->quit_label == NULL)  
       add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));  
     else  
       JUMPTO(SLJIT_JUMP, common->quit_label);  
8711      break;      break;
8712    
8713      case OP_COMMIT:      case OP_COMMIT:
# Line 8355  while (current) Line 8726  while (current)
8726      set_jumps(current->topbacktracks, LABEL());      set_jumps(current->topbacktracks, LABEL());
8727      break;      break;
8728    
8729        case OP_THEN_TRAP:
8730        /* A virtual opcode for then traps. */
8731        compile_then_trap_backtrackingpath(common, current);
8732        break;
8733    
8734      default:      default:
8735      SLJIT_ASSERT_STOP();      SLJIT_ASSERT_STOP();
8736      break;      break;
8737      }      }
8738    current = current->prev;    current = current->prev;
8739    }    }
8740    common->then_trap = save_then_trap;
8741  }  }
8742    
8743  static SLJIT_INLINE void compile_recurse(compiler_common *common)  static SLJIT_INLINE void compile_recurse(compiler_common *common)
# Line 8370  pcre_uchar *cc = common->start + common- Line 8747  pcre_uchar *cc = common->start + common-
8747  pcre_uchar *ccbegin = cc + 1 + LINK_SIZE + (*cc == OP_BRA ? 0 : IMM2_SIZE);  pcre_uchar *ccbegin = cc + 1 + LINK_SIZE + (*cc == OP_BRA ? 0 : IMM2_SIZE);
8748  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc);
8749  BOOL needs_control_head;  BOOL needs_control_head;
8750  int framesize = get_framesize(common, cc, TRUE, &needs_control_head);  int framesize = get_framesize(common, cc, NULL, TRUE, &needs_control_head);
8751  int private_data_size = get_private_data_copy_length(common, ccbegin, ccend, needs_control_head);  int private_data_size = get_private_data_copy_length(common, ccbegin, ccend, needs_control_head);
8752  int alternativesize;  int alternativesize;
8753  BOOL needs_frame;  BOOL needs_frame;
8754  backtrack_common altbacktrack;  backtrack_common altbacktrack;
8755  struct sljit_jump *jump;  struct sljit_jump *jump;
8756    
8757    /* Recurse captures then. */
8758    common->then_trap = NULL;
8759    
8760  SLJIT_ASSERT(*cc == OP_BRA || *cc == OP_CBRA || *cc == OP_CBRAPOS || *cc == OP_SCBRA || *cc == OP_SCBRAPOS);  SLJIT_ASSERT(*cc == OP_BRA || *cc == OP_CBRA || *cc == OP_CBRAPOS || *cc == OP_SCBRA || *cc == OP_SCBRAPOS);
8761  needs_frame = framesize >= 0;  needs_frame = framesize >= 0;
8762  if (!needs_frame)  if (!needs_frame)
# Line 8395  if (needs_control_head) Line 8775  if (needs_control_head)
8775    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
8776  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr, STACK_TOP, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr, STACK_TOP, 0);
8777  if (needs_frame)  if (needs_frame)
8778    init_frame(common, cc, framesize + alternativesize - 1, alternativesize, TRUE);    init_frame(common, cc, NULL, framesize + alternativesize - 1, alternativesize, TRUE);
8779    
8780  if (alternativesize > 0)  if (alternativesize > 0)
8781    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
# Line 8590  SLJIT_ASSERT(*rootbacktrack.cc == OP_BRA Line 8970  SLJIT_ASSERT(*rootbacktrack.cc == OP_BRA
8970  common->capture_last_ptr = common->ovector_start;  common->capture_last_ptr = common->ovector_start;
8971  common->ovector_start += sizeof(sljit_sw);  common->ovector_start += sizeof(sljit_sw);
8972  #endif  #endif
8973  private_data_size = get_private_data_length(common, rootbacktrack.cc, ccend);  if (!check_opcode_types(common, rootbacktrack.cc, ccend))
 if (private_data_size < 0)  
8974    {    {
8975    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
8976    return;    return;
# Line 8653  if (common->capture_last_ptr != 0) Line 9032  if (common->capture_last_ptr != 0)
9032    
9033  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));  SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0));
9034  common->cbra_ptr = OVECTOR_START + (re->top_bracket + 1) * 2 * sizeof(sljit_sw);  common->cbra_ptr = OVECTOR_START + (re->top_bracket + 1) * 2 * sizeof(sljit_sw);
9035  private_data_size += common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw);  
9036  if (private_data_size > SLJIT_MAX_LOCAL_SIZE)  common->private_data_ptrs = (int *)SLJIT_MALLOC((ccend - rootbacktrack.cc) * sizeof(sljit_si));
9037    if (!common->private_data_ptrs)
9038    {    {
9039    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9040    return;    return;
9041    }    }
9042  common->private_data_ptrs = (int *)SLJIT_MALLOC((ccend - rootbacktrack.cc) * sizeof(int));  memset(common->private_data_ptrs, 0, (ccend - rootbacktrack.cc) * sizeof(int));
9043  if (!common->private_data_ptrs)  
9044    private_data_size = common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw);
9045    set_private_data_ptrs(common, &private_data_size, ccend);
9046    if (private_data_size > SLJIT_MAX_LOCAL_SIZE)
9047    {    {
9048      SLJIT_FREE(common->private_data_ptrs);
9049    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9050    return;    return;
9051    }    }
9052  memset(common->private_data_ptrs, 0, (ccend - rootbacktrack.cc) * sizeof(int));  
9053  set_private_data_ptrs(common, common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw), ccend);  if (common->has_then)
9054      {
9055      common->then_offsets = (pcre_uint8 *)SLJIT_MALLOC(ccend - rootbacktrack.cc);
9056      if (!common->then_offsets)
9057        {
9058        SLJIT_FREE(common->optimized_cbracket);
9059        SLJIT_FREE(common->private_data_ptrs);
9060        return;
9061        }
9062      memset(common->then_offsets, 0, ccend - rootbacktrack.cc);
9063      set_then_offsets(common, rootbacktrack.cc, NULL);
9064      }
9065    
9066  compiler = sljit_create_compiler();  compiler = sljit_create_compiler();
9067  if (!compiler)  if (!compiler)
9068    {    {
9069    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9070    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
9071      if (common->has_then)
9072        SLJIT_FREE(common->then_offsets);
9073    return;    return;
9074    }    }
9075  common->compiler = compiler;  common->compiler = compiler;
# Line 8764  if (SLJIT_UNLIKELY(sljit_get_compiler_er Line 9161  if (SLJIT_UNLIKELY(sljit_get_compiler_er
9161    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
9162    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9163    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
9164      if (common->has_then)
9165        SLJIT_FREE(common->then_offsets);
9166    return;    return;
9167    }    }
9168    
# Line 8799  if (SLJIT_UNLIKELY(sljit_get_compiler_er Line 9198  if (SLJIT_UNLIKELY(sljit_get_compiler_er
9198    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
9199    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9200    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
9201      if (common->has_then)
9202        SLJIT_FREE(common->then_offsets);
9203    return;    return;
9204    }    }
9205    
# Line 8866  while (common->currententry != NULL) Line 9267  while (common->currententry != NULL)
9267      sljit_free_compiler(compiler);      sljit_free_compiler(compiler);
9268      SLJIT_FREE(common->optimized_cbracket);      SLJIT_FREE(common->optimized_cbracket);
9269      SLJIT_FREE(common->private_data_ptrs);      SLJIT_FREE(common->private_data_ptrs);
9270        if (common->has_then)
9271          SLJIT_FREE(common->then_offsets);
9272      return;      return;
9273      }      }
9274    flush_stubs(common);    flush_stubs(common);
# Line 8974  if (common->getucd != NULL) Line 9377  if (common->getucd != NULL)
9377    
9378  SLJIT_FREE(common->optimized_cbracket);  SLJIT_FREE(common->optimized_cbracket);
9379  SLJIT_FREE(common->private_data_ptrs);  SLJIT_FREE(common->private_data_ptrs);
9380    if (common->has_then)
9381      SLJIT_FREE(common->then_offsets);
9382    
9383  executable_func = sljit_generate_code(compiler);  executable_func = sljit_generate_code(compiler);
9384  executable_size = sljit_get_generated_code_size(compiler);  executable_size = sljit_get_generated_code_size(compiler);
9385  sljit_free_compiler(compiler);  sljit_free_compiler(compiler);

Legend:
Removed from v.1277  
changed lines
  Added in v.1307

  ViewVC Help
Powered by ViewVC 1.1.5