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

Unified Diff: runtime/vm/intermediate_language.cc

Issue 9453014: Implement a simple InstructionVisitor class. (Closed) Base URL: https://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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/intermediate_language.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/intermediate_language.cc
diff --git a/runtime/vm/intermediate_language.cc b/runtime/vm/intermediate_language.cc
index 7bb66206027d56466472a5a1916deec3f579cacf..c0507bbe81fad5c9b0b65ba6bd9c6703a9e87cef 100644
--- a/runtime/vm/intermediate_language.cc
+++ b/runtime/vm/intermediate_language.cc
@@ -60,66 +60,74 @@ void ConstantValue::Print() const {
}
-Instruction* DoInstr::Print() const {
- OS::Print(" ");
- computation_->Print();
+// ==== Support for visiting instructions.
+Instruction* JoinEntryInstr::Accept(InstructionVisitor* visitor) {
+ visitor->VisitJoinEntry(this);
return successor_;
}
-Instruction* BindInstr::Print() const {
- OS::Print(" t%d <-", temp_index_);
- computation_->Print();
+Instruction* TargetEntryInstr::Accept(InstructionVisitor* visitor) {
+ visitor->VisitTargetEntry(this);
return successor_;
}
-Instruction* ReturnInstr::Print() const {
- OS::Print(" return ");
- value_->Print();
- return NULL;
+Instruction* DoInstr::Accept(InstructionVisitor* visitor) {
+ visitor->VisitDo(this);
+ return successor_;
}
-Instruction* BranchInstr::Print() const {
- OS::Print(" if ");
- value_->Print();
- OS::Print(" goto(%d, %d)", true_successor_->GetBlockNumber(),
- false_successor_->GetBlockNumber());
+Instruction* BindInstr::Accept(InstructionVisitor* visitor) {
+ visitor->VisitBind(this);
+ return successor_;
+}
+
+
+Instruction* ReturnInstr::Accept(InstructionVisitor* visitor) {
+ visitor->VisitReturn(this);
return NULL;
}
-Instruction* JoinEntryInstr::Print() const {
- OS::Print("%2d: [join]", block_number_);
- return successor_;
+Instruction* BranchInstr::Accept(InstructionVisitor* visitor) {
+ visitor->VisitBranch(this);
+ return NULL;
}
-Instruction* TargetEntryInstr::Print() const {
- OS::Print("%2d: [target]", block_number_);
- return successor_;
+// Default implementation of visiting basic blocks. Can be overridden.
+void InstructionVisitor::VisitBlocks(
+ const GrowableArray<BlockEntryInstr*>& block_order) {
+ for (intptr_t i = block_order.length() - 1; i >= 0; --i) {
+ Instruction* current = block_order[i]->Accept(this);
+ while ((current != NULL) && !current->IsBlockEntry()) {
+ current = current->Accept(this);
+ }
+ }
}
-void DoInstr::Postorder(GrowableArray<Instruction*>* block_entries) {
+// ==== Postorder graph traversal.
+void DoInstr::Postorder(GrowableArray<BlockEntryInstr*>* block_entries) {
flip_mark();
if (successor_->mark() != mark()) successor_->Postorder(block_entries);
}
-void BindInstr::Postorder(GrowableArray<Instruction*>* block_entries) {
+void BindInstr::Postorder(GrowableArray<BlockEntryInstr*>* block_entries) {
flip_mark();
if (successor_->mark() != mark()) successor_->Postorder(block_entries);
}
-void ReturnInstr::Postorder(GrowableArray<Instruction*>* block_entries) {
+void ReturnInstr::Postorder(GrowableArray<BlockEntryInstr*>* block_entries) {
flip_mark();
}
-void BranchInstr::Postorder(GrowableArray<Instruction*>* block_entries) {
+void BranchInstr::Postorder(GrowableArray<BlockEntryInstr*>* block_entries) {
flip_mark();
// Visit the false successor before the true successor so they appear in
// true/false order in reverse postorder.
@@ -132,14 +140,15 @@ void BranchInstr::Postorder(GrowableArray<Instruction*>* block_entries) {
}
-void JoinEntryInstr::Postorder(GrowableArray<Instruction*>* block_entries) {
+void JoinEntryInstr::Postorder(GrowableArray<BlockEntryInstr*>* block_entries) {
flip_mark();
if (successor_->mark() != mark()) successor_->Postorder(block_entries);
block_entries->Add(this);
}
-void TargetEntryInstr::Postorder(GrowableArray<Instruction*>* block_entries) {
+void TargetEntryInstr::Postorder(
+ GrowableArray<BlockEntryInstr*>* block_entries) {
flip_mark();
if (successor_->mark() != mark()) successor_->Postorder(block_entries);
block_entries->Add(this);
« no previous file with comments | « runtime/vm/intermediate_language.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698