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

Side by Side Diff: frog/leg/ssa/codegen.dart

Issue 9351020: Implement try/catch without finally, and without type checks. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 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
« no previous file with comments | « frog/leg/ssa/closure.dart ('k') | frog/leg/ssa/nodes.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 SsaCodeGeneratorTask(Compiler compiler) : super(compiler); 6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler);
7 String get name() => 'SSA code generator'; 7 String get name() => 'SSA code generator';
8 8
9 String generate(WorkItem work, HGraph graph) { 9 String generate(WorkItem work, HGraph graph) {
10 return measure(() { 10 return measure(() {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 213
214 visitBasicBlock(HBasicBlock node) { 214 visitBasicBlock(HBasicBlock node) {
215 currentBlock = node; 215 currentBlock = node;
216 216
217 // While loop will be closed by the conditional loop-branch. 217 // While loop will be closed by the conditional loop-branch.
218 // TODO(floitsch): HACK HACK HACK. 218 // TODO(floitsch): HACK HACK HACK.
219 if (currentBlock.isLoopHeader()) beginLoop(node); 219 if (currentBlock.isLoopHeader()) beginLoop(node);
220 220
221 HInstruction instruction = node.first; 221 HInstruction instruction = node.first;
222 while (instruction != null) { 222 while (instruction != null) {
223 if (instruction is HGoto || instruction is HExit) { 223 if (instruction is HGoto || instruction is HExit || instruction is HTry) {
224 visit(instruction); 224 visit(instruction);
225 return; 225 return;
226 } else if (!instruction.generateAtUseSite()) { 226 } else if (!instruction.generateAtUseSite()) {
227 if (instruction is !HIf && instruction is !HBailoutTarget) { 227 if (instruction is !HIf && instruction is !HBailoutTarget) {
228 addIndentation(); 228 addIndentation();
229 } 229 }
230 if (instruction.usedBy.isEmpty() || instruction is HLocal) { 230 if (instruction.usedBy.isEmpty() || instruction is HLocal) {
231 visit(instruction); 231 visit(instruction);
232 } else { 232 } else {
233 define(instruction); 233 define(instruction);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 // is responsible for visiting the successor. 343 // is responsible for visiting the successor.
344 if (dominated.isEmpty()) return; 344 if (dominated.isEmpty()) return;
345 if (dominated.length > 2) unreachable(); 345 if (dominated.length > 2) unreachable();
346 if (dominated.length == 2 && currentBlock !== currentGraph.entry) { 346 if (dominated.length == 2 && currentBlock !== currentGraph.entry) {
347 unreachable(); 347 unreachable();
348 } 348 }
349 assert(dominated[0] == currentBlock.successors[0]); 349 assert(dominated[0] == currentBlock.successors[0]);
350 visitBasicBlock(dominated[0]); 350 visitBasicBlock(dominated[0]);
351 } 351 }
352 352
353 visitTry(HTry node) {
354 addIndentation();
355 buffer.add('try {\n');
356 indent++;
357 List<HBasicBlock> successors = node.block.successors;
358 visitBasicBlock(successors[0]);
359 indent--;
360
361 if (node.finallyBlock != successors[1]) {
362 addIndentation();
363 buffer.add('} catch (e) {\n');
364 indent++;
365 }
366
367 for (int i = 1; i < successors.length - 1; i++) {
368 // TODO(ngeoffray): add the type check.
369 visitBasicBlock(successors[i]);
370 }
371
372 if (node.finallyBlock == null) {
373 // TODO(ngeoffray): add the type check.
374 visitBasicBlock(successors[successors.length - 1]);
375 } else {
376 addIndentation();
377 buffer.add('} finally {\n');
378 indent++;
379 visitBasicBlock(node.finallyBlock);
380 }
381 indent--;
382 addIndentation();
383 buffer.add('}\n');
384 }
385
353 visitIf(HIf node) { 386 visitIf(HIf node) {
354 startIf(node); 387 startIf(node);
355 assert(!node.generateAtUseSite()); 388 assert(!node.generateAtUseSite());
356 startThen(node); 389 startThen(node);
357 visitBasicBlock(node.thenBlock); 390 visitBasicBlock(node.thenBlock);
358 endThen(node); 391 endThen(node);
359 if (node.hasElse) { 392 if (node.hasElse) {
360 startElse(node); 393 startElse(node);
361 visitBasicBlock(node.elseBlock); 394 visitBasicBlock(node.elseBlock);
362 endElse(node); 395 endElse(node);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 buffer.add('.'); 503 buffer.add('.');
471 } 504 }
472 String name = JsNames.getValid('${node.element.name}'); 505 String name = JsNames.getValid('${node.element.name}');
473 buffer.add(name); 506 buffer.add(name);
474 } 507 }
475 508
476 visitFieldSet(HFieldSet node) { 509 visitFieldSet(HFieldSet node) {
477 if (node.receiver != null) { 510 if (node.receiver != null) {
478 use(node.receiver); 511 use(node.receiver);
479 buffer.add('.'); 512 buffer.add('.');
513 } else {
514 // TODO(ngeoffray): Remove the 'var' once we don't globally box
515 // variables used in a try/catch.
516 buffer.add('var ');
480 } 517 }
481 String name = JsNames.getValid('${node.element.name}'); 518 String name = JsNames.getValid('${node.element.name}');
482 buffer.add(name); 519 buffer.add(name);
483 buffer.add(' = '); 520 buffer.add(' = ');
484 use(node.value); 521 use(node.value);
485 } 522 }
486 523
487 visitForeign(HForeign node) { 524 visitForeign(HForeign node) {
488 String code = '${node.code}'; 525 String code = '${node.code}';
489 List<HInstruction> inputs = node.inputs; 526 List<HInstruction> inputs = node.inputs;
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 startBailoutSwitch(); 1148 startBailoutSwitch();
1112 } 1149 }
1113 } 1150 }
1114 1151
1115 void endElse(HIf node) { 1152 void endElse(HIf node) {
1116 if (node.elseBlock.hasBailouts()) { 1153 if (node.elseBlock.hasBailouts()) {
1117 endBailoutSwitch(); 1154 endBailoutSwitch();
1118 } 1155 }
1119 } 1156 }
1120 } 1157 }
OLDNEW
« no previous file with comments | « frog/leg/ssa/closure.dart ('k') | frog/leg/ssa/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698