20#include "llvm/ADT/StringExtras.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/Support/IOSandbox.h"
23#include "llvm/Support/Path.h"
24#include "llvm/TargetParser/Triple.h"
32static std::optional<std::pair<llvm::StringRef, llvm::StringRef>>
34 StringRef SSAFTUSummaryFile) {
36 StringRef Ext = llvm::sys::path::extension(SSAFTUSummaryFile);
37 StringRef FilePath = SSAFTUSummaryFile.drop_back(Ext.size());
39 if (!Ext.consume_front(
".") || FilePath.empty()) {
40 Diags.
Report(diag::warn_ssaf_extract_tu_summary_file_unknown_format)
46 Diags.
Report(diag::warn_ssaf_extract_tu_summary_file_unknown_output_format)
47 << Ext << SSAFTUSummaryFile;
51 return std::pair{Ext, FilePath};
58 if (SSAFExtractSummaries.empty()) {
59 Diags.
Report(diag::warn_ssaf_must_enable_summary_extractors);
63 std::vector<StringRef> UnrecognizedExtractorNames;
64 for (StringRef Name : SSAFExtractSummaries)
66 UnrecognizedExtractorNames.push_back(Name);
68 if (!UnrecognizedExtractorNames.empty()) {
69 Diags.
Report(diag::warn_ssaf_extract_summary_unknown_extractor_name)
70 << UnrecognizedExtractorNames.size()
71 << llvm::join(UnrecognizedExtractorNames,
", ");
78static std::vector<std::unique_ptr<ASTConsumer>>
81 std::vector<std::unique_ptr<ASTConsumer>> Extractors;
82 Extractors.reserve(SSAFExtractSummaries.size());
83 for (StringRef Name : SSAFExtractSummaries) {
99 static std::unique_ptr<TUSummaryRunner>
create(CompilerInstance &CI);
102 TUSummaryRunner(llvm::Triple TargetTriple,
103 std::unique_ptr<SerializationFormat> Format,
104 const SSAFOptions &Opts);
106 void HandleTranslationUnit(ASTContext &Ctx)
override;
111 const SSAFOptions &Opts;
113 TUSummaryBuilder Builder = TUSummaryBuilder(Summary, Opts);
114 std::unique_ptr<SerializationFormat> Format;
118std::unique_ptr<TUSummaryRunner> TUSummaryRunner::create(
CompilerInstance &CI) {
123 Diags.
Report(diag::warn_ssaf_tu_summary_requires_compilation_unit_id);
129 if (!MaybePair.has_value())
131 auto [FormatName, OutputPath] = MaybePair.value();
136 return std::unique_ptr<TUSummaryRunner>{
new TUSummaryRunner{
140TUSummaryRunner::TUSummaryRunner(llvm::Triple TargetTriple,
141 std::unique_ptr<SerializationFormat> Format,
142 const SSAFOptions &Opts)
143 : MultiplexConsumer(std::vector<std::unique_ptr<ASTConsumer>>{}),
144 Summary(std::move(TargetTriple),
147 Opts(Opts), Format(std::move(Format)) {
148 assert(this->Format);
154 assert(!Extractors.empty());
163void TUSummaryRunner::HandleTranslationUnit(
ASTContext &Ctx) {
168 llvm::sys::sandbox::ScopedSetting Guard = llvm::sys::sandbox::scopedDisable();
171 if (
auto Err = Format->writeTUSummary(Summary, Opts.
TUSummaryFile)) {
183std::unique_ptr<ASTConsumer>
187 if (!WrappedConsumer)
190 if (
auto Runner = TUSummaryRunner::create(CI)) {
192 std::vector<std::unique_ptr<ASTConsumer>> Consumers;
193 Consumers.reserve(2);
194 Consumers.push_back(std::move(WrappedConsumer));
195 Consumers.push_back(std::move(Runner));
196 return std::make_unique<MultiplexConsumer>(std::move(Consumers));
198 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.
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.
The JSON file list parser is used to communicate input to InstallAPI.