| 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 class SsaCodeGeneratorTask extends CompilerTask { | 5 class SsaCodeGeneratorTask extends CompilerTask { |
| 6 | 6 |
| 7 final JavaScriptBackend backend; | 7 final JavaScriptBackend backend; |
| 8 | 8 |
| 9 SsaCodeGeneratorTask(JavaScriptBackend backend) | 9 SsaCodeGeneratorTask(JavaScriptBackend backend) |
| 10 : this.backend = backend, | 10 : this.backend = backend, |
| (...skipping 2130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2141 } | 2141 } |
| 2142 | 2142 |
| 2143 void checkInt(HInstruction input, String cmp) { | 2143 void checkInt(HInstruction input, String cmp) { |
| 2144 use(input); | 2144 use(input); |
| 2145 js.Expression left = pop(); | 2145 js.Expression left = pop(); |
| 2146 use(input); | 2146 use(input); |
| 2147 js.Expression or0 = new js.Binary("|", pop(), new js.LiteralNumber("0")); | 2147 js.Expression or0 = new js.Binary("|", pop(), new js.LiteralNumber("0")); |
| 2148 push(new js.Binary(cmp, left, or0)); | 2148 push(new js.Binary(cmp, left, or0)); |
| 2149 } | 2149 } |
| 2150 | 2150 |
| 2151 void checkBigInt(HInstruction input, String cmp) { |
| 2152 use(input); |
| 2153 js.Expression left = pop(); |
| 2154 use(input); |
| 2155 js.Expression right = pop(); |
| 2156 // TODO(4984): Deal with infinity. |
| 2157 push(new js.LiteralExpression.withData('Math.floor(#) === #', |
| 2158 <js.Expression>[left, right])); |
| 2159 } |
| 2160 |
| 2151 void checkTypeOf(HInstruction input, String cmp, String typeName) { | 2161 void checkTypeOf(HInstruction input, String cmp, String typeName) { |
| 2152 use(input); | 2162 use(input); |
| 2153 js.Expression typeOf = new js.Prefix("typeof", pop()); | 2163 js.Expression typeOf = new js.Prefix("typeof", pop()); |
| 2154 push(new js.Binary(cmp, typeOf, new js.LiteralString("'$typeName'"))); | 2164 push(new js.Binary(cmp, typeOf, new js.LiteralString("'$typeName'"))); |
| 2155 } | 2165 } |
| 2156 | 2166 |
| 2157 void checkNum(HInstruction input, String cmp) | 2167 void checkNum(HInstruction input, String cmp) |
| 2158 => checkTypeOf(input, cmp, 'number'); | 2168 => checkTypeOf(input, cmp, 'number'); |
| 2159 | 2169 |
| 2160 void checkDouble(HInstruction input, String cmp) => checkNum(input, cmp); | 2170 void checkDouble(HInstruction input, String cmp) => checkNum(input, cmp); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2296 } else if (element == compiler.numClass) { | 2306 } else if (element == compiler.numClass) { |
| 2297 checkNum(input, '==='); | 2307 checkNum(input, '==='); |
| 2298 attachLocationToLast(node); | 2308 attachLocationToLast(node); |
| 2299 } else if (element == compiler.boolClass) { | 2309 } else if (element == compiler.boolClass) { |
| 2300 checkBool(input, '==='); | 2310 checkBool(input, '==='); |
| 2301 attachLocationToLast(node); | 2311 attachLocationToLast(node); |
| 2302 } else if (element == compiler.functionClass) { | 2312 } else if (element == compiler.functionClass) { |
| 2303 checkFunction(input, type); | 2313 checkFunction(input, type); |
| 2304 attachLocationToLast(node); | 2314 attachLocationToLast(node); |
| 2305 } else if (element == compiler.intClass) { | 2315 } else if (element == compiler.intClass) { |
| 2316 // The is check in the code tells us that it might not be an |
| 2317 // int. So we do a typeof first to avoid possible |
| 2318 // deoptimizations on the JS engine due to the Math.floor check. |
| 2306 checkNum(input, '==='); | 2319 checkNum(input, '==='); |
| 2307 js.Expression numTest = pop(); | 2320 js.Expression numTest = pop(); |
| 2308 checkInt(input, '==='); | 2321 checkBigInt(input, '==='); |
| 2309 push(new js.Binary('&&', numTest, pop()), node); | 2322 push(new js.Binary('&&', numTest, pop()), node); |
| 2310 } else if (Elements.isStringSupertype(element, compiler)) { | 2323 } else if (Elements.isStringSupertype(element, compiler)) { |
| 2311 handleStringSupertypeCheck(input, type); | 2324 handleStringSupertypeCheck(input, type); |
| 2312 attachLocationToLast(node); | 2325 attachLocationToLast(node); |
| 2313 } else if (element === compiler.listClass | 2326 } else if (element === compiler.listClass |
| 2314 || Elements.isListSupertype(element, compiler)) { | 2327 || Elements.isListSupertype(element, compiler)) { |
| 2315 handleListOrSupertypeCheck(input, type); | 2328 handleListOrSupertypeCheck(input, type); |
| 2316 attachLocationToLast(node); | 2329 attachLocationToLast(node); |
| 2317 } else if (types[input].canBePrimitive() || types[input].canBeNull()) { | 2330 } else if (types[input].canBePrimitive() || types[input].canBeNull()) { |
| 2318 checkObject(input, '==='); | 2331 checkObject(input, '==='); |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2933 if (leftType.canBeNull() && rightType.canBeNull()) { | 2946 if (leftType.canBeNull() && rightType.canBeNull()) { |
| 2934 if (left.isConstantNull() || right.isConstantNull() || | 2947 if (left.isConstantNull() || right.isConstantNull() || |
| 2935 (leftType.isPrimitive() && leftType == rightType)) { | 2948 (leftType.isPrimitive() && leftType == rightType)) { |
| 2936 return '=='; | 2949 return '=='; |
| 2937 } | 2950 } |
| 2938 return null; | 2951 return null; |
| 2939 } else { | 2952 } else { |
| 2940 return '==='; | 2953 return '==='; |
| 2941 } | 2954 } |
| 2942 } | 2955 } |
| OLD | NEW |