21#include "llvm/ADT/StringExtras.h"
22#include "llvm/ADT/StringRef.h"
23#include "llvm/Support/IOSandbox.h"
24#include "llvm/Support/Path.h"
25#include "llvm/TargetParser/Triple.h"
33static std::optional<std::pair<llvm::StringRef, llvm::StringRef>>
35 StringRef SSAFTUSummaryFile) {
37 StringRef Ext = llvm::sys::path::extension(SSAFTUSummaryFile);
38 StringRef FilePath = SSAFTUSummaryFile.drop_back(Ext.size());
40 if (!Ext.consume_front(
".") || FilePath.empty()) {
41 Diags.
Report(diag::warn_ssaf_extract_tu_summary_file_unknown_format)
47 Diags.
Report(diag::warn_ssaf_extract_tu_summary_file_unknown_output_format)
48 << Ext << SSAFTUSummaryFile;
52 return std::pair{Ext, FilePath};
59 if (SSAFExtractSummaries.empty()) {
60 Diags.
Report(diag::warn_ssaf_must_enable_summary_extractors);
64 std::vector<StringRef> UnrecognizedExtractorNames;
65 for (StringRef Name : SSAFExtractSummaries)
67 UnrecognizedExtractorNames.push_back(Name);
69 if (!UnrecognizedExtractorNames.empty()) {
70 Diags.
Report(diag::warn_ssaf_extract_summary_unknown_extractor_name)
71 << UnrecognizedExtractorNames.size()
72 << llvm::join(UnrecognizedExtractorNames,
", ");
79static std::vector<std::unique_ptr<ASTConsumer>>
82 std::vector<std::unique_ptr<ASTConsumer>> Extractors;
83 Extractors.reserve(SSAFExtractSummaries.size());
84 for (StringRef Name : SSAFExtractSummaries) {
100 static std::unique_ptr<TUSummaryRunner>
create(CompilerInstance &CI);
103 TUSummaryRunner(llvm::Triple TargetTriple,
104 std::unique_ptr<SerializationFormat> Format,
105 const SSAFOptions &Opts);
107 void HandleTranslationUnit(ASTContext &Ctx)
override;
112 const SSAFOptions &Opts;
114 TUSummaryBuilder Builder = TUSummaryBuilder(Summary, Opts);
115 std::unique_ptr<SerializationFormat> Format;
119std::unique_ptr<TUSummaryRunner> TUSummaryRunner::create(
CompilerInstance &CI) {
124 Diags.
Report(diag::warn_ssaf_tu_summary_requires_compilation_unit_id);
130 if (!MaybePair.has_value())
132 auto [FormatName, OutputPath] = MaybePair.value();
137 return std::unique_ptr<TUSummaryRunner>{
new TUSummaryRunner{
141TUSummaryRunner::TUSummaryRunner(llvm::Triple TargetTriple,
142 std::unique_ptr<SerializationFormat> Format,
143 const SSAFOptions &Opts)
144 : MultiplexConsumer(std::vector<std::unique_ptr<ASTConsumer>>{}),
145 Summary(std::move(TargetTriple),
148 Opts(Opts), Format(std::move(Format)) {
149 assert(this->Format);
155 assert(!Extractors.empty());
164void TUSummaryRunner::HandleTranslationUnit(
ASTContext &Ctx) {
169 llvm::sys::sandbox::ScopedSetting Guard = llvm::sys::sandbox::scopedDisable();
172 if (
auto Err = Format->writeTUSummary(Summary, Opts.
TUSummaryFile)) {
184std::unique_ptr<ASTConsumer>
188 if (!WrappedConsumer)
191 if (
auto Runner = TUSummaryRunner::create(CI)) {
193 std::vector<std::unique_ptr<ASTConsumer>> Consumers;
194 Consumers.reserve(2);
195 Consumers.push_back(std::move(WrappedConsumer));
196 Consumers.push_back(std::move(Runner));
197 return std::make_unique<MultiplexConsumer>(std::move(Consumers));
199 return WrappedConsumer;
Defines the clang::ASTContext interface.
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.
ssaf::SSAFOptions & getSSAFOpts()
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.
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.
std::string CompilationUnitId
Stable identifier used as the name of the CompilationUnit BuildNamespace of every produced TU summary...
std::vector< std::string > ExtractSummaries
List of SSAF extractors to enable.
std::string TUSummaryFile
The TU summary output file with the file extension representing the serialization format.
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.
Top level wrappers for InstallAPI frontend operations.