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/wasm/module-decoder.h" | 5 #include "src/wasm/module-decoder.h" |
6 | 6 |
7 #include "src/base/functional.h" | 7 #include "src/base/functional.h" |
8 #include "src/base/platform/platform.h" | 8 #include "src/base/platform/platform.h" |
9 #include "src/flags.h" | 9 #include "src/flags.h" |
10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 &table->max_size); | 317 &table->max_size); |
318 break; | 318 break; |
319 } | 319 } |
320 case kExternalMemory: { | 320 case kExternalMemory: { |
321 // ===== Imported memory ========================================= | 321 // ===== Imported memory ========================================= |
322 bool has_max = false; | 322 bool has_max = false; |
323 consume_resizable_limits("memory", "pages", kV8MaxWasmMemoryPages, | 323 consume_resizable_limits("memory", "pages", kV8MaxWasmMemoryPages, |
324 &module->min_mem_pages, &has_max, | 324 &module->min_mem_pages, &has_max, |
325 kSpecMaxWasmMemoryPages, | 325 kSpecMaxWasmMemoryPages, |
326 &module->max_mem_pages); | 326 &module->max_mem_pages); |
327 if (module->has_memory) { | 327 SetHasMemory(module); |
328 error("At most one memory object is supported"); | |
329 } else { | |
330 module->has_memory = true; | |
331 } | |
332 break; | 328 break; |
333 } | 329 } |
334 case kExternalGlobal: { | 330 case kExternalGlobal: { |
335 // ===== Imported global ========================================= | 331 // ===== Imported global ========================================= |
336 import->index = static_cast<uint32_t>(module->globals.size()); | 332 import->index = static_cast<uint32_t>(module->globals.size()); |
337 module->globals.push_back( | 333 module->globals.push_back( |
338 {kWasmStmt, false, WasmInitExpr(), 0, true, false}); | 334 {kWasmStmt, false, WasmInitExpr(), 0, true, false}); |
339 WasmGlobal* global = &module->globals.back(); | 335 WasmGlobal* global = &module->globals.back(); |
340 global->type = consume_value_type(); | 336 global->type = consume_value_type(); |
341 global->mutability = consume_u8("mutability") != 0; | 337 global->mutability = consume_u8("mutability") != 0; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 // ===== Memory section ================================================== | 392 // ===== Memory section ================================================== |
397 if (section_iter.section_code() == kMemorySectionCode) { | 393 if (section_iter.section_code() == kMemorySectionCode) { |
398 uint32_t memory_count = consume_count("memory count", kV8MaxWasmMemories); | 394 uint32_t memory_count = consume_count("memory count", kV8MaxWasmMemories); |
399 | 395 |
400 for (uint32_t i = 0; ok() && i < memory_count; i++) { | 396 for (uint32_t i = 0; ok() && i < memory_count; i++) { |
401 bool has_max = false; | 397 bool has_max = false; |
402 consume_resizable_limits( | 398 consume_resizable_limits( |
403 "memory", "pages", kV8MaxWasmMemoryPages, &module->min_mem_pages, | 399 "memory", "pages", kV8MaxWasmMemoryPages, &module->min_mem_pages, |
404 &has_max, kSpecMaxWasmMemoryPages, &module->max_mem_pages); | 400 &has_max, kSpecMaxWasmMemoryPages, &module->max_mem_pages); |
405 } | 401 } |
406 module->has_memory = true; | 402 SetHasMemory(module); |
407 section_iter.advance(); | 403 section_iter.advance(); |
408 } | 404 } |
409 | 405 |
410 // ===== Global section ================================================== | 406 // ===== Global section ================================================== |
411 if (section_iter.section_code() == kGlobalSectionCode) { | 407 if (section_iter.section_code() == kGlobalSectionCode) { |
412 uint32_t globals_count = | 408 uint32_t globals_count = |
413 consume_count("globals count", kV8MaxWasmGlobals); | 409 consume_count("globals count", kV8MaxWasmGlobals); |
414 uint32_t imported_globals = static_cast<uint32_t>(module->globals.size()); | 410 uint32_t imported_globals = static_cast<uint32_t>(module->globals.size()); |
415 module->globals.reserve(imported_globals + globals_count); | 411 module->globals.reserve(imported_globals + globals_count); |
416 for (uint32_t i = 0; ok() && i < globals_count; ++i) { | 412 for (uint32_t i = 0; ok() && i < globals_count; ++i) { |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 return consume_init_expr(nullptr, kWasmStmt); | 673 return consume_init_expr(nullptr, kWasmStmt); |
678 } | 674 } |
679 | 675 |
680 private: | 676 private: |
681 Zone* module_zone; | 677 Zone* module_zone; |
682 ModuleResult result_; | 678 ModuleResult result_; |
683 ModuleOrigin origin_; | 679 ModuleOrigin origin_; |
684 | 680 |
685 uint32_t off(const byte* ptr) { return static_cast<uint32_t>(ptr - start_); } | 681 uint32_t off(const byte* ptr) { return static_cast<uint32_t>(ptr - start_); } |
686 | 682 |
| 683 void SetHasMemory(WasmModule* module) { |
| 684 if (module->has_memory) { |
| 685 error("At most one memory object is supported"); |
| 686 } else { |
| 687 module->has_memory = true; |
| 688 } |
| 689 } |
| 690 |
687 // Decodes a single global entry inside a module starting at {pc_}. | 691 // Decodes a single global entry inside a module starting at {pc_}. |
688 void DecodeGlobalInModule(WasmModule* module, uint32_t index, | 692 void DecodeGlobalInModule(WasmModule* module, uint32_t index, |
689 WasmGlobal* global) { | 693 WasmGlobal* global) { |
690 global->type = consume_value_type(); | 694 global->type = consume_value_type(); |
691 global->mutability = consume_u8("mutability") != 0; | 695 global->mutability = consume_u8("mutability") != 0; |
692 const byte* pos = pc(); | 696 const byte* pos = pc(); |
693 global->init = consume_init_expr(module, kWasmStmt); | 697 global->init = consume_init_expr(module, kWasmStmt); |
694 switch (global->init.kind) { | 698 switch (global->init.kind) { |
695 case WasmInitExpr::kGlobalIndex: { | 699 case WasmInitExpr::kGlobalIndex: { |
696 uint32_t other_index = global->init.val.global_index; | 700 uint32_t other_index = global->init.val.global_index; |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 table.push_back(std::move(func_asm_offsets)); | 1235 table.push_back(std::move(func_asm_offsets)); |
1232 } | 1236 } |
1233 if (decoder.more()) decoder.error("unexpected additional bytes"); | 1237 if (decoder.more()) decoder.error("unexpected additional bytes"); |
1234 | 1238 |
1235 return decoder.toResult(std::move(table)); | 1239 return decoder.toResult(std::move(table)); |
1236 } | 1240 } |
1237 | 1241 |
1238 } // namespace wasm | 1242 } // namespace wasm |
1239 } // namespace internal | 1243 } // namespace internal |
1240 } // namespace v8 | 1244 } // namespace v8 |
OLD | NEW |