...

Source file src/cmd/compile/internal/ssa/id.go

Documentation: cmd/compile/internal/ssa

     1  // Copyright 2015 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 ssa
     6  
     7  type ID int32
     8  
     9  // idAlloc provides an allocator for unique integers.
    10  type idAlloc struct {
    11  	last ID
    12  }
    13  
    14  // get allocates an ID and returns it. IDs are always > 0.
    15  func (a *idAlloc) get() ID {
    16  	x := a.last
    17  	x++
    18  	if x == 1<<31-1 {
    19  		panic("too many ids for this function")
    20  	}
    21  	a.last = x
    22  	return x
    23  }
    24  
    25  // num returns the maximum ID ever returned + 1.
    26  func (a *idAlloc) num() int {
    27  	return int(a.last + 1)
    28  }
    29  

View as plain text