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

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') | src/IceOperand.cpp » ('J')
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 69faa95f98809635ecb66ffede847d95310957a4..252deeb1bad16f2baa47c89f64f2e94677573bc2 100644
--- a/src/IceAssembler.h
+++ b/src/IceAssembler.h
@@ -63,49 +63,45 @@ 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();
+#ifdef NDEBUG
Karl 2015/06/22 15:41:06 Why not create a boolean (inline) function in IceD
John 2015/06/22 17:13:46 I agree with Karl on this one. Perhaps IceDefs cou
Jim Stichnoth 2015/06/23 21:42:07 Did both, in IceDefs.h: constexpr bool buildAllo
+ return;
+#endif // NDEBUG
+ 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; }
+ bool hasEnsuredCapacity() const {
+#ifdef NDEBUG
Karl 2015/06/22 15:41:06 same here.
John 2015/06/22 17:13:46 This makes me nervous that, with NDEBUG, some comp
+ // Disable the actual check in non-debug mode.
+ return true;
#endif // NDEBUG
+ return HasEnsuredCapacity;
+ }
// Returns the position in the instruction stream.
intptr_t getPosition() const { return Cursor - Contents; }
@@ -124,7 +120,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') | src/IceOperand.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698