4a0cf37a6eb25c5aab1523146ec453e31205cd4f
[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 MCELFObjectTargetWriter;
20 class MCFixup;
21 class MCInst;
22 class MCObjectWriter;
23 class MCSection;
24 template<typename T>
25 class SmallVectorImpl;
26 class raw_ostream;
27
28 /// MCAsmBackend - Generic interface to target specific assembler backends.
29 class MCAsmBackend {
30   MCAsmBackend(const MCAsmBackend &);   // DO NOT IMPLEMENT
31   void operator=(const MCAsmBackend &);  // DO NOT IMPLEMENT
32 protected: // Can only create subclasses.
33   MCAsmBackend();
34
35   unsigned HasReliableSymbolDifference : 1;
36
37 public:
38   virtual ~MCAsmBackend();
39
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;
43
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");
48     return 0;
49   }
50
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.
56   ///
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;
63   }
64
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 {
68     return false;
69   }
70
71   /// isSectionAtomizable - Check whether the given section can be split into
72   /// atoms.
73   ///
74   /// \see MCAssembler::isSymbolLinkerVisible().
75   virtual bool isSectionAtomizable(const MCSection &Section) const {
76     return true;
77   }
78
79   /// @name Target Fixup Interfaces
80   /// @{
81
82   /// getNumFixupKinds - Get the number of target specific fixup kinds.
83   virtual unsigned getNumFixupKinds() const = 0;
84
85   /// getFixupKindInfo - Get information on a fixup kind.
86   virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
87
88   /// @}
89
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;
95
96   /// @}
97
98   /// @name Target Relaxation Interfaces
99   /// @{
100
101   /// MayNeedRelaxation - Check whether the given instruction may need
102   /// relaxation.
103   ///
104   /// \param Inst - The instruction to test.
105   virtual bool MayNeedRelaxation(const MCInst &Inst) const = 0;
106
107   /// RelaxInstruction - Relax the instruction in the given fragment to the next
108   /// wider instruction.
109   ///
110   /// \param Inst - The instruction to relax, which may be the same as the
111   /// output.
112   /// \parm Res [output] - On return, the relaxed instruction.
113   virtual void RelaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
114
115   /// @}
116
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
119   /// error.
120   ///
121   /// \return - True on success.
122   virtual bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
123
124   /// HandleAssemblerFlag - Handle any target-specific assembler flags.
125   /// By default, do nothing.
126   virtual void HandleAssemblerFlag(MCAssemblerFlag Flag) {}
127 };
128
129 } // End llvm namespace
130
131 #endif