-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvgo.go
60 lines (53 loc) · 1.03 KB
/
vgo.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
package main
import (
"bytes"
"go/ast"
"go/printer"
"go/scanner"
"go/token"
"os"
"path/filepath"
"runtime"
)
var (
fset = token.NewFileSet()
printconfig = printer.Config{Mode: printer.SourcePos}
)
func FormatNode(node ast.Node) string {
buf := new(bytes.Buffer)
printer.Fprint(buf, fset, node)
return string(buf.Bytes())
}
func main() {
goarch := runtime.GOARCH
gosubarch := ""
if s := os.Getenv("GOARCH"); s != "" {
goarch = s
}
if s := os.Getenv("GOSUBARCH"); s != "" {
gosubarch = s
}
tr := NewTranslator(goarch, gosubarch)
files, _ := filepath.Glob("*.vgo")
for _, file := range files {
err := tr.ProcessFile(file)
if err != nil {
scanner.PrintError(os.Stderr, err)
}
}
}
type Translator struct {
fset *token.FileSet
goarch string
gosubarch string
arch Arch
funcs []*Function
}
func NewTranslator(goarch, gosubarch string) *Translator {
return &Translator{
fset: token.NewFileSet(),
goarch: goarch,
gosubarch: gosubarch,
arch: FindArch(goarch, gosubarch),
}
}