| 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 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 DCHECK_NE(kAstStmt, var_type); | 454 DCHECK_NE(kAstStmt, var_type); |
| 455 if (var->IsContextSlot()) { | 455 if (var->IsContextSlot()) { |
| 456 AddLeb128(LookupOrInsertGlobal(var, var_type), false); | 456 AddLeb128(LookupOrInsertGlobal(var, var_type), false); |
| 457 } else { | 457 } else { |
| 458 AddLeb128(LookupOrInsertLocal(var, var_type), true); | 458 AddLeb128(LookupOrInsertLocal(var, var_type), true); |
| 459 } | 459 } |
| 460 } | 460 } |
| 461 } | 461 } |
| 462 | 462 |
| 463 void VisitLiteral(Literal* expr) { | 463 void VisitLiteral(Literal* expr) { |
| 464 if (in_function_) { | 464 Handle<Object> value = expr->value(); |
| 465 if (expr->raw_value()->IsNumber()) { | 465 if (!in_function_ || !value->IsNumber()) { |
| 466 LocalType type = TypeOf(expr); | 466 return; |
| 467 switch (type) { | 467 } |
| 468 case kAstI32: { | 468 Type* type = expr->bounds().upper; |
| 469 int val = static_cast<int>(expr->raw_value()->AsNumber()); | 469 if (type->Is(cache_.kAsmSigned)) { |
| 470 // TODO(bradnelson): variable size | 470 int32_t i; |
| 471 byte code[] = {WASM_I32V(val)}; | 471 if (!value->ToInt32(&i)) { |
| 472 current_function_builder_->EmitCode(code, sizeof(code)); | 472 UNREACHABLE(); |
| 473 break; | |
| 474 } | |
| 475 case kAstF32: { | |
| 476 float val = static_cast<float>(expr->raw_value()->AsNumber()); | |
| 477 byte code[] = {WASM_F32(val)}; | |
| 478 current_function_builder_->EmitCode(code, sizeof(code)); | |
| 479 break; | |
| 480 } | |
| 481 case kAstF64: { | |
| 482 double val = static_cast<double>(expr->raw_value()->AsNumber()); | |
| 483 byte code[] = {WASM_F64(val)}; | |
| 484 current_function_builder_->EmitCode(code, sizeof(code)); | |
| 485 break; | |
| 486 } | |
| 487 default: | |
| 488 UNREACHABLE(); | |
| 489 } | |
| 490 } | 473 } |
| 474 byte code[] = {WASM_I32V(i)}; |
| 475 current_function_builder_->EmitCode(code, sizeof(code)); |
| 476 } else if (type->Is(cache_.kAsmUnsigned) || type->Is(cache_.kAsmFixnum)) { |
| 477 uint32_t u; |
| 478 if (!value->ToUint32(&u)) { |
| 479 UNREACHABLE(); |
| 480 } |
| 481 int32_t i = static_cast<int32_t>(u); |
| 482 byte code[] = {WASM_I32V(i)}; |
| 483 current_function_builder_->EmitCode(code, sizeof(code)); |
| 484 } else if (type->Is(cache_.kAsmDouble)) { |
| 485 double val = expr->raw_value()->AsNumber(); |
| 486 byte code[] = {WASM_F64(val)}; |
| 487 current_function_builder_->EmitCode(code, sizeof(code)); |
| 488 } else { |
| 489 UNREACHABLE(); |
| 491 } | 490 } |
| 492 } | 491 } |
| 493 | 492 |
| 494 void VisitRegExpLiteral(RegExpLiteral* expr) { UNREACHABLE(); } | 493 void VisitRegExpLiteral(RegExpLiteral* expr) { UNREACHABLE(); } |
| 495 | 494 |
| 496 void VisitObjectLiteral(ObjectLiteral* expr) { | 495 void VisitObjectLiteral(ObjectLiteral* expr) { |
| 497 ZoneList<ObjectLiteralProperty*>* props = expr->properties(); | 496 ZoneList<ObjectLiteralProperty*>* props = expr->properties(); |
| 498 for (int i = 0; i < props->length(); ++i) { | 497 for (int i = 0; i < props->length(); ++i) { |
| 499 ObjectLiteralProperty* prop = props->at(i); | 498 ObjectLiteralProperty* prop = props->at(i); |
| 500 DCHECK(marking_exported); | 499 DCHECK(marking_exported); |
| (...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1534 // that zone in constructor may be thrown away once wasm module is written. | 1533 // that zone in constructor may be thrown away once wasm module is written. |
| 1535 WasmModuleIndex* AsmWasmBuilder::Run() { | 1534 WasmModuleIndex* AsmWasmBuilder::Run() { |
| 1536 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_, typer_); | 1535 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_, typer_); |
| 1537 impl.Compile(); | 1536 impl.Compile(); |
| 1538 WasmModuleWriter* writer = impl.builder_->Build(zone_); | 1537 WasmModuleWriter* writer = impl.builder_->Build(zone_); |
| 1539 return writer->WriteTo(zone_); | 1538 return writer->WriteTo(zone_); |
| 1540 } | 1539 } |
| 1541 } // namespace wasm | 1540 } // namespace wasm |
| 1542 } // namespace internal | 1541 } // namespace internal |
| 1543 } // namespace v8 | 1542 } // namespace v8 |
| OLD | NEW |