From 24fa159a2e5cba1c0038af7ae55802eb58fcb591 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Mon, 6 Jan 2020 13:43:51 -0800 Subject: [PATCH] cmd/compile: add a flag to print the source line for generated rules When working on rulegen, I often find myself searching the rules files to find the source of generated code. Add a flag to make that easier. The flag needs to be off by default, so that adding a single rule doesn't cause a massive diff. Change-Id: I5a6f09129dc6fceef7c9cd1ad7eee24f3880ba91 Reviewed-on: https://go-review.googlesource.com/c/go/+/213700 Run-TryBot: Josh Bleecher Snyder Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/gen/rulegen.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/ssa/gen/rulegen.go b/src/cmd/compile/internal/ssa/gen/rulegen.go index d5ad96c890cc29..fa0b7c8a6b7be6 100644 --- a/src/cmd/compile/internal/ssa/gen/rulegen.go +++ b/src/cmd/compile/internal/ssa/gen/rulegen.go @@ -54,7 +54,10 @@ import ( // If multiple rules match, the first one in file order is selected. -var genLog = flag.Bool("log", false, "generate code that logs; for debugging only") +var ( + genLog = flag.Bool("log", false, "generate code that logs; for debugging only") + addLine = flag.Bool("line", false, "add line number comment to generated rules; for debugging only") +) type Rule struct { rule string @@ -598,6 +601,9 @@ func fprint(w io.Writer, n Node) { fprint(w, n) } case *RuleRewrite: + if *addLine { + fmt.Fprintf(w, "// %s\n", n.loc) + } fmt.Fprintf(w, "// match: %s\n", n.match) if n.cond != "" { fmt.Fprintf(w, "// cond: %s\n", n.cond)