github.com/euank/go@v0.0.0-20160829210321-495514729181/src/cmd/internal/obj/go.go (about)

     1  // Copyright 2009 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 obj
     6  
     7  import (
     8  	"fmt"
     9  	"os"
    10  	"strings"
    11  )
    12  
    13  // go-specific code shared across loaders (5l, 6l, 8l).
    14  
    15  var (
    16  	framepointer_enabled int
    17  	Fieldtrack_enabled   int
    18  )
    19  
    20  // Toolchain experiments.
    21  // These are controlled by the GOEXPERIMENT environment
    22  // variable recorded when the toolchain is built.
    23  // This list is also known to cmd/gc.
    24  var exper = []struct {
    25  	name string
    26  	val  *int
    27  }{
    28  	{"fieldtrack", &Fieldtrack_enabled},
    29  	{"framepointer", &framepointer_enabled},
    30  }
    31  
    32  func addexp(s string) {
    33  	// Could do general integer parsing here, but the runtime copy doesn't yet.
    34  	v := 1
    35  	name := s
    36  	if len(name) > 2 && name[:2] == "no" {
    37  		v = 0
    38  		name = name[2:]
    39  	}
    40  	for i := 0; i < len(exper); i++ {
    41  		if exper[i].name == name {
    42  			if exper[i].val != nil {
    43  				*exper[i].val = v
    44  			}
    45  			return
    46  		}
    47  	}
    48  
    49  	fmt.Printf("unknown experiment %s\n", s)
    50  	os.Exit(2)
    51  }
    52  
    53  func init() {
    54  	framepointer_enabled = 1 // default
    55  	for _, f := range strings.Split(goexperiment, ",") {
    56  		if f != "" {
    57  			addexp(f)
    58  		}
    59  	}
    60  }
    61  
    62  func Framepointer_enabled(goos, goarch string) bool {
    63  	return framepointer_enabled != 0 && goarch == "amd64" && goos != "nacl"
    64  }
    65  
    66  func Nopout(p *Prog) {
    67  	p.As = ANOP
    68  	p.Scond = 0
    69  	p.From = Addr{}
    70  	p.From3 = nil
    71  	p.Reg = 0
    72  	p.To = Addr{}
    73  }
    74  
    75  func Expstring() string {
    76  	buf := "X"
    77  	for i := range exper {
    78  		if *exper[i].val != 0 {
    79  			buf += "," + exper[i].name
    80  		}
    81  	}
    82  	if buf == "X" {
    83  		buf += ",none"
    84  	}
    85  	return "X:" + buf[2:]
    86  }