aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/compiler/compiler.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2022-04-29 09:15:41 +0200
committerDmitry Vyukov <dvyukov@google.com>2022-04-29 16:23:27 +0200
commit44a5ca633e186c5836010366c515a4017836121b (patch)
tree326b10c295737e0af8ce69ef8cbf2dbf4ecaccba /pkg/compiler/compiler.go
parente9076525f882cc932139b6e813c39f3f0043c3f5 (diff)
pkg/ast, pkg/compiler: support per-file metadata
We have a bunch of hacks in syz-extract, syz-sysgen and syz-check with respect to description files unsupported on some arches, or that must not be part of make extract. Add 2 meta attribtues to files: meta noextract Tells `make extract` to not extract constants for this file. Though, `syz-extract` can still be invoked manually on this file. meta arches["arch1", "arch2"] Restricts this file only to the given set of architectures. `make extract` and ``make generate` will not use it on other architectures. Later we can potentially use meta attributes to specify git tree/commit that must be used for extraction. Maybe something else. Fixes #2754
Diffstat (limited to 'pkg/compiler/compiler.go')
-rw-r--r--pkg/compiler/compiler.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go
index 62a102d40..b3e39be06 100644
--- a/pkg/compiler/compiler.go
+++ b/pkg/compiler/compiler.go
@@ -7,6 +7,7 @@ package compiler
import (
"fmt"
+ "path/filepath"
"sort"
"strconv"
"strings"
@@ -74,6 +75,7 @@ func createCompiler(desc *ast.Description, target *targets.Target, eh ast.ErrorH
// Compile compiles sys description.
func Compile(desc *ast.Description, consts map[string]uint64, target *targets.Target, eh ast.ErrorHandler) *Prog {
comp := createCompiler(desc.Clone(), target, eh)
+ comp.filterArch()
comp.typecheck()
// The subsequent, more complex, checks expect basic validity of the tree,
// in particular corrent number of type arguments. If there were errors,
@@ -151,6 +153,24 @@ func (comp *compiler) warning(pos ast.Pos, msg string, args ...interface{}) {
comp.warnings = append(comp.warnings, warn{pos, fmt.Sprintf(msg, args...)})
}
+func (comp *compiler) filterArch() {
+ files := comp.fileList()
+ comp.desc = comp.desc.Filter(func(n ast.Node) bool {
+ pos, typ, name := n.Info()
+ meta := files[filepath.Base(pos.File)]
+ if meta.SupportsArch(comp.target.Arch) {
+ return true
+ }
+ switch n.(type) {
+ case *ast.Resource, *ast.Struct, *ast.Call, *ast.TypeDef:
+ // This is required to keep the unsupported diagnostic working,
+ // otherwise sysgen will think that these things are still supported on some arches.
+ comp.unsupported[typ+" "+name] = true
+ }
+ return false
+ })
+}
+
func (comp *compiler) structIsVarlen(name string) bool {
if varlen, ok := comp.structVarlen[name]; ok {
return varlen