1 //===-- llvm/MC/MCAsmBack.h - MC Asm Backend --------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_MCASMBACKEND_H
11 #define LLVM_MC_MCASMBACKEND_H
13 #include "llvm/MC/MCDirectives.h"
14 #include "llvm/MC/MCFixup.h"
15 #include "llvm/Support/DataTypes.h"
16 #include "llvm/Support/ErrorHandling.h"
21 class MCELFObjectTargetWriter;
22 struct MCFixupKindInfo;
25 class MCRelaxableFragment;
31 /// MCAsmBackend - Generic interface to target specific assembler backends.
33 MCAsmBackend(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
34 void operator=(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
35 protected: // Can only create subclasses.
38 unsigned HasReliableSymbolDifference : 1;
39 unsigned HasDataInCodeSupport : 1;
42 virtual ~MCAsmBackend();
44 /// lifetime management
45 virtual void reset() { }
47 /// createObjectWriter - Create a new MCObjectWriter instance for use by the
48 /// assembler backend to emit the final object file.
49 virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
51 /// createELFObjectTargetWriter - Create a new ELFObjectTargetWriter to enable
52 /// non-standard ELFObjectWriters.
53 virtual MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
54 llvm_unreachable("createELFObjectTargetWriter is not supported by asm "
58 /// hasReliableSymbolDifference - Check whether this target implements
59 /// accurate relocations for differences between symbols. If not, differences
60 /// between symbols will always be relocatable expressions and any references
61 /// to temporary symbols will be assumed to be in the same atom, unless they
62 /// reside in a different section.
64 /// This should always be true (since it results in fewer relocations with no
65 /// loss of functionality), but is currently supported as a way to maintain
66 /// exact object compatibility with Darwin 'as' (on non-x86_64). It should
67 /// eventually should be eliminated.
68 bool hasReliableSymbolDifference() const {
69 return HasReliableSymbolDifference;
72 /// hasDataInCodeSupport - Check whether this target implements data-in-code
73 /// markers. If not, data region directives will be ignored.
74 bool hasDataInCodeSupport() const {
75 return HasDataInCodeSupport;
78 /// doesSectionRequireSymbols - Check whether the given section requires that
79 /// all symbols (even temporaries) have symbol table entries.
80 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
84 /// isSectionAtomizable - Check whether the given section can be split into
87 /// \see MCAssembler::isSymbolLinkerVisible().
88 virtual bool isSectionAtomizable(const MCSection &Section) const {
92 /// @name Target Fixup Interfaces
95 /// getNumFixupKinds - Get the number of target specific fixup kinds.
96 virtual unsigned getNumFixupKinds() const = 0;
98 /// getFixupKindInfo - Get information on a fixup kind.
99 virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
101 /// processFixupValue - Target hook to adjust the literal value of a fixup
102 /// if necessary. IsResolved signals whether the caller believes a relocation
103 /// is needed; the target can modify the value. The default does nothing.
104 virtual void processFixupValue(const MCAssembler &Asm,
105 const MCAsmLayout &Layout,
106 const MCFixup &Fixup, const MCFragment *DF,
107 MCValue &Target, uint64_t &Value,
112 /// applyFixup - Apply the \p Value for given \p Fixup into the provided
113 /// data fragment, at the offset specified by the fixup and following the
114 /// fixup kind as appropriate.
115 virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
116 uint64_t Value) const = 0;
120 /// @name Target Relaxation Interfaces
123 /// mayNeedRelaxation - Check whether the given instruction may need
126 /// \param Inst - The instruction to test.
127 virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0;
129 /// fixupNeedsRelaxation - Target specific predicate for whether a given
130 /// fixup requires the associated instruction to be relaxed.
131 virtual bool fixupNeedsRelaxation(const MCFixup &Fixup,
133 const MCRelaxableFragment *DF,
134 const MCAsmLayout &Layout) const = 0;
136 /// RelaxInstruction - Relax the instruction in the given fragment to the next
137 /// wider instruction.
139 /// \param Inst The instruction to relax, which may be the same as the
141 /// \param [out] Res On return, the relaxed instruction.
142 virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
146 /// getMinimumNopSize - Returns the minimum size of a nop in bytes on this
147 /// target. The assembler will use this to emit excess padding in situations
148 /// where the padding required for simple alignment would be less than the
149 /// minimum nop size.
151 virtual unsigned getMinimumNopSize() const { return 1; }
153 /// writeNopData - Write an (optimal) nop sequence of Count bytes to the given
154 /// output. If the target cannot generate such a sequence, it should return an
157 /// \return - True on success.
158 virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
160 /// handleAssemblerFlag - Handle any target-specific assembler flags.
161 /// By default, do nothing.
162 virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {}
165 } // End llvm namespace