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::{FnType, ArgType, LayoutExt, Reg, Uniform};
12 use context::CrateContext;
14 fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tcx>) {
15 if !ret.layout.is_aggregate() {
16 ret.extend_integer_width_to(32);
19 let size = ret.layout.size(ccx);
20 let bits = size.bits();
22 let unit = if bits <= 8 {
24 } else if bits <= 16 {
29 ret.cast_to(ccx, Uniform {
35 ret.make_indirect(ccx);
38 fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>) {
39 if !arg.layout.is_aggregate() {
40 arg.extend_integer_width_to(32);
43 let align = arg.layout.align(ccx).abi();
44 let total = arg.layout.size(ccx);
45 arg.cast_to(ccx, Uniform {
46 unit: if align <= 4 { Reg::i32() } else { Reg::i64() },
51 pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
52 if !fty.ret.is_ignore() {
53 classify_ret_ty(ccx, &mut fty.ret);
56 for arg in &mut fty.args {
57 if arg.is_ignore() { continue; }
58 classify_arg_ty(ccx, arg);