summaryrefslogtreecommitdiff
path: root/include/llvm/ConstPoolVals.h
blob: 235ab12f26361b0f0db3d50e7545fa94fd329aac (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
//===-- llvm/ConstPoolVals.h - Constant Value nodes --------------*- C++ -*--=//
//
// This file contains the declarations for the ConstPoolVal class and all of
// its subclasses, which represent the different type of constant pool values
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CONSTPOOLVALS_H
#define LLVM_CONSTPOOLVALS_H

#include "llvm/User.h"
#include "llvm/Support/DataTypes.h"

class ArrayType;
class StructType;
class PointerType;

//===----------------------------------------------------------------------===//
//                            ConstPoolVal Class
//===----------------------------------------------------------------------===//

class ConstPoolVal : public User {
protected:
  inline ConstPoolVal(const Type *Ty) : User(Ty, Value::ConstantVal) {}
  ~ConstPoolVal() {}

public:
  // Specialize setName to handle symbol table majik...
  virtual void setName(const string &name, SymbolTable *ST = 0);

  virtual string getStrValue() const = 0;

  // Static constructor to get a '0' constant of arbitrary type...
  static ConstPoolVal *getNullConstant(const Type *Ty);

  // Methods for support type inquiry through isa, cast, and dyn_cast:
  static inline bool classof(const ConstPoolVal *) { return true; }
  static inline bool classof(const Value *V) {
    return V->getValueType() == Value::ConstantVal;
  }
};



//===----------------------------------------------------------------------===//
//              Classes to represent constant pool variable defs
//===----------------------------------------------------------------------===//

//===---------------------------------------------------------------------------
// ConstPoolBool - Boolean Values
//
class ConstPoolBool : public ConstPoolVal {
  bool Val;
  ConstPoolBool(const ConstPoolBool &);     // DO NOT IMPLEMENT
  ConstPoolBool(bool V);
  ~ConstPoolBool() {}
public:
  static ConstPoolBool *True, *False;  // The True & False values

  // Factory objects - Return objects of the specified value
  static ConstPoolBool *get(bool Value) { return Value ? True : False; }
  static ConstPoolBool *get(const Type *Ty, bool Value) { return get(Value); }

  // inverted - Return the opposite value of the current value.
  inline ConstPoolBool *inverted() const { return (this==True) ? False : True; }

  virtual string getStrValue() const;
  inline bool getValue() const { return Val; }

  // Methods for support type inquiry through isa, cast, and dyn_cast:
  static inline bool classof(const ConstPoolBool *) { return true; }
  static bool classof(const ConstPoolVal *CPV) {
    return (CPV == True) | (CPV == False);
  }
  static inline bool classof(const Value *V) {
    return isa<ConstPoolVal>(V) && classof(cast<ConstPoolVal>(V));
  }
};


//===---------------------------------------------------------------------------
// ConstPoolInt - Superclass of ConstPoolSInt & ConstPoolUInt, to make dealing
// with integral constants easier.
//
class ConstPoolInt : public ConstPoolVal {
protected:
  union {
    int64_t  Signed;
    uint64_t Unsigned;
  } Val;
  ConstPoolInt(const ConstPoolInt &);      // DO NOT IMPLEMENT
  ConstPoolInt(const Type *Ty, uint64_t V);
  ~ConstPoolInt() {}
public:
  // equalsInt - Provide a helper method that can be used to determine if the 
  // constant contained within is equal to a constant.  This only works for very
  // small values, because this is all that can be represented with all types.
  //
  bool equalsInt(unsigned char V) const {
    assert(V <= 127 &&
	   "equals: Can only be used with very small positive constants!");
    return Val.Unsigned == V;
  }

  // ConstPoolInt::get static method: return a constant pool int with the
  // specified value.  as above, we work only with very small values here.
  //
  static ConstPoolInt *get(const Type *Ty, unsigned char V);

  // Methods for support type inquiry through isa, cast, and dyn_cast:
  static inline bool classof(const ConstPoolInt *) { return true; }
  static bool classof(const ConstPoolVal *CPV);  // defined in CPV.cpp
  static inline bool classof(const Value *V) {
    return isa<ConstPoolVal>(V) && classof(cast<ConstPoolVal>(V));
  }
};


//===---------------------------------------------------------------------------
// ConstPoolSInt - Signed Integer Values [sbyte, short, int, long]
//
class ConstPoolSInt : public ConstPoolInt {
  ConstPoolSInt(const ConstPoolSInt &);      // DO NOT IMPLEMENT
protected:
  ConstPoolSInt(const Type *Ty, int64_t V);
  ~ConstPoolSInt() {}
public:
  static ConstPoolSInt *get(const Type *Ty, int64_t V);

  virtual string getStrValue() const;

  static bool isValueValidForType(const Type *Ty, int64_t V);
  inline int64_t getValue() const { return Val.Signed; }
};

//===---------------------------------------------------------------------------
// ConstPoolUInt - Unsigned Integer Values [ubyte, ushort, uint, ulong]
//
class ConstPoolUInt : public ConstPoolInt {
  ConstPoolUInt(const ConstPoolUInt &);      // DO NOT IMPLEMENT
protected:
  ConstPoolUInt(const Type *Ty, uint64_t V);
  ~ConstPoolUInt() {}
public:
  static ConstPoolUInt *get(const Type *Ty, uint64_t V);

  virtual string getStrValue() const;

  static bool isValueValidForType(const Type *Ty, uint64_t V);
  inline uint64_t getValue() const { return Val.Unsigned; }
};


//===---------------------------------------------------------------------------
// ConstPoolFP - Floating Point Values [float, double]
//
class ConstPoolFP : public ConstPoolVal {
  double Val;
  ConstPoolFP(const ConstPoolFP &);      // DO NOT IMPLEMENT
protected:
  ConstPoolFP(const Type *Ty, double V);
  ~ConstPoolFP() {}
public:
  static ConstPoolFP *get(const Type *Ty, double V);

  virtual string getStrValue() const;

  static bool isValueValidForType(const Type *Ty, double V);
  inline double getValue() const { return Val; }
};


//===---------------------------------------------------------------------------
// ConstPoolArray - Constant Array Declarations
//
class ConstPoolArray : public ConstPoolVal {
  ConstPoolArray(const ConstPoolArray &);      // DO NOT IMPLEMENT
protected:
  ConstPoolArray(const ArrayType *T, const vector<ConstPoolVal*> &Val);
  ~ConstPoolArray() {}
public:
  static ConstPoolArray *get(const ArrayType *T, const vector<ConstPoolVal*> &);

  virtual string getStrValue() const;

  inline const vector<Use> &getValues() const { return Operands; }
};


//===---------------------------------------------------------------------------
// ConstPoolStruct - Constant Struct Declarations
//
class ConstPoolStruct : public ConstPoolVal {
  ConstPoolStruct(const ConstPoolStruct &);      // DO NOT IMPLEMENT
protected:
  ConstPoolStruct(const StructType *T, const vector<ConstPoolVal*> &Val);
  ~ConstPoolStruct() {}
public:
  static ConstPoolStruct *get(const StructType *T,
			      const vector<ConstPoolVal*> &V);

  virtual string getStrValue() const;

  inline const vector<Use> &getValues() const { return Operands; }
};

//===---------------------------------------------------------------------------
// ConstPoolPointer - Constant Pointer Declarations
//
// The ConstPoolPointer class represents a null pointer of a specific type. For
// a more specific/useful instance, a subclass of ConstPoolPointer should be
// used.
//
class ConstPoolPointer : public ConstPoolVal {
  ConstPoolPointer(const ConstPoolPointer &);      // DO NOT IMPLEMENT
protected:
  ConstPoolPointer(const PointerType *T);
  ~ConstPoolPointer() {}
public:
  static ConstPoolPointer *getNull(const PointerType *T);

  virtual string getStrValue() const;
};


// ConstPoolPointerReference - a constant pointer value that is initialized to
// point to a global value, which lies at a constant, fixed address.
//
class ConstPoolPointerReference : public ConstPoolPointer {
  ConstPoolPointerReference(const ConstPoolPointerReference &); // DNI!
protected:
  ConstPoolPointerReference(GlobalValue *GV);
  ~ConstPoolPointerReference() {}
public:
  static ConstPoolPointerReference *get(GlobalValue *GV) {
    // FIXME: These should all be shared!
    return new ConstPoolPointerReference(GV);
  }

  virtual string getStrValue() const;

  const GlobalValue *getValue() const { 
    return cast<GlobalValue>(Operands[0].get());
  }
  GlobalValue *getValue() {
    return cast<GlobalValue>(Operands[0].get());
  }
};



#endif