| OLD | NEW |
| 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 #ifndef VM_INTERMEDIATE_LANGUAGE_H_ | 5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_ |
| 6 #define VM_INTERMEDIATE_LANGUAGE_H_ | 6 #define VM_INTERMEDIATE_LANGUAGE_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/ast.h" | 9 #include "vm/ast.h" |
| 10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
| 11 #include "vm/handles_impl.h" | 11 #include "vm/handles_impl.h" |
| 12 #include "vm/object.h" | 12 #include "vm/object.h" |
| 13 | 13 |
| 14 namespace dart { | 14 namespace dart { |
| 15 | 15 |
| 16 class FlowGraphVisitor; | 16 class FlowGraphVisitor; |
| 17 class LocalVariable; | 17 class LocalVariable; |
| 18 | 18 |
| 19 // Computations and values. | 19 // Computations and values. |
| 20 // | 20 // |
| 21 // <Computation> ::= | 21 // <Computation> ::= |
| 22 // <Value> | 22 // <Value> |
| 23 // | CopyTemp <int> |
| 24 // | SetTemp <int> |
| 23 // | AssertAssignable <Value> <AbstractType> | 25 // | AssertAssignable <Value> <AbstractType> |
| 24 // | InstanceCall <AstNode> <String> <Value> ... | 26 // | InstanceCall <AstNode> <String> <Value> ... |
| 25 // | StaticCall <StaticCallNode> <Value> ... | 27 // | StaticCall <StaticCallNode> <Value> ... |
| 26 // | LoadLocal <LocalVariable> | 28 // | LoadLocal <LocalVariable> |
| 27 // | StoreLocal <LocalVariable> <Value> | 29 // | StoreLocal <LocalVariable> <Value> |
| 28 // | StrictCompare <Token::kind> <Value> <Value> | 30 // | StrictCompare <Token::kind> <Value> <Value> |
| 29 // | NativeCall <NativeBodyNode> | 31 // | NativeCall <NativeBodyNode> |
| 30 // | StoreIndexed <StoreIndexedNode> <Value> <Value> <Value> | 32 // | StoreIndexed <StoreIndexedNode> <Value> <Value> <Value> |
| 31 // | InstanceSetter <InstanceSetterNode> <Value> <Value> | 33 // | InstanceSetter <InstanceSetterNode> <Value> <Value> |
| 32 // | 34 // |
| 33 // <Value> ::= | 35 // <Value> ::= |
| 34 // Temp <int> | 36 // Temp <int> |
| 35 // | Constant <Instance> | 37 // | Constant <Instance> |
| 36 | 38 |
| 37 // M is a two argument macro. It is applied to each concrete value's | 39 // M is a two argument macro. It is applied to each concrete value's |
| 38 // typename and classname. | 40 // typename and classname. |
| 39 #define FOR_EACH_VALUE(M) \ | 41 #define FOR_EACH_VALUE(M) \ |
| 40 M(Temp, TempVal) \ | 42 M(Temp, TempVal) \ |
| 41 M(Constant, ConstantVal) \ | 43 M(Constant, ConstantVal) \ |
| 42 | 44 |
| 43 | 45 |
| 44 // M is a two argument macro. It is applied to each concrete instruction's | 46 // M is a two argument macro. It is applied to each concrete instruction's |
| 45 // (including the values) typename and classname. | 47 // (including the values) typename and classname. |
| 46 #define FOR_EACH_COMPUTATION(M) \ | 48 #define FOR_EACH_COMPUTATION(M) \ |
| 47 FOR_EACH_VALUE(M) \ | 49 FOR_EACH_VALUE(M) \ |
| 50 M(CopyTemp, CopyTempComp) \ |
| 51 M(SetTemp, SetTempComp) \ |
| 48 M(AssertAssignable, AssertAssignableComp) \ | 52 M(AssertAssignable, AssertAssignableComp) \ |
| 49 M(InstanceCall, InstanceCallComp) \ | 53 M(InstanceCall, InstanceCallComp) \ |
| 50 M(StaticCall, StaticCallComp) \ | 54 M(StaticCall, StaticCallComp) \ |
| 51 M(LoadLocal, LoadLocalComp) \ | 55 M(LoadLocal, LoadLocalComp) \ |
| 52 M(StoreLocal, StoreLocalComp) \ | 56 M(StoreLocal, StoreLocalComp) \ |
| 53 M(StrictCompare, StrictCompareComp) \ | 57 M(StrictCompare, StrictCompareComp) \ |
| 54 M(NativeCall, NativeCallComp) \ | 58 M(NativeCall, NativeCallComp) \ |
| 55 M(StoreIndexed, StoreIndexedComp) \ | 59 M(StoreIndexed, StoreIndexedComp) \ |
| 56 M(InstanceSetter, InstanceSetterComp) \ | 60 M(InstanceSetter, InstanceSetterComp) \ |
| 57 | 61 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 129 |
| 126 private: | 130 private: |
| 127 const Instance& instance_; | 131 const Instance& instance_; |
| 128 | 132 |
| 129 DISALLOW_COPY_AND_ASSIGN(ConstantVal); | 133 DISALLOW_COPY_AND_ASSIGN(ConstantVal); |
| 130 }; | 134 }; |
| 131 | 135 |
| 132 #undef DECLARE_VALUE | 136 #undef DECLARE_VALUE |
| 133 | 137 |
| 134 | 138 |
| 139 // A computation that produces a copy of a (random-access) temporary. The |
| 140 // index is relative to the last temporary allocated (e.g., the last |
| 141 // temporary is index 0, the one before that is -1, etc.). This instruction |
| 142 // is used in the non-optimizing backend and compiled away in the optimizing |
| 143 // backend. |
| 144 class CopyTempComp : public Computation { |
| 145 public: |
| 146 explicit CopyTempComp(intptr_t index) : index_(index) { } |
| 147 |
| 148 DECLARE_COMPUTATION(CopyTemp) |
| 149 |
| 150 intptr_t index() const { return index_; } |
| 151 |
| 152 private: |
| 153 const intptr_t index_; |
| 154 |
| 155 DISALLOW_COPY_AND_ASSIGN(CopyTempComp); |
| 156 }; |
| 157 |
| 158 |
| 159 // A computation that assigns (a duplicate of) the last allocated temporary |
| 160 // to a random-access already allocated temporary. The index is relative to |
| 161 // the last temporary allocated (e.g., the last temporary is index 0, the |
| 162 // one before that is -1, etc.). This instruction is used in the |
| 163 // non-optimizing backend and compiled away in the optimizing backend. |
| 164 class SetTempComp : public Computation { |
| 165 public: |
| 166 explicit SetTempComp(intptr_t index) : index_(index) { } |
| 167 |
| 168 DECLARE_COMPUTATION(SetTemp) |
| 169 |
| 170 intptr_t index() const { return index_; } |
| 171 |
| 172 private: |
| 173 const intptr_t index_; |
| 174 |
| 175 DISALLOW_COPY_AND_ASSIGN(SetTempComp); |
| 176 }; |
| 177 |
| 178 |
| 135 class AssertAssignableComp : public Computation { | 179 class AssertAssignableComp : public Computation { |
| 136 public: | 180 public: |
| 137 AssertAssignableComp(Value* value, const AbstractType& type) | 181 AssertAssignableComp(Value* value, const AbstractType& type) |
| 138 : value_(value), type_(type) { } | 182 : value_(value), type_(type) { } |
| 139 | 183 |
| 140 DECLARE_COMPUTATION(AssertAssignable) | 184 DECLARE_COMPUTATION(AssertAssignable) |
| 141 | 185 |
| 142 Value* value() const { return value_; } | 186 Value* value() const { return value_; } |
| 143 const AbstractType& type() const { return type_; } | 187 const AbstractType& type() const { return type_; } |
| 144 | 188 |
| 145 private: | 189 private: |
| 146 Value* value_; | 190 Value* value_; |
| 147 const AbstractType& type_; | 191 const AbstractType& type_; |
| 148 | 192 |
| 149 DISALLOW_COPY_AND_ASSIGN(AssertAssignableComp); | 193 DISALLOW_COPY_AND_ASSIGN(AssertAssignableComp); |
| 150 }; | 194 }; |
| 151 | 195 |
| 152 | 196 |
| 153 class InstanceCallComp : public Computation { | 197 class InstanceCallComp : public Computation { |
| 154 public: | 198 public: |
| 155 InstanceCallComp(AstNode* node, | 199 InstanceCallComp(intptr_t node_id, |
| 200 intptr_t token_index, |
| 156 const String& function_name, | 201 const String& function_name, |
| 157 ZoneGrowableArray<Value*>* arguments, | 202 ZoneGrowableArray<Value*>* arguments, |
| 158 const Array& argument_names, | 203 const Array& argument_names, |
| 159 intptr_t checked_argument_count) | 204 intptr_t checked_argument_count) |
| 160 : ast_node_(*node), | 205 : node_id_(node_id), |
| 206 token_index_(token_index), |
| 161 function_name_(function_name), | 207 function_name_(function_name), |
| 162 arguments_(arguments), | 208 arguments_(arguments), |
| 163 argument_names_(argument_names), | 209 argument_names_(argument_names), |
| 164 checked_argument_count_(checked_argument_count) { | 210 checked_argument_count_(checked_argument_count) { |
| 165 ASSERT(function_name.IsZoneHandle()); | 211 ASSERT(function_name.IsZoneHandle()); |
| 166 ASSERT(!arguments->is_empty()); | 212 ASSERT(!arguments->is_empty()); |
| 167 ASSERT(argument_names.IsZoneHandle()); | 213 ASSERT(argument_names.IsZoneHandle()); |
| 168 } | 214 } |
| 169 | 215 |
| 170 DECLARE_COMPUTATION(InstanceCall) | 216 DECLARE_COMPUTATION(InstanceCall) |
| 171 | 217 |
| 172 // Accessors forwarded to the AST node. | 218 intptr_t node_id() const { return node_id_; } |
| 173 intptr_t node_id() const { return ast_node_.id(); } | 219 intptr_t token_index() const { return token_index_; } |
| 174 intptr_t token_index() const { return ast_node_.token_index(); } | |
| 175 | |
| 176 const String& function_name() const { return function_name_; } | 220 const String& function_name() const { return function_name_; } |
| 177 int ArgumentCount() const { return arguments_->length(); } | 221 int ArgumentCount() const { return arguments_->length(); } |
| 178 Value* ArgumentAt(int index) const { return (*arguments_)[index]; } | 222 Value* ArgumentAt(int index) const { return (*arguments_)[index]; } |
| 179 const Array& argument_names() const { return argument_names_; } | 223 const Array& argument_names() const { return argument_names_; } |
| 180 intptr_t checked_argument_count() const { return checked_argument_count_; } | 224 intptr_t checked_argument_count() const { return checked_argument_count_; } |
| 181 | 225 |
| 182 private: | 226 private: |
| 183 const AstNode& ast_node_; | 227 const intptr_t node_id_; |
| 228 const intptr_t token_index_; |
| 184 const String& function_name_; | 229 const String& function_name_; |
| 185 ZoneGrowableArray<Value*>* const arguments_; | 230 ZoneGrowableArray<Value*>* const arguments_; |
| 186 const Array& argument_names_; | 231 const Array& argument_names_; |
| 187 const intptr_t checked_argument_count_; | 232 const intptr_t checked_argument_count_; |
| 188 | 233 |
| 189 DISALLOW_COPY_AND_ASSIGN(InstanceCallComp); | 234 DISALLOW_COPY_AND_ASSIGN(InstanceCallComp); |
| 190 }; | 235 }; |
| 191 | 236 |
| 192 | 237 |
| 193 class StrictCompareComp : public Computation { | 238 class StrictCompareComp : public Computation { |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 #undef DECLARE_VISIT_INSTRUCTION | 664 #undef DECLARE_VISIT_INSTRUCTION |
| 620 | 665 |
| 621 private: | 666 private: |
| 622 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 667 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
| 623 }; | 668 }; |
| 624 | 669 |
| 625 | 670 |
| 626 } // namespace dart | 671 } // namespace dart |
| 627 | 672 |
| 628 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 673 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |