cl: callRuntimeInit; runtime: TracePanic
This commit is contained in:
@@ -13,6 +13,9 @@ source_filename = "github.com/goplus/llgo/internal/runtime"
|
||||
@"github.com/goplus/llgo/internal/runtime.init$guard" = global ptr null
|
||||
@"github.com/goplus/llgo/internal/runtime.sizeBasicTypes" = global ptr null
|
||||
@0 = private unnamed_addr constant [21 x i8] c"I2Int: type mismatch\00", align 1
|
||||
@1 = private unnamed_addr constant [19 x i8] c"MakeAnyString(%p)\0A\00", align 1
|
||||
@2 = private unnamed_addr constant [11 x i8] c"Panic(%p)\0A\00", align 1
|
||||
@3 = private unnamed_addr constant [11 x i8] c"panic: %s\0A\00", align 1
|
||||
|
||||
define ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 %0) {
|
||||
_llgo_0:
|
||||
@@ -108,51 +111,52 @@ _llgo_1: ; preds = %_llgo_0
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
%11 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @0, i64 20)
|
||||
%12 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %11)
|
||||
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %12)
|
||||
unreachable
|
||||
}
|
||||
|
||||
define %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAny"(ptr %0, ptr %1) {
|
||||
_llgo_0:
|
||||
%2 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, i32 0, i32 0
|
||||
%4 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 16)
|
||||
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %4, i32 0, i32 0
|
||||
%6 = load ptr, ptr @"github.com/goplus/llgo/internal/runtime.TyAny", align 8
|
||||
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %4, i32 0, i32 1
|
||||
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %4, i32 0, i32 2
|
||||
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %4, i32 0, i32 4
|
||||
%10 = getelementptr inbounds i64, ptr %9, i64 0
|
||||
store ptr %6, ptr %5, align 8
|
||||
store ptr %0, ptr %7, align 8
|
||||
store i32 0, ptr %8, align 4
|
||||
store i64 0, ptr %10, align 4
|
||||
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, i32 0, i32 1
|
||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 16)
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %2, i32 0, i32 0
|
||||
%4 = load ptr, ptr @"github.com/goplus/llgo/internal/runtime.TyAny", align 8
|
||||
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %2, i32 0, i32 1
|
||||
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %2, i32 0, i32 2
|
||||
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %2, i32 0, i32 4
|
||||
%8 = getelementptr inbounds i64, ptr %7, i64 0
|
||||
store ptr %4, ptr %3, align 8
|
||||
store ptr %0, ptr %5, align 8
|
||||
store i32 0, ptr %6, align 4
|
||||
store i64 0, ptr %8, align 4
|
||||
%9 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8
|
||||
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %9, i32 0, i32 0
|
||||
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %9, i32 0, i32 1
|
||||
store ptr %2, ptr %10, align 8
|
||||
store ptr %1, ptr %11, align 8
|
||||
%12 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, align 8
|
||||
%12 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %9, align 8
|
||||
ret %"github.com/goplus/llgo/internal/runtime.iface" %12
|
||||
}
|
||||
|
||||
define %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %0, i64 %1) {
|
||||
_llgo_0:
|
||||
%2 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, i32 0, i32 0
|
||||
%4 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 16)
|
||||
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %4, i32 0, i32 0
|
||||
%6 = load ptr, ptr @"github.com/goplus/llgo/internal/runtime.TyAny", align 8
|
||||
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %4, i32 0, i32 1
|
||||
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %4, i32 0, i32 2
|
||||
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %4, i32 0, i32 4
|
||||
%10 = getelementptr inbounds i64, ptr %9, i64 0
|
||||
store ptr %6, ptr %5, align 8
|
||||
store ptr %0, ptr %7, align 8
|
||||
store i32 0, ptr %8, align 4
|
||||
store i64 0, ptr %10, align 4
|
||||
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, i32 0, i32 1
|
||||
%12 = inttoptr i64 %1 to ptr
|
||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 16)
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %2, i32 0, i32 0
|
||||
%4 = load ptr, ptr @"github.com/goplus/llgo/internal/runtime.TyAny", align 8
|
||||
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %2, i32 0, i32 1
|
||||
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %2, i32 0, i32 2
|
||||
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %2, i32 0, i32 4
|
||||
%8 = getelementptr inbounds i64, ptr %7, i64 0
|
||||
store ptr %4, ptr %3, align 8
|
||||
store ptr %0, ptr %5, align 8
|
||||
store i32 0, ptr %6, align 4
|
||||
store i64 0, ptr %8, align 4
|
||||
%9 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8
|
||||
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %9, i32 0, i32 0
|
||||
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %9, i32 0, i32 1
|
||||
%12 = inttoptr i64 %1 to ptr
|
||||
store ptr %2, ptr %10, align 8
|
||||
store ptr %12, ptr %11, align 8
|
||||
%13 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, align 8
|
||||
%13 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %9, align 8
|
||||
ret %"github.com/goplus/llgo/internal/runtime.iface" %13
|
||||
}
|
||||
|
||||
@@ -160,45 +164,46 @@ define %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo
|
||||
_llgo_0:
|
||||
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 16)
|
||||
store %"github.com/goplus/llgo/internal/runtime.String" %0, ptr %1, align 8
|
||||
%2 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8
|
||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, i32 0, i32 0
|
||||
%4 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 16)
|
||||
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %4, i32 0, i32 0
|
||||
%6 = load ptr, ptr @"github.com/goplus/llgo/internal/runtime.TyAny", align 8
|
||||
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %4, i32 0, i32 1
|
||||
%8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24)
|
||||
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %4, i32 0, i32 2
|
||||
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %4, i32 0, i32 4
|
||||
%11 = getelementptr inbounds i64, ptr %10, i64 0
|
||||
store ptr %6, ptr %5, align 8
|
||||
store ptr %8, ptr %7, align 8
|
||||
store i32 0, ptr %9, align 4
|
||||
store i64 0, ptr %11, align 4
|
||||
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, i32 0, i32 1
|
||||
store ptr %4, ptr %3, align 8
|
||||
store ptr %1, ptr %12, align 8
|
||||
%13 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, align 8
|
||||
ret %"github.com/goplus/llgo/internal/runtime.iface" %13
|
||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24)
|
||||
%3 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 16)
|
||||
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %3, i32 0, i32 0
|
||||
%5 = load ptr, ptr @"github.com/goplus/llgo/internal/runtime.TyAny", align 8
|
||||
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %3, i32 0, i32 1
|
||||
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %3, i32 0, i32 2
|
||||
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %3, i32 0, i32 4
|
||||
%9 = getelementptr inbounds i64, ptr %8, i64 0
|
||||
store ptr %5, ptr %4, align 8
|
||||
store ptr %2, ptr %6, align 8
|
||||
store i32 0, ptr %7, align 4
|
||||
store i64 0, ptr %9, align 4
|
||||
%10 = call i32 (ptr, ...) @printf(ptr @1, ptr %2)
|
||||
%11 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8
|
||||
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %11, i32 0, i32 0
|
||||
%13 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %11, i32 0, i32 1
|
||||
store ptr %3, ptr %12, align 8
|
||||
store ptr %1, ptr %13, align 8
|
||||
%14 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %11, align 8
|
||||
ret %"github.com/goplus/llgo/internal/runtime.iface" %14
|
||||
}
|
||||
|
||||
define %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeInterface"(ptr %0, ptr %1, ptr %2) {
|
||||
_llgo_0:
|
||||
%3 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8
|
||||
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %3, i32 0, i32 0
|
||||
%5 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 16)
|
||||
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %5, i32 0, i32 0
|
||||
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %5, i32 0, i32 1
|
||||
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %5, i32 0, i32 2
|
||||
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %5, i32 0, i32 4
|
||||
%10 = getelementptr inbounds i64, ptr %9, i64 0
|
||||
store ptr %0, ptr %6, align 8
|
||||
store ptr %1, ptr %7, align 8
|
||||
store i32 0, ptr %8, align 4
|
||||
store i64 0, ptr %10, align 4
|
||||
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %3, i32 0, i32 1
|
||||
store ptr %5, ptr %4, align 8
|
||||
%3 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 16)
|
||||
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %3, i32 0, i32 0
|
||||
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %3, i32 0, i32 1
|
||||
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %3, i32 0, i32 2
|
||||
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %3, i32 0, i32 4
|
||||
%8 = getelementptr inbounds i64, ptr %7, i64 0
|
||||
store ptr %0, ptr %4, align 8
|
||||
store ptr %1, ptr %5, align 8
|
||||
store i32 0, ptr %6, align 4
|
||||
store i64 0, ptr %8, align 4
|
||||
%9 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8
|
||||
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %9, i32 0, i32 0
|
||||
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %9, i32 0, i32 1
|
||||
store ptr %3, ptr %10, align 8
|
||||
store ptr %2, ptr %11, align 8
|
||||
%12 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %3, align 8
|
||||
%12 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %9, align 8
|
||||
ret %"github.com/goplus/llgo/internal/runtime.iface" %12
|
||||
}
|
||||
|
||||
@@ -281,6 +286,41 @@ _llgo_0:
|
||||
ret i64 %3
|
||||
}
|
||||
|
||||
define void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %0) {
|
||||
_llgo_0:
|
||||
%1 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8
|
||||
store %"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %1, align 8
|
||||
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %1, i32 0, i32 0
|
||||
%3 = load ptr, ptr %2, align 8
|
||||
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %3, i32 0, i32 1
|
||||
%5 = load ptr, ptr %4, align 8
|
||||
%6 = call i32 (ptr, ...) @printf(ptr @2, ptr %5)
|
||||
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %1, i32 0, i32 0
|
||||
%8 = load ptr, ptr %7, align 8
|
||||
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %8, i32 0, i32 1
|
||||
%10 = load ptr, ptr %9, align 8
|
||||
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %10, i32 0, i32 6
|
||||
%12 = load i8, ptr %11, align 1
|
||||
%13 = sext i8 %12 to i64
|
||||
%14 = icmp eq i64 %13, 24
|
||||
br i1 %14, label %_llgo_2, label %_llgo_1
|
||||
|
||||
_llgo_1: ; preds = %_llgo_2, %_llgo_0
|
||||
ret void
|
||||
|
||||
_llgo_2: ; preds = %_llgo_0
|
||||
%15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %1, i32 0, i32 1
|
||||
%16 = load ptr, ptr %15, align 8
|
||||
%17 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %16, i32 0, i32 1
|
||||
%18 = load i64, ptr %17, align 4
|
||||
%19 = add i64 %18, 1
|
||||
%20 = alloca i8, i64 %19, align 1
|
||||
%21 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %16, align 8
|
||||
%22 = call ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr %20, %"github.com/goplus/llgo/internal/runtime.String" %21)
|
||||
%23 = call i32 (ptr, ...) @printf(ptr @3, ptr %22)
|
||||
br label %_llgo_1
|
||||
}
|
||||
|
||||
define ptr @"github.com/goplus/llgo/internal/runtime.basicType"(i64 %0) {
|
||||
_llgo_0:
|
||||
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 16)
|
||||
@@ -386,6 +426,8 @@ declare ptr @malloc(i64)
|
||||
|
||||
declare ptr @memcpy(ptr, ptr, i64)
|
||||
|
||||
declare i32 @printf(ptr, ...)
|
||||
|
||||
declare i32 @rand()
|
||||
|
||||
declare void @"github.com/goplus/llgo/internal/abi.init"()
|
||||
|
||||
@@ -19,6 +19,7 @@ package runtime
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/internal/abi"
|
||||
"github.com/goplus/llgo/internal/runtime/c"
|
||||
)
|
||||
|
||||
@@ -27,18 +28,15 @@ func Alloc(size uintptr) unsafe.Pointer {
|
||||
return c.Malloc(size)
|
||||
}
|
||||
|
||||
/*
|
||||
// Panic panics with a value.
|
||||
func Panic(v Interface) {
|
||||
c.Printf(c.String("Panic!!!\n"))
|
||||
// TracePanic prints panic message.
|
||||
func TracePanic(v Interface) {
|
||||
c.Printf(c.Str("Panic(%p)\n"), v.tab._type)
|
||||
kind := abi.Kind(v.tab._type.Kind_)
|
||||
switch {
|
||||
case kind == abi.String:
|
||||
s := (*String)(v.data)
|
||||
cs := c.Alloca(uintptr(s.len) + 1)
|
||||
c.Memcpy(cs, s.data, uintptr(s.len))
|
||||
(*[1 << 30]int8)(cs)[s.len] = 0
|
||||
c.Printf(c.String("%s\n"), cs)
|
||||
c.Printf(c.Str("panic: %s\n"), CStrCopy(cs, *s))
|
||||
}
|
||||
// TODO(xsw): other message type
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/internal/abi"
|
||||
"github.com/goplus/llgo/internal/runtime/c"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -35,29 +36,35 @@ var (
|
||||
type Interface = iface
|
||||
|
||||
func MakeAnyInt(typ *Type, data uintptr) Interface {
|
||||
tab := &itab{inter: TyAny, _type: typ, hash: 0, fun: [1]uintptr{0}}
|
||||
return Interface{
|
||||
tab: &itab{inter: TyAny, _type: typ, hash: 0, fun: [1]uintptr{0}},
|
||||
tab: tab,
|
||||
data: unsafe.Pointer(data),
|
||||
}
|
||||
}
|
||||
|
||||
func MakeAnyString(data string) Interface {
|
||||
typ := Basic(abi.String)
|
||||
tab := &itab{inter: TyAny, _type: typ, hash: 0, fun: [1]uintptr{0}}
|
||||
c.Printf(c.Str("MakeAnyString(%p)\n"), typ)
|
||||
return Interface{
|
||||
tab: &itab{inter: TyAny, _type: Basic(abi.String), hash: 0, fun: [1]uintptr{0}},
|
||||
tab: tab,
|
||||
data: unsafe.Pointer(&data),
|
||||
}
|
||||
}
|
||||
|
||||
func MakeAny(typ *Type, data unsafe.Pointer) Interface {
|
||||
tab := &itab{inter: TyAny, _type: typ, hash: 0, fun: [1]uintptr{0}}
|
||||
return Interface{
|
||||
tab: &itab{inter: TyAny, _type: typ, hash: 0, fun: [1]uintptr{0}},
|
||||
tab: tab,
|
||||
data: data,
|
||||
}
|
||||
}
|
||||
|
||||
func MakeInterface(inter *InterfaceType, typ *Type, data unsafe.Pointer) Interface {
|
||||
tab := &itab{inter: inter, _type: typ, hash: 0, fun: [1]uintptr{0}}
|
||||
return Interface{
|
||||
tab: &itab{inter: inter, _type: typ, hash: 0, fun: [1]uintptr{0}},
|
||||
tab: tab,
|
||||
data: data,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user