1 //===-- llvm/Target/TargetAsmBackend.h - Target 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_TARGET_TARGETASMBACKEND_H
11 #define LLVM_TARGET_TARGETASMBACKEND_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"
25 class SmallVectorImpl;
28 /// TargetAsmBackend - Generic interface to target specific assembler backends.
29 class TargetAsmBackend {
30 TargetAsmBackend(const TargetAsmBackend &); // DO NOT IMPLEMENT
31 void operator=(const TargetAsmBackend &); // DO NOT IMPLEMENT
32 protected: // Can only create subclasses.
35 unsigned HasReliableSymbolDifference : 1;
36 unsigned HasScatteredSymbols : 1;
39 virtual ~TargetAsmBackend();
41 virtual const MCObjectFormat &getObjectFormat() const = 0;
43 /// createObjectWriter - Create a new MCObjectWriter instance for use by the
44 /// assembler backend to emit the final object file.
45 virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
47 /// hasReliableSymbolDifference - Check whether this target implements
48 /// accurate relocations for differences between symbols. If not, differences
49 /// between symbols will always be relocatable expressions and any references
50 /// to temporary symbols will be assumed to be in the same atom, unless they
51 /// reside in a different section.
53 /// This should always be true (since it results in fewer relocations with no
54 /// loss of functionality), but is currently supported as a way to maintain
55 /// exact object compatibility with Darwin 'as' (on non-x86_64). It should
56 /// eventually should be eliminated.
57 bool hasReliableSymbolDifference() const {
58 return HasReliableSymbolDifference;
61 /// hasScatteredSymbols - Check whether this target supports scattered
62 /// symbols. If so, the assembler should assume that atoms can be scattered by
63 /// the linker. In particular, this means that the offsets between symbols
64 /// which are in distinct atoms is not known at link time, and the assembler
65 /// must generate fixups and relocations appropriately.
67 /// Note that the assembler currently does not reason about atoms, instead it
68 /// assumes all temporary symbols reside in the "current atom".
69 bool hasScatteredSymbols() const { return HasScatteredSymbols; }
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;
96 /// ApplyFixup - Apply the \arg Value for given \arg Fixup into the provided
97 /// data fragment, at the offset specified by the fixup and following the
98 /// fixup kind as appropriate.
99 virtual void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
100 uint64_t Value) const = 0;
104 /// @name Target Relaxation Interfaces
107 /// MayNeedRelaxation - Check whether the given instruction may need
110 /// \param Inst - The instruction to test.
111 virtual bool MayNeedRelaxation(const MCInst &Inst) const = 0;
113 /// RelaxInstruction - Relax the instruction in the given fragment to the next
114 /// wider instruction.
116 /// \param Inst - The instruction to relax, which may be the same as the
118 /// \parm Res [output] - On return, the relaxed instruction.
119 virtual void RelaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
123 /// WriteNopData - Write an (optimal) nop sequence of Count bytes to the given
124 /// output. If the target cannot generate such a sequence, it should return an
127 /// \return - True on success.
128 virtual bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
130 /// HandleAssemblerFlag - Handle any target-specific assembler flags.
131 /// By default, do nothing.
132 virtual void HandleAssemblerFlag(MCAssemblerFlag Flag) {}
135 } // End llvm namespace