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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 module->signatures = new std::vector<FunctionSig*>(); | 53 module->signatures = new std::vector<FunctionSig*>(); |
54 module->functions = new std::vector<WasmFunction>(); | 54 module->functions = new std::vector<WasmFunction>(); |
55 module->data_segments = new std::vector<WasmDataSegment>(); | 55 module->data_segments = new std::vector<WasmDataSegment>(); |
56 module->function_table = new std::vector<uint16_t>(); | 56 module->function_table = new std::vector<uint16_t>(); |
57 module->import_table = new std::vector<WasmImport>(); | 57 module->import_table = new std::vector<WasmImport>(); |
58 module->export_table = new std::vector<WasmExport>(); | 58 module->export_table = new std::vector<WasmExport>(); |
59 | 59 |
60 bool sections[kMaxModuleSectionCode]; | 60 bool sections[kMaxModuleSectionCode]; |
61 memset(sections, 0, sizeof(sections)); | 61 memset(sections, 0, sizeof(sections)); |
62 | 62 |
63 const byte* pos = pc_; | |
64 uint32_t magic_number = consume_u32("wasm magic"); | |
65 if (magic_number != kWasmMagic) { | |
66 error(pos, pos, "expected magic bytes 0 a s m"); | |
JF
2016/02/27 19:43:04
"0 a s m" will be incorrect if we change kWasmMagi
titzer
2016/02/27 23:05:09
Done.
| |
67 return toResult(module); | |
68 } | |
69 | |
70 pos = pc_; | |
71 uint32_t magic_version = consume_u32("wasm version"); | |
72 if (magic_version != kWasmVersion) { | |
73 error(pos, pos, "expected version %02x %02x %02x %02x", | |
74 (kWasmVersion & 0xff), (kWasmVersion >> 8) & 0xff, | |
75 (kWasmVersion >> 16) & 0xff, (kWasmVersion >> 24) & 0xff); | |
JF
2016/02/27 19:43:04
Same here, print magic_version.
titzer
2016/02/27 23:05:09
Done.
| |
76 return toResult(module); | |
77 } | |
78 | |
63 // Decode the module sections. | 79 // Decode the module sections. |
64 while (pc_ < limit_) { | 80 while (pc_ < limit_) { |
65 TRACE("DecodeSection\n"); | 81 TRACE("DecodeSection\n"); |
66 WasmSectionDeclCode section = | 82 WasmSectionDeclCode section = |
67 static_cast<WasmSectionDeclCode>(consume_u8("section")); | 83 static_cast<WasmSectionDeclCode>(consume_u8("section")); |
68 // Each section should appear at most once. | 84 // Each section should appear at most once. |
69 if (section < kMaxModuleSectionCode) { | 85 if (section < kMaxModuleSectionCode) { |
70 CheckForPreviousSection(sections, section, false); | 86 CheckForPreviousSection(sections, section, false); |
71 sections[section] = true; | 87 sections[section] = true; |
72 } | 88 } |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
636 if (function_start > function_end) return FunctionError("start > end"); | 652 if (function_start > function_end) return FunctionError("start > end"); |
637 if (size > kMaxFunctionSize) | 653 if (size > kMaxFunctionSize) |
638 return FunctionError("size > maximum function size"); | 654 return FunctionError("size > maximum function size"); |
639 WasmFunction* function = new WasmFunction(); | 655 WasmFunction* function = new WasmFunction(); |
640 ModuleDecoder decoder(zone, function_start, function_end, false); | 656 ModuleDecoder decoder(zone, function_start, function_end, false); |
641 return decoder.DecodeSingleFunction(module_env, function); | 657 return decoder.DecodeSingleFunction(module_env, function); |
642 } | 658 } |
643 } // namespace wasm | 659 } // namespace wasm |
644 } // namespace internal | 660 } // namespace internal |
645 } // namespace v8 | 661 } // namespace v8 |
OLD | NEW |