summaryrefslogtreecommitdiff
path: root/include/llvm/ConstPoolVals.h
blob: dbdda62f92dbb8bd45afc0e0abc75a4ac40c0826 (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
//===-- 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/SymTabValue.h"
#include "llvm/Tools/DataTypes.h"
#include <vector>

class ArrayType;
class StructType;

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

class ConstPoolVal;
typedef UseTy<ConstPoolVal> ConstPoolUse;

class ConstPoolVal : public User {
  SymTabValue *Parent;

  friend class ValueHolder<ConstPoolVal, SymTabValue>;
  inline void setParent(SymTabValue *parent) { 
    Parent = parent;
  }

public:
  inline ConstPoolVal(const Type *Ty, const string &Name = "") 
    : User(Ty, Value::ConstantVal, Name) { Parent = 0; }

  // Specialize setName to handle symbol table majik...
  virtual void setName(const string &name);

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

  // clone() - Create a copy of 'this' value that is identical in all ways
  // except the following:
  //   * The value has no parent
  //   * The value has no name
  //
  virtual ConstPoolVal *clone() const = 0;

  virtual string getStrValue() const = 0;
  virtual bool equals(const ConstPoolVal *V) const = 0;

  inline const SymTabValue *getParent() const { return Parent; }
  inline       SymTabValue *getParent()       { return Parent; }

  // if i > the number of operands, then getOperand() returns 0, and setOperand
  // returns false.  setOperand() may also return false if the operand is of
  // the wrong type.
  //
  // Note that some subclasses may change this default no argument behavior
  //
  virtual Value *getOperand(unsigned i) { return 0; }
  virtual const Value *getOperand(unsigned i) const { return 0; }
  virtual bool setOperand(unsigned i, Value *Val) { return false; }
  virtual void dropAllReferences() {}
};



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

//===---------------------------------------------------------------------------
// ConstPoolBool - Boolean Values
//
class ConstPoolBool : public ConstPoolVal {
  bool Val;
  ConstPoolBool(const ConstPoolBool &CP);
public:
  ConstPoolBool(bool V, const string &Name = "");

  virtual string getStrValue() const;
  virtual bool equals(const ConstPoolVal *V) const;

  virtual ConstPoolVal *clone() const { return new ConstPoolBool(*this); }

  inline bool getValue() const { return Val; }

  // setValue - Be careful... if there is more than one 'use' of this node, then
  // they will ALL see the value that you set...
  //
  inline void setValue(bool v) { Val = v; } 
};


//===---------------------------------------------------------------------------
// ConstPoolSInt - Signed Integer Values [sbyte, short, int, long]
//
class ConstPoolSInt : public ConstPoolVal {
  int64_t Val;
  ConstPoolSInt(const ConstPoolSInt &CP);
public:
  ConstPoolSInt(const Type *Ty, int64_t V, const string &Name = "");

  virtual ConstPoolVal *clone() const { return new ConstPoolSInt(*this); }

  virtual string getStrValue() const;
  virtual bool equals(const ConstPoolVal *V) const;

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


//===---------------------------------------------------------------------------
// ConstPoolUInt - Unsigned Integer Values [ubyte, ushort, uint, ulong]
//
class ConstPoolUInt : public ConstPoolVal {
  uint64_t Val;
  ConstPoolUInt(const ConstPoolUInt &CP);
public:
  ConstPoolUInt(const Type *Ty, uint64_t V, const string &Name = "");

  virtual ConstPoolVal *clone() const { return new ConstPoolUInt(*this); }

  virtual string getStrValue() const;
  virtual bool equals(const ConstPoolVal *V) const;

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


//===---------------------------------------------------------------------------
// ConstPoolFP - Floating Point Values [float, double]
//
class ConstPoolFP : public ConstPoolVal {
  double Val;
  ConstPoolFP(const ConstPoolFP &CP);
public:
  ConstPoolFP(const Type *Ty, double V, const string &Name = "");

  virtual ConstPoolVal *clone() const { return new ConstPoolFP(*this); }
  virtual string getStrValue() const;
  virtual bool equals(const ConstPoolVal *V) const;

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


//===---------------------------------------------------------------------------
// ConstPoolType - Type Declarations
//
class ConstPoolType : public ConstPoolVal {
  const Type *Val;
  ConstPoolType(const ConstPoolType &CPT);
public:
  ConstPoolType(const Type *V, const string &Name = "");

  virtual ConstPoolVal *clone() const { return new ConstPoolType(*this); }
  virtual string getStrValue() const;
  virtual bool equals(const ConstPoolVal *V) const;

  inline const Type *getValue() const { return Val; }
};


//===---------------------------------------------------------------------------
// ConstPoolArray - Constant Array Declarations
//
class ConstPoolArray : public ConstPoolVal {
  vector<ConstPoolUse> Val;
  ConstPoolArray(const ConstPoolArray &CPT);
public:
  ConstPoolArray(const ArrayType *T, vector<ConstPoolVal*> &V, 
		 const string &Name = "");
  inline ~ConstPoolArray() { dropAllReferences(); }

  virtual ConstPoolVal *clone() const { return new ConstPoolArray(*this); }
  virtual string getStrValue() const;
  virtual bool equals(const ConstPoolVal *V) const;

  inline const vector<ConstPoolUse> &getValues() const { return Val; }

  // Implement User stuff...
  //
  virtual Value *getOperand(unsigned i) { 
    return (i < Val.size()) ? Val[i] : 0; 
  }
  virtual const Value *getOperand(unsigned i) const {
    return (i < Val.size()) ? Val[i] : 0; 
  }

  // setOperand fails! You can't change a constant!
  virtual bool setOperand(unsigned i, Value *Val) { return false; }
  virtual void dropAllReferences() { Val.clear(); }
};


//===---------------------------------------------------------------------------
// ConstPoolStruct - Constant Struct Declarations
//
class ConstPoolStruct : public ConstPoolVal {
  vector<ConstPoolUse> Val;
  ConstPoolStruct(const ConstPoolStruct &CPT);
public:
  ConstPoolStruct(const StructType *T, vector<ConstPoolVal*> &V, 
		  const string &Name = "");
  inline ~ConstPoolStruct() { dropAllReferences(); }

  virtual ConstPoolVal *clone() const { return new ConstPoolStruct(*this); }
  virtual string getStrValue() const;
  virtual bool equals(const ConstPoolVal *V) const;

  inline const vector<ConstPoolUse> &getValues() const { return Val; }

  // Implement User stuff...
  //
  virtual Value *getOperand(unsigned i) { 
    return (i < Val.size()) ? Val[i] : 0; 
  }
  virtual const Value *getOperand(unsigned i) const {
    return (i < Val.size()) ? Val[i] : 0; 
  }

  // setOperand fails! You can't change a constant!
  virtual bool setOperand(unsigned i, Value *Val) { return false; }
  virtual void dropAllReferences() { Val.clear(); }
};

#endif