mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-15 23:31:37 +00:00
mmap() seems to be failing on Sparc, so just use malloc()/free() .
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6387 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ecc7fd3c56
commit
8e5bf70dff
@ -32,8 +32,16 @@ namespace {
|
|||||||
std::pair<unsigned*,MachineInstr*> > > BBRefs;
|
std::pair<unsigned*,MachineInstr*> > > BBRefs;
|
||||||
std::map<BasicBlock*, unsigned> BBLocations;
|
std::map<BasicBlock*, unsigned> BBLocations;
|
||||||
std::vector<void*> ConstantPoolAddresses;
|
std::vector<void*> ConstantPoolAddresses;
|
||||||
|
std::vector<void*> funcMemory;
|
||||||
public:
|
public:
|
||||||
SparcEmitter(VM &vm) : TheVM(vm) {}
|
SparcEmitter(VM &vm) : TheVM(vm) {}
|
||||||
|
~SparcEmitter() {
|
||||||
|
while (! funcMemory.empty()) {
|
||||||
|
void* addr = funcMemory.back();
|
||||||
|
free(addr);
|
||||||
|
funcMemory.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual void startFunction(MachineFunction &F);
|
virtual void startFunction(MachineFunction &F);
|
||||||
virtual void finishFunction(MachineFunction &F);
|
virtual void finishFunction(MachineFunction &F);
|
||||||
@ -50,8 +58,10 @@ namespace {
|
|||||||
|
|
||||||
virtual void saveBBreference(BasicBlock *BB, MachineInstr &MI);
|
virtual void saveBBreference(BasicBlock *BB, MachineInstr &MI);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void emitAddress(void *Addr, bool isPCRelative);
|
void emitAddress(void *Addr, bool isPCRelative);
|
||||||
|
void* getMemory(unsigned NumPages);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,22 +76,36 @@ MachineCodeEmitter *VM::createSparcEmitter(VM &V) {
|
|||||||
|
|
||||||
// FIXME: This should be rewritten to support a real memory manager for
|
// FIXME: This should be rewritten to support a real memory manager for
|
||||||
// executable memory pages!
|
// executable memory pages!
|
||||||
static void *getMemory(unsigned NumPages) {
|
void * SparcEmitter::getMemory(unsigned NumPages) {
|
||||||
return mmap(0, 4096*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
|
#if 0
|
||||||
|
void *pa = mmap(0, 4096*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
|
||||||
MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
|
MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
|
||||||
|
if (pa == MAP_FAILED) {
|
||||||
|
perror("mmap");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
void *pa = malloc(4096*NumPages);
|
||||||
|
if (!pa) {
|
||||||
|
perror("malloc");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
funcMemory.push_back(pa);
|
||||||
|
return pa;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SparcEmitter::startFunction(MachineFunction &F) {
|
void SparcEmitter::startFunction(MachineFunction &F) {
|
||||||
CurBlock = (unsigned char *)getMemory(8);
|
CurBlock = (unsigned char *)getMemory(8);
|
||||||
|
std::cerr << "Starting function " << F.getFunction()->getName() << "\n";
|
||||||
CurByte = CurBlock; // Start writing at the beginning of the fn.
|
CurByte = CurBlock; // Start writing at the beginning of the fn.
|
||||||
TheVM.addGlobalMapping(F.getFunction(), CurBlock);
|
TheVM.addGlobalMapping(F.getFunction(), CurBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SparcEmitter::finishFunction(MachineFunction &F) {
|
void SparcEmitter::finishFunction(MachineFunction &F) {
|
||||||
ConstantPoolAddresses.clear();
|
ConstantPoolAddresses.clear();
|
||||||
for (unsigned i = 0, e = BBRefs.size(); i != e; ++i) {
|
|
||||||
// Re-write branches to BasicBlocks for the entire function
|
// Re-write branches to BasicBlocks for the entire function
|
||||||
|
for (unsigned i = 0, e = BBRefs.size(); i != e; ++i) {
|
||||||
unsigned Location = BBLocations[BBRefs[i].first];
|
unsigned Location = BBLocations[BBRefs[i].first];
|
||||||
unsigned *Ref = BBRefs[i].second.first;
|
unsigned *Ref = BBRefs[i].second.first;
|
||||||
MachineInstr *MI = BBRefs[i].second.second;
|
MachineInstr *MI = BBRefs[i].second.second;
|
||||||
@ -149,6 +173,7 @@ void SparcEmitter::emitByte(unsigned char B) {
|
|||||||
// BasicBlock -> pair<memloc, MachineInstr>
|
// BasicBlock -> pair<memloc, MachineInstr>
|
||||||
// when the BB is emitted, machineinstr is modified with then-currbyte,
|
// when the BB is emitted, machineinstr is modified with then-currbyte,
|
||||||
// processed with MCE, and written out at memloc.
|
// processed with MCE, and written out at memloc.
|
||||||
|
// Should be called by the emitter if its outputting a PCRelative disp
|
||||||
void SparcEmitter::saveBBreference(BasicBlock *BB, MachineInstr &MI) {
|
void SparcEmitter::saveBBreference(BasicBlock *BB, MachineInstr &MI) {
|
||||||
BBRefs.push_back(std::make_pair(BB, std::make_pair((unsigned*)CurByte, &MI)));
|
BBRefs.push_back(std::make_pair(BB, std::make_pair((unsigned*)CurByte, &MI)));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user