line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
// Copyright (c) 2023 Yuki Kimoto |
2
|
|
|
|
|
|
|
// MIT License |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
#include |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#include "spvm_typedecl.h" |
7
|
|
|
|
|
|
|
#include "spvm_native.h" |
8
|
|
|
|
|
|
|
#include "spvm_runtime_method.h" |
9
|
|
|
|
|
|
|
#include "spvm_runtime_arg.h" |
10
|
|
|
|
|
|
|
#include "spvm_opcode.h" |
11
|
|
|
|
|
|
|
#include "spvm_api_method.h" |
12
|
|
|
|
|
|
|
|
13
|
119195
|
|
|
|
|
|
SPVM_API_METHOD* SPVM_API_METHOD_new_api() { |
14
|
|
|
|
|
|
|
|
15
|
119195
|
|
|
|
|
|
void* native_apis_init[] = { |
16
|
|
|
|
|
|
|
SPVM_API_METHOD_get_name, |
17
|
|
|
|
|
|
|
SPVM_API_METHOD_get_index, |
18
|
|
|
|
|
|
|
SPVM_API_METHOD_get_return_basic_type, |
19
|
|
|
|
|
|
|
SPVM_API_METHOD_get_return_type_dimension, |
20
|
|
|
|
|
|
|
SPVM_API_METHOD_get_return_type_flag, |
21
|
|
|
|
|
|
|
SPVM_API_METHOD_get_arg_by_index, |
22
|
|
|
|
|
|
|
SPVM_API_METHOD_get_args_length, |
23
|
|
|
|
|
|
|
SPVM_API_METHOD_get_required_args_length, |
24
|
|
|
|
|
|
|
SPVM_API_METHOD_get_current_basic_type, |
25
|
|
|
|
|
|
|
SPVM_API_METHOD_get_opcode_by_index, |
26
|
|
|
|
|
|
|
SPVM_API_METHOD_get_opcodes_length, |
27
|
|
|
|
|
|
|
SPVM_API_METHOD_is_class_method, |
28
|
|
|
|
|
|
|
SPVM_API_METHOD_is_anon, |
29
|
|
|
|
|
|
|
SPVM_API_METHOD_is_native, |
30
|
|
|
|
|
|
|
SPVM_API_METHOD_is_precompile, |
31
|
|
|
|
|
|
|
SPVM_API_METHOD_is_enum, |
32
|
|
|
|
|
|
|
SPVM_API_METHOD_get_byte_vars_width, |
33
|
|
|
|
|
|
|
SPVM_API_METHOD_get_short_vars_width, |
34
|
|
|
|
|
|
|
SPVM_API_METHOD_get_int_vars_width, |
35
|
|
|
|
|
|
|
SPVM_API_METHOD_get_long_vars_width, |
36
|
|
|
|
|
|
|
SPVM_API_METHOD_get_float_vars_width, |
37
|
|
|
|
|
|
|
SPVM_API_METHOD_get_double_vars_width, |
38
|
|
|
|
|
|
|
SPVM_API_METHOD_get_object_vars_width, |
39
|
|
|
|
|
|
|
SPVM_API_METHOD_get_ref_vars_width, |
40
|
|
|
|
|
|
|
SPVM_API_METHOD_get_mortal_stack_length, |
41
|
|
|
|
|
|
|
SPVM_API_METHOD_get_native_address, |
42
|
|
|
|
|
|
|
SPVM_API_METHOD_set_native_address, |
43
|
|
|
|
|
|
|
SPVM_API_METHOD_get_precompile_address, |
44
|
|
|
|
|
|
|
SPVM_API_METHOD_set_precompile_address, |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
119195
|
|
|
|
|
|
SPVM_API_METHOD* native_apis = calloc(1, sizeof(native_apis_init)); |
48
|
|
|
|
|
|
|
|
49
|
119195
|
|
|
|
|
|
memcpy(native_apis, native_apis_init, sizeof(native_apis_init)); |
50
|
|
|
|
|
|
|
|
51
|
119195
|
|
|
|
|
|
return native_apis; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
119195
|
|
|
|
|
|
void SPVM_API_METHOD_free_api(SPVM_API_METHOD* api) { |
55
|
|
|
|
|
|
|
|
56
|
119195
|
|
|
|
|
|
free(api); |
57
|
119195
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
78264
|
|
|
|
|
|
const char* SPVM_API_METHOD_get_name(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
60
|
|
|
|
|
|
|
|
61
|
78264
|
|
|
|
|
|
return method->name; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
int32_t SPVM_API_METHOD_get_index(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return method->index; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
197086
|
|
|
|
|
|
SPVM_RUNTIME_BASIC_TYPE* SPVM_API_METHOD_get_return_basic_type(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
70
|
|
|
|
|
|
|
|
71
|
197086
|
|
|
|
|
|
return method->return_basic_type; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
197080
|
|
|
|
|
|
int32_t SPVM_API_METHOD_get_return_type_dimension(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
75
|
|
|
|
|
|
|
|
76
|
197080
|
|
|
|
|
|
return method->return_type_dimension; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
52
|
|
|
|
|
|
int32_t SPVM_API_METHOD_get_return_type_flag(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
80
|
|
|
|
|
|
|
|
81
|
52
|
|
|
|
|
|
return method->return_type_flag; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
590790
|
|
|
|
|
|
SPVM_RUNTIME_ARG* SPVM_API_METHOD_get_arg_by_index(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method, int32_t arg_index) { |
85
|
|
|
|
|
|
|
|
86
|
590790
|
50
|
|
|
|
|
if (arg_index < 0) { |
87
|
0
|
|
|
|
|
|
return NULL; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
590790
|
50
|
|
|
|
|
if (arg_index >= method->args_length) { |
91
|
0
|
|
|
|
|
|
return NULL; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
590790
|
|
|
|
|
|
SPVM_RUNTIME_ARG* arg = &method->args[arg_index]; |
95
|
|
|
|
|
|
|
|
96
|
590790
|
|
|
|
|
|
return arg; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
197200
|
|
|
|
|
|
int32_t SPVM_API_METHOD_get_args_length(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
100
|
|
|
|
|
|
|
|
101
|
197200
|
|
|
|
|
|
return method->args_length; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
197206
|
|
|
|
|
|
int32_t SPVM_API_METHOD_get_required_args_length(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
105
|
|
|
|
|
|
|
|
106
|
197206
|
|
|
|
|
|
return method->required_args_length; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
SPVM_RUNTIME_BASIC_TYPE* SPVM_API_METHOD_get_current_basic_type(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return method->current_basic_type; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
SPVM_OPCODE* SPVM_API_METHOD_get_opcode_by_index(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method, int32_t opcode_index) { |
115
|
|
|
|
|
|
|
|
116
|
0
|
0
|
|
|
|
|
if (opcode_index < 0) { |
117
|
0
|
|
|
|
|
|
return NULL; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
|
if (opcode_index >= method->opcodes_length) { |
121
|
0
|
|
|
|
|
|
return NULL; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
SPVM_OPCODE* opcode = &method->opcodes[opcode_index]; |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
return opcode; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
int32_t SPVM_API_METHOD_get_opcodes_length(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
return method->opcodes_length; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
209687
|
|
|
|
|
|
int32_t SPVM_API_METHOD_is_class_method(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
135
|
|
|
|
|
|
|
|
136
|
209687
|
|
|
|
|
|
return method->is_class_method; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
int32_t SPVM_API_METHOD_is_anon(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
return method->is_anon; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
110545
|
|
|
|
|
|
int32_t SPVM_API_METHOD_is_native(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
145
|
|
|
|
|
|
|
|
146
|
110545
|
|
|
|
|
|
return method->is_native; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
85243
|
|
|
|
|
|
int32_t SPVM_API_METHOD_is_precompile(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
150
|
|
|
|
|
|
|
|
151
|
85243
|
|
|
|
|
|
return method->is_precompile; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
2
|
|
|
|
|
|
int32_t SPVM_API_METHOD_is_enum(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
155
|
|
|
|
|
|
|
|
156
|
2
|
|
|
|
|
|
return method->is_enum; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
int32_t SPVM_API_METHOD_get_byte_vars_width(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
int32_t byte_vars_width = method->byte_vars_width; |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
return byte_vars_width; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
int32_t SPVM_API_METHOD_get_short_vars_width(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
return method->short_vars_width; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
int32_t SPVM_API_METHOD_get_int_vars_width(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
172
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
return method->int_vars_width; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
|
int32_t SPVM_API_METHOD_get_long_vars_width(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
return method->long_vars_width; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
int32_t SPVM_API_METHOD_get_float_vars_width(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
182
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
return method->float_vars_width; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
int32_t SPVM_API_METHOD_get_double_vars_width(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
return method->double_vars_width; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
int32_t SPVM_API_METHOD_get_object_vars_width(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
return method->object_vars_width; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
int32_t SPVM_API_METHOD_get_ref_vars_width(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
return method->ref_vars_width; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
0
|
|
|
|
|
|
int32_t SPVM_API_METHOD_get_mortal_stack_length(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
202
|
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
|
return method->mortal_stack_length; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
void* SPVM_API_METHOD_get_native_address(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
207
|
|
|
|
|
|
|
|
208
|
0
|
|
|
|
|
|
return method->native_address; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
35235
|
|
|
|
|
|
void SPVM_API_METHOD_set_native_address(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method, void* address) { |
212
|
|
|
|
|
|
|
|
213
|
35235
|
|
|
|
|
|
method->native_address = address; |
214
|
35235
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
0
|
|
|
|
|
|
void* SPVM_API_METHOD_get_precompile_address(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method) { |
217
|
|
|
|
|
|
|
|
218
|
0
|
|
|
|
|
|
return method->precompile_address; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
16905
|
|
|
|
|
|
void SPVM_API_METHOD_set_precompile_address(SPVM_RUNTIME* runtime, SPVM_RUNTIME_METHOD* method, void* address) { |
222
|
|
|
|
|
|
|
|
223
|
16905
|
|
|
|
|
|
method->precompile_address = address; |
224
|
16905
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|