diff options
-rwxr-xr-x | build-js.sh | 1 | ||||
-rw-r--r-- | src/binaryen-c.cpp | 9 | ||||
-rw-r--r-- | src/binaryen-c.h | 4 | ||||
-rw-r--r-- | src/js/binaryen.js-post.js | 5 | ||||
-rw-r--r-- | test/binaryen.js/global.js | 2 | ||||
-rw-r--r-- | test/binaryen.js/global.js.txt | 1 |
6 files changed, 20 insertions, 2 deletions
diff --git a/build-js.sh b/build-js.sh index 9665bbc71..9709752f9 100755 --- a/build-js.sh +++ b/build-js.sh @@ -754,6 +754,7 @@ export_function "_BinaryenAddFunction" export_function "_BinaryenGetFunction" export_function "_BinaryenRemoveFunction" export_function "_BinaryenAddGlobal" +export_function "_BinaryenGetGlobal" export_function "_BinaryenRemoveGlobal" export_function "_BinaryenAddFunctionImport" export_function "_BinaryenAddTableImport" diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index fb8b730c7..6bf2e7d7c 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -2751,6 +2751,15 @@ BinaryenGlobalRef BinaryenAddGlobal(BinaryenModuleRef module, wasm->addGlobal(ret); return ret; } +BinaryenGlobalRef BinaryenGetGlobal(BinaryenModuleRef module, + const char* name) { + if (tracing) { + std::cout << " BinaryenGetGlobal(the_module, \"" << name << "\");\n"; + } + + auto* wasm = (Module*)module; + return wasm->getGlobal(name); +} void BinaryenRemoveGlobal(BinaryenModuleRef module, const char* name) { if (tracing) { std::cout << " BinaryenRemoveGlobal(the_module, \"" << name << "\");\n"; diff --git a/src/binaryen-c.h b/src/binaryen-c.h index ae6747cea..03da33931 100644 --- a/src/binaryen-c.h +++ b/src/binaryen-c.h @@ -853,11 +853,9 @@ BinaryenFunctionRef BinaryenAddFunction(BinaryenModuleRef module, BinaryenType* varTypes, BinaryenIndex numVarTypes, BinaryenExpressionRef body); - // Gets a function reference by name. BinaryenFunctionRef BinaryenGetFunction(BinaryenModuleRef module, const char* name); - // Removes a function by name. void BinaryenRemoveFunction(BinaryenModuleRef module, const char* name); @@ -913,6 +911,8 @@ BinaryenGlobalRef BinaryenAddGlobal(BinaryenModuleRef module, BinaryenType type, int8_t mutable_, BinaryenExpressionRef init); +// Gets a global reference by name. +BinaryenGlobalRef BinaryenGetGlobal(BinaryenModuleRef module, const char* name); void BinaryenRemoveGlobal(BinaryenModuleRef module, const char* name); // Function table. One per module diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 6f0bec734..c64d3caca 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -1776,6 +1776,11 @@ function wrapModule(module, self) { return Module['_BinaryenAddGlobal'](module, strToStack(name), type, mutable, init); }); } + self['getGlobal'] = function(name) { + return preserveStack(function() { + return Module['_BinaryenGetGlobal'](module, strToStack(name)); + }); + }; self['removeGlobal'] = function(name) { return preserveStack(function() { return Module['_BinaryenRemoveGlobal'](module, strToStack(name)); diff --git a/test/binaryen.js/global.js b/test/binaryen.js/global.js index f24331d82..ca041d5bb 100644 --- a/test/binaryen.js/global.js +++ b/test/binaryen.js/global.js @@ -13,6 +13,8 @@ var module = new Binaryen.Module(); var initExpr = module.i32.const(1); var global = module.addGlobal("a-global", Binaryen.i32, false, initExpr); +console.log("GetGlobal is equal: " + (global === module.getGlobal("a-global"))); + var globalInfo = Binaryen.getGlobalInfo(global); console.log("getGlobalInfo=" + JSON.stringify(cleanInfo(globalInfo))); diff --git a/test/binaryen.js/global.js.txt b/test/binaryen.js/global.js.txt index 49a0a4b0b..fb3e93dfe 100644 --- a/test/binaryen.js/global.js.txt +++ b/test/binaryen.js/global.js.txt @@ -1,3 +1,4 @@ +GetGlobal is equal: true getGlobalInfo={"module":"","base":"","mutable":false} getExpressionInfo(init)={"id":14,"value":1} (i32.const 1) |