mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-05-29 23:51:35 +00:00
function signatures
This commit is contained in:
parent
779f3257cd
commit
054e9d71e2
@ -19,6 +19,9 @@ fn main() {
|
|||||||
&Section::Import(ref import_section) => {
|
&Section::Import(ref import_section) => {
|
||||||
println!("Imports {}", import_section.entries().len());
|
println!("Imports {}", import_section.entries().len());
|
||||||
},
|
},
|
||||||
|
&Section::Function(ref functions_section) => {
|
||||||
|
println!("Functions {}", functions_section.entries().len());
|
||||||
|
},
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,12 +45,8 @@ impl Deserialize for Module {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod integration_tests {
|
mod integration_tests {
|
||||||
|
|
||||||
use std::io::{self, Read};
|
use super::super::deserialize_file;
|
||||||
use std::fs::File;
|
|
||||||
|
|
||||||
use super::super::{Deserialize, deserialize_file};
|
|
||||||
use super::Module;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn hello() {
|
fn hello() {
|
||||||
let module = deserialize_file("./res/cases/v1/hello.wasm").expect("Should be deserialized");
|
let module = deserialize_file("./res/cases/v1/hello.wasm").expect("Should be deserialized");
|
||||||
|
@ -10,6 +10,7 @@ pub enum Section {
|
|||||||
Custom(Vec<u8>),
|
Custom(Vec<u8>),
|
||||||
Type(TypeSection),
|
Type(TypeSection),
|
||||||
Import(ImportSection),
|
Import(ImportSection),
|
||||||
|
Function(FunctionsSection),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deserialize for Section {
|
impl Deserialize for Section {
|
||||||
@ -33,6 +34,9 @@ impl Deserialize for Section {
|
|||||||
2 => {
|
2 => {
|
||||||
Section::Import(ImportSection::deserialize(reader)?)
|
Section::Import(ImportSection::deserialize(reader)?)
|
||||||
},
|
},
|
||||||
|
3 => {
|
||||||
|
Section::Function(FunctionsSection::deserialize(reader)?)
|
||||||
|
},
|
||||||
_ => {
|
_ => {
|
||||||
Section::Unparsed { id: id.into(), payload: Unparsed::deserialize(reader)?.into() }
|
Section::Unparsed { id: id.into(), payload: Unparsed::deserialize(reader)?.into() }
|
||||||
}
|
}
|
||||||
@ -79,6 +83,33 @@ impl Deserialize for ImportSection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Function signature (type reference)
|
||||||
|
pub struct Function(pub u32);
|
||||||
|
|
||||||
|
pub struct FunctionsSection(Vec<Function>);
|
||||||
|
|
||||||
|
impl FunctionsSection {
|
||||||
|
pub fn entries(&self) -> &[Function] {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deserialize for FunctionsSection {
|
||||||
|
type Error = Error;
|
||||||
|
|
||||||
|
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
|
||||||
|
// todo: maybe use reader.take(section_length)
|
||||||
|
let _section_length = VarUint32::deserialize(reader)?;
|
||||||
|
let funcs: Vec<Function> = CountedList::<VarUint32>::deserialize(reader)?
|
||||||
|
.into_inner()
|
||||||
|
.into_iter()
|
||||||
|
.map(|f| Function(f.into()))
|
||||||
|
.collect();
|
||||||
|
Ok(FunctionsSection(funcs))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
@ -121,8 +152,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(type_section.types().len(), 1);
|
assert_eq!(type_section.types().len(), 1);
|
||||||
match type_section.types()[0] {
|
match type_section.types()[0] {
|
||||||
Type::Function(_) => {},
|
Type::Function(_) => {}
|
||||||
_ => panic!("Type should be a function")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user