Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 part of ssa; | 5 part of ssa; |
| 6 | 6 |
| 7 class SsaCodeGeneratorTask extends CompilerTask { | 7 class SsaCodeGeneratorTask extends CompilerTask { |
| 8 | 8 |
| 9 final JavaScriptBackend backend; | 9 final JavaScriptBackend backend; |
| 10 | 10 |
| (...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1606 List<DartType> instantiatedTypes = node.instantiatedTypes; | 1606 List<DartType> instantiatedTypes = node.instantiatedTypes; |
| 1607 | 1607 |
| 1608 world.registerStaticUse(element); | 1608 world.registerStaticUse(element); |
| 1609 | 1609 |
| 1610 if (instantiatedTypes != null && !instantiatedTypes.isEmpty) { | 1610 if (instantiatedTypes != null && !instantiatedTypes.isEmpty) { |
| 1611 instantiatedTypes.forEach((type) { | 1611 instantiatedTypes.forEach((type) { |
| 1612 world.registerInstantiatedType(type, work.resolutionTree); | 1612 world.registerInstantiatedType(type, work.resolutionTree); |
| 1613 }); | 1613 }); |
| 1614 } | 1614 } |
| 1615 | 1615 |
| 1616 push(new js.VariableUse(backend.namer.isolateAccess(node.element))); | 1616 push(backend.namer.elementAccess(node.element)); |
| 1617 push(new js.Call(pop(), visitArguments(node.inputs, start: 0)), node); | 1617 push(new js.Call(pop(), visitArguments(node.inputs, start: 0)), node); |
| 1618 } | 1618 } |
| 1619 | 1619 |
| 1620 visitInvokeSuper(HInvokeSuper node) { | 1620 visitInvokeSuper(HInvokeSuper node) { |
| 1621 Element superMethod = node.element; | 1621 Element superMethod = node.element; |
| 1622 world.registerStaticUse(superMethod); | 1622 world.registerStaticUse(superMethod); |
| 1623 ClassElement superClass = superMethod.getEnclosingClass(); | 1623 ClassElement superClass = superMethod.getEnclosingClass(); |
| 1624 if (superMethod.kind == ElementKind.FIELD) { | 1624 if (superMethod.kind == ElementKind.FIELD) { |
| 1625 String fieldName = backend.namer.instanceFieldPropertyName(superMethod); | 1625 String fieldName = backend.namer.instanceFieldPropertyName(superMethod); |
| 1626 use(node.inputs[0]); | 1626 use(node.inputs[0]); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1738 interpolatedExpressions.add(pop()); | 1738 interpolatedExpressions.add(pop()); |
| 1739 } | 1739 } |
| 1740 push(node.codeTemplate.instantiate(interpolatedExpressions)); | 1740 push(node.codeTemplate.instantiate(interpolatedExpressions)); |
| 1741 } | 1741 } |
| 1742 | 1742 |
| 1743 // TODO(sra): Tell world.nativeEnqueuer about the types created here. | 1743 // TODO(sra): Tell world.nativeEnqueuer about the types created here. |
| 1744 registerForeignTypes(node); | 1744 registerForeignTypes(node); |
| 1745 } | 1745 } |
| 1746 | 1746 |
| 1747 visitForeignNew(HForeignNew node) { | 1747 visitForeignNew(HForeignNew node) { |
| 1748 String jsClassReference = backend.namer.isolateAccess(node.element); | 1748 js.Expression jsClassReference = backend.namer.elementAccess(node.element); |
| 1749 List<js.Expression> arguments = visitArguments(node.inputs, start: 0); | 1749 List<js.Expression> arguments = visitArguments(node.inputs, start: 0); |
| 1750 // TODO(floitsch): jsClassReference is an Access. We shouldn't treat it | 1750 push(new js.New(jsClassReference, arguments), node); |
| 1751 // as if it was a string. | |
| 1752 push(new js.New(new js.VariableUse(jsClassReference), arguments), node); | |
| 1753 registerForeignTypes(node); | 1751 registerForeignTypes(node); |
| 1754 if (node.instantiatedTypes == null) { | 1752 if (node.instantiatedTypes == null) { |
| 1755 return; | 1753 return; |
| 1756 } | 1754 } |
| 1757 node.instantiatedTypes.forEach((type) { | 1755 node.instantiatedTypes.forEach((type) { |
| 1758 world.registerInstantiatedType(type, work.resolutionTree); | 1756 world.registerInstantiatedType(type, work.resolutionTree); |
| 1759 }); | 1757 }); |
| 1760 } | 1758 } |
| 1761 | 1759 |
| 1762 js.Expression newLiteralBool(bool value) { | 1760 js.Expression newLiteralBool(bool value) { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1978 thenBody = unwrapStatement(thenBody); | 1976 thenBody = unwrapStatement(thenBody); |
| 1979 pushStatement(new js.If.noElse(underOver, thenBody), node); | 1977 pushStatement(new js.If.noElse(underOver, thenBody), node); |
| 1980 } else { | 1978 } else { |
| 1981 generateThrowWithHelper('ioore', [node.array, node.index]); | 1979 generateThrowWithHelper('ioore', [node.array, node.index]); |
| 1982 } | 1980 } |
| 1983 } | 1981 } |
| 1984 | 1982 |
| 1985 void generateThrowWithHelper(String helperName, argument) { | 1983 void generateThrowWithHelper(String helperName, argument) { |
| 1986 Element helper = compiler.findHelper(helperName); | 1984 Element helper = compiler.findHelper(helperName); |
| 1987 world.registerStaticUse(helper); | 1985 world.registerStaticUse(helper); |
| 1988 js.VariableUse jsHelper = | 1986 js.Expression jsHelper = backend.namer.elementAccess(helper); |
| 1989 new js.VariableUse(backend.namer.isolateAccess(helper)); | |
| 1990 List arguments = []; | 1987 List arguments = []; |
| 1991 var location; | 1988 var location; |
| 1992 if (argument is List) { | 1989 if (argument is List) { |
| 1993 location = argument[0]; | 1990 location = argument[0]; |
| 1994 argument.forEach((instruction) { | 1991 argument.forEach((instruction) { |
| 1995 use(instruction); | 1992 use(instruction); |
| 1996 arguments.add(pop()); | 1993 arguments.add(pop()); |
| 1997 }); | 1994 }); |
| 1998 } else { | 1995 } else { |
| 1999 location = argument; | 1996 location = argument; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 2012 } | 2009 } |
| 2013 } | 2010 } |
| 2014 | 2011 |
| 2015 visitThrowExpression(HThrowExpression node) { | 2012 visitThrowExpression(HThrowExpression node) { |
| 2016 HInstruction argument = node.inputs[0]; | 2013 HInstruction argument = node.inputs[0]; |
| 2017 use(argument); | 2014 use(argument); |
| 2018 | 2015 |
| 2019 Element helper = compiler.findHelper("throwExpression"); | 2016 Element helper = compiler.findHelper("throwExpression"); |
| 2020 world.registerStaticUse(helper); | 2017 world.registerStaticUse(helper); |
| 2021 | 2018 |
| 2022 js.VariableUse jsHelper = | 2019 js.Expression jsHelper = backend.namer.elementAccess(helper); |
| 2023 new js.VariableUse(backend.namer.isolateAccess(helper)); | |
| 2024 js.Call value = new js.Call(jsHelper, [pop()]); | 2020 js.Call value = new js.Call(jsHelper, [pop()]); |
| 2025 attachLocation(value, argument); | 2021 attachLocation(value, argument); |
| 2026 push(value, node); | 2022 push(value, node); |
| 2027 } | 2023 } |
| 2028 | 2024 |
| 2029 void visitSwitch(HSwitch node) { | 2025 void visitSwitch(HSwitch node) { |
| 2030 // Switches are handled using [visitSwitchInfo]. | 2026 // Switches are handled using [visitSwitchInfo]. |
| 2031 } | 2027 } |
| 2032 | 2028 |
| 2033 void visitStatic(HStatic node) { | 2029 void visitStatic(HStatic node) { |
| 2034 Element element = node.element; | 2030 Element element = node.element; |
| 2035 if (element.isFunction()) { | 2031 if (element.isFunction()) { |
| 2036 push(new js.VariableUse( | 2032 push(backend.namer.isolateStaticClosureAccess(node.element)); |
| 2037 backend.namer.isolateStaticClosureAccess(node.element))); | |
| 2038 } else { | 2033 } else { |
| 2039 push(new js.VariableUse(backend.namer.isolateAccess(node.element))); | 2034 push(backend.namer.elementAccess(node.element)); |
| 2040 } | 2035 } |
| 2041 world.registerStaticUse(element); | 2036 world.registerStaticUse(element); |
| 2042 } | 2037 } |
| 2043 | 2038 |
| 2044 void visitLazyStatic(HLazyStatic node) { | 2039 void visitLazyStatic(HLazyStatic node) { |
| 2045 Element element = node.element; | 2040 Element element = node.element; |
| 2046 world.registerStaticUse(element); | 2041 world.registerStaticUse(element); |
| 2047 String lazyGetter = backend.namer.isolateLazyInitializerAccess(element); | 2042 js.Expression lazyGetter = backend.namer.isolateLazyInitializerAccess(elemen t); |
|
floitsch
2014/04/28 14:17:51
long line.
sra1
2014/04/28 23:00:41
Done.
| |
| 2048 js.VariableUse target = new js.VariableUse(lazyGetter); | 2043 //js.VariableUse target = new js.VariableUse(lazyGetter); |
|
floitsch
2014/04/28 14:17:51
dead code.
sra1
2014/04/28 23:00:41
Done.
| |
| 2049 js.Call call = new js.Call(target, <js.Expression>[]); | 2044 js.Call call = new js.Call(lazyGetter, <js.Expression>[]); |
| 2050 push(call, node); | 2045 push(call, node); |
| 2051 } | 2046 } |
| 2052 | 2047 |
| 2053 void visitStaticStore(HStaticStore node) { | 2048 void visitStaticStore(HStaticStore node) { |
| 2054 world.registerStaticUse(node.element); | 2049 world.registerStaticUse(node.element); |
| 2055 js.Node variable = backend.namer.elementAccess(node.element); | 2050 js.Node variable = backend.namer.elementAccess(node.element); |
| 2056 use(node.inputs[0]); | 2051 use(node.inputs[0]); |
| 2057 push(new js.Assignment(variable, pop()), node); | 2052 push(new js.Assignment(variable, pop()), node); |
| 2058 } | 2053 } |
| 2059 | 2054 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 2076 && node.usedBy[0] is HStringConcat | 2071 && node.usedBy[0] is HStringConcat |
| 2077 && node.usedBy[0].inputs[1] == node) { | 2072 && node.usedBy[0].inputs[1] == node) { |
| 2078 // The context is already <string> + value. | 2073 // The context is already <string> + value. |
| 2079 } else { | 2074 } else { |
| 2080 // Force an empty string for the first operand. | 2075 // Force an empty string for the first operand. |
| 2081 push(new js.Binary('+', js.string(""), pop()), node); | 2076 push(new js.Binary('+', js.string(""), pop()), node); |
| 2082 } | 2077 } |
| 2083 } else { | 2078 } else { |
| 2084 Element convertToString = backend.getStringInterpolationHelper(); | 2079 Element convertToString = backend.getStringInterpolationHelper(); |
| 2085 world.registerStaticUse(convertToString); | 2080 world.registerStaticUse(convertToString); |
| 2086 js.VariableUse variableUse = | 2081 js.Expression jsHelper = backend.namer.elementAccess(convertToString); |
| 2087 new js.VariableUse(backend.namer.isolateAccess(convertToString)); | |
| 2088 use(input); | 2082 use(input); |
| 2089 push(new js.Call(variableUse, <js.Expression>[pop()]), node); | 2083 push(new js.Call(jsHelper, <js.Expression>[pop()]), node); |
| 2090 } | 2084 } |
| 2091 } | 2085 } |
| 2092 | 2086 |
| 2093 void visitLiteralList(HLiteralList node) { | 2087 void visitLiteralList(HLiteralList node) { |
| 2094 world.registerInstantiatedClass( | 2088 world.registerInstantiatedClass( |
| 2095 compiler.listClass, work.resolutionTree); | 2089 compiler.listClass, work.resolutionTree); |
| 2096 generateArrayLiteral(node); | 2090 generateArrayLiteral(node); |
| 2097 } | 2091 } |
| 2098 | 2092 |
| 2099 void generateArrayLiteral(HLiteralList node) { | 2093 void generateArrayLiteral(HLiteralList node) { |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2683 js.PropertyAccess accessHelper(String name) { | 2677 js.PropertyAccess accessHelper(String name) { |
| 2684 Element helper = compiler.findHelper(name); | 2678 Element helper = compiler.findHelper(name); |
| 2685 if (helper == null) { | 2679 if (helper == null) { |
| 2686 // For mocked-up tests. | 2680 // For mocked-up tests. |
| 2687 return js.js('(void 0).$name'); | 2681 return js.js('(void 0).$name'); |
| 2688 } | 2682 } |
| 2689 world.registerStaticUse(helper); | 2683 world.registerStaticUse(helper); |
| 2690 return backend.namer.elementAccess(helper); | 2684 return backend.namer.elementAccess(helper); |
| 2691 } | 2685 } |
| 2692 } | 2686 } |
| OLD | NEW |