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

Side by Side Diff: src/wasm/asm-wasm-builder.cc

Issue 1974933002: [wasm] Remove the use of the "external" bit on OldFunctions section. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove unused variable. 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 | « src/compiler/wasm-compiler.cc ('k') | src/wasm/encoder.h » ('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/v8.h" 5 #include "src/v8.h"
6 6
7 // Required to get M_E etc. in MSVC. 7 // Required to get M_E etc. in MSVC.
8 #if defined(_WIN32) 8 #if defined(_WIN32)
9 #define _USE_MATH_DEFINES 9 #define _USE_MATH_DEFINES
10 #endif 10 #endif
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 VariableProxy* expr = prop->value()->AsVariableProxy(); 559 VariableProxy* expr = prop->value()->AsVariableProxy();
560 DCHECK_NOT_NULL(expr); 560 DCHECK_NOT_NULL(expr);
561 Variable* var = expr->var(); 561 Variable* var = expr->var();
562 Literal* name = prop->key()->AsLiteral(); 562 Literal* name = prop->key()->AsLiteral();
563 DCHECK_NOT_NULL(name); 563 DCHECK_NOT_NULL(name);
564 DCHECK(name->IsPropertyName()); 564 DCHECK(name->IsPropertyName());
565 const AstRawString* raw_name = name->AsRawPropertyName(); 565 const AstRawString* raw_name = name->AsRawPropertyName();
566 if (var->is_function()) { 566 if (var->is_function()) {
567 uint16_t index = LookupOrInsertFunction(var); 567 uint16_t index = LookupOrInsertFunction(var);
568 builder_->FunctionAt(index)->Exported(1); 568 builder_->FunctionAt(index)->Exported(1);
569 builder_->FunctionAt(index) 569 builder_->FunctionAt(index)->SetName(
570 ->SetName(raw_name->raw_data(), raw_name->length()); 570 reinterpret_cast<const char*>(raw_name->raw_data()),
571 raw_name->length());
571 } 572 }
572 } 573 }
573 } 574 }
574 575
575 void VisitArrayLiteral(ArrayLiteral* expr) { UNREACHABLE(); } 576 void VisitArrayLiteral(ArrayLiteral* expr) { UNREACHABLE(); }
576 577
577 void LoadInitFunction() { 578 void LoadInitFunction() {
578 current_function_builder_ = builder_->FunctionAt(init_function_index_); 579 current_function_builder_ = builder_->FunctionAt(init_function_index_);
579 scope_ = kInitScope; 580 scope_ = kInitScope;
580 } 581 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 ZoneHashMap::Entry* entry = 626 ZoneHashMap::Entry* entry =
626 function_tables_.Lookup(v, ComputePointerHash(v)); 627 function_tables_.Lookup(v, ComputePointerHash(v));
627 DCHECK_NOT_NULL(entry); 628 DCHECK_NOT_NULL(entry);
628 return reinterpret_cast<FunctionTableIndices*>(entry->value); 629 return reinterpret_cast<FunctionTableIndices*>(entry->value);
629 } 630 }
630 631
631 class ImportedFunctionTable { 632 class ImportedFunctionTable {
632 private: 633 private:
633 class ImportedFunctionIndices : public ZoneObject { 634 class ImportedFunctionIndices : public ZoneObject {
634 public: 635 public:
635 const unsigned char* name_; 636 const char* name_;
636 int name_length_; 637 int name_length_;
637 WasmModuleBuilder::SignatureMap signature_to_index_; 638 WasmModuleBuilder::SignatureMap signature_to_index_;
638 639
639 ImportedFunctionIndices(const unsigned char* name, int name_length, 640 ImportedFunctionIndices(const char* name, int name_length, Zone* zone)
640 Zone* zone)
641 : name_(name), name_length_(name_length), signature_to_index_(zone) {} 641 : name_(name), name_length_(name_length), signature_to_index_(zone) {}
642 }; 642 };
643 ZoneHashMap table_; 643 ZoneHashMap table_;
644 AsmWasmBuilderImpl* builder_; 644 AsmWasmBuilderImpl* builder_;
645 645
646 public: 646 public:
647 explicit ImportedFunctionTable(AsmWasmBuilderImpl* builder) 647 explicit ImportedFunctionTable(AsmWasmBuilderImpl* builder)
648 : table_(HashMap::PointersMatch, ZoneHashMap::kDefaultHashMapCapacity, 648 : table_(HashMap::PointersMatch, ZoneHashMap::kDefaultHashMapCapacity,
649 ZoneAllocationPolicy(builder->zone())), 649 ZoneAllocationPolicy(builder->zone())),
650 builder_(builder) {} 650 builder_(builder) {}
651 651
652 void AddImport(Variable* v, const unsigned char* name, int name_length) { 652 void AddImport(Variable* v, const char* name, int name_length) {
653 ImportedFunctionIndices* indices = new (builder_->zone()) 653 ImportedFunctionIndices* indices = new (builder_->zone())
654 ImportedFunctionIndices(name, name_length, builder_->zone()); 654 ImportedFunctionIndices(name, name_length, builder_->zone());
655 ZoneHashMap::Entry* entry = table_.LookupOrInsert( 655 ZoneHashMap::Entry* entry = table_.LookupOrInsert(
656 v, ComputePointerHash(v), ZoneAllocationPolicy(builder_->zone())); 656 v, ComputePointerHash(v), ZoneAllocationPolicy(builder_->zone()));
657 entry->value = indices; 657 entry->value = indices;
658 } 658 }
659 659
660 uint16_t GetFunctionIndex(Variable* v, FunctionSig* sig) { 660 uint16_t GetFunctionIndex(Variable* v, FunctionSig* sig) {
661 ZoneHashMap::Entry* entry = table_.Lookup(v, ComputePointerHash(v)); 661 ZoneHashMap::Entry* entry = table_.Lookup(v, ComputePointerHash(v));
662 DCHECK_NOT_NULL(entry); 662 DCHECK_NOT_NULL(entry);
663 ImportedFunctionIndices* indices = 663 ImportedFunctionIndices* indices =
664 reinterpret_cast<ImportedFunctionIndices*>(entry->value); 664 reinterpret_cast<ImportedFunctionIndices*>(entry->value);
665 WasmModuleBuilder::SignatureMap::iterator pos = 665 WasmModuleBuilder::SignatureMap::iterator pos =
666 indices->signature_to_index_.find(sig); 666 indices->signature_to_index_.find(sig);
667 if (pos != indices->signature_to_index_.end()) { 667 if (pos != indices->signature_to_index_.end()) {
668 return pos->second; 668 return pos->second;
669 } else { 669 } else {
670 uint16_t index = builder_->builder_->AddFunction(); 670 uint32_t index = builder_->builder_->AddImport(
671 indices->name_, indices->name_length_, sig);
671 indices->signature_to_index_[sig] = index; 672 indices->signature_to_index_[sig] = index;
672 WasmFunctionBuilder* function = builder_->builder_->FunctionAt(index);
673 function->External(1);
674 function->SetName(indices->name_, indices->name_length_);
675 if (sig->return_count() > 0) {
676 function->ReturnType(sig->GetReturn());
677 }
678 for (size_t i = 0; i < sig->parameter_count(); i++) {
679 function->AddParam(sig->GetParam(i));
680 }
681 return index; 673 return index;
682 } 674 }
683 } 675 }
684 }; 676 };
685 677
686 void EmitAssignmentLhs(Expression* target, MachineType* mtype) { 678 void EmitAssignmentLhs(Expression* target, MachineType* mtype) {
687 // Match the left hand side of the assignment. 679 // Match the left hand side of the assignment.
688 VariableProxy* target_var = target->AsVariableProxy(); 680 VariableProxy* target_var = target->AsVariableProxy();
689 if (target_var != nullptr) { 681 if (target_var != nullptr) {
690 // Left hand side is a local or a global variable, no code on LHS. 682 // Left hand side is a local or a global variable, no code on LHS.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 if (scope_ == kModuleScope) { 788 if (scope_ == kModuleScope) {
797 Property* prop = expr->value()->AsProperty(); 789 Property* prop = expr->value()->AsProperty();
798 if (prop != nullptr) { 790 if (prop != nullptr) {
799 VariableProxy* vp = prop->obj()->AsVariableProxy(); 791 VariableProxy* vp = prop->obj()->AsVariableProxy();
800 if (vp != nullptr && vp->var()->IsParameter() && 792 if (vp != nullptr && vp->var()->IsParameter() &&
801 vp->var()->index() == 1) { 793 vp->var()->index() == 1) {
802 VariableProxy* target = expr->target()->AsVariableProxy(); 794 VariableProxy* target = expr->target()->AsVariableProxy();
803 if (bounds_->get(target).lower->Is(Type::Function())) { 795 if (bounds_->get(target).lower->Is(Type::Function())) {
804 const AstRawString* name = 796 const AstRawString* name =
805 prop->key()->AsLiteral()->AsRawPropertyName(); 797 prop->key()->AsLiteral()->AsRawPropertyName();
806 imported_function_table_.AddImport(target->var(), name->raw_data(), 798 imported_function_table_.AddImport(
807 name->length()); 799 target->var(), reinterpret_cast<const char*>(name->raw_data()),
800 name->length());
808 } 801 }
809 } 802 }
810 // Property values in module scope don't emit code, so return. 803 // Property values in module scope don't emit code, so return.
811 return; 804 return;
812 } 805 }
813 ArrayLiteral* funcs = expr->value()->AsArrayLiteral(); 806 ArrayLiteral* funcs = expr->value()->AsArrayLiteral();
814 if (funcs != nullptr && 807 if (funcs != nullptr &&
815 bounds_->get(funcs).lower->AsArray()->Element()->IsFunction()) { 808 bounds_->get(funcs).lower->AsArray()->Element()->IsFunction()) {
816 VariableProxy* target = expr->target()->AsVariableProxy(); 809 VariableProxy* target = expr->target()->AsVariableProxy();
817 DCHECK_NOT_NULL(target); 810 DCHECK_NOT_NULL(target);
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 FunctionSig::Builder sig(zone(), return_type == kAstStmt ? 0 : 1, 1261 FunctionSig::Builder sig(zone(), return_type == kAstStmt ? 0 : 1,
1269 args->length()); 1262 args->length());
1270 if (return_type != kAstStmt) { 1263 if (return_type != kAstStmt) {
1271 sig.AddReturn(return_type); 1264 sig.AddReturn(return_type);
1272 } 1265 }
1273 for (int i = 0; i < args->length(); i++) { 1266 for (int i = 0; i < args->length(); i++) {
1274 sig.AddParam(TypeOf(args->at(i))); 1267 sig.AddParam(TypeOf(args->at(i)));
1275 } 1268 }
1276 index = 1269 index =
1277 imported_function_table_.GetFunctionIndex(vp->var(), sig.Build()); 1270 imported_function_table_.GetFunctionIndex(vp->var(), sig.Build());
1271 VisitCallArgs(expr);
1272 current_function_builder_->Emit(kExprCallImport);
1273 current_function_builder_->EmitVarInt(expr->arguments()->length());
1274 current_function_builder_->EmitVarInt(index);
1278 } else { 1275 } else {
1279 index = LookupOrInsertFunction(vp->var()); 1276 index = LookupOrInsertFunction(vp->var());
1277 VisitCallArgs(expr);
1278 current_function_builder_->Emit(kExprCallFunction);
1279 current_function_builder_->EmitVarInt(expr->arguments()->length());
1280 current_function_builder_->EmitVarInt(index);
1280 } 1281 }
1281 VisitCallArgs(expr);
1282 current_function_builder_->Emit(kExprCallFunction);
1283 current_function_builder_->EmitVarInt(expr->arguments()->length());
1284 current_function_builder_->EmitVarInt(index);
1285 break; 1282 break;
1286 } 1283 }
1287 case Call::KEYED_PROPERTY_CALL: { 1284 case Call::KEYED_PROPERTY_CALL: {
1288 DCHECK_EQ(kFuncScope, scope_); 1285 DCHECK_EQ(kFuncScope, scope_);
1289 Property* p = expr->expression()->AsProperty(); 1286 Property* p = expr->expression()->AsProperty();
1290 DCHECK_NOT_NULL(p); 1287 DCHECK_NOT_NULL(p);
1291 VariableProxy* var = p->obj()->AsVariableProxy(); 1288 VariableProxy* var = p->obj()->AsVariableProxy();
1292 DCHECK_NOT_NULL(var); 1289 DCHECK_NOT_NULL(var);
1293 FunctionTableIndices* indices = LookupFunctionTable(var->var()); 1290 FunctionTableIndices* indices = LookupFunctionTable(var->var());
1294 RECURSE(Visit(p->key())); 1291 RECURSE(Visit(p->key()));
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 // that zone in constructor may be thrown away once wasm module is written. 1742 // that zone in constructor may be thrown away once wasm module is written.
1746 WasmModuleIndex* AsmWasmBuilder::Run() { 1743 WasmModuleIndex* AsmWasmBuilder::Run() {
1747 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_, typer_); 1744 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_, typer_);
1748 impl.Compile(); 1745 impl.Compile();
1749 WasmModuleWriter* writer = impl.builder_->Build(zone_); 1746 WasmModuleWriter* writer = impl.builder_->Build(zone_);
1750 return writer->WriteTo(zone_); 1747 return writer->WriteTo(zone_);
1751 } 1748 }
1752 } // namespace wasm 1749 } // namespace wasm
1753 } // namespace internal 1750 } // namespace internal
1754 } // namespace v8 1751 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/wasm/encoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698