rust/compiler/rustc_target/src/spec/abi.rs

126 lines
3.7 KiB
Rust
Raw Normal View History

use std::fmt;
use rustc_macros::HashStable_Generic;
#[cfg(test)]
mod tests;
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Debug)]
#[derive(HashStable_Generic, Encodable, Decodable)]
pub enum Abi {
// N.B., this ordering MUST match the AbiDatas array below.
// (This is ensured by the test indices_are_correct().)
// 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
Cdecl,
Stdcall,
Fastcall,
Vectorcall,
Thiscall,
Aapcs,
2013-11-16 18:25:56 -05:00
Win64,
SysV64,
PtxKernel,
Msp430Interrupt,
X86Interrupt,
AmdGpuKernel,
EfiApi,
2016-05-06 09:32:10 -04:00
AvrInterrupt,
AvrNonBlockingInterrupt,
2016-10-24 11:04:04 +02:00
// Multiplatform / generic ABIs
System,
RustIntrinsic,
RustCall,
PlatformIntrinsic,
2019-12-22 17:42:04 -05:00
Unadjusted,
}
2015-03-30 09:38:59 -04:00
#[derive(Copy, Clone)]
pub struct AbiData {
abi: Abi,
2016-10-24 11:04:04 +02:00
/// Name of this ABI as we like it called.
name: &'static str,
2016-10-24 11:04:04 +02:00
/// A generic ABI is supported on all platforms.
generic: bool,
}
2014-10-27 15:37:07 -07:00
#[allow(non_upper_case_globals)]
2018-08-09 15:42:43 +02:00
const AbiDatas: &[AbiData] = &[
// Cross-platform ABIs
AbiData { abi: Abi::Rust, name: "Rust", generic: true },
AbiData { abi: Abi::C, name: "C", generic: true },
// 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,
},
// 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 },
];
2014-06-09 13:12:30 -07:00
/// Returns the ABI with the given name (if any).
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)
}
pub fn all_names() -> Vec<&'static str> {
AbiDatas.iter().map(|d| d.name).collect()
}
impl Abi {
#[inline]
2018-08-09 15:42:43 +02:00
pub fn index(self) -> usize {
self as usize
}
#[inline]
2018-08-09 15:42:43 +02:00
pub fn data(self) -> &'static AbiData {
&AbiDatas[self.index()]
}
2018-08-09 15:42:43 +02:00
pub fn name(self) -> &'static str {
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
}
}
std: Rename Show/String to Debug/Display This commit is an implementation of [RFC 565][rfc] which is a stabilization of the `std::fmt` module and the implementations of various formatting traits. Specifically, the following changes were performed: [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0565-show-string-guidelines.md * The `Show` trait is now deprecated, it was renamed to `Debug` * The `String` trait is now deprecated, it was renamed to `Display` * Many `Debug` and `Display` implementations were audited in accordance with the RFC and audited implementations now have the `#[stable]` attribute * Integers and floats no longer print a suffix * Smart pointers no longer print details that they are a smart pointer * Paths with `Debug` are now quoted and escape characters * The `unwrap` methods on `Result` now require `Display` instead of `Debug` * The `Error` trait no longer has a `detail` method and now requires that `Display` must be implemented. With the loss of `String`, this has moved into libcore. * `impl<E: Error> FromError<E> for Box<Error>` now exists * `derive(Show)` has been renamed to `derive(Debug)`. This is not currently warned about due to warnings being emitted on stage1+ While backwards compatibility is attempted to be maintained with a blanket implementation of `Display` for the old `String` trait (and the same for `Show`/`Debug`) this is still a breaking change due to primitives no longer implementing `String` as well as modifications such as `unwrap` and the `Error` trait. Most code is fairly straightforward to update with a rename or tweaks of method calls. [breaking-change] Closes #21436
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 {
write!(f, "\"{}\"", self.name())
}
}