Move backend_id to static str

This commit is contained in:
Syrus 2020-01-13 15:40:09 +01:00
parent cb5cf00442
commit a1d8b9aa5b
6 changed files with 17 additions and 11 deletions

View File

@ -32,6 +32,8 @@ use wasmer_runtime_core::{
};
use wasmparser::Type as WpType;
static BACKEND_ID: &str = "cranelift";
pub struct CraneliftModuleCodeGenerator {
isa: Box<dyn isa::TargetIsa>,
signatures: Option<Arc<Map<SigIndex, FuncSig>>>,
@ -58,8 +60,8 @@ impl ModuleCodeGenerator<CraneliftFunctionCodeGenerator, Caller, CodegenError>
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> {

View File

@ -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<LLVMFunctionCodeGenerator<'ctx>, 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> {

View File

@ -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

View File

@ -92,7 +92,7 @@ pub trait ModuleCodeGenerator<FCG: FunctionCodeGenerator<E>, 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(),

View File

@ -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(),

View File

@ -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<X64FunctionCode, X64ExecutionContext, CodegenError>
false
}
fn backend_id() -> String {
"singlepass".to_string()
fn backend_id() -> &'static str {
BACKEND_ID
}
fn new_with_target(_: Option<String>, _: Option<String>, _: Option<String>) -> Self {