1
2
3
4
5
6
7
8
9
10
11 package main
12
13 import (
14 "bufio"
15 "flag"
16 "fmt"
17 "log"
18 "os"
19 "regexp"
20 "strings"
21 )
22
23 var (
24 input = flag.String("i", "", "input file name")
25 output = flag.String("o", "", "output file name")
26 pkg = flag.String("p", "", "package name")
27 )
28
29 var Are = regexp.MustCompile(`^\tA([A-Za-z0-9]+)`)
30
31 func main() {
32 flag.Parse()
33 if *input == "" || *output == "" || *pkg == "" {
34 flag.Usage()
35 os.Exit(2)
36 }
37 in, err := os.Open(*input)
38 if err != nil {
39 log.Fatal(err)
40 }
41 fd, err := os.Create(*output)
42 if err != nil {
43 log.Fatal(err)
44 }
45 out := bufio.NewWriter(fd)
46 defer out.Flush()
47 var on = false
48 s := bufio.NewScanner(in)
49 first := true
50 for s.Scan() {
51 line := s.Text()
52 if !on {
53
54
55 const prefix = "= obj.ABase"
56 index := strings.Index(line, prefix)
57 if index < 0 {
58 continue
59 }
60
61 fmt.Fprintf(out, header, *input, *output, *pkg, *pkg)
62 on = true
63 line = line[:index]
64 }
65
66 index := strings.Index(line, "//")
67 if index > 0 {
68 line = line[:index]
69 }
70 index = strings.Index(line, "/*")
71 if index > 0 {
72 line = line[:index]
73 }
74
75
76 if strings.HasPrefix(line, "}") || strings.ContainsRune(line, '=') {
77 break
78 }
79 sub := Are.FindStringSubmatch(line)
80 if len(sub) < 2 {
81 continue
82 }
83 if first {
84 fmt.Fprintf(out, "\tobj.A_ARCHSPECIFIC: %q,\n", sub[1])
85 first = false
86 } else {
87 fmt.Fprintf(out, "\t%q,\n", sub[1])
88 }
89 }
90 fmt.Fprintln(out, "}")
91 if s.Err() != nil {
92 log.Fatal(err)
93 }
94 }
95
96 const header = `// Code generated by stringer -i %s -o %s -p %s; DO NOT EDIT.
97
98 package %s
99
100 import "cmd/internal/obj"
101
102 var Anames = []string{
103 `
104
View as plain text