Add a new emitAlignment method
[oota-llvm.git] / include / llvm / CodeGen / MachineCodeEmitter.h
index f63d6ed0f422f6c5bdf544f05565f957fbe01d36..43b14ca38f9359ca368aad40e2060f5daab6dfe7 100644 (file)
@@ -18,7 +18,7 @@
 #define LLVM_CODEGEN_MACHINECODEEMITTER_H
 
 #include "llvm/Support/DataTypes.h"
-#include <map>
+#include <vector>
 
 namespace llvm {
 
@@ -76,10 +76,10 @@ public:
   
   /// emitJumpTableInfo - This callback is invoked to output the jump tables
   /// for the function.  In addition to a pointer to the MachineJumpTableInfo,
-  /// this function also takes a map of MBBs to addresses, so that the final
+  /// this function also takes a map of MBB IDs to addresses, so that the final
   /// addresses of the MBBs can be written to the jump tables.
   virtual void emitJumpTableInfo(MachineJumpTableInfo *MJTI,
-                              std::map<MachineBasicBlock*,uint64_t> &MBBM) = 0;
+                                 std::vector<uint64_t> &MBBM) = 0;
   
   /// startFunctionStub - This callback is invoked when the JIT needs the
   /// address of a function that has not been code generated yet.  The StubSize
@@ -130,14 +130,22 @@ 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) {
+  /// emitAlignment - Move the CurBufferPtr pointer up the the specified
+  /// alignment (saturated to BufferEnd of course).
+  void emitAlignment(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));
+    if (CurBufferPtr > BufferEnd)
+      CurBufferPtr = BufferEnd;
+  }
+  
+  /// 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) {
+    emitAlignment(Alignment);
     void *Result = CurBufferPtr;
     
     // Allocate the space.