LCOV - code coverage report
Current view: top level - lib/DebugInfo/CodeView - TypeIndex.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 17 18 94.4 %
Date: 2018-10-20 13:21:21 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- TypeIndex.cpp - CodeView type index ---------------------*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : 
      10             : #include "llvm/DebugInfo/CodeView/TypeIndex.h"
      11             : 
      12             : #include "llvm/DebugInfo/CodeView/TypeCollection.h"
      13             : #include "llvm/Support/ScopedPrinter.h"
      14             : 
      15             : using namespace llvm;
      16             : using namespace llvm::codeview;
      17             : 
      18             : namespace {
      19             : struct SimpleTypeEntry {
      20             :   StringRef Name;
      21             :   SimpleTypeKind Kind;
      22             : };
      23             : 
      24             : /// The names here all end in "*". If the simple type is a pointer type, we
      25             : /// return the whole name. Otherwise we lop off the last character in our
      26             : /// StringRef.
      27             : static const SimpleTypeEntry SimpleTypeNames[] = {
      28             :     {"void*", SimpleTypeKind::Void},
      29             :     {"<not translated>*", SimpleTypeKind::NotTranslated},
      30             :     {"HRESULT*", SimpleTypeKind::HResult},
      31             :     {"signed char*", SimpleTypeKind::SignedCharacter},
      32             :     {"unsigned char*", SimpleTypeKind::UnsignedCharacter},
      33             :     {"char*", SimpleTypeKind::NarrowCharacter},
      34             :     {"wchar_t*", SimpleTypeKind::WideCharacter},
      35             :     {"char16_t*", SimpleTypeKind::Character16},
      36             :     {"char32_t*", SimpleTypeKind::Character32},
      37             :     {"__int8*", SimpleTypeKind::SByte},
      38             :     {"unsigned __int8*", SimpleTypeKind::Byte},
      39             :     {"short*", SimpleTypeKind::Int16Short},
      40             :     {"unsigned short*", SimpleTypeKind::UInt16Short},
      41             :     {"__int16*", SimpleTypeKind::Int16},
      42             :     {"unsigned __int16*", SimpleTypeKind::UInt16},
      43             :     {"long*", SimpleTypeKind::Int32Long},
      44             :     {"unsigned long*", SimpleTypeKind::UInt32Long},
      45             :     {"int*", SimpleTypeKind::Int32},
      46             :     {"unsigned*", SimpleTypeKind::UInt32},
      47             :     {"__int64*", SimpleTypeKind::Int64Quad},
      48             :     {"unsigned __int64*", SimpleTypeKind::UInt64Quad},
      49             :     {"__int64*", SimpleTypeKind::Int64},
      50             :     {"unsigned __int64*", SimpleTypeKind::UInt64},
      51             :     {"__int128*", SimpleTypeKind::Int128},
      52             :     {"unsigned __int128*", SimpleTypeKind::UInt128},
      53             :     {"__half*", SimpleTypeKind::Float16},
      54             :     {"float*", SimpleTypeKind::Float32},
      55             :     {"float*", SimpleTypeKind::Float32PartialPrecision},
      56             :     {"__float48*", SimpleTypeKind::Float48},
      57             :     {"double*", SimpleTypeKind::Float64},
      58             :     {"long double*", SimpleTypeKind::Float80},
      59             :     {"__float128*", SimpleTypeKind::Float128},
      60             :     {"_Complex float*", SimpleTypeKind::Complex32},
      61             :     {"_Complex double*", SimpleTypeKind::Complex64},
      62             :     {"_Complex long double*", SimpleTypeKind::Complex80},
      63             :     {"_Complex __float128*", SimpleTypeKind::Complex128},
      64             :     {"bool*", SimpleTypeKind::Boolean8},
      65             :     {"__bool16*", SimpleTypeKind::Boolean16},
      66             :     {"__bool32*", SimpleTypeKind::Boolean32},
      67             :     {"__bool64*", SimpleTypeKind::Boolean64},
      68             : };
      69             : } // namespace
      70             : 
      71        2784 : StringRef TypeIndex::simpleTypeName(TypeIndex TI) {
      72             :   assert(TI.isNoneType() || TI.isSimple());
      73             : 
      74        2784 :   if (TI.isNoneType())
      75           8 :     return "<no type>";
      76             : 
      77             :   // This is a simple type.
      78       30424 :   for (const auto &SimpleTypeName : SimpleTypeNames) {
      79       60848 :     if (SimpleTypeName.Kind == TI.getSimpleKind()) {
      80        2776 :       if (TI.getSimpleMode() == SimpleTypeMode::Direct)
      81             :         return SimpleTypeName.Name.drop_back(1);
      82             :       // Otherwise, this is a pointer type. We gloss over the distinction
      83             :       // between near, far, 64, 32, etc, and just give a pointer type.
      84          61 :       return SimpleTypeName.Name;
      85             :     }
      86             :   }
      87           0 :   return "<unknown simple type>";
      88             : }
      89             : 
      90        9962 : void llvm::codeview::printTypeIndex(ScopedPrinter &Printer, StringRef FieldName,
      91             :                                     TypeIndex TI, TypeCollection &Types) {
      92        9962 :   StringRef TypeName;
      93        9962 :   if (!TI.isNoneType()) {
      94        7247 :     if (TI.isSimple())
      95        1232 :       TypeName = TypeIndex::simpleTypeName(TI);
      96             :     else
      97        6015 :       TypeName = Types.getTypeName(TI);
      98             :   }
      99             : 
     100        9962 :   if (!TypeName.empty())
     101        7028 :     Printer.printHex(FieldName, TypeName, TI.getIndex());
     102             :   else
     103        2934 :     Printer.printHex(FieldName, TI.getIndex());
     104        9962 : }

Generated by: LCOV version 1.13