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"
20 class MCELFObjectTargetWriter;
27 class SmallVectorImpl;
30 /// MCAsmBackend - Generic interface to target specific assembler backends.
32 MCAsmBackend(const MCAsmBackend &); // DO NOT IMPLEMENT
33 void operator=(const MCAsmBackend &); // DO NOT IMPLEMENT
34 protected: // Can only create subclasses.
37 unsigned HasReliableSymbolDifference : 1;
40 virtual ~MCAsmBackend();
42 /// createObjectWriter - Create a new MCObjectWriter instance for use by the
43 /// assembler backend to emit the final object file.
44 virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
46 /// createELFObjectTargetWriter - Create a new ELFObjectTargetWriter to enable
47 /// non-standard ELFObjectWriters.
48 virtual MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
49 assert(0 && "createELFObjectTargetWriter is not supported by asm backend");
53 /// hasReliableSymbolDifference - Check whether this target implements
54 /// accurate relocations for differences between symbols. If not, differences
55 /// between symbols will always be relocatable expressions and any references
56 /// to temporary symbols will be assumed to be in the same atom, unless they
57 /// reside in a different section.
59 /// This should always be true (since it results in fewer relocations with no
60 /// loss of functionality), but is currently supported as a way to maintain
61 /// exact object compatibility with Darwin 'as' (on non-x86_64). It should
62 /// eventually should be eliminated.
63 bool hasReliableSymbolDifference() const {
64 return HasReliableSymbolDifference;
67 /// doesSectionRequireSymbols - Check whether the given section requires that
68 /// all symbols (even temporaries) have symbol table entries.
69 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
73 /// isSectionAtomizable - Check whether the given section can be split into
76 /// \see MCAssembler::isSymbolLinkerVisible().
77 virtual bool isSectionAtomizable(const MCSection &Section) const {
81 /// @name Target Fixup Interfaces
84 /// getNumFixupKinds - Get the number of target specific fixup kinds.
85 virtual unsigned getNumFixupKinds() const = 0;
87 /// getFixupKindInfo - Get information on a fixup kind.
88 virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
92 /// ApplyFixup - Apply the \arg Value for given \arg Fixup into the provided
93 /// data fragment, at the offset specified by the fixup and following the
94 /// fixup kind as appropriate.
95 virtual void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
96 uint64_t Value) const = 0;
100 /// @name Target Relaxation Interfaces
103 /// MayNeedRelaxation - Check whether the given instruction may need
106 /// \param Inst - The instruction to test.
107 virtual bool MayNeedRelaxation(const MCInst &Inst) const = 0;
109 /// fixupNeedsRelaxation - Target specific predicate for whether a given
110 /// fixup requires the associated instruction to be relaxed.
111 virtual bool fixupNeedsRelaxation(const MCFixup &Fixup,
113 const MCInstFragment *DF,
114 const MCAsmLayout &Layout) const = 0;
116 /// RelaxInstruction - Relax the instruction in the given fragment to the next
117 /// wider instruction.
119 /// \param Inst - The instruction to relax, which may be the same as the
121 /// \parm Res [output] - On return, the relaxed instruction.
122 virtual void RelaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
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
130 /// \return - True on success.
131 virtual bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
133 /// HandleAssemblerFlag - Handle any target-specific assembler flags.
134 /// By default, do nothing.
135 virtual void HandleAssemblerFlag(MCAssemblerFlag Flag) {}
138 } // End llvm namespace