...
1
2
3
18
19 package loader
20
21 import (
22 `github.com/bytedance/sonic/internal/rt`
23 )
24
25
26
27
28
29
30
31
32
33
34
35
36 func (self Loader) LoadOne(text []byte, funcName string, frameSize int, argSize int, argPtrs []bool, localPtrs []bool) Function {
37 size := uint32(len(text))
38
39 fn := Func{
40 Name: funcName,
41 TextSize: size,
42 ArgsSize: int32(argSize),
43 }
44
45
46 fn.Pcsp = &Pcdata{
47 {PC: size, Val: int32(frameSize)},
48 }
49
50 if self.NoPreempt {
51 fn.PcUnsafePoint = &Pcdata{
52 {PC: size, Val: PCDATA_UnsafePointUnsafe},
53 }
54 } else {
55 fn.PcUnsafePoint = &Pcdata{
56 {PC: size, Val: PCDATA_UnsafePointSafe},
57 }
58 }
59
60
61 fn.PcStackMapIndex = &Pcdata{
62 {PC: size, Val: 0},
63 }
64
65 if argPtrs != nil {
66 args := rt.StackMapBuilder{}
67 for _, b := range argPtrs {
68 args.AddField(b)
69 }
70 fn.ArgsPointerMaps = args.Build()
71 }
72
73 if localPtrs != nil {
74 locals := rt .StackMapBuilder{}
75 for _, b := range localPtrs {
76 locals.AddField(b)
77 }
78 fn.LocalsPointerMaps = locals.Build()
79 }
80
81 out := Load(text, []Func{fn}, self.Name + funcName, []string{self.File})
82 return out[0]
83 }
84
85
86
87
88 func Load(text []byte, funcs []Func, modulename string, filenames []string) (out []Function) {
89 ids := make([]string, len(funcs))
90 for i, f := range funcs {
91 ids[i] = f.Name
92 }
93
94 mod := makeModuledata(modulename, filenames, &funcs, text)
95
96
97 moduledataverify1(mod)
98 registerModule(mod)
99
100
101
102 out = make([]Function, len(funcs))
103 for i, s := range ids {
104 for _, f := range funcs {
105 if f.Name == s {
106 m := uintptr(mod.text + uintptr(f.EntryOff))
107 out[i] = Function(&m)
108 }
109 }
110 }
111 return
112 }
113
View as plain text