26#include "llvm/ADT/StringRef.h"
27#include "llvm/Support/IOSandbox.h"
28#include "llvm/Support/Path.h"
42 void addReplacement(clang::tooling::Replacement R)
override {
43 Replacements.push_back(std::move(R));
46 std::vector<clang::tooling::Replacement> Replacements;
53 clang::CharSourceRange Range, StringRef Message)
override {
57 std::vector<ReportResult> Results;
66 static std::unique_ptr<SourceTransformationRunner>
67 create(CompilerInstance &CI, StringRef InFile);
70 SourceTransformationRunner(WPASuite Suite,
const SSAFOptions &Opts,
73 void HandleTranslationUnit(ASTContext &Ctx)
override;
76 AccumulatorSourceEditEmitter Edits;
77 AccumulatorReportEmitter Report;
78 const SSAFOptions &Opts;
87 StringRef Ext = llvm::sys::path::extension(Path);
88 if (!Ext.consume_front(
"."))
116 bool Reported =
false;
120 Diags.
Report(diag::warn_ssaf_source_transformation_requires)
125 Diags.
Report(diag::warn_ssaf_source_transformation_requires)
130 Diags.
Report(diag::warn_ssaf_source_transformation_requires)
135 Diags.
Report(diag::warn_ssaf_source_transformation_requires)
141 Diags.
Report(diag::warn_ssaf_option_ignored_without_source_transformation)
146 Diags.
Report(diag::warn_ssaf_option_ignored_without_source_transformation)
155std::unique_ptr<SourceTransformationRunner>
166 Diags.
Report(diag::warn_ssaf_source_transformation_unknown_name)
171 std::optional<StringRef> WPAExt =
173 std::unique_ptr<SerializationFormat> WPAFormat =
176 Diags.
Report(diag::warn_ssaf_read_wpa_suite_failed)
180 llvm::sys::sandbox::ScopedSetting Guard = llvm::sys::sandbox::scopedDisable();
181 llvm::Expected<WPASuite> SuiteOrErr =
184 Diags.
Report(diag::warn_ssaf_read_wpa_suite_failed)
186 << llvm::toString(SuiteOrErr.takeError());
190 return std::unique_ptr<SourceTransformationRunner>{
191 new SourceTransformationRunner(std::move(*SuiteOrErr), Opts, InFile)};
194SourceTransformationRunner::SourceTransformationRunner(WPASuite Suite,
195 const SSAFOptions &Opts,
197 : MultiplexConsumer(std::vector<std::unique_ptr<ASTConsumer>>{}),
198 Suite(std::move(Suite)), Opts(Opts), InFile(InFile) {
201 std::vector<std::unique_ptr<ASTConsumer>> Consumers;
204 assert(Consumers.front());
208void SourceTransformationRunner::HandleTranslationUnit(
ASTContext &Ctx) {
212 llvm::sys::sandbox::ScopedSetting Guard = llvm::sys::sandbox::scopedDisable();
215 clang::tooling::TranslationUnitReplacements EditDoc;
220 << Opts.
SrcEditFile << llvm::toString(std::move(Err));
225 std::move(
Report.Results)};
229 diag::warn_ssaf_write_transformation_report_failed)
241std::unique_ptr<ASTConsumer>
245 if (!WrappedConsumer)
248 if (
auto Runner = SourceTransformationRunner::create(CI, InFile)) {
250 std::vector<std::unique_ptr<ASTConsumer>> Consumers;
251 Consumers.reserve(2);
252 Consumers.push_back(std::move(WrappedConsumer));
253 Consumers.push_back(std::move(Runner));
254 return std::make_unique<MultiplexConsumer>(std::move(Consumers));
256 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 ...
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.
Top level wrappers for InstallAPI frontend operations.
SarifResultLevel
The level of severity associated with a SarifResult.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...