aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2017-02-22 16:13:06 -0500
committerAustin Clements <austin@google.com>2017-03-03 15:50:49 +0000
commit8eb14e9de5018afbcf7eefd7b4bce7a200d0ce3f (patch)
tree04e8d953a11fa7f7735c0674f37980ec60dd6f03 /src
parent5bfd1ef036f2cd549f78a0acd3e2666b42bcc07d (diff)
downloadgo-8eb14e9de5018afbcf7eefd7b4bce7a200d0ce3f.tar.xz
cmd/compile: accept string debug flags
The compiler's -d flag accepts string-valued flags, but currently only for SSA debug flags. Extend it to support string values for other flags. This also makes the syntax somewhat more sane so flag=value and flag:value now both accept integers and strings. Change-Id: Idd144d8479a430970cc1688f824bffe0a56ed2df Reviewed-on: https://go-review.googlesource.com/37345 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/gc/main.go40
-rw-r--r--src/cmd/compile/internal/ssa/compile.go2
2 files changed, 25 insertions, 17 deletions
diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go
index b9350d33e0..7eecde4c37 100644
--- a/src/cmd/compile/internal/gc/main.go
+++ b/src/cmd/compile/internal/gc/main.go
@@ -41,11 +41,12 @@ var (
// Debug arguments.
// These can be specified with the -d flag, as in "-d nil"
-// to set the debug_checknil variable. In general the list passed
-// to -d can be comma-separated.
+// to set the debug_checknil variable.
+// Multiple options can be comma-separated.
+// Each option accepts an optional argument, as in "gcprog=2"
var debugtab = []struct {
name string
- val *int
+ val interface{} // must be *int or *string
}{
{"append", &Debug_append}, // print information about append compilation
{"closure", &Debug_closure}, // print information about closure compilation
@@ -269,26 +270,33 @@ func Main() {
if name == "" {
continue
}
- val := 1
- valstring := ""
- if i := strings.Index(name, "="); i >= 0 {
+ val, valstring, haveInt := 1, "", true
+ if i := strings.IndexAny(name, "=:"); i >= 0 {
var err error
- val, err = strconv.Atoi(name[i+1:])
+ name, valstring = name[:i], name[i+1:]
+ val, err = strconv.Atoi(valstring)
if err != nil {
- log.Fatalf("invalid debug value %v", name)
+ val, haveInt = 1, false
}
- name = name[:i]
- } else if i := strings.Index(name, ":"); i >= 0 {
- valstring = name[i+1:]
- name = name[:i]
}
for _, t := range debugtab {
- if t.name == name {
- if t.val != nil {
- *t.val = val
- continue Split
+ if t.name != name {
+ continue
+ }
+ switch vp := t.val.(type) {
+ case nil:
+ // Ignore
+ case *string:
+ *vp = valstring
+ case *int:
+ if !haveInt {
+ log.Fatalf("invalid debug value %v", name)
}
+ *vp = val
+ default:
+ panic("bad debugtab type")
}
+ continue Split
}
// special case for ssa for now
if strings.HasPrefix(name, "ssa/") {
diff --git a/src/cmd/compile/internal/ssa/compile.go b/src/cmd/compile/internal/ssa/compile.go
index 975845f258..c03436cdf0 100644
--- a/src/cmd/compile/internal/ssa/compile.go
+++ b/src/cmd/compile/internal/ssa/compile.go
@@ -204,7 +204,7 @@ func PhaseOption(phase, flag string, val int, valString string) string {
}
}
return "" +
- `GcFlag -d=ssa/<phase>/<flag>[=<value>]|[:<function_name>]
+ `GcFlag -d=ssa/<phase>/<flag>[=<value>|<function_name>]
<phase> is one of:
` + phasenames + `
<flag> is one of on, off, debug, mem, time, test, stats, dump