builtin.go (1050B)
1 // Copyright 2019 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 goobj 6 7 // Builtin (compiler-generated) function references appear 8 // frequently. We assign special indices for them, so they 9 // don't need to be referenced by name. 10 11 // NBuiltin returns the number of listed builtin 12 // symbols. 13 func NBuiltin() int { 14 return len(builtins) 15 } 16 17 // BuiltinName returns the name and ABI of the i-th 18 // builtin symbol. 19 func BuiltinName(i int) (string, int) { 20 return builtins[i].name, builtins[i].abi 21 } 22 23 // BuiltinIdx returns the index of the builtin with the 24 // given name and abi, or -1 if it is not a builtin. 25 func BuiltinIdx(name string, abi int) int { 26 i, ok := builtinMap[name] 27 if !ok { 28 return -1 29 } 30 if builtins[i].abi != abi { 31 return -1 32 } 33 return i 34 } 35 36 //go:generate go run mkbuiltin.go 37 38 var builtinMap map[string]int 39 40 func init() { 41 builtinMap = make(map[string]int, len(builtins)) 42 for i, b := range builtins { 43 builtinMap[b.name] = i 44 } 45 }