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 |
11 SsaCodeGeneratorTask(JavaScriptBackend backend) | 11 SsaCodeGeneratorTask(JavaScriptBackend backend) |
12 : this.backend = backend, | 12 : this.backend = backend, |
13 super(backend.compiler); | 13 super(backend.compiler); |
14 String get name => 'SSA code generator'; | 14 String get name => 'SSA code generator'; |
15 NativeEmitter get nativeEmitter => backend.emitter.nativeEmitter; | 15 NativeEmitter get nativeEmitter => backend.emitter.nativeEmitter; |
16 | 16 |
17 | 17 |
18 js.Fun buildJavaScriptFunction(FunctionElement element, | 18 js.Fun buildJavaScriptFunction(FunctionElement element, |
19 List<js.Parameter> parameters, | 19 List<js.Parameter> parameters, |
20 js.Block body) { | 20 js.Block body) { |
21 FunctionExpression expression = | |
22 element.implementation.parseNode(backend.compiler); | |
23 js.Fun result = new js.Fun(parameters, body); | 21 js.Fun result = new js.Fun(parameters, body); |
24 // TODO(johnniwinther): remove the 'element.patch' hack. | 22 // TODO(johnniwinther): remove the 'element.patch' hack. |
25 Element sourceElement = element.patch == null ? element : element.patch; | 23 Element sourceElement = element.patch == null ? element : element.patch; |
26 SourceFile sourceFile = sourceElement.getCompilationUnit().script.file; | 24 SourceFile sourceFile = sourceElement.getCompilationUnit().script.file; |
| 25 Node expression = |
| 26 element.implementation.parseNode(backend.compiler); |
| 27 Token beginToken; |
| 28 Token endToken; |
| 29 if (expression == null) { |
| 30 // Synthesized node. Use the enclosing element for the location. |
| 31 beginToken = endToken = element.position(); |
| 32 } else { |
| 33 beginToken = expression.getBeginToken(); |
| 34 endToken = expression.getEndToken(); |
| 35 } |
27 // TODO(podivilov): find the right sourceFile here and remove offset checks | 36 // TODO(podivilov): find the right sourceFile here and remove offset checks |
28 // below. | 37 // below. |
29 if (expression.getBeginToken().charOffset < sourceFile.text.length) { | 38 if (beginToken.charOffset < sourceFile.text.length) { |
30 result.sourcePosition = new SourceFileLocation( | 39 result.sourcePosition = new SourceFileLocation(sourceFile, beginToken); |
31 sourceFile, expression.getBeginToken()); | |
32 } | 40 } |
33 if (expression.getEndToken().charOffset < sourceFile.text.length) { | 41 if (endToken.charOffset < sourceFile.text.length) { |
34 result.endSourcePosition = new SourceFileLocation( | 42 result.endSourcePosition = new SourceFileLocation(sourceFile, endToken); |
35 sourceFile, expression.getEndToken()); | |
36 } | 43 } |
37 return result; | 44 return result; |
38 } | 45 } |
39 | 46 |
40 CodeBuffer prettyPrint(js.Node node) { | 47 CodeBuffer prettyPrint(js.Node node) { |
41 var code = js.prettyPrint(node, compiler, allowVariableMinification: true); | 48 var code = js.prettyPrint(node, compiler, allowVariableMinification: true); |
42 return code; | 49 return code; |
43 } | 50 } |
44 | 51 |
45 js.Expression generateCode(CodegenWorkItem work, HGraph graph) { | 52 js.Expression generateCode(CodegenWorkItem work, HGraph graph) { |
(...skipping 2930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2976 if (leftType.canBeNull() && rightType.canBeNull()) { | 2983 if (leftType.canBeNull() && rightType.canBeNull()) { |
2977 if (left.isConstantNull() || right.isConstantNull() || | 2984 if (left.isConstantNull() || right.isConstantNull() || |
2978 (leftType.isPrimitive(compiler) && leftType == rightType)) { | 2985 (leftType.isPrimitive(compiler) && leftType == rightType)) { |
2979 return '=='; | 2986 return '=='; |
2980 } | 2987 } |
2981 return null; | 2988 return null; |
2982 } else { | 2989 } else { |
2983 return '==='; | 2990 return '==='; |
2984 } | 2991 } |
2985 } | 2992 } |
OLD | NEW |