1 //===- AppendingTypeTableBuilder.h -------------------------------*- C++-*-===// 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 9 #ifndef LLVM_DEBUGINFO_CODEVIEW_APPENDINGTYPETABLEBUILDER_H 10 #define LLVM_DEBUGINFO_CODEVIEW_APPENDINGTYPETABLEBUILDER_H 11 12 #include "llvm/ADT/ArrayRef.h" 13 #include "llvm/ADT/SmallVector.h" 14 #include "llvm/DebugInfo/CodeView/CodeView.h" 15 #include "llvm/DebugInfo/CodeView/SimpleTypeSerializer.h" 16 #include "llvm/DebugInfo/CodeView/TypeCollection.h" 17 #include "llvm/DebugInfo/CodeView/TypeIndex.h" 18 #include "llvm/Support/Allocator.h" 19 #include <cassert> 20 #include <cstdint> 21 #include <memory> 22 #include <vector> 23 24 namespace llvm { 25 namespace codeview { 26 27 class ContinuationRecordBuilder; 28 29 class AppendingTypeTableBuilder : public TypeCollection { 30 31 BumpPtrAllocator &RecordStorage; 32 SimpleTypeSerializer SimpleSerializer; 33 34 /// Contains a list of all records indexed by TypeIndex.toArrayIndex(). 35 SmallVector<ArrayRef<uint8_t>, 2> SeenRecords; 36 37 public: 38 explicit AppendingTypeTableBuilder(BumpPtrAllocator &Storage); 39 ~AppendingTypeTableBuilder(); 40 41 // TypeCollection overrides 42 Optional<TypeIndex> getFirst() override; 43 Optional<TypeIndex> getNext(TypeIndex Prev) override; 44 CVType getType(TypeIndex Index) override; 45 StringRef getTypeName(TypeIndex Index) override; 46 bool contains(TypeIndex Index) override; 47 uint32_t size() override; 48 uint32_t capacity() override; 49 bool replaceType(TypeIndex &Index, CVType Data, bool Stabilize) 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