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

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

Issue 2372823004: [wasm] asm.js: Work around parser converting !0 and !1 to boolean. (Closed)
Patch Set: Created 4 years, 2 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/asmjs/asm-typer.cc ('k') | test/mjsunit/wasm/asm-wasm.js » ('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 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 WasmFunctionBuilder* function = LookupOrInsertFunction(var); 582 WasmFunctionBuilder* function = LookupOrInsertFunction(var);
583 function->SetExported(); 583 function->SetExported();
584 function->SetName( 584 function->SetName(
585 AsmWasmBuilder::single_function_name, 585 AsmWasmBuilder::single_function_name,
586 static_cast<int>(strlen(AsmWasmBuilder::single_function_name))); 586 static_cast<int>(strlen(AsmWasmBuilder::single_function_name)));
587 } 587 }
588 } 588 }
589 589
590 void VisitLiteral(Literal* expr) { 590 void VisitLiteral(Literal* expr) {
591 Handle<Object> value = expr->value(); 591 Handle<Object> value = expr->value();
592 if (!value->IsNumber() || (scope_ != kFuncScope && scope_ != kInitScope)) { 592 if (!(value->IsNumber() || expr->raw_value()->IsTrue() ||
593 expr->raw_value()->IsFalse()) ||
594 (scope_ != kFuncScope && scope_ != kInitScope)) {
593 return; 595 return;
594 } 596 }
595 AsmType* type = typer_->TypeOf(expr); 597 AsmType* type = typer_->TypeOf(expr);
596 DCHECK_NE(type, AsmType::None()); 598 DCHECK_NE(type, AsmType::None());
597 599
598 if (type->IsA(AsmType::Signed())) { 600 if (type->IsA(AsmType::Signed())) {
599 int32_t i = 0; 601 int32_t i = 0;
600 if (!value->ToInt32(&i)) { 602 if (!value->ToInt32(&i)) {
601 UNREACHABLE(); 603 UNREACHABLE();
602 } 604 }
603 byte code[] = {WASM_I32V(i)}; 605 byte code[] = {WASM_I32V(i)};
604 current_function_builder_->EmitCode(code, sizeof(code)); 606 current_function_builder_->EmitCode(code, sizeof(code));
605 } else if (type->IsA(AsmType::Unsigned()) || type->IsA(AsmType::FixNum())) { 607 } else if (type->IsA(AsmType::Unsigned()) || type->IsA(AsmType::FixNum())) {
606 uint32_t u = 0; 608 uint32_t u = 0;
607 if (!value->ToUint32(&u)) { 609 if (!value->ToUint32(&u)) {
608 UNREACHABLE(); 610 UNREACHABLE();
609 } 611 }
610 int32_t i = static_cast<int32_t>(u); 612 int32_t i = static_cast<int32_t>(u);
611 byte code[] = {WASM_I32V(i)}; 613 byte code[] = {WASM_I32V(i)};
612 current_function_builder_->EmitCode(code, sizeof(code)); 614 current_function_builder_->EmitCode(code, sizeof(code));
615 } else if (type->IsA(AsmType::Int())) {
616 // The parser can collapse !0, !1 etc to true / false.
617 // Allow these as int literals.
618 if (expr->raw_value()->IsTrue()) {
619 byte code[] = {WASM_I32V(1)};
620 current_function_builder_->EmitCode(code, sizeof(code));
621 } else if (expr->raw_value()->IsFalse()) {
622 byte code[] = {WASM_I32V(0)};
623 current_function_builder_->EmitCode(code, sizeof(code));
624 } else {
625 UNREACHABLE();
626 }
613 } else if (type->IsA(AsmType::Double())) { 627 } else if (type->IsA(AsmType::Double())) {
614 double val = expr->raw_value()->AsNumber(); 628 double val = expr->raw_value()->AsNumber();
615 byte code[] = {WASM_F64(val)}; 629 byte code[] = {WASM_F64(val)};
616 current_function_builder_->EmitCode(code, sizeof(code)); 630 current_function_builder_->EmitCode(code, sizeof(code));
617 } else { 631 } else {
618 UNREACHABLE(); 632 UNREACHABLE();
619 } 633 }
620 } 634 }
621 635
622 void VisitRegExpLiteral(RegExpLiteral* expr) { UNREACHABLE(); } 636 void VisitRegExpLiteral(RegExpLiteral* expr) { UNREACHABLE(); }
(...skipping 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 impl.builder_->WriteTo(*buffer); 1901 impl.builder_->WriteTo(*buffer);
1888 return buffer; 1902 return buffer;
1889 } 1903 }
1890 1904
1891 const char* AsmWasmBuilder::foreign_init_name = "__foreign_init__"; 1905 const char* AsmWasmBuilder::foreign_init_name = "__foreign_init__";
1892 const char* AsmWasmBuilder::single_function_name = "__single_function__"; 1906 const char* AsmWasmBuilder::single_function_name = "__single_function__";
1893 1907
1894 } // namespace wasm 1908 } // namespace wasm
1895 } // namespace internal 1909 } // namespace internal
1896 } // namespace v8 1910 } // namespace v8
OLDNEW
« no previous file with comments | « src/asmjs/asm-typer.cc ('k') | test/mjsunit/wasm/asm-wasm.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698