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

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

Issue 2017853003: [wasm] Remove redundant intermediate data structures in encoder.cc. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 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 | « no previous file | src/wasm/encoder.h » ('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 83
84 void BuildForeignInitFunction() { 84 void BuildForeignInitFunction() {
85 foreign_init_function_index_ = builder_->AddFunction(); 85 foreign_init_function_index_ = builder_->AddFunction();
86 FunctionSig::Builder b(zone(), 0, foreign_variables_.size()); 86 FunctionSig::Builder b(zone(), 0, foreign_variables_.size());
87 for (auto i = foreign_variables_.begin(); i != foreign_variables_.end(); 87 for (auto i = foreign_variables_.begin(); i != foreign_variables_.end();
88 ++i) { 88 ++i) {
89 b.AddParam(i->type); 89 b.AddParam(i->type);
90 } 90 }
91 current_function_builder_ = 91 current_function_builder_ =
92 builder_->FunctionAt(foreign_init_function_index_); 92 builder_->FunctionAt(foreign_init_function_index_);
93 current_function_builder_->Exported(1); 93 current_function_builder_->SetExported();
94 std::string raw_name = "__foreign_init__"; 94 std::string raw_name = "__foreign_init__";
95 current_function_builder_->SetName(raw_name.data(), 95 current_function_builder_->SetName(raw_name.data(),
96 static_cast<int>(raw_name.size())); 96 static_cast<int>(raw_name.size()));
97 current_function_builder_->SetSignature(b.Build()); 97 current_function_builder_->SetSignature(b.Build());
98 for (size_t pos = 0; pos < foreign_variables_.size(); ++pos) { 98 for (size_t pos = 0; pos < foreign_variables_.size(); ++pos) {
99 current_function_builder_->EmitGetLocal(static_cast<uint32_t>(pos)); 99 current_function_builder_->EmitGetLocal(static_cast<uint32_t>(pos));
100 ForeignVariable* fv = &foreign_variables_[pos]; 100 ForeignVariable* fv = &foreign_variables_[pos];
101 uint32_t index = LookupOrInsertGlobal(fv->var, fv->type); 101 uint32_t index = LookupOrInsertGlobal(fv->var, fv->type);
102 current_function_builder_->EmitWithVarInt(kExprStoreGlobal, index); 102 current_function_builder_->EmitWithVarInt(kExprStoreGlobal, index);
103 } 103 }
104 current_function_builder_ = nullptr; 104 current_function_builder_ = nullptr;
105 } 105 }
106 106
107 i::Handle<i::FixedArray> GetForeignArgs() { 107 i::Handle<i::FixedArray> GetForeignArgs() {
108 i::Handle<FixedArray> ret = isolate_->factory()->NewFixedArray( 108 i::Handle<FixedArray> ret = isolate_->factory()->NewFixedArray(
109 static_cast<int>(foreign_variables_.size())); 109 static_cast<int>(foreign_variables_.size()));
110 for (size_t i = 0; i < foreign_variables_.size(); ++i) { 110 for (size_t i = 0; i < foreign_variables_.size(); ++i) {
111 ForeignVariable* fv = &foreign_variables_[i]; 111 ForeignVariable* fv = &foreign_variables_[i];
112 ret->set(static_cast<int>(i), *fv->name); 112 ret->set(static_cast<int>(i), *fv->name);
113 } 113 }
114 return ret; 114 return ret;
115 } 115 }
116 116
117 void Compile() { 117 void Build() {
118 InitializeInitFunction(); 118 InitializeInitFunction();
119 RECURSE(VisitFunctionLiteral(literal_)); 119 RECURSE(VisitFunctionLiteral(literal_));
120 BuildForeignInitFunction(); 120 BuildForeignInitFunction();
121 } 121 }
122 122
123 void VisitVariableDeclaration(VariableDeclaration* decl) {} 123 void VisitVariableDeclaration(VariableDeclaration* decl) {}
124 124
125 void VisitFunctionDeclaration(FunctionDeclaration* decl) { 125 void VisitFunctionDeclaration(FunctionDeclaration* decl) {
126 DCHECK_EQ(kModuleScope, scope_); 126 DCHECK_EQ(kModuleScope, scope_);
127 DCHECK_NULL(current_function_builder_); 127 DCHECK_NULL(current_function_builder_);
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 DCHECK_EQ(kExportScope, scope_); 600 DCHECK_EQ(kExportScope, scope_);
601 VariableProxy* expr = prop->value()->AsVariableProxy(); 601 VariableProxy* expr = prop->value()->AsVariableProxy();
602 DCHECK_NOT_NULL(expr); 602 DCHECK_NOT_NULL(expr);
603 Variable* var = expr->var(); 603 Variable* var = expr->var();
604 Literal* name = prop->key()->AsLiteral(); 604 Literal* name = prop->key()->AsLiteral();
605 DCHECK_NOT_NULL(name); 605 DCHECK_NOT_NULL(name);
606 DCHECK(name->IsPropertyName()); 606 DCHECK(name->IsPropertyName());
607 const AstRawString* raw_name = name->AsRawPropertyName(); 607 const AstRawString* raw_name = name->AsRawPropertyName();
608 if (var->is_function()) { 608 if (var->is_function()) {
609 uint32_t index = LookupOrInsertFunction(var); 609 uint32_t index = LookupOrInsertFunction(var);
610 builder_->FunctionAt(index)->Exported(1); 610 builder_->FunctionAt(index)->SetExported();
611 builder_->FunctionAt(index)->SetName( 611 builder_->FunctionAt(index)->SetName(
612 reinterpret_cast<const char*>(raw_name->raw_data()), 612 reinterpret_cast<const char*>(raw_name->raw_data()),
613 raw_name->length()); 613 raw_name->length());
614 } 614 }
615 } 615 }
616 } 616 }
617 617
618 void VisitArrayLiteral(ArrayLiteral* expr) { UNREACHABLE(); } 618 void VisitArrayLiteral(ArrayLiteral* expr) { UNREACHABLE(); }
619 619
620 void LoadInitFunction() { 620 void LoadInitFunction() {
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 }; 1754 };
1755 1755
1756 AsmWasmBuilder::AsmWasmBuilder(Isolate* isolate, Zone* zone, 1756 AsmWasmBuilder::AsmWasmBuilder(Isolate* isolate, Zone* zone,
1757 FunctionLiteral* literal, AsmTyper* typer) 1757 FunctionLiteral* literal, AsmTyper* typer)
1758 : isolate_(isolate), zone_(zone), literal_(literal), typer_(typer) {} 1758 : isolate_(isolate), zone_(zone), literal_(literal), typer_(typer) {}
1759 1759
1760 // TODO(aseemgarg): probably should take zone (to write wasm to) as input so 1760 // TODO(aseemgarg): probably should take zone (to write wasm to) as input so
1761 // that zone in constructor may be thrown away once wasm module is written. 1761 // that zone in constructor may be thrown away once wasm module is written.
1762 ZoneBuffer* AsmWasmBuilder::Run(i::Handle<i::FixedArray>* foreign_args) { 1762 ZoneBuffer* AsmWasmBuilder::Run(i::Handle<i::FixedArray>* foreign_args) {
1763 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, typer_); 1763 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, typer_);
1764 impl.Compile(); 1764 impl.Build();
1765 *foreign_args = impl.GetForeignArgs(); 1765 *foreign_args = impl.GetForeignArgs();
1766 ZoneBuffer* buffer = new (zone_) ZoneBuffer(zone_); 1766 ZoneBuffer* buffer = new (zone_) ZoneBuffer(zone_);
1767 WasmModuleWriter* writer = impl.builder_->Build(zone_); 1767 impl.builder_->WriteTo(*buffer);
1768 writer->WriteTo(*buffer);
1769 return buffer; 1768 return buffer;
1770 } 1769 }
1771 } // namespace wasm 1770 } // namespace wasm
1772 } // namespace internal 1771 } // namespace internal
1773 } // namespace v8 1772 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/wasm/encoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698