mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-05-23 12:41:34 +00:00
Merge remote-tracking branch 'origin/master' into drop-wast
This commit is contained in:
commit
b8f0b22132
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "parity-wasm"
|
||||
version = "0.35.2"
|
||||
version = "0.35.3"
|
||||
authors = ["Nikolay Volf <nikvolf@gmail.com>", "Svyatoslav Nikolsky <svyatonik@yandex.ru>", "Sergey Shulepov <s.pepyakin@gmail.com>"]
|
||||
license = "MIT/Apache-2.0"
|
||||
readme = "README.md"
|
||||
|
BIN
res/cases/v1/start_mut.wasm
Normal file
BIN
res/cases/v1/start_mut.wasm
Normal file
Binary file not shown.
24
res/cases/v1/start_mut.wast
Normal file
24
res/cases/v1/start_mut.wast
Normal file
@ -0,0 +1,24 @@
|
||||
(module
|
||||
(type $0 (func (param i32) (result i32)))
|
||||
(type $1 (func (result i32)))
|
||||
(type $2 (func))
|
||||
(import "env" "memoryBase" (global $gimport$0 i32))
|
||||
(import "env" "memory" (memory $0 256))
|
||||
(import "env" "table" (table 0 anyfunc))
|
||||
(import "env" "tableBase" (global $gimport$4 i32))
|
||||
(import "env" "_puts" (func $fimport$1 (param i32) (result i32)))
|
||||
(global $global$0 (mut i32) (i32.const 0))
|
||||
(global $global$1 (mut i32) (i32.const 0))
|
||||
(global $global$2 i32 (i32.const 0))
|
||||
(data (i32.const 13) "hello, world!")
|
||||
(export "_main" (func $0))
|
||||
(start $0)
|
||||
(func $0 (type $2)
|
||||
(drop
|
||||
(call $fimport$1
|
||||
(get_global $gimport$0)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -56,7 +56,7 @@ pub struct ExportEntry {
|
||||
}
|
||||
|
||||
impl ExportEntry {
|
||||
/// New export entry
|
||||
/// New export entry.
|
||||
pub fn new(field: String, internal: Internal) -> Self {
|
||||
ExportEntry {
|
||||
field_str: field,
|
||||
@ -64,10 +64,10 @@ impl ExportEntry {
|
||||
}
|
||||
}
|
||||
|
||||
/// Public name
|
||||
/// Public name.
|
||||
pub fn field(&self) -> &str { &self.field_str }
|
||||
|
||||
/// Public name (mutable)
|
||||
/// Public name (mutable).
|
||||
pub fn field_mut(&mut self) -> &mut String { &mut self.field_str }
|
||||
|
||||
/// Internal reference of the export entry.
|
||||
|
@ -89,12 +89,12 @@ pub struct FuncBody {
|
||||
}
|
||||
|
||||
impl FuncBody {
|
||||
/// New function body with given `locals` and `instructions`
|
||||
/// New function body with given `locals` and `instructions`.
|
||||
pub fn new(locals: Vec<Local>, instructions: Instructions) -> Self {
|
||||
FuncBody { locals: locals, instructions: instructions }
|
||||
}
|
||||
|
||||
/// List of individual instructions
|
||||
/// List of individual instructions.
|
||||
pub fn empty() -> Self {
|
||||
FuncBody { locals: Vec::new(), instructions: Instructions::empty() }
|
||||
}
|
||||
@ -103,6 +103,7 @@ impl FuncBody {
|
||||
pub fn locals(&self) -> &[Local] { &self.locals }
|
||||
|
||||
/// Instruction list of the function body. Minimal instruction list
|
||||
///
|
||||
/// is just `&[Instruction::End]`
|
||||
pub fn code(&self) -> &Instructions { &self.instructions }
|
||||
|
||||
@ -117,7 +118,6 @@ impl Deserialize for FuncBody {
|
||||
type Error = Error;
|
||||
|
||||
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
|
||||
// todo: maybe use reader.take(section_length)
|
||||
let mut body_reader = SectionReader::new(reader)?;
|
||||
let locals: Vec<Local> = CountedList::<Local>::deserialize(&mut body_reader)?.into_inner();
|
||||
|
||||
|
@ -9,7 +9,7 @@ pub struct GlobalEntry {
|
||||
}
|
||||
|
||||
impl GlobalEntry {
|
||||
/// New global entry
|
||||
/// New global entry.
|
||||
pub fn new(global_type: GlobalType, init_expr: InitExpr) -> Self {
|
||||
GlobalEntry {
|
||||
global_type: global_type,
|
||||
@ -20,9 +20,9 @@ impl GlobalEntry {
|
||||
pub fn global_type(&self) -> &GlobalType { &self.global_type }
|
||||
/// Initialization expression (instructions) for global.
|
||||
pub fn init_expr(&self) -> &InitExpr { &self.init_expr }
|
||||
/// Global type (mutable)
|
||||
/// Global type (mutable).
|
||||
pub fn global_type_mut(&mut self) -> &mut GlobalType { &mut self.global_type }
|
||||
/// Initialization expression (instructions) for global (mutable)
|
||||
/// Initialization expression (instructions) for global (mutable).
|
||||
pub fn init_expr_mut(&mut self) -> &mut InitExpr { &mut self.init_expr }
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ pub struct ResizableLimits {
|
||||
}
|
||||
|
||||
impl ResizableLimits {
|
||||
/// New memory limits definition
|
||||
/// New memory limits definition.
|
||||
pub fn new(min: u32, max: Option<u32>) -> Self {
|
||||
ResizableLimits {
|
||||
initial: min,
|
||||
@ -116,11 +116,11 @@ impl ResizableLimits {
|
||||
shared: false,
|
||||
}
|
||||
}
|
||||
/// Initial size
|
||||
/// Initial size.
|
||||
pub fn initial(&self) -> u32 { self.initial }
|
||||
/// Maximum size
|
||||
/// Maximum size.
|
||||
pub fn maximum(&self) -> Option<u32> { self.maximum }
|
||||
/// Whether or not this is a shared array buffer
|
||||
/// Whether or not this is a shared array buffer.
|
||||
pub fn shared(&self) -> bool { self.shared }
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ pub use self::reloc_section::{
|
||||
RelocSection, RelocationEntry,
|
||||
};
|
||||
|
||||
/// Deserialization from serial i/o
|
||||
/// Deserialization from serial i/o.
|
||||
pub trait Deserialize : Sized {
|
||||
/// Serialization error produced by deserialization routine.
|
||||
type Error: From<io::Error>;
|
||||
@ -82,68 +82,68 @@ pub trait Serialize {
|
||||
/// Deserialization/serialization error
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Error {
|
||||
/// Unexpected end of input
|
||||
/// Unexpected end of input.
|
||||
UnexpectedEof,
|
||||
/// Invalid magic
|
||||
/// Invalid magic.
|
||||
InvalidMagic,
|
||||
/// Unsupported version
|
||||
/// Unsupported version.
|
||||
UnsupportedVersion(u32),
|
||||
/// Inconsistence between declared and actual length
|
||||
/// Inconsistence between declared and actual length.
|
||||
InconsistentLength {
|
||||
/// Expected length of the definition
|
||||
/// Expected length of the definition.
|
||||
expected: usize,
|
||||
/// Actual length of the definition
|
||||
/// Actual length of the definition.
|
||||
actual: usize
|
||||
},
|
||||
/// Other static error
|
||||
/// Other static error.
|
||||
Other(&'static str),
|
||||
/// Other allocated error
|
||||
/// Other allocated error.
|
||||
HeapOther(String),
|
||||
/// Invalid/unknown value type declaration
|
||||
/// Invalid/unknown value type declaration.
|
||||
UnknownValueType(i8),
|
||||
/// Invalid/unknown table element type declaration
|
||||
/// Invalid/unknown table element type declaration.
|
||||
UnknownTableElementType(i8),
|
||||
/// Non-utf8 string
|
||||
/// Non-utf8 string.
|
||||
NonUtf8String,
|
||||
/// Unknown external kind code
|
||||
/// Unknown external kind code.
|
||||
UnknownExternalKind(u8),
|
||||
/// Unknown internal kind code
|
||||
/// Unknown internal kind code.
|
||||
UnknownInternalKind(u8),
|
||||
/// Unknown opcode encountered
|
||||
/// Unknown opcode encountered.
|
||||
UnknownOpcode(u8),
|
||||
/// Unknown SIMD opcode encountered
|
||||
/// Unknown SIMD opcode encountered.
|
||||
UnknownSimdOpcode(u32),
|
||||
/// Invalid VarUint1 value
|
||||
/// Invalid VarUint1 value.
|
||||
InvalidVarUint1(u8),
|
||||
/// Invalid VarInt32 value
|
||||
/// Invalid VarInt32 value.
|
||||
InvalidVarInt32,
|
||||
/// Invalid VarInt64 value
|
||||
/// Invalid VarInt64 value.
|
||||
InvalidVarInt64,
|
||||
/// Invalid VarUint32 value
|
||||
/// Invalid VarUint32 value.
|
||||
InvalidVarUint32,
|
||||
/// Invalid VarUint64 value
|
||||
/// Invalid VarUint64 value.
|
||||
InvalidVarUint64,
|
||||
/// Inconsistent metadata
|
||||
/// Inconsistent metadata.
|
||||
InconsistentMetadata,
|
||||
/// Invalid section id
|
||||
/// Invalid section id.
|
||||
InvalidSectionId(u8),
|
||||
/// Sections are out of order
|
||||
/// Sections are out of order.
|
||||
SectionsOutOfOrder,
|
||||
/// Duplicated sections
|
||||
/// Duplicated sections.
|
||||
DuplicatedSections(u8),
|
||||
/// Invalid memory reference (should be 0)
|
||||
/// Invalid memory reference (should be 0).
|
||||
InvalidMemoryReference(u8),
|
||||
/// Invalid table reference (should be 0)
|
||||
/// Invalid table reference (should be 0).
|
||||
InvalidTableReference(u8),
|
||||
/// Invalid value used for flags in limits type.
|
||||
InvalidLimitsFlags(u8),
|
||||
/// Unknown function form (should be 0x60)
|
||||
/// Unknown function form (should be 0x60).
|
||||
UnknownFunctionForm(u8),
|
||||
/// Invalid varint7 (should be in -64..63 range)
|
||||
/// Invalid varint7 (should be in -64..63 range).
|
||||
InvalidVarInt7(u8),
|
||||
/// Number of function body entries and signatures does not match
|
||||
/// Number of function body entries and signatures does not match.
|
||||
InconsistentCode,
|
||||
/// Only flags 0, 1, and 2 are accepted on segments
|
||||
/// Only flags 0, 1, and 2 are accepted on segments.
|
||||
InvalidSegmentFlags(u32),
|
||||
/// Sum of counts of locals is greater than 2^32.
|
||||
TooManyLocals,
|
||||
@ -232,7 +232,7 @@ impl From<io::Error> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
/// Unparsed part of the module/section
|
||||
/// Unparsed part of the module/section.
|
||||
pub struct Unparsed(pub Vec<u8>);
|
||||
|
||||
impl Deserialize for Unparsed {
|
||||
|
@ -61,12 +61,14 @@ impl Module {
|
||||
pub fn version(&self) -> u32 { self.version }
|
||||
|
||||
/// Sections list.
|
||||
///
|
||||
/// Each known section is optional and may appear at most once.
|
||||
pub fn sections(&self) -> &[Section] {
|
||||
&self.sections
|
||||
}
|
||||
|
||||
/// Sections list (mutable)
|
||||
/// Sections list (mutable).
|
||||
///
|
||||
/// Each known section is optional and may appear at most once.
|
||||
pub fn sections_mut(&mut self) -> &mut Vec<Section> {
|
||||
&mut self.sections
|
||||
@ -241,7 +243,34 @@ impl Module {
|
||||
None
|
||||
}
|
||||
|
||||
/// Changes the module's start section.
|
||||
pub fn set_start_section(&mut self, new_start : u32) {
|
||||
for section in self.sections_mut() {
|
||||
if let &mut Section::Start(_sect) = section {
|
||||
*section = Section::Start(new_start);
|
||||
return
|
||||
}
|
||||
}
|
||||
self.sections_mut().push(Section::Start(new_start));
|
||||
}
|
||||
|
||||
/// Removes the module's start section.
|
||||
pub fn clear_start_section(&mut self) {
|
||||
let sections = self.sections_mut();
|
||||
let mut rmidx = sections.len();
|
||||
for (index, section) in sections.iter_mut().enumerate() {
|
||||
if let Section::Start(_sect) = section {
|
||||
rmidx = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if rmidx < sections.len() {
|
||||
sections.remove(rmidx);
|
||||
}
|
||||
}
|
||||
|
||||
/// Functions signatures section reference, if any.
|
||||
///
|
||||
/// NOTE: name section is not parsed by default so `names_section` could return None even if name section exists.
|
||||
/// Call `parse_names` to parse name section
|
||||
pub fn names_section(&self) -> Option<&NameSection> {
|
||||
@ -252,6 +281,7 @@ impl Module {
|
||||
}
|
||||
|
||||
/// Functions signatures section mutable reference, if any.
|
||||
///
|
||||
/// NOTE: name section is not parsed by default so `names_section` could return None even if name section exists.
|
||||
/// Call `parse_names` to parse name section
|
||||
pub fn names_section_mut(&mut self) -> Option<&mut NameSection> {
|
||||
@ -261,7 +291,8 @@ impl Module {
|
||||
None
|
||||
}
|
||||
|
||||
/// Try to parse name section in place
|
||||
/// Try to parse name section in place/
|
||||
///
|
||||
/// Corresponding custom section with proper header will convert to name sections
|
||||
/// If some of them will fail to be decoded, Err variant is returned with the list of
|
||||
/// (index, Error) tuples of failed sections.
|
||||
@ -295,7 +326,8 @@ impl Module {
|
||||
}
|
||||
}
|
||||
|
||||
/// Try to parse reloc section in place
|
||||
/// Try to parse reloc section in place.
|
||||
///
|
||||
/// Corresponding custom section with proper header will convert to reloc sections
|
||||
/// If some of them will fail to be decoded, Err variant is returned with the list of
|
||||
/// (index, Error) tuples of failed sections.
|
||||
@ -336,7 +368,7 @@ impl Module {
|
||||
}
|
||||
}
|
||||
|
||||
/// Count imports by provided type
|
||||
/// Count imports by provided type.
|
||||
pub fn import_count(&self, count_type: ImportCountType) -> usize {
|
||||
self.import_section()
|
||||
.map(|is|
|
||||
@ -350,25 +382,25 @@ impl Module {
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
/// Query functions space
|
||||
/// Query functions space.
|
||||
pub fn functions_space(&self) -> usize {
|
||||
self.import_count(ImportCountType::Function) +
|
||||
self.function_section().map(|fs| fs.entries().len()).unwrap_or(0)
|
||||
}
|
||||
|
||||
/// Query globals space
|
||||
/// Query globals space.
|
||||
pub fn globals_space(&self) -> usize {
|
||||
self.import_count(ImportCountType::Global) +
|
||||
self.global_section().map(|gs| gs.entries().len()).unwrap_or(0)
|
||||
}
|
||||
|
||||
/// Query table space
|
||||
/// Query table space.
|
||||
pub fn table_space(&self) -> usize {
|
||||
self.import_count(ImportCountType::Table) +
|
||||
self.table_section().map(|ts| ts.entries().len()).unwrap_or(0)
|
||||
}
|
||||
|
||||
/// Query memory space
|
||||
/// Query memory space.
|
||||
pub fn memory_space(&self) -> usize {
|
||||
self.import_count(ImportCountType::Memory) +
|
||||
self.memory_section().map(|ms| ms.entries().len()).unwrap_or(0)
|
||||
@ -463,7 +495,7 @@ impl<'a> io::Read for PeekSection<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns size of the module in the provided stream
|
||||
/// Returns size of the module in the provided stream.
|
||||
pub fn peek_size(source: &[u8]) -> usize {
|
||||
if source.len() < 9 {
|
||||
return 0;
|
||||
@ -713,4 +745,14 @@ mod integration_tests {
|
||||
let module = deserialize_file("./res/cases/v1/two-mems.wasm").expect("failed to deserialize");
|
||||
assert_eq!(module.memory_space(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mut_start() {
|
||||
let mut module = deserialize_file("./res/cases/v1/start_mut.wasm").expect("failed to deserialize");
|
||||
assert_eq!(module.start_section().expect("Did not find any start section"), 1);
|
||||
module.set_start_section(0);
|
||||
assert_eq!(module.start_section().expect("Did not find any start section"), 0);
|
||||
module.clear_start_section();
|
||||
assert_eq!(None, module.start_section());
|
||||
}
|
||||
}
|
||||
|
@ -62,12 +62,13 @@ pub struct InitExpr(Vec<Instruction>);
|
||||
|
||||
impl InitExpr {
|
||||
/// New initialization expression from instruction list.
|
||||
///
|
||||
/// `code` must end with the `Instruction::End` instruction!
|
||||
pub fn new(code: Vec<Instruction>) -> Self {
|
||||
InitExpr(code)
|
||||
}
|
||||
|
||||
/// Empty expression with only `Instruction::End` instruction
|
||||
/// Empty expression with only `Instruction::End` instruction.
|
||||
pub fn empty() -> Self {
|
||||
InitExpr(vec![Instruction::End])
|
||||
}
|
||||
@ -102,7 +103,7 @@ impl Deserialize for InitExpr {
|
||||
}
|
||||
}
|
||||
|
||||
/// Instruction
|
||||
/// Instruction.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[allow(missing_docs)]
|
||||
pub enum Instruction {
|
||||
@ -561,7 +562,8 @@ impl Instruction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Is this instruction determines the termination of instruction sequence
|
||||
/// Is this instruction determines the termination of instruction sequence?
|
||||
///
|
||||
/// `true` for `Instruction::End`
|
||||
pub fn is_terminal(&self) -> bool {
|
||||
match self {
|
||||
|
@ -141,7 +141,7 @@ impl From<u64> for VarUint64 {
|
||||
}
|
||||
}
|
||||
|
||||
/// 7-bit unsigned integer, encoded in LEB128 (always 1 byte length)
|
||||
/// 7-bit unsigned integer, encoded in LEB128 (always 1 byte length).
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub struct VarUint7(u8);
|
||||
|
||||
@ -261,7 +261,7 @@ impl Serialize for Uint8 {
|
||||
}
|
||||
|
||||
|
||||
/// 32-bit signed integer, encoded in LEB128 (can be 1-5 bytes length)
|
||||
/// 32-bit signed integer, encoded in LEB128 (can be 1-5 bytes length).
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub struct VarInt32(i32);
|
||||
|
||||
@ -334,7 +334,7 @@ impl Serialize for VarInt32 {
|
||||
}
|
||||
}
|
||||
|
||||
/// 64-bit signed integer, encoded in LEB128 (can be 1-9 bytes length)
|
||||
/// 64-bit signed integer, encoded in LEB128 (can be 1-9 bytes length).
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub struct VarInt64(i64);
|
||||
|
||||
@ -406,7 +406,7 @@ impl Serialize for VarInt64 {
|
||||
}
|
||||
}
|
||||
|
||||
/// 32-bit unsigned integer, encoded in little endian
|
||||
/// 32-bit unsigned integer, encoded in little endian.
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub struct Uint32(u32);
|
||||
|
||||
@ -442,7 +442,7 @@ impl From<u32> for Uint32 {
|
||||
fn from(u: u32) -> Self { Uint32(u) }
|
||||
}
|
||||
|
||||
/// 64-bit unsigned integer, encoded in little endian
|
||||
/// 64-bit unsigned integer, encoded in little endian.
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub struct Uint64(u64);
|
||||
|
||||
@ -479,7 +479,7 @@ impl From<Uint64> for u64 {
|
||||
}
|
||||
|
||||
|
||||
/// VarUint1, 1-bit value (0/1)
|
||||
/// VarUint1, 1-bit value (0/1).
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub struct VarUint1(bool);
|
||||
|
||||
@ -545,7 +545,7 @@ impl Serialize for String {
|
||||
}
|
||||
|
||||
/// List for reading sequence of elements typed `T`, given
|
||||
/// they are preceded by length (serialized as VarUint32)
|
||||
/// they are preceded by length (serialized as VarUint32).
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CountedList<T: Deserialize>(Vec<T>);
|
||||
|
||||
@ -574,7 +574,7 @@ pub struct CountedWriter<'a, W: 'a + io::Write> {
|
||||
}
|
||||
|
||||
impl<'a, W: 'a + io::Write> CountedWriter<'a, W> {
|
||||
/// New counted writer on top of the given serial writer
|
||||
/// New counted writer on top of the given serial writer.
|
||||
pub fn new(writer: &'a mut W) -> Self {
|
||||
CountedWriter {
|
||||
writer: writer,
|
||||
@ -603,7 +603,7 @@ impl<'a, W: 'a + io::Write> io::Write for CountedWriter<'a, W> {
|
||||
}
|
||||
|
||||
/// Helper struct to write series of `T` preceded by the length of the sequence
|
||||
/// serialized as VarUint32
|
||||
/// serialized as VarUint32.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CountedListWriter<I: Serialize<Error=::elements::Error>, T: IntoIterator<Item=I>>(pub usize, pub T);
|
||||
|
||||
|
@ -35,34 +35,34 @@ const ENTRIES_BUFFER_LENGTH: usize = 16384;
|
||||
pub enum Section {
|
||||
/// Section is unparsed.
|
||||
Unparsed {
|
||||
/// id of the unparsed section
|
||||
/// id of the unparsed section.
|
||||
id: u8,
|
||||
/// raw bytes of the unparsed section
|
||||
/// raw bytes of the unparsed section.
|
||||
payload: Vec<u8>,
|
||||
},
|
||||
/// Custom section (`id=0`)
|
||||
/// Custom section (`id=0`).
|
||||
Custom(CustomSection),
|
||||
/// Types section
|
||||
/// Types section.
|
||||
Type(TypeSection),
|
||||
/// Import section
|
||||
/// Import section.
|
||||
Import(ImportSection),
|
||||
/// Function signatures section
|
||||
/// Function signatures section.
|
||||
Function(FunctionSection),
|
||||
/// Table definition section
|
||||
/// Table definition section.
|
||||
Table(TableSection),
|
||||
/// Memory definition section
|
||||
/// Memory definition section.
|
||||
Memory(MemorySection),
|
||||
/// Global entries section
|
||||
/// Global entries section.
|
||||
Global(GlobalSection),
|
||||
/// Export definitions
|
||||
/// Export definitions.
|
||||
Export(ExportSection),
|
||||
/// Entry reference of the module
|
||||
/// Entry reference of the module.
|
||||
Start(u32),
|
||||
/// Elements section
|
||||
/// Elements section.
|
||||
Element(ElementSection),
|
||||
/// Function bodies section
|
||||
/// Function bodies section.
|
||||
Code(CodeSection),
|
||||
/// Data definition section
|
||||
/// Data definition section.
|
||||
Data(DataSection),
|
||||
/// Name section.
|
||||
///
|
||||
@ -72,7 +72,7 @@ pub enum Section {
|
||||
///
|
||||
/// Note that initially it is not parsed until `parse_reloc` is called explicitly.
|
||||
/// Also note that currently there are serialization (but not de-serialization)
|
||||
/// issues with this section (#198)
|
||||
/// issues with this section (#198).
|
||||
Reloc(RelocSection),
|
||||
}
|
||||
|
||||
@ -279,7 +279,7 @@ fn read_entries<R: io::Read, T: Deserialize<Error=::elements::Error>>(reader: &m
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Custom section
|
||||
/// Custom section.
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
pub struct CustomSection {
|
||||
name: String,
|
||||
@ -287,27 +287,27 @@ pub struct CustomSection {
|
||||
}
|
||||
|
||||
impl CustomSection {
|
||||
/// Creates a new custom section with the given name and payload
|
||||
/// Creates a new custom section with the given name and payload.
|
||||
pub fn new(name: String, payload: Vec<u8>) -> CustomSection {
|
||||
CustomSection { name, payload }
|
||||
}
|
||||
|
||||
/// Name of the custom section
|
||||
/// Name of the custom section.
|
||||
pub fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
|
||||
/// Payload of the custom secion
|
||||
/// Payload of the custom secion.
|
||||
pub fn payload(&self) -> &[u8] {
|
||||
&self.payload
|
||||
}
|
||||
|
||||
/// Name of the custom section (mutable)
|
||||
/// Name of the custom section (mutable).
|
||||
pub fn name_mut(&mut self) -> &mut String {
|
||||
&mut self.name
|
||||
}
|
||||
|
||||
/// Payload of the custom section (mutable)
|
||||
/// Payload of the custom section (mutable).
|
||||
pub fn payload_mut(&mut self) -> &mut Vec<u8> {
|
||||
&mut self.payload
|
||||
}
|
||||
@ -340,22 +340,22 @@ impl Serialize for CustomSection {
|
||||
}
|
||||
}
|
||||
|
||||
/// Section with type declarations
|
||||
/// Section with type declarations.
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
pub struct TypeSection(Vec<Type>);
|
||||
|
||||
impl TypeSection {
|
||||
/// New type section with provided types
|
||||
/// New type section with provided types.
|
||||
pub fn with_types(types: Vec<Type>) -> Self {
|
||||
TypeSection(types)
|
||||
}
|
||||
|
||||
/// List of type declarations
|
||||
/// List of type declarations.
|
||||
pub fn types(&self) -> &[Type] {
|
||||
&self.0
|
||||
}
|
||||
|
||||
/// List of type declarations (mutable)
|
||||
/// List of type declarations (mutable).
|
||||
pub fn types_mut(&mut self) -> &mut Vec<Type> {
|
||||
&mut self.0
|
||||
}
|
||||
@ -390,7 +390,7 @@ impl Serialize for TypeSection {
|
||||
pub struct ImportSection(Vec<ImportEntry>);
|
||||
|
||||
impl ImportSection {
|
||||
/// New import section with provided types
|
||||
/// New import section with provided types.
|
||||
pub fn with_entries(entries: Vec<ImportEntry>) -> Self {
|
||||
ImportSection(entries)
|
||||
}
|
||||
@ -405,7 +405,7 @@ impl ImportSection {
|
||||
&mut self.0
|
||||
}
|
||||
|
||||
/// Returns number of functions
|
||||
/// Returns number of functions.
|
||||
pub fn functions(&self) -> usize {
|
||||
self.0.iter()
|
||||
.filter(|entry| match entry.external() { &External::Function(_) => true, _ => false })
|
||||
@ -449,17 +449,17 @@ impl Serialize for ImportSection {
|
||||
pub struct FunctionSection(Vec<Func>);
|
||||
|
||||
impl FunctionSection {
|
||||
/// New function signatures section with provided entries
|
||||
/// New function signatures section with provided entries.
|
||||
pub fn with_entries(entries: Vec<Func>) -> Self {
|
||||
FunctionSection(entries)
|
||||
}
|
||||
|
||||
/// List of all functions in the section, mutable
|
||||
/// List of all functions in the section, mutable.
|
||||
pub fn entries_mut(&mut self) -> &mut Vec<Func> {
|
||||
&mut self.0
|
||||
}
|
||||
|
||||
/// List of all functions in the section
|
||||
/// List of all functions in the section.
|
||||
pub fn entries(&self) -> &[Func] {
|
||||
&self.0
|
||||
}
|
||||
@ -499,7 +499,7 @@ impl TableSection {
|
||||
&self.0
|
||||
}
|
||||
|
||||
/// New table section with provided table entries
|
||||
/// New table section with provided table entries.
|
||||
pub fn with_entries(entries: Vec<TableType>) -> Self {
|
||||
TableSection(entries)
|
||||
}
|
||||
@ -544,12 +544,12 @@ impl MemorySection {
|
||||
&self.0
|
||||
}
|
||||
|
||||
/// New memory section with memory types
|
||||
/// New memory section with memory types.
|
||||
pub fn with_entries(entries: Vec<MemoryType>) -> Self {
|
||||
MemorySection(entries)
|
||||
}
|
||||
|
||||
/// Mutable list of all memory entries in the section
|
||||
/// Mutable list of all memory entries in the section.
|
||||
pub fn entries_mut(&mut self) -> &mut Vec<MemoryType> {
|
||||
&mut self.0
|
||||
}
|
||||
@ -584,17 +584,17 @@ impl Serialize for MemorySection {
|
||||
pub struct GlobalSection(Vec<GlobalEntry>);
|
||||
|
||||
impl GlobalSection {
|
||||
/// List of all global entries in the section
|
||||
/// List of all global entries in the section.
|
||||
pub fn entries(&self) -> &[GlobalEntry] {
|
||||
&self.0
|
||||
}
|
||||
|
||||
/// New global section from list of global entries
|
||||
/// New global section from list of global entries.
|
||||
pub fn with_entries(entries: Vec<GlobalEntry>) -> Self {
|
||||
GlobalSection(entries)
|
||||
}
|
||||
|
||||
/// List of all global entries in the section (mutable)
|
||||
/// List of all global entries in the section (mutable).
|
||||
pub fn entries_mut(&mut self) -> &mut Vec<GlobalEntry> {
|
||||
&mut self.0
|
||||
}
|
||||
@ -629,17 +629,17 @@ impl Serialize for GlobalSection {
|
||||
pub struct ExportSection(Vec<ExportEntry>);
|
||||
|
||||
impl ExportSection {
|
||||
/// List of all export entries in the section
|
||||
/// List of all export entries in the section.
|
||||
pub fn entries(&self) -> &[ExportEntry] {
|
||||
&self.0
|
||||
}
|
||||
|
||||
/// New export section from list of export entries
|
||||
/// New export section from list of export entries.
|
||||
pub fn with_entries(entries: Vec<ExportEntry>) -> Self {
|
||||
ExportSection(entries)
|
||||
}
|
||||
|
||||
/// List of all export entries in the section (mutable)
|
||||
/// List of all export entries in the section (mutable).
|
||||
pub fn entries_mut(&mut self) -> &mut Vec<ExportEntry> {
|
||||
&mut self.0
|
||||
}
|
||||
@ -674,7 +674,7 @@ impl Serialize for ExportSection {
|
||||
pub struct CodeSection(Vec<FuncBody>);
|
||||
|
||||
impl CodeSection {
|
||||
/// New code section with specified function bodies
|
||||
/// New code section with specified function bodies.
|
||||
pub fn with_bodies(bodies: Vec<FuncBody>) -> Self {
|
||||
CodeSection(bodies)
|
||||
}
|
||||
@ -719,17 +719,17 @@ impl Serialize for CodeSection {
|
||||
pub struct ElementSection(Vec<ElementSegment>);
|
||||
|
||||
impl ElementSection {
|
||||
/// New elements section
|
||||
/// New elements section.
|
||||
pub fn with_entries(entries: Vec<ElementSegment>) -> Self {
|
||||
ElementSection(entries)
|
||||
}
|
||||
|
||||
/// New elements entries in the section
|
||||
/// New elements entries in the section.
|
||||
pub fn entries(&self) -> &[ElementSegment] {
|
||||
&self.0
|
||||
}
|
||||
|
||||
/// List of all data entries in the section (mutable)
|
||||
/// List of all data entries in the section (mutable).
|
||||
pub fn entries_mut(&mut self) -> &mut Vec<ElementSegment> {
|
||||
&mut self.0
|
||||
}
|
||||
@ -764,17 +764,17 @@ impl Serialize for ElementSection {
|
||||
pub struct DataSection(Vec<DataSegment>);
|
||||
|
||||
impl DataSection {
|
||||
/// New data section
|
||||
/// New data section.
|
||||
pub fn with_entries(entries: Vec<DataSegment>) -> Self {
|
||||
DataSection(entries)
|
||||
}
|
||||
|
||||
/// List of all data entries in the section
|
||||
/// List of all data entries in the section.
|
||||
pub fn entries(&self) -> &[DataSegment] {
|
||||
&self.0
|
||||
}
|
||||
|
||||
/// List of all data entries in the section (mutable)
|
||||
/// List of all data entries in the section (mutable).
|
||||
pub fn entries_mut(&mut self) -> &mut Vec<DataSegment> {
|
||||
&mut self.0
|
||||
}
|
||||
|
@ -143,10 +143,10 @@ impl DataSegment {
|
||||
/// Initial value of the data segment (mutable).
|
||||
pub fn value_mut(&mut self) -> &mut Vec<u8> { &mut self.value }
|
||||
|
||||
/// Whether or not this data segment is "passive"
|
||||
/// Whether or not this data segment is "passive".
|
||||
pub fn passive(&self) -> bool { self.passive }
|
||||
|
||||
/// Whether or not this data segment is "passive" (mutable)
|
||||
/// Whether or not this data segment is "passive" (mutable).
|
||||
pub fn passive_mut(&mut self) -> &mut bool { &mut self.passive }
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user