LCOV - code coverage report
Current view: top level - lib/DebugInfo/CodeView - ModuleDebugFragmentRecord.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 31 40 77.5 %
Date: 2017-05-20 02:07:48 Functions: 8 9 88.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- ModuleDebugFragmentRecord.cpp -----------------------------*- 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/ModuleDebugFragmentRecord.h"
      11             : #include "llvm/DebugInfo/CodeView/ModuleDebugFragment.h"
      12             : 
      13             : #include "llvm/Support/BinaryStreamReader.h"
      14             : 
      15             : using namespace llvm;
      16             : using namespace llvm::codeview;
      17             : 
      18          12 : ModuleDebugFragmentRecord::ModuleDebugFragmentRecord()
      19          24 :     : Kind(ModuleDebugFragmentKind::None) {}
      20             : 
      21           0 : ModuleDebugFragmentRecord::ModuleDebugFragmentRecord(
      22           0 :     ModuleDebugFragmentKind Kind, BinaryStreamRef Data)
      23           0 :     : Kind(Kind), Data(Data) {}
      24             : 
      25           9 : Error ModuleDebugFragmentRecord::initialize(BinaryStreamRef Stream,
      26             :                                             ModuleDebugFragmentRecord &Info) {
      27             :   const ModuleDebugFragmentHeader *Header;
      28          27 :   BinaryStreamReader Reader(Stream);
      29          27 :   if (auto EC = Reader.readObject(Header))
      30           0 :     return EC;
      31             : 
      32             :   ModuleDebugFragmentKind Kind =
      33          18 :       static_cast<ModuleDebugFragmentKind>(uint32_t(Header->Kind));
      34             :   switch (Kind) {
      35             :   case ModuleDebugFragmentKind::FileChecksums:
      36             :   case ModuleDebugFragmentKind::Lines:
      37             :   case ModuleDebugFragmentKind::InlineeLines:
      38             :     break;
      39             :   default:
      40           0 :     llvm_unreachable("Unexpected debug fragment kind!");
      41             :   }
      42          36 :   if (auto EC = Reader.readStreamRef(Info.Data, Header->Length))
      43           0 :     return EC;
      44           9 :   Info.Kind = Kind;
      45          27 :   return Error::success();
      46             : }
      47             : 
      48           9 : uint32_t ModuleDebugFragmentRecord::getRecordLength() const {
      49           9 :   uint32_t Result = sizeof(ModuleDebugFragmentHeader) + Data.getLength();
      50             :   assert(Result % 4 == 0);
      51           9 :   return Result;
      52             : }
      53             : 
      54           9 : ModuleDebugFragmentKind ModuleDebugFragmentRecord::kind() const { return Kind; }
      55             : 
      56           9 : BinaryStreamRef ModuleDebugFragmentRecord::getRecordData() const {
      57           9 :   return Data;
      58             : }
      59             : 
      60           3 : ModuleDebugFragmentRecordBuilder::ModuleDebugFragmentRecordBuilder(
      61           3 :     ModuleDebugFragmentKind Kind, ModuleDebugFragment &Frag)
      62           3 :     : Kind(Kind), Frag(Frag) {}
      63             : 
      64           9 : uint32_t ModuleDebugFragmentRecordBuilder::calculateSerializedLength() {
      65           9 :   uint32_t Size = sizeof(ModuleDebugFragmentHeader) +
      66          27 :                   alignTo(Frag.calculateSerializedLength(), 4);
      67           9 :   return Size;
      68             : }
      69             : 
      70           3 : Error ModuleDebugFragmentRecordBuilder::commit(BinaryStreamWriter &Writer) {
      71           3 :   ModuleDebugFragmentHeader Header;
      72           6 :   Header.Kind = uint32_t(Kind);
      73           3 :   Header.Length =
      74           6 :       calculateSerializedLength() - sizeof(ModuleDebugFragmentHeader);
      75             : 
      76           9 :   if (auto EC = Writer.writeObject(Header))
      77           0 :     return EC;
      78           9 :   if (auto EC = Frag.commit(Writer))
      79           0 :     return EC;
      80           9 :   if (auto EC = Writer.padToAlignment(4))
      81           0 :     return EC;
      82             : 
      83           9 :   return Error::success();
      84             : }

Generated by: LCOV version 1.13