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

Side by Side Diff: src/wasm/module-decoder.cc

Issue 1740373002: [wasm] Add a magic word and a version number to the binary. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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/encoder.cc ('k') | src/wasm/wasm-macro-gen.h » ('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 #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
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
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
OLDNEW
« no previous file with comments | « src/wasm/encoder.cc ('k') | src/wasm/wasm-macro-gen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698