d86b387f9c
for code
--------8<--------
> cat ../backend.native/tests/codegen/basics/check_type.kt
interface I
class A() : I {}
class B() {}
//-----------------------------------------------------------------------------//
fun isTypeOf(a: Any) : Boolean {
return a is A
}
fun check_type(): Boolean {
val a = A()
return isTypeOf(a)
}
//-----------------------------------------------------------------------------//
fun isNotTypeOf(a: Any) : Boolean {
return a !is A
}
fun check_not_type(): Boolean {
val b = B()
return isNotTypeOf(b)
}
//-----------------------------------------------------------------------------//
fun isTypeOfInterface(a: Any) : Boolean {
return a is I
}
fun check_interface(): Boolean {
val a = A()
return isTypeOfInterface(a)
}
--------8<--------
translator generates:
--------8<--------
> llvm-dis-mp-3.8 ../backend.native/tests/codegen/basics/check_type.kt.bc -o -
; ModuleID = '../backend.native/tests/codegen/basics/check_type.kt.bc'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.12.0"
...
define i1 @"kfun:isTypeOf(Any)"(i8*) {
entry:
%a = alloca i8*
store i8* %0, i8** %a
%tmp_1 = load i8*, i8** %a
%tmp_2 = bitcast i8* %tmp_1 to %struct.ObjHeader*
%tmp_3 = call i8 @IsInstance(%struct.ObjHeader* %tmp_2, %struct.TypeInfo* @"ktype:A")
%tmp_0 = trunc i8 %tmp_3 to i1
ret i1 %tmp_0
}
...
define i1 @"kfun:isNotTypeOf(Any)"(i8*) {
entry:
%a = alloca i8*
store i8* %0, i8** %a
%tmp_2 = load i8*, i8** %a
%tmp_3 = bitcast i8* %tmp_2 to %struct.ObjHeader*
%tmp_4 = call i8 @IsInstance(%struct.ObjHeader* %tmp_3, %struct.TypeInfo* @"ktype:A")
%tmp_1 = trunc i8 %tmp_4 to i1
%tmp_0 = xor i1 %tmp_1, true
ret i1 %tmp_0
}
...
define i1 @"kfun:isTypeOfInterface(Any)"(i8*) {
entry:
%a = alloca i8*
store i8* %0, i8** %a
%tmp_1 = load i8*, i8** %a
%tmp_2 = bitcast i8* %tmp_1 to %struct.ObjHeader*
%tmp_3 = call i8 @IsInstance(%struct.ObjHeader* %tmp_2, %struct.TypeInfo* @"ktype:I")
%tmp_0 = trunc i8 %tmp_3 to i1
ret i1 %tmp_0
}
--------8<--------