1 // Copyright 2012 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 use lib::llvm::Attribute;
13 use middle::trans::context::CrateContext;
14 use middle::trans::cabi_x86;
15 use middle::trans::cabi_x86_64;
16 use middle::trans::cabi_arm;
17 use middle::trans::cabi_mips;
18 use middle::trans::type_::Type;
19 use syntax::abi::{X86, X86_64, Arm, Mips};
21 #[deriving(Clone, Eq)]
23 /// Pass the argument directly using the normal converted
24 /// LLVM type or by coercing to another specified type
26 /// Pass the argument indirectly via a hidden pointer
30 /// Information about how a specific C type
31 /// should be passed to or returned from a function
33 /// This is borrowed from clang's ABIInfo.h
37 /// Original LLVM type
40 cast: option::Option<Type>,
41 /// Dummy argument, which is emitted before the real argument
42 pad: option::Option<Type>,
43 /// LLVM attribute of argument
44 attr: option::Option<Attribute>
48 pub fn direct(ty: Type, cast: option::Option<Type>,
49 pad: option::Option<Type>,
50 attr: option::Option<Attribute>) -> ArgType {
60 pub fn indirect(ty: Type, attr: option::Option<Attribute>) -> ArgType {
70 pub fn is_direct(&self) -> bool {
71 return self.kind == Direct;
74 pub fn is_indirect(&self) -> bool {
75 return self.kind == Indirect;
79 /// Metadata describing how the arguments to a native function
80 /// should be passed in order to respect the native ABI.
82 /// I will do my best to describe this structure, but these
83 /// comments are reverse-engineered and may be inaccurate. -NDM
85 /// The LLVM types of each argument.
92 pub fn compute_abi_info(ccx: &CrateContext,
95 ret_def: bool) -> FnType {
96 match ccx.sess.targ_cfg.arch {
97 X86 => cabi_x86::compute_abi_info(ccx, atys, rty, ret_def),
98 X86_64 => cabi_x86_64::compute_abi_info(ccx, atys, rty, ret_def),
99 Arm => cabi_arm::compute_abi_info(ccx, atys, rty, ret_def),
100 Mips => cabi_mips::compute_abi_info(ccx, atys, rty, ret_def),