Fix 80-col viola.
[oota-llvm.git] / include / llvm / Target / TargetAsmBackend.h
1 //===-- llvm/Target/TargetAsmBackend.h - Target 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_TARGET_TARGETASMBACKEND_H
11 #define LLVM_TARGET_TARGETASMBACKEND_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 MCFixup;
20 class MCInst;
21 class MCObjectFormat;
22 class MCObjectWriter;
23 class MCSection;
24 template<typename T>
25 class SmallVectorImpl;
26 class raw_ostream;
27
28 /// TargetAsmBackend - Generic interface to target specific assembler backends.
29 class TargetAsmBackend {
30   TargetAsmBackend(const TargetAsmBackend &);   // DO NOT IMPLEMENT
31   void operator=(const TargetAsmBackend &);  // DO NOT IMPLEMENT
32 protected: // Can only create subclasses.
33   TargetAsmBackend();
34
35   unsigned HasReliableSymbolDifference : 1;
36   unsigned HasScatteredSymbols : 1;
37
38 public:
39   virtual ~TargetAsmBackend();
40
41   virtual const MCObjectFormat &getObjectFormat() const = 0;
42
43   /// createObjectWriter - Create a new MCObjectWriter instance for use by the
44   /// assembler backend to emit the final object file.
45   virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
46
47   /// hasReliableSymbolDifference - Check whether this target implements
48   /// accurate relocations for differences between symbols. If not, differences
49   /// between symbols will always be relocatable expressions and any references
50   /// to temporary symbols will be assumed to be in the same atom, unless they
51   /// reside in a different section.
52   ///
53   /// This should always be true (since it results in fewer relocations with no
54   /// loss of functionality), but is currently supported as a way to maintain
55   /// exact object compatibility with Darwin 'as' (on non-x86_64). It should
56   /// eventually should be eliminated.
57   bool hasReliableSymbolDifference() const {
58     return HasReliableSymbolDifference;
59   }
60
61   /// hasScatteredSymbols - Check whether this target supports scattered
62   /// symbols. If so, the assembler should assume that atoms can be scattered by
63   /// the linker. In particular, this means that the offsets between symbols
64   /// which are in distinct atoms is not known at link time, and the assembler
65   /// must generate fixups and relocations appropriately.
66   ///
67   /// Note that the assembler currently does not reason about atoms, instead it
68   /// assumes all temporary symbols reside in the "current atom".
69   bool hasScatteredSymbols() const { return HasScatteredSymbols; }
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   /// @}
95
96   /// ApplyFixup - Apply the \arg Value for given \arg Fixup into the provided
97   /// data fragment, at the offset specified by the fixup and following the
98   /// fixup kind as appropriate.
99   virtual void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
100                           uint64_t Value) const = 0;
101
102   /// @}
103
104   /// @name Target Relaxation Interfaces
105   /// @{
106
107   /// MayNeedRelaxation - Check whether the given instruction may need
108   /// relaxation.
109   ///
110   /// \param Inst - The instruction to test.
111   virtual bool MayNeedRelaxation(const MCInst &Inst) const = 0;
112
113   /// RelaxInstruction - Relax the instruction in the given fragment to the next
114   /// wider instruction.
115   ///
116   /// \param Inst - The instruction to relax, which may be the same as the
117   /// output.
118   /// \parm Res [output] - On return, the relaxed instruction.
119   virtual void RelaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
120
121   /// @}
122
123   /// WriteNopData - Write an (optimal) nop sequence of Count bytes to the given
124   /// output. If the target cannot generate such a sequence, it should return an
125   /// error.
126   ///
127   /// \return - True on success.
128   virtual bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
129
130   /// HandleAssemblerFlag - Handle any target-specific assembler flags.
131   /// By default, do nothing.
132   virtual void HandleAssemblerFlag(MCAssemblerFlag Flag) {}
133 };
134
135 } // End llvm namespace
136
137 #endif