3 use rustc_macros::HashStable_Generic;
8 #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Debug)]
9 #[derive(HashStable_Generic, Encodable, Decodable)]
11 // Some of the ABIs come first because every time we add a new ABI, we have to re-bless all the
12 // hashing tests. These are used in many places, so giving them stable values reduces test
13 // churn. The specific values are meaningless.
17 Stdcall { unwind: bool },
20 Thiscall { unwind: bool },
30 AvrNonBlockingInterrupt,
33 System { unwind: bool },
40 #[derive(Copy, Clone)]
44 /// Name of this ABI as we like it called.
48 #[allow(non_upper_case_globals)]
49 const AbiDatas: &[AbiData] = &[
50 AbiData { abi: Abi::Rust, name: "Rust" },
51 AbiData { abi: Abi::C { unwind: false }, name: "C" },
52 AbiData { abi: Abi::C { unwind: true }, name: "C-unwind" },
53 AbiData { abi: Abi::Cdecl, name: "cdecl" },
54 AbiData { abi: Abi::Stdcall { unwind: false }, name: "stdcall" },
55 AbiData { abi: Abi::Stdcall { unwind: true }, name: "stdcall-unwind" },
56 AbiData { abi: Abi::Fastcall, name: "fastcall" },
57 AbiData { abi: Abi::Vectorcall, name: "vectorcall" },
58 AbiData { abi: Abi::Thiscall { unwind: false }, name: "thiscall" },
59 AbiData { abi: Abi::Thiscall { unwind: true }, name: "thiscall-unwind" },
60 AbiData { abi: Abi::Aapcs, name: "aapcs" },
61 AbiData { abi: Abi::Win64, name: "win64" },
62 AbiData { abi: Abi::SysV64, name: "sysv64" },
63 AbiData { abi: Abi::PtxKernel, name: "ptx-kernel" },
64 AbiData { abi: Abi::Msp430Interrupt, name: "msp430-interrupt" },
65 AbiData { abi: Abi::X86Interrupt, name: "x86-interrupt" },
66 AbiData { abi: Abi::AmdGpuKernel, name: "amdgpu-kernel" },
67 AbiData { abi: Abi::EfiApi, name: "efiapi" },
68 AbiData { abi: Abi::AvrInterrupt, name: "avr-interrupt" },
69 AbiData { abi: Abi::AvrNonBlockingInterrupt, name: "avr-non-blocking-interrupt" },
70 AbiData { abi: Abi::CCmseNonSecureCall, name: "C-cmse-nonsecure-call" },
71 AbiData { abi: Abi::Wasm, name: "wasm" },
72 AbiData { abi: Abi::System { unwind: false }, name: "system" },
73 AbiData { abi: Abi::System { unwind: true }, name: "system-unwind" },
74 AbiData { abi: Abi::RustIntrinsic, name: "rust-intrinsic" },
75 AbiData { abi: Abi::RustCall, name: "rust-call" },
76 AbiData { abi: Abi::PlatformIntrinsic, name: "platform-intrinsic" },
77 AbiData { abi: Abi::Unadjusted, name: "unadjusted" },
80 /// Returns the ABI with the given name (if any).
81 pub fn lookup(name: &str) -> Option<Abi> {
82 AbiDatas.iter().find(|abi_data| name == abi_data.name).map(|&x| x.abi)
85 pub fn all_names() -> Vec<&'static str> {
86 AbiDatas.iter().map(|d| d.name).collect()
90 /// Default ABI chosen for `extern fn` declarations without an explicit ABI.
91 pub const FALLBACK: Abi = Abi::C { unwind: false };
94 pub fn index(self) -> usize {
95 // N.B., this ordering MUST match the AbiDatas array above.
96 // (This is ensured by the test indices_are_correct().)
99 // Cross-platform ABIs
101 C { unwind: false } => 1,
102 C { unwind: true } => 2,
103 // Platform-specific ABIs
105 Stdcall { unwind: false } => 4,
106 Stdcall { unwind: true } => 5,
109 Thiscall { unwind: false } => 8,
110 Thiscall { unwind: true } => 9,
115 Msp430Interrupt => 14,
120 AvrNonBlockingInterrupt => 19,
121 CCmseNonSecureCall => 20,
123 // Cross-platform ABIs
124 System { unwind: false } => 22,
125 System { unwind: true } => 23,
128 PlatformIntrinsic => 26,
135 .find(|(_, AbiData { abi, .. })| *abi == self)
136 .map(|(index, _)| index)
137 .expect("abi variant has associated data")
139 "Abi index did not match `AbiDatas` ordering"
145 pub fn data(self) -> &'static AbiData {
146 &AbiDatas[self.index()]
149 pub fn name(self) -> &'static str {
154 impl fmt::Display for Abi {
155 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
157 abi => write!(f, "\"{}\"", abi.name()),