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"
19 class MCELFObjectTargetWriter;
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;
38 virtual ~TargetAsmBackend();
40 /// createObjectWriter - Create a new MCObjectWriter instance for use by the
41 /// assembler backend to emit the final object file.
42 virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
44 /// createELFObjectTargetWriter - Create a new ELFObjectTargetWriter to enable
45 /// non-standard ELFObjectWriters.
46 virtual MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
47 assert(0 && "createELFObjectTargetWriter is not supported by asm backend");
51 /// hasReliableSymbolDifference - Check whether this target implements
52 /// accurate relocations for differences between symbols. If not, differences
53 /// between symbols will always be relocatable expressions and any references
54 /// to temporary symbols will be assumed to be in the same atom, unless they
55 /// reside in a different section.
57 /// This should always be true (since it results in fewer relocations with no
58 /// loss of functionality), but is currently supported as a way to maintain
59 /// exact object compatibility with Darwin 'as' (on non-x86_64). It should
60 /// eventually should be eliminated.
61 bool hasReliableSymbolDifference() const {
62 return HasReliableSymbolDifference;
65 /// doesSectionRequireSymbols - Check whether the given section requires that
66 /// all symbols (even temporaries) have symbol table entries.
67 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
71 /// isSectionAtomizable - Check whether the given section can be split into
74 /// \see MCAssembler::isSymbolLinkerVisible().
75 virtual bool isSectionAtomizable(const MCSection &Section) const {
79 /// @name Target Fixup Interfaces
82 /// getNumFixupKinds - Get the number of target specific fixup kinds.
83 virtual unsigned getNumFixupKinds() const = 0;
85 /// getFixupKindInfo - Get information on a fixup kind.
86 virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
90 /// ApplyFixup - Apply the \arg Value for given \arg Fixup into the provided
91 /// data fragment, at the offset specified by the fixup and following the
92 /// fixup kind as appropriate.
93 virtual void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
94 uint64_t Value) const = 0;
98 /// @name Target Relaxation Interfaces
101 /// MayNeedRelaxation - Check whether the given instruction may need
104 /// \param Inst - The instruction to test.
105 virtual bool MayNeedRelaxation(const MCInst &Inst) const = 0;
107 /// RelaxInstruction - Relax the instruction in the given fragment to the next
108 /// wider instruction.
110 /// \param Inst - The instruction to relax, which may be the same as the
112 /// \parm Res [output] - On return, the relaxed instruction.
113 virtual void RelaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
117 /// WriteNopData - Write an (optimal) nop sequence of Count bytes to the given
118 /// output. If the target cannot generate such a sequence, it should return an
121 /// \return - True on success.
122 virtual bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
124 /// HandleAssemblerFlag - Handle any target-specific assembler flags.
125 /// By default, do nothing.
126 virtual void HandleAssemblerFlag(MCAssemblerFlag Flag) {}
129 } // End llvm namespace