/[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 1358 by zherczeg, Thu Aug 29 13:40:47 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 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 737  static BOOL check_opcode_types(compiler_ Line 738  static BOOL check_opcode_types(compiler_
738  {  {
739  pcre_uchar *name;  pcre_uchar *name;
740  pcre_uchar *name2;  pcre_uchar *name2;
741  int i, cbra_index;  unsigned int cbra_index;
742    int i;
743    
744  /* 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. */
745  while (cc < ccend)  while (cc < ccend)
# Line 892  pcre_uchar *next; Line 894  pcre_uchar *next;
894  pcre_uchar *next_end;  pcre_uchar *next_end;
895  pcre_uchar *max_end;  pcre_uchar *max_end;
896  pcre_uchar type;  pcre_uchar type;
897  sljit_uw length = end - begin;  sljit_sw length = end - begin;
898  int min, max, i;  int min, max, i;
899    
900  /* Detect fixed iterations first. */  /* Detect fixed iterations first. */
# Line 2021  while (list_item) Line 2023  while (list_item)
2023  common->stubs = NULL;  common->stubs = NULL;
2024  }  }
2025    
2026  static SLJIT_INLINE void decrease_call_count(compiler_common *common)  static SLJIT_INLINE void count_match(compiler_common *common)
2027  {  {
2028  DEFINE_COMPILER;  DEFINE_COMPILER;
2029    
2030  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);
2031  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));  add_jump(compiler, &common->calllimit, JUMP(SLJIT_C_ZERO));
2032  }  }
2033    
# Line 2372  return (bit < 256) ? ((0 << 8) | bit) : Line 2374  return (bit < 256) ? ((0 << 8) | bit) :
2374    
2375  static void check_partial(compiler_common *common, BOOL force)  static void check_partial(compiler_common *common, BOOL force)
2376  {  {
2377  /* Checks whether a partial matching is occured. Does not modify registers. */  /* Checks whether a partial matching is occurred. Does not modify registers. */
2378  DEFINE_COMPILER;  DEFINE_COMPILER;
2379  struct sljit_jump *jump = NULL;  struct sljit_jump *jump = NULL;
2380    
# Line 5291  if (!minimize) Line 5293  if (!minimize)
5293    JUMPHERE(zerolength);    JUMPHERE(zerolength);
5294    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();    BACKTRACK_AS(iterator_backtrack)->matchingpath = LABEL();
5295    
5296    decrease_call_count(common);    count_match(common);
5297    return cc;    return cc;
5298    }    }
5299    
# Line 5330  if (jump != NULL) Line 5332  if (jump != NULL)
5332    JUMPHERE(jump);    JUMPHERE(jump);
5333  JUMPHERE(zerolength);  JUMPHERE(zerolength);
5334    
5335  decrease_call_count(common);  count_match(common);
5336  return cc;  return cc;
5337  }  }
5338    
# Line 6663  if (bra == OP_BRAMINZERO) Line 6665  if (bra == OP_BRAMINZERO)
6665    }    }
6666    
6667  if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)  if ((ket != OP_KET && bra != OP_BRAMINZERO) || bra == OP_BRAZERO)
6668    decrease_call_count(common);    count_match(common);
6669    
6670  /* Skip the other alternatives. */  /* Skip the other alternatives. */
6671  while (*cc == OP_ALT)  while (*cc == OP_ALT)
# Line 6950  if (!zero) Line 6952  if (!zero)
6952    
6953  /* None of them matched. */  /* None of them matched. */
6954  set_jumps(emptymatch, LABEL());  set_jumps(emptymatch, LABEL());
6955  decrease_call_count(common);  count_match(common);
6956  return cc + 1 + LINK_SIZE;  return cc + 1 + LINK_SIZE;
6957  }  }
6958    
# Line 7260  switch(opcode) Line 7262  switch(opcode)
7262    break;    break;
7263    }    }
7264    
7265  decrease_call_count(common);  count_match(common);
7266  return end;  return end;
7267  }  }
7268    
# Line 7587  while (cc < ccend) Line 7589  while (cc < ccend)
7589        }        }
7590      BACKTRACK_AS(braminzero_backtrack)->matchingpath = LABEL();      BACKTRACK_AS(braminzero_backtrack)->matchingpath = LABEL();
7591      if (cc[1] > OP_ASSERTBACK_NOT)      if (cc[1] > OP_ASSERTBACK_NOT)
7592        decrease_call_count(common);        count_match(common);
7593      break;      break;
7594    
7595      case OP_ONCE:      case OP_ONCE:
# Line 8225  if (has_alternatives) Line 8227  if (has_alternatives)
8227          return;          return;
8228        }        }
8229    
8230      /* Instructions after the current alternative is succesfully matched. */      /* Instructions after the current alternative is successfully matched. */
8231      /* There is a similar code in compile_bracket_matchingpath. */      /* There is a similar code in compile_bracket_matchingpath. */
8232      if (opcode == OP_ONCE)      if (opcode == OP_ONCE)
8233        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 8970  common->use_ucp = (re->options & PCRE_UC Line 8972  common->use_ucp = (re->options & PCRE_UC
8972  ccend = bracketend(rootbacktrack.cc);  ccend = bracketend(rootbacktrack.cc);
8973    
8974  /* Calculate the local space size on the stack. */  /* Calculate the local space size on the stack. */
8975  common->ovector_start = CALL_LIMIT + sizeof(sljit_sw);  common->ovector_start = LIMIT_MATCH + sizeof(sljit_sw);
8976  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);  common->optimized_cbracket = (pcre_uint8 *)SLJIT_MALLOC(re->top_bracket + 1);
8977  if (!common->optimized_cbracket)  if (!common->optimized_cbracket)
8978    return;    return;
# Line 9102  OP1(SLJIT_MOV, TMP1, 0, SLJIT_SAVED_REG1 Line 9104  OP1(SLJIT_MOV, TMP1, 0, SLJIT_SAVED_REG1
9104  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));
9105  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));
9106  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));
9107  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));
9108  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));
9109  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));
9110  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), CALL_LIMIT, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), LIMIT_MATCH, TMP1, 0);
9111    
9112  if (mode == JIT_PARTIAL_SOFT_COMPILE)  if (mode == JIT_PARTIAL_SOFT_COMPILE)
9113    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 9149  if (common->req_char_ptr != 0)
9149  /* Store the current STR_PTR in OVECTOR(0). */  /* Store the current STR_PTR in OVECTOR(0). */
9150  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);
9151  /* Copy the limit of allowed recursions. */  /* Copy the limit of allowed recursions. */
9152  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);
9153  if (common->capture_last_ptr != 0)  if (common->capture_last_ptr != 0)
9154    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);
9155    
# Line 9425  else Line 9427  else
9427      }      }
9428    memset(functions, 0, sizeof(executable_functions));    memset(functions, 0, sizeof(executable_functions));
9429    functions->top_bracket = (re->top_bracket + 1) * 2;    functions->top_bracket = (re->top_bracket + 1) * 2;
9430      functions->limit_match = (re->flags & PCRE_MLSET) != 0 ? re->limit_match : 0;
9431    extra->executable_jit = functions;    extra->executable_jit = functions;
9432    extra->flags |= PCRE_EXTRA_EXECUTABLE_JIT;    extra->flags |= PCRE_EXTRA_EXECUTABLE_JIT;
9433    }    }
# Line 9479  arguments.begin = subject; Line 9482  arguments.begin = subject;
9482  arguments.end = subject + length;  arguments.end = subject + length;
9483  arguments.mark_ptr = NULL;  arguments.mark_ptr = NULL;
9484  /* JIT decreases this value less frequently than the interpreter. */  /* JIT decreases this value less frequently than the interpreter. */
9485  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);
9486    if (functions->limit_match != 0 && functions->limit_match < arguments.limit_match)
9487      arguments.limit_match = functions->limit_match;
9488  arguments.notbol = (options & PCRE_NOTBOL) != 0;  arguments.notbol = (options & PCRE_NOTBOL) != 0;
9489  arguments.noteol = (options & PCRE_NOTEOL) != 0;  arguments.noteol = (options & PCRE_NOTEOL) != 0;
9490  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
# Line 9570  arguments.begin = subject_ptr; Line 9575  arguments.begin = subject_ptr;
9575  arguments.end = subject_ptr + length;  arguments.end = subject_ptr + length;
9576  arguments.mark_ptr = NULL;  arguments.mark_ptr = NULL;
9577  /* JIT decreases this value less frequently than the interpreter. */  /* JIT decreases this value less frequently than the interpreter. */
9578  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);
9579    if (functions->limit_match != 0 && functions->limit_match < arguments.limit_match)
9580      arguments.limit_match = functions->limit_match;
9581  arguments.notbol = (options & PCRE_NOTBOL) != 0;  arguments.notbol = (options & PCRE_NOTBOL) != 0;
9582  arguments.noteol = (options & PCRE_NOTEOL) != 0;  arguments.noteol = (options & PCRE_NOTEOL) != 0;
9583  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;  arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
# Line 9689  if (extra != NULL && Line 9696  if (extra != NULL &&
9696    }    }
9697  }  }
9698    
9699    #if defined COMPILE_PCRE8
9700    PCRE_EXP_DECL void
9701    pcre_jit_free_unused_memory(void)
9702    #elif defined COMPILE_PCRE16
9703    PCRE_EXP_DECL void
9704    pcre16_jit_free_unused_memory(void)
9705    #elif defined COMPILE_PCRE32
9706    PCRE_EXP_DECL void
9707    pcre32_jit_free_unused_memory(void)
9708    #endif
9709    {
9710    sljit_free_unused_memory_exec();
9711    }
9712    
9713  #else  /* SUPPORT_JIT */  #else  /* SUPPORT_JIT */
9714    
9715  /* 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 9761  pcre32_assign_jit_stack(pcre32_extra *ex
9761  (void)userdata;  (void)userdata;
9762  }  }
9763    
9764    #if defined COMPILE_PCRE8
9765    PCRE_EXP_DECL void
9766    pcre_jit_free_unused_memory(void)
9767    #elif defined COMPILE_PCRE16
9768    PCRE_EXP_DECL void
9769    pcre16_jit_free_unused_memory(void)
9770    #elif defined COMPILE_PCRE32
9771    PCRE_EXP_DECL void
9772    pcre32_jit_free_unused_memory(void)
9773    #endif
9774    {
9775    }
9776    
9777  #endif  #endif
9778    
9779  /* End of pcre_jit_compile.c */  /* End of pcre_jit_compile.c */

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

  ViewVC Help
Powered by ViewVC 1.1.5