aboutsummaryrefslogtreecommitdiffstats
path: root/prog/target.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-04-26 14:14:14 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-05-01 13:31:17 +0200
commite54e9781a4e043b3140b0c908ba4f4e469fd317e (patch)
tree16e6387d78a8577c5f3d9fb8d05a51752da6338e /prog/target.go
parent3f4dbb2f6fff9479d6c250e224bc3cb7f5cd66ed (diff)
prog: remove Dir from Type
Having Dir is Type is handy, but forces us to duplicate lots of types. E.g. if a struct is referenced as both in and out, then we need to have 2 copies and 2 copies of structs/types it includes. If also prevents us from having the struct type as struct identity (because we can have up to 3 of them). Revert to the old way we used to do it: propagate Dir as we walk syscall arguments. This moves lots of dir passing from pkg/compiler to prog package. Now Arg contains the dir, so once we build the tree, we can use dirs as before. Reduces size of sys/linux/gen/amd64.go from 6058336 to 5661150 (-6.6%). Update #1580
Diffstat (limited to 'prog/target.go')
-rw-r--r--prog/target.go20
1 files changed, 10 insertions, 10 deletions
diff --git a/prog/target.go b/prog/target.go
index f9e10b6f4..692d0b877 100644
--- a/prog/target.go
+++ b/prog/target.go
@@ -45,7 +45,7 @@ type Target struct {
// allocate memory, etc. typ is the struct/union type. old is the old value of the struct/union
// for mutation, or nil for generation. The function returns a new value of the struct/union,
// and optionally any calls that need to be inserted before the arg reference.
- SpecialTypes map[string]func(g *Gen, typ Type, old Arg) (Arg, []*Call)
+ SpecialTypes map[string]func(g *Gen, typ Type, dir Dir, old Arg) (Arg, []*Call)
// Special strings that can matter for the target.
// Used as fallback when string type does not have own dictionary.
@@ -197,7 +197,7 @@ func restoreLinks(syscalls []*Syscall, resources []*ResourceDesc, structs []*Key
if c.Ret != nil {
unref(&c.Ret, types)
}
- ForeachType(c, func(t0 Type) {
+ foreachType(c, func(t0 Type, _ typeCtx) {
switch t := t0.(type) {
case *PtrType:
unref(&t.Type, types)
@@ -247,20 +247,20 @@ func (g *Gen) NOutOf(n, outOf int) bool {
return g.r.nOutOf(n, outOf)
}
-func (g *Gen) Alloc(ptrType Type, data Arg) (Arg, []*Call) {
- return g.r.allocAddr(g.s, ptrType, data.Size(), data), nil
+func (g *Gen) Alloc(ptrType Type, dir Dir, data Arg) (Arg, []*Call) {
+ return g.r.allocAddr(g.s, ptrType, dir, data.Size(), data), nil
}
-func (g *Gen) GenerateArg(typ Type, pcalls *[]*Call) Arg {
- return g.generateArg(typ, pcalls, false)
+func (g *Gen) GenerateArg(typ Type, dir Dir, pcalls *[]*Call) Arg {
+ return g.generateArg(typ, dir, pcalls, false)
}
-func (g *Gen) GenerateSpecialArg(typ Type, pcalls *[]*Call) Arg {
- return g.generateArg(typ, pcalls, true)
+func (g *Gen) GenerateSpecialArg(typ Type, dir Dir, pcalls *[]*Call) Arg {
+ return g.generateArg(typ, dir, pcalls, true)
}
-func (g *Gen) generateArg(typ Type, pcalls *[]*Call, ignoreSpecial bool) Arg {
- arg, calls := g.r.generateArgImpl(g.s, typ, ignoreSpecial)
+func (g *Gen) generateArg(typ Type, dir Dir, pcalls *[]*Call, ignoreSpecial bool) Arg {
+ arg, calls := g.r.generateArgImpl(g.s, typ, dir, ignoreSpecial)
*pcalls = append(*pcalls, calls...)
g.r.target.assignSizesArray([]Arg{arg}, nil)
return arg