Add a puffs/cmd/commonflags package.

This commit is contained in:
Nigel Tao committed 2017-11-04 11:09:14 +11:00
1 parent 66047db6d8
commit a0fd42f6d4
6 files changed
+76 -71

No files matched your search

+3 -1
View File
@@ -21,11 +21,13 @@ import (
"os/exec"
"path/filepath"
"strings"
cf "github.com/google/puffs/cmd/commonflags"
)
func doGenlib(args []string) error {
flags := flag.FlagSet{}
ccompilersFlag := flags.String("ccompilers", ccompilersDefault, ccompilersUsage)
ccompilersFlag := flags.String("ccompilers", cf.CcompilersDefault, cf.CcompilersUsage)
dstdirFlag := flags.String("dstdir", "", "directory containing the object files ")
srcdirFlag := flags.String("srcdir", "", "directory containing the C source files")
if err := flags.Parse(args); err != nil {
-16
View File
@@ -46,19 +46,3 @@ func main1() error {
}
return fmt.Errorf("bad sub-command %q", os.Args[1])
}
const (
ccompilersDefault = "clang,gcc"
ccompilersUsage = `comma-separated list of C compilers, e.g. "clang,gcc"`
focusDefault = ""
focusUsage = `comma-separated list of tests or benchmarks (name prefixes) to focus on, e.g. "puffs_gif_decode"`
mimicDefault = false
mimicUsage = `whether to compare Puffs' output with other libraries' output`
repsDefault = 5
repsMin = 0
repsMax = 1000000
repsUsage = `the number of repetitions per benchmark`
)
+10 -20
View File
@@ -23,42 +23,32 @@ import (
"os/exec"
"path/filepath"
"strings"
)
func isStringList(s string) bool {
for i := 0; i < len(s); i++ {
c := s[i]
if c == ',' || c == '-' || c == '.' || c == '/' || ('0' <= c && c <= '9') || ('A' <= c && c <= 'Z') ||
c == '_' || ('a' <= c && c <= 'z') {
continue
}
return false
}
return true
}
cf "github.com/google/puffs/cmd/commonflags"
)
func doBench(args []string) error { return doBenchTest(args, true) }
func doTest(args []string) error { return doBenchTest(args, false) }
func doBenchTest(args []string, bench bool) error {
flags := flag.FlagSet{}
ccompilersFlag := flags.String("ccompilers", ccompilersDefault, ccompilersUsage)
focusFlag := flags.String("focus", focusDefault, focusUsage)
mimicFlag := flags.Bool("mimic", mimicDefault, mimicUsage)
repsFlag := flags.Int("reps", repsDefault, repsUsage)
ccompilersFlag := flags.String("ccompilers", cf.CcompilersDefault, cf.CcompilersUsage)
focusFlag := flags.String("focus", cf.FocusDefault, cf.FocusUsage)
mimicFlag := flags.Bool("mimic", cf.MimicDefault, cf.MimicUsage)
repsFlag := flags.Int("reps", cf.RepsDefault, cf.RepsUsage)
if err := flags.Parse(args); err != nil {
return err
}
if !isStringList(*ccompilersFlag) {
if !cf.IsAlphaNumericIsh(*ccompilersFlag) {
return fmt.Errorf("bad -ccompilers flag value %q", *ccompilersFlag)
}
if !isStringList(*focusFlag) {
if !cf.IsAlphaNumericIsh(*focusFlag) {
return fmt.Errorf("bad -focus flag value %q", *focusFlag)
}
if *repsFlag < repsMin || repsMax < *repsFlag {
return fmt.Errorf("bad -reps flag value %d, outside the range [%d..%d]", *repsFlag, repsMin, repsMax)
if *repsFlag < cf.RepsMin || cf.RepsMax < *repsFlag {
return fmt.Errorf("bad -reps flag value %d, outside the range [%d..%d]", *repsFlag, cf.RepsMin, cf.RepsMax)
}
args = flags.Args()