wasm-utils/src/lib.rs

81 lines
1.6 KiB
Rust
Raw Normal View History

2018-05-15 08:22:29 +08:00
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]
#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc;
2017-09-25 20:14:46 +03:00
extern crate byteorder;
extern crate parity_wasm;
#[macro_use]
extern crate log;
2017-05-04 15:59:22 +03:00
2017-07-27 13:38:21 +03:00
pub mod rules;
mod build;
2017-05-05 16:05:21 +03:00
mod ext;
mod gas;
mod optimizer;
mod pack;
2017-09-25 20:14:46 +03:00
mod runtime_type;
mod symbols;
2017-05-04 16:08:57 +03:00
pub mod stack_height;
pub use build::{build, Error as BuildError, SourceTarget};
pub use ext::{
externalize, externalize_mem, shrink_unknown_stack, underscore_funcs, ununderscore_funcs,
};
2017-05-05 15:51:08 +03:00
pub use gas::inject_gas_counter;
pub use optimizer::{optimize, Error as OptimizerError};
2018-03-27 17:11:00 +03:00
pub use pack::{pack_instance, Error as PackingError};
2017-09-25 20:14:46 +03:00
pub use runtime_type::inject_runtime_type;
2018-05-15 08:22:29 +08:00
pub struct TargetSymbols {
pub create: &'static str,
pub call: &'static str,
pub return_: &'static str,
}
pub enum TargetRuntime {
Substrate(TargetSymbols),
PWasm(TargetSymbols),
2018-09-30 18:24:36 +01:00
}
impl TargetRuntime {
pub fn substrate() -> TargetRuntime {
TargetRuntime::Substrate(TargetSymbols {
create: "deploy",
call: "call",
return_: "ext_return",
})
}
pub fn pwasm() -> TargetRuntime {
TargetRuntime::PWasm(TargetSymbols {
create: "deploy",
call: "call",
return_: "ret",
})
}
pub fn symbols(&self) -> &TargetSymbols {
match self {
TargetRuntime::Substrate(s) => s,
TargetRuntime::PWasm(s) => s,
2018-09-30 18:24:36 +01:00
}
}
2018-09-30 18:24:36 +01:00
}
2018-05-15 08:22:29 +08:00
#[cfg(not(feature = "std"))]
mod std {
pub use alloc::{borrow, boxed, string, vec};
pub use core::*;
2018-05-15 08:22:29 +08:00
pub mod collections {
pub use alloc::collections::{BTreeMap, BTreeSet};
}
2018-05-15 08:22:29 +08:00
}