From 7231ff8b265f13e1d78125dbcda9ee726bab7b0f Mon Sep 17 00:00:00 2001 From: Jay Phelps Date: Sun, 26 Aug 2018 16:23:41 -0400 Subject: [PATCH 1/2] Support for mutable global imports/exports --- src/binaryen-c.cpp | 3 ++- src/binaryen-c.h | 2 +- src/passes/Print.cpp | 10 +++++++++- src/wasm.h | 1 + src/wasm/wasm-binary.cpp | 6 ++---- src/wasm/wasm-validator.cpp | 11 ++++++++++- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 33281ff82b3..25f2562a8d4 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -1765,7 +1765,7 @@ BinaryenImportRef BinaryenAddMemoryImport(BinaryenModuleRef module, const char* wasm->addImport(ret); return ret; } -BinaryenImportRef BinaryenAddGlobalImport(BinaryenModuleRef module, const char* internalName, const char* externalModuleName, const char* externalBaseName, BinaryenType globalType) { +BinaryenImportRef BinaryenAddGlobalImport(BinaryenModuleRef module, const char* internalName, const char* externalModuleName, const char* externalBaseName, BinaryenType globalType, int8_t mutable_) { auto* wasm = (Module*)module; auto* ret = new Import(); @@ -1780,6 +1780,7 @@ BinaryenImportRef BinaryenAddGlobalImport(BinaryenModuleRef module, const char* ret->base = externalBaseName; ret->globalType = Type(globalType); ret->kind = ExternalKind::Global; + ret->mutable_ = !!mutable_; wasm->addImport(ret); return ret; } diff --git a/src/binaryen-c.h b/src/binaryen-c.h index c61668c6d69..4ae9a7072af 100644 --- a/src/binaryen-c.h +++ b/src/binaryen-c.h @@ -612,7 +612,7 @@ WASM_DEPRECATED BinaryenImportRef BinaryenAddImport(BinaryenModuleRef module, co BinaryenImportRef BinaryenAddFunctionImport(BinaryenModuleRef module, const char* internalName, const char* externalModuleName, const char *externalBaseName, BinaryenFunctionTypeRef functionType); BinaryenImportRef BinaryenAddTableImport(BinaryenModuleRef module, const char* internalName, const char* externalModuleName, const char *externalBaseName); BinaryenImportRef BinaryenAddMemoryImport(BinaryenModuleRef module, const char* internalName, const char* externalModuleName, const char *externalBaseName); -BinaryenImportRef BinaryenAddGlobalImport(BinaryenModuleRef module, const char* internalName, const char* externalModuleName, const char *externalBaseName, BinaryenType globalType); +BinaryenImportRef BinaryenAddGlobalImport(BinaryenModuleRef module, const char* internalName, const char* externalModuleName, const char *externalBaseName, BinaryenType globalType, int8_t mutable_); void BinaryenRemoveImport(BinaryenModuleRef module, const char* internalName); // Exports diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 28e7cc34fb6..6ed72e4a2e1 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -822,7 +822,15 @@ struct PrintSExpression : public Visitor { case ExternalKind::Function: if (curr->functionType.is()) visitFunctionType(currModule->getFunctionType(curr->functionType), &curr->name); break; case ExternalKind::Table: printTableHeader(&currModule->table); break; case ExternalKind::Memory: printMemoryHeader(&currModule->memory); break; - case ExternalKind::Global: o << "(global " << curr->name << ' ' << printType(curr->globalType) << ")"; break; + case ExternalKind::Global: + o << "(global " << curr->name << ' '; + if (curr->mutable_) { + o << "(mut " << printType(curr->globalType) << ") "; + } else { + o << printType(curr->globalType) << ' '; + } + o << ")"; + break; default: WASM_UNREACHABLE(); } o << ')'; diff --git a/src/wasm.h b/src/wasm.h index 49b0881b92f..f8dc8fe21cb 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -656,6 +656,7 @@ class Import { ExternalKind kind; Name functionType; // for Function imports Type globalType; // for Global imports + bool mutable_; // for Global imports }; class Export { diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 935660d9529..b1fb53d4635 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -196,7 +196,7 @@ void WasmBinaryWriter::writeImports() { } case ExternalKind::Global: o << binaryType(import->globalType); - o << U32LEB(0); // Mutable global's can't be imported for now. + o << U32LEB(import->mutable_); break; default: WASM_UNREACHABLE(); } @@ -959,9 +959,7 @@ void WasmBinaryBuilder::readImports() { curr->name = Name(std::string("gimport$") + std::to_string(i)); curr->globalType = getConcreteType(); auto globalMutable = getU32LEB(); - // TODO: actually use the globalMutable flag. Currently mutable global - // imports is a future feature, to be implemented with thread support. - (void)globalMutable; + curr->mutable_ = !!globalMutable; break; } default: { diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 4a6ed19be77..80dade53992 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -509,10 +509,19 @@ void FunctionValidator::visitGetGlobal(GetGlobal* curr) { void FunctionValidator::visitSetGlobal(SetGlobal* curr) { if (!info.validateGlobally) return; auto* global = getModule()->getGlobalOrNull(curr->name); - if (shouldBeTrue(global != NULL, curr, "set_global name must be valid (and not an import; imports can't be modified)")) { + if (global) { shouldBeTrue(global->mutable_, curr, "set_global global must be mutable"); shouldBeEqualOrFirstIsUnreachable(curr->value->type, global->type, curr, "set_global value must have right type"); + return; + } + auto* import = getModule()->getImportOrNull(curr->name); + if (import) { + shouldBeTrue(import->kind == ExternalKind::Global, curr, "set_global imported name is not a global"); + shouldBeTrue(import->mutable_, curr, "set_global imported global must be mutable"); + shouldBeEqualOrFirstIsUnreachable(curr->value->type, import->globalType, curr, "set_global value must have right type"); + return; } + info.fail("set_global global must exist", curr, getFunction()); } void FunctionValidator::visitLoad(Load* curr) { From 8a0fb7ab5bf68eca2c1a2bada2ef71fa1f81dbd3 Mon Sep 17 00:00:00 2001 From: Jay Phelps Date: Sun, 26 Aug 2018 18:33:32 -0400 Subject: [PATCH 2/2] WIP addition fixes for mutable global imports and tests --- src/passes/Print.cpp | 4 ++-- src/tools/wasm-merge.cpp | 2 ++ src/wasm.h | 2 +- src/wasm/wasm-s-parser.cpp | 7 ++++--- test/emcc_hello_world.fromasm | 2 +- test/empty.fromasm.clamp.no-opts | 4 ++-- test/empty.fromasm.imprecise.no-opts | 4 ++-- test/empty.fromasm.no-opts | 4 ++-- test/hello_world.fromasm.clamp.no-opts | 2 +- test/hello_world.fromasm.imprecise.no-opts | 2 +- test/hello_world.fromasm.no-opts | 2 +- test/i64-setTempRet0.fromasm.clamp.no-opts | 2 +- test/i64-setTempRet0.fromasm.no-opts | 2 +- test/memorygrowth.fromasm.clamp | 4 ++-- test/merge/fusing.wast.combined | 2 +- test/merge/fusing.wast.combined.finalized | 2 +- .../main-lacks-segments.wast.combined.finalized | 4 ++-- .../post-instantiate-b.wast.combined.finalized | 2 +- test/min.fromasm | 2 +- test/min.fromasm.clamp | 2 +- test/min.fromasm.clamp.no-opts | 2 +- test/min.fromasm.imprecise.no-opts | 2 +- test/min.fromasm.no-opts | 2 +- test/mutable-global.wast | 12 ++++++++++++ test/mutable-global.wast.from-wast | 12 ++++++++++++ test/mutable-global.wast.fromBinary | 13 +++++++++++++ test/mutable-global.wast.fromBinary.noDebugInfo | 13 +++++++++++++ test/passes/memory-packing.txt | 6 +++--- test/use-import-and-drop.fromasm | 2 +- test/use-import-and-drop.fromasm.clamp | 2 +- test/use-import-and-drop.fromasm.clamp.no-opts | 2 +- test/use-import-and-drop.fromasm.imprecise.no-opts | 2 +- test/use-import-and-drop.fromasm.no-opts | 2 +- 33 files changed, 91 insertions(+), 38 deletions(-) create mode 100644 test/mutable-global.wast create mode 100644 test/mutable-global.wast.from-wast create mode 100644 test/mutable-global.wast.fromBinary create mode 100644 test/mutable-global.wast.fromBinary.noDebugInfo diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 6ed72e4a2e1..a74a280d9c7 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -825,9 +825,9 @@ struct PrintSExpression : public Visitor { case ExternalKind::Global: o << "(global " << curr->name << ' '; if (curr->mutable_) { - o << "(mut " << printType(curr->globalType) << ") "; + o << "(mut " << printType(curr->globalType) << ")"; } else { - o << printType(curr->globalType) << ' '; + o << printType(curr->globalType); } o << ")"; break; diff --git a/src/tools/wasm-merge.cpp b/src/tools/wasm-merge.cpp index 6c7bd46afc7..22e78550ca8 100644 --- a/src/tools/wasm-merge.cpp +++ b/src/tools/wasm-merge.cpp @@ -130,6 +130,7 @@ struct Mergeable { import->base = MEMORY_BASE; import->kind = ExternalKind::Global; import->globalType = i32; + import->mutable_ = false; wasm.addImport(import); memoryBaseGlobals.insert(import->name); } @@ -143,6 +144,7 @@ struct Mergeable { import->base = TABLE_BASE; import->kind = ExternalKind::Global; import->globalType = i32; + import->mutable_ = false; wasm.addImport(import); tableBaseGlobals.insert(import->name); } diff --git a/src/wasm.h b/src/wasm.h index f8dc8fe21cb..20e09e3f480 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -650,7 +650,7 @@ enum class ExternalKind { class Import { public: - Import() : globalType(none) {} + Import() : globalType(none), mutable_(false) {} Name name, module, base; // name = module.base ExternalKind kind; diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index 5635282f7bf..f28324bc707 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -1754,7 +1754,7 @@ void SExpressionWasmBuilder::parseImport(Element& s) { auto& inner2 = *inner[j]; if (inner2[0]->str() != MUT) throw ParseException("expected mut"); im->globalType = stringToType(inner2[1]->str()); - throw ParseException("cannot import a mutable global", s.line, s.col); + im->mutable_ = true; } } else if (im->kind == ExternalKind::Table) { if (j < inner.size() - 1) { @@ -1824,14 +1824,15 @@ void SExpressionWasmBuilder::parseGlobal(Element& s, bool preParseImport) { if (importModule.is()) { // this is an import, actually if (!preParseImport) throw ParseException("!preParseImport in global"); - if (mutable_) throw ParseException("cannot import a mutable global", s.line, s.col); std::unique_ptr im = make_unique(); im->name = global->name; im->module = importModule; im->base = importBase; im->kind = ExternalKind::Global; im->globalType = type; - if (wasm.getImportOrNull(im->name)) throw ParseException("duplicate import", s.line, s.col); + im->mutable_ = mutable_; + if (wasm.getImportOrNull(im->name)) + throw ParseException("duplicate import", s.line, s.col); wasm.addImport(im.release()); return; } diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm index 6811213dc63..8d314aafee4 100644 --- a/test/emcc_hello_world.fromasm +++ b/test/emcc_hello_world.fromasm @@ -10,7 +10,7 @@ (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 18 18 anyfunc)) (import "env" "tableBase" (global $tableBase i32)) - (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32)) + (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import (mut i32))) (import "env" "STACK_MAX" (global $STACK_MAX$asm2wasm$import i32)) (import "env" "tempDoublePtr" (global $tempDoublePtr$asm2wasm$import i32)) (import "env" "abort" (func $abort)) diff --git a/test/empty.fromasm.clamp.no-opts b/test/empty.fromasm.clamp.no-opts index ddb433043ea..370dab8aa7c 100644 --- a/test/empty.fromasm.clamp.no-opts +++ b/test/empty.fromasm.clamp.no-opts @@ -1,6 +1,6 @@ (module (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 0 0 anyfunc)) - (import "env" "memoryBase" (global $memoryBase i32)) - (import "env" "tableBase" (global $tableBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) + (import "env" "tableBase" (global $tableBase (mut i32))) ) diff --git a/test/empty.fromasm.imprecise.no-opts b/test/empty.fromasm.imprecise.no-opts index ddb433043ea..370dab8aa7c 100644 --- a/test/empty.fromasm.imprecise.no-opts +++ b/test/empty.fromasm.imprecise.no-opts @@ -1,6 +1,6 @@ (module (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 0 0 anyfunc)) - (import "env" "memoryBase" (global $memoryBase i32)) - (import "env" "tableBase" (global $tableBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) + (import "env" "tableBase" (global $tableBase (mut i32))) ) diff --git a/test/empty.fromasm.no-opts b/test/empty.fromasm.no-opts index ddb433043ea..370dab8aa7c 100644 --- a/test/empty.fromasm.no-opts +++ b/test/empty.fromasm.no-opts @@ -1,6 +1,6 @@ (module (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 0 0 anyfunc)) - (import "env" "memoryBase" (global $memoryBase i32)) - (import "env" "tableBase" (global $tableBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) + (import "env" "tableBase" (global $tableBase (mut i32))) ) diff --git a/test/hello_world.fromasm.clamp.no-opts b/test/hello_world.fromasm.clamp.no-opts index 90861e2898c..290a0ac36ee 100644 --- a/test/hello_world.fromasm.clamp.no-opts +++ b/test/hello_world.fromasm.clamp.no-opts @@ -1,7 +1,7 @@ (module (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 0 0 anyfunc)) - (import "env" "memoryBase" (global $memoryBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) (import "env" "tableBase" (global $tableBase i32)) (export "add" (func $add)) (func $add (; 0 ;) (param $x i32) (param $y i32) (result i32) diff --git a/test/hello_world.fromasm.imprecise.no-opts b/test/hello_world.fromasm.imprecise.no-opts index 90861e2898c..290a0ac36ee 100644 --- a/test/hello_world.fromasm.imprecise.no-opts +++ b/test/hello_world.fromasm.imprecise.no-opts @@ -1,7 +1,7 @@ (module (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 0 0 anyfunc)) - (import "env" "memoryBase" (global $memoryBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) (import "env" "tableBase" (global $tableBase i32)) (export "add" (func $add)) (func $add (; 0 ;) (param $x i32) (param $y i32) (result i32) diff --git a/test/hello_world.fromasm.no-opts b/test/hello_world.fromasm.no-opts index 90861e2898c..290a0ac36ee 100644 --- a/test/hello_world.fromasm.no-opts +++ b/test/hello_world.fromasm.no-opts @@ -1,7 +1,7 @@ (module (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 0 0 anyfunc)) - (import "env" "memoryBase" (global $memoryBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) (import "env" "tableBase" (global $tableBase i32)) (export "add" (func $add)) (func $add (; 0 ;) (param $x i32) (param $y i32) (result i32) diff --git a/test/i64-setTempRet0.fromasm.clamp.no-opts b/test/i64-setTempRet0.fromasm.clamp.no-opts index 6ade6f2a887..90f9e8d76c5 100644 --- a/test/i64-setTempRet0.fromasm.clamp.no-opts +++ b/test/i64-setTempRet0.fromasm.clamp.no-opts @@ -3,7 +3,7 @@ (type $legaltype$illegalImportResult (func (result i32))) (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 0 0 anyfunc)) - (import "env" "memoryBase" (global $memoryBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) (import "env" "tableBase" (global $tableBase i32)) (import "env" "illegalImportResult" (func $illegalImportResult (result i64))) (import "env" "illegalImportResult" (func $legalimport$illegalImportResult (result i32))) diff --git a/test/i64-setTempRet0.fromasm.no-opts b/test/i64-setTempRet0.fromasm.no-opts index 6ade6f2a887..90f9e8d76c5 100644 --- a/test/i64-setTempRet0.fromasm.no-opts +++ b/test/i64-setTempRet0.fromasm.no-opts @@ -3,7 +3,7 @@ (type $legaltype$illegalImportResult (func (result i32))) (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 0 0 anyfunc)) - (import "env" "memoryBase" (global $memoryBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) (import "env" "tableBase" (global $tableBase i32)) (import "env" "illegalImportResult" (func $illegalImportResult (result i64))) (import "env" "illegalImportResult" (func $legalimport$illegalImportResult (result i32))) diff --git a/test/memorygrowth.fromasm.clamp b/test/memorygrowth.fromasm.clamp index 5afec926b1d..217e3cdda21 100644 --- a/test/memorygrowth.fromasm.clamp +++ b/test/memorygrowth.fromasm.clamp @@ -7,8 +7,8 @@ (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (import "env" "memory" (memory $0 256)) (import "env" "table" (table 8 8 anyfunc)) - (import "env" "memoryBase" (global $memoryBase i32)) - (import "env" "tableBase" (global $tableBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) + (import "env" "tableBase" (global $tableBase (mut i32))) (import "env" "STACKTOP" (global $r$asm2wasm$import i32)) (import "env" "STACK_MAX" (global $s$asm2wasm$import i32)) (import "env" "abort" (func $ja (param i32))) diff --git a/test/merge/fusing.wast.combined b/test/merge/fusing.wast.combined index d3d0bbed34c..0a605645bb8 100644 --- a/test/merge/fusing.wast.combined +++ b/test/merge/fusing.wast.combined @@ -5,7 +5,7 @@ (import "env" "tableBase" (global $tableBase i32)) (import "env" "memory" (memory $0 256)) (import "env" "table" (table 0 anyfunc)) - (import "env" "memoryBase" (global $memoryBase$0 i32)) + (import "env" "memoryBase" (global $memoryBase$0 (mut i32))) (import "env" "tableBase" (global $tableBase$0 i32)) (global $a-global i32 (i32.const 0)) (global $b-global f64 (f64.const 2.14281428)) diff --git a/test/merge/fusing.wast.combined.finalized b/test/merge/fusing.wast.combined.finalized index 0473302d398..90e22c024f2 100644 --- a/test/merge/fusing.wast.combined.finalized +++ b/test/merge/fusing.wast.combined.finalized @@ -5,7 +5,7 @@ (import "env" "tableBase" (global $tableBase i32)) (import "env" "memory" (memory $0 256)) (import "env" "table" (table 8 anyfunc)) - (import "env" "memoryBase" (global $memoryBase$0 i32)) + (import "env" "memoryBase" (global $memoryBase$0 (mut i32))) (import "env" "tableBase" (global $tableBase$0 i32)) (global $a-global i32 (i32.const 0)) (global $b-global f64 (f64.const 2.14281428)) diff --git a/test/merge/main-lacks-segments.wast.combined.finalized b/test/merge/main-lacks-segments.wast.combined.finalized index dd180662d3f..633c9687912 100644 --- a/test/merge/main-lacks-segments.wast.combined.finalized +++ b/test/merge/main-lacks-segments.wast.combined.finalized @@ -1,7 +1,7 @@ (module (type $0 (func)) - (import "env" "memoryBase" (global $memoryBase i32)) - (import "env" "tableBase" (global $tableBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) + (import "env" "tableBase" (global $tableBase (mut i32))) (import "env" "memory" (memory $0 256)) (import "env" "table" (table 10 anyfunc)) (import "env" "memoryBase" (global $memoryBase$0 i32)) diff --git a/test/merge/post-instantiate-b.wast.combined.finalized b/test/merge/post-instantiate-b.wast.combined.finalized index f832716a9f5..0124acbd781 100644 --- a/test/merge/post-instantiate-b.wast.combined.finalized +++ b/test/merge/post-instantiate-b.wast.combined.finalized @@ -2,7 +2,7 @@ (type $0 (func)) (type $0$0 (func)) (import "env" "memoryBase" (global $memoryBase i32)) - (import "env" "tableBase" (global $tableBase i32)) + (import "env" "tableBase" (global $tableBase (mut i32))) (import "env" "memoryBase" (global $memoryBase$0 i32)) (import "env" "tableBase" (global $tableBase$0 i32)) (export "__post_instantiate" (func $0$0)) diff --git a/test/min.fromasm b/test/min.fromasm index d46362b923f..dbfe7995062 100644 --- a/test/min.fromasm +++ b/test/min.fromasm @@ -1,6 +1,6 @@ (module (import "env" "memory" (memory $0 256 256)) - (import "env" "memoryBase" (global $memoryBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) (global $M (mut i32) (i32.const 0)) (data (get_global $memoryBase) "min.asm.js") (export "floats" (func $legalstub$floats)) diff --git a/test/min.fromasm.clamp b/test/min.fromasm.clamp index d46362b923f..dbfe7995062 100644 --- a/test/min.fromasm.clamp +++ b/test/min.fromasm.clamp @@ -1,6 +1,6 @@ (module (import "env" "memory" (memory $0 256 256)) - (import "env" "memoryBase" (global $memoryBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) (global $M (mut i32) (i32.const 0)) (data (get_global $memoryBase) "min.asm.js") (export "floats" (func $legalstub$floats)) diff --git a/test/min.fromasm.clamp.no-opts b/test/min.fromasm.clamp.no-opts index 7586e5fc2f6..aa0cc12a6a8 100644 --- a/test/min.fromasm.clamp.no-opts +++ b/test/min.fromasm.clamp.no-opts @@ -1,7 +1,7 @@ (module (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 0 0 anyfunc)) - (import "env" "memoryBase" (global $memoryBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) (import "env" "tableBase" (global $tableBase i32)) (import "env" "tempDoublePtr" (global $tDP$asm2wasm$import i32)) (global $tDP (mut i32) (get_global $tDP$asm2wasm$import)) diff --git a/test/min.fromasm.imprecise.no-opts b/test/min.fromasm.imprecise.no-opts index 7586e5fc2f6..aa0cc12a6a8 100644 --- a/test/min.fromasm.imprecise.no-opts +++ b/test/min.fromasm.imprecise.no-opts @@ -1,7 +1,7 @@ (module (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 0 0 anyfunc)) - (import "env" "memoryBase" (global $memoryBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) (import "env" "tableBase" (global $tableBase i32)) (import "env" "tempDoublePtr" (global $tDP$asm2wasm$import i32)) (global $tDP (mut i32) (get_global $tDP$asm2wasm$import)) diff --git a/test/min.fromasm.no-opts b/test/min.fromasm.no-opts index 7586e5fc2f6..aa0cc12a6a8 100644 --- a/test/min.fromasm.no-opts +++ b/test/min.fromasm.no-opts @@ -1,7 +1,7 @@ (module (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 0 0 anyfunc)) - (import "env" "memoryBase" (global $memoryBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) (import "env" "tableBase" (global $tableBase i32)) (import "env" "tempDoublePtr" (global $tDP$asm2wasm$import i32)) (global $tDP (mut i32) (get_global $tDP$asm2wasm$import)) diff --git a/test/mutable-global.wast b/test/mutable-global.wast new file mode 100644 index 00000000000..71d333b1794 --- /dev/null +++ b/test/mutable-global.wast @@ -0,0 +1,12 @@ +(module + (type $0 (func)) + (import "env" "global-mut" (global $global-mut (mut i32))) + (func $foo (type $0) + (set_global $global-mut + (i32.add + (get_global $global-mut) + (i32.const 1) + ) + ) + ) +) diff --git a/test/mutable-global.wast.from-wast b/test/mutable-global.wast.from-wast new file mode 100644 index 00000000000..f12fb3fa427 --- /dev/null +++ b/test/mutable-global.wast.from-wast @@ -0,0 +1,12 @@ +(module + (type $0 (func)) + (import "env" "global-mut" (global $global-mut (mut i32))) + (func $foo (; 0 ;) (type $0) + (set_global $global-mut + (i32.add + (get_global $global-mut) + (i32.const 1) + ) + ) + ) +) diff --git a/test/mutable-global.wast.fromBinary b/test/mutable-global.wast.fromBinary new file mode 100644 index 00000000000..3273575ef0a --- /dev/null +++ b/test/mutable-global.wast.fromBinary @@ -0,0 +1,13 @@ +(module + (type $0 (func)) + (import "env" "global-mut" (global $gimport$0 (mut i32))) + (func $foo (; 0 ;) (type $0) + (set_global $gimport$0 + (i32.add + (get_global $gimport$0) + (i32.const 1) + ) + ) + ) +) + diff --git a/test/mutable-global.wast.fromBinary.noDebugInfo b/test/mutable-global.wast.fromBinary.noDebugInfo new file mode 100644 index 00000000000..aba18cdc40d --- /dev/null +++ b/test/mutable-global.wast.fromBinary.noDebugInfo @@ -0,0 +1,13 @@ +(module + (type $0 (func)) + (import "env" "global-mut" (global $gimport$0 (mut i32))) + (func $0 (; 0 ;) (type $0) + (set_global $gimport$0 + (i32.add + (get_global $gimport$0) + (i32.const 1) + ) + ) + ) +) + diff --git a/test/passes/memory-packing.txt b/test/passes/memory-packing.txt index 6f67f9dcbdd..4de12f82578 100644 --- a/test/passes/memory-packing.txt +++ b/test/passes/memory-packing.txt @@ -1,6 +1,6 @@ (module (import "env" "memory" (memory $0 2048 2048)) - (import "env" "memoryBase" (global $memoryBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) (data (get_global $memoryBase) "waka this cannot be optimized\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00we don\'t know where it will go") (data (i32.const 1024) "waka this CAN be optimized") (data (i32.const 1107) "we DO know where it will go") @@ -12,9 +12,9 @@ ) (module (import "env" "memory" (memory $0 2048 2048)) - (import "env" "memoryBase" (global $memoryBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) ) (module (import "env" "memory" (memory $0 2048 2048)) - (import "env" "memoryBase" (global $memoryBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) ) diff --git a/test/use-import-and-drop.fromasm b/test/use-import-and-drop.fromasm index 52de2289531..70428eb64d0 100644 --- a/test/use-import-and-drop.fromasm +++ b/test/use-import-and-drop.fromasm @@ -1,5 +1,5 @@ (module (import "env" "memory" (memory $0 256 256)) - (import "env" "memoryBase" (global $memoryBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) (data (get_global $memoryBase) "use-import-and-drop.asm.js") ) diff --git a/test/use-import-and-drop.fromasm.clamp b/test/use-import-and-drop.fromasm.clamp index 52de2289531..70428eb64d0 100644 --- a/test/use-import-and-drop.fromasm.clamp +++ b/test/use-import-and-drop.fromasm.clamp @@ -1,5 +1,5 @@ (module (import "env" "memory" (memory $0 256 256)) - (import "env" "memoryBase" (global $memoryBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) (data (get_global $memoryBase) "use-import-and-drop.asm.js") ) diff --git a/test/use-import-and-drop.fromasm.clamp.no-opts b/test/use-import-and-drop.fromasm.clamp.no-opts index 90d0cc9f13d..be2d8a7525d 100644 --- a/test/use-import-and-drop.fromasm.clamp.no-opts +++ b/test/use-import-and-drop.fromasm.clamp.no-opts @@ -2,7 +2,7 @@ (type $FUNCSIG$vi (func (param i32))) (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 0 0 anyfunc)) - (import "env" "memoryBase" (global $memoryBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) (import "env" "tableBase" (global $tableBase i32)) (import "env" "setTempRet0" (func $setTempRet0 (param i32))) (func $test1 (; 1 ;) (result i32) diff --git a/test/use-import-and-drop.fromasm.imprecise.no-opts b/test/use-import-and-drop.fromasm.imprecise.no-opts index 90d0cc9f13d..be2d8a7525d 100644 --- a/test/use-import-and-drop.fromasm.imprecise.no-opts +++ b/test/use-import-and-drop.fromasm.imprecise.no-opts @@ -2,7 +2,7 @@ (type $FUNCSIG$vi (func (param i32))) (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 0 0 anyfunc)) - (import "env" "memoryBase" (global $memoryBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) (import "env" "tableBase" (global $tableBase i32)) (import "env" "setTempRet0" (func $setTempRet0 (param i32))) (func $test1 (; 1 ;) (result i32) diff --git a/test/use-import-and-drop.fromasm.no-opts b/test/use-import-and-drop.fromasm.no-opts index 90d0cc9f13d..be2d8a7525d 100644 --- a/test/use-import-and-drop.fromasm.no-opts +++ b/test/use-import-and-drop.fromasm.no-opts @@ -2,7 +2,7 @@ (type $FUNCSIG$vi (func (param i32))) (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 0 0 anyfunc)) - (import "env" "memoryBase" (global $memoryBase i32)) + (import "env" "memoryBase" (global $memoryBase (mut i32))) (import "env" "tableBase" (global $tableBase i32)) (import "env" "setTempRet0" (func $setTempRet0 (param i32))) (func $test1 (; 1 ;) (result i32)