Chris seems fond of #include <vector>. Fix these. Also convert use list in
[oota-llvm.git] / include / llvm / ConstPoolVals.h
1 //===-- llvm/ConstPoolVals.h - Constant Value nodes --------------*- C++ -*--=//
2 //
3 // This file contains the declarations for the ConstPoolVal class and all of
4 // its subclasses, which represent the different type of constant pool values
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LLVM_CONSTPOOLVALS_H
9 #define LLVM_CONSTPOOLVALS_H
10
11 #include "llvm/User.h"
12 #include "llvm/Support/DataTypes.h"
13
14 class ArrayType;
15 class StructType;
16
17 //===----------------------------------------------------------------------===//
18 //                            ConstPoolVal Class
19 //===----------------------------------------------------------------------===//
20
21 class ConstPoolVal : public User {
22 protected:
23   inline ConstPoolVal(const Type *Ty) : User(Ty, Value::ConstantVal) {}
24   ~ConstPoolVal() {}
25
26 public:
27   // Specialize setName to handle symbol table majik...
28   virtual void setName(const string &name, SymbolTable *ST = 0);
29
30   virtual string getStrValue() const = 0;
31
32   // Static constructor to get a '0' constant of arbitrary type...
33   static ConstPoolVal *getNullConstant(const Type *Ty);
34 };
35
36
37
38 //===----------------------------------------------------------------------===//
39 //              Classes to represent constant pool variable defs
40 //===----------------------------------------------------------------------===//
41
42 //===---------------------------------------------------------------------------
43 // ConstPoolBool - Boolean Values
44 //
45 class ConstPoolBool : public ConstPoolVal {
46   bool Val;
47   ConstPoolBool(const ConstPoolBool &);     // DO NOT IMPLEMENT
48   ConstPoolBool(bool V);
49   ~ConstPoolBool() {}
50 public:
51   static ConstPoolBool *True, *False;  // The True & False values
52
53   // Factory objects - Return objects of the specified value
54   static ConstPoolBool *get(bool Value) { return Value ? True : False; }
55   static ConstPoolBool *get(const Type *Ty, bool Value) { return get(Value); }
56
57   // inverted - Return the opposite value of the current value.
58   inline ConstPoolBool *inverted() const { return (this==True) ? False : True; }
59
60   virtual string getStrValue() const;
61   inline bool getValue() const { return Val; }
62 };
63
64
65 //===---------------------------------------------------------------------------
66 // ConstPoolInt - Superclass of ConstPoolSInt & ConstPoolUInt, to make dealing
67 // with integral constants easier.
68 //
69 class ConstPoolInt : public ConstPoolVal {
70 protected:
71   union {
72     int64_t  Signed;
73     uint64_t Unsigned;
74   } Val;
75   ConstPoolInt(const ConstPoolInt &);      // DO NOT IMPLEMENT
76   ConstPoolInt(const Type *Ty, uint64_t V);
77   ~ConstPoolInt() {}
78 public:
79   // equalsInt - Provide a helper method that can be used to determine if the 
80   // constant contained within is equal to a constant.  This only works for very
81   // small values, because this is all that can be represented with all types.
82   //
83   bool equalsInt(unsigned char V) const {
84     assert(V <= 127 &&
85            "equals: Can only be used with very small positive constants!");
86     return Val.Unsigned == V;
87   }
88
89   // ConstPoolInt::get static method: return a constant pool int with the
90   // specified value.  as above, we work only with very small values here.
91   //
92   static ConstPoolInt *get(const Type *Ty, unsigned char V);
93 };
94
95
96 //===---------------------------------------------------------------------------
97 // ConstPoolSInt - Signed Integer Values [sbyte, short, int, long]
98 //
99 class ConstPoolSInt : public ConstPoolInt {
100   ConstPoolSInt(const ConstPoolSInt &);      // DO NOT IMPLEMENT
101 protected:
102   ConstPoolSInt(const Type *Ty, int64_t V);
103   ~ConstPoolSInt() {}
104 public:
105   static ConstPoolSInt *get(const Type *Ty, int64_t V);
106
107   virtual string getStrValue() const;
108
109   static bool isValueValidForType(const Type *Ty, int64_t V);
110   inline int64_t getValue() const { return Val.Signed; }
111 };
112
113
114 //===---------------------------------------------------------------------------
115 // ConstPoolUInt - Unsigned Integer Values [ubyte, ushort, uint, ulong]
116 //
117 class ConstPoolUInt : public ConstPoolInt {
118   ConstPoolUInt(const ConstPoolUInt &);      // DO NOT IMPLEMENT
119 protected:
120   ConstPoolUInt(const Type *Ty, uint64_t V);
121   ~ConstPoolUInt() {}
122 public:
123   static ConstPoolUInt *get(const Type *Ty, uint64_t V);
124
125   virtual string getStrValue() const;
126
127   static bool isValueValidForType(const Type *Ty, uint64_t V);
128   inline uint64_t getValue() const { return Val.Unsigned; }
129 };
130
131
132 //===---------------------------------------------------------------------------
133 // ConstPoolFP - Floating Point Values [float, double]
134 //
135 class ConstPoolFP : public ConstPoolVal {
136   double Val;
137   ConstPoolFP(const ConstPoolFP &);      // DO NOT IMPLEMENT
138 protected:
139   ConstPoolFP(const Type *Ty, double V);
140   ~ConstPoolFP() {}
141 public:
142   static ConstPoolFP *get(const Type *Ty, double V);
143
144   virtual string getStrValue() const;
145
146   static bool isValueValidForType(const Type *Ty, double V);
147   inline double getValue() const { return Val; }
148 };
149
150
151 //===---------------------------------------------------------------------------
152 // ConstPoolArray - Constant Array Declarations
153 //
154 class ConstPoolArray : public ConstPoolVal {
155   ConstPoolArray(const ConstPoolArray &);      // DO NOT IMPLEMENT
156 protected:
157   ConstPoolArray(const ArrayType *T, const vector<ConstPoolVal*> &Val);
158   ~ConstPoolArray() {}
159 public:
160   static ConstPoolArray *get(const ArrayType *T, const vector<ConstPoolVal*> &);
161
162   virtual string getStrValue() const;
163
164   inline const vector<Use> &getValues() const { return Operands; }
165 };
166
167
168 //===---------------------------------------------------------------------------
169 // ConstPoolStruct - Constant Struct Declarations
170 //
171 class ConstPoolStruct : public ConstPoolVal {
172   ConstPoolStruct(const ConstPoolStruct &);      // DO NOT IMPLEMENT
173 protected:
174   ConstPoolStruct(const StructType *T, const vector<ConstPoolVal*> &Val);
175   ~ConstPoolStruct() {}
176 public:
177   static ConstPoolStruct *get(const StructType *T,
178                               const vector<ConstPoolVal*> &V);
179
180   virtual string getStrValue() const;
181
182   inline const vector<Use> &getValues() const { return Operands; }
183 };
184
185 #endif