PandA-2024.02
call_graph.hpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
45 #ifndef CALL_GRAPH_HPP
46 #define CALL_GRAPH_HPP
47 #include "custom_map.hpp"
48 #include "custom_set.hpp"
49 #include "edge_info.hpp" // for EdgeInfo, EdgeIn...
50 #include "graph.hpp" // for graph, vertex
51 #include "graph_info.hpp" // for GraphInfo
52 #include "node_info.hpp" // for NodeInfo
53 #include "refcount.hpp" // for refcount, Refcou...
54 
55 #include <iosfwd> // for ostream
56 #include <string> // for string
57 
59 
60 #define STD_SELECTOR (1 << 0)
61 #define FEEDBACK_SELECTOR (1 << 1)
62 
66 struct FunctionInfo : public NodeInfo
67 {
69  unsigned int nodeID;
70 
74  FunctionInfo();
75 };
76 
80 struct FunctionEdgeInfo : public EdgeInfo
81 {
86 
87  enum class CallType
88  {
89  direct_call,
90  indirect_call,
91  function_address,
92  call_any
93  };
94 
99 };
102 
106 struct CallGraphInfo : public GraphInfo
107 {
108  public:
110  std::map<unsigned int, FunctionBehaviorRef> behaviors;
111 };
115 
120 {
121  public:
127  CallGraphsCollection(const CallGraphInfoRef call_graph_info, const ParameterConstRef _parameters);
128 
132  ~CallGraphsCollection() override;
133 
141  inline EdgeDescriptor AddEdge(const vertex source, const vertex target, const int selector)
142  {
143  if(ExistsEdge(source, target))
144  {
145  return AddSelector(source, target, selector);
146  }
147  else
148  {
149  return InternalAddEdge(source, target, selector, EdgeInfoRef(new FunctionEdgeInfo()));
150  }
151  }
152 };
156 
160 class CallGraph : public graph
161 {
162  public:
168  CallGraph(const CallGraphsCollectionRef call_graphs_collection, const int selector);
169 
176  CallGraph(const CallGraphsCollectionRef call_graphs_collection, const int selector,
177  const CustomUnorderedSet<vertex>& vertices);
178 
182  ~CallGraph() override;
183 
189  {
190  return RefcountCast<const FunctionEdgeInfo>(graph::CGetEdgeInfo(edge));
191  }
192 
198  {
199  return RefcountCast<const CallGraphInfo>(graph::CGetGraphInfo());
200  }
201 
207  {
208  return RefcountCast<CallGraphInfo>(graph::GetGraphInfo());
209  }
210 
215  void WriteDot(const std::string& file_name) const;
216 };
220 
225 {
226  private:
228  const std::map<unsigned int, FunctionBehaviorRef>& behaviors;
229 
230  public:
235  explicit FunctionWriter(const CallGraph* call_graph);
236 
242  void operator()(std::ostream& out, const vertex& v) const override;
243 };
244 
249 {
250  private:
252  const std::map<unsigned int, FunctionBehaviorRef>& behaviors;
253 
254  public:
259  explicit FunctionEdgeWriter(const CallGraph* call_graph);
260 
264  ~FunctionEdgeWriter() override;
265 
271  void operator()(std::ostream& out, const EdgeDescriptor& e) const override;
272 };
273 #endif
Information associated with a call_graph edge.
Definition: call_graph.hpp:80
Base class storing user data information to the whole graph.
Definition: graph_info.hpp:60
CustomOrderedSet< unsigned int > function_addresses
Definition: call_graph.hpp:85
string target
Definition: lenet_tvm.py:16
const std::map< unsigned int, FunctionBehaviorRef > & behaviors
reference to the behaviors
Definition: call_graph.hpp:252
Class specification of the graph structures.
Functor used by write_graphviz to write the label of the vertices of a function graph.
Definition: call_graph.hpp:224
const EdgeInfoConstRef CGetEdgeInfo(typename boost::graph_traits< graphs_collection >::vertex_descriptor source, typename boost::graph_traits< graphs_collection >::vertex_descriptor target) const
Get the edge property.
Definition: graph.hpp:811
Information associated with a call_graph node.
Definition: call_graph.hpp:66
redefinition of map to manage ordered/unordered structures
Functor used by write_graphviz to write the edges of a function graph.
Definition: call_graph.hpp:248
std::map< unsigned int, FunctionBehaviorRef > behaviors
reference to the behaviors
Definition: call_graph.hpp:110
The info associated with the call graph.
Definition: call_graph.hpp:106
This class is the view of a call graph.
Definition: call_graph.hpp:160
EdgeDescriptor AddEdge(const vertex source, const vertex target, const int selector)
Add an edge with empty information associated.
Definition: call_graph.hpp:141
FunctionInfo()
Constructor.
Definition: call_graph.cpp:59
Functor used to write the content of a vertex to dotty file.
Definition: graph.hpp:1406
CallGraphInfoRef GetCallGraphInfo()
Return the info associated with the call graph.
Definition: call_graph.hpp:206
unsigned int nodeID
this is the nodeID of the function associated with the vertex
Definition: call_graph.hpp:69
Base class description of data information associated with each node of a graph.
refcount< EdgeInfo > EdgeInfoRef
RefCount type definition of the edge_info class structure.
Definition: edge_info.hpp:67
redefinition of set to manage ordered/unordered structures
This class collects information concerning the set of functions that will be analyzed by the PandA fr...
Definition: call_graph.hpp:119
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
General class used to describe a graph in PandA.
Definition: graph.hpp:771
Base class storing user data information.
Definition: edge_info.hpp:55
Base class for graph property.
GraphInfoRef GetGraphInfo()
FIXME: this method should become protected and called by equivalent method in subclasses Get the grap...
Definition: graph.hpp:1051
Template definition of refcount.
Base class description of data information associated with each edge of a graph.
bulk graph.
Definition: graph.hpp:287
Functor used to write the content of the edges to a dotty file.
Definition: graph.hpp:1441
const GraphInfoConstRef CGetGraphInfo() const
FIXME: this method should become protected and called by equivalent method in subclasses Get the grap...
Definition: graph.hpp:1062
REF_FORWARD_DECL(FunctionBehavior)
const std::map< unsigned int, FunctionBehaviorRef > & behaviors
reference to the behaviors
Definition: call_graph.hpp:228
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
CustomOrderedSet< unsigned int > indirect_call_points
Definition: call_graph.hpp:84
CustomOrderedSet< unsigned int > direct_call_points
the index of the statements of the caller function where the target is called;
Definition: call_graph.hpp:83
const FunctionEdgeInfoConstRef CGetFunctionEdgeInfo(const EdgeDescriptor edge) const
Return the info associated with an edge.
Definition: call_graph.hpp:188
const CallGraphInfoConstRef CGetCallGraphInfo() const
Return the info associated with the call graph.
Definition: call_graph.hpp:197
boost::graph_traits< graph >::edge_descriptor EdgeDescriptor
edge definition.
Definition: graph.hpp:1316

Generated on Mon Feb 12 2024 13:02:50 for PandA-2024.02 by doxygen 1.8.13