Skip to content

Commit 1ec5a4f

Browse files
dcodeIOkripken
authored andcommitted
Add BinaryenRemoveGlobal / Module.removeGlobal to C/JS API (#1692)
1 parent e775682 commit 1ec5a4f

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

build-js.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ export_function "_BinaryenAddFunction"
535535
export_function "_BinaryenGetFunction"
536536
export_function "_BinaryenRemoveFunction"
537537
export_function "_BinaryenAddGlobal"
538+
export_function "_BinaryenRemoveGlobal"
538539
export_function "_BinaryenAddFunctionImport"
539540
export_function "_BinaryenAddTableImport"
540541
export_function "_BinaryenAddMemoryImport"

src/binaryen-c.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,14 @@ BinaryenGlobalRef BinaryenAddGlobal(BinaryenModuleRef module, const char* name,
16451645
wasm->addGlobal(ret);
16461646
return ret;
16471647
}
1648+
void BinaryenRemoveGlobal(BinaryenModuleRef module, const char* name) {
1649+
if (tracing) {
1650+
std::cout << " BinaryenRemoveGlobal(the_module, \"" << name << "\");\n";
1651+
}
1652+
1653+
auto* wasm = (Module*)module;
1654+
wasm->removeGlobal(name);
1655+
}
16481656

16491657
// Imports
16501658

src/binaryen-c.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ void BinaryenRemoveExport(BinaryenModuleRef module, const char* externalName);
613613
typedef void* BinaryenGlobalRef;
614614

615615
BinaryenGlobalRef BinaryenAddGlobal(BinaryenModuleRef module, const char* name, BinaryenType type, int8_t mutable_, BinaryenExpressionRef init);
616+
void BinaryenRemoveGlobal(BinaryenModuleRef module, const char* name);
616617

617618
// Function table. One per module
618619

src/js/binaryen.js-post.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,11 @@ Module['Module'] = function(module) {
10661066
return Module['_BinaryenAddGlobal'](module, strToStack(name), type, mutable, init);
10671067
});
10681068
}
1069+
this['removeGlobal'] = function(name) {
1070+
return preserveStack(function () {
1071+
return Module['_BinaryenRemoveGlobal'](module, strToStack(name));
1072+
});
1073+
}
10691074
this['addFunctionImport'] = function(internalName, externalModuleName, externalBaseName, functionType) {
10701075
return preserveStack(function() {
10711076
return Module['_BinaryenAddFunctionImport'](module, strToStack(internalName), strToStack(externalModuleName), strToStack(externalBaseName), functionType);

0 commit comments

Comments
 (0)