rustc_target/asm/
msp430.rs

1use std::fmt;
2
3use rustc_span::Symbol;
4
5use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
6
7def_reg_class! {
8    Msp430 Msp430InlineAsmRegClass {
9        reg,
10    }
11}
12
13impl Msp430InlineAsmRegClass {
14    pub fn valid_modifiers(self, _arch: super::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<ModifierInfo> {
27        None
28    }
29
30    pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<ModifierInfo> {
31        None
32    }
33
34    pub fn supported_types(
35        self,
36        arch: InlineAsmArch,
37    ) -> &'static [(InlineAsmType, Option<Symbol>)] {
38        match (self, arch) {
39            (Self::reg, _) => types! { _: I8, I16; },
40        }
41    }
42}
43
44// The reserved registers are taken from:
45// https://github.com/llvm/llvm-project/blob/36cb29cbbe1b22dcd298ad65e1fabe899b7d7249/llvm/lib/Target/MSP430/MSP430RegisterInfo.cpp#L73.
46def_regs! {
47    Msp430 Msp430InlineAsmReg Msp430InlineAsmRegClass {
48        r5: reg = ["r5"],
49        r6: reg = ["r6"],
50        r7: reg = ["r7"],
51        r8: reg = ["r8"],
52        r9: reg = ["r9"],
53        r10: reg = ["r10"],
54        r11: reg = ["r11"],
55        r12: reg = ["r12"],
56        r13: reg = ["r13"],
57        r14: reg = ["r14"],
58        r15: reg = ["r15"],
59
60        #error = ["r0", "pc"] =>
61            "the program counter cannot be used as an operand for inline asm",
62        #error = ["r1", "sp"] =>
63            "the stack pointer cannot be used as an operand for inline asm",
64        #error = ["r2", "sr"] =>
65            "the status register cannot be used as an operand for inline asm",
66        #error = ["r3", "cg"] =>
67            "the constant generator cannot be used as an operand for inline asm",
68        #error = ["r4", "fp"] =>
69            "the frame pointer cannot be used as an operand for inline asm",
70    }
71}
72
73impl Msp430InlineAsmReg {
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}