LCOV - code coverage report
Current view: top level - lib/MC - MCLinkerOptimizationHint.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 18 18 100.0 %
Date: 2018-10-20 13:21:21 Functions: 6 7 85.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- llvm/MC/MCLinkerOptimizationHint.cpp ----- LOH handling ------------===//
       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/MC/MCLinkerOptimizationHint.h"
      11             : #include "llvm/MC/MCAsmLayout.h"
      12             : #include "llvm/MC/MCMachObjectWriter.h"
      13             : #include "llvm/Support/LEB128.h"
      14             : #include "llvm/Support/raw_ostream.h"
      15             : #include <cstddef>
      16             : #include <cstdint>
      17             : 
      18             : using namespace llvm;
      19             : 
      20             : // Each LOH is composed by, in this order (each field is encoded using ULEB128):
      21             : // - Its kind.
      22             : // - Its number of arguments (let say N).
      23             : // - Its arg1.
      24             : // - ...
      25             : // - Its argN.
      26             : // <arg1> to <argN> are absolute addresses in the object file, i.e.,
      27             : // relative addresses from the beginning of the object file.
      28           2 : void MCLOHDirective::emit_impl(raw_ostream &OutStream,
      29             :                                const MachObjectWriter &ObjWriter,
      30             :                                const MCAsmLayout &Layout) const {
      31           2 :   encodeULEB128(Kind, OutStream);
      32           4 :   encodeULEB128(Args.size(), OutStream);
      33           6 :   for (const MCSymbol *Arg : Args)
      34           4 :     encodeULEB128(ObjWriter.getSymbolAddress(*Arg, Layout), OutStream);
      35           2 : }
      36             : 
      37           1 : void MCLOHDirective::emit(MachObjectWriter &ObjWriter,
      38             :                           const MCAsmLayout &Layout) const {
      39           1 :   raw_ostream &OutStream = ObjWriter.W.OS;
      40           1 :   emit_impl(OutStream, ObjWriter, Layout);
      41           1 : }
      42             : 
      43           1 : uint64_t MCLOHDirective::getEmitSize(const MachObjectWriter &ObjWriter,
      44             :                                      const MCAsmLayout &Layout) const {
      45             :   class raw_counting_ostream : public raw_ostream {
      46             :     uint64_t Count = 0;
      47             : 
      48           1 :     void write_impl(const char *, size_t size) override { Count += size; }
      49             : 
      50           1 :     uint64_t current_pos() const override { return Count; }
      51             : 
      52             :   public:
      53           1 :     raw_counting_ostream() = default;
      54           2 :     ~raw_counting_ostream() override { flush(); }
      55             :   };
      56             : 
      57           1 :   raw_counting_ostream OutStream;
      58           1 :   emit_impl(OutStream, ObjWriter, Layout);
      59           1 :   return OutStream.tell();
      60             : }

Generated by: LCOV version 1.13