diff --git a/cl/_testgo/abiname/in.go b/cl/_testgo/abiname/in.go deleted file mode 100644 index eea265b5..00000000 --- a/cl/_testgo/abiname/in.go +++ /dev/null @@ -1,16 +0,0 @@ -package main - -import "github.com/goplus/llgo/internal/abi" - -// NewPkgName creates a package name. -func NewPkgName(pkgPath string) (ret abi.Name) { - if len(pkgPath) > 0 { - ret = abi.NewName(pkgPath, "", false, false) - } - return -} - -func main() { - n := NewPkgName("pkgPath") - println(n.Name(), n.Tag(), n.IsExported(), n.IsEmbedded(), n.IsBlank()) -} diff --git a/cl/_testgo/abiname/out.ll b/cl/_testgo/abiname/out.ll deleted file mode 100644 index 4330a755..00000000 --- a/cl/_testgo/abiname/out.ll +++ /dev/null @@ -1,104 +0,0 @@ -; ModuleID = 'main' -source_filename = "main" - -%"github.com/goplus/llgo/internal/abi.Name" = type { ptr } -%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 } - -@"main.init$guard" = global ptr null -@0 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 -@__llgo_argc = global ptr null -@__llgo_argv = global ptr null -@1 = private unnamed_addr constant [8 x i8] c"pkgPath\00", align 1 - -define %"github.com/goplus/llgo/internal/abi.Name" @main.NewPkgName(%"github.com/goplus/llgo/internal/runtime.String" %0) { -_llgo_0: - %1 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %0, 1 - %2 = icmp sgt i64 %1, 0 - br i1 %2, label %_llgo_1, label %_llgo_2 - -_llgo_1: ; preds = %_llgo_0 - %3 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 0 - store ptr @0, ptr %4, align 8 - %5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 1 - store i64 0, ptr %5, align 4 - %6 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %3, align 8 - %7 = call %"github.com/goplus/llgo/internal/abi.Name" @"github.com/goplus/llgo/internal/abi.NewName"(%"github.com/goplus/llgo/internal/runtime.String" %0, %"github.com/goplus/llgo/internal/runtime.String" %6, i1 false, i1 false) - %8 = extractvalue %"github.com/goplus/llgo/internal/abi.Name" %7, 0 - br label %_llgo_2 - -_llgo_2: ; preds = %_llgo_1, %_llgo_0 - %9 = phi ptr [ null, %_llgo_0 ], [ %8, %_llgo_1 ] - %10 = alloca %"github.com/goplus/llgo/internal/abi.Name", align 8 - %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/abi.Name", ptr %10, i32 0, i32 0 - store ptr %9, ptr %11, align 8 - %12 = load %"github.com/goplus/llgo/internal/abi.Name", ptr %10, align 8 - ret %"github.com/goplus/llgo/internal/abi.Name" %12 -} - -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 - call void @"github.com/goplus/llgo/internal/abi.init"() - br label %_llgo_2 - -_llgo_2: ; preds = %_llgo_1, %_llgo_0 - ret void -} - -define i32 @main(i32 %0, ptr %1) { -_llgo_0: - store i32 %0, ptr @__llgo_argc, align 4 - store ptr %1, ptr @__llgo_argv, align 8 - call void @"github.com/goplus/llgo/internal/runtime.init"() - call void @main.init() - %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 - store ptr @1, ptr %3, align 8 - %4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 1 - store i64 7, ptr %4, align 4 - %5 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %2, align 8 - %6 = call %"github.com/goplus/llgo/internal/abi.Name" @main.NewPkgName(%"github.com/goplus/llgo/internal/runtime.String" %5) - %7 = call %"github.com/goplus/llgo/internal/runtime.String" @"(github.com/goplus/llgo/internal/abi.Name).Name"(%"github.com/goplus/llgo/internal/abi.Name" %6) - %8 = call %"github.com/goplus/llgo/internal/runtime.String" @"(github.com/goplus/llgo/internal/abi.Name).Tag"(%"github.com/goplus/llgo/internal/abi.Name" %6) - %9 = call i1 @"(github.com/goplus/llgo/internal/abi.Name).IsExported"(%"github.com/goplus/llgo/internal/abi.Name" %6) - %10 = call i1 @"(github.com/goplus/llgo/internal/abi.Name).IsEmbedded"(%"github.com/goplus/llgo/internal/abi.Name" %6) - %11 = call i1 @"(github.com/goplus/llgo/internal/abi.Name).IsBlank"(%"github.com/goplus/llgo/internal/abi.Name" %6) - call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %7) - call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %8) - call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %9) - call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %10) - call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %11) - call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) - ret i32 0 -} - -declare %"github.com/goplus/llgo/internal/abi.Name" @"github.com/goplus/llgo/internal/abi.NewName"(%"github.com/goplus/llgo/internal/runtime.String", %"github.com/goplus/llgo/internal/runtime.String", i1, i1) - -declare void @"github.com/goplus/llgo/internal/abi.init"() - -declare void @"github.com/goplus/llgo/internal/runtime.init"() - -declare %"github.com/goplus/llgo/internal/runtime.String" @"(github.com/goplus/llgo/internal/abi.Name).Name"(%"github.com/goplus/llgo/internal/abi.Name") - -declare %"github.com/goplus/llgo/internal/runtime.String" @"(github.com/goplus/llgo/internal/abi.Name).Tag"(%"github.com/goplus/llgo/internal/abi.Name") - -declare i1 @"(github.com/goplus/llgo/internal/abi.Name).IsExported"(%"github.com/goplus/llgo/internal/abi.Name") - -declare i1 @"(github.com/goplus/llgo/internal/abi.Name).IsEmbedded"(%"github.com/goplus/llgo/internal/abi.Name") - -declare i1 @"(github.com/goplus/llgo/internal/abi.Name).IsBlank"(%"github.com/goplus/llgo/internal/abi.Name") - -declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String") - -declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8) - -declare void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1) diff --git a/cl/_testgo/strucintf/out.ll b/cl/_testgo/strucintf/out.ll index 964328d1..e9932f44 100644 --- a/cl/_testgo/strucintf/out.ll +++ b/cl/_testgo/strucintf/out.ll @@ -158,118 +158,85 @@ _llgo_10: ; preds = %_llgo_0 %45 = getelementptr inbounds { { i64 }, i1 }, ptr %43, i32 0, i32 1 store i1 true, ptr %45, align 1 %46 = load { { i64 }, i1 }, ptr %43, align 4 - %47 = extractvalue { { i64 }, i1 } %46, 0 - %48 = extractvalue { { i64 }, i1 } %46, 1 br label %_llgo_12 _llgo_11: ; preds = %_llgo_0 - %49 = alloca { { i64 }, i1 }, align 8 - %50 = getelementptr inbounds { { i64 }, i1 }, ptr %49, i32 0, i32 0 - store { i64 } zeroinitializer, ptr %50, align 4 - %51 = getelementptr inbounds { { i64 }, i1 }, ptr %49, i32 0, i32 1 - store i1 false, ptr %51, align 1 - %52 = load { { i64 }, i1 }, ptr %49, align 4 - %53 = extractvalue { { i64 }, i1 } %52, 0 - %54 = extractvalue { { i64 }, i1 } %52, 1 + %47 = alloca { { i64 }, i1 }, align 8 + %48 = getelementptr inbounds { { i64 }, i1 }, ptr %47, i32 0, i32 0 + store { i64 } zeroinitializer, ptr %48, align 4 + %49 = getelementptr inbounds { { i64 }, i1 }, ptr %47, i32 0, i32 1 + store i1 false, ptr %49, align 1 + %50 = load { { i64 }, i1 }, ptr %47, align 4 br label %_llgo_12 _llgo_12: ; preds = %_llgo_11, %_llgo_10 - %55 = phi i64 [ %47, %_llgo_10 ], [ %53, %_llgo_11 ] - %56 = phi i1 [ %48, %_llgo_10 ], [ %54, %_llgo_11 ] - %57 = alloca { { i64 }, i1 }, align 8 - %58 = getelementptr inbounds { { i64 }, i1 }, ptr %57, i32 0, i32 0 - store i64 %55, ptr %58, align 4 - %59 = getelementptr inbounds { { i64 }, i1 }, ptr %57, i32 0, i32 1 - store i1 %56, ptr %59, align 1 - %60 = load { { i64 }, i1 }, ptr %57, align 4 - %61 = extractvalue { { i64 }, i1 } %60, 0 - store { i64 } %61, ptr %4, align 4 - %62 = extractvalue { { i64 }, i1 } %60, 1 - br i1 %62, label %_llgo_1, label %_llgo_3 + %51 = phi { { i64 }, i1 } [ %46, %_llgo_10 ], [ %50, %_llgo_11 ] + %52 = extractvalue { { i64 }, i1 } %51, 0 + store { i64 } %52, ptr %4, align 4 + %53 = extractvalue { { i64 }, i1 } %51, 1 + br i1 %53, label %_llgo_1, label %_llgo_3 _llgo_13: ; preds = %_llgo_2 - %63 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %10, 1 - %64 = ptrtoint ptr %63 to i64 - %65 = alloca { i64 }, align 8 - %66 = getelementptr inbounds { i64 }, ptr %65, i32 0, i32 0 - store i64 %64, ptr %66, align 4 - %67 = load { i64 }, ptr %65, align 4 - %68 = alloca { { i64 }, i1 }, align 8 - %69 = getelementptr inbounds { { i64 }, i1 }, ptr %68, i32 0, i32 0 - store { i64 } %67, ptr %69, align 4 - %70 = getelementptr inbounds { { i64 }, i1 }, ptr %68, i32 0, i32 1 - store i1 true, ptr %70, align 1 - %71 = load { { i64 }, i1 }, ptr %68, align 4 - %72 = extractvalue { { i64 }, i1 } %71, 0 - %73 = extractvalue { { i64 }, i1 } %71, 1 + %54 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %10, 1 + %55 = ptrtoint ptr %54 to i64 + %56 = alloca { i64 }, align 8 + %57 = getelementptr inbounds { i64 }, ptr %56, i32 0, i32 0 + store i64 %55, ptr %57, align 4 + %58 = load { i64 }, ptr %56, align 4 + %59 = alloca { { i64 }, i1 }, align 8 + %60 = getelementptr inbounds { { i64 }, i1 }, ptr %59, i32 0, i32 0 + store { i64 } %58, ptr %60, align 4 + %61 = getelementptr inbounds { { i64 }, i1 }, ptr %59, i32 0, i32 1 + store i1 true, ptr %61, align 1 + %62 = load { { i64 }, i1 }, ptr %59, align 4 br label %_llgo_15 _llgo_14: ; preds = %_llgo_2 - %74 = alloca { { i64 }, i1 }, align 8 - %75 = getelementptr inbounds { { i64 }, i1 }, ptr %74, i32 0, i32 0 - store { i64 } zeroinitializer, ptr %75, align 4 - %76 = getelementptr inbounds { { i64 }, i1 }, ptr %74, i32 0, i32 1 - store i1 false, ptr %76, align 1 - %77 = load { { i64 }, i1 }, ptr %74, align 4 - %78 = extractvalue { { i64 }, i1 } %77, 0 - %79 = extractvalue { { i64 }, i1 } %77, 1 + %63 = alloca { { i64 }, i1 }, align 8 + %64 = getelementptr inbounds { { i64 }, i1 }, ptr %63, i32 0, i32 0 + store { i64 } zeroinitializer, ptr %64, align 4 + %65 = getelementptr inbounds { { i64 }, i1 }, ptr %63, i32 0, i32 1 + store i1 false, ptr %65, align 1 + %66 = load { { i64 }, i1 }, ptr %63, align 4 br label %_llgo_15 _llgo_15: ; preds = %_llgo_14, %_llgo_13 - %80 = phi i64 [ %72, %_llgo_13 ], [ %78, %_llgo_14 ] - %81 = phi i1 [ %73, %_llgo_13 ], [ %79, %_llgo_14 ] - %82 = alloca { { i64 }, i1 }, align 8 - %83 = getelementptr inbounds { { i64 }, i1 }, ptr %82, i32 0, i32 0 - store i64 %80, ptr %83, align 4 - %84 = getelementptr inbounds { { i64 }, i1 }, ptr %82, i32 0, i32 1 - store i1 %81, ptr %84, align 1 - %85 = load { { i64 }, i1 }, ptr %82, align 4 - %86 = extractvalue { { i64 }, i1 } %85, 0 - store { i64 } %86, ptr %12, align 4 - %87 = extractvalue { { i64 }, i1 } %85, 1 - br i1 %87, label %_llgo_4, label %_llgo_6 + %67 = phi { { i64 }, i1 } [ %62, %_llgo_13 ], [ %66, %_llgo_14 ] + %68 = extractvalue { { i64 }, i1 } %67, 0 + store { i64 } %68, ptr %12, align 4 + %69 = extractvalue { { i64 }, i1 } %67, 1 + br i1 %69, label %_llgo_4, label %_llgo_6 _llgo_16: ; preds = %_llgo_5 - %88 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %24, 1 - %89 = ptrtoint ptr %88 to i64 - %90 = alloca { i64 }, align 8 - %91 = getelementptr inbounds { i64 }, ptr %90, i32 0, i32 0 - store i64 %89, ptr %91, align 4 - %92 = load { i64 }, ptr %90, align 4 - %93 = alloca { { i64 }, i1 }, align 8 - %94 = getelementptr inbounds { { i64 }, i1 }, ptr %93, i32 0, i32 0 - store { i64 } %92, ptr %94, align 4 - %95 = getelementptr inbounds { { i64 }, i1 }, ptr %93, i32 0, i32 1 - store i1 true, ptr %95, align 1 - %96 = load { { i64 }, i1 }, ptr %93, align 4 - %97 = extractvalue { { i64 }, i1 } %96, 0 - %98 = extractvalue { { i64 }, i1 } %96, 1 + %70 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %24, 1 + %71 = ptrtoint ptr %70 to i64 + %72 = alloca { i64 }, align 8 + %73 = getelementptr inbounds { i64 }, ptr %72, i32 0, i32 0 + store i64 %71, ptr %73, align 4 + %74 = load { i64 }, ptr %72, align 4 + %75 = alloca { { i64 }, i1 }, align 8 + %76 = getelementptr inbounds { { i64 }, i1 }, ptr %75, i32 0, i32 0 + store { i64 } %74, ptr %76, align 4 + %77 = getelementptr inbounds { { i64 }, i1 }, ptr %75, i32 0, i32 1 + store i1 true, ptr %77, align 1 + %78 = load { { i64 }, i1 }, ptr %75, align 4 br label %_llgo_18 _llgo_17: ; preds = %_llgo_5 - %99 = alloca { { i64 }, i1 }, align 8 - %100 = getelementptr inbounds { { i64 }, i1 }, ptr %99, i32 0, i32 0 - store { i64 } zeroinitializer, ptr %100, align 4 - %101 = getelementptr inbounds { { i64 }, i1 }, ptr %99, i32 0, i32 1 - store i1 false, ptr %101, align 1 - %102 = load { { i64 }, i1 }, ptr %99, align 4 - %103 = extractvalue { { i64 }, i1 } %102, 0 - %104 = extractvalue { { i64 }, i1 } %102, 1 + %79 = alloca { { i64 }, i1 }, align 8 + %80 = getelementptr inbounds { { i64 }, i1 }, ptr %79, i32 0, i32 0 + store { i64 } zeroinitializer, ptr %80, align 4 + %81 = getelementptr inbounds { { i64 }, i1 }, ptr %79, i32 0, i32 1 + store i1 false, ptr %81, align 1 + %82 = load { { i64 }, i1 }, ptr %79, align 4 br label %_llgo_18 _llgo_18: ; preds = %_llgo_17, %_llgo_16 - %105 = phi i64 [ %97, %_llgo_16 ], [ %103, %_llgo_17 ] - %106 = phi i1 [ %98, %_llgo_16 ], [ %104, %_llgo_17 ] - %107 = alloca { { i64 }, i1 }, align 8 - %108 = getelementptr inbounds { { i64 }, i1 }, ptr %107, i32 0, i32 0 - store i64 %105, ptr %108, align 4 - %109 = getelementptr inbounds { { i64 }, i1 }, ptr %107, i32 0, i32 1 - store i1 %106, ptr %109, align 1 - %110 = load { { i64 }, i1 }, ptr %107, align 4 - %111 = extractvalue { { i64 }, i1 } %110, 0 - store { i64 } %111, ptr %23, align 4 - %112 = extractvalue { { i64 }, i1 } %110, 1 - br i1 %112, label %_llgo_7, label %_llgo_9 + %83 = phi { { i64 }, i1 } [ %78, %_llgo_16 ], [ %82, %_llgo_17 ] + %84 = extractvalue { { i64 }, i1 } %83, 0 + store { i64 } %84, ptr %23, align 4 + %85 = extractvalue { { i64 }, i1 } %83, 1 + br i1 %85, label %_llgo_7, label %_llgo_9 } declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64) diff --git a/cl/_testgo/struczero/in.go b/cl/_testgo/struczero/in.go index 589b75f2..ce583d11 100644 --- a/cl/_testgo/struczero/in.go +++ b/cl/_testgo/struczero/in.go @@ -20,6 +20,7 @@ func Bar(v any) (ret foo.Foo, ok bool) { func main() { ret, ok := Foo(nil) println(ret.pb, ret.f, "notOk:", !ok) + ret2, ok2 := Bar(foo.Foo{}) println(ret2.Pb(), ret2.F, ok2) } diff --git a/cl/_testgo/struczero/out.ll b/cl/_testgo/struczero/out.ll index 60b85986..a47925bb 100644 --- a/cl/_testgo/struczero/out.ll +++ b/cl/_testgo/struczero/out.ll @@ -1,103 +1,77 @@ ; ModuleID = 'main' source_filename = "main" -%"github.com/goplus/llgo/cl/internal/foo.Foo" = type { ptr, float } -%"github.com/goplus/llgo/internal/runtime.eface" = type { ptr, ptr } %main.bar = type { ptr, float } +%"github.com/goplus/llgo/internal/runtime.eface" = type { ptr, ptr } %"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 } -%"github.com/goplus/llgo/internal/abi.StructField" = type { %"github.com/goplus/llgo/internal/abi.Name", ptr, i64 } -%"github.com/goplus/llgo/internal/abi.Name" = type { ptr } +%"github.com/goplus/llgo/internal/abi.StructField" = type { %"github.com/goplus/llgo/internal/runtime.String", ptr, i64, %"github.com/goplus/llgo/internal/runtime.String", i1 } %"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 } @"main.init$guard" = global ptr null -@"github.com/goplus/llgo/cl/internal/foo.Foo" = linkonce global ptr null +@0 = private unnamed_addr constant [4 x i8] c"Foo\00", align 1 @main.bar = global ptr null +@1 = private unnamed_addr constant [9 x i8] c"Foo done\00", align 1 @__llgo_argc = global ptr null @__llgo_argv = global ptr null -@0 = private unnamed_addr constant [7 x i8] c"notOk:\00", align 1 -@1 = private unnamed_addr constant [3 x i8] c"pb\00", align 1 +@2 = private unnamed_addr constant [5 x i8] c"main\00", align 1 +@3 = private unnamed_addr constant [7 x i8] c"notOk:\00", align 1 +@4 = private unnamed_addr constant [3 x i8] c"pb\00", align 1 @"*_llgo_byte" = linkonce global ptr null -@2 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 -@3 = private unnamed_addr constant [2 x i8] c"F\00", align 1 -@4 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 -@5 = private unnamed_addr constant [5 x i8] c"main\00", align 1 -@6 = private unnamed_addr constant [43 x i8] c"github.com/goplus/llgo/cl/internal/foo.Foo\00", align 1 -@7 = private unnamed_addr constant [3 x i8] c"pb\00", align 1 -@8 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 -@9 = private unnamed_addr constant [2 x i8] c"f\00", align 1 -@10 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 -@11 = private unnamed_addr constant [5 x i8] c"main\00", align 1 -@12 = private unnamed_addr constant [9 x i8] c"main.bar\00", align 1 - -define { %"github.com/goplus/llgo/cl/internal/foo.Foo", i1 } @main.Bar(%"github.com/goplus/llgo/internal/runtime.eface" %0) { -_llgo_0: - %1 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 - %2 = load ptr, ptr @"github.com/goplus/llgo/cl/internal/foo.Foo", align 8 - %3 = icmp eq ptr %1, %2 - br i1 %3, label %_llgo_1, label %_llgo_2 - -_llgo_1: ; preds = %_llgo_0 - %4 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1 - %5 = load %"github.com/goplus/llgo/cl/internal/foo.Foo", ptr %4, align 8 - %6 = alloca { %"github.com/goplus/llgo/cl/internal/foo.Foo", i1 }, align 8 - %7 = getelementptr inbounds { %"github.com/goplus/llgo/cl/internal/foo.Foo", i1 }, ptr %6, i32 0, i32 0 - store %"github.com/goplus/llgo/cl/internal/foo.Foo" %5, ptr %7, align 8 - %8 = getelementptr inbounds { %"github.com/goplus/llgo/cl/internal/foo.Foo", i1 }, ptr %6, i32 0, i32 1 - store i1 true, ptr %8, align 1 - %9 = load { %"github.com/goplus/llgo/cl/internal/foo.Foo", i1 }, ptr %6, align 8 - br label %_llgo_3 - -_llgo_2: ; preds = %_llgo_0 - %10 = alloca { %"github.com/goplus/llgo/cl/internal/foo.Foo", i1 }, align 8 - %11 = getelementptr inbounds { %"github.com/goplus/llgo/cl/internal/foo.Foo", i1 }, ptr %10, i32 0, i32 0 - store { ptr, double } zeroinitializer, ptr %11, align 8 - %12 = getelementptr inbounds { %"github.com/goplus/llgo/cl/internal/foo.Foo", i1 }, ptr %10, i32 0, i32 1 - store i1 false, ptr %12, align 1 - %13 = load { %"github.com/goplus/llgo/cl/internal/foo.Foo", i1 }, ptr %10, align 8 - br label %_llgo_3 - -_llgo_3: ; preds = %_llgo_2, %_llgo_1 - %14 = phi { %"github.com/goplus/llgo/cl/internal/foo.Foo", i1 } [ %9, %_llgo_1 ], [ %13, %_llgo_2 ] - %15 = extractvalue { %"github.com/goplus/llgo/cl/internal/foo.Foo", i1 } %14, 0 - %16 = extractvalue { %"github.com/goplus/llgo/cl/internal/foo.Foo", i1 } %14, 1 - %mrv = insertvalue { %"github.com/goplus/llgo/cl/internal/foo.Foo", i1 } poison, %"github.com/goplus/llgo/cl/internal/foo.Foo" %15, 0 - %mrv1 = insertvalue { %"github.com/goplus/llgo/cl/internal/foo.Foo", i1 } %mrv, i1 %16, 1 - ret { %"github.com/goplus/llgo/cl/internal/foo.Foo", i1 } %mrv1 -} +@5 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 +@6 = private unnamed_addr constant [2 x i8] c"f\00", align 1 +@7 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 +@8 = private unnamed_addr constant [5 x i8] c"main\00", align 1 +@9 = private unnamed_addr constant [9 x i8] c"main.bar\00", align 1 define { %main.bar, i1 } @main.Foo(%"github.com/goplus/llgo/internal/runtime.eface" %0) { _llgo_0: - %1 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 - %2 = load ptr, ptr @main.bar, align 8 - %3 = icmp eq ptr %1, %2 - br i1 %3, label %_llgo_1, label %_llgo_2 + %1 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %1, i32 0, i32 0 + store ptr @0, ptr %2, align 8 + %3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %1, i32 0, i32 1 + store i64 3, ptr %3, align 4 + %4 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %1, align 8 + call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %4) + call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) + %5 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 + %6 = load ptr, ptr @main.bar, align 8 + %7 = icmp eq ptr %5, %6 + br i1 %7, label %_llgo_1, label %_llgo_2 _llgo_1: ; preds = %_llgo_0 - %4 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1 - %5 = load %main.bar, ptr %4, align 8 - %6 = alloca { %main.bar, i1 }, align 8 - %7 = getelementptr inbounds { %main.bar, i1 }, ptr %6, i32 0, i32 0 - store %main.bar %5, ptr %7, align 8 - %8 = getelementptr inbounds { %main.bar, i1 }, ptr %6, i32 0, i32 1 - store i1 true, ptr %8, align 1 - %9 = load { %main.bar, i1 }, ptr %6, align 8 - br label %_llgo_3 - -_llgo_2: ; preds = %_llgo_0 + %8 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1 + %9 = load %main.bar, ptr %8, align 8 %10 = alloca { %main.bar, i1 }, align 8 %11 = getelementptr inbounds { %main.bar, i1 }, ptr %10, i32 0, i32 0 - store { ptr, double } zeroinitializer, ptr %11, align 8 + store %main.bar %9, ptr %11, align 8 %12 = getelementptr inbounds { %main.bar, i1 }, ptr %10, i32 0, i32 1 - store i1 false, ptr %12, align 1 + store i1 true, ptr %12, align 1 %13 = load { %main.bar, i1 }, ptr %10, align 8 br label %_llgo_3 +_llgo_2: ; preds = %_llgo_0 + %14 = alloca { %main.bar, i1 }, align 8 + %15 = getelementptr inbounds { %main.bar, i1 }, ptr %14, i32 0, i32 0 + store { ptr, double } zeroinitializer, ptr %15, align 8 + %16 = getelementptr inbounds { %main.bar, i1 }, ptr %14, i32 0, i32 1 + store i1 false, ptr %16, align 1 + %17 = load { %main.bar, i1 }, ptr %14, align 8 + br label %_llgo_3 + _llgo_3: ; preds = %_llgo_2, %_llgo_1 - %14 = phi { %main.bar, i1 } [ %9, %_llgo_1 ], [ %13, %_llgo_2 ] - %15 = extractvalue { %main.bar, i1 } %14, 0 - %16 = extractvalue { %main.bar, i1 } %14, 1 - %mrv = insertvalue { %main.bar, i1 } poison, %main.bar %15, 0 - %mrv1 = insertvalue { %main.bar, i1 } %mrv, i1 %16, 1 + %18 = phi { %main.bar, i1 } [ %13, %_llgo_1 ], [ %17, %_llgo_2 ] + %19 = extractvalue { %main.bar, i1 } %18, 0 + %20 = extractvalue { %main.bar, i1 } %18, 1 + %21 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %21, i32 0, i32 0 + store ptr @1, ptr %22, align 8 + %23 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %21, i32 0, i32 1 + store i64 8, ptr %23, align 4 + %24 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %21, align 8 + call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %24) + call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) + %mrv = insertvalue { %main.bar, i1 } poison, %main.bar %19, 0 + %mrv1 = insertvalue { %main.bar, i1 } %mrv, i1 %20, 1 ret { %main.bar, i1 } %mrv1 } @@ -108,7 +82,6 @@ _llgo_0: _llgo_1: ; preds = %_llgo_0 store i1 true, ptr @"main.init$guard", align 1 - call void @"github.com/goplus/llgo/cl/internal/foo.init"() call void @"main.init$abi"() br label %_llgo_2 @@ -122,62 +95,46 @@ _llgo_0: store ptr %1, ptr @__llgo_argv, align 8 call void @"github.com/goplus/llgo/internal/runtime.init"() call void @main.init() - %2 = alloca %main.bar, align 8 - %3 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %2, i64 16) - %4 = call { %main.bar, i1 } @main.Foo(%"github.com/goplus/llgo/internal/runtime.eface" zeroinitializer) - %5 = extractvalue { %main.bar, i1 } %4, 0 - store %main.bar %5, ptr %3, align 8 - %6 = extractvalue { %main.bar, i1 } %4, 1 - %7 = getelementptr inbounds %main.bar, ptr %3, i32 0, i32 0 - %8 = load ptr, ptr %7, align 8 - %9 = getelementptr inbounds %main.bar, ptr %3, i32 0, i32 1 - %10 = load float, ptr %9, align 4 - %11 = xor i1 %6, true - %12 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %13 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %12, i32 0, i32 0 - store ptr @0, ptr %13, align 8 - %14 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %12, i32 0, i32 1 - store i64 6, ptr %14, align 4 - %15 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %12, align 8 - call void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr %8) - call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - %16 = fpext float %10 to double - call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double %16) - call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %15) - call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %11) + %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 + store ptr @2, ptr %3, align 8 + %4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 1 + store i64 4, ptr %4, align 4 + %5 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %2, align 8 + call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %5) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) - %17 = alloca %"github.com/goplus/llgo/cl/internal/foo.Foo", align 8 - %18 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %17, i64 16) - %19 = load ptr, ptr @"github.com/goplus/llgo/cl/internal/foo.Foo", align 8 - %20 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) - store %"github.com/goplus/llgo/cl/internal/foo.Foo" zeroinitializer, ptr %20, align 8 - %21 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 - %22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %21, i32 0, i32 0 - store ptr %19, ptr %22, align 8 - %23 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %21, i32 0, i32 1 - store ptr %20, ptr %23, align 8 - %24 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %21, align 8 - %25 = call { %"github.com/goplus/llgo/cl/internal/foo.Foo", i1 } @main.Bar(%"github.com/goplus/llgo/internal/runtime.eface" %24) - %26 = extractvalue { %"github.com/goplus/llgo/cl/internal/foo.Foo", i1 } %25, 0 - store %"github.com/goplus/llgo/cl/internal/foo.Foo" %26, ptr %18, align 8 - %27 = extractvalue { %"github.com/goplus/llgo/cl/internal/foo.Foo", i1 } %25, 1 - %28 = load %"github.com/goplus/llgo/cl/internal/foo.Foo", ptr %18, align 8 - %29 = call ptr @"(github.com/goplus/llgo/cl/internal/foo.Foo).Pb"(%"github.com/goplus/llgo/cl/internal/foo.Foo" %28) - %30 = getelementptr inbounds %"github.com/goplus/llgo/cl/internal/foo.Foo", ptr %18, i32 0, i32 1 - %31 = load float, ptr %30, align 4 - call void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr %29) + %6 = alloca %main.bar, align 8 + %7 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %6, i64 16) + %8 = call { %main.bar, i1 } @main.Foo(%"github.com/goplus/llgo/internal/runtime.eface" zeroinitializer) + %9 = extractvalue { %main.bar, i1 } %8, 0 + store %main.bar %9, ptr %7, align 8 + %10 = extractvalue { %main.bar, i1 } %8, 1 + %11 = getelementptr inbounds %main.bar, ptr %7, i32 0, i32 0 + %12 = load ptr, ptr %11, align 8 + %13 = getelementptr inbounds %main.bar, ptr %7, i32 0, i32 1 + %14 = load float, ptr %13, align 4 + %15 = xor i1 %10, true + %16 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %17 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %16, i32 0, i32 0 + store ptr @3, ptr %17, align 8 + %18 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %16, i32 0, i32 1 + store i64 6, ptr %18, align 4 + %19 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %16, align 8 + call void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr %12) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - %32 = fpext float %31 to double - call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double %32) + %20 = fpext float %14 to double + call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double %20) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %27) + call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %19) + call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) + call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 %15) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) ret i32 0 } -declare void @"github.com/goplus/llgo/cl/internal/foo.init"() +declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String") + +declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8) declare void @"github.com/goplus/llgo/internal/runtime.init"() @@ -185,147 +142,77 @@ declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64) declare void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr) -declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8) - declare void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double) -declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String") - declare void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1) -declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64) - -declare ptr @"(github.com/goplus/llgo/cl/internal/foo.Foo).Pb"(%"github.com/goplus/llgo/cl/internal/foo.Foo") - define void @"main.init$abi"() { _llgo_0: - %0 = load ptr, ptr @"github.com/goplus/llgo/cl/internal/foo.Foo", align 8 - %1 = icmp eq ptr %0, null - br i1 %1, label %_llgo_1, label %_llgo_2 - -_llgo_1: ; preds = %_llgo_0 - %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 - store ptr @1, ptr %3, align 8 - %4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 1 - store i64 2, ptr %4, align 4 - %5 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %2, align 8 - %6 = load ptr, ptr @"*_llgo_byte", align 8 - %7 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 0 - store ptr @2, ptr %8, align 8 - %9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 1 - store i64 0, ptr %9, align 4 - %10 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %7, align 8 - %11 = call %"github.com/goplus/llgo/internal/abi.StructField" @"github.com/goplus/llgo/internal/runtime.StructField"(%"github.com/goplus/llgo/internal/runtime.String" %5, ptr %6, i64 0, %"github.com/goplus/llgo/internal/runtime.String" %10, i1 false, i1 false) - %12 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %13 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %12, i32 0, i32 0 - store ptr @3, ptr %13, align 8 - %14 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %12, i32 0, i32 1 - store i64 1, ptr %14, align 4 - %15 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %12, align 8 - %16 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 13) - %17 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %18 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %17, i32 0, i32 0 - store ptr @4, ptr %18, align 8 - %19 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %17, i32 0, i32 1 - store i64 0, ptr %19, align 4 - %20 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %17, align 8 - %21 = call %"github.com/goplus/llgo/internal/abi.StructField" @"github.com/goplus/llgo/internal/runtime.StructField"(%"github.com/goplus/llgo/internal/runtime.String" %15, ptr %16, i64 8, %"github.com/goplus/llgo/internal/runtime.String" %20, i1 true, i1 false) - %22 = 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 - store ptr @5, ptr %23, align 8 - %24 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %22, i32 0, i32 1 - store i64 4, ptr %24, align 4 - %25 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %22, align 8 - %26 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 48) - %27 = getelementptr %"github.com/goplus/llgo/internal/abi.StructField", ptr %26, i64 0 - store %"github.com/goplus/llgo/internal/abi.StructField" %11, ptr %27, align 8 - %28 = getelementptr %"github.com/goplus/llgo/internal/abi.StructField", ptr %26, i64 1 - store %"github.com/goplus/llgo/internal/abi.StructField" %21, ptr %28, align 8 - %29 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 - %30 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %29, i32 0, i32 0 - store ptr %26, ptr %30, align 8 - %31 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %29, i32 0, i32 1 - store i64 2, ptr %31, align 4 - %32 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %29, i32 0, i32 2 - store i64 2, ptr %32, align 4 - %33 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %29, align 8 - %34 = call ptr @"github.com/goplus/llgo/internal/runtime.Struct"(%"github.com/goplus/llgo/internal/runtime.String" %25, %"github.com/goplus/llgo/internal/runtime.Slice" %33) - %35 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %36 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %35, i32 0, i32 0 - store ptr @6, ptr %36, align 8 - %37 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %35, i32 0, i32 1 - store i64 42, ptr %37, align 4 - %38 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %35, align 8 - %39 = call ptr @"github.com/goplus/llgo/internal/runtime.Named"(%"github.com/goplus/llgo/internal/runtime.String" %38, ptr %34) - store ptr %39, ptr @"github.com/goplus/llgo/cl/internal/foo.Foo", align 8 - br label %_llgo_2 - -_llgo_2: ; preds = %_llgo_1, %_llgo_0 - %40 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %41 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %40, i32 0, i32 0 - store ptr @7, ptr %41, align 8 - %42 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %40, i32 0, i32 1 - store i64 2, ptr %42, align 4 - %43 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %40, align 8 - %44 = load ptr, ptr @"*_llgo_byte", align 8 - %45 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %46 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %45, i32 0, i32 0 - store ptr @8, ptr %46, align 8 - %47 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %45, i32 0, i32 1 - store i64 0, ptr %47, align 4 - %48 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %45, align 8 - %49 = call %"github.com/goplus/llgo/internal/abi.StructField" @"github.com/goplus/llgo/internal/runtime.StructField"(%"github.com/goplus/llgo/internal/runtime.String" %43, ptr %44, i64 0, %"github.com/goplus/llgo/internal/runtime.String" %48, i1 false, i1 false) - %50 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %51 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %50, i32 0, i32 0 - store ptr @9, ptr %51, align 8 - %52 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %50, i32 0, i32 1 - store i64 1, ptr %52, align 4 - %53 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %50, align 8 - %54 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 13) - %55 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %56 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %55, i32 0, i32 0 - store ptr @10, ptr %56, align 8 - %57 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %55, i32 0, i32 1 - store i64 0, ptr %57, align 4 - %58 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %55, align 8 - %59 = call %"github.com/goplus/llgo/internal/abi.StructField" @"github.com/goplus/llgo/internal/runtime.StructField"(%"github.com/goplus/llgo/internal/runtime.String" %53, ptr %54, i64 8, %"github.com/goplus/llgo/internal/runtime.String" %58, i1 false, i1 false) - %60 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %61 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %60, i32 0, i32 0 - store ptr @11, ptr %61, align 8 - %62 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %60, i32 0, i32 1 - store i64 4, ptr %62, align 4 - %63 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %60, align 8 - %64 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 48) - %65 = getelementptr %"github.com/goplus/llgo/internal/abi.StructField", ptr %64, i64 0 - store %"github.com/goplus/llgo/internal/abi.StructField" %49, ptr %65, align 8 - %66 = getelementptr %"github.com/goplus/llgo/internal/abi.StructField", ptr %64, i64 1 - store %"github.com/goplus/llgo/internal/abi.StructField" %59, ptr %66, align 8 - %67 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 - %68 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %67, i32 0, i32 0 - store ptr %64, ptr %68, align 8 - %69 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %67, i32 0, i32 1 - store i64 2, ptr %69, align 4 - %70 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %67, i32 0, i32 2 - store i64 2, ptr %70, align 4 - %71 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %67, align 8 - %72 = call ptr @"github.com/goplus/llgo/internal/runtime.Struct"(%"github.com/goplus/llgo/internal/runtime.String" %63, %"github.com/goplus/llgo/internal/runtime.Slice" %71) - %73 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %74 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %73, i32 0, i32 0 - store ptr @12, ptr %74, align 8 - %75 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %73, i32 0, i32 1 - store i64 8, ptr %75, align 4 - %76 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %73, align 8 - %77 = call ptr @"github.com/goplus/llgo/internal/runtime.Named"(%"github.com/goplus/llgo/internal/runtime.String" %76, ptr %72) - store ptr %77, ptr @main.bar, 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 + store ptr @4, ptr %1, align 8 + %2 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %0, i32 0, i32 1 + store i64 2, ptr %2, align 4 + %3 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %0, align 8 + %4 = load ptr, ptr @"*_llgo_byte", align 8 + %5 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %5, i32 0, i32 0 + store ptr @5, ptr %6, align 8 + %7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %5, i32 0, i32 1 + store i64 0, ptr %7, align 4 + %8 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %5, align 8 + %9 = call %"github.com/goplus/llgo/internal/abi.StructField" @"github.com/goplus/llgo/internal/runtime.StructField"(%"github.com/goplus/llgo/internal/runtime.String" %3, ptr %4, i64 0, %"github.com/goplus/llgo/internal/runtime.String" %8, i1 false) + %10 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %10, i32 0, i32 0 + store ptr @6, ptr %11, align 8 + %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %10, i32 0, i32 1 + store i64 1, ptr %12, align 4 + %13 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %10, align 8 + %14 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 13) + %15 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %16 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %15, i32 0, i32 0 + store ptr @7, ptr %16, align 8 + %17 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %15, i32 0, i32 1 + store i64 0, ptr %17, align 4 + %18 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %15, align 8 + %19 = call %"github.com/goplus/llgo/internal/abi.StructField" @"github.com/goplus/llgo/internal/runtime.StructField"(%"github.com/goplus/llgo/internal/runtime.String" %13, ptr %14, i64 8, %"github.com/goplus/llgo/internal/runtime.String" %18, i1 false) + %20 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %21 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %20, i32 0, i32 0 + store ptr @8, ptr %21, align 8 + %22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %20, i32 0, i32 1 + store i64 4, ptr %22, align 4 + %23 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %20, align 8 + %24 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 112) + %25 = getelementptr %"github.com/goplus/llgo/internal/abi.StructField", ptr %24, i64 0 + store %"github.com/goplus/llgo/internal/abi.StructField" %9, ptr %25, align 8 + %26 = getelementptr %"github.com/goplus/llgo/internal/abi.StructField", ptr %24, i64 1 + store %"github.com/goplus/llgo/internal/abi.StructField" %19, ptr %26, align 8 + %27 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 + %28 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %27, i32 0, i32 0 + store ptr %24, ptr %28, align 8 + %29 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %27, i32 0, i32 1 + store i64 2, ptr %29, align 4 + %30 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %27, i32 0, i32 2 + store i64 2, ptr %30, align 4 + %31 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %27, align 8 + %32 = call ptr @"github.com/goplus/llgo/internal/runtime.Struct"(%"github.com/goplus/llgo/internal/runtime.String" %23, i64 16, %"github.com/goplus/llgo/internal/runtime.Slice" %31) + %33 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %34 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %33, i32 0, i32 0 + store ptr @9, ptr %34, align 8 + %35 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %33, i32 0, i32 1 + store i64 8, ptr %35, align 4 + %36 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %33, align 8 + %37 = call ptr @"github.com/goplus/llgo/internal/runtime.Named"(%"github.com/goplus/llgo/internal/runtime.String" %36, ptr %32) + store ptr %37, ptr @main.bar, align 8 ret void } -declare ptr @"github.com/goplus/llgo/internal/runtime.Struct"(i64, %"github.com/goplus/llgo/internal/runtime.String", %"github.com/goplus/llgo/internal/runtime.Slice") +declare ptr @"github.com/goplus/llgo/internal/runtime.Struct"(%"github.com/goplus/llgo/internal/runtime.String", i64, %"github.com/goplus/llgo/internal/runtime.Slice") -declare %"github.com/goplus/llgo/internal/abi.StructField" @"github.com/goplus/llgo/internal/runtime.StructField"(%"github.com/goplus/llgo/internal/runtime.String", ptr, i64, %"github.com/goplus/llgo/internal/runtime.String", i1, i1) +declare %"github.com/goplus/llgo/internal/abi.StructField" @"github.com/goplus/llgo/internal/runtime.StructField"(%"github.com/goplus/llgo/internal/runtime.String", ptr, i64, %"github.com/goplus/llgo/internal/runtime.String", i1) declare ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64) -declare ptr @"github.com/goplus/llgo/internal/runtime.Named"(%"github.com/goplus/llgo/internal/runtime.String", ptr) +declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64) + +declare ptr @"github.com/goplus/llgo/internal/runtime.Named"(%"github.com/goplus/llgo/internal/runtime.String", %"github.com/goplus/llgo/internal/runtime.String", ptr, %"github.com/goplus/llgo/internal/runtime.Slice") diff --git a/cl/_testrt/concat/out.ll b/cl/_testrt/concat/out.ll index 7217f45f..1ef2685d 100644 --- a/cl/_testrt/concat/out.ll +++ b/cl/_testrt/concat/out.ll @@ -25,37 +25,26 @@ _llgo_0: %4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 1 store i64 0, ptr %4, align 4 %5 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %2, align 8 - %6 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %5, 0 - %7 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %5, 1 br label %_llgo_1 _llgo_1: ; preds = %_llgo_2, %_llgo_0 - %8 = phi ptr [ %6, %_llgo_0 ], [ %22, %_llgo_2 ] - %9 = phi i64 [ %7, %_llgo_0 ], [ %23, %_llgo_2 ] - %10 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %10, i32 0, i32 0 - store ptr %8, ptr %11, align 8 - %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %10, i32 0, i32 1 - store i64 %9, ptr %12, align 4 - %13 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %10, align 8 - %14 = phi i64 [ -1, %_llgo_0 ], [ %15, %_llgo_2 ] - %15 = add i64 %14, 1 - %16 = icmp slt i64 %15, %1 - br i1 %16, label %_llgo_2, label %_llgo_3 + %6 = phi %"github.com/goplus/llgo/internal/runtime.String" [ %5, %_llgo_0 ], [ %14, %_llgo_2 ] + %7 = phi i64 [ -1, %_llgo_0 ], [ %8, %_llgo_2 ] + %8 = add i64 %7, 1 + %9 = icmp slt i64 %8, %1 + br i1 %9, label %_llgo_2, label %_llgo_3 _llgo_2: ; preds = %_llgo_1 - %17 = icmp slt i64 %15, 0 - call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %17) - %18 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0 - %19 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %18, i64 %15 - %20 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %19, align 8 - %21 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String" %13, %"github.com/goplus/llgo/internal/runtime.String" %20) - %22 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %21, 0 - %23 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %21, 1 + %10 = icmp slt i64 %8, 0 + call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %10) + %11 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0 + %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %11, i64 %8 + %13 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %12, align 8 + %14 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.StringCat"(%"github.com/goplus/llgo/internal/runtime.String" %6, %"github.com/goplus/llgo/internal/runtime.String" %13) br label %_llgo_1 _llgo_3: ; preds = %_llgo_1 - ret %"github.com/goplus/llgo/internal/runtime.String" %13 + ret %"github.com/goplus/llgo/internal/runtime.String" %6 } define %"github.com/goplus/llgo/internal/runtime.String" @main.info(%"github.com/goplus/llgo/internal/runtime.String" %0) { diff --git a/internal/abi/llgo_autogen.lla b/internal/abi/llgo_autogen.lla index 728e9013..2eb60535 100644 Binary files a/internal/abi/llgo_autogen.lla and b/internal/abi/llgo_autogen.lla differ diff --git a/internal/abi/type.go b/internal/abi/type.go index a6a01d85..8cf09096 100644 --- a/internal/abi/type.go +++ b/internal/abi/type.go @@ -20,6 +20,15 @@ import ( "unsafe" ) +// IsExported reports whether name starts with an upper-case letter. +func IsExported(name string) bool { + if len(name) > 0 { + c := name[0] + return 'A' <= c && c <= 'Z' + } + return false +} + // ----------------------------------------------------------------------------- // Type is the runtime representation of a Go type. @@ -46,8 +55,8 @@ type Type struct { // If the KindGCProg bit is set in kind, GCData is a GC program. // Otherwise it is a ptrmask bitmap. See mbitmap.go for details. GCData *byte - Str_ Name // string form - PtrToThis_ *Type // type for pointer to this type, may be nil + Str_ string // string form + PtrToThis_ *Type // type for pointer to this type, may be nil } // A Kind represents the specific kind of type that a Type represents. @@ -209,32 +218,41 @@ func (p *FuncType) Variadic() bool { } type StructField struct { - Name Name // name is always non-empty + Name_ string // name is always non-empty Typ *Type // type of field Offset uintptr // byte offset of field + + Tag_ string + Embedded_ bool } +// Embedded reports whether the field is embedded. func (f *StructField) Embedded() bool { - return f.Name.IsEmbedded() + return f.Embedded_ +} + +// Exported reports whether the field is exported. +func (f *StructField) Exported() bool { + return IsExported(f.Name_) } type StructType struct { Type - PkgPath Name - Fields []StructField + PkgPath_ string + Fields []StructField } type InterfaceType struct { Type - PkgPath Name // import path - Methods []Imethod // sorted by hash + PkgPath_ string // import path + Methods []Imethod // sorted by hash } type Text = unsafe.Pointer // TODO(xsw): to be confirmed // Method on non-interface type type Method struct { - Name_ Name // name of method + Name_ string // name of method Mtyp_ *FuncType // method type (without receiver) Ifn_ Text // fn used in interface call (one-word receiver) Tfn_ Text // fn used for normal method call @@ -242,7 +260,7 @@ type Method struct { // Exported reports whether the method is exported. func (p *Method) Exported() bool { - return p.Name_.IsExported() + return IsExported(p.Name_) } // UncommonType is present only for defined types or types with methods @@ -250,7 +268,7 @@ func (p *Method) Exported() bool { // Using a pointer to this struct reduces the overall size required // to describe a non-defined type with no methods. type UncommonType struct { - PkgPath_ Name // import path; empty for built-in types like int, string + PkgPath_ string // import path; empty for built-in types like int, string Mcount uint16 // number of methods Xcount uint16 // number of exported methods Moff uint32 // offset from this uncommontype to [mcount]Method @@ -272,7 +290,7 @@ func (t *UncommonType) ExportedMethods() []Method { // Imethod represents a method on an interface type type Imethod struct { - Name_ Name // name of method + Name_ string // name of method Typ_ *FuncType // .(*FuncType) underneath } @@ -438,6 +456,7 @@ func addChecked(p unsafe.Pointer, x uintptr, whySafe string) unsafe.Pointer { return unsafe.Pointer(uintptr(p) + x) } +/* // Name is an encoded type Name with optional extra data. // // The first byte is a bit field containing: @@ -588,5 +607,6 @@ func NewName(n, tag string, exported, embedded bool) Name { return Name{Bytes: &b[0]} } +*/ // ----------------------------------------------------------------------------- diff --git a/internal/runtime/llgo_autogen.lla b/internal/runtime/llgo_autogen.lla index 8bb2787b..6b788455 100644 Binary files a/internal/runtime/llgo_autogen.lla and b/internal/runtime/llgo_autogen.lla differ diff --git a/internal/runtime/z_face.go b/internal/runtime/z_face.go index 01907b0a..c7611fd3 100644 --- a/internal/runtime/z_face.go +++ b/internal/runtime/z_face.go @@ -86,7 +86,7 @@ func Func(in, out []*Type, variadic bool) *FuncType { } // Imethod returns an interface method. -func Imethod(name Name, typ *FuncType) abi.Imethod { +func Imethod(name string, typ *FuncType) abi.Imethod { return abi.Imethod{ Name_: name, Typ_: typ, @@ -94,7 +94,7 @@ func Imethod(name Name, typ *FuncType) abi.Imethod { } // Method returns a method. -func Method(name Name, typ *FuncType, ifn, tfn abi.Text) abi.Method { +func Method(name string, typ *FuncType, ifn, tfn abi.Text) abi.Method { return abi.Method{ Name_: name, Mtyp_: typ, @@ -104,11 +104,11 @@ func Method(name Name, typ *FuncType, ifn, tfn abi.Text) abi.Method { } // Named returns a named type. -func Named(pkgPath, name Name, underlying *Type, methods []abi.Method) *Type { +func Named(pkgPath, name string, underlying *Type, methods []abi.Method) *Type { tflag := underlying.TFlag size := typeHdrSize n := len(methods) - if n > 0 || pkgPath.Bytes != nil { + if n > 0 || pkgPath != "" { size += uncommonTypeHdrSize + uintptr(n)*methodSize tflag |= abi.TFlagUncommon } @@ -139,15 +139,15 @@ func Named(pkgPath, name Name, underlying *Type, methods []abi.Method) *Type { } // Interface returns an interface type. -func Interface(pkgPath Name, methods []abi.Imethod) *Type { +func Interface(pkgPath string, methods []abi.Imethod) *Type { ret := &abi.InterfaceType{ Type: Type{ Size_: unsafe.Sizeof(eface{}), Hash: uint32(abi.Interface), // TODO(xsw): hash Kind_: uint8(abi.Interface), }, - PkgPath: pkgPath, - Methods: methods, + PkgPath_: pkgPath, + Methods: methods, } return &ret.Type } @@ -168,7 +168,7 @@ func NewItab(inter *InterfaceType, typ *Type) *Itab { ret.fun[0] = 0 } else { data := (*uintptr)(c.Advance(ptr, int(itabHdrSize))) - mthds := methods(u, inter.PkgPath) + mthds := methods(u, inter.PkgPath_) for i, m := range inter.Methods { fn := findMethod(mthds, m) if fn == nil { @@ -182,9 +182,9 @@ func NewItab(inter *InterfaceType, typ *Type) *Itab { } func findMethod(mthds []abi.Method, im abi.Imethod) abi.Text { - imName := im.Name_.Name() + imName := im.Name_ for _, m := range mthds { - mName := m.Name_.Name() + mName := m.Name_ if mName >= imName { if mName == imName && m.Mtyp_ == im.Typ_ { return m.Ifn_ @@ -195,8 +195,8 @@ func findMethod(mthds []abi.Method, im abi.Imethod) abi.Text { return nil } -func methods(u *abi.UncommonType, from abi.Name) []abi.Method { - if u.PkgPath_.Name() == from.Name() { +func methods(u *abi.UncommonType, from string) []abi.Method { + if u.PkgPath_ == from { return u.Methods() } return u.ExportedMethods() diff --git a/internal/runtime/z_type.go b/internal/runtime/z_type.go index dfe2a4d4..aa4431bb 100644 --- a/internal/runtime/z_type.go +++ b/internal/runtime/z_type.go @@ -23,11 +23,13 @@ import ( ) type Kind = abi.Kind -type Name = abi.Name type Type = abi.Type // ----------------------------------------------------------------------------- +/* +type Name = abi.Name + // NewName creates a new name. func NewName(name string, exported bool) Name { return abi.NewName(name, "", exported, false) @@ -40,6 +42,7 @@ func NewPkgName(pkgPath string) (ret Name) { } return } +*/ // ----------------------------------------------------------------------------- @@ -102,25 +105,26 @@ func basicType(kind abi.Kind) *Type { // ----------------------------------------------------------------------------- // StructField returns a struct field. -func StructField(name string, typ *Type, off uintptr, tag string, exported, embedded bool) abi.StructField { - n := abi.NewName(name, tag, exported, embedded) +func StructField(name string, typ *Type, off uintptr, tag string, embedded bool) abi.StructField { return abi.StructField{ - Name: n, - Typ: typ, - Offset: off, + Name_: name, + Typ: typ, + Offset: off, + Tag_: tag, + Embedded_: embedded, } } // Struct returns a struct type. -func Struct(pkgPath Name, size uintptr, fields ...abi.StructField) *Type { +func Struct(pkgPath string, size uintptr, fields ...abi.StructField) *Type { ret := &abi.StructType{ Type: Type{ Size_: size, Hash: uint32(abi.Struct), // TODO(xsw): hash Kind_: uint8(abi.Struct), }, - PkgPath: pkgPath, - Fields: fields, + PkgPath_: pkgPath, + Fields: fields, } return &ret.Type } diff --git a/ssa/cl_test.go b/ssa/cl_test.go index e65de0f7..513944c1 100644 --- a/ssa/cl_test.go +++ b/ssa/cl_test.go @@ -26,7 +26,7 @@ import ( ) func TestFromTestgo(t *testing.T) { - cltest.FromDir(t, "strucintf", "../cl/_testgo", false) + cltest.FromDir(t, "", "../cl/_testgo", false) } func TestFromTestpy(t *testing.T) { diff --git a/ssa/expr.go b/ssa/expr.go index ca48328e..5e7b50af 100644 --- a/ssa/expr.go +++ b/ssa/expr.go @@ -91,6 +91,8 @@ func (p Program) Zero(t Type) Expr { flds[i] = p.Zero(p.rawType(u.Field(i).Type())).impl } ret = llvm.ConstStruct(flds, false) + case *types.Slice: + ret = p.Zero(p.rtType("Slice")).impl default: log.Panicln("todo:", u) } @@ -193,7 +195,8 @@ func (b Builder) Str(v string) (ret Expr) { func (b Builder) pkgName(pkgPath string) Expr { // TODO(xsw): use a global cache - return b.Call(b.Pkg.rtFunc("NewPkgName"), b.Str(pkgPath)) + // return b.Call(b.Pkg.rtFunc("NewPkgName"), b.Str(pkgPath)) + return b.Str(pkgPath) } // unsafeString(data *byte, size int) string @@ -513,38 +516,42 @@ func llvmPredBlocks(preds []BasicBlock) []llvm.BasicBlock { type aPhi struct { Expr - phis []llvm.Value + // phis []llvm.Value } // Phi represents a phi node. type Phi = *aPhi +/* func (b Builder) newPhi(t Type, phis []llvm.Value) Phi { ret := b.aggregateValue(t, phis...) return &aPhi{ret, phis} } +*/ // AddIncoming adds incoming values to a phi node. func (p Phi) AddIncoming(b Builder, preds []BasicBlock, f func(i int, blk BasicBlock) Expr) { bs := llvmPredBlocks(preds) - phis := p.phis - if phis != nil { - vals := make([][]llvm.Value, len(phis)) - for iblk, blk := range preds { - val := f(iblk, blk).impl - impl := b.impl - b.SetBlockEx(blk, BeforeLast, false) - for i := range phis { - if iblk == 0 { - vals[i] = make([]llvm.Value, len(preds)) + /* + phis := p.phis + if phis != nil { + vals := make([][]llvm.Value, len(phis)) + for iblk, blk := range preds { + val := f(iblk, blk).impl + impl := b.impl + b.SetBlockEx(blk, BeforeLast, false) + for i := range phis { + if iblk == 0 { + vals[i] = make([]llvm.Value, len(preds)) + } + vals[i][iblk] = llvm.CreateExtractValue(impl, val, i) } - vals[i][iblk] = llvm.CreateExtractValue(impl, val, i) } - } - for i, phi := range phis { - phi.AddIncoming(vals[i], bs) - } - } else { + for i, phi := range phis { + phi.AddIncoming(vals[i], bs) + } + } else */ + { vals := make([]llvm.Value, len(preds)) for iblk, blk := range preds { vals[iblk] = f(iblk, blk).impl @@ -556,24 +563,27 @@ func (p Phi) AddIncoming(b Builder, preds []BasicBlock, f func(i int, blk BasicB // Phi returns a phi node. func (b Builder) Phi(t Type) Phi { impl := b.impl - switch tund := t.raw.Type.Underlying().(type) { - case *types.Basic: - kind := tund.Kind() - switch kind { - case types.String: - phis := createStringPhis(impl, make([]llvm.Value, 0, 2), b.Prog) + /* + switch tund := t.raw.Type.Underlying().(type) { + case *types.Basic: + kind := tund.Kind() + switch kind { + case types.String: + phis := createStringPhis(impl, make([]llvm.Value, 0, 2), b.Prog) + return b.newPhi(t, phis) + } + case *types.Struct: + phis := createStrucPhis(impl, nil, tund, b.Prog) return b.newPhi(t, phis) + default: + log.Panicf("todo: %T\n", tund) } - case *types.Struct: - phis := createStrucPhis(impl, nil, tund, b.Prog) - return b.newPhi(t, phis) - default: - log.Panicf("todo: %T\n", tund) - } + */ phi := llvm.CreatePHI(impl, t.ll) - return &aPhi{Expr{phi, t}, nil} + return &aPhi{Expr{phi, t}} //, nil} } +/* func createStringPhis(b llvm.Builder, phis []llvm.Value, prog Program) []llvm.Value { phis = append(phis, llvm.CreatePHI(b, prog.tyVoidPtr())) return append(phis, llvm.CreatePHI(b, prog.tyInt())) @@ -611,6 +621,7 @@ func createBasicPhi(b llvm.Builder, phis []llvm.Value, t types.Type, prog Progra phi := llvm.CreatePHI(b, tll) return append(phis, phi) } +*/ // ----------------------------------------------------------------------------- diff --git a/ssa/interface.go b/ssa/interface.go index 696a782f..217d231a 100644 --- a/ssa/interface.go +++ b/ssa/interface.go @@ -59,10 +59,19 @@ func (b Builder) abiTypeOf(t types.Type) Expr { panic("todo") } +// func Named(pkgPath, name string, underlying *Type, methods []abi.Method) func (b Builder) abiNamedOf(t *types.Named) Expr { under := b.abiTypeOf(t.Underlying()) name := NameOf(t) - return b.Call(b.Pkg.rtFunc("Named"), b.Str(name), under) + + prog := b.Prog + pkg := b.Pkg + pkgPath := b.pkgName(pkg.Path()) + fn := pkg.rtFunc("Named") + tSlice := lastParamType(prog, fn) + // TODO(xsw): methods + methods := prog.Zero(tSlice) + return b.Call(fn, pkgPath, b.Str(name), under, methods) } func (b Builder) abiPointerOf(t *types.Pointer) Expr { @@ -70,7 +79,7 @@ func (b Builder) abiPointerOf(t *types.Pointer) Expr { return b.Call(b.Pkg.rtFunc("Pointer"), elem) } -// func Struct(size uintptr, pkgPath string, fields []abi.StructField) *abi.Type +// func Struct(pkgPath string, size uintptr, fields []abi.StructField) func (b Builder) abiStructOf(t *types.Struct) Expr { pkg := b.Pkg prog := b.Prog @@ -85,20 +94,23 @@ func (b Builder) abiStructOf(t *types.Struct) Expr { flds[i] = b.structField(sfAbi, prog, f, off, t.Tag(i)) } pkgPath := b.pkgName(pkg.Path()) - params := strucAbi.raw.Type.(*types.Signature).Params() - tSlice := prog.rawType(params.At(params.Len() - 1).Type().(*types.Slice)) + tSlice := lastParamType(prog, strucAbi) fldSlice := b.SliceLit(tSlice, flds...) size := prog.IntVal(prog.SizeOf(typ), prog.Uintptr()) return b.Call(strucAbi, pkgPath, size, fldSlice) } -// func StructField(name string, typ *abi.Type, off uintptr, tag string, exported, embedded bool) abi.StructField +func lastParamType(prog Program, fn Expr) Type { + params := fn.raw.Type.(*types.Signature).Params() + return prog.rawType(params.At(params.Len() - 1).Type()) +} + +// func StructField(name string, typ *abi.Type, off uintptr, tag string, embedded bool) abi.StructField func (b Builder) structField(sfAbi Expr, prog Program, f *types.Var, offset uintptr, tag string) Expr { name := b.Str(f.Name()) typ := b.abiType(f.Type()) - exported := prog.Val(f.Exported()) embedded := prog.Val(f.Embedded()) - return b.Call(sfAbi, name, typ, prog.Val(offset), b.Str(tag), exported, embedded) + return b.Call(sfAbi, name, typ, prog.Val(offset), b.Str(tag), embedded) } // abiType returns the abi type of the specified type.