ssa: support string and pointer debug info, fix params debugging

This commit is contained in:
Li Jie
2024-09-18 16:42:47 +08:00
parent 4dbfc9483e
commit d85a080f9b
8 changed files with 342 additions and 283 deletions

View File

@@ -28,10 +28,10 @@ type StructWithAllTypeFields struct {
c128 complex128 c128 complex128
// slice []int // slice []int
// arr [3]int // arr [3]int
// s string s string
e E e E
// pf *StructWithAllTypeFields // resursive pf *StructWithAllTypeFields // resursive
// pi *int pi *int
// intr Interface // intr Interface
// m map[string]uint64 // m map[string]uint64
// c chan int // c chan int
@@ -51,6 +51,7 @@ func (s *Struct) Foo(a []int, b string) int {
func FuncWithAllTypeStructParam(s StructWithAllTypeFields) { func FuncWithAllTypeStructParam(s StructWithAllTypeFields) {
println(&s) println(&s)
println(len(s.s))
} }
// Params is a function with all types of parameters. // Params is a function with all types of parameters.
@@ -72,11 +73,11 @@ func FuncWithAllTypeParams(
c128 complex128, c128 complex128,
// slice []int, // slice []int,
// arr [3]int, // arr [3]int,
// s string, s string,
e E, e E,
f StructWithAllTypeFields, f StructWithAllTypeFields,
// pf *StructWithAllTypeFields, pf *StructWithAllTypeFields,
// pi *int, pi *int,
// intr Interface, // intr Interface,
// m map[string]uint64, // m map[string]uint64,
// c chan int, // c chan int,
@@ -88,7 +89,8 @@ func FuncWithAllTypeParams(
f32, f64, b, f32, f64, b,
c64, c128, c64, c128,
// slice, arr[0:], // slice, arr[0:],
// s, &e, &f, pf, pi, intr, m, c, err, s,
// &e, &f, pf, pi, intr, m, c, err,
// fn, // fn,
) )
return 1, errors.New("Some error") return 1, errors.New("Some error")
@@ -114,10 +116,10 @@ func main() {
c128: 15 + 16i, c128: 15 + 16i,
// slice: []int{21, 22, 23}, // slice: []int{21, 22, 23},
// arr: [3]int{24, 25, 26}, // arr: [3]int{24, 25, 26},
// s: "hello", s: "hello",
e: E{i: 30}, e: E{i: 30},
// pf: &StructWithAllTypeFields{}, pf: &StructWithAllTypeFields{},
// pi: &i, pi: &i,
// intr: &Struct{}, // intr: &Struct{},
// m: make(map[string]uint64), // m: make(map[string]uint64),
// c: make(chan int), // 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.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.f32, s.f64, s.b,
s.c64, s.c128, s.c64, s.c128,
// s.slice, s.arr, s.s, // s.slice, s.arr,
s.s,
s.e, s, s.e, s,
// s.pf, s.pi, s.pf, s.pi,
// s.intr, s.m, s.c, s.err, // s.intr, s.m, s.c, s.err,
// s.fn, // s.fn,
) )

View File

@@ -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) %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 %25 = load ptr, ptr %2, align 8
%26 = alloca {}, align 8 %26 = alloca {}, align 8
%27 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %26, i64 0) call void @llvm.memset(ptr %26, i8 0, i64 0, i1 false)
store {} zeroinitializer, ptr %27, align 1 store {} zeroinitializer, ptr %26, align 1
%28 = call i1 @"github.com/goplus/llgo/internal/runtime.ChanSend"(ptr %25, ptr %27, i64 0) %27 = call i1 @"github.com/goplus/llgo/internal/runtime.ChanSend"(ptr %25, ptr %26, i64 0)
%29 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %28 = 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 %29 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %28, i32 0, i32 0
store ptr @0, ptr %30, align 8 store ptr @0, ptr %29, align 8
%31 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %29, i32 0, i32 1 %30 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %28, i32 0, i32 1
store i64 4, ptr %31, align 4 store i64 4, ptr %30, align 4
%32 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %29, align 8 %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" %32) 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) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
%33 = load ptr, ptr %4, align 8 %32 = load ptr, ptr %4, align 8
%34 = alloca {}, align 8 %33 = alloca {}, align 8
%35 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %34, i64 0) call void @llvm.memset(ptr %33, i8 0, i64 0, i1 false)
%36 = alloca %"github.com/goplus/llgo/internal/runtime.ChanOp", align 8 %34 = 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 %35 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %34, i32 0, i32 0
store ptr %33, ptr %37, align 8 store ptr %32, ptr %35, align 8
%38 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %36, i32 0, i32 1 %36 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %34, i32 0, i32 1
store ptr %35, ptr %38, align 8 store ptr %33, ptr %36, align 8
%39 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %36, i32 0, i32 2 %37 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %34, i32 0, i32 2
store i64 0, ptr %39, align 4 store i64 0, ptr %37, align 4
%40 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %36, i32 0, i32 3 %38 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %34, i32 0, i32 3
store i1 false, ptr %40, align 1 store i1 false, ptr %38, align 1
%41 = load %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %36, align 8 %39 = load %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %34, align 8
%42 = alloca {}, align 8 %40 = alloca {}, align 8
%43 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %42, i64 0) call void @llvm.memset(ptr %40, i8 0, i64 0, i1 false)
%44 = alloca %"github.com/goplus/llgo/internal/runtime.ChanOp", align 8 %41 = 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 %42 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %41, i32 0, i32 0
store ptr %8, ptr %45, align 8 store ptr %8, ptr %42, align 8
%46 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %44, i32 0, i32 1 %43 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %41, i32 0, i32 1
store ptr %43, ptr %46, align 8 store ptr %40, ptr %43, align 8
%47 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %44, i32 0, i32 2 %44 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %41, i32 0, i32 2
store i64 0, ptr %47, align 4 store i64 0, ptr %44, align 4
%48 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %44, i32 0, i32 3 %45 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %41, i32 0, i32 3
store i1 false, ptr %48, align 1 store i1 false, ptr %45, align 1
%49 = load %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %44, align 8 %46 = load %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %41, align 8
%50 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 48) %47 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 48)
%51 = getelementptr %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %50, i64 0 %48 = getelementptr %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %47, i64 0
store %"github.com/goplus/llgo/internal/runtime.ChanOp" %41, ptr %51, align 8 store %"github.com/goplus/llgo/internal/runtime.ChanOp" %39, ptr %48, align 8
%52 = getelementptr %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %50, i64 1 %49 = getelementptr %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %47, i64 1
store %"github.com/goplus/llgo/internal/runtime.ChanOp" %49, ptr %52, align 8 store %"github.com/goplus/llgo/internal/runtime.ChanOp" %46, ptr %49, align 8
%53 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 %50 = 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 %51 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %50, i32 0, i32 0
store ptr %50, ptr %54, align 8 store ptr %47, ptr %51, align 8
%55 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %53, i32 0, i32 1 %52 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %50, i32 0, i32 1
store i64 2, ptr %55, align 4 store i64 2, ptr %52, align 4
%56 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %53, i32 0, i32 2 %53 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %50, i32 0, i32 2
store i64 2, ptr %56, align 4 store i64 2, ptr %53, align 4
%57 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %53, align 8 %54 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %50, align 8
%58 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.Select"(%"github.com/goplus/llgo/internal/runtime.Slice" %57) %55 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.Select"(%"github.com/goplus/llgo/internal/runtime.Slice" %54)
%59 = extractvalue { i64, i1 } %58, 0 %56 = extractvalue { i64, i1 } %55, 0
%60 = extractvalue { i64, i1 } %58, 1 %57 = extractvalue { i64, i1 } %55, 1
%61 = extractvalue %"github.com/goplus/llgo/internal/runtime.ChanOp" %41, 1 %58 = extractvalue %"github.com/goplus/llgo/internal/runtime.ChanOp" %39, 1
%62 = load {}, ptr %61, align 1 %59 = load {}, ptr %58, align 1
%63 = extractvalue %"github.com/goplus/llgo/internal/runtime.ChanOp" %49, 1 %60 = extractvalue %"github.com/goplus/llgo/internal/runtime.ChanOp" %46, 1
%64 = load {}, ptr %63, align 1 %61 = load {}, ptr %60, align 1
%65 = alloca { i64, i1, {}, {} }, align 8 %62 = alloca { i64, i1, {}, {} }, align 8
%66 = getelementptr inbounds { i64, i1, {}, {} }, ptr %65, i32 0, i32 0 %63 = getelementptr inbounds { i64, i1, {}, {} }, ptr %62, i32 0, i32 0
store i64 %59, ptr %66, align 4 store i64 %56, ptr %63, align 4
%67 = getelementptr inbounds { i64, i1, {}, {} }, ptr %65, i32 0, i32 1 %64 = getelementptr inbounds { i64, i1, {}, {} }, ptr %62, i32 0, i32 1
store i1 %60, ptr %67, align 1 store i1 %57, ptr %64, align 1
%68 = getelementptr inbounds { i64, i1, {}, {} }, ptr %65, i32 0, i32 2 %65 = getelementptr inbounds { i64, i1, {}, {} }, ptr %62, i32 0, i32 2
store {} %62, ptr %68, align 1 store {} %59, ptr %65, align 1
%69 = getelementptr inbounds { i64, i1, {}, {} }, ptr %65, i32 0, i32 3 %66 = getelementptr inbounds { i64, i1, {}, {} }, ptr %62, i32 0, i32 3
store {} %64, ptr %69, align 1 store {} %61, ptr %66, align 1
%70 = load { i64, i1, {}, {} }, ptr %65, align 4 %67 = load { i64, i1, {}, {} }, ptr %62, align 4
%71 = extractvalue { i64, i1, {}, {} } %70, 0 %68 = extractvalue { i64, i1, {}, {} } %67, 0
%72 = icmp eq i64 %71, 0 %69 = icmp eq i64 %68, 0
br i1 %72, label %_llgo_2, label %_llgo_3 br i1 %69, label %_llgo_2, label %_llgo_3
_llgo_1: ; preds = %_llgo_4, %_llgo_2 _llgo_1: ; preds = %_llgo_4, %_llgo_2
ret i32 0 ret i32 0
_llgo_2: ; preds = %_llgo_0 _llgo_2: ; preds = %_llgo_0
%73 = extractvalue { i64, i1, {}, {} } %70, 2 %70 = extractvalue { i64, i1, {}, {} } %67, 2
%74 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %71 = 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 %72 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %71, i32 0, i32 0
store ptr @1, ptr %75, align 8 store ptr @1, ptr %72, align 8
%76 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %74, i32 0, i32 1 %73 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %71, i32 0, i32 1
store i64 4, ptr %76, align 4 store i64 4, ptr %73, align 4
%77 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %74, align 8 %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" %77) 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) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
br label %_llgo_1 br label %_llgo_1
_llgo_3: ; preds = %_llgo_0 _llgo_3: ; preds = %_llgo_0
%78 = icmp eq i64 %71, 1 %75 = icmp eq i64 %68, 1
br i1 %78, label %_llgo_4, label %_llgo_5 br i1 %75, label %_llgo_4, label %_llgo_5
_llgo_4: ; preds = %_llgo_3 _llgo_4: ; preds = %_llgo_3
%79 = extractvalue { i64, i1, {}, {} } %70, 3 %76 = extractvalue { i64, i1, {}, {} } %67, 3
%80 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %77 = 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 %78 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %77, i32 0, i32 0
store ptr @2, ptr %81, align 8 store ptr @2, ptr %78, align 8
%82 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %80, i32 0, i32 1 %79 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %77, i32 0, i32 1
store i64 4, ptr %82, align 4 store i64 4, ptr %79, align 4
%83 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %80, align 8 %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" %83) 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) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
br label %_llgo_1 br label %_llgo_1
_llgo_5: ; preds = %_llgo_3 _llgo_5: ; preds = %_llgo_3
%84 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %81 = 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 %82 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %81, i32 0, i32 0
store ptr @3, ptr %85, align 8 store ptr @3, ptr %82, align 8
%86 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %84, i32 0, i32 1 %83 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %81, i32 0, i32 1
store i64 31, ptr %86, align 4 store i64 31, ptr %83, align 4
%87 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %84, align 8 %84 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %81, align 8
%88 = load ptr, ptr @_llgo_string, align 8 %85 = load ptr, ptr @_llgo_string, align 8
%89 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) %86 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16)
store %"github.com/goplus/llgo/internal/runtime.String" %87, ptr %89, align 8 store %"github.com/goplus/llgo/internal/runtime.String" %84, ptr %86, align 8
%90 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 %87 = 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 %88 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %87, i32 0, i32 0
store ptr %88, ptr %91, align 8 store ptr %85, ptr %88, align 8
%92 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %90, i32 0, i32 1 %89 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %87, i32 0, i32 1
store ptr %89, ptr %92, align 8 store ptr %86, ptr %89, align 8
%93 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %90, 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" %93) call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %90)
unreachable unreachable
} }
@@ -202,123 +202,123 @@ _llgo_0:
%2 = extractvalue { ptr, ptr, ptr } %1, 0 %2 = extractvalue { ptr, ptr, ptr } %1, 0
%3 = load ptr, ptr %2, align 8 %3 = load ptr, ptr %2, align 8
%4 = alloca {}, align 8 %4 = alloca {}, align 8
%5 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %4, i64 0) call void @llvm.memset(ptr %4, i8 0, i64 0, i1 false)
%6 = call i1 @"github.com/goplus/llgo/internal/runtime.ChanRecv"(ptr %3, ptr %5, i64 0) %5 = call i1 @"github.com/goplus/llgo/internal/runtime.ChanRecv"(ptr %3, ptr %4, i64 0)
%7 = load {}, ptr %5, align 1 %6 = load {}, ptr %4, align 1
%8 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %7 = 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 %8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 0
store ptr @4, ptr %9, align 8 store ptr @4, ptr %8, align 8
%10 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %8, i32 0, i32 1 %9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 1
store i64 4, ptr %10, align 4 store i64 4, ptr %9, align 4
%11 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %8, align 8 %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" %11) 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) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
%12 = extractvalue { ptr, ptr, ptr } %1, 1 %11 = extractvalue { ptr, ptr, ptr } %1, 1
%13 = load ptr, ptr %12, align 8 %12 = load ptr, ptr %11, align 8
%14 = extractvalue { ptr, ptr, ptr } %1, 2 %13 = extractvalue { ptr, ptr, ptr } %1, 2
%15 = load ptr, ptr %14, align 8 %14 = load ptr, ptr %13, align 8
%16 = alloca {}, align 8 %15 = alloca {}, align 8
%17 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %16, i64 0) call void @llvm.memset(ptr %15, i8 0, i64 0, i1 false)
store {} zeroinitializer, ptr %17, align 1 store {} zeroinitializer, ptr %15, align 1
%18 = alloca %"github.com/goplus/llgo/internal/runtime.ChanOp", align 8 %16 = 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 %17 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %16, i32 0, i32 0
store ptr %13, ptr %19, align 8 store ptr %12, ptr %17, align 8
%20 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %18, i32 0, i32 1 %18 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %16, i32 0, i32 1
store ptr %17, ptr %20, align 8 store ptr %15, ptr %18, align 8
%21 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %18, i32 0, i32 2 %19 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %16, i32 0, i32 2
store i32 0, ptr %21, align 4 store i32 0, ptr %19, align 4
%22 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %18, i32 0, i32 3 %20 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %16, i32 0, i32 3
store i1 true, ptr %22, align 1 store i1 true, ptr %20, align 1
%23 = load %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %18, align 8 %21 = load %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %16, align 8
%24 = alloca {}, align 8 %22 = alloca {}, align 8
%25 = call ptr @"github.com/goplus/llgo/internal/runtime.Zeroinit"(ptr %24, i64 0) call void @llvm.memset(ptr %22, i8 0, i64 0, i1 false)
%26 = alloca %"github.com/goplus/llgo/internal/runtime.ChanOp", align 8 %23 = 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 %24 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %23, i32 0, i32 0
store ptr %15, ptr %27, align 8 store ptr %14, ptr %24, align 8
%28 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %26, i32 0, i32 1 %25 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %23, i32 0, i32 1
store ptr %25, ptr %28, align 8 store ptr %22, ptr %25, align 8
%29 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %26, i32 0, i32 2 %26 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %23, i32 0, i32 2
store i64 0, ptr %29, align 4 store i64 0, ptr %26, align 4
%30 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %26, i32 0, i32 3 %27 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %23, i32 0, i32 3
store i1 false, ptr %30, align 1 store i1 false, ptr %27, align 1
%31 = load %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %26, align 8 %28 = load %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %23, align 8
%32 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 48) %29 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 48)
%33 = getelementptr %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %32, i64 0 %30 = getelementptr %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %29, i64 0
store %"github.com/goplus/llgo/internal/runtime.ChanOp" %23, ptr %33, align 8 store %"github.com/goplus/llgo/internal/runtime.ChanOp" %21, ptr %30, align 8
%34 = getelementptr %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %32, i64 1 %31 = getelementptr %"github.com/goplus/llgo/internal/runtime.ChanOp", ptr %29, i64 1
store %"github.com/goplus/llgo/internal/runtime.ChanOp" %31, ptr %34, align 8 store %"github.com/goplus/llgo/internal/runtime.ChanOp" %28, ptr %31, align 8
%35 = alloca %"github.com/goplus/llgo/internal/runtime.Slice", align 8 %32 = 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 %33 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %32, i32 0, i32 0
store ptr %32, ptr %36, align 8 store ptr %29, ptr %33, align 8
%37 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %35, i32 0, i32 1 %34 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %32, i32 0, i32 1
store i64 2, ptr %37, align 4 store i64 2, ptr %34, align 4
%38 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %35, i32 0, i32 2 %35 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.Slice", ptr %32, i32 0, i32 2
store i64 2, ptr %38, align 4 store i64 2, ptr %35, align 4
%39 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %35, align 8 %36 = load %"github.com/goplus/llgo/internal/runtime.Slice", ptr %32, align 8
%40 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.Select"(%"github.com/goplus/llgo/internal/runtime.Slice" %39) %37 = call { i64, i1 } @"github.com/goplus/llgo/internal/runtime.Select"(%"github.com/goplus/llgo/internal/runtime.Slice" %36)
%41 = extractvalue { i64, i1 } %40, 0 %38 = extractvalue { i64, i1 } %37, 0
%42 = extractvalue { i64, i1 } %40, 1 %39 = extractvalue { i64, i1 } %37, 1
%43 = extractvalue %"github.com/goplus/llgo/internal/runtime.ChanOp" %31, 1 %40 = extractvalue %"github.com/goplus/llgo/internal/runtime.ChanOp" %28, 1
%44 = load {}, ptr %43, align 1 %41 = load {}, ptr %40, align 1
%45 = alloca { i64, i1, {} }, align 8 %42 = alloca { i64, i1, {} }, align 8
%46 = getelementptr inbounds { i64, i1, {} }, ptr %45, i32 0, i32 0 %43 = getelementptr inbounds { i64, i1, {} }, ptr %42, i32 0, i32 0
store i64 %41, ptr %46, align 4 store i64 %38, ptr %43, align 4
%47 = getelementptr inbounds { i64, i1, {} }, ptr %45, i32 0, i32 1 %44 = getelementptr inbounds { i64, i1, {} }, ptr %42, i32 0, i32 1
store i1 %42, ptr %47, align 1 store i1 %39, ptr %44, align 1
%48 = getelementptr inbounds { i64, i1, {} }, ptr %45, i32 0, i32 2 %45 = getelementptr inbounds { i64, i1, {} }, ptr %42, i32 0, i32 2
store {} %44, ptr %48, align 1 store {} %41, ptr %45, align 1
%49 = load { i64, i1, {} }, ptr %45, align 4 %46 = load { i64, i1, {} }, ptr %42, align 4
%50 = extractvalue { i64, i1, {} } %49, 0 %47 = extractvalue { i64, i1, {} } %46, 0
%51 = icmp eq i64 %50, 0 %48 = icmp eq i64 %47, 0
br i1 %51, label %_llgo_2, label %_llgo_3 br i1 %48, label %_llgo_2, label %_llgo_3
_llgo_1: ; preds = %_llgo_4, %_llgo_2 _llgo_1: ; preds = %_llgo_4, %_llgo_2
ret void ret void
_llgo_2: ; preds = %_llgo_0 _llgo_2: ; preds = %_llgo_0
%52 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %49 = 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 %50 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %49, i32 0, i32 0
store ptr @5, ptr %53, align 8 store ptr @5, ptr %50, align 8
%54 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %52, i32 0, i32 1 %51 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %49, i32 0, i32 1
store i64 4, ptr %54, align 4 store i64 4, ptr %51, align 4
%55 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %52, align 8 %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" %55) 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) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
br label %_llgo_1 br label %_llgo_1
_llgo_3: ; preds = %_llgo_0 _llgo_3: ; preds = %_llgo_0
%56 = icmp eq i64 %50, 1 %53 = icmp eq i64 %47, 1
br i1 %56, label %_llgo_4, label %_llgo_5 br i1 %53, label %_llgo_4, label %_llgo_5
_llgo_4: ; preds = %_llgo_3 _llgo_4: ; preds = %_llgo_3
%57 = extractvalue { i64, i1, {} } %49, 2 %54 = extractvalue { i64, i1, {} } %46, 2
%58 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %55 = 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 %56 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %55, i32 0, i32 0
store ptr @6, ptr %59, align 8 store ptr @6, ptr %56, align 8
%60 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %58, i32 0, i32 1 %57 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %55, i32 0, i32 1
store i64 4, ptr %60, align 4 store i64 4, ptr %57, align 4
%61 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %58, align 8 %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" %61) 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) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10)
br label %_llgo_1 br label %_llgo_1
_llgo_5: ; preds = %_llgo_3 _llgo_5: ; preds = %_llgo_3
%62 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 %59 = 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 %60 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %59, i32 0, i32 0
store ptr @3, ptr %63, align 8 store ptr @3, ptr %60, align 8
%64 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %62, i32 0, i32 1 %61 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %59, i32 0, i32 1
store i64 31, ptr %64, align 4 store i64 31, ptr %61, align 4
%65 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %62, align 8 %62 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %59, align 8
%66 = load ptr, ptr @_llgo_string, align 8 %63 = load ptr, ptr @_llgo_string, align 8
%67 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16) %64 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 16)
store %"github.com/goplus/llgo/internal/runtime.String" %65, ptr %67, align 8 store %"github.com/goplus/llgo/internal/runtime.String" %62, ptr %64, align 8
%68 = alloca %"github.com/goplus/llgo/internal/runtime.eface", align 8 %65 = 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 %66 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %65, i32 0, i32 0
store ptr %66, ptr %69, align 8 store ptr %63, ptr %66, align 8
%70 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, i32 0, i32 1 %67 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %65, i32 0, i32 1
store ptr %67, ptr %70, align 8 store ptr %64, ptr %67, align 8
%71 = load %"github.com/goplus/llgo/internal/runtime.eface", ptr %68, 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" %71) call void @"github.com/goplus/llgo/internal/runtime.Panic"(%"github.com/goplus/llgo/internal/runtime.eface" %68)
unreachable unreachable
} }
@@ -355,7 +355,8 @@ _llgo_0:
declare i1 @"github.com/goplus/llgo/internal/runtime.ChanSend"(ptr, ptr, i64) 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") 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 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) declare i1 @"github.com/goplus/llgo/internal/runtime.ChanRecv"(ptr, ptr, i64)
attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }

View File

@@ -273,9 +273,6 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
off[i] = p.compilePhis(b, block) off[i] = p.compilePhis(b, block)
} }
p.blkInfos = blocks.Infos(f.Blocks) p.blkInfos = blocks.Infos(f.Blocks)
if debugSymbols {
p.debugParams(b, f)
}
i := 0 i := 0
for { for {
block := f.Blocks[i] 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 instrs = block.Instrs[n:]
var ret = fn.Block(block.Index) var ret = fn.Block(block.Index)
b.SetBlock(ret) b.SetBlock(ret)
// place here to avoid wrong current-block
if debugSymbols && block.Index == 0 {
p.debugParams(b, block.Parent())
}
if doModInit { if doModInit {
if pyModInit = p.pyMod != ""; pyModInit { if pyModInit = p.pyMod != ""; pyModInit {
last = len(instrs) - 1 last = len(instrs) - 1
@@ -722,9 +723,7 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
x := p.compileValue(b, v.X) x := p.compileValue(b, v.X)
b.Send(ch, x) b.Send(ch, x)
case *ssa.DebugRef: case *ssa.DebugRef:
if !debugSymbols { if debugSymbols {
return
}
object := v.Object() object := v.Object()
variable, ok := object.(*types.Var) variable, ok := object.(*types.Var)
if !ok { if !ok {
@@ -735,11 +734,17 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) {
// *ssa.Alloc or *ssa.FieldAddr // *ssa.Alloc or *ssa.FieldAddr
return return
} }
fn := v.Parent()
dbgVar := p.getLocalVariable(b, fn, variable)
pos := p.goProg.Fset.Position(getPos(v)) pos := p.goProg.Fset.Position(getPos(v))
value := p.compileValue(b, v.X) 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)) b.DIValue(value, dbgVar, p.fn, pos, b.Func.Block(v.Block().Index))
}
}
default: default:
panic(fmt.Sprintf("compileInstr: unknown instr - %T\n", instr)) 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() fn := v.Parent()
for idx, param := range fn.Params { for idx, param := range fn.Params {
if param == v { if param == v {
return p.fn.Param(idx) return b.Param(idx)
} }
} }
case *ssa.Function: case *ssa.Function:
@@ -905,7 +910,7 @@ func NewPackageEx(prog llssa.Program, patches Patches, pkg *ssa.Package, files [
} }
ret = prog.NewPackage(pkgName, pkgPath) ret = prog.NewPackage(pkgName, pkgPath)
if debugSymbols { if debugSymbols {
ret.EnableDebugSymbols(pkgName, pkgPath) ret.InitDebugSymbols(pkgName, pkgPath)
} }
ctx := &context{ ctx := &context{

View File

@@ -274,7 +274,7 @@ func (p Function) NewBuilder() Builder {
b := prog.ctx.NewBuilder() b := prog.ctx.NewBuilder()
// TODO(xsw): Finalize may cause panic, so comment it. // TODO(xsw): Finalize may cause panic, so comment it.
// b.Finalize() // 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. // HasBody reports whether the function has a body.

107
ssa/di.go
View File

@@ -3,7 +3,6 @@ package ssa
import ( import (
"debug/dwarf" "debug/dwarf"
"fmt" "fmt"
"go/constant"
"go/token" "go/token"
"go/types" "go/types"
"path/filepath" "path/filepath"
@@ -135,12 +134,7 @@ func (b diBuilder) createType(ty Type, pos token.Position) DIType {
} else if t.Info()&types.IsComplex != 0 { } else if t.Info()&types.IsComplex != 0 {
return b.createComplexType(ty) return b.createComplexType(ty)
} else if t.Info()&types.IsString != 0 { } else if t.Info()&types.IsString != 0 {
typ = b.di.CreateBasicType(llvm.DIBasicType{ return b.createStringType(pos)
Name: "string",
SizeInBits: b.prog.SizeOf(b.prog.rawType(t)) * 8,
Encoding: llvm.DW_ATE_unsigned_char,
})
return &aDIType{typ}
} else { } else {
panic(fmt.Errorf("can't create debug info of basic type: %v, %T", ty.RawType(), ty.RawType())) 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 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 { 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 { func (b diBuilder) createComplexType(t Type) DIType {
var tfield Type var tfield Type
if t.RawType().(*types.Basic).Kind() == types.Complex128 { 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) { func (b diBuilder) createStructType(ty Type, pos token.Position) (ret DIType) {
structType := ty.RawType().(*types.Struct)
scope := b.file(pos.Filename) scope := b.file(pos.Filename)
ret = &aDIType{b.di.CreateReplaceableCompositeType( ret = &aDIType{b.di.CreateReplaceableCompositeType(
scope.ll, scope.ll,
llvm.DIReplaceableCompositeType{ llvm.DIReplaceableCompositeType{
Tag: dwarf.TagStructType, Tag: dwarf.TagStructType,
Name: ty.RawType().String(), 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 b.types[ty] = ret
// Create struct type
structType := ty.RawType().(*types.Struct)
fields := make([]llvm.Metadata, structType.NumFields()) fields := make([]llvm.Metadata, structType.NumFields())
for i := 0; i < structType.NumFields(); i++ { 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. // Copy struct parameters to alloca'd memory.
func (b Builder) allocatedVar(v Expr) (Expr, bool) { func (b Builder) debug(v Expr) (dbgPtr Expr, dbgVal Expr) {
if v, ok := b.allocVars[v]; ok { if v, ok := b.dbgVars[v]; ok {
return v, true return v.ptr, v.val
} }
t := v.Type.RawType().Underlying() t := v.Type.RawType().Underlying()
var ty Type var ty Type
@@ -484,22 +510,30 @@ func (b Builder) allocatedVar(v Expr) (Expr, bool) {
} else { } else {
ty = b.Prog.Complex64() ty = b.Prog.Complex64()
} }
} else if t.Info()&types.IsString != 0 {
ty = b.Prog.rtType("String")
} else { } else {
return v, false ty = v.Type
} }
case *types.Struct: case *types.Struct:
ty = v.Type ty = v.Type
case *types.Slice: case *types.Slice:
ty = b.Prog.Type(b.Prog.rtType("Slice").RawType().Underlying(), InGo) 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: default:
return v, false ty = v.Type
} }
size := b.Const(constant.MakeUint64(b.Prog.SizeOf(ty)), b.Prog.Uint64()) // fmt.Printf("ty: %T, %v, %T, %v\n", ty.RawType(), ty.RawType(), t, t)
p := b.Alloca(size) dbgPtr = b.AllocaT(ty)
p.Type = b.Prog.Pointer(ty) dbgPtr.Type = b.Prog.Pointer(v.Type)
b.Store(p, v) b.Store(dbgPtr, v)
b.allocVars[v] = p dbgVal = b.Load(dbgPtr)
return p, true b.dbgVars[v] = dbgExpr{dbgPtr, dbgVal}
return dbgPtr, dbgVal
} }
const ( const (
@@ -507,16 +541,14 @@ const (
) )
func skipType(t types.Type) bool { func skipType(t types.Type) bool {
switch t := t.(type) { switch t.(type) {
case *types.Slice: case *types.Slice:
return true return true
case *types.Interface: case *types.Interface:
return true return true
case *types.Basic: case *types.Signature:
if t.Info()&types.IsString != 0 {
return true return true
} }
}
return false return false
} }
@@ -525,12 +557,9 @@ func (b Builder) DIDeclare(v Expr, dv DIVar, scope DIScope, pos token.Position,
if skipType(t) { if skipType(t) {
return return
} }
v, alloced := b.allocatedVar(v) dbgPtr, _ := b.debug(v)
expr := b.Pkg.diBuilder().createExpression(nil) expr := b.Pkg.diBuilder().createExpression(nil)
if alloced { b.Pkg.diBuilder().dbgDeclare(dbgPtr, dv, scope, pos, expr, blk)
expr = b.Pkg.diBuilder().createExpression([]uint64{opDeref})
}
b.Pkg.diBuilder().dbgDeclare(v, dv, scope, pos, expr, blk)
} }
func (b Builder) DIValue(v Expr, dv DIVar, scope DIScope, pos token.Position, blk BasicBlock) { 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) { if skipType(t) {
return return
} }
v, alloced := b.allocatedVar(v)
expr := b.Pkg.diBuilder().createExpression(nil) 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) 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) 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
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@@ -144,6 +144,16 @@ func (b Builder) Alloca(n Expr) (ret Expr) {
return 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): /* TODO(xsw):
// AllocaU allocates uninitialized space for n*sizeof(elem) bytes. // AllocaU allocates uninitialized space for n*sizeof(elem) bytes.
func (b Builder) AllocaU(elem Type, n ...int64) (ret Expr) { func (b Builder) AllocaU(elem Type, n ...int64) (ret Expr) {

View File

@@ -712,7 +712,7 @@ func (p Package) diBuilder() diBuilder {
return p.di return p.di
} }
func (p Package) EnableDebugSymbols(name, pkgPath string) { func (p Package) InitDebugSymbols(name, pkgPath string) {
p.di = newDIBuilder(p.Prog, p) p.di = newDIBuilder(p.Prog, p)
p.cu = p.di.createCompileUnit(name, pkgPath) p.cu = p.di.createCompileUnit(name, pkgPath)
} }

View File

@@ -57,6 +57,11 @@ func (p BasicBlock) Addr() Expr {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
type dbgExpr struct {
ptr Expr
val Expr
}
type aBuilder struct { type aBuilder struct {
impl llvm.Builder impl llvm.Builder
blk BasicBlock blk BasicBlock
@@ -64,7 +69,7 @@ type aBuilder struct {
Pkg Package Pkg Package
Prog Program Prog Program
allocVars map[Expr]Expr dbgVars map[Expr]dbgExpr
} }
// Builder represents a builder for creating instructions in a function. // Builder represents a builder for creating instructions in a function.