1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
//
// Created by ztuowen on 9/24/16.
//
#include "printers/dump.h"
using namespace chill::printer;
using namespace std;
void dumpVector(GenericPrinter *p, string ident, chillAST_NodeList *n, ostringstream &o) {
for (int i = 0; i < n->size(); ++i)
p->print("", (*n)[i], o);
}
void Dump::print(string ident, chillAST_Node *n, ostringStream &o) {
o << "(" << n->getTypeString() << " ";
if (n->getParameters()) {
o << "(Params: ";
dumpVector(this, ident, n->getParameters(), o);
o << ") ";
}
if (n->getSymbolTable()) {
o << "(VarScope: ";
dumpVector(this, ident, n->getSymbolTable(), o);
o << ") ";
}
if (n->getTypedefTable()) {
o << "(TypeDef: ";
dumpVector(this, ident, n->getTypedefTable(), o);
o << ") ";
}
o << ": ";
// Recurse
GenericPrinter::print(ident, n, o);
o << ") ";
}
void Dump::print(std::string ident, chillAST_ArraySubscriptExpr *n, std::ostringstream &o);
void Dump::print(std::string ident, chillAST_BinaryOperator *n, std::ostringstream &o);
void Dump::print(std::string ident, chillAST_CallExpr *n, std::ostringstream &o);
void Dump::print(std::string ident, chillAST_CompoundStmt *n, std::ostringstream &o);
void Dump::print(std::string ident, chillAST_CStyleAddressOf *n, std::ostringstream &o);
void Dump::print(std::string ident, chillAST_CStyleCastExpr *n, std::ostringstream &o);
void Dump::print(std::string ident, chillAST_CudaFree *n, std::ostringstream &o);
void Dump::print(std::string ident, chillAST_CudaKernelCall *n, std::ostringstream &o);
void Dump::print(std::string ident, chillAST_CudaMalloc *n, std::ostringstream &o) {
print(ident, n->devPtr, o);
print(ident, n->sizeinbytes, o);
}
void Dump::print(std::string ident, chillAST_CudaMemcpy *n, std::ostringstream &o) {
o << cudaMemcpyKind << " ";
print(ident, n->dest, o);
print(ident, n->src, o);
print(ident, n->size, o);
};
void Dump::print(std::string ident, chillAST_CudaSyncthreads *n, std::ostringstream &o);
void Dump::print(std::string ident, chillAST_DeclRefExpr *n, std::ostringstream &o) {
chillAST_VarDecl *vd = n->getVarDecl();
if (vd)
if (vd->isAParameter) o << "ParmVar "; else o << "Var ";
o << n->declarationName << " ";
chillAST_FunctionDecl *fd = n->getFunctionDecl();
if (fd) dumpVector(this, ident, fd->getParameters(), o);
}
void Dump::print(std::string ident, chillAST_FloatingLiteral *n, std::ostringstream &o);
void Dump::print(std::string ident, chillAST_ForStmt *n, std::ostringstream &o) {
print(ident, n->init, o);
print(ident, n->cond, o);
print(ident, n->incr, o);
print(ident, n->body, o);
}
void Dump::print(std::string ident, chillAST_Free *n, std::ostringstream &o);
void Dump::print(std::string ident, chillAST_FunctionDecl *n, std::ostringstream &o) {
if (n->filename) o << filename << " ";
if (n->isFromSourceFile) o << "FromSourceFile" << " ";
o << n->returnType << " " << n->functionName << " ";
if (n->body) print(ident, n->body, o);
}
void Dump::print(std::string ident, chillAST_IfStmt *n, std::ostringstream &o) {
print(ident, n->cond, o);
print(ident, n->thenpart, o);
if (n->elsepart)
print(ident, n->elsepart, o);
}
void Dump::print(std::string ident, chillAST_IntegerLiteral *n, std::ostringstream &o);
void Dump::print(std::string ident, chillAST_ImplicitCastExpr *n, std::ostringstream &o) {
print(ident, n->subexpr, o);
}
void Dump::print(std::string ident, chillAST_MacroDefinition *n, std::ostringstream &o) {
o << n->macroName << " ";
dumpVector(this, ident, n->getParameters(), o);
print(ident, n->getBody(), o);
if (n->rhsString) o << " (aka " << n->rhsString << ") ";
}
void Dump::print(std::string ident, chillAST_Malloc *n, std::ostringstream &o) {
print(ident, n->sizeexpr, o);
}
void Dump::print(std::string ident, chillAST_MemberExpr *n, std::ostringstream &o) {
print(ident, n->base, o);
if (n->exptype == CHILLAST_MEMBER_EXP_ARROW) o << "-> ";
else o << ". ";
o << n->member << " ";
}
void Dump::print(std::string ident, chillAST_NULL *n, std::ostringstream &o) {
o << "(NULL) ";
}
void Dump::print(std::string ident, chillAST_NoOp *n, std::ostringstream &o) {};
void Dump::print(std::string ident, chillAST_ParenExpr *n, std::ostringstream &o);
void Dump::print(std::string ident, chillAST_Preprocessing *n, std::ostringstream &o);
void Dump::print(std::string ident, chillAST_RecordDecl *n, std::ostringstream &o) {
// TODO access control
o << n->getName() << " ";
o << n->isAStruct() << " ";
o << n->isAUnion() << " ";
}
void Dump::print(std::string ident, chillAST_ReturnStmt *n, std::ostringstream &o) {
if (n->returnvalue) print(ident, n->returnvalue, o);
}
void Dump::print(std::string ident, chillAST_Sizeof *n, std::ostringstream &o);
void Dump::print(std::string ident, chillAST_SourceFile *n, std::ostringstream &o);
void Dump::print(std::string ident, chillAST_TypedefDecl *n, std::ostringstream &o) {
o << n->underlyingtype << " " << n->newtype << " " << n->arraypart << " ";
}
void Dump::print(std::string ident, chillAST_TernaryOperator *n, std::ostringstream &o);
void Dump::print(std::string ident, chillAST_UnaryOperator *n, std::ostringstream &o);
void Dump::print(std::string ident, chillAST_VarDecl *n, std::ostringstream &o);
|