LLVM CodeView library
[oota-llvm.git] / lib / DebugInfo / CodeView / MemoryTypeTableBuilder.cpp
1 //===-- MemoryTypeTableBuilder.cpp ----------------------------------------===//
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 #include "llvm/DebugInfo/CodeView/MemoryTypeTableBuilder.h"
11 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
12
13 using namespace llvm;
14 using namespace codeview;
15
16 MemoryTypeTableBuilder::Record::Record(StringRef RData)
17     : Size(RData.size()), Data(new char[RData.size()]) {
18   memcpy(Data.get(), RData.data(), RData.size());
19 }
20
21 TypeIndex MemoryTypeTableBuilder::writeRecord(StringRef Data) {
22   auto I = HashedRecords.find(Data);
23   if (I != HashedRecords.end()) {
24     return I->second;
25   }
26
27   std::unique_ptr<Record> R(new Record(Data));
28
29   TypeIndex TI(static_cast<uint32_t>(Records.size()) +
30                TypeIndex::FirstNonSimpleIndex);
31   HashedRecords.insert(std::make_pair(StringRef(R->data(), R->size()), TI));
32   Records.push_back(std::move(R));
33
34   return TI;
35 }