aboutsummaryrefslogtreecommitdiffstats
path: root/tools/jello/VM.h
blob: 5d0cd38941c4e71eb518d1a0dee89f383a20d1c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//===-- VM.h - Definitions for Virtual Machine ------------------*- C++ -*-===//
//
// This file defines the top level Virtual Machine data structure.
//
//===----------------------------------------------------------------------===//

#ifndef VM_H
#define VM_H

#include "llvm/PassManager.h"
#include <string>
#include <map>

class TargetMachine;
class Function;
class GlobalValue;
class MachineCodeEmitter;

class VM {
  std::string ExeName;
  Module &M;               // The LLVM program we are running
  TargetMachine &TM;       // The current target we are compiling to
  PassManager PM;          // Passes to compile a function
  MachineCodeEmitter *MCE; // MCE object

  std::map<const GlobalValue*, void *> GlobalAddress;
public:
  VM(const std::string &name, Module &m, TargetMachine &tm)
    : ExeName(name), M(m), TM(tm) {
    MCE = createEmitter(*this);  // Initialize MCE
    setupPassManager();
  }

  ~VM();

  int run(Function *F);

  void addGlobalMapping(const Function *F, void *Addr) {
    void *&CurVal = GlobalAddress[(const GlobalValue*)F];
    assert(CurVal == 0 && "GlobalMapping already established!");
    CurVal = Addr;
  }

private:
  static MachineCodeEmitter *createEmitter(VM &V);
  void setupPassManager();
  void *getPointerToFunction(Function *F);
};

#endif