2002-12-24 08:01:22 +08:00
|
|
|
//===-- VM.h - Definitions for Virtual Machine ------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// This file defines the top-level Virtual Machine data structure.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef VM_H
|
|
|
|
#define VM_H
|
|
|
|
|
|
|
|
#include "../ExecutionEngine.h"
|
|
|
|
#include "llvm/PassManager.h"
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
class Function;
|
|
|
|
class GlobalValue;
|
|
|
|
class Constant;
|
|
|
|
class TargetMachine;
|
|
|
|
class MachineCodeEmitter;
|
|
|
|
|
|
|
|
class VM : public ExecutionEngine {
|
|
|
|
TargetMachine &TM; // The current target we are compiling to
|
2003-08-14 02:16:50 +08:00
|
|
|
FunctionPassManager PM; // Passes to compile a function
|
2002-12-24 08:01:22 +08:00
|
|
|
MachineCodeEmitter *MCE; // MCE object
|
|
|
|
|
|
|
|
public:
|
|
|
|
VM(Module *M, TargetMachine *tm);
|
|
|
|
~VM();
|
|
|
|
|
2003-09-04 04:34:19 +08:00
|
|
|
/// create - Create an return a new JIT compiler if there is one available
|
|
|
|
/// for the current target. Otherwise, return null.
|
|
|
|
///
|
|
|
|
static ExecutionEngine *create(Module *M);
|
|
|
|
|
2002-12-24 08:01:22 +08:00
|
|
|
/// run - Start execution with the specified function and arguments.
|
|
|
|
///
|
|
|
|
virtual int run(const std::string &FnName,
|
2003-08-22 05:12:30 +08:00
|
|
|
const std::vector<std::string> &Args,
|
|
|
|
const char ** envp);
|
2002-12-24 08:01:22 +08:00
|
|
|
|
2003-01-13 09:00:48 +08:00
|
|
|
/// getPointerToNamedFunction - This method returns the address of the
|
|
|
|
/// specified function by using the dlsym function call. As such it is only
|
|
|
|
/// useful for resolving library symbols, not code generated symbols.
|
|
|
|
///
|
|
|
|
void *getPointerToNamedFunction(const std::string &Name);
|
|
|
|
|
2003-05-09 05:34:11 +08:00
|
|
|
// CompilationCallback - Invoked the first time that a call site is found,
|
|
|
|
// which causes lazy compilation of the target function.
|
|
|
|
//
|
|
|
|
static void CompilationCallback();
|
2003-05-14 21:53:40 +08:00
|
|
|
|
|
|
|
/// runAtExitHandlers - Before exiting the program, at_exit functions must be
|
|
|
|
/// called. This method calls them.
|
|
|
|
///
|
|
|
|
static void runAtExitHandlers();
|
|
|
|
|
2003-06-02 07:24:36 +08:00
|
|
|
/// getPointerToFunction - This returns the address of the specified function,
|
|
|
|
/// compiling it if necessary.
|
2003-08-14 02:16:50 +08:00
|
|
|
void *getPointerToFunction(Function *F);
|
2003-06-02 07:24:36 +08:00
|
|
|
|
2002-12-24 08:01:22 +08:00
|
|
|
private:
|
2003-06-02 11:23:16 +08:00
|
|
|
static MachineCodeEmitter *createEmitter(VM &V);
|
2002-12-24 08:01:22 +08:00
|
|
|
void setupPassManager();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|