2013-04-01 19:47:38 -05:00
|
|
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-07-07 19:58:01 -05:00
|
|
|
use llvm::*;
|
2016-03-22 12:23:36 -05:00
|
|
|
use abi::FnType;
|
|
|
|
use type_::Type;
|
2013-04-01 19:47:38 -05:00
|
|
|
use super::common::*;
|
|
|
|
use super::machine::*;
|
2013-06-16 05:52:44 -05:00
|
|
|
|
2016-02-23 13:55:19 -06:00
|
|
|
pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
|
2016-02-17 00:33:27 -06:00
|
|
|
if !fty.ret.is_ignore() {
|
|
|
|
if fty.ret.ty.kind() == Struct {
|
|
|
|
// Returning a structure. Most often, this will use
|
|
|
|
// a hidden first argument. On some platforms, though,
|
|
|
|
// small structs are returned as integers.
|
|
|
|
//
|
|
|
|
// Some links:
|
|
|
|
// http://www.angelcode.com/dev/callconv/callconv.html
|
|
|
|
// Clang's ABI handling is in lib/CodeGen/TargetInfo.cpp
|
|
|
|
let t = &ccx.sess().target.target;
|
|
|
|
if t.options.is_like_osx || t.options.is_like_windows {
|
|
|
|
match llsize_of_alloc(ccx, fty.ret.ty) {
|
|
|
|
1 => fty.ret.cast = Some(Type::i8(ccx)),
|
|
|
|
2 => fty.ret.cast = Some(Type::i16(ccx)),
|
|
|
|
4 => fty.ret.cast = Some(Type::i32(ccx)),
|
|
|
|
8 => fty.ret.cast = Some(Type::i64(ccx)),
|
|
|
|
_ => fty.ret.make_indirect(ccx)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fty.ret.make_indirect(ccx);
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
2014-07-23 13:56:36 -05:00
|
|
|
} else {
|
2016-02-17 00:33:27 -06:00
|
|
|
fty.ret.extend_integer_width_to(32);
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-23 13:55:19 -06:00
|
|
|
for arg in &mut fty.args {
|
2016-03-06 04:36:39 -06:00
|
|
|
if arg.is_ignore() { continue; }
|
2016-02-23 13:55:19 -06:00
|
|
|
if arg.ty.kind() == Struct {
|
2016-03-06 04:36:39 -06:00
|
|
|
arg.make_indirect(ccx);
|
|
|
|
arg.attrs.set(Attribute::ByVal);
|
2016-02-17 00:33:27 -06:00
|
|
|
} else {
|
|
|
|
arg.extend_integer_width_to(32);
|
2016-02-23 13:55:19 -06:00
|
|
|
}
|
2013-04-01 19:47:38 -05:00
|
|
|
}
|
|
|
|
}
|