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

Last change on this file since 4602 was 4602, checked in by nmedfort, 4 years ago

Fixed PabloBuilder? and intergrated it into CC Compiler.

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