From: Argyrios Kyrtzidis Date: Mon, 4 Apr 2011 23:11:45 +0000 (+0000) Subject: Move Driver::createInvocationFromArgs function to Frontend library to avoid dependenc... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=832316e9a04242972f4b57281dccb8e4cf5894ea;p=clang Move Driver::createInvocationFromArgs function to Frontend library to avoid dependency cycle between libFrontend and libDriver. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128852 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h index 016f56ac6f..099a354145 100644 --- a/include/clang/Driver/Driver.h +++ b/include/clang/Driver/Driver.h @@ -28,7 +28,6 @@ namespace llvm { template class ArrayRef; } namespace clang { - class CompilerInvocation; namespace driver { class Action; class ArgList; @@ -352,17 +351,6 @@ public: /// @} - - /// createInvocationFromArgs - Construct a compiler invocation object for a - /// command line argument vector. - /// - /// \return A CompilerInvocation, or 0 if none was built for the given - /// argument vector. - static CompilerInvocation * - createInvocationFromArgs(llvm::ArrayRef Args, - llvm::IntrusiveRefCntPtr Diags = - llvm::IntrusiveRefCntPtr()); - /// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and /// return the grouped values as integers. Numbers which are not /// provided are set to 0. diff --git a/include/clang/Frontend/Utils.h b/include/clang/Frontend/Utils.h index dc99bc34be..8ffa2902e8 100644 --- a/include/clang/Frontend/Utils.h +++ b/include/clang/Frontend/Utils.h @@ -15,6 +15,8 @@ #define LLVM_CLANG_FRONTEND_UTILS_H #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/Support/raw_ostream.h" namespace llvm { @@ -24,6 +26,7 @@ class Triple; namespace clang { class ASTConsumer; class CompilerInstance; +class CompilerInvocation; class Decl; class DependencyOutputOptions; class Diagnostic; @@ -92,6 +95,16 @@ void AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders = false, /// a seekable stream. void CacheTokens(Preprocessor &PP, llvm::raw_fd_ostream* OS); +/// createInvocationFromCommandLine - Construct a compiler invocation object for +/// a command line argument vector. +/// +/// \return A CompilerInvocation, or 0 if none was built for the given +/// argument vector. +CompilerInvocation * +createInvocationFromCommandLine(llvm::ArrayRef Args, + llvm::IntrusiveRefCntPtr Diags = + llvm::IntrusiveRefCntPtr()); + } // end namespace clang #endif diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 6dd8fb8f88..9d02dee540 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -27,9 +27,6 @@ #include "clang/Driver/ToolChain.h" #include "clang/Driver/Types.h" -#include "clang/Frontend/CompilerInstance.h" -#include "clang/Frontend/DiagnosticOptions.h" -#include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Basic/Version.h" #include "llvm/Config/config.h" @@ -41,7 +38,6 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/Program.h" -#include "llvm/Support/Host.h" #include "InputInfo.h" @@ -1434,72 +1430,6 @@ bool Driver::ShouldUseClangCompiler(const Compilation &C, const JobAction &JA, return true; } -/// createInvocationFromArgs - Construct a compiler invocation object for a -/// command line argument vector. -/// -/// \return A CompilerInvocation, or 0 if none was built for the given -/// argument vector. -CompilerInvocation * -Driver::createInvocationFromArgs(llvm::ArrayRef ArgList, - llvm::IntrusiveRefCntPtr Diags) { - if (!Diags.getPtr()) { - // No diagnostics engine was provided, so create our own diagnostics object - // with the default options. - DiagnosticOptions DiagOpts; - Diags = CompilerInstance::createDiagnostics(DiagOpts, ArgList.size(), - ArgList.begin()); - } - - llvm::SmallVector Args; - Args.push_back(""); // FIXME: Remove dummy argument. - Args.insert(Args.end(), ArgList.begin(), ArgList.end()); - - // FIXME: Find a cleaner way to force the driver into restricted modes. We - // also want to force it to use clang. - Args.push_back("-fsyntax-only"); - - // FIXME: We shouldn't have to pass in the path info. - driver::Driver TheDriver("clang", llvm::sys::getHostTriple(), - "a.out", false, false, *Diags); - - // Don't check that inputs exist, they may have been remapped. - TheDriver.setCheckInputsExist(false); - - llvm::OwningPtr C(TheDriver.BuildCompilation(Args)); - - // Just print the cc1 options if -### was present. - if (C->getArgs().hasArg(driver::options::OPT__HASH_HASH_HASH)) { - C->PrintJob(llvm::errs(), C->getJobs(), "\n", true); - return 0; - } - - // We expect to get back exactly one command job, if we didn't something - // failed. - const driver::JobList &Jobs = C->getJobs(); - if (Jobs.size() != 1 || !isa(Jobs.begin())) { - llvm::SmallString<256> Msg; - llvm::raw_svector_ostream OS(Msg); - C->PrintJob(OS, C->getJobs(), "; ", true); - Diags->Report(diag::err_fe_expected_compiler_job) << OS.str(); - return 0; - } - - const driver::Command *Cmd = cast(*Jobs.begin()); - if (llvm::StringRef(Cmd->getCreator().getName()) != "clang") { - Diags->Report(diag::err_fe_expected_clang_command); - return 0; - } - - const driver::ArgStringList &CCArgs = Cmd->getArguments(); - CompilerInvocation *CI = new CompilerInvocation(); - CompilerInvocation::CreateFromArgs(*CI, - const_cast(CCArgs.data()), - const_cast(CCArgs.data()) + - CCArgs.size(), - *Diags); - return CI; -} - /// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and return the /// grouped values as integers. Numbers which are not provided are set to 0. /// diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index bfa2791ef6..2a1244841e 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -1641,7 +1641,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin, CaptureDroppedDiagnostics Capture(CaptureDiagnostics, *Diags, StoredDiagnostics); - CI = driver::Driver::createInvocationFromArgs( + CI = clang::createInvocationFromCommandLine( llvm::ArrayRef(ArgBegin, ArgEnd-ArgBegin), Diags); if (!CI)