1
0
mirror of https://github.com/golang/go synced 2024-11-23 15:40:06 -07:00

cmd/compile/internal/gc: change flags to bool where possible

Some of the Debug[x] flags are actually boolean too, but not all, so
they need to be handled separately.

While here, change some obj.Flagstr and obj.Flagint64 calls to
directly use flag.StringVar and flag.Int64Var instead.

Change-Id: Iccedf6fed4328240ee2257f57fe6d66688f237c4
Reviewed-on: https://go-review.googlesource.com/22052
Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
This commit is contained in:
Matthew Dempsky 2016-04-13 18:37:18 -07:00
parent ae98045958
commit 980ab12ade
19 changed files with 88 additions and 87 deletions

View File

@ -316,11 +316,12 @@ func genhash(sym *Sym, t *Type) {
// for a struct containing a reflect.Value, which itself has
// an unexported field of type unsafe.Pointer.
old_safemode := safemode
safemode = false
safemode = 0
Disable_checknil++
funccompile(fn)
Disable_checknil--
safemode = old_safemode
}
@ -509,7 +510,7 @@ func geneq(sym *Sym, t *Type) {
// for a struct containing a reflect.Value, which itself has
// an unexported field of type unsafe.Pointer.
old_safemode := safemode
safemode = 0
safemode = false
// Disable checknils while compiling this code.
// We are comparing a struct or an array,

View File

@ -261,7 +261,7 @@ func export(out *bufio.Writer, trace bool) int {
}
// write compiler-specific flags
p.bool(safemode != 0)
p.bool(safemode)
if p.trace {
p.tracef("\n")
}

View File

@ -419,7 +419,7 @@ func closuredebugruntimecheck(r *Node) {
Warnl(r.Lineno, "stack closure, captured vars = %v", r.Func.Cvars)
}
}
if compiling_runtime > 0 && r.Esc == EscHeap {
if compiling_runtime && r.Esc == EscHeap {
yyerrorl(r.Lineno, "heap-allocated closure, not allowed in runtime.")
}
}

View File

@ -1330,7 +1330,7 @@ func makefuncsym(s *Sym) {
if isblanksym(s) {
return
}
if compiling_runtime != 0 && s.Name == "getg" {
if compiling_runtime && s.Name == "getg" {
// runtime.getg() is not a real function and so does
// not get a funcsym.
return
@ -1440,7 +1440,7 @@ func (c *nowritebarrierrecChecker) visitcall(n *Node) {
if fn == nil || fn.Op != ONAME || fn.Class != PFUNC || fn.Name.Defn == nil {
return
}
if (compiling_runtime != 0 || fn.Sym.Pkg == Runtimepkg) && fn.Sym.Name == "allocm" {
if (compiling_runtime || fn.Sym.Pkg == Runtimepkg) && fn.Sym.Name == "allocm" {
return
}
defn := fn.Name.Defn

View File

@ -15,8 +15,8 @@ import (
)
var (
newexport int // if set, use new export format
Debug_export int // if set, print debugging information about export data
newexport bool // if set, use new export format
Debug_export int // if set, print debugging information about export data
exportsize int
)
@ -377,7 +377,7 @@ func dumpexport() {
}
size := 0 // size of export section without enclosing markers
if forceNewExport || newexport != 0 {
if forceNewExport || newexport {
// binary export
// The linker also looks for the $$ marker - use char after $$ to distinguish format.
exportf("\n$$B\n") // indicate binary format
@ -417,7 +417,7 @@ func dumpexport() {
exportf("\n$$\n") // indicate textual format
exportsize = 0
exportf("package %s", localpkg.Name)
if safemode != 0 {
if safemode {
exportf(" safe")
}
exportf("\n")

View File

@ -246,7 +246,7 @@ func cgen_dcl(n *Node) {
if n.Class&PHEAP == 0 {
return
}
if compiling_runtime != 0 {
if compiling_runtime {
Yyerror("%v escapes to heap, not allowed in runtime.", n)
}
if prealloc[n] == nil {

View File

@ -144,9 +144,9 @@ var nsyntaxerrors int
var decldepth int32
var safemode int
var safemode bool
var nolocalimports int
var nolocalimports bool
var Debug [256]int
@ -261,21 +261,21 @@ var Funcdepth int32
var typecheckok bool
var compiling_runtime int
var compiling_runtime bool
var compiling_wrappers int
var use_writebarrier int
var use_writebarrier bool
var pure_go int
var pure_go bool
var flag_installsuffix string
var flag_race int
var flag_race bool
var flag_msan int
var flag_msan bool
var flag_largemodel int
var flag_largemodel bool
// Whether we are adding any sort of code instrumentation, such as
// when the race detector is enabled.
@ -285,7 +285,7 @@ var debuglive int
var Ctxt *obj.Link
var writearchive int
var writearchive bool
var bstdout *bufio.Writer

View File

@ -71,7 +71,7 @@ func typecheckinl(fn *Node) {
}
save_safemode := safemode
safemode = 0
safemode = false
savefn := Curfn
Curfn = fn
@ -492,7 +492,7 @@ func mkinlcall(n *Node, fn *Node, isddd bool) *Node {
pkg := fnpkg(fn)
if pkg != localpkg && pkg != nil {
safemode = 0
safemode = false
}
n = mkinlcall1(n, fn, isddd)
safemode = save_safemode

View File

@ -914,17 +914,17 @@ func (l *lexer) getlinepragma() rune {
case "go:noinline":
l.pragma |= Noinline
case "go:systemstack":
if compiling_runtime == 0 {
if !compiling_runtime {
Yyerror("//go:systemstack only allowed in runtime")
}
l.pragma |= Systemstack
case "go:nowritebarrier":
if compiling_runtime == 0 {
if !compiling_runtime {
Yyerror("//go:nowritebarrier only allowed in runtime")
}
l.pragma |= Nowritebarrier
case "go:nowritebarrierrec":
if compiling_runtime == 0 {
if !compiling_runtime {
Yyerror("//go:nowritebarrierrec only allowed in runtime")
}
l.pragma |= Nowritebarrierrec | Nowritebarrier // implies Nowritebarrier

View File

@ -142,15 +142,14 @@ func Main() {
Nacl = goos == "nacl"
if Nacl {
flag_largemodel = 1
flag_largemodel = true
}
outfile = ""
obj.Flagcount("+", "compiling runtime", &compiling_runtime)
flag.BoolVar(&compiling_runtime, "+", false, "compiling runtime")
obj.Flagcount("%", "debug non-static initializers", &Debug['%'])
obj.Flagcount("A", "for bootstrapping, allow 'any' type", &Debug['A'])
obj.Flagcount("B", "disable bounds checking", &Debug['B'])
obj.Flagstr("D", "set relative `path` for local imports", &localimport)
flag.StringVar(&localimport, "D", "", "set relative `path` for local imports")
obj.Flagcount("E", "debug symbol export", &Debug['E'])
obj.Flagfn1("I", "add `directory` to import search path", addidir)
obj.Flagcount("K", "debug missing line numbers", &Debug['K'])
@ -162,57 +161,59 @@ func Main() {
obj.Flagcount("S", "print assembly listing", &Debug['S'])
obj.Flagfn0("V", "print compiler version", doversion)
obj.Flagcount("W", "debug parse tree after type checking", &Debug['W'])
obj.Flagstr("asmhdr", "write assembly header to `file`", &asmhdr)
obj.Flagstr("buildid", "record `id` as the build id in the export metadata", &buildid)
obj.Flagcount("complete", "compiling complete package (no C or assembly)", &pure_go)
obj.Flagstr("d", "print debug information about items in `list`", &debugstr)
flag.StringVar(&asmhdr, "asmhdr", "", "write assembly header to `file`")
flag.StringVar(&buildid, "buildid", "", "record `id` as the build id in the export metadata")
flag.BoolVar(&pure_go, "complete", false, "compiling complete package (no C or assembly)")
flag.StringVar(&debugstr, "d", "", "print debug information about items in `list`")
obj.Flagcount("e", "no limit on number of errors reported", &Debug['e'])
obj.Flagcount("f", "debug stack frames", &Debug['f'])
obj.Flagcount("g", "debug code generation", &Debug['g'])
obj.Flagcount("h", "halt on error", &Debug['h'])
obj.Flagcount("i", "debug line number stack", &Debug['i'])
obj.Flagfn1("importmap", "add `definition` of the form source=actual to import map", addImportMap)
obj.Flagstr("installsuffix", "set pkg directory `suffix`", &flag_installsuffix)
flag.StringVar(&flag_installsuffix, "installsuffix", "", "set pkg directory `suffix`")
obj.Flagcount("j", "debug runtime-initialized variables", &Debug['j'])
obj.Flagcount("l", "disable inlining", &Debug['l'])
obj.Flagcount("live", "debug liveness analysis", &debuglive)
obj.Flagcount("m", "print optimization decisions", &Debug['m'])
obj.Flagcount("msan", "build code compatible with C/C++ memory sanitizer", &flag_msan)
obj.Flagcount("newexport", "use new export format", &newexport) // TODO(gri) remove eventually (issue 13241)
obj.Flagcount("nolocalimports", "reject local (relative) imports", &nolocalimports)
obj.Flagstr("o", "write output to `file`", &outfile)
obj.Flagstr("p", "set expected package import `path`", &myimportpath)
obj.Flagcount("pack", "write package file instead of object file", &writearchive)
flag.BoolVar(&flag_msan, "msan", false, "build code compatible with C/C++ memory sanitizer")
flag.BoolVar(&newexport, "newexport", false, "use new export format") // TODO(gri) remove eventually (issue 13241)
flag.BoolVar(&nolocalimports, "nolocalimports", false, "reject local (relative) imports")
flag.StringVar(&outfile, "o", "", "write output to `file`")
flag.StringVar(&myimportpath, "p", "", "set expected package import `path`")
flag.BoolVar(&writearchive, "pack", false, "write package file instead of object file")
obj.Flagcount("r", "debug generated wrappers", &Debug['r'])
obj.Flagcount("race", "enable race detector", &flag_race)
flag.BoolVar(&flag_race, "race", false, "enable race detector")
obj.Flagcount("s", "warn about composite literals that can be simplified", &Debug['s'])
obj.Flagstr("trimpath", "remove `prefix` from recorded source file paths", &Ctxt.LineHist.TrimPathPrefix)
obj.Flagcount("u", "reject unsafe code", &safemode)
flag.StringVar(&Ctxt.LineHist.TrimPathPrefix, "trimpath", "", "remove `prefix` from recorded source file paths")
flag.BoolVar(&safemode, "u", false, "reject unsafe code")
obj.Flagcount("v", "increase debug verbosity", &Debug['v'])
obj.Flagcount("w", "debug type checking", &Debug['w'])
use_writebarrier = 1
obj.Flagcount("wb", "enable write barrier", &use_writebarrier)
flag.BoolVar(&use_writebarrier, "wb", true, "enable write barrier")
obj.Flagcount("x", "debug lexer", &Debug['x'])
obj.Flagcount("y", "debug declarations in canned imports (with -d)", &Debug['y'])
var flag_shared int
var flag_shared bool
var flag_dynlink bool
if supportsDynlink(Thearch.LinkArch.Arch) {
obj.Flagcount("shared", "generate code that can be linked into a shared library", &flag_shared)
flag.BoolVar(&flag_shared, "shared", false, "generate code that can be linked into a shared library")
flag.BoolVar(&flag_dynlink, "dynlink", false, "support references to Go symbols defined in other shared libraries")
}
if Thearch.LinkArch.Family == sys.AMD64 {
obj.Flagcount("largemodel", "generate code that assumes a large memory model", &flag_largemodel)
flag.BoolVar(&flag_largemodel, "largemodel", false, "generate code that assumes a large memory model")
}
obj.Flagstr("cpuprofile", "write cpu profile to `file`", &cpuprofile)
obj.Flagstr("memprofile", "write memory profile to `file`", &memprofile)
obj.Flagint64("memprofilerate", "set runtime.MemProfileRate to `rate`", &memprofilerate)
flag.StringVar(&cpuprofile, "cpuprofile", "", "write cpu profile to `file`")
flag.StringVar(&memprofile, "memprofile", "", "write memory profile to `file`")
flag.Int64Var(&memprofilerate, "memprofilerate", 0, "set runtime.MemProfileRate to `rate`")
flag.BoolVar(&ssaEnabled, "ssa", true, "use SSA backend to generate code")
obj.Flagparse(usage)
if flag_dynlink {
flag_shared = 1
flag_shared = true
}
if flag_shared {
// TODO(mdempsky): Change Flag_shared to bool.
Ctxt.Flag_shared = 1
}
Ctxt.Flag_shared = int32(flag_shared)
Ctxt.Flag_dynlink = flag_dynlink
Ctxt.Flag_optimize = Debug['N'] == 0
@ -225,17 +226,17 @@ func Main() {
startProfile()
if flag_race != 0 {
if flag_race {
racepkg = mkpkg("runtime/race")
racepkg.Name = "race"
}
if flag_msan != 0 {
if flag_msan {
msanpkg = mkpkg("runtime/msan")
msanpkg.Name = "msan"
}
if flag_race != 0 && flag_msan != 0 {
if flag_race && flag_msan {
log.Fatal("cannot use both -race and -msan")
} else if flag_race != 0 || flag_msan != 0 {
} else if flag_race || flag_msan {
instrumenting = true
}
@ -471,7 +472,7 @@ func Main() {
fninit(xtop)
}
if compiling_runtime != 0 {
if compiling_runtime {
checknowritebarrierrec()
}
@ -569,7 +570,7 @@ func islocalname(name string) bool {
func findpkg(name string) (file string, ok bool) {
if islocalname(name) {
if safemode != 0 || nolocalimports != 0 {
if safemode || nolocalimports {
return "", false
}
@ -612,10 +613,10 @@ func findpkg(name string) (file string, ok bool) {
if flag_installsuffix != "" {
suffixsep = "_"
suffix = flag_installsuffix
} else if flag_race != 0 {
} else if flag_race {
suffixsep = "_"
suffix = "race"
} else if flag_msan != 0 {
} else if flag_msan {
suffixsep = "_"
suffix = "msan"
}
@ -694,7 +695,7 @@ func importfile(f *Val, indent []byte) {
}
if path_ == "unsafe" {
if safemode != 0 {
if safemode {
Yyerror("cannot import package unsafe")
errorexit()
}
@ -818,7 +819,7 @@ func importfile(f *Val, indent []byte) {
errorexit()
}
if safemode != 0 && !importpkg.Safe {
if safemode && !importpkg.Safe {
Yyerror("cannot import unsafe package %q", importpkg.Path)
}
}
@ -896,7 +897,7 @@ func mkpackage(pkgname string) {
p = p[:i]
}
suffix := ".o"
if writearchive > 0 {
if writearchive {
suffix = ".a"
}
outfile = p + suffix

View File

@ -33,7 +33,7 @@ func dumpobj() {
startobj := int64(0)
var arhdr [ArhdrSize]byte
if writearchive != 0 {
if writearchive {
bout.WriteString("!<arch>\n")
arhdr = [ArhdrSize]byte{}
bout.Write(arhdr[:])
@ -43,7 +43,7 @@ func dumpobj() {
fmt.Fprintf(bout, "go object %s %s %s %s\n", obj.Getgoos(), obj.Getgoarch(), obj.Getgoversion(), obj.Expstring())
dumpexport()
if writearchive != 0 {
if writearchive {
bout.Flush()
size := bout.Offset() - startobj
if size&1 != 0 {
@ -62,7 +62,7 @@ func dumpobj() {
}
if pragcgobuf != "" {
if writearchive != 0 {
if writearchive {
// write empty export section; must be before cgo section
fmt.Fprintf(bout, "\n$$\n\n$$\n\n")
}
@ -90,7 +90,7 @@ func dumpobj() {
dumpdata()
obj.Writeobjdirect(Ctxt, bout)
if writearchive != 0 {
if writearchive {
bout.Flush()
size := bout.Offset() - startobj
if size&1 != 0 {

View File

@ -364,7 +364,7 @@ func compile(fn *Node) {
dowidth(Curfn.Type)
if len(fn.Nbody.Slice()) == 0 {
if pure_go != 0 || strings.HasPrefix(fn.Func.Nname.Sym.Name, "init.") {
if pure_go || strings.HasPrefix(fn.Func.Nname.Sym.Name, "init.") {
Yyerror("missing function body for %q", fn.Func.Nname.Sym.Name)
return
}

View File

@ -54,14 +54,14 @@ func instrument(fn *Node) {
return
}
if flag_race == 0 || !ispkgin(norace_inst_pkgs) {
if !flag_race || !ispkgin(norace_inst_pkgs) {
instrumentlist(fn.Nbody, nil)
// nothing interesting for race detector in fn->enter
instrumentlist(fn.Func.Exit, nil)
}
if flag_race != 0 {
if flag_race {
// nodpc is the PC of the caller as extracted by
// getcallerpc. We use -widthptr(FP) for x86.
// BUG: this will not work on arm.
@ -503,7 +503,7 @@ func callinstr(np **Node, init *Nodes, wr int, skip int) bool {
n = treecopy(n, 0)
makeaddable(n)
var f *Node
if flag_msan != 0 {
if flag_msan {
name := "msanread"
if wr != 0 {
name = "msanwrite"
@ -515,7 +515,7 @@ func callinstr(np **Node, init *Nodes, wr int, skip int) bool {
Fatalf("instrument: %v badwidth", t)
}
f = mkcall(name, nil, init, uintptraddr(n), Nodintconst(w))
} else if flag_race != 0 && (t.IsStruct() || t.IsArray()) {
} else if flag_race && (t.IsStruct() || t.IsArray()) {
name := "racereadrange"
if wr != 0 {
name = "racewriterange"
@ -527,7 +527,7 @@ func callinstr(np **Node, init *Nodes, wr int, skip int) bool {
Fatalf("instrument: %v badwidth", t)
}
f = mkcall(name, nil, init, uintptraddr(n), Nodintconst(w))
} else if flag_race != 0 {
} else if flag_race {
name := "raceread"
if wr != 0 {
name = "racewrite"

View File

@ -1424,10 +1424,10 @@ func dumptypestructs() {
// add paths for runtime and main, which 6l imports implicitly.
dimportpath(Runtimepkg)
if flag_race != 0 {
if flag_race {
dimportpath(racepkg)
}
if flag_msan != 0 {
if flag_msan {
dimportpath(msanpkg)
}
dimportpath(mkpkg("main"))

View File

@ -554,7 +554,7 @@ func (s *state) stmt(n *Node) {
case OCALLFUNC, OCALLMETH, OCALLINTER:
s.call(n, callNormal)
if n.Op == OCALLFUNC && n.Left.Op == ONAME && n.Left.Class == PFUNC &&
(compiling_runtime != 0 && n.Left.Sym.Name == "throw" ||
(compiling_runtime && n.Left.Sym.Name == "throw" ||
n.Left.Sym.Pkg == Runtimepkg && (n.Left.Sym.Name == "gopanic" || n.Left.Sym.Name == "selectgo" || n.Left.Sym.Name == "block")) {
m := s.mem()
b := s.endBlock()
@ -579,7 +579,7 @@ func (s *state) stmt(n *Node) {
if n.Left.Class&PHEAP == 0 {
return
}
if compiling_runtime != 0 {
if compiling_runtime {
Fatalf("%v escapes to heap, not allowed in runtime.", n)
}

View File

@ -750,7 +750,7 @@ func assignop(src *Type, dst *Type, why *string) Op {
// TODO(rsc,lvd): This behaves poorly in the presence of inlining.
// https://golang.org/issue/2795
if safemode != 0 && importpkg == nil && src != nil && src.Etype == TUNSAFEPTR {
if safemode && importpkg == nil && src != nil && src.Etype == TUNSAFEPTR {
Yyerror("cannot use unsafe.Pointer")
errorexit()
}

View File

@ -1354,7 +1354,7 @@ OpSwitch:
if t.Results().NumFields() == 1 {
n.Type = l.Type.Results().Field(0).Type
if n.Op == OCALLFUNC && n.Left.Op == ONAME && (compiling_runtime != 0 || n.Left.Sym.Pkg == Runtimepkg) && n.Left.Sym.Name == "getg" {
if n.Op == OCALLFUNC && n.Left.Op == ONAME && (compiling_runtime || n.Left.Sym.Pkg == Runtimepkg) && n.Left.Sym.Name == "getg" {
// Emit code for runtime.getg() directly instead of calling function.
// Most such rewrites (for example the similar one for math.Sqrt) should be done in walk,
// so that the ordering pass can make sure to preserve the semantics of the original code
@ -2176,7 +2176,7 @@ OpSwitch:
}
}
if safemode != 0 && incannedimport == 0 && importpkg == nil && compiling_wrappers == 0 && t != nil && t.Etype == TUNSAFEPTR {
if safemode && incannedimport == 0 && importpkg == nil && compiling_wrappers == 0 && t != nil && t.Etype == TUNSAFEPTR {
Yyerror("cannot use unsafe.Pointer")
}

View File

@ -9,7 +9,7 @@ func unsafenmagic(nn *Node) *Node {
fn := nn.Left
args := nn.List
if safemode != 0 || fn == nil || fn.Op != ONAME {
if safemode || fn == nil || fn.Op != ONAME {
return nil
}
s := fn.Sym

View File

@ -594,8 +594,7 @@ opswitch:
// for a struct containing a reflect.Value, which itself has
// an unexported field of type unsafe.Pointer.
old_safemode := safemode
safemode = 0
safemode = false
n = walkcompare(n, init)
safemode = old_safemode
@ -1938,7 +1937,7 @@ func walkprint(nn *Node, init *Nodes) *Node {
on = substArgTypes(on, n.Type) // any-1
} else if Isint[et] {
if et == TUINT64 {
if (t.Sym.Pkg == Runtimepkg || compiling_runtime != 0) && t.Sym.Name == "hex" {
if (t.Sym.Pkg == Runtimepkg || compiling_runtime) && t.Sym.Name == "hex" {
on = syslook("printhex")
} else {
on = syslook("printuint")
@ -2041,7 +2040,7 @@ func isglobal(n *Node) bool {
// Do we need a write barrier for the assignment l = r?
func needwritebarrier(l *Node, r *Node) bool {
if use_writebarrier == 0 {
if !use_writebarrier {
return false
}
@ -2550,7 +2549,7 @@ func paramstoheap(params *Type, out bool) []*Node {
}
// generate allocation & copying code
if compiling_runtime != 0 {
if compiling_runtime {
Yyerror("%v escapes to heap, not allowed in runtime.", v)
}
if prealloc[v] == nil {