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.
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::{ArgType, FnType, LayoutExt, Reg, Uniform};
12 use context::CrateContext;
14 use rustc::ty::layout::Size;
16 fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
17 ret: &mut ArgType<'tcx>,
19 if !ret.layout.is_aggregate() {
20 ret.extend_integer_width_to(32);
23 *offset += ccx.tcx().data_layout.pointer_size;
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);
32 if arg.layout.is_aggregate() {
37 if !offset.is_abi_aligned(align) {
38 arg.pad_with(Reg::i32());
41 arg.extend_integer_width_to(32);
44 *offset = offset.abi_align(align) + size.abi_align(align);
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);
53 for arg in &mut fty.args {
54 if arg.is_ignore() { continue; }
55 classify_arg_ty(ccx, arg, &mut offset);