1# RUN: %PYTHON %s | FileCheck %s 2 3from mlir.ir import * 4import mlir.dialects.emitc as emitc 5 6 7def run(f): 8 print("\nTEST:", f.__name__) 9 with Context() as ctx, Location.unknown(): 10 module = Module.create() 11 with InsertionPoint(module.body): 12 f(ctx) 13 print(module) 14 15 16# CHECK-LABEL: TEST: testConstantOp 17@run 18def testConstantOp(ctx): 19 i32 = IntegerType.get_signless(32) 20 a = emitc.ConstantOp(result=i32, value=IntegerAttr.get(i32, 42)) 21 # CHECK: %{{.*}} = "emitc.constant"() <{value = 42 : i32}> : () -> i32 22 23 24# CHECK-LABEL: TEST: testAddOp 25@run 26def testAddOp(ctx): 27 i32 = IntegerType.get_signless(32) 28 lhs = emitc.ConstantOp(result=i32, value=IntegerAttr.get(i32, 0)) 29 rhs = emitc.ConstantOp(result=i32, value=IntegerAttr.get(i32, 0)) 30 a = emitc.AddOp(i32, lhs, rhs) 31 # CHECK: %{{.*}} = emitc.add %{{.*}}, %{{.*}} : (i32, i32) -> i32 32