From e54e9781a4e043b3140b0c908ba4f4e469fd317e Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sun, 26 Apr 2020 14:14:14 +0200 Subject: 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 --- prog/target.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'prog/target.go') 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 -- cgit mrf-deployment