summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/inlining/pruner.cc
diff options
context:
space:
mode:
Diffstat (limited to 'tiger-compiler/src/inlining/pruner.cc')
-rw-r--r--tiger-compiler/src/inlining/pruner.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/tiger-compiler/src/inlining/pruner.cc b/tiger-compiler/src/inlining/pruner.cc
new file mode 100644
index 0000000..edb20eb
--- /dev/null
+++ b/tiger-compiler/src/inlining/pruner.cc
@@ -0,0 +1,34 @@
+/**
+ ** \file inlining/pruner.cc
+ ** \brief Implementation of inlining::Pruner.
+ */
+
+#include <inlining/pruner.hh>
+
+namespace inlining
+{
+ using namespace ast;
+
+ ast::FunctionChunk* Pruner::prune(ast::FunctionChunk& e)
+ {
+ while (true)
+ {
+ auto [remove_begin, remove_end] =
+ std::ranges::remove_if(e, [&](ast::FunctionDec* func_dec) {
+ if (!func_dec->body_get() || func_dec->name_get() == "_main")
+ return false;
+ else
+ return called_functions_[func_dec->name_get()] == 0;
+ });
+
+ if (remove_begin == remove_end)
+ break;
+ e.erase(remove_begin, remove_end);
+ }
+
+ return new FunctionChunk(e.location_get(), &e.decs_get());
+ }
+
+ // FIXME: Some code was deleted here.
+
+} // namespace inlining