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

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

Issue 1574263002: [wasm] Fix empty asm.js function in ASM->WASM. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 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 | test/mjsunit/wasm/asm-wasm.js » ('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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 void WasmFunctionBuilder::Exported(uint8_t flag) { exported_ = flag; } 150 void WasmFunctionBuilder::Exported(uint8_t flag) { exported_ = flag; }
151 151
152 152
153 void WasmFunctionBuilder::External(uint8_t flag) { external_ = flag; } 153 void WasmFunctionBuilder::External(uint8_t flag) { external_ = flag; }
154 154
155 155
156 WasmFunctionEncoder* WasmFunctionBuilder::Build(Zone* zone, 156 WasmFunctionEncoder* WasmFunctionBuilder::Build(Zone* zone,
157 WasmModuleBuilder* mb) const { 157 WasmModuleBuilder* mb) const {
158 WasmFunctionEncoder* e = 158 WasmFunctionEncoder* e =
159 new (zone) WasmFunctionEncoder(zone, return_type_, exported_, external_); 159 new (zone) WasmFunctionEncoder(zone, return_type_, exported_, external_);
160 auto var_index = new uint16_t[locals_.size()]; 160 uint16_t* var_index = zone->NewArray<uint16_t>(locals_.size());
161 IndexVars(e, var_index); 161 IndexVars(e, var_index);
162 const byte* start = &body_[0]; 162 if (body_.size() > 0) {
163 const byte* end = start + body_.size(); 163 // TODO(titzer): iterate over local indexes, not the bytes.
164 size_t local_index = 0; 164 const byte* start = &body_[0];
165 for (size_t i = 0; i < body_.size();) { 165 const byte* end = start + body_.size();
166 if (local_index < local_indices_.size() && 166 size_t local_index = 0;
167 i == local_indices_[local_index]) { 167 for (size_t i = 0; i < body_.size();) {
168 int length = 0; 168 if (local_index < local_indices_.size() &&
169 uint32_t index; 169 i == local_indices_[local_index]) {
170 ReadUnsignedLEB128Operand(start + i, end, &length, &index); 170 int length = 0;
171 uint16_t new_index = var_index[index]; 171 uint32_t index;
172 const std::vector<uint8_t>& index_vec = UnsignedLEB128From(new_index); 172 ReadUnsignedLEB128Operand(start + i, end, &length, &index);
173 for (size_t j = 0; j < index_vec.size(); j++) { 173 uint16_t new_index = var_index[index];
174 e->body_.push_back(index_vec.at(j)); 174 const std::vector<uint8_t>& index_vec = UnsignedLEB128From(new_index);
175 for (size_t j = 0; j < index_vec.size(); j++) {
176 e->body_.push_back(index_vec.at(j));
177 }
178 i += length;
179 local_index++;
180 } else {
181 e->body_.push_back(*(start + i));
182 i++;
175 } 183 }
176 i += length;
177 local_index++;
178 } else {
179 e->body_.push_back(*(start + i));
180 i++;
181 } 184 }
182 } 185 }
183 FunctionSig::Builder sig(zone, return_type_ == kAstStmt ? 0 : 1, 186 FunctionSig::Builder sig(zone, return_type_ == kAstStmt ? 0 : 1,
184 e->params_.size()); 187 e->params_.size());
185 if (return_type_ != kAstStmt) { 188 if (return_type_ != kAstStmt) {
186 sig.AddReturn(static_cast<LocalType>(return_type_)); 189 sig.AddReturn(static_cast<LocalType>(return_type_));
187 } 190 }
188 for (size_t i = 0; i < e->params_.size(); i++) { 191 for (size_t i = 0; i < e->params_.size(); i++) {
189 sig.AddParam(static_cast<LocalType>(e->params_[i])); 192 sig.AddParam(static_cast<LocalType>(e->params_[i]));
190 } 193 }
191 e->signature_index_ = mb->AddSignature(sig.Build()); 194 e->signature_index_ = mb->AddSignature(sig.Build());
192 delete[] var_index;
193 e->name_.insert(e->name_.begin(), name_.begin(), name_.end()); 195 e->name_.insert(e->name_.begin(), name_.begin(), name_.end());
194 return e; 196 return e;
195 } 197 }
196 198
197 199
198 void WasmFunctionBuilder::IndexVars(WasmFunctionEncoder* e, 200 void WasmFunctionBuilder::IndexVars(WasmFunctionEncoder* e,
199 uint16_t* var_index) const { 201 uint16_t* var_index) const {
200 uint16_t param = 0; 202 uint16_t param = 0;
201 uint16_t int32 = 0; 203 uint16_t int32 = 0;
202 uint16_t int64 = 0; 204 uint16_t int64 = 0;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 290
289 if (HasLocals()) { 291 if (HasLocals()) {
290 EmitUint16(header, local_int32_count_); 292 EmitUint16(header, local_int32_count_);
291 EmitUint16(header, local_int64_count_); 293 EmitUint16(header, local_int64_count_);
292 EmitUint16(header, local_float32_count_); 294 EmitUint16(header, local_float32_count_);
293 EmitUint16(header, local_float64_count_); 295 EmitUint16(header, local_float64_count_);
294 } 296 }
295 297
296 if (!external_) { 298 if (!external_) {
297 EmitUint16(header, static_cast<uint16_t>(body_.size())); 299 EmitUint16(header, static_cast<uint16_t>(body_.size()));
298 std::memcpy(*header, &body_[0], body_.size()); 300 if (body_.size() > 0) {
299 (*header) += body_.size(); 301 std::memcpy(*header, &body_[0], body_.size());
302 (*header) += body_.size();
303 }
300 } 304 }
301 } 305 }
302 306
303 307
304 WasmDataSegmentEncoder::WasmDataSegmentEncoder(Zone* zone, const byte* data, 308 WasmDataSegmentEncoder::WasmDataSegmentEncoder(Zone* zone, const byte* data,
305 uint32_t size, uint32_t dest) 309 uint32_t size, uint32_t dest)
306 : data_(zone), dest_(dest) { 310 : data_(zone), dest_(dest) {
307 for (size_t i = 0; i < size; i++) { 311 for (size_t i = 0; i < size; i++) {
308 data_.push_back(data[i]); 312 data_.push_back(data[i]);
309 } 313 }
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 next = next | 0x80; 583 next = next | 0x80;
580 } 584 }
581 output.push_back(next); 585 output.push_back(next);
582 shift += 7; 586 shift += 7;
583 } while ((next & 0x80) != 0); 587 } while ((next & 0x80) != 0);
584 return output; 588 return output;
585 } 589 }
586 } // namespace wasm 590 } // namespace wasm
587 } // namespace internal 591 } // namespace internal
588 } // namespace v8 592 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/wasm/asm-wasm.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698