| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 if (elem.first == stmt->target()) { | 180 if (elem.first == stmt->target()) { |
| 181 DCHECK(elem.second); | 181 DCHECK(elem.second); |
| 182 break; | 182 break; |
| 183 } else if (elem.second) { | 183 } else if (elem.second) { |
| 184 block_distance += 2; | 184 block_distance += 2; |
| 185 } else { | 185 } else { |
| 186 block_distance += 1; | 186 block_distance += 1; |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 DCHECK(i >= 0); | 189 DCHECK(i >= 0); |
| 190 current_function_builder_->Emit(kExprNop); | |
| 191 current_function_builder_->EmitWithU8(kExprBr, ARITY_0); | 190 current_function_builder_->EmitWithU8(kExprBr, ARITY_0); |
| 192 current_function_builder_->EmitVarInt(block_distance); | 191 current_function_builder_->EmitVarInt(block_distance); |
| 193 } | 192 } |
| 194 | 193 |
| 195 void VisitBreakStatement(BreakStatement* stmt) { | 194 void VisitBreakStatement(BreakStatement* stmt) { |
| 196 DCHECK_EQ(kFuncScope, scope_); | 195 DCHECK_EQ(kFuncScope, scope_); |
| 197 DCHECK_NOT_NULL(stmt->target()); | 196 DCHECK_NOT_NULL(stmt->target()); |
| 198 int i = static_cast<int>(breakable_blocks_.size()) - 1; | 197 int i = static_cast<int>(breakable_blocks_.size()) - 1; |
| 199 int block_distance = 0; | 198 int block_distance = 0; |
| 200 for (; i >= 0; i--) { | 199 for (; i >= 0; i--) { |
| 201 auto elem = breakable_blocks_.at(i); | 200 auto elem = breakable_blocks_.at(i); |
| 202 if (elem.first == stmt->target()) { | 201 if (elem.first == stmt->target()) { |
| 203 if (elem.second) { | 202 if (elem.second) { |
| 204 block_distance++; | 203 block_distance++; |
| 205 } | 204 } |
| 206 break; | 205 break; |
| 207 } else if (elem.second) { | 206 } else if (elem.second) { |
| 208 block_distance += 2; | 207 block_distance += 2; |
| 209 } else { | 208 } else { |
| 210 block_distance += 1; | 209 block_distance += 1; |
| 211 } | 210 } |
| 212 } | 211 } |
| 213 DCHECK(i >= 0); | 212 DCHECK(i >= 0); |
| 214 current_function_builder_->Emit(kExprNop); | |
| 215 current_function_builder_->EmitWithU8(kExprBr, ARITY_0); | 213 current_function_builder_->EmitWithU8(kExprBr, ARITY_0); |
| 216 current_function_builder_->EmitVarInt(block_distance); | 214 current_function_builder_->EmitVarInt(block_distance); |
| 217 } | 215 } |
| 218 | 216 |
| 219 void VisitReturnStatement(ReturnStatement* stmt) { | 217 void VisitReturnStatement(ReturnStatement* stmt) { |
| 220 if (scope_ == kModuleScope) { | 218 if (scope_ == kModuleScope) { |
| 221 scope_ = kExportScope; | 219 scope_ = kExportScope; |
| 222 RECURSE(Visit(stmt->expression())); | 220 RECURSE(Visit(stmt->expression())); |
| 223 scope_ = kModuleScope; | 221 scope_ = kModuleScope; |
| 224 } else if (scope_ == kFuncScope) { | 222 } else if (scope_ == kFuncScope) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 breakable_blocks_.push_back(std::make_pair(nullptr, false)); | 254 breakable_blocks_.push_back(std::make_pair(nullptr, false)); |
| 257 HandleCase(node->right, case_to_block, tag, default_block, if_depth); | 255 HandleCase(node->right, case_to_block, tag, default_block, if_depth); |
| 258 current_function_builder_->Emit(kExprElse); | 256 current_function_builder_->Emit(kExprElse); |
| 259 } | 257 } |
| 260 if (node->begin == node->end) { | 258 if (node->begin == node->end) { |
| 261 VisitVariableProxy(tag); | 259 VisitVariableProxy(tag); |
| 262 current_function_builder_->EmitI32Const(node->begin); | 260 current_function_builder_->EmitI32Const(node->begin); |
| 263 current_function_builder_->Emit(kExprI32Eq); | 261 current_function_builder_->Emit(kExprI32Eq); |
| 264 current_function_builder_->Emit(kExprIf); | 262 current_function_builder_->Emit(kExprIf); |
| 265 DCHECK(case_to_block.find(node->begin) != case_to_block.end()); | 263 DCHECK(case_to_block.find(node->begin) != case_to_block.end()); |
| 266 current_function_builder_->Emit(kExprNop); | |
| 267 current_function_builder_->EmitWithU8(kExprBr, ARITY_0); | 264 current_function_builder_->EmitWithU8(kExprBr, ARITY_0); |
| 268 current_function_builder_->EmitVarInt(1 + if_depth + | 265 current_function_builder_->EmitVarInt(1 + if_depth + |
| 269 case_to_block.at(node->begin)); | 266 case_to_block.at(node->begin)); |
| 270 current_function_builder_->Emit(kExprEnd); | 267 current_function_builder_->Emit(kExprEnd); |
| 271 } else { | 268 } else { |
| 272 current_function_builder_->Emit(kExprNop); | |
| 273 if (node->begin != 0) { | 269 if (node->begin != 0) { |
| 274 VisitVariableProxy(tag); | 270 VisitVariableProxy(tag); |
| 275 current_function_builder_->EmitI32Const(node->begin); | 271 current_function_builder_->EmitI32Const(node->begin); |
| 276 current_function_builder_->Emit(kExprI32Sub); | 272 current_function_builder_->Emit(kExprI32Sub); |
| 277 } else { | 273 } else { |
| 278 VisitVariableProxy(tag); | 274 VisitVariableProxy(tag); |
| 279 } | 275 } |
| 280 current_function_builder_->EmitWithU8(kExprBrTable, ARITY_0); | 276 current_function_builder_->EmitWithU8(kExprBrTable, ARITY_0); |
| 281 current_function_builder_->EmitVarInt(node->end - node->begin + 1); | 277 current_function_builder_->EmitVarInt(node->end - node->begin + 1); |
| 282 for (int v = node->begin; v <= node->end; v++) { | 278 for (int v = node->begin; v <= node->end; v++) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 } | 331 } |
| 336 if (!has_default || case_count > 1) { | 332 if (!has_default || case_count > 1) { |
| 337 int default_block = has_default ? case_count - 1 : case_count; | 333 int default_block = has_default ? case_count - 1 : case_count; |
| 338 BlockVisitor switch_logic_block(this, nullptr, kExprBlock, false); | 334 BlockVisitor switch_logic_block(this, nullptr, kExprBlock, false); |
| 339 CaseNode* root = OrderCases(&cases, zone_); | 335 CaseNode* root = OrderCases(&cases, zone_); |
| 340 HandleCase(root, case_to_block, tag, default_block, 0); | 336 HandleCase(root, case_to_block, tag, default_block, 0); |
| 341 if (root->left != nullptr || root->right != nullptr || | 337 if (root->left != nullptr || root->right != nullptr || |
| 342 root->begin == root->end) { | 338 root->begin == root->end) { |
| 343 current_function_builder_->EmitWithU8(kExprBr, ARITY_0); | 339 current_function_builder_->EmitWithU8(kExprBr, ARITY_0); |
| 344 current_function_builder_->EmitVarInt(default_block); | 340 current_function_builder_->EmitVarInt(default_block); |
| 345 current_function_builder_->Emit(kExprNop); | |
| 346 } | 341 } |
| 347 } | 342 } |
| 348 for (int i = 0; i < case_count; i++) { | 343 for (int i = 0; i < case_count; i++) { |
| 349 CaseClause* clause = clauses->at(i); | 344 CaseClause* clause = clauses->at(i); |
| 350 RECURSE(VisitStatements(clause->statements())); | 345 RECURSE(VisitStatements(clause->statements())); |
| 351 BlockVisitor* v = blocks.at(case_count - i - 1); | 346 BlockVisitor* v = blocks.at(case_count - i - 1); |
| 352 blocks.pop_back(); | 347 blocks.pop_back(); |
| 353 delete v; | 348 delete v; |
| 354 } | 349 } |
| 355 } | 350 } |
| (...skipping 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1742 // that zone in constructor may be thrown away once wasm module is written. | 1737 // that zone in constructor may be thrown away once wasm module is written. |
| 1743 WasmModuleIndex* AsmWasmBuilder::Run() { | 1738 WasmModuleIndex* AsmWasmBuilder::Run() { |
| 1744 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_, typer_); | 1739 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_, typer_); |
| 1745 impl.Compile(); | 1740 impl.Compile(); |
| 1746 WasmModuleWriter* writer = impl.builder_->Build(zone_); | 1741 WasmModuleWriter* writer = impl.builder_->Build(zone_); |
| 1747 return writer->WriteTo(zone_); | 1742 return writer->WriteTo(zone_); |
| 1748 } | 1743 } |
| 1749 } // namespace wasm | 1744 } // namespace wasm |
| 1750 } // namespace internal | 1745 } // namespace internal |
| 1751 } // namespace v8 | 1746 } // namespace v8 |
| OLD | NEW |