1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
13 #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Clone, Copy, Debug)]
15 // NB: This ordering MUST match the AbiDatas array below.
16 // (This is ensured by the test indices_are_correct().)
18 // Single platform ABIs
32 // Multiplatform / generic ABIs
42 #[derive(Copy, Clone)]
46 /// Name of this ABI as we like it called.
49 /// A generic ABI is supported on all platforms.
53 #[allow(non_upper_case_globals)]
54 const AbiDatas
: &[AbiData
] = &[
55 // Platform-specific ABIs
56 AbiData {abi: Abi::Cdecl, name: "cdecl", generic: false }
,
57 AbiData {abi: Abi::Stdcall, name: "stdcall", generic: false }
,
58 AbiData {abi: Abi::Fastcall, name: "fastcall", generic: false }
,
59 AbiData {abi: Abi::Vectorcall, name: "vectorcall", generic: false}
,
60 AbiData {abi: Abi::Thiscall, name: "thiscall", generic: false}
,
61 AbiData {abi: Abi::Aapcs, name: "aapcs", generic: false }
,
62 AbiData {abi: Abi::Win64, name: "win64", generic: false }
,
63 AbiData {abi: Abi::SysV64, name: "sysv64", generic: false }
,
64 AbiData {abi: Abi::PtxKernel, name: "ptx-kernel", generic: false }
,
65 AbiData {abi: Abi::Msp430Interrupt, name: "msp430-interrupt", generic: false }
,
66 AbiData {abi: Abi::X86Interrupt, name: "x86-interrupt", generic: false }
,
67 AbiData {abi: Abi::AmdGpuKernel, name: "amdgpu-kernel", generic: false }
,
69 // Cross-platform ABIs
70 AbiData {abi: Abi::Rust, name: "Rust", generic: true }
,
71 AbiData {abi: Abi::C, name: "C", generic: true }
,
72 AbiData {abi: Abi::System, name: "system", generic: true }
,
73 AbiData {abi: Abi::RustIntrinsic, name: "rust-intrinsic", generic: true }
,
74 AbiData {abi: Abi::RustCall, name: "rust-call", generic: true }
,
75 AbiData {abi: Abi::PlatformIntrinsic, name: "platform-intrinsic", generic: true }
,
76 AbiData {abi: Abi::Unadjusted, name: "unadjusted", generic: true }
,
79 /// Returns the ABI with the given name (if any).
80 pub fn lookup(name
: &str) -> Option
<Abi
> {
81 AbiDatas
.iter().find(|abi_data
| name
== abi_data
.name
).map(|&x
| x
.abi
)
84 pub fn all_names() -> Vec
<&'
static str> {
85 AbiDatas
.iter().map(|d
| d
.name
).collect()
90 pub fn index(self) -> usize {
95 pub fn data(self) -> &'
static AbiData
{
96 &AbiDatas
[self.index()]
99 pub fn name(self) -> &'
static str {
103 pub fn generic(self) -> bool
{
108 impl fmt
::Display
for Abi
{
109 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
110 write
!(f
, "\"{}\"", self.name())
114 #[allow(non_snake_case)]
117 let abi
= lookup("Rust");
118 assert
!(abi
.is_some() && abi
.unwrap().data().name
== "Rust");
123 let abi
= lookup("cdecl");
124 assert
!(abi
.is_some() && abi
.unwrap().data().name
== "cdecl");
129 let abi
= lookup("baz");
130 assert
!(abi
.is_none());
134 fn indices_are_correct() {
135 for (i
, abi_data
) in AbiDatas
.iter().enumerate() {
136 assert_eq
!(i
, abi_data
.abi
.index());