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

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

Issue 2628203003: Reland of [wasm] Enforce that function bodies end with the \"end\" opcode. (Closed)
Patch Set: Created 3 years, 11 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/function-body-decoder.cc » ('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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 94 }
95 foreign_init_function_->ExportAs( 95 foreign_init_function_->ExportAs(
96 CStrVector(AsmWasmBuilder::foreign_init_name)); 96 CStrVector(AsmWasmBuilder::foreign_init_name));
97 foreign_init_function_->SetSignature(b.Build()); 97 foreign_init_function_->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 foreign_init_function_->EmitGetLocal(static_cast<uint32_t>(pos)); 99 foreign_init_function_->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 foreign_init_function_->EmitWithVarInt(kExprSetGlobal, index); 102 foreign_init_function_->EmitWithVarInt(kExprSetGlobal, index);
103 } 103 }
104 foreign_init_function_->Emit(kExprEnd);
104 } 105 }
105 106
106 Handle<FixedArray> GetForeignArgs() { 107 Handle<FixedArray> GetForeignArgs() {
107 Handle<FixedArray> ret = isolate_->factory()->NewFixedArray( 108 Handle<FixedArray> ret = isolate_->factory()->NewFixedArray(
108 static_cast<int>(foreign_variables_.size())); 109 static_cast<int>(foreign_variables_.size()));
109 for (size_t i = 0; i < foreign_variables_.size(); ++i) { 110 for (size_t i = 0; i < foreign_variables_.size(); ++i) {
110 ForeignVariable* fv = &foreign_variables_[i]; 111 ForeignVariable* fv = &foreign_variables_[i];
111 ret->set(static_cast<int>(i), *fv->name); 112 ret->set(static_cast<int>(i), *fv->name);
112 } 113 }
113 return ret; 114 return ret;
(...skipping 10 matching lines...) Expand all
124 return false; 125 return false;
125 } 126 }
126 if (!typer_finished_) { 127 if (!typer_finished_) {
127 typer_->FailWithMessage("Module missing export section."); 128 typer_->FailWithMessage("Module missing export section.");
128 typer_failed_ = true; 129 typer_failed_ = true;
129 } 130 }
130 if (typer_failed_) { 131 if (typer_failed_) {
131 return false; 132 return false;
132 } 133 }
133 BuildForeignInitFunction(); 134 BuildForeignInitFunction();
135 init_function_->Emit(kExprEnd); // finish init function.
134 return true; 136 return true;
135 } 137 }
136 138
137 void VisitVariableDeclaration(VariableDeclaration* decl) {} 139 void VisitVariableDeclaration(VariableDeclaration* decl) {}
138 140
139 void VisitFunctionDeclaration(FunctionDeclaration* decl) { 141 void VisitFunctionDeclaration(FunctionDeclaration* decl) {
140 DCHECK_EQ(kModuleScope, scope_); 142 DCHECK_EQ(kModuleScope, scope_);
141 DCHECK_NULL(current_function_builder_); 143 DCHECK_NULL(current_function_builder_);
142 FunctionLiteral* old_func = decl->fun(); 144 FunctionLiteral* old_func = decl->fun();
143 Zone zone(isolate_->allocator(), ZONE_NAME); 145 Zone zone(isolate_->allocator(), ZONE_NAME);
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 DCHECK_NE(kWasmStmt, type); 538 DCHECK_NE(kWasmStmt, type);
537 InsertParameter(scope->parameter(i), type, i); 539 InsertParameter(scope->parameter(i), type, i);
538 } 540 }
539 } else { 541 } else {
540 UNREACHABLE(); 542 UNREACHABLE();
541 } 543 }
542 } 544 }
543 RECURSE(VisitDeclarations(scope->declarations())); 545 RECURSE(VisitDeclarations(scope->declarations()));
544 if (typer_failed_) return; 546 if (typer_failed_) return;
545 RECURSE(VisitStatements(expr->body())); 547 RECURSE(VisitStatements(expr->body()));
548 if (scope_ == kFuncScope) {
549 // Finish the function-body scope block.
550 current_function_builder_->Emit(kExprEnd);
551 }
546 } 552 }
547 553
548 void VisitNativeFunctionLiteral(NativeFunctionLiteral* expr) { 554 void VisitNativeFunctionLiteral(NativeFunctionLiteral* expr) {
549 UNREACHABLE(); 555 UNREACHABLE();
550 } 556 }
551 557
552 void VisitConditional(Conditional* expr) { 558 void VisitConditional(Conditional* expr) {
553 DCHECK_EQ(kFuncScope, scope_); 559 DCHECK_EQ(kFuncScope, scope_);
554 RECURSE(Visit(expr->condition())); 560 RECURSE(Visit(expr->condition()));
555 // WASM ifs come with implicit blocks for both arms. 561 // WASM ifs come with implicit blocks for both arms.
(...skipping 1439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 impl.builder_->WriteAsmJsOffsetTable(*asm_offsets_buffer); 2001 impl.builder_->WriteAsmJsOffsetTable(*asm_offsets_buffer);
1996 return {module_buffer, asm_offsets_buffer, success}; 2002 return {module_buffer, asm_offsets_buffer, success};
1997 } 2003 }
1998 2004
1999 const char* AsmWasmBuilder::foreign_init_name = "__foreign_init__"; 2005 const char* AsmWasmBuilder::foreign_init_name = "__foreign_init__";
2000 const char* AsmWasmBuilder::single_function_name = "__single_function__"; 2006 const char* AsmWasmBuilder::single_function_name = "__single_function__";
2001 2007
2002 } // namespace wasm 2008 } // namespace wasm
2003 } // namespace internal 2009 } // namespace internal
2004 } // namespace v8 2010 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/wasm/function-body-decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698