Changeset 4357 for icGREP


Ignore:
Timestamp:
Dec 24, 2014, 12:59:05 PM (5 years ago)
Author:
cameron
Message:

Move non-ASCII byte class computation inside if-structure.

Location:
icGREP/icgrep-devel/icgrep
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.cpp

    r4337 r4357  
    4949
    5050pablo::Var * CC_Compiler::compileCC(const re::CC *cc) {
    51      return mCG.createVar(mCG.createAssign(cc->canonicalName(ByteClass), charset_expr(cc)));
     51     return compileCC(cc, mCG);
     52}
     53
     54pablo::Var * CC_Compiler::compileCC(const re::CC *cc, pablo::PabloBlock & pb) {
     55     return pb.createVar(pb.createAssign(cc->canonicalName(ByteClass), charset_expr(cc, pb)));
    5256}
    5357
     
    8488        }
    8589        else if (d && isa<CC>(d)) {
    86             name->setCompiled(compileCC(cast<CC>(d)));
     90            name->setCompiled(compileCC(cast<CC>(d), mCG));
    8791        }
    8892    }
     
    9599
    96100
    97 PabloAST * CC_Compiler::charset_expr(const CC * cc) {
     101PabloAST * CC_Compiler::charset_expr(const CC * cc, pablo::PabloBlock & pb) {
    98102    if (cc->empty()) {
    99         return mCG.createZeroes();
     103        return pb.createZeroes();
    100104    }
    101105    if (cc->size() > 2) {
     
    123127                lo &= (mask - 1);
    124128                hi |= (mask ^ (mask - 1));
    125                 PabloAST * expr = make_range(lo, hi);
     129                PabloAST * expr = make_range(lo, hi, pb);
    126130                PabloAST * bit0 = getBasisVar(0);
    127131                if ((lo & 1) == 0) {
    128                     bit0 = mCG.createNot(bit0);
     132                    bit0 = pb.createNot(bit0);
    129133                }
    130                 return mCG.createAnd(expr, bit0);
     134                return pb.createAnd(expr, bit0);
    131135            }
    132136        }
     
    134138    PabloAST * expr = nullptr;
    135139    for (const CharSetItem & item : *cc) {
    136         PabloAST * temp = char_or_range_expr(item.lo_codepoint, item.hi_codepoint);
    137         expr = (expr == nullptr) ? temp : mCG.createOr(expr, temp);
     140        PabloAST * temp = char_or_range_expr(item.lo_codepoint, item.hi_codepoint, pb);
     141        expr = (expr == nullptr) ? temp : pb.createOr(expr, temp);
    138142    }
    139143    return expr;
    140144}
    141145
    142 PabloAST * CC_Compiler::bit_pattern_expr(const unsigned pattern, unsigned selected_bits)
     146PabloAST * CC_Compiler::bit_pattern_expr(const unsigned pattern, unsigned selected_bits, pablo::PabloBlock & pb)
    143147{
    144148    if (selected_bits == 0) {
    145         return mCG.createOnes();
     149        return pb.createOnes();
    146150    }
    147151
     
    165169        else
    166170        {
    167             bit_terms.push_back(mCG.createOnes());
     171            bit_terms.push_back(pb.createOnes());
    168172        }
    169173        selected_bits &= ~test_bit;
     
    177181        for (auto i = 0; i < (bit_terms.size()/2); i++)
    178182        {
    179             new_terms.push_back(mCG.createAnd(bit_terms[(2 * i) + 1], bit_terms[2 * i]));
     183            new_terms.push_back(pb.createAnd(bit_terms[(2 * i) + 1], bit_terms[2 * i]));
    180184        }
    181185        if (bit_terms.size() % 2 == 1)
     
    188192}
    189193
    190 inline PabloAST * CC_Compiler::char_test_expr(const CodePointType ch)
    191 {
    192     return bit_pattern_expr(ch, mEncoding.getMask());
    193 }
    194 
    195 PabloAST * CC_Compiler::make_range(const CodePointType n1, const CodePointType n2)
     194inline PabloAST * CC_Compiler::char_test_expr(const CodePointType ch, pablo::PabloBlock & pb)
     195{
     196    return bit_pattern_expr(ch, mEncoding.getMask(), pb);
     197}
     198
     199PabloAST * CC_Compiler::make_range(const CodePointType n1, const CodePointType n2, pablo::PabloBlock & pb)
    196200{
    197201    CodePointType diff_count = 0;
     
    206210    const CodePointType mask0 = (static_cast<CodePointType>(1) << diff_count) - 1;
    207211
    208     PabloAST * common = bit_pattern_expr(n1 & ~mask0, mEncoding.getMask() ^ mask0);
     212    PabloAST * common = bit_pattern_expr(n1 & ~mask0, mEncoding.getMask() ^ mask0, pb);
    209213
    210214    if (diff_count == 0) return common;
     
    212216    const CodePointType mask1 = (static_cast<CodePointType>(1) << (diff_count - 1)) - 1;
    213217
    214     PabloAST* lo_test = GE_Range(diff_count - 1, n1 & mask1);
    215     PabloAST* hi_test = LE_Range(diff_count - 1, n2 & mask1);
    216 
    217     return mCG.createAnd(common, mCG.createSel(getBasisVar(diff_count - 1), hi_test, lo_test));
    218 }
    219 
    220 PabloAST * CC_Compiler::GE_Range(const unsigned N, const unsigned n) {
     218    PabloAST* lo_test = GE_Range(diff_count - 1, n1 & mask1, pb);
     219    PabloAST* hi_test = LE_Range(diff_count - 1, n2 & mask1, pb);
     220
     221    return pb.createAnd(common, pb.createSel(getBasisVar(diff_count - 1), hi_test, lo_test));
     222}
     223
     224PabloAST * CC_Compiler::GE_Range(const unsigned N, const unsigned n, pablo::PabloBlock & pb) {
    221225    if (N == 0) {
    222         return mCG.createOnes(); //Return a true literal.
     226        return pb.createOnes(); //Return a true literal.
    223227    }
    224228    else if (((N % 2) == 0) && ((n >> (N - 2)) == 0)) {
    225         return mCG.createOr(mCG.createOr(getBasisVar(N - 1), getBasisVar(N - 2)), GE_Range(N - 2, n));
     229        return pb.createOr(pb.createOr(getBasisVar(N - 1), getBasisVar(N - 2)), GE_Range(N - 2, n, pb));
    226230    }
    227231    else if (((N % 2) == 0) && ((n >> (N - 2)) == 3)) {
    228         return mCG.createAnd(mCG.createAnd(getBasisVar(N - 1), getBasisVar(N - 2)), GE_Range(N - 2, n - (3 << (N - 2))));
     232        return pb.createAnd(pb.createAnd(getBasisVar(N - 1), getBasisVar(N - 2)), GE_Range(N - 2, n - (3 << (N - 2)), pb));
    229233    }
    230234    else if (N >= 1)
     
    232236        int hi_bit = n & (1 << (N - 1));
    233237        int lo_bits = n - hi_bit;
    234         PabloAST * lo_range = GE_Range(N - 1, lo_bits);
     238        PabloAST * lo_range = GE_Range(N - 1, lo_bits, pb);
    235239        if (hi_bit == 0)
    236240        {
     
    240244              the value of GE_range(N-1), lo_range) is required.
    241245            */
    242             return mCG.createOr(getBasisVar(N - 1), lo_range);
     246            return pb.createOr(getBasisVar(N - 1), lo_range);
    243247        }
    244248        else
     
    248252              in the target for >= and GE_range(N-1, lo_bits) must also be true.
    249253            */
    250             return mCG.createAnd(getBasisVar(N - 1), lo_range);
     254            return pb.createAnd(getBasisVar(N - 1), lo_range);
    251255        }
    252256    }
     
    254258}
    255259
    256 PabloAST * CC_Compiler::LE_Range(const unsigned N, const unsigned n)
     260PabloAST * CC_Compiler::LE_Range(const unsigned N, const unsigned n, pablo::PabloBlock & pb)
    257261{
    258262    /*
     
    261265    */
    262266    if ((n + 1) == (1 << N)) {
    263         return mCG.createOnes(); //True.
     267        return pb.createOnes(); //True.
    264268    }
    265269    else {
    266         return mCG.createNot(GE_Range(N, n + 1));
    267     }
    268 }
    269 
    270 inline PabloAST * CC_Compiler::char_or_range_expr(const CodePointType lo, const CodePointType hi) {
     270        return pb.createNot(GE_Range(N, n + 1, pb));
     271    }
     272}
     273
     274inline PabloAST * CC_Compiler::char_or_range_expr(const CodePointType lo, const CodePointType hi, pablo::PabloBlock & pb) {
    271275    if (lo == hi) {
    272         return char_test_expr(lo);
     276        return char_test_expr(lo, pb);
    273277    }
    274278    else if (lo < hi) {
    275         return make_range(lo, hi);
     279        return make_range(lo, hi, pb);
    276280    }
    277281    throw std::runtime_error(std::string("Invalid Character Set Range: [") + std::to_string(lo) + "," + std::to_string(hi) + "]");
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.h

    r4337 r4357  
    2828    std::vector<pablo::Var *> getBasisBits(const CC_NameMap & nameMap);
    2929
     30    pablo::Var * compileCC(const re::CC *cc, pablo::PabloBlock & pb);
     31
    3032    pablo::Var * compileCC(const re::CC *cc);
    3133
     
    3436private:
    3537    pablo::Var * getBasisVar(const int n) const;
    36     pablo::PabloAST * bit_pattern_expr(const unsigned pattern, unsigned selected_bits);
    37     pablo::PabloAST * char_test_expr(const re::CodePointType ch);
    38     pablo::PabloAST * make_range(const re::CodePointType n1, const re::CodePointType n2);
    39     pablo::PabloAST * GE_Range(const unsigned N, const unsigned n);
    40     pablo::PabloAST * LE_Range(const unsigned N, const unsigned n);
    41     pablo::PabloAST * char_or_range_expr(const re::CodePointType lo, const re::CodePointType hi);
    42     pablo::PabloAST * charset_expr(const re::CC *cc);
     38    pablo::PabloAST * bit_pattern_expr(const unsigned pattern, unsigned selected_bits, pablo::PabloBlock & pb);
     39    pablo::PabloAST * char_test_expr(const re::CodePointType ch, pablo::PabloBlock & pb);
     40    pablo::PabloAST * make_range(const re::CodePointType n1, const re::CodePointType n2, pablo::PabloBlock & pb);
     41    pablo::PabloAST * GE_Range(const unsigned N, const unsigned n, pablo::PabloBlock & pb);
     42    pablo::PabloAST * LE_Range(const unsigned N, const unsigned n, pablo::PabloBlock & pb);
     43    pablo::PabloAST * char_or_range_expr(const re::CodePointType lo, const re::CodePointType hi, pablo::PabloBlock & pb);
     44    pablo::PabloAST * charset_expr(const re::CC *cc, pablo::PabloBlock & pb);
    4345
    4446    void computeVariableConstraints();
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r4352 r4357  
    8080    mLineFeed = mCG.createVar(LF);
    8181    PabloAST * CR = ccc.compileCC(makeCC(0x0D));
     82    PabloAST * LF_VT_FF_CR = ccc.compileCC(makeCC(0x0A, 0x0D));
    8283#ifndef USE_IF_FOR_CRLF
    8384    mCRLF = mCG.createAnd(mCG.createAdvance(CR, 1), mLineFeed);
     
    9091#endif
    9192   
    92     PabloAST * LF_VT_FF_CR = ccc.compileCC(makeCC(0x0A, 0x0D));
     93#ifndef USE_IF_FOR_NONFINAL
    9394    PabloAST * u8single = ccc.compileCC(makeCC(0x00, 0x7F));
    9495    PabloAST * u8pfx2 = ccc.compileCC(makeCC(0xC2, 0xDF));
     
    9798    PabloAST * u8pfx = mCG.createOr(mCG.createOr(u8pfx2, u8pfx3), u8pfx4);
    9899    mInitial = mCG.createVar(mCG.createAssign(initial, mCG.createOr(u8pfx, u8single)));
    99 
    100     #ifndef USE_IF_FOR_NONFINAL
     100   
    101101    PabloAST * u8scope32 = mCG.createAdvance(u8pfx3, 1);
    102102    PabloAST * u8scope42 = mCG.createAdvance(u8pfx4, 1);
     
    108108    mNonFinal = mCG.createVar(mCG.createAssign(nonfinal, mCG.createOr(mCG.createOr(u8pfx, u8scope32), mCG.createOr(u8scope42, u8scope43))));
    109109    mUnicodeLineBreak = mCG.createAnd(LB_chars, mCG.createNot(mCRLF));  // count the CR, but not CRLF
    110     #endif
    111     #ifdef USE_IF_FOR_NONFINAL
     110#endif
     111
     112#ifdef USE_IF_FOR_NONFINAL
     113    PabloAST * u8single = ccc.compileCC(makeCC(0x00, 0x7F));
     114    PabloAST * u8pfx = ccc.compileCC(makeCC(0xC0, 0xFF));
    112115    PabloBlock it(mCG);
     116    PabloAST * u8pfx2 = ccc.compileCC(makeCC(0xC2, 0xDF), it);
     117    PabloAST * u8pfx3 = ccc.compileCC(makeCC(0xE0, 0xEF), it);
     118    PabloAST * u8pfx4 = ccc.compileCC(makeCC(0xF0, 0xF4), it);
     119    Assign * valid_pfx = it.createAssign("valid_pfx", it.createOr(it.createOr(u8pfx2, u8pfx3), u8pfx4));
    113120    PabloAST * u8scope32 = it.createAdvance(u8pfx3, 1);
    114121    PabloAST * u8scope42 = it.createVar(it.createAssign("u8scope42", it.createAdvance(u8pfx4, 1)));
    115122    PabloAST * u8scope43 = it.createAdvance(u8scope42, 1);
    116     Assign * a = it.createAssign(nonfinal, it.createOr(it.createOr(u8pfx, u8scope32), it.createOr(u8scope42, u8scope43)));
    117     PabloAST * NEL = it.createAnd(it.createAdvance(ccc.compileCC(makeCC(0xC2)), 1), ccc.compileCC(makeCC(0x85)));
    118     PabloAST * E2_80 = it.createAnd(it.createAdvance(ccc.compileCC(makeCC(0xE2)), 1), ccc.compileCC(makeCC(0x80)));
    119     PabloAST * LS_PS = it.createAnd(it.createAdvance(E2_80, 1), ccc.compileCC(makeCC(0xA8,0xA9)));
     123    Assign * a_nonfinal = it.createAssign(nonfinal, it.createOr(it.createOr(u8pfx, u8scope32), it.createOr(u8scope42, u8scope43)));
     124    PabloAST * NEL = it.createAnd(it.createAdvance(ccc.compileCC(makeCC(0xC2), it), 1), ccc.compileCC(makeCC(0x85), it));
     125    PabloAST * E2_80 = it.createAnd(it.createAdvance(ccc.compileCC(makeCC(0xE2), it), 1), ccc.compileCC(makeCC(0x80), it));
     126    PabloAST * LS_PS = it.createAnd(it.createAdvance(E2_80, 1), ccc.compileCC(makeCC(0xA8,0xA9), it));
    120127    Assign * NEL_LS_PS = it.createAssign("NEL_LS_PS", it.createOr(NEL, LS_PS));
    121     mCG.createIf(u8pfx, std::move(std::vector<Assign *>{a, NEL_LS_PS}), std::move(it));
     128    mCG.createIf(u8pfx, std::move(std::vector<Assign *>{valid_pfx, a_nonfinal, NEL_LS_PS}), std::move(it));
    122129    PabloAST * LB_chars = mCG.createOr(LF_VT_FF_CR, mCG.createVar(NEL_LS_PS));
    123     mNonFinal = mCG.createVar(a);   
     130    mInitial = mCG.createVar(mCG.createAssign(initial, mCG.createOr(u8single, mCG.createVar(valid_pfx))));
     131    mNonFinal = mCG.createVar(a_nonfinal);   
    124132    mUnicodeLineBreak = mCG.createAnd(LB_chars, mCG.createNot(mCRLF));  // count the CR, but not CRLF
    125133    #endif
Note: See TracChangeset for help on using the changeset viewer.