]> git.lizzy.rs Git - rust.git/blob - src/librustc_trans/cabi_mips.rs
Fixes doc important trait display on mobile
[rust.git] / src / librustc_trans / cabi_mips.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 abi::{ArgType, FnType, LayoutExt, Reg, Uniform};
12 use context::CrateContext;
13
14 use rustc::ty::layout::Size;
15
16 fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
17                              ret: &mut ArgType<'tcx>,
18                              offset: &mut Size) {
19     if !ret.layout.is_aggregate() {
20         ret.extend_integer_width_to(32);
21     } else {
22         ret.make_indirect();
23         *offset += ccx.tcx().data_layout.pointer_size;
24     }
25 }
26
27 fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, offset: &mut Size) {
28     let dl = &ccx.tcx().data_layout;
29     let size = arg.layout.size;
30     let align = arg.layout.align.max(dl.i32_align).min(dl.i64_align);
31
32     if arg.layout.is_aggregate() {
33         arg.cast_to(Uniform {
34             unit: Reg::i32(),
35             total: size
36         });
37         if !offset.is_abi_aligned(align) {
38             arg.pad_with(Reg::i32());
39         }
40     } else {
41         arg.extend_integer_width_to(32);
42     }
43
44     *offset = offset.abi_align(align) + size.abi_align(align);
45 }
46
47 pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
48     let mut offset = Size::from_bytes(0);
49     if !fty.ret.is_ignore() {
50         classify_ret_ty(ccx, &mut fty.ret, &mut offset);
51     }
52
53     for arg in &mut fty.args {
54         if arg.is_ignore() { continue; }
55         classify_arg_ty(ccx, arg, &mut offset);
56     }
57 }