@@ -21,7 +21,7 @@ def testParsePrint():
21
21
assert t .context is ctx
22
22
ctx = None
23
23
gc .collect ()
24
- # CHECK: " hello"
24
+ # CHECK: hello
25
25
print (str (t ))
26
26
# CHECK: StringAttr("hello")
27
27
print (repr (t ))
@@ -169,6 +169,8 @@ def testFloatAttr():
169
169
fattr = FloatAttr (Attribute .parse ("42.0 : f32" ))
170
170
# CHECK: fattr value: 42.0
171
171
print ("fattr value:" , fattr .value )
172
+ # CHECK: fattr float: 42.0 <class 'float'>
173
+ print ("fattr float:" , float (fattr ), type (float (fattr )))
172
174
173
175
# Test factory methods.
174
176
# CHECK: default_get: 4.200000e+01 : f32
@@ -196,15 +198,23 @@ def testIntegerAttr():
196
198
print ("i_attr value:" , i_attr .value )
197
199
# CHECK: i_attr type: i64
198
200
print ("i_attr type:" , i_attr .type )
201
+ # CHECK: i_attr int: 42 <class 'int'>
202
+ print ("i_attr int:" , int (i_attr ), type (int (i_attr )))
199
203
si_attr = IntegerAttr (Attribute .parse ("-1 : si8" ))
200
204
# CHECK: si_attr value: -1
201
205
print ("si_attr value:" , si_attr .value )
202
206
ui_attr = IntegerAttr (Attribute .parse ("255 : ui8" ))
207
+ # CHECK: i_attr int: -1 <class 'int'>
208
+ print ("si_attr int:" , int (si_attr ), type (int (si_attr )))
203
209
# CHECK: ui_attr value: 255
204
210
print ("ui_attr value:" , ui_attr .value )
211
+ # CHECK: i_attr int: 255 <class 'int'>
212
+ print ("ui_attr int:" , int (ui_attr ), type (int (ui_attr )))
205
213
idx_attr = IntegerAttr (Attribute .parse ("-1 : index" ))
206
214
# CHECK: idx_attr value: -1
207
215
print ("idx_attr value:" , idx_attr .value )
216
+ # CHECK: idx_attr int: -1 <class 'int'>
217
+ print ("idx_attr int:" , int (idx_attr ), type (int (idx_attr )))
208
218
209
219
# Test factory methods.
210
220
# CHECK: default_get: 42 : i32
@@ -218,6 +228,8 @@ def testBoolAttr():
218
228
battr = BoolAttr (Attribute .parse ("true" ))
219
229
# CHECK: iattr value: True
220
230
print ("iattr value:" , battr .value )
231
+ # CHECK: iattr bool: True <class 'bool'>
232
+ print ("iattr bool:" , bool (battr ), type (bool (battr )))
221
233
222
234
# Test factory methods.
223
235
# CHECK: default_get: true
@@ -278,14 +290,25 @@ def testStringAttr():
278
290
sattr = StringAttr (Attribute .parse ('"stringattr"' ))
279
291
# CHECK: sattr value: stringattr
280
292
print ("sattr value:" , sattr .value )
281
- # CHECK: sattr value: b'stringattr'
282
- print ("sattr value:" , sattr .value_bytes )
293
+ # CHECK: sattr value_bytes: b'stringattr'
294
+ print ("sattr value_bytes:" , sattr .value_bytes )
295
+ # CHECK: sattr str: stringattr
296
+ print ("sattr str:" , str (sattr ))
297
+
298
+ typed_sattr = StringAttr (Attribute .parse ('"stringattr" : i32' ))
299
+ # CHECK: typed_sattr value: stringattr
300
+ print ("typed_sattr value:" , typed_sattr .value )
301
+ # CHECK: typed_sattr str: stringattr
302
+ print ("typed_sattr str:" , str (typed_sattr ))
283
303
284
304
# Test factory methods.
285
- # CHECK: default_get: "foobar"
286
- print ("default_get:" , StringAttr .get ("foobar" ))
287
- # CHECK: typed_get: "12345" : i32
288
- print ("typed_get:" , StringAttr .get_typed (IntegerType .get_signless (32 ), "12345" ))
305
+ # CHECK: default_get: StringAttr("foobar")
306
+ print ("default_get:" , repr (StringAttr .get ("foobar" )))
307
+ # CHECK: typed_get: StringAttr("12345" : i32)
308
+ print (
309
+ "typed_get:" ,
310
+ repr (StringAttr .get_typed (IntegerType .get_signless (32 ), "12345" )),
311
+ )
289
312
290
313
291
314
# CHECK-LABEL: TEST: testNamedAttr
@@ -294,8 +317,8 @@ def testNamedAttr():
294
317
with Context ():
295
318
a = Attribute .parse ('"stringattr"' )
296
319
named = a .get_named ("foobar" ) # Note: under the small object threshold
297
- # CHECK: attr: "stringattr"
298
- print ("attr:" , named .attr )
320
+ # CHECK: attr: StringAttr( "stringattr")
321
+ print ("attr:" , repr ( named .attr ) )
299
322
# CHECK: name: foobar
300
323
print ("name:" , named .name )
301
324
# CHECK: named: NamedAttribute(foobar="stringattr")
@@ -367,6 +390,65 @@ def __bool__(self):
367
390
print ("myboolarray:" , DenseBoolArrayAttr .get ([MyBool ()]))
368
391
369
392
393
+ # CHECK-LABEL: TEST: testDenseArrayAttrConstruction
394
+ @run
395
+ def testDenseArrayAttrConstruction ():
396
+ with Context (), Location .unknown ():
397
+
398
+ def create_and_print (cls , x ):
399
+ try :
400
+ darr = cls .get (x )
401
+ print (f"input: { x } ({ type (x )} ), result: { darr } " )
402
+ except Exception as ex :
403
+ print (f"input: { x } ({ type (x )} ), error: { ex } " )
404
+
405
+ # CHECK: input: [4, 2] (<class 'list'>),
406
+ # CHECK-SAME: result: array<i8: 4, 2>
407
+ create_and_print (DenseI8ArrayAttr , [4 , 2 ])
408
+
409
+ # CHECK: input: [4, 2.0] (<class 'list'>),
410
+ # CHECK-SAME: error: get(): incompatible function arguments
411
+ create_and_print (DenseI8ArrayAttr , [4 , 2.0 ])
412
+
413
+ # CHECK: input: [40000, 2] (<class 'list'>),
414
+ # CHECK-SAME: error: get(): incompatible function arguments
415
+ create_and_print (DenseI8ArrayAttr , [40000 , 2 ])
416
+
417
+ # CHECK: input: range(0, 4) (<class 'range'>),
418
+ # CHECK-SAME: result: array<i8: 0, 1, 2, 3>
419
+ create_and_print (DenseI8ArrayAttr , range (4 ))
420
+
421
+ # CHECK: input: [IntegerAttr(4 : i64), IntegerAttr(2 : i64)] (<class 'list'>),
422
+ # CHECK-SAME: result: array<i8: 4, 2>
423
+ create_and_print (DenseI8ArrayAttr , [Attribute .parse (f"{ x } " ) for x in [4 , 2 ]])
424
+
425
+ # CHECK: input: [IntegerAttr(4000 : i64), IntegerAttr(2 : i64)] (<class 'list'>),
426
+ # CHECK-SAME: error: get(): incompatible function arguments
427
+ create_and_print (DenseI8ArrayAttr , [Attribute .parse (f"{ x } " ) for x in [4000 , 2 ]])
428
+
429
+ # CHECK: input: [IntegerAttr(4 : i64), FloatAttr(2.000000e+00 : f64)] (<class 'list'>),
430
+ # CHECK-SAME: error: get(): incompatible function arguments
431
+ create_and_print (DenseI8ArrayAttr , [Attribute .parse (f"{ x } " ) for x in [4 , 2.0 ]])
432
+
433
+ # CHECK: input: [IntegerAttr(4 : i8), IntegerAttr(2 : ui16)] (<class 'list'>),
434
+ # CHECK-SAME: result: array<i8: 4, 2>
435
+ create_and_print (
436
+ DenseI8ArrayAttr , [Attribute .parse (s ) for s in ["4 : i8" , "2 : ui16" ]]
437
+ )
438
+
439
+ # CHECK: input: [FloatAttr(4.000000e+00 : f64), FloatAttr(2.000000e+00 : f64)] (<class 'list'>)
440
+ # CHECK-SAME: result: array<f32: 4.000000e+00, 2.000000e+00>
441
+ create_and_print (
442
+ DenseF32ArrayAttr , [Attribute .parse (f"{ x } " ) for x in [4.0 , 2.0 ]]
443
+ )
444
+
445
+ # CHECK: [BoolAttr(true), BoolAttr(false)] (<class 'list'>),
446
+ # CHECK-SAME: result: array<i1: true, false>
447
+ create_and_print (
448
+ DenseBoolArrayAttr , [Attribute .parse (f"{ x } " ) for x in ["true" , "false" ]]
449
+ )
450
+
451
+
370
452
# CHECK-LABEL: TEST: testDenseIntAttrGetItem
371
453
@run
372
454
def testDenseIntAttrGetItem ():
@@ -620,7 +702,6 @@ def print_container_item(attr_asm):
620
702
@run
621
703
def testConcreteAttributesRoundTrip ():
622
704
with Context (), Location .unknown ():
623
-
624
705
# CHECK: FloatAttr(4.200000e+01 : f32)
625
706
print (repr (Attribute .parse ("42.0 : f32" )))
626
707
0 commit comments