From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- tiger-compiler/src/callgraph/fundec-graph.hh | 76 ++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tiger-compiler/src/callgraph/fundec-graph.hh (limited to 'tiger-compiler/src/callgraph/fundec-graph.hh') 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 + +#include + +#include +#include + +namespace callgraph +{ + /*--------------. + | FundecGraph. | + `--------------*/ + + class FundecGraph : public misc::directed_graph + { + 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; + + 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::vertex_iterator; + /// Iterator on the edges of a FundecGraph. + using fundecgraph_edge_iter_type = + boost::graph_traits::edge_iterator; + /// Iterator on the neighborhood of a vertex of a FundecGraph. + using fundecgraph_neighb_iter_type = + boost::graph_traits::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 -- cgit v1.2.3