LLVM  5.0.0
SymbolSerializer.cpp
Go to the documentation of this file.
1 //===- SymbolSerializer.cpp -----------------------------------------------===//
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 
11 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/Support/Endian.h"
14 #include "llvm/Support/Error.h"
15 #include <cassert>
16 #include <cstdint>
17 #include <cstring>
18 
19 using namespace llvm;
20 using namespace llvm::codeview;
21 
23  CodeViewContainer Container)
24  : Storage(Allocator), RecordBuffer(MaxRecordLength),
25  Stream(RecordBuffer, support::little), Writer(Stream),
26  Mapping(Writer, Container) {}
27 
29  assert(!CurrentSymbol.hasValue() && "Already in a symbol mapping!");
30 
31  Writer.setOffset(0);
32 
33  if (auto EC = writeRecordPrefix(Record.kind()))
34  return EC;
35 
36  CurrentSymbol = Record.kind();
37  if (auto EC = Mapping.visitSymbolBegin(Record))
38  return EC;
39 
40  return Error::success();
41 }
42 
44  assert(CurrentSymbol.hasValue() && "Not in a symbol mapping!");
45 
46  if (auto EC = Mapping.visitSymbolEnd(Record))
47  return EC;
48 
49  uint32_t RecordEnd = Writer.getOffset();
50  uint16_t Length = RecordEnd - 2;
51  Writer.setOffset(0);
52  if (auto EC = Writer.writeInteger(Length))
53  return EC;
54 
55  uint8_t *StableStorage = Storage.Allocate<uint8_t>(RecordEnd);
56  ::memcpy(StableStorage, &RecordBuffer[0], RecordEnd);
57  Record.RecordData = ArrayRef<uint8_t>(StableStorage, RecordEnd);
58  CurrentSymbol.reset();
59 
60  return Error::success();
61 }
bool hasValue() const
Definition: Optional.h:133
Kind kind() const
Definition: CVRecord.h:37
Error visitSymbolEnd(CVSymbol &Record) override
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:138
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, size_t Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:212
Error writeInteger(T Value)
Write the the integer Value to the underlying stream in the specified endianness. ...
Error visitSymbolEnd(CVSymbol &Record) override
Basic Register Allocator
static ErrorSuccess success()
Create a success value.
Definition: Error.h:311
SymbolSerializer(BumpPtrAllocator &Storage, CodeViewContainer Container)
void setOffset(uint32_t Off)
ArrayRef< uint8_t > RecordData
Definition: CVRecord.h:53
Error visitSymbolBegin(CVSymbol &Record) override
void reset()
Definition: Optional.h:120
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
Error visitSymbolBegin(CVSymbol &Record) override