22 using namespace llvm::codeview;
58 class TypeStreamMerger {
61 : IndexMap(SourceToDest) {
90 size_t slotForIndex(
TypeIndex Idx)
const {
95 Error errorCorruptRecord()
const {
110 bool IsSecondPass =
false;
112 unsigned NumBadIndices = 0;
134 case TypeLeafKind::LF_FUNC_ID:
135 case TypeLeafKind::LF_MFUNC_ID:
136 case TypeLeafKind::LF_STRING_ID:
137 case TypeLeafKind::LF_SUBSTR_LIST:
138 case TypeLeafKind::LF_BUILDINFO:
139 case TypeLeafKind::LF_UDT_SRC_LINE:
140 case TypeLeafKind::LF_UDT_MOD_SRC_LINE:
147 void TypeStreamMerger::addMapping(
TypeIndex Idx) {
149 assert(IndexMap.size() == slotForIndex(CurIndex) &&
150 "visitKnownRecord should add one index map entry");
151 IndexMap.push_back(Idx);
153 assert(slotForIndex(CurIndex) < IndexMap.size());
154 IndexMap[slotForIndex(CurIndex)] = Idx;
166 unsigned MapPos = slotForIndex(Idx);
167 if (MapPos < Map.
size() && Map[MapPos] != Untranslated) {
174 if (IsSecondPass && MapPos >= Map.
size()) {
177 LastError =
joinErrors(std::move(*LastError), errorCorruptRecord());
188 bool TypeStreamMerger::remapTypeIndex(
TypeIndex &Idx) {
194 if (DestTypeStream ==
nullptr)
195 return remapIndex(Idx, TypeLookup);
197 assert(TypeLookup.empty());
198 return remapIndex(Idx, IndexMap);
201 bool TypeStreamMerger::remapItemIndex(
TypeIndex &Idx) {
203 return remapIndex(Idx, IndexMap);
208 DestTypeStream = &Dest;
216 DestIdStream = &Dest;
217 TypeLookup = TypeSourceToDest;
225 DestIdStream = &DestIds;
226 DestTypeStream = &DestTypes;
227 return doit(IdsAndTypes);
231 if (
auto EC = remapAllTypes(Types))
241 while (!LastError && NumBadIndices > 0) {
242 unsigned BadIndicesRemaining = NumBadIndices;
247 if (
auto EC = remapAllTypes(Types))
250 assert(NumBadIndices <= BadIndicesRemaining &&
251 "second pass found more bad indices");
252 if (!LastError && NumBadIndices == BadIndicesRemaining) {
253 return llvm::make_error<CodeViewError>(
259 return std::move(*LastError);
265 if (
auto EC = remapType(
Type))
274 bool MappedAllIndices = remapIndices(R, Refs);
277 if (
auto EC = writeRecord(Dest, R, MappedAllIndices))
281 assert((IsSecondPass || IndexMap.size() == slotForIndex(CurIndex)) &&
282 "visitKnownRecord should add one index map entry");
290 for (
auto &Ref : Refs) {
295 for (
auto TI : TIs) {
298 ? remapItemIndex(NewTI)
299 : remapTypeIndex(NewTI);
300 if (ThisSuccess && NewTI != TI)
301 Record.
Mappings.emplace_back(Offset, NewTI);
303 Success &= ThisSuccess;
312 TypeStreamMerger M(SourceToDest);
313 return M.mergeTypeRecords(Dest, Types);
320 TypeStreamMerger M(SourceToDest);
321 return M.mergeIdRecords(Dest, TypeSourceToDest, Ids);
327 TypeStreamMerger M(SourceToDest);
328 return M.mergeTypesAndIds(DestIds, DestTypes, IdsAndTypes);
void discoverTypeIndices(ArrayRef< uint8_t > RecordData, SmallVectorImpl< TiReference > &Refs)
Error mergeTypeRecords(TypeTableBuilder &Dest, SmallVectorImpl< TypeIndex > &SourceToDest, const CVTypeArray &Types)
Merge one set of type records into another.
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
SmallVector< std::pair< uint32_t, TypeIndex >, 8 > Mappings
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
CVRecord< Kind > OriginalRecord
static const uint32_t FirstNonSimpleIndex
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
size_t size() const
size - Get the array size.
uint32_t getIndex() const
TypeIndex writeSerializedRecord(ArrayRef< uint8_t > Record)
Error mergeTypeAndIdRecords(TypeTableBuilder &DestIds, TypeTableBuilder &DestTypes, SmallVectorImpl< TypeIndex > &SourceToDest, const CVTypeArray &IdsAndTypes)
Merge a unified set of type and id records, splitting them into separate output streams.
The instances of the Type class are immutable: once they are created, they are never changed...
static ErrorSuccess success()
Create a success value.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static bool isIdRecord(TypeLeafKind K)
ArrayRef< uint8_t > RecordData
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Error mergeIdRecords(TypeTableBuilder &Dest, ArrayRef< TypeIndex > Types, SmallVectorImpl< TypeIndex > &SourceToDest, const CVTypeArray &Ids)
Merge one set of id records into another.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.