Index: src/IceAssembler.h |
diff --git a/src/IceAssembler.h b/src/IceAssembler.h |
index de4dd869dab99a5e29d2cdbd2568fad7217c77d0..9b1c58a0c8dbab788d473322db5f66581c5fa772 100644 |
--- a/src/IceAssembler.h |
+++ b/src/IceAssembler.h |
@@ -63,49 +63,42 @@ public: |
intptr_t size() const { return Cursor - Contents; } |
uintptr_t contents() const { return Contents; } |
-// To emit an instruction to the assembler buffer, the EnsureCapacity helper |
-// must be used to guarantee that the underlying data area is big enough to |
-// hold the emitted instruction. Usage: |
-// |
-// AssemblerBuffer buffer; |
-// AssemblerBuffer::EnsureCapacity ensured(&buffer); |
-// ... emit bytes for single instruction ... |
+ // To emit an instruction to the assembler buffer, the EnsureCapacity helper |
+ // must be used to guarantee that the underlying data area is big enough to |
+ // hold the emitted instruction. Usage: |
+ // |
+ // AssemblerBuffer buffer; |
+ // AssemblerBuffer::EnsureCapacity ensured(&buffer); |
+ // ... emit bytes for single instruction ... |
-#ifndef NDEBUG |
class EnsureCapacity { |
EnsureCapacity(const EnsureCapacity &) = delete; |
EnsureCapacity &operator=(const EnsureCapacity &) = delete; |
public: |
- explicit EnsureCapacity(AssemblerBuffer *Buffer); |
+ explicit EnsureCapacity(AssemblerBuffer *Buffer) : Buffer(Buffer), Gap(0) { |
+ if (Buffer->cursor() >= Buffer->limit()) |
+ Buffer->extendCapacity(); |
+ if (buildAllowsAsserts()) |
+ validate(Buffer); |
+ } |
~EnsureCapacity(); |
private: |
AssemblerBuffer *Buffer; |
intptr_t Gap; |
+ void validate(AssemblerBuffer *Buffer); |
intptr_t computeGap() { return Buffer->capacity() - Buffer->size(); } |
}; |
bool HasEnsuredCapacity; |
- bool hasEnsuredCapacity() const { return HasEnsuredCapacity; } |
-#else // NDEBUG |
- class EnsureCapacity { |
- EnsureCapacity(const EnsureCapacity &) = delete; |
- EnsureCapacity &operator=(const EnsureCapacity &) = delete; |
- |
- public: |
- explicit EnsureCapacity(AssemblerBuffer *Buffer) { |
- if (Buffer->cursor() >= Buffer->limit()) |
- Buffer->extendCapacity(); |
- } |
- }; |
- |
- // When building the C++ tests, assertion code is enabled. To allow |
- // asserting that the user of the assembler buffer has ensured the |
- // capacity needed for emitting, we add a dummy method in non-debug mode. |
- bool hasEnsuredCapacity() const { return true; } |
-#endif // NDEBUG |
+ bool hasEnsuredCapacity() const { |
+ if (buildAllowsAsserts()) |
+ return HasEnsuredCapacity; |
+ // Disable the actual check in non-debug mode. |
+ return true; |
+ } |
// Returns the position in the instruction stream. |
intptr_t getPosition() const { return Cursor - Contents; } |
@@ -124,7 +117,7 @@ private: |
// The limit is set to kMinimumGap bytes before the end of the data area. |
// This leaves enough space for the longest possible instruction and allows |
// for a single, fast space check per instruction. |
- static const intptr_t kMinimumGap = 32; |
+ static constexpr intptr_t kMinimumGap = 32; |
uintptr_t Contents; |
uintptr_t Cursor; |