clang  6.0.0svn
AVR.cpp
Go to the documentation of this file.
1 //===--- AVR.cpp - Implement AVR target feature support -------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements AVR TargetInfo objects.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "AVR.h"
16 #include "llvm/ADT/StringSwitch.h"
17 
18 using namespace clang;
19 using namespace clang::targets;
20 
21 namespace clang {
22 namespace targets {
23 
24 /// Information about a specific microcontroller.
25 struct LLVM_LIBRARY_VISIBILITY MCUInfo {
26  const char *Name;
27  const char *DefineName;
28 };
29 
30 // This list should be kept up-to-date with AVRDevices.td in LLVM.
32  {"at90s1200", "__AVR_AT90S1200__"},
33  {"attiny11", "__AVR_ATtiny11__"},
34  {"attiny12", "__AVR_ATtiny12__"},
35  {"attiny15", "__AVR_ATtiny15__"},
36  {"attiny28", "__AVR_ATtiny28__"},
37  {"at90s2313", "__AVR_AT90S2313__"},
38  {"at90s2323", "__AVR_AT90S2323__"},
39  {"at90s2333", "__AVR_AT90S2333__"},
40  {"at90s2343", "__AVR_AT90S2343__"},
41  {"attiny22", "__AVR_ATtiny22__"},
42  {"attiny26", "__AVR_ATtiny26__"},
43  {"at86rf401", "__AVR_AT86RF401__"},
44  {"at90s4414", "__AVR_AT90S4414__"},
45  {"at90s4433", "__AVR_AT90S4433__"},
46  {"at90s4434", "__AVR_AT90S4434__"},
47  {"at90s8515", "__AVR_AT90S8515__"},
48  {"at90c8534", "__AVR_AT90c8534__"},
49  {"at90s8535", "__AVR_AT90S8535__"},
50  {"ata5272", "__AVR_ATA5272__"},
51  {"attiny13", "__AVR_ATtiny13__"},
52  {"attiny13a", "__AVR_ATtiny13A__"},
53  {"attiny2313", "__AVR_ATtiny2313__"},
54  {"attiny2313a", "__AVR_ATtiny2313A__"},
55  {"attiny24", "__AVR_ATtiny24__"},
56  {"attiny24a", "__AVR_ATtiny24A__"},
57  {"attiny4313", "__AVR_ATtiny4313__"},
58  {"attiny44", "__AVR_ATtiny44__"},
59  {"attiny44a", "__AVR_ATtiny44A__"},
60  {"attiny84", "__AVR_ATtiny84__"},
61  {"attiny84a", "__AVR_ATtiny84A__"},
62  {"attiny25", "__AVR_ATtiny25__"},
63  {"attiny45", "__AVR_ATtiny45__"},
64  {"attiny85", "__AVR_ATtiny85__"},
65  {"attiny261", "__AVR_ATtiny261__"},
66  {"attiny261a", "__AVR_ATtiny261A__"},
67  {"attiny461", "__AVR_ATtiny461__"},
68  {"attiny461a", "__AVR_ATtiny461A__"},
69  {"attiny861", "__AVR_ATtiny861__"},
70  {"attiny861a", "__AVR_ATtiny861A__"},
71  {"attiny87", "__AVR_ATtiny87__"},
72  {"attiny43u", "__AVR_ATtiny43U__"},
73  {"attiny48", "__AVR_ATtiny48__"},
74  {"attiny88", "__AVR_ATtiny88__"},
75  {"attiny828", "__AVR_ATtiny828__"},
76  {"at43usb355", "__AVR_AT43USB355__"},
77  {"at76c711", "__AVR_AT76C711__"},
78  {"atmega103", "__AVR_ATmega103__"},
79  {"at43usb320", "__AVR_AT43USB320__"},
80  {"attiny167", "__AVR_ATtiny167__"},
81  {"at90usb82", "__AVR_AT90USB82__"},
82  {"at90usb162", "__AVR_AT90USB162__"},
83  {"ata5505", "__AVR_ATA5505__"},
84  {"atmega8u2", "__AVR_ATmega8U2__"},
85  {"atmega16u2", "__AVR_ATmega16U2__"},
86  {"atmega32u2", "__AVR_ATmega32U2__"},
87  {"attiny1634", "__AVR_ATtiny1634__"},
88  {"atmega8", "__AVR_ATmega8__"},
89  {"ata6289", "__AVR_ATA6289__"},
90  {"atmega8a", "__AVR_ATmega8A__"},
91  {"ata6285", "__AVR_ATA6285__"},
92  {"ata6286", "__AVR_ATA6286__"},
93  {"atmega48", "__AVR_ATmega48__"},
94  {"atmega48a", "__AVR_ATmega48A__"},
95  {"atmega48pa", "__AVR_ATmega48PA__"},
96  {"atmega48p", "__AVR_ATmega48P__"},
97  {"atmega88", "__AVR_ATmega88__"},
98  {"atmega88a", "__AVR_ATmega88A__"},
99  {"atmega88p", "__AVR_ATmega88P__"},
100  {"atmega88pa", "__AVR_ATmega88PA__"},
101  {"atmega8515", "__AVR_ATmega8515__"},
102  {"atmega8535", "__AVR_ATmega8535__"},
103  {"atmega8hva", "__AVR_ATmega8HVA__"},
104  {"at90pwm1", "__AVR_AT90PWM1__"},
105  {"at90pwm2", "__AVR_AT90PWM2__"},
106  {"at90pwm2b", "__AVR_AT90PWM2B__"},
107  {"at90pwm3", "__AVR_AT90PWM3__"},
108  {"at90pwm3b", "__AVR_AT90PWM3B__"},
109  {"at90pwm81", "__AVR_AT90PWM81__"},
110  {"ata5790", "__AVR_ATA5790__"},
111  {"ata5795", "__AVR_ATA5795__"},
112  {"atmega16", "__AVR_ATmega16__"},
113  {"atmega16a", "__AVR_ATmega16A__"},
114  {"atmega161", "__AVR_ATmega161__"},
115  {"atmega162", "__AVR_ATmega162__"},
116  {"atmega163", "__AVR_ATmega163__"},
117  {"atmega164a", "__AVR_ATmega164A__"},
118  {"atmega164p", "__AVR_ATmega164P__"},
119  {"atmega164pa", "__AVR_ATmega164PA__"},
120  {"atmega165", "__AVR_ATmega165__"},
121  {"atmega165a", "__AVR_ATmega165A__"},
122  {"atmega165p", "__AVR_ATmega165P__"},
123  {"atmega165pa", "__AVR_ATmega165PA__"},
124  {"atmega168", "__AVR_ATmega168__"},
125  {"atmega168a", "__AVR_ATmega168A__"},
126  {"atmega168p", "__AVR_ATmega168P__"},
127  {"atmega168pa", "__AVR_ATmega168PA__"},
128  {"atmega169", "__AVR_ATmega169__"},
129  {"atmega169a", "__AVR_ATmega169A__"},
130  {"atmega169p", "__AVR_ATmega169P__"},
131  {"atmega169pa", "__AVR_ATmega169PA__"},
132  {"atmega32", "__AVR_ATmega32__"},
133  {"atmega32a", "__AVR_ATmega32A__"},
134  {"atmega323", "__AVR_ATmega323__"},
135  {"atmega324a", "__AVR_ATmega324A__"},
136  {"atmega324p", "__AVR_ATmega324P__"},
137  {"atmega324pa", "__AVR_ATmega324PA__"},
138  {"atmega325", "__AVR_ATmega325__"},
139  {"atmega325a", "__AVR_ATmega325A__"},
140  {"atmega325p", "__AVR_ATmega325P__"},
141  {"atmega325pa", "__AVR_ATmega325PA__"},
142  {"atmega3250", "__AVR_ATmega3250__"},
143  {"atmega3250a", "__AVR_ATmega3250A__"},
144  {"atmega3250p", "__AVR_ATmega3250P__"},
145  {"atmega3250pa", "__AVR_ATmega3250PA__"},
146  {"atmega328", "__AVR_ATmega328__"},
147  {"atmega328p", "__AVR_ATmega328P__"},
148  {"atmega329", "__AVR_ATmega329__"},
149  {"atmega329a", "__AVR_ATmega329A__"},
150  {"atmega329p", "__AVR_ATmega329P__"},
151  {"atmega329pa", "__AVR_ATmega329PA__"},
152  {"atmega3290", "__AVR_ATmega3290__"},
153  {"atmega3290a", "__AVR_ATmega3290A__"},
154  {"atmega3290p", "__AVR_ATmega3290P__"},
155  {"atmega3290pa", "__AVR_ATmega3290PA__"},
156  {"atmega406", "__AVR_ATmega406__"},
157  {"atmega64", "__AVR_ATmega64__"},
158  {"atmega64a", "__AVR_ATmega64A__"},
159  {"atmega640", "__AVR_ATmega640__"},
160  {"atmega644", "__AVR_ATmega644__"},
161  {"atmega644a", "__AVR_ATmega644A__"},
162  {"atmega644p", "__AVR_ATmega644P__"},
163  {"atmega644pa", "__AVR_ATmega644PA__"},
164  {"atmega645", "__AVR_ATmega645__"},
165  {"atmega645a", "__AVR_ATmega645A__"},
166  {"atmega645p", "__AVR_ATmega645P__"},
167  {"atmega649", "__AVR_ATmega649__"},
168  {"atmega649a", "__AVR_ATmega649A__"},
169  {"atmega649p", "__AVR_ATmega649P__"},
170  {"atmega6450", "__AVR_ATmega6450__"},
171  {"atmega6450a", "__AVR_ATmega6450A__"},
172  {"atmega6450p", "__AVR_ATmega6450P__"},
173  {"atmega6490", "__AVR_ATmega6490__"},
174  {"atmega6490a", "__AVR_ATmega6490A__"},
175  {"atmega6490p", "__AVR_ATmega6490P__"},
176  {"atmega64rfr2", "__AVR_ATmega64RFR2__"},
177  {"atmega644rfr2", "__AVR_ATmega644RFR2__"},
178  {"atmega16hva", "__AVR_ATmega16HVA__"},
179  {"atmega16hva2", "__AVR_ATmega16HVA2__"},
180  {"atmega16hvb", "__AVR_ATmega16HVB__"},
181  {"atmega16hvbrevb", "__AVR_ATmega16HVBREVB__"},
182  {"atmega32hvb", "__AVR_ATmega32HVB__"},
183  {"atmega32hvbrevb", "__AVR_ATmega32HVBREVB__"},
184  {"atmega64hve", "__AVR_ATmega64HVE__"},
185  {"at90can32", "__AVR_AT90CAN32__"},
186  {"at90can64", "__AVR_AT90CAN64__"},
187  {"at90pwm161", "__AVR_AT90PWM161__"},
188  {"at90pwm216", "__AVR_AT90PWM216__"},
189  {"at90pwm316", "__AVR_AT90PWM316__"},
190  {"atmega32c1", "__AVR_ATmega32C1__"},
191  {"atmega64c1", "__AVR_ATmega64C1__"},
192  {"atmega16m1", "__AVR_ATmega16M1__"},
193  {"atmega32m1", "__AVR_ATmega32M1__"},
194  {"atmega64m1", "__AVR_ATmega64M1__"},
195  {"atmega16u4", "__AVR_ATmega16U4__"},
196  {"atmega32u4", "__AVR_ATmega32U4__"},
197  {"atmega32u6", "__AVR_ATmega32U6__"},
198  {"at90usb646", "__AVR_AT90USB646__"},
199  {"at90usb647", "__AVR_AT90USB647__"},
200  {"at90scr100", "__AVR_AT90SCR100__"},
201  {"at94k", "__AVR_AT94K__"},
202  {"m3000", "__AVR_AT000__"},
203  {"atmega128", "__AVR_ATmega128__"},
204  {"atmega128a", "__AVR_ATmega128A__"},
205  {"atmega1280", "__AVR_ATmega1280__"},
206  {"atmega1281", "__AVR_ATmega1281__"},
207  {"atmega1284", "__AVR_ATmega1284__"},
208  {"atmega1284p", "__AVR_ATmega1284P__"},
209  {"atmega128rfa1", "__AVR_ATmega128RFA1__"},
210  {"atmega128rfr2", "__AVR_ATmega128RFR2__"},
211  {"atmega1284rfr2", "__AVR_ATmega1284RFR2__"},
212  {"at90can128", "__AVR_AT90CAN128__"},
213  {"at90usb1286", "__AVR_AT90USB1286__"},
214  {"at90usb1287", "__AVR_AT90USB1287__"},
215  {"atmega2560", "__AVR_ATmega2560__"},
216  {"atmega2561", "__AVR_ATmega2561__"},
217  {"atmega256rfr2", "__AVR_ATmega256RFR2__"},
218  {"atmega2564rfr2", "__AVR_ATmega2564RFR2__"},
219  {"atxmega16a4", "__AVR_ATxmega16A4__"},
220  {"atxmega16a4u", "__AVR_ATxmega16a4U__"},
221  {"atxmega16c4", "__AVR_ATxmega16C4__"},
222  {"atxmega16d4", "__AVR_ATxmega16D4__"},
223  {"atxmega32a4", "__AVR_ATxmega32A4__"},
224  {"atxmega32a4u", "__AVR_ATxmega32A4U__"},
225  {"atxmega32c4", "__AVR_ATxmega32C4__"},
226  {"atxmega32d4", "__AVR_ATxmega32D4__"},
227  {"atxmega32e5", "__AVR_ATxmega32E5__"},
228  {"atxmega16e5", "__AVR_ATxmega16E5__"},
229  {"atxmega8e5", "__AVR_ATxmega8E5__"},
230  {"atxmega32x1", "__AVR_ATxmega32X1__"},
231  {"atxmega64a3", "__AVR_ATxmega64A3__"},
232  {"atxmega64a3u", "__AVR_ATxmega64A3U__"},
233  {"atxmega64a4u", "__AVR_ATxmega64A4U__"},
234  {"atxmega64b1", "__AVR_ATxmega64B1__"},
235  {"atxmega64b3", "__AVR_ATxmega64B3__"},
236  {"atxmega64c3", "__AVR_ATxmega64C3__"},
237  {"atxmega64d3", "__AVR_ATxmega64D3__"},
238  {"atxmega64d4", "__AVR_ATxmega64D4__"},
239  {"atxmega64a1", "__AVR_ATxmega64A1__"},
240  {"atxmega64a1u", "__AVR_ATxmega64A1U__"},
241  {"atxmega128a3", "__AVR_ATxmega128A3__"},
242  {"atxmega128a3u", "__AVR_ATxmega128A3U__"},
243  {"atxmega128b1", "__AVR_ATxmega128B1__"},
244  {"atxmega128b3", "__AVR_ATxmega128B3__"},
245  {"atxmega128c3", "__AVR_ATxmega128C3__"},
246  {"atxmega128d3", "__AVR_ATxmega128D3__"},
247  {"atxmega128d4", "__AVR_ATxmega128D4__"},
248  {"atxmega192a3", "__AVR_ATxmega192A3__"},
249  {"atxmega192a3u", "__AVR_ATxmega192A3U__"},
250  {"atxmega192c3", "__AVR_ATxmega192C3__"},
251  {"atxmega192d3", "__AVR_ATxmega192D3__"},
252  {"atxmega256a3", "__AVR_ATxmega256A3__"},
253  {"atxmega256a3u", "__AVR_ATxmega256A3U__"},
254  {"atxmega256a3b", "__AVR_ATxmega256A3B__"},
255  {"atxmega256a3bu", "__AVR_ATxmega256A3BU__"},
256  {"atxmega256c3", "__AVR_ATxmega256C3__"},
257  {"atxmega256d3", "__AVR_ATxmega256D3__"},
258  {"atxmega384c3", "__AVR_ATxmega384C3__"},
259  {"atxmega384d3", "__AVR_ATxmega384D3__"},
260  {"atxmega128a1", "__AVR_ATxmega128A1__"},
261  {"atxmega128a1u", "__AVR_ATxmega128A1U__"},
262  {"atxmega128a4u", "__AVR_ATxmega128a4U__"},
263  {"attiny4", "__AVR_ATtiny4__"},
264  {"attiny5", "__AVR_ATtiny5__"},
265  {"attiny9", "__AVR_ATtiny9__"},
266  {"attiny10", "__AVR_ATtiny10__"},
267  {"attiny20", "__AVR_ATtiny20__"},
268  {"attiny40", "__AVR_ATtiny40__"},
269  {"attiny102", "__AVR_ATtiny102__"},
270  {"attiny104", "__AVR_ATtiny104__"},
271 };
272 
273 } // namespace targets
274 } // namespace clang
275 
276 bool AVRTargetInfo::isValidCPUName(StringRef Name) const {
277  bool IsFamily = llvm::StringSwitch<bool>(Name)
278  .Case("avr1", true)
279  .Case("avr2", true)
280  .Case("avr25", true)
281  .Case("avr3", true)
282  .Case("avr31", true)
283  .Case("avr35", true)
284  .Case("avr4", true)
285  .Case("avr5", true)
286  .Case("avr51", true)
287  .Case("avr6", true)
288  .Case("avrxmega1", true)
289  .Case("avrxmega2", true)
290  .Case("avrxmega3", true)
291  .Case("avrxmega4", true)
292  .Case("avrxmega5", true)
293  .Case("avrxmega6", true)
294  .Case("avrxmega7", true)
295  .Case("avrtiny", true)
296  .Default(false);
297 
298  bool IsMCU =
299  std::find_if(AVRMcus.begin(), AVRMcus.end(), [&](const MCUInfo &Info) {
300  return Info.Name == Name;
301  }) != AVRMcus.end();
302  return IsFamily || IsMCU;
303 }
304 
306  MacroBuilder &Builder) const {
307  Builder.defineMacro("AVR");
308  Builder.defineMacro("__AVR");
309  Builder.defineMacro("__AVR__");
310 
311  if (!this->CPU.empty()) {
312  auto It =
313  std::find_if(AVRMcus.begin(), AVRMcus.end(), [&](const MCUInfo &Info) {
314  return Info.Name == this->CPU;
315  });
316 
317  if (It != AVRMcus.end())
318  Builder.defineMacro(It->DefineName);
319  }
320 }
Defines the clang::MacroBuilder utility class.
Information about a specific microcontroller.
Definition: AVR.cpp:25
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
const char * Name
Definition: AVR.cpp:26
const char * DefineName
Definition: AVR.cpp:27
static ArrayRef< MCUInfo > AVRMcus
Definition: AVR.cpp:31
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods --------------------——===//
Definition: AVR.cpp:305
bool isValidCPUName(StringRef Name) const override
brief Determine whether this TargetInfo supports the given CPU name.
Definition: AVR.cpp:276
Dataflow Directional Tag Classes.
void defineMacro(const Twine &Name, const Twine &Value="1")
Append a #define line for macro of the form "\#define Name Value\n".
Definition: MacroBuilder.h:30