diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-05-03 11:29:12 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-05-03 12:55:42 +0200 |
| commit | 58ae5e18624eaaac79cab00e63d6f32c9bd64ee0 (patch) | |
| tree | 00515dd9b2e461102e898930df00bc80400bf996 /prog/target.go | |
| parent | 5457883a514281287bbd81364c4e26e25828563d (diff) | |
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
Diffstat (limited to 'prog/target.go')
| -rw-r--r-- | prog/target.go | 63 |
1 files changed, 14 insertions, 49 deletions
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 |
