llvm_runner.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 "toolchain/driver/llvm_runner.h"
  5. #include <algorithm>
  6. #include <memory>
  7. #include <numeric>
  8. #include <optional>
  9. #include <string>
  10. #include "common/vlog.h"
  11. #include "lld/Common/Driver.h"
  12. #include "llvm/ADT/ArrayRef.h"
  13. #include "llvm/ADT/StringRef.h"
  14. namespace Carbon {
  15. auto LLVMRunner::Run(LLVMTool tool, llvm::ArrayRef<llvm::StringRef> args)
  16. -> bool {
  17. std::string path = installation_->llvm_tool_path(tool);
  18. // Allocate one chunk of storage for the actual C-strings and a vector of
  19. // pointers into the storage.
  20. llvm::OwningArrayRef<char> cstr_arg_storage;
  21. llvm::SmallVector<const char*, 64> cstr_args = BuildCStrArgs(
  22. tool.name(), path, /*verbose_flag=*/std::nullopt, args, cstr_arg_storage);
  23. CARBON_VLOG("Running LLVM's {0} tool...\n", tool.name());
  24. int exit_code = tool.main_fn()(
  25. cstr_args.size(), const_cast<char**>(cstr_args.data()),
  26. {.Path = path.c_str(), .PrependArg = nullptr, .NeedsPrependArg = false});
  27. // TODO: Should this be forwarding the full exit code?
  28. return exit_code == 0;
  29. }
  30. } // namespace Carbon