LLVM  6.0.0svn
DebugStringTableSubsection.cpp
Go to the documentation of this file.
1 //===- DebugStringTableSubsection.cpp - CodeView String Table -------------===//
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 
11 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/Error.h"
16 #include <algorithm>
17 #include <cassert>
18 #include <cstdint>
19 
20 using namespace llvm;
21 using namespace llvm::codeview;
22 
25 
27  Stream = Contents;
28  return Error::success();
29 }
30 
32  return Reader.readStreamRef(Stream);
33 }
34 
37  BinaryStreamReader Reader(Stream);
38  Reader.setOffset(Offset);
39  StringRef Result;
40  if (auto EC = Reader.readCString(Result))
41  return std::move(EC);
42  return Result;
43 }
44 
47 
49  auto P = Strings.insert({S, StringSize});
50 
51  // If a given string didn't exist in the string table, we want to increment
52  // the string table size.
53  if (P.second)
54  StringSize += S.size() + 1; // +1 for '\0'
55  return P.first->second;
56 }
57 
59  return StringSize;
60 }
61 
63  uint32_t Begin = Writer.getOffset();
64  uint32_t End = Begin + StringSize;
65 
66  // Write a null string at the beginning.
67  if (auto EC = Writer.writeCString(StringRef()))
68  return EC;
69 
70  for (auto &Pair : Strings) {
71  StringRef S = Pair.getKey();
72  uint32_t Offset = Begin + Pair.getValue();
73  Writer.setOffset(Offset);
74  if (auto EC = Writer.writeCString(S))
75  return EC;
76  assert(Writer.getOffset() <= End);
77  }
78 
79  Writer.setOffset(End);
80  assert((End - Begin) == StringSize);
81  return Error::success();
82 }
83 
84 uint32_t DebugStringTableSubsection::size() const { return Strings.size(); }
85 
87  auto Iter = Strings.find(S);
88  assert(Iter != Strings.end());
89  return Iter->second;
90 }
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
iterator find(StringRef Key)
Definition: StringMap.h:337
Error commit(BinaryStreamWriter &Writer) const override
Expected< StringRef > getString(uint32_t Offset) const
unsigned size() const
Definition: StringMap.h:112
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
Error readCString(StringRef &Dest)
Read a null terminated string from Dest.
#define P(N)
Provides write only access to a subclass of WritableBinaryStream.
static const unsigned End
Error writeCString(StringRef Str)
Write the the string Str to the underlying stream followed by a null terminator.
void setOffset(uint32_t Off)
static ErrorSuccess success()
Create a success value.
Definition: Error.h:313
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:370
void setOffset(uint32_t Off)
Error readStreamRef(BinaryStreamRef &Ref)
Read the entire remainder of the underlying stream into Ref.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
Provides read only access to a subclass of BinaryStream.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
iterator end()
Definition: StringMap.h:322