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.

167 lines
6.0 KiB

  1. //===-- llvm/MC/MCAsmBack.h - MC Asm Backend --------------------*- 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_MCASMBACKEND_H
  10. #define LLVM_MC_MCASMBACKEND_H
  11. #include "llvm/MC/MCDirectives.h"
  12. #include "llvm/MC/MCFixup.h"
  13. #include "llvm/Support/DataTypes.h"
  14. #include "llvm/Support/ErrorHandling.h"
  15. namespace llvm {
  16. class MCAsmLayout;
  17. class MCAssembler;
  18. class MCELFObjectTargetWriter;
  19. struct MCFixupKindInfo;
  20. class MCFragment;
  21. class MCInst;
  22. class MCRelaxableFragment;
  23. class MCObjectWriter;
  24. class MCSection;
  25. class MCValue;
  26. class raw_ostream;
  27. /// MCAsmBackend - Generic interface to target specific assembler backends.
  28. class MCAsmBackend {
  29. MCAsmBackend(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
  30. void operator=(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
  31. protected: // Can only create subclasses.
  32. MCAsmBackend();
  33. unsigned HasReliableSymbolDifference : 1;
  34. unsigned HasDataInCodeSupport : 1;
  35. public:
  36. virtual ~MCAsmBackend();
  37. /// lifetime management
  38. virtual void reset() { }
  39. /// createObjectWriter - Create a new MCObjectWriter instance for use by the
  40. /// assembler backend to emit the final object file.
  41. virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
  42. /// createELFObjectTargetWriter - Create a new ELFObjectTargetWriter to enable
  43. /// non-standard ELFObjectWriters.
  44. virtual MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
  45. llvm_unreachable("createELFObjectTargetWriter is not supported by asm "
  46. "backend");
  47. }
  48. /// hasReliableSymbolDifference - Check whether this target implements
  49. /// accurate relocations for differences between symbols. If not, differences
  50. /// between symbols will always be relocatable expressions and any references
  51. /// to temporary symbols will be assumed to be in the same atom, unless they
  52. /// reside in a different section.
  53. ///
  54. /// This should always be true (since it results in fewer relocations with no
  55. /// loss of functionality), but is currently supported as a way to maintain
  56. /// exact object compatibility with Darwin 'as' (on non-x86_64). It should
  57. /// eventually should be eliminated.
  58. bool hasReliableSymbolDifference() const {
  59. return HasReliableSymbolDifference;
  60. }
  61. /// hasDataInCodeSupport - Check whether this target implements data-in-code
  62. /// markers. If not, data region directives will be ignored.
  63. bool hasDataInCodeSupport() const {
  64. return HasDataInCodeSupport;
  65. }
  66. /// doesSectionRequireSymbols - Check whether the given section requires that
  67. /// all symbols (even temporaries) have symbol table entries.
  68. virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
  69. return false;
  70. }
  71. /// isSectionAtomizable - Check whether the given section can be split into
  72. /// atoms.
  73. ///
  74. /// \see MCAssembler::isSymbolLinkerVisible().
  75. virtual bool isSectionAtomizable(const MCSection &Section) const {
  76. return true;
  77. }
  78. /// @name Target Fixup Interfaces
  79. /// @{
  80. /// getNumFixupKinds - Get the number of target specific fixup kinds.
  81. virtual unsigned getNumFixupKinds() const = 0;
  82. /// getFixupKindInfo - Get information on a fixup kind.
  83. virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
  84. /// processFixupValue - Target hook to adjust the literal value of a fixup
  85. /// if necessary. IsResolved signals whether the caller believes a relocation
  86. /// is needed; the target can modify the value. The default does nothing.
  87. virtual void processFixupValue(const MCAssembler &Asm,
  88. const MCAsmLayout &Layout,
  89. const MCFixup &Fixup, const MCFragment *DF,
  90. MCValue &Target, uint64_t &Value,
  91. bool &IsResolved) {}
  92. /// @}
  93. /// applyFixup - Apply the \p Value for given \p Fixup into the provided
  94. /// data fragment, at the offset specified by the fixup and following the
  95. /// fixup kind as appropriate.
  96. virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
  97. uint64_t Value) const = 0;
  98. /// @}
  99. /// @name Target Relaxation Interfaces
  100. /// @{
  101. /// mayNeedRelaxation - Check whether the given instruction may need
  102. /// relaxation.
  103. ///
  104. /// \param Inst - The instruction to test.
  105. virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0;
  106. /// fixupNeedsRelaxation - Target specific predicate for whether a given
  107. /// fixup requires the associated instruction to be relaxed.
  108. virtual bool fixupNeedsRelaxation(const MCFixup &Fixup,
  109. uint64_t Value,
  110. const MCRelaxableFragment *DF,
  111. const MCAsmLayout &Layout) const = 0;
  112. /// RelaxInstruction - Relax the instruction in the given fragment to the next
  113. /// wider instruction.
  114. ///
  115. /// \param Inst The instruction to relax, which may be the same as the
  116. /// output.
  117. /// \param [out] Res On return, the relaxed instruction.
  118. virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
  119. /// @}
  120. /// getMinimumNopSize - Returns the minimum size of a nop in bytes on this
  121. /// target. The assembler will use this to emit excess padding in situations
  122. /// where the padding required for simple alignment would be less than the
  123. /// minimum nop size.
  124. ///
  125. virtual unsigned getMinimumNopSize() const { return 1; }
  126. /// writeNopData - Write an (optimal) nop sequence of Count bytes to the given
  127. /// output. If the target cannot generate such a sequence, it should return an
  128. /// error.
  129. ///
  130. /// \return - True on success.
  131. virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
  132. /// handleAssemblerFlag - Handle any target-specific assembler flags.
  133. /// By default, do nothing.
  134. virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {}
  135. };
  136. } // End llvm namespace
  137. #endif