diff options
author | Daniel Wirtz <dcode@dcode.io> | 2017-08-24 18:31:15 +0200 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2017-08-24 09:31:15 -0700 |
commit | b07fafcebebab82dba46012256edc6445862cfce (patch) | |
tree | d819f110386bfe6ce3dab4aee6daeefc7f1a81ca /src/binaryen-c.cpp | |
parent | ac8ee6c9e7c43c80d8fb2c8166fd73f23e212069 (diff) | |
download | binaryen-b07fafcebebab82dba46012256edc6445862cfce.tar.gz binaryen-b07fafcebebab82dba46012256edc6445862cfce.tar.bz2 binaryen-b07fafcebebab82dba46012256edc6445862cfce.zip |
Initial asm.js output for binaryen-c / binaryen.js (#1136)
* Added BinaryenModulePrintAsmjs (using wasm2asm) + Module#emitAsmjs JS binding
Diffstat (limited to 'src/binaryen-c.cpp')
-rw-r--r-- | src/binaryen-c.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index dfdca516f..2aa0633af 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -29,6 +29,7 @@ #include "wasm-printing.h" #include "wasm-s-parser.h" #include "wasm-validator.h" +#include "wasm2asm.h" #include "cfg/Relooper.h" #include "ast_utils.h" #include "shell-interface.h" @@ -651,7 +652,7 @@ BinaryenExpressionRef BinaryenDrop(BinaryenModuleRef module, BinaryenExpressionR } BinaryenExpressionRef BinaryenReturn(BinaryenModuleRef module, BinaryenExpressionRef value) { auto* ret = Builder(*((Module*)module)).makeReturn((Expression*)value); - + if (tracing) { auto id = noteExpression(ret); std::cout << " expressions[" << id << "] = BinaryenReturn(the_module, expressions[" << expressions[value] << "]);\n"; @@ -932,6 +933,21 @@ void BinaryenModulePrint(BinaryenModuleRef module) { WasmPrinter::printModule((Module*)module); } +void BinaryenModulePrintAsmjs(BinaryenModuleRef module) { + if (tracing) { + std::cout << " BinaryenModulePrintAsmjs(the_module);\n"; + } + + Module* wasm = (Module*)module; + Wasm2AsmBuilder::Flags builderFlags; + Wasm2AsmBuilder wasm2asm(builderFlags); + Ref asmjs = wasm2asm.processWasm(wasm); + JSPrinter jser(true, true, asmjs); + jser.printAst(); + + std::cout << jser.buffer; +} + int BinaryenModuleValidate(BinaryenModuleRef module) { if (tracing) { std::cout << " BinaryenModuleValidate(the_module);\n"; |