]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/include/llvm/MC/MCAsmBackend.h
MFC r244628:
[FreeBSD/stable/9.git] / contrib / llvm / 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/Support/DataTypes.h"
16 #include "llvm/Support/ErrorHandling.h"
17
18 namespace llvm {
19 class MCAsmLayout;
20 class MCAssembler;
21 class MCELFObjectTargetWriter;
22 struct MCFixupKindInfo;
23 class MCFragment;
24 class MCInst;
25 class MCInstFragment;
26 class MCObjectWriter;
27 class MCSection;
28 class MCValue;
29 class raw_ostream;
30
31 /// MCAsmBackend - Generic interface to target specific assembler backends.
32 class MCAsmBackend {
33   MCAsmBackend(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
34   void operator=(const MCAsmBackend &) LLVM_DELETED_FUNCTION;
35 protected: // Can only create subclasses.
36   MCAsmBackend();
37
38   unsigned HasReliableSymbolDifference : 1;
39   unsigned HasDataInCodeSupport : 1;
40
41 public:
42   virtual ~MCAsmBackend();
43
44   /// createObjectWriter - Create a new MCObjectWriter instance for use by the
45   /// assembler backend to emit the final object file.
46   virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
47
48   /// createELFObjectTargetWriter - Create a new ELFObjectTargetWriter to enable
49   /// non-standard ELFObjectWriters.
50   virtual  MCELFObjectTargetWriter *createELFObjectTargetWriter() const {
51     llvm_unreachable("createELFObjectTargetWriter is not supported by asm "
52                      "backend");
53   }
54
55   /// hasReliableSymbolDifference - Check whether this target implements
56   /// accurate relocations for differences between symbols. If not, differences
57   /// between symbols will always be relocatable expressions and any references
58   /// to temporary symbols will be assumed to be in the same atom, unless they
59   /// reside in a different section.
60   ///
61   /// This should always be true (since it results in fewer relocations with no
62   /// loss of functionality), but is currently supported as a way to maintain
63   /// exact object compatibility with Darwin 'as' (on non-x86_64). It should
64   /// eventually should be eliminated.
65   bool hasReliableSymbolDifference() const {
66     return HasReliableSymbolDifference;
67   }
68
69   /// hasDataInCodeSupport - Check whether this target implements data-in-code
70   /// markers. If not, data region directives will be ignored.
71   bool hasDataInCodeSupport() const {
72     return HasDataInCodeSupport;
73   }
74
75   /// doesSectionRequireSymbols - Check whether the given section requires that
76   /// all symbols (even temporaries) have symbol table entries.
77   virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
78     return false;
79   }
80
81   /// isSectionAtomizable - Check whether the given section can be split into
82   /// atoms.
83   ///
84   /// \see MCAssembler::isSymbolLinkerVisible().
85   virtual bool isSectionAtomizable(const MCSection &Section) const {
86     return true;
87   }
88
89   /// @name Target Fixup Interfaces
90   /// @{
91
92   /// getNumFixupKinds - Get the number of target specific fixup kinds.
93   virtual unsigned getNumFixupKinds() const = 0;
94
95   /// getFixupKindInfo - Get information on a fixup kind.
96   virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const;
97
98   /// processFixupValue - Target hook to adjust the literal value of a fixup
99   /// if necessary. IsResolved signals whether the caller believes a relocation
100   /// is needed; the target can modify the value. The default does nothing.
101   virtual void processFixupValue(const MCAssembler &Asm,
102                                  const MCAsmLayout &Layout,
103                                  const MCFixup &Fixup, const MCFragment *DF,
104                                  MCValue &Target, uint64_t &Value,
105                                  bool &IsResolved) {}
106
107   /// @}
108
109   /// applyFixup - Apply the \p Value for given \p Fixup into the provided
110   /// data fragment, at the offset specified by the fixup and following the
111   /// fixup kind as appropriate.
112   virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
113                           uint64_t Value) const = 0;
114
115   /// @}
116
117   /// @name Target Relaxation Interfaces
118   /// @{
119
120   /// mayNeedRelaxation - Check whether the given instruction may need
121   /// relaxation.
122   ///
123   /// \param Inst - The instruction to test.
124   virtual bool mayNeedRelaxation(const MCInst &Inst) const = 0;
125
126   /// fixupNeedsRelaxation - Target specific predicate for whether a given
127   /// fixup requires the associated instruction to be relaxed.
128   virtual bool fixupNeedsRelaxation(const MCFixup &Fixup,
129                                     uint64_t Value,
130                                     const MCInstFragment *DF,
131                                     const MCAsmLayout &Layout) const = 0;
132
133   /// RelaxInstruction - Relax the instruction in the given fragment to the next
134   /// wider instruction.
135   ///
136   /// \param Inst The instruction to relax, which may be the same as the
137   /// output.
138   /// \param [out] Res On return, the relaxed instruction.
139   virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
140
141   /// @}
142
143   /// getMinimumNopSize - Returns the minimum size of a nop in bytes on this
144   /// target. The assembler will use this to emit excess padding in situations
145   /// where the padding required for simple alignment would be less than the
146   /// minimum nop size.
147   ///
148   virtual unsigned getMinimumNopSize() const { return 1; }
149
150   /// writeNopData - Write an (optimal) nop sequence of Count bytes to the given
151   /// output. If the target cannot generate such a sequence, it should return an
152   /// error.
153   ///
154   /// \return - True on success.
155   virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
156
157   /// handleAssemblerFlag - Handle any target-specific assembler flags.
158   /// By default, do nothing.
159   virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {}
160 };
161
162 } // End llvm namespace
163
164 #endif