mirror of
https://github.com/fluencelabs/wasmer
synced 2025-07-31 07:12:10 +00:00
Remove unused code, cleanup
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
#[macro_use]
|
||||
extern crate wasmer_runtime_core;
|
||||
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use libc::c_int;
|
||||
use std::cell::UnsafeCell;
|
||||
use std::{ffi::c_void, mem, ptr};
|
||||
use std::{fmt, mem::size_of, slice};
|
||||
use std::{ffi::c_void, fmt, mem, ptr};
|
||||
use wasmer_runtime_core::{
|
||||
error::{CallResult, ResolveError},
|
||||
error::CallResult,
|
||||
export::{Context, Export, FuncPointer, GlobalPointer, MemoryPointer, TablePointer},
|
||||
import::{ImportObject, Namespace},
|
||||
instance::Instance,
|
||||
@@ -15,11 +13,7 @@ use wasmer_runtime_core::{
|
||||
module::Module,
|
||||
structures::TypedIndex,
|
||||
table::TableBacking,
|
||||
types::{
|
||||
ElementType, FuncSig, GlobalDesc, LocalMemoryIndex, Memory, Table,
|
||||
Type::{self, *},
|
||||
Value,
|
||||
},
|
||||
types::{ElementType, FuncSig, GlobalDesc, LocalMemoryIndex, Memory, Table, Type::*, Value},
|
||||
vm::Ctx,
|
||||
vm::LocalGlobal,
|
||||
vm::LocalMemory,
|
||||
@@ -163,7 +157,7 @@ pub fn run_emscripten_instance(
|
||||
|
||||
let main_func = instance.func("_main")?;
|
||||
let num_params = main_func.signature().params.len();
|
||||
let result = match num_params {
|
||||
let _result = match num_params {
|
||||
2 => {
|
||||
let (argc, argv) = store_module_arguments(path, args, instance.ctx());
|
||||
instance.call("_main", &[Value::I32(argc as i32), Value::I32(argv as i32)])?;
|
||||
@@ -202,118 +196,6 @@ fn store_module_arguments(path: &str, args: Vec<&str>, ctx: &mut Ctx) -> (u32, u
|
||||
(argc as u32, argv_offset)
|
||||
}
|
||||
|
||||
/// Passes arguments from the host to the WebAssembly instance.
|
||||
fn get_main_args(
|
||||
main_name: &str,
|
||||
args: Vec<&str>,
|
||||
instance: &mut Instance,
|
||||
) -> CallResult<Vec<Value>> {
|
||||
// Getting main function signature.
|
||||
|
||||
let func = instance.func(main_name)?;
|
||||
let func_sig = func.signature();
|
||||
let params = &func_sig.params;
|
||||
|
||||
// Check for a () or (i32, i32) sig.
|
||||
match params.as_slice() {
|
||||
&[Type::I32, Type::I32] => {
|
||||
// Copy strings into wasm memory and get addresses to them.
|
||||
let string_addresses = args
|
||||
.iter()
|
||||
.map(|string| copy_string_into_wasm(instance, (*string).to_string()).unwrap())
|
||||
.collect();
|
||||
|
||||
// Create a wasm array to the strings.
|
||||
let array = create_wasm_array(instance, string_addresses).unwrap();
|
||||
|
||||
Ok(vec![
|
||||
Value::I32(array as i32),
|
||||
Value::I32(args.len() as i32),
|
||||
])
|
||||
}
|
||||
&[] => Ok(vec![]),
|
||||
_ => Err(ResolveError::Signature {
|
||||
expected: FuncSig {
|
||||
params: vec![Type::I32, Type::I32],
|
||||
returns: vec![],
|
||||
},
|
||||
found: params.to_vec(),
|
||||
}
|
||||
.into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Copy rust string to wasm instance.
|
||||
fn copy_string_into_wasm(instance: &mut Instance, string: String) -> CallResult<u32> {
|
||||
let string_len = string.len();
|
||||
|
||||
let space_offset = instance
|
||||
.call("_malloc", &[Value::I32((string_len as i32) + 1)])
|
||||
.unwrap();
|
||||
|
||||
let space_offset = match space_offset.as_slice() {
|
||||
&[Value::I32(res)] => Some(res as u32),
|
||||
_ => None,
|
||||
}
|
||||
.unwrap();
|
||||
|
||||
let raw_memory = instance.ctx().memory(0)[space_offset as usize] as *mut u8;
|
||||
|
||||
let slice = unsafe { slice::from_raw_parts_mut(raw_memory, string_len) };
|
||||
|
||||
for (byte, loc) in string.bytes().zip(slice.iter_mut()) {
|
||||
*loc = byte;
|
||||
}
|
||||
|
||||
unsafe { *raw_memory.add(string_len) = 0 };
|
||||
|
||||
Ok(space_offset)
|
||||
}
|
||||
|
||||
/// Create a pointer to an array of items in a wasm memory
|
||||
fn create_wasm_array(instance: &mut Instance, values: Vec<u32>) -> CallResult<u32> {
|
||||
let values_len = values.len();
|
||||
|
||||
// Space to store pointers to values
|
||||
let values_offset = instance
|
||||
.call(
|
||||
"_malloc",
|
||||
&[Value::I32((size_of::<u32>() * values.len()) as i32)],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let values_offset = match values_offset.as_slice() {
|
||||
&[Value::I32(res)] => Some(res as u32),
|
||||
_ => None,
|
||||
}
|
||||
.unwrap();
|
||||
|
||||
let raw_memory = instance.ctx().memory(0)[values_offset as usize] as *mut u32;
|
||||
|
||||
let slice = unsafe { slice::from_raw_parts_mut(raw_memory, values_len) };
|
||||
|
||||
for (value, loc) in values.iter().zip(slice.iter_mut()) {
|
||||
*loc = value.clone();
|
||||
}
|
||||
|
||||
// Space to store pointer to array
|
||||
let array_offset = instance
|
||||
.call("_malloc", &[Value::I32(size_of::<u32>() as i32)])
|
||||
.unwrap();
|
||||
|
||||
let array_offset = match array_offset.as_slice() {
|
||||
&[Value::I32(res)] => Some(res as u32),
|
||||
_ => None,
|
||||
}
|
||||
.unwrap();
|
||||
|
||||
let raw_memory = instance.ctx().memory(0)[values_offset as usize] as *mut u32;
|
||||
|
||||
unsafe { *raw_memory = values_offset };
|
||||
|
||||
Ok(array_offset)
|
||||
}
|
||||
|
||||
pub fn emscripten_set_up_memory(memory: &mut LinearMemory) {
|
||||
let dynamictop_ptr = dynamictop_ptr(STATIC_BUMP) as usize;
|
||||
let dynamictop_ptr_offset = dynamictop_ptr + mem::size_of::<u32>();
|
||||
|
@@ -26,17 +26,17 @@ pub extern "C" fn _sigaddset(set: u32, signum: u32, ctx: &mut Ctx) -> i32 {
|
||||
0
|
||||
}
|
||||
|
||||
pub extern "C" fn _sigsuspend(one: i32, ctx: &mut Ctx) -> i32 {
|
||||
pub extern "C" fn _sigsuspend(_one: i32, _ctx: &mut Ctx) -> i32 {
|
||||
debug!("emscripten::_sigsuspend");
|
||||
-1
|
||||
}
|
||||
|
||||
pub extern "C" fn _sigprocmask(one: i32, two: i32, three: i32, ctx: &mut Ctx) -> i32 {
|
||||
pub extern "C" fn _sigprocmask(_one: i32, _two: i32, _three: i32, _ctx: &mut Ctx) -> i32 {
|
||||
debug!("emscripten::_sigprocmask");
|
||||
0
|
||||
}
|
||||
|
||||
pub extern "C" fn _signal(sig: u32, two: i32, _ctx: &mut Ctx) -> i32 {
|
||||
pub extern "C" fn _signal(sig: u32, _two: i32, _ctx: &mut Ctx) -> i32 {
|
||||
debug!("emscripten::_signal ({})", sig);
|
||||
0
|
||||
}
|
||||
|
@@ -99,17 +99,17 @@ pub extern "C" fn _difftime(t0: u32, t1: u32) -> f64 {
|
||||
(t0 - t1) as _
|
||||
}
|
||||
|
||||
pub extern "C" fn _gmtime_r(one: i32, two: i32, ctx: &mut Ctx) -> i32 {
|
||||
pub extern "C" fn _gmtime_r(_one: i32, _two: i32, _ctx: &mut Ctx) -> i32 {
|
||||
debug!("emscripten::_gmtime_r");
|
||||
-1
|
||||
}
|
||||
|
||||
pub extern "C" fn _mktime(one: i32, ctx: &mut Ctx) -> i32 {
|
||||
pub extern "C" fn _mktime(_one: i32, _ctx: &mut Ctx) -> i32 {
|
||||
debug!("emscripten::_mktime");
|
||||
-1
|
||||
}
|
||||
|
||||
pub extern "C" fn _gmtime(one: i32, ctx: &mut Ctx) -> i32 {
|
||||
pub extern "C" fn _gmtime(_one: i32, _ctx: &mut Ctx) -> i32 {
|
||||
debug!("emscripten::_gmtime");
|
||||
-1
|
||||
}
|
||||
|
Reference in New Issue
Block a user