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

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

Issue 1750153002: Replace __init__ function in asm-wasm-builder with the start function section (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
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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 uint32_t body_offset = static_cast<uint32_t>(*body - buffer); 326 uint32_t body_offset = static_cast<uint32_t>(*body - buffer);
327 EmitUint32(header, dest_); 327 EmitUint32(header, dest_);
328 EmitUint32(header, body_offset); 328 EmitUint32(header, body_offset);
329 EmitUint32(header, static_cast<uint32_t>(data_.size())); 329 EmitUint32(header, static_cast<uint32_t>(data_.size()));
330 EmitUint8(header, 1); // init 330 EmitUint8(header, 1); // init
331 331
332 std::memcpy(*body, &data_[0], data_.size()); 332 std::memcpy(*body, &data_[0], data_.size());
333 (*body) += data_.size(); 333 (*body) += data_.size();
334 } 334 }
335 335
336
337 WasmModuleBuilder::WasmModuleBuilder(Zone* zone) 336 WasmModuleBuilder::WasmModuleBuilder(Zone* zone)
338 : zone_(zone), 337 : zone_(zone),
339 signatures_(zone), 338 signatures_(zone),
340 functions_(zone), 339 functions_(zone),
341 data_segments_(zone), 340 data_segments_(zone),
342 indirect_functions_(zone), 341 indirect_functions_(zone),
343 globals_(zone), 342 globals_(zone),
344 signature_map_(zone) {} 343 signature_map_(zone),
345 344 has_start_function_(false),
345 start_function_index_(0) {}
346 346
347 uint16_t WasmModuleBuilder::AddFunction() { 347 uint16_t WasmModuleBuilder::AddFunction() {
348 functions_.push_back(new (zone_) WasmFunctionBuilder(zone_)); 348 functions_.push_back(new (zone_) WasmFunctionBuilder(zone_));
349 return static_cast<uint16_t>(functions_.size() - 1); 349 return static_cast<uint16_t>(functions_.size() - 1);
350 } 350 }
351 351
352 352
353 WasmFunctionBuilder* WasmModuleBuilder::FunctionAt(size_t index) { 353 WasmFunctionBuilder* WasmModuleBuilder::FunctionAt(size_t index) {
354 if (functions_.size() > index) { 354 if (functions_.size() > index) {
355 return functions_.at(index); 355 return functions_.at(index);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 signatures_.push_back(sig); 392 signatures_.push_back(sig);
393 return index; 393 return index;
394 } 394 }
395 } 395 }
396 396
397 397
398 void WasmModuleBuilder::AddIndirectFunction(uint16_t index) { 398 void WasmModuleBuilder::AddIndirectFunction(uint16_t index) {
399 indirect_functions_.push_back(index); 399 indirect_functions_.push_back(index);
400 } 400 }
401 401
402 void WasmModuleBuilder::MarkStartFunction(uint16_t index) {
403 has_start_function_ = true;
404 start_function_index_ = index;
405 }
402 406
403 WasmModuleWriter* WasmModuleBuilder::Build(Zone* zone) { 407 WasmModuleWriter* WasmModuleBuilder::Build(Zone* zone) {
404 WasmModuleWriter* writer = new (zone) WasmModuleWriter(zone); 408 WasmModuleWriter* writer = new (zone) WasmModuleWriter(zone);
405 for (auto function : functions_) { 409 for (auto function : functions_) {
406 writer->functions_.push_back(function->Build(zone, this)); 410 writer->functions_.push_back(function->Build(zone, this));
407 } 411 }
408 for (auto segment : data_segments_) { 412 for (auto segment : data_segments_) {
409 writer->data_segments_.push_back(segment); 413 writer->data_segments_.push_back(segment);
410 } 414 }
411 for (auto sig : signatures_) { 415 for (auto sig : signatures_) {
412 writer->signatures_.push_back(sig); 416 writer->signatures_.push_back(sig);
413 } 417 }
414 for (auto index : indirect_functions_) { 418 for (auto index : indirect_functions_) {
415 writer->indirect_functions_.push_back(index); 419 writer->indirect_functions_.push_back(index);
416 } 420 }
417 for (auto global : globals_) { 421 for (auto global : globals_) {
418 writer->globals_.push_back(global); 422 writer->globals_.push_back(global);
419 } 423 }
424 writer->has_start_function_ = has_start_function_;
425 writer->start_function_index_ = start_function_index_;
420 return writer; 426 return writer;
421 } 427 }
422 428
423 429
424 uint32_t WasmModuleBuilder::AddGlobal(MachineType type, bool exported) { 430 uint32_t WasmModuleBuilder::AddGlobal(MachineType type, bool exported) {
425 globals_.push_back(std::make_pair(type, exported)); 431 globals_.push_back(std::make_pair(type, exported));
426 return static_cast<uint32_t>(globals_.size() - 1); 432 return static_cast<uint32_t>(globals_.size() - 1);
427 } 433 }
428 434
429 435
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 if (globals_.size() > 0) { 481 if (globals_.size() > 0) {
476 sizes.Add(kDeclGlobalSize * globals_.size(), 0); 482 sizes.Add(kDeclGlobalSize * globals_.size(), 0);
477 } 483 }
478 484
479 sizes.AddSection(functions_.size()); 485 sizes.AddSection(functions_.size());
480 for (auto function : functions_) { 486 for (auto function : functions_) {
481 sizes.Add(function->HeaderSize() + function->BodySize(), 487 sizes.Add(function->HeaderSize() + function->BodySize(),
482 function->NameSize()); 488 function->NameSize());
483 } 489 }
484 490
491 if (has_start_function_) {
492 sizes.Add(1, 0);
493 uint16_t size = start_function_index_;
494 do {
titzer 2016/03/01 02:09:33 Let's lift out this varint encoding into a helper
aseemgarg 2016/03/01 02:37:34 This is enclosed in AddSection for other. Just for
titzer 2016/03/01 02:43:58 At least lift it out to a helper that computes the
aseemgarg 2016/03/01 03:00:24 Done.
495 sizes.Add(1, 0);
496 size = size >> 7;
497 } while (size > 0);
498 }
499
485 sizes.AddSection(data_segments_.size()); 500 sizes.AddSection(data_segments_.size());
486 for (auto segment : data_segments_) { 501 for (auto segment : data_segments_) {
487 sizes.Add(segment->HeaderSize(), segment->BodySize()); 502 sizes.Add(segment->HeaderSize(), segment->BodySize());
488 } 503 }
489 504
490 sizes.AddSection(indirect_functions_.size()); 505 sizes.AddSection(indirect_functions_.size());
491 sizes.Add(2 * static_cast<uint32_t>(indirect_functions_.size()), 0); 506 sizes.Add(2 * static_cast<uint32_t>(indirect_functions_.size()), 0);
492 507
493 if (sizes.body_size > 0) sizes.Add(1, 0); 508 if (sizes.body_size > 0) sizes.Add(1, 0);
494 509
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 // -- emit functions --------------------------------------------------------- 555 // -- emit functions ---------------------------------------------------------
541 if (functions_.size() > 0) { 556 if (functions_.size() > 0) {
542 EmitUint8(&header, kDeclFunctions); 557 EmitUint8(&header, kDeclFunctions);
543 EmitVarInt(&header, functions_.size()); 558 EmitVarInt(&header, functions_.size());
544 559
545 for (auto func : functions_) { 560 for (auto func : functions_) {
546 func->Serialize(buffer, &header, &body); 561 func->Serialize(buffer, &header, &body);
547 } 562 }
548 } 563 }
549 564
565 // -- emit start function index ----------------------------------------------
566 if (has_start_function_) {
567 EmitUint8(&header, kDeclStartFunction);
568 EmitVarInt(&header, start_function_index_);
569 }
570
550 // -- emit data segments ----------------------------------------------------- 571 // -- emit data segments -----------------------------------------------------
551 if (data_segments_.size() > 0) { 572 if (data_segments_.size() > 0) {
552 EmitUint8(&header, kDeclDataSegments); 573 EmitUint8(&header, kDeclDataSegments);
553 EmitVarInt(&header, data_segments_.size()); 574 EmitVarInt(&header, data_segments_.size());
554 575
555 for (auto segment : data_segments_) { 576 for (auto segment : data_segments_) {
556 segment->Serialize(buffer, &header, &body); 577 segment->Serialize(buffer, &header, &body);
557 } 578 }
558 } 579 }
559 580
(...skipping 23 matching lines...) Expand all
583 next = next | 0x80; 604 next = next | 0x80;
584 } 605 }
585 output.push_back(next); 606 output.push_back(next);
586 shift += 7; 607 shift += 7;
587 } while ((next & 0x80) != 0); 608 } while ((next & 0x80) != 0);
588 return output; 609 return output;
589 } 610 }
590 } // namespace wasm 611 } // namespace wasm
591 } // namespace internal 612 } // namespace internal
592 } // namespace v8 613 } // namespace v8
OLDNEW
« src/wasm/encoder.h ('K') | « src/wasm/encoder.h ('k') | test/mjsunit/wasm/asm-wasm.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698