25#include "llvm/ADT/StringRef.h"
26#include "llvm/Support/IOSandbox.h"
27#include "llvm/Support/Path.h"
41 void addReplacement(clang::tooling::Replacement R)
override {
42 Replacements.push_back(std::move(R));
45 std::vector<clang::tooling::Replacement> Replacements;
52 clang::CharSourceRange Range, StringRef Message)
override {
56 std::vector<ReportResult> Results;
65 static std::unique_ptr<SourceTransformationRunner>
66 create(CompilerInstance &CI, StringRef InFile);
69 SourceTransformationRunner(WPASuite Suite,
const SSAFOptions &Opts,
72 void HandleTranslationUnit(ASTContext &Ctx)
override;
75 AccumulatorSourceEditEmitter Edits;
76 AccumulatorReportEmitter Report;
77 const SSAFOptions &Opts;
86 StringRef Ext = llvm::sys::path::extension(Path);
87 if (!Ext.consume_front(
"."))
115 bool Reported =
false;
119 Diags.
Report(diag::warn_ssaf_source_transformation_requires)
124 Diags.
Report(diag::warn_ssaf_source_transformation_requires)
129 Diags.
Report(diag::warn_ssaf_source_transformation_requires)
134 Diags.
Report(diag::warn_ssaf_source_transformation_requires)
140 Diags.
Report(diag::warn_ssaf_option_ignored_without_source_transformation)
145 Diags.
Report(diag::warn_ssaf_option_ignored_without_source_transformation)
154std::unique_ptr<SourceTransformationRunner>
165 Diags.
Report(diag::warn_ssaf_source_transformation_unknown_name)
170 std::optional<StringRef> WPAExt =
172 std::unique_ptr<SerializationFormat> WPAFormat =
175 Diags.
Report(diag::warn_ssaf_read_wpa_suite_failed)
179 llvm::sys::sandbox::ScopedSetting Guard = llvm::sys::sandbox::scopedDisable();
180 llvm::Expected<WPASuite> SuiteOrErr =
183 Diags.
Report(diag::warn_ssaf_read_wpa_suite_failed)
185 << llvm::toString(SuiteOrErr.takeError());
189 return std::unique_ptr<SourceTransformationRunner>{
190 new SourceTransformationRunner(std::move(*SuiteOrErr), Opts, InFile)};
193SourceTransformationRunner::SourceTransformationRunner(WPASuite Suite,
194 const SSAFOptions &Opts,
196 : MultiplexConsumer(std::vector<std::unique_ptr<ASTConsumer>>{}),
197 Suite(std::move(Suite)), Opts(Opts), InFile(InFile) {
200 std::vector<std::unique_ptr<ASTConsumer>> Consumers;
203 assert(Consumers.front());
207void SourceTransformationRunner::HandleTranslationUnit(
ASTContext &Ctx) {
211 llvm::sys::sandbox::ScopedSetting Guard = llvm::sys::sandbox::scopedDisable();
214 clang::tooling::TranslationUnitReplacements EditDoc;
219 << Opts.
SrcEditFile << llvm::toString(std::move(Err));
224 std::move(
Report.Results)};
228 diag::warn_ssaf_write_transformation_report_failed)
240std::unique_ptr<ASTConsumer>
244 if (!WrappedConsumer)
247 if (
auto Runner = SourceTransformationRunner::create(CI, InFile)) {
249 std::vector<std::unique_ptr<ASTConsumer>> Consumers;
250 Consumers.reserve(2);
251 Consumers.push_back(std::move(WrappedConsumer));
252 Consumers.push_back(std::move(Runner));
253 return std::make_unique<MultiplexConsumer>(std::move(Consumers));
255 return WrappedConsumer;
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
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()
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
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
std::string SrcEditFile
Path of the source-edit output file produced by the source transformation.
std::string TransformationReportFile
Path of the transformation-report output file produced by the source transformation.
std::string CompilationUnitId
Stable identifier used as the name of the CompilationUnit BuildNamespace of every produced TU summary...
std::string SourceTransformation
Name of the SSAF source transformation to run.
std::string GlobalScopeAnalysisResult
Path of the WPASuite input consumed by the source transformation.
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.
llvm::Error writeSARIFTransformationReport(const ReportDocument &Doc, llvm::StringRef Path)
Writes Doc to Path as a SARIF JSON document.
llvm::Error writeYAMLSourceEdits(const clang::tooling::TranslationUnitReplacements &Doc, llvm::StringRef Path)
Writes Doc to Path as a YAML document compatible with clang-apply-replacements.
bool isFormatRegistered(llvm::StringRef FormatName)
Check if a SerializationFormat was registered with a given name.
std::unique_ptr< Transformation > makeTransformation(llvm::StringRef Name, const WPASuite &Suite, SourceEditEmitter &Edits, TransformationReportEmitter &Report)
Try to instantiate a Transformation with a given name.
bool isTransformationRegistered(llvm::StringRef Name)
Check if a Transformation was registered with a given name.
The JSON file list parser is used to communicate input to InstallAPI.
SarifResultLevel
The level of severity associated with a SarifResult.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...