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

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

Issue 10386086: RFC: Start refactoring to provide more than a single backend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 WorkItem { 5 class WorkItem {
6 final Element element; 6 final Element element;
7 TreeElements resolutionTree; 7 TreeElements resolutionTree;
8 Function run; 8 Function run;
9 bool allowSpeculativeOptimization = true; 9 bool allowSpeculativeOptimization = true;
10 List<HTypeGuard> guards = const <HTypeGuard>[]; 10 List<HTypeGuard> guards = const <HTypeGuard>[];
(...skipping 12 matching lines...) Expand all
23 23
24 String compile(Compiler compiler) { 24 String compile(Compiler compiler) {
25 return compiler.compile(this); 25 return compiler.compile(this);
26 } 26 }
27 27
28 String codegen(Compiler compiler) { 28 String codegen(Compiler compiler) {
29 return compiler.codegen(this); 29 return compiler.codegen(this);
30 } 30 }
31 } 31 }
32 32
33 interface Backend {
ahe 2012/05/11 11:39:48 This looks reasonable, but I would prefer to have
floitsch 2012/05/11 13:51:04 Personally I prefer an interface over an empty cla
Anton Muhin 2012/05/12 15:48:43 I erred to interface for as of now I'd rather move
34 String codegen(WorkItem work);
35 }
36
37 class JsBackend implements Backend {
ahe 2012/05/11 11:39:48 Personally, I prefer JavaScriptBackend instead of
Anton Muhin 2012/05/12 15:48:43 Done.
38 Compiler compiler;
39 SsaBuilderTask builder;
40 SsaOptimizerTask optimizer;
41 SsaCodeGeneratorTask generator;
42
43 JsBackend(Compiler compiler)
44 : this.compiler = compiler,
45 builder = new SsaBuilderTask(compiler),
46 optimizer = new SsaOptimizerTask(compiler),
47 generator = new SsaCodeGeneratorTask(compiler);
48
49 String codegen(WorkItem work) {
50 HGraph graph = builder.build(work);
51 optimizer.optimize(work, graph);
52 if (work.allowSpeculativeOptimization
53 && optimizer.trySpeculativeOptimizations(work, graph)) {
54 String code = generator.generateBailoutMethod(work, graph);
55 compiler.universe.addBailoutCode(work, code);
56 optimizer.prepareForSpeculativeOptimizations(work, graph);
57 optimizer.optimize(work, graph);
58 }
59 return generator.generateMethod(work, graph);
60 }
61 }
62
33 class Compiler implements DiagnosticListener { 63 class Compiler implements DiagnosticListener {
34 Queue<WorkItem> worklist; 64 Queue<WorkItem> worklist;
35 Universe universe; 65 Universe universe;
36 World world; 66 World world;
37 String assembledCode; 67 String assembledCode;
38 Namer namer; 68 Namer namer;
39 Types types; 69 Types types;
40 bool enableTypeAssertions = false; 70 bool enableTypeAssertions = false;
41 71
42 final Tracer tracer; 72 final Tracer tracer;
(...skipping 30 matching lines...) Expand all
73 } 103 }
74 } 104 }
75 105
76 List<CompilerTask> tasks; 106 List<CompilerTask> tasks;
77 ScannerTask scanner; 107 ScannerTask scanner;
78 DietParserTask dietParser; 108 DietParserTask dietParser;
79 ParserTask parser; 109 ParserTask parser;
80 TreeValidatorTask validator; 110 TreeValidatorTask validator;
81 ResolverTask resolver; 111 ResolverTask resolver;
82 TypeCheckerTask checker; 112 TypeCheckerTask checker;
83 SsaBuilderTask builder; 113 Backend backend;
84 SsaOptimizerTask optimizer;
85 SsaCodeGeneratorTask generator;
86 CodeEmitterTask emitter; 114 CodeEmitterTask emitter;
87 ConstantHandler constantHandler; 115 ConstantHandler constantHandler;
88 EnqueueTask enqueuer; 116 EnqueueTask enqueuer;
89 117
90 static final SourceString MAIN = const SourceString('main'); 118 static final SourceString MAIN = const SourceString('main');
91 static final SourceString NO_SUCH_METHOD = const SourceString('noSuchMethod'); 119 static final SourceString NO_SUCH_METHOD = const SourceString('noSuchMethod');
92 static final SourceString NO_SUCH_METHOD_EXCEPTION = 120 static final SourceString NO_SUCH_METHOD_EXCEPTION =
93 const SourceString('NoSuchMethodException'); 121 const SourceString('NoSuchMethodException');
94 static final SourceString START_ROOT_ISOLATE = 122 static final SourceString START_ROOT_ISOLATE =
95 const SourceString('startRootIsolate'); 123 const SourceString('startRootIsolate');
96 bool enabledNoSuchMethod = false; 124 bool enabledNoSuchMethod = false;
97 125
98 bool workListIsClosed = false; 126 bool workListIsClosed = false;
99 127
100 Stopwatch codegenProgress; 128 Stopwatch codegenProgress;
101 129
102 Compiler([this.tracer = const Tracer()]) 130 Compiler([this.tracer = const Tracer()])
103 : universe = new Universe(), 131 : universe = new Universe(),
104 world = new World(), 132 world = new World(),
105 worklist = new Queue<WorkItem>(), 133 worklist = new Queue<WorkItem>(),
106 codegenProgress = new Stopwatch.start() { 134 codegenProgress = new Stopwatch.start() {
107 namer = new Namer(this); 135 namer = new Namer(this);
108 constantHandler = new ConstantHandler(this); 136 constantHandler = new ConstantHandler(this);
109 scanner = new ScannerTask(this); 137 scanner = new ScannerTask(this);
110 dietParser = new DietParserTask(this); 138 dietParser = new DietParserTask(this);
111 parser = new ParserTask(this); 139 parser = new ParserTask(this);
112 validator = new TreeValidatorTask(this); 140 validator = new TreeValidatorTask(this);
113 resolver = new ResolverTask(this); 141 resolver = new ResolverTask(this);
114 checker = new TypeCheckerTask(this); 142 checker = new TypeCheckerTask(this);
115 builder = new SsaBuilderTask(this); 143 backend = new JsBackend(this);
116 optimizer = new SsaOptimizerTask(this);
117 generator = new SsaCodeGeneratorTask(this);
118 emitter = new CodeEmitterTask(this); 144 emitter = new CodeEmitterTask(this);
119 enqueuer = new EnqueueTask(this); 145 enqueuer = new EnqueueTask(this);
120 tasks = [scanner, dietParser, parser, resolver, checker, 146 tasks = [scanner, dietParser, parser, resolver, checker,
121 builder, optimizer, generator,
122 emitter, constantHandler, enqueuer]; 147 emitter, constantHandler, enqueuer];
123 } 148 }
124 149
125 void ensure(bool condition) { 150 void ensure(bool condition) {
126 if (!condition) cancel('failed assertion in leg'); 151 if (!condition) cancel('failed assertion in leg');
127 } 152 }
128 153
129 void unimplemented(String methodName, 154 void unimplemented(String methodName,
130 [Node node, Token token, HInstruction instruction, 155 [Node node, Token token, HInstruction instruction,
131 Element element]) { 156 Element element]) {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 if (codegenProgress.elapsedInMs() > 500) { 363 if (codegenProgress.elapsedInMs() > 500) {
339 // TODO(ahe): Add structured diagnostics to the compiler API and 364 // TODO(ahe): Add structured diagnostics to the compiler API and
340 // use it to separate this from the --verbose option. 365 // use it to separate this from the --verbose option.
341 log('compiled ${universe.generatedCode.length} methods'); 366 log('compiled ${universe.generatedCode.length} methods');
342 codegenProgress.reset(); 367 codegenProgress.reset();
343 } 368 }
344 if (work.element.kind.category == ElementCategory.VARIABLE) { 369 if (work.element.kind.category == ElementCategory.VARIABLE) {
345 constantHandler.compileWorkItem(work); 370 constantHandler.compileWorkItem(work);
346 return null; 371 return null;
347 } else { 372 } else {
348 HGraph graph = builder.build(work); 373 String code = backend.codegen(work);
349 optimizer.optimize(work, graph); 374 universe.addGeneratedCode(work, code);
350 if (work.allowSpeculativeOptimization 375 return code;
351 && optimizer.trySpeculativeOptimizations(work, graph)) {
352 String code = generator.generateBailoutMethod(work, graph);
353 universe.addBailoutCode(work, code);
354 optimizer.prepareForSpeculativeOptimizations(work, graph);
355 optimizer.optimize(work, graph);
356 code = generator.generateMethod(work, graph);
357 universe.addGeneratedCode(work, code);
358 return code;
359 } else {
360 String code = generator.generateMethod(work, graph);
361 universe.addGeneratedCode(work, code);
362 return code;
363 }
364 } 376 }
365 } 377 }
366 378
367 String compile(WorkItem work) { 379 String compile(WorkItem work) {
368 String code = universe.generatedCode[work.element]; 380 String code = universe.generatedCode[work.element];
369 if (code !== null) return code; 381 if (code !== null) return code;
370 analyze(work); 382 analyze(work);
371 return codegen(work); 383 return codegen(work);
372 } 384 }
373 385
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 } 584 }
573 } 585 }
574 586
575 class SourceSpan { 587 class SourceSpan {
576 final Uri uri; 588 final Uri uri;
577 final int begin; 589 final int begin;
578 final int end; 590 final int end;
579 591
580 const SourceSpan(this.uri, this.begin, this.end); 592 const SourceSpan(this.uri, this.begin, this.end);
581 } 593 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/builder.dart » ('j') | lib/compiler/implementation/ssa/builder.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698