aboutsummaryrefslogtreecommitdiffstats
path: root/sys/syz-extract
diff options
context:
space:
mode:
Diffstat (limited to 'sys/syz-extract')
-rw-r--r--sys/syz-extract/extract.go32
1 files changed, 2 insertions, 30 deletions
diff --git a/sys/syz-extract/extract.go b/sys/syz-extract/extract.go
index 5f978a37e..7000bdc5f 100644
--- a/sys/syz-extract/extract.go
+++ b/sys/syz-extract/extract.go
@@ -4,14 +4,11 @@
package main
import (
- "bytes"
"flag"
"fmt"
- "io"
"io/ioutil"
"os"
"path/filepath"
- "sort"
"strings"
"github.com/google/syzkaller/pkg/ast"
@@ -75,26 +72,12 @@ func main() {
consts := compileConsts(archs[*flagArch], desc)
- out := new(bytes.Buffer)
- generateConsts(*flagArch, consts, out)
- if err := osutil.WriteFile(outname, out.Bytes()); err != nil {
+ data := compiler.SerializeConsts(consts)
+ if err := osutil.WriteFile(outname, data); err != nil {
failf("failed to write output file: %v", err)
}
}
-func generateConsts(arch string, consts map[string]uint64, out io.Writer) {
- var nv []NameValue
- for k, v := range consts {
- nv = append(nv, NameValue{k, v})
- }
- sort.Sort(NameValueArray(nv))
-
- fmt.Fprintf(out, "# AUTOGENERATED FILE\n")
- for _, x := range nv {
- fmt.Fprintf(out, "%v = %v\n", x.name, x.val)
- }
-}
-
func compileConsts(arch *Arch, desc *ast.Description) map[string]uint64 {
valArr, includes, incdirs, defines := compiler.ExtractConsts(desc)
if len(valArr) == 0 {
@@ -107,17 +90,6 @@ func compileConsts(arch *Arch, desc *ast.Description) map[string]uint64 {
return consts
}
-type NameValue struct {
- name string
- val uint64
-}
-
-type NameValueArray []NameValue
-
-func (a NameValueArray) Len() int { return len(a) }
-func (a NameValueArray) Less(i, j int) bool { return a[i].name < a[j].name }
-func (a NameValueArray) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
-
func failf(msg string, args ...interface{}) {
fmt.Fprintf(os.Stderr, msg+"\n", args...)
os.Exit(1)