diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-04-26 14:14:14 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-05-01 13:31:17 +0200 |
| commit | e54e9781a4e043b3140b0c908ba4f4e469fd317e (patch) | |
| tree | 16e6387d78a8577c5f3d9fb8d05a51752da6338e /sys/linux/init.go | |
| parent | 3f4dbb2f6fff9479d6c250e224bc3cb7f5cd66ed (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 'sys/linux/init.go')
| -rw-r--r-- | sys/linux/init.go | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/sys/linux/init.go b/sys/linux/init.go index c816bbd28..9a6eaf62e 100644 --- a/sys/linux/init.go +++ b/sys/linux/init.go @@ -50,7 +50,7 @@ func InitTarget(target *prog.Target) { target.MakeDataMmap = targets.MakePosixMmap(target, true, true) target.Neutralize = arch.neutralize - target.SpecialTypes = map[string]func(g *prog.Gen, typ prog.Type, old prog.Arg) ( + target.SpecialTypes = map[string]func(g *prog.Gen, typ prog.Type, dir prog.Dir, old prog.Arg) ( prog.Arg, []*prog.Call){ "timespec": arch.generateTimespec, "timeval": arch.generateTimespec, @@ -276,7 +276,8 @@ func (arch *arch) neutralizeIoctl(c *prog.Call) { } } -func (arch *arch) generateTimespec(g *prog.Gen, typ0 prog.Type, old prog.Arg) (arg prog.Arg, calls []*prog.Call) { +func (arch *arch) generateTimespec(g *prog.Gen, typ0 prog.Type, dir prog.Dir, old prog.Arg) ( + arg prog.Arg, calls []*prog.Call) { typ := typ0.(*prog.StructType) // We need to generate timespec/timeval that are either // (1) definitely in the past, or @@ -293,9 +294,9 @@ func (arch *arch) generateTimespec(g *prog.Gen, typ0 prog.Type, old prog.Arg) (a switch { case g.NOutOf(1, 4): // Now for relative, past for absolute. - arg = prog.MakeGroupArg(typ, []prog.Arg{ - prog.MakeResultArg(typ.Fields[0], nil, 0), - prog.MakeResultArg(typ.Fields[1], nil, 0), + arg = prog.MakeGroupArg(typ, dir, []prog.Arg{ + prog.MakeResultArg(typ.Fields[0], dir, nil, 0), + prog.MakeResultArg(typ.Fields[1], dir, nil, 0), }) case g.NOutOf(1, 3): // Few ms ahead for relative, past for absolute @@ -306,38 +307,38 @@ func (arch *arch) generateTimespec(g *prog.Gen, typ0 prog.Type, old prog.Arg) (a if usec { nsec /= 1e3 } - arg = prog.MakeGroupArg(typ, []prog.Arg{ - prog.MakeResultArg(typ.Fields[0], nil, 0), - prog.MakeResultArg(typ.Fields[1], nil, nsec), + arg = prog.MakeGroupArg(typ, dir, []prog.Arg{ + prog.MakeResultArg(typ.Fields[0], dir, nil, 0), + prog.MakeResultArg(typ.Fields[1], dir, nil, nsec), }) case g.NOutOf(1, 2): // Unreachable fututre for both relative and absolute - arg = prog.MakeGroupArg(typ, []prog.Arg{ - prog.MakeResultArg(typ.Fields[0], nil, 2e9), - prog.MakeResultArg(typ.Fields[1], nil, 0), + arg = prog.MakeGroupArg(typ, dir, []prog.Arg{ + prog.MakeResultArg(typ.Fields[0], dir, nil, 2e9), + prog.MakeResultArg(typ.Fields[1], dir, nil, 0), }) default: // Few ms ahead for absolute. meta := arch.clockGettimeSyscall ptrArgType := meta.Args[1].(*prog.PtrType) argType := ptrArgType.Type.(*prog.StructType) - tp := prog.MakeGroupArg(argType, []prog.Arg{ - prog.MakeResultArg(argType.Fields[0], nil, 0), - prog.MakeResultArg(argType.Fields[1], nil, 0), + tp := prog.MakeGroupArg(argType, prog.DirOut, []prog.Arg{ + prog.MakeResultArg(argType.Fields[0], prog.DirOut, nil, 0), + prog.MakeResultArg(argType.Fields[1], prog.DirOut, nil, 0), }) var tpaddr prog.Arg - tpaddr, calls = g.Alloc(ptrArgType, tp) + tpaddr, calls = g.Alloc(ptrArgType, prog.DirIn, tp) gettime := &prog.Call{ Meta: meta, Args: []prog.Arg{ - prog.MakeConstArg(meta.Args[0], arch.CLOCK_REALTIME), + prog.MakeConstArg(meta.Args[0], prog.DirIn, arch.CLOCK_REALTIME), tpaddr, }, Ret: prog.MakeReturnArg(meta.Ret), } calls = append(calls, gettime) - sec := prog.MakeResultArg(typ.Fields[0], tp.Inner[0].(*prog.ResultArg), 0) - nsec := prog.MakeResultArg(typ.Fields[1], tp.Inner[1].(*prog.ResultArg), 0) + sec := prog.MakeResultArg(typ.Fields[0], dir, tp.Inner[0].(*prog.ResultArg), 0) + nsec := prog.MakeResultArg(typ.Fields[1], dir, tp.Inner[1].(*prog.ResultArg), 0) msec := timeout1 if g.NOutOf(1, 2) { msec = timeout2 @@ -348,7 +349,7 @@ func (arch *arch) generateTimespec(g *prog.Gen, typ0 prog.Type, old prog.Arg) (a } else { nsec.OpAdd = msec * 1e6 } - arg = prog.MakeGroupArg(typ, []prog.Arg{sec, nsec}) + arg = prog.MakeGroupArg(typ, dir, []prog.Arg{sec, nsec}) } return } |
