summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/inlining/pruner.cc
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/src/inlining/pruner.cc
add: added projectsHEADmain
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