]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_target/src/asm/bpf.rs
Rollup merge of #98775 - notriddle:notriddle/mobile-sidebar-scroll-lock, r=jsha
[rust.git] / compiler / rustc_target / src / asm / bpf.rs
1 use super::{InlineAsmArch, InlineAsmType};
2 use rustc_macros::HashStable_Generic;
3 use rustc_span::Symbol;
4 use std::fmt;
5
6 def_reg_class! {
7     Bpf BpfInlineAsmRegClass {
8         reg,
9         wreg,
10     }
11 }
12
13 impl BpfInlineAsmRegClass {
14     pub fn valid_modifiers(self, _arch: InlineAsmArch) -> &'static [char] {
15         &[]
16     }
17
18     pub fn suggest_class(self, _arch: InlineAsmArch, _ty: InlineAsmType) -> Option<Self> {
19         None
20     }
21
22     pub fn suggest_modifier(
23         self,
24         _arch: InlineAsmArch,
25         _ty: InlineAsmType,
26     ) -> Option<(char, &'static str)> {
27         None
28     }
29
30     pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<(char, &'static str)> {
31         None
32     }
33
34     pub fn supported_types(
35         self,
36         _arch: InlineAsmArch,
37     ) -> &'static [(InlineAsmType, Option<Symbol>)] {
38         match self {
39             Self::reg => types! { _: I8, I16, I32, I64; },
40             Self::wreg => types! { alu32: I8, I16, I32; },
41         }
42     }
43 }
44
45 def_regs! {
46     Bpf BpfInlineAsmReg BpfInlineAsmRegClass {
47         r0: reg = ["r0"],
48         r1: reg = ["r1"],
49         r2: reg = ["r2"],
50         r3: reg = ["r3"],
51         r4: reg = ["r4"],
52         r5: reg = ["r5"],
53         r6: reg = ["r6"],
54         r7: reg = ["r7"],
55         r8: reg = ["r8"],
56         r9: reg = ["r9"],
57         w0: wreg = ["w0"],
58         w1: wreg = ["w1"],
59         w2: wreg = ["w2"],
60         w3: wreg = ["w3"],
61         w4: wreg = ["w4"],
62         w5: wreg = ["w5"],
63         w6: wreg = ["w6"],
64         w7: wreg = ["w7"],
65         w8: wreg = ["w8"],
66         w9: wreg = ["w9"],
67
68         #error = ["r10", "w10"] =>
69             "the stack pointer cannot be used as an operand for inline asm",
70     }
71 }
72
73 impl BpfInlineAsmReg {
74     pub fn emit(
75         self,
76         out: &mut dyn fmt::Write,
77         _arch: InlineAsmArch,
78         _modifier: Option<char>,
79     ) -> fmt::Result {
80         out.write_str(self.name())
81     }
82
83     pub fn overlapping_regs(self, mut cb: impl FnMut(BpfInlineAsmReg)) {
84         cb(self);
85
86         macro_rules! reg_conflicts {
87             (
88                 $(
89                     $r:ident : $w:ident
90                 ),*
91             ) => {
92                 match self {
93                     $(
94                         Self::$r => {
95                             cb(Self::$w);
96                         }
97                         Self::$w => {
98                             cb(Self::$r);
99                         }
100                     )*
101                 }
102             };
103         }
104
105         reg_conflicts! {
106             r0 : w0,
107             r1 : w1,
108             r2 : w2,
109             r3 : w3,
110             r4 : w4,
111             r5 : w5,
112             r6 : w6,
113             r7 : w7,
114             r8 : w8,
115             r9 : w9
116         }
117     }
118 }