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