LLVM  5.0.0
SymbolSerializer.h
Go to the documentation of this file.
1 //===- SymbolSerializer.h ---------------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_DEBUGINFO_CODEVIEW_SYMBOLSERIALIZER_H
11 #define LLVM_DEBUGINFO_CODEVIEW_SYMBOLSERIALIZER_H
12 
13 #include "llvm/ADT/Optional.h"
19 #include "llvm/Support/Allocator.h"
22 #include "llvm/Support/Error.h"
23 #include <cstdint>
24 #include <vector>
25 
26 namespace llvm {
27 namespace codeview {
28 
30  BumpPtrAllocator &Storage;
31  std::vector<uint8_t> RecordBuffer;
33  BinaryStreamWriter Writer;
34  SymbolRecordMapping Mapping;
35  Optional<SymbolKind> CurrentSymbol;
36 
37  Error writeRecordPrefix(SymbolKind Kind) {
39  Prefix.RecordKind = Kind;
40  Prefix.RecordLen = 0;
41  if (auto EC = Writer.writeObject(Prefix))
42  return EC;
43  return Error::success();
44  }
45 
46 public:
48 
49  template <typename SymType>
50  static CVSymbol writeOneSymbol(SymType &Sym, BumpPtrAllocator &Storage,
51  CodeViewContainer Container) {
52  CVSymbol Result;
53  Result.Type = static_cast<SymbolKind>(Sym.Kind);
54  SymbolSerializer Serializer(Storage, Container);
55  consumeError(Serializer.visitSymbolBegin(Result));
56  consumeError(Serializer.visitKnownRecord(Result, Sym));
57  consumeError(Serializer.visitSymbolEnd(Result));
58  return Result;
59  }
60 
63 
64 #define SYMBOL_RECORD(EnumName, EnumVal, Name) \
65  Error visitKnownRecord(CVSymbol &CVR, Name &Record) override { \
66  return visitKnownRecordImpl(CVR, Record); \
67  }
68 #define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
69 #include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
70 
71 private:
72  template <typename RecordKind>
73  Error visitKnownRecordImpl(CVSymbol &CVR, RecordKind &Record) {
74  return Mapping.visitKnownRecord(CVR, Record);
75  }
76 };
77 
78 } // end namespace codeview
79 } // end namespace llvm
80 
81 #endif // LLVM_DEBUGINFO_CODEVIEW_SYMBOLSERIALIZER_H
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer...
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
CVRecord< SymbolKind > CVSymbol
Definition: SymbolRecord.h:945
Error visitSymbolEnd(CVSymbol &Record) override
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:138
Provides write only access to a subclass of WritableBinaryStream.
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:593
static CVSymbol writeOneSymbol(SymType &Sym, BumpPtrAllocator &Storage, CodeViewContainer Container)
static ErrorSuccess success()
Create a success value.
Definition: Error.h:311
SymbolSerializer(BumpPtrAllocator &Storage, CodeViewContainer Container)
Error visitSymbolBegin(CVSymbol &Record) override
SymbolKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:48
const unsigned Kind
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156