diff options
Diffstat (limited to 'tiger-compiler/src/inlining/libinlining.cc')
| -rw-r--r-- | tiger-compiler/src/inlining/libinlining.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tiger-compiler/src/inlining/libinlining.cc b/tiger-compiler/src/inlining/libinlining.cc new file mode 100644 index 0000000..3f6e6b9 --- /dev/null +++ b/tiger-compiler/src/inlining/libinlining.cc @@ -0,0 +1,54 @@ +/** + ** \file inlining/libinlining.cc + ** \brief Functions exported by the inlining module. + */ + +#include <memory> + +#include <ast/exp.hh> +#include <desugar/libdesugar.hh> +#include <inlining/inliner.hh> +#include <inlining/libinlining.hh> +#include <inlining/pruner.hh> + +namespace inlining +{ + /*-----------. + | Inlining. | + `-----------*/ + + template <typename A> A* inline_expand(const A& tree) + { + // Inline. + Inliner inline_expand(tree); + inline_expand(tree); + A* inlined = dynamic_cast<A*>(inline_expand.result_get()); + assertion(inlined); + std::unique_ptr<A> inlined_ptr(inlined); + // Recompute the bindings and the types. + desugar::bind_and_types_check(*inlined_ptr); + return inlined_ptr.release(); + } + + template ast::ChunkList* inline_expand(const ast::ChunkList&); + + /*-------------------. + | Function pruning. | + `-------------------*/ + + template <typename A> A* prune(const A& tree) + { + // Prune unused functions. + Pruner prune; + prune(tree); + A* pruned = dynamic_cast<A*>(prune.result_get()); + assertion(pruned); + std::unique_ptr<A> pruned_ptr(pruned); + // Recompute the bindings and the types. + desugar::bind_and_types_check(*pruned_ptr); + return pruned_ptr.release(); + } + + template ast::ChunkList* prune(const ast::ChunkList&); + +} // namespace inlining |
