1 // Copyright 2015 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.
7 // This file defines the BuilderMode type and its command-line flag.
14 // BuilderMode is a bitmask of options for diagnostics and checking.
16 // *BuilderMode satisfies the flag.Value interface. Example:
18 // var mode = ir.BuilderMode(0)
19 // func init() { flag.Var(&mode, "build", ir.BuilderModeDoc) }
24 PrintPackages BuilderMode = 1 << iota // Print package inventory to stdout
25 PrintFunctions // Print function IR code to stdout
26 PrintSource // Print source code when printing function IR
27 LogSource // Log source locations as IR builder progresses
28 SanityCheckFunctions // Perform sanity checking of function bodies
29 NaiveForm // Build naïve IR form: don't replace local loads/stores with registers
30 GlobalDebug // Enable debug info for all packages
33 const BuilderModeDoc = `Options controlling the IR builder.
34 The value is a sequence of zero or more of these letters:
35 C perform sanity [C]hecking of the IR form.
36 D include [D]ebug info for every function.
37 P print [P]ackage inventory.
38 F print [F]unction IR code.
39 A print [A]ST nodes responsible for IR instructions
40 S log [S]ource locations as IR builder progresses.
41 N build [N]aive IR form: don't replace local loads/stores with registers.
44 func (m BuilderMode) String() string {
46 if m&GlobalDebug != 0 {
49 if m&PrintPackages != 0 {
52 if m&PrintFunctions != 0 {
55 if m&PrintSource != 0 {
61 if m&SanityCheckFunctions != 0 {
70 // Set parses the flag characters in s and updates *m.
71 func (m *BuilderMode) Set(s string) error {
80 mode |= PrintFunctions
86 mode |= SanityCheckFunctions
90 return fmt.Errorf("unknown BuilderMode option: %q", c)
98 func (m BuilderMode) Get() interface{} { return m }