/[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 1308 by zherczeg, Tue Apr 2 06:58:55 2013 UTC revision 1367 by zherczeg, Mon Oct 7 07:41:44 2013 UTC
# Line 168  typedef struct jit_arguments { Line 168  typedef struct jit_arguments {
168    pcre_uchar *mark_ptr;    pcre_uchar *mark_ptr;
169    void *callout_data;    void *callout_data;
170    /* Everything else after. */    /* Everything else after. */
171      pcre_uint32 limit_match;
172    int real_offset_count;    int real_offset_count;
173    int offset_count;    int offset_count;
   int call_limit;  
174    pcre_uint8 notbol;    pcre_uint8 notbol;
175    pcre_uint8 noteol;    pcre_uint8 noteol;
176    pcre_uint8 notempty;    pcre_uint8 notempty;
# Line 182  typedef struct executable_functions { Line 182  typedef struct executable_functions {
182    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
183    void *userdata;    void *userdata;
184    pcre_uint32 top_bracket;    pcre_uint32 top_bracket;
185      pcre_uint32 limit_match;
186    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
187  } executable_functions;  } executable_functions;
188    
# Line 210  typedef int (SLJIT_CALL *jit_function)(j Line 211  typedef int (SLJIT_CALL *jit_function)(j
211    
212  /* The following structure is the key data type for the recursive  /* The following structure is the key data type for the recursive
213  code generator. It is allocated by compile_matchingpath, and contains  code generator. It is allocated by compile_matchingpath, and contains
214  the aguments for compile_backtrackingpath. Must be the first member  the arguments for compile_backtrackingpath. Must be the first member
215  of its descendants. */  of its descendants. */
216  typedef struct backtrack_common {  typedef struct backtrack_common {
217    /* Concatenation stack. */    /* Concatenation stack. */
# Line 370  typedef struct compiler_common { Line 371  typedef struct compiler_common {
371    sljit_sw ctypes;    sljit_sw ctypes;
372    int digits[2 + MAX_RANGE_SIZE];    int digits[2 + MAX_RANGE_SIZE];
373    /* Named capturing brackets. */    /* Named capturing brackets. */
374    sljit_uw name_table;    pcre_uchar *name_table;
375    sljit_sw name_count;    sljit_sw name_count;
376    sljit_sw name_entry_size;    sljit_sw name_entry_size;
377    
# Line 463  typedef struct compare_context { Line 464  typedef struct compare_context {
464  #define STACK_TOP     SLJIT_SCRATCH_REG2  #define STACK_TOP     SLJIT_SCRATCH_REG2
465  #define STACK_LIMIT   SLJIT_SAVED_REG3  #define STACK_LIMIT   SLJIT_SAVED_REG3
466  #define ARGUMENTS     SLJIT_SAVED_EREG1  #define ARGUMENTS     SLJIT_SAVED_EREG1
467  #define CALL_COUNT    SLJIT_SAVED_EREG2  #define COUNT_MATCH   SLJIT_SAVED_EREG2
468  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1  #define RETURN_ADDR   SLJIT_TEMPORARY_EREG1
469    
470  /* Local space layout. */  /* Local space layout. */
# Line 474  typedef struct compare_context { Line 475  typedef struct compare_context {
475  #define POSSESSIVE0      (2 * sizeof(sljit_sw))  #define POSSESSIVE0      (2 * sizeof(sljit_sw))
476  #define POSSESSIVE1      (3 * sizeof(sljit_sw))  #define POSSESSIVE1      (3 * sizeof(sljit_sw))
477  /* Max limit of recursions. */  /* Max limit of recursions. */
478  #define CALL_LIMIT       (4 * sizeof(sljit_sw))  #define LIMIT_MATCH      (4 * sizeof(sljit_sw))
479  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
480  to characters. The vector data is divided into two groups: the first  to characters. The vector data is divided into two groups: the first
481  group contains the start / end character pointers, and the second is  group contains the start / end character pointers, and the second is
482  the start pointers when the end of the capturing group has not yet reached. */  the start pointers when the end of the capturing group has not yet reached. */
483  #define OVECTOR_START    (common->ovector_start)  #define OVECTOR_START    (common->ovector_start)
484  #define OVECTOR(i)       (OVECTOR_START + (i) * sizeof(sljit_sw))  #define OVECTOR(i)       (OVECTOR_START + (i) * (sljit_sw)sizeof(sljit_sw))
485  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * sizeof(sljit_sw))  #define OVECTOR_PRIV(i)  (common->cbra_ptr + (i) * (sljit_sw)sizeof(sljit_sw))
486  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])  #define PRIVATE_DATA(cc) (common->private_data_ptrs[(cc) - common->start])
487    
488  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
# Line 613  switch(*cc) Line 614  switch(*cc)
614    case OP_SCBRAPOS:    case OP_SCBRAPOS:
615    case OP_SCOND:    case OP_SCOND:
616    case OP_CREF:    case OP_CREF:
617    case OP_NCREF:    case OP_DNCREF:
618    case OP_RREF:    case OP_RREF:
619    case OP_NRREF:    case OP_DNRREF:
620    case OP_DEF:    case OP_DEF:
621    case OP_BRAZERO:    case OP_BRAZERO:
622    case OP_BRAMINZERO:    case OP_BRAMINZERO:
# Line 735  switch(*cc) Line 736  switch(*cc)
736    
737  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)  static BOOL check_opcode_types(compiler_common *common, pcre_uchar *cc, pcre_uchar *ccend)
738  {  {
739  pcre_uchar *name;  pcre_uchar *slot;
740  pcre_uchar *name2;  int i;
 int i, cbra_index;  
741    
742  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */  /* Calculate important variables (like stack size) and checks whether all opcodes are supported. */
743  while (cc < ccend)  while (cc < ccend)
# Line 776  while (cc < ccend) Line 776  while (cc < ccend)
776      cc += 1 + IMM2_SIZE;      cc += 1 + IMM2_SIZE;
777      break;      break;
778    
779      case OP_NCREF:      case OP_DNCREF:
780      cbra_index = GET2(cc, 1);      i = GET2(cc, 1 + IMM2_SIZE);
781      name = (pcre_uchar *)common->name_table;      slot = common->name_table + GET2(cc, 1) * common->name_entry_size;
782      name2 = name;      while (i-- > 0)
783      for (i = 0; i < common->name_count; i++)        {
784        {        common->optimized_cbracket[GET2(slot, 0)] = 0;
785        if (GET2(name, 0) == cbra_index) break;        slot += common->name_entry_size;
       name += common->name_entry_size;  
       }  
     SLJIT_ASSERT(i != common->name_count);  
   
     for (i = 0; i < common->name_count; i++)  
       {  
       if (STRCMP_UC_UC(name2 + IMM2_SIZE, name + IMM2_SIZE) == 0)  
         common->optimized_cbracket[GET2(name2, 0)] = 0;  
       name2 += common->name_entry_size;  
786        }        }
787      cc += 1 + IMM2_SIZE;      cc += 1 + 2 * IMM2_SIZE;
788      break;      break;
789    
790      case OP_RECURSE:      case OP_RECURSE:
# Line 892  pcre_uchar *next; Line 883  pcre_uchar *next;
883  pcre_uchar *next_end;  pcre_uchar *next_end;
884  pcre_uchar *max_end;  pcre_uchar *max_end;
885  pcre_uchar type;  pcre_uchar type;
886  sljit_uw length = end - begin;  sljit_sw length = end - begin;
887  int min, max, i;  int min, max, i;
888    
889  /* Detect fixed iterations first. */  /* Detect fixed iterations first. */
# Line 2021  while (list_item) Line 2012  while (list_item)
2012  common->stubs = NULL;  common->stubs = NULL;
2013  }  }
2014    
2015  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2016  {  {
2017  DEFINE_COMPILER;  DEFINE_COMPILER;
2018    
2019  OP2(SLJIT_SUB | SLJIT_SET_E, CALL_COUNT, 0, CALL_COUNT, 0, SLJIT_IMM, 1);  OP2(SLJIT_SUB | SLJIT_SET_E, COUNT_MATCH, 0, COUNT_MATCH, 0, SLJIT_IMM, 1);
2020  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2021  }  }
2022    
# Line 2372  return (bit < 256) ? ((0 << 8) | bit) : Line 2363  return (bit < 256) ? ((0 << 8) | bit) :
2363    
2364  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2365  {  {
2366  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2367  DEFINE_COMPILER;  DEFINE_COMPILER;
2368  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2369    
# Line 4315  while (*cc != XCL_END) Line 4306  while (*cc != XCL_END)
4306    
4307        case PT_SPACE:        case PT_SPACE:
4308        case PT_PXSPACE:        case PT_PXSPACE:
       if (*cc == PT_SPACE)  
         {  
         OP1(SLJIT_MOV, TMP2, 0, SLJIT_IMM, 0);  
         jump = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, 11 - charoffset);  
         }  
4309        SET_CHAR_OFFSET(9);        SET_CHAR_OFFSET(9);
4310        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 13 - 9);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, 13 - 9);
4311        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);        OP_FLAGS(SLJIT_MOV, TMP2, 0, SLJIT_UNUSED, 0, SLJIT_C_LESS_EQUAL);
       if (*cc == PT_SPACE)  
         JUMPHERE(jump);  
4312    
4313        SET_TYPE_OFFSET(ucp_Zl);        SET_TYPE_OFFSET(ucp_Zl);
4314        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl);        OP2(SLJIT_SUB | SLJIT_SET_U, SLJIT_UNUSED, 0, typereg, 0, SLJIT_IMM, ucp_Zs - ucp_Zl);
# Line 5291  if (!minimize) Line 5275  if (!minimize)
5275    JUMPHERE(zerolength);    JUMPHERE(zerolength);
5276    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5277    
5278    decrease_call_count(common);    count_match(common);
5279    return cc;    return cc;
5280    }    }
5281    
# Line 5330  if (jump != NULL) Line 5314  if (jump != NULL)
5314    JUMPHERE(jump);    JUMPHERE(jump);
5315  JUMPHERE(zerolength);  JUMPHERE(zerolength);
5316    
5317  decrease_call_count(common);  count_match(common);
5318  return cc;  return cc;
5319  }  }
5320    
# Line 5900  common->accept = save_accept; Line 5884  common->accept = save_accept;
5884  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
5885  }  }
5886    
 static sljit_sw SLJIT_CALL do_searchovector(sljit_uw refno, sljit_sw* locals, pcre_uchar *name_table)  
 {  
 int condition = FALSE;  
 pcre_uchar *slotA = name_table;  
 pcre_uchar *slotB;  
 sljit_sw name_count = locals[LOCALS0 / sizeof(sljit_sw)];  
 sljit_sw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];  
 sljit_sw no_capture;  
 int i;  
   
 locals += refno & 0xff;  
 refno >>= 8;  
 no_capture = locals[1];  
   
 for (i = 0; i < name_count; i++)  
   {  
   if (GET2(slotA, 0) == refno) break;  
   slotA += name_entry_size;  
   }  
   
 if (i < name_count)  
   {  
   /* Found a name for the number - there can be only one; duplicate names  
   for different numbers are allowed, but not vice versa. First scan down  
   for duplicates. */  
   
   slotB = slotA;  
   while (slotB > name_table)  
     {  
     slotB -= name_entry_size;  
     if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)  
       {  
       condition = locals[GET2(slotB, 0) << 1] != no_capture;  
       if (condition) break;  
       }  
     else break;  
     }  
   
   /* Scan up for duplicates */  
   if (!condition)  
     {  
     slotB = slotA;  
     for (i++; i < name_count; i++)  
       {  
       slotB += name_entry_size;  
       if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)  
         {  
         condition = locals[GET2(slotB, 0) << 1] != no_capture;  
         if (condition) break;  
         }  
       else break;  
       }  
     }  
   }  
 return condition;  
 }  
   
 static sljit_sw SLJIT_CALL do_searchgroups(sljit_uw recno, sljit_uw* locals, pcre_uchar *name_table)  
 {  
 int condition = FALSE;  
 pcre_uchar *slotA = name_table;  
 pcre_uchar *slotB;  
 sljit_uw name_count = locals[LOCALS0 / sizeof(sljit_sw)];  
 sljit_uw name_entry_size = locals[LOCALS1 / sizeof(sljit_sw)];  
 sljit_uw group_num = locals[POSSESSIVE0 / sizeof(sljit_sw)];  
 sljit_uw i;  
   
 for (i = 0; i < name_count; i++)  
   {  
   if (GET2(slotA, 0) == recno) break;  
   slotA += name_entry_size;  
   }  
   
 if (i < name_count)  
   {  
   /* Found a name for the number - there can be only one; duplicate  
   names for different numbers are allowed, but not vice versa. First  
   scan down for duplicates. */  
   
   slotB = slotA;  
   while (slotB > name_table)  
     {  
     slotB -= name_entry_size;  
     if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)  
       {  
       condition = GET2(slotB, 0) == group_num;  
       if (condition) break;  
       }  
     else break;  
     }  
   
   /* Scan up for duplicates */  
   if (!condition)  
     {  
     slotB = slotA;  
     for (i++; i < name_count; i++)  
       {  
       slotB += name_entry_size;  
       if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)  
         {  
         condition = GET2(slotB, 0) == group_num;  
         if (condition) break;  
         }  
       else break;  
       }  
     }  
   }  
 return condition;  
 }  
   
5887  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)  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)
5888  {  {
5889  DEFINE_COMPILER;  DEFINE_COMPILER;
# Line 6142  backtrack_common *backtrack; Line 6016  backtrack_common *backtrack;
6016  pcre_uchar opcode;  pcre_uchar opcode;
6017  int private_data_ptr = 0;  int private_data_ptr = 0;
6018  int offset = 0;  int offset = 0;
6019  int stacksize;  int i, stacksize;
6020  int repeat_ptr = 0, repeat_length = 0;  int repeat_ptr = 0, repeat_length = 0;
6021  int repeat_type = 0, repeat_count = 0;  int repeat_type = 0, repeat_count = 0;
6022  pcre_uchar *ccbegin;  pcre_uchar *ccbegin;
6023  pcre_uchar *matchingpath;  pcre_uchar *matchingpath;
6024    pcre_uchar *slot;
6025  pcre_uchar bra = OP_BRA;  pcre_uchar bra = OP_BRA;
6026  pcre_uchar ket;  pcre_uchar ket;
6027  assert_backtrack *assert;  assert_backtrack *assert;
# Line 6196  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket Line 6071  SLJIT_ASSERT(!((bra == OP_BRAZERO && ket
6071  cc += GET(cc, 1);  cc += GET(cc, 1);
6072    
6073  has_alternatives = *cc == OP_ALT;  has_alternatives = *cc == OP_ALT;
6074  if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND))  if (SLJIT_UNLIKELY(opcode == OP_COND || opcode == OP_SCOND))
6075    {    has_alternatives = (*matchingpath == OP_RREF || *matchingpath == OP_DNRREF) ? FALSE : TRUE;
   has_alternatives = (*matchingpath == OP_RREF) ? FALSE : TRUE;  
   if (*matchingpath == OP_NRREF)  
     {  
     stacksize = GET2(matchingpath, 1);  
     if (common->currententry == NULL || stacksize == RREF_ANY)  
       has_alternatives = FALSE;  
     else if (common->currententry->start == 0)  
       has_alternatives = stacksize != 0;  
     else  
       has_alternatives = stacksize != (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);  
     }  
   }  
6076    
6077  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))  if (SLJIT_UNLIKELY(opcode == OP_COND) && (*cc == OP_KETRMAX || *cc == OP_KETRMIN))
6078    opcode = OP_SCOND;    opcode = OP_SCOND;
# Line 6446  if (opcode == OP_COND || opcode == OP_SC Line 6309  if (opcode == OP_COND || opcode == OP_SC
6309        CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(matchingpath, 1) << 1), SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));        CMP(SLJIT_C_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(matchingpath, 1) << 1), SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1)));
6310      matchingpath += 1 + IMM2_SIZE;      matchingpath += 1 + IMM2_SIZE;
6311      }      }
6312    else if (*matchingpath == OP_NCREF)    else if (*matchingpath == OP_DNCREF)
6313      {      {
6314      SLJIT_ASSERT(has_alternatives);      SLJIT_ASSERT(has_alternatives);
     stacksize = GET2(matchingpath, 1);  
     jump = CMP(SLJIT_C_NOT_EQUAL, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(stacksize << 1), SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));  
   
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);  
     OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);  
     OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, (stacksize << 8) | (common->ovector_start / sizeof(sljit_sw)));  
     GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, 0);  
     OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);  
     sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchovector));  
     OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);  
     add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0));  
6315    
6316      JUMPHERE(jump);      i = GET2(matchingpath, 1 + IMM2_SIZE);
6317      matchingpath += 1 + IMM2_SIZE;      slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;
6318        OP1(SLJIT_MOV, TMP3, 0, STR_PTR, 0);
6319        OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(1));
6320        OP2(SLJIT_SUB | SLJIT_SET_E, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
6321        slot += common->name_entry_size;
6322        i--;
6323        while (i-- > 0)
6324          {
6325          OP2(SLJIT_SUB, STR_PTR, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), OVECTOR(GET2(slot, 0) << 1), TMP1, 0);
6326          OP2(SLJIT_OR | SLJIT_SET_E, TMP2, 0, TMP2, 0, STR_PTR, 0);
6327          slot += common->name_entry_size;
6328          }
6329        OP1(SLJIT_MOV, STR_PTR, 0, TMP3, 0);
6330        add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), JUMP(SLJIT_C_ZERO));
6331        matchingpath += 1 + 2 * IMM2_SIZE;
6332      }      }
6333    else if (*matchingpath == OP_RREF || *matchingpath == OP_NRREF)    else if (*matchingpath == OP_RREF || *matchingpath == OP_DNRREF)
6334      {      {
6335      /* Never has other case. */      /* Never has other case. */
6336      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;      BACKTRACK_AS(bracket_backtrack)->u.condfailed = NULL;
6337        SLJIT_ASSERT(!has_alternatives);
6338    
6339      stacksize = GET2(matchingpath, 1);      if (*matchingpath == OP_RREF)
     if (common->currententry == NULL)  
       stacksize = 0;  
     else if (stacksize == RREF_ANY)  
       stacksize = 1;  
     else if (common->currententry->start == 0)  
       stacksize = stacksize == 0;  
     else  
       stacksize = stacksize == (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);  
   
     if (*matchingpath == OP_RREF || stacksize || common->currententry == NULL)  
6340        {        {
6341        SLJIT_ASSERT(!has_alternatives);        stacksize = GET2(matchingpath, 1);
6342          if (common->currententry == NULL)
6343            stacksize = 0;
6344          else if (stacksize == RREF_ANY)
6345            stacksize = 1;
6346          else if (common->currententry->start == 0)
6347            stacksize = stacksize == 0;
6348          else
6349            stacksize = stacksize == (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6350    
6351        if (stacksize != 0)        if (stacksize != 0)
6352          matchingpath += 1 + IMM2_SIZE;          matchingpath += 1 + IMM2_SIZE;
6353          }
6354        else
6355          {
6356          if (common->currententry == NULL || common->currententry->start == 0)
6357            stacksize = 0;
6358        else        else
6359          {          {
6360            stacksize = GET2(matchingpath, 1 + IMM2_SIZE);
6361            slot = common->name_table + GET2(matchingpath, 1) * common->name_entry_size;
6362            i = (int)GET2(common->start, common->currententry->start + 1 + LINK_SIZE);
6363            while (stacksize > 0)
6364              {
6365              if (GET2(slot, 0) == i)
6366                break;
6367              slot += common->name_entry_size;
6368              stacksize--;
6369              }
6370            }
6371    
6372          if (stacksize != 0)
6373            matchingpath += 1 + 2 * IMM2_SIZE;
6374          }
6375    
6376          /* The stacksize == 0 is a common "else" case. */
6377          if (stacksize == 0)
6378            {
6379          if (*cc == OP_ALT)          if (*cc == OP_ALT)
6380            {            {
6381            matchingpath = cc + 1 + LINK_SIZE;            matchingpath = cc + 1 + LINK_SIZE;
# Line 6495  if (opcode == OP_COND || opcode == OP_SC Line 6384  if (opcode == OP_COND || opcode == OP_SC
6384          else          else
6385            matchingpath = cc;            matchingpath = cc;
6386          }          }
       }  
     else  
       {  
       SLJIT_ASSERT(has_alternatives);  
   
       stacksize = GET2(matchingpath, 1);  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1, STACK_TOP, 0);  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS0, SLJIT_IMM, common->name_count);  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LOCALS1, SLJIT_IMM, common->name_entry_size);  
       OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0, SLJIT_IMM, GET2(common->start, common->currententry->start + 1 + LINK_SIZE));  
       OP1(SLJIT_MOV, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, stacksize);  
       GET_LOCAL_BASE(SLJIT_SCRATCH_REG2, 0, 0);  
       OP1(SLJIT_MOV, SLJIT_SCRATCH_REG3, 0, SLJIT_IMM, common->name_table);  
       sljit_emit_ijump(compiler, SLJIT_CALL3, SLJIT_IMM, SLJIT_FUNC_OFFSET(do_searchgroups));  
       OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE1);  
       add_jump(compiler, &(BACKTRACK_AS(bracket_backtrack)->u.condfailed), CMP(SLJIT_C_EQUAL, SLJIT_SCRATCH_REG1, 0, SLJIT_IMM, 0));  
       matchingpath += 1 + IMM2_SIZE;  
       }  
6387      }      }
6388    else    else
6389      {      {
# Line 6663  if (bra == OP_BRAMINZERO) Line 6534  if (bra == OP_BRAMINZERO)
6534    }    }
6535    
6536  if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)  if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)
6537    decrease_call_count(common);    count_match(common);
6538    
6539  /* Skip the other alternatives. */  /* Skip the other alternatives. */
6540  while (*cc == OP_ALT)  while (*cc == OP_ALT)
# Line 6950  if (!zero) Line 6821  if (!zero)
6821    
6822  /* None of them matched. */  /* None of them matched. */
6823  set_jumps(emptymatch, LABEL());  set_jumps(emptymatch, LABEL());
6824  decrease_call_count(common);  count_match(common);
6825  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
6826  }  }
6827    
# Line 7260  switch(opcode) Line 7131  switch(opcode)
7131    break;    break;
7132    }    }
7133    
7134  decrease_call_count(common);  count_match(common);
7135  return end;  return end;
7136  }  }
7137    
# Line 7587  while (cc < ccend) Line 7458  while (cc < ccend)
7458        }        }
7459      BACKTRACK_AS(braminzero_backtrack)->matchingpath = LABEL();      BACKTRACK_AS(braminzero_backtrack)->matchingpath = LABEL();
7460      if (cc[1] > OP_ASSERTBACK_NOT)      if (cc[1] > OP_ASSERTBACK_NOT)
7461        decrease_call_count(common);        count_match(common);
7462      break;      break;
7463    
7464      case OP_ONCE:      case OP_ONCE:
# Line 8225  if (has_alternatives) Line 8096  if (has_alternatives)
8096          return;          return;
8097        }        }
8098    
8099      /* Instructions after the current alternative is succesfully matched. */      /* Instructions after the current alternative is successfully matched. */
8100      /* There is a similar code in compile_bracket_matchingpath. */      /* There is a similar code in compile_bracket_matchingpath. */
8101      if (opcode == OP_ONCE)      if (opcode == OP_ONCE)
8102        match_once_common(common, ket, CURRENT_AS(bracket_backtrack)->u.framesize, private_data_ptr, has_alternatives, needs_control_head);        match_once_common(common, ket, CURRENT_AS(bracket_backtrack)->u.framesize, private_data_ptr, has_alternatives, needs_control_head);
# Line 8956  else Line 8827  else
8827  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  common->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
8828  common->ctypes = (sljit_sw)(tables + ctypes_offset);  common->ctypes = (sljit_sw)(tables + ctypes_offset);
8829  common->digits[0] = -2;  common->digits[0] = -2;
8830  common->name_table = (sljit_sw)((pcre_uchar *)re + re->name_table_offset);  common->name_table = ((pcre_uchar *)re) + re->name_table_offset;
8831  common->name_count = re->name_count;  common->name_count = re->name_count;
8832  common->name_entry_size = re->name_entry_size;  common->name_entry_size = re->name_entry_size;
8833  common->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;  common->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
# Line 8970  common->use_ucp = (re->options & PCRE_UC Line 8841  common->use_ucp = (re->options & PCRE_UC
8841  ccend = bracketend(rootbacktrack.cc);  ccend = bracketend(rootbacktrack.cc);
8842    
8843  /* Calculate the local space size on the stack. */  /* Calculate the local space size on the stack. */
8844  common->ovector_start = CALL_LIMIT + sizeof(sljit_sw);  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);
8845  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);
8846  if (!common->optimized_cbracket)  if (!common->optimized_cbracket)
8847    return;    return;
# Line 9102  OP1(SLJIT_MOV, TMP1, 0, SLJIT_SAVED_REG1 Line 8973  OP1(SLJIT_MOV, TMP1, 0, SLJIT_SAVED_REG1
8973  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));  OP1(SLJIT_MOV, STR_PTR, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
8974  OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, end));  OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, end));
8975  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, stack));  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, stack));
8976  OP1(SLJIT_MOV_SI, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, call_limit));  OP1(SLJIT_MOV_UI, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, limit_match));
8977  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, base));  OP1(SLJIT_MOV, STACK_TOP, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, base));
8978  OP1(SLJIT_MOV, STACK_LIMIT, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, limit));  OP1(SLJIT_MOV, STACK_LIMIT, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(struct sljit_stack, limit));
8979  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CALL_LIMIT, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LIMIT_MATCH, TMP1, 0);
8980    
8981  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
8982    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);
# Line 9147  if (common->req_char_ptr != 0) Line 9018  if (common->req_char_ptr != 0)
9018  /* Store the current STR_PTR in OVECTOR(0). */  /* Store the current STR_PTR in OVECTOR(0). */
9019  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);
9020  /* Copy the limit of allowed recursions. */  /* Copy the limit of allowed recursions. */
9021  OP1(SLJIT_MOV, CALL_COUNT, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), CALL_LIMIT);  OP1(SLJIT_MOV, COUNT_MATCH, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), LIMIT_MATCH);
9022  if (common->capture_last_ptr != 0)  if (common->capture_last_ptr != 0)
9023    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, -1);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), common->capture_last_ptr, SLJIT_IMM, -1);
9024    
# Line 9425  else Line 9296  else
9296      }      }
9297    memset(functions, 0, sizeof(executable_functions));    memset(functions, 0, sizeof(executable_functions));
9298    functions->top_bracket = (re->top_bracket + 1) * 2;    functions->top_bracket = (re->top_bracket + 1) * 2;
9299      functions->limit_match = (re->flags & PCRE_MLSET) != 0 ? re->limit_match : 0;
9300    extra->executable_jit = functions;    extra->executable_jit = functions;
9301    extra->flags |= PCRE_EXTRA_EXECUTABLE_JIT;    extra->flags |= PCRE_EXTRA_EXECUTABLE_JIT;
9302    }    }
# Line 9479  arguments.begin = subject; Line 9351  arguments.begin = subject;
9351  arguments.end = subject + length;  arguments.end = subject + length;
9352  arguments.mark_ptr = NULL;  arguments.mark_ptr = NULL;
9353  /* JIT decreases this value less frequently than the interpreter. */  /* JIT decreases this value less frequently than the interpreter. */
9354  arguments.call_limit = ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0) ? MATCH_LIMIT : extra_data->match_limit;  arguments.limit_match = ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0) ? MATCH_LIMIT : (pcre_uint32)(extra_data->match_limit);
9355    if (functions->limit_match != 0 && functions->limit_match < arguments.limit_match)
9356      arguments.limit_match = functions->limit_match;
9357  arguments.notbol = (options & PCRE_NOTBOL) != 0;  arguments.notbol = (options & PCRE_NOTBOL) != 0;
9358  arguments.noteol = (options & PCRE_NOTEOL) != 0;  arguments.noteol = (options & PCRE_NOTEOL) != 0;
9359  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
# Line 9570  arguments.begin = subject_ptr; Line 9444  arguments.begin = subject_ptr;
9444  arguments.end = subject_ptr + length;  arguments.end = subject_ptr + length;
9445  arguments.mark_ptr = NULL;  arguments.mark_ptr = NULL;
9446  /* JIT decreases this value less frequently than the interpreter. */  /* JIT decreases this value less frequently than the interpreter. */
9447  arguments.call_limit = ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0) ? MATCH_LIMIT : extra_data->match_limit;  arguments.limit_match = ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0) ? MATCH_LIMIT : (pcre_uint32)(extra_data->match_limit);
9448    if (functions->limit_match != 0 && functions->limit_match < arguments.limit_match)
9449      arguments.limit_match = functions->limit_match;
9450  arguments.notbol = (options & PCRE_NOTBOL) != 0;  arguments.notbol = (options & PCRE_NOTBOL) != 0;
9451  arguments.noteol = (options & PCRE_NOTEOL) != 0;  arguments.noteol = (options & PCRE_NOTEOL) != 0;
9452  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
# Line 9689  if (extra != NULL && Line 9565  if (extra != NULL &&
9565    }    }
9566  }  }
9567    
9568    #if defined COMPILE_PCRE8
9569    PCRE_EXP_DECL void
9570    pcre_jit_free_unused_memory(void)
9571    #elif defined COMPILE_PCRE16
9572    PCRE_EXP_DECL void
9573    pcre16_jit_free_unused_memory(void)
9574    #elif defined COMPILE_PCRE32
9575    PCRE_EXP_DECL void
9576    pcre32_jit_free_unused_memory(void)
9577    #endif
9578    {
9579    sljit_free_unused_memory_exec();
9580    }
9581    
9582  #else  /* SUPPORT_JIT */  #else  /* SUPPORT_JIT */
9583    
9584  /* These are dummy functions to avoid linking errors when JIT support is not  /* These are dummy functions to avoid linking errors when JIT support is not
# Line 9740  pcre32_assign_jit_stack(pcre32_extra *ex Line 9630  pcre32_assign_jit_stack(pcre32_extra *ex
9630  (void)userdata;  (void)userdata;
9631  }  }
9632    
9633    #if defined COMPILE_PCRE8
9634    PCRE_EXP_DECL void
9635    pcre_jit_free_unused_memory(void)
9636    #elif defined COMPILE_PCRE16
9637    PCRE_EXP_DECL void
9638    pcre16_jit_free_unused_memory(void)
9639    #elif defined COMPILE_PCRE32
9640    PCRE_EXP_DECL void
9641    pcre32_jit_free_unused_memory(void)
9642    #endif
9643    {
9644    }
9645    
9646  #endif  #endif
9647    
9648  /* End of pcre_jit_compile.c */  /* End of pcre_jit_compile.c */

Legend:
Removed from v.1308  
changed lines
  Added in v.1367

  ViewVC Help
Powered by ViewVC 1.1.5