Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: src/asmjs/asm-wasm-builder.cc

Issue 2348383003: [wasm] Support asm.js modules with a single function. (Closed)
Patch Set: fix Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/asmjs/asm-wasm-builder.h ('k') | test/mjsunit/wasm/asm-wasm.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 void BuildForeignInitFunction() { 83 void BuildForeignInitFunction() {
84 foreign_init_function_index_ = builder_->AddFunction(); 84 foreign_init_function_index_ = builder_->AddFunction();
85 FunctionSig::Builder b(zone(), 0, foreign_variables_.size()); 85 FunctionSig::Builder b(zone(), 0, foreign_variables_.size());
86 for (auto i = foreign_variables_.begin(); i != foreign_variables_.end(); 86 for (auto i = foreign_variables_.begin(); i != foreign_variables_.end();
87 ++i) { 87 ++i) {
88 b.AddParam(i->type); 88 b.AddParam(i->type);
89 } 89 }
90 current_function_builder_ = 90 current_function_builder_ =
91 builder_->FunctionAt(foreign_init_function_index_); 91 builder_->FunctionAt(foreign_init_function_index_);
92 current_function_builder_->SetExported(); 92 current_function_builder_->SetExported();
93 std::string raw_name = "__foreign_init__"; 93 current_function_builder_->SetName(
94 current_function_builder_->SetName(raw_name.data(), 94 AsmWasmBuilder::foreign_init_name,
95 static_cast<int>(raw_name.size())); 95 static_cast<int>(strlen(AsmWasmBuilder::foreign_init_name)));
96 current_function_builder_->SetSignature(b.Build()); 96 current_function_builder_->SetSignature(b.Build());
97 for (size_t pos = 0; pos < foreign_variables_.size(); ++pos) { 97 for (size_t pos = 0; pos < foreign_variables_.size(); ++pos) {
98 current_function_builder_->EmitGetLocal(static_cast<uint32_t>(pos)); 98 current_function_builder_->EmitGetLocal(static_cast<uint32_t>(pos));
99 ForeignVariable* fv = &foreign_variables_[pos]; 99 ForeignVariable* fv = &foreign_variables_[pos];
100 uint32_t index = LookupOrInsertGlobal(fv->var, fv->type); 100 uint32_t index = LookupOrInsertGlobal(fv->var, fv->type);
101 current_function_builder_->EmitWithVarInt(kExprSetGlobal, index); 101 current_function_builder_->EmitWithVarInt(kExprSetGlobal, index);
102 } 102 }
103 current_function_builder_ = nullptr; 103 current_function_builder_ = nullptr;
104 } 104 }
105 105
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 } 544 }
545 LocalType var_type = TypeOf(expr); 545 LocalType var_type = TypeOf(expr);
546 DCHECK_NE(kAstStmt, var_type); 546 DCHECK_NE(kAstStmt, var_type);
547 if (var->IsContextSlot()) { 547 if (var->IsContextSlot()) {
548 current_function_builder_->EmitWithVarInt( 548 current_function_builder_->EmitWithVarInt(
549 kExprGetGlobal, LookupOrInsertGlobal(var, var_type)); 549 kExprGetGlobal, LookupOrInsertGlobal(var, var_type));
550 } else { 550 } else {
551 current_function_builder_->EmitGetLocal( 551 current_function_builder_->EmitGetLocal(
552 LookupOrInsertLocal(var, var_type)); 552 LookupOrInsertLocal(var, var_type));
553 } 553 }
554 } else if (scope_ == kExportScope) {
555 Variable* var = expr->var();
556 DCHECK(var->is_function());
557 uint32_t index = LookupOrInsertFunction(var);
558 builder_->FunctionAt(index)->SetExported();
559 builder_->FunctionAt(index)->SetName(
560 AsmWasmBuilder::single_function_name,
561 static_cast<int>(strlen(AsmWasmBuilder::single_function_name)));
554 } 562 }
555 } 563 }
556 564
557 void VisitLiteral(Literal* expr) { 565 void VisitLiteral(Literal* expr) {
558 Handle<Object> value = expr->value(); 566 Handle<Object> value = expr->value();
559 if (!value->IsNumber() || (scope_ != kFuncScope && scope_ != kInitScope)) { 567 if (!value->IsNumber() || (scope_ != kFuncScope && scope_ != kInitScope)) {
560 return; 568 return;
561 } 569 }
562 AsmType* type = typer_->TypeOf(expr); 570 AsmType* type = typer_->TypeOf(expr);
563 DCHECK_NE(type, AsmType::None()); 571 DCHECK_NE(type, AsmType::None());
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 // TODO(aseemgarg): probably should take zone (to write wasm to) as input so 1793 // TODO(aseemgarg): probably should take zone (to write wasm to) as input so
1786 // that zone in constructor may be thrown away once wasm module is written. 1794 // that zone in constructor may be thrown away once wasm module is written.
1787 ZoneBuffer* AsmWasmBuilder::Run(i::Handle<i::FixedArray>* foreign_args) { 1795 ZoneBuffer* AsmWasmBuilder::Run(i::Handle<i::FixedArray>* foreign_args) {
1788 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, typer_); 1796 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, typer_);
1789 impl.Build(); 1797 impl.Build();
1790 *foreign_args = impl.GetForeignArgs(); 1798 *foreign_args = impl.GetForeignArgs();
1791 ZoneBuffer* buffer = new (zone_) ZoneBuffer(zone_); 1799 ZoneBuffer* buffer = new (zone_) ZoneBuffer(zone_);
1792 impl.builder_->WriteTo(*buffer); 1800 impl.builder_->WriteTo(*buffer);
1793 return buffer; 1801 return buffer;
1794 } 1802 }
1803
1804 const char* AsmWasmBuilder::foreign_init_name = "__foreign_init__";
1805 const char* AsmWasmBuilder::single_function_name = "__single_function__";
1806
1795 } // namespace wasm 1807 } // namespace wasm
1796 } // namespace internal 1808 } // namespace internal
1797 } // namespace v8 1809 } // namespace v8
OLDNEW
« no previous file with comments | « src/asmjs/asm-wasm-builder.h ('k') | test/mjsunit/wasm/asm-wasm.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698