forked from xdslproject/xdsl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
65 lines (49 loc) · 1.92 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from io import StringIO
from typing import Any
from xdsl.ir import Operation
from xdsl.printer import Printer
from xdsl.utils.diagnostic import Diagnostic
def assert_print_op(
operation: Operation,
expected: str,
diagnostic: Diagnostic | None,
print_generic_format: bool = True,
print_debuginfo: bool = False,
**printer_options: Any,
):
"""
Utility function that helps to check the printing of an operation compared to
some string
Examples
--------
To check that an operation, namely Add prints as:
expected = \
builtin.module() {
%0 : !i32 = arith.addi(%<UNKNOWN> : !i32, %<UNKNOWN> : !i32)
-----------------------^^^^^^^^^^----------------------------------------------------------------
| ERROR: SSAValue is not part of the IR, are you sure all operations are added before their uses?
-------------------------------------------------------------------------------------------------
------------------------------------------^^^^^^^^^^---------------------------------------------
| ERROR: SSAValue is not part of the IR, are you sure all operations are added before their uses?
-------------------------------------------------------------------------------------------------
%1 : !i32 = arith.addi(%0 : !i32, %0 : !i32)
}
we call:
.. code-block:: python
assert_print_op(add, expected)
Additional options can be passed to the printer using keyword arguments:
.. code-block:: python
assert_print_op(add, expected, print_unknown_value_error=False)
"""
file = StringIO("")
if diagnostic is None:
diagnostic = Diagnostic()
printer = Printer(
stream=file,
print_generic_format=print_generic_format,
print_debuginfo=print_debuginfo,
diagnostic=diagnostic,
**printer_options,
)
printer.print(operation)
assert file.getvalue().strip() == expected.strip()