aboutsummaryrefslogtreecommitdiff
path: root/lib/ExecutionEngine/Interpreter/ExecutionAnnotations.h
blob: f6a27265f04b87df76cd614e1a128bed4d6f146d (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//===-- ExecutionAnnotations.h ---------------------------------*- C++ -*--===//
//
// This header file defines annotations used by the execution engine.
//
//===----------------------------------------------------------------------===//

#ifndef LLI_EXECUTION_ANNOTATIONS_H
#define LLI_EXECUTION_ANNOTATIONS_H

//===----------------------------------------------------------------------===//
// Support for MethodInfo annotations
//===----------------------------------------------------------------------===//

// This annotation (attached only to Method objects) is used to cache useful
// information about the method, including the number of types present in the
// method, and the number of values for each type.
//
// This annotation object is created on demand, and attaches other annotation
// objects to the instructions in the method when it's created.
//
static AnnotationID MethodInfoAID(
	            AnnotationManager::getID("Interpreter::MethodInfo"));

struct MethodInfo : public Annotation {
  MethodInfo(Method *M);
  vector<unsigned> NumPlaneElements;


  // Create - Factory function to allow MethodInfo annotations to be
  // created on demand.
  //
  static Annotation *Create(AnnotationID AID, const Annotable *O, void *) {
    assert(AID == MethodInfoAID);
    return new MethodInfo(cast<Method>((Value*)O));  // Simply invoke the ctor
  }

private:
  unsigned getValueSlot(const Value *V);
};

//===----------------------------------------------------------------------===//
// Support for the SlotNumber annotation
//===----------------------------------------------------------------------===//

// This annotation (attached only to MethodArgument & Instruction objects) is
// used to hold the the slot number for the value in its type plane.
//
// Entities have this annotation attached to them when the containing
// method has it's MethodInfo created (by the MethodInfo ctor).
//
static AnnotationID SlotNumberAID(
	            AnnotationManager::getID("Interpreter::SlotNumber"));

struct SlotNumber : public Annotation {
  unsigned SlotNum;   // Ranges from 0->

  SlotNumber(unsigned sn) : Annotation(SlotNumberAID), 
			    SlotNum(sn) {}
};




//===----------------------------------------------------------------------===//
// Support for the InstNumber annotation
//===----------------------------------------------------------------------===//

// This annotation (attached only to Instruction objects) is used to hold the
// instruction number of the instruction, and the slot number for the value in
// its type plane.  InstNumber's are used for user interaction, and for
// calculating which value slot to store the result of the instruction in.
//
// Instructions have this annotation attached to them when the containing method
// has it's MethodInfo created (by the MethodInfo ctor).
//
struct InstNumber : public SlotNumber {
  unsigned InstNum;   // Ranges from 1->

  InstNumber(unsigned in, unsigned sn) : SlotNumber(sn), InstNum(in) {}
};


//===----------------------------------------------------------------------===//
// Support for the Breakpoint annotation
//===----------------------------------------------------------------------===//

static AnnotationID BreakpointAID(
	            AnnotationManager::getID("Interpreter::Breakpoint"));
// Just use an Annotation directly, Breakpoint is currently just a marker


//===----------------------------------------------------------------------===//
// Support for the GlobalAddress annotation
//===----------------------------------------------------------------------===//

// This annotation (attached only to GlobalValue objects) is used to hold the
// address of the chunk of memory that represents a global value.  For Method's,
// this pointer is the Method object pointer that represents it.  For global
// variables, this is the dynamically allocated (and potentially initialized)
// chunk of memory for the global.  This annotation is created on demand.
//
static AnnotationID GlobalAddressAID(
	            AnnotationManager::getID("Interpreter::GlobalAddress"));

struct GlobalAddress : public Annotation {
  void *Ptr;   // The pointer itself
  bool Delete; // Should I delete them memory on destruction?

  GlobalAddress(void *ptr, bool d) : Annotation(GlobalAddressAID), Ptr(ptr), 
                                     Delete(d) {}
  ~GlobalAddress() { if (Delete) free(Ptr); }
  
  // Create - Factory function to allow GlobalAddress annotations to be
  // created on demand.
  //
  static Annotation *Create(AnnotationID AID, const Annotable *O, void *);
};

#endif