mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-14 07:21:42 +00:00
move func to mod
This commit is contained in:
@ -10,9 +10,8 @@ use super::{
|
||||
MemoryType,
|
||||
TableType,
|
||||
ExportEntry,
|
||||
Opcodes,
|
||||
ValueType,
|
||||
GlobalEntry,
|
||||
FuncBody,
|
||||
};
|
||||
|
||||
use super::types::Type;
|
||||
@ -231,10 +230,10 @@ impl Deserialize for ExportSection {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CodeSection(Vec<FunctionBody>);
|
||||
pub struct CodeSection(Vec<FuncBody>);
|
||||
|
||||
impl CodeSection {
|
||||
pub fn bodies(&self) -> &[FunctionBody] {
|
||||
pub fn bodies(&self) -> &[FuncBody] {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
@ -245,53 +244,11 @@ impl Deserialize for CodeSection {
|
||||
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 entries: Vec<FunctionBody> = CountedList::deserialize(reader)?.into_inner();
|
||||
let entries: Vec<FuncBody> = CountedList::deserialize(reader)?.into_inner();
|
||||
Ok(CodeSection(entries))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Local {
|
||||
count: u32,
|
||||
value_type: ValueType,
|
||||
}
|
||||
|
||||
impl Local {
|
||||
pub fn count(&self) -> u32 { self.count }
|
||||
pub fn value_type(&self) -> ValueType { self.value_type }
|
||||
}
|
||||
|
||||
impl Deserialize for Local {
|
||||
type Error = Error;
|
||||
|
||||
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
|
||||
let count = VarUint32::deserialize(reader)?;
|
||||
let value_type = ValueType::deserialize(reader)?;
|
||||
Ok(Local { count: count.into(), value_type: value_type })
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FunctionBody {
|
||||
locals: Vec<Local>,
|
||||
opcodes: Opcodes,
|
||||
}
|
||||
|
||||
impl FunctionBody {
|
||||
pub fn locals(&self) -> &[Local] { &self.locals }
|
||||
pub fn code(&self) -> &Opcodes { &self.opcodes }
|
||||
}
|
||||
|
||||
impl Deserialize for FunctionBody {
|
||||
type Error = Error;
|
||||
|
||||
fn deserialize<R: io::Read>(reader: &mut R) -> Result<Self, Self::Error> {
|
||||
// todo: maybe use reader.take(section_length)
|
||||
let _body_size = VarUint32::deserialize(reader)?;
|
||||
let locals: Vec<Local> = CountedList::deserialize(reader)?.into_inner();
|
||||
let opcodes = Opcodes::deserialize(reader)?;
|
||||
Ok(FunctionBody { locals: locals, opcodes: opcodes })
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
|
Reference in New Issue
Block a user