/[pcre]/code/tags/pcre-8.37/pcre_jit_compile.c
ViewVC logotype

Diff of /code/tags/pcre-8.37/pcre_jit_compile.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1275 by zherczeg, Sun Mar 10 05:32:10 2013 UTC revision 1300 by zherczeg, Mon Mar 25 12:34:26 2013 UTC
# Line 202  enum frame_types { Line 202  enum frame_types {
202  };  };
203    
204  enum control_types {  enum control_types {
205    type_commit = 0,    type_mark = 0,
206    type_prune = 1,    type_then_trap = 1
   type_skip = 2  
207  };  };
208    
209  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);  typedef int (SLJIT_CALL *jit_function)(jit_arguments *args);
# Line 227  typedef struct backtrack_common { Line 226  typedef struct backtrack_common {
226  typedef struct assert_backtrack {  typedef struct assert_backtrack {
227    backtrack_common common;    backtrack_common common;
228    jump_list *condfailed;    jump_list *condfailed;
229    /* Less than 0 (-1) if a frame is not needed. */    /* Less than 0 if a frame is not needed. */
230    int framesize;    int framesize;
231    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
232    int private_data_ptr;    int private_data_ptr;
# Line 248  typedef struct bracket_backtrack { Line 247  typedef struct bracket_backtrack {
247      /* Both for OP_COND, OP_SCOND. */      /* Both for OP_COND, OP_SCOND. */
248      jump_list *condfailed;      jump_list *condfailed;
249      assert_backtrack *assert;      assert_backtrack *assert;
250      /* For OP_ONCE. -1 if not needed. */      /* For OP_ONCE. Less than 0 if not needed. */
251      int framesize;      int framesize;
252    } u;    } u;
253    /* Points to our private memory word on the stack. */    /* Points to our private memory word on the stack. */
# Line 283  typedef struct recurse_entry { Line 282  typedef struct recurse_entry {
282    /* Collects the calls until the function is not created. */    /* Collects the calls until the function is not created. */
283    jump_list *calls;    jump_list *calls;
284    /* Points to the starting opcode. */    /* Points to the starting opcode. */
285    int start;    sljit_sw start;
286  } recurse_entry;  } recurse_entry;
287    
288  typedef struct recurse_backtrack {  typedef struct recurse_backtrack {
# Line 291  typedef struct recurse_backtrack { Line 290  typedef struct recurse_backtrack {
290    BOOL inlined_pattern;    BOOL inlined_pattern;
291  } recurse_backtrack;  } recurse_backtrack;
292    
293    #define OP_THEN_TRAP OP_TABLE_LENGTH
294    
295    typedef struct then_trap_backtrack {
296      backtrack_common common;
297      /* If then_trap is not NULL, this structure contains the real
298      then_trap for the backtracking path. */
299      struct then_trap_backtrack *then_trap;
300      /* Points to the starting opcode. */
301      sljit_sw start;
302      /* Exit point for the then opcodes of this alternative. */
303      jump_list *quit;
304      /* Frame size of the current alternative. */
305      int framesize;
306    } then_trap_backtrack;
307    
308  #define MAX_RANGE_SIZE 6  #define MAX_RANGE_SIZE 6
309    
310  typedef struct compiler_common {  typedef struct compiler_common {
# Line 302  typedef struct compiler_common { Line 316  typedef struct compiler_common {
316    int *private_data_ptrs;    int *private_data_ptrs;
317    /* Tells whether the capturing bracket is optimized. */    /* Tells whether the capturing bracket is optimized. */
318    pcre_uint8 *optimized_cbracket;    pcre_uint8 *optimized_cbracket;
319      /* Tells whether the starting offset is a target of then. */
320      pcre_uint8 *then_offsets;
321      /* Current position where a THEN must jump. */
322      then_trap_backtrack *then_trap;
323    /* Starting offset of private data for capturing brackets. */    /* Starting offset of private data for capturing brackets. */
324    int cbra_ptr;    int cbra_ptr;
325    /* Output vector starting point. Must be divisible by 2. */    /* Output vector starting point. Must be divisible by 2. */
# Line 330  typedef struct compiler_common { Line 348  typedef struct compiler_common {
348    sljit_sw lcc;    sljit_sw lcc;
349    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */    /* Mode can be PCRE_STUDY_JIT_COMPILE and others. */
350    int mode;    int mode;
351    /* \K is in the pattern. */    /* \K is found in the pattern. */
352    BOOL has_set_som;    BOOL has_set_som;
353      /* (*SKIP:arg) is found in the pattern. */
354      BOOL has_skip_arg;
355      /* (*THEN) is found in the pattern. */
356      BOOL has_then;
357    /* Needs to know the start position anytime. */    /* Needs to know the start position anytime. */
358    BOOL needs_start_ptr;    BOOL needs_start_ptr;
359    /* Currently in recurse or assert. */    /* Currently in recurse. */
360    BOOL local_exit;    BOOL local_exit;
361      /* Currently in assert. */
362      int then_local_exit;
363    /* Newline control. */    /* Newline control. */
364    int nltype;    int nltype;
365    int newline;    int newline;
# Line 360  typedef struct compiler_common { Line 384  typedef struct compiler_common {
384    recurse_entry *currententry;    recurse_entry *currententry;
385    jump_list *partialmatch;    jump_list *partialmatch;
386    jump_list *quit;    jump_list *quit;
387      jump_list *then_quit;
388    jump_list *forced_quit;    jump_list *forced_quit;
389    jump_list *accept;    jump_list *accept;
390    jump_list *calllimit;    jump_list *calllimit;
# Line 513  return cc; Line 538  return cc;
538   set_private_data_ptrs   set_private_data_ptrs
539   get_framesize   get_framesize
540   init_frame   init_frame
541   get_private_data_length_for_copy   get_private_data_copy_length
542   copy_private_data   copy_private_data
543   compile_matchingpath   compile_matchingpath
544   compile_backtrackingpath   compile_backtrackingpath
# Line 597  switch(*cc) Line 622  switch(*cc)
622    case OP_BRAPOSZERO:    case OP_BRAPOSZERO:
623    case OP_PRUNE:    case OP_PRUNE:
624    case OP_SKIP:    case OP_SKIP:
625      case OP_THEN:
626    case OP_COMMIT:    case OP_COMMIT:
627    case OP_FAIL:    case OP_FAIL:
628    case OP_ACCEPT:    case OP_ACCEPT:
# Line 696  switch(*cc) Line 722  switch(*cc)
722    
723    case OP_MARK:    case OP_MARK:
724    case OP_PRUNE_ARG:    case OP_PRUNE_ARG:
725      case OP_SKIP_ARG:
726      case OP_THEN_ARG:
727    return cc + 1 + 2 + cc[1];    return cc + 1 + 2 + cc[1];
728    
729    default:    default:
730      /* All opcodes are supported now! */
731      SLJIT_ASSERT_STOP();
732    return NULL;    return NULL;
733    }    }
734  }  }
# Line 947  while (cc < ccend) Line 977  while (cc < ccend)
977      cc += 2 + 2 * LINK_SIZE;      cc += 2 + 2 * LINK_SIZE;
978      break;      break;
979    
980        case OP_THEN_ARG:
981        common->has_then = TRUE;
982        common->control_head_ptr = 1;
983        /* Fall through. */
984    
985      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
986      common->needs_start_ptr = TRUE;      common->needs_start_ptr = TRUE;
     common->control_head_ptr = 1;  
987      /* Fall through. */      /* Fall through. */
988    
989      case OP_MARK:      case OP_MARK:
# Line 961  while (cc < ccend) Line 995  while (cc < ccend)
995      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
996      break;      break;
997    
998        case OP_THEN:
999        common->has_then = TRUE;
1000        common->control_head_ptr = 1;
1001        /* Fall through. */
1002    
1003      case OP_PRUNE:      case OP_PRUNE:
1004      case OP_SKIP:      case OP_SKIP:
1005      common->needs_start_ptr = TRUE;      common->needs_start_ptr = TRUE;
1006      /* Fall through. */      cc += 1;
1007        break;
1008    
1009      case OP_COMMIT:      case OP_SKIP_ARG:
1010      common->control_head_ptr = 1;      common->control_head_ptr = 1;
1011      cc += 1;      common->has_skip_arg = TRUE;
1012        cc += 1 + 2 + cc[1];
1013      break;      break;
1014    
1015      default:      default:
# Line 1148  while (cc < ccend) Line 1189  while (cc < ccend)
1189  }  }
1190    
1191  /* Returns with a frame_types (always < 0) if no need for frame. */  /* Returns with a frame_types (always < 0) if no need for frame. */
1192  static int get_framesize(compiler_common *common, pcre_uchar *cc, BOOL recursive)  static int get_framesize(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL recursive, BOOL* needs_control_head)
1193  {  {
 pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);  
1194  int length = 0;  int length = 0;
1195  int possessive = 0;  int possessive = 0;
1196  BOOL stack_restore = FALSE;  BOOL stack_restore = FALSE;
# Line 1159  BOOL setmark_found = recursive; Line 1199  BOOL setmark_found = recursive;
1199  /* The last capture is a local variable even for recursions. */  /* The last capture is a local variable even for recursions. */
1200  BOOL capture_last_found = FALSE;  BOOL capture_last_found = FALSE;
1201    
1202  if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))  #if defined DEBUG_FORCE_CONTROL_HEAD && DEBUG_FORCE_CONTROL_HEAD
1203    SLJIT_ASSERT(common->control_head_ptr != 0);
1204    *needs_control_head = TRUE;
1205    #else
1206    *needs_control_head = FALSE;
1207    #endif
1208    
1209    if (ccend == NULL)
1210    {    {
1211    possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;    ccend = bracketend(cc) - (1 + LINK_SIZE);
1212    /* This is correct regardless of common->capture_last_ptr. */    if (!recursive && (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS))
1213    capture_last_found = TRUE;      {
1214        possessive = length = (common->capture_last_ptr != 0) ? 5 : 3;
1215        /* This is correct regardless of common->capture_last_ptr. */
1216        capture_last_found = TRUE;
1217        }
1218      cc = next_opcode(common, cc);
1219    }    }
1220    
 cc = next_opcode(common, cc);  
1221  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1222  while (cc < ccend)  while (cc < ccend)
1223    switch(*cc)    switch(*cc)
# Line 1184  while (cc < ccend) Line 1235  while (cc < ccend)
1235    
1236      case OP_MARK:      case OP_MARK:
1237      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
1238        case OP_THEN_ARG:
1239      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1240      stack_restore = TRUE;      stack_restore = TRUE;
1241      if (!setmark_found)      if (!setmark_found)
# Line 1191  while (cc < ccend) Line 1243  while (cc < ccend)
1243        length += 2;        length += 2;
1244        setmark_found = TRUE;        setmark_found = TRUE;
1245        }        }
1246        if (common->control_head_ptr != 0)
1247          *needs_control_head = TRUE;
1248      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
1249      break;      break;
1250    
# Line 1310  if (length > 0) Line 1364  if (length > 0)
1364  return stack_restore ? no_frame : no_stack;  return stack_restore ? no_frame : no_stack;
1365  }  }
1366    
1367  static void init_frame(compiler_common *common, pcre_uchar *cc, int stackpos, int stacktop, BOOL recursive)  static void init_frame(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, int stackpos, int stacktop, BOOL recursive)
1368  {  {
1369  DEFINE_COMPILER;  DEFINE_COMPILER;
 pcre_uchar *ccend = bracketend(cc) - (1 + LINK_SIZE);  
1370  BOOL setsom_found = recursive;  BOOL setsom_found = recursive;
1371  BOOL setmark_found = recursive;  BOOL setmark_found = recursive;
1372  /* The last capture is a local variable even for recursions. */  /* The last capture is a local variable even for recursions. */
# Line 1325  SLJIT_UNUSED_ARG(stacktop); Line 1378  SLJIT_UNUSED_ARG(stacktop);
1378  SLJIT_ASSERT(stackpos >= stacktop + 2);  SLJIT_ASSERT(stackpos >= stacktop + 2);
1379    
1380  stackpos = STACK(stackpos);  stackpos = STACK(stackpos);
1381  if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))  if (ccend == NULL)
1382    cc = next_opcode(common, cc);    {
1383      ccend = bracketend(cc) - (1 + LINK_SIZE);
1384      if (recursive || (*cc != OP_CBRAPOS && *cc != OP_SCBRAPOS))
1385        cc = next_opcode(common, cc);
1386      }
1387    
1388  SLJIT_ASSERT(cc != NULL);  SLJIT_ASSERT(cc != NULL);
1389  while (cc < ccend)  while (cc < ccend)
1390    switch(*cc)    switch(*cc)
# Line 1347  while (cc < ccend) Line 1405  while (cc < ccend)
1405    
1406      case OP_MARK:      case OP_MARK:
1407      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
1408        case OP_THEN_ARG:
1409      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
1410      if (!setmark_found)      if (!setmark_found)
1411        {        {
# Line 1427  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), st Line 1486  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), st
1486  SLJIT_ASSERT(stackpos == STACK(stacktop));  SLJIT_ASSERT(stackpos == STACK(stacktop));
1487  }  }
1488    
1489  static SLJIT_INLINE int get_private_data_length_for_copy(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static SLJIT_INLINE int get_private_data_copy_length(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, BOOL needs_control_head)
1490  {  {
1491  int private_data_length = common->control_head_ptr ? 3 : 2;  int private_data_length = needs_control_head ? 3 : 2;
1492  int size;  int size;
1493  pcre_uchar *alternative;  pcre_uchar *alternative;
1494  /* Calculate the sum of the private machine words. */  /* Calculate the sum of the private machine words. */
# Line 1542  return private_data_length; Line 1601  return private_data_length;
1601  }  }
1602    
1603  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,  static void copy_private_data(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend,
1604    BOOL save, int stackptr, int stacktop)    BOOL save, int stackptr, int stacktop, BOOL needs_control_head)
1605  {  {
1606  DEFINE_COMPILER;  DEFINE_COMPILER;
1607  int srcw[2];  int srcw[2];
# Line 1563  stacktop = STACK(stacktop - 1); Line 1622  stacktop = STACK(stacktop - 1);
1622    
1623  if (!save)  if (!save)
1624    {    {
1625    stackptr += (common->control_head_ptr ? 2 : 1) * sizeof(sljit_sw);    stackptr += (needs_control_head ? 2 : 1) * sizeof(sljit_sw);
1626    if (stackptr < stacktop)    if (stackptr < stacktop)
1627      {      {
1628      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), stackptr);
# Line 1588  do Line 1647  do
1647      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);      SLJIT_ASSERT(save && common->recursive_head_ptr != 0);
1648      count = 1;      count = 1;
1649      srcw[0] = common->recursive_head_ptr;      srcw[0] = common->recursive_head_ptr;
1650      if (common->control_head_ptr != 0)      if (needs_control_head)
1651        {        {
1652          SLJIT_ASSERT(common->control_head_ptr != 0);
1653        count = 2;        count = 2;
1654        srcw[1] = common->control_head_ptr;        srcw[1] = common->control_head_ptr;
1655        }        }
# Line 1851  if (save) Line 1911  if (save)
1911  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));  SLJIT_ASSERT(cc == ccend && stackptr == stacktop && (save || (tmp1empty && tmp2empty)));
1912  }  }
1913    
1914    static SLJIT_INLINE pcre_uchar *set_then_offsets(compiler_common *common, pcre_uchar *cc, pcre_uint8 *current_offset)
1915    {
1916    pcre_uchar *end = bracketend(cc);
1917    BOOL has_alternatives = cc[GET(cc, 1)] == OP_ALT;
1918    
1919    /* Assert captures then. */
1920    if (*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT)
1921      current_offset = NULL;
1922    /* Conditional block does not. */
1923    if (*cc == OP_COND || *cc == OP_SCOND)
1924      has_alternatives = FALSE;
1925    
1926    cc = next_opcode(common, cc);
1927    if (has_alternatives)
1928      current_offset = common->then_offsets + (cc - common->start);
1929    
1930    while (cc < end)
1931      {
1932      if ((*cc >= OP_ASSERT && *cc <= OP_ASSERTBACK_NOT) || (*cc >= OP_ONCE && *cc <= OP_SCOND))
1933        cc = set_then_offsets(common, cc, current_offset);
1934      else
1935        {
1936        if (*cc == OP_ALT && has_alternatives)
1937          current_offset = common->then_offsets + (cc + 1 + LINK_SIZE - common->start);
1938        if (*cc >= OP_THEN && *cc <= OP_THEN_ARG && current_offset != NULL)
1939          *current_offset = 1;
1940        cc = next_opcode(common, cc);
1941        }
1942      }
1943    
1944    return end;
1945    }
1946    
1947  #undef CASE_ITERATOR_PRIVATE_DATA_1  #undef CASE_ITERATOR_PRIVATE_DATA_1
1948  #undef CASE_ITERATOR_PRIVATE_DATA_2A  #undef CASE_ITERATOR_PRIVATE_DATA_2A
1949  #undef CASE_ITERATOR_PRIVATE_DATA_2B  #undef CASE_ITERATOR_PRIVATE_DATA_2B
# Line 1998  else Line 2091  else
2091  OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);  OP1(SLJIT_MOV, STACK_TOP, 0, ARGUMENTS, 0);
2092  if (common->mark_ptr != 0)  if (common->mark_ptr != 0)
2093    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, SLJIT_IMM, 0);
2094  SLJIT_ASSERT(common->control_head_ptr != 0);  if (common->control_head_ptr != 0)
2095  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
2096  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(jit_arguments, stack));
2097  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->start_ptr);
2098  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), SLJIT_OFFSETOF(struct sljit_stack, base));
2099  }  }
2100    
2101  static sljit_sw do_check_control_chain(sljit_sw *current)  static sljit_sw SLJIT_CALL do_search_mark(sljit_sw *current, const pcre_uchar *skip_arg)
2102  {  {
2103  sljit_sw return_value = 0;  while (current != NULL)
   
 SLJIT_ASSERT(current != NULL);  
 do  
2104    {    {
2105    switch (current[-2])    switch (current[-2])
2106      {      {
2107      case type_commit:      case type_then_trap:
     /* Commit overwrites all. */  
     return -1;  
   
     case type_prune:  
2108      break;      break;
2109    
2110      case type_skip:      case type_mark:
2111      /* Overwrites prune, but not other skips. */      if (STRCMP_UC_UC(skip_arg, (pcre_uchar *)current[-3]) == 0)
2112      if (return_value == 0)        return current[-4];
       return_value = current[-3];  
2113      break;      break;
2114    
2115      default:      default:
# Line 2033  do Line 2118  do
2118      }      }
2119    current = (sljit_sw*)current[-1];    current = (sljit_sw*)current[-1];
2120    }    }
2121  while (current != NULL);  return -1;
 return return_value;  
2122  }  }
2123    
2124  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)  static SLJIT_INLINE void copy_ovector(compiler_common *common, int topbracket)
# Line 2106  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJI Line 2190  OP1(SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJI
2190  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));  OP1(SLJIT_MOV, SLJIT_SCRATCH_REG2, 0, SLJIT_MEM1(SLJIT_SCRATCH_REG2), SLJIT_OFFSETOF(jit_arguments, offsets));
2191    
2192  jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);  jump = CMP(SLJIT_C_SIG_LESS, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, 3);
2193  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + sizeof(sljit_sw)), SLJIT_SAVED_REG1, 0);  OP2(SLJIT_SUB, SLJIT_SCRATCH_REG3, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mode == JIT_PARTIAL_HARD_COMPILE ? common->start_ptr : (common->hit_start + (int)sizeof(sljit_sw)), SLJIT_SAVED_REG1, 0);
2194  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32  #if defined COMPILE_PCRE16 || defined COMPILE_PCRE32
2195  OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);  OP2(SLJIT_ASHR, SLJIT_SCRATCH_REG3, 0, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, UCHAR_SHIFT);
2196  #endif  #endif
# Line 5242  DEFINE_COMPILER; Line 5326  DEFINE_COMPILER;
5326  backtrack_common *backtrack;  backtrack_common *backtrack;
5327  recurse_entry *entry = common->entries;  recurse_entry *entry = common->entries;
5328  recurse_entry *prev = NULL;  recurse_entry *prev = NULL;
5329  int start = GET(cc, 1);  sljit_sw start = GET(cc, 1);
5330  pcre_uchar *start_cc;  pcre_uchar *start_cc;
5331    BOOL needs_control_head;
5332    
5333  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);  PUSH_BACKTRACK(sizeof(recurse_backtrack), cc, NULL);
5334    
5335  /* Inlining simple patterns. */  /* Inlining simple patterns. */
5336  if (get_framesize(common, common->start + start, TRUE) == no_stack)  if (get_framesize(common, common->start + start, NULL, TRUE, &needs_control_head) == no_stack)
5337    {    {
5338    start_cc = common->start + start;    start_cc = common->start + start;
5339    compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);    compile_matchingpath(common, next_opcode(common, start_cc), bracketend(start_cc) - (1 + LINK_SIZE), backtrack);
# Line 5408  static pcre_uchar *compile_assert_matchi Line 5493  static pcre_uchar *compile_assert_matchi
5493  DEFINE_COMPILER;  DEFINE_COMPILER;
5494  int framesize;  int framesize;
5495  int extrasize;  int extrasize;
5496  BOOL needs_control_head = common->control_head_ptr != 0;  BOOL needs_control_head;
5497  int private_data_ptr;  int private_data_ptr;
5498  backtrack_common altbacktrack;  backtrack_common altbacktrack;
5499  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
# Line 5418  jump_list *tmp = NULL; Line 5503  jump_list *tmp = NULL;
5503  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;  jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.topbacktracks;
5504  jump_list **found;  jump_list **found;
5505  /* Saving previous accept variables. */  /* Saving previous accept variables. */
5506  struct sljit_label *save_quit_label = common->quit_label;  int save_then_local_exit = common->then_local_exit;
5507    then_trap_backtrack *save_then_trap = common->then_trap;
5508  struct sljit_label *save_accept_label = common->accept_label;  struct sljit_label *save_accept_label = common->accept_label;
5509  jump_list *save_quit = common->quit;  jump_list *save_then_quit = common->then_quit;
5510  jump_list *save_accept = common->accept;  jump_list *save_accept = common->accept;
 BOOL save_local_exit = common->local_exit;  
5511  struct sljit_jump *jump;  struct sljit_jump *jump;
5512  struct sljit_jump *brajump = NULL;  struct sljit_jump *brajump = NULL;
5513    
5514    /* Assert captures then. */
5515    common->then_trap = NULL;
5516    
5517  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)  if (*cc == OP_BRAZERO || *cc == OP_BRAMINZERO)
5518    {    {
5519    SLJIT_ASSERT(!conditional);    SLJIT_ASSERT(!conditional);
# Line 5434  if (*cc == OP_BRAZERO || *cc == OP_BRAMI Line 5522  if (*cc == OP_BRAZERO || *cc == OP_BRAMI
5522    }    }
5523  private_data_ptr = PRIVATE_DATA(cc);  private_data_ptr = PRIVATE_DATA(cc);
5524  SLJIT_ASSERT(private_data_ptr != 0);  SLJIT_ASSERT(private_data_ptr != 0);
5525  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
5526  backtrack->framesize = framesize;  backtrack->framesize = framesize;
5527  backtrack->private_data_ptr = private_data_ptr;  backtrack->private_data_ptr = private_data_ptr;
5528  opcode = *cc;  opcode = *cc;
# Line 5454  if (bra == OP_BRAMINZERO) Line 5542  if (bra == OP_BRAMINZERO)
5542  if (framesize < 0)  if (framesize < 0)
5543    {    {
5544    extrasize = needs_control_head ? 2 : 1;    extrasize = needs_control_head ? 2 : 1;
5545    if (framesize != no_stack)    if (framesize == no_frame)
5546      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
5547    allocate_stack(common, extrasize);    allocate_stack(common, extrasize);
5548    if (needs_control_head)    if (needs_control_head)
# Line 5484  else Line 5572  else
5572      }      }
5573    else    else
5574      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);
5575    init_frame(common, ccbegin, framesize + extrasize - 1, extrasize, FALSE);    init_frame(common, ccbegin, NULL, framesize + extrasize - 1, extrasize, FALSE);
5576    }    }
5577    
5578  memset(&altbacktrack, 0, sizeof(backtrack_common));  memset(&altbacktrack, 0, sizeof(backtrack_common));
5579  common->local_exit = TRUE;  common->then_local_exit = (opcode == OP_ASSERT || opcode == OP_ASSERTBACK) ? 1 : -1;
5580  common->quit_label = NULL;  common->then_quit = NULL;
 common->quit = NULL;  
5581  while (1)  while (1)
5582    {    {
5583    common->accept_label = NULL;    common->accept_label = NULL;
# Line 5505  while (1) Line 5592  while (1)
5592    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);    compile_matchingpath(common, ccbegin + 1 + LINK_SIZE, cc, &altbacktrack);
5593    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5594      {      {
5595      common->local_exit = save_local_exit;      common->then_local_exit = save_then_local_exit;
5596      common->quit_label = save_quit_label;      common->then_trap = save_then_trap;
5597      common->accept_label = save_accept_label;      common->accept_label = save_accept_label;
5598      common->quit = save_quit;      common->then_quit = save_then_quit;
5599      common->accept = save_accept;      common->accept = save_accept;
5600      return NULL;      return NULL;
5601      }      }
# Line 5519  while (1) Line 5606  while (1)
5606    /* Reset stack. */    /* Reset stack. */
5607    if (framesize < 0)    if (framesize < 0)
5608      {      {
5609      if (framesize != no_stack)      if (framesize == no_frame)
5610        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5611      else      else
5612        free_stack(common, extrasize);        free_stack(common, extrasize);
# Line 5573  while (1) Line 5660  while (1)
5660    compile_backtrackingpath(common, altbacktrack.top);    compile_backtrackingpath(common, altbacktrack.top);
5661    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))    if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
5662      {      {
5663      common->local_exit = save_local_exit;      common->then_local_exit = save_then_local_exit;
5664      common->quit_label = save_quit_label;      common->then_trap = save_then_trap;
5665      common->accept_label = save_accept_label;      common->accept_label = save_accept_label;
5666      common->quit = save_quit;      common->then_quit = save_then_quit;
5667      common->accept = save_accept;      common->accept = save_accept;
5668      return NULL;      return NULL;
5669      }      }
# Line 5590  while (1) Line 5677  while (1)
5677    }    }
5678    
5679  /* None of them matched. */  /* None of them matched. */
5680  if (common->quit != NULL)  if (common->then_quit != NULL)
5681    {    {
5682    jump = JUMP(SLJIT_JUMP);    jump = JUMP(SLJIT_JUMP);
5683    set_jumps(common->quit, LABEL());    set_jumps(common->then_quit, LABEL());
5684    SLJIT_ASSERT(framesize != no_stack);    SLJIT_ASSERT(framesize != no_stack);
5685    if (framesize < 0)    if (framesize < 0)
5686      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, extrasize * sizeof(sljit_sw));
# Line 5753  else Line 5840  else
5840      }      }
5841    }    }
5842    
5843  common->local_exit = save_local_exit;  common->then_local_exit = save_then_local_exit;
5844  common->quit_label = save_quit_label;  common->then_trap = save_then_trap;
5845  common->accept_label = save_accept_label;  common->accept_label = save_accept_label;
5846  common->quit = save_quit;  common->then_quit = save_then_quit;
5847  common->accept = save_accept;  common->accept = save_accept;
5848  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5849  }  }
# Line 5871  if (i < name_count) Line 5958  if (i < name_count)
5958  return condition;  return condition;
5959  }  }
5960    
5961    static SLJIT_INLINE void match_once_common(compiler_common *common, pcre_uchar ket, int framesize, int private_data_ptr, BOOL has_alternatives, BOOL needs_control_head)
5962    {
5963    DEFINE_COMPILER;
5964    int stacksize;
5965    
5966    if (framesize < 0)
5967      {
5968      if (framesize == no_frame)
5969        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
5970      else
5971        {
5972        stacksize = needs_control_head ? 1 : 0;
5973        if (ket != OP_KET || has_alternatives)
5974          stacksize++;
5975        free_stack(common, stacksize);
5976        }
5977    
5978      if (needs_control_head)
5979        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), (ket != OP_KET || has_alternatives) ? sizeof(sljit_sw) : 0);
5980    
5981      /* TMP2 which is set here used by OP_KETRMAX below. */
5982      if (ket == OP_KETRMAX)
5983        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);
5984      else if (ket == OP_KETRMIN)
5985        {
5986        /* Move the STR_PTR to the private_data_ptr. */
5987        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);
5988        }
5989      }
5990    else
5991      {
5992      stacksize = (ket != OP_KET || has_alternatives) ? 2 : 1;
5993      OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (framesize + stacksize) * sizeof(sljit_sw));
5994      if (needs_control_head)
5995        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 0);
5996    
5997      if (ket == OP_KETRMAX)
5998        {
5999        /* TMP2 which is set here used by OP_KETRMAX below. */
6000        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
6001        }
6002      }
6003    if (needs_control_head)
6004      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP1, 0);
6005    }
6006    
6007    static SLJIT_INLINE int match_capture_common(compiler_common *common, int stacksize, int offset, int private_data_ptr)
6008    {
6009    DEFINE_COMPILER;
6010    
6011    if (common->capture_last_ptr != 0)
6012      {
6013      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6014      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);
6015      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6016      stacksize++;
6017      }
6018    if (common->optimized_cbracket[offset >> 1] == 0)
6019      {
6020      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6021      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
6022      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6023      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6024      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6025      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);
6026      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);
6027      stacksize += 2;
6028      }
6029    return stacksize;
6030    }
6031    
6032  /*  /*
6033    Handling bracketed expressions is probably the most complex part.    Handling bracketed expressions is probably the most complex part.
6034    
# Line 5939  pcre_uchar bra = OP_BRA; Line 6097  pcre_uchar bra = OP_BRA;
6097  pcre_uchar ket;  pcre_uchar ket;
6098  assert_backtrack *assert;  assert_backtrack *assert;
6099  BOOL has_alternatives;  BOOL has_alternatives;
6100    BOOL needs_control_head = FALSE;
6101  struct sljit_jump *jump;  struct sljit_jump *jump;
6102  struct sljit_jump *skip;  struct sljit_jump *skip;
6103  struct sljit_label *rmaxlabel = NULL;  struct sljit_label *rmaxlabel = NULL;
# Line 6014  else if (opcode == OP_ONCE || opcode == Line 6173  else if (opcode == OP_ONCE || opcode ==
6173    SLJIT_ASSERT(private_data_ptr != 0);    SLJIT_ASSERT(private_data_ptr != 0);
6174    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;    BACKTRACK_AS(bracket_backtrack)->private_data_ptr = private_data_ptr;
6175    if (opcode == OP_ONCE)    if (opcode == OP_ONCE)
6176      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, FALSE);      BACKTRACK_AS(bracket_backtrack)->u.framesize = get_framesize(common, ccbegin, NULL, FALSE, &needs_control_head);
6177    }    }
6178    
6179  /* Instructions before the first alternative. */  /* Instructions before the first alternative. */
6180  stacksize = 0;  stacksize = 0;
6181  if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))  if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
6182    stacksize++;    stacksize++;
6183  if (bra == OP_BRAZERO)  if (bra == OP_BRAZERO)
6184    stacksize++;    stacksize++;
# Line 6028  if (stacksize > 0) Line 6187  if (stacksize > 0)
6187    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6188    
6189  stacksize = 0;  stacksize = 0;
6190  if ((ket == OP_KETRMAX) || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))  if (ket == OP_KETRMAX || (ket == OP_KETRMIN && bra != OP_BRAMINZERO))
6191    {    {
6192    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, 0);
6193    stacksize++;    stacksize++;
# Line 6091  if (ket == OP_KETRMAX) Line 6250  if (ket == OP_KETRMAX)
6250  /* Handling capturing brackets and alternatives. */  /* Handling capturing brackets and alternatives. */
6251  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
6252    {    {
6253      stacksize = 0;
6254      if (needs_control_head)
6255        {
6256        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6257        stacksize++;
6258        }
6259    
6260    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)    if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)
6261      {      {
6262      /* Neither capturing brackets nor recursions are not found in the block. */      /* Neither capturing brackets nor recursions are found in the block. */
6263      if (ket == OP_KETRMIN)      if (ket == OP_KETRMIN)
6264        {        {
6265        OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);        stacksize += 2;
6266        allocate_stack(common, 2);        if (!needs_control_head)
6267        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);  
       OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));  
6268        }        }
6269      else if (ket == OP_KETRMAX || has_alternatives)      else
6270        {        {
6271        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);        if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)
6272        allocate_stack(common, 1);          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6273        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);        if (ket == OP_KETRMAX || has_alternatives)
6274            stacksize++;
6275        }        }
6276      else  
6277        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);      if (stacksize > 0)
6278          allocate_stack(common, stacksize);
6279    
6280        stacksize = 0;
6281        if (needs_control_head)
6282          {
6283          stacksize++;
6284          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6285          }
6286    
6287        if (ket == OP_KETRMIN)
6288          {
6289          if (needs_control_head)
6290            OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6291          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6292          if (BACKTRACK_AS(bracket_backtrack)->u.framesize == no_frame)
6293            OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, needs_control_head ? (2 * sizeof(sljit_sw)) : sizeof(sljit_sw));
6294          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);
6295          }
6296        else if (ket == OP_KETRMAX || has_alternatives)
6297          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
6298      }      }
6299    else    else
6300      {      {
6301      if (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives)      if (ket != OP_KET || has_alternatives)
6302          stacksize++;
6303    
6304        stacksize += BACKTRACK_AS(bracket_backtrack)->u.framesize + 1;
6305        allocate_stack(common, stacksize);
6306    
6307        if (needs_control_head)
6308          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);
6309    
6310        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6311        OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, stacksize * sizeof(sljit_sw));
6312    
6313        stacksize = needs_control_head ? 1 : 0;
6314        if (ket != OP_KET || has_alternatives)
6315        {        {
6316        allocate_stack(common, BACKTRACK_AS(bracket_backtrack)->u.framesize + 2);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), STR_PTR, 0);
       OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
       OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(BACKTRACK_AS(bracket_backtrack)->u.framesize + 1));  
       OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);  
6317        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);
6318        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP1, 0);        stacksize++;
6319        init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize + 1, 2, FALSE);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
6320        }        }
6321      else      else
6322        {        {
       allocate_stack(common, BACKTRACK_AS(bracket_backtrack)->u.framesize + 1);  
       OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
       OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(BACKTRACK_AS(bracket_backtrack)->u.framesize));  
6323        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);
6324        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);
       init_frame(common, ccbegin, BACKTRACK_AS(bracket_backtrack)->u.framesize, 1, FALSE);  
6325        }        }
6326        init_frame(common, ccbegin, NULL, BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize, stacksize + 1, FALSE);
6327      }      }
6328    }    }
6329  else if (opcode == OP_CBRA || opcode == OP_SCBRA)  else if (opcode == OP_CBRA || opcode == OP_SCBRA)
# Line 6267  if (SLJIT_UNLIKELY(sljit_get_compiler_er Line 6459  if (SLJIT_UNLIKELY(sljit_get_compiler_er
6459    return NULL;    return NULL;
6460    
6461  if (opcode == OP_ONCE)  if (opcode == OP_ONCE)
6462    {    match_once_common(common, ket, BACKTRACK_AS(bracket_backtrack)->u.framesize, private_data_ptr, has_alternatives, needs_control_head);
   if (BACKTRACK_AS(bracket_backtrack)->u.framesize < 0)  
     {  
     OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
     /* TMP2 which is set here used by OP_KETRMAX below. */  
     if (ket == OP_KETRMAX)  
       OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);  
     else if (ket == OP_KETRMIN)  
       {  
       /* Move the STR_PTR to the private_data_ptr. */  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);  
       }  
     }  
   else  
     {  
     stacksize = (ket == OP_KETRMIN || ket == OP_KETRMAX || has_alternatives) ? 2 : 1;  
     OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (BACKTRACK_AS(bracket_backtrack)->u.framesize + stacksize) * sizeof(sljit_sw));  
     if (ket == OP_KETRMAX)  
       {  
       /* TMP2 which is set here used by OP_KETRMAX below. */  
       OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));  
       }  
     }  
   }  
6463    
6464  stacksize = 0;  stacksize = 0;
6465  if (ket != OP_KET || bra != OP_BRA)  if (ket != OP_KET || bra != OP_BRA)
# Line 6319  if (ket != OP_KET || bra != OP_BRA) Line 6488  if (ket != OP_KET || bra != OP_BRA)
6488    }    }
6489    
6490  if (offset != 0)  if (offset != 0)
6491    {    stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);
   if (common->capture_last_ptr != 0)  
     {  
     OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP2, 0);  
     stacksize++;  
     }  
   if (common->optimized_cbracket[offset >> 1] == 0)  
     {  
     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  
     OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);  
     OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);  
     stacksize += 2;  
     }  
   }  
6492    
6493  if (has_alternatives)  if (has_alternatives)
6494    {    {
# Line 6409  if ((ket != OP_KET && bra != OP_BRAMINZE Line 6559  if ((ket != OP_KET && bra != OP_BRAMINZE
6559  while (*cc == OP_ALT)  while (*cc == OP_ALT)
6560    cc += GET(cc, 1);    cc += GET(cc, 1);
6561  cc += 1 + LINK_SIZE;  cc += 1 + LINK_SIZE;
6562    
6563    /* Temporarily encoding the needs_control_head in framesize. */
6564    if (opcode == OP_ONCE)
6565      BACKTRACK_AS(bracket_backtrack)->u.framesize = (BACKTRACK_AS(bracket_backtrack)->u.framesize << 1) | (needs_control_head ? 1 : 0);
6566  return cc;  return cc;
6567  }  }
6568    
# Line 6419  backtrack_common *backtrack; Line 6573  backtrack_common *backtrack;
6573  pcre_uchar opcode;  pcre_uchar opcode;
6574  int private_data_ptr;  int private_data_ptr;
6575  int cbraprivptr = 0;  int cbraprivptr = 0;
6576    BOOL needs_control_head;
6577  int framesize;  int framesize;
6578  int stacksize;  int stacksize;
6579  int offset = 0;  int offset = 0;
6580  BOOL zero = FALSE;  BOOL zero = FALSE;
6581  pcre_uchar *ccbegin = NULL;  pcre_uchar *ccbegin = NULL;
6582  int stack;  int stack; /* Also contains the offset of control head. */
6583  struct sljit_label *loop = NULL;  struct sljit_label *loop = NULL;
6584  struct jump_list *emptymatch = NULL;  struct jump_list *emptymatch = NULL;
6585    
# Line 6462  switch(opcode) Line 6617  switch(opcode)
6617    break;    break;
6618    }    }
6619    
6620  framesize = get_framesize(common, cc, FALSE);  framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head);
6621  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;  BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize;
6622  if (framesize < 0)  if (framesize < 0)
6623    {    {
# Line 6475  if (framesize < 0) Line 6630  if (framesize < 0)
6630    else    else
6631      stacksize = 1;      stacksize = 1;
6632    
6633      if (needs_control_head)
6634        stacksize++;
6635    if (!zero)    if (!zero)
6636      stacksize++;      stacksize++;
6637    
# Line 6483  if (framesize < 0) Line 6640  if (framesize < 0)
6640    if (framesize == no_frame)    if (framesize == no_frame)
6641      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0);
6642    
6643      stack = 0;
6644    if (offset != 0)    if (offset != 0)
6645      {      {
6646        stack = 2;
6647      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));
6648      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));
6649      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
6650      if (common->capture_last_ptr != 0)      if (common->capture_last_ptr != 0)
6651        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);
6652      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), TMP2, 0);
6653        if (needs_control_head)
6654          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6655      if (common->capture_last_ptr != 0)      if (common->capture_last_ptr != 0)
6656          {
6657        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), TMP1, 0);
6658          stack = 3;
6659          }
6660      }      }
6661    else    else
6662        {
6663        if (needs_control_head)
6664          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6665      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
6666        stack = 1;
6667        }
6668    
6669      if (needs_control_head)
6670        stack++;
6671    if (!zero)    if (!zero)
6672      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize - 1), SLJIT_IMM, 1);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), SLJIT_IMM, 1);
6673      if (needs_control_head)
6674        {
6675        stack--;
6676        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP2, 0);
6677        }
6678    }    }
6679  else  else
6680    {    {
6681    stacksize = framesize + 1;    stacksize = framesize + 1;
6682    if (!zero)    if (!zero)
6683      stacksize++;      stacksize++;
6684    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)    if (needs_control_head)
6685        stacksize++;
6686      if (offset == 0)
6687      stacksize++;      stacksize++;
6688    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;    BACKTRACK_AS(bracketpos_backtrack)->stacksize = stacksize;
6689    
6690    allocate_stack(common, stacksize);    allocate_stack(common, stacksize);
6691    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
6692    OP2(SLJIT_SUB, TMP2, 0, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));    if (needs_control_head)
6693    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, TMP2, 0);      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
6694      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, STACK_TOP, 0, SLJIT_IMM, -STACK(stacksize - 1));
6695    
6696    stack = 0;    stack = 0;
6697    if (!zero)    if (!zero)
6698      {      {
6699      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 1);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 1);
6700        stack = 1;
6701        }
6702      if (needs_control_head)
6703        {
6704        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP2, 0);
6705      stack++;      stack++;
6706      }      }
6707    if (opcode == OP_BRAPOS || opcode == OP_SBRAPOS)    if (offset == 0)
6708      {      {
6709      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), STR_PTR, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), STR_PTR, 0);
6710      stack++;      stack++;
6711      }      }
6712    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stack), TMP1, 0);
6713    init_frame(common, cc, stacksize - 1, stacksize - framesize, FALSE);    init_frame(common, cc, NULL, stacksize - 1, stacksize - framesize, FALSE);
6714      stack -= 1 + (offset == 0);
6715    }    }
6716    
6717  if (offset != 0)  if (offset != 0)
# Line 6602  while (*cc != OP_KETRPOS) Line 6787  while (*cc != OP_KETRPOS)
6787          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), SLJIT_IMM, 0);
6788        }        }
6789      }      }
6790    
6791      if (needs_control_head)
6792        OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_MEM1(STACK_TOP), STACK(stack));
6793    
6794    JUMPTO(SLJIT_JUMP, loop);    JUMPTO(SLJIT_JUMP, loop);
6795    flush_stubs(common);    flush_stubs(common);
6796    
# Line 6638  while (*cc != OP_KETRPOS) Line 6827  while (*cc != OP_KETRPOS)
6827    ccbegin = cc + 1 + LINK_SIZE;    ccbegin = cc + 1 + LINK_SIZE;
6828    }    }
6829    
6830    /* We don't have to restore the control head in case of a failed match. */
6831    
6832  backtrack->topbacktracks = NULL;  backtrack->topbacktracks = NULL;
6833  if (!zero)  if (!zero)
6834    {    {
# Line 7026  if (!optimized_cbracket) Line 7217  if (!optimized_cbracket)
7217  return cc + 1 + IMM2_SIZE;  return cc + 1 + IMM2_SIZE;
7218  }  }
7219    
7220    static SLJIT_INLINE pcre_uchar *compile_control_verb_matchingpath(compiler_common *common, pcre_uchar *cc, backtrack_common *parent)
7221    {
7222    DEFINE_COMPILER;
7223    backtrack_common *backtrack;
7224    pcre_uchar opcode = *cc;
7225    pcre_uchar *ccend = cc + 1;
7226    
7227    if (opcode == OP_PRUNE_ARG || opcode == OP_SKIP_ARG || opcode == OP_THEN_ARG)
7228      ccend += 2 + cc[1];
7229    
7230    PUSH_BACKTRACK(sizeof(backtrack_common), cc, NULL);
7231    
7232    if (opcode == OP_SKIP)
7233      {
7234      allocate_stack(common, 1);
7235      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
7236      return ccend;
7237      }
7238    
7239    if (opcode == OP_PRUNE_ARG || opcode == OP_THEN_ARG)
7240      {
7241      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
7242      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));
7243      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);
7244      OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);
7245      }
7246    
7247    return ccend;
7248    }
7249    
7250    static pcre_uchar then_trap_opcode[1] = { OP_THEN_TRAP };
7251    
7252    static SLJIT_INLINE void compile_then_trap_matchingpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, backtrack_common *parent)
7253    {
7254    DEFINE_COMPILER;
7255    backtrack_common *backtrack;
7256    BOOL needs_control_head;
7257    int size;
7258    
7259    PUSH_BACKTRACK_NOVALUE(sizeof(then_trap_backtrack), cc);
7260    common->then_trap = BACKTRACK_AS(then_trap_backtrack);
7261    BACKTRACK_AS(then_trap_backtrack)->common.cc = then_trap_opcode;
7262    BACKTRACK_AS(then_trap_backtrack)->start = (sljit_sw)(cc - common->start);
7263    BACKTRACK_AS(then_trap_backtrack)->framesize = get_framesize(common, cc, ccend, FALSE, &needs_control_head);
7264    
7265    size = BACKTRACK_AS(then_trap_backtrack)->framesize;
7266    size = 3 + (size < 0 ? 0 : size);
7267    
7268    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
7269    allocate_stack(common, size);
7270    if (size > 3)
7271      OP2(SLJIT_SUB, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0, SLJIT_IMM, (size - 3) * sizeof(sljit_sw));
7272    else
7273      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);
7274    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 1), SLJIT_IMM, BACKTRACK_AS(then_trap_backtrack)->start);
7275    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 2), SLJIT_IMM, type_then_trap);
7276    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(size - 3), TMP2, 0);
7277    
7278    size = BACKTRACK_AS(then_trap_backtrack)->framesize;
7279    if (size >= 0)
7280      init_frame(common, cc, ccend, size - 1, 0, FALSE);
7281    }
7282    
7283  static void compile_matchingpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, backtrack_common *parent)  static void compile_matchingpath(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend, backtrack_common *parent)
7284  {  {
7285  DEFINE_COMPILER;  DEFINE_COMPILER;
7286  backtrack_common *backtrack;  backtrack_common *backtrack;
7287    BOOL has_then_trap = FALSE;
7288    then_trap_backtrack *save_then_trap = NULL;
7289    
7290    SLJIT_ASSERT(*ccend == OP_END || (*ccend >= OP_ALT && *ccend <= OP_KETRPOS));
7291    
7292    if (common->has_then && common->then_offsets[cc - common->start] != 0)
7293      {
7294      SLJIT_ASSERT(*ccend != OP_END && common->control_head_ptr != 0);
7295      has_then_trap = TRUE;
7296      save_then_trap = common->then_trap;
7297      /* Tail item on backtrack. */
7298      compile_then_trap_matchingpath(common, cc, ccend, parent);
7299      }
7300    
7301  while (cc < ccend)  while (cc < ccend)
7302    {    {
# Line 7246  while (cc < ccend) Line 7513  while (cc < ccend)
7513      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);
7514      SLJIT_ASSERT(common->mark_ptr != 0);      SLJIT_ASSERT(common->mark_ptr != 0);
7515      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);
7516      allocate_stack(common, 1);      allocate_stack(common, common->has_skip_arg ? 5 : 1);
7517      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);      OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
7518      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(common->has_skip_arg ? 4 : 0), TMP2, 0);
7519      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));      OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));
7520      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);
7521      OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);
7522        if (common->has_skip_arg)
7523          {
7524          OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
7525          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);
7526          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, type_mark);
7527          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), SLJIT_IMM, (sljit_sw)(cc + 2));
7528          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(3), STR_PTR, 0);
7529          OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP1, 0);
7530          }
7531      cc += 1 + 2 + cc[1];      cc += 1 + 2 + cc[1];
7532      break;      break;
7533    
     case OP_PRUNE_ARG:  
     OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);  
     OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, (sljit_sw)(cc + 2));  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP2, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr), TMP2, 0);  
     /* Fall through. */  
   
7534      case OP_PRUNE:      case OP_PRUNE:
7535      case OP_COMMIT:      case OP_PRUNE_ARG:
     PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);  
     SLJIT_ASSERT(common->control_head_ptr != 0);  
     OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);  
     allocate_stack(common, 2);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, *cc == OP_COMMIT ? type_commit : type_prune);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);  
     cc += (*cc == OP_PRUNE_ARG) ? (1 + 2 + cc[1]) : 1;  
     break;  
   
7536      case OP_SKIP:      case OP_SKIP:
7537      PUSH_BACKTRACK_NOVALUE(sizeof(backtrack_common), cc);      case OP_SKIP_ARG:
7538      OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);      case OP_THEN:
7539      allocate_stack(common, 3);      case OP_THEN_ARG:
7540      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, STACK_TOP, 0);      case OP_COMMIT:
7541      OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(1), SLJIT_IMM, type_skip);      cc = compile_control_verb_matchingpath(common, cc, parent);
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(2), STR_PTR, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), TMP2, 0);  
     cc += 1;  
7542      break;      break;
7543    
7544      case OP_FAIL:      case OP_FAIL:
# Line 7306  while (cc < ccend) Line 7562  while (cc < ccend)
7562    if (cc == NULL)    if (cc == NULL)
7563      return;      return;
7564    }    }
7565    
7566    if (has_then_trap)
7567      {
7568      /* Head item on backtrack. */
7569      PUSH_BACKTRACK_NOVALUE(sizeof(then_trap_backtrack), cc);
7570      BACKTRACK_AS(then_trap_backtrack)->common.cc = then_trap_opcode;
7571      BACKTRACK_AS(then_trap_backtrack)->then_trap = common->then_trap;
7572      common->then_trap = save_then_trap;
7573      }
7574  SLJIT_ASSERT(cc == ccend);  SLJIT_ASSERT(cc == ccend);
7575  }  }
7576    
# Line 7467  switch(opcode) Line 7732  switch(opcode)
7732    }    }
7733  }  }
7734    
7735  static void compile_ref_iterator_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static SLJIT_INLINE void compile_ref_iterator_backtrackingpath(compiler_common *common, struct backtrack_common *current)
7736  {  {
7737  DEFINE_COMPILER;  DEFINE_COMPILER;
7738  pcre_uchar *cc = current->cc;  pcre_uchar *cc = current->cc;
# Line 7489  set_jumps(current->topbacktracks, LABEL( Line 7754  set_jumps(current->topbacktracks, LABEL(
7754  free_stack(common, 2);  free_stack(common, 2);
7755  }  }
7756    
7757  static void compile_recurse_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static SLJIT_INLINE void compile_recurse_backtrackingpath(compiler_common *common, struct backtrack_common *current)
7758  {  {
7759  DEFINE_COMPILER;  DEFINE_COMPILER;
7760    
# Line 7599  pcre_uchar bra = OP_BRA; Line 7864  pcre_uchar bra = OP_BRA;
7864  pcre_uchar ket;  pcre_uchar ket;
7865  assert_backtrack *assert;  assert_backtrack *assert;
7866  BOOL has_alternatives;  BOOL has_alternatives;
7867    BOOL needs_control_head = FALSE;
7868  struct sljit_jump *brazero = NULL;  struct sljit_jump *brazero = NULL;
7869  struct sljit_jump *once = NULL;  struct sljit_jump *once = NULL;
7870  struct sljit_jump *cond = NULL;  struct sljit_jump *cond = NULL;
# Line 7624  if (SLJIT_UNLIKELY(opcode == OP_COND) && Line 7890  if (SLJIT_UNLIKELY(opcode == OP_COND) &&
7890  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))  if (SLJIT_UNLIKELY(opcode == OP_ONCE_NC))
7891    opcode = OP_ONCE;    opcode = OP_ONCE;
7892    
7893    /* Decoding the needs_control_head in framesize. */
7894    if (opcode == OP_ONCE)
7895      {
7896      needs_control_head = (CURRENT_AS(bracket_backtrack)->u.framesize & 0x1) != 0;
7897      CURRENT_AS(bracket_backtrack)->u.framesize >>= 1;
7898      }
7899    
7900  if (ket == OP_KETRMAX)  if (ket == OP_KETRMAX)
7901    {    {
7902    if (bra == OP_BRAZERO)    if (bra == OP_BRAZERO)
# Line 7781  if (has_alternatives) Line 8054  if (has_alternatives)
8054      current->top = NULL;      current->top = NULL;
8055      current->topbacktracks = NULL;      current->topbacktracks = NULL;
8056      current->nextbacktracks = NULL;      current->nextbacktracks = NULL;
8057        /* Conditional blocks always have an additional alternative, even if it is empty. */
8058      if (*cc == OP_ALT)      if (*cc == OP_ALT)
8059        {        {
8060        ccprev = cc + 1 + LINK_SIZE;        ccprev = cc + 1 + LINK_SIZE;
8061        cc += GET(cc, 1);        cc += GET(cc, 1);
8062        if (opcode != OP_COND && opcode != OP_SCOND)        if (opcode != OP_COND && opcode != OP_SCOND)
8063          {          {
8064          if (private_data_ptr != 0 && opcode != OP_ONCE)          if (opcode != OP_ONCE)
8065            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);            {
8066              if (private_data_ptr != 0)
8067                OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);
8068              else
8069                OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8070              }
8071          else          else
8072            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));            OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(needs_control_head ? 1 : 0));
8073          }          }
8074        compile_matchingpath(common, ccprev, cc, current);        compile_matchingpath(common, ccprev, cc, current);
8075        if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))        if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler)))
# Line 7800  if (has_alternatives) Line 8079  if (has_alternatives)
8079      /* Instructions after the current alternative is succesfully matched. */      /* Instructions after the current alternative is succesfully matched. */
8080      /* There is a similar code in compile_bracket_matchingpath. */      /* There is a similar code in compile_bracket_matchingpath. */
8081      if (opcode == OP_ONCE)      if (opcode == OP_ONCE)
8082        {        match_once_common(common, ket, CURRENT_AS(bracket_backtrack)->u.framesize, private_data_ptr, has_alternatives, needs_control_head);
       if (CURRENT_AS(bracket_backtrack)->u.framesize < 0)  
         {  
         OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
         /* TMP2 which is set here used by OP_KETRMAX below. */  
         if (ket == OP_KETRMAX)  
           OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), 0);  
         else if (ket == OP_KETRMIN)  
           {  
           /* Move the STR_PTR to the private_data_ptr. */  
           OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_MEM1(STACK_TOP), 0);  
           }  
         }  
       else  
         {  
         OP2(SLJIT_ADD, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr, SLJIT_IMM, (CURRENT_AS(bracket_backtrack)->u.framesize + 2) * sizeof(sljit_sw));  
         if (ket == OP_KETRMAX)  
           {  
           /* TMP2 which is set here used by OP_KETRMAX below. */  
           OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));  
           }  
         }  
       }  
8083    
8084      stacksize = 0;      stacksize = 0;
8085      if (ket != OP_KET || bra != OP_BRA)      if (ket != OP_KET || bra != OP_BRA)
# Line 7837  if (has_alternatives) Line 8094  if (has_alternatives)
8094      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
8095        stacksize++;        stacksize++;
8096    
8097      if (stacksize > 0) {      if (stacksize > 0)
8098          {
8099        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize >= 0)        if (opcode != OP_ONCE || CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
8100          allocate_stack(common, stacksize);          allocate_stack(common, stacksize);
8101        else        else
# Line 7846  if (has_alternatives) Line 8104  if (has_alternatives)
8104          SLJIT_ASSERT(stacksize == 1);          SLJIT_ASSERT(stacksize == 1);
8105          OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));          OP2(SLJIT_ADD, STACK_TOP, 0, STACK_TOP, 0, SLJIT_IMM, sizeof(sljit_sw));
8106          }          }
8107      }        }
8108    
8109      stacksize = 0;      stacksize = 0;
8110      if (ket != OP_KET || bra != OP_BRA)      if (ket != OP_KET || bra != OP_BRA)
# Line 7859  if (has_alternatives) Line 8117  if (has_alternatives)
8117        }        }
8118    
8119      if (offset != 0)      if (offset != 0)
8120        {        stacksize = match_capture_common(common, stacksize, offset, private_data_ptr);
       if (common->capture_last_ptr != 0)  
         {  
         OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr);  
         OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, offset >> 1);  
         OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);  
         stacksize++;  
         }  
       if (common->optimized_cbracket[offset >> 1] == 0)  
         {  
         OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset));  
         OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1));  
         OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), TMP1, 0);  
         OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), private_data_ptr);  
         OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize + 1), TMP2, 0);  
         OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset + 1), STR_PTR, 0);  
         OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(offset), TMP1, 0);  
         stacksize += 2;  
         }  
       }  
8121    
8122      if (opcode != OP_ONCE)      if (opcode != OP_ONCE)
8123        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, count++);        OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(stacksize), SLJIT_IMM, count++);
# Line 7951  else if (opcode == OP_SBRA || opcode == Line 8190  else if (opcode == OP_SBRA || opcode ==
8190  else if (opcode == OP_ONCE)  else if (opcode == OP_ONCE)
8191    {    {
8192    cc = ccbegin + GET(ccbegin, 1);    cc = ccbegin + GET(ccbegin, 1);
8193      stacksize = needs_control_head ? 1 : 0;
8194    
8195    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)    if (CURRENT_AS(bracket_backtrack)->u.framesize >= 0)
8196      {      {
8197      /* Reset head and drop saved frame. */      /* Reset head and drop saved frame. */
8198      stacksize = (ket == OP_KETRMAX || ket == OP_KETRMIN || *cc == OP_ALT) ? 2 : 1;      stacksize += CURRENT_AS(bracket_backtrack)->u.framesize + ((ket != OP_KET || *cc == OP_ALT) ? 2 : 1);
     free_stack(common, CURRENT_AS(bracket_backtrack)->u.framesize + stacksize);  
8199      }      }
8200    else if (ket == OP_KETRMAX || (*cc == OP_ALT && ket != OP_KETRMIN))    else if (ket == OP_KETRMAX || (*cc == OP_ALT && ket != OP_KETRMIN))
8201      {      {
8202      /* The STR_PTR must be released. */      /* The STR_PTR must be released. */
8203      free_stack(common, 1);      stacksize++;
8204      }      }
8205      free_stack(common, stacksize);
8206    
8207    JUMPHERE(once);    JUMPHERE(once);
8208    /* Restore previous private_data_ptr */    /* Restore previous private_data_ptr */
# Line 8013  else if (bra == OP_BRAZERO) Line 8254  else if (bra == OP_BRAZERO)
8254    }    }
8255  }  }
8256    
8257  static void compile_bracketpos_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static SLJIT_INLINE void compile_bracketpos_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8258  {  {
8259  DEFINE_COMPILER;  DEFINE_COMPILER;
8260  int offset;  int offset;
# Line 8052  if (current->topbacktracks) Line 8293  if (current->topbacktracks)
8293  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(bracketpos_backtrack)->private_data_ptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(bracketpos_backtrack)->framesize * sizeof(sljit_sw));  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CURRENT_AS(bracketpos_backtrack)->private_data_ptr, SLJIT_MEM1(STACK_TOP), CURRENT_AS(bracketpos_backtrack)->framesize * sizeof(sljit_sw));
8294  }  }
8295    
8296  static void compile_braminzero_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static SLJIT_INLINE void compile_braminzero_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8297  {  {
8298  assert_backtrack backtrack;  assert_backtrack backtrack;
8299    
# Line 8076  else Line 8317  else
8317  SLJIT_ASSERT(!current->nextbacktracks && !current->topbacktracks);  SLJIT_ASSERT(!current->nextbacktracks && !current->topbacktracks);
8318  }  }
8319    
8320    static SLJIT_INLINE void compile_control_verb_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8321    {
8322    DEFINE_COMPILER;
8323    pcre_uchar opcode = *current->cc;
8324    struct sljit_label *loop;
8325    struct sljit_jump *jump;
8326    
8327    if (opcode == OP_THEN || opcode == OP_THEN_ARG)
8328      {
8329      if (common->then_trap != NULL)
8330        {
8331        SLJIT_ASSERT(common->control_head_ptr != 0);
8332    
8333        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
8334        OP1(SLJIT_MOV, TMP1, 0, SLJIT_IMM, type_then_trap);
8335        OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, common->then_trap->start);
8336        jump = JUMP(SLJIT_JUMP);
8337    
8338        loop = LABEL();
8339        OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(STACK_TOP), -(int)sizeof(sljit_sw));
8340        JUMPHERE(jump);
8341        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(STACK_TOP), -(int)(2 * sizeof(sljit_sw)), TMP1, 0, loop);
8342        CMPTO(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(STACK_TOP), -(int)(3 * sizeof(sljit_sw)), TMP2, 0, loop);
8343        add_jump(compiler, &common->then_trap->quit, JUMP(SLJIT_JUMP));
8344        return;
8345        }
8346      else if (common->then_local_exit != 0)
8347        {
8348        if (common->then_local_exit > 0)
8349          add_jump(compiler, &common->then_quit, JUMP(SLJIT_JUMP));
8350        else if (common->accept_label == NULL)
8351          add_jump(compiler, &common->accept, JUMP(SLJIT_JUMP));
8352        else
8353          JUMPTO(SLJIT_JUMP, common->accept_label);
8354        return;
8355        }
8356      }
8357    
8358    if (common->local_exit)
8359      {
8360      if (common->quit_label == NULL)
8361        add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));
8362      else
8363        JUMPTO(SLJIT_JUMP, common->quit_label);
8364      return;
8365      }
8366    
8367    if (opcode == OP_SKIP_ARG)
8368      {
8369      SLJIT_ASSERT(common->control_head_ptr != 0);
8370      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);
8371      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);
8372      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_IMM, (sljit_sw)(current->cc + 2));
8373      sljit_emit_ijump(compiler, SLJIT_CALL2, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_search_mark));
8374      OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);
8375    
8376      OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);
8377      add_jump(compiler, &common->reset_match, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, -1));
8378      return;
8379      }
8380    
8381    if (opcode == OP_SKIP)
8382      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8383    else
8384      OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_IMM, 0);
8385    add_jump(compiler, &common->reset_match, JUMP(SLJIT_JUMP));
8386    }
8387    
8388    static SLJIT_INLINE void compile_then_trap_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8389    {
8390    DEFINE_COMPILER;
8391    struct sljit_jump *jump;
8392    int size;
8393    
8394    if (CURRENT_AS(then_trap_backtrack)->then_trap)
8395      {
8396      common->then_trap = CURRENT_AS(then_trap_backtrack)->then_trap;
8397      return;
8398      }
8399    
8400    size = CURRENT_AS(then_trap_backtrack)->framesize;
8401    size = 3 + (size < 0 ? 0 : size);
8402    
8403    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(size - 3));
8404    free_stack(common, size);
8405    jump = JUMP(SLJIT_JUMP);
8406    
8407    set_jumps(CURRENT_AS(then_trap_backtrack)->quit, LABEL());
8408    /* STACK_TOP is set by THEN. */
8409    if (CURRENT_AS(then_trap_backtrack)->framesize >= 0)
8410      add_jump(compiler, &common->revertframes, JUMP(SLJIT_FAST_CALL));
8411    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8412    free_stack(common, 3);
8413    
8414    JUMPHERE(jump);
8415    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP1, 0);
8416    }
8417    
8418  static void compile_backtrackingpath(compiler_common *common, struct backtrack_common *current)  static void compile_backtrackingpath(compiler_common *common, struct backtrack_common *current)
8419  {  {
8420  DEFINE_COMPILER;  DEFINE_COMPILER;
8421    then_trap_backtrack *save_then_trap = common->then_trap;
8422    
8423  while (current)  while (current)
8424    {    {
# Line 8212  while (current) Line 8552  while (current)
8552      break;      break;
8553    
8554      case OP_MARK:      case OP_MARK:
8555      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));      OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(common->has_skip_arg ? 4 : 0));
8556      free_stack(common, 1);      if (common->has_skip_arg)
8557          OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
8558        free_stack(common, common->has_skip_arg ? 5 : 1);
8559      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP1, 0);      OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->mark_ptr, TMP1, 0);
8560        if (common->has_skip_arg)
8561          OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, TMP2, 0);
8562      break;      break;
8563    
8564        case OP_THEN:
8565        case OP_THEN_ARG:
8566      case OP_PRUNE:      case OP_PRUNE:
8567      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
8568      case OP_SKIP:      case OP_SKIP:
8569      if (!common->local_exit)      case OP_SKIP_ARG:
8570        {      compile_control_verb_backtrackingpath(common, current);
       SLJIT_ASSERT(common->control_head_ptr != 0);  
       OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr);  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, STACK_TOP, 0);  
       sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_check_control_chain));  
       OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0);  
   
       OP1(SLJIT_MOV, STR_PTR, 0, TMP1, 0);  
       add_jump(compiler, &common->reset_match, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, SLJIT_IMM, -1));  
   
       OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE_ERROR_NOMATCH);  
       }  
   
     /* Commit or in recurse or accept. */  
     if (common->quit_label == NULL)  
       add_jump(compiler, &common->quit, JUMP(SLJIT_JUMP));  
     else  
       JUMPTO(SLJIT_JUMP, common->quit_label);  
8571      break;      break;
8572    
8573      case OP_COMMIT:      case OP_COMMIT:
# Line 8257  while (current) Line 8586  while (current)
8586      set_jumps(current->topbacktracks, LABEL());      set_jumps(current->topbacktracks, LABEL());
8587      break;      break;
8588    
8589        case OP_THEN_TRAP:
8590        /* A virtual opcode for then traps. */
8591        compile_then_trap_backtrackingpath(common, current);
8592        break;
8593    
8594      default:      default:
8595      SLJIT_ASSERT_STOP();      SLJIT_ASSERT_STOP();
8596      break;      break;
8597      }      }
8598    current = current->prev;    current = current->prev;
8599    }    }
8600    common->then_trap = save_then_trap;
8601  }  }
8602    
8603  static SLJIT_INLINE void compile_recurse(compiler_common *common)  static SLJIT_INLINE void compile_recurse(compiler_common *common)
# Line 8271  DEFINE_COMPILER; Line 8606  DEFINE_COMPILER;
8606  pcre_uchar *cc = common->start + common->currententry->start;  pcre_uchar *cc = common->start + common->currententry->start;
8607  pcre_uchar *ccbegin = cc + 1 + LINK_SIZE + (*cc == OP_BRA ? 0 : IMM2_SIZE);  pcre_uchar *ccbegin = cc + 1 + LINK_SIZE + (*cc == OP_BRA ? 0 : IMM2_SIZE);
8608  pcre_uchar *ccend = bracketend(cc);  pcre_uchar *ccend = bracketend(cc);
8609  int private_data_size = get_private_data_length_for_copy(common, ccbegin, ccend);  BOOL needs_control_head;
8610  int framesize = get_framesize(common, cc, TRUE);  int framesize = get_framesize(common, cc, NULL, TRUE, &needs_control_head);
8611    int private_data_size = get_private_data_copy_length(common, ccbegin, ccend, needs_control_head);
8612  int alternativesize;  int alternativesize;
8613  BOOL needs_frame;  BOOL needs_frame;
8614  backtrack_common altbacktrack;  backtrack_common altbacktrack;
8615  struct sljit_jump *jump;  struct sljit_jump *jump;
8616    
8617    /* Recurse captures then. */
8618    common->then_trap = NULL;
8619    
8620  SLJIT_ASSERT(*cc == OP_BRA || *cc == OP_CBRA || *cc == OP_CBRAPOS || *cc == OP_SCBRA || *cc == OP_SCBRAPOS);  SLJIT_ASSERT(*cc == OP_BRA || *cc == OP_CBRA || *cc == OP_CBRAPOS || *cc == OP_SCBRA || *cc == OP_SCBRAPOS);
8621  needs_frame = framesize >= 0;  needs_frame = framesize >= 0;
8622  if (!needs_frame)  if (!needs_frame)
# Line 8291  set_jumps(common->currententry->calls, c Line 8630  set_jumps(common->currententry->calls, c
8630  sljit_emit_fast_enter(compiler, TMP2, 0);  sljit_emit_fast_enter(compiler, TMP2, 0);
8631  allocate_stack(common, private_data_size + framesize + alternativesize);  allocate_stack(common, private_data_size + framesize + alternativesize);
8632  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(private_data_size + framesize + alternativesize - 1), TMP2, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(private_data_size + framesize + alternativesize - 1), TMP2, 0);
8633  copy_private_data(common, ccbegin, ccend, TRUE, private_data_size + framesize + alternativesize, framesize + alternativesize);  copy_private_data(common, ccbegin, ccend, TRUE, private_data_size + framesize + alternativesize, framesize + alternativesize, needs_control_head);
8634  if (common->control_head_ptr != 0)  if (needs_control_head)
8635    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->control_head_ptr, SLJIT_IMM, 0);
8636  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr, STACK_TOP, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->recursive_head_ptr, STACK_TOP, 0);
8637  if (needs_frame)  if (needs_frame)
8638    init_frame(common, cc, framesize + alternativesize - 1, alternativesize, TRUE);    init_frame(common, cc, NULL, framesize + alternativesize - 1, alternativesize, TRUE);
8639    
8640  if (alternativesize > 0)  if (alternativesize > 0)
8641    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(STACK_TOP), STACK(0), STR_PTR, 0);
# Line 8366  OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 1); Line 8705  OP1(SLJIT_MOV, TMP3, 0, SLJIT_IMM, 1);
8705  JUMPHERE(jump);  JUMPHERE(jump);
8706  if (common->quit != NULL)  if (common->quit != NULL)
8707    set_jumps(common->quit, LABEL());    set_jumps(common->quit, LABEL());
8708  copy_private_data(common, ccbegin, ccend, FALSE, private_data_size + framesize + alternativesize, framesize + alternativesize);  copy_private_data(common, ccbegin, ccend, FALSE, private_data_size + framesize + alternativesize, framesize + alternativesize, needs_control_head);
8709  free_stack(common, private_data_size + framesize + alternativesize);  free_stack(common, private_data_size + framesize + alternativesize);
8710  if (common->control_head_ptr != 0)  if (needs_control_head)
8711    {    {
8712    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 2 * sizeof(sljit_sw));    OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), 2 * sizeof(sljit_sw));
8713    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), sizeof(sljit_sw));    OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), sizeof(sljit_sw));
# Line 8560  if (private_data_size > SLJIT_MAX_LOCAL_ Line 8899  if (private_data_size > SLJIT_MAX_LOCAL_
8899    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
8900    return;    return;
8901    }    }
8902    
8903  common->private_data_ptrs = (int *)SLJIT_MALLOC((ccend - rootbacktrack.cc) * sizeof(int));  common->private_data_ptrs = (int *)SLJIT_MALLOC((ccend - rootbacktrack.cc) * sizeof(int));
8904  if (!common->private_data_ptrs)  if (!common->private_data_ptrs)
8905    {    {
# Line 8569  if (!common->private_data_ptrs) Line 8909  if (!common->private_data_ptrs)
8909  memset(common->private_data_ptrs, 0, (ccend - rootbacktrack.cc) * sizeof(int));  memset(common->private_data_ptrs, 0, (ccend - rootbacktrack.cc) * sizeof(int));
8910  set_private_data_ptrs(common, common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw), ccend);  set_private_data_ptrs(common, common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw), ccend);
8911    
8912    if (common->has_then)
8913      {
8914      common->then_offsets = (pcre_uint8 *)SLJIT_MALLOC(ccend - rootbacktrack.cc);
8915      if (!common->then_offsets)
8916        {
8917        SLJIT_FREE(common->optimized_cbracket);
8918        SLJIT_FREE(common->private_data_ptrs);
8919        return;
8920        }
8921      memset(common->then_offsets, 0, ccend - rootbacktrack.cc);
8922      set_then_offsets(common, rootbacktrack.cc, NULL);
8923      }
8924    
8925  compiler = sljit_create_compiler();  compiler = sljit_create_compiler();
8926  if (!compiler)  if (!compiler)
8927    {    {
8928    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
8929    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
8930      if (common->has_then)
8931        SLJIT_FREE(common->then_offsets);
8932    return;    return;
8933    }    }
8934  common->compiler = compiler;  common->compiler = compiler;
# Line 8665  if (SLJIT_UNLIKELY(sljit_get_compiler_er Line 9020  if (SLJIT_UNLIKELY(sljit_get_compiler_er
9020    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
9021    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9022    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
9023      if (common->has_then)
9024        SLJIT_FREE(common->then_offsets);
9025    return;    return;
9026    }    }
9027    
# Line 8700  if (SLJIT_UNLIKELY(sljit_get_compiler_er Line 9057  if (SLJIT_UNLIKELY(sljit_get_compiler_er
9057    sljit_free_compiler(compiler);    sljit_free_compiler(compiler);
9058    SLJIT_FREE(common->optimized_cbracket);    SLJIT_FREE(common->optimized_cbracket);
9059    SLJIT_FREE(common->private_data_ptrs);    SLJIT_FREE(common->private_data_ptrs);
9060      if (common->has_then)
9061        SLJIT_FREE(common->then_offsets);
9062    return;    return;
9063    }    }
9064    
# Line 8767  while (common->currententry != NULL) Line 9126  while (common->currententry != NULL)
9126      sljit_free_compiler(compiler);      sljit_free_compiler(compiler);
9127      SLJIT_FREE(common->optimized_cbracket);      SLJIT_FREE(common->optimized_cbracket);
9128      SLJIT_FREE(common->private_data_ptrs);      SLJIT_FREE(common->private_data_ptrs);
9129        if (common->has_then)
9130          SLJIT_FREE(common->then_offsets);
9131      return;      return;
9132      }      }
9133    flush_stubs(common);    flush_stubs(common);
# Line 8875  if (common->getucd != NULL) Line 9236  if (common->getucd != NULL)
9236    
9237  SLJIT_FREE(common->optimized_cbracket);  SLJIT_FREE(common->optimized_cbracket);
9238  SLJIT_FREE(common->private_data_ptrs);  SLJIT_FREE(common->private_data_ptrs);
9239    if (common->has_then)
9240      SLJIT_FREE(common->then_offsets);
9241    
9242  executable_func = sljit_generate_code(compiler);  executable_func = sljit_generate_code(compiler);
9243  executable_size = sljit_get_generated_code_size(compiler);  executable_size = sljit_get_generated_code_size(compiler);
9244  sljit_free_compiler(compiler);  sljit_free_compiler(compiler);

Legend:
Removed from v.1275  
changed lines
  Added in v.1300

  ViewVC Help
Powered by ViewVC 1.1.5