LCOV - code coverage report
Current view: top level - lib/DebugInfo/CodeView - SimpleTypeSerializer.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 25 25 100.0 %
Date: 2018-06-17 00:07:59 Functions: 27 29 93.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include "llvm/DebugInfo/CodeView/SimpleTypeSerializer.h"
       2             : 
       3             : using namespace llvm;
       4             : using namespace llvm::codeview;
       5             : 
       6        2501 : static void writeRecordPrefix(BinaryStreamWriter &Writer, TypeLeafKind Kind) {
       7             :   RecordPrefix Prefix;
       8             :   Prefix.RecordKind = Kind;
       9             :   Prefix.RecordLen = 0;
      10        2501 :   cantFail(Writer.writeObject(Prefix));
      11        2501 : }
      12             : 
      13        2501 : static void addPadding(BinaryStreamWriter &Writer) {
      14        2501 :   uint32_t Align = Writer.getOffset() % 4;
      15        2501 :   if (Align == 0)
      16             :     return;
      17             : 
      18         790 :   int PaddingBytes = 4 - Align;
      19        4070 :   while (PaddingBytes > 0) {
      20        1640 :     uint8_t Pad = static_cast<uint8_t>(LF_PAD0 + PaddingBytes);
      21        3280 :     cantFail(Writer.writeInteger(Pad));
      22        1640 :     --PaddingBytes;
      23             :   }
      24             : }
      25             : 
      26        6004 : SimpleTypeSerializer::SimpleTypeSerializer() : ScratchBuffer(MaxRecordLength) {}
      27             : 
      28       12006 : SimpleTypeSerializer::~SimpleTypeSerializer() {}
      29             : 
      30             : template <typename T>
      31        2501 : ArrayRef<uint8_t> SimpleTypeSerializer::serialize(T &Record) {
      32        2501 :   BinaryStreamWriter Writer(ScratchBuffer, support::little);
      33             :   TypeRecordMapping Mapping(Writer);
      34             : 
      35             :   CVType CVT;
      36        2501 :   CVT.Type = static_cast<TypeLeafKind>(Record.getKind());
      37             : 
      38        2501 :   writeRecordPrefix(Writer, CVT.Type);
      39             : 
      40        5002 :   cantFail(Mapping.visitTypeBegin(CVT));
      41        5002 :   cantFail(Mapping.visitKnownRecord(CVT, Record));
      42        5002 :   cantFail(Mapping.visitTypeEnd(CVT));
      43             : 
      44        2501 :   addPadding(Writer);
      45             : 
      46        2501 :   RecordPrefix *Prefix = reinterpret_cast<RecordPrefix *>(ScratchBuffer.data());
      47             : 
      48        2501 :   Prefix->RecordKind = CVT.kind();
      49        2501 :   Prefix->RecordLen = Writer.getOffset() - sizeof(uint16_t);
      50             : 
      51        5002 :   return {ScratchBuffer.data(), Writer.getOffset()};
      52             : }
      53             : 
      54             : // Explicitly instantiate the member function for each known type so that we can
      55             : // implement this in the cpp file.
      56             : #define TYPE_RECORD(EnumName, EnumVal, Name)                                   \
      57             :   template ArrayRef<uint8_t> llvm::codeview::SimpleTypeSerializer::serialize(  \
      58             :       Name##Record &Record);
      59             : #define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
      60             : #define MEMBER_RECORD(EnumName, EnumVal, Name)
      61             : #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
      62             : #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"

Generated by: LCOV version 1.13