diff options
author | Daniel Wirtz <dcode@dcode.io> | 2017-11-21 21:43:12 +0100 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2017-11-21 12:43:12 -0800 |
commit | eedcc291164a46474116e0e54ede3133214a7621 (patch) | |
tree | 6350e315b74464f48c4f02c6c77a1338b630e144 /src/binaryen-c.cpp | |
parent | 07c54750eb626ea7434341e439f6cee75efbf4b5 (diff) | |
download | binaryen-eedcc291164a46474116e0e54ede3133214a7621.tar.gz binaryen-eedcc291164a46474116e0e54ede3133214a7621.tar.bz2 binaryen-eedcc291164a46474116e0e54ede3133214a7621.zip |
Running passes on a single function in binaryen-c/.js (#1295)
* Also other function utilities in C and JS APIs
Diffstat (limited to 'src/binaryen-c.cpp')
-rw-r--r-- | src/binaryen-c.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 9b46f0aba..70c907666 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -912,6 +912,22 @@ BinaryenFunctionRef BinaryenAddFunction(BinaryenModuleRef module, const char* na return ret; } +BinaryenFunctionRef BinaryenGetFunction(BinaryenModuleRef module, const char* name) { + if (tracing) { + std::cout << " BinaryenGetFunction(the_module, \"" << name << "\");\n"; + } + + auto* wasm = (Module*)module; + return wasm->getFunction(name); +} +void BinaryenRemoveFunction(BinaryenModuleRef module, const char* name) { + if (tracing) { + std::cout << " BinaryenRemoveFunction(the_module, \"" << name << "\");\n"; + } + + auto* wasm = (Module*)module; + wasm->removeFunction(name); +} BinaryenGlobalRef BinaryenAddGlobal(BinaryenModuleRef module, const char* name, BinaryenType type, int8_t mutable_, BinaryenExpressionRef init) { if (tracing) { @@ -1214,6 +1230,50 @@ void BinaryenModuleInterpret(BinaryenModuleRef module) { } // +// ========== Function Operations ========== +// + +BinaryenExpressionRef BinaryenFunctionGetBody(BinaryenFunctionRef func) { + if (tracing) { + std::cout << " BinaryenFunctionGetBody(functions[" << functions[func] << "]);\n"; + } + + return ((Function*)func)->body; +} + +void BinaryenFunctionOptimize(BinaryenFunctionRef func, BinaryenModuleRef module) { + if (tracing) { + std::cout << " BinaryenFunctionOptimize(functions[" << functions[func] << "], the_module);\n"; + } + + Module* wasm = (Module*)module; + PassRunner passRunner(wasm); + passRunner.addDefaultOptimizationPasses(); + passRunner.runFunction((Function*)func); +} + +void BinaryenFunctionRunPasses(BinaryenFunctionRef func, BinaryenModuleRef module, const char **passes, BinaryenIndex numPasses) { + if (tracing) { + std::cout << " {\n"; + std::cout << " const char* passes[] = { "; + for (BinaryenIndex i = 0; i < numPasses; i++) { + if (i > 0) std::cout << ", "; + std::cout << "\"" << passes[i] << "\""; + } + std::cout << " };\n"; + std::cout << " BinaryenFunctionRunPasses(functions[" << functions[func] << ", the_module, passes, " << numPasses << ");\n"; + std::cout << " }\n"; + } + + Module* wasm = (Module*)module; + PassRunner passRunner(wasm); + for (BinaryenIndex i = 0; i < numPasses; i++) { + passRunner.add(passes[i]); + } + passRunner.runFunction((Function*)func); +} + +// // ========== CFG / Relooper ========== // |