summaryrefslogtreecommitdiff
path: root/src/binaryen-c.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/binaryen-c.cpp')
-rw-r--r--src/binaryen-c.cpp38
1 files changed, 14 insertions, 24 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp
index b13c0a11e..a2b40714d 100644
--- a/src/binaryen-c.cpp
+++ b/src/binaryen-c.cpp
@@ -33,7 +33,6 @@
#include "cfg/Relooper.h"
#include "ir/utils.h"
#include "shell-interface.h"
-#include "support/defaults.h"
using namespace wasm;
@@ -72,9 +71,7 @@ static std::mutex BinaryenFunctionMutex;
static std::mutex BinaryenFunctionTypeMutex;
// Optimization options
-static int optimizeLevel = BINARYEN_DEFAULT_OPTIMIZE_LEVEL;
-static int shrinkLevel = BINARYEN_DEFAULT_SHRINK_LEVEL;
-static bool debugInfo = BINARYEN_DEFAULT_DEBUG_INFO;
+static PassOptions globalPassOptions = PassOptions::getWithDefaultOptimizationOptions();
// Tracing support
@@ -385,6 +382,7 @@ BinaryenExpressionRef BinaryenBlock(BinaryenModuleRef module, const char* name,
std::cout << " BinaryenExpressionRef children[] = { ";
for (BinaryenIndex i = 0; i < numChildren; i++) {
if (i > 0) std::cout << ", ";
+ if (i % 6 == 5) std::cout << "\n "; // don't create hugely long lines
std::cout << "expressions[" << expressions[children[i]] << "]";
}
if (numChildren == 0) std::cout << "0"; // ensure the array is not empty, otherwise a compiler error on VS
@@ -2013,9 +2011,7 @@ void BinaryenModuleOptimize(BinaryenModuleRef module) {
Module* wasm = (Module*)module;
PassRunner passRunner(wasm);
- passRunner.options.optimizeLevel = optimizeLevel;
- passRunner.options.shrinkLevel = shrinkLevel;
- passRunner.options.debugInfo = debugInfo;
+ passRunner.options = globalPassOptions;
passRunner.addDefaultOptimizationPasses();
passRunner.run();
}
@@ -2025,7 +2021,7 @@ int BinaryenGetOptimizeLevel() {
std::cout << " BinaryenGetOptimizeLevel();\n";
}
- return optimizeLevel;
+ return globalPassOptions.optimizeLevel;
}
void BinaryenSetOptimizeLevel(int level) {
@@ -2033,7 +2029,7 @@ void BinaryenSetOptimizeLevel(int level) {
std::cout << " BinaryenSetOptimizeLevel(" << level << ");\n";
}
- optimizeLevel = level;
+ globalPassOptions.optimizeLevel = level;
}
int BinaryenGetShrinkLevel() {
@@ -2041,7 +2037,7 @@ int BinaryenGetShrinkLevel() {
std::cout << " BinaryenGetShrinkLevel();\n";
}
- return shrinkLevel;
+ return globalPassOptions.shrinkLevel;
}
void BinaryenSetShrinkLevel(int level) {
@@ -2049,7 +2045,7 @@ void BinaryenSetShrinkLevel(int level) {
std::cout << " BinaryenSetShrinkLevel(" << level << ");\n";
}
- shrinkLevel = level;
+ globalPassOptions.shrinkLevel = level;
}
int BinaryenGetDebugInfo() {
@@ -2057,7 +2053,7 @@ int BinaryenGetDebugInfo() {
std::cout << " BinaryenGetDebugInfo();\n";
}
- return debugInfo;
+ return globalPassOptions.debugInfo;
}
void BinaryenSetDebugInfo(int on) {
@@ -2065,7 +2061,7 @@ void BinaryenSetDebugInfo(int on) {
std::cout << " BinaryenSetDebugInfo(" << on << ");\n";
}
- debugInfo = bool(on);
+ globalPassOptions.debugInfo = bool(on);
}
void BinaryenModuleRunPasses(BinaryenModuleRef module, const char **passes, BinaryenIndex numPasses) {
@@ -2083,9 +2079,7 @@ void BinaryenModuleRunPasses(BinaryenModuleRef module, const char **passes, Bina
Module* wasm = (Module*)module;
PassRunner passRunner(wasm);
- passRunner.options.optimizeLevel = optimizeLevel;
- passRunner.options.shrinkLevel = shrinkLevel;
- passRunner.options.debugInfo = debugInfo;
+ passRunner.options = globalPassOptions;
for (BinaryenIndex i = 0; i < numPasses; i++) {
passRunner.add(passes[i]);
}
@@ -2099,7 +2093,7 @@ void BinaryenModuleAutoDrop(BinaryenModuleRef module) {
Module* wasm = (Module*)module;
PassRunner passRunner(wasm);
- passRunner.options.debugInfo = debugInfo;
+ passRunner.options = globalPassOptions;
passRunner.add<AutoDrop>();
passRunner.run();
}
@@ -2112,7 +2106,7 @@ size_t BinaryenModuleWrite(BinaryenModuleRef module, char* output, size_t output
Module* wasm = (Module*)module;
BufferWithRandomAccess buffer(false);
WasmBinaryWriter writer(wasm, buffer, false);
- writer.setNamesSection(debugInfo);
+ writer.setNamesSection(globalPassOptions.debugInfo);
writer.write();
size_t bytes = std::min(buffer.size(), outputSize);
std::copy_n(buffer.begin(), bytes, output);
@@ -2254,9 +2248,7 @@ void BinaryenFunctionOptimize(BinaryenFunctionRef func, BinaryenModuleRef module
Module* wasm = (Module*)module;
PassRunner passRunner(wasm);
- passRunner.options.optimizeLevel = optimizeLevel;
- passRunner.options.shrinkLevel = shrinkLevel;
- passRunner.options.debugInfo = debugInfo;
+ passRunner.options = globalPassOptions;
passRunner.addDefaultOptimizationPasses();
passRunner.runOnFunction((Function*)func);
}
@@ -2275,9 +2267,7 @@ void BinaryenFunctionRunPasses(BinaryenFunctionRef func, BinaryenModuleRef modul
Module* wasm = (Module*)module;
PassRunner passRunner(wasm);
- passRunner.options.optimizeLevel = optimizeLevel;
- passRunner.options.shrinkLevel = shrinkLevel;
- passRunner.options.debugInfo = debugInfo;
+ passRunner.options = globalPassOptions;
for (BinaryenIndex i = 0; i < numPasses; i++) {
passRunner.add(passes[i]);
}