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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/intermediate_language.h ('k') | no next file » | 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 #include "vm/intermediate_language.h" 5 #include "vm/intermediate_language.h"
6 6
7 #include "vm/object.h" 7 #include "vm/object.h"
8 #include "vm/os.h" 8 #include "vm/os.h"
9 #include "vm/scopes.h" 9 #include "vm/scopes.h"
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 void TempValue::Print() const { 53 void TempValue::Print() const {
54 OS::Print("t%d", index_); 54 OS::Print("t%d", index_);
55 } 55 }
56 56
57 57
58 void ConstantValue::Print() const { 58 void ConstantValue::Print() const {
59 OS::Print("#%s", instance_.ToCString()); 59 OS::Print("#%s", instance_.ToCString());
60 } 60 }
61 61
62 62
63 Instruction* DoInstr::Print() const { 63 // ==== Support for visiting instructions.
64 OS::Print(" "); 64 Instruction* JoinEntryInstr::Accept(InstructionVisitor* visitor) {
65 computation_->Print(); 65 visitor->VisitJoinEntry(this);
66 return successor_; 66 return successor_;
67 } 67 }
68 68
69 69
70 Instruction* BindInstr::Print() const { 70 Instruction* TargetEntryInstr::Accept(InstructionVisitor* visitor) {
71 OS::Print(" t%d <-", temp_index_); 71 visitor->VisitTargetEntry(this);
72 computation_->Print();
73 return successor_; 72 return successor_;
74 } 73 }
75 74
76 75
77 Instruction* ReturnInstr::Print() const { 76 Instruction* DoInstr::Accept(InstructionVisitor* visitor) {
78 OS::Print(" return "); 77 visitor->VisitDo(this);
79 value_->Print(); 78 return successor_;
79 }
80
81
82 Instruction* BindInstr::Accept(InstructionVisitor* visitor) {
83 visitor->VisitBind(this);
84 return successor_;
85 }
86
87
88 Instruction* ReturnInstr::Accept(InstructionVisitor* visitor) {
89 visitor->VisitReturn(this);
80 return NULL; 90 return NULL;
81 } 91 }
82 92
83 93
84 Instruction* BranchInstr::Print() const { 94 Instruction* BranchInstr::Accept(InstructionVisitor* visitor) {
85 OS::Print(" if "); 95 visitor->VisitBranch(this);
86 value_->Print();
87 OS::Print(" goto(%d, %d)", true_successor_->GetBlockNumber(),
88 false_successor_->GetBlockNumber());
89 return NULL; 96 return NULL;
90 } 97 }
91 98
92 99
93 Instruction* JoinEntryInstr::Print() const { 100 // Default implementation of visiting basic blocks. Can be overridden.
94 OS::Print("%2d: [join]", block_number_); 101 void InstructionVisitor::VisitBlocks(
95 return successor_; 102 const GrowableArray<BlockEntryInstr*>& block_order) {
103 for (intptr_t i = block_order.length() - 1; i >= 0; --i) {
104 Instruction* current = block_order[i]->Accept(this);
105 while ((current != NULL) && !current->IsBlockEntry()) {
106 current = current->Accept(this);
107 }
108 }
96 } 109 }
97 110
98 111
99 Instruction* TargetEntryInstr::Print() const { 112 // ==== Postorder graph traversal.
100 OS::Print("%2d: [target]", block_number_); 113 void DoInstr::Postorder(GrowableArray<BlockEntryInstr*>* block_entries) {
101 return successor_;
102 }
103
104
105 void DoInstr::Postorder(GrowableArray<Instruction*>* block_entries) {
106 flip_mark(); 114 flip_mark();
107 if (successor_->mark() != mark()) successor_->Postorder(block_entries); 115 if (successor_->mark() != mark()) successor_->Postorder(block_entries);
108 } 116 }
109 117
110 118
111 void BindInstr::Postorder(GrowableArray<Instruction*>* block_entries) { 119 void BindInstr::Postorder(GrowableArray<BlockEntryInstr*>* block_entries) {
112 flip_mark(); 120 flip_mark();
113 if (successor_->mark() != mark()) successor_->Postorder(block_entries); 121 if (successor_->mark() != mark()) successor_->Postorder(block_entries);
114 } 122 }
115 123
116 124
117 void ReturnInstr::Postorder(GrowableArray<Instruction*>* block_entries) { 125 void ReturnInstr::Postorder(GrowableArray<BlockEntryInstr*>* block_entries) {
118 flip_mark(); 126 flip_mark();
119 } 127 }
120 128
121 129
122 void BranchInstr::Postorder(GrowableArray<Instruction*>* block_entries) { 130 void BranchInstr::Postorder(GrowableArray<BlockEntryInstr*>* block_entries) {
123 flip_mark(); 131 flip_mark();
124 // Visit the false successor before the true successor so they appear in 132 // Visit the false successor before the true successor so they appear in
125 // true/false order in reverse postorder. 133 // true/false order in reverse postorder.
126 if (false_successor_->mark() != mark()) { 134 if (false_successor_->mark() != mark()) {
127 false_successor_->Postorder(block_entries); 135 false_successor_->Postorder(block_entries);
128 } 136 }
129 if (true_successor_->mark() != mark()) { 137 if (true_successor_->mark() != mark()) {
130 true_successor_->Postorder(block_entries); 138 true_successor_->Postorder(block_entries);
131 } 139 }
132 } 140 }
133 141
134 142
135 void JoinEntryInstr::Postorder(GrowableArray<Instruction*>* block_entries) { 143 void JoinEntryInstr::Postorder(GrowableArray<BlockEntryInstr*>* block_entries) {
136 flip_mark(); 144 flip_mark();
137 if (successor_->mark() != mark()) successor_->Postorder(block_entries); 145 if (successor_->mark() != mark()) successor_->Postorder(block_entries);
138 block_entries->Add(this); 146 block_entries->Add(this);
139 } 147 }
140 148
141 149
142 void TargetEntryInstr::Postorder(GrowableArray<Instruction*>* block_entries) { 150 void TargetEntryInstr::Postorder(
151 GrowableArray<BlockEntryInstr*>* block_entries) {
143 flip_mark(); 152 flip_mark();
144 if (successor_->mark() != mark()) successor_->Postorder(block_entries); 153 if (successor_->mark() != mark()) successor_->Postorder(block_entries);
145 block_entries->Add(this); 154 block_entries->Add(this);
146 } 155 }
147 156
148 157
149 } // namespace dart 158 } // namespace dart
OLDNEW
« 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