Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/cranelift/codegen/meta/src/isa/mod.rs
1693 views
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 pulley;
7
mod riscv64;
8
mod s390x;
9
pub(crate) mod x86;
10
11
/// Represents known ISA target.
12
#[derive(PartialEq, Copy, Clone)]
13
pub enum Isa {
14
X86,
15
Arm64,
16
S390x,
17
Riscv64,
18
Pulley32,
19
Pulley64,
20
}
21
22
impl Isa {
23
/// Creates isa target using name.
24
pub fn from_name(name: &str) -> Option<Self> {
25
Isa::all()
26
.iter()
27
.cloned()
28
.find(|isa| isa.to_string() == name)
29
}
30
31
/// Creates isa target from arch.
32
pub fn from_arch(arch: &str) -> Option<Self> {
33
match arch {
34
"aarch64" => Some(Isa::Arm64),
35
"s390x" => Some(Isa::S390x),
36
x if ["x86_64", "i386", "i586", "i686"].contains(&x) => Some(Isa::X86),
37
"riscv64" | "riscv64gc" | "riscv64imac" => Some(Isa::Riscv64),
38
"pulley32" => Some(Isa::Pulley32),
39
"pulley64" => Some(Isa::Pulley64),
40
_ => None,
41
}
42
}
43
44
/// Returns all supported isa targets.
45
pub fn all() -> &'static [Isa] {
46
&[
47
Isa::X86,
48
Isa::Arm64,
49
Isa::S390x,
50
Isa::Riscv64,
51
Isa::Pulley32,
52
Isa::Pulley64,
53
]
54
}
55
}
56
57
impl fmt::Display for Isa {
58
// These names should be kept in sync with the crate features.
59
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
60
match *self {
61
Isa::X86 => write!(f, "x86"),
62
Isa::Arm64 => write!(f, "arm64"),
63
Isa::S390x => write!(f, "s390x"),
64
Isa::Riscv64 => write!(f, "riscv64"),
65
Isa::Pulley32 => write!(f, "pulley32"),
66
Isa::Pulley64 => write!(f, "pulley64"),
67
}
68
}
69
}
70
71
pub(crate) fn define(isas: &[Isa]) -> Vec<TargetIsa> {
72
isas.iter()
73
.map(|isa| match isa {
74
Isa::X86 => x86::define(),
75
Isa::Arm64 => arm64::define(),
76
Isa::S390x => s390x::define(),
77
Isa::Riscv64 => riscv64::define(),
78
Isa::Pulley32 | Isa::Pulley64 => pulley::define(),
79
})
80
.collect()
81
}
82
83