mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-08 04:53:42 +00:00
compiler: simplify interface lowering
This commit simplifies the IR a little bit: instead of calling pseudo-functions runtime.interfaceImplements and runtime.interfaceMethod, real declared functions are being called that are then defined in the interface lowering pass. This should simplify the interaction between various transformation passes. It also reduces the number of lines of code, which is generally a good thing.
This commit is contained in:
committed by
Ron Evans
parent
90076f9401
commit
a4afc3b4b0
Vendored
+22
-18
@@ -1,12 +1,12 @@
|
||||
target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
|
||||
target triple = "armv7m-none-eabi"
|
||||
|
||||
%runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo* }
|
||||
%runtime.typecodeID = type { %runtime.typecodeID*, i32, %runtime.interfaceMethodInfo*, %runtime.typecodeID*, i32 }
|
||||
%runtime.interfaceMethodInfo = type { i8*, i32 }
|
||||
|
||||
@"reflect/types.type:basic:uint8" = private constant %runtime.typecodeID zeroinitializer
|
||||
@"reflect/types.type:basic:int" = private constant %runtime.typecodeID zeroinitializer
|
||||
@"reflect/types.type:named:Number" = private constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:basic:int", i32 0, %runtime.interfaceMethodInfo* null }
|
||||
@"reflect/types.type:named:Number" = private constant %runtime.typecodeID { %runtime.typecodeID* @"reflect/types.type:basic:int", i32 0, %runtime.interfaceMethodInfo* null, %runtime.typecodeID* null, i32 0 }
|
||||
|
||||
declare void @runtime.printuint8(i8)
|
||||
|
||||
@@ -28,8 +28,8 @@ define void @printInterfaces() {
|
||||
}
|
||||
|
||||
define void @printInterface(i32 %typecode, i8* %value) {
|
||||
%typeassert.ok1 = call i1 @"Unmatched$typeassert"(i32 %typecode)
|
||||
br i1 %typeassert.ok1, label %typeswitch.Unmatched, label %typeswitch.notUnmatched
|
||||
%isUnmatched = call i1 @"Unmatched$typeassert"(i32 %typecode)
|
||||
br i1 %isUnmatched, label %typeswitch.Unmatched, label %typeswitch.notUnmatched
|
||||
|
||||
typeswitch.Unmatched: ; preds = %0
|
||||
%unmatched = ptrtoint i8* %value to i32
|
||||
@@ -38,17 +38,17 @@ typeswitch.Unmatched: ; preds = %0
|
||||
ret void
|
||||
|
||||
typeswitch.notUnmatched: ; preds = %0
|
||||
%typeassert.ok = call i1 @"Doubler$typeassert"(i32 %typecode)
|
||||
br i1 %typeassert.ok, label %typeswitch.Doubler, label %typeswitch.notDoubler
|
||||
%isDoubler = call i1 @"Doubler$typeassert"(i32 %typecode)
|
||||
br i1 %isDoubler, label %typeswitch.Doubler, label %typeswitch.notDoubler
|
||||
|
||||
typeswitch.Doubler: ; preds = %typeswitch.notUnmatched
|
||||
%1 = call i32 @"(Doubler).Double"(i8* %value, i8* null, i32 %typecode, i8* null)
|
||||
call void @runtime.printint32(i32 %1)
|
||||
%doubler.result = call i32 @"Doubler.Double$invoke"(i8* %value, i32 %typecode, i8* undef, i8* undef)
|
||||
call void @runtime.printint32(i32 %doubler.result)
|
||||
ret void
|
||||
|
||||
typeswitch.notDoubler: ; preds = %typeswitch.notUnmatched
|
||||
%typeassert.ok2 = icmp eq i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:basic:uint8" to i32), %typecode
|
||||
br i1 %typeassert.ok2, label %typeswitch.byte, label %typeswitch.notByte
|
||||
%typeassert.ok = icmp eq i32 ptrtoint (%runtime.typecodeID* @"reflect/types.type:basic:uint8" to i32), %typecode
|
||||
br i1 %typeassert.ok, label %typeswitch.byte, label %typeswitch.notByte
|
||||
|
||||
typeswitch.byte: ; preds = %typeswitch.notDoubler
|
||||
%byte = ptrtoint i8* %value to i8
|
||||
@@ -69,32 +69,32 @@ typeswitch.notInt16: ; preds = %typeswitch.notByte
|
||||
ret void
|
||||
}
|
||||
|
||||
define i32 @"(Number).Double"(i32 %receiver, i8* %parentHandle) {
|
||||
define i32 @"(Number).Double"(i32 %receiver, i8* %context, i8* %parentHandle) {
|
||||
%ret = mul i32 %receiver, 2
|
||||
ret i32 %ret
|
||||
}
|
||||
|
||||
define i32 @"(Number).Double$invoke"(i8* %receiverPtr, i8* %parentHandle) {
|
||||
define i32 @"(Number).Double$invoke"(i8* %receiverPtr, i8* %context, i8* %parentHandle) {
|
||||
%receiver = ptrtoint i8* %receiverPtr to i32
|
||||
%ret = call i32 @"(Number).Double"(i32 %receiver, i8* null)
|
||||
%ret = call i32 @"(Number).Double"(i32 %receiver, i8* undef, i8* null)
|
||||
ret i32 %ret
|
||||
}
|
||||
|
||||
define internal i32 @"(Doubler).Double"(i8* %0, i8* %1, i32 %actualType, i8* %parentHandle) unnamed_addr {
|
||||
define internal i32 @"Doubler.Double$invoke"(i8* %receiver, i32 %actualType, i8* %context, i8* %parentHandle) unnamed_addr #0 {
|
||||
entry:
|
||||
%"named:Number.icmp" = icmp eq i32 %actualType, ptrtoint (%runtime.typecodeID* @"reflect/types.type:named:Number" to i32)
|
||||
br i1 %"named:Number.icmp", label %"named:Number", label %"named:Number.next"
|
||||
|
||||
"named:Number": ; preds = %entry
|
||||
%2 = call i32 @"(Number).Double$invoke"(i8* %0, i8* %1)
|
||||
ret i32 %2
|
||||
%0 = call i32 @"(Number).Double$invoke"(i8* %receiver, i8* undef, i8* undef)
|
||||
ret i32 %0
|
||||
|
||||
"named:Number.next": ; preds = %entry
|
||||
call void @runtime.nilPanic(i8* undef, i8* undef)
|
||||
unreachable
|
||||
}
|
||||
|
||||
define internal i1 @"Doubler$typeassert"(i32 %actualType) unnamed_addr {
|
||||
define internal i1 @"Doubler$typeassert"(i32 %actualType) unnamed_addr #1 {
|
||||
entry:
|
||||
%"named:Number.icmp" = icmp eq i32 %actualType, ptrtoint (%runtime.typecodeID* @"reflect/types.type:named:Number" to i32)
|
||||
br i1 %"named:Number.icmp", label %then, label %"named:Number.next"
|
||||
@@ -106,10 +106,14 @@ then: ; preds = %entry
|
||||
ret i1 false
|
||||
}
|
||||
|
||||
define internal i1 @"Unmatched$typeassert"(i32 %actualType) unnamed_addr {
|
||||
define internal i1 @"Unmatched$typeassert"(i32 %actualType) unnamed_addr #2 {
|
||||
entry:
|
||||
ret i1 false
|
||||
|
||||
then: ; No predecessors!
|
||||
ret i1 true
|
||||
}
|
||||
|
||||
attributes #0 = { "tinygo-invoke"="reflect/methods.Double() int" "tinygo-methods"="reflect/methods.Double() int" }
|
||||
attributes #1 = { "tinygo-methods"="reflect/methods.Double() int" }
|
||||
attributes #2 = { "tinygo-methods"="reflect/methods.NeverImplementedMethod()" }
|
||||
|
||||
Reference in New Issue
Block a user