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-05-21 14:25:44 -05:00
|
|
|
pub fn compute_abi_info(ccx: &mut CrateContext,
|
|
|
|
atys: &[Type],
|
|
|
|
rty: Type,
|
|
|
|
ret_def: bool) -> FnType {
|
|
|
|
let mut arg_tys = ~[];
|
2013-04-01 19:47:38 -05:00
|
|
|
|
2013-05-21 14:25:44 -05:00
|
|
|
let ret_ty;
|
|
|
|
if !ret_def {
|
2013-09-25 05:30:44 -05:00
|
|
|
ret_ty = ArgType::direct(Type::void(), 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 }
|
|
|
|
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) {
|
|
|
|
1 => RetValue(Type::i8()),
|
|
|
|
2 => RetValue(Type::i16()),
|
|
|
|
4 => RetValue(Type::i32()),
|
|
|
|
8 => RetValue(Type::i64()),
|
|
|
|
_ => 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
|
|
|
}
|
|
|
|
|
|
|
|
for &a in atys.iter() {
|
2013-09-25 05:30:44 -05:00
|
|
|
arg_tys.push(ArgType::direct(a, None, None, None));
|
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
|
|
|
}
|