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()
91 pub fn index(self) -> usize {
92 // N.B., this ordering MUST match the AbiDatas array above.
93 // (This is ensured by the test indices_are_correct().)
96 // Cross-platform ABIs
98 C { unwind: false } => 1,
99 C { unwind: true } => 2,
100 // Platform-specific ABIs
102 Stdcall { unwind: false } => 4,
103 Stdcall { unwind: true } => 5,
106 Thiscall { unwind: false } => 8,
107 Thiscall { unwind: true } => 9,
112 Msp430Interrupt => 14,
117 AvrNonBlockingInterrupt => 19,
118 CCmseNonSecureCall => 20,
120 // Cross-platform ABIs
121 System { unwind: false } => 22,
122 System { unwind: true } => 23,
125 PlatformIntrinsic => 26,
132 .find(|(_, AbiData { abi, .. })| *abi == self)
133 .map(|(index, _)| index)
134 .expect("abi variant has associated data")
136 "Abi index did not match `AbiDatas` ordering"
142 pub fn data(self) -> &'static AbiData {
143 &AbiDatas[self.index()]
146 pub fn name(self) -> &'static str {
151 impl fmt::Display for Abi {
152 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
154 abi => write!(f, "\"{}\"", abi.name()),