blob: f79be1f34958dd3969c049ac4fdb4a8a0d590599 [file] [log] [blame]
Chris Lattner836f6752002-12-24 00:01:22 +00001//===-- VM.h - Definitions for Virtual Machine ------------------*- C++ -*-===//
2//
3// This file defines the top-level Virtual Machine data structure.
4//
5//===----------------------------------------------------------------------===//
6
7#ifndef VM_H
8#define VM_H
9
Brian Gaeke97222942003-09-05 19:39:22 +000010#include "llvm/ExecutionEngine/ExecutionEngine.h"
Chris Lattner836f6752002-12-24 00:01:22 +000011#include "llvm/PassManager.h"
12#include <map>
13
14class Function;
15class GlobalValue;
16class Constant;
17class TargetMachine;
18class MachineCodeEmitter;
19
20class VM : public ExecutionEngine {
21 TargetMachine &TM; // The current target we are compiling to
Brian Gaekec227c1f2003-08-13 18:16:50 +000022 FunctionPassManager PM; // Passes to compile a function
Chris Lattner836f6752002-12-24 00:01:22 +000023 MachineCodeEmitter *MCE; // MCE object
24
Chris Lattner836f6752002-12-24 00:01:22 +000025public:
26 VM(Module *M, TargetMachine *tm);
27 ~VM();
28
Brian Gaeke82d82772003-09-03 20:34:19 +000029 /// create - Create an return a new JIT compiler if there is one available
30 /// for the current target. Otherwise, return null.
31 ///
32 static ExecutionEngine *create(Module *M);
33
Chris Lattner836f6752002-12-24 00:01:22 +000034 /// run - Start execution with the specified function and arguments.
35 ///
Brian Gaeke70975ee2003-09-05 18:42:01 +000036 virtual GenericValue run(Function *F,
37 const std::vector<GenericValue> &ArgValues);
Chris Lattner836f6752002-12-24 00:01:22 +000038
Chris Lattner0d448c02003-01-13 01:00:48 +000039 /// getPointerToNamedFunction - This method returns the address of the
40 /// specified function by using the dlsym function call. As such it is only
41 /// useful for resolving library symbols, not code generated symbols.
42 ///
43 void *getPointerToNamedFunction(const std::string &Name);
44
Chris Lattnerc309a762003-05-08 21:34:11 +000045 // CompilationCallback - Invoked the first time that a call site is found,
46 // which causes lazy compilation of the target function.
47 //
48 static void CompilationCallback();
Chris Lattner22080f92003-05-14 13:53:40 +000049
50 /// runAtExitHandlers - Before exiting the program, at_exit functions must be
51 /// called. This method calls them.
52 ///
53 static void runAtExitHandlers();
54
Chris Lattnerbba1b6d2003-06-01 23:24:36 +000055 /// getPointerToFunction - This returns the address of the specified function,
56 /// compiling it if necessary.
Brian Gaekec227c1f2003-08-13 18:16:50 +000057 void *getPointerToFunction(Function *F);
Chris Lattnerbba1b6d2003-06-01 23:24:36 +000058
Chris Lattner836f6752002-12-24 00:01:22 +000059private:
Misha Brukman906f5fa2003-06-02 03:23:16 +000060 static MachineCodeEmitter *createEmitter(VM &V);
Chris Lattner836f6752002-12-24 00:01:22 +000061 void setupPassManager();
Chris Lattner836f6752002-12-24 00:01:22 +000062};
63
64#endif