diff options
author | Heejin Ahn <aheejin@gmail.com> | 2019-05-24 15:02:42 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-24 15:02:42 -0700 |
commit | dc37d7b74edde1876f2114ad8edd10ab076e778f (patch) | |
tree | f9253c9b93ac7e544b29a594c96e1ba217b51d2d /src | |
parent | 7ae38053cf1e1e5c8f84c34a142efb043f6d4810 (diff) | |
download | binaryen-dc37d7b74edde1876f2114ad8edd10ab076e778f.tar.gz binaryen-dc37d7b74edde1876f2114ad8edd10ab076e778f.tar.bz2 binaryen-dc37d7b74edde1876f2114ad8edd10ab076e778f.zip |
Add `getGlobal` to binaryen.js (#2142)
We have `getFunction`, but not `getGlobal` because its name clashed with
APIs for the deprecated instruction `get_global`. Now we have reflected
instruction renaming in code, we can add it for consistency.
Diffstat (limited to 'src')
-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 |
3 files changed, 16 insertions, 2 deletions
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)); |