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/call-graph-visitor.cc | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tiger-compiler/src/callgraph/call-graph-visitor.cc (limited to 'tiger-compiler/src/callgraph/call-graph-visitor.cc') diff --git a/tiger-compiler/src/callgraph/call-graph-visitor.cc b/tiger-compiler/src/callgraph/call-graph-visitor.cc new file mode 100644 index 0000000..6ad31c5 --- /dev/null +++ b/tiger-compiler/src/callgraph/call-graph-visitor.cc @@ -0,0 +1,56 @@ +/** + ** \file callgraph/call-graph-visitor.cc + ** \brief Implementation of callgraph::CallGraphVisitor. + **/ + +#include +#include +#include + +namespace callgraph +{ + const CallGraph* CallGraphVisitor::create(const ast::Ast& tree) + { + // Create a new empty callgraph + callgraph_ = new CallGraph(); + + // Launch visitor. + tree.accept(*this); + + // Return created callgraph. + return callgraph_; + } + + CallGraph* CallGraphVisitor::create(ast::Ast& tree) + { + return const_cast(create(const_cast(tree))); + } + + /*-----------. + | Visiting. | + `-----------*/ + + void CallGraphVisitor::operator()(const ast::CallExp& e) + { + // FIXME: Some code was deleted here (Link the Caller with the CallExp's declaration). + } + + void CallGraphVisitor::operator()(const ast::FunctionChunk& e) + { + // First define the nodes for each defined function. + for (ast::FunctionDec* f : e) + callgraph_->fundec_add(f); + // Now bind callers and callees. + super_type::operator()(e); + } + + void CallGraphVisitor::operator()(const ast::FunctionDec& e) + { + // Current function becomes temporarily the caller function. + ast::FunctionDec* save = caller; + caller = const_cast(&e); + super_type::operator()(e); + caller = save; + } + +} // namespace callgraph -- cgit v1.2.3