Add some platform checks. Also fix a typo on a Makefile.
[oota-llvm.git] / include / llvm / LLVMContext.h
1 //===-- llvm/LLVMContext.h - Class for managing "global" state --*- 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 // This file declares LLVMContext, a container of "global" state in LLVM, such
11 // as the global type and constant uniquing tables.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LLVMCONTEXT_H
16 #define LLVM_LLVMCONTEXT_H
17
18 namespace llvm {
19
20 class LLVMContextImpl;
21 class StringRef;
22 class Instruction;
23 class Module;
24 class SMDiagnostic;
25 template <typename T> class SmallVectorImpl;
26
27 /// This is an important class for using LLVM in a threaded context.  It
28 /// (opaquely) owns and manages the core "global" data of LLVM's core 
29 /// infrastructure, including the type and constant uniquing tables.
30 /// LLVMContext itself provides no locking guarantees, so you should be careful
31 /// to have one context per thread.
32 class LLVMContext {
33 public:
34   LLVMContextImpl *const pImpl;
35   LLVMContext();
36   ~LLVMContext();
37   
38   // Pinned metadata names, which always have the same value.  This is a
39   // compile-time performance optimization, not a correctness optimization.
40   enum {
41     MD_dbg = 0,  // "dbg"
42     MD_tbaa = 1  // "tbaa"
43   };
44   
45   /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
46   /// This ID is uniqued across modules in the current LLVMContext.
47   unsigned getMDKindID(StringRef Name) const;
48   
49   /// getMDKindNames - Populate client supplied SmallVector with the name for
50   /// custom metadata IDs registered in this LLVMContext.
51   void getMDKindNames(SmallVectorImpl<StringRef> &Result) const;
52   
53   
54   typedef void (*InlineAsmDiagHandlerTy)(const SMDiagnostic&, void *Context,
55                                          unsigned LocCookie);
56   
57   /// setInlineAsmDiagnosticHandler - This method sets a handler that is invoked
58   /// when problems with inline asm are detected by the backend.  The first
59   /// argument is a function pointer and the second is a context pointer that
60   /// gets passed into the DiagHandler.
61   ///
62   /// LLVMContext doesn't take ownership or interpret either of these
63   /// pointers.
64   void setInlineAsmDiagnosticHandler(InlineAsmDiagHandlerTy DiagHandler,
65                                      void *DiagContext = 0);
66
67   /// getInlineAsmDiagnosticHandler - Return the diagnostic handler set by
68   /// setInlineAsmDiagnosticHandler.
69   InlineAsmDiagHandlerTy getInlineAsmDiagnosticHandler() const;
70
71   /// getInlineAsmDiagnosticContext - Return the diagnostic context set by
72   /// setInlineAsmDiagnosticHandler.
73   void *getInlineAsmDiagnosticContext() const;
74   
75   
76   /// emitError - Emit an error message to the currently installed error handler
77   /// with optional location information.  This function returns, so code should
78   /// be prepared to drop the erroneous construct on the floor and "not crash".
79   /// The generated code need not be correct.  The error message will be
80   /// implicitly prefixed with "error: " and should not end with a ".".
81   void emitError(unsigned LocCookie, StringRef ErrorStr);
82   void emitError(const Instruction *I, StringRef ErrorStr);
83   void emitError(StringRef ErrorStr);
84
85 private:
86   // DO NOT IMPLEMENT
87   LLVMContext(LLVMContext&);
88   void operator=(LLVMContext&);
89
90   /// addModule - Register a module as being instantiated in this context.  If
91   /// the context is deleted, the module will be deleted as well.
92   void addModule(Module*);
93   
94   /// removeModule - Unregister a module from this context.
95   void removeModule(Module*);
96   
97   // Module needs access to the add/removeModule methods.
98   friend class Module;
99 };
100
101 /// getGlobalContext - Returns a global context.  This is for LLVM clients that
102 /// only care about operating on a single thread.
103 extern LLVMContext &getGlobalContext();
104
105 }
106
107 #endif