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.
|
|
|
|
|
2013-05-17 17:28:44 -05:00
|
|
|
|
2013-11-08 13:06:57 -06:00
|
|
|
use syntax::abi::{OsWin32, OsMacos};
|
2013-04-01 19:47:38 -05:00
|
|
|
use lib::llvm::*;
|
|
|
|
use super::cabi::*;
|
|
|
|
use super::common::*;
|
|
|
|
use super::machine::*;
|
2013-06-16 05:52:44 -05:00
|
|
|
use middle::trans::type_::Type;
|
|
|
|
|
2013-12-19 18:47:15 -06:00
|
|
|
pub fn compute_abi_info(ccx: &CrateContext,
|
2013-05-21 14:25:44 -05:00
|
|
|
atys: &[Type],
|
|
|
|
rty: Type,
|
|
|
|
ret_def: bool) -> FnType {
|
2014-03-04 12:02:49 -06:00
|
|
|
let mut arg_tys = Vec::new();
|
2013-04-01 19:47:38 -05:00
|
|
|
|
2013-05-21 14:25:44 -05:00
|
|
|
let ret_ty;
|
|
|
|
if !ret_def {
|
2014-03-15 15:29:34 -05:00
|
|
|
ret_ty = ArgType::direct(Type::void(ccx), None, None, None);
|
2013-05-21 14:25:44 -05:00
|
|
|
} else if rty.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:
|
2013-04-01 19:47:38 -05:00
|
|
|
// http://www.angelcode.com/dev/callconv/callconv.html
|
2013-04-18 16:10:13 -05:00
|
|
|
// Clang's ABI handling is in lib/CodeGen/TargetInfo.cpp
|
2013-05-21 14:25:44 -05:00
|
|
|
|
|
|
|
enum Strategy { RetValue(Type), RetPointer }
|
2014-03-05 08:36:01 -06:00
|
|
|
let strategy = match ccx.sess().targ_cfg.os {
|
2013-08-31 11:13:04 -05:00
|
|
|
OsWin32 | OsMacos => {
|
2013-05-21 14:25:44 -05:00
|
|
|
match llsize_of_alloc(ccx, rty) {
|
2014-03-15 15:29:34 -05:00
|
|
|
1 => RetValue(Type::i8(ccx)),
|
|
|
|
2 => RetValue(Type::i16(ccx)),
|
|
|
|
4 => RetValue(Type::i32(ccx)),
|
|
|
|
8 => RetValue(Type::i64(ccx)),
|
2013-05-21 14:25:44 -05:00
|
|
|
_ => RetPointer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
RetPointer
|
|
|
|
}
|
2013-04-01 19:47:38 -05:00
|
|
|
};
|
|
|
|
|
2013-05-21 14:25:44 -05:00
|
|
|
match strategy {
|
|
|
|
RetValue(t) => {
|
2013-09-25 05:30:44 -05:00
|
|
|
ret_ty = ArgType::direct(rty, Some(t), None, None);
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
RetPointer => {
|
2013-09-25 05:30:44 -05:00
|
|
|
ret_ty = ArgType::indirect(rty, Some(StructRetAttribute));
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2013-09-25 05:30:44 -05:00
|
|
|
ret_ty = ArgType::direct(rty, None, None, None);
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
|
2014-03-07 20:23:06 -06:00
|
|
|
for &t in atys.iter() {
|
|
|
|
let ty = match t.kind() {
|
|
|
|
Struct => {
|
2014-03-09 00:42:22 -06:00
|
|
|
let size = llsize_of_alloc(ccx, t);
|
|
|
|
if size == 0 {
|
|
|
|
ArgType::ignore(t)
|
|
|
|
} else {
|
|
|
|
ArgType::indirect(t, Some(ByValAttribute))
|
|
|
|
}
|
2014-03-07 20:23:06 -06:00
|
|
|
}
|
|
|
|
_ => ArgType::direct(t, None, None, None),
|
|
|
|
};
|
|
|
|
arg_tys.push(ty);
|
2013-04-01 19:47:38 -05:00
|
|
|
}
|
|
|
|
|
2013-05-21 14:25:44 -05:00
|
|
|
return FnType {
|
|
|
|
arg_tys: arg_tys,
|
|
|
|
ret_ty: ret_ty,
|
|
|
|
};
|
2013-04-01 19:47:38 -05:00
|
|
|
}
|