Path: blob/main/cranelift/codegen/meta/src/isa/mod.rs
1693 views
//! Define supported ISAs; includes ISA-specific instructions, encodings, registers, settings, etc.1use crate::cdsl::isa::TargetIsa;2use std::fmt;34mod arm64;5mod pulley;6mod riscv64;7mod s390x;8pub(crate) mod x86;910/// Represents known ISA target.11#[derive(PartialEq, Copy, Clone)]12pub enum Isa {13X86,14Arm64,15S390x,16Riscv64,17Pulley32,18Pulley64,19}2021impl Isa {22/// Creates isa target using name.23pub fn from_name(name: &str) -> Option<Self> {24Isa::all()25.iter()26.cloned()27.find(|isa| isa.to_string() == name)28}2930/// Creates isa target from arch.31pub fn from_arch(arch: &str) -> Option<Self> {32match arch {33"aarch64" => Some(Isa::Arm64),34"s390x" => Some(Isa::S390x),35x if ["x86_64", "i386", "i586", "i686"].contains(&x) => Some(Isa::X86),36"riscv64" | "riscv64gc" | "riscv64imac" => Some(Isa::Riscv64),37"pulley32" => Some(Isa::Pulley32),38"pulley64" => Some(Isa::Pulley64),39_ => None,40}41}4243/// Returns all supported isa targets.44pub fn all() -> &'static [Isa] {45&[46Isa::X86,47Isa::Arm64,48Isa::S390x,49Isa::Riscv64,50Isa::Pulley32,51Isa::Pulley64,52]53}54}5556impl fmt::Display for Isa {57// These names should be kept in sync with the crate features.58fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {59match *self {60Isa::X86 => write!(f, "x86"),61Isa::Arm64 => write!(f, "arm64"),62Isa::S390x => write!(f, "s390x"),63Isa::Riscv64 => write!(f, "riscv64"),64Isa::Pulley32 => write!(f, "pulley32"),65Isa::Pulley64 => write!(f, "pulley64"),66}67}68}6970pub(crate) fn define(isas: &[Isa]) -> Vec<TargetIsa> {71isas.iter()72.map(|isa| match isa {73Isa::X86 => x86::define(),74Isa::Arm64 => arm64::define(),75Isa::S390x => s390x::define(),76Isa::Riscv64 => riscv64::define(),77Isa::Pulley32 | Isa::Pulley64 => pulley::define(),78})79.collect()80}818283