1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 // mkpost processes the output of cgo -godefs to
8 // modify the generated types. It is used to clean up
9 // the sys API in an architecture specific manner.
11 // mkpost is run after cgo -godefs by mkall.sh.
24 b, err := ioutil.ReadAll(os.Stdin)
30 goarch := os.Getenv("GOARCH")
31 goos := os.Getenv("GOOS")
32 if goarch == "s390x" && goos == "linux" {
33 // Export the types of PtraceRegs fields.
34 re := regexp.MustCompile("ptrace(Psw|Fpregs|Per)")
35 s = re.ReplaceAllString(s, "Ptrace$1")
37 // Replace padding fields inserted by cgo with blank identifiers.
38 re = regexp.MustCompile("Pad_cgo[A-Za-z0-9_]*")
39 s = re.ReplaceAllString(s, "_")
41 // Replace other unwanted fields with blank identifiers.
42 re = regexp.MustCompile("X_[A-Za-z0-9_]*")
43 s = re.ReplaceAllString(s, "_")
45 // Replace the control_regs union with a blank identifier for now.
46 re = regexp.MustCompile("(Control_regs)\\s+\\[0\\]uint64")
47 s = re.ReplaceAllString(s, "_ [0]uint64")
51 b, err = format.Source([]byte(s))
56 // Append this command to the header to show where the new file
58 re := regexp.MustCompile("(cgo -godefs [a-zA-Z0-9_]+\\.go.*)")
59 b = re.ReplaceAll(b, []byte("$1 | go run mkpost.go"))