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

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

Issue 10827180: Move types out of the HInstructions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Simplifications. 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 5
6 /** 6 /**
7 * If true, print a warning for each method that was resolved, but not 7 * If true, print a warning for each method that was resolved, but not
8 * compiled. 8 * compiled.
9 */ 9 */
10 final bool REPORT_EXCESS_RESOLUTION = false; 10 final bool REPORT_EXCESS_RESOLUTION = false;
11 11
12 /** 12 /**
13 * If true, trace information on pass2 optimizations. 13 * If true, trace information on pass2 optimizations.
14 */ 14 */
15 final bool REPORT_PASS2_OPTIMIZATIONS = false; 15 final bool REPORT_PASS2_OPTIMIZATIONS = false;
16 16
17 /**
18 * Contains backend-specific data that is used throughout the compilation of
19 * one work item.
20 */
21 class ItemCompilationContext {
22 }
23
17 class WorkItem { 24 class WorkItem {
25 final ItemCompilationContext compilationContext;
18 final Element element; 26 final Element element;
19 TreeElements resolutionTree; 27 TreeElements resolutionTree;
20 bool allowSpeculativeOptimization = true; 28 bool allowSpeculativeOptimization = true;
21 List<HTypeGuard> guards = const <HTypeGuard>[]; 29 List<HTypeGuard> guards = const <HTypeGuard>[];
22 30
23 WorkItem(this.element, this.resolutionTree); 31 WorkItem(this.element, this.resolutionTree, this.compilationContext);
24 32
25 bool isAnalyzed() => resolutionTree !== null; 33 bool isAnalyzed() => resolutionTree !== null;
26 34
27 String run(Compiler compiler, Enqueuer world) { 35 String run(Compiler compiler, Enqueuer world) {
28 CodeBuffer codeBuffer = world.universe.generatedCode[element]; 36 CodeBuffer codeBuffer = world.universe.generatedCode[element];
29 if (codeBuffer !== null) return codeBuffer.toString(); 37 if (codeBuffer !== null) return codeBuffer.toString();
30 resolutionTree = compiler.analyze(this, world); 38 resolutionTree = compiler.analyze(this, world);
31 return compiler.codegen(this, world); 39 return compiler.codegen(this, world);
32 } 40 }
33 } 41 }
34 42
35 class Backend { 43 class Backend {
36 final Compiler compiler; 44 final Compiler compiler;
37 45
38 Backend(this.compiler); 46 Backend(this.compiler);
39 47
40 void enqueueAllTopLevelFunctions(LibraryElement lib, Enqueuer world) { 48 void enqueueAllTopLevelFunctions(LibraryElement lib, Enqueuer world) {
41 lib.forEachExport((Element e) { 49 lib.forEachExport((Element e) {
42 if (e.isFunction()) world.addToWorkList(e); 50 if (e.isFunction()) world.addToWorkList(e);
43 }); 51 });
44 } 52 }
45 53
46 abstract void enqueueHelpers(Enqueuer world); 54 abstract void enqueueHelpers(Enqueuer world);
47 abstract CodeBuffer codegen(WorkItem work); 55 abstract CodeBuffer codegen(WorkItem work);
48 abstract void processNativeClasses(Enqueuer world, 56 abstract void processNativeClasses(Enqueuer world,
49 Collection<LibraryElement> libraries); 57 Collection<LibraryElement> libraries);
50 abstract void assembleProgram(); 58 abstract void assembleProgram();
51 abstract List<CompilerTask> get tasks(); 59 abstract List<CompilerTask> get tasks();
60
61 ItemCompilationContext createItemCompilationContext() {
62 return new ItemCompilationContext();
63 }
64 }
65
66 class JavaScriptItemCompilationContext extends ItemCompilationContext {
67 final HTypeMap types;
68
69 JavaScriptItemCompilationContext()
70 : types = new HTypeMap();
ngeoffray 2012/08/16 13:07:00 fits in one line
floitsch 2012/08/16 14:10:04 Done.
52 } 71 }
53 72
54 class JavaScriptBackend extends Backend { 73 class JavaScriptBackend extends Backend {
55 SsaBuilderTask builder; 74 SsaBuilderTask builder;
56 SsaOptimizerTask optimizer; 75 SsaOptimizerTask optimizer;
57 SsaCodeGeneratorTask generator; 76 SsaCodeGeneratorTask generator;
58 CodeEmitterTask emitter; 77 CodeEmitterTask emitter;
59 final Map<Element, Map<Element, HType>> fieldInitializers; 78 final Map<Element, Map<Element, HType>> fieldInitializers;
60 final Map<Element, Map<Element, HType>> fieldConstructorSetters; 79 final Map<Element, Map<Element, HType>> fieldConstructorSetters;
61 final Map<Element, Map<Element, HType>> fieldSettersType; 80 final Map<Element, Map<Element, HType>> fieldSettersType;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 HType fieldSettersTypeSoFar(Element field) { 216 HType fieldSettersTypeSoFar(Element field) {
198 assert(field.isField()); 217 assert(field.isField());
199 assert(field.enclosingElement.isClass()); 218 assert(field.enclosingElement.isClass());
200 if (!fieldSettersType.containsKey(field.enclosingElement)) { 219 if (!fieldSettersType.containsKey(field.enclosingElement)) {
201 return HType.CONFLICTING; 220 return HType.CONFLICTING;
202 } 221 }
203 Map<Element, HType> fields = fieldSettersType[field.enclosingElement]; 222 Map<Element, HType> fields = fieldSettersType[field.enclosingElement];
204 if (!fields.containsKey(field)) return HType.CONFLICTING; 223 if (!fields.containsKey(field)) return HType.CONFLICTING;
205 return fields[field]; 224 return fields[field];
206 } 225 }
226
227 JavaScriptItemCompilationContext createItemCompilationContext() {
228 return new JavaScriptItemCompilationContext();
229 }
207 } 230 }
208 231
209 class Compiler implements DiagnosticListener { 232 class Compiler implements DiagnosticListener {
210 final Map<String, LibraryElement> libraries; 233 final Map<String, LibraryElement> libraries;
211 int nextFreeClassId = 0; 234 int nextFreeClassId = 0;
212 World world; 235 World world;
213 String assembledCode; 236 String assembledCode;
214 Namer namer; 237 Namer namer;
215 Types types; 238 Types types;
216 final bool enableTypeAssertions; 239 final bool enableTypeAssertions;
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 String banner = 'compiler cancelled'; 1094 String banner = 'compiler cancelled';
1072 return (reason !== null) ? '$banner: $reason' : '$banner'; 1095 return (reason !== null) ? '$banner: $reason' : '$banner';
1073 } 1096 }
1074 } 1097 }
1075 1098
1076 class Tracer { 1099 class Tracer {
1077 final bool enabled = false; 1100 final bool enabled = false;
1078 1101
1079 const Tracer(); 1102 const Tracer();
1080 1103
1081 void traceCompilation(String methodName) { 1104 void traceCompilation(String methodName, ItemCompilationContext context) {
1082 } 1105 }
1083 1106
1084 void traceGraph(String name, var graph) { 1107 void traceGraph(String name, var graph) {
1085 } 1108 }
1086 1109
1087 void close() { 1110 void close() {
1088 } 1111 }
1089 } 1112 }
1090 1113
1091 class SourceSpan { 1114 class SourceSpan {
1092 final Uri uri; 1115 final Uri uri;
1093 final int begin; 1116 final int begin;
1094 final int end; 1117 final int end;
1095 1118
1096 const SourceSpan(this.uri, this.begin, this.end); 1119 const SourceSpan(this.uri, this.begin, this.end);
1097 1120
1098 static withCharacterOffsets(Token begin, Token end, 1121 static withCharacterOffsets(Token begin, Token end,
1099 f(int beginOffset, int endOffset)) { 1122 f(int beginOffset, int endOffset)) {
1100 final beginOffset = begin.charOffset; 1123 final beginOffset = begin.charOffset;
1101 final endOffset = end.charOffset + end.slowCharCount; 1124 final endOffset = end.charOffset + end.slowCharCount;
1102 1125
1103 // [begin] and [end] might be the same for the same empty token. This 1126 // [begin] and [end] might be the same for the same empty token. This
1104 // happens for instance when scanning '$$'. 1127 // happens for instance when scanning '$$'.
1105 assert(endOffset >= beginOffset); 1128 assert(endOffset >= beginOffset);
1106 return f(beginOffset, endOffset); 1129 return f(beginOffset, endOffset);
1107 } 1130 }
1108 1131
1109 String toString() => 'SourceSpan($uri, $begin, $end)'; 1132 String toString() => 'SourceSpan($uri, $begin, $end)';
1110 } 1133 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/enqueue.dart » ('j') | lib/compiler/implementation/ssa/codegen.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698