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