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

Side by Side Diff: src/wasm/encoder.cc

Issue 1896863003: [wasm] Binary 11: Module changes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 val = next; 73 val = next;
74 } else { 74 } else {
75 *(start++) = out; 75 *(start++) = out;
76 // TODO(jfb) check that the pre-allocated fixup size isn't overflowed. 76 // TODO(jfb) check that the pre-allocated fixup size isn't overflowed.
77 } 77 }
78 } 78 }
79 } 79 }
80 80
81 // Returns the start of the section, where the section VarInt size is. 81 // Returns the start of the section, where the section VarInt size is.
82 byte* EmitSection(WasmSection::Code code, byte** b) { 82 byte* EmitSection(WasmSection::Code code, byte** b) {
83 // Emit a placeholder for the length.
84 byte* start = *b;
85 for (size_t padding = 0; padding != kPaddedVarintSize; ++padding) {
86 EmitUint8(b, 0xff); // Will get fixed up later.
87 }
88 // Emit the section name. 83 // Emit the section name.
89 const char* name = WasmSection::getName(code); 84 const char* name = WasmSection::getName(code);
90 TRACE("emit section: %s\n", name); 85 TRACE("emit section: %s\n", name);
91 size_t length = WasmSection::getNameLength(code); 86 size_t length = WasmSection::getNameLength(code);
92 EmitVarInt(b, length); // Section name string size. 87 EmitVarInt(b, length); // Section name string size.
93 for (size_t i = 0; i != length; ++i) EmitUint8(b, name[i]); 88 for (size_t i = 0; i != length; ++i) EmitUint8(b, name[i]);
94 89
90 // Emit a placeholder for the length.
91 byte* start = *b;
92 for (size_t padding = 0; padding != kPaddedVarintSize; ++padding) {
93 EmitUint8(b, 0xff); // Will get fixed up later.
94 }
95
95 return start; 96 return start;
96 } 97 }
97 } // namespace 98 } // namespace
98 99
99 struct WasmFunctionBuilder::Type { 100 struct WasmFunctionBuilder::Type {
100 bool param_; 101 bool param_;
101 LocalType type_; 102 LocalType type_;
102 }; 103 };
103 104
104 105
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 /* These globals never have names, so are always 3 bytes. */ 580 /* These globals never have names, so are always 3 bytes. */
580 sizes.Add(3 * globals_.size(), 0); 581 sizes.Add(3 * globals_.size(), 0);
581 TRACE("Size after globals: %u, %u\n", (unsigned)sizes.header_size, 582 TRACE("Size after globals: %u, %u\n", (unsigned)sizes.header_size,
582 (unsigned)sizes.body_size); 583 (unsigned)sizes.body_size);
583 } 584 }
584 585
585 if (signatures_.size() > 0) { 586 if (signatures_.size() > 0) {
586 sizes.AddSection(WasmSection::Code::Signatures, signatures_.size()); 587 sizes.AddSection(WasmSection::Code::Signatures, signatures_.size());
587 for (auto sig : signatures_) { 588 for (auto sig : signatures_) {
588 sizes.Add(1 + LEBHelper::sizeof_u32v(sig->parameter_count()) + 589 sizes.Add(1 + LEBHelper::sizeof_u32v(sig->parameter_count()) +
589 sig->parameter_count(), 590 sig->parameter_count() +
591 LEBHelper::sizeof_u32v(sig->return_count()) +
592 sig->return_count(),
590 0); 593 0);
591 } 594 }
592 TRACE("Size after signatures: %u, %u\n", (unsigned)sizes.header_size, 595 TRACE("Size after signatures: %u, %u\n", (unsigned)sizes.header_size,
593 (unsigned)sizes.body_size); 596 (unsigned)sizes.body_size);
594 } 597 }
595 598
596 if (functions_.size() > 0) { 599 if (functions_.size() > 0) {
597 sizes.AddSection(WasmSection::Code::Functions, functions_.size()); 600 sizes.AddSection(WasmSection::Code::OldFunctions, functions_.size());
598 for (auto function : functions_) { 601 for (auto function : functions_) {
599 sizes.Add(function->HeaderSize() + function->BodySize(), 602 sizes.Add(function->HeaderSize() + function->BodySize(),
600 function->NameSize()); 603 function->NameSize());
601 } 604 }
602 TRACE("Size after functions: %u, %u\n", (unsigned)sizes.header_size, 605 TRACE("Size after functions: %u, %u\n", (unsigned)sizes.header_size,
603 (unsigned)sizes.body_size); 606 (unsigned)sizes.body_size);
604 } 607 }
605 608
606 if (indirect_functions_.size() > 0) { 609 if (indirect_functions_.size() > 0) {
607 sizes.AddSection(WasmSection::Code::FunctionTable, 610 sizes.AddSection(WasmSection::Code::FunctionTable,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 } 665 }
663 FixupSection(section, header); 666 FixupSection(section, header);
664 } 667 }
665 668
666 // -- emit signatures -------------------------------------------------------- 669 // -- emit signatures --------------------------------------------------------
667 if (signatures_.size() > 0) { 670 if (signatures_.size() > 0) {
668 byte* section = EmitSection(WasmSection::Code::Signatures, &header); 671 byte* section = EmitSection(WasmSection::Code::Signatures, &header);
669 EmitVarInt(&header, signatures_.size()); 672 EmitVarInt(&header, signatures_.size());
670 673
671 for (FunctionSig* sig : signatures_) { 674 for (FunctionSig* sig : signatures_) {
675 EmitUint8(&header, kWasmFunctionTypeForm);
672 EmitVarInt(&header, sig->parameter_count()); 676 EmitVarInt(&header, sig->parameter_count());
673 if (sig->return_count() > 0) {
674 EmitUint8(&header, WasmOpcodes::LocalTypeCodeFor(sig->GetReturn()));
675 } else {
676 EmitUint8(&header, kLocalVoid);
677 }
678 for (size_t j = 0; j < sig->parameter_count(); j++) { 677 for (size_t j = 0; j < sig->parameter_count(); j++) {
679 EmitUint8(&header, WasmOpcodes::LocalTypeCodeFor(sig->GetParam(j))); 678 EmitUint8(&header, WasmOpcodes::LocalTypeCodeFor(sig->GetParam(j)));
680 } 679 }
680 EmitVarInt(&header, sig->return_count());
681 for (size_t j = 0; j < sig->return_count(); j++) {
682 EmitUint8(&header, WasmOpcodes::LocalTypeCodeFor(sig->GetReturn(j)));
683 }
681 } 684 }
682 FixupSection(section, header); 685 FixupSection(section, header);
683 } 686 }
684 687
685 // -- emit functions --------------------------------------------------------- 688 // -- emit functions ---------------------------------------------------------
686 if (functions_.size() > 0) { 689 if (functions_.size() > 0) {
687 byte* section = EmitSection(WasmSection::Code::Functions, &header); 690 byte* section = EmitSection(WasmSection::Code::OldFunctions, &header);
688 EmitVarInt(&header, functions_.size()); 691 EmitVarInt(&header, functions_.size());
689 692
690 for (auto func : functions_) { 693 for (auto func : functions_) {
691 func->Serialize(buffer, &header, &body); 694 func->Serialize(buffer, &header, &body);
692 } 695 }
693 FixupSection(section, header); 696 FixupSection(section, header);
694 } 697 }
695 698
696 // -- emit function table ---------------------------------------------------- 699 // -- emit function table ----------------------------------------------------
697 if (indirect_functions_.size() > 0) { 700 if (indirect_functions_.size() > 0) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 if (sizes.body_size > 0) { 738 if (sizes.body_size > 0) {
736 byte* section = EmitSection(WasmSection::Code::End, &header); 739 byte* section = EmitSection(WasmSection::Code::End, &header);
737 FixupSection(section, header); 740 FixupSection(section, header);
738 } 741 }
739 742
740 return new (zone) WasmModuleIndex(buffer, buffer + sizes.total()); 743 return new (zone) WasmModuleIndex(buffer, buffer + sizes.total());
741 } 744 }
742 } // namespace wasm 745 } // namespace wasm
743 } // namespace internal 746 } // namespace internal
744 } // namespace v8 747 } // 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