#include "mlir/IR/SymbolTable.h"
#include "mlir/Pass/Pass.h"
#include "llvm/Support/SourceMgr.h"
using namespace mlir;
namespace {
struct TestDiagnosticFilterPass
: public PassWrapper<TestDiagnosticFilterPass,
InterfacePass<SymbolOpInterface>> {
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestDiagnosticFilterPass)
StringRef getArgument() const final { return "test-diagnostic-filter"; }
StringRef getDescription() const final {
return "Test diagnostic filtering support.";
}
TestDiagnosticFilterPass() = default;
TestDiagnosticFilterPass(const TestDiagnosticFilterPass &) {}
void runOnOperation() override {
llvm::errs() << "Test '" << getOperation().getName() << "'\n";
auto filterFn = [&](Location loc) {
FileLineColLoc fileLoc = dyn_cast<FileLineColLoc>(loc);
if (!fileLoc)
return true;
return llvm::none_of(filters, [&](StringRef filter) {
return fileLoc.getFilename().strref().contains(filter);
});
};
llvm::SourceMgr sourceMgr;
SourceMgrDiagnosticHandler handler(sourceMgr, &getContext(), llvm::errs(),
filterFn);
getOperation()->walk([&](Operation *op) {
if (LocationAttr locAttr = op->getAttrOfType<LocationAttr>("test.loc"))
emitError(locAttr, "test diagnostic");
});
}
ListOption<std::string> filters{
*this, "filters",
llvm::cl::desc("Specifies the diagnostic file name filters.")};
};
}
namespace mlir {
namespace test {
void registerTestDiagnosticsPass() {
PassRegistration<TestDiagnosticFilterPass>{};
}
}
}