1# RUN: %PYTHON %s | FileCheck %s 2 3import gc 4from mlir.ir import * 5 6def run(f): 7 print("\nTEST:", f.__name__) 8 f() 9 gc.collect() 10 assert Context._get_live_count() == 0 11 12 13# CHECK-LABEL: TEST: testUnknown 14def testUnknown(): 15 with Context() as ctx: 16 loc = Location.unknown() 17 assert loc.context is ctx 18 ctx = None 19 gc.collect() 20 # CHECK: unknown str: loc(unknown) 21 print("unknown str:", str(loc)) 22 # CHECK: unknown repr: loc(unknown) 23 print("unknown repr:", repr(loc)) 24 25run(testUnknown) 26 27 28# CHECK-LABEL: TEST: testFileLineCol 29def testFileLineCol(): 30 with Context() as ctx: 31 loc = Location.file("foo.txt", 123, 56) 32 ctx = None 33 gc.collect() 34 # CHECK: file str: loc("foo.txt":123:56) 35 print("file str:", str(loc)) 36 # CHECK: file repr: loc("foo.txt":123:56) 37 print("file repr:", repr(loc)) 38 39run(testFileLineCol) 40 41 42# CHECK-LABEL: TEST: testLocationCapsule 43def testLocationCapsule(): 44 with Context() as ctx: 45 loc1 = Location.file("foo.txt", 123, 56) 46 # CHECK: mlir.ir.Location._CAPIPtr 47 loc_capsule = loc1._CAPIPtr 48 print(loc_capsule) 49 loc2 = Location._CAPICreate(loc_capsule) 50 assert loc2 == loc1 51 assert loc2.context is ctx 52 53run(testLocationCapsule) 54