forked from dyninst/dyninst
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopTreeNode.tex
More file actions
82 lines (68 loc) · 2.79 KB
/
Copy pathLoopTreeNode.tex
File metadata and controls
82 lines (68 loc) · 2.79 KB
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
\subsection{Class LoopTreeNode}
\definedin{CFG.h}
The LoopTreeNode class provides a tree interface to a collection of instances of class
Loop contained in a function. The structure of the tree
follows the nesting relationship of the loops in a function.
Each LoopTreeNode contains a pointer to a loop (represented by Loop), and a set
of sub-loops (represented by other LoopTreeNode objects). The \code{loop} field
at the root node is always \code{NULL} since a function may contain multiple outer
loops. The \code{loop} field is never \code{NULL} at any other node since it
always corresponds to a real loop.
Therefore, the outer most loops in the function are contained in the vector of \code{children} of the root.
Each instance of LoopTreeNode is given a name that indicates its position in the hierarchy of loops.
The name of each outermost loop takes the form of \code{loop\_x},
where \code{x} is an integer from 1 to n,
where n is the number of outer loops in the function.
Each sub-loop has the name of its parent,
followed by a \code{.y}, where \code{y} is 1 to m, where m is the number of sub-loops under the outer loop.
For example, consider the following C function:
\lstset{language=[GNU]C++,basicstyle=\fontfamily{fvm}\selectfont\small}
\lstset{showstringspaces=false, numbers=none}
\begin{lstlisting}
void foo() {
int x, y, z, i;
for (x=0; x<10; x++) {
for (y = 0; y<10; y++)
...
for (z = 0; z<10; z++)
...
}
for (i = 0; i<10; i++) {
...
}
}
\end{lstlisting}
The \code{foo} function will have a root LoopTreeNode, containing a NULL loop entry and
two LoopTreeNode children representing the functions outermost loops. These children
would have names \code{loop\_1} and \code{loop\_2}, respectively representing the \code{x} and \code{i} loops. \code{loop\_2} has
no children. \code{loop\_1} has two child LoopTreeNode objects, named
\code{loop\_1.1} and
\code{loop\_1.2}, respectively representing the \code{y} and \code{z} loops.
\begin{apient}
Loop *loop;
\end{apient}
\apidesc{The Loop instance it points to.}
\begin{apient}
std::vector<LoopTreeNode *> children;
\end{apient}
\apidesc{The LoopTreeNode instances nested within this loop.}
\begin{apient}
const char * name();
\end{apient}
\apidesc{Returns the hierarchical name of this loop.}
\begin{apient}
const char * getCalleeName(unsigned int i)
\end{apient}
\apidesc{Returns the function name of the ith callee.}
\begin{apient}
unsigned int numCallees()
\end{apient}
\apidesc{Returns the number of callees contained in this loop's body.}
\begin{apient}
bool getCallees(vector<Function *> &v);
\end{apient}
\apidesc{Fills \code{v} with a vector of the functions called inside this loop.}
\begin{apient}
Loop * findLoop(const char *name);
\end{apient}
\apidesc{Looks up a loop by the hierarchical name}