LCOV - code coverage report
Current view: top level - lib/DebugInfo/CodeView - GlobalTypeTableBuilder.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 30 40 75.0 %
Date: 2018-10-20 13:21:21 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        2148 : TypeIndex GlobalTypeTableBuilder::nextTypeIndex() const {
      32        4296 :   return TypeIndex::fromArrayIndex(SeenRecords.size());
      33             : }
      34             : 
      35         308 : GlobalTypeTableBuilder::GlobalTypeTableBuilder(BumpPtrAllocator &Storage)
      36         308 :     : RecordStorage(Storage) {
      37             :   SeenRecords.reserve(4096);
      38         308 : }
      39             : 
      40             : GlobalTypeTableBuilder::~GlobalTypeTableBuilder() = default;
      41             : 
      42           4 : Optional<TypeIndex> GlobalTypeTableBuilder::getFirst() {
      43           4 :   if (empty())
      44             :     return None;
      45             : 
      46           4 :   return TypeIndex(TypeIndex::FirstNonSimpleIndex);
      47             : }
      48             : 
      49          38 : Optional<TypeIndex> GlobalTypeTableBuilder::getNext(TypeIndex Prev) {
      50          38 :   if (++Prev == nextTypeIndex())
      51             :     return None;
      52             :   return Prev;
      53             : }
      54             : 
      55          44 : CVType GlobalTypeTableBuilder::getType(TypeIndex Index) {
      56             :   CVType Type;
      57          44 :   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           0 :     return false;
      74             : 
      75           0 :   return Index.toArrayIndex() < SeenRecords.size();
      76             : }
      77             : 
      78         136 : uint32_t GlobalTypeTableBuilder::size() { return SeenRecords.size(); }
      79             : 
      80           0 : uint32_t GlobalTypeTableBuilder::capacity() { return SeenRecords.size(); }
      81             : 
      82         130 : ArrayRef<ArrayRef<uint8_t>> GlobalTypeTableBuilder::records() const {
      83         130 :   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        1944 : TypeIndex GlobalTypeTableBuilder::insertRecordBytes(ArrayRef<uint8_t> Record) {
      96             :   GloballyHashedType GHT =
      97        1944 :       GloballyHashedType::hashType(Record, SeenHashes, SeenHashes);
      98             :   return insertRecordAs(GHT, Record.size(),
      99             :                         [Record](MutableArrayRef<uint8_t> Data) {
     100             :                           assert(Data.size() == Record.size());
     101        1722 :                           ::memcpy(Data.data(), Record.data(), Record.size());
     102             :                           return Data;
     103        1944 :                         });
     104             : }
     105             : 
     106             : TypeIndex
     107         112 : GlobalTypeTableBuilder::insertRecord(ContinuationRecordBuilder &Builder) {
     108             :   TypeIndex TI;
     109         112 :   auto Fragments = Builder.end(nextTypeIndex());
     110             :   assert(!Fragments.empty());
     111         228 :   for (auto C : Fragments)
     112         116 :     TI = insertRecordBytes(C.RecordData);
     113         112 :   return TI;
     114             : }

Generated by: LCOV version 1.13