summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDaniel Wirtz <dcode@dcode.io>2019-10-12 00:41:32 +0200
committerAlon Zakai <azakai@google.com>2019-10-11 15:41:32 -0700
commit66cb7b3f80f6ce32f426c3cb52eaf19430289ac2 (patch)
treec93ad30df8f2e0959d914afe42470ceeb3996e7d /test
parent4e80fde446764102fe5685496f351f0539377ff6 (diff)
downloadbinaryen-66cb7b3f80f6ce32f426c3cb52eaf19430289ac2.tar.gz
binaryen-66cb7b3f80f6ce32f426c3cb52eaf19430289ac2.tar.bz2
binaryen-66cb7b3f80f6ce32f426c3cb52eaf19430289ac2.zip
Add BinaryenAddCustomSection API (#2381)
This adds a new BinaryenAddCustomSection API so a generator can add arbitrary custom sections to a module.
Diffstat (limited to 'test')
-rw-r--r--test/binaryen.js/custom-section.js11
-rw-r--r--test/binaryen.js/custom-section.js.txt26
2 files changed, 37 insertions, 0 deletions
diff --git a/test/binaryen.js/custom-section.js b/test/binaryen.js/custom-section.js
new file mode 100644
index 000000000..f61af0096
--- /dev/null
+++ b/test/binaryen.js/custom-section.js
@@ -0,0 +1,11 @@
+function assert(x) {
+ if (!x) throw 'error!';
+}
+
+Binaryen.setAPITracing(true);
+var module = new Binaryen.Module();
+
+module.addCustomSection("hello", [119, 111, 114, 108, 100]);
+
+assert(module.validate());
+console.log(module.emitText());
diff --git a/test/binaryen.js/custom-section.js.txt b/test/binaryen.js/custom-section.js.txt
new file mode 100644
index 000000000..7ac835fdf
--- /dev/null
+++ b/test/binaryen.js/custom-section.js.txt
@@ -0,0 +1,26 @@
+// beginning a Binaryen API trace
+#include <math.h>
+#include <map>
+#include "binaryen-c.h"
+int main() {
+ std::map<size_t, BinaryenFunctionTypeRef> functionTypes;
+ std::map<size_t, BinaryenExpressionRef> expressions;
+ std::map<size_t, BinaryenFunctionRef> functions;
+ std::map<size_t, BinaryenGlobalRef> globals;
+ std::map<size_t, BinaryenEventRef> events;
+ std::map<size_t, BinaryenExportRef> exports;
+ std::map<size_t, RelooperBlockRef> relooperBlocks;
+ BinaryenModuleRef the_module = NULL;
+ RelooperRef the_relooper = NULL;
+ the_module = BinaryenModuleCreate();
+ expressions[size_t(NULL)] = BinaryenExpressionRef(NULL);
+ {
+ const char contents[] = { 119, 111, 114, 108, 100 };
+ BinaryenAddCustomSection(the_module, "hello", contents, 5);
+ }
+ BinaryenModuleValidate(the_module);
+ BinaryenModulePrint(the_module);
+(module
+ ;; custom section "hello", size 5, contents: "world"
+)
+