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 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 void emitIdentityComparison(HIdentity instruction, bool inverse) { | 1254 void emitIdentityComparison(HIdentity instruction, bool inverse) { |
1255 String op = instruction.singleComparisonOp; | 1255 String op = instruction.singleComparisonOp; |
1256 HInstruction left = instruction.left; | 1256 HInstruction left = instruction.left; |
1257 HInstruction right = instruction.right; | 1257 HInstruction right = instruction.right; |
1258 if (op != null) { | 1258 if (op != null) { |
1259 use(left); | 1259 use(left); |
1260 js.Expression jsLeft = pop(); | 1260 js.Expression jsLeft = pop(); |
1261 use(right); | 1261 use(right); |
1262 push(new js.Binary(mapRelationalOperator(op, inverse), jsLeft, pop())); | 1262 push(new js.Binary(mapRelationalOperator(op, inverse), jsLeft, pop())); |
1263 } else { | 1263 } else { |
1264 assert(NullConstant.JsNull == 'null'); | 1264 assert(NullConstantValue.JsNull == 'null'); |
1265 use(left); | 1265 use(left); |
1266 js.Binary leftEqualsNull = | 1266 js.Binary leftEqualsNull = |
1267 new js.Binary("==", pop(), new js.LiteralNull()); | 1267 new js.Binary("==", pop(), new js.LiteralNull()); |
1268 use(right); | 1268 use(right); |
1269 js.Binary rightEqualsNull = | 1269 js.Binary rightEqualsNull = |
1270 new js.Binary(mapRelationalOperator("==", inverse), | 1270 new js.Binary(mapRelationalOperator("==", inverse), |
1271 pop(), new js.LiteralNull()); | 1271 pop(), new js.LiteralNull()); |
1272 use(right); | 1272 use(right); |
1273 use(left); | 1273 use(left); |
1274 js.Binary tripleEq = new js.Binary(mapRelationalOperator("===", inverse), | 1274 js.Binary tripleEq = new js.Binary(mapRelationalOperator("===", inverse), |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1796 | 1796 |
1797 js.Expression newLiteralBool(bool value) { | 1797 js.Expression newLiteralBool(bool value) { |
1798 if (compiler.enableMinification) { | 1798 if (compiler.enableMinification) { |
1799 // Use !0 for true, !1 for false. | 1799 // Use !0 for true, !1 for false. |
1800 return new js.Prefix("!", new js.LiteralNumber(value ? "0" : "1")); | 1800 return new js.Prefix("!", new js.LiteralNumber(value ? "0" : "1")); |
1801 } else { | 1801 } else { |
1802 return new js.LiteralBool(value); | 1802 return new js.LiteralBool(value); |
1803 } | 1803 } |
1804 } | 1804 } |
1805 | 1805 |
1806 void generateConstant(Constant constant) { | 1806 void generateConstant(ConstantValue constant) { |
1807 if (constant.isFunction) { | 1807 if (constant.isFunction) { |
1808 FunctionConstant function = constant; | 1808 FunctionConstantValue function = constant; |
1809 registry.registerStaticUse(function.element); | 1809 registry.registerStaticUse(function.element); |
1810 } | 1810 } |
1811 if (constant.isType) { | 1811 if (constant.isType) { |
1812 // If the type is a web component, we need to ensure the constructors are | 1812 // If the type is a web component, we need to ensure the constructors are |
1813 // available to 'upgrade' the native object. | 1813 // available to 'upgrade' the native object. |
1814 TypeConstant type = constant; | 1814 TypeConstantValue type = constant; |
1815 Element element = type.representedType.element; | 1815 Element element = type.representedType.element; |
1816 if (element != null && element.isClass) { | 1816 if (element != null && element.isClass) { |
1817 registry.registerTypeConstant(element); | 1817 registry.registerTypeConstant(element); |
1818 } | 1818 } |
1819 } | 1819 } |
1820 push(backend.emitter.constantReference(constant)); | 1820 push(backend.emitter.constantReference(constant)); |
1821 } | 1821 } |
1822 | 1822 |
1823 visitConstant(HConstant node) { | 1823 visitConstant(HConstant node) { |
1824 assert(isGenerateAtUseSite(node)); | 1824 assert(isGenerateAtUseSite(node)); |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2181 | 2181 |
2182 void checkDouble(HInstruction input, String cmp) => checkNum(input, cmp); | 2182 void checkDouble(HInstruction input, String cmp) => checkNum(input, cmp); |
2183 | 2183 |
2184 void checkString(HInstruction input, String cmp) | 2184 void checkString(HInstruction input, String cmp) |
2185 => checkTypeOf(input, cmp, 'string'); | 2185 => checkTypeOf(input, cmp, 'string'); |
2186 | 2186 |
2187 void checkBool(HInstruction input, String cmp) | 2187 void checkBool(HInstruction input, String cmp) |
2188 => checkTypeOf(input, cmp, 'boolean'); | 2188 => checkTypeOf(input, cmp, 'boolean'); |
2189 | 2189 |
2190 void checkObject(HInstruction input, String cmp) { | 2190 void checkObject(HInstruction input, String cmp) { |
2191 assert(NullConstant.JsNull == 'null'); | 2191 assert(NullConstantValue.JsNull == 'null'); |
2192 if (cmp == "===") { | 2192 if (cmp == "===") { |
2193 checkTypeOf(input, '===', 'object'); | 2193 checkTypeOf(input, '===', 'object'); |
2194 js.Expression left = pop(); | 2194 js.Expression left = pop(); |
2195 use(input); | 2195 use(input); |
2196 js.Expression notNull = new js.Binary("!==", pop(), new js.LiteralNull()); | 2196 js.Expression notNull = new js.Binary("!==", pop(), new js.LiteralNull()); |
2197 push(new js.Binary("&&", left, notNull)); | 2197 push(new js.Binary("&&", left, notNull)); |
2198 } else { | 2198 } else { |
2199 assert(cmp == "!=="); | 2199 assert(cmp == "!=="); |
2200 checkTypeOf(input, '!==', 'object'); | 2200 checkTypeOf(input, '!==', 'object'); |
2201 js.Expression left = pop(); | 2201 js.Expression left = pop(); |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2713 js.PropertyAccess accessHelper(String name) { | 2713 js.PropertyAccess accessHelper(String name) { |
2714 Element helper = backend.findHelper(name); | 2714 Element helper = backend.findHelper(name); |
2715 if (helper == null) { | 2715 if (helper == null) { |
2716 // For mocked-up tests. | 2716 // For mocked-up tests. |
2717 return js.js('(void 0).$name'); | 2717 return js.js('(void 0).$name'); |
2718 } | 2718 } |
2719 registry.registerStaticUse(helper); | 2719 registry.registerStaticUse(helper); |
2720 return backend.namer.elementAccess(helper); | 2720 return backend.namer.elementAccess(helper); |
2721 } | 2721 } |
2722 } | 2722 } |
OLD | NEW |