| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 79     kF64Const | 79     kF64Const | 
| 80   } kind; | 80   } kind; | 
| 81 | 81 | 
| 82   union { | 82   union { | 
| 83     int32_t i32_const; | 83     int32_t i32_const; | 
| 84     int64_t i64_const; | 84     int64_t i64_const; | 
| 85     float f32_const; | 85     float f32_const; | 
| 86     double f64_const; | 86     double f64_const; | 
| 87     uint32_t global_index; | 87     uint32_t global_index; | 
| 88   } val; | 88   } val; | 
|  | 89 | 
|  | 90   WasmInitExpr() : kind(kNone) {} | 
|  | 91   explicit WasmInitExpr(int32_t v) : kind(kI32Const) { val.i32_const = v; } | 
|  | 92   explicit WasmInitExpr(int64_t v) : kind(kI64Const) { val.i64_const = v; } | 
|  | 93   explicit WasmInitExpr(float v) : kind(kF32Const) { val.f32_const = v; } | 
|  | 94   explicit WasmInitExpr(double v) : kind(kF64Const) { val.f64_const = v; } | 
|  | 95   WasmInitExpr(WasmInitKind kind, uint32_t global_index) : kind(kGlobalIndex) { | 
|  | 96     val.global_index = global_index; | 
|  | 97   } | 
| 89 }; | 98 }; | 
| 90 | 99 | 
| 91 #define NO_INIT                 \ |  | 
| 92   {                             \ |  | 
| 93     WasmInitExpr::kNone, { 0u } \ |  | 
| 94   } |  | 
| 95 |  | 
| 96 // Static representation of a WASM function. | 100 // Static representation of a WASM function. | 
| 97 struct WasmFunction { | 101 struct WasmFunction { | 
| 98   FunctionSig* sig;      // signature of the function. | 102   FunctionSig* sig;      // signature of the function. | 
| 99   uint32_t func_index;   // index into the function table. | 103   uint32_t func_index;   // index into the function table. | 
| 100   uint32_t sig_index;    // index into the signature table. | 104   uint32_t sig_index;    // index into the signature table. | 
| 101   uint32_t name_offset;  // offset in the module bytes of the name, if any. | 105   uint32_t name_offset;  // offset in the module bytes of the name, if any. | 
| 102   uint32_t name_length;  // length in bytes of the name. | 106   uint32_t name_length;  // length in bytes of the name. | 
| 103   uint32_t code_start_offset;    // offset in the module bytes of code start. | 107   uint32_t code_start_offset;    // offset in the module bytes of code start. | 
| 104   uint32_t code_end_offset;      // offset in the module bytes of code end. | 108   uint32_t code_end_offset;      // offset in the module bytes of code end. | 
| 105   bool imported; | 109   bool imported; | 
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 377 | 381 | 
| 378 #define WCM_WEAK_LINK(TYPE, NAME)                        \ | 382 #define WCM_WEAK_LINK(TYPE, NAME)                        \ | 
| 379   WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME); \ | 383   WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME); \ | 
| 380                                                          \ | 384                                                          \ | 
| 381   Handle<TYPE> NAME() const {                            \ | 385   Handle<TYPE> NAME() const {                            \ | 
| 382     return handle(TYPE::cast(weak_##NAME()->value()));   \ | 386     return handle(TYPE::cast(weak_##NAME()->value()));   \ | 
| 383   } | 387   } | 
| 384 | 388 | 
| 385 #define CORE_WCM_PROPERTY_TABLE(MACRO)                \ | 389 #define CORE_WCM_PROPERTY_TABLE(MACRO)                \ | 
| 386   MACRO(OBJECT, FixedArray, code_table)               \ | 390   MACRO(OBJECT, FixedArray, code_table)               \ | 
| 387   MACRO(OBJECT, FixedArray, import_data)              \ | 391   MACRO(OBJECT, FixedArray, imports)                  \ | 
| 388   MACRO(OBJECT, FixedArray, exports)                  \ | 392   MACRO(OBJECT, FixedArray, exports)                  \ | 
|  | 393   MACRO(OBJECT, FixedArray, inits)                    \ | 
| 389   MACRO(OBJECT, FixedArray, startup_function)         \ | 394   MACRO(OBJECT, FixedArray, startup_function)         \ | 
| 390   MACRO(OBJECT, FixedArray, indirect_function_tables) \ | 395   MACRO(OBJECT, FixedArray, indirect_function_tables) \ | 
| 391   MACRO(OBJECT, String, module_bytes)                 \ | 396   MACRO(OBJECT, String, module_bytes)                 \ | 
| 392   MACRO(OBJECT, ByteArray, function_names)            \ | 397   MACRO(OBJECT, ByteArray, function_names)            \ | 
| 393   MACRO(SMALL_NUMBER, uint32_t, min_memory_pages)     \ | 398   MACRO(SMALL_NUMBER, uint32_t, min_memory_pages)     \ | 
| 394   MACRO(OBJECT, FixedArray, data_segments_info)       \ | 399   MACRO(OBJECT, FixedArray, data_segments_info)       \ | 
| 395   MACRO(OBJECT, ByteArray, data_segments)             \ | 400   MACRO(OBJECT, ByteArray, data_segments)             \ | 
| 396   MACRO(SMALL_NUMBER, uint32_t, globals_size)         \ | 401   MACRO(SMALL_NUMBER, uint32_t, globals_size)         \ | 
| 397   MACRO(OBJECT, JSArrayBuffer, heap)                  \ | 402   MACRO(OBJECT, JSArrayBuffer, heap)                  \ | 
| 398   MACRO(SMALL_NUMBER, bool, export_memory)            \ |  | 
| 399   MACRO(SMALL_NUMBER, ModuleOrigin, origin)           \ | 403   MACRO(SMALL_NUMBER, ModuleOrigin, origin)           \ | 
| 400   MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \ | 404   MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \ | 
| 401   MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \ | 405   MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \ | 
| 402   MACRO(WEAK_LINK, JSObject, owning_instance)         \ | 406   MACRO(WEAK_LINK, JSObject, owning_instance)         \ | 
| 403   MACRO(WEAK_LINK, JSObject, module_object) | 407   MACRO(WEAK_LINK, JSObject, module_object) | 
| 404 | 408 | 
| 405 #if DEBUG | 409 #if DEBUG | 
| 406 #define DEBUG_ONLY_TABLE(MACRO) MACRO(SMALL_NUMBER, uint32_t, instance_id) | 410 #define DEBUG_ONLY_TABLE(MACRO) MACRO(SMALL_NUMBER, uint32_t, instance_id) | 
| 407 #else | 411 #else | 
| 408 #define DEBUG_ONLY_TABLE(IGNORE) | 412 #define DEBUG_ONLY_TABLE(IGNORE) | 
| 409   uint32_t instance_id() const { return -1; } | 413   uint32_t instance_id() const { return -1; } | 
| 410 #endif | 414 #endif | 
| 411 | 415 | 
| 412 #define WCM_PROPERTY_TABLE(MACRO) \ | 416 #define WCM_PROPERTY_TABLE(MACRO) \ | 
| 413   CORE_WCM_PROPERTY_TABLE(MACRO)  \ | 417   CORE_WCM_PROPERTY_TABLE(MACRO)  \ | 
| 414   DEBUG_ONLY_TABLE(MACRO) | 418   DEBUG_ONLY_TABLE(MACRO) | 
| 415 | 419 | 
| 416  private: | 420  private: | 
| 417   enum PropertyIndices { | 421   enum PropertyIndices { | 
| 418 #define INDICES(IGNORE1, IGNORE2, NAME) kID_##NAME, | 422 #define INDICES(IGNORE1, IGNORE2, NAME) kID_##NAME, | 
| 419     WCM_PROPERTY_TABLE(INDICES) Count | 423     WCM_PROPERTY_TABLE(INDICES) Count | 
| 420 #undef INDICES | 424 #undef INDICES | 
| 421   }; | 425   }; | 
| 422 | 426 | 
| 423  public: | 427  public: | 
| 424   static Handle<WasmCompiledModule> New(Isolate* isolate, | 428   static Handle<WasmCompiledModule> New(Isolate* isolate, | 
| 425                                         uint32_t min_memory_pages, | 429                                         uint32_t min_memory_pages, | 
| 426                                         uint32_t globals_size, | 430                                         uint32_t globals_size, | 
| 427                                         bool export_memory, |  | 
| 428                                         ModuleOrigin origin); | 431                                         ModuleOrigin origin); | 
| 429 | 432 | 
| 430   static Handle<WasmCompiledModule> Clone(Isolate* isolate, | 433   static Handle<WasmCompiledModule> Clone(Isolate* isolate, | 
| 431                                           Handle<WasmCompiledModule> module) { | 434                                           Handle<WasmCompiledModule> module) { | 
| 432     Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast( | 435     Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast( | 
| 433         isolate->factory()->CopyFixedArray(module)); | 436         isolate->factory()->CopyFixedArray(module)); | 
| 434     ret->Init(); | 437     ret->Init(); | 
| 435     ret->reset_weak_owning_instance(); | 438     ret->reset_weak_owning_instance(); | 
| 436     ret->reset_weak_next_instance(); | 439     ret->reset_weak_next_instance(); | 
| 437     ret->reset_weak_prev_instance(); | 440     ret->reset_weak_prev_instance(); | 
| 438     return ret; | 441     return ret; | 
| 439   } | 442   } | 
| 440 | 443 | 
| 441   uint32_t mem_size() const { | 444   uint32_t mem_size() const { | 
| 442     DCHECK(has_heap()); | 445     DCHECK(has_heap()); | 
| 443     return heap()->byte_length()->Number(); | 446     return heap()->byte_length()->Number(); | 
| 444   } | 447   } | 
| 445 | 448 | 
| 446   uint32_t default_mem_size() const { | 449   uint32_t default_mem_size() const { | 
| 447     return min_memory_pages() * WasmModule::kPageSize; | 450     return min_memory_pages() * WasmModule::kPageSize; | 
| 448   } | 451   } | 
| 449 | 452 | 
| 450 #define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME) | 453 #define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME) | 
| 451   WCM_PROPERTY_TABLE(DECLARATION) | 454   WCM_PROPERTY_TABLE(DECLARATION) | 
| 452 #undef DECLARATION | 455 #undef DECLARATION | 
| 453 | 456 | 
| 454   void PrintInstancesChain(); | 457   void PrintInstancesChain(); | 
| 455 | 458 | 
| 456  private: | 459  private: | 
| 457 #if DEBUG |  | 
| 458   static uint32_t instance_id_counter_; |  | 
| 459 #endif |  | 
| 460   void Init(); | 460   void Init(); | 
| 461 | 461 | 
| 462   DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule); | 462   DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule); | 
| 463 }; | 463 }; | 
| 464 | 464 | 
| 465 // Extract a function name from the given wasm object. | 465 // Extract a function name from the given wasm object. | 
| 466 // Returns "<WASM UNNAMED>" if the function is unnamed or the name is not a | 466 // Returns "<WASM UNNAMED>" if the function is unnamed or the name is not a | 
| 467 // valid UTF-8 string. | 467 // valid UTF-8 string. | 
| 468 Handle<String> GetWasmFunctionName(Isolate* isolate, Handle<Object> wasm, | 468 Handle<String> GetWasmFunctionName(Isolate* isolate, Handle<Object> wasm, | 
| 469                                    uint32_t func_index); | 469                                    uint32_t func_index); | 
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 543                             int instance_count); | 543                             int instance_count); | 
| 544 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); | 544 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); | 
| 545 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); | 545 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); | 
| 546 | 546 | 
| 547 }  // namespace testing | 547 }  // namespace testing | 
| 548 }  // namespace wasm | 548 }  // namespace wasm | 
| 549 }  // namespace internal | 549 }  // namespace internal | 
| 550 }  // namespace v8 | 550 }  // namespace v8 | 
| 551 | 551 | 
| 552 #endif  // V8_WASM_MODULE_H_ | 552 #endif  // V8_WASM_MODULE_H_ | 
| OLD | NEW | 
|---|