OLD | NEW |
---|---|
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef WASM_RUN_UTILS_H | 5 #ifndef WASM_RUN_UTILS_H |
6 #define WASM_RUN_UTILS_H | 6 #define WASM_RUN_UTILS_H |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 isolate_, ret_code, name, | 213 isolate_, ret_code, name, |
214 static_cast<int>(this->module->functions[index].sig->parameter_count()), | 214 static_cast<int>(this->module->functions[index].sig->parameter_count()), |
215 module_object); | 215 module_object); |
216 return ret; | 216 return ret; |
217 } | 217 } |
218 | 218 |
219 void SetFunctionCode(uint32_t index, Handle<Code> code) { | 219 void SetFunctionCode(uint32_t index, Handle<Code> code) { |
220 instance->function_code[index] = code; | 220 instance->function_code[index] = code; |
221 } | 221 } |
222 | 222 |
223 void AddIndirectFunctionTable(int* functions, int table_size) { | 223 void AddIndirectFunctionTable(uint16_t* functions, uint32_t table_size) { |
224 Handle<FixedArray> fixed = | 224 module_.function_tables.push_back( |
225 isolate_->factory()->NewFixedArray(2 * table_size); | 225 {table_size, table_size, std::vector<uint16_t>()}); |
226 instance->function_table = fixed; | |
227 DCHECK_EQ(0u, module->function_table.size()); | |
228 for (int i = 0; i < table_size; i++) { | 226 for (int i = 0; i < table_size; i++) { |
Mircea Trofin
2016/07/26 03:37:27
++i
ddchen
2016/07/26 05:44:44
Done.
| |
229 module_.function_table.push_back(functions[i]); | 227 module_.function_tables.back().values.push_back(functions[i]); |
228 } | |
229 | |
230 Handle<FixedArray> values = BuildFunctionTable( | |
231 isolate_, static_cast<int>(module_.function_tables.size() - 1), | |
232 &module_); | |
233 instance->function_tables.push_back(values); | |
234 } | |
235 | |
236 void PopulateIndirectFunctionTable() { | |
237 for (int i = 0; i < instance->function_tables.size(); i++) { | |
238 PopulateFunctionTable(instance->function_tables[i], | |
239 module_.function_tables[i].size, | |
240 &instance->function_code); | |
230 } | 241 } |
231 } | 242 } |
232 | 243 |
233 void PopulateIndirectFunctionTable() { | |
234 if (instance->function_table.is_null()) return; | |
235 int table_size = static_cast<int>(module->function_table.size()); | |
236 for (int i = 0; i < table_size; i++) { | |
237 int function_index = module->function_table[i]; | |
238 const WasmFunction* function = &module->functions[function_index]; | |
239 instance->function_table->set(i, Smi::FromInt(function->sig_index)); | |
240 instance->function_table->set(i + table_size, | |
241 *instance->function_code[function_index]); | |
242 } | |
243 } | |
244 | |
245 WasmFunction* GetFunctionAt(int index) { return &module_.functions[index]; } | 244 WasmFunction* GetFunctionAt(int index) { return &module_.functions[index]; } |
246 | 245 |
247 WasmInterpreter* interpreter() { return interpreter_; } | 246 WasmInterpreter* interpreter() { return interpreter_; } |
248 WasmExecutionMode execution_mode() { return execution_mode_; } | 247 WasmExecutionMode execution_mode() { return execution_mode_; } |
249 | 248 |
250 private: | 249 private: |
251 WasmExecutionMode execution_mode_; | 250 WasmExecutionMode execution_mode_; |
252 WasmModule module_; | 251 WasmModule module_; |
253 WasmModuleInstance instance_; | 252 WasmModuleInstance instance_; |
254 Isolate* isolate_; | 253 Isolate* isolate_; |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
767 // interpreter. | 766 // interpreter. |
768 #define WASM_EXEC_TEST(name) \ | 767 #define WASM_EXEC_TEST(name) \ |
769 void RunWasm_##name(WasmExecutionMode execution_mode); \ | 768 void RunWasm_##name(WasmExecutionMode execution_mode); \ |
770 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ | 769 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ |
771 TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \ | 770 TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \ |
772 void RunWasm_##name(WasmExecutionMode execution_mode) | 771 void RunWasm_##name(WasmExecutionMode execution_mode) |
773 | 772 |
774 } // namespace | 773 } // namespace |
775 | 774 |
776 #endif | 775 #endif |
OLD | NEW |