Skip to content

Commit 939706d

Browse files
authored
Avoid returning a PassRunner just for OptimizationOptions (#1234)
* avoid returning a PassRunner just for OptimizationOptions, it would need a more careful design with a copy constructor. instead, just simplify the API to do the thing we need, which is run the passes * disallow copy constructor * delete copy operator too
1 parent 23808ad commit 939706d

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/pass.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ struct PassRunner {
7676
PassRunner(Module* wasm) : wasm(wasm), allocator(&wasm->allocator) {}
7777
PassRunner(Module* wasm, PassOptions options) : wasm(wasm), allocator(&wasm->allocator), options(options) {}
7878

79+
// no copying, we control |passes|
80+
PassRunner(const PassRunner&) = delete;
81+
PassRunner& operator=(const PassRunner&) = delete;
82+
7983
void setDebug(bool debug_) {
8084
options.debug = debug_;
8185
options.validateGlobally = debug_; // validate everything by default if debugging

src/tools/optimization-options.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ struct OptimizationOptions : public Options {
115115
return passes.size() > 0;
116116
}
117117

118-
PassRunner getPassRunner(Module& wasm) {
118+
void runPasses(Module& wasm) {
119119
PassRunner passRunner(&wasm, passOptions);
120120
if (debug) passRunner.setDebug(true);
121121
for (auto& pass : passes) {
@@ -125,7 +125,7 @@ struct OptimizationOptions : public Options {
125125
passRunner.add(pass);
126126
}
127127
}
128-
return passRunner;
128+
passRunner.run();
129129
}
130130
};
131131

src/tools/wasm-opt.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ std::string runCommand(std::string command) {
6262

6363
int main(int argc, const char* argv[]) {
6464
Name entry;
65-
std::vector<std::string> passes;
6665
bool emitBinary = true;
6766
bool debugInfo = false;
6867
bool fuzzExec = false;
@@ -173,8 +172,7 @@ int main(int argc, const char* argv[]) {
173172

174173
if (options.runningPasses()) {
175174
if (options.debug) std::cerr << "running passes...\n";
176-
PassRunner passRunner = options.getPassRunner(wasm);
177-
passRunner.run();
175+
options.runPasses(wasm);
178176
assert(WasmValidator().validate(wasm));
179177
}
180178

0 commit comments

Comments
 (0)