18#include "llvm/ADT/StringExtras.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/Support/IOSandbox.h"
21#include "llvm/Support/Path.h"
29static std::optional<std::pair<llvm::StringRef, llvm::StringRef>>
31 StringRef SSAFTUSummaryFile) {
33 StringRef Ext = llvm::sys::path::extension(SSAFTUSummaryFile);
34 StringRef FilePath = SSAFTUSummaryFile.drop_back(Ext.size());
36 if (!Ext.consume_front(
".") || FilePath.empty()) {
37 Diags.
Report(diag::warn_ssaf_extract_tu_summary_file_unknown_format)
43 Diags.
Report(diag::warn_ssaf_extract_tu_summary_file_unknown_output_format)
44 << Ext << SSAFTUSummaryFile;
48 return std::pair{Ext, FilePath};
55 if (SSAFExtractSummaries.empty()) {
56 Diags.
Report(diag::warn_ssaf_must_enable_summary_extractors);
60 std::vector<StringRef> UnrecognizedExtractorNames;
61 for (StringRef Name : SSAFExtractSummaries)
63 UnrecognizedExtractorNames.push_back(Name);
65 if (!UnrecognizedExtractorNames.empty()) {
66 Diags.
Report(diag::warn_ssaf_extract_summary_unknown_extractor_name)
67 << UnrecognizedExtractorNames.size()
68 << llvm::join(UnrecognizedExtractorNames,
", ");
75static std::vector<std::unique_ptr<ASTConsumer>>
78 std::vector<std::unique_ptr<ASTConsumer>> Extractors;
79 Extractors.reserve(SSAFExtractSummaries.size());
80 for (StringRef Name : SSAFExtractSummaries) {
96 static std::unique_ptr<TUSummaryRunner>
create(CompilerInstance &CI,
100 TUSummaryRunner(StringRef InFile, std::unique_ptr<SerializationFormat> Format,
101 const FrontendOptions &Opts);
103 void HandleTranslationUnit(ASTContext &Ctx)
override;
106 TUSummaryBuilder Builder = TUSummaryBuilder(Summary);
107 std::unique_ptr<SerializationFormat> Format;
108 const FrontendOptions &Opts;
112std::unique_ptr<TUSummaryRunner> TUSummaryRunner::create(
CompilerInstance &CI,
119 if (!MaybePair.has_value())
121 auto [FormatName, OutputPath] = MaybePair.value();
126 return std::unique_ptr<TUSummaryRunner>{
127 new TUSummaryRunner{InFile,
makeFormat(FormatName), Opts}};
130TUSummaryRunner::TUSummaryRunner(StringRef InFile,
131 std::unique_ptr<SerializationFormat> Format,
132 const FrontendOptions &Opts)
133 : MultiplexConsumer(std::vector<std::unique_ptr<ASTConsumer>>{}),
134 Summary(
BuildNamespace(BuildNamespaceKind::CompilationUnit, InFile)),
135 Format(std::move(Format)), Opts(Opts) {
136 assert(this->Format);
141 assert(!Extractors.empty());
150void TUSummaryRunner::HandleTranslationUnit(
ASTContext &Ctx) {
155 llvm::sys::sandbox::ScopedSetting Guard = llvm::sys::sandbox::scopedDisable();
170std::unique_ptr<ASTConsumer>
174 if (!WrappedConsumer)
177 if (
auto Runner = TUSummaryRunner::create(CI, InFile)) {
179 std::vector<std::unique_ptr<ASTConsumer>> Consumers;
180 Consumers.reserve(2);
181 Consumers.push_back(std::move(WrappedConsumer));
182 Consumers.push_back(std::move(Runner));
183 return std::make_unique<MultiplexConsumer>(std::move(Consumers));
185 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()
CodeGenOptions & getCodeGenOpts()
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.