Raise an exception, that will also print all messages in the IR.
Source code in xdsl/utils/diagnostic.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 | def raise_exception(self, ir: IRNode, underlying_error: Exception) -> NoReturn:
"""Raise an exception, that will also print all messages in the IR."""
from xdsl.printer import Printer
f = StringIO()
p = Printer(stream=f, diagnostic=self, print_generic_format=True)
toplevel = ir.get_toplevel_object()
match toplevel:
case Operation():
p.print_op(toplevel)
p.print_string("\n")
case Block():
p.print_block(toplevel)
p.print_string("\n")
case Region():
p.print_region(toplevel)
# __notes__ only in 3.11 and above
if hasattr(underlying_error, "add_note"):
# Use official API if present
getattr(underlying_error, "add_note")(f.getvalue())
else:
# Add our own __notes__ if not
if not hasattr(underlying_error, "__notes__"):
notes: list[str] = []
setattr(underlying_error, "__notes__", notes)
else:
notes = getattr(underlying_error, "__notes__")
notes.append(f.getvalue())
raise underlying_error
|