Trailing whitespace.
[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/System/DataTypes.h"
14
15 namespace llvm {
16 class MCDataFragment;
17 class MCFixup;
18 class MCInst;
19 class MCObjectFormat;
20 class MCObjectWriter;
21 class MCSection;
22 template<typename T>
23 class SmallVectorImpl;
24 class Target;
25 class raw_ostream;
26
27 /// TargetAsmBackend - Generic interface to target specific assembler backends.
28 class TargetAsmBackend {
29   TargetAsmBackend(const TargetAsmBackend &);   // DO NOT IMPLEMENT
30   void operator=(const TargetAsmBackend &);  // DO NOT IMPLEMENT
31 protected: // Can only create subclasses.
32   TargetAsmBackend(const Target &);
33
34   /// TheTarget - The Target that this machine was created for.
35   const Target &TheTarget;
36
37   unsigned HasReliableSymbolDifference : 1;
38   unsigned HasScatteredSymbols : 1;
39
40 public:
41   virtual ~TargetAsmBackend();
42
43   const Target &getTarget() const { return TheTarget; }
44
45   virtual const MCObjectFormat &getObjectFormat() const = 0;
46
47   /// createObjectWriter - Create a new MCObjectWriter instance for use by the
48   /// assembler backend to emit the final object file.
49   virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const = 0;
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   /// hasScatteredSymbols - Check whether this target supports scattered
66   /// symbols. If so, the assembler should assume that atoms can be scattered by
67   /// the linker. In particular, this means that the offsets between symbols
68   /// which are in distinct atoms is not known at link time, and the assembler
69   /// must generate fixups and relocations appropriately.
70   ///
71   /// Note that the assembler currently does not reason about atoms, instead it
72   /// assumes all temporary symbols reside in the "current atom".
73   bool hasScatteredSymbols() const { return HasScatteredSymbols; }
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   /// isVirtualSection - Check whether the given section is "virtual", that is
90   /// has no actual object file contents.
91   virtual bool isVirtualSection(const MCSection &Section) const = 0;
92
93   /// getPointerSize - Get the pointer size in bytes.
94   virtual unsigned getPointerSize() const = 0;
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, MCDataFragment &Fragment,
100                           uint64_t Value) const = 0;
101
102   /// MayNeedRelaxation - Check whether the given instruction may need
103   /// relaxation.
104   ///
105   /// \param Inst - The instruction to test.
106   virtual bool MayNeedRelaxation(const MCInst &Inst) const = 0;
107
108   /// RelaxInstruction - Relax the instruction in the given fragment to the next
109   /// wider instruction.
110   ///
111   /// \param Inst - The instruction to relax, which may be the same as the
112   /// output.
113   /// \parm Res [output] - On return, the relaxed instruction.
114   virtual void RelaxInstruction(const MCInst &Inst, MCInst &Res) const = 0;
115
116   /// WriteNopData - Write an (optimal) nop sequence of Count bytes to the given
117   /// output. If the target cannot generate such a sequence, it should return an
118   /// error.
119   ///
120   /// \return - True on success.
121   virtual bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const = 0;
122 };
123
124 } // End llvm namespace
125
126 #endif