From d60340762b216a82a942cfb0fb952e72ec6fb7f3 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Tue, 22 Jan 2019 18:28:15 +0300 Subject: [PATCH] public api exposure and fix warnings --- src/graph.rs | 92 ++++++++++++++++++++++++------------------------- src/lib.rs | 2 ++ src/ref_list.rs | 7 ++-- 3 files changed, 49 insertions(+), 52 deletions(-) diff --git a/src/graph.rs b/src/graph.rs index cabed75..ba48e98 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -7,7 +7,7 @@ use std::borrow::ToOwned; use std::string::String; use std::collections::BTreeMap; -enum ImportedOrDeclared { +pub enum ImportedOrDeclared { Imported(String, String), Declared(T), } @@ -18,82 +18,82 @@ impl From<&elements::ImportEntry> for ImportedOrDeclared { } } -type FuncOrigin = ImportedOrDeclared>; -type GlobalOrigin = ImportedOrDeclared>; -type MemoryOrigin = ImportedOrDeclared; -type TableOrigin = ImportedOrDeclared; +pub type FuncOrigin = ImportedOrDeclared>; +pub type GlobalOrigin = ImportedOrDeclared>; +pub type MemoryOrigin = ImportedOrDeclared; +pub type TableOrigin = ImportedOrDeclared; -struct Func { - type_ref: EntryRef, - origin: FuncOrigin, +pub struct Func { + pub type_ref: EntryRef, + pub origin: FuncOrigin, } -struct Global { - content: elements::ValueType, - is_mut: bool, - origin: GlobalOrigin, +pub struct Global { + pub content: elements::ValueType, + pub is_mut: bool, + pub origin: GlobalOrigin, } -enum Instruction { +pub enum Instruction { Plain(elements::Instruction), Call(EntryRef), } -struct Memory { - limits: elements::ResizableLimits, - origin: MemoryOrigin, +pub struct Memory { + pub limits: elements::ResizableLimits, + pub origin: MemoryOrigin, } -struct Table { - origin: TableOrigin, - limits: elements::ResizableLimits, +pub struct Table { + pub origin: TableOrigin, + pub limits: elements::ResizableLimits, } -enum SegmentLocation { +pub enum SegmentLocation { Passive, Default(Vec), WithIndex(u32, Vec), } -struct DataSegment { - location: SegmentLocation, - value: Vec, +pub struct DataSegment { + pub location: SegmentLocation, + pub value: Vec, } -struct ElementSegment { - location: SegmentLocation, - value: Vec, +pub struct ElementSegment { + pub location: SegmentLocation, + pub value: Vec, } -enum ExportLocal { +pub enum ExportLocal { Func(EntryRef), Global(EntryRef), Table(EntryRef), Memory(EntryRef), } -struct Export { - name: String, - local: ExportLocal, +pub struct Export { + pub name: String, + pub local: ExportLocal, } #[derive(Default)] -struct Module { - types: RefList, - funcs: RefList, - memory: RefList, - tables: RefList
, - globals: RefList, - start: Option>, - exports: Vec, - elements: Vec, - data: Vec, - other: BTreeMap, +pub struct Module { + pub types: RefList, + pub funcs: RefList, + pub memory: RefList, + pub tables: RefList
, + pub globals: RefList, + pub start: Option>, + pub exports: Vec, + pub elements: Vec, + pub data: Vec, + pub other: BTreeMap, } impl Module { - fn from_elements(module: &elements::Module) -> Self { + pub fn from_elements(module: &elements::Module) -> Self { let mut idx = 0; let mut res = Module::default(); @@ -469,7 +469,6 @@ impl Module { ExportLocal::Memory(ref memory_ref) => { elements::Internal::Memory(memory_ref.order().expect("detached memory ref") as u32) }, - _ => continue, }; exports.push(elements::ExportEntry::new(export.name.to_owned(), internal)); @@ -521,7 +520,7 @@ impl Module { // CODE SECTION (10) let mut code_section = elements::CodeSection::default(); { - let mut funcs = code_section.bodies_mut(); + let funcs = code_section.bodies_mut(); for func in self.funcs.iter() { match func.read().origin { @@ -587,11 +586,11 @@ fn custom_round( } } -fn parse(wasm: &[u8]) -> Module { +pub fn parse(wasm: &[u8]) -> Module { Module::from_elements(&::parity_wasm::deserialize_buffer(wasm).expect("failed to parse wasm")) } -fn generate(f: &Module) -> Vec { +pub fn generate(f: &Module) -> Vec { let pm = f.generate(); ::parity_wasm::serialize(pm).expect("failed to generate wasm") } @@ -600,7 +599,6 @@ fn generate(f: &Module) -> Vec { mod tests { extern crate wabt; - use parity_wasm; #[test] fn smoky() { diff --git a/src/lib.rs b/src/lib.rs index 244fb50..2ab34dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,6 +29,8 @@ pub use gas::inject_gas_counter; pub use ext::{externalize, externalize_mem, underscore_funcs, ununderscore_funcs, shrink_unknown_stack}; pub use pack::{pack_instance, Error as PackingError}; pub use runtime_type::inject_runtime_type; +pub use graph::{Module, parse, generate}; +pub use ref_list::{RefList, Entry, EntryRef, DeleteTransaction}; pub struct TargetRuntime { pub create_symbol: &'static str, diff --git a/src/ref_list.rs b/src/ref_list.rs index 82d04d9..df10547 100644 --- a/src/ref_list.rs +++ b/src/ref_list.rs @@ -110,9 +110,6 @@ impl RefList { } fn done_delete(&mut self, indices: &[usize]) { - - let mut index = 0; - for idx in indices { let mut detached = self.items.remove(*idx); detached.write().index = EntryOrigin::Detached; @@ -174,13 +171,13 @@ pub struct DeleteTransaction<'a, T> { } impl<'a, T> DeleteTransaction<'a, T> { - pub fn push(mut self, idx: usize) -> Self { + pub fn push(self, idx: usize) -> Self { let mut tx = self; tx.deleted.push(idx); tx } - pub fn done(mut self) { + pub fn done(self) { let indices = self.deleted; let list = self.list; list.done_delete(&indices[..]);