summaryrefslogtreecommitdiffstats
path: root/third_party/rust/wasm-encoder/src/core/memories.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/wasm-encoder/src/core/memories.rs')
-rw-r--r--third_party/rust/wasm-encoder/src/core/memories.rs25
1 files changed, 21 insertions, 4 deletions
diff --git a/third_party/rust/wasm-encoder/src/core/memories.rs b/third_party/rust/wasm-encoder/src/core/memories.rs
index 892545eb98..d64ef01210 100644
--- a/third_party/rust/wasm-encoder/src/core/memories.rs
+++ b/third_party/rust/wasm-encoder/src/core/memories.rs
@@ -15,6 +15,7 @@ use crate::{encode_section, Encode, Section, SectionId};
/// maximum: None,
/// memory64: false,
/// shared: false,
+/// page_size_log2: None,
/// });
///
/// let mut module = Module::new();
@@ -75,26 +76,41 @@ pub struct MemoryType {
pub memory64: bool,
/// Whether or not this memory is shared.
pub shared: bool,
+ /// The log base 2 of a custom page size for this memory.
+ ///
+ /// The default page size for Wasm memories is 64KiB, i.e. 2<sup>16</sup> or
+ /// `65536`.
+ ///
+ /// After the introduction of [the custom-page-sizes
+ /// proposal](https://github.com/WebAssembly/custom-page-sizes), Wasm can
+ /// customize the page size. It must be a power of two that is less than or
+ /// equal to 64KiB. Attempting to encode an invalid page size may panic.
+ pub page_size_log2: Option<u32>,
}
impl Encode for MemoryType {
fn encode(&self, sink: &mut Vec<u8>) {
let mut flags = 0;
if self.maximum.is_some() {
- flags |= 0b001;
+ flags |= 0b0001;
}
if self.shared {
- flags |= 0b010;
+ flags |= 0b0010;
}
if self.memory64 {
- flags |= 0b100;
+ flags |= 0b0100;
+ }
+ if self.page_size_log2.is_some() {
+ flags |= 0b1000;
}
-
sink.push(flags);
self.minimum.encode(sink);
if let Some(max) = self.maximum {
max.encode(sink);
}
+ if let Some(p) = self.page_size_log2 {
+ p.encode(sink);
+ }
}
}
@@ -106,6 +122,7 @@ impl From<wasmparser::MemoryType> for MemoryType {
maximum: memory_ty.maximum,
memory64: memory_ty.memory64,
shared: memory_ty.shared,
+ page_size_log2: memory_ty.page_size_log2,
}
}
}