Zachary Turner | 407dec5 | 2017-03-13 14:57:45 +0000 | [diff] [blame] | 1 | //===- SymbolSerializer.cpp -------------------------------------*- 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 | #include "llvm/DebugInfo/CodeView/SymbolSerializer.h" |
| 11 | |
| 12 | using namespace llvm; |
| 13 | using namespace llvm::codeview; |
| 14 | |
Zachary Turner | ebd3ae8 | 2017-06-01 21:52:41 +0000 | [diff] [blame^] | 15 | SymbolSerializer::SymbolSerializer(BumpPtrAllocator &Allocator, |
| 16 | CodeViewContainer Container) |
| 17 | : Storage(Allocator), RecordBuffer(MaxRecordLength), |
| 18 | Stream(RecordBuffer, llvm::support::little), Writer(Stream), |
| 19 | Mapping(Writer, Container) {} |
Zachary Turner | 407dec5 | 2017-03-13 14:57:45 +0000 | [diff] [blame] | 20 | |
| 21 | Error SymbolSerializer::visitSymbolBegin(CVSymbol &Record) { |
| 22 | assert(!CurrentSymbol.hasValue() && "Already in a symbol mapping!"); |
| 23 | |
| 24 | Writer.setOffset(0); |
| 25 | |
| 26 | if (auto EC = writeRecordPrefix(Record.kind())) |
| 27 | return EC; |
| 28 | |
| 29 | CurrentSymbol = Record.kind(); |
| 30 | if (auto EC = Mapping.visitSymbolBegin(Record)) |
| 31 | return EC; |
| 32 | |
| 33 | return Error::success(); |
| 34 | } |
| 35 | |
| 36 | Error SymbolSerializer::visitSymbolEnd(CVSymbol &Record) { |
| 37 | assert(CurrentSymbol.hasValue() && "Not in a symbol mapping!"); |
| 38 | |
| 39 | if (auto EC = Mapping.visitSymbolEnd(Record)) |
| 40 | return EC; |
| 41 | |
| 42 | uint32_t RecordEnd = Writer.getOffset(); |
| 43 | uint16_t Length = RecordEnd - 2; |
| 44 | Writer.setOffset(0); |
| 45 | if (auto EC = Writer.writeInteger(Length)) |
| 46 | return EC; |
| 47 | |
| 48 | uint8_t *StableStorage = Storage.Allocate<uint8_t>(RecordEnd); |
| 49 | ::memcpy(StableStorage, &RecordBuffer[0], RecordEnd); |
| 50 | Record.RecordData = ArrayRef<uint8_t>(StableStorage, RecordEnd); |
| 51 | CurrentSymbol.reset(); |
| 52 | |
| 53 | return Error::success(); |
| 54 | } |