mirror of
https://github.com/mii443/wasmer.git
synced 2025-08-29 03:39:29 +00:00
Renamed FuncType to FunctionType
This commit is contained in:
@ -4,7 +4,7 @@ use crate::store::{Store, StoreObject};
|
|||||||
use crate::types::{Val, ValAnyFunc};
|
use crate::types::{Val, ValAnyFunc};
|
||||||
use crate::Mutability;
|
use crate::Mutability;
|
||||||
use crate::RuntimeError;
|
use crate::RuntimeError;
|
||||||
use crate::{ExternType, FuncType, GlobalType, MemoryType, TableType, ValType};
|
use crate::{ExternType, FunctionType, GlobalType, MemoryType, TableType, ValType};
|
||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use wasm_common::{Bytes, HostFunction, Pages, ValueType, WasmTypeList, WithEnv, WithoutEnv};
|
use wasm_common::{Bytes, HostFunction, Pages, ValueType, WasmTypeList, WithEnv, WithoutEnv};
|
||||||
@ -563,7 +563,7 @@ impl Func {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the underlying type of this function.
|
/// Returns the underlying type of this function.
|
||||||
pub fn ty(&self) -> FuncType {
|
pub fn ty(&self) -> FunctionType {
|
||||||
self.store
|
self.store
|
||||||
.engine()
|
.engine()
|
||||||
.lookup_signature(self.exported.signature)
|
.lookup_signature(self.exported.signature)
|
||||||
|
@ -22,7 +22,7 @@ pub use crate::ptr::{Array, Item, WasmPtr};
|
|||||||
pub use crate::store::{Engine, Store, StoreObject};
|
pub use crate::store::{Engine, Store, StoreObject};
|
||||||
pub use crate::tunables::Tunables;
|
pub use crate::tunables::Tunables;
|
||||||
pub use crate::types::{
|
pub use crate::types::{
|
||||||
AnyRef, ExportType, ExternType, FuncType, GlobalType, HostInfo, HostRef, ImportType,
|
AnyRef, ExportType, ExternType, FunctionType, GlobalType, HostInfo, HostRef, ImportType,
|
||||||
MemoryType, Mutability, TableType, Val, ValType,
|
MemoryType, Mutability, TableType, Val, ValType,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ use crate::RuntimeError;
|
|||||||
use std::ptr;
|
use std::ptr;
|
||||||
use wasm_common::Value;
|
use wasm_common::Value;
|
||||||
pub use wasm_common::{
|
pub use wasm_common::{
|
||||||
AnyRef, ExportType, ExternType, FuncType, GlobalType, HostInfo, HostRef, ImportType,
|
AnyRef, ExportType, ExternType, FunctionType, GlobalType, HostInfo, HostRef, ImportType,
|
||||||
MemoryType, Mutability, TableType, Type as ValType,
|
MemoryType, Mutability, TableType, Type as ValType,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ use cranelift_codegen::{binemit, isa, Context};
|
|||||||
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
|
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
|
||||||
use wasm_common::entity::{EntityRef, PrimaryMap, SecondaryMap};
|
use wasm_common::entity::{EntityRef, PrimaryMap, SecondaryMap};
|
||||||
use wasm_common::{
|
use wasm_common::{
|
||||||
Features, FuncIndex, FuncType, LocalFuncIndex, MemoryIndex, SignatureIndex, TableIndex,
|
Features, FuncIndex, FunctionType, LocalFuncIndex, MemoryIndex, SignatureIndex, TableIndex,
|
||||||
};
|
};
|
||||||
use wasmer_compiler::CompileError;
|
use wasmer_compiler::CompileError;
|
||||||
use wasmer_compiler::{
|
use wasmer_compiler::{
|
||||||
@ -288,7 +288,7 @@ impl Compiler for CraneliftCompiler {
|
|||||||
|
|
||||||
fn compile_wasm_trampolines(
|
fn compile_wasm_trampolines(
|
||||||
&self,
|
&self,
|
||||||
signatures: &[FuncType],
|
signatures: &[FunctionType],
|
||||||
) -> Result<Vec<FunctionBody>, CompileError> {
|
) -> Result<Vec<FunctionBody>, CompileError> {
|
||||||
signatures
|
signatures
|
||||||
.par_iter()
|
.par_iter()
|
||||||
|
@ -14,14 +14,14 @@ use cranelift_codegen::print_errors::pretty_error;
|
|||||||
use cranelift_codegen::Context;
|
use cranelift_codegen::Context;
|
||||||
use cranelift_codegen::{binemit, ir};
|
use cranelift_codegen::{binemit, ir};
|
||||||
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
|
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
|
||||||
use wasm_common::FuncType;
|
use wasm_common::FunctionType;
|
||||||
use wasmer_compiler::{CompileError, CompiledFunction, CompiledFunctionFrameInfo, FunctionBody};
|
use wasmer_compiler::{CompileError, CompiledFunction, CompiledFunctionFrameInfo, FunctionBody};
|
||||||
|
|
||||||
/// Create a trampoline for invoking a WebAssembly function.
|
/// Create a trampoline for invoking a WebAssembly function.
|
||||||
pub fn make_wasm_trampoline(
|
pub fn make_wasm_trampoline(
|
||||||
isa: &dyn TargetIsa,
|
isa: &dyn TargetIsa,
|
||||||
fn_builder_ctx: &mut FunctionBuilderContext,
|
fn_builder_ctx: &mut FunctionBuilderContext,
|
||||||
func_type: &FuncType,
|
func_type: &FunctionType,
|
||||||
value_size: usize,
|
value_size: usize,
|
||||||
) -> Result<FunctionBody, CompileError> {
|
) -> Result<FunctionBody, CompileError> {
|
||||||
let pointer_type = isa.pointer_type();
|
let pointer_type = isa.pointer_type();
|
||||||
|
@ -7,7 +7,7 @@ use cranelift_codegen::binemit::Reloc;
|
|||||||
use cranelift_codegen::ir::{self, AbiParam};
|
use cranelift_codegen::ir::{self, AbiParam};
|
||||||
use cranelift_codegen::isa::TargetFrontendConfig;
|
use cranelift_codegen::isa::TargetFrontendConfig;
|
||||||
use cranelift_frontend::FunctionBuilder;
|
use cranelift_frontend::FunctionBuilder;
|
||||||
use wasm_common::{FuncType, Type};
|
use wasm_common::{FunctionType, Type};
|
||||||
use wasmer_compiler::wasm_unsupported;
|
use wasmer_compiler::wasm_unsupported;
|
||||||
use wasmer_compiler::wasmparser;
|
use wasmer_compiler::wasmparser;
|
||||||
use wasmer_compiler::RelocationKind;
|
use wasmer_compiler::RelocationKind;
|
||||||
@ -16,7 +16,7 @@ use wasmer_runtime::libcalls::LibCall;
|
|||||||
|
|
||||||
/// Helper function translate a Funciton signature into Cranelift Ir
|
/// Helper function translate a Funciton signature into Cranelift Ir
|
||||||
pub fn signature_to_cranelift_ir(
|
pub fn signature_to_cranelift_ir(
|
||||||
signature: &FuncType,
|
signature: &FunctionType,
|
||||||
target_config: &TargetFrontendConfig,
|
target_config: &TargetFrontendConfig,
|
||||||
) -> ir::Signature {
|
) -> ir::Signature {
|
||||||
let mut sig = ir::Signature::new(target_config.default_call_conv);
|
let mut sig = ir::Signature::new(target_config.default_call_conv);
|
||||||
|
@ -8,7 +8,7 @@ use crate::translator::FuncTranslator;
|
|||||||
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
|
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
|
||||||
use wasm_common::entity::{EntityRef, PrimaryMap, SecondaryMap};
|
use wasm_common::entity::{EntityRef, PrimaryMap, SecondaryMap};
|
||||||
use wasm_common::Features;
|
use wasm_common::Features;
|
||||||
use wasm_common::{FuncIndex, FuncType, LocalFuncIndex, MemoryIndex, TableIndex};
|
use wasm_common::{FuncIndex, FunctionType, LocalFuncIndex, MemoryIndex, TableIndex};
|
||||||
use wasmer_compiler::{
|
use wasmer_compiler::{
|
||||||
Compilation, CompileError, CompiledFunction, Compiler, CompilerConfig, CustomSection,
|
Compilation, CompileError, CompiledFunction, Compiler, CompilerConfig, CustomSection,
|
||||||
CustomSectionProtection, FunctionBody, FunctionBodyData, ModuleTranslationState, Relocation,
|
CustomSectionProtection, FunctionBody, FunctionBodyData, ModuleTranslationState, Relocation,
|
||||||
@ -141,7 +141,7 @@ impl Compiler for LLVMCompiler {
|
|||||||
|
|
||||||
fn compile_wasm_trampolines(
|
fn compile_wasm_trampolines(
|
||||||
&self,
|
&self,
|
||||||
signatures: &[FuncType],
|
signatures: &[FunctionType],
|
||||||
) -> Result<Vec<FunctionBody>, CompileError> {
|
) -> Result<Vec<FunctionBody>, CompileError> {
|
||||||
signatures
|
signatures
|
||||||
.par_iter()
|
.par_iter()
|
||||||
|
@ -4,7 +4,7 @@ use inkwell::{
|
|||||||
context::Context, module::Linkage, passes::PassManager, targets::FileType, types::BasicType,
|
context::Context, module::Linkage, passes::PassManager, targets::FileType, types::BasicType,
|
||||||
values::FunctionValue, AddressSpace,
|
values::FunctionValue, AddressSpace,
|
||||||
};
|
};
|
||||||
use wasm_common::{FuncType, Type};
|
use wasm_common::{FunctionType, Type};
|
||||||
use wasmer_compiler::{CompileError, CompiledFunctionUnwindInfo, FunctionBody};
|
use wasmer_compiler::{CompileError, CompiledFunctionUnwindInfo, FunctionBody};
|
||||||
|
|
||||||
pub struct FuncTrampoline {
|
pub struct FuncTrampoline {
|
||||||
@ -20,7 +20,7 @@ impl FuncTrampoline {
|
|||||||
|
|
||||||
pub fn trampoline(
|
pub fn trampoline(
|
||||||
&mut self,
|
&mut self,
|
||||||
ty: &FuncType,
|
ty: &FunctionType,
|
||||||
config: &LLVMConfig,
|
config: &LLVMConfig,
|
||||||
) -> Result<FunctionBody, CompileError> {
|
) -> Result<FunctionBody, CompileError> {
|
||||||
let mut module = self.ctx.create_module("");
|
let mut module = self.ctx.create_module("");
|
||||||
@ -104,7 +104,7 @@ impl FuncTrampoline {
|
|||||||
|
|
||||||
fn generate_trampoline<'ctx>(
|
fn generate_trampoline<'ctx>(
|
||||||
trampoline_func: FunctionValue,
|
trampoline_func: FunctionValue,
|
||||||
func_sig: &FuncType,
|
func_sig: &FunctionType,
|
||||||
context: &'ctx Context,
|
context: &'ctx Context,
|
||||||
intrinsics: &Intrinsics<'ctx>,
|
intrinsics: &Intrinsics<'ctx>,
|
||||||
) -> Result<(), CompileError> {
|
) -> Result<(), CompileError> {
|
||||||
|
@ -33,7 +33,8 @@ use std::collections::HashMap;
|
|||||||
use crate::config::LLVMConfig;
|
use crate::config::LLVMConfig;
|
||||||
use wasm_common::entity::{EntityRef, PrimaryMap, SecondaryMap};
|
use wasm_common::entity::{EntityRef, PrimaryMap, SecondaryMap};
|
||||||
use wasm_common::{
|
use wasm_common::{
|
||||||
FuncIndex, FuncType, GlobalIndex, LocalFuncIndex, MemoryIndex, SignatureIndex, TableIndex, Type,
|
FuncIndex, FunctionType, GlobalIndex, LocalFuncIndex, MemoryIndex, SignatureIndex, TableIndex,
|
||||||
|
Type,
|
||||||
};
|
};
|
||||||
use wasmer_compiler::wasmparser::{self, BinaryReader, MemoryImmediate, Operator};
|
use wasmer_compiler::wasmparser::{self, BinaryReader, MemoryImmediate, Operator};
|
||||||
use wasmer_compiler::{
|
use wasmer_compiler::{
|
||||||
|
@ -34,8 +34,8 @@ use wasmer_runtime_core::{
|
|||||||
*/
|
*/
|
||||||
use wasm_common::entity::{EntityRef, PrimaryMap};
|
use wasm_common::entity::{EntityRef, PrimaryMap};
|
||||||
use wasm_common::{
|
use wasm_common::{
|
||||||
FuncIndex, FuncType, GlobalIndex, MemoryIndex, Mutability, Pages, SignatureIndex, TableIndex,
|
FuncIndex, FunctionType as FuncType, GlobalIndex, MemoryIndex, Mutability, Pages,
|
||||||
Type,
|
SignatureIndex, TableIndex, Type,
|
||||||
};
|
};
|
||||||
use wasmer_runtime::Module as WasmerCompilerModule;
|
use wasmer_runtime::Module as WasmerCompilerModule;
|
||||||
use wasmer_runtime::{MemoryPlan, MemoryStyle, VMOffsets};
|
use wasmer_runtime::{MemoryPlan, MemoryStyle, VMOffsets};
|
||||||
|
@ -6,7 +6,7 @@ use crate::config::SinglepassConfig;
|
|||||||
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
|
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
|
||||||
use wasm_common::entity::{EntityRef, PrimaryMap};
|
use wasm_common::entity::{EntityRef, PrimaryMap};
|
||||||
use wasm_common::Features;
|
use wasm_common::Features;
|
||||||
use wasm_common::{FuncIndex, FuncType, LocalFuncIndex, MemoryIndex, TableIndex};
|
use wasm_common::{FuncIndex, FunctionType, LocalFuncIndex, MemoryIndex, TableIndex};
|
||||||
use wasmer_compiler::FunctionBodyData;
|
use wasmer_compiler::FunctionBodyData;
|
||||||
use wasmer_compiler::TrapInformation;
|
use wasmer_compiler::TrapInformation;
|
||||||
use wasmer_compiler::{Compilation, CompileError, Compiler, FunctionBody};
|
use wasmer_compiler::{Compilation, CompileError, Compiler, FunctionBody};
|
||||||
@ -67,7 +67,7 @@ impl Compiler for SinglepassCompiler {
|
|||||||
|
|
||||||
fn compile_wasm_trampolines(
|
fn compile_wasm_trampolines(
|
||||||
&self,
|
&self,
|
||||||
_signatures: &[FuncType],
|
_signatures: &[FunctionType],
|
||||||
) -> Result<Vec<FunctionBody>, CompileError> {
|
) -> Result<Vec<FunctionBody>, CompileError> {
|
||||||
// Note: do not implement this yet
|
// Note: do not implement this yet
|
||||||
Err(CompileError::Codegen(
|
Err(CompileError::Codegen(
|
||||||
|
@ -9,7 +9,7 @@ use crate::target::Target;
|
|||||||
use crate::FunctionBodyData;
|
use crate::FunctionBodyData;
|
||||||
use crate::ModuleTranslationState;
|
use crate::ModuleTranslationState;
|
||||||
use wasm_common::entity::PrimaryMap;
|
use wasm_common::entity::PrimaryMap;
|
||||||
use wasm_common::{Features, FuncType, LocalFuncIndex, MemoryIndex, TableIndex};
|
use wasm_common::{Features, FunctionType, LocalFuncIndex, MemoryIndex, TableIndex};
|
||||||
use wasmer_runtime::Module;
|
use wasmer_runtime::Module;
|
||||||
use wasmer_runtime::{MemoryPlan, TablePlan};
|
use wasmer_runtime::{MemoryPlan, TablePlan};
|
||||||
use wasmparser::{validate, OperatorValidatorConfig, ValidatingParserConfig};
|
use wasmparser::{validate, OperatorValidatorConfig, ValidatingParserConfig};
|
||||||
@ -82,6 +82,6 @@ pub trait Compiler {
|
|||||||
/// ```
|
/// ```
|
||||||
fn compile_wasm_trampolines(
|
fn compile_wasm_trampolines(
|
||||||
&self,
|
&self,
|
||||||
signatures: &[FuncType],
|
signatures: &[FunctionType],
|
||||||
) -> Result<Vec<FunctionBody>, CompileError>;
|
) -> Result<Vec<FunctionBody>, CompileError>;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ use crate::{WasmError, WasmResult};
|
|||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wasm_common::entity::PrimaryMap;
|
use wasm_common::entity::PrimaryMap;
|
||||||
use wasm_common::FuncType;
|
use wasm_common::FunctionType;
|
||||||
use wasm_common::{
|
use wasm_common::{
|
||||||
DataIndex, DataInitializer, DataInitializerLocation, ElemIndex, ExportIndex, FuncIndex,
|
DataIndex, DataInitializer, DataInitializerLocation, ElemIndex, ExportIndex, FuncIndex,
|
||||||
GlobalIndex, GlobalInit, GlobalType, ImportIndex, LocalFuncIndex, MemoryIndex, MemoryType,
|
GlobalIndex, GlobalInit, GlobalType, ImportIndex, LocalFuncIndex, MemoryIndex, MemoryType,
|
||||||
@ -102,7 +102,7 @@ impl<'data> ModuleEnvironment<'data> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn declare_signature(&mut self, sig: FuncType) -> WasmResult<()> {
|
pub(crate) fn declare_signature(&mut self, sig: FunctionType) -> WasmResult<()> {
|
||||||
// TODO: Deduplicate signatures.
|
// TODO: Deduplicate signatures.
|
||||||
self.result.module.signatures.push(sig);
|
self.result.module.signatures.push(sig);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -18,15 +18,16 @@ use std::vec::Vec;
|
|||||||
use wasm_common::entity::packed_option::ReservedValue;
|
use wasm_common::entity::packed_option::ReservedValue;
|
||||||
use wasm_common::entity::EntityRef;
|
use wasm_common::entity::EntityRef;
|
||||||
use wasm_common::{
|
use wasm_common::{
|
||||||
DataIndex, ElemIndex, FuncIndex, FuncType, GlobalIndex, GlobalInit, GlobalType, MemoryIndex,
|
DataIndex, ElemIndex, FuncIndex, FunctionType, GlobalIndex, GlobalInit, GlobalType,
|
||||||
MemoryType, Pages, SignatureIndex, TableIndex, TableType, Type, V128,
|
MemoryIndex, MemoryType, Pages, SignatureIndex, TableIndex, TableType, Type, V128,
|
||||||
};
|
};
|
||||||
use wasmparser::{
|
use wasmparser::{
|
||||||
self, CodeSectionReader, Data, DataKind, DataSectionReader, Element, ElementItem, ElementItems,
|
self, CodeSectionReader, Data, DataKind, DataSectionReader, Element, ElementItem, ElementItems,
|
||||||
ElementKind, ElementSectionReader, Export, ExportSectionReader, ExternalKind,
|
ElementKind, ElementSectionReader, Export, ExportSectionReader, ExternalKind,
|
||||||
FuncType as WPFuncType, FunctionSectionReader, GlobalSectionReader, GlobalType as WPGlobalType,
|
FuncType as WPFunctionType, FunctionSectionReader, GlobalSectionReader,
|
||||||
ImportSectionEntryType, ImportSectionReader, MemorySectionReader, MemoryType as WPMemoryType,
|
GlobalType as WPGlobalType, ImportSectionEntryType, ImportSectionReader, MemorySectionReader,
|
||||||
NameSectionReader, Naming, NamingReader, Operator, TableSectionReader, TypeSectionReader,
|
MemoryType as WPMemoryType, NameSectionReader, Naming, NamingReader, Operator,
|
||||||
|
TableSectionReader, TypeSectionReader,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Helper function translating wasmparser types to Wasm Type.
|
/// Helper function translating wasmparser types to Wasm Type.
|
||||||
@ -57,7 +58,7 @@ pub fn parse_type_section(
|
|||||||
|
|
||||||
for entry in types {
|
for entry in types {
|
||||||
match entry.map_err(to_wasm_error)? {
|
match entry.map_err(to_wasm_error)? {
|
||||||
WPFuncType {
|
WPFunctionType {
|
||||||
form: wasmparser::Type::Func,
|
form: wasmparser::Type::Func,
|
||||||
params,
|
params,
|
||||||
returns,
|
returns,
|
||||||
@ -76,7 +77,7 @@ pub fn parse_type_section(
|
|||||||
.expect("only numeric types are supported in function signatures")
|
.expect("only numeric types are supported in function signatures")
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let sig = FuncType::new(sig_params, sig_returns);
|
let sig = FunctionType::new(sig_params, sig_returns);
|
||||||
environ.declare_signature(sig)?;
|
environ.declare_signature(sig)?;
|
||||||
module_translation_state.wasm_types.push((params, returns));
|
module_translation_state.wasm_types.push((params, returns));
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ use std::cell::RefCell;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wasm_common::entity::PrimaryMap;
|
use wasm_common::entity::PrimaryMap;
|
||||||
use wasm_common::{FuncType, LocalFuncIndex, MemoryIndex, SignatureIndex, TableIndex};
|
use wasm_common::{FunctionType, LocalFuncIndex, MemoryIndex, SignatureIndex, TableIndex};
|
||||||
use wasmer_compiler::{Compilation, CompileError, FunctionBody, Target};
|
use wasmer_compiler::{Compilation, CompileError, FunctionBody, Target};
|
||||||
#[cfg(feature = "compiler")]
|
#[cfg(feature = "compiler")]
|
||||||
use wasmer_compiler::{Compiler, CompilerConfig};
|
use wasmer_compiler::{Compiler, CompilerConfig};
|
||||||
@ -92,13 +92,13 @@ impl JITEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Register a signature
|
/// Register a signature
|
||||||
pub fn register_signature(&self, func_type: &FuncType) -> VMSharedSignatureIndex {
|
pub fn register_signature(&self, func_type: &FunctionType) -> VMSharedSignatureIndex {
|
||||||
let compiler = self.compiler();
|
let compiler = self.compiler();
|
||||||
compiler.signatures().register(func_type)
|
compiler.signatures().register(func_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Lookup a signature
|
/// Lookup a signature
|
||||||
pub fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option<FuncType> {
|
pub fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option<FunctionType> {
|
||||||
let compiler = self.compiler();
|
let compiler = self.compiler();
|
||||||
compiler.signatures().lookup(sig)
|
compiler.signatures().lookup(sig)
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,8 @@ use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wasm_common::entity::{EntityRef, PrimaryMap};
|
use wasm_common::entity::{EntityRef, PrimaryMap};
|
||||||
use wasm_common::{
|
use wasm_common::{
|
||||||
DataIndex, ElemIndex, ExportIndex, ExportType, ExternType, FuncIndex, FuncType, GlobalIndex,
|
DataIndex, ElemIndex, ExportIndex, ExportType, ExternType, FuncIndex, FunctionType,
|
||||||
GlobalInit, GlobalType, ImportIndex, ImportType, LocalFuncIndex, LocalGlobalIndex,
|
GlobalIndex, GlobalInit, GlobalType, ImportIndex, ImportType, LocalFuncIndex, LocalGlobalIndex,
|
||||||
LocalMemoryIndex, LocalTableIndex, MemoryIndex, MemoryType, Pages, SignatureIndex, TableIndex,
|
LocalMemoryIndex, LocalTableIndex, MemoryIndex, MemoryType, Pages, SignatureIndex, TableIndex,
|
||||||
TableType,
|
TableType,
|
||||||
};
|
};
|
||||||
@ -132,7 +132,7 @@ pub struct Module {
|
|||||||
pub func_names: HashMap<FuncIndex, String>,
|
pub func_names: HashMap<FuncIndex, String>,
|
||||||
|
|
||||||
/// WebAssembly function signatures.
|
/// WebAssembly function signatures.
|
||||||
pub signatures: PrimaryMap<SignatureIndex, FuncType>,
|
pub signatures: PrimaryMap<SignatureIndex, FunctionType>,
|
||||||
|
|
||||||
/// Types of functions (imported and local).
|
/// Types of functions (imported and local).
|
||||||
pub functions: PrimaryMap<FuncIndex, SignatureIndex>,
|
pub functions: PrimaryMap<FuncIndex, SignatureIndex>,
|
||||||
@ -191,7 +191,7 @@ impl Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the exported signatures of the module
|
/// Get the exported signatures of the module
|
||||||
pub fn exported_signatures(&self) -> Vec<FuncType> {
|
pub fn exported_signatures(&self) -> Vec<FunctionType> {
|
||||||
self.exports
|
self.exports
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(_name, export_index)| match export_index {
|
.filter_map(|(_name, export_index)| match export_index {
|
||||||
@ -202,7 +202,7 @@ impl Module {
|
|||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.collect::<Vec<FuncType>>()
|
.collect::<Vec<FunctionType>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the export types of the module
|
/// Get the export types of the module
|
||||||
|
@ -6,7 +6,7 @@ use more_asserts::{assert_lt, debug_assert_lt};
|
|||||||
use std::collections::{hash_map, HashMap};
|
use std::collections::{hash_map, HashMap};
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
use wasm_common::FuncType;
|
use wasm_common::FunctionType;
|
||||||
|
|
||||||
/// WebAssembly requires that the caller and callee signatures in an indirect
|
/// WebAssembly requires that the caller and callee signatures in an indirect
|
||||||
/// call must match. To implement this efficiently, keep a registry of all
|
/// call must match. To implement this efficiently, keep a registry of all
|
||||||
@ -24,8 +24,8 @@ pub struct SignatureRegistry {
|
|||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
struct Inner {
|
struct Inner {
|
||||||
signature2index: HashMap<FuncType, VMSharedSignatureIndex>,
|
signature2index: HashMap<FunctionType, VMSharedSignatureIndex>,
|
||||||
index2signature: HashMap<VMSharedSignatureIndex, FuncType>,
|
index2signature: HashMap<VMSharedSignatureIndex, FunctionType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SignatureRegistry {
|
impl SignatureRegistry {
|
||||||
@ -37,7 +37,7 @@ impl SignatureRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Register a signature and return its unique index.
|
/// Register a signature and return its unique index.
|
||||||
pub fn register(&self, sig: &FuncType) -> VMSharedSignatureIndex {
|
pub fn register(&self, sig: &FunctionType) -> VMSharedSignatureIndex {
|
||||||
let mut inner = self.inner.write().unwrap();
|
let mut inner = self.inner.write().unwrap();
|
||||||
let len = inner.signature2index.len();
|
let len = inner.signature2index.len();
|
||||||
match inner.signature2index.entry(sig.clone()) {
|
match inner.signature2index.entry(sig.clone()) {
|
||||||
@ -62,7 +62,7 @@ impl SignatureRegistry {
|
|||||||
///
|
///
|
||||||
/// Note that for this operation to be semantically correct the `idx` must
|
/// Note that for this operation to be semantically correct the `idx` must
|
||||||
/// have previously come from a call to `register` of this same object.
|
/// have previously come from a call to `register` of this same object.
|
||||||
pub fn lookup(&self, idx: VMSharedSignatureIndex) -> Option<FuncType> {
|
pub fn lookup(&self, idx: VMSharedSignatureIndex) -> Option<FunctionType> {
|
||||||
self.inner
|
self.inner
|
||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -51,8 +51,8 @@ pub use crate::r#ref::{AnyRef, HostInfo, HostRef};
|
|||||||
pub use crate::units::{Bytes, Pages};
|
pub use crate::units::{Bytes, Pages};
|
||||||
pub use crate::values::Value;
|
pub use crate::values::Value;
|
||||||
pub use types::{
|
pub use types::{
|
||||||
ExportType, ExternType, FuncType, GlobalInit, GlobalType, ImportType, MemoryType, Mutability,
|
ExportType, ExternType, FunctionType, GlobalInit, GlobalType, ImportType, MemoryType,
|
||||||
TableType, Type, V128,
|
Mutability, TableType, Type, V128,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Version number of this crate.
|
/// Version number of this crate.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! This module permits to create native functions
|
//! This module permits to create native functions
|
||||||
//! easily in Rust, thanks to it's advanced typing system.
|
//! easily in Rust, thanks to it's advanced typing system.
|
||||||
|
|
||||||
use crate::types::{FuncType, Type};
|
use crate::types::{FunctionType, Type};
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
@ -300,8 +300,8 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the type of the Func
|
/// Get the type of the Func
|
||||||
pub fn ty(&self) -> FuncType {
|
pub fn ty(&self) -> FunctionType {
|
||||||
FuncType::new(Args::wasm_types(), Rets::wasm_types())
|
FunctionType::new(Args::wasm_types(), Rets::wasm_types())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the type of the Func
|
/// Get the type of the Func
|
||||||
@ -633,30 +633,30 @@ mod test_func {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_function_types() {
|
fn test_function_types() {
|
||||||
assert_eq!(Func::new(func).ty(), FuncType::new(vec![], vec![]));
|
assert_eq!(Func::new(func).ty(), FunctionType::new(vec![], vec![]));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Func::new(func__i32).ty(),
|
Func::new(func__i32).ty(),
|
||||||
FuncType::new(vec![], vec![Type::I32])
|
FunctionType::new(vec![], vec![Type::I32])
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Func::new(func_i32).ty(),
|
Func::new(func_i32).ty(),
|
||||||
FuncType::new(vec![Type::I32], vec![])
|
FunctionType::new(vec![Type::I32], vec![])
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Func::new(func_i32__i32).ty(),
|
Func::new(func_i32__i32).ty(),
|
||||||
FuncType::new(vec![Type::I32], vec![Type::I32])
|
FunctionType::new(vec![Type::I32], vec![Type::I32])
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Func::new(func_i32_i32__i32).ty(),
|
Func::new(func_i32_i32__i32).ty(),
|
||||||
FuncType::new(vec![Type::I32, Type::I32], vec![Type::I32])
|
FunctionType::new(vec![Type::I32, Type::I32], vec![Type::I32])
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Func::new(func_i32_i32__i32_i32).ty(),
|
Func::new(func_i32_i32__i32_i32).ty(),
|
||||||
FuncType::new(vec![Type::I32, Type::I32], vec![Type::I32, Type::I32])
|
FunctionType::new(vec![Type::I32, Type::I32], vec![Type::I32, Type::I32])
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Func::new(func_f32_i32__i32_f32).ty(),
|
Func::new(func_f32_i32__i32_f32).ty(),
|
||||||
FuncType::new(vec![Type::F32, Type::I32], vec![Type::I32, Type::F32])
|
FunctionType::new(vec![Type::F32, Type::I32], vec![Type::I32, Type::F32])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ impl From<&[u8]> for V128 {
|
|||||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||||
pub enum ExternType {
|
pub enum ExternType {
|
||||||
/// This external type is the type of a WebAssembly function.
|
/// This external type is the type of a WebAssembly function.
|
||||||
Func(FuncType),
|
Func(FunctionType),
|
||||||
/// This external type is the type of a WebAssembly global.
|
/// This external type is the type of a WebAssembly global.
|
||||||
Global(GlobalType),
|
Global(GlobalType),
|
||||||
/// This external type is the type of a WebAssembly table.
|
/// This external type is the type of a WebAssembly table.
|
||||||
@ -192,7 +192,7 @@ macro_rules! accessors {
|
|||||||
|
|
||||||
impl ExternType {
|
impl ExternType {
|
||||||
accessors! {
|
accessors! {
|
||||||
(Func(FuncType) func unwrap_func)
|
(Func(FunctionType) func unwrap_func)
|
||||||
(Global(GlobalType) global unwrap_global)
|
(Global(GlobalType) global unwrap_global)
|
||||||
(Table(TableType) table unwrap_table)
|
(Table(TableType) table unwrap_table)
|
||||||
(Memory(MemoryType) memory unwrap_memory)
|
(Memory(MemoryType) memory unwrap_memory)
|
||||||
@ -216,14 +216,14 @@ impl ExternType {
|
|||||||
/// WebAssembly functions can have 0 or more parameters and results.
|
/// WebAssembly functions can have 0 or more parameters and results.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
|
||||||
pub struct FuncType {
|
pub struct FunctionType {
|
||||||
/// The parameters of the function
|
/// The parameters of the function
|
||||||
params: Vec<Type>,
|
params: Vec<Type>,
|
||||||
/// The return values of the function
|
/// The return values of the function
|
||||||
results: Vec<Type>,
|
results: Vec<Type>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FuncType {
|
impl FunctionType {
|
||||||
/// Creates a new Function Type with the given parameter and return types.
|
/// Creates a new Function Type with the given parameter and return types.
|
||||||
pub fn new<Params, Returns>(params: Params, returns: Returns) -> Self
|
pub fn new<Params, Returns>(params: Params, returns: Returns) -> Self
|
||||||
where
|
where
|
||||||
@ -257,7 +257,7 @@ impl FuncType {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for FuncType {
|
impl std::fmt::Display for FunctionType {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
let params = self
|
let params = self
|
||||||
.params
|
.params
|
||||||
|
Reference in New Issue
Block a user