ARMAttributeParser.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. //===- ARMAttributeParser.cpp - ARM Attribute Information Printer ---------===//
  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. #include "llvm/Support/ARMAttributeParser.h"
  9. #include "llvm/ADT/STLArrayExtras.h"
  10. #include "llvm/ADT/StringExtras.h"
  11. #include "llvm/Support/ScopedPrinter.h"
  12. using namespace llvm;
  13. using namespace llvm::ARMBuildAttrs;
  14. #define ATTRIBUTE_HANDLER(attr) \
  15. { ARMBuildAttrs::attr, &ARMAttributeParser::attr }
  16. const ARMAttributeParser::DisplayHandler ARMAttributeParser::displayRoutines[] =
  17. {
  18. {ARMBuildAttrs::CPU_raw_name, &ARMAttributeParser::stringAttribute},
  19. {ARMBuildAttrs::CPU_name, &ARMAttributeParser::stringAttribute},
  20. ATTRIBUTE_HANDLER(CPU_arch),
  21. ATTRIBUTE_HANDLER(CPU_arch_profile),
  22. ATTRIBUTE_HANDLER(ARM_ISA_use),
  23. ATTRIBUTE_HANDLER(THUMB_ISA_use),
  24. ATTRIBUTE_HANDLER(FP_arch),
  25. ATTRIBUTE_HANDLER(WMMX_arch),
  26. ATTRIBUTE_HANDLER(Advanced_SIMD_arch),
  27. ATTRIBUTE_HANDLER(MVE_arch),
  28. ATTRIBUTE_HANDLER(PCS_config),
  29. ATTRIBUTE_HANDLER(ABI_PCS_R9_use),
  30. ATTRIBUTE_HANDLER(ABI_PCS_RW_data),
  31. ATTRIBUTE_HANDLER(ABI_PCS_RO_data),
  32. ATTRIBUTE_HANDLER(ABI_PCS_GOT_use),
  33. ATTRIBUTE_HANDLER(ABI_PCS_wchar_t),
  34. ATTRIBUTE_HANDLER(ABI_FP_rounding),
  35. ATTRIBUTE_HANDLER(ABI_FP_denormal),
  36. ATTRIBUTE_HANDLER(ABI_FP_exceptions),
  37. ATTRIBUTE_HANDLER(ABI_FP_user_exceptions),
  38. ATTRIBUTE_HANDLER(ABI_FP_number_model),
  39. ATTRIBUTE_HANDLER(ABI_align_needed),
  40. ATTRIBUTE_HANDLER(ABI_align_preserved),
  41. ATTRIBUTE_HANDLER(ABI_enum_size),
  42. ATTRIBUTE_HANDLER(ABI_HardFP_use),
  43. ATTRIBUTE_HANDLER(ABI_VFP_args),
  44. ATTRIBUTE_HANDLER(ABI_WMMX_args),
  45. ATTRIBUTE_HANDLER(ABI_optimization_goals),
  46. ATTRIBUTE_HANDLER(ABI_FP_optimization_goals),
  47. ATTRIBUTE_HANDLER(compatibility),
  48. ATTRIBUTE_HANDLER(CPU_unaligned_access),
  49. ATTRIBUTE_HANDLER(FP_HP_extension),
  50. ATTRIBUTE_HANDLER(ABI_FP_16bit_format),
  51. ATTRIBUTE_HANDLER(MPextension_use),
  52. ATTRIBUTE_HANDLER(DIV_use),
  53. ATTRIBUTE_HANDLER(DSP_extension),
  54. ATTRIBUTE_HANDLER(T2EE_use),
  55. ATTRIBUTE_HANDLER(Virtualization_use),
  56. ATTRIBUTE_HANDLER(PAC_extension),
  57. ATTRIBUTE_HANDLER(BTI_extension),
  58. ATTRIBUTE_HANDLER(PACRET_use),
  59. ATTRIBUTE_HANDLER(BTI_use),
  60. ATTRIBUTE_HANDLER(nodefaults),
  61. };
  62. #undef ATTRIBUTE_HANDLER
  63. Error ARMAttributeParser::stringAttribute(AttrType tag) {
  64. StringRef tagName =
  65. ELFAttrs::attrTypeAsString(tag, tagToStringMap, /*hasTagPrefix=*/false);
  66. StringRef desc = de.getCStrRef(cursor);
  67. if (sw) {
  68. DictScope scope(*sw, "Attribute");
  69. sw->printNumber("Tag", tag);
  70. if (!tagName.empty())
  71. sw->printString("TagName", tagName);
  72. sw->printString("Value", desc);
  73. }
  74. return Error::success();
  75. }
  76. Error ARMAttributeParser::CPU_arch(AttrType tag) {
  77. static const char *strings[] = {
  78. "Pre-v4", "ARM v4", "ARM v4T", "ARM v5T", "ARM v5TE", "ARM v5TEJ", "ARM v6",
  79. "ARM v6KZ", "ARM v6T2", "ARM v6K", "ARM v7", "ARM v6-M", "ARM v6S-M",
  80. "ARM v7E-M", "ARM v8", nullptr,
  81. "ARM v8-M Baseline", "ARM v8-M Mainline", nullptr, nullptr, nullptr,
  82. "ARM v8.1-M Mainline"
  83. };
  84. return parseStringAttribute("CPU_arch", tag, makeArrayRef(strings));
  85. }
  86. Error ARMAttributeParser::CPU_arch_profile(AttrType tag) {
  87. uint64_t value = de.getULEB128(cursor);
  88. StringRef profile;
  89. switch (value) {
  90. default: profile = "Unknown"; break;
  91. case 'A': profile = "Application"; break;
  92. case 'R': profile = "Real-time"; break;
  93. case 'M': profile = "Microcontroller"; break;
  94. case 'S': profile = "Classic"; break;
  95. case 0: profile = "None"; break;
  96. }
  97. printAttribute(tag, value, profile);
  98. return Error::success();
  99. }
  100. Error ARMAttributeParser::ARM_ISA_use(AttrType tag) {
  101. static const char *strings[] = {"Not Permitted", "Permitted"};
  102. return parseStringAttribute("ARM_ISA_use", tag, makeArrayRef(strings));
  103. }
  104. Error ARMAttributeParser::THUMB_ISA_use(AttrType tag) {
  105. static const char *strings[] = {"Not Permitted", "Thumb-1", "Thumb-2", "Permitted"};
  106. return parseStringAttribute("THUMB_ISA_use", tag, makeArrayRef(strings));
  107. }
  108. Error ARMAttributeParser::FP_arch(AttrType tag) {
  109. static const char *strings[] = {
  110. "Not Permitted", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16",
  111. "VFPv4", "VFPv4-D16", "ARMv8-a FP", "ARMv8-a FP-D16"};
  112. return parseStringAttribute("FP_arch", tag, makeArrayRef(strings));
  113. }
  114. Error ARMAttributeParser::WMMX_arch(AttrType tag) {
  115. static const char *strings[] = {"Not Permitted", "WMMXv1", "WMMXv2"};
  116. return parseStringAttribute("WMMX_arch", tag, makeArrayRef(strings));
  117. }
  118. Error ARMAttributeParser::Advanced_SIMD_arch(AttrType tag) {
  119. static const char *strings[] = {"Not Permitted", "NEONv1", "NEONv2+FMA",
  120. "ARMv8-a NEON", "ARMv8.1-a NEON"};
  121. return parseStringAttribute("Advanced_SIMD_arch", tag, makeArrayRef(strings));
  122. }
  123. Error ARMAttributeParser::MVE_arch(AttrType tag) {
  124. static const char *strings[] = {"Not Permitted", "MVE integer",
  125. "MVE integer and float"};
  126. return parseStringAttribute("MVE_arch", tag, makeArrayRef(strings));
  127. }
  128. Error ARMAttributeParser::PCS_config(AttrType tag) {
  129. static const char *strings[] = {
  130. "None", "Bare Platform", "Linux Application", "Linux DSO", "Palm OS 2004",
  131. "Reserved (Palm OS)", "Symbian OS 2004", "Reserved (Symbian OS)"};
  132. return parseStringAttribute("PCS_config", tag, makeArrayRef(strings));
  133. }
  134. Error ARMAttributeParser::ABI_PCS_R9_use(AttrType tag) {
  135. static const char *strings[] = {"v6", "Static Base", "TLS", "Unused"};
  136. return parseStringAttribute("ABI_PCS_R9_use", tag, makeArrayRef(strings));
  137. }
  138. Error ARMAttributeParser::ABI_PCS_RW_data(AttrType tag) {
  139. static const char *strings[] = {"Absolute", "PC-relative", "SB-relative",
  140. "Not Permitted"};
  141. return parseStringAttribute("ABI_PCS_RW_data", tag, makeArrayRef(strings));
  142. }
  143. Error ARMAttributeParser::ABI_PCS_RO_data(AttrType tag) {
  144. static const char *strings[] = {"Absolute", "PC-relative", "Not Permitted"};
  145. return parseStringAttribute("ABI_PCS_RO_data", tag, makeArrayRef(strings));
  146. }
  147. Error ARMAttributeParser::ABI_PCS_GOT_use(AttrType tag) {
  148. static const char *strings[] = {"Not Permitted", "Direct", "GOT-Indirect"};
  149. return parseStringAttribute("ABI_PCS_GOT_use", tag, makeArrayRef(strings));
  150. }
  151. Error ARMAttributeParser::ABI_PCS_wchar_t(AttrType tag) {
  152. static const char *strings[] = {"Not Permitted", "Unknown", "2-byte",
  153. "Unknown", "4-byte"};
  154. return parseStringAttribute("ABI_PCS_wchar_t", tag, makeArrayRef(strings));
  155. }
  156. Error ARMAttributeParser::ABI_FP_rounding(AttrType tag) {
  157. static const char *strings[] = {"IEEE-754", "Runtime"};
  158. return parseStringAttribute("ABI_FP_rounding", tag, makeArrayRef(strings));
  159. }
  160. Error ARMAttributeParser::ABI_FP_denormal(AttrType tag) {
  161. static const char *strings[] = {"Unsupported", "IEEE-754", "Sign Only"};
  162. return parseStringAttribute("ABI_FP_denormal", tag, makeArrayRef(strings));
  163. }
  164. Error ARMAttributeParser::ABI_FP_exceptions(AttrType tag) {
  165. static const char *strings[] = {"Not Permitted", "IEEE-754"};
  166. return parseStringAttribute("ABI_FP_exceptions", tag, makeArrayRef(strings));
  167. }
  168. Error ARMAttributeParser::ABI_FP_user_exceptions(AttrType tag) {
  169. static const char *strings[] = {"Not Permitted", "IEEE-754"};
  170. return parseStringAttribute("ABI_FP_user_exceptions", tag,
  171. makeArrayRef(strings));
  172. }
  173. Error ARMAttributeParser::ABI_FP_number_model(AttrType tag) {
  174. static const char *strings[] = {"Not Permitted", "Finite Only", "RTABI",
  175. "IEEE-754"};
  176. return parseStringAttribute("ABI_FP_number_model", tag,
  177. makeArrayRef(strings));
  178. }
  179. Error ARMAttributeParser::ABI_align_needed(AttrType tag) {
  180. static const char *strings[] = {"Not Permitted", "8-byte alignment",
  181. "4-byte alignment", "Reserved"};
  182. uint64_t value = de.getULEB128(cursor);
  183. std::string description;
  184. if (value < array_lengthof(strings))
  185. description = strings[value];
  186. else if (value <= 12)
  187. description = "8-byte alignment, " + utostr(1ULL << value) +
  188. "-byte extended alignment";
  189. else
  190. description = "Invalid";
  191. printAttribute(tag, value, description);
  192. return Error::success();
  193. }
  194. Error ARMAttributeParser::ABI_align_preserved(AttrType tag) {
  195. static const char *strings[] = {"Not Required", "8-byte data alignment",
  196. "8-byte data and code alignment", "Reserved"};
  197. uint64_t value = de.getULEB128(cursor);
  198. std::string description;
  199. if (value < array_lengthof(strings))
  200. description = std::string(strings[value]);
  201. else if (value <= 12)
  202. description = std::string("8-byte stack alignment, ") +
  203. utostr(1ULL << value) + std::string("-byte data alignment");
  204. else
  205. description = "Invalid";
  206. printAttribute(tag, value, description);
  207. return Error::success();
  208. }
  209. Error ARMAttributeParser::ABI_enum_size(AttrType tag) {
  210. static const char *strings[] = {"Not Permitted", "Packed", "Int32",
  211. "External Int32"};
  212. return parseStringAttribute("ABI_enum_size", tag, makeArrayRef(strings));
  213. }
  214. Error ARMAttributeParser::ABI_HardFP_use(AttrType tag) {
  215. static const char *strings[] = {"Tag_FP_arch", "Single-Precision", "Reserved",
  216. "Tag_FP_arch (deprecated)"};
  217. return parseStringAttribute("ABI_HardFP_use", tag, makeArrayRef(strings));
  218. }
  219. Error ARMAttributeParser::ABI_VFP_args(AttrType tag) {
  220. static const char *strings[] = {"AAPCS", "AAPCS VFP", "Custom",
  221. "Not Permitted"};
  222. return parseStringAttribute("ABI_VFP_args", tag, makeArrayRef(strings));
  223. }
  224. Error ARMAttributeParser::ABI_WMMX_args(AttrType tag) {
  225. static const char *strings[] = {"AAPCS", "iWMMX", "Custom"};
  226. return parseStringAttribute("ABI_WMMX_args", tag, makeArrayRef(strings));
  227. }
  228. Error ARMAttributeParser::ABI_optimization_goals(AttrType tag) {
  229. static const char *strings[] = {
  230. "None", "Speed", "Aggressive Speed", "Size", "Aggressive Size", "Debugging",
  231. "Best Debugging"
  232. };
  233. return parseStringAttribute("ABI_optimization_goals", tag,
  234. makeArrayRef(strings));
  235. }
  236. Error ARMAttributeParser::ABI_FP_optimization_goals(AttrType tag) {
  237. static const char *strings[] = {
  238. "None", "Speed", "Aggressive Speed", "Size", "Aggressive Size",
  239. "Accuracy", "Best Accuracy"};
  240. return parseStringAttribute("ABI_FP_optimization_goals", tag,
  241. makeArrayRef(strings));
  242. }
  243. Error ARMAttributeParser::compatibility(AttrType tag) {
  244. uint64_t integer = de.getULEB128(cursor);
  245. StringRef string = de.getCStrRef(cursor);
  246. if (sw) {
  247. DictScope scope(*sw, "Attribute");
  248. sw->printNumber("Tag", tag);
  249. sw->startLine() << "Value: " << integer << ", " << string << '\n';
  250. sw->printString("TagName",
  251. ELFAttrs::attrTypeAsString(tag, tagToStringMap,
  252. /*hasTagPrefix=*/false));
  253. switch (integer) {
  254. case 0:
  255. sw->printString("Description", StringRef("No Specific Requirements"));
  256. break;
  257. case 1:
  258. sw->printString("Description", StringRef("AEABI Conformant"));
  259. break;
  260. default:
  261. sw->printString("Description", StringRef("AEABI Non-Conformant"));
  262. break;
  263. }
  264. }
  265. return Error::success();
  266. }
  267. Error ARMAttributeParser::CPU_unaligned_access(AttrType tag) {
  268. static const char *strings[] = {"Not Permitted", "v6-style"};
  269. return parseStringAttribute("CPU_unaligned_access", tag,
  270. makeArrayRef(strings));
  271. }
  272. Error ARMAttributeParser::FP_HP_extension(AttrType tag) {
  273. static const char *strings[] = {"If Available", "Permitted"};
  274. return parseStringAttribute("FP_HP_extension", tag, makeArrayRef(strings));
  275. }
  276. Error ARMAttributeParser::ABI_FP_16bit_format(AttrType tag) {
  277. static const char *strings[] = {"Not Permitted", "IEEE-754", "VFPv3"};
  278. return parseStringAttribute("ABI_FP_16bit_format", tag,
  279. makeArrayRef(strings));
  280. }
  281. Error ARMAttributeParser::MPextension_use(AttrType tag) {
  282. static const char *strings[] = {"Not Permitted", "Permitted"};
  283. return parseStringAttribute("MPextension_use", tag, makeArrayRef(strings));
  284. }
  285. Error ARMAttributeParser::DIV_use(AttrType tag) {
  286. static const char *strings[] = {"If Available", "Not Permitted", "Permitted"};
  287. return parseStringAttribute("DIV_use", tag, makeArrayRef(strings));
  288. }
  289. Error ARMAttributeParser::DSP_extension(AttrType tag) {
  290. static const char *strings[] = {"Not Permitted", "Permitted"};
  291. return parseStringAttribute("DSP_extension", tag, makeArrayRef(strings));
  292. }
  293. Error ARMAttributeParser::T2EE_use(AttrType tag) {
  294. static const char *strings[] = {"Not Permitted", "Permitted"};
  295. return parseStringAttribute("T2EE_use", tag, makeArrayRef(strings));
  296. }
  297. Error ARMAttributeParser::Virtualization_use(AttrType tag) {
  298. static const char *strings[] = {"Not Permitted", "TrustZone",
  299. "Virtualization Extensions",
  300. "TrustZone + Virtualization Extensions"};
  301. return parseStringAttribute("Virtualization_use", tag, makeArrayRef(strings));
  302. }
  303. Error ARMAttributeParser::PAC_extension(ARMBuildAttrs::AttrType tag) {
  304. static const char *strings[] = {"Not Permitted", "Permitted in NOP space",
  305. "Permitted"};
  306. return parseStringAttribute("PAC_extension", tag, makeArrayRef(strings));
  307. }
  308. Error ARMAttributeParser::BTI_extension(ARMBuildAttrs::AttrType tag) {
  309. static const char *strings[] = {"Not Permitted", "Permitted in NOP space",
  310. "Permitted"};
  311. return parseStringAttribute("BTI_extension", tag, makeArrayRef(strings));
  312. }
  313. Error ARMAttributeParser::PACRET_use(ARMBuildAttrs::AttrType tag) {
  314. static const char *strings[] = {"Not Used", "Used"};
  315. return parseStringAttribute("PACRET_use", tag, makeArrayRef(strings));
  316. }
  317. Error ARMAttributeParser::BTI_use(ARMBuildAttrs::AttrType tag) {
  318. static const char *strings[] = {"Not Used", "Used"};
  319. return parseStringAttribute("BTI_use", tag, makeArrayRef(strings));
  320. }
  321. Error ARMAttributeParser::nodefaults(AttrType tag) {
  322. uint64_t value = de.getULEB128(cursor);
  323. printAttribute(tag, value, "Unspecified Tags UNDEFINED");
  324. return Error::success();
  325. }
  326. Error ARMAttributeParser::handler(uint64_t tag, bool &handled) {
  327. handled = false;
  328. for (unsigned AHI = 0, AHE = array_lengthof(displayRoutines); AHI != AHE;
  329. ++AHI) {
  330. if (uint64_t(displayRoutines[AHI].attribute) == tag) {
  331. if (Error e =
  332. (this->*displayRoutines[AHI].routine)(static_cast<AttrType>(tag)))
  333. return e;
  334. handled = true;
  335. break;
  336. }
  337. }
  338. return Error::success();
  339. }