]> git.proxmox.com Git - rustc.git/blob - src/librustc_trans/cabi_x86.rs
New upstream version 1.15.0+dfsg1
[rustc.git] / src / librustc_trans / cabi_x86.rs
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.
4 //
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.
10
11 use llvm::*;
12 use abi::{ArgAttribute, FnType};
13 use type_::Type;
14 use super::common::*;
15 use super::machine::*;
16
17 pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
18 if !fty.ret.is_ignore() {
19 if fty.ret.ty.kind() == Struct {
20 // Returning a structure. Most often, this will use
21 // a hidden first argument. On some platforms, though,
22 // small structs are returned as integers.
23 //
24 // Some links:
25 // http://www.angelcode.com/dev/callconv/callconv.html
26 // Clang's ABI handling is in lib/CodeGen/TargetInfo.cpp
27 let t = &ccx.sess().target.target;
28 if t.options.is_like_osx || t.options.is_like_windows
29 || t.options.is_like_openbsd {
30 match llsize_of_alloc(ccx, fty.ret.ty) {
31 1 => fty.ret.cast = Some(Type::i8(ccx)),
32 2 => fty.ret.cast = Some(Type::i16(ccx)),
33 4 => fty.ret.cast = Some(Type::i32(ccx)),
34 8 => fty.ret.cast = Some(Type::i64(ccx)),
35 _ => fty.ret.make_indirect(ccx)
36 }
37 } else {
38 fty.ret.make_indirect(ccx);
39 }
40 } else {
41 fty.ret.extend_integer_width_to(32);
42 }
43 }
44
45 for arg in &mut fty.args {
46 if arg.is_ignore() { continue; }
47 if arg.ty.kind() == Struct {
48 arg.make_indirect(ccx);
49 arg.attrs.set(ArgAttribute::ByVal);
50 } else {
51 arg.extend_integer_width_to(32);
52 }
53 }
54 }