summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/callgraph/fundec-graph.hh
diff options
context:
space:
mode:
Diffstat (limited to 'tiger-compiler/src/callgraph/fundec-graph.hh')
-rw-r--r--tiger-compiler/src/callgraph/fundec-graph.hh76
1 files changed, 76 insertions, 0 deletions
diff --git a/tiger-compiler/src/callgraph/fundec-graph.hh b/tiger-compiler/src/callgraph/fundec-graph.hh
new file mode 100644
index 0000000..1addd0d
--- /dev/null
+++ b/tiger-compiler/src/callgraph/fundec-graph.hh
@@ -0,0 +1,76 @@
+/**
+ ** \file callgraph/fundec-graph.hh
+ ** \brief Declare and define fundec graph.
+ */
+
+#pragma once
+
+#include <map>
+
+#include <boost/graph/adjacency_list.hpp>
+
+#include <ast/function-dec.hh>
+#include <misc/graph.hh>
+
+namespace callgraph
+{
+ /*--------------.
+ | FundecGraph. |
+ `--------------*/
+
+ class FundecGraph : public misc::directed_graph<ast::FunctionDec*>
+ {
+ public:
+ /// Add a vertex to the graph, and attach a function definition to it.
+ void fundec_add(ast::FunctionDec* f);
+ /// Create an edge between two vertices, identified by the
+ /// FunctionDec attached to each of them.
+ void fundec_link(ast::FunctionDec* fu, ast::FunctionDec* fv);
+
+ /// Retrieve the vertex handle corresponding to a FunctionDec.
+ vertex_descriptor hfundec_get(ast::FunctionDec* f) const;
+
+ // Search if FunctionDec 'searched' is 'start' or one of its parent.
+ ast::FunctionDec* hfundec_deep_get(ast::FunctionDec* start,
+ ast::FunctionDec* searched) const;
+
+ protected:
+ /// Print the label of vertex of a graph.
+ std::ostream& vertex_print(vertex_descriptor v,
+ std::ostream& ostr) const override;
+
+ using hfundecs_type = std::map<ast::FunctionDec*, vertex_descriptor>;
+
+ hfundecs_type hfundecs;
+ };
+
+ using CallGraph = FundecGraph;
+ using ParentGraph = FundecGraph;
+
+ /*------------.
+ | Iterators. |
+ `------------*/
+
+ /// Iterator on the vertices of a FundecGraph.
+ using fundecgraph_vertex_iter_type =
+ boost::graph_traits<FundecGraph>::vertex_iterator;
+ /// Iterator on the edges of a FundecGraph.
+ using fundecgraph_edge_iter_type =
+ boost::graph_traits<FundecGraph>::edge_iterator;
+ /// Iterator on the neighborhood of a vertex of a FundecGraph.
+ using fundecgraph_neighb_iter_type =
+ boost::graph_traits<FundecGraph>::adjacency_iterator;
+
+ /// \name Aliases.
+ /// \{
+ /// Iterator on the vertices of a CallGraph.
+ using callgraph_vertex_iter_type = fundecgraph_vertex_iter_type;
+ /// Iterator on the neighborhood of a vertex of a CallGraph.
+ using callgraph_neighb_iter_type = fundecgraph_neighb_iter_type;
+ /// Iterator on the neighborhood of a vertex of a ParentGraph.
+ using parentgraph_neighb_iter_type = fundecgraph_neighb_iter_type;
+ /// \}
+
+} // namespace callgraph
+
+#include <callgraph/fundec-graph.hxx>