Source file src/internal/abi/compiletype.go
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 abi 6 7 // These functions are the build-time version of the Go type data structures. 8 9 // Their contents must be kept in sync with their definitions. 10 // Because the host and target type sizes can differ, the compiler and 11 // linker cannot use the host information that they might get from 12 // either unsafe.Sizeof and Alignof, nor runtime, reflect, or reflectlite. 13 14 // CommonSize returns sizeof(Type) for a compilation target with a given ptrSize 15 func CommonSize(ptrSize int) int { return 4*ptrSize + 8 + 8 } 16 17 // StructFieldSize returns sizeof(StructField) for a compilation target with a given ptrSize 18 func StructFieldSize(ptrSize int) int { return 3 * ptrSize } 19 20 // UncommonSize returns sizeof(UncommonType). This currently does not depend on ptrSize. 21 // This exported function is in an internal package, so it may change to depend on ptrSize in the future. 22 func UncommonSize() uint64 { return 4 + 2 + 2 + 4 + 4 } 23 24 // TFlagOff returns the offset of Type.TFlag for a compilation target with a given ptrSize 25 func TFlagOff(ptrSize int) int { return 2*ptrSize + 4 } 26 27 // ITabTypeOff returns the offset of ITab.Type for a compilation target with a given ptrSize 28 func ITabTypeOff(ptrSize int) int { return ptrSize } 29