llvm_runner.cpp 1.3 KB

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