github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/rttype/rttype.go (about) 1 // Copyright 2023 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package rttype allows the compiler to share type information with 6 // the runtime. The shared type information is stored in 7 // internal/abi. This package translates those types from the host 8 // machine on which the compiler runs to the target machine on which 9 // the compiled program will run. In particular, this package handles 10 // layout differences between e.g. a 64 bit compiler and 32 bit 11 // target. 12 package rttype 13 14 import ( 15 "github.com/shogo82148/std/cmd/compile/internal/types" 16 "github.com/shogo82148/std/cmd/internal/obj" 17 ) 18 19 // The type structures shared with the runtime. 20 var Type *types.Type 21 22 var ArrayType *types.Type 23 var ChanType *types.Type 24 var FuncType *types.Type 25 var InterfaceType *types.Type 26 var MapType *types.Type 27 var PtrType *types.Type 28 var SliceType *types.Type 29 var StructType *types.Type 30 31 // Types that are parts of the types above. 32 var IMethod *types.Type 33 var Method *types.Type 34 var StructField *types.Type 35 var UncommonType *types.Type 36 37 // Type switches and asserts 38 var InterfaceSwitch *types.Type 39 var TypeAssert *types.Type 40 41 // Interface tables (itabs) 42 var ITab *types.Type 43 44 func Init() 45 46 // A Cursor represents a typed location inside a static variable where we 47 // are going to write. 48 type Cursor struct { 49 lsym *obj.LSym 50 offset int64 51 typ *types.Type 52 } 53 54 // NewCursor returns a cursor starting at lsym+off and having type t. 55 func NewCursor(lsym *obj.LSym, off int64, t *types.Type) Cursor 56 57 // WritePtr writes a pointer "target" to the component at the location specified by c. 58 func (c Cursor) WritePtr(target *obj.LSym) 59 60 func (c Cursor) WritePtrWeak(target *obj.LSym) 61 62 func (c Cursor) WriteUintptr(val uint64) 63 64 func (c Cursor) WriteUint32(val uint32) 65 66 func (c Cursor) WriteUint16(val uint16) 67 68 func (c Cursor) WriteUint8(val uint8) 69 70 func (c Cursor) WriteInt(val int64) 71 72 func (c Cursor) WriteInt32(val int32) 73 74 func (c Cursor) WriteBool(val bool) 75 76 // WriteSymPtrOff writes a "pointer" to the given symbol. The symbol 77 // is encoded as a uint32 offset from the start of the section. 78 func (c Cursor) WriteSymPtrOff(target *obj.LSym, weak bool) 79 80 // WriteSlice writes a slice header to c. The pointer is target+off, the len and cap fields are given. 81 func (c Cursor) WriteSlice(target *obj.LSym, off, len, cap int64) 82 83 // Reloc adds a relocation from the current cursor position. 84 // Reloc fills in Off and Siz fields. Caller should fill in the rest (Type, others). 85 func (c Cursor) Reloc() *obj.Reloc 86 87 // Field selects the field with the given name from the struct pointed to by c. 88 func (c Cursor) Field(name string) Cursor 89 90 func (c Cursor) Elem(i int64) Cursor 91 92 type ArrayCursor struct { 93 c Cursor 94 n int 95 } 96 97 // NewArrayCursor returns a cursor starting at lsym+off and having n copies of type t. 98 func NewArrayCursor(lsym *obj.LSym, off int64, t *types.Type, n int) ArrayCursor 99 100 // Elem selects element i of the array pointed to by c. 101 func (a ArrayCursor) Elem(i int) Cursor 102 103 // ModifyArray converts a cursor pointing at a type [k]T to a cursor pointing 104 // at a type [n]T. 105 // Also returns the size delta, aka (n-k)*sizeof(T). 106 func (c Cursor) ModifyArray(n int) (ArrayCursor, int64)