mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-19 03:24:09 +00:00
Eliminate the dependency of ExecutionEngine on the JIT/Interpreter libraries.
Now you can build a tool with just the JIT or just the interpreter. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26946 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -13,8 +13,6 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#define DEBUG_TYPE "jit"
|
#define DEBUG_TYPE "jit"
|
||||||
#include "Interpreter/Interpreter.h"
|
|
||||||
#include "JIT/JIT.h"
|
|
||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
@ -26,6 +24,7 @@
|
|||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/System/DynamicLibrary.h"
|
#include "llvm/System/DynamicLibrary.h"
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
|
#include <iostream>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -33,6 +32,9 @@ namespace {
|
|||||||
Statistic<> NumGlobals ("lli", "Number of global vars initialized");
|
Statistic<> NumGlobals ("lli", "Number of global vars initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExecutionEngine::EECtorFn ExecutionEngine::JITCtor = 0;
|
||||||
|
ExecutionEngine::EECtorFn ExecutionEngine::InterpCtor = 0;
|
||||||
|
|
||||||
ExecutionEngine::ExecutionEngine(ModuleProvider *P) :
|
ExecutionEngine::ExecutionEngine(ModuleProvider *P) :
|
||||||
CurMod(*P->getModule()), MP(P) {
|
CurMod(*P->getModule()), MP(P) {
|
||||||
assert(P && "ModuleProvider is null?");
|
assert(P && "ModuleProvider is null?");
|
||||||
@ -163,24 +165,12 @@ ExecutionEngine *ExecutionEngine::create(ModuleProvider *MP,
|
|||||||
ExecutionEngine *EE = 0;
|
ExecutionEngine *EE = 0;
|
||||||
|
|
||||||
// Unless the interpreter was explicitly selected, try making a JIT.
|
// Unless the interpreter was explicitly selected, try making a JIT.
|
||||||
if (!ForceInterpreter)
|
if (!ForceInterpreter && JITCtor)
|
||||||
EE = JIT::create(MP, IL);
|
EE = JITCtor(MP, IL);
|
||||||
|
|
||||||
// If we can't make a JIT, make an interpreter instead.
|
// If we can't make a JIT, make an interpreter instead.
|
||||||
if (EE == 0) {
|
if (EE == 0 && InterpCtor)
|
||||||
try {
|
EE = InterpCtor(MP, IL);
|
||||||
Module *M = MP->materializeModule();
|
|
||||||
try {
|
|
||||||
EE = Interpreter::create(M, IL);
|
|
||||||
} catch (...) {
|
|
||||||
std::cerr << "Error creating the interpreter!\n";
|
|
||||||
}
|
|
||||||
} catch (std::string& errmsg) {
|
|
||||||
std::cerr << "Error reading the bytecode file: " << errmsg << "\n";
|
|
||||||
} catch (...) {
|
|
||||||
std::cerr << "Error reading the bytecode file!\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (EE == 0)
|
if (EE == 0)
|
||||||
delete IL;
|
delete IL;
|
||||||
|
@ -17,11 +17,24 @@
|
|||||||
#include "llvm/CodeGen/IntrinsicLowering.h"
|
#include "llvm/CodeGen/IntrinsicLowering.h"
|
||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
|
#include "llvm/ModuleProvider.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
static struct RegisterInterp {
|
||||||
|
RegisterInterp() { Interpreter::Register(); }
|
||||||
|
} InterpRegistrator;
|
||||||
|
|
||||||
/// create - Create a new interpreter object. This can never fail.
|
/// create - Create a new interpreter object. This can never fail.
|
||||||
///
|
///
|
||||||
ExecutionEngine *Interpreter::create(Module *M, IntrinsicLowering *IL) {
|
ExecutionEngine *Interpreter::create(ModuleProvider *MP,
|
||||||
|
IntrinsicLowering *IL) {
|
||||||
|
Module *M;
|
||||||
|
try {
|
||||||
|
M = MP->materializeModule();
|
||||||
|
} catch (...) {
|
||||||
|
return 0; // error materializing the module.
|
||||||
|
}
|
||||||
|
|
||||||
bool isLittleEndian = false;
|
bool isLittleEndian = false;
|
||||||
switch (M->getEndianness()) {
|
switch (M->getEndianness()) {
|
||||||
case Module::LittleEndian: isLittleEndian = true; break;
|
case Module::LittleEndian: isLittleEndian = true; break;
|
||||||
|
@ -102,11 +102,15 @@ public:
|
|||||||
///
|
///
|
||||||
void runAtExitHandlers();
|
void runAtExitHandlers();
|
||||||
|
|
||||||
|
static void Register() {
|
||||||
|
InterpCtor = create;
|
||||||
|
}
|
||||||
|
|
||||||
/// create - Create an interpreter ExecutionEngine. This can never fail. The
|
/// create - Create an interpreter ExecutionEngine. This can never fail. The
|
||||||
/// specified IntrinsicLowering implementation will be deleted when the
|
/// specified IntrinsicLowering implementation will be deleted when the
|
||||||
/// Interpreter execution engine is destroyed.
|
/// Interpreter execution engine is destroyed.
|
||||||
///
|
///
|
||||||
static ExecutionEngine *create(Module *M, IntrinsicLowering *IL);
|
static ExecutionEngine *create(ModuleProvider *M, IntrinsicLowering *IL);
|
||||||
|
|
||||||
/// run - Start execution with the specified function and arguments.
|
/// run - Start execution with the specified function and arguments.
|
||||||
///
|
///
|
||||||
|
@ -26,9 +26,12 @@
|
|||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
#include "llvm/Target/TargetJITInfo.h"
|
#include "llvm/Target/TargetJITInfo.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
static struct RegisterJIT {
|
||||||
|
RegisterJIT() { JIT::Register(); }
|
||||||
|
} JITRegistrator;
|
||||||
|
|
||||||
JIT::JIT(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji)
|
JIT::JIT(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji)
|
||||||
: ExecutionEngine(MP), TM(tm), TJI(tji), state(MP) {
|
: ExecutionEngine(MP), TM(tm), TJI(tji), state(MP) {
|
||||||
setTargetData(TM.getTargetData());
|
setTargetData(TM.getTargetData());
|
||||||
|
@ -60,6 +60,10 @@ class JIT : public ExecutionEngine {
|
|||||||
public:
|
public:
|
||||||
~JIT();
|
~JIT();
|
||||||
|
|
||||||
|
static void Register() {
|
||||||
|
JITCtor = create;
|
||||||
|
}
|
||||||
|
|
||||||
/// getJITInfo - Return the target JIT information structure.
|
/// getJITInfo - Return the target JIT information structure.
|
||||||
///
|
///
|
||||||
TargetJITInfo &getJITInfo() const { return TJI; }
|
TargetJITInfo &getJITInfo() const { return TJI; }
|
||||||
|
Reference in New Issue
Block a user