18#include "llvm/ADT/StringExtras.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/Support/Path.h"
28static std::optional<std::pair<llvm::StringRef, llvm::StringRef>>
30 StringRef SSAFTUSummaryFile) {
32 StringRef Ext = llvm::sys::path::extension(SSAFTUSummaryFile);
33 StringRef FilePath = SSAFTUSummaryFile.drop_back(Ext.size());
35 if (!Ext.consume_front(
".") || FilePath.empty()) {
36 Diags.
Report(diag::warn_ssaf_extract_tu_summary_file_unknown_format)
42 Diags.
Report(diag::warn_ssaf_extract_tu_summary_file_unknown_output_format)
43 << Ext << SSAFTUSummaryFile;
47 return std::pair{Ext, FilePath};
54 if (SSAFExtractSummaries.empty()) {
55 Diags.
Report(diag::warn_ssaf_must_enable_summary_extractors);
59 std::vector<StringRef> UnrecognizedExtractorNames;
60 for (StringRef Name : SSAFExtractSummaries)
62 UnrecognizedExtractorNames.push_back(Name);
64 if (!UnrecognizedExtractorNames.empty()) {
65 Diags.
Report(diag::warn_ssaf_extract_summary_unknown_extractor_name)
66 << UnrecognizedExtractorNames.size()
67 << llvm::join(UnrecognizedExtractorNames,
", ");
74static std::vector<std::unique_ptr<ASTConsumer>>
77 std::vector<std::unique_ptr<ASTConsumer>> Extractors;
78 Extractors.reserve(SSAFExtractSummaries.size());
79 for (StringRef Name : SSAFExtractSummaries) {
95 static std::unique_ptr<TUSummaryRunner>
create(CompilerInstance &CI,
99 TUSummaryRunner(StringRef InFile, std::unique_ptr<SerializationFormat> Format,
100 const FrontendOptions &Opts);
102 void HandleTranslationUnit(ASTContext &Ctx)
override;
105 TUSummaryBuilder Builder = TUSummaryBuilder(Summary);
106 std::unique_ptr<SerializationFormat> Format;
107 const FrontendOptions &Opts;
111std::unique_ptr<TUSummaryRunner> TUSummaryRunner::create(
CompilerInstance &CI,
118 if (!MaybePair.has_value())
120 auto [FormatName, OutputPath] = MaybePair.value();
125 return std::unique_ptr<TUSummaryRunner>{
126 new TUSummaryRunner{InFile,
makeFormat(FormatName), Opts}};
129TUSummaryRunner::TUSummaryRunner(StringRef InFile,
130 std::unique_ptr<SerializationFormat> Format,
131 const FrontendOptions &Opts)
132 : MultiplexConsumer(std::vector<std::unique_ptr<ASTConsumer>>{}),
133 Summary(
BuildNamespace(BuildNamespaceKind::CompilationUnit, InFile)),
134 Format(std::move(Format)), Opts(Opts) {
135 assert(this->Format);
140 assert(!Extractors.empty());
149void TUSummaryRunner::HandleTranslationUnit(
ASTContext &Ctx) {
166std::unique_ptr<ASTConsumer>
170 if (!WrappedConsumer)
173 if (
auto Runner = TUSummaryRunner::create(CI, InFile)) {
174 std::vector<std::unique_ptr<ASTConsumer>> Consumers;
175 Consumers.reserve(2);
176 Consumers.push_back(std::move(WrappedConsumer));
177 Consumers.push_back(std::move(Runner));
178 return std::make_unique<MultiplexConsumer>(std::move(Consumers));
180 return WrappedConsumer;
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
DiagnosticsEngine & getDiagnostics() const
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
FrontendOptions & getFrontendOpts()
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
std::string SSAFTUSummaryFile
The TU summary output file with the file extension representing the file format.
std::vector< std::string > SSAFExtractSummaries
List of SSAF extractors to enable.
void HandleTranslationUnit(ASTContext &Ctx) override
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
std::vector< std::unique_ptr< ASTConsumer > > Consumers
WrapperFrontendAction(std::unique_ptr< FrontendAction > WrappedAction)
Construct a WrapperFrontendAction from an existing action, taking ownership of it.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
std::unique_ptr< FrontendAction > WrappedAction
Represents a single namespace in the build process.
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions &DiagOpts, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
std::unique_ptr< ASTConsumer > makeTUSummaryExtractor(llvm::StringRef SummaryName, TUSummaryBuilder &Builder)
Try to instantiate a TUSummaryExtractor with a given name.
std::unique_ptr< SerializationFormat > makeFormat(llvm::StringRef FormatName)
Try to instantiate a SerializationFormat with a given name.
bool isFormatRegistered(llvm::StringRef FormatName)
Check if a SerializationFormat was registered with a given name.
bool isTUSummaryExtractorRegistered(llvm::StringRef SummaryName)
Check if a TUSummaryExtractor was registered with a given name.
The JSON file list parser is used to communicate input to InstallAPI.