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 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1352 sig.AddReturn(return_type); | 1352 sig.AddReturn(return_type); |
1353 } else { | 1353 } else { |
1354 returns_value = false; | 1354 returns_value = false; |
1355 } | 1355 } |
1356 for (int i = 0; i < args->length(); ++i) { | 1356 for (int i = 0; i < args->length(); ++i) { |
1357 sig.AddParam(TypeOf(args->at(i))); | 1357 sig.AddParam(TypeOf(args->at(i))); |
1358 } | 1358 } |
1359 uint32_t index = imported_function_table_.LookupOrInsertImport( | 1359 uint32_t index = imported_function_table_.LookupOrInsertImport( |
1360 vp->var(), sig.Build()); | 1360 vp->var(), sig.Build()); |
1361 VisitCallArgs(expr); | 1361 VisitCallArgs(expr); |
| 1362 current_function_builder_->AddAsmWasmOffset(expr->position()); |
1362 current_function_builder_->Emit(kExprCallFunction); | 1363 current_function_builder_->Emit(kExprCallFunction); |
1363 current_function_builder_->EmitVarInt(index); | 1364 current_function_builder_->EmitVarInt(index); |
1364 } else { | 1365 } else { |
1365 WasmFunctionBuilder* function = LookupOrInsertFunction(vp->var()); | 1366 WasmFunctionBuilder* function = LookupOrInsertFunction(vp->var()); |
1366 VisitCallArgs(expr); | 1367 VisitCallArgs(expr); |
| 1368 current_function_builder_->AddAsmWasmOffset(expr->position()); |
1367 current_function_builder_->Emit(kExprCallFunction); | 1369 current_function_builder_->Emit(kExprCallFunction); |
1368 current_function_builder_->EmitDirectCallIndex( | 1370 current_function_builder_->EmitDirectCallIndex( |
1369 function->func_index()); | 1371 function->func_index()); |
1370 returns_value = function->signature()->return_count() > 0; | 1372 returns_value = function->signature()->return_count() > 0; |
1371 } | 1373 } |
1372 break; | 1374 break; |
1373 } | 1375 } |
1374 case Call::KEYED_PROPERTY_CALL: { | 1376 case Call::KEYED_PROPERTY_CALL: { |
1375 DCHECK_EQ(kFuncScope, scope_); | 1377 DCHECK_EQ(kFuncScope, scope_); |
1376 Property* p = expr->expression()->AsProperty(); | 1378 Property* p = expr->expression()->AsProperty(); |
1377 DCHECK_NOT_NULL(p); | 1379 DCHECK_NOT_NULL(p); |
1378 VariableProxy* var = p->obj()->AsVariableProxy(); | 1380 VariableProxy* var = p->obj()->AsVariableProxy(); |
1379 DCHECK_NOT_NULL(var); | 1381 DCHECK_NOT_NULL(var); |
1380 FunctionTableIndices* indices = LookupFunctionTable(var->var()); | 1382 FunctionTableIndices* indices = LookupFunctionTable(var->var()); |
1381 Visit(p->key()); // TODO(titzer): should use RECURSE() | 1383 Visit(p->key()); // TODO(titzer): should use RECURSE() |
1382 | 1384 |
1383 // We have to use a temporary for the correct order of evaluation. | 1385 // We have to use a temporary for the correct order of evaluation. |
1384 current_function_builder_->EmitI32Const(indices->start_index); | 1386 current_function_builder_->EmitI32Const(indices->start_index); |
1385 current_function_builder_->Emit(kExprI32Add); | 1387 current_function_builder_->Emit(kExprI32Add); |
1386 WasmTemporary tmp(current_function_builder_, kAstI32); | 1388 WasmTemporary tmp(current_function_builder_, kAstI32); |
1387 current_function_builder_->EmitSetLocal(tmp.index()); | 1389 current_function_builder_->EmitSetLocal(tmp.index()); |
1388 | 1390 |
1389 VisitCallArgs(expr); | 1391 VisitCallArgs(expr); |
1390 | 1392 |
1391 current_function_builder_->EmitGetLocal(tmp.index()); | 1393 current_function_builder_->EmitGetLocal(tmp.index()); |
| 1394 current_function_builder_->AddAsmWasmOffset(expr->position()); |
1392 current_function_builder_->Emit(kExprCallIndirect); | 1395 current_function_builder_->Emit(kExprCallIndirect); |
1393 current_function_builder_->EmitVarInt(indices->signature_index); | 1396 current_function_builder_->EmitVarInt(indices->signature_index); |
1394 returns_value = | 1397 returns_value = |
1395 builder_->GetSignature(indices->signature_index)->return_count() > | 1398 builder_->GetSignature(indices->signature_index)->return_count() > |
1396 0; | 1399 0; |
1397 break; | 1400 break; |
1398 } | 1401 } |
1399 default: | 1402 default: |
1400 UNREACHABLE(); | 1403 UNREACHABLE(); |
1401 } | 1404 } |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1863 private: | 1866 private: |
1864 DISALLOW_COPY_AND_ASSIGN(AsmWasmBuilderImpl); | 1867 DISALLOW_COPY_AND_ASSIGN(AsmWasmBuilderImpl); |
1865 }; | 1868 }; |
1866 | 1869 |
1867 AsmWasmBuilder::AsmWasmBuilder(Isolate* isolate, Zone* zone, | 1870 AsmWasmBuilder::AsmWasmBuilder(Isolate* isolate, Zone* zone, |
1868 FunctionLiteral* literal, AsmTyper* typer) | 1871 FunctionLiteral* literal, AsmTyper* typer) |
1869 : isolate_(isolate), zone_(zone), literal_(literal), typer_(typer) {} | 1872 : isolate_(isolate), zone_(zone), literal_(literal), typer_(typer) {} |
1870 | 1873 |
1871 // TODO(aseemgarg): probably should take zone (to write wasm to) as input so | 1874 // TODO(aseemgarg): probably should take zone (to write wasm to) as input so |
1872 // that zone in constructor may be thrown away once wasm module is written. | 1875 // that zone in constructor may be thrown away once wasm module is written. |
1873 ZoneBuffer* AsmWasmBuilder::Run(i::Handle<i::FixedArray>* foreign_args) { | 1876 AsmWasmBuilder::Result AsmWasmBuilder::Run( |
| 1877 i::Handle<i::FixedArray>* foreign_args) { |
1874 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, typer_); | 1878 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, typer_); |
1875 impl.Build(); | 1879 impl.Build(); |
1876 *foreign_args = impl.GetForeignArgs(); | 1880 *foreign_args = impl.GetForeignArgs(); |
1877 ZoneBuffer* buffer = new (zone_) ZoneBuffer(zone_); | 1881 ZoneBuffer* module_buffer = new (zone_) ZoneBuffer(zone_); |
1878 impl.builder_->WriteTo(*buffer); | 1882 impl.builder_->WriteTo(*module_buffer); |
1879 return buffer; | 1883 ZoneBuffer* asm_offsets_buffer = new (zone_) ZoneBuffer(zone_); |
| 1884 impl.builder_->WriteAsmJsOffsetTable(*asm_offsets_buffer); |
| 1885 return {module_buffer, asm_offsets_buffer}; |
1880 } | 1886 } |
1881 | 1887 |
1882 const char* AsmWasmBuilder::foreign_init_name = "__foreign_init__"; | 1888 const char* AsmWasmBuilder::foreign_init_name = "__foreign_init__"; |
1883 const char* AsmWasmBuilder::single_function_name = "__single_function__"; | 1889 const char* AsmWasmBuilder::single_function_name = "__single_function__"; |
1884 | 1890 |
1885 } // namespace wasm | 1891 } // namespace wasm |
1886 } // namespace internal | 1892 } // namespace internal |
1887 } // namespace v8 | 1893 } // namespace v8 |
OLD | NEW |