github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/transform/testdata/interface.ll (about) 1 target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" 2 target triple = "armv7m-none-eabi" 3 4 @"reflect/types.type:basic:uint8" = linkonce_odr constant { i8, ptr } { i8 8, ptr @"reflect/types.type:pointer:basic:uint8" }, align 4 5 @"reflect/types.type:pointer:basic:uint8" = linkonce_odr constant { i8, ptr } { i8 21, ptr @"reflect/types.type:basic:uint8" }, align 4 6 @"reflect/types.typeid:basic:uint8" = external constant i8 7 @"reflect/types.typeid:basic:int16" = external constant i8 8 @"reflect/types.type:basic:int" = linkonce_odr constant { i8, ptr } { i8 2, ptr @"reflect/types.type:pointer:basic:int" }, align 4 9 @"reflect/types.type:pointer:basic:int" = linkonce_odr constant { i8, ptr } { i8 21, ptr @"reflect/types.type:basic:int" }, align 4 10 @"reflect/methods.NeverImplementedMethod()" = linkonce_odr constant i8 0 11 @"reflect/methods.Double() int" = linkonce_odr constant i8 0 12 @"Number$methodset" = linkonce_odr unnamed_addr constant { i32, [1 x ptr], { ptr } } { i32 1, [1 x ptr] [ptr @"reflect/methods.Double() int"], { ptr } { ptr @"(Number).Double$invoke" } } 13 @"reflect/types.type:named:Number" = linkonce_odr constant { ptr, i8, ptr, ptr } { ptr @"Number$methodset", i8 34, ptr @"reflect/types.type:pointer:named:Number", ptr @"reflect/types.type:basic:int" }, align 4 14 @"reflect/types.type:pointer:named:Number" = linkonce_odr constant { i8, ptr } { i8 21, ptr getelementptr inbounds ({ ptr, i8, ptr, ptr }, ptr @"reflect/types.type:named:Number", i32 0, i32 1) }, align 4 15 16 declare i1 @runtime.typeAssert(ptr, ptr) 17 declare void @runtime.printuint8(i8) 18 declare void @runtime.printint16(i16) 19 declare void @runtime.printint32(i32) 20 declare void @runtime.printptr(i32) 21 declare void @runtime.printnl() 22 declare void @runtime.nilPanic(ptr) 23 24 define void @printInterfaces() { 25 call void @printInterface(ptr @"reflect/types.type:basic:int", ptr inttoptr (i32 5 to ptr)) 26 call void @printInterface(ptr @"reflect/types.type:basic:uint8", ptr inttoptr (i8 120 to ptr)) 27 call void @printInterface(ptr getelementptr inbounds ({ ptr, i8, ptr, ptr }, ptr @"reflect/types.type:named:Number", i32 0, i32 1), ptr inttoptr (i32 3 to ptr)) 28 29 ret void 30 } 31 32 define void @printInterface(ptr %typecode, ptr %value) { 33 %isUnmatched = call i1 @Unmatched$typeassert(ptr %typecode) 34 br i1 %isUnmatched, label %typeswitch.Unmatched, label %typeswitch.notUnmatched 35 36 typeswitch.Unmatched: 37 %unmatched = ptrtoint ptr %value to i32 38 call void @runtime.printptr(i32 %unmatched) 39 call void @runtime.printnl() 40 ret void 41 42 typeswitch.notUnmatched: 43 %isDoubler = call i1 @Doubler$typeassert(ptr %typecode) 44 br i1 %isDoubler, label %typeswitch.Doubler, label %typeswitch.notDoubler 45 46 typeswitch.Doubler: 47 %doubler.result = call i32 @"Doubler.Double$invoke"(ptr %value, ptr %typecode, ptr undef) 48 call void @runtime.printint32(i32 %doubler.result) 49 ret void 50 51 typeswitch.notDoubler: 52 %isByte = call i1 @runtime.typeAssert(ptr %typecode, ptr nonnull @"reflect/types.typeid:basic:uint8") 53 br i1 %isByte, label %typeswitch.byte, label %typeswitch.notByte 54 55 typeswitch.byte: 56 %byte = ptrtoint ptr %value to i8 57 call void @runtime.printuint8(i8 %byte) 58 call void @runtime.printnl() 59 ret void 60 61 typeswitch.notByte: 62 ; this is a type assert that always fails 63 %isInt16 = call i1 @runtime.typeAssert(ptr %typecode, ptr nonnull @"reflect/types.typeid:basic:int16") 64 br i1 %isInt16, label %typeswitch.int16, label %typeswitch.notInt16 65 66 typeswitch.int16: 67 %int16 = ptrtoint ptr %value to i16 68 call void @runtime.printint16(i16 %int16) 69 call void @runtime.printnl() 70 ret void 71 72 typeswitch.notInt16: 73 ret void 74 } 75 76 define i32 @"(Number).Double"(i32 %receiver, ptr %context) { 77 %ret = mul i32 %receiver, 2 78 ret i32 %ret 79 } 80 81 define i32 @"(Number).Double$invoke"(ptr %receiverPtr, ptr %context) { 82 %receiver = ptrtoint ptr %receiverPtr to i32 83 %ret = call i32 @"(Number).Double"(i32 %receiver, ptr undef) 84 ret i32 %ret 85 } 86 87 declare i32 @"Doubler.Double$invoke"(ptr %receiver, ptr %typecode, ptr %context) #0 88 89 declare i1 @Doubler$typeassert(ptr %typecode) #1 90 91 declare i1 @Unmatched$typeassert(ptr %typecode) #2 92 93 attributes #0 = { "tinygo-invoke"="reflect/methods.Double() int" "tinygo-methods"="reflect/methods.Double() int" } 94 attributes #1 = { "tinygo-methods"="reflect/methods.Double() int" } 95 attributes #2 = { "tinygo-methods"="reflect/methods.NeverImplementedMethod()" }