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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 CodeBuffer generateMethod(WorkItem work, HGraph graph) { | 66 CodeBuffer generateMethod(WorkItem work, HGraph graph) { |
67 return measure(() { | 67 return measure(() { |
68 compiler.tracer.traceGraph("codegen", graph); | 68 compiler.tracer.traceGraph("codegen", graph); |
69 SsaOptimizedCodeGenerator codegen = | 69 SsaOptimizedCodeGenerator codegen = |
70 new SsaOptimizedCodeGenerator(backend, work); | 70 new SsaOptimizedCodeGenerator(backend, work); |
71 codegen.visitGraph(graph); | 71 codegen.visitGraph(graph); |
72 | 72 |
73 FunctionElement element = work.element; | 73 FunctionElement element = work.element; |
74 js.Block body; | 74 js.Block body; |
75 ClassElement enclosingClass = element.getEnclosingClass(); | 75 ClassElement enclosingClass = element.getEnclosingClass(); |
76 bool allowVariableMinification; | 76 bool allowVariableMinification = !codegen.visitedForeignCode; |
| 77 |
77 if (element.isInstanceMember() | 78 if (element.isInstanceMember() |
78 && enclosingClass.isNative() | 79 && enclosingClass.isNative() |
79 && native.isOverriddenMethod( | 80 && native.isOverriddenMethod( |
80 element, enclosingClass, nativeEmitter)) { | 81 element, enclosingClass, nativeEmitter)) { |
81 // Record that this method is overridden. In case of optional | 82 // Record that this method is overridden. In case of optional |
82 // arguments, the emitter will generate stubs to handle them, | 83 // arguments, the emitter will generate stubs to handle them, |
83 // and needs to know if the method is overridden. | 84 // and needs to know if the method is overridden. |
84 nativeEmitter.overriddenMethods.add(element); | 85 nativeEmitter.overriddenMethods.add(element); |
85 StringBuffer buffer = new StringBuffer(); | 86 StringBuffer buffer = new StringBuffer(); |
86 String codeString = prettyPrint(codegen.body).toString(); | 87 body = |
87 String parametersString = | 88 nativeEmitter.generateMethodBodyWithPrototypeCheckForElement( |
88 Strings.join(codegen.parameterNames.values, ", "); | 89 element, codegen.body, codegen.parameters); |
89 native.generateMethodWithPrototypeCheckForElement( | |
90 compiler, buffer, element, codeString, parametersString); | |
91 js.Node nativeCode = new js.LiteralStatement(buffer.toString()); | |
92 body = new js.Block(<js.Statement>[nativeCode]); | |
93 allowVariableMinification = false; | |
94 } else { | 90 } else { |
95 body = codegen.body; | 91 body = codegen.body; |
96 allowVariableMinification = !codegen.visitedForeignCode; | |
97 } | 92 } |
| 93 |
98 js.Fun fun = buildJavaScriptFunction(element, codegen.parameters, body); | 94 js.Fun fun = buildJavaScriptFunction(element, codegen.parameters, body); |
99 return prettyPrint(fun, | 95 return prettyPrint(fun, |
100 allowVariableMinification: allowVariableMinification); | 96 allowVariableMinification: allowVariableMinification); |
101 }); | 97 }); |
102 } | 98 } |
103 | 99 |
104 CodeBuffer generateBailoutMethod(WorkItem work, HGraph graph) { | 100 CodeBuffer generateBailoutMethod(WorkItem work, HGraph graph) { |
105 return measure(() { | 101 return measure(() { |
106 compiler.tracer.traceGraph("codegen-bailout", graph); | 102 compiler.tracer.traceGraph("codegen-bailout", graph); |
107 | 103 |
(...skipping 2926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3034 if (leftType.canBeNull() && rightType.canBeNull()) { | 3030 if (leftType.canBeNull() && rightType.canBeNull()) { |
3035 if (left.isConstantNull() || right.isConstantNull() || | 3031 if (left.isConstantNull() || right.isConstantNull() || |
3036 (leftType.isPrimitive() && leftType == rightType)) { | 3032 (leftType.isPrimitive() && leftType == rightType)) { |
3037 return '=='; | 3033 return '=='; |
3038 } | 3034 } |
3039 return null; | 3035 return null; |
3040 } else { | 3036 } else { |
3041 return '==='; | 3037 return '==='; |
3042 } | 3038 } |
3043 } | 3039 } |
OLD | NEW |