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;
22 use trans::type_::Type;
24 #[derive(Clone, Copy, PartialEq)]
26 /// Pass the argument directly using the normal converted
27 /// LLVM type or by coercing to another specified type
29 /// Pass the argument indirectly via a hidden pointer
31 /// Ignore the argument (useful for empty struct)
35 /// Information about how a specific C type
36 /// should be passed to or returned from a function
38 /// This is borrowed from clang's ABIInfo.h
39 #[derive(Clone, Copy)]
42 /// Original LLVM type
45 pub cast: option::Option<Type>,
46 /// Dummy argument, which is emitted before the real argument
47 pub pad: option::Option<Type>,
48 /// LLVM attribute of argument
49 pub attr: option::Option<Attribute>
53 pub fn direct(ty: Type, cast: option::Option<Type>,
54 pad: option::Option<Type>,
55 attr: option::Option<Attribute>) -> ArgType {
65 pub fn indirect(ty: Type, attr: option::Option<Attribute>) -> ArgType {
69 cast: option::Option::None,
70 pad: option::Option::None,
75 pub fn ignore(ty: Type) -> ArgType {
85 pub fn is_indirect(&self) -> bool {
86 return self.kind == Indirect;
89 pub fn is_ignore(&self) -> bool {
90 return self.kind == Ignore;
94 /// Metadata describing how the arguments to a native function
95 /// should be passed in order to respect the native ABI.
97 /// I will do my best to describe this structure, but these
98 /// comments are reverse-engineered and may be inaccurate. -NDM
100 /// The LLVM types of each argument.
101 pub arg_tys: Vec<ArgType> ,
103 /// LLVM return type.
107 pub fn compute_abi_info(ccx: &CrateContext,
110 ret_def: bool) -> FnType {
111 match ccx.sess().target.target.arch[] {
112 "x86" => cabi_x86::compute_abi_info(ccx, atys, rty, ret_def),
113 "x86_64" => if ccx.sess().target.target.options.is_like_windows {
114 cabi_x86_win64::compute_abi_info(ccx, atys, rty, ret_def)
116 cabi_x86_64::compute_abi_info(ccx, atys, rty, ret_def)
118 "arm" => cabi_arm::compute_abi_info(ccx, atys, rty, ret_def),
119 "aarch64" => cabi_aarch64::compute_abi_info(ccx, atys, rty, ret_def),
120 "mips" => cabi_mips::compute_abi_info(ccx, atys, rty, ret_def),
121 a => ccx.sess().fatal((format!("unrecognized arch \"{}\" in target specification", a))