Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / honnef.co / go / tools@v0.0.1-2020.1.5 / ir / mode.go
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.
4
5 package ir
6
7 // This file defines the BuilderMode type and its command-line flag.
8
9 import (
10         "bytes"
11         "fmt"
12 )
13
14 // BuilderMode is a bitmask of options for diagnostics and checking.
15 //
16 // *BuilderMode satisfies the flag.Value interface.  Example:
17 //
18 //      var mode = ir.BuilderMode(0)
19 //      func init() { flag.Var(&mode, "build", ir.BuilderModeDoc) }
20 //
21 type BuilderMode uint
22
23 const (
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
31 )
32
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.
42 `
43
44 func (m BuilderMode) String() string {
45         var buf bytes.Buffer
46         if m&GlobalDebug != 0 {
47                 buf.WriteByte('D')
48         }
49         if m&PrintPackages != 0 {
50                 buf.WriteByte('P')
51         }
52         if m&PrintFunctions != 0 {
53                 buf.WriteByte('F')
54         }
55         if m&PrintSource != 0 {
56                 buf.WriteByte('A')
57         }
58         if m&LogSource != 0 {
59                 buf.WriteByte('S')
60         }
61         if m&SanityCheckFunctions != 0 {
62                 buf.WriteByte('C')
63         }
64         if m&NaiveForm != 0 {
65                 buf.WriteByte('N')
66         }
67         return buf.String()
68 }
69
70 // Set parses the flag characters in s and updates *m.
71 func (m *BuilderMode) Set(s string) error {
72         var mode BuilderMode
73         for _, c := range s {
74                 switch c {
75                 case 'D':
76                         mode |= GlobalDebug
77                 case 'P':
78                         mode |= PrintPackages
79                 case 'F':
80                         mode |= PrintFunctions
81                 case 'A':
82                         mode |= PrintSource
83                 case 'S':
84                         mode |= LogSource
85                 case 'C':
86                         mode |= SanityCheckFunctions
87                 case 'N':
88                         mode |= NaiveForm
89                 default:
90                         return fmt.Errorf("unknown BuilderMode option: %q", c)
91                 }
92         }
93         *m = mode
94         return nil
95 }
96
97 // Get returns m.
98 func (m BuilderMode) Get() interface{} { return m }