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