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 1794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1805 js.Expression newLiteralBool(bool value) { | 1805 js.Expression newLiteralBool(bool value) { |
1806 if (compiler.enableMinification) { | 1806 if (compiler.enableMinification) { |
1807 // Use !0 for true, !1 for false. | 1807 // Use !0 for true, !1 for false. |
1808 return new js.Prefix("!", new js.LiteralNumber(value ? "0" : "1")); | 1808 return new js.Prefix("!", new js.LiteralNumber(value ? "0" : "1")); |
1809 } else { | 1809 } else { |
1810 return new js.LiteralBool(value); | 1810 return new js.LiteralBool(value); |
1811 } | 1811 } |
1812 } | 1812 } |
1813 | 1813 |
1814 void generateConstant(Constant constant) { | 1814 void generateConstant(Constant constant) { |
1815 Namer namer = backend.namer; | 1815 if (constant.isFunction()) { |
1816 // TODO(floitsch): should we use the ConstantVisitor here? | 1816 FunctionConstant function = constant; |
1817 if (!constant.isObject()) { | 1817 world.registerStaticUse(function.element); |
1818 if (constant.isBool()) { | |
1819 BoolConstant boolConstant = constant; | |
1820 push(newLiteralBool(boolConstant.value)); | |
1821 } else if (constant.isNum()) { | |
1822 // TODO(floitsch): get rid of the code buffer. | |
1823 CodeBuffer buffer = new CodeBuffer(); | |
1824 backend.emitter.writeConstantToBuffer(constant, buffer); | |
1825 push(new js.LiteralNumber(buffer.toString())); | |
1826 } else if (constant.isNull()) { | |
1827 push(new js.LiteralNull()); | |
1828 } else if (constant.isString()) { | |
1829 // TODO(floitsch): get rid of the code buffer. | |
1830 CodeBuffer buffer = new CodeBuffer(); | |
1831 backend.emitter.writeConstantToBuffer(constant, buffer); | |
1832 push(new js.LiteralString(buffer.toString())); | |
1833 } else if (constant.isFunction()) { | |
1834 FunctionConstant function = constant; | |
1835 world.registerStaticUse(function.element); | |
1836 push(new js.VariableUse(namer.isolateAccess(function.element))); | |
1837 } else if (constant.isSentinel()) { | |
1838 // TODO(floitsch): get rid of the code buffer. | |
1839 CodeBuffer buffer = new CodeBuffer(); | |
1840 backend.emitter.writeConstantToBuffer(constant, buffer); | |
1841 push(new js.VariableUse(buffer.toString())); | |
1842 } else { | |
1843 compiler.internalError( | |
1844 "The compiler does not know how generate code for " | |
1845 "constant $constant"); | |
1846 } | |
1847 } else { | |
1848 String name = namer.constantName(constant); | |
1849 js.VariableUse currentIsolateUse = | |
1850 new js.VariableUse(backend.namer.CURRENT_ISOLATE); | |
1851 push(new js.PropertyAccess.field(currentIsolateUse, name)); | |
1852 } | 1818 } |
| 1819 push(backend.emitter.constantReference(constant)); |
1853 } | 1820 } |
1854 | 1821 |
1855 visitConstant(HConstant node) { | 1822 visitConstant(HConstant node) { |
1856 assert(isGenerateAtUseSite(node)); | 1823 assert(isGenerateAtUseSite(node)); |
1857 generateConstant(node.constant); | 1824 generateConstant(node.constant); |
1858 DartType type = node.constant.computeType(compiler); | 1825 DartType type = node.constant.computeType(compiler); |
1859 world.registerInstantiatedClass(type.element); | 1826 world.registerInstantiatedClass(type.element); |
1860 } | 1827 } |
1861 | 1828 |
1862 visitLoopBranch(HLoopBranch node) { | 1829 visitLoopBranch(HLoopBranch node) { |
(...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3049 if (leftType.canBeNull() && rightType.canBeNull()) { | 3016 if (leftType.canBeNull() && rightType.canBeNull()) { |
3050 if (left.isConstantNull() || right.isConstantNull() || | 3017 if (left.isConstantNull() || right.isConstantNull() || |
3051 (leftType.isPrimitive() && leftType == rightType)) { | 3018 (leftType.isPrimitive() && leftType == rightType)) { |
3052 return '=='; | 3019 return '=='; |
3053 } | 3020 } |
3054 return null; | 3021 return null; |
3055 } else { | 3022 } else { |
3056 return '==='; | 3023 return '==='; |
3057 } | 3024 } |
3058 } | 3025 } |
OLD | NEW |