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