diff --git a/chore/gentests/gentests.go b/chore/gentests/gentests.go index 2a8c2214..2eb83129 100644 --- a/chore/gentests/gentests.go +++ b/chore/gentests/gentests.go @@ -33,6 +33,7 @@ func main() { llgenDir(dir + "/cl/_testlibc") llgenDir(dir + "/cl/_testrt") + llgenDir(dir + "/cl/_testgo") llgenDir(dir+"/cl/_testpy", "") llgenDir(dir+"/cl/_testdata", "") } diff --git a/cl/_testdata/print/out.ll b/cl/_testdata/print/out.ll index 0e4003b5..27462d72 100644 --- a/cl/_testdata/print/out.ll +++ b/cl/_testdata/print/out.ll @@ -5,7 +5,7 @@ source_filename = "main" %"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 } %main.stringStruct = type { ptr, i64 } %main.slice = type { ptr, i64, i64 } -%"github.com/goplus/llgo/internal/runtime.iface" = type { ptr, ptr } +%"github.com/goplus/llgo/internal/runtime.eface" = type { ptr, ptr } @"main.init$guard" = global ptr null @main.minhexdigits = global ptr null @@ -104,127 +104,272 @@ _llgo_0: call void @main.prinfsub(double 1.001000e+02) call void @main.printnl() %6 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 13) - %7 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %6, i64 1315859240) - call void @main.printany(%"github.com/goplus/llgo/internal/runtime.iface" %7) + %7 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %7, i32 0, i32 0 + store ptr %6, ptr %8, align 8 + %9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %7, i32 0, i32 1 + store ptr inttoptr (i32 1315859240 to ptr), ptr %9, align 8 + %10 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %7, align 8 + call void @main.printany(%"github.com/goplus/llgo/internal/runtime.eface" %10) call void @main.printnl() - %8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 14) - %9 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %8, i64 4746175415993761792) - call void @main.printany(%"github.com/goplus/llgo/internal/runtime.iface" %9) + %11 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 14) + %12 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %13 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %12, i32 0, i32 0 + store ptr %11, ptr %13, align 8 + %14 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %12, i32 0, i32 1 + store ptr inttoptr (i64 4746175415993761792 to ptr), ptr %14, align 8 + %15 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %12, align 8 + call void @main.printany(%"github.com/goplus/llgo/internal/runtime.eface" %15) call void @main.printnl() br i1 true, label %_llgo_3, label %_llgo_2 _llgo_1: ; preds = %_llgo_3 - %10 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32) - %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %10, i64 0 - %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 @2, ptr %13, align 8 - %14 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %12, i32 0, i32 1 - store i64 10, ptr %14, align 4 - %15 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %12, align 8 - %16 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %15) - store %"github.com/goplus/llgo/internal/runtime.iface" %16, ptr %11, align 8 - %17 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %10, i64 1 - %18 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1) - %19 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %18, i64 -1) - store %"github.com/goplus/llgo/internal/runtime.iface" %19, ptr %17, align 8 - %20 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %10, i64 16, i64 2, i64 0, i64 2, i64 2) - call void @main.println(%"github.com/goplus/llgo/internal/runtime.Slice" %20) + %16 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32) + %17 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %16, i64 0 + %18 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %19 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %18, i32 0, i32 0 + store ptr @2, ptr %19, align 8 + %20 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %18, i32 0, i32 1 + store i64 10, ptr %20, align 4 + %21 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %18, align 8 + %22 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) + %23 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %21, ptr %23, align 8 + %24 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %25 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %24, i32 0, i32 0 + store ptr %22, ptr %25, align 8 + %26 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %24, i32 0, i32 1 + store ptr %23, ptr %26, align 8 + %27 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %24, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %27, ptr %17, align 8 + %28 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %16, i64 1 + %29 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1) + %30 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %31 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %30, i32 0, i32 0 + store ptr %29, ptr %31, align 8 + %32 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %30, i32 0, i32 1 + store ptr inttoptr (i64 -1 to ptr), ptr %32, align 8 + %33 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %30, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %33, ptr %28, align 8 + %34 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 + %35 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %34, i32 0, i32 0 + store ptr %16, ptr %35, align 8 + %36 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %34, i32 0, i32 1 + store i64 2, ptr %36, align 4 + %37 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %34, i32 0, i32 2 + store i64 2, ptr %37, align 4 + %38 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %34, align 8 + call void @main.println(%"github.com/goplus/llgo/internal/runtime.Slice" %38) br label %_llgo_2 _llgo_2: ; preds = %_llgo_3, %_llgo_1, %_llgo_0 - %21 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 48) - %22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %21, i64 0 - %23 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %24 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %23, i32 0, i32 0 - store ptr @3, ptr %24, align 8 - %25 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %23, i32 0, i32 1 - store i64 8, ptr %25, align 4 - %26 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %23, align 8 - %27 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %26) - store %"github.com/goplus/llgo/internal/runtime.iface" %27, ptr %22, align 8 - %28 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %21, i64 1 - %29 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1) - %30 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %29, i64 -1) - store %"github.com/goplus/llgo/internal/runtime.iface" %30, ptr %28, align 8 - %31 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %21, i64 2 - %32 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1) - %33 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %32, i64 -1) - store %"github.com/goplus/llgo/internal/runtime.iface" %33, ptr %31, align 8 - %34 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %21, i64 16, i64 3, i64 0, i64 3, i64 3) - call void @main.println(%"github.com/goplus/llgo/internal/runtime.Slice" %34) - %35 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 256) - %36 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %35, i64 0 - %37 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1) - %38 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %37, i64 -1) - store %"github.com/goplus/llgo/internal/runtime.iface" %38, ptr %36, align 8 - %39 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %35, i64 1 - %40 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1) - %41 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %40, i64 0) - store %"github.com/goplus/llgo/internal/runtime.iface" %41, ptr %39, align 8 - %42 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %35, i64 2 - %43 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5) - %44 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %43, i64 97) - store %"github.com/goplus/llgo/internal/runtime.iface" %44, ptr %42, align 8 - %45 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %35, i64 3 - %46 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5) - %47 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %46, i64 65) - store %"github.com/goplus/llgo/internal/runtime.iface" %47, ptr %45, align 8 - %48 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %35, i64 4 - %49 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5) - %50 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %49, i64 20013) - store %"github.com/goplus/llgo/internal/runtime.iface" %50, ptr %48, align 8 - %51 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %35, i64 5 - %52 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 3) - %53 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %52, i64 1) - store %"github.com/goplus/llgo/internal/runtime.iface" %53, ptr %51, align 8 - %54 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %35, i64 6 - %55 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 4) - %56 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %55, i64 2) - store %"github.com/goplus/llgo/internal/runtime.iface" %56, ptr %54, align 8 - %57 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %35, i64 7 - %58 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5) - %59 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %58, i64 3) - store %"github.com/goplus/llgo/internal/runtime.iface" %59, ptr %57, align 8 - %60 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %35, i64 8 - %61 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 6) - %62 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %61, i64 4) - store %"github.com/goplus/llgo/internal/runtime.iface" %62, ptr %60, align 8 - %63 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %35, i64 9 - %64 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2) - %65 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %64, i64 5) - store %"github.com/goplus/llgo/internal/runtime.iface" %65, ptr %63, align 8 - %66 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %35, i64 10 - %67 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 8) - %68 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %67, i64 1) - store %"github.com/goplus/llgo/internal/runtime.iface" %68, ptr %66, align 8 - %69 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %35, i64 11 - %70 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 9) - %71 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %70, i64 2) - store %"github.com/goplus/llgo/internal/runtime.iface" %71, ptr %69, align 8 - %72 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %35, i64 12 - %73 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 10) - %74 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %73, i64 3) - store %"github.com/goplus/llgo/internal/runtime.iface" %74, ptr %72, align 8 - %75 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %35, i64 13 - %76 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 11) - %77 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %76, i64 4) - store %"github.com/goplus/llgo/internal/runtime.iface" %77, ptr %75, align 8 - %78 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %35, i64 14 - %79 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 12) - %80 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %79, i64 5) - store %"github.com/goplus/llgo/internal/runtime.iface" %80, ptr %78, align 8 - %81 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %35, i64 15 - %82 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %83 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %82, i32 0, i32 0 - store ptr @4, ptr %83, align 8 - %84 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %82, i32 0, i32 1 - store i64 4, ptr %84, align 4 - %85 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %82, align 8 - %86 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %85) - store %"github.com/goplus/llgo/internal/runtime.iface" %86, ptr %81, align 8 - %87 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %35, i64 16, i64 16, i64 0, i64 16, i64 16) - call void @main.println(%"github.com/goplus/llgo/internal/runtime.Slice" %87) + %39 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 48) + %40 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %39, i64 0 + %41 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %42 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %41, i32 0, i32 0 + store ptr @3, ptr %42, align 8 + %43 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %41, i32 0, i32 1 + store i64 8, ptr %43, align 4 + %44 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %41, align 8 + %45 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) + %46 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %44, ptr %46, align 8 + %47 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %48 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %47, i32 0, i32 0 + store ptr %45, ptr %48, align 8 + %49 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %47, i32 0, i32 1 + store ptr %46, ptr %49, align 8 + %50 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %47, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %50, ptr %40, align 8 + %51 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %39, i64 1 + %52 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1) + %53 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %54 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %53, i32 0, i32 0 + store ptr %52, ptr %54, align 8 + %55 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %53, i32 0, i32 1 + store ptr inttoptr (i64 -1 to ptr), ptr %55, align 8 + %56 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %53, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %56, ptr %51, align 8 + %57 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %39, i64 2 + %58 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1) + %59 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %60 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %59, i32 0, i32 0 + store ptr %58, ptr %60, align 8 + %61 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %59, i32 0, i32 1 + store ptr inttoptr (i64 -1 to ptr), ptr %61, align 8 + %62 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %59, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %62, ptr %57, align 8 + %63 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 + %64 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %63, i32 0, i32 0 + store ptr %39, ptr %64, align 8 + %65 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %63, i32 0, i32 1 + store i64 3, ptr %65, align 4 + %66 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %63, i32 0, i32 2 + store i64 3, ptr %66, align 4 + %67 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %63, align 8 + call void @main.println(%"github.com/goplus/llgo/internal/runtime.Slice" %67) + %68 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 256) + %69 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i64 0 + %70 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1) + %71 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %72 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %71, i32 0, i32 0 + store ptr %70, ptr %72, align 8 + %73 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %71, i32 0, i32 1 + store ptr inttoptr (i64 -1 to ptr), ptr %73, align 8 + %74 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %71, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %74, ptr %69, align 8 + %75 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i64 1 + %76 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1) + %77 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %78 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %77, i32 0, i32 0 + store ptr %76, ptr %78, align 8 + %79 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %77, i32 0, i32 1 + store ptr null, ptr %79, align 8 + %80 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %77, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %80, ptr %75, align 8 + %81 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i64 2 + %82 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5) + %83 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %84 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %83, i32 0, i32 0 + store ptr %82, ptr %84, align 8 + %85 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %83, i32 0, i32 1 + store ptr inttoptr (i64 97 to ptr), ptr %85, align 8 + %86 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %83, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %86, ptr %81, align 8 + %87 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i64 3 + %88 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5) + %89 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %90 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %89, i32 0, i32 0 + store ptr %88, ptr %90, align 8 + %91 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %89, i32 0, i32 1 + store ptr inttoptr (i64 65 to ptr), ptr %91, align 8 + %92 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %89, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %92, ptr %87, align 8 + %93 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i64 4 + %94 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5) + %95 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %96 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %95, i32 0, i32 0 + store ptr %94, ptr %96, align 8 + %97 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %95, i32 0, i32 1 + store ptr inttoptr (i64 20013 to ptr), ptr %97, align 8 + %98 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %95, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %98, ptr %93, align 8 + %99 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i64 5 + %100 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 3) + %101 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %102 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %101, i32 0, i32 0 + store ptr %100, ptr %102, align 8 + %103 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %101, i32 0, i32 1 + store ptr inttoptr (i64 1 to ptr), ptr %103, align 8 + %104 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %101, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %104, ptr %99, align 8 + %105 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i64 6 + %106 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 4) + %107 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %108 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %107, i32 0, i32 0 + store ptr %106, ptr %108, align 8 + %109 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %107, i32 0, i32 1 + store ptr inttoptr (i64 2 to ptr), ptr %109, align 8 + %110 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %107, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %110, ptr %105, align 8 + %111 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i64 7 + %112 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5) + %113 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %114 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %113, i32 0, i32 0 + store ptr %112, ptr %114, align 8 + %115 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %113, i32 0, i32 1 + store ptr inttoptr (i64 3 to ptr), ptr %115, align 8 + %116 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %113, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %116, ptr %111, align 8 + %117 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i64 8 + %118 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 6) + %119 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %120 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %119, i32 0, i32 0 + store ptr %118, ptr %120, align 8 + %121 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %119, i32 0, i32 1 + store ptr inttoptr (i64 4 to ptr), ptr %121, align 8 + %122 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %119, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %122, ptr %117, align 8 + %123 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i64 9 + %124 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2) + %125 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %126 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %125, i32 0, i32 0 + store ptr %124, ptr %126, align 8 + %127 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %125, i32 0, i32 1 + store ptr inttoptr (i64 5 to ptr), ptr %127, align 8 + %128 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %125, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %128, ptr %123, align 8 + %129 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i64 10 + %130 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 8) + %131 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %132 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %131, i32 0, i32 0 + store ptr %130, ptr %132, align 8 + %133 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %131, i32 0, i32 1 + store ptr inttoptr (i64 1 to ptr), ptr %133, align 8 + %134 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %131, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %134, ptr %129, align 8 + %135 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i64 11 + %136 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 9) + %137 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %138 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %137, i32 0, i32 0 + store ptr %136, ptr %138, align 8 + %139 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %137, i32 0, i32 1 + store ptr inttoptr (i64 2 to ptr), ptr %139, align 8 + %140 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %137, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %140, ptr %135, align 8 + %141 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i64 12 + %142 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 10) + %143 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %144 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %143, i32 0, i32 0 + store ptr %142, ptr %144, align 8 + %145 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %143, i32 0, i32 1 + store ptr inttoptr (i64 3 to ptr), ptr %145, align 8 + %146 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %143, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %146, ptr %141, align 8 + %147 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i64 13 + %148 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 11) + %149 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %150 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %149, i32 0, i32 0 + store ptr %148, ptr %150, align 8 + %151 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %149, i32 0, i32 1 + store ptr inttoptr (i64 4 to ptr), ptr %151, align 8 + %152 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %149, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %152, ptr %147, align 8 + %153 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i64 14 + %154 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 12) + %155 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %156 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %155, i32 0, i32 0 + store ptr %154, ptr %156, align 8 + %157 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %155, i32 0, i32 1 + store ptr inttoptr (i64 5 to ptr), ptr %157, align 8 + %158 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %155, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %158, ptr %153, align 8 + %159 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i64 15 + %160 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %161 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %160, i32 0, i32 0 + store ptr @4, ptr %161, align 8 + %162 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %160, i32 0, i32 1 + store i64 4, ptr %162, align 4 + %163 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %160, align 8 + %164 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) + %165 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %163, ptr %165, align 8 + %166 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %167 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %166, i32 0, i32 0 + store ptr %164, ptr %167, align 8 + %168 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %166, i32 0, i32 1 + store ptr %165, ptr %168, align 8 + %169 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %166, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %169, ptr %159, align 8 + %170 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 + %171 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %170, i32 0, i32 0 + store ptr %68, ptr %171, align 8 + %172 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %170, i32 0, i32 1 + store i64 16, ptr %172, align 4 + %173 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %170, i32 0, i32 2 + store i64 16, ptr %173, align 4 + %174 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %170, align 8 + call void @main.println(%"github.com/goplus/llgo/internal/runtime.Slice" %174) ret i32 0 _llgo_3: ; preds = %_llgo_0 @@ -245,190 +390,430 @@ _llgo_0: ret void } -define void @main.printany(%"github.com/goplus/llgo/internal/runtime.iface" %0) { +define void @main.printany(%"github.com/goplus/llgo/internal/runtime.eface" %0) { _llgo_0: - %1 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1) - %2 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %1) - %3 = extractvalue { i64, i1 } %2, 0 - %4 = trunc i64 %3 to i1 - %5 = extractvalue { i64, i1 } %2, 1 - br i1 %5, label %_llgo_2, label %_llgo_3 + %1 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 + %2 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 1) + %3 = icmp eq ptr %1, %2 + %4 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1 + %5 = ptrtoint ptr %4 to i64 + %6 = trunc i64 %5 to i1 + %7 = alloca { i1, i1 }, align 8 + %8 = getelementptr inbounds { i1, i1 }, ptr %7, i32 0, i32 0 + store i1 %6, ptr %8, align 1 + %9 = getelementptr inbounds { i1, i1 }, ptr %7, i32 0, i32 1 + store i1 true, ptr %9, align 1 + %10 = load { i1, i1 }, ptr %7, align 1 + %11 = alloca { i1, i1 }, align 8 + %12 = getelementptr inbounds { i1, i1 }, ptr %11, i32 0, i32 0 + store i1 false, ptr %12, align 1 + %13 = getelementptr inbounds { i1, i1 }, ptr %11, i32 0, i32 1 + store i1 false, ptr %13, align 1 + %14 = load { i1, i1 }, ptr %11, align 1 + %15 = select i1 %3, { i1, i1 } %10, { i1, i1 } %14 + %16 = extractvalue { i1, i1 } %15, 0 + %17 = extractvalue { i1, i1 } %15, 1 + br i1 %17, label %_llgo_2, label %_llgo_3 _llgo_1: ; preds = %_llgo_30, %_llgo_29, %_llgo_28, %_llgo_26, %_llgo_24, %_llgo_22, %_llgo_20, %_llgo_18, %_llgo_16, %_llgo_14, %_llgo_12, %_llgo_10, %_llgo_8, %_llgo_6, %_llgo_4, %_llgo_2 ret void _llgo_2: ; preds = %_llgo_0 - call void @main.printbool(i1 %4) + call void @main.printbool(i1 %16) br label %_llgo_1 _llgo_3: ; preds = %_llgo_0 - %6 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2) - %7 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %6) - %8 = extractvalue { i64, i1 } %7, 0 - %9 = extractvalue { i64, i1 } %7, 1 - br i1 %9, label %_llgo_4, label %_llgo_5 + %18 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 + %19 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2) + %20 = icmp eq ptr %18, %19 + %21 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1 + %22 = ptrtoint ptr %21 to i64 + %23 = alloca { i64, i1 }, align 8 + %24 = getelementptr inbounds { i64, i1 }, ptr %23, i32 0, i32 0 + store i64 %22, ptr %24, align 4 + %25 = getelementptr inbounds { i64, i1 }, ptr %23, i32 0, i32 1 + store i1 true, ptr %25, align 1 + %26 = load { i64, i1 }, ptr %23, align 4 + %27 = alloca { i64, i1 }, align 8 + %28 = getelementptr inbounds { i64, i1 }, ptr %27, i32 0, i32 0 + store i64 0, ptr %28, align 4 + %29 = getelementptr inbounds { i64, i1 }, ptr %27, i32 0, i32 1 + store i1 false, ptr %29, align 1 + %30 = load { i64, i1 }, ptr %27, align 4 + %31 = select i1 %20, { i64, i1 } %26, { i64, i1 } %30 + %32 = extractvalue { i64, i1 } %31, 0 + %33 = extractvalue { i64, i1 } %31, 1 + br i1 %33, label %_llgo_4, label %_llgo_5 _llgo_4: ; preds = %_llgo_3 - call void @main.printint(i64 %8) + call void @main.printint(i64 %32) br label %_llgo_1 _llgo_5: ; preds = %_llgo_3 - %10 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 3) - %11 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %10) - %12 = extractvalue { i64, i1 } %11, 0 - %13 = trunc i64 %12 to i8 - %14 = extractvalue { i64, i1 } %11, 1 - br i1 %14, label %_llgo_6, label %_llgo_7 + %34 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 + %35 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 3) + %36 = icmp eq ptr %34, %35 + %37 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1 + %38 = ptrtoint ptr %37 to i64 + %39 = trunc i64 %38 to i8 + %40 = alloca { i8, i1 }, align 8 + %41 = getelementptr inbounds { i8, i1 }, ptr %40, i32 0, i32 0 + store i8 %39, ptr %41, align 1 + %42 = getelementptr inbounds { i8, i1 }, ptr %40, i32 0, i32 1 + store i1 true, ptr %42, align 1 + %43 = load { i8, i1 }, ptr %40, align 1 + %44 = alloca { i8, i1 }, align 8 + %45 = getelementptr inbounds { i8, i1 }, ptr %44, i32 0, i32 0 + store i8 0, ptr %45, align 1 + %46 = getelementptr inbounds { i8, i1 }, ptr %44, i32 0, i32 1 + store i1 false, ptr %46, align 1 + %47 = load { i8, i1 }, ptr %44, align 1 + %48 = select i1 %36, { i8, i1 } %43, { i8, i1 } %47 + %49 = extractvalue { i8, i1 } %48, 0 + %50 = extractvalue { i8, i1 } %48, 1 + br i1 %50, label %_llgo_6, label %_llgo_7 _llgo_6: ; preds = %_llgo_5 - %15 = sext i8 %13 to i64 - call void @main.printint(i64 %15) + %51 = sext i8 %49 to i64 + call void @main.printint(i64 %51) br label %_llgo_1 _llgo_7: ; preds = %_llgo_5 - %16 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 4) - %17 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %16) - %18 = extractvalue { i64, i1 } %17, 0 - %19 = trunc i64 %18 to i16 - %20 = extractvalue { i64, i1 } %17, 1 - br i1 %20, label %_llgo_8, label %_llgo_9 + %52 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 + %53 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 4) + %54 = icmp eq ptr %52, %53 + %55 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1 + %56 = ptrtoint ptr %55 to i64 + %57 = trunc i64 %56 to i16 + %58 = alloca { i16, i1 }, align 8 + %59 = getelementptr inbounds { i16, i1 }, ptr %58, i32 0, i32 0 + store i16 %57, ptr %59, align 2 + %60 = getelementptr inbounds { i16, i1 }, ptr %58, i32 0, i32 1 + store i1 true, ptr %60, align 1 + %61 = load { i16, i1 }, ptr %58, align 2 + %62 = alloca { i16, i1 }, align 8 + %63 = getelementptr inbounds { i16, i1 }, ptr %62, i32 0, i32 0 + store i16 0, ptr %63, align 2 + %64 = getelementptr inbounds { i16, i1 }, ptr %62, i32 0, i32 1 + store i1 false, ptr %64, align 1 + %65 = load { i16, i1 }, ptr %62, align 2 + %66 = select i1 %54, { i16, i1 } %61, { i16, i1 } %65 + %67 = extractvalue { i16, i1 } %66, 0 + %68 = extractvalue { i16, i1 } %66, 1 + br i1 %68, label %_llgo_8, label %_llgo_9 _llgo_8: ; preds = %_llgo_7 - %21 = sext i16 %19 to i64 - call void @main.printint(i64 %21) + %69 = sext i16 %67 to i64 + call void @main.printint(i64 %69) br label %_llgo_1 _llgo_9: ; preds = %_llgo_7 - %22 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5) - %23 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %22) - %24 = extractvalue { i64, i1 } %23, 0 - %25 = trunc i64 %24 to i32 - %26 = extractvalue { i64, i1 } %23, 1 - br i1 %26, label %_llgo_10, label %_llgo_11 + %70 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 + %71 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 5) + %72 = icmp eq ptr %70, %71 + %73 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1 + %74 = ptrtoint ptr %73 to i64 + %75 = trunc i64 %74 to i32 + %76 = alloca { i32, i1 }, align 8 + %77 = getelementptr inbounds { i32, i1 }, ptr %76, i32 0, i32 0 + store i32 %75, ptr %77, align 4 + %78 = getelementptr inbounds { i32, i1 }, ptr %76, i32 0, i32 1 + store i1 true, ptr %78, align 1 + %79 = load { i32, i1 }, ptr %76, align 4 + %80 = alloca { i32, i1 }, align 8 + %81 = getelementptr inbounds { i32, i1 }, ptr %80, i32 0, i32 0 + store i32 0, ptr %81, align 4 + %82 = getelementptr inbounds { i32, i1 }, ptr %80, i32 0, i32 1 + store i1 false, ptr %82, align 1 + %83 = load { i32, i1 }, ptr %80, align 4 + %84 = select i1 %72, { i32, i1 } %79, { i32, i1 } %83 + %85 = extractvalue { i32, i1 } %84, 0 + %86 = extractvalue { i32, i1 } %84, 1 + br i1 %86, label %_llgo_10, label %_llgo_11 _llgo_10: ; preds = %_llgo_9 - %27 = sext i32 %25 to i64 - call void @main.printint(i64 %27) + %87 = sext i32 %85 to i64 + call void @main.printint(i64 %87) br label %_llgo_1 _llgo_11: ; preds = %_llgo_9 - %28 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 6) - %29 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %28) - %30 = extractvalue { i64, i1 } %29, 0 - %31 = extractvalue { i64, i1 } %29, 1 - br i1 %31, label %_llgo_12, label %_llgo_13 + %88 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 + %89 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 6) + %90 = icmp eq ptr %88, %89 + %91 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1 + %92 = ptrtoint ptr %91 to i64 + %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 = alloca { i64, i1 }, align 8 + %98 = getelementptr inbounds { i64, i1 }, ptr %97, i32 0, i32 0 + store i64 0, ptr %98, align 4 + %99 = getelementptr inbounds { i64, i1 }, ptr %97, i32 0, i32 1 + store i1 false, ptr %99, align 1 + %100 = load { i64, i1 }, ptr %97, align 4 + %101 = select i1 %90, { i64, i1 } %96, { i64, i1 } %100 + %102 = extractvalue { i64, i1 } %101, 0 + %103 = extractvalue { i64, i1 } %101, 1 + br i1 %103, label %_llgo_12, label %_llgo_13 _llgo_12: ; preds = %_llgo_11 - call void @main.printint(i64 %30) + call void @main.printint(i64 %102) br label %_llgo_1 _llgo_13: ; preds = %_llgo_11 - %32 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 7) - %33 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %32) - %34 = extractvalue { i64, i1 } %33, 0 - %35 = extractvalue { i64, i1 } %33, 1 - br i1 %35, label %_llgo_14, label %_llgo_15 + %104 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 + %105 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 7) + %106 = icmp eq ptr %104, %105 + %107 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1 + %108 = ptrtoint ptr %107 to i64 + %109 = alloca { i64, i1 }, align 8 + %110 = getelementptr inbounds { i64, i1 }, ptr %109, i32 0, i32 0 + store i64 %108, ptr %110, align 4 + %111 = getelementptr inbounds { i64, i1 }, ptr %109, i32 0, i32 1 + store i1 true, ptr %111, align 1 + %112 = load { i64, i1 }, ptr %109, align 4 + %113 = alloca { i64, i1 }, align 8 + %114 = getelementptr inbounds { i64, i1 }, ptr %113, i32 0, i32 0 + store i64 0, ptr %114, align 4 + %115 = getelementptr inbounds { i64, i1 }, ptr %113, i32 0, i32 1 + store i1 false, ptr %115, align 1 + %116 = load { i64, i1 }, ptr %113, align 4 + %117 = select i1 %106, { i64, i1 } %112, { i64, i1 } %116 + %118 = extractvalue { i64, i1 } %117, 0 + %119 = extractvalue { i64, i1 } %117, 1 + br i1 %119, label %_llgo_14, label %_llgo_15 _llgo_14: ; preds = %_llgo_13 - call void @main.printuint(i64 %34) + call void @main.printuint(i64 %118) br label %_llgo_1 _llgo_15: ; preds = %_llgo_13 - %36 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 8) - %37 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %36) - %38 = extractvalue { i64, i1 } %37, 0 - %39 = trunc i64 %38 to i8 - %40 = extractvalue { i64, i1 } %37, 1 - br i1 %40, label %_llgo_16, label %_llgo_17 + %120 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 + %121 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 8) + %122 = icmp eq ptr %120, %121 + %123 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1 + %124 = ptrtoint ptr %123 to i64 + %125 = trunc i64 %124 to i8 + %126 = alloca { i8, i1 }, align 8 + %127 = getelementptr inbounds { i8, i1 }, ptr %126, i32 0, i32 0 + store i8 %125, ptr %127, align 1 + %128 = getelementptr inbounds { i8, i1 }, ptr %126, i32 0, i32 1 + store i1 true, ptr %128, align 1 + %129 = load { i8, i1 }, ptr %126, align 1 + %130 = alloca { i8, i1 }, align 8 + %131 = getelementptr inbounds { i8, i1 }, ptr %130, i32 0, i32 0 + store i8 0, ptr %131, align 1 + %132 = getelementptr inbounds { i8, i1 }, ptr %130, i32 0, i32 1 + store i1 false, ptr %132, align 1 + %133 = load { i8, i1 }, ptr %130, align 1 + %134 = select i1 %122, { i8, i1 } %129, { i8, i1 } %133 + %135 = extractvalue { i8, i1 } %134, 0 + %136 = extractvalue { i8, i1 } %134, 1 + br i1 %136, label %_llgo_16, label %_llgo_17 _llgo_16: ; preds = %_llgo_15 - %41 = zext i8 %39 to i64 - call void @main.printuint(i64 %41) + %137 = zext i8 %135 to i64 + call void @main.printuint(i64 %137) br label %_llgo_1 _llgo_17: ; preds = %_llgo_15 - %42 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 9) - %43 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %42) - %44 = extractvalue { i64, i1 } %43, 0 - %45 = trunc i64 %44 to i16 - %46 = extractvalue { i64, i1 } %43, 1 - br i1 %46, label %_llgo_18, label %_llgo_19 + %138 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 + %139 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 9) + %140 = icmp eq ptr %138, %139 + %141 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1 + %142 = ptrtoint ptr %141 to i64 + %143 = trunc i64 %142 to i16 + %144 = alloca { i16, i1 }, align 8 + %145 = getelementptr inbounds { i16, i1 }, ptr %144, i32 0, i32 0 + store i16 %143, ptr %145, align 2 + %146 = getelementptr inbounds { i16, i1 }, ptr %144, i32 0, i32 1 + store i1 true, ptr %146, align 1 + %147 = load { i16, i1 }, ptr %144, align 2 + %148 = alloca { i16, i1 }, align 8 + %149 = getelementptr inbounds { i16, i1 }, ptr %148, i32 0, i32 0 + store i16 0, ptr %149, align 2 + %150 = getelementptr inbounds { i16, i1 }, ptr %148, i32 0, i32 1 + store i1 false, ptr %150, align 1 + %151 = load { i16, i1 }, ptr %148, align 2 + %152 = select i1 %140, { i16, i1 } %147, { i16, i1 } %151 + %153 = extractvalue { i16, i1 } %152, 0 + %154 = extractvalue { i16, i1 } %152, 1 + br i1 %154, label %_llgo_18, label %_llgo_19 _llgo_18: ; preds = %_llgo_17 - %47 = zext i16 %45 to i64 - call void @main.printuint(i64 %47) + %155 = zext i16 %153 to i64 + call void @main.printuint(i64 %155) br label %_llgo_1 _llgo_19: ; preds = %_llgo_17 - %48 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 10) - %49 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %48) - %50 = extractvalue { i64, i1 } %49, 0 - %51 = trunc i64 %50 to i32 - %52 = extractvalue { i64, i1 } %49, 1 - br i1 %52, label %_llgo_20, label %_llgo_21 + %156 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 + %157 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 10) + %158 = icmp eq ptr %156, %157 + %159 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1 + %160 = ptrtoint ptr %159 to i64 + %161 = trunc i64 %160 to i32 + %162 = alloca { i32, i1 }, align 8 + %163 = getelementptr inbounds { i32, i1 }, ptr %162, i32 0, i32 0 + store i32 %161, ptr %163, align 4 + %164 = getelementptr inbounds { i32, i1 }, ptr %162, i32 0, i32 1 + store i1 true, ptr %164, align 1 + %165 = load { i32, i1 }, ptr %162, align 4 + %166 = alloca { i32, i1 }, align 8 + %167 = getelementptr inbounds { i32, i1 }, ptr %166, i32 0, i32 0 + store i32 0, ptr %167, align 4 + %168 = getelementptr inbounds { i32, i1 }, ptr %166, i32 0, i32 1 + store i1 false, ptr %168, align 1 + %169 = load { i32, i1 }, ptr %166, align 4 + %170 = select i1 %158, { i32, i1 } %165, { i32, i1 } %169 + %171 = extractvalue { i32, i1 } %170, 0 + %172 = extractvalue { i32, i1 } %170, 1 + br i1 %172, label %_llgo_20, label %_llgo_21 _llgo_20: ; preds = %_llgo_19 - %53 = zext i32 %51 to i64 - call void @main.printuint(i64 %53) + %173 = zext i32 %171 to i64 + call void @main.printuint(i64 %173) br label %_llgo_1 _llgo_21: ; preds = %_llgo_19 - %54 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 11) - %55 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %54) - %56 = extractvalue { i64, i1 } %55, 0 - %57 = extractvalue { i64, i1 } %55, 1 - br i1 %57, label %_llgo_22, label %_llgo_23 + %174 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 + %175 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 11) + %176 = icmp eq ptr %174, %175 + %177 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1 + %178 = ptrtoint ptr %177 to i64 + %179 = alloca { i64, i1 }, align 8 + %180 = getelementptr inbounds { i64, i1 }, ptr %179, i32 0, i32 0 + store i64 %178, ptr %180, align 4 + %181 = getelementptr inbounds { i64, i1 }, ptr %179, i32 0, i32 1 + store i1 true, ptr %181, align 1 + %182 = load { i64, i1 }, ptr %179, align 4 + %183 = alloca { i64, i1 }, align 8 + %184 = getelementptr inbounds { i64, i1 }, ptr %183, i32 0, i32 0 + store i64 0, ptr %184, align 4 + %185 = getelementptr inbounds { i64, i1 }, ptr %183, i32 0, i32 1 + store i1 false, ptr %185, align 1 + %186 = load { i64, i1 }, ptr %183, align 4 + %187 = select i1 %176, { i64, i1 } %182, { i64, i1 } %186 + %188 = extractvalue { i64, i1 } %187, 0 + %189 = extractvalue { i64, i1 } %187, 1 + br i1 %189, label %_llgo_22, label %_llgo_23 _llgo_22: ; preds = %_llgo_21 - call void @main.printuint(i64 %56) + call void @main.printuint(i64 %188) br label %_llgo_1 _llgo_23: ; preds = %_llgo_21 - %58 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 12) - %59 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %58) - %60 = extractvalue { i64, i1 } %59, 0 - %61 = extractvalue { i64, i1 } %59, 1 - br i1 %61, label %_llgo_24, label %_llgo_25 + %190 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 + %191 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 12) + %192 = icmp eq ptr %190, %191 + %193 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1 + %194 = ptrtoint ptr %193 to i64 + %195 = alloca { i64, i1 }, align 8 + %196 = getelementptr inbounds { i64, i1 }, ptr %195, i32 0, i32 0 + store i64 %194, ptr %196, align 4 + %197 = getelementptr inbounds { i64, i1 }, ptr %195, i32 0, i32 1 + store i1 true, ptr %197, align 1 + %198 = load { i64, i1 }, ptr %195, align 4 + %199 = alloca { i64, i1 }, align 8 + %200 = getelementptr inbounds { i64, i1 }, ptr %199, i32 0, i32 0 + store i64 0, ptr %200, align 4 + %201 = getelementptr inbounds { i64, i1 }, ptr %199, i32 0, i32 1 + store i1 false, ptr %201, align 1 + %202 = load { i64, i1 }, ptr %199, align 4 + %203 = select i1 %192, { i64, i1 } %198, { i64, i1 } %202 + %204 = extractvalue { i64, i1 } %203, 0 + %205 = extractvalue { i64, i1 } %203, 1 + br i1 %205, label %_llgo_24, label %_llgo_25 _llgo_24: ; preds = %_llgo_23 - call void @main.printuint(i64 %60) + call void @main.printuint(i64 %204) br label %_llgo_1 _llgo_25: ; preds = %_llgo_23 - %62 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 13) - %63 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %62) - %64 = extractvalue { i64, i1 } %63, 0 - %65 = trunc i64 %64 to i32 - %66 = bitcast i32 %65 to float - %67 = extractvalue { i64, i1 } %63, 1 - br i1 %67, label %_llgo_26, label %_llgo_27 + %206 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 + %207 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 13) + %208 = icmp eq ptr %206, %207 + %209 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1 + %210 = ptrtoint ptr %209 to i64 + %211 = trunc i64 %210 to i32 + %212 = bitcast i32 %211 to float + %213 = alloca { float, i1 }, align 8 + %214 = getelementptr inbounds { float, i1 }, ptr %213, i32 0, i32 0 + store float %212, ptr %214, align 4 + %215 = getelementptr inbounds { float, i1 }, ptr %213, i32 0, i32 1 + store i1 true, ptr %215, align 1 + %216 = load { float, i1 }, ptr %213, align 4 + %217 = alloca { float, i1 }, align 8 + %218 = getelementptr inbounds { float, i1 }, ptr %217, i32 0, i32 0 + store double 0.000000e+00, ptr %218, align 8 + %219 = getelementptr inbounds { float, i1 }, ptr %217, i32 0, i32 1 + store i1 false, ptr %219, align 1 + %220 = load { float, i1 }, ptr %217, align 4 + %221 = select i1 %208, { float, i1 } %216, { float, i1 } %220 + %222 = extractvalue { float, i1 } %221, 0 + %223 = extractvalue { float, i1 } %221, 1 + br i1 %223, label %_llgo_26, label %_llgo_27 _llgo_26: ; preds = %_llgo_25 - %68 = fpext float %66 to double - call void @main.printfloat(double %68) + %224 = fpext float %222 to double + call void @main.printfloat(double %224) br label %_llgo_1 _llgo_27: ; preds = %_llgo_25 - %69 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 14) - %70 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %69) - %71 = extractvalue { i64, i1 } %70, 0 - %72 = bitcast i64 %71 to double - %73 = extractvalue { i64, i1 } %70, 1 - br i1 %73, label %_llgo_28, label %_llgo_29 + %225 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 + %226 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 14) + %227 = icmp eq ptr %225, %226 + %228 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1 + %229 = ptrtoint ptr %228 to i64 + %230 = bitcast i64 %229 to double + %231 = alloca { double, i1 }, align 8 + %232 = getelementptr inbounds { double, i1 }, ptr %231, i32 0, i32 0 + store double %230, ptr %232, align 8 + %233 = getelementptr inbounds { double, i1 }, ptr %231, i32 0, i32 1 + store i1 true, ptr %233, align 1 + %234 = load { double, i1 }, ptr %231, align 8 + %235 = alloca { double, i1 }, align 8 + %236 = getelementptr inbounds { double, i1 }, ptr %235, i32 0, i32 0 + store double 0.000000e+00, ptr %236, align 8 + %237 = getelementptr inbounds { double, i1 }, ptr %235, i32 0, i32 1 + store i1 false, ptr %237, align 1 + %238 = load { double, i1 }, ptr %235, align 8 + %239 = select i1 %227, { double, i1 } %234, { double, i1 } %238 + %240 = extractvalue { double, i1 } %239, 0 + %241 = extractvalue { double, i1 } %239, 1 + br i1 %241, label %_llgo_28, label %_llgo_29 _llgo_28: ; preds = %_llgo_27 - call void @main.printfloat(double %72) + call void @main.printfloat(double %240) br label %_llgo_1 _llgo_29: ; preds = %_llgo_27 - %74 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) - %75 = call { %"github.com/goplus/llgo/internal/runtime.String", i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2String"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %74) - %76 = extractvalue { %"github.com/goplus/llgo/internal/runtime.String", i1 } %75, 0 - %77 = extractvalue { %"github.com/goplus/llgo/internal/runtime.String", i1 } %75, 1 - br i1 %77, label %_llgo_30, label %_llgo_1 + %242 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 + %243 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) + %244 = icmp eq ptr %242, %243 + %245 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 1 + %246 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %245, align 8 + %247 = alloca { %"github.com/goplus/llgo/internal/runtime.String", i1 }, align 8 + %248 = getelementptr inbounds { %"github.com/goplus/llgo/internal/runtime.String", i1 }, ptr %247, i32 0, i32 0 + store %"github.com/goplus/llgo/internal/runtime.String" %246, ptr %248, align 8 + %249 = getelementptr inbounds { %"github.com/goplus/llgo/internal/runtime.String", i1 }, ptr %247, i32 0, i32 1 + store i1 true, ptr %249, align 1 + %250 = load { %"github.com/goplus/llgo/internal/runtime.String", i1 }, ptr %247, align 8 + %251 = alloca { %"github.com/goplus/llgo/internal/runtime.String", i1 }, align 8 + %252 = getelementptr inbounds { %"github.com/goplus/llgo/internal/runtime.String", i1 }, ptr %251, i32 0, i32 0 + store { ptr, i64 } zeroinitializer, ptr %252, align 8 + %253 = getelementptr inbounds { %"github.com/goplus/llgo/internal/runtime.String", i1 }, ptr %251, i32 0, i32 1 + store i1 false, ptr %253, align 1 + %254 = load { %"github.com/goplus/llgo/internal/runtime.String", i1 }, ptr %251, align 8 + %255 = select i1 %244, { %"github.com/goplus/llgo/internal/runtime.String", i1 } %250, { %"github.com/goplus/llgo/internal/runtime.String", i1 } %254 + %256 = extractvalue { %"github.com/goplus/llgo/internal/runtime.String", i1 } %255, 0 + %257 = extractvalue { %"github.com/goplus/llgo/internal/runtime.String", i1 } %255, 1 + br i1 %257, label %_llgo_30, label %_llgo_1 _llgo_30: ; preds = %_llgo_29 - call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %76) + call void @main.printstring(%"github.com/goplus/llgo/internal/runtime.String" %256) br label %_llgo_1 } @@ -658,8 +1043,15 @@ _llgo_29: ; preds = %_llgo_28, %_llgo_26 %86 = add i8 %85, 48 %87 = getelementptr inbounds i8, ptr %20, i64 13 store i8 %86, ptr %87, align 1 - %88 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %20, i64 1, i64 14, i64 0, i64 14, i64 14) - call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %88) + %88 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 + %89 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %88, i32 0, i32 0 + store ptr %20, ptr %89, align 8 + %90 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %88, i32 0, i32 1 + store i64 14, ptr %90, align 4 + %91 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %88, i32 0, i32 2 + store i64 14, ptr %91, align 4 + %92 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %88, align 8 + call void @main.gwrite(%"github.com/goplus/llgo/internal/runtime.Slice" %92) ret void } @@ -756,8 +1148,8 @@ _llgo_2: ; preds = %_llgo_1 %5 = icmp slt i64 %3, 0 call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %5) %6 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0 - %7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %6, i64 %3 - %8 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %7, align 8 + %7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %6, i64 %3 + %8 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %7, align 8 %9 = icmp ne i64 %3, 0 br i1 %9, label %_llgo_4, label %_llgo_5 @@ -776,7 +1168,7 @@ _llgo_4: ; preds = %_llgo_2 br label %_llgo_5 _llgo_5: ; preds = %_llgo_4, %_llgo_2 - call void @main.printany(%"github.com/goplus/llgo/internal/runtime.iface" %8) + call void @main.printany(%"github.com/goplus/llgo/internal/runtime.eface" %8) br label %_llgo_1 } @@ -869,16 +1261,10 @@ declare i32 @printf(ptr, ...) declare void @"github.com/goplus/llgo/internal/runtime.init"() -declare %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr, i64) - declare ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64) -declare %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String") - -declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64) - -declare { i64, i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2Int"(%"github.com/goplus/llgo/internal/runtime.iface", ptr) - -declare { %"github.com/goplus/llgo/internal/runtime.String", i1 } @"github.com/goplus/llgo/internal/runtime.CheckI2String"(%"github.com/goplus/llgo/internal/runtime.iface", ptr) +declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64) declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1) + +declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64) diff --git a/cl/_testdata/vargs/out.ll b/cl/_testdata/vargs/out.ll index 86c098c9..9d9d841e 100644 --- a/cl/_testdata/vargs/out.ll +++ b/cl/_testdata/vargs/out.ll @@ -1,13 +1,15 @@ ; ModuleID = 'main' source_filename = "main" -%"github.com/goplus/llgo/internal/runtime.iface" = type { ptr, ptr } +%"github.com/goplus/llgo/internal/runtime.eface" = type { ptr, ptr } %"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 } +%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 } @"main.init$guard" = global ptr null @__llgo_argc = global ptr null @__llgo_argv = global ptr null @0 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1 +@1 = private unnamed_addr constant [22 x i8] c"type assertion failed\00", align 1 define void @main.init() { _llgo_0: @@ -29,20 +31,42 @@ _llgo_0: call void @"github.com/goplus/llgo/internal/runtime.init"() call void @main.init() %2 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 48) - %3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, i64 0 + %3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %2, i64 0 %4 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2) - %5 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %4, i64 1) - store %"github.com/goplus/llgo/internal/runtime.iface" %5, ptr %3, align 8 - %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, i64 1 - %7 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2) - %8 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %7, i64 2) - store %"github.com/goplus/llgo/internal/runtime.iface" %8, ptr %6, align 8 - %9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %2, i64 2 + %5 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %5, i32 0, i32 0 + store ptr %4, ptr %6, align 8 + %7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %5, i32 0, i32 1 + store ptr inttoptr (i64 1 to ptr), ptr %7, align 8 + %8 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %5, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %8, ptr %3, align 8 + %9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %2, i64 1 %10 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2) - %11 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %10, i64 3) - store %"github.com/goplus/llgo/internal/runtime.iface" %11, ptr %9, align 8 - %12 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %2, i64 16, i64 3, i64 0, i64 3, i64 3) - call void @main.test(%"github.com/goplus/llgo/internal/runtime.Slice" %12) + %11 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %11, i32 0, i32 0 + store ptr %10, ptr %12, align 8 + %13 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %11, i32 0, i32 1 + store ptr inttoptr (i64 2 to ptr), ptr %13, align 8 + %14 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %11, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %14, ptr %9, align 8 + %15 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %2, i64 2 + %16 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2) + %17 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %18 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %17, i32 0, i32 0 + store ptr %16, ptr %18, align 8 + %19 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %17, i32 0, i32 1 + store ptr inttoptr (i64 3 to ptr), ptr %19, align 8 + %20 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %17, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %20, ptr %15, align 8 + %21 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 + %22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %21, i32 0, i32 0 + store ptr %2, ptr %22, align 8 + %23 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %21, i32 0, i32 1 + store i64 3, ptr %23, align 4 + %24 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %21, i32 0, i32 2 + store i64 3, ptr %24, align 4 + %25 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %21, align 8 + call void @main.test(%"github.com/goplus/llgo/internal/runtime.Slice" %25) ret i32 0 } @@ -51,8 +75,8 @@ _llgo_0: %1 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 1 br label %_llgo_1 -_llgo_1: ; preds = %_llgo_2, %_llgo_0 - %2 = phi i64 [ -1, %_llgo_0 ], [ %3, %_llgo_2 ] +_llgo_1: ; preds = %_llgo_4, %_llgo_0 + %2 = phi i64 [ -1, %_llgo_0 ], [ %3, %_llgo_4 ] %3 = add i64 %2, 1 %4 = icmp slt i64 %3, %1 br i1 %4, label %_llgo_2, label %_llgo_3 @@ -61,29 +85,41 @@ _llgo_2: ; preds = %_llgo_1 %5 = icmp slt i64 %3, 0 call void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1 %5) %6 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %0, 0 - %7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.iface", ptr %6, i64 %3 - %8 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %7, align 8 - %9 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2) - %10 = call i64 @"github.com/goplus/llgo/internal/runtime.I2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %8, ptr %9) - %11 = call i32 (ptr, ...) @printf(ptr @0, i64 %10) - br label %_llgo_1 + %7 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %6, i64 %3 + %8 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %7, align 8 + %9 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %8, 0 + %10 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2) + %11 = icmp eq ptr %9, %10 + br i1 %11, label %_llgo_4, label %_llgo_5 _llgo_3: ; preds = %_llgo_1 ret void + +_llgo_4: ; preds = %_llgo_2 + %12 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %8, 1 + %13 = ptrtoint ptr %12 to i64 + %14 = call i32 (ptr, ...) @printf(ptr @0, i64 %13) + br label %_llgo_1 + +_llgo_5: ; preds = %_llgo_2 + %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 @1, ptr %16, align 8 + %17 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %15, i32 0, i32 1 + store i64 21, ptr %17, align 4 + %18 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %15, align 8 + call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.String" %18) + unreachable } declare void @"github.com/goplus/llgo/internal/runtime.init"() declare ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64) -declare %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr, i64) - declare ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64) -declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr, i64, i64, i64, i64, i64) - declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1) -declare i64 @"github.com/goplus/llgo/internal/runtime.I2Int"(%"github.com/goplus/llgo/internal/runtime.iface", ptr) +declare void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface") declare i32 @printf(ptr, ...) diff --git a/cl/_testgo/strucintf/in.go b/cl/_testgo/strucintf/in.go new file mode 100644 index 00000000..1af4b02d --- /dev/null +++ b/cl/_testgo/strucintf/in.go @@ -0,0 +1,20 @@ +package main + +import ( + "github.com/goplus/llgo/c" + "github.com/goplus/llgo/cl/internal/foo" +) + +func main() { + bar := foo.Bar() + if x, ok := bar.(struct{ V int }); ok { + c.Printf(c.Str("%d\n"), x.V) + } else { + c.Printf(c.Str("Bar: not ok\n")) + } + if x, ok := foo.F().(struct{ v int }); ok { + c.Printf(c.Str("%d\n"), x.v) + } else { + c.Printf(c.Str("F: not ok\n")) + } +} diff --git a/cl/_testgo/strucintf/out.ll b/cl/_testgo/strucintf/out.ll new file mode 100644 index 00000000..57492612 --- /dev/null +++ b/cl/_testgo/strucintf/out.ll @@ -0,0 +1,229 @@ +; ModuleID = 'main' +source_filename = "main" + +%"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/runtime.Slice" = type { ptr, i64, i64 } + +@"main.init$guard" = global ptr null +@__llgo_argc = global ptr null +@__llgo_argv = global ptr null +@"_llgo_struct$K-dZ9QotZfVPz2a0YdRa9vmZUuDXPTqZOlMShKEDJtk" = linkonce global ptr null +@0 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1 +@"main.struct$MYpsoM99ZwFY087IpUOkIw1zjBA_sgFXVodmn1m-G88" = global ptr null +@1 = private unnamed_addr constant [13 x i8] c"Bar: not ok\0A\00", align 1 +@2 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1 +@3 = private unnamed_addr constant [11 x i8] c"F: not ok\0A\00", align 1 +@4 = private unnamed_addr constant [2 x i8] c"V\00", align 1 +@5 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 +@6 = private unnamed_addr constant [5 x i8] c"main\00", align 1 +@7 = private unnamed_addr constant [2 x i8] c"v\00", align 1 +@8 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 +@9 = private unnamed_addr constant [5 x i8] c"main\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 + call void @"github.com/goplus/llgo/cl/internal/foo.init"() + call void @"main.init$abi"() + 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 = call %"github.com/goplus/llgo/internal/runtime.eface" @"github.com/goplus/llgo/cl/internal/foo.Bar"() + %3 = alloca { i64 }, align 8 + %4 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %3, i64 8) + %5 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %2, 0 + %6 = load ptr, ptr @"_llgo_struct$K-dZ9QotZfVPz2a0YdRa9vmZUuDXPTqZOlMShKEDJtk", align 8 + %7 = icmp eq ptr %5, %6 + %8 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %2, 1 + %9 = ptrtoint ptr %8 to i64 + %10 = alloca { i64 }, align 8 + %11 = getelementptr inbounds { i64 }, ptr %10, i32 0, i32 0 + store i64 %9, ptr %11, align 4 + %12 = load { i64 }, ptr %10, align 4 + %13 = alloca { { i64 }, i1 }, align 8 + %14 = getelementptr inbounds { { i64 }, i1 }, ptr %13, i32 0, i32 0 + store { i64 } %12, ptr %14, align 4 + %15 = getelementptr inbounds { { i64 }, i1 }, ptr %13, i32 0, i32 1 + store i1 true, ptr %15, align 1 + %16 = load { { i64 }, i1 }, ptr %13, align 4 + %17 = alloca { { i64 }, i1 }, align 8 + %18 = getelementptr inbounds { { i64 }, i1 }, ptr %17, i32 0, i32 0 + store { i64 } zeroinitializer, ptr %18, align 4 + %19 = getelementptr inbounds { { i64 }, i1 }, ptr %17, i32 0, i32 1 + store i1 false, ptr %19, align 1 + %20 = load { { i64 }, i1 }, ptr %17, align 4 + %21 = select i1 %7, { { i64 }, i1 } %16, { { i64 }, i1 } %20 + %22 = extractvalue { { i64 }, i1 } %21, 0 + store { i64 } %22, ptr %4, align 4 + %23 = extractvalue { { i64 }, i1 } %21, 1 + br i1 %23, label %_llgo_1, label %_llgo_3 + +_llgo_1: ; preds = %_llgo_0 + %24 = getelementptr inbounds { i64 }, ptr %4, i32 0, i32 0 + %25 = load i64, ptr %24, align 4 + %26 = call i32 (ptr, ...) @printf(ptr @0, i64 %25) + br label %_llgo_2 + +_llgo_2: ; preds = %_llgo_3, %_llgo_1 + %27 = alloca { i64 }, align 8 + %28 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %27, i64 8) + %29 = call %"github.com/goplus/llgo/internal/runtime.eface" @"github.com/goplus/llgo/cl/internal/foo.F"() + %30 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %29, 0 + %31 = load ptr, ptr @"main.struct$MYpsoM99ZwFY087IpUOkIw1zjBA_sgFXVodmn1m-G88", align 8 + %32 = icmp eq ptr %30, %31 + %33 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %29, 1 + %34 = ptrtoint ptr %33 to i64 + %35 = alloca { i64 }, align 8 + %36 = getelementptr inbounds { i64 }, ptr %35, i32 0, i32 0 + store i64 %34, ptr %36, align 4 + %37 = load { i64 }, ptr %35, align 4 + %38 = alloca { { i64 }, i1 }, align 8 + %39 = getelementptr inbounds { { i64 }, i1 }, ptr %38, i32 0, i32 0 + store { i64 } %37, ptr %39, align 4 + %40 = getelementptr inbounds { { i64 }, i1 }, ptr %38, i32 0, i32 1 + store i1 true, ptr %40, align 1 + %41 = load { { i64 }, i1 }, ptr %38, align 4 + %42 = alloca { { i64 }, i1 }, align 8 + %43 = getelementptr inbounds { { i64 }, i1 }, ptr %42, i32 0, i32 0 + store { i64 } zeroinitializer, ptr %43, align 4 + %44 = getelementptr inbounds { { i64 }, i1 }, ptr %42, i32 0, i32 1 + store i1 false, ptr %44, align 1 + %45 = load { { i64 }, i1 }, ptr %42, align 4 + %46 = select i1 %32, { { i64 }, i1 } %41, { { i64 }, i1 } %45 + %47 = extractvalue { { i64 }, i1 } %46, 0 + store { i64 } %47, ptr %28, align 4 + %48 = extractvalue { { i64 }, i1 } %46, 1 + br i1 %48, label %_llgo_4, label %_llgo_6 + +_llgo_3: ; preds = %_llgo_0 + %49 = call i32 (ptr, ...) @printf(ptr @1) + br label %_llgo_2 + +_llgo_4: ; preds = %_llgo_2 + %50 = getelementptr inbounds { i64 }, ptr %28, i32 0, i32 0 + %51 = load i64, ptr %50, align 4 + %52 = call i32 (ptr, ...) @printf(ptr @2, i64 %51) + br label %_llgo_5 + +_llgo_5: ; preds = %_llgo_6, %_llgo_4 + ret i32 0 + +_llgo_6: ; preds = %_llgo_2 + %53 = call i32 (ptr, ...) @printf(ptr @3) + br label %_llgo_5 +} + +declare void @"github.com/goplus/llgo/cl/internal/foo.init"() + +declare void @"github.com/goplus/llgo/internal/runtime.init"() + +declare %"github.com/goplus/llgo/internal/runtime.eface" @"github.com/goplus/llgo/cl/internal/foo.Bar"() + +declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64) + +declare i32 @printf(ptr, ...) + +declare %"github.com/goplus/llgo/internal/runtime.eface" @"github.com/goplus/llgo/cl/internal/foo.F"() + +define void @"main.init$abi"() { +_llgo_0: + %0 = load ptr, ptr @"_llgo_struct$K-dZ9QotZfVPz2a0YdRa9vmZUuDXPTqZOlMShKEDJtk", 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 @4, ptr %3, align 8 + %4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 1 + store i64 1, ptr %4, align 4 + %5 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %2, align 8 + %6 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2) + %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 @5, 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 true, 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 @6, ptr %13, align 8 + %14 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %12, i32 0, i32 1 + store i64 4, 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.AllocU"(i64 24) + %17 = getelementptr %"github.com/goplus/llgo/internal/abi.StructField", ptr %16, i64 0 + store %"github.com/goplus/llgo/internal/abi.StructField" %11, ptr %17, align 8 + %18 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 + %19 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %18, i32 0, i32 0 + store ptr %16, ptr %19, align 8 + %20 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %18, i32 0, i32 1 + store i64 1, ptr %20, align 4 + %21 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %18, i32 0, i32 2 + store i64 1, ptr %21, align 4 + %22 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %18, align 8 + %23 = call ptr @"github.com/goplus/llgo/internal/runtime.Struct"(%"github.com/goplus/llgo/internal/runtime.String" %15, %"github.com/goplus/llgo/internal/runtime.Slice" %22) + store ptr %23, ptr @"_llgo_struct$K-dZ9QotZfVPz2a0YdRa9vmZUuDXPTqZOlMShKEDJtk", align 8 + br label %_llgo_2 + +_llgo_2: ; preds = %_llgo_1, %_llgo_0 + %24 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %25 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %24, i32 0, i32 0 + store ptr @7, ptr %25, align 8 + %26 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %24, i32 0, i32 1 + store i64 1, ptr %26, align 4 + %27 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %24, align 8 + %28 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2) + %29 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %30 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %29, i32 0, i32 0 + store ptr @8, ptr %30, align 8 + %31 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %29, i32 0, i32 1 + store i64 0, ptr %31, align 4 + %32 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %29, align 8 + %33 = call %"github.com/goplus/llgo/internal/abi.StructField" @"github.com/goplus/llgo/internal/runtime.StructField"(%"github.com/goplus/llgo/internal/runtime.String" %27, ptr %28, i64 0, %"github.com/goplus/llgo/internal/runtime.String" %32, i1 false, i1 false) + %34 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %35 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %34, i32 0, i32 0 + store ptr @9, ptr %35, align 8 + %36 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %34, i32 0, i32 1 + store i64 4, ptr %36, align 4 + %37 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %34, align 8 + %38 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 24) + %39 = getelementptr %"github.com/goplus/llgo/internal/abi.StructField", ptr %38, i64 0 + store %"github.com/goplus/llgo/internal/abi.StructField" %33, ptr %39, align 8 + %40 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 + %41 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %40, i32 0, i32 0 + store ptr %38, ptr %41, align 8 + %42 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %40, i32 0, i32 1 + store i64 1, ptr %42, align 4 + %43 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %40, i32 0, i32 2 + store i64 1, ptr %43, align 4 + %44 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %40, align 8 + %45 = call ptr @"github.com/goplus/llgo/internal/runtime.Struct"(%"github.com/goplus/llgo/internal/runtime.String" %37, %"github.com/goplus/llgo/internal/runtime.Slice" %44) + store ptr %45, ptr @"main.struct$MYpsoM99ZwFY087IpUOkIw1zjBA_sgFXVodmn1m-G88", 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 %"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 ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64) + +declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64) diff --git a/cl/_testrt/gotypes/in.go b/cl/_testrt/_gotypes/in.go similarity index 100% rename from cl/_testrt/gotypes/in.go rename to cl/_testrt/_gotypes/in.go diff --git a/cl/_testrt/gotypes/out.ll b/cl/_testrt/_gotypes/out.ll similarity index 100% rename from cl/_testrt/gotypes/out.ll rename to cl/_testrt/_gotypes/out.ll diff --git a/cl/_testrt/any/out.ll b/cl/_testrt/any/out.ll index fbf58289..207fc6d3 100644 --- a/cl/_testrt/any/out.ll +++ b/cl/_testrt/any/out.ll @@ -1,19 +1,37 @@ ; ModuleID = 'main' source_filename = "main" -%"github.com/goplus/llgo/internal/runtime.iface" = type { ptr, ptr } +%"github.com/goplus/llgo/internal/runtime.eface" = type { ptr, ptr } +%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 } @"main.init$guard" = global ptr null +@0 = private unnamed_addr constant [22 x i8] c"type assertion failed\00", align 1 @__llgo_argc = global ptr null @__llgo_argv = global ptr null -@0 = private unnamed_addr constant [10 x i8] c"Hello %d\0A\00", align 1 +@1 = private unnamed_addr constant [10 x i8] c"Hello %d\0A\00", align 1 -define i64 @main.incVal(%"github.com/goplus/llgo/internal/runtime.iface" %0) { +define i64 @main.incVal(%"github.com/goplus/llgo/internal/runtime.eface" %0) { _llgo_0: - %1 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2) - %2 = call i64 @"github.com/goplus/llgo/internal/runtime.I2Int"(%"github.com/goplus/llgo/internal/runtime.iface" %0, ptr %1) - %3 = add i64 %2, 1 - ret i64 %3 + %1 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0 + %2 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2) + %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 = ptrtoint ptr %4 to i64 + %6 = add i64 %5, 1 + ret i64 %6 + +_llgo_2: ; preds = %_llgo_0 + %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 @0, ptr %8, align 8 + %9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 1 + store i64 21, ptr %9, align 4 + %10 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %7, align 8 + call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.String" %10) + unreachable } define void @main.init() { @@ -36,18 +54,21 @@ _llgo_0: call void @"github.com/goplus/llgo/internal/runtime.init"() call void @main.init() %2 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2) - %3 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %2, i64 100) - %4 = call i64 @main.incVal(%"github.com/goplus/llgo/internal/runtime.iface" %3) - %5 = call i32 (ptr, ...) @printf(ptr @0, i64 %4) + %3 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %3, i32 0, i32 0 + store ptr %2, ptr %4, align 8 + %5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %3, i32 0, i32 1 + store ptr inttoptr (i64 100 to ptr), ptr %5, align 8 + %6 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %3, align 8 + %7 = call i64 @main.incVal(%"github.com/goplus/llgo/internal/runtime.eface" %6) + %8 = call i32 (ptr, ...) @printf(ptr @1, i64 %7) ret i32 0 } -declare i64 @"github.com/goplus/llgo/internal/runtime.I2Int"(%"github.com/goplus/llgo/internal/runtime.iface", ptr) - declare ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64) +declare void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface") + declare void @"github.com/goplus/llgo/internal/runtime.init"() -declare %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr, i64) - declare i32 @printf(ptr, ...) diff --git a/cl/_testrt/builtin/out.ll b/cl/_testrt/builtin/out.ll index c921f898..d6c806f3 100644 --- a/cl/_testrt/builtin/out.ll +++ b/cl/_testrt/builtin/out.ll @@ -3,7 +3,7 @@ source_filename = "main" %"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 } %"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 } -%"github.com/goplus/llgo/internal/runtime.iface" = type { ptr, ptr } +%"github.com/goplus/llgo/internal/runtime.eface" = type { ptr, ptr } @main.a = global ptr null @main.b = global ptr null @@ -55,33 +55,40 @@ _llgo_0: store i64 3, ptr %5, align 4 %6 = getelementptr inbounds i64, ptr %2, i64 3 store i64 4, ptr %6, align 4 - %7 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %2, i64 8, i64 4, i64 0, i64 4, i64 4) - %8 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32) - %9 = getelementptr inbounds i64, ptr %8, i64 0 - %10 = getelementptr inbounds i64, ptr %8, i64 1 - %11 = getelementptr inbounds i64, ptr %8, i64 2 - %12 = getelementptr inbounds i64, ptr %8, i64 3 - store i64 1, ptr %9, align 4 - store i64 2, ptr %10, align 4 - store i64 3, ptr %11, align 4 - store i64 4, ptr %12, align 4 - %13 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 10) - %14 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %13, i64 1, i64 10, i64 0, i64 4, i64 10) - %15 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 1 - %16 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2 - call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %7) + %7 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 + %8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %7, i32 0, i32 0 + store ptr %2, ptr %8, align 8 + %9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %7, i32 0, i32 1 + store i64 4, ptr %9, align 4 + %10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %7, i32 0, i32 2 + store i64 4, ptr %10, align 4 + %11 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %7, align 8 + %12 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32) + %13 = getelementptr inbounds i64, ptr %12, i64 0 + %14 = getelementptr inbounds i64, ptr %12, i64 1 + %15 = getelementptr inbounds i64, ptr %12, i64 2 + %16 = getelementptr inbounds i64, ptr %12, i64 3 + store i64 1, ptr %13, align 4 + store i64 2, ptr %14, align 4 + store i64 3, ptr %15, align 4 + store i64 4, ptr %16, align 4 + %17 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 10) + %18 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %17, i64 1, i64 10, i64 0, i64 4, i64 10) + %19 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %11, 1 + %20 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %11, 2 + call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %11) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %15) + call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %19) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %16) + call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %20) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) - %17 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %14, 1 - %18 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %14, 2 - call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %14) + %21 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %18, 1 + %22 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %18, 2 + call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %18) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %17) + call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %21) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %18) + call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %22) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 4) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) @@ -91,161 +98,187 @@ _llgo_0: call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 4) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) - %19 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32) - %20 = getelementptr inbounds i64, ptr %19, i64 0 - store i64 1, ptr %20, align 4 - %21 = getelementptr inbounds i64, ptr %19, i64 1 - store i64 2, ptr %21, align 4 - %22 = getelementptr inbounds i64, ptr %19, i64 2 - store i64 3, ptr %22, align 4 - %23 = getelementptr inbounds i64, ptr %19, i64 3 - store i64 4, ptr %23, align 4 - %24 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %19, i64 8, i64 4, i64 0, i64 4, i64 4) - %25 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %24, 1 - call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %25) + %23 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32) + %24 = getelementptr inbounds i64, ptr %23, i64 0 + store i64 1, ptr %24, align 4 + %25 = getelementptr inbounds i64, ptr %23, i64 1 + store i64 2, ptr %25, align 4 + %26 = getelementptr inbounds i64, ptr %23, i64 2 + store i64 3, ptr %26, align 4 + %27 = getelementptr inbounds i64, ptr %23, i64 3 + store i64 4, ptr %27, align 4 + %28 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 + %29 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %28, i32 0, i32 0 + store ptr %23, ptr %29, align 8 + %30 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %28, i32 0, i32 1 + store i64 4, ptr %30, align 4 + %31 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %28, i32 0, i32 2 + store i64 4, ptr %31, align 4 + %32 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %28, align 8 + %33 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %32, 1 + call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %33) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 4) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) - %26 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2 - %27 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2 - %28 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0 - %29 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %28, i64 8, i64 %26, i64 1, i64 %27, i64 %26) - %30 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %29, 1 - %31 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2 - %32 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2 - %33 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0 - %34 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %33, i64 8, i64 %31, i64 1, i64 %32, i64 %31) - %35 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %34, 2 - %36 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2 - %37 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0 - %38 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %37, i64 8, i64 %36, i64 1, i64 2, i64 %36) - %39 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %38, 1 - %40 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2 - %41 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0 - %42 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %41, i64 8, i64 %40, i64 1, i64 2, i64 %40) + %34 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %11, 2 + %35 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %11, 2 + %36 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %11, 0 + %37 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %36, i64 32, i64 %34, i64 1, i64 %35, i64 %34) + %38 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %37, 1 + %39 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %11, 2 + %40 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %11, 2 + %41 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %11, 0 + %42 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %41, i64 32, i64 %39, i64 1, i64 %40, i64 %39) %43 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %42, 2 - %44 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2 - %45 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0 - %46 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %45, i64 8, i64 %44, i64 1, i64 2, i64 2) + %44 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %11, 2 + %45 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %11, 0 + %46 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %45, i64 32, i64 %44, i64 1, i64 2, i64 %44) %47 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %46, 1 - %48 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 2 - %49 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %7, 0 - %50 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %49, i64 8, i64 %48, i64 1, i64 2, i64 2) + %48 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %11, 2 + %49 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %11, 0 + %50 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %49, i64 32, i64 %48, i64 1, i64 2, i64 %48) %51 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %50, 2 - call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %30) - call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %35) - call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %39) + %52 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %11, 2 + %53 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %11, 0 + %54 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %53, i64 32, i64 %52, i64 1, i64 2, i64 2) + %55 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %54, 1 + %56 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %11, 2 + %57 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %11, 0 + %58 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %57, i64 32, i64 %56, i64 1, i64 2, i64 2) + %59 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %58, 2 + call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %38) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %43) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %47) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %51) - call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) - %52 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 4, i64 4) - %53 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %52, 1 - %54 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 4, i64 4) - %55 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %54, 2 - %56 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 4) - %57 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %56, 1 - %58 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 4) - %59 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %58, 2 - %60 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 2) - %61 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %60, 1 - %62 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %8, i64 8, i64 4, i64 1, i64 2, i64 2) - %63 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %62, 2 - call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %53) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %55) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %57) - call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %59) - call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) + call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) + %60 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %12, i64 8, i64 4, i64 1, i64 4, i64 4) + %61 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %60, 1 + %62 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %12, i64 8, i64 4, i64 1, i64 4, i64 4) + %63 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %62, 2 + %64 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %12, i64 8, i64 4, i64 1, i64 2, i64 4) + %65 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %64, 1 + %66 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %12, i64 8, i64 4, i64 1, i64 2, i64 4) + %67 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %66, 2 + %68 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %12, i64 8, i64 4, i64 1, i64 2, i64 2) + %69 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %68, 1 + %70 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %12, i64 8, i64 4, i64 1, i64 2, i64 2) + %71 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %70, 2 call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %61) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %63) - call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) - %64 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %65 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %64, i32 0, i32 0 - store ptr @0, ptr %65, align 8 - %66 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %64, i32 0, i32 1 - store i64 5, ptr %66, align 4 - %67 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %64, align 8 - %68 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %67, 1 - %69 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %67, i64 1, i64 %68) - %70 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %71 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %70, i32 0, i32 0 - store ptr @1, ptr %71, align 8 - %72 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %70, i32 0, i32 1 - store i64 5, ptr %72, align 4 - %73 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %70, align 8 - %74 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %73, i64 1, i64 2) - %75 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %76 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %75, i32 0, i32 0 - store ptr @2, ptr %76, align 8 - %77 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %75, i32 0, i32 1 - store i64 5, ptr %77, align 4 - %78 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %75, align 8 - %79 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %78, 1 - %80 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %78, i64 5, i64 %79) - %81 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %80, 1 - %82 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %83 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %82, i32 0, i32 0 - store ptr @3, ptr %83, align 8 - %84 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %82, i32 0, i32 1 - store i64 5, ptr %84, align 4 - %85 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %82, align 8 - call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %85) 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" %69) + call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %65) 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" %74) + call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %67) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %81) + call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %69) + call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) + call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %71) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) - %86 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32) - %87 = getelementptr inbounds i64, ptr %86, i64 0 - store i64 5, ptr %87, align 4 - %88 = getelementptr inbounds i64, ptr %86, i64 1 - store i64 6, ptr %88, align 4 - %89 = getelementptr inbounds i64, ptr %86, i64 2 - store i64 7, ptr %89, align 4 - %90 = getelementptr inbounds i64, ptr %86, i64 3 - store i64 8, ptr %90, align 4 - %91 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %86, i64 8, i64 4, i64 0, i64 4, i64 4) - %92 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %91, 0 - %93 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %91, 1 - %94 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.SliceAppend"(%"github.com/goplus/llgo/internal/runtime.Slice" %7, ptr %92, i64 %93, i64 8) - call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %94) + %72 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %73 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %72, i32 0, i32 0 + store ptr @0, ptr %73, align 8 + %74 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %72, i32 0, i32 1 + store i64 5, ptr %74, align 4 + %75 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %72, align 8 + %76 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %75, 1 + %77 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %75, i64 1, i64 %76) + %78 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %79 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %78, i32 0, i32 0 + store ptr @1, ptr %79, align 8 + %80 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %78, i32 0, i32 1 + store i64 5, ptr %80, align 4 + %81 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %78, align 8 + %82 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %81, i64 1, i64 2) + %83 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %84 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %83, i32 0, i32 0 + store ptr @2, ptr %84, align 8 + %85 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %83, i32 0, i32 1 + store i64 5, ptr %85, align 4 + %86 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %83, align 8 + %87 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %86, 1 + %88 = call %"github.com/goplus/llgo/internal/runtime.String" @"github.com/goplus/llgo/internal/runtime.NewStringSlice"(%"github.com/goplus/llgo/internal/runtime.String" %86, i64 5, i64 %87) + %89 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %88, 1 + %90 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %91 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %90, i32 0, i32 0 + store ptr @3, ptr %91, align 8 + %92 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %90, i32 0, i32 1 + store i64 5, ptr %92, align 4 + %93 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %90, align 8 + call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %93) + 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" %77) + 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" %82) + call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) + call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %89) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) - %95 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 3) - %96 = getelementptr inbounds i8, ptr %95, i64 0 - store i8 97, ptr %96, align 1 - %97 = getelementptr inbounds i8, ptr %95, i64 1 - store i8 98, ptr %97, align 1 - %98 = getelementptr inbounds i8, ptr %95, i64 2 - store i8 99, ptr %98, align 1 - %99 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %95, i64 1, i64 3, i64 0, i64 3, i64 3) - %100 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %101 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %100, i32 0, i32 0 - store ptr @4, ptr %101, align 8 - %102 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %100, i32 0, i32 1 - store i64 3, ptr %102, align 4 - %103 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %100, align 8 - %104 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %103, 0 - %105 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %103, 1 - %106 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.SliceAppend"(%"github.com/goplus/llgo/internal/runtime.Slice" %99, ptr %104, i64 %105, i64 1) + %94 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 32) + %95 = getelementptr inbounds i64, ptr %94, i64 0 + store i64 5, ptr %95, align 4 + %96 = getelementptr inbounds i64, ptr %94, i64 1 + store i64 6, ptr %96, align 4 + %97 = getelementptr inbounds i64, ptr %94, i64 2 + store i64 7, ptr %97, align 4 + %98 = getelementptr inbounds i64, ptr %94, i64 3 + store i64 8, ptr %98, align 4 + %99 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 + %100 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %99, i32 0, i32 0 + store ptr %94, ptr %100, align 8 + %101 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %99, i32 0, i32 1 + store i64 4, ptr %101, align 4 + %102 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %99, i32 0, i32 2 + store i64 4, ptr %102, align 4 + %103 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %99, align 8 + %104 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %103, 0 + %105 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %103, 1 + %106 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.SliceAppend"(%"github.com/goplus/llgo/internal/runtime.Slice" %11, ptr %104, i64 %105, i64 32) call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %106) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) - %107 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 16) - %108 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2) - %109 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr %108, i64 100) - store %"github.com/goplus/llgo/internal/runtime.iface" %109, ptr %107, align 8 - %110 = load %"github.com/goplus/llgo/internal/runtime.iface", ptr %107, align 8 - %111 = ptrtoint ptr %107 to i64 + %107 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 3) + %108 = getelementptr inbounds i8, ptr %107, i64 0 + store i8 97, ptr %108, align 1 + %109 = getelementptr inbounds i8, ptr %107, i64 1 + store i8 98, ptr %109, align 1 + %110 = getelementptr inbounds i8, ptr %107, i64 2 + store i8 99, ptr %110, align 1 + %111 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 + %112 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %111, i32 0, i32 0 + store ptr %107, ptr %112, align 8 + %113 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %111, i32 0, i32 1 + store i64 3, ptr %113, align 4 + %114 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %111, i32 0, i32 2 + store i64 3, ptr %114, align 4 + %115 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %111, align 8 + %116 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %117 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %116, i32 0, i32 0 + store ptr @4, ptr %117, align 8 + %118 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %116, i32 0, i32 1 + store i64 3, ptr %118, align 4 + %119 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %116, align 8 + %120 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %119, 0 + %121 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %119, 1 + %122 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.SliceAppend"(%"github.com/goplus/llgo/internal/runtime.Slice" %115, ptr %120, i64 %121, i64 1) + call void @"github.com/goplus/llgo/internal/runtime.PrintSlice"(%"github.com/goplus/llgo/internal/runtime.Slice" %122) + call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) + %123 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 16) + %124 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 2) + %125 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %126 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %125, i32 0, i32 0 + store ptr %124, ptr %126, align 8 + %127 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %125, i32 0, i32 1 + store ptr inttoptr (i64 100 to ptr), ptr %127, align 8 + %128 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %125, align 8 + store %"github.com/goplus/llgo/internal/runtime.eface" %128, ptr %123, align 8 + %129 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %123, align 8 + %130 = ptrtoint ptr %123 to i64 call void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1 true) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 0) @@ -262,83 +295,90 @@ _llgo_0: call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double 1.005000e+02) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintIface"(%"github.com/goplus/llgo/internal/runtime.iface" %110) + call void @"github.com/goplus/llgo/internal/runtime.PrintEface"(%"github.com/goplus/llgo/internal/runtime.eface" %129) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr %107) + call void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr %123) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %111) + call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %130) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) - %112 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 3) - %113 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 8) - %114 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %112, i64 1, i64 3, i64 0, i64 3, i64 3) - %115 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %106, 0 - %116 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %106, 1 - %117 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCopy"(%"github.com/goplus/llgo/internal/runtime.Slice" %114, ptr %115, i64 %116, i64 1) - store i64 %117, ptr %113, align 4 - %118 = load i64, ptr %113, align 4 - %119 = getelementptr inbounds i8, ptr %112, i64 0 - %120 = load i8, ptr %119, align 1 - %121 = getelementptr inbounds i8, ptr %112, i64 1 - %122 = load i8, ptr %121, align 1 - %123 = getelementptr inbounds i8, ptr %112, i64 2 - %124 = load i8, ptr %123, align 1 - call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %118) + %131 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 3) + %132 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 8) + %133 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 + %134 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %133, i32 0, i32 0 + store ptr %131, ptr %134, align 8 + %135 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %133, i32 0, i32 1 + store i64 3, ptr %135, align 4 + %136 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %133, i32 0, i32 2 + store i64 3, ptr %136, align 4 + %137 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %133, align 8 + %138 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %122, 0 + %139 = extractvalue %"github.com/goplus/llgo/internal/runtime.Slice" %122, 1 + %140 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCopy"(%"github.com/goplus/llgo/internal/runtime.Slice" %137, ptr %138, i64 %139, i64 3) + store i64 %140, ptr %132, align 4 + %141 = load i64, ptr %132, align 4 + %142 = getelementptr inbounds i8, ptr %131, i64 0 + %143 = load i8, ptr %142, align 1 + %144 = getelementptr inbounds i8, ptr %131, i64 1 + %145 = load i8, ptr %144, align 1 + %146 = getelementptr inbounds i8, ptr %131, i64 2 + %147 = load i8, ptr %146, align 1 + call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %141) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - %125 = zext i8 %120 to i64 - call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %125) + %148 = zext i8 %143 to i64 + call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %148) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - %126 = zext i8 %122 to i64 - call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %126) + %149 = zext i8 %145 to i64 + call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %149) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - %127 = zext i8 %124 to i64 - call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %127) + %150 = zext i8 %147 to i64 + call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %150) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) - %128 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %112, i64 1, i64 3, i64 1, i64 3, i64 3) - %129 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %130 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %129, i32 0, i32 0 - store ptr @5, ptr %130, align 8 - %131 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %129, i32 0, i32 1 - store i64 4, ptr %131, align 4 - %132 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %129, align 8 - %133 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %132, 0 - %134 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %132, 1 - %135 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCopy"(%"github.com/goplus/llgo/internal/runtime.Slice" %128, ptr %133, i64 %134, i64 1) - store i64 %135, ptr %113, align 4 - %136 = load i64, ptr %113, align 4 - %137 = getelementptr inbounds i8, ptr %112, i64 0 - %138 = load i8, ptr %137, align 1 - %139 = getelementptr inbounds i8, ptr %112, i64 1 - %140 = load i8, ptr %139, align 1 - %141 = getelementptr inbounds i8, ptr %112, i64 2 - %142 = load i8, ptr %141, align 1 - call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %136) + %151 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %131, i64 1, i64 3, i64 1, i64 3, i64 3) + %152 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %153 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %152, i32 0, i32 0 + store ptr @5, ptr %153, align 8 + %154 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %152, i32 0, i32 1 + store i64 4, ptr %154, align 4 + %155 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %152, align 8 + %156 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %155, 0 + %157 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %155, 1 + %158 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceCopy"(%"github.com/goplus/llgo/internal/runtime.Slice" %151, ptr %156, i64 %157, i64 1) + store i64 %158, ptr %132, align 4 + %159 = load i64, ptr %132, align 4 + %160 = getelementptr inbounds i8, ptr %131, i64 0 + %161 = load i8, ptr %160, align 1 + %162 = getelementptr inbounds i8, ptr %131, i64 1 + %163 = load i8, ptr %162, align 1 + %164 = getelementptr inbounds i8, ptr %131, i64 2 + %165 = load i8, ptr %164, align 1 + call void @"github.com/goplus/llgo/internal/runtime.PrintInt"(i64 %159) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - %143 = zext i8 %138 to i64 - call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %143) + %166 = zext i8 %161 to i64 + call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %166) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - %144 = zext i8 %140 to i64 - call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %144) + %167 = zext i8 %163 to i64 + call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %167) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - %145 = zext i8 %142 to i64 - call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %145) + %168 = zext i8 %165 to i64 + call void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64 %168) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) - %146 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8) - %147 = getelementptr inbounds { ptr }, ptr %146, i32 0, i32 0 - store ptr %113, ptr %147, align 8 - %148 = alloca { ptr, ptr }, align 8 - %149 = getelementptr inbounds { ptr, ptr }, ptr %148, i32 0, i32 0 - store ptr @"main.main$2", ptr %149, align 8 - %150 = getelementptr inbounds { ptr, ptr }, ptr %148, i32 0, i32 1 - store ptr %146, ptr %150, align 8 - %151 = load { ptr, ptr }, ptr %148, align 8 + %169 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8) + %170 = getelementptr inbounds { ptr }, ptr %169, i32 0, i32 0 + store ptr %132, ptr %170, align 8 + %171 = alloca { ptr, ptr }, align 8 + %172 = getelementptr inbounds { ptr, ptr }, ptr %171, i32 0, i32 0 + store ptr @"main.main$2", ptr %172, align 8 + %173 = getelementptr inbounds { ptr, ptr }, ptr %171, i32 0, i32 1 + store ptr %169, ptr %173, align 8 + %174 = load { ptr, ptr }, ptr %171, align 8 call void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr @main.demo) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) call void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr @main.demo) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) call void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr @"main.main$1") call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - %152 = extractvalue { ptr, ptr } %151, 0 - call void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr %152) + %175 = extractvalue { ptr, ptr } %174, 0 + call void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr %175) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) ret i32 0 } @@ -361,8 +401,6 @@ declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com declare %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.SliceAppend"(%"github.com/goplus/llgo/internal/runtime.Slice", ptr, i64, i64) -declare %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyIntptr"(ptr, i64) - declare ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64) declare void @"github.com/goplus/llgo/internal/runtime.PrintBool"(i1) @@ -371,7 +409,7 @@ declare void @"github.com/goplus/llgo/internal/runtime.PrintUint"(i64) declare void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double) -declare void @"github.com/goplus/llgo/internal/runtime.PrintIface"(%"github.com/goplus/llgo/internal/runtime.iface") +declare void @"github.com/goplus/llgo/internal/runtime.PrintEface"(%"github.com/goplus/llgo/internal/runtime.eface") declare void @"github.com/goplus/llgo/internal/runtime.PrintPointer"(ptr) diff --git a/cl/_testrt/cast/out.ll b/cl/_testrt/cast/out.ll index b6739dbb..794eea9e 100644 --- a/cl/_testrt/cast/out.ll +++ b/cl/_testrt/cast/out.ll @@ -2,7 +2,7 @@ source_filename = "main" %"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 } -%"github.com/goplus/llgo/internal/runtime.iface" = type { ptr, ptr } +%"github.com/goplus/llgo/internal/runtime.eface" = type { ptr, ptr } @"main.init$guard" = global ptr null @0 = private unnamed_addr constant [6 x i8] c"error\00", align 1 @@ -34,8 +34,16 @@ _llgo_1: ; preds = %_llgo_0 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %4, i32 0, i32 1 store i64 5, ptr %6, align 4 %7 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %4, align 8 - %8 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %7) - call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %8) + %8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) + %9 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %7, ptr %9, align 8 + %10 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 0 + store ptr %8, ptr %11, align 8 + %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1 + store ptr %9, ptr %12, align 8 + %13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8 + call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13) unreachable _llgo_2: ; preds = %_llgo_0 @@ -55,8 +63,16 @@ _llgo_1: ; preds = %_llgo_0 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %4, i32 0, i32 1 store i64 5, ptr %6, align 4 %7 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %4, align 8 - %8 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %7) - call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %8) + %8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) + %9 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %7, ptr %9, align 8 + %10 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 0 + store ptr %8, ptr %11, align 8 + %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1 + store ptr %9, ptr %12, align 8 + %13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8 + call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13) unreachable _llgo_2: ; preds = %_llgo_0 @@ -76,8 +92,16 @@ _llgo_1: ; preds = %_llgo_0 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %4, i32 0, i32 1 store i64 5, ptr %6, align 4 %7 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %4, align 8 - %8 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %7) - call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %8) + %8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) + %9 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %7, ptr %9, align 8 + %10 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 0 + store ptr %8, ptr %11, align 8 + %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1 + store ptr %9, ptr %12, align 8 + %13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8 + call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13) unreachable _llgo_2: ; preds = %_llgo_0 @@ -97,8 +121,16 @@ _llgo_1: ; preds = %_llgo_0 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %4, i32 0, i32 1 store i64 5, ptr %6, align 4 %7 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %4, align 8 - %8 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %7) - call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %8) + %8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) + %9 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %7, ptr %9, align 8 + %10 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 0 + store ptr %8, ptr %11, align 8 + %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1 + store ptr %9, ptr %12, align 8 + %13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8 + call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13) unreachable _llgo_2: ; preds = %_llgo_0 @@ -118,8 +150,16 @@ _llgo_1: ; preds = %_llgo_0 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %4, i32 0, i32 1 store i64 5, ptr %6, align 4 %7 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %4, align 8 - %8 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %7) - call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %8) + %8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) + %9 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %7, ptr %9, align 8 + %10 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 0 + store ptr %8, ptr %11, align 8 + %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1 + store ptr %9, ptr %12, align 8 + %13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8 + call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13) unreachable _llgo_2: ; preds = %_llgo_0 @@ -139,8 +179,16 @@ _llgo_1: ; preds = %_llgo_0 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %4, i32 0, i32 1 store i64 5, ptr %6, align 4 %7 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %4, align 8 - %8 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %7) - call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %8) + %8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) + %9 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %7, ptr %9, align 8 + %10 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 0 + store ptr %8, ptr %11, align 8 + %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1 + store ptr %9, ptr %12, align 8 + %13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8 + call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13) unreachable _llgo_2: ; preds = %_llgo_0 @@ -160,8 +208,16 @@ _llgo_1: ; preds = %_llgo_0 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %4, i32 0, i32 1 store i64 5, ptr %6, align 4 %7 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %4, align 8 - %8 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %7) - call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %8) + %8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) + %9 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %7, ptr %9, align 8 + %10 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 0 + store ptr %8, ptr %11, align 8 + %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1 + store ptr %9, ptr %12, align 8 + %13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8 + call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13) unreachable _llgo_2: ; preds = %_llgo_0 @@ -181,8 +237,16 @@ _llgo_1: ; preds = %_llgo_0 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %4, i32 0, i32 1 store i64 5, ptr %6, align 4 %7 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %4, align 8 - %8 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %7) - call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %8) + %8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) + %9 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %7, ptr %9, align 8 + %10 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 0 + store ptr %8, ptr %11, align 8 + %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1 + store ptr %9, ptr %12, align 8 + %13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8 + call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13) unreachable _llgo_2: ; preds = %_llgo_0 @@ -202,8 +266,16 @@ _llgo_1: ; preds = %_llgo_0 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %4, i32 0, i32 1 store i64 5, ptr %6, align 4 %7 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %4, align 8 - %8 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %7) - call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %8) + %8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) + %9 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %7, ptr %9, align 8 + %10 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 0 + store ptr %8, ptr %11, align 8 + %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1 + store ptr %9, ptr %12, align 8 + %13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8 + call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13) unreachable _llgo_2: ; preds = %_llgo_0 @@ -223,8 +295,16 @@ _llgo_1: ; preds = %_llgo_0 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %4, i32 0, i32 1 store i64 5, ptr %6, align 4 %7 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %4, align 8 - %8 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %7) - call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %8) + %8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) + %9 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %7, ptr %9, align 8 + %10 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 0 + store ptr %8, ptr %11, align 8 + %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1 + store ptr %9, ptr %12, align 8 + %13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8 + call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13) unreachable _llgo_2: ; preds = %_llgo_0 @@ -244,8 +324,16 @@ _llgo_1: ; preds = %_llgo_0 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %4, i32 0, i32 1 store i64 5, ptr %6, align 4 %7 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %4, align 8 - %8 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %7) - call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %8) + %8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) + %9 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %7, ptr %9, align 8 + %10 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 0 + store ptr %8, ptr %11, align 8 + %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1 + store ptr %9, ptr %12, align 8 + %13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8 + call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13) unreachable _llgo_2: ; preds = %_llgo_0 @@ -265,24 +353,40 @@ _llgo_1: ; preds = %_llgo_0 %6 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %4, i32 0, i32 1 store i64 5, ptr %6, align 4 %7 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %4, align 8 - %8 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %7) - call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %8) + %8 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) + %9 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %7, ptr %9, align 8 + %10 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %11 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 0 + store ptr %8, ptr %11, align 8 + %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, i32 0, i32 1 + store ptr %9, ptr %12, align 8 + %13 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %10, align 8 + call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %13) unreachable _llgo_2: ; preds = %_llgo_0 - %9 = trunc i64 %1 to i32 - %10 = icmp ne i32 %9, %0 - br i1 %10, label %_llgo_3, label %_llgo_4 + %14 = trunc i64 %1 to i32 + %15 = icmp ne i32 %14, %0 + br i1 %15, label %_llgo_3, label %_llgo_4 _llgo_3: ; preds = %_llgo_2 - %11 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %12 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %11, i32 0, i32 0 - store ptr @12, ptr %12, align 8 - %13 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %11, i32 0, i32 1 - store i64 5, ptr %13, align 4 - %14 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %11, align 8 - %15 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %14) - call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %15) + %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 @12, ptr %17, align 8 + %18 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %16, i32 0, i32 1 + store i64 5, ptr %18, align 4 + %19 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %16, align 8 + %20 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) + %21 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %19, ptr %21, align 8 + %22 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %23 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %22, i32 0, i32 0 + store ptr %20, ptr %23, align 8 + %24 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %22, i32 0, i32 1 + store ptr %21, ptr %24, align 8 + %25 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %22, align 8 + call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %25) unreachable _llgo_4: ; preds = %_llgo_2 @@ -366,8 +470,10 @@ _llgo_0: ret i32 0 } -declare %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String") +declare ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64) -declare void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface") +declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64) + +declare void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface") declare void @"github.com/goplus/llgo/internal/runtime.init"() diff --git a/cl/_testrt/concat/out.ll b/cl/_testrt/concat/out.ll index 845d1d0c..f850807f 100644 --- a/cl/_testrt/concat/out.ll +++ b/cl/_testrt/concat/out.ll @@ -121,14 +121,21 @@ _llgo_0: store i64 5, ptr %16, align 4 %17 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %14, align 8 store %"github.com/goplus/llgo/internal/runtime.String" %17, ptr %13, align 8 - %18 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %2, i64 16, i64 3, i64 0, i64 3, i64 3) - %19 = call %"github.com/goplus/llgo/internal/runtime.String" @main.concat(%"github.com/goplus/llgo/internal/runtime.Slice" %18) - %20 = load ptr, ptr @__stderrp, align 8 - %21 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %19, 1 - %22 = add i64 %21, 1 - %23 = alloca i8, i64 %22, align 1 - %24 = call ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr %23, %"github.com/goplus/llgo/internal/runtime.String" %19) - %25 = call i32 (ptr, ptr, ...) @fprintf(ptr %20, ptr @6, ptr %24) + %18 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 + %19 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %18, i32 0, i32 0 + store ptr %2, ptr %19, align 8 + %20 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %18, i32 0, i32 1 + store i64 3, ptr %20, align 4 + %21 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %18, i32 0, i32 2 + store i64 3, ptr %21, align 4 + %22 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %18, align 8 + %23 = call %"github.com/goplus/llgo/internal/runtime.String" @main.concat(%"github.com/goplus/llgo/internal/runtime.Slice" %22) + %24 = load ptr, ptr @__stderrp, align 8 + %25 = extractvalue %"github.com/goplus/llgo/internal/runtime.String" %23, 1 + %26 = add i64 %25, 1 + %27 = alloca i8, i64 %26, align 1 + %28 = call ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr %27, %"github.com/goplus/llgo/internal/runtime.String" %23) + %29 = call i32 (ptr, ptr, ...) @fprintf(ptr %24, ptr @6, ptr %28) ret i32 0 } @@ -140,8 +147,6 @@ declare void @"github.com/goplus/llgo/internal/runtime.init"() 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 ptr @"github.com/goplus/llgo/internal/runtime.CStrCopy"(ptr, %"github.com/goplus/llgo/internal/runtime.String") declare i32 @fprintf(ptr, ptr, ...) diff --git a/cl/_testrt/panic/out.ll b/cl/_testrt/panic/out.ll index f8923d33..362b3bb2 100644 --- a/cl/_testrt/panic/out.ll +++ b/cl/_testrt/panic/out.ll @@ -2,7 +2,7 @@ source_filename = "main" %"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 } -%"github.com/goplus/llgo/internal/runtime.iface" = type { ptr, ptr } +%"github.com/goplus/llgo/internal/runtime.eface" = type { ptr, ptr } @"main.init$guard" = global ptr null @__llgo_argc = global ptr null @@ -34,13 +34,23 @@ _llgo_0: %4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %2, i32 0, i32 1 store i64 13, ptr %4, align 4 %5 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %2, align 8 - %6 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String" %5) - call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface" %6) + %6 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 24) + %7 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %5, ptr %7, align 8 + %8 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %8, i32 0, i32 0 + store ptr %6, ptr %9, align 8 + %10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %8, i32 0, i32 1 + store ptr %7, ptr %10, align 8 + %11 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %8, align 8 + call void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface" %11) unreachable } declare void @"github.com/goplus/llgo/internal/runtime.init"() -declare %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAnyString"(%"github.com/goplus/llgo/internal/runtime.String") +declare ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64) -declare void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.iface") +declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64) + +declare void @"github.com/goplus/llgo/internal/runtime.TracePanic"(%"github.com/goplus/llgo/internal/runtime.eface") diff --git a/cl/_testrt/sum/out.ll b/cl/_testrt/sum/out.ll index e13b24a2..c36f08d1 100644 --- a/cl/_testrt/sum/out.ll +++ b/cl/_testrt/sum/out.ll @@ -36,9 +36,16 @@ _llgo_0: store i64 3, ptr %5, align 4 %6 = getelementptr inbounds i64, ptr %2, i64 3 store i64 4, ptr %6, align 4 - %7 = call %"github.com/goplus/llgo/internal/runtime.Slice" @"github.com/goplus/llgo/internal/runtime.NewSlice3"(ptr %2, i64 8, i64 4, i64 0, i64 4, i64 4) - %8 = call i64 @main.sum(%"github.com/goplus/llgo/internal/runtime.Slice" %7) - %9 = call i32 (ptr, ...) @printf(ptr @0, i64 %8) + %7 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 + %8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %7, i32 0, i32 0 + store ptr %2, ptr %8, align 8 + %9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %7, i32 0, i32 1 + store i64 4, ptr %9, align 4 + %10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %7, i32 0, i32 2 + store i64 4, ptr %10, align 4 + %11 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %7, align 8 + %12 = call i64 @main.sum(%"github.com/goplus/llgo/internal/runtime.Slice" %11) + %13 = call i32 (ptr, ...) @printf(ptr @0, i64 %12) ret i32 0 } @@ -71,8 +78,6 @@ declare void @"github.com/goplus/llgo/internal/runtime.init"() 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 i32 @printf(ptr, ...) declare void @"github.com/goplus/llgo/internal/runtime.AssertIndexRange"(i1) diff --git a/cl/compile.go b/cl/compile.go index 6974ee81..1b23d3b8 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -352,9 +352,9 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do last = len(instrs) - 1 instrs = instrs[:last] } else { - // TODO(xsw): confirm pyMod don't need to call LoadPyModSyms + // TODO(xsw): confirm pyMod don't need to call AfterInit p.inits = append(p.inits, func() { - pkg.PyLoadModSyms(b, ret) + pkg.AfterInit(b, ret) }) } } else if doMainInit { @@ -381,7 +381,7 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do cond := b.BinOp(token.NEQ, mod, prog.Null(mod.Type)) newBlk := p.fn.MakeBlock() b.If(cond, jumpTo, newBlk) - b.SetBlock(newBlk) + b.SetBlockEx(newBlk, llssa.AtEnd, false) b.Store(modPtr, b.PyImportMod(modPath)) b.Jump(jumpTo) } @@ -508,7 +508,7 @@ func isPhi(i ssa.Instruction) bool { func (p *context) compilePhis(b llssa.Builder, block *ssa.BasicBlock) int { ret := p.fn.Block(block.Index) - b.SetBlockEx(ret, llssa.AtEnd) + b.SetBlockEx(ret, llssa.AtEnd, false) if ninstr := len(block.Instrs); ninstr > 0 { if isPhi(block.Instrs[0]) { n := 1 diff --git a/cl/compile_test.go b/cl/compile_test.go index f1841da6..2d601ae2 100644 --- a/cl/compile_test.go +++ b/cl/compile_test.go @@ -28,12 +28,6 @@ func testCompile(t *testing.T, src, expected string) { cltest.TestCompileEx(t, src, "foo.go", expected) } -/* -func TestFromTestgo(t *testing.T) { - cltest.FromDir(t, "strucintf", "./_testgo", false) -} -*/ - func TestFromTestpy(t *testing.T) { cltest.FromDir(t, "", "./_testpy", false) } diff --git a/cl/internal/foo/foo.go b/cl/internal/foo/foo.go new file mode 100644 index 00000000..e385a31d --- /dev/null +++ b/cl/internal/foo/foo.go @@ -0,0 +1,9 @@ +package foo + +func Bar() any { + return struct{ V int }{1} +} + +func F() any { + return struct{ v int }{1} +} diff --git a/internal/abi/llgo_autogen.lla b/internal/abi/llgo_autogen.lla index 505458a8..7fed6350 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 085a6475..21f90142 100644 --- a/internal/abi/type.go +++ b/internal/abi/type.go @@ -84,14 +84,12 @@ const ( UnsafePointer ) -/* const ( // TODO (khr, drchase) why aren't these in TFlag? Investigate, fix if possible. KindDirectIface = 1 << 5 KindGCProg = 1 << 6 // Type.gc points to GC program KindMask = (1 << 5) - 1 ) -*/ // TFlag is used by a Type to signal what extra type information is // available in the memory directly following the Type value. @@ -229,7 +227,7 @@ type Imethod struct { Typ TypeOff // .(*FuncType) underneath } -func (t *Type) Kind() Kind { return Kind(t.Kind_) } +func (t *Type) Kind() Kind { return Kind(t.Kind_ & KindMask) } // Size returns the size of data with type t. func (t *Type) Size() uintptr { return t.Size_ } diff --git a/internal/runtime/llgo_autogen.lla b/internal/runtime/llgo_autogen.lla index 3bb1386b..a5c5b75b 100644 Binary files a/internal/runtime/llgo_autogen.lla and b/internal/runtime/llgo_autogen.lla differ diff --git a/internal/runtime/runtime2.go b/internal/runtime/runtime2.go index d0d8bea7..027c408f 100644 --- a/internal/runtime/runtime2.go +++ b/internal/runtime/runtime2.go @@ -8,21 +8,20 @@ import ( "unsafe" ) -type iface struct { - tab *itab - data unsafe.Pointer -} - -/* type eface struct { _type *_type data unsafe.Pointer } +/* func efaceOf(ep *any) *eface { return (*eface)(unsafe.Pointer(ep)) } -*/ + +type iface struct { + tab *itab + data unsafe.Pointer +} // layout of Itab known to compilers // allocated in non-garbage-collected memory @@ -35,3 +34,11 @@ type itab struct { _ [4]byte fun [1]uintptr // variable sized. fun[0]==0 means _type does not implement inter. } + +func MakeInterface(inter *InterfaceType, typ *Type, data unsafe.Pointer) Interface { + tab := &itab{inter: inter, _type: typ, hash: 0, fun: [1]uintptr{0}} + return Interface{ + tab: tab, data: data, + } +} +*/ diff --git a/internal/runtime/z_c.go b/internal/runtime/z_c.go index 1ea1efbd..2689b8cc 100644 --- a/internal/runtime/z_c.go +++ b/internal/runtime/z_c.go @@ -40,8 +40,8 @@ func Zeroinit(p c.Pointer, size uintptr) c.Pointer { } // TracePanic prints panic message. -func TracePanic(v Interface) { - kind := abi.Kind(v.tab._type.Kind_) +func TracePanic(v Eface) { + kind := abi.Kind(v._type.Kind_) switch { case kind == abi.String: stringTracef(c.Stderr, c.Str("panic: %s\n"), *(*String)(v.data)) diff --git a/internal/runtime/z_eface.go b/internal/runtime/z_eface.go new file mode 100644 index 00000000..a0f96d03 --- /dev/null +++ b/internal/runtime/z_eface.go @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package runtime + +import ( + "unsafe" + + "github.com/goplus/llgo/internal/abi" +) + +type Eface = eface + +// ----------------------------------------------------------------------------- + +func MakeAnyIntptr(typ *Type, data uintptr) Eface { + return eface{ + _type: typ, data: unsafe.Pointer(data), + } +} + +func MakeAnyString(data string) Eface { + typ := basicTypes[abi.String] + return eface{ + _type: typ, data: unsafe.Pointer(&data), + } +} + +func I2Int(v Eface, t *Type) uintptr { + if v._type == t { + return uintptr(v.data) + } + panic("I2Int: type mismatch") +} + +func CheckI2Int(v Eface, t *Type) (uintptr, bool) { + if v._type == t { + return uintptr(v.data), true + } + return 0, false +} + +func I2String(v Eface) string { + if v._type.Kind() == abi.String { + return *(*string)(v.data) + } + panic("I2String: type mismatch") +} + +func CheckI2String(v Eface) (string, bool) { + if v._type.Kind() == abi.String { + return *(*string)(v.data), true + } + return "", false +} + +// ----------------------------------------------------------------------------- diff --git a/internal/runtime/z_iface.go b/internal/runtime/z_iface.go deleted file mode 100644 index c64449ca..00000000 --- a/internal/runtime/z_iface.go +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package runtime - -import ( - "unsafe" - - "github.com/goplus/llgo/internal/abi" -) - -// ----------------------------------------------------------------------------- - -type InterfaceType = abi.InterfaceType - -var ( - TyAny = &InterfaceType{} -) - -// ----------------------------------------------------------------------------- - -type Interface = iface - -func MakeAnyIntptr(typ *Type, data uintptr) Interface { - tab := &itab{inter: TyAny, _type: typ, hash: 0, fun: [1]uintptr{0}} - return Interface{ - tab: tab, data: unsafe.Pointer(data), - } -} - -func MakeAnyString(data string) Interface { - typ := basicTypes[abi.String] - tab := &itab{inter: TyAny, _type: typ, hash: 0, fun: [1]uintptr{0}} - return Interface{ - tab: tab, data: unsafe.Pointer(&data), - } -} - -func MakeAny(typ *Type, data unsafe.Pointer) Interface { - tab := &itab{inter: TyAny, _type: typ, hash: 0, fun: [1]uintptr{0}} - return Interface{ - tab: tab, data: data, - } -} - -func MakeInterface(inter *InterfaceType, typ *Type, data unsafe.Pointer) Interface { - tab := &itab{inter: inter, _type: typ, hash: 0, fun: [1]uintptr{0}} - return Interface{ - tab: tab, data: data, - } -} - -func I2Int(v Interface, t *Type) uintptr { - if v.tab._type == t { - return uintptr(v.data) - } - panic("I2Int: type mismatch") -} - -func CheckI2Int(v Interface, t *Type) (uintptr, bool) { - if v.tab._type == t { - return uintptr(v.data), true - } - return 0, false -} - -func I2String(v Interface, t *Type) string { - if v.tab._type == t { - return *(*string)(v.data) - } - panic("I2String: type mismatch") -} - -func CheckI2String(v Interface, t *Type) (string, bool) { - if v.tab._type == t { - return *(*string)(v.data), true - } - return "", false -} - -// ----------------------------------------------------------------------------- diff --git a/internal/runtime/z_print.go b/internal/runtime/z_print.go index 4d4ea802..7aeca7f3 100644 --- a/internal/runtime/z_print.go +++ b/internal/runtime/z_print.go @@ -66,6 +66,6 @@ func PrintSlice(s Slice) { print("[", s.len, "/", s.cap, "]", s.data) } -func PrintIface(i Interface) { - print("(", i.tab, ",", i.data, ")") +func PrintEface(e Eface) { + print("(", e._type, ",", e.data, ")") } diff --git a/internal/runtime/z_type.go b/internal/runtime/z_type.go index f9915453..a4860621 100644 --- a/internal/runtime/z_type.go +++ b/internal/runtime/z_type.go @@ -97,15 +97,16 @@ func StructField(name string, typ *Type, off uintptr, tag string, exported, embe // Struct returns a struct type. func Struct(size uintptr, pkgPath string, fields ...abi.StructField) *Type { - npkg := abi.NewName(pkgPath, "", false, false) + // TODO(xsw): pkgPath + // npkg := abi.NewName(pkgPath, "", false, false) ret := &abi.StructType{ Type: Type{ Size_: size, Hash: uint32(abi.Struct), // TODO(xsw): hash Kind_: uint8(abi.Struct), }, - PkgPath: npkg, - Fields: fields, + // PkgPath: npkg, + Fields: fields, } return &ret.Type } diff --git a/ssa/_abi/abi.go b/ssa/_abi/abi.go deleted file mode 100644 index 65578218..00000000 --- a/ssa/_abi/abi.go +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package abi - -import ( - "crypto/sha256" - "encoding/base64" - "fmt" - "go/types" - "hash" -) - -// Builder is a helper for constructing ABI types. -type Builder struct { - h hash.Hash - buf []byte -} - -// New creates a new ABI type Builder. -func New() *Builder { - h := sha256.New() - buf := make([]byte, sha256.Size) - return &Builder{h, buf} -} - -// TypeName returns the ABI type name for the specified type. -func (b *Builder) TypeName(t types.Type) string { - switch t := t.(type) { - case *types.Basic: - return t.Name() - case *types.Pointer: - return "*" + b.TypeName(t.Elem()) - case *types.Struct: - return b.StructName(t) - } - panic("todo") -} - -// StructName returns the ABI type name for the specified struct type. -func (b *Builder) StructName(t *types.Struct) string { - hash := b.structHash(t) - return "struct$" + base64.RawURLEncoding.EncodeToString(hash) -} - -func (b *Builder) structHash(t *types.Struct) []byte { - h := b.h - h.Reset() - n := t.NumFields() - fmt.Fprintln(h, "struct", n) - for i := 0; i < n; i++ { - f := t.Field(i) - name := f.Name() - if f.Embedded() { - name = "-" - } - fmt.Fprintln(h, name, b.TypeName(f.Type())) - } - return h.Sum(b.buf[:0]) -} diff --git a/ssa/abi/abi.go b/ssa/abi/abi.go new file mode 100644 index 00000000..042755f8 --- /dev/null +++ b/ssa/abi/abi.go @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package abi + +import ( + "crypto/sha256" + "encoding/base64" + "fmt" + "go/types" + "hash" + + "github.com/goplus/llgo/internal/abi" +) + +// ----------------------------------------------------------------------------- + +func BasicKind(t *types.Basic) abi.Kind { + kind := t.Kind() + switch kind { + case types.String: + return abi.String + case types.UnsafePointer: + return abi.UnsafePointer + } + return abi.Kind(kind) +} + +// ----------------------------------------------------------------------------- + +type Kind int + +const ( + Invalid Kind = iota + Indirect // allocate memory for the value + Pointer // store a pointer value directly in the interface value + Integer // store a integer value directly in the interface value + BitCast // store other value (need bitcast) directly in the interface value +) + +func KindOf(raw types.Type, lvl int, is32Bits bool) (Kind, types.Type, int) { + switch t := raw.Underlying().(type) { + case *types.Basic: + kind := t.Kind() + switch { + case types.Bool <= kind && kind <= types.Uintptr: + if is32Bits && (kind == types.Int64 || kind == types.Uint64) { + return Indirect, raw, lvl + } + return Integer, raw, lvl + case kind == types.Float32: + return BitCast, raw, lvl + case kind == types.Float64 || kind == types.Complex64: + if is32Bits { + return Indirect, raw, lvl + } + return BitCast, raw, lvl + case kind == types.UnsafePointer: + return Pointer, raw, lvl + } + case *types.Pointer, *types.Signature, *types.Map, *types.Chan: + return Pointer, raw, lvl + case *types.Struct: + if t.NumFields() == 1 { + return KindOf(t.Field(0).Type(), lvl+1, is32Bits) + } + case *types.Interface, *types.Slice: + case *types.Array: + if t.Len() == 1 { + return KindOf(t.Elem(), lvl+1, is32Bits) + } + default: + panic("unkown type") + } + return Indirect, raw, lvl +} + +// ----------------------------------------------------------------------------- + +// Builder is a helper for constructing ABI types. +type Builder struct { + h hash.Hash + buf []byte + Pkg string +} + +// New creates a new ABI type Builder. +func New(pkg string) *Builder { + ret := new(Builder) + ret.Init(pkg) + return ret +} + +func (b *Builder) Init(pkg string) { + b.Pkg = pkg + b.h = sha256.New() + b.buf = make([]byte, sha256.Size) +} + +// TypeName returns the ABI type name for the specified type. +func (b *Builder) TypeName(t types.Type) (ret string, private bool) { + switch t := t.(type) { + case *types.Basic: + return BasicName(t), false + case *types.Pointer: + ret, private = b.TypeName(t.Elem()) + return "*" + ret, private + case *types.Struct: + return b.StructName(t) + } + panic("todo") +} + +func BasicName(t *types.Basic) string { + return "_llgo_" + t.Name() +} + +// StructName returns the ABI type name for the specified struct type. +func (b *Builder) StructName(t *types.Struct) (ret string, private bool) { + hash, private := b.structHash(t) + hashStr := base64.RawURLEncoding.EncodeToString(hash) + if private { + return b.Pkg + ".struct$" + hashStr, true + } + return "_llgo_struct$" + hashStr, false +} + +func (b *Builder) structHash(t *types.Struct) (ret []byte, private bool) { + h := b.h + h.Reset() + n := t.NumFields() + fmt.Fprintln(h, "struct", n) + for i := 0; i < n; i++ { + f := t.Field(i) + if !f.Exported() { + private = true + } + name := f.Name() + if f.Embedded() { + name = "-" + } + ft, fpriv := b.TypeName(f.Type()) + if fpriv { + private = true + } + fmt.Fprintln(h, name, ft) + } + ret = h.Sum(b.buf[:0]) + return +} + +// ----------------------------------------------------------------------------- diff --git a/ssa/cl_test.go b/ssa/cl_test.go index c89a0958..513944c1 100644 --- a/ssa/cl_test.go +++ b/ssa/cl_test.go @@ -25,6 +25,10 @@ import ( "github.com/goplus/llgo/ssa/ssatest" ) +func TestFromTestgo(t *testing.T) { + cltest.FromDir(t, "", "../cl/_testgo", false) +} + func TestFromTestpy(t *testing.T) { cltest.FromDir(t, "", "../cl/_testpy", false) } @@ -56,26 +60,34 @@ func TestMakeInterface(t *testing.T) { ssatest.Assert(t, pkg, `; ModuleID = 'foo' source_filename = "foo" -%"github.com/goplus/llgo/internal/runtime.iface" = type { ptr, ptr } +%"github.com/goplus/llgo/internal/runtime.eface" = type { ptr, ptr } define void @main() { _llgo_0: - %0 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8) - store i64 100, ptr %0, align 4 - %1 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 6) - %2 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAny"(ptr %1, ptr %0) - %3 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8) - store double 1.000000e+02, ptr %3, align 8 - %4 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 14) - %5 = call %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAny"(ptr %4, ptr %3) + %0 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 6) + %1 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8) + store i64 100, ptr %1, align 4 + %2 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %3 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %2, i32 0, i32 0 + store ptr %0, ptr %3, align 8 + %4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %2, i32 0, i32 1 + store ptr %1, ptr %4, align 8 + %5 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %2, align 8 + %6 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 14) + %7 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8) + store double 1.000000e+02, ptr %7, align 8 + %8 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %8, i32 0, i32 0 + store ptr %6, ptr %9, align 8 + %10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %8, i32 0, i32 1 + store ptr %7, ptr %10, align 8 + %11 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %8, align 8 ret void } -declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64) - -declare %"github.com/goplus/llgo/internal/runtime.iface" @"github.com/goplus/llgo/internal/runtime.MakeAny"(ptr, ptr) - declare ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64) + +declare ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64) `) } diff --git a/ssa/datastruct.go b/ssa/datastruct.go index 0ce70e97..0ff80d6a 100644 --- a/ssa/datastruct.go +++ b/ssa/datastruct.go @@ -70,9 +70,8 @@ func (b Builder) StringData(x Expr) Expr { if debugInstr { log.Printf("StringData %v\n", x.impl) } - prog := b.Prog ptr := llvm.CreateExtractValue(b.impl, x.impl, 0) - return Expr{ptr, prog.CStr()} + return Expr{ptr, b.Prog.CStr()} } // StringLen returns the length of a string. @@ -80,9 +79,8 @@ func (b Builder) StringLen(x Expr) Expr { if debugInstr { log.Printf("StringLen %v\n", x.impl) } - prog := b.Prog ptr := llvm.CreateExtractValue(b.impl, x.impl, 1) - return Expr{ptr, prog.Int()} + return Expr{ptr, b.Prog.Int()} } // SliceData returns the data pointer of a slice. @@ -90,9 +88,8 @@ func (b Builder) SliceData(x Expr) Expr { if debugInstr { log.Printf("SliceData %v\n", x.impl) } - prog := b.Prog ptr := llvm.CreateExtractValue(b.impl, x.impl, 0) - return Expr{ptr, prog.CStr()} + return Expr{ptr, b.Prog.VoidPtr()} } // SliceLen returns the length of a slice. @@ -100,9 +97,8 @@ func (b Builder) SliceLen(x Expr) Expr { if debugInstr { log.Printf("SliceLen %v\n", x.impl) } - prog := b.Prog ptr := llvm.CreateExtractValue(b.impl, x.impl, 1) - return Expr{ptr, prog.Int()} + return Expr{ptr, b.Prog.Int()} } // SliceCap returns the length of a slice cap. @@ -110,9 +106,8 @@ func (b Builder) SliceCap(x Expr) Expr { if debugInstr { log.Printf("SliceCap %v\n", x.impl) } - prog := b.Prog ptr := llvm.CreateExtractValue(b.impl, x.impl, 2) - return Expr{ptr, prog.Int()} + return Expr{ptr, b.Prog.Int()} } // The IndexAddr instruction yields the address of the element at @@ -188,7 +183,7 @@ func (b Builder) Index(x, idx Expr, addr func(Expr) Expr) Expr { if addr != nil { ptr = addr(x) } else { - size := b.SizeOf(telem, t.Len()) + size := SizeOf(prog, telem, t.Len()) ptr = b.Alloca(size) b.Store(ptr, x) } @@ -240,7 +235,8 @@ func (b Builder) Slice(x, low, high, max Expr) (ret Expr) { var nCap Expr var nEltSize Expr var base Expr - if low.IsNil() { + var lowIsNil = low.IsNil() + if lowIsNil { low = prog.IntVal(0, prog.Int()) } switch t := x.raw.Type.Underlying().(type) { @@ -255,7 +251,7 @@ func (b Builder) Slice(x, low, high, max Expr) (ret Expr) { ret.impl = b.InlineCall(b.Pkg.rtFunc("NewStringSlice"), x, low, high).impl return case *types.Slice: - nEltSize = b.SizeOf(prog.Index(x.Type)) + nEltSize = SizeOf(prog, prog.Index(x.Type)) nCap = b.SliceCap(x) if high.IsNil() { high = b.SliceCap(x) @@ -268,9 +264,12 @@ func (b Builder) Slice(x, low, high, max Expr) (ret Expr) { case *types.Array: elem := prog.rawType(te.Elem()) ret.Type = prog.Slice(elem) - nEltSize = b.SizeOf(elem) + nEltSize = SizeOf(prog, elem) nCap = prog.IntVal(uint64(te.Len()), prog.Int()) if high.IsNil() { + if lowIsNil && max.IsNil() { + return b.unsafeSlice(x, nCap.impl, nCap.impl) + } high = nCap } base = x @@ -283,6 +282,18 @@ func (b Builder) Slice(x, low, high, max Expr) (ret Expr) { return } +// SliceLit creates a new slice with the specified elements. +func (b Builder) SliceLit(t Type, elts ...Expr) Expr { + prog := b.Prog + telem := prog.Index(t) + ptr := b.AllocU(telem, int64(len(elts))) + for i, elt := range elts { + b.Store(b.Advance(ptr, prog.Val(i)), elt) + } + size := llvm.ConstInt(prog.tyInt(), uint64(len(elts)), false) + return b.unsafeSlice(ptr, size, size) +} + // ----------------------------------------------------------------------------- // The MakeMap instruction creates a new hash-table-based map object @@ -323,10 +334,11 @@ func (b Builder) MakeSlice(t Type, len, cap Expr) (ret Expr) { log.Printf("MakeSlice %v, %v, %v\n", t.RawType(), len.impl, cap.impl) } pkg := b.Pkg + prog := b.Prog if cap.IsNil() { cap = len } - elemSize := b.SizeOf(b.Prog.Index(t)) + elemSize := SizeOf(prog, 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 diff --git a/ssa/decl.go b/ssa/decl.go index 97856aa3..2ff49cde 100644 --- a/ssa/decl.go +++ b/ssa/decl.go @@ -58,6 +58,13 @@ type aNamedConst struct { // it augments with the name and position of its 'const' declaration. type NamedConst = *aNamedConst +/* +// NewConst creates a new named constant. +func (p Package) NewConst(name string, val constant.Value) NamedConst { + return &aNamedConst{} +} +*/ + // ----------------------------------------------------------------------------- type aGlobal struct { @@ -75,9 +82,21 @@ func (p Package) NewVar(name string, typ types.Type, bg Background) Global { return v } t := p.Prog.Type(typ, bg) + return p.doNewVar(name, t) +} + +// NewVarFrom creates a new global variable. +func (p Package) NewVarFrom(name string, t Type) Global { + if v, ok := p.vars[name]; ok { + return v + } + return p.doNewVar(name, t) +} + +func (p Package) doNewVar(name string, t Type) Global { var gbl llvm.Value var array bool - if t.kind == vkPtr && p.Prog.Elem(t).kind == vkArray { + if t.kind == vkPtr && p.Prog.Elem(t).kind == vkArray { // TODO(xsw): check this code typ := p.Prog.Elem(t).ll gbl = llvm.AddGlobal(p.mod, typ, name) gbl.SetInitializer(llvm.Undef(typ)) @@ -97,7 +116,7 @@ func (p Package) VarOf(name string) Global { // Init initializes the global variable with the given value. func (g Global) Init(v Expr) { - if g.array && v.kind == vkPtr { + if g.array && v.kind == vkPtr { // TODO(xsw): check this code return } g.impl.SetInitializer(v.impl) @@ -219,6 +238,13 @@ func newParams(fn Type, prog Program) (params []Type, hasVArg bool) { return } +/* +// Name returns the function's name. +func (p Function) Name() string { + return p.impl.Name() +} +*/ + // Params returns the function's ith parameter. func (p Function) Param(i int) Expr { i += p.base // skip if hasFreeVars @@ -248,7 +274,7 @@ func (p Function) NewBuilder() Builder { b := prog.ctx.NewBuilder() // TODO(xsw): Finalize may cause panic, so comment it. // b.Finalize() - return &aBuilder{b, p, p.Pkg, prog} + return &aBuilder{b, nil, p, p.Pkg, prog} } // HasBody reports whether the function has a body. @@ -261,7 +287,8 @@ func (p Function) HasBody() bool { func (p Function) MakeBody(nblk int) Builder { p.MakeBlocks(nblk) b := p.NewBuilder() - b.impl.SetInsertPointAtEnd(p.blks[0].impl) + b.blk = p.blks[0] + b.impl.SetInsertPointAtEnd(b.blk.last) return b } @@ -280,7 +307,7 @@ func (p Function) MakeBlocks(nblk int) []BasicBlock { func (p Function) addBlock(idx int) BasicBlock { label := "_llgo_" + strconv.Itoa(idx) blk := llvm.AddBasicBlock(p.impl, label) - ret := &aBasicBlock{blk, p, idx} + ret := &aBasicBlock{blk, blk, p, idx} p.blks = append(p.blks, ret) return ret } @@ -350,15 +377,14 @@ func (p Package) PyObjOf(name string) PyObjRef { return p.pyobjs[name] } -// PyLoadModSyms loads module symbols used in this package. -func (p Package) PyLoadModSyms(b Builder, ret BasicBlock) { - objs := p.pyobjs - n := len(objs) - if n == 0 { - return - } +func (p Package) pyHasModSyms() bool { + return len(p.pyobjs) > 0 +} - names := make([]string, 0, n) +// pyLoadModSyms loads module symbols used in this package. +func (p Package) pyLoadModSyms(b Builder) { + objs := p.pyobjs + names := make([]string, 0, len(objs)) for name := range objs { names = append(names, name) } @@ -376,7 +402,6 @@ func (p Package) PyLoadModSyms(b Builder, ret BasicBlock) { } } - b.SetBlockEx(ret, afterInit) for _, modName := range modNames { objs := mods[modName] b.PyLoadModSyms(modName, objs...) diff --git a/ssa/expr.go b/ssa/expr.go index 49ccc6d9..6fce4fbe 100644 --- a/ssa/expr.go +++ b/ssa/expr.go @@ -93,6 +93,40 @@ func phisExpr(t Type, phis []llvm.Value) Expr { // ----------------------------------------------------------------------------- +func (p Program) Zero(t Type) Expr { + var ret llvm.Value + switch u := t.raw.Type.Underlying().(type) { + case *types.Basic: + kind := u.Kind() + switch { + case kind >= types.Bool && kind <= types.Uintptr: + ret = llvm.ConstInt(p.rawType(u).ll, 0, false) + case kind == types.String: + ret = p.Zero(p.rtType("String")).impl + case kind == types.UnsafePointer: + ret = llvm.ConstPointerNull(p.tyVoidPtr()) + case kind <= types.Float64: + ret = llvm.ConstFloat(p.Float64().ll, 0) + case kind == types.Float32: + ret = llvm.ConstFloat(p.Float32().ll, 0) + default: + panic("todo") + } + case *types.Pointer: + return Expr{llvm.ConstNull(t.ll), t} + case *types.Struct: + n := u.NumFields() + flds := make([]llvm.Value, n) + for i := 0; i < n; i++ { + flds[i] = p.Zero(p.rawType(u.Field(i).Type())).impl + } + ret = llvm.ConstStruct(flds, false) + default: + log.Panicln("todo:", u) + } + return Expr{ret, t} +} + // Null returns a null constant expression. func (p Program) Null(t Type) Expr { return Expr{llvm.ConstNull(t.ll), t} @@ -125,12 +159,6 @@ func (p Program) FloatVal(v float64, t Type) Expr { return Expr{ret, t} } -func (p Program) ByteVal(v byte) Expr { - t := p.Byte() - ret := llvm.ConstInt(t.ll, uint64(v), false) - return Expr{ret, t} -} - // Val returns a constant expression. func (p Program) Val(v interface{}) Expr { switch v := v.(type) { @@ -180,13 +208,6 @@ func (b Builder) Const(v constant.Value, typ Type) Expr { panic(fmt.Sprintf("unsupported Const: %v, %v", v, raw)) } -// 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. func (b Builder) CStr(v string) Expr { return Expr{llvm.CreateGlobalStringPtr(b.impl, v), b.Prog.CStr()} @@ -200,10 +221,17 @@ func (b Builder) Str(v string) (ret Expr) { return Expr{aggregateValue(b.impl, prog.rtString(), data, size), prog.String()} } -// unsafe.String(data *byte, size int) string -func (b Builder) String(data, size Expr) Expr { +// unsafeString(data *byte, size int) string +func (b Builder) unsafeString(data, size llvm.Value) Expr { prog := b.Prog - return Expr{aggregateValue(b.impl, prog.rtString(), data.impl, size.impl), prog.String()} + return Expr{aggregateValue(b.impl, prog.rtString(), data, size), prog.String()} +} + +// unsafeSlice(data *T, size, cap int) []T +func (b Builder) unsafeSlice(data Expr, size, cap llvm.Value) Expr { + prog := b.Prog + tslice := prog.Slice(prog.Elem(data.Type)) + return Expr{aggregateValue(b.impl, prog.rtSlice(), data.impl, size, cap), tslice} } // ----------------------------------------------------------------------------- @@ -397,7 +425,7 @@ func (b Builder) UnOp(op token.Token, x Expr) (ret Expr) { case token.MUL: return b.Load(x) case token.SUB: - switch t := x.Type.raw.Underlying().(type) { + switch t := x.raw.Type.Underlying().(type) { case *types.Basic: ret.Type = x.Type if t.Info()&types.IsInteger != 0 { @@ -489,10 +517,10 @@ func llvmDelayValues(f func(i int) Expr, n int) []llvm.Value { return ret } -func llvmBlocks(bblks []BasicBlock) []llvm.BasicBlock { - ret := make([]llvm.BasicBlock, len(bblks)) - for i, v := range bblks { - ret[i] = v.impl +func llvmPredBlocks(preds []BasicBlock) []llvm.BasicBlock { + ret := make([]llvm.BasicBlock, len(preds)) + for i, v := range preds { + ret[i] = v.last } return ret } @@ -503,24 +531,24 @@ type Phi struct { } // AddIncoming adds incoming values to a phi node. -func (p Phi) AddIncoming(b Builder, bblks []BasicBlock, f func(i int) Expr) { - bs := llvmBlocks(bblks) +func (p Phi) AddIncoming(b Builder, preds []BasicBlock, f func(i int) Expr) { + bs := llvmPredBlocks(preds) if p.kind != vkPhisExpr { // normal phi node - vs := llvmDelayValues(f, len(bblks)) + vs := llvmDelayValues(f, len(preds)) p.impl.AddIncoming(vs, bs) return } e := p.raw.Type.(*phisExprTy) phis := e.phis vals := make([][]llvm.Value, len(phis)) - for iblk, blk := range bblks { - last := blk.impl.LastInstruction() + for iblk, blk := range preds { + last := blk.last.LastInstruction() b.impl.SetInsertPointBefore(last) impl := b.impl val := f(iblk).impl for i := range phis { if iblk == 0 { - vals[i] = make([]llvm.Value, len(bblks)) + vals[i] = make([]llvm.Value, len(preds)) } vals[i][iblk] = llvm.CreateExtractValue(impl, val, i) } @@ -667,7 +695,7 @@ func (b Builder) Alloc(elem Type, heap bool) (ret Expr) { } prog := b.Prog pkg := b.Pkg - size := b.SizeOf(elem) + size := SizeOf(prog, elem) if heap { ret = b.InlineCall(pkg.rtFunc("AllocZ"), size) } else { @@ -683,9 +711,10 @@ func (b Builder) AllocU(elem Type, n ...int64) (ret Expr) { if debugInstr { log.Printf("AllocU %v, %v\n", elem.raw.Type, n) } - size := b.SizeOf(elem, n...) + prog := b.Prog + size := SizeOf(prog, elem, n...) ret = b.InlineCall(b.Pkg.rtFunc("AllocU"), size) - ret.Type = b.Prog.Pointer(elem) + ret.Type = prog.Pointer(elem) return } @@ -940,21 +969,6 @@ func (b Builder) Call(fn Expr, args ...Expr) (ret Expr) { return } -// The Extract instruction yields component Index of Tuple. -// -// This is used to access the results of instructions with multiple -// return values, such as Call, TypeAssert, Next, UnOp(ARROW) and -// IndexExpr(Map). -// -// Example printed form: -// -// t1 = extract t0 #1 -func (b Builder) Extract(x Expr, index int) (ret Expr) { - ret.Type = b.Prog.toType(x.Type.raw.Type.(*types.Tuple).At(index).Type()) - ret.impl = llvm.CreateExtractValue(b.impl, x.impl, index) - return -} - // A Builtin represents a specific use of a built-in function, e.g. len. // // Builtins are immutable values. Builtins do not have addresses. @@ -1008,7 +1022,7 @@ func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr) { ret.Type = prog.Void() for i, arg := range args { if ln && i > 0 { - b.InlineCall(b.Pkg.rtFunc("PrintByte"), prog.ByteVal(' ')) + b.InlineCall(b.Pkg.rtFunc("PrintByte"), prog.IntVal(' ', prog.Byte())) } var fn string typ := arg.Type @@ -1035,8 +1049,8 @@ func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr) { typ = prog.VoidPtr() case vkString: fn = "PrintString" - case vkInterface: - fn = "PrintIface" + case vkEface: + fn = "PrintEface" // case vkComplex: // fn = "PrintComplex" default: @@ -1048,7 +1062,7 @@ func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr) { b.InlineCall(b.Pkg.rtFunc(fn), arg) } if ln { - b.InlineCall(b.Pkg.rtFunc("PrintByte"), prog.ByteVal('\n')) + b.InlineCall(b.Pkg.rtFunc("PrintByte"), prog.IntVal('\n', prog.Byte())) } return case "copy": @@ -1067,7 +1081,10 @@ func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr) { } } case "String": // unsafe.String - return b.String(args[0], args[1]) + return b.unsafeString(args[0].impl, args[1].impl) + case "Slice": // unsafe.Slice + size := args[1].impl + return b.unsafeSlice(args[0], size, size) } panic("todo: " + fn) } diff --git a/ssa/interface.go b/ssa/interface.go index 16004054..c1104663 100644 --- a/ssa/interface.go +++ b/ssa/interface.go @@ -20,36 +20,107 @@ import ( "go/token" "go/types" "log" + "unsafe" - "github.com/goplus/llgo/internal/abi" + "github.com/goplus/llgo/ssa/abi" "github.com/goplus/llvm" ) // ----------------------------------------------------------------------------- // abiBasic returns the abi type of the specified basic kind. -func (b Builder) abiBasic(kind types.BasicKind) Expr { - return b.InlineCall(b.Pkg.rtFunc("Basic"), b.Prog.Val(int(kind))) +func (b Builder) abiBasic(t *types.Basic) Expr { + /* + TODO(xsw): + name := abi.BasicName(t) + g := b.Pkg.NewVarFrom(name, b.Prog.AbiTypePtrPtr()) + return b.Load(g.Expr) + */ + kind := int(abi.BasicKind(t)) + return b.InlineCall(b.Pkg.rtFunc("Basic"), b.Prog.Val(kind)) } -/* // abiStruct returns the abi type of the specified struct type. func (b Builder) abiStruct(t *types.Struct) Expr { - // name := "__llgo_" + b.Prog.abi.StructName(t) + pkg := b.Pkg + name, private := pkg.abi.StructName(t) + g := pkg.VarOf(name) + if g == nil { + prog := b.Prog + g = pkg.doNewVar(name, prog.AbiTypePtrPtr()) + g.Init(prog.Null(g.Type)) + pub := !private + if pub { + g.impl.SetLinkage(llvm.LinkOnceAnyLinkage) + } + pkg.abiini = append(pkg.abiini, func(param unsafe.Pointer) { + b := Builder(param) + expr := g.Expr + var blks []BasicBlock + if pub { + eq := b.BinOp(token.EQL, b.Load(expr), b.Prog.Null(expr.Type)) + blks = b.Func.MakeBlocks(2) + b.If(eq, blks[0], blks[1]) + b.SetBlockEx(blks[0], AtEnd, false) + } + tabi := b.structOf(t) + b.Store(expr, tabi) + if pub { + b.Jump(blks[1]) + b.SetBlockEx(blks[1], AtEnd, false) + b.blk.last = blks[1].last + } + }) + } + return b.Load(g.Expr) } -*/ -// AbiType returns the abi type of the specified type. -func (b Builder) AbiType(t Type) Expr { - switch tx := t.raw.Type.(type) { +// func Struct(size uintptr, pkgPath string, fields []abi.StructField) *abi.Type +func (b Builder) structOf(t *types.Struct) Expr { + pkg := b.Pkg + prog := b.Prog + n := t.NumFields() + flds := make([]Expr, n) + strucAbi := pkg.rtFunc("Struct") + sfAbi := pkg.rtFunc("StructField") + typ := prog.rawType(t) + for i := 0; i < n; i++ { + f := t.Field(i) + off := uintptr(prog.OffsetOf(typ, i)) + flds[i] = b.structField(sfAbi, prog, f, off, t.Tag(i)) + } + pkgPath := b.Str(pkg.abi.Pkg) + params := strucAbi.raw.Type.(*types.Signature).Params() + tSlice := prog.rawType(params.At(params.Len() - 1).Type().(*types.Slice)) + fldSlice := b.SliceLit(tSlice, flds...) + return b.Call(strucAbi, pkgPath, fldSlice) +} + +// func StructField(name string, typ *abi.Type, off uintptr, tag string, exported, 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) +} + +// abiType returns the abi type of the specified type. +func (b Builder) abiType(raw types.Type) Expr { + switch tx := raw.(type) { case *types.Basic: - return b.abiBasic(tx.Kind()) - //case *types.Struct: - // return b.abiStruct(tx) + return b.abiBasic(tx) + case *types.Struct: + return b.abiStruct(tx) } panic("todo") } +// unsafeEface(t *abi.Type, data unsafe.Pointer) Eface +func (b Builder) unsafeEface(t, data llvm.Value) llvm.Value { + return aggregateValue(b.impl, b.Prog.rtEface(), t, data) +} + // ----------------------------------------------------------------------------- // MakeInterface constructs an instance of an interface type from a @@ -73,60 +144,84 @@ func (b Builder) MakeInterface(tinter Type, x Expr) (ret Expr) { } prog := b.Prog typ := x.Type - switch tx := typ.raw.Type.Underlying().(type) { - case *types.Basic: - kind := tx.Kind() - switch { - case kind >= types.Bool && kind <= types.Uintptr: - if prog.is32Bits && (kind == types.Int64 || kind == types.Uint64) { - return b.makeIntfAlloc(tinter, rawIntf, typ, x) - } - return b.makeIntfByIntptr(tinter, rawIntf, typ, x.impl) - case kind == types.Float32: - i32 := llvm.CreateBitCast(b.impl, x.impl, prog.tyInt32()) - return b.makeIntfByIntptr(tinter, rawIntf, typ, i32) - case kind == types.Float64: - if prog.is32Bits { - return b.makeIntfAlloc(tinter, rawIntf, typ, x) - } - i64 := llvm.CreateBitCast(b.impl, x.impl, prog.tyInt64()) - return b.makeIntfByIntptr(tinter, rawIntf, typ, i64) - case kind == types.String: - return Expr{b.InlineCall(b.Pkg.rtFunc("MakeAnyString"), x).impl, tinter} + tabi := b.abiType(typ.raw.Type) + kind, _, lvl := abi.KindOf(typ.raw.Type, 0, prog.is32Bits) + switch kind { + case abi.Indirect: + vptr := b.AllocU(typ) + b.Store(vptr, x) + return Expr{b.unsafeEface(tabi.impl, vptr.impl), tinter} + } + ximpl := x.impl + if lvl > 0 { + ximpl = extractVal(b.impl, ximpl, lvl) + } + var u llvm.Value + switch kind { + case abi.Pointer: + return Expr{b.unsafeEface(tabi.impl, ximpl), tinter} + case abi.Integer: + tu := prog.Uintptr() + u = llvm.CreateIntCast(b.impl, ximpl, tu.ll) + case abi.BitCast: + tu := prog.Uintptr() + u = llvm.CreateBitCast(b.impl, ximpl, tu.ll) + default: + panic("todo") + } + data := llvm.CreateIntToPtr(b.impl, u, prog.tyVoidPtr()) + return Expr{b.unsafeEface(tabi.impl, data), tinter} +} + +func (b Builder) valFromData(typ Type, data llvm.Value) Expr { + prog := b.Prog + kind, real, lvl := abi.KindOf(typ.raw.Type, 0, prog.is32Bits) + switch kind { + case abi.Indirect: + impl := b.impl + tll := typ.ll + tptr := llvm.PointerType(tll, 0) + ptr := llvm.CreatePointerCast(impl, data, tptr) + return Expr{llvm.CreateLoad(impl, tll, ptr), typ} + } + t := typ + if lvl > 0 { + t = prog.rawType(real) + } + switch kind { + case abi.Pointer: + return b.buildVal(typ, data, lvl) + case abi.Integer: + x := castUintptr(b, data, prog.Uintptr()) + return b.buildVal(typ, castInt(b, x, t), lvl) + case abi.BitCast: + x := castUintptr(b, data, prog.Uintptr()) + if int(prog.SizeOf(t)) != prog.PointerSize() { + x = castInt(b, x, prog.Int32()) } - /* case *types.Struct: - size := int(prog.SizeOf(typ)) - if size > prog.PointerSize() { - return b.makeIntfAlloc(tinter, rawIntf, typ, x) - } - tv := prog.ctx.IntType(size * 8) - iv := llvm.CreateBitCast(b.impl, x.impl, tv) - return b.makeIntfByIntptr(tinter, rawIntf, typ, iv) */ + return b.buildVal(typ, llvm.CreateBitCast(b.impl, x, t.ll), lvl) } panic("todo") } -func (b Builder) makeIntfAlloc(tinter Type, rawIntf *types.Interface, typ Type, x Expr) (ret Expr) { - vptr := b.AllocU(typ) - b.Store(vptr, x) - return b.makeIntfByPtr(tinter, rawIntf, typ, vptr) -} - -func (b Builder) makeIntfByPtr(tinter Type, rawIntf *types.Interface, typ Type, vptr Expr) (ret Expr) { - if rawIntf.Empty() { - ret = b.InlineCall(b.Pkg.rtFunc("MakeAny"), b.AbiType(typ), vptr) - ret.Type = tinter - return +func extractVal(b llvm.Builder, val llvm.Value, lvl int) llvm.Value { + for lvl > 0 { + // TODO(xsw): check array support + val = llvm.CreateExtractValue(b, val, 0) + lvl-- } - panic("todo") + return val } -func (b Builder) makeIntfByIntptr(tinter Type, rawIntf *types.Interface, typ Type, x llvm.Value) (ret Expr) { - if rawIntf.Empty() { - tptr := b.Prog.Uintptr() - x = llvm.CreateIntCast(b.impl, x, tptr.ll) - impl := b.InlineCall(b.Pkg.rtFunc("MakeAnyIntptr"), b.AbiType(typ), Expr{x, tptr}).impl - return Expr{impl, tinter} +func (b Builder) buildVal(typ Type, val llvm.Value, lvl int) Expr { + if lvl == 0 { + return Expr{val, typ} + } + switch t := typ.raw.Type.Underlying().(type) { + case *types.Struct: + telem := b.Prog.rawType(t.Field(0).Type()) + elem := b.buildVal(telem, val, lvl-1) + return Expr{aggregateValue(b.impl, typ.ll, elem.impl), typ} } panic("todo") } @@ -170,10 +265,40 @@ func (b Builder) makeIntfByIntptr(tinter Type, rawIntf *types.Interface, typ Typ // // t1 = typeassert t0.(int) // t3 = typeassert,ok t2.(T) +func (b Builder) TypeAssert(x Expr, assertedTyp Type, commaOk bool) Expr { + if debugInstr { + log.Printf("TypeAssert %v, %v, %v\n", x.impl, assertedTyp.raw.Type, commaOk) + } + tx := b.faceAbiType(x) + tabi := b.abiType(assertedTyp.raw.Type) + eq := b.BinOp(token.EQL, tx, tabi) + if commaOk { + prog := b.Prog + t := prog.Tuple(assertedTyp, prog.Bool()) + val := b.valFromData(assertedTyp, b.faceData(x.impl)) + zero := prog.Zero(assertedTyp) + valTrue := aggregateValue(b.impl, t.ll, val.impl, prog.BoolVal(true).impl) + valFalse := aggregateValue(b.impl, t.ll, zero.impl, prog.BoolVal(false).impl) + return Expr{llvm.CreateSelect(b.impl, eq.impl, valTrue, valFalse), t} + } + blks := b.Func.MakeBlocks(2) + b.If(eq, blks[0], blks[1]) + b.SetBlockEx(blks[1], AtEnd, false) + b.Panic(b.Str("type assertion failed")) + b.SetBlockEx(blks[0], AtEnd, false) + b.blk.last = blks[0].last + return b.valFromData(assertedTyp, b.faceData(x.impl)) +} + +/* func (b Builder) TypeAssert(x Expr, assertedTyp Type, commaOk bool) (ret Expr) { if debugInstr { log.Printf("TypeAssert %v, %v, %v\n", x.impl, assertedTyp.raw.Type, commaOk) } + // TODO(xsw) + // if x.kind != vkEface { + // panic("todo: non empty interface") + // } switch assertedTyp.kind { case vkSigned, vkUnsigned, vkFloat, vkBool: pkg := b.Pkg @@ -183,13 +308,14 @@ func (b Builder) TypeAssert(x Expr, assertedTyp Type, commaOk bool) (ret Expr) { } fn := pkg.rtFunc(fnName) var kind types.BasicKind + var typ Expr switch t := assertedTyp.raw.Type.(type) { case *types.Basic: kind = t.Kind() + typ = b.abiBasic(t) default: panic("todo") } - typ := b.InlineCall(pkg.rtFunc("Basic"), b.Prog.Val(int(kind))) ret = b.InlineCall(fn, x, typ) if kind != types.Uintptr { conv := func(v llvm.Value) llvm.Value { @@ -226,11 +352,32 @@ func (b Builder) TypeAssert(x Expr, assertedTyp Type, commaOk bool) (ret Expr) { if commaOk { fnName = "CheckI2String" } - fn := pkg.rtFunc(fnName) - typ := b.InlineCall(pkg.rtFunc("Basic"), b.Prog.Val(int(abi.String))) - return b.InlineCall(fn, x, typ) + return b.InlineCall(pkg.rtFunc(fnName), x) } panic("todo") } +*/ + +// ----------------------------------------------------------------------------- + +// InterfaceData returns the data pointer of an interface. +func (b Builder) InterfaceData(x Expr) Expr { + if debugInstr { + log.Printf("InterfaceData %v\n", x.impl) + } + return Expr{b.faceData(x.impl), b.Prog.VoidPtr()} +} + +func (b Builder) faceData(x llvm.Value) llvm.Value { + return llvm.CreateExtractValue(b.impl, x, 1) +} + +func (b Builder) faceAbiType(x Expr) Expr { + if x.kind == vkIface { + panic("todo") + } + typ := llvm.CreateExtractValue(b.impl, x.impl, 0) + return Expr{typ, b.Prog.AbiTypePtr()} +} // ----------------------------------------------------------------------------- diff --git a/ssa/package.go b/ssa/package.go index 9e9356bb..da180b66 100644 --- a/ssa/package.go +++ b/ssa/package.go @@ -19,7 +19,9 @@ package ssa import ( "go/token" "go/types" + "unsafe" + "github.com/goplus/llgo/ssa/abi" "github.com/goplus/llvm" "golang.org/x/tools/go/types/typeutil" ) @@ -99,7 +101,6 @@ type aProgram struct { ctx llvm.Context typs typeutil.Map // rawType -> Type gocvt goTypes - //abi *abi.Builder rt *types.Package rtget func() *types.Package @@ -122,7 +123,7 @@ type aProgram struct { voidPtrTy llvm.Type rtStringTy llvm.Type - rtIfaceTy llvm.Type + rtEfaceTy llvm.Type rtSliceTy llvm.Type rtMapTy llvm.Type @@ -137,6 +138,7 @@ type aProgram struct { intTy Type uintTy Type f64Ty Type + f32Ty Type byteTy Type i32Ty Type u32Ty Type @@ -144,6 +146,9 @@ type aProgram struct { u64Ty Type pyObjPtr Type pyObjPPtr Type + abiTyptr Type + abiTypptr Type + efaceTy Type pyImpTy *types.Signature pyNewList *types.Signature @@ -184,7 +189,7 @@ func NewProgram(target *Target) Program { */ is32Bits := (td.PointerSize() == 4 || target.GOARCH == "x86") // TODO(xsw): remove temp code return &aProgram{ - ctx: ctx, gocvt: newGoTypes(), // abi: abi.New(), + ctx: ctx, gocvt: newGoTypes(), target: target, td: td, is32Bits: is32Bits, named: make(map[string]llvm.Type), } @@ -243,11 +248,11 @@ func (p Program) rtType(name string) Type { return p.rawType(p.rtNamed(name)) } -func (p Program) rtIface() llvm.Type { - if p.rtIfaceTy.IsNil() { - p.rtIfaceTy = p.rtType("Interface").ll +func (p Program) rtEface() llvm.Type { + if p.rtEfaceTy.IsNil() { + p.rtEfaceTy = p.rtType("Eface").ll } - return p.rtIfaceTy + return p.rtEfaceTy } func (p Program) rtMap() llvm.Type { @@ -284,7 +289,44 @@ func (p Program) NewPackage(name, pkgPath string) Package { p.NeedRuntime = false // Don't need reset p.needPyInit here // p.needPyInit = false - return &aPackage{mod, gbls, fns, stubs, pyobjs, pymods, p} + ret := &aPackage{ + mod: mod, vars: gbls, fns: fns, stubs: stubs, + pyobjs: pyobjs, pymods: pymods, Prog: p} + ret.abi.Init(pkgPath) + return ret +} + +// Tuple returns a tuple type. +func (p Program) Tuple(typs ...Type) Type { + els := make([]*types.Var, len(typs)) + for i, t := range typs { + els[i] = types.NewParam(token.NoPos, nil, "", t.raw.Type) + } + return p.rawType(types.NewTuple(els...)) +} + +// Eface returns the empty interface type. +func (p Program) Eface() Type { + if p.efaceTy == nil { + p.efaceTy = p.rawType(tyAny) + } + return p.efaceTy +} + +// AbiTypePtr returns *abi.Type. +func (p Program) AbiTypePtr() Type { + if p.abiTyptr == nil { + p.abiTyptr = p.rawType(types.NewPointer(p.rtNamed("Type"))) + } + return p.abiTyptr +} + +// AbiTypePtrPtr returns **abi.Type. +func (p Program) AbiTypePtrPtr() Type { + if p.abiTypptr == nil { + p.abiTypptr = p.Pointer(p.AbiTypePtr()) + } + return p.abiTypptr } // PyObjectPtrPtr returns the **py.Object type. @@ -388,6 +430,14 @@ func (p Program) Float64() Type { return p.f64Ty } +// Float32 returns float32 type. +func (p Program) Float32() Type { + if p.f32Ty == nil { + p.f32Ty = p.rawType(types.Typ[types.Float32]) + } + return p.f32Ty +} + // Byte returns byte type. func (p Program) Byte() Type { if p.byteTy == nil { @@ -440,6 +490,8 @@ func (p Program) Uint64() Type { // and unspecified other things too. type aPackage struct { mod llvm.Module + abi abi.Builder + abiini []func(b unsafe.Pointer) // b Builder vars map[string]Global fns map[string]Function stubs map[string]Function @@ -450,13 +502,6 @@ type aPackage struct { type Package = *aPackage -/* -// NewConst creates a new named constant. -func (p Package) NewConst(name string, val constant.Value) NamedConst { - return &aNamedConst{} -} -*/ - func (p Package) rtFunc(fnName string) Expr { fn := p.Prog.runtime().Scope().Lookup(fnName).(*types.Func) name := FullName(fn.Pkg(), fnName) @@ -509,6 +554,28 @@ func (p Package) String() string { return p.mod.String() } +// AfterInit is called after the package is initialized (init all packages that depends on). +func (p Package) AfterInit(b Builder, ret BasicBlock) { + doAbiInit := len(p.abiini) > 0 + doPyLoadModSyms := p.pyHasModSyms() + if doAbiInit || doPyLoadModSyms { + b.SetBlockEx(ret, afterInit, false) + if doAbiInit { + sigAbiInit := types.NewSignatureType(nil, nil, nil, nil, nil, false) + fn := p.NewFunc(p.abi.Pkg+".init$abi", sigAbiInit, InC) + fnb := fn.MakeBody(1) + for _, abiInit := range p.abiini { + abiInit(unsafe.Pointer(fnb)) + } + fnb.Return() + b.Call(fn.Expr) + } + if doPyLoadModSyms { + p.pyLoadModSyms(b) + } + } +} + /* type CodeGenFileType = llvm.CodeGenFileType @@ -676,7 +743,7 @@ func (p Program) tyGetAttrString() *types.Signature { func (p Package) PyInit() bool { if fn := p.FuncOf("main"); fn != nil { b := fn.NewBuilder() - b.SetBlockEx(fn.Block(0), AtStart).callPyInit() + b.SetBlockEx(fn.Block(0), AtStart, false).callPyInit() b.Dispose() return true } diff --git a/ssa/ssa_test.go b/ssa/ssa_test.go index 103ee79e..3e23e756 100644 --- a/ssa/ssa_test.go +++ b/ssa/ssa_test.go @@ -52,7 +52,7 @@ func TestSetBlockEx(t *testing.T) { }() fn := &aFunction{} b := &aBuilder{Func: fn} - b.SetBlockEx(&aBasicBlock{fn: fn}, -1) + b.SetBlockEx(&aBasicBlock{fn: fn}, -1, false) } func TestSetPython(t *testing.T) { @@ -130,7 +130,7 @@ func TestAny(t *testing.T) { prog.SetRuntime(func() *types.Package { ret := types.NewPackage("runtime", "runtime") scope := ret.Scope() - name := types.NewTypeName(0, ret, "Interface", nil) + name := types.NewTypeName(0, ret, "Eface", nil) types.NewNamed(name, types.NewStruct(nil, nil), nil) scope.Insert(name) return ret diff --git a/ssa/stmt_builder.go b/ssa/stmt_builder.go index 2bbaf771..93c462a4 100644 --- a/ssa/stmt_builder.go +++ b/ssa/stmt_builder.go @@ -29,9 +29,10 @@ import ( // ----------------------------------------------------------------------------- type aBasicBlock struct { - impl llvm.BasicBlock - fn Function - idx int + first llvm.BasicBlock + last llvm.BasicBlock + fn Function + idx int } // BasicBlock represents a basic block in a function. @@ -51,6 +52,7 @@ func (p BasicBlock) Index() int { type aBuilder struct { impl llvm.Builder + blk BasicBlock Func Function Pkg Package Prog Program @@ -64,12 +66,12 @@ func (b Builder) Dispose() { b.impl.Dispose() } -// SetBlock means SetBlockEx(blk, AtEnd). +// SetBlock means SetBlockEx(blk, AtEnd, true). func (b Builder) SetBlock(blk BasicBlock) Builder { if debugInstr { log.Printf("Block _llgo_%v:\n", blk.idx) } - b.SetBlockEx(blk, AtEnd) + b.SetBlockEx(blk, AtEnd, true) return b } @@ -82,20 +84,23 @@ const ( ) // SetBlockEx sets blk as current basic block and pos as its insert point. -func (b Builder) SetBlockEx(blk BasicBlock, pos InsertPoint) Builder { +func (b Builder) SetBlockEx(blk BasicBlock, pos InsertPoint, setBlk bool) Builder { if b.Func != blk.fn { panic("mismatched function") } switch pos { case AtEnd: - b.impl.SetInsertPointAtEnd(blk.impl) + b.impl.SetInsertPointAtEnd(blk.last) case AtStart: - b.impl.SetInsertPointBefore(blk.impl.FirstInstruction()) + b.impl.SetInsertPointBefore(blk.first.FirstInstruction()) case afterInit: - b.impl.SetInsertPointBefore(instrAfterInit(blk.impl)) + b.impl.SetInsertPointBefore(instrAfterInit(blk.first)) default: panic("SetBlockEx: invalid pos") } + if setBlk { + b.blk = blk + } return b } @@ -160,6 +165,22 @@ func (b Builder) Return(results ...Expr) { } } +// The Extract instruction yields component Index of Tuple. +// +// This is used to access the results of instructions with multiple +// return values, such as Call, TypeAssert, Next, UnOp(ARROW) and +// IndexExpr(Map). +// +// Example printed form: +// +// t1 = extract t0 #1 +func (b Builder) Extract(x Expr, i int) (ret Expr) { + if debugInstr { + log.Printf("Extract %v, %d\n", x.impl, i) + } + return b.getField(x, i) +} + // Jump emits a jump instruction. func (b Builder) Jump(jmpb BasicBlock) { if b.Func != jmpb.fn { @@ -168,7 +189,7 @@ func (b Builder) Jump(jmpb BasicBlock) { if debugInstr { log.Printf("Jump _llgo_%v\n", jmpb.idx) } - b.impl.CreateBr(jmpb.impl) + b.impl.CreateBr(jmpb.first) } // If emits an if instruction. @@ -179,7 +200,7 @@ func (b Builder) If(cond Expr, thenb, elseb BasicBlock) { if debugInstr { log.Printf("If %v, _llgo_%v, _llgo_%v\n", cond.impl, thenb.idx, elseb.idx) } - b.impl.CreateCondBr(cond.impl, thenb.impl, elseb.impl) + b.impl.CreateCondBr(cond.impl, thenb.first, elseb.first) } // The MapUpdate instruction updates the association of Map[Key] to diff --git a/ssa/type.go b/ssa/type.go index b7307c39..d8ba01a7 100644 --- a/ssa/type.go +++ b/ssa/type.go @@ -49,7 +49,9 @@ const ( vkSlice vkArray vkMap - vkInterface + vkEface + vkIface + vkStruct vkPhisExpr = -1 ) @@ -73,7 +75,7 @@ func indexType(t types.Type) types.Type { // ----------------------------------------------------------------------------- type rawType struct { - types.Type + Type types.Type } type aType struct { @@ -99,6 +101,22 @@ func (p Program) SizeOf(typ Type, n ...int64) uint64 { return size } +// OffsetOf returns the offset of a field in a struct. +func (p Program) OffsetOf(typ Type, i int) uint64 { + return p.td.ElementOffset(typ.ll, i) +} + +// SizeOf returns the size of a type. +func SizeOf(prog Program, t Type, n ...int64) Expr { + size := prog.SizeOf(t, n...) + return prog.IntVal(size, prog.Uintptr()) +} + +func OffsetOf(prog Program, t Type, i int) Expr { + offset := prog.OffsetOf(t, i) + return prog.IntVal(offset, prog.Uintptr()) +} + func (p Program) PointerSize() int { return p.td.PointerSize() } @@ -113,7 +131,6 @@ func (p Program) Pointer(typ Type) Type { func (p Program) Elem(typ Type) Type { elem := typ.raw.Type.(interface { - types.Type Elem() types.Type }).Elem() return p.rawType(elem) @@ -124,9 +141,14 @@ func (p Program) Index(typ Type) Type { } func (p Program) Field(typ Type, i int) Type { - tunder := typ.raw.Type.Underlying() - tfld := tunder.(*types.Struct).Field(i).Type() - return p.rawType(tfld) + var fld *types.Var + switch t := typ.raw.Type.(type) { + case *types.Tuple: + fld = t.At(i) + default: + fld = t.Underlying().(*types.Struct).Field(i) + } + return p.rawType(fld.Type()) } func (p Program) rawType(raw types.Type) Type { @@ -201,9 +223,11 @@ func (p Program) tyInt64() llvm.Type { return p.int64Type } +/* func (p Program) toTuple(typ *types.Tuple) Type { return &aType{p.toLLVMTuple(typ), rawType{typ}, vkTuple} } +*/ func (p Program) toType(raw types.Type) Type { typ := rawType{raw} @@ -247,7 +271,9 @@ func (p Program) toType(raw types.Type) Type { elem := p.rawType(t.Elem()) return &aType{llvm.PointerType(elem.ll, 0), typ, vkPtr} case *types.Interface: - return &aType{p.rtIface(), typ, vkInterface} + if t.Empty() { + return &aType{p.rtEface(), typ, vkEface} + } case *types.Slice: return &aType{p.rtSlice(), typ, vkSlice} case *types.Map: @@ -259,12 +285,14 @@ func (p Program) toType(raw types.Type) Type { return p.toNamed(t) case *types.Signature: // represents a C function pointer in raw type return &aType{p.toLLVMFuncPtr(t), typ, vkFuncPtr} + case *types.Tuple: + return &aType{p.toLLVMTuple(t), typ, vkTuple} case *types.Array: elem := p.rawType(t.Elem()) return &aType{llvm.ArrayType(elem.ll, int(t.Len())), typ, vkArray} case *types.Chan: } - panic(fmt.Sprintf("toLLVMType: todo - %T\n", typ)) + panic(fmt.Sprintf("toLLVMType: todo - %T\n", raw)) } func (p Program) toLLVMNamedStruct(name string, raw *types.Struct) llvm.Type { @@ -283,6 +311,8 @@ func (p Program) toLLVMStruct(raw *types.Struct) (ret llvm.Type, kind valueKind) ret = p.ctx.StructType(fields, false) if isClosure(raw) { kind = vkClosure + } else { + kind = vkStruct } return } @@ -364,7 +394,7 @@ func (p Program) toNamed(raw *types.Named) Type { switch t := raw.Underlying().(type) { case *types.Struct: name := NameOf(raw) - return &aType{p.toLLVMNamedStruct(name, t), rawType{raw}, vkInvalid} + return &aType{p.toLLVMNamedStruct(name, t), rawType{raw}, vkStruct} default: return p.rawType(t) }