/[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 1176 by ph10, Sat Oct 27 15:46:35 2012 UTC revision 1187 by zherczeg, Mon Oct 29 11:30:45 2012 UTC
# Line 170  typedef struct executable_functions { Line 170  typedef struct executable_functions {
170    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];    void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
171    PUBL(jit_callback) callback;    PUBL(jit_callback) callback;
172    void *userdata;    void *userdata;
173      pcre_uint32 top_bracket;
174    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];    sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
175  } executable_functions;  } executable_functions;
176    
# Line 8242  else Line 8243  else
8243      return;      return;
8244      }      }
8245    memset(functions, 0, sizeof(executable_functions));    memset(functions, 0, sizeof(executable_functions));
8246      functions->top_bracket = (re->top_bracket + 1) * 2;
8247    extra->executable_jit = functions;    extra->executable_jit = functions;
8248    extra->flags |= PCRE_EXTRA_EXECUTABLE_JIT;    extra->flags |= PCRE_EXTRA_EXECUTABLE_JIT;
8249    }    }
# Line 8269  return convert_executable_func.call_exec Line 8271  return convert_executable_func.call_exec
8271  }  }
8272    
8273  int  int
8274  PRIV(jit_exec)(const REAL_PCRE *re, const PUBL(extra) *extra_data, const pcre_uchar *subject,  PRIV(jit_exec)(const PUBL(extra) *extra_data, const pcre_uchar *subject,
8275    int length, int start_offset, int options, int *offsets, int offsetcount)    int length, int start_offset, int options, int *offsets, int offsetcount)
8276  {  {
8277  executable_functions *functions = (executable_functions *)extra_data->executable_jit;  executable_functions *functions = (executable_functions *)extra_data->executable_jit;
# Line 8288  else if ((options & PCRE_PARTIAL_SOFT) ! Line 8290  else if ((options & PCRE_PARTIAL_SOFT) !
8290    mode = JIT_PARTIAL_SOFT_COMPILE;    mode = JIT_PARTIAL_SOFT_COMPILE;
8291    
8292  if (functions->executable_funcs[mode] == NULL)  if (functions->executable_funcs[mode] == NULL)
8293    return PCRE_ERROR_NULL;    return PCRE_ERROR_JIT_BADOPTION;
8294    
8295  /* Sanity checks should be handled by pcre_exec. */  /* Sanity checks should be handled by pcre_exec. */
 arguments.stack = NULL;  
8296  arguments.str = subject + start_offset;  arguments.str = subject + start_offset;
8297  arguments.begin = subject;  arguments.begin = subject;
8298  arguments.end = subject + length;  arguments.end = subject + length;
# Line 8312  gets the same result with and without JI Line 8313  gets the same result with and without JI
8313    
8314  if (offsetcount != 2)  if (offsetcount != 2)
8315    offsetcount = ((offsetcount - (offsetcount % 3)) * 2) / 3;    offsetcount = ((offsetcount - (offsetcount % 3)) * 2) / 3;
8316  maxoffsetcount = (re->top_bracket + 1) * 2;  maxoffsetcount = functions->top_bracket;
8317  if (offsetcount > maxoffsetcount)  if (offsetcount > maxoffsetcount)
8318    offsetcount = maxoffsetcount;    offsetcount = maxoffsetcount;
8319  arguments.offsetcount = offsetcount;  arguments.offsetcount = offsetcount;
# Line 8332  else Line 8333  else
8333    
8334  if (retval * 2 > offsetcount)  if (retval * 2 > offsetcount)
8335    retval = 0;    retval = 0;
8336    if ((extra_data->flags & PCRE_EXTRA_MARK) != 0)
8337      *(extra_data->mark) = arguments.mark_ptr;
8338    
8339    return retval;
8340    }
8341    
8342    #if defined COMPILE_PCRE8
8343    PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
8344    pcre_jit_exec(const pcre *argument_re, const pcre_extra *extra_data,
8345      PCRE_SPTR subject, int length, int start_offset, int options,
8346      int *offsets, int offsetcount, pcre_jit_stack *stack)
8347    #elif defined COMPILE_PCRE16
8348    PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
8349    pcre16_jit_exec(const pcre16 *argument_re, const pcre16_extra *extra_data,
8350      PCRE_SPTR16 subject, int length, int start_offset, int options,
8351      int *offsets, int offsetcount, pcre16_jit_stack *stack)
8352    #elif defined COMPILE_PCRE32
8353    PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
8354    pcre32_jit_exec(const pcre32 *argument_re, const pcre32_extra *extra_data,
8355      PCRE_SPTR32 subject, int length, int start_offset, int options,
8356      int *offsets, int offsetcount, pcre32_jit_stack *stack)
8357    #endif
8358    {
8359    pcre_uchar *subject_ptr = (pcre_uchar *)subject;
8360    executable_functions *functions = (executable_functions *)extra_data->executable_jit;
8361    union {
8362       void* executable_func;
8363       jit_function call_executable_func;
8364    } convert_executable_func;
8365    jit_arguments arguments;
8366    int maxoffsetcount;
8367    int retval;
8368    int mode = JIT_COMPILE;
8369    
8370    SLJIT_UNUSED_ARG(argument_re);
8371    
8372    /* Plausibility checks */
8373    if ((options & ~PUBLIC_JIT_EXEC_OPTIONS) != 0) return PCRE_ERROR_JIT_BADOPTION;
8374    
8375    if ((options & PCRE_PARTIAL_HARD) != 0)
8376      mode = JIT_PARTIAL_HARD_COMPILE;
8377    else if ((options & PCRE_PARTIAL_SOFT) != 0)
8378      mode = JIT_PARTIAL_SOFT_COMPILE;
8379    
8380    if (functions->executable_funcs[mode] == NULL)
8381      return PCRE_ERROR_JIT_BADOPTION;
8382    
8383    /* Sanity checks should be handled by pcre_exec. */
8384    arguments.stack = (struct sljit_stack *)stack;
8385    arguments.str = subject_ptr + start_offset;
8386    arguments.begin = subject_ptr;
8387    arguments.end = subject_ptr + length;
8388    arguments.mark_ptr = NULL;
8389    /* JIT decreases this value less frequently than the interpreter. */
8390    arguments.calllimit = ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0) ? MATCH_LIMIT : extra_data->match_limit;
8391    arguments.notbol = (options & PCRE_NOTBOL) != 0;
8392    arguments.noteol = (options & PCRE_NOTEOL) != 0;
8393    arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
8394    arguments.notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;
8395    arguments.offsets = offsets;
8396    
8397    /* pcre_exec() rounds offsetcount to a multiple of 3, and then uses only 2/3 of
8398    the output vector for storing captured strings, with the remainder used as
8399    workspace. We don't need the workspace here. For compatibility, we limit the
8400    number of captured strings in the same way as pcre_exec(), so that the user
8401    gets the same result with and without JIT. */
8402    
8403    if (offsetcount != 2)
8404      offsetcount = ((offsetcount - (offsetcount % 3)) * 2) / 3;
8405    maxoffsetcount = functions->top_bracket;
8406    if (offsetcount > maxoffsetcount)
8407      offsetcount = maxoffsetcount;
8408    arguments.offsetcount = offsetcount;
8409    
8410    convert_executable_func.executable_func = functions->executable_funcs[mode];
8411    retval = convert_executable_func.call_executable_func(&arguments);
8412    
8413    if (retval * 2 > offsetcount)
8414      retval = 0;
8415  if ((extra_data->flags & PCRE_EXTRA_MARK) != 0)  if ((extra_data->flags & PCRE_EXTRA_MARK) != 0)
8416    *(extra_data->mark) = arguments.mark_ptr;    *(extra_data->mark) = arguments.mark_ptr;
8417    

Legend:
Removed from v.1176  
changed lines
  Added in v.1187

  ViewVC Help
Powered by ViewVC 1.1.5