@@ -385,45 +385,51 @@ Context() do ctx
385
385
386
386
@testset " array constants" begin
387
387
388
+ # from Julia values
388
389
let
389
- typ = LLVM. Int32Type (ctx)
390
390
vec = Int32[1 ,2 ,3 ,4 ]
391
- ca = ConstantArray (typ, vec)
392
- @test convert (Int32, ConstantInt (ca[1 ])):: Int32 == Int32 (1 )
393
- @test convert (Vector{Int32}, ca) == vec
391
+ ca = ConstantArray (vec, ctx)
392
+ @test size (vec) == size (ca)
393
+ @test length (vec) == length (ca)
394
+ @test ca[1 ] == ConstantInt (vec[1 ], ctx)
395
+ @test collect (ca) == ConstantInt .(vec, Ref (ctx))
394
396
end
395
397
let
396
- typ = LLVM. FloatType (ctx)
397
398
vec = Float32[1.1f0 ,2.2f0 ,3.3f0 ,4.4f0 ]
398
- ca = ConstantArray (typ, vec)
399
- @test convert (Float32, ConstantFP (ca[1 ])):: Float32 == 1.1f0
400
- @test convert (Vector{Float32}, ca) == vec
399
+ ca = ConstantArray (vec, ctx)
400
+ @test size (vec) == size (ca)
401
+ @test length (vec) == length (ca)
402
+ @test ca[1 ] == ConstantFP (vec[1 ], ctx)
403
+ @test collect (ca) == ConstantFP .(vec, Ref (ctx))
401
404
end
405
+
406
+ # multidimensional
402
407
let
403
- typ = LLVM. Int64Type (ctx)
404
- vec = fill (5 , 3 , 4 , 5 , 6 )
405
- ca = ConstantArray (typ, vec)
406
- @test length (ca) == size (vec, 1 )
407
- @test llvmtype (ca) == LLVM. ArrayType (LLVM. ArrayType (LLVM. ArrayType (LLVM. ArrayType (LLVM. Int64Type (ctx), 6 ), 5 ), 4 ), 3 )
408
- # NOTE: can't test content of the array because the API does not support reading from multidimensional arrays
408
+ vec = rand (Int, 2 ,3 ,4 )
409
+ ca = ConstantArray (vec, ctx)
410
+ @test size (vec) == size (ca)
411
+ @test length (vec) == length (ca)
412
+ @test collect (ca) == ConstantInt .(vec, Ref (ctx))
409
413
end
410
414
411
415
end
412
416
413
417
@testset " struct constants" begin
414
-
418
+
419
+ # from Julia values
415
420
let
416
421
test_struct = TestStruct (true , - 99 , 1.5 )
417
- constant_struct = ConstantStruct (test_struct, ctx)
422
+ constant_struct = ConstantStruct (test_struct, ctx; anonymous = true )
418
423
constant_struct_type = llvmtype (constant_struct)
419
-
420
- @test typeof ( constant_struct_type) == LLVM. StructType
421
- @test context (constant_struct_type ) == ctx
424
+
425
+ @test constant_struct_type isa LLVM. StructType
426
+ @test context (constant_struct ) == ctx
422
427
@test ! ispacked (constant_struct_type)
423
428
@test ! isopaque (constant_struct_type)
424
429
425
- @test collect (elements (constant_struct_type)) == [LLVM. Int1Type (ctx), LLVM. Int64Type (ctx), LLVM. HalfType (ctx)]
426
-
430
+ @test collect (elements (constant_struct_type)) ==
431
+ [LLVM. Int1Type (ctx), LLVM. Int64Type (ctx), LLVM. HalfType (ctx)]
432
+
427
433
expected_operands = [
428
434
ConstantInt (LLVM. Int1Type (ctx), Int (true )),
429
435
ConstantInt (LLVM. Int64Type (ctx), - 99 ),
@@ -432,13 +438,11 @@ Context() do ctx
432
438
@test collect (operands (constant_struct)) == expected_operands
433
439
end
434
440
let
435
- named_struct_type = LLVM. StructType (" named_struct" , ctx)
436
- elements! (named_struct_type, [LLVM. Int1Type (ctx), LLVM. Int64Type (ctx), LLVM. HalfType (ctx)], true )
437
-
438
441
test_struct = TestStruct (false , 52 , - 2.5 )
439
- constant_struct = ConstantStruct (test_struct, named_struct_type)
442
+ constant_struct = ConstantStruct (test_struct, ctx; anonymous= false )
443
+ constant_struct_type = llvmtype (constant_struct)
440
444
441
- @test llvmtype (constant_struct) == named_struct_type
445
+ @test constant_struct_type isa LLVM . StructType
442
446
443
447
expected_operands = [
444
448
ConstantInt (LLVM. Int1Type (ctx), Int (false )),
0 commit comments