Skip to main content

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::{CanonAbi, TyAbiInterface};
5
6use crate::callconv::{ArgAbi, ComputeCallConv};
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) struct MSP430CallConv;
38
39impl<'a, Ty, C> ComputeCallConv<'a, Ty, C> for MSP430CallConv
40where
41    Ty: TyAbiInterface<'a, C> + Copy,
42{
43    fn new(_cx: &C, _conv: CanonAbi, _c_variadic: bool) -> Self {
44        Self
45    }
46
47    fn passes_zsts(&self) -> bool {
48        true
49    }
50
51    fn compute_ret_abi(&mut self, _cx: &C, ret: &mut ArgAbi<'a, Ty>) {
52        if !ret.is_ignore() {
53            classify_ret(ret);
54        }
55    }
56
57    fn compute_arg_abi(&mut self, cx: &C, arg: &mut ArgAbi<'a, Ty>, _is_vararg: bool) {
58        classify_arg(cx, arg);
59    }
60}