rustc_target/callconv/
csky.rs1use rustc_abi::{CanonAbi, TyAbiInterface};
8
9use crate::callconv::{ArgAbi, ComputeCallConv, Reg, Uniform};
10
11fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
12 if !ret.layout.is_sized() {
13 return;
15 }
16 if ret.layout.is_aggregate() {
19 let total = ret.layout.size;
20 if total.bits() > 64 {
21 ret.make_indirect();
22 } else if total.bits() > 32 {
23 ret.cast_to(Uniform::new(Reg::i32(), total));
24 } else {
25 ret.cast_to(Reg::i32());
26 }
27 } else {
28 ret.extend_integer_width_to(32);
29 }
30}
31
32fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
33where
34 Ty: TyAbiInterface<'a, C> + Copy,
35{
36 if !arg.layout.is_sized() {
37 return;
39 }
40 if arg.layout.pass_indirectly_in_non_rustic_abis(cx) {
41 arg.make_indirect();
42 return;
43 }
44 if arg.layout.is_aggregate() {
48 let total = arg.layout.size;
49 if total.bits() > 32 {
50 arg.cast_to(Uniform::new(Reg::i32(), total));
51 } else {
52 arg.cast_to(Reg::i32());
53 }
54 } else {
55 arg.extend_integer_width_to(32);
56 }
57}
58
59pub(crate) struct CSkyCallConv;
60
61impl<'a, Ty, C> ComputeCallConv<'a, Ty, C> for CSkyCallConv
62where
63 Ty: TyAbiInterface<'a, C> + Copy,
64{
65 fn new(_cx: &C, _conv: CanonAbi, _c_variadic: bool) -> Self {
66 Self
67 }
68
69 fn compute_ret_abi(&mut self, _cx: &C, ret: &mut ArgAbi<'a, Ty>) {
70 classify_ret(ret);
71 }
72
73 fn compute_arg_abi(&mut self, cx: &C, arg: &mut ArgAbi<'a, Ty>, _is_vararg: bool) {
74 classify_arg(cx, arg);
75 }
76}