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

Side by Side Diff: src/wasm/encoder.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 | « no previous file | src/wasm/module-decoder.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 #include "src/signature.h" 5 #include "src/signature.h"
6 6
7 #include "src/handles.h" 7 #include "src/handles.h"
8 #include "src/v8.h" 8 #include "src/v8.h"
9 #include "src/zone-containers.h" 9 #include "src/zone-containers.h"
10 10
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 size = size >> 7; 454 size = size >> 7;
455 } 455 }
456 } 456 }
457 } 457 }
458 }; 458 };
459 459
460 460
461 WasmModuleIndex* WasmModuleWriter::WriteTo(Zone* zone) const { 461 WasmModuleIndex* WasmModuleWriter::WriteTo(Zone* zone) const {
462 Sizes sizes = {0, 0}; 462 Sizes sizes = {0, 0};
463 463
464 sizes.Add(2 * sizeof(uint32_t), 0); // header
465
464 sizes.Add(1, 0); 466 sizes.Add(1, 0);
465 sizes.Add(kDeclMemorySize, 0); 467 sizes.Add(kDeclMemorySize, 0);
466 468
467 sizes.AddSection(signatures_.size()); 469 sizes.AddSection(signatures_.size());
468 for (auto sig : signatures_) { 470 for (auto sig : signatures_) {
469 sizes.Add(2 + sig->parameter_count(), 0); 471 sizes.Add(2 + sig->parameter_count(), 0);
470 } 472 }
471 473
472 sizes.AddSection(globals_.size()); 474 sizes.AddSection(globals_.size());
473 if (globals_.size() > 0) { 475 if (globals_.size() > 0) {
(...skipping 14 matching lines...) Expand all
488 sizes.AddSection(indirect_functions_.size()); 490 sizes.AddSection(indirect_functions_.size());
489 sizes.Add(2 * static_cast<uint32_t>(indirect_functions_.size()), 0); 491 sizes.Add(2 * static_cast<uint32_t>(indirect_functions_.size()), 0);
490 492
491 if (sizes.body_size > 0) sizes.Add(1, 0); 493 if (sizes.body_size > 0) sizes.Add(1, 0);
492 494
493 ZoneVector<uint8_t> buffer_vector(sizes.total(), zone); 495 ZoneVector<uint8_t> buffer_vector(sizes.total(), zone);
494 byte* buffer = &buffer_vector[0]; 496 byte* buffer = &buffer_vector[0];
495 byte* header = buffer; 497 byte* header = buffer;
496 byte* body = buffer + sizes.header_size; 498 byte* body = buffer + sizes.header_size;
497 499
500 // -- emit magic -------------------------------------------------------------
501 EmitUint32(&header, kWasmMagic);
502 EmitUint32(&header, kWasmVersion);
503
498 // -- emit memory declaration ------------------------------------------------ 504 // -- emit memory declaration ------------------------------------------------
499 EmitUint8(&header, kDeclMemory); 505 EmitUint8(&header, kDeclMemory);
500 EmitUint8(&header, 16); // min memory size 506 EmitUint8(&header, 16); // min memory size
501 EmitUint8(&header, 16); // max memory size 507 EmitUint8(&header, 16); // max memory size
502 EmitUint8(&header, 0); // memory export 508 EmitUint8(&header, 0); // memory export
503 509
504 // -- emit globals ----------------------------------------------------------- 510 // -- emit globals -----------------------------------------------------------
505 if (globals_.size() > 0) { 511 if (globals_.size() > 0) {
506 EmitUint8(&header, kDeclGlobals); 512 EmitUint8(&header, kDeclGlobals);
507 EmitVarInt(&header, globals_.size()); 513 EmitVarInt(&header, globals_.size());
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 next = next | 0x80; 583 next = next | 0x80;
578 } 584 }
579 output.push_back(next); 585 output.push_back(next);
580 shift += 7; 586 shift += 7;
581 } while ((next & 0x80) != 0); 587 } while ((next & 0x80) != 0);
582 return output; 588 return output;
583 } 589 }
584 } // namespace wasm 590 } // namespace wasm
585 } // namespace internal 591 } // namespace internal
586 } // namespace v8 592 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/wasm/module-decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698