PandA-2024.02
call_graph_manager.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_MANAGER_HPP
46 #define CALL_GRAPH_MANAGER_HPP
47 
48 #include "call_graph.hpp" // for CallGraph (ptr o...
49 #include "custom_map.hpp"
50 #include "custom_set.hpp"
51 #include "graph.hpp" // for vertex, EdgeDesc...
52 #include "refcount.hpp" // for CONSTREF_FORWARD...
53 #include <boost/graph/depth_first_search.hpp> // for default_dfs_visitor
54 
67 
72 {
73  private:
74  friend class call_graph_computation;
75 
77 
80 
83 
85  std::map<unsigned int, CustomSet<unsigned int>> called_by;
86 
88  std::map<unsigned int, vertex> functionID_vertex_map;
89 
92 
95 
98 
101 
104 
107 
109  const int debug_level;
110 
118  void AddCallPoint(unsigned int caller_id, unsigned int called_id, unsigned int call_id,
119  enum FunctionEdgeInfo::CallType call_type);
128  void AddFunctionAndCallPoint(unsigned int caller_id, unsigned int called_id, unsigned int call_id,
129  const FunctionBehaviorRef called_function_behavior,
130  enum FunctionEdgeInfo::CallType call_type);
138  bool IsCallPoint(unsigned int caller_id, unsigned int called_id, unsigned int call_id,
139  enum FunctionEdgeInfo::CallType call_type) const;
140 
146 
147  public:
149  const FunctionExpanderConstRef function_expander;
150 
159  CallGraphManager(const FunctionExpanderConstRef function_expander, const bool allow_recursive_functions,
160  const tree_managerConstRef tree_manager, const ParameterConstRef Param);
161 
166 
171 
176 
182 
187  CustomSet<unsigned int> get_called_by(unsigned int index) const;
188 
194  CustomSet<unsigned int> get_called_by(const OpGraphConstRef cfg, const vertex& caller) const;
195 
201  unsigned int get_function(vertex node) const;
202 
208  vertex GetVertex(const unsigned int index) const;
209 
215  void SetRootFunctions(const CustomSet<unsigned int>& root_functions);
216 
222 
228 
235  CustomSet<unsigned int> GetReachedFunctionsFrom(unsigned int from_f, bool with_body = true) const;
236 
243  unsigned int GetRootFunction(unsigned int fid) const;
244 
250 
255  bool IsVertex(unsigned int functionID) const;
256 
261  void AddFunction(unsigned int new_function_id, const FunctionBehaviorRef fun_behavior);
262 
271  void AddFunctionAndCallPoint(const application_managerRef AppM, unsigned int caller_id, unsigned int called_id,
272  unsigned int call_id, enum FunctionEdgeInfo::CallType call_type);
273 
280  void RemoveCallPoint(const unsigned int caller_id, const unsigned int called_id, const unsigned int call_id);
281 
287  void RemoveCallPoint(EdgeDescriptor e, const unsigned int callid);
288 
295  void ReplaceCallPoint(const EdgeDescriptor e, const unsigned int orig, const unsigned int repl);
296 
301  bool ExistsAddressedFunction() const;
302 
307 
316  unsigned int current, const tree_managerRef& TM, const tree_nodeRef& tn,
317  unsigned int node_stmt, enum FunctionEdgeInfo::CallType call_type,
318  int DL);
320  unsigned int f_id, int DL);
322  unsigned int caller_id, unsigned int called_id, unsigned int call_id,
323  enum FunctionEdgeInfo::CallType call_type, int DL);
324 };
325 
328 
329 #endif
bool IsCallPoint(unsigned int caller_id, unsigned int called_id, unsigned int call_id, enum FunctionEdgeInfo::CallType call_type) const
Returns true if the call point is present.
const CustomSet< unsigned int > & GetReachedBodyFunctions() const
Returns the source code functions called by the root functions.
CustomSet< unsigned int > GetRootFunctions() const
Returns the root functions (i.e., the functions that are not called by any other ones.
CustomSet< unsigned int > reached_body_functions
source code functions directly or indirectly called by the root functions
This class manages the tree structures extracted from the raw file.
CustomSet< unsigned int > addressed_functions
set of functions whose address is taken
Class specification of the graph structures.
const tree_managerConstRef tree_manager
The tree manager.
CallGraphManager(const FunctionExpanderConstRef function_expander, const bool allow_recursive_functions, const tree_managerConstRef tree_manager, const ParameterConstRef Param)
Constructor.
CustomSet< unsigned int > GetAddressedFunctions() const
Returns a set containing all the reachable addressed_functions.
std::map< unsigned int, vertex > functionID_vertex_map
put into relation function F_i and the vertex in the call graph representing it
redefinition of map to manage ordered/unordered structures
CustomSet< unsigned int > root_functions
Root functions.
Build call graph structures starting from the tree_manager.
Abstract pure class for the tree structure.
Definition: tree_node.hpp:139
unsigned int get_function(vertex node) const
Given a vertex of the call graph, this returns the index of the corresponding function.
const FunctionExpanderConstRef function_expander
Functor used to check if the analysis should consider the body of a function.
static void addCallPointAndExpand(CustomUnorderedSet< unsigned int > &AV, const application_managerRef AM, unsigned int caller_id, unsigned int called_id, unsigned int call_id, enum FunctionEdgeInfo::CallType call_type, int DL)
This class is the view of a call graph.
Definition: call_graph.hpp:160
const bool allow_recursive_functions
True if recursive calls are allowed.
std::map< unsigned int, CustomSet< unsigned int > > called_by
put into relation function F_i and the list of functions called by F_i
static void call_graph_computation_recursive(CustomUnorderedSet< unsigned int > &AV, const application_managerRef AM, unsigned int current, const tree_managerRef &TM, const tree_nodeRef &tn, unsigned int node_stmt, enum FunctionEdgeInfo::CallType call_type, int DL)
Recursive analysis of the tree nodes looking for call expressions.
CustomSet< unsigned int > reached_library_functions
library functions directly or indirectly called by the root functions
#define index(x, y)
Definition: Keccak.c:74
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
void ReplaceCallPoint(const EdgeDescriptor e, const unsigned int orig, const unsigned int repl)
Replaces a call point.
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
void AddCallPoint(unsigned int caller_id, unsigned int called_id, unsigned int call_id, enum FunctionEdgeInfo::CallType call_type)
Creates a new call point.
CallGraphConstRef CGetCallGraph() const
Return the call graph.
Call graph hierarchy.
used to avoid expansion of c library function or type
Template definition of refcount.
bool ExistsAddressedFunction() const
Returns true is there is at least a reachable function that is called through a function pointer or i...
CustomSet< unsigned int > GetReachedFunctionsFrom(unsigned int from_f, bool with_body=true) const
compute the list of reached function starting from a given function
const int debug_level
the debug level
void AddFunctionAndCallPoint(unsigned int caller_id, unsigned int called_id, unsigned int call_id, const FunctionBehaviorRef called_function_behavior, enum FunctionEdgeInfo::CallType call_type)
Creates a new called function and directly adds the call to the call graph.
CustomSet< unsigned int > get_called_by(unsigned int index) const
Returns the set of functions called by a function.
const ParameterConstRef Param
set of input parameters
const application_managerRef AppM
The application manager.
REF_FORWARD_DECL(application_manager)
CustomSet< unsigned int > GetReachedLibraryFunctions() const
Returns the library functions called by the root functions.
~CallGraphManager()
Destructor.
This class manages the accesses to the CallGraph.
void RemoveCallPoint(const unsigned int caller_id, const unsigned int called_id, const unsigned int call_id)
Remove a function call, like RemoveCallPoint with a different API.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
void ComputeRootAndReachedFunctions()
Compute the root and reached functions, maintaining the internal data structures coherent.
unsigned int GetRootFunction(unsigned int fid) const
Get the parent root function.
CallGraphConstRef CGetCallSubGraph(const CustomUnorderedSet< vertex > &vertices) const
Return a subset of the call graph.
void AddFunction(unsigned int new_function_id, const FunctionBehaviorRef fun_behavior)
Class used to describe a particular graph with operations as nodes.
Definition: op_graph.hpp:783
vertex GetVertex(const unsigned int index) const
Return the vertex given the function id.
CallGraphConstRef CGetAcyclicCallGraph() const
Return an acyclic version of the call graph.
bool IsVertex(unsigned int functionID) const
return true in case the vertex has been already created
void SetRootFunctions(const CustomSet< unsigned int > &root_functions)
Set the root functions.
const CallGraphsCollectionRef call_graphs_collection
static void expandCallGraphFromFunction(CustomUnorderedSet< unsigned int > &AV, const application_managerRef AM, unsigned int f_id, int DL)
const CallGraphRef call_graph
The view of call graph with all the edges.
CONSTREF_FORWARD_DECL(application_manager)
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