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

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

Issue 1763433002: [wasm] Rework encoding of local declarations. (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.h ('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
11 #include "src/wasm/ast-decoder.h" 11 #include "src/wasm/ast-decoder.h"
12 #include "src/wasm/encoder.h" 12 #include "src/wasm/encoder.h"
13 #include "src/wasm/wasm-macro-gen.h"
13 #include "src/wasm/wasm-module.h" 14 #include "src/wasm/wasm-module.h"
14 #include "src/wasm/wasm-opcodes.h" 15 #include "src/wasm/wasm-opcodes.h"
15 16
16 #include "src/v8memory.h" 17 #include "src/v8memory.h"
17 18
18 namespace v8 { 19 namespace v8 {
19 namespace internal { 20 namespace internal {
20 namespace wasm { 21 namespace wasm {
21 22
22 /*TODO: add error cases for adding too many locals, too many functions and bad 23 /*TODO: add error cases for adding too many locals, too many functions and bad
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 bool exported, bool external) 244 bool exported, bool external)
244 : params_(zone), 245 : params_(zone),
245 exported_(exported), 246 exported_(exported),
246 external_(external), 247 external_(external),
247 body_(zone), 248 body_(zone),
248 name_(zone) {} 249 name_(zone) {}
249 250
250 251
251 uint32_t WasmFunctionEncoder::HeaderSize() const { 252 uint32_t WasmFunctionEncoder::HeaderSize() const {
252 uint32_t size = 3; 253 uint32_t size = 3;
253 if (HasLocals()) size += 8;
254 if (!external_) size += 2; 254 if (!external_) size += 2;
255 if (HasName()) size += 4; 255 if (HasName()) size += 4;
256 return size; 256 return size;
257 } 257 }
258 258
259 259
260 uint32_t WasmFunctionEncoder::BodySize(void) const { 260 uint32_t WasmFunctionEncoder::BodySize(void) const {
261 return external_ ? 0 : static_cast<uint32_t>(body_.size()); 261 // TODO(titzer): embed a LocalDeclEncoder in the WasmFunctionEncoder
262 LocalDeclEncoder local_decl;
263 local_decl.AddLocals(local_i32_count_, kAstI32);
264 local_decl.AddLocals(local_i64_count_, kAstI64);
265 local_decl.AddLocals(local_f32_count_, kAstF32);
266 local_decl.AddLocals(local_f64_count_, kAstF64);
267
268 return external_ ? 0
269 : static_cast<uint32_t>(body_.size() + local_decl.Size());
262 } 270 }
263 271
264 272
265 uint32_t WasmFunctionEncoder::NameSize() const { 273 uint32_t WasmFunctionEncoder::NameSize() const {
266 return HasName() ? static_cast<uint32_t>(name_.size()) : 0; 274 return HasName() ? static_cast<uint32_t>(name_.size()) : 0;
267 } 275 }
268 276
269 277
270 void WasmFunctionEncoder::Serialize(byte* buffer, byte** header, 278 void WasmFunctionEncoder::Serialize(byte* buffer, byte** header,
271 byte** body) const { 279 byte** body) const {
272 uint8_t decl_bits = (exported_ ? kDeclFunctionExport : 0) | 280 uint8_t decl_bits = (exported_ ? kDeclFunctionExport : 0) |
273 (external_ ? kDeclFunctionImport : 0) | 281 (external_ ? kDeclFunctionImport : 0) |
274 (HasLocals() ? kDeclFunctionLocals : 0) |
275 (HasName() ? kDeclFunctionName : 0); 282 (HasName() ? kDeclFunctionName : 0);
276 283
277 EmitUint8(header, decl_bits); 284 EmitUint8(header, decl_bits);
278 EmitUint16(header, signature_index_); 285 EmitUint16(header, signature_index_);
279 286
280 if (HasName()) { 287 if (HasName()) {
281 uint32_t name_offset = static_cast<uint32_t>(*body - buffer); 288 uint32_t name_offset = static_cast<uint32_t>(*body - buffer);
282 EmitUint32(header, name_offset); 289 EmitUint32(header, name_offset);
283 std::memcpy(*body, &name_[0], name_.size()); 290 std::memcpy(*body, &name_[0], name_.size());
284 (*body) += name_.size(); 291 (*body) += name_.size();
285 } 292 }
286 293
287 if (HasLocals()) {
288 EmitUint16(header, local_i32_count_);
289 EmitUint16(header, local_i64_count_);
290 EmitUint16(header, local_f32_count_);
291 EmitUint16(header, local_f64_count_);
292 }
293 294
294 if (!external_) { 295 if (!external_) {
295 EmitUint16(header, static_cast<uint16_t>(body_.size())); 296 // TODO(titzer): embed a LocalDeclEncoder in the WasmFunctionEncoder
297 LocalDeclEncoder local_decl;
298 local_decl.AddLocals(local_i32_count_, kAstI32);
299 local_decl.AddLocals(local_i64_count_, kAstI64);
300 local_decl.AddLocals(local_f32_count_, kAstF32);
301 local_decl.AddLocals(local_f64_count_, kAstF64);
302
303 EmitUint16(header, static_cast<uint16_t>(body_.size() + local_decl.Size()));
304 (*header) += local_decl.Emit(*header);
296 if (body_.size() > 0) { 305 if (body_.size() > 0) {
297 std::memcpy(*header, &body_[0], body_.size()); 306 std::memcpy(*header, &body_[0], body_.size());
298 (*header) += body_.size(); 307 (*header) += body_.size();
299 } 308 }
300 } 309 }
301 } 310 }
302 311
303 312
304 WasmDataSegmentEncoder::WasmDataSegmentEncoder(Zone* zone, const byte* data, 313 WasmDataSegmentEncoder::WasmDataSegmentEncoder(Zone* zone, const byte* data,
305 uint32_t size, uint32_t dest) 314 uint32_t size, uint32_t dest)
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 next = next | 0x80; 611 next = next | 0x80;
603 } 612 }
604 output.push_back(next); 613 output.push_back(next);
605 shift += 7; 614 shift += 7;
606 } while ((next & 0x80) != 0); 615 } while ((next & 0x80) != 0);
607 return output; 616 return output;
608 } 617 }
609 } // namespace wasm 618 } // namespace wasm
610 } // namespace internal 619 } // namespace internal
611 } // namespace v8 620 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/encoder.h ('k') | src/wasm/module-decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698