Add ability to call CLIF functions with arbitrary arguments in filetests

This resolves the work started in https://github.com/bytecodealliance/cranelift/pull/1231 and https://github.com/bytecodealliance/wasmtime/pull/1436. Cranelift filetests currently have the ability to run CLIF functions with a signature like `() -> b*` and check that the result is true under the `test run` directive. This PR adds the ability to call functions with arbitrary arguments and non-boolean returns and either print the result or check against a list of expected results:
 - `run` commands look like `; run: %add(2, 2) == 4` or `; run: %add(2, 2) != 5` and verify that the executed CLIF function returns the expected value
 - `print` commands look like `; print: %add(2, 2)` and print the result of the function to stdout

To make this work, this PR compiles a single Cranelift `Function` into a `CompiledFunction` using a `SingleFunctionCompiler`. Because we will not know the signature of the function until runtime, we use a `Trampoline` to place the values in the appropriate location for the calling convention; this should look a lot like what @alexcrichton is doing with `VMTrampoline` in wasmtime (see 3b7cb6ee64/crates/api/src/func.rs (L510-L526), 3b7cb6ee64/crates/jit/src/compiler.rs (L260)). To avoid re-compiling `Trampoline`s for the same function signatures, `Trampoline`s are cached in the `SingleFunctionCompiler`.
This commit is contained in:
Andrew Brown
2020-04-15 13:50:51 -07:00
parent 2048d3d30c
commit 38dff29179
8 changed files with 510 additions and 93 deletions

2
Cargo.lock generated
View File

@@ -409,6 +409,7 @@ version = "0.63.0"
dependencies = [
"byteorder",
"cranelift-codegen",
"cranelift-frontend",
"cranelift-native",
"cranelift-preopt",
"cranelift-reader",
@@ -420,6 +421,7 @@ dependencies = [
"num_cpus",
"region",
"target-lexicon",
"thiserror",
]
[[package]]