ssa: debug info of Array and Slice
This commit is contained in:
@@ -11,27 +11,28 @@ type E struct {
|
|||||||
i int
|
i int
|
||||||
}
|
}
|
||||||
type StructWithAllTypeFields struct {
|
type StructWithAllTypeFields struct {
|
||||||
i8 int8
|
i8 int8
|
||||||
i16 int16
|
i16 int16
|
||||||
i32 int32
|
i32 int32
|
||||||
i64 int64
|
i64 int64
|
||||||
i int
|
i int
|
||||||
u8 uint8
|
u8 uint8
|
||||||
u16 uint16
|
u16 uint16
|
||||||
u32 uint32
|
u32 uint32
|
||||||
u64 uint64
|
u64 uint64
|
||||||
u uint
|
u uint
|
||||||
f32 float32
|
f32 float32
|
||||||
f64 float64
|
f64 float64
|
||||||
b bool
|
b bool
|
||||||
c64 complex64
|
c64 complex64
|
||||||
c128 complex128
|
c128 complex128
|
||||||
// slice []int
|
slice []int
|
||||||
// arr [3]int
|
arr [3]int
|
||||||
s string
|
arr2 [3]E
|
||||||
e E
|
s string
|
||||||
pf *StructWithAllTypeFields // resursive
|
e E
|
||||||
pi *int
|
pf *StructWithAllTypeFields // resursive
|
||||||
|
pi *int
|
||||||
// intr Interface
|
// intr Interface
|
||||||
// m map[string]uint64
|
// m map[string]uint64
|
||||||
// c chan int
|
// c chan int
|
||||||
@@ -71,8 +72,9 @@ func FuncWithAllTypeParams(
|
|||||||
b bool,
|
b bool,
|
||||||
c64 complex64,
|
c64 complex64,
|
||||||
c128 complex128,
|
c128 complex128,
|
||||||
// slice []int,
|
slice []int,
|
||||||
// arr [3]int,
|
arr [3]int,
|
||||||
|
arr2 [3]E,
|
||||||
s string,
|
s string,
|
||||||
e E,
|
e E,
|
||||||
f StructWithAllTypeFields,
|
f StructWithAllTypeFields,
|
||||||
@@ -88,7 +90,7 @@ func FuncWithAllTypeParams(
|
|||||||
i8, i16, i32, i64, i, u8, u16, u32, u64, u,
|
i8, i16, i32, i64, i, u8, u16, u32, u64, u,
|
||||||
f32, f64, b,
|
f32, f64, b,
|
||||||
c64, c128,
|
c64, c128,
|
||||||
// slice, arr[0:],
|
slice, arr[0:],
|
||||||
s,
|
s,
|
||||||
// &e, &f, pf, pi, intr, m, c, err,
|
// &e, &f, pf, pi, intr, m, c, err,
|
||||||
// fn,
|
// fn,
|
||||||
@@ -99,27 +101,28 @@ func FuncWithAllTypeParams(
|
|||||||
func main() {
|
func main() {
|
||||||
i := 100
|
i := 100
|
||||||
s := StructWithAllTypeFields{
|
s := StructWithAllTypeFields{
|
||||||
i8: 1,
|
i8: 1,
|
||||||
i16: 2,
|
i16: 2,
|
||||||
i32: 3,
|
i32: 3,
|
||||||
i64: 4,
|
i64: 4,
|
||||||
i: 5,
|
i: 5,
|
||||||
u8: 6,
|
u8: 6,
|
||||||
u16: 7,
|
u16: 7,
|
||||||
u32: 8,
|
u32: 8,
|
||||||
u64: 9,
|
u64: 9,
|
||||||
u: 10,
|
u: 10,
|
||||||
f32: 11,
|
f32: 11,
|
||||||
f64: 12,
|
f64: 12,
|
||||||
b: true,
|
b: true,
|
||||||
c64: 13 + 14i,
|
c64: 13 + 14i,
|
||||||
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",
|
arr2: [3]E{{i: 27}, {i: 28}, {i: 29}},
|
||||||
e: E{i: 30},
|
s: "hello",
|
||||||
pf: &StructWithAllTypeFields{},
|
e: E{i: 30},
|
||||||
pi: &i,
|
pf: &StructWithAllTypeFields{},
|
||||||
|
pi: &i,
|
||||||
// intr: &Struct{},
|
// intr: &Struct{},
|
||||||
// m: make(map[string]uint64),
|
// m: make(map[string]uint64),
|
||||||
// c: make(chan int),
|
// c: make(chan int),
|
||||||
@@ -136,7 +139,7 @@ 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.slice, s.arr, s.arr2,
|
||||||
s.s,
|
s.s,
|
||||||
s.e, s,
|
s.e, s,
|
||||||
s.pf, s.pi,
|
s.pf, s.pi,
|
||||||
|
|||||||
133
ssa/di.go
133
ssa/di.go
@@ -152,7 +152,8 @@ func (b diBuilder) createType(ty Type, pos token.Position) DIType {
|
|||||||
return b.createBasicType(ty)
|
return b.createBasicType(ty)
|
||||||
case *types.Slice:
|
case *types.Slice:
|
||||||
ty := b.prog.rawType(b.prog.rtType("Slice").RawType().Underlying())
|
ty := b.prog.rawType(b.prog.rtType("Slice").RawType().Underlying())
|
||||||
return b.createStructType(ty, pos)
|
tyElem := b.prog.rawType(t.Elem())
|
||||||
|
return b.createSliceType(ty, tyElem)
|
||||||
case *types.Struct:
|
case *types.Struct:
|
||||||
return b.createStructType(ty, pos)
|
return b.createStructType(ty, pos)
|
||||||
case *types.Signature:
|
case *types.Signature:
|
||||||
@@ -160,7 +161,7 @@ func (b diBuilder) createType(ty Type, pos token.Position) DIType {
|
|||||||
case *types.Tuple:
|
case *types.Tuple:
|
||||||
return b.createBasicType(ty)
|
return b.createBasicType(ty)
|
||||||
case *types.Array:
|
case *types.Array:
|
||||||
return b.createBasicType(ty)
|
return b.createArrayType(ty, t.Len())
|
||||||
case *types.Chan:
|
case *types.Chan:
|
||||||
return b.createBasicType(ty)
|
return b.createBasicType(ty)
|
||||||
case *types.Map:
|
case *types.Map:
|
||||||
@@ -257,33 +258,107 @@ func (b diBuilder) createBasicType(t Type) DIType {
|
|||||||
func (b diBuilder) createStringType(pos token.Position) DIType {
|
func (b diBuilder) createStringType(pos token.Position) DIType {
|
||||||
ty := b.prog.rtType("String")
|
ty := b.prog.rtType("String")
|
||||||
|
|
||||||
return &aDIType{ll: b.di.CreateStructType(
|
return &aDIType{
|
||||||
llvm.Metadata{},
|
ll: b.di.CreateStructType(
|
||||||
llvm.DIStructType{
|
llvm.Metadata{},
|
||||||
Name: "string",
|
llvm.DIStructType{
|
||||||
SizeInBits: b.prog.SizeOf(ty) * 8,
|
Name: "string",
|
||||||
AlignInBits: uint32(b.prog.sizes.Alignof(ty.RawType()) * 8),
|
SizeInBits: b.prog.SizeOf(ty) * 8,
|
||||||
Elements: []llvm.Metadata{
|
AlignInBits: uint32(b.prog.sizes.Alignof(ty.RawType()) * 8),
|
||||||
b.di.CreateMemberType(
|
Elements: []llvm.Metadata{
|
||||||
llvm.Metadata{},
|
b.di.CreateMemberType(
|
||||||
llvm.DIMemberType{
|
llvm.Metadata{},
|
||||||
Name: "data",
|
llvm.DIMemberType{
|
||||||
SizeInBits: b.prog.SizeOf(b.prog.CStr()) * 8,
|
Name: "data",
|
||||||
AlignInBits: uint32(b.prog.sizes.Alignof(b.prog.CStr().RawType()) * 8),
|
SizeInBits: b.prog.SizeOf(b.prog.CStr()) * 8,
|
||||||
Type: b.diType(b.prog.CStr(), pos).ll,
|
AlignInBits: uint32(b.prog.sizes.Alignof(b.prog.CStr().RawType()) * 8),
|
||||||
},
|
OffsetInBits: b.prog.OffsetOf(ty, 0) * 8,
|
||||||
),
|
Type: b.diType(b.prog.CStr(), pos).ll,
|
||||||
b.di.CreateMemberType(
|
},
|
||||||
llvm.Metadata{},
|
),
|
||||||
llvm.DIMemberType{
|
b.di.CreateMemberType(
|
||||||
Name: "len",
|
llvm.Metadata{},
|
||||||
SizeInBits: b.prog.SizeOf(b.prog.Int()) * 8,
|
llvm.DIMemberType{
|
||||||
AlignInBits: uint32(b.prog.sizes.Alignof(b.prog.Uint().RawType()) * 8),
|
Name: "len",
|
||||||
Type: b.diType(b.prog.Int(), pos).ll,
|
SizeInBits: b.prog.SizeOf(b.prog.Uint()) * 8,
|
||||||
},
|
AlignInBits: uint32(b.prog.sizes.Alignof(b.prog.Uint().RawType()) * 8),
|
||||||
),
|
OffsetInBits: b.prog.OffsetOf(ty, 1) * 8,
|
||||||
|
Type: b.diType(b.prog.Uint(), pos).ll,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})}
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b diBuilder) createArrayType(ty Type, l int64) DIType {
|
||||||
|
tyElem := b.prog.rawType(ty.RawType().(*types.Array).Elem())
|
||||||
|
return &aDIType{ll: b.di.CreateArrayType(llvm.DIArrayType{
|
||||||
|
SizeInBits: b.prog.SizeOf(ty) * 8,
|
||||||
|
AlignInBits: uint32(b.prog.sizes.Alignof(ty.RawType()) * 8),
|
||||||
|
ElementType: b.diType(tyElem, token.Position{}).ll,
|
||||||
|
Subscripts: []llvm.DISubrange{{
|
||||||
|
Count: l,
|
||||||
|
}},
|
||||||
|
})}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b diBuilder) createSliceType(ty, tyElem Type) DIType {
|
||||||
|
pos := token.Position{}
|
||||||
|
diTyElem := b.diType(tyElem, pos)
|
||||||
|
|
||||||
|
diPtrTyElem := b.di.CreatePointerType(
|
||||||
|
llvm.DIPointerType{
|
||||||
|
Name: tyElem.RawType().String(),
|
||||||
|
Pointee: diTyElem.ll,
|
||||||
|
SizeInBits: b.prog.SizeOf(b.prog.Uintptr()) * 8,
|
||||||
|
AlignInBits: uint32(b.prog.sizes.Alignof(b.prog.Uintptr().RawType()) * 8),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
return &aDIType{
|
||||||
|
ll: b.di.CreateStructType(
|
||||||
|
llvm.Metadata{},
|
||||||
|
llvm.DIStructType{
|
||||||
|
Name: ty.RawType().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.Uintptr()) * 8,
|
||||||
|
AlignInBits: uint32(b.prog.sizes.Alignof(b.prog.Uintptr().RawType()) * 8),
|
||||||
|
OffsetInBits: b.prog.OffsetOf(ty, 0) * 8,
|
||||||
|
Type: diPtrTyElem,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
b.di.CreateMemberType(
|
||||||
|
llvm.Metadata{},
|
||||||
|
llvm.DIMemberType{
|
||||||
|
Name: "len",
|
||||||
|
SizeInBits: b.prog.SizeOf(b.prog.Uint()) * 8,
|
||||||
|
AlignInBits: uint32(b.prog.sizes.Alignof(b.prog.Uint().RawType()) * 8),
|
||||||
|
OffsetInBits: b.prog.OffsetOf(ty, 1) * 8,
|
||||||
|
Type: b.diType(b.prog.Uint(), pos).ll,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
b.di.CreateMemberType(
|
||||||
|
llvm.Metadata{},
|
||||||
|
llvm.DIMemberType{
|
||||||
|
Name: "cap",
|
||||||
|
SizeInBits: b.prog.SizeOf(b.prog.Uint()) * 8,
|
||||||
|
AlignInBits: uint32(b.prog.sizes.Alignof(b.prog.Uint().RawType()) * 8),
|
||||||
|
OffsetInBits: b.prog.OffsetOf(ty, 2) * 8,
|
||||||
|
Type: b.diType(b.prog.Uint(), pos).ll,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b diBuilder) createComplexType(t Type) DIType {
|
func (b diBuilder) createComplexType(t Type) DIType {
|
||||||
@@ -542,8 +617,6 @@ const (
|
|||||||
|
|
||||||
func skipType(t types.Type) bool {
|
func skipType(t types.Type) bool {
|
||||||
switch t.(type) {
|
switch t.(type) {
|
||||||
case *types.Slice:
|
|
||||||
return true
|
|
||||||
case *types.Interface:
|
case *types.Interface:
|
||||||
return true
|
return true
|
||||||
case *types.Signature:
|
case *types.Signature:
|
||||||
|
|||||||
Reference in New Issue
Block a user