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.
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.
11 use abi::{align_up_to, FnType, ArgType, LayoutExt, Reg, Uniform};
12 use context::CrateContext;
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);
20 ret.make_indirect(ccx);
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);
29 if arg.layout.is_aggregate() {
30 arg.cast_to(ccx, Uniform {
34 if ((align - 1) & *offset) > 0 {
35 arg.pad_with(ccx, Reg::i32());
38 arg.extend_integer_width_to(32);
41 *offset = align_up_to(*offset, align);
42 *offset += align_up_to(size.bytes(), align);
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);
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);