github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/transform/testdata/reflect-implements.ll (about) 1 target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128" 2 target triple = "i686--linux" 3 4 %runtime._interface = type { ptr, ptr } 5 6 @"reflect/types.type:named:error" = internal constant { i8, i16, ptr, ptr } { i8 52, i16 0, ptr @"reflect/types.type:pointer:named:error", ptr @"reflect/types.type:interface:{Error:func:{}{basic:string}}" }, align 4 7 @"reflect/types.type:interface:{Error:func:{}{basic:string}}" = internal constant { i8, ptr } { i8 20, ptr @"reflect/types.type:pointer:interface:{Error:func:{}{basic:string}}" }, align 4 8 @"reflect/types.type:pointer:interface:{Error:func:{}{basic:string}}" = internal constant { i8, ptr } { i8 21, ptr @"reflect/types.type:interface:{Error:func:{}{basic:string}}" }, align 4 9 @"reflect/types.type:pointer:named:error" = internal constant { i8, i16, ptr } { i8 21, i16 0, ptr @"reflect/types.type:named:error" }, align 4 10 @"reflect/types.type:pointer:named:reflect.rawType" = internal constant { ptr, i8, i16, ptr } { ptr null, i8 21, i16 0, ptr null }, align 4 11 @"reflect/methods.Implements(reflect.Type) bool" = internal constant i8 0, align 1 12 13 ; var errorType = reflect.TypeOf((*error)(nil)).Elem() 14 ; func isError(typ reflect.Type) bool { 15 ; return typ.Implements(errorType) 16 ; } 17 ; The type itself is stored in %typ.value, %typ.typecode just refers to the 18 ; type of reflect.Type. This function can be optimized because errorType is 19 ; known at compile time (after the interp pass has run). 20 define i1 @main.isError(ptr %typ.typecode, ptr %typ.value, ptr %context) { 21 entry: 22 %result = call i1 @"reflect.Type.Implements$invoke"(ptr %typ.value, ptr getelementptr inbounds ({ ptr, i8, ptr }, ptr @"reflect/types.type:pointer:named:reflect.rawType", i32 0, i32 1), ptr @"reflect/types.type:named:error", ptr %typ.typecode, ptr undef) 23 ret i1 %result 24 } 25 26 ; This Implements method call can not be optimized because itf is not known at 27 ; compile time. 28 ; func isUnknown(typ, itf reflect.Type) bool { 29 ; return typ.Implements(itf) 30 ; } 31 define i1 @main.isUnknown(ptr %typ.typecode, ptr %typ.value, ptr %itf.typecode, ptr %itf.value, ptr %context) { 32 entry: 33 %result = call i1 @"reflect.Type.Implements$invoke"(ptr %typ.value, ptr %itf.typecode, ptr %itf.value, ptr %typ.typecode, ptr undef) 34 ret i1 %result 35 } 36 37 declare i1 @"reflect.Type.Implements$invoke"(ptr, ptr, ptr, ptr, ptr) #0 38 declare i1 @"interface:{Error:func:{}{basic:string}}.$typeassert"(ptr %0) #1 39 40 attributes #0 = { "tinygo-invoke"="reflect/methods.Implements(reflect.Type) bool" "tinygo-methods"="reflect/methods.Align() int; reflect/methods.Implements(reflect.Type) bool" } 41 attributes #1 = { "tinygo-methods"="reflect/methods.Error() string" }