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