[cfe-commits] r87078 - in /cfe/trunk: include/clang/Frontend/CompilerInstance.h lib/Frontend/CMakeLists.txt lib/Frontend/CompilerInstance.cpp tools/clang-cc/clang-cc.cpp
Daniel Dunbar
daniel at zuster.org
Thu Nov 12 19:51:45 PST 2009
Author: ddunbar
Date: Thu Nov 12 21:51:44 2009
New Revision: 87078
URL: http://llvm.org/viewvc/llvm-project?rev=87078&view=rev
Log:
Add CompilerInstance, and starting moving clang-cc to it.
- The design philosophy is in the CompilerInstance doxyment, if you don't agree
with it now would be a good time to speak up.
Added:
cfe/trunk/include/clang/Frontend/CompilerInstance.h
cfe/trunk/lib/Frontend/CompilerInstance.cpp
Modified:
cfe/trunk/lib/Frontend/CMakeLists.txt
cfe/trunk/tools/clang-cc/clang-cc.cpp
Added: cfe/trunk/include/clang/Frontend/CompilerInstance.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=87078&view=auto
==============================================================================
--- cfe/trunk/include/clang/Frontend/CompilerInstance.h (added)
+++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Thu Nov 12 21:51:44 2009
@@ -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
Modified: cfe/trunk/lib/Frontend/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CMakeLists.txt?rev=87078&r1=87077&r2=87078&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CMakeLists.txt (original)
+++ cfe/trunk/lib/Frontend/CMakeLists.txt Thu Nov 12 21:51:44 2009
@@ -6,6 +6,7 @@
AnalysisConsumer.cpp
Backend.cpp
CacheTokens.cpp
+ CompilerInstance.cpp
DeclXML.cpp
DependencyFile.cpp
DiagChecker.cpp
Added: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=87078&view=auto
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (added)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Thu Nov 12 21:51:44 2009
@@ -0,0 +1,25 @@
+//===--- CompilerInstance.cpp ---------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/TargetInfo.h"
+#include "llvm/LLVMContext.h"
+using namespace clang;
+
+CompilerInstance::CompilerInstance(llvm::LLVMContext *_LLVMContext,
+ bool _OwnsLLVMContext)
+ : LLVMContext(_LLVMContext),
+ OwnsLLVMContext(_OwnsLLVMContext) {
+}
+
+CompilerInstance::~CompilerInstance() {
+ if (OwnsLLVMContext)
+ delete LLVMContext;
+}
Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=87078&r1=87077&r2=87078&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Thu Nov 12 21:51:44 2009
@@ -31,6 +31,7 @@
#include "clang/Frontend/AnalysisConsumer.h"
#include "clang/Frontend/ChainedDiagnosticClient.h"
#include "clang/Frontend/CommandLineSourceLoc.h"
+#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/DependencyOutputOptions.h"
#include "clang/Frontend/FixItRewriter.h"
@@ -320,15 +321,15 @@
/// anything.
llvm::Timer *ClangFrontendTimer = 0;
-static llvm::raw_ostream *ComputeOutFile(const CompilerInvocation &CompOpts,
+static llvm::raw_ostream *ComputeOutFile(const FrontendOptions &Opts,
const std::string &InFile,
const char *Extension,
bool Binary,
llvm::sys::Path& OutPath) {
llvm::raw_ostream *Ret;
std::string OutFile;
- if (!CompOpts.getFrontendOpts().OutputFile.empty())
- OutFile = CompOpts.getFrontendOpts().OutputFile;
+ if (!Opts.OutputFile.empty())
+ OutFile = Opts.OutputFile;
else if (InFile == "-") {
OutFile = "-";
} else if (Extension) {
@@ -379,25 +380,25 @@
return AddedFixItLocation;
}
-static ASTConsumer *CreateConsumerAction(const CompilerInvocation &CompOpts,
+static ASTConsumer *CreateConsumerAction(CompilerInstance &CI,
Preprocessor &PP,
const std::string &InFile,
ProgActions PA,
llvm::OwningPtr<llvm::raw_ostream> &OS,
- llvm::sys::Path &OutPath,
- llvm::LLVMContext& Context) {
- const FrontendOptions &FEOpts = CompOpts.getFrontendOpts();
+ llvm::sys::Path &OutPath) {
+ const FrontendOptions &FEOpts = CI.getFrontendOpts();
switch (PA) {
default:
return 0;
case ASTPrint:
- OS.reset(ComputeOutFile(CompOpts, InFile, 0, false, OutPath));
+ OS.reset(ComputeOutFile(CI.getFrontendOpts(), InFile, 0, false, OutPath));
return CreateASTPrinter(OS.get());
case ASTPrintXML:
- OS.reset(ComputeOutFile(CompOpts, InFile, "xml", false, OutPath));
+ OS.reset(ComputeOutFile(CI.getFrontendOpts(), InFile, "xml", false,
+ OutPath));
return CreateASTPrinterXML(OS.get());
case ASTDump:
@@ -419,15 +420,18 @@
BackendAction Act;
if (ProgAction == EmitAssembly) {
Act = Backend_EmitAssembly;
- OS.reset(ComputeOutFile(CompOpts, InFile, "s", true, OutPath));
+ OS.reset(ComputeOutFile(CI.getFrontendOpts(), InFile, "s", true,
+ OutPath));
} else if (ProgAction == EmitLLVM) {
Act = Backend_EmitLL;
- OS.reset(ComputeOutFile(CompOpts, InFile, "ll", true, OutPath));
+ OS.reset(ComputeOutFile(CI.getFrontendOpts(), InFile, "ll", true,
+ OutPath));
} else if (ProgAction == EmitLLVMOnly) {
Act = Backend_EmitNothing;
} else {
Act = Backend_EmitBC;
- OS.reset(ComputeOutFile(CompOpts, InFile, "bc", true, OutPath));
+ OS.reset(ComputeOutFile(CI.getFrontendOpts(), InFile, "bc", true,
+ OutPath));
}
// Fix-its can change semantics, disallow with any IRgen action.
@@ -437,15 +441,15 @@
}
return CreateBackendConsumer(Act, PP.getDiagnostics(), PP.getLangOptions(),
- CompOpts.getCodeGenOpts(), InFile, OS.get(),
- Context);
+ CI.getCodeGenOpts(), InFile, OS.get(),
+ CI.getLLVMContext());
}
case RewriteObjC:
- OS.reset(ComputeOutFile(CompOpts, InFile, "cpp", true, OutPath));
+ OS.reset(ComputeOutFile(CI.getFrontendOpts(), InFile, "cpp", true, OutPath));
return CreateObjCRewriter(InFile, OS.get(), PP.getDiagnostics(),
PP.getLangOptions(),
- CompOpts.getDiagnosticOpts().NoRewriteMacros);
+ CI.getDiagnosticOpts().NoRewriteMacros);
case RewriteBlocks:
return CreateBlockRewriter(InFile, PP.getDiagnostics(),
@@ -464,11 +468,11 @@
///
/// \return The AST source, or null on failure.
static ExternalASTSource *ReadPCHFile(llvm::StringRef Path,
- const CompilerInvocation &CompOpts,
+ const std::string Sysroot,
Preprocessor &PP,
ASTContext &Context) {
// If the user specified -isysroot, it will be used for relocatable PCH files.
- const char *isysrootPCH = CompOpts.getHeaderSearchOpts().Sysroot.c_str();
+ const char *isysrootPCH = Sysroot.c_str();
if (isysrootPCH[0] == '\0')
isysrootPCH = 0;
@@ -496,10 +500,9 @@
/// ProcessInputFile - Process a single input file with the specified state.
///
-static void ProcessInputFile(const CompilerInvocation &CompOpts,
- Preprocessor &PP, const std::string &InFile,
- ProgActions PA, llvm::LLVMContext& Context) {
- const FrontendOptions &FEOpts = CompOpts.getFrontendOpts();
+static void ProcessInputFile(CompilerInstance &CI, Preprocessor &PP,
+ const std::string &InFile, ProgActions PA) {
+ const FrontendOptions &FEOpts = CI.getFrontendOpts();
llvm::OwningPtr<llvm::raw_ostream> OS;
llvm::OwningPtr<ASTConsumer> Consumer;
FixItRewriter *FixItRewrite = 0;
@@ -508,8 +511,7 @@
switch (PA) {
default:
- Consumer.reset(CreateConsumerAction(CompOpts, PP, InFile, PA, OS, OutPath,
- Context));
+ Consumer.reset(CreateConsumerAction(CI, PP, InFile, PA, OS, OutPath));
if (!Consumer.get()) {
PP.getDiagnostics().Report(diag::err_fe_invalid_ast_action);
return;
@@ -517,24 +519,24 @@
break;
case EmitHTML:
- OS.reset(ComputeOutFile(CompOpts, InFile, 0, true, OutPath));
+ OS.reset(ComputeOutFile(CI.getFrontendOpts(), InFile, 0, true, OutPath));
Consumer.reset(CreateHTMLPrinter(OS.get(), PP));
break;
case RunAnalysis:
Consumer.reset(CreateAnalysisConsumer(PP, FEOpts.OutputFile,
- CompOpts.getAnalyzerOpts()));
+ CI.getAnalyzerOpts()));
break;
case GeneratePCH: {
- const std::string &Sysroot = CompOpts.getHeaderSearchOpts().Sysroot;
+ const std::string &Sysroot = CI.getHeaderSearchOpts().Sysroot;
bool Relocatable = FEOpts.RelocatablePCH;
if (Relocatable && Sysroot.empty()) {
PP.Diag(SourceLocation(), diag::err_relocatable_without_without_isysroot);
Relocatable = false;
}
- OS.reset(ComputeOutFile(CompOpts, InFile, 0, true, OutPath));
+ OS.reset(ComputeOutFile(CI.getFrontendOpts(), InFile, 0, true, OutPath));
if (Relocatable)
Consumer.reset(CreatePCHGenerator(PP, OS.get(), Sysroot.c_str()));
else
@@ -557,14 +559,14 @@
llvm::errs() << "ERROR: PTH requires an seekable file for output!\n";
::exit(1);
}
- OS.reset(ComputeOutFile(CompOpts, InFile, 0, true, OutPath));
+ OS.reset(ComputeOutFile(CI.getFrontendOpts(), InFile, 0, true, OutPath));
break;
case PrintPreprocessedInput:
case ParsePrintCallbacks:
case RewriteMacros:
case RewriteTest:
- OS.reset(ComputeOutFile(CompOpts, InFile, 0, true, OutPath));
+ OS.reset(ComputeOutFile(CI.getFrontendOpts(), InFile, 0, true, OutPath));
break;
}
@@ -585,7 +587,7 @@
llvm::OwningPtr<ASTContext> ContextOwner;
llvm::OwningPtr<ExternalASTSource> Source;
const std::string &ImplicitPCHInclude =
- CompOpts.getPreprocessorOpts().getImplicitPCHInclude();
+ CI.getPreprocessorOpts().getImplicitPCHInclude();
if (Consumer) {
ContextOwner.reset(new ASTContext(PP.getLangOptions(),
PP.getSourceManager(),
@@ -597,7 +599,8 @@
/* size_reserve = */0));
if (!ImplicitPCHInclude.empty()) {
- Source.reset(ReadPCHFile(ImplicitPCHInclude, CompOpts, PP,
+ Source.reset(ReadPCHFile(ImplicitPCHInclude,
+ CI.getHeaderSearchOpts().Sysroot, PP,
*ContextOwner));
if (!Source)
return;
@@ -613,7 +616,7 @@
// Initialize the main file entry. This needs to be delayed until after PCH
// has loaded.
- if (InitializeSourceManager(PP, CompOpts.getFrontendOpts(), InFile))
+ if (InitializeSourceManager(PP, CI.getFrontendOpts(), InFile))
return;
CodeCompleteConsumer *(*CreateCodeCompleter)(Sema &, void *) = 0;
@@ -648,7 +651,7 @@
// Initialize the main file entry. This needs to be delayed until after PCH
// has loaded.
- if (InitializeSourceManager(PP, CompOpts.getFrontendOpts(), InFile))
+ if (InitializeSourceManager(PP, CI.getFrontendOpts(), InFile))
return;
// Run the preprocessor actions.
@@ -698,8 +701,7 @@
break;
case PrintPreprocessedInput:
- DoPrintPreprocessedInput(PP, OS.get(),
- CompOpts.getPreprocessorOutputOpts());
+ DoPrintPreprocessedInput(PP, OS.get(), CI.getPreprocessorOutputOpts());
break;
case RewriteMacros:
@@ -735,7 +737,7 @@
ContextOwner.reset();
}
- if (CompOpts.getDiagnosticOpts().VerifyDiagnostics)
+ if (CI.getDiagnosticOpts().VerifyDiagnostics)
if (CheckDiagnostics(PP))
exit(1);
@@ -759,15 +761,13 @@
/// ProcessInputFile - Process a single AST input file with the specified state.
///
-static void ProcessASTInputFile(const CompilerInvocation &CompOpts,
- const std::string &InFile, ProgActions PA,
- Diagnostic &Diags, FileManager &FileMgr,
- llvm::LLVMContext& Context) {
- const FrontendOptions &FEOpts = CompOpts.getFrontendOpts();
+static void ProcessASTInputFile(CompilerInstance &CI, const std::string &InFile,
+ ProgActions PA, FileManager &FileMgr) {
+ const FrontendOptions &FEOpts = CI.getFrontendOpts();
std::string Error;
llvm::OwningPtr<ASTUnit> AST(ASTUnit::LoadFromPCHFile(InFile, &Error));
if (!AST) {
- Diags.Report(diag::err_fe_invalid_ast_file) << Error;
+ CI.getDiagnostics().Report(diag::err_fe_invalid_ast_file) << Error;
return;
}
@@ -775,11 +775,10 @@
llvm::OwningPtr<llvm::raw_ostream> OS;
llvm::sys::Path OutPath;
- llvm::OwningPtr<ASTConsumer> Consumer(CreateConsumerAction(CompOpts, PP,
- InFile, PA, OS,
- OutPath, Context));
+ llvm::OwningPtr<ASTConsumer> Consumer(CreateConsumerAction(CI, PP, InFile, PA,
+ OS, OutPath));
if (!Consumer.get()) {
- Diags.Report(diag::err_fe_invalid_ast_action);
+ CI.getDiagnostics().Report(diag::err_fe_invalid_ast_action);
return;
}
@@ -793,9 +792,9 @@
AST->getSourceManager().createMainFileIDForMemBuffer(SB);
// Stream the input AST to the consumer.
- Diags.getClient()->BeginSourceFile(PP.getLangOptions());
+ CI.getDiagnostics().getClient()->BeginSourceFile(PP.getLangOptions());
ParseAST(PP, Consumer.get(), AST->getASTContext(), FEOpts.ShowStats);
- Diags.getClient()->EndSourceFile();
+ CI.getDiagnostics().getClient()->EndSourceFile();
// Release the consumer and the AST, in that order since the consumer may
// perform actions in its destructor which require the context.
@@ -936,7 +935,7 @@
int main(int argc, char **argv) {
llvm::sys::PrintStackTraceOnErrorSignal();
llvm::PrettyStackTraceProgram X(argc, argv);
- llvm::LLVMContext &Context = llvm::getGlobalContext();
+ CompilerInstance Clang(&llvm::getGlobalContext(), false);
// Initialize targets first, so that --version shows registered targets.
llvm::InitializeAllTargets();
@@ -949,44 +948,43 @@
// client to use for any errors during option handling.
DiagnosticOptions DiagOpts;
InitializeDiagnosticOptions(DiagOpts);
- llvm::OwningPtr<Diagnostic>
- Diags(CreateDiagnosticEngine(DiagOpts, argc, argv));
- if (!Diags)
+ Clang.setDiagnostics(CreateDiagnosticEngine(DiagOpts, argc, argv));
+ if (!&Clang.getDiagnostics())
return 1;
// FIXME: Hack to make sure we release the diagnostic client, the engine
// should (optionally?) take ownership of it.
- llvm::OwningPtr<DiagnosticClient> DiagClient(Diags->getClient());
+ Clang.setDiagnosticClient(Clang.getDiagnostics().getClient());
// Now that we have initialized the diagnostics engine, create the target and
// the compiler invocation object.
//
// FIXME: We should move .ast inputs to taking a separate path, they are
// really quite different.
- CompilerInvocation CompOpts;
bool IsAST;
- llvm::OwningPtr<TargetInfo> Target(
- ConstructCompilerInvocation(CompOpts, *Diags, argv[0], DiagOpts, IsAST));
- if (!Target)
+ Clang.setTarget(
+ ConstructCompilerInvocation(Clang.getInvocation(), Clang.getDiagnostics(),
+ argv[0], DiagOpts, IsAST));
+ if (!&Clang.getTarget())
return 1;
// Validate/process some options
- if (CompOpts.getHeaderSearchOpts().Verbose)
+ if (Clang.getHeaderSearchOpts().Verbose)
llvm::errs() << "clang-cc version " CLANG_VERSION_STRING
<< " based upon " << PACKAGE_STRING
<< " hosted on " << llvm::sys::getHostTriple() << "\n";
- if (CompOpts.getFrontendOpts().ShowTimers)
+ if (Clang.getFrontendOpts().ShowTimers)
ClangFrontendTimer = new llvm::Timer("Clang front-end time");
- if (CompOpts.getDiagnosticOpts().VerifyDiagnostics &&
- CompOpts.getFrontendOpts().Inputs.size() > 1) {
+ if (Clang.getDiagnosticOpts().VerifyDiagnostics &&
+ Clang.getFrontendOpts().Inputs.size() > 1) {
fprintf(stderr, "-verify only works on single input files.\n");
return 1;
}
// C++ visualization?
- if (!CompOpts.getFrontendOpts().ViewClassInheritance.empty())
+ if (!Clang.getFrontendOpts().ViewClassInheritance.empty())
ProgAction = InheritanceView;
// Create the source manager.
@@ -995,14 +993,12 @@
// Create a file manager object to provide access to and cache the filesystem.
FileManager FileMgr;
- for (unsigned i = 0, e = CompOpts.getFrontendOpts().Inputs.size();
- i != e; ++i) {
- const std::string &InFile = CompOpts.getFrontendOpts().Inputs[i].second;
+ for (unsigned i = 0, e = Clang.getFrontendOpts().Inputs.size(); i != e; ++i) {
+ const std::string &InFile = Clang.getFrontendOpts().Inputs[i].second;
// AST inputs are handled specially.
if (IsAST) {
- ProcessASTInputFile(CompOpts, InFile, ProgAction, *Diags, FileMgr,
- Context);
+ ProcessASTInputFile(Clang, InFile, ProgAction, FileMgr);
continue;
}
@@ -1012,24 +1008,24 @@
// Set up the preprocessor with these options.
llvm::OwningPtr<Preprocessor>
- PP(CreatePreprocessor(*Diags, CompOpts.getLangOpts(),
- CompOpts.getPreprocessorOpts(),
- CompOpts.getHeaderSearchOpts(),
- CompOpts.getDependencyOutputOpts(),
- *Target, SourceMgr, FileMgr));
+ PP(CreatePreprocessor(Clang.getDiagnostics(), Clang.getLangOpts(),
+ Clang.getPreprocessorOpts(),
+ Clang.getHeaderSearchOpts(),
+ Clang.getDependencyOutputOpts(),
+ Clang.getTarget(), SourceMgr, FileMgr));
// Process the source file.
- Diags->getClient()->BeginSourceFile(CompOpts.getLangOpts());
- ProcessInputFile(CompOpts, *PP, InFile, ProgAction, Context);
- Diags->getClient()->EndSourceFile();
+ Clang.getDiagnostics().getClient()->BeginSourceFile(Clang.getLangOpts());
+ ProcessInputFile(Clang, *PP, InFile, ProgAction);
+ Clang.getDiagnostics().getClient()->EndSourceFile();
}
- if (CompOpts.getDiagnosticOpts().ShowCarets)
- if (unsigned NumDiagnostics = Diags->getNumDiagnostics())
+ if (Clang.getDiagnosticOpts().ShowCarets)
+ if (unsigned NumDiagnostics = Clang.getDiagnostics().getNumDiagnostics())
fprintf(stderr, "%d diagnostic%s generated.\n", NumDiagnostics,
(NumDiagnostics == 1 ? "" : "s"));
- if (CompOpts.getFrontendOpts().ShowStats) {
+ if (Clang.getFrontendOpts().ShowStats) {
FileMgr.PrintStats();
fprintf(stderr, "\n");
}
@@ -1037,12 +1033,12 @@
delete ClangFrontendTimer;
// If verifying diagnostics and we reached here, all is well.
- if (CompOpts.getDiagnosticOpts().VerifyDiagnostics)
+ if (Clang.getDiagnosticOpts().VerifyDiagnostics)
return 0;
// Managed static deconstruction. Useful for making things like
// -time-passes usable.
llvm::llvm_shutdown();
- return (Diags->getNumErrors() != 0);
+ return (Clang.getDiagnostics().getNumErrors() != 0);
}
More information about the cfe-commits
mailing list