-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgosl.go
78 lines (64 loc) · 2.03 KB
/
gosl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2022, The Goki Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// copied and heavily edited from go src/cmd/gofmt/gofmt.go:
// Copyright 2009 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.
package main
import (
"flag"
"fmt"
"os"
"strings"
"github.com/emer/gosl/v2/slprint"
)
// flags
var (
outDir = flag.String("out", "shaders", "output directory for shader code, relative to where gosl is invoked -- must not be an empty string")
excludeFuns = flag.String("exclude", "Update,Defaults", "comma-separated list of names of functions to exclude from exporting to HLSL")
keepTmp = flag.Bool("keep", false, "keep temporary converted versions of the source files, for debugging")
debug = flag.Bool("debug", false, "enable debugging messages while running")
excludeFunMap = map[string]bool{}
)
// Keep these in sync with go/format/format.go.
const (
tabWidth = 8
printerMode = slprint.UseSpaces | slprint.TabIndent | printerNormalizeNumbers
// printerNormalizeNumbers means to canonicalize number literal prefixes
// and exponents while printing. See https://golang.org/doc/go1.13#gosl.
//
// This value is defined in go/printer specifically for go/format and cmd/gosl.
printerNormalizeNumbers = 1 << 30
)
func usage() {
fmt.Fprintf(os.Stderr, "usage: gosl [flags] [path ...]\n")
flag.PrintDefaults()
}
func main() {
flag.Usage = usage
flag.Parse()
goslMain()
}
func GoslArgs() {
exs := *excludeFuns
ex := strings.Split(exs, ",")
for _, fn := range ex {
excludeFunMap[fn] = true
}
}
func goslMain() {
if *outDir == "" {
fmt.Printf("Must have an output directory (default shaders), specified in -out arg\n")
return
}
os.MkdirAll(*outDir, 0755)
RemoveGenFiles(*outDir)
args := flag.Args()
if len(args) == 0 {
fmt.Printf("at least one file name must be passed\n")
return
}
GoslArgs()
ProcessFiles(args)
}