]> git.lizzy.rs Git - rust.git/blob - src/librustc_trans/cabi_sparc.rs
Auto merge of #43651 - petrochenkov:foreign-life, r=eddyb
[rust.git] / src / librustc_trans / cabi_sparc.rs
1 // Copyright 2012-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 std::cmp;
12 use abi::{align_up_to, ArgType, FnType, LayoutExt, Reg, Uniform};
13 use context::CrateContext;
14
15 fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tcx>) {
16     if !ret.layout.is_aggregate() {
17         ret.extend_integer_width_to(32);
18     } else {
19         ret.make_indirect(ccx);
20     }
21 }
22
23 fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, offset: &mut u64) {
24     let size = arg.layout.size(ccx);
25     let mut align = arg.layout.align(ccx).abi();
26     align = cmp::min(cmp::max(align, 4), 8);
27
28     if arg.layout.is_aggregate() {
29         arg.cast_to(ccx, Uniform {
30             unit: Reg::i32(),
31             total: size
32         });
33         if ((align - 1) & *offset) > 0 {
34             arg.pad_with(ccx, Reg::i32());
35         }
36     } else {
37         arg.extend_integer_width_to(32)
38     }
39
40     *offset = align_up_to(*offset, align);
41     *offset += align_up_to(size.bytes(), align);
42 }
43
44 pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
45     if !fty.ret.is_ignore() {
46         classify_ret_ty(ccx, &mut fty.ret);
47     }
48
49     let mut offset = if fty.ret.is_indirect() { 4 } else { 0 };
50     for arg in &mut fty.args {
51         if arg.is_ignore() { continue; }
52         classify_arg_ty(ccx, arg, &mut offset);
53     }
54 }