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-08-31 11:13:04 -05:00
|
|
|
use driver::session::{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 = ~[];
|
|
|
|
let mut attrs = ~[];
|
2013-04-01 19:47:38 -05:00
|
|
|
|
2013-05-21 14:25:44 -05:00
|
|
|
let ret_ty;
|
|
|
|
let sret;
|
|
|
|
if !ret_def {
|
|
|
|
ret_ty = LLVMType {
|
2013-04-01 19:47:38 -05:00
|
|
|
cast: false,
|
2013-05-21 14:25:44 -05:00
|
|
|
ty: Type::void(),
|
2013-04-01 19:47:38 -05:00
|
|
|
};
|
2013-05-21 14:25:44 -05:00
|
|
|
sret = false;
|
|
|
|
} 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) => {
|
|
|
|
ret_ty = LLVMType {
|
|
|
|
cast: true,
|
|
|
|
ty: t
|
|
|
|
};
|
|
|
|
sret = false;
|
|
|
|
}
|
|
|
|
RetPointer => {
|
|
|
|
arg_tys.push(LLVMType {
|
|
|
|
cast: false,
|
|
|
|
ty: rty.ptr_to()
|
|
|
|
});
|
|
|
|
attrs.push(Some(StructRetAttribute));
|
2013-04-01 19:47:38 -05:00
|
|
|
|
2013-05-21 14:25:44 -05:00
|
|
|
ret_ty = LLVMType {
|
|
|
|
cast: false,
|
|
|
|
ty: Type::void(),
|
|
|
|
};
|
|
|
|
sret = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret_ty = LLVMType {
|
|
|
|
cast: false,
|
|
|
|
ty: rty
|
2013-04-01 19:47:38 -05:00
|
|
|
};
|
2013-05-21 14:25:44 -05:00
|
|
|
sret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for &a in atys.iter() {
|
|
|
|
arg_tys.push(LLVMType { cast: false, ty: a });
|
|
|
|
attrs.push(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,
|
|
|
|
attrs: attrs,
|
|
|
|
sret: sret
|
|
|
|
};
|
2013-04-01 19:47:38 -05:00
|
|
|
}
|