MLIR  19.0.0git
Diagnostics.h
Go to the documentation of this file.
1 //===-- mlir-c/Diagnostics.h - MLIR Diagnostic subsystem C API ----*- C -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM
4 // Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This header declares the C APIs accessing MLIR Diagnostics subsystem.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_C_DIAGNOSTICS_H
15 #define MLIR_C_DIAGNOSTICS_H
16 
17 #include "mlir-c/IR.h"
18 #include "mlir-c/Support.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 /// An opaque reference to a diagnostic, always owned by the diagnostics engine
25 /// (context). Must not be stored outside of the diagnostic handler.
27  void *ptr;
28 };
29 typedef struct MlirDiagnostic MlirDiagnostic;
30 
31 /// Severity of a diagnostic.
37 };
39 
40 /// Opaque identifier of a diagnostic handler, useful to detach a handler.
41 typedef uint64_t MlirDiagnosticHandlerID;
42 
43 /// Diagnostic handler type. Accepts a reference to a diagnostic, which is only
44 /// guaranteed to be live during the call. The handler is passed the `userData`
45 /// that was provided when the handler was attached to a context. If the handler
46 /// processed the diagnostic completely, it is expected to return success.
47 /// Otherwise, it is expected to return failure to indicate that other handlers
48 /// should attempt to process the diagnostic.
50  void *userData);
51 
52 /// Prints a diagnostic using the provided callback.
54  MlirStringCallback callback,
55  void *userData);
56 
57 /// Returns the location at which the diagnostic is reported.
58 MLIR_CAPI_EXPORTED MlirLocation
60 
61 /// Returns the severity of the diagnostic.
64 
65 /// Returns the number of notes attached to the diagnostic.
66 MLIR_CAPI_EXPORTED intptr_t
68 
69 /// Returns `pos`-th note attached to the diagnostic. Expects `pos` to be a
70 /// valid zero-based index into the list of notes.
72 mlirDiagnosticGetNote(MlirDiagnostic diagnostic, intptr_t pos);
73 
74 /// Attaches the diagnostic handler to the context. Handlers are invoked in the
75 /// reverse order of attachment until one of them processes the diagnostic
76 /// completely. When a handler is invoked it is passed the `userData` that was
77 /// provided when it was attached. If non-NULL, `deleteUserData` is called once
78 /// the system no longer needs to call the handler (for instance after the
79 /// handler is detached or the context is destroyed). Returns an identifier that
80 /// can be used to detach the handler.
81 
83  MlirContext context, MlirDiagnosticHandler handler, void *userData,
84  void (*deleteUserData)(void *));
85 
86 /// Detaches an attached diagnostic handler from the context given its
87 /// identifier.
89 mlirContextDetachDiagnosticHandler(MlirContext context,
91 
92 /// Emits an error at the given location through the diagnostics engine. Used
93 /// for testing purposes.
94 MLIR_CAPI_EXPORTED void mlirEmitError(MlirLocation location,
95  const char *message);
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 #endif // MLIR_C_DIAGNOSTICS_H
MLIR_CAPI_EXPORTED intptr_t mlirDiagnosticGetNumNotes(MlirDiagnostic diagnostic)
Returns the number of notes attached to the diagnostic.
Definition: Diagnostics.cpp:44
MLIR_CAPI_EXPORTED MlirDiagnosticSeverity mlirDiagnosticGetSeverity(MlirDiagnostic diagnostic)
Returns the severity of the diagnostic.
Definition: Diagnostics.cpp:28
MLIR_CAPI_EXPORTED void mlirDiagnosticPrint(MlirDiagnostic diagnostic, MlirStringCallback callback, void *userData)
Prints a diagnostic using the provided callback.
Definition: Diagnostics.cpp:18
MlirDiagnosticSeverity
Severity of a diagnostic.
Definition: Diagnostics.h:32
@ MlirDiagnosticNote
Definition: Diagnostics.h:35
@ MlirDiagnosticRemark
Definition: Diagnostics.h:36
@ MlirDiagnosticWarning
Definition: Diagnostics.h:34
@ MlirDiagnosticError
Definition: Diagnostics.h:33
MLIR_CAPI_EXPORTED MlirDiagnostic mlirDiagnosticGetNote(MlirDiagnostic diagnostic, intptr_t pos)
Returns pos-th note attached to the diagnostic.
Definition: Diagnostics.cpp:50
MlirLogicalResult(* MlirDiagnosticHandler)(MlirDiagnostic, void *userData)
Diagnostic handler type.
Definition: Diagnostics.h:49
MLIR_CAPI_EXPORTED void mlirEmitError(MlirLocation location, const char *message)
Emits an error at the given location through the diagnostics engine.
Definition: Diagnostics.cpp:78
MLIR_CAPI_EXPORTED MlirDiagnosticHandlerID mlirContextAttachDiagnosticHandler(MlirContext context, MlirDiagnosticHandler handler, void *userData, void(*deleteUserData)(void *))
Attaches the diagnostic handler to the context.
Definition: Diagnostics.cpp:56
struct MlirDiagnostic MlirDiagnostic
Definition: Diagnostics.h:29
MLIR_CAPI_EXPORTED void mlirContextDetachDiagnosticHandler(MlirContext context, MlirDiagnosticHandlerID id)
Detaches an attached diagnostic handler from the context given its identifier.
Definition: Diagnostics.cpp:72
uint64_t MlirDiagnosticHandlerID
Opaque identifier of a diagnostic handler, useful to detach a handler.
Definition: Diagnostics.h:41
MLIR_CAPI_EXPORTED MlirLocation mlirDiagnosticGetLocation(MlirDiagnostic diagnostic)
Returns the location at which the diagnostic is reported.
Definition: Diagnostics.cpp:24
struct MlirLogicalResult MlirLogicalResult
Definition: Support.h:119
#define MLIR_CAPI_EXPORTED
Definition: Support.h:46
void(* MlirStringCallback)(MlirStringRef, void *)
A callback for returning string references.
Definition: Support.h:105
An opaque reference to a diagnostic, always owned by the diagnostics engine (context).
Definition: Diagnostics.h:26