TypeTableCollection.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //===- TypeTableCollection.cpp -------------------------------- *- C++ --*-===//
  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. #include "llvm/DebugInfo/CodeView/TypeTableCollection.h"
  10. #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
  11. #include "llvm/DebugInfo/CodeView/RecordName.h"
  12. #include "llvm/DebugInfo/CodeView/TypeTableBuilder.h"
  13. #include "llvm/Support/BinaryByteStream.h"
  14. #include "llvm/Support/BinaryStreamReader.h"
  15. using namespace llvm;
  16. using namespace llvm::codeview;
  17. TypeTableCollection::TypeTableCollection(ArrayRef<ArrayRef<uint8_t>> Records)
  18. : NameStorage(Allocator), Records(Records) {
  19. Names.resize(Records.size());
  20. }
  21. Optional<TypeIndex> TypeTableCollection::getFirst() {
  22. if (empty())
  23. return None;
  24. return TypeIndex::fromArrayIndex(0);
  25. }
  26. Optional<TypeIndex> TypeTableCollection::getNext(TypeIndex Prev) {
  27. assert(contains(Prev));
  28. ++Prev;
  29. if (Prev.toArrayIndex() == size())
  30. return None;
  31. return Prev;
  32. }
  33. CVType TypeTableCollection::getType(TypeIndex Index) {
  34. assert(Index.toArrayIndex() < Records.size());
  35. ArrayRef<uint8_t> Bytes = Records[Index.toArrayIndex()];
  36. const RecordPrefix *Prefix =
  37. reinterpret_cast<const RecordPrefix *>(Bytes.data());
  38. TypeLeafKind Kind = static_cast<TypeLeafKind>(uint16_t(Prefix->RecordKind));
  39. return CVType(Kind, Bytes);
  40. }
  41. StringRef TypeTableCollection::getTypeName(TypeIndex Index) {
  42. if (Index.isNoneType() || Index.isSimple())
  43. return TypeIndex::simpleTypeName(Index);
  44. uint32_t I = Index.toArrayIndex();
  45. if (Names[I].data() == nullptr) {
  46. StringRef Result = NameStorage.save(computeTypeName(*this, Index));
  47. Names[I] = Result;
  48. }
  49. return Names[I];
  50. }
  51. bool TypeTableCollection::contains(TypeIndex Index) {
  52. return Index.toArrayIndex() <= size();
  53. }
  54. uint32_t TypeTableCollection::size() { return Records.size(); }
  55. uint32_t TypeTableCollection::capacity() { return Records.size(); }