|
35 | 35 | #include "wasm-validator.h" |
36 | 36 | #include "wasm.h" |
37 | 37 | #include "wasm2js.h" |
| 38 | +#include <iostream> |
| 39 | +#include <sstream> |
38 | 40 |
|
39 | 41 | #ifdef __EMSCRIPTEN__ |
40 | 42 | #include <emscripten.h> |
@@ -3288,6 +3290,26 @@ BinaryenModuleWrite(BinaryenModuleRef module, char* output, size_t outputSize) { |
3288 | 3290 | .outputBytes; |
3289 | 3291 | } |
3290 | 3292 |
|
| 3293 | +size_t BinaryenModuleWriteText(BinaryenModuleRef module, |
| 3294 | + char* output, |
| 3295 | + size_t outputSize) { |
| 3296 | + |
| 3297 | + if (tracing) { |
| 3298 | + std::cout << " // BinaryenModuleWriteTextr\n"; |
| 3299 | + } |
| 3300 | + |
| 3301 | + // use a stringstream as an std::ostream. Extract the std::string |
| 3302 | + // representation, and then store in the output. |
| 3303 | + std::stringstream ss; |
| 3304 | + WasmPrinter::printModule((Module*)module, ss); |
| 3305 | + |
| 3306 | + const auto temp = ss.str(); |
| 3307 | + const auto ctemp = temp.c_str(); |
| 3308 | + |
| 3309 | + strncpy(output, ctemp, outputSize); |
| 3310 | + return std::min(outputSize, temp.size()); |
| 3311 | +} |
| 3312 | + |
3291 | 3313 | BinaryenBufferSizes BinaryenModuleWriteWithSourceMap(BinaryenModuleRef module, |
3292 | 3314 | const char* url, |
3293 | 3315 | char* output, |
@@ -3333,6 +3355,21 @@ BinaryenModuleAllocateAndWrite(BinaryenModuleRef module, |
3333 | 3355 | return {binary, buffer.size(), sourceMap}; |
3334 | 3356 | } |
3335 | 3357 |
|
| 3358 | +char* BinaryenModuleAllocateAndWriteText(BinaryenModuleRef* module) { |
| 3359 | + if (tracing) { |
| 3360 | + std::cout << " // BinaryenModuleAllocateAndWriteText(the_module);"; |
| 3361 | + } |
| 3362 | + |
| 3363 | + std::stringstream ss; |
| 3364 | + WasmPrinter::printModule((Module*)module, ss); |
| 3365 | + |
| 3366 | + const std::string out = ss.str(); |
| 3367 | + const int len = out.length() + 1; |
| 3368 | + char* cout = (char*)malloc(len); |
| 3369 | + strncpy(cout, out.c_str(), len); |
| 3370 | + return cout; |
| 3371 | +} |
| 3372 | + |
3336 | 3373 | BinaryenModuleRef BinaryenModuleRead(char* input, size_t inputSize) { |
3337 | 3374 | if (tracing) { |
3338 | 3375 | std::cout << " // BinaryenModuleRead\n"; |
|
0 commit comments