blob: 3f6e6b960ef20dcf9a0de072eccbd4a44b6e3e9b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
|