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