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

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

Issue 1895013002: [wasm] Introduce Encoder::GetLocal and Encoder::SetLocal utilities. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 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 | « no previous file | 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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 default: { return false; } 503 default: { return false; }
504 } 504 }
505 byte code[] = {WASM_F64(value)}; 505 byte code[] = {WASM_F64(value)};
506 current_function_builder_->EmitCode(code, sizeof(code)); 506 current_function_builder_->EmitCode(code, sizeof(code));
507 return true; 507 return true;
508 } 508 }
509 509
510 void VisitVariableProxy(VariableProxy* expr) { 510 void VisitVariableProxy(VariableProxy* expr) {
511 if (in_function_) { 511 if (in_function_) {
512 Variable* var = expr->var(); 512 Variable* var = expr->var();
513 LocalType var_type = TypeOf(expr);
513 if (is_set_op_) { 514 if (is_set_op_) {
515 is_set_op_ = false;
514 if (var->IsContextSlot()) { 516 if (var->IsContextSlot()) {
515 current_function_builder_->Emit(kExprStoreGlobal); 517 return current_function_builder_->EmitWithVarInt(
518 kExprStoreGlobal, LookupOrInsertGlobal(var, var_type));
516 } else { 519 } else {
517 current_function_builder_->Emit(kExprSetLocal); 520 return current_function_builder_->EmitSetLocal(
521 LookupOrInsertLocal(var, var_type));
518 } 522 }
519 is_set_op_ = false;
520 } else { 523 } else {
521 if (VisitStdlibConstant(var)) { 524 if (VisitStdlibConstant(var)) {
522 return; 525 return;
523 } 526 }
524 if (var->IsContextSlot()) { 527 if (var->IsContextSlot()) {
525 current_function_builder_->Emit(kExprLoadGlobal); 528 return current_function_builder_->EmitWithVarInt(
529 kExprLoadGlobal, LookupOrInsertGlobal(var, var_type));
526 } else { 530 } else {
527 current_function_builder_->Emit(kExprGetLocal); 531 return current_function_builder_->EmitGetLocal(
532 LookupOrInsertLocal(var, var_type));
528 } 533 }
529 } 534 }
530 LocalType var_type = TypeOf(expr);
531 DCHECK_NE(kAstStmt, var_type);
532 if (var->IsContextSlot()) {
533 AddLeb128(LookupOrInsertGlobal(var, var_type), false);
534 } else {
535 AddLeb128(LookupOrInsertLocal(var, var_type), true);
536 }
537 } 535 }
538 } 536 }
539 537
540 void VisitLiteral(Literal* expr) { 538 void VisitLiteral(Literal* expr) {
541 Handle<Object> value = expr->value(); 539 Handle<Object> value = expr->value();
542 if (!in_function_ || !value->IsNumber()) { 540 if (!in_function_ || !value->IsNumber()) {
543 return; 541 return;
544 } 542 }
545 Type* type = expr->bounds().upper; 543 Type* type = expr->bounds().upper;
546 if (type->Is(cache_.kAsmSigned)) { 544 if (type->Is(cache_.kAsmSigned)) {
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
1380 break; 1378 break;
1381 } 1379 }
1382 default: 1380 default:
1383 UNREACHABLE(); 1381 UNREACHABLE();
1384 } 1382 }
1385 RECURSE(Visit(expr->left())); 1383 RECURSE(Visit(expr->left()));
1386 RECURSE(Visit(expr->right())); 1384 RECURSE(Visit(expr->right()));
1387 } 1385 }
1388 } 1386 }
1389 1387
1390 void AddLeb128(uint32_t index, bool is_local) {
1391 std::vector<uint8_t> index_vec = UnsignedLEB128From(index);
1392 if (is_local) {
1393 uint32_t pos_of_index[1] = {0};
1394 current_function_builder_->EmitCode(
1395 &index_vec[0], static_cast<uint32_t>(index_vec.size()), pos_of_index,
1396 1);
1397 } else {
1398 current_function_builder_->EmitCode(
1399 &index_vec[0], static_cast<uint32_t>(index_vec.size()));
1400 }
1401 }
1402
1403 void VisitCompareOperation(CompareOperation* expr) { 1388 void VisitCompareOperation(CompareOperation* expr) {
1404 switch (expr->op()) { 1389 switch (expr->op()) {
1405 BINOP_CASE(Token::EQ, Eq, NON_SIGNED_BINOP, false); 1390 BINOP_CASE(Token::EQ, Eq, NON_SIGNED_BINOP, false);
1406 BINOP_CASE(Token::LT, Lt, SIGNED_BINOP, false); 1391 BINOP_CASE(Token::LT, Lt, SIGNED_BINOP, false);
1407 BINOP_CASE(Token::LTE, Le, SIGNED_BINOP, false); 1392 BINOP_CASE(Token::LTE, Le, SIGNED_BINOP, false);
1408 BINOP_CASE(Token::GT, Gt, SIGNED_BINOP, false); 1393 BINOP_CASE(Token::GT, Gt, SIGNED_BINOP, false);
1409 BINOP_CASE(Token::GTE, Ge, SIGNED_BINOP, false); 1394 BINOP_CASE(Token::GTE, Ge, SIGNED_BINOP, false);
1410 default: 1395 default:
1411 UNREACHABLE(); 1396 UNREACHABLE();
1412 } 1397 }
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 // that zone in constructor may be thrown away once wasm module is written. 1595 // that zone in constructor may be thrown away once wasm module is written.
1611 WasmModuleIndex* AsmWasmBuilder::Run() { 1596 WasmModuleIndex* AsmWasmBuilder::Run() {
1612 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_, typer_); 1597 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_, typer_);
1613 impl.Compile(); 1598 impl.Compile();
1614 WasmModuleWriter* writer = impl.builder_->Build(zone_); 1599 WasmModuleWriter* writer = impl.builder_->Build(zone_);
1615 return writer->WriteTo(zone_); 1600 return writer->WriteTo(zone_);
1616 } 1601 }
1617 } // namespace wasm 1602 } // namespace wasm
1618 } // namespace internal 1603 } // namespace internal
1619 } // namespace v8 1604 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/wasm/encoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698