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.
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.
12 use abi::{align_up_to, ArgType, FnType, LayoutExt, Reg, Uniform};
13 use context::CrateContext;
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(64);
19 ret.make_indirect(ccx);
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);
28 if arg.layout.is_aggregate() {
29 arg.cast_to(ccx, Uniform {
33 if ((align - 1) & *offset) > 0 {
34 arg.pad_with(ccx, Reg::i64());
37 arg.extend_integer_width_to(64);
40 *offset = align_up_to(*offset, align);
41 *offset += align_up_to(size.bytes(), align);
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);
49 let mut offset = if fty.ret.is_indirect() { 8 } else { 0 };
50 for arg in &mut fty.args {
51 if arg.is_ignore() { continue; }
52 classify_arg_ty(ccx, arg, &mut offset);