1 // Copyright 2013 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 self::Strategy
::*;
13 use trans
::cabi
::{ArgType, FnType}
;
14 use trans
::type_
::Type
;
16 use super::machine
::*;
18 enum Strategy { RetValue(Type), RetPointer }
19 pub fn compute_abi_info(ccx
: &CrateContext
,
22 ret_def
: bool
) -> FnType
{
23 let mut arg_tys
= Vec
::new();
27 ret_ty
= ArgType
::direct(Type
::void(ccx
), None
, None
, None
);
28 } else if rty
.kind() == Struct
{
29 // Returning a structure. Most often, this will use
30 // a hidden first argument. On some platforms, though,
31 // small structs are returned as integers.
34 // http://www.angelcode.com/dev/callconv/callconv.html
35 // Clang's ABI handling is in lib/CodeGen/TargetInfo.cpp
37 let t
= &ccx
.sess().target
.target
;
38 let strategy
= if t
.options
.is_like_osx
|| t
.options
.is_like_windows
{
39 match llsize_of_alloc(ccx
, rty
) {
40 1 => RetValue(Type
::i8(ccx
)),
41 2 => RetValue(Type
::i16(ccx
)),
42 4 => RetValue(Type
::i32(ccx
)),
43 8 => RetValue(Type
::i64(ccx
)),
52 ret_ty
= ArgType
::direct(rty
, Some(t
), None
, None
);
55 ret_ty
= ArgType
::indirect(rty
, Some(Attribute
::StructRet
));
59 let attr
= if rty
== Type
::i1(ccx
) { Some(Attribute::ZExt) }
else { None }
;
60 ret_ty
= ArgType
::direct(rty
, None
, None
, attr
);
64 let ty
= match t
.kind() {
66 let size
= llsize_of_alloc(ccx
, t
);
70 ArgType
::indirect(t
, Some(Attribute
::ByVal
))
74 let attr
= if t
== Type
::i1(ccx
) { Some(Attribute::ZExt) }
else { None }
;
75 ArgType
::direct(t
, None
, None
, attr
)