| 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 <setjmp.h> | 8 #include <setjmp.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <stdlib.h> | 10 #include <stdlib.h> |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 for (int j = 0; j < table_size; j++) { | 260 for (int j = 0; j < table_size; j++) { |
| 261 WasmFunction& function = module_.functions[table.values[j]]; | 261 WasmFunction& function = module_.functions[table.values[j]]; |
| 262 array->set(j, Smi::FromInt(table.map.Find(function.sig))); | 262 array->set(j, Smi::FromInt(table.map.Find(function.sig))); |
| 263 array->set(j + table_size, | 263 array->set(j + table_size, |
| 264 *instance->function_code[function.func_index]); | 264 *instance->function_code[function.func_index]); |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 } | 267 } |
| 268 | 268 |
| 269 uint32_t AddBytes(Vector<const byte> bytes) { | 269 uint32_t AddBytes(Vector<const byte> bytes) { |
| 270 Handle<SeqOneByteString> old_bytes = | 270 Handle<SeqOneByteString> old_bytes( |
| 271 instance_object_->get_compiled_module()->module_bytes(); | 271 instance_object_->compiled_module()->module_bytes(), isolate_); |
| 272 uint32_t old_size = static_cast<uint32_t>(old_bytes->length()); | 272 uint32_t old_size = static_cast<uint32_t>(old_bytes->length()); |
| 273 ScopedVector<byte> new_bytes(old_size + bytes.length()); | 273 ScopedVector<byte> new_bytes(old_size + bytes.length()); |
| 274 memcpy(new_bytes.start(), old_bytes->GetChars(), old_size); | 274 memcpy(new_bytes.start(), old_bytes->GetChars(), old_size); |
| 275 memcpy(new_bytes.start() + old_size, bytes.start(), bytes.length()); | 275 memcpy(new_bytes.start() + old_size, bytes.start(), bytes.length()); |
| 276 Handle<SeqOneByteString> new_bytes_str = Handle<SeqOneByteString>::cast( | 276 Handle<SeqOneByteString> new_bytes_str = Handle<SeqOneByteString>::cast( |
| 277 isolate_->factory()->NewStringFromOneByte(new_bytes).ToHandleChecked()); | 277 isolate_->factory()->NewStringFromOneByte(new_bytes).ToHandleChecked()); |
| 278 instance_object_->get_compiled_module()->set_module_bytes(new_bytes_str); | 278 instance_object_->compiled_module()->shared()->set_module_bytes( |
| 279 *new_bytes_str); |
| 279 return old_size; | 280 return old_size; |
| 280 } | 281 } |
| 281 | 282 |
| 282 WasmFunction* GetFunctionAt(int index) { return &module_.functions[index]; } | 283 WasmFunction* GetFunctionAt(int index) { return &module_.functions[index]; } |
| 283 | 284 |
| 284 WasmInterpreter* interpreter() { return interpreter_; } | 285 WasmInterpreter* interpreter() { return interpreter_; } |
| 285 WasmExecutionMode execution_mode() { return execution_mode_; } | 286 WasmExecutionMode execution_mode() { return execution_mode_; } |
| 286 Isolate* isolate() { return isolate_; } | 287 Isolate* isolate() { return isolate_; } |
| 287 Handle<WasmInstanceObject> instance_object() { return instance_object_; } | 288 Handle<WasmInstanceObject> instance_object() { return instance_object_; } |
| 288 | 289 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 301 global_offset = (global_offset + size - 1) & ~(size - 1); // align | 302 global_offset = (global_offset + size - 1) & ~(size - 1); // align |
| 302 module_.globals.push_back( | 303 module_.globals.push_back( |
| 303 {type, true, WasmInitExpr(), global_offset, false, false}); | 304 {type, true, WasmInitExpr(), global_offset, false, false}); |
| 304 global_offset += size; | 305 global_offset += size; |
| 305 // limit number of globals. | 306 // limit number of globals. |
| 306 CHECK_LT(global_offset, kMaxGlobalsSize); | 307 CHECK_LT(global_offset, kMaxGlobalsSize); |
| 307 return &module->globals.back(); | 308 return &module->globals.back(); |
| 308 } | 309 } |
| 309 | 310 |
| 310 Handle<WasmInstanceObject> InitInstanceObject() { | 311 Handle<WasmInstanceObject> InitInstanceObject() { |
| 312 Handle<SeqOneByteString> empty_string = Handle<SeqOneByteString>::cast( |
| 313 isolate_->factory()->NewStringFromOneByte({}).ToHandleChecked()); |
| 311 Handle<Managed<wasm::WasmModule>> module_wrapper = | 314 Handle<Managed<wasm::WasmModule>> module_wrapper = |
| 312 Managed<wasm::WasmModule>::New(isolate_, &module_, false); | 315 Managed<wasm::WasmModule>::New(isolate_, &module_, false); |
| 316 Handle<Script> script = |
| 317 isolate_->factory()->NewScript(isolate_->factory()->empty_string()); |
| 318 script->set_type(Script::TYPE_WASM); |
| 319 Handle<WasmSharedModuleData> shared_module_data = |
| 320 WasmSharedModuleData::New(isolate_, module_wrapper, empty_string, |
| 321 script, Handle<ByteArray>::null()); |
| 313 Handle<WasmCompiledModule> compiled_module = | 322 Handle<WasmCompiledModule> compiled_module = |
| 314 WasmCompiledModule::New(isolate_, module_wrapper); | 323 WasmCompiledModule::New(isolate_, shared_module_data); |
| 315 // Minimally initialize the compiled module such that IsWasmCompiledModule | 324 // Minimally initialize the compiled module such that IsWasmCompiledModule |
| 316 // passes. | 325 // passes. |
| 317 // If tests need more (correct) information, add it later. | 326 // If tests need more (correct) information, add it later. |
| 318 compiled_module->set_min_mem_pages(0); | 327 compiled_module->set_min_mem_pages(0); |
| 319 compiled_module->set_max_mem_pages(Smi::kMaxValue); | 328 compiled_module->set_max_mem_pages(Smi::kMaxValue); |
| 320 Handle<SeqOneByteString> empty_string = Handle<SeqOneByteString>::cast( | |
| 321 isolate_->factory()->NewStringFromOneByte({}).ToHandleChecked()); | |
| 322 compiled_module->set_module_bytes(empty_string); | |
| 323 DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module)); | 329 DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module)); |
| 324 return WasmInstanceObject::New(isolate_, compiled_module); | 330 return WasmInstanceObject::New(isolate_, compiled_module); |
| 325 } | 331 } |
| 326 }; | 332 }; |
| 327 | 333 |
| 328 inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module, | 334 inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module, |
| 329 FunctionSig* sig, | 335 FunctionSig* sig, |
| 330 SourcePositionTable* source_position_table, | 336 SourcePositionTable* source_position_table, |
| 331 const byte* start, const byte* end) { | 337 const byte* start, const byte* end) { |
| 332 compiler::WasmGraphBuilder builder(zone, jsgraph, sig, source_position_table); | 338 compiler::WasmGraphBuilder builder(zone, jsgraph, sig, source_position_table); |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 void RunWasm_##name(WasmExecutionMode execution_mode) | 796 void RunWasm_##name(WasmExecutionMode execution_mode) |
| 791 | 797 |
| 792 #define WASM_EXEC_COMPILED_TEST(name) \ | 798 #define WASM_EXEC_COMPILED_TEST(name) \ |
| 793 void RunWasm_##name(WasmExecutionMode execution_mode); \ | 799 void RunWasm_##name(WasmExecutionMode execution_mode); \ |
| 794 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ | 800 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ |
| 795 void RunWasm_##name(WasmExecutionMode execution_mode) | 801 void RunWasm_##name(WasmExecutionMode execution_mode) |
| 796 | 802 |
| 797 } // namespace | 803 } // namespace |
| 798 | 804 |
| 799 #endif | 805 #endif |
| OLD | NEW |