rustc_target/callconv/
sparc.rs1use rustc_abi::{
2 BackendRepr, CanonAbi, Float, HasDataLayout, Integer, Numeric, Primitive, RegKind,
3 TyAbiInterface,
4};
5
6use crate::callconv::{ArgAbi, ArgAttribute, CastTarget, ComputeCallConv, Reg};
7
8fn classify_shared<'a, Ty>(val: &mut ArgAbi<'a, Ty>) {
9 if val.layout.is_aggregate() {
10 val.make_indirect();
11 } else if let BackendRepr::Scalar(scalar) = val.layout.backend_repr
12 && scalar.primitive() == Primitive::Float(Float::F128)
13 {
14 val.make_indirect();
16 } else {
17 val.extend_integer_width_to(32);
18 }
19}
20
21fn classify_complex_ret<'a, Ty>(ret: &mut ArgAbi<'a, Ty>, component: Numeric) {
22 let reg = Reg { kind: component.reg_kind(), size: component.size() };
23 let mut cast = CastTarget::pair(reg, reg);
24
25 match component {
26 Numeric::Float(Float::F128) => {
27 cast.attrs.set(ArgAttribute::InReg);
30 }
31 Numeric::Int(Integer::I8 | Integer::I16 | Integer::I32, _) => {
32 let size = ret.layout.size;
33 cast = CastTarget::from(Reg { kind: RegKind::Integer, size });
34 }
35 _ => { }
36 }
37
38 ret.cast_to(cast);
39}
40
41fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
42where
43 Ty: TyAbiInterface<'a, C> + Copy,
44 C: HasDataLayout,
45{
46 if !arg.layout.is_sized() {
47 return;
49 }
50 if arg.layout.pass_indirectly_in_non_rustic_abis(cx) {
51 arg.make_indirect();
52 return;
53 }
54
55 if let Some(component) = arg.layout.complex_number(cx) {
56 if let Numeric::Int(Integer::I8 | Integer::I16 | Integer::I32, _) = component {
57 arg.cast_to(Reg { kind: RegKind::Integer, size: 2 * component.size() });
58 } else {
59 arg.make_indirect();
60 }
61 return;
62 }
63
64 classify_shared(arg)
65}
66
67pub(crate) struct SparcCallConv;
68
69impl<'a, Ty, C> ComputeCallConv<'a, Ty, C> for SparcCallConv
70where
71 Ty: TyAbiInterface<'a, C> + Copy,
72 C: HasDataLayout,
73{
74 fn new(_cx: &C, _conv: CanonAbi, _c_variadic: bool) -> Self {
75 Self
76 }
77
78 fn passes_zsts(&self) -> bool {
79 true
80 }
81
82 fn compute_ret_abi(&mut self, cx: &C, ret: &mut ArgAbi<'a, Ty>) {
83 if !ret.is_ignore() {
84 if let Some(component) = ret.layout.complex_number(cx) {
85 classify_complex_ret(ret, component);
86 } else {
87 classify_shared(ret);
88 };
89 }
90 }
91
92 fn compute_arg_abi(&mut self, cx: &C, arg: &mut ArgAbi<'a, Ty>, _is_vararg: bool) {
93 if arg.is_ignore() {
94 arg.make_indirect_from_ignore();
95 return;
96 }
97 classify_arg(cx, arg);
98 }
99}