diff --git a/lib/clif-backend/src/code.rs b/lib/clif-backend/src/code.rs index 390dbfecb..74e59d344 100644 --- a/lib/clif-backend/src/code.rs +++ b/lib/clif-backend/src/code.rs @@ -32,6 +32,8 @@ use wasmer_runtime_core::{ }; use wasmparser::Type as WpType; +static BACKEND_ID: &str = "cranelift"; + pub struct CraneliftModuleCodeGenerator { isa: Box, signatures: Option>>, @@ -58,8 +60,8 @@ impl ModuleCodeGenerator unimplemented!("cross compilation is not available for clif backend") } - fn backend_id() -> String { - "cranelift".to_string() + fn backend_id() -> &'static str { + BACKEND_ID } fn check_precondition(&mut self, _module_info: &ModuleInfo) -> Result<(), CodegenError> { diff --git a/lib/llvm-backend/src/code.rs b/lib/llvm-backend/src/code.rs index 4333dbbf0..a892349bb 100644 --- a/lib/llvm-backend/src/code.rs +++ b/lib/llvm-backend/src/code.rs @@ -45,6 +45,8 @@ use wasmer_runtime_core::{ }; use wasmparser::{BinaryReaderError, MemoryImmediate, Operator, Type as WpType}; +static BACKEND_ID: &str = "llvm"; + fn func_sig_to_llvm<'ctx>( context: &'ctx Context, intrinsics: &Intrinsics<'ctx>, @@ -8721,8 +8723,8 @@ impl<'ctx> ModuleCodeGenerator, LLVMBackend, Cod } } - fn backend_id() -> String { - "llvm".to_string() + fn backend_id() -> &'static str { + BACKEND_ID } fn check_precondition(&mut self, _module_info: &ModuleInfo) -> Result<(), CodegenError> { diff --git a/lib/middleware-common-tests/src/lib.rs b/lib/middleware-common-tests/src/lib.rs index 20d69bb3d..d3beeb8f7 100644 --- a/lib/middleware-common-tests/src/lib.rs +++ b/lib/middleware-common-tests/src/lib.rs @@ -110,7 +110,7 @@ mod tests { baseline: true, msm: msm, base: instance.module.runnable_module.get_code().unwrap().as_ptr() as usize, - backend: MCG::backend_id(), + backend: MCG::backend_id().to_string(), runnable_module: instance.module.runnable_module.clone(), }); true @@ -152,7 +152,7 @@ mod tests { baseline: true, msm: msm, base: instance.module.runnable_module.get_code().unwrap().as_ptr() as usize, - backend: MCG::backend_id(), + backend: MCG::backend_id().to_string(), runnable_module: instance.module.runnable_module.clone(), }); true diff --git a/lib/runtime-core/src/codegen.rs b/lib/runtime-core/src/codegen.rs index 376b8337e..9322b9d5b 100644 --- a/lib/runtime-core/src/codegen.rs +++ b/lib/runtime-core/src/codegen.rs @@ -92,7 +92,7 @@ pub trait ModuleCodeGenerator, RM: RunnableModule, ) -> Self; /// Returns the backend id associated with this MCG. - fn backend_id() -> String; + fn backend_id() -> &'static str; /// It sets if the current compiler requires validation before compilation fn requires_pre_validation() -> bool { @@ -231,7 +231,7 @@ impl< validate_with_features(wasm, &compiler_config.features)?; } - let mut mcg = match MCG::backend_id().as_ref() { + let mut mcg = match MCG::backend_id() { "llvm" => MCG::new_with_target( compiler_config.triple.clone(), compiler_config.cpu_name.clone(), diff --git a/lib/runtime-core/src/parse.rs b/lib/runtime-core/src/parse.rs index 5a050f5c1..3d4e27b41 100644 --- a/lib/runtime-core/src/parse.rs +++ b/lib/runtime-core/src/parse.rs @@ -82,7 +82,7 @@ pub fn read_module< func_assoc: Map::new(), signatures: Map::new(), - backend: MCG::backend_id(), + backend: MCG::backend_id().to_string(), namespace_table: StringTable::new(), name_table: StringTable::new(), diff --git a/lib/singlepass-backend/src/codegen_x64.rs b/lib/singlepass-backend/src/codegen_x64.rs index e10b0fc98..3dc12ea29 100644 --- a/lib/singlepass-backend/src/codegen_x64.rs +++ b/lib/singlepass-backend/src/codegen_x64.rs @@ -59,6 +59,8 @@ pub const INLINE_BREAKPOINT_SIZE_X86_SINGLEPASS: usize = 7; /// Inline breakpoint size for aarch64. pub const INLINE_BREAKPOINT_SIZE_AARCH64_SINGLEPASS: usize = 12; +static BACKEND_ID: &str = "singlepass"; + #[cfg(target_arch = "x86_64")] lazy_static! { /// Performs a System V call to `target` with [stack_top..stack_base] as the argument list, from right to left. @@ -651,8 +653,8 @@ impl ModuleCodeGenerator false } - fn backend_id() -> String { - "singlepass".to_string() + fn backend_id() -> &'static str { + BACKEND_ID } fn new_with_target(_: Option, _: Option, _: Option) -> Self {