ROSE  0.11.145.0
newCallGraph.h
1 
2 // DQ (6/30/2015): This is a new call graph analysis designed to support intremental
3 // generation of the a dot file representing the call graph of an application as it
4 // is compiled file by file. It is the start of a different sort fo ultifile support
5 // in ROSE.
6 
7 namespace NewCallGraph
8  {
9 
11  {
12  // Express nodes in terms of function declarations for now.
13  // Later this will have to be mangled names.
14  public:
16  SgFunctionDeclaration* functionDeclaration;
17 
18  // Avoid redundant nodes (e.g. inlined functions that would be seen in each translation unit).
19  bool skip_writing_out_to_file;
20  };
21 
23  {
24  // Express edges in terms of links between nodes.
25  public:
26  // SgFunctionDeclaration* from_functionDeclaration;
27  // SgFunctionDeclaration* to_functionDeclaration;
29  CallGraphNodeInfo* from;
31 
32  // Avoid redundant edges (e.g. function call in inlined functions that would be seen in each translation unit).
33  bool skip_writing_out_to_file;
34  };
35 
37  {
38  public:
39  std::map<std::string,CallGraphNodeInfo*> nodeMap;
40  std::map<std::string,CallGraphEdgeInfo*> edgeMap;
41 
42  CallGraph();
43  void visit ( SgNode* astNode );
44  };
45 
47  {
48  // This data type is used to write the call graph nodes and edges to a file
49  // to support accumulation of multiple file data.
50 
51  // Note:
52  // 1) If we want to write and read variable length strings then we would have
53  // to write the size of the string into the binary file, read that value, then
54  // read that many bytes and put the data into a string.
55  // 2) We could also write out a table into the top of the binary file to hold
56  // all of the file names, directory names, and command lines used to compile the
57  // source files to generate each function. This would be a space optimization,
58  // to be done later.
59 
60 #define functionNameLength 256
61 #define fileNameLength 256
62 #define directoryLength 1000
63 #define commandlineLength 2000
64 
65  public:
66  // const size_t functionNameLength;
67  // const size_t fileNameLength;
68 
69  bool isNode; // if not a node then this is a call graph edge.
70  bool isDefiningDeclaration;
71  char function_name[functionNameLength]; // If this is an edge this is the "from" function.
72 #if 0
73  // Use of a union is just a space optimization.
74  union name_data
75  {
76  char function_call_name[functionNameLength]; // if this is an edge then this is the "to" function.
77  char file_name[fileNameLength]; // if this is a node then this is the absolute path with the filename for the function.
78  };
79 #else
80  char function_call_name[functionNameLength]; // if this is an edge then this is the "to" function.
81  char file_name[fileNameLength]; // if this is a node then this is the absolute path with the filename for the function.
82 #endif
83  // If this is an node then this is the location from which to compile the source code (using the saved command line).
84  char directoryToUseInCompilingSourceFile[directoryLength];
85 
86  // This is a potentially very long string.
87  // If this is an node then this is the command line required to compile the source file to generate the AST for the defining function declaration.
88  char commandlineToCompileSourceFile[commandlineLength];
89 
91  };
92 
93  // File support
94  int getLock();
95  void releaseLock (int fd );
96  void generateCallGraphFile(SgProject* project, CallGraph & cg);
97  // void readCallGraphFile(SgProject* project, CallGraph & cg);
98  std::vector<CallGraphFileStructure>* readCallGraphFile(std::string binaryFilename);
99 
100  // Write out the dot file for the call graph (uses data from whatever is written in the binary file).
101  void generateDotFile (std::string binaryFilename);
102 
103  // API function
104  int buildCallGraph (SgProject* project);
105  }
This class represents the concept of a function declaration statement.
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:9846
void visit(SgNode *astNode)
this method is called at every traversed node.
This class represents a source project, with a list of SgFile objects and global information about th...