[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / lib / DebugInfo / CodeView / SimpleTypeSerializer.cpp
blobac3b30175956e76044c9782f47023bf09ded7277
1 //===- SimpleTypeSerializer.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 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/CodeView/SimpleTypeSerializer.h"
10 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
11 #include "llvm/DebugInfo/CodeView/TypeRecordMapping.h"
12 #include "llvm/Support/BinaryStreamWriter.h"
14 using namespace llvm;
15 using namespace llvm::codeview;
17 static void addPadding(BinaryStreamWriter &Writer) {
18 uint32_t Align = Writer.getOffset() % 4;
19 if (Align == 0)
20 return;
22 int PaddingBytes = 4 - Align;
23 while (PaddingBytes > 0) {
24 uint8_t Pad = static_cast<uint8_t>(LF_PAD0 + PaddingBytes);
25 cantFail(Writer.writeInteger(Pad));
26 --PaddingBytes;
30 SimpleTypeSerializer::SimpleTypeSerializer() : ScratchBuffer(MaxRecordLength) {}
32 SimpleTypeSerializer::~SimpleTypeSerializer() {}
34 template <typename T>
35 ArrayRef<uint8_t> SimpleTypeSerializer::serialize(T &Record) {
36 BinaryStreamWriter Writer(ScratchBuffer, support::little);
37 TypeRecordMapping Mapping(Writer);
39 // Write the record prefix first with a dummy length but real kind.
40 RecordPrefix DummyPrefix(uint16_t(Record.getKind()));
41 cantFail(Writer.writeObject(DummyPrefix));
43 RecordPrefix *Prefix = reinterpret_cast<RecordPrefix *>(ScratchBuffer.data());
44 CVType CVT(Prefix, sizeof(RecordPrefix));
46 cantFail(Mapping.visitTypeBegin(CVT));
47 cantFail(Mapping.visitKnownRecord(CVT, Record));
48 cantFail(Mapping.visitTypeEnd(CVT));
50 addPadding(Writer);
52 // Update the size and kind after serialization.
53 Prefix->RecordKind = CVT.kind();
54 Prefix->RecordLen = Writer.getOffset() - sizeof(uint16_t);
56 return {ScratchBuffer.data(), Writer.getOffset()};
59 // Explicitly instantiate the member function for each known type so that we can
60 // implement this in the cpp file.
61 #define TYPE_RECORD(EnumName, EnumVal, Name) \
62 template ArrayRef<uint8_t> llvm::codeview::SimpleTypeSerializer::serialize( \
63 Name##Record &Record);
64 #define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
65 #define MEMBER_RECORD(EnumName, EnumVal, Name)
66 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
67 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"