Ignore:
Timestamp:
Jun 12, 2015, 2:16:59 PM (4 years ago)
Author:
nmedfort
Message:

Fixed PabloBuilder? and intergrated it into CC Compiler.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/builder.cpp

    r4443 r4602  
    33namespace pablo {
    44
    5 #define CALL_UNARY_FUNCTOR(NAME, TYPE, ARGS...) \
     5#define MAKE_UNARY(NAME, TYPE, ARGS...) \
    66struct __##NAME { \
    7     inline PabloAST * operator()(PabloAST * expr) { \
    8         return mPB->NAME(expr); \
     7    inline PabloAST * operator()(PabloAST * arg) { \
     8        return mPb.NAME(arg); \
    99    } \
    10     inline __##NAME(PabloBlock * pb) : mPB(pb) {} \
     10    inline __##NAME(PabloBlock & pb) : mPb(pb) {} \
    1111private: \
    12     PabloBlock * mPB; \
     12    PabloBlock & mPb; \
    1313}; \
    14 __##NAME functor(this); \
    15 mExprTable.findUnaryOrCall<__##NAME>(std::move(functor), TYPE, ARGS)
     14__##NAME functor(mPb); \
     15PabloAST * result = mExprTable.findUnaryOrCall(std::move(functor), TYPE, ARGS)
    1616
    1717
    18 #define CALL_BINARY_FUNCTOR(NAME, TYPE, ARGS...) \
     18#define MAKE_BINARY(NAME, TYPE, ARGS...) \
    1919struct __##NAME { \
    20     inline PabloAST * operator()(PabloAST * expr) { \
    21         return mPB->NAME(expr); \
     20    inline PabloAST * operator()(PabloAST * arg1, PabloAST * arg2) { \
     21        return mPb.NAME(arg1, arg2); \
    2222    } \
    23     inline __##NAME(PabloBlock * pb) : mPB(pb) {} \
     23    inline __##NAME(PabloBlock & pb) : mPb(pb) {} \
    2424private: \
    25     PabloBlock * mPB; \
     25    PabloBlock & mPb; \
    2626}; \
    27 __##NAME functor(this); \
    28 mExprTable.findBinaryOrCall<__##NAME>(std::move(functor), TYPE, ARGS)
     27__##NAME functor(mPb); \
     28PabloAST * result = mExprTable.findBinaryOrCall(std::move(functor), TYPE, ARGS)
    2929
    30 #define CALL_TERNARY_FUNCTOR(NAME, TYPE, ARGS...) \
     30#define MAKE_TERNARY(NAME, TYPE, ARGS...) \
    3131struct __##NAME { \
    32     inline PabloAST * operator()(PabloAST * expr) { \
    33         return mPB->NAME(expr); \
     32    inline PabloAST * operator()(PabloAST * arg1, PabloAST * arg2, PabloAST * arg3) { \
     33        return mPb.NAME(arg1, arg2, arg3); \
    3434    } \
    35     inline __##NAME(PabloBlock * pb) : mPB(pb) {} \
     35    inline __##NAME(PabloBlock & pb) : mPb(pb) {} \
    3636private: \
    37     PabloBlock * mPB; \
     37    PabloBlock & mPb; \
    3838}; \
    39 __##NAME functor(this); \
    40 mExprTable.findTernaryOrCall<__##NAME>(std::move(functor), TYPE, ARGS)
     39__##NAME functor(mPb); \
     40PabloAST * result = mExprTable.findTernaryOrCall(std::move(functor), TYPE, ARGS)
    4141
    4242
    4343Call * PabloBuilder::createCall(String * name) {
    44     return CALL_UNARY_FUNCTOR(createCall, PabloAST::ClassTypeId::Call, name);
    45 }
    46 
    47 
    48 Assign * PabloBuilder::createAssign(const std::string prefix, PabloAST * expr, const int outputIndex) {
    49 
     44    MAKE_UNARY(createCall, PabloAST::ClassTypeId::Call, name);
     45    return cast<Call>(result);
    5046}
    5147
    5248PabloAST * PabloBuilder::createAdvance(PabloAST * expr, PabloAST * shiftAmount) {
    53 
     49    MAKE_BINARY(createAdvance, PabloAST::ClassTypeId::Advance, expr, shiftAmount);
     50    return result;
    5451}
    5552
    5653PabloAST * PabloBuilder::createNot(PabloAST * expr) {
    57     return CALL_UNARY_FUNCTOR(createNot, PabloAST::ClassTypeId::Not, expr);
     54    MAKE_UNARY(createNot, PabloAST::ClassTypeId::Not, expr);
     55    return result;
    5856}
    5957
     
    6260        std::swap(expr1, expr2);
    6361    }
    64     return CALL_BINARY_FUNCTOR(createAnd, PabloAST::ClassTypeId::And, expr1, expr2);
     62    MAKE_BINARY(createAnd, PabloAST::ClassTypeId::And, expr1, expr2);
     63    return result;
    6564}
    6665
     
    6968        std::swap(expr1, expr2);
    7069    }
    71     return CALL_BINARY_FUNCTOR(createOr, PabloAST::ClassTypeId::Or, expr1, expr2);
     70    MAKE_BINARY(createOr, PabloAST::ClassTypeId::Or, expr1, expr2);
     71    return result;
    7272}
    7373
     
    7676        std::swap(expr1, expr2);
    7777    }
    78     return CALL_BINARY_FUNCTOR(createXor, PabloAST::ClassTypeId::Xor, expr1, expr2);
     78    MAKE_BINARY(createXor, PabloAST::ClassTypeId::Xor, expr1, expr2);
     79    return result;
    7980}
    8081
    8182PabloAST * PabloBuilder::createMatchStar(PabloAST * marker, PabloAST * charclass) {
    82     return CALL_BINARY_FUNCTOR(createMatchStar, PabloAST::ClassTypeId::MatchStar, marker, charclass);
     83    MAKE_BINARY(createMatchStar, PabloAST::ClassTypeId::MatchStar, marker, charclass);
     84    return result;
    8385}
    8486
    8587PabloAST * PabloBuilder::createScanThru(PabloAST * from, PabloAST * thru) {
    86     return CALL_BINARY_FUNCTOR(createScanThru, PabloAST::ClassTypeId::ScanThru, from, thru);
     88    MAKE_BINARY(createScanThru, PabloAST::ClassTypeId::ScanThru, from, thru);
     89    return result;
    8790}
    8891
    89 PabloAST * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr) {
    90     return CALL_TERNARY_FUNCTOR(createSel, PabloAST::ClassTypeId::Sel, condition, trueExpr, falseExpr);
     92PabloAST * PabloBuilder::createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr) {
     93    MAKE_TERNARY(createSel, PabloAST::ClassTypeId::Sel, condition, trueExpr, falseExpr);
     94    return result;
    9195}
    9296
Note: See TracChangeset for help on using the changeset viewer.