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. IsResolved signals whether the caller believes a relocation
96 /// is needed; the target can modify the value. The default does nothing.
97 virtual void processFixupValue(const MCAssembler &Asm,
98 const MCAsmLayout &Layout,
99 const MCFixup &Fixup, const MCFragment *DF,
100 MCValue &Target, uint64_t &Value,
105 /// applyFixup - Apply the \arg Value for given \arg Fixup into the provided
106 /// data fragment, at the offset specified by the fixup and following the
107 /// fixup kind as appropriate.
108 virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
109 uint64_t Value) const = 0;
113 /// @name Target Relaxation Interfaces
116 /// mayNeedRelaxation - Check whether the given instruction may need
119 /// \param Inst - The instruction to test.
120 virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0;
122 /// fixupNeedsRelaxation - Target specific predicate for whether a given
123 /// fixup requires the associated instruction to be relaxed.
124 virtual bool fixupNeedsRelaxation(const MCFixup &Fixup,
126 const MCInstFragment *DF,
127 const MCAsmLayout &Layout) const = 0;
129 /// RelaxInstruction - Relax the instruction in the given fragment to the next
130 /// wider instruction.
132 /// \param Inst - The instruction to relax, which may be the same as the
134 /// \parm Res [output] - On return, the relaxed instruction.
135 virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
139 /// writeNopData - Write an (optimal) nop sequence of Count bytes to the given
140 /// output. If the target cannot generate such a sequence, it should return an
143 /// \return - True on success.
144 virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
146 /// handleAssemblerFlag - Handle any target-specific assembler flags.
147 /// By default, do nothing.
148 virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {}
151 } // End llvm namespace