1 //! Define supported ISAs; includes ISA-specific instructions, encodings, registers, settings, etc. 2 use crate::cdsl::isa::TargetIsa; 3 use std::fmt; 4 5 mod arm64; 6 mod riscv64; 7 mod s390x; 8 pub(crate) mod x86; 9 10 /// Represents known ISA target. 11 #[derive(PartialEq, Copy, Clone)] 12 pub enum Isa { 13 X86, 14 Arm64, 15 S390x, 16 Riscv64, 17 } 18 19 impl Isa { 20 /// Creates isa target using name. 21 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 /// Creates isa target from arch. 29 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 /// Returns all supported isa targets. 40 pub fn all() -> &'static [Isa] { 41 &[Isa::X86, Isa::Arm64, Isa::S390x, Isa::Riscv64] 42 } 43 } 44 45 impl fmt::Display for Isa { 46 // These names should be kept in sync with the crate features. 47 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 57 pub(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 } 67