OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #include "vm/intermediate_language.h" |
| 6 |
| 7 #include "vm/object.h" |
| 8 #include "vm/os.h" |
| 9 #include "vm/scopes.h" |
| 10 |
| 11 namespace dart { |
| 12 |
| 13 // ==== Printing support. |
| 14 void AssertAssignableComp::Print() const { |
| 15 OS::Print("AssertAssignable("); |
| 16 value_->Print(); |
| 17 OS::Print(", %s)", type_.ToCString()); |
| 18 } |
| 19 |
| 20 |
| 21 void InstanceCallComp::Print() const { |
| 22 OS::Print("InstanceCall(%s", name_); |
| 23 for (intptr_t i = 0; i < arguments_->length(); ++i) { |
| 24 OS::Print(", "); |
| 25 (*arguments_)[i]->Print(); |
| 26 } |
| 27 OS::Print(")"); |
| 28 } |
| 29 |
| 30 |
| 31 void StaticCallComp::Print() const { |
| 32 OS::Print("StaticCall(%s", String::Handle(function_.name()).ToCString()); |
| 33 for (intptr_t i = 0; i < arguments_->length(); ++i) { |
| 34 OS::Print(", "); |
| 35 (*arguments_)[i]->Print(); |
| 36 } |
| 37 OS::Print(")"); |
| 38 } |
| 39 |
| 40 |
| 41 void LoadLocalComp::Print() const { |
| 42 OS::Print("LoadLocal(%s)", local_.name().ToCString()); |
| 43 } |
| 44 |
| 45 |
| 46 void StoreLocalComp::Print() const { |
| 47 OS::Print("StoreLocal(%s, ", local_.name().ToCString()); |
| 48 value_->Print(); |
| 49 OS::Print(")"); |
| 50 } |
| 51 |
| 52 |
| 53 void TempValue::Print() const { |
| 54 OS::Print("t%d", index_); |
| 55 } |
| 56 |
| 57 |
| 58 void ConstantValue::Print() const { |
| 59 OS::Print("#%s", instance_.ToCString()); |
| 60 } |
| 61 |
| 62 |
| 63 void Instruction::PrintGotoSuccessor( |
| 64 Instruction* successor, |
| 65 intptr_t instruction_index, |
| 66 const GrowableArray<Instruction*>& instruction_list) const { |
| 67 if ((instruction_index == 0) || |
| 68 (instruction_list[instruction_index - 1] != successor)) { |
| 69 // Linear search of the instruction list for the successor's index. |
| 70 for (intptr_t i = 0; i < instruction_list.length(); ++i) { |
| 71 if (instruction_list[i] == successor) { |
| 72 intptr_t instruction_number = instruction_list.length() - i; |
| 73 OS::Print(" goto %d", instruction_number); |
| 74 break; |
| 75 } |
| 76 } |
| 77 } |
| 78 } |
| 79 |
| 80 |
| 81 void DoInstr::Print(intptr_t instruction_index, |
| 82 const GrowableArray<Instruction*>& instruction_list) const { |
| 83 computation_->Print(); |
| 84 PrintGotoSuccessor(successor_, instruction_index, instruction_list); |
| 85 } |
| 86 |
| 87 |
| 88 void BindInstr::Print( |
| 89 intptr_t instruction_index, |
| 90 const GrowableArray<Instruction*>& instruction_list) const { |
| 91 OS::Print("t%d <-", temp_index_); |
| 92 computation_->Print(); |
| 93 PrintGotoSuccessor(successor_, instruction_index, instruction_list); |
| 94 } |
| 95 |
| 96 |
| 97 void ReturnInstr::Print( |
| 98 intptr_t instruction_index, |
| 99 const GrowableArray<Instruction*>& instruction_list) const { |
| 100 OS::Print("return "); |
| 101 value_->Print(); |
| 102 } |
| 103 |
| 104 |
| 105 void BranchInstr::Print( |
| 106 intptr_t instruction_index, |
| 107 const GrowableArray<Instruction*>& instruction_list) const { |
| 108 OS::Print("if "); |
| 109 value_->Print(); |
| 110 // Linear search for the instruction numbers of the successors. |
| 111 intptr_t true_successor_number = -1; |
| 112 intptr_t false_successor_number = -1; |
| 113 for (intptr_t i = 0; i < instruction_list.length(); ++i) { |
| 114 if (instruction_list[i] == true_successor_) { |
| 115 true_successor_number = instruction_list.length() - i; |
| 116 if (false_successor_number >= 0) break; |
| 117 } |
| 118 if (instruction_list[i] == false_successor_) { |
| 119 false_successor_number = instruction_list.length() - i; |
| 120 if (true_successor_number >= 0) break; |
| 121 } |
| 122 } |
| 123 OS::Print(" goto(%d, %d)", true_successor_number, false_successor_number); |
| 124 } |
| 125 |
| 126 |
| 127 void JoinEntryInstr::Print( |
| 128 intptr_t instruction_index, |
| 129 const GrowableArray<Instruction*>& instruction_list) const { |
| 130 OS::Print("[join]"); |
| 131 PrintGotoSuccessor(successor_, instruction_index, instruction_list); |
| 132 } |
| 133 |
| 134 |
| 135 void TargetEntryInstr::Print( |
| 136 intptr_t instruction_index, |
| 137 const GrowableArray<Instruction*>& instruction_list) const { |
| 138 OS::Print("[target]"); |
| 139 PrintGotoSuccessor(successor_, instruction_index, instruction_list); |
| 140 } |
| 141 |
| 142 |
| 143 void DoInstr::Postorder(GrowableArray<Instruction*>* visited) { |
| 144 flip_mark(); |
| 145 if (successor_->mark() != mark()) successor_->Postorder(visited); |
| 146 visited->Add(this); |
| 147 } |
| 148 |
| 149 |
| 150 void BindInstr::Postorder(GrowableArray<Instruction*>* visited) { |
| 151 flip_mark(); |
| 152 if (successor_->mark() != mark()) successor_->Postorder(visited); |
| 153 visited->Add(this); |
| 154 } |
| 155 |
| 156 |
| 157 void ReturnInstr::Postorder(GrowableArray<Instruction*>* visited) { |
| 158 flip_mark(); |
| 159 visited->Add(this); |
| 160 } |
| 161 |
| 162 |
| 163 void BranchInstr::Postorder(GrowableArray<Instruction*>* visited) { |
| 164 flip_mark(); |
| 165 // Visit the false successor before the true successor so they appear in |
| 166 // true/false order in reverse postorder. |
| 167 if (false_successor_->mark() != mark()) { |
| 168 false_successor_->Postorder(visited); |
| 169 } |
| 170 if (true_successor_->mark() != mark()) { |
| 171 true_successor_->Postorder(visited); |
| 172 } |
| 173 visited->Add(this); |
| 174 } |
| 175 |
| 176 |
| 177 void JoinEntryInstr::Postorder(GrowableArray<Instruction*>* visited) { |
| 178 flip_mark(); |
| 179 if (successor_->mark() != mark()) successor_->Postorder(visited); |
| 180 visited->Add(this); |
| 181 } |
| 182 |
| 183 |
| 184 void TargetEntryInstr::Postorder(GrowableArray<Instruction*>* visited) { |
| 185 flip_mark(); |
| 186 if (successor_->mark() != mark()) successor_->Postorder(visited); |
| 187 visited->Add(this); |
| 188 } |
| 189 |
| 190 |
| 191 } // namespace dart |
OLD | NEW |