| 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/growable_array.h" | 9 #include "vm/growable_array.h" |
| 10 #include "vm/handles_impl.h" | 10 #include "vm/handles_impl.h" |
| 11 #include "vm/object.h" | 11 #include "vm/object.h" |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 | 14 |
| 15 class LocalVariable; | 15 class LocalVariable; |
| 16 class ConstantValue; |
| 17 class TempValue; |
| 16 | 18 |
| 17 // Computations and values. | 19 // Computations and values. |
| 18 // | 20 // |
| 19 // <Computation> ::= <Value> | 21 // <Computation> ::= <Value> |
| 20 // | AssertAssignable <Value> <AbstractType> | 22 // | AssertAssignable <Value> <AbstractType> |
| 21 // | InstanceCall <cstring> <Value> ... | 23 // | InstanceCall <cstring> <Value> ... |
| 22 // | StaticCall <Function> <Value> ... | 24 // | StaticCall <Function> <Value> ... |
| 23 // | LoadLocal <LocalVariable> | 25 // | LoadLocal <LocalVariable> |
| 24 // | StoreLocal <LocalVariable> <Value> | 26 // | StoreLocal <LocalVariable> <Value> |
| 25 // | 27 // |
| 26 // <Value> ::= Temp <int> | 28 // <Value> ::= Temp <int> |
| 27 // | Constant <Instance> | 29 // | Constant <Instance> |
| 28 | 30 |
| 29 class Computation : public ZoneAllocated { | 31 class Computation : public ZoneAllocated { |
| 30 public: | 32 public: |
| 31 Computation() { } | 33 Computation() { } |
| 32 | 34 |
| 33 // Prints a computation without indentation or trailing newlines. | 35 // Prints a computation without indentation or trailing newlines. |
| 34 virtual void Print() const = 0; | 36 virtual void Print() const = 0; |
| 35 | 37 |
| 36 private: | 38 private: |
| 37 DISALLOW_COPY_AND_ASSIGN(Computation); | 39 DISALLOW_COPY_AND_ASSIGN(Computation); |
| 38 }; | 40 }; |
| 39 | 41 |
| 40 | 42 |
| 41 class Value : public Computation { | 43 class Value : public Computation { |
| 42 public: | 44 public: |
| 43 Value() { } | 45 Value() { } |
| 44 | 46 |
| 47 virtual TempValue* AsTemp() { return NULL; } |
| 48 virtual ConstantValue* AsConstant() { return NULL; } |
| 49 |
| 50 bool IsTemp() { return AsTemp() != NULL; } |
| 51 bool IsConstant() { return AsConstant() != NULL; } |
| 52 |
| 45 private: | 53 private: |
| 46 DISALLOW_COPY_AND_ASSIGN(Value); | 54 DISALLOW_COPY_AND_ASSIGN(Value); |
| 47 }; | 55 }; |
| 48 | 56 |
| 49 | 57 |
| 50 class AssertAssignableComp : public Computation { | 58 class AssertAssignableComp : public Computation { |
| 51 public: | 59 public: |
| 52 AssertAssignableComp(Value* value, const AbstractType& type) | 60 AssertAssignableComp(Value* value, const AbstractType& type) |
| 53 : value_(value), type_(type) { } | 61 : value_(value), type_(type) { } |
| 54 | 62 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 Value* value_; | 127 Value* value_; |
| 120 | 128 |
| 121 DISALLOW_COPY_AND_ASSIGN(StoreLocalComp); | 129 DISALLOW_COPY_AND_ASSIGN(StoreLocalComp); |
| 122 }; | 130 }; |
| 123 | 131 |
| 124 | 132 |
| 125 class TempValue : public Value { | 133 class TempValue : public Value { |
| 126 public: | 134 public: |
| 127 explicit TempValue(intptr_t index) : index_(index) { } | 135 explicit TempValue(intptr_t index) : index_(index) { } |
| 128 | 136 |
| 137 virtual TempValue* AsTemp() { return this; } |
| 129 virtual void Print() const; | 138 virtual void Print() const; |
| 130 | 139 |
| 131 private: | 140 private: |
| 132 intptr_t index_; | 141 intptr_t index_; |
| 133 | 142 |
| 134 DISALLOW_COPY_AND_ASSIGN(TempValue); | 143 DISALLOW_COPY_AND_ASSIGN(TempValue); |
| 135 }; | 144 }; |
| 136 | 145 |
| 137 | 146 |
| 138 class ConstantValue: public Value { | 147 class ConstantValue: public Value { |
| 139 public: | 148 public: |
| 140 explicit ConstantValue(const Instance& instance) : instance_(instance) { } | 149 explicit ConstantValue(const Instance& instance) : instance_(instance) { } |
| 141 | 150 |
| 151 virtual ConstantValue* AsConstant() { return this; } |
| 142 virtual void Print() const; | 152 virtual void Print() const; |
| 143 | 153 |
| 154 const Instance& instance() const { return instance_; } |
| 155 |
| 144 private: | 156 private: |
| 145 const Instance& instance_; | 157 const Instance& instance_; |
| 146 | 158 |
| 147 DISALLOW_COPY_AND_ASSIGN(ConstantValue); | 159 DISALLOW_COPY_AND_ASSIGN(ConstantValue); |
| 148 }; | 160 }; |
| 149 | 161 |
| 150 | 162 |
| 151 // Instructions. | 163 // Instructions. |
| 152 // | 164 // |
| 153 // <Instruction> ::= Do <Computation> <Instruction> | 165 // <Instruction> ::= Do <Computation> <Instruction> |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 #undef DECLARE_INSTRUCTION | 385 #undef DECLARE_INSTRUCTION |
| 374 | 386 |
| 375 | 387 |
| 376 class InstructionVisitor { | 388 class InstructionVisitor { |
| 377 public: | 389 public: |
| 378 InstructionVisitor() { } | 390 InstructionVisitor() { } |
| 379 virtual ~InstructionVisitor() { } | 391 virtual ~InstructionVisitor() { } |
| 380 | 392 |
| 381 // Visit each block in the array list in reverse, and for each block its | 393 // Visit each block in the array list in reverse, and for each block its |
| 382 // instructions in order from the block entry to exit. | 394 // instructions in order from the block entry to exit. |
| 383 void VisitBlocks(const GrowableArray<BlockEntryInstr*>& block_order); | 395 virtual void VisitBlocks(const GrowableArray<BlockEntryInstr*>& block_order); |
| 384 | 396 |
| 385 #define DECLARE_VISIT(type) \ | 397 #define DECLARE_VISIT(type) \ |
| 386 virtual void Visit##type(type##Instr* instr) { } | 398 virtual void Visit##type(type##Instr* instr) { } |
| 387 FOR_EACH_INSTRUCTION(DECLARE_VISIT) | 399 FOR_EACH_INSTRUCTION(DECLARE_VISIT) |
| 388 #undef DECLARE_VISIT | 400 #undef DECLARE_VISIT |
| 389 | 401 |
| 390 private: | 402 private: |
| 391 DISALLOW_COPY_AND_ASSIGN(InstructionVisitor); | 403 DISALLOW_COPY_AND_ASSIGN(InstructionVisitor); |
| 392 }; | 404 }; |
| 393 | 405 |
| 394 | 406 |
| 395 } // namespace dart | 407 } // namespace dart |
| 396 | 408 |
| 397 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 409 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |