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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "src/assembler-inl.h" | 7 #include "src/assembler-inl.h" |
8 #include "src/base/adapters.h" | 8 #include "src/base/adapters.h" |
9 #include "src/base/atomic-utils.h" | 9 #include "src/base/atomic-utils.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1519 if (value->IsSmi()) { | 1519 if (value->IsSmi()) { |
1520 num = Smi::cast(*value)->value(); | 1520 num = Smi::cast(*value)->value(); |
1521 } else if (value->IsHeapNumber()) { | 1521 } else if (value->IsHeapNumber()) { |
1522 num = HeapNumber::cast(*value)->value(); | 1522 num = HeapNumber::cast(*value)->value(); |
1523 } else { | 1523 } else { |
1524 UNREACHABLE(); | 1524 UNREACHABLE(); |
1525 } | 1525 } |
1526 TRACE("init [globals+%u] = %lf, type = %s\n", global.offset, num, | 1526 TRACE("init [globals+%u] = %lf, type = %s\n", global.offset, num, |
1527 WasmOpcodes::TypeName(global.type)); | 1527 WasmOpcodes::TypeName(global.type)); |
1528 switch (global.type) { | 1528 switch (global.type) { |
1529 case kAstI32: | 1529 case kWasmI32: |
1530 *GetRawGlobalPtr<int32_t>(global) = static_cast<int32_t>(num); | 1530 *GetRawGlobalPtr<int32_t>(global) = static_cast<int32_t>(num); |
1531 break; | 1531 break; |
1532 case kAstI64: | 1532 case kWasmI64: |
1533 // TODO(titzer): initialization of imported i64 globals. | 1533 // TODO(titzer): initialization of imported i64 globals. |
1534 UNREACHABLE(); | 1534 UNREACHABLE(); |
1535 break; | 1535 break; |
1536 case kAstF32: | 1536 case kWasmF32: |
1537 *GetRawGlobalPtr<float>(global) = static_cast<float>(num); | 1537 *GetRawGlobalPtr<float>(global) = static_cast<float>(num); |
1538 break; | 1538 break; |
1539 case kAstF64: | 1539 case kWasmF64: |
1540 *GetRawGlobalPtr<double>(global) = static_cast<double>(num); | 1540 *GetRawGlobalPtr<double>(global) = static_cast<double>(num); |
1541 break; | 1541 break; |
1542 default: | 1542 default: |
1543 UNREACHABLE(); | 1543 UNREACHABLE(); |
1544 } | 1544 } |
1545 } | 1545 } |
1546 | 1546 |
1547 // Process the imports, including functions, tables, globals, and memory, in | 1547 // Process the imports, including functions, tables, globals, and memory, in |
1548 // order, loading them from the {ffi_} object. Returns the number of imported | 1548 // order, loading them from the {ffi_} object. Returns the number of imported |
1549 // functions. | 1549 // functions. |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1700 case WasmInitExpr::kF64Const: | 1700 case WasmInitExpr::kF64Const: |
1701 *GetRawGlobalPtr<double>(global) = global.init.val.f64_const; | 1701 *GetRawGlobalPtr<double>(global) = global.init.val.f64_const; |
1702 break; | 1702 break; |
1703 case WasmInitExpr::kGlobalIndex: { | 1703 case WasmInitExpr::kGlobalIndex: { |
1704 // Initialize with another global. | 1704 // Initialize with another global. |
1705 uint32_t new_offset = global.offset; | 1705 uint32_t new_offset = global.offset; |
1706 uint32_t old_offset = | 1706 uint32_t old_offset = |
1707 module_->globals[global.init.val.global_index].offset; | 1707 module_->globals[global.init.val.global_index].offset; |
1708 TRACE("init [globals+%u] = [globals+%d]\n", global.offset, | 1708 TRACE("init [globals+%u] = [globals+%d]\n", global.offset, |
1709 old_offset); | 1709 old_offset); |
1710 size_t size = (global.type == kAstI64 || global.type == kAstF64) | 1710 size_t size = (global.type == kWasmI64 || global.type == kWasmF64) |
1711 ? sizeof(double) | 1711 ? sizeof(double) |
1712 : sizeof(int32_t); | 1712 : sizeof(int32_t); |
1713 memcpy(raw_buffer_ptr(globals_, new_offset), | 1713 memcpy(raw_buffer_ptr(globals_, new_offset), |
1714 raw_buffer_ptr(globals_, old_offset), size); | 1714 raw_buffer_ptr(globals_, old_offset), size); |
1715 break; | 1715 break; |
1716 } | 1716 } |
1717 case WasmInitExpr::kNone: | 1717 case WasmInitExpr::kNone: |
1718 // Happens with imported globals. | 1718 // Happens with imported globals. |
1719 break; | 1719 break; |
1720 default: | 1720 default: |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1851 } | 1851 } |
1852 | 1852 |
1853 desc.set_value(memory_object); | 1853 desc.set_value(memory_object); |
1854 break; | 1854 break; |
1855 } | 1855 } |
1856 case kExternalGlobal: { | 1856 case kExternalGlobal: { |
1857 // Export the value of the global variable as a number. | 1857 // Export the value of the global variable as a number. |
1858 WasmGlobal& global = module_->globals[exp.index]; | 1858 WasmGlobal& global = module_->globals[exp.index]; |
1859 double num = 0; | 1859 double num = 0; |
1860 switch (global.type) { | 1860 switch (global.type) { |
1861 case kAstI32: | 1861 case kWasmI32: |
1862 num = *GetRawGlobalPtr<int32_t>(global); | 1862 num = *GetRawGlobalPtr<int32_t>(global); |
1863 break; | 1863 break; |
1864 case kAstF32: | 1864 case kWasmF32: |
1865 num = *GetRawGlobalPtr<float>(global); | 1865 num = *GetRawGlobalPtr<float>(global); |
1866 break; | 1866 break; |
1867 case kAstF64: | 1867 case kWasmF64: |
1868 num = *GetRawGlobalPtr<double>(global); | 1868 num = *GetRawGlobalPtr<double>(global); |
1869 break; | 1869 break; |
1870 default: | 1870 default: |
1871 UNREACHABLE(); | 1871 UNREACHABLE(); |
1872 } | 1872 } |
1873 desc.set_value(isolate_->factory()->NewNumber(num)); | 1873 desc.set_value(isolate_->factory()->NewNumber(num)); |
1874 break; | 1874 break; |
1875 } | 1875 } |
1876 default: | 1876 default: |
1877 UNREACHABLE(); | 1877 UNREACHABLE(); |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2298 CHECK(!compiled_module->has_weak_owning_instance()); | 2298 CHECK(!compiled_module->has_weak_owning_instance()); |
2299 } | 2299 } |
2300 | 2300 |
2301 void testing::ValidateOrphanedInstance(Isolate* isolate, | 2301 void testing::ValidateOrphanedInstance(Isolate* isolate, |
2302 Handle<WasmInstanceObject> instance) { | 2302 Handle<WasmInstanceObject> instance) { |
2303 DisallowHeapAllocation no_gc; | 2303 DisallowHeapAllocation no_gc; |
2304 WasmCompiledModule* compiled_module = instance->compiled_module(); | 2304 WasmCompiledModule* compiled_module = instance->compiled_module(); |
2305 CHECK(compiled_module->has_weak_wasm_module()); | 2305 CHECK(compiled_module->has_weak_wasm_module()); |
2306 CHECK(compiled_module->ptr_to_weak_wasm_module()->cleared()); | 2306 CHECK(compiled_module->ptr_to_weak_wasm_module()->cleared()); |
2307 } | 2307 } |
OLD | NEW |