AVR.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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. StringRef Arch; // The __AVR_ARCH__ value.
  24. const int NumFlashBanks; // Set to 0 for the devices do not support LPM/ELPM.
  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. {"avr1", NULL, "1", 0},
  29. {"at90s1200", "__AVR_AT90S1200__", "1", 0},
  30. {"attiny11", "__AVR_ATtiny11__", "1", 0},
  31. {"attiny12", "__AVR_ATtiny12__", "1", 0},
  32. {"attiny15", "__AVR_ATtiny15__", "1", 0},
  33. {"attiny28", "__AVR_ATtiny28__", "1", 0},
  34. {"avr2", NULL, "2", 1},
  35. {"at90s2313", "__AVR_AT90S2313__", "2", 1},
  36. {"at90s2323", "__AVR_AT90S2323__", "2", 1},
  37. {"at90s2333", "__AVR_AT90S2333__", "2", 1},
  38. {"at90s2343", "__AVR_AT90S2343__", "2", 1},
  39. {"attiny22", "__AVR_ATtiny22__", "2", 1},
  40. {"attiny26", "__AVR_ATtiny26__", "2", 1},
  41. {"at86rf401", "__AVR_AT86RF401__", "25", 1},
  42. {"at90s4414", "__AVR_AT90S4414__", "2", 1},
  43. {"at90s4433", "__AVR_AT90S4433__", "2", 1},
  44. {"at90s4434", "__AVR_AT90S4434__", "2", 1},
  45. {"at90s8515", "__AVR_AT90S8515__", "2", 1},
  46. {"at90c8534", "__AVR_AT90c8534__", "2", 1},
  47. {"at90s8535", "__AVR_AT90S8535__", "2", 1},
  48. {"avr25", NULL, "25", 1},
  49. {"ata5272", "__AVR_ATA5272__", "25", 1},
  50. {"ata6616c", "__AVR_ATA6616c__", "25", 1},
  51. {"attiny13", "__AVR_ATtiny13__", "25", 1},
  52. {"attiny13a", "__AVR_ATtiny13A__", "25", 1},
  53. {"attiny2313", "__AVR_ATtiny2313__", "25", 1},
  54. {"attiny2313a", "__AVR_ATtiny2313A__", "25", 1},
  55. {"attiny24", "__AVR_ATtiny24__", "25", 1},
  56. {"attiny24a", "__AVR_ATtiny24A__", "25", 1},
  57. {"attiny4313", "__AVR_ATtiny4313__", "25", 1},
  58. {"attiny44", "__AVR_ATtiny44__", "25", 1},
  59. {"attiny44a", "__AVR_ATtiny44A__", "25", 1},
  60. {"attiny84", "__AVR_ATtiny84__", "25", 1},
  61. {"attiny84a", "__AVR_ATtiny84A__", "25", 1},
  62. {"attiny25", "__AVR_ATtiny25__", "25", 1},
  63. {"attiny45", "__AVR_ATtiny45__", "25", 1},
  64. {"attiny85", "__AVR_ATtiny85__", "25", 1},
  65. {"attiny261", "__AVR_ATtiny261__", "25", 1},
  66. {"attiny261a", "__AVR_ATtiny261A__", "25", 1},
  67. {"attiny441", "__AVR_ATtiny441__", "25", 1},
  68. {"attiny461", "__AVR_ATtiny461__", "25", 1},
  69. {"attiny461a", "__AVR_ATtiny461A__", "25", 1},
  70. {"attiny841", "__AVR_ATtiny841__", "25", 1},
  71. {"attiny861", "__AVR_ATtiny861__", "25", 1},
  72. {"attiny861a", "__AVR_ATtiny861A__", "25", 1},
  73. {"attiny87", "__AVR_ATtiny87__", "25", 1},
  74. {"attiny43u", "__AVR_ATtiny43U__", "25", 1},
  75. {"attiny48", "__AVR_ATtiny48__", "25", 1},
  76. {"attiny88", "__AVR_ATtiny88__", "25", 1},
  77. {"attiny828", "__AVR_ATtiny828__", "25", 1},
  78. {"avr3", NULL, "3", 1},
  79. {"at43usb355", "__AVR_AT43USB355__", "3", 1},
  80. {"at76c711", "__AVR_AT76C711__", "3", 1},
  81. {"avr31", NULL, "31", 1},
  82. {"atmega103", "__AVR_ATmega103__", "31", 1},
  83. {"at43usb320", "__AVR_AT43USB320__", "31", 1},
  84. {"avr35", NULL, "35", 1},
  85. {"attiny167", "__AVR_ATtiny167__", "35", 1},
  86. {"at90usb82", "__AVR_AT90USB82__", "35", 1},
  87. {"at90usb162", "__AVR_AT90USB162__", "35", 1},
  88. {"ata5505", "__AVR_ATA5505__", "35", 1},
  89. {"ata6617c", "__AVR_ATA6617C__", "35", 1},
  90. {"ata664251", "__AVR_ATA664251__", "35", 1},
  91. {"atmega8u2", "__AVR_ATmega8U2__", "35", 1},
  92. {"atmega16u2", "__AVR_ATmega16U2__", "35", 1},
  93. {"atmega32u2", "__AVR_ATmega32U2__", "35", 1},
  94. {"attiny1634", "__AVR_ATtiny1634__", "35", 1},
  95. {"avr4", NULL, "4", 1},
  96. {"atmega8", "__AVR_ATmega8__", "4", 1},
  97. {"ata6289", "__AVR_ATA6289__", "4", 1},
  98. {"atmega8a", "__AVR_ATmega8A__", "4", 1},
  99. {"ata6285", "__AVR_ATA6285__", "4", 1},
  100. {"ata6286", "__AVR_ATA6286__", "4", 1},
  101. {"ata6612c", "__AVR_ATA6612C__", "4", 1},
  102. {"atmega48", "__AVR_ATmega48__", "4", 1},
  103. {"atmega48a", "__AVR_ATmega48A__", "4", 1},
  104. {"atmega48pa", "__AVR_ATmega48PA__", "4", 1},
  105. {"atmega48pb", "__AVR_ATmega48PB__", "4", 1},
  106. {"atmega48p", "__AVR_ATmega48P__", "4", 1},
  107. {"atmega88", "__AVR_ATmega88__", "4", 1},
  108. {"atmega88a", "__AVR_ATmega88A__", "4", 1},
  109. {"atmega88p", "__AVR_ATmega88P__", "4", 1},
  110. {"atmega88pa", "__AVR_ATmega88PA__", "4", 1},
  111. {"atmega88pb", "__AVR_ATmega88PB__", "4", 1},
  112. {"atmega8515", "__AVR_ATmega8515__", "4", 1},
  113. {"atmega8535", "__AVR_ATmega8535__", "4", 1},
  114. {"atmega8hva", "__AVR_ATmega8HVA__", "4", 1},
  115. {"at90pwm1", "__AVR_AT90PWM1__", "4", 1},
  116. {"at90pwm2", "__AVR_AT90PWM2__", "4", 1},
  117. {"at90pwm2b", "__AVR_AT90PWM2B__", "4", 1},
  118. {"at90pwm3", "__AVR_AT90PWM3__", "4", 1},
  119. {"at90pwm3b", "__AVR_AT90PWM3B__", "4", 1},
  120. {"at90pwm81", "__AVR_AT90PWM81__", "4", 1},
  121. {"avr5", NULL, "5", 1},
  122. {"ata5702m322", "__AVR_ATA5702M322__", "5", 1},
  123. {"ata5782", "__AVR_ATA5782__", "5", 1},
  124. {"ata5790", "__AVR_ATA5790__", "5", 1},
  125. {"ata5790n", "__AVR_ATA5790N__", "5", 1},
  126. {"ata5791", "__AVR_ATA5791__", "5", 1},
  127. {"ata5795", "__AVR_ATA5795__", "5", 1},
  128. {"ata5831", "__AVR_ATA5831__", "5", 1},
  129. {"ata6613c", "__AVR_ATA6613C__", "5", 1},
  130. {"ata6614q", "__AVR_ATA6614Q__", "5", 1},
  131. {"ata8210", "__AVR_ATA8210__", "5", 1},
  132. {"ata8510", "__AVR_ATA8510__", "5", 1},
  133. {"atmega16", "__AVR_ATmega16__", "5", 1},
  134. {"atmega16a", "__AVR_ATmega16A__", "5", 1},
  135. {"atmega161", "__AVR_ATmega161__", "5", 1},
  136. {"atmega162", "__AVR_ATmega162__", "5", 1},
  137. {"atmega163", "__AVR_ATmega163__", "5", 1},
  138. {"atmega164a", "__AVR_ATmega164A__", "5", 1},
  139. {"atmega164p", "__AVR_ATmega164P__", "5", 1},
  140. {"atmega164pa", "__AVR_ATmega164PA__", "5", 1},
  141. {"atmega165", "__AVR_ATmega165__", "5", 1},
  142. {"atmega165a", "__AVR_ATmega165A__", "5", 1},
  143. {"atmega165p", "__AVR_ATmega165P__", "5", 1},
  144. {"atmega165pa", "__AVR_ATmega165PA__", "5", 1},
  145. {"atmega168", "__AVR_ATmega168__", "5", 1},
  146. {"atmega168a", "__AVR_ATmega168A__", "5", 1},
  147. {"atmega168p", "__AVR_ATmega168P__", "5", 1},
  148. {"atmega168pa", "__AVR_ATmega168PA__", "5", 1},
  149. {"atmega168pb", "__AVR_ATmega168PB__", "5", 1},
  150. {"atmega169", "__AVR_ATmega169__", "5", 1},
  151. {"atmega169a", "__AVR_ATmega169A__", "5", 1},
  152. {"atmega169p", "__AVR_ATmega169P__", "5", 1},
  153. {"atmega169pa", "__AVR_ATmega169PA__", "5", 1},
  154. {"atmega32", "__AVR_ATmega32__", "5", 1},
  155. {"atmega32a", "__AVR_ATmega32A__", "5", 1},
  156. {"atmega323", "__AVR_ATmega323__", "5", 1},
  157. {"atmega324a", "__AVR_ATmega324A__", "5", 1},
  158. {"atmega324p", "__AVR_ATmega324P__", "5", 1},
  159. {"atmega324pa", "__AVR_ATmega324PA__", "5", 1},
  160. {"atmega324pb", "__AVR_ATmega324PB__", "5", 1},
  161. {"atmega325", "__AVR_ATmega325__", "5", 1},
  162. {"atmega325a", "__AVR_ATmega325A__", "5", 1},
  163. {"atmega325p", "__AVR_ATmega325P__", "5", 1},
  164. {"atmega325pa", "__AVR_ATmega325PA__", "5", 1},
  165. {"atmega3250", "__AVR_ATmega3250__", "5", 1},
  166. {"atmega3250a", "__AVR_ATmega3250A__", "5", 1},
  167. {"atmega3250p", "__AVR_ATmega3250P__", "5", 1},
  168. {"atmega3250pa", "__AVR_ATmega3250PA__", "5", 1},
  169. {"atmega328", "__AVR_ATmega328__", "5", 1},
  170. {"atmega328p", "__AVR_ATmega328P__", "5", 1},
  171. {"atmega328pb", "__AVR_ATmega328PB__", "5", 1},
  172. {"atmega329", "__AVR_ATmega329__", "5", 1},
  173. {"atmega329a", "__AVR_ATmega329A__", "5", 1},
  174. {"atmega329p", "__AVR_ATmega329P__", "5", 1},
  175. {"atmega329pa", "__AVR_ATmega329PA__", "5", 1},
  176. {"atmega3290", "__AVR_ATmega3290__", "5", 1},
  177. {"atmega3290a", "__AVR_ATmega3290A__", "5", 1},
  178. {"atmega3290p", "__AVR_ATmega3290P__", "5", 1},
  179. {"atmega3290pa", "__AVR_ATmega3290PA__", "5", 1},
  180. {"atmega406", "__AVR_ATmega406__", "5", 1},
  181. {"atmega64", "__AVR_ATmega64__", "5", 1},
  182. {"atmega64a", "__AVR_ATmega64A__", "5", 1},
  183. {"atmega640", "__AVR_ATmega640__", "5", 1},
  184. {"atmega644", "__AVR_ATmega644__", "5", 1},
  185. {"atmega644a", "__AVR_ATmega644A__", "5", 1},
  186. {"atmega644p", "__AVR_ATmega644P__", "5", 1},
  187. {"atmega644pa", "__AVR_ATmega644PA__", "5", 1},
  188. {"atmega645", "__AVR_ATmega645__", "5", 1},
  189. {"atmega645a", "__AVR_ATmega645A__", "5", 1},
  190. {"atmega645p", "__AVR_ATmega645P__", "5", 1},
  191. {"atmega649", "__AVR_ATmega649__", "5", 1},
  192. {"atmega649a", "__AVR_ATmega649A__", "5", 1},
  193. {"atmega649p", "__AVR_ATmega649P__", "5", 1},
  194. {"atmega6450", "__AVR_ATmega6450__", "5", 1},
  195. {"atmega6450a", "__AVR_ATmega6450A__", "5", 1},
  196. {"atmega6450p", "__AVR_ATmega6450P__", "5", 1},
  197. {"atmega6490", "__AVR_ATmega6490__", "5", 1},
  198. {"atmega6490a", "__AVR_ATmega6490A__", "5", 1},
  199. {"atmega6490p", "__AVR_ATmega6490P__", "5", 1},
  200. {"atmega64rfr2", "__AVR_ATmega64RFR2__", "5", 1},
  201. {"atmega644rfr2", "__AVR_ATmega644RFR2__", "5", 1},
  202. {"atmega16hva", "__AVR_ATmega16HVA__", "5", 1},
  203. {"atmega16hva2", "__AVR_ATmega16HVA2__", "5", 1},
  204. {"atmega16hvb", "__AVR_ATmega16HVB__", "5", 1},
  205. {"atmega16hvbrevb", "__AVR_ATmega16HVBREVB__", "5", 1},
  206. {"atmega32hvb", "__AVR_ATmega32HVB__", "5", 1},
  207. {"atmega32hvbrevb", "__AVR_ATmega32HVBREVB__", "5", 1},
  208. {"atmega64hve", "__AVR_ATmega64HVE__", "5", 1},
  209. {"atmega64hve2", "__AVR_ATmega64HVE2__", "5", 1},
  210. {"at90can32", "__AVR_AT90CAN32__", "5", 1},
  211. {"at90can64", "__AVR_AT90CAN64__", "5", 1},
  212. {"at90pwm161", "__AVR_AT90PWM161__", "5", 1},
  213. {"at90pwm216", "__AVR_AT90PWM216__", "5", 1},
  214. {"at90pwm316", "__AVR_AT90PWM316__", "5", 1},
  215. {"atmega32c1", "__AVR_ATmega32C1__", "5", 1},
  216. {"atmega64c1", "__AVR_ATmega64C1__", "5", 1},
  217. {"atmega16m1", "__AVR_ATmega16M1__", "5", 1},
  218. {"atmega32m1", "__AVR_ATmega32M1__", "5", 1},
  219. {"atmega64m1", "__AVR_ATmega64M1__", "5", 1},
  220. {"atmega16u4", "__AVR_ATmega16U4__", "5", 1},
  221. {"atmega32u4", "__AVR_ATmega32U4__", "5", 1},
  222. {"atmega32u6", "__AVR_ATmega32U6__", "5", 1},
  223. {"at90usb646", "__AVR_AT90USB646__", "5", 1},
  224. {"at90usb647", "__AVR_AT90USB647__", "5", 1},
  225. {"at90scr100", "__AVR_AT90SCR100__", "5", 1},
  226. {"at94k", "__AVR_AT94K__", "5", 1},
  227. {"m3000", "__AVR_AT000__", "5", 1},
  228. {"avr51", NULL, "51", 2},
  229. {"atmega128", "__AVR_ATmega128__", "51", 2},
  230. {"atmega128a", "__AVR_ATmega128A__", "51", 2},
  231. {"atmega1280", "__AVR_ATmega1280__", "51", 2},
  232. {"atmega1281", "__AVR_ATmega1281__", "51", 2},
  233. {"atmega1284", "__AVR_ATmega1284__", "51", 2},
  234. {"atmega1284p", "__AVR_ATmega1284P__", "51", 2},
  235. {"atmega128rfa1", "__AVR_ATmega128RFA1__", "51", 2},
  236. {"atmega128rfr2", "__AVR_ATmega128RFR2__", "51", 2},
  237. {"atmega1284rfr2", "__AVR_ATmega1284RFR2__", "51", 2},
  238. {"at90can128", "__AVR_AT90CAN128__", "51", 2},
  239. {"at90usb1286", "__AVR_AT90USB1286__", "51", 2},
  240. {"at90usb1287", "__AVR_AT90USB1287__", "51", 2},
  241. {"avr6", NULL, "6", 4},
  242. {"atmega2560", "__AVR_ATmega2560__", "6", 4},
  243. {"atmega2561", "__AVR_ATmega2561__", "6", 4},
  244. {"atmega256rfr2", "__AVR_ATmega256RFR2__", "6", 4},
  245. {"atmega2564rfr2", "__AVR_ATmega2564RFR2__", "6", 4},
  246. {"avrxmega2", NULL, "102", 1},
  247. {"atxmega16a4", "__AVR_ATxmega16A4__", "102", 1},
  248. {"atxmega16a4u", "__AVR_ATxmega16A4U__", "102", 1},
  249. {"atxmega16c4", "__AVR_ATxmega16C4__", "102", 1},
  250. {"atxmega16d4", "__AVR_ATxmega16D4__", "102", 1},
  251. {"atxmega32a4", "__AVR_ATxmega32A4__", "102", 1},
  252. {"atxmega32a4u", "__AVR_ATxmega32A4U__", "102", 1},
  253. {"atxmega32c3", "__AVR_ATxmega32C3__", "102", 1},
  254. {"atxmega32c4", "__AVR_ATxmega32C4__", "102", 1},
  255. {"atxmega32d3", "__AVR_ATxmega32D3__", "102", 1},
  256. {"atxmega32d4", "__AVR_ATxmega32D4__", "102", 1},
  257. {"atxmega32e5", "__AVR_ATxmega32E5__", "102", 1},
  258. {"atxmega16e5", "__AVR_ATxmega16E5__", "102", 1},
  259. {"atxmega8e5", "__AVR_ATxmega8E5__", "102", 1},
  260. {"avrxmega4", NULL, "104", 1},
  261. {"atxmega64a3", "__AVR_ATxmega64A3__", "104", 1},
  262. {"atxmega64a3u", "__AVR_ATxmega64A3U__", "104", 1},
  263. {"atxmega64a4u", "__AVR_ATxmega64A4U__", "104", 1},
  264. {"atxmega64b1", "__AVR_ATxmega64B1__", "104", 1},
  265. {"atxmega64b3", "__AVR_ATxmega64B3__", "104", 1},
  266. {"atxmega64c3", "__AVR_ATxmega64C3__", "104", 1},
  267. {"atxmega64d3", "__AVR_ATxmega64D3__", "104", 1},
  268. {"atxmega64d4", "__AVR_ATxmega64D4__", "104", 1},
  269. {"avrxmega5", NULL, "105", 1},
  270. {"atxmega64a1", "__AVR_ATxmega64A1__", "105", 1},
  271. {"atxmega64a1u", "__AVR_ATxmega64A1U__", "105", 1},
  272. {"avrxmega6", NULL, "106", 6},
  273. {"atxmega128a3", "__AVR_ATxmega128A3__", "106", 2},
  274. {"atxmega128a3u", "__AVR_ATxmega128A3U__", "106", 2},
  275. {"atxmega128b1", "__AVR_ATxmega128B1__", "106", 2},
  276. {"atxmega128b3", "__AVR_ATxmega128B3__", "106", 2},
  277. {"atxmega128c3", "__AVR_ATxmega128C3__", "106", 2},
  278. {"atxmega128d3", "__AVR_ATxmega128D3__", "106", 2},
  279. {"atxmega128d4", "__AVR_ATxmega128D4__", "106", 2},
  280. {"atxmega192a3", "__AVR_ATxmega192A3__", "106", 3},
  281. {"atxmega192a3u", "__AVR_ATxmega192A3U__", "106", 3},
  282. {"atxmega192c3", "__AVR_ATxmega192C3__", "106", 3},
  283. {"atxmega192d3", "__AVR_ATxmega192D3__", "106", 3},
  284. {"atxmega256a3", "__AVR_ATxmega256A3__", "106", 4},
  285. {"atxmega256a3u", "__AVR_ATxmega256A3U__", "106", 4},
  286. {"atxmega256a3b", "__AVR_ATxmega256A3B__", "106", 4},
  287. {"atxmega256a3bu", "__AVR_ATxmega256A3BU__", "106", 4},
  288. {"atxmega256c3", "__AVR_ATxmega256C3__", "106", 4},
  289. {"atxmega256d3", "__AVR_ATxmega256D3__", "106", 4},
  290. {"atxmega384c3", "__AVR_ATxmega384C3__", "106", 6},
  291. {"atxmega384d3", "__AVR_ATxmega384D3__", "106", 6},
  292. {"avrxmega7", NULL, "107", 2},
  293. {"atxmega128a1", "__AVR_ATxmega128A1__", "107", 2},
  294. {"atxmega128a1u", "__AVR_ATxmega128A1U__", "107", 2},
  295. {"atxmega128a4u", "__AVR_ATxmega128A4U__", "107", 2},
  296. {"avrtiny", NULL, "100", 0},
  297. {"attiny4", "__AVR_ATtiny4__", "100", 0},
  298. {"attiny5", "__AVR_ATtiny5__", "100", 0},
  299. {"attiny9", "__AVR_ATtiny9__", "100", 0},
  300. {"attiny10", "__AVR_ATtiny10__", "100", 0},
  301. {"attiny20", "__AVR_ATtiny20__", "100", 0},
  302. {"attiny40", "__AVR_ATtiny40__", "100", 0},
  303. {"attiny102", "__AVR_ATtiny102__", "100", 0},
  304. {"attiny104", "__AVR_ATtiny104__", "100", 0},
  305. {"avrxmega3", NULL, "103", 1},
  306. {"attiny202", "__AVR_ATtiny202__", "103", 1},
  307. {"attiny402", "__AVR_ATtiny402__", "103", 1},
  308. {"attiny204", "__AVR_ATtiny204__", "103", 1},
  309. {"attiny404", "__AVR_ATtiny404__", "103", 1},
  310. {"attiny804", "__AVR_ATtiny804__", "103", 1},
  311. {"attiny1604", "__AVR_ATtiny1604__", "103", 1},
  312. {"attiny406", "__AVR_ATtiny406__", "103", 1},
  313. {"attiny806", "__AVR_ATtiny806__", "103", 1},
  314. {"attiny1606", "__AVR_ATtiny1606__", "103", 1},
  315. {"attiny807", "__AVR_ATtiny807__", "103", 1},
  316. {"attiny1607", "__AVR_ATtiny1607__", "103", 1},
  317. {"attiny212", "__AVR_ATtiny212__", "103", 1},
  318. {"attiny412", "__AVR_ATtiny412__", "103", 1},
  319. {"attiny214", "__AVR_ATtiny214__", "103", 1},
  320. {"attiny414", "__AVR_ATtiny414__", "103", 1},
  321. {"attiny814", "__AVR_ATtiny814__", "103", 1},
  322. {"attiny1614", "__AVR_ATtiny1614__", "103", 1},
  323. {"attiny416", "__AVR_ATtiny416__", "103", 1},
  324. {"attiny816", "__AVR_ATtiny816__", "103", 1},
  325. {"attiny1616", "__AVR_ATtiny1616__", "103", 1},
  326. {"attiny3216", "__AVR_ATtiny3216__", "103", 1},
  327. {"attiny417", "__AVR_ATtiny417__", "103", 1},
  328. {"attiny817", "__AVR_ATtiny817__", "103", 1},
  329. {"attiny1617", "__AVR_ATtiny1617__", "103", 1},
  330. {"attiny3217", "__AVR_ATtiny3217__", "103", 1},
  331. {"attiny1624", "__AVR_ATtiny1624__", "103", 1},
  332. {"attiny1626", "__AVR_ATtiny1626__", "103", 1},
  333. {"attiny1627", "__AVR_ATtiny1627__", "103", 1},
  334. {"atmega808", "__AVR_ATmega808__", "103", 1},
  335. {"atmega809", "__AVR_ATmega809__", "103", 1},
  336. {"atmega1608", "__AVR_ATmega1608__", "103", 1},
  337. {"atmega1609", "__AVR_ATmega1609__", "103", 1},
  338. {"atmega3208", "__AVR_ATmega3208__", "103", 1},
  339. {"atmega3209", "__AVR_ATmega3209__", "103", 1},
  340. {"atmega4808", "__AVR_ATmega4808__", "103", 1},
  341. {"atmega4809", "__AVR_ATmega4809__", "103", 1},
  342. };
  343. } // namespace targets
  344. } // namespace clang
  345. static bool ArchHasELPM(StringRef Arch) {
  346. return llvm::StringSwitch<bool>(Arch)
  347. .Cases("31", "51", "6", true)
  348. .Cases("102", "104", "105", "106", "107", true)
  349. .Default(false);
  350. }
  351. static bool ArchHasELPMX(StringRef Arch) {
  352. return llvm::StringSwitch<bool>(Arch)
  353. .Cases("51", "6", true)
  354. .Cases("102", "104", "105", "106", "107", true)
  355. .Default(false);
  356. }
  357. static bool ArchHasMOVW(StringRef Arch) {
  358. return llvm::StringSwitch<bool>(Arch)
  359. .Cases("25", "35", "4", "5", "51", "6", true)
  360. .Cases("102", "103", "104", "105", "106", "107", true)
  361. .Default(false);
  362. }
  363. static bool ArchHasLPMX(StringRef Arch) {
  364. return ArchHasMOVW(Arch); // same architectures
  365. }
  366. static bool ArchHasMUL(StringRef Arch) {
  367. return llvm::StringSwitch<bool>(Arch)
  368. .Cases("4", "5", "51", "6", true)
  369. .Cases("102", "103", "104", "105", "106", "107", true)
  370. .Default(false);
  371. }
  372. static bool ArchHasJMPCALL(StringRef Arch) {
  373. return llvm::StringSwitch<bool>(Arch)
  374. .Cases("3", "31", "35", "5", "51", "6", true)
  375. .Cases("102", "103", "104", "105", "106", "107", true)
  376. .Default(false);
  377. }
  378. static bool ArchHas3BytePC(StringRef Arch) {
  379. // These devices have more than 128kB of program memory.
  380. // Note:
  381. // - Not fully correct for arch 106: only about half the chips have more
  382. // than 128kB program memory and therefore a 3 byte PC.
  383. // - Doesn't match GCC entirely: avr-gcc thinks arch 107 goes beyond 128kB
  384. // but in fact it doesn't.
  385. return llvm::StringSwitch<bool>(Arch)
  386. .Case("6", true)
  387. .Case("106", true)
  388. .Default(false);
  389. }
  390. bool AVRTargetInfo::isValidCPUName(StringRef Name) const {
  391. return llvm::any_of(
  392. AVRMcus, [&](const MCUInfo &Info) { return Info.Name == Name; });
  393. }
  394. void AVRTargetInfo::fillValidCPUList(SmallVectorImpl<StringRef> &Values) const {
  395. for (const MCUInfo &Info : AVRMcus)
  396. Values.push_back(Info.Name);
  397. }
  398. bool AVRTargetInfo::setCPU(const std::string &Name) {
  399. // Set the ABI field based on the device or family name.
  400. auto It = llvm::find_if(
  401. AVRMcus, [&](const MCUInfo &Info) { return Info.Name == Name; });
  402. if (It != std::end(AVRMcus)) {
  403. CPU = Name;
  404. ABI = (It->Arch == "100") ? "avrtiny" : "avr";
  405. DefineName = It->DefineName;
  406. Arch = It->Arch;
  407. NumFlashBanks = It->NumFlashBanks;
  408. return true;
  409. }
  410. // Parameter Name is neither valid family name nor valid device name.
  411. return false;
  412. }
  413. void AVRTargetInfo::getTargetDefines(const LangOptions &Opts,
  414. MacroBuilder &Builder) const {
  415. Builder.defineMacro("AVR");
  416. Builder.defineMacro("__AVR");
  417. Builder.defineMacro("__AVR__");
  418. Builder.defineMacro("__ELF__");
  419. if (ABI == "avrtiny")
  420. Builder.defineMacro("__AVR_TINY__", "1");
  421. if (DefineName.size() != 0)
  422. Builder.defineMacro(DefineName);
  423. Builder.defineMacro("__AVR_ARCH__", Arch);
  424. // TODO: perhaps we should use the information from AVRDevices.td instead?
  425. if (ArchHasELPM(Arch))
  426. Builder.defineMacro("__AVR_HAVE_ELPM__");
  427. if (ArchHasELPMX(Arch))
  428. Builder.defineMacro("__AVR_HAVE_ELPMX__");
  429. if (ArchHasMOVW(Arch))
  430. Builder.defineMacro("__AVR_HAVE_MOVW__");
  431. if (ArchHasLPMX(Arch))
  432. Builder.defineMacro("__AVR_HAVE_LPMX__");
  433. if (ArchHasMUL(Arch))
  434. Builder.defineMacro("__AVR_HAVE_MUL__");
  435. if (ArchHasJMPCALL(Arch))
  436. Builder.defineMacro("__AVR_HAVE_JMP_CALL__");
  437. if (ArchHas3BytePC(Arch)) {
  438. // Note: some devices do support eijmp/eicall even though this macro isn't
  439. // set. This is the case if they have less than 128kB flash and so
  440. // eijmp/eicall isn't very useful anyway. (This matches gcc, although it's
  441. // debatable whether we should be bug-compatible in this case).
  442. Builder.defineMacro("__AVR_HAVE_EIJMP_EICALL__");
  443. Builder.defineMacro("__AVR_3_BYTE_PC__");
  444. } else {
  445. Builder.defineMacro("__AVR_2_BYTE_PC__");
  446. }
  447. if (NumFlashBanks >= 1)
  448. Builder.defineMacro("__flash", "__attribute__((__address_space__(1)))");
  449. if (NumFlashBanks >= 2)
  450. Builder.defineMacro("__flash1", "__attribute__((__address_space__(2)))");
  451. if (NumFlashBanks >= 3)
  452. Builder.defineMacro("__flash2", "__attribute__((__address_space__(3)))");
  453. if (NumFlashBanks >= 4)
  454. Builder.defineMacro("__flash3", "__attribute__((__address_space__(4)))");
  455. if (NumFlashBanks >= 5)
  456. Builder.defineMacro("__flash4", "__attribute__((__address_space__(5)))");
  457. if (NumFlashBanks >= 6)
  458. Builder.defineMacro("__flash5", "__attribute__((__address_space__(6)))");
  459. }