github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/base/flag.go (about) 1 // Copyright 2009 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 base 6 7 import ( 8 "github.com/shogo82148/std/cmd/internal/cov/covcmd" 9 "github.com/shogo82148/std/flag" 10 ) 11 12 // Flag holds the parsed command-line flags. 13 // See ParseFlag for non-zero defaults. 14 var Flag CmdFlags 15 16 // A CountFlag is a counting integer flag. 17 // It accepts -name=value to set the value directly, 18 // but it also accepts -name with no =value to increment the count. 19 type CountFlag int 20 21 // CmdFlags defines the command-line flags (see var Flag). 22 // Each struct field is a different flag, by default named for the lower-case of the field name. 23 // If the flag name is a single letter, the default flag name is left upper-case. 24 // If the flag name is "Lower" followed by a single letter, the default flag name is the lower-case of the last letter. 25 // 26 // If this default flag name can't be made right, the `flag` struct tag can be used to replace it, 27 // but this should be done only in exceptional circumstances: it helps everyone if the flag name 28 // is obvious from the field name when the flag is used elsewhere in the compiler sources. 29 // The `flag:"-"` struct tag makes a field invisible to the flag logic and should also be used sparingly. 30 // 31 // Each field must have a `help` struct tag giving the flag help message. 32 // 33 // The allowed field types are bool, int, string, pointers to those (for values stored elsewhere), 34 // CountFlag (for a counting flag), and func(string) (for a flag that uses special code for parsing). 35 type CmdFlags struct { 36 // Single letters 37 B CountFlag "help:\"disable bounds checking\"" 38 C CountFlag "help:\"disable printing of columns in error messages\"" 39 D string "help:\"set relative `path` for local imports\"" 40 E CountFlag "help:\"debug symbol export\"" 41 I func(string) "help:\"add `directory` to import search path\"" 42 K CountFlag "help:\"debug missing line numbers\"" 43 L CountFlag "help:\"also show actual source file names in error messages for positions affected by //line directives\"" 44 N CountFlag "help:\"disable optimizations\"" 45 S CountFlag "help:\"print assembly listing\"" 46 // V is added by objabi.AddVersionFlag 47 W CountFlag "help:\"debug parse tree after type checking\"" 48 49 LowerC int "help:\"concurrency during compilation (1 means no concurrency)\"" 50 LowerD flag.Value "help:\"enable debugging settings; try -d help\"" 51 LowerE CountFlag "help:\"no limit on number of errors reported\"" 52 LowerH CountFlag "help:\"halt on error\"" 53 LowerJ CountFlag "help:\"debug runtime-initialized variables\"" 54 LowerL CountFlag "help:\"disable inlining\"" 55 LowerM CountFlag "help:\"print optimization decisions\"" 56 LowerO string "help:\"write output to `file`\"" 57 LowerP *string "help:\"set expected package import `path`\"" 58 LowerR CountFlag "help:\"debug generated wrappers\"" 59 LowerT bool "help:\"enable tracing for debugging the compiler\"" 60 LowerW CountFlag "help:\"debug type checking\"" 61 LowerV *bool "help:\"increase debug verbosity\"" 62 63 // Special characters 64 Percent CountFlag "flag:\"%\" help:\"debug non-static initializers\"" 65 CompilingRuntime bool "flag:\"+\" help:\"compiling runtime\"" 66 67 // Longer names 68 AsmHdr string "help:\"write assembly header to `file`\"" 69 ASan bool "help:\"build code compatible with C/C++ address sanitizer\"" 70 Bench string "help:\"append benchmark times to `file`\"" 71 BlockProfile string "help:\"write block profile to `file`\"" 72 BuildID string "help:\"record `id` as the build id in the export metadata\"" 73 CPUProfile string "help:\"write cpu profile to `file`\"" 74 Complete bool "help:\"compiling complete package (no C or assembly)\"" 75 ClobberDead bool "help:\"clobber dead stack slots (for debugging)\"" 76 ClobberDeadReg bool "help:\"clobber dead registers (for debugging)\"" 77 Dwarf bool "help:\"generate DWARF symbols\"" 78 DwarfBASEntries *bool "help:\"use base address selection entries in DWARF\"" 79 DwarfLocationLists *bool "help:\"add location lists to DWARF in optimized mode\"" 80 Dynlink *bool "help:\"support references to Go symbols defined in other shared libraries\"" 81 EmbedCfg func(string) "help:\"read go:embed configuration from `file`\"" 82 Env func(string) "help:\"add `definition` of the form key=value to environment\"" 83 GenDwarfInl int "help:\"generate DWARF inline info records\"" 84 GoVersion string "help:\"required version of the runtime\"" 85 ImportCfg func(string) "help:\"read import configuration from `file`\"" 86 InstallSuffix string "help:\"set pkg directory `suffix`\"" 87 JSON string "help:\"version,file for JSON compiler/optimizer detail output\"" 88 Lang string "help:\"Go language version source code expects\"" 89 LinkObj string "help:\"write linker-specific object to `file`\"" 90 LinkShared *bool "help:\"generate code that will be linked against Go shared libraries\"" 91 Live CountFlag "help:\"debug liveness analysis\"" 92 MSan bool "help:\"build code compatible with C/C++ memory sanitizer\"" 93 MemProfile string "help:\"write memory profile to `file`\"" 94 MemProfileRate int "help:\"set runtime.MemProfileRate to `rate`\"" 95 MutexProfile string "help:\"write mutex profile to `file`\"" 96 NoLocalImports bool "help:\"reject local (relative) imports\"" 97 CoverageCfg func(string) "help:\"read coverage configuration from `file`\"" 98 Pack bool "help:\"write to file.a instead of file.o\"" 99 Race bool "help:\"enable race detector\"" 100 Shared *bool "help:\"generate code that can be linked into a shared library\"" 101 SmallFrames bool "help:\"reduce the size limit for stack allocated objects\"" 102 Spectre string "help:\"enable spectre mitigations in `list` (all, index, ret)\"" 103 Std bool "help:\"compiling standard library\"" 104 SymABIs string "help:\"read symbol ABIs from `file`\"" 105 TraceProfile string "help:\"write an execution trace to `file`\"" 106 TrimPath string "help:\"remove `prefix` from recorded source file paths\"" 107 WB bool "help:\"enable write barrier\"" 108 PgoProfile string "help:\"read profile or pre-process profile from `file`\"" 109 ErrorURL bool "help:\"print explanatory URL with error message if applicable\"" 110 111 // Configuration derived from flags; not a flag itself. 112 Cfg struct { 113 Embed struct { 114 Patterns map[string][]string 115 Files map[string]string 116 } 117 ImportDirs []string 118 ImportMap map[string]string 119 PackageFile map[string]string 120 CoverageInfo *covcmd.CoverFixupConfig 121 SpectreIndex bool 122 123 Instrumenting bool 124 } 125 } 126 127 // ParseFlags parses the command-line flags into Flag. 128 func ParseFlags()