summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm-binary.h8
-rw-r--r--src/wasm-stack.h14
-rw-r--r--src/wasm/wasm-binary.cpp34
-rw-r--r--src/wasm/wasm-stack.cpp33
-rw-r--r--test/atomics64.wast.fromBinary86
-rw-r--r--test/atomics64.wast.fromBinary.noDebugInfo86
-rw-r--r--test/heap-types.wast.fromBinary12
-rw-r--r--test/heap-types.wast.fromBinary.noDebugInfo12
-rw-r--r--test/passes/reorder-locals_print_roundtrip.txt58
-rw-r--r--test/passes/reorder-locals_print_roundtrip.wast19
-rw-r--r--test/reference-types.wast.fromBinary96
-rw-r--r--test/reference-types.wast.fromBinary.noDebugInfo96
-rw-r--r--test/typed-function-references.wast.fromBinary4
-rw-r--r--test/typed-function-references.wast.fromBinary.noDebugInfo4
14 files changed, 339 insertions, 223 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index 9f298662b..d490a2a96 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -1090,6 +1090,9 @@ enum FeaturePrefix {
} // namespace BinaryConsts
+// (local index in IR, tuple index) => binary local index
+using MappedLocals = std::unordered_map<std::pair<Index, Index>, size_t>;
+
// Writes out wasm to the binary format
class WasmBinaryWriter {
@@ -1275,6 +1278,11 @@ private:
// the function is written out.
std::vector<Expression*> binaryLocationTrackedExpressionsForFunc;
+ // Maps function names to their mapped locals. This is used when we emit the
+ // local names section: we map the locals when writing the function, save that
+ // info here, and then use it when writing the names.
+ std::unordered_map<Name, MappedLocals> funcMappedLocals;
+
void prepare();
};
diff --git a/src/wasm-stack.h b/src/wasm-stack.h
index 5af9adbce..38b64dff4 100644
--- a/src/wasm-stack.h
+++ b/src/wasm-stack.h
@@ -118,6 +118,8 @@ public:
void emitUnreachable();
void mapLocalsAndEmitHeader();
+ MappedLocals mappedLocals;
+
private:
void emitMemoryAccess(size_t alignment, size_t bytes, uint32_t offset);
int32_t getBreakIndex(Name name);
@@ -130,10 +132,12 @@ private:
std::vector<Name> breakStack;
+ // The types of locals in the compact form, in order.
+ std::vector<Type> localTypes;
// type => number of locals of that type in the compact form
- std::map<Type, size_t> numLocalsByType;
- // (local index, tuple index) => binary local index
- std::map<std::pair<Index, Index>, size_t> mappedLocals;
+ std::unordered_map<Type, size_t> numLocalsByType;
+
+ void noteLocalType(Type type);
// Keeps track of the binary index of the scratch locals used to lower
// tuple.extract.
@@ -401,6 +405,8 @@ public:
}
}
+ MappedLocals& getMappedLocals() { return writer.mappedLocals; }
+
private:
WasmBinaryWriter& parent;
BinaryInstWriter writer;
@@ -458,6 +464,8 @@ public:
void write();
+ MappedLocals& getMappedLocals() { return writer.mappedLocals; }
+
private:
BinaryInstWriter writer;
Function* func;
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 0993eb124..0f40cfd58 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -336,10 +336,18 @@ void WasmBinaryWriter::writeFunctions() {
// Emit Stack IR if present, and if we can
if (func->stackIR && !sourceMap && !DWARF) {
BYN_TRACE("write Stack IR\n");
- StackIRToBinaryWriter(*this, o, func).write();
+ StackIRToBinaryWriter writer(*this, o, func);
+ writer.write();
+ if (debugInfo) {
+ funcMappedLocals[func->name] = std::move(writer.getMappedLocals());
+ }
} else {
BYN_TRACE("write Binaryen IR\n");
- BinaryenIRToBinaryWriter(*this, o, func, sourceMap, DWARF).write();
+ BinaryenIRToBinaryWriter writer(*this, o, func, sourceMap, DWARF);
+ writer.write();
+ if (debugInfo) {
+ funcMappedLocals[func->name] = std::move(writer.getMappedLocals());
+ }
}
size_t size = o.size() - start;
assert(size <= std::numeric_limits<uint32_t>::max());
@@ -678,20 +686,28 @@ void WasmBinaryWriter::writeNames() {
startSubsection(BinaryConsts::UserSections::Subsection::NameLocal);
o << U32LEB(functionsWithLocalNames.size());
Index emitted = 0;
- for (auto& indexedFunc : functionsWithLocalNames) {
+ for (auto& kv : functionsWithLocalNames) {
+ auto index = kv.first;
+ auto* func = kv.second;
+ // Pairs of (local index in IR, name).
std::vector<std::pair<Index, Name>> localsWithNames;
- auto numLocals = indexedFunc.second->getNumLocals();
+ auto numLocals = func->getNumLocals();
for (Index i = 0; i < numLocals; ++i) {
- if (indexedFunc.second->hasLocalName(i)) {
- localsWithNames.push_back({i, indexedFunc.second->getLocalName(i)});
+ if (func->hasLocalName(i)) {
+ localsWithNames.push_back({i, func->getLocalName(i)});
}
}
assert(localsWithNames.size());
- o << U32LEB(indexedFunc.first);
+ o << U32LEB(index);
o << U32LEB(localsWithNames.size());
for (auto& indexedLocal : localsWithNames) {
- o << U32LEB(indexedLocal.first);
- writeEscapedName(indexedLocal.second.str);
+ auto indexInFunc = indexedLocal.first;
+ auto name = indexedLocal.second;
+ // TODO: handle multivalue
+ auto indexInBinary =
+ funcMappedLocals.at(func->name)[{indexInFunc, 0}];
+ o << U32LEB(indexInBinary);
+ writeEscapedName(name.str);
}
emitted++;
}
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp
index 4c4e4e9d1..0c7448c58 100644
--- a/src/wasm/wasm-stack.cpp
+++ b/src/wasm/wasm-stack.cpp
@@ -2166,7 +2166,7 @@ void BinaryInstWriter::mapLocalsAndEmitHeader() {
}
for (auto type : func->vars) {
for (const auto& t : type) {
- numLocalsByType[t]++;
+ noteLocalType(t);
}
}
countScratchLocals();
@@ -2176,24 +2176,31 @@ void BinaryInstWriter::mapLocalsAndEmitHeader() {
for (const auto& type : func->getLocalType(i)) {
auto fullIndex = std::make_pair(i, j++);
Index index = func->getVarIndexBase();
- for (auto& typeCount : numLocalsByType) {
- if (type == typeCount.first) {
- mappedLocals[fullIndex] = index + currLocalsByType[typeCount.first];
+ for (auto& localType : localTypes) {
+ if (type == localType) {
+ mappedLocals[fullIndex] = index + currLocalsByType[localType];
currLocalsByType[type]++;
break;
}
- index += typeCount.second;
+ index += numLocalsByType.at(localType);
}
}
}
setScratchLocals();
o << U32LEB(numLocalsByType.size());
- for (auto& typeCount : numLocalsByType) {
- o << U32LEB(typeCount.second);
- parent.writeType(typeCount.first);
+ for (auto& localType : localTypes) {
+ o << U32LEB(numLocalsByType.at(localType));
+ parent.writeType(localType);
}
}
+void BinaryInstWriter::noteLocalType(Type type) {
+ if (!numLocalsByType.count(type)) {
+ localTypes.push_back(type);
+ }
+ numLocalsByType[type]++;
+}
+
void BinaryInstWriter::countScratchLocals() {
// Add a scratch register in `numLocalsByType` for each type of
// tuple.extract with nonzero index present.
@@ -2204,16 +2211,16 @@ void BinaryInstWriter::countScratchLocals() {
}
}
for (auto t : scratchLocals) {
- numLocalsByType[t.first]++;
+ noteLocalType(t.first);
}
}
void BinaryInstWriter::setScratchLocals() {
Index index = func->getVarIndexBase();
- for (auto& typeCount : numLocalsByType) {
- index += typeCount.second;
- if (scratchLocals.find(typeCount.first) != scratchLocals.end()) {
- scratchLocals[typeCount.first] = index - 1;
+ for (auto& localType : localTypes) {
+ index += numLocalsByType[localType];
+ if (scratchLocals.find(localType) != scratchLocals.end()) {
+ scratchLocals[localType] = index - 1;
}
}
}
diff --git a/test/atomics64.wast.fromBinary b/test/atomics64.wast.fromBinary
index 2661142cf..60ab444ce 100644
--- a/test/atomics64.wast.fromBinary
+++ b/test/atomics64.wast.fromBinary
@@ -2,183 +2,183 @@
(type $0 (func))
(memory $0 (shared i64 23 256))
(func $atomic-loadstore
- (local $0 i32)
+ (local $0 i64)
(local $1 i64)
- (local $2 i64)
+ (local $2 i32)
(drop
(i32.atomic.load8_u offset=4
- (local.get $1)
+ (local.get $0)
)
)
(drop
(i32.atomic.load16_u offset=4
- (local.get $1)
+ (local.get $0)
)
)
(drop
(i32.atomic.load offset=4
- (local.get $1)
+ (local.get $0)
)
)
(drop
(i64.atomic.load8_u
- (local.get $1)
+ (local.get $0)
)
)
(drop
(i64.atomic.load16_u
- (local.get $1)
+ (local.get $0)
)
)
(drop
(i64.atomic.load32_u
- (local.get $1)
+ (local.get $0)
)
)
(drop
(i64.atomic.load
- (local.get $1)
+ (local.get $0)
)
)
(i32.atomic.store offset=4
- (local.get $1)
(local.get $0)
+ (local.get $2)
)
(i32.atomic.store8 offset=4
- (local.get $1)
(local.get $0)
+ (local.get $2)
)
(i32.atomic.store16 offset=4
- (local.get $1)
(local.get $0)
+ (local.get $2)
)
(i64.atomic.store offset=4
+ (local.get $0)
(local.get $1)
- (local.get $2)
)
(i64.atomic.store8 offset=4
+ (local.get $0)
(local.get $1)
- (local.get $2)
)
(i64.atomic.store16 offset=4
+ (local.get $0)
(local.get $1)
- (local.get $2)
)
(i64.atomic.store32 offset=4
+ (local.get $0)
(local.get $1)
- (local.get $2)
)
)
(func $atomic-rmw
- (local $0 i32)
+ (local $0 i64)
(local $1 i64)
- (local $2 i64)
+ (local $2 i32)
(drop
(i32.atomic.rmw.add offset=4
- (local.get $1)
(local.get $0)
+ (local.get $2)
)
)
(drop
(i32.atomic.rmw8.add_u offset=4
- (local.get $1)
(local.get $0)
+ (local.get $2)
)
)
(drop
(i32.atomic.rmw16.and_u
- (local.get $1)
(local.get $0)
+ (local.get $2)
)
)
(drop
(i64.atomic.rmw32.or_u
+ (local.get $0)
(local.get $1)
- (local.get $2)
)
)
(drop
(i32.atomic.rmw8.xchg_u
- (local.get $1)
(local.get $0)
+ (local.get $2)
)
)
)
(func $atomic-cmpxchg
- (local $0 i32)
+ (local $0 i64)
(local $1 i64)
- (local $2 i64)
+ (local $2 i32)
(drop
(i32.atomic.rmw.cmpxchg offset=4
- (local.get $1)
- (local.get $0)
(local.get $0)
+ (local.get $2)
+ (local.get $2)
)
)
(drop
(i32.atomic.rmw8.cmpxchg_u
- (local.get $1)
- (local.get $0)
(local.get $0)
+ (local.get $2)
+ (local.get $2)
)
)
(drop
(i64.atomic.rmw.cmpxchg offset=4
+ (local.get $0)
+ (local.get $1)
(local.get $1)
- (local.get $2)
- (local.get $2)
)
)
(drop
(i64.atomic.rmw32.cmpxchg_u
+ (local.get $0)
+ (local.get $1)
(local.get $1)
- (local.get $2)
- (local.get $2)
)
)
)
(func $atomic-wait-notify
- (local $0 i32)
+ (local $0 i64)
(local $1 i64)
- (local $2 i64)
+ (local $2 i32)
(drop
(memory.atomic.wait32
- (local.get $1)
(local.get $0)
(local.get $2)
+ (local.get $1)
)
)
(drop
(memory.atomic.wait32 offset=4
- (local.get $1)
(local.get $0)
(local.get $2)
+ (local.get $1)
)
)
(drop
(memory.atomic.notify
- (local.get $1)
(local.get $0)
+ (local.get $2)
)
)
(drop
(memory.atomic.notify offset=24
- (local.get $1)
(local.get $0)
+ (local.get $2)
)
)
(drop
(memory.atomic.wait64
+ (local.get $0)
+ (local.get $1)
(local.get $1)
- (local.get $2)
- (local.get $2)
)
)
(drop
(memory.atomic.wait64 offset=16
+ (local.get $0)
+ (local.get $1)
(local.get $1)
- (local.get $2)
- (local.get $2)
)
)
)
diff --git a/test/atomics64.wast.fromBinary.noDebugInfo b/test/atomics64.wast.fromBinary.noDebugInfo
index afa8a3b7c..c3f508833 100644
--- a/test/atomics64.wast.fromBinary.noDebugInfo
+++ b/test/atomics64.wast.fromBinary.noDebugInfo
@@ -2,183 +2,183 @@
(type $none_=>_none (func))
(memory $0 (shared i64 23 256))
(func $0
- (local $0 i32)
+ (local $0 i64)
(local $1 i64)
- (local $2 i64)
+ (local $2 i32)
(drop
(i32.atomic.load8_u offset=4
- (local.get $1)
+ (local.get $0)
)
)
(drop
(i32.atomic.load16_u offset=4
- (local.get $1)
+ (local.get $0)
)
)
(drop
(i32.atomic.load offset=4
- (local.get $1)
+ (local.get $0)
)
)
(drop
(i64.atomic.load8_u
- (local.get $1)
+ (local.get $0)
)
)
(drop
(i64.atomic.load16_u
- (local.get $1)
+ (local.get $0)
)
)
(drop
(i64.atomic.load32_u
- (local.get $1)
+ (local.get $0)
)
)
(drop
(i64.atomic.load
- (local.get $1)
+ (local.get $0)
)
)
(i32.atomic.store offset=4
- (local.get $1)
(local.get $0)
+ (local.get $2)
)
(i32.atomic.store8 offset=4
- (local.get $1)
(local.get $0)
+ (local.get $2)
)
(i32.atomic.store16 offset=4
- (local.get $1)
(local.get $0)
+ (local.get $2)
)
(i64.atomic.store offset=4
+ (local.get $0)
(local.get $1)
- (local.get $2)
)
(i64.atomic.store8 offset=4
+ (local.get $0)
(local.get $1)
- (local.get $2)
)
(i64.atomic.store16 offset=4
+ (local.get $0)
(local.get $1)
- (local.get $2)
)
(i64.atomic.store32 offset=4
+ (local.get $0)
(local.get $1)
- (local.get $2)
)
)
(func $1
- (local $0 i32)
+ (local $0 i64)
(local $1 i64)
- (local $2 i64)
+ (local $2 i32)
(drop
(i32.atomic.rmw.add offset=4
- (local.get $1)
(local.get $0)
+ (local.get $2)
)
)
(drop
(i32.atomic.rmw8.add_u offset=4
- (local.get $1)
(local.get $0)
+ (local.get $2)
)
)
(drop
(i32.atomic.rmw16.and_u
- (local.get $1)
(local.get $0)
+ (local.get $2)
)
)
(drop
(i64.atomic.rmw32.or_u
+ (local.get $0)
(local.get $1)
- (local.get $2)
)
)
(drop
(i32.atomic.rmw8.xchg_u
- (local.get $1)
(local.get $0)
+ (local.get $2)
)
)
)
(func $2
- (local $0 i32)
+ (local $0 i64)
(local $1 i64)
- (local $2 i64)
+ (local $2 i32)
(drop
(i32.atomic.rmw.cmpxchg offset=4
- (local.get $1)
- (local.get $0)
(local.get $0)
+ (local.get $2)
+ (local.get $2)
)
)
(drop
(i32.atomic.rmw8.cmpxchg_u
- (local.get $1)
- (local.get $0)
(local.get $0)
+ (local.get $2)
+ (local.get $2)
)
)
(drop
(i64.atomic.rmw.cmpxchg offset=4
+ (local.get $0)
+ (local.get $1)
(local.get $1)
- (local.get $2)
- (local.get $2)
)
)
(drop
(i64.atomic.rmw32.cmpxchg_u
+ (local.get $0)
+ (local.get $1)
(local.get $1)
- (local.get $2)
- (local.get $2)
)
)
)
(func $3
- (local $0 i32)
+ (local $0 i64)
(local $1 i64)
- (local $2 i64)
+ (local $2 i32)
(drop
(memory.atomic.wait32
- (local.get $1)
(local.get $0)
(local.get $2)
+ (local.get $1)
)
)
(drop
(memory.atomic.wait32 offset=4
- (local.get $1)
(local.get $0)
(local.get $2)
+ (local.get $1)
)
)
(drop
(memory.atomic.notify
- (local.get $1)
(local.get $0)
+ (local.get $2)
)
)
(drop
(memory.atomic.notify offset=24
- (local.get $1)
(local.get $0)
+ (local.get $2)
)
)
(drop
(memory.atomic.wait64
+ (local.get $0)
+ (local.get $1)
(local.get $1)
- (local.get $2)
- (local.get $2)
)
)
(drop
(memory.atomic.wait64 offset=16
+ (local.get $0)
+ (local.get $1)
(local.get $1)
- (local.get $2)
- (local.get $2)
)
)
)
diff --git a/test/heap-types.wast.fromBinary b/test/heap-types.wast.fromBinary
index 90e129511..3b75de68f 100644
--- a/test/heap-types.wast.fromBinary
+++ b/test/heap-types.wast.fromBinary
@@ -26,8 +26,8 @@
(local $tA (ref null $struct.A))
(local $tB (ref null $struct.B))
(local $tc (ref null $struct.C))
- (local $tv (ref null $matrix))
- (local $tm (ref null $vector))
+ (local $tv (ref null $vector))
+ (local $tm (ref null $matrix))
(drop
(local.get $x)
)
@@ -118,10 +118,10 @@
(unreachable)
)
(func $arrays (param $x (ref null $vector)) (result (ref null $matrix))
- (local $tv (ref null $matrix))
- (local $tm (ref null $words))
+ (local $tv (ref null $vector))
+ (local $tm (ref null $matrix))
(local $tb (ref null $bytes))
- (local $tw (ref null $vector))
+ (local $tw (ref null $words))
(drop
(array.new_with_rtt $vector
(f64.const 3.14159)
@@ -153,7 +153,7 @@
)
(drop
(array.get $words
- (local.get $tm)
+ (local.get $tw)
(i32.const 1)
)
)
diff --git a/test/heap-types.wast.fromBinary.noDebugInfo b/test/heap-types.wast.fromBinary.noDebugInfo
index e75ddbe26..a4b16afd8 100644
--- a/test/heap-types.wast.fromBinary.noDebugInfo
+++ b/test/heap-types.wast.fromBinary.noDebugInfo
@@ -26,8 +26,8 @@
(local $1 (ref null ${i32_f32_f64}))
(local $2 (ref null ${i8_mut:i16_ref?|{i32_f32_f64}|_mut:ref?|{i32_f32_f64}|}))
(local $3 (ref null ${mut:f32}))
- (local $4 (ref null $[ref?|[mut:f64]|]))
- (local $5 (ref null $[mut:f64]))
+ (local $4 (ref null $[mut:f64]))
+ (local $5 (ref null $[ref?|[mut:f64]|]))
(drop
(local.get $0)
)
@@ -118,10 +118,10 @@
(unreachable)
)
(func $1 (param $0 (ref null $[mut:f64])) (result (ref null $[ref?|[mut:f64]|]))
- (local $1 (ref null $[ref?|[mut:f64]|]))
- (local $2 (ref null $[mut:i32]))
+ (local $1 (ref null $[mut:f64]))
+ (local $2 (ref null $[ref?|[mut:f64]|]))
(local $3 (ref null $[mut:i8]))
- (local $4 (ref null $[mut:f64]))
+ (local $4 (ref null $[mut:i32]))
(drop
(array.new_with_rtt $[mut:f64]
(f64.const 3.14159)
@@ -153,7 +153,7 @@
)
(drop
(array.get $[mut:i32]
- (local.get $2)
+ (local.get $4)
(i32.const 1)
)
)
diff --git a/test/passes/reorder-locals_print_roundtrip.txt b/test/passes/reorder-locals_print_roundtrip.txt
new file mode 100644
index 000000000..5e97559c4
--- /dev/null
+++ b/test/passes/reorder-locals_print_roundtrip.txt
@@ -0,0 +1,58 @@
+(module
+ (type $none_=>_none (func))
+ (func $a
+ (local $x i32)
+ (local $y f64)
+ (drop
+ (local.get $x)
+ )
+ (drop
+ (local.get $x)
+ )
+ (drop
+ (local.get $y)
+ )
+ )
+ (func $b
+ (local $y f64)
+ (local $x i32)
+ (drop
+ (local.get $x)
+ )
+ (drop
+ (local.get $y)
+ )
+ (drop
+ (local.get $y)
+ )
+ )
+)
+(module
+ (type $none_=>_none (func))
+ (func $a
+ (local $x i32)
+ (local $y f64)
+ (drop
+ (local.get $x)
+ )
+ (drop
+ (local.get $x)
+ )
+ (drop
+ (local.get $y)
+ )
+ )
+ (func $b
+ (local $y f64)
+ (local $x i32)
+ (drop
+ (local.get $x)
+ )
+ (drop
+ (local.get $y)
+ )
+ (drop
+ (local.get $y)
+ )
+ )
+)
diff --git a/test/passes/reorder-locals_print_roundtrip.wast b/test/passes/reorder-locals_print_roundtrip.wast
new file mode 100644
index 000000000..764c16470
--- /dev/null
+++ b/test/passes/reorder-locals_print_roundtrip.wast
@@ -0,0 +1,19 @@
+(module
+ (func $a
+ (local $x i32)
+ (local $y f64)
+ ;; x appears twice
+ (drop (local.get $x))
+ (drop (local.get $x))
+ (drop (local.get $y))
+ )
+ (func $b
+ (local $x i32)
+ (local $y f64)
+ ;; y appears twice, so it will be reordered to be first, and that should be
+ ;; preserved in the binary format
+ (drop (local.get $x))
+ (drop (local.get $y))
+ (drop (local.get $y))
+ )
+)
diff --git a/test/reference-types.wast.fromBinary b/test/reference-types.wast.fromBinary
index f55aae6be..16f59d07a 100644
--- a/test/reference-types.wast.fromBinary
+++ b/test/reference-types.wast.fromBinary
@@ -36,28 +36,28 @@
(nop)
)
(func $test
- (local $local_externref funcref)
- (local $local_funcref externref)
+ (local $local_externref externref)
+ (local $local_funcref funcref)
(local $local_anyref anyref)
- (local.set $local_funcref
- (local.get $local_funcref)
+ (local.set $local_externref
+ (local.get $local_externref)
)
- (local.set $local_funcref
+ (local.set $local_externref
(global.get $global_externref)
)
- (local.set $local_funcref
+ (local.set $local_externref
(ref.null extern)
)
- (local.set $local_externref
- (local.get $local_externref)
+ (local.set $local_funcref
+ (local.get $local_funcref)
)
- (local.set $local_externref
+ (local.set $local_funcref
(global.get $global_funcref)
)
- (local.set $local_externref
+ (local.set $local_funcref
(ref.null func)
)
- (local.set $local_externref
+ (local.set $local_funcref
(ref.func $foo)
)
(local.set $local_anyref
@@ -70,7 +70,7 @@
(ref.null any)
)
(local.set $local_anyref
- (local.get $local_funcref)
+ (local.get $local_externref)
)
(local.set $local_anyref
(global.get $global_externref)
@@ -79,7 +79,7 @@
(ref.null extern)
)
(local.set $local_anyref
- (local.get $local_externref)
+ (local.get $local_funcref)
)
(local.set $local_anyref
(global.get $global_funcref)
@@ -94,7 +94,7 @@
(global.get $global_externref)
)
(global.set $global_externref
- (local.get $local_funcref)
+ (local.get $local_externref)
)
(global.set $global_externref
(ref.null extern)
@@ -103,7 +103,7 @@
(global.get $global_funcref)
)
(global.set $global_funcref
- (local.get $local_externref)
+ (local.get $local_funcref)
)
(global.set $global_funcref
(ref.null func)
@@ -124,7 +124,7 @@
(global.get $global_externref)
)
(global.set $global_anyref
- (local.get $local_funcref)
+ (local.get $local_externref)
)
(global.set $global_anyref
(ref.null extern)
@@ -133,7 +133,7 @@
(global.get $global_funcref)
)
(global.set $global_anyref
- (local.get $local_externref)
+ (local.get $local_funcref)
)
(global.set $global_anyref
(ref.null func)
@@ -142,7 +142,7 @@
(ref.func $foo)
)
(call $take_externref
- (local.get $local_funcref)
+ (local.get $local_externref)
)
(call $take_externref
(global.get $global_externref)
@@ -151,7 +151,7 @@
(ref.null extern)
)
(call $take_funcref
- (local.get $local_externref)
+ (local.get $local_funcref)
)
(call $take_funcref
(global.get $global_funcref)
@@ -172,7 +172,7 @@
(ref.null any)
)
(call $take_anyref
- (local.get $local_funcref)
+ (local.get $local_externref)
)
(call $take_anyref
(global.get $global_externref)
@@ -181,7 +181,7 @@
(ref.null extern)
)
(call $take_anyref
- (local.get $local_externref)
+ (local.get $local_funcref)
)
(call $take_anyref
(global.get $global_funcref)
@@ -193,7 +193,7 @@
(ref.func $foo)
)
(call_indirect $0 (type $sig_externref)
- (local.get $local_funcref)
+ (local.get $local_externref)
(i32.const 0)
)
(call_indirect $0 (type $sig_externref)
@@ -205,7 +205,7 @@
(i32.const 0)
)
(call_indirect $0 (type $sig_funcref)
- (local.get $local_externref)
+ (local.get $local_funcref)
(i32.const 1)
)
(call_indirect $0 (type $sig_funcref)
@@ -233,7 +233,7 @@
(i32.const 3)
)
(call_indirect $0 (type $sig_anyref)
- (local.get $local_funcref)
+ (local.get $local_externref)
(i32.const 3)
)
(call_indirect $0 (type $sig_anyref)
@@ -245,7 +245,7 @@
(i32.const 3)
)
(call_indirect $0 (type $sig_anyref)
- (local.get $local_externref)
+ (local.get $local_funcref)
(i32.const 3)
)
(call_indirect $0 (type $sig_anyref)
@@ -263,7 +263,7 @@
(drop
(block $label$1 (result externref)
(br_if $label$1
- (local.get $local_funcref)
+ (local.get $local_externref)
(i32.const 1)
)
)
@@ -287,7 +287,7 @@
(drop
(block $label$4 (result funcref)
(br_if $label$4
- (local.get $local_externref)
+ (local.get $local_funcref)
(i32.const 1)
)
)
@@ -343,7 +343,7 @@
(drop
(block $label$11 (result anyref)
(br_if $label$11
- (local.get $local_funcref)
+ (local.get $local_externref)
(i32.const 1)
)
)
@@ -351,7 +351,7 @@
(drop
(block $label$12 (result anyref)
(br_if $label$12
- (local.get $local_externref)
+ (local.get $local_funcref)
(i32.const 1)
)
)
@@ -382,7 +382,7 @@
)
(drop
(loop $label$16 (result externref)
- (local.get $local_funcref)
+ (local.get $local_externref)
)
)
(drop
@@ -397,7 +397,7 @@
)
(drop
(loop $label$19 (result funcref)
- (local.get $local_externref)
+ (local.get $local_funcref)
)
)
(drop
@@ -432,7 +432,7 @@
)
(drop
(loop $label$26 (result anyref)
- (local.get $local_funcref)
+ (local.get $local_externref)
)
)
(drop
@@ -447,7 +447,7 @@
)
(drop
(loop $label$29 (result anyref)
- (local.get $local_externref)
+ (local.get $local_funcref)
)
)
(drop
@@ -468,14 +468,14 @@
(drop
(if (result externref)
(i32.const 1)
- (local.get $local_funcref)
+ (local.get $local_externref)
(ref.null extern)
)
)
(drop
(if (result funcref)
(i32.const 1)
- (local.get $local_externref)
+ (local.get $local_funcref)
(ref.null func)
)
)
@@ -489,8 +489,8 @@
(drop
(if (result anyref)
(i32.const 1)
- (local.get $local_funcref)
(local.get $local_externref)
+ (local.get $local_funcref)
)
)
(drop
@@ -510,7 +510,7 @@
(drop
(try $label$47 (result externref)
(do
- (local.get $local_funcref)
+ (local.get $local_externref)
)
(catch $event$0
(drop
@@ -536,7 +536,7 @@
(drop
(try $label$53 (result anyref)
(do
- (local.get $local_funcref)
+ (local.get $local_externref)
)
(catch $event$0
(drop
@@ -555,20 +555,20 @@
(drop
(pop i32)
)
- (local.get $local_funcref)
+ (local.get $local_externref)
)
)
)
(drop
(select (result externref)
- (local.get $local_funcref)
+ (local.get $local_externref)
(ref.null extern)
(i32.const 1)
)
)
(drop
(select (result funcref)
- (local.get $local_externref)
+ (local.get $local_funcref)
(ref.null func)
(i32.const 1)
)
@@ -582,21 +582,21 @@
)
(drop
(select (result anyref)
- (local.get $local_funcref)
(local.get $local_externref)
+ (local.get $local_funcref)
(i32.const 1)
)
)
(drop
(select (result anyref)
- (local.get $local_externref)
(local.get $local_funcref)
+ (local.get $local_externref)
(i32.const 1)
)
)
(drop
(ref.is_null
- (local.get $local_funcref)
+ (local.get $local_externref)
)
)
(drop
@@ -611,7 +611,7 @@
)
(drop
(ref.is_null
- (local.get $local_externref)
+ (local.get $local_funcref)
)
)
(drop
@@ -720,10 +720,10 @@
)
)
(func $returns_anyref2 (result anyref)
- (local $local_externref funcref)
- (local $local_funcref externref)
+ (local $local_externref externref)
+ (local $local_funcref funcref)
(return
- (local.get $local_funcref)
+ (local.get $local_externref)
)
)
(func $ref-user
diff --git a/test/reference-types.wast.fromBinary.noDebugInfo b/test/reference-types.wast.fromBinary.noDebugInfo
index 970037571..5d168c185 100644
--- a/test/reference-types.wast.fromBinary.noDebugInfo
+++ b/test/reference-types.wast.fromBinary.noDebugInfo
@@ -36,28 +36,28 @@
(nop)
)
(func $4
- (local $0 funcref)
- (local $1 externref)
+ (local $0 externref)
+ (local $1 funcref)
(local $2 anyref)
- (local.set $1
- (local.get $1)
+ (local.set $0
+ (local.get $0)
)
- (local.set $1
+ (local.set $0
(global.get $global$0)
)
- (local.set $1
+ (local.set $0
(ref.null extern)
)
- (local.set $0
- (local.get $0)
+ (local.set $1
+ (local.get $1)
)
- (local.set $0
+ (local.set $1
(global.get $global$1)
)
- (local.set $0
+ (local.set $1
(ref.null func)
)
- (local.set $0
+ (local.set $1
(ref.func $3)
)
(local.set $2
@@ -70,7 +70,7 @@
(ref.null any)
)
(local.set $2
- (local.get $1)
+ (local.get $0)
)
(local.set $2
(global.get $global$0)
@@ -79,7 +79,7 @@
(ref.null extern)
)
(local.set $2
- (local.get $0)
+ (local.get $1)
)
(local.set $2
(global.get $global$1)
@@ -94,7 +94,7 @@
(global.get $global$0)
)
(global.set $global$0
- (local.get $1)
+ (local.get $0)
)
(global.set $global$0
(ref.null extern)
@@ -103,7 +103,7 @@
(global.get $global$1)
)
(global.set $global$1
- (local.get $0)
+ (local.get $1)
)
(global.set $global$1
(ref.null func)
@@ -124,7 +124,7 @@
(global.get $global$0)
)
(global.set $global$3
- (local.get $1)
+ (local.get $0)
)
(global.set $global$3
(ref.null extern)
@@ -133,7 +133,7 @@
(global.get $global$1)
)
(global.set $global$3
- (local.get $0)
+ (local.get $1)
)
(global.set $global$3
(ref.null func)
@@ -142,7 +142,7 @@
(ref.func $3)
)
(call $0
- (local.get $1)
+ (local.get $0)
)
(call $0
(global.get $global$0)
@@ -151,7 +151,7 @@
(ref.null extern)
)
(call $1
- (local.get $0)
+ (local.get $1)
)
(call $1
(global.get $global$1)
@@ -172,7 +172,7 @@
(ref.null any)
)
(call $2
- (local.get $1)
+ (local.get $0)
)
(call $2
(global.get $global$0)
@@ -181,7 +181,7 @@
(ref.null extern)
)
(call $2
- (local.get $0)
+ (local.get $1)
)
(call $2
(global.get $global$1)
@@ -193,7 +193,7 @@
(ref.func $3)
)
(call_indirect $0 (type $externref_=>_none)
- (local.get $1)
+ (local.get $0)
(i32.const 0)
)
(call_indirect $0 (type $externref_=>_none)
@@ -205,7 +205,7 @@
(i32.const 0)
)
(call_indirect $0 (type $funcref_=>_none)
- (local.get $0)
+ (local.get $1)
(i32.const 1)
)
(call_indirect $0 (type $funcref_=>_none)
@@ -233,7 +233,7 @@
(i32.const 3)
)
(call_indirect $0 (type $anyref_=>_none)
- (local.get $1)
+ (local.get $0)
(i32.const 3)
)
(call_indirect $0 (type $anyref_=>_none)
@@ -245,7 +245,7 @@
(i32.const 3)
)
(call_indirect $0 (type $anyref_=>_none)
- (local.get $0)
+ (local.get $1)
(i32.const 3)
)
(call_indirect $0 (type $anyref_=>_none)
@@ -263,7 +263,7 @@
(drop
(block $label$1 (result externref)
(br_if $label$1
- (local.get $1)
+ (local.get $0)
(i32.const 1)
)
)
@@ -287,7 +287,7 @@
(drop
(block $label$4 (result funcref)
(br_if $label$4
- (local.get $0)
+ (local.get $1)
(i32.const 1)
)
)
@@ -343,7 +343,7 @@
(drop
(block $label$11 (result anyref)
(br_if $label$11
- (local.get $1)
+ (local.get $0)
(i32.const 1)
)
)
@@ -351,7 +351,7 @@
(drop
(block $label$12 (result anyref)
(br_if $label$12
- (local.get $0)
+ (local.get $1)
(i32.const 1)
)
)
@@ -382,7 +382,7 @@
)
(drop
(loop $label$16 (result externref)
- (local.get $1)
+ (local.get $0)
)
)
(drop
@@ -397,7 +397,7 @@
)
(drop
(loop $label$19 (result funcref)
- (local.get $0)
+ (local.get $1)
)
)
(drop
@@ -432,7 +432,7 @@
)
(drop
(loop $label$26 (result anyref)
- (local.get $1)
+ (local.get $0)
)
)
(drop
@@ -447,7 +447,7 @@
)
(drop
(loop $label$29 (result anyref)
- (local.get $0)
+ (local.get $1)
)
)
(drop
@@ -468,14 +468,14 @@
(drop
(if (result externref)
(i32.const 1)
- (local.get $1)
+ (local.get $0)
(ref.null extern)
)
)
(drop
(if (result funcref)
(i32.const 1)
- (local.get $0)
+ (local.get $1)
(ref.null func)
)
)
@@ -489,8 +489,8 @@
(drop
(if (result anyref)
(i32.const 1)
- (local.get $1)
(local.get $0)
+ (local.get $1)
)
)
(drop
@@ -510,7 +510,7 @@
(drop
(try $label$47 (result externref)
(do
- (local.get $1)
+ (local.get $0)
)
(catch $event$0
(drop
@@ -536,7 +536,7 @@
(drop
(try $label$53 (result anyref)
(do
- (local.get $1)
+ (local.get $0)
)
(catch $event$0
(drop
@@ -555,20 +555,20 @@
(drop
(pop i32)
)
- (local.get $1)
+ (local.get $0)
)
)
)
(drop
(select (result externref)
- (local.get $1)
+ (local.get $0)
(ref.null extern)
(i32.const 1)
)
)
(drop
(select (result funcref)
- (local.get $0)
+ (local.get $1)
(ref.null func)
(i32.const 1)
)
@@ -582,21 +582,21 @@
)
(drop
(select (result anyref)
- (local.get $1)
(local.get $0)
+ (local.get $1)
(i32.const 1)
)
)
(drop
(select (result anyref)
- (local.get $0)
(local.get $1)
+ (local.get $0)
(i32.const 1)
)
)
(drop
(ref.is_null
- (local.get $1)
+ (local.get $0)
)
)
(drop
@@ -611,7 +611,7 @@
)
(drop
(ref.is_null
- (local.get $0)
+ (local.get $1)
)
)
(drop
@@ -720,10 +720,10 @@
)
)
(func $25 (result anyref)
- (local $0 funcref)
- (local $1 externref)
+ (local $0 externref)
+ (local $1 funcref)
(return
- (local.get $1)
+ (local.get $0)
)
)
(func $26
diff --git a/test/typed-function-references.wast.fromBinary b/test/typed-function-references.wast.fromBinary
index 047767ca6..798c02512 100644
--- a/test/typed-function-references.wast.fromBinary
+++ b/test/typed-function-references.wast.fromBinary
@@ -52,8 +52,8 @@
)
(func $type-only-in-tuple-local
(local $x i32)
- (local $1 f64)
- (local $2 (ref null $=>anyref))
+ (local $1 (ref null $=>anyref))
+ (local $2 f64)
(nop)
)
(func $type-only-in-tuple-block
diff --git a/test/typed-function-references.wast.fromBinary.noDebugInfo b/test/typed-function-references.wast.fromBinary.noDebugInfo
index 7cecbd5b1..01d474e45 100644
--- a/test/typed-function-references.wast.fromBinary.noDebugInfo
+++ b/test/typed-function-references.wast.fromBinary.noDebugInfo
@@ -52,8 +52,8 @@
)
(func $7
(local $0 i32)
- (local $1 f64)
- (local $2 (ref null $none_=>_anyref))
+ (local $1 (ref null $none_=>_anyref))
+ (local $2 f64)
(nop)
)
(func $8