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

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

Issue 10668029: Associate partial source map with each code block in Universe.generatedCode. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 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 String buildJavaScriptFunction(FunctionElement element, 14 CodeBlock buildJavaScriptFunction(FunctionElement element,
15 String parameters, 15 String parameters,
16 String body) { 16 String body) {
17 String extraSpace = ""; 17 String extraSpace = "";
18 // Members are emitted inside a JavaScript object literal. To line up the 18 // Members are emitted inside a JavaScript object literal. To line up the
19 // indentation we want the closing curly brace to be indented by one space. 19 // indentation we want the closing curly brace to be indented by one space.
20 // Example: 20 // Example:
21 // defineClass("A", "B", ... , { 21 // defineClass("A", "B", ... , {
22 // foo$1: function(..) { 22 // foo$1: function(..) {
23 // }, /* <========== indent by 1. */ 23 // }, /* <========== indent by 1. */
24 // bar$2: function(..) { 24 // bar$2: function(..) {
25 // }, /* <========== indent by 1. */ 25 // }, /* <========== indent by 1. */
26 // 26 //
27 // For static functions this is not necessary: 27 // For static functions this is not necessary:
28 // $.staticFun = function() { 28 // $.staticFun = function() {
29 // ... 29 // ...
30 // }; 30 // };
31 if (element.isInstanceMember() || 31 if (element.isInstanceMember() ||
32 element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { 32 element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) {
33 extraSpace = " "; 33 extraSpace = " ";
34 } 34 }
35 return 'function($parameters) {\n$body$extraSpace}'; 35
36 String code = 'function($parameters) {\n$body$extraSpace}';
37 List<SourceMappingEntry> sourceMappings = new List<SourceMappingEntry>();
38 SourceFile sourceFile = element.getCompilationUnit().script.file;
39 FunctionExpression expression = element.cachedNode;
40 sourceMappings.add(new SourceMappingEntry(
41 sourceFile, expression.getBeginToken().charOffset, 0));
42 sourceMappings.add(new SourceMappingEntry(
43 sourceFile, expression.getEndToken().charOffset, code.length - 1));
44 return new CodeBlock(code, sourceMappings);
36 } 45 }
37 46
38 String generateMethod(WorkItem work, HGraph graph) { 47 CodeBlock generateMethod(WorkItem work, HGraph graph) {
39 return measure(() { 48 return measure(() {
40 compiler.tracer.traceGraph("codegen", graph); 49 compiler.tracer.traceGraph("codegen", graph);
41 Map<Element, String> parameterNames = getParameterNames(work); 50 Map<Element, String> parameterNames = getParameterNames(work);
42 parameterNames.forEach((element, name) { 51 parameterNames.forEach((element, name) {
43 compiler.enqueuer.codegen.addToWorkList(element); 52 compiler.enqueuer.codegen.addToWorkList(element);
44 }); 53 });
45 String parameters = Strings.join(parameterNames.getValues(), ', '); 54 String parameters = Strings.join(parameterNames.getValues(), ', ');
46 SsaOptimizedCodeGenerator codegen = new SsaOptimizedCodeGenerator( 55 SsaOptimizedCodeGenerator codegen = new SsaOptimizedCodeGenerator(
47 backend, work, parameters, parameterNames); 56 backend, work, parameters, parameterNames);
48 codegen.visitGraph(graph); 57 codegen.visitGraph(graph);
(...skipping 13 matching lines...) Expand all
62 native.generateMethodWithPrototypeCheckForElement( 71 native.generateMethodWithPrototypeCheckForElement(
63 compiler, buffer, element, '${codegen.buffer}', parameters); 72 compiler, buffer, element, '${codegen.buffer}', parameters);
64 code = buffer.toString(); 73 code = buffer.toString();
65 } else { 74 } else {
66 code = codegen.buffer.toString(); 75 code = codegen.buffer.toString();
67 } 76 }
68 return buildJavaScriptFunction(element, parameters, code); 77 return buildJavaScriptFunction(element, parameters, code);
69 }); 78 });
70 } 79 }
71 80
72 String generateBailoutMethod(WorkItem work, HGraph graph) { 81 CodeBlock generateBailoutMethod(WorkItem work, HGraph graph) {
73 return measure(() { 82 return measure(() {
74 compiler.tracer.traceGraph("codegen-bailout", graph); 83 compiler.tracer.traceGraph("codegen-bailout", graph);
75 84
76 Map<Element, String> parameterNames = getParameterNames(work); 85 Map<Element, String> parameterNames = getParameterNames(work);
77 String parameters = Strings.join(parameterNames.getValues(), ', '); 86 String parameters = Strings.join(parameterNames.getValues(), ', ');
78 SsaUnoptimizedCodeGenerator codegen = new SsaUnoptimizedCodeGenerator( 87 SsaUnoptimizedCodeGenerator codegen = new SsaUnoptimizedCodeGenerator(
79 backend, work, parameters, parameterNames); 88 backend, work, parameters, parameterNames);
80 codegen.visitGraph(graph); 89 codegen.visitGraph(graph);
81 90
82 String body = '${codegen.setup}${codegen.buffer}'; 91 String body = '${codegen.setup}${codegen.buffer}';
(...skipping 2839 matching lines...) Expand 10 before | Expand all | Expand 10 after
2922 startBailoutSwitch(); 2931 startBailoutSwitch();
2923 } 2932 }
2924 } 2933 }
2925 2934
2926 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { 2935 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) {
2927 if (labeledBlockInfo.body.start.hasGuards()) { 2936 if (labeledBlockInfo.body.start.hasGuards()) {
2928 endBailoutSwitch(); 2937 endBailoutSwitch();
2929 } 2938 }
2930 } 2939 }
2931 } 2940 }
2941
2942 class SourceMappingEntry {
floitsch 2012/07/02 15:18:32 I don't think these classes belong here. The CodeB
podivilov 2012/07/03 13:08:49 Moved CodeBlock to universe.dart. Please let me kn
2943 SourceFile sourceFile;
2944 int sourceOffset;
2945 int targetOffset;
2946 String sourceName;
2947
2948 SourceMappingEntry(this.sourceFile,
2949 this.sourceOffset,
2950 this.targetOffset,
2951 [this.sourceName]);
2952 }
2953
2954 class CodeBlock {
2955 String code;
2956 List<SourceMappingEntry> sourceMappings;
2957 CodeBlock(this.code, this.sourceMappings);
2958 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698