2
0

MCELFStreamer.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //===- MCELFStreamer.h - MCStreamer ELF 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_MCELFSTREAMER_H
  10. #define LLVM_MC_MCELFSTREAMER_H
  11. #include "llvm/ADT/SmallPtrSet.h"
  12. #include "llvm/MC/MCDirectives.h"
  13. #include "llvm/MC/MCObjectStreamer.h"
  14. #include "llvm/MC/SectionKind.h"
  15. #include "llvm/Support/DataTypes.h"
  16. #include <vector>
  17. namespace llvm {
  18. class MCAsmBackend;
  19. class MCAssembler;
  20. class MCCodeEmitter;
  21. class MCExpr;
  22. class MCInst;
  23. class raw_ostream;
  24. class MCELFStreamer : public MCObjectStreamer {
  25. public:
  26. MCELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_pwrite_stream &OS,
  27. MCCodeEmitter *Emitter)
  28. : MCObjectStreamer(Context, TAB, OS, Emitter), SeenIdent(false) {}
  29. ~MCELFStreamer() override;
  30. /// state management
  31. void reset() override {
  32. SeenIdent = false;
  33. LocalCommons.clear();
  34. BundleGroups.clear();
  35. MCObjectStreamer::reset();
  36. }
  37. /// \name MCStreamer Interface
  38. /// @{
  39. void InitSections(bool NoExecStack) override;
  40. void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
  41. void EmitLabel(MCSymbol *Symbol) override;
  42. void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
  43. void EmitThumbFunc(MCSymbol *Func) override;
  44. void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
  45. bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
  46. void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
  47. void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
  48. unsigned ByteAlignment) override;
  49. void BeginCOFFSymbolDef(const MCSymbol *Symbol) override;
  50. void EmitCOFFSymbolStorageClass(int StorageClass) override;
  51. void EmitCOFFSymbolType(int Type) override;
  52. void EndCOFFSymbolDef() override;
  53. void emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) override;
  54. void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
  55. unsigned ByteAlignment) override;
  56. void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
  57. uint64_t Size = 0, unsigned ByteAlignment = 0) override;
  58. void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
  59. unsigned ByteAlignment = 0) override;
  60. void EmitValueImpl(const MCExpr *Value, unsigned Size,
  61. const SMLoc &Loc = SMLoc()) override;
  62. void EmitFileDirective(StringRef Filename) override;
  63. void EmitIdent(StringRef IdentString) override;
  64. void EmitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override;
  65. void Flush() override;
  66. void FinishImpl() override;
  67. void EmitBundleAlignMode(unsigned AlignPow2) override;
  68. void EmitBundleLock(bool AlignToEnd) override;
  69. void EmitBundleUnlock() override;
  70. private:
  71. bool isBundleLocked() const;
  72. void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &) override;
  73. void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override;
  74. void fixSymbolsInTLSFixups(const MCExpr *expr);
  75. /// \brief Merge the content of the fragment \p EF into the fragment \p DF.
  76. void mergeFragment(MCDataFragment *, MCDataFragment *);
  77. bool SeenIdent;
  78. struct LocalCommon {
  79. const MCSymbol *Symbol;
  80. uint64_t Size;
  81. unsigned ByteAlignment;
  82. };
  83. std::vector<LocalCommon> LocalCommons;
  84. /// BundleGroups - The stack of fragments holding the bundle-locked
  85. /// instructions.
  86. llvm::SmallVector<MCDataFragment *, 4> BundleGroups;
  87. };
  88. MCELFStreamer *createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB,
  89. raw_pwrite_stream &OS,
  90. MCCodeEmitter *Emitter, bool RelaxAll,
  91. bool IsThumb);
  92. } // end namespace llvm
  93. #endif