Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Connect part of the llvm backend to the runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlansneff committed Feb 28, 2019
1 parent d4ae5cd commit 359ac5a
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/artifacts
.DS_Store
.idea
**/.vscode
40 changes: 21 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/llvm-backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "llvm-backend"
name = "wasmer-llvm-backend"
version = "0.1.0"
authors = ["Lachlan Sneff <[email protected]>"]
edition = "2018"
Expand Down
9 changes: 7 additions & 2 deletions lib/llvm-backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
};
Expand Down
6 changes: 6 additions & 0 deletions lib/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 38 additions & 0 deletions lib/runtime/examples/call.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
5 changes: 3 additions & 2 deletions lib/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 359ac5a

Please sign in to comment.