github.com/ovechkin-dm/go-dyno@v0.0.23/cmd/generate/main.go (about) 1 package main 2 3 import ( 4 "flag" 5 "os" 6 "text/template" 7 ) 8 9 var goTemplate = ` 10 package proxy 11 12 import "unsafe" 13 import "reflect" 14 15 var methods = make([]unsafe.Pointer, {{len .}}) 16 17 func init(){ 18 {{range $idx,$_:= .}} 19 methods[{{$idx}}] = unsafe.Pointer(reflect.ValueOf(makeFuncStub{{$idx}}).Pointer()) 20 {{end}} 21 } 22 23 {{range $idx,$_:= .}} 24 func makeFuncStub{{$idx}}() 25 {{end}} 26 ` 27 28 var asmTemplate = ` 29 #include "textflag.h" 30 #include "funcdata.h" 31 #include "go_asm.h" 32 33 #define LOCAL_RETVALID 32 34 #define LOCAL_REGARGS 40 35 36 {{range $idx,$_:= .}} 37 38 TEXT ·makeFuncStub{{$idx}}(SB),(NOSPLIT|WRAPPER),$312 39 NO_LOCAL_POINTERS 40 LEAQ LOCAL_REGARGS(SP), R12 41 CALL runtime·spillArgs(SB) 42 MOVQ AX, 24(SP) 43 MOVQ AX, 0(SP) 44 MOVQ R12, 8(SP) 45 MOVQ ${{$idx}}, 16(SP) 46 CALL ·moveMakeFuncArgPtrsCustom(SB) 47 MOVQ 24(SP), AX 48 MOVQ AX, 0(SP) 49 LEAQ argframe+0(FP), AX 50 MOVQ AX, 8(SP) 51 MOVB $0, LOCAL_RETVALID(SP) 52 LEAQ LOCAL_RETVALID(SP), AX 53 MOVQ AX, 16(SP) 54 LEAQ LOCAL_REGARGS(SP), AX 55 MOVQ AX, 24(SP) 56 MOVQ ${{$idx}}, 32(SP) 57 CALL ·callReflectCustom(SB) 58 LEAQ LOCAL_REGARGS(SP), R12 59 CALL runtime·unspillArgs(SB) 60 RET 61 62 {{end}} 63 ` 64 65 var armTemplate = ` 66 #include "textflag.h" 67 #include "funcdata.h" 68 69 #define LOCAL_RETVALID 40 70 #define LOCAL_REGARGS 48 71 72 {{range $idx,$_:= .}} 73 TEXT ·makeFuncStub{{$idx}}(SB),(NOSPLIT|WRAPPER),$432 74 NO_LOCAL_POINTERS 75 ADD $LOCAL_REGARGS, RSP, R20 76 CALL runtime·spillArgs(SB) 77 MOVD R20, 16(RSP) 78 MOVD R0, 8(RSP) 79 MOVD ${{$idx}}, R26 80 MOVD R26, 24(RSP) 81 CALL ·moveMakeFuncArgPtrsCustom(SB) 82 MOVD $argframe+0(FP), R3 83 MOVD R3, 16(RSP) 84 MOVB $0, LOCAL_RETVALID(RSP) 85 ADD $LOCAL_RETVALID, RSP, R3 86 MOVD R3, 24(RSP) 87 ADD $LOCAL_REGARGS, RSP, R3 88 MOVD R3, 32(RSP) 89 MOVD ${{$idx}}, R3 90 MOVD R3, 40(RSP) 91 CALL ·callReflectCustom(SB) 92 ADD $LOCAL_REGARGS, RSP, R20 93 CALL runtime·unspillArgs(SB) 94 RET 95 {{end}} 96 ` 97 98 var num = flag.Int("m", 250, "") 99 100 func main() { 101 goT := template.Must(template.New("").Parse(goTemplate)) 102 mg, err := os.Create("./proxy/gen.go") 103 if err != nil { 104 panic(err) 105 } 106 defer mg.Close() 107 108 goT.Execute(mg, make([]struct{}, *num)) 109 110 amdasmT := template.Must(template.New("").Parse(asmTemplate)) 111 ag2, _ := os.Create("./proxy/asm_amd64.s") 112 defer ag2.Close() 113 amdasmT.Execute(ag2, make([]struct{}, *num)) 114 115 armasmT := template.Must(template.New("").Parse(armTemplate)) 116 ag3, _ := os.Create("./proxy/asm_arm64.s") 117 defer ag3.Close() 118 armasmT.Execute(ag3, make([]struct{}, *num)) 119 120 }