diff --git a/cl/_testdata/debug/in.go b/cl/_testdata/debug/in.go index cb7d2f05..d44f8314 100644 --- a/cl/_testdata/debug/in.go +++ b/cl/_testdata/debug/in.go @@ -28,10 +28,10 @@ type StructWithAllTypeFields struct { c128 complex128 // slice []int // arr [3]int - // s string - e E - // pf *StructWithAllTypeFields // resursive - // pi *int + s string + e E + pf *StructWithAllTypeFields // resursive + pi *int // intr Interface // m map[string]uint64 // c chan int @@ -51,6 +51,7 @@ func (s *Struct) Foo(a []int, b string) int { func FuncWithAllTypeStructParam(s StructWithAllTypeFields) { println(&s) + println(len(s.s)) } // Params is a function with all types of parameters. @@ -72,11 +73,11 @@ func FuncWithAllTypeParams( c128 complex128, // slice []int, // arr [3]int, - // s string, + s string, e E, f StructWithAllTypeFields, - // pf *StructWithAllTypeFields, - // pi *int, + pf *StructWithAllTypeFields, + pi *int, // intr Interface, // m map[string]uint64, // c chan int, @@ -88,7 +89,8 @@ func FuncWithAllTypeParams( f32, f64, b, c64, c128, // slice, arr[0:], - // s, &e, &f, pf, pi, intr, m, c, err, + s, + // &e, &f, pf, pi, intr, m, c, err, // fn, ) return 1, errors.New("Some error") @@ -114,10 +116,10 @@ func main() { c128: 15 + 16i, // slice: []int{21, 22, 23}, // arr: [3]int{24, 25, 26}, - // s: "hello", - e: E{i: 30}, - // pf: &StructWithAllTypeFields{}, - // pi: &i, + s: "hello", + e: E{i: 30}, + pf: &StructWithAllTypeFields{}, + pi: &i, // intr: &Struct{}, // m: make(map[string]uint64), // c: make(chan int), @@ -134,9 +136,10 @@ func main() { s.i8, s.i16, s.i32, s.i64, s.i, s.u8, s.u16, s.u32, s.u64, s.u, s.f32, s.f64, s.b, s.c64, s.c128, - // s.slice, s.arr, s.s, + // s.slice, s.arr, + s.s, s.e, s, - // s.pf, s.pi, + s.pf, s.pi, // s.intr, s.m, s.c, s.err, // s.fn, ) diff --git a/cl/_testgo/selects/out.ll b/cl/_testgo/selects/out.ll index 6ca105e4..196b8fbb 100644 --- a/cl/_testgo/selects/out.ll +++ b/cl/_testgo/selects/out.ll @@ -75,124 +75,124 @@ _llgo_0: %24 = call i32 @"github.com/goplus/llgo/internal/runtime.CreateThread"(ptr %19, ptr null, %"github.com/goplus/llgo/c/pthread.RoutineFunc" %23, ptr %17) %25 = load ptr, ptr %2, align 8 %26 = alloca {}, align 8 - %27 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %26, i64 0) - store {} zeroinitializer, ptr %27, align 1 - %28 = call i1 @"github.com/goplus/llgo/internal/runtime.ChanSend"(ptr %25, ptr %27, i64 0) - %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 @0, ptr %30, align 8 - %31 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %29, i32 0, i32 1 - store i64 4, ptr %31, align 4 - %32 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %29, align 8 - call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %32) + call void @llvm.memset(ptr %26, i8 0, i64 0, i1 false) + store {} zeroinitializer, ptr %26, align 1 + %27 = call i1 @"github.com/goplus/llgo/internal/runtime.ChanSend"(ptr %25, ptr %26, i64 0) + %28 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %29 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %28, i32 0, i32 0 + store ptr @0, ptr %29, align 8 + %30 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %28, i32 0, i32 1 + store i64 4, ptr %30, align 4 + %31 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %28, align 8 + call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %31) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) - %33 = load ptr, ptr %4, align 8 - %34 = alloca {}, align 8 - %35 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %34, i64 0) - %36 = alloca %"github.com/goplus/llgo/internal/runtime.ChanOp", align 8 - %37 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %36, i32 0, i32 0 - store ptr %33, ptr %37, align 8 - %38 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %36, i32 0, i32 1 - store ptr %35, ptr %38, align 8 - %39 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %36, i32 0, i32 2 - store i64 0, ptr %39, align 4 - %40 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %36, i32 0, i32 3 - store i1 false, ptr %40, align 1 - %41 = load %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %36, align 8 - %42 = alloca {}, align 8 - %43 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %42, i64 0) - %44 = alloca %"github.com/goplus/llgo/internal/runtime.ChanOp", align 8 - %45 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %44, i32 0, i32 0 - store ptr %8, ptr %45, align 8 - %46 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %44, i32 0, i32 1 - store ptr %43, ptr %46, align 8 - %47 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %44, i32 0, i32 2 - store i64 0, ptr %47, align 4 - %48 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %44, i32 0, i32 3 - store i1 false, ptr %48, align 1 - %49 = load %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %44, align 8 - %50 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 48) - %51 = getelementptr %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %50, i64 0 - store %"github.com/goplus/llgo/internal/runtime.ChanOp" %41, ptr %51, align 8 - %52 = getelementptr %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %50, i64 1 - store %"github.com/goplus/llgo/internal/runtime.ChanOp" %49, ptr %52, align 8 - %53 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 - %54 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %53, i32 0, i32 0 - store ptr %50, ptr %54, align 8 - %55 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %53, i32 0, i32 1 - store i64 2, ptr %55, align 4 - %56 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %53, i32 0, i32 2 - store i64 2, ptr %56, align 4 - %57 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %53, align 8 - %58 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.Select"(%"github.com/goplus/llgo/internal/runtime.Slice" %57) - %59 = extractvalue { i64, i1 } %58, 0 - %60 = extractvalue { i64, i1 } %58, 1 - %61 = extractvalue %"github.com/goplus/llgo/internal/runtime.ChanOp" %41, 1 - %62 = load {}, ptr %61, align 1 - %63 = extractvalue %"github.com/goplus/llgo/internal/runtime.ChanOp" %49, 1 - %64 = load {}, ptr %63, align 1 - %65 = alloca { i64, i1, {}, {} }, align 8 - %66 = getelementptr inbounds { i64, i1, {}, {} }, ptr %65, i32 0, i32 0 - store i64 %59, ptr %66, align 4 - %67 = getelementptr inbounds { i64, i1, {}, {} }, ptr %65, i32 0, i32 1 - store i1 %60, ptr %67, align 1 - %68 = getelementptr inbounds { i64, i1, {}, {} }, ptr %65, i32 0, i32 2 - store {} %62, ptr %68, align 1 - %69 = getelementptr inbounds { i64, i1, {}, {} }, ptr %65, i32 0, i32 3 - store {} %64, ptr %69, align 1 - %70 = load { i64, i1, {}, {} }, ptr %65, align 4 - %71 = extractvalue { i64, i1, {}, {} } %70, 0 - %72 = icmp eq i64 %71, 0 - br i1 %72, label %_llgo_2, label %_llgo_3 + %32 = load ptr, ptr %4, align 8 + %33 = alloca {}, align 8 + call void @llvm.memset(ptr %33, i8 0, i64 0, i1 false) + %34 = alloca %"github.com/goplus/llgo/internal/runtime.ChanOp", align 8 + %35 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %34, i32 0, i32 0 + store ptr %32, ptr %35, align 8 + %36 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %34, i32 0, i32 1 + store ptr %33, ptr %36, align 8 + %37 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %34, i32 0, i32 2 + store i64 0, ptr %37, align 4 + %38 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %34, i32 0, i32 3 + store i1 false, ptr %38, align 1 + %39 = load %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %34, align 8 + %40 = alloca {}, align 8 + call void @llvm.memset(ptr %40, i8 0, i64 0, i1 false) + %41 = alloca %"github.com/goplus/llgo/internal/runtime.ChanOp", align 8 + %42 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %41, i32 0, i32 0 + store ptr %8, ptr %42, align 8 + %43 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %41, i32 0, i32 1 + store ptr %40, ptr %43, align 8 + %44 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %41, i32 0, i32 2 + store i64 0, ptr %44, align 4 + %45 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %41, i32 0, i32 3 + store i1 false, ptr %45, align 1 + %46 = load %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %41, align 8 + %47 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 48) + %48 = getelementptr %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %47, i64 0 + store %"github.com/goplus/llgo/internal/runtime.ChanOp" %39, ptr %48, align 8 + %49 = getelementptr %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %47, i64 1 + store %"github.com/goplus/llgo/internal/runtime.ChanOp" %46, ptr %49, align 8 + %50 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 + %51 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %50, i32 0, i32 0 + store ptr %47, ptr %51, align 8 + %52 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %50, i32 0, i32 1 + store i64 2, ptr %52, align 4 + %53 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %50, i32 0, i32 2 + store i64 2, ptr %53, align 4 + %54 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %50, align 8 + %55 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.Select"(%"github.com/goplus/llgo/internal/runtime.Slice" %54) + %56 = extractvalue { i64, i1 } %55, 0 + %57 = extractvalue { i64, i1 } %55, 1 + %58 = extractvalue %"github.com/goplus/llgo/internal/runtime.ChanOp" %39, 1 + %59 = load {}, ptr %58, align 1 + %60 = extractvalue %"github.com/goplus/llgo/internal/runtime.ChanOp" %46, 1 + %61 = load {}, ptr %60, align 1 + %62 = alloca { i64, i1, {}, {} }, align 8 + %63 = getelementptr inbounds { i64, i1, {}, {} }, ptr %62, i32 0, i32 0 + store i64 %56, ptr %63, align 4 + %64 = getelementptr inbounds { i64, i1, {}, {} }, ptr %62, i32 0, i32 1 + store i1 %57, ptr %64, align 1 + %65 = getelementptr inbounds { i64, i1, {}, {} }, ptr %62, i32 0, i32 2 + store {} %59, ptr %65, align 1 + %66 = getelementptr inbounds { i64, i1, {}, {} }, ptr %62, i32 0, i32 3 + store {} %61, ptr %66, align 1 + %67 = load { i64, i1, {}, {} }, ptr %62, align 4 + %68 = extractvalue { i64, i1, {}, {} } %67, 0 + %69 = icmp eq i64 %68, 0 + br i1 %69, label %_llgo_2, label %_llgo_3 _llgo_1: ; preds = %_llgo_4, %_llgo_2 ret i32 0 _llgo_2: ; preds = %_llgo_0 - %73 = extractvalue { i64, i1, {}, {} } %70, 2 - %74 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %75 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %74, i32 0, i32 0 - store ptr @1, ptr %75, align 8 - %76 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %74, i32 0, i32 1 - store i64 4, ptr %76, align 4 - %77 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %74, align 8 - call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %77) + %70 = extractvalue { i64, i1, {}, {} } %67, 2 + %71 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %72 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %71, i32 0, i32 0 + store ptr @1, ptr %72, align 8 + %73 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %71, i32 0, i32 1 + store i64 4, ptr %73, align 4 + %74 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %71, align 8 + 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.PrintByte"(i8 10) br label %_llgo_1 _llgo_3: ; preds = %_llgo_0 - %78 = icmp eq i64 %71, 1 - br i1 %78, label %_llgo_4, label %_llgo_5 + %75 = icmp eq i64 %68, 1 + br i1 %75, label %_llgo_4, label %_llgo_5 _llgo_4: ; preds = %_llgo_3 - %79 = extractvalue { i64, i1, {}, {} } %70, 3 - %80 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %81 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %80, i32 0, i32 0 - store ptr @2, ptr %81, align 8 - %82 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %80, i32 0, i32 1 - store i64 4, ptr %82, align 4 - %83 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %80, align 8 - call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %83) + %76 = extractvalue { i64, i1, {}, {} } %67, 3 + %77 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %78 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %77, i32 0, i32 0 + store ptr @2, ptr %78, align 8 + %79 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %77, i32 0, i32 1 + store i64 4, ptr %79, align 4 + %80 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %77, align 8 + call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %80) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) br label %_llgo_1 _llgo_5: ; preds = %_llgo_3 - %84 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %85 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %84, i32 0, i32 0 - store ptr @3, ptr %85, align 8 - %86 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %84, i32 0, i32 1 - store i64 31, ptr %86, align 4 - %87 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %84, align 8 - %88 = load ptr, ptr @_llgo_string, align 8 - %89 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) - store %"github.com/goplus/llgo/internal/runtime.String" %87, ptr %89, align 8 - %90 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 - %91 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %90, i32 0, i32 0 - store ptr %88, ptr %91, align 8 - %92 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %90, i32 0, i32 1 - store ptr %89, ptr %92, align 8 - %93 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %90, align 8 - call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %93) + %81 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %82 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %81, i32 0, i32 0 + store ptr @3, ptr %82, align 8 + %83 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %81, i32 0, i32 1 + store i64 31, ptr %83, align 4 + %84 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %81, align 8 + %85 = load ptr, ptr @_llgo_string, align 8 + %86 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %84, ptr %86, align 8 + %87 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %88 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %87, i32 0, i32 0 + store ptr %85, ptr %88, align 8 + %89 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %87, i32 0, i32 1 + store ptr %86, ptr %89, align 8 + %90 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %87, align 8 + call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %90) unreachable } @@ -202,123 +202,123 @@ _llgo_0: %2 = extractvalue { ptr, ptr, ptr } %1, 0 %3 = load ptr, ptr %2, align 8 %4 = alloca {}, align 8 - %5 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %4, i64 0) - %6 = call i1 @"github.com/goplus/llgo/internal/runtime.ChanRecv"(ptr %3, ptr %5, i64 0) - %7 = load {}, ptr %5, align 1 - %8 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %8, i32 0, i32 0 - store ptr @4, ptr %9, align 8 - %10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %8, i32 0, i32 1 - store i64 4, ptr %10, align 4 - %11 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %8, align 8 - call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %11) + call void @llvm.memset(ptr %4, i8 0, i64 0, i1 false) + %5 = call i1 @"github.com/goplus/llgo/internal/runtime.ChanRecv"(ptr %3, ptr %4, i64 0) + %6 = load {}, ptr %4, align 1 + %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 @4, ptr %8, align 8 + %9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 1 + store i64 4, 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.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %10) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) - %12 = extractvalue { ptr, ptr, ptr } %1, 1 - %13 = load ptr, ptr %12, align 8 - %14 = extractvalue { ptr, ptr, ptr } %1, 2 - %15 = load ptr, ptr %14, align 8 - %16 = alloca {}, align 8 - %17 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %16, i64 0) - store {} zeroinitializer, ptr %17, align 1 - %18 = alloca %"github.com/goplus/llgo/internal/runtime.ChanOp", align 8 - %19 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %18, i32 0, i32 0 - store ptr %13, ptr %19, align 8 - %20 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %18, i32 0, i32 1 - store ptr %17, ptr %20, align 8 - %21 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %18, i32 0, i32 2 - store i32 0, ptr %21, align 4 - %22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %18, i32 0, i32 3 - store i1 true, ptr %22, align 1 - %23 = load %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %18, align 8 - %24 = alloca {}, align 8 - %25 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %24, i64 0) - %26 = alloca %"github.com/goplus/llgo/internal/runtime.ChanOp", align 8 - %27 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %26, i32 0, i32 0 - store ptr %15, ptr %27, align 8 - %28 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %26, i32 0, i32 1 - store ptr %25, ptr %28, align 8 - %29 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %26, i32 0, i32 2 - store i64 0, ptr %29, align 4 - %30 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %26, i32 0, i32 3 - store i1 false, ptr %30, align 1 - %31 = load %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %26, align 8 - %32 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 48) - %33 = getelementptr %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %32, i64 0 - store %"github.com/goplus/llgo/internal/runtime.ChanOp" %23, ptr %33, align 8 - %34 = getelementptr %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %32, i64 1 - store %"github.com/goplus/llgo/internal/runtime.ChanOp" %31, ptr %34, align 8 - %35 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 - %36 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %35, i32 0, i32 0 - store ptr %32, ptr %36, align 8 - %37 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %35, i32 0, i32 1 - store i64 2, ptr %37, align 4 - %38 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %35, i32 0, i32 2 - store i64 2, ptr %38, align 4 - %39 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %35, align 8 - %40 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.Select"(%"github.com/goplus/llgo/internal/runtime.Slice" %39) - %41 = extractvalue { i64, i1 } %40, 0 - %42 = extractvalue { i64, i1 } %40, 1 - %43 = extractvalue %"github.com/goplus/llgo/internal/runtime.ChanOp" %31, 1 - %44 = load {}, ptr %43, align 1 - %45 = alloca { i64, i1, {} }, align 8 - %46 = getelementptr inbounds { i64, i1, {} }, ptr %45, i32 0, i32 0 - store i64 %41, ptr %46, align 4 - %47 = getelementptr inbounds { i64, i1, {} }, ptr %45, i32 0, i32 1 - store i1 %42, ptr %47, align 1 - %48 = getelementptr inbounds { i64, i1, {} }, ptr %45, i32 0, i32 2 - store {} %44, ptr %48, align 1 - %49 = load { i64, i1, {} }, ptr %45, align 4 - %50 = extractvalue { i64, i1, {} } %49, 0 - %51 = icmp eq i64 %50, 0 - br i1 %51, label %_llgo_2, label %_llgo_3 + %11 = extractvalue { ptr, ptr, ptr } %1, 1 + %12 = load ptr, ptr %11, align 8 + %13 = extractvalue { ptr, ptr, ptr } %1, 2 + %14 = load ptr, ptr %13, align 8 + %15 = alloca {}, align 8 + call void @llvm.memset(ptr %15, i8 0, i64 0, i1 false) + store {} zeroinitializer, ptr %15, align 1 + %16 = alloca %"github.com/goplus/llgo/internal/runtime.ChanOp", align 8 + %17 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %16, i32 0, i32 0 + store ptr %12, ptr %17, align 8 + %18 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %16, i32 0, i32 1 + store ptr %15, ptr %18, align 8 + %19 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %16, i32 0, i32 2 + store i32 0, ptr %19, align 4 + %20 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %16, i32 0, i32 3 + store i1 true, ptr %20, align 1 + %21 = load %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %16, align 8 + %22 = alloca {}, align 8 + call void @llvm.memset(ptr %22, i8 0, i64 0, i1 false) + %23 = alloca %"github.com/goplus/llgo/internal/runtime.ChanOp", align 8 + %24 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %23, i32 0, i32 0 + store ptr %14, ptr %24, align 8 + %25 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %23, i32 0, i32 1 + store ptr %22, ptr %25, align 8 + %26 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %23, i32 0, i32 2 + store i64 0, ptr %26, align 4 + %27 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %23, i32 0, i32 3 + store i1 false, ptr %27, align 1 + %28 = load %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %23, align 8 + %29 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 48) + %30 = getelementptr %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %29, i64 0 + store %"github.com/goplus/llgo/internal/runtime.ChanOp" %21, ptr %30, align 8 + %31 = getelementptr %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %29, i64 1 + store %"github.com/goplus/llgo/internal/runtime.ChanOp" %28, ptr %31, align 8 + %32 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 + %33 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %32, i32 0, i32 0 + store ptr %29, ptr %33, align 8 + %34 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %32, i32 0, i32 1 + store i64 2, ptr %34, align 4 + %35 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %32, i32 0, i32 2 + store i64 2, ptr %35, align 4 + %36 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %32, align 8 + %37 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.Select"(%"github.com/goplus/llgo/internal/runtime.Slice" %36) + %38 = extractvalue { i64, i1 } %37, 0 + %39 = extractvalue { i64, i1 } %37, 1 + %40 = extractvalue %"github.com/goplus/llgo/internal/runtime.ChanOp" %28, 1 + %41 = load {}, ptr %40, align 1 + %42 = alloca { i64, i1, {} }, align 8 + %43 = getelementptr inbounds { i64, i1, {} }, ptr %42, i32 0, i32 0 + store i64 %38, ptr %43, align 4 + %44 = getelementptr inbounds { i64, i1, {} }, ptr %42, i32 0, i32 1 + store i1 %39, ptr %44, align 1 + %45 = getelementptr inbounds { i64, i1, {} }, ptr %42, i32 0, i32 2 + store {} %41, ptr %45, align 1 + %46 = load { i64, i1, {} }, ptr %42, align 4 + %47 = extractvalue { i64, i1, {} } %46, 0 + %48 = icmp eq i64 %47, 0 + br i1 %48, label %_llgo_2, label %_llgo_3 _llgo_1: ; preds = %_llgo_4, %_llgo_2 ret void _llgo_2: ; preds = %_llgo_0 - %52 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %53 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %52, i32 0, i32 0 - store ptr @5, ptr %53, align 8 - %54 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %52, i32 0, i32 1 - store i64 4, ptr %54, align 4 - %55 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %52, align 8 - call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %55) + %49 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %50 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %49, i32 0, i32 0 + store ptr @5, ptr %50, align 8 + %51 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %49, i32 0, i32 1 + store i64 4, ptr %51, align 4 + %52 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %49, align 8 + call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %52) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) br label %_llgo_1 _llgo_3: ; preds = %_llgo_0 - %56 = icmp eq i64 %50, 1 - br i1 %56, label %_llgo_4, label %_llgo_5 + %53 = icmp eq i64 %47, 1 + br i1 %53, label %_llgo_4, label %_llgo_5 _llgo_4: ; preds = %_llgo_3 - %57 = extractvalue { i64, i1, {} } %49, 2 - %58 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %59 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %58, i32 0, i32 0 - store ptr @6, ptr %59, align 8 - %60 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %58, i32 0, i32 1 - store i64 4, ptr %60, align 4 - %61 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %58, align 8 - call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %61) + %54 = extractvalue { i64, i1, {} } %46, 2 + %55 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %56 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %55, i32 0, i32 0 + store ptr @6, ptr %56, align 8 + %57 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %55, i32 0, i32 1 + store i64 4, ptr %57, align 4 + %58 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %55, align 8 + call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %58) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) br label %_llgo_1 _llgo_5: ; preds = %_llgo_3 - %62 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %63 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %62, i32 0, i32 0 - store ptr @3, ptr %63, align 8 - %64 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %62, i32 0, i32 1 - store i64 31, ptr %64, align 4 - %65 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %62, align 8 - %66 = load ptr, ptr @_llgo_string, align 8 - %67 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) - store %"github.com/goplus/llgo/internal/runtime.String" %65, ptr %67, align 8 - %68 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 - %69 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i32 0, i32 0 - store ptr %66, ptr %69, align 8 - %70 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i32 0, i32 1 - store ptr %67, ptr %70, align 8 - %71 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, align 8 - call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %71) + %59 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %60 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %59, i32 0, i32 0 + store ptr @3, ptr %60, align 8 + %61 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %59, i32 0, i32 1 + store i64 31, ptr %61, align 4 + %62 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %59, align 8 + %63 = load ptr, ptr @_llgo_string, align 8 + %64 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) + store %"github.com/goplus/llgo/internal/runtime.String" %62, ptr %64, align 8 + %65 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 + %66 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %65, i32 0, i32 0 + store ptr %63, ptr %66, align 8 + %67 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %65, i32 0, i32 1 + store ptr %64, ptr %67, align 8 + %68 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %65, align 8 + call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %68) unreachable } @@ -355,7 +355,8 @@ _llgo_0: declare i1 @"github.com/goplus/llgo/internal/runtime.ChanSend"(ptr, ptr, i64) -declare ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr, i64) +; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write) +declare void @llvm.memset(ptr nocapture writeonly, i8, i64, i1 immarg) #0 declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String") @@ -383,3 +384,5 @@ declare ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64) declare void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface") declare i1 @"github.com/goplus/llgo/internal/runtime.ChanRecv"(ptr, ptr, i64) + +attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) } diff --git a/cl/compile.go b/cl/compile.go index bc87802c..65eab810 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -273,9 +273,6 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun off[i] = p.compilePhis(b, block) } p.blkInfos = blocks.Infos(f.Blocks) - if debugSymbols { - p.debugParams(b, f) - } i := 0 for { block := f.Blocks[i] @@ -318,6 +315,10 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do var instrs = block.Instrs[n:] var ret = fn.Block(block.Index) b.SetBlock(ret) + // place here to avoid wrong current-block + if debugSymbols && block.Index == 0 { + p.debugParams(b, block.Parent()) + } if doModInit { if pyModInit = p.pyMod != ""; pyModInit { last = len(instrs) - 1 @@ -722,24 +723,28 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) { x := p.compileValue(b, v.X) b.Send(ch, x) case *ssa.DebugRef: - if !debugSymbols { - return + if debugSymbols { + object := v.Object() + variable, ok := object.(*types.Var) + if !ok { + // Not a local variable. + return + } + if v.IsAddr { + // *ssa.Alloc or *ssa.FieldAddr + return + } + + pos := p.goProg.Fset.Position(getPos(v)) + value := p.compileValue(b, v.X) + fn := v.Parent() + dbgVar := p.getLocalVariable(b, fn, variable) + if v.IsAddr { + b.DIDeclare(value, dbgVar, p.fn, pos, b.Func.Block(v.Block().Index)) + } else { + b.DIValue(value, dbgVar, p.fn, pos, b.Func.Block(v.Block().Index)) + } } - object := v.Object() - variable, ok := object.(*types.Var) - if !ok { - // Not a local variable. - return - } - if v.IsAddr { - // *ssa.Alloc or *ssa.FieldAddr - return - } - fn := v.Parent() - dbgVar := p.getLocalVariable(b, fn, variable) - pos := p.goProg.Fset.Position(getPos(v)) - value := p.compileValue(b, v.X) - b.DIValue(value, dbgVar, p.fn, pos, b.Func.Block(v.Block().Index)) default: panic(fmt.Sprintf("compileInstr: unknown instr - %T\n", instr)) } @@ -816,7 +821,7 @@ func (p *context) compileValue(b llssa.Builder, v ssa.Value) llssa.Expr { fn := v.Parent() for idx, param := range fn.Params { if param == v { - return p.fn.Param(idx) + return b.Param(idx) } } case *ssa.Function: @@ -905,7 +910,7 @@ func NewPackageEx(prog llssa.Program, patches Patches, pkg *ssa.Package, files [ } ret = prog.NewPackage(pkgName, pkgPath) if debugSymbols { - ret.EnableDebugSymbols(pkgName, pkgPath) + ret.InitDebugSymbols(pkgName, pkgPath) } ctx := &context{ diff --git a/ssa/decl.go b/ssa/decl.go index b5416b37..7858c9b2 100644 --- a/ssa/decl.go +++ b/ssa/decl.go @@ -274,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, nil, p, p.Pkg, prog, make(map[Expr]Expr)} + return &aBuilder{b, nil, p, p.Pkg, prog, make(map[Expr]dbgExpr)} } // HasBody reports whether the function has a body. diff --git a/ssa/di.go b/ssa/di.go index a9daf124..d22cba9e 100644 --- a/ssa/di.go +++ b/ssa/di.go @@ -3,7 +3,6 @@ package ssa import ( "debug/dwarf" "fmt" - "go/constant" "go/token" "go/types" "path/filepath" @@ -135,12 +134,7 @@ func (b diBuilder) createType(ty Type, pos token.Position) DIType { } else if t.Info()&types.IsComplex != 0 { return b.createComplexType(ty) } else if t.Info()&types.IsString != 0 { - typ = b.di.CreateBasicType(llvm.DIBasicType{ - Name: "string", - SizeInBits: b.prog.SizeOf(b.prog.rawType(t)) * 8, - Encoding: llvm.DW_ATE_unsigned_char, - }) - return &aDIType{typ} + return b.createStringType(pos) } else { panic(fmt.Errorf("can't create debug info of basic type: %v, %T", ty.RawType(), ty.RawType())) } @@ -185,10 +179,6 @@ type aDIFunction struct { type DIFunction = *aDIFunction -func (b diBuilder) createFunction(scope DIScope, pos token.Position, name, linkageName string, ty DIType, isLocalToUnit, isDefinition, isOptimized bool) DIFunction { - return &aDIFunction{ll: scope.scopeMeta(b, pos).ll} -} - // ---------------------------------------------------------------------------- type aDIGlobalVariableExpression struct { @@ -264,6 +254,38 @@ func (b diBuilder) createBasicType(t Type) DIType { })} } +func (b diBuilder) createStringType(pos token.Position) DIType { + ty := b.prog.rtType("String") + + return &aDIType{ll: b.di.CreateStructType( + llvm.Metadata{}, + llvm.DIStructType{ + Name: "string", + SizeInBits: b.prog.SizeOf(ty) * 8, + AlignInBits: uint32(b.prog.sizes.Alignof(ty.RawType()) * 8), + Elements: []llvm.Metadata{ + b.di.CreateMemberType( + llvm.Metadata{}, + llvm.DIMemberType{ + Name: "data", + SizeInBits: b.prog.SizeOf(b.prog.CStr()) * 8, + AlignInBits: uint32(b.prog.sizes.Alignof(b.prog.CStr().RawType()) * 8), + Type: b.diType(b.prog.CStr(), pos).ll, + }, + ), + b.di.CreateMemberType( + llvm.Metadata{}, + llvm.DIMemberType{ + Name: "len", + SizeInBits: b.prog.SizeOf(b.prog.Int()) * 8, + AlignInBits: uint32(b.prog.sizes.Alignof(b.prog.Uint().RawType()) * 8), + Type: b.diType(b.prog.Int(), pos).ll, + }, + ), + }, + })} +} + func (b diBuilder) createComplexType(t Type) DIType { var tfield Type if t.RawType().(*types.Basic).Kind() == types.Complex128 { @@ -317,18 +339,22 @@ func (b diBuilder) createPointerType(ty Type, pos token.Position) DIType { } func (b diBuilder) createStructType(ty Type, pos token.Position) (ret DIType) { + structType := ty.RawType().(*types.Struct) + scope := b.file(pos.Filename) ret = &aDIType{b.di.CreateReplaceableCompositeType( scope.ll, llvm.DIReplaceableCompositeType{ - Tag: dwarf.TagStructType, - Name: ty.RawType().String(), + Tag: dwarf.TagStructType, + Name: ty.RawType().String(), + File: b.file(pos.Filename).ll, + Line: pos.Line, + SizeInBits: b.prog.SizeOf(ty) * 8, + AlignInBits: uint32(b.prog.sizes.Alignof(structType) * 8), }, )} b.types[ty] = ret - // Create struct type - structType := ty.RawType().(*types.Struct) fields := make([]llvm.Metadata, structType.NumFields()) for i := 0; i < structType.NumFields(); i++ { @@ -470,9 +496,9 @@ func (b diBuilder) createExpression(ops []uint64) DIExpression { // ----------------------------------------------------------------------------- // Copy struct parameters to alloca'd memory. -func (b Builder) allocatedVar(v Expr) (Expr, bool) { - if v, ok := b.allocVars[v]; ok { - return v, true +func (b Builder) debug(v Expr) (dbgPtr Expr, dbgVal Expr) { + if v, ok := b.dbgVars[v]; ok { + return v.ptr, v.val } t := v.Type.RawType().Underlying() var ty Type @@ -484,22 +510,30 @@ func (b Builder) allocatedVar(v Expr) (Expr, bool) { } else { ty = b.Prog.Complex64() } + } else if t.Info()&types.IsString != 0 { + ty = b.Prog.rtType("String") } else { - return v, false + ty = v.Type } case *types.Struct: ty = v.Type case *types.Slice: ty = b.Prog.Type(b.Prog.rtType("Slice").RawType().Underlying(), InGo) + case *types.Signature: + fmt.Printf("t: %T, %v\n", t, t) + ty = b.Prog.Type(b.Prog.rtType("Func").RawType().Underlying(), InGo) + case *types.Named: + ty = b.Prog.Type(t.Underlying(), InGo) default: - return v, false + ty = v.Type } - size := b.Const(constant.MakeUint64(b.Prog.SizeOf(ty)), b.Prog.Uint64()) - p := b.Alloca(size) - p.Type = b.Prog.Pointer(ty) - b.Store(p, v) - b.allocVars[v] = p - return p, true + // fmt.Printf("ty: %T, %v, %T, %v\n", ty.RawType(), ty.RawType(), t, t) + dbgPtr = b.AllocaT(ty) + dbgPtr.Type = b.Prog.Pointer(v.Type) + b.Store(dbgPtr, v) + dbgVal = b.Load(dbgPtr) + b.dbgVars[v] = dbgExpr{dbgPtr, dbgVal} + return dbgPtr, dbgVal } const ( @@ -507,15 +541,13 @@ const ( ) func skipType(t types.Type) bool { - switch t := t.(type) { + switch t.(type) { case *types.Slice: return true case *types.Interface: return true - case *types.Basic: - if t.Info()&types.IsString != 0 { - return true - } + case *types.Signature: + return true } return false } @@ -525,12 +557,9 @@ func (b Builder) DIDeclare(v Expr, dv DIVar, scope DIScope, pos token.Position, if skipType(t) { return } - v, alloced := b.allocatedVar(v) + dbgPtr, _ := b.debug(v) expr := b.Pkg.diBuilder().createExpression(nil) - if alloced { - expr = b.Pkg.diBuilder().createExpression([]uint64{opDeref}) - } - b.Pkg.diBuilder().dbgDeclare(v, dv, scope, pos, expr, blk) + b.Pkg.diBuilder().dbgDeclare(dbgPtr, dv, scope, pos, expr, blk) } func (b Builder) DIValue(v Expr, dv DIVar, scope DIScope, pos token.Position, blk BasicBlock) { @@ -538,11 +567,7 @@ func (b Builder) DIValue(v Expr, dv DIVar, scope DIScope, pos token.Position, bl if skipType(t) { return } - v, alloced := b.allocatedVar(v) expr := b.Pkg.diBuilder().createExpression(nil) - if alloced { - expr = b.Pkg.diBuilder().createExpression([]uint64{opDeref}) - } b.Pkg.diBuilder().dbgValue(v, dv, scope, pos, expr, blk) } @@ -570,4 +595,12 @@ func (b Builder) DebugFunction(f Function, pos token.Position) { f.scopeMeta(b.Pkg.di, pos) } +func (b Builder) Param(idx int) Expr { + p := b.Func.Param(idx) + if v, ok := b.dbgVars[p]; ok { + return v.val + } + return p +} + // ----------------------------------------------------------------------------- diff --git a/ssa/memory.go b/ssa/memory.go index d9f469e9..e0a46b5a 100644 --- a/ssa/memory.go +++ b/ssa/memory.go @@ -144,6 +144,16 @@ func (b Builder) Alloca(n Expr) (ret Expr) { return } +func (b Builder) AllocaT(t Type) (ret Expr) { + if debugInstr { + log.Printf("AllocaT %v\n", t.RawType()) + } + prog := b.Prog + ret.impl = llvm.CreateAlloca(b.impl, t.ll) + ret.Type = prog.Pointer(t) + return +} + /* TODO(xsw): // AllocaU allocates uninitialized space for n*sizeof(elem) bytes. func (b Builder) AllocaU(elem Type, n ...int64) (ret Expr) { diff --git a/ssa/package.go b/ssa/package.go index ea65e6bf..c8dd9d91 100644 --- a/ssa/package.go +++ b/ssa/package.go @@ -712,7 +712,7 @@ func (p Package) diBuilder() diBuilder { return p.di } -func (p Package) EnableDebugSymbols(name, pkgPath string) { +func (p Package) InitDebugSymbols(name, pkgPath string) { p.di = newDIBuilder(p.Prog, p) p.cu = p.di.createCompileUnit(name, pkgPath) } diff --git a/ssa/stmt_builder.go b/ssa/stmt_builder.go index 2140e986..2c2d423d 100644 --- a/ssa/stmt_builder.go +++ b/ssa/stmt_builder.go @@ -57,6 +57,11 @@ func (p BasicBlock) Addr() Expr { // ----------------------------------------------------------------------------- +type dbgExpr struct { + ptr Expr + val Expr +} + type aBuilder struct { impl llvm.Builder blk BasicBlock @@ -64,7 +69,7 @@ type aBuilder struct { Pkg Package Prog Program - allocVars map[Expr]Expr + dbgVars map[Expr]dbgExpr } // Builder represents a builder for creating instructions in a function.