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