| 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_ASSEMBLER_H_ | 5 #ifndef VM_ASSEMBLER_H_ |
| 6 #define VM_ASSEMBLER_H_ | 6 #define VM_ASSEMBLER_H_ |
| 7 | 7 |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
| 10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 void EmitObject(const Object& object); | 101 void EmitObject(const Object& object); |
| 102 | 102 |
| 103 // Emit a fixup at the current location. | 103 // Emit a fixup at the current location. |
| 104 void EmitFixup(AssemblerFixup* fixup) { | 104 void EmitFixup(AssemblerFixup* fixup) { |
| 105 fixup->set_previous(fixup_); | 105 fixup->set_previous(fixup_); |
| 106 fixup->set_position(Size()); | 106 fixup->set_position(Size()); |
| 107 fixup_ = fixup; | 107 fixup_ = fixup; |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Get the size of the emitted code. | 110 // Get the size of the emitted code. |
| 111 int Size() const { return cursor_ - contents_; } | 111 intptr_t Size() const { return cursor_ - contents_; } |
| 112 uword contents() const { return contents_; } | 112 uword contents() const { return contents_; } |
| 113 | 113 |
| 114 // Copy the assembled instructions into the specified memory block | 114 // Copy the assembled instructions into the specified memory block |
| 115 // and apply all fixups. | 115 // and apply all fixups. |
| 116 void FinalizeInstructions(const MemoryRegion& region); | 116 void FinalizeInstructions(const MemoryRegion& region); |
| 117 | 117 |
| 118 // To emit an instruction to the assembler buffer, the EnsureCapacity helper | 118 // To emit an instruction to the assembler buffer, the EnsureCapacity helper |
| 119 // must be used to guarantee that the underlying data area is big enough to | 119 // must be used to guarantee that the underlying data area is big enough to |
| 120 // hold the emitted instruction. Usage: | 120 // hold the emitted instruction. Usage: |
| 121 // | 121 // |
| 122 // AssemblerBuffer buffer; | 122 // AssemblerBuffer buffer; |
| 123 // AssemblerBuffer::EnsureCapacity ensured(&buffer); | 123 // AssemblerBuffer::EnsureCapacity ensured(&buffer); |
| 124 // ... emit bytes for single instruction ... | 124 // ... emit bytes for single instruction ... |
| 125 | 125 |
| 126 #if defined(DEBUG) | 126 #if defined(DEBUG) |
| 127 class EnsureCapacity : public ValueObject { | 127 class EnsureCapacity : public ValueObject { |
| 128 public: | 128 public: |
| 129 explicit EnsureCapacity(AssemblerBuffer* buffer); | 129 explicit EnsureCapacity(AssemblerBuffer* buffer); |
| 130 ~EnsureCapacity(); | 130 ~EnsureCapacity(); |
| 131 | 131 |
| 132 private: | 132 private: |
| 133 AssemblerBuffer* buffer_; | 133 AssemblerBuffer* buffer_; |
| 134 int gap_; | 134 intptr_t gap_; |
| 135 | 135 |
| 136 int ComputeGap() { return buffer_->Capacity() - buffer_->Size(); } | 136 intptr_t ComputeGap() { return buffer_->Capacity() - buffer_->Size(); } |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 bool has_ensured_capacity_; | 139 bool has_ensured_capacity_; |
| 140 bool HasEnsuredCapacity() const { return has_ensured_capacity_; } | 140 bool HasEnsuredCapacity() const { return has_ensured_capacity_; } |
| 141 #else | 141 #else |
| 142 class EnsureCapacity : public ValueObject { | 142 class EnsureCapacity : public ValueObject { |
| 143 public: | 143 public: |
| 144 explicit EnsureCapacity(AssemblerBuffer* buffer) { | 144 explicit EnsureCapacity(AssemblerBuffer* buffer) { |
| 145 if (buffer->cursor() >= buffer->limit()) buffer->ExtendCapacity(); | 145 if (buffer->cursor() >= buffer->limit()) buffer->ExtendCapacity(); |
| 146 } | 146 } |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 // When building the C++ tests, assertion code is enabled. To allow | 149 // When building the C++ tests, assertion code is enabled. To allow |
| 150 // asserting that the user of the assembler buffer has ensured the | 150 // asserting that the user of the assembler buffer has ensured the |
| 151 // capacity needed for emitting, we add a dummy method in non-debug mode. | 151 // capacity needed for emitting, we add a dummy method in non-debug mode. |
| 152 bool HasEnsuredCapacity() const { return true; } | 152 bool HasEnsuredCapacity() const { return true; } |
| 153 #endif | 153 #endif |
| 154 | 154 |
| 155 // Returns the position in the instruction stream. | 155 // Returns the position in the instruction stream. |
| 156 int GetPosition() const { return cursor_ - contents_; } | 156 intptr_t GetPosition() const { return cursor_ - contents_; } |
| 157 | 157 |
| 158 private: | 158 private: |
| 159 // The limit is set to kMinimumGap bytes before the end of the data area. | 159 // The limit is set to kMinimumGap bytes before the end of the data area. |
| 160 // This leaves enough space for the longest possible instruction and allows | 160 // This leaves enough space for the longest possible instruction and allows |
| 161 // for a single, fast space check per instruction. | 161 // for a single, fast space check per instruction. |
| 162 static const int kMinimumGap = 32; | 162 static const intptr_t kMinimumGap = 32; |
| 163 | 163 |
| 164 uword contents_; | 164 uword contents_; |
| 165 uword cursor_; | 165 uword cursor_; |
| 166 uword limit_; | 166 uword limit_; |
| 167 AssemblerFixup* fixup_; | 167 AssemblerFixup* fixup_; |
| 168 ZoneGrowableArray<int>* pointer_offsets_; | 168 ZoneGrowableArray<int>* pointer_offsets_; |
| 169 #if defined(DEBUG) | 169 #if defined(DEBUG) |
| 170 bool fixups_processed_; | 170 bool fixups_processed_; |
| 171 #endif | 171 #endif |
| 172 | 172 |
| 173 uword cursor() const { return cursor_; } | 173 uword cursor() const { return cursor_; } |
| 174 uword limit() const { return limit_; } | 174 uword limit() const { return limit_; } |
| 175 int Capacity() const { | 175 intptr_t Capacity() const { |
| 176 ASSERT(limit_ >= contents_); | 176 ASSERT(limit_ >= contents_); |
| 177 return (limit_ - contents_) + kMinimumGap; | 177 return (limit_ - contents_) + kMinimumGap; |
| 178 } | 178 } |
| 179 | 179 |
| 180 // Process the fixup chain. | 180 // Process the fixup chain. |
| 181 void ProcessFixups(const MemoryRegion& region); | 181 void ProcessFixups(const MemoryRegion& region); |
| 182 | 182 |
| 183 // Compute the limit based on the data area and the capacity. See | 183 // Compute the limit based on the data area and the capacity. See |
| 184 // description of kMinimumGap for the reasoning behind the value. | 184 // description of kMinimumGap for the reasoning behind the value. |
| 185 static uword ComputeLimit(uword data, int capacity) { | 185 static uword ComputeLimit(uword data, intptr_t capacity) { |
| 186 return data + capacity - kMinimumGap; | 186 return data + capacity - kMinimumGap; |
| 187 } | 187 } |
| 188 | 188 |
| 189 void ExtendCapacity(); | 189 void ExtendCapacity(); |
| 190 | 190 |
| 191 friend class AssemblerFixup; | 191 friend class AssemblerFixup; |
| 192 }; | 192 }; |
| 193 | 193 |
| 194 } // namespace dart | 194 } // namespace dart |
| 195 | 195 |
| 196 | 196 |
| 197 #if defined(TARGET_ARCH_IA32) | 197 #if defined(TARGET_ARCH_IA32) |
| 198 #include "vm/assembler_ia32.h" | 198 #include "vm/assembler_ia32.h" |
| 199 #elif defined(TARGET_ARCH_X64) | 199 #elif defined(TARGET_ARCH_X64) |
| 200 #include "vm/assembler_x64.h" | 200 #include "vm/assembler_x64.h" |
| 201 #elif defined(TARGET_ARCH_ARM) | 201 #elif defined(TARGET_ARCH_ARM) |
| 202 #include "vm/assembler_arm.h" | 202 #include "vm/assembler_arm.h" |
| 203 #else | 203 #else |
| 204 #error Unknown architecture. | 204 #error Unknown architecture. |
| 205 #endif | 205 #endif |
| 206 | 206 |
| 207 #endif // VM_ASSEMBLER_H_ | 207 #endif // VM_ASSEMBLER_H_ |
| OLD | NEW |