/[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 958 by zherczeg, Wed Apr 11 10:19:10 2012 UTC revision 987 by zherczeg, Sat Jul 7 04:11:29 2012 UTC
# Line 82  The code generator follows the recursive Line 82  The code generator follows the recursive
82  expressions. The basic blocks of regular expressions are condition checkers  expressions. The basic blocks of regular expressions are condition checkers
83  whose execute different commands depending on the result of the condition check.  whose execute different commands depending on the result of the condition check.
84  The relationship between the operators can be horizontal (concatenation) and  The relationship between the operators can be horizontal (concatenation) and
85  vertical (sub-expression) (See struct fallback_common for more details).  vertical (sub-expression) (See struct backtrack_common for more details).
86    
87    'ab' - 'a' and 'b' regexps are concatenated    'ab' - 'a' and 'b' regexps are concatenated
88    'a+' - 'a' is the sub-expression of the '+' operator    'a+' - 'a' is the sub-expression of the '+' operator
89    
90  The condition checkers are boolean (true/false) checkers. Machine code is generated  The condition checkers are boolean (true/false) checkers. Machine code is generated
91  for the checker itself and for the actions depending on the result of the checker.  for the checker itself and for the actions depending on the result of the checker.
92  The 'true' case is called as the hot path (expected path), and the other is called as  The 'true' case is called as the try path (expected path), and the other is called as
93  the 'fallback' path. Branch instructions are expesive for all CPUs, so we avoid taken  the 'backtrack' path. Branch instructions are expesive for all CPUs, so we avoid taken
94  branches on the hot path.  branches on the try path.
95    
96   Greedy star operator (*) :   Greedy star operator (*) :
97     Hot path: match happens.     Try path: match happens.
98     Fallback path: match failed.     Backtrack path: match failed.
99   Non-greedy star operator (*?) :   Non-greedy star operator (*?) :
100     Hot path: no need to perform a match.     Try path: no need to perform a match.
101     Fallback path: match is required.     Backtrack path: match is required.
102    
103  The following example shows how the code generated for a capturing bracket  The following example shows how the code generated for a capturing bracket
104  with two alternatives. Let A, B, C, D are arbirary regular expressions, and  with two alternatives. Let A, B, C, D are arbirary regular expressions, and
# Line 108  we have the following regular expression Line 108  we have the following regular expression
108    
109  The generated code will be the following:  The generated code will be the following:
110    
111   A hot path   A try path
112   '(' hot path (pushing arguments to the stack)   '(' try path (pushing arguments to the stack)
113   B hot path   B try path
114   ')' hot path (pushing arguments to the stack)   ')' try path (pushing arguments to the stack)
115   D hot path   D try path
116   return with successful match   return with successful match
117    
118   D fallback path   D backtrack path
119   ')' fallback path (If we arrived from "C" jump to the fallback of "C")   ')' backtrack path (If we arrived from "C" jump to the backtrack of "C")
120   B fallback path   B backtrack path
121   C expected path   C expected path
122   jump to D hot path   jump to D try path
123   C fallback path   C backtrack path
124   A fallback path   A backtrack path
125    
126   Notice, that the order of fallback code paths are the opposite of the fast   Notice, that the order of backtrack code paths are the opposite of the fast
127   code paths. In this way the topmost value on the stack is always belong   code paths. In this way the topmost value on the stack is always belong
128   to the current fallback code path. The fallback code path must check   to the current backtrack code path. The backtrack path must check
129   whether there is a next alternative. If so, it needs to jump back to   whether there is a next alternative. If so, it needs to jump back to
130   the hot path eventually. Otherwise it needs to clear out its own stack   the try path eventually. Otherwise it needs to clear out its own stack
131   frame and continue the execution on the fallback code paths.   frame and continue the execution on the backtrack code paths.
132  */  */
133    
134  /*  /*
135  Saved stack frames:  Saved stack frames:
136    
137  Atomic blocks and asserts require reloading the values of local variables  Atomic blocks and asserts require reloading the values of local variables
138  when the fallback mechanism performed. Because of OP_RECURSE, the locals  when the backtrack mechanism performed. Because of OP_RECURSE, the locals
139  are not necessarly known in compile time, thus we need a dynamic restore  are not necessarly known in compile time, thus we need a dynamic restore
140  mechanism.  mechanism.
141    
# Line 188  typedef struct stub_list { Line 188  typedef struct stub_list {
188  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
189    
190  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
191  code generator. It is allocated by compile_hotpath, and contains  code generator. It is allocated by compile_trypath, and contains
192  the aguments for compile_fallbackpath. Must be the first member  the aguments for compile_backtrackpath. Must be the first member
193  of its descendants. */  of its descendants. */
194  typedef struct fallback_common {  typedef struct backtrack_common {
195    /* Concatenation stack. */    /* Concatenation stack. */
196    struct fallback_common *prev;    struct backtrack_common *prev;
197    jump_list *nextfallbacks;    jump_list *nextbacktracks;
198    /* Internal stack (for component operators). */    /* Internal stack (for component operators). */
199    struct fallback_common *top;    struct backtrack_common *top;
200    jump_list *topfallbacks;    jump_list *topbacktracks;
201    /* Opcode pointer. */    /* Opcode pointer. */
202    pcre_uchar *cc;    pcre_uchar *cc;
203  } fallback_common;  } backtrack_common;
204    
205  typedef struct assert_fallback {  typedef struct assert_backtrack {
206    fallback_common common;    backtrack_common common;
207    jump_list *condfailed;    jump_list *condfailed;
208    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 (-1) if a frame is not needed. */
209    int framesize;    int framesize;
210    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
211    int localptr;    int localptr;
212    /* For iterators. */    /* For iterators. */
213    struct sljit_label *hotpath;    struct sljit_label *trypath;
214  } assert_fallback;  } assert_backtrack;
215    
216  typedef struct bracket_fallback {  typedef struct bracket_backtrack {
217    fallback_common common;    backtrack_common common;
218    /* Where to coninue if an alternative is successfully matched. */    /* Where to coninue if an alternative is successfully matched. */
219    struct sljit_label *althotpath;    struct sljit_label *alttrypath;
220    /* For rmin and rmax iterators. */    /* For rmin and rmax iterators. */
221    struct sljit_label *recursivehotpath;    struct sljit_label *recursivetrypath;
222    /* For greedy ? operator. */    /* For greedy ? operator. */
223    struct sljit_label *zerohotpath;    struct sljit_label *zerotrypath;
224    /* Contains the branches of a failed condition. */    /* Contains the branches of a failed condition. */
225    union {    union {
226      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
227      jump_list *condfailed;      jump_list *condfailed;
228      assert_fallback *assert;      assert_backtrack *assert;
229      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. -1 if not needed. */
230      int framesize;      int framesize;
231    } u;    } u;
232    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
233    int localptr;    int localptr;
234  } bracket_fallback;  } bracket_backtrack;
235    
236  typedef struct bracketpos_fallback {  typedef struct bracketpos_backtrack {
237    fallback_common common;    backtrack_common common;
238    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
239    int localptr;    int localptr;
240    /* Reverting stack is needed. */    /* Reverting stack is needed. */
241    int framesize;    int framesize;
242    /* Allocated stack size. */    /* Allocated stack size. */
243    int stacksize;    int stacksize;
244  } bracketpos_fallback;  } bracketpos_backtrack;
245    
246  typedef struct braminzero_fallback {  typedef struct braminzero_backtrack {
247    fallback_common common;    backtrack_common common;
248    struct sljit_label *hotpath;    struct sljit_label *trypath;
249  } braminzero_fallback;  } braminzero_backtrack;
250    
251  typedef struct iterator_fallback {  typedef struct iterator_backtrack {
252    fallback_common common;    backtrack_common common;
253    /* Next iteration. */    /* Next iteration. */
254    struct sljit_label *hotpath;    struct sljit_label *trypath;
255  } iterator_fallback;  } iterator_backtrack;
256    
257  typedef struct recurse_entry {  typedef struct recurse_entry {
258    struct recurse_entry *next;    struct recurse_entry *next;
# Line 264  typedef struct recurse_entry { Line 264  typedef struct recurse_entry {
264    int start;    int start;
265  } recurse_entry;  } recurse_entry;
266    
267  typedef struct recurse_fallback {  typedef struct recurse_backtrack {
268    fallback_common common;    backtrack_common common;
269  } recurse_fallback;  } recurse_backtrack;
270    
271  typedef struct compiler_common {  typedef struct compiler_common {
272    struct sljit_compiler *compiler;    struct sljit_compiler *compiler;
# Line 467  return cc; Line 467  return cc;
467   init_frame   init_frame
468   get_localsize   get_localsize
469   copy_locals   copy_locals
470   compile_hotpath   compile_trypath
471   compile_fallbackpath   compile_backtrackpath
472  */  */
473    
474  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)  static pcre_uchar *next_opcode(compiler_common *common, pcre_uchar *cc)
# Line 667  switch(*cc) Line 667  switch(*cc)
667    }    }
668  }  }
669    
670    #define CASE_ITERATOR_LOCAL1 \
671        case OP_MINSTAR: \
672        case OP_MINPLUS: \
673        case OP_QUERY: \
674        case OP_MINQUERY: \
675        case OP_MINSTARI: \
676        case OP_MINPLUSI: \
677        case OP_QUERYI: \
678        case OP_MINQUERYI: \
679        case OP_NOTMINSTAR: \
680        case OP_NOTMINPLUS: \
681        case OP_NOTQUERY: \
682        case OP_NOTMINQUERY: \
683        case OP_NOTMINSTARI: \
684        case OP_NOTMINPLUSI: \
685        case OP_NOTQUERYI: \
686        case OP_NOTMINQUERYI:
687    
688    #define CASE_ITERATOR_LOCAL2A \
689        case OP_STAR: \
690        case OP_PLUS: \
691        case OP_STARI: \
692        case OP_PLUSI: \
693        case OP_NOTSTAR: \
694        case OP_NOTPLUS: \
695        case OP_NOTSTARI: \
696        case OP_NOTPLUSI:
697    
698    #define CASE_ITERATOR_LOCAL2B \
699        case OP_UPTO: \
700        case OP_MINUPTO: \
701        case OP_UPTOI: \
702        case OP_MINUPTOI: \
703        case OP_NOTUPTO: \
704        case OP_NOTMINUPTO: \
705        case OP_NOTUPTOI: \
706        case OP_NOTMINUPTOI:
707    
708    #define CASE_ITERATOR_TYPE_LOCAL1 \
709        case OP_TYPEMINSTAR: \
710        case OP_TYPEMINPLUS: \
711        case OP_TYPEQUERY: \
712        case OP_TYPEMINQUERY:
713    
714    #define CASE_ITERATOR_TYPE_LOCAL2A \
715        case OP_TYPESTAR: \
716        case OP_TYPEPLUS:
717    
718    #define CASE_ITERATOR_TYPE_LOCAL2B \
719        case OP_TYPEUPTO: \
720        case OP_TYPEMINUPTO:
721    
722    static int get_class_iterator_size(pcre_uchar *cc)
723    {
724    switch(*cc)
725      {
726      case OP_CRSTAR:
727      case OP_CRPLUS:
728      return 2;
729    
730      case OP_CRMINSTAR:
731      case OP_CRMINPLUS:
732      case OP_CRQUERY:
733      case OP_CRMINQUERY:
734      return 1;
735    
736      case OP_CRRANGE:
737      case OP_CRMINRANGE:
738      if (GET2(cc, 1) == GET2(cc, 1 + IMM2_SIZE))
739        return 0;
740      return 2;
741    
742      default:
743      return 0;
744      }
745    }
746    
747  static int get_localspace(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static int get_localspace(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
748  {  {
749  int localspace = 0;  int localspace = 0;
750  pcre_uchar *alternative;  pcre_uchar *alternative;
751    pcre_uchar *end = NULL;
752    int space, size, bracketlen;
753    
754  /* 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. */
755  while (cc < ccend)  while (cc < ccend)
756    {    {
757      space = 0;
758      size = 0;
759      bracketlen = 0;
760    switch(*cc)    switch(*cc)
761      {      {
762      case OP_SET_SOM:      case OP_SET_SOM:
# Line 692  while (cc < ccend) Line 775  while (cc < ccend)
775      case OP_SBRAPOS:      case OP_SBRAPOS:
776      case OP_SCOND:      case OP_SCOND:
777      localspace += sizeof(sljit_w);      localspace += sizeof(sljit_w);
778      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
779      break;      break;
780    
781      case OP_CBRAPOS:      case OP_CBRAPOS:
782      case OP_SCBRAPOS:      case OP_SCBRAPOS:
783      localspace += sizeof(sljit_w);      localspace += sizeof(sljit_w);
784      cc += 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
785      break;      break;
786    
787      case OP_COND:      case OP_COND:
# Line 706  while (cc < ccend) Line 789  while (cc < ccend)
789      alternative = cc + GET(cc, 1);      alternative = cc + GET(cc, 1);
790      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)      if (*alternative == OP_KETRMAX || *alternative == OP_KETRMIN)
791        localspace += sizeof(sljit_w);        localspace += sizeof(sljit_w);
792      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
793        break;
794    
795        case OP_BRA:
796        bracketlen = 1 + LINK_SIZE;
797        break;
798    
799        case OP_CBRA:
800        case OP_SCBRA:
801        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
802        break;
803    
804        CASE_ITERATOR_LOCAL1
805        space = 1;
806        size = -2;
807        break;
808    
809        CASE_ITERATOR_LOCAL2A
810        space = 2;
811        size = -2;
812        break;
813    
814        CASE_ITERATOR_LOCAL2B
815        space = 2;
816        size = -(2 + IMM2_SIZE);
817        break;
818    
819        CASE_ITERATOR_TYPE_LOCAL1
820        space = 1;
821        size = 1;
822        break;
823    
824        CASE_ITERATOR_TYPE_LOCAL2A
825        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
826          space = 2;
827        size = 1;
828        break;
829    
830        CASE_ITERATOR_TYPE_LOCAL2B
831        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
832          space = 2;
833        size = 1 + IMM2_SIZE;
834      break;      break;
835    
836        case OP_CLASS:
837        case OP_NCLASS:
838        size += 1 + 32 / sizeof(pcre_uchar);
839        space = get_class_iterator_size(cc + size);
840        break;
841    
842    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
843        case OP_XCLASS:
844        size = GET(cc, 1);
845        space = get_class_iterator_size(cc + size);
846        break;
847    #endif
848    
849      case OP_RECURSE:      case OP_RECURSE:
850      /* Set its value only once. */      /* Set its value only once. */
851      if (common->recursive_head == 0)      if (common->recursive_head == 0)
# Line 734  while (cc < ccend) Line 871  while (cc < ccend)
871        return -1;        return -1;
872      break;      break;
873      }      }
874    
875      if (space > 0 && cc >= end)
876        localspace += sizeof(sljit_w) * space;
877    
878      if (size != 0)
879        {
880        if (size < 0)
881          {
882          cc += -size;
883    #ifdef SUPPORT_UTF
884          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
885    #endif
886          }
887        else
888          cc += size;
889        }
890    
891      if (bracketlen > 0)
892        {
893        if (cc >= end)
894          {
895          end = bracketend(cc);
896          if (end[-1 - LINK_SIZE] == OP_KET)
897            end = NULL;
898          }
899        cc += bracketlen;
900        }
901    }    }
902  return localspace;  return localspace;
903  }  }
# Line 742  static void set_localptrs(compiler_commo Line 906  static void set_localptrs(compiler_commo
906  {  {
907  pcre_uchar *cc = common->start;  pcre_uchar *cc = common->start;
908  pcre_uchar *alternative;  pcre_uchar *alternative;
909    pcre_uchar *end = NULL;
910    int space, size, bracketlen;
911    
912  while (cc < ccend)  while (cc < ccend)
913    {    {
914      space = 0;
915      size = 0;
916      bracketlen = 0;
917    switch(*cc)    switch(*cc)
918      {      {
919      case OP_ASSERT:      case OP_ASSERT:
# Line 758  while (cc < ccend) Line 928  while (cc < ccend)
928      case OP_SCOND:      case OP_SCOND:
929      common->localptrs[cc - common->start] = localptr;      common->localptrs[cc - common->start] = localptr;
930      localptr += sizeof(sljit_w);      localptr += sizeof(sljit_w);
931      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
932      break;      break;
933    
934      case OP_CBRAPOS:      case OP_CBRAPOS:
935      case OP_SCBRAPOS:      case OP_SCBRAPOS:
936      common->localptrs[cc - common->start] = localptr;      common->localptrs[cc - common->start] = localptr;
937      localptr += sizeof(sljit_w);      localptr += sizeof(sljit_w);
938      cc += 1 + LINK_SIZE + IMM2_SIZE;      bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
939      break;      break;
940    
941      case OP_COND:      case OP_COND:
# Line 776  while (cc < ccend) Line 946  while (cc < ccend)
946        common->localptrs[cc - common->start] = localptr;        common->localptrs[cc - common->start] = localptr;
947        localptr += sizeof(sljit_w);        localptr += sizeof(sljit_w);
948        }        }
949      cc += 1 + LINK_SIZE;      bracketlen = 1 + LINK_SIZE;
950        break;
951    
952        case OP_BRA:
953        bracketlen = 1 + LINK_SIZE;
954        break;
955    
956        case OP_CBRA:
957        case OP_SCBRA:
958        bracketlen = 1 + LINK_SIZE + IMM2_SIZE;
959        break;
960    
961        CASE_ITERATOR_LOCAL1
962        space = 1;
963        size = -2;
964        break;
965    
966        CASE_ITERATOR_LOCAL2A
967        space = 2;
968        size = -2;
969        break;
970    
971        CASE_ITERATOR_LOCAL2B
972        space = 2;
973        size = -(2 + IMM2_SIZE);
974        break;
975    
976        CASE_ITERATOR_TYPE_LOCAL1
977        space = 1;
978        size = 1;
979        break;
980    
981        CASE_ITERATOR_TYPE_LOCAL2A
982        if (cc[1] != OP_ANYNL && cc[1] != OP_EXTUNI)
983          space = 2;
984        size = 1;
985        break;
986    
987        CASE_ITERATOR_TYPE_LOCAL2B
988        if (cc[1 + IMM2_SIZE] != OP_ANYNL && cc[1 + IMM2_SIZE] != OP_EXTUNI)
989          space = 2;
990        size = 1 + IMM2_SIZE;
991      break;      break;
992    
993        case OP_CLASS:
994        case OP_NCLASS:
995        size += 1 + 32 / sizeof(pcre_uchar);
996        space = get_class_iterator_size(cc + size);
997        break;
998    
999    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1000        case OP_XCLASS:
1001        size = GET(cc, 1);
1002        space = get_class_iterator_size(cc + size);
1003        break;
1004    #endif
1005    
1006      default:      default:
1007      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1008      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
1009      break;      break;
1010      }      }
1011    
1012      if (space > 0 && cc >= end)
1013        {
1014        common->localptrs[cc - common->start] = localptr;
1015        localptr += sizeof(sljit_w) * space;
1016        }
1017    
1018      if (size != 0)
1019        {
1020        if (size < 0)
1021          {
1022          cc += -size;
1023    #ifdef SUPPORT_UTF
1024          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1025    #endif
1026          }
1027        else
1028          cc += size;
1029        }
1030    
1031      if (bracketlen > 0)
1032        {
1033        if (cc >= end)
1034          {
1035          end = bracketend(cc);
1036          if (end[-1 - LINK_SIZE] == OP_KET)
1037            end = NULL;
1038          }
1039        cc += bracketlen;
1040        }
1041    }    }
1042  }  }
1043    
# Line 963  SLJIT_ASSERT(stackpos == STACK(stacktop) Line 1217  SLJIT_ASSERT(stackpos == STACK(stacktop)
1217  static SLJIT_INLINE int get_localsize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static SLJIT_INLINE int get_localsize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
1218  {  {
1219  int localsize = 2;  int localsize = 2;
1220    int size;
1221  pcre_uchar *alternative;  pcre_uchar *alternative;
1222  /* Calculate the sum of the local variables. */  /* Calculate the sum of the local variables. */
1223  while (cc < ccend)  while (cc < ccend)
1224    {    {
1225      size = 0;
1226    switch(*cc)    switch(*cc)
1227      {      {
1228      case OP_ASSERT:      case OP_ASSERT:
# Line 1003  while (cc < ccend) Line 1259  while (cc < ccend)
1259      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1260      break;      break;
1261    
1262        CASE_ITERATOR_LOCAL1
1263        if (PRIV_DATA(cc))
1264          localsize++;
1265        cc += 2;
1266    #ifdef SUPPORT_UTF
1267        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1268    #endif
1269        break;
1270    
1271        CASE_ITERATOR_LOCAL2A
1272        if (PRIV_DATA(cc))
1273          localsize += 2;
1274        cc += 2;
1275    #ifdef SUPPORT_UTF
1276        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1277    #endif
1278        break;
1279    
1280        CASE_ITERATOR_LOCAL2B
1281        if (PRIV_DATA(cc))
1282          localsize += 2;
1283        cc += 2 + IMM2_SIZE;
1284    #ifdef SUPPORT_UTF
1285        if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1286    #endif
1287        break;
1288    
1289        CASE_ITERATOR_TYPE_LOCAL1
1290        if (PRIV_DATA(cc))
1291          localsize++;
1292        cc += 1;
1293        break;
1294    
1295        CASE_ITERATOR_TYPE_LOCAL2A
1296        if (PRIV_DATA(cc))
1297          localsize += 2;
1298        cc += 1;
1299        break;
1300    
1301        CASE_ITERATOR_TYPE_LOCAL2B
1302        if (PRIV_DATA(cc))
1303          localsize += 2;
1304        cc += 1 + IMM2_SIZE;
1305        break;
1306    
1307        case OP_CLASS:
1308        case OP_NCLASS:
1309    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1310        case OP_XCLASS:
1311        size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / sizeof(pcre_uchar);
1312    #else
1313        size = 1 + 32 / sizeof(pcre_uchar);
1314    #endif
1315        if (PRIV_DATA(cc))
1316          localsize += get_class_iterator_size(cc + size);
1317        cc += size;
1318        break;
1319    
1320      default:      default:
1321      cc = next_opcode(common, cc);      cc = next_opcode(common, cc);
1322      SLJIT_ASSERT(cc != NULL);      SLJIT_ASSERT(cc != NULL);
# Line 1018  static void copy_locals(compiler_common Line 1332  static void copy_locals(compiler_common
1332  {  {
1333  DEFINE_COMPILER;  DEFINE_COMPILER;
1334  int srcw[2];  int srcw[2];
1335  int count;  int count, size;
1336  BOOL tmp1next = TRUE;  BOOL tmp1next = TRUE;
1337  BOOL tmp1empty = TRUE;  BOOL tmp1empty = TRUE;
1338  BOOL tmp2empty = TRUE;  BOOL tmp2empty = TRUE;
# Line 1098  while (status != end) Line 1412  while (status != end)
1412        case OP_CBRAPOS:        case OP_CBRAPOS:
1413        case OP_SCBRAPOS:        case OP_SCBRAPOS:
1414        count = 2;        count = 2;
1415        srcw[1] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));        srcw[0] = OVECTOR_PRIV(GET2(cc, 1 + LINK_SIZE));
1416        srcw[0] = PRIV_DATA(cc);        srcw[1] = PRIV_DATA(cc);
1417        SLJIT_ASSERT(srcw[0] != 0);        SLJIT_ASSERT(srcw[0] != 0);
1418        cc += 1 + LINK_SIZE + IMM2_SIZE;        cc += 1 + LINK_SIZE + IMM2_SIZE;
1419        break;        break;
# Line 1116  while (status != end) Line 1430  while (status != end)
1430        cc += 1 + LINK_SIZE;        cc += 1 + LINK_SIZE;
1431        break;        break;
1432    
1433          CASE_ITERATOR_LOCAL1
1434          if (PRIV_DATA(cc))
1435            {
1436            count = 1;
1437            srcw[0] = PRIV_DATA(cc);
1438            }
1439          cc += 2;
1440    #ifdef SUPPORT_UTF
1441          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1442    #endif
1443          break;
1444    
1445          CASE_ITERATOR_LOCAL2A
1446          if (PRIV_DATA(cc))
1447            {
1448            count = 2;
1449            srcw[0] = PRIV_DATA(cc);
1450            srcw[1] = PRIV_DATA(cc) + sizeof(sljit_w);
1451            }
1452          cc += 2;
1453    #ifdef SUPPORT_UTF
1454          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1455    #endif
1456          break;
1457    
1458          CASE_ITERATOR_LOCAL2B
1459          if (PRIV_DATA(cc))
1460            {
1461            count = 2;
1462            srcw[0] = PRIV_DATA(cc);
1463            srcw[1] = PRIV_DATA(cc) + sizeof(sljit_w);
1464            }
1465          cc += 2 + IMM2_SIZE;
1466    #ifdef SUPPORT_UTF
1467          if (common->utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1468    #endif
1469          break;
1470    
1471          CASE_ITERATOR_TYPE_LOCAL1
1472          if (PRIV_DATA(cc))
1473            {
1474            count = 1;
1475            srcw[0] = PRIV_DATA(cc);
1476            }
1477          cc += 1;
1478          break;
1479    
1480          CASE_ITERATOR_TYPE_LOCAL2A
1481          if (PRIV_DATA(cc))
1482            {
1483            count = 2;
1484            srcw[0] = PRIV_DATA(cc);
1485            srcw[1] = srcw[0] + sizeof(sljit_w);
1486            }
1487          cc += 1;
1488          break;
1489    
1490          CASE_ITERATOR_TYPE_LOCAL2B
1491          if (PRIV_DATA(cc))
1492            {
1493            count = 2;
1494            srcw[0] = PRIV_DATA(cc);
1495            srcw[1] = srcw[0] + sizeof(sljit_w);
1496            }
1497          cc += 1 + IMM2_SIZE;
1498          break;
1499    
1500          case OP_CLASS:
1501          case OP_NCLASS:
1502    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
1503          case OP_XCLASS:
1504          size = (*cc == OP_XCLASS) ? GET(cc, 1) : 1 + 32 / sizeof(pcre_uchar);
1505    #else
1506          size = 1 + 32 / sizeof(pcre_uchar);
1507    #endif
1508          if (PRIV_DATA(cc))
1509            switch(get_class_iterator_size(cc + size))
1510              {
1511              case 1:
1512              count = 1;
1513              srcw[0] = PRIV_DATA(cc);
1514              break;
1515    
1516              case 2:
1517              count = 2;
1518              srcw[0] = PRIV_DATA(cc);
1519              srcw[1] = srcw[0] + sizeof(sljit_w);
1520              break;
1521    
1522              default:
1523              SLJIT_ASSERT_STOP();
1524              break;
1525              }
1526          cc += size;
1527          break;
1528    
1529        default:        default:
1530        cc = next_opcode(common, cc);        cc = next_opcode(common, cc);
1531        SLJIT_ASSERT(cc != NULL);        SLJIT_ASSERT(cc != NULL);
# Line 1218  if (save) Line 1628  if (save)
1628  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1629  }  }
1630    
1631    #undef CASE_ITERATOR_LOCAL1
1632    #undef CASE_ITERATOR_LOCAL2A
1633    #undef CASE_ITERATOR_LOCAL2B
1634    #undef CASE_ITERATOR_TYPE_LOCAL1
1635    #undef CASE_ITERATOR_TYPE_LOCAL2A
1636    #undef CASE_ITERATOR_TYPE_LOCAL2B
1637    
1638  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)  static SLJIT_INLINE BOOL ispowerof2(unsigned int value)
1639  {  {
1640  return (value & (value - 1)) == 0;  return (value & (value - 1)) == 0;
# Line 1622  JUMPHERE(jump); Line 2039  JUMPHERE(jump);
2039  return return_value;  return return_value;
2040  }  }
2041    
2042  static void fallback_at_str_end(compiler_common *common, jump_list **fallbacks)  static void detect_partial_match(compiler_common *common, jump_list **backtracks)
2043  {  {
2044  DEFINE_COMPILER;  DEFINE_COMPILER;
2045  struct sljit_jump *jump;  struct sljit_jump *jump;
2046    
2047  if (common->mode == JIT_COMPILE)  if (common->mode == JIT_COMPILE)
2048    {    {
2049    add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
2050    return;    return;
2051    }    }
2052    
2053  /* Partial matching mode. */  /* Partial matching mode. */
2054  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);  jump = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
2055  add_jump(compiler, fallbacks, 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));
2056  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)  if (common->mode == JIT_PARTIAL_SOFT_COMPILE)
2057    {    {
2058    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, -1);
2059    add_jump(compiler, fallbacks, JUMP(SLJIT_JUMP));    add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
2060    }    }
2061  else  else
2062    {    {
# Line 1789  if (common->utf) Line 2206  if (common->utf)
2206  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));
2207  }  }
2208    
2209  static void check_newlinechar(compiler_common *common, int nltype, jump_list **fallbacks, BOOL jumpiftrue)  static void check_newlinechar(compiler_common *common, int nltype, jump_list **backtracks, BOOL jumpiftrue)
2210  {  {
2211  /* 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. */
2212  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 1797  DEFINE_COMPILER; Line 2214  DEFINE_COMPILER;
2214  if (nltype == NLTYPE_ANY)  if (nltype == NLTYPE_ANY)
2215    {    {
2216    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
2217    add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2218    }    }
2219  else if (nltype == NLTYPE_ANYCRLF)  else if (nltype == NLTYPE_ANYCRLF)
2220    {    {
# Line 1805  else if (nltype == NLTYPE_ANYCRLF) Line 2222  else if (nltype == NLTYPE_ANYCRLF)
2222    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);
2223    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);
2224    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
2225    add_jump(compiler, fallbacks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(jumpiftrue ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
2226    }    }
2227  else  else
2228    {    {
2229    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);    SLJIT_ASSERT(nltype == NLTYPE_FIXED && common->newline < 256);
2230    add_jump(compiler, fallbacks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));    add_jump(compiler, backtracks, CMP(jumpiftrue ? SLJIT_C_EQUAL : SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
2231    }    }
2232  }  }
2233    
# Line 2089  if (newlinecheck) Line 2506  if (newlinecheck)
2506  return mainloop;  return mainloop;
2507  }  }
2508    
2509    static SLJIT_INLINE BOOL fast_forward_first_two_chars(compiler_common *common, BOOL firstline)
2510    {
2511    DEFINE_COMPILER;
2512    struct sljit_label *start;
2513    struct sljit_jump *leave;
2514    struct sljit_jump *found;
2515    pcre_int32 chars[4];
2516    pcre_uchar *cc = common->start + 1 + IMM2_SIZE;
2517    int index = 0;
2518    pcre_int32 len, c, bit;
2519    unsigned int caseless;
2520    BOOL must_end;
2521    
2522    #ifdef COMPILE_PCRE8
2523    union {
2524        sljit_uh ascombined;
2525        sljit_ub asuchars[2];
2526    } pair;
2527    #else
2528    union {
2529        sljit_ui ascombined;
2530        sljit_uh asuchars[2];
2531    } pair;
2532    #endif
2533    
2534    if (*(common->start + GET(common->start, 1)) == OP_ALT)
2535      return FALSE;
2536    
2537    while (TRUE)
2538      {
2539      caseless = 0;
2540      must_end = TRUE;
2541      switch(*cc)
2542        {
2543        case OP_CHAR:
2544        must_end = FALSE;
2545        cc++;
2546        break;
2547    
2548        case OP_CHARI:
2549        caseless = 1;
2550        must_end = FALSE;
2551        cc++;
2552        break;
2553    
2554        case OP_SOD:
2555        case OP_SOM:
2556        case OP_SET_SOM:
2557        case OP_NOT_WORD_BOUNDARY:
2558        case OP_WORD_BOUNDARY:
2559        case OP_EODN:
2560        case OP_EOD:
2561        case OP_CIRC:
2562        case OP_CIRCM:
2563        case OP_DOLL:
2564        case OP_DOLLM:
2565        /* Zero width assertions. */
2566        cc++;
2567        continue;
2568    
2569        case OP_PLUS:
2570        case OP_MINPLUS:
2571        case OP_POSPLUS:
2572        cc++;
2573        break;
2574    
2575        case OP_EXACT:
2576        cc += 1 + IMM2_SIZE;
2577        break;
2578    
2579        case OP_PLUSI:
2580        case OP_MINPLUSI:
2581        case OP_POSPLUSI:
2582        caseless = 1;
2583        cc++;
2584        break;
2585    
2586        case OP_EXACTI:
2587        caseless = 1;
2588        cc += 1 + IMM2_SIZE;
2589        break;
2590    
2591        default:
2592        return FALSE;
2593        }
2594    
2595      len = 1;
2596    #ifdef SUPPORT_UTF
2597      if (common->utf && HAS_EXTRALEN(cc[0])) len += GET_EXTRALEN(cc[0]);
2598    #endif
2599    
2600      if (caseless && char_has_othercase(common, cc))
2601        {
2602        caseless = char_get_othercase_bit(common, cc);
2603        if (caseless == 0)
2604          return FALSE;
2605    #ifdef COMPILE_PCRE8
2606        caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 8));
2607    #else
2608        if ((caseless & 0x100) != 0)
2609          caseless = ((caseless & 0xff) << 16) | (len - (caseless >> 9));
2610        else
2611          caseless = ((caseless & 0xff) << 8) | (len - (caseless >> 9));
2612    #endif
2613        }
2614      else
2615        caseless = 0;
2616    
2617      while (len > 0 && index < 2 * 2)
2618        {
2619        c = *cc;
2620        bit = 0;
2621        if (len == (caseless & 0xff))
2622          {
2623          bit = caseless >> 8;
2624          c |= bit;
2625          }
2626    
2627        chars[index] = c;
2628        chars[index + 1] = bit;
2629    
2630        len--;
2631        index += 2;
2632        cc++;
2633        }
2634    
2635      if (index == 2 * 2)
2636        break;
2637      else if (must_end)
2638        return FALSE;
2639      }
2640    
2641    if (firstline)
2642      {
2643      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, STR_END, 0);
2644      OP2(SLJIT_SUB, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->first_line_end, SLJIT_IMM, 1);
2645      }
2646    else
2647      OP2(SLJIT_SUB, STR_END, 0, STR_END, 0, SLJIT_IMM, 1);
2648    
2649    start = LABEL();
2650    leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
2651    #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
2652    #ifdef COMPILE_PCRE8
2653    OP1(SLJIT_MOV_UH, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2654    #else /* COMPILE_PCRE8 */
2655    OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2656    #endif
2657    
2658    #else /* SLJIT_UNALIGNED */
2659    
2660    #if defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN
2661    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), 0);
2662    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2663    #else /* SLJIT_BIG_ENDIAN */
2664    OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
2665    OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
2666    #endif /* SLJIT_BIG_ENDIAN */
2667    
2668    #ifdef COMPILE_PCRE8
2669    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 8);
2670    #else /* COMPILE_PCRE8 */
2671    OP2(SLJIT_SHL, TMP2, 0, TMP2, 0, SLJIT_IMM, 16);
2672    #endif
2673    OP2(SLJIT_OR, TMP1, 0, TMP1, 0, TMP2, 0);
2674    
2675    #endif
2676    
2677    if (chars[1] != 0 || chars[3] != 0)
2678      {
2679      pair.asuchars[0] = chars[1];
2680      pair.asuchars[1] = chars[3];
2681      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, pair.ascombined);
2682      }
2683    
2684    pair.asuchars[0] = chars[0];
2685    pair.asuchars[1] = chars[2];
2686    found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, pair.ascombined);
2687    
2688    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
2689    JUMPTO(SLJIT_JUMP, start);
2690    JUMPHERE(found);
2691    JUMPHERE(leave);
2692    
2693    if (firstline)
2694      OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);
2695    OP2(SLJIT_ADD, STR_END, 0, STR_END, 0, SLJIT_IMM, 1);
2696    return TRUE;
2697    }
2698    
2699  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)
2700  {  {
2701  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 2137  else Line 2744  else
2744    }    }
2745    
2746  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));
 #if defined SUPPORT_UTF && defined COMPILE_PCRE8  
 if (common->utf)  
   {  
   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xc0, start);  
   OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)PRIV(utf8_table4) - 0xc0);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   }  
 #endif  
 #if defined SUPPORT_UTF && defined COMPILE_PCRE16  
 if (common->utf)  
   {  
   CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, 0xd800, start);  
   OP2(SLJIT_AND, TMP1, 0, TMP1, 0, SLJIT_IMM, 0xfc00);  
   OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 0xd800);  
   COND_VALUE(SLJIT_MOV, TMP1, 0, SLJIT_C_EQUAL);  
   OP2(SLJIT_SHL, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);  
   OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP1, 0);  
   }  
 #endif  
2747  JUMPTO(SLJIT_JUMP, start);  JUMPTO(SLJIT_JUMP, start);
2748  JUMPHERE(found);  JUMPHERE(found);
2749  JUMPHERE(leave);  JUMPHERE(leave);
# Line 2733  return src2; Line 3321  return src2;
3321  #endif /* SUPPORT_UTF && SUPPORT_UCP */  #endif /* SUPPORT_UTF && SUPPORT_UCP */
3322    
3323  static pcre_uchar *byte_sequence_compare(compiler_common *common, BOOL caseless, pcre_uchar *cc,  static pcre_uchar *byte_sequence_compare(compiler_common *common, BOOL caseless, pcre_uchar *cc,
3324      compare_context* context, jump_list **fallbacks)      compare_context* context, jump_list **backtracks)
3325  {  {
3326  DEFINE_COMPILER;  DEFINE_COMPILER;
3327  unsigned int othercasebit = 0;  unsigned int othercasebit = 0;
# Line 2834  do Line 3422  do
3422        case 4 / sizeof(pcre_uchar):        case 4 / sizeof(pcre_uchar):
3423        if (context->oc.asint != 0)        if (context->oc.asint != 0)
3424          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asint);          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asint);
3425        add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asint | context->oc.asint));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asint | context->oc.asint));
3426        break;        break;
3427    
3428        case 2 / sizeof(pcre_uchar):        case 2 / sizeof(pcre_uchar):
3429        if (context->oc.asushort != 0)        if (context->oc.asushort != 0)
3430          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asushort);          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asushort);
3431        add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asushort | context->oc.asushort));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asushort | context->oc.asushort));
3432        break;        break;
3433    
3434  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3435        case 1:        case 1:
3436        if (context->oc.asbyte != 0)        if (context->oc.asbyte != 0)
3437          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asbyte);          OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, context->oc.asbyte);
3438        add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asbyte | context->oc.asbyte));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, context->c.asbyte | context->oc.asbyte));
3439        break;        break;
3440  #endif  #endif
3441    
# Line 2873  do Line 3461  do
3461    if (othercasebit != 0 && othercasechar == cc)    if (othercasebit != 0 && othercasechar == cc)
3462      {      {
3463      OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, othercasebit);      OP2(SLJIT_OR, context->sourcereg, 0, context->sourcereg, 0, SLJIT_IMM, othercasebit);
3464      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, *cc | othercasebit));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, *cc | othercasebit));
3465      }      }
3466    else    else
3467      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, *cc));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, context->sourcereg, 0, SLJIT_IMM, *cc));
3468    
3469  #endif  #endif
3470    
# Line 2912  return cc; Line 3500  return cc;
3500      } \      } \
3501    charoffset = (value);    charoffset = (value);
3502    
3503  static void compile_xclass_hotpath(compiler_common *common, pcre_uchar *cc, jump_list **fallbacks)  static void compile_xclass_trypath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)
3504  {  {
3505  DEFINE_COMPILER;  DEFINE_COMPILER;
3506  jump_list *found = NULL;  jump_list *found = NULL;
3507  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : fallbacks;  jump_list **list = (*cc & XCL_NOT) == 0 ? &found : backtracks;
3508  unsigned int c;  unsigned int c;
3509  int compares;  int compares;
3510  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
# Line 2931  int invertcmp, numberofcmps; Line 3519  int invertcmp, numberofcmps;
3519  unsigned int charoffset;  unsigned int charoffset;
3520    
3521  /* Although SUPPORT_UTF must be defined, we are not necessary in utf mode. */  /* Although SUPPORT_UTF must be defined, we are not necessary in utf mode. */
3522  fallback_at_str_end(common, fallbacks);  detect_partial_match(common, backtracks);
3523  read_char(common);  read_char(common);
3524    
3525  if ((*cc++ & XCL_MAP) != 0)  if ((*cc++ & XCL_MAP) != 0)
# Line 3082  typeoffset = 0; Line 3670  typeoffset = 0;
3670  while (*cc != XCL_END)  while (*cc != XCL_END)
3671    {    {
3672    compares--;    compares--;
3673    invertcmp = (compares == 0 && list != fallbacks);    invertcmp = (compares == 0 && list != backtracks);
3674    jump = NULL;    jump = NULL;
3675    
3676    if (*cc == XCL_SINGLE)    if (*cc == XCL_SINGLE)
# Line 3164  while (*cc != XCL_END) Line 3752  while (*cc != XCL_END)
3752      switch(*cc)      switch(*cc)
3753        {        {
3754        case PT_ANY:        case PT_ANY:
3755        if (list != fallbacks)        if (list != backtracks)
3756          {          {
3757          if ((cc[-1] == XCL_NOTPROP && compares > 0) || (cc[-1] == XCL_PROP && compares == 0))          if ((cc[-1] == XCL_NOTPROP && compares > 0) || (cc[-1] == XCL_PROP && compares == 0))
3758            continue;            continue;
# Line 3237  while (*cc != XCL_END) Line 3825  while (*cc != XCL_END)
3825  #endif  #endif
3826    
3827    if (jump != NULL)    if (jump != NULL)
3828      add_jump(compiler, compares > 0 ? list : fallbacks, jump);      add_jump(compiler, compares > 0 ? list : backtracks, jump);
3829    }    }
3830    
3831  if (found != NULL)  if (found != NULL)
# Line 3249  if (found != NULL) Line 3837  if (found != NULL)
3837    
3838  #endif  #endif
3839    
3840  static pcre_uchar *compile_char1_hotpath(compiler_common *common, pcre_uchar type, pcre_uchar *cc, jump_list **fallbacks)  static pcre_uchar *compile_char1_trypath(compiler_common *common, pcre_uchar type, pcre_uchar *cc, jump_list **backtracks)
3841  {  {
3842  DEFINE_COMPILER;  DEFINE_COMPILER;
3843  int length;  int length;
# Line 3268  switch(type) Line 3856  switch(type)
3856    case OP_SOD:    case OP_SOD:
3857    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
3858    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
3859    add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, TMP1, 0));    add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, TMP1, 0));
3860    return cc;    return cc;
3861    
3862    case OP_SOM:    case OP_SOM:
3863    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
3864    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
3865    add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, TMP1, 0));    add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, TMP1, 0));
3866    return cc;    return cc;
3867    
3868    case OP_NOT_WORD_BOUNDARY:    case OP_NOT_WORD_BOUNDARY:
3869    case OP_WORD_BOUNDARY:    case OP_WORD_BOUNDARY:
3870    add_jump(compiler, &common->wordboundary, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->wordboundary, JUMP(SLJIT_FAST_CALL));
3871    add_jump(compiler, fallbacks, JUMP(type == OP_NOT_WORD_BOUNDARY ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_NOT_WORD_BOUNDARY ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
3872    return cc;    return cc;
3873    
3874    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
3875    case OP_DIGIT:    case OP_DIGIT:
3876    fallback_at_str_end(common, fallbacks);    detect_partial_match(common, backtracks);
3877    read_char8_type(common);    read_char8_type(common);
3878    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_digit);
3879    add_jump(compiler, fallbacks, JUMP(type == OP_DIGIT ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_DIGIT ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
3880    return cc;    return cc;
3881    
3882    case OP_NOT_WHITESPACE:    case OP_NOT_WHITESPACE:
3883    case OP_WHITESPACE:    case OP_WHITESPACE:
3884    fallback_at_str_end(common, fallbacks);    detect_partial_match(common, backtracks);
3885    read_char8_type(common);    read_char8_type(common);
3886    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_space);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_space);
3887    add_jump(compiler, fallbacks, JUMP(type == OP_WHITESPACE ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_WHITESPACE ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
3888    return cc;    return cc;
3889    
3890    case OP_NOT_WORDCHAR:    case OP_NOT_WORDCHAR:
3891    case OP_WORDCHAR:    case OP_WORDCHAR:
3892    fallback_at_str_end(common, fallbacks);    detect_partial_match(common, backtracks);
3893    read_char8_type(common);    read_char8_type(common);
3894    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_word);    OP2(SLJIT_AND | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, ctype_word);
3895    add_jump(compiler, fallbacks, JUMP(type == OP_WORDCHAR ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_WORDCHAR ? SLJIT_C_ZERO : SLJIT_C_NOT_ZERO));
3896    return cc;    return cc;
3897    
3898    case OP_ANY:    case OP_ANY:
3899    fallback_at_str_end(common, fallbacks);    detect_partial_match(common, backtracks);
3900    read_char(common);    read_char(common);
3901    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
3902      {      {
# Line 3319  switch(type) Line 3907  switch(type)
3907        jump[1] = check_str_end(common);        jump[1] = check_str_end(common);
3908    
3909      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
3910      add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff));      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, common->newline & 0xff));
3911      if (jump[1] != NULL)      if (jump[1] != NULL)
3912        JUMPHERE(jump[1]);        JUMPHERE(jump[1]);
3913      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
3914      }      }
3915    else    else
3916      check_newlinechar(common, common->nltype, fallbacks, TRUE);      check_newlinechar(common, common->nltype, backtracks, TRUE);
3917    return cc;    return cc;
3918    
3919    case OP_ALLANY:    case OP_ALLANY:
3920    fallback_at_str_end(common, fallbacks);    detect_partial_match(common, backtracks);
3921  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3922    if (common->utf)    if (common->utf)
3923      {      {
# Line 3357  switch(type) Line 3945  switch(type)
3945    return cc;    return cc;
3946    
3947    case OP_ANYBYTE:    case OP_ANYBYTE:
3948    fallback_at_str_end(common, fallbacks);    detect_partial_match(common, backtracks);
3949    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));
3950    return cc;    return cc;
3951    
# Line 3370  switch(type) Line 3958  switch(type)
3958    propdata[2] = cc[0];    propdata[2] = cc[0];
3959    propdata[3] = cc[1];    propdata[3] = cc[1];
3960    propdata[4] = XCL_END;    propdata[4] = XCL_END;
3961    compile_xclass_hotpath(common, propdata, fallbacks);    compile_xclass_trypath(common, propdata, backtracks);
3962    return cc + 2;    return cc + 2;
3963  #endif  #endif
3964  #endif  #endif
3965    
3966    case OP_ANYNL:    case OP_ANYNL:
3967    fallback_at_str_end(common, fallbacks);    detect_partial_match(common, backtracks);
3968    read_char(common);    read_char(common);
3969    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);    jump[0] = CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_CR);
3970    /* We don't need to handle soft partial matching case. */    /* We don't need to handle soft partial matching case. */
# Line 3389  switch(type) Line 3977  switch(type)
3977    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));
3978    jump[3] = JUMP(SLJIT_JUMP);    jump[3] = JUMP(SLJIT_JUMP);
3979    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
3980    check_newlinechar(common, common->bsr_nltype, fallbacks, FALSE);    check_newlinechar(common, common->bsr_nltype, backtracks, FALSE);
3981    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
3982    JUMPHERE(jump[2]);    JUMPHERE(jump[2]);
3983    JUMPHERE(jump[3]);    JUMPHERE(jump[3]);
# Line 3397  switch(type) Line 3985  switch(type)
3985    
3986    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
3987    case OP_HSPACE:    case OP_HSPACE:
3988    fallback_at_str_end(common, fallbacks);    detect_partial_match(common, backtracks);
3989    read_char(common);    read_char(common);
3990    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->hspace, JUMP(SLJIT_FAST_CALL));
3991    add_jump(compiler, fallbacks, JUMP(type == OP_NOT_HSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_NOT_HSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
3992    return cc;    return cc;
3993    
3994    case OP_NOT_VSPACE:    case OP_NOT_VSPACE:
3995    case OP_VSPACE:    case OP_VSPACE:
3996    fallback_at_str_end(common, fallbacks);    detect_partial_match(common, backtracks);
3997    read_char(common);    read_char(common);
3998    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->vspace, JUMP(SLJIT_FAST_CALL));
3999    add_jump(compiler, fallbacks, JUMP(type == OP_NOT_VSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(type == OP_NOT_VSPACE ? SLJIT_C_NOT_ZERO : SLJIT_C_ZERO));
4000    return cc;    return cc;
4001    
4002  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4003    case OP_EXTUNI:    case OP_EXTUNI:
4004    fallback_at_str_end(common, fallbacks);    detect_partial_match(common, backtracks);
4005    read_char(common);    read_char(common);
4006    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->getucd, JUMP(SLJIT_FAST_CALL));
4007    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Mc);    OP2(SLJIT_SUB, TMP1, 0, TMP1, 0, SLJIT_IMM, ucp_Mc);
4008    add_jump(compiler, fallbacks, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, ucp_Mn - ucp_Mc));    add_jump(compiler, backtracks, CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, ucp_Mn - ucp_Mc));
4009    
4010    label = LABEL();    label = LABEL();
4011    jump[0] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);    jump[0] = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
# Line 3447  switch(type) Line 4035  switch(type)
4035      OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));      OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
4036      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
4037      if (common->mode == JIT_COMPILE)      if (common->mode == JIT_COMPILE)
4038        add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_END, 0));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_END, 0));
4039      else      else
4040        {        {
4041        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);        jump[1] = CMP(SLJIT_C_EQUAL, TMP2, 0, STR_END, 0);
# Line 3455  switch(type) Line 4043  switch(type)
4043        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS);        COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_LESS);
4044        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);        OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff);
4045        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_NOT_EQUAL);        COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_NOT_EQUAL);
4046        add_jump(compiler, fallbacks, JUMP(SLJIT_C_NOT_EQUAL));        add_jump(compiler, backtracks, JUMP(SLJIT_C_NOT_EQUAL));
4047        check_partial(common, TRUE);        check_partial(common, TRUE);
4048        add_jump(compiler, fallbacks, JUMP(SLJIT_JUMP));        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4049        JUMPHERE(jump[1]);        JUMPHERE(jump[1]);
4050        }        }
4051      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
4052      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff));
4053      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff));
4054      }      }
4055    else if (common->nltype == NLTYPE_FIXED)    else if (common->nltype == NLTYPE_FIXED)
4056      {      {
4057      OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));      OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
4058      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
4059      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_END, 0));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_END, 0));
4060      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, common->newline));
4061      }      }
4062    else    else
4063      {      {
# Line 3478  switch(type) Line 4066  switch(type)
4066      OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));      OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
4067      OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP2, 0, STR_END, 0);      OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP2, 0, STR_END, 0);
4068      jump[2] = JUMP(SLJIT_C_GREATER);      jump[2] = JUMP(SLJIT_C_GREATER);
4069      add_jump(compiler, fallbacks, JUMP(SLJIT_C_LESS));      add_jump(compiler, backtracks, JUMP(SLJIT_C_LESS));
4070      /* Equal. */      /* Equal. */
4071      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
4072      jump[3] = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL);      jump[3] = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL);
4073      add_jump(compiler, fallbacks, JUMP(SLJIT_JUMP));      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4074    
4075      JUMPHERE(jump[1]);      JUMPHERE(jump[1]);
4076      if (common->nltype == NLTYPE_ANYCRLF)      if (common->nltype == NLTYPE_ANYCRLF)
4077        {        {
4078        OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));        OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1));
4079        add_jump(compiler, fallbacks, CMP(SLJIT_C_LESS, TMP2, 0, STR_END, 0));        add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP2, 0, STR_END, 0));
4080        add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, CHAR_NL));
4081        }        }
4082      else      else
4083        {        {
4084        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, STR_PTR, 0);
4085        read_char(common);        read_char(common);
4086        add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, STR_END, 0));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, STR_END, 0));
4087        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->anynewline, JUMP(SLJIT_FAST_CALL));
4088        add_jump(compiler, fallbacks, JUMP(SLJIT_C_ZERO));        add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
4089        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);        OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1);
4090        }        }
4091      JUMPHERE(jump[2]);      JUMPHERE(jump[2]);
# Line 3508  switch(type) Line 4096  switch(type)
4096    return cc;    return cc;
4097    
4098    case OP_EOD:    case OP_EOD:
4099    add_jump(compiler, fallbacks, CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0));    add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0));
4100    check_partial(common, FALSE);    check_partial(common, FALSE);
4101    return cc;    return cc;
4102    
4103    case OP_CIRC:    case OP_CIRC:
4104    OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0);
4105    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, begin));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, begin));
4106    add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER, STR_PTR, 0, TMP1, 0));    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER, STR_PTR, 0, TMP1, 0));
4107    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, notbol));    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, notbol));
4108    add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));    add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
4109    return cc;    return cc;
4110    
4111    case OP_CIRCM:    case OP_CIRCM:
# Line 3525  switch(type) Line 4113  switch(type)
4113    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, begin));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, begin));
4114    jump[1] = CMP(SLJIT_C_GREATER, STR_PTR, 0, TMP1, 0);    jump[1] = CMP(SLJIT_C_GREATER, STR_PTR, 0, TMP1, 0);
4115    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, notbol));    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, notbol));
4116    add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));    add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
4117    jump[0] = JUMP(SLJIT_JUMP);    jump[0] = JUMP(SLJIT_JUMP);
4118    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
4119    
4120    add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0));
4121    if (common->nltype == NLTYPE_FIXED && common->newline > 255)    if (common->nltype == NLTYPE_FIXED && common->newline > 255)
4122      {      {
4123      OP2(SLJIT_SUB, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));      OP2(SLJIT_SUB, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
4124      add_jump(compiler, fallbacks, CMP(SLJIT_C_LESS, TMP2, 0, TMP1, 0));      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, TMP2, 0, TMP1, 0));
4125      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-2));
4126      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(-1));
4127      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff));
4128      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff));
4129      }      }
4130    else    else
4131      {      {
4132      skip_char_back(common);      skip_char_back(common);
4133      read_char(common);      read_char(common);
4134      check_newlinechar(common, common->nltype, fallbacks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
4135      }      }
4136    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4137    return cc;    return cc;
# Line 3551  switch(type) Line 4139  switch(type)
4139    case OP_DOLL:    case OP_DOLL:
4140    OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0);
4141    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, noteol));    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, noteol));
4142    add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));    add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
4143    
4144    if (!common->endonly)    if (!common->endonly)
4145      compile_char1_hotpath(common, OP_EODN, cc, fallbacks);      compile_char1_trypath(common, OP_EODN, cc, backtracks);
4146    else    else
4147      {      {
4148      add_jump(compiler, fallbacks, CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0));      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0));
4149      check_partial(common, FALSE);      check_partial(common, FALSE);
4150      }      }
4151    return cc;    return cc;
# Line 3566  switch(type) Line 4154  switch(type)
4154    jump[1] = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);    jump[1] = CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0);
4155    OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0);    OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0);
4156    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, noteol));    OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, noteol));
4157    add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));    add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
4158    check_partial(common, FALSE);    check_partial(common, FALSE);
4159    jump[0] = JUMP(SLJIT_JUMP);    jump[0] = JUMP(SLJIT_JUMP);
4160    JUMPHERE(jump[1]);    JUMPHERE(jump[1]);
# Line 3576  switch(type) Line 4164  switch(type)
4164      OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));      OP2(SLJIT_ADD, TMP2, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(2));
4165      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));      OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(0));
4166      if (common->mode == JIT_COMPILE)      if (common->mode == JIT_COMPILE)
4167        add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER, TMP2, 0, STR_END, 0));        add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER, TMP2, 0, STR_END, 0));
4168      else      else
4169        {        {
4170        jump[1] = CMP(SLJIT_C_LESS_EQUAL, TMP2, 0, STR_END, 0);        jump[1] = CMP(SLJIT_C_LESS_EQUAL, TMP2, 0, STR_END, 0);
4171        /* STR_PTR = STR_END - IN_UCHARS(1) */        /* STR_PTR = STR_END - IN_UCHARS(1) */
4172        add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff));        add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff));
4173        check_partial(common, TRUE);        check_partial(common, TRUE);
4174        add_jump(compiler, fallbacks, JUMP(SLJIT_JUMP));        add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4175        JUMPHERE(jump[1]);        JUMPHERE(jump[1]);
4176        }        }
4177    
4178      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));      OP1(MOV_UCHAR, TMP2, 0, SLJIT_MEM1(STR_PTR), IN_UCHARS(1));
4179      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, (common->newline >> 8) & 0xff));
4180      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, common->newline & 0xff));
4181      }      }
4182    else    else
4183      {      {
4184      peek_char(common);      peek_char(common);
4185      check_newlinechar(common, common->nltype, fallbacks, FALSE);      check_newlinechar(common, common->nltype, backtracks, FALSE);
4186      }      }
4187    JUMPHERE(jump[0]);    JUMPHERE(jump[0]);
4188    return cc;    return cc;
# Line 3608  switch(type) Line 4196  switch(type)
4196    if (common->mode == JIT_COMPILE && (type == OP_CHAR || !char_has_othercase(common, cc) || char_get_othercase_bit(common, cc) != 0))    if (common->mode == JIT_COMPILE && (type == OP_CHAR || !char_has_othercase(common, cc) || char_get_othercase_bit(common, cc) != 0))
4197      {      {
4198      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(length));      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(length));
4199      add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER, STR_PTR, 0, STR_END, 0));      add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER, STR_PTR, 0, STR_END, 0));
4200    
4201      context.length = IN_UCHARS(length);      context.length = IN_UCHARS(length);
4202      context.sourcereg = -1;      context.sourcereg = -1;
4203  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
4204      context.ucharptr = 0;      context.ucharptr = 0;
4205  #endif  #endif
4206      return byte_sequence_compare(common, type == OP_CHARI, cc, &context, fallbacks);      return byte_sequence_compare(common, type == OP_CHARI, cc, &context, backtracks);
4207      }      }
4208    fallback_at_str_end(common, fallbacks);    detect_partial_match(common, backtracks);
4209    read_char(common);    read_char(common);
4210  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4211    if (common->utf)    if (common->utf)
# Line 3629  switch(type) Line 4217  switch(type)
4217      c = *cc;      c = *cc;
4218    if (type == OP_CHAR || !char_has_othercase(common, cc))    if (type == OP_CHAR || !char_has_othercase(common, cc))
4219      {      {
4220      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c));
4221      return cc + length;      return cc + length;
4222      }      }
4223    oc = char_othercase(common, c);    oc = char_othercase(common, c);
# Line 3637  switch(type) Line 4225  switch(type)
4225    if (ispowerof2(bit))    if (ispowerof2(bit))
4226      {      {
4227      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4228      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));
4229      return cc + length;      return cc + length;
4230      }      }
4231    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c);    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, c);
4232    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);    COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);
4233    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, char_othercase(common, c));    OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, char_othercase(common, c));
4234    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);    COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
4235    add_jump(compiler, fallbacks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
4236    return cc + length;    return cc + length;
4237    
4238    case OP_NOT:    case OP_NOT:
4239    case OP_NOTI:    case OP_NOTI:
4240    fallback_at_str_end(common, fallbacks);    detect_partial_match(common, backtracks);
4241    length = 1;    length = 1;
4242  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4243    if (common->utf)    if (common->utf)
# Line 3660  switch(type) Line 4248  switch(type)
4248        {        {
4249        OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);        OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
4250        if (type == OP_NOT || !char_has_othercase(common, cc))        if (type == OP_NOT || !char_has_othercase(common, cc))
4251          add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c));          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c));
4252        else        else
4253          {          {
4254          /* Since UTF8 code page is fixed, we know that c is in [a-z] or [A-Z] range. */          /* Since UTF8 code page is fixed, we know that c is in [a-z] or [A-Z] range. */
4255          OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x20);          OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, 0x20);
4256          add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, c | 0x20));          add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, c | 0x20));
4257          }          }
4258        /* Skip the variable-length character. */        /* Skip the variable-length character. */
4259        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));
# Line 3690  switch(type) Line 4278  switch(type)
4278      }      }
4279    
4280    if (type == OP_NOT || !char_has_othercase(common, cc))    if (type == OP_NOT || !char_has_othercase(common, cc))
4281      add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c));      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c));
4282    else    else
4283      {      {
4284      oc = char_othercase(common, c);      oc = char_othercase(common, c);
# Line 3698  switch(type) Line 4286  switch(type)
4286      if (ispowerof2(bit))      if (ispowerof2(bit))
4287        {        {
4288        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);        OP2(SLJIT_OR, TMP1, 0, TMP1, 0, SLJIT_IMM, bit);
4289        add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c | bit));
4290        }        }
4291      else      else
4292        {        {
4293        add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c));        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, c));
4294        add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, oc));        add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, oc));
4295        }        }
4296      }      }
4297    return cc + length;    return cc + length;
4298    
4299    case OP_CLASS:    case OP_CLASS:
4300    case OP_NCLASS:    case OP_NCLASS:
4301    fallback_at_str_end(common, fallbacks);    detect_partial_match(common, backtracks);
4302    read_char(common);    read_char(common);
4303  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4304    jump[0] = NULL;    jump[0] = NULL;
# Line 3723  switch(type) Line 4311  switch(type)
4311      jump[0] = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);      jump[0] = CMP(SLJIT_C_GREATER, TMP1, 0, SLJIT_IMM, 255);
4312      if (type == OP_CLASS)      if (type == OP_CLASS)
4313        {        {
4314        add_jump(compiler, fallbacks, jump[0]);        add_jump(compiler, backtracks, jump[0]);
4315        jump[0] = NULL;        jump[0] = NULL;
4316        }        }
4317      }      }
# Line 3733  switch(type) Line 4321  switch(type)
4321    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);    OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(TMP1), (sljit_w)cc);
4322    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);    OP2(SLJIT_SHL, TMP2, 0, SLJIT_IMM, 1, TMP2, 0);
4323    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);
4324    add_jump(compiler, fallbacks, JUMP(SLJIT_C_ZERO));    add_jump(compiler, backtracks, JUMP(SLJIT_C_ZERO));
4325  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4326    if (jump[0] != NULL)    if (jump[0] != NULL)
4327      JUMPHERE(jump[0]);      JUMPHERE(jump[0]);
# Line 3742  switch(type) Line 4330  switch(type)
4330    
4331  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16
4332    case OP_XCLASS:    case OP_XCLASS:
4333    compile_xclass_hotpath(common, cc + LINK_SIZE, fallbacks);    compile_xclass_trypath(common, cc + LINK_SIZE, backtracks);
4334    return cc + GET(cc, 0) - 1;    return cc + GET(cc, 0) - 1;
4335  #endif  #endif
4336    
# Line 3757  switch(type) Line 4345  switch(type)
4345      OP1(SLJIT_MOV, TMP3, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));      OP1(SLJIT_MOV, TMP3, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
4346      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, length);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, length);
4347      label = LABEL();      label = LABEL();
4348      add_jump(compiler, fallbacks, CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP3, 0));      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS_EQUAL, STR_PTR, 0, TMP3, 0));
4349      skip_char_back(common);      skip_char_back(common);
4350      OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);      OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, TMP2, 0, SLJIT_IMM, 1);
4351      JUMPTO(SLJIT_C_NOT_ZERO, label);      JUMPTO(SLJIT_C_NOT_ZERO, label);
# Line 3767  switch(type) Line 4355  switch(type)
4355      {      {
4356      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
4357      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(length));      OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(length));
4358      add_jump(compiler, fallbacks, CMP(SLJIT_C_LESS, STR_PTR, 0, TMP1, 0));      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, STR_PTR, 0, TMP1, 0));
4359      }      }
4360    check_start_used_ptr(common);    check_start_used_ptr(common);
4361    return cc + LINK_SIZE;    return cc + LINK_SIZE;
# Line 3776  SLJIT_ASSERT_STOP(); Line 4364  SLJIT_ASSERT_STOP();
4364  return cc;  return cc;
4365  }  }
4366    
4367  static SLJIT_INLINE pcre_uchar *compile_charn_hotpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, jump_list **fallbacks)  static SLJIT_INLINE pcre_uchar *compile_charn_trypath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, jump_list **backtracks)
4368  {  {
4369  /* This function consumes at least one input character. */  /* This function consumes at least one input character. */
4370  /* To decrease the number of length checks, we try to concatenate the fixed length character sequences. */  /* To decrease the number of length checks, we try to concatenate the fixed length character sequences. */
# Line 3828  if (context.length > 0) Line 4416  if (context.length > 0)
4416    {    {
4417    /* We have a fixed-length byte sequence. */    /* We have a fixed-length byte sequence. */
4418    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, context.length);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, context.length);
4419    add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER, STR_PTR, 0, STR_END, 0));    add_jump(compiler, backtracks, CMP(SLJIT_C_GREATER, STR_PTR, 0, STR_END, 0));
4420    
4421    context.sourcereg = -1;    context.sourcereg = -1;
4422  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
4423    context.ucharptr = 0;    context.ucharptr = 0;
4424  #endif  #endif
4425    do cc = byte_sequence_compare(common, *cc == OP_CHARI, cc + 1, &context, fallbacks); while (context.length > 0);    do cc = byte_sequence_compare(common, *cc == OP_CHARI, cc + 1, &context, backtracks); while (context.length > 0);
4426    return cc;    return cc;
4427    }    }
4428    
4429  /* A non-fixed length character will be checked if length == 0. */  /* A non-fixed length character will be checked if length == 0. */
4430  return compile_char1_hotpath(common, *cc, cc + 1, fallbacks);  return compile_char1_trypath(common, *cc, cc + 1, backtracks);
4431  }  }
4432    
4433  static struct sljit_jump *compile_ref_checks(compiler_common *common, pcre_uchar *cc, jump_list **fallbacks)  static struct sljit_jump *compile_ref_checks(compiler_common *common, pcre_uchar *cc, jump_list **backtracks)
4434  {  {
4435  DEFINE_COMPILER;  DEFINE_COMPILER;
4436  int offset = GET2(cc, 1) << 1;  int offset = GET2(cc, 1) << 1;
# Line 3850  int offset = GET2(cc, 1) << 1; Line 4438  int offset = GET2(cc, 1) << 1;
4438  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
4439  if (!common->jscript_compat)  if (!common->jscript_compat)
4440    {    {
4441    if (fallbacks == NULL)    if (backtracks == NULL)
4442      {      {
4443      /* OVECTOR(1) contains the "string begin - 1" constant. */      /* OVECTOR(1) contains the "string begin - 1" constant. */
4444      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
# Line 3859  if (!common->jscript_compat) Line 4447  if (!common->jscript_compat)
4447      COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);      COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
4448      return JUMP(SLJIT_C_NOT_ZERO);      return JUMP(SLJIT_C_NOT_ZERO);
4449      }      }
4450    add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));    add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
4451    }    }
4452  return CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  return CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
4453  }  }
4454    
4455  /* Forward definitions. */  /* Forward definitions. */
4456  static void compile_hotpath(compiler_common *, pcre_uchar *, pcre_uchar *, fallback_common *);  static void compile_trypath(compiler_common *, pcre_uchar *, pcre_uchar *, backtrack_common *);
4457  static void compile_fallbackpath(compiler_common *, struct fallback_common *);  static void compile_backtrackpath(compiler_common *, struct backtrack_common *);
4458    
4459  #define PUSH_FALLBACK(size, ccstart, error) \  #define PUSH_BACKTRACK(size, ccstart, error) \
4460    do \    do \
4461      { \      { \
4462      fallback = sljit_alloc_memory(compiler, (size)); \      backtrack = sljit_alloc_memory(compiler, (size)); \
4463      if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) \      if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) \
4464        return error; \        return error; \
4465      memset(fallback, 0, size); \      memset(backtrack, 0, size); \
4466      fallback->prev = parent->top; \      backtrack->prev = parent->top; \
4467      fallback->cc = (ccstart); \      backtrack->cc = (ccstart); \
4468      parent->top = fallback; \      parent->top = backtrack; \
4469      } \      } \
4470    while (0)    while (0)
4471    
4472  #define PUSH_FALLBACK_NOVALUE(size, ccstart) \  #define PUSH_BACKTRACK_NOVALUE(size, ccstart) \
4473    do \    do \
4474      { \      { \
4475      fallback = sljit_alloc_memory(compiler, (size)); \      backtrack = sljit_alloc_memory(compiler, (size)); \
4476      if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) \      if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) \
4477        return; \        return; \
4478      memset(fallback, 0, size); \      memset(backtrack, 0, size); \
4479      fallback->prev = parent->top; \      backtrack->prev = parent->top; \
4480      fallback->cc = (ccstart); \      backtrack->cc = (ccstart); \
4481      parent->top = fallback; \      parent->top = backtrack; \
4482      } \      } \
4483    while (0)    while (0)
4484    
4485  #define FALLBACK_AS(type) ((type *)fallback)  #define BACKTRACK_AS(type) ((type *)backtrack)
4486    
4487  static pcre_uchar *compile_ref_hotpath(compiler_common *common, pcre_uchar *cc, jump_list **fallbacks, BOOL withchecks, BOOL emptyfail)  static pcre_uchar *compile_ref_trypath(compiler_common *common, pcre_uchar *cc, jump_list **backtracks, BOOL withchecks, BOOL emptyfail)
4488  {  {
4489  DEFINE_COMPILER;  DEFINE_COMPILER;
4490  int offset = GET2(cc, 1) << 1;  int offset = GET2(cc, 1) << 1;
# Line 3907  struct sljit_jump *nopartial; Line 4495  struct sljit_jump *nopartial;
4495  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
4496  /* OVECTOR(1) contains the "string begin - 1" constant. */  /* OVECTOR(1) contains the "string begin - 1" constant. */
4497  if (withchecks && !common->jscript_compat)  if (withchecks && !common->jscript_compat)
4498    add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));    add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
4499    
4500  #if defined SUPPORT_UTF && defined SUPPORT_UCP  #if defined SUPPORT_UTF && defined SUPPORT_UCP
4501  if (common->utf && *cc == OP_REFI)  if (common->utf && *cc == OP_REFI)
# Line 3924  if (common->utf && *cc == OP_REFI) Line 4512  if (common->utf && *cc == OP_REFI)
4512    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_utf_caselesscmp));    sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_utf_caselesscmp));
4513    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
4514    if (common->mode == JIT_COMPILE)    if (common->mode == JIT_COMPILE)
4515      add_jump(compiler, fallbacks, CMP(SLJIT_C_LESS_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1));      add_jump(compiler, backtracks, CMP(SLJIT_C_LESS_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1));
4516    else    else
4517      {      {
4518      add_jump(compiler, fallbacks, CMP(SLJIT_C_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0));      add_jump(compiler, backtracks, CMP(SLJIT_C_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0));
4519      nopartial = CMP(SLJIT_C_NOT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);      nopartial = CMP(SLJIT_C_NOT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1);
4520      check_partial(common, FALSE);      check_partial(common, FALSE);
4521      add_jump(compiler, fallbacks, JUMP(SLJIT_JUMP));      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4522      JUMPHERE(nopartial);      JUMPHERE(nopartial);
4523      }      }
4524    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_RETURN_REG, 0);    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_RETURN_REG, 0);
# Line 3945  else Line 4533  else
4533    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);    OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, TMP2, 0);
4534    partial = CMP(SLJIT_C_GREATER, STR_PTR, 0, STR_END, 0);    partial = CMP(SLJIT_C_GREATER, STR_PTR, 0, STR_END, 0);
4535    if (common->mode == JIT_COMPILE)    if (common->mode == JIT_COMPILE)
4536      add_jump(compiler, fallbacks, partial);      add_jump(compiler, backtracks, partial);
4537    
4538    add_jump(compiler, *cc == OP_REF ? &common->casefulcmp : &common->caselesscmp, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, *cc == OP_REF ? &common->casefulcmp : &common->caselesscmp, JUMP(SLJIT_FAST_CALL));
4539    add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));    add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
4540    
4541    if (common->mode != JIT_COMPILE)    if (common->mode != JIT_COMPILE)
4542      {      {
# Line 3960  else Line 4548  else
4548      partial = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0);      partial = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0);
4549      OP1(SLJIT_MOV, STR_PTR, 0, STR_END, 0);      OP1(SLJIT_MOV, STR_PTR, 0, STR_END, 0);
4550      add_jump(compiler, *cc == OP_REF ? &common->casefulcmp : &common->caselesscmp, JUMP(SLJIT_FAST_CALL));      add_jump(compiler, *cc == OP_REF ? &common->casefulcmp : &common->caselesscmp, JUMP(SLJIT_FAST_CALL));
4551      add_jump(compiler, fallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));      add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
4552      JUMPHERE(partial);      JUMPHERE(partial);
4553      check_partial(common, FALSE);      check_partial(common, FALSE);
4554      add_jump(compiler, fallbacks, JUMP(SLJIT_JUMP));      add_jump(compiler, backtracks, JUMP(SLJIT_JUMP));
4555      JUMPHERE(nopartial);      JUMPHERE(nopartial);
4556      }      }
4557    }    }
# Line 3971  else Line 4559  else
4559  if (jump != NULL)  if (jump != NULL)
4560    {    {
4561    if (emptyfail)    if (emptyfail)
4562      add_jump(compiler, fallbacks, jump);      add_jump(compiler, backtracks, jump);
4563    else    else
4564      JUMPHERE(jump);      JUMPHERE(jump);
4565    }    }
4566  return cc + 1 + IMM2_SIZE;  return cc + 1 + IMM2_SIZE;
4567  }  }
4568    
4569  static SLJIT_INLINE pcre_uchar *compile_ref_iterator_hotpath(compiler_common *common, pcre_uchar *cc, fallback_common *parent)  static SLJIT_INLINE pcre_uchar *compile_ref_iterator_trypath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
4570  {  {
4571  DEFINE_COMPILER;  DEFINE_COMPILER;
4572  fallback_common *fallback;  backtrack_common *backtrack;
4573  pcre_uchar type;  pcre_uchar type;
4574  struct sljit_label *label;  struct sljit_label *label;
4575  struct sljit_jump *zerolength;  struct sljit_jump *zerolength;
# Line 3990  pcre_uchar *ccbegin = cc; Line 4578  pcre_uchar *ccbegin = cc;
4578  int min = 0, max = 0;  int min = 0, max = 0;
4579  BOOL minimize;  BOOL minimize;
4580    
4581  PUSH_FALLBACK(sizeof(iterator_fallback), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
4582    
4583  type = cc[1 + IMM2_SIZE];  type = cc[1 + IMM2_SIZE];
4584  minimize = (type & 0x1) != 0;  minimize = (type & 0x1) != 0;
# Line 4042  if (!minimize) Line 4630  if (!minimize)
4630      {      {
4631      allocate_stack(common, 1);      allocate_stack(common, 1);
4632      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
4633      zerolength = compile_ref_checks(common, ccbegin, &fallback->topfallbacks);      zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);
4634      }      }
4635    
4636    if (min > 1 || max > 1)    if (min > 1 || max > 1)
4637      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
4638    
4639    label = LABEL();    label = LABEL();
4640    compile_ref_hotpath(common, ccbegin, &fallback->topfallbacks, FALSE, FALSE);    compile_ref_trypath(common, ccbegin, &backtrack->topbacktracks, FALSE, FALSE);
4641    
4642    if (min > 1 || max > 1)    if (min > 1 || max > 1)
4643      {      {
# Line 4077  if (!minimize) Line 4665  if (!minimize)
4665      }      }
4666    
4667    JUMPHERE(zerolength);    JUMPHERE(zerolength);
4668    FALLBACK_AS(iterator_fallback)->hotpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->trypath = LABEL();
4669    
4670    decrease_call_count(common);    decrease_call_count(common);
4671    return cc;    return cc;
# Line 4095  if (min == 0) Line 4683  if (min == 0)
4683    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
4684    }    }
4685  else  else
4686    zerolength = compile_ref_checks(common, ccbegin, &fallback->topfallbacks);    zerolength = compile_ref_checks(common, ccbegin, &backtrack->topbacktracks);
4687    
4688  FALLBACK_AS(iterator_fallback)->hotpath = LABEL();  BACKTRACK_AS(iterator_backtrack)->trypath = LABEL();
4689  if (max > 0)  if (max > 0)
4690    add_jump(compiler, &fallback->topfallbacks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, max));    add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_GREATER_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, max));
4691    
4692  compile_ref_hotpath(common, ccbegin, &fallback->topfallbacks, TRUE, TRUE);  compile_ref_trypath(common, ccbegin, &backtrack->topbacktracks, TRUE, TRUE);
4693  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
4694    
4695  if (min > 1)  if (min > 1)
# Line 4109  if (min > 1) Line 4697  if (min > 1)
4697    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
4698    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
4699    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
4700    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min, FALLBACK_AS(iterator_fallback)->hotpath);    CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, min, BACKTRACK_AS(iterator_backtrack)->trypath);
4701    }    }
4702  else if (max > 0)  else if (max > 0)
4703    OP2(SLJIT_ADD, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 1);    OP2(SLJIT_ADD, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 1);
# Line 4122  decrease_call_count(common); Line 4710  decrease_call_count(common);
4710  return cc;  return cc;
4711  }  }
4712    
4713  static SLJIT_INLINE pcre_uchar *compile_recurse_hotpath(compiler_common *common, pcre_uchar *cc, fallback_common *parent)  static SLJIT_INLINE pcre_uchar *compile_recurse_trypath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
4714  {  {
4715  DEFINE_COMPILER;  DEFINE_COMPILER;
4716  fallback_common *fallback;  backtrack_common *backtrack;
4717  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
4718  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
4719  int start = GET(cc, 1);  int start = GET(cc, 1);
4720    
4721  PUSH_FALLBACK(sizeof(recurse_fallback), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
4722  while (entry != NULL)  while (entry != NULL)
4723    {    {
4724    if (entry->start == start)    if (entry->start == start)
# Line 4175  if (entry->entry == NULL) Line 4763  if (entry->entry == NULL)
4763  else  else
4764    JUMPTO(SLJIT_FAST_CALL, entry->entry);    JUMPTO(SLJIT_FAST_CALL, entry->entry);
4765  /* Leave if the match is failed. */  /* Leave if the match is failed. */
4766  add_jump(compiler, &fallback->topfallbacks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0));  add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 0));
4767  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
4768  }  }
4769    
4770  static pcre_uchar *compile_assert_hotpath(compiler_common *common, pcre_uchar *cc, assert_fallback *fallback, BOOL conditional)  static pcre_uchar *compile_assert_trypath(compiler_common *common, pcre_uchar *cc, assert_backtrack *backtrack, BOOL conditional)
4771  {  {
4772  DEFINE_COMPILER;  DEFINE_COMPILER;
4773  int framesize;  int framesize;
4774  int localptr;  int localptr;
4775  fallback_common altfallback;  backtrack_common altbacktrack;
4776  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
4777  pcre_uchar opcode;  pcre_uchar opcode;
4778  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
4779  jump_list *tmp = NULL;  jump_list *tmp = NULL;
4780  jump_list **target = (conditional) ? &fallback->condfailed : &fallback->common.topfallbacks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
4781  jump_list **found;  jump_list **found;
4782  /* Saving previous accept variables. */  /* Saving previous accept variables. */
4783  struct sljit_label *save_leavelabel = common->leavelabel;  struct sljit_label *save_leavelabel = common->leavelabel;
# Line 4208  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 4796  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
4796  localptr = PRIV_DATA(cc);  localptr = PRIV_DATA(cc);
4797  SLJIT_ASSERT(localptr != 0);  SLJIT_ASSERT(localptr != 0);
4798  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, FALSE);
4799  fallback->framesize = framesize;  backtrack->framesize = framesize;
4800  fallback->localptr = localptr;  backtrack->localptr = localptr;
4801  opcode = *cc;  opcode = *cc;
4802  SLJIT_ASSERT(opcode >= OP_ASSERT && opcode <= OP_ASSERTBACK_NOT);  SLJIT_ASSERT(opcode >= OP_ASSERT && opcode <= OP_ASSERTBACK_NOT);
4803  found = (opcode == OP_ASSERT || opcode == OP_ASSERTBACK) ? &tmp : target;  found = (opcode == OP_ASSERT || opcode == OP_ASSERTBACK) ? &tmp : target;
# Line 4218  cc += GET(cc, 1); Line 4806  cc += GET(cc, 1);
4806    
4807  if (bra == OP_BRAMINZERO)  if (bra == OP_BRAMINZERO)
4808    {    {
4809    /* This is a braminzero fallback path. */    /* This is a braminzero backtrack path. */
4810    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
4811    free_stack(common, 1);    free_stack(common, 1);
4812    brajump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);    brajump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);
# Line 4241  else Line 4829  else
4829    init_frame(common, ccbegin, framesize + 1, 2, FALSE);    init_frame(common, ccbegin, framesize + 1, 2, FALSE);
4830    }    }
4831    
4832  memset(&altfallback, 0, sizeof(fallback_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
4833  common->leavelabel = NULL;  common->leavelabel = NULL;
4834  common->leave = NULL;  common->leave = NULL;
4835  while (1)  while (1)
4836    {    {
4837    common->acceptlabel = NULL;    common->acceptlabel = NULL;
4838    common->accept = NULL;    common->accept = NULL;
4839    altfallback.top = NULL;    altbacktrack.top = NULL;
4840    altfallback.topfallbacks = NULL;    altbacktrack.topbacktracks = NULL;
4841    
4842    if (*ccbegin == OP_ALT)    if (*ccbegin == OP_ALT)
4843      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
4844    
4845    altfallback.cc = ccbegin;    altbacktrack.cc = ccbegin;
4846    compile_hotpath(common, ccbegin + 1 + LINK_SIZE, cc, &altfallback);    compile_trypath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
4847    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
4848      {      {
4849      common->leavelabel = save_leavelabel;      common->leavelabel = save_leavelabel;
# Line 4310  while (1) Line 4898  while (1)
4898      }      }
4899    add_jump(compiler, found, JUMP(SLJIT_JUMP));    add_jump(compiler, found, JUMP(SLJIT_JUMP));
4900    
4901    compile_fallbackpath(common, altfallback.top);    compile_backtrackpath(common, altbacktrack.top);
4902    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
4903      {      {
4904      common->leavelabel = save_leavelabel;      common->leavelabel = save_leavelabel;
# Line 4319  while (1) Line 4907  while (1)
4907      common->accept = save_accept;      common->accept = save_accept;
4908      return NULL;      return NULL;
4909      }      }
4910    set_jumps(altfallback.topfallbacks, LABEL());    set_jumps(altbacktrack.topbacktracks, LABEL());
4911    
4912    if (*cc != OP_ALT)    if (*cc != OP_ALT)
4913      break;      break;
# Line 4396  if (opcode == OP_ASSERT || opcode == OP_ Line 4984  if (opcode == OP_ASSERT || opcode == OP_
4984    
4985    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
4986      {      {
4987      fallback->hotpath = LABEL();      backtrack->trypath = LABEL();
4988      sljit_set_label(jump, fallback->hotpath);      sljit_set_label(jump, backtrack->trypath);
4989      }      }
4990    else if (bra == OP_BRAMINZERO)    else if (bra == OP_BRAMINZERO)
4991      {      {
4992      JUMPTO(SLJIT_JUMP, fallback->hotpath);      JUMPTO(SLJIT_JUMP, backtrack->trypath);
4993      JUMPHERE(brajump);      JUMPHERE(brajump);
4994      if (framesize >= 0)      if (framesize >= 0)
4995        {        {
# Line 4409  if (opcode == OP_ASSERT || opcode == OP_ Line 4997  if (opcode == OP_ASSERT || opcode == OP_
4997        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
4998        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_w));        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_MEM1(STACK_TOP), framesize * sizeof(sljit_w));
4999        }        }
5000      set_jumps(fallback->common.topfallbacks, LABEL());      set_jumps(backtrack->common.topbacktracks, LABEL());
5001      }      }
5002    }    }
5003  else  else
# Line 4439  else Line 5027  else
5027      }      }
5028    
5029    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
5030      fallback->hotpath = LABEL();      backtrack->trypath = LABEL();
5031    else if (bra == OP_BRAMINZERO)    else if (bra == OP_BRAMINZERO)
5032      {      {
5033      JUMPTO(SLJIT_JUMP, fallback->hotpath);      JUMPTO(SLJIT_JUMP, backtrack->trypath);
5034      JUMPHERE(brajump);      JUMPHERE(brajump);
5035      }      }
5036    
5037    if (bra != OP_BRA)    if (bra != OP_BRA)
5038      {      {
5039      SLJIT_ASSERT(found == &fallback->common.topfallbacks);      SLJIT_ASSERT(found == &backtrack->common.topbacktracks);
5040      set_jumps(fallback->common.topfallbacks, LABEL());      set_jumps(backtrack->common.topbacktracks, LABEL());
5041      fallback->common.topfallbacks = NULL;      backtrack->common.topbacktracks = NULL;
5042      }      }
5043    }    }
5044    
# Line 4625  return condition; Line 5213  return condition;
5213                                            Or nothing, if trace is unnecessary                                            Or nothing, if trace is unnecessary
5214  */  */
5215    
5216  static pcre_uchar *compile_bracket_hotpath(compiler_common *common, pcre_uchar *cc, fallback_common *parent)  static pcre_uchar *compile_bracket_trypath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5217  {  {
5218  DEFINE_COMPILER;  DEFINE_COMPILER;
5219  fallback_common *fallback;  backtrack_common *backtrack;
5220  pcre_uchar opcode;  pcre_uchar opcode;
5221  int localptr = 0;  int localptr = 0;
5222  int offset = 0;  int offset = 0;
5223  int stacksize;  int stacksize;
5224  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
5225  pcre_uchar *hotpath;  pcre_uchar *trypath;
5226  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
5227  pcre_uchar ket;  pcre_uchar ket;
5228  assert_fallback *assert;  assert_backtrack *assert;
5229  BOOL has_alternatives;  BOOL has_alternatives;
5230  struct sljit_jump *jump;  struct sljit_jump *jump;
5231  struct sljit_jump *skip;  struct sljit_jump *skip;
5232  struct sljit_label *rmaxlabel = NULL;  struct sljit_label *rmaxlabel = NULL;
5233  struct sljit_jump *braminzerojump = NULL;  struct sljit_jump *braminzerojump = NULL;
5234    
5235  PUSH_FALLBACK(sizeof(bracket_fallback), cc, NULL);  PUSH_BACKTRACK(sizeof(bracket_backtrack), cc, NULL);
5236    
5237  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
5238    {    {
# Line 4655  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 5243  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
5243    
5244  opcode = *cc;  opcode = *cc;
5245  ccbegin = cc;  ccbegin = cc;
5246  hotpath = ccbegin + 1 + LINK_SIZE;  trypath = ccbegin + 1 + LINK_SIZE;
5247    
5248  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)
5249    {    {
5250    /* Drop this bracket_fallback. */    /* Drop this bracket_backtrack. */
5251    parent->top = fallback->prev;    parent->top = backtrack->prev;
5252    return bracketend(cc);    return bracketend(cc);
5253    }    }
5254    
# Line 4672  cc += GET(cc, 1); Line 5260  cc += GET(cc, 1);
5260  has_alternatives = *cc == OP_ALT;  has_alternatives = *cc == OP_ALT;
5261  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))
5262    {    {
5263    has_alternatives = (*hotpath == OP_RREF) ? FALSE : TRUE;    has_alternatives = (*trypath == OP_RREF) ? FALSE : TRUE;
5264    if (*hotpath == OP_NRREF)    if (*trypath == OP_NRREF)
5265      {      {
5266      stacksize = GET2(hotpath, 1);      stacksize = GET2(trypath, 1);
5267      if (common->currententry == NULL || stacksize == RREF_ANY)      if (common->currententry == NULL || stacksize == RREF_ANY)
5268        has_alternatives = FALSE;        has_alternatives = FALSE;
5269      else if (common->currententry->start == 0)      else if (common->currententry->start == 0)
# Line 4696  if (opcode == OP_CBRA || opcode == OP_SC Line 5284  if (opcode == OP_CBRA || opcode == OP_SC
5284    offset = GET2(ccbegin, 1 + LINK_SIZE);    offset = GET2(ccbegin, 1 + LINK_SIZE);
5285    localptr = OVECTOR_PRIV(offset);    localptr = OVECTOR_PRIV(offset);
5286    offset <<= 1;    offset <<= 1;
5287    FALLBACK_AS(bracket_fallback)->localptr = localptr;    BACKTRACK_AS(bracket_backtrack)->localptr = localptr;
5288    hotpath += IMM2_SIZE;    trypath += IMM2_SIZE;
5289    }    }
5290  else if (opcode == OP_ONCE || opcode == OP_SBRA || opcode == OP_SCOND)  else if (opcode == OP_ONCE || opcode == OP_SBRA || opcode == OP_SCOND)
5291    {    {
5292    /* Other brackets simply allocate the next entry. */    /* Other brackets simply allocate the next entry. */
5293    localptr = PRIV_DATA(ccbegin);    localptr = PRIV_DATA(ccbegin);
5294    SLJIT_ASSERT(localptr != 0);    SLJIT_ASSERT(localptr != 0);
5295    FALLBACK_AS(bracket_fallback)->localptr = localptr;    BACKTRACK_AS(bracket_backtrack)->localptr = localptr;
5296    if (opcode == OP_ONCE)    if (opcode == OP_ONCE)
5297      FALLBACK_AS(bracket_fallback)->u.framesize = get_framesize(common, ccbegin, FALSE);      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, FALSE);
5298    }    }
5299    
5300  /* Instructions before the first alternative. */  /* Instructions before the first alternative. */
# Line 4731  if (bra == OP_BRAZERO) Line 5319  if (bra == OP_BRAZERO)
5319    
5320  if (bra == OP_BRAMINZERO)  if (bra == OP_BRAMINZERO)
5321    {    {
5322    /* This is a fallback path! (Since the hot-path of OP_BRAMINZERO matches to the empty string) */    /* This is a backtrack path! (Since the try-path of OP_BRAMINZERO matches to the empty string) */
5323    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
5324    if (ket != OP_KETRMIN)    if (ket != OP_KETRMIN)
5325      {      {
# Line 4748  if (bra == OP_BRAMINZERO) Line 5336  if (bra == OP_BRAMINZERO)
5336        skip = JUMP(SLJIT_JUMP);        skip = JUMP(SLJIT_JUMP);
5337        JUMPHERE(jump);        JUMPHERE(jump);
5338        /* Checking zero-length iteration. */        /* Checking zero-length iteration. */
5339        if (opcode != OP_ONCE || FALLBACK_AS(bracket_fallback)->u.framesize < 0)        if (opcode != OP_ONCE || BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
5340          {          {
5341          /* When we come from outside, localptr contains the previous STR_PTR. */          /* When we come from outside, localptr contains the previous STR_PTR. */
5342          braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);          braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
# Line 4757  if (bra == OP_BRAMINZERO) Line 5345  if (bra == OP_BRAMINZERO)
5345          {          {
5346          /* Except when the whole stack frame must be saved. */          /* Except when the whole stack frame must be saved. */
5347          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
5348          braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (FALLBACK_AS(bracket_fallback)->u.framesize + 1) * sizeof(sljit_w));          braminzerojump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (BACKTRACK_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_w));
5349          }          }
5350        JUMPHERE(skip);        JUMPHERE(skip);
5351        }        }
# Line 4771  if (bra == OP_BRAMINZERO) Line 5359  if (bra == OP_BRAMINZERO)
5359    }    }
5360    
5361  if (ket == OP_KETRMIN)  if (ket == OP_KETRMIN)
5362    FALLBACK_AS(bracket_fallback)->recursivehotpath = LABEL();    BACKTRACK_AS(bracket_backtrack)->recursivetrypath = LABEL();
5363    
5364  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
5365    {    {
5366    rmaxlabel = LABEL();    rmaxlabel = LABEL();
5367    if (has_alternatives && opcode != OP_ONCE && opcode < OP_SBRA)    if (has_alternatives && opcode != OP_ONCE && opcode < OP_SBRA)
5368      FALLBACK_AS(bracket_fallback)->althotpath = rmaxlabel;      BACKTRACK_AS(bracket_backtrack)->alttrypath = rmaxlabel;
5369    }    }
5370    
5371  /* Handling capturing brackets and alternatives. */  /* Handling capturing brackets and alternatives. */
5372  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
5373    {    {
5374    if (FALLBACK_AS(bracket_fallback)->u.framesize < 0)    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
5375      {      {
5376      /* Neither capturing brackets nor recursions are not found in the block. */      /* Neither capturing brackets nor recursions are not found in the block. */
5377      if (ket == OP_KETRMIN)      if (ket == OP_KETRMIN)
# Line 4807  if (opcode == OP_ONCE) Line 5395  if (opcode == OP_ONCE)
5395      {      {
5396      if (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives)      if (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives)
5397        {        {
5398        allocate_stack(common, FALLBACK_AS(bracket_fallback)->u.framesize + 2);        allocate_stack(common, BACKTRACK_AS(bracket_backtrack)->u.framesize + 2);
5399        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
5400        OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(FALLBACK_AS(bracket_fallback)->u.framesize + 1));        OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(BACKTRACK_AS(bracket_backtrack)->u.framesize + 1));
5401        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
5402        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP2, 0);
5403        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5404        init_frame(common, ccbegin, FALLBACK_AS(bracket_fallback)->u.framesize + 1, 2, FALSE);        init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize + 1, 2, FALSE);
5405        }        }
5406      else      else
5407        {        {
5408        allocate_stack(common, FALLBACK_AS(bracket_fallback)->u.framesize + 1);        allocate_stack(common, BACKTRACK_AS(bracket_backtrack)->u.framesize + 1);
5409        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
5410        OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(FALLBACK_AS(bracket_fallback)->u.framesize));        OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(BACKTRACK_AS(bracket_backtrack)->u.framesize));
5411        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, TMP2, 0);
5412        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
5413        init_frame(common, ccbegin, FALLBACK_AS(bracket_fallback)->u.framesize, 1, FALSE);        init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize, 1, FALSE);
5414        }        }
5415      }      }
5416    }    }
# Line 4856  else if (has_alternatives) Line 5444  else if (has_alternatives)
5444  /* Generating code for the first alternative. */  /* Generating code for the first alternative. */
5445  if (opcode == OP_COND || opcode == OP_SCOND)  if (opcode == OP_COND || opcode == OP_SCOND)
5446    {    {
5447    if (*hotpath == OP_CREF)    if (*trypath == OP_CREF)
5448      {      {
5449      SLJIT_ASSERT(has_alternatives);      SLJIT_ASSERT(has_alternatives);
5450      add_jump(compiler, &(FALLBACK_AS(bracket_fallback)->u.condfailed),      add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed),
5451        CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(hotpath, 1) << 1), SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));        CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(trypath, 1) << 1), SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
5452      hotpath += 1 + IMM2_SIZE;      trypath += 1 + IMM2_SIZE;
5453      }      }
5454    else if (*hotpath == OP_NCREF)    else if (*trypath == OP_NCREF)
5455      {      {
5456      SLJIT_ASSERT(has_alternatives);      SLJIT_ASSERT(has_alternatives);
5457      stacksize = GET2(hotpath, 1);      stacksize = GET2(trypath, 1);
5458      jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(stacksize << 1), SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));      jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(stacksize << 1), SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
5459    
5460      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);
# Line 4877  if (opcode == OP_COND || opcode == OP_SC Line 5465  if (opcode == OP_COND || opcode == OP_SC
5465      OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, common->name_table);      OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, common->name_table);
5466      sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchovector));      sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchovector));
5467      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
5468      add_jump(compiler, &(FALLBACK_AS(bracket_fallback)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0));      add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0));
5469    
5470      JUMPHERE(jump);      JUMPHERE(jump);
5471      hotpath += 1 + IMM2_SIZE;      trypath += 1 + IMM2_SIZE;
5472      }      }
5473    else if (*hotpath == OP_RREF || *hotpath == OP_NRREF)    else if (*trypath == OP_RREF || *trypath == OP_NRREF)
5474      {      {
5475      /* Never has other case. */      /* Never has other case. */
5476      FALLBACK_AS(bracket_fallback)->u.condfailed = NULL;      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;
5477    
5478      stacksize = GET2(hotpath, 1);      stacksize = GET2(trypath, 1);
5479      if (common->currententry == NULL)      if (common->currententry == NULL)
5480        stacksize = 0;        stacksize = 0;
5481      else if (stacksize == RREF_ANY)      else if (stacksize == RREF_ANY)
# Line 4897  if (opcode == OP_COND || opcode == OP_SC Line 5485  if (opcode == OP_COND || opcode == OP_SC
5485      else      else
5486        stacksize = stacksize == GET2(common->start, common->currententry->start + 1 + LINK_SIZE);        stacksize = stacksize == GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
5487    
5488      if (*hotpath == OP_RREF || stacksize || common->currententry == NULL)      if (*trypath == OP_RREF || stacksize || common->currententry == NULL)
5489        {        {
5490        SLJIT_ASSERT(!has_alternatives);        SLJIT_ASSERT(!has_alternatives);
5491        if (stacksize != 0)        if (stacksize != 0)
5492          hotpath += 1 + IMM2_SIZE;          trypath += 1 + IMM2_SIZE;
5493        else        else
5494          {          {
5495          if (*cc == OP_ALT)          if (*cc == OP_ALT)
5496            {            {
5497            hotpath = cc + 1 + LINK_SIZE;            trypath = cc + 1 + LINK_SIZE;
5498            cc += GET(cc, 1);            cc += GET(cc, 1);
5499            }            }
5500          else          else
5501            hotpath = cc;            trypath = cc;
5502          }          }
5503        }        }
5504      else      else
5505        {        {
5506        SLJIT_ASSERT(has_alternatives);        SLJIT_ASSERT(has_alternatives);
5507    
5508        stacksize = GET2(hotpath, 1);        stacksize = GET2(trypath, 1);
5509        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);
5510        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);
5511        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);
# Line 4927  if (opcode == OP_COND || opcode == OP_SC Line 5515  if (opcode == OP_COND || opcode == OP_SC
5515        OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, common->name_table);        OP1(SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, common->name_table);
5516        sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchgroups));        sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchgroups));
5517        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
5518        add_jump(compiler, &(FALLBACK_AS(bracket_fallback)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0));        add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 0));
5519        hotpath += 1 + IMM2_SIZE;        trypath += 1 + IMM2_SIZE;
5520        }        }
5521      }      }
5522    else    else
5523      {      {
5524      SLJIT_ASSERT(has_alternatives && *hotpath >= OP_ASSERT && *hotpath <= OP_ASSERTBACK_NOT);      SLJIT_ASSERT(has_alternatives && *trypath >= OP_ASSERT && *trypath <= OP_ASSERTBACK_NOT);
5525      /* Similar code as PUSH_FALLBACK macro. */      /* Similar code as PUSH_BACKTRACK macro. */
5526      assert = sljit_alloc_memory(compiler, sizeof(assert_fallback));      assert = sljit_alloc_memory(compiler, sizeof(assert_backtrack));
5527      if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))      if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5528        return NULL;        return NULL;
5529      memset(assert, 0, sizeof(assert_fallback));      memset(assert, 0, sizeof(assert_backtrack));
5530      assert->common.cc = hotpath;      assert->common.cc = trypath;
5531      FALLBACK_AS(bracket_fallback)->u.assert = assert;      BACKTRACK_AS(bracket_backtrack)->u.assert = assert;
5532      hotpath = compile_assert_hotpath(common, hotpath, assert, TRUE);      trypath = compile_assert_trypath(common, trypath, assert, TRUE);
5533      }      }
5534    }    }
5535    
5536  compile_hotpath(common, hotpath, cc, fallback);  compile_trypath(common, trypath, cc, backtrack);
5537  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))  if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5538    return NULL;    return NULL;
5539    
5540  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
5541    {    {
5542    if (FALLBACK_AS(bracket_fallback)->u.framesize < 0)    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
5543      {      {
5544      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
5545      /* TMP2 which is set here used by OP_KETRMAX below. */      /* TMP2 which is set here used by OP_KETRMAX below. */
# Line 4966  if (opcode == OP_ONCE) Line 5554  if (opcode == OP_ONCE)
5554    else    else
5555      {      {
5556      stacksize = (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives) ? 2 : 1;      stacksize = (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives) ? 2 : 1;
5557      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_IMM, (FALLBACK_AS(bracket_fallback)->u.framesize + stacksize) * sizeof(sljit_w));      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_IMM, (BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize) * sizeof(sljit_w));
5558      if (ket == OP_KETRMAX)      if (ket == OP_KETRMAX)
5559        {        {
5560        /* TMP2 which is set here used by OP_KETRMAX below. */        /* TMP2 which is set here used by OP_KETRMAX below. */
# Line 5001  if (has_alternatives) Line 5589  if (has_alternatives)
5589    if (opcode != OP_ONCE)    if (opcode != OP_ONCE)
5590      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
5591    if (ket != OP_KETRMAX)    if (ket != OP_KETRMAX)
5592      FALLBACK_AS(bracket_fallback)->althotpath = LABEL();      BACKTRACK_AS(bracket_backtrack)->alttrypath = LABEL();
5593    }    }
5594    
5595  /* Must be after the hotpath label. */  /* Must be after the trypath label. */
5596  if (offset != 0)  if (offset != 0)
5597    {    {
5598    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
# Line 5017  if (ket == OP_KETRMAX) Line 5605  if (ket == OP_KETRMAX)
5605    if (opcode == OP_ONCE || opcode >= OP_SBRA)    if (opcode == OP_ONCE || opcode >= OP_SBRA)
5606      {      {
5607      if (has_alternatives)      if (has_alternatives)
5608        FALLBACK_AS(bracket_fallback)->althotpath = LABEL();        BACKTRACK_AS(bracket_backtrack)->alttrypath = LABEL();
5609      /* Checking zero-length iteration. */      /* Checking zero-length iteration. */
5610      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
5611          {
5612        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STR_PTR, 0, rmaxlabel);        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STR_PTR, 0, rmaxlabel);
5613          /* Drop STR_PTR for greedy plus quantifier. */
5614          if (bra != OP_BRAZERO)
5615            free_stack(common, 1);
5616          }
5617      else      else
5618        /* TMP2 must contain the starting STR_PTR. */        /* TMP2 must contain the starting STR_PTR. */
5619        CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, rmaxlabel);        CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, rmaxlabel);
5620      }      }
5621    else    else
5622      JUMPTO(SLJIT_JUMP, rmaxlabel);      JUMPTO(SLJIT_JUMP, rmaxlabel);
5623    FALLBACK_AS(bracket_fallback)->recursivehotpath = LABEL();    BACKTRACK_AS(bracket_backtrack)->recursivetrypath = LABEL();
5624    }    }
5625    
5626  if (bra == OP_BRAZERO)  if (bra == OP_BRAZERO)
5627    FALLBACK_AS(bracket_fallback)->zerohotpath = LABEL();    BACKTRACK_AS(bracket_backtrack)->zerotrypath = LABEL();
5628    
5629  if (bra == OP_BRAMINZERO)  if (bra == OP_BRAMINZERO)
5630    {    {
5631    /* This is a fallback path! (From the viewpoint of OP_BRAMINZERO) */    /* This is a backtrack path! (From the viewpoint of OP_BRAMINZERO) */
5632    JUMPTO(SLJIT_JUMP, ((braminzero_fallback *)parent)->hotpath);    JUMPTO(SLJIT_JUMP, ((braminzero_backtrack *)parent)->trypath);
5633    if (braminzerojump != NULL)    if (braminzerojump != NULL)
5634      {      {
5635      JUMPHERE(braminzerojump);      JUMPHERE(braminzerojump);
5636      /* We need to release the end pointer to perform the      /* We need to release the end pointer to perform the
5637      fallback for the zero-length iteration. When      backtrack for the zero-length iteration. When
5638      framesize is < 0, OP_ONCE will do the release itself. */      framesize is < 0, OP_ONCE will do the release itself. */
5639      if (opcode == OP_ONCE && FALLBACK_AS(bracket_fallback)->u.framesize >= 0)      if (opcode == OP_ONCE && BACKTRACK_AS(bracket_backtrack)->u.framesize >= 0)
5640        {        {
5641        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
5642        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));        add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
# Line 5051  if (bra == OP_BRAMINZERO) Line 5644  if (bra == OP_BRAMINZERO)
5644      else if (ket == OP_KETRMIN && opcode != OP_ONCE)      else if (ket == OP_KETRMIN && opcode != OP_ONCE)
5645        free_stack(common, 1);        free_stack(common, 1);
5646      }      }
5647    /* Continue to the normal fallback. */    /* Continue to the normal backtrack. */
5648    }    }
5649    
5650  if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)  if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)
# Line 5064  cc += 1 + LINK_SIZE; Line 5657  cc += 1 + LINK_SIZE;
5657  return cc;  return cc;
5658  }  }
5659    
5660  static pcre_uchar *compile_bracketpos_hotpath(compiler_common *common, pcre_uchar *cc, fallback_common *parent)  static pcre_uchar *compile_bracketpos_trypath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5661  {  {
5662  DEFINE_COMPILER;  DEFINE_COMPILER;
5663  fallback_common *fallback;  backtrack_common *backtrack;
5664  pcre_uchar opcode;  pcre_uchar opcode;
5665  int localptr;  int localptr;
5666  int cbraprivptr = 0;  int cbraprivptr = 0;
# Line 5080  int stack; Line 5673  int stack;
5673  struct sljit_label *loop = NULL;  struct sljit_label *loop = NULL;
5674  struct jump_list *emptymatch = NULL;  struct jump_list *emptymatch = NULL;
5675    
5676  PUSH_FALLBACK(sizeof(bracketpos_fallback), cc, NULL);  PUSH_BACKTRACK(sizeof(bracketpos_backtrack), cc, NULL);
5677  if (*cc == OP_BRAPOSZERO)  if (*cc == OP_BRAPOSZERO)
5678    {    {
5679    zero = TRUE;    zero = TRUE;
# Line 5090  if (*cc == OP_BRAPOSZERO) Line 5683  if (*cc == OP_BRAPOSZERO)
5683  opcode = *cc;  opcode = *cc;
5684  localptr = PRIV_DATA(cc);  localptr = PRIV_DATA(cc);
5685  SLJIT_ASSERT(localptr != 0);  SLJIT_ASSERT(localptr != 0);
5686  FALLBACK_AS(bracketpos_fallback)->localptr = localptr;  BACKTRACK_AS(bracketpos_backtrack)->localptr = localptr;
5687  switch(opcode)  switch(opcode)
5688    {    {
5689    case OP_BRAPOS:    case OP_BRAPOS:
# Line 5112  switch(opcode) Line 5705  switch(opcode)
5705    }    }
5706    
5707  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, FALSE);
5708  FALLBACK_AS(bracketpos_fallback)->framesize = framesize;  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;
5709  if (framesize < 0)  if (framesize < 0)
5710    {    {
5711    stacksize = (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS) ? 2 : 1;    stacksize = (opcode == OP_CBRAPOS || opcode == OP_SCBRAPOS) ? 2 : 1;
5712    if (!zero)    if (!zero)
5713      stacksize++;      stacksize++;
5714    FALLBACK_AS(bracketpos_fallback)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
5715    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
5716    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STACK_TOP, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, STACK_TOP, 0);
5717    
# Line 5142  else Line 5735  else
5735      stacksize++;      stacksize++;
5736    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)
5737      stacksize++;      stacksize++;
5738    FALLBACK_AS(bracketpos_fallback)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
5739    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
5740    
5741    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
# Line 5169  if (opcode == OP_CBRAPOS || opcode == OP Line 5762  if (opcode == OP_CBRAPOS || opcode == OP
5762  loop = LABEL();  loop = LABEL();
5763  while (*cc != OP_KETRPOS)  while (*cc != OP_KETRPOS)
5764    {    {
5765    fallback->top = NULL;    backtrack->top = NULL;
5766    fallback->topfallbacks = NULL;    backtrack->topbacktracks = NULL;
5767    cc += GET(cc, 1);    cc += GET(cc, 1);
5768    
5769    compile_hotpath(common, ccbegin, cc, fallback);    compile_trypath(common, ccbegin, cc, backtrack);
5770    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5771      return NULL;      return NULL;
5772    
# Line 5234  while (*cc != OP_KETRPOS) Line 5827  while (*cc != OP_KETRPOS)
5827    JUMPTO(SLJIT_JUMP, loop);    JUMPTO(SLJIT_JUMP, loop);
5828    flush_stubs(common);    flush_stubs(common);
5829    
5830    compile_fallbackpath(common, fallback->top);    compile_backtrackpath(common, backtrack->top);
5831    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5832      return NULL;      return NULL;
5833    set_jumps(fallback->topfallbacks, LABEL());    set_jumps(backtrack->topbacktracks, LABEL());
5834    
5835    if (framesize < 0)    if (framesize < 0)
5836      {      {
# Line 5267  while (*cc != OP_KETRPOS) Line 5860  while (*cc != OP_KETRPOS)
5860    ccbegin = cc + 1 + LINK_SIZE;    ccbegin = cc + 1 + LINK_SIZE;
5861    }    }
5862    
5863  fallback->topfallbacks = NULL;  backtrack->topbacktracks = NULL;
5864  if (!zero)  if (!zero)
5865    {    {
5866    if (framesize < 0)    if (framesize < 0)
5867      add_jump(compiler, &fallback->topfallbacks, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(stacksize - 1), SLJIT_IMM, 0));      add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(stacksize - 1), SLJIT_IMM, 0));
5868    else /* TMP2 is set to [localptr] above. */    else /* TMP2 is set to [localptr] above. */
5869      add_jump(compiler, &fallback->topfallbacks, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(TMP2), (stacksize - 1) * sizeof(sljit_w), SLJIT_IMM, 0));      add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(TMP2), (stacksize - 1) * sizeof(sljit_w), SLJIT_IMM, 0));
5870    }    }
5871    
5872  /* None of them matched. */  /* None of them matched. */
# Line 5374  if (end != NULL) Line 5967  if (end != NULL)
5967  return cc;  return cc;
5968  }  }
5969    
5970  static pcre_uchar *compile_iterator_hotpath(compiler_common *common, pcre_uchar *cc, fallback_common *parent)  static pcre_uchar *compile_iterator_trypath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
5971  {  {
5972  DEFINE_COMPILER;  DEFINE_COMPILER;
5973  fallback_common *fallback;  backtrack_common *backtrack;
5974  pcre_uchar opcode;  pcre_uchar opcode;
5975  pcre_uchar type;  pcre_uchar type;
5976  int arg1 = -1, arg2 = -1;  int arg1 = -1, arg2 = -1;
# Line 5385  pcre_uchar* end; Line 5978  pcre_uchar* end;
5978  jump_list *nomatch = NULL;  jump_list *nomatch = NULL;
5979  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
5980  struct sljit_label *label;  struct sljit_label *label;
5981    int localptr = PRIV_DATA(cc);
5982    int base = (localptr == 0) ? SLJIT_MEM1(STACK_TOP) : SLJIT_MEM1(SLJIT_LOCALS_REG);
5983    int offset0 = (localptr == 0) ? STACK(0) : localptr;
5984    int offset1 = (localptr == 0) ? STACK(1) : localptr + sizeof(sljit_w);
5985    
5986  PUSH_FALLBACK(sizeof(iterator_fallback), cc, NULL);  PUSH_BACKTRACK(sizeof(iterator_backtrack), cc, NULL);
5987    
5988  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, &end);
5989    
# Line 5398  switch(opcode) Line 5995  switch(opcode)
5995    case OP_CRRANGE:    case OP_CRRANGE:
5996    if (type == OP_ANYNL || type == OP_EXTUNI)    if (type == OP_ANYNL || type == OP_EXTUNI)
5997      {      {
5998        SLJIT_ASSERT(localptr == 0);
5999      if (opcode == OP_STAR || opcode == OP_UPTO)      if (opcode == OP_STAR || opcode == OP_UPTO)
6000        {        {
6001        allocate_stack(common, 2);        allocate_stack(common, 2);
# Line 5413  switch(opcode) Line 6011  switch(opcode)
6011        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 0);
6012    
6013      label = LABEL();      label = LABEL();
6014      compile_char1_hotpath(common, type, cc, &fallback->topfallbacks);      compile_char1_trypath(common, type, cc, &backtrack->topbacktracks);
6015      if (opcode == OP_UPTO || opcode == OP_CRRANGE)      if (opcode == OP_UPTO || opcode == OP_CRRANGE)
6016        {        {
6017        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);
# Line 5433  switch(opcode) Line 6031  switch(opcode)
6031      }      }
6032    else    else
6033      {      {
6034      allocate_stack(common, 2);      if (opcode == OP_PLUS)
6035      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);        compile_char1_trypath(common, type, cc, &backtrack->topbacktracks);
6036      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 1);      if (localptr == 0)
6037          allocate_stack(common, 2);
6038        OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
6039        OP1(SLJIT_MOV, base, offset1, SLJIT_IMM, 1);
6040      label = LABEL();      label = LABEL();
6041      compile_char1_hotpath(common, type, cc, &nomatch);      compile_char1_trypath(common, type, cc, &nomatch);
6042      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
6043      if (opcode <= OP_PLUS || (opcode == OP_CRRANGE && arg1 == 0))      if (opcode <= OP_PLUS || (opcode == OP_CRRANGE && arg1 == 0))
6044        {        {
6045        OP2(SLJIT_ADD, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 1);        OP2(SLJIT_ADD, base, offset1, base, offset1, SLJIT_IMM, 1);
6046        JUMPTO(SLJIT_JUMP, label);        JUMPTO(SLJIT_JUMP, label);
6047        }        }
6048      else      else
6049        {        {
6050        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));        OP1(SLJIT_MOV, TMP1, 0, base, offset1);
6051        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);        OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
6052        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);        OP1(SLJIT_MOV, base, offset1, TMP1, 0);
6053        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg1 + 1, label);        CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg1 + 1, label);
6054        }        }
6055      set_jumps(nomatch, LABEL());      set_jumps(nomatch, LABEL());
6056      if (opcode == OP_PLUS || opcode == OP_CRRANGE)      if (opcode == OP_CRRANGE)
6057        add_jump(compiler, &fallback->topfallbacks,        add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_LESS, base, offset1, SLJIT_IMM, arg2 + 1));
6058          CMP(SLJIT_C_LESS, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, opcode == OP_PLUS ? 2 : arg2 + 1));      OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
     OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));  
6059      }      }
6060    FALLBACK_AS(iterator_fallback)->hotpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->trypath = LABEL();
6061    break;    break;
6062    
6063    case OP_MINSTAR:    case OP_MINSTAR:
6064    case OP_MINPLUS:    case OP_MINPLUS:
   allocate_stack(common, 1);  
   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  
6065    if (opcode == OP_MINPLUS)    if (opcode == OP_MINPLUS)
6066      add_jump(compiler, &fallback->topfallbacks, JUMP(SLJIT_JUMP));      compile_char1_trypath(common, type, cc, &backtrack->topbacktracks);
6067    FALLBACK_AS(iterator_fallback)->hotpath = LABEL();    if (localptr == 0)
6068        allocate_stack(common, 1);
6069      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
6070      BACKTRACK_AS(iterator_backtrack)->trypath = LABEL();
6071    break;    break;
6072    
6073    case OP_MINUPTO:    case OP_MINUPTO:
6074    case OP_CRMINRANGE:    case OP_CRMINRANGE:
6075    allocate_stack(common, 2);    if (localptr == 0)
6076    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      allocate_stack(common, 2);
6077    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 1);    OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
6078      OP1(SLJIT_MOV, base, offset1, SLJIT_IMM, 1);
6079    if (opcode == OP_CRMINRANGE)    if (opcode == OP_CRMINRANGE)
6080      add_jump(compiler, &fallback->topfallbacks, JUMP(SLJIT_JUMP));      add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_JUMP));
6081    FALLBACK_AS(iterator_fallback)->hotpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->trypath = LABEL();
6082    break;    break;
6083    
6084    case OP_QUERY:    case OP_QUERY:
6085    case OP_MINQUERY:    case OP_MINQUERY:
6086    allocate_stack(common, 1);    if (localptr == 0)
6087    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      allocate_stack(common, 1);
6088      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
6089    if (opcode == OP_QUERY)    if (opcode == OP_QUERY)
6090      compile_char1_hotpath(common, type, cc, &fallback->topfallbacks);      compile_char1_trypath(common, type, cc, &backtrack->topbacktracks);
6091    FALLBACK_AS(iterator_fallback)->hotpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->trypath = LABEL();
6092    break;    break;
6093    
6094    case OP_EXACT:    case OP_EXACT:
6095    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 1);
6096    label = LABEL();    label = LABEL();
6097    compile_char1_hotpath(common, type, cc, &fallback->topfallbacks);    compile_char1_trypath(common, type, cc, &backtrack->topbacktracks);
6098    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);
6099    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
6100    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, TMP1, 0);
# Line 5505  switch(opcode) Line 6108  switch(opcode)
6108      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 1);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 1);
6109    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STR_PTR, 0);
6110    label = LABEL();    label = LABEL();
6111    compile_char1_hotpath(common, type, cc, &nomatch);    compile_char1_trypath(common, type, cc, &nomatch);
6112    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STR_PTR, 0);
6113    if (opcode != OP_POSUPTO)    if (opcode != OP_POSUPTO)
6114      {      {
# Line 5522  switch(opcode) Line 6125  switch(opcode)
6125      }      }
6126    set_jumps(nomatch, LABEL());    set_jumps(nomatch, LABEL());
6127    if (opcode == OP_POSPLUS)    if (opcode == OP_POSPLUS)
6128      add_jump(compiler, &fallback->topfallbacks, CMP(SLJIT_C_LESS, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 2));      add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_LESS, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, 2));
6129    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
6130    break;    break;
6131    
6132    case OP_POSQUERY:    case OP_POSQUERY:
6133    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STR_PTR, 0);
6134    compile_char1_hotpath(common, type, cc, &nomatch);    compile_char1_trypath(common, type, cc, &nomatch);
6135    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STR_PTR, 0);
6136    set_jumps(nomatch, LABEL());    set_jumps(nomatch, LABEL());
6137    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);
# Line 5543  decrease_call_count(common); Line 6146  decrease_call_count(common);
6146  return end;  return end;
6147  }  }
6148    
6149  static SLJIT_INLINE pcre_uchar *compile_fail_accept_hotpath(compiler_common *common, pcre_uchar *cc, fallback_common *parent)  static SLJIT_INLINE pcre_uchar *compile_fail_accept_trypath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
6150  {  {
6151  DEFINE_COMPILER;  DEFINE_COMPILER;
6152  fallback_common *fallback;  backtrack_common *backtrack;
6153    
6154  PUSH_FALLBACK(sizeof(bracket_fallback), cc, NULL);  PUSH_BACKTRACK(sizeof(bracket_backtrack), cc, NULL);
6155    
6156  if (*cc == OP_FAIL)  if (*cc == OP_FAIL)
6157    {    {
6158    add_jump(compiler, &fallback->topfallbacks, JUMP(SLJIT_JUMP));    add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_JUMP));
6159    return cc + 1;    return cc + 1;
6160    }    }
6161    
# Line 5572  else Line 6175  else
6175    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), common->acceptlabel);    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), common->acceptlabel);
6176  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
6177  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty));
6178  add_jump(compiler, &fallback->topfallbacks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));  add_jump(compiler, &backtrack->topbacktracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
6179  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty_atstart));  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, notempty_atstart));
6180  if (common->acceptlabel == NULL)  if (common->acceptlabel == NULL)
6181    add_jump(compiler, &common->accept, CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0));    add_jump(compiler, &common->accept, CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, 0));
# Line 5583  if (common->acceptlabel == NULL) Line 6186  if (common->acceptlabel == NULL)
6186    add_jump(compiler, &common->accept, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0));    add_jump(compiler, &common->accept, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0));
6187  else  else
6188    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, common->acceptlabel);    CMPTO(SLJIT_C_NOT_EQUAL, TMP2, 0, STR_PTR, 0, common->acceptlabel);
6189  add_jump(compiler, &fallback->topfallbacks, JUMP(SLJIT_JUMP));  add_jump(compiler, &backtrack->topbacktracks, JUMP(SLJIT_JUMP));
6190  return cc + 1;  return cc + 1;
6191  }  }
6192    
6193  static SLJIT_INLINE pcre_uchar *compile_close_hotpath(compiler_common *common, pcre_uchar *cc)  static SLJIT_INLINE pcre_uchar *compile_close_trypath(compiler_common *common, pcre_uchar *cc)
6194  {  {
6195  DEFINE_COMPILER;  DEFINE_COMPILER;
6196  int offset = GET2(cc, 1);  int offset = GET2(cc, 1);
# Line 5603  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_R Line 6206  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_R
6206  return cc + 1 + IMM2_SIZE;  return cc + 1 + IMM2_SIZE;
6207  }  }
6208    
6209  static void compile_hotpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, fallback_common *parent)  static void compile_trypath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, backtrack_common *parent)
6210  {  {
6211  DEFINE_COMPILER;  DEFINE_COMPILER;
6212  fallback_common *fallback;  backtrack_common *backtrack;
6213    
6214  while (cc < ccend)  while (cc < ccend)
6215    {    {
# Line 5642  while (cc < ccend) Line 6245  while (cc < ccend)
6245      case OP_NOT:      case OP_NOT:
6246      case OP_NOTI:      case OP_NOTI:
6247      case OP_REVERSE:      case OP_REVERSE:
6248      cc = compile_char1_hotpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->nextfallbacks : &parent->topfallbacks);      cc = compile_char1_trypath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);
6249      break;      break;
6250    
6251      case OP_SET_SOM:      case OP_SET_SOM:
6252      PUSH_FALLBACK_NOVALUE(sizeof(fallback_common), cc);      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);
6253      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0));
6254      allocate_stack(common, 1);      allocate_stack(common, 1);
6255      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(0), STR_PTR, 0);
# Line 5657  while (cc < ccend) Line 6260  while (cc < ccend)
6260      case OP_CHAR:      case OP_CHAR:
6261      case OP_CHARI:      case OP_CHARI:
6262      if (common->mode == JIT_COMPILE)      if (common->mode == JIT_COMPILE)
6263        cc = compile_charn_hotpath(common, cc, ccend, parent->top != NULL ? &parent->top->nextfallbacks : &parent->topfallbacks);        cc = compile_charn_trypath(common, cc, ccend, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);
6264      else      else
6265        cc = compile_char1_hotpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->nextfallbacks : &parent->topfallbacks);        cc = compile_char1_trypath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);
6266      break;      break;
6267    
6268      case OP_STAR:      case OP_STAR:
# Line 5727  while (cc < ccend) Line 6330  while (cc < ccend)
6330      case OP_TYPEPOSPLUS:      case OP_TYPEPOSPLUS:
6331      case OP_TYPEPOSQUERY:      case OP_TYPEPOSQUERY:
6332      case OP_TYPEPOSUPTO:      case OP_TYPEPOSUPTO:
6333      cc = compile_iterator_hotpath(common, cc, parent);      cc = compile_iterator_trypath(common, cc, parent);
6334      break;      break;
6335    
6336      case OP_CLASS:      case OP_CLASS:
6337      case OP_NCLASS:      case OP_NCLASS:
6338      if (cc[1 + (32 / sizeof(pcre_uchar))] >= OP_CRSTAR && cc[1 + (32 / sizeof(pcre_uchar))] <= OP_CRMINRANGE)      if (cc[1 + (32 / sizeof(pcre_uchar))] >= OP_CRSTAR && cc[1 + (32 / sizeof(pcre_uchar))] <= OP_CRMINRANGE)
6339        cc = compile_iterator_hotpath(common, cc, parent);        cc = compile_iterator_trypath(common, cc, parent);
6340      else      else
6341        cc = compile_char1_hotpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->nextfallbacks : &parent->topfallbacks);        cc = compile_char1_trypath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);
6342      break;      break;
6343    
6344  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || defined COMPILE_PCRE16
6345      case OP_XCLASS:      case OP_XCLASS:
6346      if (*(cc + GET(cc, 1)) >= OP_CRSTAR && *(cc + GET(cc, 1)) <= OP_CRMINRANGE)      if (*(cc + GET(cc, 1)) >= OP_CRSTAR && *(cc + GET(cc, 1)) <= OP_CRMINRANGE)
6347        cc = compile_iterator_hotpath(common, cc, parent);        cc = compile_iterator_trypath(common, cc, parent);
6348      else      else
6349        cc = compile_char1_hotpath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->nextfallbacks : &parent->topfallbacks);        cc = compile_char1_trypath(common, *cc, cc + 1, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks);
6350      break;      break;
6351  #endif  #endif
6352    
6353      case OP_REF:      case OP_REF:
6354      case OP_REFI:      case OP_REFI:
6355      if (cc[1 + IMM2_SIZE] >= OP_CRSTAR && cc[1 + IMM2_SIZE] <= OP_CRMINRANGE)      if (cc[1 + IMM2_SIZE] >= OP_CRSTAR && cc[1 + IMM2_SIZE] <= OP_CRMINRANGE)
6356        cc = compile_ref_iterator_hotpath(common, cc, parent);        cc = compile_ref_iterator_trypath(common, cc, parent);
6357      else      else
6358        cc = compile_ref_hotpath(common, cc, parent->top != NULL ? &parent->top->nextfallbacks : &parent->topfallbacks, TRUE, FALSE);        cc = compile_ref_trypath(common, cc, parent->top != NULL ? &parent->top->nextbacktracks : &parent->topbacktracks, TRUE, FALSE);
6359      break;      break;
6360    
6361      case OP_RECURSE:      case OP_RECURSE:
6362      cc = compile_recurse_hotpath(common, cc, parent);      cc = compile_recurse_trypath(common, cc, parent);
6363      break;      break;
6364    
6365      case OP_ASSERT:      case OP_ASSERT:
6366      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
6367      case OP_ASSERTBACK:      case OP_ASSERTBACK:
6368      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
6369      PUSH_FALLBACK_NOVALUE(sizeof(assert_fallback), cc);      PUSH_BACKTRACK_NOVALUE(sizeof(assert_backtrack), cc);
6370      cc = compile_assert_hotpath(common, cc, FALLBACK_AS(assert_fallback), FALSE);      cc = compile_assert_trypath(common, cc, BACKTRACK_AS(assert_backtrack), FALSE);
6371      break;      break;
6372    
6373      case OP_BRAMINZERO:      case OP_BRAMINZERO:
6374      PUSH_FALLBACK_NOVALUE(sizeof(braminzero_fallback), cc);      PUSH_BACKTRACK_NOVALUE(sizeof(braminzero_backtrack), cc);
6375      cc = bracketend(cc + 1);      cc = bracketend(cc + 1);
6376      if (*(cc - 1 - LINK_SIZE) != OP_KETRMIN)      if (*(cc - 1 - LINK_SIZE) != OP_KETRMIN)
6377        {        {
# Line 5781  while (cc < ccend) Line 6384  while (cc < ccend)
6384        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6385        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), STR_PTR, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), STR_PTR, 0);
6386        }        }
6387      FALLBACK_AS(braminzero_fallback)->hotpath = LABEL();      BACKTRACK_AS(braminzero_backtrack)->trypath = LABEL();
6388      if (cc[1] > OP_ASSERTBACK_NOT)      if (cc[1] > OP_ASSERTBACK_NOT)
6389        decrease_call_count(common);        decrease_call_count(common);
6390      break;      break;
# Line 5794  while (cc < ccend) Line 6397  while (cc < ccend)
6397      case OP_SBRA:      case OP_SBRA:
6398      case OP_SCBRA:      case OP_SCBRA:
6399      case OP_SCOND:      case OP_SCOND:
6400      cc = compile_bracket_hotpath(common, cc, parent);      cc = compile_bracket_trypath(common, cc, parent);
6401      break;      break;
6402    
6403      case OP_BRAZERO:      case OP_BRAZERO:
6404      if (cc[1] > OP_ASSERTBACK_NOT)      if (cc[1] > OP_ASSERTBACK_NOT)
6405        cc = compile_bracket_hotpath(common, cc, parent);        cc = compile_bracket_trypath(common, cc, parent);
6406      else      else
6407        {        {
6408        PUSH_FALLBACK_NOVALUE(sizeof(assert_fallback), cc);        PUSH_BACKTRACK_NOVALUE(sizeof(assert_backtrack), cc);
6409        cc = compile_assert_hotpath(common, cc, FALLBACK_AS(assert_fallback), FALSE);        cc = compile_assert_trypath(common, cc, BACKTRACK_AS(assert_backtrack), FALSE);
6410        }        }
6411      break;      break;
6412    
# Line 5812  while (cc < ccend) Line 6415  while (cc < ccend)
6415      case OP_SBRAPOS:      case OP_SBRAPOS:
6416      case OP_SCBRAPOS:      case OP_SCBRAPOS:
6417      case OP_BRAPOSZERO:      case OP_BRAPOSZERO:
6418      cc = compile_bracketpos_hotpath(common, cc, parent);      cc = compile_bracketpos_trypath(common, cc, parent);
6419      break;      break;
6420    
6421      case OP_MARK:      case OP_MARK:
6422      PUSH_FALLBACK_NOVALUE(sizeof(fallback_common), cc);      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);
6423      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
6424      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);
6425      allocate_stack(common, 1);      allocate_stack(common, 1);
# Line 5829  while (cc < ccend) Line 6432  while (cc < ccend)
6432      break;      break;
6433    
6434      case OP_COMMIT:      case OP_COMMIT:
6435      PUSH_FALLBACK_NOVALUE(sizeof(fallback_common), cc);      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);
6436      cc += 1;      cc += 1;
6437      break;      break;
6438    
6439      case OP_FAIL:      case OP_FAIL:
6440      case OP_ACCEPT:      case OP_ACCEPT:
6441      case OP_ASSERT_ACCEPT:      case OP_ASSERT_ACCEPT:
6442      cc = compile_fail_accept_hotpath(common, cc, parent);      cc = compile_fail_accept_trypath(common, cc, parent);
6443      break;      break;
6444    
6445      case OP_CLOSE:      case OP_CLOSE:
6446      cc = compile_close_hotpath(common, cc);      cc = compile_close_trypath(common, cc);
6447      break;      break;
6448    
6449      case OP_SKIPZERO:      case OP_SKIPZERO:
# Line 5857  while (cc < ccend) Line 6460  while (cc < ccend)
6460  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
6461  }  }
6462    
6463  #undef PUSH_FALLBACK  #undef PUSH_BACKTRACK
6464  #undef PUSH_FALLBACK_NOVALUE  #undef PUSH_BACKTRACK_NOVALUE
6465  #undef FALLBACK_AS  #undef BACKTRACK_AS
6466    
6467  #define COMPILE_FALLBACKPATH(current) \  #define COMPILE_BACKTRACKPATH(current) \
6468    do \    do \
6469      { \      { \
6470      compile_fallbackpath(common, (current)); \      compile_backtrackpath(common, (current)); \
6471      if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) \      if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) \
6472        return; \        return; \
6473      } \      } \
# Line 5872  SLJIT_ASSERT(cc == ccend); Line 6475  SLJIT_ASSERT(cc == ccend);
6475    
6476  #define CURRENT_AS(type) ((type *)current)  #define CURRENT_AS(type) ((type *)current)
6477    
6478  static void compile_iterator_fallbackpath(compiler_common *common, struct fallback_common *current)  static void compile_iterator_backtrackpath(compiler_common *common, struct backtrack_common *current)
6479  {  {
6480  DEFINE_COMPILER;  DEFINE_COMPILER;
6481  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
# Line 5881  pcre_uchar type; Line 6484  pcre_uchar type;
6484  int arg1 = -1, arg2 = -1;  int arg1 = -1, arg2 = -1;
6485  struct sljit_label *label = NULL;  struct sljit_label *label = NULL;
6486  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
6487    jump_list *jumplist = NULL;
6488    int localptr = PRIV_DATA(cc);
6489    int base = (localptr == 0) ? SLJIT_MEM1(STACK_TOP) : SLJIT_MEM1(SLJIT_LOCALS_REG);
6490    int offset0 = (localptr == 0) ? STACK(0) : localptr;
6491    int offset1 = (localptr == 0) ? STACK(1) : localptr + sizeof(sljit_w);
6492    
6493  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, NULL);  cc = get_iterator_parameters(common, cc, &opcode, &type, &arg1, &arg2, NULL);
6494    
# Line 5892  switch(opcode) Line 6500  switch(opcode)
6500    case OP_CRRANGE:    case OP_CRRANGE:
6501    if (type == OP_ANYNL || type == OP_EXTUNI)    if (type == OP_ANYNL || type == OP_EXTUNI)
6502      {      {
6503      set_jumps(current->topfallbacks, LABEL());      SLJIT_ASSERT(localptr == 0);
6504        set_jumps(current->topbacktracks, LABEL());
6505      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6506      free_stack(common, 1);      free_stack(common, 1);
6507      CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(iterator_fallback)->hotpath);      CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(iterator_backtrack)->trypath);
6508      }      }
6509    else    else
6510      {      {
6511      if (opcode == OP_STAR || opcode == OP_UPTO)      if (opcode <= OP_PLUS || opcode == OP_UPTO)
6512        arg2 = 0;        arg2 = 0;
6513      else if (opcode == OP_PLUS)      OP1(SLJIT_MOV, TMP1, 0, base, offset1);
6514        arg2 = 1;      jump = CMP(SLJIT_C_LESS_EQUAL, TMP1, 0, SLJIT_IMM, arg2 + 1);
6515      jump = CMP(SLJIT_C_LESS_EQUAL, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, arg2 + 1);      OP2(SLJIT_SUB, base, offset1, TMP1, 0, SLJIT_IMM, 1);
6516      OP2(SLJIT_SUB, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, 1);      OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
     OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));  
6517      skip_char_back(common);      skip_char_back(common);
6518      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
6519      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_fallback)->hotpath);      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->trypath);
6520      if (opcode == OP_PLUS || opcode == OP_CRRANGE)      if (opcode == OP_CRRANGE)
6521        set_jumps(current->topfallbacks, LABEL());        set_jumps(current->topbacktracks, LABEL());
6522      JUMPHERE(jump);      JUMPHERE(jump);
6523      free_stack(common, 2);      if (localptr == 0)
6524          free_stack(common, 2);
6525        if (opcode == OP_PLUS)
6526          set_jumps(current->topbacktracks, LABEL());
6527      }      }
6528    break;    break;
6529    
6530    case OP_MINSTAR:    case OP_MINSTAR:
6531    case OP_MINPLUS:    case OP_MINPLUS:
6532    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
6533      compile_char1_trypath(common, type, cc, &jumplist);
6534      OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
6535      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->trypath);
6536      set_jumps(jumplist, LABEL());
6537      if (localptr == 0)
6538        free_stack(common, 1);
6539    if (opcode == OP_MINPLUS)    if (opcode == OP_MINPLUS)
6540      {      set_jumps(current->topbacktracks, LABEL());
     set_jumps(current->topfallbacks, LABEL());  
     current->topfallbacks = NULL;  
     }  
   compile_char1_hotpath(common, type, cc, &current->topfallbacks);  
   OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  
   JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_fallback)->hotpath);  
   set_jumps(current->topfallbacks, LABEL());  
   free_stack(common, 1);  
6541    break;    break;
6542    
6543    case OP_MINUPTO:    case OP_MINUPTO:
6544    case OP_CRMINRANGE:    case OP_CRMINRANGE:
6545    if (opcode == OP_CRMINRANGE)    if (opcode == OP_CRMINRANGE)
6546      {      {
     set_jumps(current->topfallbacks, LABEL());  
     current->topfallbacks = NULL;  
6547      label = LABEL();      label = LABEL();
6548        set_jumps(current->topbacktracks, label);
6549      }      }
6550    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
6551    compile_char1_hotpath(common, type, cc, &current->topfallbacks);    compile_char1_trypath(common, type, cc, &jumplist);
6552    
6553    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));    OP1(SLJIT_MOV, TMP1, 0, base, offset1);
6554    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, base, offset0, STR_PTR, 0);
6555    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, TMP1, 0, TMP1, 0, SLJIT_IMM, 1);
6556    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);    OP1(SLJIT_MOV, base, offset1, TMP1, 0);
6557    
6558    if (opcode == OP_CRMINRANGE)    if (opcode == OP_CRMINRANGE)
6559      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg2 + 1, label);      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg2 + 1, label);
6560    
6561    if (opcode == OP_CRMINRANGE && arg1 == 0)    if (opcode == OP_CRMINRANGE && arg1 == 0)
6562      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_fallback)->hotpath);      JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->trypath);
6563    else    else
6564      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg1 + 2, CURRENT_AS(iterator_fallback)->hotpath);      CMPTO(SLJIT_C_LESS, TMP1, 0, SLJIT_IMM, arg1 + 2, CURRENT_AS(iterator_backtrack)->trypath);
6565    
6566    set_jumps(current->topfallbacks, LABEL());    set_jumps(jumplist, LABEL());
6567    free_stack(common, 2);    if (localptr == 0)
6568        free_stack(common, 2);
6569    break;    break;
6570    
6571    case OP_QUERY:    case OP_QUERY:
6572    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
6573    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);    OP1(SLJIT_MOV, base, offset0, SLJIT_IMM, 0);
6574    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(iterator_fallback)->hotpath);    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(iterator_backtrack)->trypath);
6575    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
6576    set_jumps(current->topfallbacks, LABEL());    set_jumps(current->topbacktracks, LABEL());
6577    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
6578    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);    OP1(SLJIT_MOV, base, offset0, SLJIT_IMM, 0);
6579    JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_fallback)->hotpath);    JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->trypath);
6580    JUMPHERE(jump);    JUMPHERE(jump);
6581    free_stack(common, 1);    if (localptr == 0)
6582        free_stack(common, 1);
6583    break;    break;
6584    
6585    case OP_MINQUERY:    case OP_MINQUERY:
6586    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, base, offset0);
6587    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);    OP1(SLJIT_MOV, base, offset0, SLJIT_IMM, 0);
6588    jump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);    jump = CMP(SLJIT_C_EQUAL, STR_PTR, 0, SLJIT_IMM, 0);
6589    compile_char1_hotpath(common, type, cc, &current->topfallbacks);    compile_char1_trypath(common, type, cc, &jumplist);
6590    JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_fallback)->hotpath);    JUMPTO(SLJIT_JUMP, CURRENT_AS(iterator_backtrack)->trypath);
6591    set_jumps(current->topfallbacks, LABEL());    set_jumps(jumplist, LABEL());
6592    JUMPHERE(jump);    JUMPHERE(jump);
6593    free_stack(common, 1);    if (localptr == 0)
6594        free_stack(common, 1);
6595    break;    break;
6596    
6597    case OP_EXACT:    case OP_EXACT:
6598    case OP_POSPLUS:    case OP_POSPLUS:
6599    set_jumps(current->topfallbacks, LABEL());    set_jumps(current->topbacktracks, LABEL());
6600    break;    break;
6601    
6602    case OP_POSSTAR:    case OP_POSSTAR:
# Line 5999  switch(opcode) Line 6610  switch(opcode)
6610    }    }
6611  }  }
6612    
6613  static void compile_ref_iterator_fallbackpath(compiler_common *common, struct fallback_common *current)  static void compile_ref_iterator_backtrackpath(compiler_common *common, struct backtrack_common *current)
6614  {  {
6615  DEFINE_COMPILER;  DEFINE_COMPILER;
6616  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
# Line 6008  pcre_uchar type; Line 6619  pcre_uchar type;
6619  type = cc[1 + IMM2_SIZE];  type = cc[1 + IMM2_SIZE];
6620  if ((type & 0x1) == 0)  if ((type & 0x1) == 0)
6621    {    {
6622    set_jumps(current->topfallbacks, LABEL());    set_jumps(current->topbacktracks, LABEL());
6623    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6624    free_stack(common, 1);    free_stack(common, 1);
6625    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(iterator_fallback)->hotpath);    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(iterator_backtrack)->trypath);
6626    return;    return;
6627    }    }
6628    
6629  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6630  CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(iterator_fallback)->hotpath);  CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(iterator_backtrack)->trypath);
6631  set_jumps(current->topfallbacks, LABEL());  set_jumps(current->topbacktracks, LABEL());
6632  free_stack(common, 2);  free_stack(common, 2);
6633  }  }
6634    
6635  static void compile_recurse_fallbackpath(compiler_common *common, struct fallback_common *current)  static void compile_recurse_backtrackpath(compiler_common *common, struct backtrack_common *current)
6636  {  {
6637  DEFINE_COMPILER;  DEFINE_COMPILER;
6638    
6639  set_jumps(current->topfallbacks, LABEL());  set_jumps(current->topbacktracks, LABEL());
6640    
6641  if (common->has_set_som && common->mark_ptr != 0)  if (common->has_set_som && common->mark_ptr != 0)
6642    {    {
# Line 6043  else if (common->has_set_som || common-> Line 6654  else if (common->has_set_som || common->
6654    }    }
6655  }  }
6656    
6657  static void compile_assert_fallbackpath(compiler_common *common, struct fallback_common *current)  static void compile_assert_backtrackpath(compiler_common *common, struct backtrack_common *current)
6658  {  {
6659  DEFINE_COMPILER;  DEFINE_COMPILER;
6660  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
# Line 6059  if (*cc == OP_BRAZERO) Line 6670  if (*cc == OP_BRAZERO)
6670    
6671  if (bra == OP_BRAZERO)  if (bra == OP_BRAZERO)
6672    {    {
6673    SLJIT_ASSERT(current->topfallbacks == NULL);    SLJIT_ASSERT(current->topbacktracks == NULL);
6674    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6675    }    }
6676    
6677  if (CURRENT_AS(assert_fallback)->framesize < 0)  if (CURRENT_AS(assert_backtrack)->framesize < 0)
6678    {    {
6679    set_jumps(current->topfallbacks, LABEL());    set_jumps(current->topbacktracks, LABEL());
6680    
6681    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
6682      {      {
6683      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6684      CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(assert_fallback)->hotpath);      CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(assert_backtrack)->trypath);
6685      free_stack(common, 1);      free_stack(common, 1);
6686      }      }
6687    return;    return;
# Line 6081  if (bra == OP_BRAZERO) Line 6692  if (bra == OP_BRAZERO)
6692    if (*cc == OP_ASSERT_NOT || *cc == OP_ASSERTBACK_NOT)    if (*cc == OP_ASSERT_NOT || *cc == OP_ASSERTBACK_NOT)
6693      {      {
6694      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6695      CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(assert_fallback)->hotpath);      CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(assert_backtrack)->trypath);
6696      free_stack(common, 1);      free_stack(common, 1);
6697      return;      return;
6698      }      }
# Line 6091  if (bra == OP_BRAZERO) Line 6702  if (bra == OP_BRAZERO)
6702    
6703  if (*cc == OP_ASSERT || *cc == OP_ASSERTBACK)  if (*cc == OP_ASSERT || *cc == OP_ASSERTBACK)
6704    {    {
6705    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(assert_fallback)->localptr);    OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(assert_backtrack)->localptr);
6706    add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));    add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
6707    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(assert_fallback)->localptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(assert_fallback)->framesize * sizeof(sljit_w));    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(assert_backtrack)->localptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(assert_backtrack)->framesize * sizeof(sljit_w));
6708    
6709    set_jumps(current->topfallbacks, LABEL());    set_jumps(current->topbacktracks, LABEL());
6710    }    }
6711  else  else
6712    set_jumps(current->topfallbacks, LABEL());    set_jumps(current->topbacktracks, LABEL());
6713    
6714  if (bra == OP_BRAZERO)  if (bra == OP_BRAZERO)
6715    {    {
6716    /* We know there is enough place on the stack. */    /* We know there is enough place on the stack. */
6717    OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));    OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_w));
6718    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6719    JUMPTO(SLJIT_JUMP, CURRENT_AS(assert_fallback)->hotpath);    JUMPTO(SLJIT_JUMP, CURRENT_AS(assert_backtrack)->trypath);
6720    JUMPHERE(brajump);    JUMPHERE(brajump);
6721    }    }
6722  }  }
6723    
6724  static void compile_bracket_fallbackpath(compiler_common *common, struct fallback_common *current)  static void compile_bracket_backtrackpath(compiler_common *common, struct backtrack_common *current)
6725  {  {
6726  DEFINE_COMPILER;  DEFINE_COMPILER;
6727  int opcode;  int opcode;
6728  int offset = 0;  int offset = 0;
6729  int localptr = CURRENT_AS(bracket_fallback)->localptr;  int localptr = CURRENT_AS(bracket_backtrack)->localptr;
6730  int stacksize;  int stacksize;
6731  int count;  int count;
6732  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
# Line 6125  jump_list *jumplist = NULL; Line 6736  jump_list *jumplist = NULL;
6736  jump_list *jumplistitem = NULL;  jump_list *jumplistitem = NULL;
6737  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
6738  pcre_uchar ket;  pcre_uchar ket;
6739  assert_fallback *assert;  assert_backtrack *assert;
6740  BOOL has_alternatives;  BOOL has_alternatives;
6741  struct sljit_jump *brazero = NULL;  struct sljit_jump *brazero = NULL;
6742  struct sljit_jump *once = NULL;  struct sljit_jump *once = NULL;
# Line 6144  ket = *(bracketend(ccbegin) - 1 - LINK_S Line 6755  ket = *(bracketend(ccbegin) - 1 - LINK_S
6755  cc += GET(cc, 1);  cc += GET(cc, 1);
6756  has_alternatives = *cc == OP_ALT;  has_alternatives = *cc == OP_ALT;
6757  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))
6758    has_alternatives = (ccbegin[1 + LINK_SIZE] >= OP_ASSERT && ccbegin[1 + LINK_SIZE] <= OP_ASSERTBACK_NOT) || CURRENT_AS(bracket_fallback)->u.condfailed != NULL;    has_alternatives = (ccbegin[1 + LINK_SIZE] >= OP_ASSERT && ccbegin[1 + LINK_SIZE] <= OP_ASSERTBACK_NOT) || CURRENT_AS(bracket_backtrack)->u.condfailed != NULL;
6759  if (opcode == OP_CBRA || opcode == OP_SCBRA)  if (opcode == OP_CBRA || opcode == OP_SCBRA)
6760    offset = (GET2(ccbegin, 1 + LINK_SIZE)) << 1;    offset = (GET2(ccbegin, 1 + LINK_SIZE)) << 1;
6761  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))
# Line 6154  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC) Line 6765  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC)
6765    
6766  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
6767    {    {
6768    if (bra != OP_BRAZERO)    if (bra == OP_BRAZERO)
     free_stack(common, 1);  
   else  
6769      {      {
6770      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6771      free_stack(common, 1);      free_stack(common, 1);
# Line 6171  else if (ket == OP_KETRMIN) Line 6780  else if (ket == OP_KETRMIN)
6780      if (opcode >= OP_SBRA || opcode == OP_ONCE)      if (opcode >= OP_SBRA || opcode == OP_ONCE)
6781        {        {
6782        /* Checking zero-length iteration. */        /* Checking zero-length iteration. */
6783        if (opcode != OP_ONCE || CURRENT_AS(bracket_fallback)->u.framesize < 0)        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize < 0)
6784          CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, CURRENT_AS(bracket_fallback)->recursivehotpath);          CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, CURRENT_AS(bracket_backtrack)->recursivetrypath);
6785        else        else
6786          {          {
6787          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
6788          CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (CURRENT_AS(bracket_fallback)->u.framesize + 1) * sizeof(sljit_w), CURRENT_AS(bracket_fallback)->recursivehotpath);          CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_MEM1(TMP1), (CURRENT_AS(bracket_backtrack)->u.framesize + 1) * sizeof(sljit_w), CURRENT_AS(bracket_backtrack)->recursivetrypath);
6789          }          }
6790        if (opcode != OP_ONCE)        if (opcode != OP_ONCE)
6791          free_stack(common, 1);          free_stack(common, 1);
6792        }        }
6793      else      else
6794        JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_fallback)->recursivehotpath);        JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->recursivetrypath);
6795      }      }
6796    rminlabel = LABEL();    rminlabel = LABEL();
6797    }    }
# Line 6195  else if (bra == OP_BRAZERO) Line 6804  else if (bra == OP_BRAZERO)
6804    
6805  if (SLJIT_UNLIKELY(opcode == OP_ONCE))  if (SLJIT_UNLIKELY(opcode == OP_ONCE))
6806    {    {
6807    if (CURRENT_AS(bracket_fallback)->u.framesize >= 0)    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
6808      {      {
6809      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
6810      add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));      add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
# Line 6250  else if (*cc == OP_ALT) Line 6859  else if (*cc == OP_ALT)
6859    cc = ccbegin + GET(ccbegin, 1);    cc = ccbegin + GET(ccbegin, 1);
6860    }    }
6861    
6862  COMPILE_FALLBACKPATH(current->top);  COMPILE_BACKTRACKPATH(current->top);
6863  if (current->topfallbacks)  if (current->topbacktracks)
6864    set_jumps(current->topfallbacks, LABEL());    set_jumps(current->topbacktracks, LABEL());
6865    
6866  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))
6867    {    {
# Line 6260  if (SLJIT_UNLIKELY(opcode == OP_COND) || Line 6869  if (SLJIT_UNLIKELY(opcode == OP_COND) ||
6869    if (ccbegin[1 + LINK_SIZE] >= OP_ASSERT && ccbegin[1 + LINK_SIZE] <= OP_ASSERTBACK_NOT)    if (ccbegin[1 + LINK_SIZE] >= OP_ASSERT && ccbegin[1 + LINK_SIZE] <= OP_ASSERTBACK_NOT)
6870      {      {
6871      SLJIT_ASSERT(has_alternatives);      SLJIT_ASSERT(has_alternatives);
6872      assert = CURRENT_AS(bracket_fallback)->u.assert;      assert = CURRENT_AS(bracket_backtrack)->u.assert;
6873      if (assert->framesize >= 0 && (ccbegin[1 + LINK_SIZE] == OP_ASSERT || ccbegin[1 + LINK_SIZE] == OP_ASSERTBACK))      if (assert->framesize >= 0 && (ccbegin[1 + LINK_SIZE] == OP_ASSERT || ccbegin[1 + LINK_SIZE] == OP_ASSERTBACK))
6874        {        {
6875        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->localptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->localptr);
# Line 6268  if (SLJIT_UNLIKELY(opcode == OP_COND) || Line 6877  if (SLJIT_UNLIKELY(opcode == OP_COND) ||
6877        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->localptr, SLJIT_MEM1(STACK_TOP), assert->framesize * sizeof(sljit_w));        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), assert->localptr, SLJIT_MEM1(STACK_TOP), assert->framesize * sizeof(sljit_w));
6878        }        }
6879      cond = JUMP(SLJIT_JUMP);      cond = JUMP(SLJIT_JUMP);
6880      set_jumps(CURRENT_AS(bracket_fallback)->u.assert->condfailed, LABEL());      set_jumps(CURRENT_AS(bracket_backtrack)->u.assert->condfailed, LABEL());
6881      }      }
6882    else if (CURRENT_AS(bracket_fallback)->u.condfailed != NULL)    else if (CURRENT_AS(bracket_backtrack)->u.condfailed != NULL)
6883      {      {
6884      SLJIT_ASSERT(has_alternatives);      SLJIT_ASSERT(has_alternatives);
6885      cond = JUMP(SLJIT_JUMP);      cond = JUMP(SLJIT_JUMP);
6886      set_jumps(CURRENT_AS(bracket_fallback)->u.condfailed, LABEL());      set_jumps(CURRENT_AS(bracket_backtrack)->u.condfailed, LABEL());
6887      }      }
6888    else    else
6889      SLJIT_ASSERT(!has_alternatives);      SLJIT_ASSERT(!has_alternatives);
# Line 6286  if (has_alternatives) Line 6895  if (has_alternatives)
6895    do    do
6896      {      {
6897      current->top = NULL;      current->top = NULL;
6898      current->topfallbacks = NULL;      current->topbacktracks = NULL;
6899      current->nextfallbacks = NULL;      current->nextbacktracks = NULL;
6900      if (*cc == OP_ALT)      if (*cc == OP_ALT)
6901        {        {
6902        ccprev = cc + 1 + LINK_SIZE;        ccprev = cc + 1 + LINK_SIZE;
# Line 6299  if (has_alternatives) Line 6908  if (has_alternatives)
6908          else          else
6909            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6910          }          }
6911        compile_hotpath(common, ccprev, cc, current);        compile_trypath(common, ccprev, cc, current);
6912        if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))        if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
6913          return;          return;
6914        }        }
6915    
6916      /* Instructions after the current alternative is succesfully matched. */      /* Instructions after the current alternative is succesfully matched. */
6917      /* There is a similar code in compile_bracket_hotpath. */      /* There is a similar code in compile_bracket_trypath. */
6918      if (opcode == OP_ONCE)      if (opcode == OP_ONCE)
6919        {        {
6920        if (CURRENT_AS(bracket_fallback)->u.framesize < 0)        if (CURRENT_AS(bracket_backtrack)->u.framesize < 0)
6921          {          {
6922          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);          OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr);
6923          /* TMP2 which is set here used by OP_KETRMAX below. */          /* TMP2 which is set here used by OP_KETRMAX below. */
# Line 6322  if (has_alternatives) Line 6931  if (has_alternatives)
6931          }          }
6932        else        else
6933          {          {
6934          OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_IMM, (CURRENT_AS(bracket_fallback)->u.framesize + 2) * sizeof(sljit_w));          OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_IMM, (CURRENT_AS(bracket_backtrack)->u.framesize + 2) * sizeof(sljit_w));
6935          if (ket == OP_KETRMAX)          if (ket == OP_KETRMAX)
6936            {            {
6937            /* TMP2 which is set here used by OP_KETRMAX below. */            /* TMP2 which is set here used by OP_KETRMAX below. */
# Line 6338  if (has_alternatives) Line 6947  if (has_alternatives)
6947        stacksize++;        stacksize++;
6948    
6949      if (stacksize > 0) {      if (stacksize > 0) {
6950        if (opcode != OP_ONCE || CURRENT_AS(bracket_fallback)->u.framesize >= 0)        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
6951          allocate_stack(common, stacksize);          allocate_stack(common, stacksize);
6952        else        else
6953          {          {
# Line 6368  if (has_alternatives) Line 6977  if (has_alternatives)
6977        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 0), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 0), TMP1, 0);
6978        }        }
6979    
6980      JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_fallback)->althotpath);      JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->alttrypath);
6981    
6982      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
6983        {        {
# Line 6377  if (has_alternatives) Line 6986  if (has_alternatives)
6986        jumplist = jumplist->next;        jumplist = jumplist->next;
6987        }        }
6988    
6989      COMPILE_FALLBACKPATH(current->top);      COMPILE_BACKTRACKPATH(current->top);
6990      if (current->topfallbacks)      if (current->topbacktracks)
6991        set_jumps(current->topfallbacks, LABEL());        set_jumps(current->topbacktracks, LABEL());
6992      SLJIT_ASSERT(!current->nextfallbacks);      SLJIT_ASSERT(!current->nextbacktracks);
6993      }      }
6994    while (*cc == OP_ALT);    while (*cc == OP_ALT);
6995    SLJIT_ASSERT(!jumplist);    SLJIT_ASSERT(!jumplist);
# Line 6388  if (has_alternatives) Line 6997  if (has_alternatives)
6997    if (cond != NULL)    if (cond != NULL)
6998      {      {
6999      SLJIT_ASSERT(opcode == OP_COND || opcode == OP_SCOND);      SLJIT_ASSERT(opcode == OP_COND || opcode == OP_SCOND);
7000      assert = CURRENT_AS(bracket_fallback)->u.assert;      assert = CURRENT_AS(bracket_backtrack)->u.assert;
7001      if ((ccbegin[1 + LINK_SIZE] == OP_ASSERT_NOT || ccbegin[1 + LINK_SIZE] == OP_ASSERTBACK_NOT) && assert->framesize >= 0)      if ((ccbegin[1 + LINK_SIZE] == OP_ASSERT_NOT || ccbegin[1 + LINK_SIZE] == OP_ASSERTBACK_NOT) && assert->framesize >= 0)
7002    
7003        {        {
# Line 6422  else if (opcode == OP_SBRA || opcode == Line 7031  else if (opcode == OP_SBRA || opcode ==
7031  else if (opcode == OP_ONCE)  else if (opcode == OP_ONCE)
7032    {    {
7033    cc = ccbegin + GET(ccbegin, 1);    cc = ccbegin + GET(ccbegin, 1);
7034    if (CURRENT_AS(bracket_fallback)->u.framesize >= 0)    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
7035      {      {
7036      /* Reset head and drop saved frame. */      /* Reset head and drop saved frame. */
7037      stacksize = (ket == OP_KETRMAX || ket == OP_KETRMIN || *cc == OP_ALT) ? 2 : 1;      stacksize = (ket == OP_KETRMAX || ket == OP_KETRMIN || *cc == OP_ALT) ? 2 : 1;
7038      free_stack(common, CURRENT_AS(bracket_fallback)->u.framesize + stacksize);      free_stack(common, CURRENT_AS(bracket_backtrack)->u.framesize + stacksize);
7039      }      }
7040    else if (ket == OP_KETRMAX || (*cc == OP_ALT && ket != OP_KETRMIN))    else if (ket == OP_KETRMAX || (*cc == OP_ALT && ket != OP_KETRMIN))
7041      {      {
# Line 6436  else if (opcode == OP_ONCE) Line 7045  else if (opcode == OP_ONCE)
7045    
7046    JUMPHERE(once);    JUMPHERE(once);
7047    /* Restore previous localptr */    /* Restore previous localptr */
7048    if (CURRENT_AS(bracket_fallback)->u.framesize >= 0)    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
7049      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(bracket_fallback)->u.framesize * sizeof(sljit_w));      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), localptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(bracket_backtrack)->u.framesize * sizeof(sljit_w));
7050    else if (ket == OP_KETRMIN)    else if (ket == OP_KETRMIN)
7051      {      {
7052      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
# Line 6450  else if (opcode == OP_ONCE) Line 7059  else if (opcode == OP_ONCE)
7059  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
7060    {    {
7061    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7062    CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(bracket_fallback)->recursivehotpath);    if (bra != OP_BRAZERO)
7063        free_stack(common, 1);
7064      CMPTO(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, 0, CURRENT_AS(bracket_backtrack)->recursivetrypath);
7065    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
7066      {      {
7067      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(1));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
7068      JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_fallback)->zerohotpath);      JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->zerotrypath);
7069      JUMPHERE(brazero);      JUMPHERE(brazero);
7070        free_stack(common, 1);
7071      }      }
   free_stack(common, 1);  
7072    }    }
7073  else if (ket == OP_KETRMIN)  else if (ket == OP_KETRMIN)
7074    {    {
7075    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7076    
7077    /* OP_ONCE removes everything in case of a fallback, so we don't    /* OP_ONCE removes everything in case of a backtrack, so we don't
7078    need to explicitly release the STR_PTR. The extra release would    need to explicitly release the STR_PTR. The extra release would
7079    affect badly the free_stack(2) above. */    affect badly the free_stack(2) above. */
7080    if (opcode != OP_ONCE)    if (opcode != OP_ONCE)
# Line 6477  else if (ket == OP_KETRMIN) Line 7088  else if (ket == OP_KETRMIN)
7088  else if (bra == OP_BRAZERO)  else if (bra == OP_BRAZERO)
7089    {    {
7090    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));    OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7091    JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_fallback)->zerohotpath);    JUMPTO(SLJIT_JUMP, CURRENT_AS(bracket_backtrack)->zerotrypath);
7092    JUMPHERE(brazero);    JUMPHERE(brazero);
7093    }    }
7094  }  }
7095    
7096  static void compile_bracketpos_fallbackpath(compiler_common *common, struct fallback_common *current)  static void compile_bracketpos_backtrackpath(compiler_common *common, struct backtrack_common *current)
7097  {  {
7098  DEFINE_COMPILER;  DEFINE_COMPILER;
7099  int offset;  int offset;
7100  struct sljit_jump *jump;  struct sljit_jump *jump;
7101    
7102  if (CURRENT_AS(bracketpos_fallback)->framesize < 0)  if (CURRENT_AS(bracketpos_backtrack)->framesize < 0)
7103    {    {
7104    if (*current->cc == OP_CBRAPOS || *current->cc == OP_SCBRAPOS)    if (*current->cc == OP_CBRAPOS || *current->cc == OP_SCBRAPOS)
7105      {      {
# Line 6498  if (CURRENT_AS(bracketpos_fallback)->fra Line 7109  if (CURRENT_AS(bracketpos_fallback)->fra
7109      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
7110      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), TMP2, 0);
7111      }      }
7112    set_jumps(current->topfallbacks, LABEL());    set_jumps(current->topbacktracks, LABEL());
7113    free_stack(common, CURRENT_AS(bracketpos_fallback)->stacksize);    free_stack(common, CURRENT_AS(bracketpos_backtrack)->stacksize);
7114    return;    return;
7115    }    }
7116    
7117  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(bracketpos_fallback)->localptr);  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(bracketpos_backtrack)->localptr);
7118  add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));  add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
7119    
7120  if (current->topfallbacks)  if (current->topbacktracks)
7121    {    {
7122    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
7123    set_jumps(current->topfallbacks, LABEL());    set_jumps(current->topbacktracks, LABEL());
7124    /* Drop the stack frame. */    /* Drop the stack frame. */
7125    free_stack(common, CURRENT_AS(bracketpos_fallback)->stacksize);    free_stack(common, CURRENT_AS(bracketpos_backtrack)->stacksize);
7126    JUMPHERE(jump);    JUMPHERE(jump);
7127    }    }
7128  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(bracketpos_fallback)->localptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(bracketpos_fallback)->framesize * sizeof(sljit_w));  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(bracketpos_backtrack)->localptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(bracketpos_backtrack)->framesize * sizeof(sljit_w));
7129  }  }
7130    
7131  static void compile_braminzero_fallbackpath(compiler_common *common, struct fallback_common *current)  static void compile_braminzero_backtrackpath(compiler_common *common, struct backtrack_common *current)
7132  {  {
7133  assert_fallback fallback;  assert_backtrack backtrack;
7134    
7135  current->top = NULL;  current->top = NULL;
7136  current->topfallbacks = NULL;  current->topbacktracks = NULL;
7137  current->nextfallbacks = NULL;  current->nextbacktracks = NULL;
7138  if (current->cc[1] > OP_ASSERTBACK_NOT)  if (current->cc[1] > OP_ASSERTBACK_NOT)
7139    {    {
7140    /* Manual call of compile_bracket_hotpath and compile_bracket_fallbackpath. */    /* Manual call of compile_bracket_trypath and compile_bracket_backtrackpath. */
7141    compile_bracket_hotpath(common, current->cc, current);    compile_bracket_trypath(common, current->cc, current);
7142    compile_bracket_fallbackpath(common, current->top);    compile_bracket_backtrackpath(common, current->top);
7143    }    }
7144  else  else
7145    {    {
7146    memset(&fallback, 0, sizeof(fallback));    memset(&backtrack, 0, sizeof(backtrack));
7147    fallback.common.cc = current->cc;    backtrack.common.cc = current->cc;
7148    fallback.hotpath = CURRENT_AS(braminzero_fallback)->hotpath;    backtrack.trypath = CURRENT_AS(braminzero_backtrack)->trypath;
7149    /* Manual call of compile_assert_hotpath. */    /* Manual call of compile_assert_trypath. */
7150    compile_assert_hotpath(common, current->cc, &fallback, FALSE);    compile_assert_trypath(common, current->cc, &backtrack, FALSE);
7151    }    }
7152  SLJIT_ASSERT(!current->nextfallbacks && !current->topfallbacks);  SLJIT_ASSERT(!current->nextbacktracks && !current->topbacktracks);
7153  }  }
7154    
7155  static void compile_fallbackpath(compiler_common *common, struct fallback_common *current)  static void compile_backtrackpath(compiler_common *common, struct backtrack_common *current)
7156  {  {
7157  DEFINE_COMPILER;  DEFINE_COMPILER;
7158    
7159  while (current)  while (current)
7160    {    {
7161    if (current->nextfallbacks != NULL)    if (current->nextbacktracks != NULL)
7162      set_jumps(current->nextfallbacks, LABEL());      set_jumps(current->nextbacktracks, LABEL());
7163    switch(*current->cc)    switch(*current->cc)
7164      {      {
7165      case OP_SET_SOM:      case OP_SET_SOM:
# Line 6627  while (current) Line 7238  while (current)
7238  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
7239      case OP_XCLASS:      case OP_XCLASS:
7240  #endif  #endif
7241      compile_iterator_fallbackpath(common, current);      compile_iterator_backtrackpath(common, current);
7242      break;      break;
7243    
7244      case OP_REF:      case OP_REF:
7245      case OP_REFI:      case OP_REFI:
7246      compile_ref_iterator_fallbackpath(common, current);      compile_ref_iterator_backtrackpath(common, current);
7247      break;      break;
7248    
7249      case OP_RECURSE:      case OP_RECURSE:
7250      compile_recurse_fallbackpath(common, current);      compile_recurse_backtrackpath(common, current);
7251      break;      break;
7252    
7253      case OP_ASSERT:      case OP_ASSERT:
7254      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
7255      case OP_ASSERTBACK:      case OP_ASSERTBACK:
7256      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
7257      compile_assert_fallbackpath(common, current);      compile_assert_backtrackpath(common, current);
7258      break;      break;
7259    
7260      case OP_ONCE:      case OP_ONCE:
# Line 6654  while (current) Line 7265  while (current)
7265      case OP_SBRA:      case OP_SBRA:
7266      case OP_SCBRA:      case OP_SCBRA:
7267      case OP_SCOND:      case OP_SCOND:
7268      compile_bracket_fallbackpath(common, current);      compile_bracket_backtrackpath(common, current);
7269      break;      break;
7270    
7271      case OP_BRAZERO:      case OP_BRAZERO:
7272      if (current->cc[1] > OP_ASSERTBACK_NOT)      if (current->cc[1] > OP_ASSERTBACK_NOT)
7273        compile_bracket_fallbackpath(common, current);        compile_bracket_backtrackpath(common, current);
7274      else      else
7275        compile_assert_fallbackpath(common, current);        compile_assert_backtrackpath(common, current);
7276      break;      break;
7277    
7278      case OP_BRAPOS:      case OP_BRAPOS:
# Line 6669  while (current) Line 7280  while (current)
7280      case OP_SBRAPOS:      case OP_SBRAPOS:
7281      case OP_SCBRAPOS:      case OP_SCBRAPOS:
7282      case OP_BRAPOSZERO:      case OP_BRAPOSZERO:
7283      compile_bracketpos_fallbackpath(common, current);      compile_bracketpos_backtrackpath(common, current);
7284      break;      break;
7285    
7286      case OP_BRAMINZERO:      case OP_BRAMINZERO:
7287      compile_braminzero_fallbackpath(common, current);      compile_braminzero_backtrackpath(common, current);
7288      break;      break;
7289    
7290      case OP_MARK:      case OP_MARK:
# Line 6693  while (current) Line 7304  while (current)
7304      case OP_FAIL:      case OP_FAIL:
7305      case OP_ACCEPT:      case OP_ACCEPT:
7306      case OP_ASSERT_ACCEPT:      case OP_ASSERT_ACCEPT:
7307      set_jumps(current->topfallbacks, LABEL());      set_jumps(current->topbacktracks, LABEL());
7308      break;      break;
7309    
7310      default:      default:
# Line 6714  int localsize = get_localsize(common, cc Line 7325  int localsize = get_localsize(common, cc
7325  int framesize = get_framesize(common, cc, TRUE);  int framesize = get_framesize(common, cc, TRUE);
7326  int alternativesize;  int alternativesize;
7327  BOOL needsframe;  BOOL needsframe;
7328  fallback_common altfallback;  backtrack_common altbacktrack;
7329  struct sljit_label *save_leavelabel = common->leavelabel;  struct sljit_label *save_leavelabel = common->leavelabel;
7330  jump_list *save_leave = common->leave;  jump_list *save_leave = common->leave;
7331  struct sljit_jump *jump;  struct sljit_jump *jump;
# Line 6740  if (needsframe) Line 7351  if (needsframe)
7351  if (alternativesize > 0)  if (alternativesize > 0)
7352    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
7353    
7354  memset(&altfallback, 0, sizeof(fallback_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
7355  common->leavelabel = NULL;  common->leavelabel = NULL;
7356  common->acceptlabel = NULL;  common->acceptlabel = NULL;
7357  common->leave = NULL;  common->leave = NULL;
7358  common->accept = NULL;  common->accept = NULL;
7359  altfallback.cc = ccbegin;  altbacktrack.cc = ccbegin;
7360  cc += GET(cc, 1);  cc += GET(cc, 1);
7361  while (1)  while (1)
7362    {    {
7363    altfallback.top = NULL;    altbacktrack.top = NULL;
7364    altfallback.topfallbacks = NULL;    altbacktrack.topbacktracks = NULL;
7365    
7366    if (altfallback.cc != ccbegin)    if (altbacktrack.cc != ccbegin)
7367      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
7368    
7369    compile_hotpath(common, altfallback.cc, cc, &altfallback);    compile_trypath(common, altbacktrack.cc, cc, &altbacktrack);
7370    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
7371      {      {
7372      common->leavelabel = save_leavelabel;      common->leavelabel = save_leavelabel;
# Line 6765  while (1) Line 7376  while (1)
7376    
7377    add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP));    add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP));
7378    
7379    compile_fallbackpath(common, altfallback.top);    compile_backtrackpath(common, altbacktrack.top);
7380    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
7381      {      {
7382      common->leavelabel = save_leavelabel;      common->leavelabel = save_leavelabel;
7383      common->leave = save_leave;      common->leave = save_leave;
7384      return;      return;
7385      }      }
7386    set_jumps(altfallback.topfallbacks, LABEL());    set_jumps(altbacktrack.topbacktracks, LABEL());
7387    
7388    if (*cc != OP_ALT)    if (*cc != OP_ALT)
7389      break;      break;
7390    
7391    altfallback.cc = cc + 1 + LINK_SIZE;    altbacktrack.cc = cc + 1 + LINK_SIZE;
7392    cc += GET(cc, 1);    cc += GET(cc, 1);
7393    }    }
7394  /* None of them matched. */  /* None of them matched. */
# Line 6809  common->leavelabel = save_leavelabel; Line 7420  common->leavelabel = save_leavelabel;
7420  common->leave = save_leave;  common->leave = save_leave;
7421  }  }
7422    
7423  #undef COMPILE_FALLBACKPATH  #undef COMPILE_BACKTRACKPATH
7424  #undef CURRENT_AS  #undef CURRENT_AS
7425    
7426  void  void
7427  PRIV(jit_compile)(const REAL_PCRE *re, PUBL(extra) *extra, int mode)  PRIV(jit_compile)(const REAL_PCRE *re, PUBL(extra) *extra, int mode)
7428  {  {
7429  struct sljit_compiler *compiler;  struct sljit_compiler *compiler;
7430  fallback_common rootfallback;  backtrack_common rootbacktrack;
7431  compiler_common common_data;  compiler_common common_data;
7432  compiler_common *common = &common_data;  compiler_common *common = &common_data;
7433  const pcre_uint8 *tables = re->tables;  const pcre_uint8 *tables = re->tables;
# Line 6828  void *executable_func; Line 7439  void *executable_func;
7439  sljit_uw executable_size;  sljit_uw executable_size;
7440  struct sljit_label *mainloop = NULL;  struct sljit_label *mainloop = NULL;
7441  struct sljit_label *empty_match_found;  struct sljit_label *empty_match_found;
7442  struct sljit_label *empty_match_fallback;  struct sljit_label *empty_match_backtrack;
7443  struct sljit_jump *jump;  struct sljit_jump *jump;
7444  struct sljit_jump *reqbyte_notfound = NULL;  struct sljit_jump *reqbyte_notfound = NULL;
7445  struct sljit_jump *empty_match;  struct sljit_jump *empty_match;
# Line 6839  study = extra->study_data; Line 7450  study = extra->study_data;
7450  if (!tables)  if (!tables)
7451    tables = PRIV(default_tables);    tables = PRIV(default_tables);
7452    
7453  memset(&rootfallback, 0, sizeof(fallback_common));  memset(&rootbacktrack, 0, sizeof(backtrack_common));
7454  memset(common, 0, sizeof(compiler_common));  memset(common, 0, sizeof(compiler_common));
7455  rootfallback.cc = (pcre_uchar *)re + re->name_table_offset + re->name_count * re->name_entry_size;  rootbacktrack.cc = (pcre_uchar *)re + re->name_table_offset + re->name_count * re->name_entry_size;
7456    
7457  common->start = rootfallback.cc;  common->start = rootbacktrack.cc;
7458  common->fcc = tables + fcc_offset;  common->fcc = tables + fcc_offset;
7459  common->lcc = (sljit_w)(tables + lcc_offset);  common->lcc = (sljit_w)(tables + lcc_offset);
7460  common->mode = mode;  common->mode = mode;
# Line 6852  switch(re->options & PCRE_NEWLINE_BITS) Line 7463  switch(re->options & PCRE_NEWLINE_BITS)
7463    {    {
7464    case 0:    case 0:
7465    /* Compile-time default */    /* Compile-time default */
7466    switch (NEWLINE)    switch(NEWLINE)
7467      {      {
7468      case -1: common->newline = (CHAR_CR << 8) | CHAR_NL; common->nltype = NLTYPE_ANY; break;      case -1: common->newline = (CHAR_CR << 8) | CHAR_NL; common->nltype = NLTYPE_ANY; break;
7469      case -2: common->newline = (CHAR_CR << 8) | CHAR_NL; common->nltype = NLTYPE_ANYCRLF; break;      case -2: common->newline = (CHAR_CR << 8) | CHAR_NL; common->nltype = NLTYPE_ANYCRLF; break;
# Line 6892  common->utf = (re->options & PCRE_UTF8) Line 7503  common->utf = (re->options & PCRE_UTF8)
7503  common->use_ucp = (re->options & PCRE_UCP) != 0;  common->use_ucp = (re->options & PCRE_UCP) != 0;
7504  #endif  #endif
7505  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
7506  ccend = bracketend(rootfallback.cc);  ccend = bracketend(rootbacktrack.cc);
7507    
7508  /* Calculate the local space size on the stack. */  /* Calculate the local space size on the stack. */
7509  common->ovector_start = CALL_LIMIT + sizeof(sljit_w);  common->ovector_start = CALL_LIMIT + sizeof(sljit_w);
7510    
7511  SLJIT_ASSERT(*rootfallback.cc == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);  SLJIT_ASSERT(*rootbacktrack.cc == OP_BRA && ccend[-(1 + LINK_SIZE)] == OP_KET);
7512  localsize = get_localspace(common, rootfallback.cc, ccend);  localsize = get_localspace(common, rootbacktrack.cc, ccend);
7513  if (localsize < 0)  if (localsize < 0)
7514    return;    return;
7515    
# Line 6933  common->cbraptr = OVECTOR_START + (re->t Line 7544  common->cbraptr = OVECTOR_START + (re->t
7544  localsize += common->cbraptr + (re->top_bracket + 1) * sizeof(sljit_w);  localsize += common->cbraptr + (re->top_bracket + 1) * sizeof(sljit_w);
7545  if (localsize > SLJIT_MAX_LOCAL_SIZE)  if (localsize > SLJIT_MAX_LOCAL_SIZE)
7546    return;    return;
7547  common->localptrs = (int *)SLJIT_MALLOC((ccend - rootfallback.cc) * sizeof(int));  common->localptrs = (int *)SLJIT_MALLOC((ccend - rootbacktrack.cc) * sizeof(int));
7548  if (!common->localptrs)  if (!common->localptrs)
7549    return;    return;
7550  memset(common->localptrs, 0, (ccend - rootfallback.cc) * sizeof(int));  memset(common->localptrs, 0, (ccend - rootbacktrack.cc) * sizeof(int));