Run spectests with both compilers, activate using features

This commit is contained in:
Brandon Fish
2019-03-06 00:15:07 -06:00
parent 0e5d1172d6
commit 03909fe3c2
4 changed files with 51 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
use wabt::wat2wasm;
use wasmer_clif_backend::CraneliftCompiler;
use wasmer_runtime_core::{
backend::Compiler,
error,
global::Global,
memory::Memory,
@@ -10,12 +10,31 @@ use wasmer_runtime_core::{
units::Pages,
};
#[cfg(feature = "clif")]
fn get_compiler() -> impl Compiler {
use wasmer_clif_backend::CraneliftCompiler;
CraneliftCompiler::new()
}
#[cfg(feature = "llvm")]
fn get_compiler() -> impl Compiler {
use wasmer_llvm_backend::LLVMCompiler;
LLVMCompiler::new()
}
#[cfg(not(any(feature = "llvm", feature = "clif")))]
fn get_compiler() -> impl Compiler {
panic!("compiler not specified, activate a compiler via features");
use wasmer_clif_backend::CraneliftCompiler;
CraneliftCompiler::new()
}
static EXAMPLE_WASM: &'static [u8] = include_bytes!("simple.wasm");
fn main() -> error::Result<()> {
let wasm_binary = wat2wasm(IMPORT_MODULE.as_bytes()).expect("WAST not valid or malformed");
let inner_module = wasmer_runtime_core::compile_with(&wasm_binary, &CraneliftCompiler::new())?;
let inner_module = wasmer_runtime_core::compile_with(&wasm_binary, &get_compiler())?;
let memory = Memory::new(MemoryDescriptor {
minimum: Pages(1),
@@ -50,7 +69,7 @@ fn main() -> error::Result<()> {
"env" => inner_instance,
};
let outer_module = wasmer_runtime_core::compile_with(EXAMPLE_WASM, &CraneliftCompiler::new())?;
let outer_module = wasmer_runtime_core::compile_with(EXAMPLE_WASM, &get_compiler())?;
let outer_instance = outer_module.instantiate(&outer_imports)?;
let ret = outer_instance.call("main", &[Value::I32(42)])?;
println!("ret: {:?}", ret);