LLVM  14.0.0git
DebugCrossImpSubsection.cpp
Go to the documentation of this file.
1 //===- DebugCrossImpSubsection.cpp ----------------------------------------===//
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/ArrayRef.h"
15 #include "llvm/Support/Endian.h"
16 #include "llvm/Support/Error.h"
17 #include <algorithm>
18 #include <cstdint>
19 #include <utility>
20 #include <vector>
21 
22 using namespace llvm;
23 using namespace llvm::codeview;
24 
28  BinaryStreamReader Reader(Stream);
29  if (Reader.bytesRemaining() < sizeof(CrossModuleImport))
30  return make_error<CodeViewError>(
32  "Not enough bytes for a Cross Module Import Header!");
33  if (auto EC = Reader.readObject(Item.Header))
34  return EC;
35  if (Reader.bytesRemaining() < Item.Header->Count * sizeof(uint32_t))
36  return make_error<CodeViewError>(
38  "Not enough to read specified number of Cross Module References!");
39  if (auto EC = Reader.readArray(Item.Imports, Item.Header->Count))
40  return EC;
41  return Error::success();
42 }
43 
45  BinaryStreamReader Reader) {
46  return Reader.readArray(References, Reader.bytesRemaining());
47 }
48 
50  BinaryStreamReader Reader(Stream);
51  return initialize(Reader);
52 }
53 
55  uint32_t ImportId) {
56  Strings.insert(Module);
57  std::vector<support::ulittle32_t> Targets = {support::ulittle32_t(ImportId)};
58  auto Result = Mappings.insert(std::make_pair(Module, Targets));
59  if (!Result.second)
60  Result.first->getValue().push_back(Targets[0]);
61 }
62 
64  uint32_t Size = 0;
65  for (const auto &Item : Mappings) {
66  Size += sizeof(CrossModuleImport);
67  Size += sizeof(support::ulittle32_t) * Item.second.size();
68  }
69  return Size;
70 }
71 
73  BinaryStreamWriter &Writer) const {
74  using T = decltype(&*Mappings.begin());
75  std::vector<T> Ids;
76  Ids.reserve(Mappings.size());
77 
78  for (const auto &M : Mappings)
79  Ids.push_back(&M);
80 
81  llvm::sort(Ids, [this](const T &L1, const T &L2) {
82  return Strings.getIdForString(L1->getKey()) <
83  Strings.getIdForString(L2->getKey());
84  });
85 
86  for (const auto &Item : Ids) {
88  Imp.ModuleNameOffset = Strings.getIdForString(Item->getKey());
89  Imp.Count = Item->getValue().size();
90  if (auto EC = Writer.writeObject(Imp))
91  return EC;
92  if (auto EC = Writer.writeArray(makeArrayRef(Item->getValue())))
93  return EC;
94  }
95  return Error::success();
96 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
BinaryStreamReader.h
llvm::BinaryStreamReader::bytesRemaining
uint32_t bytesRemaining() const
Definition: BinaryStreamReader.h:257
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::codeview::DebugCrossModuleImportsSubsectionRef::initialize
Error initialize(BinaryStreamReader Reader)
Definition: DebugCrossImpSubsection.cpp:44
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
Error.h
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::BinaryStreamWriter::writeArray
Error writeArray(ArrayRef< T > Array)
Writes an array of objects of type T to the underlying stream, as if by using memcpy.
Definition: BinaryStreamWriter.h:151
llvm::codeview::cv_error_code::insufficient_buffer
@ insufficient_buffer
llvm::codeview::CrossModuleImportItem
Definition: DebugCrossImpSubsection.h:28
llvm::codeview::CrossModuleImport::ModuleNameOffset
support::ulittle32_t ModuleNameOffset
Definition: CodeView.h:602
llvm::codeview::CrossModuleImportItem::Imports
FixedStreamArray< support::ulittle32_t > Imports
Definition: DebugCrossImpSubsection.h:30
llvm::codeview::CrossModuleImport
Definition: CodeView.h:601
L2
add sub stmia L5 ldr L2
Definition: README.txt:201
llvm::codeview::DebugCrossModuleImportsSubsection::calculateSerializedSize
uint32_t calculateSerializedSize() const override
Definition: DebugCrossImpSubsection.cpp:63
llvm::codeview::CrossModuleImportItem::Header
const CrossModuleImport * Header
Definition: DebugCrossImpSubsection.h:29
llvm::VarStreamArrayExtractor::operator()
Error operator()(BinaryStreamRef Stream, uint32_t &Len, T &Item) const =delete
Definition: DebugChecksumsSubsection.cpp:35
llvm::codeview::CrossModuleImport::Count
support::ulittle32_t Count
Definition: CodeView.h:603
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:31
llvm::support::ulittle32_t
detail::packed_endian_specific_integral< uint32_t, little, unaligned > ulittle32_t
Definition: Endian.h:272
ArrayRef.h
llvm::codeview::CompileSym2Flags::EC
@ EC
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::codeview::DebugCrossModuleImportsSubsection::commit
Error commit(BinaryStreamWriter &Writer) const override
Definition: DebugCrossImpSubsection.cpp:72
llvm::BinaryStreamWriter::writeObject
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
Definition: BinaryStreamWriter.h:135
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
uint32_t
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
DebugCrossImpSubsection.h
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1488
DebugStringTableSubsection.h
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:476
BinaryStreamWriter.h
llvm::codeview::DebugStringTableSubsection::getIdForString
uint32_t getIdForString(StringRef S) const
Definition: DebugStringTableSubsection.cpp:97
CodeViewError.h
Endian.h
llvm::BinaryStreamReader::readArray
Error readArray(ArrayRef< T > &Array, uint32_t NumElements)
Get a reference to a NumElements element array of objects of type T from the underlying stream as if ...
Definition: BinaryStreamReader.h:187
llvm::BinaryStreamRef
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Definition: BinaryStreamRef.h:156
llvm::codeview::DebugCrossModuleImportsSubsection::addImport
void addImport(StringRef Module, uint32_t ImportId)
Definition: DebugCrossImpSubsection.cpp:54