summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binaryen-c.cpp12
-rw-r--r--src/binaryen-c.h8
2 files changed, 15 insertions, 5 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp
index bbafdf49d..a876c998b 100644
--- a/src/binaryen-c.cpp
+++ b/src/binaryen-c.cpp
@@ -23,6 +23,7 @@
#include "wasm.h"
#include "wasm-builder.h"
#include "wasm-printing.h"
+#include "wasm-validator.h"
#include "cfg/Relooper.h"
using namespace wasm;
@@ -193,7 +194,7 @@ BinaryenExpressionRef BinaryenLoop(BinaryenModuleRef module, const char* out, co
if (out && !in) abort();
return Builder(*((Module*)module)).makeLoop(out ? Name(out) : Name(), in ? Name(in) : Name(), (Expression*)body);
}
-BinaryenExpressionRef BinaryenBreak(BinaryenModuleRef module, const char* name, BinaryenExpressionRef value, BinaryenExpressionRef condition) {
+BinaryenExpressionRef BinaryenBreak(BinaryenModuleRef module, const char* name, BinaryenExpressionRef condition, BinaryenExpressionRef value) {
return Builder(*((Module*)module)).makeBreak(name, (Expression*)value, (Expression*)condition);
}
BinaryenExpressionRef BinaryenSwitch(BinaryenModuleRef module, const char **names, BinaryenIndex numNames, const char* defaultName, BinaryenExpressionRef condition, BinaryenExpressionRef value) {
@@ -372,9 +373,9 @@ void BinaryenSetMemory(BinaryenModuleRef module, BinaryenIndex initial, Binaryen
// Start function. One per module
-void BinaryenSetStart(BinaryenModuleRef module, const char* name) {
+void BinaryenSetStart(BinaryenModuleRef module, BinaryenFunctionRef start) {
auto* wasm = (Module*)module;
- wasm->addStart(name);
+ wasm->addStart(((Function*)start)->name);
}
//
@@ -385,6 +386,11 @@ void BinaryenModulePrint(BinaryenModuleRef module) {
WasmPrinter::printModule((Module*)module);
}
+int BinaryenModuleValidate(BinaryenModuleRef module) {
+ Module* wasm = (Module*)module;
+ return WasmValidator().validate(*wasm) ? 1 : 0;
+}
+
void BinaryenModuleOptimize(BinaryenModuleRef module) {
Module* wasm = (Module*)module;
PassRunner passRunner(wasm);
diff --git a/src/binaryen-c.h b/src/binaryen-c.h
index 2e0a7b996..9319de209 100644
--- a/src/binaryen-c.h
+++ b/src/binaryen-c.h
@@ -196,7 +196,7 @@ BinaryenExpressionRef BinaryenIf(BinaryenModuleRef module, BinaryenExpressionRef
// Loop: both out and in can be NULL, or just out can be NULL
BinaryenExpressionRef BinaryenLoop(BinaryenModuleRef module, const char* out, const char* in, BinaryenExpressionRef body);
// Break: value and condition can be NULL
-BinaryenExpressionRef BinaryenBreak(BinaryenModuleRef module, const char* name, BinaryenExpressionRef value, BinaryenExpressionRef condition);
+BinaryenExpressionRef BinaryenBreak(BinaryenModuleRef module, const char* name, BinaryenExpressionRef condition, BinaryenExpressionRef value);
// Switch: value can be NULL
BinaryenExpressionRef BinaryenSwitch(BinaryenModuleRef module, const char **names, BinaryenIndex numNames, const char* defaultName, BinaryenExpressionRef condition, BinaryenExpressionRef value);
BinaryenExpressionRef BinaryenCall(BinaryenModuleRef module, const char *target, BinaryenExpressionRef* operands, BinaryenIndex numOperands);
@@ -257,7 +257,7 @@ void BinaryenSetMemory(BinaryenModuleRef module, BinaryenIndex initial, Binaryen
// Start function. One per module
-void BinaryenSetStart(BinaryenModuleRef module, const char* name);
+void BinaryenSetStart(BinaryenModuleRef module, BinaryenFunctionRef start);
//
// ========== Module Operations ==========
@@ -266,6 +266,10 @@ void BinaryenSetStart(BinaryenModuleRef module, const char* name);
// Print a module to stdout.
void BinaryenModulePrint(BinaryenModuleRef module);
+// Validate a module, showing errors on problems.
+// @return 0 if an error occurred, 1 if validated succesfully
+int BinaryenModuleValidate(BinaryenModuleRef module);
+
// Run the standard optimization passes on the module.
void BinaryenModuleOptimize(BinaryenModuleRef module);