ssa: set pointer directiface

This commit is contained in:
visualfc
2024-07-03 22:16:24 +08:00
parent 490a16a8df
commit bcb217c1da
19 changed files with 1098 additions and 386 deletions

View File

@@ -179,6 +179,8 @@ func typehash(t *_type, p unsafe.Pointer, h uintptr) uintptr {
h = typehash(a.Elem, add(p, i*a.Elem.Size_), h)
}
return h
case abi.Chan:
return typehash(t.Elem(), p, h)
case abi.Struct:
s := (*structtype)(unsafe.Pointer(t))
for _, f := range s.Fields {
@@ -195,8 +197,8 @@ func typehash(t *_type, p unsafe.Pointer, h uintptr) uintptr {
}
}
func ptrequal(p, q unsafe.Pointer) bool {
return p == q
func memequalptr(p, q unsafe.Pointer) bool {
return *(*uintptr)(p) == *(*uintptr)(q)
}
func memequal0(p, q unsafe.Pointer) bool {
return true

View File

@@ -291,8 +291,13 @@ func IfacePtrData(i iface) unsafe.Pointer {
if i.tab == nil {
panic(errorString("invalid memory address or nil pointer dereference").Error())
}
if i.tab._type.Kind_&abi.KindDirectIface != 0 {
return unsafe.Pointer(&i.data)
switch i.tab._type.Kind() {
case abi.Bool, abi.Int, abi.Int8, abi.Int16, abi.Int32, abi.Int64,
abi.Uint, abi.Uint8, abi.Uint16, abi.Uint32, abi.Uint64, abi.Uintptr,
abi.Float32, abi.Float64, abi.Array, abi.Struct:
if isDirectIface(i.tab._type) {
return unsafe.Pointer(&i.data)
}
}
return i.data
}

View File

@@ -55,7 +55,7 @@ func basicEqual(kind Kind, size uintptr) func(a, b unsafe.Pointer) bool {
case abi.String:
return strequal
case abi.UnsafePointer:
return ptrequal
return memequalptr
}
panic("unreachable")
}
@@ -195,7 +195,7 @@ func newPointer(elem *Type) *Type {
Align_: pointerAlign,
FieldAlign_: pointerAlign,
Kind_: uint8(abi.Pointer),
Equal: ptrequal,
Equal: memequalptr,
},
Elem: elem,
}
@@ -266,11 +266,13 @@ func ChanOf(dir int, strChan string, elem *Type) *Type {
Align_: pointerAlign,
FieldAlign_: pointerAlign,
Kind_: uint8(abi.Chan),
Equal: memequalptr,
Str_: strChan + " " + elem.String(),
},
Elem: elem,
Dir: abi.ChanDir(dir),
}
return &ret.Type
}