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

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

Issue 9632018: Switch-implementation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 233
234 visit(HInstruction node, int expectedPrecedence) { 234 visit(HInstruction node, int expectedPrecedence) {
235 int oldPrecedence = this.expectedPrecedence; 235 int oldPrecedence = this.expectedPrecedence;
236 this.expectedPrecedence = expectedPrecedence; 236 this.expectedPrecedence = expectedPrecedence;
237 node.accept(this); 237 node.accept(this);
238 this.expectedPrecedence = oldPrecedence; 238 this.expectedPrecedence = oldPrecedence;
239 } 239 }
240 240
241 void handleLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { 241 void handleLabeledBlock(HLabeledBlockInformation labeledBlockInfo) {
242 addIndentation(); 242 addIndentation();
243 for (SourceString label in labeledBlockInfo.labels) { 243 for (LabelElement label in labeledBlockInfo.labels) {
244 addLabel(label); 244 addLabel(label);
245 buffer.add(":"); 245 buffer.add(":");
246 } 246 }
247 buffer.add("{\n"); 247 buffer.add("{\n");
248 indent++; 248 indent++;
249 249
250 visitSubGraph(labeledBlockInfo.body); 250 visitSubGraph(labeledBlockInfo.body);
251 251
252 indent--; 252 indent--;
253 addIndentation(); 253 addIndentation();
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 if (dominated.length == 2 && currentBlock !== currentGraph.entry) { 415 if (dominated.length == 2 && currentBlock !== currentGraph.entry) {
416 unreachable(); 416 unreachable();
417 } 417 }
418 assert(dominated[0] == currentBlock.successors[0]); 418 assert(dominated[0] == currentBlock.successors[0]);
419 visitBasicBlock(dominated[0]); 419 visitBasicBlock(dominated[0]);
420 } 420 }
421 421
422 // Used to write the name of labels. 422 // Used to write the name of labels.
423 // The default implementation uses the unmodified Dart label name. 423 // The default implementation uses the unmodified Dart label name.
424 // Specializations might change this. 424 // Specializations might change this.
425 void addLabel(SourceString label) { 425 void addLabel(LabelElement label) {
426 buffer.add(label.slowToString()); 426 buffer.add(label.labelName);
427 } 427 }
428 428
429 visitBreak(HBreak node) { 429 visitBreak(HBreak node) {
430 assert(currentBlock.successors.length == 1); 430 assert(currentBlock.successors.length == 1);
431 // No block finishing with a 'break' can have more than 431 // No block finishing with a 'break' can have more than
432 // one dominated block (since it has only one successor). 432 // one dominated block (since it has only one successor).
433 // If the successor is dominated by another block, then the other block 433 // If the successor is dominated by another block, then the other block
434 // is responsible for visiting the successor. 434 // is responsible for visiting the successor.
435 List<HBasicBlock> dominated = currentBlock.dominatedBlocks; 435 List<HBasicBlock> dominated = currentBlock.dominatedBlocks;
436 assert(dominated.isEmpty()); 436 assert(dominated.isEmpty());
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 // need to work together to avoid the parenthesis. See r4928 for an 664 // need to work together to avoid the parenthesis. See r4928 for an
665 // implementation that still dealt with precedence. 665 // implementation that still dealt with precedence.
666 ConstantHandler handler = compiler.constantHandler; 666 ConstantHandler handler = compiler.constantHandler;
667 String name = handler.getNameForConstant(node.constant); 667 String name = handler.getNameForConstant(node.constant);
668 if (name === null) { 668 if (name === null) {
669 assert(!node.constant.isObject()); 669 assert(!node.constant.isObject());
670 node.constant.writeJsCode(buffer, handler); 670 node.constant.writeJsCode(buffer, handler);
671 } else { 671 } else {
672 buffer.add(compiler.namer.CURRENT_ISOLATE); 672 buffer.add(compiler.namer.CURRENT_ISOLATE);
673 buffer.add("."); 673 buffer.add(".");
674 buffer.add(name); 674 buffer.add(name);
675 } 675 }
676 } 676 }
677 677
678 visitLoopBranch(HLoopBranch node) { 678 visitLoopBranch(HLoopBranch node) {
679 HBasicBlock branchBlock = currentBlock; 679 HBasicBlock branchBlock = currentBlock;
680 handleLoopCondition(node); 680 handleLoopCondition(node);
681 List<HBasicBlock> dominated = currentBlock.dominatedBlocks; 681 List<HBasicBlock> dominated = currentBlock.dominatedBlocks;
682 // For a do while loop, the body has already been visited. 682 // For a do while loop, the body has already been visited.
683 if (!node.isDoWhile()) { 683 if (!node.isDoWhile()) {
684 visitBasicBlock(dominated[0]); 684 visitBasicBlock(dominated[0]);
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 checkArray(input, '!=='); 1120 checkArray(input, '!==');
1121 buffer.add(')) '); 1121 buffer.add(')) ');
1122 bailout(node, 'Not a string or array'); 1122 bailout(node, 'Not a string or array');
1123 } else { 1123 } else {
1124 unreachable(); 1124 unreachable();
1125 } 1125 }
1126 } 1126 }
1127 1127
1128 void beginLoop(HBasicBlock block) { 1128 void beginLoop(HBasicBlock block) {
1129 addIndentation(); 1129 addIndentation();
1130 for (SourceString label in block.loopInformation.labels) { 1130 for (LabelElement label in block.loopInformation.labels) {
1131 buffer.add("${label.slowToString()}:"); 1131 buffer.add(label.labelName);
1132 } 1132 }
1133 buffer.add('while (true) {\n'); 1133 buffer.add('while (true) {\n');
1134 indent++; 1134 indent++;
1135 } 1135 }
1136 1136
1137 void endLoop(HBasicBlock block) { 1137 void endLoop(HBasicBlock block) {
1138 indent--; 1138 indent--;
1139 addIndentation(); 1139 addIndentation();
1140 buffer.add('}\n'); // Close 'while' loop. 1140 buffer.add('}\n'); // Close 'while' loop.
1141 } 1141 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 void endBailoutSwitch() { 1287 void endBailoutSwitch() {
1288 indent--; // Close 'case'. 1288 indent--; // Close 'case'.
1289 indent--; 1289 indent--;
1290 addIndentation(); 1290 addIndentation();
1291 buffer.add('}\n'); // Close 'switch'. 1291 buffer.add('}\n'); // Close 'switch'.
1292 } 1292 }
1293 1293
1294 // Adds a "$" in front of names of labels from the original source. 1294 // Adds a "$" in front of names of labels from the original source.
1295 // This avoids conflicts with labels introduced by bailouts, which 1295 // This avoids conflicts with labels introduced by bailouts, which
1296 // starts with a non-"$" character. 1296 // starts with a non-"$" character.
1297 void addLabel(SourceString label) { 1297 void addLabel(LabelElement label) {
1298 buffer.add("\$$label"); 1298 buffer.add("\$${label.labelName}");
1299 } 1299 }
1300 1300
1301 void beginLoop(HBasicBlock block) { 1301 void beginLoop(HBasicBlock block) {
1302 // TODO(ngeoffray): Don't put labels on loops that don't bailout. 1302 // TODO(ngeoffray): Don't put labels on loops that don't bailout.
1303 String newLabel = pushLabel(); 1303 String newLabel = pushLabel();
1304 if (block.hasBailouts()) { 1304 if (block.hasBailouts()) {
1305 startBailoutCase(block.bailouts, const <HBailoutTarget>[]); 1305 startBailoutCase(block.bailouts, const <HBailoutTarget>[]);
1306 } 1306 }
1307 1307
1308 addIndentation(); 1308 addIndentation();
1309 for (SourceString label in block.loopInformation.labels) { 1309 for (LabelElement label in block.loopInformation.labels) {
1310 addLabel(label); 1310 addLabel(label);
1311 buffer.add(":"); 1311 buffer.add(":");
1312 } 1312 }
1313 buffer.add('$newLabel: while (true) {\n'); 1313 buffer.add('$newLabel: while (true) {\n');
1314 indent++; 1314 indent++;
1315 1315
1316 if (block.hasBailouts()) { 1316 if (block.hasBailouts()) {
1317 startBailoutSwitch(); 1317 startBailoutSwitch();
1318 } 1318 }
1319 } 1319 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 startBailoutSwitch(); 1392 startBailoutSwitch();
1393 } 1393 }
1394 } 1394 }
1395 1395
1396 void endElse(HIf node) { 1396 void endElse(HIf node) {
1397 if (node.elseBlock.hasBailouts()) { 1397 if (node.elseBlock.hasBailouts()) {
1398 endBailoutSwitch(); 1398 endBailoutSwitch();
1399 } 1399 }
1400 } 1400 }
1401 } 1401 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698