blob: 25e7a41e51143760fa7ef649a05f3eddc09b7723 (
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#include <pass.h>
namespace wasm {
// PassRegistry
PassRegistry* PassRegistry::get() {
static PassRegistry* manager = nullptr;
if (!manager) {
manager = new PassRegistry();
}
return manager;
}
void PassRegistry::registerPass(const char* name, Creator create) {
assert(passCreatorMap.find(name) == passCreatorMap.end());
passCreatorMap[name] = create;
}
Pass* PassRegistry::createPass(std::string name) {
Creator creator = passCreatorMap[name];
if (!creator) return nullptr;
return creator();
}
std::vector<std::string> PassRegistry::getRegisteredNames() {
std::vector<std::string> ret;
for (auto pair : passCreatorMap) {
ret.push_back(pair.first);
}
return ret;
}
// PassRunner
void PassRunner::add(std::string passName) {
passes.push_back(PassRegistry::get()->createPass(passName));
}
template<class P>
void PassRunner::add() {
passes.push_back(new P());
}
void PassRunner::run(Module* module) {
for (auto pass : passes) {
currPass = pass;
pass->run(this, module);
}
}
template<class P>
P* PassRunner::getLast() {
bool found = false;
P* ret;
for (int i = passes.size() - 1; i >= 0; i--) {
if (found && (ret = dynamic_cast<P*>(passes[i]))) {
return ret;
}
if (passes[i] == currPass) {
found = true;
}
}
return nullptr;
}
PassRunner::~PassRunner() {
for (auto pass : passes) {
delete(pass);
}
}
} // namespace wasm
|