Browse Source

cranelift: Add some libcalls to `test interpret` (#7320)

pull/7324/head
Afonso Bordado 1 year ago
committed by GitHub
parent
commit
9bb6b1b579
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      Cargo.lock
  2. 3
      cranelift/filetests/Cargo.toml
  3. 5
      cranelift/filetests/filetests/runtests/call_libcall.clif
  4. 21
      cranelift/filetests/src/test_interpret.rs

1
Cargo.lock

@ -647,6 +647,7 @@ dependencies = [
"serde",
"serde_derive",
"similar",
"smallvec",
"target-lexicon",
"thiserror",
"toml",

3
cranelift/filetests/Cargo.toml

@ -26,7 +26,7 @@ num_cpus = "1.8.0"
target-lexicon = { workspace = true }
thiserror = { workspace = true }
anyhow = { workspace = true }
similar ={ workspace = true }
similar = { workspace = true }
wat.workspace = true
toml = { workspace = true }
serde = { workspace = true }
@ -34,3 +34,4 @@ serde_derive = { workspace = true }
cranelift-wasm.workspace = true
wasmparser.workspace = true
cranelift.workspace = true
smallvec = { workspace = true }

5
cranelift/filetests/filetests/runtests/call_libcall.clif

@ -1,6 +1,9 @@
test interpret
test run
target x86_64
; AArch64 Does not have these libcalls
target aarch64
target aarch64 sign_return_address
target aarch64 has_pauth sign_return_address
target s390x
target riscv64
target riscv64 has_c has_zcb

21
cranelift/filetests/src/test_interpret.rs

@ -6,15 +6,17 @@
use crate::runone::FileUpdate;
use crate::subtest::SubTest;
use anyhow::Context;
use cranelift_codegen::ir::Function;
use cranelift_codegen::data_value::DataValue;
use cranelift_codegen::ir::{Function, LibCall};
use cranelift_codegen::isa::TargetIsa;
use cranelift_codegen::settings::Flags;
use cranelift_codegen::{self, ir};
use cranelift_interpreter::environment::FunctionStore;
use cranelift_interpreter::interpreter::{Interpreter, InterpreterState};
use cranelift_interpreter::interpreter::{Interpreter, InterpreterState, LibCallValues};
use cranelift_interpreter::step::ControlFlow;
use cranelift_reader::{parse_run_command, Details, TestCommand, TestFile};
use log::{info, trace};
use smallvec::smallvec;
use std::borrow::Cow;
struct TestInterpret;
@ -83,7 +85,20 @@ fn run_test(func_store: &FunctionStore, func: &Function, details: &Details) -> a
.run(|func_name, run_args| {
// Rebuild the interpreter state on every run to ensure that we don't accidentally depend on
// some leftover state
let state = InterpreterState::default().with_function_store(func_store.clone());
let state = InterpreterState::default()
.with_function_store(func_store.clone())
.with_libcall_handler(|libcall: LibCall, args: LibCallValues| {
use LibCall::*;
Ok(smallvec![match (libcall, &args[..]) {
(CeilF32, [DataValue::F32(a)]) => DataValue::F32(a.ceil()),
(CeilF64, [DataValue::F64(a)]) => DataValue::F64(a.ceil()),
(FloorF32, [DataValue::F32(a)]) => DataValue::F32(a.floor()),
(FloorF64, [DataValue::F64(a)]) => DataValue::F64(a.floor()),
(TruncF32, [DataValue::F32(a)]) => DataValue::F32(a.trunc()),
(TruncF64, [DataValue::F64(a)]) => DataValue::F64(a.trunc()),
_ => unreachable!(),
}])
});
let mut args = Vec::with_capacity(run_args.len());
args.extend_from_slice(run_args);

Loading…
Cancel
Save