mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-06-30 23:11:41 +00:00
make unknown-unknown primary
This commit is contained in:
@ -14,7 +14,7 @@ use std::path::PathBuf;
|
|||||||
use clap::{App, Arg};
|
use clap::{App, Arg};
|
||||||
use parity_wasm::elements;
|
use parity_wasm::elements;
|
||||||
|
|
||||||
use wasm_utils::{CREATE_SYMBOL, CALL_SYMBOL, underscore_funcs};
|
use wasm_utils::{CREATE_SYMBOL, CALL_SYMBOL, MEMORY_SYMBOL, ununderscore_funcs};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
@ -125,15 +125,7 @@ fn main() {
|
|||||||
let mut module = parity_wasm::deserialize_file(&path).unwrap();
|
let mut module = parity_wasm::deserialize_file(&path).unwrap();
|
||||||
|
|
||||||
if let source::SourceTarget::Unknown = source_input.target() {
|
if let source::SourceTarget::Unknown = source_input.target() {
|
||||||
module = underscore_funcs(module);
|
module = ununderscore_funcs(module);
|
||||||
// Removes the start section for 'wasm32-unknown-unknown' target if exists
|
|
||||||
module.sections_mut().retain(|section| {
|
|
||||||
if let &elements::Section::Start(ref _a) = section {
|
|
||||||
false
|
|
||||||
} else {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(runtime_type) = matches.value_of("runtime_type") {
|
if let Some(runtime_type) = matches.value_of("runtime_type") {
|
||||||
@ -149,7 +141,10 @@ fn main() {
|
|||||||
let mut ctor_module = module.clone();
|
let mut ctor_module = module.clone();
|
||||||
|
|
||||||
if !matches.is_present("skip_optimization") {
|
if !matches.is_present("skip_optimization") {
|
||||||
wasm_utils::optimize(&mut module, vec![CALL_SYMBOL]).expect("Optimizer to finish without errors");
|
wasm_utils::optimize(
|
||||||
|
&mut module,
|
||||||
|
vec![CALL_SYMBOL, MEMORY_SYMBOL]
|
||||||
|
).expect("Optimizer to finish without errors");
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(save_raw_path) = matches.value_of("save_raw") {
|
if let Some(save_raw_path) = matches.value_of("save_raw") {
|
||||||
|
35
src/ext.rs
35
src/ext.rs
@ -49,20 +49,37 @@ pub fn externalize_mem(mut module: elements::Module) -> elements::Module {
|
|||||||
module
|
module
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn underscore_funcs(mut module: elements::Module) -> elements::Module {
|
fn foreach_public_func_name<F>(mut module: elements::Module, f: F) -> elements::Module
|
||||||
for entry in import_section(&mut module).expect("Import section to exist").entries_mut() {
|
where F: Fn(&mut String)
|
||||||
if let elements::External::Function(_) = *entry.external() {
|
{
|
||||||
entry.field_mut().insert(0, '_');
|
import_section(&mut module).map(|is| {
|
||||||
|
for entry in is.entries_mut() {
|
||||||
|
if let elements::External::Function(_) = *entry.external() {
|
||||||
|
f(entry.field_mut())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
for entry in export_section(&mut module).expect("Import section to exist").entries_mut() {
|
|
||||||
if let elements::Internal::Function(_) = *entry.internal() {
|
export_section(&mut module).map(|es| {
|
||||||
entry.field_mut().insert(0, '_');
|
for entry in es.entries_mut() {
|
||||||
|
if let elements::Internal::Function(_) = *entry.internal() {
|
||||||
|
f(entry.field_mut())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
module
|
module
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn underscore_funcs(mut module: elements::Module) -> elements::Module {
|
||||||
|
foreach_public_func_name(module, |n| n.insert(0, '_'))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn ununderscore_funcs(mut module: elements::Module) -> elements::Module {
|
||||||
|
foreach_public_func_name(module, |n| { n.remove(0); })
|
||||||
|
}
|
||||||
|
|
||||||
pub fn externalize(
|
pub fn externalize(
|
||||||
module: elements::Module,
|
module: elements::Module,
|
||||||
replaced_funcs: Vec<&str>,
|
replaced_funcs: Vec<&str>,
|
||||||
|
@ -4,8 +4,9 @@ extern crate byteorder;
|
|||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
#[macro_use] extern crate lazy_static;
|
#[macro_use] extern crate lazy_static;
|
||||||
|
|
||||||
pub static CREATE_SYMBOL: &'static str = "_deploy";
|
pub static CREATE_SYMBOL: &'static str = "deploy";
|
||||||
pub static CALL_SYMBOL: &'static str = "_call";
|
pub static CALL_SYMBOL: &'static str = "call";
|
||||||
|
pub static MEMORY_SYMBOL: &'static str = "memory";
|
||||||
|
|
||||||
pub mod rules;
|
pub mod rules;
|
||||||
|
|
||||||
@ -21,8 +22,7 @@ mod runtime_type;
|
|||||||
pub use optimizer::{optimize, Error as OptimizerError};
|
pub use optimizer::{optimize, Error as OptimizerError};
|
||||||
pub use gas::inject_gas_counter;
|
pub use gas::inject_gas_counter;
|
||||||
pub use logger::init_log;
|
pub use logger::init_log;
|
||||||
pub use ext::{externalize, externalize_mem, underscore_funcs};
|
pub use ext::{externalize, externalize_mem, underscore_funcs, ununderscore_funcs};
|
||||||
pub use pack::pack_instance;
|
pub use pack::pack_instance;
|
||||||
pub use nondeterminism_check::is_deterministic;
|
pub use nondeterminism_check::is_deterministic;
|
||||||
pub use runtime_type::inject_runtime_type;
|
pub use runtime_type::inject_runtime_type;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user