Skip to content

Commit

Permalink
simplify PassRunner API, get a module directly
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken committed May 5, 2016
1 parent adda43e commit aa1cf3d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/asm2wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1725,12 +1725,12 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
}

void Asm2WasmBuilder::optimize() {
PassRunner passRunner(&allocator);
PassRunner passRunner(&wasm);
passRunner.addDefaultOptimizationPasses();
if (maxGlobal < 1024) {
passRunner.add("post-emscripten");
}
passRunner.run(&wasm);
passRunner.run();
}

} // namespace wasm
Expand Down
4 changes: 2 additions & 2 deletions src/binaryen-shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ int main(int argc, const char* argv[]) {

if (passes.size() > 0) {
if (options.debug) std::cerr << "running passes...\n";
PassRunner passRunner(&moreModuleAllocations);
PassRunner passRunner(&wasm);
if (options.debug) passRunner.setDebug(true);
for (auto& passName : passes) {
if (passName == "O") {
Expand All @@ -232,7 +232,7 @@ int main(int argc, const char* argv[]) {
passRunner.add(passName);
}
}
passRunner.run(&wasm);
passRunner.run();
}

run_asserts(&i, &checked, &wasm, &root, &builder, entry);
Expand Down
4 changes: 2 additions & 2 deletions src/pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void PassRunner::addDefaultOptimizationPasses() {
add("optimize-instructions");
}

void PassRunner::run(Module* module) {
void PassRunner::run() {
std::chrono::high_resolution_clock::time_point beforeEverything;
size_t padding = 0;
if (debug) {
Expand All @@ -88,7 +88,7 @@ void PassRunner::run(Module* module) {
}
before = std::chrono::high_resolution_clock::now();
}
pass->run(this, module);
pass->run(this, wasm);
if (debug) {
auto after = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = after - before;
Expand Down
5 changes: 3 additions & 2 deletions src/pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ struct RegisterPass {
// Runs a set of passes, in order
//
struct PassRunner {
Module* wasm;
MixedArena* allocator;
std::vector<Pass*> passes;
Pass* currPass;
bool debug = false;

PassRunner(MixedArena* allocator) : allocator(allocator) {}
PassRunner(Module* wasm) : wasm(wasm), allocator(&wasm->allocator) {}

void setDebug(bool debug_) { debug = debug_; }

Expand All @@ -95,7 +96,7 @@ struct PassRunner {
// what -O does.
void addDefaultOptimizationPasses();

void run(Module* module);
void run();

// Get the last pass that was already executed of a certain type.
template<class P>
Expand Down
4 changes: 2 additions & 2 deletions src/wasm-printing.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ namespace wasm {

struct WasmPrinter {
static std::ostream& printModule(Module* module, std::ostream& o) {
PassRunner passRunner(nullptr);
PassRunner passRunner(module);
passRunner.add<Printer>(o);
passRunner.run(module);
passRunner.run();
return o;
}

Expand Down

0 comments on commit aa1cf3d

Please sign in to comment.