11#include "mlir/IR/BuiltinAttributes.h"
12#include "mlir/IR/Diagnostics.h"
13#include "mlir/IR/Location.h"
14#include "mlir/IR/MLIRContext.h"
22#include "llvm/Support/ErrorHandling.h"
32 :
mlir::ScopedDiagnosticHandler(ctx), Diags(diags), SrcMgr(srcMgr),
34 setHandler([
this](mlir::Diagnostic &D) {
return handle(D); });
41 if (
auto file = mlir::dyn_cast<mlir::FileLineColLoc>(loc)) {
44 if (file.getLine() == 0 || file.getColumn() == 0)
52 if (
auto fused = mlir::dyn_cast<mlir::FusedLoc>(loc)) {
53 for (mlir::Location child : fused.getLocations()) {
58 return clang::SourceLocation();
60 if (
auto callsite = mlir::dyn_cast<mlir::CallSiteLoc>(loc))
61 return translateLoc(callsite.getCallee());
62 if (
auto named = mlir::dyn_cast<mlir::NameLoc>(loc))
63 return translateLoc(named.getChildLoc());
65 return clang::SourceLocation();
68void CIRDiagnosticHandler::emit(mlir::Diagnostic &diag,
bool isNote) {
71 assert(diag.getSeverity() == mlir::DiagnosticSeverity::Note &&
72 "a note attached to a diagnostic must have Note severity");
73 diagID = clang::diag::note_cir_mlir_diagnostic;
75 switch (diag.getSeverity()) {
76 case mlir::DiagnosticSeverity::Error:
77 diagID = clang::diag::err_cir_mlir_diagnostic;
79 case mlir::DiagnosticSeverity::Warning:
80 diagID = clang::diag::warn_cir_mlir_diagnostic;
82 case mlir::DiagnosticSeverity::Remark:
83 diagID = clang::diag::remark_cir_mlir_diagnostic;
85 case mlir::DiagnosticSeverity::Note:
86 llvm_unreachable(
"a top-level MLIR diagnostic should not have Note "
87 "severity; notes arrive via getNotes()");
90 Diags.Report(translateLoc(diag.getLocation()), diagID) << diag.str();
93mlir::LogicalResult CIRDiagnosticHandler::handle(mlir::Diagnostic &diag) {
95 for (mlir::Diagnostic ¬e : diag.getNotes())
97 return mlir::success();
Defines the Diagnostic-related interfaces.
Defines the clang::FileManager interface and associated types.
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
CIRDiagnosticHandler(mlir::MLIRContext *ctx, clang::DiagnosticsEngine &diags, clang::SourceManager &srcMgr, clang::FileManager &fileMgr)
Concrete class used by the front-end to report problems and issues.
Implements support for file system lookup, file system caching, and directory search management.
OptionalFileEntryRef getOptionalFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true, bool IsText=true)
Get a FileEntryRef if it exists, without doing anything on error.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
SourceLocation translateFileLineCol(const FileEntry *SourceFile, unsigned Line, unsigned Col) const
Get the source location for the given file:line:col triplet.