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

Side by Side Diff: lib/compiler/implementation/ssa/codegen.dart

Issue 10544026: Simplify generated code for string interpolation by delaying the constant folding. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge. Created 8 years, 6 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
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 final JavaScriptBackend backend; 6 final JavaScriptBackend backend;
7 SsaCodeGeneratorTask(JavaScriptBackend backend) 7 SsaCodeGeneratorTask(JavaScriptBackend backend)
8 : this.backend = backend, 8 : this.backend = backend,
9 super(backend.compiler); 9 super(backend.compiler);
10 String get name() => 'SSA code generator'; 10 String get name() => 'SSA code generator';
(...skipping 1838 matching lines...) Expand 10 before | Expand all | Expand 10 after
1849 1849
1850 void visitStaticStore(HStaticStore node) { 1850 void visitStaticStore(HStaticStore node) {
1851 world.registerStaticUse(node.element); 1851 world.registerStaticUse(node.element);
1852 beginExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE); 1852 beginExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE);
1853 buffer.add(compiler.namer.isolateAccess(node.element)); 1853 buffer.add(compiler.namer.isolateAccess(node.element));
1854 buffer.add(' = '); 1854 buffer.add(' = ');
1855 use(node.inputs[0], JSPrecedence.ASSIGNMENT_PRECEDENCE); 1855 use(node.inputs[0], JSPrecedence.ASSIGNMENT_PRECEDENCE);
1856 endExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE); 1856 endExpression(JSPrecedence.ASSIGNMENT_PRECEDENCE);
1857 } 1857 }
1858 1858
1859 void visitStringConcat(HStringConcat node) {
1860 if (isEmptyString(node.left)) {
1861 beginExpression(JSPrecedence.CALL_PRECEDENCE);
1862 useStringified(node.right, JSPrecedence.EXPRESSION_PRECEDENCE);
1863 endExpression(JSPrecedence.CALL_PRECEDENCE);
1864 } else if (isEmptyString(node.right)) {
1865 beginExpression(JSPrecedence.CALL_PRECEDENCE);
1866 useStringified(node.left, JSPrecedence.EXPRESSION_PRECEDENCE);
1867 endExpression(JSPrecedence.CALL_PRECEDENCE);
1868 } else {
1869 JSBinaryOperatorPrecedence operatorPrecedences = JSPrecedence.binary['+'];
1870 beginExpression(operatorPrecedences.precedence);
1871 useStringified(node.left, operatorPrecedences.left);
1872 buffer.add(' + ');
1873 // If the right hand side is a string concatenation itself it is
1874 // safe to make it left associative.
1875 int rightPrecedence = (node.right is HStringConcat)
1876 ? JSPrecedence.ADDITIVE_PRECEDENCE
1877 : operatorPrecedences.right;
1878 useStringified(node.right, rightPrecedence);
1879 endExpression(operatorPrecedences.precedence);
1880 }
1881 }
1882
1883 bool isEmptyString(HInstruction node) {
1884 if (!node.isConstantString()) return false;
1885 HConstant constant = node;
1886 StringConstant string = constant.constant;
1887 return string.value.length == 0;
1888 }
1889
1890 void useStringified(HInstruction node, int precedence) {
1891 if (node.isString()) {
1892 use(node, precedence);
1893 } else {
1894 Element convertToString = compiler.findHelper(const SourceString("S"));
1895 world.registerStaticUse(convertToString);
1896 buffer.add(compiler.namer.isolateAccess(convertToString));
1897 buffer.add('(');
1898 use(node, JSPrecedence.EXPRESSION_PRECEDENCE);
1899 buffer.add(')');
1900 }
1901 }
1902
1859 void visitLiteralList(HLiteralList node) { 1903 void visitLiteralList(HLiteralList node) {
1860 generateArrayLiteral(node); 1904 generateArrayLiteral(node);
1861 } 1905 }
1862 1906
1863 void generateArrayLiteral(HLiteralList node) { 1907 void generateArrayLiteral(HLiteralList node) {
1864 buffer.add('['); 1908 buffer.add('[');
1865 int len = node.inputs.length; 1909 int len = node.inputs.length;
1866 for (int i = 0; i < len; i++) { 1910 for (int i = 0; i < len; i++) {
1867 if (i != 0) buffer.add(', '); 1911 if (i != 0) buffer.add(', ');
1868 use(node.inputs[i], JSPrecedence.ASSIGNMENT_PRECEDENCE); 1912 use(node.inputs[i], JSPrecedence.ASSIGNMENT_PRECEDENCE);
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
2629 startBailoutSwitch(); 2673 startBailoutSwitch();
2630 } 2674 }
2631 } 2675 }
2632 2676
2633 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { 2677 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) {
2634 if (labeledBlockInfo.body.start.hasGuards()) { 2678 if (labeledBlockInfo.body.start.hasGuards()) {
2635 endBailoutSwitch(); 2679 endBailoutSwitch();
2636 } 2680 }
2637 } 2681 }
2638 } 2682 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698