LLVM API Documentation

MCObjectStreamer.h
Go to the documentation of this file.
00001 //===- MCObjectStreamer.h - MCStreamer Object File Interface ----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef LLVM_MC_MCOBJECTSTREAMER_H
00011 #define LLVM_MC_MCOBJECTSTREAMER_H
00012 
00013 #include "llvm/MC/MCAssembler.h"
00014 #include "llvm/MC/MCStreamer.h"
00015 
00016 namespace llvm {
00017 class MCAssembler;
00018 class MCCodeEmitter;
00019 class MCSectionData;
00020 class MCSubtargetInfo;
00021 class MCExpr;
00022 class MCFragment;
00023 class MCDataFragment;
00024 class MCAsmBackend;
00025 class raw_ostream;
00026 
00027 /// \brief Streaming object file generation interface.
00028 ///
00029 /// This class provides an implementation of the MCStreamer interface which is
00030 /// suitable for use with the assembler backend. Specific object file formats
00031 /// are expected to subclass this interface to implement directives specific
00032 /// to that file format or custom semantics expected by the object writer
00033 /// implementation.
00034 class MCObjectStreamer : public MCStreamer {
00035   MCAssembler *Assembler;
00036   MCSectionData *CurSectionData;
00037   MCSectionData::iterator CurInsertionPoint;
00038   bool EmitEHFrame;
00039   bool EmitDebugFrame;
00040 
00041   virtual void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo&) = 0;
00042   void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
00043   void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
00044 
00045 protected:
00046   MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &_OS,
00047                    MCCodeEmitter *_Emitter);
00048   MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &_OS,
00049                    MCCodeEmitter *_Emitter, MCAssembler *_Assembler);
00050   ~MCObjectStreamer();
00051 
00052 public:
00053   /// state management
00054   void reset() override;
00055 
00056   /// Object streamers require the integrated assembler.
00057   bool isIntegratedAssemblerRequired() const override { return true; }
00058 
00059   MCSymbolData &getOrCreateSymbolData(const MCSymbol *Symbol) {
00060     return getAssembler().getOrCreateSymbolData(*Symbol);
00061   }
00062   void EmitFrames(MCAsmBackend *MAB);
00063   void EmitCFISections(bool EH, bool Debug) override;
00064 
00065 protected:
00066   MCSectionData *getCurrentSectionData() const {
00067     return CurSectionData;
00068   }
00069 
00070   MCFragment *getCurrentFragment() const;
00071 
00072   void insert(MCFragment *F) const {
00073     CurSectionData->getFragmentList().insert(CurInsertionPoint, F);
00074     F->setParent(CurSectionData);
00075   }
00076 
00077   /// Get a data fragment to write into, creating a new one if the current
00078   /// fragment is not a data fragment.
00079   MCDataFragment *getOrCreateDataFragment() const;
00080 
00081 public:
00082   void visitUsedSymbol(const MCSymbol &Sym) override;
00083 
00084   MCAssembler &getAssembler() { return *Assembler; }
00085 
00086   /// @name MCStreamer Interface
00087   /// @{
00088 
00089   void EmitLabel(MCSymbol *Symbol) override;
00090   void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
00091   void EmitValueImpl(const MCExpr *Value, unsigned Size,
00092                      const SMLoc &Loc = SMLoc()) override;
00093   void EmitULEB128Value(const MCExpr *Value) override;
00094   void EmitSLEB128Value(const MCExpr *Value) override;
00095   void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
00096   void ChangeSection(const MCSection *Section,
00097                      const MCExpr *Subsection) override;
00098   void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo& STI) override;
00099 
00100   /// \brief Emit an instruction to a special fragment, because this instruction
00101   /// can change its size during relaxation.
00102   virtual void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &);
00103 
00104   void EmitBundleAlignMode(unsigned AlignPow2) override;
00105   void EmitBundleLock(bool AlignToEnd) override;
00106   void EmitBundleUnlock() override;
00107   void EmitBytes(StringRef Data) override;
00108   void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
00109                             unsigned ValueSize = 1,
00110                             unsigned MaxBytesToEmit = 0) override;
00111   void EmitCodeAlignment(unsigned ByteAlignment,
00112                          unsigned MaxBytesToEmit = 0) override;
00113   bool EmitValueToOffset(const MCExpr *Offset, unsigned char Value) override;
00114   void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
00115                              unsigned Column, unsigned Flags,
00116                              unsigned Isa, unsigned Discriminator,
00117                              StringRef FileName) override;
00118   void EmitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel,
00119                                 const MCSymbol *Label,
00120                                 unsigned PointerSize);
00121   void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
00122                                  const MCSymbol *Label);
00123   void EmitGPRel32Value(const MCExpr *Value) override;
00124   void EmitGPRel64Value(const MCExpr *Value) override;
00125   void EmitFill(uint64_t NumBytes, uint8_t FillValue) override;
00126   void EmitZeros(uint64_t NumBytes) override;
00127   void FinishImpl() override;
00128 
00129   bool mayHaveInstructions() const override {
00130     return getCurrentSectionData()->hasInstructions();
00131   }
00132 };
00133 
00134 } // end namespace llvm
00135 
00136 #endif