OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #include "src/macro-assembler.h" | 5 #include "src/macro-assembler.h" |
6 #include "src/objects.h" | 6 #include "src/objects.h" |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/simulator.h" | 9 #include "src/simulator.h" |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 if (function.local_i32_count) os << function.local_i32_count << " i32s "; | 37 if (function.local_i32_count) os << function.local_i32_count << " i32s "; |
38 if (function.local_i64_count) os << function.local_i64_count << " i64s "; | 38 if (function.local_i64_count) os << function.local_i64_count << " i64s "; |
39 if (function.local_f32_count) os << function.local_f32_count << " f32s "; | 39 if (function.local_f32_count) os << function.local_f32_count << " f32s "; |
40 if (function.local_f64_count) os << function.local_f64_count << " f64s "; | 40 if (function.local_f64_count) os << function.local_f64_count << " f64s "; |
41 | 41 |
42 os << " code bytes: " | 42 os << " code bytes: " |
43 << (function.code_end_offset - function.code_start_offset); | 43 << (function.code_end_offset - function.code_start_offset); |
44 return os; | 44 return os; |
45 } | 45 } |
46 | 46 |
| 47 std::ostream& operator<<(std::ostream& os, const WasmFunctionName& pair) { |
| 48 os << "#" << pair.function_->func_index << ":"; |
| 49 if (pair.function_->name_offset > 0) { |
| 50 if (pair.module_) { |
| 51 os << pair.module_->GetName(pair.function_->name_offset); |
| 52 } else { |
| 53 os << "+" << pair.function_->func_index; |
| 54 } |
| 55 } else { |
| 56 os << "?"; |
| 57 } |
| 58 return os; |
| 59 } |
47 | 60 |
48 // A helper class for compiling multiple wasm functions that offers | 61 // A helper class for compiling multiple wasm functions that offers |
49 // placeholder code objects for calling functions that are not yet compiled. | 62 // placeholder code objects for calling functions that are not yet compiled. |
50 class WasmLinker { | 63 class WasmLinker { |
51 public: | 64 public: |
52 WasmLinker(Isolate* isolate, size_t size) | 65 WasmLinker(Isolate* isolate, size_t size) |
53 : isolate_(isolate), placeholder_code_(size), function_code_(size) {} | 66 : isolate_(isolate), placeholder_code_(size), function_code_(size) {} |
54 | 67 |
55 // Get the code object for a function, allocating a placeholder if it has | 68 // Get the code object for a function, allocating a placeholder if it has |
56 // not yet been compiled. | 69 // not yet been compiled. |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 } | 347 } |
335 if (!instance.globals_buffer.is_null()) { | 348 if (!instance.globals_buffer.is_null()) { |
336 instance.js_object->SetInternalField(kWasmGlobalsArrayBuffer, | 349 instance.js_object->SetInternalField(kWasmGlobalsArrayBuffer, |
337 *instance.globals_buffer); | 350 *instance.globals_buffer); |
338 } | 351 } |
339 | 352 |
340 //------------------------------------------------------------------------- | 353 //------------------------------------------------------------------------- |
341 // Compile all functions in the module. | 354 // Compile all functions in the module. |
342 //------------------------------------------------------------------------- | 355 //------------------------------------------------------------------------- |
343 instance.function_table = BuildFunctionTable(isolate, this); | 356 instance.function_table = BuildFunctionTable(isolate, this); |
344 int index = 0; | 357 uint32_t index = 0; |
345 WasmLinker linker(isolate, functions->size()); | 358 WasmLinker linker(isolate, functions->size()); |
346 ModuleEnv module_env; | 359 ModuleEnv module_env; |
347 module_env.module = this; | 360 module_env.module = this; |
348 module_env.instance = &instance; | 361 module_env.instance = &instance; |
349 module_env.linker = &linker; | 362 module_env.linker = &linker; |
350 module_env.asm_js = false; | 363 module_env.asm_js = false; |
351 | 364 |
352 // First pass: compile each function and initialize the code table. | 365 // First pass: compile each function and initialize the code table. |
353 for (const WasmFunction& func : *functions) { | 366 for (const WasmFunction& func : *functions) { |
354 if (thrower.error()) break; | 367 if (thrower.error()) break; |
| 368 DCHECK_EQ(index, func.func_index); |
355 | 369 |
356 const char* cstr = GetName(func.name_offset); | 370 const char* cstr = GetName(func.name_offset); |
357 Handle<String> name = factory->InternalizeUtf8String(cstr); | 371 Handle<String> name = factory->InternalizeUtf8String(cstr); |
358 Handle<Code> code = Handle<Code>::null(); | 372 Handle<Code> code = Handle<Code>::null(); |
359 Handle<JSFunction> function = Handle<JSFunction>::null(); | 373 Handle<JSFunction> function = Handle<JSFunction>::null(); |
360 if (func.external) { | 374 if (func.external) { |
361 // Lookup external function in FFI object. | 375 // Lookup external function in FFI object. |
362 if (!ffi.is_null()) { | 376 if (!ffi.is_null()) { |
363 MaybeHandle<Object> result = Object::GetProperty(ffi, name); | 377 MaybeHandle<Object> result = Object::GetProperty(ffi, name); |
364 if (!result.is_null()) { | 378 if (!result.is_null()) { |
(...skipping 10 matching lines...) Expand all Loading... |
375 } else { | 389 } else { |
376 thrower.Error("FFI function #%d:%s not found.", index, cstr); | 390 thrower.Error("FFI function #%d:%s not found.", index, cstr); |
377 return MaybeHandle<JSObject>(); | 391 return MaybeHandle<JSObject>(); |
378 } | 392 } |
379 } else { | 393 } else { |
380 thrower.Error("FFI table is not an object."); | 394 thrower.Error("FFI table is not an object."); |
381 return MaybeHandle<JSObject>(); | 395 return MaybeHandle<JSObject>(); |
382 } | 396 } |
383 } else { | 397 } else { |
384 // Compile the function. | 398 // Compile the function. |
385 code = compiler::CompileWasmFunction(thrower, isolate, &module_env, func, | 399 code = compiler::CompileWasmFunction(thrower, isolate, &module_env, func); |
386 index); | |
387 if (code.is_null()) { | 400 if (code.is_null()) { |
388 thrower.Error("Compilation of #%d:%s failed.", index, cstr); | 401 thrower.Error("Compilation of #%d:%s failed.", index, cstr); |
389 return MaybeHandle<JSObject>(); | 402 return MaybeHandle<JSObject>(); |
390 } | 403 } |
391 if (func.exported) { | 404 if (func.exported) { |
392 function = compiler::CompileJSToWasmWrapper( | 405 function = compiler::CompileJSToWasmWrapper( |
393 isolate, &module_env, name, code, instance.js_object, index); | 406 isolate, &module_env, name, code, instance.js_object, index); |
394 } | 407 } |
395 } | 408 } |
396 if (!code.is_null()) { | 409 if (!code.is_null()) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 // Create module environment. | 509 // Create module environment. |
497 WasmLinker linker(isolate, module->functions->size()); | 510 WasmLinker linker(isolate, module->functions->size()); |
498 ModuleEnv module_env; | 511 ModuleEnv module_env; |
499 module_env.module = module; | 512 module_env.module = module; |
500 module_env.instance = &instance; | 513 module_env.instance = &instance; |
501 module_env.linker = &linker; | 514 module_env.linker = &linker; |
502 module_env.asm_js = false; | 515 module_env.asm_js = false; |
503 | 516 |
504 // Compile all functions. | 517 // Compile all functions. |
505 Handle<Code> main_code = Handle<Code>::null(); // record last code. | 518 Handle<Code> main_code = Handle<Code>::null(); // record last code. |
506 int index = 0; | 519 uint32_t index = 0; |
507 int main_index = 0; | 520 int main_index = 0; |
508 for (const WasmFunction& func : *module->functions) { | 521 for (const WasmFunction& func : *module->functions) { |
| 522 DCHECK_EQ(index, func.func_index); |
509 if (!func.external) { | 523 if (!func.external) { |
510 // Compile the function and install it in the code table. | 524 // Compile the function and install it in the code table. |
511 Handle<Code> code = compiler::CompileWasmFunction( | 525 Handle<Code> code = |
512 thrower, isolate, &module_env, func, index); | 526 compiler::CompileWasmFunction(thrower, isolate, &module_env, func); |
513 if (!code.is_null()) { | 527 if (!code.is_null()) { |
514 if (func.exported) { | 528 if (func.exported) { |
515 main_code = code; | 529 main_code = code; |
516 main_index = index; | 530 main_index = index; |
517 } | 531 } |
518 linker.Finish(index, code); | 532 linker.Finish(index, code); |
519 } | 533 } |
520 if (thrower.error()) return -1; | 534 if (thrower.error()) return -1; |
521 } | 535 } |
522 index++; | 536 index++; |
(...skipping 28 matching lines...) Expand all Loading... |
551 } | 565 } |
552 if (result->IsHeapNumber()) { | 566 if (result->IsHeapNumber()) { |
553 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); | 567 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); |
554 } | 568 } |
555 thrower.Error("WASM.compileRun() failed: Return value should be number"); | 569 thrower.Error("WASM.compileRun() failed: Return value should be number"); |
556 return -1; | 570 return -1; |
557 } | 571 } |
558 } // namespace wasm | 572 } // namespace wasm |
559 } // namespace internal | 573 } // namespace internal |
560 } // namespace v8 | 574 } // namespace v8 |
OLD | NEW |