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.
11 pub use self::ArgKind::*;
15 use trans::context::CrateContext;
17 use trans::cabi_x86_64;
18 use trans::cabi_x86_win64;
20 use trans::cabi_aarch64;
21 use trans::cabi_powerpc;
23 use trans::type_::Type;
25 #[derive(Clone, Copy, PartialEq)]
27 /// Pass the argument directly using the normal converted
28 /// LLVM type or by coercing to another specified type
30 /// Pass the argument indirectly via a hidden pointer
32 /// Ignore the argument (useful for empty struct)
36 /// Information about how a specific C type
37 /// should be passed to or returned from a function
39 /// This is borrowed from clang's ABIInfo.h
40 #[derive(Clone, Copy)]
43 /// Original LLVM type
46 pub cast: option::Option<Type>,
47 /// Dummy argument, which is emitted before the real argument
48 pub pad: option::Option<Type>,
49 /// LLVM attribute of argument
50 pub attr: option::Option<Attribute>
54 pub fn direct(ty: Type, cast: option::Option<Type>,
55 pad: option::Option<Type>,
56 attr: option::Option<Attribute>) -> ArgType {
66 pub fn indirect(ty: Type, attr: option::Option<Attribute>) -> ArgType {
70 cast: option::Option::None,
71 pad: option::Option::None,
76 pub fn ignore(ty: Type) -> ArgType {
86 pub fn is_indirect(&self) -> bool {
87 return self.kind == Indirect;
90 pub fn is_ignore(&self) -> bool {
91 return self.kind == Ignore;
95 /// Metadata describing how the arguments to a native function
96 /// should be passed in order to respect the native ABI.
98 /// I will do my best to describe this structure, but these
99 /// comments are reverse-engineered and may be inaccurate. -NDM
101 /// The LLVM types of each argument.
102 pub arg_tys: Vec<ArgType> ,
104 /// LLVM return type.
108 pub fn compute_abi_info(ccx: &CrateContext,
111 ret_def: bool) -> FnType {
112 match &ccx.sess().target.target.arch[..] {
113 "x86" => cabi_x86::compute_abi_info(ccx, atys, rty, ret_def),
114 "x86_64" => if ccx.sess().target.target.options.is_like_windows {
115 cabi_x86_win64::compute_abi_info(ccx, atys, rty, ret_def)
117 cabi_x86_64::compute_abi_info(ccx, atys, rty, ret_def)
119 "aarch64" => cabi_aarch64::compute_abi_info(ccx, atys, rty, ret_def),
121 let flavor = if ccx.sess().target.target.target_os == "ios" {
122 cabi_arm::Flavor::Ios
124 cabi_arm::Flavor::General
126 cabi_arm::compute_abi_info(ccx, atys, rty, ret_def, flavor)
128 "mips" => cabi_mips::compute_abi_info(ccx, atys, rty, ret_def),
129 "powerpc" => cabi_powerpc::compute_abi_info(ccx, atys, rty, ret_def),
130 a => ccx.sess().fatal(&format!("unrecognized arch \"{}\" in target specification", a)