LLVM 18.0.0git
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"
11#include "llvm/Support/Endian.h"
12#include "llvm/Support/Error.h"
14#include <cassert>
15#include <cstdint>
16#include <cstring>
17
18using namespace llvm;
19using namespace llvm::codeview;
20
22 CodeViewContainer Container)
23 : Storage(Allocator), Stream(RecordBuffer, support::little), Writer(Stream),
24 Mapping(Writer, Container) {}
25
27 assert(!CurrentSymbol && "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 && "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}
Basic Register Allocator
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Error writeInteger(T Value)
Write the integer Value to the underlying stream in the specified endianness.
void setOffset(uint64_t Off)
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:148
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:334
CVRecord is a fat pointer (base + size pair) to a symbol or type record.
Definition: CVRecord.h:29
Error visitSymbolEnd(CVSymbol &Record) override
Error visitSymbolBegin(CVSymbol &Record) override
Error visitSymbolBegin(CVSymbol &Record) override
SymbolSerializer(BumpPtrAllocator &Storage, CodeViewContainer Container)
Error visitSymbolEnd(CVSymbol &Record) override
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Length
Definition: DWP.cpp:440