driver_main.cpp 956 B

12345678910111213141516171819202122232425262728293031
  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/init_llvm.h"
  7. #include "llvm/ADT/SmallVector.h"
  8. #include "llvm/ADT/StringRef.h"
  9. #include "toolchain/driver/driver.h"
  10. auto main(int argc, char** argv) -> int {
  11. Carbon::InitLLVM init_llvm(argc, argv);
  12. if (argc < 1) {
  13. return EXIT_FAILURE;
  14. }
  15. Carbon::SetWorkingDirForBazel();
  16. // Printing to stderr should flush stdout. This is most noticeable when stderr
  17. // is piped to stdout.
  18. llvm::errs().tie(&llvm::outs());
  19. llvm::SmallVector<llvm::StringRef> args(argv + 1, argv + argc);
  20. auto fs = llvm::vfs::getRealFileSystem();
  21. Carbon::Driver driver(*fs, llvm::outs(), llvm::errs());
  22. bool success = driver.RunCommand(args);
  23. return success ? EXIT_SUCCESS : EXIT_FAILURE;
  24. }