llvm_runner.cpp 1.3 KB

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