LLVM CodeView library
[oota-llvm.git] / include / llvm / DebugInfo / CodeView / MemoryTypeTableBuilder.h
1 //===- MemoryTypeTableBuilder.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_MEMORYTYPETABLEBUILDER_H
11 #define LLVM_DEBUGINFO_CODEVIEW_MEMORYTYPETABLEBUILDER_H
12
13 #include "llvm/ADT/Hashing.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/DebugInfo/CodeView/TypeTableBuilder.h"
16 #include <functional>
17 #include <memory>
18 #include <unordered_map>
19 #include <vector>
20
21 namespace llvm {
22 namespace codeview {
23
24 class MemoryTypeTableBuilder : public TypeTableBuilder {
25 public:
26   class Record {
27   public:
28     explicit Record(llvm::StringRef RData);
29
30     const char *data() const { return Data.get(); }
31     uint16_t size() const { return Size; }
32
33   private:
34     uint16_t Size;
35     std::unique_ptr<char[]> Data;
36   };
37
38 private:
39   class RecordHash : std::unary_function<llvm::StringRef, size_t> {
40   public:
41     size_t operator()(llvm::StringRef Val) const {
42       return static_cast<size_t>(llvm::hash_value(Val));
43     }
44   };
45
46 public:
47   MemoryTypeTableBuilder() {}
48
49   template <typename TFunc> void ForEachRecord(TFunc Func) {
50     uint32_t Index = TypeIndex::FirstNonSimpleIndex;
51
52     for (const std::unique_ptr<Record> &R : Records) {
53       Func(TypeIndex(Index), R.get());
54       ++Index;
55     }
56   }
57
58 private:
59   virtual TypeIndex writeRecord(llvm::StringRef Data) override;
60
61 private:
62   std::vector<std::unique_ptr<Record>> Records;
63   std::unordered_map<llvm::StringRef, TypeIndex, RecordHash> HashedRecords;
64 };
65 }
66 }
67
68 #endif