aboutsummaryrefslogtreecommitdiffstats
path: root/sys/syz-extract
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-08-27 15:08:11 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-08-27 15:28:49 +0200
commite2ffb4fc9111e28f1d8e0e987cb06172cbbd4e84 (patch)
tree8dc4d76063e3430321622cd81763a95a972f2e3a /sys/syz-extract
parente71c87fbf52c83d8e514e4685d40da4d4d0f1a1c (diff)
pkg/compiler: move more const-processing code to compiler
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)