LLVM  8.0.1
ARMAttributeParser.cpp
Go to the documentation of this file.
1 //===--- ARMAttributeParser.cpp - ARM Attribute Information Printer -------===//
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 
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/ADT/StringExtras.h"
13 #include "llvm/Support/LEB128.h"
15 
16 using namespace llvm;
17 using namespace llvm::ARMBuildAttrs;
18 
19 
20 static const EnumEntry<unsigned> TagNames[] = {
21  { "Tag_File", ARMBuildAttrs::File },
22  { "Tag_Section", ARMBuildAttrs::Section },
23  { "Tag_Symbol", ARMBuildAttrs::Symbol },
24 };
25 
26 namespace llvm {
27 #define ATTRIBUTE_HANDLER(Attr_) \
28  { ARMBuildAttrs::Attr_, &ARMAttributeParser::Attr_ }
29 
30 const ARMAttributeParser::DisplayHandler
31 ARMAttributeParser::DisplayRoutines[] = {
32  { ARMBuildAttrs::CPU_raw_name, &ARMAttributeParser::StringAttribute, },
33  { ARMBuildAttrs::CPU_name, &ARMAttributeParser::StringAttribute },
70 };
71 
72 #undef ATTRIBUTE_HANDLER
73 
74 uint64_t ARMAttributeParser::ParseInteger(const uint8_t *Data,
75  uint32_t &Offset) {
76  unsigned Length;
77  uint64_t Value = decodeULEB128(Data + Offset, &Length);
78  Offset = Offset + Length;
79  return Value;
80 }
81 
82 StringRef ARMAttributeParser::ParseString(const uint8_t *Data,
83  uint32_t &Offset) {
84  const char *String = reinterpret_cast<const char*>(Data + Offset);
85  size_t Length = std::strlen(String);
86  Offset = Offset + Length + 1;
87  return StringRef(String, Length);
88 }
89 
90 void ARMAttributeParser::IntegerAttribute(AttrType Tag, const uint8_t *Data,
91  uint32_t &Offset) {
92 
93  uint64_t Value = ParseInteger(Data, Offset);
94  Attributes.insert(std::make_pair(Tag, Value));
95 
96  if (SW)
97  SW->printNumber(ARMBuildAttrs::AttrTypeAsString(Tag), Value);
98 }
99 
100 void ARMAttributeParser::StringAttribute(AttrType Tag, const uint8_t *Data,
101  uint32_t &Offset) {
102  StringRef TagName = ARMBuildAttrs::AttrTypeAsString(Tag, /*TagPrefix*/false);
103  StringRef ValueDesc = ParseString(Data, Offset);
104 
105  if (SW) {
106  DictScope AS(*SW, "Attribute");
107  SW->printNumber("Tag", Tag);
108  if (!TagName.empty())
109  SW->printString("TagName", TagName);
110  SW->printString("Value", ValueDesc);
111  }
112 }
113 
114 void ARMAttributeParser::PrintAttribute(unsigned Tag, unsigned Value,
115  StringRef ValueDesc) {
116  Attributes.insert(std::make_pair(Tag, Value));
117 
118  if (SW) {
120  /*TagPrefix*/false);
121  DictScope AS(*SW, "Attribute");
122  SW->printNumber("Tag", Tag);
123  SW->printNumber("Value", Value);
124  if (!TagName.empty())
125  SW->printString("TagName", TagName);
126  if (!ValueDesc.empty())
127  SW->printString("Description", ValueDesc);
128  }
129 }
130 
131 void ARMAttributeParser::CPU_arch(AttrType Tag, const uint8_t *Data,
132  uint32_t &Offset) {
133  static const char *const Strings[] = {
134  "Pre-v4", "ARM v4", "ARM v4T", "ARM v5T", "ARM v5TE", "ARM v5TEJ", "ARM v6",
135  "ARM v6KZ", "ARM v6T2", "ARM v6K", "ARM v7", "ARM v6-M", "ARM v6S-M",
136  "ARM v7E-M", "ARM v8"
137  };
138 
139  uint64_t Value = ParseInteger(Data, Offset);
140  StringRef ValueDesc =
141  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
142  PrintAttribute(Tag, Value, ValueDesc);
143 }
144 
145 void ARMAttributeParser::CPU_arch_profile(AttrType Tag, const uint8_t *Data,
146  uint32_t &Offset) {
147  uint64_t Encoded = ParseInteger(Data, Offset);
148 
149  StringRef Profile;
150  switch (Encoded) {
151  default: Profile = "Unknown"; break;
152  case 'A': Profile = "Application"; break;
153  case 'R': Profile = "Real-time"; break;
154  case 'M': Profile = "Microcontroller"; break;
155  case 'S': Profile = "Classic"; break;
156  case 0: Profile = "None"; break;
157  }
158 
159  PrintAttribute(Tag, Encoded, Profile);
160 }
161 
162 void ARMAttributeParser::ARM_ISA_use(AttrType Tag, const uint8_t *Data,
163  uint32_t &Offset) {
164  static const char *const Strings[] = { "Not Permitted", "Permitted" };
165 
166  uint64_t Value = ParseInteger(Data, Offset);
167  StringRef ValueDesc =
168  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
169  PrintAttribute(Tag, Value, ValueDesc);
170 }
171 
172 void ARMAttributeParser::THUMB_ISA_use(AttrType Tag, const uint8_t *Data,
173  uint32_t &Offset) {
174  static const char *const Strings[] = { "Not Permitted", "Thumb-1", "Thumb-2" };
175 
176  uint64_t Value = ParseInteger(Data, Offset);
177  StringRef ValueDesc =
178  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
179  PrintAttribute(Tag, Value, ValueDesc);
180 }
181 
182 void ARMAttributeParser::FP_arch(AttrType Tag, const uint8_t *Data,
183  uint32_t &Offset) {
184  static const char *const Strings[] = {
185  "Not Permitted", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4",
186  "VFPv4-D16", "ARMv8-a FP", "ARMv8-a FP-D16"
187  };
188 
189  uint64_t Value = ParseInteger(Data, Offset);
190  StringRef ValueDesc =
191  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
192  PrintAttribute(Tag, Value, ValueDesc);
193 }
194 
195 void ARMAttributeParser::WMMX_arch(AttrType Tag, const uint8_t *Data,
196  uint32_t &Offset) {
197  static const char *const Strings[] = { "Not Permitted", "WMMXv1", "WMMXv2" };
198 
199  uint64_t Value = ParseInteger(Data, Offset);
200  StringRef ValueDesc =
201  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
202  PrintAttribute(Tag, Value, ValueDesc);
203 }
204 
205 void ARMAttributeParser::Advanced_SIMD_arch(AttrType Tag, const uint8_t *Data,
206  uint32_t &Offset) {
207  static const char *const Strings[] = {
208  "Not Permitted", "NEONv1", "NEONv2+FMA", "ARMv8-a NEON", "ARMv8.1-a NEON"
209  };
210 
211  uint64_t Value = ParseInteger(Data, Offset);
212  StringRef ValueDesc =
213  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
214  PrintAttribute(Tag, Value, ValueDesc);
215 }
216 
217 void ARMAttributeParser::PCS_config(AttrType Tag, const uint8_t *Data,
218  uint32_t &Offset) {
219  static const char *const Strings[] = {
220  "None", "Bare Platform", "Linux Application", "Linux DSO", "Palm OS 2004",
221  "Reserved (Palm OS)", "Symbian OS 2004", "Reserved (Symbian OS)"
222  };
223 
224  uint64_t Value = ParseInteger(Data, Offset);
225  StringRef ValueDesc =
226  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
227  PrintAttribute(Tag, Value, ValueDesc);
228 }
229 
230 void ARMAttributeParser::ABI_PCS_R9_use(AttrType Tag, const uint8_t *Data,
231  uint32_t &Offset) {
232  static const char *const Strings[] = { "v6", "Static Base", "TLS", "Unused" };
233 
234  uint64_t Value = ParseInteger(Data, Offset);
235  StringRef ValueDesc =
236  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
237  PrintAttribute(Tag, Value, ValueDesc);
238 }
239 
240 void ARMAttributeParser::ABI_PCS_RW_data(AttrType Tag, const uint8_t *Data,
241  uint32_t &Offset) {
242  static const char *const Strings[] = {
243  "Absolute", "PC-relative", "SB-relative", "Not Permitted"
244  };
245 
246  uint64_t Value = ParseInteger(Data, Offset);
247  StringRef ValueDesc =
248  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
249  PrintAttribute(Tag, Value, ValueDesc);
250 }
251 
252 void ARMAttributeParser::ABI_PCS_RO_data(AttrType Tag, const uint8_t *Data,
253  uint32_t &Offset) {
254  static const char *const Strings[] = {
255  "Absolute", "PC-relative", "Not Permitted"
256  };
257 
258  uint64_t Value = ParseInteger(Data, Offset);
259  StringRef ValueDesc =
260  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
261  PrintAttribute(Tag, Value, ValueDesc);
262 }
263 
264 void ARMAttributeParser::ABI_PCS_GOT_use(AttrType Tag, const uint8_t *Data,
265  uint32_t &Offset) {
266  static const char *const Strings[] = {
267  "Not Permitted", "Direct", "GOT-Indirect"
268  };
269 
270  uint64_t Value = ParseInteger(Data, Offset);
271  StringRef ValueDesc =
272  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
273  PrintAttribute(Tag, Value, ValueDesc);
274 }
275 
276 void ARMAttributeParser::ABI_PCS_wchar_t(AttrType Tag, const uint8_t *Data,
277  uint32_t &Offset) {
278  static const char *const Strings[] = {
279  "Not Permitted", "Unknown", "2-byte", "Unknown", "4-byte"
280  };
281 
282  uint64_t Value = ParseInteger(Data, Offset);
283  StringRef ValueDesc =
284  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
285  PrintAttribute(Tag, Value, ValueDesc);
286 }
287 
288 void ARMAttributeParser::ABI_FP_rounding(AttrType Tag, const uint8_t *Data,
289  uint32_t &Offset) {
290  static const char *const Strings[] = { "IEEE-754", "Runtime" };
291 
292  uint64_t Value = ParseInteger(Data, Offset);
293  StringRef ValueDesc =
294  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
295  PrintAttribute(Tag, Value, ValueDesc);
296 }
297 
298 void ARMAttributeParser::ABI_FP_denormal(AttrType Tag, const uint8_t *Data,
299  uint32_t &Offset) {
300  static const char *const Strings[] = {
301  "Unsupported", "IEEE-754", "Sign Only"
302  };
303 
304  uint64_t Value = ParseInteger(Data, Offset);
305  StringRef ValueDesc =
306  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
307  PrintAttribute(Tag, Value, ValueDesc);
308 }
309 
310 void ARMAttributeParser::ABI_FP_exceptions(AttrType Tag, const uint8_t *Data,
311  uint32_t &Offset) {
312  static const char *const Strings[] = { "Not Permitted", "IEEE-754" };
313 
314  uint64_t Value = ParseInteger(Data, Offset);
315  StringRef ValueDesc =
316  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
317  PrintAttribute(Tag, Value, ValueDesc);
318 }
319 
320 void ARMAttributeParser::ABI_FP_user_exceptions(AttrType Tag,
321  const uint8_t *Data,
322  uint32_t &Offset) {
323  static const char *const Strings[] = { "Not Permitted", "IEEE-754" };
324 
325  uint64_t Value = ParseInteger(Data, Offset);
326  StringRef ValueDesc =
327  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
328  PrintAttribute(Tag, Value, ValueDesc);
329 }
330 
331 void ARMAttributeParser::ABI_FP_number_model(AttrType Tag, const uint8_t *Data,
332  uint32_t &Offset) {
333  static const char *const Strings[] = {
334  "Not Permitted", "Finite Only", "RTABI", "IEEE-754"
335  };
336 
337  uint64_t Value = ParseInteger(Data, Offset);
338  StringRef ValueDesc =
339  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
340  PrintAttribute(Tag, Value, ValueDesc);
341 }
342 
343 void ARMAttributeParser::ABI_align_needed(AttrType Tag, const uint8_t *Data,
344  uint32_t &Offset) {
345  static const char *const Strings[] = {
346  "Not Permitted", "8-byte alignment", "4-byte alignment", "Reserved"
347  };
348 
349  uint64_t Value = ParseInteger(Data, Offset);
350 
351  std::string Description;
352  if (Value < array_lengthof(Strings))
353  Description = std::string(Strings[Value]);
354  else if (Value <= 12)
355  Description = std::string("8-byte alignment, ") + utostr(1ULL << Value)
356  + std::string("-byte extended alignment");
357  else
358  Description = "Invalid";
359 
360  PrintAttribute(Tag, Value, Description);
361 }
362 
363 void ARMAttributeParser::ABI_align_preserved(AttrType Tag, const uint8_t *Data,
364  uint32_t &Offset) {
365  static const char *const Strings[] = {
366  "Not Required", "8-byte data alignment", "8-byte data and code alignment",
367  "Reserved"
368  };
369 
370  uint64_t Value = ParseInteger(Data, Offset);
371 
372  std::string Description;
373  if (Value < array_lengthof(Strings))
374  Description = std::string(Strings[Value]);
375  else if (Value <= 12)
376  Description = std::string("8-byte stack alignment, ") +
377  utostr(1ULL << Value) + std::string("-byte data alignment");
378  else
379  Description = "Invalid";
380 
381  PrintAttribute(Tag, Value, Description);
382 }
383 
384 void ARMAttributeParser::ABI_enum_size(AttrType Tag, const uint8_t *Data,
385  uint32_t &Offset) {
386  static const char *const Strings[] = {
387  "Not Permitted", "Packed", "Int32", "External Int32"
388  };
389 
390  uint64_t Value = ParseInteger(Data, Offset);
391  StringRef ValueDesc =
392  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
393  PrintAttribute(Tag, Value, ValueDesc);
394 }
395 
396 void ARMAttributeParser::ABI_HardFP_use(AttrType Tag, const uint8_t *Data,
397  uint32_t &Offset) {
398  static const char *const Strings[] = {
399  "Tag_FP_arch", "Single-Precision", "Reserved", "Tag_FP_arch (deprecated)"
400  };
401 
402  uint64_t Value = ParseInteger(Data, Offset);
403  StringRef ValueDesc =
404  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
405  PrintAttribute(Tag, Value, ValueDesc);
406 }
407 
408 void ARMAttributeParser::ABI_VFP_args(AttrType Tag, const uint8_t *Data,
409  uint32_t &Offset) {
410  static const char *const Strings[] = {
411  "AAPCS", "AAPCS VFP", "Custom", "Not Permitted"
412  };
413 
414  uint64_t Value = ParseInteger(Data, Offset);
415  StringRef ValueDesc =
416  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
417  PrintAttribute(Tag, Value, ValueDesc);
418 }
419 
420 void ARMAttributeParser::ABI_WMMX_args(AttrType Tag, const uint8_t *Data,
421  uint32_t &Offset) {
422  static const char *const Strings[] = { "AAPCS", "iWMMX", "Custom" };
423 
424  uint64_t Value = ParseInteger(Data, Offset);
425  StringRef ValueDesc =
426  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
427  PrintAttribute(Tag, Value, ValueDesc);
428 }
429 
430 void ARMAttributeParser::ABI_optimization_goals(AttrType Tag,
431  const uint8_t *Data,
432  uint32_t &Offset) {
433  static const char *const Strings[] = {
434  "None", "Speed", "Aggressive Speed", "Size", "Aggressive Size", "Debugging",
435  "Best Debugging"
436  };
437 
438  uint64_t Value = ParseInteger(Data, Offset);
439  StringRef ValueDesc =
440  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
441  PrintAttribute(Tag, Value, ValueDesc);
442 }
443 
444 void ARMAttributeParser::ABI_FP_optimization_goals(AttrType Tag,
445  const uint8_t *Data,
446  uint32_t &Offset) {
447  static const char *const Strings[] = {
448  "None", "Speed", "Aggressive Speed", "Size", "Aggressive Size", "Accuracy",
449  "Best Accuracy"
450  };
451 
452  uint64_t Value = ParseInteger(Data, Offset);
453  StringRef ValueDesc =
454  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
455  PrintAttribute(Tag, Value, ValueDesc);
456 }
457 
458 void ARMAttributeParser::compatibility(AttrType Tag, const uint8_t *Data,
459  uint32_t &Offset) {
460  uint64_t Integer = ParseInteger(Data, Offset);
461  StringRef String = ParseString(Data, Offset);
462 
463  if (SW) {
464  DictScope AS(*SW, "Attribute");
465  SW->printNumber("Tag", Tag);
466  SW->startLine() << "Value: " << Integer << ", " << String << '\n';
467  SW->printString("TagName", AttrTypeAsString(Tag, /*TagPrefix*/false));
468  switch (Integer) {
469  case 0:
470  SW->printString("Description", StringRef("No Specific Requirements"));
471  break;
472  case 1:
473  SW->printString("Description", StringRef("AEABI Conformant"));
474  break;
475  default:
476  SW->printString("Description", StringRef("AEABI Non-Conformant"));
477  break;
478  }
479  }
480 }
481 
482 void ARMAttributeParser::CPU_unaligned_access(AttrType Tag, const uint8_t *Data,
483  uint32_t &Offset) {
484  static const char *const Strings[] = { "Not Permitted", "v6-style" };
485 
486  uint64_t Value = ParseInteger(Data, Offset);
487  StringRef ValueDesc =
488  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
489  PrintAttribute(Tag, Value, ValueDesc);
490 }
491 
492 void ARMAttributeParser::FP_HP_extension(AttrType Tag, const uint8_t *Data,
493  uint32_t &Offset) {
494  static const char *const Strings[] = { "If Available", "Permitted" };
495 
496  uint64_t Value = ParseInteger(Data, Offset);
497  StringRef ValueDesc =
498  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
499  PrintAttribute(Tag, Value, ValueDesc);
500 }
501 
502 void ARMAttributeParser::ABI_FP_16bit_format(AttrType Tag, const uint8_t *Data,
503  uint32_t &Offset) {
504  static const char *const Strings[] = { "Not Permitted", "IEEE-754", "VFPv3" };
505 
506  uint64_t Value = ParseInteger(Data, Offset);
507  StringRef ValueDesc =
508  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
509  PrintAttribute(Tag, Value, ValueDesc);
510 }
511 
512 void ARMAttributeParser::MPextension_use(AttrType Tag, const uint8_t *Data,
513  uint32_t &Offset) {
514  static const char *const Strings[] = { "Not Permitted", "Permitted" };
515 
516  uint64_t Value = ParseInteger(Data, Offset);
517  StringRef ValueDesc =
518  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
519  PrintAttribute(Tag, Value, ValueDesc);
520 }
521 
522 void ARMAttributeParser::DIV_use(AttrType Tag, const uint8_t *Data,
523  uint32_t &Offset) {
524  static const char *const Strings[] = {
525  "If Available", "Not Permitted", "Permitted"
526  };
527 
528  uint64_t Value = ParseInteger(Data, Offset);
529  StringRef ValueDesc =
530  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
531  PrintAttribute(Tag, Value, ValueDesc);
532 }
533 
534 void ARMAttributeParser::DSP_extension(AttrType Tag, const uint8_t *Data,
535  uint32_t &Offset) {
536  static const char *const Strings[] = { "Not Permitted", "Permitted" };
537 
538  uint64_t Value = ParseInteger(Data, Offset);
539  StringRef ValueDesc =
540  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
541  PrintAttribute(Tag, Value, ValueDesc);
542 }
543 
544 void ARMAttributeParser::T2EE_use(AttrType Tag, const uint8_t *Data,
545  uint32_t &Offset) {
546  static const char *const Strings[] = { "Not Permitted", "Permitted" };
547 
548  uint64_t Value = ParseInteger(Data, Offset);
549  StringRef ValueDesc =
550  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
551  PrintAttribute(Tag, Value, ValueDesc);
552 }
553 
554 void ARMAttributeParser::Virtualization_use(AttrType Tag, const uint8_t *Data,
555  uint32_t &Offset) {
556  static const char *const Strings[] = {
557  "Not Permitted", "TrustZone", "Virtualization Extensions",
558  "TrustZone + Virtualization Extensions"
559  };
560 
561  uint64_t Value = ParseInteger(Data, Offset);
562  StringRef ValueDesc =
563  (Value < array_lengthof(Strings)) ? Strings[Value] : nullptr;
564  PrintAttribute(Tag, Value, ValueDesc);
565 }
566 
567 void ARMAttributeParser::nodefaults(AttrType Tag, const uint8_t *Data,
568  uint32_t &Offset) {
569  uint64_t Value = ParseInteger(Data, Offset);
570  PrintAttribute(Tag, Value, "Unspecified Tags UNDEFINED");
571 }
572 
573 void ARMAttributeParser::ParseIndexList(const uint8_t *Data, uint32_t &Offset,
574  SmallVectorImpl<uint8_t> &IndexList) {
575  for (;;) {
576  unsigned Length;
577  uint64_t Value = decodeULEB128(Data + Offset, &Length);
578  Offset = Offset + Length;
579  if (Value == 0)
580  break;
581  IndexList.push_back(Value);
582  }
583 }
584 
585 void ARMAttributeParser::ParseAttributeList(const uint8_t *Data,
586  uint32_t &Offset, uint32_t Length) {
587  while (Offset < Length) {
588  unsigned Length;
589  uint64_t Tag = decodeULEB128(Data + Offset, &Length);
590  Offset += Length;
591 
592  bool Handled = false;
593  for (unsigned AHI = 0, AHE = array_lengthof(DisplayRoutines);
594  AHI != AHE && !Handled; ++AHI) {
595  if (uint64_t(DisplayRoutines[AHI].Attribute) == Tag) {
596  (this->*DisplayRoutines[AHI].Routine)(ARMBuildAttrs::AttrType(Tag),
597  Data, Offset);
598  Handled = true;
599  break;
600  }
601  }
602  if (!Handled) {
603  if (Tag < 32) {
604  errs() << "unhandled AEABI Tag " << Tag
605  << " (" << ARMBuildAttrs::AttrTypeAsString(Tag) << ")\n";
606  continue;
607  }
608 
609  if (Tag % 2 == 0)
610  IntegerAttribute(ARMBuildAttrs::AttrType(Tag), Data, Offset);
611  else
612  StringAttribute(ARMBuildAttrs::AttrType(Tag), Data, Offset);
613  }
614  }
615 }
616 
617 void ARMAttributeParser::ParseSubsection(const uint8_t *Data, uint32_t Length) {
618  uint32_t Offset = sizeof(uint32_t); /* SectionLength */
619 
620  const char *VendorName = reinterpret_cast<const char*>(Data + Offset);
621  size_t VendorNameLength = std::strlen(VendorName);
622  Offset = Offset + VendorNameLength + 1;
623 
624  if (SW) {
625  SW->printNumber("SectionLength", Length);
626  SW->printString("Vendor", StringRef(VendorName, VendorNameLength));
627  }
628 
629  if (StringRef(VendorName, VendorNameLength).lower() != "aeabi") {
630  return;
631  }
632 
633  while (Offset < Length) {
634  /// Tag_File | Tag_Section | Tag_Symbol uleb128:byte-size
635  uint8_t Tag = Data[Offset];
636  Offset = Offset + sizeof(Tag);
637 
638  uint32_t Size =
639  *reinterpret_cast<const support::ulittle32_t*>(Data + Offset);
640  Offset = Offset + sizeof(Size);
641 
642  if (SW) {
643  SW->printEnum("Tag", Tag, makeArrayRef(TagNames));
644  SW->printNumber("Size", Size);
645  }
646 
647  if (Size > Length) {
648  errs() << "subsection length greater than section length\n";
649  return;
650  }
651 
652  StringRef ScopeName, IndexName;
653  SmallVector<uint8_t, 8> Indicies;
654  switch (Tag) {
655  case ARMBuildAttrs::File:
656  ScopeName = "FileAttributes";
657  break;
659  ScopeName = "SectionAttributes";
660  IndexName = "Sections";
661  ParseIndexList(Data, Offset, Indicies);
662  break;
664  ScopeName = "SymbolAttributes";
665  IndexName = "Symbols";
666  ParseIndexList(Data, Offset, Indicies);
667  break;
668  default:
669  errs() << "unrecognised tag: 0x" << Twine::utohexstr(Tag) << '\n';
670  return;
671  }
672 
673  if (SW) {
674  DictScope ASS(*SW, ScopeName);
675  if (!Indicies.empty())
676  SW->printList(IndexName, Indicies);
677  ParseAttributeList(Data, Offset, Length);
678  } else {
679  ParseAttributeList(Data, Offset, Length);
680  }
681  }
682 }
683 
685  size_t Offset = 1;
686  unsigned SectionNumber = 0;
687 
688  while (Offset < Section.size()) {
689  uint32_t SectionLength = isLittle ?
690  support::endian::read32le(Section.data() + Offset) :
692 
693  if (SW) {
694  SW->startLine() << "Section " << ++SectionNumber << " {\n";
695  SW->indent();
696  }
697 
698  ParseSubsection(Section.data() + Offset, SectionLength);
699  Offset = Offset + SectionLength;
700 
701  if (SW) {
702  SW->unindent();
703  SW->startLine() << "}\n";
704  }
705  }
706 }
707 }
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
#define ATTRIBUTE_HANDLER(Attr_)
void push_back(const T &Elt)
Definition: SmallVector.h:218
uint32_t read32be(const void *P)
Definition: Endian.h:372
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
StringRef AttrTypeAsString(unsigned Attr, bool HasTagPrefix=true)
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
uint64_t decodeULEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a ULEB128 value.
Definition: LEB128.h:129
static const EnumEntry< unsigned > TagNames[]
const T * data() const
Definition: ArrayRef.h:146
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
Definition: STLExtras.h:1044
static Twine utohexstr(const uint64_t &Val)
Definition: Twine.h:385
std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:224
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:56
uint32_t read32le(const void *P)
Definition: Endian.h:369
uint32_t Size
Definition: Profile.cpp:47
LLVM Value Representation.
Definition: Value.h:73
void Parse(ArrayRef< uint8_t > Section, bool isLittle)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49