From 58ae5e18624eaaac79cab00e63d6f32c9bd64ee0 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sun, 3 May 2020 11:29:12 +0200 Subject: prog: remove StructDesc Remove StructDesc, KeyedStruct, StructKey and all associated logic/complexity in prog and pkg/compiler. We can now handle recursion more generically with the Ref type, and Dir/FieldName are not a part of the type anymore. This makes StructType/UnionType simpler and more natural. Reduces size of sys/linux/gen/amd64.go from 5201321 to 4180861 (-20%). Update #1580 --- prog/target.go | 63 +++++++++++++--------------------------------------------- 1 file changed, 14 insertions(+), 49 deletions(-) (limited to 'prog/target.go') diff --git a/prog/target.go b/prog/target.go index 89940a61a..8999f25ac 100644 --- a/prog/target.go +++ b/prog/target.go @@ -22,7 +22,6 @@ type Target struct { Syscalls []*Syscall Resources []*ResourceDesc - Structs []*KeyedStruct Consts []ConstValue Types []Type @@ -137,8 +136,7 @@ func (target *Target) initTarget() { target.ConstMap[c.Name] = c.Value } - target.resourceMap = restoreLinks(target.Syscalls, target.Resources, target.Structs, target.Types) - target.Structs = nil + target.resourceMap = restoreLinks(target.Syscalls, target.Resources, target.Types) target.Types = nil target.SyscallMap = make(map[string]*Syscall) @@ -173,63 +171,30 @@ func (target *Target) sanitize(c *Call, fix bool) error { return nil } -func RestoreLinks(syscalls []*Syscall, resources []*ResourceDesc, structs []*KeyedStruct, types []Type) { - restoreLinks(syscalls, resources, structs, types) +func RestoreLinks(syscalls []*Syscall, resources []*ResourceDesc, types []Type) { + restoreLinks(syscalls, resources, types) } -func restoreLinks(syscalls []*Syscall, resources []*ResourceDesc, structs []*KeyedStruct, - types []Type) map[string]*ResourceDesc { +func restoreLinks(syscalls []*Syscall, resources []*ResourceDesc, types []Type) map[string]*ResourceDesc { resourceMap := make(map[string]*ResourceDesc) for _, res := range resources { resourceMap[res.Name] = res } - keyedStructs := make(map[StructKey]*StructDesc) - for _, desc := range structs { - keyedStructs[desc.Key] = desc.Desc - for i := range desc.Desc.Fields { - unref(&desc.Desc.Fields[i].Type, types) + ForeachType(syscalls, func(_ Type, ctx TypeCtx) { + if ref, ok := (*ctx.Ptr).(Ref); ok { + *ctx.Ptr = types[ref] } - } - for _, c := range syscalls { - for i := range c.Args { - unref(&c.Args[i].Type, types) - } - if c.Ret != nil { - unref(&c.Ret, types) - } - foreachType(c, func(t0 Type, _ typeCtx) { - switch t := t0.(type) { - case *PtrType: - unref(&t.Elem, types) - case *ArrayType: - unref(&t.Elem, types) - case *ResourceType: - t.Desc = resourceMap[t.TypeName] - if t.Desc == nil { - panic("no resource desc") - } - case *StructType: - t.StructDesc = keyedStructs[t.Key] - if t.StructDesc == nil { - panic("no struct desc") - } - case *UnionType: - t.StructDesc = keyedStructs[t.Key] - if t.StructDesc == nil { - panic("no union desc") - } + switch t := (*ctx.Ptr).(type) { + case *ResourceType: + t.Desc = resourceMap[t.TypeName] + if t.Desc == nil { + panic("no resource desc") } - }) - } + } + }) return resourceMap } -func unref(tp *Type, types []Type) { - if ref, ok := (*tp).(Ref); ok { - *tp = types[ref] - } -} - type Gen struct { r *randGen s *state -- cgit mrf-deployment