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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 builder_->MarkStartFunction(init_function_); | 75 builder_->MarkStartFunction(init_function_); |
76 } | 76 } |
77 | 77 |
78 void BuildForeignInitFunction() { | 78 void BuildForeignInitFunction() { |
79 foreign_init_function_ = builder_->AddFunction(); | 79 foreign_init_function_ = builder_->AddFunction(); |
80 FunctionSig::Builder b(zone(), 0, foreign_variables_.size()); | 80 FunctionSig::Builder b(zone(), 0, foreign_variables_.size()); |
81 for (auto i = foreign_variables_.begin(); i != foreign_variables_.end(); | 81 for (auto i = foreign_variables_.begin(); i != foreign_variables_.end(); |
82 ++i) { | 82 ++i) { |
83 b.AddParam(i->type); | 83 b.AddParam(i->type); |
84 } | 84 } |
85 foreign_init_function_->SetExported(); | 85 foreign_init_function_->ExportAs( |
86 std::string raw_name = "__foreign_init__"; | 86 CStrVector(AsmWasmBuilder::foreign_init_name)); |
87 foreign_init_function_->SetName( | |
88 AsmWasmBuilder::foreign_init_name, | |
89 static_cast<int>(strlen(AsmWasmBuilder::foreign_init_name))); | |
90 | |
91 foreign_init_function_->SetName(raw_name.data(), | |
92 static_cast<int>(raw_name.size())); | |
93 foreign_init_function_->SetSignature(b.Build()); | 87 foreign_init_function_->SetSignature(b.Build()); |
94 for (size_t pos = 0; pos < foreign_variables_.size(); ++pos) { | 88 for (size_t pos = 0; pos < foreign_variables_.size(); ++pos) { |
95 foreign_init_function_->EmitGetLocal(static_cast<uint32_t>(pos)); | 89 foreign_init_function_->EmitGetLocal(static_cast<uint32_t>(pos)); |
96 ForeignVariable* fv = &foreign_variables_[pos]; | 90 ForeignVariable* fv = &foreign_variables_[pos]; |
97 uint32_t index = LookupOrInsertGlobal(fv->var, fv->type); | 91 uint32_t index = LookupOrInsertGlobal(fv->var, fv->type); |
98 foreign_init_function_->EmitWithVarInt(kExprSetGlobal, index); | 92 foreign_init_function_->EmitWithVarInt(kExprSetGlobal, index); |
99 } | 93 } |
100 } | 94 } |
101 | 95 |
102 i::Handle<i::FixedArray> GetForeignArgs() { | 96 i::Handle<i::FixedArray> GetForeignArgs() { |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 current_function_builder_->EmitWithVarInt( | 551 current_function_builder_->EmitWithVarInt( |
558 kExprGetGlobal, LookupOrInsertGlobal(var, var_type)); | 552 kExprGetGlobal, LookupOrInsertGlobal(var, var_type)); |
559 } else { | 553 } else { |
560 current_function_builder_->EmitGetLocal( | 554 current_function_builder_->EmitGetLocal( |
561 LookupOrInsertLocal(var, var_type)); | 555 LookupOrInsertLocal(var, var_type)); |
562 } | 556 } |
563 } else if (scope_ == kExportScope) { | 557 } else if (scope_ == kExportScope) { |
564 Variable* var = expr->var(); | 558 Variable* var = expr->var(); |
565 DCHECK(var->is_function()); | 559 DCHECK(var->is_function()); |
566 WasmFunctionBuilder* function = LookupOrInsertFunction(var); | 560 WasmFunctionBuilder* function = LookupOrInsertFunction(var); |
567 function->SetExported(); | 561 function->ExportAs(CStrVector(AsmWasmBuilder::single_function_name)); |
568 function->SetName( | |
569 AsmWasmBuilder::single_function_name, | |
570 static_cast<int>(strlen(AsmWasmBuilder::single_function_name))); | |
571 } | 562 } |
572 } | 563 } |
573 | 564 |
574 void VisitLiteral(Literal* expr) { | 565 void VisitLiteral(Literal* expr) { |
575 Handle<Object> value = expr->value(); | 566 Handle<Object> value = expr->value(); |
576 if (!(value->IsNumber() || expr->raw_value()->IsTrue() || | 567 if (!(value->IsNumber() || expr->raw_value()->IsTrue() || |
577 expr->raw_value()->IsFalse()) || | 568 expr->raw_value()->IsFalse()) || |
578 (scope_ != kFuncScope && scope_ != kInitScope)) { | 569 (scope_ != kFuncScope && scope_ != kInitScope)) { |
579 return; | 570 return; |
580 } | 571 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 DCHECK_EQ(kExportScope, scope_); | 635 DCHECK_EQ(kExportScope, scope_); |
645 VariableProxy* expr = prop->value()->AsVariableProxy(); | 636 VariableProxy* expr = prop->value()->AsVariableProxy(); |
646 DCHECK_NOT_NULL(expr); | 637 DCHECK_NOT_NULL(expr); |
647 Variable* var = expr->var(); | 638 Variable* var = expr->var(); |
648 Literal* name = prop->key()->AsLiteral(); | 639 Literal* name = prop->key()->AsLiteral(); |
649 DCHECK_NOT_NULL(name); | 640 DCHECK_NOT_NULL(name); |
650 DCHECK(name->IsPropertyName()); | 641 DCHECK(name->IsPropertyName()); |
651 const AstRawString* raw_name = name->AsRawPropertyName(); | 642 const AstRawString* raw_name = name->AsRawPropertyName(); |
652 if (var->is_function()) { | 643 if (var->is_function()) { |
653 WasmFunctionBuilder* function = LookupOrInsertFunction(var); | 644 WasmFunctionBuilder* function = LookupOrInsertFunction(var); |
654 function->SetExported(); | 645 function->Export(); |
655 function->SetName(reinterpret_cast<const char*>(raw_name->raw_data()), | 646 function->SetName({reinterpret_cast<const char*>(raw_name->raw_data()), |
656 raw_name->length()); | 647 raw_name->length()}); |
657 } | 648 } |
658 } | 649 } |
659 } | 650 } |
660 | 651 |
661 void VisitArrayLiteral(ArrayLiteral* expr) { UNREACHABLE(); } | 652 void VisitArrayLiteral(ArrayLiteral* expr) { UNREACHABLE(); } |
662 | 653 |
663 void LoadInitFunction() { | 654 void LoadInitFunction() { |
664 current_function_builder_ = init_function_; | 655 current_function_builder_ = init_function_; |
665 scope_ = kInitScope; | 656 scope_ = kInitScope; |
666 } | 657 } |
(...skipping 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 for (int i = 0; i < static_cast<int>(arguments.size()); ++i) { | 1806 for (int i = 0; i < static_cast<int>(arguments.size()); ++i) { |
1816 LocalType type = TypeFrom(arguments[i]); | 1807 LocalType type = TypeFrom(arguments[i]); |
1817 DCHECK_NE(kAstStmt, type); | 1808 DCHECK_NE(kAstStmt, type); |
1818 b.AddParam(type); | 1809 b.AddParam(type); |
1819 } | 1810 } |
1820 | 1811 |
1821 WasmFunctionBuilder* function = builder_->AddFunction(b.Build()); | 1812 WasmFunctionBuilder* function = builder_->AddFunction(b.Build()); |
1822 entry = functions_.LookupOrInsert(v, ComputePointerHash(v), | 1813 entry = functions_.LookupOrInsert(v, ComputePointerHash(v), |
1823 ZoneAllocationPolicy(zone())); | 1814 ZoneAllocationPolicy(zone())); |
1824 function->SetName( | 1815 function->SetName( |
1825 reinterpret_cast<const char*>(v->raw_name()->raw_data()), | 1816 {reinterpret_cast<const char*>(v->raw_name()->raw_data()), |
1826 v->raw_name()->length()); | 1817 v->raw_name()->length()}); |
1827 entry->value = function; | 1818 entry->value = function; |
1828 } | 1819 } |
1829 return (reinterpret_cast<WasmFunctionBuilder*>(entry->value)); | 1820 return (reinterpret_cast<WasmFunctionBuilder*>(entry->value)); |
1830 } | 1821 } |
1831 | 1822 |
1832 LocalType TypeOf(Expression* expr) { return TypeFrom(typer_->TypeOf(expr)); } | 1823 LocalType TypeOf(Expression* expr) { return TypeFrom(typer_->TypeOf(expr)); } |
1833 | 1824 |
1834 LocalType TypeFrom(AsmType* type) { | 1825 LocalType TypeFrom(AsmType* type) { |
1835 if (type->IsA(AsmType::Intish())) { | 1826 if (type->IsA(AsmType::Intish())) { |
1836 return kAstI32; | 1827 return kAstI32; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1887 impl.builder_->WriteTo(*buffer); | 1878 impl.builder_->WriteTo(*buffer); |
1888 return buffer; | 1879 return buffer; |
1889 } | 1880 } |
1890 | 1881 |
1891 const char* AsmWasmBuilder::foreign_init_name = "__foreign_init__"; | 1882 const char* AsmWasmBuilder::foreign_init_name = "__foreign_init__"; |
1892 const char* AsmWasmBuilder::single_function_name = "__single_function__"; | 1883 const char* AsmWasmBuilder::single_function_name = "__single_function__"; |
1893 | 1884 |
1894 } // namespace wasm | 1885 } // namespace wasm |
1895 } // namespace internal | 1886 } // namespace internal |
1896 } // namespace v8 | 1887 } // namespace v8 |
OLD | NEW |