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 1797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1808 js.Expression newLiteralBool(bool value) { | 1808 js.Expression newLiteralBool(bool value) { |
1809 if (compiler.enableMinification) { | 1809 if (compiler.enableMinification) { |
1810 // Use !0 for true, !1 for false. | 1810 // Use !0 for true, !1 for false. |
1811 return new js.Prefix("!", new js.LiteralNumber(value ? "0" : "1")); | 1811 return new js.Prefix("!", new js.LiteralNumber(value ? "0" : "1")); |
1812 } else { | 1812 } else { |
1813 return new js.LiteralBool(value); | 1813 return new js.LiteralBool(value); |
1814 } | 1814 } |
1815 } | 1815 } |
1816 | 1816 |
1817 void generateConstant(Constant constant) { | 1817 void generateConstant(Constant constant) { |
1818 Namer namer = backend.namer; | 1818 if (constant.isFunction()) { |
1819 // TODO(floitsch): should we use the ConstantVisitor here? | 1819 FunctionConstant function = constant; |
1820 if (!constant.isObject()) { | 1820 world.registerStaticUse(function.element); |
1821 if (constant.isBool()) { | |
1822 BoolConstant boolConstant = constant; | |
1823 push(newLiteralBool(boolConstant.value)); | |
1824 } else if (constant.isNum()) { | |
1825 // TODO(floitsch): get rid of the code buffer. | |
1826 CodeBuffer buffer = new CodeBuffer(); | |
1827 backend.emitter.writeConstantToBuffer(constant, buffer); | |
1828 push(new js.LiteralNumber(buffer.toString())); | |
1829 } else if (constant.isNull()) { | |
1830 push(new js.LiteralNull()); | |
1831 } else if (constant.isString()) { | |
1832 // TODO(floitsch): get rid of the code buffer. | |
1833 CodeBuffer buffer = new CodeBuffer(); | |
1834 backend.emitter.writeConstantToBuffer(constant, buffer); | |
1835 push(new js.LiteralString(buffer.toString())); | |
1836 } else if (constant.isFunction()) { | |
1837 FunctionConstant function = constant; | |
1838 world.registerStaticUse(function.element); | |
1839 push(new js.VariableUse(namer.isolateAccess(function.element))); | |
1840 } else if (constant.isSentinel()) { | |
1841 // TODO(floitsch): get rid of the code buffer. | |
1842 CodeBuffer buffer = new CodeBuffer(); | |
1843 backend.emitter.writeConstantToBuffer(constant, buffer); | |
1844 push(new js.VariableUse(buffer.toString())); | |
1845 } else { | |
1846 compiler.internalError( | |
1847 "The compiler does not know how generate code for " | |
1848 "constant $constant"); | |
1849 } | |
1850 } else { | |
1851 String name = namer.constantName(constant); | |
1852 js.VariableUse currentIsolateUse = | |
1853 new js.VariableUse(backend.namer.CURRENT_ISOLATE); | |
1854 push(new js.PropertyAccess.field(currentIsolateUse, name)); | |
1855 } | 1821 } |
| 1822 push(backend.emitter.constantReference(constant)); |
1856 } | 1823 } |
1857 | 1824 |
1858 visitConstant(HConstant node) { | 1825 visitConstant(HConstant node) { |
1859 assert(isGenerateAtUseSite(node)); | 1826 assert(isGenerateAtUseSite(node)); |
1860 generateConstant(node.constant); | 1827 generateConstant(node.constant); |
1861 } | 1828 } |
1862 | 1829 |
1863 visitLoopBranch(HLoopBranch node) { | 1830 visitLoopBranch(HLoopBranch node) { |
1864 if (subGraph != null && identical(node.block, subGraph.end)) { | 1831 if (subGraph != null && identical(node.block, subGraph.end)) { |
1865 // We are generating code for a loop condition. | 1832 // We are generating code for a loop condition. |
(...skipping 1183 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 |