Ignore:
Timestamp:
Jun 29, 2015, 1:46:55 PM (4 years ago)
Author:
nmedfort
Message:

Preliminary changes to inclusion of UCD Compiler into the RE Compiler.

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/UCD/ucd_compiler.cpp

    r4617 r4622  
    423423 * @brief constructor
    424424 ** ------------------------------------------------------------------------------------------------------------- */
    425 UCDCompiler::UCDCompiler(PabloBlock & entry, const Encoding & encoding)
    426 : mCharacterClassCompiler(entry, encoding)
     425UCDCompiler::UCDCompiler(cc::CC_Compiler & ccCompiler)
     426: mCharacterClassCompiler(ccCompiler)
    427427, mSuffix(makeCC(0x80, 0xBF)) { }
    428428
  • icGREP/icgrep-devel/icgrep/UCD/ucd_compiler.hpp

    r4617 r4622  
    2121
    2222public:
    23     UCDCompiler(pablo::PabloBlock & entry, const Encoding & encoding);
     23    UCDCompiler(cc::CC_Compiler & ccCompiler);
    2424
    2525    PabloAST * generateWithDefaultIfHierarchy(const UnicodeSet & set, PabloBuilder & entry);
     
    5454
    5555private:
    56     cc::CC_Compiler         mCharacterClassCompiler;
     56    cc::CC_Compiler &       mCharacterClassCompiler;
    5757    CC * const              mSuffix;
    5858};
  • icGREP/icgrep-devel/icgrep/UCD/unicode_set.cpp

    r4621 r4622  
    112112        }
    113113    }
    114     out.flush();
    115114}
    116115
     
    151150    const auto e2 = other.quad_end();
    152151    for (auto i1 = quad_begin(), i2 = other.quad_begin(); i1 != e1 && i2 != e2; ) {
    153         const auto run1 = i1.getRun();
    154         const auto run2 = i2.getRun();
     152        const auto run1 = i1.run();
     153        const auto run2 = i2.run();
    155154        const auto n = std::min(lengthOf(run1), lengthOf(run2));
    156155        if (typeOf(run1) == typeOf(run2) && typeOf(run1) != Mixed) {
     
    161160        else if (typeOf(run1) == Full) {
    162161            for (unsigned i = 0; i != n; ++i, ++i2) {
    163                 append_quad(i2.getQuad(), quads, runs);
     162                append_quad(i2.quad(), quads, runs);
    164163            }
    165164            i1 += n;
     
    167166        else if (typeOf(run2) == Full) {
    168167            for (unsigned i = 0; i != n; ++i, ++i1) {
    169                 append_quad(i1.getQuad(), quads, runs);
     168                append_quad(i1.quad(), quads, runs);
    170169            }
    171170            i2 += n;
     
    173172        else {
    174173            for (unsigned i = 0; i != n; ++i, ++i1, ++i2) {
    175                 append_quad(i1.getQuad() & i2.getQuad(), quads, runs);
     174                append_quad(i1.quad() & i2.quad(), quads, runs);
    176175            }
    177176        }
     
    191190    auto i1 = quad_begin(), i2 = other.quad_begin();
    192191    for (; i1 != e1 && i2 != e2; ) {
    193         const auto run1 = i1.getRun();
    194         const auto run2 = i2.getRun();
     192        const auto run1 = i1.run();
     193        const auto run2 = i2.run();
    195194        const auto n = std::min(lengthOf(run1), lengthOf(run2));
    196195        if ((typeOf(run1) == Empty) && (typeOf(run2) == Empty)) {
     
    206205        else if (typeOf(run1) == Empty) {
    207206            for (unsigned i = 0; i != n; ++i, ++i2) {
    208                 append_quad(i2.getQuad(), quads, runs);
     207                append_quad(i2.quad(), quads, runs);
    209208            }
    210209            i1 += n;
     
    212211        else if (typeOf(run2) == Empty) {
    213212            for (unsigned i = 0; i != n; ++i, ++i1) {
    214                 append_quad(i1.getQuad(), quads, runs);
     213                append_quad(i1.quad(), quads, runs);
    215214            }
    216215            i2 += n;
     
    218217        else {
    219218            for (unsigned i = 0; i < n; ++i, ++i1, ++i2) {
    220                 append_quad(i1.getQuad() | i2.getQuad(), quads, runs);
     219                append_quad(i1.quad() | i2.quad(), quads, runs);
    221220            }
    222221        }
     
    235234    const auto e2 = other.quad_end();
    236235    for (auto i1 = quad_begin(), i2 = other.quad_begin(); i1 != e1 && i2 != e2; ) {
    237         const auto run1 = i1.getRun();
    238         const auto run2 = i2.getRun();
     236        const auto run1 = i1.run();
     237        const auto run2 = i2.run();
    239238        unsigned n = std::min(lengthOf(run1), lengthOf(run2));
    240239        if ((typeOf(run1) == Empty) || (typeOf(run2) == Full) || (typeOf(run1) == Full && typeOf(run2) == Empty)) {
     
    245244        else if (typeOf(run1) == Full) {
    246245            for (unsigned i = 0; i != n; ++i, ++i2) {
    247                 append_quad(FULL_QUAD_MASK ^ i2.getQuad(), quads, runs);
     246                append_quad(FULL_QUAD_MASK ^ i2.quad(), quads, runs);
    248247            }
    249248            i1 += n;
     
    251250        else if (typeOf(run2) == Empty) {
    252251            for (unsigned i = 0; i != n; ++i, ++i1) {
    253                 append_quad(i1.getQuad(), quads, runs);
     252                append_quad(i1.quad(), quads, runs);
    254253            }
    255254            i2 += n;
     
    257256        else {
    258257            for (unsigned i = 0; i != n; ++i, ++i1, ++i2) {
    259                 append_quad(i1.getQuad() &~ i2.getQuad(), quads, runs);
     258                append_quad(i1.quad() &~ i2.quad(), quads, runs);
    260259            }
    261260        }
     
    274273    const auto e2 = other.quad_end();
    275274    for (auto i1 = quad_begin(), i2 = other.quad_begin(); i1 != e1 && i2 != e2; ) {
    276         const auto run1 = i1.getRun();
    277         const auto run2 = i2.getRun();
     275        const auto run1 = i1.run();
     276        const auto run2 = i2.run();
    278277        unsigned n = std::min(lengthOf(run1), lengthOf(run2));
    279278        if (typeOf(run1) != Mixed && typeOf(run2) != Mixed) {
     
    284283        else if (typeOf(run1) == Empty) {
    285284            for (unsigned i = 0; i < n; ++i, ++i2) {
    286                 append_quad(i2.getQuad(), quads, runs);
     285                append_quad(i2.quad(), quads, runs);
    287286            }
    288287            i1 += n;
     
    290289        else if (typeOf(run2) == Empty) {
    291290            for (unsigned i = 0; i < n; ++i, ++i1) {
    292                 append_quad(i1.getQuad(), quads, runs);
     291                append_quad(i1.quad(), quads, runs);
    293292            }
    294293            i2 += n;
     
    296295        else if (typeOf(run1) == Full) {
    297296            for (unsigned i = 0; i < n; ++i, ++i2) {
    298                 append_quad(FULL_QUAD_MASK ^ i2.getQuad(), quads, runs);
     297                append_quad(FULL_QUAD_MASK ^ i2.quad(), quads, runs);
    299298            }
    300299            i1 += n;
     
    302301        else if (typeOf(run2) == Empty) {
    303302            for (unsigned i = 0; i < n; ++i, ++i1) {
    304                 append_quad(FULL_QUAD_MASK ^ i1.getQuad(), quads, runs);
     303                append_quad(FULL_QUAD_MASK ^ i1.quad(), quads, runs);
    305304            }
    306305            i2 += n;
     
    308307        else {
    309308            for (unsigned i = 0; i != n; ++i, ++i1, ++i2) {
    310                 append_quad(i1.getQuad() ^ i2.getQuad(), quads, runs);
     309                append_quad(i1.quad() ^ i2.quad(), quads, runs);
    311310            }
    312311        }
     
    331330    return true;
    332331}
    333 
    334332
    335333/** ------------------------------------------------------------------------------------------------------------- *
     
    420418            // If we found nothing in the quad, restart the loop.
    421419            if (found) {
    422                 // std::cerr << "Min: " << mMinCodePoint << " = " << mBaseCodePoint << " + " << mQuadOffset << std::endl;
    423420                break;
    424421            }
     
    461458            // If we found nothing in the quad, restart the loop.
    462459            if (found) {
    463                 // std::cerr << "Max: " << mMinCodePoint << " = " << mBaseCodePoint << " + " << mQuadOffset << std::endl;
    464460                break;
    465461            }
  • icGREP/icgrep-devel/icgrep/UCD/unicode_set.h

    r4621 r4622  
    4444    using length_t = uint16_t;
    4545    using run_t = std::pair<run_type_t, length_t>;
     46    using quad_iterator_return_t = std::pair<run_t, bitquad_t>;
    4647
    4748    using codepoint_t = re::codepoint_t;
     
    6364        void advance(const unsigned n);
    6465
    65         re::interval_t dereference() const {
     66        inline interval_t dereference() const {
    6667            return std::make_pair(mMinCodePoint, mMaxCodePoint);
    6768        }
     
    7172        }
    7273
    73         inline bool equal(iterator const & other) const {
     74        inline bool equal(const iterator & other) const {
    7475            return (mRunIterator == other.mRunIterator) && (mQuadIterator == other.mQuadIterator) &&
    7576                   (mMixedRunIndex == other.mMixedRunIndex) && (mQuadOffset == other.mQuadOffset);
     
    9495    }
    9596
    96     class quad_iterator : public boost::iterator_facade<quad_iterator, std::pair<run_t, bitquad_t>, boost::random_access_traversal_tag> {
     97    class quad_iterator : public boost::iterator_facade<quad_iterator, quad_iterator_return_t, boost::random_access_traversal_tag, quad_iterator_return_t> {
    9798        friend class UnicodeSet;
    9899        friend class boost::iterator_core_access;
     
    103104        void advance(unsigned n);
    104105
    105         inline const std::pair<run_t, bitquad_t> dereference() const {
    106             return std::make_pair(getRun(), getQuad());
     106        inline quad_iterator_return_t dereference() const {
     107            return std::make_pair(run(), quad());
    107108        }
    108109
     
    111112        }
    112113
    113         inline run_t getRun() const {
     114        inline run_t run() const {
    114115            const auto & t = *mRunIterator;
    115116            return std::make_pair(std::get<0>(t), std::get<1>(t) - mOffset);
    116117        }
    117118
    118         inline bitquad_t getQuad() const {
     119        inline bitquad_t quad() const {
    119120            return *mQuadIterator;
    120121        }
     
    147148    UnicodeSet operator-(const UnicodeSet & other) const;
    148149    UnicodeSet operator^(const UnicodeSet & other) const;
     150    inline UnicodeSet & operator=(const UnicodeSet & other) = default;
     151    inline UnicodeSet & operator=(UnicodeSet && other) = default;
    149152    UnicodeSet operator==(const UnicodeSet & other) const;
    150153
     
    152155    UnicodeSet(const codepoint_t codepoint);
    153156    UnicodeSet(const codepoint_t lo_codepoint, const codepoint_t hi_codepoint);
     157    inline UnicodeSet(const UnicodeSet & other) = default;
    154158    UnicodeSet(std::initializer_list<run_t> r, std::initializer_list<bitquad_t> q) : mRuns(r), mQuads(q) {}
    155159    UnicodeSet(std::vector<run_t> && r, std::vector<bitquad_t> && q) : mRuns(r), mQuads(q) {}
     
    160164private:
    161165
    162     std::vector<run_t>   mRuns;
    163     std::vector<bitquad_t>      mQuads;
     166    RunVector       mRuns;
     167    QuadVector      mQuads;
    164168};
    165169
    166170inline void UnicodeSet::swap(UnicodeSet & other) {
    167     mRuns.swap(other.mRuns);
    168     mQuads.swap(other.mQuads);
     171    mRuns.swap(other.mRuns); mQuads.swap(other.mQuads);
    169172}
    170173
    171174inline void UnicodeSet::swap(UnicodeSet && other) {
    172     mRuns.swap(other.mRuns);
    173     mQuads.swap(other.mQuads);
     175    mRuns.swap(other.mRuns); mQuads.swap(other.mQuads);
    174176}
    175177
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.h

    r4617 r4622  
    3434    pablo::Assign * compileCC(const std::string && canonicalName, const re::CC *cc, pablo::PabloBlock & block);
    3535
    36     pablo::Assign * compileCC(const std::string &&canonicalName, const re::CC *cc, pablo::PabloBuilder & builder);
     36    pablo::Assign * compileCC(const std::string && canonicalName, const re::CC *cc, pablo::PabloBuilder & builder);
    3737
    3838    void compileByteClasses(re::RE * re);
     39
     40    pablo::PabloBuilder & getBuilder();
    3941
    4042private:
     
    7678}
    7779
     80inline pablo::PabloBuilder & CC_Compiler::getBuilder() {
     81    return mBuilder;
     82}
     83
    7884
    7985}
  • icGREP/icgrep-devel/icgrep/compiler.cpp

    r4594 r4622  
    150150    }
    151151   
    152     RE_Compiler re_compiler(main);
    153     re_compiler.initializeRequiredStreams(cc_compiler);
     152    RE_Compiler re_compiler(cc_compiler);
     153    re_compiler.initializeRequiredStreams();
    154154    re_compiler.finalizeMatchResult(re_compiler.compile(re_ast));
    155155
  • icGREP/icgrep-devel/icgrep/pablo/builder.cpp

    r4603 r4622  
    1515PabloAST * result = mExprTable.findUnaryOrCall(std::move(functor), TYPE, ARGS)
    1616
     17#define MAKE_NAMED_UNARY(NAME, TYPE, ARGS...) \
     18struct __##NAME { \
     19    inline PabloAST * operator()(PabloAST * arg, const std::string name) { \
     20        return mPb.NAME(arg, name); \
     21    } \
     22    inline __##NAME(PabloBlock & pb) : mPb(pb) {} \
     23private: \
     24    PabloBlock & mPb; \
     25}; \
     26__##NAME functor(mPb); \
     27PabloAST * result = mExprTable.findUnaryOrCall(std::move(functor), TYPE, ARGS)
    1728
    1829#define MAKE_BINARY(NAME, TYPE, ARGS...) \
     
    5263PabloAST * result = mExprTable.findTernaryOrCall(std::move(functor), TYPE, ARGS)
    5364
     65#define MAKE_NAMED_TERNARY(NAME, TYPE, ARGS...) \
     66struct __##NAME { \
     67    inline PabloAST * operator()(PabloAST * arg1, PabloAST * arg2, PabloAST * arg3, const std::string name) { \
     68        return mPb.NAME(arg1, arg2, arg3, name); \
     69    } \
     70    inline __##NAME(PabloBlock & pb) : mPb(pb) {} \
     71private: \
     72    PabloBlock & mPb; \
     73}; \
     74__##NAME functor(mPb); \
     75PabloAST * result = mExprTable.findTernaryOrCall(std::move(functor), TYPE, ARGS)
     76
    5477
    5578Call * PabloBuilder::createCall(String * name) {
     
    7396}
    7497
     98PabloAST * PabloBuilder::createNot(PabloAST * expr, const std::string prefix) {
     99    MAKE_NAMED_UNARY(createNot, PabloAST::ClassTypeId::Not, expr, prefix);
     100    return result;
     101}
     102
    75103PabloAST * PabloBuilder::createAnd(PabloAST * expr1, PabloAST * expr2) {
    76104    if (expr1 < expr2) {
     
    78106    }
    79107    MAKE_BINARY(createAnd, PabloAST::ClassTypeId::And, expr1, expr2);
     108    return result;
     109}
     110
     111PabloAST * PabloBuilder::createAnd(PabloAST * expr1, PabloAST * expr2, const std::string prefix) {
     112    if (expr1 < expr2) {
     113        std::swap(expr1, expr2);
     114    }
     115    MAKE_NAMED_BINARY(createAnd, PabloAST::ClassTypeId::And, expr1, expr2, prefix);
    80116    return result;
    81117}
     
    89125}
    90126
     127PabloAST * PabloBuilder::createOr(PabloAST * expr1, PabloAST * expr2, const std::string prefix) {
     128    if (expr1 < expr2) {
     129        std::swap(expr1, expr2);
     130    }
     131    MAKE_NAMED_BINARY(createOr, PabloAST::ClassTypeId::Or, expr1, expr2, prefix);
     132    return result;
     133}
     134
    91135PabloAST * PabloBuilder::createXor(PabloAST * expr1, PabloAST * expr2) {
    92136    if (expr1 < expr2) {
     
    97141}
    98142
     143PabloAST * PabloBuilder::createXor(PabloAST * expr1, PabloAST * expr2, const std::string prefix) {
     144    if (expr1 < expr2) {
     145        std::swap(expr1, expr2);
     146    }
     147    MAKE_NAMED_BINARY(createXor, PabloAST::ClassTypeId::Xor, expr1, expr2, prefix);
     148    return result;
     149}
     150
    99151PabloAST * PabloBuilder::createMatchStar(PabloAST * marker, PabloAST * charclass) {
    100152    MAKE_BINARY(createMatchStar, PabloAST::ClassTypeId::MatchStar, marker, charclass);
     153    return result;
     154}
     155
     156PabloAST * PabloBuilder::createMatchStar(PabloAST * marker, PabloAST * charclass, const std::string prefix) {
     157    MAKE_NAMED_BINARY(createMatchStar, PabloAST::ClassTypeId::MatchStar, marker, charclass, prefix);
    101158    return result;
    102159}
     
    107164}
    108165
     166PabloAST * PabloBuilder::createScanThru(PabloAST * from, PabloAST * thru, const std::string prefix) {
     167    MAKE_NAMED_BINARY(createScanThru, PabloAST::ClassTypeId::ScanThru, from, thru, prefix);
     168    return result;
     169}
     170
     171
    109172PabloAST * PabloBuilder::createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr) {
    110173    MAKE_TERNARY(createSel, PabloAST::ClassTypeId::Sel, condition, trueExpr, falseExpr);
     
    112175}
    113176
     177PabloAST * PabloBuilder::createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr, const std::string prefix) {
     178    MAKE_NAMED_TERNARY(createSel, PabloAST::ClassTypeId::Sel, condition, trueExpr, falseExpr, prefix);
     179    return result;
    114180}
     181
     182
     183}
  • icGREP/icgrep-devel/icgrep/pablo/builder.hpp

    r4617 r4622  
    1010public:
    1111
    12     PabloBuilder(PabloBlock & pb) : mPb(pb) {}
     12    PabloBuilder(PabloBlock & block) : mPb(block), mParent(nullptr) {}
    1313
    14     inline static PabloBuilder Create(PabloBuilder & parent) {
    15         return PabloBuilder(parent.getPabloBlock().Create(parent.getPabloBlock()), parent);
     14    PabloBuilder(PabloBlock & block, PabloBuilder & parent) : mPb(block), mParent(&parent), mExprTable(&(parent.mExprTable)) {}
     15
     16    inline static PabloBuilder && Create(PabloBuilder & parent) {
     17        return std::move(PabloBuilder(parent.mPb.Create(parent.mPb), parent));
    1618    }
    1719
     
    5557    PabloAST * createAdvance(PabloAST * expr, PabloAST * shiftAmount);
    5658
     59    inline PabloAST * createAdvance(PabloAST * expr, const Integer::integer_t shiftAmount, const std::string prefix) {
     60        if (shiftAmount == 0) {
     61            return expr;
     62        }
     63        return createAdvance(expr, mPb.getInteger(shiftAmount), prefix);
     64    }
     65
    5766    PabloAST * createAdvance(PabloAST * expr, PabloAST * shiftAmount, const std::string prefix);
    5867
    59     Next * createNext(Assign * assign, PabloAST * expr);
     68    inline Next * createNext(Assign * assign, PabloAST * expr) {
     69        return mPb.createNext(assign, expr);
     70    }
    6071
    6172    PabloAST * createAnd(PabloAST * expr1, PabloAST * expr2);
    6273
     74    PabloAST * createAnd(PabloAST * expr1, PabloAST * expr2, const std::string prefix);
     75
    6376    PabloAST * createNot(PabloAST * expr);
     77
     78    PabloAST * createNot(PabloAST * expr, const std::string prefix);
    6479
    6580    PabloAST * createOr(PabloAST * expr1, PabloAST * expr2);
    6681
     82    PabloAST * createOr(PabloAST * expr1, PabloAST * expr2, const std::string prefix);
     83
    6784    PabloAST * createXor(PabloAST * expr1, PabloAST * expr2);
     85
     86    PabloAST * createXor(PabloAST * expr1, PabloAST * expr2, const std::string prefix);
    6887
    6988    PabloAST * createMatchStar(PabloAST * marker, PabloAST * charclass);
    7089
     90    PabloAST * createMatchStar(PabloAST * marker, PabloAST * charclass, const std::string prefix);
     91
    7192    PabloAST * createScanThru(PabloAST * from, PabloAST * thru);
    7293
     94    PabloAST * createScanThru(PabloAST * from, PabloAST * thru, const std::string prefix);
     95
    7396    PabloAST * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr);
     97
     98    PabloAST * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr, const std::string prefix);
     99
     100    inline If * createIf(PabloAST * condition, std::initializer_list<Assign *> definedVars, PabloBuilder & body) {
     101        return mPb.createIf(condition, std::move(definedVars), body.mPb);
     102    }
    74103
    75104    inline If * createIf(PabloAST * condition, std::initializer_list<Assign *> definedVars, PabloBlock & body) {
     
    77106    }
    78107
     108    inline If * createIf(PabloAST * condition, std::vector<Assign *> definedVars, PabloBuilder & body) {
     109        return mPb.createIf(condition, std::move(definedVars), body.mPb);
     110    }
     111
    79112    inline If * createIf(PabloAST * condition, std::vector<Assign *> definedVars, PabloBlock & body) {
    80113        return mPb.createIf(condition, std::move(definedVars), body);
     114    }
     115
     116    inline While * createWhile(PabloAST * condition, PabloBuilder & body) {
     117        return mPb.createWhile(condition, body.mPb);
    81118    }
    82119
     
    109146    }
    110147
    111 protected:
    112 
    113     PabloBuilder(PabloBlock & pb, PabloBuilder & parent) : mPb(pb), mExprTable(&(parent.mExprTable)) {}
     148    inline PabloBuilder * getParent() {
     149        return mParent;
     150    }
    114151
    115152private:
    116153
    117154    PabloBlock &        mPb;
     155    PabloBuilder *      mParent;
    118156    ExpressionTable     mExprTable;
    119157};
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r4609 r4622  
    2121#include <cc/cc_namemap.hpp>
    2222#include <pablo/codegenstate.h>
     23#include <UCD/ucd_compiler.hpp>
    2324
    2425#include <assert.h>
     
    4647
    4748
    48 RE_Compiler::RE_Compiler(PabloBlock & baseCG)
    49 : mPB(baseCG)
     49RE_Compiler::RE_Compiler(cc::CC_Compiler & ccCompiler)
     50: mCCCompiler(ccCompiler)
     51, mPB(ccCompiler.getBuilder().getPabloBlock(), ccCompiler.getBuilder())
    5052, mLineFeed(nullptr)
    5153, mInitial(nullptr)
     
    5860
    5961   
    60 MarkerType RE_Compiler::AdvanceMarker(MarkerType m, MarkerPosition newpos, PabloBlock & pb) {
     62MarkerType RE_Compiler::AdvanceMarker(MarkerType m, MarkerPosition newpos, PabloBuilder & pb) {
    6163    if (m.pos == newpos) return m;
    6264    PabloAST * a = m.stream;
     
    7375}
    7476
    75 void RE_Compiler::AlignMarkers(MarkerType & m1, MarkerType & m2, PabloBlock & pb) {
     77void RE_Compiler::AlignMarkers(MarkerType & m1, MarkerType & m2, PabloBuilder & pb) {
    7678    if (m1.pos < m2.pos) {
    7779        m1 = AdvanceMarker(m1, m2.pos, pb);
     
    8587
    8688
    87 void RE_Compiler::initializeRequiredStreams(cc::CC_Compiler & ccc) {
    88 
    89     Assign * LF = mPB.createAssign("LF", ccc.compileCC(makeCC(0x0A)));
     89void RE_Compiler::initializeRequiredStreams() {
     90
     91    Assign * LF = mPB.createAssign("LF", mCCCompiler.compileCC(makeCC(0x0A)));
    9092    mLineFeed = LF;
    91     PabloAST * CR = ccc.compileCC(makeCC(0x0D));
    92     PabloAST * LF_VT_FF_CR = ccc.compileCC(makeCC(0x0A, 0x0D));
    93 
    94     PabloBlock & crb = PabloBlock::Create(mPB);
     93    PabloAST * CR = mCCCompiler.compileCC(makeCC(0x0D));
     94    PabloAST * LF_VT_FF_CR = mCCCompiler.compileCC(makeCC(0x0A, 0x0D));
     95
     96    PabloBuilder crb = PabloBuilder::Create(mPB);
    9597    PabloAST * cr1 = crb.createAdvance(CR, 1, "cr1");
    9698    Assign * acrlf = crb.createAssign("crlf", crb.createAnd(cr1, LF));
     
    98100    mCRLF = acrlf;
    99101
    100     PabloAST * u8pfx = ccc.compileCC(makeCC(0xC0, 0xFF));
    101     PabloBlock & it = PabloBlock::Create(mPB);
    102     PabloAST * u8pfx2 = ccc.compileCC(makeCC(0xC2, 0xDF), it);
    103     PabloAST * u8pfx3 = ccc.compileCC(makeCC(0xE0, 0xEF), it);
    104     PabloAST * u8pfx4 = ccc.compileCC(makeCC(0xF0, 0xF4), it);
    105     Assign * u8suffix = it.createAssign("u8suffix", ccc.compileCC(makeCC(0x80, 0xBF)));
     102    PabloAST * u8pfx = mCCCompiler.compileCC(makeCC(0xC0, 0xFF));
     103    PabloBuilder it = PabloBuilder::Create(mPB);
     104    PabloAST * u8pfx2 = mCCCompiler.compileCC(makeCC(0xC2, 0xDF), it);
     105    PabloAST * u8pfx3 = mCCCompiler.compileCC(makeCC(0xE0, 0xEF), it);
     106    PabloAST * u8pfx4 = mCCCompiler.compileCC(makeCC(0xF0, 0xF4), it);
     107    Assign * u8suffix = it.createAssign("u8suffix", mCCCompiler.compileCC(makeCC(0x80, 0xBF)));
    106108   
    107109    //
    108110    // Two-byte sequences
    109     PabloBlock & it2 = PabloBlock::Create(it);
     111    PabloBuilder it2 = PabloBuilder::Create(it);
    110112    Assign * u8scope22 = it2.createAssign("u8scope22", it2.createAdvance(u8pfx2, 1));
    111     Assign * NEL = it2.createAssign("NEL", it2.createAnd(it2.createAdvance(ccc.compileCC(makeCC(0xC2), it2), 1), ccc.compileCC(makeCC(0x85), it2)));
     113    Assign * NEL = it2.createAssign("NEL", it2.createAnd(it2.createAdvance(mCCCompiler.compileCC(makeCC(0xC2), it2), 1), mCCCompiler.compileCC(makeCC(0x85), it2)));
    112114    it.createIf(u8pfx2, {u8scope22, NEL}, it2);
    113115   
    114116    //
    115117    // Three-byte sequences
    116     PabloBlock & it3 = PabloBlock::Create(it);
     118    PabloBuilder it3 = PabloBuilder::Create(it);
    117119    Assign * u8scope32 = it3.createAssign("u8scope32", it3.createAdvance(u8pfx3, 1));
    118120    PabloAST * u8scope33 = it3.createAdvance(u8pfx3, 2);
    119121    Assign * u8scope3X = it3.createAssign("u8scope3X", it3.createOr(u8scope32, u8scope33));
    120     PabloAST * E2_80 = it3.createAnd(it3.createAdvance(ccc.compileCC(makeCC(0xE2), it3), 1), ccc.compileCC(makeCC(0x80), it3));
    121     Assign * LS_PS = it3.createAssign("LS_PS", it3.createAnd(it3.createAdvance(E2_80, 1), ccc.compileCC(makeCC(0xA8,0xA9), it3)));
    122     PabloAST * E0_invalid = it3.createAnd(it3.createAdvance(ccc.compileCC(makeCC(0xE0), it3), 1), ccc.compileCC(makeCC(0x80, 0x9F), it3));
    123     PabloAST * ED_invalid = it3.createAnd(it3.createAdvance(ccc.compileCC(makeCC(0xED), it3), 1), ccc.compileCC(makeCC(0xA0, 0xBF), it3));
     122    PabloAST * E2_80 = it3.createAnd(it3.createAdvance(mCCCompiler.compileCC(makeCC(0xE2), it3), 1), mCCCompiler.compileCC(makeCC(0x80), it3));
     123    Assign * LS_PS = it3.createAssign("LS_PS", it3.createAnd(it3.createAdvance(E2_80, 1), mCCCompiler.compileCC(makeCC(0xA8,0xA9), it3)));
     124    PabloAST * E0_invalid = it3.createAnd(it3.createAdvance(mCCCompiler.compileCC(makeCC(0xE0), it3), 1), mCCCompiler.compileCC(makeCC(0x80, 0x9F), it3));
     125    PabloAST * ED_invalid = it3.createAnd(it3.createAdvance(mCCCompiler.compileCC(makeCC(0xED), it3), 1), mCCCompiler.compileCC(makeCC(0xA0, 0xBF), it3));
    124126    Assign * EX_invalid = it3.createAssign("EX_invalid", it3.createOr(E0_invalid, ED_invalid));
    125127    it.createIf(u8pfx3, {u8scope32, u8scope3X, LS_PS, EX_invalid}, it3);
     
    127129    //
    128130    // Four-byte sequences
    129     PabloBlock & it4 = PabloBlock::Create(it);
     131    PabloBuilder it4 = PabloBuilder::Create(it);
    130132    PabloAST * u8scope42 = it4.createAdvance(u8pfx4, 1, "u8scope42");
    131133    PabloAST * u8scope43 = it4.createAdvance(u8scope42, 1, "u8scope43");
     
    133135    Assign * u8scope4nonfinal = it4.createAssign("u8scope4nonfinal", it4.createOr(u8scope42, u8scope43));
    134136    Assign * u8scope4X = it4.createAssign("u8scope4X", it4.createOr(u8scope4nonfinal, u8scope44));
    135     PabloAST * F0_invalid = it4.createAnd(it4.createAdvance(ccc.compileCC(makeCC(0xF0), it4), 1), ccc.compileCC(makeCC(0x80, 0x8F), it4));
    136     PabloAST * F4_invalid = it4.createAnd(it4.createAdvance(ccc.compileCC(makeCC(0xF4), it4), 1), ccc.compileCC(makeCC(0x90, 0xBF), it4));
     137    PabloAST * F0_invalid = it4.createAnd(it4.createAdvance(mCCCompiler.compileCC(makeCC(0xF0), it4), 1), mCCCompiler.compileCC(makeCC(0x80, 0x8F), it4));
     138    PabloAST * F4_invalid = it4.createAnd(it4.createAdvance(mCCCompiler.compileCC(makeCC(0xF4), it4), 1), mCCCompiler.compileCC(makeCC(0x90, 0xBF), it4));
    137139    Assign * FX_invalid = it4.createAssign("FX_invalid", it4.createOr(F0_invalid, F4_invalid));
    138140    it.createIf(u8pfx4, {u8scope4nonfinal, u8scope4X, FX_invalid}, it4);
     
    160162   
    161163    PabloAST * LB_chars = mPB.createOr(LF_VT_FF_CR, NEL_LS_PS);
    162     PabloAST * u8single = mPB.createAnd(ccc.compileCC(makeCC(0x00, 0x7F)), mPB.createNot(u8invalid));
     164    PabloAST * u8single = mPB.createAnd(mCCCompiler.compileCC(makeCC(0x00, 0x7F)), mPB.createNot(u8invalid));
    163165    mInitial = mPB.createOr(u8single, valid_pfx, "initial");
    164166    mFinal = mPB.createNot(mPB.createOr(mNonFinal, u8invalid), "final");
     
    174176}
    175177
    176 MarkerType RE_Compiler::compile(RE * re, PabloBlock & pb) {
     178MarkerType RE_Compiler::compile(RE * re, PabloBuilder & pb) {
    177179    return process(re, makeMarker(FinalPostPositionByte, pb.createOnes()), pb);
    178180}
    179181
    180 PabloAST * RE_Compiler::nextUnicodePosition(MarkerType m, PabloBlock & pb) {
     182PabloAST * RE_Compiler::nextUnicodePosition(MarkerType m, PabloBuilder & pb) {
    181183    if (markerPos(m) == FinalPostPositionByte) {
    182184        return markerVar(m);
     
    190192}
    191193
    192 MarkerType RE_Compiler::process(RE * re, MarkerType marker, PabloBlock & pb) {
     194MarkerType RE_Compiler::process(RE * re, MarkerType marker, PabloBuilder & pb) {
    193195    if (Name * name = dyn_cast<Name>(re)) {
    194196        return process(name, marker, pb);
     
    240242}
    241243
    242 MarkerType RE_Compiler::process(Name * name, MarkerType marker, PabloBlock & pb) {
     244MarkerType RE_Compiler::process(Name * name, MarkerType marker, PabloBuilder & pb) {
    243245    MarkerType nextPos;
    244246    if (markerPos(marker) == FinalPostPositionByte) nextPos = marker;
     
    249251        nextPos = AdvanceMarker(marker, FinalPostPositionByte, pb);
    250252    }
    251     return makeMarker(FinalMatchByte, pb.createAnd(markerVar(nextPos), getNamedCharacterClassStream(name), "m"));
    252 }
    253 
    254 PabloAST * RE_Compiler::getNamedCharacterClassStream(Name * name) {
     253    return makeMarker(FinalMatchByte, pb.createAnd(markerVar(nextPos), getNamedCharacterClassStream(name, pb), "m"));
     254}
     255
     256PabloAST * RE_Compiler::getNamedCharacterClassStream(Name * name, PabloBuilder & pb) {
    255257    PabloAST * var = name->getCompiled();
    256258    if (LLVM_LIKELY(var != nullptr)) {
     
    258260    }
    259261    else if (name->getDefinition() != nullptr) {
    260         MarkerType m = compile(name->getDefinition(), mPB);
     262        MarkerType m = compile(name->getDefinition(), pb);
    261263        assert(markerPos(m) == FinalMatchByte);
    262264        var = markerVar(m);
     
    264266    else if (name->getType() == Name::Type::UnicodeProperty) {
    265267        var = mPB.createCall(name->getName());
     268        // UCD::UCDCompiler ucdCompiler(mCCCompiler);
    266269    }
    267270    else {
     
    269272    }
    270273
    271     var = mPB.createAnd(var, mPB.createNot(UNICODE_LINE_BREAK ? mUnicodeLineBreak : mLineFeed));
     274    var = pb.createAnd(var, pb.createNot(UNICODE_LINE_BREAK ? mUnicodeLineBreak : mLineFeed));
    272275    name->setCompiled(var);
    273276    return var;
     
    275278
    276279
    277 MarkerType RE_Compiler::process(Seq * seq, MarkerType marker, PabloBlock & pb) {
     280MarkerType RE_Compiler::process(Seq * seq, MarkerType marker, PabloBuilder & pb) {
    278281    // if-hierarchies are not inserted within unbounded repetitions
    279282    if (mStarDepth > 0) {
     
    288291}
    289292
    290 MarkerType RE_Compiler::processSeqTail(Seq::iterator current, Seq::iterator end, int matchLenSoFar, MarkerType marker, PabloBlock & pb) {
     293MarkerType RE_Compiler::processSeqTail(Seq::iterator current, Seq::iterator end, int matchLenSoFar, MarkerType marker, PabloBuilder & pb) {
    291294    if (current == end) return marker;
    292295    if (matchLenSoFar < IfInsertionGap) {
     
    297300    }
    298301    else {
    299         PabloBlock & nested = PabloBlock::Create(pb);
     302        PabloBuilder nested = PabloBuilder::Create(pb);
    300303        MarkerType m1 = processSeqTail(current, end, 0, marker, nested);
    301304        Assign * m1a = nested.createAssign("m", markerVar(m1));
     
    305308}
    306309
    307 MarkerType RE_Compiler::process(Alt * alt, MarkerType marker, PabloBlock & pb) {
     310MarkerType RE_Compiler::process(Alt * alt, MarkerType marker, PabloBuilder & pb) {
    308311    std::vector<PabloAST *>  accum = {pb.createZeroes(), pb.createZeroes(), pb.createZeroes()};
    309312    MarkerType const base = marker;
     
    327330}
    328331
    329 MarkerType RE_Compiler::process(Assertion * a, MarkerType marker, PabloBlock & pb) {
     332MarkerType RE_Compiler::process(Assertion * a, MarkerType marker, PabloBuilder & pb) {
    330333    RE * asserted = a->getAsserted();
    331334    if (a->getKind() == Assertion::Kind::Lookbehind) {
     
    354357}
    355358
    356 MarkerType RE_Compiler::process(Diff * diff, MarkerType marker, PabloBlock & pb) {
     359MarkerType RE_Compiler::process(Diff * diff, MarkerType marker, PabloBuilder & pb) {
    357360    RE * lh = diff->getLH();
    358361    RE * rh = diff->getRH();
     
    366369}
    367370
    368 MarkerType RE_Compiler::process(Intersect * x, MarkerType marker, PabloBlock & pb) {
     371MarkerType RE_Compiler::process(Intersect * x, MarkerType marker, PabloBuilder & pb) {
    369372    RE * lh = x->getLH();
    370373    RE * rh = x->getRH();
     
    378381}
    379382
    380 MarkerType RE_Compiler::process(Rep * rep, MarkerType marker, PabloBlock & pb) {
     383MarkerType RE_Compiler::process(Rep * rep, MarkerType marker, PabloBuilder & pb) {
    381384    int lb = rep->getLB();
    382385    int ub = rep->getUB();
     
    401404*/
    402405
    403 inline PabloAST * RE_Compiler::consecutive1(PabloAST * repeated, int repeated_lgth, int repeat_count, pablo::PabloBlock & pb) {
     406inline PabloAST * RE_Compiler::consecutive1(PabloAST * repeated, int repeated_lgth, int repeat_count, PabloBuilder & pb) {
    404407        int i = repeated_lgth;
    405408        int total_lgth = repeat_count * repeated_lgth;
     
    418421}
    419422
    420 inline PabloAST * RE_Compiler::reachable(PabloAST *repeated, int repeated_lgth, int repeat_count, pablo::PabloBlock & pb) {
     423inline PabloAST * RE_Compiler::reachable(PabloAST *repeated, int repeated_lgth, int repeat_count, PabloBuilder & pb) {
    421424        int i = repeated_lgth;
    422425        int total_lgth = repeat_count * repeated_lgth;
     
    438441}
    439442
    440 MarkerType RE_Compiler::processLowerBound(RE * repeated, int lb, MarkerType marker, PabloBlock & pb) {
     443MarkerType RE_Compiler::processLowerBound(RE * repeated, int lb, MarkerType marker, PabloBuilder & pb) {
    441444    if (isByteLength(repeated) && !DisableLog2BoundedRepetition) {
    442445        PabloAST * cc = markerVar(compile(repeated, pb));
     
    452455}
    453456
    454 MarkerType RE_Compiler::processBoundedRep(RE * repeated, int ub, MarkerType marker, PabloBlock & pb) {
     457MarkerType RE_Compiler::processBoundedRep(RE * repeated, int ub, MarkerType marker, PabloBuilder & pb) {
    455458    if (isByteLength(repeated) && ub > 1 && !DisableLog2BoundedRepetition) {
    456459        // log2 upper bound for fixed length (=1) class
     
    473476}
    474477
    475 MarkerType RE_Compiler::processUnboundedRep(RE * repeated, MarkerType marker, PabloBlock & pb) {
     478MarkerType RE_Compiler::processUnboundedRep(RE * repeated, MarkerType marker, PabloBuilder & pb) {
    476479    // always use PostPosition markers for unbounded repetition.
    477480    PabloAST * base = markerVar(AdvanceMarker(marker, InitialPostPositionByte, pb));
     
    487490    else if (mStarDepth > 0){
    488491       
    489         PabloBlock * outerb = pb.getParent();
     492        PabloBuilder * outerb = pb.getParent();
    490493       
    491494        Assign * starPending = outerb->createAssign("pending", outerb->createZeroes());
     
    509512        mWhileTest = pb.createZeroes();
    510513
    511         PabloBlock & wb = PabloBlock::Create(pb);
     514        PabloBuilder wb = PabloBuilder::Create(pb);
    512515        mStarDepth++;
    513516
  • icGREP/icgrep-devel/icgrep/re/re_compiler.h

    r4609 r4622  
    1111#include <re/re_seq.h>
    1212#include <cc/cc_compiler.h>
    13 
     13#include <pablo/builder.hpp>
    1414#include <string>
    1515#include <list>
     
    1818namespace cc {
    1919class CC_NameMap;
    20 }
    21 
    22 namespace pablo {
    23 class PabloBlock;
    24 class PabloAST;
    25 class Assign;
    26 class Var;
    2720}
    2821
     
    5851public:
    5952
    60     RE_Compiler(pablo::PabloBlock & baseCG);
    61     void initializeRequiredStreams(cc::CC_Compiler & ccc);
     53    RE_Compiler(cc::CC_Compiler & ccCompiler);
     54    void initializeRequiredStreams();
    6255    void finalizeMatchResult(MarkerType match_result);
    6356    MarkerType compile(RE * re) {
     
    6760private:
    6861
    69     MarkerType compile(RE * re, pablo::PabloBlock & cg);
    70     MarkerType AdvanceMarker(MarkerType m, MarkerPosition newpos, pablo::PabloBlock & pb);
     62    MarkerType compile(RE * re, pablo::PabloBuilder & cg);
     63    MarkerType AdvanceMarker(MarkerType m, MarkerPosition newpos, pablo::PabloBuilder & pb);
    7164   
    72     void AlignMarkers(MarkerType & m1, MarkerType & m2, pablo::PabloBlock & pb);
     65    void AlignMarkers(MarkerType & m1, MarkerType & m2, pablo::PabloBuilder & pb);
    7366   
    74     pablo::PabloAST * getNamedCharacterClassStream(Name * name);
    75     pablo::PabloAST * nextUnicodePosition(MarkerType m, pablo::PabloBlock & pb);
    76     MarkerType process(RE * re, MarkerType marker, pablo::PabloBlock & pb);
    77     MarkerType process(Name * name, MarkerType marker, pablo::PabloBlock & pb);
    78     MarkerType process(Seq * seq, MarkerType marker, pablo::PabloBlock & pb);
    79     MarkerType processSeqTail(Seq::iterator current, Seq::iterator end, int matchLenSoFar, MarkerType marker, pablo::PabloBlock & pb);
    80     MarkerType process(Alt * alt, MarkerType marker, pablo::PabloBlock & pb);
    81     MarkerType process(Assertion * a, MarkerType marker, pablo::PabloBlock & pb);
    82     MarkerType process(Rep * rep, MarkerType marker, pablo::PabloBlock & pb);
    83     MarkerType process(Diff * diff, MarkerType marker, pablo::PabloBlock & cg);
    84     MarkerType process(Intersect * x, MarkerType marker, pablo::PabloBlock & cg);
    85     pablo::PabloAST *consecutive1(pablo::PabloAST *repeated,  int repeated_lgth, int repeat_count, pablo::PabloBlock & pb);
    86     pablo::PabloAST * reachable(pablo::PabloAST * repeated,  int repeated_lgth, int repeat_count, pablo::PabloBlock & pb);
     67    pablo::PabloAST * getNamedCharacterClassStream(Name * name, pablo::PabloBuilder & pb);
     68    pablo::PabloAST * nextUnicodePosition(MarkerType m, pablo::PabloBuilder & pb);
     69    MarkerType process(RE * re, MarkerType marker, pablo::PabloBuilder & pb);
     70    MarkerType process(Name * name, MarkerType marker, pablo::PabloBuilder & pb);
     71    MarkerType process(Seq * seq, MarkerType marker, pablo::PabloBuilder & pb);
     72    MarkerType processSeqTail(Seq::iterator current, Seq::iterator end, int matchLenSoFar, MarkerType marker, pablo::PabloBuilder & pb);
     73    MarkerType process(Alt * alt, MarkerType marker, pablo::PabloBuilder & pb);
     74    MarkerType process(Assertion * a, MarkerType marker, pablo::PabloBuilder & pb);
     75    MarkerType process(Rep * rep, MarkerType marker, pablo::PabloBuilder & pb);
     76    MarkerType process(Diff * diff, MarkerType marker, pablo::PabloBuilder & cg);
     77    MarkerType process(Intersect * x, MarkerType marker, pablo::PabloBuilder & cg);
     78    pablo::PabloAST *consecutive1(pablo::PabloAST *repeated,  int repeated_lgth, int repeat_count, pablo::PabloBuilder & pb);
     79    pablo::PabloAST * reachable(pablo::PabloAST * repeated,  int repeated_lgth, int repeat_count, pablo::PabloBuilder & pb);
    8780    static bool isFixedLength(RE * regexp);
    88     MarkerType processLowerBound(RE * repeated,  int lb, MarkerType marker, pablo::PabloBlock & pb);
    89     MarkerType processUnboundedRep(RE * repeated, MarkerType marker, pablo::PabloBlock & pb);
    90     MarkerType processBoundedRep(RE * repeated, int ub, MarkerType marker, pablo::PabloBlock & pb);
     81    MarkerType processLowerBound(RE * repeated,  int lb, MarkerType marker, pablo::PabloBuilder & pb);
     82    MarkerType processUnboundedRep(RE * repeated, MarkerType marker, pablo::PabloBuilder & pb);
     83    MarkerType processBoundedRep(RE * repeated, int ub, MarkerType marker, pablo::PabloBuilder & pb);
    9184
    92     pablo::PabloBlock &                             mPB;
     85private:
     86
     87    cc::CC_Compiler &                               mCCCompiler;
     88    pablo::PabloBuilder                             mPB;
    9389    pablo::Assign *                                 mLineFeed;
    9490    pablo::PabloAST *                               mCRLF;
  • icGREP/icgrep-devel/icgrep/re/re_parser.cpp

    r4516 r4622  
    592592    }
    593593    while (_cursor != _end) {
    594         CharsetOperatorKind op = getCharsetOperator();
     594        const CharsetOperatorKind op = getCharsetOperator();
    595595        switch (op) {
    596596            case intersectOp:
     
    883883        caseInsensitiveInsertRange(cc, lo, hi);
    884884    }
    885     else cc-> insert_range(lo, hi);
    886 }
    887    
    888    
    889 }
     885    else cc->insert_range(lo, hi);
     886}
     887   
     888   
     889}
Note: See TracChangeset for help on using the changeset viewer.