summaryrefslogtreecommitdiff
path: root/include/llvm/CodeGen/MachineCodeEmitter.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-05-02 22:51:03 +0000
committerChris Lattner <sabre@nondot.org>2006-05-02 22:51:03 +0000
commit1f4549f35c69376a07360bd57ff06ed8f636d153 (patch)
tree5e93624ad3f2b3e1cf773cdd12acdad8d3496990 /include/llvm/CodeGen/MachineCodeEmitter.h
parenta11a92976a1f299509402525a54e38ccf77a6544 (diff)
downloadllvm-1f4549f35c69376a07360bd57ff06ed8f636d153.tar.gz
llvm-1f4549f35c69376a07360bd57ff06ed8f636d153.tar.bz2
llvm-1f4549f35c69376a07360bd57ff06ed8f636d153.tar.xz
Add a method for allocating space from the code buffer.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28064 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/CodeGen/MachineCodeEmitter.h')
-rw-r--r--include/llvm/CodeGen/MachineCodeEmitter.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/include/llvm/CodeGen/MachineCodeEmitter.h b/include/llvm/CodeGen/MachineCodeEmitter.h
index 58e232d341..d26d7e773f 100644
--- a/include/llvm/CodeGen/MachineCodeEmitter.h
+++ b/include/llvm/CodeGen/MachineCodeEmitter.h
@@ -140,6 +140,28 @@ public:
}
}
+ /// allocateSpace - Allocate a block of space in the current output buffer,
+ /// returning null (and setting conditions to indicate buffer overflow) on
+ /// failure. Alignment is the alignment in bytes of the buffer desired.
+ void *allocateSpace(intptr_t Size, unsigned Alignment) {
+ if (Alignment == 0) Alignment = 1;
+ // Move the current buffer ptr up to the specified alignment.
+ CurBufferPtr =
+ (unsigned char*)(((intptr_t)CurBufferPtr+Alignment-1) & ~(Alignment-1));
+ void *Result = CurBufferPtr;
+
+ // Allocate the space.
+ CurBufferPtr += Size;
+
+ // Check for buffer overflow.
+ if (CurBufferPtr >= BufferEnd) {
+ CurBufferPtr = BufferEnd;
+ Result = 0;
+ }
+ return Result;
+ }
+
+
/// getCurrentPCValue - This returns the address that the next emitted byte
/// will be output to.
///