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-09-23 13:06:45 Functions: 4 4 100.0 %
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        2564 : static void writeRecordPrefix(BinaryStreamWriter &Writer, TypeLeafKind Kind) {
       7             :   RecordPrefix Prefix;
       8             :   Prefix.RecordKind = Kind;
       9             :   Prefix.RecordLen = 0;
      10        2564 :   cantFail(Writer.writeObject(Prefix));
      11        2564 : }
      12             : 
      13        2564 : static void addPadding(BinaryStreamWriter &Writer) {
      14        2564 :   uint32_t Align = Writer.getOffset() % 4;
      15        2564 :   if (Align == 0)
      16             :     return;
      17             : 
      18         811 :   int PaddingBytes = 4 - Align;
      19        2499 :   while (PaddingBytes > 0) {
      20        1688 :     uint8_t Pad = static_cast<uint8_t>(LF_PAD0 + PaddingBytes);
      21        1688 :     cantFail(Writer.writeInteger(Pad));
      22        1688 :     --PaddingBytes;
      23             :   }
      24             : }
      25             : 
      26        6474 : SimpleTypeSerializer::SimpleTypeSerializer() : ScratchBuffer(MaxRecordLength) {}
      27             : 
      28        6471 : SimpleTypeSerializer::~SimpleTypeSerializer() {}
      29             : 
      30             : template <typename T>
      31        2564 : ArrayRef<uint8_t> SimpleTypeSerializer::serialize(T &Record) {
      32        2564 :   BinaryStreamWriter Writer(ScratchBuffer, support::little);
      33             :   TypeRecordMapping Mapping(Writer);
      34             : 
      35             :   CVType CVT;
      36        2564 :   CVT.Type = static_cast<TypeLeafKind>(Record.getKind());
      37             : 
      38        2564 :   writeRecordPrefix(Writer, CVT.Type);
      39             : 
      40        2564 :   cantFail(Mapping.visitTypeBegin(CVT));
      41        2564 :   cantFail(Mapping.visitKnownRecord(CVT, Record));
      42        2564 :   cantFail(Mapping.visitTypeEnd(CVT));
      43             : 
      44        2564 :   addPadding(Writer);
      45             : 
      46        2564 :   RecordPrefix *Prefix = reinterpret_cast<RecordPrefix *>(ScratchBuffer.data());
      47             : 
      48        2564 :   Prefix->RecordKind = CVT.kind();
      49        2564 :   Prefix->RecordLen = Writer.getOffset() - sizeof(uint16_t);
      50             : 
      51        2564 :   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