Index: include/llvm/CodeGen/MachineCodeEmitter.h |
=================================================================== |
--- include/llvm/CodeGen/MachineCodeEmitter.h (revision 89159) |
+++ include/llvm/CodeGen/MachineCodeEmitter.h (working copy) |
@@ -48,18 +48,42 @@ |
/// occurred, more memory is allocated, and we reemit the code into it. |
/// |
class MachineCodeEmitter { |
+public: |
+ class BufferState { |
+ friend class MachineCodeEmitter; |
+ /// BufferBegin/BufferEnd - Pointers to the start and end of the memory |
+ /// allocated for this code buffer. |
+ uint8_t *BufferBegin, *BufferEnd; |
+ |
+ /// CurBufferPtr - Pointer to the next byte of memory to fill when emitting |
+ /// code. This is guranteed to be in the range [BufferBegin,BufferEnd]. If |
+ /// this pointer is at BufferEnd, it will never move due to code emission, |
+ /// and all code emission requests will be ignored (this is the buffer |
+ /// overflow condition). |
+ uint8_t *CurBufferPtr; |
+ public: |
+ BufferState() : BufferBegin(NULL), BufferEnd(NULL), CurBufferPtr(NULL) {} |
+ }; |
+ |
protected: |
- /// BufferBegin/BufferEnd - Pointers to the start and end of the memory |
- /// allocated for this code buffer. |
- uint8_t *BufferBegin, *BufferEnd; |
- |
- /// CurBufferPtr - Pointer to the next byte of memory to fill when emitting |
- /// code. This is guranteed to be in the range [BufferBegin,BufferEnd]. If |
- /// this pointer is at BufferEnd, it will never move due to code emission, and |
- /// all code emission requests will be ignored (this is the buffer overflow |
- /// condition). |
- uint8_t *CurBufferPtr; |
+ /// These have the same meanings as the fields in BufferState |
+ uint8_t *BufferBegin, *BufferEnd, *CurBufferPtr; |
+ /// Save or restore the current buffer state. The BufferState objects must be |
+ /// used as a stack. |
+ void SaveStateTo(BufferState &BS) { |
+ assert(BS.BufferBegin == NULL && |
+ "Can't save state into the same BufferState twice."); |
+ BS.BufferBegin = BufferBegin; |
+ BS.BufferEnd = BufferEnd; |
+ BS.CurBufferPtr = CurBufferPtr; |
+ } |
+ void RestoreStateFrom(BufferState &BS) { |
+ BufferBegin = BS.BufferBegin; |
+ BufferEnd = BS.BufferEnd; |
+ CurBufferPtr = BS.CurBufferPtr; |
+ } |
+ |
public: |
virtual ~MachineCodeEmitter() {} |