/[pcre]/code/branches/pcre16/pcre_jit_compile.c
ViewVC logotype

Diff of /code/branches/pcre16/pcre_jit_compile.c

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

revision 773 by zherczeg, Mon Nov 28 20:39:30 2011 UTC revision 774 by zherczeg, Thu Dec 1 06:08:45 2011 UTC
# Line 375  enum { Line 375  enum {
375  /* Max limit of recursions. */  /* Max limit of recursions. */
376  #define CALL_LIMIT       (5 * sizeof(sljit_w))  #define CALL_LIMIT       (5 * sizeof(sljit_w))
377  /* Last known position of the requested byte. */  /* Last known position of the requested byte. */
378  #define REQ_BYTE_PTR     (6 * sizeof(sljit_w))  #define REQ_CHAR_PTR     (6 * sizeof(sljit_w))
379  /* End pointer of the first line. */  /* End pointer of the first line. */
380  #define FIRSTLINE_END    (7 * sizeof(sljit_w))  #define FIRSTLINE_END    (7 * sizeof(sljit_w))
381  /* The output vector is stored on the stack, and contains pointers  /* The output vector is stored on the stack, and contains pointers
# Line 1279  if (common->utf8) Line 1279  if (common->utf8)
1279  else  else
1280  #endif  #endif
1281    c = *cc;    c = *cc;
1282  return common->fcc[c] != c;  return MAX_255(c) ? common->fcc[c] != c : FALSE;
1283  }  }
1284    
1285  static SLJIT_INLINE unsigned int char_othercase(compiler_common *common, unsigned int c)  static SLJIT_INLINE unsigned int char_othercase(compiler_common *common, unsigned int c)
# Line 1295  if (common->utf8 && c > 127) Line 1295  if (common->utf8 && c > 127)
1295  #endif  #endif
1296    }    }
1297  #endif  #endif
1298  return common->fcc[c];  return TABLE_GET(c, common->fcc, c);
1299  }  }
1300    
1301  static unsigned int char_get_othercase_bit(compiler_common *common, pcre_uchar* cc)  static unsigned int char_get_othercase_bit(compiler_common *common, pcre_uchar* cc)
# Line 1728  if (newlinecheck) Line 1728  if (newlinecheck)
1728  return mainloop;  return mainloop;
1729  }  }
1730    
1731  static SLJIT_INLINE void fast_forward_first_byte(compiler_common *common, pcre_uint16 firstbyte, BOOL firstline)  static SLJIT_INLINE void fast_forward_first_char(compiler_common *common, pcre_uchar firstchar, BOOL caseless, BOOL firstline)
1732  {  {
1733  DEFINE_COMPILER;  DEFINE_COMPILER;
1734  struct sljit_label *start;  struct sljit_label *start;
1735  struct sljit_jump *leave;  struct sljit_jump *leave;
1736  struct sljit_jump *found;  struct sljit_jump *found;
1737  pcre_uint16 oc, bit;  pcre_uchar oc, bit;
1738    
1739  if (firstline)  if (firstline)
1740    {    {
# Line 1744  if (firstline) Line 1744  if (firstline)
1744    
1745  start = LABEL();  start = LABEL();
1746  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);  leave = CMP(SLJIT_C_GREATER_EQUAL, STR_PTR, 0, STR_END, 0);
1747  OP1(SLJIT_MOV_UB, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);  OP1(MOV_UCHAR, TMP1, 0, SLJIT_MEM1(STR_PTR), 0);
1748    
1749  if ((firstbyte & REQ_CASELESS) == 0)  oc = firstchar;
1750    found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, firstbyte & 0xff);  if (caseless)
1751      oc = TABLE_GET(firstchar, common->fcc, firstchar);
1752    if (firstchar == oc)
1753      found = CMP(SLJIT_C_EQUAL, TMP1, 0, SLJIT_IMM, firstchar);
1754  else  else
1755    {    {
1756    firstbyte &= 0xff;    bit = firstchar ^ oc;
   oc = common->fcc[firstbyte];  
   bit = firstbyte ^ oc;  
1757    if (ispowerof2(bit))    if (ispowerof2(bit))
1758      {      {
1759      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP1, 0, SLJIT_IMM, bit);
1760      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, firstbyte | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, firstchar | bit);
1761      }      }
1762    else    else
1763      {      {
1764      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, firstbyte);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, firstchar);
1765      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);      COND_VALUE(SLJIT_MOV, TMP2, 0, SLJIT_C_EQUAL);
1766      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);      OP2(SLJIT_SUB | SLJIT_SET_E, SLJIT_UNUSED, 0, TMP1, 0, SLJIT_IMM, oc);
1767      COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);      COND_VALUE(SLJIT_OR | SLJIT_SET_E, TMP2, 0, SLJIT_C_EQUAL);
# Line 1915  if (firstline) Line 1916  if (firstline)
1916    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);    OP1(SLJIT_MOV, STR_END, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), POSSESSIVE0);
1917  }  }
1918    
1919  static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uint16 reqbyte, BOOL has_firstbyte)  static SLJIT_INLINE struct sljit_jump *search_requested_char(compiler_common *common, pcre_uchar reqchar, BOOL caseless, BOOL has_firstchar)
1920  {  {
1921  DEFINE_COMPILER;  DEFINE_COMPILER;
1922  struct sljit_label *loop;  struct sljit_label *loop;
# Line 1924  struct sljit_jump *alreadyfound; Line 1925  struct sljit_jump *alreadyfound;
1925  struct sljit_jump *found;  struct sljit_jump *found;
1926  struct sljit_jump *foundoc = NULL;  struct sljit_jump *foundoc = NULL;
1927  struct sljit_jump *notfound;  struct sljit_jump *notfound;
1928  pcre_uint16 oc, bit;  pcre_uchar oc, bit;
1929    
1930  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_BYTE_PTR);  OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_CHAR_PTR);
1931  OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, REQ_BYTE_MAX);  OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, REQ_BYTE_MAX);
1932  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);  toolong = CMP(SLJIT_C_LESS, TMP1, 0, STR_END, 0);
1933  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);  alreadyfound = CMP(SLJIT_C_LESS, STR_PTR, 0, TMP2, 0);
1934    
1935  if (has_firstbyte)  if (has_firstchar)
1936    OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, 1);    OP2(SLJIT_ADD, TMP1, 0, STR_PTR, 0, SLJIT_IMM, 1);
1937  else  else
1938    OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);    OP1(SLJIT_MOV, TMP1, 0, STR_PTR, 0);
# Line 1940  loop = LABEL(); Line 1941  loop = LABEL();
1941  notfound = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, STR_END, 0);  notfound = CMP(SLJIT_C_GREATER_EQUAL, TMP1, 0, STR_END, 0);
1942    
1943  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), 0);  OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP1), 0);
1944  if ((reqbyte & REQ_CASELESS) == 0)  oc = reqchar;
1945    found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte & 0xff);  if (caseless)
1946      oc = TABLE_GET(reqchar, common->fcc, reqchar);
1947    if (reqchar == oc)
1948      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqchar);
1949  else  else
1950    {    {
1951    reqbyte &= 0xff;    bit = reqchar ^ oc;
   oc = common->fcc[reqbyte];  
   bit = reqbyte ^ oc;  
1952    if (ispowerof2(bit))    if (ispowerof2(bit))
1953      {      {
1954      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);      OP2(SLJIT_OR, TMP2, 0, TMP2, 0, SLJIT_IMM, bit);
1955      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte | bit);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqchar | bit);
1956      }      }
1957    else    else
1958      {      {
1959      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqbyte);      found = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, reqchar);
1960      foundoc = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, oc);      foundoc = CMP(SLJIT_C_EQUAL, TMP2, 0, SLJIT_IMM, oc);
1961      }      }
1962    }    }
# Line 1964  JUMPTO(SLJIT_JUMP, loop); Line 1966  JUMPTO(SLJIT_JUMP, loop);
1966  JUMPHERE(found);  JUMPHERE(found);
1967  if (foundoc)  if (foundoc)
1968    JUMPHERE(foundoc);    JUMPHERE(foundoc);
1969  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_BYTE_PTR, TMP1, 0);  OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_CHAR_PTR, TMP1, 0);
1970  JUMPHERE(alreadyfound);  JUMPHERE(alreadyfound);
1971  JUMPHERE(toolong);  JUMPHERE(toolong);
1972  return notfound;  return notfound;
# Line 3092  switch(type) Line 3094  switch(type)
3094    
3095    case OP_CHAR:    case OP_CHAR:
3096    case OP_CHARI:    case OP_CHARI:
3097    length = IN_UCHARS(1);    length = 1;
3098  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
3099    if (common->utf8 && *cc >= 0xc0) length += PRIV(utf8_table4)[*cc & 0x3f];    if (common->utf8 && *cc >= 0xc0) length += PRIV(utf8_table4)[*cc & 0x3f];
3100  #endif  #endif
3101    if (type == OP_CHAR || !char_has_othercase(common, cc) || char_get_othercase_bit(common, cc) != 0)    if (type == OP_CHAR || !char_has_othercase(common, cc) || char_get_othercase_bit(common, cc) != 0)
3102      {      {
3103      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, length);      OP2(SLJIT_ADD, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(length));
3104      add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER, STR_PTR, 0, STR_END, 0));      add_jump(compiler, fallbacks, CMP(SLJIT_C_GREATER, STR_PTR, 0, STR_END, 0));
3105    
3106      context.length = length;      context.length = IN_UCHARS(length);
3107      context.sourcereg = -1;      context.sourcereg = -1;
3108  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED  #if defined SLJIT_UNALIGNED && SLJIT_UNALIGNED
3109      context.ucharptr = 0;      context.ucharptr = 0;
# Line 3307  if (context.length > 0) Line 3309  if (context.length > 0)
3309    context.ucharptr = 0;    context.ucharptr = 0;
3310  #endif  #endif
3311    do cc = byte_sequence_compare(common, *cc == OP_CHARI, cc + 1, &context, fallbacks); while (context.length > 0);    do cc = byte_sequence_compare(common, *cc == OP_CHARI, cc + 1, &context, fallbacks); while (context.length > 0);
 sljit_emit_op0(compiler, SLJIT_NOP);  
3312    return cc;    return cc;
3313    }    }
3314    
# Line 6291  sljit_emit_enter(compiler, 1, 5, 5, comm Line 6292  sljit_emit_enter(compiler, 1, 5, 5, comm
6292  /* Register init. */  /* Register init. */
6293  reset_ovector(common, (re->top_bracket + 1) * 2);  reset_ovector(common, (re->top_bracket + 1) * 2);
6294  if ((re->flags & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
6295    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_BYTE_PTR, SLJIT_TEMPORARY_REG1, 0);    OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_LOCALS_REG), REQ_CHAR_PTR, SLJIT_TEMPORARY_REG1, 0);
6296    
6297  OP1(SLJIT_MOV, ARGUMENTS, 0, SLJIT_GENERAL_REG1, 0);  OP1(SLJIT_MOV, ARGUMENTS, 0, SLJIT_GENERAL_REG1, 0);
6298  OP1(SLJIT_MOV, TMP1, 0, SLJIT_GENERAL_REG1, 0);  OP1(SLJIT_MOV, TMP1, 0, SLJIT_GENERAL_REG1, 0);
# Line 6309  if ((re->options & PCRE_ANCHORED) == 0) Line 6310  if ((re->options & PCRE_ANCHORED) == 0)
6310    mainloop = mainloop_entry(common, (re->flags & PCRE_HASCRORLF) != 0, (re->options & PCRE_FIRSTLINE) != 0);    mainloop = mainloop_entry(common, (re->flags & PCRE_HASCRORLF) != 0, (re->options & PCRE_FIRSTLINE) != 0);
6311    /* Forward search if possible. */    /* Forward search if possible. */
6312    if ((re->flags & PCRE_FIRSTSET) != 0)    if ((re->flags & PCRE_FIRSTSET) != 0)
6313      fast_forward_first_byte(common, re->first_byte, (re->options & PCRE_FIRSTLINE) != 0);      fast_forward_first_char(common, re->first_char, (re->flags & PCRE_FCH_CASELESS) != 0, (re->options & PCRE_FIRSTLINE) != 0);
6314    else if ((re->flags & PCRE_STARTLINE) != 0)    else if ((re->flags & PCRE_STARTLINE) != 0)
6315      fast_forward_newline(common, (re->options & PCRE_FIRSTLINE) != 0);      fast_forward_newline(common, (re->options & PCRE_FIRSTLINE) != 0);
6316    else if ((re->flags & PCRE_STARTLINE) == 0 && study != NULL && (study->flags & PCRE_STUDY_MAPPED) != 0)    else if ((re->flags & PCRE_STARTLINE) == 0 && study != NULL && (study->flags & PCRE_STUDY_MAPPED) != 0)
6317      fast_forward_start_bits(common, (sljit_uw)study->start_bits, (re->options & PCRE_FIRSTLINE) != 0);      fast_forward_start_bits(common, (sljit_uw)study->start_bits, (re->options & PCRE_FIRSTLINE) != 0);
6318    }    }
6319  if ((re->flags & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
6320    reqbyte_notfound = search_requested_char(common, re->req_byte, (re->flags & PCRE_FIRSTSET) != 0);    reqbyte_notfound = search_requested_char(common, re->req_char, (re->flags & PCRE_RCH_CASELESS) != 0, (re->flags & PCRE_FIRSTSET) != 0);
6321    
6322  /* Store the current STR_PTR in OVECTOR(0). */  /* Store the current STR_PTR in OVECTOR(0). */
6323  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);

Legend:
Removed from v.773  
changed lines
  Added in v.774

  ViewVC Help
Powered by ViewVC 1.1.5