clang_invocation.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. #ifndef CARBON_TOOLCHAIN_BASE_CLANG_INVOCATION_H_
  5. #define CARBON_TOOLCHAIN_BASE_CLANG_INVOCATION_H_
  6. #include <string>
  7. #include "clang/Frontend/CompilerInvocation.h"
  8. #include "llvm/ADT/ArrayRef.h"
  9. #include "llvm/ADT/IntrusiveRefCntPtr.h"
  10. #include "llvm/Support/VirtualFileSystem.h"
  11. #include "toolchain/base/install_paths.h"
  12. #include "toolchain/diagnostics/diagnostic_emitter.h"
  13. namespace Carbon {
  14. // Builds and returns a clang `CompilerInvocation` to use when building code for
  15. // interop, from a list of clang driver arguments. Emits diagnostics to
  16. // `consumer` if the arguments are invalid.
  17. auto BuildClangInvocation(Diagnostics::Consumer& consumer,
  18. llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs,
  19. const InstallPaths& install_paths,
  20. llvm::StringRef target_str,
  21. llvm::ArrayRef<llvm::StringRef> extra_args = {})
  22. -> std::unique_ptr<clang::CompilerInvocation>;
  23. // Appends the default Clang command line arguments used when building a
  24. // Carbon-compatible Clang invocation.
  25. //
  26. // Where possible, code should use `BuildClangInvocation` above. However, when
  27. // invoking Clang directly, this can be used to get the core compatible flags.
  28. auto AppendDefaultClangArgs(const InstallPaths& install_paths,
  29. llvm::StringRef target_str,
  30. llvm::SmallVectorImpl<std::string>& args) -> void;
  31. } // namespace Carbon
  32. #endif // CARBON_TOOLCHAIN_BASE_CLANG_INVOCATION_H_