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/pablo
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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};
Note: See TracChangeset for help on using the changeset viewer.