github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/sync2/runtime2/gen.go (about) 1 // +build ignore 2 3 package main 4 5 import ( 6 "fmt" 7 "reflect" 8 9 "github.com/egonelbre/exp/sync2/runtime2/reflect2" 10 ) 11 12 func main() { 13 for _, t := range reflect2.TypesByString("*runtime.g") { 14 if t.Kind() == reflect.Ptr { 15 t = t.Elem() 16 } 17 18 goid, ok := t.FieldByName("goid") 19 if !ok { 20 fmt.Println("did not find g.goid") 21 } 22 fmt.Printf("#define G_ID_OFFSET %v\n", goid.Offset) 23 24 m, ok := t.FieldByName("m") 25 if !ok { 26 fmt.Println("did not find g.m") 27 } 28 fmt.Printf("#define G_M_OFFSET %v\n", m.Offset) 29 30 mp, ok := m.Type.Elem().FieldByName("p") 31 if !ok { 32 fmt.Println("did not find m.p") 33 } 34 fmt.Printf("#define M_P_OFFSET %v\n", mp.Offset) 35 } 36 37 for _, t := range reflect2.TypesByString("*runtime.p") { 38 if t.Kind() == reflect.Ptr { 39 t = t.Elem() 40 } 41 42 pid, ok := t.FieldByName("id") 43 if !ok { 44 fmt.Println("did not find p.id") 45 } 46 fmt.Printf("#define P_ID_OFFSET %v\n", pid.Offset) 47 } 48 }