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/MC/MCAssembler.h" 14 #include "llvm/MC/MCStreamer.h" 15 16 namespace llvm { 17 class MCAssembler; 18 class MCCodeEmitter; 19 class MCSectionData; 20 class MCSubtargetInfo; 21 class MCExpr; 22 class MCFragment; 23 class MCDataFragment; 24 class MCAsmBackend; 25 class raw_ostream; 26 27 /// \brief Streaming object file generation interface. 28 /// 29 /// This class provides an implementation of the MCStreamer interface which is 30 /// suitable for use with the assembler backend. Specific object file formats 31 /// are expected to subclass this interface to implement directives specific 32 /// to that file format or custom semantics expected by the object writer 33 /// implementation. 34 class MCObjectStreamer : public MCStreamer { 35 MCAssembler *Assembler; 36 MCSectionData *CurSectionData; 37 MCSectionData::iterator CurInsertionPoint; 38 bool EmitEHFrame; 39 bool EmitDebugFrame; 40 41 virtual void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo&) = 0; 42 void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override; 43 void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override; 44 45 protected: 46 MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &_OS, 47 MCCodeEmitter *_Emitter); 48 MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &_OS, 49 MCCodeEmitter *_Emitter, MCAssembler *_Assembler); 50 ~MCObjectStreamer(); 51 52 public: 53 /// state management 54 void reset() override; 55 56 /// Object streamers require the integrated assembler. 57 bool isIntegratedAssemblerRequired() const override { return true; } 58 59 MCSymbolData &getOrCreateSymbolData(const MCSymbol *Symbol) { 60 return getAssembler().getOrCreateSymbolData(*Symbol); 61 } 62 void EmitFrames(MCAsmBackend *MAB); 63 void EmitCFISections(bool EH, bool Debug) override; 64 65 protected: 66 MCSectionData *getCurrentSectionData() const { 67 return CurSectionData; 68 } 69 70 MCFragment *getCurrentFragment() const; 71 72 void insert(MCFragment *F) const { 73 CurSectionData->getFragmentList().insert(CurInsertionPoint, F); 74 F->setParent(CurSectionData); 75 } 76 77 /// Get a data fragment to write into, creating a new one if the current 78 /// fragment is not a data fragment. 79 MCDataFragment *getOrCreateDataFragment() const; 80 81 public: 82 void visitUsedSymbol(const MCSymbol &Sym) override; 83 84 MCAssembler &getAssembler() { return *Assembler; } 85 86 /// @name MCStreamer Interface 87 /// @{ 88 89 void EmitLabel(MCSymbol *Symbol) override; 90 void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override; 91 void EmitValueImpl(const MCExpr *Value, unsigned Size, 92 const SMLoc &Loc = SMLoc()) override; 93 void EmitULEB128Value(const MCExpr *Value) override; 94 void EmitSLEB128Value(const MCExpr *Value) override; 95 void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override; 96 void ChangeSection(const MCSection *Section, 97 const MCExpr *Subsection) override; 98 void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo& STI) override; 99 100 /// \brief Emit an instruction to a special fragment, because this instruction 101 /// can change its size during relaxation. 102 virtual void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &); 103 104 void EmitBundleAlignMode(unsigned AlignPow2) override; 105 void EmitBundleLock(bool AlignToEnd) override; 106 void EmitBundleUnlock() override; 107 void EmitBytes(StringRef Data) override; 108 void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0, 109 unsigned ValueSize = 1, 110 unsigned MaxBytesToEmit = 0) override; 111 void EmitCodeAlignment(unsigned ByteAlignment, 112 unsigned MaxBytesToEmit = 0) override; 113 bool EmitValueToOffset(const MCExpr *Offset, unsigned char Value) override; 114 void EmitDwarfLocDirective(unsigned FileNo, unsigned Line, 115 unsigned Column, unsigned Flags, 116 unsigned Isa, unsigned Discriminator, 117 StringRef FileName) override; 118 void EmitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel, 119 const MCSymbol *Label, 120 unsigned PointerSize); 121 void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, 122 const MCSymbol *Label); 123 void EmitGPRel32Value(const MCExpr *Value) override; 124 void EmitGPRel64Value(const MCExpr *Value) override; 125 void EmitFill(uint64_t NumBytes, uint8_t FillValue) override; 126 void EmitZeros(uint64_t NumBytes) override; 127 void FinishImpl() override; 128 129 virtual bool mayHaveInstructions() const { 130 return getCurrentSectionData()->hasInstructions(); 131 } 132 }; 133 134 } // end namespace llvm 135 136 #endif 137