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