LLVM  8.0.1
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), Stream(RecordBuffer, support::little), Writer(Stream),
25  Mapping(Writer, Container) {}
26 
28  assert(!CurrentSymbol.hasValue() && "Already in a symbol mapping!");
29 
30  Writer.setOffset(0);
31 
32  if (auto EC = writeRecordPrefix(Record.kind()))
33  return EC;
34 
35  CurrentSymbol = Record.kind();
36  if (auto EC = Mapping.visitSymbolBegin(Record))
37  return EC;
38 
39  return Error::success();
40 }
41 
43  assert(CurrentSymbol.hasValue() && "Not in a symbol mapping!");
44 
45  if (auto EC = Mapping.visitSymbolEnd(Record))
46  return EC;
47 
48  uint32_t RecordEnd = Writer.getOffset();
49  uint16_t Length = RecordEnd - 2;
50  Writer.setOffset(0);
51  if (auto EC = Writer.writeInteger(Length))
52  return EC;
53 
54  uint8_t *StableStorage = Storage.Allocate<uint8_t>(RecordEnd);
55  ::memcpy(StableStorage, &RecordBuffer[0], RecordEnd);
56  Record.RecordData = ArrayRef<uint8_t>(StableStorage, RecordEnd);
57  CurrentSymbol.reset();
58 
59  return Error::success();
60 }
Kind kind() const
Definition: CVRecord.h:37
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Error visitSymbolEnd(CVSymbol &Record) override
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:141
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:215
Error writeInteger(T Value)
Write 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:327
SymbolSerializer(BumpPtrAllocator &Storage, CodeViewContainer Container)
void setOffset(uint32_t Off)
bool hasValue() const
Definition: Optional.h:165
ArrayRef< uint8_t > RecordData
Definition: CVRecord.h:49
Error visitSymbolBegin(CVSymbol &Record) override
void reset()
Definition: Optional.h:151
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158
Error visitSymbolBegin(CVSymbol &Record) override