Files
wasmtime/cranelift/filetests/src/test_vcode.rs
Chris Fallin 48cf2c2f50 Address review comments:
- Undo temporary changes to default features (`all-arch`) and a
  signal-handler test.
- Remove `SIGTRAP` handler: no longer needed now that we've found an
  "undefined opcode" option on ARM64.
- Rename pp.rs to pretty_print.rs in machinst/.
- Only use empty stack-probe on non-x86. As per a comment in
  rust-lang/compiler-builtins [1], LLVM only supports stack probes on
  x86 and x86-64. Thus, on any other CPU architecture, we cannot refer
  to `__rust_probestack`, because it does not exist.
- Rename arm64 to aarch64.
- Use `target` directive in vcode filetests.
- Run the flags verifier, but without encinfo, when using new backends.
- Clean up warning overrides.
- Fix up use of casts: use u32::from(x) and siblings when possible,
  u32::try_from(x).unwrap() when not, to avoid silent truncation.
- Take immutable `Function` borrows as input; we don't actually
  mutate the input IR.
- Lots of other miscellaneous cleanups.

[1] cae3e6ea23/src/probestack.rs (L39)
2020-04-15 17:21:28 -07:00

68 lines
1.8 KiB
Rust

use crate::subtest::{run_filecheck, Context, SubTest, SubtestResult};
use cranelift_codegen::ir::Function;
use cranelift_codegen::isa::lookup;
use cranelift_codegen::settings;
use cranelift_codegen::Context as CodegenContext;
use cranelift_reader::{TestCommand, TestOption};
use log::info;
use std::borrow::Cow;
use std::string::String;
struct TestVCode {
arch: String,
}
pub fn subtest(parsed: &TestCommand) -> SubtestResult<Box<dyn SubTest>> {
assert_eq!(parsed.command, "vcode");
let mut arch = "arm64".to_string();
for option in &parsed.options {
match option {
TestOption::Value(k, v) if k == &"arch" => {
arch = v.to_string();
}
_ => {}
}
}
Ok(Box::new(TestVCode { arch }))
}
impl SubTest for TestVCode {
fn name(&self) -> &'static str {
"vcode"
}
fn is_mutating(&self) -> bool {
true
}
fn needs_isa(&self) -> bool {
true
}
fn run(&self, func: Cow<Function>, context: &Context) -> SubtestResult<()> {
let triple = context.isa.unwrap().triple().clone();
let func = func.into_owned();
let mut isa = lookup(triple)
.map_err(|_| format!("Could not look up backend for arch '{}'", self.arch))?
.finish(settings::Flags::new(settings::builder()));
let mut codectx = CodegenContext::for_function(func);
codectx.set_disasm(true);
codectx
.compile(&mut *isa)
.map_err(|e| format!("Could not compile with arch '{}': {:?}", self.arch, e))?;
let result = codectx.mach_compile_result.take().unwrap();
let text = result.disasm.unwrap();
info!("text input to filecheck is:\n{}\n", text);
run_filecheck(&text, context)
}
}