#ifndef LLVM_SUPPORT_ALLOCATOR_H
#define LLVM_SUPPORT_ALLOCATOR_H
#include "llvm/Support/AlignOf.h"
#include <cstdlib>
namespace llvm {
class MallocAllocator {
public:
MallocAllocator() {}
~MallocAllocator() {}
void Reset() {}
void *Allocate(size_t Size, size_t ) { return malloc(Size); }
template <typename T>
T *Allocate() { return static_cast<T*>(malloc(sizeof(T))); }
template <typename T>
T *Allocate(size_t Num) {
return static_cast<T*>(malloc(sizeof(T)*Num));
}
void Deallocate(const void *Ptr) { free(const_cast<void*>(Ptr)); }
void PrintStats() const {}
};
class BumpPtrAllocator {
BumpPtrAllocator(const BumpPtrAllocator &); void operator=(const BumpPtrAllocator &);
void *TheMemory;
public:
BumpPtrAllocator();
~BumpPtrAllocator();
void Reset();
void *Allocate(size_t Size, size_t Alignment);
template <typename T>
T *Allocate() {
return static_cast<T*>(Allocate(sizeof(T),AlignOf<T>::Alignment));
}
template <typename T>
T *Allocate(size_t Num) {
return static_cast<T*>(Allocate(Num * sizeof(T), AlignOf<T>::Alignment));
}
template <typename T>
T *Allocate(size_t Num, size_t Alignment) {
size_t EltSize = (sizeof(T)+Alignment-1)&(-Alignment);
return static_cast<T*>(Allocate(Num * EltSize, Alignment));
}
void Deallocate(const void * ) {}
void PrintStats() const;
};
}
#endif