/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/DebugInfo/CodeView/TypeIndex.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- TypeIndex.cpp - CodeView type index ---------------------*- 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/TypeIndex.h" |
10 | | |
11 | | #include "llvm/DebugInfo/CodeView/TypeCollection.h" |
12 | | #include "llvm/Support/ScopedPrinter.h" |
13 | | |
14 | | using namespace llvm; |
15 | | using namespace llvm::codeview; |
16 | | |
17 | | namespace { |
18 | | struct SimpleTypeEntry { |
19 | | StringRef Name; |
20 | | SimpleTypeKind Kind; |
21 | | }; |
22 | | |
23 | | /// The names here all end in "*". If the simple type is a pointer type, we |
24 | | /// return the whole name. Otherwise we lop off the last character in our |
25 | | /// StringRef. |
26 | | static const SimpleTypeEntry SimpleTypeNames[] = { |
27 | | {"void*", SimpleTypeKind::Void}, |
28 | | {"<not translated>*", SimpleTypeKind::NotTranslated}, |
29 | | {"HRESULT*", SimpleTypeKind::HResult}, |
30 | | {"signed char*", SimpleTypeKind::SignedCharacter}, |
31 | | {"unsigned char*", SimpleTypeKind::UnsignedCharacter}, |
32 | | {"char*", SimpleTypeKind::NarrowCharacter}, |
33 | | {"wchar_t*", SimpleTypeKind::WideCharacter}, |
34 | | {"char16_t*", SimpleTypeKind::Character16}, |
35 | | {"char32_t*", SimpleTypeKind::Character32}, |
36 | | {"__int8*", SimpleTypeKind::SByte}, |
37 | | {"unsigned __int8*", SimpleTypeKind::Byte}, |
38 | | {"short*", SimpleTypeKind::Int16Short}, |
39 | | {"unsigned short*", SimpleTypeKind::UInt16Short}, |
40 | | {"__int16*", SimpleTypeKind::Int16}, |
41 | | {"unsigned __int16*", SimpleTypeKind::UInt16}, |
42 | | {"long*", SimpleTypeKind::Int32Long}, |
43 | | {"unsigned long*", SimpleTypeKind::UInt32Long}, |
44 | | {"int*", SimpleTypeKind::Int32}, |
45 | | {"unsigned*", SimpleTypeKind::UInt32}, |
46 | | {"__int64*", SimpleTypeKind::Int64Quad}, |
47 | | {"unsigned __int64*", SimpleTypeKind::UInt64Quad}, |
48 | | {"__int64*", SimpleTypeKind::Int64}, |
49 | | {"unsigned __int64*", SimpleTypeKind::UInt64}, |
50 | | {"__int128*", SimpleTypeKind::Int128}, |
51 | | {"unsigned __int128*", SimpleTypeKind::UInt128}, |
52 | | {"__half*", SimpleTypeKind::Float16}, |
53 | | {"float*", SimpleTypeKind::Float32}, |
54 | | {"float*", SimpleTypeKind::Float32PartialPrecision}, |
55 | | {"__float48*", SimpleTypeKind::Float48}, |
56 | | {"double*", SimpleTypeKind::Float64}, |
57 | | {"long double*", SimpleTypeKind::Float80}, |
58 | | {"__float128*", SimpleTypeKind::Float128}, |
59 | | {"_Complex float*", SimpleTypeKind::Complex32}, |
60 | | {"_Complex double*", SimpleTypeKind::Complex64}, |
61 | | {"_Complex long double*", SimpleTypeKind::Complex80}, |
62 | | {"_Complex __float128*", SimpleTypeKind::Complex128}, |
63 | | {"bool*", SimpleTypeKind::Boolean8}, |
64 | | {"__bool16*", SimpleTypeKind::Boolean16}, |
65 | | {"__bool32*", SimpleTypeKind::Boolean32}, |
66 | | {"__bool64*", SimpleTypeKind::Boolean64}, |
67 | | }; |
68 | | } // namespace |
69 | | |
70 | 4.50k | StringRef TypeIndex::simpleTypeName(TypeIndex TI) { |
71 | 4.50k | assert(TI.isNoneType() || TI.isSimple()); |
72 | 4.50k | |
73 | 4.50k | if (TI.isNoneType()) |
74 | 12 | return "<no type>"; |
75 | 4.49k | |
76 | 4.49k | if (TI == TypeIndex::NullptrT()) |
77 | 2 | return "std::nullptr_t"; |
78 | 4.49k | |
79 | 4.49k | // This is a simple type. |
80 | 49.6k | for (const auto &SimpleTypeName : SimpleTypeNames)4.49k { |
81 | 49.6k | if (SimpleTypeName.Kind == TI.getSimpleKind()) { |
82 | 4.49k | if (TI.getSimpleMode() == SimpleTypeMode::Direct) |
83 | 4.39k | return SimpleTypeName.Name.drop_back(1); |
84 | 97 | // Otherwise, this is a pointer type. We gloss over the distinction |
85 | 97 | // between near, far, 64, 32, etc, and just give a pointer type. |
86 | 97 | return SimpleTypeName.Name; |
87 | 97 | } |
88 | 49.6k | } |
89 | 4.49k | return "<unknown simple type>"0 ; |
90 | 4.49k | } |
91 | | |
92 | | void llvm::codeview::printTypeIndex(ScopedPrinter &Printer, StringRef FieldName, |
93 | 14.9k | TypeIndex TI, TypeCollection &Types) { |
94 | 14.9k | StringRef TypeName; |
95 | 14.9k | if (!TI.isNoneType()) { |
96 | 10.6k | if (TI.isSimple()) |
97 | 1.75k | TypeName = TypeIndex::simpleTypeName(TI); |
98 | 8.88k | else |
99 | 8.88k | TypeName = Types.getTypeName(TI); |
100 | 10.6k | } |
101 | 14.9k | |
102 | 14.9k | if (!TypeName.empty()) |
103 | 10.3k | Printer.printHex(FieldName, TypeName, TI.getIndex()); |
104 | 4.65k | else |
105 | 4.65k | Printer.printHex(FieldName, TI.getIndex()); |
106 | 14.9k | } |