aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/compiler/consts.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-08-10 07:50:55 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-08-13 17:22:16 +0200
commitb6de93e603915b57a1eccadc8bd530efd00d28f2 (patch)
treeab3d846f6363872e7429603c17a6d645dcc90b3c /pkg/compiler/consts.go
parent598f4936eb24a3835f35dfbf7840f0c7065634a8 (diff)
pkg/compiler: merge const files into a single file
We now have 8 arches for Linux and .const files produce lots of noise in PRs and lots of diffs. If 3 .txt files are touched, the PR will have 24 .const files, which will be intermixed with .txt files. Frequently const values are equal across arches, and even if they don't spreading a single value across 8 files is inconvinient. Merge all 8 *_arch.const files into a single .const file. See the test for details of the new format. The old format is still parsed for now, we can't update all OSes at once. For Linux this reduces number of const files/lines from 1288/96599 to 158/11603. Fixes #1983
Diffstat (limited to 'pkg/compiler/consts.go')
-rw-r--r--pkg/compiler/consts.go116
1 files changed, 0 insertions, 116 deletions
diff --git a/pkg/compiler/consts.go b/pkg/compiler/consts.go
index e57d599cb..3e8773a03 100644
--- a/pkg/compiler/consts.go
+++ b/pkg/compiler/consts.go
@@ -4,13 +4,7 @@
package compiler
import (
- "bufio"
- "bytes"
"fmt"
- "io/ioutil"
- "path/filepath"
- "sort"
- "strconv"
"strings"
"github.com/google/syzkaller/pkg/ast"
@@ -294,113 +288,3 @@ func (comp *compiler) patchConst(val *uint64, id *string, consts map[string]uint
*val = 1
return false
}
-
-func SerializeConsts(consts map[string]uint64, undeclared map[string]bool) []byte {
- type nameValuePair struct {
- declared bool
- name string
- val uint64
- }
- var nv []nameValuePair
- for k, v := range consts {
- nv = append(nv, nameValuePair{true, k, v})
- }
- for k := range undeclared {
- nv = append(nv, nameValuePair{false, k, 0})
- }
- sort.Slice(nv, func(i, j int) bool {
- return nv[i].name < nv[j].name
- })
-
- buf := new(bytes.Buffer)
- fmt.Fprintf(buf, "# AUTOGENERATED FILE\n")
- for _, x := range nv {
- if x.declared {
- fmt.Fprintf(buf, "%v = %v\n", x.name, x.val)
- } else {
- fmt.Fprintf(buf, "# %v is not set\n", x.name)
- }
- }
- return buf.Bytes()
-}
-
-func DeserializeConsts(data []byte, file string, eh ast.ErrorHandler) map[string]uint64 {
- consts := make(map[string]uint64)
- pos := ast.Pos{
- File: file,
- Line: 1,
- }
- ok := true
- s := bufio.NewScanner(bytes.NewReader(data))
- for ; s.Scan(); pos.Line++ {
- line := s.Text()
- if line == "" || line[0] == '#' {
- continue
- }
- eq := strings.IndexByte(line, '=')
- if eq == -1 {
- eh(pos, "expect '='")
- ok = false
- continue
- }
- name := strings.TrimSpace(line[:eq])
- val, err := strconv.ParseUint(strings.TrimSpace(line[eq+1:]), 0, 64)
- if err != nil {
- eh(pos, fmt.Sprintf("failed to parse int: %v", err))
- ok = false
- continue
- }
- if _, dup := consts[name]; dup {
- eh(pos, fmt.Sprintf("duplicate const %q", name))
- ok = false
- continue
- }
- consts[name] = val
- }
- if err := s.Err(); err != nil {
- eh(pos, fmt.Sprintf("failed to parse: %v", err))
- ok = false
- }
- if !ok {
- return nil
- }
- return consts
-}
-
-func DeserializeConstsGlob(glob string, eh ast.ErrorHandler) map[string]uint64 {
- if eh == nil {
- eh = ast.LoggingHandler
- }
- files, err := filepath.Glob(glob)
- if err != nil {
- eh(ast.Pos{}, fmt.Sprintf("failed to find const files: %v", err))
- return nil
- }
- if len(files) == 0 {
- eh(ast.Pos{}, fmt.Sprintf("no const files matched by glob %q", glob))
- return nil
- }
- consts := make(map[string]uint64)
- for _, f := range files {
- data, err := ioutil.ReadFile(f)
- if err != nil {
- eh(ast.Pos{}, fmt.Sprintf("failed to read const file: %v", err))
- return nil
- }
- consts1 := DeserializeConsts(data, filepath.Base(f), eh)
- if consts1 == nil {
- consts = nil
- }
- if consts != nil {
- for n, v := range consts1 {
- if old, ok := consts[n]; ok && old != v {
- eh(ast.Pos{}, fmt.Sprintf(
- "different values for const %q: %v vs %v", n, v, old))
- return nil
- }
- consts[n] = v
- }
- }
- }
- return consts
-}