cranelift-filetest: Add support for Wasm-to-CLIF translation filetests (#5412)
This adds support for `.wat` tests in `cranelift-filetest`. The test runner translates the WAT to Wasm and then uses `cranelift-wasm` to translate the Wasm to CLIF. These tests are always precise output tests. The test expectations can be updated by running tests with the `CRANELIFT_TEST_BLESS=1` environment variable set, similar to our compile precise output tests. The test's expected output is contained in the last comment in the test file. The tests allow for configuring the kinds of heaps used to implement Wasm linear memory via TOML in a `;;!` comment at the start of the test. To get ISA and Cranelift flags parsing available in the filetests crate, I had to move the `parse_sets_and_triple` helper from the `cranelift-tools` binary crate to the `cranelift-reader` crate, where I think it logically fits. Additionally, I had to make some more bits of `cranelift-wasm`'s dummy environment `pub` so that I could properly wrap and compose it with the environment used for the `.wat` tests. I don't think this is a big deal, but if we eventually want to clean this stuff up, we can probably remove the dummy environments completely, remove `translate_module`, and fold them into these new test environments and test runner (since Wasmtime isn't using those things anyways).
This commit is contained in:
42
cranelift/filetests/filetests/wasm/basic-wat-test.wat
Normal file
42
cranelift/filetests/filetests/wasm/basic-wat-test.wat
Normal file
@@ -0,0 +1,42 @@
|
||||
;;! target = "x86_64"
|
||||
;;!
|
||||
;;! [globals.vmctx]
|
||||
;;! type = "i64"
|
||||
;;! vmctx = true
|
||||
;;!
|
||||
;;! [globals.heap_base]
|
||||
;;! type = "i64"
|
||||
;;! load = { base = "vmctx", offset = 0, readonly = true }
|
||||
;;!
|
||||
;;! [[heaps]]
|
||||
;;! base = "heap_base"
|
||||
;;! min_size = 0
|
||||
;;! offset_guard_size = 0xFFFFFFFF
|
||||
;;! index_type = "i32"
|
||||
;;! style = { kind = "static", bound = 0x1000 }
|
||||
|
||||
(module
|
||||
(memory 0)
|
||||
(func (param i32 i32) (result i32)
|
||||
local.get 0
|
||||
i32.load
|
||||
local.get 1
|
||||
i32.load
|
||||
i32.add))
|
||||
|
||||
;; function u0:0(i32, i32, i64 vmctx) -> i32 fast {
|
||||
;; gv0 = vmctx
|
||||
;; gv1 = load.i64 notrap aligned readonly gv0
|
||||
;; heap0 = static gv1, min 0, bound 4096, offset_guard 0xffff_ffff, index_type i32
|
||||
;;
|
||||
;; block0(v0: i32, v1: i32, v2: i64):
|
||||
;; @0021 v4 = heap_addr.i64 heap0, v0, 0, 4
|
||||
;; @0021 v5 = load.i32 little heap v4
|
||||
;; @0026 v6 = heap_addr.i64 heap0, v1, 0, 4
|
||||
;; @0026 v7 = load.i32 little heap v6
|
||||
;; @0029 v8 = iadd v5, v7
|
||||
;; @002a jump block1(v8)
|
||||
;;
|
||||
;; block1(v3: i32):
|
||||
;; @002a return v3
|
||||
;; }
|
||||
Reference in New Issue
Block a user