diff options
author | Ashley Nelson <nashley@google.com> | 2022-08-25 13:35:46 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-25 13:35:46 -0700 |
commit | 8b81405778eb85fccbfdbe789beeba5108cf1021 (patch) | |
tree | 0263c08a9453021cb30712a199d9b8917e944fa6 /src | |
parent | 37b457a00a46e5604b2a8a388efaf0813b3d1170 (diff) | |
download | binaryen-8b81405778eb85fccbfdbe789beeba5108cf1021.tar.gz binaryen-8b81405778eb85fccbfdbe789beeba5108cf1021.tar.bz2 binaryen-8b81405778eb85fccbfdbe789beeba5108cf1021.zip |
Adding Multi-Memories Wasm Feature (#4968)
Adding multi-memories to the the list of wasm-features.
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/tool-options.h | 1 | ||||
-rw-r--r-- | src/wasm-binary.h | 1 | ||||
-rw-r--r-- | src/wasm-features.h | 9 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 4 | ||||
-rw-r--r-- | src/wasm/wasm-validator.cpp | 6 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 1 |
6 files changed, 20 insertions, 2 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 |