options.go raw
1 package compileopts
2
3 import (
4 "fmt"
5 "regexp"
6 "strings"
7 "time"
8 )
9
10 var (
11 validBuildModeOptions = []string{"default", "c-shared"}
12 validSchedulerOptions = []string{"none", "tasks"}
13 validPanicStrategyOptions = []string{"print", "trap"}
14 validOptOptions = []string{"none", "0", "1", "2", "s", "z"}
15 )
16
17 // Options contains extra options to give to the compiler.
18 type Options struct {
19 GOOS string
20 GOARCH string
21 Directory string // working dir
22 Target string
23 BuildMode string
24 Opt string
25 PanicStrategy string
26 Scheduler string
27 StackSize uint64
28 Work bool
29 InterpTimeout time.Duration
30 PrintIR bool
31 DumpSSA bool
32 VerifyIR bool
33 SkipDWARF bool
34 PrintCommands func(cmd string, args ...string) `json:"-"`
35 Semaphore chan struct{} `json:"-"`
36 Debug bool
37 Nobounds bool
38 PrintSizes string
39 PrintAllocs *regexp.Regexp
40 PrintStacks bool
41 Tags []string
42 GlobalValues map[string]map[string]string
43 TestConfig TestConfig
44 LLVMFeatures string
45 ExtLDFlags []string
46 StandaloneRuntime bool // skip internalization, keep runtime symbols external
47 }
48
49 // Verify performs validation on the given options.
50 func (o *Options) Verify() error {
51 if o.BuildMode != "" && !isInArray(validBuildModeOptions, o.BuildMode) {
52 return fmt.Errorf(`invalid buildmode option '%s': valid values are %s`,
53 o.BuildMode, strings.Join(validBuildModeOptions, ", "))
54 }
55 if o.Scheduler != "" && !isInArray(validSchedulerOptions, o.Scheduler) {
56 return fmt.Errorf(`invalid scheduler option '%s': valid values are %s`,
57 o.Scheduler, strings.Join(validSchedulerOptions, ", "))
58 }
59 if o.PanicStrategy != "" && !isInArray(validPanicStrategyOptions, o.PanicStrategy) {
60 return fmt.Errorf(`invalid panic option '%s': valid values are %s`,
61 o.PanicStrategy, strings.Join(validPanicStrategyOptions, ", "))
62 }
63 if o.Opt != "" && !isInArray(validOptOptions, o.Opt) {
64 return fmt.Errorf("invalid -opt=%s: valid values are %s",
65 o.Opt, strings.Join(validOptOptions, ", "))
66 }
67 return nil
68 }
69
70 func isInArray(arr []string, item string) bool {
71 for _, i := range arr {
72 if i == item {
73 return true
74 }
75 }
76 return false
77 }
78