OpenADFortTk (including Open64 and OpenAnalysis references)
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
EvalToConstVisitor.cpp
Go to the documentation of this file.
1
15
#include <
OpenAnalysis/ExprTree/EvalToConstVisitor.hpp
>
16
17
static
bool
debug
=
false
;
18
19
namespace
OA {
20
21
22
EvalToConstVisitor::EvalToConstVisitor
(
OA_ptr<EvalToConstVisitorIRInterface>
ir,
23
OA_ptr<ReachConsts::Interface>
rc)
24
: mIR(ir), mReachConsts(rc)
25
{
26
mEvalResult
=
NULL
;
27
}
28
31
void
EvalToConstVisitor::visitNode
(
ExprTree::Node
&)
32
{
33
mEvalResult
=
NULL
;
34
}
35
36
void
EvalToConstVisitor::visitOpNode
(
ExprTree::OpNode
&
n
)
37
{
38
OpHandle
opH = n.
getHandle
();
39
OA_ptr<ConstValBasicInterface>
ch1; ch1 =
NULL
;
40
OA_ptr<ConstValBasicInterface>
ch2; ch2 =
NULL
;
41
42
if
(
debug
){
43
std::cout <<
"In EvalToConstVisitor::visitOpNode---> OP="
44
<<
mIR
->returnOpEnumValInt(opH)
45
<<
" ("
<< n.
num_children
() <<
" children), "
;
46
}
47
48
// check that there are at most 2 children
49
if
( n.
num_children
() <= 2 ) {
50
51
// if so then visit each child
52
OA_ptr<ExprTree::Node>
cetNodePtr;
53
ExprTree::ChildNodesIterator
cNodesIter(n);
54
55
// child1
56
if
(cNodesIter.
isValid
()) {
57
cetNodePtr = cNodesIter.
current
();
58
59
cetNodePtr->acceptVisitor(*
this
);
60
ch1 =
getConstVal
();
61
}
62
++cNodesIter;
63
64
// child2
65
if
(cNodesIter.
isValid
()) {
66
cetNodePtr = cNodesIter.
current
();
67
68
cetNodePtr->acceptVisitor(*
this
);
69
ch2 =
getConstVal
();
70
}
71
72
if
(
debug
){
73
std::cout <<
" with children { ("
;
74
if
(ch1.
ptrEqual
(
NULL
)) {
75
std::cout <<
"NULL"
;
76
}
else
{
77
std::cout << ch1->toString();
78
}
79
std::cout <<
") ("
;
80
if
(ch2.
ptrEqual
(
NULL
)) {
81
std::cout <<
"NULL"
;
82
}
else
{
83
std::cout << ch2->toString();
84
}
85
std::cout <<
")"
<< std::endl;
86
std::cout.flush();
87
}
88
89
mEvalResult
=
mIR
->evalOp(opH,ch1,ch2);
90
91
// there are more than 2 children
92
}
else
{
93
mEvalResult
=
NULL
;
94
}
95
96
if
(
debug
) {
97
if
(
mEvalResult
.ptrEqual(
NULL
)) {
98
std::cout <<
" } evalResult (NULL)"
<< std::endl;
99
}
else
{
100
std::cout <<
" } evalResult ("
<<
mEvalResult
->toString()
101
<<
")"
<< std::endl;
102
}
103
}
104
105
}
106
107
void
EvalToConstVisitor::visitCallNode
(
ExprTree::CallNode
&
n
)
108
{
109
mEvalResult
=
NULL
;
110
}
111
112
void
EvalToConstVisitor::visitMemRefNode
(
ExprTree::MemRefNode
&
n
)
113
{
114
MemRefHandle
memref = n.
getHandle
();
115
116
//ConstValBasicInterface *cvbiPtr = cpPtr->getReachConst(memref);
117
//std::cout << "In MemRefNode::eval---> got memref (" << mIR->toString(memref)
118
// << ") with ReachConst (" << cvbiPtr->toString() << ")"
119
// << std::endl;
120
121
if
(
mReachConsts
.
ptrEqual
(
NULL
)) {
122
mEvalResult
=
NULL
;
123
}
else
{
124
// if this memref has its address taken, then this should result
125
// in no constant value. need to check this ... BK
126
mEvalResult
=
mReachConsts
->
getReachConst
(memref);
127
}
128
129
}
130
131
void
EvalToConstVisitor::visitConstSymNode
(
ExprTree::ConstSymNode
&
n
)
132
{
133
mEvalResult
=
mIR
->getConstValBasic(n.
getHandle
());
134
}
135
136
void
EvalToConstVisitor::visitConstValNode
(
ExprTree::ConstValNode
&
n
)
137
{
138
mEvalResult
=
mIR
->getConstValBasic(n.
getHandle
());
139
}
140
141
142
}
// end of OA namespace
143
OpenAnalysis
src
OpenAnalysis
ExprTree
EvalToConstVisitor.cpp
Generated on Fri Mar 14 2014 04:23:10 for OpenADFortTk (including Open64 and OpenAnalysis references) by
1.8.4