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/MCStreamer.h" 14 15 namespace llvm { 16 class MCAssembler; 17 class MCCodeEmitter; 18 class MCSectionData; 19 class MCExpr; 20 class MCFragment; 21 class MCDataFragment; 22 class MCAsmBackend; 23 class raw_ostream; 24 25 /// \brief Streaming object file generation interface. 26 /// 27 /// This class provides an implementation of the MCStreamer interface which is 28 /// suitable for use with the assembler backend. Specific object file formats 29 /// are expected to subclass this interface to implement directives specific 30 /// to that file format or custom semantics expected by the object writer 31 /// implementation. 32 class MCObjectStreamer : public MCStreamer { 33 MCAssembler *Assembler; 34 MCSectionData *CurSectionData; 35 36 virtual void EmitInstToData(const MCInst &Inst) = 0; 37 38 protected: 39 MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, 40 raw_ostream &_OS, MCCodeEmitter *_Emitter); 41 MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, 42 raw_ostream &_OS, MCCodeEmitter *_Emitter, 43 MCAssembler *_Assembler); 44 ~MCObjectStreamer(); 45 getCurrentSectionData()46 MCSectionData *getCurrentSectionData() const { 47 return CurSectionData; 48 } 49 50 MCFragment *getCurrentFragment() const; 51 52 /// Get a data fragment to write into, creating a new one if the current 53 /// fragment is not a data fragment. 54 MCDataFragment *getOrCreateDataFragment() const; 55 56 const MCExpr *AddValueSymbols(const MCExpr *Value); 57 58 public: getAssembler()59 MCAssembler &getAssembler() { return *Assembler; } 60 61 /// @name MCStreamer Interface 62 /// @{ 63 64 virtual void EmitLabel(MCSymbol *Symbol); 65 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size, 66 unsigned AddrSpace); 67 virtual void EmitULEB128Value(const MCExpr *Value); 68 virtual void EmitSLEB128Value(const MCExpr *Value); 69 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol); 70 virtual void ChangeSection(const MCSection *Section); 71 virtual void EmitInstruction(const MCInst &Inst); 72 virtual void EmitInstToFragment(const MCInst &Inst); 73 virtual void EmitValueToOffset(const MCExpr *Offset, unsigned char Value); 74 virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta, 75 const MCSymbol *LastLabel, 76 const MCSymbol *Label, 77 unsigned PointerSize); 78 virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, 79 const MCSymbol *Label); 80 virtual void Finish(); 81 82 /// @} 83 }; 84 85 } // end namespace llvm 86 87 #endif 88