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

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

Issue 2094573002: [wasm] Cleaning up code (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 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/ast-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/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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 int default_block = has_default ? case_count - 1 : case_count; 378 int default_block = has_default ? case_count - 1 : case_count;
379 BlockVisitor switch_logic_block(this, nullptr, kExprBlock, false); 379 BlockVisitor switch_logic_block(this, nullptr, kExprBlock, false);
380 CaseNode* root = OrderCases(&cases, zone_); 380 CaseNode* root = OrderCases(&cases, zone_);
381 HandleCase(root, case_to_block, tag, default_block, 0); 381 HandleCase(root, case_to_block, tag, default_block, 0);
382 if (root->left != nullptr || root->right != nullptr || 382 if (root->left != nullptr || root->right != nullptr ||
383 root->begin == root->end) { 383 root->begin == root->end) {
384 current_function_builder_->EmitWithU8(kExprBr, ARITY_0); 384 current_function_builder_->EmitWithU8(kExprBr, ARITY_0);
385 current_function_builder_->EmitVarInt(default_block); 385 current_function_builder_->EmitVarInt(default_block);
386 } 386 }
387 } 387 }
388 for (int i = 0; i < case_count; i++) { 388 for (int i = 0; i < case_count; ++i) {
389 CaseClause* clause = clauses->at(i); 389 CaseClause* clause = clauses->at(i);
390 RECURSE(VisitStatements(clause->statements())); 390 RECURSE(VisitStatements(clause->statements()));
391 BlockVisitor* v = blocks.at(case_count - i - 1); 391 BlockVisitor* v = blocks.at(case_count - i - 1);
392 blocks.pop_back(); 392 blocks.pop_back();
393 delete v; 393 delete v;
394 } 394 }
395 } 395 }
396 396
397 void VisitCaseClause(CaseClause* clause) override { UNREACHABLE(); } 397 void VisitCaseClause(CaseClause* clause) override { UNREACHABLE(); }
398 398
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 void VisitFunctionLiteral(FunctionLiteral* expr) override { 461 void VisitFunctionLiteral(FunctionLiteral* expr) override {
462 Scope* scope = expr->scope(); 462 Scope* scope = expr->scope();
463 if (scope_ == kFuncScope) { 463 if (scope_ == kFuncScope) {
464 if (bounds_->get(expr).lower->IsFunction()) { 464 if (bounds_->get(expr).lower->IsFunction()) {
465 // Build the signature for the function. 465 // Build the signature for the function.
466 FunctionType* func_type = bounds_->get(expr).lower->AsFunction(); 466 FunctionType* func_type = bounds_->get(expr).lower->AsFunction();
467 LocalType return_type = TypeFrom(func_type->Result()); 467 LocalType return_type = TypeFrom(func_type->Result());
468 FunctionSig::Builder b(zone(), return_type == kAstStmt ? 0 : 1, 468 FunctionSig::Builder b(zone(), return_type == kAstStmt ? 0 : 1,
469 func_type->Arity()); 469 func_type->Arity());
470 if (return_type != kAstStmt) b.AddReturn(return_type); 470 if (return_type != kAstStmt) b.AddReturn(return_type);
471 for (int i = 0; i < expr->parameter_count(); i++) { 471 for (int i = 0; i < expr->parameter_count(); ++i) {
472 LocalType type = TypeFrom(func_type->Parameter(i)); 472 LocalType type = TypeFrom(func_type->Parameter(i));
473 DCHECK_NE(kAstStmt, type); 473 DCHECK_NE(kAstStmt, type);
474 b.AddParam(type); 474 b.AddParam(type);
475 InsertParameter(scope->parameter(i), type, i); 475 InsertParameter(scope->parameter(i), type, i);
476 } 476 }
477 current_function_builder_->SetSignature(b.Build()); 477 current_function_builder_->SetSignature(b.Build());
478 } else { 478 } else {
479 UNREACHABLE(); 479 UNREACHABLE();
480 } 480 }
481 } 481 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 638
639 void AddFunctionTable(VariableProxy* table, ArrayLiteral* funcs) { 639 void AddFunctionTable(VariableProxy* table, ArrayLiteral* funcs) {
640 FunctionType* func_type = 640 FunctionType* func_type =
641 bounds_->get(funcs).lower->AsArray()->Element()->AsFunction(); 641 bounds_->get(funcs).lower->AsArray()->Element()->AsFunction();
642 LocalType return_type = TypeFrom(func_type->Result()); 642 LocalType return_type = TypeFrom(func_type->Result());
643 FunctionSig::Builder sig(zone(), return_type == kAstStmt ? 0 : 1, 643 FunctionSig::Builder sig(zone(), return_type == kAstStmt ? 0 : 1,
644 func_type->Arity()); 644 func_type->Arity());
645 if (return_type != kAstStmt) { 645 if (return_type != kAstStmt) {
646 sig.AddReturn(static_cast<LocalType>(return_type)); 646 sig.AddReturn(static_cast<LocalType>(return_type));
647 } 647 }
648 for (int i = 0; i < func_type->Arity(); i++) { 648 for (int i = 0; i < func_type->Arity(); ++i) {
649 sig.AddParam(TypeFrom(func_type->Parameter(i))); 649 sig.AddParam(TypeFrom(func_type->Parameter(i)));
650 } 650 }
651 uint32_t signature_index = builder_->AddSignature(sig.Build()); 651 uint32_t signature_index = builder_->AddSignature(sig.Build());
652 InsertFunctionTable(table->var(), next_table_index_, signature_index); 652 InsertFunctionTable(table->var(), next_table_index_, signature_index);
653 next_table_index_ += funcs->values()->length(); 653 next_table_index_ += funcs->values()->length();
654 for (int i = 0; i < funcs->values()->length(); i++) { 654 for (int i = 0; i < funcs->values()->length(); ++i) {
655 VariableProxy* func = funcs->values()->at(i)->AsVariableProxy(); 655 VariableProxy* func = funcs->values()->at(i)->AsVariableProxy();
656 DCHECK_NOT_NULL(func); 656 DCHECK_NOT_NULL(func);
657 builder_->AddIndirectFunction(LookupOrInsertFunction(func->var())); 657 builder_->AddIndirectFunction(LookupOrInsertFunction(func->var()));
658 } 658 }
659 } 659 }
660 660
661 struct FunctionTableIndices : public ZoneObject { 661 struct FunctionTableIndices : public ZoneObject {
662 uint32_t start_index; 662 uint32_t start_index;
663 uint32_t signature_index; 663 uint32_t signature_index;
664 }; 664 };
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 VariableProxy* vp = expr->expression()->AsVariableProxy(); 1279 VariableProxy* vp = expr->expression()->AsVariableProxy();
1280 if (vp != nullptr && 1280 if (vp != nullptr &&
1281 Type::Any()->Is(bounds_->get(vp).lower->AsFunction()->Result())) { 1281 Type::Any()->Is(bounds_->get(vp).lower->AsFunction()->Result())) {
1282 LocalType return_type = TypeOf(expr); 1282 LocalType return_type = TypeOf(expr);
1283 ZoneList<Expression*>* args = expr->arguments(); 1283 ZoneList<Expression*>* args = expr->arguments();
1284 FunctionSig::Builder sig(zone(), return_type == kAstStmt ? 0 : 1, 1284 FunctionSig::Builder sig(zone(), return_type == kAstStmt ? 0 : 1,
1285 args->length()); 1285 args->length());
1286 if (return_type != kAstStmt) { 1286 if (return_type != kAstStmt) {
1287 sig.AddReturn(return_type); 1287 sig.AddReturn(return_type);
1288 } 1288 }
1289 for (int i = 0; i < args->length(); i++) { 1289 for (int i = 0; i < args->length(); ++i) {
1290 sig.AddParam(TypeOf(args->at(i))); 1290 sig.AddParam(TypeOf(args->at(i)));
1291 } 1291 }
1292 index = 1292 index =
1293 imported_function_table_.GetFunctionIndex(vp->var(), sig.Build()); 1293 imported_function_table_.GetFunctionIndex(vp->var(), sig.Build());
1294 VisitCallArgs(expr); 1294 VisitCallArgs(expr);
1295 current_function_builder_->Emit(kExprCallImport); 1295 current_function_builder_->Emit(kExprCallImport);
1296 current_function_builder_->EmitVarInt(expr->arguments()->length()); 1296 current_function_builder_->EmitVarInt(expr->arguments()->length());
1297 current_function_builder_->EmitVarInt(index); 1297 current_function_builder_->EmitVarInt(index);
1298 } else { 1298 } else {
1299 index = LookupOrInsertFunction(vp->var()); 1299 index = LookupOrInsertFunction(vp->var());
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
1778 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, typer_); 1778 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, typer_);
1779 impl.Build(); 1779 impl.Build();
1780 *foreign_args = impl.GetForeignArgs(); 1780 *foreign_args = impl.GetForeignArgs();
1781 ZoneBuffer* buffer = new (zone_) ZoneBuffer(zone_); 1781 ZoneBuffer* buffer = new (zone_) ZoneBuffer(zone_);
1782 impl.builder_->WriteTo(*buffer); 1782 impl.builder_->WriteTo(*buffer);
1783 return buffer; 1783 return buffer;
1784 } 1784 }
1785 } // namespace wasm 1785 } // namespace wasm
1786 } // namespace internal 1786 } // namespace internal
1787 } // namespace v8 1787 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/wasm/ast-decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698