LLVM  14.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/Error.h"
22 #include <cstdint>
23 
24 namespace llvm {
25 namespace codeview {
26 
28  BumpPtrAllocator &Storage;
29  // Since this is a fixed size buffer, use a stack allocated buffer. This
30  // yields measurable performance increase over the repeated heap allocations
31  // when serializing many independent records via writeOneSymbol.
32  std::array<uint8_t, MaxRecordLength> RecordBuffer;
34  BinaryStreamWriter Writer;
35  SymbolRecordMapping Mapping;
36  Optional<SymbolKind> CurrentSymbol;
37 
38  Error writeRecordPrefix(SymbolKind Kind) {
40  Prefix.RecordKind = Kind;
41  Prefix.RecordLen = 0;
42  if (auto EC = Writer.writeObject(Prefix))
43  return EC;
44  return Error::success();
45  }
46 
47 public:
49 
50  template <typename SymType>
51  static CVSymbol writeOneSymbol(SymType &Sym, BumpPtrAllocator &Storage,
52  CodeViewContainer Container) {
53  RecordPrefix Prefix{uint16_t(Sym.Kind)};
54  CVSymbol Result(&Prefix, sizeof(Prefix));
55  SymbolSerializer Serializer(Storage, Container);
56  consumeError(Serializer.visitSymbolBegin(Result));
57  consumeError(Serializer.visitKnownRecord(Result, Sym));
58  consumeError(Serializer.visitSymbolEnd(Result));
59  return Result;
60  }
61 
64 
65 #define SYMBOL_RECORD(EnumName, EnumVal, Name) \
66  Error visitKnownRecord(CVSymbol &CVR, Name &Record) override { \
67  return visitKnownRecordImpl(CVR, Record); \
68  }
69 #define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
70 #include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
71 
72 private:
73  template <typename RecordKind>
74  Error visitKnownRecordImpl(CVSymbol &CVR, RecordKind &Record) {
75  return Mapping.visitKnownRecord(CVR, Record);
76  }
77 };
78 
79 } // end namespace codeview
80 } // end namespace llvm
81 
82 #endif // LLVM_DEBUGINFO_CODEVIEW_SYMBOLSERIALIZER_H
SymbolRecordMapping.h
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
Optional.h
llvm::MutableBinaryByteStream
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer.
Definition: BinaryByteStream.h:89
RecordSerialization.h
llvm::cl::Prefix
@ Prefix
Definition: CommandLine.h:164
BinaryByteStream.h
llvm::codeview::SymbolKind
SymbolKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:47
SymbolRecord.h
llvm::BinaryStreamWriter
Provides write only access to a subclass of WritableBinaryStream.
Definition: BinaryStreamWriter.h:31
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
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:33
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1035
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:51
SymbolVisitorCallbacks.h
llvm::codeview::SymbolSerializer::SymbolSerializer
SymbolSerializer(BumpPtrAllocator &Storage, CodeViewContainer Container)
Definition: SymbolSerializer.cpp:21
llvm::codeview::SymbolSerializer
Definition: SymbolSerializer.h:27
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:67
llvm::codeview::CompileSym2Flags::EC
@ EC
llvm::Record
Definition: Record.h:1472
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::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:157
llvm::codeview::CodeViewContainer
CodeViewContainer
Definition: CodeView.h:607
BinaryStreamWriter.h