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 --- .../src/callgraph/parent-graph-visitor.cc | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tiger-compiler/src/callgraph/parent-graph-visitor.cc (limited to 'tiger-compiler/src/callgraph/parent-graph-visitor.cc') diff --git a/tiger-compiler/src/callgraph/parent-graph-visitor.cc b/tiger-compiler/src/callgraph/parent-graph-visitor.cc new file mode 100644 index 0000000..f99121d --- /dev/null +++ b/tiger-compiler/src/callgraph/parent-graph-visitor.cc @@ -0,0 +1,42 @@ +/** + ** \file callgraph/parent-graph-visitor.cc + ** \brief Implementation for callgraph::ParentGraphVisitor. + **/ + +#include +#include + +namespace callgraph +{ + ParentGraph* ParentGraphVisitor::create(ast::Ast& tree) + { + // Create a new empty parentgraph + parentgraph = new ParentGraph(); + + // Launch visitor. + tree.accept(*this); + + // Return created parentgraph. + return parentgraph; + } + + void ParentGraphVisitor::operator()(ast::FunctionChunk& e) + { + for (ast::FunctionDec* f : e) + { + parentgraph->fundec_add(f); + parentgraph->fundec_link(f, parent); + } + super_type::operator()(e); + } + + void ParentGraphVisitor::operator()(ast::FunctionDec& e) + { + // Current function becomes temporarily the parent function. + ast::FunctionDec* tmp = parent; + parent = &e; + super_type::operator()(e); + parent = tmp; + } + +} // namespace callgraph -- cgit v1.2.3