/src/llvm-project/clang/lib/Basic/Targets/AVR.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- AVR.h - Declare AVR target feature support -------------*- C++ -*-===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // This file declares AVR TargetInfo objects. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_AVR_H |
14 | | #define LLVM_CLANG_LIB_BASIC_TARGETS_AVR_H |
15 | | |
16 | | #include "clang/Basic/TargetInfo.h" |
17 | | #include "clang/Basic/TargetOptions.h" |
18 | | #include "llvm/Support/Compiler.h" |
19 | | #include "llvm/TargetParser/Triple.h" |
20 | | |
21 | | namespace clang { |
22 | | namespace targets { |
23 | | |
24 | | // AVR Target |
25 | | class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo { |
26 | | public: |
27 | | AVRTargetInfo(const llvm::Triple &Triple, const TargetOptions &) |
28 | 0 | : TargetInfo(Triple) { |
29 | 0 | TLSSupported = false; |
30 | 0 | PointerWidth = 16; |
31 | 0 | PointerAlign = 8; |
32 | 0 | IntWidth = 16; |
33 | 0 | IntAlign = 8; |
34 | 0 | LongWidth = 32; |
35 | 0 | LongAlign = 8; |
36 | 0 | LongLongWidth = 64; |
37 | 0 | LongLongAlign = 8; |
38 | 0 | SuitableAlign = 8; |
39 | 0 | DefaultAlignForAttributeAligned = 8; |
40 | 0 | HalfWidth = 16; |
41 | 0 | HalfAlign = 8; |
42 | 0 | FloatWidth = 32; |
43 | 0 | FloatAlign = 8; |
44 | 0 | DoubleWidth = 32; |
45 | 0 | DoubleAlign = 8; |
46 | 0 | DoubleFormat = &llvm::APFloat::IEEEsingle(); |
47 | 0 | LongDoubleWidth = 32; |
48 | 0 | LongDoubleAlign = 8; |
49 | 0 | LongDoubleFormat = &llvm::APFloat::IEEEsingle(); |
50 | 0 | SizeType = UnsignedInt; |
51 | 0 | PtrDiffType = SignedInt; |
52 | 0 | IntPtrType = SignedInt; |
53 | 0 | Char16Type = UnsignedInt; |
54 | 0 | WIntType = SignedInt; |
55 | 0 | Int16Type = SignedInt; |
56 | 0 | Char32Type = UnsignedLong; |
57 | 0 | SigAtomicType = SignedChar; |
58 | 0 | resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"); |
59 | 0 | } |
60 | | |
61 | | void getTargetDefines(const LangOptions &Opts, |
62 | | MacroBuilder &Builder) const override; |
63 | | |
64 | 0 | ArrayRef<Builtin::Info> getTargetBuiltins() const override { |
65 | 0 | return std::nullopt; |
66 | 0 | } |
67 | | |
68 | 0 | BuiltinVaListKind getBuiltinVaListKind() const override { |
69 | 0 | return TargetInfo::VoidPtrBuiltinVaList; |
70 | 0 | } |
71 | | |
72 | 0 | std::string_view getClobbers() const override { return ""; } |
73 | | |
74 | 0 | ArrayRef<const char *> getGCCRegNames() const override { |
75 | 0 | static const char *const GCCRegNames[] = { |
76 | 0 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", |
77 | 0 | "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19", |
78 | 0 | "r20", "r21", "r22", "r23", "r24", "r25", "X", "Y", "Z", "SP"}; |
79 | 0 | return llvm::ArrayRef(GCCRegNames); |
80 | 0 | } |
81 | | |
82 | 0 | ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override { |
83 | 0 | return std::nullopt; |
84 | 0 | } |
85 | | |
86 | 0 | ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override { |
87 | 0 | static const TargetInfo::AddlRegName AddlRegNames[] = { |
88 | 0 | {{"r26", "r27"}, 26}, |
89 | 0 | {{"r28", "r29"}, 27}, |
90 | 0 | {{"r30", "r31"}, 28}, |
91 | 0 | {{"SPL", "SPH"}, 29}, |
92 | 0 | }; |
93 | 0 | return llvm::ArrayRef(AddlRegNames); |
94 | 0 | } |
95 | | |
96 | | bool validateAsmConstraint(const char *&Name, |
97 | 0 | TargetInfo::ConstraintInfo &Info) const override { |
98 | | // There aren't any multi-character AVR specific constraints. |
99 | 0 | if (StringRef(Name).size() > 1) |
100 | 0 | return false; |
101 | | |
102 | 0 | switch (*Name) { |
103 | 0 | default: |
104 | 0 | return false; |
105 | 0 | case 'a': // Simple upper registers |
106 | 0 | case 'b': // Base pointer registers pairs |
107 | 0 | case 'd': // Upper register |
108 | 0 | case 'l': // Lower registers |
109 | 0 | case 'e': // Pointer register pairs |
110 | 0 | case 'q': // Stack pointer register |
111 | 0 | case 'r': // Any register |
112 | 0 | case 'w': // Special upper register pairs |
113 | 0 | case 't': // Temporary register |
114 | 0 | case 'x': |
115 | 0 | case 'X': // Pointer register pair X |
116 | 0 | case 'y': |
117 | 0 | case 'Y': // Pointer register pair Y |
118 | 0 | case 'z': |
119 | 0 | case 'Z': // Pointer register pair Z |
120 | 0 | Info.setAllowsRegister(); |
121 | 0 | return true; |
122 | 0 | case 'I': // 6-bit positive integer constant |
123 | 0 | Info.setRequiresImmediate(0, 63); |
124 | 0 | return true; |
125 | 0 | case 'J': // 6-bit negative integer constant |
126 | 0 | Info.setRequiresImmediate(-63, 0); |
127 | 0 | return true; |
128 | 0 | case 'K': // Integer constant (Range: 2) |
129 | 0 | Info.setRequiresImmediate(2); |
130 | 0 | return true; |
131 | 0 | case 'L': // Integer constant (Range: 0) |
132 | 0 | Info.setRequiresImmediate(0); |
133 | 0 | return true; |
134 | 0 | case 'M': // 8-bit integer constant |
135 | 0 | Info.setRequiresImmediate(0, 0xff); |
136 | 0 | return true; |
137 | 0 | case 'N': // Integer constant (Range: -1) |
138 | 0 | Info.setRequiresImmediate(-1); |
139 | 0 | return true; |
140 | 0 | case 'O': // Integer constant (Range: 8, 16, 24) |
141 | 0 | Info.setRequiresImmediate({8, 16, 24}); |
142 | 0 | return true; |
143 | 0 | case 'P': // Integer constant (Range: 1) |
144 | 0 | Info.setRequiresImmediate(1); |
145 | 0 | return true; |
146 | 0 | case 'R': // Integer constant (Range: -6 to 5) |
147 | 0 | Info.setRequiresImmediate(-6, 5); |
148 | 0 | return true; |
149 | 0 | case 'G': // Floating point constant 0.0 |
150 | 0 | Info.setRequiresImmediate(0); |
151 | 0 | return true; |
152 | 0 | case 'Q': // A memory address based on Y or Z pointer with displacement. |
153 | 0 | return true; |
154 | 0 | } |
155 | | |
156 | 0 | return false; |
157 | 0 | } |
158 | | |
159 | 0 | IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final { |
160 | | // AVR prefers int for 16-bit integers. |
161 | 0 | return BitWidth == 16 ? (IsSigned ? SignedInt : UnsignedInt) |
162 | 0 | : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned); |
163 | 0 | } |
164 | | |
165 | 0 | IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final { |
166 | | // AVR uses int for int_least16_t and int_fast16_t. |
167 | 0 | return BitWidth == 16 |
168 | 0 | ? (IsSigned ? SignedInt : UnsignedInt) |
169 | 0 | : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned); |
170 | 0 | } |
171 | | |
172 | | bool isValidCPUName(StringRef Name) const override; |
173 | | void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override; |
174 | | bool setCPU(const std::string &Name) override; |
175 | | std::optional<std::string> handleAsmEscapedChar(char EscChar) const override; |
176 | 0 | StringRef getABI() const override { return ABI; } |
177 | | |
178 | | protected: |
179 | | std::string CPU; |
180 | | StringRef ABI; |
181 | | StringRef DefineName; |
182 | | StringRef Arch; |
183 | | int NumFlashBanks = 0; |
184 | | }; |
185 | | |
186 | | } // namespace targets |
187 | | } // namespace clang |
188 | | |
189 | | #endif // LLVM_CLANG_LIB_BASIC_TARGETS_AVR_H |