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, 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
31 // Multiplatform / generic ABIs
41 #[derive(Copy, Clone)]
45 /// Name of this ABI as we like it called.
48 /// A generic ABI is supported on all platforms.
52 #[allow(non_upper_case_globals)]
53 const AbiDatas: &'static [AbiData] = &[
54 // Platform-specific ABIs
55 AbiData {abi: Abi::Cdecl, name: "cdecl", generic: false },
56 AbiData {abi: Abi::Stdcall, name: "stdcall", generic: false },
57 AbiData {abi: Abi::Fastcall, name: "fastcall", generic: false },
58 AbiData {abi: Abi::Vectorcall, name: "vectorcall", generic: false},
59 AbiData {abi: Abi::Thiscall, name: "thiscall", generic: false},
60 AbiData {abi: Abi::Aapcs, name: "aapcs", generic: false },
61 AbiData {abi: Abi::Win64, name: "win64", generic: false },
62 AbiData {abi: Abi::SysV64, name: "sysv64", generic: false },
63 AbiData {abi: Abi::PtxKernel, name: "ptx-kernel", generic: false },
64 AbiData {abi: Abi::Msp430Interrupt, name: "msp430-interrupt", generic: false },
65 AbiData {abi: Abi::X86Interrupt, name: "x86-interrupt", generic: false },
67 // Cross-platform ABIs
68 AbiData {abi: Abi::Rust, name: "Rust", generic: true },
69 AbiData {abi: Abi::C, name: "C", generic: true },
70 AbiData {abi: Abi::System, name: "system", generic: true },
71 AbiData {abi: Abi::RustIntrinsic, name: "rust-intrinsic", generic: true },
72 AbiData {abi: Abi::RustCall, name: "rust-call", generic: true },
73 AbiData {abi: Abi::PlatformIntrinsic, name: "platform-intrinsic", generic: true },
74 AbiData {abi: Abi::Unadjusted, name: "unadjusted", generic: true },
77 /// Returns the ABI with the given name (if any).
78 pub fn lookup(name: &str) -> Option<Abi> {
79 AbiDatas.iter().find(|abi_data| name == abi_data.name).map(|&x| x.abi)
82 pub fn all_names() -> Vec<&'static str> {
83 AbiDatas.iter().map(|d| d.name).collect()
88 pub fn index(&self) -> usize {
93 pub fn data(&self) -> &'static AbiData {
94 &AbiDatas[self.index()]
97 pub fn name(&self) -> &'static str {
101 pub fn generic(&self) -> bool {
106 impl fmt::Display for Abi {
107 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
108 write!(f, "\"{}\"", self.name())
112 #[allow(non_snake_case)]
115 let abi = lookup("Rust");
116 assert!(abi.is_some() && abi.unwrap().data().name == "Rust");
121 let abi = lookup("cdecl");
122 assert!(abi.is_some() && abi.unwrap().data().name == "cdecl");
127 let abi = lookup("baz");
128 assert!(abi.is_none());
132 fn indices_are_correct() {
133 for (i, abi_data) in AbiDatas.iter().enumerate() {
134 assert_eq!(i, abi_data.abi.index());