| 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 final JavaScriptBackend backend; | 6 final JavaScriptBackend backend; |
| 7 SsaCodeGeneratorTask(JavaScriptBackend backend) | 7 SsaCodeGeneratorTask(JavaScriptBackend backend) |
| 8 : this.backend = backend, | 8 : this.backend = backend, |
| 9 super(backend.compiler); | 9 super(backend.compiler); |
| 10 String get name => 'SSA code generator'; | 10 String get name => 'SSA code generator'; |
| (...skipping 2010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2021 node); | 2021 node); |
| 2022 } else { | 2022 } else { |
| 2023 visitInvokeStatic(node); | 2023 visitInvokeStatic(node); |
| 2024 } | 2024 } |
| 2025 } | 2025 } |
| 2026 | 2026 |
| 2027 String builtinJsName(HInvokeInterceptor interceptor) { | 2027 String builtinJsName(HInvokeInterceptor interceptor) { |
| 2028 // Don't count the target method or the receiver in the arity. | 2028 // Don't count the target method or the receiver in the arity. |
| 2029 int arity = interceptor.inputs.length - 2; | 2029 int arity = interceptor.inputs.length - 2; |
| 2030 HInstruction receiver = interceptor.inputs[1]; | 2030 HInstruction receiver = interceptor.inputs[1]; |
| 2031 bool getter = interceptor.getter; | 2031 bool isCall = interceptor.selector.isCall(); |
| 2032 SourceString name = interceptor.name; | 2032 SourceString name = interceptor.selector.name; |
| 2033 | 2033 |
| 2034 if (interceptor.isLengthGetterOnStringOrArray(types)) { | 2034 if (interceptor.isLengthGetterOnStringOrArray(types)) { |
| 2035 return 'length'; | 2035 return 'length'; |
| 2036 } else if (receiver.isExtendableArray(types) && !getter) { | 2036 } else if (receiver.isExtendableArray(types) && isCall) { |
| 2037 if (name == const SourceString('add') && arity == 1) { | 2037 if (name == const SourceString('add') && arity == 1) { |
| 2038 return 'push'; | 2038 return 'push'; |
| 2039 } | 2039 } |
| 2040 if (name == const SourceString('removeLast') && arity == 0) { | 2040 if (name == const SourceString('removeLast') && arity == 0) { |
| 2041 return 'pop'; | 2041 return 'pop'; |
| 2042 } | 2042 } |
| 2043 } else if (receiver.isString(types) && !getter) { | 2043 } else if (receiver.isString(types) && isCall) { |
| 2044 if (name == const SourceString('concat') && | 2044 if (name == const SourceString('concat') && |
| 2045 arity == 1 && | 2045 arity == 1 && |
| 2046 interceptor.inputs[2].isString(types)) { | 2046 interceptor.inputs[2].isString(types)) { |
| 2047 return '+'; | 2047 return '+'; |
| 2048 } | 2048 } |
| 2049 } | 2049 } |
| 2050 | 2050 |
| 2051 return null; | 2051 return null; |
| 2052 } | 2052 } |
| 2053 | 2053 |
| 2054 void visitInvokeInterceptor(HInvokeInterceptor node) { | 2054 void visitInvokeInterceptor(HInvokeInterceptor node) { |
| 2055 String builtin = builtinJsName(node); | 2055 String builtin = builtinJsName(node); |
| 2056 if (builtin !== null) { | 2056 if (builtin !== null) { |
| 2057 if (builtin == '+') { | 2057 if (builtin == '+') { |
| 2058 use(node.inputs[1]); | 2058 use(node.inputs[1]); |
| 2059 js.Expression left = pop(); | 2059 js.Expression left = pop(); |
| 2060 use(node.inputs[2]); | 2060 use(node.inputs[2]); |
| 2061 push(new js.Binary("+", left, pop()), node); | 2061 push(new js.Binary("+", left, pop()), node); |
| 2062 } else { | 2062 } else { |
| 2063 use(node.inputs[1]); | 2063 use(node.inputs[1]); |
| 2064 js.PropertyAccess access = new js.PropertyAccess.field(pop(), builtin); | 2064 js.PropertyAccess access = new js.PropertyAccess.field(pop(), builtin); |
| 2065 if (node.getter) { | 2065 if (node.selector.isGetter()) { |
| 2066 push(access, node); | 2066 push(access, node); |
| 2067 return; | 2067 return; |
| 2068 } | 2068 } |
| 2069 List<js.Expression> arguments = <js.Expression>[]; | 2069 List<js.Expression> arguments = <js.Expression>[]; |
| 2070 for (int i = 2; i < node.inputs.length; i++) { | 2070 for (int i = 2; i < node.inputs.length; i++) { |
| 2071 use(node.inputs[i]); | 2071 use(node.inputs[i]); |
| 2072 arguments.add(pop()); | 2072 arguments.add(pop()); |
| 2073 } | 2073 } |
| 2074 push(new js.Call(access, arguments), node); | 2074 push(new js.Call(access, arguments), node); |
| 2075 } | 2075 } |
| (...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2907 if (leftType.canBeNull() && rightType.canBeNull()) { | 2907 if (leftType.canBeNull() && rightType.canBeNull()) { |
| 2908 if (left.isConstantNull() || right.isConstantNull() || | 2908 if (left.isConstantNull() || right.isConstantNull() || |
| 2909 (leftType.isPrimitive() && leftType == rightType)) { | 2909 (leftType.isPrimitive() && leftType == rightType)) { |
| 2910 return '=='; | 2910 return '=='; |
| 2911 } | 2911 } |
| 2912 return null; | 2912 return null; |
| 2913 } else { | 2913 } else { |
| 2914 return '==='; | 2914 return '==='; |
| 2915 } | 2915 } |
| 2916 } | 2916 } |
| OLD | NEW |