driver_main.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include <cstdlib>
  5. #include "common/bazel_working_dir.h"
  6. #include "common/exe_path.h"
  7. #include "common/init_llvm.h"
  8. #include "llvm/ADT/SmallVector.h"
  9. #include "llvm/ADT/StringRef.h"
  10. #include "llvm/Support/Path.h"
  11. #include "toolchain/driver/driver.h"
  12. #include "toolchain/install/install_paths.h"
  13. auto main(int argc, char** argv) -> int {
  14. Carbon::InitLLVM init_llvm(argc, argv);
  15. if (argc < 1) {
  16. return EXIT_FAILURE;
  17. }
  18. std::string exe_path = Carbon::FindExecutablePath(argv[0]);
  19. Carbon::SetWorkingDirForBazel();
  20. llvm::SmallVector<llvm::StringRef> args(argv + 1, argv + argc);
  21. auto fs = llvm::vfs::getRealFileSystem();
  22. const auto install_paths = Carbon::InstallPaths::MakeExeRelative(exe_path);
  23. // Construct the data directory relative to the executable location.
  24. // TODO: Will be removed when everything moves to the install_paths.
  25. llvm::SmallString<256> data_dir(llvm::sys::path::parent_path(exe_path));
  26. llvm::sys::path::append(data_dir, llvm::sys::path::Style::posix,
  27. "carbon.runfiles/_main/");
  28. Carbon::Driver driver(*fs, &install_paths, data_dir, llvm::outs(),
  29. llvm::errs());
  30. bool success = driver.RunCommand(args).success;
  31. return success ? EXIT_SUCCESS : EXIT_FAILURE;
  32. }