diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/binaryen-c.cpp | 31 | ||||
-rw-r--r-- | src/binaryen-c.h | 9 | ||||
-rw-r--r-- | src/js/binaryen.js-post.js | 5 |
3 files changed, 45 insertions, 0 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 2307de3e6..1cb0963a2 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -4307,6 +4307,37 @@ const char* BinaryenExportGetValue(BinaryenExportRef export_) { } // +// ========= Custom sections ========= +// + +void BinaryenAddCustomSection(BinaryenModuleRef module, + const char* name, + const char* contents, + BinaryenIndex contentsSize) { + if (tracing) { + std::cout << " {\n"; + std::cout << " const char contents[] = { "; + for (BinaryenIndex i = 0; i < contentsSize; i++) { + if (i > 0) { + std::cout << ", "; + } + std::cout << int(contents[i]); + } + std::cout << " };\n"; + std::cout << " BinaryenAddCustomSection(the_module, "; + traceNameOrNULL(name); + std::cout << ", contents, " << contentsSize << ");\n"; + std::cout << " }\n"; + } + + auto* wasm = (Module*)module; + wasm::UserSection customSection; + customSection.name = name; + customSection.data = std::vector<char>(contents, contents + contentsSize); + wasm->userSections.push_back(customSection); +} + +// // ========== CFG / Relooper ========== // diff --git a/src/binaryen-c.h b/src/binaryen-c.h index ab159695a..ae0a06835 100644 --- a/src/binaryen-c.h +++ b/src/binaryen-c.h @@ -1433,6 +1433,15 @@ BINARYEN_API const char* BinaryenExportGetName(BinaryenExportRef export_); BINARYEN_API const char* BinaryenExportGetValue(BinaryenExportRef export_); // +// ========= Custom sections ========= +// + +BINARYEN_API void BinaryenAddCustomSection(BinaryenModuleRef module, + const char* name, + const char* contents, + BinaryenIndex contentsSize); + +// // ========== CFG / Relooper ========== // // General usage is (1) create a relooper, (2) create blocks, (3) add diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 03e57d3d5..7c99ded15 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -2105,6 +2105,11 @@ function wrapModule(module, self) { self['setFeatures'] = function(features) { Module['_BinaryenModuleSetFeatures'](module, features); }; + self['addCustomSection'] = function(name, contents) { + return preserveStack(function() { + return Module['_BinaryenAddCustomSection'](module, strToStack(name), i8sToStack(contents), contents.length); + }); + }; self['emitText'] = function() { var old = out; var ret = ''; |