blob: 7c378c41c826ff46523f970786bb6ce4d0324566 [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
10#include "../ExecutionEngine.h"
11#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
22 PassManager PM; // Passes to compile a function
23 MachineCodeEmitter *MCE; // MCE object
24
Chris Lattner836f6752002-12-24 00:01:22 +000025public:
26 VM(Module *M, TargetMachine *tm);
27 ~VM();
28
29 /// run - Start execution with the specified function and arguments.
30 ///
31 virtual int run(const std::string &FnName,
32 const std::vector<std::string> &Args);
33
Chris Lattner0d448c02003-01-13 01:00:48 +000034 /// getPointerToNamedFunction - This method returns the address of the
35 /// specified function by using the dlsym function call. As such it is only
36 /// useful for resolving library symbols, not code generated symbols.
37 ///
38 void *getPointerToNamedFunction(const std::string &Name);
39
Chris Lattnerc309a762003-05-08 21:34:11 +000040 // CompilationCallback - Invoked the first time that a call site is found,
41 // which causes lazy compilation of the target function.
42 //
43 static void CompilationCallback();
Chris Lattner22080f92003-05-14 13:53:40 +000044
45 /// runAtExitHandlers - Before exiting the program, at_exit functions must be
46 /// called. This method calls them.
47 ///
48 static void runAtExitHandlers();
49
Chris Lattnerbba1b6d2003-06-01 23:24:36 +000050 /// getPointerToFunction - This returns the address of the specified function,
51 /// compiling it if necessary.
52 void *getPointerToFunction(const Function *F);
53
Chris Lattner836f6752002-12-24 00:01:22 +000054private:
Misha Brukmanabb027c2003-05-27 21:40:39 +000055 static MachineCodeEmitter *createX86Emitter(VM &V);
56 static MachineCodeEmitter *createSparcEmitter(VM &V);
Chris Lattner836f6752002-12-24 00:01:22 +000057 void setupPassManager();
Chris Lattner836f6752002-12-24 00:01:22 +000058};
59
60#endif