summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tools/tool-options.h1
-rw-r--r--src/wasm-binary.h1
-rw-r--r--src/wasm-features.h9
-rw-r--r--src/wasm/wasm-binary.cpp4
-rw-r--r--src/wasm/wasm-validator.cpp6
-rw-r--r--src/wasm/wasm.cpp1
-rw-r--r--test/binaryen.js/kitchen-sink.js.txt2
-rw-r--r--test/example/c-api-kitchen-sink.txt2
-rw-r--r--test/lit/help/wasm-as.test4
-rw-r--r--test/lit/help/wasm-ctor-eval.test4
-rw-r--r--test/lit/help/wasm-dis.test4
-rw-r--r--test/lit/help/wasm-emscripten-finalize.test4
-rw-r--r--test/lit/help/wasm-metadce.test4
-rw-r--r--test/lit/help/wasm-opt.test4
-rw-r--r--test/lit/help/wasm-reduce.test4
-rw-r--r--test/lit/help/wasm-split.test4
-rw-r--r--test/lit/help/wasm2js.test4
-rw-r--r--test/passes/strip-target-features_roundtrip_print-features_all-features.txt1
-rw-r--r--test/unit/test_features.py1
19 files changed, 60 insertions, 4 deletions
diff --git a/src/tools/tool-options.h b/src/tools/tool-options.h
index 320cd6ba1..0cc1722a7 100644
--- a/src/tools/tool-options.h
+++ b/src/tools/tool-options.h
@@ -95,6 +95,7 @@ struct ToolOptions : public Options {
.addFeature(FeatureSet::RelaxedSIMD, "relaxed SIMD")
.addFeature(FeatureSet::ExtendedConst, "extended const expressions")
.addFeature(FeatureSet::Strings, "strings")
+ .addFeature(FeatureSet::MultiMemories, "multi-memories")
.add("--no-validation",
"-n",
"Disables validation, assumes inputs are correct",
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index c229e4666..e787baa9d 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -438,6 +438,7 @@ extern const char* TypedFunctionReferencesFeature;
extern const char* RelaxedSIMDFeature;
extern const char* ExtendedConstFeature;
extern const char* StringsFeature;
+extern const char* MultiMemoriesFeature;
enum Subsection {
NameModule = 0,
diff --git a/src/wasm-features.h b/src/wasm-features.h
index 10e4ac4c7..4b3f7c85a 100644
--- a/src/wasm-features.h
+++ b/src/wasm-features.h
@@ -44,11 +44,12 @@ struct FeatureSet {
RelaxedSIMD = 1 << 14,
ExtendedConst = 1 << 15,
Strings = 1 << 16,
+ MultiMemories = 1 << 17,
// GCNNLocals are opt-in: merely asking for "All" does not apply them. To
// get all possible values use AllPossible. See setAll() below for more
// details.
- All = ((1 << 17) - 1) & ~GCNNLocals,
- AllPossible = (1 << 17) - 1,
+ All = ((1 << 18) - 1) & ~GCNNLocals,
+ AllPossible = (1 << 18) - 1,
};
static std::string toString(Feature f) {
@@ -87,6 +88,8 @@ struct FeatureSet {
return "extended-const";
case Strings:
return "strings";
+ case MultiMemories:
+ return "multi-memories";
default:
WASM_UNREACHABLE("unexpected feature");
}
@@ -134,6 +137,7 @@ struct FeatureSet {
bool hasRelaxedSIMD() const { return (features & RelaxedSIMD) != 0; }
bool hasExtendedConst() const { return (features & ExtendedConst) != 0; }
bool hasStrings() const { return (features & Strings) != 0; }
+ bool hasMultiMemories() const { return (features & MultiMemories) != 0; }
bool hasAll() const { return (features & AllPossible) != 0; }
void set(FeatureSet f, bool v = true) {
@@ -158,6 +162,7 @@ struct FeatureSet {
void setRelaxedSIMD(bool v = true) { set(RelaxedSIMD, v); }
void setExtendedConst(bool v = true) { set(ExtendedConst, v); }
void setStrings(bool v = true) { set(Strings, v); }
+ void setMultiMemories(bool v = true) { set(MultiMemories, v); }
void setMVP() { features = MVP; }
void setAll() {
// Do not set GCNNLocals, which forces the user to opt in to that feature
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 0a5933baf..f8f3d9fbe 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -1202,6 +1202,8 @@ void WasmBinaryWriter::writeFeaturesSection() {
return BinaryConsts::UserSections::ExtendedConstFeature;
case FeatureSet::Strings:
return BinaryConsts::UserSections::StringsFeature;
+ case FeatureSet::MultiMemories:
+ return BinaryConsts::UserSections::MultiMemoriesFeature;
default:
WASM_UNREACHABLE("unexpected feature flag");
}
@@ -3534,6 +3536,8 @@ void WasmBinaryBuilder::readFeatures(size_t payloadLen) {
feature = FeatureSet::ExtendedConst;
} else if (name == BinaryConsts::UserSections::StringsFeature) {
feature = FeatureSet::Strings;
+ } else if (name == BinaryConsts::UserSections::MultiMemoriesFeature) {
+ feature = FeatureSet::MultiMemories;
} else {
// Silently ignore unknown features (this may be and old binaryen running
// on a new wasm).
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index 4fdae0bb6..532529d2a 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -3048,6 +3048,12 @@ static void validateGlobals(Module& module, ValidationInfo& info) {
}
static void validateMemories(Module& module, ValidationInfo& info) {
+ if (module.memories.size() > 1) {
+ info.shouldBeTrue(
+ module.features.hasMultiMemories(),
+ "memory",
+ "multiple memories present, but multi-memories is disabled");
+ }
for (auto& memory : module.memories) {
info.shouldBeFalse(
memory->initial > memory->max, "memory", "memory max >= initial");
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index 20d1b643e..8226e9079 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -51,6 +51,7 @@ const char* TypedFunctionReferencesFeature = "typed-function-references";
const char* RelaxedSIMDFeature = "relaxed-simd";
const char* ExtendedConstFeature = "extended-const";
const char* StringsFeature = "strings";
+const char* MultiMemoriesFeature = "multi-memories";
} // namespace UserSections
} // namespace BinaryConsts
diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt
index 3e5f9afb0..de3510545 100644
--- a/test/binaryen.js/kitchen-sink.js.txt
+++ b/test/binaryen.js/kitchen-sink.js.txt
@@ -33,7 +33,7 @@ Features.TypedFunctionReferences: 4096
Features.RelaxedSIMD: 16384
Features.ExtendedConst: 32768
Features.Strings: 65536
-Features.All: 122879
+Features.All: 253951
InvalidId: 0
BlockId: 1
IfId: 2
diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt
index 31a6875bb..82c917067 100644
--- a/test/example/c-api-kitchen-sink.txt
+++ b/test/example/c-api-kitchen-sink.txt
@@ -45,7 +45,7 @@ BinaryenFeatureMemory64: 2048
BinaryenFeatureTypedFunctionReferences: 4096
BinaryenFeatureRelaxedSIMD: 16384
BinaryenFeatureExtendedConst: 32768
-BinaryenFeatureAll: 122879
+BinaryenFeatureAll: 253951
(f32.neg
(f32.const -33.61199951171875)
)
diff --git a/test/lit/help/wasm-as.test b/test/lit/help/wasm-as.test
index 35c621056..320fcee2b 100644
--- a/test/lit/help/wasm-as.test
+++ b/test/lit/help/wasm-as.test
@@ -108,6 +108,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-strings Disable strings
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-multi-memories Enable multi-memories
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-multi-memories Disable multi-memories
+;; CHECK-NEXT:
;; CHECK-NEXT: --no-validation,-n Disables validation, assumes inputs are
;; CHECK-NEXT: correct
;; CHECK-NEXT:
diff --git a/test/lit/help/wasm-ctor-eval.test b/test/lit/help/wasm-ctor-eval.test
index 43e551451..c8998d1e8 100644
--- a/test/lit/help/wasm-ctor-eval.test
+++ b/test/lit/help/wasm-ctor-eval.test
@@ -112,6 +112,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-strings Disable strings
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-multi-memories Enable multi-memories
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-multi-memories Disable multi-memories
+;; CHECK-NEXT:
;; CHECK-NEXT: --no-validation,-n Disables validation, assumes inputs are
;; CHECK-NEXT: correct
;; CHECK-NEXT:
diff --git a/test/lit/help/wasm-dis.test b/test/lit/help/wasm-dis.test
index 195554c65..cf16f94e8 100644
--- a/test/lit/help/wasm-dis.test
+++ b/test/lit/help/wasm-dis.test
@@ -101,6 +101,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-strings Disable strings
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-multi-memories Enable multi-memories
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-multi-memories Disable multi-memories
+;; CHECK-NEXT:
;; CHECK-NEXT: --no-validation,-n Disables validation, assumes inputs are
;; CHECK-NEXT: correct
;; CHECK-NEXT:
diff --git a/test/lit/help/wasm-emscripten-finalize.test b/test/lit/help/wasm-emscripten-finalize.test
index 43e1652c5..4a2795ab8 100644
--- a/test/lit/help/wasm-emscripten-finalize.test
+++ b/test/lit/help/wasm-emscripten-finalize.test
@@ -148,6 +148,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-strings Disable strings
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-multi-memories Enable multi-memories
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-multi-memories Disable multi-memories
+;; CHECK-NEXT:
;; CHECK-NEXT: --no-validation,-n Disables validation, assumes inputs are
;; CHECK-NEXT: correct
;; CHECK-NEXT:
diff --git a/test/lit/help/wasm-metadce.test b/test/lit/help/wasm-metadce.test
index 8c49e3536..287d7ef17 100644
--- a/test/lit/help/wasm-metadce.test
+++ b/test/lit/help/wasm-metadce.test
@@ -149,6 +149,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-strings Disable strings
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-multi-memories Enable multi-memories
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-multi-memories Disable multi-memories
+;; CHECK-NEXT:
;; CHECK-NEXT: --no-validation,-n Disables validation, assumes inputs are
;; CHECK-NEXT: correct
;; CHECK-NEXT:
diff --git a/test/lit/help/wasm-opt.test b/test/lit/help/wasm-opt.test
index 70decf453..b2ac0c7f5 100644
--- a/test/lit/help/wasm-opt.test
+++ b/test/lit/help/wasm-opt.test
@@ -623,6 +623,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-strings Disable strings
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-multi-memories Enable multi-memories
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-multi-memories Disable multi-memories
+;; CHECK-NEXT:
;; CHECK-NEXT: --no-validation,-n Disables validation, assumes
;; CHECK-NEXT: inputs are correct
;; CHECK-NEXT:
diff --git a/test/lit/help/wasm-reduce.test b/test/lit/help/wasm-reduce.test
index 11cf0e45f..08e02a944 100644
--- a/test/lit/help/wasm-reduce.test
+++ b/test/lit/help/wasm-reduce.test
@@ -137,6 +137,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-strings Disable strings
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-multi-memories Enable multi-memories
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-multi-memories Disable multi-memories
+;; CHECK-NEXT:
;; CHECK-NEXT: --no-validation,-n Disables validation, assumes inputs are
;; CHECK-NEXT: correct
;; CHECK-NEXT:
diff --git a/test/lit/help/wasm-split.test b/test/lit/help/wasm-split.test
index 2bc015027..9a1f95099 100644
--- a/test/lit/help/wasm-split.test
+++ b/test/lit/help/wasm-split.test
@@ -201,6 +201,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-strings Disable strings
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-multi-memories Enable multi-memories
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-multi-memories Disable multi-memories
+;; CHECK-NEXT:
;; CHECK-NEXT: --no-validation,-n Disables validation, assumes inputs are
;; CHECK-NEXT: correct
;; CHECK-NEXT:
diff --git a/test/lit/help/wasm2js.test b/test/lit/help/wasm2js.test
index 54010cec5..f70f7d6ef 100644
--- a/test/lit/help/wasm2js.test
+++ b/test/lit/help/wasm2js.test
@@ -582,6 +582,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-strings Disable strings
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-multi-memories Enable multi-memories
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-multi-memories Disable multi-memories
+;; CHECK-NEXT:
;; CHECK-NEXT: --no-validation,-n Disables validation, assumes
;; CHECK-NEXT: inputs are correct
;; CHECK-NEXT:
diff --git a/test/passes/strip-target-features_roundtrip_print-features_all-features.txt b/test/passes/strip-target-features_roundtrip_print-features_all-features.txt
index 994453007..7a597a410 100644
--- a/test/passes/strip-target-features_roundtrip_print-features_all-features.txt
+++ b/test/passes/strip-target-features_roundtrip_print-features_all-features.txt
@@ -14,6 +14,7 @@
--enable-relaxed-simd
--enable-extended-const
--enable-strings
+--enable-multi-memories
(module
(type $none_=>_v128_externref (func (result v128 externref)))
(func $foo (result v128 externref)
diff --git a/test/unit/test_features.py b/test/unit/test_features.py
index 03862d4cc..a7a1ab444 100644
--- a/test/unit/test_features.py
+++ b/test/unit/test_features.py
@@ -399,4 +399,5 @@ class TargetFeaturesSectionTest(utils.BinaryenTestCase):
'--enable-relaxed-simd',
'--enable-extended-const',
'--enable-strings',
+ '--enable-multi-memories',
], p2.stdout.splitlines())