rustc_target/callconv/
msp430.rs

1// Reference: MSP430 Embedded Application Binary Interface
2// https://www.ti.com/lit/an/slaa534a/slaa534a.pdf
3
4use rustc_abi::TyAbiInterface;
5
6use crate::callconv::{ArgAbi, FnAbi};
7
8// 3.5 Structures or Unions Passed and Returned by Reference
9//
10// "Structures (including classes) and unions larger than 32 bits are passed and
11// returned by reference. To pass a structure or union by reference, the caller
12// places its address in the appropriate location: either in a register or on
13// the stack, according to its position in the argument list. (..)"
14fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
15    if ret.layout.is_aggregate() && ret.layout.size.bits() > 32 {
16        ret.make_indirect();
17    } else {
18        ret.extend_integer_width_to(16);
19    }
20}
21
22fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
23where
24    Ty: TyAbiInterface<'a, C> + Copy,
25{
26    if arg.layout.pass_indirectly_in_non_rustic_abis(cx) {
27        arg.make_indirect();
28        return;
29    }
30    if arg.layout.is_aggregate() && arg.layout.size.bits() > 32 {
31        arg.make_indirect();
32    } else {
33        arg.extend_integer_width_to(16);
34    }
35}
36
37pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
38where
39    Ty: TyAbiInterface<'a, C> + Copy,
40{
41    if !fn_abi.ret.is_ignore() {
42        classify_ret(&mut fn_abi.ret);
43    }
44
45    for arg in fn_abi.args.iter_mut() {
46        if arg.is_ignore() {
47            continue;
48        }
49        classify_arg(cx, arg);
50    }
51}