A couple of places in LLD were passing references to
TypeTableCollections around, which makes it hard to change the
implementation at runtime. However, these cases only needed to
iterate over the types in the collection, and TypeCollection
already provides a handy abstract interface for this purpose.
By implementing this interface, we can get rid of the need to
pass TypeTableBuilder references around, which should allow us
to swap the implementation at runtime in subsequent patches.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319345
91177308-0d34-0410-b5e6-
96231b3b80d8
virtual bool contains(TypeIndex Index) = 0;
virtual uint32_t size() = 0;
virtual uint32_t capacity() = 0;
+
+ template <typename TFunc> void ForEachRecord(TFunc Func) {
+ Optional<TypeIndex> Next = getFirst();
+
+ while (Next.hasValue()) {
+ TypeIndex N = *Next;
+ Func(N, getType(N));
+ Next = getNext(N);
+ }
+ }
};
}
}
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/DebugInfo/CodeView/CodeView.h"
-#include "llvm/DebugInfo/CodeView/RecordSerialization.h"
#include "llvm/DebugInfo/CodeView/SimpleTypeSerializer.h"
+#include "llvm/DebugInfo/CodeView/TypeCollection.h"
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
-#include "llvm/DebugInfo/CodeView/TypeRecordMapping.h"
-#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
#include "llvm/Support/Allocator.h"
-#include "llvm/Support/BinaryByteStream.h"
-#include "llvm/Support/BinaryStreamWriter.h"
#include "llvm/Support/Error.h"
#include <cassert>
#include <cstdint>
class ContinuationRecordBuilder;
class TypeHasher;
-class TypeTableBuilder {
+class TypeTableBuilder : public TypeCollection {
BumpPtrAllocator &RecordStorage;
SimpleTypeSerializer SimpleSerializer;
explicit TypeTableBuilder(BumpPtrAllocator &Storage, bool Hash = true);
~TypeTableBuilder();
- void reset();
-
- bool empty() const { return SeenRecords.empty(); }
+ // TypeTableCollection overrides
+ Optional<TypeIndex> getFirst() override;
+ Optional<TypeIndex> getNext(TypeIndex Prev) override;
+ CVType getType(TypeIndex Index) override;
+ StringRef getTypeName(TypeIndex Index) override;
+ bool contains(TypeIndex Index) override;
+ uint32_t size() override;
+ uint32_t capacity() override;
+ // public interface
+ void reset();
TypeIndex nextTypeIndex() const;
BumpPtrAllocator &getAllocator() { return RecordStorage; }
ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
return insertRecordBytes(Data);
}
-
- template <typename TFunc> void ForEachRecord(TFunc Func) {
- uint32_t Index = TypeIndex::FirstNonSimpleIndex;
-
- for (auto Record : SeenRecords) {
- Func(TypeIndex(Index), Record);
- ++Index;
- }
- }
};
} // end namespace codeview
TypeTableBuilder::~TypeTableBuilder() = default;
+Optional<TypeIndex> TypeTableBuilder::getFirst() {
+ if (empty())
+ return None;
+
+ return TypeIndex(TypeIndex::FirstNonSimpleIndex);
+}
+
+Optional<TypeIndex> TypeTableBuilder::getNext(TypeIndex Prev) {
+ if (++Prev == nextTypeIndex())
+ return None;
+ return Prev;
+}
+
+CVType TypeTableBuilder::getType(TypeIndex Index) {
+ CVType Type;
+ Type.RecordData = SeenRecords[Index.toArrayIndex()];
+ const RecordPrefix *P =
+ reinterpret_cast<const RecordPrefix *>(Type.RecordData.data());
+ Type.Type = static_cast<TypeLeafKind>(uint16_t(P->RecordKind));
+ return Type;
+}
+
+StringRef TypeTableBuilder::getTypeName(TypeIndex Index) {
+ llvm_unreachable("Method not implemented");
+}
+
+bool TypeTableBuilder::contains(TypeIndex Index) {
+ if (Index.isSimple() || Index.isNoneType())
+ return false;
+
+ return Index.toArrayIndex() < SeenRecords.size();
+}
+
+uint32_t TypeTableBuilder::size() { return SeenRecords.size(); }
+
+uint32_t TypeTableBuilder::capacity() { return SeenRecords.size(); }
+
ArrayRef<ArrayRef<uint8_t>> TypeTableBuilder::records() const {
return SeenRecords;
}
auto &DestTpi = Builder.getTpiBuilder();
auto &DestIpi = Builder.getIpiBuilder();
- MergedTpi.ForEachRecord([&DestTpi](TypeIndex TI, ArrayRef<uint8_t> Data) {
- DestTpi.addTypeRecord(Data, None);
+ MergedTpi.ForEachRecord([&DestTpi](TypeIndex TI, const CVType &Type) {
+ DestTpi.addTypeRecord(Type.RecordData, None);
});
- MergedIpi.ForEachRecord([&DestIpi](TypeIndex TI, ArrayRef<uint8_t> Data) {
- DestIpi.addTypeRecord(Data, None);
+ MergedIpi.ForEachRecord([&DestIpi](TypeIndex TI, const CVType &Type) {
+ DestIpi.addTypeRecord(Type.RecordData, None);
});
Builder.getInfoBuilder().addFeature(PdbRaw_FeatureSig::VC140);
llvm::codeview::TypeTableBuilder &CVTypes) {
// Flatten it first, then run our dumper on it.
SmallString<0> TypeBuf;
- CVTypes.ForEachRecord([&](TypeIndex TI, ArrayRef<uint8_t> Record) {
- TypeBuf.append(Record.begin(), Record.end());
+ CVTypes.ForEachRecord([&](TypeIndex TI, const CVType &Record) {
+ TypeBuf.append(Record.RecordData.begin(), Record.RecordData.end());
});
TypeTableCollection TpiTypes(CVTypes.records());