mirror of
https://github.com/fluencelabs/wasmer
synced 2025-04-25 10:22:19 +00:00
Merge #1358
1358: Update C API to use new API r=MarkMcCaskey a=MarkMcCaskey # Review - [ ] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Mark McCaskey <mark@wasmer.io> Co-authored-by: Mark McCaskey <5770194+MarkMcCaskey@users.noreply.github.com>
This commit is contained in:
commit
ab106af422
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2934,8 +2934,8 @@ version = "0.16.2"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"cbindgen",
|
"cbindgen",
|
||||||
"libc",
|
"libc",
|
||||||
|
"wasmer",
|
||||||
"wasmer-emscripten",
|
"wasmer-emscripten",
|
||||||
"wasmer-runtime",
|
|
||||||
"wasmer-runtime-core",
|
"wasmer-runtime-core",
|
||||||
"wasmer-wasi",
|
"wasmer-wasi",
|
||||||
]
|
]
|
||||||
|
@ -74,6 +74,7 @@ pub mod wasm {
|
|||||||
pub use wasmer_runtime_core::global::Global;
|
pub use wasmer_runtime_core::global::Global;
|
||||||
pub use wasmer_runtime_core::instance::{DynFunc, Instance};
|
pub use wasmer_runtime_core::instance::{DynFunc, Instance};
|
||||||
pub use wasmer_runtime_core::memory::Memory;
|
pub use wasmer_runtime_core::memory::Memory;
|
||||||
|
pub use wasmer_runtime_core::module::Module;
|
||||||
pub use wasmer_runtime_core::table::Table;
|
pub use wasmer_runtime_core::table::Table;
|
||||||
pub use wasmer_runtime_core::types::{ExportDescriptor, ExternDescriptor, ImportDescriptor};
|
pub use wasmer_runtime_core::types::{ExportDescriptor, ExternDescriptor, ImportDescriptor};
|
||||||
pub use wasmer_runtime_core::types::{
|
pub use wasmer_runtime_core::types::{
|
||||||
@ -281,13 +282,16 @@ pub mod codegen {
|
|||||||
// TODO: `import` or `imports`?
|
// TODO: `import` or `imports`?
|
||||||
pub mod import {
|
pub mod import {
|
||||||
//! Types and functions for Wasm imports.
|
//! Types and functions for Wasm imports.
|
||||||
pub use wasmer_runtime_core::import::{ImportObject, LikeNamespace, Namespace};
|
pub use wasmer_runtime_core::import::{
|
||||||
|
ImportObject, ImportObjectIterator, LikeNamespace, Namespace,
|
||||||
|
};
|
||||||
pub use wasmer_runtime_core::types::{ExternDescriptor, ImportDescriptor};
|
pub use wasmer_runtime_core::types::{ExternDescriptor, ImportDescriptor};
|
||||||
pub use wasmer_runtime_core::{func, imports};
|
pub use wasmer_runtime_core::{func, imports};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod export {
|
pub mod export {
|
||||||
//! Types and functions for Wasm exports.
|
//! Types and functions for Wasm exports.
|
||||||
|
pub use wasmer_runtime_core::export::Export;
|
||||||
pub use wasmer_runtime_core::types::{ExportDescriptor, ExternDescriptor};
|
pub use wasmer_runtime_core::types::{ExportDescriptor, ExternDescriptor};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@ crate-type = ["cdylib", "rlib", "staticlib"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
libc = "0.2.60"
|
libc = "0.2.60"
|
||||||
|
|
||||||
[dependencies.wasmer-runtime]
|
[dependencies.wasmer]
|
||||||
default-features = false
|
default-features = false
|
||||||
path = "../runtime"
|
path = "../api"
|
||||||
version = "0.16.2"
|
version = "0.16.2"
|
||||||
|
|
||||||
[dependencies.wasmer-runtime-core]
|
[dependencies.wasmer-runtime-core]
|
||||||
@ -40,9 +40,9 @@ optional = true
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["cranelift-backend", "wasi"]
|
default = ["cranelift-backend", "wasi"]
|
||||||
singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass"]
|
singlepass-backend = ["wasmer/singlepass", "wasmer/default-backend-singlepass"]
|
||||||
cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift"]
|
cranelift-backend = ["wasmer/cranelift", "wasmer/default-backend-cranelift"]
|
||||||
llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm"]
|
llvm-backend = ["wasmer/llvm", "wasmer/default-backend-llvm"]
|
||||||
wasi = ["wasmer-wasi"]
|
wasi = ["wasmer-wasi"]
|
||||||
emscripten = ["wasmer-emscripten"]
|
emscripten = ["wasmer-emscripten"]
|
||||||
|
|
||||||
|
@ -13,8 +13,9 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use libc::{c_int, c_uint};
|
use libc::{c_int, c_uint};
|
||||||
use std::{ptr, slice};
|
use std::{ptr, slice};
|
||||||
use wasmer_runtime::{Instance, Module, Value};
|
use wasmer::export::{ExportDescriptor, ExternDescriptor};
|
||||||
use wasmer_runtime_core::{export::Export, module::ExportIndex};
|
use wasmer::wasm::{Memory, Value};
|
||||||
|
use wasmer::{Instance, Module};
|
||||||
|
|
||||||
/// Intermediate representation of an `Export` instance that is
|
/// Intermediate representation of an `Export` instance that is
|
||||||
/// exposed to C.
|
/// exposed to C.
|
||||||
@ -23,7 +24,7 @@ pub(crate) struct NamedExport {
|
|||||||
pub(crate) name: String,
|
pub(crate) name: String,
|
||||||
|
|
||||||
/// The export instance.
|
/// The export instance.
|
||||||
pub(crate) export: Export,
|
pub(crate) extern_descriptor: ExternDescriptor,
|
||||||
|
|
||||||
/// The instance that holds the export.
|
/// The instance that holds the export.
|
||||||
pub(crate) instance: *mut Instance,
|
pub(crate) instance: *mut Instance,
|
||||||
@ -145,7 +146,7 @@ pub unsafe extern "C" fn wasmer_export_descriptors(
|
|||||||
let module = &*(module as *const Module);
|
let module = &*(module as *const Module);
|
||||||
|
|
||||||
let named_export_descriptors: Box<NamedExportDescriptors> = Box::new(NamedExportDescriptors(
|
let named_export_descriptors: Box<NamedExportDescriptors> = Box::new(NamedExportDescriptors(
|
||||||
module.info().exports.iter().map(|e| e.into()).collect(),
|
module.exports().into_iter().map(|e| e.into()).collect(),
|
||||||
));
|
));
|
||||||
*export_descriptors =
|
*export_descriptors =
|
||||||
Box::into_raw(named_export_descriptors) as *mut wasmer_export_descriptors_t;
|
Box::into_raw(named_export_descriptors) as *mut wasmer_export_descriptors_t;
|
||||||
@ -268,11 +269,11 @@ pub unsafe extern "C" fn wasmer_export_kind(
|
|||||||
export: *mut wasmer_export_t,
|
export: *mut wasmer_export_t,
|
||||||
) -> wasmer_import_export_kind {
|
) -> wasmer_import_export_kind {
|
||||||
let named_export = &*(export as *mut NamedExport);
|
let named_export = &*(export as *mut NamedExport);
|
||||||
match named_export.export {
|
match named_export.extern_descriptor {
|
||||||
Export::Table(_) => wasmer_import_export_kind::WASM_TABLE,
|
ExternDescriptor::Table(_) => wasmer_import_export_kind::WASM_TABLE,
|
||||||
Export::Function { .. } => wasmer_import_export_kind::WASM_FUNCTION,
|
ExternDescriptor::Function { .. } => wasmer_import_export_kind::WASM_FUNCTION,
|
||||||
Export::Global(_) => wasmer_import_export_kind::WASM_GLOBAL,
|
ExternDescriptor::Global(_) => wasmer_import_export_kind::WASM_GLOBAL,
|
||||||
Export::Memory(_) => wasmer_import_export_kind::WASM_MEMORY,
|
ExternDescriptor::Memory(_) => wasmer_import_export_kind::WASM_MEMORY,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,8 +290,8 @@ pub unsafe extern "C" fn wasmer_export_func_params_arity(
|
|||||||
result: *mut u32,
|
result: *mut u32,
|
||||||
) -> wasmer_result_t {
|
) -> wasmer_result_t {
|
||||||
let named_export = &*(func as *const NamedExport);
|
let named_export = &*(func as *const NamedExport);
|
||||||
let export = &named_export.export;
|
let export = &named_export.extern_descriptor;
|
||||||
if let Export::Function { ref signature, .. } = *export {
|
if let ExternDescriptor::Function(ref signature) = *export {
|
||||||
*result = signature.params().len() as u32;
|
*result = signature.params().len() as u32;
|
||||||
wasmer_result_t::WASMER_OK
|
wasmer_result_t::WASMER_OK
|
||||||
} else {
|
} else {
|
||||||
@ -315,8 +316,8 @@ pub unsafe extern "C" fn wasmer_export_func_params(
|
|||||||
params_len: u32,
|
params_len: u32,
|
||||||
) -> wasmer_result_t {
|
) -> wasmer_result_t {
|
||||||
let named_export = &*(func as *const NamedExport);
|
let named_export = &*(func as *const NamedExport);
|
||||||
let export = &named_export.export;
|
let export = &named_export.extern_descriptor;
|
||||||
if let Export::Function { ref signature, .. } = *export {
|
if let ExternDescriptor::Function(ref signature) = *export {
|
||||||
let params: &mut [wasmer_value_tag] =
|
let params: &mut [wasmer_value_tag] =
|
||||||
slice::from_raw_parts_mut(params, params_len as usize);
|
slice::from_raw_parts_mut(params, params_len as usize);
|
||||||
for (i, item) in signature.params().iter().enumerate() {
|
for (i, item) in signature.params().iter().enumerate() {
|
||||||
@ -345,8 +346,8 @@ pub unsafe extern "C" fn wasmer_export_func_returns(
|
|||||||
returns_len: u32,
|
returns_len: u32,
|
||||||
) -> wasmer_result_t {
|
) -> wasmer_result_t {
|
||||||
let named_export = &*(func as *const NamedExport);
|
let named_export = &*(func as *const NamedExport);
|
||||||
let export = &named_export.export;
|
let export = &named_export.extern_descriptor;
|
||||||
if let Export::Function { ref signature, .. } = *export {
|
if let ExternDescriptor::Function(ref signature) = *export {
|
||||||
let returns: &mut [wasmer_value_tag] =
|
let returns: &mut [wasmer_value_tag] =
|
||||||
slice::from_raw_parts_mut(returns, returns_len as usize);
|
slice::from_raw_parts_mut(returns, returns_len as usize);
|
||||||
for (i, item) in signature.returns().iter().enumerate() {
|
for (i, item) in signature.returns().iter().enumerate() {
|
||||||
@ -374,8 +375,8 @@ pub unsafe extern "C" fn wasmer_export_func_returns_arity(
|
|||||||
result: *mut u32,
|
result: *mut u32,
|
||||||
) -> wasmer_result_t {
|
) -> wasmer_result_t {
|
||||||
let named_export = &*(func as *const NamedExport);
|
let named_export = &*(func as *const NamedExport);
|
||||||
let export = &named_export.export;
|
let export = &named_export.extern_descriptor;
|
||||||
if let Export::Function { ref signature, .. } = *export {
|
if let ExternDescriptor::Function(ref signature) = *export {
|
||||||
*result = signature.returns().len() as u32;
|
*result = signature.returns().len() as u32;
|
||||||
wasmer_result_t::WASMER_OK
|
wasmer_result_t::WASMER_OK
|
||||||
} else {
|
} else {
|
||||||
@ -408,9 +409,9 @@ pub unsafe extern "C" fn wasmer_export_to_memory(
|
|||||||
memory: *mut *mut wasmer_memory_t,
|
memory: *mut *mut wasmer_memory_t,
|
||||||
) -> wasmer_result_t {
|
) -> wasmer_result_t {
|
||||||
let named_export = &*(export as *const NamedExport);
|
let named_export = &*(export as *const NamedExport);
|
||||||
let export = &named_export.export;
|
let instance = &*named_export.instance;
|
||||||
|
|
||||||
if let Export::Memory(exported_memory) = export {
|
if let Ok(exported_memory) = instance.exports.get::<Memory>(&named_export.name) {
|
||||||
let mem = Box::new(exported_memory.clone());
|
let mem = Box::new(exported_memory.clone());
|
||||||
*memory = Box::into_raw(mem) as *mut wasmer_memory_t;
|
*memory = Box::into_raw(mem) as *mut wasmer_memory_t;
|
||||||
wasmer_result_t::WASMER_OK
|
wasmer_result_t::WASMER_OK
|
||||||
@ -517,16 +518,16 @@ pub unsafe extern "C" fn wasmer_export_func_call(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(&std::string::String, &ExportIndex)> for NamedExportDescriptor {
|
impl<'a> From<ExportDescriptor<'a>> for NamedExportDescriptor {
|
||||||
fn from((name, export_index): (&String, &ExportIndex)) -> Self {
|
fn from(ed: ExportDescriptor) -> Self {
|
||||||
let kind = match *export_index {
|
let kind = match ed.ty {
|
||||||
ExportIndex::Memory(_) => wasmer_import_export_kind::WASM_MEMORY,
|
ExternDescriptor::Memory(_) => wasmer_import_export_kind::WASM_MEMORY,
|
||||||
ExportIndex::Global(_) => wasmer_import_export_kind::WASM_GLOBAL,
|
ExternDescriptor::Global(_) => wasmer_import_export_kind::WASM_GLOBAL,
|
||||||
ExportIndex::Table(_) => wasmer_import_export_kind::WASM_TABLE,
|
ExternDescriptor::Table(_) => wasmer_import_export_kind::WASM_TABLE,
|
||||||
ExportIndex::Func(_) => wasmer_import_export_kind::WASM_FUNCTION,
|
ExternDescriptor::Function(_) => wasmer_import_export_kind::WASM_FUNCTION,
|
||||||
};
|
};
|
||||||
NamedExportDescriptor {
|
NamedExportDescriptor {
|
||||||
name: name.clone(),
|
name: ed.name.to_string(),
|
||||||
kind,
|
kind,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! Create, set, get and destroy global variables of an instance.
|
//! Create, set, get and destroy global variables of an instance.
|
||||||
|
|
||||||
use crate::value::{wasmer_value_t, wasmer_value_tag};
|
use crate::value::{wasmer_value_t, wasmer_value_tag};
|
||||||
use wasmer_runtime::Global;
|
use wasmer::wasm::Global;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -4,8 +4,8 @@ use super::*;
|
|||||||
use crate::{get_slice_checked, instance::wasmer_instance_t, module::wasmer_module_t};
|
use crate::{get_slice_checked, instance::wasmer_instance_t, module::wasmer_module_t};
|
||||||
|
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
use wasmer::wasm::{Instance, Module};
|
||||||
use wasmer_emscripten::{EmscriptenData, EmscriptenGlobals};
|
use wasmer_emscripten::{EmscriptenData, EmscriptenGlobals};
|
||||||
use wasmer_runtime::{Instance, Module};
|
|
||||||
|
|
||||||
/// Type used to construct an import_object_t with Emscripten imports.
|
/// Type used to construct an import_object_t with Emscripten imports.
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
@ -17,12 +17,12 @@ use std::{
|
|||||||
ptr, slice,
|
ptr, slice,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
use wasmer_runtime::{Ctx, Global, Memory, Module, Table};
|
use wasmer::import::{ImportObject, ImportObjectIterator};
|
||||||
|
use wasmer::vm::Ctx;
|
||||||
|
use wasmer::wasm::{Export, FuncSig, Global, Memory, Module, Table, Type};
|
||||||
use wasmer_runtime_core::{
|
use wasmer_runtime_core::{
|
||||||
export::{Context, Export, FuncPointer},
|
export::{Context, FuncPointer},
|
||||||
import::{ImportObject, ImportObjectIterator},
|
|
||||||
module::ImportName,
|
module::ImportName,
|
||||||
types::{FuncSig, Type},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
@ -10,11 +10,9 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use libc::{c_char, c_int, c_void};
|
use libc::{c_char, c_int, c_void};
|
||||||
use std::{collections::HashMap, ffi::CStr, ptr, slice};
|
use std::{collections::HashMap, ffi::CStr, ptr, slice};
|
||||||
use wasmer_runtime::{Ctx, Global, Instance, Memory, Table, Value};
|
use wasmer::import::{ImportObject, Namespace};
|
||||||
use wasmer_runtime_core::{
|
use wasmer::vm::Ctx;
|
||||||
export::Export,
|
use wasmer::wasm::{Export, Global, Instance, Memory, Table, Value};
|
||||||
import::{ImportObject, Namespace},
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Opaque pointer to a `wasmer_runtime::Instance` value in Rust.
|
/// Opaque pointer to a `wasmer_runtime::Instance` value in Rust.
|
||||||
///
|
///
|
||||||
@ -166,7 +164,15 @@ pub unsafe extern "C" fn wasmer_instantiate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize);
|
let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize);
|
||||||
let result = wasmer_runtime::instantiate(bytes, &import_object);
|
let module_result = wasmer::compiler::compile(bytes);
|
||||||
|
let module = match module_result {
|
||||||
|
Ok(module) => module,
|
||||||
|
Err(error) => {
|
||||||
|
update_last_error(error);
|
||||||
|
return wasmer_result_t::WASMER_ERROR;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let result = module.instantiate(&import_object);
|
||||||
let new_instance = match result {
|
let new_instance = match result {
|
||||||
Ok(instance) => instance,
|
Ok(instance) => instance,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
@ -387,10 +393,10 @@ pub unsafe extern "C" fn wasmer_instance_exports(
|
|||||||
let instance_ref = &mut *(instance as *mut Instance);
|
let instance_ref = &mut *(instance as *mut Instance);
|
||||||
let mut exports_vec: Vec<NamedExport> = Vec::with_capacity(instance_ref.exports().count());
|
let mut exports_vec: Vec<NamedExport> = Vec::with_capacity(instance_ref.exports().count());
|
||||||
|
|
||||||
for (name, export) in instance_ref.exports() {
|
for export_descriptor in instance_ref.module.exports().into_iter() {
|
||||||
exports_vec.push(NamedExport {
|
exports_vec.push(NamedExport {
|
||||||
name: name.clone(),
|
name: export_descriptor.name.to_string(),
|
||||||
export: export.clone(),
|
extern_descriptor: export_descriptor.ty,
|
||||||
instance: instance as *mut Instance,
|
instance: instance as *mut Instance,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -90,8 +90,6 @@
|
|||||||
unused_unsafe,
|
unused_unsafe,
|
||||||
unreachable_patterns
|
unreachable_patterns
|
||||||
)]
|
)]
|
||||||
extern crate wasmer_runtime;
|
|
||||||
extern crate wasmer_runtime_core;
|
|
||||||
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod export;
|
pub mod export;
|
||||||
|
@ -5,11 +5,9 @@ use crate::{
|
|||||||
wasmer_limits_t, wasmer_result_t,
|
wasmer_limits_t, wasmer_result_t,
|
||||||
};
|
};
|
||||||
use std::{cell::Cell, ptr};
|
use std::{cell::Cell, ptr};
|
||||||
use wasmer_runtime::Memory;
|
use wasmer::types::MemoryDescriptor;
|
||||||
use wasmer_runtime_core::{
|
use wasmer::units::{Bytes, Pages};
|
||||||
types::MemoryDescriptor,
|
use wasmer::wasm::Memory;
|
||||||
units::{Bytes, Pages},
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Opaque pointer to a `wasmer_runtime::Memory` value in Rust.
|
/// Opaque pointer to a `wasmer_runtime::Memory` value in Rust.
|
||||||
///
|
///
|
||||||
|
@ -9,10 +9,11 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use libc::c_int;
|
use libc::c_int;
|
||||||
use std::{collections::HashMap, slice};
|
use std::{collections::HashMap, slice};
|
||||||
use wasmer_runtime::{
|
use wasmer::compiler::{compile, default_compiler};
|
||||||
compile, default_compiler, Global, ImportObject, Instance, Memory, Module, Table,
|
use wasmer::import::{ImportObject, Namespace};
|
||||||
};
|
use wasmer::wasm::{Export, Global, Table};
|
||||||
use wasmer_runtime_core::{cache::Artifact, export::Export, import::Namespace, load_cache_with};
|
use wasmer::{Instance, Memory, Module};
|
||||||
|
use wasmer_runtime_core::{cache::Artifact, load_cache_with};
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct wasmer_module_t;
|
pub struct wasmer_module_t;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
//! Create, grow, destroy tables of an instance.
|
//! Create, grow, destroy tables of an instance.
|
||||||
|
|
||||||
use crate::{error::update_last_error, wasmer_limits_t, wasmer_result_t};
|
use crate::{error::update_last_error, wasmer_limits_t, wasmer_result_t};
|
||||||
use wasmer_runtime::Table;
|
use wasmer::types::{ElementType, TableDescriptor};
|
||||||
use wasmer_runtime_core::types::{ElementType, TableDescriptor};
|
use wasmer::wasm::Table;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -44,7 +44,7 @@ pub unsafe extern "C" fn wasmer_trampoline_buffer_builder_add_callinfo_trampolin
|
|||||||
ctx: *const c_void,
|
ctx: *const c_void,
|
||||||
num_params: u32,
|
num_params: u32,
|
||||||
) -> usize {
|
) -> usize {
|
||||||
use wasmer_runtime_core::types::Type;
|
use wasmer::types::Type;
|
||||||
let builder = &mut *(builder as *mut TrampolineBufferBuilder);
|
let builder = &mut *(builder as *mut TrampolineBufferBuilder);
|
||||||
builder.add_callinfo_trampoline(
|
builder.add_callinfo_trampoline(
|
||||||
mem::transmute(func),
|
mem::transmute(func),
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! Create and map Rust to WebAssembly values.
|
//! Create and map Rust to WebAssembly values.
|
||||||
|
|
||||||
use wasmer_runtime::Value;
|
use wasmer::types::Type;
|
||||||
use wasmer_runtime_core::types::Type;
|
use wasmer::wasm::Value;
|
||||||
|
|
||||||
/// Represents all possibles WebAssembly value types.
|
/// Represents all possibles WebAssembly value types.
|
||||||
///
|
///
|
||||||
@ -146,7 +146,7 @@ impl From<wasmer_value_tag> for Type {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&wasmer_runtime::wasm::Type> for wasmer_value_tag {
|
impl From<&wasmer::wasm::Type> for wasmer_value_tag {
|
||||||
fn from(ty: &Type) -> Self {
|
fn from(ty: &Type) -> Self {
|
||||||
match *ty {
|
match *ty {
|
||||||
Type::I32 => wasmer_value_tag::WASM_I32,
|
Type::I32 => wasmer_value_tag::WASM_I32,
|
||||||
|
@ -171,43 +171,9 @@ impl Module {
|
|||||||
&self.inner.info
|
&self.inner.info
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate over the [`ExportDescriptor`]s of the exports that this module provides.
|
|
||||||
pub(crate) fn exports_iter(&self) -> impl Iterator<Item = ExportDescriptor> + '_ {
|
|
||||||
self.info()
|
|
||||||
.exports
|
|
||||||
.iter()
|
|
||||||
.map(move |(name, &ei)| ExportDescriptor {
|
|
||||||
name,
|
|
||||||
ty: match ei {
|
|
||||||
ExportIndex::Func(f_idx) => {
|
|
||||||
let sig_idx = self.info().func_assoc[f_idx].into();
|
|
||||||
self.info().signatures[sig_idx].clone().into()
|
|
||||||
}
|
|
||||||
ExportIndex::Global(g_idx) => {
|
|
||||||
let info = self.info();
|
|
||||||
let local_global_idx =
|
|
||||||
LocalGlobalIndex::new(g_idx.index() - info.imported_globals.len());
|
|
||||||
info.globals[local_global_idx].desc.into()
|
|
||||||
}
|
|
||||||
ExportIndex::Memory(m_idx) => {
|
|
||||||
let info = self.info();
|
|
||||||
let local_memory_idx =
|
|
||||||
LocalMemoryIndex::new(m_idx.index() - info.imported_memories.len());
|
|
||||||
info.memories[local_memory_idx].into()
|
|
||||||
}
|
|
||||||
ExportIndex::Table(t_idx) => {
|
|
||||||
let info = self.info();
|
|
||||||
let local_table_idx =
|
|
||||||
LocalTableIndex::new(t_idx.index() - info.imported_tables.len());
|
|
||||||
info.tables[local_table_idx].into()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the [`ExportDescriptor`]s of the exports this [`Module`] provides.
|
/// Get the [`ExportDescriptor`]s of the exports this [`Module`] provides.
|
||||||
pub fn exports(&self) -> Vec<ExportDescriptor> {
|
pub fn exports(&self) -> Vec<ExportDescriptor> {
|
||||||
self.exports_iter().collect()
|
self.inner.exports()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the [`ImportDescriptor`]s describing the imports this [`Module`]
|
/// Get the [`ImportDescriptor`]s describing the imports this [`Module`]
|
||||||
@ -304,7 +270,46 @@ impl Clone for Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModuleInner {}
|
impl ModuleInner {
|
||||||
|
/// Iterate over the [`ExportDescriptor`]s of the exports that this module provides.
|
||||||
|
pub(crate) fn exports_iter(&self) -> impl Iterator<Item = ExportDescriptor> + '_ {
|
||||||
|
self.info
|
||||||
|
.exports
|
||||||
|
.iter()
|
||||||
|
.map(move |(name, &ei)| ExportDescriptor {
|
||||||
|
name,
|
||||||
|
ty: match ei {
|
||||||
|
ExportIndex::Func(f_idx) => {
|
||||||
|
let sig_idx = self.info.func_assoc[f_idx].into();
|
||||||
|
self.info.signatures[sig_idx].clone().into()
|
||||||
|
}
|
||||||
|
ExportIndex::Global(g_idx) => {
|
||||||
|
let info = &self.info;
|
||||||
|
let local_global_idx =
|
||||||
|
LocalGlobalIndex::new(g_idx.index() - info.imported_globals.len());
|
||||||
|
info.globals[local_global_idx].desc.into()
|
||||||
|
}
|
||||||
|
ExportIndex::Memory(m_idx) => {
|
||||||
|
let info = &self.info;
|
||||||
|
let local_memory_idx =
|
||||||
|
LocalMemoryIndex::new(m_idx.index() - info.imported_memories.len());
|
||||||
|
info.memories[local_memory_idx].into()
|
||||||
|
}
|
||||||
|
ExportIndex::Table(t_idx) => {
|
||||||
|
let info = &self.info;
|
||||||
|
let local_table_idx =
|
||||||
|
LocalTableIndex::new(t_idx.index() - info.imported_tables.len());
|
||||||
|
info.tables[local_table_idx].into()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the [`ExportDescriptor`]s of the exports this [`Module`] provides.
|
||||||
|
pub fn exports(&self) -> Vec<ExportDescriptor> {
|
||||||
|
self.exports_iter().collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user