19#include "llvm/ADT/StringExtras.h"
20#include "llvm/ADT/StringRef.h"
21#include "llvm/Support/IOSandbox.h"
22#include "llvm/Support/Path.h"
23#include "llvm/TargetParser/Triple.h"
31static std::optional<std::pair<llvm::StringRef, llvm::StringRef>>
33 StringRef SSAFTUSummaryFile) {
35 StringRef Ext = llvm::sys::path::extension(SSAFTUSummaryFile);
36 StringRef FilePath = SSAFTUSummaryFile.drop_back(Ext.size());
38 if (!Ext.consume_front(
".") || FilePath.empty()) {
39 Diags.
Report(diag::warn_ssaf_extract_tu_summary_file_unknown_format)
45 Diags.
Report(diag::warn_ssaf_extract_tu_summary_file_unknown_output_format)
46 << Ext << SSAFTUSummaryFile;
50 return std::pair{Ext, FilePath};
57 if (SSAFExtractSummaries.empty()) {
58 Diags.
Report(diag::warn_ssaf_must_enable_summary_extractors);
62 std::vector<StringRef> UnrecognizedExtractorNames;
63 for (StringRef Name : SSAFExtractSummaries)
65 UnrecognizedExtractorNames.push_back(Name);
67 if (!UnrecognizedExtractorNames.empty()) {
68 Diags.
Report(diag::warn_ssaf_extract_summary_unknown_extractor_name)
69 << UnrecognizedExtractorNames.size()
70 << llvm::join(UnrecognizedExtractorNames,
", ");
77static std::vector<std::unique_ptr<ASTConsumer>>
80 std::vector<std::unique_ptr<ASTConsumer>> Extractors;
81 Extractors.reserve(SSAFExtractSummaries.size());
82 for (StringRef Name : SSAFExtractSummaries) {
98 static std::unique_ptr<TUSummaryRunner>
create(CompilerInstance &CI);
101 TUSummaryRunner(llvm::Triple TargetTriple,
102 std::unique_ptr<SerializationFormat> Format,
103 const FrontendOptions &Opts);
105 void HandleTranslationUnit(ASTContext &Ctx)
override;
108 TUSummaryBuilder Builder = TUSummaryBuilder(Summary);
109 std::unique_ptr<SerializationFormat> Format;
110 const FrontendOptions &Opts;
114std::unique_ptr<TUSummaryRunner> TUSummaryRunner::create(
CompilerInstance &CI) {
119 Diags.
Report(diag::warn_ssaf_tu_summary_requires_compilation_unit_id);
125 if (!MaybePair.has_value())
127 auto [FormatName, OutputPath] = MaybePair.value();
132 return std::unique_ptr<TUSummaryRunner>{
new TUSummaryRunner{
136TUSummaryRunner::TUSummaryRunner(llvm::Triple TargetTriple,
137 std::unique_ptr<SerializationFormat> Format,
138 const FrontendOptions &Opts)
139 : MultiplexConsumer(std::vector<std::unique_ptr<ASTConsumer>>{}),
140 Summary(std::move(TargetTriple),
143 Format(std::move(Format)), Opts(Opts) {
144 assert(this->Format);
150 assert(!Extractors.empty());
159void TUSummaryRunner::HandleTranslationUnit(
ASTContext &Ctx) {
164 llvm::sys::sandbox::ScopedSetting Guard = llvm::sys::sandbox::scopedDisable();
179std::unique_ptr<ASTConsumer>
183 if (!WrappedConsumer)
186 if (
auto Runner = TUSummaryRunner::create(CI)) {
188 std::vector<std::unique_ptr<ASTConsumer>> Consumers;
189 Consumers.reserve(2);
190 Consumers.push_back(std::move(WrappedConsumer));
191 Consumers.push_back(std::move(Runner));
192 return std::make_unique<MultiplexConsumer>(std::move(Consumers));
194 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()
TargetInfo & getTarget() const
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::string SSAFCompilationUnitId
Stable identifier for this translation unit, used as the name of the CompilationUnit BuildNamespace o...
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
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
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.
Defines the clang::TargetInfo interface.
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< SerializationFormat > makeFormat(llvm::StringRef FormatName)
Try to instantiate a SerializationFormat with a given name.
std::unique_ptr< TUSummaryExtractor > makeTUSummaryExtractor(llvm::StringRef SummaryName, TUSummaryBuilder &Builder)
Try to instantiate a TUSummaryExtractor 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.