ARM BL/BLX instruction fixups should use relocations.
[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 #include "llvm/Support/ErrorHandling.h"
18
19 namespace llvm {
20 class MCAsmLayout;
21 class MCAssembler;
22 class MCELFObjectTargetWriter;
23 class MCFixup;
24 class MCFragment;
25 class MCInst;
26 class MCInstFragment;
27 class MCObjectWriter;
28 class MCSection;
29 class MCValue;
30 template<typename T>
31 class SmallVectorImpl;
32 class raw_ostream;
33
34 /// MCAsmBackend - Generic interface to target specific assembler backends.
35 class MCAsmBackend {
36   MCAsmBackend(const MCAsmBackend &);   // DO NOT IMPLEMENT
37   void operator=(const MCAsmBackend &);  // DO NOT IMPLEMENT
38 protected: // Can only create subclasses.
39   MCAsmBackend();
40
41   unsigned HasReliableSymbolDifference : 1;
42
43 public:
44   virtual ~MCAsmBackend();
45
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;
49
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 "
54                      "backend");
55   }
56
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.
62   ///
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;
69   }
70
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 {
74     return false;
75   }
76
77   /// isSectionAtomizable - Check whether the given section can be split into
78   /// atoms.
79   ///
80   /// \see MCAssembler::isSymbolLinkerVisible().
81   virtual bool isSectionAtomizable(const MCSection &Section) const {
82     return true;
83   }
84
85   /// @name Target Fixup Interfaces
86   /// @{
87
88   /// getNumFixupKinds - Get the number of target specific fixup kinds.
89   virtual unsigned getNumFixupKinds() const = 0;
90
91   /// getFixupKindInfo - Get information on a fixup kind.
92   virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
93
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,
101                                  bool &IsResolved) {}
102
103   /// @}
104
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;
110
111   /// @}
112
113   /// @name Target Relaxation Interfaces
114   /// @{
115
116   /// mayNeedRelaxation - Check whether the given instruction may need
117   /// relaxation.
118   ///
119   /// \param Inst - The instruction to test.
120   virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0;
121
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,
125                                     uint64_t Value,
126                                     const MCInstFragment *DF,
127                                     const MCAsmLayout &Layout) const = 0;
128
129   /// RelaxInstruction - Relax the instruction in the given fragment to the next
130   /// wider instruction.
131   ///
132   /// \param Inst - The instruction to relax, which may be the same as the
133   /// output.
134   /// \parm Res [output] - On return, the relaxed instruction.
135   virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
136
137   /// @}
138
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
141   /// error.
142   ///
143   /// \return - True on success.
144   virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
145
146   /// handleAssemblerFlag - Handle any target-specific assembler flags.
147   /// By default, do nothing.
148   virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {}
149 };
150
151 } // End llvm namespace
152
153 #endif