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