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.

114 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_IR_LLVMCONTEXT_H
  15. #define LLVM_IR_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. MD_invariant_load = 6 // "invariant.load"
  45. };
  46. /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
  47. /// This ID is uniqued across modules in the current LLVMContext.
  48. unsigned getMDKindID(StringRef Name) const;
  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. typedef void (*InlineAsmDiagHandlerTy)(const SMDiagnostic&, void *Context,
  53. unsigned LocCookie);
  54. /// setInlineAsmDiagnosticHandler - This method sets a handler that is invoked
  55. /// when problems with inline asm are detected by the backend. The first
  56. /// argument is a function pointer and the second is a context pointer that
  57. /// gets passed into the DiagHandler.
  58. ///
  59. /// LLVMContext doesn't take ownership or interpret either of these
  60. /// pointers.
  61. void setInlineAsmDiagnosticHandler(InlineAsmDiagHandlerTy DiagHandler,
  62. void *DiagContext = 0);
  63. /// getInlineAsmDiagnosticHandler - Return the diagnostic handler set by
  64. /// setInlineAsmDiagnosticHandler.
  65. InlineAsmDiagHandlerTy getInlineAsmDiagnosticHandler() const;
  66. /// getInlineAsmDiagnosticContext - Return the diagnostic context set by
  67. /// setInlineAsmDiagnosticHandler.
  68. void *getInlineAsmDiagnosticContext() const;
  69. /// emitError - Emit an error message to the currently installed error handler
  70. /// with optional location information. This function returns, so code should
  71. /// be prepared to drop the erroneous construct on the floor and "not crash".
  72. /// The generated code need not be correct. The error message will be
  73. /// implicitly prefixed with "error: " and should not end with a ".".
  74. void emitError(unsigned LocCookie, const Twine &ErrorStr);
  75. void emitError(const Instruction *I, const Twine &ErrorStr);
  76. void emitError(const Twine &ErrorStr);
  77. private:
  78. LLVMContext(LLVMContext&) LLVM_DELETED_FUNCTION;
  79. void operator=(LLVMContext&) LLVM_DELETED_FUNCTION;
  80. /// addModule - Register a module as being instantiated in this context. If
  81. /// the context is deleted, the module will be deleted as well.
  82. void addModule(Module*);
  83. /// removeModule - Unregister a module from this context.
  84. void removeModule(Module*);
  85. // Module needs access to the add/removeModule methods.
  86. friend class Module;
  87. };
  88. /// getGlobalContext - Returns a global context. This is for LLVM clients that
  89. /// only care about operating on a single thread.
  90. extern LLVMContext &getGlobalContext();
  91. }
  92. #endif