1 //===- AppendingTypeTableBuilder.h -------------------------------*- 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 10 #ifndef LLVM_DEBUGINFO_CODEVIEW_APPENDINGTYPETABLEBUILDER_H 11 #define LLVM_DEBUGINFO_CODEVIEW_APPENDINGTYPETABLEBUILDER_H 12 13 #include "llvm/ADT/ArrayRef.h" 14 #include "llvm/ADT/SmallVector.h" 15 #include "llvm/DebugInfo/CodeView/CodeView.h" 16 #include "llvm/DebugInfo/CodeView/SimpleTypeSerializer.h" 17 #include "llvm/DebugInfo/CodeView/TypeCollection.h" 18 #include "llvm/DebugInfo/CodeView/TypeIndex.h" 19 #include "llvm/Support/Allocator.h" 20 #include <cassert> 21 #include <cstdint> 22 #include <memory> 23 #include <vector> 24 25 namespace llvm { 26 namespace codeview { 27 28 class ContinuationRecordBuilder; 29 30 class AppendingTypeTableBuilder : public TypeCollection { 31 32 BumpPtrAllocator &RecordStorage; 33 SimpleTypeSerializer SimpleSerializer; 34 35 /// Contains a list of all records indexed by TypeIndex.toArrayIndex(). 36 SmallVector<ArrayRef<uint8_t>, 2> SeenRecords; 37 38 public: 39 explicit AppendingTypeTableBuilder(BumpPtrAllocator &Storage); 40 ~AppendingTypeTableBuilder(); 41 42 // TypeTableCollection overrides 43 Optional<TypeIndex> getFirst() override; 44 Optional<TypeIndex> getNext(TypeIndex Prev) override; 45 CVType getType(TypeIndex Index) override; 46 StringRef getTypeName(TypeIndex Index) override; 47 bool contains(TypeIndex Index) override; 48 uint32_t size() override; 49 uint32_t capacity() override; 50 51 // public interface 52 void reset(); 53 TypeIndex nextTypeIndex() const; 54 getAllocator()55 BumpPtrAllocator &getAllocator() { return RecordStorage; } 56 57 ArrayRef<ArrayRef<uint8_t>> records() const; 58 TypeIndex insertRecordBytes(ArrayRef<uint8_t> &Record); 59 TypeIndex insertRecord(ContinuationRecordBuilder &Builder); 60 writeLeafType(T & Record)61 template <typename T> TypeIndex writeLeafType(T &Record) { 62 ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record); 63 return insertRecordBytes(Data); 64 } 65 }; 66 67 } // end namespace codeview 68 } // end namespace llvm 69 70 #endif // LLVM_DEBUGINFO_CODEVIEW_TYPETABLEBUILDER_H 71