11a081b207c56fb6941c8f6eeb162a3d48ccd69b
[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. The default does nothing.
96   virtual void processFixupValue(const MCAssembler &Asm,
97                                  const MCAsmLayout &Layout,
98                                  const MCFixup &Fixup, const MCFragment *DF,
99                                  MCValue &Target, uint64_t &Value) {}
100
101   /// @}
102
103   /// applyFixup - Apply the \arg Value for given \arg Fixup into the provided
104   /// data fragment, at the offset specified by the fixup and following the
105   /// fixup kind as appropriate.
106   virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
107                           uint64_t Value) const = 0;
108
109   /// @}
110
111   /// @name Target Relaxation Interfaces
112   /// @{
113
114   /// mayNeedRelaxation - Check whether the given instruction may need
115   /// relaxation.
116   ///
117   /// \param Inst - The instruction to test.
118   virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0;
119
120   /// fixupNeedsRelaxation - Target specific predicate for whether a given
121   /// fixup requires the associated instruction to be relaxed.
122   virtual bool fixupNeedsRelaxation(const MCFixup &Fixup,
123                                     uint64_t Value,
124                                     const MCInstFragment *DF,
125                                     const MCAsmLayout &Layout) const = 0;
126
127   /// RelaxInstruction - Relax the instruction in the given fragment to the next
128   /// wider instruction.
129   ///
130   /// \param Inst - The instruction to relax, which may be the same as the
131   /// output.
132   /// \parm Res [output] - On return, the relaxed instruction.
133   virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
134
135   /// @}
136
137   /// writeNopData - Write an (optimal) nop sequence of Count bytes to the given
138   /// output. If the target cannot generate such a sequence, it should return an
139   /// error.
140   ///
141   /// \return - True on success.
142   virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
143
144   /// handleAssemblerFlag - Handle any target-specific assembler flags.
145   /// By default, do nothing.
146   virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {}
147 };
148
149 } // End llvm namespace
150
151 #endif