Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: src/wasm/wasm-module.h

Issue 2395133002: Revert of [wasm] Refactor import handling for 0xC. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/module-decoder.cc ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 };
89 90
90 WasmInitExpr() : kind(kNone) {} 91 #define NO_INIT \
91 explicit WasmInitExpr(int32_t v) : kind(kI32Const) { val.i32_const = v; } 92 { \
92 explicit WasmInitExpr(int64_t v) : kind(kI64Const) { val.i64_const = v; } 93 WasmInitExpr::kNone, { 0u } \
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 } 94 }
98 };
99 95
100 // Static representation of a WASM function. 96 // Static representation of a WASM function.
101 struct WasmFunction { 97 struct WasmFunction {
102 FunctionSig* sig; // signature of the function. 98 FunctionSig* sig; // signature of the function.
103 uint32_t func_index; // index into the function table. 99 uint32_t func_index; // index into the function table.
104 uint32_t sig_index; // index into the signature table. 100 uint32_t sig_index; // index into the signature table.
105 uint32_t name_offset; // offset in the module bytes of the name, if any. 101 uint32_t name_offset; // offset in the module bytes of the name, if any.
106 uint32_t name_length; // length in bytes of the name. 102 uint32_t name_length; // length in bytes of the name.
107 uint32_t code_start_offset; // offset in the module bytes of code start. 103 uint32_t code_start_offset; // offset in the module bytes of code start.
108 uint32_t code_end_offset; // offset in the module bytes of code end. 104 uint32_t code_end_offset; // offset in the module bytes of code end.
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 377
382 #define WCM_WEAK_LINK(TYPE, NAME) \ 378 #define WCM_WEAK_LINK(TYPE, NAME) \
383 WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME); \ 379 WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME); \
384 \ 380 \
385 Handle<TYPE> NAME() const { \ 381 Handle<TYPE> NAME() const { \
386 return handle(TYPE::cast(weak_##NAME()->value())); \ 382 return handle(TYPE::cast(weak_##NAME()->value())); \
387 } 383 }
388 384
389 #define CORE_WCM_PROPERTY_TABLE(MACRO) \ 385 #define CORE_WCM_PROPERTY_TABLE(MACRO) \
390 MACRO(OBJECT, FixedArray, code_table) \ 386 MACRO(OBJECT, FixedArray, code_table) \
391 MACRO(OBJECT, FixedArray, imports) \ 387 MACRO(OBJECT, FixedArray, import_data) \
392 MACRO(OBJECT, FixedArray, exports) \ 388 MACRO(OBJECT, FixedArray, exports) \
393 MACRO(OBJECT, FixedArray, inits) \
394 MACRO(OBJECT, FixedArray, startup_function) \ 389 MACRO(OBJECT, FixedArray, startup_function) \
395 MACRO(OBJECT, FixedArray, indirect_function_tables) \ 390 MACRO(OBJECT, FixedArray, indirect_function_tables) \
396 MACRO(OBJECT, String, module_bytes) \ 391 MACRO(OBJECT, String, module_bytes) \
397 MACRO(OBJECT, ByteArray, function_names) \ 392 MACRO(OBJECT, ByteArray, function_names) \
398 MACRO(SMALL_NUMBER, uint32_t, min_memory_pages) \ 393 MACRO(SMALL_NUMBER, uint32_t, min_memory_pages) \
399 MACRO(OBJECT, FixedArray, data_segments_info) \ 394 MACRO(OBJECT, FixedArray, data_segments_info) \
400 MACRO(OBJECT, ByteArray, data_segments) \ 395 MACRO(OBJECT, ByteArray, data_segments) \
401 MACRO(SMALL_NUMBER, uint32_t, globals_size) \ 396 MACRO(SMALL_NUMBER, uint32_t, globals_size) \
402 MACRO(OBJECT, JSArrayBuffer, heap) \ 397 MACRO(OBJECT, JSArrayBuffer, heap) \
398 MACRO(SMALL_NUMBER, bool, export_memory) \
403 MACRO(SMALL_NUMBER, ModuleOrigin, origin) \ 399 MACRO(SMALL_NUMBER, ModuleOrigin, origin) \
404 MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \ 400 MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \
405 MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \ 401 MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \
406 MACRO(WEAK_LINK, JSObject, owning_instance) \ 402 MACRO(WEAK_LINK, JSObject, owning_instance) \
407 MACRO(WEAK_LINK, JSObject, module_object) 403 MACRO(WEAK_LINK, JSObject, module_object)
408 404
409 #if DEBUG 405 #if DEBUG
410 #define DEBUG_ONLY_TABLE(MACRO) MACRO(SMALL_NUMBER, uint32_t, instance_id) 406 #define DEBUG_ONLY_TABLE(MACRO) MACRO(SMALL_NUMBER, uint32_t, instance_id)
411 #else 407 #else
412 #define DEBUG_ONLY_TABLE(IGNORE) 408 #define DEBUG_ONLY_TABLE(IGNORE)
413 uint32_t instance_id() const { return -1; } 409 uint32_t instance_id() const { return -1; }
414 #endif 410 #endif
415 411
416 #define WCM_PROPERTY_TABLE(MACRO) \ 412 #define WCM_PROPERTY_TABLE(MACRO) \
417 CORE_WCM_PROPERTY_TABLE(MACRO) \ 413 CORE_WCM_PROPERTY_TABLE(MACRO) \
418 DEBUG_ONLY_TABLE(MACRO) 414 DEBUG_ONLY_TABLE(MACRO)
419 415
420 private: 416 private:
421 enum PropertyIndices { 417 enum PropertyIndices {
422 #define INDICES(IGNORE1, IGNORE2, NAME) kID_##NAME, 418 #define INDICES(IGNORE1, IGNORE2, NAME) kID_##NAME,
423 WCM_PROPERTY_TABLE(INDICES) Count 419 WCM_PROPERTY_TABLE(INDICES) Count
424 #undef INDICES 420 #undef INDICES
425 }; 421 };
426 422
427 public: 423 public:
428 static Handle<WasmCompiledModule> New(Isolate* isolate, 424 static Handle<WasmCompiledModule> New(Isolate* isolate,
429 uint32_t min_memory_pages, 425 uint32_t min_memory_pages,
430 uint32_t globals_size, 426 uint32_t globals_size,
427 bool export_memory,
431 ModuleOrigin origin); 428 ModuleOrigin origin);
432 429
433 static Handle<WasmCompiledModule> Clone(Isolate* isolate, 430 static Handle<WasmCompiledModule> Clone(Isolate* isolate,
434 Handle<WasmCompiledModule> module) { 431 Handle<WasmCompiledModule> module) {
435 Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast( 432 Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast(
436 isolate->factory()->CopyFixedArray(module)); 433 isolate->factory()->CopyFixedArray(module));
437 ret->Init(); 434 ret->Init();
438 ret->reset_weak_owning_instance(); 435 ret->reset_weak_owning_instance();
439 ret->reset_weak_next_instance(); 436 ret->reset_weak_next_instance();
440 ret->reset_weak_prev_instance(); 437 ret->reset_weak_prev_instance();
441 return ret; 438 return ret;
442 } 439 }
443 440
444 uint32_t mem_size() const { 441 uint32_t mem_size() const {
445 DCHECK(has_heap()); 442 DCHECK(has_heap());
446 return heap()->byte_length()->Number(); 443 return heap()->byte_length()->Number();
447 } 444 }
448 445
449 uint32_t default_mem_size() const { 446 uint32_t default_mem_size() const {
450 return min_memory_pages() * WasmModule::kPageSize; 447 return min_memory_pages() * WasmModule::kPageSize;
451 } 448 }
452 449
453 #define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME) 450 #define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME)
454 WCM_PROPERTY_TABLE(DECLARATION) 451 WCM_PROPERTY_TABLE(DECLARATION)
455 #undef DECLARATION 452 #undef DECLARATION
456 453
457 void PrintInstancesChain(); 454 void PrintInstancesChain();
458 455
459 private: 456 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 int instance_count); 545 int instance_count);
546 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); 546 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj);
547 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); 547 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance);
548 548
549 } // namespace testing 549 } // namespace testing
550 } // namespace wasm 550 } // namespace wasm
551 } // namespace internal 551 } // namespace internal
552 } // namespace v8 552 } // namespace v8
553 553
554 #endif // V8_WASM_MODULE_H_ 554 #endif // V8_WASM_MODULE_H_
OLDNEW
« no previous file with comments | « src/wasm/module-decoder.cc ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698