]> git.proxmox.com Git - rustc.git/blob - src/librustc_trans/cabi_x86.rs
Imported Upstream version 1.9.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::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 match llsize_of_alloc(ccx, fty.ret.ty) {
30 1 => fty.ret.cast = Some(Type::i8(ccx)),
31 2 => fty.ret.cast = Some(Type::i16(ccx)),
32 4 => fty.ret.cast = Some(Type::i32(ccx)),
33 8 => fty.ret.cast = Some(Type::i64(ccx)),
34 _ => fty.ret.make_indirect(ccx)
35 }
36 } else {
37 fty.ret.make_indirect(ccx);
38 }
39 } else {
40 fty.ret.extend_integer_width_to(32);
41 }
42 }
43
44 for arg in &mut fty.args {
45 if arg.is_ignore() { continue; }
46 if arg.ty.kind() == Struct {
47 arg.make_indirect(ccx);
48 arg.attrs.set(Attribute::ByVal);
49 } else {
50 arg.extend_integer_width_to(32);
51 }
52 }
53 }