From 6f9baea140411cdc1995ddf7e8872f96ae0c89a7 Mon Sep 17 00:00:00 2001 From: vms Date: Fri, 6 Nov 2020 23:27:30 +0300 Subject: [PATCH] introduce function name for LocalImport and Export --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/errors.rs | 8 ++++---- src/interpreter/instructions/call_core.rs | 4 ++-- src/interpreter/instructions/utils.rs | 4 +++- src/interpreter/wasm/structures.rs | 10 ++++++++++ 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 33886c6..c871242 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -161,7 +161,7 @@ checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" [[package]] name = "wasmer-interface-types-fl" -version = "0.17.12" +version = "0.17.15" dependencies = [ "log", "nom", diff --git a/Cargo.toml b/Cargo.toml index 8e87ae1..d1334b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-interface-types-fl" -version = "0.17.12" +version = "0.17.15" description = "WebAssembly Interface Types library for Wasmer" license = "MIT" authors = ["The Wasmer Engineering Team "] diff --git a/src/errors.rs b/src/errors.rs index 4215cff..845a4f0 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -130,8 +130,8 @@ pub enum InstructionErrorKind { /// Failed to call a local or import function. LocalOrImportCall { - /// The local or import function index that has been called. - function_index: u32, + /// The local or import function name that has been called. + function_name: String, }, /// The memory doesn't exist. @@ -237,10 +237,10 @@ impl Display for InstructionErrorKind { function_index, expected.0, expected.1, received.0, received.1, ), - Self::LocalOrImportCall { function_index } => write!( + Self::LocalOrImportCall { function_name } => write!( formatter, "failed while calling the local or import function `{}`", - function_index + function_name ), Self::MemoryIsMissing { memory_index } => write!( diff --git a/src/interpreter/instructions/call_core.rs b/src/interpreter/instructions/call_core.rs index 04f168d..340974f 100644 --- a/src/interpreter/instructions/call_core.rs +++ b/src/interpreter/instructions/call_core.rs @@ -31,13 +31,13 @@ executable_instruction!( super::check_function_signature(&**instance, local_or_import, &inputs, instruction.clone())?; - log::trace!("call-core: calling {} with arguments: {:?}", function_index, inputs); + log::trace!("call-core: calling {} with arguments: {:?}", local_or_import.name(), inputs); let outputs = local_or_import.call(&inputs).map_err(|_| { InstructionError::new( instruction.clone(), InstructionErrorKind::LocalOrImportCall { - function_index, + function_name: local_or_import.name().to_string(), }, ) })?; diff --git a/src/interpreter/instructions/utils.rs b/src/interpreter/instructions/utils.rs index 6ebd4ca..ac099ae 100644 --- a/src/interpreter/instructions/utils.rs +++ b/src/interpreter/instructions/utils.rs @@ -184,7 +184,9 @@ where let outputs = local_or_import.call(&inputs).map_err(|_| { InstructionError::new( instruction.clone(), - InstructionErrorKind::LocalOrImportCall { function_index }, + InstructionErrorKind::LocalOrImportCall { + function_name: local_or_import.name().to_string(), + }, ) })?; diff --git a/src/interpreter/wasm/structures.rs b/src/interpreter/wasm/structures.rs index 0db3ab2..cb7c92e 100644 --- a/src/interpreter/wasm/structures.rs +++ b/src/interpreter/wasm/structures.rs @@ -43,6 +43,7 @@ impl LocalImportIndex for FunctionIndex { } pub trait Export { + fn name(&self) -> &str; fn inputs_cardinality(&self) -> usize; fn outputs_cardinality(&self) -> usize; fn arguments(&self) -> &[FunctionArg]; @@ -51,6 +52,7 @@ pub trait Export { } pub trait LocalImport { + fn name(&self) -> &str; fn inputs_cardinality(&self) -> usize; fn outputs_cardinality(&self) -> usize; fn arguments(&self) -> &[FunctionArg]; @@ -81,6 +83,10 @@ where } impl Export for () { + fn name(&self) -> &str { + "" + } + fn inputs_cardinality(&self) -> usize { 0 } @@ -103,6 +109,10 @@ impl Export for () { } impl LocalImport for () { + fn name(&self) -> &str { + "" + } + fn inputs_cardinality(&self) -> usize { 0 }