mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-08 19:25:47 +00:00
simplify creation of the interpreter, make ExecutionEngine ctor protected,
delete one ExecutionEngine ctor, minor cleanup. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44646 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -12,8 +12,8 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#ifndef EXECUTION_ENGINE_H
|
#ifndef LLVM_EXECUTION_ENGINE_H
|
||||||
#define EXECUTION_ENGINE_H
|
#define LLVM_EXECUTION_ENGINE_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -34,6 +34,7 @@ class ModuleProvider;
|
|||||||
class TargetData;
|
class TargetData;
|
||||||
class Type;
|
class Type;
|
||||||
class MutexGuard;
|
class MutexGuard;
|
||||||
|
class JITMemoryManager;
|
||||||
|
|
||||||
class ExecutionEngineState {
|
class ExecutionEngineState {
|
||||||
private:
|
private:
|
||||||
@@ -90,18 +91,36 @@ public:
|
|||||||
/// any of those classes.
|
/// any of those classes.
|
||||||
sys::Mutex lock; // Used to make this class and subclasses thread-safe
|
sys::Mutex lock; // Used to make this class and subclasses thread-safe
|
||||||
|
|
||||||
ExecutionEngine(ModuleProvider *P);
|
//===----------------------------------------------------------------------===//
|
||||||
ExecutionEngine(Module *M);
|
// ExecutionEngine Startup
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
virtual ~ExecutionEngine();
|
virtual ~ExecutionEngine();
|
||||||
|
|
||||||
const TargetData *getTargetData() const { return TD; }
|
/// create - This is the factory method for creating an execution engine which
|
||||||
|
/// is appropriate for the current machine. This takes ownership of the
|
||||||
|
/// module provider.
|
||||||
|
static ExecutionEngine *create(ModuleProvider *MP,
|
||||||
|
bool ForceInterpreter = false,
|
||||||
|
std::string *ErrorStr = 0);
|
||||||
|
|
||||||
|
/// create - This is the factory method for creating an execution engine which
|
||||||
|
/// is appropriate for the current machine. This takes ownership of the
|
||||||
|
/// module.
|
||||||
|
static ExecutionEngine *create(Module *M);
|
||||||
|
|
||||||
|
|
||||||
/// addModuleProvider - Add a ModuleProvider to the list of modules that we
|
/// addModuleProvider - Add a ModuleProvider to the list of modules that we
|
||||||
/// can JIT from. Note that this takes ownership of the ModuleProvider: when
|
/// can JIT from. Note that this takes ownership of the ModuleProvider: when
|
||||||
/// the ExecutionEngine is destroyed, it destroys the MP as well.
|
/// the ExecutionEngine is destroyed, it destroys the MP as well.
|
||||||
void addModuleProvider(ModuleProvider *P) {
|
void addModuleProvider(ModuleProvider *P) {
|
||||||
Modules.push_back(P);
|
Modules.push_back(P);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
const TargetData *getTargetData() const { return TD; }
|
||||||
|
|
||||||
|
|
||||||
/// removeModuleProvider - Remove a ModuleProvider from the list of modules.
|
/// removeModuleProvider - Remove a ModuleProvider from the list of modules.
|
||||||
/// Release module from ModuleProvider.
|
/// Release module from ModuleProvider.
|
||||||
@@ -112,18 +131,6 @@ public:
|
|||||||
/// general code.
|
/// general code.
|
||||||
Function *FindFunctionNamed(const char *FnName);
|
Function *FindFunctionNamed(const char *FnName);
|
||||||
|
|
||||||
/// create - This is the factory method for creating an execution engine which
|
|
||||||
/// is appropriate for the current machine. This takes ownership of the
|
|
||||||
/// module provider.
|
|
||||||
static ExecutionEngine *create(ModuleProvider *MP,
|
|
||||||
bool ForceInterpreter = false,
|
|
||||||
std::string *ErrorStr = 0);
|
|
||||||
|
|
||||||
/// create - This is the factory method for creating an execution engine which
|
|
||||||
/// is appropriate for the current machine. This takes ownership of the
|
|
||||||
/// module.
|
|
||||||
static ExecutionEngine *create(Module *M);
|
|
||||||
|
|
||||||
/// runFunction - Execute the specified function with the specified arguments,
|
/// runFunction - Execute the specified function with the specified arguments,
|
||||||
/// and return the result.
|
/// and return the result.
|
||||||
///
|
///
|
||||||
@@ -233,6 +240,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
ExecutionEngine(ModuleProvider *P);
|
||||||
|
|
||||||
void emitGlobals();
|
void emitGlobals();
|
||||||
|
|
||||||
// EmitGlobalVariable - This method emits the specified global variable to the
|
// EmitGlobalVariable - This method emits the specified global variable to the
|
||||||
|
@@ -39,12 +39,6 @@ ExecutionEngine::ExecutionEngine(ModuleProvider *P) : LazyFunctionCreator(0) {
|
|||||||
assert(P && "ModuleProvider is null?");
|
assert(P && "ModuleProvider is null?");
|
||||||
}
|
}
|
||||||
|
|
||||||
ExecutionEngine::ExecutionEngine(Module *M) : LazyFunctionCreator(0) {
|
|
||||||
LazyCompilationDisabled = false;
|
|
||||||
assert(M && "Module is null?");
|
|
||||||
Modules.push_back(new ExistingModuleProvider(M));
|
|
||||||
}
|
|
||||||
|
|
||||||
ExecutionEngine::~ExecutionEngine() {
|
ExecutionEngine::~ExecutionEngine() {
|
||||||
clearAllGlobalMappings();
|
clearAllGlobalMappings();
|
||||||
for (unsigned i = 0, e = Modules.size(); i != e; ++i)
|
for (unsigned i = 0, e = Modules.size(); i != e; ++i)
|
||||||
|
@@ -33,26 +33,18 @@ namespace llvm {
|
|||||||
///
|
///
|
||||||
ExecutionEngine *Interpreter::create(ModuleProvider *MP, std::string* ErrStr) {
|
ExecutionEngine *Interpreter::create(ModuleProvider *MP, std::string* ErrStr) {
|
||||||
// Tell this ModuleProvide to materialize and release the module
|
// Tell this ModuleProvide to materialize and release the module
|
||||||
Module *M = MP->releaseModule(ErrStr);
|
if (!MP->materializeModule(ErrStr))
|
||||||
if (!M)
|
|
||||||
// We got an error, just return 0
|
// We got an error, just return 0
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// This is a bit nasty, but the ExecutionEngine won't be able to delete the
|
return new Interpreter(MP);
|
||||||
// module due to use/def issues if we don't delete this MP here. Below we
|
|
||||||
// construct a new Interpreter with the Module we just got. This creates a
|
|
||||||
// new ExistingModuleProvider in the EE instance. Consequently, MP is left
|
|
||||||
// dangling and it contains references into the module which cause problems
|
|
||||||
// when the module is deleted via the ExistingModuleProvide via EE.
|
|
||||||
delete MP;
|
|
||||||
|
|
||||||
return new Interpreter(M);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Interpreter ctor - Initialize stuff
|
// Interpreter ctor - Initialize stuff
|
||||||
//
|
//
|
||||||
Interpreter::Interpreter(Module *M) : ExecutionEngine(M), TD(M) {
|
Interpreter::Interpreter(ModuleProvider *M)
|
||||||
|
: ExecutionEngine(M), TD(M->getModule()) {
|
||||||
|
|
||||||
memset(&ExitValue.Untyped, 0, sizeof(ExitValue.Untyped));
|
memset(&ExitValue.Untyped, 0, sizeof(ExitValue.Untyped));
|
||||||
setTargetData(&TD);
|
setTargetData(&TD);
|
||||||
|
@@ -94,7 +94,7 @@ class Interpreter : public ExecutionEngine, public InstVisitor<Interpreter> {
|
|||||||
std::vector<Function*> AtExitHandlers;
|
std::vector<Function*> AtExitHandlers;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Interpreter(Module *M);
|
explicit Interpreter(ModuleProvider *M);
|
||||||
~Interpreter();
|
~Interpreter();
|
||||||
|
|
||||||
/// runAtExitHandlers - Run any functions registered by the program's calls to
|
/// runAtExitHandlers - Run any functions registered by the program's calls to
|
||||||
|
@@ -66,7 +66,7 @@ JIT::JIT(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji)
|
|||||||
setTargetData(TM.getTargetData());
|
setTargetData(TM.getTargetData());
|
||||||
|
|
||||||
// Initialize MCE
|
// Initialize MCE
|
||||||
MCE = createEmitter(*this);
|
MCE = createEmitter(*this, 0);
|
||||||
|
|
||||||
// Add target data
|
// Add target data
|
||||||
MutexGuard locked(lock);
|
MutexGuard locked(lock);
|
||||||
|
@@ -121,7 +121,7 @@ public:
|
|||||||
/// getCodeEmitter - Return the code emitter this JIT is emitting into.
|
/// getCodeEmitter - Return the code emitter this JIT is emitting into.
|
||||||
MachineCodeEmitter *getCodeEmitter() const { return MCE; }
|
MachineCodeEmitter *getCodeEmitter() const { return MCE; }
|
||||||
private:
|
private:
|
||||||
static MachineCodeEmitter *createEmitter(JIT &J);
|
static MachineCodeEmitter *createEmitter(JIT &J, JITMemoryManager *JMM);
|
||||||
void runJITOnFunction (Function *F);
|
void runJITOnFunction (Function *F);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -312,8 +312,8 @@ namespace {
|
|||||||
/// Resolver - This contains info about the currently resolved functions.
|
/// Resolver - This contains info about the currently resolved functions.
|
||||||
JITResolver Resolver;
|
JITResolver Resolver;
|
||||||
public:
|
public:
|
||||||
JITEmitter(JIT &jit) : Resolver(jit) {
|
JITEmitter(JIT &jit, JITMemoryManager *JMM) : Resolver(jit) {
|
||||||
MemMgr = JITMemoryManager::CreateDefaultMemManager();
|
MemMgr = JMM ? JMM : JITMemoryManager::CreateDefaultMemManager();
|
||||||
if (jit.getJITInfo().needsGOT()) {
|
if (jit.getJITInfo().needsGOT()) {
|
||||||
MemMgr->AllocateGOT();
|
MemMgr->AllocateGOT();
|
||||||
DOUT << "JIT is managing a GOT\n";
|
DOUT << "JIT is managing a GOT\n";
|
||||||
@@ -637,8 +637,8 @@ intptr_t JITEmitter::getJumpTableEntryAddress(unsigned Index) const {
|
|||||||
// Public interface to this file
|
// Public interface to this file
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
MachineCodeEmitter *JIT::createEmitter(JIT &jit) {
|
MachineCodeEmitter *JIT::createEmitter(JIT &jit, JITMemoryManager *JMM) {
|
||||||
return new JITEmitter(jit);
|
return new JITEmitter(jit, JMM);
|
||||||
}
|
}
|
||||||
|
|
||||||
// getPointerToNamedFunction - This function is used as a global wrapper to
|
// getPointerToNamedFunction - This function is used as a global wrapper to
|
||||||
|
Reference in New Issue
Block a user