diff options
author | Daniel Wirtz <dcode@dcode.io> | 2020-09-14 11:51:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-14 11:51:59 +0200 |
commit | 18716065cc470c3bc29a4fecf3889891a9bf604b (patch) | |
tree | f106abf584fcc2ab1e14320682962326357479e8 /test/binaryen.js/debug-names.js | |
parent | 0ade3f2761b0661ab4d1290ab704c594c1d90df9 (diff) | |
download | binaryen-18716065cc470c3bc29a4fecf3889891a9bf604b.tar.gz binaryen-18716065cc470c3bc29a4fecf3889891a9bf604b.tar.bz2 binaryen-18716065cc470c3bc29a4fecf3889891a9bf604b.zip |
Implement module and local names in name section (#3115)
Adds support for the module and local subsections of the name section plus the respective C and JS APIs to populate and obtain local names.
C API:
* BinaryenFunctionGetNumLocals(func)
* BinaryenFunctionHasLocalName(func, index)
* BinaryenFunctionGetLocalName(func, index)
* BinaryenFunctionSetLocalName(func, index, name)
JS API:
* Function.getNumLocals(func)
* Function.hasLocalName(func, index)
* Function.getLocalName(func, index)
* Function.setLocalName(func, index, name)
Diffstat (limited to 'test/binaryen.js/debug-names.js')
-rw-r--r-- | test/binaryen.js/debug-names.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/binaryen.js/debug-names.js b/test/binaryen.js/debug-names.js new file mode 100644 index 000000000..539b119aa --- /dev/null +++ b/test/binaryen.js/debug-names.js @@ -0,0 +1,36 @@ +var wast = ` +(module $hello + (global $world i32 (i32.const 0)) + (func $of (param $wasm i32) + (local $!#$%&'*+-./:<=>?@\\^_\`|~ f64) + ) +) +`; +// Note that global names are not yet covered by the name section, so it is +// expected that the global's name is lost after roundtripping. + +console.log("=== input wast ===" + wast); + +var module = binaryen.parseText(wast); + +console.log("=== parsed wast ===\n" + module.emitText()); + +var func = binaryen.Function(module.getFunction("of")); +assert(func.numLocals === 2); +assert(func.hasLocalName(0) === true); +assert(func.getLocalName(0) === "wasm"); +assert(func.hasLocalName(1) === true); +assert(func.getLocalName(1) === "!#$%&'*+-./:<=>?@\\^_\`|~"); +assert(func.hasLocalName(2) === false); +func.setLocalName(0, "js"); +assert(func.getLocalName(0) === "js"); + +binaryen.setDebugInfo(true); + +var module2 = binaryen.readBinary(module.emitBinary()); + +module.dispose(); + +console.log("=== roundtripped ===\n" + module2.emitText()); + +module2.dispose(); |