github.com/sanprasirt/go@v0.0.0-20170607001320-a027466e4b6d/src/cmd/compile/internal/ssa/location.go (about)

     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  import (
     8  	"cmd/compile/internal/types"
     9  	"fmt"
    10  )
    11  
    12  // A place that an ssa variable can reside.
    13  type Location interface {
    14  	Name() string // name to use in assembly templates: %rax, 16(%rsp), ...
    15  }
    16  
    17  // A Register is a machine register, like %rax.
    18  // They are numbered densely from 0 (for each architecture).
    19  type Register struct {
    20  	num    int32
    21  	objNum int16 // register number from cmd/internal/obj/$ARCH
    22  	name   string
    23  }
    24  
    25  func (r *Register) Name() string {
    26  	return r.name
    27  }
    28  
    29  // A LocalSlot is a location in the stack frame.
    30  // It is (possibly a subpiece of) a PPARAM, PPARAMOUT, or PAUTO ONAME node.
    31  type LocalSlot struct {
    32  	N    GCNode      // an ONAME *gc.Node representing a variable on the stack
    33  	Type *types.Type // type of slot
    34  	Off  int64       // offset of slot in N
    35  }
    36  
    37  func (s LocalSlot) Name() string {
    38  	if s.Off == 0 {
    39  		return fmt.Sprintf("%v[%v]", s.N, s.Type)
    40  	}
    41  	return fmt.Sprintf("%v+%d[%v]", s.N, s.Off, s.Type)
    42  }
    43  
    44  type LocPair [2]Location
    45  
    46  func (t LocPair) Name() string {
    47  	n0, n1 := "nil", "nil"
    48  	if t[0] != nil {
    49  		n0 = t[0].Name()
    50  	}
    51  	if t[1] != nil {
    52  		n1 = t[1].Name()
    53  	}
    54  	return fmt.Sprintf("<%s,%s>", n0, n1)
    55  }