//===--- Execution.h - Executing clang frontend actions -*- C++ ---------*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file defines framework for executing clang frontend actions. // // The framework can be extended to support different execution plans including // standalone execution on the given TUs or parallel execution on all TUs in // the codebase. // // In order to enable multiprocessing execution, tool actions are expected to // output result into the ToolResults provided by the executor. The // `ToolResults` is an interface that abstracts how results are stored e.g. // in-memory for standalone execution or on-disk for large-scale execution. // // New executors can be registered as ToolExecutorPlugins via the // `ToolExecutorPluginRegistry`. CLI tools can use // `createExecutorFromCommandLineArgs` to create a specific registered executor // according to the command-line arguments. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_TOOLING_EXECUTION_H #define LLVM_CLANG_TOOLING_EXECUTION_H #include "clang/Tooling/CommonOptionsParser.h" #include "clang/Tooling/Tooling.h" #include "llvm/Support/Error.h" #include "llvm/Support/Registry.h" #include "llvm/Support/StringSaver.h" namespace clang { namespace tooling { extern llvm::cl::opt<std::string> ExecutorName; /// An abstraction for the result of a tool execution. For example, the /// underlying result can be in-memory or on-disk. /// /// Results should be string key-value pairs. For example, a refactoring tool /// can use source location as key and a replacement in YAML format as value. class ToolResults { … }; /// Stores the key-value results in memory. It maintains the lifetime of /// the result. Clang tools using this class are expected to generate a small /// set of different results, or a large set of duplicated results. class InMemoryToolResults : public ToolResults { … }; /// The context of an execution, including the information about /// compilation and results. class ExecutionContext { … }; /// Interface for executing clang frontend actions. /// /// This can be extended to support running tool actions in different /// execution mode, e.g. on a specific set of TUs or many TUs in parallel. /// /// New executors can be registered as ToolExecutorPlugins via the /// `ToolExecutorPluginRegistry`. CLI tools can use /// `createExecutorFromCommandLineArgs` to create a specific registered /// executor according to the command-line arguments. class ToolExecutor { … }; /// Interface for factories that create specific executors. This is also /// used as a plugin to be registered into ToolExecutorPluginRegistry. class ToolExecutorPlugin { … }; /// This creates a ToolExecutor that is in the global registry based on /// commandline arguments. /// /// This picks the right executor based on the `--executor` option. This parses /// the commandline arguments with `CommonOptionsParser`, so caller does not /// need to parse again. /// /// By default, this creates a `StandaloneToolExecutor` ("standalone") if /// `--executor` is not provided. llvm::Expected<std::unique_ptr<ToolExecutor>> createExecutorFromCommandLineArgs(int &argc, const char **argv, llvm::cl::OptionCategory &Category, const char *Overview = nullptr); namespace internal { llvm::Expected<std::unique_ptr<ToolExecutor>> createExecutorFromCommandLineArgsImpl(int &argc, const char **argv, llvm::cl::OptionCategory &Category, const char *Overview = nullptr); } // end namespace internal } // end namespace tooling } // end namespace clang #endif // LLVM_CLANG_TOOLING_EXECUTION_H