LLVM  9.0.0svn
SymbolSerializer.cpp
Go to the documentation of this file.
1 //===- SymbolSerializer.cpp -----------------------------------------------===//
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 
10 #include "llvm/ADT/ArrayRef.h"
12 #include "llvm/Support/Endian.h"
13 #include "llvm/Support/Error.h"
14 #include <cassert>
15 #include <cstdint>
16 #include <cstring>
17 
18 using namespace llvm;
19 using namespace llvm::codeview;
20 
22  CodeViewContainer Container)
23  : Storage(Allocator), Stream(RecordBuffer, support::little), Writer(Stream),
24  Mapping(Writer, Container) {}
25 
27  assert(!CurrentSymbol.hasValue() && "Already in a symbol mapping!");
28 
29  Writer.setOffset(0);
30 
31  if (auto EC = writeRecordPrefix(Record.kind()))
32  return EC;
33 
34  CurrentSymbol = Record.kind();
35  if (auto EC = Mapping.visitSymbolBegin(Record))
36  return EC;
37 
38  return Error::success();
39 }
40 
42  assert(CurrentSymbol.hasValue() && "Not in a symbol mapping!");
43 
44  if (auto EC = Mapping.visitSymbolEnd(Record))
45  return EC;
46 
47  uint32_t RecordEnd = Writer.getOffset();
48  uint16_t Length = RecordEnd - 2;
49  Writer.setOffset(0);
50  if (auto EC = Writer.writeInteger(Length))
51  return EC;
52 
53  uint8_t *StableStorage = Storage.Allocate<uint8_t>(RecordEnd);
54  ::memcpy(StableStorage, &RecordBuffer[0], RecordEnd);
55  Record.RecordData = ArrayRef<uint8_t>(StableStorage, RecordEnd);
56  CurrentSymbol.reset();
57 
58  return Error::success();
59 }
Kind kind() const
Definition: CVRecord.h:43
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Error visitSymbolEnd(CVSymbol &Record) override
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:140
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:214
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:326
SymbolSerializer(BumpPtrAllocator &Storage, CodeViewContainer Container)
void setOffset(uint32_t Off)
bool hasValue() const
Definition: Optional.h:259
ArrayRef< uint8_t > RecordData
Definition: CVRecord.h:61
Error visitSymbolBegin(CVSymbol &Record) override
void reset()
Definition: Optional.h:251
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
Error visitSymbolBegin(CVSymbol &Record) override
CVRecord is a fat pointer (base + size pair) to a symbol or type record.
Definition: CVRecord.h:30