LLVM  15.0.0git
SymbolSerializer.h
Go to the documentation of this file.
1 //===- SymbolSerializer.h ---------------------------------------*- C++ -*-===//
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 
9 #ifndef LLVM_DEBUGINFO_CODEVIEW_SYMBOLSERIALIZER_H
10 #define LLVM_DEBUGINFO_CODEVIEW_SYMBOLSERIALIZER_H
11 
12 #include "llvm/ADT/Optional.h"
18 #include "llvm/Support/Allocator.h"
21 #include "llvm/Support/Endian.h"
22 #include "llvm/Support/Error.h"
23 #include <array>
24 #include <cstdint>
25 
26 namespace llvm {
27 namespace codeview {
28 
30  BumpPtrAllocator &Storage;
31  // Since this is a fixed size buffer, use a stack allocated buffer. This
32  // yields measurable performance increase over the repeated heap allocations
33  // when serializing many independent records via writeOneSymbol.
34  std::array<uint8_t, MaxRecordLength> RecordBuffer;
36  BinaryStreamWriter Writer;
37  SymbolRecordMapping Mapping;
38  Optional<SymbolKind> CurrentSymbol;
39 
40  Error writeRecordPrefix(SymbolKind Kind) {
42  Prefix.RecordKind = Kind;
43  Prefix.RecordLen = 0;
44  if (auto EC = Writer.writeObject(Prefix))
45  return EC;
46  return Error::success();
47  }
48 
49 public:
51 
52  template <typename SymType>
53  static CVSymbol writeOneSymbol(SymType &Sym, BumpPtrAllocator &Storage,
54  CodeViewContainer Container) {
55  RecordPrefix Prefix{uint16_t(Sym.Kind)};
56  CVSymbol Result(&Prefix, sizeof(Prefix));
57  SymbolSerializer Serializer(Storage, Container);
58  consumeError(Serializer.visitSymbolBegin(Result));
59  consumeError(Serializer.visitKnownRecord(Result, Sym));
60  consumeError(Serializer.visitSymbolEnd(Result));
61  return Result;
62  }
63 
66 
67 #define SYMBOL_RECORD(EnumName, EnumVal, Name) \
68  Error visitKnownRecord(CVSymbol &CVR, Name &Record) override { \
69  return visitKnownRecordImpl(CVR, Record); \
70  }
71 #define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
72 #include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
73 
74 private:
75  template <typename RecordKind>
76  Error visitKnownRecordImpl(CVSymbol &CVR, RecordKind &Record) {
77  return Mapping.visitKnownRecord(CVR, Record);
78  }
79 };
80 
81 } // end namespace codeview
82 } // end namespace llvm
83 
84 #endif // LLVM_DEBUGINFO_CODEVIEW_SYMBOLSERIALIZER_H
SymbolRecordMapping.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
Optional.h
llvm::MutableBinaryByteStream
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer.
Definition: BinaryByteStream.h:88
RecordSerialization.h
llvm::cl::Prefix
@ Prefix
Definition: CommandLine.h:160
BinaryByteStream.h
llvm::codeview::SymbolKind
SymbolKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:47
llvm::BinaryStreamWriter
Provides write only access to a subclass of WritableBinaryStream.
Definition: BinaryStreamWriter.h:30
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
Allocator.h
Error.h
llvm::Optional< SymbolKind >
llvm::codeview::SymbolSerializer::visitSymbolBegin
Error visitSymbolBegin(CVSymbol &Record) override
Definition: SymbolSerializer.cpp:26
llvm::codeview::RecordPrefix
Definition: RecordSerialization.h:32
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1043
llvm::codeview::SymbolRecordMapping
Definition: SymbolRecordMapping.h:20
llvm::codeview::SymbolSerializer::visitSymbolEnd
Error visitSymbolEnd(CVSymbol &Record) override
Definition: SymbolSerializer.cpp:41
llvm::codeview::CVSymbol
CVRecord< SymbolKind > CVSymbol
Definition: CVRecord.h:65
llvm::codeview::SymbolSerializer::writeOneSymbol
static CVSymbol writeOneSymbol(SymType &Sym, BumpPtrAllocator &Storage, CodeViewContainer Container)
Definition: SymbolSerializer.h:53
SymbolVisitorCallbacks.h
llvm::codeview::SymbolSerializer::SymbolSerializer
SymbolSerializer(BumpPtrAllocator &Storage, CodeViewContainer Container)
Definition: SymbolSerializer.cpp:21
llvm::codeview::SymbolSerializer
Definition: SymbolSerializer.h:29
CodeView.h
llvm::codeview::SymbolVisitorCallbacks
Definition: SymbolVisitorCallbacks.h:18
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:63
llvm::codeview::CompileSym2Flags::EC
@ EC
llvm::Record
Definition: Record.h:1543
llvm::BinaryStreamWriter::writeObject
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
Definition: BinaryStreamWriter.h:129
llvm::codeview::CVRecord
CVRecord is a fat pointer (base + size pair) to a symbol or type record.
Definition: CVRecord.h:29
uint16_t
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
CVRecord.h
llvm::codeview::CodeViewContainer
CodeViewContainer
Definition: CodeView.h:609
BinaryStreamWriter.h
Endian.h