@@ -1,20 +1,19 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goplus/llgo/c"
|
|
||||||
"github.com/goplus/llgo/cl/internal/foo"
|
"github.com/goplus/llgo/cl/internal/foo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
bar := foo.Bar()
|
bar := foo.Bar()
|
||||||
if x, ok := bar.(struct{ V int }); ok {
|
if x, ok := bar.(struct{ V int }); ok {
|
||||||
c.Printf(c.Str("%d\n"), x.V)
|
println(x.V)
|
||||||
} else {
|
} else {
|
||||||
c.Printf(c.Str("Bar: not ok\n"))
|
println("Bar: not ok")
|
||||||
}
|
}
|
||||||
if x, ok := foo.F().(struct{ v int }); ok {
|
if x, ok := foo.F().(struct{ v int }); ok {
|
||||||
c.Printf(c.Str("%d\n"), x.v)
|
println(x.v)
|
||||||
} else {
|
} else {
|
||||||
c.Printf(c.Str("F: not ok\n"))
|
println("F: not ok")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,17 +11,15 @@ source_filename = "main"
|
|||||||
@__llgo_argc = global ptr null
|
@__llgo_argc = global ptr null
|
||||||
@__llgo_argv = global ptr null
|
@__llgo_argv = global ptr null
|
||||||
@"_llgo_struct$K-dZ9QotZfVPz2a0YdRa9vmZUuDXPTqZOlMShKEDJtk" = linkonce global ptr null
|
@"_llgo_struct$K-dZ9QotZfVPz2a0YdRa9vmZUuDXPTqZOlMShKEDJtk" = linkonce global ptr null
|
||||||
@0 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
|
|
||||||
@"main.struct$MYpsoM99ZwFY087IpUOkIw1zjBA_sgFXVodmn1m-G88" = global ptr null
|
@"main.struct$MYpsoM99ZwFY087IpUOkIw1zjBA_sgFXVodmn1m-G88" = global ptr null
|
||||||
@1 = private unnamed_addr constant [13 x i8] c"Bar: not ok\0A\00", align 1
|
@0 = private unnamed_addr constant [12 x i8] c"Bar: not ok\00", align 1
|
||||||
@2 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
|
@1 = private unnamed_addr constant [10 x i8] c"F: not ok\00", align 1
|
||||||
@3 = private unnamed_addr constant [11 x i8] c"F: not ok\0A\00", align 1
|
@2 = private unnamed_addr constant [2 x i8] c"V\00", align 1
|
||||||
@4 = private unnamed_addr constant [2 x i8] c"V\00", align 1
|
@3 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1
|
||||||
@5 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1
|
@4 = private unnamed_addr constant [5 x i8] c"main\00", align 1
|
||||||
@6 = private unnamed_addr constant [5 x i8] c"main\00", align 1
|
@5 = private unnamed_addr constant [2 x i8] c"v\00", align 1
|
||||||
@7 = private unnamed_addr constant [2 x i8] c"v\00", align 1
|
@6 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1
|
||||||
@8 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1
|
@7 = private unnamed_addr constant [5 x i8] c"main\00", align 1
|
||||||
@9 = private unnamed_addr constant [5 x i8] c"main\00", align 1
|
|
||||||
|
|
||||||
define void @main.init() {
|
define void @main.init() {
|
||||||
_llgo_0:
|
_llgo_0:
|
||||||
@@ -77,55 +75,71 @@ _llgo_0:
|
|||||||
_llgo_1: ; preds = %_llgo_0
|
_llgo_1: ; preds = %_llgo_0
|
||||||
%24 = getelementptr inbounds { i64 }, ptr %4, i32 0, i32 0
|
%24 = getelementptr inbounds { i64 }, ptr %4, i32 0, i32 0
|
||||||
%25 = load i64, ptr %24, align 4
|
%25 = load i64, ptr %24, align 4
|
||||||
%26 = call i32 (ptr, ...) @printf(ptr @0, i64 %25)
|
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %25)
|
||||||
|
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||||
br label %_llgo_2
|
br label %_llgo_2
|
||||||
|
|
||||||
_llgo_2: ; preds = %_llgo_3, %_llgo_1
|
_llgo_2: ; preds = %_llgo_3, %_llgo_1
|
||||||
%27 = alloca { i64 }, align 8
|
%26 = alloca { i64 }, align 8
|
||||||
%28 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %27, i64 8)
|
%27 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %26, i64 8)
|
||||||
%29 = call %"github.com/goplus/llgo/internal/runtime.eface" @"github.com/goplus/llgo/cl/internal/foo.F"()
|
%28 = call %"github.com/goplus/llgo/internal/runtime.eface" @"github.com/goplus/llgo/cl/internal/foo.F"()
|
||||||
%30 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %29, 0
|
%29 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %28, 0
|
||||||
%31 = load ptr, ptr @"main.struct$MYpsoM99ZwFY087IpUOkIw1zjBA_sgFXVodmn1m-G88", align 8
|
%30 = load ptr, ptr @"main.struct$MYpsoM99ZwFY087IpUOkIw1zjBA_sgFXVodmn1m-G88", align 8
|
||||||
%32 = icmp eq ptr %30, %31
|
%31 = icmp eq ptr %29, %30
|
||||||
%33 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %29, 1
|
%32 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %28, 1
|
||||||
%34 = ptrtoint ptr %33 to i64
|
%33 = ptrtoint ptr %32 to i64
|
||||||
%35 = alloca { i64 }, align 8
|
%34 = alloca { i64 }, align 8
|
||||||
%36 = getelementptr inbounds { i64 }, ptr %35, i32 0, i32 0
|
%35 = getelementptr inbounds { i64 }, ptr %34, i32 0, i32 0
|
||||||
store i64 %34, ptr %36, align 4
|
store i64 %33, ptr %35, align 4
|
||||||
%37 = load { i64 }, ptr %35, align 4
|
%36 = load { i64 }, ptr %34, align 4
|
||||||
%38 = alloca { { i64 }, i1 }, align 8
|
%37 = alloca { { i64 }, i1 }, align 8
|
||||||
%39 = getelementptr inbounds { { i64 }, i1 }, ptr %38, i32 0, i32 0
|
%38 = getelementptr inbounds { { i64 }, i1 }, ptr %37, i32 0, i32 0
|
||||||
store { i64 } %37, ptr %39, align 4
|
store { i64 } %36, ptr %38, align 4
|
||||||
%40 = getelementptr inbounds { { i64 }, i1 }, ptr %38, i32 0, i32 1
|
%39 = getelementptr inbounds { { i64 }, i1 }, ptr %37, i32 0, i32 1
|
||||||
store i1 true, ptr %40, align 1
|
store i1 true, ptr %39, align 1
|
||||||
%41 = load { { i64 }, i1 }, ptr %38, align 4
|
%40 = load { { i64 }, i1 }, ptr %37, align 4
|
||||||
%42 = alloca { { i64 }, i1 }, align 8
|
%41 = alloca { { i64 }, i1 }, align 8
|
||||||
%43 = getelementptr inbounds { { i64 }, i1 }, ptr %42, i32 0, i32 0
|
%42 = getelementptr inbounds { { i64 }, i1 }, ptr %41, i32 0, i32 0
|
||||||
store { i64 } zeroinitializer, ptr %43, align 4
|
store { i64 } zeroinitializer, ptr %42, align 4
|
||||||
%44 = getelementptr inbounds { { i64 }, i1 }, ptr %42, i32 0, i32 1
|
%43 = getelementptr inbounds { { i64 }, i1 }, ptr %41, i32 0, i32 1
|
||||||
store i1 false, ptr %44, align 1
|
store i1 false, ptr %43, align 1
|
||||||
%45 = load { { i64 }, i1 }, ptr %42, align 4
|
%44 = load { { i64 }, i1 }, ptr %41, align 4
|
||||||
%46 = select i1 %32, { { i64 }, i1 } %41, { { i64 }, i1 } %45
|
%45 = select i1 %31, { { i64 }, i1 } %40, { { i64 }, i1 } %44
|
||||||
%47 = extractvalue { { i64 }, i1 } %46, 0
|
%46 = extractvalue { { i64 }, i1 } %45, 0
|
||||||
store { i64 } %47, ptr %28, align 4
|
store { i64 } %46, ptr %27, align 4
|
||||||
%48 = extractvalue { { i64 }, i1 } %46, 1
|
%47 = extractvalue { { i64 }, i1 } %45, 1
|
||||||
br i1 %48, label %_llgo_4, label %_llgo_6
|
br i1 %47, label %_llgo_4, label %_llgo_6
|
||||||
|
|
||||||
_llgo_3: ; preds = %_llgo_0
|
_llgo_3: ; preds = %_llgo_0
|
||||||
%49 = call i32 (ptr, ...) @printf(ptr @1)
|
%48 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||||
|
%49 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %48, i32 0, i32 0
|
||||||
|
store ptr @0, ptr %49, align 8
|
||||||
|
%50 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %48, i32 0, i32 1
|
||||||
|
store i64 11, ptr %50, align 4
|
||||||
|
%51 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %48, align 8
|
||||||
|
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %51)
|
||||||
|
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||||
br label %_llgo_2
|
br label %_llgo_2
|
||||||
|
|
||||||
_llgo_4: ; preds = %_llgo_2
|
_llgo_4: ; preds = %_llgo_2
|
||||||
%50 = getelementptr inbounds { i64 }, ptr %28, i32 0, i32 0
|
%52 = getelementptr inbounds { i64 }, ptr %27, i32 0, i32 0
|
||||||
%51 = load i64, ptr %50, align 4
|
%53 = load i64, ptr %52, align 4
|
||||||
%52 = call i32 (ptr, ...) @printf(ptr @2, i64 %51)
|
call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %53)
|
||||||
|
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||||
br label %_llgo_5
|
br label %_llgo_5
|
||||||
|
|
||||||
_llgo_5: ; preds = %_llgo_6, %_llgo_4
|
_llgo_5: ; preds = %_llgo_6, %_llgo_4
|
||||||
ret i32 0
|
ret i32 0
|
||||||
|
|
||||||
_llgo_6: ; preds = %_llgo_2
|
_llgo_6: ; preds = %_llgo_2
|
||||||
%53 = call i32 (ptr, ...) @printf(ptr @3)
|
%54 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||||
|
%55 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %54, i32 0, i32 0
|
||||||
|
store ptr @1, ptr %55, align 8
|
||||||
|
%56 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %54, i32 0, i32 1
|
||||||
|
store i64 9, ptr %56, align 4
|
||||||
|
%57 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %54, align 8
|
||||||
|
call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %57)
|
||||||
|
call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
|
||||||
br label %_llgo_5
|
br label %_llgo_5
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,10 +151,14 @@ declare %"github.com/goplus/llgo/internal/runtime.eface" @"github.com/goplus/llg
|
|||||||
|
|
||||||
declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64)
|
declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64)
|
||||||
|
|
||||||
declare i32 @printf(ptr, ...)
|
declare void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64)
|
||||||
|
|
||||||
|
declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8)
|
||||||
|
|
||||||
declare %"github.com/goplus/llgo/internal/runtime.eface" @"github.com/goplus/llgo/cl/internal/foo.F"()
|
declare %"github.com/goplus/llgo/internal/runtime.eface" @"github.com/goplus/llgo/cl/internal/foo.F"()
|
||||||
|
|
||||||
|
declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")
|
||||||
|
|
||||||
define void @"main.init$abi"() {
|
define void @"main.init$abi"() {
|
||||||
_llgo_0:
|
_llgo_0:
|
||||||
%0 = load ptr, ptr @"_llgo_struct$K-dZ9QotZfVPz2a0YdRa9vmZUuDXPTqZOlMShKEDJtk", align 8
|
%0 = load ptr, ptr @"_llgo_struct$K-dZ9QotZfVPz2a0YdRa9vmZUuDXPTqZOlMShKEDJtk", align 8
|
||||||
@@ -150,21 +168,21 @@ _llgo_0:
|
|||||||
_llgo_1: ; preds = %_llgo_0
|
_llgo_1: ; preds = %_llgo_0
|
||||||
%2 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
%2 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||||
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 0
|
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 0
|
||||||
store ptr @4, ptr %3, align 8
|
store ptr @2, ptr %3, align 8
|
||||||
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 1
|
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 1
|
||||||
store i64 1, ptr %4, align 4
|
store i64 1, ptr %4, align 4
|
||||||
%5 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %2, align 8
|
%5 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %2, align 8
|
||||||
%6 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
%6 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||||
%7 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
%7 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||||
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 0
|
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 0
|
||||||
store ptr @5, ptr %8, align 8
|
store ptr @3, ptr %8, align 8
|
||||||
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 1
|
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 1
|
||||||
store i64 0, ptr %9, align 4
|
store i64 0, ptr %9, align 4
|
||||||
%10 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %7, align 8
|
%10 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %7, align 8
|
||||||
%11 = call %"github.com/goplus/llgo/internal/abi.StructField" @"github.com/goplus/llgo/internal/runtime.StructField"(%"github.com/goplus/llgo/internal/runtime.String" %5, ptr %6, i64 0, %"github.com/goplus/llgo/internal/runtime.String" %10, i1 true, i1 false)
|
%11 = call %"github.com/goplus/llgo/internal/abi.StructField" @"github.com/goplus/llgo/internal/runtime.StructField"(%"github.com/goplus/llgo/internal/runtime.String" %5, ptr %6, i64 0, %"github.com/goplus/llgo/internal/runtime.String" %10, i1 true, i1 false)
|
||||||
%12 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
%12 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||||
%13 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %12, i32 0, i32 0
|
%13 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %12, i32 0, i32 0
|
||||||
store ptr @6, ptr %13, align 8
|
store ptr @4, ptr %13, align 8
|
||||||
%14 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %12, i32 0, i32 1
|
%14 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %12, i32 0, i32 1
|
||||||
store i64 4, ptr %14, align 4
|
store i64 4, ptr %14, align 4
|
||||||
%15 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %12, align 8
|
%15 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %12, align 8
|
||||||
@@ -186,21 +204,21 @@ _llgo_1: ; preds = %_llgo_0
|
|||||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||||
%24 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
%24 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||||
%25 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %24, i32 0, i32 0
|
%25 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %24, i32 0, i32 0
|
||||||
store ptr @7, ptr %25, align 8
|
store ptr @5, ptr %25, align 8
|
||||||
%26 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %24, i32 0, i32 1
|
%26 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %24, i32 0, i32 1
|
||||||
store i64 1, ptr %26, align 4
|
store i64 1, ptr %26, align 4
|
||||||
%27 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %24, align 8
|
%27 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %24, align 8
|
||||||
%28 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
%28 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||||
%29 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
%29 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||||
%30 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %29, i32 0, i32 0
|
%30 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %29, i32 0, i32 0
|
||||||
store ptr @8, ptr %30, align 8
|
store ptr @6, ptr %30, align 8
|
||||||
%31 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %29, i32 0, i32 1
|
%31 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %29, i32 0, i32 1
|
||||||
store i64 0, ptr %31, align 4
|
store i64 0, ptr %31, align 4
|
||||||
%32 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %29, align 8
|
%32 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %29, align 8
|
||||||
%33 = call %"github.com/goplus/llgo/internal/abi.StructField" @"github.com/goplus/llgo/internal/runtime.StructField"(%"github.com/goplus/llgo/internal/runtime.String" %27, ptr %28, i64 0, %"github.com/goplus/llgo/internal/runtime.String" %32, i1 false, i1 false)
|
%33 = call %"github.com/goplus/llgo/internal/abi.StructField" @"github.com/goplus/llgo/internal/runtime.StructField"(%"github.com/goplus/llgo/internal/runtime.String" %27, ptr %28, i64 0, %"github.com/goplus/llgo/internal/runtime.String" %32, i1 false, i1 false)
|
||||||
%34 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
%34 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||||
%35 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %34, i32 0, i32 0
|
%35 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %34, i32 0, i32 0
|
||||||
store ptr @9, ptr %35, align 8
|
store ptr @7, ptr %35, align 8
|
||||||
%36 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %34, i32 0, i32 1
|
%36 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %34, i32 0, i32 1
|
||||||
store i64 4, ptr %36, align 4
|
store i64 4, ptr %36, align 4
|
||||||
%37 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %34, align 8
|
%37 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %34, align 8
|
||||||
|
|||||||
@@ -4,10 +4,14 @@ import (
|
|||||||
"github.com/goplus/llgo/internal/runtime/c"
|
"github.com/goplus/llgo/internal/runtime/c"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func hi(a any) *c.Char {
|
||||||
|
return a.(*c.Char)
|
||||||
|
}
|
||||||
|
|
||||||
func incVal(a any) int {
|
func incVal(a any) int {
|
||||||
return a.(int) + 1
|
return a.(int) + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
c.Printf(c.Str("Hello %d\n"), incVal(100))
|
c.Printf(c.Str("%s %d\n"), hi(c.Str("Hello")), incVal(100))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,35 @@ source_filename = "main"
|
|||||||
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
|
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
|
||||||
|
|
||||||
@"main.init$guard" = global ptr null
|
@"main.init$guard" = global ptr null
|
||||||
|
@"*_llgo_int8" = linkonce global ptr null
|
||||||
@0 = private unnamed_addr constant [22 x i8] c"type assertion failed\00", align 1
|
@0 = private unnamed_addr constant [22 x i8] c"type assertion failed\00", align 1
|
||||||
|
@1 = private unnamed_addr constant [22 x i8] c"type assertion failed\00", align 1
|
||||||
@__llgo_argc = global ptr null
|
@__llgo_argc = global ptr null
|
||||||
@__llgo_argv = global ptr null
|
@__llgo_argv = global ptr null
|
||||||
@1 = private unnamed_addr constant [10 x i8] c"Hello %d\0A\00", align 1
|
@2 = private unnamed_addr constant [7 x i8] c"%s %d\0A\00", align 1
|
||||||
|
@3 = private unnamed_addr constant [6 x i8] c"Hello\00", align 1
|
||||||
|
|
||||||
|
define ptr @main.hi(%"github.com/goplus/llgo/internal/runtime.eface" %0) {
|
||||||
|
_llgo_0:
|
||||||
|
%1 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0
|
||||||
|
%2 = load ptr, ptr @"*_llgo_int8", align 8
|
||||||
|
%3 = icmp eq ptr %1, %2
|
||||||
|
br i1 %3, label %_llgo_1, label %_llgo_2
|
||||||
|
|
||||||
|
_llgo_1: ; preds = %_llgo_0
|
||||||
|
%4 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1
|
||||||
|
ret ptr %4
|
||||||
|
|
||||||
|
_llgo_2: ; preds = %_llgo_0
|
||||||
|
%5 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||||
|
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %5, i32 0, i32 0
|
||||||
|
store ptr @0, ptr %6, align 8
|
||||||
|
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %5, i32 0, i32 1
|
||||||
|
store i64 21, ptr %7, align 4
|
||||||
|
%8 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %5, align 8
|
||||||
|
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.String" %8)
|
||||||
|
unreachable
|
||||||
|
}
|
||||||
|
|
||||||
define i64 @main.incVal(%"github.com/goplus/llgo/internal/runtime.eface" %0) {
|
define i64 @main.incVal(%"github.com/goplus/llgo/internal/runtime.eface" %0) {
|
||||||
_llgo_0:
|
_llgo_0:
|
||||||
@@ -26,7 +51,7 @@ _llgo_1: ; preds = %_llgo_0
|
|||||||
_llgo_2: ; preds = %_llgo_0
|
_llgo_2: ; preds = %_llgo_0
|
||||||
%7 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
%7 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
|
||||||
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 0
|
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 0
|
||||||
store ptr @0, ptr %8, align 8
|
store ptr @1, ptr %8, align 8
|
||||||
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 1
|
%9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 1
|
||||||
store i64 21, ptr %9, align 4
|
store i64 21, ptr %9, align 4
|
||||||
%10 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %7, align 8
|
%10 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %7, align 8
|
||||||
@@ -41,6 +66,7 @@ _llgo_0:
|
|||||||
|
|
||||||
_llgo_1: ; preds = %_llgo_0
|
_llgo_1: ; preds = %_llgo_0
|
||||||
store i1 true, ptr @"main.init$guard", align 1
|
store i1 true, ptr @"main.init$guard", align 1
|
||||||
|
call void @"main.init$abi"()
|
||||||
br label %_llgo_2
|
br label %_llgo_2
|
||||||
|
|
||||||
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||||
@@ -53,22 +79,48 @@ _llgo_0:
|
|||||||
store ptr %1, ptr @__llgo_argv, align 8
|
store ptr %1, ptr @__llgo_argv, align 8
|
||||||
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
call void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||||
call void @main.init()
|
call void @main.init()
|
||||||
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
%2 = load ptr, ptr @"*_llgo_int8", align 8
|
||||||
%3 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8
|
%3 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8
|
||||||
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %3, i32 0, i32 0
|
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %3, i32 0, i32 0
|
||||||
store ptr %2, ptr %4, align 8
|
store ptr %2, ptr %4, align 8
|
||||||
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %3, i32 0, i32 1
|
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %3, i32 0, i32 1
|
||||||
store ptr inttoptr (i64 100 to ptr), ptr %5, align 8
|
store ptr @3, ptr %5, align 8
|
||||||
%6 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %3, align 8
|
%6 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %3, align 8
|
||||||
%7 = call i64 @main.incVal(%"github.com/goplus/llgo/internal/runtime.eface" %6)
|
%7 = call ptr @main.hi(%"github.com/goplus/llgo/internal/runtime.eface" %6)
|
||||||
%8 = call i32 (ptr, ...) @printf(ptr @1, i64 %7)
|
%8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2)
|
||||||
|
%9 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8
|
||||||
|
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %9, i32 0, i32 0
|
||||||
|
store ptr %8, ptr %10, align 8
|
||||||
|
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %9, i32 0, i32 1
|
||||||
|
store ptr inttoptr (i64 100 to ptr), ptr %11, align 8
|
||||||
|
%12 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %9, align 8
|
||||||
|
%13 = call i64 @main.incVal(%"github.com/goplus/llgo/internal/runtime.eface" %12)
|
||||||
|
%14 = call i32 (ptr, ...) @printf(ptr @2, ptr %7, i64 %13)
|
||||||
ret i32 0
|
ret i32 0
|
||||||
}
|
}
|
||||||
|
|
||||||
declare ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64)
|
|
||||||
|
|
||||||
declare void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface")
|
declare void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface")
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64)
|
||||||
|
|
||||||
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
declare void @"github.com/goplus/llgo/internal/runtime.init"()
|
||||||
|
|
||||||
declare i32 @printf(ptr, ...)
|
declare i32 @printf(ptr, ...)
|
||||||
|
|
||||||
|
define void @"main.init$abi"() {
|
||||||
|
_llgo_0:
|
||||||
|
%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.Pointer"(ptr %2)
|
||||||
|
store ptr %3, ptr @"*_llgo_int8", align 8
|
||||||
|
br label %_llgo_2
|
||||||
|
|
||||||
|
_llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
declare ptr @"github.com/goplus/llgo/internal/runtime.Pointer"(ptr)
|
||||||
|
|||||||
Binary file not shown.
@@ -111,4 +111,17 @@ func Struct(size uintptr, pkgPath string, fields ...abi.StructField) *Type {
|
|||||||
return &ret.Type
|
return &ret.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pointer returns a pointer type.
|
||||||
|
func Pointer(elem *Type) *Type {
|
||||||
|
ret := &abi.PtrType{
|
||||||
|
Type: Type{
|
||||||
|
Size_: unsafe.Sizeof(uintptr(0)),
|
||||||
|
Hash: uint32(abi.Pointer), // TODO(xsw): hash
|
||||||
|
Kind_: uint8(abi.Pointer),
|
||||||
|
},
|
||||||
|
Elem: elem,
|
||||||
|
}
|
||||||
|
return &ret.Type
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -40,43 +40,25 @@ func (b Builder) abiBasic(t *types.Basic) Expr {
|
|||||||
return b.InlineCall(b.Pkg.rtFunc("Basic"), b.Prog.Val(kind))
|
return b.InlineCall(b.Pkg.rtFunc("Basic"), b.Prog.Val(kind))
|
||||||
}
|
}
|
||||||
|
|
||||||
// abiStruct returns the abi type of the specified struct type.
|
func (b Builder) abiTypeOf(t types.Type) Expr {
|
||||||
func (b Builder) abiStruct(t *types.Struct) Expr {
|
switch t := t.(type) {
|
||||||
pkg := b.Pkg
|
case *types.Basic:
|
||||||
name, private := pkg.abi.StructName(t)
|
return b.abiBasic(t)
|
||||||
g := pkg.VarOf(name)
|
case *types.Pointer:
|
||||||
if g == nil {
|
return b.abiPointerOf(t)
|
||||||
prog := b.Prog
|
case *types.Struct:
|
||||||
g = pkg.doNewVar(name, prog.AbiTypePtrPtr())
|
return b.abiStructOf(t)
|
||||||
g.Init(prog.Null(g.Type))
|
|
||||||
pub := !private
|
|
||||||
if pub {
|
|
||||||
g.impl.SetLinkage(llvm.LinkOnceAnyLinkage)
|
|
||||||
}
|
|
||||||
pkg.abiini = append(pkg.abiini, func(param unsafe.Pointer) {
|
|
||||||
b := Builder(param)
|
|
||||||
expr := g.Expr
|
|
||||||
var blks []BasicBlock
|
|
||||||
if pub {
|
|
||||||
eq := b.BinOp(token.EQL, b.Load(expr), b.Prog.Null(expr.Type))
|
|
||||||
blks = b.Func.MakeBlocks(2)
|
|
||||||
b.If(eq, blks[0], blks[1])
|
|
||||||
b.SetBlockEx(blks[0], AtEnd, false)
|
|
||||||
}
|
|
||||||
tabi := b.structOf(t)
|
|
||||||
b.Store(expr, tabi)
|
|
||||||
if pub {
|
|
||||||
b.Jump(blks[1])
|
|
||||||
b.SetBlockEx(blks[1], AtEnd, false)
|
|
||||||
b.blk.last = blks[1].last
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
return b.Load(g.Expr)
|
panic("todo")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b Builder) abiPointerOf(t *types.Pointer) Expr {
|
||||||
|
elem := b.abiTypeOf(t.Elem())
|
||||||
|
return b.Call(b.Pkg.rtFunc("Pointer"), elem)
|
||||||
}
|
}
|
||||||
|
|
||||||
// func Struct(size uintptr, pkgPath string, fields []abi.StructField) *abi.Type
|
// func Struct(size uintptr, pkgPath string, fields []abi.StructField) *abi.Type
|
||||||
func (b Builder) structOf(t *types.Struct) Expr {
|
func (b Builder) abiStructOf(t *types.Struct) Expr {
|
||||||
pkg := b.Pkg
|
pkg := b.Pkg
|
||||||
prog := b.Prog
|
prog := b.Prog
|
||||||
n := t.NumFields()
|
n := t.NumFields()
|
||||||
@@ -106,14 +88,41 @@ func (b Builder) structField(sfAbi Expr, prog Program, f *types.Var, offset uint
|
|||||||
}
|
}
|
||||||
|
|
||||||
// abiType returns the abi type of the specified type.
|
// abiType returns the abi type of the specified type.
|
||||||
func (b Builder) abiType(raw types.Type) Expr {
|
func (b Builder) abiType(t types.Type) Expr {
|
||||||
switch tx := raw.(type) {
|
if tx, ok := t.(*types.Basic); ok {
|
||||||
case *types.Basic:
|
|
||||||
return b.abiBasic(tx)
|
return b.abiBasic(tx)
|
||||||
case *types.Struct:
|
|
||||||
return b.abiStruct(tx)
|
|
||||||
}
|
}
|
||||||
panic("todo")
|
pkg := b.Pkg
|
||||||
|
name, private := pkg.abi.TypeName(t)
|
||||||
|
g := pkg.VarOf(name)
|
||||||
|
if g == nil {
|
||||||
|
prog := b.Prog
|
||||||
|
g = pkg.doNewVar(name, prog.AbiTypePtrPtr())
|
||||||
|
g.Init(prog.Null(g.Type))
|
||||||
|
pub := !private
|
||||||
|
if pub {
|
||||||
|
g.impl.SetLinkage(llvm.LinkOnceAnyLinkage)
|
||||||
|
}
|
||||||
|
pkg.abiini = append(pkg.abiini, func(param unsafe.Pointer) {
|
||||||
|
b := Builder(param)
|
||||||
|
expr := g.Expr
|
||||||
|
var blks []BasicBlock
|
||||||
|
if pub {
|
||||||
|
eq := b.BinOp(token.EQL, b.Load(expr), b.Prog.Null(expr.Type))
|
||||||
|
blks = b.Func.MakeBlocks(2)
|
||||||
|
b.If(eq, blks[0], blks[1])
|
||||||
|
b.SetBlockEx(blks[0], AtEnd, false)
|
||||||
|
}
|
||||||
|
tabi := b.abiTypeOf(t)
|
||||||
|
b.Store(expr, tabi)
|
||||||
|
if pub {
|
||||||
|
b.Jump(blks[1])
|
||||||
|
b.SetBlockEx(blks[1], AtEnd, false)
|
||||||
|
b.blk.last = blks[1].last
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return b.Load(g.Expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// unsafeEface(t *abi.Type, data unsafe.Pointer) Eface
|
// unsafeEface(t *abi.Type, data unsafe.Pointer) Eface
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import (
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
type aBasicBlock struct {
|
type aBasicBlock struct {
|
||||||
first llvm.BasicBlock
|
first llvm.BasicBlock // a Go SSA basic block may have multiple LLVM basic blocks
|
||||||
last llvm.BasicBlock
|
last llvm.BasicBlock
|
||||||
fn Function
|
fn Function
|
||||||
idx int
|
idx int
|
||||||
|
|||||||
Reference in New Issue
Block a user