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

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

Issue 10917285: Stub implementation of patch invariants for the patch refactoring. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments Created 8 years, 3 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 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,
11 super(backend.compiler); 11 super(backend.compiler);
12 String get name => 'SSA code generator'; 12 String get name => 'SSA code generator';
13 NativeEmitter get nativeEmitter => backend.emitter.nativeEmitter; 13 NativeEmitter get nativeEmitter => backend.emitter.nativeEmitter;
14 14
15 15
16 js.Fun buildJavaScriptFunction(FunctionElement element, 16 js.Fun buildJavaScriptFunction(FunctionElement element,
17 List<js.Parameter> parameters, 17 List<js.Parameter> parameters,
18 js.Block body) { 18 js.Block body) {
19 FunctionExpression expression = element.cachedNode; 19 FunctionExpression expression =
20 element.implementation.parseNode(backend.compiler);
20 js.Fun result = new js.Fun(parameters, body); 21 js.Fun result = new js.Fun(parameters, body);
21 // TODO(johnniwinther): remove the 'element.patch' hack. 22 // TODO(johnniwinther): remove the 'element.patch' hack.
22 Element sourceElement = element.patch == null ? element : element.patch; 23 Element sourceElement = element.patch == null ? element : element.patch;
23 SourceFile sourceFile = sourceElement.getCompilationUnit().script.file; 24 SourceFile sourceFile = sourceElement.getCompilationUnit().script.file;
24 // TODO(podivilov): find the right sourceFile here and remove offset checks 25 // TODO(podivilov): find the right sourceFile here and remove offset checks
25 // below. 26 // below.
26 if (expression.getBeginToken().charOffset < sourceFile.text.length) { 27 if (expression.getBeginToken().charOffset < sourceFile.text.length) {
27 result.sourcePosition = new SourceFileLocation( 28 result.sourcePosition = new SourceFileLocation(
28 sourceFile, expression.getBeginToken()); 29 sourceFile, expression.getBeginToken());
29 } 30 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 graph.exit.predecessors.forEach((block) { 67 graph.exit.predecessors.forEach((block) {
67 assert(block.last is HGoto || block.last is HReturn); 68 assert(block.last is HGoto || block.last is HReturn);
68 if (block.last is HReturn) { 69 if (block.last is HReturn) {
69 backend.registerReturnType(work.element, types[block.last.inputs[0]]); 70 backend.registerReturnType(work.element, types[block.last.inputs[0]]);
70 } else { 71 } else {
71 backend.registerReturnType(work.element, HType.NULL); 72 backend.registerReturnType(work.element, HType.NULL);
72 } 73 }
73 }); 74 });
74 compiler.tracer.traceGraph("codegen", graph); 75 compiler.tracer.traceGraph("codegen", graph);
75 Map<Element, String> parameterNames = getParameterNames(work); 76 Map<Element, String> parameterNames = getParameterNames(work);
76 parameterNames.forEach((element, name) { 77 // Use [work.element] to ensure that the parameter element come from
78 // the declaration.
79 work.element.computeSignature(compiler).forEachParameter((element) {
77 compiler.enqueuer.codegen.addToWorkList(element); 80 compiler.enqueuer.codegen.addToWorkList(element);
78 }); 81 });
79 List<js.Parameter> parameters = <js.Parameter>[]; 82 List<js.Parameter> parameters = <js.Parameter>[];
80 parameterNames.forEach((element, name) { 83 parameterNames.forEach((element, name) {
81 parameters.add(new js.Parameter(name)); 84 parameters.add(new js.Parameter(name));
82 }); 85 });
83 addTypeParameters(work.element, parameters, parameterNames); 86 addTypeParameters(work.element, parameters, parameterNames);
84 String parametersString = Strings.join(parameterNames.getValues(), ", "); 87 String parametersString = Strings.join(parameterNames.getValues(), ", ");
85 SsaOptimizedCodeGenerator codegen = new SsaOptimizedCodeGenerator( 88 SsaOptimizedCodeGenerator codegen = new SsaOptimizedCodeGenerator(
86 backend, work, parameters, parameterNames); 89 backend, work, parameters, parameterNames);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 if (codegen.setup != null) body.statements.add(codegen.setup); 152 if (codegen.setup != null) body.statements.add(codegen.setup);
150 body.statements.add(codegen.body); 153 body.statements.add(codegen.body);
151 js.Fun fun = 154 js.Fun fun =
152 buildJavaScriptFunction(work.element, codegen.newParameters, body); 155 buildJavaScriptFunction(work.element, codegen.newParameters, body);
153 return prettyPrint(fun); 156 return prettyPrint(fun);
154 }); 157 });
155 } 158 }
156 159
157 Map<Element, String> getParameterNames(WorkItem work) { 160 Map<Element, String> getParameterNames(WorkItem work) {
158 Map<Element, String> parameterNames = new LinkedHashMap<Element, String>(); 161 Map<Element, String> parameterNames = new LinkedHashMap<Element, String>();
159 FunctionElement function = work.element; 162 FunctionElement function = work.element.implementation;
160 163
161 // The dom/html libraries have inline JS code that reference 164 // The dom/html libraries have inline JS code that reference
162 // parameter names directly. Long-term such code will be rejected. 165 // parameter names directly. Long-term such code will be rejected.
163 // Now, just don't mangle the parameter name. 166 // Now, just don't mangle the parameter name.
164 function.computeSignature(compiler).forEachParameter((Element element) { 167 function.computeSignature(compiler).forEachParameter((Element element) {
165 parameterNames[element] = function.isNative() 168 parameterNames[element] = function.isNative()
166 ? element.name.slowToString() 169 ? element.name.slowToString()
167 : JsNames.getValid('${element.name.slowToString()}'); 170 : JsNames.getValid('${element.name.slowToString()}');
168 }); 171 });
169 return parameterNames; 172 return parameterNames;
(...skipping 2819 matching lines...) Expand 10 before | Expand all | Expand 10 after
2989 if (leftType.canBeNull() && rightType.canBeNull()) { 2992 if (leftType.canBeNull() && rightType.canBeNull()) {
2990 if (left.isConstantNull() || right.isConstantNull() || 2993 if (left.isConstantNull() || right.isConstantNull() ||
2991 (leftType.isPrimitive() && leftType == rightType)) { 2994 (leftType.isPrimitive() && leftType == rightType)) {
2992 return '=='; 2995 return '==';
2993 } 2996 }
2994 return null; 2997 return null;
2995 } else { 2998 } else {
2996 return '==='; 2999 return '===';
2997 } 3000 }
2998 } 3001 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/ssa/builder.dart ('k') | lib/compiler/implementation/ssa/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698