AVR.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. //===--- AVR.cpp - Implement AVR target feature support -------------------===//
  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 implements AVR TargetInfo objects.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "AVR.h"
  13. #include "clang/Basic/MacroBuilder.h"
  14. #include "llvm/ADT/StringSwitch.h"
  15. using namespace clang;
  16. using namespace clang::targets;
  17. namespace clang {
  18. namespace targets {
  19. /// Information about a specific microcontroller.
  20. struct LLVM_LIBRARY_VISIBILITY MCUInfo {
  21. const char *Name;
  22. const char *DefineName;
  23. const int NumFlashBanks; // Set to 0 for the devices do not support LPM/ELPM.
  24. bool IsTiny; // Set to true for the devices belong to the avrtiny family.
  25. };
  26. // NOTE: This list has been synchronized with gcc-avr 5.4.0 and avr-libc 2.0.0.
  27. static MCUInfo AVRMcus[] = {
  28. {"at90s1200", "__AVR_AT90S1200__", 0, false},
  29. {"attiny11", "__AVR_ATtiny11__", 0, false},
  30. {"attiny12", "__AVR_ATtiny12__", 0, false},
  31. {"attiny15", "__AVR_ATtiny15__", 0, false},
  32. {"attiny28", "__AVR_ATtiny28__", 0, false},
  33. {"at90s2313", "__AVR_AT90S2313__", 1, false},
  34. {"at90s2323", "__AVR_AT90S2323__", 1, false},
  35. {"at90s2333", "__AVR_AT90S2333__", 1, false},
  36. {"at90s2343", "__AVR_AT90S2343__", 1, false},
  37. {"attiny22", "__AVR_ATtiny22__", 1, false},
  38. {"attiny26", "__AVR_ATtiny26__", 1, false},
  39. {"at86rf401", "__AVR_AT86RF401__", 1, false},
  40. {"at90s4414", "__AVR_AT90S4414__", 1, false},
  41. {"at90s4433", "__AVR_AT90S4433__", 1, false},
  42. {"at90s4434", "__AVR_AT90S4434__", 1, false},
  43. {"at90s8515", "__AVR_AT90S8515__", 1, false},
  44. {"at90c8534", "__AVR_AT90c8534__", 1, false},
  45. {"at90s8535", "__AVR_AT90S8535__", 1, false},
  46. {"ata5272", "__AVR_ATA5272__", 1, false},
  47. {"attiny13", "__AVR_ATtiny13__", 1, false},
  48. {"attiny13a", "__AVR_ATtiny13A__", 1, false},
  49. {"attiny2313", "__AVR_ATtiny2313__", 1, false},
  50. {"attiny2313a", "__AVR_ATtiny2313A__", 1, false},
  51. {"attiny24", "__AVR_ATtiny24__", 1, false},
  52. {"attiny24a", "__AVR_ATtiny24A__", 1, false},
  53. {"attiny4313", "__AVR_ATtiny4313__", 1, false},
  54. {"attiny44", "__AVR_ATtiny44__", 1, false},
  55. {"attiny44a", "__AVR_ATtiny44A__", 1, false},
  56. {"attiny84", "__AVR_ATtiny84__", 1, false},
  57. {"attiny84a", "__AVR_ATtiny84A__", 1, false},
  58. {"attiny25", "__AVR_ATtiny25__", 1, false},
  59. {"attiny45", "__AVR_ATtiny45__", 1, false},
  60. {"attiny85", "__AVR_ATtiny85__", 1, false},
  61. {"attiny261", "__AVR_ATtiny261__", 1, false},
  62. {"attiny261a", "__AVR_ATtiny261A__", 1, false},
  63. {"attiny441", "__AVR_ATtiny441__", 1, false},
  64. {"attiny461", "__AVR_ATtiny461__", 1, false},
  65. {"attiny461a", "__AVR_ATtiny461A__", 1, false},
  66. {"attiny841", "__AVR_ATtiny841__", 1, false},
  67. {"attiny861", "__AVR_ATtiny861__", 1, false},
  68. {"attiny861a", "__AVR_ATtiny861A__", 1, false},
  69. {"attiny87", "__AVR_ATtiny87__", 1, false},
  70. {"attiny43u", "__AVR_ATtiny43U__", 1, false},
  71. {"attiny48", "__AVR_ATtiny48__", 1, false},
  72. {"attiny88", "__AVR_ATtiny88__", 1, false},
  73. {"attiny828", "__AVR_ATtiny828__", 1, false},
  74. {"at43usb355", "__AVR_AT43USB355__", 1, false},
  75. {"at76c711", "__AVR_AT76C711__", 1, false},
  76. {"atmega103", "__AVR_ATmega103__", 1, false},
  77. {"at43usb320", "__AVR_AT43USB320__", 1, false},
  78. {"attiny167", "__AVR_ATtiny167__", 1, false},
  79. {"at90usb82", "__AVR_AT90USB82__", 1, false},
  80. {"at90usb162", "__AVR_AT90USB162__", 1, false},
  81. {"ata5505", "__AVR_ATA5505__", 1, false},
  82. {"ata6617c", "__AVR_ATA6617C__", 1, false},
  83. {"ata664251", "__AVR_ATA664251__", 1, false},
  84. {"atmega8u2", "__AVR_ATmega8U2__", 1, false},
  85. {"atmega16u2", "__AVR_ATmega16U2__", 1, false},
  86. {"atmega32u2", "__AVR_ATmega32U2__", 1, false},
  87. {"attiny1634", "__AVR_ATtiny1634__", 1, false},
  88. {"atmega8", "__AVR_ATmega8__", 1, false},
  89. {"ata6289", "__AVR_ATA6289__", 1, false},
  90. {"atmega8a", "__AVR_ATmega8A__", 1, false},
  91. {"ata6285", "__AVR_ATA6285__", 1, false},
  92. {"ata6286", "__AVR_ATA6286__", 1, false},
  93. {"ata6612c", "__AVR_ATA6612C__", 1, false},
  94. {"atmega48", "__AVR_ATmega48__", 1, false},
  95. {"atmega48a", "__AVR_ATmega48A__", 1, false},
  96. {"atmega48pa", "__AVR_ATmega48PA__", 1, false},
  97. {"atmega48pb", "__AVR_ATmega48PB__", 1, false},
  98. {"atmega48p", "__AVR_ATmega48P__", 1, false},
  99. {"atmega88", "__AVR_ATmega88__", 1, false},
  100. {"atmega88a", "__AVR_ATmega88A__", 1, false},
  101. {"atmega88p", "__AVR_ATmega88P__", 1, false},
  102. {"atmega88pa", "__AVR_ATmega88PA__", 1, false},
  103. {"atmega88pb", "__AVR_ATmega88PB__", 1, false},
  104. {"atmega8515", "__AVR_ATmega8515__", 1, false},
  105. {"atmega8535", "__AVR_ATmega8535__", 1, false},
  106. {"atmega8hva", "__AVR_ATmega8HVA__", 1, false},
  107. {"at90pwm1", "__AVR_AT90PWM1__", 1, false},
  108. {"at90pwm2", "__AVR_AT90PWM2__", 1, false},
  109. {"at90pwm2b", "__AVR_AT90PWM2B__", 1, false},
  110. {"at90pwm3", "__AVR_AT90PWM3__", 1, false},
  111. {"at90pwm3b", "__AVR_AT90PWM3B__", 1, false},
  112. {"at90pwm81", "__AVR_AT90PWM81__", 1, false},
  113. {"ata5702m322", "__AVR_ATA5702M322__", 1, false},
  114. {"ata5782", "__AVR_ATA5782__", 1, false},
  115. {"ata5790", "__AVR_ATA5790__", 1, false},
  116. {"ata5790n", "__AVR_ATA5790N__", 1, false},
  117. {"ata5791", "__AVR_ATA5791__", 1, false},
  118. {"ata5795", "__AVR_ATA5795__", 1, false},
  119. {"ata5831", "__AVR_ATA5831__", 1, false},
  120. {"ata6613c", "__AVR_ATA6613C__", 1, false},
  121. {"ata6614q", "__AVR_ATA6614Q__", 1, false},
  122. {"ata8210", "__AVR_ATA8210__", 1, false},
  123. {"ata8510", "__AVR_ATA8510__", 1, false},
  124. {"atmega16", "__AVR_ATmega16__", 1, false},
  125. {"atmega16a", "__AVR_ATmega16A__", 1, false},
  126. {"atmega161", "__AVR_ATmega161__", 1, false},
  127. {"atmega162", "__AVR_ATmega162__", 1, false},
  128. {"atmega163", "__AVR_ATmega163__", 1, false},
  129. {"atmega164a", "__AVR_ATmega164A__", 1, false},
  130. {"atmega164p", "__AVR_ATmega164P__", 1, false},
  131. {"atmega164pa", "__AVR_ATmega164PA__", 1, false},
  132. {"atmega165", "__AVR_ATmega165__", 1, false},
  133. {"atmega165a", "__AVR_ATmega165A__", 1, false},
  134. {"atmega165p", "__AVR_ATmega165P__", 1, false},
  135. {"atmega165pa", "__AVR_ATmega165PA__", 1, false},
  136. {"atmega168", "__AVR_ATmega168__", 1, false},
  137. {"atmega168a", "__AVR_ATmega168A__", 1, false},
  138. {"atmega168p", "__AVR_ATmega168P__", 1, false},
  139. {"atmega168pa", "__AVR_ATmega168PA__", 1, false},
  140. {"atmega168pb", "__AVR_ATmega168PB__", 1, false},
  141. {"atmega169", "__AVR_ATmega169__", 1, false},
  142. {"atmega169a", "__AVR_ATmega169A__", 1, false},
  143. {"atmega169p", "__AVR_ATmega169P__", 1, false},
  144. {"atmega169pa", "__AVR_ATmega169PA__", 1, false},
  145. {"atmega32", "__AVR_ATmega32__", 1, false},
  146. {"atmega32a", "__AVR_ATmega32A__", 1, false},
  147. {"atmega323", "__AVR_ATmega323__", 1, false},
  148. {"atmega324a", "__AVR_ATmega324A__", 1, false},
  149. {"atmega324p", "__AVR_ATmega324P__", 1, false},
  150. {"atmega324pa", "__AVR_ATmega324PA__", 1, false},
  151. {"atmega324pb", "__AVR_ATmega324PB__", 1, false},
  152. {"atmega325", "__AVR_ATmega325__", 1, false},
  153. {"atmega325a", "__AVR_ATmega325A__", 1, false},
  154. {"atmega325p", "__AVR_ATmega325P__", 1, false},
  155. {"atmega325pa", "__AVR_ATmega325PA__", 1, false},
  156. {"atmega3250", "__AVR_ATmega3250__", 1, false},
  157. {"atmega3250a", "__AVR_ATmega3250A__", 1, false},
  158. {"atmega3250p", "__AVR_ATmega3250P__", 1, false},
  159. {"atmega3250pa", "__AVR_ATmega3250PA__", 1, false},
  160. {"atmega328", "__AVR_ATmega328__", 1, false},
  161. {"atmega328p", "__AVR_ATmega328P__", 1, false},
  162. {"atmega328pb", "__AVR_ATmega328PB__", 1, false},
  163. {"atmega329", "__AVR_ATmega329__", 1, false},
  164. {"atmega329a", "__AVR_ATmega329A__", 1, false},
  165. {"atmega329p", "__AVR_ATmega329P__", 1, false},
  166. {"atmega329pa", "__AVR_ATmega329PA__", 1, false},
  167. {"atmega3290", "__AVR_ATmega3290__", 1, false},
  168. {"atmega3290a", "__AVR_ATmega3290A__", 1, false},
  169. {"atmega3290p", "__AVR_ATmega3290P__", 1, false},
  170. {"atmega3290pa", "__AVR_ATmega3290PA__", 1, false},
  171. {"atmega406", "__AVR_ATmega406__", 1, false},
  172. {"atmega64", "__AVR_ATmega64__", 1, false},
  173. {"atmega64a", "__AVR_ATmega64A__", 1, false},
  174. {"atmega640", "__AVR_ATmega640__", 1, false},
  175. {"atmega644", "__AVR_ATmega644__", 1, false},
  176. {"atmega644a", "__AVR_ATmega644A__", 1, false},
  177. {"atmega644p", "__AVR_ATmega644P__", 1, false},
  178. {"atmega644pa", "__AVR_ATmega644PA__", 1, false},
  179. {"atmega645", "__AVR_ATmega645__", 1, false},
  180. {"atmega645a", "__AVR_ATmega645A__", 1, false},
  181. {"atmega645p", "__AVR_ATmega645P__", 1, false},
  182. {"atmega649", "__AVR_ATmega649__", 1, false},
  183. {"atmega649a", "__AVR_ATmega649A__", 1, false},
  184. {"atmega649p", "__AVR_ATmega649P__", 1, false},
  185. {"atmega6450", "__AVR_ATmega6450__", 1, false},
  186. {"atmega6450a", "__AVR_ATmega6450A__", 1, false},
  187. {"atmega6450p", "__AVR_ATmega6450P__", 1, false},
  188. {"atmega6490", "__AVR_ATmega6490__", 1, false},
  189. {"atmega6490a", "__AVR_ATmega6490A__", 1, false},
  190. {"atmega6490p", "__AVR_ATmega6490P__", 1, false},
  191. {"atmega64rfr2", "__AVR_ATmega64RFR2__", 1, false},
  192. {"atmega644rfr2", "__AVR_ATmega644RFR2__", 1, false},
  193. {"atmega16hva", "__AVR_ATmega16HVA__", 1, false},
  194. {"atmega16hva2", "__AVR_ATmega16HVA2__", 1, false},
  195. {"atmega16hvb", "__AVR_ATmega16HVB__", 1, false},
  196. {"atmega16hvbrevb", "__AVR_ATmega16HVBREVB__", 1, false},
  197. {"atmega32hvb", "__AVR_ATmega32HVB__", 1, false},
  198. {"atmega32hvbrevb", "__AVR_ATmega32HVBREVB__", 1, false},
  199. {"atmega64hve", "__AVR_ATmega64HVE__", 1, false},
  200. {"atmega64hve2", "__AVR_ATmega64HVE2__", 1, false},
  201. {"at90can32", "__AVR_AT90CAN32__", 1, false},
  202. {"at90can64", "__AVR_AT90CAN64__", 1, false},
  203. {"at90pwm161", "__AVR_AT90PWM161__", 1, false},
  204. {"at90pwm216", "__AVR_AT90PWM216__", 1, false},
  205. {"at90pwm316", "__AVR_AT90PWM316__", 1, false},
  206. {"atmega32c1", "__AVR_ATmega32C1__", 1, false},
  207. {"atmega64c1", "__AVR_ATmega64C1__", 1, false},
  208. {"atmega16m1", "__AVR_ATmega16M1__", 1, false},
  209. {"atmega32m1", "__AVR_ATmega32M1__", 1, false},
  210. {"atmega64m1", "__AVR_ATmega64M1__", 1, false},
  211. {"atmega16u4", "__AVR_ATmega16U4__", 1, false},
  212. {"atmega32u4", "__AVR_ATmega32U4__", 1, false},
  213. {"atmega32u6", "__AVR_ATmega32U6__", 1, false},
  214. {"at90usb646", "__AVR_AT90USB646__", 1, false},
  215. {"at90usb647", "__AVR_AT90USB647__", 1, false},
  216. {"at90scr100", "__AVR_AT90SCR100__", 1, false},
  217. {"at94k", "__AVR_AT94K__", 1, false},
  218. {"m3000", "__AVR_AT000__", 1, false},
  219. {"atmega128", "__AVR_ATmega128__", 2, false},
  220. {"atmega128a", "__AVR_ATmega128A__", 2, false},
  221. {"atmega1280", "__AVR_ATmega1280__", 2, false},
  222. {"atmega1281", "__AVR_ATmega1281__", 2, false},
  223. {"atmega1284", "__AVR_ATmega1284__", 2, false},
  224. {"atmega1284p", "__AVR_ATmega1284P__", 2, false},
  225. {"atmega128rfa1", "__AVR_ATmega128RFA1__", 2, false},
  226. {"atmega128rfr2", "__AVR_ATmega128RFR2__", 2, false},
  227. {"atmega1284rfr2", "__AVR_ATmega1284RFR2__", 2, false},
  228. {"at90can128", "__AVR_AT90CAN128__", 2, false},
  229. {"at90usb1286", "__AVR_AT90USB1286__", 2, false},
  230. {"at90usb1287", "__AVR_AT90USB1287__", 2, false},
  231. {"atmega2560", "__AVR_ATmega2560__", 4, false},
  232. {"atmega2561", "__AVR_ATmega2561__", 4, false},
  233. {"atmega256rfr2", "__AVR_ATmega256RFR2__", 4, false},
  234. {"atmega2564rfr2", "__AVR_ATmega2564RFR2__", 4, false},
  235. {"atxmega16a4", "__AVR_ATxmega16A4__", 1, false},
  236. {"atxmega16a4u", "__AVR_ATxmega16A4U__", 1, false},
  237. {"atxmega16c4", "__AVR_ATxmega16C4__", 1, false},
  238. {"atxmega16d4", "__AVR_ATxmega16D4__", 1, false},
  239. {"atxmega32a4", "__AVR_ATxmega32A4__", 1, false},
  240. {"atxmega32a4u", "__AVR_ATxmega32A4U__", 1, false},
  241. {"atxmega32c3", "__AVR_ATxmega32C3__", 1, false},
  242. {"atxmega32c4", "__AVR_ATxmega32C4__", 1, false},
  243. {"atxmega32d3", "__AVR_ATxmega32D3__", 1, false},
  244. {"atxmega32d4", "__AVR_ATxmega32D4__", 1, false},
  245. {"atxmega32e5", "__AVR_ATxmega32E5__", 1, false},
  246. {"atxmega16e5", "__AVR_ATxmega16E5__", 1, false},
  247. {"atxmega8e5", "__AVR_ATxmega8E5__", 1, false},
  248. {"atxmega32x1", "__AVR_ATxmega32X1__", 1, false},
  249. {"atxmega64a3", "__AVR_ATxmega64A3__", 1, false},
  250. {"atxmega64a3u", "__AVR_ATxmega64A3U__", 1, false},
  251. {"atxmega64a4u", "__AVR_ATxmega64A4U__", 1, false},
  252. {"atxmega64b1", "__AVR_ATxmega64B1__", 1, false},
  253. {"atxmega64b3", "__AVR_ATxmega64B3__", 1, false},
  254. {"atxmega64c3", "__AVR_ATxmega64C3__", 1, false},
  255. {"atxmega64d3", "__AVR_ATxmega64D3__", 1, false},
  256. {"atxmega64d4", "__AVR_ATxmega64D4__", 1, false},
  257. {"atxmega64a1", "__AVR_ATxmega64A1__", 1, false},
  258. {"atxmega64a1u", "__AVR_ATxmega64A1U__", 1, false},
  259. {"atxmega128a3", "__AVR_ATxmega128A3__", 2, false},
  260. {"atxmega128a3u", "__AVR_ATxmega128A3U__", 2, false},
  261. {"atxmega128b1", "__AVR_ATxmega128B1__", 2, false},
  262. {"atxmega128b3", "__AVR_ATxmega128B3__", 2, false},
  263. {"atxmega128c3", "__AVR_ATxmega128C3__", 2, false},
  264. {"atxmega128d3", "__AVR_ATxmega128D3__", 2, false},
  265. {"atxmega128d4", "__AVR_ATxmega128D4__", 2, false},
  266. {"atxmega192a3", "__AVR_ATxmega192A3__", 3, false},
  267. {"atxmega192a3u", "__AVR_ATxmega192A3U__", 3, false},
  268. {"atxmega192c3", "__AVR_ATxmega192C3__", 3, false},
  269. {"atxmega192d3", "__AVR_ATxmega192D3__", 3, false},
  270. {"atxmega256a3", "__AVR_ATxmega256A3__", 4, false},
  271. {"atxmega256a3u", "__AVR_ATxmega256A3U__", 4, false},
  272. {"atxmega256a3b", "__AVR_ATxmega256A3B__", 4, false},
  273. {"atxmega256a3bu", "__AVR_ATxmega256A3BU__", 4, false},
  274. {"atxmega256c3", "__AVR_ATxmega256C3__", 4, false},
  275. {"atxmega256d3", "__AVR_ATxmega256D3__", 4, false},
  276. {"atxmega384c3", "__AVR_ATxmega384C3__", 6, false},
  277. {"atxmega384d3", "__AVR_ATxmega384D3__", 6, false},
  278. {"atxmega128a1", "__AVR_ATxmega128A1__", 2, false},
  279. {"atxmega128a1u", "__AVR_ATxmega128A1U__", 2, false},
  280. {"atxmega128a4u", "__AVR_ATxmega128A4U__", 2, false},
  281. {"attiny4", "__AVR_ATtiny4__", 0, true},
  282. {"attiny5", "__AVR_ATtiny5__", 0, true},
  283. {"attiny9", "__AVR_ATtiny9__", 0, true},
  284. {"attiny10", "__AVR_ATtiny10__", 0, true},
  285. {"attiny20", "__AVR_ATtiny20__", 0, true},
  286. {"attiny40", "__AVR_ATtiny40__", 0, true},
  287. {"attiny102", "__AVR_ATtiny102__", 0, true},
  288. {"attiny104", "__AVR_ATtiny104__", 0, true},
  289. {"attiny202", "__AVR_ATtiny202__", 1, true},
  290. {"attiny402", "__AVR_ATtiny402__", 1, true},
  291. {"attiny204", "__AVR_ATtiny204__", 1, true},
  292. {"attiny404", "__AVR_ATtiny404__", 1, true},
  293. {"attiny804", "__AVR_ATtiny804__", 1, true},
  294. {"attiny1604", "__AVR_ATtiny1604__", 1, true},
  295. {"attiny406", "__AVR_ATtiny406__", 1, true},
  296. {"attiny806", "__AVR_ATtiny806__", 1, true},
  297. {"attiny1606", "__AVR_ATtiny1606__", 1, true},
  298. {"attiny807", "__AVR_ATtiny807__", 1, true},
  299. {"attiny1607", "__AVR_ATtiny1607__", 1, true},
  300. {"attiny212", "__AVR_ATtiny212__", 1, true},
  301. {"attiny412", "__AVR_ATtiny412__", 1, true},
  302. {"attiny214", "__AVR_ATtiny214__", 1, true},
  303. {"attiny414", "__AVR_ATtiny414__", 1, true},
  304. {"attiny814", "__AVR_ATtiny814__", 1, true},
  305. {"attiny1614", "__AVR_ATtiny1614__", 1, true},
  306. {"attiny416", "__AVR_ATtiny416__", 1, true},
  307. {"attiny816", "__AVR_ATtiny816__", 1, true},
  308. {"attiny1616", "__AVR_ATtiny1616__", 1, true},
  309. {"attiny3216", "__AVR_ATtiny3216__", 1, true},
  310. {"attiny417", "__AVR_ATtiny417__", 1, true},
  311. {"attiny817", "__AVR_ATtiny817__", 1, true},
  312. {"attiny1617", "__AVR_ATtiny1617__", 1, true},
  313. {"attiny3217", "__AVR_ATtiny3217__", 1, true},
  314. };
  315. } // namespace targets
  316. } // namespace clang
  317. static constexpr llvm::StringLiteral ValidFamilyNames[] = {
  318. "avr1", "avr2", "avr25", "avr3", "avr31",
  319. "avr35", "avr4", "avr5", "avr51", "avr6",
  320. "avrxmega1", "avrxmega2", "avrxmega3", "avrxmega4", "avrxmega5",
  321. "avrxmega6", "avrxmega7", "avrtiny"};
  322. bool AVRTargetInfo::isValidCPUName(StringRef Name) const {
  323. bool IsFamily = llvm::is_contained(ValidFamilyNames, Name);
  324. bool IsMCU = llvm::any_of(
  325. AVRMcus, [&](const MCUInfo &Info) { return Info.Name == Name; });
  326. return IsFamily || IsMCU;
  327. }
  328. void AVRTargetInfo::fillValidCPUList(SmallVectorImpl<StringRef> &Values) const {
  329. Values.append(std::begin(ValidFamilyNames), std::end(ValidFamilyNames));
  330. for (const MCUInfo &Info : AVRMcus)
  331. Values.push_back(Info.Name);
  332. }
  333. bool AVRTargetInfo::setCPU(const std::string &Name) {
  334. // Set the ABI and CPU fields if parameter Name is a family name.
  335. if (llvm::is_contained(ValidFamilyNames, Name)) {
  336. CPU = Name;
  337. ABI = Name == "avrtiny" ? "avrtiny" : "avr";
  338. return true;
  339. }
  340. // Set the ABI field if parameter Name is a device name.
  341. auto It = llvm::find_if(
  342. AVRMcus, [&](const MCUInfo &Info) { return Info.Name == Name; });
  343. if (It != std::end(AVRMcus)) {
  344. CPU = Name;
  345. ABI = It->IsTiny ? "avrtiny" : "avr";
  346. return true;
  347. }
  348. // Parameter Name is neither valid family name nor valid device name.
  349. return false;
  350. }
  351. void AVRTargetInfo::getTargetDefines(const LangOptions &Opts,
  352. MacroBuilder &Builder) const {
  353. Builder.defineMacro("AVR");
  354. Builder.defineMacro("__AVR");
  355. Builder.defineMacro("__AVR__");
  356. Builder.defineMacro("__ELF__");
  357. if (!this->CPU.empty()) {
  358. auto It = llvm::find_if(
  359. AVRMcus, [&](const MCUInfo &Info) { return Info.Name == this->CPU; });
  360. if (It != std::end(AVRMcus)) {
  361. Builder.defineMacro(It->DefineName);
  362. if (It->NumFlashBanks >= 1)
  363. Builder.defineMacro("__flash", "__attribute__((address_space(1)))");
  364. if (It->NumFlashBanks >= 2)
  365. Builder.defineMacro("__flash1", "__attribute__((address_space(2)))");
  366. if (It->NumFlashBanks >= 3)
  367. Builder.defineMacro("__flash2", "__attribute__((address_space(3)))");
  368. if (It->NumFlashBanks >= 4)
  369. Builder.defineMacro("__flash3", "__attribute__((address_space(4)))");
  370. if (It->NumFlashBanks >= 5)
  371. Builder.defineMacro("__flash4", "__attribute__((address_space(5)))");
  372. if (It->NumFlashBanks >= 6)
  373. Builder.defineMacro("__flash5", "__attribute__((address_space(6)))");
  374. }
  375. }
  376. }