| 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 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 if (!(value->IsNumber() || expr->raw_value()->IsTrue() || | 676 if (!(value->IsNumber() || expr->raw_value()->IsTrue() || |
| 677 expr->raw_value()->IsFalse()) || | 677 expr->raw_value()->IsFalse()) || |
| 678 (scope_ != kFuncScope && scope_ != kInitScope)) { | 678 (scope_ != kFuncScope && scope_ != kInitScope)) { |
| 679 return; | 679 return; |
| 680 } | 680 } |
| 681 AsmType* type = typer_->TypeOf(expr); | 681 AsmType* type = typer_->TypeOf(expr); |
| 682 DCHECK_NE(type, AsmType::None()); | 682 DCHECK_NE(type, AsmType::None()); |
| 683 | 683 |
| 684 if (type->IsA(AsmType::Signed())) { | 684 if (type->IsA(AsmType::Signed())) { |
| 685 int32_t i = 0; | 685 int32_t i = 0; |
| 686 if (!value->ToInt32(&i)) { | 686 CHECK(value->ToInt32(&i)); |
| 687 UNREACHABLE(); | 687 current_function_builder_->EmitI32Const(i); |
| 688 } | |
| 689 byte code[] = {WASM_I32V(i)}; | |
| 690 current_function_builder_->EmitCode(code, sizeof(code)); | |
| 691 } else if (type->IsA(AsmType::Unsigned()) || type->IsA(AsmType::FixNum())) { | 688 } else if (type->IsA(AsmType::Unsigned()) || type->IsA(AsmType::FixNum())) { |
| 692 uint32_t u = 0; | 689 uint32_t u = 0; |
| 693 if (!value->ToUint32(&u)) { | 690 CHECK(value->ToUint32(&u)); |
| 694 UNREACHABLE(); | 691 current_function_builder_->EmitI32Const(bit_cast<int32_t>(u)); |
| 695 } | |
| 696 int32_t i = static_cast<int32_t>(u); | |
| 697 byte code[] = {WASM_I32V(i)}; | |
| 698 current_function_builder_->EmitCode(code, sizeof(code)); | |
| 699 } else if (type->IsA(AsmType::Int())) { | 692 } else if (type->IsA(AsmType::Int())) { |
| 700 // The parser can collapse !0, !1 etc to true / false. | 693 // The parser can collapse !0, !1 etc to true / false. |
| 701 // Allow these as int literals. | 694 // Allow these as int literals. |
| 702 if (expr->raw_value()->IsTrue()) { | 695 if (expr->raw_value()->IsTrue()) { |
| 703 byte code[] = {WASM_I32V(1)}; | 696 byte code[] = {WASM_ONE}; |
| 704 current_function_builder_->EmitCode(code, sizeof(code)); | 697 current_function_builder_->EmitCode(code, sizeof(code)); |
| 705 } else if (expr->raw_value()->IsFalse()) { | 698 } else if (expr->raw_value()->IsFalse()) { |
| 706 byte code[] = {WASM_I32V(0)}; | 699 byte code[] = {WASM_ZERO}; |
| 707 current_function_builder_->EmitCode(code, sizeof(code)); | 700 current_function_builder_->EmitCode(code, sizeof(code)); |
| 708 } else if (expr->raw_value()->IsNumber()) { | 701 } else if (expr->raw_value()->IsNumber()) { |
| 709 // This can happen when -x becomes x * -1 (due to the parser). | 702 // This can happen when -x becomes x * -1 (due to the parser). |
| 710 int32_t i = 0; | 703 int32_t i = 0; |
| 711 if (!value->ToInt32(&i) || i != -1) { | 704 CHECK(value->ToInt32(&i) && i == -1); |
| 712 UNREACHABLE(); | 705 byte code[] = {WASM_I32V_1(-1)}; |
| 713 } | |
| 714 byte code[] = {WASM_I32V(i)}; | |
| 715 current_function_builder_->EmitCode(code, sizeof(code)); | 706 current_function_builder_->EmitCode(code, sizeof(code)); |
| 716 } else { | 707 } else { |
| 717 UNREACHABLE(); | 708 UNREACHABLE(); |
| 718 } | 709 } |
| 719 } else if (type->IsA(AsmType::Double())) { | 710 } else if (type->IsA(AsmType::Double())) { |
| 720 // TODO(bradnelson): Pattern match the case where negation occurs and | 711 // TODO(bradnelson): Pattern match the case where negation occurs and |
| 721 // emit f64.neg instead. | 712 // emit f64.neg instead. |
| 722 double val = expr->raw_value()->AsNumber(); | 713 double val = expr->raw_value()->AsNumber(); |
| 723 byte code[] = {WASM_F64(val)}; | 714 byte code[] = {WASM_F64(val)}; |
| 724 current_function_builder_->EmitCode(code, sizeof(code)); | 715 current_function_builder_->EmitCode(code, sizeof(code)); |
| (...skipping 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2015 impl.builder_->WriteAsmJsOffsetTable(*asm_offsets_buffer); | 2006 impl.builder_->WriteAsmJsOffsetTable(*asm_offsets_buffer); |
| 2016 return {module_buffer, asm_offsets_buffer, success}; | 2007 return {module_buffer, asm_offsets_buffer, success}; |
| 2017 } | 2008 } |
| 2018 | 2009 |
| 2019 const char* AsmWasmBuilder::foreign_init_name = "__foreign_init__"; | 2010 const char* AsmWasmBuilder::foreign_init_name = "__foreign_init__"; |
| 2020 const char* AsmWasmBuilder::single_function_name = "__single_function__"; | 2011 const char* AsmWasmBuilder::single_function_name = "__single_function__"; |
| 2021 | 2012 |
| 2022 } // namespace wasm | 2013 } // namespace wasm |
| 2023 } // namespace internal | 2014 } // namespace internal |
| 2024 } // namespace v8 | 2015 } // namespace v8 |
| OLD | NEW |