LCOV - code coverage report
Current view: top level - lib/CodeGen/AsmPrinter - ByteStreamer.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 27 41 65.9 %
Date: 2017-09-14 15:23:50 Functions: 5 9 55.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- llvm/CodeGen/ByteStreamer.h - ByteStreamer class --------*- 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             : // This file contains a class that can take bytes that would normally be
      11             : // streamed via the AsmPrinter.
      12             : //
      13             : //===----------------------------------------------------------------------===//
      14             : 
      15             : #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_BYTESTREAMER_H
      16             : #define LLVM_LIB_CODEGEN_ASMPRINTER_BYTESTREAMER_H
      17             : 
      18             : #include "DIEHash.h"
      19             : #include "llvm/CodeGen/AsmPrinter.h"
      20             : #include "llvm/MC/MCStreamer.h"
      21             : #include "llvm/Support/LEB128.h"
      22             : #include <string>
      23             : 
      24             : namespace llvm {
      25             : class ByteStreamer {
      26             :  protected:
      27             :   ~ByteStreamer() = default;
      28             :   ByteStreamer(const ByteStreamer&) = default;
      29             :   ByteStreamer() = default;
      30             : 
      31             :  public:
      32             :   // For now we're just handling the calls we need for dwarf emission/hashing.
      33             :   virtual void EmitInt8(uint8_t Byte, const Twine &Comment = "") = 0;
      34             :   virtual void EmitSLEB128(uint64_t DWord, const Twine &Comment = "") = 0;
      35             :   virtual void EmitULEB128(uint64_t DWord, const Twine &Comment = "") = 0;
      36             : };
      37             : 
      38             : class APByteStreamer final : public ByteStreamer {
      39             : private:
      40             :   AsmPrinter &AP;
      41             : 
      42             : public:
      43       12715 :   APByteStreamer(AsmPrinter &Asm) : AP(Asm) {}
      44       17347 :   void EmitInt8(uint8_t Byte, const Twine &Comment) override {
      45       34694 :     AP.OutStreamer->AddComment(Comment);
      46       17347 :     AP.EmitInt8(Byte);
      47       17347 :   }
      48           0 :   void EmitSLEB128(uint64_t DWord, const Twine &Comment) override {
      49           0 :     AP.OutStreamer->AddComment(Comment);
      50           0 :     AP.EmitSLEB128(DWord);
      51           0 :   }
      52           0 :   void EmitULEB128(uint64_t DWord, const Twine &Comment) override {
      53           0 :     AP.OutStreamer->AddComment(Comment);
      54           0 :     AP.EmitULEB128(DWord);
      55           0 :   }
      56             : };
      57             : 
      58             : class HashingByteStreamer final : public ByteStreamer {
      59             :  private:
      60             :   DIEHash &Hash;
      61             :  public:
      62           1 :  HashingByteStreamer(DIEHash &H) : Hash(H) {}
      63           5 :   void EmitInt8(uint8_t Byte, const Twine &Comment) override {
      64          10 :     Hash.update(Byte);
      65           5 :   }
      66           0 :   void EmitSLEB128(uint64_t DWord, const Twine &Comment) override {
      67           0 :     Hash.addSLEB128(DWord);
      68           0 :   }
      69           0 :   void EmitULEB128(uint64_t DWord, const Twine &Comment) override {
      70           0 :     Hash.addULEB128(DWord);
      71           0 :   }
      72             : };
      73             : 
      74             : class BufferByteStreamer final : public ByteStreamer {
      75             : private:
      76             :   SmallVectorImpl<char> &Buffer;
      77             :   SmallVectorImpl<std::string> &Comments;
      78             : 
      79             :   /// \brief Only verbose textual output needs comments.  This will be set to
      80             :   /// true for that case, and false otherwise.  If false, comments passed in to
      81             :   /// the emit methods will be ignored.
      82             :   bool GenerateComments;
      83             : 
      84             : public:
      85             :   BufferByteStreamer(SmallVectorImpl<char> &Buffer,
      86             :                      SmallVectorImpl<std::string> &Comments,
      87             :                      bool GenerateComments)
      88       12721 :   : Buffer(Buffer), Comments(Comments), GenerateComments(GenerateComments) {}
      89       14119 :   void EmitInt8(uint8_t Byte, const Twine &Comment) override {
      90       14119 :     Buffer.push_back(Byte);
      91       14119 :     if (GenerateComments)
      92         562 :       Comments.push_back(Comment.str());
      93       14119 :   }
      94        1755 :   void EmitSLEB128(uint64_t DWord, const Twine &Comment) override {
      95        5265 :     raw_svector_ostream OSE(Buffer);
      96        1755 :     encodeSLEB128(DWord, OSE);
      97        1755 :     if (GenerateComments)
      98          92 :       Comments.push_back(Comment.str());
      99        1755 :   }
     100         616 :   void EmitULEB128(uint64_t DWord, const Twine &Comment) override {
     101        1848 :     raw_svector_ostream OSE(Buffer);
     102         616 :     encodeULEB128(DWord, OSE);
     103         616 :     if (GenerateComments)
     104          62 :       Comments.push_back(Comment.str());
     105         616 :   }
     106             : };
     107             : 
     108             : }
     109             : 
     110             : #endif

Generated by: LCOV version 1.13