LLVM  14.0.0git
DebugStringTableSubsection.cpp
Go to the documentation of this file.
1 //===- DebugStringTableSubsection.cpp - CodeView String Table -------------===//
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 
10 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/Error.h"
15 #include <algorithm>
16 #include <cassert>
17 #include <cstdint>
18 
19 using namespace llvm;
20 using namespace llvm::codeview;
21 
24 
26  Stream = Contents;
27  return Error::success();
28 }
29 
31  return Reader.readStreamRef(Stream);
32 }
33 
36  BinaryStreamReader Reader(Stream);
37  Reader.setOffset(Offset);
38  StringRef Result;
39  if (auto EC = Reader.readCString(Result))
40  return std::move(EC);
41  return Result;
42 }
43 
46 
48  auto P = StringToId.insert({S, StringSize});
49 
50  // If a given string didn't exist in the string table, we want to increment
51  // the string table size and insert it into the reverse lookup.
52  if (P.second) {
53  IdToString.insert({P.first->getValue(), P.first->getKey()});
54  StringSize += S.size() + 1; // +1 for '\0'
55  }
56 
57  return P.first->second;
58 }
59 
61  return StringSize;
62 }
63 
65  uint32_t Begin = Writer.getOffset();
66  uint32_t End = Begin + StringSize;
67 
68  // Write a null string at the beginning.
69  if (auto EC = Writer.writeCString(StringRef()))
70  return EC;
71 
72  for (auto &Pair : StringToId) {
73  StringRef S = Pair.getKey();
74  uint32_t Offset = Begin + Pair.getValue();
75  Writer.setOffset(Offset);
76  if (auto EC = Writer.writeCString(S))
77  return EC;
78  assert(Writer.getOffset() <= End);
79  }
80 
81  Writer.setOffset(End);
82  assert((End - Begin) == StringSize);
83  return Error::success();
84 }
85 
86 uint32_t DebugStringTableSubsection::size() const { return StringToId.size(); }
87 
88 std::vector<uint32_t> DebugStringTableSubsection::sortedIds() const {
89  std::vector<uint32_t> Result;
90  Result.reserve(IdToString.size());
91  for (const auto &Entry : IdToString)
92  Result.push_back(Entry.first);
93  llvm::sort(Result);
94  return Result;
95 }
96 
98  auto Iter = StringToId.find(S);
99  assert(Iter != StringToId.end());
100  return Iter->second;
101 }
102 
104  auto Iter = IdToString.find(Id);
105  assert(Iter != IdToString.end());
106  return Iter->second;
107 }
BinaryStreamReader.h
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::codeview::DebugStringTableSubsection::calculateSerializedSize
uint32_t calculateSerializedSize() const override
Definition: DebugStringTableSubsection.cpp:60
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::BinaryStreamWriter
Provides write only access to a subclass of WritableBinaryStream.
Definition: BinaryStreamWriter.h:31
llvm::codeview::DebugStringTableSubsection::insert
uint32_t insert(StringRef S)
Definition: DebugStringTableSubsection.cpp:47
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::BinaryStreamReader::setOffset
void setOffset(uint32_t Off)
Definition: BinaryStreamReader.h:254
Error.h
llvm::StringMap::end
iterator end()
Definition: StringMap.h:205
llvm::codeview::DebugStringTableSubsectionRef::DebugStringTableSubsectionRef
DebugStringTableSubsectionRef()
Definition: DebugStringTableSubsection.cpp:22
llvm::codeview::DebugStringTableSubsection::size
uint32_t size() const
Definition: DebugStringTableSubsection.cpp:86
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::codeview::DebugSubsectionKind::StringTable
@ StringTable
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::StringMap::find
iterator find(StringRef Key)
Definition: StringMap.h:218
llvm::codeview::DebugStringTableSubsectionRef::initialize
Error initialize(BinaryStreamRef Contents)
Definition: DebugStringTableSubsection.cpp:25
llvm::StringMap::insert
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:276
llvm::codeview::DebugSubsectionRef
Definition: DebugSubsection.h:19
llvm::BinaryStreamWriter::getOffset
uint32_t getOffset() const
Definition: BinaryStreamWriter.h:184
llvm::BinaryStreamReader::readStreamRef
Error readStreamRef(BinaryStreamRef &Ref)
Read the entire remainder of the underlying stream into Ref.
Definition: BinaryStreamReader.cpp:130
CodeView.h
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:31
llvm::codeview::DebugStringTableSubsection::getStringForId
StringRef getStringForId(uint32_t Id) const
Definition: DebugStringTableSubsection.cpp:103
llvm::BinaryStreamReader::readCString
Error readCString(StringRef &Dest)
Read a null terminated string from Dest.
Definition: BinaryStreamReader.cpp:74
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::BinaryStreamWriter::writeCString
Error writeCString(StringRef Str)
Write the string Str to the underlying stream followed by a null terminator.
Definition: BinaryStreamWriter.cpp:47
llvm::codeview::CompileSym2Flags::EC
@ EC
llvm::StringMapImpl::size
unsigned size() const
Definition: StringMap.h:93
llvm::codeview::DebugStringTableSubsection::sortedIds
std::vector< uint32_t > sortedIds() const
Definition: DebugStringTableSubsection.cpp:88
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
uint32_t
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::codeview::DebugSubsection
Definition: DebugSubsection.h:32
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::codeview::DebugStringTableSubsection::DebugStringTableSubsection
DebugStringTableSubsection()
Definition: DebugStringTableSubsection.cpp:44
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1488
DebugStringTableSubsection.h
llvm::codeview::DebugSubsectionKind
DebugSubsectionKind
Definition: CodeView.h:313
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::codeview::DebugStringTableSubsection::commit
Error commit(BinaryStreamWriter &Writer) const override
Definition: DebugStringTableSubsection.cpp:64
llvm::codeview::DebugStringTableSubsectionRef::getString
Expected< StringRef > getString(uint32_t Offset) const
Definition: DebugStringTableSubsection.cpp:35
llvm::BinaryStreamWriter::setOffset
void setOffset(uint32_t Off)
Definition: BinaryStreamWriter.h:183
BinaryStreamWriter.h
llvm::codeview::DebugStringTableSubsection::getIdForString
uint32_t getIdForString(StringRef S) const
Definition: DebugStringTableSubsection.cpp:97
llvm::AMDGPU::VGPRIndexMode::Id
Id
Definition: SIDefines.h:221
llvm::BinaryStreamRef
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Definition: BinaryStreamRef.h:156