Yi Kong | e5b9f24 | 2023-04-26 13:35:57 +0900 | [diff] [blame^] | 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/CVRecord.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 <cstdint> |
| 20 | |
| 21 | namespace llvm { |
| 22 | namespace codeview { |
| 23 | |
| 24 | class ContinuationRecordBuilder; |
| 25 | |
| 26 | class AppendingTypeTableBuilder : public TypeCollection { |
| 27 | |
| 28 | BumpPtrAllocator &RecordStorage; |
| 29 | SimpleTypeSerializer SimpleSerializer; |
| 30 | |
| 31 | /// Contains a list of all records indexed by TypeIndex.toArrayIndex(). |
| 32 | SmallVector<ArrayRef<uint8_t>, 2> SeenRecords; |
| 33 | |
| 34 | public: |
| 35 | explicit AppendingTypeTableBuilder(BumpPtrAllocator &Storage); |
| 36 | ~AppendingTypeTableBuilder(); |
| 37 | |
| 38 | // TypeCollection overrides |
| 39 | std::optional<TypeIndex> getFirst() override; |
| 40 | std::optional<TypeIndex> getNext(TypeIndex Prev) override; |
| 41 | CVType getType(TypeIndex Index) override; |
| 42 | StringRef getTypeName(TypeIndex Index) override; |
| 43 | bool contains(TypeIndex Index) override; |
| 44 | uint32_t size() override; |
| 45 | uint32_t capacity() override; |
| 46 | bool replaceType(TypeIndex &Index, CVType Data, bool Stabilize) override; |
| 47 | |
| 48 | // public interface |
| 49 | void reset(); |
| 50 | TypeIndex nextTypeIndex() const; |
| 51 | |
| 52 | BumpPtrAllocator &getAllocator() { return RecordStorage; } |
| 53 | |
| 54 | ArrayRef<ArrayRef<uint8_t>> records() const; |
| 55 | TypeIndex insertRecordBytes(ArrayRef<uint8_t> &Record); |
| 56 | TypeIndex insertRecord(ContinuationRecordBuilder &Builder); |
| 57 | |
| 58 | template <typename T> TypeIndex writeLeafType(T &Record) { |
| 59 | ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record); |
| 60 | return insertRecordBytes(Data); |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | } // end namespace codeview |
| 65 | } // end namespace llvm |
| 66 | |
| 67 | #endif // LLVM_DEBUGINFO_CODEVIEW_APPENDINGTYPETABLEBUILDER_H |