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/resources.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'prog/resources.go') diff --git a/prog/resources.go b/prog/resources.go index fa03e6cd6..b7bcecf95 100644 --- a/prog/resources.go +++ b/prog/resources.go @@ -46,10 +46,10 @@ func (target *Target) populateResourceCtors() { // Find resources that are created by each call. callsResources := make([][]*ResourceDesc, len(target.Syscalls)) for call, meta := range target.Syscalls { - ForeachType(meta, func(typ Type) { + foreachType(meta, func(typ Type, ctx typeCtx) { switch typ1 := typ.(type) { case *ResourceType: - if typ1.Dir() != DirIn { + if ctx.Dir != DirIn { callsResources[call] = append(callsResources[call], typ1.Desc) } } @@ -84,21 +84,19 @@ func (target *Target) populateResourceCtors() { // isCompatibleResource returns true if resource of kind src can be passed as an argument of kind dst. func (target *Target) isCompatibleResource(dst, src string) bool { - if dst == target.any.res16.TypeName || - dst == target.any.res32.TypeName || - dst == target.any.res64.TypeName || - dst == target.any.resdec.TypeName || - dst == target.any.reshex.TypeName || - dst == target.any.resoct.TypeName { + if target.isAnyRes(dst) { return true } + if target.isAnyRes(src) { + return false + } dstRes := target.resourceMap[dst] if dstRes == nil { - panic(fmt.Sprintf("unknown resource '%v'", dst)) + panic(fmt.Sprintf("unknown resource %q", dst)) } srcRes := target.resourceMap[src] if srcRes == nil { - panic(fmt.Sprintf("unknown resource '%v'", src)) + panic(fmt.Sprintf("unknown resource %q", src)) } return isCompatibleResourceImpl(dstRes.Kind, srcRes.Kind, false) } @@ -128,8 +126,8 @@ func isCompatibleResourceImpl(dst, src []string, precise bool) bool { func (target *Target) getInputResources(c *Syscall) []*ResourceDesc { var resources []*ResourceDesc - ForeachType(c, func(typ Type) { - if typ.Dir() == DirOut { + foreachType(c, func(typ Type, ctx typeCtx) { + if ctx.Dir == DirOut { return } switch typ1 := typ.(type) { @@ -148,10 +146,10 @@ func (target *Target) getInputResources(c *Syscall) []*ResourceDesc { func (target *Target) getOutputResources(c *Syscall) []*ResourceDesc { var resources []*ResourceDesc - ForeachType(c, func(typ Type) { + foreachType(c, func(typ Type, ctx typeCtx) { switch typ1 := typ.(type) { case *ResourceType: - if typ1.Dir() != DirIn { + if ctx.Dir != DirIn { resources = append(resources, typ1.Desc) } } -- cgit mrf-deployment