Delete LoopPass::runOnFunctionBody. It was never used or implemented.
[oota-llvm.git] / include / llvm / MC / MCContext.h
1 //===- MCContext.h - Machine Code Context -----------------------*- 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_MCCONTEXT_H
11 #define LLVM_MC_MCCONTEXT_H
12
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/StringMap.h"
15 #include "llvm/Support/Allocator.h"
16
17 namespace llvm {
18   class MCValue;
19   class MCSection;
20   class MCSymbol;
21
22   /// MCContext - Context object for machine code objects.
23   class MCContext {
24     MCContext(const MCContext&); // DO NOT IMPLEMENT
25     MCContext &operator=(const MCContext&); // DO NOT IMPLEMENT
26
27     /// Sections - Bindings of names to allocated sections.
28     StringMap<MCSection*> Sections;
29
30     /// Symbols - Bindings of names to symbols.
31     StringMap<MCSymbol*> Symbols;
32
33     /// SymbolValues - Bindings of symbols to values.
34     DenseMap<MCSymbol*, MCValue> SymbolValues;
35
36     /// Allocator - Allocator object used for creating machine code objects.
37     ///
38     /// We use a bump pointer allocator to avoid the need to track all allocated
39     /// objects.
40     BumpPtrAllocator Allocator;
41
42   public:
43     MCContext();
44     ~MCContext();
45
46     /// GetSection - Get or create a new section with the given @param Name.
47     MCSection *GetSection(const char *Name);
48     
49     /// CreateSymbol - Create a new symbol with the specified @param Name.
50     ///
51     /// @param Name - The symbol name, which must be unique across all symbols.
52     MCSymbol *CreateSymbol(const char *Name);
53
54     /// GetOrCreateSymbol - Lookup the symbol inside with the specified
55     /// @param Name.  If it exists, return it.  If not, create a forward
56     /// reference and return it.
57     ///
58     /// @param Name - The symbol name, which must be unique across all symbols.
59     MCSymbol *GetOrCreateSymbol(const char *Name);
60     
61     /// CreateTemporarySymbol - Create a new temporary symbol with the specified
62     /// @param Name.
63     ///
64     /// @param Name - The symbol name, for debugging purposes only, temporary
65     /// symbols do not surive assembly. If non-empty the name must be unique
66     /// across all symbols.
67     MCSymbol *CreateTemporarySymbol(const char *Name = "");
68
69     /// LookupSymbol - Get the symbol for @param Name, or null.
70     MCSymbol *LookupSymbol(const char *Name) const;
71
72     /// ClearSymbolValue - Erase a value binding for @param Symbol, if one
73     /// exists.
74     void ClearSymbolValue(MCSymbol *Symbol);
75
76     /// SetSymbolValue - Set the value binding for @param Symbol to @param
77     /// Value.
78     void SetSymbolValue(MCSymbol *Symbol, const MCValue &Value);
79
80     /// GetSymbolValue - Return the current value for @param Symbol, or null if
81     /// none exists.
82     const MCValue *GetSymbolValue(MCSymbol *Symbol) const;
83
84     void *Allocate(unsigned Size, unsigned Align = 8) {
85       return Allocator.Allocate(Size, Align);
86     }
87     void Deallocate(void *Ptr) { 
88     }
89   };
90
91 } // end namespace llvm
92
93 // operator new and delete aren't allowed inside namespaces.
94 // The throw specifications are mandated by the standard.
95 /// @brief Placement new for using the MCContext's allocator.
96 ///
97 /// This placement form of operator new uses the MCContext's allocator for
98 /// obtaining memory. It is a non-throwing new, which means that it returns
99 /// null on error. (If that is what the allocator does. The current does, so if
100 /// this ever changes, this operator will have to be changed, too.)
101 /// Usage looks like this (assuming there's an MCContext 'Context' in scope):
102 /// @code
103 /// // Default alignment (16)
104 /// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments);
105 /// // Specific alignment
106 /// IntegerLiteral *Ex2 = new (Context, 8) IntegerLiteral(arguments);
107 /// @endcode
108 /// Please note that you cannot use delete on the pointer; it must be
109 /// deallocated using an explicit destructor call followed by
110 /// @c Context.Deallocate(Ptr).
111 ///
112 /// @param Bytes The number of bytes to allocate. Calculated by the compiler.
113 /// @param C The MCContext that provides the allocator.
114 /// @param Alignment The alignment of the allocated memory (if the underlying
115 ///                  allocator supports it).
116 /// @return The allocated memory. Could be NULL.
117 inline void *operator new(size_t Bytes, llvm::MCContext &C,
118                           size_t Alignment = 16) throw () {
119   return C.Allocate(Bytes, Alignment);
120 }
121 /// @brief Placement delete companion to the new above.
122 ///
123 /// This operator is just a companion to the new above. There is no way of
124 /// invoking it directly; see the new operator for more details. This operator
125 /// is called implicitly by the compiler if a placement new expression using
126 /// the MCContext throws in the object constructor.
127 inline void operator delete(void *Ptr, llvm::MCContext &C, size_t)
128               throw () {
129   C.Deallocate(Ptr);
130 }
131
132 /// This placement form of operator new[] uses the MCContext's allocator for
133 /// obtaining memory. It is a non-throwing new[], which means that it returns
134 /// null on error.
135 /// Usage looks like this (assuming there's an MCContext 'Context' in scope):
136 /// @code
137 /// // Default alignment (16)
138 /// char *data = new (Context) char[10];
139 /// // Specific alignment
140 /// char *data = new (Context, 8) char[10];
141 /// @endcode
142 /// Please note that you cannot use delete on the pointer; it must be
143 /// deallocated using an explicit destructor call followed by
144 /// @c Context.Deallocate(Ptr).
145 ///
146 /// @param Bytes The number of bytes to allocate. Calculated by the compiler.
147 /// @param C The MCContext that provides the allocator.
148 /// @param Alignment The alignment of the allocated memory (if the underlying
149 ///                  allocator supports it).
150 /// @return The allocated memory. Could be NULL.
151 inline void *operator new[](size_t Bytes, llvm::MCContext& C,
152                             size_t Alignment = 16) throw () {
153   return C.Allocate(Bytes, Alignment);
154 }
155
156 /// @brief Placement delete[] companion to the new[] above.
157 ///
158 /// This operator is just a companion to the new[] above. There is no way of
159 /// invoking it directly; see the new[] operator for more details. This operator
160 /// is called implicitly by the compiler if a placement new[] expression using
161 /// the MCContext throws in the object constructor.
162 inline void operator delete[](void *Ptr, llvm::MCContext &C) throw () {
163   C.Deallocate(Ptr);
164 }
165
166 #endif