diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2019-12-17 17:34:47 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2019-12-17 19:03:39 +0100 |
| commit | f950e82d47572b79581fd6b8355504cddb06a7f4 (patch) | |
| tree | d57c02a2642c55356877ab523f8b78456c26b6b1 | |
| parent | a6bc9c88b9c64a9b25f560ee6c4d784ff27d0c7d (diff) | |
prog: export RestoreLinks function
Allows to use compiled descriptions.
Will be useful for static checking utility.
| -rw-r--r-- | prog/target.go | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/prog/target.go b/prog/target.go index d02a3dd37..78cf98b3a 100644 --- a/prog/target.go +++ b/prog/target.go @@ -132,40 +132,13 @@ func (target *Target) initTarget() { target.ConstMap[c.Name] = c.Value } - target.resourceMap = make(map[string]*ResourceDesc) - for _, res := range target.Resources { - target.resourceMap[res.Name] = res - } - - keyedStructs := make(map[StructKey]*StructDesc) - for _, desc := range target.Structs { - keyedStructs[desc.Key] = desc.Desc - } + target.resourceMap = restoreLinks(target.Syscalls, target.Resources, target.Structs) target.Structs = nil target.SyscallMap = make(map[string]*Syscall) for i, c := range target.Syscalls { c.ID = i target.SyscallMap[c.Name] = c - ForeachType(c, func(t0 Type) { - switch t := t0.(type) { - case *ResourceType: - t.Desc = target.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") - } - } - }) } target.populateResourceCtors() @@ -187,6 +160,43 @@ func (target *Target) GetConst(name string) uint64 { return v } +func RestoreLinks(syscalls []*Syscall, resources []*ResourceDesc, structs []*KeyedStruct) { + restoreLinks(syscalls, resources, structs) +} + +func restoreLinks(syscalls []*Syscall, resources []*ResourceDesc, structs []*KeyedStruct) 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 _, c := range syscalls { + ForeachType(c, func(t0 Type) { + switch t := t0.(type) { + 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") + } + } + }) + } + return resourceMap +} + type Gen struct { r *randGen s *state |
