Move target-specific logic out of generic MCAssembler.
[oota-llvm.git] / include / llvm / MC / MCAsmBackend.h
1 //===-- llvm/MC/MCAsmBack.h - MC Asm Backend --------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_MC_MCASMBACKEND_H
11 #define LLVM_MC_MCASMBACKEND_H
12
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
18 namespace llvm {
19 class MCAsmLayout;
20 class MCELFObjectTargetWriter;
21 class MCFixup;
22 class MCInst;
23 class MCInstFragment;
24 class MCObjectWriter;
25 class MCSection;
26 template<typename T>
27 class SmallVectorImpl;
28 class raw_ostream;
29
30 /// MCAsmBackend - Generic interface to target specific assembler backends.
31 class MCAsmBackend {
32   MCAsmBackend(const MCAsmBackend &);   // DO NOT IMPLEMENT
33   void operator=(const MCAsmBackend &);  // DO NOT IMPLEMENT
34 protected: // Can only create subclasses.
35   MCAsmBackend();
36
37   unsigned HasReliableSymbolDifference : 1;
38
39 public:
40   virtual ~MCAsmBackend();
41
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;
45
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");
50     return 0;
51   }
52
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.
58   ///
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;
65   }
66
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 {
70     return false;
71   }
72
73   /// isSectionAtomizable - Check whether the given section can be split into
74   /// atoms.
75   ///
76   /// \see MCAssembler::isSymbolLinkerVisible().
77   virtual bool isSectionAtomizable(const MCSection &Section) const {
78     return true;
79   }
80
81   /// @name Target Fixup Interfaces
82   /// @{
83
84   /// getNumFixupKinds - Get the number of target specific fixup kinds.
85   virtual unsigned getNumFixupKinds() const = 0;
86
87   /// getFixupKindInfo - Get information on a fixup kind.
88   virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
89
90   /// @}
91
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;
97
98   /// @}
99
100   /// @name Target Relaxation Interfaces
101   /// @{
102
103   /// MayNeedRelaxation - Check whether the given instruction may need
104   /// relaxation.
105   ///
106   /// \param Inst - The instruction to test.
107   virtual bool MayNeedRelaxation(const MCInst &Inst) const = 0;
108
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,
112                                     uint64_t Value,
113                                     const MCInstFragment *DF,
114                                     const MCAsmLayout &Layout) const = 0;
115
116   /// RelaxInstruction - Relax the instruction in the given fragment to the next
117   /// wider instruction.
118   ///
119   /// \param Inst - The instruction to relax, which may be the same as the
120   /// output.
121   /// \parm Res [output] - On return, the relaxed instruction.
122   virtual void RelaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
123
124   /// @}
125
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
128   /// error.
129   ///
130   /// \return - True on success.
131   virtual bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
132
133   /// HandleAssemblerFlag - Handle any target-specific assembler flags.
134   /// By default, do nothing.
135   virtual void HandleAssemblerFlag(MCAssemblerFlag Flag) {}
136 };
137
138 } // End llvm namespace
139
140 #endif