From 18716065cc470c3bc29a4fecf3889891a9bf604b Mon Sep 17 00:00:00 2001 From: Daniel Wirtz Date: Mon, 14 Sep 2020 11:51:59 +0200 Subject: 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) --- test/binaryen.js/debug-names.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/binaryen.js/debug-names.js (limited to 'test/binaryen.js/debug-names.js') 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(); -- cgit v1.2.3