]> git.lizzy.rs Git - rust.git/blob - src/librustc_trans/cabi_s390x.rs
Fixes doc important trait display on mobile
[rust.git] / src / librustc_trans / cabi_s390x.rs
1 // Copyright 2016 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 // FIXME: The assumes we're using the non-vector ABI, i.e. compiling
12 // for a pre-z13 machine or using -mno-vx.
13
14 use abi::{FnType, ArgType, LayoutExt, Reg};
15 use context::CrateContext;
16
17 use rustc::ty::layout::{self, TyLayout};
18
19 fn classify_ret_ty(ret: &mut ArgType) {
20     if !ret.layout.is_aggregate() && ret.layout.size.bits() <= 64 {
21         ret.extend_integer_width_to(64);
22     } else {
23         ret.make_indirect();
24     }
25 }
26
27 fn is_single_fp_element<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
28                                   layout: TyLayout<'tcx>) -> bool {
29     match layout.abi {
30         layout::Abi::Scalar(ref scalar) => {
31             match scalar.value {
32                 layout::F32 | layout::F64 => true,
33                 _ => false
34             }
35         }
36         layout::Abi::Aggregate { .. } => {
37             if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 {
38                 is_single_fp_element(ccx, layout.field(ccx, 0))
39             } else {
40                 false
41             }
42         }
43         _ => false
44     }
45 }
46
47 fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>) {
48     if !arg.layout.is_aggregate() && arg.layout.size.bits() <= 64 {
49         arg.extend_integer_width_to(64);
50         return;
51     }
52
53     if is_single_fp_element(ccx, arg.layout) {
54         match arg.layout.size.bytes() {
55             4 => arg.cast_to(Reg::f32()),
56             8 => arg.cast_to(Reg::f64()),
57             _ => arg.make_indirect()
58         }
59     } else {
60         match arg.layout.size.bytes() {
61             1 => arg.cast_to(Reg::i8()),
62             2 => arg.cast_to(Reg::i16()),
63             4 => arg.cast_to(Reg::i32()),
64             8 => arg.cast_to(Reg::i64()),
65             _ => arg.make_indirect()
66         }
67     }
68 }
69
70 pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
71     if !fty.ret.is_ignore() {
72         classify_ret_ty(&mut fty.ret);
73     }
74
75     for arg in &mut fty.args {
76         if arg.is_ignore() { continue; }
77         classify_arg_ty(ccx, arg);
78     }
79 }