]> git.proxmox.com Git - rustc.git/blame - src/librustc_trans/cabi_sparc.rs
New upstream version 1.26.2+dfsg1
[rustc.git] / src / librustc_trans / cabi_sparc.rs
CommitLineData
32a655c1
SL
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.
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
ff7c6d11 11use abi::{ArgType, FnType, LayoutExt, Reg, Uniform};
2c00a5a8 12use context::CodegenCx;
32a655c1 13
ff7c6d11
XL
14use rustc::ty::layout::Size;
15
2c00a5a8 16fn classify_ret_ty<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
ff7c6d11
XL
17 ret: &mut ArgType<'tcx>,
18 offset: &mut Size) {
cc61c64b 19 if !ret.layout.is_aggregate() {
32a655c1
SL
20 ret.extend_integer_width_to(32);
21 } else {
ff7c6d11 22 ret.make_indirect();
2c00a5a8 23 *offset += cx.tcx.data_layout.pointer_size;
32a655c1
SL
24 }
25}
26
2c00a5a8
XL
27fn classify_arg_ty(cx: &CodegenCx, arg: &mut ArgType, offset: &mut Size) {
28 let dl = &cx.tcx.data_layout;
ff7c6d11
XL
29 let size = arg.layout.size;
30 let align = arg.layout.align.max(dl.i32_align).min(dl.i64_align);
32a655c1 31
cc61c64b 32 if arg.layout.is_aggregate() {
ff7c6d11 33 arg.cast_to(Uniform {
cc61c64b
XL
34 unit: Reg::i32(),
35 total: size
36 });
ff7c6d11
XL
37 if !offset.is_abi_aligned(align) {
38 arg.pad_with(Reg::i32());
32a655c1 39 }
cc61c64b 40 } else {
ff7c6d11 41 arg.extend_integer_width_to(32);
32a655c1
SL
42 }
43
ff7c6d11 44 *offset = offset.abi_align(align) + size.abi_align(align);
32a655c1
SL
45}
46
2c00a5a8 47pub fn compute_abi_info<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, fty: &mut FnType<'tcx>) {
ff7c6d11 48 let mut offset = Size::from_bytes(0);
32a655c1 49 if !fty.ret.is_ignore() {
2c00a5a8 50 classify_ret_ty(cx, &mut fty.ret, &mut offset);
32a655c1
SL
51 }
52
32a655c1
SL
53 for arg in &mut fty.args {
54 if arg.is_ignore() { continue; }
2c00a5a8 55 classify_arg_ty(cx, arg, &mut offset);
32a655c1
SL
56 }
57}