1//===- TypeRecordHelpers.cpp ------------------------------------*- C++ -*-===//
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
9#include "llvm/DebugInfo/CodeView/TypeRecordHelpers.h"
10
11#include "llvm/ADT/SmallVector.h"
12#include "llvm/DebugInfo/CodeView/TypeIndexDiscovery.h"
13#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
14
15using namespace llvm;
16using namespace llvm::codeview;
17
18template <typename RecordT> static ClassOptions getUdtOptions(CVType CVT) {
19  RecordT Record;
20  if (auto EC = TypeDeserializer::deserializeAs<RecordT>(CVT, Record)) {
21    consumeError(std::move(EC));
22    return ClassOptions::None;
23  }
24  return Record.getOptions();
25}
26
27bool llvm::codeview::isUdtForwardRef(CVType CVT) {
28  ClassOptions UdtOptions = ClassOptions::None;
29  switch (CVT.kind()) {
30  case LF_STRUCTURE:
31  case LF_CLASS:
32  case LF_INTERFACE:
33    UdtOptions = getUdtOptions<ClassRecord>(std::move(CVT));
34    break;
35  case LF_ENUM:
36    UdtOptions = getUdtOptions<EnumRecord>(std::move(CVT));
37    break;
38  case LF_UNION:
39    UdtOptions = getUdtOptions<UnionRecord>(std::move(CVT));
40    break;
41  default:
42    return false;
43  }
44  return (UdtOptions & ClassOptions::ForwardReference) != ClassOptions::None;
45}
46
47TypeIndex llvm::codeview::getModifiedType(const CVType &CVT) {
48  assert(CVT.kind() == LF_MODIFIER);
49  SmallVector<TypeIndex, 1> Refs;
50  discoverTypeIndices(CVT, Refs);
51  return Refs.front();
52}
53