From c573acd9e96b850cee9d9cf148e8831f004fbe62 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Thu, 23 Mar 2017 00:14:23 +0000 Subject: [PATCH] [codeview] Move type index remapping logic to type merger Summary: This removes the 'remapTypeIndices' method on every TypeRecord class. My original idea was that this would be the beginning of some kind of generic entry point that would enumerate all of the TypeIndices inside of a TypeRecord, so that we could write generic graph algorithms for them without duplicating the knowledge of which fields are type index fields everywhere. This never happened, and nothing else uses this method. I need to change the API to deal with merging into IPI streams, so let's move it into the file that uses it first. Reviewers: zturner, ruiu Reviewed By: zturner, ruiu Subscribers: mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D31267 llvm-svn: 298564 --- llvm/include/llvm/DebugInfo/CodeView/TypeRecord.h | 127 ----------- llvm/lib/DebugInfo/CodeView/CMakeLists.txt | 1 - llvm/lib/DebugInfo/CodeView/TypeRecord.cpp | 220 ------------------- llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp | 246 +++++++++++++++++++--- 4 files changed, 219 insertions(+), 375 deletions(-) delete mode 100644 llvm/lib/DebugInfo/CodeView/TypeRecord.cpp diff --git a/llvm/include/llvm/DebugInfo/CodeView/TypeRecord.h b/llvm/include/llvm/DebugInfo/CodeView/TypeRecord.h index 64e30af..aa70cff 100644 --- a/llvm/include/llvm/DebugInfo/CodeView/TypeRecord.h +++ b/llvm/include/llvm/DebugInfo/CodeView/TypeRecord.h @@ -105,10 +105,6 @@ public: PointerToMemberRepresentation Representation) : ContainingType(ContainingType), Representation(Representation) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - TypeIndex getContainingType() const { return ContainingType; } PointerToMemberRepresentation getRepresentation() const { return Representation; @@ -138,10 +134,6 @@ public: : TypeRecord(TypeRecordKind::Modifier), ModifiedType(ModifiedType), Modifiers(Modifiers) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - TypeIndex getModifiedType() const { return ModifiedType; } ModifierOptions getModifiers() const { return Modifiers; } @@ -160,10 +152,6 @@ public: CallConv(CallConv), Options(Options), ParameterCount(ParameterCount), ArgumentList(ArgumentList) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - TypeIndex getReturnType() const { return ReturnType; } CallingConvention getCallConv() const { return CallConv; } FunctionOptions getOptions() const { return Options; } @@ -192,10 +180,6 @@ public: ArgumentList(ArgumentList), ThisPointerAdjustment(ThisPointerAdjustment) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - TypeIndex getReturnType() const { return ReturnType; } TypeIndex getClassType() const { return ClassType; } TypeIndex getThisType() const { return ThisType; } @@ -224,10 +208,6 @@ public: : TypeRecord(TypeRecordKind::MemberFuncId), ClassType(ClassType), FunctionType(FunctionType), Name(Name) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - TypeIndex getClassType() const { return ClassType; } TypeIndex getFunctionType() const { return FunctionType; } StringRef getName() const { return Name; } @@ -244,10 +224,6 @@ public: ArgListRecord(TypeRecordKind Kind, ArrayRef Indices) : TypeRecord(Kind), ArgIndices(Indices) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - ArrayRef getIndices() const { return ArgIndices; } std::vector ArgIndices; @@ -261,10 +237,6 @@ public: StringListRecord(TypeRecordKind Kind, ArrayRef Indices) : TypeRecord(Kind), StringIndices(Indices) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - ArrayRef getIndices() const { return StringIndices; } std::vector StringIndices; @@ -306,10 +278,6 @@ public: : TypeRecord(TypeRecordKind::Pointer), ReferentType(ReferentType), Attrs(Attrs), MemberInfo(Member) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - TypeIndex getReferentType() const { return ReferentType; } PointerKind getPointerKind() const { @@ -372,10 +340,6 @@ public: NestedTypeRecord(TypeIndex Type, StringRef Name) : TypeRecord(TypeRecordKind::NestedType), Type(Type), Name(Name) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - TypeIndex getNestedType() const { return Type; } StringRef getName() const { return Name; } @@ -390,10 +354,6 @@ public: explicit FieldListRecord(ArrayRef Data) : TypeRecord(TypeRecordKind::FieldList), Data(Data) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap) { return false; } - ArrayRef Data; }; @@ -406,10 +366,6 @@ public: : TypeRecord(TypeRecordKind::Array), ElementType(ElementType), IndexType(IndexType), Size(Size), Name(Name) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - TypeIndex getElementType() const { return ElementType; } TypeIndex getIndexType() const { return IndexType; } uint64_t getSize() const { return Size; } @@ -430,10 +386,6 @@ protected: FieldList(FieldList), Name(Name), UniqueName(UniqueName) {} public: - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - static const int HfaKindShift = 11; static const int HfaKindMask = 0x1800; static const int WinRTKindShift = 14; @@ -467,10 +419,6 @@ public: : TagRecord(Kind, MemberCount, Options, FieldList, Name, UniqueName), DerivationList(DerivationList), VTableShape(VTableShape), Size(Size) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - HfaKind getHfa() const { uint16_t Value = static_cast(Options); Value = (Value & HfaKindMask) >> HfaKindShift; @@ -522,9 +470,6 @@ public: UniqueName), UnderlyingType(UnderlyingType) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - TypeIndex getUnderlyingType() const { return UnderlyingType; } TypeIndex UnderlyingType; }; @@ -537,10 +482,6 @@ public: : TypeRecord(TypeRecordKind::BitField), Type(Type), BitSize(BitSize), BitOffset(BitOffset) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - TypeIndex getType() const { return Type; } uint8_t getBitOffset() const { return BitOffset; } uint8_t getBitSize() const { return BitSize; } @@ -558,10 +499,6 @@ public: explicit VFTableShapeRecord(std::vector Slots) : TypeRecord(TypeRecordKind::VFTableShape), Slots(std::move(Slots)) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - ArrayRef getSlots() const { if (!SlotsRef.empty()) return SlotsRef; @@ -581,10 +518,6 @@ public: : TypeRecord(TypeRecordKind::TypeServer2), Guid(Guid), Age(Age), Name(Name) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - StringRef getGuid() const { return Guid; } uint32_t getAge() const { return Age; } @@ -603,10 +536,6 @@ public: StringIdRecord(TypeIndex Id, StringRef String) : TypeRecord(TypeRecordKind::StringId), Id(Id), String(String) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - TypeIndex getId() const { return Id; } StringRef getString() const { return String; } @@ -622,10 +551,6 @@ public: : TypeRecord(TypeRecordKind::FuncId), ParentScope(ParentScope), FunctionType(FunctionType), Name(Name) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - TypeIndex getParentScope() const { return ParentScope; } TypeIndex getFunctionType() const { return FunctionType; } @@ -645,10 +570,6 @@ public: : TypeRecord(TypeRecordKind::UdtSourceLine), UDT(UDT), SourceFile(SourceFile), LineNumber(LineNumber) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - TypeIndex getUDT() const { return UDT; } TypeIndex getSourceFile() const { return SourceFile; } uint32_t getLineNumber() const { return LineNumber; } @@ -667,8 +588,6 @@ public: : TypeRecord(TypeRecordKind::UdtSourceLine), UDT(UDT), SourceFile(SourceFile), LineNumber(LineNumber), Module(Module) {} - bool remapTypeIndices(ArrayRef IndexMap); - TypeIndex getUDT() const { return UDT; } TypeIndex getSourceFile() const { return SourceFile; } uint32_t getLineNumber() const { return LineNumber; } @@ -688,10 +607,6 @@ public: : TypeRecord(TypeRecordKind::BuildInfo), ArgIndices(ArgIndices.begin(), ArgIndices.end()) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - ArrayRef getArgs() const { return ArgIndices; } SmallVector ArgIndices; }; @@ -709,10 +624,6 @@ public: MethodNames.insert(MethodNames.end(), Methods.begin(), Methods.end()); } - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - TypeIndex getCompleteClass() const { return CompleteClass; } TypeIndex getOverriddenVTable() const { return OverriddenVFTable; } uint32_t getVFPtrOffset() const { return VFPtrOffset; } @@ -741,10 +652,6 @@ public: : TypeRecord(TypeRecordKind::OneMethod), Type(Type), Attrs(Access, MK, Options), VFTableOffset(VFTableOffset), Name(Name) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - TypeIndex getType() const { return Type; } MethodKind getMethodKind() const { return Attrs.getMethodKind(); } MethodOptions getOptions() const { return Attrs.getFlags(); } @@ -770,10 +677,6 @@ public: MethodOverloadListRecord(ArrayRef Methods) : TypeRecord(TypeRecordKind::MethodOverloadList), Methods(Methods) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - ArrayRef getMethods() const { return Methods; } std::vector Methods; }; @@ -787,10 +690,6 @@ public: : TypeRecord(TypeRecordKind::OverloadedMethod), NumOverloads(NumOverloads), MethodList(MethodList), Name(Name) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - uint16_t getNumOverloads() const { return NumOverloads; } TypeIndex getMethodList() const { return MethodList; } StringRef getName() const { return Name; } @@ -812,10 +711,6 @@ public: : TypeRecord(TypeRecordKind::DataMember), Attrs(Access), Type(Type), FieldOffset(Offset), Name(Name) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - MemberAccess getAccess() const { return Attrs.getAccess(); } TypeIndex getType() const { return Type; } uint64_t getFieldOffset() const { return FieldOffset; } @@ -838,10 +733,6 @@ public: : TypeRecord(TypeRecordKind::StaticDataMember), Attrs(Access), Type(Type), Name(Name) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - MemberAccess getAccess() const { return Attrs.getAccess(); } TypeIndex getType() const { return Type; } StringRef getName() const { return Name; } @@ -862,10 +753,6 @@ public: : TypeRecord(TypeRecordKind::Enumerator), Attrs(Access), Value(std::move(Value)), Name(Name) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - MemberAccess getAccess() const { return Attrs.getAccess(); } APSInt getValue() const { return Value; } StringRef getName() const { return Name; } @@ -882,10 +769,6 @@ public: VFPtrRecord(TypeIndex Type) : TypeRecord(TypeRecordKind::VFPtr), Type(Type) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - TypeIndex getType() const { return Type; } TypeIndex Type; @@ -902,10 +785,6 @@ public: : TypeRecord(TypeRecordKind::BaseClass), Attrs(Access), Type(Type), Offset(Offset) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - MemberAccess getAccess() const { return Attrs.getAccess(); } TypeIndex getBaseType() const { return Type; } uint64_t getBaseOffset() const { return Offset; } @@ -930,10 +809,6 @@ public: : TypeRecord(Kind), Attrs(Access), BaseType(BaseType), VBPtrType(VBPtrType), VBPtrOffset(Offset), VTableIndex(Index) {} - /// Rewrite member type indices with IndexMap. Returns false if a type index - /// is not in the map. - bool remapTypeIndices(ArrayRef IndexMap); - MemberAccess getAccess() const { return Attrs.getAccess(); } TypeIndex getBaseType() const { return BaseType; } TypeIndex getVBPtrType() const { return VBPtrType; } @@ -958,8 +833,6 @@ public: TypeIndex getContinuationIndex() const { return ContinuationIndex; } - bool remapTypeIndices(ArrayRef IndexMap); - TypeIndex ContinuationIndex; }; diff --git a/llvm/lib/DebugInfo/CodeView/CMakeLists.txt b/llvm/lib/DebugInfo/CodeView/CMakeLists.txt index a120484..6e9214d 100644 --- a/llvm/lib/DebugInfo/CodeView/CMakeLists.txt +++ b/llvm/lib/DebugInfo/CodeView/CMakeLists.txt @@ -16,7 +16,6 @@ add_llvm_library(LLVMDebugInfoCodeView TypeDatabase.cpp TypeDatabaseVisitor.cpp TypeDumpVisitor.cpp - TypeRecord.cpp TypeRecordMapping.cpp TypeSerializer.cpp TypeStreamMerger.cpp diff --git a/llvm/lib/DebugInfo/CodeView/TypeRecord.cpp b/llvm/lib/DebugInfo/CodeView/TypeRecord.cpp deleted file mode 100644 index 6482f29..0000000 --- a/llvm/lib/DebugInfo/CodeView/TypeRecord.cpp +++ /dev/null @@ -1,220 +0,0 @@ -//===-- TypeRecord.cpp ------------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "llvm/DebugInfo/CodeView/TypeRecord.h" -#include "llvm/DebugInfo/CodeView/RecordSerialization.h" -#include "llvm/DebugInfo/CodeView/TypeIndex.h" -#include "llvm/Support/BinaryByteStream.h" -#include "llvm/Support/BinaryStreamReader.h" - -using namespace llvm; -using namespace llvm::codeview; - -//===----------------------------------------------------------------------===// -// Type index remapping -//===----------------------------------------------------------------------===// - -static bool remapIndex(ArrayRef IndexMap, TypeIndex &Idx) { - // Simple types are unchanged. - if (Idx.isSimple()) - return true; - unsigned MapPos = Idx.getIndex() - TypeIndex::FirstNonSimpleIndex; - if (MapPos < IndexMap.size()) { - Idx = IndexMap[MapPos]; - return true; - } - - // This type index is invalid. Remap this to "not translated by cvpack", - // and return failure. - Idx = TypeIndex(SimpleTypeKind::NotTranslated, SimpleTypeMode::Direct); - return false; -} - -bool ModifierRecord::remapTypeIndices(ArrayRef IndexMap) { - return remapIndex(IndexMap, ModifiedType); -} - -bool ProcedureRecord::remapTypeIndices(ArrayRef IndexMap) { - bool Success = true; - Success &= remapIndex(IndexMap, ReturnType); - Success &= remapIndex(IndexMap, ArgumentList); - return Success; -} - -bool MemberFunctionRecord::remapTypeIndices(ArrayRef IndexMap) { - bool Success = true; - Success &= remapIndex(IndexMap, ReturnType); - Success &= remapIndex(IndexMap, ClassType); - Success &= remapIndex(IndexMap, ThisType); - Success &= remapIndex(IndexMap, ArgumentList); - return Success; -} - -bool MemberFuncIdRecord::remapTypeIndices(ArrayRef IndexMap) { - bool Success = true; - Success &= remapIndex(IndexMap, ClassType); - Success &= remapIndex(IndexMap, FunctionType); - return Success; -} - -bool ArgListRecord::remapTypeIndices(ArrayRef IndexMap) { - bool Success = true; - for (TypeIndex &Arg : ArgIndices) - Success &= remapIndex(IndexMap, Arg); - return Success; -} - -bool StringListRecord::remapTypeIndices(ArrayRef IndexMap) { - bool Success = true; - for (TypeIndex &Str : StringIndices) - Success &= remapIndex(IndexMap, Str); - return Success; -} - -bool MemberPointerInfo::remapTypeIndices(ArrayRef IndexMap) { - return remapIndex(IndexMap, ContainingType); -} - -bool PointerRecord::remapTypeIndices(ArrayRef IndexMap) { - bool Success = true; - Success &= remapIndex(IndexMap, ReferentType); - if (isPointerToMember()) - Success &= MemberInfo->remapTypeIndices(IndexMap); - return Success; -} - -bool NestedTypeRecord::remapTypeIndices(ArrayRef IndexMap) { - return remapIndex(IndexMap, Type); -} - -bool ArrayRecord::remapTypeIndices(ArrayRef IndexMap) { - bool Success = true; - Success &= remapIndex(IndexMap, ElementType); - Success &= remapIndex(IndexMap, IndexType); - return Success; -} - -bool TagRecord::remapTypeIndices(ArrayRef IndexMap) { - return remapIndex(IndexMap, FieldList); -} - -bool ClassRecord::remapTypeIndices(ArrayRef IndexMap) { - bool Success = true; - Success &= TagRecord::remapTypeIndices(IndexMap); - Success &= remapIndex(IndexMap, DerivationList); - Success &= remapIndex(IndexMap, VTableShape); - return Success; -} - -bool EnumRecord::remapTypeIndices(ArrayRef IndexMap) { - bool Success = true; - Success &= TagRecord::remapTypeIndices(IndexMap); - Success &= remapIndex(IndexMap, UnderlyingType); - return Success; -} - -bool BitFieldRecord::remapTypeIndices(ArrayRef IndexMap) { - return remapIndex(IndexMap, Type); -} - -bool VFTableShapeRecord::remapTypeIndices(ArrayRef IndexMap) { - return true; -} - -bool TypeServer2Record::remapTypeIndices(ArrayRef IndexMap) { - return true; -} - -bool StringIdRecord::remapTypeIndices(ArrayRef IndexMap) { - return remapIndex(IndexMap, Id); -} - -bool FuncIdRecord::remapTypeIndices(ArrayRef IndexMap) { - bool Success = true; - Success &= remapIndex(IndexMap, ParentScope); - Success &= remapIndex(IndexMap, FunctionType); - return Success; -} - -bool UdtSourceLineRecord::remapTypeIndices(ArrayRef IndexMap) { - bool Success = true; - Success &= remapIndex(IndexMap, UDT); - Success &= remapIndex(IndexMap, SourceFile); - return Success; -} - -bool UdtModSourceLineRecord::remapTypeIndices(ArrayRef IndexMap) { - bool Success = true; - Success &= remapIndex(IndexMap, UDT); - Success &= remapIndex(IndexMap, SourceFile); - return Success; -} - -bool BuildInfoRecord::remapTypeIndices(ArrayRef IndexMap) { - bool Success = true; - for (TypeIndex &Arg : ArgIndices) - Success &= remapIndex(IndexMap, Arg); - return Success; -} - -bool VFTableRecord::remapTypeIndices(ArrayRef IndexMap) { - bool Success = true; - Success &= remapIndex(IndexMap, CompleteClass); - Success &= remapIndex(IndexMap, OverriddenVFTable); - return Success; -} - -bool OneMethodRecord::remapTypeIndices(ArrayRef IndexMap) { - bool Success = true; - Success &= remapIndex(IndexMap, Type); - return Success; -} - -bool MethodOverloadListRecord::remapTypeIndices(ArrayRef IndexMap) { - bool Success = true; - for (OneMethodRecord &Meth : Methods) - if ((Success = Meth.remapTypeIndices(IndexMap))) - return Success; - return Success; -} - -bool OverloadedMethodRecord::remapTypeIndices(ArrayRef IndexMap) { - return remapIndex(IndexMap, MethodList); -} - -bool DataMemberRecord::remapTypeIndices(ArrayRef IndexMap) { - return remapIndex(IndexMap, Type); -} - -bool StaticDataMemberRecord::remapTypeIndices(ArrayRef IndexMap) { - return remapIndex(IndexMap, Type); -} - -bool EnumeratorRecord::remapTypeIndices(ArrayRef IndexMap) { - return true; -} - -bool VFPtrRecord::remapTypeIndices(ArrayRef IndexMap) { - return remapIndex(IndexMap, Type); -} - -bool BaseClassRecord::remapTypeIndices(ArrayRef IndexMap) { - return remapIndex(IndexMap, Type); -} - -bool VirtualBaseClassRecord::remapTypeIndices(ArrayRef IndexMap) { - bool Success = true; - Success &= remapIndex(IndexMap, BaseType); - Success &= remapIndex(IndexMap, VBPtrType); - return Success; -} - -bool ListContinuationRecord::remapTypeIndices(ArrayRef IndexMap) { - return remapIndex(IndexMap, ContinuationIndex); -} diff --git a/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp b/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp index 85104d2..b01eaa8 100644 --- a/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp +++ b/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp @@ -76,31 +76,27 @@ public: Error mergeStream(const CVTypeArray &Types); private: + bool remapIndex(TypeIndex &Idx); + template - Error visitKnownRecordImpl(RecordType &Record) { - if (!Record.remapTypeIndices(IndexMap)) + Error writeRecord(RecordType &R, bool RemapSuccess) { + if (!RemapSuccess) { LastError = joinErrors( std::move(*LastError), llvm::make_error(cv_error_code::corrupt_record)); - IndexMap.push_back(DestStream.writeKnownType(Record)); - return Error::success(); - } - - Error visitKnownRecordImpl(FieldListRecord &Record) { - CVTypeVisitor Visitor(*this); - - if (auto EC = Visitor.visitFieldListMemberStream(Record.Data)) - return EC; + } + IndexMap.push_back(DestStream.writeKnownType(R)); return Error::success(); } template - Error visitKnownMemberRecordImpl(RecordType &Record) { - if (!Record.remapTypeIndices(IndexMap)) + Error writeMember(RecordType &R, bool RemapSuccess) { + if (!RemapSuccess) { LastError = joinErrors( std::move(*LastError), llvm::make_error(cv_error_code::corrupt_record)); - FieldListBuilder.writeMemberType(Record); + } + FieldListBuilder.writeMemberType(R); return Error::success(); } @@ -112,7 +108,7 @@ private: FieldListRecordBuilder FieldListBuilder; TypeServerHandler *Handler; - bool IsInFieldList{false}; + bool IsInFieldList = false; size_t BeginIndexMapSize = 0; /// Map from source type index to destination type index. Indexed by source @@ -146,19 +142,215 @@ Error TypeStreamMerger::visitMemberEnd(CVMemberRecord &Rec) { return Error::success(); } -#define TYPE_RECORD(EnumName, EnumVal, Name) \ - Error TypeStreamMerger::visitKnownRecord(CVType &CVR, \ - Name##Record &Record) { \ - return visitKnownRecordImpl(Record); \ +bool TypeStreamMerger::remapIndex(TypeIndex &Idx) { + // Simple types are unchanged. + if (Idx.isSimple()) + return true; + unsigned MapPos = Idx.getIndex() - TypeIndex::FirstNonSimpleIndex; + if (MapPos < IndexMap.size()) { + Idx = IndexMap[MapPos]; + return true; } -#define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) -#define MEMBER_RECORD(EnumName, EnumVal, Name) \ - Error TypeStreamMerger::visitKnownMember(CVMemberRecord &CVR, \ - Name##Record &Record) { \ - return visitKnownMemberRecordImpl(Record); \ - } -#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName) -#include "llvm/DebugInfo/CodeView/TypeRecords.def" + + // This type index is invalid. Remap this to "not translated by cvpack", + // and return failure. + Idx = TypeIndex(SimpleTypeKind::NotTranslated, SimpleTypeMode::Direct); + return false; +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, ModifierRecord &R) { + return writeRecord(R, remapIndex(R.ModifiedType)); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, ProcedureRecord &R) { + bool Success = true; + Success &= remapIndex(R.ReturnType); + Success &= remapIndex(R.ArgumentList); + return writeRecord(R, Success); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, MemberFunctionRecord &R) { + bool Success = true; + Success &= remapIndex(R.ReturnType); + Success &= remapIndex(R.ClassType); + Success &= remapIndex(R.ThisType); + Success &= remapIndex(R.ArgumentList); + return writeRecord(R, Success); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, MemberFuncIdRecord &R) { + bool Success = true; + Success &= remapIndex(R.ClassType); + Success &= remapIndex(R.FunctionType); + return writeRecord(R, Success); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, ArgListRecord &R) { + bool Success = true; + for (TypeIndex &Arg : R.ArgIndices) + Success &= remapIndex(Arg); + return writeRecord(R, Success); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, StringListRecord &R) { + bool Success = true; + for (TypeIndex &Str : R.StringIndices) + Success &= remapIndex(Str); + return writeRecord(R, Success); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, PointerRecord &R) { + bool Success = true; + Success &= remapIndex(R.ReferentType); + if (R.isPointerToMember()) + Success &= remapIndex(R.MemberInfo->ContainingType); + return writeRecord(R, Success); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, ArrayRecord &R) { + bool Success = true; + Success &= remapIndex(R.ElementType); + Success &= remapIndex(R.IndexType); + return writeRecord(R, Success); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, ClassRecord &R) { + bool Success = true; + Success &= remapIndex(R.FieldList); + Success &= remapIndex(R.DerivationList); + Success &= remapIndex(R.VTableShape); + return writeRecord(R, Success); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, UnionRecord &R) { + return writeRecord(R, remapIndex(R.FieldList)); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, EnumRecord &R) { + bool Success = true; + Success &= remapIndex(R.FieldList); + Success &= remapIndex(R.UnderlyingType); + return writeRecord(R, Success); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, BitFieldRecord &R) { + return writeRecord(R, remapIndex(R.Type)); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, VFTableShapeRecord &R) { + return writeRecord(R, true); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, TypeServer2Record &R) { + return writeRecord(R, true); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, StringIdRecord &R) { + return writeRecord(R, remapIndex(R.Id)); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, FuncIdRecord &R) { + bool Success = true; + Success &= remapIndex(R.ParentScope); + Success &= remapIndex(R.FunctionType); + return writeRecord(R, Success); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, UdtSourceLineRecord &R) { + bool Success = true; + Success &= remapIndex(R.UDT); + Success &= remapIndex(R.SourceFile); + return writeRecord(R, Success); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, UdtModSourceLineRecord &R) { + bool Success = true; + Success &= remapIndex(R.UDT); + Success &= remapIndex(R.SourceFile); + return writeRecord(R, Success); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, BuildInfoRecord &R) { + bool Success = true; + for (TypeIndex &Arg : R.ArgIndices) + Success &= remapIndex(Arg); + return writeRecord(R, Success); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, VFTableRecord &R) { + bool Success = true; + Success &= remapIndex(R.CompleteClass); + Success &= remapIndex(R.OverriddenVFTable); + return writeRecord(R, Success); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, + MethodOverloadListRecord &R) { + bool Success = true; + for (OneMethodRecord &Meth : R.Methods) + Success &= remapIndex(Meth.Type); + return writeRecord(R, Success); +} + +Error TypeStreamMerger::visitKnownRecord(CVType &, FieldListRecord &R) { + // Visit the members inside the field list. + CVTypeVisitor Visitor(*this); + if (auto EC = Visitor.visitFieldListMemberStream(R.Data)) + return EC; + return Error::success(); +} + +Error TypeStreamMerger::visitKnownMember(CVMemberRecord &, + NestedTypeRecord &R) { + return writeMember(R, remapIndex(R.Type)); +} + +Error TypeStreamMerger::visitKnownMember(CVMemberRecord &, OneMethodRecord &R) { + bool Success = true; + Success &= remapIndex(R.Type); + return writeMember(R, Success); +} + +Error TypeStreamMerger::visitKnownMember(CVMemberRecord &, + OverloadedMethodRecord &R) { + return writeMember(R, remapIndex(R.MethodList)); +} + +Error TypeStreamMerger::visitKnownMember(CVMemberRecord &, + DataMemberRecord &R) { + return writeMember(R, remapIndex(R.Type)); +} + +Error TypeStreamMerger::visitKnownMember(CVMemberRecord &, + StaticDataMemberRecord &R) { + return writeMember(R, remapIndex(R.Type)); +} + +Error TypeStreamMerger::visitKnownMember(CVMemberRecord &, + EnumeratorRecord &R) { + return writeMember(R, true); +} + +Error TypeStreamMerger::visitKnownMember(CVMemberRecord &, VFPtrRecord &R) { + return writeMember(R, remapIndex(R.Type)); +} + +Error TypeStreamMerger::visitKnownMember(CVMemberRecord &, BaseClassRecord &R) { + return writeMember(R, remapIndex(R.Type)); +} + +Error TypeStreamMerger::visitKnownMember(CVMemberRecord &, + VirtualBaseClassRecord &R) { + bool Success = true; + Success &= remapIndex(R.BaseType); + Success &= remapIndex(R.VBPtrType); + return writeMember(R, Success); +} + +Error TypeStreamMerger::visitKnownMember(CVMemberRecord &, + ListContinuationRecord &R) { + return writeMember(R, remapIndex(R.ContinuationIndex)); +} Error TypeStreamMerger::visitUnknownType(CVType &Rec) { // We failed to translate a type. Translate this index as "not translated". -- 2.7.4