2014-02-19 18:56:33 -08:00
|
|
|
use std::fmt;
|
2013-03-13 22:25:28 -04:00
|
|
|
|
2019-11-09 22:27:52 +01:00
|
|
|
use rustc_macros::HashStable_Generic;
|
|
|
|
|
2019-08-01 03:20:03 +03:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
|
|
|
|
2020-06-11 15:49:57 +01:00
|
|
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Debug)]
|
|
|
|
#[derive(HashStable_Generic, Encodable, Decodable)]
|
2013-03-13 22:25:28 -04:00
|
|
|
pub enum Abi {
|
2018-11-27 02:59:49 +00:00
|
|
|
// N.B., this ordering MUST match the AbiDatas array below.
|
2013-03-13 22:25:28 -04:00
|
|
|
// (This is ensured by the test indices_are_correct().)
|
|
|
|
|
2020-06-01 22:20:12 -04:00
|
|
|
// Multiplatform / generic ABIs
|
|
|
|
//
|
|
|
|
// These ABIs come first because every time we add a new ABI, we
|
|
|
|
// have to re-bless all the hashing tests. These are used in many
|
|
|
|
// places, so giving them stable values reduces test churn. The
|
|
|
|
// specific values are meaningless.
|
|
|
|
Rust = 0,
|
|
|
|
C = 1,
|
|
|
|
|
2016-10-24 11:04:04 +02:00
|
|
|
// Single platform ABIs
|
2013-03-13 22:25:28 -04:00
|
|
|
Cdecl,
|
|
|
|
Stdcall,
|
|
|
|
Fastcall,
|
2015-12-26 21:29:28 +01:00
|
|
|
Vectorcall,
|
2017-05-17 09:40:46 -04:00
|
|
|
Thiscall,
|
2013-03-13 22:25:28 -04:00
|
|
|
Aapcs,
|
2013-11-16 18:25:56 -05:00
|
|
|
Win64,
|
2016-06-27 02:34:02 +02:00
|
|
|
SysV64,
|
2016-12-22 16:24:29 -05:00
|
|
|
PtxKernel,
|
2016-12-18 23:45:20 -05:00
|
|
|
Msp430Interrupt,
|
2017-02-14 21:39:42 +01:00
|
|
|
X86Interrupt,
|
2018-07-01 22:42:00 -05:00
|
|
|
AmdGpuKernel,
|
2019-10-24 15:29:29 +00:00
|
|
|
EfiApi,
|
2016-05-06 09:32:10 -04:00
|
|
|
AvrInterrupt,
|
|
|
|
AvrNonBlockingInterrupt,
|
2013-03-13 22:25:28 -04:00
|
|
|
|
2016-10-24 11:04:04 +02:00
|
|
|
// Multiplatform / generic ABIs
|
2013-11-08 11:06:57 -08:00
|
|
|
System,
|
2013-03-13 22:25:28 -04:00
|
|
|
RustIntrinsic,
|
2014-05-28 22:26:56 -07:00
|
|
|
RustCall,
|
2015-08-06 11:11:26 -07:00
|
|
|
PlatformIntrinsic,
|
2019-12-22 17:42:04 -05:00
|
|
|
Unadjusted,
|
2013-03-13 22:25:28 -04:00
|
|
|
}
|
|
|
|
|
2015-03-30 09:38:59 -04:00
|
|
|
#[derive(Copy, Clone)]
|
2014-02-27 18:48:21 +11:00
|
|
|
pub struct AbiData {
|
2013-03-13 22:25:28 -04:00
|
|
|
abi: Abi,
|
|
|
|
|
2016-10-24 11:04:04 +02:00
|
|
|
/// Name of this ABI as we like it called.
|
2013-03-13 22:25:28 -04:00
|
|
|
name: &'static str,
|
|
|
|
|
2016-10-24 11:04:04 +02:00
|
|
|
/// A generic ABI is supported on all platforms.
|
|
|
|
generic: bool,
|
2013-03-13 22:25:28 -04:00
|
|
|
}
|
|
|
|
|
2014-10-27 15:37:07 -07:00
|
|
|
#[allow(non_upper_case_globals)]
|
2018-08-09 15:42:43 +02:00
|
|
|
const AbiDatas: &[AbiData] = &[
|
2020-06-01 22:20:12 -04:00
|
|
|
// Cross-platform ABIs
|
|
|
|
AbiData { abi: Abi::Rust, name: "Rust", generic: true },
|
|
|
|
AbiData { abi: Abi::C, name: "C", generic: true },
|
2013-03-13 22:25:28 -04:00
|
|
|
// Platform-specific ABIs
|
2019-12-22 17:42:04 -05:00
|
|
|
AbiData { abi: Abi::Cdecl, name: "cdecl", generic: false },
|
|
|
|
AbiData { abi: Abi::Stdcall, name: "stdcall", generic: false },
|
|
|
|
AbiData { abi: Abi::Fastcall, name: "fastcall", generic: false },
|
|
|
|
AbiData { abi: Abi::Vectorcall, name: "vectorcall", generic: false },
|
|
|
|
AbiData { abi: Abi::Thiscall, name: "thiscall", generic: false },
|
|
|
|
AbiData { abi: Abi::Aapcs, name: "aapcs", generic: false },
|
|
|
|
AbiData { abi: Abi::Win64, name: "win64", generic: false },
|
|
|
|
AbiData { abi: Abi::SysV64, name: "sysv64", generic: false },
|
|
|
|
AbiData { abi: Abi::PtxKernel, name: "ptx-kernel", generic: false },
|
|
|
|
AbiData { abi: Abi::Msp430Interrupt, name: "msp430-interrupt", generic: false },
|
|
|
|
AbiData { abi: Abi::X86Interrupt, name: "x86-interrupt", generic: false },
|
|
|
|
AbiData { abi: Abi::AmdGpuKernel, name: "amdgpu-kernel", generic: false },
|
|
|
|
AbiData { abi: Abi::EfiApi, name: "efiapi", generic: false },
|
2016-05-06 09:32:10 -04:00
|
|
|
AbiData { abi: Abi::AvrInterrupt, name: "avr-interrupt", generic: false },
|
|
|
|
AbiData {
|
|
|
|
abi: Abi::AvrNonBlockingInterrupt,
|
|
|
|
name: "avr-non-blocking-interrupt",
|
|
|
|
generic: false,
|
|
|
|
},
|
2013-03-13 22:25:28 -04:00
|
|
|
// Cross-platform ABIs
|
2019-12-22 17:42:04 -05:00
|
|
|
AbiData { abi: Abi::System, name: "system", generic: true },
|
|
|
|
AbiData { abi: Abi::RustIntrinsic, name: "rust-intrinsic", generic: true },
|
|
|
|
AbiData { abi: Abi::RustCall, name: "rust-call", generic: true },
|
|
|
|
AbiData { abi: Abi::PlatformIntrinsic, name: "platform-intrinsic", generic: true },
|
|
|
|
AbiData { abi: Abi::Unadjusted, name: "unadjusted", generic: true },
|
2013-03-13 22:25:28 -04:00
|
|
|
];
|
|
|
|
|
2014-06-09 13:12:30 -07:00
|
|
|
/// Returns the ABI with the given name (if any).
|
2013-03-13 22:25:28 -04:00
|
|
|
pub fn lookup(name: &str) -> Option<Abi> {
|
2014-06-12 06:13:25 -04:00
|
|
|
AbiDatas.iter().find(|abi_data| name == abi_data.name).map(|&x| x.abi)
|
2013-03-13 22:25:28 -04:00
|
|
|
}
|
|
|
|
|
2014-02-28 13:09:09 -08:00
|
|
|
pub fn all_names() -> Vec<&'static str> {
|
2014-02-28 12:54:01 -08:00
|
|
|
AbiDatas.iter().map(|d| d.name).collect()
|
2013-03-13 22:25:28 -04:00
|
|
|
}
|
|
|
|
|
2013-05-31 15:17:22 -07:00
|
|
|
impl Abi {
|
2013-03-13 22:25:28 -04:00
|
|
|
#[inline]
|
2018-08-09 15:42:43 +02:00
|
|
|
pub fn index(self) -> usize {
|
|
|
|
self as usize
|
2013-03-13 22:25:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2018-08-09 15:42:43 +02:00
|
|
|
pub fn data(self) -> &'static AbiData {
|
2013-03-13 22:25:28 -04:00
|
|
|
&AbiDatas[self.index()]
|
|
|
|
}
|
|
|
|
|
2018-08-09 15:42:43 +02:00
|
|
|
pub fn name(self) -> &'static str {
|
2013-03-13 22:25:28 -04:00
|
|
|
self.data().name
|
|
|
|
}
|
2016-10-24 11:04:04 +02:00
|
|
|
|
2018-08-09 15:42:43 +02:00
|
|
|
pub fn generic(self) -> bool {
|
2016-10-24 11:04:04 +02:00
|
|
|
self.data().generic
|
|
|
|
}
|
2013-03-13 22:25:28 -04:00
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl fmt::Display for Abi {
|
2019-02-08 21:00:07 +09:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2014-05-10 14:05:06 -07:00
|
|
|
write!(f, "\"{}\"", self.name())
|
2013-03-13 22:25:28 -04:00
|
|
|
}
|
|
|
|
}
|