26 #ifndef TVM_IR_DIAGNOSTIC_H_
27 #define TVM_IR_DIAGNOSTIC_H_
29 #include <tvm/ffi/reflection/registry.h>
46 class DiagnosticBuilder;
73 refl::ObjectDef<DiagnosticNode>()
88 const std::string& error_kind);
137 template <
typename T>
162 return Diagnostic(this->level, this->span, this->stream_.str(), this->error_kind);
166 std::stringstream stream_;
204 TVM_FFI_ICHECK(get() !=
nullptr);
225 refl::ObjectDef<DiagnosticContextNode>()
257 TVM_FFI_ICHECK(get() !=
nullptr);
A wrapper around std::stringstream to build a diagnostic.
Definition: diagnostic.h:118
DiagnosticBuilder(DiagnosticLevel level, ObjectRef loc)
Definition: diagnostic.h:153
friend class Diagnostic
Definition: diagnostic.h:167
DiagnosticBuilder(const DiagnosticBuilder &builder)
Definition: diagnostic.h:145
Span span
The span of the diagnostic.
Definition: diagnostic.h:127
DiagnosticBuilder(DiagnosticLevel level, Span span)
Definition: diagnostic.h:151
SourceName source_name
The source name.
Definition: diagnostic.h:124
DiagnosticBuilder & operator<<(const T &val)
Definition: diagnostic.h:138
DiagnosticLevel level
The level.
Definition: diagnostic.h:121
DiagnosticBuilder & WithErrorKind(std::string kind)
Set the error kind for this diagnostic.
Definition: diagnostic.h:156
DiagnosticBuilder()
Definition: diagnostic.h:143
std::string error_kind
The error kind (e.g. "TypeError", "ValueError").
Definition: diagnostic.h:135
ObjectRef loc
The object location at which to report an error.
Definition: diagnostic.h:132
Definition: diagnostic.h:212
ffi::Array< Diagnostic > diagnostics
The set of diagnostics to report.
Definition: diagnostic.h:218
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: diagnostic.h:230
static void RegisterReflection()
Definition: diagnostic.h:223
IRModule module
The Module to report against.
Definition: diagnostic.h:215
DiagnosticRenderer renderer
The renderer set for the context.
Definition: diagnostic.h:221
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("DiagnosticContext", DiagnosticContextNode, Object)
Definition: diagnostic.h:234
void Render()
Render the errors and raise a DiagnosticError exception.
void Emit(const Diagnostic &diagnostic)
Emit a diagnostic.
void EmitFatal(const Diagnostic &diagnostic)
Emit a diagnostic and then immediately attempt to render all errors.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(DiagnosticContext, ObjectRef, DiagnosticContextNode)
DiagnosticContextNode * operator->()
Definition: diagnostic.h:256
DiagnosticContext(const IRModule &module, const DiagnosticRenderer &renderer)
static DiagnosticContext Default(const IRModule &source_map)
A compiler diagnostic message.
Definition: diagnostic.h:52
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: diagnostic.h:80
ObjectRef loc
The object location at which to report an error.
Definition: diagnostic.h:65
ffi::String error_kind
The error kind when the diagnostic is used as an error (e.g. "TypeError").
Definition: diagnostic.h:69
ffi::String message
The diagnostic message.
Definition: diagnostic.h:67
DiagnosticLevel level
The level.
Definition: diagnostic.h:55
static void RegisterReflection()
Definition: diagnostic.h:71
Span span
The span at which to report an error.
Definition: diagnostic.h:57
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("Diagnostic", DiagnosticNode, Object)
Display diagnostics in a given display format.
Definition: diagnostic.h:184
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("DiagnosticRenderer", DiagnosticRendererNode, Object)
ffi::TypedFunction< void(DiagnosticContext ctx)> renderer
Definition: diagnostic.h:186
static void RegisterReflection()
Definition: diagnostic.h:188
Definition: diagnostic.h:195
DiagnosticRenderer(ffi::TypedFunction< void(DiagnosticContext ctx)> render)
void Render(const DiagnosticContext &ctx)
DiagnosticRendererNode * operator->()
Definition: diagnostic.h:203
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(DiagnosticRenderer, ObjectRef, DiagnosticRendererNode)
DiagnosticRenderer()
Definition: diagnostic.h:198
Definition: diagnostic.h:84
static DiagnosticBuilder Error(const Object *loc)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Diagnostic, ObjectRef, DiagnosticNode)
static DiagnosticBuilder Error(std::string error_kind, const Object *loc)
static DiagnosticBuilder Bug(ObjectRef loc)
Diagnostic(DiagnosticLevel level, Span span, const std::string &message)
static DiagnosticBuilder Warning(Span span)
static DiagnosticBuilder Note(ObjectRef loc)
static DiagnosticBuilder Warning(const Object *loc)
static DiagnosticBuilder Bug(Span span)
static DiagnosticBuilder Help(Span span)
static DiagnosticBuilder Note(const Object *loc)
static DiagnosticBuilder Bug(const Object *loc)
static DiagnosticBuilder Help(ObjectRef loc)
static DiagnosticBuilder Warning(ObjectRef loc)
static DiagnosticBuilder Error(Span span)
static DiagnosticBuilder Help(const Object *loc)
static DiagnosticBuilder Error(std::string error_kind, Span span)
Diagnostic(DiagnosticLevel level, Span span, const std::string &message, const std::string &error_kind)
static DiagnosticBuilder Error(std::string error_kind, ObjectRef loc)
static DiagnosticBuilder Error(ObjectRef loc)
static DiagnosticBuilder Note(Span span)
Managed reference class to IRModuleNode.
Definition: module.h:257
The source name of a file span.
Definition: source_map.h:64
Definition: source_map.h:111
IRModule that holds the functions and type definitions.
Definition: repr_printer.h:91
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:37
DiagnosticRenderer TerminalRenderer(std::ostream &ostream)
DiagnosticLevel
The diagnostic level, controls the printing of the message.
Definition: diagnostic.h:38