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

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

Issue 2094573002: [wasm] Cleaning up code (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 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/ast-decoder.cc ('k') | 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 80
81 void WasmFunctionBuilder::EmitGetLocal(uint32_t local_index) { 81 void WasmFunctionBuilder::EmitGetLocal(uint32_t local_index) {
82 EmitWithVarInt(kExprGetLocal, local_index); 82 EmitWithVarInt(kExprGetLocal, local_index);
83 } 83 }
84 84
85 void WasmFunctionBuilder::EmitSetLocal(uint32_t local_index) { 85 void WasmFunctionBuilder::EmitSetLocal(uint32_t local_index) {
86 EmitWithVarInt(kExprSetLocal, local_index); 86 EmitWithVarInt(kExprSetLocal, local_index);
87 } 87 }
88 88
89 void WasmFunctionBuilder::EmitCode(const byte* code, uint32_t code_size) { 89 void WasmFunctionBuilder::EmitCode(const byte* code, uint32_t code_size) {
90 for (size_t i = 0; i < code_size; i++) { 90 for (size_t i = 0; i < code_size; ++i) {
91 body_.push_back(code[i]); 91 body_.push_back(code[i]);
92 } 92 }
93 } 93 }
94 94
95 void WasmFunctionBuilder::Emit(WasmOpcode opcode) { 95 void WasmFunctionBuilder::Emit(WasmOpcode opcode) {
96 body_.push_back(static_cast<byte>(opcode)); 96 body_.push_back(static_cast<byte>(opcode));
97 } 97 }
98 98
99 void WasmFunctionBuilder::EmitWithU8(WasmOpcode opcode, const byte immediate) { 99 void WasmFunctionBuilder::EmitWithU8(WasmOpcode opcode, const byte immediate) {
100 body_.push_back(static_cast<byte>(opcode)); 100 body_.push_back(static_cast<byte>(opcode));
(...skipping 21 matching lines...) Expand all
122 byte code[] = {WASM_I32V_5(value)}; 122 byte code[] = {WASM_I32V_5(value)};
123 EmitCode(code, sizeof(code)); 123 EmitCode(code, sizeof(code));
124 } 124 }
125 } 125 }
126 126
127 void WasmFunctionBuilder::SetExported() { exported_ = true; } 127 void WasmFunctionBuilder::SetExported() { exported_ = true; }
128 128
129 void WasmFunctionBuilder::SetName(const char* name, int name_length) { 129 void WasmFunctionBuilder::SetName(const char* name, int name_length) {
130 name_.clear(); 130 name_.clear();
131 if (name_length > 0) { 131 if (name_length > 0) {
132 for (int i = 0; i < name_length; i++) { 132 for (int i = 0; i < name_length; ++i) {
133 name_.push_back(*(name + i)); 133 name_.push_back(*(name + i));
134 } 134 }
135 } 135 }
136 } 136 }
137 137
138 void WasmFunctionBuilder::WriteSignature(ZoneBuffer& buffer) const { 138 void WasmFunctionBuilder::WriteSignature(ZoneBuffer& buffer) const {
139 buffer.write_u32v(signature_index_); 139 buffer.write_u32v(signature_index_);
140 } 140 }
141 141
142 void WasmFunctionBuilder::WriteExport(ZoneBuffer& buffer, 142 void WasmFunctionBuilder::WriteExport(ZoneBuffer& buffer,
(...skipping 15 matching lines...) Expand all
158 locals_.Emit(*ptr); 158 locals_.Emit(*ptr);
159 (*ptr) += locals_size; // UGLY: manual bump of position pointer 159 (*ptr) += locals_size; // UGLY: manual bump of position pointer
160 if (body_.size() > 0) { 160 if (body_.size() > 0) {
161 buffer.write(&body_[0], body_.size()); 161 buffer.write(&body_[0], body_.size());
162 } 162 }
163 } 163 }
164 164
165 WasmDataSegmentEncoder::WasmDataSegmentEncoder(Zone* zone, const byte* data, 165 WasmDataSegmentEncoder::WasmDataSegmentEncoder(Zone* zone, const byte* data,
166 uint32_t size, uint32_t dest) 166 uint32_t size, uint32_t dest)
167 : data_(zone), dest_(dest) { 167 : data_(zone), dest_(dest) {
168 for (size_t i = 0; i < size; i++) { 168 for (size_t i = 0; i < size; ++i) {
169 data_.push_back(data[i]); 169 data_.push_back(data[i]);
170 } 170 }
171 } 171 }
172 172
173 void WasmDataSegmentEncoder::Write(ZoneBuffer& buffer) const { 173 void WasmDataSegmentEncoder::Write(ZoneBuffer& buffer) const {
174 buffer.write_u32v(dest_); 174 buffer.write_u32v(dest_);
175 buffer.write_u32v(static_cast<uint32_t>(data_.size())); 175 buffer.write_u32v(static_cast<uint32_t>(data_.size()));
176 buffer.write(&data_[0], data_.size()); 176 buffer.write(&data_[0], data_.size());
177 } 177 }
178 178
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 373
374 for (auto segment : data_segments_) { 374 for (auto segment : data_segments_) {
375 segment->Write(buffer); 375 segment->Write(buffer);
376 } 376 }
377 FixupSection(buffer, start); 377 FixupSection(buffer, start);
378 } 378 }
379 } 379 }
380 } // namespace wasm 380 } // namespace wasm
381 } // namespace internal 381 } // namespace internal
382 } // namespace v8 382 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/ast-decoder.cc ('k') | src/wasm/module-decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698