diff options
author | Russ Cox <rsc@golang.org> | 2011-02-24 17:11:20 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2011-02-24 17:11:20 -0500 |
commit | 8d36a78440f4a489d961ecb034dfc2b0fdb6ab51 (patch) | |
tree | 8707653d23065293ebd1570fb71b102937962edd | |
parent | 820dc9ff1af5771a66ce4666e4e7620f831fba45 (diff) | |
download | go-8d36a78440f4a489d961ecb034dfc2b0fdb6ab51.tar.gz go-8d36a78440f4a489d961ecb034dfc2b0fdb6ab51.zip |
reflect: add pointer word to CommonType
The pointer will eventually let us find *T given T.
This CL just makes room for it, always storing a zero.
R=r, r2
CC=golang-dev
https://golang.org/cl/4221046
-rw-r--r-- | src/cmd/gc/reflect.c | 5 | ||||
-rw-r--r-- | src/cmd/ld/dwarf.c | 40 | ||||
-rw-r--r-- | src/pkg/reflect/type.go | 1 | ||||
-rw-r--r-- | src/pkg/runtime/type.go | 3 | ||||
-rw-r--r-- | src/pkg/runtime/type.h | 1 |
5 files changed, 30 insertions, 20 deletions
diff --git a/src/cmd/gc/reflect.c b/src/cmd/gc/reflect.c index 36c245d478..4dbe9d28d7 100644 --- a/src/cmd/gc/reflect.c +++ b/src/cmd/gc/reflect.c @@ -592,7 +592,8 @@ dcommontype(Sym *s, int ot, Type *t) // fieldAlign uint8; // kind uint8; // string *string; - // *nameInfo; + // *extraType; + // ptrToThis *Type // } ot = duintptr(s, ot, t->width); ot = duint32(s, ot, typehash(t)); @@ -616,7 +617,7 @@ dcommontype(Sym *s, int ot, Type *t) ot = dsymptr(s, ot, s1, 0); // extraType else ot = duintptr(s, ot, 0); - + ot = duintptr(s, ot, 0); // ptr type (placeholder for now) return ot; } diff --git a/src/cmd/ld/dwarf.c b/src/cmd/ld/dwarf.c index 8c53d7d133..5ba4b7c643 100644 --- a/src/cmd/ld/dwarf.c +++ b/src/cmd/ld/dwarf.c @@ -772,6 +772,9 @@ enum { KindUnsafePointer, KindNoPointers = 1<<7, + + // size of Type interface header + CommonType structure. + CommonSize = 2*PtrSize+ 4*PtrSize + 8, }; static Reloc* @@ -849,59 +852,59 @@ decodetype_size(Sym *s) static Sym* decodetype_arrayelem(Sym *s) { - return decode_reloc_sym(s, 5*PtrSize + 8); // 0x1c / 0x30 + return decode_reloc_sym(s, CommonSize); // 0x1c / 0x30 } static vlong decodetype_arraylen(Sym *s) { - return decode_inuxi(s->p + 6*PtrSize + 8, PtrSize); + return decode_inuxi(s->p + CommonSize+PtrSize, PtrSize); } // Type.PtrType.elem static Sym* decodetype_ptrelem(Sym *s) { - return decode_reloc_sym(s, 5*PtrSize + 8); // 0x1c / 0x30 + return decode_reloc_sym(s, CommonSize); // 0x1c / 0x30 } // Type.MapType.key, elem static Sym* decodetype_mapkey(Sym *s) { - return decode_reloc_sym(s, 5*PtrSize + 8); // 0x1c / 0x30 + return decode_reloc_sym(s, CommonSize); // 0x1c / 0x30 } static Sym* decodetype_mapvalue(Sym *s) { - return decode_reloc_sym(s, 6*PtrSize + 8); // 0x20 / 0x38 + return decode_reloc_sym(s, CommonSize+PtrSize); // 0x20 / 0x38 } // Type.ChanType.elem static Sym* decodetype_chanelem(Sym *s) { - return decode_reloc_sym(s, 5*PtrSize + 8); // 0x1c / 0x30 + return decode_reloc_sym(s, CommonSize); // 0x1c / 0x30 } // Type.FuncType.dotdotdot static int decodetype_funcdotdotdot(Sym *s) { - return s->p[5*PtrSize + 8]; + return s->p[CommonSize]; } // Type.FuncType.in.len static int decodetype_funcincount(Sym *s) { - return decode_inuxi(s->p + 7*PtrSize + 8, 4); + return decode_inuxi(s->p + CommonSize+2*PtrSize, 4); } static int decodetype_funcoutcount(Sym *s) { - return decode_inuxi(s->p + 8*PtrSize + 16, 4); + return decode_inuxi(s->p + CommonSize+3*PtrSize + 2*4, 4); } static Sym* @@ -909,7 +912,7 @@ decodetype_funcintype(Sym *s, int i) { Reloc *r; - r = decode_reloc(s, 6*PtrSize + 8); + r = decode_reloc(s, CommonSize + PtrSize); if (r == nil) return nil; return decode_reloc_sym(r->sym, r->add + i * PtrSize); @@ -920,7 +923,7 @@ decodetype_funcouttype(Sym *s, int i) { Reloc *r; - r = decode_reloc(s, 7*PtrSize + 16); + r = decode_reloc(s, CommonSize + 2*PtrSize + 2*4); if (r == nil) return nil; return decode_reloc_sym(r->sym, r->add + i * PtrSize); @@ -930,15 +933,18 @@ decodetype_funcouttype(Sym *s, int i) static int decodetype_structfieldcount(Sym *s) { - return decode_inuxi(s->p + 6*PtrSize + 8, 4); // 0x20 / 0x38 + return decode_inuxi(s->p + CommonSize + PtrSize, 4); } -// Type.StructType.fields[]-> name, typ and offset. sizeof(structField) = 5*PtrSize +enum { + StructFieldSize = 5*PtrSize +}; +// Type.StructType.fields[]-> name, typ and offset. static char* decodetype_structfieldname(Sym *s, int i) { // go.string."foo" 0x28 / 0x40 - s = decode_reloc_sym(s, 6*PtrSize + 0x10 + i*5*PtrSize); + s = decode_reloc_sym(s, CommonSize + PtrSize + 2*4 + i*StructFieldSize); if (s == nil) // embedded structs have a nil name. return nil; s = decode_reloc_sym(s, 0); // string."foo" @@ -950,20 +956,20 @@ decodetype_structfieldname(Sym *s, int i) static Sym* decodetype_structfieldtype(Sym *s, int i) { - return decode_reloc_sym(s, 8*PtrSize + 0x10 + i*5*PtrSize); // 0x30 / 0x50 + return decode_reloc_sym(s, CommonSize + PtrSize + 2*4 + i*StructFieldSize + 2*PtrSize); } static vlong decodetype_structfieldoffs(Sym *s, int i) { - return decode_inuxi(s->p + 10*PtrSize + 0x10 + i*5*PtrSize, 4); // 0x38 / 0x60 + return decode_inuxi(s->p + CommonSize + PtrSize + 2*4 + i*StructFieldSize + 4*PtrSize, 4); } // InterfaceTYpe.methods.len static vlong decodetype_ifacemethodcount(Sym *s) { - return decode_inuxi(s->p + 6*PtrSize + 8, 4); + return decode_inuxi(s->p + CommonSize + PtrSize, 4); } diff --git a/src/pkg/reflect/type.go b/src/pkg/reflect/type.go index 9ccee3ae9d..efe0238eaa 100644 --- a/src/pkg/reflect/type.go +++ b/src/pkg/reflect/type.go @@ -48,6 +48,7 @@ type commonType struct { kind uint8 string *string *uncommonType + ptrToThis *runtime.Type } type method struct { diff --git a/src/pkg/runtime/type.go b/src/pkg/runtime/type.go index 87268db4cf..71ad4e7a54 100644 --- a/src/pkg/runtime/type.go +++ b/src/pkg/runtime/type.go @@ -9,7 +9,7 @@ * data structures and must be kept in sync with this file: * * ../../cmd/gc/reflect.c - * ../../cmd/ld/dwarf.c + * ../../cmd/ld/dwarf.c decodetype_* * ../reflect/type.go * type.h */ @@ -35,6 +35,7 @@ type commonType struct { kind uint8 // enumeration for C string *string // string form; unnecessary but undeniably useful *uncommonType // (relatively) uncommon fields + ptrToThis *Type // pointer to this type, if used in binary or has methods } // Values for commonType.kind. diff --git a/src/pkg/runtime/type.h b/src/pkg/runtime/type.h index c7d9dace27..1adb6dc2e7 100644 --- a/src/pkg/runtime/type.h +++ b/src/pkg/runtime/type.h @@ -31,6 +31,7 @@ struct CommonType uint8 kind; String *string; UncommonType *x; + Type *ptrto; }; enum { |