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.
4 //
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.
10
11 use lib::llvm::Attribute;
12 use std::option;
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};
20
21 #[deriving(Clone, Eq)]
22 pub enum ArgKind {
23 /// Pass the argument directly using the normal converted
24 /// LLVM type or by coercing to another specified type
25 Direct,
26 /// Pass the argument indirectly via a hidden pointer
27 Indirect,
28 /// Ignore the argument (useful for empty struct)
29 Ignore,
30 }
31
32 /// Information about how a specific C type
33 /// should be passed to or returned from a function
34 ///
35 /// This is borrowed from clang's ABIInfo.h
36 #[deriving(Clone)]
37 pub struct ArgType {
38 pub kind: ArgKind,
39 /// Original LLVM type
40 pub ty: Type,
41 /// Coerced LLVM Type
42 pub cast: option::Option<Type>,
43 /// Dummy argument, which is emitted before the real argument
44 pub pad: option::Option<Type>,
45 /// LLVM attribute of argument
46 pub attr: option::Option<Attribute>
47 }
48
49 impl ArgType {
50 pub fn direct(ty: Type, cast: option::Option<Type>,
51 pad: option::Option<Type>,
52 attr: option::Option<Attribute>) -> ArgType {
53 ArgType {
54 kind: Direct,
55 ty: ty,
56 cast: cast,
57 pad: pad,
58 attr: attr
59 }
60 }
61
62 pub fn indirect(ty: Type, attr: option::Option<Attribute>) -> ArgType {
63 ArgType {
64 kind: Indirect,
65 ty: ty,
66 cast: option::None,
67 pad: option::None,
68 attr: attr
69 }
70 }
71
72 pub fn ignore(ty: Type) -> ArgType {
73 ArgType {
74 kind: Ignore,
75 ty: ty,
76 cast: None,
77 pad: None,
78 attr: None,
79 }
80 }
81
82 pub fn is_indirect(&self) -> bool {
83 return self.kind == Indirect;
84 }
85
86 pub fn is_ignore(&self) -> bool {
87 return self.kind == Ignore;
88 }
89 }
90
91 /// Metadata describing how the arguments to a native function
92 /// should be passed in order to respect the native ABI.
93 ///
94 /// I will do my best to describe this structure, but these
95 /// comments are reverse-engineered and may be inaccurate. -NDM
96 pub struct FnType {
97 /// The LLVM types of each argument.
98 pub arg_tys: Vec<ArgType> ,
99
100 /// LLVM return type.
101 pub ret_ty: ArgType,
102 }
103
104 pub fn compute_abi_info(ccx: &CrateContext,
105 atys: &[Type],
106 rty: Type,
107 ret_def: bool) -> FnType {
108 match ccx.sess().targ_cfg.arch {
109 X86 => cabi_x86::compute_abi_info(ccx, atys, rty, ret_def),
110 X86_64 => cabi_x86_64::compute_abi_info(ccx, atys, rty, ret_def),
111 Arm => cabi_arm::compute_abi_info(ccx, atys, rty, ret_def),
112 Mips => cabi_mips::compute_abi_info(ccx, atys, rty, ret_def),
113 }
114 }
librustc/middle/trans/cabi.rs:21:23-21:23 -enum- definition:
pub enum ArgKind {
/// Pass the argument directly using the normal converted
/// LLVM type or by coercing to another specified type
references:- 637: pub struct ArgType {
38: pub kind: ArgKind,
39: /// Original LLVM type
librustc/middle/trans/cabi.rs:36:19-36:19 -struct- definition:
pub struct ArgType {
pub kind: ArgKind,
/// Original LLVM type
references:- 1935: /// This is borrowed from clang's ABIInfo.h
37: pub struct ArgType {
--
72: pub fn ignore(ty: Type) -> ArgType {
73: ArgType {
74: kind: Ignore,
--
100: /// LLVM return type.
101: pub ret_ty: ArgType,
102: }
librustc/middle/trans/cabi_x86_64.rs:
340: attr: Attribute)
341: -> ArgType {
342: if !ty.is_reg_ty() {
librustc/middle/trans/cabi_arm.rs:
104: fn classify_arg_ty(ccx: &CrateContext, ty: Type) -> ArgType {
105: if is_reg_ty(ty) {
librustc/middle/trans/cabi_mips.rs:
94: fn classify_arg_ty(ccx: &CrateContext, ty: Type, offset: &mut uint) -> ArgType {
95: let orig_offset = *offset;
librustc/middle/trans/foreign.rs:
277: let arg_tys: &[cabi::ArgType] = fn_type.arg_tys.as_slice();
librustc/middle/trans/cabi.rs:
97: /// The LLVM types of each argument.
98: pub arg_tys: Vec<ArgType> ,
librustc/middle/trans/cabi.rs:95:64-95:64 -struct- definition:
/// comments are reverse-engineered and may be inaccurate. -NDM
pub struct FnType {
/// The LLVM types of each argument.
references:- 10librustc/middle/trans/cabi_x86.rs:
80: return FnType {
81: arg_tys: arg_tys,
librustc/middle/trans/cabi_x86_64.rs:
369: return FnType {
370: arg_tys: arg_tys,
librustc/middle/trans/cabi_arm.rs:
144: return FnType {
145: arg_tys: arg_tys,
librustc/middle/trans/cabi_mips.rs:
177: return FnType {
178: arg_tys: arg_tys,
librustc/middle/trans/cabi.rs:
106: rty: Type,
107: ret_def: bool) -> FnType {
108: match ccx.sess().targ_cfg.arch {
librustc/middle/trans/cabi_x86.rs:
21: rty: Type,
22: ret_def: bool) -> FnType {
23: let mut arg_tys = Vec::new();
librustc/middle/trans/cabi_x86_64.rs:
335: rty: Type,
336: ret_def: bool) -> FnType {
337: fn x86_64_ty(ccx: &CrateContext,
librustc/middle/trans/cabi_mips.rs:
160: rty: Type,
161: ret_def: bool) -> FnType {
162: let ret_ty = if ret_def {
librustc/middle/trans/foreign.rs:
47: /// don't want to know)
48: fn_ty: cabi::FnType,
librustc/middle/trans/cabi_arm.rs:
130: rty: Type,
131: ret_def: bool) -> FnType {
132: let mut arg_tys = Vec::new();
librustc/middle/trans/cabi.rs:103:1-103:1 -fn- definition:
pub fn compute_abi_info(ccx: &CrateContext,
atys: &[Type],
rty: Type,
references:- 2librustc/middle/trans/foreign.rs:
841: let ret_def = !return_type_is_void(ccx, fn_sig.output);
842: let fn_ty = cabi::compute_abi_info(ccx,
843: llsig.llarg_tys.as_slice(),