#include <string>
#include "llvm/Support/DataTypes.h"
-#include "llvm/Support/Streams.h"
#include "llvm/CodeGen/MachineCodeEmitter.h"
using namespace std;
/// emitByte - This callback is invoked when a byte needs to be written to the
/// output stream.
///
- void emitByte(unsigned char B) {
+ void emitByte(uint8_t B) {
if (CurBufferPtr != BufferEnd)
*CurBufferPtr++ = B;
}
/// emitWordLE - This callback is invoked when a 32-bit word needs to be
/// written to the output stream in little-endian format.
///
- void emitWordLE(unsigned W) {
+ void emitWordLE(uint32_t W) {
if (4 <= BufferEnd-CurBufferPtr) {
- *CurBufferPtr++ = (unsigned char)(W >> 0);
- *CurBufferPtr++ = (unsigned char)(W >> 8);
- *CurBufferPtr++ = (unsigned char)(W >> 16);
- *CurBufferPtr++ = (unsigned char)(W >> 24);
+ *CurBufferPtr++ = (uint8_t)(W >> 0);
+ *CurBufferPtr++ = (uint8_t)(W >> 8);
+ *CurBufferPtr++ = (uint8_t)(W >> 16);
+ *CurBufferPtr++ = (uint8_t)(W >> 24);
} else {
CurBufferPtr = BufferEnd;
}
/// emitWordBE - This callback is invoked when a 32-bit word needs to be
/// written to the output stream in big-endian format.
///
- void emitWordBE(unsigned W) {
+ void emitWordBE(uint32_t W) {
if (4 <= BufferEnd-CurBufferPtr) {
- *CurBufferPtr++ = (unsigned char)(W >> 24);
- *CurBufferPtr++ = (unsigned char)(W >> 16);
- *CurBufferPtr++ = (unsigned char)(W >> 8);
- *CurBufferPtr++ = (unsigned char)(W >> 0);
+ *CurBufferPtr++ = (uint8_t)(W >> 24);
+ *CurBufferPtr++ = (uint8_t)(W >> 16);
+ *CurBufferPtr++ = (uint8_t)(W >> 8);
+ *CurBufferPtr++ = (uint8_t)(W >> 0);
} else {
CurBufferPtr = BufferEnd;
}
///
void emitDWordLE(uint64_t W) {
if (8 <= BufferEnd-CurBufferPtr) {
- *CurBufferPtr++ = (unsigned char)(W >> 0);
- *CurBufferPtr++ = (unsigned char)(W >> 8);
- *CurBufferPtr++ = (unsigned char)(W >> 16);
- *CurBufferPtr++ = (unsigned char)(W >> 24);
- *CurBufferPtr++ = (unsigned char)(W >> 32);
- *CurBufferPtr++ = (unsigned char)(W >> 40);
- *CurBufferPtr++ = (unsigned char)(W >> 48);
- *CurBufferPtr++ = (unsigned char)(W >> 56);
+ *CurBufferPtr++ = (uint8_t)(W >> 0);
+ *CurBufferPtr++ = (uint8_t)(W >> 8);
+ *CurBufferPtr++ = (uint8_t)(W >> 16);
+ *CurBufferPtr++ = (uint8_t)(W >> 24);
+ *CurBufferPtr++ = (uint8_t)(W >> 32);
+ *CurBufferPtr++ = (uint8_t)(W >> 40);
+ *CurBufferPtr++ = (uint8_t)(W >> 48);
+ *CurBufferPtr++ = (uint8_t)(W >> 56);
} else {
CurBufferPtr = BufferEnd;
}
///
void emitDWordBE(uint64_t W) {
if (8 <= BufferEnd-CurBufferPtr) {
- *CurBufferPtr++ = (unsigned char)(W >> 56);
- *CurBufferPtr++ = (unsigned char)(W >> 48);
- *CurBufferPtr++ = (unsigned char)(W >> 40);
- *CurBufferPtr++ = (unsigned char)(W >> 32);
- *CurBufferPtr++ = (unsigned char)(W >> 24);
- *CurBufferPtr++ = (unsigned char)(W >> 16);
- *CurBufferPtr++ = (unsigned char)(W >> 8);
- *CurBufferPtr++ = (unsigned char)(W >> 0);
+ *CurBufferPtr++ = (uint8_t)(W >> 56);
+ *CurBufferPtr++ = (uint8_t)(W >> 48);
+ *CurBufferPtr++ = (uint8_t)(W >> 40);
+ *CurBufferPtr++ = (uint8_t)(W >> 32);
+ *CurBufferPtr++ = (uint8_t)(W >> 24);
+ *CurBufferPtr++ = (uint8_t)(W >> 16);
+ *CurBufferPtr++ = (uint8_t)(W >> 8);
+ *CurBufferPtr++ = (uint8_t)(W >> 0);
} else {
CurBufferPtr = BufferEnd;
}
if(Alignment <= (uintptr_t)(BufferEnd-CurBufferPtr)) {
// Move the current buffer ptr up to the specified alignment.
CurBufferPtr =
- (unsigned char*)(((uintptr_t)CurBufferPtr+Alignment-1) &
- ~(uintptr_t)(Alignment-1));
+ (uint8_t*)(((uintptr_t)CurBufferPtr+Alignment-1) &
+ ~(uintptr_t)(Alignment-1));
} else {
CurBufferPtr = BufferEnd;
}
/// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to be
/// written to the output stream.
- void emitULEB128Bytes(unsigned Value) {
+ void emitULEB128Bytes(uint64_t Value) {
do {
- unsigned char Byte = Value & 0x7f;
+ uint8_t Byte = Value & 0x7f;
Value >>= 7;
if (Value) Byte |= 0x80;
emitByte(Byte);
/// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to be
/// written to the output stream.
- void emitSLEB128Bytes(int Value) {
- int Sign = Value >> (8 * sizeof(Value) - 1);
+ void emitSLEB128Bytes(int64_t Value) {
+ int32_t Sign = Value >> (8 * sizeof(Value) - 1);
bool IsMore;
do {
- unsigned char Byte = Value & 0x7f;
+ uint8_t Byte = Value & 0x7f;
Value >>= 7;
IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
if (IsMore) Byte |= 0x80;
void emitString(const std::string &String) {
for (unsigned i = 0, N = static_cast<unsigned>(String.size());
i < N; ++i) {
- unsigned char C = String[i];
+ uint8_t C = String[i];
emitByte(C);
}
emitByte(0);
}
/// emitInt32 - Emit a int32 directive.
- void emitInt32(int Value) {
+ void emitInt32(uint32_t Value) {
if (4 <= BufferEnd-CurBufferPtr) {
*((uint32_t*)CurBufferPtr) = Value;
CurBufferPtr += 4;
return Result;
}
+ /// allocateGlobal - Allocate memory for a global. Unlike allocateSpace,
+ /// this method does not allocate memory in the current output buffer,
+ /// because a global may live longer than the current function.
+ virtual void *allocateGlobal(uintptr_t Size, unsigned Alignment) = 0;
+
/// StartMachineBasicBlock - This should be called by the target when a new
/// basic block is about to be emitted. This way the MCE knows where the
/// start of the block is, and can implement getMachineBasicBlockAddress.