...
1
2
3
4
5 package ssa
6
7
8
9 import (
10 "bytes"
11 "fmt"
12 )
13
14
15
16
17
18
19
20 type BuilderMode uint
21
22 const (
23 PrintPackages BuilderMode = 1 << iota
24 PrintFunctions
25 LogSource
26 SanityCheckFunctions
27 NaiveForm
28 BuildSerially
29 GlobalDebug
30 BareInits
31 InstantiateGenerics
32 )
33
34 const BuilderModeDoc = `Options controlling the SSA builder.
35 The value is a sequence of zero or more of these letters:
36 C perform sanity [C]hecking of the SSA form.
37 D include [D]ebug info for every function.
38 P print [P]ackage inventory.
39 F print [F]unction SSA code.
40 S log [S]ource locations as SSA builder progresses.
41 L build distinct packages seria[L]ly instead of in parallel.
42 N build [N]aive SSA form: don't replace local loads/stores with registers.
43 I build bare [I]nit functions: no init guards or calls to dependent inits.
44 G instantiate [G]eneric function bodies via monomorphization
45 `
46
47 func (m BuilderMode) String() string {
48 var buf bytes.Buffer
49 if m&GlobalDebug != 0 {
50 buf.WriteByte('D')
51 }
52 if m&PrintPackages != 0 {
53 buf.WriteByte('P')
54 }
55 if m&PrintFunctions != 0 {
56 buf.WriteByte('F')
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 if m&BuildSerially != 0 {
68 buf.WriteByte('L')
69 }
70 if m&BareInits != 0 {
71 buf.WriteByte('I')
72 }
73 if m&InstantiateGenerics != 0 {
74 buf.WriteByte('G')
75 }
76 return buf.String()
77 }
78
79
80 func (m *BuilderMode) Set(s string) error {
81 var mode BuilderMode
82 for _, c := range s {
83 switch c {
84 case 'D':
85 mode |= GlobalDebug
86 case 'P':
87 mode |= PrintPackages
88 case 'F':
89 mode |= PrintFunctions
90 case 'S':
91 mode |= LogSource | BuildSerially
92 case 'C':
93 mode |= SanityCheckFunctions
94 case 'N':
95 mode |= NaiveForm
96 case 'L':
97 mode |= BuildSerially
98 case 'I':
99 mode |= BareInits
100 case 'G':
101 mode |= InstantiateGenerics
102 default:
103 return fmt.Errorf("unknown BuilderMode option: %q", c)
104 }
105 }
106 *m = mode
107 return nil
108 }
109
110
111 func (m BuilderMode) Get() interface{} { return m }
112
View as plain text