Ignore:
Timestamp:
Jul 23, 2015, 4:47:59 PM (4 years ago)
Author:
nmedfort
Message:

Temporary check in.

File:
1 edited

Legend:

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

    r4683 r4692  
    88        return mPb->NAME(arg); \
    99    } \
    10     inline __##NAME(PabloBlock * pb) : mPb(pb) {} \
    11 private: \
    12     PabloBlock * mPb; \
    13 }; \
    14 __##NAME functor(mPb); \
    15 PabloAST * result = mExprTable.findUnaryOrCall(std::move(functor), TYPE, ARGS)
    16 
    17 #define MAKE_NAMED_UNARY(NAME, TYPE, ARGS...) \
    18 struct __##NAME { \
    1910    inline PabloAST * operator()(PabloAST * arg, const std::string name) { \
    2011        return mPb->NAME(arg, name); \
     
    2718PabloAST * result = mExprTable.findUnaryOrCall(std::move(functor), TYPE, ARGS)
    2819
    29 #define MAKE_UNARY_VARIABLE(NAME, TYPE, ARGS...) \
    30 struct __##NAME { \
    31     inline PabloAST * operator()(PabloAST * arg, const std::vector<PabloAST *> & args) { \
    32         return mPb->NAME(arg, args); \
    33     } \
    34     inline __##NAME(PabloBlock * pb) : mPb(pb) {} \
    35 private: \
    36     PabloBlock * mPb; \
    37 }; \
    38 __##NAME functor(mPb); \
    39 PabloAST * result = mExprTable.findUnaryVariableOrCall(std::move(functor), TYPE, ARGS)
    40 
    41 
    4220#define MAKE_BINARY(NAME, TYPE, ARGS...) \
    4321struct __##NAME { \
     
    4523        return mPb->NAME(arg1, arg2); \
    4624    } \
    47     inline __##NAME(PabloBlock * pb) : mPb(pb) {} \
    48 private: \
    49     PabloBlock * mPb; \
    50 }; \
    51 __##NAME functor(mPb); \
    52 PabloAST * result = mExprTable.findBinaryOrCall(std::move(functor), TYPE, ARGS)
    53 
    54 #define MAKE_NAMED_BINARY(NAME, TYPE, ARGS...) \
    55 struct __##NAME { \
    5625    inline PabloAST * operator()(PabloAST * arg1, PabloAST * arg2, const std::string name) { \
    5726        return mPb->NAME(arg1, arg2, name); \
     
    6433PabloAST * result = mExprTable.findBinaryOrCall(std::move(functor), TYPE, ARGS)
    6534
     35
    6636#define MAKE_TERNARY(NAME, TYPE, ARGS...) \
    6737struct __##NAME { \
     
    6939        return mPb->NAME(arg1, arg2, arg3); \
    7040    } \
    71     inline __##NAME(PabloBlock * pb) : mPb(pb) {} \
    72 private: \
    73     PabloBlock * mPb; \
    74 }; \
    75 __##NAME functor(mPb); \
    76 PabloAST * result = mExprTable.findTernaryOrCall(std::move(functor), TYPE, ARGS)
    77 
    78 #define MAKE_NAMED_TERNARY(NAME, TYPE, ARGS...) \
    79 struct __##NAME { \
    8041    inline PabloAST * operator()(PabloAST * arg1, PabloAST * arg2, PabloAST * arg3, const std::string name) { \
    8142        return mPb->NAME(arg1, arg2, arg3, name); \
     
    8849PabloAST * result = mExprTable.findTernaryOrCall(std::move(functor), TYPE, ARGS)
    8950
    90 #define MAKE_VARIABLE(NAME, TYPE, ARGS) \
     51#define MAKE_VARIABLE(NAME, TYPE, ARGS...) \
    9152struct __##NAME { \
    92     inline PabloAST * operator()(PabloAST * arg) { \
    93         return mPb->NAME(arg); \
     53    inline PabloAST * operator()(const std::vector<PabloAST *> & args, PabloAST * prototype) { \
     54        return mPb->NAME(prototype, args); \
    9455    } \
    9556    inline __##NAME(PabloBlock * pb) : mPb(pb) {} \
     
    9859}; \
    9960__##NAME functor(mPb); \
    100 PabloAST * result = mExprTable.findUnaryOrCall(std::move(functor), TYPE, ARGS)
     61PabloAST * result = mExprTable.findVariableOrCall(std::move(functor), TYPE, ARGS)
    10162
    102 
    103 Call * PabloBuilder::createCall(Prototype * prototype, const std::vector<Var *> & args) {
     63Call * PabloBuilder::createCall(Prototype * prototype, const std::vector<PabloAST *> & args) {
     64    if (prototype == nullptr) {
     65        throw std::runtime_error("Call object cannot be created with a Null prototype!");
     66    }
    10467    if (args.size() != cast<Prototype>(prototype)->getNumOfParameters()) {
    10568        throw std::runtime_error("Invalid number of arguments passed into Call object!");
    10669    }
    107     MAKE_UNARY_VARIABLE(createCall, PabloAST::ClassTypeId::Call, prototype, reinterpret_cast<const std::vector<PabloAST *> &>(args));
     70    MAKE_VARIABLE(createCall, PabloAST::ClassTypeId::Call, prototype->getName(), args, prototype);
    10871    return cast<Call>(result);
    10972}
     
    11578
    11679PabloAST * PabloBuilder::createAdvance(PabloAST * expr, PabloAST * shiftAmount, const std::string prefix) {
    117     MAKE_NAMED_BINARY(createAdvance, PabloAST::ClassTypeId::Advance, expr, shiftAmount, prefix);
     80    MAKE_BINARY(createAdvance, PabloAST::ClassTypeId::Advance, expr, shiftAmount, prefix);
    11881    return result;
    11982}
     
    12588
    12689PabloAST * PabloBuilder::createNot(PabloAST * expr, const std::string prefix) {
    127     MAKE_NAMED_UNARY(createNot, PabloAST::ClassTypeId::Not, expr, prefix);
     90    MAKE_UNARY(createNot, PabloAST::ClassTypeId::Not, expr, prefix);
    12891    return result;
    12992}
     
    141104        std::swap(expr1, expr2);
    142105    }
    143     MAKE_NAMED_BINARY(createAnd, PabloAST::ClassTypeId::And, expr1, expr2, prefix);
     106    MAKE_BINARY(createAnd, PabloAST::ClassTypeId::And, expr1, expr2, prefix);
    144107    return result;
    145108}
     
    157120        std::swap(expr1, expr2);
    158121    }
    159     MAKE_NAMED_BINARY(createOr, PabloAST::ClassTypeId::Or, expr1, expr2, prefix);
     122    MAKE_BINARY(createOr, PabloAST::ClassTypeId::Or, expr1, expr2, prefix);
    160123    return result;
    161124}
     
    173136        std::swap(expr1, expr2);
    174137    }
    175     MAKE_NAMED_BINARY(createXor, PabloAST::ClassTypeId::Xor, expr1, expr2, prefix);
     138    MAKE_BINARY(createXor, PabloAST::ClassTypeId::Xor, expr1, expr2, prefix);
    176139    return result;
    177140}
     
    183146
    184147PabloAST * PabloBuilder::createMatchStar(PabloAST * marker, PabloAST * charclass, const std::string prefix) {
    185     MAKE_NAMED_BINARY(createMatchStar, PabloAST::ClassTypeId::MatchStar, marker, charclass, prefix);
     148    MAKE_BINARY(createMatchStar, PabloAST::ClassTypeId::MatchStar, marker, charclass, prefix);
    186149    return result;
    187150}
     
    193156
    194157PabloAST * PabloBuilder::createScanThru(PabloAST * from, PabloAST * thru, const std::string prefix) {
    195     MAKE_NAMED_BINARY(createScanThru, PabloAST::ClassTypeId::ScanThru, from, thru, prefix);
     158    MAKE_BINARY(createScanThru, PabloAST::ClassTypeId::ScanThru, from, thru, prefix);
    196159    return result;
    197160}
     
    204167
    205168PabloAST * PabloBuilder::createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr, const std::string prefix) {
    206     MAKE_NAMED_TERNARY(createSel, PabloAST::ClassTypeId::Sel, condition, trueExpr, falseExpr, prefix);
     169    MAKE_TERNARY(createSel, PabloAST::ClassTypeId::Sel, condition, trueExpr, falseExpr, prefix);
    207170    return result;
    208171}
Note: See TracChangeset for help on using the changeset viewer.