Files
clang-p2996/mlir/test/Bindings/Python/ir_location.py
Stella Laurenzo ad958f648e [mlir][Python] Add missing capsule->module and Context.create_module.
* Extends Context/Operation interning to cover Module as well.
* Implements Module.context, Attribute.context, Type.context, and Location.context back-references (facilitated testing and also on the TODO list).
* Adds method to create an empty Module.
* Discovered missing in npcomp.

Differential Revision: https://reviews.llvm.org/D89294
2020-10-13 13:10:33 -07:00

41 lines
843 B
Python

# RUN: %PYTHON %s | FileCheck %s
import gc
import mlir
def run(f):
print("\nTEST:", f.__name__)
f()
gc.collect()
assert mlir.ir.Context._get_live_count() == 0
# CHECK-LABEL: TEST: testUnknown
def testUnknown():
ctx = mlir.ir.Context()
loc = ctx.get_unknown_location()
assert loc.context is ctx
ctx = None
gc.collect()
# CHECK: unknown str: loc(unknown)
print("unknown str:", str(loc))
# CHECK: unknown repr: loc(unknown)
print("unknown repr:", repr(loc))
run(testUnknown)
# CHECK-LABEL: TEST: testFileLineCol
def testFileLineCol():
ctx = mlir.ir.Context()
loc = ctx.get_file_location("foo.txt", 123, 56)
ctx = None
gc.collect()
# CHECK: file str: loc("foo.txt":123:56)
print("file str:", str(loc))
# CHECK: file repr: loc("foo.txt":123:56)
print("file repr:", repr(loc))
run(testFileLineCol)