cranelift_codegen_meta/isa/
mod.rs1use crate::cdsl::isa::TargetIsa;
3use std::fmt;
4
5mod arm64;
6mod riscv64;
7mod s390x;
8pub(crate) mod x86;
9
10#[derive(PartialEq, Copy, Clone)]
12pub enum Isa {
13 X86,
14 Arm64,
15 S390x,
16 Riscv64,
17}
18
19impl Isa {
20 pub fn from_name(name: &str) -> Option<Self> {
22 Isa::all()
23 .iter()
24 .cloned()
25 .find(|isa| isa.to_string() == name)
26 }
27
28 pub fn from_arch(arch: &str) -> Option<Self> {
30 match arch {
31 "aarch64" => Some(Isa::Arm64),
32 "s390x" => Some(Isa::S390x),
33 x if ["x86_64", "i386", "i586", "i686"].contains(&x) => Some(Isa::X86),
34 "riscv64" | "riscv64gc" | "riscv64imac" => Some(Isa::Riscv64),
35 _ => None,
36 }
37 }
38
39 pub fn all() -> &'static [Isa] {
41 &[Isa::X86, Isa::Arm64, Isa::S390x, Isa::Riscv64]
42 }
43}
44
45impl fmt::Display for Isa {
46 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
48 match *self {
49 Isa::X86 => write!(f, "x86"),
50 Isa::Arm64 => write!(f, "arm64"),
51 Isa::S390x => write!(f, "s390x"),
52 Isa::Riscv64 => write!(f, "riscv64"),
53 }
54 }
55}
56
57pub(crate) fn define(isas: &[Isa]) -> Vec<TargetIsa> {
58 isas.iter()
59 .map(|isa| match isa {
60 Isa::X86 => x86::define(),
61 Isa::Arm64 => arm64::define(),
62 Isa::S390x => s390x::define(),
63 Isa::Riscv64 => riscv64::define(),
64 })
65 .collect()
66}