summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm-binary.h22
-rw-r--r--src/wasm/wasm-binary.cpp186
-rw-r--r--test/binaryen.js/debug-names.js14
-rw-r--r--test/binaryen.js/debug-names.js.txt32
-rw-r--r--test/binaryen.js/kitchen-sink.js.txt2
-rw-r--r--test/dylib.wasm.fromBinary2
-rw-r--r--test/empty_imported_table.wast.fromBinary2
-rw-r--r--test/example/c-api-unused-mem.txt2
-rw-r--r--test/export-import.wast.fromBinary4
-rw-r--r--test/extra-unreachable.wast.fromBinary2
-rw-r--r--test/fib-dbg.wasm.fromBinary2
-rw-r--r--test/gc.wast.fromBinary86
-rw-r--r--test/imported_memory.wast.fromBinary2
-rw-r--r--test/imported_memory.wast.fromBinary.noDebugInfo2
-rw-r--r--test/imported_memory_growth.wast.fromBinary2
-rw-r--r--test/imported_memory_growth.wast.fromBinary.noDebugInfo2
-rw-r--r--test/lld/shared_add_to_table.wasm.out2
-rw-r--r--test/memory-import.wast.fromBinary.noDebugInfo2
-rw-r--r--test/memory-import64.wast.fromBinary.noDebugInfo2
-rw-r--r--test/multivalue.wast.fromBinary8
-rw-r--r--test/mutable-global.wast.fromBinary6
-rw-r--r--test/newsyntax.wast.fromBinary2
-rw-r--r--test/passes/converge_O3_metrics.bin.txt4
-rw-r--r--test/passes/fannkuch0_dwarf.bin.txt4
-rw-r--r--test/passes/fannkuch3_dwarf.bin.txt4
-rw-r--r--test/passes/fannkuch3_manyopts_dwarf.bin.txt2
-rw-r--r--test/passes/fib2_dwarf.bin.txt2
-rw-r--r--test/passes/fib2_emptylocspan_dwarf.bin.txt2
-rw-r--r--test/passes/fib_nonzero-low-pc_dwarf.bin.txt10
-rw-r--r--test/passes/func-metrics.txt4
-rw-r--r--test/passes/ignore_missing_func_dwarf.bin.txt4
-rw-r--r--test/passes/inlined_to_start_dwarf.bin.txt2
-rw-r--r--test/passes/multi_line_table_dwarf.bin.txt10
-rw-r--r--test/passes/print.bin.txt4
-rw-r--r--test/passes/print_g.bin.txt4
-rw-r--r--test/passes/print_g_strip-dwarf.bin.txt4
-rw-r--r--test/passes/reverse_dwarf_abbrevs.bin.txt2
-rw-r--r--test/passes/strip-debug.bin.txt2
-rw-r--r--test/passes/strip-producers.bin.txt2
-rw-r--r--test/polymorphic_stack.wast.fromBinary2
-rw-r--r--test/reference-types.wast.fromBinary168
-rw-r--r--test/table-import.wast.fromBinary2
-rwxr-xr-xtest/unit/input/atomics_target_feature.wasmbin158 -> 211 bytes
-rwxr-xr-xtest/unit/input/bulkmem_data.wasmbin177 -> 223 bytes
-rwxr-xr-xtest/unit/input/bulkmem_target_feature.wasmbin163 -> 219 bytes
-rw-r--r--test/unit/input/gc_target_feature.wasmbin61 -> 94 bytes
-rw-r--r--test/unit/input/mutable_globals_target_feature.wasmbin101 -> 115 bytes
-rw-r--r--test/unit/input/reference_types_target_feature.wasmbin150 -> 178 bytes
-rwxr-xr-xtest/unit/input/signext_target_feature.wasmbin153 -> 198 bytes
-rwxr-xr-xtest/unit/input/simd_target_feature.wasmbin152 -> 197 bytes
-rwxr-xr-xtest/unit/input/tail_call_target_feature.wasmbin112 -> 118 bytes
-rwxr-xr-xtest/unit/input/truncsat_target_feature.wasmbin165 -> 218 bytes
-rw-r--r--test/unit/input/update.sh19
53 files changed, 421 insertions, 222 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index 9ac5664d3..c869adf06 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -393,6 +393,14 @@ enum Subsection {
NameModule = 0,
NameFunction = 1,
NameLocal = 2,
+ // see: https://github.com/WebAssembly/extended-name-section
+ NameLabel = 3,
+ NameType = 4,
+ NameTable = 5,
+ NameMemory = 6,
+ NameGlobal = 7,
+ NameElem = 8,
+ NameData = 9
};
} // namespace UserSections
@@ -1299,8 +1307,8 @@ public:
Name getNextLabel();
- // We read functions before we know their names, so we need to backpatch the
- // names later
+ // We read functions and globals before we know their names, so we need to
+ // backpatch the names later
// we store functions here before wasm.addFunction after we know their names
std::vector<Function*> functions;
@@ -1314,6 +1322,14 @@ public:
// function to check
Index endOfFunction = -1;
+ // we store globals here before wasm.addGlobal after we know their names
+ std::vector<Global*> globals;
+ // we store global imports here before wasm.addGlobalImport after we know
+ // their names
+ std::vector<Global*> globalImports;
+ // at index i we have all refs to the global i
+ std::map<Index, std::vector<Expression*>> globalRefs;
+
// Throws a parsing error if we are not in a function context
void requireFunctionContext(const char* error);
@@ -1382,7 +1398,7 @@ public:
Expression* popTypedExpression(Type type);
void validateBinary(); // validations that cannot be performed on the Module
- void processFunctions();
+ void processNames();
size_t dataCount = 0;
bool hasDataCount = false;
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 85880a988..48564a897 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -551,10 +551,6 @@ void WasmBinaryWriter::writeEvents() {
}
void WasmBinaryWriter::writeNames() {
- if (wasm->functions.empty()) {
- return;
- }
-
BYN_TRACE("== writeNames\n");
auto start = startSection(BinaryConsts::Section::User);
writeInlineString(BinaryConsts::UserSections::Name);
@@ -631,6 +627,52 @@ void WasmBinaryWriter::writeNames() {
}
}
+ // table names
+ if (wasm->table.exists && wasm->table.name.is()) {
+ auto substart =
+ startSubsection(BinaryConsts::UserSections::Subsection::NameTable);
+ o << U32LEB(1) << U32LEB(0); // currently exactly 1 table at index 0
+ writeEscapedName(wasm->table.name.str);
+ finishSubsection(substart);
+ }
+
+ // memory names
+ if (wasm->memory.exists && wasm->memory.name.is()) {
+ auto substart =
+ startSubsection(BinaryConsts::UserSections::Subsection::NameMemory);
+ o << U32LEB(1) << U32LEB(0); // currently exactly 1 memory at index 0
+ writeEscapedName(wasm->memory.name.str);
+ finishSubsection(substart);
+ }
+
+ // global names
+ {
+ std::vector<std::pair<Index, Global*>> globalsWithNames;
+ Index checked = 0;
+ auto check = [&](Global* curr) {
+ if (curr->name.is()) {
+ globalsWithNames.push_back({checked, curr});
+ }
+ checked++;
+ };
+ ModuleUtils::iterImportedGlobals(*wasm, check);
+ ModuleUtils::iterDefinedGlobals(*wasm, check);
+ assert(checked == indexes.globalIndexes.size());
+ if (globalsWithNames.size() > 0) {
+ auto substart =
+ startSubsection(BinaryConsts::UserSections::Subsection::NameGlobal);
+ o << U32LEB(globalsWithNames.size());
+ for (auto& indexedGlobal : globalsWithNames) {
+ o << U32LEB(indexedGlobal.first);
+ writeEscapedName(indexedGlobal.second->name.str);
+ }
+ finishSubsection(substart);
+ }
+ }
+
+ // TODO: label, type, element and data names
+ // see: https://github.com/WebAssembly/extended-name-section
+
finishSection(start);
}
@@ -1035,7 +1077,7 @@ void WasmBinaryBuilder::read() {
}
validateBinary();
- processFunctions();
+ processNames();
}
void WasmBinaryBuilder::readUserSection(size_t payloadLen) {
@@ -1459,7 +1501,7 @@ void WasmBinaryBuilder::readImports() {
case ExternalKind::Memory: {
wasm.memory.module = module;
wasm.memory.base = base;
- wasm.memory.name = Name(std::to_string(i));
+ wasm.memory.name = Name(std::string("mimport$") + std::to_string(i));
wasm.memory.exists = true;
getResizableLimits(wasm.memory.initial,
wasm.memory.max,
@@ -1480,6 +1522,7 @@ void WasmBinaryBuilder::readImports() {
curr->module = module;
curr->base = base;
wasm.addGlobal(curr);
+ globalImports.push_back(curr);
break;
}
case ExternalKind::Event: {
@@ -1819,7 +1862,7 @@ void WasmBinaryBuilder::readGlobals() {
throwError("Global mutability must be 0 or 1");
}
auto* init = readExpression();
- wasm.addGlobal(
+ globals.push_back(
Builder::makeGlobal("global$" + std::to_string(i),
type,
init,
@@ -2008,12 +2051,15 @@ void WasmBinaryBuilder::validateBinary() {
}
}
-void WasmBinaryBuilder::processFunctions() {
+void WasmBinaryBuilder::processNames() {
for (auto* func : functions) {
wasm.addFunction(func);
}
+ for (auto* global : globals) {
+ wasm.addGlobal(global);
+ }
- // now that we have names for each function, apply things
+ // now that we have names, apply things
if (startIndex != static_cast<Index>(-1)) {
wasm.start = getFunctionName(startIndex);
@@ -2027,10 +2073,10 @@ void WasmBinaryBuilder::processFunctions() {
break;
}
case ExternalKind::Table:
- curr->value = Name::fromInt(0);
+ curr->value = wasm.table.name;
break;
case ExternalKind::Memory:
- curr->value = Name::fromInt(0);
+ curr->value = wasm.memory.name;
break;
case ExternalKind::Global:
curr->value = getGlobalName(index);
@@ -2066,6 +2112,20 @@ void WasmBinaryBuilder::processFunctions() {
}
}
+ for (auto& iter : globalRefs) {
+ size_t index = iter.first;
+ auto& refs = iter.second;
+ for (auto* ref : refs) {
+ if (auto* get = ref->dynCast<GlobalGet>()) {
+ get->name = getGlobalName(index);
+ } else if (auto* set = ref->dynCast<GlobalSet>()) {
+ set->name = getGlobalName(index);
+ } else {
+ WASM_UNREACHABLE("Invalid type in global references");
+ }
+ }
+ }
+
// Everything now has its proper name.
wasm.updateMaps();
@@ -2226,14 +2286,12 @@ void WasmBinaryBuilder::readNames(size_t payloadLen) {
for (size_t i = 0; i < num; i++) {
auto index = getU32LEB();
auto rawName = getInlineString();
- rawName = escape(rawName);
- auto name = rawName;
+ auto name = escape(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);
+ name = std::string(escape(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;
@@ -2242,7 +2300,7 @@ void WasmBinaryBuilder::readNames(size_t payloadLen) {
} else {
std::cerr << "warning: function index out of bounds in name section, "
"function subsection: "
- << std::string(name.str) << " at index "
+ << std::string(rawName.str) << " at index "
<< std::to_string(index) << std::endl;
}
}
@@ -2263,25 +2321,85 @@ void WasmBinaryBuilder::readNames(size_t payloadLen) {
<< std::to_string(funcIndex) << std::endl;
}
auto numLocals = getU32LEB();
+ std::set<Name> usedNames;
for (size_t j = 0; j < numLocals; j++) {
auto localIndex = getU32LEB();
- auto localName = getInlineString();
+ auto rawLocalName = getInlineString();
if (!func) {
continue; // read and discard in case of prior error
}
+ auto localName = escape(rawLocalName);
+ // De-duplicate names by appending .1, .2, etc.
+ for (int i = 1; !usedNames.insert(localName).second; ++i) {
+ localName = std::string(escape(rawLocalName).str) +
+ std::string(".") + std::to_string(i);
+ }
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::string(rawLocalName.str) << " at index "
<< std::to_string(localIndex) << " in function "
<< std::string(func->name.str) << std::endl;
}
}
}
+ } else if (nameType == BinaryConsts::UserSections::Subsection::NameTable) {
+ auto num = getU32LEB();
+ for (size_t i = 0; i < num; i++) {
+ auto index = getU32LEB();
+ auto rawName = getInlineString();
+ if (index == 0) {
+ wasm.table.name = escape(rawName);
+ } else {
+ std::cerr << "warning: table index out of bounds in name section, "
+ "table subsection: "
+ << std::string(rawName.str) << " at index "
+ << std::to_string(index) << std::endl;
+ }
+ }
+ } else if (nameType == BinaryConsts::UserSections::Subsection::NameMemory) {
+ auto num = getU32LEB();
+ for (size_t i = 0; i < num; i++) {
+ auto index = getU32LEB();
+ auto rawName = getInlineString();
+ if (index == 0) {
+ wasm.memory.name = escape(rawName);
+ } else {
+ std::cerr << "warning: memory index out of bounds in name section, "
+ "memory subsection: "
+ << std::string(rawName.str) << " at index "
+ << std::to_string(index) << std::endl;
+ }
+ }
+ } else if (nameType == BinaryConsts::UserSections::Subsection::NameGlobal) {
+ auto num = getU32LEB();
+ std::set<Name> usedNames;
+ for (size_t i = 0; i < num; i++) {
+ auto index = getU32LEB();
+ auto rawName = getInlineString();
+ auto name = escape(rawName);
+ // De-duplicate names by appending .1, .2, etc.
+ for (int i = 1; !usedNames.insert(name).second; ++i) {
+ name = std::string(escape(rawName).str) + std::string(".") +
+ std::to_string(i);
+ }
+ auto numGlobalImports = globalImports.size();
+ if (index < numGlobalImports) {
+ globalImports[index]->name = name;
+ } else if (index - numGlobalImports < globals.size()) {
+ globals[index - numGlobalImports]->name = name;
+ } else {
+ std::cerr << "warning: global index out of bounds in name section, "
+ "global subsection: "
+ << std::string(rawName.str) << " at index "
+ << std::to_string(index) << std::endl;
+ }
+ }
} else {
- std::cerr << "warning: unknown name subsection at " << pos << std::endl;
+ std::cerr << "warning: unknown name subsection with id "
+ << std::to_string(nameType) << " at " << pos << std::endl;
pos = subsectionPos + subsectionSize;
}
if (pos != subsectionPos + subsectionSize) {
@@ -2952,15 +3070,37 @@ void WasmBinaryBuilder::visitLocalSet(LocalSet* curr, uint8_t code) {
void WasmBinaryBuilder::visitGlobalGet(GlobalGet* curr) {
BYN_TRACE("zz node: GlobalGet " << pos << std::endl);
auto index = getU32LEB();
- curr->name = getGlobalName(index);
- curr->type = wasm.getGlobal(curr->name)->type;
+ if (index < globalImports.size()) {
+ auto* import = globalImports[index];
+ curr->name = import->name;
+ curr->type = import->type;
+ } else {
+ Index adjustedIndex = index - globalImports.size();
+ if (adjustedIndex >= globals.size()) {
+ throwError("invalid global index");
+ }
+ auto* glob = globals[adjustedIndex];
+ curr->name = glob->name;
+ curr->type = glob->type;
+ }
+ globalRefs[index].push_back(curr); // we don't know the final name yet
}
void WasmBinaryBuilder::visitGlobalSet(GlobalSet* curr) {
BYN_TRACE("zz node: GlobalSet\n");
auto index = getU32LEB();
- curr->name = getGlobalName(index);
+ if (index < globalImports.size()) {
+ auto* import = globalImports[index];
+ curr->name = import->name;
+ } else {
+ Index adjustedIndex = index - globalImports.size();
+ if (adjustedIndex >= globals.size()) {
+ throwError("invalid global index");
+ }
+ curr->name = globals[adjustedIndex]->name;
+ }
curr->value = popNonVoidExpression();
+ globalRefs[index].push_back(curr); // we don't know the final name yet
curr->finalize();
}
diff --git a/test/binaryen.js/debug-names.js b/test/binaryen.js/debug-names.js
index 539b119aa..0be6bf365 100644
--- a/test/binaryen.js/debug-names.js
+++ b/test/binaryen.js/debug-names.js
@@ -1,13 +1,13 @@
var wast = `
-(module $hello
- (global $world i32 (i32.const 0))
+(module $hel
+ (memory $lo 0 0)
+ (table $wor 0 0 funcref)
+ (global $ld 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);
@@ -33,4 +33,10 @@ module.dispose();
console.log("=== roundtripped ===\n" + module2.emitText());
+var module3 = binaryen.readBinary(module2.emitBinary());
+
module2.dispose();
+
+console.log("=== roundtripped again ===\n" + module3.emitText());
+
+module3.dispose();
diff --git a/test/binaryen.js/debug-names.js.txt b/test/binaryen.js/debug-names.js.txt
index c982f2dc1..40e94c248 100644
--- a/test/binaryen.js/debug-names.js.txt
+++ b/test/binaryen.js/debug-names.js.txt
@@ -1,15 +1,19 @@
=== input wast ===
-(module $hello
- (global $world i32 (i32.const 0))
+(module $hel
+ (memory $lo 0 0)
+ (table $wor 0 0 funcref)
+ (global $ld i32 (i32.const 0))
(func $of (param $wasm i32)
(local $!#$%&'*+-./:<=>?@\^_`|~ f64)
)
)
=== parsed wast ===
-(module $hello
+(module $hel
(type $i32_=>_none (func (param i32)))
- (global $world i32 (i32.const 0))
+ (memory $lo 0 0)
+ (table $wor 0 0 funcref)
+ (global $ld i32 (i32.const 0))
(func $of (param $wasm i32)
(local $!#$%&'*+-./:<=>?@\^_`|~ f64)
(nop)
@@ -17,11 +21,25 @@
)
=== roundtripped ===
-(module $hello
+(module $hel
(type $i32_=>_none (func (param i32)))
- (global $global$0 i32 (i32.const 0))
+ (memory $lo 0 0)
+ (table $wor 0 0 funcref)
+ (global $ld i32 (i32.const 0))
(func $of (param $js i32)
- (local $!#$%&'*+-./:<=>?@\^_`|~ f64)
+ (local $!#$%&'*+-./:<=>?@\5c^_`|~ f64)
+ (nop)
+ )
+)
+
+=== roundtripped again ===
+(module $hel
+ (type $i32_=>_none (func (param i32)))
+ (memory $lo 0 0)
+ (table $wor 0 0 funcref)
+ (global $ld i32 (i32.const 0))
+ (func $of (param $js i32)
+ (local $!#$%&'*+-./:<=>?@\5c^_`|~ f64)
(nop)
)
)
diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt
index 9fca3ae53..491f11cec 100644
--- a/test/binaryen.js/kitchen-sink.js.txt
+++ b/test/binaryen.js/kitchen-sink.js.txt
@@ -4344,7 +4344,7 @@ module loaded from binary form:
(module
(type $i32_i32_=>_none (func (param i32 i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
- (global $global$0 i32 (i32.const 3))
+ (global $a-global i32 (i32.const 3))
(event $event$0 (attr 0) (param i32 i32))
(func $adder (param $0 i32) (param $1 i32) (result i32)
(i32.add
diff --git a/test/dylib.wasm.fromBinary b/test/dylib.wasm.fromBinary
index bbd01db19..dcf6f4ec4 100644
--- a/test/dylib.wasm.fromBinary
+++ b/test/dylib.wasm.fromBinary
@@ -3,7 +3,7 @@
(type $none_=>_none (func))
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
- (import "env" "memory" (memory $5 0))
+ (import "env" "memory" (memory $mimport$5 0))
(data (global.get $gimport$4) "*\00\00\00")
(import "env" "__memory_base" (global $gimport$4 i32))
(import "env" "g$waka_mine" (func $fimport$0 (result i32)))
diff --git a/test/empty_imported_table.wast.fromBinary b/test/empty_imported_table.wast.fromBinary
index c29363236..66ee9078c 100644
--- a/test/empty_imported_table.wast.fromBinary
+++ b/test/empty_imported_table.wast.fromBinary
@@ -1,5 +1,5 @@
(module
- (import "env" "table" (table $timport$0 0 0 funcref))
+ (import "env" "table" (table $0 0 0 funcref))
(memory $0 0)
)
diff --git a/test/example/c-api-unused-mem.txt b/test/example/c-api-unused-mem.txt
index 0a5ce8061..108c04eba 100644
--- a/test/example/c-api-unused-mem.txt
+++ b/test/example/c-api-unused-mem.txt
@@ -36,7 +36,7 @@
(call $main)
)
)
-145
+151
(module
(type $none_=>_none (func))
(memory $0 1024 1024)
diff --git a/test/export-import.wast.fromBinary b/test/export-import.wast.fromBinary
index 5b7bcd030..b260f8064 100644
--- a/test/export-import.wast.fromBinary
+++ b/test/export-import.wast.fromBinary
@@ -1,8 +1,8 @@
(module
(type $none_=>_none (func))
- (import "env" "test2" (global $gimport$1 i32))
+ (import "env" "test2" (global $test2 i32))
(import "env" "test1" (func $test1))
(export "test1" (func $test1))
- (export "test2" (global $gimport$1))
+ (export "test2" (global $test2))
)
diff --git a/test/extra-unreachable.wast.fromBinary b/test/extra-unreachable.wast.fromBinary
index 681714a4e..7db2a86d9 100644
--- a/test/extra-unreachable.wast.fromBinary
+++ b/test/extra-unreachable.wast.fromBinary
@@ -4,7 +4,7 @@
(type $i32_=>_i32 (func (param i32) (result i32)))
(memory $0 (shared 1 1))
(table $0 0 funcref)
- (global $global$0 (mut f32) (f32.const 0))
+ (global $g (mut f32) (f32.const 0))
(event $event$0 (attr 0) (param i32))
(func $foo (param $0 i32) (result i32)
(i32.const 0)
diff --git a/test/fib-dbg.wasm.fromBinary b/test/fib-dbg.wasm.fromBinary
index a0e4ef26a..39780b6e3 100644
--- a/test/fib-dbg.wasm.fromBinary
+++ b/test/fib-dbg.wasm.fromBinary
@@ -4,7 +4,7 @@
(type $none_=>_none (func))
(type $i32_=>_none (func (param i32)))
(type $none_=>_i32 (func (result i32)))
- (import "env" "memory" (memory $9 256 256))
+ (import "env" "memory" (memory $mimport$9 256 256))
(import "env" "table" (table $timport$10 0 0 funcref))
(import "env" "DYNAMICTOP_PTR" (global $gimport$0 i32))
(import "env" "tempDoublePtr" (global $gimport$1 i32))
diff --git a/test/gc.wast.fromBinary b/test/gc.wast.fromBinary
index f1308b9b1..d86c08985 100644
--- a/test/gc.wast.fromBinary
+++ b/test/gc.wast.fromBinary
@@ -1,12 +1,12 @@
(module
(type $none_=>_none (func))
- (import "env" "trivial_i31ref" (global $gimport$0 i31ref))
- (global $global$0 (mut anyref) (ref.null any))
- (global $global$1 (mut eqref) (ref.null eq))
- (global $global$2 (mut i31ref) (global.get $gimport$0))
- (global $global$3 (mut anyref) (ref.null eq))
- (global $global$4 (mut anyref) (global.get $gimport$0))
- (global $global$5 (mut eqref) (global.get $gimport$0))
+ (import "env" "trivial_i31ref" (global $trivial_i31ref i31ref))
+ (global $global_anyref (mut anyref) (ref.null any))
+ (global $global_eqref (mut eqref) (ref.null eq))
+ (global $global_i31ref (mut i31ref) (global.get $trivial_i31ref))
+ (global $global_anyref2 (mut anyref) (ref.null eq))
+ (global $global_anyref3 (mut anyref) (global.get $trivial_i31ref))
+ (global $global_eqref2 (mut eqref) (global.get $trivial_i31ref))
(func $test
(local $local_i32 i32)
(local $local_anyref anyref)
@@ -16,7 +16,7 @@
(local.get $local_anyref)
)
(local.set $local_anyref
- (global.get $global$0)
+ (global.get $global_anyref)
)
(local.set $local_anyref
(ref.null any)
@@ -25,7 +25,7 @@
(local.get $local_eqref)
)
(local.set $local_eqref
- (global.get $global$1)
+ (global.get $global_eqref)
)
(local.set $local_eqref
(ref.null eq)
@@ -34,16 +34,16 @@
(local.get $local_i31ref)
)
(local.set $local_i31ref
- (global.get $global$2)
+ (global.get $global_i31ref)
)
(local.set $local_i31ref
- (global.get $gimport$0)
+ (global.get $trivial_i31ref)
)
(local.set $local_anyref
(local.get $local_eqref)
)
(local.set $local_anyref
- (global.get $global$1)
+ (global.get $global_eqref)
)
(local.set $local_anyref
(ref.null eq)
@@ -52,73 +52,73 @@
(local.get $local_i31ref)
)
(local.set $local_anyref
- (global.get $global$2)
+ (global.get $global_i31ref)
)
(local.set $local_anyref
- (global.get $gimport$0)
+ (global.get $trivial_i31ref)
)
(local.set $local_eqref
(local.get $local_i31ref)
)
(local.set $local_eqref
- (global.get $global$2)
+ (global.get $global_i31ref)
)
(local.set $local_eqref
- (global.get $gimport$0)
+ (global.get $trivial_i31ref)
)
- (global.set $global$0
+ (global.set $global_anyref
(local.get $local_anyref)
)
- (global.set $global$0
- (global.get $global$0)
+ (global.set $global_anyref
+ (global.get $global_anyref)
)
- (global.set $global$0
+ (global.set $global_anyref
(ref.null any)
)
- (global.set $global$1
+ (global.set $global_eqref
(local.get $local_eqref)
)
- (global.set $global$1
- (global.get $global$1)
+ (global.set $global_eqref
+ (global.get $global_eqref)
)
- (global.set $global$1
+ (global.set $global_eqref
(ref.null eq)
)
- (global.set $global$2
+ (global.set $global_i31ref
(local.get $local_i31ref)
)
- (global.set $global$2
- (global.get $global$2)
+ (global.set $global_i31ref
+ (global.get $global_i31ref)
)
- (global.set $global$2
- (global.get $gimport$0)
+ (global.set $global_i31ref
+ (global.get $trivial_i31ref)
)
- (global.set $global$0
+ (global.set $global_anyref
(local.get $local_eqref)
)
- (global.set $global$0
- (global.get $global$1)
+ (global.set $global_anyref
+ (global.get $global_eqref)
)
- (global.set $global$0
+ (global.set $global_anyref
(ref.null eq)
)
- (global.set $global$0
+ (global.set $global_anyref
(local.get $local_i31ref)
)
- (global.set $global$0
- (global.get $global$2)
+ (global.set $global_anyref
+ (global.get $global_i31ref)
)
- (global.set $global$0
- (global.get $gimport$0)
+ (global.set $global_anyref
+ (global.get $trivial_i31ref)
)
- (global.set $global$1
+ (global.set $global_eqref
(local.get $local_i31ref)
)
- (global.set $global$1
- (global.get $global$2)
+ (global.set $global_eqref
+ (global.get $global_i31ref)
)
- (global.set $global$1
- (global.get $gimport$0)
+ (global.set $global_eqref
+ (global.get $trivial_i31ref)
)
(local.set $local_i31ref
(i31.new
diff --git a/test/imported_memory.wast.fromBinary b/test/imported_memory.wast.fromBinary
index 5f95ef251..884a2d9f4 100644
--- a/test/imported_memory.wast.fromBinary
+++ b/test/imported_memory.wast.fromBinary
@@ -1,5 +1,5 @@
(module
(import "env" "memory" (memory $0 256 256))
- (import "env" "table" (table $timport$1 256 256 funcref))
+ (import "env" "table" (table $0 256 256 funcref))
)
diff --git a/test/imported_memory.wast.fromBinary.noDebugInfo b/test/imported_memory.wast.fromBinary.noDebugInfo
index 5f95ef251..5d350d6eb 100644
--- a/test/imported_memory.wast.fromBinary.noDebugInfo
+++ b/test/imported_memory.wast.fromBinary.noDebugInfo
@@ -1,5 +1,5 @@
(module
- (import "env" "memory" (memory $0 256 256))
+ (import "env" "memory" (memory $mimport$0 256 256))
(import "env" "table" (table $timport$1 256 256 funcref))
)
diff --git a/test/imported_memory_growth.wast.fromBinary b/test/imported_memory_growth.wast.fromBinary
index 0ede89c6d..cab44f5ff 100644
--- a/test/imported_memory_growth.wast.fromBinary
+++ b/test/imported_memory_growth.wast.fromBinary
@@ -1,5 +1,5 @@
(module
(import "env" "memory" (memory $0 256))
- (import "env" "table" (table $timport$1 256 funcref))
+ (import "env" "table" (table $0 256 funcref))
)
diff --git a/test/imported_memory_growth.wast.fromBinary.noDebugInfo b/test/imported_memory_growth.wast.fromBinary.noDebugInfo
index 0ede89c6d..bc550e1d2 100644
--- a/test/imported_memory_growth.wast.fromBinary.noDebugInfo
+++ b/test/imported_memory_growth.wast.fromBinary.noDebugInfo
@@ -1,5 +1,5 @@
(module
- (import "env" "memory" (memory $0 256))
+ (import "env" "memory" (memory $mimport$0 256))
(import "env" "table" (table $timport$1 256 funcref))
)
diff --git a/test/lld/shared_add_to_table.wasm.out b/test/lld/shared_add_to_table.wasm.out
index a3f6cd2cb..2b8ab41f2 100644
--- a/test/lld/shared_add_to_table.wasm.out
+++ b/test/lld/shared_add_to_table.wasm.out
@@ -3,7 +3,7 @@
(type $none_=>_none (func))
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
- (import "env" "memory" (memory $0 0))
+ (import "env" "memory" (memory $mimport$0 0))
(data (global.get $gimport$3) "*\00\00\00")
(import "env" "table" (table $timport$1 0 funcref))
(import "env" "__memory_base" (global $gimport$3 i32))
diff --git a/test/memory-import.wast.fromBinary.noDebugInfo b/test/memory-import.wast.fromBinary.noDebugInfo
index 06e049012..196a1b0d7 100644
--- a/test/memory-import.wast.fromBinary.noDebugInfo
+++ b/test/memory-import.wast.fromBinary.noDebugInfo
@@ -1,6 +1,6 @@
(module
(type $none_=>_i32 (func (result i32)))
- (import "env" "memory" (memory $0 1 1))
+ (import "env" "memory" (memory $mimport$0 1 1))
(func $0 (result i32)
(i32.load offset=13
(i32.const 37)
diff --git a/test/memory-import64.wast.fromBinary.noDebugInfo b/test/memory-import64.wast.fromBinary.noDebugInfo
index cf422a6aa..ff5cd6fb2 100644
--- a/test/memory-import64.wast.fromBinary.noDebugInfo
+++ b/test/memory-import64.wast.fromBinary.noDebugInfo
@@ -1,6 +1,6 @@
(module
(type $none_=>_i32 (func (result i32)))
- (import "env" "memory" (memory $0 i64 1 1))
+ (import "env" "memory" (memory $mimport$0 i64 1 1))
(func $0 (result i32)
(i32.load offset=13
(i64.const 37)
diff --git a/test/multivalue.wast.fromBinary b/test/multivalue.wast.fromBinary
index db471ebe5..bf7afcf90 100644
--- a/test/multivalue.wast.fromBinary
+++ b/test/multivalue.wast.fromBinary
@@ -8,8 +8,8 @@
(type $none_=>_i32_i64_f32 (func (result i32 i64 f32)))
(type $none_=>_f32 (func (result f32)))
(import "env" "pair" (func $pair (result i32 i64)))
- (global $global$0 (mut i32) (i32.const 0))
- (global $global$1 (mut i64) (i64.const 0))
+ (global $g1 (mut i32) (i32.const 0))
+ (global $g2 (mut i64) (i64.const 0))
(global $global$2 i32 (i32.const 0))
(global $global$3 i64 (i64.const 0))
(func $triple (result i32 i64 f32)
@@ -240,12 +240,12 @@
)
(func $global (result i32 i64)
(local $0 i32)
- (global.set $global$0
+ (global.set $g1
(block (result i32)
(local.set $0
(i32.const 42)
)
- (global.set $global$1
+ (global.set $g2
(i64.const 7)
)
(local.get $0)
diff --git a/test/mutable-global.wast.fromBinary b/test/mutable-global.wast.fromBinary
index 33d332357..04be75288 100644
--- a/test/mutable-global.wast.fromBinary
+++ b/test/mutable-global.wast.fromBinary
@@ -1,10 +1,10 @@
(module
(type $none_=>_none (func))
- (import "env" "global-mut" (global $gimport$0 (mut i32)))
+ (import "env" "global-mut" (global $global-mut (mut i32)))
(func $foo
- (global.set $gimport$0
+ (global.set $global-mut
(i32.add
- (global.get $gimport$0)
+ (global.get $global-mut)
(i32.const 1)
)
)
diff --git a/test/newsyntax.wast.fromBinary b/test/newsyntax.wast.fromBinary
index ea3b1ac9a..aaf9b1285 100644
--- a/test/newsyntax.wast.fromBinary
+++ b/test/newsyntax.wast.fromBinary
@@ -1,7 +1,7 @@
(module
(type $none_=>_none (func))
(type $i32_f64_=>_i32 (func (param i32 f64) (result i32)))
- (import "env" "table" (table $timport$0 9 9 funcref))
+ (import "env" "table" (table $0 9 9 funcref))
(export "call_indirect" (func $0))
(func $0
(drop
diff --git a/test/passes/converge_O3_metrics.bin.txt b/test/passes/converge_O3_metrics.bin.txt
index 23b53d99b..b445b6464 100644
--- a/test/passes/converge_O3_metrics.bin.txt
+++ b/test/passes/converge_O3_metrics.bin.txt
@@ -30,7 +30,7 @@ total
(type $none_=>_i32 (func (result i32)))
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $i32_i32_i32_i32_i32_i32_i32_=>_i32 (func (param i32 i32 i32 i32 i32 i32 i32) (result i32)))
- (import "env" "memory" (memory $1 256 256))
+ (import "env" "memory" (memory $mimport$1 256 256))
(data (i32.const 2948) "\03")
(data (i32.const 6828) "\04")
(data (i32.const 7028) "\0d\00\00\00\06")
@@ -275,7 +275,7 @@ total
(type $none_=>_i32 (func (result i32)))
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $i32_i32_i32_i32_i32_i32_i32_=>_i32 (func (param i32 i32 i32 i32 i32 i32 i32) (result i32)))
- (import "env" "memory" (memory $1 256 256))
+ (import "env" "memory" (memory $mimport$1 256 256))
(data (i32.const 2948) "\03")
(data (i32.const 6828) "\04")
(data (i32.const 7028) "\0d\00\00\00\06")
diff --git a/test/passes/fannkuch0_dwarf.bin.txt b/test/passes/fannkuch0_dwarf.bin.txt
index 2873bf2cd..c2e5369af 100644
--- a/test/passes/fannkuch0_dwarf.bin.txt
+++ b/test/passes/fannkuch0_dwarf.bin.txt
@@ -5195,9 +5195,9 @@ file_names[ 3]:
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
(type $none_=>_none (func))
(type $i32_=>_none (func (param i32)))
- (import "env" "memory" (memory $4 256 256))
+ (import "env" "memory" (memory $mimport$0 256 256))
(data (i32.const 1024) "Wrong argument.\n\00Pfannkuchen(%d) = %d.\n\00%d\00\n\00")
- (import "env" "__indirect_function_table" (table $timport$5 1 funcref))
+ (import "env" "__indirect_function_table" (table $timport$1 1 funcref))
(import "env" "malloc" (func $malloc (param i32) (result i32)))
(import "env" "free" (func $free (param i32)))
(import "env" "atoi" (func $atoi (param i32) (result i32)))
diff --git a/test/passes/fannkuch3_dwarf.bin.txt b/test/passes/fannkuch3_dwarf.bin.txt
index 4ff3cff6c..e9b07a971 100644
--- a/test/passes/fannkuch3_dwarf.bin.txt
+++ b/test/passes/fannkuch3_dwarf.bin.txt
@@ -4795,9 +4795,9 @@ file_names[ 4]:
(type $none_=>_none (func))
(type $i32_=>_none (func (param i32)))
(type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32)))
- (import "env" "memory" (memory $7 256 256))
+ (import "env" "memory" (memory $mimport$0 256 256))
(data (i32.const 1024) "Pfannkuchen(%d) = %d.\n\00%d\00Wrong argument.\00")
- (import "env" "__indirect_function_table" (table $timport$8 1 funcref))
+ (import "env" "__indirect_function_table" (table $timport$1 1 funcref))
(import "env" "malloc" (func $malloc (param i32) (result i32)))
(import "env" "memcpy" (func $memcpy (param i32 i32 i32) (result i32)))
(import "env" "free" (func $free (param i32)))
diff --git a/test/passes/fannkuch3_manyopts_dwarf.bin.txt b/test/passes/fannkuch3_manyopts_dwarf.bin.txt
index 4e72e0826..36c9db37b 100644
--- a/test/passes/fannkuch3_manyopts_dwarf.bin.txt
+++ b/test/passes/fannkuch3_manyopts_dwarf.bin.txt
@@ -4715,7 +4715,7 @@ file_names[ 4]:
(type $none_=>_none (func))
(type $i32_=>_none (func (param i32)))
(type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32)))
- (import "env" "memory" (memory $7 256 256))
+ (import "env" "memory" (memory $mimport$0 256 256))
(data (i32.const 1024) "Pfannkuchen(%d) = %d.\n\00%d\00Wrong argument.")
(import "env" "malloc" (func $malloc (param i32) (result i32)))
(import "env" "memcpy" (func $memcpy (param i32 i32 i32) (result i32)))
diff --git a/test/passes/fib2_dwarf.bin.txt b/test/passes/fib2_dwarf.bin.txt
index ac0c26cf5..15e57c8aa 100644
--- a/test/passes/fib2_dwarf.bin.txt
+++ b/test/passes/fib2_dwarf.bin.txt
@@ -617,7 +617,7 @@ file_names[ 1]:
(type $none_=>_i32 (func (result i32)))
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
- (import "env" "memory" (memory $0 256 256))
+ (import "env" "memory" (memory $mimport$0 256 256))
(import "env" "__indirect_function_table" (table $timport$1 1 funcref))
(global $global$0 (mut i32) (i32.const 5243904))
(global $global$1 i32 (i32.const 1024))
diff --git a/test/passes/fib2_emptylocspan_dwarf.bin.txt b/test/passes/fib2_emptylocspan_dwarf.bin.txt
index 21f2fb878..1b7686887 100644
--- a/test/passes/fib2_emptylocspan_dwarf.bin.txt
+++ b/test/passes/fib2_emptylocspan_dwarf.bin.txt
@@ -617,7 +617,7 @@ file_names[ 1]:
(type $none_=>_i32 (func (result i32)))
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
- (import "env" "memory" (memory $0 256 256))
+ (import "env" "memory" (memory $mimport$0 256 256))
(import "env" "__indirect_function_table" (table $timport$1 1 funcref))
(global $global$0 (mut i32) (i32.const 5243904))
(global $global$1 i32 (i32.const 1024))
diff --git a/test/passes/fib_nonzero-low-pc_dwarf.bin.txt b/test/passes/fib_nonzero-low-pc_dwarf.bin.txt
index ac28b21a4..4e7156e9f 100644
--- a/test/passes/fib_nonzero-low-pc_dwarf.bin.txt
+++ b/test/passes/fib_nonzero-low-pc_dwarf.bin.txt
@@ -511,11 +511,11 @@ file_names[ 1]:
(module
(type $none_=>_none (func))
(type $i32_=>_i32 (func (param i32) (result i32)))
- (import "env" "memory" (memory $3 0))
- (import "env" "__indirect_function_table" (table $timport$4 0 funcref))
- (import "env" "__stack_pointer" (global $gimport$0 (mut i32)))
- (import "env" "__memory_base" (global $gimport$1 i32))
- (import "env" "__table_base" (global $gimport$2 i32))
+ (import "env" "memory" (memory $mimport$0 0))
+ (import "env" "__indirect_function_table" (table $timport$1 0 funcref))
+ (import "env" "__stack_pointer" (global $gimport$2 (mut i32)))
+ (import "env" "__memory_base" (global $gimport$3 i32))
+ (import "env" "__table_base" (global $gimport$4 i32))
(global $global$0 i32 (i32.const 0))
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
(export "__wasm_apply_relocs" (func $__wasm_apply_relocs))
diff --git a/test/passes/func-metrics.txt b/test/passes/func-metrics.txt
index 9eb7fd131..731dd933d 100644
--- a/test/passes/func-metrics.txt
+++ b/test/passes/func-metrics.txt
@@ -219,7 +219,7 @@ func: func_a
block : 1
call : 5
start: func_a
- [removable-bytes-without-it]: 67
+ [removable-bytes-without-it]: 57
[total] : 0
(module
(type $none_=>_none (func))
@@ -247,7 +247,7 @@ func: 0
[vars] : 0
global.get : 1
export: stackSave (0)
- [removable-bytes-without-it]: 66
+ [removable-bytes-without-it]: 70
[total] : 0
(module
(type $none_=>_i32 (func (result i32)))
diff --git a/test/passes/ignore_missing_func_dwarf.bin.txt b/test/passes/ignore_missing_func_dwarf.bin.txt
index c5f45cfdc..337f81f14 100644
--- a/test/passes/ignore_missing_func_dwarf.bin.txt
+++ b/test/passes/ignore_missing_func_dwarf.bin.txt
@@ -3,7 +3,7 @@
(type $none_=>_i32 (func (result i32)))
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
- (import "env" "memory" (memory $0 256 256))
+ (import "env" "memory" (memory $mimport$0 256 256))
(data (i32.const 1024) "\nvoid used(int x) {\n x++;\n x--;\n return x;\n}\n\nvoid unused(int x) {\n x >>= 1;\n x <<= 1;\n return x;\n}\n\nint main() {\n return used(42);\n}\n\00")
(data (i32.const 1168) "\00\04\00\00")
(import "env" "__indirect_function_table" (table $timport$1 1 funcref))
@@ -826,7 +826,7 @@ file_names[ 1]:
(type $none_=>_i32 (func (result i32)))
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
- (import "env" "memory" (memory $0 256 256))
+ (import "env" "memory" (memory $mimport$0 256 256))
(data (i32.const 1024) "\nvoid used(int x) {\n x++;\n x--;\n return x;\n}\n\nvoid unused(int x) {\n x >>= 1;\n x <<= 1;\n return x;\n}\n\nint main() {\n return used(42);\n}\n\00")
(data (i32.const 1168) "\00\04\00\00")
(import "env" "__indirect_function_table" (table $timport$1 1 funcref))
diff --git a/test/passes/inlined_to_start_dwarf.bin.txt b/test/passes/inlined_to_start_dwarf.bin.txt
index 7b8694021..7205cf070 100644
--- a/test/passes/inlined_to_start_dwarf.bin.txt
+++ b/test/passes/inlined_to_start_dwarf.bin.txt
@@ -414,7 +414,7 @@ file_names[ 1]:
(type $none_=>_none (func))
(type $i32_=>_none (func (param i32)))
(type $i32_=>_i32 (func (param i32) (result i32)))
- (import "env" "memory" (memory $0 256 256))
+ (import "env" "memory" (memory $mimport$0 256 256))
(data (i32.const 1024) "\00\00\00\00")
(table $0 1 1 funcref)
(global $global$0 (mut i32) (i32.const 5243920))
diff --git a/test/passes/multi_line_table_dwarf.bin.txt b/test/passes/multi_line_table_dwarf.bin.txt
index 84305a175..f3f65ff8e 100644
--- a/test/passes/multi_line_table_dwarf.bin.txt
+++ b/test/passes/multi_line_table_dwarf.bin.txt
@@ -423,11 +423,11 @@ file_names[ 1]:
(module
(type $none_=>_none (func))
(type $none_=>_i32 (func (result i32)))
- (import "env" "memory" (memory $3 0))
- (import "env" "__indirect_function_table" (table $timport$4 0 funcref))
- (import "env" "__stack_pointer" (global $gimport$0 (mut i32)))
- (import "env" "__memory_base" (global $gimport$1 i32))
- (import "env" "__table_base" (global $gimport$2 i32))
+ (import "env" "memory" (memory $mimport$0 0))
+ (import "env" "__indirect_function_table" (table $timport$1 0 funcref))
+ (import "env" "__stack_pointer" (global $gimport$2 (mut i32)))
+ (import "env" "__memory_base" (global $gimport$3 i32))
+ (import "env" "__table_base" (global $gimport$4 i32))
(global $global$0 i32 (i32.const 0))
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
(export "__wasm_apply_relocs" (func $__wasm_apply_relocs))
diff --git a/test/passes/print.bin.txt b/test/passes/print.bin.txt
index 02fc5a36e..4ea2361ec 100644
--- a/test/passes/print.bin.txt
+++ b/test/passes/print.bin.txt
@@ -4,7 +4,7 @@
(type $i32_=>_none (func (param i32)))
(type $none_=>_i32 (func (result i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
- (import "env" "memory" (memory $0 256 256))
+ (import "env" "memory" (memory $mimport$0 256 256))
(global $global$0 (mut i32) (i32.const 5243904))
(global $global$1 i32 (i32.const 1024))
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
@@ -95,7 +95,7 @@
(type $i32_=>_none (func (param i32)))
(type $none_=>_i32 (func (result i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
- (import "env" "memory" (memory $0 256 256))
+ (import "env" "memory" (memory $mimport$0 256 256))
(global $global$0 (mut i32) (i32.const 5243904))
(global $global$1 i32 (i32.const 1024))
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
diff --git a/test/passes/print_g.bin.txt b/test/passes/print_g.bin.txt
index 9afde51e1..0980d4c7f 100644
--- a/test/passes/print_g.bin.txt
+++ b/test/passes/print_g.bin.txt
@@ -4,7 +4,7 @@
(type $i32_=>_none (func (param i32)))
(type $none_=>_i32 (func (result i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
- (import "env" "memory" (memory $0 256 256))
+ (import "env" "memory" (memory $mimport$0 256 256))
(global $global$0 (mut i32) (i32.const 5243904))
(global $global$1 i32 (i32.const 1024))
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
@@ -134,7 +134,7 @@
(type $i32_=>_none (func (param i32)))
(type $none_=>_i32 (func (result i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
- (import "env" "memory" (memory $0 256 256))
+ (import "env" "memory" (memory $mimport$0 256 256))
(global $global$0 (mut i32) (i32.const 5243904))
(global $global$1 i32 (i32.const 1024))
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
diff --git a/test/passes/print_g_strip-dwarf.bin.txt b/test/passes/print_g_strip-dwarf.bin.txt
index 9d0331fca..15df9c09f 100644
--- a/test/passes/print_g_strip-dwarf.bin.txt
+++ b/test/passes/print_g_strip-dwarf.bin.txt
@@ -4,7 +4,7 @@
(type $i32_=>_none (func (param i32)))
(type $none_=>_i32 (func (result i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
- (import "env" "memory" (memory $0 256 256))
+ (import "env" "memory" (memory $mimport$0 256 256))
(global $global$0 (mut i32) (i32.const 5243904))
(global $global$1 i32 (i32.const 1024))
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
@@ -95,7 +95,7 @@
(type $i32_=>_none (func (param i32)))
(type $none_=>_i32 (func (result i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
- (import "env" "memory" (memory $0 256 256))
+ (import "env" "memory" (memory $mimport$0 256 256))
(global $global$0 (mut i32) (i32.const 5243904))
(global $global$1 i32 (i32.const 1024))
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
diff --git a/test/passes/reverse_dwarf_abbrevs.bin.txt b/test/passes/reverse_dwarf_abbrevs.bin.txt
index 0b021420d..99da237b6 100644
--- a/test/passes/reverse_dwarf_abbrevs.bin.txt
+++ b/test/passes/reverse_dwarf_abbrevs.bin.txt
@@ -120,7 +120,7 @@ file_names[ 1]:
(type $none_=>_none (func))
(type $i32_i32_i32_i32_i32_=>_i32 (func (param i32 i32 i32 i32 i32) (result i32)))
(type $i32_i32_i64_i32_=>_i64 (func (param i32 i32 i64 i32) (result i64)))
- (import "env" "memory" (memory $3 256 256))
+ (import "env" "memory" (memory $mimport$3 256 256))
(data (i32.const 1024) "hello, world!\00\00\00\18\04")
(data (i32.const 1048) "\05")
(data (i32.const 1060) "\01")
diff --git a/test/passes/strip-debug.bin.txt b/test/passes/strip-debug.bin.txt
index 5b5720991..90627c525 100644
--- a/test/passes/strip-debug.bin.txt
+++ b/test/passes/strip-debug.bin.txt
@@ -1,6 +1,6 @@
(module
(type $none_=>_i32 (func (result i32)))
- (import "env" "__linear_memory" (memory $0 0))
+ (import "env" "__linear_memory" (memory $mimport$0 0))
(import "env" "__indirect_function_table" (table $timport$1 0 funcref))
(func $0 (result i32)
(local $0 i32)
diff --git a/test/passes/strip-producers.bin.txt b/test/passes/strip-producers.bin.txt
index 2c1070ae5..3f7b535b4 100644
--- a/test/passes/strip-producers.bin.txt
+++ b/test/passes/strip-producers.bin.txt
@@ -1,6 +1,6 @@
(module
(type $none_=>_i32 (func (result i32)))
- (import "env" "__linear_memory" (memory $0 0))
+ (import "env" "__linear_memory" (memory $mimport$0 0))
(import "env" "__indirect_function_table" (table $timport$1 0 funcref))
(func $0 (result i32)
(local $0 i32)
diff --git a/test/polymorphic_stack.wast.fromBinary b/test/polymorphic_stack.wast.fromBinary
index 1265bd080..8a3b92d6e 100644
--- a/test/polymorphic_stack.wast.fromBinary
+++ b/test/polymorphic_stack.wast.fromBinary
@@ -3,7 +3,7 @@
(type $none_=>_none (func))
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $i32_=>_none (func (param i32)))
- (import "env" "table" (table $timport$0 9 9 funcref))
+ (import "env" "table" (table $0 9 9 funcref))
(func $break-and-binary (result i32)
(block $label$1 (result i32)
(unreachable)
diff --git a/test/reference-types.wast.fromBinary b/test/reference-types.wast.fromBinary
index 7b63a755b..a540048f9 100644
--- a/test/reference-types.wast.fromBinary
+++ b/test/reference-types.wast.fromBinary
@@ -9,21 +9,21 @@
(type $none_=>_exnref (func (result exnref)))
(type $none_=>_none (func))
(type $externref_=>_funcref (func (param externref) (result funcref)))
- (import "env" "import_global" (global $gimport$1 externref))
+ (import "env" "import_global" (global $import_global externref))
(import "env" "import_func" (func $import_func (param externref) (result funcref)))
(table $0 4 4 funcref)
(elem (i32.const 0) $take_externref $take_funcref $take_exnref $take_anyref)
- (global $global$0 (mut externref) (ref.null extern))
- (global $global$1 (mut funcref) (ref.null func))
- (global $global$2 (mut funcref) (ref.func $foo))
- (global $global$3 (mut exnref) (ref.null exn))
- (global $global$4 (mut anyref) (ref.null any))
- (global $global$5 (mut anyref) (ref.null extern))
- (global $global$6 (mut anyref) (ref.null func))
- (global $global$7 (mut anyref) (ref.func $foo))
- (global $global$8 (mut anyref) (ref.null exn))
+ (global $global_externref (mut externref) (ref.null extern))
+ (global $global_funcref (mut funcref) (ref.null func))
+ (global $global_funcref_func (mut funcref) (ref.func $foo))
+ (global $global_exnref (mut exnref) (ref.null exn))
+ (global $global_anyref (mut anyref) (ref.null any))
+ (global $global_anyref2 (mut anyref) (ref.null extern))
+ (global $global_anyref3 (mut anyref) (ref.null func))
+ (global $global_anyref4 (mut anyref) (ref.func $foo))
+ (global $global_anyref5 (mut anyref) (ref.null exn))
(export "export_func" (func $import_func))
- (export "export_global" (global $gimport$1))
+ (export "export_global" (global $import_global))
(func $take_externref (param $0 externref)
(nop)
)
@@ -48,7 +48,7 @@
(local.get $local_funcref)
)
(local.set $local_funcref
- (global.get $global$0)
+ (global.get $global_externref)
)
(local.set $local_funcref
(ref.null extern)
@@ -57,7 +57,7 @@
(local.get $local_externref)
)
(local.set $local_externref
- (global.get $global$1)
+ (global.get $global_funcref)
)
(local.set $local_externref
(ref.null func)
@@ -69,7 +69,7 @@
(local.get $local_exnref)
)
(local.set $local_exnref
- (global.get $global$3)
+ (global.get $global_exnref)
)
(local.set $local_exnref
(ref.null exn)
@@ -78,7 +78,7 @@
(local.get $local_anyref)
)
(local.set $local_anyref
- (global.get $global$4)
+ (global.get $global_anyref)
)
(local.set $local_anyref
(ref.null any)
@@ -87,7 +87,7 @@
(local.get $local_funcref)
)
(local.set $local_anyref
- (global.get $global$0)
+ (global.get $global_externref)
)
(local.set $local_anyref
(ref.null extern)
@@ -96,7 +96,7 @@
(local.get $local_externref)
)
(local.set $local_anyref
- (global.get $global$1)
+ (global.get $global_funcref)
)
(local.set $local_anyref
(ref.null func)
@@ -108,85 +108,85 @@
(local.get $local_exnref)
)
(local.set $local_anyref
- (global.get $global$3)
+ (global.get $global_exnref)
)
(local.set $local_anyref
(ref.null exn)
)
- (global.set $global$0
- (global.get $global$0)
+ (global.set $global_externref
+ (global.get $global_externref)
)
- (global.set $global$0
+ (global.set $global_externref
(local.get $local_funcref)
)
- (global.set $global$0
+ (global.set $global_externref
(ref.null extern)
)
- (global.set $global$1
- (global.get $global$1)
+ (global.set $global_funcref
+ (global.get $global_funcref)
)
- (global.set $global$1
+ (global.set $global_funcref
(local.get $local_externref)
)
- (global.set $global$1
+ (global.set $global_funcref
(ref.null func)
)
- (global.set $global$1
+ (global.set $global_funcref
(ref.func $foo)
)
- (global.set $global$3
- (global.get $global$3)
+ (global.set $global_exnref
+ (global.get $global_exnref)
)
- (global.set $global$3
+ (global.set $global_exnref
(local.get $local_exnref)
)
- (global.set $global$3
+ (global.set $global_exnref
(ref.null exn)
)
- (global.set $global$4
- (global.get $global$4)
+ (global.set $global_anyref
+ (global.get $global_anyref)
)
- (global.set $global$4
+ (global.set $global_anyref
(local.get $local_anyref)
)
- (global.set $global$4
+ (global.set $global_anyref
(ref.null any)
)
- (global.set $global$4
- (global.get $global$0)
+ (global.set $global_anyref
+ (global.get $global_externref)
)
- (global.set $global$4
+ (global.set $global_anyref
(local.get $local_funcref)
)
- (global.set $global$4
+ (global.set $global_anyref
(ref.null extern)
)
- (global.set $global$4
- (global.get $global$1)
+ (global.set $global_anyref
+ (global.get $global_funcref)
)
- (global.set $global$4
+ (global.set $global_anyref
(local.get $local_externref)
)
- (global.set $global$4
+ (global.set $global_anyref
(ref.null func)
)
- (global.set $global$4
+ (global.set $global_anyref
(ref.func $foo)
)
- (global.set $global$4
- (global.get $global$3)
+ (global.set $global_anyref
+ (global.get $global_exnref)
)
- (global.set $global$4
+ (global.set $global_anyref
(local.get $local_exnref)
)
- (global.set $global$4
+ (global.set $global_anyref
(ref.null exn)
)
(call $take_externref
(local.get $local_funcref)
)
(call $take_externref
- (global.get $global$0)
+ (global.get $global_externref)
)
(call $take_externref
(ref.null extern)
@@ -195,7 +195,7 @@
(local.get $local_externref)
)
(call $take_funcref
- (global.get $global$1)
+ (global.get $global_funcref)
)
(call $take_funcref
(ref.null func)
@@ -207,7 +207,7 @@
(local.get $local_exnref)
)
(call $take_exnref
- (global.get $global$3)
+ (global.get $global_exnref)
)
(call $take_exnref
(ref.null exn)
@@ -216,7 +216,7 @@
(local.get $local_anyref)
)
(call $take_anyref
- (global.get $global$4)
+ (global.get $global_anyref)
)
(call $take_anyref
(ref.null any)
@@ -225,7 +225,7 @@
(local.get $local_funcref)
)
(call $take_anyref
- (global.get $global$0)
+ (global.get $global_externref)
)
(call $take_anyref
(ref.null extern)
@@ -234,7 +234,7 @@
(local.get $local_externref)
)
(call $take_anyref
- (global.get $global$1)
+ (global.get $global_funcref)
)
(call $take_anyref
(ref.null func)
@@ -246,7 +246,7 @@
(local.get $local_exnref)
)
(call $take_anyref
- (global.get $global$3)
+ (global.get $global_exnref)
)
(call $take_anyref
(ref.null exn)
@@ -256,7 +256,7 @@
(i32.const 0)
)
(call_indirect (type $externref_=>_none)
- (global.get $global$0)
+ (global.get $global_externref)
(i32.const 0)
)
(call_indirect (type $externref_=>_none)
@@ -268,7 +268,7 @@
(i32.const 1)
)
(call_indirect (type $funcref_=>_none)
- (global.get $global$1)
+ (global.get $global_funcref)
(i32.const 1)
)
(call_indirect (type $funcref_=>_none)
@@ -284,7 +284,7 @@
(i32.const 2)
)
(call_indirect (type $exnref_=>_none)
- (global.get $global$3)
+ (global.get $global_exnref)
(i32.const 2)
)
(call_indirect (type $exnref_=>_none)
@@ -296,7 +296,7 @@
(i32.const 3)
)
(call_indirect (type $anyref_=>_none)
- (global.get $global$4)
+ (global.get $global_anyref)
(i32.const 3)
)
(call_indirect (type $anyref_=>_none)
@@ -308,7 +308,7 @@
(i32.const 3)
)
(call_indirect (type $anyref_=>_none)
- (global.get $global$0)
+ (global.get $global_externref)
(i32.const 3)
)
(call_indirect (type $anyref_=>_none)
@@ -320,7 +320,7 @@
(i32.const 3)
)
(call_indirect (type $anyref_=>_none)
- (global.get $global$1)
+ (global.get $global_funcref)
(i32.const 3)
)
(call_indirect (type $anyref_=>_none)
@@ -336,7 +336,7 @@
(i32.const 3)
)
(call_indirect (type $anyref_=>_none)
- (global.get $global$3)
+ (global.get $global_exnref)
(i32.const 3)
)
(call_indirect (type $anyref_=>_none)
@@ -354,7 +354,7 @@
(drop
(block $label$2 (result externref)
(br_if $label$2
- (global.get $global$0)
+ (global.get $global_externref)
(i32.const 1)
)
)
@@ -378,7 +378,7 @@
(drop
(block $label$5 (result funcref)
(br_if $label$5
- (global.get $global$1)
+ (global.get $global_funcref)
(i32.const 1)
)
)
@@ -410,7 +410,7 @@
(drop
(block $label$9 (result exnref)
(br_if $label$9
- (global.get $global$3)
+ (global.get $global_exnref)
(i32.const 1)
)
)
@@ -434,7 +434,7 @@
(drop
(block $label$12 (result anyref)
(br_if $label$12
- (global.get $global$4)
+ (global.get $global_anyref)
(i32.const 1)
)
)
@@ -510,7 +510,7 @@
)
(drop
(loop $label$22 (result externref)
- (global.get $global$0)
+ (global.get $global_externref)
)
)
(drop
@@ -525,7 +525,7 @@
)
(drop
(loop $label$25 (result funcref)
- (global.get $global$1)
+ (global.get $global_funcref)
)
)
(drop
@@ -545,7 +545,7 @@
)
(drop
(loop $label$29 (result exnref)
- (global.get $global$3)
+ (global.get $global_exnref)
)
)
(drop
@@ -560,7 +560,7 @@
)
(drop
(loop $label$32 (result anyref)
- (global.get $global$4)
+ (global.get $global_anyref)
)
)
(drop
@@ -575,7 +575,7 @@
)
(drop
(loop $label$35 (result anyref)
- (global.get $global$0)
+ (global.get $global_externref)
)
)
(drop
@@ -590,7 +590,7 @@
)
(drop
(loop $label$38 (result anyref)
- (global.get $global$1)
+ (global.get $global_funcref)
)
)
(drop
@@ -610,7 +610,7 @@
)
(drop
(loop $label$42 (result anyref)
- (global.get $global$3)
+ (global.get $global_exnref)
)
)
(drop
@@ -880,7 +880,7 @@
)
(drop
(ref.is_null
- (global.get $global$0)
+ (global.get $global_externref)
)
)
(drop
@@ -895,7 +895,7 @@
)
(drop
(ref.is_null
- (global.get $global$1)
+ (global.get $global_funcref)
)
)
(drop
@@ -915,7 +915,7 @@
)
(drop
(ref.is_null
- (global.get $global$3)
+ (global.get $global_exnref)
)
)
(drop
@@ -930,7 +930,7 @@
)
(drop
(ref.is_null
- (global.get $global$4)
+ (global.get $global_anyref)
)
)
(drop
@@ -944,7 +944,7 @@
(local.get $local_externref)
)
(func $return_externref_global (result externref)
- (global.get $global$0)
+ (global.get $global_externref)
)
(func $return_externref_null (result externref)
(ref.null extern)
@@ -954,7 +954,7 @@
(local.get $local_funcref)
)
(func $return_funcref_global (result funcref)
- (global.get $global$1)
+ (global.get $global_funcref)
)
(func $return_funcref_null (result funcref)
(ref.null func)
@@ -967,7 +967,7 @@
(local.get $local_exnref)
)
(func $return_exnref_global (result exnref)
- (global.get $global$3)
+ (global.get $global_exnref)
)
(func $return_exnref_null (result exnref)
(ref.null exn)
@@ -977,7 +977,7 @@
(local.get $local_anyref)
)
(func $return_anyref_global (result anyref)
- (global.get $global$4)
+ (global.get $global_anyref)
)
(func $return_anyref_null (result anyref)
(ref.null any)
@@ -987,7 +987,7 @@
(local.get $local_externref)
)
(func $return_anyref3 (result anyref)
- (global.get $global$0)
+ (global.get $global_externref)
)
(func $return_anyref4 (result anyref)
(ref.null extern)
@@ -997,7 +997,7 @@
(local.get $local_funcref)
)
(func $return_anyref6 (result anyref)
- (global.get $global$1)
+ (global.get $global_funcref)
)
(func $return_anyref7 (result anyref)
(ref.null func)
@@ -1010,7 +1010,7 @@
(local.get $local_exnref)
)
(func $return_anyref10 (result anyref)
- (global.get $global$3)
+ (global.get $global_exnref)
)
(func $return_anyref11 (result anyref)
(ref.null exn)
diff --git a/test/table-import.wast.fromBinary b/test/table-import.wast.fromBinary
index 5cf03f48a..4597ce783 100644
--- a/test/table-import.wast.fromBinary
+++ b/test/table-import.wast.fromBinary
@@ -1,6 +1,6 @@
(module
(type $none_=>_none (func))
- (import "env" "table" (table $timport$0 1 1 funcref))
+ (import "env" "table" (table $0 1 1 funcref))
(elem (i32.const 0) $foo)
(memory $0 0)
(func $foo
diff --git a/test/unit/input/atomics_target_feature.wasm b/test/unit/input/atomics_target_feature.wasm
index 91ee36201..5e2ab0b33 100755
--- a/test/unit/input/atomics_target_feature.wasm
+++ b/test/unit/input/atomics_target_feature.wasm
Binary files differ
diff --git a/test/unit/input/bulkmem_data.wasm b/test/unit/input/bulkmem_data.wasm
index aa9e535b5..268afd01a 100755
--- a/test/unit/input/bulkmem_data.wasm
+++ b/test/unit/input/bulkmem_data.wasm
Binary files differ
diff --git a/test/unit/input/bulkmem_target_feature.wasm b/test/unit/input/bulkmem_target_feature.wasm
index 373b97c43..3c69d2323 100755
--- a/test/unit/input/bulkmem_target_feature.wasm
+++ b/test/unit/input/bulkmem_target_feature.wasm
Binary files differ
diff --git a/test/unit/input/gc_target_feature.wasm b/test/unit/input/gc_target_feature.wasm
index ccabbc16e..fce4e1412 100644
--- a/test/unit/input/gc_target_feature.wasm
+++ b/test/unit/input/gc_target_feature.wasm
Binary files differ
diff --git a/test/unit/input/mutable_globals_target_feature.wasm b/test/unit/input/mutable_globals_target_feature.wasm
index 2ca925279..3bf19165b 100644
--- a/test/unit/input/mutable_globals_target_feature.wasm
+++ b/test/unit/input/mutable_globals_target_feature.wasm
Binary files differ
diff --git a/test/unit/input/reference_types_target_feature.wasm b/test/unit/input/reference_types_target_feature.wasm
index 7ea8847e9..b388b11bb 100644
--- a/test/unit/input/reference_types_target_feature.wasm
+++ b/test/unit/input/reference_types_target_feature.wasm
Binary files differ
diff --git a/test/unit/input/signext_target_feature.wasm b/test/unit/input/signext_target_feature.wasm
index b979df8a1..173ffa4c1 100755
--- a/test/unit/input/signext_target_feature.wasm
+++ b/test/unit/input/signext_target_feature.wasm
Binary files differ
diff --git a/test/unit/input/simd_target_feature.wasm b/test/unit/input/simd_target_feature.wasm
index 75e624112..6fac47fe4 100755
--- a/test/unit/input/simd_target_feature.wasm
+++ b/test/unit/input/simd_target_feature.wasm
Binary files differ
diff --git a/test/unit/input/tail_call_target_feature.wasm b/test/unit/input/tail_call_target_feature.wasm
index be4b73caf..ddb5bfc6a 100755
--- a/test/unit/input/tail_call_target_feature.wasm
+++ b/test/unit/input/tail_call_target_feature.wasm
Binary files differ
diff --git a/test/unit/input/truncsat_target_feature.wasm b/test/unit/input/truncsat_target_feature.wasm
index 67f0a7052..90dd65b15 100755
--- a/test/unit/input/truncsat_target_feature.wasm
+++ b/test/unit/input/truncsat_target_feature.wasm
Binary files differ
diff --git a/test/unit/input/update.sh b/test/unit/input/update.sh
new file mode 100644
index 000000000..cf65bac45
--- /dev/null
+++ b/test/unit/input/update.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+# This file updates the target_feature tests in the rare but unfortunate case
+# that their roundtripped binary representations do not match the input anymore
+# due to otherwise unrelated binary format changes.
+
+WASM_OPT="../../../bin/wasm-opt" # edit when building out of tree
+
+$WASM_OPT atomics_target_feature.wasm --enable-threads -g --emit-target-features -o atomics_target_feature.wasm
+$WASM_OPT bulkmem_data.wasm --enable-bulk-memory -g --emit-target-features -o bulkmem_data.wasm
+$WASM_OPT bulkmem_target_feature.wasm --enable-bulk-memory -g --emit-target-features -o bulkmem_target_feature.wasm
+$WASM_OPT exception_handling_target_feature.wasm --enable-exception-handling --enable-reference-types -g --emit-target-features -o exception_handling_target_feature.wasm
+$WASM_OPT gc_target_feature.wasm --enable-reference-types --enable-gc -g --emit-target-features -o gc_target_feature.wasm
+$WASM_OPT mutable_globals_target_feature.wasm --enable-mutable-globals -g --emit-target-features -o mutable_globals_target_feature.wasm
+$WASM_OPT reference_types_target_feature.wasm --enable-reference-types -g --emit-target-features -o reference_types_target_feature.wasm
+$WASM_OPT signext_target_feature.wasm --enable-sign-ext -g --emit-target-features -o signext_target_feature.wasm
+$WASM_OPT simd_target_feature.wasm --enable-simd -g --emit-target-features -o simd_target_feature.wasm
+$WASM_OPT truncsat_target_feature.wasm --enable-nontrapping-float-to-int -g --emit-target-features -o truncsat_target_feature.wasm
+$WASM_OPT tail_call_target_feature.wasm --enable-tail-call -g --emit-target-features -o tail_call_target_feature.wasm