LLVM API Documentation

MCAsmBackend.h
Go to the documentation of this file.
00001 //===-- llvm/MC/MCAsmBack.h - MC Asm Backend --------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef LLVM_MC_MCASMBACKEND_H
00011 #define LLVM_MC_MCASMBACKEND_H
00012 
00013 #include "llvm/MC/MCDirectives.h"
00014 #include "llvm/MC/MCFixup.h"
00015 #include "llvm/Support/DataTypes.h"
00016 #include "llvm/Support/ErrorHandling.h"
00017 
00018 namespace llvm {
00019 class MCAsmLayout;
00020 class MCAssembler;
00021 class MCELFObjectTargetWriter;
00022 struct MCFixupKindInfo;
00023 class MCFragment;
00024 class MCInst;
00025 class MCRelaxableFragment;
00026 class MCObjectWriter;
00027 class MCSection;
00028 class MCValue;
00029 class raw_ostream;
00030 
00031 /// MCAsmBackend - Generic interface to target specific assembler backends.
00032 class MCAsmBackend {
00033   MCAsmBackend(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
00034   void operator=(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
00035 protected: // Can only create subclasses.
00036   MCAsmBackend();
00037 
00038   unsigned HasReliableSymbolDifference : 1;
00039   unsigned HasDataInCodeSupport : 1;
00040 
00041 public:
00042   virtual ~MCAsmBackend();
00043 
00044   /// lifetime management
00045   virtual void reset() { }
00046 
00047   /// createObjectWriter - Create a new MCObjectWriter instance for use by the
00048   /// assembler backend to emit the final object file.
00049   virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
00050 
00051   /// createELFObjectTargetWriter - Create a new ELFObjectTargetWriter to enable
00052   /// non-standard ELFObjectWriters.
00053   virtual  MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
00054     llvm_unreachable("createELFObjectTargetWriter is not supported by asm "
00055                      "backend");
00056   }
00057 
00058   /// hasReliableSymbolDifference - Check whether this target implements
00059   /// accurate relocations for differences between symbols. If not, differences
00060   /// between symbols will always be relocatable expressions and any references
00061   /// to temporary symbols will be assumed to be in the same atom, unless they
00062   /// reside in a different section.
00063   ///
00064   /// This should always be true (since it results in fewer relocations with no
00065   /// loss of functionality), but is currently supported as a way to maintain
00066   /// exact object compatibility with Darwin 'as' (on non-x86_64). It should
00067   /// eventually should be eliminated.
00068   bool hasReliableSymbolDifference() const {
00069     return HasReliableSymbolDifference;
00070   }
00071 
00072   /// hasDataInCodeSupport - Check whether this target implements data-in-code
00073   /// markers. If not, data region directives will be ignored.
00074   bool hasDataInCodeSupport() const {
00075     return HasDataInCodeSupport;
00076   }
00077 
00078   /// doesSectionRequireSymbols - Check whether the given section requires that
00079   /// all symbols (even temporaries) have symbol table entries.
00080   virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
00081     return false;
00082   }
00083 
00084   /// isSectionAtomizable - Check whether the given section can be split into
00085   /// atoms.
00086   ///
00087   /// \see MCAssembler::isSymbolLinkerVisible().
00088   virtual bool isSectionAtomizable(const MCSection &Section) const {
00089     return true;
00090   }
00091 
00092   /// @name Target Fixup Interfaces
00093   /// @{
00094 
00095   /// getNumFixupKinds - Get the number of target specific fixup kinds.
00096   virtual unsigned getNumFixupKinds() const = 0;
00097 
00098   /// getFixupKindInfo - Get information on a fixup kind.
00099   virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
00100 
00101   /// processFixupValue - Target hook to adjust the literal value of a fixup
00102   /// if necessary. IsResolved signals whether the caller believes a relocation
00103   /// is needed; the target can modify the value. The default does nothing.
00104   virtual void processFixupValue(const MCAssembler &Asm,
00105                                  const MCAsmLayout &Layout,
00106                                  const MCFixup &Fixup, const MCFragment *DF,
00107                                  MCValue &Target, uint64_t &Value,
00108                                  bool &IsResolved) {}
00109 
00110   /// @}
00111 
00112   /// applyFixup - Apply the \p Value for given \p Fixup into the provided
00113   /// data fragment, at the offset specified by the fixup and following the
00114   /// fixup kind as appropriate.
00115   virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
00116                           uint64_t Value) const = 0;
00117 
00118   /// @}
00119 
00120   /// @name Target Relaxation Interfaces
00121   /// @{
00122 
00123   /// mayNeedRelaxation - Check whether the given instruction may need
00124   /// relaxation.
00125   ///
00126   /// \param Inst - The instruction to test.
00127   virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0;
00128 
00129   /// fixupNeedsRelaxation - Target specific predicate for whether a given
00130   /// fixup requires the associated instruction to be relaxed.
00131   virtual bool fixupNeedsRelaxation(const MCFixup &Fixup,
00132                                     uint64_t Value,
00133                                     const MCRelaxableFragment *DF,
00134                                     const MCAsmLayout &Layout) const = 0;
00135 
00136   /// RelaxInstruction - Relax the instruction in the given fragment to the next
00137   /// wider instruction.
00138   ///
00139   /// \param Inst The instruction to relax, which may be the same as the
00140   /// output.
00141   /// \param [out] Res On return, the relaxed instruction.
00142   virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
00143 
00144   /// @}
00145 
00146   /// getMinimumNopSize - Returns the minimum size of a nop in bytes on this
00147   /// target. The assembler will use this to emit excess padding in situations
00148   /// where the padding required for simple alignment would be less than the
00149   /// minimum nop size.
00150   ///
00151   virtual unsigned getMinimumNopSize() const { return 1; }
00152 
00153   /// writeNopData - Write an (optimal) nop sequence of Count bytes to the given
00154   /// output. If the target cannot generate such a sequence, it should return an
00155   /// error.
00156   ///
00157   /// \return - True on success.
00158   virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
00159 
00160   /// handleAssemblerFlag - Handle any target-specific assembler flags.
00161   /// By default, do nothing.
00162   virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {}
00163 };
00164 
00165 } // End llvm namespace
00166 
00167 #endif