mirror of
https://github.com/fluencelabs/wasmer
synced 2025-07-31 07:12:10 +00:00
Connect part of the llvm backend to the runtime
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@
|
||||
/artifacts
|
||||
.DS_Store
|
||||
.idea
|
||||
**/.vscode
|
40
Cargo.lock
generated
40
Cargo.lock
generated
@@ -481,25 +481,6 @@ dependencies = [
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "llvm-backend"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"capstone 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"goblin 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"inkwell 0.1.0 (git+https://github.com/TheDan64/inkwell?branch=llvm7-0)",
|
||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasmer-runtime-core 0.1.2",
|
||||
"wasmparser 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "llvm-sys"
|
||||
version = "70.1.0"
|
||||
@@ -1219,13 +1200,34 @@ dependencies = [
|
||||
"wasmer-runtime-core 0.1.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasmer-llvm-backend"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"capstone 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cc 1.0.29 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"goblin 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"inkwell 0.1.0 (git+https://github.com/TheDan64/inkwell?branch=llvm7-0)",
|
||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasmer-runtime-core 0.1.2",
|
||||
"wasmparser 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasmer-runtime"
|
||||
version = "0.1.4"
|
||||
dependencies = [
|
||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasmer-clif-backend 0.1.2",
|
||||
"wasmer-llvm-backend 0.1.0",
|
||||
"wasmer-runtime-core 0.1.2",
|
||||
]
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "llvm-backend"
|
||||
name = "wasmer-llvm-backend"
|
||||
version = "0.1.0"
|
||||
authors = ["Lachlan Sneff <lachlan.sneff@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
@@ -54,10 +54,10 @@ impl Compiler for LLVMCompiler {
|
||||
_vmctx: *mut vm::Ctx,
|
||||
_: Token,
|
||||
) -> RuntimeResult<Vec<Value>> {
|
||||
Ok(vec![])
|
||||
unimplemented!("the llvm-based backend does not yet implement ProtectedCaller")
|
||||
}
|
||||
fn get_early_trapper(&self) -> Box<dyn UserTrapper> {
|
||||
unimplemented!()
|
||||
Box::new(Placeholder)
|
||||
}
|
||||
}
|
||||
impl CacheGen for Placeholder {
|
||||
@@ -68,6 +68,11 @@ impl Compiler for LLVMCompiler {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
impl UserTrapper for Placeholder {
|
||||
unsafe fn do_early_trap(&self, msg: String) -> ! {
|
||||
unimplemented!("do early trap: {}", msg)
|
||||
}
|
||||
}
|
||||
|
||||
(Box::new(Placeholder), Box::new(Placeholder))
|
||||
};
|
||||
|
@@ -20,5 +20,11 @@ version = "0.1.2"
|
||||
path = "../clif-backend"
|
||||
version = "0.1.2"
|
||||
|
||||
[dependencies.wasmer-llvm-backend]
|
||||
path = "../llvm-backend"
|
||||
|
||||
[features]
|
||||
debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"]
|
||||
|
||||
[dev-dependencies]
|
||||
wabt = "0.7.4"
|
38
lib/runtime/examples/call.rs
Normal file
38
lib/runtime/examples/call.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
use wasmer_runtime::{compile, error, imports, Func};
|
||||
|
||||
use wabt::wat2wasm;
|
||||
|
||||
static WAT: &'static str = r#"
|
||||
(module
|
||||
(type $t0 (func (param i32) (result i32)))
|
||||
(type $t1 (func (result i32)))
|
||||
(memory 1)
|
||||
(global $g0 (mut i32) (i32.const 0))
|
||||
(export "foo" (func $foo))
|
||||
(func $foo (type $t0) (param i32) (result i32)
|
||||
get_local 0
|
||||
)
|
||||
)
|
||||
"#;
|
||||
|
||||
fn get_wasm() -> Vec<u8> {
|
||||
wat2wasm(WAT).unwrap()
|
||||
}
|
||||
|
||||
fn main() -> Result<(), error::Error> {
|
||||
let wasm = get_wasm();
|
||||
|
||||
let module = compile(&wasm)?;
|
||||
|
||||
let imports = imports! {};
|
||||
|
||||
let instance = module.instantiate(&imports)?;
|
||||
|
||||
let foo: Func<i32, i32> = instance.func("foo")?;
|
||||
|
||||
let result = foo.call(42);
|
||||
|
||||
println!("result: {:?}", result);
|
||||
|
||||
Ok(())
|
||||
}
|
@@ -154,10 +154,11 @@ pub fn instantiate(wasm: &[u8], import_object: &ImportObject) -> error::Result<I
|
||||
|
||||
fn default_compiler() -> &'static dyn Compiler {
|
||||
use lazy_static::lazy_static;
|
||||
use wasmer_clif_backend::CraneliftCompiler;
|
||||
// use wasmer_clif_backend::CraneliftCompiler;
|
||||
use wasmer_llvm_backend::LLVMCompiler;
|
||||
|
||||
lazy_static! {
|
||||
static ref DEFAULT_COMPILER: CraneliftCompiler = { CraneliftCompiler::new() };
|
||||
static ref DEFAULT_COMPILER: LLVMCompiler = { LLVMCompiler::new() };
|
||||
}
|
||||
|
||||
&*DEFAULT_COMPILER as &dyn Compiler
|
||||
|
Reference in New Issue
Block a user