summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binaryen-c.cpp18
-rw-r--r--src/binaryen-c.h3
-rw-r--r--src/js/binaryen.js-post.js8
3 files changed, 29 insertions, 0 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp
index 842d96f69..36b2abbe7 100644
--- a/src/binaryen-c.cpp
+++ b/src/binaryen-c.cpp
@@ -27,6 +27,7 @@
#include "wasm-builder.h"
#include "wasm-interpreter.h"
#include "wasm-printing.h"
+#include "wasm-s-parser.h"
#include "wasm-validator.h"
#include "cfg/Relooper.h"
#include "shell-interface.h"
@@ -905,6 +906,23 @@ void BinaryenSetStart(BinaryenModuleRef module, BinaryenFunctionRef start) {
// ========== Module Operations ==========
//
+BinaryenModuleRef BinaryenModuleParse(const char* text) {
+ if (tracing) {
+ std::cout << " // BinaryenModuleRead\n";
+ }
+
+ auto* wasm = new Module;
+ try {
+ SExpressionParser parser(const_cast<char*>(text));
+ Element& root = *parser.root;
+ SExpressionWasmBuilder builder(*wasm, *root[0]);
+ } catch (ParseException& p) {
+ p.dump(std::cerr);
+ Fatal() << "error in parsing wasm text";
+ }
+ return wasm;
+}
+
void BinaryenModulePrint(BinaryenModuleRef module) {
if (tracing) {
std::cout << " BinaryenModulePrint(the_module);\n";
diff --git a/src/binaryen-c.h b/src/binaryen-c.h
index 889b5ba45..90c7795f0 100644
--- a/src/binaryen-c.h
+++ b/src/binaryen-c.h
@@ -366,6 +366,9 @@ void BinaryenSetStart(BinaryenModuleRef module, BinaryenFunctionRef start);
// ========== Module Operations ==========
//
+// Parse a module in s-expression text format
+BinaryenModuleRef BinaryenModuleParse(const char* text);
+
// Print a module to stdout. Useful for debugging.
void BinaryenModulePrint(BinaryenModuleRef module);
diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js
index 2f7defc63..9b2527fc5 100644
--- a/src/js/binaryen.js-post.js
+++ b/src/js/binaryen.js-post.js
@@ -899,6 +899,14 @@
return new Module['Module'](ptr);
};
+ Module['parseText'] = function(text) {
+ var buffer = _malloc(text.length + 1);
+ writeAsciiToMemory(text, buffer);
+ var ptr = Module['_BinaryenModuleParse'](buffer);
+ _free(buffer);
+ return new Module['Module'](ptr);
+ };
+
Module['setAPITracing'] = function(on) {
return Module['_BinaryenSetAPITracing'](on);
};