| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Classes that describe assembly patterns as used by inline caches. | 4 // Classes that describe assembly patterns as used by inline caches. |
| 5 | 5 |
| 6 #ifndef VM_INSTRUCTIONS_ARM_H_ | 6 #ifndef VM_INSTRUCTIONS_ARM_H_ |
| 7 #define VM_INSTRUCTIONS_ARM_H_ | 7 #define VM_INSTRUCTIONS_ARM_H_ |
| 8 | 8 |
| 9 #ifndef VM_INSTRUCTIONS_H_ | 9 #ifndef VM_INSTRUCTIONS_H_ |
| 10 #error Do not include instructions_arm.h directly; use instructions.h instead. | 10 #error Do not include instructions_arm.h directly; use instructions.h instead. |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include "vm/allocation.h" | |
| 14 #include "vm/object.h" | 13 #include "vm/object.h" |
| 15 | 14 |
| 16 namespace dart { | 15 namespace dart { |
| 17 | 16 |
| 18 // Forward declarations. | |
| 19 class RawClass; | |
| 20 class Immediate; | |
| 21 class RawObject; | |
| 22 | |
| 23 // Abstract class for all instruction pattern classes. | 17 // Abstract class for all instruction pattern classes. |
| 24 class InstructionPattern : public ValueObject { | 18 class InstructionPattern : public ValueObject { |
| 25 public: | 19 public: |
| 26 explicit InstructionPattern(uword pc) : end_(pc) { | 20 explicit InstructionPattern(uword pc) : end_(reinterpret_cast<uword*>(pc)) { |
| 27 ASSERT(pc != 0); | 21 ASSERT(pc != 0); |
| 28 } | 22 } |
| 29 virtual ~InstructionPattern() { } | 23 virtual ~InstructionPattern() { } |
| 30 | 24 |
| 31 // Check if the instruction ending at 'end_' matches the expected pattern. | |
| 32 virtual bool IsValid() const { | |
| 33 return TestBytesWith(pattern(), pattern_length_in_bytes()); | |
| 34 } | |
| 35 | |
| 36 // 'pattern' returns the expected byte pattern in form of an integer array | |
| 37 // with length of 'pattern_length_in_bytes'. A '-1' element means 'any byte'. | |
| 38 virtual const int* pattern() const = 0; | |
| 39 virtual int pattern_length_in_bytes() const = 0; | |
| 40 | |
| 41 protected: | 25 protected: |
| 42 uword end() const { return end_; } | 26 uword Back(int n) const; |
| 43 | 27 |
| 44 private: | 28 private: |
| 45 // Returns true if the 'num_bytes' bytes at 'num_bytes' before 'end_' | 29 const uword* end_; |
| 46 // correspond to array of integers 'data'. 'data' elements are either a byte | |
| 47 // or -1, which represents any byte. | |
| 48 bool TestBytesWith(const int* data, int num_bytes) const; | |
| 49 | |
| 50 const uword end_; | |
| 51 | 30 |
| 52 DISALLOW_COPY_AND_ASSIGN(InstructionPattern); | 31 DISALLOW_COPY_AND_ASSIGN(InstructionPattern); |
| 53 }; | 32 }; |
| 54 | 33 |
| 55 | 34 |
| 56 class CallPattern : public InstructionPattern { | 35 class CallPattern : public InstructionPattern { |
| 57 public: | 36 public: |
| 58 CallPattern(uword pc, const Code& code) | 37 CallPattern(uword pc, const Code& code); |
| 59 : InstructionPattern(pc), code_(code) { } | |
| 60 | 38 |
| 61 static const int kLengthInBytes = 1*kWordSize; // We can only match 'blx lr'. | |
| 62 | |
| 63 virtual int pattern_length_in_bytes() const { | |
| 64 return kLengthInBytes; | |
| 65 } | |
| 66 uword TargetAddress() const; | 39 uword TargetAddress() const; |
| 67 void SetTargetAddress(uword new_target) const; | 40 void SetTargetAddress(uword target_address) const; |
| 68 | 41 |
| 69 private: | 42 private: |
| 70 virtual const int* pattern() const; | 43 int DecodePoolIndex(); |
| 71 | 44 const int pool_index_; |
| 72 const Code& code_; | 45 const Array& object_pool_; |
| 73 | 46 |
| 74 DISALLOW_COPY_AND_ASSIGN(CallPattern); | 47 DISALLOW_COPY_AND_ASSIGN(CallPattern); |
| 75 }; | 48 }; |
| 76 | 49 |
| 77 | 50 |
| 78 class JumpPattern : public InstructionPattern { | 51 class JumpPattern : public InstructionPattern { |
| 79 public: | 52 public: |
| 80 explicit JumpPattern(uword pc) : InstructionPattern(pc) { } | 53 explicit JumpPattern(uword pc) : InstructionPattern(pc) { } |
| 81 | 54 |
| 82 static const int kLengthInBytes = 3*kWordSize; | 55 static const int kLengthInBytes = 3*kWordSize; |
| 83 | 56 |
| 84 virtual int pattern_length_in_bytes() const { | 57 int pattern_length_in_bytes() const { |
| 85 return kLengthInBytes; | 58 return kLengthInBytes; |
| 86 } | 59 } |
| 60 bool IsValid() const; |
| 87 uword TargetAddress() const; | 61 uword TargetAddress() const; |
| 88 void SetTargetAddress(uword new_target) const; | 62 void SetTargetAddress(uword target_address) const; |
| 89 | 63 |
| 90 private: | 64 private: |
| 91 virtual const int* pattern() const; | |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(JumpPattern); | 65 DISALLOW_COPY_AND_ASSIGN(JumpPattern); |
| 94 }; | 66 }; |
| 95 | 67 |
| 96 } // namespace dart | 68 } // namespace dart |
| 97 | 69 |
| 98 #endif // VM_INSTRUCTIONS_ARM_H_ | 70 #endif // VM_INSTRUCTIONS_ARM_H_ |
| 99 | 71 |
| OLD | NEW |