| 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 #ifndef V8_WASM_MODULE_H_ | 5 #ifndef V8_WASM_MODULE_H_ |
| 6 #define V8_WASM_MODULE_H_ | 6 #define V8_WASM_MODULE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "src/api.h" | 10 #include "src/api.h" |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 \ | 367 \ |
| 368 bool has_##NAME() const { return get(ID)->Is##TYPE(); } \ | 368 bool has_##NAME() const { return get(ID)->Is##TYPE(); } \ |
| 369 \ | 369 \ |
| 370 void reset_##NAME() { set_undefined(ID); } | 370 void reset_##NAME() { set_undefined(ID); } |
| 371 | 371 |
| 372 #define WCM_OBJECT(TYPE, NAME) WCM_OBJECT_OR_WEAK(TYPE, NAME, kID_##NAME) | 372 #define WCM_OBJECT(TYPE, NAME) WCM_OBJECT_OR_WEAK(TYPE, NAME, kID_##NAME) |
| 373 | 373 |
| 374 #define WCM_SMALL_NUMBER(TYPE, NAME) \ | 374 #define WCM_SMALL_NUMBER(TYPE, NAME) \ |
| 375 TYPE NAME() const { \ | 375 TYPE NAME() const { \ |
| 376 return static_cast<TYPE>(Smi::cast(get(kID_##NAME))->value()); \ | 376 return static_cast<TYPE>(Smi::cast(get(kID_##NAME))->value()); \ |
| 377 } \ | |
| 378 \ | |
| 379 void set_##NAME(TYPE value) { \ | |
| 380 set(kID_##NAME, Smi::FromInt(static_cast<int>(value))); \ | |
| 381 } | |
| 382 | |
| 383 #define WCM_LARGE_NUMBER(TYPE, NAME) \ | |
| 384 TYPE NAME() const { \ | |
| 385 return static_cast<TYPE>(HeapNumber::cast(get(kID_##NAME))->value()); \ | |
| 386 } \ | |
| 387 \ | |
| 388 void set_##NAME(TYPE value) { \ | |
| 389 HeapNumber::cast(get(kID_##NAME))->set_value(static_cast<double>(value)); \ | |
| 390 } | 377 } |
| 391 | 378 |
| 392 #define WCM_WEAK_LINK(TYPE, NAME) \ | 379 #define WCM_WEAK_LINK(TYPE, NAME) \ |
| 393 WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME); \ | 380 WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME); \ |
| 394 \ | 381 \ |
| 395 Handle<TYPE> NAME() const { \ | 382 Handle<TYPE> NAME() const { \ |
| 396 return handle(TYPE::cast(weak_##NAME()->value())); \ | 383 return handle(TYPE::cast(weak_##NAME()->value())); \ |
| 397 } | 384 } |
| 398 | 385 |
| 399 #define WCM_PROPERTY_TABLE(MACRO) \ | 386 #define WCM_PROPERTY_TABLE(MACRO) \ |
| 400 MACRO(OBJECT, FixedArray, code_table) \ | 387 MACRO(OBJECT, FixedArray, code_table) \ |
| 401 MACRO(OBJECT, FixedArray, import_data) \ | 388 MACRO(OBJECT, FixedArray, import_data) \ |
| 402 MACRO(OBJECT, FixedArray, exports) \ | 389 MACRO(OBJECT, FixedArray, exports) \ |
| 403 MACRO(OBJECT, FixedArray, startup_function) \ | 390 MACRO(OBJECT, FixedArray, startup_function) \ |
| 404 MACRO(OBJECT, FixedArray, indirect_function_tables) \ | 391 MACRO(OBJECT, FixedArray, indirect_function_tables) \ |
| 405 MACRO(OBJECT, String, module_bytes) \ | 392 MACRO(OBJECT, String, module_bytes) \ |
| 406 MACRO(OBJECT, ByteArray, function_names) \ | 393 MACRO(OBJECT, ByteArray, function_names) \ |
| 407 MACRO(LARGE_NUMBER, uint32_t, min_required_memory) \ | 394 MACRO(SMALL_NUMBER, uint32_t, min_memory_pages) \ |
| 408 MACRO(OBJECT, FixedArray, data_segments_info) \ | 395 MACRO(OBJECT, FixedArray, data_segments_info) \ |
| 409 MACRO(OBJECT, ByteArray, data_segments) \ | 396 MACRO(OBJECT, ByteArray, data_segments) \ |
| 410 MACRO(LARGE_NUMBER, uint32_t, globals_size) \ | 397 MACRO(SMALL_NUMBER, uint32_t, globals_size) \ |
| 411 MACRO(LARGE_NUMBER, uint32_t, mem_size) \ | 398 MACRO(OBJECT, JSArrayBuffer, heap) \ |
| 412 MACRO(OBJECT, JSArrayBuffer, mem_start) \ | |
| 413 MACRO(SMALL_NUMBER, bool, export_memory) \ | 399 MACRO(SMALL_NUMBER, bool, export_memory) \ |
| 414 MACRO(SMALL_NUMBER, ModuleOrigin, origin) \ | 400 MACRO(SMALL_NUMBER, ModuleOrigin, origin) \ |
| 415 MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \ | 401 MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \ |
| 416 MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \ | 402 MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \ |
| 417 MACRO(WEAK_LINK, JSObject, owning_instance) \ | 403 MACRO(WEAK_LINK, JSObject, owning_instance) \ |
| 418 MACRO(WEAK_LINK, JSObject, module_object) | 404 MACRO(WEAK_LINK, JSObject, module_object) |
| 419 | 405 |
| 420 private: | 406 private: |
| 421 enum PropertyIndices { | 407 enum PropertyIndices { |
| 422 #define INDICES(IGNORE1, IGNORE2, NAME) kID_##NAME, | 408 #define INDICES(IGNORE1, IGNORE2, NAME) kID_##NAME, |
| 423 WCM_PROPERTY_TABLE(INDICES) Count | 409 WCM_PROPERTY_TABLE(INDICES) Count |
| 424 #undef INDICES | 410 #undef INDICES |
| 425 }; | 411 }; |
| 426 | 412 |
| 427 public: | 413 public: |
| 428 static Handle<WasmCompiledModule> New(Isolate* isolate) { | 414 static Handle<WasmCompiledModule> New(Isolate* isolate, |
| 429 Handle<FixedArray> ret = | 415 uint32_t min_memory_pages, |
| 430 isolate->factory()->NewFixedArray(PropertyIndices::Count, TENURED); | 416 uint32_t globals_size, |
| 431 Handle<HeapNumber> number; | 417 bool export_memory, |
| 432 #define WCM_INIT_OBJECT(IGNORE1, IGNORE2) | 418 ModuleOrigin origin); |
| 433 #define WCM_INIT_WEAK_LINK(IGNORE1, IGNORE2) | |
| 434 #define WCM_INIT_SMALL_NUMBER(IGNORE1, IGNORE2) | |
| 435 #define WCM_INIT_LARGE_NUMBER(IGNORE, NAME) \ | |
| 436 number = isolate->factory()->NewHeapNumber(0.0, MUTABLE, TENURED); \ | |
| 437 ret->set(kID_##NAME, *number); | |
| 438 | |
| 439 #define INITIALIZER(KIND, TYPE, NAME) WCM_INIT_##KIND(TYPE, NAME) | |
| 440 WCM_PROPERTY_TABLE(INITIALIZER) | |
| 441 #undef INITIALIZER | |
| 442 return handle(WasmCompiledModule::cast(*ret)); | |
| 443 } | |
| 444 | 419 |
| 445 static Handle<WasmCompiledModule> Clone(Isolate* isolate, | 420 static Handle<WasmCompiledModule> Clone(Isolate* isolate, |
| 446 Handle<WasmCompiledModule> module) { | 421 Handle<WasmCompiledModule> module) { |
| 447 Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast( | 422 Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast( |
| 448 isolate->factory()->CopyFixedArray(module)); | 423 isolate->factory()->CopyFixedArray(module)); |
| 449 Handle<HeapNumber> number = | |
| 450 isolate->factory()->NewHeapNumber(0.0, MUTABLE, TENURED); | |
| 451 ret->set(kID_mem_size, *number); | |
| 452 ret->set_mem_size(module->mem_size()); | |
| 453 return ret; | 424 return ret; |
| 454 } | 425 } |
| 455 | 426 |
| 427 uint32_t mem_size() const { |
| 428 DCHECK(has_heap()); |
| 429 return heap()->byte_length()->Number(); |
| 430 } |
| 431 |
| 432 uint32_t default_mem_size() const { |
| 433 return min_memory_pages() * WasmModule::kPageSize; |
| 434 } |
| 435 |
| 456 #define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME) | 436 #define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME) |
| 457 WCM_PROPERTY_TABLE(DECLARATION) | 437 WCM_PROPERTY_TABLE(DECLARATION) |
| 458 #undef DECLARATION | 438 #undef DECLARATION |
| 459 | 439 |
| 460 private: | 440 private: |
| 461 DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule); | 441 DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule); |
| 462 }; | 442 }; |
| 463 | 443 |
| 464 // Extract a function name from the given wasm object. | 444 // Extract a function name from the given wasm object. |
| 465 // Returns "<WASM UNNAMED>" if the function is unnamed or the name is not a | 445 // Returns "<WASM UNNAMED>" if the function is unnamed or the name is not a |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 int instance_count); | 525 int instance_count); |
| 546 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); | 526 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); |
| 547 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); | 527 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); |
| 548 | 528 |
| 549 } // namespace testing | 529 } // namespace testing |
| 550 } // namespace wasm | 530 } // namespace wasm |
| 551 } // namespace internal | 531 } // namespace internal |
| 552 } // namespace v8 | 532 } // namespace v8 |
| 553 | 533 |
| 554 #endif // V8_WASM_MODULE_H_ | 534 #endif // V8_WASM_MODULE_H_ |
| OLD | NEW |