Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
4.1 KiB

  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. #ifndef LLVM_LLVMCONTEXT_H
  15. #define LLVM_LLVMCONTEXT_H
  16. #include "llvm/Support/Compiler.h"
  17. namespace llvm {
  18. class LLVMContextImpl;
  19. class StringRef;
  20. class Twine;
  21. class Instruction;
  22. class Module;
  23. class SMDiagnostic;
  24. template <typename T> class SmallVectorImpl;
  25. /// This is an important class for using LLVM in a threaded context. It
  26. /// (opaquely) owns and manages the core "global" data of LLVM's core
  27. /// infrastructure, including the type and constant uniquing tables.
  28. /// LLVMContext itself provides no locking guarantees, so you should be careful
  29. /// to have one context per thread.
  30. class LLVMContext {
  31. public:
  32. LLVMContextImpl *const pImpl;
  33. LLVMContext();
  34. ~LLVMContext();
  35. // Pinned metadata names, which always have the same value. This is a
  36. // compile-time performance optimization, not a correctness optimization.
  37. enum {
  38. MD_dbg = 0, // "dbg"
  39. MD_tbaa = 1, // "tbaa"
  40. MD_prof = 2, // "prof"
  41. MD_fpmath = 3, // "fpmath"
  42. MD_range = 4, // "range"
  43. MD_tbaa_struct = 5 // "tbaa.struct"
  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. /// getMDKindNames - Populate client supplied SmallVector with the name for
  49. /// custom metadata IDs registered in this LLVMContext.
  50. void getMDKindNames(SmallVectorImpl<StringRef> &Result) const;
  51. typedef void (*InlineAsmDiagHandlerTy)(const SMDiagnostic&, void *Context,
  52. unsigned LocCookie);
  53. /// setInlineAsmDiagnosticHandler - This method sets a handler that is invoked
  54. /// when problems with inline asm are detected by the backend. The first
  55. /// argument is a function pointer and the second is a context pointer that
  56. /// gets passed into the DiagHandler.
  57. ///
  58. /// LLVMContext doesn't take ownership or interpret either of these
  59. /// pointers.
  60. void setInlineAsmDiagnosticHandler(InlineAsmDiagHandlerTy DiagHandler,
  61. void *DiagContext = 0);
  62. /// getInlineAsmDiagnosticHandler - Return the diagnostic handler set by
  63. /// setInlineAsmDiagnosticHandler.
  64. InlineAsmDiagHandlerTy getInlineAsmDiagnosticHandler() const;
  65. /// getInlineAsmDiagnosticContext - Return the diagnostic context set by
  66. /// setInlineAsmDiagnosticHandler.
  67. void *getInlineAsmDiagnosticContext() const;
  68. /// emitError - Emit an error message to the currently installed error handler
  69. /// with optional location information. This function returns, so code should
  70. /// be prepared to drop the erroneous construct on the floor and "not crash".
  71. /// The generated code need not be correct. The error message will be
  72. /// implicitly prefixed with "error: " and should not end with a ".".
  73. void emitError(unsigned LocCookie, const Twine &ErrorStr);
  74. void emitError(const Instruction *I, const Twine &ErrorStr);
  75. void emitError(const Twine &ErrorStr);
  76. private:
  77. LLVMContext(LLVMContext&) LLVM_DELETED_FUNCTION;
  78. void operator=(LLVMContext&) LLVM_DELETED_FUNCTION;
  79. /// addModule - Register a module as being instantiated in this context. If
  80. /// the context is deleted, the module will be deleted as well.
  81. void addModule(Module*);
  82. /// removeModule - Unregister a module from this context.
  83. void removeModule(Module*);
  84. // Module needs access to the add/removeModule methods.
  85. friend class Module;
  86. };
  87. /// getGlobalContext - Returns a global context. This is for LLVM clients that
  88. /// only care about operating on a single thread.
  89. extern LLVMContext &getGlobalContext();
  90. }
  91. #endif