ssa: fix abiType & abiNamedOf

This commit is contained in:
visualfc
2024-06-25 12:11:51 +08:00
parent f41511047e
commit ef3619350d
10 changed files with 7115 additions and 885 deletions

56
cl/_testrt/abinamed/in.go Normal file
View File

@@ -0,0 +1,56 @@
package main
import (
"unsafe"
"github.com/goplus/llgo/internal/abi"
)
type T struct {
p *T
t *abi.Type
n uintptr
a []T
}
type eface struct {
typ *abi.Type
data unsafe.Pointer
}
func toEface(i any) *eface {
return (*eface)(unsafe.Pointer(&i))
}
func main() {
e := toEface(T{})
e2 := toEface(abi.Type{})
println(e.typ)
println(e.typ.PtrToThis_)
println(e2.typ)
println(e2.typ.PtrToThis_)
f0 := e.typ.StructType().Fields[0]
if f0.Typ != e.typ.PtrToThis_ {
panic("error field 0")
}
if f0.Typ.Elem() != e.typ {
panic("error field 0 elem")
}
f1 := e.typ.StructType().Fields[1]
if f1.Typ != e2.typ.PtrToThis_ {
panic("error field 1")
}
if f1.Typ.Elem() != e2.typ {
panic("error field 1 elem")
}
f2 := e.typ.StructType().Fields[2]
if f2.Typ != e2.typ.StructType().Fields[0].Typ {
panic("error field 2")
}
f3 := e.typ.StructType().Fields[3]
if f3.Typ.Elem() != e.typ {
panic("error field 3")
}
}

4992
cl/_testrt/abinamed/out.ll Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,7 @@ source_filename = "main"
%"github.com/goplus/llgo/internal/abi.Type" = type { i64, i64, i32, i8, i8, i8, i8, { ptr, ptr }, ptr, %"github.com/goplus/llgo/internal/runtime.String", ptr }
@"main.init$guard" = global i1 false, align 1
@_llgo_int8 = linkonce global ptr null, align 8
@"*_llgo_int8" = linkonce global ptr null, align 8
@0 = private unnamed_addr constant [21 x i8] c"type assertion failed", align 1
@_llgo_string = linkonce global ptr null, align 8
@@ -121,48 +122,62 @@ _llgo_0:
define void @"main.init$after"() {
_llgo_0:
%0 = load ptr, ptr @"*_llgo_int8", align 8
%0 = load ptr, ptr @_llgo_int8, align 8
%1 = icmp eq ptr %0, null
br i1 %1, label %_llgo_1, label %_llgo_2
_llgo_1: ; preds = %_llgo_0
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 3)
%3 = call ptr @"github.com/goplus/llgo/internal/runtime.PointerTo"(ptr %2)
store ptr %3, ptr @"*_llgo_int8", align 8
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %2, i32 0, i32 6
%4 = load i8, ptr %3, align 1
%5 = or i8 %4, 32
store i8 %5, ptr %3, align 1
store ptr %2, ptr @_llgo_int8, align 8
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
%4 = load ptr, ptr @_llgo_string, align 8
%5 = icmp eq ptr %4, null
br i1 %5, label %_llgo_3, label %_llgo_4
%6 = load ptr, ptr @"*_llgo_int8", align 8
%7 = icmp eq ptr %6, null
br i1 %7, label %_llgo_3, label %_llgo_4
_llgo_3: ; preds = %_llgo_2
%6 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24)
store ptr %6, ptr @_llgo_string, align 8
%8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 3)
%9 = call ptr @"github.com/goplus/llgo/internal/runtime.PointerTo"(ptr %8)
store ptr %9, ptr @"*_llgo_int8", align 8
br label %_llgo_4
_llgo_4: ; preds = %_llgo_3, %_llgo_2
%7 = load ptr, ptr @_llgo_int, align 8
%8 = icmp eq ptr %7, null
br i1 %8, label %_llgo_5, label %_llgo_6
%10 = load ptr, ptr @_llgo_string, align 8
%11 = icmp eq ptr %10, null
br i1 %11, label %_llgo_5, label %_llgo_6
_llgo_5: ; preds = %_llgo_4
%9 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %9, i32 0, i32 6
%11 = load i8, ptr %10, align 1
%12 = or i8 %11, 32
store i8 %12, ptr %10, align 1
store ptr %9, ptr @_llgo_int, align 8
%12 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24)
store ptr %12, ptr @_llgo_string, align 8
br label %_llgo_6
_llgo_6: ; preds = %_llgo_5, %_llgo_4
%13 = load ptr, ptr @_llgo_int, align 8
%14 = icmp eq ptr %13, null
br i1 %14, label %_llgo_7, label %_llgo_8
_llgo_7: ; preds = %_llgo_6
%15 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
%16 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %15, i32 0, i32 6
%17 = load i8, ptr %16, align 1
%18 = or i8 %17, 32
store i8 %18, ptr %16, align 1
store ptr %15, ptr @_llgo_int, align 8
br label %_llgo_8
_llgo_8: ; preds = %_llgo_7, %_llgo_6
ret void
}
declare ptr @"github.com/goplus/llgo/internal/runtime.PointerTo"(ptr)
declare ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64)
declare ptr @"github.com/goplus/llgo/internal/runtime.PointerTo"(ptr)
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64)
declare void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface")