| 49 | using namespace llvm::opt; |
| 50 | |
| 51 | std::unique_ptr<CompilerInvocation> createInvocationFromCommandLineBackport ( |
| 52 | ArrayRef<const char *> ArgList, |
| 53 | IntrusiveRefCntPtr<DiagnosticsEngine> Diags) { |
| 54 | if (!Diags.get()) { |
| 55 | // No diagnostics engine was provided, so create our own diagnostics object |
| 56 | // with the default options. |
| 57 | Diags = CompilerInstance::createDiagnostics(new DiagnosticOptions); |
| 58 | } |
| 59 | |
| 60 | SmallVector<const char *, 16> Args(ArgList.begin(), ArgList.end()); |
| 61 | |
| 62 | // FIXME: Find a cleaner way to force the driver into restricted modes. |
| 63 | Args.push_back("-fsyntax-only"); |
| 64 | |
| 65 | // FIXME: We shouldn't have to pass in the path info. |
| 66 | driver::Driver TheDriver(Args[0], llvm::sys::getDefaultTargetTriple(), |
| 67 | *Diags); |
| 68 | |
| 69 | // Don't check that inputs exist, they may have been remapped. |
| 70 | TheDriver.setCheckInputsExist(false); |
| 71 | |
| 72 | std::unique_ptr<driver::Compilation> C(TheDriver.BuildCompilation(Args)); |
| 73 | |
| 74 | // Just print the cc1 options if -### was present. |
| 75 | if (C->getArgs().hasArg(driver::options::OPT__HASH_HASH_HASH)) { |
| 76 | C->getJobs().Print(llvm::errs(), "\n", true); |
| 77 | return nullptr; |
| 78 | } |
| 79 | |
| 80 | // We expect to get back exactly one command job, if we didn't something |
| 81 | // failed. |
| 82 | const driver::JobList &Jobs = C->getJobs(); |
| 83 | if (Jobs.size() > 1) { |
| 84 | for (auto &A : C->getActions()){ |
| 85 | // On MacOSX real actions may end up being wrapped in BindArchAction |
| 86 | if (isa<driver::BindArchAction>(A)) |
| 87 | A = *A->begin(); |
| 88 | } |
| 89 | } |
| 90 | if (Jobs.size() == 0 || !isa<driver::Command>(*Jobs.begin()) || |
| 91 | (Jobs.size() > 1)) { |
| 92 | SmallString<256> Msg; |
| 93 | llvm::raw_svector_ostream OS(Msg); |
| 94 | Jobs.Print(OS, "; ", true); |
| 95 | Diags->Report(diag::err_fe_expected_compiler_job) << OS.str(); |
| 96 | return nullptr; |
| 97 | } |
| 98 | |
| 99 | const driver::Command &Cmd = |
| 100 | #if LLVM_VERSION_MAJOR <= 3 && LLVM_VERSION_MINOR <= 5 |
| 101 | * |
| 102 | #endif |
| 103 | cast<driver::Command>(*Jobs.begin()); |
| 104 | if (StringRef(Cmd.getCreator().getName()) != "clang") { |
| 105 | Diags->Report(diag::err_fe_expected_clang_command); |
| 106 | return nullptr; |
| 107 | } |
| 108 | |