LCOV - code coverage report
Current view: top level - lib/DebugInfo/CodeView - GlobalTypeTableBuilder.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 30 39 76.9 %
Date: 2018-07-13 00:08:38 Functions: 10 14 71.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- GlobalTypeTableBuilder.cpp -----------------------------------------===//
       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/GlobalTypeTableBuilder.h"
      11             : #include "llvm/ADT/ArrayRef.h"
      12             : #include "llvm/ADT/DenseSet.h"
      13             : #include "llvm/ADT/STLExtras.h"
      14             : #include "llvm/DebugInfo/CodeView/CodeView.h"
      15             : #include "llvm/DebugInfo/CodeView/ContinuationRecordBuilder.h"
      16             : #include "llvm/DebugInfo/CodeView/RecordSerialization.h"
      17             : #include "llvm/DebugInfo/CodeView/TypeIndex.h"
      18             : #include "llvm/Support/Allocator.h"
      19             : #include "llvm/Support/BinaryByteStream.h"
      20             : #include "llvm/Support/BinaryStreamWriter.h"
      21             : #include "llvm/Support/Endian.h"
      22             : #include "llvm/Support/Error.h"
      23             : #include <algorithm>
      24             : #include <cassert>
      25             : #include <cstdint>
      26             : #include <cstring>
      27             : 
      28             : using namespace llvm;
      29             : using namespace llvm::codeview;
      30             : 
      31        1555 : TypeIndex GlobalTypeTableBuilder::nextTypeIndex() const {
      32        3110 :   return TypeIndex::fromArrayIndex(SeenRecords.size());
      33             : }
      34             : 
      35         262 : GlobalTypeTableBuilder::GlobalTypeTableBuilder(BumpPtrAllocator &Storage)
      36         262 :     : RecordStorage(Storage) {
      37             :   SeenRecords.reserve(4096);
      38         262 : }
      39             : 
      40             : GlobalTypeTableBuilder::~GlobalTypeTableBuilder() = default;
      41             : 
      42           4 : Optional<TypeIndex> GlobalTypeTableBuilder::getFirst() {
      43           8 :   if (empty())
      44             :     return None;
      45             : 
      46           4 :   return TypeIndex(TypeIndex::FirstNonSimpleIndex);
      47             : }
      48             : 
      49          38 : Optional<TypeIndex> GlobalTypeTableBuilder::getNext(TypeIndex Prev) {
      50          76 :   if (++Prev == nextTypeIndex())
      51             :     return None;
      52             :   return Prev;
      53             : }
      54             : 
      55          44 : CVType GlobalTypeTableBuilder::getType(TypeIndex Index) {
      56             :   CVType Type;
      57          88 :   Type.RecordData = SeenRecords[Index.toArrayIndex()];
      58          44 :   if (!Type.RecordData.empty()) {
      59             :     assert(Type.RecordData.size() >= sizeof(RecordPrefix));
      60             :     const RecordPrefix *P =
      61          44 :         reinterpret_cast<const RecordPrefix *>(Type.RecordData.data());
      62          44 :     Type.Type = static_cast<TypeLeafKind>(uint16_t(P->RecordKind));
      63             :   }
      64          44 :   return Type;
      65             : }
      66             : 
      67           0 : StringRef GlobalTypeTableBuilder::getTypeName(TypeIndex Index) {
      68           0 :   llvm_unreachable("Method not implemented");
      69             : }
      70             : 
      71           0 : bool GlobalTypeTableBuilder::contains(TypeIndex Index) {
      72           0 :   if (Index.isSimple() || Index.isNoneType())
      73             :     return false;
      74             : 
      75           0 :   return Index.toArrayIndex() < SeenRecords.size();
      76             : }
      77             : 
      78         256 : uint32_t GlobalTypeTableBuilder::size() { return SeenRecords.size(); }
      79             : 
      80           0 : uint32_t GlobalTypeTableBuilder::capacity() { return SeenRecords.size(); }
      81             : 
      82         117 : ArrayRef<ArrayRef<uint8_t>> GlobalTypeTableBuilder::records() const {
      83         117 :   return SeenRecords;
      84             : }
      85             : 
      86           2 : ArrayRef<GloballyHashedType> GlobalTypeTableBuilder::hashes() const {
      87           2 :   return SeenHashes;
      88             : }
      89             : 
      90           0 : void GlobalTypeTableBuilder::reset() {
      91           0 :   HashedRecords.clear();
      92             :   SeenRecords.clear();
      93           0 : }
      94             : 
      95        1368 : TypeIndex GlobalTypeTableBuilder::insertRecordBytes(ArrayRef<uint8_t> Record) {
      96             :   GloballyHashedType GHT =
      97        1368 :       GloballyHashedType::hashType(Record, SeenHashes, SeenHashes);
      98             :   return insertRecordAs(GHT, Record.size(),
      99             :                         [Record](MutableArrayRef<uint8_t> Data) {
     100             :                           assert(Data.size() == Record.size());
     101        1161 :                           ::memcpy(Data.data(), Record.data(), Record.size());
     102             :                           return Data;
     103        1368 :                         });
     104             : }
     105             : 
     106             : TypeIndex
     107          95 : GlobalTypeTableBuilder::insertRecord(ContinuationRecordBuilder &Builder) {
     108             :   TypeIndex TI;
     109          95 :   auto Fragments = Builder.end(nextTypeIndex());
     110             :   assert(!Fragments.empty());
     111         194 :   for (auto C : Fragments)
     112          99 :     TI = insertRecordBytes(C.RecordData);
     113         190 :   return TI;
     114             : }

Generated by: LCOV version 1.13