aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--prog/target.go66
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