[cfe-commits] r90114 - in /cfe/trunk/tools: clang-cc/CMakeLists.txt clang-cc/Makefile clang-cc/clang-cc.cpp driver/CMakeLists.txt driver/Makefile driver/cc1_main.cpp driver/driver.cpp
Daniel Dunbar
daniel at zuster.org
Sun Nov 29 23:18:13 PST 2009
Author: ddunbar
Date: Mon Nov 30 01:18:13 2009
New Revision: 90114
URL: http://llvm.org/viewvc/llvm-project?rev=90114&view=rev
Log:
Put CompilerInvocation testing code in clang-cc instead of clang for now, I can't bear to link all of clang into 'clang' yet. :)
- Still triggered by a magic leading -cc1 argument, as before.
Modified:
cfe/trunk/tools/clang-cc/CMakeLists.txt
cfe/trunk/tools/clang-cc/Makefile
cfe/trunk/tools/clang-cc/clang-cc.cpp
cfe/trunk/tools/driver/CMakeLists.txt
cfe/trunk/tools/driver/Makefile
cfe/trunk/tools/driver/cc1_main.cpp
cfe/trunk/tools/driver/driver.cpp
Modified: cfe/trunk/tools/clang-cc/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/CMakeLists.txt?rev=90114&r1=90113&r2=90114&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-cc/CMakeLists.txt Mon Nov 30 01:18:13 2009
@@ -1,6 +1,7 @@
set(LLVM_NO_RTTI 1)
set( LLVM_USED_LIBS
+ clangDriver
clangFrontend
clangCodeGen
clangAnalysis
Modified: cfe/trunk/tools/clang-cc/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/Makefile?rev=90114&r1=90113&r2=90114&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/Makefile (original)
+++ cfe/trunk/tools/clang-cc/Makefile Mon Nov 30 01:18:13 2009
@@ -21,7 +21,7 @@
include $(LEVEL)/Makefile.config
LINK_COMPONENTS := $(TARGETS_TO_BUILD) bitreader bitwriter codegen ipo selectiondag
-USEDLIBS = clangFrontend.a clangCodeGen.a clangAnalysis.a \
+USEDLIBS = clangDriver.a clangFrontend.a clangCodeGen.a clangAnalysis.a \
clangRewrite.a clangSema.a clangAST.a clangParse.a \
clangLex.a clangBasic.a
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=90114&r1=90113&r2=90114&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Mon Nov 30 01:18:13 2009
@@ -21,11 +21,17 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/Version.h"
+#include "clang/Driver/Arg.h"
+#include "clang/Driver/ArgList.h"
+#include "clang/Driver/CC1Options.h"
+#include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/OptTable.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/FrontendPluginRegistry.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Frontend/VerifyDiagnosticsClient.h"
#include "llvm/LLVMContext.h"
#include "llvm/ADT/OwningPtr.h"
@@ -185,11 +191,87 @@
return true;
}
+static int cc1_main(Diagnostic &Diags,
+ const char **ArgBegin, const char **ArgEnd,
+ const char *Argv0, void *MainAddr) {
+ using namespace clang::driver;
+
+ llvm::errs() << "cc1 argv:";
+ for (const char **i = ArgBegin; i != ArgEnd; ++i)
+ llvm::errs() << " \"" << *i << '"';
+ llvm::errs() << "\n";
+
+ // Parse the arguments.
+ OptTable *Opts = createCC1OptTable();
+ unsigned MissingArgIndex, MissingArgCount;
+ InputArgList *Args = Opts->ParseArgs(ArgBegin, ArgEnd,
+ MissingArgIndex, MissingArgCount);
+
+ // Check for missing argument error.
+ if (MissingArgCount)
+ Diags.Report(clang::diag::err_drv_missing_argument)
+ << Args->getArgString(MissingArgIndex) << MissingArgCount;
+
+ // Dump the parsed arguments.
+ llvm::errs() << "cc1 parsed options:\n";
+ for (ArgList::const_iterator it = Args->begin(), ie = Args->end();
+ it != ie; ++it)
+ (*it)->dump();
+
+ // Create a compiler invocation.
+ llvm::errs() << "cc1 creating invocation.\n";
+ CompilerInvocation Invocation;
+ CompilerInvocation::CreateFromArgs(Invocation, ArgBegin, ArgEnd,
+ Argv0, MainAddr, Diags);
+
+ // Convert the invocation back to argument strings.
+ std::vector<std::string> InvocationArgs;
+ Invocation.toArgs(InvocationArgs);
+
+ // Dump the converted arguments.
+ llvm::SmallVector<const char*, 32> Invocation2Args;
+ llvm::errs() << "invocation argv :";
+ for (unsigned i = 0, e = InvocationArgs.size(); i != e; ++i) {
+ Invocation2Args.push_back(InvocationArgs[i].c_str());
+ llvm::errs() << " \"" << InvocationArgs[i] << '"';
+ }
+ llvm::errs() << "\n";
+
+ // Convert those arguments to another invocation, and check that we got the
+ // same thing.
+ CompilerInvocation Invocation2;
+ CompilerInvocation::CreateFromArgs(Invocation2, Invocation2Args.begin(),
+ Invocation2Args.end(), Argv0, MainAddr,
+ Diags);
+
+ // FIXME: Implement CompilerInvocation comparison.
+ if (true) {
+ //llvm::errs() << "warning: Invocations differ!\n";
+
+ std::vector<std::string> Invocation2Args;
+ Invocation2.toArgs(Invocation2Args);
+ llvm::errs() << "invocation2 argv:";
+ for (unsigned i = 0, e = Invocation2Args.size(); i != e; ++i)
+ llvm::errs() << " \"" << Invocation2Args[i] << '"';
+ llvm::errs() << "\n";
+ }
+
+ return 0;
+}
+
int main(int argc, char **argv) {
llvm::sys::PrintStackTraceOnErrorSignal();
llvm::PrettyStackTraceProgram X(argc, argv);
CompilerInstance Clang(&llvm::getGlobalContext(), false);
+ // Run clang -cc1 test.
+ if (argc > 1 && llvm::StringRef(argv[1]) == "-cc1") {
+ TextDiagnosticPrinter DiagClient(llvm::errs(), DiagnosticOptions());
+ Diagnostic Diags(&DiagClient);
+ return cc1_main(Diags, (const char**) argv + 2, (const char**) argv + argc,
+ argv[0], (void*) (intptr_t) GetBuiltinIncludePath);
+ }
+
// Initialize targets first, so that --version shows registered targets.
llvm::InitializeAllTargets();
llvm::InitializeAllAsmPrinters();
Modified: cfe/trunk/tools/driver/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/CMakeLists.txt?rev=90114&r1=90113&r2=90114&view=diff
==============================================================================
--- cfe/trunk/tools/driver/CMakeLists.txt (original)
+++ cfe/trunk/tools/driver/CMakeLists.txt Mon Nov 30 01:18:13 2009
@@ -3,7 +3,6 @@
set( LLVM_USED_LIBS
clangDriver
clangBasic
- clangFrontend
)
set(LLVM_LINK_COMPONENTS system support bitreader bitwriter)
Modified: cfe/trunk/tools/driver/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/Makefile?rev=90114&r1=90113&r2=90114&view=diff
==============================================================================
--- cfe/trunk/tools/driver/Makefile (original)
+++ cfe/trunk/tools/driver/Makefile Mon Nov 30 01:18:13 2009
@@ -19,7 +19,7 @@
# FIXME: It is unfortunate we need to pull in the bitcode reader and
# writer just to get the serializer stuff used by clangBasic.
LINK_COMPONENTS := system support bitreader bitwriter
-USEDLIBS = clangDriver.a clangBasic.a clangFrontend.a
+USEDLIBS = clangDriver.a clangBasic.a
include $(LEVEL)/Makefile.common
Modified: cfe/trunk/tools/driver/cc1_main.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1_main.cpp?rev=90114&r1=90113&r2=90114&view=diff
==============================================================================
--- cfe/trunk/tools/driver/cc1_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1_main.cpp Mon Nov 30 01:18:13 2009
@@ -11,81 +11,14 @@
//
//===----------------------------------------------------------------------===//
-#include "clang/Driver/Arg.h"
-#include "clang/Driver/ArgList.h"
-#include "clang/Driver/CC1Options.h"
-#include "clang/Driver/DriverDiagnostic.h"
-#include "clang/Driver/OptTable.h"
-#include "clang/Driver/Option.h"
-#include "clang/Frontend/CompilerInvocation.h"
#include "llvm/Support/raw_ostream.h"
-#include <cstdlib>
-#include <vector>
-using namespace clang;
-using namespace clang::driver;
-
-int cc1_main(Diagnostic &Diags, const char **ArgBegin, const char **ArgEnd,
+int cc1_main(const char **ArgBegin, const char **ArgEnd,
const char *Argv0, void *MainAddr) {
llvm::errs() << "cc1 argv:";
for (const char **i = ArgBegin; i != ArgEnd; ++i)
llvm::errs() << " \"" << *i << '"';
llvm::errs() << "\n";
- // Parse the arguments.
- OptTable *Opts = createCC1OptTable();
- unsigned MissingArgIndex, MissingArgCount;
- InputArgList *Args = Opts->ParseArgs(ArgBegin, ArgEnd,
- MissingArgIndex, MissingArgCount);
-
- // Check for missing argument error.
- if (MissingArgCount)
- Diags.Report(clang::diag::err_drv_missing_argument)
- << Args->getArgString(MissingArgIndex) << MissingArgCount;
-
- // Dump the parsed arguments.
- llvm::errs() << "cc1 parsed options:\n";
- for (ArgList::const_iterator it = Args->begin(), ie = Args->end();
- it != ie; ++it)
- (*it)->dump();
-
- // Create a compiler invocation.
- llvm::errs() << "cc1 creating invocation.\n";
- CompilerInvocation Invocation;
- CompilerInvocation::CreateFromArgs(Invocation, ArgBegin, ArgEnd,
- Argv0, MainAddr, Diags);
-
- // Convert the invocation back to argument strings.
- std::vector<std::string> InvocationArgs;
- Invocation.toArgs(InvocationArgs);
-
- // Dump the converted arguments.
- llvm::SmallVector<const char*, 32> Invocation2Args;
- llvm::errs() << "invocation argv :";
- for (unsigned i = 0, e = InvocationArgs.size(); i != e; ++i) {
- Invocation2Args.push_back(InvocationArgs[i].c_str());
- llvm::errs() << " \"" << InvocationArgs[i] << '"';
- }
- llvm::errs() << "\n";
-
- // Convert those arguments to another invocation, and check that we got the
- // same thing.
- CompilerInvocation Invocation2;
- CompilerInvocation::CreateFromArgs(Invocation2, Invocation2Args.begin(),
- Invocation2Args.end(), Argv0, MainAddr,
- Diags);
-
- // FIXME: Implement CompilerInvocation comparison.
- if (true) {
- //llvm::errs() << "warning: Invocations differ!\n";
-
- std::vector<std::string> Invocation2Args;
- Invocation2.toArgs(Invocation2Args);
- llvm::errs() << "invocation2 argv:";
- for (unsigned i = 0, e = Invocation2Args.size(); i != e; ++i)
- llvm::errs() << " \"" << Invocation2Args[i] << '"';
- llvm::errs() << "\n";
- }
-
return 0;
}
Modified: cfe/trunk/tools/driver/driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/driver.cpp?rev=90114&r1=90113&r2=90114&view=diff
==============================================================================
--- cfe/trunk/tools/driver/driver.cpp (original)
+++ cfe/trunk/tools/driver/driver.cpp Mon Nov 30 01:18:13 2009
@@ -178,24 +178,23 @@
}
}
-extern int cc1_main(Diagnostic &Diags,
- const char **ArgBegin, const char **ArgEnd,
+extern int cc1_main(const char **ArgBegin, const char **ArgEnd,
const char *Argv0, void *MainAddr);
int main(int argc, const char **argv) {
llvm::sys::PrintStackTraceOnErrorSignal();
llvm::PrettyStackTraceProgram X(argc, argv);
+ // Dispatch to cc1_main if appropriate.
+ if (argc > 1 && llvm::StringRef(argv[1]) == "-cc1")
+ return cc1_main(argv+2, argv+argc, argv[0],
+ (void*) (intptr_t) GetExecutablePath);
+
llvm::sys::Path Path = GetExecutablePath(argv[0]);
DriverDiagnosticPrinter DiagClient(Path.getBasename(), llvm::errs());
Diagnostic Diags(&DiagClient);
- // Dispatch to cc1_main if appropriate.
- if (argc > 1 && llvm::StringRef(argv[1]) == "-cc1")
- return cc1_main(Diags, argv+2, argv+argc, argv[0],
- (void*) (intptr_t) GetExecutablePath);
-
#ifdef CLANG_IS_PRODUCTION
bool IsProduction = true;
#else
More information about the cfe-commits
mailing list