OLD | NEW |
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 function_tables_(HashMap::PointersMatch, | 60 function_tables_(HashMap::PointersMatch, |
61 ZoneHashMap::kDefaultHashMapCapacity, | 61 ZoneHashMap::kDefaultHashMapCapacity, |
62 ZoneAllocationPolicy(zone)), | 62 ZoneAllocationPolicy(zone)), |
63 imported_function_table_(this), | 63 imported_function_table_(this), |
64 bounds_(typer->bounds()) { | 64 bounds_(typer->bounds()) { |
65 InitializeAstVisitor(isolate); | 65 InitializeAstVisitor(isolate); |
66 } | 66 } |
67 | 67 |
68 void InitializeInitFunction() { | 68 void InitializeInitFunction() { |
69 init_function_index_ = builder_->AddFunction(); | 69 init_function_index_ = builder_->AddFunction(); |
| 70 FunctionSig::Builder b(zone(), 0, 0); |
70 current_function_builder_ = builder_->FunctionAt(init_function_index_); | 71 current_function_builder_ = builder_->FunctionAt(init_function_index_); |
71 current_function_builder_->ReturnType(kAstStmt); | 72 current_function_builder_->SetSignature(b.Build()); |
72 builder_->MarkStartFunction(init_function_index_); | 73 builder_->MarkStartFunction(init_function_index_); |
73 current_function_builder_ = nullptr; | 74 current_function_builder_ = nullptr; |
74 } | 75 } |
75 | 76 |
76 void Compile() { | 77 void Compile() { |
77 InitializeInitFunction(); | 78 InitializeInitFunction(); |
78 RECURSE(VisitFunctionLiteral(literal_)); | 79 RECURSE(VisitFunctionLiteral(literal_)); |
79 } | 80 } |
80 | 81 |
81 void VisitVariableDeclaration(VariableDeclaration* decl) {} | 82 void VisitVariableDeclaration(VariableDeclaration* decl) {} |
82 | 83 |
83 void VisitFunctionDeclaration(FunctionDeclaration* decl) { | 84 void VisitFunctionDeclaration(FunctionDeclaration* decl) { |
84 DCHECK_EQ(kModuleScope, scope_); | 85 DCHECK_EQ(kModuleScope, scope_); |
85 DCHECK_NULL(current_function_builder_); | 86 DCHECK_NULL(current_function_builder_); |
86 uint16_t index = LookupOrInsertFunction(decl->proxy()->var()); | 87 uint32_t index = LookupOrInsertFunction(decl->proxy()->var()); |
87 current_function_builder_ = builder_->FunctionAt(index); | 88 current_function_builder_ = builder_->FunctionAt(index); |
88 scope_ = kFuncScope; | 89 scope_ = kFuncScope; |
89 RECURSE(Visit(decl->fun())); | 90 RECURSE(Visit(decl->fun())); |
90 scope_ = kModuleScope; | 91 scope_ = kModuleScope; |
91 current_function_builder_ = nullptr; | 92 current_function_builder_ = nullptr; |
92 local_variables_.Clear(); | 93 local_variables_.Clear(); |
93 } | 94 } |
94 | 95 |
95 void VisitImportDeclaration(ImportDeclaration* decl) {} | 96 void VisitImportDeclaration(ImportDeclaration* decl) {} |
96 | 97 |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 void VisitTryCatchStatement(TryCatchStatement* stmt) { UNREACHABLE(); } | 405 void VisitTryCatchStatement(TryCatchStatement* stmt) { UNREACHABLE(); } |
405 | 406 |
406 void VisitTryFinallyStatement(TryFinallyStatement* stmt) { UNREACHABLE(); } | 407 void VisitTryFinallyStatement(TryFinallyStatement* stmt) { UNREACHABLE(); } |
407 | 408 |
408 void VisitDebuggerStatement(DebuggerStatement* stmt) { UNREACHABLE(); } | 409 void VisitDebuggerStatement(DebuggerStatement* stmt) { UNREACHABLE(); } |
409 | 410 |
410 void VisitFunctionLiteral(FunctionLiteral* expr) { | 411 void VisitFunctionLiteral(FunctionLiteral* expr) { |
411 Scope* scope = expr->scope(); | 412 Scope* scope = expr->scope(); |
412 if (scope_ == kFuncScope) { | 413 if (scope_ == kFuncScope) { |
413 if (bounds_->get(expr).lower->IsFunction()) { | 414 if (bounds_->get(expr).lower->IsFunction()) { |
| 415 // Build the signature for the function. |
414 FunctionType* func_type = bounds_->get(expr).lower->AsFunction(); | 416 FunctionType* func_type = bounds_->get(expr).lower->AsFunction(); |
415 LocalType return_type = TypeFrom(func_type->Result()); | 417 LocalType return_type = TypeFrom(func_type->Result()); |
416 current_function_builder_->ReturnType(return_type); | 418 FunctionSig::Builder b(zone(), return_type == kAstStmt ? 0 : 1, |
| 419 func_type->Arity()); |
| 420 if (return_type != kAstStmt) b.AddReturn(return_type); |
417 for (int i = 0; i < expr->parameter_count(); i++) { | 421 for (int i = 0; i < expr->parameter_count(); i++) { |
418 LocalType type = TypeFrom(func_type->Parameter(i)); | 422 LocalType type = TypeFrom(func_type->Parameter(i)); |
419 DCHECK_NE(kAstStmt, type); | 423 DCHECK_NE(kAstStmt, type); |
420 LookupOrInsertLocal(scope->parameter(i), type); | 424 b.AddParam(type); |
| 425 InsertParameter(scope->parameter(i), type, i); |
421 } | 426 } |
| 427 current_function_builder_->SetSignature(b.Build()); |
422 } else { | 428 } else { |
423 UNREACHABLE(); | 429 UNREACHABLE(); |
424 } | 430 } |
425 } | 431 } |
426 RECURSE(VisitStatements(expr->body())); | 432 RECURSE(VisitStatements(expr->body())); |
427 RECURSE(VisitDeclarations(scope->declarations())); | 433 RECURSE(VisitDeclarations(scope->declarations())); |
428 } | 434 } |
429 | 435 |
430 void VisitNativeFunctionLiteral(NativeFunctionLiteral* expr) { | 436 void VisitNativeFunctionLiteral(NativeFunctionLiteral* expr) { |
431 UNREACHABLE(); | 437 UNREACHABLE(); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 ObjectLiteralProperty* prop = props->at(i); | 558 ObjectLiteralProperty* prop = props->at(i); |
553 DCHECK_EQ(kExportScope, scope_); | 559 DCHECK_EQ(kExportScope, scope_); |
554 VariableProxy* expr = prop->value()->AsVariableProxy(); | 560 VariableProxy* expr = prop->value()->AsVariableProxy(); |
555 DCHECK_NOT_NULL(expr); | 561 DCHECK_NOT_NULL(expr); |
556 Variable* var = expr->var(); | 562 Variable* var = expr->var(); |
557 Literal* name = prop->key()->AsLiteral(); | 563 Literal* name = prop->key()->AsLiteral(); |
558 DCHECK_NOT_NULL(name); | 564 DCHECK_NOT_NULL(name); |
559 DCHECK(name->IsPropertyName()); | 565 DCHECK(name->IsPropertyName()); |
560 const AstRawString* raw_name = name->AsRawPropertyName(); | 566 const AstRawString* raw_name = name->AsRawPropertyName(); |
561 if (var->is_function()) { | 567 if (var->is_function()) { |
562 uint16_t index = LookupOrInsertFunction(var); | 568 uint32_t index = LookupOrInsertFunction(var); |
563 builder_->FunctionAt(index)->Exported(1); | 569 builder_->FunctionAt(index)->Exported(1); |
564 builder_->FunctionAt(index)->SetName( | 570 builder_->FunctionAt(index)->SetName( |
565 reinterpret_cast<const char*>(raw_name->raw_data()), | 571 reinterpret_cast<const char*>(raw_name->raw_data()), |
566 raw_name->length()); | 572 raw_name->length()); |
567 } | 573 } |
568 } | 574 } |
569 } | 575 } |
570 | 576 |
571 void VisitArrayLiteral(ArrayLiteral* expr) { UNREACHABLE(); } | 577 void VisitArrayLiteral(ArrayLiteral* expr) { UNREACHABLE(); } |
572 | 578 |
(...skipping 12 matching lines...) Expand all Loading... |
585 bounds_->get(funcs).lower->AsArray()->Element()->AsFunction(); | 591 bounds_->get(funcs).lower->AsArray()->Element()->AsFunction(); |
586 LocalType return_type = TypeFrom(func_type->Result()); | 592 LocalType return_type = TypeFrom(func_type->Result()); |
587 FunctionSig::Builder sig(zone(), return_type == kAstStmt ? 0 : 1, | 593 FunctionSig::Builder sig(zone(), return_type == kAstStmt ? 0 : 1, |
588 func_type->Arity()); | 594 func_type->Arity()); |
589 if (return_type != kAstStmt) { | 595 if (return_type != kAstStmt) { |
590 sig.AddReturn(static_cast<LocalType>(return_type)); | 596 sig.AddReturn(static_cast<LocalType>(return_type)); |
591 } | 597 } |
592 for (int i = 0; i < func_type->Arity(); i++) { | 598 for (int i = 0; i < func_type->Arity(); i++) { |
593 sig.AddParam(TypeFrom(func_type->Parameter(i))); | 599 sig.AddParam(TypeFrom(func_type->Parameter(i))); |
594 } | 600 } |
595 uint16_t signature_index = builder_->AddSignature(sig.Build()); | 601 uint32_t signature_index = builder_->AddSignature(sig.Build()); |
596 InsertFunctionTable(table->var(), next_table_index_, signature_index); | 602 InsertFunctionTable(table->var(), next_table_index_, signature_index); |
597 next_table_index_ += funcs->values()->length(); | 603 next_table_index_ += funcs->values()->length(); |
598 for (int i = 0; i < funcs->values()->length(); i++) { | 604 for (int i = 0; i < funcs->values()->length(); i++) { |
599 VariableProxy* func = funcs->values()->at(i)->AsVariableProxy(); | 605 VariableProxy* func = funcs->values()->at(i)->AsVariableProxy(); |
600 DCHECK_NOT_NULL(func); | 606 DCHECK_NOT_NULL(func); |
601 builder_->AddIndirectFunction(LookupOrInsertFunction(func->var())); | 607 builder_->AddIndirectFunction(LookupOrInsertFunction(func->var())); |
602 } | 608 } |
603 } | 609 } |
604 | 610 |
605 struct FunctionTableIndices : public ZoneObject { | 611 struct FunctionTableIndices : public ZoneObject { |
606 uint32_t start_index; | 612 uint32_t start_index; |
607 uint16_t signature_index; | 613 uint32_t signature_index; |
608 }; | 614 }; |
609 | 615 |
610 void InsertFunctionTable(Variable* v, uint32_t start_index, | 616 void InsertFunctionTable(Variable* v, uint32_t start_index, |
611 uint16_t signature_index) { | 617 uint32_t signature_index) { |
612 FunctionTableIndices* container = new (zone()) FunctionTableIndices(); | 618 FunctionTableIndices* container = new (zone()) FunctionTableIndices(); |
613 container->start_index = start_index; | 619 container->start_index = start_index; |
614 container->signature_index = signature_index; | 620 container->signature_index = signature_index; |
615 ZoneHashMap::Entry* entry = function_tables_.LookupOrInsert( | 621 ZoneHashMap::Entry* entry = function_tables_.LookupOrInsert( |
616 v, ComputePointerHash(v), ZoneAllocationPolicy(zone())); | 622 v, ComputePointerHash(v), ZoneAllocationPolicy(zone())); |
617 entry->value = container; | 623 entry->value = container; |
618 } | 624 } |
619 | 625 |
620 FunctionTableIndices* LookupFunctionTable(Variable* v) { | 626 FunctionTableIndices* LookupFunctionTable(Variable* v) { |
621 ZoneHashMap::Entry* entry = | 627 ZoneHashMap::Entry* entry = |
(...skipping 23 matching lines...) Expand all Loading... |
645 builder_(builder) {} | 651 builder_(builder) {} |
646 | 652 |
647 void AddImport(Variable* v, const char* name, int name_length) { | 653 void AddImport(Variable* v, const char* name, int name_length) { |
648 ImportedFunctionIndices* indices = new (builder_->zone()) | 654 ImportedFunctionIndices* indices = new (builder_->zone()) |
649 ImportedFunctionIndices(name, name_length, builder_->zone()); | 655 ImportedFunctionIndices(name, name_length, builder_->zone()); |
650 ZoneHashMap::Entry* entry = table_.LookupOrInsert( | 656 ZoneHashMap::Entry* entry = table_.LookupOrInsert( |
651 v, ComputePointerHash(v), ZoneAllocationPolicy(builder_->zone())); | 657 v, ComputePointerHash(v), ZoneAllocationPolicy(builder_->zone())); |
652 entry->value = indices; | 658 entry->value = indices; |
653 } | 659 } |
654 | 660 |
655 uint16_t GetFunctionIndex(Variable* v, FunctionSig* sig) { | 661 uint32_t GetFunctionIndex(Variable* v, FunctionSig* sig) { |
656 ZoneHashMap::Entry* entry = table_.Lookup(v, ComputePointerHash(v)); | 662 ZoneHashMap::Entry* entry = table_.Lookup(v, ComputePointerHash(v)); |
657 DCHECK_NOT_NULL(entry); | 663 DCHECK_NOT_NULL(entry); |
658 ImportedFunctionIndices* indices = | 664 ImportedFunctionIndices* indices = |
659 reinterpret_cast<ImportedFunctionIndices*>(entry->value); | 665 reinterpret_cast<ImportedFunctionIndices*>(entry->value); |
660 WasmModuleBuilder::SignatureMap::iterator pos = | 666 WasmModuleBuilder::SignatureMap::iterator pos = |
661 indices->signature_to_index_.find(sig); | 667 indices->signature_to_index_.find(sig); |
662 if (pos != indices->signature_to_index_.end()) { | 668 if (pos != indices->signature_to_index_.end()) { |
663 return pos->second; | 669 return pos->second; |
664 } else { | 670 } else { |
665 uint32_t index = builder_->builder_->AddImport( | 671 uint32_t index = builder_->builder_->AddImport( |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 current_function_builder_->Emit(kExprF32Sqrt); | 1068 current_function_builder_->Emit(kExprF32Sqrt); |
1063 } else if (call_type == kAstF64) { | 1069 } else if (call_type == kAstF64) { |
1064 current_function_builder_->Emit(kExprF64Sqrt); | 1070 current_function_builder_->Emit(kExprF64Sqrt); |
1065 } else { | 1071 } else { |
1066 UNREACHABLE(); | 1072 UNREACHABLE(); |
1067 } | 1073 } |
1068 break; | 1074 break; |
1069 } | 1075 } |
1070 case AsmTyper::kMathAbs: { | 1076 case AsmTyper::kMathAbs: { |
1071 if (call_type == kAstI32) { | 1077 if (call_type == kAstI32) { |
1072 uint16_t tmp = current_function_builder_->AddLocal(kAstI32); | 1078 uint32_t tmp = current_function_builder_->AddLocal(kAstI32); |
1073 | 1079 |
1074 // if set_local(tmp, x) < 0 | 1080 // if set_local(tmp, x) < 0 |
1075 Visit(call->arguments()->at(0)); | 1081 Visit(call->arguments()->at(0)); |
1076 current_function_builder_->EmitSetLocal(tmp); | 1082 current_function_builder_->EmitSetLocal(tmp); |
1077 byte code[] = {WASM_I8(0)}; | 1083 byte code[] = {WASM_I8(0)}; |
1078 current_function_builder_->EmitCode(code, sizeof(code)); | 1084 current_function_builder_->EmitCode(code, sizeof(code)); |
1079 current_function_builder_->Emit(kExprI32LtS); | 1085 current_function_builder_->Emit(kExprI32LtS); |
1080 current_function_builder_->Emit(kExprIf); | 1086 current_function_builder_->Emit(kExprIf); |
1081 | 1087 |
1082 // then (0 - tmp) | 1088 // then (0 - tmp) |
(...skipping 14 matching lines...) Expand all Loading... |
1097 VisitCallArgs(call); | 1103 VisitCallArgs(call); |
1098 current_function_builder_->Emit(kExprF64Abs); | 1104 current_function_builder_->Emit(kExprF64Abs); |
1099 } else { | 1105 } else { |
1100 UNREACHABLE(); | 1106 UNREACHABLE(); |
1101 } | 1107 } |
1102 break; | 1108 break; |
1103 } | 1109 } |
1104 case AsmTyper::kMathMin: { | 1110 case AsmTyper::kMathMin: { |
1105 // TODO(bradnelson): Change wasm to match Math.min in asm.js mode. | 1111 // TODO(bradnelson): Change wasm to match Math.min in asm.js mode. |
1106 if (call_type == kAstI32) { | 1112 if (call_type == kAstI32) { |
1107 uint16_t tmp_x = current_function_builder_->AddLocal(kAstI32); | 1113 uint32_t tmp_x = current_function_builder_->AddLocal(kAstI32); |
1108 uint16_t tmp_y = current_function_builder_->AddLocal(kAstI32); | 1114 uint32_t tmp_y = current_function_builder_->AddLocal(kAstI32); |
1109 | 1115 |
1110 // if set_local(tmp_x, x) < set_local(tmp_y, y) | 1116 // if set_local(tmp_x, x) < set_local(tmp_y, y) |
1111 Visit(call->arguments()->at(0)); | 1117 Visit(call->arguments()->at(0)); |
1112 current_function_builder_->EmitSetLocal(tmp_x); | 1118 current_function_builder_->EmitSetLocal(tmp_x); |
1113 | 1119 |
1114 Visit(call->arguments()->at(1)); | 1120 Visit(call->arguments()->at(1)); |
1115 current_function_builder_->EmitSetLocal(tmp_y); | 1121 current_function_builder_->EmitSetLocal(tmp_y); |
1116 | 1122 |
1117 current_function_builder_->Emit(kExprI32LeS); | 1123 current_function_builder_->Emit(kExprI32LeS); |
1118 current_function_builder_->Emit(kExprIf); | 1124 current_function_builder_->Emit(kExprIf); |
(...skipping 13 matching lines...) Expand all Loading... |
1132 VisitCallArgs(call); | 1138 VisitCallArgs(call); |
1133 current_function_builder_->Emit(kExprF64Min); | 1139 current_function_builder_->Emit(kExprF64Min); |
1134 } else { | 1140 } else { |
1135 UNREACHABLE(); | 1141 UNREACHABLE(); |
1136 } | 1142 } |
1137 break; | 1143 break; |
1138 } | 1144 } |
1139 case AsmTyper::kMathMax: { | 1145 case AsmTyper::kMathMax: { |
1140 // TODO(bradnelson): Change wasm to match Math.max in asm.js mode. | 1146 // TODO(bradnelson): Change wasm to match Math.max in asm.js mode. |
1141 if (call_type == kAstI32) { | 1147 if (call_type == kAstI32) { |
1142 uint16_t tmp_x = current_function_builder_->AddLocal(kAstI32); | 1148 uint32_t tmp_x = current_function_builder_->AddLocal(kAstI32); |
1143 uint16_t tmp_y = current_function_builder_->AddLocal(kAstI32); | 1149 uint32_t tmp_y = current_function_builder_->AddLocal(kAstI32); |
1144 | 1150 |
1145 // if set_local(tmp_x, x) < set_local(tmp_y, y) | 1151 // if set_local(tmp_x, x) < set_local(tmp_y, y) |
1146 Visit(call->arguments()->at(0)); | 1152 Visit(call->arguments()->at(0)); |
1147 | 1153 |
1148 current_function_builder_->EmitSetLocal(tmp_x); | 1154 current_function_builder_->EmitSetLocal(tmp_x); |
1149 | 1155 |
1150 Visit(call->arguments()->at(1)); | 1156 Visit(call->arguments()->at(1)); |
1151 current_function_builder_->EmitSetLocal(tmp_y); | 1157 current_function_builder_->EmitSetLocal(tmp_y); |
1152 | 1158 |
1153 current_function_builder_->Emit(kExprI32LeS); | 1159 current_function_builder_->Emit(kExprI32LeS); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 Call::CallType call_type = expr->GetCallType(isolate_); | 1246 Call::CallType call_type = expr->GetCallType(isolate_); |
1241 switch (call_type) { | 1247 switch (call_type) { |
1242 case Call::OTHER_CALL: { | 1248 case Call::OTHER_CALL: { |
1243 DCHECK_EQ(kFuncScope, scope_); | 1249 DCHECK_EQ(kFuncScope, scope_); |
1244 VariableProxy* proxy = expr->expression()->AsVariableProxy(); | 1250 VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
1245 if (proxy != nullptr) { | 1251 if (proxy != nullptr) { |
1246 if (VisitStdlibFunction(expr, proxy)) { | 1252 if (VisitStdlibFunction(expr, proxy)) { |
1247 return; | 1253 return; |
1248 } | 1254 } |
1249 } | 1255 } |
1250 uint16_t index; | 1256 uint32_t index; |
1251 VariableProxy* vp = expr->expression()->AsVariableProxy(); | 1257 VariableProxy* vp = expr->expression()->AsVariableProxy(); |
1252 if (vp != nullptr && | 1258 if (vp != nullptr && |
1253 Type::Any()->Is(bounds_->get(vp).lower->AsFunction()->Result())) { | 1259 Type::Any()->Is(bounds_->get(vp).lower->AsFunction()->Result())) { |
1254 LocalType return_type = TypeOf(expr); | 1260 LocalType return_type = TypeOf(expr); |
1255 ZoneList<Expression*>* args = expr->arguments(); | 1261 ZoneList<Expression*>* args = expr->arguments(); |
1256 FunctionSig::Builder sig(zone(), return_type == kAstStmt ? 0 : 1, | 1262 FunctionSig::Builder sig(zone(), return_type == kAstStmt ? 0 : 1, |
1257 args->length()); | 1263 args->length()); |
1258 if (return_type != kAstStmt) { | 1264 if (return_type != kAstStmt) { |
1259 sig.AddReturn(return_type); | 1265 sig.AddReturn(return_type); |
1260 } | 1266 } |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1621 | 1627 |
1622 void VisitSloppyBlockFunctionStatement(SloppyBlockFunctionStatement* expr) { | 1628 void VisitSloppyBlockFunctionStatement(SloppyBlockFunctionStatement* expr) { |
1623 UNREACHABLE(); | 1629 UNREACHABLE(); |
1624 } | 1630 } |
1625 | 1631 |
1626 void VisitDoExpression(DoExpression* expr) { UNREACHABLE(); } | 1632 void VisitDoExpression(DoExpression* expr) { UNREACHABLE(); } |
1627 | 1633 |
1628 void VisitRewritableExpression(RewritableExpression* expr) { UNREACHABLE(); } | 1634 void VisitRewritableExpression(RewritableExpression* expr) { UNREACHABLE(); } |
1629 | 1635 |
1630 struct IndexContainer : public ZoneObject { | 1636 struct IndexContainer : public ZoneObject { |
1631 uint16_t index; | 1637 uint32_t index; |
1632 }; | 1638 }; |
1633 | 1639 |
1634 uint16_t LookupOrInsertLocal(Variable* v, LocalType type) { | 1640 uint32_t LookupOrInsertLocal(Variable* v, LocalType type) { |
1635 DCHECK_NOT_NULL(current_function_builder_); | 1641 DCHECK_NOT_NULL(current_function_builder_); |
1636 ZoneHashMap::Entry* entry = | 1642 ZoneHashMap::Entry* entry = |
1637 local_variables_.Lookup(v, ComputePointerHash(v)); | 1643 local_variables_.Lookup(v, ComputePointerHash(v)); |
1638 if (entry == nullptr) { | 1644 if (entry == nullptr) { |
1639 uint16_t index; | 1645 uint32_t index; |
1640 if (v->IsParameter()) { | 1646 DCHECK(!v->IsParameter()); |
1641 index = current_function_builder_->AddParam(type); | 1647 index = current_function_builder_->AddLocal(type); |
1642 } else { | |
1643 index = current_function_builder_->AddLocal(type); | |
1644 } | |
1645 IndexContainer* container = new (zone()) IndexContainer(); | 1648 IndexContainer* container = new (zone()) IndexContainer(); |
1646 container->index = index; | 1649 container->index = index; |
1647 entry = local_variables_.LookupOrInsert(v, ComputePointerHash(v), | 1650 entry = local_variables_.LookupOrInsert(v, ComputePointerHash(v), |
1648 ZoneAllocationPolicy(zone())); | 1651 ZoneAllocationPolicy(zone())); |
1649 entry->value = container; | 1652 entry->value = container; |
1650 } | 1653 } |
1651 return (reinterpret_cast<IndexContainer*>(entry->value))->index; | 1654 return (reinterpret_cast<IndexContainer*>(entry->value))->index; |
1652 } | 1655 } |
1653 | 1656 |
1654 uint16_t LookupOrInsertGlobal(Variable* v, LocalType type) { | 1657 void InsertParameter(Variable* v, LocalType type, uint32_t index) { |
| 1658 DCHECK(v->IsParameter()); |
| 1659 DCHECK_NOT_NULL(current_function_builder_); |
| 1660 ZoneHashMap::Entry* entry = |
| 1661 local_variables_.Lookup(v, ComputePointerHash(v)); |
| 1662 DCHECK_NULL(entry); |
| 1663 IndexContainer* container = new (zone()) IndexContainer(); |
| 1664 container->index = index; |
| 1665 entry = local_variables_.LookupOrInsert(v, ComputePointerHash(v), |
| 1666 ZoneAllocationPolicy(zone())); |
| 1667 entry->value = container; |
| 1668 } |
| 1669 |
| 1670 uint32_t LookupOrInsertGlobal(Variable* v, LocalType type) { |
1655 ZoneHashMap::Entry* entry = | 1671 ZoneHashMap::Entry* entry = |
1656 global_variables_.Lookup(v, ComputePointerHash(v)); | 1672 global_variables_.Lookup(v, ComputePointerHash(v)); |
1657 if (entry == nullptr) { | 1673 if (entry == nullptr) { |
1658 uint16_t index = | 1674 uint32_t index = |
1659 builder_->AddGlobal(WasmOpcodes::MachineTypeFor(type), 0); | 1675 builder_->AddGlobal(WasmOpcodes::MachineTypeFor(type), 0); |
1660 IndexContainer* container = new (zone()) IndexContainer(); | 1676 IndexContainer* container = new (zone()) IndexContainer(); |
1661 container->index = index; | 1677 container->index = index; |
1662 entry = global_variables_.LookupOrInsert(v, ComputePointerHash(v), | 1678 entry = global_variables_.LookupOrInsert(v, ComputePointerHash(v), |
1663 ZoneAllocationPolicy(zone())); | 1679 ZoneAllocationPolicy(zone())); |
1664 entry->value = container; | 1680 entry->value = container; |
1665 } | 1681 } |
1666 return (reinterpret_cast<IndexContainer*>(entry->value))->index; | 1682 return (reinterpret_cast<IndexContainer*>(entry->value))->index; |
1667 } | 1683 } |
1668 | 1684 |
1669 uint16_t LookupOrInsertFunction(Variable* v) { | 1685 uint32_t LookupOrInsertFunction(Variable* v) { |
1670 DCHECK_NOT_NULL(builder_); | 1686 DCHECK_NOT_NULL(builder_); |
1671 ZoneHashMap::Entry* entry = functions_.Lookup(v, ComputePointerHash(v)); | 1687 ZoneHashMap::Entry* entry = functions_.Lookup(v, ComputePointerHash(v)); |
1672 if (entry == nullptr) { | 1688 if (entry == nullptr) { |
1673 uint16_t index = builder_->AddFunction(); | 1689 uint32_t index = builder_->AddFunction(); |
1674 IndexContainer* container = new (zone()) IndexContainer(); | 1690 IndexContainer* container = new (zone()) IndexContainer(); |
1675 container->index = index; | 1691 container->index = index; |
1676 entry = functions_.LookupOrInsert(v, ComputePointerHash(v), | 1692 entry = functions_.LookupOrInsert(v, ComputePointerHash(v), |
1677 ZoneAllocationPolicy(zone())); | 1693 ZoneAllocationPolicy(zone())); |
1678 entry->value = container; | 1694 entry->value = container; |
1679 } | 1695 } |
1680 return (reinterpret_cast<IndexContainer*>(entry->value))->index; | 1696 return (reinterpret_cast<IndexContainer*>(entry->value))->index; |
1681 } | 1697 } |
1682 | 1698 |
1683 LocalType TypeOf(Expression* expr) { | 1699 LocalType TypeOf(Expression* expr) { |
(...skipping 21 matching lines...) Expand all Loading... |
1705 AsmScope scope_; | 1721 AsmScope scope_; |
1706 WasmModuleBuilder* builder_; | 1722 WasmModuleBuilder* builder_; |
1707 WasmFunctionBuilder* current_function_builder_; | 1723 WasmFunctionBuilder* current_function_builder_; |
1708 FunctionLiteral* literal_; | 1724 FunctionLiteral* literal_; |
1709 Isolate* isolate_; | 1725 Isolate* isolate_; |
1710 Zone* zone_; | 1726 Zone* zone_; |
1711 Handle<Object> foreign_; | 1727 Handle<Object> foreign_; |
1712 AsmTyper* typer_; | 1728 AsmTyper* typer_; |
1713 TypeCache const& cache_; | 1729 TypeCache const& cache_; |
1714 ZoneVector<std::pair<BreakableStatement*, bool>> breakable_blocks_; | 1730 ZoneVector<std::pair<BreakableStatement*, bool>> breakable_blocks_; |
1715 uint16_t init_function_index_; | 1731 uint32_t init_function_index_; |
1716 uint32_t next_table_index_; | 1732 uint32_t next_table_index_; |
1717 ZoneHashMap function_tables_; | 1733 ZoneHashMap function_tables_; |
1718 ImportedFunctionTable imported_function_table_; | 1734 ImportedFunctionTable imported_function_table_; |
1719 const AstTypeBounds* bounds_; | 1735 const AstTypeBounds* bounds_; |
1720 | 1736 |
1721 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); | 1737 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); |
1722 | 1738 |
1723 private: | 1739 private: |
1724 DISALLOW_COPY_AND_ASSIGN(AsmWasmBuilderImpl); | 1740 DISALLOW_COPY_AND_ASSIGN(AsmWasmBuilderImpl); |
1725 }; | 1741 }; |
(...skipping 11 matching lines...) Expand all Loading... |
1737 // that zone in constructor may be thrown away once wasm module is written. | 1753 // that zone in constructor may be thrown away once wasm module is written. |
1738 WasmModuleIndex* AsmWasmBuilder::Run() { | 1754 WasmModuleIndex* AsmWasmBuilder::Run() { |
1739 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_, typer_); | 1755 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_, typer_); |
1740 impl.Compile(); | 1756 impl.Compile(); |
1741 WasmModuleWriter* writer = impl.builder_->Build(zone_); | 1757 WasmModuleWriter* writer = impl.builder_->Build(zone_); |
1742 return writer->WriteTo(zone_); | 1758 return writer->WriteTo(zone_); |
1743 } | 1759 } |
1744 } // namespace wasm | 1760 } // namespace wasm |
1745 } // namespace internal | 1761 } // namespace internal |
1746 } // namespace v8 | 1762 } // namespace v8 |
OLD | NEW |