github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/internal/sys/arch.go (about) 1 // Copyright 2016 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 sys 6 7 import "encoding/binary" 8 9 // ArchFamily represents a family of one or more related architectures. 10 // For example, ppc64 and ppc64le are both members of the PPC64 family. 11 type ArchFamily byte 12 13 const ( 14 NoArch ArchFamily = iota 15 AMD64 16 ARM 17 ARM64 18 I386 19 MIPS 20 MIPS64 21 PPC64 22 RISCV64 23 S390X 24 Wasm 25 ) 26 27 // Arch represents an individual architecture. 28 type Arch struct { 29 Name string 30 Family ArchFamily 31 32 ByteOrder binary.ByteOrder 33 34 // PtrSize is the size in bytes of pointers and the 35 // predeclared "int", "uint", and "uintptr" types. 36 PtrSize int 37 38 // RegSize is the size in bytes of general purpose registers. 39 RegSize int 40 41 // MinLC is the minimum length of an instruction code. 42 MinLC int 43 } 44 45 // InFamily reports whether a is a member of any of the specified 46 // architecture families. 47 func (a *Arch) InFamily(xs ...ArchFamily) bool { 48 for _, x := range xs { 49 if a.Family == x { 50 return true 51 } 52 } 53 return false 54 } 55 56 var Arch386 = &Arch{ 57 Name: "386", 58 Family: I386, 59 ByteOrder: binary.LittleEndian, 60 PtrSize: 4, 61 RegSize: 4, 62 MinLC: 1, 63 } 64 65 var ArchAMD64 = &Arch{ 66 Name: "amd64", 67 Family: AMD64, 68 ByteOrder: binary.LittleEndian, 69 PtrSize: 8, 70 RegSize: 8, 71 MinLC: 1, 72 } 73 74 var ArchARM = &Arch{ 75 Name: "arm", 76 Family: ARM, 77 ByteOrder: binary.LittleEndian, 78 PtrSize: 4, 79 RegSize: 4, 80 MinLC: 4, 81 } 82 83 var ArchARM64 = &Arch{ 84 Name: "arm64", 85 Family: ARM64, 86 ByteOrder: binary.LittleEndian, 87 PtrSize: 8, 88 RegSize: 8, 89 MinLC: 4, 90 } 91 92 var ArchMIPS = &Arch{ 93 Name: "mips", 94 Family: MIPS, 95 ByteOrder: binary.BigEndian, 96 PtrSize: 4, 97 RegSize: 4, 98 MinLC: 4, 99 } 100 101 var ArchMIPSLE = &Arch{ 102 Name: "mipsle", 103 Family: MIPS, 104 ByteOrder: binary.LittleEndian, 105 PtrSize: 4, 106 RegSize: 4, 107 MinLC: 4, 108 } 109 110 var ArchMIPS64 = &Arch{ 111 Name: "mips64", 112 Family: MIPS64, 113 ByteOrder: binary.BigEndian, 114 PtrSize: 8, 115 RegSize: 8, 116 MinLC: 4, 117 } 118 119 var ArchMIPS64LE = &Arch{ 120 Name: "mips64le", 121 Family: MIPS64, 122 ByteOrder: binary.LittleEndian, 123 PtrSize: 8, 124 RegSize: 8, 125 MinLC: 4, 126 } 127 128 var ArchPPC64 = &Arch{ 129 Name: "ppc64", 130 Family: PPC64, 131 ByteOrder: binary.BigEndian, 132 PtrSize: 8, 133 RegSize: 8, 134 MinLC: 4, 135 } 136 137 var ArchPPC64LE = &Arch{ 138 Name: "ppc64le", 139 Family: PPC64, 140 ByteOrder: binary.LittleEndian, 141 PtrSize: 8, 142 RegSize: 8, 143 MinLC: 4, 144 } 145 146 var ArchRISCV64 = &Arch{ 147 Name: "riscv64", 148 Family: RISCV64, 149 ByteOrder: binary.LittleEndian, 150 PtrSize: 8, 151 RegSize: 8, 152 MinLC: 4, 153 } 154 155 var ArchS390X = &Arch{ 156 Name: "s390x", 157 Family: S390X, 158 ByteOrder: binary.BigEndian, 159 PtrSize: 8, 160 RegSize: 8, 161 MinLC: 2, 162 } 163 164 var ArchWasm = &Arch{ 165 Name: "wasm", 166 Family: Wasm, 167 ByteOrder: binary.LittleEndian, 168 PtrSize: 8, 169 RegSize: 8, 170 MinLC: 1, 171 } 172 173 var Archs = [...]*Arch{ 174 Arch386, 175 ArchAMD64, 176 ArchARM, 177 ArchARM64, 178 ArchMIPS, 179 ArchMIPSLE, 180 ArchMIPS64, 181 ArchMIPS64LE, 182 ArchPPC64, 183 ArchPPC64LE, 184 ArchRISCV64, 185 ArchS390X, 186 ArchWasm, 187 }