| OLD | NEW |
| 1 //===- subzero/src/IceAssembler.cpp - Assembler base class ----------------===// | 1 //===- subzero/src/IceAssembler.cpp - Assembler base class ----------------===// |
| 2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
| 4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
| 5 // | 5 // |
| 6 // Modified by the Subzero authors. | 6 // Modified by the Subzero authors. |
| 7 // | 7 // |
| 8 // This is forked from Dart revision 39313. | 8 // This is forked from Dart revision 39313. |
| 9 // Please update the revision if we merge back changes from Dart. | 9 // Please update the revision if we merge back changes from Dart. |
| 10 // https://code.google.com/p/dart/wiki/GettingTheSource | 10 // https://code.google.com/p/dart/wiki/GettingTheSource |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 AssemblerFixup *F = | 38 AssemblerFixup *F = |
| 39 new (Assemblr.allocate<AssemblerFixup>()) AssemblerFixup(); | 39 new (Assemblr.allocate<AssemblerFixup>()) AssemblerFixup(); |
| 40 F->set_position(0); | 40 F->set_position(0); |
| 41 F->set_kind(Kind); | 41 F->set_kind(Kind); |
| 42 F->set_value(Value); | 42 F->set_value(Value); |
| 43 if (!Assemblr.getPreliminary()) | 43 if (!Assemblr.getPreliminary()) |
| 44 Fixups.push_back(F); | 44 Fixups.push_back(F); |
| 45 return F; | 45 return F; |
| 46 } | 46 } |
| 47 | 47 |
| 48 #ifndef NDEBUG | 48 void AssemblerBuffer::EnsureCapacity::validate(AssemblerBuffer *buffer) { |
| 49 AssemblerBuffer::EnsureCapacity::EnsureCapacity(AssemblerBuffer *buffer) { | |
| 50 if (buffer->cursor() >= buffer->limit()) | |
| 51 buffer->extendCapacity(); | |
| 52 // In debug mode, we save the assembler buffer along with the gap | 49 // In debug mode, we save the assembler buffer along with the gap |
| 53 // size before we start emitting to the buffer. This allows us to | 50 // size before we start emitting to the buffer. This allows us to |
| 54 // check that any single generated instruction doesn't overflow the | 51 // check that any single generated instruction doesn't overflow the |
| 55 // limit implied by the minimum gap size. | 52 // limit implied by the minimum gap size. |
| 56 Buffer = buffer; | |
| 57 Gap = computeGap(); | 53 Gap = computeGap(); |
| 58 // Make sure that extending the capacity leaves a big enough gap | 54 // Make sure that extending the capacity leaves a big enough gap |
| 59 // for any kind of instruction. | 55 // for any kind of instruction. |
| 60 assert(Gap >= kMinimumGap); | 56 assert(Gap >= kMinimumGap); |
| 61 // Mark the buffer as having ensured the capacity. | 57 // Mark the buffer as having ensured the capacity. |
| 62 assert(!buffer->hasEnsuredCapacity()); // Cannot nest. | 58 assert(!buffer->hasEnsuredCapacity()); // Cannot nest. |
| 63 buffer->HasEnsuredCapacity = true; | 59 buffer->HasEnsuredCapacity = true; |
| 64 } | 60 } |
| 65 | 61 |
| 66 AssemblerBuffer::EnsureCapacity::~EnsureCapacity() { | 62 AssemblerBuffer::EnsureCapacity::~EnsureCapacity() { |
| 67 // Unmark the buffer, so we cannot emit after this. | 63 // Unmark the buffer, so we cannot emit after this. |
| 68 Buffer->HasEnsuredCapacity = false; | 64 Buffer->HasEnsuredCapacity = false; |
| 69 // Make sure the generated instruction doesn't take up more | 65 // Make sure the generated instruction doesn't take up more |
| 70 // space than the minimum gap. | 66 // space than the minimum gap. |
| 71 intptr_t delta = Gap - computeGap(); | 67 intptr_t delta = Gap - computeGap(); |
| 68 (void)delta; |
| 72 assert(delta <= kMinimumGap); | 69 assert(delta <= kMinimumGap); |
| 73 } | 70 } |
| 74 #endif // !NDEBUG | |
| 75 | 71 |
| 76 AssemblerBuffer::AssemblerBuffer(Assembler &Asm) : Assemblr(Asm) { | 72 AssemblerBuffer::AssemblerBuffer(Assembler &Asm) : Assemblr(Asm) { |
| 77 const intptr_t OneKB = 1024; | 73 const intptr_t OneKB = 1024; |
| 78 static const intptr_t kInitialBufferCapacity = 4 * OneKB; | 74 static const intptr_t kInitialBufferCapacity = 4 * OneKB; |
| 79 Contents = NewContents(Assemblr, kInitialBufferCapacity); | 75 Contents = NewContents(Assemblr, kInitialBufferCapacity); |
| 80 Cursor = Contents; | 76 Cursor = Contents; |
| 81 Limit = computeLimit(Contents, kInitialBufferCapacity); | 77 Limit = computeLimit(Contents, kInitialBufferCapacity); |
| 82 #ifndef NDEBUG | |
| 83 HasEnsuredCapacity = false; | 78 HasEnsuredCapacity = false; |
| 84 #endif // !NDEBUG | |
| 85 | 79 |
| 86 // Verify internal state. | 80 // Verify internal state. |
| 87 assert(capacity() == kInitialBufferCapacity); | 81 assert(capacity() == kInitialBufferCapacity); |
| 88 assert(size() == 0); | 82 assert(size() == 0); |
| 89 } | 83 } |
| 90 | 84 |
| 91 AssemblerBuffer::~AssemblerBuffer() {} | 85 AssemblerBuffer::~AssemblerBuffer() {} |
| 92 | 86 |
| 93 void AssemblerBuffer::extendCapacity() { | 87 void AssemblerBuffer::extendCapacity() { |
| 94 intptr_t old_size = size(); | 88 intptr_t old_size = size(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 } | 139 } |
| 146 // Handle any bytes that are not prefixed by a fixup. | 140 // Handle any bytes that are not prefixed by a fixup. |
| 147 for (intptr_t i = CurPosition; i < EndPosition; ++i) { | 141 for (intptr_t i = CurPosition; i < EndPosition; ++i) { |
| 148 Str << "\t.byte 0x"; | 142 Str << "\t.byte 0x"; |
| 149 Str.write_hex(Buffer.load<uint8_t>(i)); | 143 Str.write_hex(Buffer.load<uint8_t>(i)); |
| 150 Str << "\n"; | 144 Str << "\n"; |
| 151 } | 145 } |
| 152 } | 146 } |
| 153 | 147 |
| 154 } // end of namespace Ice | 148 } // end of namespace Ice |
| OLD | NEW |