llgo/ssa: pkgName

This commit is contained in:
xushiwei
2024-05-26 09:34:43 +08:00
parent 914a0c60b0
commit 91c9b4e168
4 changed files with 15 additions and 16 deletions

View File

@@ -12,11 +12,9 @@ import (
type _type = abi.Type
type interfacetype = abi.InterfaceType
/*
type maptype = abi.MapType
/*
type arraytype = abi.ArrayType
type chantype = abi.ChanType

View File

@@ -21,6 +21,8 @@ type iface struct {
data unsafe.Pointer
}
type interfacetype = abi.InterfaceType
// layout of Itab known to compilers
// allocated in non-garbage-collected memory
// Needs to be in sync with
@@ -126,12 +128,10 @@ func Named(pkgPath, name Name, underlying *Type, methods []abi.Method) *Type {
}
uncommon := (*abi.UncommonType)(c.Advance(ptr, int(typeHdrSize)))
*uncommon = abi.UncommonType{
PkgPath_: pkgPath,
Mcount: uint16(n),
Xcount: uint16(xcount),
Moff: uint32(uncommonTypeHdrSize),
}
uncommon.PkgPath_ = pkgPath
uncommon.Mcount = uint16(n)
uncommon.Xcount = uint16(xcount)
uncommon.Moff = uint32(uncommonTypeHdrSize)
data := (*abi.Method)(c.Advance(ptr, int(typeHdrSize+uncommonTypeHdrSize)))
copy(unsafe.Slice(data, n), methods)
@@ -139,18 +139,14 @@ func Named(pkgPath, name Name, underlying *Type, methods []abi.Method) *Type {
}
// Interface returns an interface type.
func Interface(pkgPath string, methods []abi.Imethod) *Type {
var npkg abi.Name
if len(pkgPath) > 0 {
npkg = abi.NewName(pkgPath, "", false, false)
}
func Interface(pkgPath Name, methods []abi.Imethod) *Type {
ret := &abi.InterfaceType{
Type: Type{
Size_: unsafe.Sizeof(eface{}),
Hash: uint32(abi.Interface), // TODO(xsw): hash
Kind_: uint8(abi.Interface),
},
PkgPath: npkg,
PkgPath: pkgPath,
Methods: methods,
}
return &ret.Type

View File

@@ -221,6 +221,11 @@ func (b Builder) Str(v string) (ret Expr) {
return Expr{aggregateValue(b.impl, prog.rtString(), data, size), prog.String()}
}
func (b Builder) pkgName(pkgPath string) Expr {
// TODO(xsw): use a global cache
return b.Call(b.Pkg.rtFunc("NewPkgName"), b.Str(pkgPath))
}
// unsafeString(data *byte, size int) string
func (b Builder) unsafeString(data, size llvm.Value) Expr {
prog := b.Prog

View File

@@ -84,7 +84,7 @@ func (b Builder) abiStructOf(t *types.Struct) Expr {
off := uintptr(prog.OffsetOf(typ, i))
flds[i] = b.structField(sfAbi, prog, f, off, t.Tag(i))
}
pkgPath := b.Str(pkg.Path())
pkgPath := b.pkgName(pkg.Path())
params := strucAbi.raw.Type.(*types.Signature).Params()
tSlice := prog.rawType(params.At(params.Len() - 1).Type().(*types.Slice))
fldSlice := b.SliceLit(tSlice, flds...)