Skip to content

Commit

Permalink
pr: Let parser detector detect other categories of operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
xlauko committed Nov 27, 2024
1 parent fd73384 commit a5c3474
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 35 deletions.
69 changes: 69 additions & 0 deletions tools/vast-detect-parsers/ParserCategoryDetector.cpp
Original file line number Diff line number Diff line change
@@ -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
31 changes: 0 additions & 31 deletions tools/vast-detect-parsers/ParserSourceDetector.cpp

This file was deleted.

6 changes: 3 additions & 3 deletions tools/vast-detect-parsers/SarifPasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ VAST_UNRELAX_WARNINGS
#include <gap/sarif/sarif.hpp>

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;
};
Expand Down
2 changes: 1 addition & 1 deletion tools/vast-detect-parsers/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
);
Expand Down

0 comments on commit a5c3474

Please sign in to comment.