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 #include "src/wasm/asm-wasm-builder.h" | 7 #include "src/wasm/asm-wasm-builder.h" |
8 #include "src/wasm/wasm-macro-gen.h" | 8 #include "src/wasm/wasm-macro-gen.h" |
9 #include "src/wasm/wasm-opcodes.h" | 9 #include "src/wasm/wasm-opcodes.h" |
10 | 10 |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 breakable_blocks_.push_back( | 219 breakable_blocks_.push_back( |
220 std::make_pair(stmt->AsBreakableStatement(), true)); | 220 std::make_pair(stmt->AsBreakableStatement(), true)); |
221 current_function_builder_->Emit(kExprIf); | 221 current_function_builder_->Emit(kExprIf); |
222 RECURSE(Visit(stmt->cond())); | 222 RECURSE(Visit(stmt->cond())); |
223 current_function_builder_->EmitWithU8(kExprBr, 0); | 223 current_function_builder_->EmitWithU8(kExprBr, 0); |
224 RECURSE(Visit(stmt->body())); | 224 RECURSE(Visit(stmt->body())); |
225 breakable_blocks_.pop_back(); | 225 breakable_blocks_.pop_back(); |
226 } | 226 } |
227 | 227 |
228 void VisitForStatement(ForStatement* stmt) { | 228 void VisitForStatement(ForStatement* stmt) { |
229 DCHECK(in_function_); | |
229 if (stmt->init() != NULL) { | 230 if (stmt->init() != NULL) { |
231 block_size_++; | |
230 RECURSE(Visit(stmt->init())); | 232 RECURSE(Visit(stmt->init())); |
231 } | 233 } |
234 current_function_builder_->Emit(kExprLoop); | |
235 uint32_t index = current_function_builder_->EmitEditableImmediate(0); | |
236 int prev_block_size = block_size_; | |
237 block_size_ = 0; | |
238 breakable_blocks_.push_back( | |
239 std::make_pair(stmt->AsBreakableStatement(), true)); | |
232 if (stmt->cond() != NULL) { | 240 if (stmt->cond() != NULL) { |
241 block_size_++; | |
242 current_function_builder_->Emit(kExprIf); | |
243 current_function_builder_->Emit(kExprBoolNot); | |
233 RECURSE(Visit(stmt->cond())); | 244 RECURSE(Visit(stmt->cond())); |
245 current_function_builder_->EmitWithU8(kExprBr, 1); | |
246 current_function_builder_->Emit(kExprNop); | |
247 } | |
248 if (stmt->body() != NULL) { | |
249 block_size_++; | |
250 RECURSE(Visit(stmt->body())); | |
234 } | 251 } |
235 if (stmt->next() != NULL) { | 252 if (stmt->next() != NULL) { |
253 block_size_++; | |
236 RECURSE(Visit(stmt->next())); | 254 RECURSE(Visit(stmt->next())); |
237 } | 255 } |
238 RECURSE(Visit(stmt->body())); | 256 block_size_++; |
257 current_function_builder_->EmitWithU8(kExprBr, 0); | |
258 current_function_builder_->Emit(kExprNop); | |
259 current_function_builder_->EditImmediate(index, block_size_); | |
260 block_size_ = prev_block_size; | |
261 breakable_blocks_.pop_back(); | |
239 } | 262 } |
240 | 263 |
241 void VisitForInStatement(ForInStatement* stmt) { | 264 void VisitForInStatement(ForInStatement* stmt) { |
bradnelson
2015/12/15 03:07:04
Unrelated to this CL, but since for..in, for..of,
| |
242 RECURSE(Visit(stmt->enumerable())); | 265 RECURSE(Visit(stmt->enumerable())); |
243 RECURSE(Visit(stmt->body())); | 266 RECURSE(Visit(stmt->body())); |
244 } | 267 } |
245 | 268 |
246 void VisitForOfStatement(ForOfStatement* stmt) { | 269 void VisitForOfStatement(ForOfStatement* stmt) { |
247 RECURSE(Visit(stmt->iterable())); | 270 RECURSE(Visit(stmt->iterable())); |
248 RECURSE(Visit(stmt->body())); | 271 RECURSE(Visit(stmt->body())); |
249 } | 272 } |
250 | 273 |
251 void VisitTryCatchStatement(TryCatchStatement* stmt) { | 274 void VisitTryCatchStatement(TryCatchStatement* stmt) { |
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
969 // that zone in constructor may be thrown away once wasm module is written. | 992 // that zone in constructor may be thrown away once wasm module is written. |
970 WasmModuleIndex* AsmWasmBuilder::Run() { | 993 WasmModuleIndex* AsmWasmBuilder::Run() { |
971 AsmWasmBuilderImpl impl(isolate_, zone_, literal_); | 994 AsmWasmBuilderImpl impl(isolate_, zone_, literal_); |
972 impl.Compile(); | 995 impl.Compile(); |
973 WasmModuleWriter* writer = impl.builder_->Build(zone_); | 996 WasmModuleWriter* writer = impl.builder_->Build(zone_); |
974 return writer->WriteTo(zone_); | 997 return writer->WriteTo(zone_); |
975 } | 998 } |
976 } // namespace wasm | 999 } // namespace wasm |
977 } // namespace internal | 1000 } // namespace internal |
978 } // namespace v8 | 1001 } // namespace v8 |
OLD | NEW |