Source file src/cmd/internal/goobj/builtin.go

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

View as plain text