aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Frontend/CompilerInstance.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/clang/Frontend/CompilerInstance.h')
-rw-r--r--include/clang/Frontend/CompilerInstance.h199
1 files changed, 199 insertions, 0 deletions
diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h
new file mode 100644
index 0000000000..c503d7a09f
--- /dev/null
+++ b/include/clang/Frontend/CompilerInstance.h
@@ -0,0 +1,199 @@
+//===-- CompilerInstance.h - Clang Compiler Instance ------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_
+#define LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_
+
+#include "clang/Frontend/CompilerInvocation.h"
+#include "llvm/ADT/OwningPtr.h"
+
+namespace llvm {
+class LLVMContext;
+}
+
+namespace clang {
+class Diagnostic;
+class DiagnosticClient;
+class TargetInfo;
+
+/// CompilerInstance - Helper class for managing a single instance of the Clang
+/// compiler.
+///
+/// The CompilerInstance serves two purposes:
+/// (1) It manages the various objects which are necessary to run the compiler,
+/// for example the preprocessor, the target information, and the AST
+/// context.
+/// (2) It provides utility routines for constructing and manipulating the
+/// common Clang objects.
+///
+/// The compiler instance generally owns the instance of all the objects that it
+/// manages. However, clients can still share objects by manually setting the
+/// object and retaking ownership prior to destroying the CompilerInstance.
+///
+/// The compiler instance is intended to simplify clients, but not to lock them
+/// in to the compiler instance for everything. When possible, utility functions
+/// come in two forms; a short form that reuses the CompilerInstance objects,
+/// and a long form that takes explicit instances of any required objects.
+class CompilerInstance {
+ /// The LLVM context used for this instance.
+ llvm::LLVMContext *LLVMContext;
+ bool OwnsLLVMContext;
+
+ /// The options used in this compiler instance.
+ CompilerInvocation Invocation;
+
+ /// The diagnostics engine instance.
+ llvm::OwningPtr<Diagnostic> Diagnostics;
+
+ /// The diagnostics client instance.
+ llvm::OwningPtr<DiagnosticClient> DiagClient;
+
+ /// The target being compiled for.
+ llvm::OwningPtr<TargetInfo> Target;
+
+public:
+ /// Create a new compiler instance with the given LLVM context, optionally
+ /// taking ownership of it.
+ CompilerInstance(llvm::LLVMContext *_LLVMContext = 0,
+ bool _OwnsLLVMContext = true);
+ ~CompilerInstance();
+
+ /// @name LLVM Context
+ /// {
+
+ llvm::LLVMContext &getLLVMContext() { return *LLVMContext; }
+
+ /// setLLVMContext - Replace the current LLVM context and take ownership of
+ /// \arg Value.
+ void setLLVMContext(llvm::LLVMContext *Value, bool TakeOwnership = true) {
+ LLVMContext = Value;
+ OwnsLLVMContext = TakeOwnership;
+ }
+
+ /// }
+ /// @name Compiler Invocation and Options
+ /// {
+
+ CompilerInvocation &getInvocation() { return Invocation; }
+ const CompilerInvocation &getInvocation() const { return Invocation; }
+ void setInvocation(const CompilerInvocation &Value) { Invocation = Value; }
+
+ /// }
+ /// @name Forwarding Methods
+ /// {
+
+ AnalyzerOptions &getAnalyzerOpts() {
+ return Invocation.getAnalyzerOpts();
+ }
+ const AnalyzerOptions &getAnalyzerOpts() const {
+ return Invocation.getAnalyzerOpts();
+ }
+
+ CodeGenOptions &getCodeGenOpts() {
+ return Invocation.getCodeGenOpts();
+ }
+ const CodeGenOptions &getCodeGenOpts() const {
+ return Invocation.getCodeGenOpts();
+ }
+
+ DependencyOutputOptions &getDependencyOutputOpts() {
+ return Invocation.getDependencyOutputOpts();
+ }
+ const DependencyOutputOptions &getDependencyOutputOpts() const {
+ return Invocation.getDependencyOutputOpts();
+ }
+
+ DiagnosticOptions &getDiagnosticOpts() {
+ return Invocation.getDiagnosticOpts();
+ }
+ const DiagnosticOptions &getDiagnosticOpts() const {
+ return Invocation.getDiagnosticOpts();
+ }
+
+ FrontendOptions &getFrontendOpts() {
+ return Invocation.getFrontendOpts();
+ }
+ const FrontendOptions &getFrontendOpts() const {
+ return Invocation.getFrontendOpts();
+ }
+
+ HeaderSearchOptions &getHeaderSearchOpts() {
+ return Invocation.getHeaderSearchOpts();
+ }
+ const HeaderSearchOptions &getHeaderSearchOpts() const {
+ return Invocation.getHeaderSearchOpts();
+ }
+
+ LangOptions &getLangOpts() {
+ return Invocation.getLangOpts();
+ }
+ const LangOptions &getLangOpts() const {
+ return Invocation.getLangOpts();
+ }
+
+ PreprocessorOptions &getPreprocessorOpts() {
+ return Invocation.getPreprocessorOpts();
+ }
+ const PreprocessorOptions &getPreprocessorOpts() const {
+ return Invocation.getPreprocessorOpts();
+ }
+
+ PreprocessorOutputOptions &getPreprocessorOutputOpts() {
+ return Invocation.getPreprocessorOutputOpts();
+ }
+ const PreprocessorOutputOptions &getPreprocessorOutputOpts() const {
+ return Invocation.getPreprocessorOutputOpts();
+ }
+
+ /// }
+ /// @name Diagnostics Engine
+ /// {
+
+ Diagnostic &getDiagnostics() const { return *Diagnostics; }
+
+ /// takeDiagnostics - Remove the current diagnostics engine and give ownership
+ /// to the caller.
+ Diagnostic *takeDiagnostics() { return Diagnostics.take(); }
+
+ /// setDiagnostics - Replace the current diagnostics engine; the compiler
+ /// instance takes ownership of \arg Value.
+ void setDiagnostics(Diagnostic *Value) { Diagnostics.reset(Value); }
+
+ DiagnosticClient &getDiagnosticClient() const { return *DiagClient; }
+
+ /// takeDiagnosticClient - Remove the current diagnostics client and give
+ /// ownership to the caller.
+ DiagnosticClient *takeDiagnosticClient() { return DiagClient.take(); }
+
+ /// setDiagnosticClient - Replace the current diagnostics client; the compiler
+ /// instance takes ownership of \arg Value.
+ void setDiagnosticClient(DiagnosticClient *Value) {
+ DiagClient.reset(Value);
+ }
+
+ /// }
+ /// @name Target Info
+ /// {
+
+ TargetInfo &getTarget() const { return *Target; }
+
+ /// takeTarget - Remove the current diagnostics engine and give ownership
+ /// to the caller.
+ TargetInfo *takeTarget() { return Target.take(); }
+
+ /// setTarget - Replace the current diagnostics engine; the compiler
+ /// instance takes ownership of \arg Value.
+ void setTarget(TargetInfo *Value) { Target.reset(Value); }
+
+ /// }
+};
+
+} // end namespace clang
+
+#endif