summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/binaryen-c.cpp16
-rw-r--r--src/binaryen-c.h13
-rw-r--r--src/js/binaryen.js-post.js48
-rw-r--r--src/passes/Print.cpp4
-rw-r--r--src/tools/wasm-shell.cpp4
-rw-r--r--src/wasm-binary.h1
-rw-r--r--src/wasm-s-parser.h5
-rw-r--r--src/wasm.h6
-rw-r--r--src/wasm/wasm-binary.cpp174
-rw-r--r--src/wasm/wasm-s-parser.cpp7
-rw-r--r--src/wasm/wasm.cpp5
-rw-r--r--test/binaryen.js/debug-names.js36
-rw-r--r--test/binaryen.js/debug-names.js.txt28
-rw-r--r--test/exception-handling.wast.fromBinary6
-rw-r--r--test/grow_memory.wast.fromBinary4
-rw-r--r--test/min.wast.fromBinary28
-rw-r--r--test/multivalue.wast.fromBinary10
-rw-r--r--test/polymorphic_stack.wast.fromBinary4
-rw-r--r--test/reference-types.wast.fromBinary260
19 files changed, 447 insertions, 212 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp
index e11b762dd..3582c99ca 100644
--- a/src/binaryen-c.cpp
+++ b/src/binaryen-c.cpp
@@ -3709,6 +3709,22 @@ BinaryenType BinaryenFunctionGetVar(BinaryenFunctionRef func,
assert(index < vars.size());
return vars[index].getID();
}
+BinaryenIndex BinaryenFunctionGetNumLocals(BinaryenFunctionRef func) {
+ return ((Function*)func)->getNumLocals();
+}
+int BinaryenFunctionHasLocalName(BinaryenFunctionRef func,
+ BinaryenIndex index) {
+ return ((Function*)func)->hasLocalName(index);
+}
+const char* BinaryenFunctionGetLocalName(BinaryenFunctionRef func,
+ BinaryenIndex index) {
+ return ((Function*)func)->getLocalName(index).str;
+}
+void BinaryenFunctionSetLocalName(BinaryenFunctionRef func,
+ BinaryenIndex index,
+ const char* name) {
+ ((Function*)func)->setLocalName(index, name);
+}
BinaryenExpressionRef BinaryenFunctionGetBody(BinaryenFunctionRef func) {
return ((Function*)func)->body;
}
diff --git a/src/binaryen-c.h b/src/binaryen-c.h
index e622419ac..1adc73b8e 100644
--- a/src/binaryen-c.h
+++ b/src/binaryen-c.h
@@ -2236,6 +2236,19 @@ BINARYEN_API BinaryenIndex BinaryenFunctionGetNumVars(BinaryenFunctionRef func);
// specified `Function`.
BINARYEN_API BinaryenType BinaryenFunctionGetVar(BinaryenFunctionRef func,
BinaryenIndex index);
+// Gets the number of locals within the specified function. Includes parameters.
+BINARYEN_API BinaryenIndex
+BinaryenFunctionGetNumLocals(BinaryenFunctionRef func);
+// Tests if the local at the specified index has a name.
+BINARYEN_API int BinaryenFunctionHasLocalName(BinaryenFunctionRef func,
+ BinaryenIndex index);
+// Gets the name of the local at the specified index.
+BINARYEN_API const char* BinaryenFunctionGetLocalName(BinaryenFunctionRef func,
+ BinaryenIndex index);
+// Sets the name of the local at the specified index.
+BINARYEN_API void BinaryenFunctionSetLocalName(BinaryenFunctionRef func,
+ BinaryenIndex index,
+ const char* name);
// Gets the body of the specified `Function`.
BINARYEN_API BinaryenExpressionRef
BinaryenFunctionGetBody(BinaryenFunctionRef func);
diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js
index fd121b8af..d7c1878fd 100644
--- a/src/js/binaryen.js-post.js
+++ b/src/js/binaryen.js-post.js
@@ -3061,18 +3061,18 @@ function makeExpressionWrapper(ownStaticMembers) {
// inherit from Expression
(SpecificExpression.prototype = Object.create(Expression.prototype)).constructor = SpecificExpression;
// make own instance members
- makeExpressionWrapperInstanceMembers(SpecificExpression.prototype, ownStaticMembers);
+ makeWrapperInstanceMembers(SpecificExpression.prototype, ownStaticMembers);
return SpecificExpression;
}
// Makes instance members from the given static members
-function makeExpressionWrapperInstanceMembers(prototype, staticMembers) {
+function makeWrapperInstanceMembers(prototype, staticMembers, ref = 'expr') {
Object.keys(staticMembers).forEach(memberName => {
const member = staticMembers[memberName];
if (typeof member === "function") {
// Instance method calls the respective static method
prototype[memberName] = function(...args) {
- return this.constructor[memberName](this['expr'], ...args);
+ return this.constructor[memberName](this[ref], ...args);
};
// Instance accessor calls the respective static methods
let match;
@@ -3082,10 +3082,10 @@ function makeExpressionWrapperInstanceMembers(prototype, staticMembers) {
const setterIfAny = staticMembers["set" + memberName.substring(index)];
Object.defineProperty(prototype, propertyName, {
get() {
- return member(this['expr']);
+ return member(this[ref]);
},
set(value) {
- if (setterIfAny) setterIfAny(this['expr'], value);
+ if (setterIfAny) setterIfAny(this[ref], value);
else throw Error("property '" + propertyName + "' has no setter");
}
});
@@ -3114,7 +3114,7 @@ Expression['finalize'] = function(expr) {
Expression['toText'] = function(expr) {
return Module['emitText'](expr);
};
-makeExpressionWrapperInstanceMembers(Expression.prototype, Expression);
+makeWrapperInstanceMembers(Expression.prototype, Expression);
Expression.prototype['valueOf'] = function() {
return this['expr'];
};
@@ -4281,6 +4281,42 @@ Module['TupleExtract'] = makeExpressionWrapper({
}
});
+// Function wrapper
+
+Module['Function'] = (() => {
+ function Function(func) {
+ if (!(this instanceof Function)) {
+ if (!func) return null;
+ return new Function(func);
+ }
+ if (!func) throw Error("function reference must not be null");
+ this['func'] = func;
+ }
+ Function['getName'] = function(func) {
+ return Module['_BinaryenFunctionGetName'](func);
+ };
+ Function['getNumLocals'] = function(func) {
+ return Module['_BinaryenFunctionGetNumLocals'](func);
+ };
+ Function['hasLocalName'] = function(func, index) {
+ return Boolean(Module['_BinaryenFunctionHasLocalName'](func, index));
+ };
+ Function['getLocalName'] = function(func, index) {
+ return UTF8ToString(Module['_BinaryenFunctionGetLocalName'](func, index));
+ };
+ Function['setLocalName'] = function(func, index, name) {
+ preserveStack(() => {
+ Module['_BinaryenFunctionSetLocalName'](func, index, strToStack(name));
+ });
+ };
+ // TODO: add more methods
+ makeWrapperInstanceMembers(Function.prototype, Function, 'func');
+ Function.prototype['valueOf'] = function() {
+ return this['func'];
+ };
+ return Function;
+})();
+
// Additional customizations
Module['exit'] = function(status) {
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index f4131db37..15ab97098 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -2398,6 +2398,10 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
currModule = curr;
o << '(';
printMajor(o, "module");
+ if (curr->name.is()) {
+ o << ' ';
+ printName(curr->name, o);
+ }
incIndent();
std::vector<Signature> signatures;
std::unordered_map<Signature, Index> indices;
diff --git a/src/tools/wasm-shell.cpp b/src/tools/wasm-shell.cpp
index 80229554b..8ba6a4142 100644
--- a/src/tools/wasm-shell.cpp
+++ b/src/tools/wasm-shell.cpp
@@ -304,9 +304,9 @@ int main(int argc, const char* argv[]) {
std::cerr << "BUILDING MODULE [line: " << curr.line << "]\n";
Colors::normal(std::cerr);
auto module = wasm::make_unique<Module>();
- Name moduleName;
auto builder = wasm::make_unique<SExpressionWasmBuilder>(
- *module, *root[i], IRProfile::Normal, &moduleName);
+ *module, *root[i], IRProfile::Normal);
+ auto moduleName = module->name;
builders[moduleName].swap(builder);
modules[moduleName].swap(module);
i++;
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index 33f78ce7f..8a067e3fd 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -386,6 +386,7 @@ extern const char* MultivalueFeature;
extern const char* AnyrefFeature;
enum Subsection {
+ NameModule = 0,
NameFunction = 1,
NameLocal = 2,
};
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index a4559012d..85ca217e7 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -126,10 +126,7 @@ class SExpressionWasmBuilder {
public:
// Assumes control of and modifies the input.
- SExpressionWasmBuilder(Module& wasm,
- Element& module,
- IRProfile profile,
- Name* moduleName = nullptr);
+ SExpressionWasmBuilder(Module& wasm, Element& module, IRProfile profile);
private:
// pre-parse types and function definitions, so we know function return types
diff --git a/src/wasm.h b/src/wasm.h
index 63a6fe79c..c5db2fbd3 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -1263,7 +1263,7 @@ using StackIR = std::vector<StackInst*>;
class Function : public Importable {
public:
Name name;
- Signature sig; // parameters and return value
+ Signature sig; // parameters and return value
IRProfile profile = IRProfile::Normal;
std::vector<Type> vars; // non-param locals
@@ -1328,6 +1328,7 @@ public:
Name getLocalNameOrGeneric(Index index);
bool hasLocalName(Index index) const;
+ void setLocalName(Index index, Name name);
void clearNames();
void clearDebugInfo();
@@ -1502,6 +1503,9 @@ public:
FeatureSet features = FeatureSet::MVP;
bool hasFeaturesSection = false;
+ // Module name, if specified. Serves a documentary role only.
+ Name name;
+
MixedArena allocator;
private:
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index de82f0656..fb8d97cb5 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -555,20 +555,79 @@ void WasmBinaryWriter::writeNames() {
BYN_TRACE("== writeNames\n");
auto start = startSection(BinaryConsts::Section::User);
writeInlineString(BinaryConsts::UserSections::Name);
- auto substart =
- startSubsection(BinaryConsts::UserSections::Subsection::NameFunction);
- o << U32LEB(indexes.functionIndexes.size());
- Index emitted = 0;
- auto add = [&](Function* curr) {
- o << U32LEB(emitted);
- writeEscapedName(curr->name.str);
- emitted++;
- };
- ModuleUtils::iterImportedFunctions(*wasm, add);
- ModuleUtils::iterDefinedFunctions(*wasm, add);
- assert(emitted == indexes.functionIndexes.size());
- finishSubsection(substart);
- /* TODO: locals */
+
+ // module name
+ if (wasm->name.is()) {
+ auto substart =
+ startSubsection(BinaryConsts::UserSections::Subsection::NameModule);
+ writeEscapedName(wasm->name.str);
+ finishSubsection(substart);
+ }
+
+ // function names
+ {
+ auto substart =
+ startSubsection(BinaryConsts::UserSections::Subsection::NameFunction);
+ o << U32LEB(indexes.functionIndexes.size());
+ Index emitted = 0;
+ auto add = [&](Function* curr) {
+ o << U32LEB(emitted);
+ writeEscapedName(curr->name.str);
+ emitted++;
+ };
+ ModuleUtils::iterImportedFunctions(*wasm, add);
+ ModuleUtils::iterDefinedFunctions(*wasm, add);
+ assert(emitted == indexes.functionIndexes.size());
+ finishSubsection(substart);
+ }
+
+ // local names
+ {
+ // Find all functions with at least one local name and only emit the
+ // subsection if there is at least one.
+ std::vector<std::pair<Index, Function*>> functionsWithLocalNames;
+ Index checked = 0;
+ auto check = [&](Function* curr) {
+ auto numLocals = curr->getNumLocals();
+ for (Index i = 0; i < numLocals; ++i) {
+ if (curr->hasLocalName(i)) {
+ functionsWithLocalNames.push_back({checked, curr});
+ break;
+ }
+ }
+ checked++;
+ };
+ ModuleUtils::iterImportedFunctions(*wasm, check);
+ ModuleUtils::iterDefinedFunctions(*wasm, check);
+ assert(checked == indexes.functionIndexes.size());
+ if (functionsWithLocalNames.size() > 0) {
+ // Otherwise emit those functions but only include locals with a name.
+ auto substart =
+ startSubsection(BinaryConsts::UserSections::Subsection::NameLocal);
+ o << U32LEB(functionsWithLocalNames.size());
+ Index emitted = 0;
+ for (auto& indexedFunc : functionsWithLocalNames) {
+ std::vector<std::pair<Index, Name>> localsWithNames;
+ auto numLocals = indexedFunc.second->getNumLocals();
+ for (Index i = 0; i < numLocals; ++i) {
+ if (indexedFunc.second->hasLocalName(i)) {
+ localsWithNames.push_back({i, indexedFunc.second->getLocalName(i)});
+ }
+ }
+ assert(localsWithNames.size());
+ o << U32LEB(indexedFunc.first);
+ o << U32LEB(localsWithNames.size());
+ for (auto& indexedLocal : localsWithNames) {
+ o << U32LEB(indexedLocal.first);
+ writeEscapedName(indexedLocal.second.str);
+ }
+ emitted++;
+ }
+ assert(emitted == functionsWithLocalNames.size());
+ finishSubsection(substart);
+ }
+ }
+
finishSection(start);
}
@@ -2126,33 +2185,72 @@ void WasmBinaryBuilder::readNames(size_t payloadLen) {
auto nameType = getU32LEB();
auto subsectionSize = getU32LEB();
auto subsectionPos = pos;
- if (nameType != BinaryConsts::UserSections::Subsection::NameFunction) {
- // TODO: locals
- std::cerr << "warning: unknown name subsection at " << pos << std::endl;
- pos = subsectionPos + subsectionSize;
- continue;
- }
- auto num = getU32LEB();
- std::set<Name> usedNames;
- for (size_t i = 0; i < num; i++) {
- auto index = getU32LEB();
- auto rawName = getInlineString();
- rawName = escape(rawName);
- auto name = rawName;
- // De-duplicate names by appending .1, .2, etc.
- for (int i = 1; !usedNames.insert(name).second; ++i) {
- name = rawName.str + std::string(".") + std::to_string(i);
+ if (nameType == BinaryConsts::UserSections::Subsection::NameModule) {
+ wasm.name = getInlineString();
+ } else if (nameType ==
+ BinaryConsts::UserSections::Subsection::NameFunction) {
+ auto num = getU32LEB();
+ std::set<Name> usedNames;
+ for (size_t i = 0; i < num; i++) {
+ auto index = getU32LEB();
+ auto rawName = getInlineString();
+ rawName = escape(rawName);
+ auto name = rawName;
+ // De-duplicate names by appending .1, .2, etc.
+ for (int i = 1; !usedNames.insert(name).second; ++i) {
+ name = rawName.str + std::string(".") + std::to_string(i);
+ }
+ // note: we silently ignore errors here, as name section errors
+ // are not fatal. should we warn?
+ auto numFunctionImports = functionImports.size();
+ if (index < numFunctionImports) {
+ functionImports[index]->name = name;
+ } else if (index - numFunctionImports < functions.size()) {
+ functions[index - numFunctionImports]->name = name;
+ } else {
+ std::cerr << "warning: function index out of bounds in name section, "
+ "function subsection: "
+ << std::string(name.str) << " at index "
+ << std::to_string(index) << std::endl;
+ }
}
- // note: we silently ignore errors here, as name section errors
- // are not fatal. should we warn?
+ } else if (nameType == BinaryConsts::UserSections::Subsection::NameLocal) {
+ auto numFuncs = getU32LEB();
auto numFunctionImports = functionImports.size();
- if (index < numFunctionImports) {
- functionImports[index]->name = name;
- } else if (index - numFunctionImports < functions.size()) {
- functions[index - numFunctionImports]->name = name;
- } else {
- throwError("index out of bounds: " + std::string(name.str));
+ for (size_t i = 0; i < numFuncs; i++) {
+ auto funcIndex = getU32LEB();
+ Function* func = nullptr;
+ if (funcIndex < numFunctionImports) {
+ func = functionImports[funcIndex];
+ } else if (funcIndex - numFunctionImports < functions.size()) {
+ func = functions[funcIndex - numFunctionImports];
+ } else {
+ std::cerr
+ << "warning: function index out of bounds in name section, local "
+ "subsection: "
+ << std::to_string(funcIndex) << std::endl;
+ }
+ auto numLocals = getU32LEB();
+ for (size_t j = 0; j < numLocals; j++) {
+ auto localIndex = getU32LEB();
+ auto localName = getInlineString();
+ if (!func) {
+ continue; // read and discard in case of prior error
+ }
+ if (localIndex < func->getNumLocals()) {
+ func->localNames[localIndex] = localName;
+ } else {
+ std::cerr << "warning: local index out of bounds in name "
+ "section, local subsection: "
+ << std::string(localName.str) << " at index "
+ << std::to_string(localIndex) << " in function "
+ << std::string(func->name.str) << std::endl;
+ }
+ }
}
+ } else {
+ std::cerr << "warning: unknown name subsection at " << pos << std::endl;
+ pos = subsectionPos + subsectionSize;
}
if (pos != subsectionPos + subsectionSize) {
throwError("bad names subsection position change");
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 97bfe55f9..97da80fea 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -314,8 +314,7 @@ Element* SExpressionParser::parseString() {
SExpressionWasmBuilder::SExpressionWasmBuilder(Module& wasm,
Element& module,
- IRProfile profile,
- Name* moduleName)
+ IRProfile profile)
: wasm(wasm), allocator(wasm.allocator), profile(profile) {
if (module.size() == 0) {
throw ParseException("empty toplevel, expected module");
@@ -328,9 +327,7 @@ SExpressionWasmBuilder::SExpressionWasmBuilder(Module& wasm,
}
Index i = 1;
if (module[i]->dollared()) {
- if (moduleName) {
- *moduleName = module[i]->str();
- }
+ wasm.name = module[i]->str();
i++;
}
if (i < module.size() && module[i]->isStr()) {
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index 31e05f42e..5931b56aa 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -986,6 +986,11 @@ bool Function::hasLocalName(Index index) const {
Name Function::getLocalName(Index index) { return localNames.at(index); }
+void Function::setLocalName(Index index, Name name) {
+ assert(index < getNumLocals());
+ localNames[index] = name;
+}
+
Name Function::getLocalNameOrDefault(Index index) {
auto nameIt = localNames.find(index);
if (nameIt != localNames.end()) {
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();
diff --git a/test/binaryen.js/debug-names.js.txt b/test/binaryen.js/debug-names.js.txt
new file mode 100644
index 000000000..c982f2dc1
--- /dev/null
+++ b/test/binaryen.js/debug-names.js.txt
@@ -0,0 +1,28 @@
+=== input wast ===
+(module $hello
+ (global $world i32 (i32.const 0))
+ (func $of (param $wasm i32)
+ (local $!#$%&'*+-./:<=>?@\^_`|~ f64)
+ )
+)
+
+=== parsed wast ===
+(module $hello
+ (type $i32_=>_none (func (param i32)))
+ (global $world i32 (i32.const 0))
+ (func $of (param $wasm i32)
+ (local $!#$%&'*+-./:<=>?@\^_`|~ f64)
+ (nop)
+ )
+)
+
+=== roundtripped ===
+(module $hello
+ (type $i32_=>_none (func (param i32)))
+ (global $global$0 i32 (i32.const 0))
+ (func $of (param $js i32)
+ (local $!#$%&'*+-./:<=>?@\^_`|~ f64)
+ (nop)
+ )
+)
+
diff --git a/test/exception-handling.wast.fromBinary b/test/exception-handling.wast.fromBinary
index 7add5b33e..4e1895593 100644
--- a/test/exception-handling.wast.fromBinary
+++ b/test/exception-handling.wast.fromBinary
@@ -15,7 +15,7 @@
(nop)
)
(func $eh_test
- (local $0 exnref)
+ (local $exn exnref)
(try
(do
(throw $event$0
@@ -23,14 +23,14 @@
)
)
(catch
- (local.set $0
+ (local.set $exn
(pop exnref)
)
(drop
(block $label$3 (result i32)
(rethrow
(br_on_exn $label$3 $event$0
- (local.get $0)
+ (local.get $exn)
)
)
)
diff --git a/test/grow_memory.wast.fromBinary b/test/grow_memory.wast.fromBinary
index bf93f1f35..82b5b18af 100644
--- a/test/grow_memory.wast.fromBinary
+++ b/test/grow_memory.wast.fromBinary
@@ -5,9 +5,9 @@
(export "memory" (memory $0))
(export "grow" (func $0))
(export "current" (func $1))
- (func $0 (param $0 i32) (result i32)
+ (func $0 (param $var$0 i32) (result i32)
(memory.grow
- (local.get $0)
+ (local.get $var$0)
)
)
(func $1 (result i32)
diff --git a/test/min.wast.fromBinary b/test/min.wast.fromBinary
index 1cf8a5ded..834b9cc28 100644
--- a/test/min.wast.fromBinary
+++ b/test/min.wast.fromBinary
@@ -5,36 +5,36 @@
(type $f32_=>_f32 (func (param f32) (result f32)))
(memory $0 256 256)
(export "floats" (func $floats))
- (func $floats (param $0 f32) (result f32)
- (local $1 f32)
+ (func $floats (param $f f32) (result f32)
+ (local $t f32)
(f32.add
- (local.get $1)
- (local.get $0)
+ (local.get $t)
+ (local.get $f)
)
)
- (func $neg (param $0 i32) (param $1 i32) (result f32)
- (local $2 f32)
- (local.tee $2
+ (func $neg (param $k i32) (param $p i32) (result f32)
+ (local $n f32)
+ (local.tee $n
(f32.neg
(block $label$1 (result f32)
(i32.store
- (local.get $0)
- (local.get $1)
+ (local.get $k)
+ (local.get $p)
)
(f32.load
- (local.get $0)
+ (local.get $k)
)
)
)
)
)
- (func $littleswitch (param $0 i32) (result i32)
+ (func $littleswitch (param $x i32) (result i32)
(block $label$1 (result i32)
(block $label$2
(block $label$3
(br_table $label$3 $label$2 $label$3
(i32.sub
- (local.get $0)
+ (local.get $x)
(i32.const 1)
)
)
@@ -48,8 +48,8 @@
)
)
)
- (func $f1 (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
- (local.get $2)
+ (func $f1 (param $i1 i32) (param $i2 i32) (param $i3 i32) (result i32)
+ (local.get $i3)
)
)
diff --git a/test/multivalue.wast.fromBinary b/test/multivalue.wast.fromBinary
index f4a8e20b7..db471ebe5 100644
--- a/test/multivalue.wast.fromBinary
+++ b/test/multivalue.wast.fromBinary
@@ -121,7 +121,7 @@
(local.get $0)
)
(func $reverse (result f32 i64 i32)
- (local $0 i32)
+ (local $x i32)
(local $1 i64)
(local $2 i64)
(local $3 f32)
@@ -139,7 +139,7 @@
(local.set $5
(call $triple)
)
- (local.set $0
+ (local.set $x
(block (result i32)
(local.set $7
(tuple.extract 0
@@ -167,7 +167,7 @@
(drop
(block (result i32)
(local.set $9
- (local.get $0)
+ (local.get $x)
)
(drop
(block (result i64)
@@ -191,7 +191,7 @@
(drop
(block (result i32)
(local.set $11
- (local.get $0)
+ (local.get $x)
)
(local.set $2
(block (result i64)
@@ -212,7 +212,7 @@
(local.get $2)
(block (result i32)
(local.set $13
- (local.get $0)
+ (local.get $x)
)
(drop
(block (result i64)
diff --git a/test/polymorphic_stack.wast.fromBinary b/test/polymorphic_stack.wast.fromBinary
index 11d9eb590..1265bd080 100644
--- a/test/polymorphic_stack.wast.fromBinary
+++ b/test/polymorphic_stack.wast.fromBinary
@@ -12,8 +12,8 @@
(func $call-and-unary (param $0 i32) (result i32)
(unreachable)
)
- (func $tee (param $0 i32)
- (local $1 f32)
+ (func $tee (param $x i32)
+ (local $y f32)
(unreachable)
)
(func $tee2
diff --git a/test/reference-types.wast.fromBinary b/test/reference-types.wast.fromBinary
index 00e651305..7b63a755b 100644
--- a/test/reference-types.wast.fromBinary
+++ b/test/reference-types.wast.fromBinary
@@ -40,84 +40,84 @@
(nop)
)
(func $test
- (local $0 funcref)
- (local $1 externref)
- (local $2 exnref)
- (local $3 anyref)
- (local.set $1
- (local.get $1)
- )
- (local.set $1
+ (local $local_externref funcref)
+ (local $local_funcref externref)
+ (local $local_exnref exnref)
+ (local $local_anyref anyref)
+ (local.set $local_funcref
+ (local.get $local_funcref)
+ )
+ (local.set $local_funcref
(global.get $global$0)
)
- (local.set $1
+ (local.set $local_funcref
(ref.null extern)
)
- (local.set $0
- (local.get $0)
+ (local.set $local_externref
+ (local.get $local_externref)
)
- (local.set $0
+ (local.set $local_externref
(global.get $global$1)
)
- (local.set $0
+ (local.set $local_externref
(ref.null func)
)
- (local.set $0
+ (local.set $local_externref
(ref.func $foo)
)
- (local.set $2
- (local.get $2)
+ (local.set $local_exnref
+ (local.get $local_exnref)
)
- (local.set $2
+ (local.set $local_exnref
(global.get $global$3)
)
- (local.set $2
+ (local.set $local_exnref
(ref.null exn)
)
- (local.set $3
- (local.get $3)
+ (local.set $local_anyref
+ (local.get $local_anyref)
)
- (local.set $3
+ (local.set $local_anyref
(global.get $global$4)
)
- (local.set $3
+ (local.set $local_anyref
(ref.null any)
)
- (local.set $3
- (local.get $1)
+ (local.set $local_anyref
+ (local.get $local_funcref)
)
- (local.set $3
+ (local.set $local_anyref
(global.get $global$0)
)
- (local.set $3
+ (local.set $local_anyref
(ref.null extern)
)
- (local.set $3
- (local.get $0)
+ (local.set $local_anyref
+ (local.get $local_externref)
)
- (local.set $3
+ (local.set $local_anyref
(global.get $global$1)
)
- (local.set $3
+ (local.set $local_anyref
(ref.null func)
)
- (local.set $3
+ (local.set $local_anyref
(ref.func $foo)
)
- (local.set $3
- (local.get $2)
+ (local.set $local_anyref
+ (local.get $local_exnref)
)
- (local.set $3
+ (local.set $local_anyref
(global.get $global$3)
)
- (local.set $3
+ (local.set $local_anyref
(ref.null exn)
)
(global.set $global$0
(global.get $global$0)
)
(global.set $global$0
- (local.get $1)
+ (local.get $local_funcref)
)
(global.set $global$0
(ref.null extern)
@@ -126,7 +126,7 @@
(global.get $global$1)
)
(global.set $global$1
- (local.get $0)
+ (local.get $local_externref)
)
(global.set $global$1
(ref.null func)
@@ -138,7 +138,7 @@
(global.get $global$3)
)
(global.set $global$3
- (local.get $2)
+ (local.get $local_exnref)
)
(global.set $global$3
(ref.null exn)
@@ -147,7 +147,7 @@
(global.get $global$4)
)
(global.set $global$4
- (local.get $3)
+ (local.get $local_anyref)
)
(global.set $global$4
(ref.null any)
@@ -156,7 +156,7 @@
(global.get $global$0)
)
(global.set $global$4
- (local.get $1)
+ (local.get $local_funcref)
)
(global.set $global$4
(ref.null extern)
@@ -165,7 +165,7 @@
(global.get $global$1)
)
(global.set $global$4
- (local.get $0)
+ (local.get $local_externref)
)
(global.set $global$4
(ref.null func)
@@ -177,13 +177,13 @@
(global.get $global$3)
)
(global.set $global$4
- (local.get $2)
+ (local.get $local_exnref)
)
(global.set $global$4
(ref.null exn)
)
(call $take_externref
- (local.get $1)
+ (local.get $local_funcref)
)
(call $take_externref
(global.get $global$0)
@@ -192,7 +192,7 @@
(ref.null extern)
)
(call $take_funcref
- (local.get $0)
+ (local.get $local_externref)
)
(call $take_funcref
(global.get $global$1)
@@ -204,7 +204,7 @@
(ref.func $foo)
)
(call $take_exnref
- (local.get $2)
+ (local.get $local_exnref)
)
(call $take_exnref
(global.get $global$3)
@@ -213,7 +213,7 @@
(ref.null exn)
)
(call $take_anyref
- (local.get $3)
+ (local.get $local_anyref)
)
(call $take_anyref
(global.get $global$4)
@@ -222,7 +222,7 @@
(ref.null any)
)
(call $take_anyref
- (local.get $1)
+ (local.get $local_funcref)
)
(call $take_anyref
(global.get $global$0)
@@ -231,7 +231,7 @@
(ref.null extern)
)
(call $take_anyref
- (local.get $0)
+ (local.get $local_externref)
)
(call $take_anyref
(global.get $global$1)
@@ -243,7 +243,7 @@
(ref.func $foo)
)
(call $take_anyref
- (local.get $2)
+ (local.get $local_exnref)
)
(call $take_anyref
(global.get $global$3)
@@ -252,7 +252,7 @@
(ref.null exn)
)
(call_indirect (type $externref_=>_none)
- (local.get $1)
+ (local.get $local_funcref)
(i32.const 0)
)
(call_indirect (type $externref_=>_none)
@@ -264,7 +264,7 @@
(i32.const 0)
)
(call_indirect (type $funcref_=>_none)
- (local.get $0)
+ (local.get $local_externref)
(i32.const 1)
)
(call_indirect (type $funcref_=>_none)
@@ -280,7 +280,7 @@
(i32.const 1)
)
(call_indirect (type $exnref_=>_none)
- (local.get $2)
+ (local.get $local_exnref)
(i32.const 2)
)
(call_indirect (type $exnref_=>_none)
@@ -292,7 +292,7 @@
(i32.const 2)
)
(call_indirect (type $anyref_=>_none)
- (local.get $3)
+ (local.get $local_anyref)
(i32.const 3)
)
(call_indirect (type $anyref_=>_none)
@@ -304,7 +304,7 @@
(i32.const 3)
)
(call_indirect (type $anyref_=>_none)
- (local.get $1)
+ (local.get $local_funcref)
(i32.const 3)
)
(call_indirect (type $anyref_=>_none)
@@ -316,7 +316,7 @@
(i32.const 3)
)
(call_indirect (type $anyref_=>_none)
- (local.get $0)
+ (local.get $local_externref)
(i32.const 3)
)
(call_indirect (type $anyref_=>_none)
@@ -332,7 +332,7 @@
(i32.const 3)
)
(call_indirect (type $anyref_=>_none)
- (local.get $2)
+ (local.get $local_exnref)
(i32.const 3)
)
(call_indirect (type $anyref_=>_none)
@@ -346,7 +346,7 @@
(drop
(block $label$1 (result externref)
(br_if $label$1
- (local.get $1)
+ (local.get $local_funcref)
(i32.const 1)
)
)
@@ -370,7 +370,7 @@
(drop
(block $label$4 (result funcref)
(br_if $label$4
- (local.get $0)
+ (local.get $local_externref)
(i32.const 1)
)
)
@@ -402,7 +402,7 @@
(drop
(block $label$8 (result exnref)
(br_if $label$8
- (local.get $2)
+ (local.get $local_exnref)
(i32.const 1)
)
)
@@ -426,7 +426,7 @@
(drop
(block $label$11 (result anyref)
(br_if $label$11
- (local.get $3)
+ (local.get $local_anyref)
(i32.const 1)
)
)
@@ -450,7 +450,7 @@
(drop
(block $label$14 (result anyref)
(br_if $label$14
- (local.get $1)
+ (local.get $local_funcref)
(i32.const 1)
)
)
@@ -458,7 +458,7 @@
(drop
(block $label$15 (result anyref)
(br_if $label$15
- (local.get $0)
+ (local.get $local_externref)
(i32.const 1)
)
)
@@ -466,7 +466,7 @@
(drop
(block $label$16 (result anyref)
(br_if $label$16
- (local.get $2)
+ (local.get $local_exnref)
(i32.const 1)
)
)
@@ -505,7 +505,7 @@
)
(drop
(loop $label$21 (result externref)
- (local.get $1)
+ (local.get $local_funcref)
)
)
(drop
@@ -520,7 +520,7 @@
)
(drop
(loop $label$24 (result funcref)
- (local.get $0)
+ (local.get $local_externref)
)
)
(drop
@@ -540,7 +540,7 @@
)
(drop
(loop $label$28 (result exnref)
- (local.get $2)
+ (local.get $local_exnref)
)
)
(drop
@@ -555,7 +555,7 @@
)
(drop
(loop $label$31 (result anyref)
- (local.get $3)
+ (local.get $local_anyref)
)
)
(drop
@@ -570,7 +570,7 @@
)
(drop
(loop $label$34 (result anyref)
- (local.get $1)
+ (local.get $local_funcref)
)
)
(drop
@@ -585,7 +585,7 @@
)
(drop
(loop $label$37 (result anyref)
- (local.get $0)
+ (local.get $local_externref)
)
)
(drop
@@ -605,7 +605,7 @@
)
(drop
(loop $label$41 (result anyref)
- (local.get $2)
+ (local.get $local_exnref)
)
)
(drop
@@ -621,50 +621,50 @@
(drop
(if (result externref)
(i32.const 1)
- (local.get $1)
+ (local.get $local_funcref)
(ref.null extern)
)
)
(drop
(if (result funcref)
(i32.const 1)
- (local.get $0)
+ (local.get $local_externref)
(ref.null func)
)
)
(drop
(if (result exnref)
(i32.const 1)
- (local.get $2)
+ (local.get $local_exnref)
(ref.null exn)
)
)
(drop
(if (result anyref)
(i32.const 1)
- (local.get $3)
+ (local.get $local_anyref)
(ref.null any)
)
)
(drop
(if (result anyref)
(i32.const 1)
- (local.get $1)
- (local.get $0)
+ (local.get $local_funcref)
+ (local.get $local_externref)
)
)
(drop
(if (result anyref)
(i32.const 1)
- (local.get $1)
- (local.get $2)
+ (local.get $local_funcref)
+ (local.get $local_exnref)
)
)
(drop
(if (result anyref)
(i32.const 1)
- (local.get $0)
- (local.get $2)
+ (local.get $local_externref)
+ (local.get $local_exnref)
)
)
(drop
@@ -698,7 +698,7 @@
(drop
(try (result externref)
(do
- (local.get $1)
+ (local.get $local_funcref)
)
(catch
(drop
@@ -734,7 +734,7 @@
(drop
(try (result anyref)
(do
- (local.get $1)
+ (local.get $local_funcref)
)
(catch
(drop
@@ -747,7 +747,7 @@
(drop
(try (result anyref)
(do
- (local.get $1)
+ (local.get $local_funcref)
)
(catch
(pop exnref)
@@ -763,7 +763,7 @@
(drop
(pop exnref)
)
- (local.get $1)
+ (local.get $local_funcref)
)
)
)
@@ -786,7 +786,7 @@
(drop
(pop exnref)
)
- (local.get $1)
+ (local.get $local_funcref)
)
)
)
@@ -805,21 +805,21 @@
)
(drop
(select (result externref)
- (local.get $1)
+ (local.get $local_funcref)
(ref.null extern)
(i32.const 1)
)
)
(drop
(select (result funcref)
- (local.get $0)
+ (local.get $local_externref)
(ref.null func)
(i32.const 1)
)
)
(drop
(select (result exnref)
- (local.get $2)
+ (local.get $local_exnref)
(ref.null exn)
(i32.const 1)
)
@@ -833,49 +833,49 @@
)
(drop
(select (result anyref)
- (local.get $1)
- (local.get $0)
+ (local.get $local_funcref)
+ (local.get $local_externref)
(i32.const 1)
)
)
(drop
(select (result anyref)
- (local.get $1)
- (local.get $2)
+ (local.get $local_funcref)
+ (local.get $local_exnref)
(i32.const 1)
)
)
(drop
(select (result anyref)
- (local.get $0)
- (local.get $1)
+ (local.get $local_externref)
+ (local.get $local_funcref)
(i32.const 1)
)
)
(drop
(select (result anyref)
- (local.get $0)
- (local.get $2)
+ (local.get $local_externref)
+ (local.get $local_exnref)
(i32.const 1)
)
)
(drop
(select (result anyref)
- (local.get $2)
- (local.get $1)
+ (local.get $local_exnref)
+ (local.get $local_funcref)
(i32.const 1)
)
)
(drop
(select (result anyref)
- (local.get $2)
- (local.get $0)
+ (local.get $local_exnref)
+ (local.get $local_externref)
(i32.const 1)
)
)
(drop
(ref.is_null
- (local.get $1)
+ (local.get $local_funcref)
)
)
(drop
@@ -890,7 +890,7 @@
)
(drop
(ref.is_null
- (local.get $0)
+ (local.get $local_externref)
)
)
(drop
@@ -910,7 +910,7 @@
)
(drop
(ref.is_null
- (local.get $2)
+ (local.get $local_exnref)
)
)
(drop
@@ -925,7 +925,7 @@
)
(drop
(ref.is_null
- (local.get $3)
+ (local.get $local_anyref)
)
)
(drop
@@ -940,8 +940,8 @@
)
)
(func $return_externref_local (result externref)
- (local $0 externref)
- (local.get $0)
+ (local $local_externref externref)
+ (local.get $local_externref)
)
(func $return_externref_global (result externref)
(global.get $global$0)
@@ -950,8 +950,8 @@
(ref.null extern)
)
(func $return_funcref_local (result funcref)
- (local $0 funcref)
- (local.get $0)
+ (local $local_funcref funcref)
+ (local.get $local_funcref)
)
(func $return_funcref_global (result funcref)
(global.get $global$1)
@@ -963,8 +963,8 @@
(ref.func $foo)
)
(func $return_exnref_local (result exnref)
- (local $0 exnref)
- (local.get $0)
+ (local $local_exnref exnref)
+ (local.get $local_exnref)
)
(func $return_exnref_global (result exnref)
(global.get $global$3)
@@ -973,8 +973,8 @@
(ref.null exn)
)
(func $return_anyref_local (result anyref)
- (local $0 anyref)
- (local.get $0)
+ (local $local_anyref anyref)
+ (local.get $local_anyref)
)
(func $return_anyref_global (result anyref)
(global.get $global$4)
@@ -983,8 +983,8 @@
(ref.null any)
)
(func $return_anyref2 (result anyref)
- (local $0 externref)
- (local.get $0)
+ (local $local_externref externref)
+ (local.get $local_externref)
)
(func $return_anyref3 (result anyref)
(global.get $global$0)
@@ -993,8 +993,8 @@
(ref.null extern)
)
(func $return_anyref5 (result anyref)
- (local $0 funcref)
- (local.get $0)
+ (local $local_funcref funcref)
+ (local.get $local_funcref)
)
(func $return_anyref6 (result anyref)
(global.get $global$1)
@@ -1006,8 +1006,8 @@
(ref.func $foo)
)
(func $return_anyref9 (result anyref)
- (local $0 exnref)
- (local.get $0)
+ (local $local_exnref exnref)
+ (local.get $local_exnref)
)
(func $return_anyref10 (result anyref)
(global.get $global$3)
@@ -1016,35 +1016,35 @@
(ref.null exn)
)
(func $returns_externref (result externref)
- (local $0 externref)
+ (local $local_externref externref)
(return
- (local.get $0)
+ (local.get $local_externref)
)
)
(func $returns_funcref (result funcref)
- (local $0 funcref)
+ (local $local_funcref funcref)
(return
- (local.get $0)
+ (local.get $local_funcref)
)
)
(func $returns_exnref (result exnref)
- (local $0 exnref)
+ (local $local_exnref exnref)
(return
- (local.get $0)
+ (local.get $local_exnref)
)
)
(func $returns_anyref (result anyref)
- (local $0 anyref)
+ (local $local_anyref anyref)
(return
- (local.get $0)
+ (local.get $local_anyref)
)
)
(func $returns_anyref2 (result anyref)
- (local $0 funcref)
- (local $1 externref)
- (local $2 exnref)
+ (local $local_externref funcref)
+ (local $local_funcref externref)
+ (local $local_exnref exnref)
(return
- (local.get $1)
+ (local.get $local_funcref)
)
)
)