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/wasm/decoder.h" | 9 #include "src/wasm/decoder.h" |
10 #include "src/wasm/module-decoder.h" | 10 #include "src/wasm/module-decoder.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 module->signatures = new std::vector<FunctionSig*>(); | 54 module->signatures = new std::vector<FunctionSig*>(); |
55 module->functions = new std::vector<WasmFunction>(); | 55 module->functions = new std::vector<WasmFunction>(); |
56 module->data_segments = new std::vector<WasmDataSegment>(); | 56 module->data_segments = new std::vector<WasmDataSegment>(); |
57 module->function_table = new std::vector<uint16_t>(); | 57 module->function_table = new std::vector<uint16_t>(); |
58 module->import_table = new std::vector<WasmImport>(); | 58 module->import_table = new std::vector<WasmImport>(); |
59 module->export_table = new std::vector<WasmExport>(); | 59 module->export_table = new std::vector<WasmExport>(); |
60 | 60 |
61 bool sections[kMaxModuleSectionCode]; | 61 bool sections[kMaxModuleSectionCode]; |
62 memset(sections, 0, sizeof(sections)); | 62 memset(sections, 0, sizeof(sections)); |
63 | 63 |
| 64 const byte* pos = pc_; |
| 65 uint32_t magic_word = consume_u32("wasm magic"); |
| 66 #define BYTES(x) (x & 0xff), (x >> 8) & 0xff, (x >> 16) & 0xff, (x >> 24) & 0xff |
| 67 if (magic_word != kWasmMagic) { |
| 68 error(pos, pos, |
| 69 "expected magic word %02x %02x %02x %02x, " |
| 70 "found %02x %02x %02x %02x", |
| 71 BYTES(kWasmMagic), BYTES(magic_word)); |
| 72 return toResult(module); |
| 73 } |
| 74 |
| 75 pos = pc_; |
| 76 uint32_t magic_version = consume_u32("wasm version"); |
| 77 if (magic_version != kWasmVersion) { |
| 78 error(pos, pos, |
| 79 "expected version %02x %02x %02x %02x, " |
| 80 "found %02x %02x %02x %02x", |
| 81 BYTES(kWasmVersion), BYTES(magic_version)); |
| 82 return toResult(module); |
| 83 } |
| 84 |
64 // Decode the module sections. | 85 // Decode the module sections. |
65 while (pc_ < limit_) { | 86 while (pc_ < limit_) { |
66 TRACE("DecodeSection\n"); | 87 TRACE("DecodeSection\n"); |
67 WasmSectionDeclCode section = | 88 WasmSectionDeclCode section = |
68 static_cast<WasmSectionDeclCode>(consume_u8("section")); | 89 static_cast<WasmSectionDeclCode>(consume_u8("section")); |
69 // Each section should appear at most once. | 90 // Each section should appear at most once. |
70 if (section < kMaxModuleSectionCode) { | 91 if (section < kMaxModuleSectionCode) { |
71 CheckForPreviousSection(sections, section, false); | 92 CheckForPreviousSection(sections, section, false); |
72 sections[section] = true; | 93 sections[section] = true; |
73 } | 94 } |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 if (function_start > function_end) return FunctionError("start > end"); | 657 if (function_start > function_end) return FunctionError("start > end"); |
637 if (size > kMaxFunctionSize) | 658 if (size > kMaxFunctionSize) |
638 return FunctionError("size > maximum function size"); | 659 return FunctionError("size > maximum function size"); |
639 WasmFunction* function = new WasmFunction(); | 660 WasmFunction* function = new WasmFunction(); |
640 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); | 661 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); |
641 return decoder.DecodeSingleFunction(module_env, function); | 662 return decoder.DecodeSingleFunction(module_env, function); |
642 } | 663 } |
643 } // namespace wasm | 664 } // namespace wasm |
644 } // namespace internal | 665 } // namespace internal |
645 } // namespace v8 | 666 } // namespace v8 |
OLD | NEW |