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

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

Issue 9421035: Support break and labeled statements. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 interface HVisitor<R> { 5 interface HVisitor<R> {
6 R visitAdd(HAdd node); 6 R visitAdd(HAdd node);
7 R visitBailoutTarget(HBailoutTarget node); 7 R visitBailoutTarget(HBailoutTarget node);
8 R visitBitAnd(HBitAnd node); 8 R visitBitAnd(HBitAnd node);
9 R visitBitNot(HBitNot node); 9 R visitBitNot(HBitNot node);
10 R visitBitOr(HBitOr node); 10 R visitBitOr(HBitOr node);
11 R visitBitXor(HBitXor node); 11 R visitBitXor(HBitXor node);
12 R visitBoolify(HBoolify node); 12 R visitBoolify(HBoolify node);
13 R visitBoundsCheck(HBoundsCheck node); 13 R visitBoundsCheck(HBoundsCheck node);
14 R visitBreak(HBreak node);
14 R visitDivide(HDivide node); 15 R visitDivide(HDivide node);
15 R visitEquals(HEquals node); 16 R visitEquals(HEquals node);
16 R visitExit(HExit node); 17 R visitExit(HExit node);
17 R visitFieldGet(HFieldGet node); 18 R visitFieldGet(HFieldGet node);
18 R visitFieldSet(HFieldSet node); 19 R visitFieldSet(HFieldSet node);
19 R visitForeign(HForeign node); 20 R visitForeign(HForeign node);
20 R visitForeignNew(HForeignNew); 21 R visitForeignNew(HForeignNew);
21 R visitGoto(HGoto node); 22 R visitGoto(HGoto node);
22 R visitGreater(HGreater node); 23 R visitGreater(HGreater node);
23 R visitGreaterEqual(HGreaterEqual node); 24 R visitGreaterEqual(HGreaterEqual node);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 blocks.add(block); 129 blocks.add(block);
129 assert(blocks[id] === block); 130 assert(blocks[id] === block);
130 } 131 }
131 132
132 HBasicBlock addNewBlock() { 133 HBasicBlock addNewBlock() {
133 HBasicBlock result = new HBasicBlock(); 134 HBasicBlock result = new HBasicBlock();
134 addBlock(result); 135 addBlock(result);
135 return result; 136 return result;
136 } 137 }
137 138
138 HBasicBlock addNewLoopHeaderBlock() { 139 HBasicBlock addNewLoopHeaderBlock(List<SourceString> labels) {
139 HBasicBlock result = addNewBlock(); 140 HBasicBlock result = addNewBlock();
140 result.loopInformation = new HLoopInformation(result); 141 result.loopInformation = new HLoopInformation(result, labels);
141 return result; 142 return result;
142 } 143 }
143 144
144 void finalize() { 145 void finalize() {
145 addBlock(exit); 146 addBlock(exit);
146 exit.open(); 147 exit.open();
147 exit.close(new HExit()); 148 exit.close(new HExit());
148 assignDominators(); 149 assignDominators();
149 } 150 }
150 151
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 visitRelational(HRelational node) => visitInvokeBinary(node); 201 visitRelational(HRelational node) => visitInvokeBinary(node);
201 202
202 visitAdd(HAdd node) => visitBinaryArithmetic(node); 203 visitAdd(HAdd node) => visitBinaryArithmetic(node);
203 visitBitAnd(HBitAnd node) => visitBinaryBitOp(node); 204 visitBitAnd(HBitAnd node) => visitBinaryBitOp(node);
204 visitBitNot(HBitNot node) => visitInvokeUnary(node); 205 visitBitNot(HBitNot node) => visitInvokeUnary(node);
205 visitBitOr(HBitOr node) => visitBinaryBitOp(node); 206 visitBitOr(HBitOr node) => visitBinaryBitOp(node);
206 visitBitXor(HBitXor node) => visitBinaryBitOp(node); 207 visitBitXor(HBitXor node) => visitBinaryBitOp(node);
207 visitBailoutTarget(HBailoutTarget node) => visitInstruction(node); 208 visitBailoutTarget(HBailoutTarget node) => visitInstruction(node);
208 visitBoolify(HBoolify node) => visitInstruction(node); 209 visitBoolify(HBoolify node) => visitInstruction(node);
209 visitBoundsCheck(HBoundsCheck node) => visitCheck(node); 210 visitBoundsCheck(HBoundsCheck node) => visitCheck(node);
211 visitBreak(HBreak node) => visitGoto(node);
210 visitCheck(HCheck node) => visitInstruction(node); 212 visitCheck(HCheck node) => visitInstruction(node);
211 visitDivide(HDivide node) => visitBinaryArithmetic(node); 213 visitDivide(HDivide node) => visitBinaryArithmetic(node);
212 visitEquals(HEquals node) => visitRelational(node); 214 visitEquals(HEquals node) => visitRelational(node);
213 visitExit(HExit node) => visitControlFlow(node); 215 visitExit(HExit node) => visitControlFlow(node);
214 visitFieldGet(HFieldGet node) => visitInstruction(node); 216 visitFieldGet(HFieldGet node) => visitInstruction(node);
215 visitFieldSet(HFieldSet node) => visitInstruction(node); 217 visitFieldSet(HFieldSet node) => visitInstruction(node);
216 visitForeign(HForeign node) => visitInstruction(node); 218 visitForeign(HForeign node) => visitInstruction(node);
217 visitForeignNew(HForeignNew node) => visitForeign(node); 219 visitForeignNew(HForeignNew node) => visitForeign(node);
218 visitGoto(HGoto node) => visitControlFlow(node); 220 visitGoto(HGoto node) => visitControlFlow(node);
219 visitGreater(HGreater node) => visitRelational(node); 221 visitGreater(HGreater node) => visitRelational(node);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 int id; 345 int id;
344 346
345 static final int STATUS_NEW = 0; 347 static final int STATUS_NEW = 0;
346 static final int STATUS_OPEN = 1; 348 static final int STATUS_OPEN = 1;
347 static final int STATUS_CLOSED = 2; 349 static final int STATUS_CLOSED = 2;
348 int status = STATUS_NEW; 350 int status = STATUS_NEW;
349 351
350 HInstructionList phis; 352 HInstructionList phis;
351 353
352 HLoopInformation loopInformation = null; 354 HLoopInformation loopInformation = null;
355 HLabeledBlockInformation labeledBlockInformation = null;
353 HBasicBlock parentLoopHeader = null; 356 HBasicBlock parentLoopHeader = null;
354 List<HBailoutTarget> bailouts; 357 List<HBailoutTarget> bailouts;
355 358
356 final List<HBasicBlock> predecessors; 359 final List<HBasicBlock> predecessors;
357 List<HBasicBlock> successors; 360 List<HBasicBlock> successors;
358 361
359 HBasicBlock dominator = null; 362 HBasicBlock dominator = null;
360 final List<HBasicBlock> dominatedBlocks; 363 final List<HBasicBlock> dominatedBlocks;
361 364
365 // For recognizing labeled statements.
366 List<SourceString> labels;
367
362 HBasicBlock() : this.withId(null); 368 HBasicBlock() : this.withId(null);
363 HBasicBlock.withId(this.id) 369 HBasicBlock.withId(this.id)
364 : phis = new HInstructionList(), 370 : phis = new HInstructionList(),
365 predecessors = <HBasicBlock>[], 371 predecessors = <HBasicBlock>[],
366 successors = const <HBasicBlock>[], 372 successors = const <HBasicBlock>[],
367 dominatedBlocks = <HBasicBlock>[], 373 dominatedBlocks = <HBasicBlock>[],
368 bailouts = <HBailoutTarget>[]; 374 bailouts = <HBailoutTarget>[];
369 375
370 bool isNew() => status == STATUS_NEW; 376 bool isNew() => status == STATUS_NEW;
371 bool isOpen() => status == STATUS_OPEN; 377 bool isOpen() => status == STATUS_OPEN;
372 bool isClosed() => status == STATUS_CLOSED; 378 bool isClosed() => status == STATUS_CLOSED;
373 379
374 bool isLoopHeader() => loopInformation !== null; 380 bool isLoopHeader() => loopInformation !== null;
381 bool hasLabeledBlockInformation() => labeledBlockInformation !== null;
382
375 bool hasBailouts() => !bailouts.isEmpty(); 383 bool hasBailouts() => !bailouts.isEmpty();
376 384
377 void open() { 385 void open() {
378 assert(isNew()); 386 assert(isNew());
379 status = STATUS_OPEN; 387 status = STATUS_OPEN;
380 } 388 }
381 389
382 void close(HControlFlow end) { 390 void close(HControlFlow end) {
383 assert(isOpen()); 391 assert(isOpen());
384 addAfter(last, end); 392 addAfter(last, end);
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 } 584 }
577 585
578 bool isValid() { 586 bool isValid() {
579 assert(isClosed()); 587 assert(isClosed());
580 HValidator validator = new HValidator(); 588 HValidator validator = new HValidator();
581 validator.visitBasicBlock(this); 589 validator.visitBasicBlock(this);
582 return validator.isValid; 590 return validator.isValid;
583 } 591 }
584 } 592 }
585 593
586 class HLoopInformation { 594 class HBlockInformation {
595 // Just a marker class.
596 }
597
598 class HLabeledBlockInformation extends HBlockInformation {
599 final HBasicBlock start;
600 final HBasicBlock end;
601 final List<SourceString> labels;
602 HLabeledBlockInformation(this.start, this.end, this.labels);
603 }
604
605 class HLoopInformation extends HBlockInformation {
587 final HBasicBlock header; 606 final HBasicBlock header;
588 final List<HBasicBlock> blocks; 607 final List<HBasicBlock> blocks;
589 final List<HBasicBlock> backEdges; 608 final List<HBasicBlock> backEdges;
609 final List<SourceString> labels;
590 610
591 HLoopInformation(this.header) 611 HLoopInformation(this.header, this.labels)
592 : blocks = new List<HBasicBlock>(), 612 : blocks = new List<HBasicBlock>(),
593 backEdges = new List<HBasicBlock>(); 613 backEdges = new List<HBasicBlock>();
594 614
595 void addBackEdge(HBasicBlock predecessor) { 615 void addBackEdge(HBasicBlock predecessor) {
596 backEdges.add(predecessor); 616 backEdges.add(predecessor);
597 addBlock(predecessor); 617 addBlock(predecessor);
598 } 618 }
599 619
600 // Adds a block and transitively all its predecessors in the loop as 620 // Adds a block and transitively all its predecessors in the loop as
601 // loop blocks. 621 // loop blocks.
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 toString() => 'exit'; 1647 toString() => 'exit';
1628 accept(HVisitor visitor) => visitor.visitExit(this); 1648 accept(HVisitor visitor) => visitor.visitExit(this);
1629 } 1649 }
1630 1650
1631 class HGoto extends HControlFlow { 1651 class HGoto extends HControlFlow {
1632 HGoto() : super(const <HInstruction>[]); 1652 HGoto() : super(const <HInstruction>[]);
1633 toString() => 'goto'; 1653 toString() => 'goto';
1634 accept(HVisitor visitor) => visitor.visitGoto(this); 1654 accept(HVisitor visitor) => visitor.visitGoto(this);
1635 } 1655 }
1636 1656
1657 class HBreak extends HGoto {
1658 final SourceString label;
1659 HBreak([this.label]);
1660 toString() => 'break';
1661 accept(HVisitor visitor) => visitor.visitBreak(this);
1662 }
1663
1637 class HTry extends HControlFlow { 1664 class HTry extends HControlFlow {
1638 HParameterValue exception; 1665 HParameterValue exception;
1639 HBasicBlock finallyBlock; 1666 HBasicBlock finallyBlock;
1640 HTry() : super(const <HInstruction>[]); 1667 HTry() : super(const <HInstruction>[]);
1641 toString() => 'try'; 1668 toString() => 'try';
1642 accept(HVisitor visitor) => visitor.visitTry(this); 1669 accept(HVisitor visitor) => visitor.visitTry(this);
1643 } 1670 }
1644 1671
1645 class HIf extends HConditionalBranch { 1672 class HIf extends HConditionalBranch {
1646 bool hasElse; 1673 bool hasElse;
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
2131 2158
2132 HInstruction get expression() => inputs[0]; 2159 HInstruction get expression() => inputs[0];
2133 2160
2134 HType computeType() => HType.BOOLEAN; 2161 HType computeType() => HType.BOOLEAN;
2135 bool hasExpectedType() => true; 2162 bool hasExpectedType() => true;
2136 2163
2137 accept(HVisitor visitor) => visitor.visitIs(this); 2164 accept(HVisitor visitor) => visitor.visitIs(this);
2138 2165
2139 toString() => "$expression is $typeExpression"; 2166 toString() => "$expression is $typeExpression";
2140 } 2167 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698