From 38bfda6ab52adf8e7668cbe379806490a7d1041f Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Wed, 1 Jul 2009 20:03:04 +0000 Subject: Driver: Move Compilation::Execute to Driver::ExecuteCompilation. - The Compilation is just a helper class, it shouldn't have that amount of logic in it. - No functionality change. llvm-svn: 74634 --- clang/lib/Driver/Driver.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'clang/lib/Driver/Driver.cpp') diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 2e90accf343..df72426057b 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -217,6 +217,54 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) { return C; } +int Driver::ExecuteCompilation(const Compilation &C) const { + // Just print if -### was present. + if (C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) { + C.PrintJob(llvm::errs(), C.getJobs(), "\n", true); + return 0; + } + + // If there were errors building the compilation, quit now. + if (getDiags().getNumErrors()) + return 1; + + const Command *FailingCommand = 0; + int Res = C.ExecuteJob(C.getJobs(), FailingCommand); + + // Remove temp files. + C.CleanupFileList(C.getTempFiles()); + + // If the compilation failed, remove result files as well. + if (Res != 0 && !C.getArgs().hasArg(options::OPT_save_temps)) + C.CleanupFileList(C.getResultFiles(), true); + + // Print extra information about abnormal failures, if possible. + if (Res) { + // This is ad-hoc, but we don't want to be excessively noisy. If the result + // status was 1, assume the command failed normally. In particular, if it + // was the compiler then assume it gave a reasonable error code. Failures in + // other tools are less common, and they generally have worse diagnostics, + // so always print the diagnostic there. + const Action &Source = FailingCommand->getSource(); + bool IsFriendlyTool = (isa(Source) || + isa(Source) || + isa(Source) || + isa(Source)); + + if (!IsFriendlyTool || Res != 1) { + // FIXME: See FIXME above regarding result code interpretation. + if (Res < 0) + Diag(clang::diag::err_drv_command_signalled) + << Source.getClassName() << -Res; + else + Diag(clang::diag::err_drv_command_failed) + << Source.getClassName() << Res; + } + } + + return Res; +} + void Driver::PrintOptions(const ArgList &Args) const { unsigned i = 0; for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); -- cgit v1.2.3