LCOV - code coverage report
Current view: top level - include/llvm/MC - MCObjectStreamer.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 4 4 100.0 %
Date: 2018-05-20 00:06:23 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- MCObjectStreamer.h - MCStreamer Object File Interface ----*- 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             : #ifndef LLVM_MC_MCOBJECTSTREAMER_H
      11             : #define LLVM_MC_MCOBJECTSTREAMER_H
      12             : 
      13             : #include "llvm/ADT/SmallVector.h"
      14             : #include "llvm/MC/MCAssembler.h"
      15             : #include "llvm/MC/MCSection.h"
      16             : #include "llvm/MC/MCStreamer.h"
      17             : 
      18             : namespace llvm {
      19             : class MCAssembler;
      20             : class MCCodeEmitter;
      21             : class MCSubtargetInfo;
      22             : class MCExpr;
      23             : class MCFragment;
      24             : class MCDataFragment;
      25             : class MCAsmBackend;
      26             : class raw_ostream;
      27             : class raw_pwrite_stream;
      28             : 
      29             : /// Streaming object file generation interface.
      30             : ///
      31             : /// This class provides an implementation of the MCStreamer interface which is
      32             : /// suitable for use with the assembler backend. Specific object file formats
      33             : /// are expected to subclass this interface to implement directives specific
      34             : /// to that file format or custom semantics expected by the object writer
      35             : /// implementation.
      36             : class MCObjectStreamer : public MCStreamer {
      37             :   std::unique_ptr<MCAssembler> Assembler;
      38             :   MCSection::iterator CurInsertionPoint;
      39             :   bool EmitEHFrame;
      40             :   bool EmitDebugFrame;
      41             :   SmallVector<MCSymbol *, 2> PendingLabels;
      42             : 
      43             :   virtual void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo&) = 0;
      44             :   void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
      45             :   void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
      46             :   MCSymbol *EmitCFILabel() override;
      47             :   void EmitInstructionImpl(const MCInst &Inst, const MCSubtargetInfo &STI);
      48             : 
      49             : protected:
      50             :   MCObjectStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> TAB,
      51             :                    raw_pwrite_stream &OS,
      52             :                    std::unique_ptr<MCCodeEmitter> Emitter);
      53             :   ~MCObjectStreamer();
      54             : 
      55             : public:
      56             :   /// state management
      57             :   void reset() override;
      58             : 
      59             :   /// Object streamers require the integrated assembler.
      60          18 :   bool isIntegratedAssemblerRequired() const override { return true; }
      61             : 
      62             :   void EmitFrames(MCAsmBackend *MAB);
      63             :   void EmitCFISections(bool EH, bool Debug) override;
      64             : 
      65             :   MCFragment *getCurrentFragment() const;
      66             : 
      67     2795139 :   void insert(MCFragment *F) {
      68     2795139 :     flushPendingLabels(F);
      69             :     MCSection *CurSection = getCurrentSectionOnly();
      70             :     CurSection->getFragmentList().insert(CurInsertionPoint, F);
      71             :     F->setParent(CurSection);
      72     2795138 :   }
      73             : 
      74             :   /// Get a data fragment to write into, creating a new one if the current
      75             :   /// fragment is not a data fragment.
      76             :   MCDataFragment *getOrCreateDataFragment();
      77             :   MCPaddingFragment *getOrCreatePaddingFragment();
      78             : 
      79             : protected:
      80             :   bool changeSectionImpl(MCSection *Section, const MCExpr *Subsection);
      81             : 
      82             :   /// If any labels have been emitted but not assigned fragments, ensure that
      83             :   /// they get assigned, either to F if possible or to a new data fragment.
      84             :   /// Optionally, it is also possible to provide an offset \p FOffset, which
      85             :   /// will be used as a symbol offset within the fragment.
      86             :   void flushPendingLabels(MCFragment *F, uint64_t FOffset = 0);
      87             : 
      88             :   void addFragmentAtoms();
      89             : 
      90             : public:
      91             :   void visitUsedSymbol(const MCSymbol &Sym) override;
      92             : 
      93             :   MCAssembler &getAssembler() { return *Assembler; }
      94             :   MCAssembler *getAssemblerPtr() override;
      95             :   /// \name MCStreamer Interface
      96             :   /// @{
      97             : 
      98             :   void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
      99             :   virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc, MCFragment *F);
     100             :   void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
     101             :   void EmitValueImpl(const MCExpr *Value, unsigned Size,
     102             :                      SMLoc Loc = SMLoc()) override;
     103             :   void EmitULEB128Value(const MCExpr *Value) override;
     104             :   void EmitSLEB128Value(const MCExpr *Value) override;
     105             :   void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
     106             :   void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
     107             :   void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
     108             :                        bool = false) override;
     109             : 
     110             :   /// Emit an instruction to a special fragment, because this instruction
     111             :   /// can change its size during relaxation.
     112             :   virtual void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &);
     113             : 
     114             :   void EmitBundleAlignMode(unsigned AlignPow2) override;
     115             :   void EmitBundleLock(bool AlignToEnd) override;
     116             :   void EmitBundleUnlock() override;
     117             :   void EmitBytes(StringRef Data) override;
     118             :   void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
     119             :                             unsigned ValueSize = 1,
     120             :                             unsigned MaxBytesToEmit = 0) override;
     121             :   void EmitCodeAlignment(unsigned ByteAlignment,
     122             :                          unsigned MaxBytesToEmit = 0) override;
     123             :   void emitValueToOffset(const MCExpr *Offset, unsigned char Value,
     124             :                          SMLoc Loc) override;
     125             :   void
     126             :   EmitCodePaddingBasicBlockStart(const MCCodePaddingContext &Context) override;
     127             :   void
     128             :   EmitCodePaddingBasicBlockEnd(const MCCodePaddingContext &Context) override;
     129             :   void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
     130             :                              unsigned Column, unsigned Flags,
     131             :                              unsigned Isa, unsigned Discriminator,
     132             :                              StringRef FileName) override;
     133             :   void EmitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel,
     134             :                                 const MCSymbol *Label,
     135             :                                 unsigned PointerSize);
     136             :   void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
     137             :                                  const MCSymbol *Label);
     138             :   void EmitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line,
     139             :                           unsigned Column, bool PrologueEnd, bool IsStmt,
     140             :                           StringRef FileName, SMLoc Loc) override;
     141             :   void EmitCVLinetableDirective(unsigned FunctionId, const MCSymbol *Begin,
     142             :                                 const MCSymbol *End) override;
     143             :   void EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
     144             :                                       unsigned SourceFileId,
     145             :                                       unsigned SourceLineNum,
     146             :                                       const MCSymbol *FnStartSym,
     147             :                                       const MCSymbol *FnEndSym) override;
     148             :   void EmitCVDefRangeDirective(
     149             :       ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
     150             :       StringRef FixedSizePortion) override;
     151             :   void EmitCVStringTableDirective() override;
     152             :   void EmitCVFileChecksumsDirective() override;
     153             :   void EmitCVFileChecksumOffsetDirective(unsigned FileNo) override;
     154             :   void EmitDTPRel32Value(const MCExpr *Value) override;
     155             :   void EmitDTPRel64Value(const MCExpr *Value) override;
     156             :   void EmitTPRel32Value(const MCExpr *Value) override;
     157             :   void EmitTPRel64Value(const MCExpr *Value) override;
     158             :   void EmitGPRel32Value(const MCExpr *Value) override;
     159             :   void EmitGPRel64Value(const MCExpr *Value) override;
     160             :   bool EmitRelocDirective(const MCExpr &Offset, StringRef Name,
     161             :                           const MCExpr *Expr, SMLoc Loc) override;
     162             :   using MCStreamer::emitFill;
     163             :   void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
     164             :                 SMLoc Loc = SMLoc()) override;
     165             :   void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
     166             :                 SMLoc Loc = SMLoc()) override;
     167             :   void EmitFileDirective(StringRef Filename) override;
     168             : 
     169             :   void FinishImpl() override;
     170             : 
     171             :   /// Emit the absolute difference between two symbols if possible.
     172             :   ///
     173             :   /// Emit the absolute difference between \c Hi and \c Lo, as long as we can
     174             :   /// compute it.  Currently, that requires that both symbols are in the same
     175             :   /// data fragment.  Otherwise, do nothing and return \c false.
     176             :   ///
     177             :   /// \pre Offset of \c Hi is greater than the offset \c Lo.
     178             :   void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
     179             :                               unsigned Size) override;
     180             : 
     181             :   void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi,
     182             :                                        const MCSymbol *Lo) override;
     183             : 
     184             :   bool mayHaveInstructions(MCSection &Sec) const override;
     185             : };
     186             : 
     187             : } // end namespace llvm
     188             : 
     189             : #endif

Generated by: LCOV version 1.13