source: icGREP/icgrep-devel/icgrep/pablo/builder.cpp @ 4543

Last change on this file since 4543 was 4443, checked in by nmedfort, 5 years ago

Temporary check in.

File size: 2.7 KB
Line 
1#include "builder.hpp"
2
3namespace pablo {
4
5#define CALL_UNARY_FUNCTOR(NAME, TYPE, ARGS...) \
6struct __##NAME { \
7    inline PabloAST * operator()(PabloAST * expr) { \
8        return mPB->NAME(expr); \
9    } \
10    inline __##NAME(PabloBlock * pb) : mPB(pb) {} \
11private: \
12    PabloBlock * mPB; \
13}; \
14__##NAME functor(this); \
15mExprTable.findUnaryOrCall<__##NAME>(std::move(functor), TYPE, ARGS)
16
17
18#define CALL_BINARY_FUNCTOR(NAME, TYPE, ARGS...) \
19struct __##NAME { \
20    inline PabloAST * operator()(PabloAST * expr) { \
21        return mPB->NAME(expr); \
22    } \
23    inline __##NAME(PabloBlock * pb) : mPB(pb) {} \
24private: \
25    PabloBlock * mPB; \
26}; \
27__##NAME functor(this); \
28mExprTable.findBinaryOrCall<__##NAME>(std::move(functor), TYPE, ARGS)
29
30#define CALL_TERNARY_FUNCTOR(NAME, TYPE, ARGS...) \
31struct __##NAME { \
32    inline PabloAST * operator()(PabloAST * expr) { \
33        return mPB->NAME(expr); \
34    } \
35    inline __##NAME(PabloBlock * pb) : mPB(pb) {} \
36private: \
37    PabloBlock * mPB; \
38}; \
39__##NAME functor(this); \
40mExprTable.findTernaryOrCall<__##NAME>(std::move(functor), TYPE, ARGS)
41
42
43Call * PabloBuilder::createCall(String * name) {
44    return CALL_UNARY_FUNCTOR(createCall, PabloAST::ClassTypeId::Call, name);
45}
46
47
48Assign * PabloBuilder::createAssign(const std::string prefix, PabloAST * expr, const int outputIndex) {
49
50}
51
52PabloAST * PabloBuilder::createAdvance(PabloAST * expr, PabloAST * shiftAmount) {
53
54}
55
56PabloAST * PabloBuilder::createNot(PabloAST * expr) {
57    return CALL_UNARY_FUNCTOR(createNot, PabloAST::ClassTypeId::Not, expr);
58}
59
60PabloAST * PabloBuilder::createAnd(PabloAST * expr1, PabloAST * expr2) {
61    if (expr1 < expr2) {
62        std::swap(expr1, expr2);
63    }
64    return CALL_BINARY_FUNCTOR(createAnd, PabloAST::ClassTypeId::And, expr1, expr2);
65}
66
67PabloAST * PabloBuilder::createOr(PabloAST * expr1, PabloAST * expr2) {
68    if (expr1 < expr2) {
69        std::swap(expr1, expr2);
70    }
71    return CALL_BINARY_FUNCTOR(createOr, PabloAST::ClassTypeId::Or, expr1, expr2);
72}
73
74PabloAST * PabloBuilder::createXor(PabloAST * expr1, PabloAST * expr2) {
75    if (expr1 < expr2) {
76        std::swap(expr1, expr2);
77    }
78    return CALL_BINARY_FUNCTOR(createXor, PabloAST::ClassTypeId::Xor, expr1, expr2);
79}
80
81PabloAST * PabloBuilder::createMatchStar(PabloAST * marker, PabloAST * charclass) {
82    return CALL_BINARY_FUNCTOR(createMatchStar, PabloAST::ClassTypeId::MatchStar, marker, charclass);
83}
84
85PabloAST * PabloBuilder::createScanThru(PabloAST * from, PabloAST * thru) {
86    return CALL_BINARY_FUNCTOR(createScanThru, PabloAST::ClassTypeId::ScanThru, from, thru);
87}
88
89PabloAST * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr) {
90    return CALL_TERNARY_FUNCTOR(createSel, PabloAST::ClassTypeId::Sel, condition, trueExpr, falseExpr);
91}
92
93}
Note: See TracBrowser for help on using the repository browser.