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.

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.