| 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 #include "src/wasm/asm-wasm-builder.h" | 7 #include "src/wasm/asm-wasm-builder.h" |
| 8 #include "src/wasm/wasm-macro-gen.h" | 8 #include "src/wasm/wasm-macro-gen.h" |
| 9 #include "src/wasm/wasm-opcodes.h" | 9 #include "src/wasm/wasm-opcodes.h" |
| 10 | 10 |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 } else if (type->Is(cache_.kFloat64Array)) { | 718 } else if (type->Is(cache_.kFloat64Array)) { |
| 719 mtype = MachineType::Float64(); | 719 mtype = MachineType::Float64(); |
| 720 size = 8; | 720 size = 8; |
| 721 } else { | 721 } else { |
| 722 UNREACHABLE(); | 722 UNREACHABLE(); |
| 723 } | 723 } |
| 724 current_function_builder_->EmitWithU8( | 724 current_function_builder_->EmitWithU8( |
| 725 WasmOpcodes::LoadStoreOpcodeOf(mtype, is_set_op_), | 725 WasmOpcodes::LoadStoreOpcodeOf(mtype, is_set_op_), |
| 726 WasmOpcodes::LoadStoreAccessOf(false)); | 726 WasmOpcodes::LoadStoreAccessOf(false)); |
| 727 is_set_op_ = false; | 727 is_set_op_ = false; |
| 728 Literal* value = expr->key()->AsLiteral(); | 728 if (size == 1) { |
| 729 if (value) { | 729 // Allow more general expression in byte arrays than the spec |
| 730 DCHECK(value->raw_value()->IsNumber()); | 730 // strictly permits. |
| 731 DCHECK(kAstI32 == TypeOf(value)); | 731 // Early versions of Emscripten emit HEAP8[HEAP32[..]|0] in |
| 732 int val = static_cast<int>(value->raw_value()->AsNumber()); | 732 // places that strictly should be HEAP8[HEAP32[..]>>0]. |
| 733 byte code[] = {WASM_I32(val * size)}; | 733 RECURSE(Visit(expr->key())); |
| 734 current_function_builder_->EmitCode(code, sizeof(code)); | |
| 735 return; | 734 return; |
| 736 } | 735 } else { |
| 737 BinaryOperation* binop = expr->key()->AsBinaryOperation(); | 736 Literal* value = expr->key()->AsLiteral(); |
| 738 if (binop) { | 737 if (value) { |
| 739 DCHECK(Token::SAR == binop->op()); | 738 DCHECK(value->raw_value()->IsNumber()); |
| 740 DCHECK(binop->right()->AsLiteral()->raw_value()->IsNumber()); | 739 DCHECK(kAstI32 == TypeOf(value)); |
| 741 DCHECK(kAstI32 == TypeOf(binop->right()->AsLiteral())); | 740 int val = static_cast<int>(value->raw_value()->AsNumber()); |
| 742 DCHECK(size == | 741 byte code[] = {WASM_I32(val * size)}; |
| 743 1 << static_cast<int>( | 742 current_function_builder_->EmitCode(code, sizeof(code)); |
| 744 binop->right()->AsLiteral()->raw_value()->AsNumber())); | 743 return; |
| 745 // Mask bottom bits to match asm.js behavior. | 744 } |
| 746 current_function_builder_->Emit(kExprI32And); | 745 BinaryOperation* binop = expr->key()->AsBinaryOperation(); |
| 747 byte code[] = {WASM_I8(~(size - 1))}; | 746 if (binop) { |
| 748 current_function_builder_->EmitCode(code, sizeof(code)); | 747 DCHECK(Token::SAR == binop->op()); |
| 749 RECURSE(Visit(binop->left())); | 748 DCHECK(binop->right()->AsLiteral()->raw_value()->IsNumber()); |
| 750 return; | 749 DCHECK(kAstI32 == TypeOf(binop->right()->AsLiteral())); |
| 750 DCHECK(size == |
| 751 1 << static_cast<int>( |
| 752 binop->right()->AsLiteral()->raw_value()->AsNumber())); |
| 753 // Mask bottom bits to match asm.js behavior. |
| 754 current_function_builder_->Emit(kExprI32And); |
| 755 byte code[] = {WASM_I8(~(size - 1))}; |
| 756 current_function_builder_->EmitCode(code, sizeof(code)); |
| 757 RECURSE(Visit(binop->left())); |
| 758 return; |
| 759 } |
| 751 } | 760 } |
| 752 UNREACHABLE(); | 761 UNREACHABLE(); |
| 753 } | 762 } |
| 754 | 763 |
| 755 void VisitCall(Call* expr) { | 764 void VisitCall(Call* expr) { |
| 756 Call::CallType call_type = expr->GetCallType(isolate_); | 765 Call::CallType call_type = expr->GetCallType(isolate_); |
| 757 switch (call_type) { | 766 switch (call_type) { |
| 758 case Call::OTHER_CALL: { | 767 case Call::OTHER_CALL: { |
| 759 DCHECK(in_function_); | 768 DCHECK(in_function_); |
| 760 uint16_t index; | 769 uint16_t index; |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1271 // that zone in constructor may be thrown away once wasm module is written. | 1280 // that zone in constructor may be thrown away once wasm module is written. |
| 1272 WasmModuleIndex* AsmWasmBuilder::Run() { | 1281 WasmModuleIndex* AsmWasmBuilder::Run() { |
| 1273 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_); | 1282 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_); |
| 1274 impl.Compile(); | 1283 impl.Compile(); |
| 1275 WasmModuleWriter* writer = impl.builder_->Build(zone_); | 1284 WasmModuleWriter* writer = impl.builder_->Build(zone_); |
| 1276 return writer->WriteTo(zone_); | 1285 return writer->WriteTo(zone_); |
| 1277 } | 1286 } |
| 1278 } // namespace wasm | 1287 } // namespace wasm |
| 1279 } // namespace internal | 1288 } // namespace internal |
| 1280 } // namespace v8 | 1289 } // namespace v8 |
| OLD | NEW |