vikunja-api/vendor/honnef.co/go/tools/ir/mode.go

99 lines
2.6 KiB
Go
Raw Normal View History

2018-12-28 23:15:05 +01:00
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
2020-05-29 22:15:21 +02:00
package ir
2018-12-28 23:15:05 +01:00
// This file defines the BuilderMode type and its command-line flag.
import (
"bytes"
"fmt"
)
// BuilderMode is a bitmask of options for diagnostics and checking.
//
// *BuilderMode satisfies the flag.Value interface. Example:
//
2020-05-29 22:15:21 +02:00
// var mode = ir.BuilderMode(0)
// func init() { flag.Var(&mode, "build", ir.BuilderModeDoc) }
2018-12-28 23:15:05 +01:00
//
type BuilderMode uint
const (
PrintPackages BuilderMode = 1 << iota // Print package inventory to stdout
2020-05-29 22:15:21 +02:00
PrintFunctions // Print function IR code to stdout
PrintSource // Print source code when printing function IR
LogSource // Log source locations as IR builder progresses
2018-12-28 23:15:05 +01:00
SanityCheckFunctions // Perform sanity checking of function bodies
2020-05-29 22:15:21 +02:00
NaiveForm // Build naïve IR form: don't replace local loads/stores with registers
2018-12-28 23:15:05 +01:00
GlobalDebug // Enable debug info for all packages
)
2020-05-29 22:15:21 +02:00
const BuilderModeDoc = `Options controlling the IR builder.
2018-12-28 23:15:05 +01:00
The value is a sequence of zero or more of these letters:
2020-05-29 22:15:21 +02:00
C perform sanity [C]hecking of the IR form.
2018-12-28 23:15:05 +01:00
D include [D]ebug info for every function.
P print [P]ackage inventory.
2020-05-29 22:15:21 +02:00
F print [F]unction IR code.
A print [A]ST nodes responsible for IR instructions
S log [S]ource locations as IR builder progresses.
N build [N]aive IR form: don't replace local loads/stores with registers.
2018-12-28 23:15:05 +01:00
`
func (m BuilderMode) String() string {
var buf bytes.Buffer
if m&GlobalDebug != 0 {
buf.WriteByte('D')
}
if m&PrintPackages != 0 {
buf.WriteByte('P')
}
if m&PrintFunctions != 0 {
buf.WriteByte('F')
}
2020-05-29 22:15:21 +02:00
if m&PrintSource != 0 {
buf.WriteByte('A')
}
2018-12-28 23:15:05 +01:00
if m&LogSource != 0 {
buf.WriteByte('S')
}
if m&SanityCheckFunctions != 0 {
buf.WriteByte('C')
}
if m&NaiveForm != 0 {
buf.WriteByte('N')
}
return buf.String()
}
// Set parses the flag characters in s and updates *m.
func (m *BuilderMode) Set(s string) error {
var mode BuilderMode
for _, c := range s {
switch c {
case 'D':
mode |= GlobalDebug
case 'P':
mode |= PrintPackages
case 'F':
mode |= PrintFunctions
2020-05-29 22:15:21 +02:00
case 'A':
mode |= PrintSource
2018-12-28 23:15:05 +01:00
case 'S':
2020-05-29 22:15:21 +02:00
mode |= LogSource
2018-12-28 23:15:05 +01:00
case 'C':
mode |= SanityCheckFunctions
case 'N':
mode |= NaiveForm
default:
return fmt.Errorf("unknown BuilderMode option: %q", c)
}
}
*m = mode
return nil
}
// Get returns m.
func (m BuilderMode) Get() interface{} { return m }