Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: src/IceAssembler.h

Issue 1197863003: Subzero: Reduce the amount of #ifdef'd code. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Cleanup Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/IceAssembler.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceAssembler.h
diff --git a/src/IceAssembler.h b/src/IceAssembler.h
index de4dd869dab99a5e29d2cdbd2568fad7217c77d0..b6ddf08003a4121cce3415282ca6f22117f2e3a3 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) {
+ if (Buffer->cursor() >= Buffer->limit())
+ Buffer->extendCapacity();
+ if (BuildDefs::asserts())
+ validate(Buffer);
+ }
~EnsureCapacity();
private:
AssemblerBuffer *Buffer;
- intptr_t Gap;
+ intptr_t Gap = 0;
+ 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 (BuildDefs::asserts())
+ 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;
« no previous file with comments | « no previous file | src/IceAssembler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698