Merge pull request #103 from xushiwei/q

closure
This commit is contained in:
xushiwei
2024-05-04 07:57:00 +08:00
committed by GitHub
23 changed files with 777 additions and 506 deletions

View File

@@ -1,130 +0,0 @@
; ModuleID = 'main'
source_filename = "main"
%main.point = type { i64, i64 }
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
@"main.init$guard" = global ptr null
@0 = private unnamed_addr constant [7 x i8] c"%d %d\0A\00", align 1
@1 = private unnamed_addr constant [7 x i8] c"%d %d\0A\00", align 1
@2 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
@3 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
@4 = private unnamed_addr constant [4 x i8] c"%c\0A\00", align 1
@5 = private unnamed_addr constant [7 x i8] c"123456\00", align 1
@6 = private unnamed_addr constant [4 x i8] c"%c\0A\00", align 1
@7 = private unnamed_addr constant [7 x i8] c"123456\00", align 1
define void @main.init() {
_llgo_0:
%0 = load i1, ptr @"main.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"main.init$guard", align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main() {
_llgo_0:
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
%0 = alloca %main.point, align 8
%1 = alloca [3 x %main.point], align 8
%2 = getelementptr inbounds %main.point, ptr %1, i64 0
%3 = getelementptr inbounds %main.point, ptr %2, i32 0, i32 0
%4 = getelementptr inbounds %main.point, ptr %2, i32 0, i32 1
%5 = getelementptr inbounds %main.point, ptr %1, i64 1
%6 = getelementptr inbounds %main.point, ptr %5, i32 0, i32 0
%7 = getelementptr inbounds %main.point, ptr %5, i32 0, i32 1
%8 = getelementptr inbounds %main.point, ptr %1, i64 2
%9 = getelementptr inbounds %main.point, ptr %8, i32 0, i32 0
%10 = getelementptr inbounds %main.point, ptr %8, i32 0, i32 1
store i64 1, ptr %3, align 4
store i64 2, ptr %4, align 4
store i64 3, ptr %6, align 4
store i64 4, ptr %7, align 4
store i64 5, ptr %9, align 4
store i64 6, ptr %10, align 4
%11 = load [3 x %main.point], ptr %1, align 4
%12 = getelementptr inbounds %main.point, ptr %1, i64 2
%13 = load %main.point, ptr %12, align 4
store %main.point %13, ptr %0, align 4
%14 = getelementptr inbounds %main.point, ptr %0, i32 0, i32 0
%15 = load i64, ptr %14, align 4
%16 = getelementptr inbounds %main.point, ptr %0, i32 0, i32 1
%17 = load i64, ptr %16, align 4
%18 = call i32 (ptr, ...) @printf(ptr @0, i64 %15, i64 %17)
%19 = alloca [2 x i64], align 8
%20 = alloca [2 x [2 x i64]], align 8
%21 = getelementptr inbounds [2 x i64], ptr %20, i64 0
%22 = getelementptr inbounds i64, ptr %21, i64 0
%23 = getelementptr inbounds i64, ptr %21, i64 1
%24 = getelementptr inbounds [2 x i64], ptr %20, i64 1
%25 = getelementptr inbounds i64, ptr %24, i64 0
%26 = getelementptr inbounds i64, ptr %24, i64 1
store i64 1, ptr %22, align 4
store i64 2, ptr %23, align 4
store i64 3, ptr %25, align 4
store i64 4, ptr %26, align 4
%27 = load [2 x [2 x i64]], ptr %20, align 4
%28 = getelementptr inbounds [2 x i64], ptr %20, i64 1
%29 = load [2 x i64], ptr %28, align 4
store [2 x i64] %29, ptr %19, align 4
%30 = getelementptr inbounds i64, ptr %19, i64 0
%31 = load i64, ptr %30, align 4
%32 = getelementptr inbounds i64, ptr %19, i64 1
%33 = load i64, ptr %32, align 4
%34 = call i32 (ptr, ...) @printf(ptr @1, i64 %31, i64 %33)
%35 = alloca [5 x i64], align 8
%36 = getelementptr inbounds i64, ptr %35, i64 0
%37 = getelementptr inbounds i64, ptr %35, i64 1
%38 = getelementptr inbounds i64, ptr %35, i64 2
%39 = getelementptr inbounds i64, ptr %35, i64 3
%40 = getelementptr inbounds i64, ptr %35, i64 4
store i64 1, ptr %36, align 4
store i64 2, ptr %37, align 4
store i64 3, ptr %38, align 4
store i64 4, ptr %39, align 4
store i64 5, ptr %40, align 4
%41 = load [5 x i64], ptr %35, align 4
%42 = getelementptr inbounds i64, ptr %35, i64 2
%43 = load i64, ptr %42, align 4
%44 = call i32 (ptr, ...) @printf(ptr @2, i64 %43)
%45 = alloca [5 x i64], align 8
%46 = getelementptr inbounds i64, ptr %45, i64 0
%47 = getelementptr inbounds i64, ptr %45, i64 1
%48 = getelementptr inbounds i64, ptr %45, i64 2
%49 = getelementptr inbounds i64, ptr %45, i64 3
%50 = getelementptr inbounds i64, ptr %45, i64 4
store i64 1, ptr %46, align 4
store i64 2, ptr %47, align 4
store i64 3, ptr %48, align 4
store i64 4, ptr %49, align 4
store i64 5, ptr %50, align 4
%51 = load [5 x i64], ptr %45, align 4
%52 = getelementptr inbounds i64, ptr %45, i64 2
%53 = load i64, ptr %52, align 4
%54 = call i32 (ptr, ...) @printf(ptr @3, i64 %53)
%55 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @5, i64 6)
%56 = call ptr @"github.com/goplus/llgo/internal/runtime.StringData"(%"github.com/goplus/llgo/internal/runtime.String" %55)
%57 = getelementptr inbounds i8, ptr %56, i64 2
%58 = load i8, ptr %57, align 1
%59 = call i32 (ptr, ...) @printf(ptr @4, i8 %58)
%60 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @7, i64 6)
%61 = call ptr @"github.com/goplus/llgo/internal/runtime.StringData"(%"github.com/goplus/llgo/internal/runtime.String" %60)
%62 = getelementptr inbounds i8, ptr %61, i64 1
%63 = load i8, ptr %62, align 1
%64 = call i32 (ptr, ...) @printf(ptr @6, i8 %63)
ret void
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare i32 @printf(ptr, ...)
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr, i64)
declare ptr @"github.com/goplus/llgo/internal/runtime.StringData"(%"github.com/goplus/llgo/internal/runtime.String")

20
cl/_testrt/_intgen/in.go Normal file
View File

@@ -0,0 +1,20 @@
package main
import (
"github.com/goplus/llgo/internal/runtime/c"
)
func genInts(n int, gen func() c.Int) []c.Int {
a := make([]c.Int, n)
for i := range a {
a[i] = gen()
}
return a
}
func main() {
a := genInts(5, c.Rand)
for _, v := range a {
c.Printf(c.Str("%d\n"), v)
}
}

85
cl/_testrt/_intgen/out.ll Normal file
View File

@@ -0,0 +1,85 @@
; ModuleID = 'main'
source_filename = "main"
%"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 }
%"github.com/goplus/llgo/internal/runtime.Closure" = type { ptr, ptr }
@"main.init$guard" = global ptr null
@0 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
define %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 %0, %"github.com/goplus/llgo/internal/runtime.Closure" %1) {
_llgo_0:
%2 = mul i64 %0, 4
%3 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 %2)
%4 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice"(ptr %3, i64 %0, i64 %0)
%5 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %4)
br label %_llgo_1
_llgo_1: ; preds = %_llgo_2, %_llgo_0
%6 = phi i64 [ -1, %_llgo_0 ], [ %7, %_llgo_2 ]
%7 = add i64 %6, 1
%8 = icmp slt i64 %7, %5
br i1 %8, label %_llgo_2, label %_llgo_3
_llgo_2: ; preds = %_llgo_1
%9 = call addrspace(1) %"github.com/goplus/llgo/internal/runtime.Closure" %1()
%10 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %4)
%11 = getelementptr inbounds i32, ptr %10, i64 %7
store ptr %9, ptr %11, align 8
br label %_llgo_1
_llgo_3: ; preds = %_llgo_1
ret %"github.com/goplus/llgo/internal/runtime.Slice" %4
}
define void @main.init() {
_llgo_0:
%0 = load i1, ptr @"main.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"main.init$guard", align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main() {
_llgo_0:
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
%0 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, ptr @main.Rand)
%1 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %0)
br label %_llgo_1
_llgo_1: ; preds = %_llgo_2, %_llgo_0
%2 = phi i64 [ -1, %_llgo_0 ], [ %3, %_llgo_2 ]
%3 = add i64 %2, 1
%4 = icmp slt i64 %3, %1
br i1 %4, label %_llgo_2, label %_llgo_3
_llgo_2: ; preds = %_llgo_1
%5 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %0)
%6 = getelementptr inbounds i32, ptr %5, i64 %3
%7 = load i32, ptr %6, align 4
%8 = call i32 (ptr, ...) @printf(ptr @0, i32 %7)
br label %_llgo_1
_llgo_3: ; preds = %_llgo_1
ret void
}
declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice"(ptr, i64, i64)
declare i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice")
declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare i32 @main.Rand()
declare i32 @printf(ptr, ...)

View File

@@ -34,7 +34,7 @@ define void @main() {
_llgo_0: _llgo_0:
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()
%0 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 32) %0 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
%1 = getelementptr inbounds i64, ptr %0, i64 0 %1 = getelementptr inbounds i64, ptr %0, i64 0
store i64 1, ptr %1, align 4 store i64 1, ptr %1, align 4
%2 = getelementptr inbounds i64, ptr %0, i64 1 %2 = getelementptr inbounds i64, ptr %0, i64 1
@@ -44,7 +44,7 @@ _llgo_0:
%4 = getelementptr inbounds i64, ptr %0, i64 3 %4 = getelementptr inbounds i64, ptr %0, i64 3
store i64 4, ptr %4, align 4 store i64 4, ptr %4, align 4
%5 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %0, i64 8, i64 4, i64 0, i64 4, i64 4) %5 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %0, i64 8, i64 4, i64 0, i64 4, i64 4)
%6 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 32) %6 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
%7 = getelementptr inbounds i64, ptr %6, i64 0 %7 = getelementptr inbounds i64, ptr %6, i64 0
%8 = getelementptr inbounds i64, ptr %6, i64 1 %8 = getelementptr inbounds i64, ptr %6, i64 1
%9 = getelementptr inbounds i64, ptr %6, i64 2 %9 = getelementptr inbounds i64, ptr %6, i64 2
@@ -55,7 +55,7 @@ _llgo_0:
store i64 4, ptr %10, align 4 store i64 4, ptr %10, align 4
%11 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %5) %11 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %5)
call void @main.out(i64 %11) call void @main.out(i64 %11)
%12 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 32) %12 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
%13 = getelementptr inbounds i64, ptr %12, i64 0 %13 = getelementptr inbounds i64, ptr %12, i64 0
store i64 1, ptr %13, align 4 store i64 1, ptr %13, align 4
%14 = getelementptr inbounds i64, ptr %12, i64 1 %14 = getelementptr inbounds i64, ptr %12, i64 1
@@ -155,7 +155,7 @@ _llgo_0:
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64) declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64) declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64)

View File

@@ -64,7 +64,7 @@ define void @main() {
_llgo_0: _llgo_0:
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()
%0 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 48) %0 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 48)
%1 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %0, i64 0 %1 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %0, i64 0
%2 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @1, i64 5) %2 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @1, i64 5)
store %"github.com/goplus/llgo/internal/runtime.String" %2, ptr %1, align 8 store %"github.com/goplus/llgo/internal/runtime.String" %2, ptr %1, align 8
@@ -95,7 +95,7 @@ declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/ll
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64) declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64) declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64)

View File

@@ -18,7 +18,7 @@ _llgo_0:
define ptr @main.basicType(i64 %0) { define ptr @main.basicType(i64 %0) {
_llgo_0: _llgo_0:
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 48) %1 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 56)
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %1, i32 0, i32 0 %2 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %1, i32 0, i32 0
%3 = getelementptr inbounds i64, ptr @main.sizeBasicTypes, i64 %0 %3 = getelementptr inbounds i64, ptr @main.sizeBasicTypes, i64 %0
%4 = load i64, ptr %3, align 4 %4 = load i64, ptr %3, align 4
@@ -63,7 +63,7 @@ _llgo_0:
ret void ret void
} }
declare ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64) declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
declare void @"github.com/goplus/llgo/internal/abi.init"() declare void @"github.com/goplus/llgo/internal/abi.init"()

138
cl/_testrt/index/out.ll Normal file
View File

@@ -0,0 +1,138 @@
; ModuleID = 'main'
source_filename = "main"
%main.point = type { i64, i64 }
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
@"main.init$guard" = global ptr null
@0 = private unnamed_addr constant [7 x i8] c"%d %d\0A\00", align 1
@1 = private unnamed_addr constant [7 x i8] c"%d %d\0A\00", align 1
@2 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
@3 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
@4 = private unnamed_addr constant [4 x i8] c"%c\0A\00", align 1
@5 = private unnamed_addr constant [7 x i8] c"123456\00", align 1
@6 = private unnamed_addr constant [4 x i8] c"%c\0A\00", align 1
@7 = private unnamed_addr constant [7 x i8] c"123456\00", align 1
define void @main.init() {
_llgo_0:
%0 = load i1, ptr @"main.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"main.init$guard", align 1
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main() {
_llgo_0:
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
%0 = alloca %main.point, align 8
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %0, i64 16)
%2 = alloca [3 x %main.point], align 8
%3 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %2, i64 48)
%4 = getelementptr inbounds %main.point, ptr %3, i64 0
%5 = getelementptr inbounds %main.point, ptr %4, i32 0, i32 0
%6 = getelementptr inbounds %main.point, ptr %4, i32 0, i32 1
%7 = getelementptr inbounds %main.point, ptr %3, i64 1
%8 = getelementptr inbounds %main.point, ptr %7, i32 0, i32 0
%9 = getelementptr inbounds %main.point, ptr %7, i32 0, i32 1
%10 = getelementptr inbounds %main.point, ptr %3, i64 2
%11 = getelementptr inbounds %main.point, ptr %10, i32 0, i32 0
%12 = getelementptr inbounds %main.point, ptr %10, i32 0, i32 1
store i64 1, ptr %5, align 4
store i64 2, ptr %6, align 4
store i64 3, ptr %8, align 4
store i64 4, ptr %9, align 4
store i64 5, ptr %11, align 4
store i64 6, ptr %12, align 4
%13 = load [3 x %main.point], ptr %3, align 4
%14 = getelementptr inbounds %main.point, ptr %3, i64 2
%15 = load %main.point, ptr %14, align 4
store %main.point %15, ptr %1, align 4
%16 = getelementptr inbounds %main.point, ptr %1, i32 0, i32 0
%17 = load i64, ptr %16, align 4
%18 = getelementptr inbounds %main.point, ptr %1, i32 0, i32 1
%19 = load i64, ptr %18, align 4
%20 = call i32 (ptr, ...) @printf(ptr @0, i64 %17, i64 %19)
%21 = alloca [2 x i64], align 8
%22 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %21, i64 16)
%23 = alloca [2 x [2 x i64]], align 8
%24 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %23, i64 32)
%25 = getelementptr inbounds [2 x i64], ptr %24, i64 0
%26 = getelementptr inbounds i64, ptr %25, i64 0
%27 = getelementptr inbounds i64, ptr %25, i64 1
%28 = getelementptr inbounds [2 x i64], ptr %24, i64 1
%29 = getelementptr inbounds i64, ptr %28, i64 0
%30 = getelementptr inbounds i64, ptr %28, i64 1
store i64 1, ptr %26, align 4
store i64 2, ptr %27, align 4
store i64 3, ptr %29, align 4
store i64 4, ptr %30, align 4
%31 = load [2 x [2 x i64]], ptr %24, align 4
%32 = getelementptr inbounds [2 x i64], ptr %24, i64 1
%33 = load [2 x i64], ptr %32, align 4
store [2 x i64] %33, ptr %22, align 4
%34 = getelementptr inbounds i64, ptr %22, i64 0
%35 = load i64, ptr %34, align 4
%36 = getelementptr inbounds i64, ptr %22, i64 1
%37 = load i64, ptr %36, align 4
%38 = call i32 (ptr, ...) @printf(ptr @1, i64 %35, i64 %37)
%39 = alloca [5 x i64], align 8
%40 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %39, i64 40)
%41 = getelementptr inbounds i64, ptr %40, i64 0
%42 = getelementptr inbounds i64, ptr %40, i64 1
%43 = getelementptr inbounds i64, ptr %40, i64 2
%44 = getelementptr inbounds i64, ptr %40, i64 3
%45 = getelementptr inbounds i64, ptr %40, i64 4
store i64 1, ptr %41, align 4
store i64 2, ptr %42, align 4
store i64 3, ptr %43, align 4
store i64 4, ptr %44, align 4
store i64 5, ptr %45, align 4
%46 = load [5 x i64], ptr %40, align 4
%47 = getelementptr inbounds i64, ptr %40, i64 2
%48 = load i64, ptr %47, align 4
%49 = call i32 (ptr, ...) @printf(ptr @2, i64 %48)
%50 = alloca [5 x i64], align 8
%51 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %50, i64 40)
%52 = getelementptr inbounds i64, ptr %51, i64 0
%53 = getelementptr inbounds i64, ptr %51, i64 1
%54 = getelementptr inbounds i64, ptr %51, i64 2
%55 = getelementptr inbounds i64, ptr %51, i64 3
%56 = getelementptr inbounds i64, ptr %51, i64 4
store i64 1, ptr %52, align 4
store i64 2, ptr %53, align 4
store i64 3, ptr %54, align 4
store i64 4, ptr %55, align 4
store i64 5, ptr %56, align 4
%57 = load [5 x i64], ptr %51, align 4
%58 = getelementptr inbounds i64, ptr %51, i64 2
%59 = load i64, ptr %58, align 4
%60 = call i32 (ptr, ...) @printf(ptr @3, i64 %59)
%61 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @5, i64 6)
%62 = call ptr @"github.com/goplus/llgo/internal/runtime.StringData"(%"github.com/goplus/llgo/internal/runtime.String" %61)
%63 = getelementptr inbounds i8, ptr %62, i64 2
%64 = load i8, ptr %63, align 1
%65 = call i32 (ptr, ...) @printf(ptr @4, i8 %64)
%66 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @7, i64 6)
%67 = call ptr @"github.com/goplus/llgo/internal/runtime.StringData"(%"github.com/goplus/llgo/internal/runtime.String" %66)
%68 = getelementptr inbounds i8, ptr %67, i64 1
%69 = load i8, ptr %68, align 1
%70 = call i32 (ptr, ...) @printf(ptr @6, i8 %69)
ret void
}
declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64)
declare i32 @printf(ptr, ...)
declare %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr, i64)
declare ptr @"github.com/goplus/llgo/internal/runtime.StringData"(%"github.com/goplus/llgo/internal/runtime.String")

View File

@@ -21,7 +21,7 @@ define void @main() {
_llgo_0: _llgo_0:
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()
%0 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 40) %0 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 40)
%1 = getelementptr inbounds i64, ptr %0, i64 0 %1 = getelementptr inbounds i64, ptr %0, i64 0
%2 = getelementptr inbounds i64, ptr %0, i64 1 %2 = getelementptr inbounds i64, ptr %0, i64 1
%3 = getelementptr inbounds i64, ptr %0, i64 2 %3 = getelementptr inbounds i64, ptr %0, i64 2
@@ -57,7 +57,7 @@ declare void @qsort(ptr, i64, i64, ptr)
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64) declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
define i32 @"main.main$1"(ptr %0, ptr %1) { define i32 @"main.main$1"(ptr %0, ptr %1) {
_llgo_0: _llgo_0:

View File

@@ -9,15 +9,16 @@ source_filename = "main"
define void @"(main.Foo).Print"(%main.Foo %0) { define void @"(main.Foo).Print"(%main.Foo %0) {
_llgo_0: _llgo_0:
%1 = alloca %main.Foo, align 8 %1 = alloca %main.Foo, align 8
store %main.Foo %0, ptr %1, align 4 %2 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %1, i64 8)
%2 = getelementptr inbounds %main.Foo, ptr %1, i32 0, i32 1 store %main.Foo %0, ptr %2, align 4
%3 = load i1, ptr %2, align 1 %3 = getelementptr inbounds %main.Foo, ptr %2, i32 0, i32 1
br i1 %3, label %_llgo_1, label %_llgo_2 %4 = load i1, ptr %3, align 1
br i1 %4, label %_llgo_1, label %_llgo_2
_llgo_1: ; preds = %_llgo_0 _llgo_1: ; preds = %_llgo_0
%4 = getelementptr inbounds %main.Foo, ptr %1, i32 0, i32 0 %5 = getelementptr inbounds %main.Foo, ptr %2, i32 0, i32 0
%5 = load i32, ptr %4, align 4 %6 = load i32, ptr %5, align 4
call void (ptr, ...) @printf(ptr @main.format, i32 %5) call void (ptr, ...) @printf(ptr @main.format, i32 %6)
br label %_llgo_2 br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0 _llgo_2: ; preds = %_llgo_1, %_llgo_0
@@ -59,15 +60,18 @@ _llgo_0:
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()
%0 = alloca %main.Foo, align 8 %0 = alloca %main.Foo, align 8
%1 = getelementptr inbounds %main.Foo, ptr %0, i32 0, i32 0 %1 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %0, i64 8)
%2 = getelementptr inbounds %main.Foo, ptr %0, i32 0, i32 1 %2 = getelementptr inbounds %main.Foo, ptr %1, i32 0, i32 0
store i32 100, ptr %1, align 4 %3 = getelementptr inbounds %main.Foo, ptr %1, i32 0, i32 1
store i1 true, ptr %2, align 1 store i32 100, ptr %2, align 4
%3 = load %main.Foo, ptr %0, align 4 store i1 true, ptr %3, align 1
call void @"(main.Foo).Print"(%main.Foo %3) %4 = load %main.Foo, ptr %1, align 4
call void @"(main.Foo).Print"(%main.Foo %4)
ret void ret void
} }
declare void @printf(ptr, ...) declare void @printf(ptr, ...)
declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64)
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()

View File

@@ -23,7 +23,7 @@ define void @main() {
_llgo_0: _llgo_0:
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()
%0 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 32) %0 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
%1 = getelementptr inbounds i64, ptr %0, i64 0 %1 = getelementptr inbounds i64, ptr %0, i64 0
store i64 1, ptr %1, align 4 store i64 1, ptr %1, align 4
%2 = getelementptr inbounds i64, ptr %0, i64 1 %2 = getelementptr inbounds i64, ptr %0, i64 1
@@ -63,7 +63,7 @@ _llgo_3: ; preds = %_llgo_1
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64) declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)
declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64) declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64)

View File

@@ -47,7 +47,7 @@ define void @main() {
_llgo_0: _llgo_0:
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()
%0 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 5) %0 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 8)
%1 = getelementptr inbounds { i32, i1 }, ptr %0, i32 0, i32 0 %1 = getelementptr inbounds { i32, i1 }, ptr %0, i32 0, i32 0
%2 = getelementptr inbounds { i32, i1 }, ptr %0, i32 0, i32 1 %2 = getelementptr inbounds { i32, i1 }, ptr %0, i32 0, i32 1
store i32 100, ptr %1, align 4 store i32 100, ptr %1, align 4
@@ -60,4 +60,4 @@ declare void @printf(ptr, ...)
declare void @"github.com/goplus/llgo/internal/runtime.init"() declare void @"github.com/goplus/llgo/internal/runtime.init"()
declare ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64) declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64)

View File

@@ -437,12 +437,9 @@ func (p *context) compileInstrOrValue(b llssa.Builder, iv instrOrValue, asValue
panic("todo") panic("todo")
} }
default: default:
panic("todo") fn := p.compileValue(b, cv)
/* args := p.compileValues(b, call.Args, kind)
fn := p.compileValue(b, cv) ret = b.Call(fn, args...)
args := p.compileValues(b, call.Args, kind)
ret = b.Call(fn, args...)
*/
} }
case *ssa.BinOp: case *ssa.BinOp:
x := p.compileValue(b, v.X) x := p.compileValue(b, v.X)
@@ -504,13 +501,6 @@ func (p *context) compileInstrOrValue(b llssa.Builder, iv instrOrValue, asValue
max = p.compileValue(b, v.Max) max = p.compileValue(b, v.Max)
} }
ret = b.Slice(x, low, high, max) ret = b.Slice(x, low, high, max)
case *ssa.MakeMap:
var nReserve llssa.Expr
t := v.Type()
if v.Reserve != nil {
nReserve = p.compileValue(b, v.Reserve)
}
ret = b.MakeMap(p.prog.Type(t), nReserve)
case *ssa.MakeInterface: case *ssa.MakeInterface:
const ( const (
delayExpr = true // varargs: don't need to convert an expr to any delayExpr = true // varargs: don't need to convert an expr to any
@@ -518,6 +508,21 @@ func (p *context) compileInstrOrValue(b llssa.Builder, iv instrOrValue, asValue
t := v.Type() t := v.Type()
x := p.compileValue(b, v.X) x := p.compileValue(b, v.X)
ret = b.MakeInterface(t, x, delayExpr) ret = b.MakeInterface(t, x, delayExpr)
case *ssa.MakeSlice:
var nCap llssa.Expr
t := v.Type()
nLen := p.compileValue(b, v.Len)
if v.Cap != nil {
nCap = p.compileValue(b, v.Cap)
}
ret = b.MakeSlice(p.prog.Type(t), nLen, nCap)
case *ssa.MakeMap:
var nReserve llssa.Expr
t := v.Type()
if v.Reserve != nil {
nReserve = p.compileValue(b, v.Reserve)
}
ret = b.MakeMap(p.prog.Type(t), nReserve)
case *ssa.TypeAssert: case *ssa.TypeAssert:
x := p.compileValue(b, v.X) x := p.compileValue(b, v.X)
ret = b.TypeAssert(x, p.prog.Type(v.AssertedType), v.CommaOk) ret = b.TypeAssert(x, p.prog.Type(v.AssertedType), v.CommaOk)

2
go.sum
View File

@@ -2,8 +2,6 @@ github.com/aykevl/go-wasm v0.0.1 h1:lPxy8l48P39W7I0tLrtCrLfZBOUq9IWZ7odGdyJP2AM=
github.com/aykevl/go-wasm v0.0.1/go.mod h1:b4nggwg3lEkNKOU4wzhtLKz2q2sLxSHFnc98aGt6z/Y= github.com/aykevl/go-wasm v0.0.1/go.mod h1:b4nggwg3lEkNKOU4wzhtLKz2q2sLxSHFnc98aGt6z/Y=
github.com/goplus/gogen v1.15.2 h1:Q6XaSx/Zi5tWnjfAziYsQI6Jv6MgODRpFtOYqNkiiqM= github.com/goplus/gogen v1.15.2 h1:Q6XaSx/Zi5tWnjfAziYsQI6Jv6MgODRpFtOYqNkiiqM=
github.com/goplus/gogen v1.15.2/go.mod h1:92qEzVgv7y8JEFICWG9GvYI5IzfEkxYdsA1DbmnTkqk= github.com/goplus/gogen v1.15.2/go.mod h1:92qEzVgv7y8JEFICWG9GvYI5IzfEkxYdsA1DbmnTkqk=
github.com/goplus/llvm v0.7.3 h1:I7UkAO4kzn0Es2iHKRpGU1LjYQ452XwYfsSs1OAAXk8=
github.com/goplus/llvm v0.7.3/go.mod h1:PeVK8GgzxwAYCiMiUAJb5wJR6xbhj989tu9oulKLLT4=
github.com/goplus/llvm v0.7.4-0.20240502033044-f17514e2af8a h1:FLRrz/S4mCuVTB+M1lSOiCU7bTbcbl5A5XhI3ntKfmI= github.com/goplus/llvm v0.7.4-0.20240502033044-f17514e2af8a h1:FLRrz/S4mCuVTB+M1lSOiCU7bTbcbl5A5XhI3ntKfmI=
github.com/goplus/llvm v0.7.4-0.20240502033044-f17514e2af8a/go.mod h1:PeVK8GgzxwAYCiMiUAJb5wJR6xbhj989tu9oulKLLT4= github.com/goplus/llvm v0.7.4-0.20240502033044-f17514e2af8a/go.mod h1:PeVK8GgzxwAYCiMiUAJb5wJR6xbhj989tu9oulKLLT4=
github.com/goplus/mod v0.13.10 h1:5Om6KOvo31daN7N30kWU1vC5zhsJPM+uPbcEN/FnlzE= github.com/goplus/mod v0.13.10 h1:5Om6KOvo31daN7N30kWU1vC5zhsJPM+uPbcEN/FnlzE=

View File

@@ -19,12 +19,19 @@ source_filename = "github.com/goplus/llgo/internal/runtime"
@__stderrp = external global ptr @__stderrp = external global ptr
@3 = private unnamed_addr constant [11 x i8] c"panic: %s\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) { define ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 %0) {
_llgo_0: _llgo_0:
%1 = call ptr @malloc(i64 %0) %1 = call ptr @malloc(i64 %0)
ret ptr %1 ret ptr %1
} }
define ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 %0) {
_llgo_0:
%1 = call ptr @malloc(i64 %0)
%2 = call ptr @memset(ptr %1, i32 0, i64 %0)
ret ptr %2
}
define ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 %0) { define ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 %0) {
_llgo_0: _llgo_0:
%1 = getelementptr inbounds ptr, ptr @"github.com/goplus/llgo/internal/runtime.basicTypes", i64 %0 %1 = getelementptr inbounds ptr, ptr @"github.com/goplus/llgo/internal/runtime.basicTypes", i64 %0
@@ -35,46 +42,49 @@ _llgo_0:
define ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr %0, %"github.com/goplus/llgo/internal/runtime.String" %1) { define ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr %0, %"github.com/goplus/llgo/internal/runtime.String" %1) {
_llgo_0: _llgo_0:
%2 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %2 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
store %"github.com/goplus/llgo/internal/runtime.String" %1, ptr %2, align 8 %3 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %2, i64 16)
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 1 store %"github.com/goplus/llgo/internal/runtime.String" %1, ptr %3, align 8
%4 = load i64, ptr %3, align 4 %4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 1
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 0 %5 = load i64, ptr %4, align 4
%6 = load ptr, ptr %5, align 8 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 0
%7 = call ptr @memcpy(ptr %0, ptr %6, i64 %4) %7 = load ptr, ptr %6, align 8
%8 = getelementptr inbounds i8, ptr %0, i64 %4 %8 = call ptr @memcpy(ptr %0, ptr %7, i64 %5)
store i8 0, ptr %8, align 1 %9 = getelementptr inbounds i8, ptr %0, i64 %5
store i8 0, ptr %9, align 1
ret ptr %0 ret ptr %0
} }
define ptr @"github.com/goplus/llgo/internal/runtime.CStrDup"(%"github.com/goplus/llgo/internal/runtime.String" %0) { define ptr @"github.com/goplus/llgo/internal/runtime.CStrDup"(%"github.com/goplus/llgo/internal/runtime.String" %0) {
_llgo_0: _llgo_0:
%1 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %1 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
store %"github.com/goplus/llgo/internal/runtime.String" %0, ptr %1, align 8 %2 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %1, i64 16)
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %1, i32 0, i32 1 store %"github.com/goplus/llgo/internal/runtime.String" %0, ptr %2, align 8
%3 = load i64, ptr %2, align 4 %3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 1
%4 = add i64 %3, 1 %4 = load i64, ptr %3, align 4
%5 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 %4) %5 = add i64 %4, 1
%6 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %1, align 8 %6 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 %5)
%7 = call ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr %5, %"github.com/goplus/llgo/internal/runtime.String" %6) %7 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %2, align 8
ret ptr %7 %8 = call ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr %6, %"github.com/goplus/llgo/internal/runtime.String" %7)
ret ptr %8
} }
define { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %1) { define { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %1) {
_llgo_0: _llgo_0:
%2 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8 %2 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8
store %"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %2, align 8 %3 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %2, i64 16)
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, i32 0, i32 0 store %"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %3, align 8
%4 = load ptr, ptr %3, align 8 %4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %3, i32 0, i32 0
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %4, i32 0, i32 1 %5 = load ptr, ptr %4, align 8
%6 = load ptr, ptr %5, align 8 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %5, i32 0, i32 1
%7 = icmp eq ptr %6, %1 %7 = load ptr, ptr %6, align 8
br i1 %7, label %_llgo_1, label %_llgo_2 %8 = icmp eq ptr %7, %1
br i1 %8, label %_llgo_1, label %_llgo_2
_llgo_1: ; preds = %_llgo_0 _llgo_1: ; preds = %_llgo_0
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, i32 0, i32 1 %9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %3, i32 0, i32 1
%9 = load ptr, ptr %8, align 8 %10 = load ptr, ptr %9, align 8
%10 = ptrtoint ptr %9 to i64 %11 = ptrtoint ptr %10 to i64
%mrv = insertvalue { i64, i1 } poison, i64 %10, 0 %mrv = insertvalue { i64, i1 } poison, i64 %11, 0
%mrv1 = insertvalue { i64, i1 } %mrv, i1 true, 1 %mrv1 = insertvalue { i64, i1 } %mrv, i1 true, 1
ret { i64, i1 } %mrv1 ret { i64, i1 } %mrv1
@@ -82,44 +92,66 @@ _llgo_2: ; preds = %_llgo_0
ret { i64, i1 } zeroinitializer ret { i64, i1 } zeroinitializer
} }
define ptr @"github.com/goplus/llgo/internal/runtime.ClosureData"(%"github.com/goplus/llgo/internal/runtime.Closure" %0) {
_llgo_0:
%1 = alloca %"github.com/goplus/llgo/internal/runtime.Closure", align 8
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %1, i64 16)
store %"github.com/goplus/llgo/internal/runtime.Closure" %0, ptr %2, align 8
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Closure", ptr %2, i32 0, i32 1
%4 = load ptr, ptr %3, align 8
ret ptr %4
}
define ptr @"github.com/goplus/llgo/internal/runtime.ClosureF"(%"github.com/goplus/llgo/internal/runtime.Closure" %0) {
_llgo_0:
%1 = alloca %"github.com/goplus/llgo/internal/runtime.Closure", align 8
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %1, i64 16)
store %"github.com/goplus/llgo/internal/runtime.Closure" %0, ptr %2, align 8
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Closure", ptr %2, i32 0, i32 0
%4 = load ptr, ptr %3, align 8
ret ptr %4
}
define %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.EmptyString"() { define %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.EmptyString"() {
_llgo_0: _llgo_0:
%0 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %0 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%1 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %0, i32 0, i32 0 %1 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %0, i64 16)
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %0, i32 0, i32 1 %2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %1, i32 0, i32 0
store ptr null, ptr %1, align 8 %3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %1, i32 0, i32 1
store i64 0, ptr %2, align 4 store ptr null, ptr %2, align 8
%3 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %0, align 8 store i64 0, ptr %3, align 4
ret %"github.com/goplus/llgo/internal/runtime.String" %3 %4 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %1, align 8
ret %"github.com/goplus/llgo/internal/runtime.String" %4
} }
define i64 @"github.com/goplus/llgo/internal/runtime.I2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %1) { define i64 @"github.com/goplus/llgo/internal/runtime.I2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %1) {
_llgo_0: _llgo_0:
%2 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8 %2 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8
store %"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %2, align 8 %3 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %2, i64 16)
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, i32 0, i32 0 store %"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %3, align 8
%4 = load ptr, ptr %3, align 8 %4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %3, i32 0, i32 0
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %4, i32 0, i32 1 %5 = load ptr, ptr %4, align 8
%6 = load ptr, ptr %5, align 8 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %5, i32 0, i32 1
%7 = icmp eq ptr %6, %1 %7 = load ptr, ptr %6, align 8
br i1 %7, label %_llgo_1, label %_llgo_2 %8 = icmp eq ptr %7, %1
br i1 %8, label %_llgo_1, label %_llgo_2
_llgo_1: ; preds = %_llgo_0 _llgo_1: ; preds = %_llgo_0
%8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, i32 0, i32 1 %9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %3, i32 0, i32 1
%9 = load ptr, ptr %8, align 8 %10 = load ptr, ptr %9, align 8
%10 = ptrtoint ptr %9 to i64 %11 = ptrtoint ptr %10 to i64
ret i64 %10 ret i64 %11
_llgo_2: ; 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.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) %13 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %12)
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %12) call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %13)
unreachable unreachable
} }
define %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAny"(ptr %0, ptr %1) { define %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAny"(ptr %0, ptr %1) {
_llgo_0: _llgo_0:
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 32) %2 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %2, i32 0, i32 0 %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 %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 %5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %2, i32 0, i32 1
@@ -131,17 +163,18 @@ _llgo_0:
store i32 0, ptr %6, align 4 store i32 0, ptr %6, align 4
store i64 0, ptr %8, align 4 store i64 0, ptr %8, align 4
%9 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8 %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 %10 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %9, i64 16)
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %9, i32 0, i32 1 %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %10, i32 0, i32 0
store ptr %2, ptr %10, align 8 %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %10, i32 0, i32 1
store ptr %1, ptr %11, align 8 store ptr %2, ptr %11, align 8
%12 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %9, align 8 store ptr %1, ptr %12, align 8
ret %"github.com/goplus/llgo/internal/runtime.iface" %12 %13 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %10, align 8
ret %"github.com/goplus/llgo/internal/runtime.iface" %13
} }
define %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %0, i64 %1) { define %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyInt"(ptr %0, i64 %1) {
_llgo_0: _llgo_0:
%2 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 32) %2 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %2, i32 0, i32 0 %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 %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 %5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %2, i32 0, i32 1
@@ -153,21 +186,22 @@ _llgo_0:
store i32 0, ptr %6, align 4 store i32 0, ptr %6, align 4
store i64 0, ptr %8, align 4 store i64 0, ptr %8, align 4
%9 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8 %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 %10 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %9, i64 16)
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %9, i32 0, i32 1 %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %10, i32 0, i32 0
%12 = inttoptr i64 %1 to ptr %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %10, i32 0, i32 1
store ptr %2, ptr %10, align 8 %13 = inttoptr i64 %1 to ptr
store ptr %12, ptr %11, align 8 store ptr %2, ptr %11, align 8
%13 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %9, align 8 store ptr %13, ptr %12, align 8
ret %"github.com/goplus/llgo/internal/runtime.iface" %13 %14 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %10, 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.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %0) { define %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %0) {
_llgo_0: _llgo_0:
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 16) %1 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 16)
store %"github.com/goplus/llgo/internal/runtime.String" %0, ptr %1, align 8 store %"github.com/goplus/llgo/internal/runtime.String" %0, ptr %1, align 8
%2 = load ptr, ptr getelementptr inbounds (ptr, ptr @"github.com/goplus/llgo/internal/runtime.basicTypes", i64 24), align 8 %2 = load ptr, ptr getelementptr inbounds (ptr, ptr @"github.com/goplus/llgo/internal/runtime.basicTypes", i64 24), align 8
%3 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 32) %3 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %3, i32 0, i32 0 %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 %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 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %3, i32 0, i32 1
@@ -179,17 +213,18 @@ _llgo_0:
store i32 0, ptr %7, align 4 store i32 0, ptr %7, align 4
store i64 0, ptr %9, align 4 store i64 0, ptr %9, align 4
%10 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8 %10 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %10, i32 0, i32 0 %11 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %10, i64 16)
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %10, i32 0, i32 1 %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %11, i32 0, i32 0
store ptr %3, ptr %11, align 8 %13 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %11, i32 0, i32 1
store ptr %1, ptr %12, align 8 store ptr %3, ptr %12, align 8
%13 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %10, align 8 store ptr %1, ptr %13, align 8
ret %"github.com/goplus/llgo/internal/runtime.iface" %13 %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) { define %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeInterface"(ptr %0, ptr %1, ptr %2) {
_llgo_0: _llgo_0:
%3 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 32) %3 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32)
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %3, i32 0, i32 0 %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 %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 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %3, i32 0, i32 2
@@ -200,12 +235,13 @@ _llgo_0:
store i32 0, ptr %6, align 4 store i32 0, ptr %6, align 4
store i64 0, ptr %8, align 4 store i64 0, ptr %8, align 4
%9 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8 %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 %10 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %9, i64 16)
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %9, i32 0, i32 1 %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %10, i32 0, i32 0
store ptr %3, ptr %10, align 8 %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %10, i32 0, i32 1
store ptr %2, ptr %11, align 8 store ptr %3, ptr %11, align 8
%12 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %9, align 8 store ptr %2, ptr %12, align 8
ret %"github.com/goplus/llgo/internal/runtime.iface" %12 %13 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %10, align 8
ret %"github.com/goplus/llgo/internal/runtime.iface" %13
} }
define ptr @"github.com/goplus/llgo/internal/runtime.MakeSmallMap"() { define ptr @"github.com/goplus/llgo/internal/runtime.MakeSmallMap"() {
@@ -217,263 +253,286 @@ _llgo_0:
define %"github.com/goplus/llgo/internal/runtime.Closure" @"github.com/goplus/llgo/internal/runtime.NewClosure"(ptr %0, ptr %1) { define %"github.com/goplus/llgo/internal/runtime.Closure" @"github.com/goplus/llgo/internal/runtime.NewClosure"(ptr %0, ptr %1) {
_llgo_0: _llgo_0:
%2 = alloca %"github.com/goplus/llgo/internal/runtime.Closure", align 8 %2 = alloca %"github.com/goplus/llgo/internal/runtime.Closure", align 8
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Closure", ptr %2, i32 0, i32 0 %3 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %2, i64 16)
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Closure", ptr %2, i32 0, i32 1 %4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Closure", ptr %3, i32 0, i32 0
store ptr %0, ptr %3, align 8 %5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Closure", ptr %3, i32 0, i32 1
store ptr %1, ptr %4, align 8 store ptr %0, ptr %4, align 8
%5 = load %"github.com/goplus/llgo/internal/runtime.Closure", ptr %2, align 8 store ptr %1, ptr %5, align 8
ret %"github.com/goplus/llgo/internal/runtime.Closure" %5 %6 = load %"github.com/goplus/llgo/internal/runtime.Closure", ptr %3, align 8
ret %"github.com/goplus/llgo/internal/runtime.Closure" %6
} }
define %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice"(ptr %0, i64 %1, i64 %2) { define %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice"(ptr %0, i64 %1, i64 %2) {
_llgo_0: _llgo_0:
%3 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 %3 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %3, i32 0, i32 0 %4 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %3, i64 24)
%5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %3, i32 0, i32 1 %5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %4, i32 0, i32 0
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %3, i32 0, i32 2 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %4, i32 0, i32 1
store ptr %0, ptr %4, align 8 %7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %4, i32 0, i32 2
store i64 %1, ptr %5, align 4 store ptr %0, ptr %5, align 8
store i64 %2, ptr %6, align 4 store i64 %1, ptr %6, align 4
%7 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %3, align 8 store i64 %2, ptr %7, align 4
ret %"github.com/goplus/llgo/internal/runtime.Slice" %7 %8 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %4, align 8
ret %"github.com/goplus/llgo/internal/runtime.Slice" %8
} }
define %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %0, i64 %1, i64 %2, i64 %3, i64 %4, i64 %5) { define %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %0, i64 %1, i64 %2, i64 %3, i64 %4, i64 %5) {
_llgo_0: _llgo_0:
%6 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 %6 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
%7 = icmp slt i64 %3, 0 %7 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %6, i64 24)
br i1 %7, label %_llgo_1, label %_llgo_5 %8 = icmp slt i64 %3, 0
br i1 %8, label %_llgo_1, label %_llgo_5
_llgo_1: ; preds = %_llgo_5, %_llgo_4, %_llgo_3, %_llgo_0 _llgo_1: ; preds = %_llgo_5, %_llgo_4, %_llgo_3, %_llgo_0
%8 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @1, i64 25) %9 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @1, i64 25)
%9 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %8) %10 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %9)
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %9) call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %10)
unreachable unreachable
_llgo_2: ; preds = %_llgo_3 _llgo_2: ; preds = %_llgo_3
%10 = sub i64 %4, %3 %11 = sub i64 %4, %3
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %6, i32 0, i32 1 %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %7, i32 0, i32 1
store i64 %10, ptr %11, align 4 store i64 %11, ptr %12, align 4
%12 = sub i64 %5, %3 %13 = sub i64 %5, %3
%13 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %6, i32 0, i32 2 %14 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %7, i32 0, i32 2
store i64 %12, ptr %13, align 4 store i64 %13, ptr %14, align 4
%14 = sub i64 %5, %3 %15 = sub i64 %5, %3
%15 = icmp sgt i64 %14, 0 %16 = icmp sgt i64 %15, 0
br i1 %15, label %_llgo_6, label %_llgo_8 br i1 %16, label %_llgo_6, label %_llgo_8
_llgo_3: ; preds = %_llgo_4 _llgo_3: ; preds = %_llgo_4
%16 = icmp sgt i64 %5, %2 %17 = icmp sgt i64 %5, %2
br i1 %16, label %_llgo_1, label %_llgo_2 br i1 %17, label %_llgo_1, label %_llgo_2
_llgo_4: ; preds = %_llgo_5 _llgo_4: ; preds = %_llgo_5
%17 = icmp slt i64 %5, %4 %18 = icmp slt i64 %5, %4
br i1 %17, label %_llgo_1, label %_llgo_3 br i1 %18, label %_llgo_1, label %_llgo_3
_llgo_5: ; preds = %_llgo_0 _llgo_5: ; preds = %_llgo_0
%18 = icmp slt i64 %4, %3 %19 = icmp slt i64 %4, %3
br i1 %18, label %_llgo_1, label %_llgo_4 br i1 %19, label %_llgo_1, label %_llgo_4
_llgo_6: ; preds = %_llgo_2 _llgo_6: ; preds = %_llgo_2
%19 = mul i64 %3, %1 %20 = mul i64 %3, %1
%20 = getelementptr i8, ptr %0, i64 %19 %21 = getelementptr i8, ptr %0, i64 %20
%21 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %6, i32 0, i32 0 %22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %7, i32 0, i32 0
store ptr %20, ptr %21, align 8 store ptr %21, ptr %22, align 8
br label %_llgo_7 br label %_llgo_7
_llgo_7: ; preds = %_llgo_8, %_llgo_6 _llgo_7: ; preds = %_llgo_8, %_llgo_6
%22 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %6, align 8 %23 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %7, align 8
ret %"github.com/goplus/llgo/internal/runtime.Slice" %22 ret %"github.com/goplus/llgo/internal/runtime.Slice" %23
_llgo_8: ; preds = %_llgo_2 _llgo_8: ; preds = %_llgo_2
%23 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %6, i32 0, i32 0 %24 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %7, i32 0, i32 0
store ptr %0, ptr %23, align 8 store ptr %0, ptr %24, align 8
br label %_llgo_7 br label %_llgo_7
} }
define %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr %0, i64 %1) { define %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr %0, i64 %1) {
_llgo_0: _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 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %2, i64 16)
%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 %3, i32 0, i32 0
store ptr %0, ptr %3, align 8 %5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 1
store i64 %1, ptr %4, align 4 store ptr %0, ptr %4, align 8
%5 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %2, align 8 store i64 %1, ptr %5, align 4
ret %"github.com/goplus/llgo/internal/runtime.String" %5 %6 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %3, align 8
ret %"github.com/goplus/llgo/internal/runtime.String" %6
} }
define %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %0, i64 %1, i64 %2) { define %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %0, i64 %1, i64 %2) {
_llgo_0: _llgo_0:
%3 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %3 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
store %"github.com/goplus/llgo/internal/runtime.String" %0, ptr %3, align 8 %4 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %3, i64 16)
%4 = icmp slt i64 %1, 0 store %"github.com/goplus/llgo/internal/runtime.String" %0, ptr %4, align 8
br i1 %4, label %_llgo_1, label %_llgo_4 %5 = icmp slt i64 %1, 0
br i1 %5, label %_llgo_1, label %_llgo_4
_llgo_1: ; preds = %_llgo_4, %_llgo_3, %_llgo_0 _llgo_1: ; preds = %_llgo_4, %_llgo_3, %_llgo_0
%5 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @2, i64 32) %6 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewString"(ptr @2, i64 32)
%6 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %5) %7 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %6)
call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %6) call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %7)
unreachable unreachable
_llgo_2: ; preds = %_llgo_3 _llgo_2: ; preds = %_llgo_3
%7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 1 %8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %4, i32 0, i32 1
%8 = load i64, ptr %7, align 4 %9 = load i64, ptr %8, align 4
%9 = icmp slt i64 %1, %8 %10 = icmp slt i64 %1, %9
br i1 %9, label %_llgo_5, label %_llgo_6 br i1 %10, label %_llgo_5, label %_llgo_6
_llgo_3: ; preds = %_llgo_4 _llgo_3: ; preds = %_llgo_4
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 1 %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %4, i32 0, i32 1
%11 = load i64, ptr %10, align 4 %12 = load i64, ptr %11, align 4
%12 = icmp sgt i64 %2, %11 %13 = icmp sgt i64 %2, %12
br i1 %12, label %_llgo_1, label %_llgo_2 br i1 %13, label %_llgo_1, label %_llgo_2
_llgo_4: ; preds = %_llgo_0 _llgo_4: ; preds = %_llgo_0
%13 = icmp slt i64 %2, %1 %14 = icmp slt i64 %2, %1
br i1 %13, label %_llgo_1, label %_llgo_3 br i1 %14, label %_llgo_1, label %_llgo_3
_llgo_5: ; preds = %_llgo_2 _llgo_5: ; preds = %_llgo_2
%14 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %15 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %14, i32 0, i32 0 %16 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %15, i64 16)
%16 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 0 %17 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %16, i32 0, i32 0
%17 = load ptr, ptr %16, align 8 %18 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %4, i32 0, i32 0
%18 = getelementptr i8, ptr %17, i64 %1 %19 = load ptr, ptr %18, align 8
%19 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %14, i32 0, i32 1 %20 = getelementptr i8, ptr %19, i64 %1
%20 = sub i64 %2, %1 %21 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %16, i32 0, i32 1
store ptr %18, ptr %15, align 8 %22 = sub i64 %2, %1
store i64 %20, ptr %19, align 4 store ptr %20, ptr %17, align 8
%21 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %14, align 8 store i64 %22, ptr %21, align 4
ret %"github.com/goplus/llgo/internal/runtime.String" %21 %23 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %16, align 8
ret %"github.com/goplus/llgo/internal/runtime.String" %23
_llgo_6: ; preds = %_llgo_2 _llgo_6: ; preds = %_llgo_2
%22 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %24 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%23 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %22, i32 0, i32 0 %25 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %24, i64 16)
%24 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %22, i32 0, i32 1 %26 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %25, i32 0, i32 0
store ptr null, ptr %23, align 8 %27 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %25, i32 0, i32 1
store i64 0, ptr %24, align 4 store ptr null, ptr %26, align 8
%25 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %22, align 8 store i64 0, ptr %27, align 4
ret %"github.com/goplus/llgo/internal/runtime.String" %25 %28 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %25, align 8
ret %"github.com/goplus/llgo/internal/runtime.String" %28
} }
define %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NilSlice"() { define %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NilSlice"() {
_llgo_0: _llgo_0:
%0 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 %0 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
%1 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %0, i32 0, i32 0 %1 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %0, i64 24)
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %0, i32 0, i32 1 %2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %1, i32 0, i32 0
%3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %0, i32 0, i32 2 %3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %1, i32 0, i32 1
store ptr null, ptr %1, align 8 %4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %1, i32 0, i32 2
store i64 0, ptr %2, align 4 store ptr null, ptr %2, align 8
store i64 0, ptr %3, align 4 store i64 0, ptr %3, align 4
%4 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %0, align 8 store i64 0, ptr %4, align 4
ret %"github.com/goplus/llgo/internal/runtime.Slice" %4 %5 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %1, align 8
ret %"github.com/goplus/llgo/internal/runtime.Slice" %5
} }
define i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %0) { define i64 @"github.com/goplus/llgo/internal/runtime.SliceCap"(%"github.com/goplus/llgo/internal/runtime.Slice" %0) {
_llgo_0: _llgo_0:
%1 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 %1 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
store %"github.com/goplus/llgo/internal/runtime.Slice" %0, ptr %1, align 8 %2 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %1, i64 24)
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %1, i32 0, i32 2 store %"github.com/goplus/llgo/internal/runtime.Slice" %0, ptr %2, align 8
%3 = load i64, ptr %2, align 4 %3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %2, i32 0, i32 2
ret i64 %3 %4 = load i64, ptr %3, align 4
ret i64 %4
} }
define ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %0) { define ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %0) {
_llgo_0: _llgo_0:
%1 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 %1 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
store %"github.com/goplus/llgo/internal/runtime.Slice" %0, ptr %1, align 8 %2 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %1, i64 24)
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %1, i32 0, i32 0 store %"github.com/goplus/llgo/internal/runtime.Slice" %0, ptr %2, align 8
%3 = load ptr, ptr %2, align 8 %3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %2, i32 0, i32 0
ret ptr %3 %4 = load ptr, ptr %3, align 8
ret ptr %4
} }
define i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %0) { define i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %0) {
_llgo_0: _llgo_0:
%1 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 %1 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8
store %"github.com/goplus/llgo/internal/runtime.Slice" %0, ptr %1, align 8 %2 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %1, i64 24)
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %1, i32 0, i32 1 store %"github.com/goplus/llgo/internal/runtime.Slice" %0, ptr %2, align 8
%3 = load i64, ptr %2, align 4 %3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %2, i32 0, i32 1
ret i64 %3 %4 = load i64, ptr %3, align 4
ret i64 %4
} }
define %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String" %0, %"github.com/goplus/llgo/internal/runtime.String" %1) { define %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String" %0, %"github.com/goplus/llgo/internal/runtime.String" %1) {
_llgo_0: _llgo_0:
%2 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %2 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
store %"github.com/goplus/llgo/internal/runtime.String" %0, ptr %2, align 8 %3 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %2, i64 16)
%3 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 store %"github.com/goplus/llgo/internal/runtime.String" %0, ptr %3, align 8
store %"github.com/goplus/llgo/internal/runtime.String" %1, ptr %3, align 8 %4 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 1 %5 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %4, i64 16)
%5 = load i64, ptr %4, align 4 store %"github.com/goplus/llgo/internal/runtime.String" %1, ptr %5, align 8
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 1 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 1
%7 = load i64, ptr %6, align 4 %7 = load i64, ptr %6, align 4
%8 = add i64 %5, %7 %8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %5, i32 0, i32 1
%9 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 %8) %9 = load i64, ptr %8, align 4
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 0 %10 = add i64 %7, %9
%11 = load ptr, ptr %10, align 8 %11 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 %10)
%12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 1 %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 0
%13 = load i64, ptr %12, align 4 %13 = load ptr, ptr %12, align 8
%14 = call ptr @memcpy(ptr %9, ptr %11, i64 %13) %14 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 1
%15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 1 %15 = load i64, ptr %14, align 4
%16 = load i64, ptr %15, align 4 %16 = call ptr @memcpy(ptr %11, ptr %13, i64 %15)
%17 = getelementptr i8, ptr %9, i64 %16 %17 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 1
%18 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 0 %18 = load i64, ptr %17, align 4
%19 = load ptr, ptr %18, align 8 %19 = getelementptr i8, ptr %11, i64 %18
%20 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 1 %20 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %5, i32 0, i32 0
%21 = load i64, ptr %20, align 4 %21 = load ptr, ptr %20, align 8
%22 = call ptr @memcpy(ptr %17, ptr %19, i64 %21) %22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %5, i32 0, i32 1
%23 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %23 = load i64, ptr %22, align 4
%24 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %23, i32 0, i32 0 %24 = call ptr @memcpy(ptr %19, ptr %21, i64 %23)
%25 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %23, i32 0, i32 1 %25 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
store ptr %9, ptr %24, align 8 %26 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %25, i64 16)
store i64 %8, ptr %25, align 4 %27 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %26, i32 0, i32 0
%26 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %23, align 8 %28 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %26, i32 0, i32 1
ret %"github.com/goplus/llgo/internal/runtime.String" %26 store ptr %11, ptr %27, align 8
store i64 %10, ptr %28, align 4
%29 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %26, align 8
ret %"github.com/goplus/llgo/internal/runtime.String" %29
} }
define ptr @"github.com/goplus/llgo/internal/runtime.StringData"(%"github.com/goplus/llgo/internal/runtime.String" %0) { define ptr @"github.com/goplus/llgo/internal/runtime.StringData"(%"github.com/goplus/llgo/internal/runtime.String" %0) {
_llgo_0: _llgo_0:
%1 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %1 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
store %"github.com/goplus/llgo/internal/runtime.String" %0, ptr %1, align 8 %2 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %1, i64 16)
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %1, i32 0, i32 0 store %"github.com/goplus/llgo/internal/runtime.String" %0, ptr %2, align 8
%3 = load ptr, ptr %2, align 8 %3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 0
ret ptr %3 %4 = load ptr, ptr %3, align 8
ret ptr %4
} }
define i64 @"github.com/goplus/llgo/internal/runtime.StringLen"(%"github.com/goplus/llgo/internal/runtime.String" %0) { define i64 @"github.com/goplus/llgo/internal/runtime.StringLen"(%"github.com/goplus/llgo/internal/runtime.String" %0) {
_llgo_0: _llgo_0:
%1 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %1 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
store %"github.com/goplus/llgo/internal/runtime.String" %0, ptr %1, align 8 %2 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %1, i64 16)
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %1, i32 0, i32 1 store %"github.com/goplus/llgo/internal/runtime.String" %0, ptr %2, align 8
%3 = load i64, ptr %2, align 4 %3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 1
ret i64 %3 %4 = load i64, ptr %3, align 4
ret i64 %4
} }
define void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %0) { define void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %0) {
_llgo_0: _llgo_0:
%1 = alloca %"github.com/goplus/llgo/internal/runtime.iface", align 8 %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 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %1, i64 16)
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %1, i32 0, i32 0 store %"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %2, align 8
%3 = load ptr, ptr %2, align 8 %3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, i32 0, i32 0
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %3, i32 0, i32 1 %4 = load ptr, ptr %3, align 8
%5 = load ptr, ptr %4, align 8 %5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.itab", ptr %4, i32 0, i32 1
%6 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %5, i32 0, i32 6 %6 = load ptr, ptr %5, align 8
%7 = load i8, ptr %6, align 1 %7 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %6, i32 0, i32 6
%8 = sext i8 %7 to i64 %8 = load i8, ptr %7, align 1
%9 = icmp eq i64 %8, 24 %9 = sext i8 %8 to i64
br i1 %9, label %_llgo_2, label %_llgo_1 %10 = icmp eq i64 %9, 24
br i1 %10, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_2, %_llgo_0 _llgo_1: ; preds = %_llgo_2, %_llgo_0
ret void ret void
_llgo_2: ; preds = %_llgo_0 _llgo_2: ; preds = %_llgo_0
%10 = load ptr, ptr @__stderrp, align 8 %11 = load ptr, ptr @__stderrp, align 8
%11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %1, i32 0, i32 1 %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, i32 0, i32 1
%12 = load ptr, ptr %11, align 8 %13 = load ptr, ptr %12, align 8
%13 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %12, align 8 %14 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %13, align 8
call void @"github.com/goplus/llgo/internal/runtime.stringTracef"(ptr %10, ptr @3, %"github.com/goplus/llgo/internal/runtime.String" %13) call void @"github.com/goplus/llgo/internal/runtime.stringTracef"(ptr %11, ptr @3, %"github.com/goplus/llgo/internal/runtime.String" %14)
br label %_llgo_1 br label %_llgo_1
} }
define ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %0, i64 %1) {
_llgo_0:
%2 = call ptr @memset(ptr %0, i32 0, i64 %1)
ret ptr %2
}
define ptr @"github.com/goplus/llgo/internal/runtime.basicType"(i64 %0) { define ptr @"github.com/goplus/llgo/internal/runtime.basicType"(i64 %0) {
_llgo_0: _llgo_0:
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 48) %1 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 56)
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %1, i32 0, i32 0 %2 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Type", ptr %1, i32 0, i32 0
%3 = getelementptr inbounds i64, ptr @"github.com/goplus/llgo/internal/runtime.sizeBasicTypes", i64 %0 %3 = getelementptr inbounds i64, ptr @"github.com/goplus/llgo/internal/runtime.sizeBasicTypes", i64 %0
%4 = load i64, ptr %3, align 4 %4 = load i64, ptr %3, align 4
@@ -497,7 +556,7 @@ _llgo_0:
_llgo_1: ; preds = %_llgo_0 _llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"github.com/goplus/llgo/internal/runtime.init$guard", align 1 store i1 true, ptr @"github.com/goplus/llgo/internal/runtime.init$guard", align 1
call void @"github.com/goplus/llgo/internal/abi.init"() call void @"github.com/goplus/llgo/internal/abi.init"()
%1 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 80) %1 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 88)
store ptr %1, ptr @"github.com/goplus/llgo/internal/runtime.TyAny", align 8 store ptr %1, ptr @"github.com/goplus/llgo/internal/runtime.TyAny", align 8
store i64 1, ptr getelementptr inbounds (i64, ptr @"github.com/goplus/llgo/internal/runtime.sizeBasicTypes", i64 1), align 4 store i64 1, ptr getelementptr inbounds (i64, ptr @"github.com/goplus/llgo/internal/runtime.sizeBasicTypes", i64 1), align 4
store i64 8, ptr getelementptr inbounds (i64, ptr @"github.com/goplus/llgo/internal/runtime.sizeBasicTypes", i64 2), align 4 store i64 8, ptr getelementptr inbounds (i64, ptr @"github.com/goplus/llgo/internal/runtime.sizeBasicTypes", i64 2), align 4
@@ -564,7 +623,7 @@ _llgo_0:
define ptr @"github.com/goplus/llgo/internal/runtime.makemap_small"() { define ptr @"github.com/goplus/llgo/internal/runtime.makemap_small"() {
_llgo_0: _llgo_0:
%0 = call ptr @"github.com/goplus/llgo/internal/runtime.Alloc"(i64 48) %0 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 48)
%1 = call i32 @rand() %1 = call i32 @rand()
%2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.hmap", ptr %0, i32 0, i32 4 %2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.hmap", ptr %0, i32 0, i32 4
store i32 %1, ptr %2, align 4 store i32 %1, ptr %2, align 4
@@ -574,19 +633,22 @@ _llgo_0:
define void @"github.com/goplus/llgo/internal/runtime.stringTracef"(ptr %0, ptr %1, %"github.com/goplus/llgo/internal/runtime.String" %2) { define void @"github.com/goplus/llgo/internal/runtime.stringTracef"(ptr %0, ptr %1, %"github.com/goplus/llgo/internal/runtime.String" %2) {
_llgo_0: _llgo_0:
%3 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %3 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8
store %"github.com/goplus/llgo/internal/runtime.String" %2, ptr %3, align 8 %4 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %3, i64 16)
%4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 1 store %"github.com/goplus/llgo/internal/runtime.String" %2, ptr %4, align 8
%5 = load i64, ptr %4, align 4 %5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %4, i32 0, i32 1
%6 = add i64 %5, 1 %6 = load i64, ptr %5, align 4
%7 = alloca i8, i64 %6, align 1 %7 = add i64 %6, 1
%8 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %3, align 8 %8 = alloca i8, i64 %7, align 1
%9 = call ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr %7, %"github.com/goplus/llgo/internal/runtime.String" %8) %9 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %4, align 8
%10 = call i32 (ptr, ptr, ...) @fprintf(ptr %0, ptr %1, ptr %9) %10 = call ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr %8, %"github.com/goplus/llgo/internal/runtime.String" %9)
%11 = call i32 (ptr, ptr, ...) @fprintf(ptr %0, ptr %1, ptr %10)
ret void ret void
} }
declare ptr @malloc(i64) declare ptr @malloc(i64)
declare ptr @memset(ptr, i32, i64)
declare ptr @memcpy(ptr, ptr, i64) declare ptr @memcpy(ptr, ptr, i64)
declare void @"github.com/goplus/llgo/internal/abi.init"() declare void @"github.com/goplus/llgo/internal/abi.init"()

View File

@@ -23,11 +23,22 @@ import (
"github.com/goplus/llgo/internal/runtime/c" "github.com/goplus/llgo/internal/runtime/c"
) )
// Alloc allocates memory. // AllocU allocates uninitialized memory.
func Alloc(size uintptr) unsafe.Pointer { func AllocU(size uintptr) unsafe.Pointer {
return c.Malloc(size) return c.Malloc(size)
} }
// AllocZ allocates zero-initialized memory.
func AllocZ(size uintptr) unsafe.Pointer {
ret := c.Malloc(size)
return c.Memset(ret, 0, size)
}
// Zeroinit initializes memory to zero.
func Zeroinit(p c.Pointer, size uintptr) c.Pointer {
return c.Memset(p, 0, size)
}
// TracePanic prints panic message. // TracePanic prints panic message.
func TracePanic(v Interface) { func TracePanic(v Interface) {
kind := abi.Kind(v.tab._type.Kind_) kind := abi.Kind(v.tab._type.Kind_)

View File

@@ -16,6 +16,7 @@
package runtime package runtime
/*
import ( import (
"unsafe" "unsafe"
) )
@@ -30,3 +31,14 @@ type Closure struct {
func NewClosure(f, data unsafe.Pointer) Closure { func NewClosure(f, data unsafe.Pointer) Closure {
return Closure{f, data} return Closure{f, data}
} }
// ClosureF returns the function of a closure.
func ClosureF(c Closure) unsafe.Pointer {
return c.f
}
// ClosureData returns the data of a closure.
func ClosureData(c Closure) unsafe.Pointer {
return c.data
}
*/

View File

@@ -41,6 +41,20 @@ func NewSlice(data unsafe.Pointer, len, cap int) Slice {
return Slice{data, len, cap} return Slice{data, len, cap}
} }
func NewSlice3(base unsafe.Pointer, eltSize, cap, i, j, k int) (s Slice) {
if i < 0 || j < i || k < j || k > cap {
panic("slice index out of bounds")
}
s.len = j - i
s.cap = k - i
if k-i > 0 {
s.data = c.Advance(base, i*eltSize)
} else {
s.data = base
}
return
}
// SliceLen returns the length of a slice. // SliceLen returns the length of a slice.
func SliceLen(s Slice) int { func SliceLen(s Slice) int {
return s.len return s.len
@@ -56,18 +70,4 @@ func SliceData(s Slice) unsafe.Pointer {
return s.data return s.data
} }
func NewSlice3(base unsafe.Pointer, eltSize, cap, i, j, k int) (s Slice) {
if i < 0 || j < i || k < j || k > cap {
panic("slice index out of bounds")
}
s.len = j - i
s.cap = k - i
if k-i > 0 {
s.data = c.Advance(base, i*eltSize)
} else {
s.data = base
}
return
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@@ -58,7 +58,7 @@ func StringData(s String) unsafe.Pointer {
// StringCat concatenates two strings. // StringCat concatenates two strings.
func StringCat(a, b String) String { func StringCat(a, b String) String {
n := a.len + b.len n := a.len + b.len
dest := Alloc(uintptr(n)) dest := AllocU(uintptr(n))
c.Memcpy(dest, a.data, uintptr(a.len)) c.Memcpy(dest, a.data, uintptr(a.len))
c.Memcpy(c.Advance(dest, a.len), b.data, uintptr(b.len)) c.Memcpy(c.Advance(dest, a.len), b.data, uintptr(b.len))
return String{dest, n} return String{dest, n}
@@ -76,7 +76,7 @@ func CStrCopy(dest unsafe.Pointer, s String) *int8 {
} }
func CStrDup(s String) *int8 { func CStrDup(s String) *int8 {
dest := Alloc(uintptr(s.len + 1)) dest := AllocU(uintptr(s.len + 1))
return CStrCopy(dest, s) return CStrCopy(dest, s)
} }

View File

@@ -17,9 +17,12 @@
package ssa_test package ssa_test
import ( import (
"go/types"
"testing" "testing"
"github.com/goplus/llgo/cl/cltest" "github.com/goplus/llgo/cl/cltest"
"github.com/goplus/llgo/internal/typeutil"
"github.com/goplus/llgo/ssa"
) )
func TestFromTestrt(t *testing.T) { func TestFromTestrt(t *testing.T) {
@@ -34,3 +37,17 @@ func TestRuntime(t *testing.T) {
cltest.Pkg(t, "github.com/goplus/llgo/internal/runtime", "../internal/runtime/llgo_autogen.ll") cltest.Pkg(t, "github.com/goplus/llgo/internal/runtime", "../internal/runtime/llgo_autogen.ll")
cltest.Pkg(t, "github.com/goplus/llgo/internal/abi", "../internal/abi/llgo_autogen.ll") cltest.Pkg(t, "github.com/goplus/llgo/internal/abi", "../internal/abi/llgo_autogen.ll")
} }
func TestMap(t *testing.T) {
var m typeutil.Map
sig := types.NewSignatureType(nil, nil, nil, nil, nil, false)
m.Set(sig, 1)
csig := (*ssa.CFuncPtr)(sig)
m.Set(csig, 2)
if v := m.At(sig); v.(int) != 1 {
t.Fatal("At(sig):", v)
}
if v := m.At(csig); v.(int) != 2 {
t.Fatal("At(csig):", v)
}
}

View File

@@ -173,6 +173,13 @@ func (b Builder) Const(v constant.Value, typ Type) Expr {
panic(fmt.Sprintf("unsupported Const: %v, %v", v, typ.t)) panic(fmt.Sprintf("unsupported Const: %v, %v", v, typ.t))
} }
// SizeOf returns the size of a type.
func (b Builder) SizeOf(t Type, n ...int64) Expr {
prog := b.Prog
size := prog.SizeOf(t, n...)
return prog.IntVal(size, prog.Uintptr())
}
// CStr returns a c-style string constant expression. // CStr returns a c-style string constant expression.
func (b Builder) CStr(v string) Expr { func (b Builder) CStr(v string) Expr {
return Expr{llvm.CreateGlobalStringPtr(b.impl, v), b.Prog.CStr()} return Expr{llvm.CreateGlobalStringPtr(b.impl, v), b.Prog.CStr()}
@@ -483,12 +490,6 @@ func (b Builder) aggregateValue(t Type, flds ...llvm.Value) Expr {
// //
// Type() returns a (possibly named) *types.Pointer. // Type() returns a (possibly named) *types.Pointer.
// //
// Pos() returns the position of the ast.SelectorExpr.Sel for the
// field, if explicit in the source. For implicit selections, returns
// the position of the inducing explicit selection. If produced for a
// struct literal S{f: e}, it returns the position of the colon; for
// S{e} it returns the start of expression e.
//
// Example printed form: // Example printed form:
// //
// t1 = &t0.name [#1] // t1 = &t0.name [#1]
@@ -503,6 +504,15 @@ func (b Builder) FieldAddr(x Expr, idx int) Expr {
return Expr{llvm.CreateStructGEP(b.impl, tstruc.ll, x.impl, idx), pt} return Expr{llvm.CreateStructGEP(b.impl, tstruc.ll, x.impl, idx), pt}
} }
// The Field instruction yields the value of Field of struct X.
func (b Builder) Field(x Expr, idx int) Expr {
if debugInstr {
log.Printf("Field %v, %d\n", x.impl, idx)
}
telem := b.Prog.Field(x.Type, idx)
return Expr{llvm.CreateExtractValue(b.impl, x.impl, idx), telem}
}
// The IndexAddr instruction yields the address of the element at // The IndexAddr instruction yields the address of the element at
// index `idx` of collection `x`. `idx` is an integer expression. // index `idx` of collection `x`. `idx` is an integer expression.
// //
@@ -561,7 +571,8 @@ func (b Builder) Index(x, idx Expr, addr func(Expr) Expr) Expr {
if addr != nil { if addr != nil {
ptr = addr(x) ptr = addr(x)
} else { } else {
ptr = b.Alloca(prog.IntVal(uint64(t.Len()*b.Prog.sizs.Sizeof(t.Elem())), prog.Index(x.Type))) size := b.SizeOf(telem, t.Len())
ptr = b.Alloca(size)
b.Store(ptr, x) b.Store(ptr, x)
} }
} }
@@ -580,10 +591,6 @@ func (b Builder) Index(x, idx Expr, addr func(Expr) Expr) Expr {
// Type() returns string if the type of X was string, otherwise a // Type() returns string if the type of X was string, otherwise a
// *types.Slice with the same element type as X. // *types.Slice with the same element type as X.
// //
// Pos() returns the ast.SliceExpr.Lbrack if created by a x[:] slice
// operation, the ast.CompositeLit.Lbrace if created by a literal, or
// NoPos if not explicit in the source (e.g. a variadic argument slice).
//
// Example printed form: // Example printed form:
// //
// t1 = slice t0[1:] // t1 = slice t0[1:]
@@ -601,12 +608,9 @@ func (b Builder) Slice(x, low, high, max Expr) (ret Expr) {
} }
switch t := x.t.Underlying().(type) { switch t := x.t.Underlying().(type) {
case *types.Basic: case *types.Basic:
if t.Info()&types.IsString == 0 { if t.Kind() != types.String {
panic(fmt.Errorf("invalid operation: cannot slice %v", t)) panic(fmt.Errorf("invalid operation: cannot slice %v", t))
} }
if !max.IsNil() {
panic("invalid operation: 3-index slice of string")
}
if high.IsNil() { if high.IsNil() {
high = b.InlineCall(pkg.rtFunc("StringLen"), x) high = b.InlineCall(pkg.rtFunc("StringLen"), x)
} }
@@ -614,8 +618,8 @@ func (b Builder) Slice(x, low, high, max Expr) (ret Expr) {
ret.impl = b.InlineCall(pkg.rtFunc("NewStringSlice"), x, low, high).impl ret.impl = b.InlineCall(pkg.rtFunc("NewStringSlice"), x, low, high).impl
return return
case *types.Slice: case *types.Slice:
nEltSize = b.SizeOf(prog.Index(x.Type))
nCap = b.InlineCall(pkg.rtFunc("SliceCap"), x) nCap = b.InlineCall(pkg.rtFunc("SliceCap"), x)
nEltSize = prog.IntVal(uint64(prog.sizs.Sizeof(t.Elem())), prog.Int())
if high.IsNil() { if high.IsNil() {
high = b.InlineCall(pkg.rtFunc("SliceLen"), x) high = b.InlineCall(pkg.rtFunc("SliceLen"), x)
} }
@@ -625,9 +629,10 @@ func (b Builder) Slice(x, low, high, max Expr) (ret Expr) {
telem := t.Elem() telem := t.Elem()
switch te := telem.Underlying().(type) { switch te := telem.Underlying().(type) {
case *types.Array: case *types.Array:
ret.Type = prog.Type(types.NewSlice(te.Elem())) elem := prog.Type(te.Elem())
ret.Type = prog.Slice(elem)
nEltSize = b.SizeOf(elem)
nCap = prog.IntVal(uint64(te.Len()), prog.Int()) nCap = prog.IntVal(uint64(te.Len()), prog.Int())
nEltSize = prog.IntVal(uint64(prog.sizs.Sizeof(te.Elem())), prog.Int())
if high.IsNil() { if high.IsNil() {
high = nCap high = nCap
} }
@@ -648,9 +653,6 @@ func (b Builder) Slice(x, low, high, max Expr) (ret Expr) {
// //
// t is a (possibly named) *types.Map. // t is a (possibly named) *types.Map.
// //
// Pos() returns the ast.CallExpr.Lparen, if created by make(map), or
// the ast.CompositeLit.Lbrack if created by a literal.
//
// Example printed form: // Example printed form:
// //
// t1 = make map[string]int t0 // t1 = make map[string]int t0
@@ -666,6 +668,36 @@ func (b Builder) MakeMap(t Type, nReserve Expr) (ret Expr) {
return return
} }
// The MakeSlice instruction yields a slice of length Len backed by a
// newly allocated array of length Cap.
//
// Both Len and Cap must be non-nil Values of integer type.
//
// (Alloc(types.Array) followed by Slice will not suffice because
// Alloc can only create arrays of constant length.)
//
// Type() returns a (possibly named) *types.Slice.
//
// Example printed form:
//
// t1 = make []string 1:int t0
// t1 = make StringSlice 1:int t0
func (b Builder) MakeSlice(t Type, len, cap Expr) (ret Expr) {
if debugInstr {
log.Printf("MakeSlice %v, %v, %v\n", t, len.impl, cap.impl)
}
pkg := b.fn.pkg
if cap.IsNil() {
cap = len
}
elemSize := b.SizeOf(b.Prog.Index(t))
size := b.BinOp(token.MUL, cap, elemSize)
ptr := b.InlineCall(pkg.rtFunc("AllocZ"), size)
ret.impl = b.InlineCall(pkg.rtFunc("NewSlice"), ptr, len, cap).impl
ret.Type = t
return
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// The Alloc instruction reserves space for a variable of the given type, // The Alloc instruction reserves space for a variable of the given type,
@@ -692,15 +724,15 @@ func (b Builder) Alloc(t *types.Pointer, heap bool) (ret Expr) {
log.Printf("Alloc %v, %v\n", t, heap) log.Printf("Alloc %v, %v\n", t, heap)
} }
prog := b.Prog prog := b.Prog
telem := t.Elem() pkg := b.fn.pkg
elem := prog.Type(t.Elem())
size := b.SizeOf(elem)
if heap { if heap {
pkg := b.fn.pkg ret = b.InlineCall(pkg.rtFunc("AllocZ"), size)
size := prog.sizs.Sizeof(telem)
ret = b.Call(pkg.rtFunc("Alloc"), prog.Val(uintptr(size)))
} else { } else {
ret.impl = llvm.CreateAlloca(b.impl, prog.Type(telem).ll) ret = Expr{llvm.CreateAlloca(b.impl, elem.ll), prog.VoidPtr()}
ret.impl = b.InlineCall(pkg.rtFunc("Zeroinit"), ret, size).impl
} }
// TODO(xsw): zero-initialize
ret.Type = prog.Type(t) ret.Type = prog.Type(t)
return return
} }
@@ -802,9 +834,6 @@ func (b Builder) ChangeType(t Type, x Expr) (ret Expr) {
// Conversions of untyped string/number/bool constants to a specific // Conversions of untyped string/number/bool constants to a specific
// representation are eliminated during SSA construction. // representation are eliminated during SSA construction.
// //
// Pos() returns the ast.CallExpr.Lparen, if the instruction arose
// from an explicit conversion in the source.
//
// Example printed form: // Example printed form:
// //
// t1 = convert []byte <- string (t0) // t1 = convert []byte <- string (t0)
@@ -857,9 +886,6 @@ func castPtr(b llvm.Builder, x llvm.Value, t llvm.Type) llvm.Value {
// //
// NewConst(constant.MakeNil(), T, pos) // NewConst(constant.MakeNil(), T, pos)
// //
// Pos() returns the ast.CallExpr.Lparen, if the instruction arose
// from an explicit conversion in the source.
//
// Example printed form: // Example printed form:
// //
// t1 = make interface{} <- int (42:int) // t1 = make interface{} <- int (42:int)
@@ -978,19 +1004,32 @@ func (b Builder) InlineCall(fn Expr, args ...Expr) (ret Expr) {
// t4 = t3() // t4 = t3()
// t7 = invoke t5.Println(...t6) // t7 = invoke t5.Println(...t6)
func (b Builder) Call(fn Expr, args ...Expr) (ret Expr) { func (b Builder) Call(fn Expr, args ...Expr) (ret Expr) {
prog := b.Prog
if debugInstr { if debugInstr {
var b bytes.Buffer var b bytes.Buffer
fmt.Fprint(&b, "Call ", fn.impl.Name()) name := fn.impl.Name()
if name == "" {
name = "closure"
}
fmt.Fprint(&b, "Call ", fn.t, " ", name)
sep := ": "
for _, arg := range args { for _, arg := range args {
fmt.Fprint(&b, ", ", arg.impl) fmt.Fprint(&b, sep, arg.impl)
sep = ", "
} }
log.Println(b.String()) log.Println(b.String())
} }
switch t := fn.t.(type) { t := fn.t
case *types.Signature: switch fn.kind {
ret.Type = b.Prog.retType(t) case vkClosure:
fn = b.Field(fn, 0)
t = fn.t
fallthrough
case vkFuncDecl, vkFuncPtr:
sig := t.(*types.Signature)
ret.Type = prog.retType(sig)
default: default:
panic("todo") panic("unreachable")
} }
ret.impl = llvm.CreateCall(b.impl, fn.ll, fn.impl, llvmValues(args)) ret.impl = llvm.CreateCall(b.impl, fn.ll, fn.impl, llvmValues(args))
return return

View File

@@ -18,7 +18,6 @@ package ssa
import ( import (
"go/types" "go/types"
"runtime"
"github.com/goplus/llgo/internal/typeutil" "github.com/goplus/llgo/internal/typeutil"
"github.com/goplus/llvm" "github.com/goplus/llvm"
@@ -97,7 +96,7 @@ func Initialize(flags InitFlags) {
type aProgram struct { type aProgram struct {
ctx llvm.Context ctx llvm.Context
typs typeutil.Map typs typeutil.Map
sizs types.Sizes // sizs types.Sizes
rt *types.Package rt *types.Package
rtget func() *types.Package rtget func() *types.Package
@@ -115,14 +114,14 @@ type aProgram struct {
voidType llvm.Type voidType llvm.Type
voidPtrTy llvm.Type voidPtrTy llvm.Type
rtClosureTy llvm.Type rtStringTy llvm.Type
rtStringTy llvm.Type rtIfaceTy llvm.Type
rtIfaceTy llvm.Type rtSliceTy llvm.Type
rtSliceTy llvm.Type rtMapTy llvm.Type
rtMapTy llvm.Type
anyTy Type anyTy Type
voidTy Type voidTy Type
voidPtr Type
boolTy Type boolTy Type
cstrTy Type cstrTy Type
stringTy Type stringTy Type
@@ -141,16 +140,19 @@ func NewProgram(target *Target) Program {
if target == nil { if target == nil {
target = &Target{} target = &Target{}
} }
arch := target.GOARCH
if arch == "" {
arch = runtime.GOARCH
}
ctx := llvm.NewContext() ctx := llvm.NewContext()
sizes := types.SizesFor("gc", arch)
// TODO(xsw): Finalize may cause panic, so comment it.
// ctx.Finalize()
td := llvm.NewTargetData("") // TODO(xsw): target config td := llvm.NewTargetData("") // TODO(xsw): target config
return &aProgram{ctx: ctx, sizs: sizes, target: target, td: td} /*
arch := target.GOARCH
if arch == "" {
arch = runtime.GOARCH
}
sizes := types.SizesFor("gc", arch)
// TODO(xsw): Finalize may cause panic, so comment it.
ctx.Finalize()
*/
return &aProgram{ctx: ctx, target: target, td: td}
} }
// SetRuntime sets the runtime. // SetRuntime sets the runtime.
@@ -185,13 +187,6 @@ func (p Program) rtType(name string) Type {
return p.Type(p.rtNamed(name)) return p.Type(p.rtNamed(name))
} }
func (p Program) rtClosure() llvm.Type {
if p.rtClosureTy.IsNil() {
p.rtClosureTy = p.rtType("Closure").ll
}
return p.rtClosureTy
}
func (p Program) rtIface() llvm.Type { func (p Program) rtIface() llvm.Type {
if p.rtIfaceTy.IsNil() { if p.rtIfaceTy.IsNil() {
p.rtIfaceTy = p.rtType("Interface").ll p.rtIfaceTy = p.rtType("Interface").ll
@@ -239,6 +234,13 @@ func (p Program) Void() Type {
return p.voidTy return p.voidTy
} }
func (p Program) VoidPtr() Type {
if p.voidPtr == nil {
p.voidPtr = p.Type(types.Typ[types.UnsafePointer])
}
return p.voidPtr
}
// Bool returns bool type. // Bool returns bool type.
func (p Program) Bool() Type { func (p Program) Bool() Type {
if p.boolTy == nil { if p.boolTy == nil {

View File

@@ -18,6 +18,7 @@ package ssa
import ( import (
"fmt" "fmt"
"go/token"
"go/types" "go/types"
"github.com/goplus/llvm" "github.com/goplus/llvm"
@@ -91,11 +92,19 @@ type aType struct {
type Type = *aType type Type = *aType
/* // TODO(xsw):
// how to generate platform independent code?
func (p Program) SizeOf(typ Type, n ...int64) uint64 {
size := p.td.TypeAllocSize(typ.ll)
if len(n) != 0 {
size *= uint64(n[0])
}
return size
}
func (p Program) Slice(typ Type) Type { func (p Program) Slice(typ Type) Type {
return p.Type(types.NewSlice(typ.t)) return p.Type(types.NewSlice(typ.t))
} }
*/
func (p Program) Pointer(typ Type) Type { func (p Program) Pointer(typ Type) Type {
return p.Type(types.NewPointer(typ.t)) return p.Type(types.NewPointer(typ.t))
@@ -112,15 +121,11 @@ func (p Program) Index(typ Type) Type {
func (p Program) Field(typ Type, i int) Type { func (p Program) Field(typ Type, i int) Type {
tunder := typ.t.Underlying() tunder := typ.t.Underlying()
return p.Type(tunder.(*types.Struct).Field(i).Type()) tfld := tunder.(*types.Struct).Field(i).Type()
return p.Type(tfld)
} }
func (p Program) Type(typ types.Type) Type { func (p Program) Type(typ types.Type) Type {
/* TODO(xsw): no need?
if sig, ok := typ.(*types.Signature); ok { // should methodToFunc
return p.llvmSignature(sig, true)
}
*/
if v := p.typs.At(typ); v != nil { if v := p.typs.At(typ); v != nil {
return v.(Type) return v.(Type)
} }
@@ -297,8 +302,6 @@ func (p Program) toLLVMTypes(t *types.Tuple, n int) (ret []llvm.Type) {
} }
func (p Program) toLLVMFunc(sig *types.Signature, inC, isDecl bool) Type { func (p Program) toLLVMFunc(sig *types.Signature, inC, isDecl bool) Type {
var kind valueKind
var ft llvm.Type
if isDecl || inC { if isDecl || inC {
tParams := sig.Params() tParams := sig.Params()
n := tParams.Len() n := tParams.Len()
@@ -309,6 +312,7 @@ func (p Program) toLLVMFunc(sig *types.Signature, inC, isDecl bool) Type {
params := p.toLLVMTypes(tParams, n) params := p.toLLVMTypes(tParams, n)
out := sig.Results() out := sig.Results()
var ret llvm.Type var ret llvm.Type
var kind valueKind
switch nret := out.Len(); nret { switch nret := out.Len(); nret {
case 0: case 0:
ret = p.tyVoid() ret = p.tyVoid()
@@ -317,18 +321,22 @@ func (p Program) toLLVMFunc(sig *types.Signature, inC, isDecl bool) Type {
default: default:
ret = p.toLLVMTuple(out) ret = p.toLLVMTuple(out)
} }
ft = llvm.FunctionType(ret, params, hasVArg) ft := llvm.FunctionType(ret, params, hasVArg)
if isDecl { if isDecl {
kind = vkFuncDecl kind = vkFuncDecl
} else { } else {
ft = llvm.PointerType(ft, 0) ft = llvm.PointerType(ft, 0)
kind = vkFuncPtr kind = vkFuncPtr
} }
} else { return &aType{ft, sig, kind}
ft = p.rtClosure()
kind = vkClosure
} }
return &aType{ft, sig, kind} flds := []*types.Var{
types.NewField(token.NoPos, nil, "f", (*CFuncPtr)(sig), false),
types.NewField(token.NoPos, nil, "data", types.Typ[types.UnsafePointer], false),
}
t := types.NewStruct(flds, nil)
ll := p.ctx.StructType(p.toLLVMFields(t), false)
return &aType{ll, t, vkClosure}
} }
func (p Program) retType(sig *types.Signature) Type { func (p Program) retType(sig *types.Signature) Type {