diff --git a/internal/abi/llgo_autogen.lla b/internal/abi/llgo_autogen.lla index 4f8bcd99..c349a176 100644 Binary files a/internal/abi/llgo_autogen.lla and b/internal/abi/llgo_autogen.lla differ diff --git a/internal/abi/type.go b/internal/abi/type.go index 17b61967..085a6475 100644 --- a/internal/abi/type.go +++ b/internal/abi/type.go @@ -50,8 +50,6 @@ type Type struct { PtrToThis TypeOff // type for pointer to this type, may be zero } -func (t *Type) Kind() Kind { return Kind(t.Kind_ & KindMask) } - // A Kind represents the specific kind of type that a Type represents. // The zero Kind is not a valid kind. type Kind uint @@ -86,12 +84,14 @@ const ( UnsafePointer ) +/* const ( // TODO (khr, drchase) why aren't these in TFlag? Investigate, fix if possible. KindDirectIface = 1 << 5 KindGCProg = 1 << 6 // Type.gc points to GC program KindMask = (1 << 5) - 1 ) +*/ // TFlag is used by a Type to signal what extra type information is // available in the memory directly following the Type value. @@ -207,6 +207,10 @@ type StructField struct { Offset uintptr // byte offset of field } +func (f *StructField) Embedded() bool { + return f.Name.IsEmbedded() +} + type StructType struct { Type PkgPath Name @@ -225,6 +229,16 @@ type Imethod struct { Typ TypeOff // .(*FuncType) underneath } +func (t *Type) Kind() Kind { return Kind(t.Kind_) } + +// Size returns the size of data with type t. +func (t *Type) Size() uintptr { return t.Size_ } + +// Align returns the alignment of data with type t. +func (t *Type) Align() int { return int(t.Align_) } + +func (t *Type) FieldAlign() int { return int(t.FieldAlign_) } + func (t *Type) Common() *Type { return t } diff --git a/internal/runtime/llgo_autogen.lla b/internal/runtime/llgo_autogen.lla index 1514f257..e6491d05 100644 Binary files a/internal/runtime/llgo_autogen.lla and b/internal/runtime/llgo_autogen.lla differ diff --git a/internal/runtime/z_type.go b/internal/runtime/z_type.go index e70a81ff..f9915453 100644 --- a/internal/runtime/z_type.go +++ b/internal/runtime/z_type.go @@ -78,9 +78,36 @@ var ( func basicType(kind abi.Kind) *Type { return &Type{ Size_: sizeBasicTypes[kind], - Hash: uint32(kind), + Hash: uint32(kind), // TODO(xsw): hash Kind_: uint8(kind), } } // ----------------------------------------------------------------------------- + +// StructField returns a struct field. +func StructField(name string, typ *Type, off uintptr, tag string, exported, embedded bool) abi.StructField { + n := abi.NewName(name, tag, exported, embedded) + return abi.StructField{ + Name: n, + Typ: typ, + Offset: off, + } +} + +// Struct returns a struct type. +func Struct(size uintptr, pkgPath string, fields ...abi.StructField) *Type { + npkg := abi.NewName(pkgPath, "", false, false) + ret := &abi.StructType{ + Type: Type{ + Size_: size, + Hash: uint32(abi.Struct), // TODO(xsw): hash + Kind_: uint8(abi.Struct), + }, + PkgPath: npkg, + Fields: fields, + } + return &ret.Type +} + +// -----------------------------------------------------------------------------