diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
| commit | 967be9e750221ab2ab783f95df79bb26d290a45e (patch) | |
| tree | 6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/src/callgraph/call-graph-visitor.cc | |
Diffstat (limited to 'tiger-compiler/src/callgraph/call-graph-visitor.cc')
| -rw-r--r-- | tiger-compiler/src/callgraph/call-graph-visitor.cc | 56 |
1 files changed, 56 insertions, 0 deletions
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 <ast/call-exp.hh> +#include <ast/function-dec.hh> +#include <callgraph/call-graph-visitor.hh> + +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<CallGraph*>(create(const_cast<const ast::Ast&>(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<ast::FunctionDec*>(&e); + super_type::operator()(e); + caller = save; + } + +} // namespace callgraph |
