]> git.lizzy.rs Git - rust.git/blob - src/librustc_trans/cabi_msp430.rs
Auto merge of #43651 - petrochenkov:foreign-life, r=eddyb
[rust.git] / src / librustc_trans / cabi_msp430.rs
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
11 // Reference: MSP430 Embedded Application Binary Interface
12 // http://www.ti.com/lit/an/slaa534/slaa534.pdf
13
14 use abi::{ArgType, FnType, LayoutExt};
15 use context::CrateContext;
16
17 // 3.5 Structures or Unions Passed and Returned by Reference
18 //
19 // "Structures (including classes) and unions larger than 32 bits are passed and
20 // returned by reference. To pass a structure or union by reference, the caller
21 // places its address in the appropriate location: either in a register or on
22 // the stack, according to its position in the argument list. (..)"
23 fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tcx>) {
24     if ret.layout.is_aggregate() && ret.layout.size(ccx).bits() > 32 {
25         ret.make_indirect(ccx);
26     } else {
27         ret.extend_integer_width_to(16);
28     }
29 }
30
31 fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>) {
32     if arg.layout.is_aggregate() && arg.layout.size(ccx).bits() > 32 {
33         arg.make_indirect(ccx);
34     } else {
35         arg.extend_integer_width_to(16);
36     }
37 }
38
39 pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
40     if !fty.ret.is_ignore() {
41         classify_ret_ty(ccx, &mut fty.ret);
42     }
43
44     for arg in &mut fty.args {
45         if arg.is_ignore() {
46             continue;
47         }
48         classify_arg_ty(ccx, arg);
49     }
50 }