2020-05-01 08:14:03 +08:00
|
|
|
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
# See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
"""Test for the MLIR IR Python bindings"""
|
|
|
|
|
2020-05-07 13:44:12 +08:00
|
|
|
from _npcomp.mlir import ir
|
2020-05-01 08:14:03 +08:00
|
|
|
from npcomp.utils import test_utils
|
|
|
|
|
|
|
|
test_utils.start_filecheck_test()
|
|
|
|
c = ir.MLIRContext()
|
|
|
|
|
|
|
|
# CHECK-LABEL: module @parseSuccess
|
|
|
|
m = c.parse_asm(r"""
|
|
|
|
module @parseSuccess {
|
|
|
|
func @f() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
""")
|
2020-05-01 10:23:18 +08:00
|
|
|
# CHECK: func @f
|
2020-05-01 08:14:03 +08:00
|
|
|
print(m.to_asm())
|
2020-05-01 10:23:18 +08:00
|
|
|
# CHECK: OP NAME: module
|
|
|
|
print("OP NAME:", m.name)
|
|
|
|
# CHECK: NUM_REGIONS: 1
|
|
|
|
print("NUM_REGIONS:", m.num_regions)
|
|
|
|
region = m.region(0)
|
2020-05-02 01:16:19 +08:00
|
|
|
# CHECK: CONTAINED OP: func
|
|
|
|
# CHECK: CONTAINED OP: module_terminator
|
|
|
|
for block in region.blocks:
|
|
|
|
for op in block.operations:
|
|
|
|
print("CONTAINED OP:", op.name)
|
2020-05-01 08:14:03 +08:00
|
|
|
|
|
|
|
# CHECK-LABEL: PARSE_FAILURE
|
|
|
|
print("PARSE_FAILURE")
|
|
|
|
try:
|
|
|
|
m = c.parse_asm("{{ILLEGAL SYNTAX}}")
|
|
|
|
except ValueError as e:
|
|
|
|
# CHECK: [ERROR]: expected operation name in quotes
|
|
|
|
print(e)
|
|
|
|
|
|
|
|
test_utils.end_filecheck_test(__file__)
|