| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 } | 202 } |
| 203 | 203 |
| 204 Handle<JSFunction> WrapCode(uint32_t index) { | 204 Handle<JSFunction> WrapCode(uint32_t index) { |
| 205 // Wrap the code so it can be called as a JS function. | 205 // Wrap the code so it can be called as a JS function. |
| 206 Handle<String> name = isolate_->factory()->NewStringFromStaticChars("main"); | 206 Handle<String> name = isolate_->factory()->NewStringFromStaticChars("main"); |
| 207 Handle<JSObject> module_object = Handle<JSObject>(0, isolate_); | 207 Handle<JSObject> module_object = Handle<JSObject>(0, isolate_); |
| 208 Handle<Code> code = instance->function_code[index]; | 208 Handle<Code> code = instance->function_code[index]; |
| 209 WasmJs::InstallWasmMapsIfNeeded(isolate_, isolate_->native_context()); | 209 WasmJs::InstallWasmMapsIfNeeded(isolate_, isolate_->native_context()); |
| 210 Handle<Code> ret_code = | 210 Handle<Code> ret_code = |
| 211 compiler::CompileJSToWasmWrapper(isolate_, this, code, index); | 211 compiler::CompileJSToWasmWrapper(isolate_, this, code, index); |
| 212 FunctionSig* funcSig = this->module->functions[index].sig; | |
| 213 Handle<ByteArray> exportedSig = isolate_->factory()->NewByteArray( | |
| 214 static_cast<int>(funcSig->parameter_count() + funcSig->return_count()), | |
| 215 TENURED); | |
| 216 exportedSig->copy_in(0, reinterpret_cast<const byte*>(funcSig->raw_data()), | |
| 217 exportedSig->length()); | |
| 218 Handle<JSFunction> ret = WrapExportCodeAsJSFunction( | 212 Handle<JSFunction> ret = WrapExportCodeAsJSFunction( |
| 219 isolate_, ret_code, name, | 213 isolate_, ret_code, name, this->module->functions[index].sig, |
| 220 static_cast<int>(this->module->functions[index].sig->parameter_count()), | 214 module_object); |
| 221 exportedSig, module_object); | |
| 222 return ret; | 215 return ret; |
| 223 } | 216 } |
| 224 | 217 |
| 225 void SetFunctionCode(uint32_t index, Handle<Code> code) { | 218 void SetFunctionCode(uint32_t index, Handle<Code> code) { |
| 226 instance->function_code[index] = code; | 219 instance->function_code[index] = code; |
| 227 } | 220 } |
| 228 | 221 |
| 229 void AddIndirectFunctionTable(uint16_t* functions, uint32_t table_size) { | 222 void AddIndirectFunctionTable(uint16_t* function_indexes, |
| 223 uint32_t table_size) { |
| 230 module_.function_tables.push_back({table_size, table_size, | 224 module_.function_tables.push_back({table_size, table_size, |
| 231 std::vector<int32_t>(), false, false, | 225 std::vector<int32_t>(), false, false, |
| 232 SignatureMap()}); | 226 SignatureMap()}); |
| 233 WasmIndirectFunctionTable& table = module_.function_tables.back(); | 227 WasmIndirectFunctionTable& table = module_.function_tables.back(); |
| 234 for (uint32_t i = 0; i < table_size; ++i) { | 228 for (uint32_t i = 0; i < table_size; ++i) { |
| 235 table.values.push_back(functions[i]); | 229 table.values.push_back(function_indexes[i]); |
| 236 table.map.FindOrInsert(module_.functions[functions[i]].sig); | 230 table.map.FindOrInsert(module_.functions[function_indexes[i]].sig); |
| 237 } | 231 } |
| 238 | 232 |
| 239 Handle<FixedArray> values = BuildFunctionTable( | 233 instance->function_tables.push_back( |
| 240 isolate_, static_cast<int>(module_.function_tables.size() - 1), | 234 isolate_->factory()->NewFixedArray(table_size * 2)); |
| 241 &module_); | |
| 242 instance->function_tables.push_back(values); | |
| 243 } | 235 } |
| 244 | 236 |
| 245 void PopulateIndirectFunctionTable() { | 237 void PopulateIndirectFunctionTable() { |
| 238 // Initialize the fixed arrays in instance->function_tables. |
| 246 for (uint32_t i = 0; i < instance->function_tables.size(); i++) { | 239 for (uint32_t i = 0; i < instance->function_tables.size(); i++) { |
| 247 PopulateFunctionTable(instance->function_tables[i], | 240 WasmIndirectFunctionTable& table = module_.function_tables[i]; |
| 248 module_.function_tables[i].size, | 241 Handle<FixedArray> array = instance->function_tables[i]; |
| 249 &instance->function_code); | 242 int table_size = static_cast<int>(table.values.size()); |
| 243 for (int j = 0; j < table_size; j++) { |
| 244 WasmFunction& function = module_.functions[table.values[j]]; |
| 245 array->set(j, Smi::FromInt(table.map.Find(function.sig))); |
| 246 array->set(j + table_size, |
| 247 *instance->function_code[function.func_index]); |
| 248 } |
| 250 } | 249 } |
| 251 } | 250 } |
| 252 | 251 |
| 253 WasmFunction* GetFunctionAt(int index) { return &module_.functions[index]; } | 252 WasmFunction* GetFunctionAt(int index) { return &module_.functions[index]; } |
| 254 | 253 |
| 255 WasmInterpreter* interpreter() { return interpreter_; } | 254 WasmInterpreter* interpreter() { return interpreter_; } |
| 256 WasmExecutionMode execution_mode() { return execution_mode_; } | 255 WasmExecutionMode execution_mode() { return execution_mode_; } |
| 257 | 256 |
| 258 private: | 257 private: |
| 259 WasmExecutionMode execution_mode_; | 258 WasmExecutionMode execution_mode_; |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 // interpreter. | 783 // interpreter. |
| 785 #define WASM_EXEC_TEST(name) \ | 784 #define WASM_EXEC_TEST(name) \ |
| 786 void RunWasm_##name(WasmExecutionMode execution_mode); \ | 785 void RunWasm_##name(WasmExecutionMode execution_mode); \ |
| 787 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ | 786 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ |
| 788 TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \ | 787 TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \ |
| 789 void RunWasm_##name(WasmExecutionMode execution_mode) | 788 void RunWasm_##name(WasmExecutionMode execution_mode) |
| 790 | 789 |
| 791 } // namespace | 790 } // namespace |
| 792 | 791 |
| 793 #endif | 792 #endif |
| OLD | NEW |