driver_main.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 "toolchain/driver/driver.h"
  11. #include "toolchain/install/install_paths.h"
  12. auto main(int argc, char** argv) -> int {
  13. Carbon::InitLLVM init_llvm(argc, argv);
  14. if (argc < 1) {
  15. return EXIT_FAILURE;
  16. }
  17. // Resolve paths before calling SetWorkingDirForBazel.
  18. std::string exe_path = Carbon::FindExecutablePath(argv[0]);
  19. const auto install_paths = Carbon::InstallPaths::MakeExeRelative(exe_path);
  20. if (install_paths.error()) {
  21. llvm::errs() << "error: " << *install_paths.error();
  22. return EXIT_FAILURE;
  23. }
  24. Carbon::SetWorkingDirForBazel();
  25. llvm::SmallVector<llvm::StringRef> args(argv + 1, argv + argc);
  26. auto fs = llvm::vfs::getRealFileSystem();
  27. Carbon::Driver driver(*fs, &install_paths, llvm::outs(), llvm::errs());
  28. bool success = driver.RunCommand(args).success;
  29. return success ? EXIT_SUCCESS : EXIT_FAILURE;
  30. }