Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: lib/compiler/implementation/ssa/codegen.dart

Issue 10823389: Start inferring return types for static functions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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';
11 NativeEmitter get nativeEmitter() => backend.emitter.nativeEmitter; 11 NativeEmitter get nativeEmitter() => backend.emitter.nativeEmitter;
12 12
13 13
14 js.Fun buildJavaScriptFunction(FunctionElement element, 14 js.Fun buildJavaScriptFunction(FunctionElement element,
15 List<js.Parameter> parameters, 15 List<js.Parameter> parameters,
16 js.Block body) { 16 js.Block body) {
17 FunctionExpression expression = element.cachedNode; 17 FunctionExpression expression = element.cachedNode;
18 js.Fun result = new js.Fun(parameters, body); 18 js.Fun result = new js.Fun(parameters, body);
19 result.sourcePosition = expression.getBeginToken(); 19 result.sourcePosition = expression.getBeginToken();
20 result.endSourcePosition = expression.getEndToken(); 20 result.endSourcePosition = expression.getEndToken();
21 return result; 21 return result;
22 } 22 }
23 23
24 CodeBuffer prettyPrint(js.Node node, Element positionElement) { 24 CodeBuffer prettyPrint(js.Node node, Element positionElement) {
25 return js.prettyPrint(node, compiler, positionElement); 25 return js.prettyPrint(node, compiler, positionElement);
26 } 26 }
27 27
28 CodeBuffer generateMethod(WorkItem work, HGraph graph) { 28 CodeBuffer generateMethod(WorkItem work, HGraph graph) {
29 return measure(() { 29 return measure(() {
30 HTypeMap types = work.compilationContext.types;
31 graph.exit.predecessors.forEach((block) {
32 assert(block.last is HGoto || block.last is HReturn);
33 if (block.last is HReturn) {
ngeoffray 2012/08/17 10:02:51 How about a function with multiple return?
Søren Gjesse 2012/08/17 10:08:54 This should be handled by the graph.exit.predeces
ngeoffray 2012/08/17 10:13:29 Hmm, a HReturn block has the HExit block as a succ
Søren Gjesse 2012/08/17 10:21:04 I checked the (3) places where HReturn nodes are c
34 backend.registerReturnType(work.element, types[block.last.inputs[0]]);
35 } else {
36 backend.registerReturnType(work.element, HType.NULL);
37 }
38 });
30 compiler.tracer.traceGraph("codegen", graph); 39 compiler.tracer.traceGraph("codegen", graph);
31 Map<Element, String> parameterNames = getParameterNames(work); 40 Map<Element, String> parameterNames = getParameterNames(work);
32 parameterNames.forEach((element, name) { 41 parameterNames.forEach((element, name) {
33 compiler.enqueuer.codegen.addToWorkList(element); 42 compiler.enqueuer.codegen.addToWorkList(element);
34 }); 43 });
35 List<js.Parameter> parameters = <js.Parameter>[]; 44 List<js.Parameter> parameters = <js.Parameter>[];
36 parameterNames.forEach((element, name) { 45 parameterNames.forEach((element, name) {
37 parameters.add(new js.Parameter(name)); 46 parameters.add(new js.Parameter(name));
38 }); 47 });
39 String parametersString = Strings.join(parameterNames.getValues(), ", "); 48 String parametersString = Strings.join(parameterNames.getValues(), ", ");
(...skipping 2861 matching lines...) Expand 10 before | Expand all | Expand 10 after
2901 if (leftType.canBeNull() && rightType.canBeNull()) { 2910 if (leftType.canBeNull() && rightType.canBeNull()) {
2902 if (left.isConstantNull() || right.isConstantNull() || 2911 if (left.isConstantNull() || right.isConstantNull() ||
2903 (leftType.isPrimitive() && leftType == rightType)) { 2912 (leftType.isPrimitive() && leftType == rightType)) {
2904 return '=='; 2913 return '==';
2905 } 2914 }
2906 return null; 2915 return null;
2907 } else { 2916 } else {
2908 return '==='; 2917 return '===';
2909 } 2918 }
2910 } 2919 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698