OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 SetStackOverflow(); | 232 SetStackOverflow(); |
233 } | 233 } |
234 | 234 |
235 | 235 |
236 void FlowGraphBuilder::VisitBreakStatement(BreakStatement* stmt) { | 236 void FlowGraphBuilder::VisitBreakStatement(BreakStatement* stmt) { |
237 SetStackOverflow(); | 237 SetStackOverflow(); |
238 } | 238 } |
239 | 239 |
240 | 240 |
241 void FlowGraphBuilder::VisitReturnStatement(ReturnStatement* stmt) { | 241 void FlowGraphBuilder::VisitReturnStatement(ReturnStatement* stmt) { |
242 Visit(stmt->expression()); | 242 SetStackOverflow(); |
243 graph_.AppendInstruction(stmt); | |
244 graph_.AppendNode(global_exit()); | |
245 } | 243 } |
246 | 244 |
247 | 245 |
248 void FlowGraphBuilder::VisitWithEnterStatement(WithEnterStatement* stmt) { | 246 void FlowGraphBuilder::VisitWithEnterStatement(WithEnterStatement* stmt) { |
249 Visit(stmt->expression()); | 247 SetStackOverflow(); |
250 graph_.AppendInstruction(stmt); | |
251 } | 248 } |
252 | 249 |
253 | 250 |
254 void FlowGraphBuilder::VisitWithExitStatement(WithExitStatement* stmt) { | 251 void FlowGraphBuilder::VisitWithExitStatement(WithExitStatement* stmt) { |
255 graph_.AppendInstruction(stmt); | 252 SetStackOverflow(); |
256 } | 253 } |
257 | 254 |
258 | 255 |
259 void FlowGraphBuilder::VisitSwitchStatement(SwitchStatement* stmt) { | 256 void FlowGraphBuilder::VisitSwitchStatement(SwitchStatement* stmt) { |
260 SetStackOverflow(); | 257 SetStackOverflow(); |
261 } | 258 } |
262 | 259 |
263 | 260 |
264 void FlowGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) { | 261 void FlowGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) { |
265 JoinNode* join = new JoinNode(); | 262 SetStackOverflow(); |
266 FlowGraph original = graph_; | |
267 graph_ = FlowGraph::Empty(); | |
268 Visit(stmt->body()); | |
269 | |
270 FlowGraph body = graph_; | |
271 graph_ = FlowGraph::Empty(); | |
272 Visit(stmt->cond()); | |
273 | |
274 BranchNode* branch = new BranchNode(); | |
275 | |
276 // Add body, condition and branch. | |
277 original.AppendNode(join); | |
278 original.AppendGraph(&body); | |
279 original.AppendGraph(&graph_); // The condition. | |
280 original.AppendNode(branch); | |
281 | |
282 // Tie the knot. | |
283 branch->AddSuccessor(join); | |
284 join->AddPredecessor(branch); | |
285 | |
286 graph_ = original; | |
287 } | 263 } |
288 | 264 |
289 | 265 |
290 void FlowGraphBuilder::VisitWhileStatement(WhileStatement* stmt) { | 266 void FlowGraphBuilder::VisitWhileStatement(WhileStatement* stmt) { |
291 JoinNode* join = new JoinNode(); | 267 SetStackOverflow(); |
292 FlowGraph original = graph_; | |
293 graph_ = FlowGraph::Empty(); | |
294 Visit(stmt->cond()); | |
295 | |
296 BranchNode* branch = new BranchNode(); | |
297 FlowGraph condition = graph_; | |
298 graph_ = FlowGraph::Empty(); | |
299 Visit(stmt->body()); | |
300 | |
301 original.Loop(join, &condition, branch, &graph_); | |
302 graph_ = original; | |
303 } | 268 } |
304 | 269 |
305 | 270 |
306 void FlowGraphBuilder::VisitForStatement(ForStatement* stmt) { | 271 void FlowGraphBuilder::VisitForStatement(ForStatement* stmt) { |
307 if (stmt->init() != NULL) Visit(stmt->init()); | 272 if (stmt->init() != NULL) Visit(stmt->init()); |
308 | 273 |
309 JoinNode* join = new JoinNode(); | 274 JoinNode* join = new JoinNode(); |
310 FlowGraph original = graph_; | 275 FlowGraph original = graph_; |
311 graph_ = FlowGraph::Empty(); | 276 graph_ = FlowGraph::Empty(); |
312 if (stmt->cond() != NULL) Visit(stmt->cond()); | 277 if (stmt->cond() != NULL) Visit(stmt->cond()); |
313 | 278 |
314 BranchNode* branch = new BranchNode(); | 279 BranchNode* branch = new BranchNode(); |
315 FlowGraph condition = graph_; | 280 FlowGraph condition = graph_; |
316 graph_ = FlowGraph::Empty(); | 281 graph_ = FlowGraph::Empty(); |
317 Visit(stmt->body()); | 282 Visit(stmt->body()); |
318 | 283 |
319 if (stmt->next() != NULL) Visit(stmt->next()); | 284 if (stmt->next() != NULL) Visit(stmt->next()); |
320 | 285 |
321 original.Loop(join, &condition, branch, &graph_); | 286 original.Loop(join, &condition, branch, &graph_); |
322 graph_ = original; | 287 graph_ = original; |
323 } | 288 } |
324 | 289 |
325 | 290 |
326 void FlowGraphBuilder::VisitForInStatement(ForInStatement* stmt) { | 291 void FlowGraphBuilder::VisitForInStatement(ForInStatement* stmt) { |
327 Visit(stmt->enumerable()); | 292 SetStackOverflow(); |
328 | |
329 JoinNode* join = new JoinNode(); | |
330 FlowGraph empty; | |
331 BranchNode* branch = new BranchNode(); | |
332 FlowGraph original = graph_; | |
333 graph_ = FlowGraph::Empty(); | |
334 Visit(stmt->body()); | |
335 | |
336 original.Loop(join, &empty, branch, &graph_); | |
337 graph_ = original; | |
338 } | 293 } |
339 | 294 |
340 | 295 |
341 void FlowGraphBuilder::VisitTryCatchStatement(TryCatchStatement* stmt) { | 296 void FlowGraphBuilder::VisitTryCatchStatement(TryCatchStatement* stmt) { |
342 SetStackOverflow(); | 297 SetStackOverflow(); |
343 } | 298 } |
344 | 299 |
345 | 300 |
346 void FlowGraphBuilder::VisitTryFinallyStatement(TryFinallyStatement* stmt) { | 301 void FlowGraphBuilder::VisitTryFinallyStatement(TryFinallyStatement* stmt) { |
347 SetStackOverflow(); | 302 SetStackOverflow(); |
348 } | 303 } |
349 | 304 |
350 | 305 |
351 void FlowGraphBuilder::VisitDebuggerStatement(DebuggerStatement* stmt) { | 306 void FlowGraphBuilder::VisitDebuggerStatement(DebuggerStatement* stmt) { |
352 graph_.AppendInstruction(stmt); | 307 SetStackOverflow(); |
353 } | 308 } |
354 | 309 |
355 | 310 |
356 void FlowGraphBuilder::VisitFunctionLiteral(FunctionLiteral* expr) { | 311 void FlowGraphBuilder::VisitFunctionLiteral(FunctionLiteral* expr) { |
357 graph_.AppendInstruction(expr); | 312 SetStackOverflow(); |
358 } | 313 } |
359 | 314 |
360 | 315 |
361 void FlowGraphBuilder::VisitFunctionBoilerplateLiteral( | 316 void FlowGraphBuilder::VisitFunctionBoilerplateLiteral( |
362 FunctionBoilerplateLiteral* expr) { | 317 FunctionBoilerplateLiteral* expr) { |
363 graph_.AppendInstruction(expr); | 318 SetStackOverflow(); |
364 } | 319 } |
365 | 320 |
366 | 321 |
367 void FlowGraphBuilder::VisitConditional(Conditional* expr) { | 322 void FlowGraphBuilder::VisitConditional(Conditional* expr) { |
368 Visit(expr->condition()); | 323 SetStackOverflow(); |
369 | |
370 BranchNode* branch = new BranchNode(); | |
371 FlowGraph original = graph_; | |
372 graph_ = FlowGraph::Empty(); | |
373 Visit(expr->then_expression()); | |
374 | |
375 FlowGraph left = graph_; | |
376 graph_ = FlowGraph::Empty(); | |
377 Visit(expr->else_expression()); | |
378 | |
379 JoinNode* join = new JoinNode(); | |
380 original.Split(branch, &left, &graph_, join); | |
381 graph_ = original; | |
382 } | 324 } |
383 | 325 |
384 | 326 |
385 void FlowGraphBuilder::VisitSlot(Slot* expr) { | 327 void FlowGraphBuilder::VisitSlot(Slot* expr) { |
386 UNREACHABLE(); | 328 UNREACHABLE(); |
387 } | 329 } |
388 | 330 |
389 | 331 |
390 void FlowGraphBuilder::VisitVariableProxy(VariableProxy* expr) { | 332 void FlowGraphBuilder::VisitVariableProxy(VariableProxy* expr) { |
391 graph_.AppendInstruction(expr); | 333 graph_.AppendInstruction(expr); |
392 } | 334 } |
393 | 335 |
394 | 336 |
395 void FlowGraphBuilder::VisitLiteral(Literal* expr) { | 337 void FlowGraphBuilder::VisitLiteral(Literal* expr) { |
396 graph_.AppendInstruction(expr); | 338 graph_.AppendInstruction(expr); |
397 } | 339 } |
398 | 340 |
399 | 341 |
400 void FlowGraphBuilder::VisitRegExpLiteral(RegExpLiteral* expr) { | 342 void FlowGraphBuilder::VisitRegExpLiteral(RegExpLiteral* expr) { |
401 graph_.AppendInstruction(expr); | 343 SetStackOverflow(); |
402 } | 344 } |
403 | 345 |
404 | 346 |
405 void FlowGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) { | 347 void FlowGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) { |
406 ZoneList<ObjectLiteral::Property*>* properties = expr->properties(); | 348 SetStackOverflow(); |
407 for (int i = 0, len = properties->length(); i < len; i++) { | |
408 Visit(properties->at(i)->value()); | |
409 } | |
410 graph_.AppendInstruction(expr); | |
411 } | 349 } |
412 | 350 |
413 | 351 |
414 void FlowGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) { | 352 void FlowGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) { |
415 ZoneList<Expression*>* values = expr->values(); | 353 SetStackOverflow(); |
416 for (int i = 0, len = values->length(); i < len; i++) { | |
417 Visit(values->at(i)); | |
418 } | |
419 graph_.AppendInstruction(expr); | |
420 } | 354 } |
421 | 355 |
422 | 356 |
423 void FlowGraphBuilder::VisitCatchExtensionObject(CatchExtensionObject* expr) { | 357 void FlowGraphBuilder::VisitCatchExtensionObject(CatchExtensionObject* expr) { |
424 graph_.AppendInstruction(expr); | 358 SetStackOverflow(); |
425 } | 359 } |
426 | 360 |
427 | 361 |
428 void FlowGraphBuilder::VisitAssignment(Assignment* expr) { | 362 void FlowGraphBuilder::VisitAssignment(Assignment* expr) { |
429 Variable* var = expr->target()->AsVariableProxy()->AsVariable(); | 363 Variable* var = expr->target()->AsVariableProxy()->AsVariable(); |
430 Property* prop = expr->target()->AsProperty(); | 364 Property* prop = expr->target()->AsProperty(); |
431 // Left-hand side can be a variable or property (or reference error) but | 365 // Left-hand side can be a variable or property (or reference error) but |
432 // not both. | 366 // not both. |
433 ASSERT(var == NULL || prop == NULL); | 367 ASSERT(var == NULL || prop == NULL); |
434 if (var != NULL) { | 368 if (var != NULL) { |
435 Visit(expr->value()); | 369 Visit(expr->value()); |
436 if (var->IsStackAllocated()) definitions_.Add(expr); | 370 if (var->IsStackAllocated()) definitions_.Add(expr); |
437 | 371 |
438 } else if (prop != NULL) { | 372 } else if (prop != NULL) { |
439 Visit(prop->obj()); | 373 Visit(prop->obj()); |
440 if (!prop->key()->IsPropertyName()) Visit(prop->key()); | 374 if (!prop->key()->IsPropertyName()) Visit(prop->key()); |
441 Visit(expr->value()); | 375 Visit(expr->value()); |
442 } | 376 } |
443 graph_.AppendInstruction(expr); | 377 graph_.AppendInstruction(expr); |
444 } | 378 } |
445 | 379 |
446 | 380 |
447 void FlowGraphBuilder::VisitThrow(Throw* expr) { | 381 void FlowGraphBuilder::VisitThrow(Throw* expr) { |
448 Visit(expr->exception()); | 382 SetStackOverflow(); |
449 graph_.AppendInstruction(expr); | |
450 } | 383 } |
451 | 384 |
452 | 385 |
453 void FlowGraphBuilder::VisitProperty(Property* expr) { | 386 void FlowGraphBuilder::VisitProperty(Property* expr) { |
454 Visit(expr->obj()); | 387 Visit(expr->obj()); |
455 if (!expr->key()->IsPropertyName()) Visit(expr->key()); | 388 if (!expr->key()->IsPropertyName()) Visit(expr->key()); |
456 graph_.AppendInstruction(expr); | 389 graph_.AppendInstruction(expr); |
457 } | 390 } |
458 | 391 |
459 | 392 |
460 void FlowGraphBuilder::VisitCall(Call* expr) { | 393 void FlowGraphBuilder::VisitCall(Call* expr) { |
461 Visit(expr->expression()); | 394 Visit(expr->expression()); |
462 ZoneList<Expression*>* arguments = expr->arguments(); | 395 ZoneList<Expression*>* arguments = expr->arguments(); |
463 for (int i = 0, len = arguments->length(); i < len; i++) { | 396 for (int i = 0, len = arguments->length(); i < len; i++) { |
464 Visit(arguments->at(i)); | 397 Visit(arguments->at(i)); |
465 } | 398 } |
466 graph_.AppendInstruction(expr); | 399 graph_.AppendInstruction(expr); |
467 } | 400 } |
468 | 401 |
469 | 402 |
470 void FlowGraphBuilder::VisitCallNew(CallNew* expr) { | 403 void FlowGraphBuilder::VisitCallNew(CallNew* expr) { |
471 Visit(expr->expression()); | 404 SetStackOverflow(); |
472 ZoneList<Expression*>* arguments = expr->arguments(); | |
473 for (int i = 0, len = arguments->length(); i < len; i++) { | |
474 Visit(arguments->at(i)); | |
475 } | |
476 graph_.AppendInstruction(expr); | |
477 } | 405 } |
478 | 406 |
479 | 407 |
480 void FlowGraphBuilder::VisitCallRuntime(CallRuntime* expr) { | 408 void FlowGraphBuilder::VisitCallRuntime(CallRuntime* expr) { |
481 ZoneList<Expression*>* arguments = expr->arguments(); | 409 SetStackOverflow(); |
482 for (int i = 0, len = arguments->length(); i < len; i++) { | |
483 Visit(arguments->at(i)); | |
484 } | |
485 graph_.AppendInstruction(expr); | |
486 } | 410 } |
487 | 411 |
488 | 412 |
489 void FlowGraphBuilder::VisitUnaryOperation(UnaryOperation* expr) { | 413 void FlowGraphBuilder::VisitUnaryOperation(UnaryOperation* expr) { |
490 Visit(expr->expression()); | 414 switch (expr->op()) { |
491 graph_.AppendInstruction(expr); | 415 case Token::NOT: |
| 416 case Token::BIT_NOT: |
| 417 case Token::DELETE: |
| 418 case Token::TYPEOF: |
| 419 case Token::VOID: |
| 420 SetStackOverflow(); |
| 421 break; |
| 422 |
| 423 case Token::ADD: |
| 424 case Token::SUB: |
| 425 Visit(expr->expression()); |
| 426 graph_.AppendInstruction(expr); |
| 427 break; |
| 428 |
| 429 default: |
| 430 UNREACHABLE(); |
| 431 } |
492 } | 432 } |
493 | 433 |
494 | 434 |
495 void FlowGraphBuilder::VisitCountOperation(CountOperation* expr) { | 435 void FlowGraphBuilder::VisitCountOperation(CountOperation* expr) { |
496 Visit(expr->expression()); | 436 Visit(expr->expression()); |
497 Variable* var = expr->expression()->AsVariableProxy()->AsVariable(); | 437 Variable* var = expr->expression()->AsVariableProxy()->AsVariable(); |
498 if (var != NULL && var->IsStackAllocated()) { | 438 if (var != NULL && var->IsStackAllocated()) { |
499 definitions_.Add(expr); | 439 definitions_.Add(expr); |
500 } | 440 } |
501 graph_.AppendInstruction(expr); | 441 graph_.AppendInstruction(expr); |
502 } | 442 } |
503 | 443 |
504 | 444 |
505 void FlowGraphBuilder::VisitBinaryOperation(BinaryOperation* expr) { | 445 void FlowGraphBuilder::VisitBinaryOperation(BinaryOperation* expr) { |
506 Visit(expr->left()); | |
507 | 446 |
508 switch (expr->op()) { | 447 switch (expr->op()) { |
509 case Token::COMMA: | 448 case Token::COMMA: |
510 Visit(expr->right()); | 449 case Token::OR: |
| 450 case Token::AND: |
| 451 SetStackOverflow(); |
511 break; | 452 break; |
512 | 453 |
513 case Token::OR: { | |
514 BranchNode* branch = new BranchNode(); | |
515 FlowGraph original = graph_; | |
516 graph_ = FlowGraph::Empty(); | |
517 Visit(expr->right()); | |
518 FlowGraph empty; | |
519 JoinNode* join = new JoinNode(); | |
520 original.Split(branch, &empty, &graph_, join); | |
521 graph_ = original; | |
522 break; | |
523 } | |
524 | |
525 case Token::AND: { | |
526 BranchNode* branch = new BranchNode(); | |
527 FlowGraph original = graph_; | |
528 graph_ = FlowGraph::Empty(); | |
529 Visit(expr->right()); | |
530 FlowGraph empty; | |
531 JoinNode* join = new JoinNode(); | |
532 original.Split(branch, &graph_, &empty, join); | |
533 graph_ = original; | |
534 break; | |
535 } | |
536 | |
537 case Token::BIT_OR: | 454 case Token::BIT_OR: |
538 case Token::BIT_XOR: | 455 case Token::BIT_XOR: |
539 case Token::BIT_AND: | 456 case Token::BIT_AND: |
540 case Token::SHL: | 457 case Token::SHL: |
541 case Token::SAR: | |
542 case Token::SHR: | 458 case Token::SHR: |
543 case Token::ADD: | 459 case Token::ADD: |
544 case Token::SUB: | 460 case Token::SUB: |
545 case Token::MUL: | 461 case Token::MUL: |
546 case Token::DIV: | 462 case Token::DIV: |
547 case Token::MOD: | 463 case Token::MOD: |
| 464 case Token::SAR: |
| 465 Visit(expr->left()); |
548 Visit(expr->right()); | 466 Visit(expr->right()); |
549 graph_.AppendInstruction(expr); | 467 graph_.AppendInstruction(expr); |
550 break; | 468 break; |
551 | 469 |
552 default: | 470 default: |
553 UNREACHABLE(); | 471 UNREACHABLE(); |
554 } | 472 } |
555 } | 473 } |
556 | 474 |
557 | 475 |
558 void FlowGraphBuilder::VisitCompareOperation(CompareOperation* expr) { | 476 void FlowGraphBuilder::VisitCompareOperation(CompareOperation* expr) { |
559 Visit(expr->left()); | 477 switch (expr->op()) { |
560 Visit(expr->right()); | 478 case Token::EQ: |
561 graph_.AppendInstruction(expr); | 479 case Token::NE: |
| 480 case Token::EQ_STRICT: |
| 481 case Token::NE_STRICT: |
| 482 case Token::INSTANCEOF: |
| 483 case Token::IN: |
| 484 SetStackOverflow(); |
| 485 break; |
| 486 |
| 487 case Token::LT: |
| 488 case Token::GT: |
| 489 case Token::LTE: |
| 490 case Token::GTE: |
| 491 Visit(expr->left()); |
| 492 Visit(expr->right()); |
| 493 graph_.AppendInstruction(expr); |
| 494 break; |
| 495 |
| 496 default: |
| 497 UNREACHABLE(); |
| 498 } |
562 } | 499 } |
563 | 500 |
564 | 501 |
565 void FlowGraphBuilder::VisitThisFunction(ThisFunction* expr) { | 502 void FlowGraphBuilder::VisitThisFunction(ThisFunction* expr) { |
566 graph_.AppendInstruction(expr); | 503 SetStackOverflow(); |
567 } | 504 } |
568 | 505 |
569 | 506 |
570 void AstLabeler::Label(CompilationInfo* info) { | 507 void AstLabeler::Label(CompilationInfo* info) { |
571 info_ = info; | 508 info_ = info; |
572 VisitStatements(info_->function()->body()); | 509 VisitStatements(info_->function()->body()); |
573 } | 510 } |
574 | 511 |
575 | 512 |
576 void AstLabeler::VisitStatements(ZoneList<Statement*>* stmts) { | 513 void AstLabeler::VisitStatements(ZoneList<Statement*>* stmts) { |
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1458 for (int i = postorder->length() - 1; i >= 0; i--) { | 1395 for (int i = postorder->length() - 1; i >= 0; i--) { |
1459 postorder->at(i)->PrintText(); | 1396 postorder->at(i)->PrintText(); |
1460 } | 1397 } |
1461 } | 1398 } |
1462 | 1399 |
1463 | 1400 |
1464 #endif // defined(DEBUG) | 1401 #endif // defined(DEBUG) |
1465 | 1402 |
1466 | 1403 |
1467 } } // namespace v8::internal | 1404 } } // namespace v8::internal |
OLD | NEW |