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

Side by Side Diff: dart/frog/leg/ssa/codegen.dart

Issue 9578021: Revert "Refactor constant part." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « dart/frog/leg/ssa/builder.dart ('k') | dart/frog/leg/ssa/nodes.dart » ('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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class SsaCodeGeneratorTask extends CompilerTask { 5 class SsaCodeGeneratorTask extends CompilerTask {
6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler); 6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler);
7 String get name() => 'SSA code generator'; 7 String get name() => 'SSA code generator';
8 8
9 String generate(WorkItem work, HGraph graph) { 9 String generate(WorkItem work, HGraph graph) {
10 return measure(() { 10 return measure(() {
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 // We can't use 'visitArguments', since our arguments start at input[0]. 647 // We can't use 'visitArguments', since our arguments start at input[0].
648 List<HInstruction> inputs = node.inputs; 648 List<HInstruction> inputs = node.inputs;
649 for (int i = 0; i < inputs.length; i++) { 649 for (int i = 0; i < inputs.length; i++) {
650 if (i != 0) buffer.add(', '); 650 if (i != 0) buffer.add(', ');
651 use(inputs[i], JSPrecedence.ASSIGNMENT_PRECEDENCE); 651 use(inputs[i], JSPrecedence.ASSIGNMENT_PRECEDENCE);
652 } 652 }
653 buffer.add(')'); 653 buffer.add(')');
654 endExpression(JSPrecedence.MEMBER_PRECEDENCE); 654 endExpression(JSPrecedence.MEMBER_PRECEDENCE);
655 } 655 }
656 656
657 visitConstant(HConstant node) { 657 visitLiteral(HLiteral node) {
658 // TODO(floitsch): the compile-time constant handler and the codegen 658 if (node.isLiteralNull()) {
659 // need to work together to avoid the parenthesis. See r4928 for an 659 beginExpression(JSPrecedence.PREFIX_PRECEDENCE);
660 // implementation that still dealt with precedence. 660 buffer.add("void 0");
661 ConstantHandler handler = compiler.constantHandler; 661 endExpression(JSPrecedence.PREFIX_PRECEDENCE);
662 String name = handler.getNameForConstant(node.constant); 662 } else if (node.value is num) {
663 if (name === null) { 663 int precedence = JSPrecedence.PRIMARY_PRECEDENCE;
664 assert(!node.constant.isObject()); 664 if (node.value < 0 ||
665 node.constant.writeJsCode(buffer, handler); 665 expectedPrecedence == JSPrecedence.MEMBER_PRECEDENCE) {
666 // Negative constants are really unary minus operator expressions.
667 // If the constant appear as a MemberExpression, it might be subject
668 // to the '.' operator, which shouldn't be put next to a number
669 // literal. It might be mistaken for a decimal point. Setting
670 // precedence to PREFIX_PRECEDENCE forces parentheses in this case.
671 precedence = JSPrecedence.PREFIX_PRECEDENCE;
672 }
673 beginExpression(precedence);
674 buffer.add(node.value);
675 endExpression(precedence);
676 } else if (node.isLiteralString()) {
677 DartString string = node.value;
678 buffer.add("'");
679 CompileTimeConstantHandler.writeEscapedString(string, buffer,
680 (String reason) {
681 compiler.cancel(reason, instruction: node);
682 });
683 buffer.add("'");
666 } else { 684 } else {
667 buffer.add(compiler.namer.CURRENT_ISOLATE); 685 buffer.add(node.value);
668 buffer.add(".");
669 buffer.add(name);
670 } 686 }
671 } 687 }
672 688
673 visitLoopBranch(HLoopBranch node) { 689 visitLoopBranch(HLoopBranch node) {
674 HBasicBlock branchBlock = currentBlock; 690 HBasicBlock branchBlock = currentBlock;
675 handleLoopCondition(node); 691 handleLoopCondition(node);
676 List<HBasicBlock> dominated = currentBlock.dominatedBlocks; 692 List<HBasicBlock> dominated = currentBlock.dominatedBlocks;
677 // For a do while loop, the body has already been visited. 693 // For a do while loop, the body has already been visited.
678 if (!node.isDoWhile()) { 694 if (!node.isDoWhile()) {
679 visitBasicBlock(dominated[0]); 695 visitBasicBlock(dominated[0]);
(...skipping 20 matching lines...) Expand all
700 buffer.add(parameterNames[node.element]); 716 buffer.add(parameterNames[node.element]);
701 } 717 }
702 718
703 visitPhi(HPhi node) { 719 visitPhi(HPhi node) {
704 unreachable(); 720 unreachable();
705 } 721 }
706 722
707 visitReturn(HReturn node) { 723 visitReturn(HReturn node) {
708 assert(node.inputs.length == 1); 724 assert(node.inputs.length == 1);
709 HInstruction input = node.inputs[0]; 725 HInstruction input = node.inputs[0];
710 if (input.isConstantNull()) { 726 if (input.isLiteralNull()) {
711 buffer.add('return;\n'); 727 buffer.add('return;\n');
712 } else { 728 } else {
713 buffer.add('return '); 729 buffer.add('return ');
714 use(node.inputs[0], JSPrecedence.EXPRESSION_PRECEDENCE); 730 use(node.inputs[0], JSPrecedence.EXPRESSION_PRECEDENCE);
715 buffer.add(';\n'); 731 buffer.add(';\n');
716 } 732 }
717 } 733 }
718 734
719 visitThis(HThis node) { 735 visitThis(HThis node) {
720 buffer.add('this'); 736 buffer.add('this');
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 startBailoutSwitch(); 1395 startBailoutSwitch();
1380 } 1396 }
1381 } 1397 }
1382 1398
1383 void endElse(HIf node) { 1399 void endElse(HIf node) {
1384 if (node.elseBlock.hasBailouts()) { 1400 if (node.elseBlock.hasBailouts()) {
1385 endBailoutSwitch(); 1401 endBailoutSwitch();
1386 } 1402 }
1387 } 1403 }
1388 } 1404 }
OLDNEW
« no previous file with comments | « dart/frog/leg/ssa/builder.dart ('k') | dart/frog/leg/ssa/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698