]>
Commit | Line | Data |
---|---|---|
476ff2be 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 | ||
11 | // Reference: MSP430 Embedded Application Binary Interface | |
12 | // http://www.ti.com/lit/an/slaa534/slaa534.pdf | |
13 | ||
cc61c64b | 14 | use abi::{ArgType, FnType, LayoutExt}; |
476ff2be SL |
15 | |
16 | // 3.5 Structures or Unions Passed and Returned by Reference | |
17 | // | |
18 | // "Structures (including classes) and unions larger than 32 bits are passed and | |
19 | // returned by reference. To pass a structure or union by reference, the caller | |
20 | // places its address in the appropriate location: either in a register or on | |
21 | // the stack, according to its position in the argument list. (..)" | |
ff7c6d11 XL |
22 | fn classify_ret_ty(ret: &mut ArgType) { |
23 | if ret.layout.is_aggregate() && ret.layout.size.bits() > 32 { | |
24 | ret.make_indirect(); | |
476ff2be SL |
25 | } else { |
26 | ret.extend_integer_width_to(16); | |
27 | } | |
28 | } | |
29 | ||
ff7c6d11 XL |
30 | fn classify_arg_ty(arg: &mut ArgType) { |
31 | if arg.layout.is_aggregate() && arg.layout.size.bits() > 32 { | |
32 | arg.make_indirect(); | |
476ff2be SL |
33 | } else { |
34 | arg.extend_integer_width_to(16); | |
35 | } | |
36 | } | |
37 | ||
ff7c6d11 | 38 | pub fn compute_abi_info(fty: &mut FnType) { |
476ff2be | 39 | if !fty.ret.is_ignore() { |
ff7c6d11 | 40 | classify_ret_ty(&mut fty.ret); |
476ff2be SL |
41 | } |
42 | ||
43 | for arg in &mut fty.args { | |
44 | if arg.is_ignore() { | |
45 | continue; | |
46 | } | |
ff7c6d11 | 47 | classify_arg_ty(arg); |
476ff2be SL |
48 | } |
49 | } |