3 use rustc_macros::HashStable_Generic;
8 #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Debug)]
9 #[derive(HashStable_Generic, Encodable, Decodable)]
11 // Multiplatform / generic ABIs
13 // These ABIs come first because every time we add a new ABI, we
14 // have to re-bless all the hashing tests. These are used in many
15 // places, so giving them stable values reduces test churn. The
16 // specific values are meaningless.
20 // Single platform ABIs
22 Stdcall { unwind: bool },
25 Thiscall { unwind: bool },
35 AvrNonBlockingInterrupt,
38 // Multiplatform / generic ABIs
39 System { unwind: bool },
46 #[derive(Copy, Clone)]
50 /// Name of this ABI as we like it called.
53 /// A generic ABI is supported on all platforms.
57 #[allow(non_upper_case_globals)]
58 const AbiDatas: &[AbiData] = &[
59 // Cross-platform ABIs
60 AbiData { abi: Abi::Rust, name: "Rust", generic: true },
61 AbiData { abi: Abi::C { unwind: false }, name: "C", generic: true },
62 AbiData { abi: Abi::C { unwind: true }, name: "C-unwind", generic: true },
63 // Platform-specific ABIs
64 AbiData { abi: Abi::Cdecl, name: "cdecl", generic: false },
65 AbiData { abi: Abi::Stdcall { unwind: false }, name: "stdcall", generic: false },
66 AbiData { abi: Abi::Stdcall { unwind: true }, name: "stdcall-unwind", generic: false },
67 AbiData { abi: Abi::Fastcall, name: "fastcall", generic: false },
68 AbiData { abi: Abi::Vectorcall, name: "vectorcall", generic: false },
69 AbiData { abi: Abi::Thiscall { unwind: false }, name: "thiscall", generic: false },
70 AbiData { abi: Abi::Thiscall { unwind: true }, name: "thiscall-unwind", generic: false },
71 AbiData { abi: Abi::Aapcs, name: "aapcs", generic: false },
72 AbiData { abi: Abi::Win64, name: "win64", generic: false },
73 AbiData { abi: Abi::SysV64, name: "sysv64", generic: false },
74 AbiData { abi: Abi::PtxKernel, name: "ptx-kernel", generic: false },
75 AbiData { abi: Abi::Msp430Interrupt, name: "msp430-interrupt", generic: false },
76 AbiData { abi: Abi::X86Interrupt, name: "x86-interrupt", generic: false },
77 AbiData { abi: Abi::AmdGpuKernel, name: "amdgpu-kernel", generic: false },
78 AbiData { abi: Abi::EfiApi, name: "efiapi", generic: false },
79 AbiData { abi: Abi::AvrInterrupt, name: "avr-interrupt", generic: false },
81 abi: Abi::AvrNonBlockingInterrupt,
82 name: "avr-non-blocking-interrupt",
85 AbiData { abi: Abi::CCmseNonSecureCall, name: "C-cmse-nonsecure-call", generic: false },
86 // Cross-platform ABIs
87 AbiData { abi: Abi::System { unwind: false }, name: "system", generic: true },
88 AbiData { abi: Abi::System { unwind: true }, name: "system-unwind", generic: true },
89 AbiData { abi: Abi::RustIntrinsic, name: "rust-intrinsic", generic: true },
90 AbiData { abi: Abi::RustCall, name: "rust-call", generic: true },
91 AbiData { abi: Abi::PlatformIntrinsic, name: "platform-intrinsic", generic: true },
92 AbiData { abi: Abi::Unadjusted, name: "unadjusted", generic: true },
95 /// Returns the ABI with the given name (if any).
96 pub fn lookup(name: &str) -> Option<Abi> {
97 AbiDatas.iter().find(|abi_data| name == abi_data.name).map(|&x| x.abi)
100 pub fn all_names() -> Vec<&'static str> {
101 AbiDatas.iter().map(|d| d.name).collect()
106 pub fn index(self) -> usize {
107 // N.B., this ordering MUST match the AbiDatas array above.
108 // (This is ensured by the test indices_are_correct().)
111 // Cross-platform ABIs
113 C { unwind: false } => 1,
114 C { unwind: true } => 2,
115 // Platform-specific ABIs
117 Stdcall { unwind: false } => 4,
118 Stdcall { unwind: true } => 5,
121 Thiscall { unwind: false } => 8,
122 Thiscall { unwind: true } => 9,
127 Msp430Interrupt => 14,
132 AvrNonBlockingInterrupt => 19,
133 CCmseNonSecureCall => 20,
134 // Cross-platform ABIs
135 System { unwind: false } => 21,
136 System { unwind: true } => 22,
139 PlatformIntrinsic => 25,
146 .find(|(_, AbiData { abi, .. })| *abi == self)
147 .map(|(index, _)| index)
148 .expect("abi variant has associated data")
150 "Abi index did not match `AbiDatas` ordering"
156 pub fn data(self) -> &'static AbiData {
157 &AbiDatas[self.index()]
160 pub fn name(self) -> &'static str {
164 pub fn generic(self) -> bool {
169 impl fmt::Display for Abi {
170 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
172 abi => write!(f, "\"{}\"", abi.name()),