Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
4.5 KiB

  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. #ifndef LLVM_MC_MCOBJECTSTREAMER_H
  10. #define LLVM_MC_MCOBJECTSTREAMER_H
  11. #include "llvm/MC/MCAssembler.h"
  12. #include "llvm/MC/MCStreamer.h"
  13. namespace llvm {
  14. class MCAssembler;
  15. class MCCodeEmitter;
  16. class MCSectionData;
  17. class MCExpr;
  18. class MCFragment;
  19. class MCDataFragment;
  20. class MCAsmBackend;
  21. class raw_ostream;
  22. /// \brief Streaming object file generation interface.
  23. ///
  24. /// This class provides an implementation of the MCStreamer interface which is
  25. /// suitable for use with the assembler backend. Specific object file formats
  26. /// are expected to subclass this interface to implement directives specific
  27. /// to that file format or custom semantics expected by the object writer
  28. /// implementation.
  29. class MCObjectStreamer : public MCStreamer {
  30. MCAssembler *Assembler;
  31. MCSectionData *CurSectionData;
  32. MCSectionData::iterator CurInsertionPoint;
  33. virtual void EmitInstToData(const MCInst &Inst) = 0;
  34. virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
  35. virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame);
  36. protected:
  37. MCObjectStreamer(StreamerKind Kind, MCContext &Context, MCAsmBackend &TAB,
  38. raw_ostream &_OS, MCCodeEmitter *_Emitter);
  39. MCObjectStreamer(StreamerKind Kind, MCContext &Context, MCAsmBackend &TAB,
  40. raw_ostream &_OS, MCCodeEmitter *_Emitter,
  41. MCAssembler *_Assembler);
  42. ~MCObjectStreamer();
  43. public:
  44. /// state management
  45. virtual void reset();
  46. protected:
  47. MCSectionData *getCurrentSectionData() const {
  48. return CurSectionData;
  49. }
  50. MCFragment *getCurrentFragment() const;
  51. void insert(MCFragment *F) const {
  52. CurSectionData->getFragmentList().insert(CurInsertionPoint, F);
  53. F->setParent(CurSectionData);
  54. }
  55. /// Get a data fragment to write into, creating a new one if the current
  56. /// fragment is not a data fragment.
  57. MCDataFragment *getOrCreateDataFragment() const;
  58. const MCExpr *AddValueSymbols(const MCExpr *Value);
  59. public:
  60. MCAssembler &getAssembler() { return *Assembler; }
  61. /// @name MCStreamer Interface
  62. /// @{
  63. virtual void EmitLabel(MCSymbol *Symbol);
  64. virtual void EmitDebugLabel(MCSymbol *Symbol);
  65. virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
  66. virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
  67. unsigned AddrSpace);
  68. virtual void EmitULEB128Value(const MCExpr *Value);
  69. virtual void EmitSLEB128Value(const MCExpr *Value);
  70. virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
  71. virtual void ChangeSection(const MCSection *Section,
  72. const MCExpr *Subsection);
  73. virtual void EmitInstruction(const MCInst &Inst);
  74. /// \brief Emit an instruction to a special fragment, because this instruction
  75. /// can change its size during relaxation.
  76. virtual void EmitInstToFragment(const MCInst &Inst);
  77. virtual void EmitBundleAlignMode(unsigned AlignPow2);
  78. virtual void EmitBundleLock(bool AlignToEnd);
  79. virtual void EmitBundleUnlock();
  80. virtual void EmitBytes(StringRef Data, unsigned AddrSpace = 0);
  81. virtual void EmitValueToAlignment(unsigned ByteAlignment,
  82. int64_t Value = 0,
  83. unsigned ValueSize = 1,
  84. unsigned MaxBytesToEmit = 0);
  85. virtual void EmitCodeAlignment(unsigned ByteAlignment,
  86. unsigned MaxBytesToEmit = 0);
  87. virtual bool EmitValueToOffset(const MCExpr *Offset, unsigned char Value);
  88. virtual void EmitDwarfAdvanceLineAddr(int64_t LineDelta,
  89. const MCSymbol *LastLabel,
  90. const MCSymbol *Label,
  91. unsigned PointerSize);
  92. virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
  93. const MCSymbol *Label);
  94. virtual void EmitGPRel32Value(const MCExpr *Value);
  95. virtual void EmitGPRel64Value(const MCExpr *Value);
  96. virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue,
  97. unsigned AddrSpace = 0);
  98. virtual void FinishImpl();
  99. /// @}
  100. static bool classof(const MCStreamer *S) {
  101. return S->getKind() >= SK_ELFStreamer && S->getKind() <= SK_WinCOFFStreamer;
  102. }
  103. };
  104. } // end namespace llvm
  105. #endif