mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-10 18:34:09 +00:00
ExecutionEngine: unique_ptr-ify
NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216362 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
444aa2d525
commit
1e321bba6e
@ -256,19 +256,9 @@ const GlobalValue *ExecutionEngine::getGlobalValueAtAddress(void *Addr) {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class ArgvArray {
|
class ArgvArray {
|
||||||
char *Array;
|
std::unique_ptr<char[]> Array;
|
||||||
std::vector<char*> Values;
|
std::vector<std::unique_ptr<char[]>> Values;
|
||||||
public:
|
public:
|
||||||
ArgvArray() : Array(nullptr) {}
|
|
||||||
~ArgvArray() { clear(); }
|
|
||||||
void clear() {
|
|
||||||
delete[] Array;
|
|
||||||
Array = nullptr;
|
|
||||||
for (size_t I = 0, E = Values.size(); I != E; ++I) {
|
|
||||||
delete[] Values[I];
|
|
||||||
}
|
|
||||||
Values.clear();
|
|
||||||
}
|
|
||||||
/// Turn a vector of strings into a nice argv style array of pointers to null
|
/// Turn a vector of strings into a nice argv style array of pointers to null
|
||||||
/// terminated strings.
|
/// terminated strings.
|
||||||
void *reset(LLVMContext &C, ExecutionEngine *EE,
|
void *reset(LLVMContext &C, ExecutionEngine *EE,
|
||||||
@ -277,32 +267,34 @@ public:
|
|||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
void *ArgvArray::reset(LLVMContext &C, ExecutionEngine *EE,
|
void *ArgvArray::reset(LLVMContext &C, ExecutionEngine *EE,
|
||||||
const std::vector<std::string> &InputArgv) {
|
const std::vector<std::string> &InputArgv) {
|
||||||
clear(); // Free the old contents.
|
Values.clear(); // Free the old contents.
|
||||||
|
Values.reserve(InputArgv.size());
|
||||||
unsigned PtrSize = EE->getDataLayout()->getPointerSize();
|
unsigned PtrSize = EE->getDataLayout()->getPointerSize();
|
||||||
Array = new char[(InputArgv.size()+1)*PtrSize];
|
Array = make_unique<char[]>((InputArgv.size()+1)*PtrSize);
|
||||||
|
|
||||||
DEBUG(dbgs() << "JIT: ARGV = " << (void*)Array << "\n");
|
DEBUG(dbgs() << "JIT: ARGV = " << (void*)Array.get() << "\n");
|
||||||
Type *SBytePtr = Type::getInt8PtrTy(C);
|
Type *SBytePtr = Type::getInt8PtrTy(C);
|
||||||
|
|
||||||
for (unsigned i = 0; i != InputArgv.size(); ++i) {
|
for (unsigned i = 0; i != InputArgv.size(); ++i) {
|
||||||
unsigned Size = InputArgv[i].size()+1;
|
unsigned Size = InputArgv[i].size()+1;
|
||||||
char *Dest = new char[Size];
|
auto DestOwner = make_unique<char[]>(Size);
|
||||||
Values.push_back(Dest);
|
char *Dest = DestOwner.get();
|
||||||
|
Values.push_back(std::move(DestOwner));
|
||||||
DEBUG(dbgs() << "JIT: ARGV[" << i << "] = " << (void*)Dest << "\n");
|
DEBUG(dbgs() << "JIT: ARGV[" << i << "] = " << (void*)Dest << "\n");
|
||||||
|
|
||||||
std::copy(InputArgv[i].begin(), InputArgv[i].end(), Dest);
|
std::copy(InputArgv[i].begin(), InputArgv[i].end(), Dest);
|
||||||
Dest[Size-1] = 0;
|
Dest[Size-1] = 0;
|
||||||
|
|
||||||
// Endian safe: Array[i] = (PointerTy)Dest;
|
// Endian safe: Array[i] = (PointerTy)Dest;
|
||||||
EE->StoreValueToMemory(PTOGV(Dest), (GenericValue*)(Array+i*PtrSize),
|
EE->StoreValueToMemory(PTOGV(Dest), (GenericValue*)(&Array[i*PtrSize]),
|
||||||
SBytePtr);
|
SBytePtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Null terminate it
|
// Null terminate it
|
||||||
EE->StoreValueToMemory(PTOGV(nullptr),
|
EE->StoreValueToMemory(PTOGV(nullptr),
|
||||||
(GenericValue*)(Array+InputArgv.size()*PtrSize),
|
(GenericValue*)(&Array[InputArgv.size()*PtrSize]),
|
||||||
SBytePtr);
|
SBytePtr);
|
||||||
return Array;
|
return Array.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecutionEngine::runStaticConstructorsDestructors(Module &module,
|
void ExecutionEngine::runStaticConstructorsDestructors(Module &module,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user