diff --git a/tools/vast-detect-parsers/ParserCategoryDetector.cpp b/tools/vast-detect-parsers/ParserCategoryDetector.cpp new file mode 100644 index 0000000000..a0e5c28139 --- /dev/null +++ b/tools/vast-detect-parsers/ParserCategoryDetector.cpp @@ -0,0 +1,69 @@ +// Copyright (c) 2024, Trail of Bits, Inc. + +#ifdef VAST_ENABLE_SARIF + #include "SarifPasses.hpp" + + #include "vast/Dialect/Parser/Ops.hpp" + #include "vast/Frontend/Sarif.hpp" + +namespace vast { + void ParserCategoryDetector::runOnOperation() { + getOperation().walk([&](pr::Source op) { + gap::sarif::result result{ + .ruleId{ "pr-source" }, + .ruleIndex = 0, + .kind = gap::sarif::kind::kInformational, + .level = gap::sarif::level::kNote, + .message{ + .text{ { "Parser source detected" } }, + }, + .locations{}, + }; + if (auto loc = cc::sarif::mk_location(op.getLoc()); + loc.physicalLocation.has_value()) + { + result.locations.push_back(std::move(loc)); + } + results.push_back(result); + }); + + getOperation().walk([&](pr::Sink op) { + gap::sarif::result result{ + .ruleId{ "pr-sink" }, + .ruleIndex = 0, + .kind = gap::sarif::kind::kInformational, + .level = gap::sarif::level::kNote, + .message{ + .text{ { "Parser sink detected" } }, + }, + .locations{}, + }; + if (auto loc = cc::sarif::mk_location(op.getLoc()); + loc.physicalLocation.has_value()) + { + result.locations.push_back(std::move(loc)); + } + results.push_back(result); + }); + + getOperation().walk([&](pr::Parse op) { + gap::sarif::result result{ + .ruleId{ "pr-parse" }, + .ruleIndex = 0, + .kind = gap::sarif::kind::kInformational, + .level = gap::sarif::level::kNote, + .message{ + .text{ { "Parsing operation detected" } }, + }, + .locations{}, + }; + if (auto loc = cc::sarif::mk_location(op.getLoc()); + loc.physicalLocation.has_value()) + { + result.locations.push_back(std::move(loc)); + } + results.push_back(result); + }); + } +} // namespace vast +#endif diff --git a/tools/vast-detect-parsers/ParserSourceDetector.cpp b/tools/vast-detect-parsers/ParserSourceDetector.cpp deleted file mode 100644 index 202d09f2a9..0000000000 --- a/tools/vast-detect-parsers/ParserSourceDetector.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2024, Trail of Bits, Inc. - -#ifdef VAST_ENABLE_SARIF - #include "SarifPasses.hpp" - - #include "vast/Dialect/Parser/Ops.hpp" - #include "vast/Frontend/Sarif.hpp" - -namespace vast { - void ParserSourceDetector::runOnOperation() { - getOperation().walk([&](pr::Source op) { - gap::sarif::result result{ - .ruleId{ "pr-source" }, - .ruleIndex = 0, - .kind = gap::sarif::kind::kInformational, - .level = gap::sarif::level::kNote, - .message{ - .text{ { "Parser source detected" } }, - }, - .locations{}, - }; - if (auto loc = cc::sarif::mk_location(op.getLoc()); - loc.physicalLocation.has_value()) - { - result.locations.push_back(std::move(loc)); - } - results.push_back(result); - }); - } -} // namespace vast -#endif diff --git a/tools/vast-detect-parsers/SarifPasses.hpp b/tools/vast-detect-parsers/SarifPasses.hpp index 04874855e9..40c00b05f7 100644 --- a/tools/vast-detect-parsers/SarifPasses.hpp +++ b/tools/vast-detect-parsers/SarifPasses.hpp @@ -14,12 +14,12 @@ VAST_UNRELAX_WARNINGS #include namespace vast { - struct ParserSourceDetector - : mlir::PassWrapper< ParserSourceDetector, mlir::OperationPass< mlir::ModuleOp > > + struct ParserCategoryDetector + : mlir::PassWrapper< ParserCategoryDetector, mlir::OperationPass< mlir::ModuleOp > > { std::vector< gap::sarif::result > &results; - ParserSourceDetector(std::vector< gap::sarif::result > &results) : results(results) {} + ParserCategoryDetector(std::vector< gap::sarif::result > &results) : results(results) {} void runOnOperation() override; }; diff --git a/tools/vast-detect-parsers/main.cpp b/tools/vast-detect-parsers/main.cpp index 984bb843e4..e4bc7c58b3 100644 --- a/tools/vast-detect-parsers/main.cpp +++ b/tools/vast-detect-parsers/main.cpp @@ -73,7 +73,7 @@ namespace vast { "parser-source-to-sarif", "Dumps all pr.source locations to a SARIF file.", [](mlir::OpPassManager &pm, const SarifOptions &opts) { auto writer = std::make_unique< SarifWriter >(opts.out_path); - pm.addPass(std::make_unique< vast::ParserSourceDetector >(writer->results)); + pm.addPass(std::make_unique< vast::ParserCategoryDetector >(writer->results)); pm.addPass(std::move(writer)); } );