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/MC/MCFixupKindInfo.h"
16 #include "llvm/Support/DataTypes.h"
17 #include "llvm/Support/ErrorHandling.h"
22 class MCELFObjectTargetWriter;
31 class SmallVectorImpl;
34 /// MCAsmBackend - Generic interface to target specific assembler backends.
36 MCAsmBackend(const MCAsmBackend &); // DO NOT IMPLEMENT
37 void operator=(const MCAsmBackend &); // DO NOT IMPLEMENT
38 protected: // Can only create subclasses.
41 unsigned HasReliableSymbolDifference : 1;
44 virtual ~MCAsmBackend();
46 /// createObjectWriter - Create a new MCObjectWriter instance for use by the
47 /// assembler backend to emit the final object file.
48 virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
50 /// createELFObjectTargetWriter - Create a new ELFObjectTargetWriter to enable
51 /// non-standard ELFObjectWriters.
52 virtual MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
53 llvm_unreachable("createELFObjectTargetWriter is not supported by asm "
57 /// hasReliableSymbolDifference - Check whether this target implements
58 /// accurate relocations for differences between symbols. If not, differences
59 /// between symbols will always be relocatable expressions and any references
60 /// to temporary symbols will be assumed to be in the same atom, unless they
61 /// reside in a different section.
63 /// This should always be true (since it results in fewer relocations with no
64 /// loss of functionality), but is currently supported as a way to maintain
65 /// exact object compatibility with Darwin 'as' (on non-x86_64). It should
66 /// eventually should be eliminated.
67 bool hasReliableSymbolDifference() const {
68 return HasReliableSymbolDifference;
71 /// doesSectionRequireSymbols - Check whether the given section requires that
72 /// all symbols (even temporaries) have symbol table entries.
73 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
77 /// isSectionAtomizable - Check whether the given section can be split into
80 /// \see MCAssembler::isSymbolLinkerVisible().
81 virtual bool isSectionAtomizable(const MCSection &Section) const {
85 /// @name Target Fixup Interfaces
88 /// getNumFixupKinds - Get the number of target specific fixup kinds.
89 virtual unsigned getNumFixupKinds() const = 0;
91 /// getFixupKindInfo - Get information on a fixup kind.
92 virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
94 /// processFixupValue - Target hook to adjust the literal value of a fixup
95 /// if necessary. The default does nothing.
96 virtual void processFixupValue(const MCAssembler &Asm,
97 const MCAsmLayout &Layout,
98 const MCFixup &Fixup, const MCFragment *DF,
99 MCValue &Target, uint64_t &Value) {}
103 /// applyFixup - Apply the \arg Value for given \arg Fixup into the provided
104 /// data fragment, at the offset specified by the fixup and following the
105 /// fixup kind as appropriate.
106 virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
107 uint64_t Value) const = 0;
111 /// @name Target Relaxation Interfaces
114 /// mayNeedRelaxation - Check whether the given instruction may need
117 /// \param Inst - The instruction to test.
118 virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0;
120 /// fixupNeedsRelaxation - Target specific predicate for whether a given
121 /// fixup requires the associated instruction to be relaxed.
122 virtual bool fixupNeedsRelaxation(const MCFixup &Fixup,
124 const MCInstFragment *DF,
125 const MCAsmLayout &Layout) const = 0;
127 /// RelaxInstruction - Relax the instruction in the given fragment to the next
128 /// wider instruction.
130 /// \param Inst - The instruction to relax, which may be the same as the
132 /// \parm Res [output] - On return, the relaxed instruction.
133 virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
137 /// writeNopData - Write an (optimal) nop sequence of Count bytes to the given
138 /// output. If the target cannot generate such a sequence, it should return an
141 /// \return - True on success.
142 virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
144 /// handleAssemblerFlag - Handle any target-specific assembler flags.
145 /// By default, do nothing.
146 virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {}
149 } // End llvm namespace